Expose --target flag on jsx executable
Valid values are 'es3' and 'es5'. es3: perform reserved words quoting, don't use defineProperty es5: default, don't do the above, class methods non-enumerable
Paul O’Shannessy committed
Jan 12, 2015 at 14:08 UTC
d40be68d2c559fee87aa3bf0cbbe63d949c6cfbd
3 files changed
+26
-2
bin/jsx
+9
-1
@@ -11,6 +11,13 @@ require('commoner').version(
11
}).option(
12
'--harmony',
13
'Turns on JS transformations such as ES6 Classes etc.'
14
+).option(
15
+ '--target [version]',
16
+ 'Specify your target version of ECMAScript. Valid values are "es3" and ' +
17
+ '"es5". The default is "es5". "es3" will avoid uses of defineProperty and ' +
18
+ 'will quote reserved words. WARNING: "es5" is not properly supported, even ' +
19
+ 'with the use of es5shim, es5sham. If you need to support IE8, use "es3".',
20
+ 'es5'
21
).option(
22
'--strip-types',
23
'Strips out type annotations.'
@@ -37,7 +44,8 @@ require('commoner').version(
44
sourceMap: this.options.sourceMapInline,
45
stripTypes: this.options.stripTypes,
46
es6module: this.options.es6module,
40
- nonStrictEs6Module: this.options.nonStrictEs6Module
47
+ nonStrictEs6Module: this.options.nonStrictEs6Module,
48
+ target: this.options.target
49
};
50
return transform(source, options);
51
});
main.js
+10
@@ -64,6 +64,11 @@ function processOptions(opts) {
64
options.sourceType = 'nonStrict6Module';
65
}
66
67
+ // Instead of doing any fancy validation, only look for 'es3'. If we have
68
+ // that, then use it. Otherwise use 'es5'.
69
+ options.es3 = opts.target === 'es3';
70
+ options.es5 = !options.es3;
71
+
72
return options;
73
}
74
@@ -72,6 +77,11 @@ function innerTransform(input, options) {
77
if (options.harmony) {
78
visitorSets.push('harmony');
79
}
80
+
81
+ if (options.es3) {
82
+ visitorSets.push('es3');
83
+ }
84
+
85
if (options.stripTypes) {
86
// Stripping types needs to happen before the other transforms
87
// unfortunately, due to bad interactions. For example,
vendor/fbtransform/visitors.js
+7
-1
@@ -17,6 +17,7 @@ var es7SpreadProperty =
17
require('jstransform/visitors/es7-spread-property-visitors');
18
var react = require('./transforms/react');
19
var reactDisplayName = require('./transforms/reactDisplayName');
20
+var reservedWords = require('jstransform/visitors/reserved-words-visitors');
21
22
/**
23
* Map from transformName => orderedListOfVisitors.
@@ -30,7 +31,8 @@ var transformVisitors = {
31
'es6-rest-params': es6RestParameters.visitorList,
32
'es6-templates': es6Templates.visitorList,
33
'es7-spread-property': es7SpreadProperty.visitorList,
33
- 'react': react.visitorList.concat(reactDisplayName.visitorList)
34
+ 'react': react.visitorList.concat(reactDisplayName.visitorList),
35
+ 'reserved-words': reservedWords.visitorList
36
};
37
38
var transformSets = {
@@ -44,6 +46,9 @@ var transformSets = {
46
'es6-destructuring',
47
'es7-spread-property'
48
],
49
+ 'es3': [
50
+ 'reserved-words'
51
+ ],
52
'react': [
53
'react'
54
]
@@ -53,6 +58,7 @@ var transformSets = {
58
* Specifies the order in which each transform should run.
59
*/
60
var transformRunOrder = [
61
+ 'reserved-words',
62
'es6-arrow-functions',
63
'es6-object-concise-method',
64
'es6-object-short-notation',