Skip to content

Commit 66c9ab6

Browse files
authored
fix(language-core): don't assign this to __VLS_ctx (#4845)
1 parent d8ed4c0 commit 66c9ab6

File tree

4 files changed

+16
-17
lines changed

4 files changed

+16
-17
lines changed

packages/language-core/lib/codegen/script/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,8 @@ export function* generateScript(options: ScriptCodegenOptions): Generator<Code,
114114
}
115115
else {
116116
yield generateSfcBlockSection(options.sfc.script, 0, classBlockEnd, codeFeatures.all);
117-
yield `__VLS_template = () => {`;
118-
const templateCodegenCtx = yield* generateTemplate(options, ctx, true);
117+
yield `__VLS_template = () => {${newLine}`;
118+
const templateCodegenCtx = yield* generateTemplate(options, ctx);
119119
yield* generateComponentSelf(options, ctx, templateCodegenCtx);
120120
yield `},${newLine}`;
121121
yield generateSfcBlockSection(options.sfc.script, classBlockEnd, options.sfc.script.content.length, codeFeatures.all);
@@ -140,7 +140,7 @@ export function* generateScript(options: ScriptCodegenOptions): Generator<Code,
140140

141141
if (!ctx.generatedTemplate) {
142142
yield `function __VLS_template() {${newLine}`;
143-
const templateCodegenCtx = yield* generateTemplate(options, ctx, false);
143+
const templateCodegenCtx = yield* generateTemplate(options, ctx);
144144
yield `}${endOfLine}`;
145145
yield* generateComponentSelf(options, ctx, templateCodegenCtx);
146146
}

packages/language-core/lib/codegen/script/scriptSetup.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ function* generateSetupFunction(
288288
yield* generateComponentProps(options, ctx, scriptSetup, scriptSetupRanges, definePropMirrors);
289289
yield* generateModelEmits(options, scriptSetup, scriptSetupRanges);
290290
yield `function __VLS_template() {${newLine}`;
291-
const templateCodegenCtx = yield* generateTemplate(options, ctx, false);
291+
const templateCodegenCtx = yield* generateTemplate(options, ctx);
292292
yield `}${endOfLine}`;
293293
yield* generateComponentSelf(options, ctx, templateCodegenCtx);
294294
yield `type __VLS_TemplateResult = ReturnType<typeof __VLS_template>${endOfLine}`;

packages/language-core/lib/codegen/script/template.ts

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,11 @@ import { generateStyleScopedClasses } from '../template/styleScopedClasses';
88
import type { ScriptCodegenContext } from './context';
99
import { codeFeatures, type ScriptCodegenOptions } from './index';
1010

11-
function* generateTemplateCtx(
12-
options: ScriptCodegenOptions,
13-
isClassComponent: boolean
14-
): Generator<Code> {
11+
function* generateTemplateCtx(options: ScriptCodegenOptions): Generator<Code> {
1512
const exps = [];
1613

17-
if (isClassComponent) {
18-
exps.push(`this`);
19-
}
20-
else {
21-
exps.push(`{} as InstanceType<__VLS_PickNotAny<typeof __VLS_self, new () => {}>>`);
22-
}
14+
exps.push(`{} as InstanceType<__VLS_PickNotAny<typeof __VLS_self, new () => {}>>`);
15+
2316
if (options.vueCompilerOptions.petiteVueExtensions.some(ext => options.fileBaseName.endsWith(ext))) {
2417
exps.push(`globalThis`);
2518
}
@@ -116,16 +109,15 @@ export function* generateTemplateDirectives(options: ScriptCodegenOptions): Gene
116109

117110
export function* generateTemplate(
118111
options: ScriptCodegenOptions,
119-
ctx: ScriptCodegenContext,
120-
isClassComponent: boolean
112+
ctx: ScriptCodegenContext
121113
): Generator<Code, TemplateCodegenContext> {
122114
ctx.generatedTemplate = true;
123115

124116
const templateCodegenCtx = createTemplateCodegenContext({
125117
scriptSetupBindingNames: new Set(),
126118
edited: options.edited,
127119
});
128-
yield* generateTemplateCtx(options, isClassComponent);
120+
yield* generateTemplateCtx(options);
129121
yield* generateTemplateComponents(options);
130122
yield* generateTemplateDirectives(options);
131123
yield* generateTemplateBody(options, templateCodegenCtx);
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<script lang="ts">
2+
export default class {}
3+
</script>
4+
5+
<template>
6+
<Comp></Comp>
7+
</template>

0 commit comments

Comments
 (0)