@vue-jsx-vapor/macros 2.3.0 → 2.3.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 (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 -23
  30. package/dist/options.d.ts +2 -23
  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 +221 -372
  59. package/dist/volar.d.cts +5 -4
  60. package/dist/volar.d.ts +5 -4
  61. package/dist/volar.js +218 -370
  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 +7 -7
  69. package/dist/chunk-53TNKVYD.cjs +0 -29
  70. package/dist/chunk-AUE5EAQA.js +0 -12
  71. package/dist/chunk-DANY2WQD.js +0 -29
  72. package/dist/chunk-E5WGUCGE.js +0 -68
  73. package/dist/chunk-HBVQYNJJ.js +0 -10
  74. package/dist/chunk-KUKYWPEK.cjs +0 -10
  75. package/dist/chunk-L26STXZK.cjs +0 -12
  76. package/dist/chunk-PWA6BBMQ.cjs +0 -10
  77. package/dist/chunk-SMWNQXL7.js +0 -585
  78. package/dist/chunk-UAWFIGPX.cjs +0 -68
  79. package/dist/chunk-ZQ4GVJKX.cjs +0 -585
  80. package/dist/chunk-ZXJQCFZZ.js +0 -10
package/dist/volar.cjs CHANGED
@@ -1,403 +1,252 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
2
-
3
- var _chunk53TNKVYDcjs = require('./chunk-53TNKVYD.cjs');
4
-
5
- // src/volar.ts
6
- var _common = require('@vue-macros/common');
7
- var _tsmacro = require('ts-macro');
8
-
9
- // src/volar/index.ts
10
-
11
-
12
-
13
-
14
-
15
- // src/volar/define-component.ts
16
-
17
- function transformDefineComponent(node, options) {
18
- const { codes, source, ast } = options;
19
- _tsmacro.replaceRange.call(void 0, codes, node.arguments[0].end, node.end - 1);
20
- const componentOptions = node.arguments[1];
21
- _tsmacro.replaceRange.call(void 0,
22
- codes,
23
- node.getStart(ast),
24
- node.expression.end + 1,
25
- "(",
26
- [node.expression.getText(ast), source, node.getStart(ast), _tsmacro.allCodeFeatures],
27
- "(() => ({}) as any, ",
28
- componentOptions ? [
29
- componentOptions.getText(ast),
30
- source,
31
- componentOptions.getStart(ast),
32
- _tsmacro.allCodeFeatures
33
- ] : "",
34
- "), "
35
- );
1
+ "use strict";
2
+ Object.defineProperty(exports, '__esModule', { value: true });
3
+ const require_chunk = require('./chunk-BCwAaXi7.cjs');
4
+ const require_options = require('./options-CNIhAQHD.cjs');
5
+ const __vue_macros_common = require_chunk.__toESM(require("@vue-macros/common"));
6
+ const ts_macro = require_chunk.__toESM(require("ts-macro"));
7
+ const __vue_language_core_lib_codegen_style_classProperty_js = require_chunk.__toESM(require("@vue/language-core/lib/codegen/style/classProperty.js"));
8
+ const __vue_language_core_lib_utils_parseCssClassNames_js = require_chunk.__toESM(require("@vue/language-core/lib/utils/parseCssClassNames.js"));
9
+
10
+ //#region src/volar/define-component.ts
11
+ function transformDefineComponent(node, parent, options) {
12
+ const { codes, source, ast, ts } = options;
13
+ (0, ts_macro.replaceRange)(codes, node.arguments[0].end, node.end - 1);
14
+ const componentOptions = node.arguments[1];
15
+ (0, ts_macro.replaceRange)(codes, node.getStart(ast), node.expression.end + 1, ts.isExpressionStatement(parent) ? ";" : "", "(", [
16
+ node.expression.getText(ast),
17
+ source,
18
+ node.getStart(ast),
19
+ ts_macro.allCodeFeatures
20
+ ], "(() => ({}) as any, ", componentOptions ? [
21
+ componentOptions.getText(ast),
22
+ source,
23
+ componentOptions.getStart(ast),
24
+ ts_macro.allCodeFeatures
25
+ ] : "", "), ");
36
26
  }
37
27
 
38
- // src/volar/transform.ts
39
-
40
-
41
-
42
- // src/volar/define-style.ts
43
-
44
- var _classPropertyjs = require('@vue/language-core/lib/codegen/style/classProperty.js');
45
- var _parseCssClassNamesjs = require('@vue/language-core/lib/utils/parseCssClassNames.js');
46
-
28
+ //#endregion
29
+ //#region src/volar/define-style.ts
47
30
  function transformDefineStyle(defineStyles, options) {
48
- if (!_optionalChain([defineStyles, 'optionalAccess', _ => _.length])) return;
49
- const { ts, codes, ast } = options;
50
- defineStyles.forEach(({ expression, isCssModules }, index) => {
51
- if (isCssModules && _optionalChain([expression, 'optionalAccess', _2 => _2.arguments, 'access', _3 => _3[0]]) && !expression.typeArguments && ts.isTemplateLiteral(expression.arguments[0])) {
52
- _tsmacro.replaceRange.call(void 0,
53
- codes,
54
- expression.arguments.pos - 1,
55
- expression.arguments.pos - 1,
56
- `<${_common.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
- });
31
+ if (!defineStyles?.length) return;
32
+ const { ts, codes, ast } = options;
33
+ defineStyles.forEach(({ expression, isCssModules }, index) => {
34
+ if (isCssModules && expression?.arguments[0] && !expression.typeArguments && ts.isTemplateLiteral(expression.arguments[0])) (0, ts_macro.replaceRange)(codes, expression.arguments.pos - 1, expression.arguments.pos - 1, `<${__vue_macros_common.HELPER_PREFIX}PrettifyLocal<{}`, ...generateCssClassesType(expression.arguments[0].getText(ast).slice(1, -1), expression.arguments[0].getStart(ast) + 1, index), ">>");
35
+ addEmbeddedCode(expression, index, options);
36
+ });
67
37
  }
68
38
  function* generateCssClassesType(css, offset, index) {
69
- for (const className of [..._parseCssClassNamesjs.parseCssClassNames.call(void 0, css)]) {
70
- yield* _classPropertyjs.generateClassProperty.call(void 0,
71
- index,
72
- className.text,
73
- className.offset + offset,
74
- "string"
75
- );
76
- }
39
+ for (const className of [...(0, __vue_language_core_lib_utils_parseCssClassNames_js.parseCssClassNames)(css)]) yield* (0, __vue_language_core_lib_codegen_style_classProperty_js.generateClassProperty)(index, className.text, className.offset + offset, "string");
77
40
  }
78
41
  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
- });
42
+ const { ts, ast } = options;
43
+ const languageId = ts.isPropertyAccessExpression(expression.expression) && ts.isIdentifier(expression.expression.name) ? expression.expression.name.text : "css";
44
+ const style = expression.arguments[0];
45
+ const styleText = style.getText(ast).slice(1, -1).replaceAll(/\$\{.*\}/g, (str) => "_".repeat(str.length));
46
+ options.embeddedCodes.push({
47
+ id: `style_${index}`,
48
+ languageId,
49
+ snapshot: {
50
+ getText: (start, end) => styleText.slice(start, end),
51
+ getLength: () => styleText.length,
52
+ getChangeRange: () => void 0
53
+ },
54
+ mappings: [{
55
+ sourceOffsets: [style.getStart(ast) + 1],
56
+ generatedOffsets: [0],
57
+ lengths: [styleText.length],
58
+ data: {
59
+ completion: true,
60
+ format: true,
61
+ navigation: true,
62
+ semantic: true,
63
+ structure: true,
64
+ verification: true
65
+ }
66
+ }],
67
+ embeddedCodes: []
68
+ });
108
69
  }
109
70
 
110
- // src/volar/transform.ts
71
+ //#endregion
72
+ //#region src/volar/transform.ts
111
73
  function transformJsxMacros(rootMap, options) {
112
- const { ts, codes, ast } = options;
113
- for (const [root, map] of rootMap) {
114
- transformDefineStyle(map.defineStyle, options);
115
- if (!_optionalChain([root, 'optionalAccess', _4 => _4.body])) continue;
116
- const asyncModifier = _optionalChain([root, 'access', _5 => _5.modifiers, 'optionalAccess', _6 => _6.find, 'call', _7 => _7(
117
- (modifier) => modifier.kind === ts.SyntaxKind.AsyncKeyword
118
- )]);
119
- if (asyncModifier && map.defineComponent)
120
- _tsmacro.replaceRange.call(void 0, codes, asyncModifier.pos, asyncModifier.end);
121
- const result = `({}) as __VLS_PickNotAny<typeof ${_common.HELPER_PREFIX}ctx.render, {}> & { __ctx: typeof ${_common.HELPER_PREFIX}ctx }`;
122
- const propsType = _optionalChain([root, 'access', _8 => _8.parameters, 'access', _9 => _9[0], 'optionalAccess', _10 => _10.type]) ? String(root.parameters[0].type.getText(ast)) : "{}";
123
- _tsmacro.replaceRange.call(void 0,
124
- codes,
125
- root.parameters.pos,
126
- root.parameters.pos,
127
- ts.isArrowFunction(root) && root.parameters.pos === root.pos ? "(" : "",
128
- `${_common.HELPER_PREFIX}props: typeof ${_common.HELPER_PREFIX}ctx.props & ${propsType}, `,
129
- `${_common.HELPER_PREFIX}placeholder?: {}, `,
130
- `${_common.HELPER_PREFIX}ctx = {} as Awaited<ReturnType<typeof ${_common.HELPER_PREFIX}setup>>, `,
131
- `${_common.HELPER_PREFIX}setup = (${asyncModifier ? "async" : ""}(`
132
- );
133
- if (ts.isArrowFunction(root)) {
134
- _tsmacro.replaceRange.call(void 0,
135
- codes,
136
- root.end,
137
- root.end,
138
- `))${root.pos === root.parameters.pos ? ")" : ""} => `,
139
- result
140
- );
141
- } else {
142
- _tsmacro.replaceRange.call(void 0,
143
- codes,
144
- root.body.getStart(ast),
145
- root.body.getStart(ast),
146
- "=>"
147
- );
148
- _tsmacro.replaceRange.call(void 0, codes, root.end, root.end, `)){ return `, result, "}");
149
- }
150
- ts.forEachChild(root.body, (node) => {
151
- if (ts.isReturnStatement(node) && node.expression) {
152
- const props = [..._nullishCoalesce(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
- _tsmacro.replaceRange.call(void 0,
162
- codes,
163
- node.getStart(ast),
164
- node.expression.getStart(ast),
165
- `return {
166
- props: {} as { ${props.join(", ")} }`,
167
- `,
168
- slots: {} as ${_nullishCoalesce(map.defineSlots, () => ( "{}"))}`,
169
- `,
170
- expose: (exposed: import('vue').ShallowUnwrapRef<${_nullishCoalesce(map.defineExpose, () => ( "{}"))}>) => {}`,
171
- `,
172
- render: `,
173
- shouldWrapByCall ? "(" : ""
174
- );
175
- _tsmacro.replaceRange.call(void 0,
176
- codes,
177
- node.expression.end,
178
- node.expression.end,
179
- shouldWrapByCall ? ")()" : "",
180
- `
181
- }`
182
- );
183
- }
184
- });
185
- }
74
+ const { ts, codes, ast } = options;
75
+ for (const [root, map] of rootMap) {
76
+ transformDefineStyle(map.defineStyle, options);
77
+ if (!root?.body) continue;
78
+ const asyncModifier = root.modifiers?.find((modifier) => modifier.kind === ts.SyntaxKind.AsyncKeyword);
79
+ if (asyncModifier && map.defineComponent) (0, ts_macro.replaceRange)(codes, asyncModifier.pos, asyncModifier.end);
80
+ const result = `({}) as __VLS_PickNotAny<typeof ${__vue_macros_common.HELPER_PREFIX}ctx.render, {}> & { __ctx: typeof ${__vue_macros_common.HELPER_PREFIX}ctx }`;
81
+ const propsType = root.parameters[0]?.type ? String(root.parameters[0].type.getText(ast)) : "{}";
82
+ (0, ts_macro.replaceRange)(codes, root.parameters.pos, root.parameters.pos, ts.isArrowFunction(root) && root.parameters.pos === root.pos ? "(" : "", `${__vue_macros_common.HELPER_PREFIX}props: typeof ${__vue_macros_common.HELPER_PREFIX}ctx.props & ${propsType}, `, `${__vue_macros_common.HELPER_PREFIX}placeholder?: {}, `, `${__vue_macros_common.HELPER_PREFIX}ctx = {} as Awaited<ReturnType<typeof ${__vue_macros_common.HELPER_PREFIX}setup>>, `, `${__vue_macros_common.HELPER_PREFIX}setup = (${asyncModifier ? "async" : ""}(`);
83
+ if (ts.isArrowFunction(root)) (0, ts_macro.replaceRange)(codes, root.end, root.end, `))${root.pos === root.parameters.pos ? ")" : ""} => `, result);
84
+ else {
85
+ (0, ts_macro.replaceRange)(codes, root.body.getStart(ast), root.body.getStart(ast), "=>");
86
+ (0, ts_macro.replaceRange)(codes, root.end, root.end, `)){ return `, result, "}");
87
+ }
88
+ ts.forEachChild(root.body, (node) => {
89
+ if (ts.isReturnStatement(node) && node.expression) {
90
+ const props = [...map.defineModel ?? []];
91
+ const elements = root.parameters[0] && !root.parameters[0].type && ts.isObjectBindingPattern(root.parameters[0].name) ? root.parameters[0].name.elements : [];
92
+ 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}`);
93
+ const shouldWrapByCall = (ts.isArrowFunction(node.expression) || ts.isFunctionExpression(node.expression)) && map.defineComponent;
94
+ (0, ts_macro.replaceRange)(codes, node.getStart(ast), node.expression.getStart(ast), `const ${__vue_macros_common.HELPER_PREFIX}render = `, shouldWrapByCall ? "(" : "");
95
+ (0, ts_macro.replaceRange)(codes, node.expression.end, node.expression.end, shouldWrapByCall ? ")()" : "", `
96
+ return {
97
+ props: {} as {${props.join(", ")}},
98
+ slots: {} as ${map.defineSlots ?? "{}"},
99
+ expose: (exposed: import('vue').ShallowUnwrapRef<${map.defineExpose ?? "{}"}>) => {},
100
+ render: ${__vue_macros_common.HELPER_PREFIX}render,
101
+ }`);
102
+ }
103
+ });
104
+ }
186
105
  }
187
106
 
188
- // src/volar/global-types.ts
189
-
107
+ //#endregion
108
+ //#region src/volar/global-types.ts
190
109
  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: ${_common.HELPER_PREFIX}StyleArgs): T; scss: <T>(...args: ${_common.HELPER_PREFIX}StyleArgs)=> T; sass: <T>(...args: ${_common.HELPER_PREFIX}StyleArgs)=> T; stylus: <T>(...args: ${_common.HELPER_PREFIX}StyleArgs)=> T; less: <T>(...args: ${_common.HELPER_PREFIX}StyleArgs)=> T; postcss: <T>(...args: ${_common.HELPER_PREFIX}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 `
110
+ 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("");
111
+ const defineExpose = options.defineExpose.alias.map((alias) => `declare function ${alias}<Exposed extends Record<string, any> = Record<string, any>>(exposed?: Exposed): Exposed;`).join("");
112
+ const defineStyle = options.defineStyle.alias.map((alias) => `declare const ${alias}: { <T>(...args: ${__vue_macros_common.HELPER_PREFIX}StyleArgs): T; scss: <T>(...args: ${__vue_macros_common.HELPER_PREFIX}StyleArgs)=> T; sass: <T>(...args: ${__vue_macros_common.HELPER_PREFIX}StyleArgs)=> T; stylus: <T>(...args: ${__vue_macros_common.HELPER_PREFIX}StyleArgs)=> T; less: <T>(...args: ${__vue_macros_common.HELPER_PREFIX}StyleArgs)=> T; postcss: <T>(...args: ${__vue_macros_common.HELPER_PREFIX}StyleArgs)=> T };\n`).join("");
113
+ const defineModel = options.defineModel.alias.map((alias) => alias === "defineModel" ? "defineModel" : `defineModel: ${alias}`).join(", ");
114
+ const defineComponent = options.defineComponent.alias.map((alias) => ["defineComponent", "defineVaporComponent"].includes(alias) ? "" : `defineComponent: ${alias}`).filter(Boolean).join(", ");
115
+ return `
210
116
  declare const { ${defineModel}, ${defineComponent} }: typeof import('vue')
211
117
  ${defineSlots}
212
118
  ${defineExpose}
213
119
  ${defineStyle}
214
- type ${_common.HELPER_PREFIX}StyleArgs = [style: string, options?: { scoped?: boolean }];
215
- type ${_common.HELPER_PREFIX}PrettifyLocal<T> = { [K in keyof T]: T[K]; } & {};
120
+ type ${__vue_macros_common.HELPER_PREFIX}StyleArgs = [style: string, options?: { scoped?: boolean }];
121
+ type ${__vue_macros_common.HELPER_PREFIX}PrettifyLocal<T> = { [K in keyof T]: T[K]; } & {};
216
122
  // @ts-ignore
217
123
  type __VLS_IsAny<T> = 0 extends 1 & T ? true : false; type __VLS_PickNotAny<A, B> = __VLS_IsAny<A> extends true ? B : A;
218
124
  `;
219
125
  }
220
126
 
221
- // src/volar/index.ts
127
+ //#endregion
128
+ //#region src/volar/index.ts
222
129
  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
- }
130
+ if (!node) return;
131
+ if (ts.isVariableStatement(node)) return ts.forEachChild(node.declarationList, (decl) => getExpression(decl));
132
+ else return getExpression(node);
133
+ function getExpression(decl) {
134
+ if (ts.isVariableDeclaration(decl) && decl.initializer) {
135
+ 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;
136
+ const expression = getMacroExpression(initializer);
137
+ if (expression) return {
138
+ expression,
139
+ initializer: decl.initializer,
140
+ isRequired: ts.isNonNullExpression(initializer)
141
+ };
142
+ } else if (ts.isExpressionStatement(decl)) {
143
+ const expression = getMacroExpression(decl.expression);
144
+ if (expression) return {
145
+ expression,
146
+ initializer: decl.expression,
147
+ isRequired: ts.isNonNullExpression(decl.expression)
148
+ };
149
+ }
150
+ }
151
+ function getMacroExpression(node$1) {
152
+ if (ts.isNonNullExpression(node$1)) node$1 = node$1.expression;
153
+ if (!ts.isCallExpression(node$1)) return;
154
+ const expression = ts.isPropertyAccessExpression(node$1.expression) ? node$1.expression : node$1;
155
+ return ts.isIdentifier(expression.expression) && [
156
+ ...options.defineModel.alias,
157
+ ...options.defineSlots.alias,
158
+ ...options.defineStyle.alias,
159
+ ...options.defineExpose.alias,
160
+ ...options.defineComponent.alias
161
+ ].includes(expression.expression.escapedText) && node$1;
162
+ }
264
163
  }
265
164
  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
- _tsmacro.replaceRange.call(void 0,
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
- _tsmacro.replaceRange.call(void 0,
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, `${_common.HELPER_PREFIX}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 (_optionalChain([expression, 'access', _11 => _11.typeArguments, 'optionalAccess', _12 => _12[1]])) {
331
- defineModel.push(
332
- `${modelName}Modifiers?: Partial<Record<${expression.typeArguments[1].getText(ast)}, boolean>>`
333
- );
334
- }
335
- _tsmacro.replaceRange.call(void 0,
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
- _tsmacro.replaceRange.call(void 0,
345
- codes,
346
- expression.getStart(ast),
347
- expression.getStart(ast),
348
- `// @ts-ignore
349
- ${_common.HELPER_PREFIX}slots;
350
- const ${_common.HELPER_PREFIX}slots = `
351
- );
352
- rootMap.get(root).defineSlots = `Partial<typeof ${_common.HELPER_PREFIX}slots>`;
353
- } else if (options.defineExpose.alias.includes(macroName)) {
354
- _tsmacro.replaceRange.call(void 0,
355
- codes,
356
- expression.getStart(ast),
357
- expression.getStart(ast),
358
- `// @ts-ignore
359
- ${_common.HELPER_PREFIX}exposed;
360
- const ${_common.HELPER_PREFIX}exposed = `
361
- );
362
- rootMap.get(root).defineExpose = `typeof ${_common.HELPER_PREFIX}exposed`;
363
- }
364
- }
365
- ts.forEachChild(ast, (node) => walk(node, []));
366
- return rootMap;
165
+ const { ts, ast, codes } = options;
166
+ const rootMap = new Map();
167
+ function walk(node, parents) {
168
+ ts.forEachChild(node, (child) => {
169
+ parents.unshift(node);
170
+ walk(child, parents);
171
+ parents.shift();
172
+ });
173
+ const root = parents[1] && (ts.isArrowFunction(parents[1]) || ts.isFunctionExpression(parents[1]) || ts.isFunctionDeclaration(parents[1])) ? parents[1] : void 0;
174
+ if (root && parents[2] && ts.isCallExpression(parents[2]) && !parents[2].typeArguments && options.defineComponent.alias.includes(parents[2].expression.getText(ast))) {
175
+ if (!rootMap.has(root)) rootMap.set(root, {});
176
+ if (!rootMap.get(root).defineComponent) {
177
+ rootMap.get(root).defineComponent = true;
178
+ transformDefineComponent(parents[2], parents[3], options);
179
+ }
180
+ }
181
+ const macro = getMacro(node, ts, options);
182
+ if (!macro) return;
183
+ const { expression, initializer } = macro;
184
+ let isRequired = macro.isRequired;
185
+ if (!rootMap.has(root)) rootMap.set(root, {});
186
+ const macroName = expression.expression.getText(ast);
187
+ if (macroName.startsWith("defineStyle")) (rootMap.get(root).defineStyle ??= []).push({
188
+ expression,
189
+ isCssModules: !!ts.isVariableStatement(node)
190
+ });
191
+ if (!root) return;
192
+ if (options.defineModel.alias.includes(macroName)) {
193
+ const modelName = expression.arguments[0] && ts.isStringLiteralLike(expression.arguments[0]) ? expression.arguments[0].text : "modelValue";
194
+ const modelOptions = expression.arguments[0] && ts.isStringLiteralLike(expression.arguments[0]) ? expression.arguments[1] : expression.arguments[0];
195
+ if (modelOptions && ts.isObjectLiteralExpression(modelOptions)) {
196
+ let hasRequired = false;
197
+ for (const prop of modelOptions.properties) if (ts.isPropertyAssignment(prop) && prop.name.getText(ast) === "required") {
198
+ hasRequired = true;
199
+ isRequired = prop.initializer.kind === ts.SyntaxKind.TrueKeyword;
200
+ }
201
+ if (!hasRequired && isRequired) (0, ts_macro.replaceRange)(codes, modelOptions.end - 1, modelOptions.end - 1, `${!modelOptions.properties.hasTrailingComma && modelOptions.properties.length ? "," : ""} required: true`);
202
+ } else if (isRequired) (0, ts_macro.replaceRange)(codes, expression.arguments.end, expression.arguments.end, `${!expression.arguments.hasTrailingComma && expression.arguments.length ? "," : ""} { required: true }`);
203
+ const id = toValidAssetId(modelName, `${__vue_macros_common.HELPER_PREFIX}model`);
204
+ const typeString = `import('vue').UnwrapRef<typeof ${id}>`;
205
+ const defineModel = rootMap.get(root).defineModel ??= [];
206
+ defineModel.push(`${modelName.includes("-") ? `'${modelName}'` : modelName}${isRequired ? ":" : "?:"} ${typeString}`, `'onUpdate:${modelName}'?: ($event: ${typeString}) => any`);
207
+ if (expression.typeArguments?.[1]) defineModel.push(`${modelName}Modifiers?: Partial<Record<${expression.typeArguments[1].getText(ast)}, boolean>>`);
208
+ (0, ts_macro.replaceRange)(codes, initializer.getStart(ast), initializer.getStart(ast), `// @ts-ignore\n${id};\nlet ${id} = `);
209
+ } else if (options.defineSlots.alias.includes(macroName)) {
210
+ (0, ts_macro.replaceRange)(codes, expression.getStart(ast), expression.getStart(ast), `// @ts-ignore\n${__vue_macros_common.HELPER_PREFIX}slots;\nconst ${__vue_macros_common.HELPER_PREFIX}slots = `);
211
+ rootMap.get(root).defineSlots = `Partial<typeof ${__vue_macros_common.HELPER_PREFIX}slots>`;
212
+ } else if (options.defineExpose.alias.includes(macroName)) {
213
+ (0, ts_macro.replaceRange)(codes, expression.getStart(ast), expression.getStart(ast), `// @ts-ignore\n${__vue_macros_common.HELPER_PREFIX}exposed;\nconst ${__vue_macros_common.HELPER_PREFIX}exposed = `);
214
+ rootMap.get(root).defineExpose = `typeof ${__vue_macros_common.HELPER_PREFIX}exposed`;
215
+ }
216
+ }
217
+ ts.forEachChild(ast, (node) => walk(node, []));
218
+ return rootMap;
367
219
  }
368
220
  function toValidAssetId(name, type) {
369
- return `_${type}_${name.replaceAll(/\W/g, (searchValue, replaceValue) => {
370
- return searchValue === "-" ? "_" : name.charCodeAt(replaceValue).toString();
371
- })}`;
221
+ return `_${type}_${name.replaceAll(/\W/g, (searchValue, replaceValue) => {
222
+ return searchValue === "-" ? "_" : name.charCodeAt(replaceValue).toString();
223
+ })}`;
372
224
  }
373
225
 
374
- // src/volar.ts
375
- var plugin = _tsmacro.createPlugin.call(void 0,
376
- ({ ts }, userOptions = {}) => {
377
- const resolvedOptions = _chunk53TNKVYDcjs.resolveOptions.call(void 0, userOptions);
378
- const filter = _common.createFilter.call(void 0, 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
- );
226
+ //#endregion
227
+ //#region src/volar.ts
228
+ const plugin = (0, ts_macro.createPlugin)(({ ts }, userOptions = {}) => {
229
+ const resolvedOptions = require_options.resolveOptions(userOptions);
230
+ const filter = (0, __vue_macros_common.createFilter)(resolvedOptions);
231
+ return {
232
+ name: "@vue-jsx-vapor/macros",
233
+ resolveVirtualCode(virtualCode) {
234
+ const { filePath, codes } = virtualCode;
235
+ if (!filter(filePath)) return;
236
+ const options = {
237
+ ts,
238
+ ...virtualCode,
239
+ ...resolvedOptions
240
+ };
241
+ const rootMap = getRootMap(options);
242
+ if (rootMap.size) {
243
+ transformJsxMacros(rootMap, options);
244
+ codes.push(getGlobalTypes(options));
245
+ }
246
+ }
247
+ };
248
+ });
398
249
  var volar_default = plugin;
399
250
 
400
-
401
- exports.default = volar_default;
402
-
403
- module.exports = exports.default;
251
+ //#endregion
252
+ exports.default = volar_default