Skip to content

Commit 1036087

Browse files
authored
fix: prevent access if properties couldn't be resolved when syntax highlighting in the REPL
PR-URL: #2412 Signed-off-by: Snehil Shah <snehilshah.989@gmail.com> Reviewed-by: Philipp Burckhardt <pburckhardt@outlook.com>
1 parent a50d33d commit 1036087

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

lib/node_modules/@stdlib/repl/lib/tokenizer.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,7 @@ function tokenizer( line, context ) {
270270
function resolveMemberExpression( node, compute ) {
271271
var properties = linkedList();
272272
var property;
273+
var computed;
273274
var locals;
274275
var obj;
275276

@@ -350,7 +351,12 @@ function tokenizer( line, context ) {
350351
}
351352
// Case: `foo[a.b].bar` - recursively compute the internal `MemberExpression`...
352353
if ( property.value.type === 'MemberExpression' ) {
353-
obj = obj[ resolveMemberExpression( property.value, true ) ];
354+
computed = resolveMemberExpression( property.value, true );
355+
if ( !isLiteralType( typeof computed ) ) {
356+
// Couldn't compute the internal `MemberExpression` into a definite name:
357+
break;
358+
}
359+
obj = obj[ computed ];
354360
if ( !obj ) {
355361
// Property not found in context:
356362
break;

0 commit comments

Comments
 (0)