From 6ff25b901a7a5961e714b4fbce4a6f69cbb790f1 Mon Sep 17 00:00:00 2001 From: "William C. Johnson" Date: Mon, 2 Oct 2017 20:04:53 -0400 Subject: [PATCH] Revert `?.(` syntax due to JS stage 1 proposal uncertainty --- src/parser/expression.js | 42 ++++---- .../safe-call-expression/js/basic/actual.js | 1 - .../js/basic/expected.json | 101 ------------------ 3 files changed, 18 insertions(+), 126 deletions(-) delete mode 100644 test/fixtures/safe-call-expression/js/basic/actual.js delete mode 100644 test/fixtures/safe-call-expression/js/basic/expected.json diff --git a/src/parser/expression.js b/src/parser/expression.js index 1f94a2151e..515adf5064 100644 --- a/src/parser/expression.js +++ b/src/parser/expression.js @@ -430,36 +430,30 @@ pp.parseSubscripts = function (base, startPos, startLoc, noCalls) { const op = this.state.value; this.next(); - if (op === "?." && this.match(tt.parenL) && this.hasPlugin("safeCallExpression")) { - // x?.(...) = JS safe call proposal - const [next, canSubscript] = this.parseSafeCall(base, startPos, startLoc); - if (canSubscript) base = next; else return base; - } else { - // `x?.y` `x?[y]` - const node = this.startNodeAt(startPos, startLoc); - node.object = base; - - if (op === "?.") { - if (this.match(tt.num)) { - // arr?.0 -> arr?[0] - node.property = this.parseLiteral(this.state.value, "NumericLiteral"); - node.computed = true; - } else { - node.property = this.parseIdentifierOrPlaceholder(true); - node.computed = false; - } - } else if (op === "?[") { - node.property = this.parseExpression(); + // `x?.y` `x?[y]` + const node = this.startNodeAt(startPos, startLoc); + node.object = base; + + if (op === "?.") { + if (this.match(tt.num)) { + // arr?.0 -> arr?[0] + node.property = this.parseLiteral(this.state.value, "NumericLiteral"); node.computed = true; - this.expect(tt.bracketR); } else { node.property = this.parseIdentifierOrPlaceholder(true); node.computed = false; } - - node.optional = true; - base = this.finishNode(node, "MemberExpression"); + } else if (op === "?[") { + node.property = this.parseExpression(); + node.computed = true; + this.expect(tt.bracketR); + } else { + node.property = this.parseIdentifierOrPlaceholder(true); + node.computed = false; } + + node.optional = true; + base = this.finishNode(node, "MemberExpression"); } else if ( (this.hasPlugin("safeCallExpression") || this.hasPlugin("existentialExpression")) && this.match(tt.question) && diff --git a/test/fixtures/safe-call-expression/js/basic/actual.js b/test/fixtures/safe-call-expression/js/basic/actual.js deleted file mode 100644 index fcd86af6e6..0000000000 --- a/test/fixtures/safe-call-expression/js/basic/actual.js +++ /dev/null @@ -1 +0,0 @@ -f?.(x) diff --git a/test/fixtures/safe-call-expression/js/basic/expected.json b/test/fixtures/safe-call-expression/js/basic/expected.json deleted file mode 100644 index e3d21383c0..0000000000 --- a/test/fixtures/safe-call-expression/js/basic/expected.json +++ /dev/null @@ -1,101 +0,0 @@ -{ - "type": "File", - "start": 0, - "end": 6, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 1, - "column": 6 - } - }, - "program": { - "type": "Program", - "start": 0, - "end": 6, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 1, - "column": 6 - } - }, - "sourceType": "script", - "body": [ - { - "type": "ExpressionStatement", - "start": 0, - "end": 6, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 1, - "column": 6 - } - }, - "expression": { - "type": "CallExpression", - "start": 0, - "end": 6, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 1, - "column": 6 - } - }, - "callee": { - "type": "Identifier", - "start": 0, - "end": 1, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 1, - "column": 1 - }, - "identifierName": "f" - }, - "name": "f" - }, - "optional": true, - "arguments": [ - { - "type": "Identifier", - "start": 4, - "end": 5, - "loc": { - "start": { - "line": 1, - "column": 4 - }, - "end": { - "line": 1, - "column": 5 - }, - "identifierName": "x" - }, - "name": "x" - } - ] - } - } - ], - "directives": [] - } -} \ No newline at end of file