Skip to content

Commit 6f87f71

Browse files
committed
fix: generate bindings after template variable collection
1 parent b2ac1ef commit 6f87f71

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ export function* generateTemplate(
2020
const templateCodegenCtx = createTemplateCodegenContext({
2121
scriptSetupBindingNames: new Set(),
2222
});
23-
yield* generateBindings(options, ctx);
2423
yield* generateTemplateCtx(options, ctx);
2524
yield* generateTemplateElements();
2625
yield* generateTemplateComponents(options);
2726
yield* generateTemplateDirectives(options);
2827
yield* generateTemplateBody(options, templateCodegenCtx);
28+
yield* generateBindings(options, ctx, templateCodegenCtx);
2929

3030
if (options.sfc.script && options.scriptRanges?.exportDefault) {
3131
yield `const __VLS_self = (await import('${options.vueCompilerOptions.lib}')).defineComponent(`;
@@ -183,6 +183,7 @@ function* generateCssVars(options: ScriptCodegenOptions, ctx: TemplateCodegenCon
183183
function* generateBindings(
184184
options: ScriptCodegenOptions,
185185
ctx: ScriptCodegenContext,
186+
templateCodegenCtx: TemplateCodegenContext,
186187
): Generator<Code> {
187188
yield `type __VLS_Bindings = __VLS_ProxyRefs<{${newLine}`;
188189
if (options.sfc.scriptSetup && options.scriptSetupRanges) {
@@ -197,7 +198,7 @@ function* generateBindings(
197198
) {
198199
for (const { range } of bindings) {
199200
const varName = content.slice(range.start, range.end);
200-
if (!templateUsageVars.has(varName)) {
201+
if (!templateUsageVars.has(varName) && !templateCodegenCtx.accessExternalVariables.has(varName)) {
201202
continue;
202203
}
203204

0 commit comments

Comments
 (0)