2016-12-15 12:12:40 -05:00
|
|
|
/**
|
|
|
|
* @license
|
2020-05-19 15:08:49 -04:00
|
|
|
* Copyright Google LLC All Rights Reserved.
|
2016-12-15 12:12:40 -05:00
|
|
|
*
|
|
|
|
* Use of this source code is governed by an MIT-style license that can be
|
|
|
|
* found in the LICENSE file at https://angular.io/license
|
|
|
|
*/
|
|
|
|
|
|
|
|
import {AotSummaryResolver, AotSummaryResolverHost, CompileSummaryKind, StaticSymbol, StaticSymbolCache, StaticSymbolResolver, StaticSymbolResolverHost} from '@angular/compiler';
|
2017-09-26 16:31:59 -04:00
|
|
|
import {METADATA_VERSION} from '@angular/compiler-cli';
|
2016-12-27 12:36:47 -05:00
|
|
|
import {deserializeSummaries, serializeSummaries} from '@angular/compiler/src/aot/summary_serializer';
|
|
|
|
import {summaryFileName} from '@angular/compiler/src/aot/util';
|
2016-12-15 12:12:40 -05:00
|
|
|
|
|
|
|
import {MockStaticSymbolResolverHost} from './static_symbol_resolver_spec';
|
2020-04-08 13:14:18 -04:00
|
|
|
import {createMockOutputContext, MockAotSummaryResolverHost} from './summary_resolver_spec';
|
2016-12-15 12:12:40 -05:00
|
|
|
|
|
|
|
|
2017-12-16 17:42:55 -05:00
|
|
|
{
|
2016-12-15 12:12:40 -05:00
|
|
|
describe('summary serializer', () => {
|
|
|
|
let summaryResolver: AotSummaryResolver;
|
|
|
|
let symbolResolver: StaticSymbolResolver;
|
|
|
|
let symbolCache: StaticSymbolCache;
|
|
|
|
let host: MockAotSummaryResolverHost;
|
|
|
|
|
2020-04-08 13:14:18 -04:00
|
|
|
beforeEach(() => {
|
|
|
|
symbolCache = new StaticSymbolCache();
|
|
|
|
});
|
2016-12-15 12:12:40 -05:00
|
|
|
|
|
|
|
function init(
|
|
|
|
summaries: {[filePath: string]: string} = {}, metadata: {[key: string]: any} = {}) {
|
|
|
|
host = new MockAotSummaryResolverHost(summaries);
|
|
|
|
summaryResolver = new AotSummaryResolver(host, symbolCache);
|
|
|
|
symbolResolver = new StaticSymbolResolver(
|
|
|
|
new MockStaticSymbolResolverHost(metadata), symbolCache, summaryResolver);
|
|
|
|
}
|
|
|
|
|
|
|
|
describe('summaryFileName', () => {
|
|
|
|
it('should add .ngsummary.json to the filename', () => {
|
|
|
|
init();
|
|
|
|
expect(summaryFileName('a.ts')).toBe('a.ngsummary.json');
|
|
|
|
expect(summaryFileName('a.d.ts')).toBe('a.ngsummary.json');
|
|
|
|
expect(summaryFileName('a.js')).toBe('a.ngsummary.json');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should serialize various data correctly', () => {
|
|
|
|
init();
|
|
|
|
const serializedData = serializeSummaries(
|
2017-08-15 17:41:48 -04:00
|
|
|
'someFile.ts', createMockOutputContext(), summaryResolver, symbolResolver,
|
2016-12-15 12:12:40 -05:00
|
|
|
[
|
|
|
|
{
|
|
|
|
symbol: symbolCache.get('/tmp/some_values.ts', 'Values'),
|
|
|
|
metadata: {
|
|
|
|
aNumber: 1,
|
|
|
|
aString: 'hello',
|
|
|
|
anArray: [1, 2],
|
2016-12-27 12:36:47 -05:00
|
|
|
aStaticSymbol: symbolCache.get('/tmp/some_symbol.ts', 'someName'),
|
|
|
|
aStaticSymbolWithMembers:
|
|
|
|
symbolCache.get('/tmp/some_symbol.ts', 'someName', ['someMember']),
|
2016-12-15 12:12:40 -05:00
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
symbol: symbolCache.get('/tmp/some_service.ts', 'SomeService'),
|
|
|
|
metadata: {
|
|
|
|
__symbolic: 'class',
|
|
|
|
members: {'aMethod': {__symbolic: 'function'}},
|
2017-03-30 17:51:29 -04:00
|
|
|
statics: {aStatic: true},
|
|
|
|
decorators: ['aDecoratorData']
|
2016-12-15 12:12:40 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
],
|
2017-04-26 12:24:42 -04:00
|
|
|
[{
|
|
|
|
summary: {
|
|
|
|
summaryKind: CompileSummaryKind.Injectable,
|
|
|
|
type: {
|
|
|
|
reference: symbolCache.get('/tmp/some_service.ts', 'SomeService'),
|
|
|
|
}
|
|
|
|
} as any,
|
|
|
|
metadata: null as any
|
2016-12-15 12:12:40 -05:00
|
|
|
}]);
|
|
|
|
|
|
|
|
|
2017-08-15 17:41:48 -04:00
|
|
|
const summaries =
|
|
|
|
deserializeSummaries(symbolCache, summaryResolver, 'someFile.d.ts', serializedData.json)
|
|
|
|
.summaries;
|
2016-12-15 12:12:40 -05:00
|
|
|
expect(summaries.length).toBe(2);
|
|
|
|
|
|
|
|
// Note: change from .ts to .d.ts is expected
|
|
|
|
expect(summaries[0].symbol).toBe(symbolCache.get('/tmp/some_values.d.ts', 'Values'));
|
|
|
|
expect(summaries[0].metadata).toEqual({
|
|
|
|
aNumber: 1,
|
|
|
|
aString: 'hello',
|
|
|
|
anArray: [1, 2],
|
2016-12-27 12:36:47 -05:00
|
|
|
aStaticSymbol: symbolCache.get('/tmp/some_symbol.d.ts', 'someName'),
|
|
|
|
aStaticSymbolWithMembers:
|
|
|
|
symbolCache.get('/tmp/some_symbol.d.ts', 'someName', ['someMember'])
|
2016-12-15 12:12:40 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
expect(summaries[1].symbol).toBe(symbolCache.get('/tmp/some_service.d.ts', 'SomeService'));
|
2017-03-30 17:51:29 -04:00
|
|
|
// serialization should drop class decorators
|
|
|
|
expect(summaries[1].metadata).toEqual({
|
|
|
|
__symbolic: 'class',
|
|
|
|
members: {aMethod: {__symbolic: 'function'}},
|
|
|
|
statics: {aStatic: true}
|
|
|
|
});
|
2020-04-08 13:14:18 -04:00
|
|
|
expect(summaries[1].type!.type.reference)
|
2016-12-15 12:12:40 -05:00
|
|
|
.toBe(symbolCache.get('/tmp/some_service.d.ts', 'SomeService'));
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should automatically add exported directives / pipes of NgModules that are not source files',
|
|
|
|
() => {
|
2016-12-27 12:36:47 -05:00
|
|
|
init();
|
2017-08-15 17:41:48 -04:00
|
|
|
const externalSerialized = serializeSummaries(
|
2017-08-22 20:07:55 -04:00
|
|
|
'someFile.ts', createMockOutputContext(), summaryResolver, symbolResolver,
|
|
|
|
[
|
|
|
|
{symbol: symbolCache.get('/tmp/external.ts', 'SomeExternalPipe'), metadata: null},
|
|
|
|
{symbol: symbolCache.get('/tmp/external.ts', 'SomeExternalDir'), metadata: null},
|
|
|
|
],
|
|
|
|
[
|
2017-05-16 19:30:37 -04:00
|
|
|
{
|
|
|
|
summary: {
|
|
|
|
summaryKind: CompileSummaryKind.Pipe,
|
|
|
|
type: {
|
|
|
|
reference: symbolCache.get('/tmp/external.ts', 'SomeExternalPipe'),
|
|
|
|
}
|
|
|
|
} as any,
|
|
|
|
metadata: null as any
|
2017-04-26 12:24:42 -04:00
|
|
|
},
|
2017-05-16 19:30:37 -04:00
|
|
|
{
|
|
|
|
summary: {
|
|
|
|
summaryKind: CompileSummaryKind.Directive,
|
|
|
|
type: {
|
|
|
|
reference: symbolCache.get('/tmp/external.ts', 'SomeExternalDir'),
|
|
|
|
},
|
|
|
|
providers: [],
|
|
|
|
viewProviders: [],
|
|
|
|
} as any,
|
|
|
|
metadata: null as any
|
|
|
|
}
|
|
|
|
]);
|
2016-12-15 12:12:40 -05:00
|
|
|
init({
|
2016-12-27 12:36:47 -05:00
|
|
|
'/tmp/external.ngsummary.json': externalSerialized.json,
|
2016-12-15 12:12:40 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
const serialized = serializeSummaries(
|
2017-08-22 20:07:55 -04:00
|
|
|
'someFile.ts', createMockOutputContext(), summaryResolver, symbolResolver,
|
|
|
|
[
|
|
|
|
{symbol: symbolCache.get('/tmp/some_module.ts', 'SomeModule'), metadata: null},
|
|
|
|
],
|
|
|
|
[{
|
2017-04-26 12:24:42 -04:00
|
|
|
summary: <any>{
|
|
|
|
summaryKind: CompileSummaryKind.NgModule,
|
|
|
|
type: {reference: symbolCache.get('/tmp/some_module.ts', 'SomeModule')},
|
|
|
|
exportedPipes: [
|
|
|
|
{reference: symbolCache.get('/tmp/some_pipe.ts', 'SomePipe')},
|
|
|
|
{reference: symbolCache.get('/tmp/external.d.ts', 'SomeExternalPipe')}
|
|
|
|
],
|
|
|
|
exportedDirectives: [
|
|
|
|
{reference: symbolCache.get('/tmp/some_dir.ts', 'SomeDir')},
|
|
|
|
{reference: symbolCache.get('/tmp/external.d.ts', 'SomeExternalDir')}
|
|
|
|
],
|
|
|
|
providers: [],
|
|
|
|
modules: [],
|
|
|
|
},
|
|
|
|
metadata: null as any
|
2016-12-15 12:12:40 -05:00
|
|
|
}]);
|
2017-08-15 17:41:48 -04:00
|
|
|
const summaries =
|
|
|
|
deserializeSummaries(symbolCache, summaryResolver, 'someFile.d.ts', serialized.json)
|
|
|
|
.summaries;
|
2017-08-22 20:07:55 -04:00
|
|
|
init({
|
|
|
|
'/tmp/some_module.ngsummary.json': serialized.json,
|
|
|
|
});
|
|
|
|
|
|
|
|
const serializedReexport = serializeSummaries(
|
|
|
|
'someFile.ts', createMockOutputContext(), summaryResolver, symbolResolver,
|
|
|
|
[
|
|
|
|
{
|
|
|
|
symbol: symbolCache.get('/tmp/some_reexport.ts', 'ReexportModule'),
|
|
|
|
metadata: symbolCache.get('/tmp/some_module.d.ts', 'SomeModule')
|
|
|
|
},
|
|
|
|
],
|
|
|
|
[]);
|
|
|
|
|
2016-12-15 12:12:40 -05:00
|
|
|
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'));
|
|
|
|
expect(summaries[2].symbol)
|
|
|
|
.toBe(symbolCache.get('/tmp/external.d.ts', 'SomeExternalPipe'));
|
2017-08-22 20:07:55 -04:00
|
|
|
|
|
|
|
const reexportSummaries =
|
|
|
|
deserializeSummaries(
|
|
|
|
symbolCache, summaryResolver, 'someFile.d.ts', serializedReexport.json)
|
|
|
|
.summaries;
|
|
|
|
expect(reexportSummaries.length).toBe(4);
|
|
|
|
expect(reexportSummaries[0].symbol)
|
|
|
|
.toBe(symbolCache.get('/tmp/some_reexport.d.ts', 'ReexportModule'));
|
|
|
|
expect(reexportSummaries[1].symbol)
|
|
|
|
.toBe(symbolCache.get('/tmp/some_module.d.ts', 'SomeModule'));
|
|
|
|
expect(reexportSummaries[2].symbol)
|
|
|
|
.toBe(symbolCache.get('/tmp/external.d.ts', 'SomeExternalDir'));
|
|
|
|
expect(reexportSummaries[3].symbol)
|
|
|
|
.toBe(symbolCache.get('/tmp/external.d.ts', 'SomeExternalPipe'));
|
2016-12-15 12:12:40 -05:00
|
|
|
});
|
|
|
|
|
2017-03-22 23:24:34 -04:00
|
|
|
it('should automatically add the metadata of referenced symbols that are not in the source files',
|
2016-12-15 12:12:40 -05:00
|
|
|
() => {
|
2016-12-27 12:36:47 -05:00
|
|
|
init();
|
2016-12-15 12:12:40 -05:00
|
|
|
const externalSerialized = serializeSummaries(
|
2017-08-15 17:41:48 -04:00
|
|
|
'someFile.ts', createMockOutputContext(), summaryResolver, symbolResolver,
|
2016-12-15 12:12:40 -05:00
|
|
|
[
|
|
|
|
{
|
|
|
|
symbol: symbolCache.get('/tmp/external.ts', 'PROVIDERS'),
|
|
|
|
metadata: [symbolCache.get('/tmp/external_svc.ts', 'SomeService')]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
symbol: symbolCache.get('/tmp/external_svc.ts', 'SomeService'),
|
|
|
|
metadata: {__symbolic: 'class'}
|
2017-08-22 20:07:55 -04:00
|
|
|
},
|
|
|
|
// Note: This is an important usecase when using ng1 and ng2 together via
|
|
|
|
// goog.module.
|
|
|
|
// In these cases, users write the following to get a referrable symbol in metadata
|
|
|
|
// collection:
|
|
|
|
// import UsernameService from 'goog:somePackage.UsernameService';
|
|
|
|
// export {UsernameService};
|
|
|
|
{
|
|
|
|
symbol: symbolCache.get('/tmp/external.ts', 'ReexportNonExistent'),
|
|
|
|
metadata: symbolCache.get('/tmp/external.ts', 'NonExistent'),
|
2016-12-15 12:12:40 -05:00
|
|
|
}
|
|
|
|
],
|
2017-04-26 12:24:42 -04:00
|
|
|
[{
|
|
|
|
summary: {
|
|
|
|
summaryKind: CompileSummaryKind.Injectable,
|
|
|
|
type: {
|
|
|
|
reference: symbolCache.get('/tmp/external_svc.ts', 'SomeService'),
|
|
|
|
}
|
|
|
|
} as any,
|
|
|
|
metadata: null as any
|
2016-12-15 12:12:40 -05:00
|
|
|
}]);
|
|
|
|
init(
|
|
|
|
{
|
2016-12-27 12:36:47 -05:00
|
|
|
'/tmp/external.ngsummary.json': externalSerialized.json,
|
2016-12-15 12:12:40 -05:00
|
|
|
},
|
|
|
|
{
|
|
|
|
'/tmp/local.ts': `
|
|
|
|
export var local = 'a';
|
|
|
|
`,
|
|
|
|
'/tmp/non_summary.d.ts':
|
2017-09-26 16:31:59 -04:00
|
|
|
{__symbolic: 'module', version: METADATA_VERSION, metadata: {'external': 'b'}}
|
2016-12-15 12:12:40 -05:00
|
|
|
});
|
|
|
|
const serialized = serializeSummaries(
|
2017-08-15 17:41:48 -04:00
|
|
|
'someFile.ts', createMockOutputContext(), summaryResolver, symbolResolver, [{
|
2016-12-15 12:12:40 -05:00
|
|
|
symbol: symbolCache.get('/tmp/test.ts', 'main'),
|
|
|
|
metadata: {
|
|
|
|
local: symbolCache.get('/tmp/local.ts', 'local'),
|
|
|
|
external: symbolCache.get('/tmp/external.d.ts', 'PROVIDERS'),
|
2017-08-22 20:07:55 -04:00
|
|
|
externalNonSummary: symbolCache.get('/tmp/non_summary.d.ts', 'external'),
|
|
|
|
reexportNonExistent: symbolCache.get('/tmp/external.ts', 'ReexportNonExistent'),
|
2016-12-15 12:12:40 -05:00
|
|
|
}
|
|
|
|
}],
|
|
|
|
[]);
|
|
|
|
|
2017-08-15 17:41:48 -04:00
|
|
|
const summaries =
|
|
|
|
deserializeSummaries(symbolCache, summaryResolver, 'someFile.d.ts', serialized.json)
|
|
|
|
.summaries;
|
2016-12-15 12:12:40 -05:00
|
|
|
// Note: local should not show up!
|
|
|
|
expect(summaries.length).toBe(4);
|
|
|
|
expect(summaries[0].symbol).toBe(symbolCache.get('/tmp/test.d.ts', 'main'));
|
|
|
|
expect(summaries[0].metadata).toEqual({
|
|
|
|
local: symbolCache.get('/tmp/local.d.ts', 'local'),
|
|
|
|
external: symbolCache.get('/tmp/external.d.ts', 'PROVIDERS'),
|
2017-08-22 20:07:55 -04:00
|
|
|
externalNonSummary: symbolCache.get('/tmp/non_summary.d.ts', 'external'),
|
|
|
|
reexportNonExistent: symbolCache.get('/tmp/external.d.ts', 'ReexportNonExistent'),
|
2016-12-15 12:12:40 -05:00
|
|
|
});
|
|
|
|
expect(summaries[1].symbol).toBe(symbolCache.get('/tmp/external.d.ts', 'PROVIDERS'));
|
|
|
|
expect(summaries[1].metadata).toEqual([symbolCache.get(
|
|
|
|
'/tmp/external_svc.d.ts', 'SomeService')]);
|
2017-03-22 23:24:34 -04:00
|
|
|
// SomService is a transitive dep, but should have been serialized as well.
|
2017-08-22 20:07:55 -04:00
|
|
|
expect(summaries[2].symbol).toBe(symbolCache.get('/tmp/external_svc.d.ts', 'SomeService'));
|
2020-04-08 13:14:18 -04:00
|
|
|
expect(summaries[2].type!.type.reference)
|
2016-12-15 12:12:40 -05:00
|
|
|
.toBe(symbolCache.get('/tmp/external_svc.d.ts', 'SomeService'));
|
2017-08-22 20:07:55 -04:00
|
|
|
// there was no summary for non_summary, but it should have
|
|
|
|
// been serialized as well.
|
|
|
|
expect(summaries[3].symbol).toBe(symbolCache.get('/tmp/non_summary.d.ts', 'external'));
|
|
|
|
expect(summaries[3].metadata).toEqual('b');
|
2016-12-15 12:12:40 -05:00
|
|
|
});
|
2016-12-27 12:36:47 -05:00
|
|
|
|
2017-08-22 20:07:55 -04:00
|
|
|
it('should resolve reexported values in libraries', () => {
|
|
|
|
init();
|
|
|
|
const externalSerialized = serializeSummaries(
|
|
|
|
'someFile.ts', createMockOutputContext(), summaryResolver, symbolResolver,
|
|
|
|
[
|
|
|
|
{symbol: symbolCache.get('/tmp/external.ts', 'value'), metadata: 'someString'},
|
|
|
|
{
|
|
|
|
symbol: symbolCache.get('/tmp/external.ts', 'reexportValue'),
|
|
|
|
metadata: symbolCache.get('/tmp/external.ts', 'value')
|
|
|
|
},
|
|
|
|
],
|
|
|
|
[]);
|
|
|
|
init({
|
|
|
|
'/tmp/external.ngsummary.json': externalSerialized.json,
|
|
|
|
});
|
|
|
|
const serialized = serializeSummaries(
|
|
|
|
'someFile.ts', createMockOutputContext(), summaryResolver, symbolResolver,
|
|
|
|
[
|
|
|
|
{
|
|
|
|
symbol: symbolCache.get('/tmp/test.ts', 'mainValue'),
|
|
|
|
metadata: symbolCache.get('/tmp/external.d.ts', 'reexportValue'),
|
|
|
|
},
|
|
|
|
],
|
|
|
|
[]);
|
|
|
|
|
|
|
|
const summaries =
|
|
|
|
deserializeSummaries(symbolCache, summaryResolver, 'someFile.d.ts', serialized.json)
|
|
|
|
.summaries;
|
|
|
|
expect(summaries.length).toBe(2);
|
|
|
|
expect(summaries[0].symbol).toBe(symbolCache.get('/tmp/test.d.ts', 'mainValue'));
|
|
|
|
expect(summaries[0].metadata).toBe(symbolCache.get('/tmp/external.d.ts', 'value'));
|
|
|
|
expect(summaries[1].symbol).toBe(symbolCache.get('/tmp/external.d.ts', 'value'));
|
|
|
|
expect(summaries[1].metadata).toBe('someString');
|
|
|
|
});
|
|
|
|
|
2017-10-23 20:51:19 -04:00
|
|
|
it('should use existing reexports for "importAs" for symbols of libraries', () => {
|
2017-08-22 20:07:55 -04:00
|
|
|
init();
|
|
|
|
const externalSerialized = serializeSummaries(
|
|
|
|
'someFile.ts', createMockOutputContext(), summaryResolver, symbolResolver,
|
|
|
|
[
|
2017-10-23 20:51:19 -04:00
|
|
|
{symbol: symbolCache.get('/tmp/external.ts', 'value'), metadata: 'aValue'},
|
2017-08-22 20:07:55 -04:00
|
|
|
{
|
2017-10-23 20:51:19 -04:00
|
|
|
symbol: symbolCache.get('/tmp/external.ts', 'reexportValue'),
|
|
|
|
metadata: symbolCache.get('/tmp/external.ts', 'value')
|
2017-08-22 20:07:55 -04:00
|
|
|
},
|
|
|
|
],
|
|
|
|
[]);
|
2017-10-23 20:51:19 -04:00
|
|
|
expect(externalSerialized.exportAs).toEqual([]);
|
2017-08-22 20:07:55 -04:00
|
|
|
init({
|
|
|
|
'/tmp/external.ngsummary.json': externalSerialized.json,
|
|
|
|
});
|
|
|
|
const serialized = serializeSummaries(
|
|
|
|
'someFile.ts', createMockOutputContext(), summaryResolver, symbolResolver, [{
|
2017-10-23 20:51:19 -04:00
|
|
|
symbol: symbolCache.get('/tmp/test.ts', 'mainValue'),
|
|
|
|
metadata: symbolCache.get('/tmp/external.d.ts', 'reexportValue'),
|
2017-08-22 20:07:55 -04:00
|
|
|
}],
|
|
|
|
[]);
|
2017-10-23 20:51:19 -04:00
|
|
|
expect(serialized.exportAs).toEqual([]);
|
2017-08-22 20:07:55 -04:00
|
|
|
const importAs =
|
|
|
|
deserializeSummaries(symbolCache, summaryResolver, 'someFile.d.ts', serialized.json)
|
|
|
|
.importAs;
|
2017-10-23 20:51:19 -04:00
|
|
|
expect(importAs).toEqual([{
|
|
|
|
symbol: symbolCache.get('/tmp/external.d.ts', 'value'),
|
|
|
|
importAs: symbolCache.get('/tmp/test.d.ts', 'mainValue'),
|
|
|
|
}]);
|
2017-08-22 20:07:55 -04:00
|
|
|
});
|
|
|
|
|
2017-11-28 14:20:30 -05:00
|
|
|
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');
|
|
|
|
});
|
|
|
|
});
|
2019-02-09 13:13:18 -05:00
|
|
|
|
|
|
|
|
2019-02-12 17:29:28 -05:00
|
|
|
describe('symbol re-exports enabled', () => {
|
|
|
|
it('should not create "importAs" names for ctor arguments which are types of reexported classes in libraries',
|
|
|
|
() => {
|
|
|
|
init();
|
|
|
|
const externalSerialized = serializeSummaries(
|
|
|
|
'someFile.ts', createMockOutputContext(), summaryResolver, symbolResolver,
|
|
|
|
[
|
|
|
|
{
|
|
|
|
symbol: symbolCache.get('/tmp/external.ts', 'type'),
|
|
|
|
metadata: {__symbolic: 'interface'}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
symbol: symbolCache.get('/tmp/external.ts', 'value'),
|
|
|
|
metadata: {__symbolic: 'class'}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
symbol: symbolCache.get('/tmp/external.ts', 'reexportClass'),
|
|
|
|
metadata: {
|
|
|
|
__symbolic: 'class',
|
|
|
|
'members': {
|
|
|
|
'__ctor__': [{
|
|
|
|
'__symbolic': 'constructor',
|
|
|
|
'parameters': [
|
|
|
|
symbolCache.get('/tmp/external.ts', 'type'),
|
|
|
|
symbolCache.get('/tmp/external.ts', 'value'),
|
|
|
|
]
|
|
|
|
}]
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
},
|
|
|
|
],
|
|
|
|
[], true);
|
|
|
|
expect(externalSerialized.exportAs).toEqual([]);
|
|
|
|
init({
|
|
|
|
'/tmp/external.ngsummary.json': externalSerialized.json,
|
|
|
|
});
|
|
|
|
const serialized = serializeSummaries(
|
|
|
|
'someFile.ts', createMockOutputContext(), summaryResolver, symbolResolver, [{
|
|
|
|
symbol: symbolCache.get('/tmp/test.ts', 'mainClass'),
|
|
|
|
metadata: symbolCache.get('/tmp/external.d.ts', 'reexportClass'),
|
|
|
|
}],
|
|
|
|
[], true);
|
|
|
|
const importAs =
|
|
|
|
deserializeSummaries(symbolCache, summaryResolver, 'someFile.d.ts', serialized.json)
|
|
|
|
.importAs;
|
|
|
|
expect(importAs).toEqual([
|
|
|
|
{
|
|
|
|
symbol: symbolCache.get('/tmp/external.d.ts', 'reexportClass'),
|
|
|
|
importAs: symbolCache.get('/tmp/test.d.ts', 'mainClass'),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
symbol: symbolCache.get('/tmp/external.d.ts', 'value'),
|
|
|
|
importAs: symbolCache.get('someFile.ngfactory.d.ts', 'value_3'),
|
|
|
|
}
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should create reexports in the ngfactory for symbols of libraries', () => {
|
2019-02-09 13:13:18 -05:00
|
|
|
init();
|
|
|
|
const serialized = serializeSummaries(
|
|
|
|
'someFile.ts', createMockOutputContext(), summaryResolver, symbolResolver, [{
|
|
|
|
symbol: symbolCache.get('/tmp/test.ts', 'main'),
|
|
|
|
metadata: [
|
|
|
|
symbolCache.get('/tmp/external.d.ts', 'lib'),
|
|
|
|
symbolCache.get('/tmp/external.d.ts', 'lib', ['someMember']),
|
|
|
|
]
|
|
|
|
}],
|
2019-02-12 17:29:28 -05:00
|
|
|
[], true);
|
|
|
|
// Note: no entry for the symbol with members!
|
|
|
|
expect(serialized.exportAs).toEqual([
|
|
|
|
{symbol: symbolCache.get('/tmp/external.d.ts', 'lib'), exportAs: 'lib_1'}
|
|
|
|
]);
|
|
|
|
|
2019-02-09 13:13:18 -05:00
|
|
|
const deserialized =
|
|
|
|
deserializeSummaries(symbolCache, summaryResolver, 'someFile.d.ts', serialized.json);
|
2019-02-12 17:29:28 -05:00
|
|
|
// Note: no entry for the symbol with members!
|
|
|
|
expect(deserialized.importAs).toEqual([{
|
|
|
|
symbol: symbolCache.get('/tmp/external.d.ts', 'lib'),
|
|
|
|
importAs: symbolCache.get('someFile.ngfactory.d.ts', 'lib_1')
|
|
|
|
}]);
|
2019-02-09 13:13:18 -05:00
|
|
|
});
|
|
|
|
});
|
2019-02-12 17:29:28 -05:00
|
|
|
|
|
|
|
it('should use existing reexports for "importAs" for symbols of libraries', () => {
|
|
|
|
init();
|
|
|
|
const externalSerialized = serializeSummaries(
|
|
|
|
'someFile.ts', createMockOutputContext(), summaryResolver, symbolResolver,
|
|
|
|
[
|
|
|
|
{symbol: symbolCache.get('/tmp/external.ts', 'value'), metadata: 'aValue'},
|
|
|
|
{
|
|
|
|
symbol: symbolCache.get('/tmp/external.ts', 'reexportValue'),
|
|
|
|
metadata: symbolCache.get('/tmp/external.ts', 'value')
|
|
|
|
},
|
|
|
|
],
|
|
|
|
[], false);
|
|
|
|
expect(externalSerialized.exportAs).toEqual([]);
|
|
|
|
init({
|
|
|
|
'/tmp/external.ngsummary.json': externalSerialized.json,
|
|
|
|
});
|
|
|
|
const serialized = serializeSummaries(
|
|
|
|
'someFile.ts', createMockOutputContext(), summaryResolver, symbolResolver, [{
|
|
|
|
symbol: symbolCache.get('/tmp/test.ts', 'mainValue'),
|
|
|
|
metadata: symbolCache.get('/tmp/external.d.ts', 'reexportValue'),
|
|
|
|
}],
|
|
|
|
[]);
|
|
|
|
expect(serialized.exportAs).toEqual([]);
|
|
|
|
const importAs =
|
|
|
|
deserializeSummaries(symbolCache, summaryResolver, 'someFile.d.ts', serialized.json)
|
|
|
|
.importAs;
|
|
|
|
expect(importAs).toEqual([{
|
|
|
|
symbol: symbolCache.get('/tmp/external.d.ts', 'value'),
|
|
|
|
importAs: symbolCache.get('/tmp/test.d.ts', 'mainValue'),
|
|
|
|
}]);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should not create reexports in the ngfactory for external symbols', () => {
|
|
|
|
init();
|
|
|
|
const serialized = serializeSummaries(
|
|
|
|
'someFile.ts', createMockOutputContext(), summaryResolver, symbolResolver, [{
|
|
|
|
symbol: symbolCache.get('/tmp/test.ts', 'main'),
|
|
|
|
metadata: [
|
|
|
|
symbolCache.get('/tmp/external.d.ts', 'lib'),
|
|
|
|
symbolCache.get('/tmp/external.d.ts', 'lib', ['someMember']),
|
|
|
|
]
|
|
|
|
}],
|
|
|
|
[], false);
|
|
|
|
expect(serialized.exportAs.length).toBe(0, 'Expected no external symbols to be re-exported.');
|
|
|
|
const deserialized =
|
|
|
|
deserializeSummaries(symbolCache, summaryResolver, 'someFile.d.ts', serialized.json);
|
|
|
|
expect(deserialized.importAs.length)
|
|
|
|
.toBe(0, 'Expected no symbols that can be imported from a re-exported location');
|
|
|
|
});
|
2016-12-15 12:12:40 -05:00
|
|
|
});
|
|
|
|
}
|