fix(language-service): support TypeScript 2.1 (#13655)
@angular/language-service now supports using TypeScript 2.1 as the the TypeScript host. TypeScript 2.1 is now also partially supported in `ngc` but is not recommended as Tsickle does not yet support 2.1.
This commit is contained in:

committed by
Igor Minar

parent
f1cde4339b
commit
56b4296a09
@ -15,6 +15,8 @@
|
||||
"declaration": true,
|
||||
"lib": ["es6", "dom"],
|
||||
"baseUrl": ".",
|
||||
"outDir": "../node_modules/third_party"
|
||||
}
|
||||
"outDir": "../node_modules/third_party",
|
||||
// Prevent scanning up the directory tree for types
|
||||
"typeRoots": ["node_modules/@types"]
|
||||
}
|
||||
}
|
@ -14,7 +14,9 @@
|
||||
"rootDir": "",
|
||||
"declaration": true,
|
||||
"lib": ["es6", "dom"],
|
||||
"baseUrl": "."
|
||||
"baseUrl": ".",
|
||||
// Prevent scanning up the directory tree for types
|
||||
"typeRoots": ["node_modules/@types"]
|
||||
},
|
||||
|
||||
"files": [
|
||||
|
@ -29,7 +29,17 @@ import {createLanguageService} from './language_service';
|
||||
import {ReflectorHost} from './reflector_host';
|
||||
import {BuiltinType, CompletionKind, Declaration, DeclarationError, Declarations, Definition, LanguageService, LanguageServiceHost, PipeInfo, Pipes, Signature, Span, Symbol, SymbolDeclaration, SymbolQuery, SymbolTable, TemplateSource, TemplateSources} from './types';
|
||||
|
||||
|
||||
// In TypeScript 2.1 these flags moved
|
||||
// These helpers work for both 2.0 and 2.1.
|
||||
const isPrivate = (ts as any).ModifierFlags ?
|
||||
((node: ts.Node) =>
|
||||
!!((ts as any).getCombinedModifierFlags(node) & (ts as any).ModifierFlags.Private)) :
|
||||
((node: ts.Node) => !!(node.flags & (ts as any).NodeFlags.Private));
|
||||
const isReferenceType = (ts as any).ObjectFlags ?
|
||||
((type: ts.Type) =>
|
||||
!!(type.flags & (ts as any).TypeFlags.Object &&
|
||||
(type as any).objectFlags & (ts as any).ObjectFlags.Reference)) :
|
||||
((type: ts.Type) => !!(type.flags & (ts as any).TypeFlags.Reference));
|
||||
|
||||
/**
|
||||
* Create a `LanguageServiceHost`
|
||||
@ -679,7 +689,7 @@ class TypeScriptSymbolQuery implements SymbolQuery {
|
||||
const constructorDeclaration = constructor.declarations[0] as ts.ConstructorTypeNode;
|
||||
for (const parameter of constructorDeclaration.parameters) {
|
||||
const type = this.checker.getTypeAtLocation(parameter.type);
|
||||
if (type.symbol.name == 'TemplateRef' && type.flags & ts.TypeFlags.Reference) {
|
||||
if (type.symbol.name == 'TemplateRef' && isReferenceType(type)) {
|
||||
const typeReference = type as ts.TypeReference;
|
||||
if (typeReference.typeArguments.length === 1) {
|
||||
return typeReference.typeArguments[0].symbol;
|
||||
@ -804,7 +814,7 @@ class SymbolWrapper implements Symbol {
|
||||
|
||||
get public(): boolean {
|
||||
// Symbols that are not explicitly made private are public.
|
||||
return !(getDeclarationFlagsFromSymbol(this.symbol) & ts.NodeFlags.Private);
|
||||
return !isSymbolPrivate(this.symbol);
|
||||
}
|
||||
|
||||
get callable(): boolean { return typeCallable(this.tsType); }
|
||||
@ -1096,10 +1106,8 @@ function getCombinedNodeFlags(node: ts.Node): ts.NodeFlags {
|
||||
return flags;
|
||||
}
|
||||
|
||||
function getDeclarationFlagsFromSymbol(s: ts.Symbol): ts.NodeFlags {
|
||||
return s.valueDeclaration ?
|
||||
getCombinedNodeFlags(s.valueDeclaration) :
|
||||
s.flags & ts.SymbolFlags.Prototype ? ts.NodeFlags.Public | ts.NodeFlags.Static : 0;
|
||||
function isSymbolPrivate(s: ts.Symbol): boolean {
|
||||
return s.valueDeclaration && isPrivate(s.valueDeclaration);
|
||||
}
|
||||
|
||||
function getBuiltinTypeFromTs(kind: BuiltinType, context: TypeContext): ts.Type {
|
||||
@ -1257,4 +1265,4 @@ function typeKindOf(type: ts.Type): BuiltinType {
|
||||
}
|
||||
}
|
||||
return BuiltinType.Other;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user