Skip to content

Commit

Permalink
fix(language-core): don't assign this to __VLS_ctx (#4845)
Browse files Browse the repository at this point in the history
  • Loading branch information
KazariEX committed Sep 18, 2024
1 parent d8ed4c0 commit 66c9ab6
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 17 deletions.
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>

0 comments on commit 66c9ab6

Please sign in to comment.