import { watch } from '@vue/runtime-dom'
import { SourceMapConsumer } from 'source-map'
-const self = window as any
+declare global {
+ interface Window {
+ monaco: typeof m
+ _deps: any
+ init: () => void
+ }
+}
-self.init = () => {
- const monaco = (window as any).monaco as typeof m
+window.init = () => {
+ const monaco = window.monaco
const persistedState = JSON.parse(
decodeURIComponent(window.location.hash.slice(1)) || `{}`
)
monaco.editor.setModelMarkers(editor.getModel()!, `@vue/compiler-dom`, [])
console.log(`AST: `, ast)
lastSuccessfulCode = code + `\n\n// Check the console for the AST`
- lastSuccessfulMap = new self._deps['source-map'].SourceMapConsumer(
- map
- ) as SourceMapConsumer
- lastSuccessfulMap.computeColumnSpans()
+ lastSuccessfulMap = new window._deps['source-map'].SourceMapConsumer(map)
+ lastSuccessfulMap!.computeColumnSpans()
} catch (e) {
console.error(e)
}
}
}
- const sharedEditorOptions = {
+ const sharedEditorOptions: m.editor.IEditorConstructionOptions = {
theme: 'vs-dark',
fontSize: 14,
wordWrap: 'on',
minimap: {
enabled: false
}
- } as const
-
- const editor = monaco.editor.create(
- document.getElementById('source') as HTMLElement,
- {
- value: persistedState.src || `<div>Hello World!</div>`,
- language: 'html',
- ...sharedEditorOptions
- }
- )
+ }
+
+ const editor = monaco.editor.create(document.getElementById('source')!, {
+ value: persistedState.src || `<div>Hello World!</div>`,
+ language: 'html',
+ ...sharedEditorOptions
+ })
editor.getModel()!.updateOptions({
tabSize: 2
})
- const output = monaco.editor.create(
- document.getElementById('output') as HTMLElement,
- {
- value: '',
- language: 'javascript',
- readOnly: true,
- ...sharedEditorOptions
- }
- )
+ const output = monaco.editor.create(document.getElementById('output')!, {
+ value: '',
+ language: 'javascript',
+ readOnly: true,
+ ...sharedEditorOptions
+ })
output.getModel()!.updateOptions({
tabSize: 2
})
watch(reCompile)
}
-function debounce<T extends Function>(fn: T, delay: number = 300): T {
+function debounce<T extends (...args: any[]) => any>(
+ fn: T,
+ delay: number = 300
+): T {
let prevTimer: NodeJS.Timeout | null = null
return ((...args: any[]) => {
if (prevTimer) {
checked:
compilerOptions.prefixIdentifiers ||
compilerOptions.mode === 'module',
- onChange(e: any) {
+ onChange(e: Event) {
compilerOptions.prefixIdentifiers =
- e.target.checked || compilerOptions.mode === 'module'
+ (<HTMLInputElement>e.target).checked ||
+ compilerOptions.mode === 'module'
}
}),
h('label', { for: 'prefix' }, 'prefixIdentifiers'),
type: 'checkbox',
id: 'hoist',
checked: compilerOptions.hoistStatic,
- onChange(e: any) {
- compilerOptions.hoistStatic = e.target.checked
+ onChange(e: Event) {
+ compilerOptions.hoistStatic = (<HTMLInputElement>e.target).checked
}
}),
h('label', { for: 'hoist' }, 'hoistStatic')
}
export function initOptions() {
- createApp().mount(App, document.getElementById('header') as HTMLElement)
+ createApp().mount(App, document.getElementById('header')!)
}