use of com.google.javascript.jscomp.type.ClosureReverseAbstractInterpreter in project closure-compiler by google.
the class ClosureReverseAbstractInterpreterTest method testClosureFunction.
private void testClosureFunction(String function, JSType type, JSType trueType, JSType falseType) {
// function(a) where a : type
Node n = compiler.parseTestCode("var a; " + function + "(a)");
Node call = n.getLastChild().getLastChild();
Node name = call.getLastChild();
TypedScope scope = (TypedScope) SyntacticScopeCreator.makeTyped(compiler).createScope(n, null);
FlowScope flowScope = LinkedFlowScope.createEntryLattice(scope);
assertEquals(Token.CALL, call.getToken());
assertEquals(Token.NAME, name.getToken());
flowScope.inferSlotType("a", type);
ClosureReverseAbstractInterpreter rai = new ClosureReverseAbstractInterpreter(registry);
// trueScope
Asserts.assertTypeEquals(trueType, rai.getPreciserScopeKnowingConditionOutcome(call, flowScope, true).getSlot("a").getType());
// falseScope
JSType aType = rai.getPreciserScopeKnowingConditionOutcome(call, flowScope, false).getSlot("a").getType();
if (falseType == null) {
assertThat(aType).isNull();
} else {
Asserts.assertTypeEquals(falseType, aType);
}
}
use of com.google.javascript.jscomp.type.ClosureReverseAbstractInterpreter in project closure-compiler by google.
the class TypeCheckTest method testClosureTypesMultipleWarnings.
private void testClosureTypesMultipleWarnings(String js, List<String> descriptions) {
compiler.initOptions(compiler.getOptions());
Node n = compiler.parseTestCode(js);
Node externs = IR.root();
IR.root(externs, n);
assertEquals("parsing error: " + Joiner.on(", ").join(compiler.getErrors()), 0, compiler.getErrorCount());
// For processing goog.addDependency for forward typedefs.
new ProcessClosurePrimitives(compiler, null, CheckLevel.ERROR, false).process(externs, n);
new TypeCheck(compiler, new ClosureReverseAbstractInterpreter(registry).append(new SemanticReverseAbstractInterpreter(registry)).getFirst(), registry).processForTesting(null, n);
assertEquals("unexpected error(s) : " + Joiner.on(", ").join(compiler.getErrors()), 0, compiler.getErrorCount());
if (descriptions == null) {
assertEquals("unexpected warning(s) : " + Joiner.on(", ").join(compiler.getWarnings()), 0, compiler.getWarningCount());
} else {
assertEquals("unexpected warning(s) : " + Joiner.on(", ").join(compiler.getWarnings()), descriptions.size(), compiler.getWarningCount());
Set<String> actualWarningDescriptions = new HashSet<>();
for (int i = 0; i < descriptions.size(); i++) {
actualWarningDescriptions.add(compiler.getWarnings()[i].description);
}
assertEquals(new HashSet<>(descriptions), actualWarningDescriptions);
}
}
use of com.google.javascript.jscomp.type.ClosureReverseAbstractInterpreter in project closure-compiler by google.
the class TypeCheckNoTranspileTest method testClosureTypesMultipleWarnings.
private void testClosureTypesMultipleWarnings(String js, List<String> descriptions) {
compiler.initOptions(compiler.getOptions());
Node n = compiler.parseTestCode(js);
Node externs = IR.root();
IR.root(externs, n);
assertEquals("parsing error: " + Joiner.on(", ").join(compiler.getErrors()), 0, compiler.getErrorCount());
// For processing goog.addDependency for forward typedefs.
new ProcessClosurePrimitives(compiler, null, CheckLevel.ERROR, false).process(externs, n);
new TypeCheck(compiler, new ClosureReverseAbstractInterpreter(registry).append(new SemanticReverseAbstractInterpreter(registry)).getFirst(), registry).processForTesting(null, n);
assertEquals("unexpected error(s) : " + Joiner.on(", ").join(compiler.getErrors()), 0, compiler.getErrorCount());
if (descriptions == null) {
assertEquals("unexpected warning(s) : " + Joiner.on(", ").join(compiler.getWarnings()), 0, compiler.getWarningCount());
} else {
assertEquals("unexpected warning(s) : " + Joiner.on(", ").join(compiler.getWarnings()), descriptions.size(), compiler.getWarningCount());
Set<String> actualWarningDescriptions = new HashSet<>();
for (int i = 0; i < descriptions.size(); i++) {
actualWarningDescriptions.add(compiler.getWarnings()[i].description);
}
assertEquals(new HashSet<>(descriptions), actualWarningDescriptions);
}
}
use of com.google.javascript.jscomp.type.ClosureReverseAbstractInterpreter in project closure-compiler by google.
the class Compiler method getReverseAbstractInterpreter.
@Override
public ReverseAbstractInterpreter getReverseAbstractInterpreter() {
if (abstractInterpreter == null) {
ChainableReverseAbstractInterpreter interpreter = new SemanticReverseAbstractInterpreter(getTypeRegistry());
if (options.closurePass) {
interpreter = new ClosureReverseAbstractInterpreter(getTypeRegistry()).append(interpreter).getFirst();
}
abstractInterpreter = interpreter;
}
return abstractInterpreter;
}
Aggregations