forked from facebook/react
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
41 lines (37 loc) · 1.05 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
'use strict';
var visitors = require('./vendor/fbtransform/visitors');
var transform = require('jstransform').transform;
var Buffer = require('buffer').Buffer;
module.exports = {
React: React,
transform: function(input, options) {
options = options || {};
var visitorList = getVisitors(options.harmony);
var result = transform(visitorList, input, options);
var output = result.code;
if (options.sourceMap) {
var map = inlineSourceMap(
result.sourceMap,
input,
options.sourceFilename
);
output += '\n' + map;
}
return output;
}
};
function getVisitors(harmony) {
if (harmony) {
return visitors.getAllVisitors();
} else {
return visitors.transformVisitors.react;
}
}
function inlineSourceMap(sourceMap, sourceCode, sourceFilename) {
var json = sourceMap.toJSON();
json.sources = [sourceFilename];
json.sourcesContent = [sourceCode];
var base64 = Buffer(JSON.stringify(json)).toString('base64');
return '//# sourceMappingURL=data:application/json;base64,' +
base64;
}