File tree Expand file tree Collapse file tree 5 files changed +27
-9
lines changed Expand file tree Collapse file tree 5 files changed +27
-9
lines changed Original file line number Diff line number Diff line change 22
33var visitors = require ( './vendor/fbtransform/visitors' ) ;
44var transform = require ( 'jstransform' ) . transform ;
5+ var typesSyntax = require ( 'jstransform/visitors/type-syntax' ) ;
56var Buffer = require ( 'buffer' ) . Buffer ;
67
78module . 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 ) ;
Original file line number Diff line number Diff line change 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" ,
Original file line number Diff line number Diff line change 1313
1414var buffer = require ( 'buffer' ) ;
1515var transform = require ( 'jstransform' ) . transform ;
16+ var typesSyntax = require ( 'jstransform/visitors/type-syntax' ) ;
1617var visitors = require ( './fbtransform/visitors' ) ;
1718
1819var 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 ( / ; h a r m o n y = t r u e ( ; | $ ) / . test ( script . type ) ) {
241250 options . harmony = true ;
242251 }
252+ if ( / ; s t r i p T y p e s = t r u e ( ; | $ ) / . 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' ) ;
Original file line number Diff line number Diff line change 44"use strict" ;
55
66var transform = require ( 'jstransform' ) . transform ;
7+ var typesSyntax = require ( 'jstransform/visitors/type-syntax' ) ;
78var visitors = require ( './visitors' ) ;
89
910/**
@@ -16,6 +17,12 @@ var visitors = require('./visitors');
1617function 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' ) ) ;
Original file line number Diff line number Diff line change @@ -9,7 +9,6 @@ var es6Templates = require('jstransform/visitors/es6-template-visitors');
99var es7SpreadProperty = require ( 'jstransform/visitors/es7-spread-property-visitors' ) ;
1010var react = require ( './transforms/react' ) ;
1111var 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
3028var 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 */
5247var transformRunOrder = [
53- 'types' ,
5448 'es6-arrow-functions' ,
5549 'es6-object-concise-method' ,
5650 'es6-object-short-notation' ,
You can’t perform that action at this time.
0 commit comments