@vue/language-core 1.8.19 → 1.8.20

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.
@@ -84,7 +84,7 @@ const transformContext = {
84
84
  },
85
85
  expressionPlugins: ['typescript'],
86
86
  };
87
- function generate(ts, compilerOptions, vueCompilerOptions, sourceTemplate, sourceLang, sfc, hasScriptSetupSlots, slotsAssignName, propsAssignName, codegenStack) {
87
+ function generate(ts, compilerOptions, vueCompilerOptions, template, shouldGenerateScopedClasses, stylesScopedClasses, hasScriptSetupSlots, slotsAssignName, propsAssignName, codegenStack) {
88
88
  const nativeTags = new Set(vueCompilerOptions.nativeTags);
89
89
  const [codes, codeStacks] = codegenStack ? muggle.track([]) : [[], []];
90
90
  const [formatCodes, formatCodeStacks] = codegenStack ? muggle.track([]) : [[], []];
@@ -104,12 +104,15 @@ function generate(ts, compilerOptions, vueCompilerOptions, sourceTemplate, sourc
104
104
  let ignoreStart;
105
105
  let expectedErrorStart;
106
106
  let expectedErrorNode;
107
+ if (slotsAssignName) {
108
+ localVars.set(slotsAssignName, 1);
109
+ }
107
110
  if (propsAssignName) {
108
111
  localVars.set(propsAssignName, 1);
109
112
  }
110
113
  generatePreResolveComponents();
111
- if (sfc.templateAst) {
112
- visitNode(sfc.templateAst, undefined, undefined, undefined);
114
+ if (template.ast) {
115
+ visitNode(template.ast, undefined, undefined, undefined);
113
116
  }
114
117
  generateStyleScopedClasses();
115
118
  if (!hasScriptSetupSlots) {
@@ -151,14 +154,6 @@ function generate(ts, compilerOptions, vueCompilerOptions, sourceTemplate, sourc
151
154
  return codes;
152
155
  }
153
156
  function generateStyleScopedClasses() {
154
- const allClasses = new Set();
155
- for (const block of sfc.styles) {
156
- if (block.scoped || vueCompilerOptions.experimentalResolveStyleCssClasses === 'always') {
157
- for (const className of block.classNames) {
158
- allClasses.add(className.text.substring(1));
159
- }
160
- }
161
- }
162
157
  codes.push(`if (typeof __VLS_styleScopedClasses === 'object' && !Array.isArray(__VLS_styleScopedClasses)) {\n`);
163
158
  for (const { className, offset } of scopedClasses) {
164
159
  codes.push(`__VLS_styleScopedClasses[`);
@@ -168,7 +163,7 @@ function generate(ts, compilerOptions, vueCompilerOptions, sourceTemplate, sourc
168
163
  offset,
169
164
  {
170
165
  ...capabilitiesPresets.scopedClassName,
171
- displayWithLink: allClasses.has(className),
166
+ displayWithLink: stylesScopedClasses.has(className),
172
167
  },
173
168
  ]));
174
169
  codes.push(`];\n`);
@@ -205,7 +200,7 @@ function generate(ts, compilerOptions, vueCompilerOptions, sourceTemplate, sourc
205
200
  const names = nativeTags.has(tagName) ? [tagName] : getPossibleOriginalComponentName(tagName);
206
201
  for (const name of names) {
207
202
  for (const tagRange of tagRanges) {
208
- codes.push(nativeTags.has(tagName) ? '({} as __VLS_IntrinsicElements)' : '__VLS_components', ...createPropertyAccessCode([
203
+ codes.push(nativeTags.has(tagName) ? '__VLS_intrinsicElements' : '__VLS_components', ...createPropertyAccessCode([
209
204
  name,
210
205
  'template',
211
206
  tagRange,
@@ -215,6 +210,10 @@ function generate(ts, compilerOptions, vueCompilerOptions, sourceTemplate, sourc
215
210
  normalize: tagName === name ? capabilitiesPresets.tagReference.rename.normalize : camelizeComponentName,
216
211
  apply: getTagRenameApply(tagName),
217
212
  },
213
+ ...nativeTags.has(tagName) ? {
214
+ ...capabilitiesPresets.tagHover,
215
+ ...capabilitiesPresets.diagnosticOnly,
216
+ } : {},
218
217
  },
219
218
  ]), ';');
220
219
  }
@@ -247,10 +246,10 @@ function generate(ts, compilerOptions, vueCompilerOptions, sourceTemplate, sourc
247
246
  }
248
247
  function collectTagOffsets() {
249
248
  const tagOffsetsMap = {};
250
- if (!sfc.templateAst) {
249
+ if (!template.ast) {
251
250
  return tagOffsetsMap;
252
251
  }
253
- walkElementNodes(sfc.templateAst, node => {
252
+ walkElementNodes(template.ast, node => {
254
253
  if (node.tag === 'slot') {
255
254
  // ignore
256
255
  }
@@ -267,10 +266,10 @@ function generate(ts, compilerOptions, vueCompilerOptions, sourceTemplate, sourc
267
266
  else {
268
267
  tagOffsetsMap[node.tag] ??= [];
269
268
  const offsets = tagOffsetsMap[node.tag];
270
- const source = sourceTemplate.substring(node.loc.start.offset);
269
+ const source = template.content.substring(node.loc.start.offset);
271
270
  const startTagOffset = node.loc.start.offset + source.indexOf(node.tag);
272
271
  offsets.push(startTagOffset); // start tag
273
- if (!node.isSelfClosing && sourceLang === 'html') {
272
+ if (!node.isSelfClosing && template.lang === 'html') {
274
273
  const endTagOffset = node.loc.start.offset + node.loc.source.lastIndexOf(node.tag);
275
274
  if (endTagOffset !== startTagOffset) {
276
275
  offsets.push(endTagOffset); // end tag
@@ -387,11 +386,11 @@ function generate(ts, compilerOptions, vueCompilerOptions, sourceTemplate, sourc
387
386
  let leftCharacter;
388
387
  let rightCharacter;
389
388
  // fix https://github.com/vuejs/language-tools/issues/1787
390
- while ((leftCharacter = sourceTemplate.substring(start - 1, start)).trim() === '' && leftCharacter.length) {
389
+ while ((leftCharacter = template.content.substring(start - 1, start)).trim() === '' && leftCharacter.length) {
391
390
  start--;
392
391
  content = leftCharacter + content;
393
392
  }
394
- while ((rightCharacter = sourceTemplate.substring(start + content.length, start + content.length + 1)).trim() === '' && rightCharacter.length) {
393
+ while ((rightCharacter = template.content.substring(start + content.length, start + content.length + 1)).trim() === '' && rightCharacter.length) {
395
394
  content = content + rightCharacter;
396
395
  }
397
396
  codes.push(...createInterpolationCode(content, node.content.loc, start, capabilitiesPresets.all, '(', ');\n'));
@@ -456,7 +455,7 @@ function generate(ts, compilerOptions, vueCompilerOptions, sourceTemplate, sourc
456
455
  codes.push(`for (const [`);
457
456
  if (leftExpressionRange && leftExpressionText) {
458
457
  const collectAst = createTsAst(node.parseResult, `const [${leftExpressionText}]`);
459
- (0, transform_1.colletVars)(ts, collectAst, forBlockVars);
458
+ (0, transform_1.collectVars)(ts, collectAst, forBlockVars);
460
459
  for (const varName of forBlockVars)
461
460
  localVars.set(varName, (localVars.get(varName) ?? 0) + 1);
462
461
  codes.push([leftExpressionText, 'template', leftExpressionRange.start, capabilitiesPresets.all]);
@@ -481,8 +480,8 @@ function generate(ts, compilerOptions, vueCompilerOptions, sourceTemplate, sourc
481
480
  }
482
481
  function visitElementNode(node, parentEl, componentCtxVar) {
483
482
  codes.push(`{\n`);
484
- const startTagOffset = node.loc.start.offset + sourceTemplate.substring(node.loc.start.offset).indexOf(node.tag);
485
- let endTagOffset = !node.isSelfClosing && sourceLang === 'html' ? node.loc.start.offset + node.loc.source.lastIndexOf(node.tag) : undefined;
483
+ const startTagOffset = node.loc.start.offset + template.content.substring(node.loc.start.offset).indexOf(node.tag);
484
+ let endTagOffset = !node.isSelfClosing && template.lang === 'html' ? node.loc.start.offset + node.loc.source.lastIndexOf(node.tag) : undefined;
486
485
  if (endTagOffset === startTagOffset) {
487
486
  endTagOffset = undefined;
488
487
  }
@@ -516,7 +515,7 @@ function generate(ts, compilerOptions, vueCompilerOptions, sourceTemplate, sourc
516
515
  }
517
516
  const isIntrinsicElement = nativeTags.has(tag) && tagOffsets.length;
518
517
  if (isIntrinsicElement) {
519
- codes.push('const ', var_originalComponent, ` = ({} as __VLS_IntrinsicElements)[`, ...createStringLiteralKeyCode([
518
+ codes.push('const ', var_originalComponent, ` = __VLS_intrinsicElements[`, ...createStringLiteralKeyCode([
520
519
  tag,
521
520
  'template',
522
521
  tagOffsets[0],
@@ -543,34 +542,20 @@ function generate(ts, compilerOptions, vueCompilerOptions, sourceTemplate, sourc
543
542
  codes.push(`const ${var_functionalComponent} = __VLS_asFunctionalComponent(`, `${var_originalComponent}, `, `new ${var_originalComponent}({`, ...createPropsCode(node, props, 'extraReferences'), '})', ');\n');
544
543
  }
545
544
  for (const offset of tagOffsets) {
546
- if (isNamespacedTag || dynamicTagExp) {
545
+ if (isNamespacedTag || dynamicTagExp || isIntrinsicElement) {
547
546
  continue;
548
547
  }
549
- else if (isIntrinsicElement) {
550
- codes.push(`({} as __VLS_IntrinsicElements).`);
551
- codes.push([
552
- tag,
553
- 'template',
554
- [offset, offset + tag.length],
555
- {
556
- ...capabilitiesPresets.tagHover,
557
- ...capabilitiesPresets.diagnosticOnly,
558
- },
559
- ], ';\n');
560
- }
561
- else {
562
- const key = toCanonicalComponentName(tag);
563
- codes.push(`({} as { ${key}: typeof ${var_originalComponent} }).`);
564
- codes.push([
565
- key,
566
- 'template',
567
- [offset, offset + tag.length],
568
- {
569
- ...capabilitiesPresets.tagHover,
570
- ...capabilitiesPresets.diagnosticOnly,
571
- },
572
- ], ';\n');
573
- }
548
+ const key = toCanonicalComponentName(tag);
549
+ codes.push(`({} as { ${key}: typeof ${var_originalComponent} }).`);
550
+ codes.push([
551
+ key,
552
+ 'template',
553
+ [offset, offset + tag.length],
554
+ {
555
+ ...capabilitiesPresets.tagHover,
556
+ ...capabilitiesPresets.diagnosticOnly,
557
+ },
558
+ ], ';\n');
574
559
  }
575
560
  if (vueCompilerOptions.strictTemplates) {
576
561
  // with strictTemplates, generate once for props type-checking + instance type
@@ -636,7 +621,7 @@ function generate(ts, compilerOptions, vueCompilerOptions, sourceTemplate, sourc
636
621
  }
637
622
  generateDirectives(node);
638
623
  generateElReferences(node); // <el ref="foo" />
639
- if (sfc.styles.some(s => s.scoped || vueCompilerOptions.experimentalResolveStyleCssClasses === 'always')) {
624
+ if (shouldGenerateScopedClasses) {
640
625
  generateClassScoped(node);
641
626
  }
642
627
  if (componentCtxVar) {
@@ -661,7 +646,7 @@ function generate(ts, compilerOptions, vueCompilerOptions, sourceTemplate, sourc
661
646
  if (slotDir?.exp?.type === 4 /* CompilerDOM.NodeTypes.SIMPLE_EXPRESSION */) {
662
647
  formatCodes.push(...createFormatCode(slotDir.exp.content, slotDir.exp.loc.start.offset, formatBrackets.params));
663
648
  const slotAst = createTsAst(slotDir, `(${slotDir.exp.content}) => {}`);
664
- (0, transform_1.colletVars)(ts, slotAst, slotBlockVars);
649
+ (0, transform_1.collectVars)(ts, slotAst, slotBlockVars);
665
650
  hasProps = true;
666
651
  if (slotDir.exp.content.indexOf(':') === -1) {
667
652
  codes.push('const [', [
@@ -706,6 +691,7 @@ function generate(ts, compilerOptions, vueCompilerOptions, sourceTemplate, sourc
706
691
  prev = childNode;
707
692
  }
708
693
  resolveComment();
694
+ generateAutoImportCompletionCode();
709
695
  slotBlockVars.forEach(varName => {
710
696
  localVars.set(varName, localVars.get(varName) - 1);
711
697
  });
@@ -773,7 +759,7 @@ function generate(ts, compilerOptions, vueCompilerOptions, sourceTemplate, sourc
773
759
  },
774
760
  },
775
761
  },
776
- ]), `) };\n`, `${eventVar} = {\n`);
762
+ ]), `) };\n`, `${eventVar} = { `);
777
763
  if (prop.arg.loc.source.startsWith('[') && prop.arg.loc.source.endsWith(']')) {
778
764
  codes.push('[(', ...createInterpolationCode(prop.arg.loc.source.slice(1, -1), prop.arg.loc, prop.arg.loc.start.offset + 1, capabilitiesPresets.all, '', ''), ')!]');
779
765
  }
@@ -787,7 +773,7 @@ function generate(ts, compilerOptions, vueCompilerOptions, sourceTemplate, sourc
787
773
  }
788
774
  codes.push(`: `);
789
775
  appendExpressionNode(prop);
790
- codes.push(`};\n`);
776
+ codes.push(` };\n`);
791
777
  }
792
778
  else if (prop.type === 7 /* CompilerDOM.NodeTypes.DIRECTIVE */
793
779
  && prop.name === 'on'
@@ -820,14 +806,16 @@ function generate(ts, compilerOptions, vueCompilerOptions, sourceTemplate, sourc
820
806
  }
821
807
  let prefix = '(';
822
808
  let suffix = ')';
809
+ let isFirstMapping = true;
823
810
  if (isCompoundExpression) {
824
- prefix = '$event => {\n';
811
+ codes.push('$event => {\n');
812
+ localVars.set('$event', (localVars.get('$event') ?? 0) + 1);
813
+ prefix = '';
814
+ suffix = '';
825
815
  for (const blockCondition of blockConditions) {
826
816
  prefix += `if (!(${blockCondition})) return;\n`;
827
817
  }
828
- suffix = '\n}';
829
818
  }
830
- let isFirstMapping = true;
831
819
  codes.push(...createInterpolationCode(prop.exp.content, prop.exp.loc, prop.exp.loc.start.offset, () => {
832
820
  if (isCompoundExpression && isFirstMapping) {
833
821
  isFirstMapping = false;
@@ -835,6 +823,12 @@ function generate(ts, compilerOptions, vueCompilerOptions, sourceTemplate, sourc
835
823
  }
836
824
  return capabilitiesPresets.all;
837
825
  }, prefix, suffix));
826
+ if (isCompoundExpression) {
827
+ localVars.set('$event', localVars.get('$event') - 1);
828
+ codes.push(';\n');
829
+ generateAutoImportCompletionCode();
830
+ codes.push('}\n');
831
+ }
838
832
  formatCodes.push(...createFormatCode(prop.exp.content, prop.exp.loc.start.offset, isCompoundExpression ? formatBrackets.event : formatBrackets.normal));
839
833
  }
840
834
  else {
@@ -1028,7 +1022,7 @@ function generate(ts, compilerOptions, vueCompilerOptions, sourceTemplate, sourc
1028
1022
  && prop.name === 'bind'
1029
1023
  && !prop.arg
1030
1024
  && prop.exp?.type === 4 /* CompilerDOM.NodeTypes.SIMPLE_EXPRESSION */) {
1031
- codes.push('...', ...createInterpolationCode(prop.exp.content, prop.exp.loc, prop.exp.loc.start.offset, caps_all, '(', ')'), ', ');
1025
+ codes.push(['', 'template', prop.exp.loc.start.offset, capabilitiesPresets.diagnosticOnly], '...', ...createInterpolationCode(prop.exp.content, prop.exp.loc, prop.exp.loc.start.offset, caps_all, '(', ')'), ['', 'template', prop.exp.loc.end.offset, capabilitiesPresets.diagnosticOnly], ', ');
1032
1026
  if (mode === 'normal') {
1033
1027
  formatCodes.push(...createFormatCode(prop.exp.content, prop.exp.loc.start.offset, formatBrackets.normal));
1034
1028
  }
@@ -1235,7 +1229,7 @@ function generate(ts, compilerOptions, vueCompilerOptions, sourceTemplate, sourc
1235
1229
  else {
1236
1230
  codes.push(...createInterpolationCode(slotNameExpNode.content, slotNameExpNode, undefined, undefined, '(', ')'));
1237
1231
  }
1238
- codes.push(`;\n`);
1232
+ codes.push(` as const;\n`);
1239
1233
  slotExps.set(varSlotExp, {
1240
1234
  varName: varSlot,
1241
1235
  });
package/out/index.d.ts CHANGED
@@ -2,7 +2,7 @@ export * from './generators/template';
2
2
  export * from './languageModule';
3
3
  export * from './parsers/scriptSetupRanges';
4
4
  export * from './plugins';
5
- export * from './sourceFile';
5
+ export * from './virtualFile/vueFile';
6
6
  export * from './types';
7
7
  export * from './utils/ts';
8
8
  export * from './utils/parseSfc';
package/out/index.js CHANGED
@@ -31,7 +31,7 @@ __exportStar(require("./generators/template"), exports);
31
31
  __exportStar(require("./languageModule"), exports);
32
32
  __exportStar(require("./parsers/scriptSetupRanges"), exports);
33
33
  __exportStar(require("./plugins"), exports);
34
- __exportStar(require("./sourceFile"), exports);
34
+ __exportStar(require("./virtualFile/vueFile"), exports);
35
35
  __exportStar(require("./types"), exports);
36
36
  __exportStar(require("./utils/ts"), exports);
37
37
  __exportStar(require("./utils/parseSfc"), exports);
@@ -1,5 +1,5 @@
1
1
  import type { Language } from '@volar/language-core';
2
- import { VueFile } from './sourceFile';
2
+ import { VueFile } from './virtualFile/vueFile';
3
3
  import { VueCompilerOptions } from './types';
4
4
  import type * as ts from 'typescript/lib/tsserverlibrary';
5
5
  export declare function createVueLanguage(ts: typeof import('typescript/lib/tsserverlibrary'), compilerOptions?: ts.CompilerOptions, _vueCompilerOptions?: Partial<VueCompilerOptions>, codegenStack?: boolean): Language<VueFile>;
@@ -26,7 +26,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
26
26
  exports.createLanguages = exports.createVueLanguage = void 0;
27
27
  const path_1 = require("path");
28
28
  const plugins_1 = require("./plugins");
29
- const sourceFile_1 = require("./sourceFile");
29
+ const vueFile_1 = require("./virtualFile/vueFile");
30
30
  const sharedTypes = __importStar(require("./utils/globalTypes"));
31
31
  const ts_1 = require("./utils/ts");
32
32
  const fileRegistries = [];
@@ -73,7 +73,7 @@ function createVueLanguage(ts, compilerOptions = {}, _vueCompilerOptions = {}, c
73
73
  reusedVueFile.update(snapshot);
74
74
  return reusedVueFile;
75
75
  }
76
- const vueFile = new sourceFile_1.VueFile(fileName, snapshot, vueCompilerOptions, plugins, ts, codegenStack);
76
+ const vueFile = new vueFile_1.VueFile(fileName, snapshot, vueCompilerOptions, plugins, ts, codegenStack);
77
77
  fileRegistry.set(fileName, vueFile);
78
78
  return vueFile;
79
79
  }
@@ -1,7 +1,7 @@
1
1
  import { Sfc, VueLanguagePlugin } from '../types';
2
2
  import * as muggle from 'muggle-string';
3
3
  export declare const tsCodegen: WeakMap<Sfc, {
4
- scriptRanges: import("@vue/reactivity").ComputedRef<{
4
+ scriptRanges: () => {
5
5
  exportDefault: (import("../types").TextRange & {
6
6
  expression: import("../types").TextRange;
7
7
  args: import("../types").TextRange;
@@ -11,8 +11,8 @@ export declare const tsCodegen: WeakMap<Sfc, {
11
11
  nameOption: import("../types").TextRange | undefined;
12
12
  }) | undefined;
13
13
  bindings: import("../types").TextRange[];
14
- } | undefined>;
15
- scriptSetupRanges: import("@vue/reactivity").ComputedRef<{
14
+ } | undefined;
15
+ scriptSetupRanges: () => {
16
16
  leadingCommentEndOffset: number;
17
17
  importSectionEndOffset: number;
18
18
  bindings: import("../types").TextRange[];
@@ -49,14 +49,14 @@ export declare const tsCodegen: WeakMap<Sfc, {
49
49
  defaultValue: import("../types").TextRange | undefined;
50
50
  required: boolean;
51
51
  }[];
52
- } | undefined>;
53
- lang: import("@vue/reactivity").ComputedRef<string>;
54
- generatedScript: import("@vue/reactivity").ComputedRef<{
52
+ } | undefined;
53
+ lang: () => string;
54
+ generatedScript: () => {
55
55
  codes: muggle.Segment<import("@volar/language-core").FileRangeCapabilities>[];
56
56
  codeStacks: muggle.StackNode[];
57
57
  mirrorBehaviorMappings: import("@volar/source-map").Mapping<[import("@volar/language-core").MirrorBehaviorCapabilities, import("@volar/language-core").MirrorBehaviorCapabilities]>[];
58
- }>;
59
- generatedTemplate: import("@vue/reactivity").ComputedRef<{
58
+ };
59
+ generatedTemplate: () => {
60
60
  codes: (string | [string, string | undefined, number | [number, number], import("@volar/language-core").FileRangeCapabilities])[];
61
61
  codeStacks: muggle.StackNode[];
62
62
  formatCodes: (string | [string, string | undefined, number | [number, number], import("@volar/language-core").FileRangeCapabilities])[];
@@ -66,7 +66,7 @@ export declare const tsCodegen: WeakMap<Sfc, {
66
66
  tagNames: Record<string, number[]>;
67
67
  accessedGlobalVariables: Set<string>;
68
68
  hasSlot: boolean;
69
- } | undefined>;
69
+ } | undefined;
70
70
  }>;
71
71
  declare const plugin: VueLanguagePlugin;
72
72
  export default plugin;
@@ -24,7 +24,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
26
  exports.tsCodegen = void 0;
27
- const reactivity_1 = require("@vue/reactivity");
27
+ const computeds_1 = require("computeds");
28
28
  const script_1 = require("../generators/script");
29
29
  const template_1 = require("../generators/template");
30
30
  const scriptRanges_1 = require("../parsers/scriptRanges");
@@ -44,8 +44,8 @@ const plugin = (ctx) => {
44
44
  getEmbeddedFileNames(fileName, sfc) {
45
45
  const tsx = useTsx(fileName, sfc);
46
46
  const fileNames = [];
47
- if (['js', 'ts', 'jsx', 'tsx'].includes(tsx.lang.value)) {
48
- fileNames.push(fileName + '.' + tsx.lang.value);
47
+ if (['js', 'ts', 'jsx', 'tsx'].includes(tsx.lang())) {
48
+ fileNames.push(fileName + '.' + tsx.lang());
49
49
  }
50
50
  if (sfc.template) {
51
51
  fileNames.push(fileName + '.template_format.ts');
@@ -56,7 +56,7 @@ const plugin = (ctx) => {
56
56
  resolveEmbeddedFile(fileName, sfc, embeddedFile) {
57
57
  const _tsx = useTsx(fileName, sfc);
58
58
  const suffix = embeddedFile.fileName.replace(fileName, '');
59
- if (suffix === '.' + _tsx.lang.value) {
59
+ if (suffix === '.' + _tsx.lang()) {
60
60
  embeddedFile.kind = language_core_1.FileKind.TypeScriptHostFile;
61
61
  embeddedFile.capabilities = {
62
62
  ...language_core_1.FileCapabilities.full,
@@ -64,7 +64,7 @@ const plugin = (ctx) => {
64
64
  documentFormatting: false,
65
65
  documentSymbol: false,
66
66
  };
67
- const tsx = _tsx.generatedScript.value;
67
+ const tsx = _tsx.generatedScript();
68
68
  if (tsx) {
69
69
  const [content, contentStacks] = ctx.codegenStack ? muggle.track([...tsx.codes], [...tsx.codeStacks]) : [[...tsx.codes], [...tsx.codeStacks]];
70
70
  embeddedFile.content = content;
@@ -82,8 +82,11 @@ const plugin = (ctx) => {
82
82
  codeAction: false,
83
83
  inlayHint: false,
84
84
  };
85
- if (_tsx.generatedTemplate.value) {
86
- const [content, contentStacks] = ctx.codegenStack ? muggle.track([..._tsx.generatedTemplate.value.formatCodes], [..._tsx.generatedTemplate.value.formatCodeStacks]) : [[..._tsx.generatedTemplate.value.formatCodes], [..._tsx.generatedTemplate.value.formatCodeStacks]];
85
+ const template = _tsx.generatedTemplate();
86
+ if (template) {
87
+ const [content, contentStacks] = ctx.codegenStack
88
+ ? muggle.track([...template.formatCodes], [...template.formatCodeStacks])
89
+ : [[...template.formatCodes], [...template.formatCodeStacks]];
87
90
  embeddedFile.content = content;
88
91
  embeddedFile.contentStacks = contentStacks;
89
92
  }
@@ -103,8 +106,11 @@ const plugin = (ctx) => {
103
106
  }
104
107
  else if (suffix.match(templateStyleCssReg)) {
105
108
  embeddedFile.parentFileName = fileName + '.template.' + sfc.template?.lang;
106
- if (_tsx.generatedTemplate.value) {
107
- const [content, contentStacks] = ctx.codegenStack ? muggle.track([..._tsx.generatedTemplate.value.cssCodes], [..._tsx.generatedTemplate.value.cssCodeStacks]) : [[..._tsx.generatedTemplate.value.cssCodes], [..._tsx.generatedTemplate.value.cssCodeStacks]];
109
+ const template = _tsx.generatedTemplate();
110
+ if (template) {
111
+ const [content, contentStacks] = ctx.codegenStack
112
+ ? muggle.track([...template.cssCodes], [...template.cssCodeStacks])
113
+ : [[...template.cssCodes], [...template.cssCodeStacks]];
108
114
  embeddedFile.content = content;
109
115
  embeddedFile.contentStacks = contentStacks;
110
116
  }
@@ -123,34 +129,48 @@ const plugin = (ctx) => {
123
129
  exports.default = plugin;
124
130
  function createTsx(fileName, _sfc, { vueCompilerOptions, compilerOptions, codegenStack, modules }) {
125
131
  const ts = modules.typescript;
126
- const lang = (0, reactivity_1.computed)(() => {
132
+ const lang = (0, computeds_1.computed)(() => {
127
133
  return !_sfc.script && !_sfc.scriptSetup ? 'ts'
128
134
  : _sfc.scriptSetup && _sfc.scriptSetup.lang !== 'js' ? _sfc.scriptSetup.lang
129
135
  : _sfc.script && _sfc.script.lang !== 'js' ? _sfc.script.lang
130
136
  : 'js';
131
137
  });
132
- const scriptRanges = (0, reactivity_1.computed)(() => _sfc.scriptAst
133
- ? (0, scriptRanges_1.parseScriptRanges)(ts, _sfc.scriptAst, !!_sfc.scriptSetup, false)
138
+ const scriptRanges = (0, computeds_1.computed)(() => _sfc.script
139
+ ? (0, scriptRanges_1.parseScriptRanges)(ts, _sfc.script.ast, !!_sfc.scriptSetup, false)
134
140
  : undefined);
135
- const scriptSetupRanges = (0, reactivity_1.computed)(() => _sfc.scriptSetupAst
136
- ? (0, scriptSetupRanges_1.parseScriptSetupRanges)(ts, _sfc.scriptSetupAst, vueCompilerOptions)
141
+ const scriptSetupRanges = (0, computeds_1.computed)(() => _sfc.scriptSetup
142
+ ? (0, scriptSetupRanges_1.parseScriptSetupRanges)(ts, _sfc.scriptSetup.ast, vueCompilerOptions)
137
143
  : undefined);
138
- const generatedTemplate = (0, reactivity_1.computed)(() => {
139
- if (!_sfc.templateAst)
140
- return;
141
- return (0, template_1.generate)(ts, compilerOptions, vueCompilerOptions, _sfc.template?.content ?? '', _sfc.template?.lang ?? 'html', _sfc, hasScriptSetupSlots.value, slotsAssignName.value, propsAssignName.value, codegenStack);
144
+ const shouldGenerateScopedClasses = (0, computeds_1.computed)(() => {
145
+ const option = vueCompilerOptions.experimentalResolveStyleCssClasses;
146
+ return _sfc.styles.some(s => {
147
+ return option === 'always' || (option === 'scoped' && s.scoped);
148
+ });
142
149
  });
143
- //#region remove when https://github.com/vuejs/core/pull/5912 merged
144
- const hasScriptSetupSlots = (0, reactivity_1.shallowRef)(false);
145
- const slotsAssignName = (0, reactivity_1.shallowRef)();
146
- const propsAssignName = (0, reactivity_1.shallowRef)();
147
- //#endregion
148
- const generatedScript = (0, reactivity_1.computed)(() => {
149
- hasScriptSetupSlots.value = !!scriptSetupRanges.value?.slots.define;
150
- slotsAssignName.value = scriptSetupRanges.value?.slots.name;
151
- propsAssignName.value = scriptSetupRanges.value?.props.name;
152
- return (0, script_1.generate)(ts, fileName, _sfc, lang.value, scriptRanges.value, scriptSetupRanges.value, generatedTemplate.value, compilerOptions, vueCompilerOptions, codegenStack);
150
+ const stylesScopedClasses = (0, computeds_1.computedSet)(() => {
151
+ const classes = new Set();
152
+ if (!shouldGenerateScopedClasses()) {
153
+ return classes;
154
+ }
155
+ for (const style of _sfc.styles) {
156
+ const option = vueCompilerOptions.experimentalResolveStyleCssClasses;
157
+ if ((option === 'always' || option === 'scoped') && style.scoped) {
158
+ for (const className of style.classNames) {
159
+ classes.add(className.text.substring(1));
160
+ }
161
+ }
162
+ }
163
+ return classes;
164
+ });
165
+ const generatedTemplate = (0, computeds_1.computed)(() => {
166
+ if (!_sfc.template)
167
+ return;
168
+ return (0, template_1.generate)(ts, compilerOptions, vueCompilerOptions, _sfc.template, shouldGenerateScopedClasses(), stylesScopedClasses(), hasScriptSetupSlots(), slotsAssignName(), propsAssignName(), codegenStack);
153
169
  });
170
+ const hasScriptSetupSlots = (0, computeds_1.computed)(() => !!scriptSetupRanges()?.slots.define);
171
+ const slotsAssignName = (0, computeds_1.computed)(() => scriptSetupRanges()?.slots.name);
172
+ const propsAssignName = (0, computeds_1.computed)(() => scriptSetupRanges()?.props.name);
173
+ const generatedScript = (0, computeds_1.computed)(() => (0, script_1.generate)(ts, fileName, _sfc.script, _sfc.scriptSetup, _sfc.styles, lang(), scriptRanges(), scriptSetupRanges(), generatedTemplate(), compilerOptions, vueCompilerOptions, codegenStack));
154
174
  return {
155
175
  scriptRanges,
156
176
  scriptSetupRanges,
package/out/plugins.d.ts CHANGED
@@ -20,6 +20,6 @@ export declare function getDefaultVueLanguagePlugins(ts: typeof import('typescri
20
20
  newText: string;
21
21
  }): CompilerDOM.CodegenResult | undefined;
22
22
  getEmbeddedFileNames?(fileName: string, sfc: import("./types").Sfc): string[];
23
- resolveEmbeddedFile?(fileName: string, sfc: import("./types").Sfc, embeddedFile: import("./sourceFile").VueEmbeddedFile): void;
23
+ resolveEmbeddedFile?(fileName: string, sfc: import("./types").Sfc, embeddedFile: import("./virtualFile/embeddedFile").VueEmbeddedFile): void;
24
24
  }[];
25
25
  //# sourceMappingURL=plugins.d.ts.map
package/out/types.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import type * as CompilerDOM from '@vue/compiler-dom';
2
2
  import type { SFCParseResult } from '@vue/compiler-sfc';
3
3
  import type * as ts from 'typescript/lib/tsserverlibrary';
4
- import type { VueEmbeddedFile } from './sourceFile';
4
+ import type { VueEmbeddedFile } from './virtualFile/embeddedFile';
5
5
  export type { SFCParseResult } from '@vue/compiler-sfc';
6
6
  export type RawVueCompilerOptions = Partial<Omit<VueCompilerOptions, 'target' | 'plugins'>> & {
7
7
  target?: 'auto' | 2 | 2.7 | 3 | 3.3;
@@ -75,16 +75,22 @@ export interface SfcBlock {
75
75
  attrs: Record<string, string | true>;
76
76
  }
77
77
  export interface Sfc {
78
- template: SfcBlock | null;
78
+ template: SfcBlock & {
79
+ ast: CompilerDOM.RootNode | undefined;
80
+ errors: CompilerDOM.CompilerError[];
81
+ warnings: CompilerDOM.CompilerError[];
82
+ } | undefined;
79
83
  script: (SfcBlock & {
80
84
  src: string | undefined;
81
85
  srcOffset: number;
82
- }) | null;
86
+ ast: ts.SourceFile;
87
+ }) | undefined;
83
88
  scriptSetup: SfcBlock & {
84
89
  generic: string | undefined;
85
90
  genericOffset: number;
86
- } | null;
87
- styles: (SfcBlock & {
91
+ ast: ts.SourceFile;
92
+ } | undefined;
93
+ styles: readonly (SfcBlock & {
88
94
  module: string | undefined;
89
95
  scoped: boolean;
90
96
  cssVars: {
@@ -96,11 +102,20 @@ export interface Sfc {
96
102
  offset: number;
97
103
  }[];
98
104
  })[];
99
- customBlocks: (SfcBlock & {
105
+ customBlocks: readonly (SfcBlock & {
100
106
  type: string;
101
107
  })[];
108
+ /**
109
+ * @deprecated use `template.ast` instead
110
+ */
102
111
  templateAst: CompilerDOM.RootNode | undefined;
112
+ /**
113
+ * @deprecated use `script.ast` instead
114
+ */
103
115
  scriptAst: ts.SourceFile | undefined;
116
+ /**
117
+ * @deprecated use `scriptSetup.ast` instead
118
+ */
104
119
  scriptSetupAst: ts.SourceFile | undefined;
105
120
  }
106
121
  export interface TextRange {
@@ -15,6 +15,11 @@ type __VLS_PickNotAny<A, B> = __VLS_IsAny<A> extends true ? B : A;
15
15
 
16
16
  type __VLS_Prettify<T> = { [K in keyof T]: T[K]; } & {};
17
17
 
18
+ type __VLS_OmitKeepDiscriminatedUnion<T, K extends keyof any> =
19
+ T extends any
20
+ ? Pick<T, Exclude<keyof T, K>>
21
+ : never;
22
+
18
23
  type __VLS_GlobalComponents =
19
24
  __VLS_PickNotAny<import('vue').GlobalComponents, {}>
20
25
  & __VLS_PickNotAny<import('@vue/runtime-core').GlobalComponents, {}>
@@ -27,6 +32,8 @@ type __VLS_GlobalComponents =
27
32
  | 'Teleport'
28
33
  >;
29
34
 
35
+ declare const __VLS_intrinsicElements: __VLS_IntrinsicElements;
36
+
30
37
  // v-for
31
38
  declare function __VLS_getVForSourceType(source: number): [number, number, number][];
32
39
  declare function __VLS_getVForSourceType(source: string): [string, number, number][];
@@ -5,5 +5,5 @@ export declare function walkInterpolationFragment(ts: typeof import('typescript/
5
5
  isShorthand: boolean;
6
6
  offset: number;
7
7
  }[];
8
- export declare function colletVars(ts: typeof import('typescript/lib/tsserverlibrary'), node: ts.Node, result: string[]): void;
8
+ export declare function collectVars(ts: typeof import('typescript/lib/tsserverlibrary'), node: ts.Node, result: string[]): void;
9
9
  //# sourceMappingURL=transform.d.ts.map