rename _h -> _c so that vue-template-es2015-compiler can use the new internal createElement without breaking backwards compatibility

This commit is contained in:
Evan You 2016-12-04 17:50:45 +01:00
parent 207c18c47f
commit 4b51ad0483
4 changed files with 10 additions and 8 deletions

View File

@ -81,7 +81,7 @@ declare interface Component {
_render: () => VNode;
__patch__: (a: Element | VNode | void, b: VNode) => any;
// createElement
_h: (vnode?: VNode, data?: VNodeData, children?: VNodeChildren) => VNode | void;
_c: (vnode?: VNode, data?: VNodeData, children?: VNodeChildren) => VNode | void;
// renderStatic
_m: (index: number, isInFor?: boolean) => VNode | VNodeChildren;
// markOnce

View File

@ -31,7 +31,7 @@ export function generate (
transforms = pluckModuleFunction(options.modules, 'transformCode')
dataGenFns = pluckModuleFunction(options.modules, 'genData')
platformDirectives = options.directives || {}
const code = ast ? genElement(ast) : '_h("div")'
const code = ast ? genElement(ast) : '_c("div")'
staticRenderFns = prevStaticRenderFns
onceCount = prevOnceCount
return {
@ -62,7 +62,7 @@ function genElement (el: ASTElement): string {
const data = el.plain ? undefined : genData(el)
const children = el.inlineTemplate ? null : genChildren(el, true)
code = `_h('${el.tag}'${
code = `_c('${el.tag}'${
data ? `,${data}` : '' // data
}${
children ? `,${children}` : '' // children
@ -336,7 +336,7 @@ function genSlot (el: ASTElement): string {
// componentName is el.component, take it as argument to shun flow's pessimistic refinement
function genComponent (componentName, el): string {
const children = el.inlineTemplate ? null : genChildren(el, true)
return `_h(${componentName},${genData(el)}${
return `_c(${componentName},${genData(el)}${
children ? `,${children}` : ''
})`
}

View File

@ -32,9 +32,11 @@ export function initRender (vm: Component) {
vm.$scopedSlots = {}
// bind the createElement fn to this instance
// so that we get proper render context inside it.
// args order: tag, data, children, needNormalization
// the needNormalization flag is disabled for the public version.
vm._h = (a, b, c, d) => createElement(vm, a, b, c, d, false)
// args order: tag, data, children, needNormalization, alwaysNormalize
// internal version is used by render functions compiled from templates
vm._c = (a, b, c, d) => createElement(vm, a, b, c, d, false)
// normalization is always applied for the public version, used in
// user-written render functions.
vm.$createElement = (a, b, c, d) => createElement(vm, a, b, c, d, true)
if (vm.$options.el) {
vm.$mount(vm.$options.el)

View File

@ -51,7 +51,7 @@ describe('compile options', () => {
result[validator.name] = null
})
// generate code
return `_h('validate',{props:{
return `_c('validate',{props:{
field:${JSON.stringify(el.validate.field)},
groups:${JSON.stringify(el.validate.groups)},
validators:${JSON.stringify(el.validators)},