2424
2525var parse = require ( 'acorn-loose' ) . parse ;
2626var walk = require ( 'acorn-walk' ) ;
27+ var hasProp = require ( '@stdlib/assert/has-property' ) ;
2728var linkedList = require ( '@stdlib/utils/linked-list' ) ;
2829var contains = require ( '@stdlib/array/base/assert/contains' ) ;
2930var resolveLocalScopes = require ( './resolve_local_scopes.js' ) ;
@@ -227,7 +228,7 @@ function tokenizer( line, context ) {
227228 for ( i = 0 ; i < COMMANDS . length ; i ++ ) {
228229 command = COMMANDS [ i ] ;
229230 if ( node . name === command [ 0 ] ) {
230- tokens . push ( {
231+ tokens . push ( {
231232 'value' : node . name ,
232233 'type' : 'command' ,
233234 'start' : node . start ,
@@ -240,14 +241,14 @@ function tokenizer( line, context ) {
240241 identifier = context [ node . name ] ;
241242 if ( identifier ) {
242243 if ( isLiteralType ( typeof identifier ) ) {
243- tokens . push ( {
244+ tokens . push ( {
244245 'value' : node . name ,
245246 'type' : 'variable' ,
246247 'start' : node . start ,
247248 'end' : node . end
248249 } ) ;
249250 } else {
250- tokens . push ( {
251+ tokens . push ( {
251252 'value' : node . name ,
252253 'type' : typeof identifier ,
253254 'start' : node . start ,
@@ -313,19 +314,27 @@ function tokenizer( line, context ) {
313314 }
314315 // Case: 'bar' in `foo['bar']` - property already pushed as a string token. Ignore...
315316 if ( property . value . type === 'Literal' ) {
316- obj = obj [ property . value . value ] ;
317- if ( ! obj ) {
318- // Property not found in context:
317+ try {
318+ if ( ! hasProp ( obj , property . value . value ) ) {
319+ // Property not found in context:
320+ break ;
321+ }
322+ obj = obj [ property . value . value ] ;
323+ } catch ( error ) { // eslint-disable-line no-unused-vars
319324 break ;
320325 }
321326 property = properties . next ( ) ;
322327 continue ;
323328 }
324329 // Case: `foo.bar` - resolve property and push it as a token...
325330 if ( property . value . type === 'Identifier' ) {
326- obj = obj [ property . value . name ] ;
327- if ( ! obj ) {
328- // Property not found in context:
331+ try {
332+ if ( ! hasProp ( obj , property . value . name ) ) {
333+ // Property not found in context:
334+ break ;
335+ }
336+ obj = obj [ property . value . name ] ;
337+ } catch ( error ) { // eslint-disable-line no-unused-vars
329338 break ;
330339 }
331340 if ( ! compute ) {
@@ -356,9 +365,13 @@ function tokenizer( line, context ) {
356365 // Couldn't compute the internal `MemberExpression` into a definite name:
357366 break ;
358367 }
359- obj = obj [ computed ] ;
360- if ( ! obj ) {
361- // Property not found in context:
368+ try {
369+ if ( ! hasProp ( obj , computed ) ) {
370+ // Property not found in context:
371+ break ;
372+ }
373+ obj = obj [ computed ] ;
374+ } catch ( error ) { // eslint-disable-line no-unused-vars
362375 break ;
363376 }
364377 property = properties . next ( ) ;
0 commit comments