mirror of https://github.com/vuejs/core.git
chore(compiler-sfc): gracefully handle failed parse when analyzing bindings
This commit is contained in:
parent
273d19ad46
commit
c67e78ab6f
|
@ -1,7 +1,7 @@
|
|||
import MagicString from 'magic-string'
|
||||
import { BindingMetadata } from '@vue/compiler-core'
|
||||
import { SFCDescriptor, SFCScriptBlock } from './parse'
|
||||
import { parse, ParserPlugin } from '@babel/parser'
|
||||
import { parse, ParserPlugin, ParserOptions } from '@babel/parser'
|
||||
import { babelParserDefaultPlugins, generateCodeFrame } from '@vue/shared'
|
||||
import {
|
||||
Node,
|
||||
|
@ -72,6 +72,7 @@ export function compileScript(
|
|||
// do not process non js/ts script blocks
|
||||
return script
|
||||
}
|
||||
try {
|
||||
const scriptAst = parse(script.content, {
|
||||
plugins,
|
||||
sourceType: 'module'
|
||||
|
@ -82,6 +83,11 @@ export function compileScript(
|
|||
bindings: analyzeScriptBindings(scriptAst),
|
||||
scriptAst
|
||||
}
|
||||
} catch (e) {
|
||||
// silently fallback if parse fails since user may be using custom
|
||||
// babel syntax
|
||||
return script
|
||||
}
|
||||
}
|
||||
|
||||
if (script && scriptLang !== scriptSetupLang) {
|
||||
|
|
Loading…
Reference in New Issue