Skip to content

Commit

Permalink
fix: properly parse member expression after property initializ… (#11031)
Browse files Browse the repository at this point in the history
Fixes issue 10989 where the only the identifier in a member expression that is the value of an object property would be parsed. Removing checkExpressionErrors in parseExprSubscripts results in the subscript also being parsed.
  • Loading branch information
vedantroy authored and nicolo-ribaudo committed Jan 19, 2020
1 parent 85ddc29 commit 341964b
Show file tree
Hide file tree
Showing 5 changed files with 557 additions and 4 deletions.
4 changes: 0 additions & 4 deletions packages/babel-parser/src/parser/expression.js
Expand Up @@ -532,10 +532,6 @@ export default class ExpressionParser extends LValParser {
return expr;
}

if (this.checkExpressionErrors(refExpressionErrors, false)) {
return expr;
}

return this.parseSubscripts(expr, startPos, startLoc);
}

Expand Down
@@ -0,0 +1 @@
({a = 42, b: test.d} = {})
@@ -0,0 +1,278 @@
{
"type": "File",
"start": 0,
"end": 26,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 26
}
},
"program": {
"type": "Program",
"start": 0,
"end": 26,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 26
}
},
"sourceType": "script",
"interpreter": null,
"body": [
{
"type": "ExpressionStatement",
"start": 0,
"end": 26,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 26
}
},
"expression": {
"type": "AssignmentExpression",
"start": 1,
"end": 25,
"loc": {
"start": {
"line": 1,
"column": 1
},
"end": {
"line": 1,
"column": 25
}
},
"operator": "=",
"left": {
"type": "ObjectPattern",
"start": 1,
"end": 20,
"loc": {
"start": {
"line": 1,
"column": 1
},
"end": {
"line": 1,
"column": 20
}
},
"properties": [
{
"type": "ObjectProperty",
"start": 2,
"end": 8,
"loc": {
"start": {
"line": 1,
"column": 2
},
"end": {
"line": 1,
"column": 8
}
},
"method": false,
"key": {
"type": "Identifier",
"start": 2,
"end": 3,
"loc": {
"start": {
"line": 1,
"column": 2
},
"end": {
"line": 1,
"column": 3
},
"identifierName": "a"
},
"name": "a"
},
"computed": false,
"shorthand": true,
"value": {
"type": "AssignmentPattern",
"start": 2,
"end": 8,
"loc": {
"start": {
"line": 1,
"column": 2
},
"end": {
"line": 1,
"column": 8
}
},
"left": {
"type": "Identifier",
"start": 2,
"end": 3,
"loc": {
"start": {
"line": 1,
"column": 2
},
"end": {
"line": 1,
"column": 3
},
"identifierName": "a"
},
"name": "a"
},
"right": {
"type": "NumericLiteral",
"start": 6,
"end": 8,
"loc": {
"start": {
"line": 1,
"column": 6
},
"end": {
"line": 1,
"column": 8
}
},
"extra": {
"rawValue": 42,
"raw": "42"
},
"value": 42
}
},
"extra": {
"shorthand": true
}
},
{
"type": "ObjectProperty",
"start": 10,
"end": 19,
"loc": {
"start": {
"line": 1,
"column": 10
},
"end": {
"line": 1,
"column": 19
}
},
"method": false,
"key": {
"type": "Identifier",
"start": 10,
"end": 11,
"loc": {
"start": {
"line": 1,
"column": 10
},
"end": {
"line": 1,
"column": 11
},
"identifierName": "b"
},
"name": "b"
},
"computed": false,
"shorthand": false,
"value": {
"type": "MemberExpression",
"start": 13,
"end": 19,
"loc": {
"start": {
"line": 1,
"column": 13
},
"end": {
"line": 1,
"column": 19
}
},
"object": {
"type": "Identifier",
"start": 13,
"end": 17,
"loc": {
"start": {
"line": 1,
"column": 13
},
"end": {
"line": 1,
"column": 17
},
"identifierName": "test"
},
"name": "test"
},
"property": {
"type": "Identifier",
"start": 18,
"end": 19,
"loc": {
"start": {
"line": 1,
"column": 18
},
"end": {
"line": 1,
"column": 19
},
"identifierName": "d"
},
"name": "d"
},
"computed": false
}
}
]
},
"right": {
"type": "ObjectExpression",
"start": 23,
"end": 25,
"loc": {
"start": {
"line": 1,
"column": 23
},
"end": {
"line": 1,
"column": 25
}
},
"properties": []
},
"extra": {
"parenthesized": true,
"parenStart": 0
}
}
}
],
"directives": []
}
}
@@ -0,0 +1 @@
({a = 42, b: {}.d} = {})

0 comments on commit 341964b

Please sign in to comment.