Skip to content

Commit

Permalink
Extend ClosureRewriteModule to handle goog.requireType calls.
Browse files Browse the repository at this point in the history
From the perspective of ClosureRewriteModule, goog.requireType and goog.require are identical, except that a goog.requireType is allowed to reference a later module.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=213523036
  • Loading branch information
tjgq committed Sep 19, 2018
1 parent 0bbdd5e commit 81170fb
Show file tree
Hide file tree
Showing 2 changed files with 373 additions and 209 deletions.
12 changes: 9 additions & 3 deletions src/com/google/javascript/jscomp/ClosureRewriteModule.java
Expand Up @@ -171,6 +171,8 @@ final class ClosureRewriteModule implements HotSwapCompilerPass {
private static final Node GOOG_MODULE_GET = IR.getprop(GOOG_MODULE.cloneTree(), IR.string("get")); private static final Node GOOG_MODULE_GET = IR.getprop(GOOG_MODULE.cloneTree(), IR.string("get"));
private static final Node GOOG_PROVIDE = IR.getprop(IR.name("goog"), IR.string("provide")); private static final Node GOOG_PROVIDE = IR.getprop(IR.name("goog"), IR.string("provide"));
private static final Node GOOG_REQUIRE = IR.getprop(IR.name("goog"), IR.string("require")); private static final Node GOOG_REQUIRE = IR.getprop(IR.name("goog"), IR.string("require"));
private static final Node GOOG_REQUIRETYPE =
IR.getprop(IR.name("goog"), IR.string("requireType"));


private final AbstractCompiler compiler; private final AbstractCompiler compiler;
private final PreprocessorSymbolTable preprocessorSymbolTable; private final PreprocessorSymbolTable preprocessorSymbolTable;
Expand Down Expand Up @@ -372,7 +374,9 @@ public boolean shouldTraverse(NodeTraversal t, Node n, Node parent) {
} else if (method.matchesQualifiedName(GOOG_PROVIDE)) { } else if (method.matchesQualifiedName(GOOG_PROVIDE)) {
recordGoogProvide(t, n); recordGoogProvide(t, n);
} else if (method.matchesQualifiedName(GOOG_REQUIRE)) { } else if (method.matchesQualifiedName(GOOG_REQUIRE)) {
recordGoogRequire(t, n, true /** mustBeOrdered */); recordGoogRequire(t, n, /* mustBeOrdered= */ true);
} else if (method.matchesQualifiedName(GOOG_REQUIRETYPE)) {
recordGoogRequire(t, n, /* mustBeOrdered= */ false);
} else if (method.matchesQualifiedName(GOOG_FORWARDDECLARE) && !parent.isExprResult()) { } else if (method.matchesQualifiedName(GOOG_FORWARDDECLARE) && !parent.isExprResult()) {
recordGoogForwardDeclare(t, n); recordGoogForwardDeclare(t, n);
} else if (method.matchesQualifiedName(GOOG_MODULE_GET)) { } else if (method.matchesQualifiedName(GOOG_MODULE_GET)) {
Expand Down Expand Up @@ -451,7 +455,8 @@ public boolean shouldTraverse(NodeTraversal t, Node n, Node parent) {
updateGoogModule(n); updateGoogModule(n);
} else if (method.matchesQualifiedName(GOOG_MODULE_DECLARELEGACYNAMESPACE)) { } else if (method.matchesQualifiedName(GOOG_MODULE_DECLARELEGACYNAMESPACE)) {
updateGoogDeclareLegacyNamespace(n); updateGoogDeclareLegacyNamespace(n);
} else if (method.matchesQualifiedName(GOOG_REQUIRE)) { } else if (method.matchesQualifiedName(GOOG_REQUIRE)
|| method.matchesQualifiedName(GOOG_REQUIRETYPE)) {
updateGoogRequire(t, n); updateGoogRequire(t, n);
} else if (method.matchesQualifiedName(GOOG_FORWARDDECLARE) && !parent.isExprResult()) { } else if (method.matchesQualifiedName(GOOG_FORWARDDECLARE) && !parent.isExprResult()) {
updateGoogForwardDeclare(t, n); updateGoogForwardDeclare(t, n);
Expand Down Expand Up @@ -1251,7 +1256,8 @@ private void maybeUpdateTopLevelName(NodeTraversal t, Node nameNode) {
&& nameNode.getParent().isStringKey() && nameNode.getParent().isStringKey()
&& nameNode.getGrandparent().isObjectPattern()) { && nameNode.getGrandparent().isObjectPattern()) {
Node destructuringLhsNode = nameNode.getGrandparent().getParent(); Node destructuringLhsNode = nameNode.getGrandparent().getParent();
if (isCallTo(destructuringLhsNode.getLastChild(), GOOG_REQUIRE)) { if (isCallTo(destructuringLhsNode.getLastChild(), GOOG_REQUIRE)
|| isCallTo(destructuringLhsNode.getLastChild(), GOOG_REQUIRETYPE)) {
return; return;
} }
} }
Expand Down

0 comments on commit 81170fb

Please sign in to comment.