Skip to content

Commit

Permalink
Disallow whitespace around safe tilde call operator
Browse files Browse the repository at this point in the history
  • Loading branch information
wcjohnson committed Oct 7, 2017
1 parent adbe2a4 commit 15b9b13
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/plugins/tildeCall.js
Expand Up @@ -16,7 +16,11 @@ export default function(parser) {
node.callee = this.parseSubscripts(callee, this.state.start, this.state.startLoc, true);

// Allow safe tilde calls (a~b?(c))
if (this.hasPlugin("safeCallExpression") && this.eat(tt.question)) {
if (
this.hasPlugin("safeCallExpression") &&
this.state.lastTokEnd === (this.state.pos - 1) &&
this.eat(tt.question)
) {
node.optional = true;
}

Expand All @@ -31,6 +35,9 @@ export default function(parser) {
return false;
}
} else {
if (node.optional && this.state.lastTokEnd !== (this.state.pos - 1)) {
this.unexpected(null, "Whitespace is forbidden after `?` in an optional call.");
}
this.expect(tt.parenL);
node.arguments = this.parseCallExpressionArguments(tt.parenR, false);
node.arguments.unshift(firstArg);
Expand Down
@@ -0,0 +1 @@
a~b ?(c)
@@ -0,0 +1,7 @@
{
"alternatives": {
"default": {
"throws": "Unexpected token, expected ( (1:4)"
}
}
}
@@ -0,0 +1 @@
a~b? (c)
@@ -0,0 +1,7 @@
{
"alternatives": {
"default": {
"throws": "Whitespace is forbidden after `?` in an optional call. (1:5)"
}
}
}

0 comments on commit 15b9b13

Please sign in to comment.