Skip to content

Commit fa5cdcd

Browse files
committed
refactor: collect components during codegen
1 parent 560619c commit fa5cdcd

File tree

5 files changed

+3
-12
lines changed

5 files changed

+3
-12
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ function* generateBindings(
206206
}
207207

208208
const usageVars = new Set([
209-
...options.sfc.template?.ast?.components.flatMap(c => [camelize(c), capitalize(camelize(c))]) ?? [],
209+
...options.templateCodegen?.components.flatMap(c => [camelize(c), capitalize(camelize(c))]) ?? [],
210210
...options.templateCodegen?.accessExternalVariables.keys() ?? [],
211211
...templateCodegenCtx.accessExternalVariables.keys(),
212212
]);

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ export function createTemplateCodegenContext(
211211
bindingAttrLocs,
212212
inheritedAttrVars,
213213
templateRefs,
214+
components: [] as string[],
214215
currentComponent: undefined as {
215216
get ctxVar(): string;
216217
get propsVar(): string;

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ export function* generateComponent(
3939

4040
let isCtxVarUsed = false;
4141
let isPropsVarUsed = false;
42+
ctx.components.push(node.tag);
4243
ctx.currentComponent = {
4344
get ctxVar() {
4445
isCtxVarUsed = true;

packages/language-core/lib/template/compile.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { type CompilerOptions, getBaseTransformPreset, parse, transform } from '@vue/compiler-dom';
2-
import { transformElement } from './transforms/transformElement';
32
import { transformText } from './transforms/transformText';
43
import { transformFor } from './transforms/vFor';
54
import { transformIf } from './transforms/vIf';
@@ -13,7 +12,6 @@ export function compileTemplate(source: string, options: CompilerOptions) {
1312
nodeTransforms[0]!, // transformVBindShorthand
1413
transformIf,
1514
transformFor,
16-
transformElement,
1715
transformText,
1816
...options.nodeTransforms || [],
1917
],

packages/language-core/lib/template/transforms/transformElement.ts

Lines changed: 0 additions & 9 deletions
This file was deleted.

0 commit comments

Comments
 (0)