evanw / esbuild

An extremely fast bundler for the web
https://esbuild.github.io/
MIT License
37.92k stars 1.13k forks source link

SourceMap row and col references are not being updated when Esbuild changes whitespace or minifies the final bundled file #3843

Open mitcoding opened 1 month ago

mitcoding commented 1 month ago

It's possible the bug described in the title only happens if Plugins are used to modify the output. In my particular case I discovered this issue because I'm transpiling SASS which esbuild doesn't handle natively, and thus requires the use of a plugin like esbuild-sass-plugin. With that said as far as I know the Javascript/Typescript seems to be generating correct sourceMaps, since I'm not using any plugins to bundle them. But I can't be sure as the project I'm using esbuild on I'm not as familiar with the javascript & typescript being bundled to be 100% sure.

The key issue that I'm seeing is that esbuild-sass-plugin returns a bundled css file that has a mixture of single line multi selector rules and multiline selector rules. Which esbuild then converts all the single line mulit select rules into multi line but doesn't update the sourceMap row col fields correclty thus the outputed sourceMap causes the dev tools to pull up the wrong source file for a specific block of css.

Please see a more detailed analysis and my current workaround over at esbuild-sass-plugin github issue page:

https://github.com/glromeo/esbuild-sass-plugin/issues/185

mitcoding commented 1 month ago

i've uploaded an example project that repoduces the issue described above. the final files generated by esbuild are in target/clientlib-site1/site1.EXT and the pre-minified files generated by esbuild-sass-plugin and lightiningcss are outputed in target/preMinification/

https://github.com/mitcoding/esbuild-sass-source-map-issue