Skip to content

Commit 7c89590

Browse files
lauraharkercopybara-github
authored andcommitted
Add goog.loadModule CompilerInput tests & make DepsFinder closer to regex parser
DepsFinder now doesn't mark inputs containing a goog.loadModule as an actual "goog.module", to match the regex parser. It also gives a better error message when encountering a goog.loadModule with a string literal argument. PiperOrigin-RevId: 505822642
1 parent 3b29b2d commit 7c89590

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,11 @@ void visitSubtree(Node n, @Nullable Node parent) {
435435
Node argument = n.getLastChild();
436436
switch (callee.getString()) {
437437
case "module":
438-
loadFlags.put("module", "goog");
438+
// only mark as a goog.module if this is not bundled, e.g.
439+
// goog.loadModule(function(exports) {"use strict";goog.module('Foo');
440+
if (parent.isExprResult() && parent.getParent().isModuleBody()) {
441+
loadFlags.put("module", "goog");
442+
}
439443
// Fall-through
440444
case "provide":
441445
if (!argument.isStringLit()) {
@@ -459,7 +463,12 @@ void visitSubtree(Node n, @Nullable Node parent) {
459463
return;
460464

461465
case "loadModule":
462-
// Process the block of the loadModule argument
466+
// Process the block of the loadModule argument if it's a function, as opposed to
467+
// a string.
468+
if (argument.isStringLit()) {
469+
throw new IllegalArgumentException(
470+
"Unsupported parse of goog.loadModule with string literal");
471+
}
463472
n = argument.getLastChild();
464473
break;
465474

0 commit comments

Comments
 (0)