diff --git a/bin/jsx b/bin/jsx index 8188c8a4c3..ac1fa1470c 100755 --- a/bin/jsx +++ b/bin/jsx @@ -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.' @@ -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); }); diff --git a/main.js b/main.js index e7d551440d..52d09eeb16 100644 --- a/main.js +++ b/main.js @@ -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; } @@ -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, diff --git a/vendor/fbtransform/visitors.js b/vendor/fbtransform/visitors.js index 8e78d54aee..1c2bace7c9 100644 --- a/vendor/fbtransform/visitors.js +++ b/vendor/fbtransform/visitors.js @@ -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. @@ -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 = { @@ -44,6 +46,9 @@ var transformSets = { 'es6-destructuring', 'es7-spread-property' ], + 'es3': [ + 'reserved-words' + ], 'react': [ 'react' ] @@ -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',