本文整理汇总了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
)