fix(runtime-core): should not warn unused attrs when accessed via setup context

close #625
This commit is contained in:
Evan You
2020-01-16 17:45:08 -05:00
parent c35fea3d60
commit 751d838fb9
2 changed files with 34 additions and 2 deletions

View File

@@ -28,7 +28,10 @@ import {
} from '@vue/shared'
import { SuspenseBoundary } from './components/Suspense'
import { CompilerOptions } from '@vue/compiler-core'
import { currentRenderingInstance } from './componentRenderUtils'
import {
currentRenderingInstance,
markAttrsAccessed
} from './componentRenderUtils'
export type Data = { [key: string]: unknown }
@@ -428,7 +431,12 @@ export const SetupProxySymbol = Symbol()
const SetupProxyHandlers: { [key: string]: ProxyHandler<any> } = {}
;['attrs', 'slots'].forEach((type: string) => {
SetupProxyHandlers[type] = {
get: (instance, key) => instance[type][key],
get: (instance, key) => {
if (__DEV__) {
markAttrsAccessed()
}
return instance[type][key]
},
has: (instance, key) => key === SetupProxySymbol || key in instance[type],
ownKeys: instance => Reflect.ownKeys(instance[type]),
// this is necessary for ownKeys to work properly