From 4b51ad048306367a6fb6fbee7445e086d855f31e Mon Sep 17 00:00:00 2001 From: Evan You Date: Sun, 4 Dec 2016 17:50:45 +0100 Subject: [PATCH] rename _h -> _c so that vue-template-es2015-compiler can use the new internal createElement without breaking backwards compatibility --- flow/component.js | 2 +- src/compiler/codegen/index.js | 6 +++--- src/core/instance/render.js | 8 +++++--- test/unit/modules/compiler/compiler-options.spec.js | 2 +- 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/flow/component.js b/flow/component.js index 992c7566c..f40bbd890 100644 --- a/flow/component.js +++ b/flow/component.js @@ -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 diff --git a/src/compiler/codegen/index.js b/src/compiler/codegen/index.js index f12ffaac6..ac7740500 100644 --- a/src/compiler/codegen/index.js +++ b/src/compiler/codegen/index.js @@ -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}` : '' })` } diff --git a/src/core/instance/render.js b/src/core/instance/render.js index bea490d1b..4b8568c0b 100644 --- a/src/core/instance/render.js +++ b/src/core/instance/render.js @@ -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) diff --git a/test/unit/modules/compiler/compiler-options.spec.js b/test/unit/modules/compiler/compiler-options.spec.js index 405458cc3..e5017f22f 100644 --- a/test/unit/modules/compiler/compiler-options.spec.js +++ b/test/unit/modules/compiler/compiler-options.spec.js @@ -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)},