fix(language-service): improve resilience to incomplete information
This commit is contained in:
parent
5c38012980
commit
71a8627c5d
|
@ -155,7 +155,7 @@ class ExpressionDiagnosticsVisitor extends TemplateAstChildVisitor {
|
||||||
const directive = this.directiveSummary;
|
const directive = this.directiveSummary;
|
||||||
if (directive && ast.value) {
|
if (directive && ast.value) {
|
||||||
const context = this.info.template.query.getTemplateContext(directive.type.reference);
|
const context = this.info.template.query.getTemplateContext(directive.type.reference);
|
||||||
if (!context.has(ast.value)) {
|
if (context && !context.has(ast.value)) {
|
||||||
if (ast.value === '$implicit') {
|
if (ast.value === '$implicit') {
|
||||||
this.reportError(
|
this.reportError(
|
||||||
'The template context does not have an implicit value', spanOf(ast.sourceSpan));
|
'The template context does not have an implicit value', spanOf(ast.sourceSpan));
|
||||||
|
|
|
@ -751,8 +751,10 @@ function toSymbolTable(symbols: ts.Symbol[]): ts.SymbolTable {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
function toSymbols(symbolTable: ts.SymbolTable, filter?: (symbol: ts.Symbol) => boolean) {
|
function toSymbols(
|
||||||
|
symbolTable: ts.SymbolTable | undefined, filter?: (symbol: ts.Symbol) => boolean) {
|
||||||
const result: ts.Symbol[] = [];
|
const result: ts.Symbol[] = [];
|
||||||
|
if (!symbolTable) return result;
|
||||||
const own = typeof symbolTable.hasOwnProperty === 'function' ?
|
const own = typeof symbolTable.hasOwnProperty === 'function' ?
|
||||||
(name: string) => symbolTable.hasOwnProperty(name) :
|
(name: string) => symbolTable.hasOwnProperty(name) :
|
||||||
(name: string) => !!symbolTable[name];
|
(name: string) => !!symbolTable[name];
|
||||||
|
@ -912,8 +914,9 @@ class SymbolTableWrapper implements SymbolTable {
|
||||||
private symbolTable: ts.SymbolTable;
|
private symbolTable: ts.SymbolTable;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
symbols: ts.SymbolTable|ts.Symbol[], private context: TypeContext,
|
symbols: ts.SymbolTable|ts.Symbol[]|undefined, private context: TypeContext,
|
||||||
filter?: (symbol: ts.Symbol) => boolean) {
|
filter?: (symbol: ts.Symbol) => boolean) {
|
||||||
|
symbols = symbols || [];
|
||||||
if (Array.isArray(symbols)) {
|
if (Array.isArray(symbols)) {
|
||||||
this.symbols = filter ? symbols.filter(filter) : symbols;
|
this.symbols = filter ? symbols.filter(filter) : symbols;
|
||||||
this.symbolTable = toSymbolTable(symbols);
|
this.symbolTable = toSymbolTable(symbols);
|
||||||
|
@ -1057,10 +1060,13 @@ class PipeSymbol implements Symbol {
|
||||||
return findClassSymbolInContext(type, this.context);
|
return findClassSymbolInContext(type, this.context);
|
||||||
}
|
}
|
||||||
|
|
||||||
private findTransformMethodType(classSymbol: ts.Symbol): ts.Type {
|
private findTransformMethodType(classSymbol: ts.Symbol): ts.Type|undefined {
|
||||||
const transform = classSymbol.members && classSymbol.members['transform'];
|
const classType = this.context.checker.getDeclaredTypeOfSymbol(classSymbol);
|
||||||
if (transform) {
|
if (classType) {
|
||||||
return this.context.checker.getTypeOfSymbolAtLocation(transform, this.context.node);
|
const transform = classType.getProperty('transform');
|
||||||
|
if (transform) {
|
||||||
|
return this.context.checker.getTypeOfSymbolAtLocation(transform, this.context.node);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue