Skip to content

Commit

Permalink
Fix crash in CheckNoMutatedEs6Exports on 'export default <expression>'
Browse files Browse the repository at this point in the history
Fixes #3453

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=263617675
  • Loading branch information
lauraharker committed Aug 16, 2019
1 parent 195e7ab commit 15b5c7b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,18 @@ private void visitExport(Node export) {
checkState(lhs.isName());
exportedLocalNames.add(lhs.getString());
}
} else if (export.getBooleanProp(Node.EXPORT_DEFAULT)) {
// export default function() {}
// export default function foo() {}
// export default 0;
// Note: default exports may or may not be declarations.
if (!declaration.isClass() && !declaration.isFunction()) {
return;
}
Node nameNode = declaration.getFirstChild();
if (!nameNode.isEmpty() && !nameNode.getString().isEmpty()) {
exportedLocalNames.add(nameNode.getString());
}
} else {
// export function foo() {}
// export class Bar {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,16 @@ public void testMutatedInInnerScopeIsError() {
testWarning("let x = 0; export {x as y}; () => x++;", MUTATED_EXPORT);
testWarning("export function foo() {}; () => foo = 0;", MUTATED_EXPORT);
testWarning("export default function foo() {}; () => foo = 0;", MUTATED_EXPORT);
testWarning("export default class Foo {}; () => Foo = 0;", MUTATED_EXPORT);
testWarning("export function foo() { foo = 0; };", MUTATED_EXPORT);
testWarning("export let x = 0; export function foo() { x++; };", MUTATED_EXPORT);
}

@Test
public void testExportDefaultExpressionIsOk() {
testSame("export default 0;");
testSame("export default {prop: 0}");
testSame("export default function() {};");
testSame("export default class {};");
}
}

0 comments on commit 15b5c7b

Please sign in to comment.