Skip to content

perf(language-core): drop internal component #5532

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

Draft
wants to merge 35 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
7cbcb3f
refactor: use variable `__VLS_export` to receive component and export…
KazariEX Jul 18, 2025
72f9dcc
perf: drop internal component
KazariEX Jul 18, 2025
c0b0b77
test: update snapshot
KazariEX Jul 18, 2025
2c87740
refactor: extract `__VLS_ProxyRefs`
KazariEX Jul 18, 2025
0a3d327
refactor: remove `__VLS_makeOptional`
KazariEX Jul 18, 2025
18a2ddb
fix: generate bindings after template variable collection
KazariEX Jul 18, 2025
fb1f1a3
feat: emits to props and drop internal component for generic
KazariEX Jul 19, 2025
7a9c120
refactor: simplify conditional logic
KazariEX Jul 19, 2025
e992097
fix: `withDefaults` and bypass boolean casting
KazariEX Jul 20, 2025
81854db
refactor: simplify
KazariEX Jul 20, 2025
850c2c6
fix: intersect `__VLS_PublicProps` on demand
KazariEX Jul 20, 2025
ee3eda0
refactor: `Code` to `string` for `.join(' & ')`
KazariEX Jul 20, 2025
d18dd97
fix: runtime props for generic component
KazariEX Jul 22, 2025
011e562
refactor: add `Partial` to inherited attrs in advance
KazariEX Jul 22, 2025
645dcb7
refactor: generate setup function as needed
KazariEX Jul 22, 2025
49b04c1
refactor: reduce usage of `generateIntersectMerge`
KazariEX Jul 22, 2025
4941987
refactor: only generate `ShallowUnwrapRef` for explicitly defined exp…
KazariEX Jul 22, 2025
e1bbf75
refactor: remove outdated fix for #1187
KazariEX Jul 22, 2025
cb72c6f
fix: only generate jsx slot props into `__VLS_PublicProps`
KazariEX Jul 22, 2025
4980a3f
refactor: split `generateModels` and `generatePublicProps`
KazariEX Jul 26, 2025
3843fbd
refactor: generate `__VLS_dollars` on demand
KazariEX Jul 26, 2025
64a0c22
Merge remote-tracking branch 'upstream' into perf/drop-internal-compo…
KazariEX Jul 26, 2025
127e847
refactor: simplify bindings iteration
KazariEX Jul 26, 2025
90f84f6
fix: revert access external variables detection
KazariEX Jul 26, 2025
8c152d4
refactor: remove unnecessary component name conditionals
KazariEX Jul 26, 2025
db1e456
refactor: remove `__VLS_definePublicProps`
KazariEX Jul 26, 2025
8e632ef
fix: jsdoc for export default
KazariEX Jul 27, 2025
66e6fbd
Merge remote-tracking branch 'upstream' into perf/drop-internal-compo…
KazariEX Jul 27, 2025
f987f39
test: update snapshot
KazariEX Jul 27, 2025
d4fc864
refactor: simplify local types generation
KazariEX Jul 27, 2025
a74a459
fix: compatible with class components
KazariEX Jul 28, 2025
97d9889
refactor: simplify template usage variables collection
KazariEX Jul 28, 2025
a892968
refactor: remove unnecessary bound mapping
KazariEX Jul 28, 2025
7da37e2
fix: compatible with script src
KazariEX Aug 1, 2025
990d5ec
Merge remote-tracking branch 'upstream' into perf/drop-internal-compo…
KazariEX Aug 2, 2025
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
25 changes: 17 additions & 8 deletions packages/language-core/lib/codegen/globalTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@ export function generateGlobalTypes(options: VueCompilerOptions) {
type __VLS_PickNotAny<A, B> = __VLS_IsAny<A> extends true ? B : A;
type __VLS_SpreadMerge<A, B> = Omit<A, keyof B> & B;
type __VLS_WithComponent<N0 extends string, LocalComponents, Self, N1 extends string, N2 extends string, N3 extends string> =
N1 extends keyof LocalComponents ? N1 extends N0 ? Pick<LocalComponents, N0 extends keyof LocalComponents ? N0 : never> : { [K in N0]: LocalComponents[N1] } :
N2 extends keyof LocalComponents ? N2 extends N0 ? Pick<LocalComponents, N0 extends keyof LocalComponents ? N0 : never> : { [K in N0]: LocalComponents[N2] } :
N3 extends keyof LocalComponents ? N3 extends N0 ? Pick<LocalComponents, N0 extends keyof LocalComponents ? N0 : never> : { [K in N0]: LocalComponents[N3] } :
N1 extends keyof LocalComponents ? { [K in N0]: LocalComponents[N1] } :
N2 extends keyof LocalComponents ? { [K in N0]: LocalComponents[N2] } :
N3 extends keyof LocalComponents ? { [K in N0]: LocalComponents[N3] } :
Self extends object ? { [K in N0]: Self } :
N1 extends keyof __VLS_GlobalComponents ? N1 extends N0 ? Pick<__VLS_GlobalComponents, N0 extends keyof __VLS_GlobalComponents ? N0 : never> : { [K in N0]: __VLS_GlobalComponents[N1] } :
N2 extends keyof __VLS_GlobalComponents ? N2 extends N0 ? Pick<__VLS_GlobalComponents, N0 extends keyof __VLS_GlobalComponents ? N0 : never> : { [K in N0]: __VLS_GlobalComponents[N2] } :
N3 extends keyof __VLS_GlobalComponents ? N3 extends N0 ? Pick<__VLS_GlobalComponents, N0 extends keyof __VLS_GlobalComponents ? N0 : never> : { [K in N0]: __VLS_GlobalComponents[N3] } :
N1 extends keyof __VLS_GlobalComponents ? { [K in N0]: __VLS_GlobalComponents[N1] } :
N2 extends keyof __VLS_GlobalComponents ? { [K in N0]: __VLS_GlobalComponents[N2] } :
N3 extends keyof __VLS_GlobalComponents ? { [K in N0]: __VLS_GlobalComponents[N3] } :
{};
type __VLS_FunctionalComponentCtx<T, K> = __VLS_PickNotAny<'__ctx' extends keyof __VLS_PickNotAny<K, {}>
? K extends { __ctx?: infer Ctx } ? NonNullable<Ctx> : never : any
Expand Down Expand Up @@ -118,6 +118,10 @@ export function generateGlobalTypes(options: VueCompilerOptions) {
}
>
>;
type __VLS_EmitsToProps<T> = __VLS_PrettifyGlobal<{
[K in string & keyof T as \`on\${Capitalize<K>}\`]?:
(...args: T[K] extends (...args: infer P) => any ? P : T[K] extends null ? any[] : never) => any;
}>;
type __VLS_ResolveEmits<
Comp,
Emits,
Expand All @@ -129,10 +133,16 @@ export function generateGlobalTypes(options: VueCompilerOptions) {
NormalizedEmits = __VLS_NormalizeEmits<Emits> extends infer E ? string extends keyof E ? {} : E : never,
> = __VLS_SpreadMerge<NormalizedEmits, TypeEmits>;
type __VLS_ResolveDirectives<T> = {
[K in Exclude<keyof T, keyof __VLS_GlobalDirectives> & string as \`v\${Capitalize<K>}\`]: T[K];
[K in keyof T & string as \`v\${Capitalize<K>}\`]: T[K];
};
type __VLS_PrettifyGlobal<T> = { [K in keyof T as K]: T[K]; } & {};
type __VLS_WithDefaultsGlobal<P, D> = {
[K in keyof P as K extends keyof D ? K : never]-?: P[K];
} & {
[K in keyof P as K extends keyof D ? never : K]: P[K];
};
type __VLS_UseTemplateRef<T> = Readonly<import('${lib}').ShallowRef<T | null>>;
type __VLS_ProxyRefs<T> = import('${lib}').ShallowUnwrapRef<T>;

function __VLS_getVForSourceType<T extends number | string | any[] | Iterable<any>>(source: T): [
item: T extends number ? number
Expand All @@ -154,7 +164,6 @@ export function generateGlobalTypes(options: VueCompilerOptions) {
: T extends (...args: any) => any
? T
: (arg1: unknown, arg2: unknown, arg3: unknown, arg4: unknown) => void;
function __VLS_makeOptional<T>(t: T): { [K in keyof T]?: T[K] };
function __VLS_asFunctionalComponent<T, K = T extends new (...args: any) => any ? InstanceType<T> : unknown>(t: T, instance?: K):
T extends new (...args: any) => any ? __VLS_FunctionalComponent<K>
: T extends () => any ? (props: {}, ctx?: any) => ReturnType<T>${
Expand Down
46 changes: 10 additions & 36 deletions packages/language-core/lib/codegen/localTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,11 @@ import { endOfLine } from './utils';
export function getLocalTypesGenerator(vueCompilerOptions: VueCompilerOptions) {
const used = new Set<string>();

const OmitKeepDiscriminatedUnion = defineHelper(
`__VLS_OmitKeepDiscriminatedUnion`,
const WithDefaultsLocal = defineHelper(
`__VLS_WithDefaultsLocal`,
() =>
`
type __VLS_OmitKeepDiscriminatedUnion<T, K extends keyof any> = T extends any
? Pick<T, Exclude<keyof T, K>>
: never;
`.trimStart(),
);
const WithDefaults = defineHelper(
`__VLS_WithDefaults`,
() =>
`
type __VLS_WithDefaults<P, D> = {
type __VLS_WithDefaultsLocal<P, D> = {
[K in keyof Pick<P, keyof P>]: K extends keyof D
? ${PrettifyLocal.name}<P[K] & { default: D[K] }>
: P[K]
Expand All @@ -36,7 +27,6 @@ type __VLS_WithDefaults<P, D> = {
type __VLS_WithSlots<T, S> = T & {
new(): {
${getSlotsPropertyName(vueCompilerOptions.target)}: S;
${vueCompilerOptions.jsxSlots ? `$props: ${PropsChildren.name}<S>;` : ''}
}
};
`.trimStart(),
Expand Down Expand Up @@ -78,8 +68,7 @@ type __VLS_TypePropsToOption<T> = {
);
const helpers = {
[PrettifyLocal.name]: PrettifyLocal,
[OmitKeepDiscriminatedUnion.name]: OmitKeepDiscriminatedUnion,
[WithDefaults.name]: WithDefaults,
[WithDefaultsLocal.name]: WithDefaultsLocal,
[WithSlots.name]: WithSlots,
[PropsChildren.name]: PropsChildren,
[TypePropsToOption.name]: TypePropsToOption,
Expand All @@ -89,17 +78,11 @@ type __VLS_TypePropsToOption<T> = {

return {
generate,
getUsedNames() {
return used;
},
get PrettifyLocal() {
return PrettifyLocal.name;
},
get OmitKeepDiscriminatedUnion() {
return OmitKeepDiscriminatedUnion.name;
},
get WithDefaults() {
return WithDefaults.name;
get WithDefaultsLocal() {
return WithDefaultsLocal.name;
},
get WithSlots() {
return WithSlots.name;
Expand All @@ -115,20 +98,11 @@ type __VLS_TypePropsToOption<T> = {
},
};

function* generate(names: string[]) {
const generated = new Set<string>();
while (names.length) {
used.clear();
for (const name of names) {
if (generated.has(name)) {
continue;
}
const helper = helpers[name as keyof typeof helpers];
yield helper.generate();
generated.add(name);
}
names = [...used].filter(name => !generated.has(name));
function* generate() {
for (const name of used) {
yield helpers[name].generate();
}
used.clear();
}

function defineHelper(name: string, generate: () => string) {
Expand Down
40 changes: 17 additions & 23 deletions packages/language-core/lib/codegen/script/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,18 @@ export function* generateComponent(
yield `(await import('${options.vueCompilerOptions.lib}')).defineComponent({${newLine}`;
}

const returns: Code[] = [];
const returns: string[] = [];
if (ctx.bypassDefineComponent) {
returns.push(...generateComponentSetupReturns(scriptSetupRanges));
// fill $props
if (scriptSetupRanges.defineProps) {
const name = scriptSetupRanges.defineProps.name ?? `__VLS_props`;
// NOTE: defineProps is inaccurate for $props
returns.push(name, `{} as { $props: Partial<typeof ${name}> }`);
}
// fill $emit
if (scriptSetupRanges.defineEmits) {
returns.push(`{} as { $emit: typeof ${scriptSetupRanges.defineEmits.name ?? `__VLS_emit`} }`);
}
}
if (scriptSetupRanges.defineExpose) {
returns.push(`__VLS_exposed`);
Expand All @@ -45,7 +54,7 @@ export function* generateComponent(
if (!ctx.bypassDefineComponent) {
const emitOptionCodes = [...generateEmitsOption(options, scriptSetupRanges)];
yield* emitOptionCodes;
yield* generatePropsOption(options, ctx, scriptSetup, scriptSetupRanges, !!emitOptionCodes.length, true);
yield* generatePropsOption(options, ctx, scriptSetup, scriptSetupRanges, !!emitOptionCodes.length);
}
if (
options.vueCompilerOptions.target >= 3.5
Expand All @@ -68,21 +77,7 @@ export function* generateComponent(
yield `})`;
}

export function* generateComponentSetupReturns(scriptSetupRanges: ScriptSetupRanges): Generator<Code> {
// fill $props
if (scriptSetupRanges.defineProps) {
const name = scriptSetupRanges.defineProps.name ?? `__VLS_props`;
// NOTE: defineProps is inaccurate for $props
yield name;
yield `{} as { $props: Partial<typeof ${name}> }`;
}
// fill $emit
if (scriptSetupRanges.defineEmits) {
yield `{} as { $emit: typeof ${scriptSetupRanges.defineEmits.name ?? `__VLS_emit`} }`;
}
}

export function* generateEmitsOption(
function* generateEmitsOption(
options: ScriptCodegenOptions,
scriptSetupRanges: ScriptSetupRanges,
): Generator<Code> {
Expand Down Expand Up @@ -116,18 +111,17 @@ export function* generateEmitsOption(
}
}

export function* generatePropsOption(
function* generatePropsOption(
options: ScriptCodegenOptions,
ctx: ScriptCodegenContext,
scriptSetup: NonNullable<Sfc['scriptSetup']>,
scriptSetupRanges: ScriptSetupRanges,
hasEmitsOption: boolean,
inheritAttrs: boolean,
): Generator<Code> {
const getOptionCodes: (() => Code)[] = [];
const typeOptionCodes: Code[] = [];

if (inheritAttrs && options.templateCodegen?.inheritedAttrVars.size) {
if (options.templateCodegen?.inheritedAttrVars.size) {
let attrsType = `__VLS_InheritedAttrs`;
if (hasEmitsOption) {
attrsType = `Omit<${attrsType}, \`on\${string}\`>`;
Expand All @@ -145,7 +139,7 @@ export function* generatePropsOption(
const propsType = `${ctx.localTypes.TypePropsToOption}<__VLS_PublicProps>`;
return `{} as ` + (
scriptSetupRanges.withDefaults?.arg
? `${ctx.localTypes.WithDefaults}<${propsType}, typeof __VLS_withDefaultsArg>`
? `${ctx.localTypes.WithDefaultsLocal}<${propsType}, typeof __VLS_defaults>`
: propsType
);
});
Expand All @@ -166,7 +160,7 @@ export function* generatePropsOption(
options.vueCompilerOptions.target >= 3.6
&& scriptSetupRanges.withDefaults?.arg
) {
yield `__defaults: __VLS_withDefaultsArg,${newLine}`;
yield `__defaults: __VLS_defaults,${newLine}`;
}
yield `__typeProps: `;
yield* generateSpreadMerge(typeOptionCodes);
Expand Down
65 changes: 0 additions & 65 deletions packages/language-core/lib/codegen/script/componentSelf.ts

This file was deleted.

Loading
Loading