diff --git a/src/com/google/javascript/jscomp/lint/CheckNoMutatedEs6Exports.java b/src/com/google/javascript/jscomp/lint/CheckNoMutatedEs6Exports.java index 3f702b252bc..43abd0d3425 100644 --- a/src/com/google/javascript/jscomp/lint/CheckNoMutatedEs6Exports.java +++ b/src/com/google/javascript/jscomp/lint/CheckNoMutatedEs6Exports.java @@ -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 {} diff --git a/test/com/google/javascript/jscomp/lint/CheckNoMutatedEs6ExportsTest.java b/test/com/google/javascript/jscomp/lint/CheckNoMutatedEs6ExportsTest.java index 888dbc3131a..d4ceba9f2ca 100644 --- a/test/com/google/javascript/jscomp/lint/CheckNoMutatedEs6ExportsTest.java +++ b/test/com/google/javascript/jscomp/lint/CheckNoMutatedEs6ExportsTest.java @@ -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 {};"); + } }