Skip to content
This repository was archived by the owner on Apr 10, 2023. It is now read-only.

Commit 6f35243

Browse files
committed
fix(MemberExpression): 🐛UnaryExpression
1 parent 496d322 commit 6f35243

File tree

4 files changed

+43
-2
lines changed

4 files changed

+43
-2
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
++a.b
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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+
}

lib/__tests__/parse.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff 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 = [];

lib/parse.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff 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;

0 commit comments

Comments
 (0)