Skip to content

Commit

Permalink
feat(tsc-wrapped): record original location of flattened symbols (#15367
Browse files Browse the repository at this point in the history
)

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.
  • Loading branch information
chuckjaz authored and mhevery committed Mar 22, 2017
1 parent 5efc860 commit 7354949
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
11 changes: 8 additions & 3 deletions tools/@angular/tsc-wrapped/src/bundler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,17 +92,23 @@ 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 => ({
privateName: s.privateName,
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
};
}
Expand Down Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions tools/@angular/tsc-wrapped/src/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
16 changes: 14 additions & 2 deletions tools/@angular/tsc-wrapped/test/bundler_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}
]);
});

Expand Down

0 comments on commit 7354949

Please sign in to comment.