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


TypeScript keyed.tryAdd函數代碼示例

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


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

示例1: shouldImmediateNodeBeConsidered

function shouldImmediateNodeBeConsidered(ruleKey: string, node: ts.Node, per: PerNode): boolean {
    const id = node.id;
    if (id !== undefined) {
        // AB: nodes without ID should probably be considere (not sure what it means)
        return true;
    } else {
        const key = '_' + id;
        const previousInstructions = bk.at(per.nodes, key);
        if (previousInstructions === undefined) {
            const comments = leadingCommentsStrippedOutOf(node);
            if (comments.length > 0) {
                const freshlyMadeInstructions = instructionsOutOfComments(comments);
                bk.tryAdd(
                    per.nodes,
                    key,
                    freshlyMadeInstructions
                );
                return ba.hasAnyLike(freshlyMadeInstructions, ruleKey, bb.areStringsEqual) ? false : true;
            } else {
                // AB: there are no comments assigned to the node, it means no special instructions
                bk.tryAdd(
                    per.nodes,
                    key,
                    comments // AB: we can reuse empty comments for empty special instructions
                );
                return true;
            }
        } else {
            // AB: we got some special instructions previously assigned to the node
            return ba.hasAnyLike(previousInstructions, ruleKey, bb.areStringsEqual) ? false : true;
        }
    }
}
開發者ID:aleksey-bykov,項目名稱:linting,代碼行數:33,代碼來源:per-node-rule.ts

示例2: skipArgument

 function skipArgument(parsing: LooselyParsing): $Taken<null> {
     const { parsed, options } = parsing;
     if (isLooselyParsedParameter(parsed)) {
         const { result } = parsed;
         const args = parsed.isFull ? result.fullArgs : result.shortArgs;
         if (bk.tryAdd(args, parsed.name, null)) {
             return luck(
                 looselyParsingFrom(
                     options,
                     result
                 ),
                 null
             );
         } else {
             return fail(unexpectedParameterName, 'A parameter with the same "' + parsed.name + '" was already specified.');
         }
     } else {
         return toFailedToFindBuilderInParameterState();
     }
 }
開發者ID:aleksey-bykov,項目名稱:commandlining,代碼行數:20,代碼來源:loose-builder.ts

示例3: takeArgument

    function takeArgument(parsing: LooselyParsing, token: Token): $Taken<AfterArgument> {
        const { parsed, options } = parsing;
        if (isLooselyParsedParameter(parsed)) {
            const { result } = parsed;
            const args = parsed.isFull ? result.fullArgs : result.shortArgs;
            const value = tokenToString(token)
            if (bk.tryAdd(args, parsed.name, value)) {

                return luck(
                    looselyParsingFrom(
                        options,
                        result
                    ),
                    mightNeedParameter
                );
            } else {
                return fail(unexpectedParameterName, 'A parameter with the same "' + parsed.name + '" was already specified.');
            }
        } else {
            return toFailedToFindBuilderInParameterState();
        }
    }
開發者ID:aleksey-bykov,項目名稱:commandlining,代碼行數:22,代碼來源:loose-builder.ts

示例4: tryAdd

 (result, value) => (
     void tryAdd(result, toArgument(value), value),
     result
 )
開發者ID:aleksey-bykov,項目名稱:commandlining,代碼行數:4,代碼來源:arguments.ts


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