Skip to content

split code into more tokens to fix sourcemap-validator warnings#51

Closed
connorjclark wants to merge 3 commits intowebpack:masterfrom
connorjclark:splitcode
Closed

split code into more tokens to fix sourcemap-validator warnings#51
connorjclark wants to merge 3 commits intowebpack:masterfrom
connorjclark:splitcode

Conversation

@connorjclark
Copy link
Copy Markdown

Fixes webpack/webpack#8302

Add more nodes to create a more granular identity source map. This allows for better source maps when other consumers process what webpack creates (I've been using the terser plugin).

Previous splitting resulted in this (this is post-terser):
image

note that all mappings map to column 0 for every line.

Now:

image

I also added a test that did a (too simple) check w/ sourcemap-validator. It passes even w/o these changes - I didn't spend any time thinking about how to create a test case that would mimic what terser was doing. Perhaps someone could help with that?

@jsf-clabot
Copy link
Copy Markdown

jsf-clabot commented Jul 26, 2019

CLA assistant check
Thank you for your submission, we really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.

}
return new SourceNode(null, null, null,
_splitCode(line + (idx != lines.length - 1 ? "\n" : "")).map(function(item) {
if(/^\s*$/.test(item)) {
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was from my previous attempt: #41. Removed, as it wasn't quite correct.

I think it worked in some cases, but only coincidentally. Possibly it made the first identifier on a line map correctly, and I didn't look further than that while checking it worked?

@codecov
Copy link
Copy Markdown

codecov bot commented Jul 26, 2019

Codecov Report

Merging #51 into master will decrease coverage by 61.66%.
The diff coverage is 100%.

Impacted file tree graph

@@             Coverage Diff             @@
##           master      #51       +/-   ##
===========================================
- Coverage   78.25%   16.58%   -61.67%     
===========================================
  Files          11        8        -3     
  Lines         492      416       -76     
  Branches       76       67        -9     
===========================================
- Hits          385       69      -316     
- Misses        107      347      +240
Impacted Files Coverage Δ
lib/OriginalSource.js 89.47% <100%> (-10.53%) ⬇️
lib/ReplaceSource.js 3.6% <0%> (-92.79%) ⬇️
lib/ConcatSource.js 9.09% <0%> (-80%) ⬇️
lib/PrefixSource.js 15% <0%> (-67.5%) ⬇️
lib/RawSource.js 23.52% <0%> (-64.71%) ⬇️
lib/CachedSource.js 4.87% <0%> (-41.47%) ⬇️
lib/SourceAndMapMixin.js 66.66% <0%> (-33.34%) ⬇️
lib/Source.js 15.78% <0%> (-15.79%) ⬇️
lib/SourceMapSource.js
... and 2 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b9529e9...9aab3a7. Read the comment docs.

@codecov
Copy link
Copy Markdown

codecov bot commented Jul 26, 2019

Codecov Report

Merging #51 into master will decrease coverage by 61.66%.
The diff coverage is 100%.

Impacted file tree graph

@@             Coverage Diff             @@
##           master      #51       +/-   ##
===========================================
- Coverage   78.25%   16.58%   -61.67%     
===========================================
  Files          11        8        -3     
  Lines         492      416       -76     
  Branches       76       67        -9     
===========================================
- Hits          385       69      -316     
- Misses        107      347      +240
Impacted Files Coverage Δ
lib/OriginalSource.js 89.47% <100%> (-10.53%) ⬇️
lib/ReplaceSource.js 3.6% <0%> (-92.79%) ⬇️
lib/ConcatSource.js 9.09% <0%> (-80%) ⬇️
lib/PrefixSource.js 15% <0%> (-67.5%) ⬇️
lib/RawSource.js 23.52% <0%> (-64.71%) ⬇️
lib/CachedSource.js 4.87% <0%> (-41.47%) ⬇️
lib/SourceAndMapMixin.js 66.66% <0%> (-33.34%) ⬇️
lib/Source.js 15.78% <0%> (-15.79%) ⬇️
lib/SourceMapSource.js
... and 2 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b9529e9...1b0d706. Read the comment docs.

var Source = require("./Source");

var SPLIT_REGEX = /(?!$)[^\n\r;{}]*[\n\r;{}]*/g;
var SPLIT_REGEX = /([^\d\w]+)/g;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you measure how much this affects performance? As far as I remember this could have negative performance impact on larger files.

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

Successfully merging this pull request may close these issues.

Webpack is producing invalid sourcemaps?

3 participants