Skip to content

Commit 9ccc539

Browse files
committed
fix: catch prettier errors
1 parent 243dd75 commit 9ccc539

File tree

1 file changed

+20
-14
lines changed

1 file changed

+20
-14
lines changed

src/codemirror/CodeMirror.vue

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -65,21 +65,27 @@ onMounted(() => {
6565
})
6666
6767
editor.on('blur', () => {
68-
const parser = props.mode === 'vue' ? 'html'
69-
: props.mode === 'htmlmixed' ? 'html'
70-
: props.mode === 'javascript' ? 'babel'
71-
: props.mode === 'css' ? 'postcss'
68+
const parser = props.extension === 'vue' ? 'html'
69+
: props.extension === 'html' ? 'html'
70+
: props.extension === 'css' ? 'css'
71+
: props.extension === 'js' ? 'babel'
72+
: props.extension === 'ts' ? 'babel'
7273
: props.extension || props.mode
73-
emit('change', prettier.format(
74-
editor.getValue(),
75-
{
76-
parser,
77-
plugins: [parserBabel, parserHtml, parserPostcss],
78-
semi: false,
79-
singleQuote: true,
80-
arrowParens: 'avoid',
81-
}
82-
))
74+
75+
const options = {
76+
parser,
77+
plugins: [parserBabel, parserHtml, parserPostcss],
78+
semi: false,
79+
singleQuote: true,
80+
arrowParens: 'avoid' as const,
81+
}
82+
83+
let code = editor.getValue()
84+
try {
85+
code = prettier.format(code, options)
86+
} catch (err) {}
87+
88+
emit('change', code)
8389
})
8490
8591
watchEffect(() => {

0 commit comments

Comments
 (0)