|
@@ -13,6 +13,7 @@ import { normalizeEmitsOptions } from './componentEmits'
|
|
|
import { renderEffect } from './renderEffect'
|
|
import { renderEffect } from './renderEffect'
|
|
|
|
|
|
|
|
export type RawProps = Record<string, () => unknown> & {
|
|
export type RawProps = Record<string, () => unknown> & {
|
|
|
|
|
+ // generated by compiler for :[key]="x" or v-bind="x"
|
|
|
$?: DynamicPropsSource[]
|
|
$?: DynamicPropsSource[]
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -27,12 +28,12 @@ export function resolveSource(
|
|
|
return isFunction(source) ? source() : source
|
|
return isFunction(source) ? source() : source
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-const passThrough = (val: any) => val
|
|
|
|
|
-
|
|
|
|
|
export function getPropsProxyHandlers(
|
|
export function getPropsProxyHandlers(
|
|
|
comp: VaporComponent,
|
|
comp: VaporComponent,
|
|
|
- instance: VaporComponentInstance,
|
|
|
|
|
-): [ProxyHandler<RawProps> | null, ProxyHandler<RawProps>] {
|
|
|
|
|
|
|
+): [
|
|
|
|
|
+ ProxyHandler<VaporComponentInstance> | null,
|
|
|
|
|
+ ProxyHandler<VaporComponentInstance>,
|
|
|
|
|
+] {
|
|
|
if (comp.__propsHandlers) {
|
|
if (comp.__propsHandlers) {
|
|
|
return comp.__propsHandlers
|
|
return comp.__propsHandlers
|
|
|
}
|
|
}
|
|
@@ -44,23 +45,12 @@ export function getPropsProxyHandlers(
|
|
|
key !== '$' && !isProp(key) && !isEmitListener(emitsOptions, key)
|
|
key !== '$' && !isProp(key) && !isEmitListener(emitsOptions, key)
|
|
|
: YES
|
|
: YES
|
|
|
|
|
|
|
|
- const castProp = propsOptions
|
|
|
|
|
- ? (value: any, key: string, isAbsent = false) =>
|
|
|
|
|
- resolvePropValue(
|
|
|
|
|
- propsOptions,
|
|
|
|
|
- key as string,
|
|
|
|
|
- value,
|
|
|
|
|
- instance,
|
|
|
|
|
- resolveDefault,
|
|
|
|
|
- isAbsent,
|
|
|
|
|
- )
|
|
|
|
|
- : passThrough
|
|
|
|
|
-
|
|
|
|
|
- const getProp = (target: RawProps, key: string) => {
|
|
|
|
|
|
|
+ const getProp = (instance: VaporComponentInstance, key: string) => {
|
|
|
if (key === '$' || !isProp(key)) {
|
|
if (key === '$' || !isProp(key)) {
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
- const dynamicSources = target.$
|
|
|
|
|
|
|
+ const rawProps = instance.rawProps
|
|
|
|
|
+ const dynamicSources = rawProps.$
|
|
|
if (dynamicSources) {
|
|
if (dynamicSources) {
|
|
|
let i = dynamicSources.length
|
|
let i = dynamicSources.length
|
|
|
let source, isDynamic, rawKey
|
|
let source, isDynamic, rawKey
|
|
@@ -70,17 +60,35 @@ export function getPropsProxyHandlers(
|
|
|
source = isDynamic ? (source as Function)() : source
|
|
source = isDynamic ? (source as Function)() : source
|
|
|
for (rawKey in source) {
|
|
for (rawKey in source) {
|
|
|
if (camelize(rawKey) === key) {
|
|
if (camelize(rawKey) === key) {
|
|
|
- return castProp(isDynamic ? source[rawKey] : source[rawKey](), key)
|
|
|
|
|
|
|
+ return resolvePropValue(
|
|
|
|
|
+ propsOptions!,
|
|
|
|
|
+ key,
|
|
|
|
|
+ isDynamic ? source[rawKey] : source[rawKey](),
|
|
|
|
|
+ instance,
|
|
|
|
|
+ resolveDefault,
|
|
|
|
|
+ )
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- for (const rawKey in target) {
|
|
|
|
|
|
|
+ for (const rawKey in rawProps) {
|
|
|
if (camelize(rawKey) === key) {
|
|
if (camelize(rawKey) === key) {
|
|
|
- return castProp(target[rawKey](), key)
|
|
|
|
|
|
|
+ return resolvePropValue(
|
|
|
|
|
+ propsOptions!,
|
|
|
|
|
+ key,
|
|
|
|
|
+ rawProps[rawKey](),
|
|
|
|
|
+ instance,
|
|
|
|
|
+ resolveDefault,
|
|
|
|
|
+ )
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- return castProp(undefined, key, true)
|
|
|
|
|
|
|
+ return resolvePropValue(
|
|
|
|
|
+ propsOptions!,
|
|
|
|
|
+ key,
|
|
|
|
|
+ undefined,
|
|
|
|
|
+ instance,
|
|
|
|
|
+ resolveDefault,
|
|
|
|
|
+ )
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
const propsHandlers = propsOptions
|
|
const propsHandlers = propsOptions
|
|
@@ -99,7 +107,7 @@ export function getPropsProxyHandlers(
|
|
|
ownKeys: () => Object.keys(propsOptions),
|
|
ownKeys: () => Object.keys(propsOptions),
|
|
|
set: NO,
|
|
set: NO,
|
|
|
deleteProperty: NO,
|
|
deleteProperty: NO,
|
|
|
- } satisfies ProxyHandler<RawProps>)
|
|
|
|
|
|
|
+ } satisfies ProxyHandler<VaporComponentInstance>)
|
|
|
: null
|
|
: null
|
|
|
|
|
|
|
|
const getAttr = (target: RawProps, key: string) => {
|
|
const getAttr = (target: RawProps, key: string) => {
|
|
@@ -142,25 +150,24 @@ export function getPropsProxyHandlers(
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
const attrsHandlers = {
|
|
const attrsHandlers = {
|
|
|
- get: (target, key: string) => {
|
|
|
|
|
- return getAttr(target, key)
|
|
|
|
|
- },
|
|
|
|
|
- has: hasAttr,
|
|
|
|
|
|
|
+ get: (target, key: string) => getAttr(target.rawProps, key),
|
|
|
|
|
+ has: (target, key: string) => hasAttr(target.rawProps, key),
|
|
|
getOwnPropertyDescriptor(target, key: string) {
|
|
getOwnPropertyDescriptor(target, key: string) {
|
|
|
- if (hasAttr(target, key)) {
|
|
|
|
|
|
|
+ if (hasAttr(target.rawProps, key)) {
|
|
|
return {
|
|
return {
|
|
|
configurable: true,
|
|
configurable: true,
|
|
|
enumerable: true,
|
|
enumerable: true,
|
|
|
- get: () => getAttr(target, key),
|
|
|
|
|
|
|
+ get: () => getAttr(target.rawProps, key),
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
},
|
|
},
|
|
|
ownKeys(target) {
|
|
ownKeys(target) {
|
|
|
|
|
+ const rawProps = target.rawProps
|
|
|
const keys: string[] = []
|
|
const keys: string[] = []
|
|
|
- for (const key in target) {
|
|
|
|
|
|
|
+ for (const key in rawProps) {
|
|
|
if (isAttr(key)) keys.push(key)
|
|
if (isAttr(key)) keys.push(key)
|
|
|
}
|
|
}
|
|
|
- const dynamicSources = target.$
|
|
|
|
|
|
|
+ const dynamicSources = rawProps.$
|
|
|
if (dynamicSources) {
|
|
if (dynamicSources) {
|
|
|
let i = dynamicSources.length
|
|
let i = dynamicSources.length
|
|
|
let source
|
|
let source
|
|
@@ -175,7 +182,7 @@ export function getPropsProxyHandlers(
|
|
|
},
|
|
},
|
|
|
set: NO,
|
|
set: NO,
|
|
|
deleteProperty: NO,
|
|
deleteProperty: NO,
|
|
|
- } satisfies ProxyHandler<RawProps>
|
|
|
|
|
|
|
+ } satisfies ProxyHandler<VaporComponentInstance>
|
|
|
|
|
|
|
|
return (comp.__propsHandlers = [propsHandlers, attrsHandlers])
|
|
return (comp.__propsHandlers = [propsHandlers, attrsHandlers])
|
|
|
}
|
|
}
|