@@ -3,8 +3,7 @@ import { render } from 'react-dom';
3
3
import MonacoEditor from 'react-monaco-editor' ;
4
4
import * as ts from 'typescript' ;
5
5
6
- import { allTransforms } from '../src'
7
- import { react } from './react' ;
6
+ import { allTransforms } from 'react-js-to-ts'
8
7
9
8
const defaultInput = `
10
9
import * as React from 'react';
@@ -26,7 +25,7 @@ class App extends React.Component<{}, AppState> {
26
25
static toolbarHeight = 50 ;
27
26
state = { input : defaultInput , output : '' , windowSize : { width : 0 , height : 0 } }
28
27
compilerOptions : ts . CompilerOptions = {
29
- target : ts . ScriptTarget . ES2017 ,
28
+ target : ts . ScriptTarget . ES2015 ,
30
29
module : ts . ModuleKind . ES2015 ,
31
30
}
32
31
host : ts . CompilerHost = {
@@ -41,7 +40,7 @@ class App extends React.Component<{}, AppState> {
41
40
getNewLine : ( ) => '\n' ,
42
41
getCurrentDirectory : ( ) => '/' ,
43
42
getDefaultLibFileName : ( ) => 'lib.ts' ,
44
- fileExists : ( fileName : string ) => {
43
+ fileExists : ( fileName : string ) => {
45
44
console . log ( 'fileExist' , fileName )
46
45
return fileName === 'main.tsx' ;
47
46
} ,
@@ -69,17 +68,18 @@ class App extends React.Component<{}, AppState> {
69
68
editor . focus ( ) ;
70
69
}
71
70
onChange = ( newValue : string , e : monaco . editor . IModelContentChangedEvent2 ) => {
72
- this . setState ( { input : newValue } ) ;
71
+ this . setState ( { input : newValue } ) ;
73
72
try {
74
73
const output = this . compile ( this . state . input ) ;
75
- this . setState ( { output } )
74
+ this . setState ( { output } )
76
75
} catch ( error ) {
77
76
console . error ( error ) ;
78
77
}
79
78
}
80
79
compile = ( input : string ) => {
81
- const sourceFile = ts . createSourceFile ( 'main.tsx' , this . state . input , ts . ScriptTarget . ES2017 ) ;
80
+ const sourceFile = ts . createSourceFile ( 'main.tsx' , this . state . input , this . compilerOptions . target ) ;
82
81
const program = ts . createProgram ( [ 'main.tsx' ] , this . compilerOptions , this . host ) ;
82
+ program . emit ( ) ;
83
83
const typeChecker = program . getTypeChecker ( ) ;
84
84
const result = ts . transform ( [ sourceFile ] , allTransforms . map ( f => f ( typeChecker ) ) ) ;
85
85
const printer = ts . createPrinter ( ) ;
0 commit comments