Skip to content

Commit 9ad178a

Browse files
committed
refactor(language-core): rename codegen options
1 parent 27772e5 commit 9ad178a

File tree

17 files changed

+76
-78
lines changed

17 files changed

+76
-78
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,14 @@ export function* generateComponent(
3333
if (
3434
options.vueCompilerOptions.target >= 3.5
3535
&& options.vueCompilerOptions.inferComponentDollarRefs
36-
&& options.templateCodegen?.generatedTypes.has(names.TemplateRefs)
36+
&& options.templateAndStyleTypes.has(names.TemplateRefs)
3737
) {
3838
yield `__typeRefs: {} as ${names.TemplateRefs},${newLine}`;
3939
}
4040
if (
4141
options.vueCompilerOptions.target >= 3.5
4242
&& options.vueCompilerOptions.inferComponentDollarEl
43-
&& options.templateCodegen?.generatedTypes.has(names.RootEl)
43+
&& options.templateAndStyleTypes.has(names.RootEl)
4444
) {
4545
yield `__typeEl: {} as ${names.RootEl},${newLine}`;
4646
}
@@ -91,7 +91,7 @@ function* generatePropsOption(
9191
const optionGenerates: (() => Iterable<Code>)[] = [];
9292
const typeOptionGenerates: (() => Iterable<Code>)[] = [];
9393

94-
if (options.templateCodegen?.generatedTypes.has(names.InheritedAttrs)) {
94+
if (options.templateAndStyleTypes.has(names.InheritedAttrs)) {
9595
const attrsType = hasEmitsOption
9696
? `Omit<${names.InheritedAttrs}, keyof ${names.EmitProps}>`
9797
: names.InheritedAttrs;

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import type { ScriptSetupRanges } from '../../parsers/scriptSetupRanges';
44
import type { Code, Sfc, SfcBlock, VueCompilerOptions } from '../../types';
55
import { codeFeatures } from '../codeFeatures';
66
import * as names from '../names';
7-
import type { TemplateCodegenContext } from '../template/context';
87
import { endOfLine, generateSfcBlockSection, newLine } from '../utils';
98
import { endBoundary, startBoundary } from '../utils/boundary';
109
import { createScriptCodegenContext, type ScriptCodegenContext } from './context';
@@ -20,9 +19,9 @@ export interface ScriptCodegenOptions {
2019
fileName: string;
2120
scriptRanges: ScriptRanges | undefined;
2221
scriptSetupRanges: ScriptSetupRanges | undefined;
23-
templateCodegen: TemplateCodegenContext & { codes: Code[] } | undefined;
24-
styleCodegen: TemplateCodegenContext & { codes: Code[] } | undefined;
25-
setupExposed: Set<string>;
22+
templateAndStyleTypes: Set<string>;
23+
templateAndStyleCodes: Code[];
24+
exposed: Set<string>;
2625
}
2726

2827
export { generate as generateScript };

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ export function* generateGeneric(
7676
if (scriptSetupRanges.defineEmits || scriptSetupRanges.defineModel.length) {
7777
propTypes.push(names.EmitProps);
7878
}
79-
if (options.templateCodegen?.generatedTypes.has(names.InheritedAttrs)) {
79+
if (options.templateAndStyleTypes.has(names.InheritedAttrs)) {
8080
propTypes.push(names.InheritedAttrs);
8181
}
8282
if (scriptSetupRanges.defineEmits) {
@@ -108,13 +108,13 @@ export function* generateGeneric(
108108
: `{}`;
109109
if (
110110
options.vueCompilerOptions.inferComponentDollarRefs
111-
&& options.templateCodegen?.generatedTypes.has(names.TemplateRefs)
111+
&& options.templateAndStyleTypes.has(names.TemplateRefs)
112112
) {
113113
yield ` & { $refs: ${names.TemplateRefs}; }`;
114114
}
115115
if (
116116
options.vueCompilerOptions.inferComponentDollarEl
117-
&& options.templateCodegen?.generatedTypes.has(names.RootEl)
117+
&& options.templateAndStyleTypes.has(names.RootEl)
118118
) {
119119
yield ` & { $el: ${names.RootEl}; }`;
120120
}
@@ -208,7 +208,7 @@ export function* generateSetupFunction(
208208
yield `(`;
209209
}),
210210
);
211-
const type = options.styleCodegen?.generatedTypes.has(names.StyleModules)
211+
const type = options.templateAndStyleTypes.has(names.StyleModules)
212212
? names.StyleModules
213213
: `{}`;
214214
if (arg) {
@@ -307,7 +307,7 @@ function* generateMacros(options: ScriptCodegenOptions): Generator<Code> {
307307
yield `// @ts-ignore${newLine}`;
308308
yield `declare const { `;
309309
for (const macro of Object.keys(options.vueCompilerOptions.macros)) {
310-
if (!options.setupExposed.has(macro)) {
310+
if (!options.exposed.has(macro)) {
311311
yield `${macro}, `;
312312
}
313313
}
@@ -410,7 +410,7 @@ function* generatePublicProps(
410410
function hasSlotsType(options: ScriptCodegenOptions): boolean {
411411
return !!(
412412
options.scriptSetupRanges?.defineSlots
413-
|| options.templateCodegen?.generatedTypes.has(names.Slots)
413+
|| options.templateAndStyleTypes.has(names.Slots)
414414
);
415415
}
416416

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

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,13 @@ export function* generateTemplate(
1616
yield* generateTemplateComponents(options, ctx);
1717
yield* generateTemplateDirectives(options, ctx);
1818

19-
if (options.styleCodegen) {
20-
yield* options.styleCodegen.codes;
21-
}
22-
if (options.templateCodegen) {
23-
yield* options.templateCodegen.codes;
19+
if (options.templateAndStyleCodes.length) {
20+
yield* options.templateAndStyleCodes;
2421
}
2522
}
2623

2724
function* generateTemplateCtx(
28-
{ vueCompilerOptions, styleCodegen, scriptSetupRanges, fileName }: ScriptCodegenOptions,
25+
{ vueCompilerOptions, templateAndStyleTypes, scriptSetupRanges, fileName }: ScriptCodegenOptions,
2926
ctx: ScriptCodegenContext,
3027
selfType: string | undefined,
3128
): Generator<Code> {
@@ -42,7 +39,7 @@ function* generateTemplateCtx(
4239
else {
4340
exps.push([`{} as import('${vueCompilerOptions.lib}').ComponentPublicInstance`]);
4441
}
45-
if (styleCodegen?.generatedTypes.has(names.StyleModules)) {
42+
if (templateAndStyleTypes.has(names.StyleModules)) {
4643
exps.push([`{} as ${names.StyleModules}`]);
4744
}
4845

@@ -135,16 +132,16 @@ function* generateTemplateDirectives(
135132
}
136133

137134
function* generateSetupExposed(
138-
{ setupExposed }: ScriptCodegenOptions,
135+
{ exposed }: ScriptCodegenOptions,
139136
ctx: ScriptCodegenContext,
140137
): Generator<Code> {
141-
if (!setupExposed.size) {
138+
if (!exposed.size) {
142139
return;
143140
}
144141
ctx.generatedTypes.add(names.SetupExposed);
145142

146143
yield `type ${names.SetupExposed} = __VLS_ProxyRefs<{${newLine}`;
147-
for (const bindingName of setupExposed) {
144+
for (const bindingName of exposed) {
148145
const token = Symbol(bindingName.length);
149146
yield ['', undefined, 0, { __linkedToken: token }];
150147
yield `${bindingName}: typeof `;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { generateInterpolation } from '../template/interpolation';
77
import { endOfLine } from '../utils';
88

99
export interface StyleCodegenOptions {
10-
ts: typeof import('typescript');
10+
typescript: typeof import('typescript');
1111
vueCompilerOptions: VueCompilerOptions;
1212
styles: Sfc['styles'];
1313
setupRefs: Set<string>;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ export function* generateComponent(
116116
}
117117
else {
118118
yield `let ${componentVar}!: __VLS_WithComponent<'${tag}', __VLS_LocalComponents`;
119-
yield originalNames.has(options.selfComponentName)
119+
yield originalNames.has(options.componentName)
120120
? `, typeof ${names._export}`
121121
: `, void`;
122122
for (const name of originalNames) {
@@ -347,7 +347,7 @@ export function* generateElement(
347347
}
348348

349349
function* generateStyleScopedClassReferences(
350-
{ template, ts }: TemplateCodegenOptions,
350+
{ template, typescript: ts }: TemplateCodegenOptions,
351351
node: CompilerDOM.ElementNode,
352352
): Generator<Code> {
353353
for (const prop of node.props) {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,8 @@ export function* generateEventExpression(
114114
prop: CompilerDOM.DirectiveNode,
115115
): Generator<Code> {
116116
if (prop.exp?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
117-
const ast = getTypeScriptAST(options.ts, options.template, prop.exp.content);
118-
const isCompound = isCompoundExpression(options.ts, ast);
117+
const ast = getTypeScriptAST(options.typescript, options.template, prop.exp.content);
118+
const isCompound = isCompoundExpression(options.typescript, ast);
119119
const interpolation = generateInterpolation(
120120
options,
121121
ctx,

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { generateObjectProperty } from './objectProperty';
99
import { generateTemplateChild } from './templateChild';
1010

1111
export interface TemplateCodegenOptions {
12-
ts: typeof ts;
12+
typescript: typeof ts;
1313
vueCompilerOptions: VueCompilerOptions;
1414
template: NonNullable<Sfc['template']>;
1515
setupRefs: Set<string>;
@@ -18,7 +18,7 @@ export interface TemplateCodegenOptions {
1818
propsAssignName?: string;
1919
slotsAssignName?: string;
2020
inheritAttrs: boolean;
21-
selfComponentName: string;
21+
componentName: string;
2222
}
2323

2424
export { generate as generateTemplate };

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

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,17 @@ import { collectBindingNames } from '../../utils/collectBindings';
55
import { getNodeText, getStartEnd } from '../../utils/shared';
66
import { codeFeatures } from '../codeFeatures';
77
import * as names from '../names';
8-
import type { StyleCodegenOptions } from '../style';
98
import { forEachNode, getTypeScriptAST, identifierRegex } from '../utils';
109
import type { TemplateCodegenContext } from './context';
11-
import type { TemplateCodegenOptions } from './index';
1210

1311
// https://github.com/vuejs/core/blob/fb0c3ca519f1fccf52049cd6b8db3a67a669afe9/packages/compiler-core/src/transforms/transformExpression.ts#L47
1412
const isLiteralWhitelisted = /*@__PURE__*/ makeMap('true,false,null,this');
1513

1614
export function* generateInterpolation(
17-
options: Pick<
18-
TemplateCodegenOptions | StyleCodegenOptions,
19-
'ts' | 'setupRefs'
20-
>,
15+
{ typescript, setupRefs }: {
16+
typescript: typeof import('typescript');
17+
setupRefs: Set<string>;
18+
},
2119
ctx: TemplateCodegenContext,
2220
block: SfcBlock,
2321
data: VueCodeInformation,
@@ -28,7 +26,8 @@ export function* generateInterpolation(
2826
): Generator<Code> {
2927
for (
3028
const segment of forEachInterpolationSegment(
31-
options,
29+
typescript,
30+
setupRefs,
3231
ctx,
3332
block,
3433
code,
@@ -70,10 +69,8 @@ export function* generateInterpolation(
7069
}
7170

7271
function* forEachInterpolationSegment(
73-
{ ts, setupRefs }: Pick<
74-
TemplateCodegenOptions | StyleCodegenOptions,
75-
'ts' | 'setupRefs'
76-
>,
72+
ts: typeof import('typescript'),
73+
setupRefs: Set<string>,
7774
ctx: TemplateCodegenContext,
7875
block: SfcBlock,
7976
originalCode: string,

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ export function* generateVFor(
1919

2020
yield `for (const [`;
2121
if (leftExpressionRange && leftExpressionText) {
22-
const collectAst = getTypeScriptAST(options.ts, options.template, `const [${leftExpressionText}]`);
23-
ctx.declare(...collectBindingNames(options.ts, collectAst, collectAst));
22+
const collectAst = getTypeScriptAST(options.typescript, options.template, `const [${leftExpressionText}]`);
23+
ctx.declare(...collectBindingNames(options.typescript, collectAst, collectAst));
2424
yield [
2525
leftExpressionText,
2626
'template',

0 commit comments

Comments
 (0)