Skip to content
This repository has been archived by the owner on May 19, 2018. It is now read-only.

Commit

Permalink
Check for duplicate named exports in exported destructuring assignments
Browse files Browse the repository at this point in the history
  • Loading branch information
kaicataldo committed Sep 24, 2016
1 parent 44d44a2 commit 6800abc
Show file tree
Hide file tree
Showing 31 changed files with 2,291 additions and 70 deletions.
20 changes: 17 additions & 3 deletions src/parser/statement.js
Original file line number Diff line number Diff line change
Expand Up @@ -923,9 +923,7 @@ pp.checkExport = function (node, checkNames, isDefault) {
this.checkDuplicateExports(node, node.declaration.id.name, isDefault);
} else if (node.declaration.type === "VariableDeclaration") {
for (let declaration of node.declaration.declarations) {
if (declaration.id.name) {
this.checkDuplicateExports(declaration, declaration.id.name, isDefault);
}
this.checkDeclaration(declaration.id, isDefault);
}
}
}
Expand All @@ -940,6 +938,22 @@ pp.checkExport = function (node, checkNames, isDefault) {
}
};

pp.checkDeclaration = function(node, isDefault) {
if (node.type === "ObjectPattern") {
for (let prop of node.properties) {
this.checkDeclaration(prop, isDefault);
}
} else if (node.type === "ArrayPattern") {
for (let elem of node.elements) {
this.checkDeclaration(elem, isDefault);
}
} else if (node.type === "ObjectProperty") {
this.checkDeclaration(node.value, isDefault);
} else if (node.type === "Identifier") {
this.checkDuplicateExports(node, node.name, isDefault);
}
};

pp.checkDuplicateExports = function(node, name, isDefault) {
if (this.state.exportedIdentifiers.indexOf(name) > -1) {
this.raiseDuplicateExportError(node, name, isDefault);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,11 @@
export const { rhythm } = typography;
export const { TypographyStyle } = typography;
export const { foo } = bar;
export const { foo: foo2 } = bar;
export const { foo: { baz } } = bar;
export const { foo: { baz: { qux } } } = bar;
export const { foo: { baz: { qux2 } }, foo3 } = bar;
export const [foo4] = bar;
export const [[baz2]] = bar;
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;
Loading

0 comments on commit 6800abc

Please sign in to comment.