forked from meteor/meteor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbabel.js
71 lines (58 loc) · 1.98 KB
/
babel.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
var meteorBabel = Npm.require('meteor-babel');
function validateExtraFeatures(extraFeatures) {
if (extraFeatures) {
check(extraFeatures, {
// Modify options to enable ES2015 module syntax.
modules: Match.Optional(Boolean),
// Modify options to enable async/await syntax powered by Fibers.
meteorAsyncAwait: Match.Optional(Boolean),
// Modify options to enable React/JSX syntax.
react: Match.Optional(Boolean),
// Improve compatibility in older versions of Internet Explorer.
jscript: Match.Optional(Boolean)
});
}
}
/**
* Returns a new object containing default options appropriate for
*/
function getDefaultOptions(extraFeatures) {
validateExtraFeatures(extraFeatures);
// See https://github.com/meteor/babel/blob/master/options.js for more
// information about what the default options are.
var options = meteorBabel.getDefaultOptions(extraFeatures);
// The sourceMap option should probably be removed from the default
// options returned by meteorBabel.getDefaultOptions.
delete options.sourceMap;
return options;
}
Babel = {
getDefaultOptions: getDefaultOptions,
validateExtraFeatures: validateExtraFeatures,
compile: function (source, options) {
options = options || getDefaultOptions();
return meteorBabel.compile(source, options);
},
// Provided for backwards compatibility; prefer Babel.compile.
transformMeteor: function (source, extraOptions) {
var options = getDefaultOptions();
if (extraOptions) {
if (extraOptions.extraWhitelist) {
options.whitelist.push.apply(
options.whitelist,
extraOptions.extraWhitelist
);
}
for (var key in extraOptions) {
if (key !== "extraWhitelist" &&
hasOwnProperty.call(extraOptions, key)) {
options[key] = extraOptions[key];
}
}
}
return meteorBabel.compile(source, options);
},
setCacheDir: function (cacheDir) {
meteorBabel.setCacheDir(cacheDir);
}
};