mirror of https://github.com/vuejs/vue.git
rename _h -> _c so that vue-template-es2015-compiler can use the new internal createElement without breaking backwards compatibility
This commit is contained in:
parent
207c18c47f
commit
4b51ad0483
|
@ -81,7 +81,7 @@ declare interface Component {
|
||||||
_render: () => VNode;
|
_render: () => VNode;
|
||||||
__patch__: (a: Element | VNode | void, b: VNode) => any;
|
__patch__: (a: Element | VNode | void, b: VNode) => any;
|
||||||
// createElement
|
// createElement
|
||||||
_h: (vnode?: VNode, data?: VNodeData, children?: VNodeChildren) => VNode | void;
|
_c: (vnode?: VNode, data?: VNodeData, children?: VNodeChildren) => VNode | void;
|
||||||
// renderStatic
|
// renderStatic
|
||||||
_m: (index: number, isInFor?: boolean) => VNode | VNodeChildren;
|
_m: (index: number, isInFor?: boolean) => VNode | VNodeChildren;
|
||||||
// markOnce
|
// markOnce
|
||||||
|
|
|
@ -31,7 +31,7 @@ export function generate (
|
||||||
transforms = pluckModuleFunction(options.modules, 'transformCode')
|
transforms = pluckModuleFunction(options.modules, 'transformCode')
|
||||||
dataGenFns = pluckModuleFunction(options.modules, 'genData')
|
dataGenFns = pluckModuleFunction(options.modules, 'genData')
|
||||||
platformDirectives = options.directives || {}
|
platformDirectives = options.directives || {}
|
||||||
const code = ast ? genElement(ast) : '_h("div")'
|
const code = ast ? genElement(ast) : '_c("div")'
|
||||||
staticRenderFns = prevStaticRenderFns
|
staticRenderFns = prevStaticRenderFns
|
||||||
onceCount = prevOnceCount
|
onceCount = prevOnceCount
|
||||||
return {
|
return {
|
||||||
|
@ -62,7 +62,7 @@ function genElement (el: ASTElement): string {
|
||||||
const data = el.plain ? undefined : genData(el)
|
const data = el.plain ? undefined : genData(el)
|
||||||
|
|
||||||
const children = el.inlineTemplate ? null : genChildren(el, true)
|
const children = el.inlineTemplate ? null : genChildren(el, true)
|
||||||
code = `_h('${el.tag}'${
|
code = `_c('${el.tag}'${
|
||||||
data ? `,${data}` : '' // data
|
data ? `,${data}` : '' // data
|
||||||
}${
|
}${
|
||||||
children ? `,${children}` : '' // children
|
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
|
// componentName is el.component, take it as argument to shun flow's pessimistic refinement
|
||||||
function genComponent (componentName, el): string {
|
function genComponent (componentName, el): string {
|
||||||
const children = el.inlineTemplate ? null : genChildren(el, true)
|
const children = el.inlineTemplate ? null : genChildren(el, true)
|
||||||
return `_h(${componentName},${genData(el)}${
|
return `_c(${componentName},${genData(el)}${
|
||||||
children ? `,${children}` : ''
|
children ? `,${children}` : ''
|
||||||
})`
|
})`
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,9 +32,11 @@ export function initRender (vm: Component) {
|
||||||
vm.$scopedSlots = {}
|
vm.$scopedSlots = {}
|
||||||
// bind the createElement fn to this instance
|
// bind the createElement fn to this instance
|
||||||
// so that we get proper render context inside it.
|
// so that we get proper render context inside it.
|
||||||
// args order: tag, data, children, needNormalization
|
// args order: tag, data, children, needNormalization, alwaysNormalize
|
||||||
// the needNormalization flag is disabled for the public version.
|
// internal version is used by render functions compiled from templates
|
||||||
vm._h = (a, b, c, d) => createElement(vm, a, b, c, d, false)
|
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)
|
vm.$createElement = (a, b, c, d) => createElement(vm, a, b, c, d, true)
|
||||||
if (vm.$options.el) {
|
if (vm.$options.el) {
|
||||||
vm.$mount(vm.$options.el)
|
vm.$mount(vm.$options.el)
|
||||||
|
|
|
@ -51,7 +51,7 @@ describe('compile options', () => {
|
||||||
result[validator.name] = null
|
result[validator.name] = null
|
||||||
})
|
})
|
||||||
// generate code
|
// generate code
|
||||||
return `_h('validate',{props:{
|
return `_c('validate',{props:{
|
||||||
field:${JSON.stringify(el.validate.field)},
|
field:${JSON.stringify(el.validate.field)},
|
||||||
groups:${JSON.stringify(el.validate.groups)},
|
groups:${JSON.stringify(el.validate.groups)},
|
||||||
validators:${JSON.stringify(el.validators)},
|
validators:${JSON.stringify(el.validators)},
|
||||||
|
|
Loading…
Reference in New Issue