wip(compiler-ssr): text and interpolation

This commit is contained in:
Evan You
2020-02-02 22:28:54 -05:00
parent d1eed36452
commit 63e4486645
6 changed files with 87 additions and 36 deletions

View File

@@ -1,22 +1,15 @@
import { NodeTransform } from '../transform'
import {
NodeTypes,
TemplateChildNode,
TextNode,
InterpolationNode,
CompoundExpressionNode,
createCallExpression,
CallExpression,
ElementTypes
} from '../ast'
import { isText } from '../utils'
import { CREATE_TEXT } from '../runtimeHelpers'
import { PatchFlags, PatchFlagNames } from '@vue/shared'
const isText = (
node: TemplateChildNode
): node is TextNode | InterpolationNode =>
node.type === NodeTypes.INTERPOLATION || node.type === NodeTypes.TEXT
// Merge adjacent text nodes and expressions into a single expression
// e.g. <div>abc {{ d }} {{ e }}</div> should have a single expression node as child.
export const transformText: NodeTransform = (node, context) => {

View File

@@ -22,7 +22,9 @@ import {
SlotOutletCodegenNode,
ComponentCodegenNode,
ExpressionNode,
IfBranchNode
IfBranchNode,
TextNode,
InterpolationNode
} from './ast'
import { parse } from 'acorn'
import { walk } from 'estree-walker'
@@ -213,6 +215,12 @@ export function createBlockExpression(
])
}
export function isText(
node: TemplateChildNode
): node is TextNode | InterpolationNode {
return node.type === NodeTypes.INTERPOLATION || node.type === NodeTypes.TEXT
}
export function isVSlot(p: ElementNode['props'][0]): p is DirectiveNode {
return p.type === NodeTypes.DIRECTIVE && p.name === 'slot'
}
@@ -257,10 +265,11 @@ export function injectProp(
// check existing key to avoid overriding user provided keys
if (prop.key.type === NodeTypes.SIMPLE_EXPRESSION) {
const propKeyName = prop.key.content
alreadyExists = props.properties.some(p => (
p.key.type === NodeTypes.SIMPLE_EXPRESSION &&
p.key.content === propKeyName
))
alreadyExists = props.properties.some(
p =>
p.key.type === NodeTypes.SIMPLE_EXPRESSION &&
p.key.content === propKeyName
)
}
if (!alreadyExists) {
props.properties.unshift(prop)