From e55738f54726f11ade3822e8c0f60188b467499b Mon Sep 17 00:00:00 2001 From: Jerko Steiner Date: Sun, 11 Aug 2019 23:14:14 +0700 Subject: [PATCH] Remove unused comments from typecheck.ts TODO: figure out how to determine locations of used: a) interfaces b) type aliases c) union types d) complex types like Array There should be two scenarios: a) Type is imported from a library b) Type is imported from an adjacent module c) Type is privately declared in current module --- .../scripts/src/commands/intergen.sample.ts | 1 + packages/scripts/src/commands/typecheck.ts | 36 ++++++------------- 2 files changed, 12 insertions(+), 25 deletions(-) diff --git a/packages/scripts/src/commands/intergen.sample.ts b/packages/scripts/src/commands/intergen.sample.ts index 0a3b2ec..2a9b08e 100644 --- a/packages/scripts/src/commands/intergen.sample.ts +++ b/packages/scripts/src/commands/intergen.sample.ts @@ -53,4 +53,5 @@ export class Typed { a!: ITyped b!: ITyped c!: ITyped + d!: ITyped | ITyped } diff --git a/packages/scripts/src/commands/typecheck.ts b/packages/scripts/src/commands/typecheck.ts index aa5c194..1910ca9 100644 --- a/packages/scripts/src/commands/typecheck.ts +++ b/packages/scripts/src/commands/typecheck.ts @@ -44,37 +44,22 @@ export function typecheck() { // This is a top level class, get its symbol const symbol = checker.getSymbolAtLocation(node.name) if (symbol) { + console.log('===') + console.log('text', node.getText(node.getSourceFile())) console.log('class', symbol.getName()) - - // console.log('symbolToString', checker.symbolToString(symbol)) - - // const tpd = checker.symbolToTypeParameterDeclarations(symbol) - // if (tpd) { - // console.log(' type params: %o', tpd.map(t => { - // ts.getCombinedModifierFlags(t.symbol.valueDeclaration) - // return { - // name: t.name.text, - // constraint: !!t.constraint, - // default: !!t.default, - // // constraint: !!t.constraint - // // ? checker.getTypeFromTypeNode(t.constraint) - // // : undefined, - // } - // })) - // } - const type = checker.getDeclaredTypeOfSymbol(symbol) if (type.isClassOrInterface() && type.typeParameters) { type.typeParameters.forEach(tp => { - console.log('tp.symbol.name', tp.symbol.name) + console.log(' tp.symbol.name', tp.symbol.name) const constraint = tp.getConstraint() if (constraint) { - console.log('tp.constraint', checker.typeToString(constraint)) + console.log(' tp.constraint', + checker.typeToString(constraint)) } const def = tp.getDefault() if (def) { - console.log('tp.default', checker.typeToString(def)) + console.log(' tp.default', checker.typeToString(def)) } }) } @@ -92,21 +77,22 @@ export function typecheck() { }) .map(p => { const propType = checker - .getTypeOfSymbolAtLocation(p, p.valueDeclaration!) + .getTypeOfSymbolAtLocation(p, p.valueDeclaration) return { name: p.getName(), type: checker.typeToString(propType), classOrIface: propType.isClassOrInterface(), + union: propType.isUnion(), } })) // output.push(serializeClass(symbol)) } // No need to walk any further, class expressions/inner declarations // cannot be exported - } else if (ts.isModuleDeclaration(node)) { - // This is a namespace, visit its children - ts.forEachChild(node, visit) + // } else if (ts.isModuleDeclaration(node)) { + // // This is a namespace, visit its children + // ts.forEachChild(node, visit) } }