New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
UglifyJsPlugin breaks source maps #2213
Comments
As part of the normal minification process with function and variable inlining these observations are expected since uglify causes side-effect-free code to be rearranged and variables/parameters disappear as they are folded into other values:
If better debuggability is desired, the It might be possible for uglify to correct one aspect of function inlining - pointing to the opening paren instead of the first argument as per @sokra's final example above. |
To further illustrate why debugging does not work with inlining:
|
AFAICT that there is no special souce map positioning for In fact if you look at |
The following patch creates a new source mapping at the opening paren of an IIFE. Otherwise the source map is the same. --- a/lib/output.js
+++ b/lib/output.js
@@ -1104,6 +1104,9 @@ function OutputStream(options) {
self.expression.print(output);
if (self instanceof AST_New && !need_constructor_parens(self, output))
return;
+ if (self.expression instanceof AST_Function) {
+ output.add_mapping(self.start);
+ }
output.with_parens(function(){
self.args.forEach(function(expr, i){
if (i) output.comma(); Compare source mappings: Hover mouse over Commands used:
Nothing else in this ticket is actionable. You can't debug variables that were folded into other values, nor can you get accurate stack traces for functions that have been inlined and no longer exist. |
@kzc interesting tool and thanks for the patch. I'll create that PR to address this issue now 👍 |
It doesn't really improve the Chrome debugging experience. When you try to set a breakpoint on |
@kzc how about mapping |
I don't think Chrome places any significance on the closing paren. I've had a trial and error crash course on source maps in the last day - the technology is really poorly documented!
|
You have my respect and sympathy on that one 😅
👍 |
Do you want to request a feature or report a bug?
Bug
What is the current behavior?
Webpack generates faulty source maps when the webpack.optimize.UglifyJsPlugin is active. The generated source maps suffer from various issues, e.g.:
If the current behavior is a bug, please provide the steps to reproduce.
Below is a minimal setup for creating the various issues mentioned above.
webpack.config.js
a.js
b.js
What is the expected behavior?
Source maps should not cause weird browser debugger behavior when UglifyJsPlugin is active.
Please mention other relevant information such as the browser version, Node.js version, webpack version and Operating System.
This issue was moved from webpack/webpack#5165 by @sokra. Orginal issue was by @oskargustafsson.
This seem to be a uglifyjs bug.
UglifyJS generates this code for your example:
Not how the
foo
function is inlined into the call.But the SourceMappings seem to be wrong in this case. There is no reference to the call in the SourceMap anymore.
SourceMap
Chrome seem to use the SourceMap reference at the
(
of the call.This maps to the incorrect line:
I tried changing the SourceMap to this:
That seem to work in this case.
The text was updated successfully, but these errors were encountered: