當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript nodes.isIdentifier函數代碼示例

本文整理匯總了TypeScript中typescripting/nodes.isIdentifier函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript isIdentifier函數的具體用法?TypeScript isIdentifier怎麽用?TypeScript isIdentifier使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了isIdentifier函數的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: apply

function apply(node: ts.Node, state: State): State {
    if (isBinaryExpression(node) && isAssignmentBinaryExpression(node) && isIdentifier(node.left)) {
        const symbol = state.checker.getSymbolAtLocation(node.left);
        if (symbol !== undefined) {
            const id = symbol.id;
            const key = toKey(id);
            const registration = bk.atOrElseAdd(state.all, key, () => ({
                node: undefined,
                wasReassigned: true
            }));
            registration.wasReassigned = true;
        }
    } else if (isVariableDeclaration(node) && isIdentifier(node.name)) {
        const symbol = state.checker.getSymbolAtLocation(node.name);
        if (symbol !== undefined) {
            const registration = bk.atOrElseAdd(state.all, node.name.text, () => ({
                node: undefined,
                wasReassigned: false
            }));
            const hasLetModifier = node.parent !== undefined && (node.parent.flags & ts.NodeFlags.Let) > 0;
            const hasVarModifier = node.parent !== undefined && (node.parent.flags & ts.NodeFlags.Let) === 0 && (node.parent.flags & ts.NodeFlags.Const) === 0;
            registration.node = hasLetModifier || hasVarModifier ? node.name : undefined;
        }
    }
    return state;
}
開發者ID:aleksey-bykov,項目名稱:rules,代碼行數:26,代碼來源:rule.ts

示例2: noUndeclaredSymbols

export default function noUndeclaredSymbols(node: ts.Node, checker: ts.TypeChecker): Issue | void {
    if (isIdentifier(node)) {
        const symbol = checker.getSymbolAtLocation(node);
        if (symbol === undefined) {
            return issueFrom(node, 'undeclared', 'undeclared');
        }
    }
}
開發者ID:aleksey-bykov,項目名稱:rules,代碼行數:8,代碼來源:rule.ts

示例3: nameIdentifierOutOf

// AB: TODO: move to a common place
function nameIdentifierOutOf(node: ts.Node): ts.Identifier | undefined {
    if (isFunctionDeclaration(node)) {
        if (node.name !== undefined) {
            return node.name;
        } else {
            return undefined;
        }
    } else if (isClassDeclaration(node)) {
        if (node.name !== undefined) {
            return node.name;
        } else {
            return undefined;
        }
    } else if (isInterfaceDeclaration(node)) {
        return node.name;
    } else if (isPropertyDeclaration(node)) {
        return isIdentifier(node.name) ? node.name : undefined;
    } else if (isMethodDeclaration(node)) {
        return isIdentifier(node.name) ? node.name : undefined;
    } else {
        return undefined;
    }
}
開發者ID:aleksey-bykov,項目名稱:rules,代碼行數:24,代碼來源:rule.ts

示例4: noConstantLambdas

export default function noConstantLambdas(node: ts.Node, checker: ts.TypeChecker): Issue | void {
    if (isArrowFunction(node)) {
        const body = node.body;

        if (isIdentifier(body)) {
            return isUndefined(body)
                ? issueFrom(body, 'undefined returned', 'no-undefined-lambdas')
                : verifyIdentifier(body, checker);
        }

        if (isStringLiteral(body) || isNumericLiteral(body) || isNullLiteral(body)) {
            return issueFrom(body, 'literal returned', 'no-literal-lambdas');
        }

    }
}
開發者ID:aleksey-bykov,項目名稱:rules,代碼行數:16,代碼來源:rule.ts

示例5: viaTarget

 (node, state) => {
     if (isIdentifier(node)) {
         const identifier = node;
         state.issues = ba.fold(
             state.checks,
             state.issues,
             (issues, rule) => viaTarget(
                 identifier,
                 rule.target,
                 identifier => rule.regex.test(identifier.text)
                     ? bl.add(issues, issueFrom(node, rule.message, 'invalid-name'))
                     : issues,
                 () => issues
             )
         );
     }
     return state;
 }
開發者ID:aleksey-bykov,項目名稱:rules,代碼行數:18,代碼來源:rule.ts

示例6: toNoPrimitiveToSelf

export default function toNoPrimitiveToSelf(node: ts.Node, checker: ts.TypeChecker): Issue | void {
    if (isCallExpression(node)) {
        if (isIdentifier(node.expression)) {
            if (node.arguments.length > 1) {
            } else if (node.arguments.length > 0) {
                if (node.expression.text === 'String') {
                    const argument = node.arguments[0]!;
                    const expressionType = checker.getTypeAtLocation(argument);
                    if (expressionType.flags & ts.TypeFlags.String) {
                        return issueFrom(node, 'string to string conversion', 'string-to-string');
                    }
                } else if (node.expression.text === 'Number') {
                    return issueFrom(node, 'number conversion', 'something-to-number');
                } else if (node.expression.text === 'Boolean') {
                    return issueFrom(node, 'boolean conversion', 'something-to-boolean');
                }
            }
        }
    }
}
開發者ID:aleksey-bykov,項目名稱:rules,代碼行數:20,代碼來源:rule.ts

示例7: havingFirst

 havingFirst('String("hey")', isExpressionStatement, querying => {
     const node = querying.first().sure().hope(isCallExpression).sure().self();
     if (isIdentifier(node.expression)) {
         console.warn(node.expression.text);
     }
 });
開發者ID:aleksey-bykov,項目名稱:rules,代碼行數:6,代碼來源:rule-spec.ts


注:本文中的typescripting/nodes.isIdentifier函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。