build(bazel): make resolveTypeReferenceDirectives override work with both ts 2.9 & ts 3.0 (#25581)

PR Close #25581
This commit is contained in:
Greg Magolan 2018-08-28 13:36:16 -07:00 committed by Misko Hevery
parent 910381ddbd
commit 31349fde90
2 changed files with 16 additions and 6 deletions

View File

@ -19,14 +19,19 @@ export class GeneratedFactoryHostWrapper implements ts.CompilerHost {
private delegate: ts.CompilerHost, private generator: FactoryGenerator, private delegate: ts.CompilerHost, private generator: FactoryGenerator,
private factoryToSourceMap: Map<string, string>) { private factoryToSourceMap: Map<string, string>) {
if (delegate.resolveTypeReferenceDirectives) { if (delegate.resolveTypeReferenceDirectives) {
// Backward compatibility with TypeScript 2.9 and older since return
// type has changed from (ts.ResolvedTypeReferenceDirective | undefined)[]
// to ts.ResolvedTypeReferenceDirective[] in Typescript 3.0
type ts3ResolveTypeReferenceDirectives = (names: string[], containingFile: string) =>
ts.ResolvedTypeReferenceDirective[];
this.resolveTypeReferenceDirectives = (names: string[], containingFile: string) => this.resolveTypeReferenceDirectives = (names: string[], containingFile: string) =>
delegate.resolveTypeReferenceDirectives !(names, containingFile); (delegate.resolveTypeReferenceDirectives as ts3ResolveTypeReferenceDirectives) !(
names, containingFile);
} }
} }
resolveTypeReferenceDirectives?: resolveTypeReferenceDirectives?:
(names: string[], (names: string[], containingFile: string) => ts.ResolvedTypeReferenceDirective[];
containingFile: string) => (ts.ResolvedTypeReferenceDirective | undefined)[];
getSourceFile( getSourceFile(
fileName: string, languageVersion: ts.ScriptTarget, fileName: string, languageVersion: ts.ScriptTarget,

View File

@ -79,8 +79,7 @@ export class TsCompilerAotCompilerTypeCheckHostAdapter implements ts.CompilerHos
// TODO(issue/24571): remove '!'. // TODO(issue/24571): remove '!'.
getDirectories !: (path: string) => string[]; getDirectories !: (path: string) => string[];
resolveTypeReferenceDirectives?: resolveTypeReferenceDirectives?:
(names: string[], (names: string[], containingFile: string) => ts.ResolvedTypeReferenceDirective[];
containingFile: string) => (ts.ResolvedTypeReferenceDirective | undefined)[];
directoryExists?: (directoryName: string) => boolean; directoryExists?: (directoryName: string) => boolean;
constructor( constructor(
@ -106,8 +105,14 @@ export class TsCompilerAotCompilerTypeCheckHostAdapter implements ts.CompilerHos
this.getDefaultLibLocation = () => context.getDefaultLibLocation !(); this.getDefaultLibLocation = () => context.getDefaultLibLocation !();
} }
if (context.resolveTypeReferenceDirectives) { if (context.resolveTypeReferenceDirectives) {
// Backward compatibility with TypeScript 2.9 and older since return
// type has changed from (ts.ResolvedTypeReferenceDirective | undefined)[]
// to ts.ResolvedTypeReferenceDirective[] in Typescript 3.0
type ts3ResolveTypeReferenceDirectives = (names: string[], containingFile: string) =>
ts.ResolvedTypeReferenceDirective[];
this.resolveTypeReferenceDirectives = (names: string[], containingFile: string) => this.resolveTypeReferenceDirectives = (names: string[], containingFile: string) =>
context.resolveTypeReferenceDirectives !(names, containingFile); (context.resolveTypeReferenceDirectives as ts3ResolveTypeReferenceDirectives) !(
names, containingFile);
} }
if (context.trace) { if (context.trace) {
this.trace = s => context.trace !(s); this.trace = s => context.trace !(s);