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:
parent
17e98e1678
commit
6c8e322fa1
|
@ -220,8 +220,7 @@ export function getExpressionScope(
|
||||||
|
|
||||||
class ExpressionDiagnosticsVisitor extends RecursiveTemplateAstVisitor {
|
class ExpressionDiagnosticsVisitor extends RecursiveTemplateAstVisitor {
|
||||||
private path: TemplateAstPath;
|
private path: TemplateAstPath;
|
||||||
// TODO(issue/24571): remove '!'.
|
private directiveSummary: CompileDirectiveSummary|undefined;
|
||||||
private directiveSummary !: CompileDirectiveSummary;
|
|
||||||
|
|
||||||
diagnostics: Diagnostic[] = [];
|
diagnostics: Diagnostic[] = [];
|
||||||
|
|
||||||
|
|
|
@ -19,8 +19,7 @@ export class TypeDiagnostic {
|
||||||
|
|
||||||
// AstType calculatetype of the ast given AST element.
|
// AstType calculatetype of the ast given AST element.
|
||||||
export class AstType implements AstVisitor {
|
export class AstType implements AstVisitor {
|
||||||
// TODO(issue/24571): remove '!'.
|
public diagnostics: TypeDiagnostic[] = [];
|
||||||
public diagnostics !: TypeDiagnostic[];
|
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private scope: SymbolTable, private query: SymbolQuery,
|
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);
|
return this.resolvePropertyRead(this.query.getNonNullableType(this.getType(ast.receiver)), ast);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(issue/24571): remove '!'.
|
private _anyType: Symbol|undefined;
|
||||||
private _anyType !: Symbol;
|
|
||||||
private get anyType(): Symbol {
|
private get anyType(): Symbol {
|
||||||
let result = this._anyType;
|
let result = this._anyType;
|
||||||
if (!result) {
|
if (!result) {
|
||||||
|
@ -348,8 +346,7 @@ export class AstType implements AstVisitor {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(issue/24571): remove '!'.
|
private _undefinedType: Symbol|undefined;
|
||||||
private _undefinedType !: Symbol;
|
|
||||||
private get undefinedType(): Symbol {
|
private get undefinedType(): Symbol {
|
||||||
let result = this._undefinedType;
|
let result = this._undefinedType;
|
||||||
if (!result) {
|
if (!result) {
|
||||||
|
|
|
@ -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.
|
// 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 attributeSelector = `[${ast.name}=${ast.value}]`;
|
||||||
const parsedAttribute = CssSelector.parse(attributeSelector);
|
const parsedAttribute = CssSelector.parse(attributeSelector);
|
||||||
if (!parsedAttribute.length) return;
|
if (!parsedAttribute.length) return;
|
||||||
|
|
|
@ -82,14 +82,16 @@ export function getPipesTable(
|
||||||
|
|
||||||
class TypeScriptSymbolQuery implements SymbolQuery {
|
class TypeScriptSymbolQuery implements SymbolQuery {
|
||||||
private typeCache = new Map<BuiltinType, Symbol>();
|
private typeCache = new Map<BuiltinType, Symbol>();
|
||||||
// TODO(issue/24571): remove '!'.
|
private pipesCache: SymbolTable|undefined;
|
||||||
private pipesCache !: SymbolTable;
|
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private program: ts.Program, private checker: ts.TypeChecker, private source: ts.SourceFile,
|
private program: ts.Program, private checker: ts.TypeChecker, private source: ts.SourceFile,
|
||||||
private fetchPipes: () => SymbolTable) {}
|
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 {
|
getBuiltinType(kind: BuiltinType): Symbol {
|
||||||
let result = this.typeCache.get(kind);
|
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 {
|
function typeCallable(type: ts.Type): boolean {
|
||||||
|
@ -290,9 +277,8 @@ class TypeWrapper implements Symbol {
|
||||||
return selectSignature(this.tsType, this.context, types);
|
return selectSignature(this.tsType, this.context, types);
|
||||||
}
|
}
|
||||||
|
|
||||||
indexed(argument: Symbol, value: any): Symbol|undefined {
|
indexed(type: Symbol, value: any): Symbol|undefined {
|
||||||
const type = getTypeWrapper(argument);
|
if (!(type instanceof TypeWrapper)) return;
|
||||||
if (!type) return;
|
|
||||||
|
|
||||||
const typeKind = typeKindOf(type.tsType);
|
const typeKind = typeKindOf(type.tsType);
|
||||||
switch (typeKind) {
|
switch (typeKind) {
|
||||||
|
@ -318,11 +304,7 @@ class TypeWrapper implements Symbol {
|
||||||
|
|
||||||
const typeReference = (this.tsType as ts.TypeReference);
|
const typeReference = (this.tsType as ts.TypeReference);
|
||||||
let typeArguments: ReadonlyArray<ts.Type>|undefined;
|
let typeArguments: ReadonlyArray<ts.Type>|undefined;
|
||||||
if (this.context.checker.getTypeArguments) {
|
typeArguments = this.context.checker.getTypeArguments(typeReference);
|
||||||
typeArguments = this.context.checker.getTypeArguments(typeReference);
|
|
||||||
} else {
|
|
||||||
typeArguments = typeReference.typeArguments;
|
|
||||||
}
|
|
||||||
if (!typeArguments) return undefined;
|
if (!typeArguments) return undefined;
|
||||||
return typeArguments.map(ta => new TypeWrapper(ta, this.context));
|
return typeArguments.map(ta => new TypeWrapper(ta, this.context));
|
||||||
}
|
}
|
||||||
|
@ -603,8 +585,7 @@ class PipesTable implements SymbolTable {
|
||||||
const INDEX_PATTERN = /[\\/]([^\\/]+)[\\/]\1\.d\.ts$/;
|
const INDEX_PATTERN = /[\\/]([^\\/]+)[\\/]\1\.d\.ts$/;
|
||||||
|
|
||||||
class PipeSymbol implements Symbol {
|
class PipeSymbol implements Symbol {
|
||||||
// TODO(issue/24571): remove '!'.
|
private _tsType: ts.Type|undefined;
|
||||||
private _tsType !: ts.Type;
|
|
||||||
public readonly kind: DeclarationKind = 'pipe';
|
public readonly kind: DeclarationKind = 'pipe';
|
||||||
public readonly language: string = 'typescript';
|
public readonly language: string = 'typescript';
|
||||||
public readonly container: Symbol|undefined = undefined;
|
public readonly container: Symbol|undefined = undefined;
|
||||||
|
|
|
@ -107,14 +107,11 @@ const summaryResolver = new AotSummaryResolver(
|
||||||
staticSymbolCache);
|
staticSymbolCache);
|
||||||
|
|
||||||
export class DiagnosticContext {
|
export class DiagnosticContext {
|
||||||
// tslint:disable
|
private _analyzedModules: NgAnalyzedModules|undefined;
|
||||||
// TODO(issue/24571): remove '!'.
|
private _staticSymbolResolver: StaticSymbolResolver|undefined;
|
||||||
_analyzedModules !: NgAnalyzedModules;
|
private _reflector: StaticReflector|undefined;
|
||||||
_staticSymbolResolver: StaticSymbolResolver|undefined;
|
private _errors: {e: any, path?: string}[] = [];
|
||||||
_reflector: StaticReflector|undefined;
|
private _resolver: CompileMetadataResolver|undefined;
|
||||||
_errors: {e: any, path?: string}[] = [];
|
|
||||||
_resolver: CompileMetadataResolver|undefined;
|
|
||||||
// tslint:enable
|
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
public service: ts.LanguageService, public program: ts.Program,
|
public service: ts.LanguageService, public program: ts.Program,
|
||||||
|
|
Loading…
Reference in New Issue