Skip to content

Commit 1b5da31

Browse files
Closure Teamcopybara-github
authored andcommitted
Teach InlineSimpleMethods to ignore static initialization blocks.
PiperOrigin-RevId: 788541419
1 parent 1f078be commit 1b5da31

File tree

2 files changed

+9
-29
lines changed

2 files changed

+9
-29
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,7 @@ public void visit(NodeTraversal t, Node n, Node parent) {
351351
case COMPUTED_PROP: // complicated
352352
case OBJECT_SPREAD:
353353
case COMPUTED_FIELD_DEF:
354+
case BLOCK: // ES2022 static initialization blocks are never methods.
354355
break;
355356
default:
356357
throw new IllegalStateException("Unexpected " + n.getToken() + " key: " + key);

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

Lines changed: 8 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@
1515
*/
1616
package com.google.javascript.jscomp;
1717

18-
import static com.google.common.truth.Truth.assertThat;
19-
import static org.junit.Assert.assertThrows;
20-
2118
import org.junit.Before;
2219
import org.junit.Test;
2320
import org.junit.runner.RunWith;
@@ -605,32 +602,14 @@ public void testClassFieldDoesntCrash() {
605602

606603
@Test
607604
public void testStaticInitializationBlockDoesntCrash() {
608-
RuntimeException thrownException =
609-
assertThrows(
610-
RuntimeException.class,
611-
() ->
612-
testSame(
613-
"""
614-
class C {
615-
static {
616-
alert('foo');
617-
}
618-
}
619-
"""));
620-
621-
assertThat(thrownException)
622-
.hasMessageThat()
623-
.contains(
624-
"""
625-
INTERNAL COMPILER ERROR.
626-
Please report this problem.
627-
628-
Unexpected CLASS_MEMBERS key: BLOCK 2:9 [source_file: testcode]
629-
Node(CLASS_MEMBERS): testcode:1:0
630-
class C {
631-
Parent(CLASS): testcode:1:0
632-
class C {
633-
""");
605+
testSame(
606+
"""
607+
class C {
608+
static {
609+
alert('foo');
610+
}
611+
}
612+
""");
634613
}
635614

636615
@Test

0 commit comments

Comments
 (0)