Skip to content

Commit d58c251

Browse files
Closure Teamcopybara-github
authored andcommitted
Fixed COMPUTED_FIELD_DEF to be deleted without any additional check in the RemoveNonDeclarations pass.
In the RemoveNonDeclarations `shouldTraverse()` method, the cases for `COMPUTED_PROPERTIES` and `COMPUTED_FIELD_DEF` fell into the same check which caused unassigned `COMPUTED_FIELD_DEF` to throw a null pointer exception. We now separate `COMPUTED_FIELD_DEF` into it's own check that will instantly delete the `COMPUTED_FIELD_DEF`. PiperOrigin-RevId: 551238929
1 parent f38ba47 commit d58c251

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

src/com/google/javascript/jscomp/ijs/ConvertToTypedInterface.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,11 +201,13 @@ public boolean shouldTraverse(NodeTraversal t, Node n, Node parent) {
201201
return false;
202202
}
203203
case COMPUTED_PROP:
204-
case COMPUTED_FIELD_DEF:
205204
if (!NodeUtil.isLhsByDestructuring(n.getSecondChild())) {
206205
NodeUtil.deleteNode(n, t.getCompiler());
207206
}
208207
return false;
208+
case COMPUTED_FIELD_DEF:
209+
NodeUtil.deleteNode(n, t.getCompiler());
210+
return false;
209211
case THROW:
210212
case RETURN:
211213
case BREAK:

test/com/google/javascript/jscomp/ijs/ConvertToTypedInterfaceTest.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,20 @@ public void testEmptyClass() {
7373
test("class x {;}", "class x {}");
7474
}
7575

76+
@Test
77+
public void testComputedFieldNoRHS() {
78+
test(
79+
lines(
80+
"const s = Symbol();", //
81+
"class Foo { ",
82+
" [s]",
83+
"}"),
84+
lines(
85+
"const s = Symbol();", //
86+
"class Foo {",
87+
"}"));
88+
}
89+
7690
@Test
7791
public void testSuperClassFields() {
7892
test(

0 commit comments

Comments
 (0)