How to use the typescript.forEachChild function in typescript

To help you get started, we’ve selected a few typescript 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 microsoft / vscode / build / monaco / api.js View on Github external
case ts.SyntaxKind.VariableStatement:
            case ts.SyntaxKind.TypeAliasDeclaration:
            case ts.SyntaxKind.FunctionDeclaration:
            case ts.SyntaxKind.ModuleDeclaration:
                stop = visitor(node);
        }
        // if (node.kind !== ts.SyntaxKind.SourceFile) {
        // 	if (getNodeText(sourceFile, node).indexOf('SymbolKind') >= 0) {
        // 		console.log('FOUND TEXT IN NODE: ' + ts.SyntaxKind[node.kind]);
        // 		console.log(getNodeText(sourceFile, node));
        // 	}
        // }
        if (stop) {
            return;
        }
        ts.forEachChild(node, visit);
    };
    visit(sourceFile);
github palantir / tslint / src / rules / cyclomaticComplexityRule.ts View on Github external
if (isFunctionScopeBoundary(node)) {
            // tslint:enable:deprecation
            const old = complexity;
            complexity = 1;
            ts.forEachChild(node, cb);
            if (complexity > threshold) {
                const { name } = node as ts.FunctionLikeDeclaration;
                const nameStr = name !== undefined && isIdentifier(name) ? name.text : undefined;
                ctx.addFailureAtNode(node, Rule.FAILURE_STRING(threshold, complexity, nameStr));
            }
            complexity = old;
        } else {
            if (increasesComplexity(node)) {
                complexity++;
            }
            return ts.forEachChild(node, cb);
        }
    });
}
github microsoft / tslint-microsoft-contrib / src / reactA11yTabindexNoPositiveRule.ts View on Github external
const literalString = getNumericLiteral(node) || getStringLiteral(node);

            // In case the attribute has no value of empty value.
            if (literalString === '') {
                ctx.addFailureAt(node.getStart(), node.getWidth(), getFailureString());
            } else if (literalString && literalString !== '-1' && literalString !== '0') {
                ctx.addFailureAt(node.getStart(), node.getWidth(), getFailureString());
            } else if (isEmpty(node)) {
                ctx.addFailureAt(node.getStart(), node.getWidth(), getFailureString());
            }
        }

        return ts.forEachChild(node, cb);
    }

    return ts.forEachChild(ctx.sourceFile, cb);
}
github nativescript-rtl / ui / node_modules / tslint / lib / rules / completedDocsRule.js View on Github external
function walk(context) {
    return ts.forEachChild(context.sourceFile, cb);
    function cb(node) {
        switch (node.kind) {
            case ts.SyntaxKind.ClassDeclaration:
                checkNode(node, exports.ARGUMENT_CLASSES);
                break;
            case ts.SyntaxKind.EnumDeclaration:
                checkNode(node, exports.ARGUMENT_ENUMS);
                for (var _i = 0, _a = node.members; _i < _a.length; _i++) {
                    var member = _a[_i];
                    // Enum members don't have modifiers, so use the parent
                    // enum declaration when checking the requirements.
                    checkNode(member, exports.ARGUMENT_ENUM_MEMBERS, node);
                }
                break;
            case ts.SyntaxKind.FunctionDeclaration:
                checkNode(node, exports.ARGUMENT_FUNCTIONS);
github Teal / TealUI / tools / build / lib / tscript.js View on Github external
function visit(node) {
            switch (node.kind) {
                case ts.SyntaxKind.FunctionDeclaration:
                    me.addDocCommentFromNode(node);
                    break;
            }
            ts.forEachChild(node, visit);
        }
    };
github microsoft / tslint-microsoft-contrib / noEmptyInterfacesRule.js View on Github external
function walk(ctx) {
    function cb(node) {
        if (tsutils.isInterfaceDeclaration(node) && isInterfaceEmpty(node) && !hasMultipleParents(node)) {
            ctx.addFailureAt(node.getStart(), node.getWidth(), Rule.FAILURE_STRING + "'" + node.name.getText() + "'");
        }
        return ts.forEachChild(node, cb);
    }
    return ts.forEachChild(ctx.sourceFile, cb);
    function isInterfaceEmpty(node) {
        return node.members === undefined || node.members.length === 0;
    }
    function hasMultipleParents(node) {
        if (node.heritageClauses === undefined || node.heritageClauses.length === 0) {
            return false;
        }
        return node.heritageClauses[0].types.length >= 2;
    }
}
//# sourceMappingURL=noEmptyInterfacesRule.js.map
github fossasia / susper.com / node_modules / tslint / lib / rules / noBitwiseRule.js View on Github external
function walk(ctx) {
    return ts.forEachChild(ctx.sourceFile, function cb(node) {
        if (node.kind === ts.SyntaxKind.BinaryExpression) {
            switch (node.operatorToken.kind) {
                case ts.SyntaxKind.AmpersandToken:
                case ts.SyntaxKind.AmpersandEqualsToken:
                case ts.SyntaxKind.BarToken:
                case ts.SyntaxKind.BarEqualsToken:
                case ts.SyntaxKind.CaretToken:
                case ts.SyntaxKind.CaretEqualsToken:
                case ts.SyntaxKind.LessThanLessThanToken:
                case ts.SyntaxKind.LessThanLessThanEqualsToken:
                case ts.SyntaxKind.GreaterThanGreaterThanToken:
                case ts.SyntaxKind.GreaterThanGreaterThanEqualsToken:
                case ts.SyntaxKind.GreaterThanGreaterThanGreaterThanToken:
                case ts.SyntaxKind.GreaterThanGreaterThanGreaterThanEqualsToken:
                    ctx.addFailureAtNode(node, Rule.FAILURE_STRING);
            }
github fossasia / susper.com / node_modules / tslint / lib / rules / noNonNullAssertionRule.js View on Github external
function walk(ctx) {
    return ts.forEachChild(ctx.sourceFile, function cb(node) {
        if (node.kind === ts.SyntaxKind.NonNullExpression) {
            ctx.addFailureAtNode(node, Rule.FAILURE_STRING);
        }
        return ts.forEachChild(node, cb);
    });
}
var templateObject_1;
github microsoft / vscode-js-debug / src / common / sourceUtils.ts View on Github external
for (const declaration of vd.declarations) {
          if (!declaration.initializer) {
            changes.push({ text: '(', start: declaration.pos, end: declaration.pos });
            changes.push({ text: '=undefined)', start: declaration.end, end: declaration.end });
            continue;
          }
          changes.push({ text: '(', start: declaration.pos, end: declaration.pos });
          changes.push({ text: ')', start: declaration.end, end: declaration.end });
        }
        if (!onlyOneDeclaration) {
          const last = vd.declarations[vd.declarations.length - 1];
          changes.push({ text: ')', start: last.end, end: last.end });
        }
        break;
    }
    ts.forEachChild(node, traverse);
  }
  traverse(body);
github microsoft / tslint-microsoft-contrib / reactA11yRoleSupportsAriaPropsRule.js View on Github external
function cb(node) {
        if (tsutils.isJsxElement(node)) {
            checkJsxElement(node.openingElement);
        }
        else if (tsutils.isJsxSelfClosingElement(node)) {
            checkJsxElement(node);
        }
        return ts.forEachChild(node, cb);
    }
    return ts.forEachChild(ctx.sourceFile, cb);