webpack / webpack-sources

Source code handling classes for webpack
MIT License
261 stars 71 forks source link

PrefixSource bug: source() !== sourceAndMap().source #8

Closed patrickhulce closed 7 years ago

patrickhulce commented 7 years ago

empty lines are not handled consistently which breaks ReplaceSource indices that might be based on a particular version of the source.

Example Prefix: foobar Nodes: ["console.log(1);\n", "\n", "console.log(2);\n"]

source() -> foobar console.log(1);\n\nfoobar console.log(2);\n sourceAndMap().source -> foobar console.log(1);\nfoobar \nfoobar console.log(2);\n

TheLarkInn commented 7 years ago

Is there a specific issue in which you discovered this specific bug?

patrickhulce commented 7 years ago

@TheLarkInn yep, while trying to write a webpack plugin that replaced a specific section of a bundle before uglifying using a ReplaceSource, I noticed that enabling source maps would render the output unparseable.

This may not be what ReplaceSource is intended for (and if I understood more about webpack internals I probably wouldn't even need to do it this way at all 😄), but this seemed like an undesirable property of a source either way. My current workaround is to narrow the scope of replacements to sections not containing a PrefixSource.

TheLarkInn commented 7 years ago

Oh just wanted to double check!! No problem at all and we are 1000% for the contribution. Using webpack-sources is definitely the way to go for modifying sources. We've been trying to hunt down a bug related to source maps and didn't know if this was the motivation or not.