How to use the tsutils.isLiteralExpression function in tsutils

To help you get started, we’ve selected a few tsutils examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github fossasia / susper.com / node_modules / tslint / lib / rules / strictTypePredicatesRule.js View on Github external
function getTypePredicateOneWay(left, right, isStrictEquals) {
    switch (right.kind) {
        case ts.SyntaxKind.TypeOfExpression:
            var expression = right.expression;
            if (!tsutils_1.isLiteralExpression(left)) {
                if ((tsutils_1.isIdentifier(left) && left.text === "undefined") ||
                    left.kind === ts.SyntaxKind.NullKeyword ||
                    left.kind === ts.SyntaxKind.TrueKeyword ||
                    left.kind === ts.SyntaxKind.FalseKeyword) {
                    return { kind: 2 /* TypeofTypo */ };
                }
                return undefined;
            }
            var predicate = getTypePredicateForKind(left.text);
            return predicate === undefined
                ? { kind: 2 /* TypeofTypo */ }
                : {
                    expression: expression,
                    isNullOrUndefined: left.text === "undefined",
                    kind: 0 /* Plain */,
                    predicate: predicate,
github nativescript-rtl / ui / node_modules / tslint / lib / rules / strictTypePredicatesRule.js View on Github external
function getTypePredicateOneWay(left, right, isStrictEquals) {
    switch (right.kind) {
        case ts.SyntaxKind.TypeOfExpression:
            var expression = right.expression;
            if (!tsutils_1.isLiteralExpression(left)) {
                if ((tsutils_1.isIdentifier(left) && left.text === "undefined") ||
                    left.kind === ts.SyntaxKind.NullKeyword ||
                    left.kind === ts.SyntaxKind.TrueKeyword ||
                    left.kind === ts.SyntaxKind.FalseKeyword) {
                    return { kind: 2 /* TypeofTypo */ };
                }
                return undefined;
            }
            var predicate = getTypePredicateForKind(left.text);
            return predicate === undefined
                ? { kind: 2 /* TypeofTypo */ }
                : {
                    expression: expression,
                    isNullOrUndefined: left.text === "undefined",
                    kind: 0 /* Plain */,
                    predicate: predicate,
github ajafff / tslint-consistent-codestyle / rules / noVarBeforeReturnRule.ts View on Github external
function dependsOnPrevious(element: ts.BindingElement): boolean {
        if (element.propertyName === undefined || element.propertyName.kind !== ts.SyntaxKind.ComputedPropertyName)
            return false;
        if (isIdentifier(element.propertyName.expression))
            return identifiersSeen.has(element.propertyName.expression.text);
        if (isLiteralExpression(element.propertyName.expression))
            return false;
        return true; // TODO implement better check for expressions
    }
}
github palantir / tslint / src / rules / adjacentOverloadSignaturesRule.ts View on Github external
case ts.SyntaxKind.Constructor:
            return "constructor";
        case ts.SyntaxKind.CallSignature:
            return "()";
        default: {
            const { name } = node;
            if (name === undefined) {
                return undefined;
            }

            switch (name.kind) {
                case ts.SyntaxKind.Identifier:
                    return name.text;
                case ts.SyntaxKind.ComputedPropertyName:
                    const { expression } = name;
                    return utils.isLiteralExpression(expression)
                        ? expression.text
                        : { name: expression.getText(), computed: true };
                default:
                    return utils.isLiteralExpression(name) ? name.text : undefined;
            }
        }
    }
}
github fossasia / susper.com / node_modules / tslint / lib / rules / adjacentOverloadSignaturesRule.js View on Github external
case ts.SyntaxKind.ConstructSignature:
        case ts.SyntaxKind.Constructor:
            return "constructor";
        case ts.SyntaxKind.CallSignature:
            return "()";
        default: {
            var name = node.name;
            if (name === undefined) {
                return undefined;
            }
            switch (name.kind) {
                case ts.SyntaxKind.Identifier:
                    return name.text;
                case ts.SyntaxKind.ComputedPropertyName:
                    var expression = name.expression;
                    return utils.isLiteralExpression(expression)
                        ? expression.text
                        : { name: expression.getText(), computed: true };
                default:
                    return utils.isLiteralExpression(name) ? name.text : undefined;
            }
        }
    }
}
github palantir / tslint / src / rules / strictTypePredicatesRule.ts View on Github external
function getTypePredicateOneWay(
    left: ts.Expression,
    right: ts.Expression,
    isStrictEquals: boolean,
): TypePredicate | undefined {
    switch (right.kind) {
        case ts.SyntaxKind.TypeOfExpression:
            const expression = (right as ts.TypeOfExpression).expression;
            if (!isLiteralExpression(left)) {
                if (
                    (isIdentifier(left) && left.text === "undefined") ||
                    left.kind === ts.SyntaxKind.NullKeyword ||
                    left.kind === ts.SyntaxKind.TrueKeyword ||
                    left.kind === ts.SyntaxKind.FalseKeyword
                ) {
                    return { kind: TypePredicateKind.TypeofTypo };
                }
                return undefined;
            }
            const predicate = getTypePredicateForKind(left.text);
            return predicate === undefined
                ? { kind: TypePredicateKind.TypeofTypo }
                : {
                      expression,
                      isNullOrUndefined: left.text === "undefined",
github nativescript-rtl / ui / node_modules / tslint / lib / rules / adjacentOverloadSignaturesRule.js View on Github external
case ts.SyntaxKind.ConstructSignature:
        case ts.SyntaxKind.Constructor:
            return "constructor";
        case ts.SyntaxKind.CallSignature:
            return "()";
        default: {
            var name = node.name;
            if (name === undefined) {
                return undefined;
            }
            switch (name.kind) {
                case ts.SyntaxKind.Identifier:
                    return name.text;
                case ts.SyntaxKind.ComputedPropertyName:
                    var expression = name.expression;
                    return utils.isLiteralExpression(expression)
                        ? expression.text
                        : { name: expression.getText(), computed: true };
                default:
                    return utils.isLiteralExpression(name) ? name.text : undefined;
            }
        }
    }
}
var templateObject_1;
github ajafff / tslint-consistent-codestyle / rules / noReturnUndefinedRule.ts View on Github external
function isUndefinedNotVoidExpr(expression: ts.Expression): boolean {
    if (utils.isIdentifier(expression) && expression.text === 'undefined')
        return true;
    return utils.isVoidExpression(expression) && utils.isLiteralExpression(expression.expression);
}
github nativescript-rtl / ui / node_modules / tslint / lib / rules / adjacentOverloadSignaturesRule.js View on Github external
return "()";
        default: {
            var name = node.name;
            if (name === undefined) {
                return undefined;
            }
            switch (name.kind) {
                case ts.SyntaxKind.Identifier:
                    return name.text;
                case ts.SyntaxKind.ComputedPropertyName:
                    var expression = name.expression;
                    return utils.isLiteralExpression(expression)
                        ? expression.text
                        : { name: expression.getText(), computed: true };
                default:
                    return utils.isLiteralExpression(name) ? name.text : undefined;
            }
        }
    }
}
var templateObject_1;