Move JS linting code to separate component

This commit is contained in:
Andrew Bastin
2020-08-02 11:47:16 -04:00
parent ec99b48605
commit 3c3e8a6c31
2 changed files with 154 additions and 37 deletions

View File

@@ -26,8 +26,6 @@ import "ace-builds/webpack-resolver"
import jsonParse from "~/helpers/jsonParse"
import debounce from "~/helpers/utils/debounce"
import * as esprima from "esprima"
export default {
props: {
value: {
@@ -138,41 +136,6 @@ export default {
},
])
}
} else if (this.lang === "javascript") {
try {
const res = esprima.parseScript(code, { tolerant: true })
console.log(res)
if (res.errors && res.errors.length > 0) {
this.editor.session.setAnnotations(
res.errors.map((err) => {
const pos = this.editor.session.getDocument().indexToPosition(err.index, 0)
console.log({
row: pos.row,
column: pos.column,
text: err.description,
type: "error",
})
return {
row: pos.row,
column: pos.column,
text: err.description,
type: "error",
}
})
)
}
} catch (e) {
const pos = this.editor.session.getDocument().indexToPosition(e.index, 0)
this.editor.session.setAnnotations([
{
row: pos.row,
column: pos.column,
text: e.description,
type: "error",
},
])
}
}
}, 2000),
},