Skip to content

Commit

Permalink
Fix checking of duplicate export name for star exports
Browse files Browse the repository at this point in the history
FIX: Fix an issue where duplicate quoted export names in `export *` syntax
were incorrectly checked.

Closes #1093
  • Loading branch information
marijnh committed Jan 3, 2022
1 parent 0ff68de commit 84eda6b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
10 changes: 6 additions & 4 deletions acorn/src/statement.js
Original file line number Diff line number Diff line change
Expand Up @@ -841,7 +841,7 @@ pp.parseExport = function(node, exports) {
if (this.options.ecmaVersion >= 11) {
if (this.eatContextual("as")) {
node.exported = this.parseModuleExportName()
this.checkExport(exports, node.exported.name, this.lastTokStart)
this.checkExport(exports, node.exported, this.lastTokStart)
} else {
node.exported = null
}
Expand Down Expand Up @@ -875,7 +875,7 @@ pp.parseExport = function(node, exports) {
if (node.declaration.type === "VariableDeclaration")
this.checkVariableExport(exports, node.declaration.declarations)
else
this.checkExport(exports, node.declaration.id.name, node.declaration.id.start)
this.checkExport(exports, node.declaration.id, node.declaration.id.start)
node.specifiers = []
node.source = null
} else { // export { x, y as z } [from '...']
Expand Down Expand Up @@ -905,6 +905,8 @@ pp.parseExport = function(node, exports) {

pp.checkExport = function(exports, name, pos) {
if (!exports) return
if (typeof name !== "string")
name = name.type === "Identifier" ? name.name : name.value
if (hasOwn(exports, name))
this.raiseRecoverable(pos, "Duplicate export '" + name + "'")
exports[name] = true
Expand All @@ -913,7 +915,7 @@ pp.checkExport = function(exports, name, pos) {
pp.checkPatternExport = function(exports, pat) {
let type = pat.type
if (type === "Identifier")
this.checkExport(exports, pat.name, pat.start)
this.checkExport(exports, pat, pat.start)
else if (type === "ObjectPattern")
for (let prop of pat.properties)
this.checkPatternExport(exports, prop)
Expand Down Expand Up @@ -963,7 +965,7 @@ pp.parseExportSpecifiers = function(exports) {
node.exported = this.eatContextual("as") ? this.parseModuleExportName() : node.local
this.checkExport(
exports,
node.exported[node.exported.type === "Identifier" ? "name" : "value"],
node.exported,
node.exported.start
)
nodes.push(this.finishNode(node, "ExportSpecifier"))
Expand Down
3 changes: 3 additions & 0 deletions test/tests-module-string-names.js
Original file line number Diff line number Diff line change
Expand Up @@ -337,3 +337,6 @@ testFail(
"Duplicate export 'foo' (1:47)",
{ sourceType: "module", ecmaVersion: 13 }
);

test('export * as "a" from "mod1"\nexport * as "b" from "mod2"', {},
{ sourceType: "module", ecmaVersion: 13 });

0 comments on commit 84eda6b

Please sign in to comment.