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): don't assign this to __VLS_ctx #4845

Merged
merged 1 commit into from
Sep 18, 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
6 changes: 3 additions & 3 deletions packages/language-core/lib/codegen/script/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ export function* generateScript(options: ScriptCodegenOptions): Generator<Code,
}
else {
yield generateSfcBlockSection(options.sfc.script, 0, classBlockEnd, codeFeatures.all);
yield `__VLS_template = () => {`;
const templateCodegenCtx = yield* generateTemplate(options, ctx, true);
yield `__VLS_template = () => {${newLine}`;
const templateCodegenCtx = yield* generateTemplate(options, ctx);
yield* generateComponentSelf(options, ctx, templateCodegenCtx);
yield `},${newLine}`;
yield generateSfcBlockSection(options.sfc.script, classBlockEnd, options.sfc.script.content.length, codeFeatures.all);
Expand All @@ -140,7 +140,7 @@ export function* generateScript(options: ScriptCodegenOptions): Generator<Code,

if (!ctx.generatedTemplate) {
yield `function __VLS_template() {${newLine}`;
const templateCodegenCtx = yield* generateTemplate(options, ctx, false);
const templateCodegenCtx = yield* generateTemplate(options, ctx);
yield `}${endOfLine}`;
yield* generateComponentSelf(options, ctx, templateCodegenCtx);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/language-core/lib/codegen/script/scriptSetup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ function* generateSetupFunction(
yield* generateComponentProps(options, ctx, scriptSetup, scriptSetupRanges, definePropMirrors);
yield* generateModelEmits(options, scriptSetup, scriptSetupRanges);
yield `function __VLS_template() {${newLine}`;
const templateCodegenCtx = yield* generateTemplate(options, ctx, false);
const templateCodegenCtx = yield* generateTemplate(options, ctx);
yield `}${endOfLine}`;
yield* generateComponentSelf(options, ctx, templateCodegenCtx);
yield `type __VLS_TemplateResult = ReturnType<typeof __VLS_template>${endOfLine}`;
Expand Down
18 changes: 5 additions & 13 deletions packages/language-core/lib/codegen/script/template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,11 @@ import { generateStyleScopedClasses } from '../template/styleScopedClasses';
import type { ScriptCodegenContext } from './context';
import { codeFeatures, type ScriptCodegenOptions } from './index';

function* generateTemplateCtx(
options: ScriptCodegenOptions,
isClassComponent: boolean
): Generator<Code> {
function* generateTemplateCtx(options: ScriptCodegenOptions): Generator<Code> {
const exps = [];

if (isClassComponent) {
exps.push(`this`);
}
else {
exps.push(`{} as InstanceType<__VLS_PickNotAny<typeof __VLS_self, new () => {}>>`);
}
exps.push(`{} as InstanceType<__VLS_PickNotAny<typeof __VLS_self, new () => {}>>`);

if (options.vueCompilerOptions.petiteVueExtensions.some(ext => options.fileBaseName.endsWith(ext))) {
exps.push(`globalThis`);
}
Expand Down Expand Up @@ -116,16 +109,15 @@ export function* generateTemplateDirectives(options: ScriptCodegenOptions): Gene

export function* generateTemplate(
options: ScriptCodegenOptions,
ctx: ScriptCodegenContext,
isClassComponent: boolean
ctx: ScriptCodegenContext
): Generator<Code, TemplateCodegenContext> {
ctx.generatedTemplate = true;

const templateCodegenCtx = createTemplateCodegenContext({
scriptSetupBindingNames: new Set(),
edited: options.edited,
});
yield* generateTemplateCtx(options, isClassComponent);
yield* generateTemplateCtx(options);
yield* generateTemplateComponents(options);
yield* generateTemplateDirectives(options);
yield* generateTemplateBody(options, templateCodegenCtx);
Expand Down
7 changes: 7 additions & 0 deletions test-workspace/tsc/passedFixtures/vue3/#4841/main.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<script lang="ts">
export default class {}
</script>

<template>
<Comp></Comp>
</template>