Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remapping works only with high resolution sourcemaps #91

Closed
milahu opened this issue Sep 30, 2020 · 1 comment
Closed

remapping works only with high resolution sourcemaps #91

milahu opened this issue Sep 30, 2020 · 1 comment

Comments

@milahu
Copy link
Contributor

milahu commented Sep 30, 2020

today i learned, after an hour of debugging ....
remapping via backtracing works only with high resolution sourcemaps

this should at least be documented in the readme
since some sourcemap-generators produce lowres maps by default

package source-map says

SourceMapGenerator.prototype.applySourceMap

Note: The resolution for the resulting mappings is the minimum of this map and the supplied map.

better show a warning when older mappings are not reachable
the warning can be disabled with a allowLossyRemap flag, or so

not possible in a reliable way, without tokenizing source files = out of scope

supporting sourcemap-generators who can only produce lowres maps, is ....

probably out-of-scope

modify the backtracing algorithm, to support lowres sourcemaps
lowres sourcemap means:
if one line was not changed, the mapping line is empty
(probably same for segments)

this is simple with the array interface
where every map has exactly one source file
so we can copy missing mappings from parent to child

in a more complex scene (convergent transform chain)
with multiple source files, we need a way to find the 'main source file'
index zero should work in most cases, but not in all cases

snippet to sometimes detect lost source files
// convergent transform chain:
//           3           2           1
// bundle.js < bundle.js < bundle.js <
//             src-4       src-3       src-1
//                                     src-2
// sample:
// when transform 2 gives a lowres sourcemap
// and 2 does not modify the changes of 1
// then src-1 and src-2 are 'lost source files'
//
// problem:
// this method is not reliable.
// if at least one segment can trace back
// then the sourcefile is not detected as lost

const sourcemap_list = [ /* .... */ ];
const filename = 'bundle.js'; // main source file in every sourcemap
let map_idx = 1;

const map = remapping( // use loader interface
  sourcemap_list[0], // last map
  function loader(sourcefile) {
    if (sourcefile == filename && sourcemap_list[map_idx]) {
      return sourcemap_list[map_idx++]; // idx 1, 2, ...
      // bundle file = branch node
    }
    else return null; // source file = leaf node
  }
);

// show warning if source files were lost
const sources_lost = sourcemap_list
  .map(m => m.sources.filter(s => !map.sources.includes(s)));
if (sources_lost.find(a => a.length > 0))
  console.log('warning. combine_sourcemaps lost source files:\n'
    + JSON.stringify(sources_lost, null, 2)
    + '\nprobably you want to generate high-resolution sourcemaps.'
  );
@jridgewell
Copy link
Collaborator

I'm merging this into #116 (comment). We'll support "editmaps", which can contain minimal segments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants