Skip to content

Commit 852ae10

Browse files
committed
progress
1 parent 85e24b3 commit 852ae10

File tree

3 files changed

+35
-25
lines changed

3 files changed

+35
-25
lines changed

src/compiler/codegen/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ function genNode (node: ASTNode, state: CodegenState): string {
417417
}
418418
}
419419

420-
function genText (text: ASTText | ASTExpression): string {
420+
export function genText (text: ASTText | ASTExpression): string {
421421
return `_v(${text.type === 2
422422
? text.expression // no need for () because already wrapped in _s()
423423
: transformSpecialNewlines(JSON.stringify(text.text))

src/server/optimizing-compiler/codegen.js

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@
55
// a node is not optimizable it simply falls back to the default codegen.
66

77
// import * as directives from './directives'
8-
import { FULL, PARTIAL, CHILDREN } from './optimizer'
8+
import { FULL, SELF, PARTIAL, CHILDREN } from './optimizer'
99

1010
import {
1111
genIf,
1212
genFor,
1313
genData,
14+
genText,
1415
genElement,
1516
genChildren,
1617
CodegenState
@@ -54,13 +55,16 @@ function genSSRElement (el: ASTElement, state: SSRCodegenState): string {
5455
switch (el.ssrOptimizability) {
5556
case FULL:
5657
// stringify whole tree
57-
return genStringNode(el, state, true)
58-
case PARTIAL:
58+
return genStringElement(el, state, true)
59+
case SELF:
5960
// stringify self and check children
60-
return genStringNode(el, state, false)
61+
return genStringElement(el, state, false)
6162
case CHILDREN:
63+
// generate self as VNode and stringify children
64+
return genNormalElement(el, state, true)
65+
case PARTIAL:
6266
// generate self as VNode and check children
63-
return genVNode(el, state)
67+
return genNormalElement(el, state, false)
6468
default:
6569
// bail whole tree
6670
return genElement(el, state)
@@ -70,29 +74,29 @@ function genSSRElement (el: ASTElement, state: SSRCodegenState): string {
7074
function genSSRNode (el, state) {
7175
return el.type === 1
7276
? genSSRElement(el, state)
73-
: genStringNode(el, state)
77+
: genText(el, state)
7478
}
7579

7680
function genSSRChildren (el, state, checkSkip) {
7781
return genChildren(el, state, checkSkip, genSSRElement, genSSRNode)
7882
}
7983

80-
function genVNode (el, state) {
81-
let code
84+
function genNormalElement (el, state, stringifyChildren) {
8285
const data = el.plain ? undefined : genData(el, state)
83-
const children = el.inlineTemplate ? null : genSSRChildren(el, state, true)
84-
code = `_c('${el.tag}'${
86+
const children = stringifyChildren
87+
? genStringChildren(el, state)
88+
: genSSRChildren(el, state, true)
89+
return `_c('${el.tag}'${
8590
data ? `,${data}` : '' // data
8691
}${
8792
children ? `,${children}` : '' // children
8893
})`
89-
// module transforms
90-
for (let i = 0; i < state.transforms.length; i++) {
91-
code = state.transforms[i](el, code)
92-
}
93-
return code
9494
}
9595

96-
function genStringNode (el, state, includeChildren) {
97-
return '!!!'
96+
function genStringElement (el, state, stringifyChildren) {
97+
return '"string element"'
98+
}
99+
100+
function genStringChildren (el, state) {
101+
return '"string children"'
98102
}

src/server/optimizing-compiler/optimizer.js

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ import { no, makeMap, isBuiltInTag } from 'shared/util'
55
// optimizability constants
66
export const FALSE = 0 // whole sub tree un-optimizable
77
export const FULL = 1 // whole sub tree optimizable
8-
export const PARTIAL = 2 // self optimizable but has un-optimizable children
9-
export const CHILDREN = 3 // self un-optimizable but may have optimizable children
8+
export const SELF = 2 // self optimizable but has some un-optimizable children
9+
export const CHILDREN = 3 // self un-optimizable but have fully optimizable children
10+
export const PARTIAL = 4 // self un-optimizable with some un-optimizable children
1011

1112
let isPlatformReservedTag
1213

@@ -38,16 +39,20 @@ function walk (node: ASTNode, isRoot?: boolean) {
3839
for (let i = 0, l = node.children.length; i < l; i++) {
3940
const child = node.children[i]
4041
walk(child)
41-
if (child.ssrOptimizability !== FULL && node.ssrOptimizability == null) {
42-
node.ssrOptimizability = PARTIAL
42+
if (child.ssrOptimizability !== FULL) {
43+
node.ssrOptimizability = node.ssrOptimizability === CHILDREN
44+
? PARTIAL
45+
: SELF
4346
}
4447
}
4548
if (node.ifConditions) {
4649
for (let i = 1, l = node.ifConditions.length; i < l; i++) {
4750
const block = node.ifConditions[i].block
4851
walk(block)
49-
if (block.ssrOptimizability !== FULL && node.ssrOptimizability == null) {
50-
node.ssrOptimizability = PARTIAL
52+
if (block.ssrOptimizability !== FULL) {
53+
node.ssrOptimizability = node.ssrOptimizability === CHILDREN
54+
? PARTIAL
55+
: SELF
5156
}
5257
}
5358
}
@@ -65,7 +70,8 @@ function isUnOptimizableTree (node: ASTNode): boolean {
6570
}
6671
return (
6772
isBuiltInTag(node.tag) || // built-in (slot, component)
68-
!isPlatformReservedTag(node.tag) // custom component
73+
!isPlatformReservedTag(node.tag) || // custom component
74+
!!node.component // "is" component
6975
)
7076
}
7177

0 commit comments

Comments
 (0)