@vue/language-core 2.1.10 → 2.2.2

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 (109) hide show
  1. package/index.d.ts +0 -1
  2. package/index.js +1 -2
  3. package/lib/codeFeatures.d.ts +1 -0
  4. package/lib/codeFeatures.js +3 -0
  5. package/lib/codegen/codeFeatures.d.ts +83 -0
  6. package/lib/codegen/codeFeatures.js +71 -0
  7. package/lib/codegen/globalTypes.d.ts +3 -1
  8. package/lib/codegen/globalTypes.js +39 -14
  9. package/lib/codegen/localTypes.d.ts +1 -1
  10. package/lib/codegen/localTypes.js +7 -7
  11. package/lib/codegen/script/binding.d.ts +4 -0
  12. package/lib/codegen/script/binding.js +41 -0
  13. package/lib/codegen/script/component.d.ts +1 -1
  14. package/lib/codegen/script/component.js +44 -44
  15. package/lib/codegen/script/componentSelf.d.ts +1 -1
  16. package/lib/codegen/script/componentSelf.js +14 -14
  17. package/lib/codegen/script/context.d.ts +1 -1
  18. package/lib/codegen/script/context.js +2 -2
  19. package/lib/codegen/script/index.d.ts +6 -11
  20. package/lib/codegen/script/index.js +21 -63
  21. package/lib/codegen/script/scriptSetup.d.ts +1 -1
  22. package/lib/codegen/script/scriptSetup.js +236 -205
  23. package/lib/codegen/script/src.js +8 -8
  24. package/lib/codegen/script/styleModulesType.d.ts +1 -1
  25. package/lib/codegen/script/styleModulesType.js +7 -7
  26. package/lib/codegen/script/template.d.ts +2 -2
  27. package/lib/codegen/script/template.js +81 -114
  28. package/lib/codegen/template/context.d.ts +29 -15
  29. package/lib/codegen/template/context.js +51 -96
  30. package/lib/codegen/template/element.d.ts +2 -4
  31. package/lib/codegen/template/element.js +124 -317
  32. package/lib/codegen/template/elementChildren.d.ts +1 -1
  33. package/lib/codegen/template/elementChildren.js +10 -11
  34. package/lib/codegen/template/elementDirectives.d.ts +1 -0
  35. package/lib/codegen/template/elementDirectives.js +43 -30
  36. package/lib/codegen/template/elementEvents.d.ts +2 -2
  37. package/lib/codegen/template/elementEvents.js +32 -65
  38. package/lib/codegen/template/elementProps.d.ts +5 -3
  39. package/lib/codegen/template/elementProps.js +116 -123
  40. package/lib/codegen/template/index.d.ts +1 -0
  41. package/lib/codegen/template/index.js +67 -69
  42. package/lib/codegen/template/interpolation.d.ts +5 -3
  43. package/lib/codegen/template/interpolation.js +30 -27
  44. package/lib/codegen/template/objectProperty.js +8 -8
  45. package/lib/codegen/template/propertyAccess.js +4 -4
  46. package/lib/codegen/template/slotOutlet.d.ts +1 -1
  47. package/lib/codegen/template/slotOutlet.js +47 -25
  48. package/lib/codegen/template/styleScopedClasses.d.ts +4 -1
  49. package/lib/codegen/template/styleScopedClasses.js +152 -8
  50. package/lib/codegen/template/templateChild.d.ts +1 -1
  51. package/lib/codegen/template/templateChild.js +39 -20
  52. package/lib/codegen/template/vFor.d.ts +1 -1
  53. package/lib/codegen/template/vFor.js +11 -11
  54. package/lib/codegen/template/vIf.d.ts +1 -1
  55. package/lib/codegen/template/vIf.js +6 -6
  56. package/lib/codegen/template/vSlot.d.ts +5 -0
  57. package/lib/codegen/template/vSlot.js +80 -0
  58. package/lib/codegen/utils/camelized.d.ts +2 -0
  59. package/lib/codegen/utils/camelized.js +31 -0
  60. package/lib/codegen/utils/index.d.ts +21 -0
  61. package/lib/codegen/utils/index.js +79 -0
  62. package/lib/codegen/utils/src.d.ts +2 -0
  63. package/lib/codegen/utils/src.js +19 -0
  64. package/lib/codegen/{template → utils}/stringLiteralKey.js +3 -3
  65. package/lib/codegen/utils/unicode.d.ts +2 -0
  66. package/lib/codegen/utils/unicode.js +25 -0
  67. package/lib/languagePlugin.js +1 -1
  68. package/lib/parsers/scriptRanges.d.ts +7 -2
  69. package/lib/parsers/scriptSetupRanges.d.ts +69 -83
  70. package/lib/parsers/scriptSetupRanges.js +194 -171
  71. package/lib/parsers/vueCompilerOptions.d.ts +2 -0
  72. package/lib/parsers/vueCompilerOptions.js +23 -0
  73. package/lib/plugins/file-html.js +4 -3
  74. package/lib/plugins/file-md.js +1 -1
  75. package/lib/plugins/file-vue.js +4 -4
  76. package/lib/plugins/vue-root-tags.js +2 -2
  77. package/lib/plugins/vue-style-class-names.d.ts +5 -0
  78. package/lib/plugins/vue-style-class-names.js +32 -0
  79. package/lib/plugins/vue-style-reference-link.d.ts +1 -0
  80. package/lib/plugins/vue-style-reference-link.js +3 -0
  81. package/lib/plugins/vue-style-reference-links.d.ts +3 -0
  82. package/lib/plugins/vue-style-reference-links.js +26 -0
  83. package/lib/plugins/vue-template-html.js +6 -2
  84. package/lib/plugins/vue-template-inline-css.js +1 -1
  85. package/lib/plugins/vue-template-inline-ts.js +66 -17
  86. package/lib/plugins/vue-tsx.d.ts +126 -92
  87. package/lib/plugins/vue-tsx.js +114 -97
  88. package/lib/plugins/vue-vine.d.ts +3 -0
  89. package/lib/plugins/vue-vine.js +35 -0
  90. package/lib/types.d.ts +25 -12
  91. package/lib/utils/buildMappings.d.ts +1 -1
  92. package/lib/utils/parseCssImports.d.ts +4 -0
  93. package/lib/utils/parseCssImports.js +19 -0
  94. package/lib/utils/parseSfc.d.ts +5 -0
  95. package/lib/utils/parseSfc.js +11 -5
  96. package/lib/utils/signals.d.ts +2 -0
  97. package/lib/utils/signals.js +54 -0
  98. package/lib/utils/ts.d.ts +14 -2
  99. package/lib/utils/ts.js +134 -91
  100. package/lib/virtualFile/computedEmbeddedCodes.d.ts +1 -2
  101. package/lib/virtualFile/computedEmbeddedCodes.js +11 -11
  102. package/lib/virtualFile/computedSfc.d.ts +1 -2
  103. package/lib/virtualFile/computedSfc.js +87 -79
  104. package/lib/virtualFile/computedVueSfc.d.ts +1 -2
  105. package/lib/virtualFile/computedVueSfc.js +7 -7
  106. package/lib/virtualFile/vueFile.d.ts +5 -5
  107. package/lib/virtualFile/vueFile.js +6 -6
  108. package/package.json +6 -6
  109. /package/lib/codegen/{template → utils}/stringLiteralKey.d.ts +0 -0
@@ -1,11 +1,16 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.tsCodegen = void 0;
4
+ const shared_1 = require("@vue/shared");
4
5
  const alien_signals_1 = require("alien-signals");
6
+ const path = require("path-browserify");
5
7
  const script_1 = require("../codegen/script");
6
8
  const template_1 = require("../codegen/template");
7
9
  const scriptRanges_1 = require("../parsers/scriptRanges");
8
10
  const scriptSetupRanges_1 = require("../parsers/scriptSetupRanges");
11
+ const vueCompilerOptions_1 = require("../parsers/vueCompilerOptions");
12
+ const signals_1 = require("../utils/signals");
13
+ const ts_1 = require("../utils/ts");
9
14
  exports.tsCodegen = new WeakMap();
10
15
  const fileEditTimes = new Map();
11
16
  const plugin = ctx => {
@@ -17,26 +22,25 @@ const plugin = ctx => {
17
22
  'exactOptionalPropertyTypes',
18
23
  ],
19
24
  getEmbeddedCodes(fileName, sfc) {
20
- const tsx = useTsx(fileName, sfc);
25
+ const codegen = useCodegen(fileName, sfc);
21
26
  const files = [];
22
- if (['js', 'ts', 'jsx', 'tsx'].includes(tsx.lang.get())) {
23
- files.push({ id: 'script_' + tsx.lang.get(), lang: tsx.lang.get() });
27
+ if (['js', 'ts', 'jsx', 'tsx'].includes(codegen.getLang())) {
28
+ files.push({ id: 'script_' + codegen.getLang(), lang: codegen.getLang() });
24
29
  }
25
30
  return files;
26
31
  },
27
32
  resolveEmbeddedCode(fileName, sfc, embeddedFile) {
28
- const _tsx = useTsx(fileName, sfc);
29
33
  if (/script_(js|jsx|ts|tsx)/.test(embeddedFile.id)) {
30
- const tsx = _tsx.generatedScript.get();
34
+ const codegen = useCodegen(fileName, sfc);
35
+ const tsx = codegen.getGeneratedScript();
31
36
  if (tsx) {
32
- const content = [...tsx.codes];
33
- embeddedFile.content = content;
37
+ embeddedFile.content = [...tsx.codes];
34
38
  embeddedFile.linkedCodeMappings = [...tsx.linkedCodeMappings];
35
39
  }
36
40
  }
37
41
  },
38
42
  };
39
- function useTsx(fileName, sfc) {
43
+ function useCodegen(fileName, sfc) {
40
44
  if (!exports.tsCodegen.has(sfc)) {
41
45
  let appendGlobalTypes = false;
42
46
  if (!ctx.vueCompilerOptions.__setupedGlobalTypes && !appendedGlobalTypes) {
@@ -51,37 +55,106 @@ const plugin = ctx => {
51
55
  exports.default = plugin;
52
56
  function createTsx(fileName, _sfc, ctx, appendGlobalTypes) {
53
57
  const ts = ctx.modules.typescript;
54
- const lang = (0, alien_signals_1.computed)(() => {
58
+ const getLang = (0, alien_signals_1.computed)(() => {
55
59
  return !_sfc.script && !_sfc.scriptSetup ? 'ts'
56
60
  : _sfc.scriptSetup && _sfc.scriptSetup.lang !== 'js' ? _sfc.scriptSetup.lang
57
61
  : _sfc.script && _sfc.script.lang !== 'js' ? _sfc.script.lang
58
62
  : 'js';
59
63
  });
60
- const scriptRanges = (0, alien_signals_1.computed)(() => _sfc.script
64
+ const getResolvedOptions = (0, alien_signals_1.computed)(() => {
65
+ const options = (0, vueCompilerOptions_1.parseVueCompilerOptions)(_sfc.comments);
66
+ if (options) {
67
+ const resolver = new ts_1.CompilerOptionsResolver();
68
+ resolver.addConfig(options, path.dirname(fileName));
69
+ return resolver.build(ctx.vueCompilerOptions);
70
+ }
71
+ return ctx.vueCompilerOptions;
72
+ });
73
+ const getScriptRanges = (0, alien_signals_1.computed)(() => _sfc.script
61
74
  ? (0, scriptRanges_1.parseScriptRanges)(ts, _sfc.script.ast, !!_sfc.scriptSetup, false)
62
75
  : undefined);
63
- const scriptSetupRanges = (0, alien_signals_1.computed)(() => _sfc.scriptSetup
64
- ? (0, scriptSetupRanges_1.parseScriptSetupRanges)(ts, _sfc.scriptSetup.ast, ctx.vueCompilerOptions)
76
+ const getScriptSetupRanges = (0, alien_signals_1.computed)(() => _sfc.scriptSetup
77
+ ? (0, scriptSetupRanges_1.parseScriptSetupRanges)(ts, _sfc.scriptSetup.ast, getResolvedOptions())
65
78
  : undefined);
66
- const generatedTemplate = (0, alien_signals_1.computed)(() => {
67
- if (ctx.vueCompilerOptions.skipTemplateCodegen || !_sfc.template) {
79
+ const getSetupBindingNames = (0, signals_1.computedSet)((0, alien_signals_1.computed)(() => {
80
+ const newNames = new Set();
81
+ const bindings = getScriptSetupRanges()?.bindings;
82
+ if (_sfc.scriptSetup && bindings) {
83
+ for (const { range } of bindings) {
84
+ newNames.add(_sfc.scriptSetup.content.slice(range.start, range.end));
85
+ }
86
+ }
87
+ return newNames;
88
+ }));
89
+ const getSetupImportComponentNames = (0, signals_1.computedSet)((0, alien_signals_1.computed)(() => {
90
+ const newNames = new Set();
91
+ const bindings = getScriptSetupRanges()?.bindings;
92
+ if (_sfc.scriptSetup && bindings) {
93
+ for (const { range, moduleName, isDefaultImport, isNamespace } of bindings) {
94
+ if (moduleName
95
+ && isDefaultImport
96
+ && !isNamespace
97
+ && ctx.vueCompilerOptions.extensions.some(ext => moduleName.endsWith(ext))) {
98
+ newNames.add(_sfc.scriptSetup.content.slice(range.start, range.end));
99
+ }
100
+ }
101
+ }
102
+ return newNames;
103
+ }));
104
+ const getSetupDestructuredPropNames = (0, signals_1.computedSet)((0, alien_signals_1.computed)(() => {
105
+ const newNames = new Set(getScriptSetupRanges()?.defineProps?.destructured?.keys());
106
+ const rest = getScriptSetupRanges()?.defineProps?.destructuredRest;
107
+ if (rest) {
108
+ newNames.add(rest);
109
+ }
110
+ return newNames;
111
+ }));
112
+ const getSetupTemplateRefNames = (0, signals_1.computedSet)((0, alien_signals_1.computed)(() => {
113
+ const newNames = new Set(getScriptSetupRanges()?.useTemplateRef
114
+ .map(({ name }) => name)
115
+ .filter(name => name !== undefined));
116
+ return newNames;
117
+ }));
118
+ const setupHasDefineSlots = (0, alien_signals_1.computed)(() => !!getScriptSetupRanges()?.defineSlots);
119
+ const getSetupSlotsAssignName = (0, alien_signals_1.computed)(() => getScriptSetupRanges()?.defineSlots?.name);
120
+ const getSetupPropsAssignName = (0, alien_signals_1.computed)(() => getScriptSetupRanges()?.defineProps?.name);
121
+ const getSetupInheritAttrs = (0, alien_signals_1.computed)(() => {
122
+ const value = getScriptSetupRanges()?.defineOptions?.inheritAttrs ?? getScriptRanges()?.exportDefault?.inheritAttrsOption;
123
+ return value !== 'false';
124
+ });
125
+ const getComponentSelfName = (0, alien_signals_1.computed)(() => {
126
+ const { exportDefault } = getScriptRanges() ?? {};
127
+ if (_sfc.script && exportDefault?.nameOption) {
128
+ const { nameOption } = exportDefault;
129
+ return _sfc.script.content.slice(nameOption.start + 1, nameOption.end - 1);
130
+ }
131
+ const { defineOptions } = getScriptSetupRanges() ?? {};
132
+ if (_sfc.scriptSetup && defineOptions?.name) {
133
+ return defineOptions.name;
134
+ }
135
+ const baseName = path.basename(fileName);
136
+ return (0, shared_1.capitalize)((0, shared_1.camelize)(baseName.slice(0, baseName.lastIndexOf('.'))));
137
+ });
138
+ const getGeneratedTemplate = (0, alien_signals_1.computed)(() => {
139
+ if (getResolvedOptions().skipTemplateCodegen || !_sfc.template) {
68
140
  return;
69
141
  }
70
142
  const codes = [];
71
143
  const codegen = (0, template_1.generateTemplate)({
72
144
  ts,
73
145
  compilerOptions: ctx.compilerOptions,
74
- vueCompilerOptions: ctx.vueCompilerOptions,
146
+ vueCompilerOptions: getResolvedOptions(),
75
147
  template: _sfc.template,
76
- edited: ctx.vueCompilerOptions.__test || (fileEditTimes.get(fileName) ?? 0) >= 2,
77
- scriptSetupBindingNames: scriptSetupBindingNames.get(),
78
- scriptSetupImportComponentNames: scriptSetupImportComponentNames.get(),
79
- destructuredPropNames: destructuredPropNames.get(),
80
- templateRefNames: templateRefNames.get(),
81
- hasDefineSlots: hasDefineSlots.get(),
82
- slotsAssignName: slotsAssignName.get(),
83
- propsAssignName: propsAssignName.get(),
84
- inheritAttrs: inheritAttrs.get(),
148
+ edited: getResolvedOptions().__test || (fileEditTimes.get(fileName) ?? 0) >= 2,
149
+ scriptSetupBindingNames: getSetupBindingNames(),
150
+ scriptSetupImportComponentNames: getSetupImportComponentNames(),
151
+ destructuredPropNames: getSetupDestructuredPropNames(),
152
+ templateRefNames: getSetupTemplateRefNames(),
153
+ hasDefineSlots: setupHasDefineSlots(),
154
+ slotsAssignName: getSetupSlotsAssignName(),
155
+ propsAssignName: getSetupPropsAssignName(),
156
+ inheritAttrs: getSetupInheritAttrs(),
157
+ selfComponentName: getComponentSelfName(),
85
158
  });
86
159
  let current = codegen.next();
87
160
  while (!current.done) {
@@ -91,71 +164,26 @@ function createTsx(fileName, _sfc, ctx, appendGlobalTypes) {
91
164
  }
92
165
  return {
93
166
  ...current.value,
94
- codes: codes,
167
+ codes,
95
168
  };
96
169
  });
97
- const scriptSetupBindingNames = (0, alien_signals_1.computed)(oldNames => {
98
- const newNames = new Set();
99
- const bindings = scriptSetupRanges.get()?.bindings;
100
- if (_sfc.scriptSetup && bindings) {
101
- for (const binding of bindings) {
102
- newNames.add(_sfc.scriptSetup?.content.substring(binding.start, binding.end));
103
- }
104
- }
105
- if (newNames && oldNames && twoSetsEqual(newNames, oldNames)) {
106
- return oldNames;
107
- }
108
- return newNames;
109
- });
110
- const scriptSetupImportComponentNames = (0, alien_signals_1.computed)(oldNames => {
111
- const newNames = scriptSetupRanges.get()?.importComponentNames ?? new Set();
112
- if (oldNames && twoSetsEqual(newNames, oldNames)) {
113
- return oldNames;
114
- }
115
- return newNames;
116
- });
117
- const destructuredPropNames = (0, alien_signals_1.computed)(oldNames => {
118
- const newNames = scriptSetupRanges.get()?.props.destructured ?? new Set();
119
- const rest = scriptSetupRanges.get()?.props.destructuredRest;
120
- if (rest) {
121
- newNames.add(rest);
122
- }
123
- if (oldNames && twoSetsEqual(newNames, oldNames)) {
124
- return oldNames;
125
- }
126
- return newNames;
127
- });
128
- const templateRefNames = (0, alien_signals_1.computed)(oldNames => {
129
- const newNames = new Set(scriptSetupRanges.get()?.templateRefs
130
- .map(({ name }) => name)
131
- .filter(name => name !== undefined));
132
- if (oldNames && twoSetsEqual(newNames, oldNames)) {
133
- return oldNames;
134
- }
135
- return newNames;
136
- });
137
- const hasDefineSlots = (0, alien_signals_1.computed)(() => !!scriptSetupRanges.get()?.slots.define);
138
- const slotsAssignName = (0, alien_signals_1.computed)(() => scriptSetupRanges.get()?.slots.name);
139
- const propsAssignName = (0, alien_signals_1.computed)(() => scriptSetupRanges.get()?.props.name);
140
- const inheritAttrs = (0, alien_signals_1.computed)(() => {
141
- const value = scriptSetupRanges.get()?.options.inheritAttrs ?? scriptRanges.get()?.exportDefault?.inheritAttrsOption;
142
- return value !== 'false';
143
- });
144
- const generatedScript = (0, alien_signals_1.computed)(() => {
170
+ const getGeneratedScript = (0, alien_signals_1.computed)(() => {
145
171
  const codes = [];
146
172
  const linkedCodeMappings = [];
147
173
  let generatedLength = 0;
148
174
  const codegen = (0, script_1.generateScript)({
149
175
  ts,
150
- fileName,
151
- sfc: _sfc,
152
- lang: lang.get(),
153
- scriptRanges: scriptRanges.get(),
154
- scriptSetupRanges: scriptSetupRanges.get(),
155
- templateCodegen: generatedTemplate.get(),
156
176
  compilerOptions: ctx.compilerOptions,
157
- vueCompilerOptions: ctx.vueCompilerOptions,
158
- edited: ctx.vueCompilerOptions.__test || (fileEditTimes.get(fileName) ?? 0) >= 2,
177
+ vueCompilerOptions: getResolvedOptions(),
178
+ sfc: _sfc,
179
+ edited: getResolvedOptions().__test || (fileEditTimes.get(fileName) ?? 0) >= 2,
180
+ fileName,
181
+ lang: getLang(),
182
+ scriptRanges: getScriptRanges(),
183
+ scriptSetupRanges: getScriptSetupRanges(),
184
+ templateCodegen: getGeneratedTemplate(),
185
+ destructuredPropNames: getSetupDestructuredPropNames(),
186
+ templateRefNames: getSetupTemplateRefNames(),
159
187
  getGeneratedLength: () => generatedLength,
160
188
  linkedCodeMappings,
161
189
  appendGlobalTypes,
@@ -177,22 +205,11 @@ function createTsx(fileName, _sfc, ctx, appendGlobalTypes) {
177
205
  };
178
206
  });
179
207
  return {
180
- scriptRanges,
181
- scriptSetupRanges,
182
- lang,
183
- generatedScript,
184
- generatedTemplate,
208
+ getScriptRanges,
209
+ getScriptSetupRanges,
210
+ getLang,
211
+ getGeneratedScript,
212
+ getGeneratedTemplate,
185
213
  };
186
214
  }
187
- function twoSetsEqual(a, b) {
188
- if (a.size !== b.size) {
189
- return false;
190
- }
191
- for (const file of a) {
192
- if (!b.has(file)) {
193
- return false;
194
- }
195
- }
196
- return true;
197
- }
198
215
  //# sourceMappingURL=vue-tsx.js.map
@@ -0,0 +1,3 @@
1
+ import type { VueLanguagePlugin } from '../types';
2
+ declare const plugin: VueLanguagePlugin;
3
+ export default plugin;
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const shared_1 = require("./shared");
4
+ const plugin = () => {
5
+ return {
6
+ version: 2.1,
7
+ getEmbeddedCodes(_fileName, sfc) {
8
+ const result = [];
9
+ for (let i = 0; i < sfc.customBlocks.length; i++) {
10
+ const block = sfc.customBlocks[i];
11
+ if (block.type === 'vine') {
12
+ result.push({
13
+ id: 'vine_' + i,
14
+ lang: block.lang,
15
+ });
16
+ }
17
+ }
18
+ return result;
19
+ },
20
+ resolveEmbeddedCode(_fileName, sfc, embeddedFile) {
21
+ if (embeddedFile.id.startsWith('vine_')) {
22
+ const index = parseInt(embeddedFile.id.slice('vine_'.length));
23
+ const block = sfc.customBlocks[index];
24
+ embeddedFile.content.push([
25
+ block.content,
26
+ block.name,
27
+ 0,
28
+ shared_1.allCodeFeatures,
29
+ ]);
30
+ }
31
+ },
32
+ };
33
+ };
34
+ exports.default = plugin;
35
+ //# sourceMappingURL=vue-vine.js.map
package/lib/types.d.ts CHANGED
@@ -7,7 +7,8 @@ import type { VueEmbeddedCode } from './virtualFile/embeddedFile';
7
7
  export type { SFCParseResult } from '@vue/compiler-sfc';
8
8
  export { VueEmbeddedCode };
9
9
  export type RawVueCompilerOptions = Partial<Omit<VueCompilerOptions, 'target' | 'plugins'>> & {
10
- target?: 'auto' | 2 | 2.7 | 3 | 3.3;
10
+ strictTemplates?: boolean;
11
+ target?: 'auto' | 2 | 2.7 | 3 | 3.3 | 3.5 | 99 | number;
11
12
  plugins?: string[];
12
13
  };
13
14
  export interface VueCodeInformation extends CodeInformation {
@@ -22,7 +23,10 @@ export interface VueCompilerOptions {
22
23
  vitePressExtensions: string[];
23
24
  petiteVueExtensions: string[];
24
25
  jsxSlots: boolean;
25
- strictTemplates: boolean;
26
+ checkUnknownProps: boolean;
27
+ checkUnknownEvents: boolean;
28
+ checkUnknownDirectives: boolean;
29
+ checkUnknownComponents: boolean;
26
30
  skipTemplateCodegen: boolean;
27
31
  fallthroughAttributes: boolean;
28
32
  dataAttributes: string[];
@@ -37,8 +41,10 @@ export interface VueCompilerOptions {
37
41
  defineOptions: string[];
38
42
  withDefaults: string[];
39
43
  };
40
- composibles: {
44
+ composables: {
45
+ useAttrs: string[];
41
46
  useCssModule: string[];
47
+ useSlots: string[];
42
48
  useTemplateRef: string[];
43
49
  };
44
50
  plugins: VueLanguagePlugin[];
@@ -81,8 +87,8 @@ export type VueLanguagePluginReturn = {
81
87
  };
82
88
  export type VueLanguagePlugin = (ctx: {
83
89
  modules: {
84
- typescript: typeof import('typescript');
85
- '@vue/compiler-dom': typeof import('@vue/compiler-dom');
90
+ typescript: typeof ts;
91
+ '@vue/compiler-dom': typeof CompilerDOM;
86
92
  };
87
93
  compilerOptions: ts.CompilerOptions;
88
94
  vueCompilerOptions: VueCompilerOptions;
@@ -97,14 +103,9 @@ export interface SfcBlock {
97
103
  content: string;
98
104
  attrs: Record<string, string | true>;
99
105
  }
100
- export interface SFCStyleOverride {
101
- module?: {
102
- name: string;
103
- offset?: number;
104
- };
105
- }
106
106
  export interface Sfc {
107
107
  content: string;
108
+ comments: string[];
108
109
  template: SfcBlock & {
109
110
  ast: CompilerDOM.RootNode | undefined;
110
111
  errors: CompilerDOM.CompilerError[];
@@ -120,8 +121,12 @@ export interface Sfc {
120
121
  genericOffset: number;
121
122
  ast: ts.SourceFile;
122
123
  } | undefined;
123
- styles: readonly (SfcBlock & SFCStyleOverride & {
124
+ styles: readonly (SfcBlock & {
124
125
  scoped: boolean;
126
+ module?: {
127
+ name: string;
128
+ offset?: number;
129
+ };
125
130
  cssVars: {
126
131
  text: string;
127
132
  offset: number;
@@ -135,6 +140,14 @@ export interface Sfc {
135
140
  type: string;
136
141
  })[];
137
142
  }
143
+ declare module '@vue/compiler-sfc' {
144
+ interface SFCStyleBlock {
145
+ __module?: {
146
+ name: string;
147
+ offset?: number;
148
+ };
149
+ }
150
+ }
138
151
  export interface TextRange {
139
152
  start: number;
140
153
  end: number;
@@ -1,3 +1,3 @@
1
- import type { Segment } from 'muggle-string';
2
1
  import type { Mapping } from '@volar/language-core';
2
+ import type { Segment } from 'muggle-string';
3
3
  export declare function buildMappings<T>(chunks: Segment<T>[]): Mapping<T>[];
@@ -0,0 +1,4 @@
1
+ export declare function parseCssImports(css: string): Generator<{
2
+ text: string;
3
+ offset: number;
4
+ }, void, unknown>;
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseCssImports = parseCssImports;
4
+ const cssImportReg = /(?<=@import\s+url\()(["']?).*?\1(?=\))|(?<=@import\b\s*)(["']).*?\2/g;
5
+ function* parseCssImports(css) {
6
+ const matches = css.matchAll(cssImportReg);
7
+ for (const match of matches) {
8
+ let text = match[0];
9
+ let offset = match.index;
10
+ if (text.startsWith('\'') || text.startsWith('"')) {
11
+ text = text.slice(1, -1);
12
+ offset += 1;
13
+ }
14
+ if (text) {
15
+ yield { text, offset };
16
+ }
17
+ }
18
+ }
19
+ //# sourceMappingURL=parseCssImports.js.map
@@ -1,2 +1,7 @@
1
1
  import type { SFCParseResult } from '@vue/compiler-sfc';
2
+ declare module '@vue/compiler-sfc' {
3
+ interface SFCDescriptor {
4
+ comments: string[];
5
+ }
6
+ }
2
7
  export declare function parse(source: string): SFCParseResult;
@@ -18,6 +18,7 @@ function parse(source) {
18
18
  const descriptor = {
19
19
  filename: 'anonymous.vue',
20
20
  source,
21
+ comments: [],
21
22
  template: null,
22
23
  script: null,
23
24
  scriptSetup: null,
@@ -28,7 +29,11 @@ function parse(source) {
28
29
  shouldForceReload: () => false,
29
30
  };
30
31
  ast.children.forEach(node => {
31
- if (node.type !== compiler.NodeTypes.ELEMENT) {
32
+ if (node.type === compiler.NodeTypes.COMMENT) {
33
+ descriptor.comments.push(node.content);
34
+ return;
35
+ }
36
+ else if (node.type !== compiler.NodeTypes.ELEMENT) {
32
37
  return;
33
38
  }
34
39
  switch (node.tag) {
@@ -37,7 +42,7 @@ function parse(source) {
37
42
  break;
38
43
  case 'script':
39
44
  const scriptBlock = createBlock(node, source);
40
- const isSetup = !!scriptBlock.attrs.setup;
45
+ const isSetup = !!scriptBlock.setup;
41
46
  if (isSetup && !descriptor.scriptSetup) {
42
47
  descriptor.scriptSetup = scriptBlock;
43
48
  break;
@@ -107,14 +112,15 @@ function createBlock(node, source) {
107
112
  block.scoped = true;
108
113
  }
109
114
  else if (p.name === 'module') {
110
- block.module = {
115
+ block.__module = {
111
116
  name: p.value?.content ?? '$style',
112
117
  offset: p.value?.content ? p.value?.loc.start.offset - node.loc.start.offset : undefined
113
118
  };
114
119
  }
115
120
  }
116
- else if (type === 'script' && p.name === 'setup') {
117
- block.setup = attrs.setup;
121
+ else if (type === 'script'
122
+ && (p.name === 'setup' || p.name === 'vapor')) {
123
+ block.setup = attrs[p.name];
118
124
  }
119
125
  }
120
126
  });
@@ -0,0 +1,2 @@
1
+ export declare function computedArray<I, O>(arr: () => I[], getGetter: (item: () => I, index: number) => () => O): readonly Readonly<O>[];
2
+ export declare function computedSet<T>(source: () => Set<T>): () => Set<T>;
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.computedArray = computedArray;
4
+ exports.computedSet = computedSet;
5
+ const alien_signals_1 = require("alien-signals");
6
+ function computedArray(arr, getGetter) {
7
+ const length = (0, alien_signals_1.computed)(() => arr().length);
8
+ const keys = (0, alien_signals_1.computed)(() => {
9
+ const keys = [];
10
+ for (let i = 0; i < length(); i++) {
11
+ keys.push(String(i));
12
+ }
13
+ return keys;
14
+ });
15
+ const items = (0, alien_signals_1.computed)(array => {
16
+ array ??= [];
17
+ while (array.length < length()) {
18
+ const index = array.length;
19
+ const item = (0, alien_signals_1.computed)(() => arr()[index]);
20
+ array.push((0, alien_signals_1.computed)(getGetter(item, index)));
21
+ }
22
+ if (array.length > length()) {
23
+ array.length = length();
24
+ }
25
+ return array;
26
+ });
27
+ return new Proxy({}, {
28
+ get(_, p, receiver) {
29
+ if (p === 'length') {
30
+ return length();
31
+ }
32
+ if (typeof p === 'string' && !isNaN(Number(p))) {
33
+ return items()[Number(p)]?.();
34
+ }
35
+ return Reflect.get(items(), p, receiver);
36
+ },
37
+ has(_, p) {
38
+ return Reflect.has(items(), p);
39
+ },
40
+ ownKeys() {
41
+ return keys();
42
+ },
43
+ });
44
+ }
45
+ function computedSet(source) {
46
+ return (0, alien_signals_1.computed)(oldValue => {
47
+ const newValue = source();
48
+ if (oldValue?.size === newValue.size && [...oldValue].every(c => newValue.has(c))) {
49
+ return oldValue;
50
+ }
51
+ return newValue;
52
+ });
53
+ }
54
+ //# sourceMappingURL=signals.js.map
package/lib/utils/ts.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type * as ts from 'typescript';
2
- import type { VueCompilerOptions } from '../types';
2
+ import type { RawVueCompilerOptions, VueCompilerOptions, VueLanguagePlugin } from '../types';
3
3
  export type ParsedCommandLine = ts.ParsedCommandLine & {
4
4
  vueOptions: VueCompilerOptions;
5
5
  };
@@ -7,7 +7,19 @@ export declare function createParsedCommandLineByJson(ts: typeof import('typescr
7
7
  writeFile?(path: string, data: string): void;
8
8
  }, rootDir: string, json: any, configFileName?: string, skipGlobalTypesSetup?: boolean): ParsedCommandLine;
9
9
  export declare function createParsedCommandLine(ts: typeof import('typescript'), parseConfigHost: ts.ParseConfigHost, tsConfigPath: string, skipGlobalTypesSetup?: boolean): ParsedCommandLine;
10
- export declare function resolveVueCompilerOptions(vueOptions: Partial<VueCompilerOptions>): VueCompilerOptions;
10
+ export declare class CompilerOptionsResolver {
11
+ options: Omit<RawVueCompilerOptions, 'target' | 'plugin'>;
12
+ fallbackTarget: number | undefined;
13
+ target: number | undefined;
14
+ plugins: VueLanguagePlugin[];
15
+ addConfig(options: RawVueCompilerOptions, rootDir: string): void;
16
+ build(defaults?: VueCompilerOptions): VueCompilerOptions;
17
+ }
18
+ export declare function getDefaultCompilerOptions(target?: number, lib?: string, strictTemplates?: boolean): VueCompilerOptions;
19
+ /**
20
+ * @deprecated use `getDefaultCompilerOptions` instead
21
+ */
22
+ export declare function resolveVueCompilerOptions(options: Partial<VueCompilerOptions>): VueCompilerOptions;
11
23
  export declare function setupGlobalTypes(rootDir: string, vueOptions: VueCompilerOptions, host: {
12
24
  fileExists(path: string): boolean;
13
25
  writeFile?(path: string, data: string): void;