From 7354949763d30aee56772d02be14831714338c83 Mon Sep 17 00:00:00 2001 From: Chuck Jazdzewski Date: Mon, 20 Mar 2017 16:30:50 -0700 Subject: [PATCH] feat(tsc-wrapped): record original location of flattened symbols (#15367) Added an "origins" section to the flat module `.metadata.json` files that records where the original symbols was declared. This allows correctly calculating relative path references recorded in metadata. --- tools/@angular/tsc-wrapped/src/bundler.ts | 11 ++++++++--- tools/@angular/tsc-wrapped/src/schema.ts | 1 + tools/@angular/tsc-wrapped/test/bundler_spec.ts | 16 ++++++++++++++-- 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/tools/@angular/tsc-wrapped/src/bundler.ts b/tools/@angular/tsc-wrapped/src/bundler.ts index aa913acaed..8ecf9fc3cd 100644 --- a/tools/@angular/tsc-wrapped/src/bundler.ts +++ b/tools/@angular/tsc-wrapped/src/bundler.ts @@ -92,7 +92,7 @@ export class MetadataBundler { const exportedSymbols = this.exportAll(this.rootModule); this.canonicalizeSymbols(exportedSymbols); // TODO: exports? e.g. a module re-exports a symbol from another bundle - const entries = this.getEntries(exportedSymbols); + const metadata = this.getEntries(exportedSymbols); const privates = Array.from(this.symbolMap.values()) .filter(s => s.referenced && s.isPrivate) .map(s => ({ @@ -100,9 +100,15 @@ export class MetadataBundler { name: s.declaration.name, module: s.declaration.module })); + const origins = Array.from(this.symbolMap.values()) + .filter(s => s.referenced) + .reduce<{[name: string]: string}>((p, s) => { + p[s.isPrivate ? s.privateName : s.name] = s.declaration.module; + return p; + }, {}); return { metadata: - {__symbolic: 'module', version: VERSION, metadata: entries, importAs: this.importAs}, + {__symbolic: 'module', version: VERSION, metadata, origins, importAs: this.importAs}, privates }; } @@ -235,7 +241,6 @@ export class MetadataBundler { let name = symbol.name; if (symbol.isPrivate && !symbol.privateName) { name = newPrivateName(); - ; symbol.privateName = name; } result[name] = symbol.value; diff --git a/tools/@angular/tsc-wrapped/src/schema.ts b/tools/@angular/tsc-wrapped/src/schema.ts index 7b7fbc9729..1e390394ab 100644 --- a/tools/@angular/tsc-wrapped/src/schema.ts +++ b/tools/@angular/tsc-wrapped/src/schema.ts @@ -25,6 +25,7 @@ export interface ModuleMetadata { exports?: ModuleExportMetadata[]; importAs?: string; metadata: {[name: string]: MetadataEntry}; + origins?: {[name: string]: string}; } export function isModuleMetadata(value: any): value is ModuleMetadata { return value && value.__symbolic === 'module'; diff --git a/tools/@angular/tsc-wrapped/test/bundler_spec.ts b/tools/@angular/tsc-wrapped/test/bundler_spec.ts index e473682b6e..cca3b433ae 100644 --- a/tools/@angular/tsc-wrapped/test/bundler_spec.ts +++ b/tools/@angular/tsc-wrapped/test/bundler_spec.ts @@ -25,9 +25,21 @@ describe('metadata bundler', () => { expect(Object.keys(result.metadata.metadata).sort()).toEqual([ 'ONE_CLASSES', 'One', 'OneMore', 'TWO_CLASSES', 'Two', 'TwoMore', 'ɵa', 'ɵb' ]); + + const originalOne = './src/one'; + const originalTwo = './src/two/index'; + expect(Object.keys(result.metadata.origins) + .sort() + .map(name => ({name, value: result.metadata.origins[name]}))) + .toEqual([ + {name: 'ONE_CLASSES', value: originalOne}, {name: 'One', value: originalOne}, + {name: 'OneMore', value: originalOne}, {name: 'TWO_CLASSES', value: originalTwo}, + {name: 'Two', value: originalTwo}, {name: 'TwoMore', value: originalTwo}, + {name: 'ɵa', value: originalOne}, {name: 'ɵb', value: originalTwo} + ]); expect(result.privates).toEqual([ - {privateName: 'ɵa', name: 'PrivateOne', module: './src/one'}, - {privateName: 'ɵb', name: 'PrivateTwo', module: './src/two/index'} + {privateName: 'ɵa', name: 'PrivateOne', module: originalOne}, + {privateName: 'ɵb', name: 'PrivateTwo', module: originalTwo} ]); });