From 952d50faf9e34943c60b68c6e8bfd4ecb367e827 Mon Sep 17 00:00:00 2001 From: Daniel Tschinder Date: Thu, 22 Sep 2016 22:00:39 +0200 Subject: [PATCH] Make exportIdentifiers and array so that base object properties are not accounted (#137) --- src/parser/statement.js | 4 +- src/tokenizer/state.js | 4 +- .../duplicate-named-export-builtin/actual.js | 1 + .../expected.json | 102 ++++++++++++++++++ 4 files changed, 107 insertions(+), 4 deletions(-) create mode 100644 test/fixtures/es2015/modules/duplicate-named-export-builtin/actual.js create mode 100644 test/fixtures/es2015/modules/duplicate-named-export-builtin/expected.json diff --git a/src/parser/statement.js b/src/parser/statement.js index 77879ecc5c..7687b93677 100644 --- a/src/parser/statement.js +++ b/src/parser/statement.js @@ -939,10 +939,10 @@ pp.checkExport = function (node, checkNames, isDefault) { }; pp.checkDuplicateExports = function(node, name, isDefault) { - if (this.state.exportedIdentifiers[name]) { + if (this.state.exportedIdentifiers.indexOf(name) > -1) { this.raiseDuplicateExportError(node, name, isDefault); } - this.state.exportedIdentifiers[name] = true; + this.state.exportedIdentifiers.push(name); }; pp.raiseDuplicateExportError = function(node, name, isDefault) { diff --git a/src/tokenizer/state.js b/src/tokenizer/state.js index 77c2a7407e..956b218eae 100644 --- a/src/tokenizer/state.js +++ b/src/tokenizer/state.js @@ -43,7 +43,7 @@ export default class State { this.containsEsc = this.containsOctal = false; this.octalPosition = null; - this.exportedIdentifiers = {}; + this.exportedIdentifiers = []; return this; } @@ -123,7 +123,7 @@ export default class State { // Names of exports store. `default` is stored as a name for both // `export default foo;` and `export { foo as default };`. - exportedIdentifiers: {[id:string]: boolean}; + exportedIdentifiers: Array; curPosition() { return new Position(this.curLine, this.pos - this.lineStart); diff --git a/test/fixtures/es2015/modules/duplicate-named-export-builtin/actual.js b/test/fixtures/es2015/modules/duplicate-named-export-builtin/actual.js new file mode 100644 index 0000000000..01d2b22e0b --- /dev/null +++ b/test/fixtures/es2015/modules/duplicate-named-export-builtin/actual.js @@ -0,0 +1 @@ +export { toString }; diff --git a/test/fixtures/es2015/modules/duplicate-named-export-builtin/expected.json b/test/fixtures/es2015/modules/duplicate-named-export-builtin/expected.json new file mode 100644 index 0000000000..97e6e97438 --- /dev/null +++ b/test/fixtures/es2015/modules/duplicate-named-export-builtin/expected.json @@ -0,0 +1,102 @@ +{ + "type": "File", + "start": 0, + "end": 20, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 20 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 20, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 20 + } + }, + "sourceType": "module", + "body": [ + { + "type": "ExportNamedDeclaration", + "start": 0, + "end": 20, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 20 + } + }, + "declaration": null, + "specifiers": [ + { + "type": "ExportSpecifier", + "start": 9, + "end": 17, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 17 + } + }, + "local": { + "type": "Identifier", + "start": 9, + "end": 17, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 17 + }, + "identifierName": "toString" + }, + "name": "toString" + }, + "exported": { + "type": "Identifier", + "start": 9, + "end": 17, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 17 + }, + "identifierName": "toString" + }, + "name": "toString" + } + } + ], + "source": null + } + ], + "directives": [] + } +} \ No newline at end of file