Skip to content

Commit 7c87bb1

Browse files
lauraharkercopybara-github
authored andcommitted
Remove legacy @closureUnaware AST structure support
PiperOrigin-RevId: 850143647
1 parent 9f43a4d commit 7c87bb1

File tree

5 files changed

+7
-67
lines changed

5 files changed

+7
-67
lines changed

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

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1034,13 +1034,7 @@ private void validateShadowContentIfPresent(Node n) {
10341034
}
10351035
Node shadowJsCall = exprResult.getOnlyChild();
10361036
if (!shadowJsCall.isCall()) {
1037-
1038-
// TODO: b/421971366 - remove this special allowance for FUNCTION nodes after cl/830654412
1039-
// is in the compiler release.
1040-
if (!shadowJsCall.isFunction()) {
1041-
violation("Shadow node EXPR_RESULT child is not a function or call", shadowJsCall);
1042-
return;
1043-
}
1037+
violation("Shadow node EXPR_RESULT child is not a call", shadowJsCall);
10441038
return;
10451039
}
10461040
Node shadowJsFunction = shadowJsCall.getLastChild();

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

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -207,13 +207,8 @@ protected void add(Node node, Context context, boolean printComments) {
207207
if (shadow != null) {
208208
Node script = shadow.getOnlyChild();
209209
Node sinkCall = script.getOnlyChild().getOnlyChild();
210-
if (sinkCall.isCall()) {
211-
add(sinkCall.getLastChild(), context, printComments);
212-
} else {
213-
// TODO: b/421971366 - delete this branch once cl/830654412 is in the release.
214-
checkState(sinkCall.isFunction(), sinkCall);
215-
add(sinkCall, context, printComments);
216-
}
210+
checkState(sinkCall.isCall(), sinkCall);
211+
add(sinkCall.getLastChild(), context, printComments);
217212
return;
218213
}
219214
if (printComments) {

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

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -305,20 +305,14 @@ private void tryUnwrapClosureUnawareShadowedCode(NodeTraversal t, Node n) {
305305
}
306306

307307
// ROOT -> SCRIPT -> EXPR_RESULT -> CALL -> FUNCTION
308-
// or, until cl/830654412 is fully released:
309-
// ROOT -> SCRIPT -> EXPR_RESULT -> FUNCTION
310308
Node shadowScript = shadowAstRoot.getOnlyChild();
311309
checkState(shadowScript.isScript(), shadowScript);
312310
checkState(shadowScript.hasOneChild(), shadowScript);
313311
Node exprResult = shadowScript.getOnlyChild();
314312
checkState(exprResult.isExprResult(), exprResult);
315-
Node originalCodeFunction;
316-
if (exprResult.getFirstChild().isCall()) {
317-
originalCodeFunction = exprResult.getFirstChild().getLastChild();
318-
} else {
319-
// TODO: b/421971366 - delete this branch once cl/830654412 is released.
320-
originalCodeFunction = exprResult.getFirstChild();
321-
}
313+
Node callNode = exprResult.getOnlyChild();
314+
checkState(callNode.isCall(), callNode);
315+
Node originalCodeFunction = callNode.getLastChild();
322316
checkState(originalCodeFunction.isFunction(), originalCodeFunction);
323317
originalCodeFunction.detach();
324318
n.replaceWith(originalCodeFunction);

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

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1761,7 +1761,7 @@ public void testShadowContent_validatesSingularExpectedStructure() {
17611761
expectInvalid(f, Check.STATEMENT, "Shadow SCRIPT node child is not an expr result node");
17621762

17631763
shadowHost.setClosureUnawareShadow(IR.root(this.parseValidScript("(x++)").detach()));
1764-
expectInvalid(f, Check.STATEMENT, "Shadow node EXPR_RESULT child is not a function or call");
1764+
expectInvalid(f, Check.STATEMENT, "Shadow node EXPR_RESULT child is not a call");
17651765

17661766
shadowHost.setClosureUnawareShadow(IR.root(this.parseValidScript("x()").detach()));
17671767
expectInvalid(f, Check.STATEMENT, "Shadow node CALL child is not a function");
@@ -1771,36 +1771,6 @@ public void testShadowContent_validatesSingularExpectedStructure() {
17711771
expectValid(f, Check.STATEMENT);
17721772
}
17731773

1774-
@Test
1775-
public void testShadowContent_validatesSingularExpectedStructure_legacyStructure() {
1776-
// TODO: b/421971366 - delete this test case once cl/830654412 is in the release.
1777-
// Since we're building the AST by hand, there won't be any types on it.
1778-
typeInfoValidationMode = TypeInfoValidation.NONE;
1779-
1780-
Node shadowHost = IR.name("f");
1781-
Node f = IR.exprResult(shadowHost);
1782-
expectValid(f, Check.STATEMENT);
1783-
1784-
shadowHost.setClosureUnawareShadow(IR.name("x"));
1785-
expectInvalid(f, Check.STATEMENT, "Shadow reference node is not a ROOT node");
1786-
1787-
shadowHost.setClosureUnawareShadow(IR.root());
1788-
expectInvalid(f, Check.STATEMENT, "Shadow root node's child is not a script node");
1789-
1790-
shadowHost.setClosureUnawareShadow(
1791-
IR.root(IR.script(IR.exprResult(IR.name("x")), IR.exprResult(IR.name("y")))));
1792-
expectInvalid(f, Check.STATEMENT, "Shadow SCRIPT node child has more than one child");
1793-
1794-
shadowHost.setClosureUnawareShadow(IR.root(this.parseValidScript("function foo(){}").detach()));
1795-
expectInvalid(f, Check.STATEMENT, "Shadow SCRIPT node child is not an expr result node");
1796-
1797-
shadowHost.setClosureUnawareShadow(IR.root(this.parseValidScript("(x++)").detach()));
1798-
expectInvalid(f, Check.STATEMENT, "Shadow node EXPR_RESULT child is not a function or call");
1799-
1800-
shadowHost.setClosureUnawareShadow(IR.root(this.parseValidScript("(function(){})").detach()));
1801-
expectValid(f, Check.STATEMENT);
1802-
}
1803-
18041774
@Test
18051775
public void checkRequiredInlinings_failsWithRemainingRequiredInlinings() {
18061776
// Write a reference to a function that required inlining. We need an enclosing statement

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

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4557,19 +4557,6 @@ public void testPrintsContentOfClosureUnawareShadow() {
45574557
.isEqualTo("function(){}");
45584558
}
45594559

4560-
@Test
4561-
public void testPrintsContentOfClosureUnawareShadow_legacyStructure() {
4562-
// TODO: b/421971366 - delete this test case once cl/830654412 is in the release.
4563-
Node shadowHost = IR.name("SHADOW");
4564-
AstFactory astFactory = new Compiler().createAstFactoryWithoutTypes();
4565-
Node closureUnawareFn = astFactory.createEmptyFunction(AstFactory.type(StandardColors.UNKNOWN));
4566-
shadowHost.setClosureUnawareShadow(IR.root(IR.script(IR.exprResult(closureUnawareFn))));
4567-
4568-
assertThat(
4569-
new CodePrinter.Builder(shadowHost).setCompilerOptions(new CompilerOptions()).build())
4570-
.isEqualTo("function(){}");
4571-
}
4572-
45734560
private void checkWithOriginalName(
45744561
String code, String expectedCode, CompilerOptions compilerOptions) {
45754562
compilerOptions.setCheckSymbols(true);

0 commit comments

Comments
 (0)