Skip to content

Commit

Permalink
Don't rename @define's in ProcessEs6Modules
Browse files Browse the repository at this point in the history
Treat @define's as truly global definitions and don't mangle the names.

Fixes google#1601.
  • Loading branch information
Dominator008 committed Mar 1, 2016
1 parent 03c62b0 commit 93315a6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/com/google/javascript/jscomp/ProcessEs6Modules.java
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,11 @@ public void visit(NodeTraversal t, Node n, Node parent) {

Var var = t.getScope().getVar(name);
if (var != null && var.isGlobal()) {
JSDocInfo varInfo = NodeUtil.getBestJSDocInfo(var.getNameNode());
// Assume @define's are truly global and don't mangle them.
if (varInfo != null && varInfo.isDefine()) {
return;
}
// Avoid polluting the global namespace.
n.setString(name + "$$" + suffix);
n.setOriginalName(name);
Expand Down
10 changes: 10 additions & 0 deletions test/com/google/javascript/jscomp/ProcessEs6ModulesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -606,4 +606,14 @@ public void testNamespaceImports() {
testModules("import * as Foo from 'goog:other.Foo';",
ProcessEs6Modules.NAMESPACE_IMPORT_CANNOT_USE_STAR);
}

public void testDefine() {
testModules(
LINE_JOINER.join(
"import name from 'other';",
"/** @define {boolean} */ var FOO = true; use(FOO);"),
LINE_JOINER.join(
"goog.require('module$other');",
"/** @define {boolean} */ var FOO = true; use(FOO);"));
}
}

0 comments on commit 93315a6

Please sign in to comment.