Skip to content

Commit e8e7947

Browse files
committed
Merge pull request facebook#2527 from gabelevi/master
Update stripTypes transform to use fixed up jstransform transform
2 parents 795290d + 0d308ad commit e8e7947

File tree

5 files changed

+27
-9
lines changed

5 files changed

+27
-9
lines changed

main.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
var visitors = require('./vendor/fbtransform/visitors');
44
var transform = require('jstransform').transform;
5+
var typesSyntax = require('jstransform/visitors/type-syntax');
56
var Buffer = require('buffer').Buffer;
67

78
module.exports = {
@@ -37,7 +38,11 @@ function innerTransform(input, options) {
3738
visitorSets.push('harmony');
3839
}
3940
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;
4146
}
4247

4348
var visitorList = visitors.getVisitorsBySet(visitorSets);

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
},
2828
"dependencies": {
2929
"commoner": "^0.10.0",
30-
"jstransform": "^7.0.0"
30+
"jstransform": "^8.0.0"
3131
},
3232
"devDependencies": {
3333
"benchmark": "~1.0.0",

vendor/browser-transforms.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
var buffer = require('buffer');
1515
var transform = require('jstransform').transform;
16+
var typesSyntax = require('jstransform/visitors/type-syntax');
1617
var visitors = require('./fbtransform/visitors');
1718

1819
var headEl;
@@ -42,6 +43,14 @@ function transformReact(source, options) {
4243
visitorList = visitors.transformVisitors.react;
4344
}
4445

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+
4554
return transform(visitorList, source, {
4655
sourceMap: supportsAccessors && options.sourceMap
4756
});
@@ -240,6 +249,9 @@ function loadScripts(scripts) {
240249
if (/;harmony=true(;|$)/.test(script.type)) {
241250
options.harmony = true;
242251
}
252+
if (/;stripTypes=true(;|$)/.test(script.type)) {
253+
options.stripTypes = true;
254+
}
243255

244256
// script.async is always true for non-javascript script tags
245257
var async = script.hasAttribute('async');

vendor/fbtransform/syntax.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"use strict";
55

66
var transform = require('jstransform').transform;
7+
var typesSyntax = require('jstransform/visitors/type-syntax');
78
var visitors = require('./visitors');
89

910
/**
@@ -16,6 +17,12 @@ var visitors = require('./visitors');
1617
function transformAll(source, options, excludes) {
1718
excludes = excludes || [];
1819

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+
1926
// The typechecker transform must run in a second pass in order to operate on
2027
// the entire source code -- so exclude it from the first pass
2128
var visitorsList = visitors.getAllVisitors(excludes.concat('typechecker'));

vendor/fbtransform/visitors.js

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ var es6Templates = require('jstransform/visitors/es6-template-visitors');
99
var es7SpreadProperty = require('jstransform/visitors/es7-spread-property-visitors');
1010
var react = require('./transforms/react');
1111
var reactDisplayName = require('./transforms/reactDisplayName');
12-
var typesSyntax = require('jstransform/visitors/type-syntax');
1312

1413
/**
1514
* Map from transformName => orderedListOfVisitors.
@@ -23,8 +22,7 @@ var transformVisitors = {
2322
'es6-rest-params': es6RestParameters.visitorList,
2423
'es6-templates': es6Templates.visitorList,
2524
'es7-spread-property': es7SpreadProperty.visitorList,
26-
'react': react.visitorList.concat(reactDisplayName.visitorList),
27-
'types': typesSyntax.visitorList
25+
'react': react.visitorList.concat(reactDisplayName.visitorList)
2826
};
2927

3028
var transformSets = {
@@ -40,17 +38,13 @@ var transformSets = {
4038
],
4139
'react': [
4240
'react'
43-
],
44-
'type-annotations': [
45-
'types'
4641
]
4742
};
4843

4944
/**
5045
* Specifies the order in which each transform should run.
5146
*/
5247
var transformRunOrder = [
53-
'types',
5448
'es6-arrow-functions',
5549
'es6-object-concise-method',
5650
'es6-object-short-notation',

0 commit comments

Comments
 (0)