Skip to content

Commit cbcaded

Browse files
lauraharkercopybara-github
authored andcommitted
Fix ClosureRewriteModule crash on unrecognized goog.requireDynamic
PiperOrigin-RevId: 617977488
1 parent 29c1f16 commit cbcaded

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -964,8 +964,9 @@ private void recordGoogRequireDynamic(NodeTraversal t, Node call) {
964964
if (!rewriteState.containsModule(namespaceId)) {
965965
unrecognizedRequires.add(
966966
new UnrecognizedRequire(call, namespaceId, /* mustBeOrdered= */ false));
967+
} else {
968+
this.googRequireDynamicCalls.add(call);
967969
}
968-
this.googRequireDynamicCalls.add(call);
969970
}
970971

971972
private void recordGoogModuleGet(NodeTraversal t, Node call) {

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

+17
Original file line numberDiff line numberDiff line change
@@ -1282,6 +1282,23 @@ public void testGoogRequireDynamic_then_name() {
12821282
"}")));
12831283
}
12841284

1285+
@Test
1286+
public void testGoogRequireDynamic_then_missingSources() {
1287+
test(
1288+
srcs(
1289+
lines(
1290+
"async function test() {", //
1291+
" /** @suppress {missingSourcesWarnings} */",
1292+
" goog.requireDynamic('a.b.c').then((foo) => {console.log(foo.Foo);});",
1293+
"}")),
1294+
expected(
1295+
lines(
1296+
"async function test() {", //
1297+
" /** @suppress {missingSourcesWarnings} */",
1298+
" null.then((foo) => {console.log(foo.Foo);});",
1299+
"}")));
1300+
}
1301+
12851302
@Test
12861303
public void testRequireDynamic_illegal_await_lhs() {
12871304
testError(

0 commit comments

Comments
 (0)