demo/typescript.js
function isVariableAssignedWithin(symbol, node) {
            var links = getNodeLinks(node);
            if (links.assignmentChecks) {
                var cachedResult = links.assignmentChecks[symbol.id];
                if (cachedResult !== undefined) {
                    return cachedResult;
                }
            }
            else {
                links.assignmentChecks = {};
            }
            return links.assignmentChecks[symbol.id] = isAssignedIn(node);
            function isAssignedInBinaryExpression(node) {
                if (node.operatorToken.kind >= 56 /* FirstAssignment */ && node.operatorToken.kind <= 68 /* LastAssignment */) {
                    var n = node.left;
                    while (n.kind === 172 /* ParenthesizedExpression */) {
                        n = n.expression;
                    }
                    if (n.kind === 69 /* Identifier */ && getResolvedSymbol(n) === symbol) {
                        return true;
                    }
                }
                return ts.forEachChild(node, isAssignedIn);
            }
            function isAssignedInVariableDeclaration(node) {
                if (!ts.isBindingPattern(node.name) && getSymbolOfNode(node) === symbol && hasInitializer(node)) {
                    return true;
                }
                return ts.forEachChild(node, isAssignedIn);
            }
            function isAssignedIn(node) {
                switch (node.kind) {
                    case 181 /* BinaryExpression */:
                        return isAssignedInBinaryExpression(node);
                    case 211 /* VariableDeclaration */:
                    case 163 /* BindingElement */:
                        return isAssignedInVariableDeclaration(node);
                    case 161 /* ObjectBindingPattern */:
                    case 162 /* ArrayBindingPattern */:
                    case 164 /* ArrayLiteralExpression */:
                    case 165 /* ObjectLiteralExpression */:
                    case 166 /* PropertyAccessExpression */:
                    case 167 /* ElementAccessExpression */:
                    case 168 /* CallExpression */:
                    case 169 /* NewExpression */:
                    case 171 /* TypeAssertionExpression */:
                    case 189 /* AsExpression */:
                    case 172 /* ParenthesizedExpression */:
                    case 179 /* PrefixUnaryExpression */:
                    case 175 /* DeleteExpression */:
                    case 178 /* AwaitExpression */:
                    case 176 /* TypeOfExpression */:
                    case 177 /* VoidExpression */:
                    case 180 /* PostfixUnaryExpression */:
                    case 184 /* YieldExpression */:
                    case 182 /* ConditionalExpression */:
                    case 185 /* SpreadElementExpression */:
                    case 192 /* Block */:
                    case 193 /* VariableStatement */:
                    case 195 /* ExpressionStatement */:
                    case 196 /* IfStatement */:
                    case 197 /* DoStatement */:
                    case 198 /* WhileStatement */:
                    case 199 /* ForStatement */:
                    case 200 /* ForInStatement */:
                    case 201 /* ForOfStatement */:
                    case 204 /* ReturnStatement */:
                    case 205 /* WithStatement */:
                    case 206 /* SwitchStatement */:
                    case 241 /* CaseClause */:
                    case 242 /* DefaultClause */:
                    case 207 /* LabeledStatement */:
                    case 208 /* ThrowStatement */:
                    case 209 /* TryStatement */:
                    case 244 /* CatchClause */:
                    case 233 /* JsxElement */:
                    case 234 /* JsxSelfClosingElement */:
                    case 238 /* JsxAttribute */:
                    case 239 /* JsxSpreadAttribute */:
                    case 235 /* JsxOpeningElement */:
                    case 240 /* JsxExpression */:
                        return ts.forEachChild(node, isAssignedIn);
                }
                return false;
            }
        }
function isVariableAssignedWithin(symbol, node) {
            var links = getNodeLinks(node);
            if (links.assignmentChecks) {
                var cachedResult = links.assignmentChecks[symbol.id];
                if (cachedResult !== undefined) {
                    return cachedResult;
                }
            }
            else {
                links.assignmentChecks = {};
            }
            return links.assignmentChecks[symbol.id] = isAssignedIn(node);
            function isAssignedInBinaryExpression(node) {
                if (node.operatorToken.kind >= 56 /* FirstAssignment */ && node.operatorToken.kind <= 68 /* LastAssignment */) {
                    var n = node.left;
                    while (n.kind === 172 /* ParenthesizedExpression */) {
                        n = n.expression;
                    }
                    if (n.kind === 69 /* Identifier */ && getResolvedSymbol(n) === symbol) {
                        return true;
                    }
                }
                return ts.forEachChild(node, isAssignedIn);
            }
            function isAssignedInVariableDeclaration(node) {
                if (!ts.isBindingPattern(node.name) && getSymbolOfNode(node) === symbol && hasInitializer(node)) {
                    return true;
                }
                return ts.forEachChild(node, isAssignedIn);
            }
            function isAssignedIn(node) {
                switch (node.kind) {
                    case 181 /* BinaryExpression */:
                        return isAssignedInBinaryExpression(node);
                    case 211 /* VariableDeclaration */:
                    case 163 /* BindingElement */:
                        return isAssignedInVariableDeclaration(node);
                    case 161 /* ObjectBindingPattern */:
                    case 162 /* ArrayBindingPattern */:
                    case 164 /* ArrayLiteralExpression */:
                    case 165 /* ObjectLiteralExpression */:
                    case 166 /* PropertyAccessExpression */:
                    case 167 /* ElementAccessExpression */:
                    case 168 /* CallExpression */:
                    case 169 /* NewExpression */:
                    case 171 /* TypeAssertionExpression */:
                    case 189 /* AsExpression */:
                    case 172 /* ParenthesizedExpression */:
                    case 179 /* PrefixUnaryExpression */:
                    case 175 /* DeleteExpression */:
                    case 178 /* AwaitExpression */:
                    case 176 /* TypeOfExpression */:
                    case 177 /* VoidExpression */:
                    case 180 /* PostfixUnaryExpression */:
                    case 184 /* YieldExpression */:
                    case 182 /* ConditionalExpression */:
                    case 185 /* SpreadElementExpression */:
                    case 192 /* Block */:
                    case 193 /* VariableStatement */:
                    case 195 /* ExpressionStatement */:
                    case 196 /* IfStatement */:
                    case 197 /* DoStatement */:
                    case 198 /* WhileStatement */:
                    case 199 /* ForStatement */:
                    case 200 /* ForInStatement */:
                    case 201 /* ForOfStatement */:
                    case 204 /* ReturnStatement */:
                    case 205 /* WithStatement */:
                    case 206 /* SwitchStatement */:
                    case 241 /* CaseClause */:
                    case 242 /* DefaultClause */:
                    case 207 /* LabeledStatement */:
                    case 208 /* ThrowStatement */:
                    case 209 /* TryStatement */:
                    case 244 /* CatchClause */:
                    case 233 /* JsxElement */:
                    case 234 /* JsxSelfClosingElement */:
                    case 238 /* JsxAttribute */:
                    case 239 /* JsxSpreadAttribute */:
                    case 235 /* JsxOpeningElement */:
                    case 240 /* JsxExpression */:
                        return ts.forEachChild(node, isAssignedIn);
                }
                return false;
            }
        }
Check if a given variable is assigned within a given syntax node