From 5ec9f784937e8bfeec46194ff8ba0cd191e5d48b Mon Sep 17 00:00:00 2001 From: Sebastian McKenzie Date: Wed, 5 Aug 2015 23:22:31 +0100 Subject: [PATCH] fix patterns with async keys - fixes #2171 --- src/parser/expression.js | 7 +- .../experimental/async-functions/options.json | 5 + .../async-functions/pattern/actual.js | 1 + .../async-functions/pattern/expected.json | 185 ++++++++++++++++++ 4 files changed, 195 insertions(+), 3 deletions(-) create mode 100644 test/fixtures/experimental/async-functions/options.json create mode 100644 test/fixtures/experimental/async-functions/pattern/actual.js create mode 100644 test/fixtures/experimental/async-functions/pattern/expected.json diff --git a/src/parser/expression.js b/src/parser/expression.js index 194e5a61b2..1b9e835afe 100644 --- a/src/parser/expression.js +++ b/src/parser/expression.js @@ -587,10 +587,11 @@ pp.parseObj = function (isPattern, refShorthandDefaultPos) { startPos = this.state.start; startLoc = this.state.startLoc; } - if (!isPattern) + if (!isPattern) { isGenerator = this.eat(tt.star); - if (this.options.features["es7.asyncFunctions"] && this.isContextual("async")) { - if (isGenerator || isPattern) this.unexpected(); + } + if (!isPattern && this.options.features["es7.asyncFunctions"] && this.isContextual("async")) { + if (isGenerator) this.unexpected(); var asyncId = this.parseIdent(); if (this.match(tt.colon) || this.match(tt.parenL)) { prop.key = asyncId; diff --git a/test/fixtures/experimental/async-functions/options.json b/test/fixtures/experimental/async-functions/options.json new file mode 100644 index 0000000000..2fce804177 --- /dev/null +++ b/test/fixtures/experimental/async-functions/options.json @@ -0,0 +1,5 @@ +{ + "features": { + "es7.asyncFunctions": true + } +} diff --git a/test/fixtures/experimental/async-functions/pattern/actual.js b/test/fixtures/experimental/async-functions/pattern/actual.js new file mode 100644 index 0000000000..2c4702e9cb --- /dev/null +++ b/test/fixtures/experimental/async-functions/pattern/actual.js @@ -0,0 +1 @@ +const {async} = require('../lang/task') diff --git a/test/fixtures/experimental/async-functions/pattern/expected.json b/test/fixtures/experimental/async-functions/pattern/expected.json new file mode 100644 index 0000000000..6a7dde062f --- /dev/null +++ b/test/fixtures/experimental/async-functions/pattern/expected.json @@ -0,0 +1,185 @@ +{ + "type": "File", + "start": 0, + "end": 39, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 39 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 39, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 39 + } + }, + "sourceType": "script", + "body": [ + { + "type": "VariableDeclaration", + "start": 0, + "end": 39, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 39 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 6, + "end": 39, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 39 + } + }, + "id": { + "type": "ObjectPattern", + "start": 6, + "end": 13, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 13 + } + }, + "properties": [ + { + "type": "Property", + "start": 7, + "end": 12, + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 12 + } + }, + "method": false, + "shorthand": true, + "computed": false, + "key": { + "type": "Identifier", + "start": 7, + "end": 12, + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 12 + } + }, + "name": "async" + }, + "kind": "init", + "value": { + "type": "Identifier", + "start": 7, + "end": 12, + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 12 + } + }, + "name": "async" + } + } + ] + }, + "init": { + "type": "CallExpression", + "start": 16, + "end": 39, + "loc": { + "start": { + "line": 1, + "column": 16 + }, + "end": { + "line": 1, + "column": 39 + } + }, + "callee": { + "type": "Identifier", + "start": 16, + "end": 23, + "loc": { + "start": { + "line": 1, + "column": 16 + }, + "end": { + "line": 1, + "column": 23 + } + }, + "name": "require" + }, + "arguments": [ + { + "type": "Literal", + "start": 24, + "end": 38, + "loc": { + "start": { + "line": 1, + "column": 24 + }, + "end": { + "line": 1, + "column": 38 + } + }, + "value": "../lang/task", + "rawValue": "../lang/task", + "raw": "'../lang/task'" + } + ] + } + } + ], + "kind": "const" + } + ] + } +} \ No newline at end of file