From b82461ddb734bbc572daf6331b6b9891449565eb Mon Sep 17 00:00:00 2001 From: KazariEX <1364035137@qq.com> Date: Mon, 23 Dec 2024 00:22:13 +0800 Subject: [PATCH] refactor(language-core): use non-null assertion instead of `__VLS_nonNullable` --- packages/language-core/lib/codegen/globalTypes.ts | 1 - packages/language-core/lib/codegen/template/element.ts | 4 ++-- .../language-core/lib/codegen/template/elementChildren.ts | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/packages/language-core/lib/codegen/globalTypes.ts b/packages/language-core/lib/codegen/globalTypes.ts index d34f4e924a..ac0a213671 100644 --- a/packages/language-core/lib/codegen/globalTypes.ts +++ b/packages/language-core/lib/codegen/globalTypes.ts @@ -133,7 +133,6 @@ export function generateGlobalTypes(lib: string, target: number, strictTemplates : __VLS_unknownDirective; function __VLS_withScope(ctx: T, scope: K): ctx is T & K; function __VLS_makeOptional(t: T): { [K in keyof T]?: T[K] }; - function __VLS_nonNullable(t: T): T extends null | undefined ? never : T; function __VLS_asFunctionalComponent any ? InstanceType : unknown>(t: T, instance?: K): T extends new (...args: any) => any ? (props: ${fnPropsType}, ctx?: any) => __VLS_Element & { __ctx?: { diff --git a/packages/language-core/lib/codegen/template/element.ts b/packages/language-core/lib/codegen/template/element.ts index eeded19b4b..9fbeccca69 100644 --- a/packages/language-core/lib/codegen/template/element.ts +++ b/packages/language-core/lib/codegen/template/element.ts @@ -512,7 +512,7 @@ function* generateComponentSlot( `__VLS_thisSlot` ); } - yield `} = __VLS_nonNullable(${componentCtxVar}.slots)${endOfLine}`; + yield `} = ${componentCtxVar}.slots!${endOfLine}`; if (slotDir?.exp?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) { const slotAst = createTsAst(options.ts, slotDir, `(${slotDir.exp.content}) => {}`); @@ -559,7 +559,7 @@ function* generateComponentSlot( isStatic = slotDir.arg.isStatic; } if (isStatic && slotDir && !slotDir.arg) { - yield `__VLS_nonNullable(${componentCtxVar}.slots)['`; + yield `${componentCtxVar}.slots!['`; yield [ '', 'template', diff --git a/packages/language-core/lib/codegen/template/elementChildren.ts b/packages/language-core/lib/codegen/template/elementChildren.ts index 0ebbb8e71c..b998b79451 100644 --- a/packages/language-core/lib/codegen/template/elementChildren.ts +++ b/packages/language-core/lib/codegen/template/elementChildren.ts @@ -29,7 +29,7 @@ export function* generateElementChildren( && node.tagType !== CompilerDOM.ElementTypes.TEMPLATE ) { ctx.usedComponentCtxVars.add(componentCtxVar); - yield `__VLS_nonNullable(${componentCtxVar}.slots).`; + yield `${componentCtxVar}.slots!.`; yield* wrapWith( node.children[0].loc.start.offset, node.children[node.children.length - 1].loc.end.offset,