本文整理匯總了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;
}
}
}
示例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();
}
}
示例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();
}
}
示例4: tryAdd
(result, value) => (
void tryAdd(result, toArgument(value), value),
result
)