This repository was archived by the owner on Apr 10, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 4 files changed +43
-2
lines changed
fixtures/parse/member-expression-005 Expand file tree Collapse file tree 4 files changed +43
-2
lines changed Original file line number Diff line number Diff line change 1+ ++ a . b
Original file line number Diff line number Diff line change 1+ {
2+ "type" : " Program" ,
3+ "body" : [
4+ {
5+ "type" : " ExpressionStatement" ,
6+ "expression" : {
7+ "type" : " UpdateExpression" ,
8+ "operator" : " ++" ,
9+ "argument" : {
10+ "type" : " MemberExpression" ,
11+ "object" : {
12+ "type" : " Identifier" ,
13+ "name" : " a"
14+ },
15+ "property" : {
16+ "type" : " Identifier" ,
17+ "name" : " b"
18+ },
19+ "computed" : false
20+ },
21+ "prefix" : true
22+ }
23+ }
24+ ]
25+ }
Original file line number Diff line number Diff line change @@ -17,7 +17,7 @@ test('parse', async (t) => {
1717 onlyDirectories : true ,
1818 } ) ) . filter ( ( x ) => {
1919 return true ;
20- return x === 'conditional -expression-000 ' ;
20+ return x === 'member -expression-005 ' ;
2121 } ) ;
2222
2323 const tested = [ ] ;
Original file line number Diff line number Diff line change @@ -336,6 +336,12 @@ module.exports = function parse(input) {
336336 ) ;
337337 return ( operator = null ) ;
338338 }
339+ if ( astFactory . isUpdateExpressionOperator ( operator ) ) {
340+ expressionStatement = new astFactory . ExpressionStatement (
341+ new astFactory . UpdateExpression ( operator , node , true )
342+ ) ;
343+ return ( operator = null ) ;
344+ }
339345 return ( expressionStatement = new astFactory . ExpressionStatement ( node ) ) ;
340346 }
341347
@@ -470,6 +476,7 @@ module.exports = function parse(input) {
470476 ) ;
471477 break ;
472478 case astTypes . UNARY_EXPRESSION :
479+ case astTypes . UPDATE_EXPRESSION :
473480 parent . argument = new astFactory . MemberExpression (
474481 parent . argument ,
475482 expression ,
@@ -607,7 +614,10 @@ module.exports = function parse(input) {
607614 }
608615
609616 function checkIdentifier ( node ) {
610- if ( node . type !== astTypes . IDENTIFIER ) {
617+ if (
618+ node . type !== astTypes . IDENTIFIER &&
619+ node . type !== astTypes . MEMBER_EXPRESSION
620+ ) {
611621 throwError ( 'Update operator only works on identifier nodes' ) ;
612622 }
613623 }
@@ -655,6 +665,11 @@ module.exports = function parse(input) {
655665 node = ast . property ;
656666 traverse ( node ) ;
657667 break ;
668+ case astTypes . UPDATE_EXPRESSION :
669+ parent = ast ;
670+ node = ast . argument ;
671+ traverse ( node ) ;
672+ break ;
658673 case astTypes . LITERAL :
659674 case astTypes . IDENTIFIER :
660675 break ;
You can’t perform that action at this time.
0 commit comments