Skip to content

Commit

Permalink
In externs, allow stub definitions for goog.provided names to not hav…
Browse files Browse the repository at this point in the history
…e an RHS.

This is needed to properly check .i.js files.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=144003191
  • Loading branch information
blickly committed Jan 10, 2017
1 parent f1b85f4 commit 04a053a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/com/google/javascript/jscomp/ProcessClosurePrimitives.java
Expand Up @@ -317,7 +317,7 @@ public void visit(NodeTraversal t, Node n, Node parent) {
break;

case EXPR_RESULT:
handleTypedefDefinition(t, n);
handleStubDefinition(t, n);
break;

case CLASS:
Expand Down Expand Up @@ -486,13 +486,18 @@ private void processDefineCall(NodeTraversal t, Node n, Node parent) {
}

/**
* Handles a typedef definition for a goog.provided name.
* Handles a stub definition for a goog.provided name
* (e.g. a @typedef or a definition from externs)
*
* @param n EXPR_RESULT node.
*/
private void handleTypedefDefinition(
NodeTraversal t, Node n) {
private void handleStubDefinition(NodeTraversal t, Node n) {
if (!t.inGlobalHoistScope()) {
return;
}
JSDocInfo info = n.getFirstChild().getJSDocInfo();
if (t.inGlobalHoistScope() && info != null && info.hasTypedefType()) {
boolean hasStubDefinition = info != null && (n.isFromExterns() || info.hasTypedefType());
if (hasStubDefinition) {
String name = n.getFirstChild().getQualifiedName();
if (name != null) {
ProvidedName pn = providedNames.get(name);
Expand Down
12 changes: 12 additions & 0 deletions test/com/google/javascript/jscomp/IntegrationTest.java
Expand Up @@ -3852,6 +3852,18 @@ public void testEs6OutDoesntCrash() {
test(options, "function f(x) { if (x) var x=5; }", "function f(x) { if (x) x=5; }");
}

public void testExternsProvideIsAllowed() {
CompilerOptions options = createCompilerOptions();
options.setIncrementalChecks(CompilerOptions.IncrementalCheckMode.CHECK_IJS);
options.setClosurePass(true);
options.setCheckTypes(true);

externs = ImmutableList.of(SourceFile.fromCode("<externs>",
"goog.provide('foo.bar'); /** @type {!Array<number>} */ foo.bar;"));

test(options, "", "");
}

// GitHub issue #250: https://github.com/google/closure-compiler/issues/250
public void testInlineStringConcat() {
CompilerOptions options = createCompilerOptions();
Expand Down

0 comments on commit 04a053a

Please sign in to comment.