Skip to content

Commit

Permalink
refactor: simplify toAssignable on ParenthesizedExpression
Browse files Browse the repository at this point in the history
  • Loading branch information
JLHwung committed Jan 20, 2020
1 parent 0eec2e3 commit 6b00760
Show file tree
Hide file tree
Showing 4 changed files with 146 additions and 7 deletions.
11 changes: 4 additions & 7 deletions packages/babel-parser/src/parser/lval.js
Expand Up @@ -51,12 +51,9 @@ export default class LValParser extends NodeUtils {
// When this one is updated, please check if also that one needs to be updated.

toAssignable(node: Node): Node {
if (
(this.options.createParenthesizedExpressions &&
node.type === "ParenthesizedExpression") ||
node.extra?.parenthesized
) {
const parenthesized = unwrapParenthesizedExpression(node);
let parenthesized = undefined;
if (node.type === "ParenthesizedExpression" || node.extra?.parenthesized) {
parenthesized = unwrapParenthesizedExpression(node);
if (
parenthesized.type !== "Identifier" &&
parenthesized.type !== "MemberExpression"
Expand Down Expand Up @@ -125,7 +122,7 @@ export default class LValParser extends NodeUtils {
break;

case "ParenthesizedExpression":
node.expression = this.toAssignable(node.expression);
this.toAssignable(((parenthesized: any): Expression));
break;

default:
Expand Down
@@ -0,0 +1 @@
(!a) += 1

This comment has been minimized.

Copy link
@nicolo-ribaudo

nicolo-ribaudo Jan 20, 2020

Member

Please don't create a new uncategorised test 馃槄

New tests should all have a meaningful name.

@@ -0,0 +1,3 @@
{
"createParenthesizedExpressions": true
}
138 changes: 138 additions & 0 deletions packages/babel-parser/test/fixtures/core/uncategorised/567/output.json
@@ -0,0 +1,138 @@
{
"type": "File",
"start": 0,
"end": 9,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 9
}
},
"errors": [
"SyntaxError: Invalid left-hand side in parenthesized expression (1:1)"
],
"program": {
"type": "Program",
"start": 0,
"end": 9,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 9
}
},
"sourceType": "script",
"interpreter": null,
"body": [
{
"type": "ExpressionStatement",
"start": 0,
"end": 9,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 9
}
},
"expression": {
"type": "AssignmentExpression",
"start": 0,
"end": 9,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 9
}
},
"operator": "+=",
"left": {
"type": "ParenthesizedExpression",
"start": 0,
"end": 4,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 4
}
},
"expression": {
"type": "UnaryExpression",
"start": 1,
"end": 3,
"loc": {
"start": {
"line": 1,
"column": 1
},
"end": {
"line": 1,
"column": 3
}
},
"operator": "!",
"prefix": true,
"argument": {
"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": 8,
"end": 9,
"loc": {
"start": {
"line": 1,
"column": 8
},
"end": {
"line": 1,
"column": 9
}
},
"extra": {
"rawValue": 1,
"raw": "1"
},
"value": 1
}
}
}
],
"directives": []
}
}

0 comments on commit 6b00760

Please sign in to comment.