danvk / source-map-explorer

Analyze and debug space usage through source maps
Apache License 2.0
3.82k stars 100 forks source link

`InvalidMappingColumn` for mapped eol. #179

Closed mbehzad closed 4 years ago

mbehzad commented 4 years ago

Description Sometimes during compilation of files, some plugins will add an eol to the end of the output. e.g. mini-css-extract-plugin. During the source-map generation (e.g. by mozilla/source-map) a new segment will be added for the line ending without a reference to the original source (probably because the eol didn't come from the source). Which according to the source-map spec, segments with only one variable are allowed.

source-map-explorer when reading such a source-map throws InvalidMappingColumn error with the message:

Your source map refers to generated column 15 on line 1, but the source only contains 14 column(s) on that line. Check that you are using the correct source map.

might be related to https://github.com/danvk/source-map-explorer/issues/136

Steps to reproduce

css:

body{margin:0}

/*# sourceMappingURL=output.css.map*/

source-map:

{"version":3,"sources":["webpack:///main.css"],"names":[],"mappings":"AAAA,KAAK,QAAQ,C","file":"css/output.css","sourcesContent":["body{margin:0}"],"sourceRoot":""}

run source-map-explorer with these files

Files to reproduce minimal repo: https://github.com/mbehzad/webpack-postcss-cssnano-source-map-issue

Expected behavior it would be great if source-map-explorer could detect that the column number bing one bigger that the line length and having no reference for the original source is because of a eol and ignore it.

Environment

Additional context output was generated by a webpack build using mini-css-extract-plugin and the css file was minified prior / as part of that.

nikolay-borzov commented 4 years ago

I don't think it's possible to detect that source map reference EOL when sourcesContent doesn't contain the EOL. Described mini-css-extract-plugin behavior looks like a bug. mini-css-extract-plugin should not generate mapping for EOL. I'm thinking about disabling column/line boundaries check when analyzing a source map. These checks can be useful but they bring more troubles.

nikolay-borzov commented 4 years ago

Use --no-border-checks to disable invalid mapping column/line checks

mbehzad commented 4 years ago

thank you very much for the fast response!