Skip to content
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

Reduced size of JSXTransformer.js by 10%. #1995

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions vendor/browser-transforms.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

'use strict';

var buffer = require('buffer');
var docblock = require('jstransform/src/docblock');
var transform = require('jstransform').transform;
var visitors = require('./fbtransform/visitors');
Expand All @@ -33,6 +32,11 @@ var inlineScriptCount = 0;
// the source map in that case.
var supportsAccessors = Object.prototype.hasOwnProperty('__defineGetter__');

// All the modern browsers have built-in support for Base64 conversion.
// IE<=9 doesn't have support for this but it doesn't support source maps
// either, so we are fine with not generating inline maps for it.
var supportsBase64 = typeof btoa !== 'undefined';

/**
* Run provided code through jstransform.
*
Expand All @@ -50,7 +54,7 @@ function transformReact(source, options) {
}

return transform(visitorList, source, {
sourceMap: supportsAccessors
sourceMap: supportsAccessors && supportsBase64
});
}

Expand Down Expand Up @@ -165,7 +169,7 @@ function transformCode(code, url, options) {
return (
transformed.code +
'\n//# sourceMappingURL=data:application/json;base64,' +
buffer.Buffer(JSON.stringify(map)).toString('base64')
btoa(unescape(encodeURIComponent(JSON.stringify(map))))
);
} else {
// TODO: warn that we found a script tag missing the docblock?
Expand Down