How to use the tsutils.isPrefixUnaryExpression 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 / preferConstRule.js View on Github external
_this.handleBindingName(node.variableDeclaration.name, {
                        canBeConst: false,
                        isBlockScoped: true,
                    });
                }
            }
            else if (node.kind === ts.SyntaxKind.Parameter) {
                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 {
github cartant / tslint-etc / source / rules / noUnusedDeclarationRule.ts View on Github external
function isUnaryPrefixOrPostfix(node: ts.Node): boolean {
  const { parent } = node;
  return (
    tsutils.isPrefixUnaryExpression(parent) ||
    tsutils.isPostfixUnaryExpression(parent)
  );
}
github microsoft / tslint-microsoft-contrib / noIncrementDecrementRule.js View on Github external
if (node.initializer) {
                    cb(node.initializer);
                }
                if (node.condition) {
                    cb(node.condition);
                }
            }
            else {
                ts.forEachChild(node, cb);
            }
            return;
        }
        if (tsutils.isPostfixUnaryExpression(node)) {
            validateUnaryExpression(node);
        }
        else if (tsutils.isPrefixUnaryExpression(node)) {
            validateUnaryExpression(node);
        }
        return ts.forEachChild(node, cb);
    }
    return ts.forEachChild(ctx.sourceFile, cb);
github palantir / tslint / src / rules / preferConstRule.ts View on Github external
if ((node as ts.CatchClause).variableDeclaration !== undefined) {
                    this.handleBindingName((node as ts.CatchClause).variableDeclaration!.name, {
                        canBeConst: false,
                        isBlockScoped: true,
                    });
                }
            } else if (node.kind === ts.SyntaxKind.Parameter) {
                if (node.parent.kind !== ts.SyntaxKind.IndexSignature) {
                    this.handleBindingName((node as ts.ParameterDeclaration).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 !== utils.ScopeBoundary.None) {
                ts.forEachChild(node, cb);
                this.onScopeEnd(savedScope);
github palantir / tslint / src / rules / noDynamicDeleteRule.ts View on Github external
function isNumberLike(node: ts.Node): boolean {
    if (tsutils.isPrefixUnaryExpression(node)) {
        return tsutils.isNumericLiteral(node.operand) && node.operator === ts.SyntaxKind.MinusToken;
    }

    return tsutils.isNumericLiteral(node);
}
github bfwg / angular-spring-starter / frontend / node_modules / tslint / lib / rules / noMagicNumbersRule.js View on Github external
var cb = function (node) {
            if (node.kind === ts.SyntaxKind.NumericLiteral) {
                return _this.checkNumericLiteral(node, node.text);
            }
            if (tsutils_1.isPrefixUnaryExpression(node) &&
                node.operator === ts.SyntaxKind.MinusToken &&
                node.operand.kind === ts.SyntaxKind.NumericLiteral) {
                return _this.checkNumericLiteral(node, "-" + node.operand.text);
            }
            return ts.forEachChild(node, cb);
        };
        return ts.forEachChild(sourceFile, cb);
github palantir / tslint / src / language / utils.ts View on Github external
export function isNumeric(node: ts.Expression) {
    while (
        isPrefixUnaryExpression(node) &&
        (node.operator === ts.SyntaxKind.PlusToken || node.operator === ts.SyntaxKind.MinusToken)
    ) {
        node = node.operand;
    }

    return (
        node.kind === ts.SyntaxKind.NumericLiteral ||
        (isIdentifier(node) && (node.text === "NaN" || node.text === "Infinity"))
    );
}
github fossasia / susper.com / node_modules / tslint / lib / rules / noDynamicDeleteRule.js View on Github external
function isNumberLike(node) {
    if (tsutils.isPrefixUnaryExpression(node)) {
        return tsutils.isNumericLiteral(node.operand) && node.operator === ts.SyntaxKind.MinusToken;
    }
    return tsutils.isNumericLiteral(node);
}
function isNecessaryDynamicAccess(argumentExpression) {
github nativescript-rtl / ui / node_modules / tslint / lib / rules / incrementDecrementRule.js View on Github external
function complainOnNode(node) {
        var newOperatorText = node.operator === ts.SyntaxKind.PlusPlusToken ? "+= 1" : "-= 1";
        var replacement;
        if (tsutils.isPrefixUnaryExpression(node) ||
            node.parent.kind === ts.SyntaxKind.ExpressionStatement) {
            replacement = createReplacement(node, newOperatorText);
        }
        var failure = Rule.FAILURE_STRING_FACTORY(newOperatorText);
        context.addFailureAtNode(node, failure, replacement);
    }
    function checkPostfixUnaryExpression(node) {