Skip to content

Commit

Permalink
Revert ?.( syntax due to JS stage 1 proposal uncertainty
Browse files Browse the repository at this point in the history
  • Loading branch information
wcjohnson committed Oct 3, 2017
1 parent 249aee6 commit 6ff25b9
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 126 deletions.
42 changes: 18 additions & 24 deletions src/parser/expression.js
Expand Up @@ -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) &&
Expand Down
1 change: 0 additions & 1 deletion test/fixtures/safe-call-expression/js/basic/actual.js

This file was deleted.

101 changes: 0 additions & 101 deletions test/fixtures/safe-call-expression/js/basic/expected.json

This file was deleted.

0 comments on commit 6ff25b9

Please sign in to comment.