本文整理匯總了TypeScript中ts-simple-ast.TypeGuards類的典型用法代碼示例。如果您正苦於以下問題:TypeScript TypeGuards類的具體用法?TypeScript TypeGuards怎麽用?TypeScript TypeGuards使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了TypeGuards類的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: getExtra
function getExtra(node: Node) {
const extras = []
if (TypeGuards.isJsxTagNamedNode(node)) {
extras.push(node.getTagNameNode().getText().match(/^[a-z]/) ? 'JSXIntrinsicElement' : 'JSXNonIntrinsicElement')
}
const parent = node.getParent()
if (parent && TypeGuards.isJsxTagNamedNode(parent)) {
extras.push(parent.getTagNameNode().getText().match(/^[a-z]/) ? 'JSXIntrinsicElementChild' : 'JSXNonIntrinsicElementChild')
}
return extras.length ? extras : undefined
}
示例2:
currentSourceFile.forEachChild(node => {
if (TypeGuards.isAmbientableNode(node)) {
node.setHasDeclareKeyword(false);
}
if (TypeGuards.isExportableNode(node)) {
const nodeSymbol = node.getSymbol();
if (
nodeSymbol &&
!exportedSymbols.has(nodeSymbol.getFullyQualifiedName())
) {
node.setIsExported(false);
}
}
});
示例3: getLineNumberAndOffset
.map(({ start, end }) => {
const { offset, line: startLineNumber } = getLineNumberAndOffset(start, lines, node)
const { line: endLineNumber } = getLineNumberAndOffset(end, lines, node)
return {
startLineNumber,
// Heads up : following sum fixes an error of original implementation when JSXText has multiple lines:
endLineNumber: endLineNumber + (TypeGuards.isJsxText(node) && node.getText().includes('\n') ? -1 : 0),
startColumn: start + 1 - offset,
endColumn: end + 1 - offset,
}
})
示例4:
sourceFile.forEachChild(node => {
if (TypeGuards.isExpressionStatement(node)) {
const firstChild = node.getFirstChild();
if (!firstChild) {
return;
}
if (TypeGuards.isBinaryExpression(firstChild)) {
const leftExpression = firstChild.getLeft();
if (
TypeGuards.isPropertyAccessExpression(leftExpression) &&
leftExpression.getExpression().getText() === globalVarName
) {
const globalVarProperty = leftExpression.getName();
if (globalVarProperty !== globalVarName) {
globalVariables.set(globalVarProperty, {
type: firstChild.getType(),
node
});
}
}
}
}
});
示例5: createDeclarationFile
export function createDeclarationFile(project: Project) {
const globalFile = project.addExistingSourceFile("../../shared/lib/global.d.ts");
const declarationFile = project.createSourceFile("ts-nameof.macro.d.ts", "", { overwrite: true });
const namespaceDec = declarationFile.addNamespace({
name: `"ts-nameof.macro"`,
declarationKind: NamespaceDeclarationKind.Module,
hasDeclareKeyword: true
});
namespaceDec.setBodyText(globalFile.getFullText());
for (const statement of namespaceDec.getStatements()) {
if (TypeGuards.isAmbientableNode(statement))
statement.setHasDeclareKeyword(false);
}
namespaceDec.addExportAssignment({
expression: "nameof",
isExportEquals: false
});
}