How to use the tsutils.isExpressionStatement 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 palantir / tslint / src / rules / noUnusedExpressionRule.ts View on Github external
if (isIndirectEval(node)) {
                            return false;
                        }
                        return both(node.left, node.right);
                    case ts.SyntaxKind.AmpersandAmpersandToken:
                    case ts.SyntaxKind.BarBarToken:
                        if (allowFastNullChecks) {
                            noCheck(node.left, cb);
                            return cb(node.right);
                        }
                }
            }
            noCheck(node, forEachChild);
            return isUnusedExpression(node, ctx.options);
        }
        if (isExpressionStatement(node)) {
            allowFastNullChecks = ctx.options.allowFastNullChecks;
            if (!isDirective(node)) {
                check(node.expression, node);
            }
            allowFastNullChecks = true;
            return false;
        } else if (isVoidExpression(node)) {
            // allow `void 0` and `void(0)`
            if (
                !isLiteralZero(
                    isParenthesizedExpression(node.expression)
                        ? node.expression.expression
                        : node.expression,
                )
            ) {
                check(node.expression);
github fossasia / susper.com / node_modules / tslint / lib / rules / noUnusedExpressionRule.js View on Github external
function isDirective(node) {
    if (node.expression.kind !== ts.SyntaxKind.StringLiteral || !canContainDirective(node.parent)) {
        return false;
    }
    var parent = node.parent;
    // check if all previous statements in block are also directives
    for (var i = parent.statements.indexOf(node) - 1; i >= 0; --i) {
        var statement = parent.statements[i];
        if (!tsutils_1.isExpressionStatement(statement) ||
            statement.expression.kind !== ts.SyntaxKind.StringLiteral) {
            return false;
        }
    }
    return true;
}
function canContainDirective(node) {
github fossasia / susper.com / node_modules / tslint / lib / rules / noUnusedExpressionRule.js View on Github external
if (isIndirectEval(node)) {
                            return false;
                        }
                        return both(node.left, node.right);
                    case ts.SyntaxKind.AmpersandAmpersandToken:
                    case ts.SyntaxKind.BarBarToken:
                        if (allowFastNullChecks) {
                            noCheck(node.left, cb);
                            return cb(node.right);
                        }
                }
            }
            noCheck(node, forEachChild);
            return isUnusedExpression(node, ctx.options);
        }
        if (tsutils_1.isExpressionStatement(node)) {
            allowFastNullChecks = ctx.options.allowFastNullChecks;
            if (!isDirective(node)) {
                check(node.expression, node);
            }
            allowFastNullChecks = true;
            return false;
        }
        else if (tsutils_1.isVoidExpression(node)) {
            // allow `void 0` and `void(0)`
            if (!isLiteralZero(tsutils_1.isParenthesizedExpression(node.expression)
                ? node.expression.expression
                : node.expression)) {
                check(node.expression);
            }
            return false;
        }
github palantir / tslint / src / rules / noUnusedExpressionRule.ts View on Github external
if (isIndirectEval(node)) {
                            return false;
                        }
                        return both(node.left, node.right);
                    case ts.SyntaxKind.AmpersandAmpersandToken:
                    case ts.SyntaxKind.BarBarToken:
                        if (allowFastNullChecks) {
                            noCheck(node.left, cb);
                            return cb(node.right);
                        }
                }
            }
            noCheck(node, forEachChild);
            return isUnusedExpression(node, ctx.options);
        }
        if (isExpressionStatement(node)) {
            allowFastNullChecks = ctx.options.allowFastNullChecks;
            if (!isDirective(node)) {
                check(node.expression, node);
            }
            allowFastNullChecks = true;
            return false;
        }
        if (isVoidExpression(node)) {
            // allow `void 0` and `void(0)`
            if (
                !isLiteralZero(
                    isParenthesizedExpression(node.expression)
                        ? node.expression.expression
                        : node.expression,
                )
            ) {
github palantir / tslint / src / rules / preferConditionalExpressionRule.ts View on Github external
): ts.Expression | undefined {
    if (isIfStatement(statement)) {
        if (inElse === false || (!checkElseIf && inElse) || statement.elseStatement === undefined) {
            return undefined;
        }
        const then = detectAssignment(statement.thenStatement, sourceFile, checkElseIf, false);
        if (then === undefined) {
            return undefined;
        }
        const elze = detectAssignment(statement.elseStatement, sourceFile, checkElseIf, true);
        return elze !== undefined && nodeEquals(then, elze, sourceFile) ? then : undefined;
    } else if (isBlock(statement)) {
        return statement.statements.length === 1
            ? detectAssignment(statement.statements[0], sourceFile, checkElseIf, inElse)
            : undefined;
    } else if (isExpressionStatement(statement) && isBinaryExpression(statement.expression)) {
        const {
            operatorToken: { kind },
            left,
            right,
        } = statement.expression;
        return kind === ts.SyntaxKind.EqualsToken &&
            isSameLine(sourceFile, right.getStart(sourceFile), right.end)
            ? left
            : undefined;
    } else {
        return undefined;
    }
}
github nativescript-rtl / ui / node_modules / tslint / lib / rules / quotemarkRule.js View on Github external
function isUseStrictDeclaration(node) {
    return node.text === "use strict" && tsutils_1.isExpressionStatement(node.parent);
}
function isLookupTypeParameter(node) {
github palantir / tslint / src / rules / quotemarkRule.ts View on Github external
function isUseStrictDeclaration(node: StringLiteralLike) {
    return node.text === "use strict" && isExpressionStatement(node.parent);
}
github fossasia / susper.com / node_modules / tslint / lib / rules / noFloatingPromisesRule.js View on Github external
return ts.forEachChild(ctx.sourceFile, function cb(node) {
        if (tsutils_1.isExpressionStatement(node)) {
            var expression = node.expression;
            if (tsutils_1.isCallExpression(expression) &&
                !isPromiseCatchCall(expression) &&
                !isPromiseThenCallWithRejectionHandler(expression)) {
                var symbol = tc.getTypeAtLocation(expression).symbol;
                if (symbol !== undefined && ctx.options.indexOf(symbol.name) !== -1) {
                    ctx.addFailureAtNode(expression, Rule.FAILURE_STRING);
                }
            }
        }
        return ts.forEachChild(node, cb);
    });
}
github microsoft / tslint-microsoft-contrib / noUnnecessaryOverrideRule.js View on Github external
function getCallExpressionFromStatement(statement) {
        var expression;
        if (tsutils.isExpressionStatement(statement)) {
            expression = statement.expression;
        }
        else if (tsutils.isReturnStatement(statement)) {
            expression = statement.expression;
            if (expression === undefined) {
                return undefined;
            }
        }
        else {
            return undefined;
        }
        if (!tsutils.isCallExpression(expression)) {
            return undefined;
        }
        var call = expression;
        if (!tsutils.isPropertyAccessExpression(call.expression)) {