Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This fixes the misalignment of the sourcemaps. However, two problems remain:
Instead of using
new Function(...)
I had to useeval
. I couldn't figure out a way to get theFunction
constructor to read a sourcemap, probably because sourcemaps need to be at the end of a file. There's no way to do that with aFunction
constructor, though I'd love to be wrong. The problem is that witheval
we lose the scoping advantages ofFunction
. That means the modules have access to all the local vars from theloader
function. The way to fix this is to sideload theloadAsModule
method. Are there are other side effects of this change I haven't noticed?When a new module is loaded to replace an old one, the sourcemap is discarded because the source file has the same name. The workaround here is to make the name unique somehow, and luckily we have a hash right ready for this purpose already! I already use the absolute filename for the sourcemap so that the whole
-t [ babelify --absoluteSourceMaps]
thing isn't needed. We need to figure out the best way to make this work with the hash. I'm thinking we figure out thecwd
and replace it with the hash, so that/home/username/project/src/filename.js
becomesabcdef1234567890/src/filename.js
and so on with different hashes for subsequent revisions.Despite these problems I'm opening the PR to start a discussion. I plan on addressing these two issues as described unless someone has a suggestion.