1
1
import compileModule from '../../../utils/compileModule' ;
2
2
import pkg from 'babel7/package.json' ;
3
-
4
3
const ID = 'babelv7' ;
5
4
5
+ function checkForTypescript ( data ) {
6
+ if ( data . includes ( "typescript" ) ) {
7
+ return true ;
8
+ }
9
+ for ( let item of data ) {
10
+ if ( Array . isArray ( item ) ) {
11
+ if ( checkForTypescript ( item ) ) {
12
+ return true ;
13
+ }
14
+ }
15
+ }
16
+ return false ;
17
+ }
6
18
export default {
7
19
id : ID ,
8
20
displayName : ID ,
@@ -14,46 +26,22 @@ export default {
14
26
loadTransformer ( callback ) {
15
27
require ( [
16
28
'../../../transpilers/babel' ,
29
+ '../../../transpilers/typescript' ,
17
30
'babel7' ,
18
31
'recast' ,
19
- ] , ( transpile , babel , recast ) => callback ( { transpile : transpile . default , babel, recast } ) ) ;
32
+ '../../babylon7.js' ,
33
+ ] , ( transpile , transpileTs , babel , recast , babylon7 ) => callback ( { transpile : transpile . default , transpileTs : transpileTs . default , babel, recast, babylon7 } ) ) ;
20
34
} ,
21
35
22
- transform ( { transpile, babel, recast } , transformCode , code ) {
23
- transformCode = transpile ( transformCode ) ;
36
+ transform ( { transpile, transpileTs , babel, recast, babylon7 } , transformCode , code ) {
37
+ transformCode = checkForTypescript ( babylon7 . parserOptions ) ? transpileTs ( transformCode , babylon7 . parserOptions ) : transpile ( transformCode , babylon7 . parserOptions ) ;
24
38
let transform = compileModule ( // eslint-disable-line no-shadow
25
39
transformCode ,
26
40
) ;
27
-
28
41
return babel . transformAsync ( code , {
29
42
parserOpts : {
30
43
parser : recast . parse ,
31
- plugins : [
32
- 'asyncGenerators' ,
33
- 'bigInt' ,
34
- 'classPrivateMethods' ,
35
- 'classPrivateProperties' ,
36
- 'classProperties' ,
37
- [ 'decorators' , { decoratorsBeforeExport : false } ] ,
38
- 'doExpressions' ,
39
- 'dynamicImport' ,
40
- 'exportDefaultFrom' ,
41
- 'exportNamespaceFrom' ,
42
- 'flow' ,
43
- 'flowComments' ,
44
- 'functionBind' ,
45
- 'functionSent' ,
46
- 'importMeta' ,
47
- 'jsx' ,
48
- 'logicalAssignment' ,
49
- 'nullishCoalescingOperator' ,
50
- 'numericSeparator' ,
51
- 'objectRestSpread' ,
52
- 'optionalCatchBinding' ,
53
- 'optionalChaining' ,
54
- [ 'pipelineOperator' , { proposal : 'minimal' } ] ,
55
- 'throwExpressions' ,
56
- ] ,
44
+ plugins : babylon7 . parserOptions ,
57
45
} ,
58
46
retainLines : false ,
59
47
generatorOpts : {
0 commit comments