@@ -4,10 +4,16 @@ import { compilerOptions, initOptions } from './options'
4
4
import { watch } from '@vue/runtime-dom'
5
5
import { SourceMapConsumer } from 'source-map'
6
6
7
- const self = window as any
7
+ declare global {
8
+ interface Window {
9
+ monaco : typeof m
10
+ _deps : any
11
+ init : ( ) => void
12
+ }
13
+ }
8
14
9
- self . init = ( ) => {
10
- const monaco = ( window as any ) . monaco as typeof m
15
+ window . init = ( ) => {
16
+ const monaco = window . monaco
11
17
const persistedState = JSON . parse (
12
18
decodeURIComponent ( window . location . hash . slice ( 1 ) ) || `{}`
13
19
)
@@ -28,10 +34,8 @@ self.init = () => {
28
34
monaco . editor . setModelMarkers ( editor . getModel ( ) ! , `@vue/compiler-dom` , [ ] )
29
35
console . log ( `AST: ` , ast )
30
36
lastSuccessfulCode = code + `\n\n// Check the console for the AST`
31
- lastSuccessfulMap = new self . _deps [ 'source-map' ] . SourceMapConsumer (
32
- map
33
- ) as SourceMapConsumer
34
- lastSuccessfulMap . computeColumnSpans ( )
37
+ lastSuccessfulMap = new window . _deps [ 'source-map' ] . SourceMapConsumer ( map )
38
+ lastSuccessfulMap ! . computeColumnSpans ( )
35
39
} catch ( e ) {
36
40
console . error ( e )
37
41
}
@@ -71,7 +75,7 @@ self.init = () => {
71
75
}
72
76
}
73
77
74
- const sharedEditorOptions = {
78
+ const sharedEditorOptions : m . editor . IEditorConstructionOptions = {
75
79
theme : 'vs-dark' ,
76
80
fontSize : 14 ,
77
81
wordWrap : 'on' ,
@@ -81,30 +85,24 @@ self.init = () => {
81
85
minimap : {
82
86
enabled : false
83
87
}
84
- } as const
85
-
86
- const editor = monaco . editor . create (
87
- document . getElementById ( 'source' ) as HTMLElement ,
88
- {
89
- value : persistedState . src || `<div>Hello World!</div>` ,
90
- language : 'html' ,
91
- ...sharedEditorOptions
92
- }
93
- )
88
+ }
89
+
90
+ const editor = monaco . editor . create ( document . getElementById ( 'source' ) ! , {
91
+ value : persistedState . src || `<div>Hello World!</div>` ,
92
+ language : 'html' ,
93
+ ...sharedEditorOptions
94
+ } )
94
95
95
96
editor . getModel ( ) ! . updateOptions ( {
96
97
tabSize : 2
97
98
} )
98
99
99
- const output = monaco . editor . create (
100
- document . getElementById ( 'output' ) as HTMLElement ,
101
- {
102
- value : '' ,
103
- language : 'javascript' ,
104
- readOnly : true ,
105
- ...sharedEditorOptions
106
- }
107
- )
100
+ const output = monaco . editor . create ( document . getElementById ( 'output' ) ! , {
101
+ value : '' ,
102
+ language : 'javascript' ,
103
+ readOnly : true ,
104
+ ...sharedEditorOptions
105
+ } )
108
106
output . getModel ( ) ! . updateOptions ( {
109
107
tabSize : 2
110
108
} )
@@ -207,7 +205,10 @@ self.init = () => {
207
205
watch ( reCompile )
208
206
}
209
207
210
- function debounce < T extends Function > ( fn : T , delay : number = 300 ) : T {
208
+ function debounce < T extends ( ...args : any [ ] ) => any > (
209
+ fn : T ,
210
+ delay : number = 300
211
+ ) : T {
211
212
let prevTimer : NodeJS . Timeout | null = null
212
213
return ( ( ...args : any [ ] ) => {
213
214
if ( prevTimer ) {
0 commit comments