Skip to content
This repository has been archived by the owner on May 19, 2018. It is now read-only.

Commit

Permalink
parse only method parameter decorators
Browse files Browse the repository at this point in the history
  • Loading branch information
shuhei committed Mar 22, 2016
1 parent 37849e3 commit 87edfd1
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/parser/expression.js
Original file line number Diff line number Diff line change
Expand Up @@ -824,7 +824,7 @@ pp.parseMethod = function (node, isGenerator, isAsync) {
this.state.inMethod = node.kind || true;
this.initFunction(node, isAsync);
this.expect(tt.parenL);
node.params = this.parseBindingList(tt.parenR, false, this.hasPlugin("trailingFunctionCommas"));
node.params = this.parseBindingList(tt.parenR, false, this.hasPlugin("trailingFunctionCommas"), true);
node.generator = isGenerator;
this.parseFunctionBody(node);
this.state.inMethod = oldInMethod;
Expand Down
12 changes: 7 additions & 5 deletions src/parser/lval.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ pp.parseBindingAtom = function () {
case tt.bracketL:
let node = this.startNode();
this.next();
node.elements = this.parseBindingList(tt.bracketR, true, true);
node.elements = this.parseBindingList(tt.bracketR, true, true, false);
return this.finishNode(node, "ArrayPattern");

case tt.braceL:
Expand All @@ -144,7 +144,7 @@ pp.parseBindingAtom = function () {
}
};

pp.parseBindingList = function (close, allowEmpty, allowTrailingComma) {
pp.parseBindingList = function (close, allowEmpty, allowTrailingComma, allowDecorator) {
let elts = [];
let first = true;
while (!this.eat(close)) {
Expand All @@ -163,11 +163,13 @@ pp.parseBindingList = function (close, allowEmpty, allowTrailingComma) {
break;
} else {
let decorators = [];
while (this.match(tt.at)) {
decorators.push(this.parseDecorator("ParameterDecorator"));
if (allowDecorator) {
while (this.match(tt.at)) {
decorators.push(this.parseDecorator("ParameterDecorator"));
}
}
let left = this.parseMaybeDefault();
if (decorators.length) {
if (allowDecorator && decorators.length) {
left.decorators = decorators;
}
this.parseAssignableListItemTypes(left);
Expand Down
2 changes: 1 addition & 1 deletion src/parser/statement.js
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,7 @@ pp.parseFunction = function (node, isStatement, allowExpressionBody, isAsync, op

pp.parseFunctionParams = function (node) {
this.expect(tt.parenL);
node.params = this.parseBindingList(tt.parenR, false, this.hasPlugin("trailingFunctionCommas"));
node.params = this.parseBindingList(tt.parenR, false, this.hasPlugin("trailingFunctionCommas"), false);
};

// Parse a class declaration or literal (depending on the
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
function func(@foo() x, @bar({ a: 123 }) @baz() y) {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"throws": "Unexpected token (1:14)"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
const func = function (@foo() x, @bar({ a: 123 }) @baz() y) {};
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"throws": "Unexpected token (1:23)"
}

0 comments on commit 87edfd1

Please sign in to comment.