@@ -2,6 +2,8 @@ import * as monaco from 'monaco-editor';
2
2
import { watchEffect } from 'vue' ;
3
3
import { transform } from '@babel/core' ;
4
4
import babelPluginJsx from '@vue/babel-plugin-jsx' ;
5
+ // @ts -expect-error missing types
6
+ import typescript from '@babel/plugin-syntax-typescript' ;
5
7
import {
6
8
type VueJSXPluginOptions ,
7
9
compilerOptions ,
@@ -25,6 +27,8 @@ function main() {
25
27
26
28
const sharedEditorOptions : monaco . editor . IStandaloneEditorConstructionOptions =
27
29
{
30
+ language : 'typescript' ,
31
+ tabSize : 2 ,
28
32
theme : 'vs-dark' ,
29
33
fontSize : 14 ,
30
34
wordWrap : 'on' ,
@@ -36,29 +40,37 @@ function main() {
36
40
} ,
37
41
} ;
38
42
43
+ monaco . languages . typescript . typescriptDefaults . setDiagnosticsOptions ( {
44
+ noSemanticValidation : true ,
45
+ } ) ;
39
46
monaco . languages . typescript . typescriptDefaults . setCompilerOptions ( {
40
47
allowJs : true ,
41
48
allowNonTsExtensions : true ,
42
49
jsx : monaco . languages . typescript . JsxEmit . Preserve ,
43
50
target : monaco . languages . typescript . ScriptTarget . Latest ,
51
+ module : monaco . languages . typescript . ModuleKind . ESNext ,
52
+ isolatedModules : true ,
44
53
} ) ;
45
54
46
55
const editor = monaco . editor . create ( document . getElementById ( 'source' ) ! , {
47
- value :
48
- decodeURIComponent ( window . location . hash . slice ( 1 ) ) ||
49
- persistedState . src ||
50
- 'const App = () => <div>Hello World</div>' ,
51
- language : 'typescript' ,
52
- tabSize : 2 ,
53
56
...sharedEditorOptions ,
57
+ model : monaco . editor . createModel (
58
+ decodeURIComponent ( window . location . hash . slice ( 1 ) ) ||
59
+ persistedState . src ||
60
+ 'const App = () => <div>Hello World</div>' ,
61
+ 'typescript' ,
62
+ monaco . Uri . parse ( 'file:///app.tsx' )
63
+ ) ,
54
64
} ) ;
55
65
56
66
const output = monaco . editor . create ( document . getElementById ( 'output' ) ! , {
57
- value : '' ,
58
- language : 'javascript' ,
59
67
readOnly : true ,
60
- tabSize : 2 ,
61
68
...sharedEditorOptions ,
69
+ model : monaco . editor . createModel (
70
+ '' ,
71
+ 'typescript' ,
72
+ monaco . Uri . parse ( 'file:///output.tsx' )
73
+ ) ,
62
74
} ) ;
63
75
64
76
const reCompile = ( ) => {
@@ -74,7 +86,10 @@ function main() {
74
86
src ,
75
87
{
76
88
babelrc : false ,
77
- plugins : [ [ babelPluginJsx , { ...compilerOptions } ] ] ,
89
+ plugins : [
90
+ [ babelPluginJsx , { ...compilerOptions } ] ,
91
+ [ typescript , { isTSX : true } ] ,
92
+ ] ,
78
93
ast : true ,
79
94
} ,
80
95
( err , result = { } ) => {
0 commit comments