-
Notifications
You must be signed in to change notification settings - Fork 185
Add //# sourceURL along with source map. #256
Conversation
For some odd reason, Google Chrome requires sourceURL to be able to display source maps in stack traces correctly.
For this test page, if the generated ES5 code from ES6 does not contain the With the sourceURL directive, however, it now looks like this: |
Thanks so much for this - I'll try it out soon. |
Add //# sourceURL along with source map.
Thanks so much for this - that makes a big difference to debugging! |
You're welcome. Thanks for creating this project. I've always wanted to write my apps in ES6. Even though it works well in Chrome, debugging in Safari is still painful... Somehow, its DevTools does not support source map or source URL. What I've tried so far is to—instead of evaluating the code using The code to evaluate the script using Blobs look like this: function __scriptEval(code) {
return new Promise(function(resolve, reject) {
var url = URL.createObjectURL(new Blob([code], { type: 'text/javascript' }));
var script = document.createElement('script')
script.src = url
script.onload = function() { resolve() }
script.onerror = function(e) { reject(e) }
document.body.appendChild(script)
})
} Here's the patch, an incomplete version. Note that it's done against the compiled version of es6-module-loader. I have some difficulty with it: with a moderately-sized dependency tree, there are some race conditions that caused I already used an evaluation queue to make sure that only single |
We actually do something similar to this in SystemJS already here - https://github.com/systemjs/systemjs/blob/master/lib/polyfill-wrapper-end.js#L42. I'd also be interested to hear if the process of creating the blob URL affects the performance. It could certainly be an option here since the direct ES6 evaluation feature is only for development in modern browsers. For the race condition - perhaps we can avoid wrapping the code in a promise and assume execution will be synchronous on appendChild anyway? This is because we need a synchronous lock of the global System.register for the execution to work. I think that's what I'm doing in the SystemJS version anyway? |
Alternatively if execution that way must be asynchronous, we could do the System.register global manipulation within the evaluation itself. |
I like the Blob idea. There's similar problems with Firefox's debug tools with eval() scripts. Except it's much worse; they flat out don't work. There has been some recent work to fix this on their end but I have still not been able to ever debug es6ml-based code in Firefox which saddens me greatly. |
@guybedford I know you're probably going to say no to this (and i don't blame you)... but if doEval were exposed so that it could be overwritten that would be very nice. |
What I do right now is to just modify es6-module-loader and SystemJS and use my own version instead. That refers to my using the version in the PR before it was merged. Another alternative is to be able to be able switch between System.EVAL_STRATEGY = 'eval' // uses eval() to evaluate script — should be fastest
System.EVAL_STRATEGY = 'script' // injects a script tag with inline code
System.EVAL_STRATEGY = 'blob' // injects a script tag pointing to a blob Promises also clutter the stack trace in Chrome, given that a native |
@dtinth we polyfill promises always because the included promise implementation is much faster than Chromes native promises (see https://github.com/petkaantonov/bluebird/blob/master/benchmark/stats/latest.md). @matthewp I actually agree it would make sense to open up the evaluation implementation at this point. |
For some odd reason, Google Chrome requires sourceURL to be able to
display source maps in stack traces correctly.