Skip to content

Commit 26781e8

Browse files
rishipalcopybara-github
authored andcommitted
Generate unique names for $jscomp$arguments variables to preserve normalization
This enables preserving normalization (i.e. globally unique names) even when we move this pass post-normalization. PiperOrigin-RevId: 623357035
1 parent fbd8091 commit 26781e8

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

src/com/google/javascript/jscomp/Es6RewriteArrowFunction.java

+6-2
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,8 @@ private void addVarDeclarations(NodeTraversal t, ThisAndArgumentsContext context
137137
}
138138

139139
if (context.needsArgumentsVar) {
140-
Node argumentsVar = astFactory.createArgumentsAliasDeclaration(ARGUMENTS_VAR);
140+
Node argumentsVar =
141+
astFactory.createArgumentsAliasDeclaration(ARGUMENTS_VAR + "$" + context.uniqueId);
141142
NodeUtil.addFeatureToScript(t.getCurrentScript(), Feature.CONST_DECLARATIONS, compiler);
142143
scopeBody.addChildToFront(argumentsVar);
143144

@@ -248,7 +249,10 @@ public void visit(NodeTraversal t, Node n, Node parent) {
248249
} else if (n.isName() && n.getString().equals("arguments")) {
249250
context.setNeedsArgumentsVar();
250251

251-
Node name = astFactory.createName(ARGUMENTS_VAR, AstFactory.type(n)).srcref(n);
252+
Node name =
253+
astFactory
254+
.createName(ARGUMENTS_VAR + "$" + context.uniqueId, AstFactory.type(n))
255+
.srcref(n);
252256
if (compiler.getOptions().preservesDetailedSourceInfo()) {
253257
name.setOriginalName("arguments");
254258
}

test/com/google/javascript/jscomp/CodePrinterTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -3845,7 +3845,7 @@ public void testEs6ArrowFunctionSetsOriginalNameForArguments() {
38453845
String code = "(x)=>{arguments[0]();}";
38463846
String expectedCode =
38473847
""
3848-
+ "var $jscomp$arguments = arguments;\n"
3848+
+ "var $jscomp$arguments$3556498$0 = arguments;\n"
38493849
+ "(function(x) {\n"
38503850
+ " arguments[0]();\n"
38513851
+ "});\n";

test/com/google/javascript/jscomp/Es6RewriteArrowFunctionTest.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -198,8 +198,8 @@ public void testCapturingEnclosingFunctionArgumentsInArrow() {
198198
lines("function f() {", " var x = () => arguments;", "}"),
199199
lines(
200200
"function f() {",
201-
" const $jscomp$arguments = arguments;",
202-
" var x = function() { return $jscomp$arguments; };",
201+
" const $jscomp$arguments$m1146332801$1 = arguments;",
202+
" var x = function() { return $jscomp$arguments$m1146332801$1; };",
203203
"}"));
204204
}
205205

0 commit comments

Comments
 (0)