From 0d308add09df27456d2cd0bf99848d43b0115388 Mon Sep 17 00:00:00 2001 From: Gabe Levi Date: Fri, 14 Nov 2014 17:58:51 -0800 Subject: [PATCH] Update stripTypes transform to use fixed up jstransform transform --- main.js | 7 ++++++- package.json | 2 +- vendor/browser-transforms.js | 12 ++++++++++++ vendor/fbtransform/syntax.js | 7 +++++++ vendor/fbtransform/visitors.js | 8 +------- 5 files changed, 27 insertions(+), 9 deletions(-) diff --git a/main.js b/main.js index 6973dbe5f9..7a977556d7 100644 --- a/main.js +++ b/main.js @@ -2,6 +2,7 @@ var visitors = require('./vendor/fbtransform/visitors'); var transform = require('jstransform').transform; +var typesSyntax = require('jstransform/visitors/type-syntax'); var Buffer = require('buffer').Buffer; module.exports = { @@ -37,7 +38,11 @@ function innerTransform(input, options) { visitorSets.push('harmony'); } if (options.stripTypes) { - visitorSets.push('type-annotations'); + // Stripping types needs to happen before the other transforms + // unfortunately, due to bad interactions. For example, + // es6-rest-param-visitors conflict with stripping rest param type + // annotation + input = transform(typesSyntax.visitorList, input, options).code; } var visitorList = visitors.getVisitorsBySet(visitorSets); diff --git a/package.json b/package.json index 13d09b49c2..3caf193024 100644 --- a/package.json +++ b/package.json @@ -27,7 +27,7 @@ }, "dependencies": { "commoner": "^0.10.0", - "jstransform": "^7.0.0" + "jstransform": "^8.0.0" }, "devDependencies": { "benchmark": "~1.0.0", diff --git a/vendor/browser-transforms.js b/vendor/browser-transforms.js index fa13d13d60..bed157dfc6 100644 --- a/vendor/browser-transforms.js +++ b/vendor/browser-transforms.js @@ -13,6 +13,7 @@ var buffer = require('buffer'); var transform = require('jstransform').transform; +var typesSyntax = require('jstransform/visitors/type-syntax'); var visitors = require('./fbtransform/visitors'); var headEl; @@ -42,6 +43,14 @@ function transformReact(source, options) { visitorList = visitors.transformVisitors.react; } + if (options.stripTypes) { + // Stripping types needs to happen before the other transforms + // unfortunately, due to bad interactions. For example, + // es6-rest-param-visitors conflict with stripping rest param type + // annotation + source = transform(typesSyntax.visitorList, source, options).code; + } + return transform(visitorList, source, { sourceMap: supportsAccessors && options.sourceMap }); @@ -240,6 +249,9 @@ function loadScripts(scripts) { if (/;harmony=true(;|$)/.test(script.type)) { options.harmony = true; } + if (/;stripTypes=true(;|$)/.test(script.type)) { + options.stripTypes = true; + } // script.async is always true for non-javascript script tags var async = script.hasAttribute('async'); diff --git a/vendor/fbtransform/syntax.js b/vendor/fbtransform/syntax.js index e3dcefe8bc..976649ca3d 100644 --- a/vendor/fbtransform/syntax.js +++ b/vendor/fbtransform/syntax.js @@ -4,6 +4,7 @@ "use strict"; var transform = require('jstransform').transform; +var typesSyntax = require('jstransform/visitors/type-syntax'); var visitors = require('./visitors'); /** @@ -16,6 +17,12 @@ var visitors = require('./visitors'); function transformAll(source, options, excludes) { excludes = excludes || []; + // Stripping types needs to happen before the other transforms + // unfortunately, due to bad interactions. For example, + // es6-rest-param-visitors conflict with stripping rest param type + // annotation + source = transform(typesSyntax.visitorList, source, options).code; + // The typechecker transform must run in a second pass in order to operate on // the entire source code -- so exclude it from the first pass var visitorsList = visitors.getAllVisitors(excludes.concat('typechecker')); diff --git a/vendor/fbtransform/visitors.js b/vendor/fbtransform/visitors.js index 88e209b7a3..a15a1fc2aa 100644 --- a/vendor/fbtransform/visitors.js +++ b/vendor/fbtransform/visitors.js @@ -9,7 +9,6 @@ var es6Templates = require('jstransform/visitors/es6-template-visitors'); var es7SpreadProperty = require('jstransform/visitors/es7-spread-property-visitors'); var react = require('./transforms/react'); var reactDisplayName = require('./transforms/reactDisplayName'); -var typesSyntax = require('jstransform/visitors/type-syntax'); /** * Map from transformName => orderedListOfVisitors. @@ -23,8 +22,7 @@ var transformVisitors = { 'es6-rest-params': es6RestParameters.visitorList, 'es6-templates': es6Templates.visitorList, 'es7-spread-property': es7SpreadProperty.visitorList, - 'react': react.visitorList.concat(reactDisplayName.visitorList), - 'types': typesSyntax.visitorList + 'react': react.visitorList.concat(reactDisplayName.visitorList) }; var transformSets = { @@ -40,9 +38,6 @@ var transformSets = { ], 'react': [ 'react' - ], - 'type-annotations': [ - 'types' ] }; @@ -50,7 +45,6 @@ var transformSets = { * Specifies the order in which each transform should run. */ var transformRunOrder = [ - 'types', 'es6-arrow-functions', 'es6-object-concise-method', 'es6-object-short-notation',