Update stripTypes transform to use fixed up jstransform transform
Gabe Levi committed
Nov 14, 2014 at 17:58 UTC
0d308add09df27456d2cd0bf99848d43b0115388
5 files changed
+27
-9
main.js
+6
-1
@@ -2,6 +2,7 @@
2
3
var visitors = require('./vendor/fbtransform/visitors');
4
var transform = require('jstransform').transform;
5
+var typesSyntax = require('jstransform/visitors/type-syntax');
6
var Buffer = require('buffer').Buffer;
7
8
module.exports = {
@@ -37,7 +38,11 @@ function innerTransform(input, options) {
38
visitorSets.push('harmony');
39
}
40
if (options.stripTypes) {
40
- visitorSets.push('type-annotations');
41
+ // Stripping types needs to happen before the other transforms
42
+ // unfortunately, due to bad interactions. For example,
43
+ // es6-rest-param-visitors conflict with stripping rest param type
44
+ // annotation
45
+ input = transform(typesSyntax.visitorList, input, options).code;
46
}
47
48
var visitorList = visitors.getVisitorsBySet(visitorSets);
package.json
+1
-1
@@ -27,7 +27,7 @@
27
},
28
"dependencies": {
29
"commoner": "^0.10.0",
30
- "jstransform": "^7.0.0"
30
+ "jstransform": "^8.0.0"
31
},
32
"devDependencies": {
33
"benchmark": "~1.0.0",
vendor/browser-transforms.js
+12
@@ -13,6 +13,7 @@
13
14
var buffer = require('buffer');
15
var transform = require('jstransform').transform;
16
+var typesSyntax = require('jstransform/visitors/type-syntax');
17
var visitors = require('./fbtransform/visitors');
18
19
var headEl;
@@ -42,6 +43,14 @@ function transformReact(source, options) {
43
visitorList = visitors.transformVisitors.react;
44
}
45
46
+ if (options.stripTypes) {
47
+ // Stripping types needs to happen before the other transforms
48
+ // unfortunately, due to bad interactions. For example,
49
+ // es6-rest-param-visitors conflict with stripping rest param type
50
+ // annotation
51
+ source = transform(typesSyntax.visitorList, source, options).code;
52
+ }
53
+
54
return transform(visitorList, source, {
55
sourceMap: supportsAccessors && options.sourceMap
56
});
@@ -240,6 +249,9 @@ function loadScripts(scripts) {
249
if (/;harmony=true(;|$)/.test(script.type)) {
250
options.harmony = true;
251
}
252
+ if (/;stripTypes=true(;|$)/.test(script.type)) {
253
+ options.stripTypes = true;
254
+ }
255
256
// script.async is always true for non-javascript script tags
257
var async = script.hasAttribute('async');
vendor/fbtransform/syntax.js
+7
@@ -4,6 +4,7 @@
4
"use strict";
5
6
var transform = require('jstransform').transform;
7
+var typesSyntax = require('jstransform/visitors/type-syntax');
8
var visitors = require('./visitors');
9
10
/**
@@ -16,6 +17,12 @@ var visitors = require('./visitors');
17
function transformAll(source, options, excludes) {
18
excludes = excludes || [];
19
20
+ // Stripping types needs to happen before the other transforms
21
+ // unfortunately, due to bad interactions. For example,
22
+ // es6-rest-param-visitors conflict with stripping rest param type
23
+ // annotation
24
+ source = transform(typesSyntax.visitorList, source, options).code;
25
+
26
// The typechecker transform must run in a second pass in order to operate on
27
// the entire source code -- so exclude it from the first pass
28
var visitorsList = visitors.getAllVisitors(excludes.concat('typechecker'));
vendor/fbtransform/visitors.js
+1
-7
@@ -9,7 +9,6 @@ var es6Templates = require('jstransform/visitors/es6-template-visitors');
9
var es7SpreadProperty = require('jstransform/visitors/es7-spread-property-visitors');
10
var react = require('./transforms/react');
11
var reactDisplayName = require('./transforms/reactDisplayName');
12
-var typesSyntax = require('jstransform/visitors/type-syntax');
12
13
/**
14
* Map from transformName => orderedListOfVisitors.
@@ -23,8 +22,7 @@ var transformVisitors = {
22
'es6-rest-params': es6RestParameters.visitorList,
23
'es6-templates': es6Templates.visitorList,
24
'es7-spread-property': es7SpreadProperty.visitorList,
26
- 'react': react.visitorList.concat(reactDisplayName.visitorList),
27
- 'types': typesSyntax.visitorList
25
+ 'react': react.visitorList.concat(reactDisplayName.visitorList)
26
};
27
28
var transformSets = {
@@ -40,9 +38,6 @@ var transformSets = {
38
],
39
'react': [
40
'react'
43
- ],
44
- 'type-annotations': [
45
- 'types'
41
]
42
};
43
@@ -50,7 +45,6 @@ var transformSets = {
45
* Specifies the order in which each transform should run.
46
*/
47
var transformRunOrder = [
53
- 'types',
48
'es6-arrow-functions',
49
'es6-object-concise-method',
50
'es6-object-short-notation',