Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async function visit(
// tslint:disable-next-line:no-any
tf: any, checker: ts.TypeChecker, node: ts.Node,
sourceFile: ts.SourceFile) {
const children = node.getChildren();
for (let i = 0; i < children.length; i++) {
await visit(tf, checker, children[i], sourceFile);
}
if (ts.isClassDeclaration(node) || ts.isFunctionDeclaration(node) ||
ts.isMethodDeclaration(node) || ts.isInterfaceDeclaration(node)) {
const symbol = checker.getSymbolAtLocation(node.name);
const jsdoc = getJSDocTag(symbol);
if (jsdoc == null) {
return;
}
// Ignore snippets of methods that have been marked with ignoreCI.
if (jsdoc['ignoreCI']) {
return;
}
const documentation = symbol.getDocumentationComment(checker);
if (documentation == null) {
return;
}
for (let i = 0; i < documentation.length; i++) {
ConcreteDeclaration {
const ngModule = fn.ngModule;
// For external module references, use the declaration as is.
if (ngModule.viaModule !== null) {
return ngModule;
}
// For internal (non-library) module references, redirect the module's value declaration
// to its type declaration.
const dtsNgModule = this.host.getDtsDeclaration(ngModule.node);
if (!dtsNgModule) {
throw new Error(
`No typings declaration can be found for the referenced NgModule class in ${fn.declaration.getText()}.`);
}
if (!ts.isClassDeclaration(dtsNgModule) || !hasNameIdentifier(dtsNgModule)) {
throw new Error(
`The referenced NgModule in ${fn.declaration.getText()} is not a named class declaration in the typings program; instead we get ${dtsNgModule.getText()}`);
}
return {node: dtsNgModule, viaModule: null};
}
}
function visit(node) {
if (ts.isClassDeclaration(node) || ts.isClassExpression(node)) {
const symbol = node.name ? checker.getSymbolAtLocation(node.name) : node.symbol;
let className = symbol.getName();
if (className === '__class') {
let parent = node;
while (parent.parent)
parent = parent.parent;
className = path.basename(parent.fileName, '.js');
}
if (className && !excludeClasses.has(className)) {
classes.push(serializeClass(className, symbol, node));
const parentClassName = parentClass(node);
if (parentClassName)
inheritance.set(className, parentClassName);
excludeClasses.add(className);
}
function getParentClassProperty(func: ts.FunctionLikeDeclaration) {
const propertyNode = getPropertyNodeForFunction(func);
if (propertyNode) {
const parent = propertyNode.parent;
if (ts.isClassDeclaration(parent) || ts.isClassExpression(parent)) {
return parent;
}
}
return null;
}
hasBaseClass(clazz: ClassDeclaration): boolean {
return (ts.isClassDeclaration(clazz) || ts.isClassExpression(clazz)) &&
clazz.heritageClauses !== undefined &&
clazz.heritageClauses.some(clause => clause.token === ts.SyntaxKind.ExtendsKeyword);
}
private handleSourceFile(node: ts.Node, sourceFile: ts.SourceFile) {
const jsDocs = this.getJsDocs(node, sourceFile)
const entry = jsDocs.find(jsDoc => jsDoc.name === 'entry')
if (ts.isTypeAliasDeclaration(node)) {
this.handleTypeAliasDeclaration(node, jsDocs, entry, sourceFile)
} else if (ts.isInterfaceDeclaration(node) || ts.isClassDeclaration(node)) {
this.handleInterfaceOrClassDeclaration(node, jsDocs, entry, sourceFile)
} else if (ts.isFunctionDeclaration(node)) {
this.handleFunctionDeclaration(node, jsDocs, sourceFile)
}
}
if (ts.isInterfaceDeclaration(statement)) {
return {
...info,
kind: 'interface',
extends: getHeritageClauseText(statement, ts.SyntaxKind.ExtendsKeyword),
members: parseMembers(statement.members),
};
} else if (ts.isTypeAliasDeclaration(statement)) {
return {
...info,
type: statement.type,
kind: 'typeAlias',
members: ts.isTypeLiteralNode(statement.type) ? parseMembers(statement.type.members) : undefined,
};
} else if (ts.isClassDeclaration(statement)) {
return {
...info,
kind: 'class',
members: parseMembers(statement.members),
extends: getHeritageClauseText(statement, ts.SyntaxKind.ExtendsKeyword),
implements: getHeritageClauseText(statement, ts.SyntaxKind.ImplementsKeyword),
};
}
}
export function getStructType(type: ts.ObjectType, isOpaque: boolean, generator: LLVMGenerator) {
const { context, module, checker } = generator;
const elements = getStoredProperties(type, checker).map(property =>
getLLVMType(checker.getTypeAtLocation(property.valueDeclaration), generator)
);
const declaration = type.symbol.declarations[0];
let struct: llvm.StructType | null;
if (ts.isClassDeclaration(declaration)) {
const name = mangleType(type, checker);
struct = module.getTypeByName(name);
if (!struct) {
struct = llvm.StructType.create(context, name);
if (!isOpaque) {
struct.setBody(elements);
}
}
} else {
struct = llvm.StructType.get(context, elements);
}
return struct;
}
function maybeUnwrapNameOfDeclaration(decl: ts.Declaration): ts.Declaration|ts.Identifier {
if ((ts.isClassDeclaration(decl) || ts.isVariableDeclaration(decl)) && decl.name !== undefined &&
ts.isIdentifier(decl.name)) {
return decl.name;
}
return decl;
}
private _getTypeOfResolvedValue(value: ResolvedValue): string|undefined {
if (value instanceof Map && this.isModuleWithProvidersType(value)) {
const mapValue = value.get('ngModule') !;
if (mapValue instanceof Reference && ts.isClassDeclaration(mapValue.node) &&
mapValue.node.name) {
return mapValue.node.name.text;
} else if (mapValue instanceof DynamicValue) {
addTodoToNode(mapValue.node, TODO_COMMENT);
this._updateNode(mapValue.node, mapValue.node);
}
}
return undefined;
}