@vue/language-core 2.0.16 → 2.0.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. package/lib/codegen/script/globalTypes.js +10 -14
  2. package/lib/codegen/script/index.d.ts +3 -6
  3. package/lib/codegen/script/index.js +12 -15
  4. package/lib/codegen/script/internalComponent.js +1 -1
  5. package/lib/codegen/script/scriptSetup.js +21 -23
  6. package/lib/codegen/script/template.d.ts +1 -1
  7. package/lib/codegen/script/template.js +45 -36
  8. package/lib/codegen/template/context.d.ts +8 -3
  9. package/lib/codegen/template/context.js +42 -13
  10. package/lib/codegen/template/element.js +81 -50
  11. package/lib/codegen/template/elementDirectives.js +1 -1
  12. package/lib/codegen/template/elementEvents.d.ts +2 -2
  13. package/lib/codegen/template/elementEvents.js +46 -35
  14. package/lib/codegen/template/elementProps.js +56 -63
  15. package/lib/codegen/template/index.d.ts +4 -46
  16. package/lib/codegen/template/index.js +36 -21
  17. package/lib/codegen/template/interpolation.d.ts +2 -2
  18. package/lib/codegen/template/interpolation.js +12 -46
  19. package/lib/codegen/template/vFor.js +13 -3
  20. package/lib/languageModule.d.ts +1 -1
  21. package/lib/languageModule.js +4 -4
  22. package/lib/parsers/scriptRanges.d.ts +1 -0
  23. package/lib/parsers/scriptRanges.js +7 -0
  24. package/lib/parsers/scriptSetupRanges.d.ts +4 -0
  25. package/lib/parsers/scriptSetupRanges.js +24 -0
  26. package/lib/plugins/file-md.js +1 -0
  27. package/lib/plugins/vue-script-js.d.ts +3 -0
  28. package/lib/plugins/vue-script-js.js +15 -0
  29. package/lib/plugins/vue-template-html.js +1 -1
  30. package/lib/plugins/vue-template-inline-ts.js +1 -1
  31. package/lib/plugins/vue-tsx.d.ts +46 -40
  32. package/lib/plugins/vue-tsx.js +34 -28
  33. package/lib/plugins.d.ts +1 -0
  34. package/lib/plugins.js +2 -0
  35. package/lib/types.d.ts +1 -15
  36. package/lib/utils/parseCssClassNames.js +1 -1
  37. package/lib/utils/ts.js +0 -1
  38. package/lib/virtualFile/computedSfc.js +20 -5
  39. package/package.json +3 -3
@@ -4,20 +4,23 @@ exports.generateGlobalTypes = void 0;
4
4
  const shared_1 = require("../../utils/shared");
5
5
  function generateGlobalTypes(vueCompilerOptions) {
6
6
  const fnPropsType = `(K extends { $props: infer Props } ? Props : any)${vueCompilerOptions.strictTemplates ? '' : ' & Record<string, unknown>'}`;
7
- return `
8
- ; export const __VLS_globalTypesStart = {};
7
+ return `export const __VLS_globalTypesStart = {};
9
8
  declare global {
10
9
  // @ts-ignore
11
- type __VLS_IntrinsicElements = __VLS_PickNotAny<import('vue/jsx-runtime').JSX.IntrinsicElements, __VLS_PickNotAny<globalThis.JSX.IntrinsicElements, Record<string, any>>>;
10
+ type __VLS_IntrinsicElements = __VLS_PickNotAny<import('${vueCompilerOptions.lib}/jsx-runtime').JSX.IntrinsicElements, __VLS_PickNotAny<globalThis.JSX.IntrinsicElements, Record<string, any>>>;
12
11
  // @ts-ignore
13
- type __VLS_Element = __VLS_PickNotAny<import('vue/jsx-runtime').JSX.Element, globalThis.JSX.Element>;
12
+ type __VLS_Element = __VLS_PickNotAny<import('${vueCompilerOptions.lib}/jsx-runtime').JSX.Element, globalThis.JSX.Element>;
14
13
  // @ts-ignore
15
14
  type __VLS_GlobalComponents = ${[
16
- `__VLS_PickNotAny<import('vue').GlobalComponents, {}>`,
15
+ `__VLS_PickNotAny<import('${vueCompilerOptions.lib}').GlobalComponents, {}>`,
17
16
  `__VLS_PickNotAny<import('@vue/runtime-core').GlobalComponents, {}>`,
18
17
  `__VLS_PickNotAny<import('@vue/runtime-dom').GlobalComponents, {}>`,
19
18
  `Pick<typeof import('${vueCompilerOptions.lib}'), 'Transition' | 'TransitionGroup' | 'KeepAlive' | 'Suspense' | 'Teleport'>`
20
19
  ].join(' & ')};
20
+ type __VLS_BuiltInPublicProps =
21
+ __VLS_PickNotAny<import('${vueCompilerOptions.lib}').VNodeProps, {}>
22
+ & __VLS_PickNotAny<import('${vueCompilerOptions.lib}').AllowedComponentProps, {}>
23
+ & __VLS_PickNotAny<import('${vueCompilerOptions.lib}').ComponentCustomProps, {}>;
21
24
  type __VLS_IsAny<T> = 0 extends 1 & T ? true : false;
22
25
  type __VLS_PickNotAny<A, B> = __VLS_IsAny<A> extends true ? B : A;
23
26
 
@@ -68,8 +71,6 @@ declare global {
68
71
  N3 extends keyof __VLS_GlobalComponents ? N3 extends N0 ? Pick<__VLS_GlobalComponents, N0 extends keyof __VLS_GlobalComponents ? N0 : never> : { [K in N0]: __VLS_GlobalComponents[N3] } :
69
72
  ${vueCompilerOptions.strictTemplates ? '{}' : '{ [K in N0]: unknown }'}
70
73
 
71
- type __VLS_FillingEventArg_ParametersLength<E extends (...args: any) => any> = __VLS_IsAny<Parameters<E>> extends true ? -1 : Parameters<E>['length'];
72
- type __VLS_FillingEventArg<E> = E extends (...args: any) => any ? __VLS_FillingEventArg_ParametersLength<E> extends 0 ? ($event?: undefined) => ReturnType<E> : E : E;
73
74
  function __VLS_asFunctionalComponent<T, K = T extends new (...args: any) => any ? InstanceType<T> : unknown>(t: T, instance?: K):
74
75
  T extends new (...args: any) => any
75
76
  ? (props: ${fnPropsType}, ctx?: any) => __VLS_Element & { __ctx?: {
@@ -82,12 +83,6 @@ declare global {
82
83
  : (_: {}${vueCompilerOptions.strictTemplates ? '' : ' & Record<string, unknown>'}, ctx?: any) => { __ctx?: { attrs?: any, expose?: any, slots?: any, emit?: any, props?: {}${vueCompilerOptions.strictTemplates ? '' : ' & Record<string, unknown>'} } };
83
84
  function __VLS_elementAsFunction<T>(tag: T, endTag?: T): (_: T${vueCompilerOptions.strictTemplates ? '' : ' & Record<string, unknown>'}) => void;
84
85
  function __VLS_functionalComponentArgsRest<T extends (...args: any) => any>(t: T): Parameters<T>['length'] extends 2 ? [any] : [];
85
- function __VLS_pickEvent<E1, E2>(emitEvent: E1, propEvent: E2): __VLS_FillingEventArg<
86
- __VLS_PickNotAny<
87
- __VLS_AsFunctionOrAny<E2>,
88
- __VLS_AsFunctionOrAny<E1>
89
- >
90
- > | undefined;
91
86
  function __VLS_pickFunctionalComponentCtx<T, K>(comp: T, compInstance: K): __VLS_PickNotAny<
92
87
  '__ctx' extends keyof __VLS_PickNotAny<K, {}> ? K extends { __ctx?: infer Ctx } ? Ctx : never : any
93
88
  , T extends (props: any, ctx: infer Ctx) => any ? Ctx : any
@@ -128,7 +123,8 @@ declare global {
128
123
  >;
129
124
  type __VLS_PrettifyGlobal<T> = { [K in keyof T]: T[K]; } & {};
130
125
  }
131
- export const __VLS_globalTypesEnd = {};`;
126
+ export const __VLS_globalTypesEnd = {};
127
+ `;
132
128
  }
133
129
  exports.generateGlobalTypes = generateGlobalTypes;
134
130
  ;
@@ -9,8 +9,7 @@ export declare const codeFeatures: {
9
9
  none: VueCodeInformation;
10
10
  verification: VueCodeInformation;
11
11
  navigation: VueCodeInformation;
12
- referencesCodeLens: VueCodeInformation;
13
- cssClassNavigation: VueCodeInformation;
12
+ navigationWithoutRename: VueCodeInformation;
14
13
  };
15
14
  export interface ScriptCodegenOptions {
16
15
  fileBaseName: string;
@@ -21,10 +20,8 @@ export interface ScriptCodegenOptions {
21
20
  lang: string;
22
21
  scriptRanges: ScriptRanges | undefined;
23
22
  scriptSetupRanges: ScriptSetupRanges | undefined;
24
- templateCodegen: {
25
- tsCodes: Code[];
26
- ctx: TemplateCodegenContext;
27
- hasSlot: boolean;
23
+ templateCodegen: TemplateCodegenContext & {
24
+ codes: Code[];
28
25
  } | undefined;
29
26
  globalTypes: boolean;
30
27
  getGeneratedLength: () => number;
@@ -21,14 +21,11 @@ exports.codeFeatures = {
21
21
  navigation: {
22
22
  navigation: true,
23
23
  },
24
- referencesCodeLens: {
25
- navigation: true,
26
- __referencesCodeLens: true,
27
- },
28
- cssClassNavigation: {
24
+ navigationWithoutRename: {
29
25
  navigation: {
30
- resolveRenameNewName: normalizeCssRename,
31
- resolveRenameEditText: applyCssRename,
26
+ shouldRename() {
27
+ return false;
28
+ },
32
29
  },
33
30
  },
34
31
  };
@@ -39,7 +36,7 @@ function* generateScript(options) {
39
36
  yield* (0, src_1.generateSrc)(options.sfc.script, options.sfc.script.src);
40
37
  }
41
38
  if (options.sfc.script && options.scriptRanges) {
42
- const { exportDefault } = options.scriptRanges;
39
+ const { exportDefault, classBlockEnd } = options.scriptRanges;
43
40
  const isExportRawObject = exportDefault
44
41
  && options.sfc.script.content[exportDefault.expression.start] === '{';
45
42
  if (options.sfc.scriptSetup && options.scriptSetupRanges) {
@@ -92,6 +89,11 @@ function* generateScript(options) {
92
89
  yield options.vueCompilerOptions.optionsWrapper[1];
93
90
  yield (0, common_1.generateSfcBlockSection)(options.sfc.script, exportDefault.expression.end, options.sfc.script.content.length, exports.codeFeatures.all);
94
91
  }
92
+ else if (classBlockEnd !== undefined) {
93
+ yield (0, common_1.generateSfcBlockSection)(options.sfc.script, 0, classBlockEnd, exports.codeFeatures.all);
94
+ yield* (0, template_1.generateTemplate)(options, ctx, true);
95
+ yield (0, common_1.generateSfcBlockSection)(options.sfc.script, classBlockEnd, options.sfc.script.content.length, exports.codeFeatures.all);
96
+ }
95
97
  else {
96
98
  yield (0, common_1.generateSfcBlockSection)(options.sfc.script, 0, options.sfc.script.content.length, exports.codeFeatures.all);
97
99
  }
@@ -100,13 +102,14 @@ function* generateScript(options) {
100
102
  yield (0, scriptSetup_1.generateScriptSetupImports)(options.sfc.scriptSetup, options.scriptSetupRanges);
101
103
  yield* (0, scriptSetup_1.generateScriptSetup)(options, ctx, options.sfc.scriptSetup, options.scriptSetupRanges);
102
104
  }
105
+ yield common_1.endOfLine;
103
106
  if (options.globalTypes) {
104
107
  yield (0, globalTypes_1.generateGlobalTypes)(options.vueCompilerOptions);
105
108
  }
106
109
  yield* ctx.generateHelperTypes();
107
110
  yield `\ntype __VLS_IntrinsicElementsCompletion = __VLS_IntrinsicElements${common_1.endOfLine}`;
108
111
  if (!ctx.generatedTemplate) {
109
- yield* (0, template_1.generateTemplate)(options, ctx);
112
+ yield* (0, template_1.generateTemplate)(options, ctx, false);
110
113
  }
111
114
  if (options.sfc.scriptSetup) {
112
115
  yield [
@@ -118,10 +121,4 @@ function* generateScript(options) {
118
121
  }
119
122
  }
120
123
  exports.generateScript = generateScript;
121
- function normalizeCssRename(newName) {
122
- return newName.startsWith('.') ? newName.slice(1) : newName;
123
- }
124
- function applyCssRename(newName) {
125
- return '.' + newName;
126
- }
127
124
  //# sourceMappingURL=index.js.map
@@ -22,7 +22,7 @@ function* generateInternalComponent(options, ctx, templateCodegenCtx) {
22
22
  ]) {
23
23
  for (const expose of bindings) {
24
24
  const varName = content.substring(expose.start, expose.end);
25
- if (!templateUsageVars.has(varName) && !templateCodegenCtx.accessGlobalVariables.has(varName)) {
25
+ if (!templateUsageVars.has(varName) && !templateCodegenCtx.accessExternalVariables.has(varName)) {
26
26
  continue;
27
27
  }
28
28
  const templateOffset = options.getGeneratedLength();
@@ -36,12 +36,16 @@ function* generateScriptSetup(options, ctx, scriptSetup, scriptSetupRanges) {
36
36
  + ` __VLS_expose?: NonNullable<Awaited<typeof __VLS_setup>>['expose'],${common_1.newLine}`
37
37
  + ` __VLS_setup = (async () => {${common_1.newLine}`;
38
38
  yield* generateSetupFunction(options, ctx, scriptSetup, scriptSetupRanges, undefined, definePropMirrors);
39
+ const emitTypes = ['typeof __VLS_modelEmitsType'];
40
+ if (scriptSetupRanges.emits.define) {
41
+ emitTypes.unshift(`typeof ${scriptSetupRanges.emits.name ?? '__VLS_emit'}`);
42
+ }
39
43
  yield ` return {} as {${common_1.newLine}`
40
44
  + ` props: ${ctx.helperTypes.Prettify.name}<typeof __VLS_functionalComponentProps & __VLS_PublicProps> & __VLS_BuiltInPublicProps,${common_1.newLine}`
41
45
  + ` expose(exposed: import('${options.vueCompilerOptions.lib}').ShallowUnwrapRef<${scriptSetupRanges.expose.define ? 'typeof __VLS_exposed' : '{}'}>): void,${common_1.newLine}`
42
46
  + ` attrs: any,${common_1.newLine}`
43
47
  + ` slots: ReturnType<typeof __VLS_template>,${common_1.newLine}`
44
- + ` emit: typeof ${scriptSetupRanges.emits.name ?? '__VLS_emit'} & typeof __VLS_modelEmitsType,${common_1.newLine}`
48
+ + ` emit: ${emitTypes.join(' & ')},${common_1.newLine}`
45
49
  + ` }${common_1.endOfLine}`;
46
50
  yield ` })(),${common_1.newLine}`; // __VLS_setup = (async () => {
47
51
  yield `) => ({} as import('${options.vueCompilerOptions.lib}').VNode & { __ctx?: Awaited<typeof __VLS_setup> }))`;
@@ -215,7 +219,7 @@ function* generateSetupFunction(options, ctx, scriptSetup, scriptSetupRanges, sy
215
219
  }
216
220
  yield* generateComponentProps(options, ctx, scriptSetup, scriptSetupRanges, definePropMirrors);
217
221
  yield* generateModelEmits(options, scriptSetup, scriptSetupRanges);
218
- yield* (0, template_1.generateTemplate)(options, ctx);
222
+ yield* (0, template_1.generateTemplate)(options, ctx, false);
219
223
  if (syntax) {
220
224
  if (!options.vueCompilerOptions.skipTemplateCodegen && (options.templateCodegen?.hasSlot || scriptSetupRanges?.slots.define)) {
221
225
  yield `const __VLS_component = `;
@@ -232,31 +236,25 @@ function* generateSetupFunction(options, ctx, scriptSetup, scriptSetupRanges, sy
232
236
  }
233
237
  }
234
238
  function* generateComponentProps(options, ctx, scriptSetup, scriptSetupRanges, definePropMirrors) {
235
- if (scriptSetupRanges.props.define?.arg || scriptSetupRanges.emits.define) {
236
- yield `const __VLS_fnComponent = `
237
- + `(await import('${options.vueCompilerOptions.lib}')).defineComponent({${common_1.newLine}`;
238
- if (scriptSetupRanges.props.define?.arg) {
239
- yield ` props: `;
240
- yield (0, common_1.generateSfcBlockSection)(scriptSetup, scriptSetupRanges.props.define.arg.start, scriptSetupRanges.props.define.arg.end, index_1.codeFeatures.navigation);
241
- yield `,${common_1.newLine}`;
242
- }
239
+ yield `const __VLS_fnComponent = `
240
+ + `(await import('${options.vueCompilerOptions.lib}')).defineComponent({${common_1.newLine}`;
241
+ if (scriptSetupRanges.props.define?.arg) {
242
+ yield ` props: `;
243
+ yield (0, common_1.generateSfcBlockSection)(scriptSetup, scriptSetupRanges.props.define.arg.start, scriptSetupRanges.props.define.arg.end, index_1.codeFeatures.navigation);
244
+ yield `,${common_1.newLine}`;
245
+ }
246
+ if (scriptSetupRanges.emits.define || scriptSetupRanges.defineProp.some(p => p.isModel)) {
247
+ yield ` emits: ({} as __VLS_NormalizeEmits<typeof __VLS_modelEmitsType`;
243
248
  if (scriptSetupRanges.emits.define) {
244
- yield ` emits: ({} as __VLS_NormalizeEmits<typeof `;
249
+ yield ` & typeof `;
245
250
  yield scriptSetupRanges.emits.name ?? '__VLS_emit';
246
- yield `>),${common_1.newLine}`;
247
251
  }
248
- yield `})${common_1.endOfLine}`;
249
- yield `let __VLS_functionalComponentProps!: `;
250
- yield `${ctx.helperTypes.OmitKeepDiscriminatedUnion.name}<InstanceType<typeof __VLS_fnComponent>['$props'], keyof __VLS_BuiltInPublicProps>`;
251
- yield common_1.endOfLine;
252
- }
253
- else {
254
- yield `let __VLS_functionalComponentProps!: {}${common_1.endOfLine}`;
252
+ yield `>),${common_1.newLine}`;
255
253
  }
256
- yield `type __VLS_BuiltInPublicProps =${common_1.newLine}`
257
- + ` import('${options.vueCompilerOptions.lib}').VNodeProps${common_1.newLine}`
258
- + ` & import('${options.vueCompilerOptions.lib}').AllowedComponentProps${common_1.newLine}`
259
- + ` & import('${options.vueCompilerOptions.lib}').ComponentCustomProps${common_1.endOfLine}`;
254
+ yield `})${common_1.endOfLine}`;
255
+ yield `let __VLS_functionalComponentProps!: `;
256
+ yield `${ctx.helperTypes.OmitKeepDiscriminatedUnion.name}<InstanceType<typeof __VLS_fnComponent>['$props'], keyof __VLS_BuiltInPublicProps>`;
257
+ yield common_1.endOfLine;
260
258
  if (scriptSetupRanges.defineProp.length) {
261
259
  yield `const __VLS_defaults = {${common_1.newLine}`;
262
260
  for (const defineProp of scriptSetupRanges.defineProp) {
@@ -1,5 +1,5 @@
1
1
  import type { Code } from '../../types';
2
2
  import type { ScriptCodegenContext } from './context';
3
3
  import { type ScriptCodegenOptions } from './index';
4
- export declare function generateTemplate(options: ScriptCodegenOptions, ctx: ScriptCodegenContext): Generator<Code>;
4
+ export declare function generateTemplate(options: ScriptCodegenOptions, ctx: ScriptCodegenContext, isClassComponent: boolean): Generator<Code>;
5
5
  export declare function getTemplateUsageVars(options: ScriptCodegenOptions, ctx: ScriptCodegenContext): Set<string>;
@@ -7,17 +7,22 @@ const context_1 = require("../template/context");
7
7
  const interpolation_1 = require("../template/interpolation");
8
8
  const index_1 = require("./index");
9
9
  const internalComponent_1 = require("./internalComponent");
10
- const common_2 = require("../common");
11
- function* generateTemplate(options, ctx) {
10
+ function* generateTemplate(options, ctx, isClassComponent) {
12
11
  ctx.generatedTemplate = true;
13
12
  if (!options.vueCompilerOptions.skipTemplateCodegen) {
13
+ if (isClassComponent) {
14
+ yield `__VLS_template() {${common_1.newLine}`;
15
+ }
16
+ else {
17
+ yield `function __VLS_template() {${common_1.newLine}`;
18
+ }
19
+ const templateCodegenCtx = (0, context_1.createTemplateCodegenContext)(new Set());
20
+ yield* generateCtx(options, ctx, isClassComponent);
21
+ yield* generateTemplateContext(options, templateCodegenCtx);
14
22
  yield* generateExportOptions(options);
15
23
  yield* generateConstNameOption(options);
16
- yield `function __VLS_template() {${common_1.newLine}`;
17
- const templateCodegenCtx = (0, context_1.createTemplateCodegenContext)();
18
- yield* generateTemplateContext(options, ctx, templateCodegenCtx);
19
- yield `}${common_1.newLine}`;
20
24
  yield* (0, internalComponent_1.generateInternalComponent)(options, ctx, templateCodegenCtx);
25
+ yield `}${common_1.newLine}`;
21
26
  }
22
27
  else {
23
28
  yield `function __VLS_template() {${common_1.newLine}`;
@@ -47,7 +52,6 @@ function* generateExportOptions(options) {
47
52
  yield common_1.endOfLine;
48
53
  }
49
54
  function* generateConstNameOption(options) {
50
- yield common_1.newLine;
51
55
  if (options.sfc.script && options.scriptRanges?.exportDefault?.nameOption) {
52
56
  const nameOption = options.scriptRanges.exportDefault.nameOption;
53
57
  yield `const __VLS_name = `;
@@ -55,28 +59,41 @@ function* generateConstNameOption(options) {
55
59
  yield common_1.endOfLine;
56
60
  }
57
61
  else if (options.sfc.scriptSetup) {
58
- yield `let __VLS_name!: '${options.fileBaseName.substring(0, options.fileBaseName.lastIndexOf('.'))}'${common_1.endOfLine}`;
62
+ yield `let __VLS_name!: '${options.scriptSetupRanges?.options.name ?? options.fileBaseName.substring(0, options.fileBaseName.lastIndexOf('.'))}'${common_1.endOfLine}`;
59
63
  }
60
64
  else {
61
65
  yield `const __VLS_name = undefined${common_1.endOfLine}`;
62
66
  }
63
67
  }
64
- function* generateTemplateContext(options, ctx, templateCodegenCtx) {
65
- const useGlobalThisTypeInCtx = options.fileBaseName.endsWith('.html');
66
- yield `let __VLS_ctx!: ${useGlobalThisTypeInCtx ? 'typeof globalThis &' : ''}`;
67
- yield `InstanceType<__VLS_PickNotAny<typeof __VLS_internalComponent, new () => {}>> & {${common_1.newLine}`;
68
+ function* generateCtx(options, ctx, isClassComponent) {
69
+ yield `let __VLS_ctx!: `;
70
+ if (options.vueCompilerOptions.petiteVueExtensions.some(ext => options.fileBaseName.endsWith(ext))) {
71
+ yield `typeof globalThis & `;
72
+ }
73
+ if (!isClassComponent) {
74
+ yield `InstanceType<__VLS_PickNotAny<typeof __VLS_internalComponent, new () => {}>>`;
75
+ }
76
+ else {
77
+ yield `typeof this`;
78
+ }
68
79
  /* CSS Module */
69
- for (let i = 0; i < options.sfc.styles.length; i++) {
70
- const style = options.sfc.styles[i];
71
- if (style.module) {
72
- yield `${style.module}: Record<string, string> & ${ctx.helperTypes.Prettify.name}<{}`;
73
- for (const className of style.classNames) {
74
- yield* generateCssClassProperty(i, className.text, className.offset, 'string', false, true);
80
+ if (options.sfc.styles.some(style => style.module)) {
81
+ yield `& {${common_1.newLine}`;
82
+ for (let i = 0; i < options.sfc.styles.length; i++) {
83
+ const style = options.sfc.styles[i];
84
+ if (style.module) {
85
+ yield `${style.module}: Record<string, string> & ${ctx.helperTypes.Prettify.name}<{}`;
86
+ for (const className of style.classNames) {
87
+ yield* generateCssClassProperty(i, className.text, className.offset, 'string', false);
88
+ }
89
+ yield `>${common_1.endOfLine}`;
75
90
  }
76
- yield `>${common_1.endOfLine}`;
77
91
  }
92
+ yield `}`;
78
93
  }
79
- yield `}${common_1.endOfLine}`;
94
+ yield common_1.endOfLine;
95
+ }
96
+ function* generateTemplateContext(options, templateCodegenCtx) {
80
97
  /* Components */
81
98
  yield `/* Components */${common_1.newLine}`;
82
99
  yield `let __VLS_otherComponents!: NonNullable<typeof __VLS_internalComponent extends { components: infer C } ? C : {}> & typeof __VLS_componentsOption${common_1.endOfLine}`;
@@ -91,7 +108,7 @@ function* generateTemplateContext(options, ctx, templateCodegenCtx) {
91
108
  const option = options.vueCompilerOptions.experimentalResolveStyleCssClasses;
92
109
  if (option === 'always' || (option === 'scoped' && style.scoped)) {
93
110
  for (const className of style.classNames) {
94
- yield* generateCssClassProperty(i, className.text, className.offset, 'boolean', true, !style.module);
111
+ yield* generateCssClassProperty(i, className.text, className.offset, 'boolean', true);
95
112
  }
96
113
  }
97
114
  }
@@ -99,7 +116,7 @@ function* generateTemplateContext(options, ctx, templateCodegenCtx) {
99
116
  yield `let __VLS_styleScopedClasses!: __VLS_StyleScopedClasses | keyof __VLS_StyleScopedClasses | (keyof __VLS_StyleScopedClasses)[]${common_1.endOfLine}`;
100
117
  yield* generateCssVars(options, templateCodegenCtx);
101
118
  if (options.templateCodegen) {
102
- for (const code of options.templateCodegen.tsCodes) {
119
+ for (const code of options.templateCodegen.codes) {
103
120
  yield code;
104
121
  }
105
122
  }
@@ -111,35 +128,27 @@ function* generateTemplateContext(options, ctx, templateCodegenCtx) {
111
128
  }
112
129
  yield `return ${options.scriptSetupRanges?.slots.name ?? '__VLS_slots'}${common_1.endOfLine}`;
113
130
  }
114
- function* generateCssClassProperty(styleIndex, classNameWithDot, offset, propertyType, optional, referencesCodeLens) {
131
+ function* generateCssClassProperty(styleIndex, classNameWithDot, offset, propertyType, optional) {
115
132
  yield `${common_1.newLine} & { `;
116
133
  yield [
117
134
  '',
118
135
  'style_' + styleIndex,
119
136
  offset,
120
- referencesCodeLens
121
- ? index_1.codeFeatures.navigation
122
- : index_1.codeFeatures.referencesCodeLens,
137
+ index_1.codeFeatures.navigationWithoutRename,
123
138
  ];
124
139
  yield `'`;
125
- yield [
126
- '',
127
- 'style_' + styleIndex,
128
- offset,
129
- index_1.codeFeatures.cssClassNavigation,
130
- ];
131
140
  yield [
132
141
  classNameWithDot.substring(1),
133
142
  'style_' + styleIndex,
134
143
  offset + 1,
135
- common_2.combineLastMapping,
144
+ index_1.codeFeatures.navigation,
136
145
  ];
137
146
  yield `'`;
138
147
  yield [
139
148
  '',
140
149
  'style_' + styleIndex,
141
150
  offset + classNameWithDot.length,
142
- index_1.codeFeatures.none,
151
+ index_1.codeFeatures.navigationWithoutRename,
143
152
  ];
144
153
  yield `${optional ? '?' : ''}: ${propertyType}`;
145
154
  yield ` }`;
@@ -151,7 +160,7 @@ function* generateCssVars(options, ctx) {
151
160
  yield `// CSS variable injection ${common_1.newLine}`;
152
161
  for (const style of options.sfc.styles) {
153
162
  for (const cssBind of style.cssVars) {
154
- for (const [segment, offset, onlyError] of (0, interpolation_1.forEachInterpolationSegment)(options.ts, options.vueCompilerOptions, ctx, cssBind.text, cssBind.offset, options.ts.createSourceFile('/a.txt', cssBind.text, 99))) {
163
+ for (const [segment, offset, onlyError] of (0, interpolation_1.forEachInterpolationSegment)(options.ts, ctx, cssBind.text, cssBind.offset, options.ts.createSourceFile('/a.txt', cssBind.text, 99))) {
155
164
  if (offset === undefined) {
156
165
  yield segment;
157
166
  }
@@ -186,7 +195,7 @@ function getTemplateUsageVars(options, ctx) {
186
195
  usageVars.add(component.split('.')[0]);
187
196
  }
188
197
  }
189
- for (const [varName] of options.templateCodegen.ctx.accessGlobalVariables) {
198
+ for (const [varName] of options.templateCodegen.accessExternalVariables) {
190
199
  usageVars.add(varName);
191
200
  }
192
201
  }
@@ -1,7 +1,8 @@
1
1
  import type * as CompilerDOM from '@vue/compiler-dom';
2
2
  import type { Code, VueCodeInformation } from '../../types';
3
+ import type { TemplateCodegenOptions } from './index';
3
4
  export type TemplateCodegenContext = ReturnType<typeof createTemplateCodegenContext>;
4
- export declare function createTemplateCodegenContext(): {
5
+ export declare function createTemplateCodegenContext(scriptSetupBindingNames: TemplateCodegenOptions['scriptSetupBindingNames']): {
5
6
  slots: {
6
7
  name: string;
7
8
  loc?: number | undefined;
@@ -19,12 +20,14 @@ export declare function createTemplateCodegenContext(): {
19
20
  completion: VueCodeInformation;
20
21
  additionalCompletion: VueCodeInformation;
21
22
  navigation: VueCodeInformation;
23
+ navigationWithoutRename: VueCodeInformation;
22
24
  navigationAndCompletion: VueCodeInformation;
25
+ navigationAndAdditionalCompletion: VueCodeInformation;
23
26
  withoutHighlight: VueCodeInformation;
24
27
  withoutHighlightAndCompletion: VueCodeInformation;
25
28
  withoutHighlightAndCompletionAndNavigation: VueCodeInformation;
26
29
  };
27
- accessGlobalVariables: Map<string, Set<number>>;
30
+ accessExternalVariables: Map<string, Set<number>>;
28
31
  hasSlotElements: Set<CompilerDOM.ElementNode>;
29
32
  blockConditions: string[];
30
33
  usedComponentCtxVars: Set<string>;
@@ -32,7 +35,9 @@ export declare function createTemplateCodegenContext(): {
32
35
  className: string;
33
36
  offset: number;
34
37
  }[];
35
- accessGlobalVariable(name: string, offset?: number): void;
38
+ emptyClassOffsets: number[];
39
+ hasSlot: boolean;
40
+ accessExternalVariable(name: string, offset?: number): void;
36
41
  hasLocalVariable: (name: string) => boolean;
37
42
  addLocalVariable: (name: string) => void;
38
43
  removeLocalVariable: (name: string) => void;
@@ -21,8 +21,20 @@ const _codeFeatures = {
21
21
  navigation: {
22
22
  navigation: true,
23
23
  },
24
+ navigationWithoutRename: {
25
+ navigation: {
26
+ shouldRename() {
27
+ return false;
28
+ },
29
+ },
30
+ },
24
31
  navigationAndCompletion: {
25
32
  navigation: true,
33
+ completion: true,
34
+ },
35
+ navigationAndAdditionalCompletion: {
36
+ navigation: true,
37
+ completion: { isAdditional: true },
26
38
  },
27
39
  withoutHighlight: {
28
40
  semantic: { shouldHighlight: () => false },
@@ -40,7 +52,7 @@ const _codeFeatures = {
40
52
  verification: true,
41
53
  },
42
54
  };
43
- function createTemplateCodegenContext() {
55
+ function createTemplateCodegenContext(scriptSetupBindingNames) {
44
56
  let ignoredError = false;
45
57
  let expectErrorToken;
46
58
  let variableId = 0;
@@ -73,7 +85,7 @@ function createTemplateCodegenContext() {
73
85
  },
74
86
  });
75
87
  const localVars = new Map();
76
- const accessGlobalVariables = new Map();
88
+ const accessExternalVariables = new Map();
77
89
  const slots = [];
78
90
  const dynamicSlots = [];
79
91
  const hasSlotElements = new Set();
@@ -81,19 +93,22 @@ function createTemplateCodegenContext() {
81
93
  const blockConditions = [];
82
94
  const usedComponentCtxVars = new Set();
83
95
  const scopedClasses = [];
96
+ const emptyClassOffsets = [];
84
97
  return {
85
98
  slots,
86
99
  dynamicSlots,
87
100
  codeFeatures,
88
- accessGlobalVariables,
101
+ accessExternalVariables,
89
102
  hasSlotElements,
90
103
  blockConditions,
91
104
  usedComponentCtxVars,
92
105
  scopedClasses,
93
- accessGlobalVariable(name, offset) {
94
- let arr = accessGlobalVariables.get(name);
106
+ emptyClassOffsets,
107
+ hasSlot: false,
108
+ accessExternalVariable(name, offset) {
109
+ let arr = accessExternalVariables.get(name);
95
110
  if (!arr) {
96
- accessGlobalVariables.set(name, arr = new Set());
111
+ accessExternalVariables.set(name, arr = new Set());
97
112
  }
98
113
  if (offset !== undefined) {
99
114
  arr.add(offset);
@@ -144,7 +159,7 @@ function createTemplateCodegenContext() {
144
159
  }
145
160
  },
146
161
  generateAutoImportCompletion: function* () {
147
- const all = [...accessGlobalVariables.entries()];
162
+ const all = [...accessExternalVariables.entries()];
148
163
  if (!all.some(([_, offsets]) => offsets.size)) {
149
164
  return;
150
165
  }
@@ -152,12 +167,26 @@ function createTemplateCodegenContext() {
152
167
  yield `[`;
153
168
  for (const [varName, offsets] of all) {
154
169
  for (const offset of offsets) {
155
- yield [
156
- varName,
157
- 'template',
158
- offset,
159
- codeFeatures.additionalCompletion,
160
- ];
170
+ if (scriptSetupBindingNames.has(varName)) {
171
+ // #3409
172
+ yield [
173
+ varName,
174
+ 'template',
175
+ offset,
176
+ {
177
+ ...codeFeatures.additionalCompletion,
178
+ ...codeFeatures.withoutHighlightAndCompletionAndNavigation,
179
+ },
180
+ ];
181
+ }
182
+ else {
183
+ yield [
184
+ varName,
185
+ 'template',
186
+ offset,
187
+ codeFeatures.additionalCompletion,
188
+ ];
189
+ }
161
190
  yield `,`;
162
191
  }
163
192
  offsets.clear();