Fix sourcemaps in JSXTransformer for Firefox
Fixes #1725
Paul O’Shannessy committed
Jul 9, 2014 at 09:31 UTC
336890291e0090977e0019d4aaf47ccbdbf901d3
1 file changed
+10
-1
vendor/browser-transforms.js
+10
-1
@@ -20,6 +20,7 @@
20
var runScripts;
21
var loadScripts;
22
var headEl;
23
+var dummyAnchor;
24
25
var buffer = require('buffer');
26
var transform = require('jstransform').transform;
@@ -124,13 +125,20 @@ var transformCode = function(code, source, options) {
125
if (inlineScriptCount > 1) {
126
source += ' (' + inlineScriptCount + ')';
127
}
128
+ } else if (dummyAnchor) {
129
+ // Firefox has problems when the sourcemap source is a proper URL with a
130
+ // protocol and hostname, so use the pathname. We could use just the
131
+ // filename, but hopefully using the full path will prevent potential
132
+ // issues where the same filename exists in multiple directories.
133
+ dummyAnchor.href = source;
134
+ source = dummyAnchor.pathname.substr(1);
135
}
136
map.sources = [source];
137
map.sourcesContent = [code];
138
139
return (
140
transformed.code +
133
- '//# sourceMappingURL=data:application/json;base64,' +
141
+ '\n//# sourceMappingURL=data:application/json;base64,' +
142
buffer.Buffer(JSON.stringify(map)).toString('base64')
143
);
144
} else {
@@ -226,6 +234,7 @@ runScripts = function() {
234
235
if (typeof window !== "undefined" && window !== null) {
236
headEl = document.getElementsByTagName('head')[0];
237
+ dummyAnchor = document.createElement('a');
238
239
if (window.addEventListener) {
240
window.addEventListener('DOMContentLoaded', runScripts, false);