From 2572bf508f03c1939641bae9b5bab112b7499f67 Mon Sep 17 00:00:00 2001 From: Tobias Bosch Date: Tue, 15 Aug 2017 14:41:48 -0700 Subject: [PATCH] feat(compiler): make `.ngsummary.json` files portable This also allows to customize the filePaths in `.ngsummary.json` file via the new methods `toSummaryFileName` and `fromSummaryFileName` on the `CompilerHost`. --- packages/compiler-cli/src/compiler_host.ts | 14 +++++--- packages/compiler-cli/src/transformers/api.ts | 14 ++++++++ .../src/transformers/compiler_host.ts | 31 ++++++++++++++++-- .../compiler-cli/src/transformers/program.ts | 8 +++++ .../compiler-cli/test/diagnostics/mocks.ts | 3 +- .../test/transformers/compiler_host_spec.ts | 5 +++ packages/compiler/src/aot/compiler.ts | 13 ++++---- packages/compiler/src/aot/summary_resolver.ts | 24 +++++++++++--- .../compiler/src/aot/summary_serializer.ts | 32 +++++++++++-------- packages/compiler/src/summary_resolver.ts | 10 +++--- .../test/aot/static_symbol_resolver_spec.ts | 3 +- .../test/aot/summary_resolver_spec.ts | 7 ++-- .../test/aot/summary_serializer_spec.ts | 29 ++++++++++------- packages/compiler/test/aot/test_util.ts | 6 ++-- .../language-service/src/typescript_host.ts | 3 +- 15 files changed, 149 insertions(+), 53 deletions(-) diff --git a/packages/compiler-cli/src/compiler_host.ts b/packages/compiler-cli/src/compiler_host.ts index 1367de73a6..588bfd7779 100644 --- a/packages/compiler-cli/src/compiler_host.ts +++ b/packages/compiler-cli/src/compiler_host.ts @@ -42,6 +42,10 @@ export abstract class BaseAotCompilerHost abstract fileNameToModuleName(importedFile: string, containingFile: string): string|null; + abstract toSummaryFileName(fileName: string, referringSrcFileName: string): string; + + abstract fromSummaryFileName(fileName: string, referringLibFileName: string): string; + protected getSourceFile(filePath: string): ts.SourceFile { const sf = this.program.getSourceFile(filePath); if (!sf) { @@ -144,10 +148,6 @@ export abstract class BaseAotCompilerHost return null; } - getOutputFileName(sourceFilePath: string): string { - return sourceFilePath.replace(EXT, '') + '.d.ts'; - } - isSourceFile(filePath: string): boolean { const excludeRegex = this.options.generateCodeForLibraries === false ? GENERATED_OR_DTS_FILES : GENERATED_FILES; @@ -268,6 +268,12 @@ export class CompilerHost extends BaseAotCompilerHost { }; } + toSummaryFileName(fileName: string, referringSrcFileName: string): string { + return fileName.replace(EXT, '') + '.d.ts'; + } + + fromSummaryFileName(fileName: string, referringLibFileName: string): string { return fileName; } + calculateEmitPath(filePath: string): string { // Write codegen in a directory structure matching the sources. let root = this.options.basePath !; diff --git a/packages/compiler-cli/src/transformers/api.ts b/packages/compiler-cli/src/transformers/api.ts index 3567de65fa..fb2a9e4965 100644 --- a/packages/compiler-cli/src/transformers/api.ts +++ b/packages/compiler-cli/src/transformers/api.ts @@ -130,6 +130,20 @@ export interface CompilerHost extends ts.CompilerHost { * See ImportResolver. */ fileNameToModuleName(importedFilePath: string, containingFilePath: string): string|null; + /** + * Converts a file name into a representation that should be stored in a summary file. + * This has to include changing the suffix as well. + * E.g. + * `some_file.ts` -> `some_file.d.ts` + * + * @param referringSrcFileName the soure file that refers to fileName + */ + toSummaryFileName(fileName: string, referringSrcFileName: string): string; + /** + * Converts a fileName that was processed by `toSummaryFileName` back into a real fileName + * given the fileName of the library that is referrig to it. + */ + fromSummaryFileName(fileName: string, referringLibFileName: string): string; /** * Load a referenced resource either statically or asynchronously. If the host returns a * `Promise` it is assumed the user of the corresponding `Program` will call diff --git a/packages/compiler-cli/src/transformers/compiler_host.ts b/packages/compiler-cli/src/transformers/compiler_host.ts index 375b3af80a..a6881e6f24 100644 --- a/packages/compiler-cli/src/transformers/compiler_host.ts +++ b/packages/compiler-cli/src/transformers/compiler_host.ts @@ -24,6 +24,8 @@ export function createCompilerHost( host.moduleNameToFileName = mixin.moduleNameToFileName.bind(mixin); host.fileNameToModuleName = mixin.fileNameToModuleName.bind(mixin); + host.toSummaryFileName = mixin.toSummaryFileName.bind(mixin); + host.fromSummaryFileName = mixin.fromSummaryFileName.bind(mixin); // Make sure we do not `host.realpath()` from TS as we do not want to resolve symlinks. // https://github.com/Microsoft/TypeScript/issues/9552 @@ -109,9 +111,15 @@ class CompilerHostMixin { let moduleName: string; if (importedFilePackagName === containingFilePackageName) { - moduleName = dotRelative( - path.dirname(stripRootDir(this.rootDirs, containingFile)), - stripRootDir(this.rootDirs, importedFile)); + const rootedContainingFile = stripRootDir(this.rootDirs, containingFile); + const rootedImportedFile = stripRootDir(this.rootDirs, importedFile); + + if (rootedContainingFile !== containingFile && rootedImportedFile !== importedFile) { + // if both files are contained in the `rootDirs`, then strip the rootDirs + containingFile = rootedContainingFile; + importedFile = rootedImportedFile; + } + moduleName = dotRelative(path.dirname(containingFile), importedFile); } else if (importedFilePackagName) { moduleName = stripNodeModulesPrefix(importedFile); } else { @@ -120,6 +128,18 @@ class CompilerHostMixin { } return moduleName; } + + toSummaryFileName(fileName: string, referringSrcFileName: string): string { + return this.fileNameToModuleName(fileName, referringSrcFileName); + } + + fromSummaryFileName(fileName: string, referringLibFileName: string): string { + const resolved = this.moduleNameToFileName(fileName, referringLibFileName); + if (!resolved) { + throw new Error(`Could not resolve ${fileName} from ${referringLibFileName}`); + } + return resolved; + } } interface ModuleFilenameResolutionHost extends ts.ModuleResolutionHost { @@ -189,6 +209,11 @@ function stripNodeModulesPrefix(filePath: string): string { return filePath.replace(/.*node_modules\//, ''); } +function getNodeModulesPrefix(filePath: string): string|null { + const match = /.*node_modules\//.exec(filePath); + return match ? match[1] : null; +} + function normalizePath(p: string): string { return path.normalize(path.join(p, '.')).replace(/\\/g, '/'); } \ No newline at end of file diff --git a/packages/compiler-cli/src/transformers/program.ts b/packages/compiler-cli/src/transformers/program.ts index 542f577585..e9c81d6b30 100644 --- a/packages/compiler-cli/src/transformers/program.ts +++ b/packages/compiler-cli/src/transformers/program.ts @@ -314,6 +314,14 @@ class AotCompilerHostImpl extends BaseAotCompilerHost { fileNameToModuleName(importedFile: string, containingFile: string): string|null { return this.context.fileNameToModuleName(importedFile, containingFile); } + + toSummaryFileName(fileName: string, referringSrcFileName: string): string { + return this.context.toSummaryFileName(fileName, referringSrcFileName); + } + + fromSummaryFileName(fileName: string, referringLibFileName: string): string { + return this.context.fromSummaryFileName(fileName, referringLibFileName); + } } export function createProgram( diff --git a/packages/compiler-cli/test/diagnostics/mocks.ts b/packages/compiler-cli/test/diagnostics/mocks.ts index c87acd9f96..979d352e27 100644 --- a/packages/compiler-cli/test/diagnostics/mocks.ts +++ b/packages/compiler-cli/test/diagnostics/mocks.ts @@ -105,7 +105,8 @@ const summaryResolver = new AotSummaryResolver( { loadSummary(filePath: string) { return null; }, isSourceFile(sourceFilePath: string) { return true; }, - getOutputFileName(sourceFilePath: string) { return sourceFilePath; } + toSummaryFileName(sourceFilePath: string) { return sourceFilePath; }, + fromSummaryFileName(filePath: string): string{return filePath;}, }, staticSymbolCache); diff --git a/packages/compiler-cli/test/transformers/compiler_host_spec.ts b/packages/compiler-cli/test/transformers/compiler_host_spec.ts index e0babe55c2..0d226420e6 100644 --- a/packages/compiler-cli/test/transformers/compiler_host_spec.ts +++ b/packages/compiler-cli/test/transformers/compiler_host_spec.ts @@ -67,8 +67,13 @@ describe('NgCompilerHost', () => { ] } }); + // both files are in the rootDirs expect(ngHostWithMultipleRoots.fileNameToModuleName('/tmp/src/b/b.ts', '/tmp/src/a/a.ts')) .toBe('./b'); + + // one file is not in the rootDirs + expect(ngHostWithMultipleRoots.fileNameToModuleName('/tmp/src/c/c.ts', '/tmp/src/a/a.ts')) + .toBe('../c/c'); }); it('should error if accessing a source file from a package', () => { diff --git a/packages/compiler/src/aot/compiler.ts b/packages/compiler/src/aot/compiler.ts index 9a4b870f90..76d3aca8df 100644 --- a/packages/compiler/src/aot/compiler.ts +++ b/packages/compiler/src/aot/compiler.ts @@ -207,10 +207,10 @@ export class AotCompiler { } private _createSummary( - srcFileUrl: string, directives: StaticSymbol[], pipes: StaticSymbol[], + srcFileName: string, directives: StaticSymbol[], pipes: StaticSymbol[], ngModules: StaticSymbol[], injectables: StaticSymbol[], ngFactoryCtx: OutputContext): GeneratedFile[] { - const symbolSummaries = this._symbolResolver.getSymbolsOf(srcFileUrl) + const symbolSummaries = this._symbolResolver.getSymbolsOf(srcFileName) .map(symbol => this._symbolResolver.resolveSymbol(symbol)); const typeData: { summary: CompileTypeSummary, @@ -235,18 +235,19 @@ export class AotCompiler { metadata: this._metadataResolver.getInjectableSummary(ref) !.type })) ]; - const forJitOutputCtx = this._createOutputContext(summaryForJitFileName(srcFileUrl, true)); + const forJitOutputCtx = this._createOutputContext(summaryForJitFileName(srcFileName, true)); const {json, exportAs} = serializeSummaries( - forJitOutputCtx, this._summaryResolver, this._symbolResolver, symbolSummaries, typeData); + srcFileName, forJitOutputCtx, this._summaryResolver, this._symbolResolver, symbolSummaries, + typeData); exportAs.forEach((entry) => { ngFactoryCtx.statements.push( o.variable(entry.exportAs).set(ngFactoryCtx.importExpr(entry.symbol)).toDeclStmt(null, [ o.StmtModifier.Exported ])); }); - const summaryJson = new GeneratedFile(srcFileUrl, summaryFileName(srcFileUrl), json); + const summaryJson = new GeneratedFile(srcFileName, summaryFileName(srcFileName), json); if (this._enableSummariesForJit) { - return [summaryJson, this._codegenSourceModule(srcFileUrl, forJitOutputCtx)]; + return [summaryJson, this._codegenSourceModule(srcFileName, forJitOutputCtx)]; }; return [summaryJson]; diff --git a/packages/compiler/src/aot/summary_resolver.ts b/packages/compiler/src/aot/summary_resolver.ts index 52f7857629..c630675dc7 100644 --- a/packages/compiler/src/aot/summary_resolver.ts +++ b/packages/compiler/src/aot/summary_resolver.ts @@ -23,11 +23,20 @@ export interface AotSummaryResolverHost { */ isSourceFile(sourceFilePath: string): boolean; /** - * Returns the output file path of a source file. + * Converts a file name into a representation that should be stored in a summary file. + * This has to include changing the suffix as well. * E.g. * `some_file.ts` -> `some_file.d.ts` + * + * @param referringSrcFileName the soure file that refers to fileName */ - getOutputFileName(sourceFilePath: string): string; + toSummaryFileName(fileName: string, referringSrcFileName: string): string; + + /** + * Converts a fileName that was processed by `toSummaryFileName` back into a real fileName + * given the fileName of the library that is referrig to it. + */ + fromSummaryFileName(fileName: string, referringLibFileName: string): string; } export class AotSummaryResolver implements SummaryResolver { @@ -46,7 +55,13 @@ export class AotSummaryResolver implements SummaryResolver { return !this.host.isSourceFile(stripGeneratedFileSuffix(filePath)); } - getLibraryFileName(filePath: string) { return this.host.getOutputFileName(filePath); } + toSummaryFileName(filePath: string, referringSrcFileName: string) { + return this.host.toSummaryFileName(filePath, referringSrcFileName); + } + + fromSummaryFileName(fileName: string, referringLibFileName: string) { + return this.host.fromSummaryFileName(fileName, referringLibFileName); + } resolveSummary(staticSymbol: StaticSymbol): Summary { staticSymbol.assertNoMembers(); @@ -85,7 +100,8 @@ export class AotSummaryResolver implements SummaryResolver { throw e; } if (json) { - const {summaries, importAs} = deserializeSummaries(this.staticSymbolCache, json); + const {summaries, importAs} = + deserializeSummaries(this.staticSymbolCache, this, filePath, json); summaries.forEach((summary) => this.summaryCache.set(summary.symbol, summary)); importAs.forEach((importAs) => { this.importAs.set( diff --git a/packages/compiler/src/aot/summary_serializer.ts b/packages/compiler/src/aot/summary_serializer.ts index 11e420a2d1..165c803cbf 100644 --- a/packages/compiler/src/aot/summary_serializer.ts +++ b/packages/compiler/src/aot/summary_serializer.ts @@ -15,7 +15,7 @@ import {ResolvedStaticSymbol, StaticSymbolResolver} from './static_symbol_resolv import {summaryForJitFileName, summaryForJitName} from './util'; export function serializeSummaries( - forJitCtx: OutputContext, summaryResolver: SummaryResolver, + srcFileName: string, forJitCtx: OutputContext, summaryResolver: SummaryResolver, symbolResolver: StaticSymbolResolver, symbols: ResolvedStaticSymbol[], types: { summary: CompileTypeSummary, metadata: CompileNgModuleMetadata | CompileDirectiveMetadata | CompilePipeMetadata | @@ -76,15 +76,17 @@ export function serializeSummaries( }); } }); - const {json, exportAs} = toJsonSerializer.serialize(); + const {json, exportAs} = toJsonSerializer.serialize(srcFileName); forJitSerializer.serialize(exportAs); return {json, exportAs}; } -export function deserializeSummaries(symbolCache: StaticSymbolCache, json: string): +export function deserializeSummaries( + symbolCache: StaticSymbolCache, summaryResolver: SummaryResolver, + libraryFileName: string, json: string): {summaries: Summary[], importAs: {symbol: StaticSymbol, importAs: string}[]} { - const deserializer = new FromJsonDeserializer(symbolCache); - return deserializer.deserialize(json); + const deserializer = new FromJsonDeserializer(symbolCache, summaryResolver); + return deserializer.deserialize(libraryFileName, json); } export function createForJitStub(outputCtx: OutputContext, reference: StaticSymbol) { @@ -151,7 +153,8 @@ class ToJsonSerializer extends ValueTransformer { } } - serialize(): {json: string, exportAs: {symbol: StaticSymbol, exportAs: string}[]} { + serialize(srcFileName: string): + {json: string, exportAs: {symbol: StaticSymbol, exportAs: string}[]} { const exportAs: {symbol: StaticSymbol, exportAs: string}[] = []; const json = JSON.stringify({ summaries: this.processedSummaries, @@ -165,10 +168,7 @@ class ToJsonSerializer extends ValueTransformer { return { __symbol: index, name: symbol.name, - // We convert the source filenames tinto output filenames, - // as the generated summary file will be used when the current - // compilation unit is used as a library - filePath: this.summaryResolver.getLibraryFileName(symbol.filePath), + filePath: this.summaryResolver.toSummaryFileName(symbol.filePath, srcFileName), importAs: importAs }; }) @@ -317,15 +317,21 @@ class ForJitSerializer { class FromJsonDeserializer extends ValueTransformer { private symbols: StaticSymbol[]; - constructor(private symbolCache: StaticSymbolCache) { super(); } + constructor( + private symbolCache: StaticSymbolCache, + private summaryResolver: SummaryResolver) { + super(); + } - deserialize(json: string): + deserialize(libraryFileName: string, json: string): {summaries: Summary[], importAs: {symbol: StaticSymbol, importAs: string}[]} { const data: {summaries: any[], symbols: any[]} = JSON.parse(json); const importAs: {symbol: StaticSymbol, importAs: string}[] = []; this.symbols = []; data.symbols.forEach((serializedSymbol) => { - const symbol = this.symbolCache.get(serializedSymbol.filePath, serializedSymbol.name); + const symbol = this.symbolCache.get( + this.summaryResolver.fromSummaryFileName(serializedSymbol.filePath, libraryFileName), + serializedSymbol.name); this.symbols.push(symbol); if (serializedSymbol.importAs) { importAs.push({symbol: symbol, importAs: serializedSymbol.importAs}); diff --git a/packages/compiler/src/summary_resolver.ts b/packages/compiler/src/summary_resolver.ts index d6246ac9ac..b500910fe7 100644 --- a/packages/compiler/src/summary_resolver.ts +++ b/packages/compiler/src/summary_resolver.ts @@ -17,7 +17,8 @@ export interface Summary { export abstract class SummaryResolver { abstract isLibraryFile(fileName: string): boolean; - abstract getLibraryFileName(fileName: string): string|null; + abstract toSummaryFileName(fileName: string, referringSrcFileName: string): string; + abstract fromSummaryFileName(fileName: string, referringLibFileName: string): string; abstract resolveSummary(reference: T): Summary|null; abstract getSymbolsOf(filePath: string): T[]; abstract getImportAs(reference: T): T; @@ -28,12 +29,13 @@ export abstract class SummaryResolver { export class JitSummaryResolver implements SummaryResolver> { private _summaries = new Map, Summary>>(); - isLibraryFile(fileName: string): boolean { return false; }; - getLibraryFileName(fileName: string): string|null { return null; } + isLibraryFile(): boolean { return false; }; + toSummaryFileName(fileName: string): string { return fileName; } + fromSummaryFileName(fileName: string): string { return fileName; } resolveSummary(reference: Type): Summary>|null { return this._summaries.get(reference) || null; }; - getSymbolsOf(filePath: string): Type[] { return []; } + getSymbolsOf(): Type[] { return []; } getImportAs(reference: Type): Type { return reference; } addSummary(summary: Summary>) { this._summaries.set(summary.symbol, summary); }; } diff --git a/packages/compiler/test/aot/static_symbol_resolver_spec.ts b/packages/compiler/test/aot/static_symbol_resolver_spec.ts index 4ee26ff77c..728de9264f 100644 --- a/packages/compiler/test/aot/static_symbol_resolver_spec.ts +++ b/packages/compiler/test/aot/static_symbol_resolver_spec.ts @@ -386,7 +386,8 @@ export class MockSummaryResolver implements SummaryResolver { } isLibraryFile(filePath: string): boolean { return filePath.endsWith('.d.ts'); } - getLibraryFileName(filePath: string): string { return filePath.replace(/(\.d)?\.ts$/, '.d.ts'); } + toSummaryFileName(filePath: string): string { return filePath.replace(/(\.d)?\.ts$/, '.d.ts'); } + fromSummaryFileName(filePath: string): string { return filePath; } } export class MockStaticSymbolResolverHost implements StaticSymbolResolverHost { diff --git a/packages/compiler/test/aot/summary_resolver_spec.ts b/packages/compiler/test/aot/summary_resolver_spec.ts index 60681bb609..efff637a50 100644 --- a/packages/compiler/test/aot/summary_resolver_spec.ts +++ b/packages/compiler/test/aot/summary_resolver_spec.ts @@ -35,7 +35,8 @@ export function main() { const symbolResolver = new StaticSymbolResolver( new MockStaticSymbolResolverHost({}), symbolCache, mockSummaryResolver); return serializeSummaries( - createMockOutputContext(), mockSummaryResolver, symbolResolver, symbols, []) + 'someFile.ts', createMockOutputContext(), mockSummaryResolver, symbolResolver, + symbols, []) .json; } @@ -105,10 +106,12 @@ export class MockAotSummaryResolverHost implements AotSummaryResolverHost { return './' + path.basename(fileName).replace(EXT, ''); } - getOutputFileName(sourceFileName: string): string { + toSummaryFileName(sourceFileName: string): string { return sourceFileName.replace(EXT, '') + '.d.ts'; } + fromSummaryFileName(filePath: string): string { return filePath; } + isSourceFile(filePath: string) { return !filePath.endsWith('.d.ts'); } loadSummary(filePath: string): string { return this.summaries[filePath]; } diff --git a/packages/compiler/test/aot/summary_serializer_spec.ts b/packages/compiler/test/aot/summary_serializer_spec.ts index 6a177df793..90e8c36d06 100644 --- a/packages/compiler/test/aot/summary_serializer_spec.ts +++ b/packages/compiler/test/aot/summary_serializer_spec.ts @@ -43,7 +43,7 @@ export function main() { it('should serialize various data correctly', () => { init(); const serializedData = serializeSummaries( - createMockOutputContext(), summaryResolver, symbolResolver, + 'someFile.ts', createMockOutputContext(), summaryResolver, symbolResolver, [ { symbol: symbolCache.get('/tmp/some_values.ts', 'Values'), @@ -77,7 +77,9 @@ export function main() { }]); - const summaries = deserializeSummaries(symbolCache, serializedData.json).summaries; + const summaries = + deserializeSummaries(symbolCache, summaryResolver, 'someFile.d.ts', serializedData.json) + .summaries; expect(summaries.length).toBe(2); // Note: change from .ts to .d.ts is expected @@ -105,8 +107,8 @@ export function main() { it('should automatically add exported directives / pipes of NgModules that are not source files', () => { init(); - const externalSerialized = - serializeSummaries(createMockOutputContext(), summaryResolver, symbolResolver, [], [ + const externalSerialized = serializeSummaries( + 'someFile.ts', createMockOutputContext(), summaryResolver, symbolResolver, [], [ { summary: { summaryKind: CompileSummaryKind.Pipe, @@ -133,7 +135,7 @@ export function main() { }); const serialized = serializeSummaries( - createMockOutputContext(), summaryResolver, symbolResolver, [], [{ + 'someFile.ts', createMockOutputContext(), summaryResolver, symbolResolver, [], [{ summary: { summaryKind: CompileSummaryKind.NgModule, type: {reference: symbolCache.get('/tmp/some_module.ts', 'SomeModule')}, @@ -151,7 +153,9 @@ export function main() { metadata: null as any }]); - const summaries = deserializeSummaries(symbolCache, serialized.json).summaries; + const summaries = + deserializeSummaries(symbolCache, summaryResolver, 'someFile.d.ts', serialized.json) + .summaries; expect(summaries.length).toBe(3); expect(summaries[0].symbol).toBe(symbolCache.get('/tmp/some_module.d.ts', 'SomeModule')); expect(summaries[1].symbol).toBe(symbolCache.get('/tmp/external.d.ts', 'SomeExternalDir')); @@ -163,7 +167,7 @@ export function main() { () => { init(); const externalSerialized = serializeSummaries( - createMockOutputContext(), summaryResolver, symbolResolver, + 'someFile.ts', createMockOutputContext(), summaryResolver, symbolResolver, [ { symbol: symbolCache.get('/tmp/external.ts', 'PROVIDERS'), @@ -195,7 +199,7 @@ export function main() { {__symbolic: 'module', version: 3, metadata: {'external': 'b'}} }); const serialized = serializeSummaries( - createMockOutputContext(), summaryResolver, symbolResolver, [{ + 'someFile.ts', createMockOutputContext(), summaryResolver, symbolResolver, [{ symbol: symbolCache.get('/tmp/test.ts', 'main'), metadata: { local: symbolCache.get('/tmp/local.ts', 'local'), @@ -205,7 +209,9 @@ export function main() { }], []); - const summaries = deserializeSummaries(symbolCache, serialized.json).summaries; + const summaries = + deserializeSummaries(symbolCache, summaryResolver, 'someFile.d.ts', serialized.json) + .summaries; // Note: local should not show up! expect(summaries.length).toBe(4); expect(summaries[0].symbol).toBe(symbolCache.get('/tmp/test.d.ts', 'main')); @@ -230,7 +236,7 @@ export function main() { it('should create "importAs" names for non source symbols', () => { init(); const serialized = serializeSummaries( - createMockOutputContext(), summaryResolver, symbolResolver, [{ + 'someFile.ts', createMockOutputContext(), summaryResolver, symbolResolver, [{ symbol: symbolCache.get('/tmp/test.ts', 'main'), metadata: [ symbolCache.get('/tmp/external.d.ts', 'lib'), @@ -243,7 +249,8 @@ export function main() { {symbol: symbolCache.get('/tmp/external.d.ts', 'lib'), exportAs: 'lib_1'} ]); - const deserialized = deserializeSummaries(symbolCache, serialized.json); + const deserialized = + deserializeSummaries(symbolCache, summaryResolver, 'someFile.d.ts', serialized.json); // Note: no entry for the symbol with members! expect(deserialized.importAs).toEqual([ {symbol: symbolCache.get('/tmp/external.d.ts', 'lib'), importAs: 'lib_1'} diff --git a/packages/compiler/test/aot/test_util.ts b/packages/compiler/test/aot/test_util.ts index 7ea8633c78..288aef60d1 100644 --- a/packages/compiler/test/aot/test_util.ts +++ b/packages/compiler/test/aot/test_util.ts @@ -382,9 +382,9 @@ export class MockAotCompilerHost implements AotCompilerHost { (this.dtsAreSource || !DTS.test(sourceFilePath)); } - getOutputFileName(sourceFilePath: string): string { - return sourceFilePath.replace(EXT, '') + '.d.ts'; - } + toSummaryFileName(filePath: string): string { return filePath.replace(EXT, '') + '.d.ts'; } + + fromSummaryFileName(filePath: string): string { return filePath; } // AotCompilerHost fileNameToModuleName(importedFile: string, containingFile: string): string|null { diff --git a/packages/language-service/src/typescript_host.ts b/packages/language-service/src/typescript_host.ts index e91ca3f532..ae6edd4330 100644 --- a/packages/language-service/src/typescript_host.ts +++ b/packages/language-service/src/typescript_host.ts @@ -405,7 +405,8 @@ export class TypeScriptServiceHost implements LanguageServiceHost { { loadSummary(filePath: string) { return null; }, isSourceFile(sourceFilePath: string) { return true; }, - getOutputFileName(sourceFilePath: string) { return sourceFilePath; } + toSummaryFileName(sourceFilePath: string) { return sourceFilePath; }, + fromSummaryFileName(filePath: string): string{return filePath;}, }, this._staticSymbolCache); result = this._staticSymbolResolver = new StaticSymbolResolver(