@vue-jsx-vapor/macros 1.7.0
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.
- package/LICENSE +21 -0
- package/dist/api.cjs +14 -0
- package/dist/api.d.cts +40 -0
- package/dist/api.d.ts +40 -0
- package/dist/api.js +14 -0
- package/dist/astro.cjs +22 -0
- package/dist/astro.d.cts +11 -0
- package/dist/astro.d.ts +11 -0
- package/dist/astro.js +20 -0
- package/dist/chunk-6JTF6MNY.cjs +567 -0
- package/dist/chunk-7SOTCEEO.js +10 -0
- package/dist/chunk-IXJAH75Q.js +12 -0
- package/dist/chunk-KDEA57GU.js +567 -0
- package/dist/chunk-LYT252SL.cjs +65 -0
- package/dist/chunk-PCD5JI3K.js +10 -0
- package/dist/chunk-UCG5RA54.js +65 -0
- package/dist/chunk-UZ426MO6.cjs +32 -0
- package/dist/chunk-XA5RNEAB.cjs +10 -0
- package/dist/chunk-Y4BCVHJT.cjs +12 -0
- package/dist/chunk-ZWDLDNLL.cjs +10 -0
- package/dist/chunk-ZXRSELD6.js +32 -0
- package/dist/esbuild.cjs +14 -0
- package/dist/esbuild.d.cts +7 -0
- package/dist/esbuild.d.ts +7 -0
- package/dist/esbuild.js +12 -0
- package/dist/index.cjs +12 -0
- package/dist/index.d.cts +8 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +12 -0
- package/dist/nuxt.cjs +29 -0
- package/dist/nuxt.d.cts +9 -0
- package/dist/nuxt.d.ts +9 -0
- package/dist/nuxt.js +27 -0
- package/dist/options.cjs +6 -0
- package/dist/options.d.cts +24 -0
- package/dist/options.d.ts +24 -0
- package/dist/options.js +6 -0
- package/dist/raw.cjs +10 -0
- package/dist/raw.d.cts +7 -0
- package/dist/raw.d.ts +7 -0
- package/dist/raw.js +8 -0
- package/dist/rolldown.cjs +14 -0
- package/dist/rolldown.d.cts +6 -0
- package/dist/rolldown.d.ts +6 -0
- package/dist/rolldown.js +12 -0
- package/dist/rollup.cjs +14 -0
- package/dist/rollup.d.cts +7 -0
- package/dist/rollup.d.ts +7 -0
- package/dist/rollup.js +12 -0
- package/dist/rspack.cjs +14 -0
- package/dist/rspack.d.cts +6 -0
- package/dist/rspack.d.ts +6 -0
- package/dist/rspack.js +12 -0
- package/dist/vite.cjs +12 -0
- package/dist/vite.d.cts +7 -0
- package/dist/vite.d.ts +7 -0
- package/dist/vite.js +10 -0
- package/dist/volar.cjs +394 -0
- package/dist/volar.d.cts +7 -0
- package/dist/volar.d.ts +7 -0
- package/dist/volar.js +392 -0
- package/dist/webpack.cjs +12 -0
- package/dist/webpack.d.cts +7 -0
- package/dist/webpack.d.ts +7 -0
- package/dist/webpack.js +10 -0
- package/package.json +191 -0
package/dist/volar.cjs
ADDED
|
@@ -0,0 +1,394 @@
|
|
|
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 _chunkUZ426MO6cjs = require('./chunk-UZ426MO6.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
|
+
var _compilerdom = require('@vue/compiler-dom');
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
// src/volar/define-component.ts
|
|
17
|
+
|
|
18
|
+
function transformDefineComponent(node, options) {
|
|
19
|
+
const { codes, source, ast } = options;
|
|
20
|
+
_tsmacro.replaceRange.call(void 0, codes, node.arguments[0].end, node.end - 1);
|
|
21
|
+
const componentOptions = node.arguments[1];
|
|
22
|
+
_tsmacro.replaceRange.call(void 0,
|
|
23
|
+
codes,
|
|
24
|
+
node.getStart(ast),
|
|
25
|
+
node.expression.end + 1,
|
|
26
|
+
"(",
|
|
27
|
+
[node.expression.getText(ast), source, node.getStart(ast), _tsmacro.allCodeFeatures],
|
|
28
|
+
"(() => ({}) as any, ",
|
|
29
|
+
componentOptions ? [
|
|
30
|
+
componentOptions.getText(ast),
|
|
31
|
+
source,
|
|
32
|
+
componentOptions.getStart(ast),
|
|
33
|
+
_tsmacro.allCodeFeatures
|
|
34
|
+
] : "",
|
|
35
|
+
"), "
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// src/volar/transform.ts
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
// src/volar/define-style.ts
|
|
44
|
+
|
|
45
|
+
var _classPropertyjs = require('@vue/language-core/lib/codegen/style/classProperty.js');
|
|
46
|
+
var _parseCssClassNamesjs = require('@vue/language-core/lib/utils/parseCssClassNames.js');
|
|
47
|
+
|
|
48
|
+
function transformDefineStyle(defineStyles, options) {
|
|
49
|
+
if (!_optionalChain([defineStyles, 'optionalAccess', _ => _.length])) return;
|
|
50
|
+
const { ts, codes, ast } = options;
|
|
51
|
+
defineStyles.forEach(({ expression, isCssModules }, index) => {
|
|
52
|
+
if (isCssModules && _optionalChain([expression, 'optionalAccess', _2 => _2.arguments, 'access', _3 => _3[0]]) && !expression.typeArguments && ts.isTemplateLiteral(expression.arguments[0])) {
|
|
53
|
+
_tsmacro.replaceRange.call(void 0,
|
|
54
|
+
codes,
|
|
55
|
+
expression.arguments.pos - 1,
|
|
56
|
+
expression.arguments.pos - 1,
|
|
57
|
+
`<${_common.HELPER_PREFIX}PrettifyLocal<{}`,
|
|
58
|
+
...generateCssClassesType(
|
|
59
|
+
expression.arguments[0].getText(ast).slice(1, -1),
|
|
60
|
+
expression.arguments[0].getStart(ast) + 1,
|
|
61
|
+
index
|
|
62
|
+
),
|
|
63
|
+
">>"
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
addEmbeddedCode(expression, index, options);
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
function* generateCssClassesType(css, offset, index) {
|
|
70
|
+
for (const className of [..._parseCssClassNamesjs.parseCssClassNames.call(void 0, css)]) {
|
|
71
|
+
yield* _classPropertyjs.generateClassProperty.call(void 0,
|
|
72
|
+
index,
|
|
73
|
+
className.text,
|
|
74
|
+
className.offset + offset,
|
|
75
|
+
"string"
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
function addEmbeddedCode(expression, index, options) {
|
|
80
|
+
const { ts, ast } = options;
|
|
81
|
+
const languageId = ts.isPropertyAccessExpression(expression.expression) && ts.isIdentifier(expression.expression.name) ? expression.expression.name.text : "css";
|
|
82
|
+
const style = expression.arguments[0];
|
|
83
|
+
const styleText = style.getText(ast).slice(1, -1).replaceAll(/\$\{.*\}/g, (str) => "_".repeat(str.length));
|
|
84
|
+
options.embeddedCodes.push({
|
|
85
|
+
id: `style_${index}`,
|
|
86
|
+
languageId,
|
|
87
|
+
snapshot: {
|
|
88
|
+
getText: (start, end) => styleText.slice(start, end),
|
|
89
|
+
getLength: () => styleText.length,
|
|
90
|
+
getChangeRange: () => void 0
|
|
91
|
+
},
|
|
92
|
+
mappings: [
|
|
93
|
+
{
|
|
94
|
+
sourceOffsets: [style.getStart(ast) + 1],
|
|
95
|
+
generatedOffsets: [0],
|
|
96
|
+
lengths: [styleText.length],
|
|
97
|
+
data: {
|
|
98
|
+
completion: true,
|
|
99
|
+
format: true,
|
|
100
|
+
navigation: true,
|
|
101
|
+
semantic: true,
|
|
102
|
+
structure: true,
|
|
103
|
+
verification: true
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
],
|
|
107
|
+
embeddedCodes: []
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// src/volar/transform.ts
|
|
112
|
+
function transformJsxMacros(rootMap, options) {
|
|
113
|
+
const { ts, codes, ast } = options;
|
|
114
|
+
for (const [root, map] of rootMap) {
|
|
115
|
+
transformDefineStyle(map.defineStyle, options);
|
|
116
|
+
if (!_optionalChain([root, 'optionalAccess', _4 => _4.body])) continue;
|
|
117
|
+
const asyncModifier = _optionalChain([root, 'access', _5 => _5.modifiers, 'optionalAccess', _6 => _6.find, 'call', _7 => _7(
|
|
118
|
+
(modifier) => modifier.kind === ts.SyntaxKind.AsyncKeyword
|
|
119
|
+
)]);
|
|
120
|
+
if (asyncModifier && map.defineComponent)
|
|
121
|
+
_tsmacro.replaceRange.call(void 0, codes, asyncModifier.pos, asyncModifier.end);
|
|
122
|
+
const result = `({}) as __VLS_PickNotAny<Awaited<ReturnType<typeof ${_common.HELPER_PREFIX}setup>>['render'], {}> & { __ctx: Awaited<ReturnType<typeof ${_common.HELPER_PREFIX}setup>> }`;
|
|
123
|
+
const propsType = _optionalChain([root, 'access', _8 => _8.parameters, 'access', _9 => _9[0], 'optionalAccess', _10 => _10.type]) ? String(root.parameters[0].type.getText(ast)) : "{}";
|
|
124
|
+
_tsmacro.replaceRange.call(void 0,
|
|
125
|
+
codes,
|
|
126
|
+
root.parameters.pos,
|
|
127
|
+
root.parameters.pos,
|
|
128
|
+
ts.isArrowFunction(root) && root.parameters.pos === root.pos ? "(" : "",
|
|
129
|
+
`${_common.HELPER_PREFIX}props: Awaited<ReturnType<typeof ${_common.HELPER_PREFIX}setup>>['props'] & ${propsType}, `,
|
|
130
|
+
`${_common.HELPER_PREFIX}placeholder?: {}, `,
|
|
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: ${options.lib === "vue" ? `import('vue').ShallowUnwrapRef` : "NonNullable"}<${_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
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
// src/volar/global-types.ts
|
|
189
|
+
|
|
190
|
+
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 `
|
|
210
|
+
declare const { ${defineModel}, ${defineComponent} }: typeof import('vue')
|
|
211
|
+
${defineSlots}
|
|
212
|
+
${defineExpose}
|
|
213
|
+
${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]; } & {};
|
|
216
|
+
// @ts-ignore
|
|
217
|
+
type __VLS_IsAny<T> = 0 extends 1 & T ? true : false;
|
|
218
|
+
// @ts-ignore
|
|
219
|
+
type __VLS_PickNotAny<A, B> = __VLS_IsAny<A> extends true ? B : A;
|
|
220
|
+
`;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
// src/volar/index.ts
|
|
224
|
+
function getMacro(node, ts, options) {
|
|
225
|
+
if (!node) return;
|
|
226
|
+
if (ts.isVariableStatement(node)) {
|
|
227
|
+
return ts.forEachChild(node.declarationList, (decl) => getExpression(decl));
|
|
228
|
+
} else {
|
|
229
|
+
return getExpression(node);
|
|
230
|
+
}
|
|
231
|
+
function getExpression(decl) {
|
|
232
|
+
if (ts.isVariableDeclaration(decl) && decl.initializer) {
|
|
233
|
+
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;
|
|
234
|
+
const expression = getMacroExpression(initializer);
|
|
235
|
+
if (expression) {
|
|
236
|
+
return {
|
|
237
|
+
expression,
|
|
238
|
+
initializer: decl.initializer,
|
|
239
|
+
isRequired: ts.isNonNullExpression(initializer)
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
} else if (ts.isExpressionStatement(decl)) {
|
|
243
|
+
const expression = getMacroExpression(decl.expression);
|
|
244
|
+
if (expression)
|
|
245
|
+
return {
|
|
246
|
+
expression,
|
|
247
|
+
initializer: decl.expression,
|
|
248
|
+
isRequired: ts.isNonNullExpression(decl.expression)
|
|
249
|
+
};
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
function getMacroExpression(node2) {
|
|
253
|
+
if (ts.isNonNullExpression(node2)) {
|
|
254
|
+
node2 = node2.expression;
|
|
255
|
+
}
|
|
256
|
+
if (!ts.isCallExpression(node2)) return;
|
|
257
|
+
const expression = ts.isPropertyAccessExpression(node2.expression) ? node2.expression : node2;
|
|
258
|
+
return ts.isIdentifier(expression.expression) && [
|
|
259
|
+
...options.defineModel.alias,
|
|
260
|
+
...options.defineSlots.alias,
|
|
261
|
+
...options.defineStyle.alias,
|
|
262
|
+
...options.defineExpose.alias,
|
|
263
|
+
...options.defineComponent.alias
|
|
264
|
+
].includes(expression.expression.escapedText) && node2;
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
function getRootMap(options) {
|
|
268
|
+
const { ts, ast, codes } = options;
|
|
269
|
+
const rootMap = /* @__PURE__ */ new Map();
|
|
270
|
+
function walk(node, parents) {
|
|
271
|
+
ts.forEachChild(node, (child) => {
|
|
272
|
+
parents.unshift(node);
|
|
273
|
+
walk(child, parents);
|
|
274
|
+
parents.shift();
|
|
275
|
+
});
|
|
276
|
+
const root = parents[1] && (ts.isArrowFunction(parents[1]) || ts.isFunctionExpression(parents[1]) || ts.isFunctionDeclaration(parents[1])) ? parents[1] : void 0;
|
|
277
|
+
if (root && parents[2] && ts.isCallExpression(parents[2]) && !parents[2].typeArguments && options.defineComponent.alias.includes(parents[2].expression.getText(ast))) {
|
|
278
|
+
if (!rootMap.has(root)) rootMap.set(root, {});
|
|
279
|
+
if (!rootMap.get(root).defineComponent) {
|
|
280
|
+
rootMap.get(root).defineComponent = true;
|
|
281
|
+
transformDefineComponent(parents[2], options);
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
const macro = getMacro(node, ts, options);
|
|
285
|
+
if (!macro) return;
|
|
286
|
+
const { expression, initializer } = macro;
|
|
287
|
+
let isRequired = macro.isRequired;
|
|
288
|
+
if (!rootMap.has(root)) rootMap.set(root, {});
|
|
289
|
+
const macroName = expression.expression.getText(ast);
|
|
290
|
+
if (macroName.startsWith("defineStyle")) {
|
|
291
|
+
;
|
|
292
|
+
(rootMap.get(root).defineStyle ??= []).push({
|
|
293
|
+
expression,
|
|
294
|
+
isCssModules: !!ts.isVariableStatement(node)
|
|
295
|
+
});
|
|
296
|
+
}
|
|
297
|
+
if (!root) return;
|
|
298
|
+
if (options.defineModel.alias.includes(macroName)) {
|
|
299
|
+
const modelName = expression.arguments[0] && ts.isStringLiteralLike(expression.arguments[0]) ? expression.arguments[0].text : "modelValue";
|
|
300
|
+
const modelOptions = expression.arguments[0] && ts.isStringLiteralLike(expression.arguments[0]) ? expression.arguments[1] : expression.arguments[0];
|
|
301
|
+
if (modelOptions && ts.isObjectLiteralExpression(modelOptions)) {
|
|
302
|
+
let hasRequired = false;
|
|
303
|
+
for (const prop of modelOptions.properties) {
|
|
304
|
+
if (ts.isPropertyAssignment(prop) && prop.name.getText(ast) === "required") {
|
|
305
|
+
hasRequired = true;
|
|
306
|
+
isRequired = prop.initializer.kind === ts.SyntaxKind.TrueKeyword;
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
if (!hasRequired && isRequired) {
|
|
310
|
+
_tsmacro.replaceRange.call(void 0,
|
|
311
|
+
codes,
|
|
312
|
+
modelOptions.end - 1,
|
|
313
|
+
modelOptions.end - 1,
|
|
314
|
+
`${!modelOptions.properties.hasTrailingComma && modelOptions.properties.length ? "," : ""} required: true`
|
|
315
|
+
);
|
|
316
|
+
}
|
|
317
|
+
} else if (isRequired) {
|
|
318
|
+
_tsmacro.replaceRange.call(void 0,
|
|
319
|
+
codes,
|
|
320
|
+
expression.arguments.end,
|
|
321
|
+
expression.arguments.end,
|
|
322
|
+
`${!expression.arguments.hasTrailingComma && expression.arguments.length ? "," : ""} { required: true }`
|
|
323
|
+
);
|
|
324
|
+
}
|
|
325
|
+
const id = _compilerdom.toValidAssetId.call(void 0, modelName, `${_common.HELPER_PREFIX}model`);
|
|
326
|
+
const typeString = `import('vue').UnwrapRef<typeof ${id}>`;
|
|
327
|
+
(rootMap.get(root).defineModel ??= []).push(
|
|
328
|
+
`${modelName.includes("-") ? `'${modelName}'` : modelName}${isRequired ? ":" : "?:"} ${typeString}`,
|
|
329
|
+
`'onUpdate:${modelName}'?: ($event: ${typeString}) => any`
|
|
330
|
+
);
|
|
331
|
+
_tsmacro.replaceRange.call(void 0,
|
|
332
|
+
codes,
|
|
333
|
+
initializer.getStart(ast),
|
|
334
|
+
initializer.getStart(ast),
|
|
335
|
+
`// @ts-ignore
|
|
336
|
+
${id};
|
|
337
|
+
let ${id} =`
|
|
338
|
+
);
|
|
339
|
+
} else if (options.defineSlots.alias.includes(macroName)) {
|
|
340
|
+
_tsmacro.replaceRange.call(void 0,
|
|
341
|
+
codes,
|
|
342
|
+
expression.getStart(ast),
|
|
343
|
+
expression.getStart(ast),
|
|
344
|
+
`// @ts-ignore
|
|
345
|
+
${_common.HELPER_PREFIX}slots;
|
|
346
|
+
const ${_common.HELPER_PREFIX}slots = `
|
|
347
|
+
);
|
|
348
|
+
rootMap.get(root).defineSlots = `Partial<typeof ${_common.HELPER_PREFIX}slots>`;
|
|
349
|
+
} else if (options.defineExpose.alias.includes(macroName)) {
|
|
350
|
+
_tsmacro.replaceRange.call(void 0,
|
|
351
|
+
codes,
|
|
352
|
+
expression.getStart(ast),
|
|
353
|
+
expression.getStart(ast),
|
|
354
|
+
`// @ts-ignore
|
|
355
|
+
${_common.HELPER_PREFIX}exposed;
|
|
356
|
+
const ${_common.HELPER_PREFIX}exposed = `
|
|
357
|
+
);
|
|
358
|
+
rootMap.get(root).defineExpose = `typeof ${_common.HELPER_PREFIX}exposed`;
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
ts.forEachChild(ast, (node) => walk(node, []));
|
|
362
|
+
return rootMap;
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
// src/volar.ts
|
|
366
|
+
var plugin = _tsmacro.createPlugin.call(void 0,
|
|
367
|
+
({ ts }, userOptions = {}) => {
|
|
368
|
+
const resolvedOptions = _chunkUZ426MO6cjs.resolveOptions.call(void 0, userOptions);
|
|
369
|
+
const filter = _common.createFilter.call(void 0, resolvedOptions);
|
|
370
|
+
return {
|
|
371
|
+
name: "@vue-jsx-vapor/macros",
|
|
372
|
+
resolveVirtualCode(virtualCode) {
|
|
373
|
+
const { filePath, codes } = virtualCode;
|
|
374
|
+
if (!filter(filePath)) return;
|
|
375
|
+
const options = {
|
|
376
|
+
ts,
|
|
377
|
+
...virtualCode,
|
|
378
|
+
...resolvedOptions
|
|
379
|
+
};
|
|
380
|
+
const rootMap = getRootMap(options);
|
|
381
|
+
if (rootMap.size) {
|
|
382
|
+
transformJsxMacros(rootMap, options);
|
|
383
|
+
codes.push(getGlobalTypes(options));
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
};
|
|
387
|
+
}
|
|
388
|
+
);
|
|
389
|
+
var volar_default = plugin;
|
|
390
|
+
|
|
391
|
+
|
|
392
|
+
exports.default = volar_default;
|
|
393
|
+
|
|
394
|
+
module.exports = exports.default;
|
package/dist/volar.d.cts
ADDED