Skip to content
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

fix(language-core): compatible with TS 5.5 #4492

Merged
merged 4 commits into from
Jun 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"private": true,
"packageManager": "pnpm@9.1.0",
"packageManager": "pnpm@9.4.0",
"scripts": {
"build": "tsc -b",
"watch": "npm run build && (npm run watch:base & npm run watch:vue)",
Expand Down
45 changes: 29 additions & 16 deletions packages/language-core/lib/codegen/script/globalTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,29 @@ import { getSlotsPropertyName } from '../../utils/shared';
export function generateGlobalTypes(vueCompilerOptions: VueCompilerOptions) {
const fnPropsType = `(K extends { $props: infer Props } ? Props : any)${vueCompilerOptions.strictTemplates ? '' : ' & Record<string, unknown>'}`;
return `export const __VLS_globalTypesStart = {};
declare module '${vueCompilerOptions.lib}' {
interface GlobalComponents {}
}
declare global {
// @ts-ignore
type __VLS_IntrinsicElements = __VLS_PickNotAny<import('${vueCompilerOptions.lib}/jsx-runtime').JSX.IntrinsicElements, __VLS_PickNotAny<globalThis.JSX.IntrinsicElements, Record<string, any>>>;
// @ts-ignore
type __VLS_Element = __VLS_PickNotAny<import('${vueCompilerOptions.lib}/jsx-runtime').JSX.Element, globalThis.JSX.Element>;
// @ts-ignore
type __VLS_GlobalComponents = ${[
`__VLS_PickNotAny<import('${vueCompilerOptions.lib}').GlobalComponents, {}>`,
`__VLS_PickNotAny<import('@vue/runtime-core').GlobalComponents, {}>`,
`__VLS_PickNotAny<import('@vue/runtime-dom').GlobalComponents, {}>`,
`Pick<typeof import('${vueCompilerOptions.lib}'), 'Transition' | 'TransitionGroup' | 'KeepAlive' | 'Suspense' | 'Teleport'>`
].join(' & ')};
type __VLS_BuiltInPublicProps =
__VLS_PickNotAny<import('${vueCompilerOptions.lib}').VNodeProps, {}>
& __VLS_PickNotAny<import('${vueCompilerOptions.lib}').AllowedComponentProps, {}>
& __VLS_PickNotAny<import('${vueCompilerOptions.lib}').ComponentCustomProps, {}>;
type __VLS_IntrinsicElements = ${vueCompilerOptions.target >= 3.3
? `import('${vueCompilerOptions.lib}/jsx-runtime').JSX.IntrinsicElements;`
: `globalThis.JSX.IntrinsicElements;`
}
type __VLS_Element = ${vueCompilerOptions.target >= 3.3
? `import('${vueCompilerOptions.lib}/jsx-runtime').JSX.Element;`
: `globalThis.JSX.Element;`
}
type __VLS_GlobalComponents = import('${vueCompilerOptions.lib}').GlobalComponents
& Pick<typeof import('${vueCompilerOptions.lib}'), 'Transition' | 'TransitionGroup' | 'KeepAlive' | 'Suspense' | 'Teleport'>;
type __VLS_BuiltInPublicProps = ${vueCompilerOptions.target >= 3.4
? `import('${vueCompilerOptions.lib}').PublicProps;`
: vueCompilerOptions.target >= 3.0
? `import('${vueCompilerOptions.lib}').VNodeProps
& import('${vueCompilerOptions.lib}').AllowedComponentProps
& import('${vueCompilerOptions.lib}').ComponentCustomProps;`
: `globalThis.JSX.IntrinsicAttributes;`

}
type __VLS_IsAny<T> = 0 extends 1 & T ? true : false;
type __VLS_PickNotAny<A, B> = __VLS_IsAny<A> extends true ? B : A;

Expand Down Expand Up @@ -90,7 +97,13 @@ declare global {
'__ctx' extends keyof __VLS_PickNotAny<K, {}> ? K extends { __ctx?: { props?: infer P } } ? NonNullable<P> : never
: T extends (props: infer P, ...args: any) => any ? P :
{};
type __VLS_AsFunctionOrAny<F> = unknown extends F ? any : ((...args: any) => any) extends F ? F : any;
type __VLS_IsFunction<T, K> = K extends keyof T
? __VLS_IsAny<T[K]> extends false
? unknown extends T[K]
? false
: true
: false
: false;

function __VLS_normalizeSlot<S>(s: S): S extends () => infer R ? (props: {}) => R : S;

Expand Down
8 changes: 4 additions & 4 deletions packages/language-core/lib/codegen/template/elementEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,16 @@ export function* generateElementEvents(
if (!options.vueCompilerOptions.strictTemplates) {
yield `Record<string, unknown> & `;
}
yield `(`;
yield `__VLS_IsAny<__VLS_AsFunctionOrAny<typeof ${propsVar}['${originalPropName}']>> extends false${newLine}`;
yield `(${newLine}`;
yield `__VLS_IsFunction<typeof ${propsVar}, '${originalPropName}'> extends true${newLine}`;
yield `? typeof ${propsVar}${newLine}`;
yield `: __VLS_IsAny<typeof ${eventsVar}['${prop.arg.loc.source}']> extends false${newLine}`;
yield `: __VLS_IsFunction<typeof ${eventsVar}, '${prop.arg.loc.source}'> extends true${newLine}`;
yield `? {${newLine}`;
yield `/**__VLS_emit,${emitVar},${prop.arg.loc.source}*/${newLine}`;
yield `${originalPropNameObjectKey}?: typeof ${eventsVar}['${prop.arg.loc.source}']${newLine}`;
yield `}${newLine}`;
if (prop.arg.loc.source !== camelize(prop.arg.loc.source)) {
yield `: __VLS_IsAny<typeof ${eventsVar}['${camelize(prop.arg.loc.source)}']> extends false${newLine}`;
yield `: __VLS_IsFunction<typeof ${eventsVar}, '${camelize(prop.arg.loc.source)}'> extends true${newLine}`;
yield `? {${newLine}`;
yield `/**__VLS_emit,${emitVar},${camelize(prop.arg.loc.source)}*/${newLine}`;
yield `${originalPropNameObjectKey}?: typeof ${eventsVar}['${camelize(prop.arg.loc.source)}']${newLine}`;
Expand Down
6 changes: 1 addition & 5 deletions packages/language-server/lib/hybridModeProject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export function createHybridModeProject(
return Promise.all([
...tsconfigProjects.values(),
simpleLs,
].filter(notEmpty));
].filter(promise => !!promise));
},
reload() {
for (const ls of [
Expand Down Expand Up @@ -132,7 +132,3 @@ export function createHybridModeProject(
);
}
}

export function notEmpty<T>(value: T | null | undefined): value is T {
return value !== null && value !== undefined;
}
Loading
Loading