diff --git a/lib/node_modules/@stdlib/repl/lib/tokenizer.js b/lib/node_modules/@stdlib/repl/lib/tokenizer.js index 188ae75ce857..825aba460bbd 100644 --- a/lib/node_modules/@stdlib/repl/lib/tokenizer.js +++ b/lib/node_modules/@stdlib/repl/lib/tokenizer.js @@ -24,6 +24,7 @@ var parse = require( 'acorn-loose' ).parse; var walk = require( 'acorn-walk' ); +var hasProp = require( '@stdlib/assert/has-property' ); var linkedList = require( '@stdlib/utils/linked-list' ); var contains = require( '@stdlib/array/base/assert/contains' ); var resolveLocalScopes = require( './resolve_local_scopes.js' ); @@ -227,7 +228,7 @@ function tokenizer( line, context ) { for ( i = 0; i < COMMANDS.length; i++ ) { command = COMMANDS[ i ]; if ( node.name === command[ 0 ] ) { - tokens.push( { + tokens.push({ 'value': node.name, 'type': 'command', 'start': node.start, @@ -240,14 +241,14 @@ function tokenizer( line, context ) { identifier = context[ node.name ]; if ( identifier ) { if ( isLiteralType( typeof identifier ) ) { - tokens.push( { + tokens.push({ 'value': node.name, 'type': 'variable', 'start': node.start, 'end': node.end }); } else { - tokens.push( { + tokens.push({ 'value': node.name, 'type': typeof identifier, 'start': node.start, @@ -313,9 +314,13 @@ function tokenizer( line, context ) { } // Case: 'bar' in `foo['bar']` - property already pushed as a string token. Ignore... if ( property.value.type === 'Literal' ) { - obj = obj[ property.value.value ]; - if ( !obj ) { - // Property not found in context: + try { + if ( !hasProp( obj, property.value.value ) ) { + // Property not found in context: + break; + } + obj = obj[ property.value.value ]; + } catch ( error ) { // eslint-disable-line no-unused-vars break; } property = properties.next(); @@ -323,9 +328,13 @@ function tokenizer( line, context ) { } // Case: `foo.bar` - resolve property and push it as a token... if ( property.value.type === 'Identifier' ) { - obj = obj[ property.value.name ]; - if ( !obj ) { - // Property not found in context: + try { + if ( !hasProp( obj, property.value.name ) ) { + // Property not found in context: + break; + } + obj = obj[ property.value.name ]; + } catch ( error ) { // eslint-disable-line no-unused-vars break; } if ( !compute ) { @@ -356,9 +365,13 @@ function tokenizer( line, context ) { // Couldn't compute the internal `MemberExpression` into a definite name: break; } - obj = obj[ computed ]; - if ( !obj ) { - // Property not found in context: + try { + if ( !hasProp( obj, computed ) ) { + // Property not found in context: + break; + } + obj = obj[ computed ]; + } catch ( error ) { // eslint-disable-line no-unused-vars break; } property = properties.next();