Skip to content

Commit f31ccea

Browse files
author
Mohsen Azimi
committed
WIP
1 parent 919a47d commit f31ccea

File tree

6 files changed

+52
-3561
lines changed

6 files changed

+52
-3561
lines changed

editor/editor.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ import { render } from 'react-dom';
33
import MonacoEditor from 'react-monaco-editor';
44
import * as ts from 'typescript';
55

6-
import { allTransforms } from '../src'
7-
import {react} from './react';
6+
import { allTransforms } from 'react-js-to-ts'
87

98
const defaultInput = `
109
import * 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();

editor/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"monaco-editor": "^0.9.0",
1919
"react": "^15.6.1",
2020
"react-dom": "^15.6.1",
21+
"react-js-to-ts": "^1.2.0",
2122
"react-monaco-editor": "^0.8.1",
2223
"ts-loader": "^2.3.0",
2324
"ts-node": "^3.2.0",

0 commit comments

Comments
 (0)