Skip to content

tweak: type checking and warn methods that conflict with internals #7318

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 1 commit into from
Closed
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
30 changes: 19 additions & 11 deletions src/core/instance/state.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,14 +134,21 @@ function initData (vm: Component) {
vm
)
}
if (props && hasOwn(props, key)) {
warn(
`The data property "${key}" is already declared as a prop. ` +
`Use prop default value instead.`,
vm
)
}
if (isReserved(key)) {
warn(
`Avoid defining data methods that start with _ or $.`,
vm
)
}
}
if (props && hasOwn(props, key)) {
process.env.NODE_ENV !== 'production' && warn(
`The data property "${key}" is already declared as a prop. ` +
`Use prop default value instead.`,
vm
)
} else if (!isReserved(key)) {
if (!isReserved(key)) {
proxy(vm, `_data`, key)
}
}
Expand Down Expand Up @@ -253,9 +260,9 @@ function initMethods (vm: Component, methods: Object) {
const props = vm.$options.props
for (const key in methods) {
if (process.env.NODE_ENV !== 'production') {
if (methods[key] == null) {
if (typeof methods[key] !== 'function') {
warn(
`Method "${key}" has an undefined value in the component definition. ` +
`Method "${key}" is not a function in the component definition. ` +
`Did you reference the function correctly?`,
vm
)
Expand All @@ -269,11 +276,12 @@ function initMethods (vm: Component, methods: Object) {
if ((key in vm) && isReserved(key)) {
warn(
`Method "${key}" conflicts with an existing Vue instance method. ` +
`Avoid defining component methods that start with _ or $.`
`Avoid defining component methods that start with _ or $.`,
vm
)
}
}
vm[key] = methods[key] == null ? noop : bind(methods[key], vm)
vm[key] = typeof methods[key] !== 'function' ? noop : bind(methods[key], vm)
}
}

Expand Down