mirror of https://github.com/vuejs/core.git
feat(runtime-core): enhance the warning when not explicitly declare the variable
This commit is contained in:
parent
848e27cf28
commit
d516036ee2
|
@ -526,7 +526,7 @@ export const PublicInstanceProxyHandlers: ProxyHandler<any> = {
|
||||||
`but is not defined on instance.`,
|
`but is not defined on instance.`,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
} else if (__DEV__ && !__TEST__ && !(key[0] === '$' || key[0] === '_')) {
|
} else if (__DEV__ && !__TEST__ && !isReservedPrefix(key[0])) {
|
||||||
warn(
|
warn(
|
||||||
`Property ${JSON.stringify(key)} was accessed during render ` +
|
`Property ${JSON.stringify(key)} was accessed during render ` +
|
||||||
`but is not defined on instance.`,
|
`but is not defined on instance.`,
|
||||||
|
|
|
@ -311,4 +311,27 @@ describe('compiler + runtime integration', () => {
|
||||||
app.mount(root)
|
app.mount(root)
|
||||||
expect(root.innerHTML).toBe('<div>60000000100000111</div>')
|
expect(root.innerHTML).toBe('<div>60000000100000111</div>')
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test('Warning when use undeclared variable in template', () => {
|
||||||
|
const app = createApp({
|
||||||
|
template: `
|
||||||
|
<div @click="handler">handler</div>
|
||||||
|
<div>dddd{{dddd}}</div>
|
||||||
|
<div>no warn: {{message}}</div>
|
||||||
|
`,
|
||||||
|
setup() {
|
||||||
|
return {
|
||||||
|
message: 'hello',
|
||||||
|
}
|
||||||
|
},
|
||||||
|
})
|
||||||
|
const root = document.createElement('div')
|
||||||
|
app.mount(root)
|
||||||
|
expect(
|
||||||
|
`[Vue warn]: Property "handler" was accessed during render but is not defined on instance.`,
|
||||||
|
).toHaveBeenWarned()
|
||||||
|
expect(
|
||||||
|
`[Vue warn]: Property "dddd" was accessed during render but is not defined on instance.`,
|
||||||
|
).toHaveBeenWarned()
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue