-
Notifications
You must be signed in to change notification settings - Fork 103
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
Fix source map generation #25
base: master
Are you sure you want to change the base?
Conversation
be traced back to the map output by uglify. Pass through options to generateMap
Fixes #24 |
@Rich-Harris even after this change |
hmm... it should Just Work™. Might well be an unrelated bug – I need to spend some time on that project, will add this as an issue. If you're able to help out with a reduced test case that would be very helpful, thanks! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Except for the necessary README changes, everything looks great to me! Although based on your comment, are you saying this doesn't actually resolve the issue?
file: 'optimized.js', | ||
source: 'original.js', | ||
sourceMap: true, | ||
includeContent: true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So it looks like this includes three new options - file
, source
, and includeContent
. Could you update the README please? :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will do, but I'm currently trying to get it to work with jquery, it currently did come close to working with ember.
The issue is this needs to be done after minify and a minified map is quite complicated. I'll push up a demo of the issue.
@nolanlawson it did not, I'm guessing there are some edge cases with uglify's map that magic string or sorcery is not handling and @Rich-Harris answer to magic string not using an input map is to use sorcery, as far as I can tell this PR aligns with how rollup chains source maps. |
So having trouble reducing it simple examples work well as is, this PR for certain is an improvement over the existing. I'll keep working on it, still not sure if it is socery, uglify or magic string. As I said this PR at least gets it to work in most cases. Maybe we should return {code, map} instead of inlining? Since it would be for sure something you'd want split out in prod |
@Rich-Harris @nolanlawson It is the fallback from extra mappings that don't trace back to the uglified map https://github.com/krisselden/sourcemap-issue |
@nolanlawson so I think the simplest would be just to have an option that returned the magic string instance. Unfortunately I think this is an issue with sorcery and rollup, but both do something different here to trace back to the original source that requires different To get the right result in sorcery I have to walk only the mappings in the uglified map and call |
From this conversation it sounds like this is a bug in magicstring. I'm pretty hesitant to complicate the API by returning the magicstring instance; it feels so me like emitting the sourcemap ought to be good enough. 😕 |
I understand the concern, the issue is this has to be done post minify and I don't know of any tool that can remap the sourcemap back to the input correctly. The API for magicstring that lets you mark locations at least lets you make it the same resolution as the input map so it is easier to remap to an input. Maybe an acceptable API would be to take an input map? Also, it would be nice if the return value was . |
Floating over from #5. Reading through the comment chain here, it looks like the suggested change is to pass in and emit source maps. Is anyone following this currently working on a pull request? I don't have time to dive into this for a bit, but I do have a mostly working rollup plugin that's just waiting on sourcemap support. There's also a comment about it possibly being a magicstring issue. If that's the case, has anyone filed an issue on the magicstring repo? Just seeing if I can help get some momentum going, thanks! |
@ansballard there is no issue with magicstring itself, it correctly provides a way of marking where the input mappings are with Without an input map, the correct thing to do as this PR does is add the locations for the nodes. The only issue is with this approach is if you try to use The best thing would be to at least be able to pass in the locations of the mappings you want to remap or return the magic string itself so you can do this yourself. |
@ansballard also, just to clarify, no tool I know of would map what this is currently outputting back to the minified sourcemap and this tool needs to be run after minification. Contrary to what most people think, you need to provide mappings for all the expressions and names for the identifiers in a sourcemap, not just your edits, to have the sourcemap function well. |
Hi all, I don't really have the time or motivation to maintain optimize-js anymore, and also it is quite likely that it will become obsolete, as I know both V8 and Chakra are in the midst of improving their function-parsing heuristics. So I've gone ahead and made @krisselden a GH contributor with npm owner access; please do as you wish. :) Sorry for being so slow with these PRs! |
Ensure mappings are emitted for AST locations so that mapping back to the original source map with a tool like
sorcery
is possible.