@@ -22,7 +22,8 @@ import {
22
22
SSRCodegenNode ,
23
23
TemplateLiteral ,
24
24
IfStatement ,
25
- AssignmentExpression
25
+ AssignmentExpression ,
26
+ ReturnStatement
26
27
} from './ast'
27
28
import { SourceMapGenerator , RawSourceMap } from 'source-map'
28
29
import {
@@ -44,8 +45,7 @@ import {
44
45
CREATE_TEXT ,
45
46
PUSH_SCOPE_ID ,
46
47
POP_SCOPE_ID ,
47
- WITH_SCOPE_ID ,
48
- CREATE_BLOCK
48
+ WITH_SCOPE_ID
49
49
} from './runtimeHelpers'
50
50
import { ImportItem } from './transform'
51
51
@@ -334,24 +334,12 @@ function genModulePreamble(
334
334
context : CodegenContext ,
335
335
genScopeId : boolean
336
336
) {
337
- const { push, helper, newline, scopeId, runtimeModuleName, ssr } = context
337
+ const { push, helper, newline, scopeId, runtimeModuleName } = context
338
338
339
- if ( ! __BROWSER__ ) {
340
- // in ssr mode, `withId` helper is only needed if the template contains
341
- // de-optimized component slots (which uses the createVNode helper)
342
- if (
343
- ssr &&
344
- ! (
345
- ast . helpers . includes ( CREATE_VNODE ) || ast . helpers . includes ( CREATE_BLOCK )
346
- )
347
- ) {
348
- genScopeId = false
349
- }
350
- if ( genScopeId ) {
351
- ast . helpers . push ( WITH_SCOPE_ID )
352
- if ( ast . hoists . length ) {
353
- ast . helpers . push ( PUSH_SCOPE_ID , POP_SCOPE_ID )
354
- }
339
+ if ( ! __BROWSER__ && genScopeId ) {
340
+ ast . helpers . push ( WITH_SCOPE_ID )
341
+ if ( ast . hoists . length ) {
342
+ ast . helpers . push ( PUSH_SCOPE_ID , POP_SCOPE_ID )
355
343
}
356
344
}
357
345
@@ -572,6 +560,9 @@ function genNode(node: CodegenNode | symbol | string, context: CodegenContext) {
572
560
case NodeTypes . JS_ASSIGNMENT_EXPRESSION :
573
561
! __BROWSER__ && genAssignmentExpression ( node , context )
574
562
break
563
+ case NodeTypes . JS_RETURN_STATEMENT :
564
+ ! __BROWSER__ && genReturnStatement ( node , context )
565
+ break
575
566
576
567
/* istanbul ignore next */
577
568
default :
@@ -851,3 +842,15 @@ function genAssignmentExpression(
851
842
context . push ( ` = ` )
852
843
genNode ( node . right , context )
853
844
}
845
+
846
+ function genReturnStatement (
847
+ { returns } : ReturnStatement ,
848
+ context : CodegenContext
849
+ ) {
850
+ context . push ( `return ` )
851
+ if ( isArray ( returns ) ) {
852
+ genNodeListAsArray ( returns , context )
853
+ } else {
854
+ genNode ( returns , context )
855
+ }
856
+ }
0 commit comments