Skip to content

Enable strict mode by removing with #4135

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/compiler/codegen/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) + '}'
}
Expand Down
20 changes: 12 additions & 8 deletions src/compiler/codegen/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand All @@ -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
Expand All @@ -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' : ''})`
}

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
}
2 changes: 1 addition & 1 deletion src/compiler/parser/text-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
3 changes: 2 additions & 1 deletion src/platforms/web/compiler/directives/html.js
Original file line number Diff line number Diff line change
Expand Up @@ -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})`)
}
}
2 changes: 1 addition & 1 deletion src/platforms/web/compiler/directives/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
3 changes: 2 additions & 1 deletion src/platforms/web/compiler/directives/text.js
Original file line number Diff line number Diff line change
Expand Up @@ -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})`)
}
}