Skip to content
Merged
Show file tree
Hide file tree
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: 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