use of com.google.errorprone.annotations.CheckReturnValue in project closure-compiler by google.
the class SemanticReverseAbstractInterpreter method caseInstanceOf.
@CheckReturnValue
private FlowScope caseInstanceOf(Node left, Node right, FlowScope blindScope, Outcome outcome) {
JSType leftType = getTypeIfRefinable(left, blindScope);
if (leftType == null) {
return blindScope;
}
JSType rightType = right.getJSType();
ObjectType targetType = typeRegistry.getNativeObjectType(JSTypeNative.UNKNOWN_TYPE);
if (rightType != null && rightType.isFunctionType()) {
targetType = rightType.toMaybeFunctionType();
}
Visitor<JSType> visitor;
if (outcome.isTruthy()) {
visitor = new RestrictByTrueInstanceOfResultVisitor(targetType);
} else {
visitor = new RestrictByFalseInstanceOfResultVisitor(targetType);
}
return maybeRestrictName(blindScope, left, leftType, leftType.visit(visitor));
}
use of com.google.errorprone.annotations.CheckReturnValue in project closure-compiler by google.
the class SemanticReverseAbstractInterpreter method caseEquality.
@CheckReturnValue
private FlowScope caseEquality(Node left, Node right, FlowScope blindScope, Function<TypePair, TypePair> merging) {
// left type
JSType leftType = getTypeIfRefinable(left, blindScope);
boolean leftIsRefineable;
if (leftType != null) {
leftIsRefineable = true;
} else {
leftIsRefineable = false;
leftType = left.getJSType();
}
// right type
JSType rightType = getTypeIfRefinable(right, blindScope);
boolean rightIsRefineable;
if (rightType != null) {
rightIsRefineable = true;
} else {
rightIsRefineable = false;
rightType = right.getJSType();
}
// merged types
TypePair merged = merging.apply(new TypePair(leftType, rightType));
// creating new scope
if (merged != null) {
return maybeRestrictTwoNames(blindScope, left, leftType, leftIsRefineable ? merged.typeA : null, right, rightType, rightIsRefineable ? merged.typeB : null);
}
return blindScope;
}
use of com.google.errorprone.annotations.CheckReturnValue in project closure-compiler by google.
the class TypeInference method traverseCatch.
/**
* Any value can be thrown, so it's really impossible to determine the type of a CATCH param.
* Treat it as the UNKNOWN type.
*/
@CheckReturnValue
private FlowScope traverseCatch(Node catchNode, FlowScope scope) {
Node catchTarget = catchNode.getFirstChild();
if (catchTarget.isName()) {
Node name = catchNode.getFirstChild();
JSType type = name.getJSType();
// Otherwise use "unknown".
if (type == null) {
type = unknownType;
name.setJSType(unknownType);
}
return redeclareSimpleVar(scope, name, type);
} else if (catchTarget.isDestructuringPattern()) {
Node pattern = catchNode.getFirstChild();
return traverseDestructuringPattern(pattern, scope, unknownType, AssignmentType.DECLARATION);
} else {
checkState(catchTarget.isEmpty(), catchTarget);
// ES2019 allows `try {} catch {}` with no catch expression
return scope;
}
}
use of com.google.errorprone.annotations.CheckReturnValue in project closure-compiler by google.
the class TypeInference method flowThrough.
@Override
@CheckReturnValue
FlowScope flowThrough(Node n, FlowScope input) {
// want to infer anything about this scope.
if (input == bottomScope) {
return input;
}
// This method also does some logic for ES modules right before and after entering/exiting the
// scope rooted at the module. The reasoning for separating out this logic is that we can just
// ignore the actual AST nodes for IMPORT/EXPORT, in most cases, because we have already
// created an abstraction of imports and exports.
Node root = NodeUtil.getEnclosingScopeRoot(n);
// Inferred types of ES module imports/exports aren't knowable until after TypeInference runs.
// First update the type of all imports in the scope, then do flow-sensitive inference, then
// update the implicit '*exports*' object.
Module module = ModuleImportResolver.getModuleFromScopeRoot(compiler.getModuleMap(), compiler, root);
TypedScope syntacticBlockScope = scopeCreator.createScope(root);
if (module != null && module.metadata().isEs6Module()) {
moduleImportResolver.declareEsModuleImports(module, syntacticBlockScope, compiler.getInput(NodeUtil.getInputId(n)));
}
// This logic is not specific to ES modules.
FlowScope output = input.withSyntacticScope(syntacticBlockScope);
output = inferDeclarativelyUnboundVarsWithoutTypes(output);
output = traverse(n, output);
updateModuleScope(module, syntacticBlockScope);
return output;
}
use of com.google.errorprone.annotations.CheckReturnValue in project closure-compiler by google.
the class TypeInference method traverseAssignOp.
@CheckReturnValue
private FlowScope traverseAssignOp(Node n, FlowScope scope) {
Node left = n.getFirstChild();
scope = traverseBigIntCompatibleBinaryOperator(n, scope);
// The lhs is both an input and an output, so don't update the input type here.
return updateScopeForAssignment(scope, left, getJSType(n), /* updateNode= */
null, AssignmentType.ASSIGN);
}
Aggregations