24
24
25
25
var parse = require ( 'acorn-loose' ) . parse ;
26
26
var walk = require ( 'acorn-walk' ) ;
27
+ var hasProp = require ( '@stdlib/assert/has-property' ) ;
27
28
var linkedList = require ( '@stdlib/utils/linked-list' ) ;
28
29
var contains = require ( '@stdlib/array/base/assert/contains' ) ;
29
30
var resolveLocalScopes = require ( './resolve_local_scopes.js' ) ;
@@ -227,7 +228,7 @@ function tokenizer( line, context ) {
227
228
for ( i = 0 ; i < COMMANDS . length ; i ++ ) {
228
229
command = COMMANDS [ i ] ;
229
230
if ( node . name === command [ 0 ] ) {
230
- tokens . push ( {
231
+ tokens . push ( {
231
232
'value' : node . name ,
232
233
'type' : 'command' ,
233
234
'start' : node . start ,
@@ -240,14 +241,14 @@ function tokenizer( line, context ) {
240
241
identifier = context [ node . name ] ;
241
242
if ( identifier ) {
242
243
if ( isLiteralType ( typeof identifier ) ) {
243
- tokens . push ( {
244
+ tokens . push ( {
244
245
'value' : node . name ,
245
246
'type' : 'variable' ,
246
247
'start' : node . start ,
247
248
'end' : node . end
248
249
} ) ;
249
250
} else {
250
- tokens . push ( {
251
+ tokens . push ( {
251
252
'value' : node . name ,
252
253
'type' : typeof identifier ,
253
254
'start' : node . start ,
@@ -313,19 +314,27 @@ function tokenizer( line, context ) {
313
314
}
314
315
// Case: 'bar' in `foo['bar']` - property already pushed as a string token. Ignore...
315
316
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
319
324
break ;
320
325
}
321
326
property = properties . next ( ) ;
322
327
continue ;
323
328
}
324
329
// Case: `foo.bar` - resolve property and push it as a token...
325
330
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
329
338
break ;
330
339
}
331
340
if ( ! compute ) {
@@ -356,9 +365,13 @@ function tokenizer( line, context ) {
356
365
// Couldn't compute the internal `MemberExpression` into a definite name:
357
366
break ;
358
367
}
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
362
375
break ;
363
376
}
364
377
property = properties . next ( ) ;
0 commit comments