Skip to content

Commit 7368563

Browse files
committed
some updates
1 parent 4316032 commit 7368563

File tree

6 files changed

+129
-31
lines changed

6 files changed

+129
-31
lines changed

patches/@[email protected]

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
diff --git a/dist/runtime-core.d.ts b/dist/runtime-core.d.ts
2-
index 5d4c1fb2c6859f7982ea7bb55f65a5c613d91038..93ad7c6ac81064255901ac6319a31a6853ac491e 100644
2+
index 5d4c1fb2c6859f7982ea7bb55f65a5c613d91038..e26f82d85eb272844bcffd67cd05dd8e8666db95 100644
33
--- a/dist/runtime-core.d.ts
44
+++ b/dist/runtime-core.d.ts
55
@@ -1,7 +1,7 @@
@@ -64,6 +64,15 @@ index 5d4c1fb2c6859f7982ea7bb55f65a5c613d91038..93ad7c6ac81064255901ac6319a31a68
6464
export type Prop<T, D = T> = PropOptions<T, D> | PropType<T>;
6565
type DefaultFactory<T> = (props: Data) => T | null | undefined;
6666
interface PropOptions<T = any, D = T> {
67+
@@ -467,7 +483,7 @@ export type ExtractPublicPropTypes<O> = {
68+
} & {
69+
[K in keyof Pick<O, PublicOptionalKeys<O>>]?: InferPropType<O[K]>;
70+
};
71+
-export type ExtractDefaultPropTypes<O> = O extends object ? {
72+
+export type ExtractDefaultPropTypes<O> = [O] extends [object] ? {
73+
[K in keyof Pick<O, DefaultKeys<O>>]: InferPropType<O[K]>;
74+
} : {};
75+
6776
@@ -514,6 +530,15 @@ export type DirectiveArguments = Array<[Directive | undefined] | [Directive | un
6877
*/
6978
export declare function withDirectives<T extends VNode>(vnode: T, directives: DirectiveArguments): T;
@@ -124,6 +133,15 @@ index 5d4c1fb2c6859f7982ea7bb55f65a5c613d91038..93ad7c6ac81064255901ac6319a31a68
124133
__isTeleport: boolean;
125134
process(n1: TeleportVNode | null, n2: TeleportVNode, container: RendererElement, anchor: RendererNode | null, parentComponent: ComponentInternalInstance | null, parentSuspense: SuspenseBoundary | null, isSVG: boolean, slotScopeIds: string[] | null, optimized: boolean, internals: RendererInternals): void;
126135
remove(vnode: VNode, parentComponent: ComponentInternalInstance | null, parentSuspense: SuspenseBoundary | null, optimized: boolean, { um: unmount, o: { remove: hostRemove } }: RendererInternals, doRemove: boolean): void;
136+
@@ -822,7 +848,7 @@ declare const TeleportImpl: {
137+
};
138+
declare const enum TeleportMoveTypes {
139+
TARGET_CHANGE = 0,
140+
- TOGGLE = 1,
141+
+ TOGGLE = 1,// enable / disable
142+
REORDER = 2
143+
}
144+
declare function moveTeleport(vnode: VNode, container: RendererElement, parentAnchor: RendererNode | null, { o: { insert }, m: move }: RendererInternals, moveType?: TeleportMoveTypes): void;
127145
@@ -883,7 +909,7 @@ export type VNodeProps = {
128146
onVnodeBeforeUnmount?: VNodeMountHook | VNodeMountHook[];
129147
onVnodeUnmounted?: VNodeMountHook | VNodeMountHook[];
@@ -225,7 +243,7 @@ index 5d4c1fb2c6859f7982ea7bb55f65a5c613d91038..93ad7c6ac81064255901ac6319a31a68
225243

226244
export declare const ssrContextKey: unique symbol;
227245
export declare const useSSRContext: <T = Record<string, any>>() => T | undefined;
228-
@@ -1437,6 +1476,62 @@ interface DevtoolsHook {
246+
@@ -1437,6 +1476,70 @@ interface DevtoolsHook {
229247
export declare let devtools: DevtoolsHook;
230248
export declare function setDevtoolsHook(hook: DevtoolsHook, target: any): void;
231249

@@ -268,27 +286,35 @@ index 5d4c1fb2c6859f7982ea7bb55f65a5c613d91038..93ad7c6ac81064255901ac6319a31a68
268286
+type ResolveMixin<T> = [T] extends [
269287
+ Readonly<ComponentOptionsBase<any, any, any, any, any, infer M, infer E, any, any, any, any, any, any>>
270288
+] ? IntersectionMixin<M> & IntersectionMixin<E> : {};
271-
+export type ComponentPropsWithDefaultOptional<T> = ExtractDefaultPropTypes<ExtractComponentProp<T>> extends infer Defaults ? Partial<Defaults> & Omit<ComponentProps<T>, keyof Defaults> : {};
289+
+export type ComponentPropsWithDefaultOptional<T> = ((T extends {
290+
+ props: infer P;
291+
+} ? [P] extends [Array<infer PA>] ? [PA] extends [string] ? {
292+
+ [key in PA]?: any;
293+
+} : never : P : T) extends infer Props ? ExtractDefaultPropTypes<T> extends infer Defaults ? Partial<Defaults> & Omit<ExtractPropTypes<Props>, keyof Defaults> : {} : {}) & (T extends {
294+
+ props: any;
295+
+} ? ResolveMixinProps<Omit<T, 'props'>> : ResolveMixinProps<T>);
272296
+type ResolveMixinProps<T> = UnwrapMixinsType<ResolveMixin<T>, 'P'>;
273297
+export type ComponentProps<T, excludeEmits extends boolean = false> = (excludeEmits extends false ? ExtractComponentEmits<T> extends infer E ? E extends EmitsOptions ? EmitsToProps<E> : unknown : unknown : {}) & (T extends {
274298
+ $props: infer P;
275299
+} ? P : (ExtractComponentProp<T> extends infer P ? P extends Readonly<Array<infer V>> ? [V] extends [string] ? Readonly<{
276300
+ [key in V]?: any;
277301
+}> : {} : P extends ComponentPropsOptions ? ExtractPropTypes<P> : P : {}) & (T extends {
278302
+ props: any;
279-
+} ? ResolveMixinProps<Omit<T, 'props'>> : {}));
303+
+} ? ResolveMixinProps<Omit<T, 'props'>> : ResolveMixinProps<T>));
280304
+export type ComponentSlots<T> = ExtractComponentSlots<T> extends infer S ? {
281305
+ [K in keyof S]: S[K] extends Slot<infer V> ? (arg: V) => VNode : never;
282306
+} : {};
283307
+export type ComponentEmits<T> = ExtractComponentEmits<T> extends infer E ? {} extends E ? () => void : EmitFn<E> : () => void;
284308
+export type ComponentInstance<T> = T extends {
285309
+ new (): ComponentPublicInstance;
286-
+} ? InstanceType<T> : T extends FunctionalComponent<infer Props, infer Emits> ? ComponentPublicInstance<Props, {}, {}, {}, {}, Emits> : T extends ComponentPublicInstanceConstructor ? InstanceType<T> : T extends Component<infer Props, infer RawBindings, infer D, infer C, infer M> ? ComponentPublicInstance<unknown extends Props ? {} : Props, unknown extends RawBindings ? {} : RawBindings, unknown extends D ? {} : D, C, M> : never;
310+
+} ? InstanceType<T> : T extends FunctionalComponent<infer Props, infer Emits> ? ComponentPublicInstance<Props, {}, {}, {}, {}, Emits> : T extends ComponentPublicInstanceConstructor ? InstanceType<T> : T extends ComponentDefineOptions<infer Props, infer RawBindings, infer D, infer C, infer M, infer Mixin, infer Extends, infer E, infer EE, infer I, infer II, infer S, infer Options> ? InstanceType<ReturnType<typeof defineComponent<Options extends {
311+
+ props: infer P;
312+
+} ? P extends Array<infer PA> ? PA : P : Props, RawBindings, D, C, M, Mixin, Extends, E, EE, I, II, S, Options>>> : T extends Component<infer Props, infer RawBindings, infer D, infer C, infer M> ? ComponentPublicInstance<unknown extends Props ? {} : Props, unknown extends RawBindings ? {} : RawBindings, unknown extends D ? {} : D, C, M> : never;
287313
+
288314
type HMRComponent = ComponentOptions | ClassComponent;
289315
export interface HMRRuntime {
290316
createRecord: typeof createRecord;
291-
@@ -1568,12 +1663,12 @@ interface LegacyPublicProperties {
317+
@@ -1568,12 +1671,12 @@ interface LegacyPublicProperties {
292318
*/
293319
export type CompatVue = Pick<App, 'version' | 'component' | 'directive'> & {
294320
configureCompat: typeof configureCompat;
@@ -303,7 +329,7 @@ index 5d4c1fb2c6859f7982ea7bb55f65a5c613d91038..93ad7c6ac81064255901ac6319a31a68
303329
component(name: string): Component | undefined;
304330
component(name: string, component: Component): CompatVue;
305331
directive(name: string): Directive | undefined;
306-
@@ -1582,7 +1677,7 @@ export type CompatVue = Pick<App, 'version' | 'component' | 'directive'> & {
332+
@@ -1582,7 +1685,7 @@ export type CompatVue = Pick<App, 'version' | 'component' | 'directive'> & {
307333
/**
308334
* @deprecated Vue 3 no longer supports extending constructors.
309335
*/

pnpm-lock.yaml

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/mount.ts

Lines changed: 74 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,14 @@ import {
22
ComponentPublicInstance,
33
DefineComponent,
44
VNode,
5-
ComponentInstance
5+
ComponentInstance,
6+
ComputedOptions,
7+
MethodOptions,
8+
ComponentOptionsMixin,
9+
EmitsOptions,
10+
ComponentInjectOptions,
11+
SlotsType,
12+
ComponentDefineOptions
613
} from 'vue'
714
import type { ComponentSlots } from 'vue-component-type-helpers'
815
import { createInstance } from './createInstance'
@@ -35,6 +42,71 @@ export type ComponentMountingOptions<T, P> = Omit<
3542
}
3643
} & Record<string, unknown>
3744

45+
// export function mount<
46+
// Props = never,
47+
// RawBindings = {},
48+
// D = {},
49+
// C extends ComputedOptions = {},
50+
// M extends MethodOptions = {},
51+
// Mixin extends ComponentOptionsMixin = ComponentOptionsMixin,
52+
// Extends extends ComponentOptionsMixin = ComponentOptionsMixin,
53+
// E extends EmitsOptions = {},
54+
// EE extends string = string,
55+
// I extends ComponentInjectOptions = {},
56+
// II extends string = string,
57+
// S extends SlotsType = {},
58+
// Options = {}
59+
// >(
60+
// originalComponent: ComponentDefineOptions<
61+
// Props,
62+
// RawBindings,
63+
// D,
64+
// C,
65+
// M,
66+
// Mixin,
67+
// Extends,
68+
// E,
69+
// EE,
70+
// I,
71+
// II,
72+
// S,
73+
// Options
74+
// >,
75+
// options?: ComponentMountingOptions<
76+
// ComponentDefineOptions<
77+
// Props,
78+
// RawBindings,
79+
// D,
80+
// C,
81+
// M,
82+
// Mixin,
83+
// Extends,
84+
// E,
85+
// EE,
86+
// I,
87+
// II,
88+
// S,
89+
// Options
90+
// >,
91+
// ComponentPropsWithDefaultOptional<
92+
// ComponentDefineOptions<
93+
// Props,
94+
// RawBindings,
95+
// D,
96+
// C,
97+
// M,
98+
// Mixin,
99+
// Extends,
100+
// E,
101+
// EE,
102+
// I,
103+
// II,
104+
// S,
105+
// Options
106+
// >
107+
// >
108+
// >
109+
// ): { props: Props }
38110
// defineComponent
39111
export function mount<
40112
T extends DefineComponent<
@@ -49,7 +121,7 @@ export function mount<
49121
any,
50122
any
51123
>,
52-
PropsOrOptions
124+
PropsOrOptions extends object
53125
>(
54126
originalComponent: T,
55127
options?: ComponentMountingOptions<T, ComponentPropsWithDefaultOptional<T>>

src/vnodeTransformers/stubComponentsTransformer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import { registerStub } from '../stubs'
3232

3333
export type CustomCreateStub = (params: {
3434
name: string
35-
component: ConcreteComponent
35+
component: Component
3636
registerStub: (config: { source: Component; stub: Component }) => void
3737
}) => ConcreteComponent
3838

tests/setData.spec.ts

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -189,20 +189,18 @@ describe('setData', () => {
189189
})
190190

191191
it('should keep Date object on setData', async () => {
192-
const wrapper = mount(
193-
defineComponent({
194-
template: '<div/>',
195-
props: { modelValue: Date },
196-
data() {
197-
return { value: this.modelValue }
198-
}
199-
}),
200-
{
201-
props: {
202-
modelValue: new Date('2022-08-10T12:15:54Z')
203-
}
192+
const comp = defineComponent({
193+
template: '<div/>',
194+
props: { modelValue: Date },
195+
data() {
196+
return { value: this.modelValue }
204197
}
205-
)
198+
})
199+
const wrapper = mount(comp, {
200+
props: {
201+
modelValue: new Date('2022-08-10T12:15:54Z')
202+
}
203+
})
206204

207205
expect(wrapper.vm.value).toBeInstanceOf(Date)
208206
expect(wrapper.vm.value!.toISOString()).toBe('2022-08-10T12:15:54.000Z')

tests/setProps.spec.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ describe('setProps', () => {
2323

2424
it('updates a function prop', async () => {
2525
const Foo = {
26-
props: ['obj'],
26+
props: ['obj'] as ['obj'],
2727
template: `
2828
<div>
2929
<div v-if="obj.foo()">foo</div>
@@ -37,15 +37,15 @@ describe('setProps', () => {
3737
}
3838
}
3939
})
40-
expect(wrapper.html()).toContain('foo')
4140

41+
expect(wrapper.html()).toContain('foo')
4242
await wrapper.setProps({ obj: { foo: () => false } })
4343
expect(wrapper.html()).not.toContain('foo')
4444
})
4545

4646
it('sets component props, and updates DOM when props were not initially passed', async () => {
4747
const Foo = {
48-
props: ['foo'],
48+
props: ['foo'] as ['foo'],
4949
template: `
5050
<div>{{ foo }}</div>`
5151
}
@@ -126,11 +126,11 @@ describe('setProps', () => {
126126
it('allows using only on mounted component', async () => {
127127
const Foo = {
128128
name: 'Foo',
129-
props: ['foo'],
129+
props: ['foo'] as ['foo'],
130130
template: '<div>{{ foo }}</div>'
131131
}
132132
const Baz = {
133-
props: ['baz'],
133+
props: ['baz'] as ['baz'],
134134
template: '<div><Foo :foo="baz"/></div>',
135135
components: { Foo }
136136
}
@@ -141,6 +141,8 @@ describe('setProps', () => {
141141
}
142142
})
143143
const FooResult = wrapper.findComponent({ name: 'Foo' })
144+
145+
// @ts-expect-error not valid prop
144146
expect(() => FooResult.setProps({ baz: 'bin' })).toThrowError(
145147
'You can only use setProps on your mounted component'
146148
)

0 commit comments

Comments
 (0)