Skip to content

Commit e9ce0aa

Browse files
committed
feat(compiler-sfc): allow return render in <script setup>
1 parent 2857a59 commit e9ce0aa

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

packages/compiler-sfc/src/script/context.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,12 @@ export class ScriptCompileContext {
101101
options.babelParserPlugins
102102
)
103103

104-
function parse(input: string, offset: number): Program {
104+
function parse(input: string, offset: number, setup?: boolean): Program {
105105
try {
106106
return babelParse(input, {
107107
plugins,
108-
sourceType: 'module'
108+
sourceType: 'module',
109+
allowReturnOutsideFunction: setup
109110
}).program
110111
} catch (e: any) {
111112
e.message = `[vue/compiler-sfc] ${e.message}\n\n${
@@ -125,7 +126,7 @@ export class ScriptCompileContext {
125126

126127
this.scriptSetupAst =
127128
descriptor.scriptSetup &&
128-
parse(descriptor.scriptSetup!.content, this.startOffset!)
129+
parse(descriptor.scriptSetup!.content, this.startOffset!, true)
129130
}
130131

131132
getString(node: Node, scriptSetup = true): string {

0 commit comments

Comments
 (0)