refactor(compiler): use shorter helpers for text and comment nodes

This commit is contained in:
Evan You
2019-10-24 17:55:00 -04:00
parent eb20730a67
commit 1c0a2c6d41
19 changed files with 126 additions and 108 deletions

View File

@@ -49,7 +49,7 @@ export { toString } from './helpers/toString'
export { toHandlers } from './helpers/toHandlers'
export { renderSlot } from './helpers/renderSlot'
export { createSlots } from './helpers/createSlots'
export { setBlockTracking } from './vnode'
export { setBlockTracking, createTextVNode } from './vnode'
export { capitalize, camelize } from '@vue/shared'
// Internal, for integration with runtime compiler

View File

@@ -19,10 +19,10 @@ import { AppContext } from './apiApp'
import { SuspenseBoundary } from './suspense'
export const Fragment = __DEV__ ? Symbol('Fragment') : Symbol()
export const Text = __DEV__ ? Symbol('Text') : Symbol()
export const Comment = __DEV__ ? Symbol('Comment') : Symbol()
export const Portal = __DEV__ ? Symbol('Portal') : Symbol()
export const Suspense = __DEV__ ? Symbol('Suspense') : Symbol()
export const Text = __DEV__ ? Symbol('Text') : Symbol()
export const Comment = __DEV__ ? Symbol('Comment') : Symbol()
export type VNodeTypes =
| string
@@ -254,6 +254,14 @@ export function cloneVNode(vnode: VNode): VNode {
}
}
export function createTextVNode(text: string = ' ', flag: number = 0): VNode {
return createVNode(Text, null, text, flag)
}
export function createCommentVNode(text: string = ''): VNode {
return createVNode(Comment, null, text)
}
export function normalizeVNode(child: VNodeChild): VNode {
if (child == null) {
// empty placeholder