@vue/language-core 3.1.5 → 3.1.7

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 (106) hide show
  1. package/index.d.ts +2 -1
  2. package/index.js +3 -2
  3. package/lib/codegen/codeFeatures.d.ts +5 -9
  4. package/lib/codegen/codeFeatures.js +5 -5
  5. package/lib/codegen/globalTypes.js +12 -18
  6. package/lib/codegen/localTypes.d.ts +1 -1
  7. package/lib/codegen/localTypes.js +6 -6
  8. package/lib/codegen/names.d.ts +30 -0
  9. package/lib/codegen/names.js +34 -0
  10. package/lib/codegen/script/component.js +45 -54
  11. package/lib/codegen/script/context.d.ts +2 -5
  12. package/lib/codegen/script/context.js +1 -7
  13. package/lib/codegen/script/index.d.ts +10 -12
  14. package/lib/codegen/script/index.js +74 -73
  15. package/lib/codegen/script/scriptSetup.d.ts +3 -2
  16. package/lib/codegen/script/scriptSetup.js +209 -283
  17. package/lib/codegen/script/src.js +9 -3
  18. package/lib/codegen/script/template.js +64 -108
  19. package/lib/codegen/style/common.d.ts +3 -0
  20. package/lib/codegen/style/common.js +43 -0
  21. package/lib/codegen/style/index.d.ts +63 -0
  22. package/lib/codegen/style/index.js +38 -0
  23. package/lib/codegen/style/modules.d.ts +3 -2
  24. package/lib/codegen/style/modules.js +12 -11
  25. package/lib/codegen/style/scopedClasses.d.ts +2 -3
  26. package/lib/codegen/style/scopedClasses.js +23 -21
  27. package/lib/codegen/template/context.d.ts +7 -16
  28. package/lib/codegen/template/context.js +81 -93
  29. package/lib/codegen/template/element.js +153 -55
  30. package/lib/codegen/template/elementDirectives.js +32 -12
  31. package/lib/codegen/template/elementEvents.js +27 -28
  32. package/lib/codegen/template/elementProps.d.ts +2 -2
  33. package/lib/codegen/template/elementProps.js +49 -23
  34. package/lib/codegen/template/index.d.ts +8 -19
  35. package/lib/codegen/template/index.js +85 -80
  36. package/lib/codegen/template/interpolation.d.ts +3 -3
  37. package/lib/codegen/template/interpolation.js +90 -136
  38. package/lib/codegen/template/objectProperty.js +8 -4
  39. package/lib/codegen/template/propertyAccess.d.ts +1 -1
  40. package/lib/codegen/template/propertyAccess.js +5 -7
  41. package/lib/codegen/template/slotOutlet.js +25 -8
  42. package/lib/codegen/template/styleScopedClasses.d.ts +3 -6
  43. package/lib/codegen/template/styleScopedClasses.js +23 -149
  44. package/lib/codegen/template/templateChild.d.ts +0 -1
  45. package/lib/codegen/template/templateChild.js +11 -68
  46. package/lib/codegen/template/vFor.js +10 -13
  47. package/lib/codegen/template/vIf.js +5 -3
  48. package/lib/codegen/template/vSlot.js +20 -15
  49. package/lib/codegen/utils/boundary.d.ts +3 -0
  50. package/lib/codegen/utils/boundary.js +13 -0
  51. package/lib/codegen/utils/camelized.js +3 -3
  52. package/lib/codegen/utils/escaped.js +4 -2
  53. package/lib/codegen/utils/index.d.ts +4 -5
  54. package/lib/codegen/utils/index.js +49 -21
  55. package/lib/codegen/utils/merge.d.ts +2 -2
  56. package/lib/codegen/utils/merge.js +9 -9
  57. package/lib/codegen/utils/stringLiteralKey.js +6 -3
  58. package/lib/codegen/utils/transform.d.ts +8 -0
  59. package/lib/codegen/utils/transform.js +27 -0
  60. package/lib/codegen/utils/unicode.js +4 -2
  61. package/lib/compilerOptions.d.ts +5 -2
  62. package/lib/compilerOptions.js +67 -44
  63. package/lib/languagePlugin.d.ts +1 -1
  64. package/lib/languagePlugin.js +5 -6
  65. package/lib/parsers/scriptRanges.d.ts +4 -8
  66. package/lib/parsers/scriptRanges.js +3 -2
  67. package/lib/parsers/scriptSetupRanges.d.ts +2 -6
  68. package/lib/parsers/scriptSetupRanges.js +3 -2
  69. package/lib/parsers/utils.d.ts +4 -6
  70. package/lib/parsers/utils.js +22 -27
  71. package/lib/plugins/vue-template-inline-css.js +2 -6
  72. package/lib/plugins/vue-template-inline-ts.js +12 -14
  73. package/lib/plugins/vue-tsx.d.ts +14 -32
  74. package/lib/plugins/vue-tsx.js +114 -72
  75. package/lib/plugins.js +1 -1
  76. package/lib/types.d.ts +5 -4
  77. package/lib/utils/parseSfc.js +7 -3
  78. package/lib/utils/shared.d.ts +1 -1
  79. package/lib/utils/shared.js +7 -6
  80. package/lib/utils/signals.d.ts +2 -2
  81. package/lib/utils/signals.js +8 -6
  82. package/lib/virtualCode/embeddedCodes.d.ts +12 -0
  83. package/lib/virtualCode/embeddedCodes.js +249 -0
  84. package/lib/{virtualFile/vueFile.d.ts → virtualCode/index.d.ts} +9 -9
  85. package/lib/virtualCode/index.js +81 -0
  86. package/lib/virtualCode/ir.d.ts +4 -0
  87. package/lib/{virtualFile/computedSfc.js → virtualCode/ir.js} +59 -94
  88. package/lib/virtualCode/normalize.d.ts +2 -0
  89. package/lib/virtualCode/normalize.js +170 -0
  90. package/package.json +4 -4
  91. package/lib/codegen/style/classProperty.d.ts +0 -2
  92. package/lib/codegen/style/classProperty.js +0 -18
  93. package/lib/codegen/style/imports.d.ts +0 -2
  94. package/lib/codegen/style/imports.js +0 -27
  95. package/lib/codegen/template/elementChildren.d.ts +0 -5
  96. package/lib/codegen/template/elementChildren.js +0 -12
  97. package/lib/codegen/utils/wrapWith.d.ts +0 -2
  98. package/lib/codegen/utils/wrapWith.js +0 -15
  99. package/lib/virtualFile/computedEmbeddedCodes.d.ts +0 -4
  100. package/lib/virtualFile/computedEmbeddedCodes.js +0 -262
  101. package/lib/virtualFile/computedSfc.d.ts +0 -6
  102. package/lib/virtualFile/computedVueSfc.d.ts +0 -4
  103. package/lib/virtualFile/computedVueSfc.js +0 -41
  104. package/lib/virtualFile/embeddedFile.d.ts +0 -11
  105. package/lib/virtualFile/embeddedFile.js +0 -14
  106. package/lib/virtualFile/vueFile.js +0 -49
@@ -1,6 +1,5 @@
1
1
  import type { Sfc, VueLanguagePlugin } from '../types';
2
2
  export declare const tsCodegen: WeakMap<Sfc, {
3
- getLang: () => string;
4
3
  getScriptRanges: () => {
5
4
  exportDefault: (import("../types").TextRange & {
6
5
  expression: import("../types").TextRange;
@@ -15,22 +14,14 @@ export declare const tsCodegen: WeakMap<Sfc, {
15
14
  name: import("../types").TextRange | undefined;
16
15
  inheritAttrs: string | undefined;
17
16
  } | undefined;
18
- bindings: {
19
- range: import("../types").TextRange;
20
- moduleName?: string;
21
- isDefaultImport?: boolean;
22
- isNamespace?: boolean;
23
- }[];
17
+ bindings: import("../types").TextRange[];
18
+ components: import("../types").TextRange[];
24
19
  } | undefined;
25
20
  getScriptSetupRanges: () => {
26
21
  leadingCommentEndOffset: number;
27
22
  importSectionEndOffset: number;
28
- bindings: {
29
- range: import("../types").TextRange;
30
- moduleName?: string;
31
- isDefaultImport?: boolean;
32
- isNamespace?: boolean;
33
- }[];
23
+ bindings: import("../types").TextRange[];
24
+ components: import("../types").TextRange[];
34
25
  defineModel: {
35
26
  localName?: import("../types").TextRange;
36
27
  name?: import("../types").TextRange;
@@ -121,14 +112,11 @@ export declare const tsCodegen: WeakMap<Sfc, {
121
112
  getSetupSlotsAssignName: () => string | undefined;
122
113
  getGeneratedScript: () => {
123
114
  codes: import("../types").Code[];
124
- generatedTemplate: boolean;
125
- generatedPropsType: boolean;
126
- bypassDefineComponent: boolean;
127
- bindingNames: Set<string>;
115
+ generatedTypes: Set<string>;
128
116
  localTypes: {
129
117
  generate: () => Generator<string, void, unknown>;
130
118
  readonly PrettifyLocal: string;
131
- readonly WithDefaultsLocal: string;
119
+ readonly WithDefaults: string;
132
120
  readonly WithSlots: string;
133
121
  readonly PropsChildren: string;
134
122
  readonly TypePropsToOption: string;
@@ -138,6 +126,7 @@ export declare const tsCodegen: WeakMap<Sfc, {
138
126
  };
139
127
  getGeneratedTemplate: () => {
140
128
  codes: import("../types").Code[];
129
+ generatedTypes: Set<string>;
141
130
  currentInfo: {
142
131
  ignoreError?: boolean;
143
132
  expectError?: {
@@ -150,7 +139,6 @@ export declare const tsCodegen: WeakMap<Sfc, {
150
139
  };
151
140
  };
152
141
  resolveCodeFeatures: (features: import("../types").VueCodeInformation) => import("../types").VueCodeInformation;
153
- inlineTsAsts: Map<string, import("typescript").SourceFile> | undefined;
154
142
  inVFor: boolean;
155
143
  slots: {
156
144
  name: string;
@@ -164,16 +152,9 @@ export declare const tsCodegen: WeakMap<Sfc, {
164
152
  propsVar: string;
165
153
  }[];
166
154
  dollarVars: Set<string>;
167
- accessExternalVariables: Map<string, Set<number>>;
155
+ componentAccessMap: Map<string, Map<string, Set<number>>>;
168
156
  blockConditions: string[];
169
- scopedClasses: {
170
- source: string;
171
- className: string;
172
- offset: number;
173
- }[];
174
- emptyClassOffsets: number[];
175
157
  inlayHints: import("../codegen/inlayHints").InlayHintInfo[];
176
- bindingAttrLocs: import("@vue/compiler-dom").SourceLocation[];
177
158
  inheritedAttrVars: Set<string>;
178
159
  templateRefs: Map<string, {
179
160
  typeExp: string;
@@ -186,18 +167,19 @@ export declare const tsCodegen: WeakMap<Sfc, {
186
167
  singleRootElTypes: Set<string>;
187
168
  singleRootNodes: Set<import("@vue/compiler-dom").ElementNode | null>;
188
169
  addTemplateRef(name: string, typeExp: string, offset: number): void;
189
- accessExternalVariable(name: string, offset?: number): void;
190
- hasLocalVariable(name: string): boolean;
191
- addLocalVariable(name: string): void;
192
- removeLocalVariable(name: string): void;
170
+ recordComponentAccess(source: string, name: string, offset?: number): void;
171
+ scopes: Set<string>[];
172
+ declare(...varNames: string[]): void;
173
+ startScope(): () => Generator<import("../types").Code, any, any>;
193
174
  getInternalVariable(): string;
194
175
  getHoistVariable(originalVar: string): string;
195
176
  generateHoistVariables(): Generator<string, void, unknown>;
196
177
  generateConditionGuards(): Generator<string, void, unknown>;
197
- generateAutoImportCompletion(): Generator<import("../types").Code>;
198
178
  enter(node: import("@vue/compiler-dom").RootNode | import("@vue/compiler-dom").TemplateChildNode | import("@vue/compiler-dom").SimpleExpressionNode): boolean;
199
179
  exit(): Generator<import("../types").Code>;
200
180
  } | undefined;
181
+ getImportComponentNames: () => Set<string>;
182
+ getSetupExposed: () => Set<string>;
201
183
  }>;
202
184
  declare const plugin: VueLanguagePlugin;
203
185
  export default plugin;
@@ -5,6 +5,7 @@ const shared_1 = require("@vue/shared");
5
5
  const alien_signals_1 = require("alien-signals");
6
6
  const path = require("path-browserify");
7
7
  const script_1 = require("../codegen/script");
8
+ const style_1 = require("../codegen/style");
8
9
  const template_1 = require("../codegen/template");
9
10
  const compilerOptions_1 = require("../compilerOptions");
10
11
  const scriptRanges_1 = require("../parsers/scriptRanges");
@@ -16,52 +17,40 @@ const validLangs = new Set(['js', 'jsx', 'ts', 'tsx']);
16
17
  const plugin = ctx => {
17
18
  return {
18
19
  version: 2.2,
19
- requiredCompilerOptions: [
20
- 'noPropertyAccessFromIndexSignature',
21
- ],
22
- getEmbeddedCodes(fileName, sfc) {
23
- const codegen = useCodegen(fileName, sfc);
24
- return [{
25
- id: 'script_' + codegen.getLang(),
26
- lang: codegen.getLang(),
27
- }];
20
+ getEmbeddedCodes(_fileName, sfc) {
21
+ const lang = computeLang(sfc);
22
+ return [{ lang, id: 'script_' + lang }];
28
23
  },
29
24
  resolveEmbeddedCode(fileName, sfc, embeddedFile) {
30
25
  if (/script_(js|jsx|ts|tsx)/.test(embeddedFile.id)) {
31
- const codegen = useCodegen(fileName, sfc);
32
- const tsx = codegen.getGeneratedScript();
33
- embeddedFile.content = [...tsx.codes];
26
+ let codegen = exports.tsCodegen.get(sfc);
27
+ if (!codegen) {
28
+ exports.tsCodegen.set(sfc, codegen = useCodegen(fileName, sfc, ctx));
29
+ }
30
+ const generatedScript = codegen.getGeneratedScript();
31
+ embeddedFile.content = [...generatedScript.codes];
34
32
  }
35
33
  },
36
34
  };
37
- function useCodegen(fileName, sfc) {
38
- if (!exports.tsCodegen.has(sfc)) {
39
- exports.tsCodegen.set(sfc, createTsx(fileName, sfc, ctx));
40
- }
41
- return exports.tsCodegen.get(sfc);
42
- }
43
- };
44
- exports.default = plugin;
45
- function createTsx(fileName, sfc, ctx) {
46
- const ts = ctx.modules.typescript;
47
- const getRawLang = (0, alien_signals_1.computed)(() => {
35
+ function computeLang(sfc) {
36
+ let lang = sfc.scriptSetup?.lang ?? sfc.script?.lang;
48
37
  if (sfc.script && sfc.scriptSetup) {
49
38
  if (sfc.scriptSetup.lang !== 'js') {
50
- return sfc.scriptSetup.lang;
39
+ lang = sfc.scriptSetup.lang;
51
40
  }
52
41
  else {
53
- return sfc.script.lang;
42
+ lang = sfc.script.lang;
54
43
  }
55
44
  }
56
- return sfc.scriptSetup?.lang ?? sfc.script?.lang;
57
- });
58
- const getLang = (0, alien_signals_1.computed)(() => {
59
- const rawLang = getRawLang();
60
- if (rawLang && validLangs.has(rawLang)) {
61
- return rawLang;
45
+ if (lang && validLangs.has(lang)) {
46
+ return lang;
62
47
  }
63
48
  return 'ts';
64
- });
49
+ }
50
+ };
51
+ exports.default = plugin;
52
+ function useCodegen(fileName, sfc, ctx) {
53
+ const ts = ctx.modules.typescript;
65
54
  const getResolvedOptions = (0, alien_signals_1.computed)(() => {
66
55
  const options = (0, vueCompilerOptions_1.parseVueCompilerOptions)(sfc.comments);
67
56
  if (options) {
@@ -72,51 +61,46 @@ function createTsx(fileName, sfc, ctx) {
72
61
  return ctx.vueCompilerOptions;
73
62
  });
74
63
  const getScriptRanges = (0, alien_signals_1.computed)(() => sfc.script && validLangs.has(sfc.script.lang)
75
- ? (0, scriptRanges_1.parseScriptRanges)(ts, sfc.script.ast, !!sfc.scriptSetup)
64
+ ? (0, scriptRanges_1.parseScriptRanges)(ts, sfc.script.ast, getResolvedOptions())
76
65
  : undefined);
77
66
  const getScriptSetupRanges = (0, alien_signals_1.computed)(() => sfc.scriptSetup && validLangs.has(sfc.scriptSetup.lang)
78
67
  ? (0, scriptSetupRanges_1.parseScriptSetupRanges)(ts, sfc.scriptSetup.ast, getResolvedOptions())
79
68
  : undefined);
80
- const getSetupBindingNames = (0, signals_1.computedSet)(() => {
81
- const newNames = new Set();
82
- const bindings = getScriptSetupRanges()?.bindings;
83
- if (sfc.scriptSetup && bindings) {
84
- for (const { range } of bindings) {
85
- newNames.add(sfc.scriptSetup.content.slice(range.start, range.end));
69
+ const getImportComponentNames = (0, signals_1.computedSet)(() => {
70
+ const names = new Set();
71
+ const scriptSetupRanges = getScriptSetupRanges();
72
+ if (sfc.scriptSetup && scriptSetupRanges) {
73
+ for (const range of scriptSetupRanges.components) {
74
+ names.add(sfc.scriptSetup.content.slice(range.start, range.end));
86
75
  }
87
- }
88
- return newNames;
89
- });
90
- const getSetupImportComponentNames = (0, signals_1.computedSet)(() => {
91
- const newNames = new Set();
92
- const bindings = getScriptSetupRanges()?.bindings;
93
- if (sfc.scriptSetup && bindings) {
94
- for (const { range, moduleName, isDefaultImport, isNamespace } of bindings) {
95
- if (moduleName
96
- && isDefaultImport
97
- && !isNamespace
98
- && ctx.vueCompilerOptions.extensions.some(ext => moduleName.endsWith(ext))) {
99
- newNames.add(sfc.scriptSetup.content.slice(range.start, range.end));
76
+ const scriptRange = getScriptRanges();
77
+ if (sfc.script && scriptRange) {
78
+ for (const range of scriptRange.components) {
79
+ names.add(sfc.script.content.slice(range.start, range.end));
100
80
  }
101
81
  }
102
82
  }
103
- return newNames;
83
+ return names;
104
84
  });
105
- const getSetupDestructuredPropNames = (0, signals_1.computedSet)(() => {
106
- const newNames = new Set(getScriptSetupRanges()?.defineProps?.destructured?.keys());
107
- const rest = getScriptSetupRanges()?.defineProps?.destructuredRest;
85
+ const getSetupConsts = (0, signals_1.computedSet)(() => {
86
+ const scriptSetupRanges = getScriptSetupRanges();
87
+ const names = new Set([
88
+ ...scriptSetupRanges?.defineProps?.destructured?.keys() ?? [],
89
+ ...getImportComponentNames(),
90
+ ]);
91
+ const rest = scriptSetupRanges?.defineProps?.destructuredRest;
108
92
  if (rest) {
109
- newNames.add(rest);
93
+ names.add(rest);
110
94
  }
111
- return newNames;
95
+ return names;
112
96
  });
113
- const getSetupTemplateRefNames = (0, signals_1.computedSet)(() => {
97
+ const getSetupRefs = (0, signals_1.computedSet)(() => {
114
98
  const newNames = new Set(getScriptSetupRanges()?.useTemplateRef
115
99
  .map(({ name }) => name)
116
100
  .filter(name => name !== undefined));
117
101
  return newNames;
118
102
  });
119
- const setupHasDefineSlots = (0, alien_signals_1.computed)(() => !!getScriptSetupRanges()?.defineSlots);
103
+ const hasDefineSlots = (0, alien_signals_1.computed)(() => !!getScriptSetupRanges()?.defineSlots);
120
104
  const getSetupPropsAssignName = (0, alien_signals_1.computed)(() => getScriptSetupRanges()?.defineProps?.name);
121
105
  const getSetupSlotsAssignName = (0, alien_signals_1.computed)(() => getScriptSetupRanges()?.defineSlots?.name);
122
106
  const getSetupInheritAttrs = (0, alien_signals_1.computed)(() => {
@@ -148,42 +132,100 @@ function createTsx(fileName, sfc, ctx) {
148
132
  }
149
133
  return (0, template_1.generateTemplate)({
150
134
  ts,
151
- compilerOptions: ctx.compilerOptions,
152
135
  vueCompilerOptions: getResolvedOptions(),
153
136
  template: sfc.template,
154
- scriptSetupBindingNames: getSetupBindingNames(),
155
- scriptSetupImportComponentNames: getSetupImportComponentNames(),
156
- destructuredPropNames: getSetupDestructuredPropNames(),
157
- templateRefNames: getSetupTemplateRefNames(),
158
- hasDefineSlots: setupHasDefineSlots(),
137
+ setupConsts: getSetupConsts(),
138
+ setupRefs: getSetupRefs(),
139
+ hasDefineSlots: hasDefineSlots(),
159
140
  propsAssignName: getSetupPropsAssignName(),
160
141
  slotsAssignName: getSetupSlotsAssignName(),
161
142
  inheritAttrs: getSetupInheritAttrs(),
162
143
  selfComponentName: getComponentSelfName(),
163
144
  });
164
145
  });
146
+ const getGeneratedStyle = (0, alien_signals_1.computed)(() => {
147
+ if (!sfc.styles.length) {
148
+ return;
149
+ }
150
+ return (0, style_1.generateStyle)({
151
+ ts,
152
+ vueCompilerOptions: getResolvedOptions(),
153
+ styles: sfc.styles,
154
+ setupConsts: getSetupConsts(),
155
+ setupRefs: getSetupRefs(),
156
+ });
157
+ });
158
+ const getTemplateStartTagOffset = (0, alien_signals_1.computed)(() => {
159
+ if (sfc.template) {
160
+ return sfc.template.start - sfc.template.startTagEnd;
161
+ }
162
+ });
163
+ const getSetupExposed = (0, signals_1.computedSet)(() => {
164
+ const allVars = new Set();
165
+ const scriptSetupRanges = getScriptSetupRanges();
166
+ if (!sfc.scriptSetup || !scriptSetupRanges) {
167
+ return allVars;
168
+ }
169
+ for (const range of scriptSetupRanges.bindings) {
170
+ const name = sfc.scriptSetup.content.slice(range.start, range.end);
171
+ allVars.add(name);
172
+ }
173
+ const scriptRanges = getScriptRanges();
174
+ if (sfc.script && scriptRanges) {
175
+ for (const range of scriptRanges.bindings) {
176
+ const name = sfc.script.content.slice(range.start, range.end);
177
+ allVars.add(name);
178
+ }
179
+ }
180
+ if (!allVars.size) {
181
+ return allVars;
182
+ }
183
+ const exposedNames = new Set();
184
+ const generatedTemplate = getGeneratedTemplate();
185
+ const generatedStyle = getGeneratedStyle();
186
+ for (const [name] of generatedTemplate?.componentAccessMap ?? []) {
187
+ if (allVars.has(name)) {
188
+ exposedNames.add(name);
189
+ }
190
+ }
191
+ for (const [name] of generatedStyle?.componentAccessMap ?? []) {
192
+ if (allVars.has(name)) {
193
+ exposedNames.add(name);
194
+ }
195
+ }
196
+ for (const component of sfc.template?.ast?.components ?? []) {
197
+ const testNames = new Set([(0, shared_1.camelize)(component), (0, shared_1.capitalize)((0, shared_1.camelize)(component))]);
198
+ for (const testName of testNames) {
199
+ if (allVars.has(testName)) {
200
+ exposedNames.add(testName);
201
+ }
202
+ }
203
+ }
204
+ return exposedNames;
205
+ });
165
206
  const getGeneratedScript = (0, alien_signals_1.computed)(() => {
166
207
  return (0, script_1.generateScript)({
167
208
  ts,
168
- compilerOptions: ctx.compilerOptions,
169
209
  vueCompilerOptions: getResolvedOptions(),
170
- sfc,
210
+ script: sfc.script,
211
+ scriptSetup: sfc.scriptSetup,
212
+ setupExposed: getSetupExposed(),
171
213
  fileName,
172
- lang: getLang(),
173
214
  scriptRanges: getScriptRanges(),
174
215
  scriptSetupRanges: getScriptSetupRanges(),
175
216
  templateCodegen: getGeneratedTemplate(),
176
- destructuredPropNames: getSetupDestructuredPropNames(),
177
- templateRefNames: getSetupTemplateRefNames(),
217
+ templateStartTagOffset: getTemplateStartTagOffset(),
218
+ styleCodegen: getGeneratedStyle(),
178
219
  });
179
220
  });
180
221
  return {
181
- getLang,
182
222
  getScriptRanges,
183
223
  getScriptSetupRanges,
184
224
  getSetupSlotsAssignName,
185
225
  getGeneratedScript,
186
226
  getGeneratedTemplate,
227
+ getImportComponentNames,
228
+ getSetupExposed,
187
229
  };
188
230
  }
189
231
  //# sourceMappingURL=vue-tsx.js.map
package/lib/plugins.js CHANGED
@@ -37,6 +37,7 @@ function createPlugins(pluginContext) {
37
37
  file_md_1.default,
38
38
  file_html_1.default,
39
39
  vue_root_tags_1.default,
40
+ vue_tsx_1.default,
40
41
  vue_script_js_1.default,
41
42
  vue_style_css_1.default,
42
43
  vue_template_html_1.default,
@@ -46,7 +47,6 @@ function createPlugins(pluginContext) {
46
47
  vue_sfc_customblocks_1.default,
47
48
  vue_sfc_scripts_1.default,
48
49
  vue_sfc_template_1.default,
49
- vue_tsx_1.default,
50
50
  ...pluginContext.vueCompilerOptions.plugins,
51
51
  ];
52
52
  const pluginInstances = plugins
package/lib/types.d.ts CHANGED
@@ -3,7 +3,7 @@ import type * as CompilerDOM from '@vue/compiler-dom';
3
3
  import type { SFCParseResult } from '@vue/compiler-sfc';
4
4
  import type { Segment } from 'muggle-string';
5
5
  import type * as ts from 'typescript';
6
- import type { VueEmbeddedCode } from './virtualFile/embeddedFile';
6
+ import type { VueEmbeddedCode } from './virtualCode/embeddedCodes';
7
7
  export type { SFCParseResult } from '@vue/compiler-sfc';
8
8
  export { VueEmbeddedCode };
9
9
  export type RawVueCompilerOptions = Partial<Omit<VueCompilerOptions, 'target' | 'globalTypesPath' | 'plugins'>> & {
@@ -13,7 +13,8 @@ export type RawVueCompilerOptions = Partial<Omit<VueCompilerOptions, 'target' |
13
13
  plugins?: string[];
14
14
  };
15
15
  export interface VueCodeInformation extends CodeInformation {
16
- __combineOffset?: number;
16
+ __importCompletion?: boolean;
17
+ __combineToken?: symbol;
17
18
  __linkedToken?: symbol;
18
19
  }
19
20
  export type Code = Segment<VueCodeInformation>;
@@ -64,7 +65,7 @@ export interface VueCompilerOptions {
64
65
  experimentalModelPropName: Record<string, Record<string, boolean | Record<string, string> | Record<string, string>[]>>;
65
66
  }
66
67
  export declare const validVersions: readonly [2, 2.1, 2.2];
67
- export type VueLanguagePluginReturn = {
68
+ export interface VueLanguagePluginReturn {
68
69
  version: typeof validVersions[number];
69
70
  name?: string;
70
71
  order?: number;
@@ -92,7 +93,7 @@ export type VueLanguagePluginReturn = {
92
93
  lang: string;
93
94
  }[];
94
95
  resolveEmbeddedCode?(fileName: string, sfc: Sfc, embeddedFile: VueEmbeddedCode): void;
95
- };
96
+ }
96
97
  export type VueLanguagePlugin = (ctx: {
97
98
  modules: {
98
99
  typescript: typeof ts;
@@ -109,7 +109,11 @@ function createBlock(node, source) {
109
109
  block.__src = parseAttr(p, node);
110
110
  }
111
111
  else if (isScriptBlock(block)) {
112
- if (p.name === 'setup' || p.name === 'vapor') {
112
+ if (p.name === 'vapor') {
113
+ block.setup ??= attrs[p.name];
114
+ block.__generic ??= true;
115
+ }
116
+ else if (p.name === 'setup') {
113
117
  block.setup = attrs[p.name];
114
118
  }
115
119
  else if (p.name === 'generic') {
@@ -138,9 +142,9 @@ function parseAttr(p, node) {
138
142
  if (!p.value) {
139
143
  return true;
140
144
  }
141
- const offset = (0, shared_1.getAttributeValueOffset)(p.value);
145
+ const [content, offset] = (0, shared_1.normalizeAttributeValue)(p.value);
142
146
  return {
143
- text: p.value.content,
147
+ text: content,
144
148
  offset: offset - node.loc.start.offset,
145
149
  quotes: offset > p.value.loc.start.offset,
146
150
  };
@@ -3,7 +3,7 @@ import type * as ts from 'typescript';
3
3
  import type { Sfc, TextRange } from '../types';
4
4
  export { hyphenate as hyphenateTag } from '@vue/shared';
5
5
  export declare function hyphenateAttr(str: string): string;
6
- export declare function getAttributeValueOffset(node: CompilerDOM.TextNode): number;
6
+ export declare function normalizeAttributeValue(node: CompilerDOM.TextNode): readonly [string, number];
7
7
  export declare function getElementTagOffsets(node: CompilerDOM.ElementNode, template: NonNullable<Sfc['template']>): [number] | [number, number];
8
8
  export declare function getStartEnd(ts: typeof import('typescript'), node: ts.Node, ast: ts.SourceFile): TextRange;
9
9
  export declare function getNodeText(ts: typeof import('typescript'), node: ts.Node, ast: ts.SourceFile): string;
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.hyphenateTag = void 0;
4
4
  exports.hyphenateAttr = hyphenateAttr;
5
- exports.getAttributeValueOffset = getAttributeValueOffset;
5
+ exports.normalizeAttributeValue = normalizeAttributeValue;
6
6
  exports.getElementTagOffsets = getElementTagOffsets;
7
7
  exports.getStartEnd = getStartEnd;
8
8
  exports.getNodeText = getNodeText;
@@ -17,12 +17,13 @@ function hyphenateAttr(str) {
17
17
  }
18
18
  return hyphencase;
19
19
  }
20
- function getAttributeValueOffset(node) {
21
- let offset = node.loc.start.offset;
22
- if (node.loc.source.startsWith('"') || node.loc.source.startsWith("'")) {
23
- offset++;
20
+ function normalizeAttributeValue(node) {
21
+ const { source, start } = node.loc;
22
+ if ((source.startsWith('"') && source.endsWith('"'))
23
+ || (source.startsWith("'") && source.endsWith("'"))) {
24
+ return [source.slice(1, -1), start.offset + 1];
24
25
  }
25
- return offset;
26
+ return [source, start.offset];
26
27
  }
27
28
  function getElementTagOffsets(node, template) {
28
29
  const tagOffsets = [
@@ -1,3 +1,3 @@
1
- export declare function computedArray<I, O>(arr: () => I[], getGetter: (item: () => I, index: number) => () => O): readonly Readonly<O>[];
1
+ export declare function reactiveArray<I, O>(getArr: () => I[], getGetter: (item: () => I, index: number) => () => O): readonly Readonly<O>[];
2
2
  export declare function computedSet<T>(source: () => Set<T>): () => Set<T>;
3
- export declare function computedItems<T>(source: () => T[], compareFn: (oldItem: T, newItem: T) => boolean): () => T[];
3
+ export declare function computedArray<T>(source: () => T[], compareFn?: (oldItem: T, newItem: T) => boolean): () => T[];
@@ -1,14 +1,16 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.computedArray = computedArray;
3
+ exports.reactiveArray = reactiveArray;
4
4
  exports.computedSet = computedSet;
5
- exports.computedItems = computedItems;
5
+ exports.computedArray = computedArray;
6
6
  const alien_signals_1 = require("alien-signals");
7
- function computedArray(arr, getGetter) {
7
+ function reactiveArray(getArr, getGetter) {
8
+ const arr = (0, alien_signals_1.computed)(getArr);
8
9
  const length = (0, alien_signals_1.computed)(() => arr().length);
9
10
  const keys = (0, alien_signals_1.computed)(() => {
10
- const keys = [];
11
- for (let i = 0; i < length(); i++) {
11
+ const l = length();
12
+ const keys = new Array(l);
13
+ for (let i = 0; i < l; i++) {
12
14
  keys.push(String(i));
13
15
  }
14
16
  return keys;
@@ -52,7 +54,7 @@ function computedSet(source) {
52
54
  return newValue;
53
55
  });
54
56
  }
55
- function computedItems(source, compareFn) {
57
+ function computedArray(source, compareFn = (oldItem, newItem) => oldItem === newItem) {
56
58
  return (0, alien_signals_1.computed)(oldArr => {
57
59
  oldArr ??= [];
58
60
  const newArr = source();
@@ -0,0 +1,12 @@
1
+ import type { Mapping, VirtualCode } from '@volar/language-core';
2
+ import type { Code, Sfc, VueLanguagePluginReturn } from '../types';
3
+ export declare class VueEmbeddedCode {
4
+ id: string;
5
+ lang: string;
6
+ content: Code[];
7
+ parentCodeId?: string;
8
+ linkedCodeMappings: Mapping[];
9
+ embeddedCodes: VueEmbeddedCode[];
10
+ constructor(id: string, lang: string, content: Code[]);
11
+ }
12
+ export declare function useEmbeddedCodes(plugins: VueLanguagePluginReturn[], fileName: string, sfc: Sfc): () => VirtualCode[];