From 8bb42df47e58399d75303b121e7bdc9c28ec692b Mon Sep 17 00:00:00 2001 From: Chuck Jazdzewski Date: Tue, 28 Nov 2017 11:20:30 -0800 Subject: [PATCH] fix(compiler): correctly detect when to serialze summary metadata (#20668) The change to improve error messages broke the summary serialization of summaries. PR Close #20668 --- .../compiler/src/aot/summary_serializer.ts | 6 ++-- .../test/aot/summary_serializer_spec.ts | 36 +++++++++++++++++++ 2 files changed, 39 insertions(+), 3 deletions(-) diff --git a/packages/compiler/src/aot/summary_serializer.ts b/packages/compiler/src/aot/summary_serializer.ts index e2abf3018b..195a58c737 100644 --- a/packages/compiler/src/aot/summary_serializer.ts +++ b/packages/compiler/src/aot/summary_serializer.ts @@ -11,7 +11,7 @@ import {Summary, SummaryResolver} from '../summary_resolver'; import {OutputContext, ValueTransformer, ValueVisitor, visitValue} from '../util'; import {StaticSymbol, StaticSymbolCache} from './static_symbol'; -import {ResolvedStaticSymbol, StaticSymbolResolver} from './static_symbol_resolver'; +import {ResolvedStaticSymbol, StaticSymbolResolver, unwrapResolvedMetadata} from './static_symbol_resolver'; import {isLoweredSymbol, ngfactoryFilePath, summaryForJitFileName, summaryForJitName} from './util'; export function serializeSummaries( @@ -453,10 +453,10 @@ function isCall(metadata: any): boolean { } function isFunctionCall(metadata: any): boolean { - return isCall(metadata) && metadata.expression instanceof StaticSymbol; + return isCall(metadata) && unwrapResolvedMetadata(metadata.expression) instanceof StaticSymbol; } function isMethodCallOnVariable(metadata: any): boolean { return isCall(metadata) && metadata.expression && metadata.expression.__symbolic === 'select' && - metadata.expression.expression instanceof StaticSymbol; + unwrapResolvedMetadata(metadata.expression.expression) instanceof StaticSymbol; } diff --git a/packages/compiler/test/aot/summary_serializer_spec.ts b/packages/compiler/test/aot/summary_serializer_spec.ts index 6610e72dc3..1ad1ebbafe 100644 --- a/packages/compiler/test/aot/summary_serializer_spec.ts +++ b/packages/compiler/test/aot/summary_serializer_spec.ts @@ -430,5 +430,41 @@ export function main() { importAs: symbolCache.get('someFile.ngfactory.d.ts', 'lib_1') }]); }); + + describe('with resolved symbols', () => { + it('should be able to serialize a call', () => { + init(); + const serialized = serializeSummaries( + 'someFile.ts', createMockOutputContext(), summaryResolver, symbolResolver, [{ + symbol: symbolCache.get('/tmp/test.ts', 'main'), + metadata: { + __symbolic: 'call', + expression: + {__symbolic: 'resolved', symbol: symbolCache.get('/tmp/test2.ts', 'ref')} + } + }], + []); + expect(serialized.json).not.toContain('error'); + }); + + it('should be able to serialize a call to a method', () => { + init(); + const serialized = serializeSummaries( + 'someFile.ts', createMockOutputContext(), summaryResolver, symbolResolver, [{ + symbol: symbolCache.get('/tmp/test.ts', 'main'), + metadata: { + __symbolic: 'call', + expression: { + __symbolic: 'select', + expression: + {__symbolic: 'resolved', symbol: symbolCache.get('/tmp/test2.ts', 'ref')}, + name: 'foo' + } + } + }], + []); + expect(serialized.json).not.toContain('error'); + }); + }); }); }