Skip to content

Commit fa61c00

Browse files
committed
fix proxy missing property detection when render function does not use with
1 parent 1a7b910 commit fa61c00

File tree

2 files changed

+38
-6
lines changed

2 files changed

+38
-6
lines changed

src/core/instance/proxy.js

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,15 @@ if (process.env.NODE_ENV !== 'production') {
1212
'require' // for Webpack/Browserify
1313
)
1414

15+
const warnNonPresent = (target, key) => {
16+
warn(
17+
`Property or method "${key}" is not defined on the instance but ` +
18+
`referenced during render. Make sure to declare reactive data ` +
19+
`properties in the data option.`,
20+
target
21+
)
22+
}
23+
1524
hasProxy =
1625
typeof Proxy !== 'undefined' &&
1726
Proxy.toString().match(/native code/)
@@ -21,14 +30,16 @@ if (process.env.NODE_ENV !== 'production') {
2130
const has = key in target
2231
const isAllowed = allowedGlobals(key) || key.charAt(0) === '_'
2332
if (!has && !isAllowed) {
24-
warn(
25-
`Property or method "${key}" is not defined on the instance but ` +
26-
`referenced during render. Make sure to declare reactive data ` +
27-
`properties in the data option.`,
28-
target
29-
)
33+
warnNonPresent(target, key)
3034
}
3135
return has || !isAllowed
36+
},
37+
38+
get (target, key) {
39+
if (typeof key === 'string' && !(key in target)) {
40+
warnNonPresent(target, key)
41+
}
42+
return target[key]
3243
}
3344
}
3445

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import Vue from 'vue'
2+
3+
if (typeof Proxy !== 'undefined') {
4+
describe('render proxy', () => {
5+
it('should warn missing property in render fns with `with`', () => {
6+
new Vue({
7+
template: `<div>{{ a }}</div>`
8+
}).$mount()
9+
expect(`Property or method "a" is not defined`).toHaveBeenWarned()
10+
})
11+
12+
it('should warn missing property in render fns without `with`', () => {
13+
new Vue({
14+
render (h) {
15+
return h('div', [this.a])
16+
}
17+
}).$mount()
18+
expect(`Property or method "a" is not defined`).toHaveBeenWarned()
19+
})
20+
})
21+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy