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