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.
This commit is contained in:
Chuck Jazdzewski
2017-03-20 16:30:50 -07:00
committed by Miško Hevery
parent 5efc86069f
commit 7354949763
3 changed files with 23 additions and 5 deletions

View File

@ -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;