Skip to content

Commit c67e78a

Browse files
committed
chore(compiler-sfc): gracefully handle failed parse when analyzing bindings
1 parent 273d19a commit c67e78a

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

packages/compiler-sfc/src/compileScript.ts

+16-10
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import MagicString from 'magic-string'
22
import { BindingMetadata } from '@vue/compiler-core'
33
import { SFCDescriptor, SFCScriptBlock } from './parse'
4-
import { parse, ParserPlugin } from '@babel/parser'
4+
import { parse, ParserPlugin, ParserOptions } from '@babel/parser'
55
import { babelParserDefaultPlugins, generateCodeFrame } from '@vue/shared'
66
import {
77
Node,
@@ -72,15 +72,21 @@ export function compileScript(
7272
// do not process non js/ts script blocks
7373
return script
7474
}
75-
const scriptAst = parse(script.content, {
76-
plugins,
77-
sourceType: 'module'
78-
}).program.body
79-
return {
80-
...script,
81-
content: hasCssVars ? injectCssVarsCalls(sfc, plugins) : script.content,
82-
bindings: analyzeScriptBindings(scriptAst),
83-
scriptAst
75+
try {
76+
const scriptAst = parse(script.content, {
77+
plugins,
78+
sourceType: 'module'
79+
}).program.body
80+
return {
81+
...script,
82+
content: hasCssVars ? injectCssVarsCalls(sfc, plugins) : script.content,
83+
bindings: analyzeScriptBindings(scriptAst),
84+
scriptAst
85+
}
86+
} catch (e) {
87+
// silently fallback if parse fails since user may be using custom
88+
// babel syntax
89+
return script
8490
}
8591
}
8692

0 commit comments

Comments
 (0)