Browse Source

Merge pull request #640 from rollup/update-collapse-sourcemaps

Update collapseSourcemaps to use class syntax post-620
gh-669
Rich Harris 9 years ago
parent
commit
f18bf0f1e2
  1. 18
      src/utils/collapseSourcemaps.js

18
src/utils/collapseSourcemaps.js

@ -1,25 +1,25 @@
import { encode, decode } from 'sourcemap-codec'; import { encode, decode } from 'sourcemap-codec';
function Source ( index ) { class Source {
constructor ( index ) {
this.isOriginal = true; this.isOriginal = true;
this.index = index; this.index = index;
} }
Source.prototype = {
traceSegment ( line, column, name ) { traceSegment ( line, column, name ) {
return { line, column, name, index: this.index }; return { line, column, name, index: this.index };
} }
}; }
function Link ( map, sources ) { class Link {
constructor ( map, sources ) {
if ( !map ) throw new Error( 'Cannot generate a sourcemap if non-sourcemap-generating transformers are used' ); if ( !map ) throw new Error( 'Cannot generate a sourcemap if non-sourcemap-generating transformers are used' );
this.sources = sources; this.sources = sources;
this.names = map.names; this.names = map.names;
this.mappings = decode( map.mappings ); this.mappings = decode( map.mappings );
} }
Link.prototype = { // TODO bring into line with others post-https://github.com/rollup/rollup/pull/386
traceMappings () { traceMappings () {
let names = []; let names = [];
@ -57,7 +57,7 @@ Link.prototype = { // TODO bring into line with others post-https://github.com/r
}); });
return { names, mappings }; return { names, mappings };
}, }
traceSegment ( line, column, name ) { traceSegment ( line, column, name ) {
const segments = this.mappings[ line ]; const segments = this.mappings[ line ];
@ -79,7 +79,7 @@ Link.prototype = { // TODO bring into line with others post-https://github.com/r
return null; return null;
} }
}; }
export default function collapseSourcemaps ( map, modules, bundleSourcemapChain ) { export default function collapseSourcemaps ( map, modules, bundleSourcemapChain ) {
const sources = modules.map( ( module, i ) => { const sources = modules.map( ( module, i ) => {

Loading…
Cancel
Save