gobblejs / gobble

The last build tool you'll ever need
333 stars 20 forks source link

Source map URL Regex swallows UMD/IIFE globals code #132

Closed alastaircoote closed 7 years ago

alastaircoote commented 7 years ago

The regex in sourcemap.js appears to swallow the bottom half of a UMD/IIFE wrapper in some circumstances, when it is attempting to use globals. Like so:

screen shot 2017-08-21 at 17 45 36

I've made two changes:

  1. Edited the regex to use a lazy quantifier, and to allow newline or end of string at the end of the match.
  2. Changed serveFile.js to replace all source map comments with an empty string, then append the comment at the end, rather than replace in-place. This is also what map.js does.

All the tests run, but I haven't been able to isolate exactly what causes this to create a new test of my own.

IvanSanchez commented 7 years ago

I'm gonna guess that the culprit is webpack doing some web worker bundling (or otherwise a sourcemap reference inside a IIFE module definition. That would create two sourcemap references inside the same file.

The unit tests pass (except one windows-specific directory permissions thing), so I'm happy.

IvanSanchez commented 7 years ago

@Rich-Harris Can we have this tagged as v0.12.1?

alastaircoote commented 7 years ago

We actually need to re-merge this: I discovered today that I need to preserve the (now empty) line where the source map comment was, otherwise the line numbers in the mappings do not match up any more. I've actually not had to amend a merged pull request before - shall I just make another?