Skip to content

Commit 3368902

Browse files
committed
Fix sourcemaps in JSXTransformer for Firefox
Fixes facebook#1725
1 parent 785d2ca commit 3368902

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

vendor/browser-transforms.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
var runScripts;
2121
var loadScripts;
2222
var headEl;
23+
var dummyAnchor;
2324

2425
var buffer = require('buffer');
2526
var transform = require('jstransform').transform;
@@ -124,13 +125,20 @@ var transformCode = function(code, source, options) {
124125
if (inlineScriptCount > 1) {
125126
source += ' (' + inlineScriptCount + ')';
126127
}
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);
127135
}
128136
map.sources = [source];
129137
map.sourcesContent = [code];
130138

131139
return (
132140
transformed.code +
133-
'//# sourceMappingURL=data:application/json;base64,' +
141+
'\n//# sourceMappingURL=data:application/json;base64,' +
134142
buffer.Buffer(JSON.stringify(map)).toString('base64')
135143
);
136144
} else {
@@ -226,6 +234,7 @@ runScripts = function() {
226234

227235
if (typeof window !== "undefined" && window !== null) {
228236
headEl = document.getElementsByTagName('head')[0];
237+
dummyAnchor = document.createElement('a');
229238

230239
if (window.addEventListener) {
231240
window.addEventListener('DOMContentLoaded', runScripts, false);

0 commit comments

Comments
 (0)