Skip to content

Commit

Permalink
Expose --target flag on jsx executable
Browse files Browse the repository at this point in the history
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
  • Loading branch information
zpao committed Feb 20, 2015
1 parent 8213831 commit d40be68
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
10 changes: 9 additions & 1 deletion bin/jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ require('commoner').version(
}).option(
'--harmony',
'Turns on JS transformations such as ES6 Classes etc.'
).option(
'--target [version]',
'Specify your target version of ECMAScript. Valid values are "es3" and ' +
'"es5". The default is "es5". "es3" will avoid uses of defineProperty and ' +
'will quote reserved words. WARNING: "es5" is not properly supported, even ' +
'with the use of es5shim, es5sham. If you need to support IE8, use "es3".',
'es5'
).option(
'--strip-types',
'Strips out type annotations.'
Expand All @@ -37,7 +44,8 @@ require('commoner').version(
sourceMap: this.options.sourceMapInline,
stripTypes: this.options.stripTypes,
es6module: this.options.es6module,
nonStrictEs6Module: this.options.nonStrictEs6Module
nonStrictEs6Module: this.options.nonStrictEs6Module,
target: this.options.target
};
return transform(source, options);
});
10 changes: 10 additions & 0 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ function processOptions(opts) {
options.sourceType = 'nonStrict6Module';
}

// Instead of doing any fancy validation, only look for 'es3'. If we have
// that, then use it. Otherwise use 'es5'.
options.es3 = opts.target === 'es3';
options.es5 = !options.es3;

return options;
}

Expand All @@ -72,6 +77,11 @@ function innerTransform(input, options) {
if (options.harmony) {
visitorSets.push('harmony');
}

if (options.es3) {
visitorSets.push('es3');
}

if (options.stripTypes) {
// Stripping types needs to happen before the other transforms
// unfortunately, due to bad interactions. For example,
Expand Down
8 changes: 7 additions & 1 deletion vendor/fbtransform/visitors.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ var es7SpreadProperty =
require('jstransform/visitors/es7-spread-property-visitors');
var react = require('./transforms/react');
var reactDisplayName = require('./transforms/reactDisplayName');
var reservedWords = require('jstransform/visitors/reserved-words-visitors');

/**
* Map from transformName => orderedListOfVisitors.
Expand All @@ -30,7 +31,8 @@ var transformVisitors = {
'es6-rest-params': es6RestParameters.visitorList,
'es6-templates': es6Templates.visitorList,
'es7-spread-property': es7SpreadProperty.visitorList,
'react': react.visitorList.concat(reactDisplayName.visitorList)
'react': react.visitorList.concat(reactDisplayName.visitorList),
'reserved-words': reservedWords.visitorList
};

var transformSets = {
Expand All @@ -44,6 +46,9 @@ var transformSets = {
'es6-destructuring',
'es7-spread-property'
],
'es3': [
'reserved-words'
],
'react': [
'react'
]
Expand All @@ -53,6 +58,7 @@ var transformSets = {
* Specifies the order in which each transform should run.
*/
var transformRunOrder = [
'reserved-words',
'es6-arrow-functions',
'es6-object-concise-method',
'es6-object-short-notation',
Expand Down

0 comments on commit d40be68

Please sign in to comment.