From 6a82eb5a5c70fc24e3ffa19b8bb91907355ce126 Mon Sep 17 00:00:00 2001 From: Christopher Monsanto Date: Wed, 6 May 2015 02:40:48 -0400 Subject: [PATCH] disallow async constructors -- fixes #1454 --- src/acorn/src/statement.js | 2 +- .../transformation/validation/async-constructor/actual.js | 1 + .../transformation/validation/async-constructor/options.json | 4 ++++ 3 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 test/core/fixtures/transformation/validation/async-constructor/actual.js create mode 100644 test/core/fixtures/transformation/validation/async-constructor/options.json diff --git a/src/acorn/src/statement.js b/src/acorn/src/statement.js index b704512002..23bd66f5f4 100755 --- a/src/acorn/src/statement.js +++ b/src/acorn/src/statement.js @@ -504,7 +504,7 @@ pp.parseClass = function(node, isStatement) { this.parsePropertyName(method) } method.kind = "method" - if (!method.computed && !isGenerator) { + if (!method.computed && !isGenerator && !isAsync) { if (method.key.type === "Identifier") { if (this.type !== tt.parenL && (method.key.name === "get" || method.key.name === "set")) { method.kind = method.key.name diff --git a/test/core/fixtures/transformation/validation/async-constructor/actual.js b/test/core/fixtures/transformation/validation/async-constructor/actual.js new file mode 100644 index 0000000000..70ffb97fb1 --- /dev/null +++ b/test/core/fixtures/transformation/validation/async-constructor/actual.js @@ -0,0 +1 @@ +class X { async constructor() {} } diff --git a/test/core/fixtures/transformation/validation/async-constructor/options.json b/test/core/fixtures/transformation/validation/async-constructor/options.json new file mode 100644 index 0000000000..2aa01942ac --- /dev/null +++ b/test/core/fixtures/transformation/validation/async-constructor/options.json @@ -0,0 +1,4 @@ +{ + "throws": "Illegal kind for constructor method", + "optional": ["es7.asyncFunctions"] +}