@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
@@ -1,566 +0,0 @@
1
- // src/core/helper/use-model.ts?raw
2
- var use_model_default = 'import { customRef, watchSyncEffect } from "vue";\nexport function useModel(props, name, options = {}) {\n const res = customRef((track, trigger) => {\n let localValue = options && options.default;\n let prevEmittedValue;\n watchSyncEffect(() => {\n const propValue = props[name];\n if (!Object.is(prevEmittedValue, propValue)) {\n localValue = propValue;\n trigger();\n }\n });\n return {\n get() {\n track();\n return options.get ? options.get(localValue) : localValue;\n },\n set(value) {\n if (Object.is(value, localValue)) return;\n localValue = value;\n trigger();\n const emittedValue = prevEmittedValue = options.set ? options.set(value) : value;\n for (const emit of [props[`onUpdate:${name}`]].flat()) {\n if (typeof emit === "function") emit(emittedValue);\n }\n }\n };\n });\n res[Symbol.iterator] = () => {\n let i = 0;\n return {\n next() {\n if (i < 2) {\n return {\n value: i++ ? props[`${name}Modifiers`] || {} : res,\n done: false\n };\n } else {\n return { done: true };\n }\n }\n };\n };\n return res;\n}\n';
3
-
4
- // src/core/helper/with-defaults.ts?raw
5
- var with_defaults_default = "function resolveDefaultProps(paths) {\n const result = {};\n for (const path of Object.keys(paths)) {\n const segments = path.split(/[.?[\\]]/).filter(Boolean);\n let current = result;\n for (let i = 0; i < segments.length; i++) {\n const segment = segments[i];\n if (i === segments.length - 1) {\n current[segment] = paths[path];\n } else {\n if (!current[segment]) {\n current[segment] = Number.isNaN(Number(segments[i + 1])) ? {} : [];\n }\n current = current[segment];\n }\n }\n }\n return result;\n}\nexport function createPropsDefaultProxy(props, defaults) {\n const defaultProps = resolveDefaultProps(defaults);\n const result = {};\n for (const key of [\n .../* @__PURE__ */ new Set([...Object.keys(props), ...Object.keys(defaultProps)])\n ]) {\n Object.defineProperty(result, key, {\n enumerable: true,\n get: () => props[key] === void 0 ? defaultProps[key] : props[key]\n });\n }\n return result;\n}\n";
6
-
7
- // src/core/helper/index.ts
8
- var helperPrefix = "vue-jsx-vapor/macros";
9
- var useModelHelperId = `${helperPrefix}/use-model`;
10
- var withDefaultsHelperId = `${helperPrefix}/with-defaults`;
11
-
12
- // src/core/restructure.ts
13
- import {
14
- HELPER_PREFIX,
15
- importHelperFn
16
- } from "@vue-macros/common";
17
- import { walkIdentifiers } from "@vue/compiler-sfc";
18
- function restructure(s, node, options = {}) {
19
- let index = 0;
20
- const propList = [];
21
- for (const param of node.params) {
22
- const path = `${HELPER_PREFIX}props${index++ || ""}`;
23
- const props = getProps(param, path, s, [], options);
24
- if (props) {
25
- const hasDefaultValue = props.some((i) => i.defaultValue);
26
- s.overwrite(param.start, param.end, path);
27
- propList.push(
28
- ...hasDefaultValue ? props.map((i) => ({
29
- ...i,
30
- path: i.path.replace(HELPER_PREFIX, `${HELPER_PREFIX}default_`)
31
- })) : props
32
- );
33
- }
34
- }
35
- if (propList.length) {
36
- const defaultValues = {};
37
- const rests = [];
38
- for (const prop of propList) {
39
- if (prop.defaultValue) {
40
- const basePath = prop.path.split(/\.|\[/)[0];
41
- (defaultValues[basePath] ??= []).push(prop);
42
- }
43
- if (prop.isRest) {
44
- rests.push(prop);
45
- }
46
- }
47
- for (const [path, values] of Object.entries(defaultValues)) {
48
- const createPropsDefaultProxy = importHelperFn(
49
- s,
50
- 0,
51
- "createPropsDefaultProxy",
52
- void 0,
53
- options.withDefaultsFrom ?? withDefaultsHelperId
54
- );
55
- const resolvedPath = path.replace(
56
- `${HELPER_PREFIX}default_`,
57
- HELPER_PREFIX
58
- );
59
- const resolvedValues = values.map(
60
- (i) => `'${i.path.replace(path, "")}${i.value}': ${i.defaultValue}`
61
- ).join(", ");
62
- prependFunctionalNode(
63
- node,
64
- s,
65
- `
66
- const ${path} = ${createPropsDefaultProxy}(${resolvedPath}, {${resolvedValues}})`
67
- );
68
- }
69
- for (const [index2, rest] of rests.entries()) {
70
- prependFunctionalNode(
71
- node,
72
- s,
73
- options.generateRestProps?.(rest.name, index2, rests) ?? `
74
- const ${rest.name} = ${importHelperFn(
75
- s,
76
- 0,
77
- "createPropsRestProxy"
78
- )}(${rest.path}, [${rest.value}])`
79
- );
80
- }
81
- walkIdentifiers(
82
- node.body,
83
- (id, parent) => {
84
- const prop = propList.find((i) => i.name === id.name);
85
- if (prop && !prop.isRest) {
86
- s.overwrite(
87
- id.start,
88
- id.end,
89
- `${parent?.type === "ObjectProperty" && parent.shorthand ? `${id.name}: ` : ""}${prop.path}${prop.value}`
90
- );
91
- }
92
- },
93
- false
94
- );
95
- }
96
- return propList;
97
- }
98
- function getProps(node, path = "", s, props = [], options) {
99
- const properties = node.type === "ObjectPattern" ? node.properties : node.type === "ArrayPattern" ? node.elements : [];
100
- if (!properties.length) return;
101
- const propNames = [];
102
- properties.forEach((prop, index) => {
103
- if (prop?.type === "Identifier") {
104
- props.push({ name: prop.name, path, value: `[${index}]` });
105
- propNames.push(`'${prop.name}'`);
106
- } else if (prop?.type === "AssignmentPattern" && prop.left.type === "Identifier") {
107
- props.push({
108
- path,
109
- name: prop.left.name,
110
- value: `[${index}]`,
111
- defaultValue: s.slice(prop.right.start, prop.right.end)
112
- });
113
- propNames.push(`'${prop.left.name}'`);
114
- } else if (prop?.type === "ObjectProperty" && prop.key.type === "Identifier") {
115
- if (prop.value.type === "AssignmentPattern" && prop.value.left.type === "Identifier") {
116
- props.push({
117
- path,
118
- name: prop.value.left.name,
119
- value: `.${prop.key.name}`,
120
- defaultValue: s.slice(prop.value.right.start, prop.value.right.end),
121
- isRequired: prop.value.right.type === "TSNonNullExpression"
122
- });
123
- } else if (!getProps(prop.value, `${path}.${prop.key.name}`, s, props, options)) {
124
- props.push({
125
- path,
126
- name: prop.value.type === "Identifier" ? prop.value.name : prop.key.name,
127
- value: `.${prop.key.name}`
128
- });
129
- }
130
- propNames.push(`'${prop.key.name}'`);
131
- } else if (prop?.type === "RestElement" && prop.argument.type === "Identifier" && !prop.argument.name.startsWith(`${HELPER_PREFIX}props`)) {
132
- props.push({
133
- path,
134
- name: prop.argument.name,
135
- value: propNames.join(", "),
136
- isRest: true
137
- });
138
- } else if (prop) {
139
- getProps(prop, `${path}[${index}]`, s, props, options);
140
- }
141
- });
142
- return props.length ? props : void 0;
143
- }
144
- function prependFunctionalNode(node, s, result) {
145
- const isBlockStatement = node.body.type === "BlockStatement";
146
- const start = node.body.extra?.parenthesized ? node.body.extra.parenStart : node.body.start;
147
- s.appendRight(
148
- start + (isBlockStatement ? 1 : 0),
149
- `${result};${!isBlockStatement ? "return " : ""}`
150
- );
151
- if (!isBlockStatement) {
152
- s.appendLeft(start, "{");
153
- s.appendRight(node.end, "}");
154
- }
155
- }
156
-
157
- // src/core/index.ts
158
- import {
159
- babelParse,
160
- generateTransform,
161
- getLang,
162
- HELPER_PREFIX as HELPER_PREFIX2,
163
- MagicStringAST,
164
- walkAST as walkAST3
165
- } from "@vue-macros/common";
166
-
167
- // src/core/define-component/index.ts
168
- import { importHelperFn as importHelperFn3 } from "@vue-macros/common";
169
- import { walkIdentifiers as walkIdentifiers2 } from "@vue/compiler-sfc";
170
-
171
- // src/core/define-component/await.ts
172
- import {
173
- importHelperFn as importHelperFn2,
174
- walkAST
175
- } from "@vue-macros/common";
176
- var isFunctionType = (node) => {
177
- return /Function(?:Expression|Declaration)$|Method$/.test(node.type);
178
- };
179
- function transformAwait(root, s) {
180
- if (root.body.type !== "BlockStatement") return;
181
- let hasAwait = false;
182
- for (const node of root.body.body) {
183
- if (node.type === "VariableDeclaration" && !node.declare || node.type.endsWith("Statement")) {
184
- const scope = [root.body.body];
185
- walkAST(node, {
186
- enter(child, parent) {
187
- if (isFunctionType(child)) {
188
- this.skip();
189
- }
190
- if (child.type === "BlockStatement") {
191
- scope.push(child.body);
192
- }
193
- if (child.type === "AwaitExpression") {
194
- hasAwait = true;
195
- const currentScope = scope.at(-1);
196
- const needsSemi = !!currentScope?.some((n, i) => {
197
- return (scope.length === 1 || i > 0) && n.type === "ExpressionStatement" && n.start === child.start;
198
- });
199
- processAwait(
200
- s,
201
- child,
202
- needsSemi,
203
- parent.type === "ExpressionStatement"
204
- );
205
- }
206
- },
207
- leave(node2) {
208
- if (node2.type === "BlockStatement") scope.pop();
209
- }
210
- });
211
- }
212
- }
213
- if (hasAwait) {
214
- s.prependLeft(root.body.start + 1, `
215
- let __temp, __restore
216
- `);
217
- }
218
- }
219
- function processAwait(s, node, needSemi, isStatement) {
220
- const argumentStart = node.argument.extra && node.argument.extra.parenthesized ? node.argument.extra.parenStart : node.argument.start;
221
- const argumentStr = s.slice(argumentStart, node.argument.end);
222
- const containsNestedAwait = /\bawait\b/.test(argumentStr);
223
- s.overwrite(
224
- node.start,
225
- argumentStart,
226
- `${needSemi ? `;` : ``}(
227
- ([__temp,__restore] = ${importHelperFn2(
228
- s,
229
- 0,
230
- `withAsyncContext`
231
- )}(${containsNestedAwait ? `async ` : ``}() => `
232
- );
233
- s.appendLeft(
234
- node.end,
235
- `)),
236
- ${isStatement ? `` : `__temp = `}await __temp,
237
- __restore()${isStatement ? `` : `,
238
- __temp`}
239
- )`
240
- );
241
- }
242
-
243
- // src/core/define-component/index.ts
244
- function transformDefineComponent(root, propsName, map, s) {
245
- if (!map.defineComponent) return;
246
- const defineComponentName = s.sliceNode(map.defineComponent.callee);
247
- if (defineComponentName && !["defineComponent", "defineVaporComponent"].includes(defineComponentName)) {
248
- importHelperFn3(s, 0, "defineComponent", defineComponentName);
249
- }
250
- let hasRestProp = false;
251
- const props = {};
252
- if (root.params[0]) {
253
- if (root.params[0].type === "Identifier") {
254
- getWalkedIds(root, propsName).forEach((id) => props[id] = null);
255
- } else {
256
- const restructuredProps = restructure(s, root, {
257
- generateRestProps: (restPropsName, index, list) => {
258
- if (index === list.length - 1) {
259
- hasRestProp = true;
260
- const useAttrs = importHelperFn3(s, 0, "useAttrs");
261
- return `const ${restPropsName} = ${useAttrs}()`;
262
- }
263
- }
264
- });
265
- for (const prop of restructuredProps) {
266
- if (prop.path.endsWith("props") && !prop.isRest) {
267
- props[prop.name] = prop.isRequired ? "{ required: true }" : null;
268
- }
269
- }
270
- }
271
- }
272
- for (const { expression, isRequired } of map.defineModel || []) {
273
- const modelOptions = expression.arguments[0]?.type === "ObjectExpression" ? expression.arguments[0] : expression.arguments[1]?.type === "ObjectExpression" ? expression.arguments[1] : void 0;
274
- const options = {};
275
- if (isRequired) options.required = true;
276
- for (const prop of modelOptions?.properties || []) {
277
- if (prop.type === "ObjectProperty" && prop.key.type === "Identifier" && ["validator", "type", "required"].includes(prop.key.name)) {
278
- options[prop.key.name] = s.sliceNode(prop.value);
279
- }
280
- }
281
- const propName = expression.arguments[0]?.type === "StringLiteral" ? expression.arguments[0].value : "modelValue";
282
- props[propName] = Object.keys(options).length ? `{ ${Object.entries(options).map(([key, value]) => `${key}: ${value}`).join(", ")} }` : null;
283
- props[`onUpdate:${propName}`] = null;
284
- props[`${propName === "modelValue" ? "model" : propName}Modifiers`] = null;
285
- }
286
- const propsString = Object.entries(props).map(([key, value]) => `'${key}': ${value}`).join(", ");
287
- if (propsString) {
288
- const argument = map.defineComponent.arguments[1];
289
- if (!argument) {
290
- s.appendRight(
291
- root.end,
292
- `, {${hasRestProp ? "inheritAttrs: false," : ""} props: { ${propsString} } }`
293
- );
294
- } else if (argument.type === "ObjectExpression") {
295
- prependObjectExpression(argument, "props", `{ ${propsString} }`, s);
296
- if (hasRestProp) {
297
- prependObjectExpression(argument, "inheritAttrs", "false", s);
298
- }
299
- }
300
- }
301
- transformAwait(root, s);
302
- }
303
- function prependObjectExpression(argument, name, value, s) {
304
- if (!argument.properties?.find(
305
- (prop) => prop.type === "ObjectProperty" && prop.key.type === "Identifier" && prop.key.name === name
306
- )) {
307
- s.appendRight(argument.start + 1, `${name}: ${value},`);
308
- }
309
- }
310
- function getWalkedIds(root, propsName) {
311
- const walkedIds = /* @__PURE__ */ new Set();
312
- walkIdentifiers2(
313
- root.body,
314
- (id, parent) => {
315
- if (id.name === propsName && (parent?.type === "MemberExpression" || parent?.type === "OptionalMemberExpression")) {
316
- const prop = parent.property.type === "Identifier" ? parent.property.name : parent.property.type === "StringLiteral" ? parent.property.value : "";
317
- if (prop) walkedIds.add(prop);
318
- }
319
- },
320
- false
321
- );
322
- return walkedIds;
323
- }
324
-
325
- // src/core/define-expose.ts
326
- import { importHelperFn as importHelperFn4 } from "@vue-macros/common";
327
- function transformDefineExpose(node, s, version) {
328
- s.overwriteNode(node.callee, ";");
329
- s.appendRight(
330
- node.arguments[0]?.start || node.end - 1,
331
- version >= 3.6 ? `${importHelperFn4(s, 0, "currentInstance")}.exposed = ` : `${importHelperFn4(s, 0, "getCurrentInstance")}().exposed = `
332
- );
333
- }
334
-
335
- // src/core/define-model.ts
336
- import { importHelperFn as importHelperFn5 } from "@vue-macros/common";
337
- function transformDefineModel(node, propsName, s) {
338
- s.overwriteNode(
339
- node.callee,
340
- importHelperFn5(s, 0, "useModel", void 0, useModelHelperId)
341
- );
342
- s.appendRight(
343
- node.arguments[0]?.start || node.end - 1,
344
- `${propsName}, ${node.arguments[0]?.type !== "StringLiteral" ? `'modelValue',` : ""}`
345
- );
346
- }
347
-
348
- // src/core/define-slots.ts
349
- import { importHelperFn as importHelperFn6 } from "@vue-macros/common";
350
- function transformDefineSlots(node, s) {
351
- s.overwrite(
352
- node.start,
353
- node.arguments[0]?.start && node.arguments[0].start - 1 || node.typeArguments?.end || node.callee.end,
354
- `Object.assign`
355
- );
356
- const slots = `${importHelperFn6(s, 0, "useSlots")}()`;
357
- s.appendLeft(node.end - 1, `${node.arguments[0] ? "," : "{}, "}${slots}`);
358
- }
359
-
360
- // src/core/define-style.ts
361
- import { walkAST as walkAST2 } from "@vue-macros/common";
362
- import hash from "hash-sum";
363
- function transformDefineStyle(defineStyle, index, root, s, importMap) {
364
- const { expression, lang, isDeclaration } = defineStyle;
365
- if (expression.arguments[0]?.type !== "TemplateLiteral") return;
366
- let css = s.sliceNode(expression.arguments[0]).slice(1, -1);
367
- const scopeId = hash(css);
368
- const vars = /* @__PURE__ */ new Map();
369
- expression.arguments[0].expressions.forEach((exp) => {
370
- const cssVar = s.sliceNode(exp);
371
- const cssVarId = toCssVarId(cssVar, `--${scopeId}-`);
372
- s.overwrite(exp.start - 2, exp.end + 1, `var(${cssVarId})`);
373
- vars.set(cssVarId, cssVar);
374
- });
375
- let returnExpression = root && getReturnStatement(root);
376
- if (isFunctionalNode(returnExpression)) {
377
- returnExpression = getReturnStatement(returnExpression);
378
- }
379
- if (vars.size && returnExpression) {
380
- const children = returnExpression.type === "JSXElement" ? [returnExpression] : returnExpression.type === "JSXFragment" ? returnExpression.children : [];
381
- const varString = Array.from(vars.entries()).map(([key, value]) => `'${key}': ${value}`).join(", ");
382
- for (const child of children) {
383
- if (child.type === "JSXElement") {
384
- s.appendRight(
385
- child.openingElement.name.end,
386
- ` {...{style:{${varString}}}}`
387
- );
388
- }
389
- }
390
- }
391
- let scoped = !!root;
392
- if (expression.arguments[1]?.type === "ObjectExpression") {
393
- for (const prop of expression.arguments[1].properties) {
394
- if (prop.type === "ObjectProperty" && prop.key.type === "Identifier" && prop.key.name === "scoped" && prop.value.type === "BooleanLiteral") {
395
- scoped = prop.value.value;
396
- }
397
- }
398
- }
399
- if (scoped && returnExpression) {
400
- walkAST2(returnExpression, {
401
- enter(node) {
402
- if (node.type === "JSXElement" && s.sliceNode(node.openingElement.name) !== "template") {
403
- s.appendRight(node.openingElement.name.end, ` data-v-${scopeId}=""`);
404
- }
405
- }
406
- });
407
- }
408
- css = s.sliceNode(expression.arguments[0]).slice(1, -1).replaceAll(/\/\/(.*)(?=\n)/g, "/*$1*/");
409
- const module = isDeclaration ? "module." : "";
410
- const importId = `${helperPrefix}/define-style/${index}?scopeId=${scopeId}&scoped=${scoped}&lang.${module}${lang}`;
411
- importMap.set(importId, css);
412
- s.appendLeft(
413
- 0,
414
- isDeclaration ? `import style${index} from "${importId}";` : `import "${importId}";`
415
- );
416
- s.overwriteNode(expression, isDeclaration ? `style${index}` : "");
417
- }
418
- function getReturnStatement(root) {
419
- if (root.body.type === "BlockStatement") {
420
- const returnStatement = root.body.body.find(
421
- (node) => node.type === "ReturnStatement"
422
- );
423
- if (returnStatement) {
424
- return returnStatement.argument;
425
- }
426
- } else {
427
- return root.body;
428
- }
429
- }
430
- function toCssVarId(name, prefix = "") {
431
- return prefix + name.replaceAll(/\W/g, (searchValue, replaceValue) => {
432
- return searchValue === "." ? "-" : name.charCodeAt(replaceValue).toString();
433
- });
434
- }
435
-
436
- // src/core/index.ts
437
- function transformJsxMacros(code, id, importMap, options) {
438
- const s = new MagicStringAST(code);
439
- const ast = babelParse(s.original, getLang(id));
440
- const rootMap = getRootMap(ast, s, options);
441
- let defineStyleIndex = 0;
442
- for (const [root, map] of rootMap) {
443
- map.defineStyle?.forEach((defineStyle) => {
444
- transformDefineStyle(defineStyle, defineStyleIndex++, root, s, importMap);
445
- });
446
- if (root === void 0) continue;
447
- let propsName = `${HELPER_PREFIX2}props`;
448
- if (root.params[0]) {
449
- if (root.params[0].type === "Identifier") {
450
- propsName = root.params[0].name;
451
- } else if (root.params[0].type === "ObjectPattern") {
452
- const lastProp = root.params[0].properties.at(-1);
453
- if (!map.defineComponent && lastProp?.type === "RestElement" && lastProp.argument.type === "Identifier") {
454
- propsName = lastProp.argument.name;
455
- } else {
456
- s.appendRight(
457
- root.params[0].extra?.trailingComma ? root.params[0].extra?.trailingComma + 1 : lastProp?.end || root.params[0].end - 1,
458
- `${!root.params[0].extra?.trailingComma && root.params[0].properties.length ? "," : ""} ...${HELPER_PREFIX2}props`
459
- );
460
- }
461
- }
462
- } else {
463
- s.appendRight(getParamsStart(root, s.original), propsName);
464
- }
465
- if (map.defineComponent) {
466
- transformDefineComponent(root, propsName, map, s);
467
- }
468
- if (map.defineModel?.length) {
469
- map.defineModel.forEach(({ expression }) => {
470
- transformDefineModel(expression, propsName, s);
471
- });
472
- }
473
- if (map.defineSlots) {
474
- transformDefineSlots(map.defineSlots, s);
475
- }
476
- if (map.defineExpose) {
477
- transformDefineExpose(map.defineExpose, s, options.version);
478
- }
479
- }
480
- return generateTransform(s, id);
481
- }
482
- function getRootMap(ast, s, options) {
483
- const parents = [];
484
- const rootMap = /* @__PURE__ */ new Map();
485
- walkAST3(ast, {
486
- enter(node, parent) {
487
- parents.unshift(parent);
488
- const root = isFunctionalNode(parents[1]) ? parents[1] : void 0;
489
- if (root && parents[2]?.type === "CallExpression" && options.defineComponent.alias.includes(s.sliceNode(parents[2].callee))) {
490
- if (!rootMap.has(root)) rootMap.set(root, {});
491
- if (!rootMap.get(root).defineComponent) {
492
- rootMap.get(root).defineComponent = parents[2];
493
- }
494
- }
495
- const expression = node.type === "VariableDeclaration" ? node.declarations[0].init?.type === "CallExpression" && s.sliceNode(node.declarations[0].init.callee) === "$" ? node.declarations[0].init.arguments[0] : node.declarations[0].init : node.type === "ExpressionStatement" ? node.expression : void 0;
496
- if (!expression) return;
497
- const macroExpression = getMacroExpression(expression, options);
498
- if (!macroExpression) return;
499
- if (!rootMap.has(root)) rootMap.set(root, {});
500
- const macroName = s.sliceNode(
501
- macroExpression.callee.type === "MemberExpression" ? macroExpression.callee.object : macroExpression.callee
502
- );
503
- if (macroName) {
504
- if (options.defineModel.alias.includes(macroName)) {
505
- ;
506
- (rootMap.get(root).defineModel ??= []).push({
507
- expression: macroExpression,
508
- isRequired: expression.type === "TSNonNullExpression"
509
- });
510
- } else if (options.defineStyle.alias.includes(macroName)) {
511
- const lang = macroExpression.callee.type === "MemberExpression" && macroExpression.callee.property.type === "Identifier" ? macroExpression.callee.property.name : "css";
512
- (rootMap.get(root).defineStyle ??= []).push({
513
- expression: macroExpression,
514
- isDeclaration: node.type === "VariableDeclaration",
515
- lang
516
- });
517
- } else if (options.defineSlots.alias.includes(macroName)) {
518
- rootMap.get(root).defineSlots = macroExpression;
519
- } else if (options.defineExpose.alias.includes(macroName)) {
520
- rootMap.get(root).defineExpose = macroExpression;
521
- }
522
- }
523
- },
524
- leave() {
525
- parents.shift();
526
- }
527
- });
528
- return rootMap;
529
- }
530
- function isFunctionalNode(node) {
531
- return !!(node && (node.type === "ArrowFunctionExpression" || node.type === "FunctionDeclaration" || node.type === "FunctionExpression"));
532
- }
533
- function getMacroExpression(node, options) {
534
- if (node.type === "TSNonNullExpression") {
535
- node = node.expression;
536
- }
537
- if (node.type === "CallExpression") {
538
- if (node.callee.type === "MemberExpression" && node.callee.object.type === "Identifier" && node.callee.object.name === "defineStyle") {
539
- return node;
540
- } else if (node.callee.type === "Identifier" && [
541
- ...options.defineComponent.alias,
542
- ...options.defineSlots.alias,
543
- ...options.defineModel.alias,
544
- ...options.defineExpose.alias,
545
- ...options.defineStyle.alias
546
- ].includes(node.callee.name)) {
547
- return node;
548
- }
549
- }
550
- }
551
- function getParamsStart(node, code) {
552
- return node.params[0] ? node.params[0].start : node.start + (code.slice(node.start, node.body.start).match(/\(\s*\)/)?.index || 0) + 1;
553
- }
554
-
555
- export {
556
- use_model_default,
557
- with_defaults_default,
558
- helperPrefix,
559
- useModelHelperId,
560
- withDefaultsHelperId,
561
- restructure,
562
- transformJsxMacros,
563
- isFunctionalNode,
564
- getMacroExpression,
565
- getParamsStart
566
- };
@@ -1,65 +0,0 @@
1
- import {
2
- helperPrefix,
3
- transformJsxMacros,
4
- useModelHelperId,
5
- use_model_default,
6
- withDefaultsHelperId,
7
- with_defaults_default
8
- } from "./chunk-TWP2JCYQ.js";
9
- import {
10
- resolveOptions
11
- } from "./chunk-DANY2WQD.js";
12
-
13
- // src/raw.ts
14
- import { createFilter, normalizePath } from "@vue-macros/common";
15
-
16
- // src/core/style.ts
17
- import { compileStyleAsync } from "@vue/compiler-sfc";
18
- async function transformStyle(code, id, options) {
19
- const query = new URLSearchParams(id.split("?")[1]);
20
- const result = await compileStyleAsync({
21
- filename: id,
22
- id: `data-v-${query.get("scopeId")}`,
23
- isProd: options.isProduction,
24
- source: code,
25
- scoped: query.get("scoped") === "true"
26
- });
27
- return result.code;
28
- }
29
-
30
- // src/raw.ts
31
- var name = "@vue-jsx-vapor/macros";
32
- var plugin = (userOptions = {}) => {
33
- const options = resolveOptions(userOptions);
34
- const filter = createFilter(options);
35
- const importMap = /* @__PURE__ */ new Map();
36
- return {
37
- name,
38
- enforce: "pre",
39
- resolveId(id) {
40
- if (normalizePath(id).startsWith(helperPrefix)) return id;
41
- },
42
- loadInclude(id) {
43
- return normalizePath(id).startsWith(helperPrefix);
44
- },
45
- load(_id) {
46
- const id = normalizePath(_id);
47
- if (id === useModelHelperId) return use_model_default;
48
- else if (id === withDefaultsHelperId) return with_defaults_default;
49
- else if (importMap.get(id)) return importMap.get(id);
50
- },
51
- transformInclude(id) {
52
- if (importMap.get(id)) return true;
53
- return filter(id);
54
- },
55
- transform(code, id) {
56
- if (importMap.get(id)) return transformStyle(code, id, options);
57
- return transformJsxMacros(code, id, importMap, options);
58
- }
59
- };
60
- };
61
- var raw_default = plugin;
62
-
63
- export {
64
- raw_default
65
- };
@@ -1,10 +0,0 @@
1
- import {
2
- index_default
3
- } from "./chunk-LVZNHMZC.js";
4
-
5
- // src/webpack.ts
6
- var webpack_default = index_default.webpack;
7
-
8
- export {
9
- webpack_default
10
- };
@@ -1,10 +0,0 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
-
3
- var _chunkJWJVYLYIcjs = require('./chunk-JWJVYLYI.cjs');
4
-
5
- // src/vite.ts
6
- var vite_default = _chunkJWJVYLYIcjs.index_default.vite;
7
-
8
-
9
-
10
- exports.vite_default = vite_default;