Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return type.getProperties().every(property => {
if (property.flags & ts.SymbolFlags.Property) {
// simple property / field
return true;
}
const declarations = property.getDeclarations() || [];
if (declarations.length === 0) {
return false;
}
const declaration = declarations[0];
return declaration.kind === ts.SyntaxKind.MethodDeclaration ||
(declaration.kind === ts.SyntaxKind.Constructor && !!(declaration as ts.ConstructorDeclaration).body);
});
}
constructor(options: IAstItemOptions) {
super(options);
this._classLikeDeclaration = options.declaration as ts.ClassLikeDeclaration;
this.type = this.typeChecker.getDeclaredTypeOfSymbol(this.declarationSymbol);
if (this.declarationSymbol.flags & ts.SymbolFlags.Interface) {
this.kind = AstItemKind.Interface;
} else if (this.declarationSymbol.flags & ts.SymbolFlags.TypeLiteral) {
this.kind = AstItemKind.TypeLiteral;
} else {
this.kind = AstItemKind.Class;
}
for (const memberDeclaration of this._classLikeDeclaration.members || []) {
const memberSymbol: ts.Symbol = TypeScriptHelpers.getSymbolForDeclaration(memberDeclaration);
if (memberSymbol) {
this._processMember(memberSymbol, memberDeclaration);
} else {
// If someone put an extra semicolon after their function, we don't care about that
if (memberDeclaration.kind !== ts.SyntaxKind.SemicolonClassElement) {
// If there is some other non-semantic junk, add a warning so we can investigate it
this.reportWarning(PrettyPrinter.formatFileAndLineNumber(memberDeclaration)
function symbolFlagsToString(type: typescript.Symbol) {
return Object.keys(typescript.SymbolFlags).filter(
// @ts-ignore
flagName => type.flags & typescript.SymbolFlags[flagName]
);
}
memberDoc.typeParameters = getTypeParameters(typeChecker, memberSymbol);
if(memberSymbol.flags & (ts.SymbolFlags.Signature) ) {
memberDoc.parameters = getParameters(typeChecker, memberSymbol);
memberDoc.returnType = getReturnType(typeChecker, memberSymbol);
switch(memberDoc.name) {
case '__call':
memberDoc.name = '';
break;
case '__new':
memberDoc.name = 'new';
break;
}
}
if (memberSymbol.flags & ts.SymbolFlags.Method) {
// NOTE: we use the property name `parameters` here so we don't conflict
// with the `params` property that will be updated by dgeni reading the
// `@param` tags from the docs
memberDoc.parameters = getParameters(typeChecker, memberSymbol);
}
if (memberSymbol.flags & ts.SymbolFlags.Constructor) {
memberDoc.parameters = getParameters(typeChecker, memberSymbol);
memberDoc.name = 'constructor';
}
if(memberSymbol.flags & ts.SymbolFlags.Value) {
memberDoc.returnType = getReturnType(typeChecker, memberSymbol);
}
if(memberSymbol.flags & ts.SymbolFlags.Optional) {
memberDoc.typeParameters = getTypeParameters(typeChecker, memberSymbol);
if(memberSymbol.flags & (ts.SymbolFlags.Signature) ) {
memberDoc.parameters = getParameters(typeChecker, declaration);
memberDoc.returnType = getReturnType(typeChecker, declaration);
switch(memberDoc.name) {
case '__call':
memberDoc.name = '';
break;
case '__new':
memberDoc.name = 'new';
break;
}
}
if (memberSymbol.flags & ts.SymbolFlags.Method) {
// NOTE: we use the property name `parameters` here so we don't conflict
// with the `params` property that will be updated by dgeni reading the
// `@param` tags from the docs
memberDoc.parameters = getParameters(typeChecker, declaration);
}
if (memberSymbol.flags & ts.SymbolFlags.Constructor) {
memberDoc.parameters = getParameters(typeChecker, declaration);
memberDoc.name = 'constructor';
}
if(memberSymbol.flags & ts.SymbolFlags.Value) {
memberDoc.returnType = getReturnType(typeChecker, declaration);
}
if(memberSymbol.flags & ts.SymbolFlags.Optional) {
symbolToString(sym: ts.Symbol): string|undefined {
// TypeScript resolves e.g. union types to their members, which can include symbols not declared
// in the current scope. Ensure that all symbols found this way are actually declared.
// This must happen before the alias check below, it might introduce a new alias for the symbol.
if (!this.isForExterns && (sym.flags & ts.SymbolFlags.TypeParameter) === 0) {
this.ensureSymbolDeclared(sym);
}
const name = this.typeChecker.symbolToEntityName(
sym, ts.SymbolFlags.Type, this.node, ts.NodeBuilderFlags.UseFullyQualifiedType);
// name might be undefined, e.g. for anonymous classes.
if (!name) return undefined;
// TypeScript's symbolToEntityName returns a tree of Identifier objects. tsickle needs to
// identify and alias specifiy symbols on it. The code below accesses the TypeScript @internal
// symbol field on Identifier to do so.
type IdentifierWithSymbol = ts.Identifier&{symbol: ts.Symbol};
let str = '';
/** Recursively visits components of entity name and writes them to `str` above. */
const writeEntityWithSymbols = (name: ts.EntityName) => {
let identifier: IdentifierWithSymbol;
exportSymbol.declarations.forEach(function(decl) {
var sourceFile = ts.getSourceFileOfNode(decl);
if (decl.typeParameters) {
typeParamString = '<' + getText(sourceFile, decl.typeParameters) + '>';
}
if (decl.symbol.flags & ts.SymbolFlags.TypeAlias) {
typeDefinition = getText(sourceFile, decl.type);
}
if (decl.heritageClauses) {
decl.heritageClauses.forEach(function(heritage) {
if (heritage.token == ts.SyntaxKind.ExtendsKeyword) {
heritageString += " extends";
heritage.types.forEach(function(typ, idx) {
heritageString += (idx > 0 ? ',' : '') + typ.getFullText();
});
}
if (heritage.token == ts.SyntaxKind.ImplementsKeyword) {
heritageString += " implements";
heritage.types.forEach(function(typ, idx) {
public getDeclarationLine(): string {
let result: string = '';
if (this.kind !== AstItemKind.TypeLiteral) {
result += (this.declarationSymbol.flags & ts.SymbolFlags.Interface)
? 'interface ' : 'class ';
result += this.name;
if (this._classLikeDeclaration.typeParameters) {
result += '<';
result += this._classLikeDeclaration.typeParameters
.map((param: ts.TypeParameterDeclaration) => param.getText())
.join(', ');
result += '>';
}
if (this._classLikeDeclaration.heritageClauses) {
result += ' ';
static getActiveSymbolFlags(value: ts.SymbolFlags, skipExcludes: boolean) {
let active = new Array();
if ((value & ts.SymbolFlags.None) !== 0) active.push('None');
if ((value & ts.SymbolFlags.FunctionScopedVariable) !== 0) active.push('FunctionScopedVariable');
if ((value & ts.SymbolFlags.BlockScopedVariable) !== 0) active.push('BlockScopedVariable');
if ((value & ts.SymbolFlags.Property) !== 0) active.push('Property');
if ((value & ts.SymbolFlags.EnumMember) !== 0) active.push('EnumMember');
if ((value & ts.SymbolFlags.Function) !== 0) active.push('Function');
if ((value & ts.SymbolFlags.Class) !== 0) active.push('Class');
if ((value & ts.SymbolFlags.Interface) !== 0) active.push('Interface');
if ((value & ts.SymbolFlags.ConstEnum) !== 0) active.push('ConstEnum');
if ((value & ts.SymbolFlags.RegularEnum) !== 0) active.push('RegularEnum');
if ((value & ts.SymbolFlags.ValueModule) !== 0) active.push('ValueModule');
if ((value & ts.SymbolFlags.NamespaceModule) !== 0) active.push('NamespaceModule');
if ((value & ts.SymbolFlags.TypeLiteral) !== 0) active.push('TypeLiteral');
if ((value & ts.SymbolFlags.ObjectLiteral) !== 0) active.push('ObjectLiteral');
if ((value & ts.SymbolFlags.Method) !== 0) active.push('Method');
if ((value & ts.SymbolFlags.Constructor) !== 0) active.push('Constructor');
if ((value & ts.SymbolFlags.GetAccessor) !== 0) active.push('GetAccessor');
if ((value & ts.SymbolFlags.SetAccessor) !== 0) active.push('SetAccessor');
if ((value & ts.SymbolFlags.Signature) !== 0) active.push('Signature');
if ((value & ts.SymbolFlags.TypeParameter) !== 0) active.push('TypeParameter');
function isFunction (flags?: ts.SymbolFlags) {
return SymbolFlags.includes((flags || -1) - ts.SymbolFlags.Function)
}