@vue/language-core 2.0.15 → 2.0.17

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 (37) hide show
  1. package/lib/codegen/script/component.js +2 -2
  2. package/lib/codegen/script/globalTypes.js +3 -3
  3. package/lib/codegen/script/index.d.ts +3 -6
  4. package/lib/codegen/script/index.js +12 -15
  5. package/lib/codegen/script/internalComponent.js +1 -1
  6. package/lib/codegen/script/scriptSetup.js +25 -23
  7. package/lib/codegen/script/template.d.ts +1 -1
  8. package/lib/codegen/script/template.js +45 -36
  9. package/lib/codegen/template/context.d.ts +8 -3
  10. package/lib/codegen/template/context.js +42 -13
  11. package/lib/codegen/template/element.js +81 -49
  12. package/lib/codegen/template/elementChildren.js +2 -1
  13. package/lib/codegen/template/elementDirectives.js +1 -1
  14. package/lib/codegen/template/elementEvents.d.ts +2 -2
  15. package/lib/codegen/template/elementEvents.js +16 -7
  16. package/lib/codegen/template/elementProps.js +18 -14
  17. package/lib/codegen/template/index.d.ts +4 -46
  18. package/lib/codegen/template/index.js +36 -21
  19. package/lib/codegen/template/interpolation.d.ts +2 -2
  20. package/lib/codegen/template/interpolation.js +12 -46
  21. package/lib/codegen/template/slotOutlet.js +29 -30
  22. package/lib/languageModule.d.ts +1 -1
  23. package/lib/languageModule.js +4 -4
  24. package/lib/parsers/scriptRanges.d.ts +1 -0
  25. package/lib/parsers/scriptRanges.js +7 -0
  26. package/lib/parsers/scriptSetupRanges.d.ts +4 -0
  27. package/lib/parsers/scriptSetupRanges.js +24 -0
  28. package/lib/plugins/vue-template-inline-ts.js +1 -1
  29. package/lib/plugins/vue-tsx.d.ts +46 -40
  30. package/lib/plugins/vue-tsx.js +34 -28
  31. package/lib/plugins.d.ts +1 -1
  32. package/lib/types.d.ts +1 -15
  33. package/lib/utils/parseCssClassNames.js +1 -1
  34. package/lib/utils/ts.js +0 -1
  35. package/lib/virtualFile/computedFiles.js +34 -33
  36. package/lib/virtualFile/computedSfc.js +0 -3
  37. package/package.json +3 -3
@@ -98,10 +98,10 @@ function* generateScriptSetupOptions(options, ctx, scriptSetup, scriptSetupRange
98
98
  if (options.vueCompilerOptions.target >= 3.5) {
99
99
  // https://github.com/vuejs/core/pull/10801
100
100
  if (scriptSetupRanges.props.define?.typeArg) {
101
- yield `__typeProps: typeof __VLS_typeProps,${common_1.newLine}`;
101
+ yield `__typeProps: __VLS_typeProps,${common_1.newLine}`;
102
102
  }
103
103
  if (scriptSetupRanges.emits.define?.typeArg) {
104
- yield `__typeEmits: typeof ${scriptSetupRanges.emits.name ?? '__VLS_emit'},${common_1.newLine}`;
104
+ yield `__typeEmits: ${scriptSetupRanges.emits.name ?? '__VLS_emit'},${common_1.newLine}`;
105
105
  }
106
106
  }
107
107
  }
@@ -4,8 +4,7 @@ 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
10
  type __VLS_IntrinsicElements = __VLS_PickNotAny<import('vue/jsx-runtime').JSX.IntrinsicElements, __VLS_PickNotAny<globalThis.JSX.IntrinsicElements, Record<string, any>>>;
@@ -128,7 +127,8 @@ declare global {
128
127
  >;
129
128
  type __VLS_PrettifyGlobal<T> = { [K in keyof T]: T[K]; } & {};
130
129
  }
131
- export const __VLS_globalTypesEnd = {};`;
130
+ export const __VLS_globalTypesEnd = {};
131
+ `;
132
132
  }
133
133
  exports.generateGlobalTypes = generateGlobalTypes;
134
134
  ;
@@ -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> }))`;
@@ -142,16 +146,16 @@ function* generateSetupFunction(options, ctx, scriptSetup, scriptSetupRanges, sy
142
146
  }
143
147
  }
144
148
  if (scriptSetupRanges.slots.define) {
145
- if (!scriptSetupRanges.slots.name) {
146
- setupCodeModifies.push([[`const __VLS_slots = `], scriptSetupRanges.slots.define.start, scriptSetupRanges.slots.define.start]);
147
- }
148
- else if (scriptSetupRanges.slots.isObjectBindingPattern) {
149
+ if (scriptSetupRanges.slots.isObjectBindingPattern) {
149
150
  setupCodeModifies.push([
150
151
  [`__VLS_slots;\nconst __VLS_slots = `],
151
152
  scriptSetupRanges.slots.define.start,
152
153
  scriptSetupRanges.slots.define.start,
153
154
  ]);
154
155
  }
156
+ else if (!scriptSetupRanges.slots.name) {
157
+ setupCodeModifies.push([[`const __VLS_slots = `], scriptSetupRanges.slots.define.start, scriptSetupRanges.slots.define.start]);
158
+ }
155
159
  }
156
160
  if (scriptSetupRanges.emits.define && !scriptSetupRanges.emits.name) {
157
161
  setupCodeModifies.push([[`const __VLS_emit = `], scriptSetupRanges.emits.define.start, scriptSetupRanges.emits.define.start]);
@@ -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,27 +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
  }
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;
256
258
  yield `type __VLS_BuiltInPublicProps =${common_1.newLine}`
257
259
  + ` import('${options.vueCompilerOptions.lib}').VNodeProps${common_1.newLine}`
258
260
  + ` & import('${options.vueCompilerOptions.lib}').AllowedComponentProps${common_1.newLine}`
@@ -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();