Browse Source

populate map.sourcesContent with original code

better-aggressive
Rich-Harris 9 years ago
parent
commit
61dcc1bf7c
  1. 4
      src/Bundle.js
  2. 3
      src/Module.js
  3. 1
      src/utils/collapseSourcemaps.js
  4. 3
      src/utils/transform.js

4
src/Bundle.js

@ -115,9 +115,9 @@ export default class Bundle {
return Promise.resolve( this.load( id, this.loadOptions ) ) return Promise.resolve( this.load( id, this.loadOptions ) )
.then( source => transform( source, id, this.transformers ) ) .then( source => transform( source, id, this.transformers ) )
.then( source => { .then( source => {
const { code, ast, sourceMapChain } = source; const { code, originalCode, ast, sourceMapChain } = source;
const module = new Module({ id, code, ast, sourceMapChain, bundle: this }); const module = new Module({ id, code, originalCode, ast, sourceMapChain, bundle: this });
this.modules.push( module ); this.modules.push( module );
this.moduleById[ id ] = module; this.moduleById[ id ] = module;

3
src/Module.js

@ -128,8 +128,9 @@ class SyntheticNamespaceDeclaration {
} }
export default class Module { export default class Module {
constructor ({ id, code, ast, sourceMapChain, bundle }) { constructor ({ id, code, originalCode, ast, sourceMapChain, bundle }) {
this.code = code; this.code = code;
this.originalCode = originalCode;
this.sourceMapChain = sourceMapChain; this.sourceMapChain = sourceMapChain;
this.bundle = bundle; this.bundle = bundle;

1
src/utils/collapseSourcemaps.js

@ -63,6 +63,7 @@ export default function collapseSourcemaps ( map, modules ) {
return tracedLine; return tracedLine;
}); });
map.sourcesContent = modules.map( module => module.originalCode );
map.mappings = encode( tracedMappings ); map.mappings = encode( tracedMappings );
return map; return map;
} }

3
src/utils/transform.js

@ -8,6 +8,7 @@ export default function transform ( source, id, transformers ) {
}; };
} }
let originalCode = source.code;
let ast = source.ast; let ast = source.ast;
let code = transformers.reduce( ( previous, transformer ) => { let code = transformers.reduce( ( previous, transformer ) => {
@ -29,5 +30,5 @@ export default function transform ( source, id, transformers ) {
return result.code; return result.code;
}, source.code ); }, source.code );
return { code, ast, sourceMapChain }; return { code, originalCode, ast, sourceMapChain };
} }

Loading…
Cancel
Save