How to use the tsutils.isBinaryExpression 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 / preferForOfRule.js View on Github external
case ts.SyntaxKind.PostfixUnaryExpression: {
            var _a = node, operator = _a.operator, operand = _a.operand;
            // `++x` or `x++`
            return operator === ts.SyntaxKind.PlusPlusToken && isVar(operand);
        }
        case ts.SyntaxKind.BinaryExpression:
            var _b = node, operatorToken = _b.operatorToken, updatedVar = _b.left, rhs = _b.right;
            if (!isVar(updatedVar)) {
                return false;
            }
            switch (operatorToken.kind) {
                case ts.SyntaxKind.PlusEqualsToken:
                    // x += 1
                    return isOne(rhs);
                case ts.SyntaxKind.EqualsToken: {
                    if (!utils.isBinaryExpression(rhs)) {
                        return false;
                    }
                    var rhsOp = rhs.operatorToken, left = rhs.left, right = rhs.right;
                    // `x = 1 + x` or `x = x + 1`
                    return (rhsOp.kind === ts.SyntaxKind.PlusToken &&
                        ((isVar(left) && isOne(right)) || (isOne(left) && isVar(right))));
                }
                default:
                    return false;
            }
        default:
            return false;
    }
    function isVar(id) {
        return isIdentifierNamed(id, indexVariableName);
    }
github nativescript-rtl / ui / node_modules / tslint / lib / rules / preferConstRule.js View on Github external
if (node.parent.kind !== ts.SyntaxKind.IndexSignature) {
                    _this.handleBindingName(node.name, {
                        canBeConst: false,
                        isBlockScoped: true,
                    });
                }
            }
            else if (utils.isPostfixUnaryExpression(node) ||
                (utils.isPrefixUnaryExpression(node) &&
                    (node.operator === ts.SyntaxKind.PlusPlusToken ||
                        node.operator === ts.SyntaxKind.MinusMinusToken))) {
                if (utils.isIdentifier(node.operand)) {
                    _this.scope.reassigned.add(node.operand.text);
                }
            }
            else if (utils.isBinaryExpression(node) &&
                utils.isAssignmentKind(node.operatorToken.kind)) {
                _this.handleExpression(node.left);
            }
            if (boundary !== 0 /* None */) {
                ts.forEachChild(node, cb);
                _this.onScopeEnd(savedScope);
                _this.scope = savedScope;
            }
            else {
                return ts.forEachChild(node, cb);
            }
        };
        if (ts.isExternalModule(sourceFile)) {
github fossasia / susper.com / node_modules / tslint / lib / rules / noUnusedExpressionRule.js View on Github external
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;
        }
        else if (tsutils_1.isBinaryExpression(node) &&
            node.operatorToken.kind === ts.SyntaxKind.CommaToken &&
            !isIndirectEval(node)) {
            check(node.left);
            return cb(node.right);
        }
        return ts.forEachChild(node, cb);
    }
    function forEachChild(node) {
github microsoft / tslint-microsoft-contrib / src / chaiVagueErrorsRule.ts View on Github external
}

        if (tsutils.isCallExpression(node)) {
            if (ChaiUtils.isExpectInvocation(node)) {
                if (tsutils.isPropertyAccessExpression(node.expression)) {
                    if (ChaiUtils.isEqualsInvocation(node.expression)) {
                        if (node.arguments.length === 1) {
                            if (/true|false|null|undefined/.test(node.arguments[0].getText())) {
                                ctx.addFailureAt(node.getStart(), node.getWidth(), FAILURE_STRING);
                            }
                        }
                    }
                }

                const actualValue = ChaiUtils.getFirstExpectCallParameter(node);
                if (actualValue && tsutils.isBinaryExpression(actualValue)) {
                    const expectedValue = ChaiUtils.getFirstExpectationParameter(node);
                    if (expectedValue) {
                        const operator: string = actualValue.operatorToken.getText();
                        const expectingBooleanKeyword: boolean =
                            expectedValue.kind === ts.SyntaxKind.TrueKeyword || expectedValue.kind === ts.SyntaxKind.FalseKeyword;

                        if (operator === '===' && expectingBooleanKeyword) {
                            ctx.addFailureAt(node.getStart(), node.getWidth(), FAILURE_STRING_COMPARE_TRUE);
                        } else if (operator === '!==' && expectingBooleanKeyword) {
                            ctx.addFailureAt(node.getStart(), node.getWidth(), FAILURE_STRING_COMPARE_FALSE);
                        }
                    }
                }
            }
        }
github fossasia / susper.com / node_modules / tslint / lib / rules / binaryExpressionOperandOrderRule.js View on Github external
ts.forEachChild(ctx.sourceFile, function cb(node) {
        if (tsutils_1.isBinaryExpression(node) &&
            isLiteral(node.left) &&
            !isLiteral(node.right) &&
            !isAllowedOrderedOperator(node)) {
            ctx.addFailureAtNode(node, Rule.FAILURE_STRING);
        }
        ts.forEachChild(node, cb);
    });
}
github microsoft / tslint-microsoft-contrib / noDocumentDomainRule.js View on Github external
function cb(node) {
        if (tsutils.isBinaryExpression(node) &&
            node.operatorToken.getText() === '=' &&
            tsutils.isPropertyAccessExpression(node.left) &&
            isDocumentDomainProperty(node.left)) {
            var msg = Rule.FAILURE_STRING + node.getFullText().trim();
            ctx.addFailureAt(node.getStart(), node.getWidth(), msg);
        }
        return ts.forEachChild(node, cb);
    }
    return ts.forEachChild(ctx.sourceFile, cb);
github palantir / tslint / src / rules / incrementDecrementRule.ts View on Github external
function createReplacement(
        node: ts.PostfixUnaryExpression | ts.PrefixUnaryExpression,
        newOperatorText: string,
    ): Lint.Replacement {
        let text = `${node.operand.getText(context.sourceFile)} ${newOperatorText}`;

        if (node.parent !== undefined && tsutils.isBinaryExpression(node.parent)) {
            text = `(${text})`;
        }

        return Lint.Replacement.replaceNode(node, text);
    }
github fossasia / susper.com / node_modules / tslint / lib / rules / noUnusedExpressionRule.js View on Github external
function cb(node) {
        if (checking) {
            if (tsutils_1.isParenthesizedExpression(node) || tsutils_1.isVoidExpression(node)) {
                return cb(node.expression);
            }
            else if (tsutils_1.isConditionalExpression(node)) {
                noCheck(node.condition, cb);
                return both(node.whenTrue, node.whenFalse);
            }
            else if (tsutils_1.isBinaryExpression(node)) {
                switch (node.operatorToken.kind) {
                    case ts.SyntaxKind.CommaToken:
                        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);
github palantir / tslint / src / rules / noUnusedExpressionRule.ts View on Github external
function cb(node: ts.Node): boolean | undefined {
        if (checking) {
            if (isParenthesizedExpression(node) || isVoidExpression(node)) {
                return cb(node.expression);
            } else if (isConditionalExpression(node)) {
                noCheck(node.condition, cb);
                return both(node.whenTrue, node.whenFalse);
            } else if (isBinaryExpression(node)) {
                switch (node.operatorToken.kind) {
                    case ts.SyntaxKind.CommaToken:
                        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);
github fossasia / susper.com / node_modules / tslint / lib / rules / preferTemplateRule.js View on Github external
function isPlusExpression(node) {
    return tsutils_1.isBinaryExpression(node) && node.operatorToken.kind === ts.SyntaxKind.PlusToken;
}
function isStringLike(node) {