UNPKG

tslint-react-set-state-usage

Version:

TSLint rule for detection non-functional setState statements

28 lines 1.14 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var ts = require("typescript"); var tsutils_1 = require("tsutils"); var syntaxKindUtils_1 = require("./syntaxKindUtils"); exports.isThisPropertyAccess = function (node) { return tsutils_1.isPropertyAccessExpression(node) && syntaxKindUtils_1.isThisKeyword(node.expression); }; exports.isThisSetState = function (node) { return tsutils_1.isCallExpression(node) && tsutils_1.isPropertyAccessExpression(node.expression) && syntaxKindUtils_1.isThisKeyword(node.expression.expression) && node.expression.name.text === "setState"; }; function getFirstSetStateAncestor(node) { if (node.kind === ts.SyntaxKind.SourceFile) { return null; } if (exports.isThisSetState(node)) { return node; } return getFirstSetStateAncestor(node.parent); } exports.getFirstSetStateAncestor = getFirstSetStateAncestor; exports.removeParentheses = function (node) { return tsutils_1.isParenthesizedExpression(node) ? exports.removeParentheses(node.expression) : node; }; //# sourceMappingURL=syntaxWalkerUtils.js.map