@vue-jsx-vapor/macros 2.2.0 → 2.3.1

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 (80) hide show
  1. package/dist/api.cjs +6 -13
  2. package/dist/api.d.cts +8 -4
  3. package/dist/api.d.ts +8 -4
  4. package/dist/api.js +3 -14
  5. package/dist/astro.cjs +14 -18
  6. package/dist/astro.d.cts +4 -3
  7. package/dist/astro.d.ts +4 -3
  8. package/dist/astro.js +13 -17
  9. package/dist/chunk-BCwAaXi7.cjs +31 -0
  10. package/dist/core-B1Tt-ieP.cjs +438 -0
  11. package/dist/core-cHgZBgtA.js +377 -0
  12. package/dist/esbuild.cjs +12 -14
  13. package/dist/esbuild.d.cts +6 -5
  14. package/dist/esbuild.d.ts +6 -5
  15. package/dist/esbuild.js +9 -11
  16. package/dist/index.cjs +8 -12
  17. package/dist/index.d.cts +5 -5
  18. package/dist/index.d.ts +5 -5
  19. package/dist/index.js +6 -12
  20. package/dist/nuxt.cjs +23 -26
  21. package/dist/nuxt.d.cts +6 -5
  22. package/dist/nuxt.d.ts +6 -5
  23. package/dist/nuxt.js +19 -23
  24. package/dist/options-CNIhAQHD.cjs +27 -0
  25. package/dist/options-pbSvpKdV.js +20 -0
  26. package/dist/options.cjs +2 -5
  27. package/dist/options.d-B3WOiT_L.d.cts +26 -0
  28. package/dist/options.d-DtyRfe-9.d.ts +26 -0
  29. package/dist/options.d.cts +2 -22
  30. package/dist/options.d.ts +2 -22
  31. package/dist/options.js +3 -6
  32. package/dist/raw-3ZelnSQR.cjs +62 -0
  33. package/dist/raw-9SXDNxBH.js +55 -0
  34. package/dist/raw.cjs +5 -9
  35. package/dist/raw.d.cts +5 -4
  36. package/dist/raw.d.ts +5 -4
  37. package/dist/raw.js +5 -8
  38. package/dist/rolldown.cjs +12 -14
  39. package/dist/rolldown.d.cts +4 -3
  40. package/dist/rolldown.d.ts +4 -3
  41. package/dist/rolldown.js +9 -11
  42. package/dist/rollup.cjs +12 -14
  43. package/dist/rollup.d.cts +6 -5
  44. package/dist/rollup.d.ts +6 -5
  45. package/dist/rollup.js +9 -11
  46. package/dist/rspack.cjs +12 -14
  47. package/dist/rspack.d.cts +4 -3
  48. package/dist/rspack.d.ts +4 -3
  49. package/dist/rspack.js +9 -11
  50. package/dist/src-BfZoaRPY.js +9 -0
  51. package/dist/src-DwQLomPw.cjs +16 -0
  52. package/dist/vite-C5QxH0B9.cjs +13 -0
  53. package/dist/vite-DPLCEtsm.js +7 -0
  54. package/dist/vite.cjs +8 -12
  55. package/dist/vite.d.cts +6 -5
  56. package/dist/vite.d.ts +6 -5
  57. package/dist/vite.js +7 -10
  58. package/dist/volar.cjs +220 -371
  59. package/dist/volar.d.cts +5 -4
  60. package/dist/volar.d.ts +5 -4
  61. package/dist/volar.js +217 -369
  62. package/dist/webpack-1cYmRdvx.js +7 -0
  63. package/dist/webpack-B-EPKx0G.cjs +13 -0
  64. package/dist/webpack.cjs +8 -12
  65. package/dist/webpack.d.cts +6 -5
  66. package/dist/webpack.d.ts +6 -5
  67. package/dist/webpack.js +7 -10
  68. package/package.json +3 -3
  69. package/dist/chunk-35H4MC4N.cjs +0 -65
  70. package/dist/chunk-53TNKVYD.cjs +0 -29
  71. package/dist/chunk-DANY2WQD.js +0 -29
  72. package/dist/chunk-JWJVYLYI.cjs +0 -12
  73. package/dist/chunk-LPH34H6O.cjs +0 -566
  74. package/dist/chunk-LVZNHMZC.js +0 -12
  75. package/dist/chunk-NL4CWOW2.cjs +0 -10
  76. package/dist/chunk-RC5ZHWIN.js +0 -10
  77. package/dist/chunk-TWP2JCYQ.js +0 -566
  78. package/dist/chunk-WOWB5VHY.js +0 -65
  79. package/dist/chunk-WZIZSQGW.js +0 -10
  80. package/dist/chunk-YCL7HGD4.cjs +0 -10
package/dist/volar.js CHANGED
@@ -1,401 +1,249 @@
1
- import {
2
- resolveOptions
3
- } from "./chunk-DANY2WQD.js";
4
-
5
- // src/volar.ts
6
- import { createFilter } from "@vue-macros/common";
7
- import { createPlugin } from "ts-macro";
8
-
9
- // src/volar/index.ts
10
- import {
11
- HELPER_PREFIX as HELPER_PREFIX4
12
- } from "@vue-macros/common";
13
- import { replaceRange as replaceRange4 } from "ts-macro";
1
+ import { resolveOptions } from "./options-pbSvpKdV.js";
2
+ import { HELPER_PREFIX, createFilter } from "@vue-macros/common";
3
+ import { allCodeFeatures, createPlugin, replaceRange } from "ts-macro";
4
+ import { generateClassProperty } from "@vue/language-core/lib/codegen/style/classProperty.js";
5
+ import { parseCssClassNames } from "@vue/language-core/lib/utils/parseCssClassNames.js";
14
6
 
15
- // src/volar/define-component.ts
16
- import { allCodeFeatures, replaceRange } from "ts-macro";
7
+ //#region src/volar/define-component.ts
17
8
  function transformDefineComponent(node, options) {
18
- const { codes, source, ast } = options;
19
- replaceRange(codes, node.arguments[0].end, node.end - 1);
20
- const componentOptions = node.arguments[1];
21
- replaceRange(
22
- codes,
23
- node.getStart(ast),
24
- node.expression.end + 1,
25
- "(",
26
- [node.expression.getText(ast), source, node.getStart(ast), allCodeFeatures],
27
- "(() => ({}) as any, ",
28
- componentOptions ? [
29
- componentOptions.getText(ast),
30
- source,
31
- componentOptions.getStart(ast),
32
- allCodeFeatures
33
- ] : "",
34
- "), "
35
- );
9
+ const { codes, source, ast } = options;
10
+ replaceRange(codes, node.arguments[0].end, node.end - 1);
11
+ const componentOptions = node.arguments[1];
12
+ replaceRange(codes, node.getStart(ast), node.expression.end + 1, "(", [
13
+ node.expression.getText(ast),
14
+ source,
15
+ node.getStart(ast),
16
+ allCodeFeatures
17
+ ], "(() => ({}) as any, ", componentOptions ? [
18
+ componentOptions.getText(ast),
19
+ source,
20
+ componentOptions.getStart(ast),
21
+ allCodeFeatures
22
+ ] : "", "), ");
36
23
  }
37
24
 
38
- // src/volar/transform.ts
39
- import { HELPER_PREFIX as HELPER_PREFIX2 } from "@vue-macros/common";
40
- import { replaceRange as replaceRange3 } from "ts-macro";
41
-
42
- // src/volar/define-style.ts
43
- import { HELPER_PREFIX } from "@vue-macros/common";
44
- import { generateClassProperty } from "@vue/language-core/lib/codegen/style/classProperty.js";
45
- import { parseCssClassNames } from "@vue/language-core/lib/utils/parseCssClassNames.js";
46
- import { replaceRange as replaceRange2 } from "ts-macro";
25
+ //#endregion
26
+ //#region src/volar/define-style.ts
47
27
  function transformDefineStyle(defineStyles, options) {
48
- if (!defineStyles?.length) return;
49
- const { ts, codes, ast } = options;
50
- defineStyles.forEach(({ expression, isCssModules }, index) => {
51
- if (isCssModules && expression?.arguments[0] && !expression.typeArguments && ts.isTemplateLiteral(expression.arguments[0])) {
52
- replaceRange2(
53
- codes,
54
- expression.arguments.pos - 1,
55
- expression.arguments.pos - 1,
56
- `<${HELPER_PREFIX}PrettifyLocal<{}`,
57
- ...generateCssClassesType(
58
- expression.arguments[0].getText(ast).slice(1, -1),
59
- expression.arguments[0].getStart(ast) + 1,
60
- index
61
- ),
62
- ">>"
63
- );
64
- }
65
- addEmbeddedCode(expression, index, options);
66
- });
28
+ if (!defineStyles?.length) return;
29
+ const { ts, codes, ast } = options;
30
+ defineStyles.forEach(({ expression, isCssModules }, index) => {
31
+ if (isCssModules && expression?.arguments[0] && !expression.typeArguments && ts.isTemplateLiteral(expression.arguments[0])) replaceRange(codes, expression.arguments.pos - 1, expression.arguments.pos - 1, `<${HELPER_PREFIX}PrettifyLocal<{}`, ...generateCssClassesType(expression.arguments[0].getText(ast).slice(1, -1), expression.arguments[0].getStart(ast) + 1, index), ">>");
32
+ addEmbeddedCode(expression, index, options);
33
+ });
67
34
  }
68
35
  function* generateCssClassesType(css, offset, index) {
69
- for (const className of [...parseCssClassNames(css)]) {
70
- yield* generateClassProperty(
71
- index,
72
- className.text,
73
- className.offset + offset,
74
- "string"
75
- );
76
- }
36
+ for (const className of [...parseCssClassNames(css)]) yield* generateClassProperty(index, className.text, className.offset + offset, "string");
77
37
  }
78
38
  function addEmbeddedCode(expression, index, options) {
79
- const { ts, ast } = options;
80
- const languageId = ts.isPropertyAccessExpression(expression.expression) && ts.isIdentifier(expression.expression.name) ? expression.expression.name.text : "css";
81
- const style = expression.arguments[0];
82
- const styleText = style.getText(ast).slice(1, -1).replaceAll(/\$\{.*\}/g, (str) => "_".repeat(str.length));
83
- options.embeddedCodes.push({
84
- id: `style_${index}`,
85
- languageId,
86
- snapshot: {
87
- getText: (start, end) => styleText.slice(start, end),
88
- getLength: () => styleText.length,
89
- getChangeRange: () => void 0
90
- },
91
- mappings: [
92
- {
93
- sourceOffsets: [style.getStart(ast) + 1],
94
- generatedOffsets: [0],
95
- lengths: [styleText.length],
96
- data: {
97
- completion: true,
98
- format: true,
99
- navigation: true,
100
- semantic: true,
101
- structure: true,
102
- verification: true
103
- }
104
- }
105
- ],
106
- embeddedCodes: []
107
- });
39
+ const { ts, ast } = options;
40
+ const languageId = ts.isPropertyAccessExpression(expression.expression) && ts.isIdentifier(expression.expression.name) ? expression.expression.name.text : "css";
41
+ const style = expression.arguments[0];
42
+ const styleText = style.getText(ast).slice(1, -1).replaceAll(/\$\{.*\}/g, (str) => "_".repeat(str.length));
43
+ options.embeddedCodes.push({
44
+ id: `style_${index}`,
45
+ languageId,
46
+ snapshot: {
47
+ getText: (start, end) => styleText.slice(start, end),
48
+ getLength: () => styleText.length,
49
+ getChangeRange: () => void 0
50
+ },
51
+ mappings: [{
52
+ sourceOffsets: [style.getStart(ast) + 1],
53
+ generatedOffsets: [0],
54
+ lengths: [styleText.length],
55
+ data: {
56
+ completion: true,
57
+ format: true,
58
+ navigation: true,
59
+ semantic: true,
60
+ structure: true,
61
+ verification: true
62
+ }
63
+ }],
64
+ embeddedCodes: []
65
+ });
108
66
  }
109
67
 
110
- // src/volar/transform.ts
68
+ //#endregion
69
+ //#region src/volar/transform.ts
111
70
  function transformJsxMacros(rootMap, options) {
112
- const { ts, codes, ast } = options;
113
- for (const [root, map] of rootMap) {
114
- transformDefineStyle(map.defineStyle, options);
115
- if (!root?.body) continue;
116
- const asyncModifier = root.modifiers?.find(
117
- (modifier) => modifier.kind === ts.SyntaxKind.AsyncKeyword
118
- );
119
- if (asyncModifier && map.defineComponent)
120
- replaceRange3(codes, asyncModifier.pos, asyncModifier.end);
121
- const result = `({}) as __VLS_PickNotAny<typeof ${HELPER_PREFIX2}ctx.render, {}> & { __ctx: typeof ${HELPER_PREFIX2}ctx }`;
122
- const propsType = root.parameters[0]?.type ? String(root.parameters[0].type.getText(ast)) : "{}";
123
- replaceRange3(
124
- codes,
125
- root.parameters.pos,
126
- root.parameters.pos,
127
- ts.isArrowFunction(root) && root.parameters.pos === root.pos ? "(" : "",
128
- `${HELPER_PREFIX2}props: typeof ${HELPER_PREFIX2}ctx.props & ${propsType}, `,
129
- `${HELPER_PREFIX2}placeholder?: {}, `,
130
- `${HELPER_PREFIX2}ctx = {} as Awaited<ReturnType<typeof ${HELPER_PREFIX2}setup>>, `,
131
- `${HELPER_PREFIX2}setup = (${asyncModifier ? "async" : ""}(`
132
- );
133
- if (ts.isArrowFunction(root)) {
134
- replaceRange3(
135
- codes,
136
- root.end,
137
- root.end,
138
- `))${root.pos === root.parameters.pos ? ")" : ""} => `,
139
- result
140
- );
141
- } else {
142
- replaceRange3(
143
- codes,
144
- root.body.getStart(ast),
145
- root.body.getStart(ast),
146
- "=>"
147
- );
148
- replaceRange3(codes, root.end, root.end, `)){ return `, result, "}");
149
- }
150
- ts.forEachChild(root.body, (node) => {
151
- if (ts.isReturnStatement(node) && node.expression) {
152
- const props = [...map.defineModel ?? []];
153
- const elements = root.parameters[0] && !root.parameters[0].type && ts.isObjectBindingPattern(root.parameters[0].name) ? root.parameters[0].name.elements : [];
154
- for (const element of elements) {
155
- if (ts.isIdentifier(element.name))
156
- props.push(
157
- `${element.name.escapedText}${element.initializer && ts.isNonNullExpression(element.initializer) ? ":" : "?:"} typeof ${element.name.escapedText}`
158
- );
159
- }
160
- const shouldWrapByCall = (ts.isArrowFunction(node.expression) || ts.isFunctionExpression(node.expression)) && map.defineComponent;
161
- replaceRange3(
162
- codes,
163
- node.getStart(ast),
164
- node.expression.getStart(ast),
165
- `return {
166
- props: {} as { ${props.join(", ")} }`,
167
- `,
168
- slots: {} as ${map.defineSlots ?? "{}"}`,
169
- `,
170
- expose: (exposed: import('vue').ShallowUnwrapRef<${map.defineExpose ?? "{}"}>) => {}`,
171
- `,
172
- render: `,
173
- shouldWrapByCall ? "(" : ""
174
- );
175
- replaceRange3(
176
- codes,
177
- node.expression.end,
178
- node.expression.end,
179
- shouldWrapByCall ? ")()" : "",
180
- `
181
- }`
182
- );
183
- }
184
- });
185
- }
71
+ const { ts, codes, ast } = options;
72
+ for (const [root, map] of rootMap) {
73
+ transformDefineStyle(map.defineStyle, options);
74
+ if (!root?.body) continue;
75
+ const asyncModifier = root.modifiers?.find((modifier) => modifier.kind === ts.SyntaxKind.AsyncKeyword);
76
+ if (asyncModifier && map.defineComponent) replaceRange(codes, asyncModifier.pos, asyncModifier.end);
77
+ const result = `({}) as __VLS_PickNotAny<typeof ${HELPER_PREFIX}ctx.render, {}> & { __ctx: typeof ${HELPER_PREFIX}ctx }`;
78
+ const propsType = root.parameters[0]?.type ? String(root.parameters[0].type.getText(ast)) : "{}";
79
+ replaceRange(codes, root.parameters.pos, root.parameters.pos, ts.isArrowFunction(root) && root.parameters.pos === root.pos ? "(" : "", `${HELPER_PREFIX}props: typeof ${HELPER_PREFIX}ctx.props & ${propsType}, `, `${HELPER_PREFIX}placeholder?: {}, `, `${HELPER_PREFIX}ctx = {} as Awaited<ReturnType<typeof ${HELPER_PREFIX}setup>>, `, `${HELPER_PREFIX}setup = (${asyncModifier ? "async" : ""}(`);
80
+ if (ts.isArrowFunction(root)) replaceRange(codes, root.end, root.end, `))${root.pos === root.parameters.pos ? ")" : ""} => `, result);
81
+ else {
82
+ replaceRange(codes, root.body.getStart(ast), root.body.getStart(ast), "=>");
83
+ replaceRange(codes, root.end, root.end, `)){ return `, result, "}");
84
+ }
85
+ ts.forEachChild(root.body, (node) => {
86
+ if (ts.isReturnStatement(node) && node.expression) {
87
+ const props = [...map.defineModel ?? []];
88
+ const elements = root.parameters[0] && !root.parameters[0].type && ts.isObjectBindingPattern(root.parameters[0].name) ? root.parameters[0].name.elements : [];
89
+ for (const element of elements) if (ts.isIdentifier(element.name)) props.push(`${element.name.escapedText}${element.initializer && ts.isNonNullExpression(element.initializer) ? ":" : "?:"} typeof ${element.name.escapedText}`);
90
+ const shouldWrapByCall = (ts.isArrowFunction(node.expression) || ts.isFunctionExpression(node.expression)) && map.defineComponent;
91
+ replaceRange(codes, node.getStart(ast), node.expression.getStart(ast), `const ${HELPER_PREFIX}render = `, shouldWrapByCall ? "(" : "");
92
+ replaceRange(codes, node.expression.end, node.expression.end, shouldWrapByCall ? ")()" : "", `
93
+ return {
94
+ props: {} as {${props.join(", ")}},
95
+ slots: {} as ${map.defineSlots ?? "{}"},
96
+ expose: (exposed: import('vue').ShallowUnwrapRef<${map.defineExpose ?? "{}"}>) => {},
97
+ render: ${HELPER_PREFIX}render,
98
+ }`);
99
+ }
100
+ });
101
+ }
186
102
  }
187
103
 
188
- // src/volar/global-types.ts
189
- import { HELPER_PREFIX as HELPER_PREFIX3 } from "@vue-macros/common";
104
+ //#endregion
105
+ //#region src/volar/global-types.ts
190
106
  function getGlobalTypes(options) {
191
- const defineSlots = options.defineSlots.alias.flatMap((alias) => [
192
- `declare function ${alias}<T extends Record<string, any>>(): Partial<T>;`,
193
- `declare function ${alias}<T extends Record<string, any>>(slots: T): T;
194
- `
195
- ]).join("");
196
- const defineExpose = options.defineExpose.alias.map(
197
- (alias) => `declare function ${alias}<Exposed extends Record<string, any> = Record<string, any>>(exposed?: Exposed): Exposed;`
198
- ).join("");
199
- const defineStyle = options.defineStyle.alias.map(
200
- (alias) => `declare const ${alias}: { <T>(...args: ${HELPER_PREFIX3}StyleArgs): T; scss: <T>(...args: ${HELPER_PREFIX3}StyleArgs)=> T; sass: <T>(...args: ${HELPER_PREFIX3}StyleArgs)=> T; stylus: <T>(...args: ${HELPER_PREFIX3}StyleArgs)=> T; less: <T>(...args: ${HELPER_PREFIX3}StyleArgs)=> T; postcss: <T>(...args: ${HELPER_PREFIX3}StyleArgs)=> T };
201
- `
202
- ).join("");
203
- const defineModel = options.defineModel.alias.map(
204
- (alias) => alias === "defineModel" ? "defineModel" : `defineModel: ${alias}`
205
- ).join(", ");
206
- const defineComponent = options.defineComponent.alias.map(
207
- (alias) => ["defineComponent", "defineVaporComponent"].includes(alias) ? "" : `defineComponent: ${alias}`
208
- ).filter(Boolean).join(", ");
209
- return `
107
+ const defineSlots = options.defineSlots.alias.flatMap((alias) => [`declare function ${alias}<T extends Record<string, any>>(): Partial<T>;`, `declare function ${alias}<T extends Record<string, any>>(slots: T): T;\n`]).join("");
108
+ const defineExpose = options.defineExpose.alias.map((alias) => `declare function ${alias}<Exposed extends Record<string, any> = Record<string, any>>(exposed?: Exposed): Exposed;`).join("");
109
+ const defineStyle = options.defineStyle.alias.map((alias) => `declare const ${alias}: { <T>(...args: ${HELPER_PREFIX}StyleArgs): T; scss: <T>(...args: ${HELPER_PREFIX}StyleArgs)=> T; sass: <T>(...args: ${HELPER_PREFIX}StyleArgs)=> T; stylus: <T>(...args: ${HELPER_PREFIX}StyleArgs)=> T; less: <T>(...args: ${HELPER_PREFIX}StyleArgs)=> T; postcss: <T>(...args: ${HELPER_PREFIX}StyleArgs)=> T };\n`).join("");
110
+ const defineModel = options.defineModel.alias.map((alias) => alias === "defineModel" ? "defineModel" : `defineModel: ${alias}`).join(", ");
111
+ const defineComponent = options.defineComponent.alias.map((alias) => ["defineComponent", "defineVaporComponent"].includes(alias) ? "" : `defineComponent: ${alias}`).filter(Boolean).join(", ");
112
+ return `
210
113
  declare const { ${defineModel}, ${defineComponent} }: typeof import('vue')
211
114
  ${defineSlots}
212
115
  ${defineExpose}
213
116
  ${defineStyle}
214
- type ${HELPER_PREFIX3}StyleArgs = [style: string, options?: { scoped?: boolean }];
215
- type ${HELPER_PREFIX3}PrettifyLocal<T> = { [K in keyof T]: T[K]; } & {};
117
+ type ${HELPER_PREFIX}StyleArgs = [style: string, options?: { scoped?: boolean }];
118
+ type ${HELPER_PREFIX}PrettifyLocal<T> = { [K in keyof T]: T[K]; } & {};
216
119
  // @ts-ignore
217
120
  type __VLS_IsAny<T> = 0 extends 1 & T ? true : false; type __VLS_PickNotAny<A, B> = __VLS_IsAny<A> extends true ? B : A;
218
121
  `;
219
122
  }
220
123
 
221
- // src/volar/index.ts
124
+ //#endregion
125
+ //#region src/volar/index.ts
222
126
  function getMacro(node, ts, options) {
223
- if (!node) return;
224
- if (ts.isVariableStatement(node)) {
225
- return ts.forEachChild(node.declarationList, (decl) => getExpression(decl));
226
- } else {
227
- return getExpression(node);
228
- }
229
- function getExpression(decl) {
230
- if (ts.isVariableDeclaration(decl) && decl.initializer) {
231
- const initializer = ts.isCallExpression(decl.initializer) && ts.isIdentifier(decl.initializer.expression) && decl.initializer.expression.escapedText === "$" && decl.initializer.arguments[0] ? decl.initializer.arguments[0] : decl.initializer;
232
- const expression = getMacroExpression(initializer);
233
- if (expression) {
234
- return {
235
- expression,
236
- initializer: decl.initializer,
237
- isRequired: ts.isNonNullExpression(initializer)
238
- };
239
- }
240
- } else if (ts.isExpressionStatement(decl)) {
241
- const expression = getMacroExpression(decl.expression);
242
- if (expression)
243
- return {
244
- expression,
245
- initializer: decl.expression,
246
- isRequired: ts.isNonNullExpression(decl.expression)
247
- };
248
- }
249
- }
250
- function getMacroExpression(node2) {
251
- if (ts.isNonNullExpression(node2)) {
252
- node2 = node2.expression;
253
- }
254
- if (!ts.isCallExpression(node2)) return;
255
- const expression = ts.isPropertyAccessExpression(node2.expression) ? node2.expression : node2;
256
- return ts.isIdentifier(expression.expression) && [
257
- ...options.defineModel.alias,
258
- ...options.defineSlots.alias,
259
- ...options.defineStyle.alias,
260
- ...options.defineExpose.alias,
261
- ...options.defineComponent.alias
262
- ].includes(expression.expression.escapedText) && node2;
263
- }
127
+ if (!node) return;
128
+ if (ts.isVariableStatement(node)) return ts.forEachChild(node.declarationList, (decl) => getExpression(decl));
129
+ else return getExpression(node);
130
+ function getExpression(decl) {
131
+ if (ts.isVariableDeclaration(decl) && decl.initializer) {
132
+ const initializer = ts.isCallExpression(decl.initializer) && ts.isIdentifier(decl.initializer.expression) && decl.initializer.expression.escapedText === "$" && decl.initializer.arguments[0] ? decl.initializer.arguments[0] : decl.initializer;
133
+ const expression = getMacroExpression(initializer);
134
+ if (expression) return {
135
+ expression,
136
+ initializer: decl.initializer,
137
+ isRequired: ts.isNonNullExpression(initializer)
138
+ };
139
+ } else if (ts.isExpressionStatement(decl)) {
140
+ const expression = getMacroExpression(decl.expression);
141
+ if (expression) return {
142
+ expression,
143
+ initializer: decl.expression,
144
+ isRequired: ts.isNonNullExpression(decl.expression)
145
+ };
146
+ }
147
+ }
148
+ function getMacroExpression(node$1) {
149
+ if (ts.isNonNullExpression(node$1)) node$1 = node$1.expression;
150
+ if (!ts.isCallExpression(node$1)) return;
151
+ const expression = ts.isPropertyAccessExpression(node$1.expression) ? node$1.expression : node$1;
152
+ return ts.isIdentifier(expression.expression) && [
153
+ ...options.defineModel.alias,
154
+ ...options.defineSlots.alias,
155
+ ...options.defineStyle.alias,
156
+ ...options.defineExpose.alias,
157
+ ...options.defineComponent.alias
158
+ ].includes(expression.expression.escapedText) && node$1;
159
+ }
264
160
  }
265
161
  function getRootMap(options) {
266
- const { ts, ast, codes } = options;
267
- const rootMap = /* @__PURE__ */ new Map();
268
- function walk(node, parents) {
269
- ts.forEachChild(node, (child) => {
270
- parents.unshift(node);
271
- walk(child, parents);
272
- parents.shift();
273
- });
274
- const root = parents[1] && (ts.isArrowFunction(parents[1]) || ts.isFunctionExpression(parents[1]) || ts.isFunctionDeclaration(parents[1])) ? parents[1] : void 0;
275
- if (root && parents[2] && ts.isCallExpression(parents[2]) && !parents[2].typeArguments && options.defineComponent.alias.includes(parents[2].expression.getText(ast))) {
276
- if (!rootMap.has(root)) rootMap.set(root, {});
277
- if (!rootMap.get(root).defineComponent) {
278
- rootMap.get(root).defineComponent = true;
279
- transformDefineComponent(parents[2], options);
280
- }
281
- }
282
- const macro = getMacro(node, ts, options);
283
- if (!macro) return;
284
- const { expression, initializer } = macro;
285
- let isRequired = macro.isRequired;
286
- if (!rootMap.has(root)) rootMap.set(root, {});
287
- const macroName = expression.expression.getText(ast);
288
- if (macroName.startsWith("defineStyle")) {
289
- ;
290
- (rootMap.get(root).defineStyle ??= []).push({
291
- expression,
292
- isCssModules: !!ts.isVariableStatement(node)
293
- });
294
- }
295
- if (!root) return;
296
- if (options.defineModel.alias.includes(macroName)) {
297
- const modelName = expression.arguments[0] && ts.isStringLiteralLike(expression.arguments[0]) ? expression.arguments[0].text : "modelValue";
298
- const modelOptions = expression.arguments[0] && ts.isStringLiteralLike(expression.arguments[0]) ? expression.arguments[1] : expression.arguments[0];
299
- if (modelOptions && ts.isObjectLiteralExpression(modelOptions)) {
300
- let hasRequired = false;
301
- for (const prop of modelOptions.properties) {
302
- if (ts.isPropertyAssignment(prop) && prop.name.getText(ast) === "required") {
303
- hasRequired = true;
304
- isRequired = prop.initializer.kind === ts.SyntaxKind.TrueKeyword;
305
- }
306
- }
307
- if (!hasRequired && isRequired) {
308
- replaceRange4(
309
- codes,
310
- modelOptions.end - 1,
311
- modelOptions.end - 1,
312
- `${!modelOptions.properties.hasTrailingComma && modelOptions.properties.length ? "," : ""} required: true`
313
- );
314
- }
315
- } else if (isRequired) {
316
- replaceRange4(
317
- codes,
318
- expression.arguments.end,
319
- expression.arguments.end,
320
- `${!expression.arguments.hasTrailingComma && expression.arguments.length ? "," : ""} { required: true }`
321
- );
322
- }
323
- const id = toValidAssetId(modelName, `${HELPER_PREFIX4}model`);
324
- const typeString = `import('vue').UnwrapRef<typeof ${id}>`;
325
- const defineModel = rootMap.get(root).defineModel ??= [];
326
- defineModel.push(
327
- `${modelName.includes("-") ? `'${modelName}'` : modelName}${isRequired ? ":" : "?:"} ${typeString}`,
328
- `'onUpdate:${modelName}'?: ($event: ${typeString}) => any`
329
- );
330
- if (expression.typeArguments?.[1]) {
331
- defineModel.push(
332
- `${modelName}Modifiers?: Partial<Record<${expression.typeArguments[1].getText(ast)}, boolean>>`
333
- );
334
- }
335
- replaceRange4(
336
- codes,
337
- initializer.getStart(ast),
338
- initializer.getStart(ast),
339
- `// @ts-ignore
340
- ${id};
341
- let ${id} = `
342
- );
343
- } else if (options.defineSlots.alias.includes(macroName)) {
344
- replaceRange4(
345
- codes,
346
- expression.getStart(ast),
347
- expression.getStart(ast),
348
- `// @ts-ignore
349
- ${HELPER_PREFIX4}slots;
350
- const ${HELPER_PREFIX4}slots = `
351
- );
352
- rootMap.get(root).defineSlots = `Partial<typeof ${HELPER_PREFIX4}slots>`;
353
- } else if (options.defineExpose.alias.includes(macroName)) {
354
- replaceRange4(
355
- codes,
356
- expression.getStart(ast),
357
- expression.getStart(ast),
358
- `// @ts-ignore
359
- ${HELPER_PREFIX4}exposed;
360
- const ${HELPER_PREFIX4}exposed = `
361
- );
362
- rootMap.get(root).defineExpose = `typeof ${HELPER_PREFIX4}exposed`;
363
- }
364
- }
365
- ts.forEachChild(ast, (node) => walk(node, []));
366
- return rootMap;
162
+ const { ts, ast, codes } = options;
163
+ const rootMap = new Map();
164
+ function walk(node, parents) {
165
+ ts.forEachChild(node, (child) => {
166
+ parents.unshift(node);
167
+ walk(child, parents);
168
+ parents.shift();
169
+ });
170
+ const root = parents[1] && (ts.isArrowFunction(parents[1]) || ts.isFunctionExpression(parents[1]) || ts.isFunctionDeclaration(parents[1])) ? parents[1] : void 0;
171
+ if (root && parents[2] && ts.isCallExpression(parents[2]) && !parents[2].typeArguments && options.defineComponent.alias.includes(parents[2].expression.getText(ast))) {
172
+ if (!rootMap.has(root)) rootMap.set(root, {});
173
+ if (!rootMap.get(root).defineComponent) {
174
+ rootMap.get(root).defineComponent = true;
175
+ transformDefineComponent(parents[2], options);
176
+ }
177
+ }
178
+ const macro = getMacro(node, ts, options);
179
+ if (!macro) return;
180
+ const { expression, initializer } = macro;
181
+ let isRequired = macro.isRequired;
182
+ if (!rootMap.has(root)) rootMap.set(root, {});
183
+ const macroName = expression.expression.getText(ast);
184
+ if (macroName.startsWith("defineStyle")) (rootMap.get(root).defineStyle ??= []).push({
185
+ expression,
186
+ isCssModules: !!ts.isVariableStatement(node)
187
+ });
188
+ if (!root) return;
189
+ if (options.defineModel.alias.includes(macroName)) {
190
+ const modelName = expression.arguments[0] && ts.isStringLiteralLike(expression.arguments[0]) ? expression.arguments[0].text : "modelValue";
191
+ const modelOptions = expression.arguments[0] && ts.isStringLiteralLike(expression.arguments[0]) ? expression.arguments[1] : expression.arguments[0];
192
+ if (modelOptions && ts.isObjectLiteralExpression(modelOptions)) {
193
+ let hasRequired = false;
194
+ for (const prop of modelOptions.properties) if (ts.isPropertyAssignment(prop) && prop.name.getText(ast) === "required") {
195
+ hasRequired = true;
196
+ isRequired = prop.initializer.kind === ts.SyntaxKind.TrueKeyword;
197
+ }
198
+ if (!hasRequired && isRequired) replaceRange(codes, modelOptions.end - 1, modelOptions.end - 1, `${!modelOptions.properties.hasTrailingComma && modelOptions.properties.length ? "," : ""} required: true`);
199
+ } else if (isRequired) replaceRange(codes, expression.arguments.end, expression.arguments.end, `${!expression.arguments.hasTrailingComma && expression.arguments.length ? "," : ""} { required: true }`);
200
+ const id = toValidAssetId(modelName, `${HELPER_PREFIX}model`);
201
+ const typeString = `import('vue').UnwrapRef<typeof ${id}>`;
202
+ const defineModel = rootMap.get(root).defineModel ??= [];
203
+ defineModel.push(`${modelName.includes("-") ? `'${modelName}'` : modelName}${isRequired ? ":" : "?:"} ${typeString}`, `'onUpdate:${modelName}'?: ($event: ${typeString}) => any`);
204
+ if (expression.typeArguments?.[1]) defineModel.push(`${modelName}Modifiers?: Partial<Record<${expression.typeArguments[1].getText(ast)}, boolean>>`);
205
+ replaceRange(codes, initializer.getStart(ast), initializer.getStart(ast), `// @ts-ignore\n${id};\nlet ${id} = `);
206
+ } else if (options.defineSlots.alias.includes(macroName)) {
207
+ replaceRange(codes, expression.getStart(ast), expression.getStart(ast), `// @ts-ignore\n${HELPER_PREFIX}slots;\nconst ${HELPER_PREFIX}slots = `);
208
+ rootMap.get(root).defineSlots = `Partial<typeof ${HELPER_PREFIX}slots>`;
209
+ } else if (options.defineExpose.alias.includes(macroName)) {
210
+ replaceRange(codes, expression.getStart(ast), expression.getStart(ast), `// @ts-ignore\n${HELPER_PREFIX}exposed;\nconst ${HELPER_PREFIX}exposed = `);
211
+ rootMap.get(root).defineExpose = `typeof ${HELPER_PREFIX}exposed`;
212
+ }
213
+ }
214
+ ts.forEachChild(ast, (node) => walk(node, []));
215
+ return rootMap;
367
216
  }
368
217
  function toValidAssetId(name, type) {
369
- return `_${type}_${name.replaceAll(/\W/g, (searchValue, replaceValue) => {
370
- return searchValue === "-" ? "_" : name.charCodeAt(replaceValue).toString();
371
- })}`;
218
+ return `_${type}_${name.replaceAll(/\W/g, (searchValue, replaceValue) => {
219
+ return searchValue === "-" ? "_" : name.charCodeAt(replaceValue).toString();
220
+ })}`;
372
221
  }
373
222
 
374
- // src/volar.ts
375
- var plugin = createPlugin(
376
- ({ ts }, userOptions = {}) => {
377
- const resolvedOptions = resolveOptions(userOptions);
378
- const filter = createFilter(resolvedOptions);
379
- return {
380
- name: "@vue-jsx-vapor/macros",
381
- resolveVirtualCode(virtualCode) {
382
- const { filePath, codes } = virtualCode;
383
- if (!filter(filePath)) return;
384
- const options = {
385
- ts,
386
- ...virtualCode,
387
- ...resolvedOptions
388
- };
389
- const rootMap = getRootMap(options);
390
- if (rootMap.size) {
391
- transformJsxMacros(rootMap, options);
392
- codes.push(getGlobalTypes(options));
393
- }
394
- }
395
- };
396
- }
397
- );
223
+ //#endregion
224
+ //#region src/volar.ts
225
+ const plugin = createPlugin(({ ts }, userOptions = {}) => {
226
+ const resolvedOptions = resolveOptions(userOptions);
227
+ const filter = createFilter(resolvedOptions);
228
+ return {
229
+ name: "@vue-jsx-vapor/macros",
230
+ resolveVirtualCode(virtualCode) {
231
+ const { filePath, codes } = virtualCode;
232
+ if (!filter(filePath)) return;
233
+ const options = {
234
+ ts,
235
+ ...virtualCode,
236
+ ...resolvedOptions
237
+ };
238
+ const rootMap = getRootMap(options);
239
+ if (rootMap.size) {
240
+ transformJsxMacros(rootMap, options);
241
+ codes.push(getGlobalTypes(options));
242
+ }
243
+ }
244
+ };
245
+ });
398
246
  var volar_default = plugin;
399
- export {
400
- volar_default as default
401
- };
247
+
248
+ //#endregion
249
+ export { volar_default as default };
@@ -0,0 +1,7 @@
1
+ import { src_default } from "./src-BfZoaRPY.js";
2
+
3
+ //#region src/webpack.ts
4
+ var webpack_default = src_default.webpack;
5
+
6
+ //#endregion
7
+ export { webpack_default };
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ const require_src = require('./src-DwQLomPw.cjs');
3
+
4
+ //#region src/webpack.ts
5
+ var webpack_default = require_src.src_default.webpack;
6
+
7
+ //#endregion
8
+ Object.defineProperty(exports, 'webpack_default', {
9
+ enumerable: true,
10
+ get: function () {
11
+ return webpack_default;
12
+ }
13
+ });