From 82943ad5dab3489c71db04d243b4eae8cb3a8bdc Mon Sep 17 00:00:00 2001 From: Shuhei Kagawa Date: Wed, 23 Mar 2016 00:39:19 +0900 Subject: [PATCH] parse only method parameter decorators --- src/parser/expression.js | 2 +- src/parser/lval.js | 10 ++++++---- .../function-declaration-parameter-decorator/actual.js | 1 + .../options.json | 3 +++ .../function-expression-parameter-decorator/actual.js | 1 + .../options.json | 3 +++ .../actual.js | 0 .../expected.json | 0 8 files changed, 15 insertions(+), 5 deletions(-) create mode 100644 test/fixtures/experimental/decorators/function-declaration-parameter-decorator/actual.js create mode 100644 test/fixtures/experimental/decorators/function-declaration-parameter-decorator/options.json create mode 100644 test/fixtures/experimental/decorators/function-expression-parameter-decorator/actual.js create mode 100644 test/fixtures/experimental/decorators/function-expression-parameter-decorator/options.json rename test/fixtures/experimental/decorators/{parameter-decorator => method-parameter-decorator}/actual.js (100%) rename test/fixtures/experimental/decorators/{parameter-decorator => method-parameter-decorator}/expected.json (100%) diff --git a/src/parser/expression.js b/src/parser/expression.js index bc89b4bdf5..74d9b604b9 100644 --- a/src/parser/expression.js +++ b/src/parser/expression.js @@ -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; diff --git a/src/parser/lval.js b/src/parser/lval.js index 1c0f536e5b..a01bbee801 100644 --- a/src/parser/lval.js +++ b/src/parser/lval.js @@ -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)) { @@ -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); diff --git a/test/fixtures/experimental/decorators/function-declaration-parameter-decorator/actual.js b/test/fixtures/experimental/decorators/function-declaration-parameter-decorator/actual.js new file mode 100644 index 0000000000..d7deff7cfe --- /dev/null +++ b/test/fixtures/experimental/decorators/function-declaration-parameter-decorator/actual.js @@ -0,0 +1 @@ +function func(@foo() x, @bar({ a: 123 }) @baz() y) {} diff --git a/test/fixtures/experimental/decorators/function-declaration-parameter-decorator/options.json b/test/fixtures/experimental/decorators/function-declaration-parameter-decorator/options.json new file mode 100644 index 0000000000..d50e8469b8 --- /dev/null +++ b/test/fixtures/experimental/decorators/function-declaration-parameter-decorator/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Unexpected token (1:14)" +} diff --git a/test/fixtures/experimental/decorators/function-expression-parameter-decorator/actual.js b/test/fixtures/experimental/decorators/function-expression-parameter-decorator/actual.js new file mode 100644 index 0000000000..73998d525e --- /dev/null +++ b/test/fixtures/experimental/decorators/function-expression-parameter-decorator/actual.js @@ -0,0 +1 @@ +const func = function (@foo() x, @bar({ a: 123 }) @baz() y) {}; diff --git a/test/fixtures/experimental/decorators/function-expression-parameter-decorator/options.json b/test/fixtures/experimental/decorators/function-expression-parameter-decorator/options.json new file mode 100644 index 0000000000..562afcef48 --- /dev/null +++ b/test/fixtures/experimental/decorators/function-expression-parameter-decorator/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Unexpected token (1:23)" +} diff --git a/test/fixtures/experimental/decorators/parameter-decorator/actual.js b/test/fixtures/experimental/decorators/method-parameter-decorator/actual.js similarity index 100% rename from test/fixtures/experimental/decorators/parameter-decorator/actual.js rename to test/fixtures/experimental/decorators/method-parameter-decorator/actual.js diff --git a/test/fixtures/experimental/decorators/parameter-decorator/expected.json b/test/fixtures/experimental/decorators/method-parameter-decorator/expected.json similarity index 100% rename from test/fixtures/experimental/decorators/parameter-decorator/expected.json rename to test/fixtures/experimental/decorators/method-parameter-decorator/expected.json