Merge pull request #2527 from gabelevi/master

Update stripTypes transform to use fixed up jstransform transform
This commit is contained in:
Christopher Chedeau
2014-11-15 16:57:25 -08:00
5 changed files with 27 additions and 9 deletions
+6 -1
View File
@@ -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);
+1 -1
View File
@@ -27,7 +27,7 @@
},
"dependencies": {
"commoner": "^0.10.0",
"jstransform": "^7.0.0"
"jstransform": "^8.0.0"
},
"devDependencies": {
"benchmark": "~1.0.0",
+12
View File
@@ -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');
+7
View File
@@ -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'));
+1 -7
View File
@@ -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',