fix(language-service): improve resilience to incomplete information

This commit is contained in:
Chuck Jazdzewski 2017-03-30 10:44:20 -07:00 committed by Alex Rickabaugh
parent 5c38012980
commit 71a8627c5d
2 changed files with 13 additions and 7 deletions

View File

@ -155,7 +155,7 @@ class ExpressionDiagnosticsVisitor extends TemplateAstChildVisitor {
const directive = this.directiveSummary;
if (directive && ast.value) {
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') {
this.reportError(
'The template context does not have an implicit value', spanOf(ast.sourceSpan));

View File

@ -751,8 +751,10 @@ function toSymbolTable(symbols: ts.Symbol[]): ts.SymbolTable {
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[] = [];
if (!symbolTable) return result;
const own = typeof symbolTable.hasOwnProperty === 'function' ?
(name: string) => symbolTable.hasOwnProperty(name) :
(name: string) => !!symbolTable[name];
@ -912,8 +914,9 @@ class SymbolTableWrapper implements SymbolTable {
private symbolTable: ts.SymbolTable;
constructor(
symbols: ts.SymbolTable|ts.Symbol[], private context: TypeContext,
symbols: ts.SymbolTable|ts.Symbol[]|undefined, private context: TypeContext,
filter?: (symbol: ts.Symbol) => boolean) {
symbols = symbols || [];
if (Array.isArray(symbols)) {
this.symbols = filter ? symbols.filter(filter) : symbols;
this.symbolTable = toSymbolTable(symbols);
@ -1057,12 +1060,15 @@ class PipeSymbol implements Symbol {
return findClassSymbolInContext(type, this.context);
}
private findTransformMethodType(classSymbol: ts.Symbol): ts.Type {
const transform = classSymbol.members && classSymbol.members['transform'];
private findTransformMethodType(classSymbol: ts.Symbol): ts.Type|undefined {
const classType = this.context.checker.getDeclaredTypeOfSymbol(classSymbol);
if (classType) {
const transform = classType.getProperty('transform');
if (transform) {
return this.context.checker.getTypeOfSymbolAtLocation(transform, this.context.node);
}
}
}
}
function findClassSymbolInContext(type: StaticSymbol, context: TypeContext): ts.Symbol {