Skip to content

Commit cf81a29

Browse files
committed
wip
1 parent f571838 commit cf81a29

File tree

4 files changed

+24
-20
lines changed

4 files changed

+24
-20
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export interface StyleCodegenOptions {
1212
usedCssModule: boolean;
1313
styles: Sfc['styles'];
1414
templateRefNames: Set<string>;
15-
destructuredPropNames: Set<string>;
15+
rawBindingNames: Set<string>;
1616
setupBindingNames: Set<string>;
1717
}
1818

@@ -21,7 +21,7 @@ export { generate as generateStyle };
2121
function* generate(options: StyleCodegenOptions) {
2222
const ctx = createTemplateCodegenContext(options.setupBindingNames);
2323
const endScope = ctx.startScope();
24-
ctx.declare(...options.destructuredPropNames);
24+
ctx.declare(...options.rawBindingNames);
2525
yield* generateStyleScopedClasses(options);
2626
yield* generateStyleModules(options, ctx);
2727
yield* generateCssVars(options, ctx);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export function* generateComponent(
3131
const tagOffsets = getElementTagOffsets(node, options.template);
3232
const failGeneratedExpressions: FailGeneratedExpression[] = [];
3333
const possibleOriginalNames = getPossibleOriginalComponentNames(node.tag, true);
34-
const matchImportName = possibleOriginalNames.find(name => options.scriptSetupImportComponentNames.has(name));
34+
const matchImportName = possibleOriginalNames.find(name => options.rawBindingNames.has(name));
3535
const componentOriginalVar = matchImportName ?? ctx.getInternalVariable();
3636
const componentFunctionalVar = ctx.getInternalVariable();
3737
const componentVNodeVar = ctx.getInternalVariable();

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,9 @@ export interface TemplateCodegenOptions {
1313
compilerOptions: ts.CompilerOptions;
1414
vueCompilerOptions: VueCompilerOptions;
1515
template: NonNullable<Sfc['template']>;
16-
destructuredPropNames: Set<string>;
16+
rawBindingNames: Set<string>;
1717
setupBindingNames: Set<string>;
1818
templateRefNames: Set<string>;
19-
scriptSetupImportComponentNames: Set<string>;
2019
hasDefineSlots?: boolean;
2120
propsAssignName?: string;
2221
slotsAssignName?: string;
@@ -47,7 +46,7 @@ function* generateWorker(
4746
ctx: TemplateCodegenContext,
4847
): Generator<Code> {
4948
const endScope = ctx.startScope();
50-
ctx.declare(...options.destructuredPropNames);
49+
ctx.declare(...options.rawBindingNames);
5150
const {
5251
slotsAssignName,
5352
propsAssignName,

packages/language-core/lib/plugins/vue-tsx.ts

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,10 @@ function useCodegen(
107107
return newNames;
108108
}
109109
for (const { range } of scriptSetupRanges.bindings) {
110-
newNames.add(sfc.scriptSetup.content.slice(range.start, range.end));
110+
const name = sfc.scriptSetup.content.slice(range.start, range.end);
111+
if (!getImportComponentNames().has(name)) {
112+
newNames.add(name);
113+
}
111114
}
112115
const scriptRanges = getScriptRanges();
113116
if (sfc.script && scriptRanges) {
@@ -118,31 +121,34 @@ function useCodegen(
118121
return newNames;
119122
});
120123

121-
const getSetupImportComponentNames = computedSet(() => {
122-
const newNames = new Set<string>();
123-
const bindings = getScriptSetupRanges()?.bindings;
124-
if (sfc.scriptSetup && bindings) {
125-
for (const { range, moduleName, isDefaultImport, isNamespace } of bindings) {
124+
const getImportComponentNames = computedSet(() => {
125+
const names = new Set<string>();
126+
const scriptSetupRanges = getScriptSetupRanges();
127+
if (sfc.scriptSetup && scriptSetupRanges) {
128+
for (const { range, moduleName, isDefaultImport, isNamespace } of scriptSetupRanges.bindings) {
126129
if (
127130
moduleName
128131
&& isDefaultImport
129132
&& !isNamespace
130133
&& ctx.vueCompilerOptions.extensions.some(ext => moduleName.endsWith(ext))
131134
) {
132-
newNames.add(sfc.scriptSetup.content.slice(range.start, range.end));
135+
names.add(sfc.scriptSetup.content.slice(range.start, range.end));
133136
}
134137
}
135138
}
136-
return newNames;
139+
return names;
137140
});
138141

139142
const getDestructuredPropNames = computedSet(() => {
140-
const newNames = new Set(getScriptSetupRanges()?.defineProps?.destructured?.keys());
143+
const names = new Set([
144+
...getScriptSetupRanges()?.defineProps?.destructured?.keys() ?? [],
145+
...getImportComponentNames(),
146+
]);
141147
const rest = getScriptSetupRanges()?.defineProps?.destructuredRest;
142148
if (rest) {
143-
newNames.add(rest);
149+
names.add(rest);
144150
}
145-
return newNames;
151+
return names;
146152
});
147153

148154
const getSetupTemplateRefNames = computedSet(() => {
@@ -197,10 +203,9 @@ function useCodegen(
197203
compilerOptions: ctx.compilerOptions,
198204
vueCompilerOptions: getResolvedOptions(),
199205
template: sfc.template,
200-
destructuredPropNames: getDestructuredPropNames(),
206+
rawBindingNames: getDestructuredPropNames(),
201207
setupBindingNames: getSetupBindingNames(),
202208
templateRefNames: getSetupTemplateRefNames(),
203-
scriptSetupImportComponentNames: getSetupImportComponentNames(),
204209
hasDefineSlots: setupHasDefineSlots(),
205210
propsAssignName: getSetupPropsAssignName(),
206211
slotsAssignName: getSetupSlotsAssignName(),
@@ -248,7 +253,7 @@ function useCodegen(
248253
vueCompilerOptions: getResolvedOptions(),
249254
usedCssModule: usedCssModule(),
250255
styles: sfc.styles,
251-
destructuredPropNames: getDestructuredPropNames(),
256+
rawBindingNames: getDestructuredPropNames(),
252257
templateRefNames: getSetupTemplateRefNames(),
253258
setupBindingNames: getSetupBindingNames(),
254259
});

0 commit comments

Comments
 (0)