Skip to content

Commit

Permalink
fix(runtime-core): warn reserved prefix for setup return properties a…
Browse files Browse the repository at this point in the history
…nd ensure consistent dev/prod behavior

close #2042
  • Loading branch information
yyx990803 committed Sep 3, 2020
1 parent 95c07d8 commit fa7ab0a
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions packages/runtime-core/src/componentPublicInstance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -299,12 +299,16 @@ export const PublicInstanceProxyHandlers: ProxyHandler<any> = {
// to infinite warning loop
key.indexOf('__v') !== 0)
) {
if (data !== EMPTY_OBJ && key[0] === '$' && hasOwn(data, key)) {
if (
data !== EMPTY_OBJ &&
(key[0] === '$' || key[0] === '_') &&
hasOwn(data, key)
) {
warn(
`Property ${JSON.stringify(
key
)} must be accessed via $data because it starts with a reserved ` +
`character and is not proxied on the render context.`
`character ("$" or "_") and is not proxied on the render context.`
)
} else {
warn(
Expand Down Expand Up @@ -474,6 +478,15 @@ export function exposeSetupStateOnRenderContext(
) {
const { ctx, setupState } = instance
Object.keys(toRaw(setupState)).forEach(key => {
if (key[0] === '$' || key[0] === '_') {
warn(
`setup() return property ${JSON.stringify(
key
)} should not start with "$" or "_" ` +
`which are reserved prefixes for Vue internals.`
)
return
}
Object.defineProperty(ctx, key, {
enumerable: true,
configurable: true,
Expand Down

0 comments on commit fa7ab0a

Please sign in to comment.