From 5614c4ff0fbfc7e856849d1f539934f46b4bca4b Mon Sep 17 00:00:00 2001 From: Tobias Bosch Date: Mon, 5 Dec 2016 13:35:24 -0800 Subject: [PATCH] fix(compiler): serialize any `StaticSymbol` correctly, not matter in which context. --- .../compiler/src/aot/summary_resolver.ts | 4 +-- .../test/aot/summary_resolver_spec.ts | 31 ++++++++++--------- 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/modules/@angular/compiler/src/aot/summary_resolver.ts b/modules/@angular/compiler/src/aot/summary_resolver.ts index 7f9709bc4f..cfe651bda5 100644 --- a/modules/@angular/compiler/src/aot/summary_resolver.ts +++ b/modules/@angular/compiler/src/aot/summary_resolver.ts @@ -43,7 +43,7 @@ export class AotSummaryResolver implements SummaryResolver { serializeSummaries(srcFileUrl: string, summaries: CompileTypeSummary[]): GeneratedFile { const jsonReplacer = (key: string, value: any) => { - if (key === 'reference' && value instanceof StaticSymbol) { + if (value instanceof StaticSymbol) { // We convert the source filenames into output filenames, // as the generated summary file will be used when the current // compilation unit is used as a library @@ -84,7 +84,7 @@ export class AotSummaryResolver implements SummaryResolver { if (!summary) { try { const jsonReviver = (key: string, value: any) => { - if (key === 'reference' && value && value['__symbolic__'] === 'symbol') { + if (value && value['__symbolic__'] === 'symbol') { // Note: We can't use staticReflector.findDeclaration here: // Summary files can contain symbols of transitive compilation units // (via the providers), and findDeclaration needs .metadata.json / .d.ts files, diff --git a/modules/@angular/compiler/test/aot/summary_resolver_spec.ts b/modules/@angular/compiler/test/aot/summary_resolver_spec.ts index f2f2c7acdc..cc22a84847 100644 --- a/modules/@angular/compiler/test/aot/summary_resolver_spec.ts +++ b/modules/@angular/compiler/test/aot/summary_resolver_spec.ts @@ -36,31 +36,34 @@ export function main() { expect(resolver.serializeSummaries('a.js', []).genFileUrl).toBe('a.ngsummary.json'); }); - it('should serialize summary for .ts files and deserialize based on .d.ts files', () => { + it('should serialize various data correctly', () => { init(); const serializedData = resolver.serializeSummaries( - '/tmp/some_pipe.ts', [{ + '/tmp/some_pipe.ts', [{ summaryKind: CompileSummaryKind.Pipe, type: { reference: staticReflector.getStaticSymbol('/tmp/some_pipe.ts', 'SomePipe'), - diDeps: [], - lifecycleHooks: [] }, + aNumber: 1, + aString: 'hello', + anArray: [1, 2], + aStaticSymbol: + staticReflector.getStaticSymbol('/tmp/some_symbol.ts', 'someName', ['someMember']) }]); // Note: this creates a new staticReflector! init({[serializedData.genFileUrl]: serializedData.source}); - expect(resolver.resolveSummary( - staticReflector.getStaticSymbol('/tmp/some_pipe.d.ts', 'SomePipe'))) - .toEqual({ - summaryKind: CompileSummaryKind.Pipe, - type: { - reference: staticReflector.getStaticSymbol('/tmp/some_pipe.d.ts', 'SomePipe'), - diDeps: [], - lifecycleHooks: [] - }, - }); + const deserialized = resolver.resolveSummary( + staticReflector.getStaticSymbol('/tmp/some_pipe.d.ts', 'SomePipe')); + expect(deserialized.aNumber).toBe(1); + expect(deserialized.aString).toBe('hello'); + expect(deserialized.anArray).toEqual([1, 2]); + expect(deserialized.aStaticSymbol instanceof StaticSymbol).toBe(true); + // Note: change from .ts to .d.ts is expected + expect(deserialized.aStaticSymbol) + .toEqual( + staticReflector.getStaticSymbol('/tmp/some_symbol.d.ts', 'someName', ['someMember'])); }); it('should store reexports in the same file', () => {