@@ -486,42 +486,30 @@ function parser(inputTokens) {
486486 return null ;
487487 }
488488
489- if ( tokens [ 0 ] . type !== tokenTypes . IDENTIFIER || tokens [ tokens . length - 1 ] . type !== tokenTypes . IDENTIFIER ) {
490- return null ;
489+ if (
490+ tokens [ tokens . length - 1 ] . type === tokenTypes . IDENTIFIER &&
491+ tokens [ tokens . length - 2 ] . type === tokenTypes . LABEL &&
492+ tokens [ tokens . length - 2 ] . value === '.'
493+ ) {
494+ return new astFactory . MemberExpression ( getExpression ( tokens . slice ( 0 , - 2 ) ) , getExpression ( tokens . slice ( - 1 ) ) ) ;
491495 }
492496
493- // * ... + (identifier || literal) + label(.) + identify
494- // * ... + (identifier || literal) + label([) + (identify || literal) + label(])
495- let expecting = tokenTypes . IDENTIFIER ;
496- let access = [ ] ;
497- let i = 0 ;
498- while (
499- i < tokens . length && (
500- ( tokens [ i ] . type === expecting && expecting === tokenTypes . LABEL && tokens [ i ] . value === '.' )
501- || ( tokens [ i ] . type === expecting && expecting === tokenTypes . IDENTIFIER )
502- )
503- ) {
504- if ( tokens [ i ] . type === tokenTypes . IDENTIFIER ) {
505- access . push ( tokens [ i ] ) ;
497+ if ( tokens [ tokens . length - 1 ] . type === tokenTypes . LABEL && tokens [ tokens . length - 1 ] . value === ']' ) {
498+ // get [ index
499+ let startBracketIndex = - 1 ;
500+ for ( let i = tokens . length - 1 ; i >= 0 ; i -- ) {
501+ if ( tokens [ i ] . type === tokenTypes . LABEL && tokens [ i ] . value === '[' ) {
502+ startBracketIndex = i ;
503+ break ;
504+ }
506505 }
507- i ++ ;
508- if ( expecting === tokenTypes . LABEL ) {
509- expecting = tokenTypes . IDENTIFIER ;
510- } else {
511- expecting = tokenTypes . LABEL ;
506+ if ( startBracketIndex === - 1 ) {
507+ throw new Error ( 'Expect [' ) ;
512508 }
509+ return new astFactory . MemberExpression ( getExpression ( tokens . slice ( 0 , startBracketIndex ) ) , getExpression ( tokens . slice ( startBracketIndex + 1 , tokens . length - 1 ) ) ) ;
513510 }
514511
515- if ( expecting === tokenTypes . IDENTIFIER && i !== tokens . length - 1 ) {
516- return null ;
517- }
518-
519- let object = new astFactory . Identifier ( access [ 0 ] . value ) ;
520-
521- for ( let j = 1 ; j < access . length ; j ++ ) {
522- object = new astFactory . MemberExpression ( object , new astFactory . Identifier ( access [ j ] . value ) ) ;
523- }
524- return object ;
512+ return null ;
525513 }
526514
527515 function getExpression ( tokens ) {
0 commit comments