@@ -3,8 +3,7 @@ import { render } from 'react-dom';
33import MonacoEditor from 'react-monaco-editor' ;
44import * as ts from 'typescript' ;
55
6- import { allTransforms } from '../src'
7- import { react } from './react' ;
6+ import { allTransforms } from 'react-js-to-ts'
87
98const defaultInput = `
109import * as React from 'react';
@@ -26,7 +25,7 @@ class App extends React.Component<{}, AppState> {
2625 static toolbarHeight = 50 ;
2726 state = { input : defaultInput , output : '' , windowSize : { width : 0 , height : 0 } }
2827 compilerOptions : ts . CompilerOptions = {
29- target : ts . ScriptTarget . ES2017 ,
28+ target : ts . ScriptTarget . ES2015 ,
3029 module : ts . ModuleKind . ES2015 ,
3130 }
3231 host : ts . CompilerHost = {
@@ -41,7 +40,7 @@ class App extends React.Component<{}, AppState> {
4140 getNewLine : ( ) => '\n' ,
4241 getCurrentDirectory : ( ) => '/' ,
4342 getDefaultLibFileName : ( ) => 'lib.ts' ,
44- fileExists : ( fileName : string ) => {
43+ fileExists : ( fileName : string ) => {
4544 console . log ( 'fileExist' , fileName )
4645 return fileName === 'main.tsx' ;
4746 } ,
@@ -69,17 +68,18 @@ class App extends React.Component<{}, AppState> {
6968 editor . focus ( ) ;
7069 }
7170 onChange = ( newValue : string , e : monaco . editor . IModelContentChangedEvent2 ) => {
72- this . setState ( { input : newValue } ) ;
71+ this . setState ( { input : newValue } ) ;
7372 try {
7473 const output = this . compile ( this . state . input ) ;
75- this . setState ( { output } )
74+ this . setState ( { output } )
7675 } catch ( error ) {
7776 console . error ( error ) ;
7877 }
7978 }
8079 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 ) ;
8281 const program = ts . createProgram ( [ 'main.tsx' ] , this . compilerOptions , this . host ) ;
82+ program . emit ( ) ;
8383 const typeChecker = program . getTypeChecker ( ) ;
8484 const result = ts . transform ( [ sourceFile ] , allTransforms . map ( f => f ( typeChecker ) ) ) ;
8585 const printer = ts . createPrinter ( ) ;
0 commit comments