Skip to content

Commit cd82e21

Browse files
lauraharkercopybara-github
authored andcommitted
Add test for renaming collisions with goog.exportSymbol-generated names
PiperOrigin-RevId: 715496306
1 parent 7f8af46 commit cd82e21

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

test/com/google/javascript/jscomp/integration/TypedAstIntegrationTest.java

+23
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,29 @@ public void exportAnnotationOnProperty_ignoredInUnusedTypedAstShard() throws IOE
368368
"alert(new a());"));
369369
}
370370

371+
@Test
372+
public void exportSymbol_preventsVariableRenamingCollision() throws IOException {
373+
SourceFile lib1 =
374+
code("/** @fileoverview @suppress {checkTypes} */ var goog, x; goog.exportSymbol('a', x);");
375+
precompileLibrary(lib1);
376+
377+
CompilerOptions options = new CompilerOptions();
378+
options.setEmitUseStrict(false);
379+
options.setClosurePass(true);
380+
options.setVariableRenaming(VariableRenamingPolicy.ALL);
381+
382+
Compiler compiler = compileTypedAstShards(options);
383+
384+
assertCompiledCodeEquals(
385+
// TODO - b/389980981: don't reuse the name 'a' in variable renaming 'a' because it's also
386+
// used in the goog.exportSymbol call.
387+
compiler,
388+
lines(
389+
"var a;", //
390+
"var b;",
391+
"a.exportSymbol('a', b);"));
392+
}
393+
371394
@Test
372395
public void lateFulfilledGlobalVariableIsRenamed() throws IOException {
373396
SourceFile lib1 =

0 commit comments

Comments
 (0)