babel-generator: Expose raw mappings

Exposes raw mappings when source map generation is enabled. To avoid the cost of source map generation for consumers of the raw mappings only, `.map` is changed to a getter that generates the source map lazily on first access.
This commit is contained in:
David Aurelio
2016-12-09 09:55:42 +00:00
parent f8f78f50e5
commit 7ea283eb82
3 changed files with 156 additions and 20 deletions

View File

@@ -38,10 +38,25 @@ export default class Buffer {
get(): Object {
this._flush();
return {
const map = this._map;
const result = {
code: trimEnd(this._buf.join("")),
map: this._map ? this._map.get() : null,
map: null,
rawMappings: map && map.getRawMappings(),
};
if (map) {
Object.defineProperty(result, "map", {
get() {
return this.map = map.get();
},
set(value) {
Object.defineProperty(this, "map", {value, writable: true});
},
});
}
return result;
}
/**