diff --git a/src/compiler/codegen/events.js b/src/compiler/codegen/events.js index 20f8b3b1f6a..3d61123e166 100644 --- a/src/compiler/codegen/events.js +++ b/src/compiler/codegen/events.js @@ -24,7 +24,7 @@ const modifierCode = { export function genHandlers (events: ASTElementHandlers, native?: boolean): string { let res = native ? 'nativeOn:{' : 'on:{' for (const name in events) { - res += `"${name}":${genHandler(events[name])},` + res += `"${name}":v.${genHandler(events[name])},` } return res.slice(0, -1) + '}' } diff --git a/src/compiler/codegen/index.js b/src/compiler/codegen/index.js index 4fd183b5dab..a6c43c19d95 100644 --- a/src/compiler/codegen/index.js +++ b/src/compiler/codegen/index.js @@ -30,11 +30,11 @@ 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) : 'v._h("div")' staticRenderFns = prevStaticRenderFns onceCount = prevOnceCount return { - render: `with(this){return ${code}}`, + render: `var v = this; return ${code}`, staticRenderFns: currentStaticRenderFns } } @@ -61,7 +61,7 @@ function genElement (el: ASTElement): string { const data = el.plain ? undefined : genData(el) const children = el.inlineTemplate ? null : genChildren(el) - code = `_h('${el.tag}'${ + code = `v._h('${el.tag}'${ data ? `,${data}` : '' // data }${ children ? `,${children}` : '' // children @@ -78,7 +78,7 @@ function genElement (el: ASTElement): string { // hoist static sub-trees out function genStatic (el: ASTElement): string { el.staticProcessed = true - staticRenderFns.push(`with(this){return ${genElement(el)}}`) + staticRenderFns.push(`var v = this; return ${genElement(el)}`) return `_m(${staticRenderFns.length - 1}${el.staticInFor ? ',true' : ''})` } @@ -168,7 +168,7 @@ function genData (el: ASTElement): string { } // DOM props if (el.props) { - data += `domProps:{${genProps(el.props)}},` + data += `domProps:{${genProps(el.props, true)}},` } // event handlers if (el.events) { @@ -264,16 +264,20 @@ 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) - return `_h(${componentName},${genData(el)}${ + return `v._h(${componentName},${genData(el)}${ children ? `,${children}` : '' })` } -function genProps (props: Array<{ name: string, value: string }>): string { +function genProps (props: Array<{ name: string, value: string }>, prefix): string { let res = '' for (let i = 0; i < props.length; i++) { const prop = props[i] - res += `"${prop.name}":${prop.value},` + if (prefix) { + res += `"${prop.name}":v.${prop.value},` + } else { + res += `"${prop.name}":${prop.value},` + } } return res.slice(0, -1) } diff --git a/src/compiler/parser/text-parser.js b/src/compiler/parser/text-parser.js index 34f1e018e9d..db05536e986 100644 --- a/src/compiler/parser/text-parser.js +++ b/src/compiler/parser/text-parser.js @@ -31,7 +31,7 @@ export function parseText ( } // tag token const exp = parseFilters(match[1].trim()) - tokens.push(`_s(${exp})`) + tokens.push(`v._s(${exp})`) lastIndex = index + match[0].length } if (lastIndex < text.length) { diff --git a/src/platforms/web/compiler/directives/html.js b/src/platforms/web/compiler/directives/html.js index 58569d8e47e..76d40ca1842 100644 --- a/src/platforms/web/compiler/directives/html.js +++ b/src/platforms/web/compiler/directives/html.js @@ -4,6 +4,7 @@ import { addProp } from 'compiler/helpers' export default function html (el: ASTElement, dir: ASTDirective) { if (dir.value) { - addProp(el, 'innerHTML', `_s(${dir.value})`) + // `v.` prefix is added in genHandlers + addProp(el, 'innerHTML', `_s(v.${dir.value})`) } } diff --git a/src/platforms/web/compiler/directives/model.js b/src/platforms/web/compiler/directives/model.js index 2ae6b711452..2e1f626dece 100644 --- a/src/platforms/web/compiler/directives/model.js +++ b/src/platforms/web/compiler/directives/model.js @@ -141,7 +141,7 @@ function genDefaultModel ( `File inputs are read only. Use a v-on:change listener instead.` ) } - addProp(el, 'value', isNative ? `_s(${value})` : `(${value})`) + addProp(el, 'value', isNative ? `v._s(v.${value})` : `(v.${value})`) addHandler(el, event, code, null, true) } diff --git a/src/platforms/web/compiler/directives/text.js b/src/platforms/web/compiler/directives/text.js index 1af914f8ea0..1246c45c330 100644 --- a/src/platforms/web/compiler/directives/text.js +++ b/src/platforms/web/compiler/directives/text.js @@ -4,6 +4,7 @@ import { addProp } from 'compiler/helpers' export default function text (el: ASTElement, dir: ASTDirective) { if (dir.value) { - addProp(el, 'textContent', `_s(${dir.value})`) + // `v.` prefix is added in genHandlers + addProp(el, 'textContent', `_s(v.${dir.value})`) } }