@vue/language-core 1.8.19 → 1.8.21

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.
@@ -6,7 +6,8 @@ import type { ScriptRanges } from '../parsers/scriptRanges';
6
6
  import type { ScriptSetupRanges } from '../parsers/scriptSetupRanges';
7
7
  import type { VueCompilerOptions } from '../types';
8
8
  import { Sfc } from '../types';
9
- export declare function generate(ts: typeof import('typescript/lib/tsserverlibrary'), fileName: string, _sfc: Sfc, lang: string, scriptRanges: ScriptRanges | undefined, scriptSetupRanges: ScriptSetupRanges | undefined, htmlGen: ReturnType<typeof templateGen['generate']> | undefined, compilerOptions: ts.CompilerOptions, vueCompilerOptions: VueCompilerOptions, codegenStack: boolean): {
9
+ export declare function generate(ts: typeof import('typescript/lib/tsserverlibrary'), fileName: string, script: Sfc['script'], scriptSetup: Sfc['scriptSetup'], styles: Sfc['styles'], // TODO: computed it
10
+ lang: string, scriptRanges: ScriptRanges | undefined, scriptSetupRanges: ScriptSetupRanges | undefined, htmlGen: ReturnType<typeof templateGen['generate']> | undefined, compilerOptions: ts.CompilerOptions, vueCompilerOptions: VueCompilerOptions, codegenStack: boolean): {
10
11
  codes: SourceMaps.Segment<FileRangeCapabilities>[];
11
12
  codeStacks: SourceMaps.StackNode[];
12
13
  mirrorBehaviorMappings: SourceMaps.Mapping<[MirrorBehaviorCapabilities, MirrorBehaviorCapabilities]>[];
@@ -1,45 +1,19 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
2
  Object.defineProperty(exports, "__esModule", { value: true });
26
3
  exports.generate = void 0;
27
4
  const language_core_1 = require("@volar/language-core");
28
5
  const source_map_1 = require("@volar/source-map");
29
- const muggle = __importStar(require("muggle-string"));
6
+ const muggle = require("muggle-string");
30
7
  const path_1 = require("path");
31
8
  const shared_1 = require("../utils/shared");
32
9
  const transform_1 = require("../utils/transform");
33
- function generate(ts, fileName, _sfc, lang, scriptRanges, scriptSetupRanges, htmlGen, compilerOptions, vueCompilerOptions, codegenStack) {
10
+ function generate(ts, fileName, script, scriptSetup, styles, // TODO: computed it
11
+ lang, scriptRanges, scriptSetupRanges, htmlGen, compilerOptions, vueCompilerOptions, codegenStack) {
34
12
  const [codes, codeStacks] = codegenStack ? muggle.track([]) : [[], []];
35
13
  const mirrorBehaviorMappings = [];
36
14
  //#region monkey fix: https://github.com/vuejs/language-tools/pull/2113
37
- const sfc = {
38
- script: _sfc.script,
39
- scriptSetup: _sfc.scriptSetup,
40
- };
41
- if (!sfc.script && !sfc.scriptSetup) {
42
- sfc.scriptSetup = {
15
+ if (!script && !scriptSetup) {
16
+ scriptSetup = {
43
17
  content: '',
44
18
  lang: 'ts',
45
19
  name: '',
@@ -50,6 +24,7 @@ function generate(ts, fileName, _sfc, lang, scriptRanges, scriptSetupRanges, htm
50
24
  generic: undefined,
51
25
  genericOffset: 0,
52
26
  attrs: {},
27
+ ast: ts.createSourceFile('', '', ts.ScriptTarget.Latest, false, ts.ScriptKind.TS),
53
28
  };
54
29
  scriptSetupRanges = {
55
30
  bindings: [],
@@ -64,8 +39,8 @@ function generate(ts, fileName, _sfc, lang, scriptRanges, scriptSetupRanges, htm
64
39
  }
65
40
  //#endregion
66
41
  const bindingNames = new Set([
67
- ...scriptRanges?.bindings.map(range => sfc.script.content.substring(range.start, range.end)) ?? [],
68
- ...scriptSetupRanges?.bindings.map(range => sfc.scriptSetup.content.substring(range.start, range.end)) ?? [],
42
+ ...scriptRanges?.bindings.map(range => script.content.substring(range.start, range.end)) ?? [],
43
+ ...scriptSetupRanges?.bindings.map(range => scriptSetup.content.substring(range.start, range.end)) ?? [],
69
44
  ]);
70
45
  const bypassDefineComponent = lang === 'js' || lang === 'jsx';
71
46
  const usedHelperTypes = {
@@ -85,12 +60,12 @@ function generate(ts, fileName, _sfc, lang, scriptRanges, scriptSetupRanges, htm
85
60
  if (!generatedTemplate) {
86
61
  generateTemplate(false);
87
62
  }
88
- if (sfc.scriptSetup) {
63
+ if (scriptSetup) {
89
64
  // for code action edits
90
65
  codes.push([
91
66
  '',
92
67
  'scriptSetup',
93
- sfc.scriptSetup.content.length,
68
+ scriptSetup.content.length,
94
69
  {},
95
70
  ]);
96
71
  }
@@ -118,7 +93,7 @@ function generate(ts, fileName, _sfc, lang, scriptRanges, scriptSetupRanges, htm
118
93
  };\n`);
119
94
  }
120
95
  if (usedHelperTypes.WithTemplateSlots) {
121
- codes.push(`type __VLS_WithTemplateSlots<T, S> = T & { new(): {\n`, `$slots: S;\n`);
96
+ codes.push(`type __VLS_WithTemplateSlots<T, S> = T & { new(): {\n`, `${(0, shared_1.getSlotsPropertyName)(vueCompilerOptions.target)}: S;\n`);
122
97
  if (vueCompilerOptions.jsxSlots) {
123
98
  usedHelperTypes.PropsChildren = true;
124
99
  codes.push(`$props: __VLS_PropsChildren<S>;\n`);
@@ -130,9 +105,9 @@ function generate(ts, fileName, _sfc, lang, scriptRanges, scriptSetupRanges, htm
130
105
  }
131
106
  }
132
107
  function generateSrc() {
133
- if (!sfc.script?.src)
108
+ if (!script?.src)
134
109
  return;
135
- let src = sfc.script.src;
110
+ let src = script.src;
136
111
  if (src.endsWith('.d.ts'))
137
112
  src = src.substring(0, src.length - '.d.ts'.length);
138
113
  else if (src.endsWith('.ts'))
@@ -145,23 +120,23 @@ function generate(ts, fileName, _sfc, lang, scriptRanges, scriptSetupRanges, htm
145
120
  codes.push([
146
121
  `'${src}'`,
147
122
  'script',
148
- [sfc.script.srcOffset - 1, sfc.script.srcOffset + sfc.script.src.length + 1],
123
+ [script.srcOffset - 1, script.srcOffset + script.src.length + 1],
149
124
  {
150
125
  ...language_core_1.FileRangeCapabilities.full,
151
- rename: src === sfc.script.src ? true : {
126
+ rename: src === script.src ? true : {
152
127
  normalize: undefined,
153
128
  apply(newName) {
154
129
  if (newName.endsWith('.jsx')
155
130
  || newName.endsWith('.js')) {
156
131
  newName = newName.split('.').slice(0, -1).join('.');
157
132
  }
158
- if (sfc.script?.src?.endsWith('.d.ts')) {
133
+ if (script?.src?.endsWith('.d.ts')) {
159
134
  newName = newName + '.d.ts';
160
135
  }
161
- else if (sfc.script?.src?.endsWith('.ts')) {
136
+ else if (script?.src?.endsWith('.ts')) {
162
137
  newName = newName + '.ts';
163
138
  }
164
- else if (sfc.script?.src?.endsWith('.tsx')) {
139
+ else if (script?.src?.endsWith('.tsx')) {
165
140
  newName = newName + '.tsx';
166
141
  }
167
142
  return newName;
@@ -173,15 +148,15 @@ function generate(ts, fileName, _sfc, lang, scriptRanges, scriptSetupRanges, htm
173
148
  codes.push(`export { default } from '${src}';\n`);
174
149
  }
175
150
  function generateScriptContentBeforeExportDefault() {
176
- if (!sfc.script)
151
+ if (!script)
177
152
  return;
178
- if (!!sfc.scriptSetup && scriptRanges?.exportDefault) {
153
+ if (!!scriptSetup && scriptRanges?.exportDefault) {
179
154
  addVirtualCode('script', 0, scriptRanges.exportDefault.expression.start);
180
155
  }
181
156
  else {
182
157
  let isExportRawObject = false;
183
158
  if (scriptRanges?.exportDefault) {
184
- isExportRawObject = sfc.script.content.substring(scriptRanges.exportDefault.expression.start, scriptRanges.exportDefault.expression.end).startsWith('{');
159
+ isExportRawObject = script.content.substring(scriptRanges.exportDefault.expression.start, scriptRanges.exportDefault.expression.end).startsWith('{');
185
160
  }
186
161
  if (isExportRawObject && vueCompilerOptions.optionsWrapper.length === 2 && scriptRanges?.exportDefault) {
187
162
  addVirtualCode('script', 0, scriptRanges.exportDefault.expression.start);
@@ -207,63 +182,63 @@ function generate(ts, fileName, _sfc, lang, scriptRanges, scriptSetupRanges, htm
207
182
  }]);
208
183
  }
209
184
  codes.push(vueCompilerOptions.optionsWrapper[1]);
210
- addVirtualCode('script', scriptRanges.exportDefault.expression.end, sfc.script.content.length);
185
+ addVirtualCode('script', scriptRanges.exportDefault.expression.end, script.content.length);
211
186
  }
212
187
  else {
213
- addVirtualCode('script', 0, sfc.script.content.length);
188
+ addVirtualCode('script', 0, script.content.length);
214
189
  }
215
190
  }
216
191
  }
217
192
  function generateScriptContentAfterExportDefault() {
218
- if (!sfc.script)
193
+ if (!script)
219
194
  return;
220
- if (!!sfc.scriptSetup && scriptRanges?.exportDefault) {
221
- addVirtualCode('script', scriptRanges.exportDefault.end, sfc.script.content.length);
195
+ if (!!scriptSetup && scriptRanges?.exportDefault) {
196
+ addVirtualCode('script', scriptRanges.exportDefault.end, script.content.length);
222
197
  }
223
198
  }
224
199
  function generateScriptSetupImports() {
225
- if (!sfc.scriptSetup)
200
+ if (!scriptSetup)
226
201
  return;
227
202
  if (!scriptSetupRanges)
228
203
  return;
229
204
  codes.push([
230
- sfc.scriptSetup.content.substring(0, Math.max(scriptSetupRanges.importSectionEndOffset, scriptSetupRanges.leadingCommentEndOffset)) + '\n',
205
+ scriptSetup.content.substring(0, Math.max(scriptSetupRanges.importSectionEndOffset, scriptSetupRanges.leadingCommentEndOffset)) + '\n',
231
206
  'scriptSetup',
232
207
  0,
233
208
  language_core_1.FileRangeCapabilities.full,
234
209
  ]);
235
210
  }
236
211
  function generateExportDefaultEndMapping() {
237
- if (!sfc.scriptSetup) {
212
+ if (!scriptSetup) {
238
213
  return;
239
214
  }
240
215
  // fix https://github.com/vuejs/language-tools/issues/1127
241
216
  codes.push([
242
217
  '',
243
218
  'scriptSetup',
244
- sfc.scriptSetup.content.length,
219
+ scriptSetup.content.length,
245
220
  { diagnostic: true },
246
221
  ]);
247
222
  codes.push(`\n`);
248
223
  }
249
224
  function generateScriptSetupAndTemplate() {
250
- if (!sfc.scriptSetup || !scriptSetupRanges) {
225
+ if (!scriptSetup || !scriptSetupRanges) {
251
226
  return;
252
227
  }
253
228
  const definePropMirrors = {};
254
229
  let scriptSetupGeneratedOffset;
255
- if (sfc.scriptSetup.generic) {
230
+ if (scriptSetup.generic) {
256
231
  if (!scriptRanges?.exportDefault) {
257
232
  codes.push('export default ');
258
233
  }
259
234
  codes.push(`(<`);
260
235
  codes.push([
261
- sfc.scriptSetup.generic,
262
- sfc.scriptSetup.name,
263
- sfc.scriptSetup.genericOffset,
236
+ scriptSetup.generic,
237
+ scriptSetup.name,
238
+ scriptSetup.genericOffset,
264
239
  language_core_1.FileRangeCapabilities.full,
265
240
  ]);
266
- if (!sfc.scriptSetup.generic.endsWith(',')) {
241
+ if (!scriptSetup.generic.endsWith(',')) {
267
242
  codes.push(`,`);
268
243
  }
269
244
  codes.push(`>`);
@@ -290,13 +265,13 @@ function generate(ts, fileName, _sfc, lang, scriptRanges, scriptSetupRanges, htm
290
265
  for (const defineProp of scriptSetupRanges.defineProp) {
291
266
  if (defineProp.defaultValue) {
292
267
  if (defineProp.name) {
293
- codes.push(sfc.scriptSetup.content.substring(defineProp.name.start, defineProp.name.end));
268
+ codes.push(scriptSetup.content.substring(defineProp.name.start, defineProp.name.end));
294
269
  }
295
270
  else {
296
271
  codes.push('modelValue');
297
272
  }
298
273
  codes.push(`: `);
299
- codes.push(sfc.scriptSetup.content.substring(defineProp.defaultValue.start, defineProp.defaultValue.end));
274
+ codes.push(scriptSetup.content.substring(defineProp.defaultValue.start, defineProp.defaultValue.end));
300
275
  codes.push(`,\n`);
301
276
  }
302
277
  }
@@ -312,13 +287,13 @@ function generate(ts, fileName, _sfc, lang, scriptRanges, scriptSetupRanges, htm
312
287
  for (const defineProp of scriptSetupRanges.defineProp) {
313
288
  let propName = 'modelValue';
314
289
  if (defineProp.name) {
315
- propName = sfc.scriptSetup.content.substring(defineProp.name.start, defineProp.name.end);
290
+ propName = scriptSetup.content.substring(defineProp.name.start, defineProp.name.end);
316
291
  const propMirrorStart = muggle.getLength(codes);
317
292
  definePropMirrors[propName] = [propMirrorStart, propMirrorStart + propName.length];
318
293
  }
319
294
  codes.push(`${propName}${defineProp.required ? '' : '?'}: `);
320
295
  if (defineProp.type) {
321
- codes.push(sfc.scriptSetup.content.substring(defineProp.type.start, defineProp.type.end));
296
+ codes.push(scriptSetup.content.substring(defineProp.type.start, defineProp.type.end));
322
297
  }
323
298
  else if (defineProp.defaultValue) {
324
299
  codes.push(`typeof __VLS_defaults['`);
@@ -347,7 +322,7 @@ function generate(ts, fileName, _sfc, lang, scriptRanges, scriptSetupRanges, htm
347
322
  codes.push(`let __VLS_defaultProps!: `, `import('${vueCompilerOptions.lib}').VNodeProps`, `& import('${vueCompilerOptions.lib}').AllowedComponentProps`, `& import('${vueCompilerOptions.lib}').ComponentCustomProps`, `;\n`);
348
323
  //#endregion
349
324
  codes.push('return {} as {\n');
350
- codes.push(`props: __VLS_Prettify<Omit<typeof __VLS_fnPropsDefineComponent & typeof __VLS_fnPropsTypeOnly, keyof typeof __VLS_defaultProps>> & typeof __VLS_fnPropsSlots & typeof __VLS_defaultProps,\n`);
325
+ codes.push(`props: __VLS_Prettify<__VLS_OmitKeepDiscriminatedUnion<typeof __VLS_fnPropsDefineComponent & typeof __VLS_fnPropsTypeOnly, keyof typeof __VLS_defaultProps>> & typeof __VLS_fnPropsSlots & typeof __VLS_defaultProps,\n`);
351
326
  codes.push(`expose(exposed: import('${vueCompilerOptions.lib}').ShallowUnwrapRef<${scriptSetupRanges.expose.define ? 'typeof __VLS_exposed' : '{}'}>): void,\n`);
352
327
  codes.push('attrs: any,\n');
353
328
  codes.push('slots: ReturnType<typeof __VLS_template>,\n');
@@ -356,7 +331,7 @@ function generate(ts, fileName, _sfc, lang, scriptRanges, scriptSetupRanges, htm
356
331
  codes.push('})(),\n');
357
332
  codes.push(`) => ({} as import('${vueCompilerOptions.lib}').VNode & { __ctx?: Awaited<typeof __VLS_setup> }))`);
358
333
  }
359
- else if (!sfc.script) {
334
+ else if (!script) {
360
335
  // no script block, generate script setup code at root
361
336
  scriptSetupGeneratedOffset = generateSetupFunction(false, 'export', definePropMirrors);
362
337
  }
@@ -374,7 +349,7 @@ function generate(ts, fileName, _sfc, lang, scriptRanges, scriptSetupRanges, htm
374
349
  if (!defineProp.name) {
375
350
  continue;
376
351
  }
377
- const propName = sfc.scriptSetup.content.substring(defineProp.name.start, defineProp.name.end);
352
+ const propName = scriptSetup.content.substring(defineProp.name.start, defineProp.name.end);
378
353
  const propMirror = definePropMirrors[propName];
379
354
  if (propMirror) {
380
355
  mirrorBehaviorMappings.push({
@@ -390,11 +365,11 @@ function generate(ts, fileName, _sfc, lang, scriptRanges, scriptSetupRanges, htm
390
365
  }
391
366
  }
392
367
  function generateSetupFunction(functional, mode, definePropMirrors) {
393
- if (!scriptSetupRanges || !sfc.scriptSetup) {
368
+ if (!scriptSetupRanges || !scriptSetup) {
394
369
  return;
395
370
  }
396
- const definePropProposalA = sfc.scriptSetup.content.trimStart().startsWith('// @experimentalDefinePropProposal=kevinEdition') || vueCompilerOptions.experimentalDefinePropProposal === 'kevinEdition';
397
- const definePropProposalB = sfc.scriptSetup.content.trimStart().startsWith('// @experimentalDefinePropProposal=johnsonEdition') || vueCompilerOptions.experimentalDefinePropProposal === 'johnsonEdition';
371
+ const definePropProposalA = scriptSetup.content.trimStart().startsWith('// @experimentalDefinePropProposal=kevinEdition') || vueCompilerOptions.experimentalDefinePropProposal === 'kevinEdition';
372
+ const definePropProposalB = scriptSetup.content.trimStart().startsWith('// @experimentalDefinePropProposal=johnsonEdition') || vueCompilerOptions.experimentalDefinePropProposal === 'johnsonEdition';
398
373
  if (vueCompilerOptions.target >= 3.3) {
399
374
  codes.push('const { ');
400
375
  for (const macro of Object.keys(vueCompilerOptions.macros)) {
@@ -492,7 +467,7 @@ declare function defineProp<T>(value?: T | (() => T), required?: boolean, rest?:
492
467
  addExtraReferenceVirtualCode('scriptSetup', defineProp.name.start, defineProp.name.end);
493
468
  }
494
469
  else if (defineProp.name) {
495
- propName = sfc.scriptSetup.content.substring(defineProp.name.start, defineProp.name.end);
470
+ propName = scriptSetup.content.substring(defineProp.name.start, defineProp.name.end);
496
471
  const start = muggle.getLength(codes);
497
472
  definePropMirrors[propName] = [start, start + propName.length];
498
473
  codes.push(propName);
@@ -506,7 +481,7 @@ declare function defineProp<T>(value?: T | (() => T), required?: boolean, rest?:
506
481
  type = `NonNullable<typeof ${propName}['value']>`;
507
482
  }
508
483
  else if (defineProp.type) {
509
- type = sfc.scriptSetup.content.substring(defineProp.type.start, defineProp.type.end);
484
+ type = scriptSetup.content.substring(defineProp.type.start, defineProp.type.end);
510
485
  }
511
486
  if (defineProp.required) {
512
487
  codes.push(`{ required: true, type: import('${vueCompilerOptions.lib}').PropType<${type}> },\n`);
@@ -562,17 +537,20 @@ declare function defineProp<T>(value?: T | (() => T), required?: boolean, rest?:
562
537
  }
563
538
  function generateComponentOptions(functional) {
564
539
  if (scriptSetupRanges && !bypassDefineComponent) {
565
- if (scriptSetupRanges.props.define?.arg || scriptSetupRanges.props.define?.typeArg || (!functional && scriptSetupRanges.defineProp.length)) {
566
- codes.push(`props: {\n`);
567
- if (scriptSetupRanges.props.define?.arg) {
568
- codes.push('...');
569
- addExtraReferenceVirtualCode('scriptSetup', scriptSetupRanges.props.define.arg.start, scriptSetupRanges.props.define.arg.end);
570
- codes.push(',\n');
571
- }
572
- if (scriptSetupRanges.props.define?.typeArg) {
540
+ const ranges = scriptSetupRanges;
541
+ const propsCodegens = [];
542
+ if (ranges.props.define?.arg) {
543
+ const arg = ranges.props.define.arg;
544
+ propsCodegens.push(() => {
545
+ addExtraReferenceVirtualCode('scriptSetup', arg.start, arg.end);
546
+ });
547
+ }
548
+ if (ranges.props.define?.typeArg) {
549
+ const typeArg = ranges.props.define.typeArg;
550
+ propsCodegens.push(() => {
573
551
  usedHelperTypes.DefinePropsToOptions = true;
574
- codes.push('...{} as ');
575
- if (scriptSetupRanges.props.withDefaults?.arg) {
552
+ codes.push(`{} as `);
553
+ if (ranges.props.withDefaults?.arg) {
576
554
  usedHelperTypes.MergePropDefaults = true;
577
555
  codes.push(`__VLS_WithDefaults<`);
578
556
  }
@@ -581,22 +559,38 @@ declare function defineProp<T>(value?: T | (() => T), required?: boolean, rest?:
581
559
  codes.push(`typeof __VLS_fnPropsTypeOnly`);
582
560
  }
583
561
  else {
584
- addExtraReferenceVirtualCode('scriptSetup', scriptSetupRanges.props.define.typeArg.start, scriptSetupRanges.props.define.typeArg.end);
562
+ addExtraReferenceVirtualCode('scriptSetup', typeArg.start, typeArg.end);
585
563
  }
586
564
  codes.push(`>`);
587
- if (scriptSetupRanges.props.withDefaults?.arg) {
565
+ if (ranges.props.withDefaults?.arg) {
588
566
  codes.push(`, typeof __VLS_withDefaultsArg`);
589
567
  codes.push(`>`);
590
568
  }
591
- codes.push(',\n');
569
+ });
570
+ }
571
+ if (!functional && ranges.defineProp.length) {
572
+ propsCodegens.push(() => {
573
+ codes.push(`__VLS_propsOption_defineProp`);
574
+ });
575
+ }
576
+ if (propsCodegens.length === 1) {
577
+ codes.push(`props: `);
578
+ for (const generate of propsCodegens) {
579
+ generate();
592
580
  }
593
- if (!functional && scriptSetupRanges.defineProp.length) {
594
- codes.push(`...__VLS_propsOption_defineProp,\n`);
581
+ codes.push(`,\n`);
582
+ }
583
+ else if (propsCodegens.length >= 2) {
584
+ codes.push(`props: {\n`);
585
+ for (const generate of propsCodegens) {
586
+ codes.push('...');
587
+ generate();
588
+ codes.push(',\n');
595
589
  }
596
590
  codes.push(`},\n`);
597
591
  }
598
- if (scriptSetupRanges.emits.define) {
599
- codes.push(`emits: ({} as __VLS_NormalizeEmits<typeof `, scriptSetupRanges.emits.name ?? '__VLS_emit', `>),\n`);
592
+ if (ranges.emits.define) {
593
+ codes.push(`emits: ({} as __VLS_NormalizeEmits<typeof `, ranges.emits.name ?? '__VLS_emit', `>),\n`);
600
594
  }
601
595
  }
602
596
  if (scriptRanges?.exportDefault?.args) {
@@ -637,7 +631,7 @@ declare function defineProp<T>(value?: T | (() => T), required?: boolean, rest?:
637
631
  }
638
632
  }
639
633
  function generateComponentForTemplateUsage(functional, cssIds) {
640
- if (sfc.scriptSetup && scriptSetupRanges) {
634
+ if (scriptSetup && scriptSetupRanges) {
641
635
  codes.push(`const __VLS_internalComponent = (await import('${vueCompilerOptions.lib}')).defineComponent({\n`);
642
636
  generateComponentOptions(functional);
643
637
  codes.push(`setup() {\n`);
@@ -646,9 +640,9 @@ declare function defineProp<T>(value?: T | (() => T), required?: boolean, rest?:
646
640
  // bindings
647
641
  const templateUsageVars = getTemplateUsageVars();
648
642
  for (const [content, bindings] of [
649
- [sfc.scriptSetup.content, scriptSetupRanges.bindings],
650
- scriptRanges && sfc.script
651
- ? [sfc.script.content, scriptRanges.bindings]
643
+ [scriptSetup.content, scriptSetupRanges.bindings],
644
+ scriptRanges && script
645
+ ? [script.content, scriptRanges.bindings]
652
646
  : ['', []],
653
647
  ]) {
654
648
  for (const expose of bindings) {
@@ -678,7 +672,7 @@ declare function defineProp<T>(value?: T | (() => T), required?: boolean, rest?:
678
672
  codes.push(`},\n`); // setup() {
679
673
  codes.push(`});\n`); // defineComponent({
680
674
  }
681
- else if (sfc.script) {
675
+ else if (script) {
682
676
  codes.push(`let __VLS_internalComponent!: typeof import('./${path_1.posix.basename(fileName)}')['default'];\n`);
683
677
  }
684
678
  else {
@@ -688,10 +682,10 @@ declare function defineProp<T>(value?: T | (() => T), required?: boolean, rest?:
688
682
  function generateExportOptions() {
689
683
  codes.push(`\n`);
690
684
  codes.push(`const __VLS_componentsOption = `);
691
- if (sfc.script && scriptRanges?.exportDefault?.componentsOption) {
685
+ if (script && scriptRanges?.exportDefault?.componentsOption) {
692
686
  const componentsOption = scriptRanges.exportDefault.componentsOption;
693
687
  codes.push([
694
- sfc.script.content.substring(componentsOption.start, componentsOption.end),
688
+ script.content.substring(componentsOption.start, componentsOption.end),
695
689
  'script',
696
690
  componentsOption.start,
697
691
  {
@@ -707,13 +701,13 @@ declare function defineProp<T>(value?: T | (() => T), required?: boolean, rest?:
707
701
  }
708
702
  function generateConstNameOption() {
709
703
  codes.push(`\n`);
710
- if (sfc.script && scriptRanges?.exportDefault?.nameOption) {
704
+ if (script && scriptRanges?.exportDefault?.nameOption) {
711
705
  const nameOption = scriptRanges.exportDefault.nameOption;
712
706
  codes.push(`const __VLS_name = `);
713
- codes.push(`${sfc.script.content.substring(nameOption.start, nameOption.end)} as const`);
707
+ codes.push(`${script.content.substring(nameOption.start, nameOption.end)} as const`);
714
708
  codes.push(`;\n`);
715
709
  }
716
- else if (sfc.scriptSetup) {
710
+ else if (scriptSetup) {
717
711
  codes.push(`let __VLS_name!: '${path_1.posix.basename(fileName.substring(0, fileName.lastIndexOf('.')))}';\n`);
718
712
  }
719
713
  else {
@@ -725,15 +719,15 @@ declare function defineProp<T>(value?: T | (() => T), required?: boolean, rest?:
725
719
  codes.push(`let __VLS_ctx!: ${useGlobalThisTypeInCtx ? 'typeof globalThis &' : ''}`);
726
720
  codes.push(`InstanceType<__VLS_PickNotAny<typeof __VLS_internalComponent, new () => {}>> & {\n`);
727
721
  /* CSS Module */
728
- for (let i = 0; i < _sfc.styles.length; i++) {
729
- const style = _sfc.styles[i];
730
- if (!style.module)
731
- continue;
732
- codes.push(`${style.module}: Record<string, string> & __VLS_Prettify<{}`);
733
- for (const className of style.classNames) {
734
- generateCssClassProperty(i, className.text.substring(1), { start: className.offset, end: className.offset + className.text.length }, 'string', false, true);
722
+ for (let i = 0; i < styles.length; i++) {
723
+ const style = styles[i];
724
+ if (style.module) {
725
+ codes.push(`${style.module}: Record<string, string> & __VLS_Prettify<{}`);
726
+ for (const className of style.classNames) {
727
+ generateCssClassProperty(i, className.text.substring(1), { start: className.offset, end: className.offset + className.text.length }, 'string', false, true);
728
+ }
729
+ codes.push('>;\n');
735
730
  }
736
- codes.push('>;\n');
737
731
  }
738
732
  codes.push(`};\n`);
739
733
  /* Components */
@@ -745,12 +739,13 @@ declare function defineProp<T>(value?: T | (() => T), required?: boolean, rest?:
745
739
  /* Style Scoped */
746
740
  codes.push('/* Style Scoped */\n');
747
741
  codes.push('type __VLS_StyleScopedClasses = {}');
748
- for (let i = 0; i < _sfc.styles.length; i++) {
749
- const style = _sfc.styles[i];
750
- if (!style.scoped && vueCompilerOptions.experimentalResolveStyleCssClasses !== 'always')
751
- continue;
752
- for (const className of style.classNames) {
753
- generateCssClassProperty(i, className.text.substring(1), { start: className.offset, end: className.offset + className.text.length }, 'boolean', true, !style.module);
742
+ for (let i = 0; i < styles.length; i++) {
743
+ const style = styles[i];
744
+ const option = vueCompilerOptions.experimentalResolveStyleCssClasses;
745
+ if ((option === 'always' || option === 'scoped') && style.scoped) {
746
+ for (const className of style.classNames) {
747
+ generateCssClassProperty(i, className.text.substring(1), { start: className.offset, end: className.offset + className.text.length }, 'boolean', true, !style.module);
748
+ }
754
749
  }
755
750
  }
756
751
  codes.push(';\n');
@@ -813,7 +808,7 @@ declare function defineProp<T>(value?: T | (() => T), required?: boolean, rest?:
813
808
  function generateCssVars() {
814
809
  const emptyLocalVars = new Map();
815
810
  const identifiers = new Set();
816
- for (const style of _sfc.styles) {
811
+ for (const style of styles) {
817
812
  for (const cssBind of style.cssVars) {
818
813
  (0, transform_1.walkInterpolationFragment)(ts, cssBind.text, ts.createSourceFile('/a.txt', cssBind.text, ts.ScriptTarget.ESNext), (frag, fragOffset, onlyForErrorMapping) => {
819
814
  if (fragOffset === undefined) {
@@ -859,7 +854,7 @@ declare function defineProp<T>(value?: T | (() => T), required?: boolean, rest?:
859
854
  function addVirtualCode(vueTag, start, end) {
860
855
  muggle.offsetStack();
861
856
  codes.push([
862
- sfc[vueTag].content.substring(start, end),
857
+ (vueTag === 'script' ? script : scriptSetup).content.substring(start, end),
863
858
  vueTag,
864
859
  start,
865
860
  language_core_1.FileRangeCapabilities.full, // diagnostic also working for setup() returns unused in template checking
@@ -869,7 +864,7 @@ declare function defineProp<T>(value?: T | (() => T), required?: boolean, rest?:
869
864
  function addExtraReferenceVirtualCode(vueTag, start, end) {
870
865
  muggle.offsetStack();
871
866
  codes.push([
872
- sfc[vueTag].content.substring(start, end),
867
+ (vueTag === 'script' ? script : scriptSetup).content.substring(start, end),
873
868
  vueTag,
874
869
  start,
875
870
  {
@@ -5,7 +5,7 @@ import * as muggle from 'muggle-string';
5
5
  import type * as ts from 'typescript/lib/tsserverlibrary';
6
6
  import { Sfc, VueCompilerOptions } from '../types';
7
7
  type Code = Segment<FileRangeCapabilities>;
8
- export declare function generate(ts: typeof import('typescript/lib/tsserverlibrary'), compilerOptions: ts.CompilerOptions, vueCompilerOptions: VueCompilerOptions, sourceTemplate: string, sourceLang: string, sfc: Sfc, hasScriptSetupSlots: boolean, slotsAssignName: string | undefined, propsAssignName: string | undefined, codegenStack: boolean): {
8
+ export declare function generate(ts: typeof import('typescript/lib/tsserverlibrary'), compilerOptions: ts.CompilerOptions, vueCompilerOptions: VueCompilerOptions, template: NonNullable<Sfc['template']>, shouldGenerateScopedClasses: boolean, stylesScopedClasses: Set<string>, hasScriptSetupSlots: boolean, slotsAssignName: string | undefined, propsAssignName: string | undefined, codegenStack: boolean): {
9
9
  codes: Code[];
10
10
  codeStacks: muggle.StackNode[];
11
11
  formatCodes: Code[];