From e14f93d1bb967310b7df213c005df3d394fbf00e Mon Sep 17 00:00:00 2001 From: Jeroen Engels Date: Thu, 13 Oct 2016 01:36:08 +0200 Subject: [PATCH] Fix crash when exporting with destructuring and sparse array (#170) * Create reproducible crash when exporting with destructuring and sparse array * Fix crash when exporting with destructuring and sparse array --- src/parser/statement.js | 4 +- .../actual.js | 1 + .../expected.json | 164 +++++++++++++++++- 3 files changed, 162 insertions(+), 7 deletions(-) diff --git a/src/parser/statement.js b/src/parser/statement.js index cb61499172..676920fff4 100644 --- a/src/parser/statement.js +++ b/src/parser/statement.js @@ -943,7 +943,9 @@ pp.checkDeclaration = function(node) { } } else if (node.type === "ArrayPattern") { for (let elem of node.elements) { - this.checkDeclaration(elem); + if (elem) { + this.checkDeclaration(elem); + } } } else if (node.type === "ObjectProperty") { this.checkDeclaration(node.value); diff --git a/test/fixtures/es2015/modules/duplicate-named-export-destructuring/actual.js b/test/fixtures/es2015/modules/duplicate-named-export-destructuring/actual.js index baa04e6386..3440d42c6c 100644 --- a/test/fixtures/es2015/modules/duplicate-named-export-destructuring/actual.js +++ b/test/fixtures/es2015/modules/duplicate-named-export-destructuring/actual.js @@ -9,3 +9,4 @@ export const [{ foo: [baz3] }, { foo2: [baz4] }] = bar; export const { foo: { baz: { qux3 } }, foo2: { baz2: [qux4]} } = bar; export const { foo: { baz: { qux5 } }, foo2: { baz2: [{qux6}]} } = bar; export const { Foo } = bar; +export const { foo: [ ,, qux7 ] } = bar; diff --git a/test/fixtures/es2015/modules/duplicate-named-export-destructuring/expected.json b/test/fixtures/es2015/modules/duplicate-named-export-destructuring/expected.json index e9bb8a3edc..3d8ba60894 100644 --- a/test/fixtures/es2015/modules/duplicate-named-export-destructuring/expected.json +++ b/test/fixtures/es2015/modules/duplicate-named-export-destructuring/expected.json @@ -1,29 +1,29 @@ { "type": "File", "start": 0, - "end": 481, + "end": 522, "loc": { "start": { "line": 1, "column": 0 }, "end": { - "line": 11, - "column": 27 + "line": 12, + "column": 40 } }, "program": { "type": "Program", "start": 0, - "end": 481, + "end": 522, "loc": { "start": { "line": 1, "column": 0 }, "end": { - "line": 11, - "column": 27 + "line": 12, + "column": 40 } }, "sourceType": "module", @@ -2431,6 +2431,158 @@ ], "kind": "const" } + }, + { + "type": "ExportNamedDeclaration", + "start": 482, + "end": 522, + "loc": { + "start": { + "line": 12, + "column": 0 + }, + "end": { + "line": 12, + "column": 40 + } + }, + "specifiers": [], + "source": null, + "declaration": { + "type": "VariableDeclaration", + "start": 489, + "end": 522, + "loc": { + "start": { + "line": 12, + "column": 7 + }, + "end": { + "line": 12, + "column": 40 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 495, + "end": 521, + "loc": { + "start": { + "line": 12, + "column": 13 + }, + "end": { + "line": 12, + "column": 39 + } + }, + "id": { + "type": "ObjectPattern", + "start": 495, + "end": 515, + "loc": { + "start": { + "line": 12, + "column": 13 + }, + "end": { + "line": 12, + "column": 33 + } + }, + "properties": [ + { + "type": "ObjectProperty", + "start": 497, + "end": 513, + "loc": { + "start": { + "line": 12, + "column": 15 + }, + "end": { + "line": 12, + "column": 31 + } + }, + "method": false, + "shorthand": false, + "computed": false, + "key": { + "type": "Identifier", + "start": 497, + "end": 500, + "loc": { + "start": { + "line": 12, + "column": 15 + }, + "end": { + "line": 12, + "column": 18 + } + }, + "name": "foo" + }, + "value": { + "type": "ArrayPattern", + "start": 502, + "end": 513, + "loc": { + "start": { + "line": 12, + "column": 20 + }, + "end": { + "line": 12, + "column": 31 + } + }, + "elements": [ + null, + null, + { + "type": "Identifier", + "start": 507, + "end": 511, + "loc": { + "start": { + "line": 12, + "column": 25 + }, + "end": { + "line": 12, + "column": 29 + } + }, + "name": "qux7" + } + ] + } + } + ] + }, + "init": { + "type": "Identifier", + "start": 518, + "end": 521, + "loc": { + "start": { + "line": 12, + "column": 36 + }, + "end": { + "line": 12, + "column": 39 + } + }, + "name": "bar" + } + } + ], + "kind": "const" + } } ], "directives": []