@@ -15,17 +15,21 @@ import * as t from "@babel/types"
15
15
16
16
export function parseCode ( code , extname ) {
17
17
const plugins = [
18
- 'jsx' ,
19
18
'classProperties' ,
20
19
'objectRestSpread' ,
21
20
'optionalChaining' ,
22
21
[ 'decorators' , { decoratorsBeforeExport : true } ] ,
23
22
]
24
23
25
- if ( extname === '.ts' || extname === '.tsx' ) {
24
+
25
+ if ( extname === '.ts' ) {
26
+ plugins . push ( 'typescript' )
27
+ } else if ( extname === '.tsx' ) {
26
28
plugins . push ( 'typescript' )
29
+ plugins . push ( 'jsx' )
27
30
} else {
28
31
plugins . push ( 'flow' )
32
+ plugins . push ( 'jsx' )
29
33
}
30
34
31
35
return parse ( code , {
@@ -39,8 +43,8 @@ const babelTransformJSX = babel.createConfigItem(require("../misc/transformJSX")
39
43
40
44
41
45
const babelFlow = babel . createConfigItem ( require ( "@babel/preset-flow" ) , { type : 'presets' } )
42
- const babelTSX = babel . createConfigItem ( [ require ( "@babel/plugin-transform- typescript" ) , { isTSX : true } ] , { type : 'plugin' } )
43
- const babelTS = babel . createConfigItem ( [ require ( "@babel/plugin-transform- typescript" ) , { isTSX : false } ] , { type : 'plugin' } )
46
+ const babelTSX = babel . createConfigItem ( [ require ( "@babel/preset- typescript" ) , { isTSX : true , allExtensions : true } ] , { type : 'plugin' } )
47
+ const babelTS = babel . createConfigItem ( [ require ( "@babel/preset- typescript" ) , { isTSX : false , allExtensions : true } ] , { type : 'plugin' } )
44
48
45
49
const babelRestSpread = babel . createConfigItem ( [ require ( "@babel/plugin-proposal-object-rest-spread" ) , { "loose" : true , "useBuiltIns" : true } ] )
46
50
const babelClassProperties = babel . createConfigItem ( [ require ( "@babel/plugin-proposal-class-properties" ) , { "loose" : true } ] )
@@ -82,13 +86,15 @@ export function geneReactCode(ast, extname) {
82
86
babelTransformJSX ,
83
87
]
84
88
if ( extname === '.tsx' ) {
85
- plugins . push ( babelTSX )
89
+ presets . push ( babelTSX )
86
90
} else if ( extname === '.ts' ) {
87
- plugins . push ( babelTS )
91
+ presets . push ( babelTS )
88
92
} else {
89
93
presets . push ( babelFlow )
90
94
}
91
95
96
+ console . log ( 'plugins:' , plugins )
97
+
92
98
code = babel . transformSync ( code , {
93
99
babelrc : false ,
94
100
configFile : false ,
0 commit comments