workflow: make template-explorer error tolerant
This commit is contained in:
parent
0615cf0108
commit
723dc8791b
@ -25,13 +25,20 @@ window.init = () => {
|
|||||||
function compileCode(source: string): string {
|
function compileCode(source: string): string {
|
||||||
console.clear()
|
console.clear()
|
||||||
try {
|
try {
|
||||||
|
const errors: CompilerError[] = []
|
||||||
const { code, ast, map } = compile(source, {
|
const { code, ast, map } = compile(source, {
|
||||||
filename: 'template.vue',
|
filename: 'template.vue',
|
||||||
...compilerOptions,
|
...compilerOptions,
|
||||||
sourceMap: true,
|
sourceMap: true,
|
||||||
onError: displayError
|
onError: err => {
|
||||||
|
errors.push(err)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
monaco.editor.setModelMarkers(editor.getModel()!, `@vue/compiler-dom`, [])
|
monaco.editor.setModelMarkers(
|
||||||
|
editor.getModel()!,
|
||||||
|
`@vue/compiler-dom`,
|
||||||
|
errors.filter(e => e.loc).map(formatError)
|
||||||
|
)
|
||||||
console.log(`AST: `, ast)
|
console.log(`AST: `, ast)
|
||||||
lastSuccessfulCode = code + `\n\n// Check the console for the AST`
|
lastSuccessfulCode = code + `\n\n// Check the console for the AST`
|
||||||
lastSuccessfulMap = new window._deps['source-map'].SourceMapConsumer(map)
|
lastSuccessfulMap = new window._deps['source-map'].SourceMapConsumer(map)
|
||||||
@ -42,11 +49,9 @@ window.init = () => {
|
|||||||
return lastSuccessfulCode
|
return lastSuccessfulCode
|
||||||
}
|
}
|
||||||
|
|
||||||
function displayError(err: CompilerError) {
|
function formatError(err: CompilerError) {
|
||||||
const loc = err.loc
|
const loc = err.loc!
|
||||||
if (loc) {
|
return {
|
||||||
monaco.editor.setModelMarkers(editor.getModel()!, `@vue/compiler-dom`, [
|
|
||||||
{
|
|
||||||
severity: monaco.MarkerSeverity.Error,
|
severity: monaco.MarkerSeverity.Error,
|
||||||
startLineNumber: loc.start.line,
|
startLineNumber: loc.start.line,
|
||||||
startColumn: loc.start.column,
|
startColumn: loc.start.column,
|
||||||
@ -55,9 +60,6 @@ window.init = () => {
|
|||||||
message: `Vue template compilation error: ${err.message}`,
|
message: `Vue template compilation error: ${err.message}`,
|
||||||
code: String(err.code)
|
code: String(err.code)
|
||||||
}
|
}
|
||||||
])
|
|
||||||
}
|
|
||||||
throw err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function reCompile() {
|
function reCompile() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user