File tree 1 file changed +16
-10
lines changed
packages/compiler-sfc/src
1 file changed +16
-10
lines changed Original file line number Diff line number Diff line change 1
1
import MagicString from 'magic-string'
2
2
import { BindingMetadata } from '@vue/compiler-core'
3
3
import { SFCDescriptor , SFCScriptBlock } from './parse'
4
- import { parse , ParserPlugin } from '@babel/parser'
4
+ import { parse , ParserPlugin , ParserOptions } from '@babel/parser'
5
5
import { babelParserDefaultPlugins , generateCodeFrame } from '@vue/shared'
6
6
import {
7
7
Node ,
@@ -72,15 +72,21 @@ export function compileScript(
72
72
// do not process non js/ts script blocks
73
73
return script
74
74
}
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
84
90
}
85
91
}
86
92
You can’t perform that action at this time.
0 commit comments