Skip to content

Commit

Permalink
When creating JSTypeExpressions, be more specific so that errors are …
Browse files Browse the repository at this point in the history
…easier to track down.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=188558119
  • Loading branch information
tbreisacher authored and blickly committed Mar 12, 2018
1 parent c04e794 commit 6037dc9
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 18 deletions.
31 changes: 16 additions & 15 deletions src/com/google/javascript/jscomp/PolymerClassRewriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
* understood by the compiler.
*/
final class PolymerClassRewriter {

private static final String VIRTUAL_FILE = "<PolymerClassRewriter.java>";
private final AbstractCompiler compiler;
private final int polymerVersion;
private final boolean propertyRenamingEnabled;
Expand Down Expand Up @@ -216,8 +216,8 @@ void rewritePolymerClassDeclaration(
if (!readOnlyProps.isEmpty() || !attributeReflectedProps.isEmpty()) {
JSDocInfoBuilder classInfo = JSDocInfoBuilder.maybeCopyFrom(clazz.getJSDocInfo());
String interfaceName = getInterfaceName(cls);
JSTypeExpression interfaceType = new JSTypeExpression(
new Node(Token.BANG, IR.string(interfaceName)), PolymerPass.VIRTUAL_FILE);
JSTypeExpression interfaceType =
new JSTypeExpression(new Node(Token.BANG, IR.string(interfaceName)), VIRTUAL_FILE);
classInfo.recordImplementedInterface(interfaceType);
clazz.setJSDocInfo(classInfo.build());
}
Expand All @@ -229,18 +229,18 @@ void rewritePolymerClassDeclaration(
compiler.reportChangeToEnclosingScope(stmt);
}

addReturnTypeIfMissing(cls, "is", new JSTypeExpression(IR.string("string"), ""));
addReturnTypeIfMissing(cls, "is", new JSTypeExpression(IR.string("string"), VIRTUAL_FILE));

Node type = new Node(Token.BANG);
Node array = IR.string("Array");
type.addChildToBack(array);
Node arrayTemplateType = new Node(Token.BLOCK, IR.string("string"));
array.addChildToBack(arrayTemplateType);
addReturnTypeIfMissing(cls, "observers", new JSTypeExpression(type, ""));
addReturnTypeIfMissing(cls, "observers", new JSTypeExpression(type, VIRTUAL_FILE));
addReturnTypeIfMissing(
cls,
"properties",
new JSTypeExpression(IR.string(POLYMER_ELEMENT_PROP_CONFIG), ""));
new JSTypeExpression(IR.string(POLYMER_ELEMENT_PROP_CONFIG), VIRTUAL_FILE));

// If property renaming is enabled, wrap the properties object literal
// in a reflection call so that the properties are renamed consistently
Expand Down Expand Up @@ -290,8 +290,8 @@ private void addTypesToFunctions(
Node value = keyNode.getLastChild();
if (value != null && value.isFunction()) {
JSDocInfoBuilder fnDoc = JSDocInfoBuilder.maybeCopyFrom(keyNode.getJSDocInfo());
fnDoc.recordThisType(new JSTypeExpression(
new Node(Token.BANG, IR.string(thisType)), PolymerPass.VIRTUAL_FILE));
fnDoc.recordThisType(
new JSTypeExpression(new Node(Token.BANG, IR.string(thisType)), VIRTUAL_FILE));
keyNode.setJSDocInfo(fnDoc.build());
}
}
Expand All @@ -309,8 +309,8 @@ private void addTypesToFunctions(
}
Node defaultValueKey = defaultValue.getParent();
JSDocInfoBuilder fnDoc = JSDocInfoBuilder.maybeCopyFrom(defaultValueKey.getJSDocInfo());
fnDoc.recordThisType(new JSTypeExpression(
new Node(Token.BANG, IR.string(thisType)), PolymerPass.VIRTUAL_FILE));
fnDoc.recordThisType(
new JSTypeExpression(new Node(Token.BANG, IR.string(thisType)), VIRTUAL_FILE));
fnDoc.recordReturnType(PolymerPassStaticUtils.getTypeFromProperty(property, compiler));
defaultValueKey.setJSDocInfo(fnDoc.build());
}
Expand Down Expand Up @@ -368,14 +368,15 @@ private JSDocInfoBuilder getConstructorDoc(final PolymerClassDefinition cls) {
JSDocInfoBuilder constructorDoc = JSDocInfoBuilder.maybeCopyFrom(cls.constructor.info);
constructorDoc.recordConstructor();

JSTypeExpression baseType = new JSTypeExpression(
new Node(Token.BANG, IR.string(PolymerPassStaticUtils.getPolymerElementType(cls))),
PolymerPass.VIRTUAL_FILE);
JSTypeExpression baseType =
new JSTypeExpression(
new Node(Token.BANG, IR.string(PolymerPassStaticUtils.getPolymerElementType(cls))),
VIRTUAL_FILE);
constructorDoc.recordBaseType(baseType);

String interfaceName = getInterfaceName(cls);
JSTypeExpression interfaceType = new JSTypeExpression(
new Node(Token.BANG, IR.string(interfaceName)), PolymerPass.VIRTUAL_FILE);
JSTypeExpression interfaceType =
new JSTypeExpression(new Node(Token.BANG, IR.string(interfaceName)), VIRTUAL_FILE);
constructorDoc.recordImplementedInterface(interfaceType);

return constructorDoc;
Expand Down
3 changes: 1 addition & 2 deletions src/com/google/javascript/jscomp/PolymerPass.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@
* @author jlklein@google.com (Jeremy Klein)
*/
final class PolymerPass extends AbstractPostOrderCallback implements HotSwapCompilerPass {

static final String VIRTUAL_FILE = "<PolymerPass.java>";
private static final String VIRTUAL_FILE = "<PolymerPass.java>";

private final AbstractCompiler compiler;
private final ImmutableMap<String, String> tagNameMap;
Expand Down
3 changes: 2 additions & 1 deletion src/com/google/javascript/jscomp/PolymerPassStaticUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
* Simple static utility functions shared between the {@link PolymerPass} and its helper classes.
*/
final class PolymerPassStaticUtils {
private static final String VIRTUAL_FILE = "<PolymerPassStaticUtils.java>";

/** @return Whether the call represents a call to the Polymer function. */
@VisibleForTesting
Expand Down Expand Up @@ -161,7 +162,7 @@ static JSTypeExpression getTypeFromProperty(
return null;
}

return new JSTypeExpression(typeNode, PolymerPass.VIRTUAL_FILE);
return new JSTypeExpression(typeNode, VIRTUAL_FILE);
}

/**
Expand Down

0 comments on commit 6037dc9

Please sign in to comment.