use of com.google.javascript.jscomp.colors.Color in project closure-compiler by google.
the class NodeUtil method isConstructor.
static boolean isConstructor(Node fnNode) {
if (fnNode == null || !fnNode.isFunction()) {
return false;
}
JSType type = fnNode.getJSType();
JSDocInfo jsDocInfo = getBestJSDocInfo(fnNode);
Color color = fnNode.getColor();
return (type != null && type.isConstructor()) || (jsDocInfo != null && jsDocInfo.isConstructor()) || (color != null && color.isConstructor()) || isEs6Constructor(fnNode);
}
use of com.google.javascript.jscomp.colors.Color in project closure-compiler by google.
the class Es6ConvertSuperConstructorCalls method getTypeOfThisForConstructor.
private AstFactory.Type getTypeOfThisForConstructor(Node constructor) {
checkArgument(constructor.isFunction(), constructor);
final Color constructorType = constructor.getColor();
return constructorType != null && !constructorType.getInstanceColors().isEmpty() ? type(Color.createUnion(constructorType.getInstanceColors())) : type(StandardColors.UNKNOWN);
}
use of com.google.javascript.jscomp.colors.Color in project closure-compiler by google.
the class Es6TemplateLiterals method createCookedStringArray.
private Node createCookedStringArray(Node n) {
Color templateArrayType = astFactory.isAddingColors() ? compiler.getColorRegistry().get(StandardColors.I_TEMPLATE_ARRAY_ID) : null;
Node array = astFactory.createArraylit().setColor(// tighten the type from Array to ITemplateArray
templateArrayType);
for (Node child = n.getFirstChild(); child != null; child = child.getNext()) {
if (child.isTemplateLitString()) {
if (child.getCookedString() != null) {
array.addChildToBack(astFactory.createString(child.getCookedString()));
} else {
// undefined cooked string due to exception in template escapes
array.addChildToBack(astFactory.createVoid(astFactory.createNumber(0)));
}
}
}
return array;
}
use of com.google.javascript.jscomp.colors.Color in project closure-compiler by google.
the class AstFactory method createName.
Node createName(StaticScope scope, String name) {
Node result = IR.name(name);
switch(this.typeMode) {
case JSTYPE:
JSType definitionType = getVarDefinitionNode(scope, name).getJSType();
// TODO(b/149843534): crash instead of defaulting to unknown
result.setJSType(definitionType != null ? definitionType : unknownType);
break;
case COLOR:
Color definitionColor = getVarDefinitionNode(scope, name).getColor();
// TODO(b/149843534): crash instead of defaulting to unknown
result.setColor(definitionColor != null ? definitionColor : StandardColors.UNKNOWN);
break;
case NONE:
break;
}
return result;
}
use of com.google.javascript.jscomp.colors.Color in project closure-compiler by google.
the class Es6RewriteClassTest method testComputedSuper.
@Test
public void testComputedSuper() {
test(lines("/** @unrestricted */", "class Foo {", " ['m']() { return 1; }", "}", "", "/** @unrestricted */", "class Bar extends Foo {", " ['m']() {", " RETURN: return super['m']() + 1;", " }", "}"), lines("/** @constructor */", "let Foo = function() {};", "Foo.prototype['m'] = function() { return 1; };", "/** @constructor */", "let Bar = function() { Foo.apply(this, arguments); };", "$jscomp.inherits(Bar, Foo);", "Bar.prototype['m'] = function () {", " RETURN: return Foo.prototype['m'].call(this) + 1;", "};"));
Color fooType = getNodeWithName(getLastCompiler().getJsRoot(), "Foo").getColor();
Color barType = getNodeWithName(getLastCompiler().getJsRoot(), "Bar").getColor();
// Foo.prototype['m'].call(this)
Node callNode = getNodeMatchingLabel(getLastCompiler().getJsRoot(), "RETURN").getFirstFirstChild();
assertNode(callNode).hasToken(Token.CALL);
assertNode(callNode).hasColorThat().isEqualTo(StandardColors.UNKNOWN);
// Foo.prototype['m'].call
Node callee = callNode.getFirstChild();
assertNode(callee).hasToken(Token.GETPROP);
assertNode(callee).hasColorThat().isEqualTo(StandardColors.UNKNOWN);
// Foo.prototype['m']
Node property = callee.getFirstChild();
assertNode(property).hasToken(Token.GETELEM);
assertNode(callee).hasColorThat().isEqualTo(StandardColors.UNKNOWN);
// Foo.prototype
Node prototype = property.getFirstChild();
assertNode(prototype).matchesQualifiedName("Foo.prototype").hasOriginalName("super");
assertThat(fooType.getPrototypes()).containsExactly(prototype.getColor());
// Foo
Node superDotGReplacement = prototype.getFirstChild();
assertNode(superDotGReplacement).matchesQualifiedName("Foo");
assertNode(superDotGReplacement).hasColorThat().isEqualTo(fooType);
// `this` node from `Foo.prototype['m'].call(this)`
Node thisNode = callee.getNext();
assertNode(thisNode).hasToken(Token.THIS);
assertThat(barType.getInstanceColors()).containsExactly(thisNode.getColor());
}
Aggregations