refactor(language-service): cleanup of low-hanging TODOs (#34784)

Cleans up some simple TODOs. Also removes
`typescript_symbols#getTypeWrapper`, which I thought I had but failed to
remove in #34571.

PR Close #34784
This commit is contained in:
ayazhafiz 2020-01-14 22:48:13 -08:00 committed by Matias Niemelä
parent 17e98e1678
commit 6c8e322fa1
5 changed files with 18 additions and 46 deletions

View File

@ -220,8 +220,7 @@ export function getExpressionScope(
class ExpressionDiagnosticsVisitor extends RecursiveTemplateAstVisitor {
private path: TemplateAstPath;
// TODO(issue/24571): remove '!'.
private directiveSummary !: CompileDirectiveSummary;
private directiveSummary: CompileDirectiveSummary|undefined;
diagnostics: Diagnostic[] = [];

View File

@ -19,8 +19,7 @@ export class TypeDiagnostic {
// AstType calculatetype of the ast given AST element.
export class AstType implements AstVisitor {
// TODO(issue/24571): remove '!'.
public diagnostics !: TypeDiagnostic[];
public diagnostics: TypeDiagnostic[] = [];
constructor(
private scope: SymbolTable, private query: SymbolQuery,
@ -338,8 +337,7 @@ export class AstType implements AstVisitor {
return this.resolvePropertyRead(this.query.getNonNullableType(this.getType(ast.receiver)), ast);
}
// TODO(issue/24571): remove '!'.
private _anyType !: Symbol;
private _anyType: Symbol|undefined;
private get anyType(): Symbol {
let result = this._anyType;
if (!result) {
@ -348,8 +346,7 @@ export class AstType implements AstVisitor {
return result;
}
// TODO(issue/24571): remove '!'.
private _undefinedType !: Symbol;
private _undefinedType: Symbol|undefined;
private get undefinedType(): Symbol {
let result = this._undefinedType;
if (!result) {

View File

@ -98,8 +98,6 @@ export function locateSymbol(info: AstResult, position: number): SymbolInfo|unde
}
// See if this attribute matches the selector of any directive on the element.
// TODO(ayazhafiz): Consider caching selector matches (at the expense of potentially
// very high memory usage).
const attributeSelector = `[${ast.name}=${ast.value}]`;
const parsedAttribute = CssSelector.parse(attributeSelector);
if (!parsedAttribute.length) return;

View File

@ -82,14 +82,16 @@ export function getPipesTable(
class TypeScriptSymbolQuery implements SymbolQuery {
private typeCache = new Map<BuiltinType, Symbol>();
// TODO(issue/24571): remove '!'.
private pipesCache !: SymbolTable;
private pipesCache: SymbolTable|undefined;
constructor(
private program: ts.Program, private checker: ts.TypeChecker, private source: ts.SourceFile,
private fetchPipes: () => SymbolTable) {}
getTypeKind(symbol: Symbol): BuiltinType { return typeKindOf(this.getTsTypeOf(symbol)); }
getTypeKind(symbol: Symbol): BuiltinType {
const type = symbol instanceof TypeWrapper ? symbol.tsType : undefined;
return typeKindOf(type);
}
getBuiltinType(kind: BuiltinType): Symbol {
let result = this.typeCache.get(kind);
@ -205,21 +207,6 @@ class TypeScriptSymbolQuery implements SymbolQuery {
}
}
}
private getTsTypeOf(symbol: Symbol): ts.Type|undefined {
const type = getTypeWrapper(symbol);
return type && type.tsType;
}
}
function getTypeWrapper(symbol: Symbol): TypeWrapper|undefined {
let type: TypeWrapper|undefined = undefined;
if (symbol instanceof TypeWrapper) {
type = symbol;
} else if (symbol.type instanceof TypeWrapper) {
type = symbol.type;
}
return type;
}
function typeCallable(type: ts.Type): boolean {
@ -290,9 +277,8 @@ class TypeWrapper implements Symbol {
return selectSignature(this.tsType, this.context, types);
}
indexed(argument: Symbol, value: any): Symbol|undefined {
const type = getTypeWrapper(argument);
if (!type) return;
indexed(type: Symbol, value: any): Symbol|undefined {
if (!(type instanceof TypeWrapper)) return;
const typeKind = typeKindOf(type.tsType);
switch (typeKind) {
@ -318,11 +304,7 @@ class TypeWrapper implements Symbol {
const typeReference = (this.tsType as ts.TypeReference);
let typeArguments: ReadonlyArray<ts.Type>|undefined;
if (this.context.checker.getTypeArguments) {
typeArguments = this.context.checker.getTypeArguments(typeReference);
} else {
typeArguments = typeReference.typeArguments;
}
typeArguments = this.context.checker.getTypeArguments(typeReference);
if (!typeArguments) return undefined;
return typeArguments.map(ta => new TypeWrapper(ta, this.context));
}
@ -603,8 +585,7 @@ class PipesTable implements SymbolTable {
const INDEX_PATTERN = /[\\/]([^\\/]+)[\\/]\1\.d\.ts$/;
class PipeSymbol implements Symbol {
// TODO(issue/24571): remove '!'.
private _tsType !: ts.Type;
private _tsType: ts.Type|undefined;
public readonly kind: DeclarationKind = 'pipe';
public readonly language: string = 'typescript';
public readonly container: Symbol|undefined = undefined;

View File

@ -107,14 +107,11 @@ const summaryResolver = new AotSummaryResolver(
staticSymbolCache);
export class DiagnosticContext {
// tslint:disable
// TODO(issue/24571): remove '!'.
_analyzedModules !: NgAnalyzedModules;
_staticSymbolResolver: StaticSymbolResolver|undefined;
_reflector: StaticReflector|undefined;
_errors: {e: any, path?: string}[] = [];
_resolver: CompileMetadataResolver|undefined;
// tslint:enable
private _analyzedModules: NgAnalyzedModules|undefined;
private _staticSymbolResolver: StaticSymbolResolver|undefined;
private _reflector: StaticReflector|undefined;
private _errors: {e: any, path?: string}[] = [];
private _resolver: CompileMetadataResolver|undefined;
constructor(
public service: ts.LanguageService, public program: ts.Program,