Browse Source

progress

dev
Evan You 8 years ago
parent
commit
852ae102d4
  1. 2
      src/compiler/codegen/index.js
  2. 38
      src/server/optimizing-compiler/codegen.js
  3. 20
      src/server/optimizing-compiler/optimizer.js

2
src/compiler/codegen/index.js

@ -417,7 +417,7 @@ function genNode (node: ASTNode, state: CodegenState): string {
}
}
function genText (text: ASTText | ASTExpression): string {
export function genText (text: ASTText | ASTExpression): string {
return `_v(${text.type === 2
? text.expression // no need for () because already wrapped in _s()
: transformSpecialNewlines(JSON.stringify(text.text))

38
src/server/optimizing-compiler/codegen.js

@ -5,12 +5,13 @@
// a node is not optimizable it simply falls back to the default codegen.
// import * as directives from './directives'
import { FULL, PARTIAL, CHILDREN } from './optimizer'
import { FULL, SELF, PARTIAL, CHILDREN } from './optimizer'
import {
genIf,
genFor,
genData,
genText,
genElement,
genChildren,
CodegenState
@ -54,13 +55,16 @@ function genSSRElement (el: ASTElement, state: SSRCodegenState): string {
switch (el.ssrOptimizability) {
case FULL:
// stringify whole tree
return genStringNode(el, state, true)
case PARTIAL:
return genStringElement(el, state, true)
case SELF:
// stringify self and check children
return genStringNode(el, state, false)
return genStringElement(el, state, false)
case CHILDREN:
// generate self as VNode and stringify children
return genNormalElement(el, state, true)
case PARTIAL:
// generate self as VNode and check children
return genVNode(el, state)
return genNormalElement(el, state, false)
default:
// bail whole tree
return genElement(el, state)
@ -70,29 +74,29 @@ function genSSRElement (el: ASTElement, state: SSRCodegenState): string {
function genSSRNode (el, state) {
return el.type === 1
? genSSRElement(el, state)
: genStringNode(el, state)
: genText(el, state)
}
function genSSRChildren (el, state, checkSkip) {
return genChildren(el, state, checkSkip, genSSRElement, genSSRNode)
}
function genVNode (el, state) {
let code
function genNormalElement (el, state, stringifyChildren) {
const data = el.plain ? undefined : genData(el, state)
const children = el.inlineTemplate ? null : genSSRChildren(el, state, true)
code = `_c('${el.tag}'${
const children = stringifyChildren
? genStringChildren(el, state)
: genSSRChildren(el, state, true)
return `_c('${el.tag}'${
data ? `,${data}` : '' // data
}${
children ? `,${children}` : '' // children
})`
// module transforms
for (let i = 0; i < state.transforms.length; i++) {
code = state.transforms[i](el, code)
}
return code
}
function genStringNode (el, state, includeChildren) {
return '!!!'
function genStringElement (el, state, stringifyChildren) {
return '"string element"'
}
function genStringChildren (el, state) {
return '"string children"'
}

20
src/server/optimizing-compiler/optimizer.js

@ -5,8 +5,9 @@ import { no, makeMap, isBuiltInTag } from 'shared/util'
// optimizability constants
export const FALSE = 0 // whole sub tree un-optimizable
export const FULL = 1 // whole sub tree optimizable
export const PARTIAL = 2 // self optimizable but has un-optimizable children
export const CHILDREN = 3 // self un-optimizable but may have optimizable children
export const SELF = 2 // self optimizable but has some un-optimizable children
export const CHILDREN = 3 // self un-optimizable but have fully optimizable children
export const PARTIAL = 4 // self un-optimizable with some un-optimizable children
let isPlatformReservedTag
@ -38,16 +39,20 @@ function walk (node: ASTNode, isRoot?: boolean) {
for (let i = 0, l = node.children.length; i < l; i++) {
const child = node.children[i]
walk(child)
if (child.ssrOptimizability !== FULL && node.ssrOptimizability == null) {
node.ssrOptimizability = PARTIAL
if (child.ssrOptimizability !== FULL) {
node.ssrOptimizability = node.ssrOptimizability === CHILDREN
? PARTIAL
: SELF
}
}
if (node.ifConditions) {
for (let i = 1, l = node.ifConditions.length; i < l; i++) {
const block = node.ifConditions[i].block
walk(block)
if (block.ssrOptimizability !== FULL && node.ssrOptimizability == null) {
node.ssrOptimizability = PARTIAL
if (block.ssrOptimizability !== FULL) {
node.ssrOptimizability = node.ssrOptimizability === CHILDREN
? PARTIAL
: SELF
}
}
}
@ -65,7 +70,8 @@ function isUnOptimizableTree (node: ASTNode): boolean {
}
return (
isBuiltInTag(node.tag) || // built-in (slot, component)
!isPlatformReservedTag(node.tag) // custom component
!isPlatformReservedTag(node.tag) || // custom component
!!node.component // "is" component
)
}

Loading…
Cancel
Save