Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
castImplicit(type: ts.Type, context: CodeGenerationContext): Value | any {
if (type.flags & ts.TypeFlags.BooleanLike) {
return Primitive.false(context, type);
}
if (type.flags & ts.TypeFlags.IntLike) {
return new Primitive(llvm.ConstantInt.get(context.llvmContext, 0), type);
}
if (type.flags & ts.TypeFlags.NumberLike) {
return new Primitive(llvm.ConstantFP.getNaN(llvm.Type.getDoubleTy(context.llvmContext)), type);
}
// cast pointer
if (type.flags & ts.TypeFlags.Object || isMaybeObjectType(type) || type.flags & ts.TypeFlags.Undefined) {
return new Undefined(context.builder.createBitCast(this.generateIR(context), context.toLLVMType(type)));
}
return undefined;
}
function getKind(type: ts.Type): TypeKind {
// tslint:disable:no-bitwise
if (is(ts.TypeFlags.String | ts.TypeFlags.StringLiteral)) {
return TypeKind.String;
} else if (is(ts.TypeFlags.Number | ts.TypeFlags.NumberLiteral)) {
return TypeKind.Number;
} else if (is(ts.TypeFlags.BooleanLike)) {
return TypeKind.Boolean;
} else if (is(ts.TypeFlags.Null)) {
return TypeKind.Null;
} else if (is(ts.TypeFlags.Undefined)) {
return TypeKind.Undefined;
} else if (is(ts.TypeFlags.Any)) {
return TypeKind.Any;
} else {
return TypeKind.Object;
}
// tslint:enable:no-bitwise
function is(flags: ts.TypeFlags) {
return isTypeFlagSet(type, flags);
}
}
switch (kind) {
case "undefined":
return flagPredicate(undefinedFlags);
case "boolean":
return flagPredicate(ts.TypeFlags.BooleanLike);
case "number":
return flagPredicate(ts.TypeFlags.NumberLike);
case "string":
return flagPredicate(ts.TypeFlags.StringLike);
case "symbol":
return flagPredicate(ts.TypeFlags.ESSymbol);
case "function":
return isFunction;
case "object":
// It's an object if it's not any of the above.
var allFlags_1 = ts.TypeFlags.Undefined | ts.TypeFlags.Void | ts.TypeFlags.BooleanLike |
ts.TypeFlags.NumberLike | ts.TypeFlags.StringLike | ts.TypeFlags.ESSymbol;
return function (type) { return !Lint.isTypeFlagSet(type, allFlags_1) && !isFunction(type); };
default:
return undefined;
}
}
function flagPredicate(testedFlag) {
function getTypeFailure(type, options) {
if (isUnionType(type)) {
return handleUnion(type, options);
}
var kind = getKind(type);
var failure = failureForKind(kind, /*isInUnion*/ false, options);
if (failure !== undefined) {
return failure;
}
switch (triState(kind)) {
case true:
// Allow 'any'. Allow 'true' itself, but not any other always-truthy type.
// tslint:disable-next-line no-bitwise
return tsutils_1.isTypeFlagSet(type, ts.TypeFlags.Any | ts.TypeFlags.BooleanLiteral)
? undefined
: 0 /* AlwaysTruthy */;
case false:
// Allow 'false' itself, but not any other always-falsy type
return tsutils_1.isTypeFlagSet(type, ts.TypeFlags.BooleanLiteral)
? undefined
: 1 /* AlwaysFalsy */;
case undefined:
return undefined;
}
}
function isBooleanUndefined(type) {
}
if (isString(type)) {
return getStringType(context);
}
if (isObject(type)) {
// TODO: Pass correct isOpaque parameter.
return getStructType(type, false, generator).getPointerTo();
}
if (type.flags & ts.TypeFlags.Void) {
return llvm.Type.getVoidTy(context);
}
if (type.flags & ts.TypeFlags.Any) {
return error("'any' type is not supported");
}
return error(`Unhandled ts.Type '${checker.typeToString(type)}'`);
}
function getTypePredicateForKind(kind) {
switch (kind) {
case "undefined":
return flagPredicate(undefinedFlags);
case "boolean":
return flagPredicate(ts.TypeFlags.BooleanLike);
case "number":
return flagPredicate(ts.TypeFlags.NumberLike);
case "string":
return flagPredicate(ts.TypeFlags.StringLike);
case "symbol":
return flagPredicate(ts.TypeFlags.ESSymbol);
case "function":
return isFunction;
case "object":
// It's an object if it's not any of the above.
var allFlags_1 = ts.TypeFlags.Undefined |
ts.TypeFlags.Void |
ts.TypeFlags.BooleanLike |
ts.TypeFlags.NumberLike |
ts.TypeFlags.StringLike |
ts.TypeFlags.ESSymbol;
return function (type) { return !tsutils_1.isTypeFlagSet(type, allFlags_1) && !isFunction(type); };
default:
return undefined;
}
return ts.forEachChild(sourceFile, function cb(node) {
if (isPossiblyVoidExpression(node) &&
!isParentAllowedVoid(node) &&
tsutils_1.isTypeFlagSet(checker.getTypeAtLocation(node), ts.TypeFlags.Void)) {
ctx.addFailureAtNode(node, Rule.FAILURE_STRING);
}
return ts.forEachChild(node, cb);
});
function isParentAllowedVoid(node) {
(function (type) {
return !!(type.flags & ts.TypeFlags.Object &&
type.objectFlags & ts.ObjectFlags.Reference);
}) :
(function (type) { return !!(type.flags & ts.TypeFlags.Reference); });
(function (type) { return !!(type.flags & ts.TypeFlags.Reference); });
function getSymbolQuery(program, checker, source, fetchPipes) {
NoInferredEmptyObjectTypeRule.prototype.checkNewExpression = function (node) {
var _this = this;
if (node.typeArguments === undefined) {
var objType = this.checker.getTypeAtLocation(node);
if (utils_1.isTypeFlagSet(objType, ts.TypeFlags.Object) && objType.typeArguments !== undefined) {
var typeArgs = objType.typeArguments;
if (typeArgs.some(function (a) { return _this.isEmptyObjectInterface(a); })) {
this.addFailureAtNode(node, Rule.EMPTY_INTERFACE_INSTANCE);
}
}
}
};
NoInferredEmptyObjectTypeRule.prototype.checkCallExpression = function (node) {