Browse Source

Cache decoded mappings

semi-dynamic-namespace-imports
Bogdan Chadkin 9 years ago
parent
commit
d8addbb82e
  1. 4
      src/Bundle.js
  2. 4
      src/utils/collapseSourcemaps.js
  3. 10
      src/utils/transform.js
  4. 6
      src/utils/transformBundle.js

4
src/Bundle.js

@ -1,3 +1,4 @@
import { decode } from 'sourcemap-codec';
import { Bundle as MagicStringBundle } from 'magic-string';
import first from './utils/first.js';
import { find } from './utils/array.js';
@ -354,6 +355,9 @@ export default class Bundle {
if ( this.hasLoaders || find( this.plugins, plugin => plugin.transform || plugin.transformBundle ) ) {
map = magicString.generateMap( {} );
if ( typeof map.mappings === 'string' ) {
map.mappings = decode( map.mappings );
}
map = collapseSourcemaps( file, map, usedModules, bundleSourcemapChain, this.onwarn );
} else {
map = magicString.generateMap({ file, includeContent: true });

4
src/utils/collapseSourcemaps.js

@ -1,4 +1,4 @@
import { encode, decode } from 'sourcemap-codec';
import { encode } from 'sourcemap-codec';
import { dirname, relative, resolve } from './path.js';
class Source {
@ -17,7 +17,7 @@ class Link {
constructor ( map, sources ) {
this.sources = sources;
this.names = map.names;
this.mappings = decode( map.mappings );
this.mappings = map.mappings;
}
traceMappings () {

10
src/utils/transform.js

@ -1,8 +1,14 @@
import { decode } from 'sourcemap-codec';
export default function transform ( source, id, plugins ) {
const sourceMapChain = [];
const originalSourceMap = typeof source.map === 'string' ? JSON.parse( source.map ) : source.map;
if ( originalSourceMap && typeof originalSourceMap.mappings === 'string' ) {
originalSourceMap.mappings = decode( originalSourceMap.mappings );
}
const originalCode = source.code;
let ast = source.ast;
@ -25,6 +31,10 @@ export default function transform ( source, id, plugins ) {
result.map = JSON.parse( result.map );
}
if ( result.map && typeof result.map.mappings === 'string' ) {
result.map.mappings = decode( result.map.mappings );
}
sourceMapChain.push( result.map || { missing: true, plugin: plugin.name }); // lil' bit hacky but it works
ast = result.ast;

6
src/utils/transformBundle.js

@ -1,3 +1,5 @@
import { decode } from 'sourcemap-codec';
export default function transformBundle ( code, plugins, sourceMapChain ) {
return plugins.reduce( ( code, plugin ) => {
if ( !plugin.transformBundle ) return code;
@ -22,6 +24,10 @@ export default function transformBundle ( code, plugins, sourceMapChain ) {
}
const map = typeof result.map === 'string' ? JSON.parse( result.map ) : result.map;
if ( map && typeof map.mappings === 'string' ) {
map.mappings = decode( map.mappings );
}
sourceMapChain.push( map );
return result.code;

Loading…
Cancel
Save