@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.
- package/dist/api.cjs +6 -13
- package/dist/api.d.cts +8 -4
- package/dist/api.d.ts +8 -4
- package/dist/api.js +3 -14
- package/dist/astro.cjs +14 -18
- package/dist/astro.d.cts +4 -3
- package/dist/astro.d.ts +4 -3
- package/dist/astro.js +13 -17
- package/dist/chunk-BCwAaXi7.cjs +31 -0
- package/dist/core-B1Tt-ieP.cjs +438 -0
- package/dist/core-cHgZBgtA.js +377 -0
- package/dist/esbuild.cjs +12 -14
- package/dist/esbuild.d.cts +6 -5
- package/dist/esbuild.d.ts +6 -5
- package/dist/esbuild.js +9 -11
- package/dist/index.cjs +8 -12
- package/dist/index.d.cts +5 -5
- package/dist/index.d.ts +5 -5
- package/dist/index.js +6 -12
- package/dist/nuxt.cjs +23 -26
- package/dist/nuxt.d.cts +6 -5
- package/dist/nuxt.d.ts +6 -5
- package/dist/nuxt.js +19 -23
- package/dist/options-CNIhAQHD.cjs +27 -0
- package/dist/options-pbSvpKdV.js +20 -0
- package/dist/options.cjs +2 -5
- package/dist/options.d-B3WOiT_L.d.cts +26 -0
- package/dist/options.d-DtyRfe-9.d.ts +26 -0
- package/dist/options.d.cts +2 -23
- package/dist/options.d.ts +2 -23
- package/dist/options.js +3 -6
- package/dist/raw-3ZelnSQR.cjs +62 -0
- package/dist/raw-9SXDNxBH.js +55 -0
- package/dist/raw.cjs +5 -9
- package/dist/raw.d.cts +5 -4
- package/dist/raw.d.ts +5 -4
- package/dist/raw.js +5 -8
- package/dist/rolldown.cjs +12 -14
- package/dist/rolldown.d.cts +4 -3
- package/dist/rolldown.d.ts +4 -3
- package/dist/rolldown.js +9 -11
- package/dist/rollup.cjs +12 -14
- package/dist/rollup.d.cts +6 -5
- package/dist/rollup.d.ts +6 -5
- package/dist/rollup.js +9 -11
- package/dist/rspack.cjs +12 -14
- package/dist/rspack.d.cts +4 -3
- package/dist/rspack.d.ts +4 -3
- package/dist/rspack.js +9 -11
- package/dist/src-BfZoaRPY.js +9 -0
- package/dist/src-DwQLomPw.cjs +16 -0
- package/dist/vite-C5QxH0B9.cjs +13 -0
- package/dist/vite-DPLCEtsm.js +7 -0
- package/dist/vite.cjs +8 -12
- package/dist/vite.d.cts +6 -5
- package/dist/vite.d.ts +6 -5
- package/dist/vite.js +7 -10
- package/dist/volar.cjs +221 -372
- package/dist/volar.d.cts +5 -4
- package/dist/volar.d.ts +5 -4
- package/dist/volar.js +218 -370
- package/dist/webpack-1cYmRdvx.js +7 -0
- package/dist/webpack-B-EPKx0G.cjs +13 -0
- package/dist/webpack.cjs +8 -12
- package/dist/webpack.d.cts +6 -5
- package/dist/webpack.d.ts +6 -5
- package/dist/webpack.js +7 -10
- package/package.json +7 -7
- package/dist/chunk-53TNKVYD.cjs +0 -29
- package/dist/chunk-AUE5EAQA.js +0 -12
- package/dist/chunk-DANY2WQD.js +0 -29
- package/dist/chunk-E5WGUCGE.js +0 -68
- package/dist/chunk-HBVQYNJJ.js +0 -10
- package/dist/chunk-KUKYWPEK.cjs +0 -10
- package/dist/chunk-L26STXZK.cjs +0 -12
- package/dist/chunk-PWA6BBMQ.cjs +0 -10
- package/dist/chunk-SMWNQXL7.js +0 -585
- package/dist/chunk-UAWFIGPX.cjs +0 -68
- package/dist/chunk-ZQ4GVJKX.cjs +0 -585
- package/dist/chunk-ZXJQCFZZ.js +0 -10
package/dist/chunk-SMWNQXL7.js
DELETED
|
@@ -1,585 +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/return.ts
|
|
244
|
-
function transformReturn(root, s) {
|
|
245
|
-
const node = root.body.type === "BlockStatement" ? root.body.body.find((node2) => node2.type === "ReturnStatement")?.argument : root.body;
|
|
246
|
-
if (!node || isFunctionalNode(node)) return;
|
|
247
|
-
s.appendRight(
|
|
248
|
-
node.extra?.parenthesized ? node.extra.parenStart : node.start,
|
|
249
|
-
"() => "
|
|
250
|
-
);
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
// src/core/define-component/index.ts
|
|
254
|
-
function transformDefineComponent(root, propsName, map, s, autoReturnFunction = false) {
|
|
255
|
-
if (!map.defineComponent) return;
|
|
256
|
-
const defineComponentName = s.sliceNode(map.defineComponent.callee);
|
|
257
|
-
if (defineComponentName && !["defineComponent", "defineVaporComponent"].includes(defineComponentName)) {
|
|
258
|
-
importHelperFn3(s, 0, "defineComponent", defineComponentName);
|
|
259
|
-
}
|
|
260
|
-
let hasRestProp = false;
|
|
261
|
-
const props = {};
|
|
262
|
-
if (root.params[0]) {
|
|
263
|
-
if (root.params[0].type === "Identifier") {
|
|
264
|
-
getWalkedIds(root, propsName).forEach((id) => props[id] = null);
|
|
265
|
-
} else {
|
|
266
|
-
const restructuredProps = restructure(s, root, {
|
|
267
|
-
generateRestProps: (restPropsName, index, list) => {
|
|
268
|
-
if (index === list.length - 1) {
|
|
269
|
-
hasRestProp = true;
|
|
270
|
-
const useAttrs = importHelperFn3(s, 0, "useAttrs");
|
|
271
|
-
return `const ${restPropsName} = ${useAttrs}()`;
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
});
|
|
275
|
-
for (const prop of restructuredProps) {
|
|
276
|
-
if (prop.path.endsWith("props") && !prop.isRest) {
|
|
277
|
-
props[prop.name] = prop.isRequired ? "{ required: true }" : null;
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
|
-
}
|
|
281
|
-
}
|
|
282
|
-
for (const { expression, isRequired } of map.defineModel || []) {
|
|
283
|
-
const modelOptions = expression.arguments[0]?.type === "ObjectExpression" ? expression.arguments[0] : expression.arguments[1]?.type === "ObjectExpression" ? expression.arguments[1] : void 0;
|
|
284
|
-
const options = {};
|
|
285
|
-
if (isRequired) options.required = true;
|
|
286
|
-
for (const prop of modelOptions?.properties || []) {
|
|
287
|
-
if (prop.type === "ObjectProperty" && prop.key.type === "Identifier" && ["validator", "type", "required"].includes(prop.key.name)) {
|
|
288
|
-
options[prop.key.name] = s.sliceNode(prop.value);
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
const propName = expression.arguments[0]?.type === "StringLiteral" ? expression.arguments[0].value : "modelValue";
|
|
292
|
-
props[propName] = Object.keys(options).length ? `{ ${Object.entries(options).map(([key, value]) => `${key}: ${value}`).join(", ")} }` : null;
|
|
293
|
-
props[`onUpdate:${propName}`] = null;
|
|
294
|
-
props[`${propName === "modelValue" ? "model" : propName}Modifiers`] = null;
|
|
295
|
-
}
|
|
296
|
-
const propsString = Object.entries(props).map(([key, value]) => `'${key}': ${value}`).join(", ");
|
|
297
|
-
if (propsString) {
|
|
298
|
-
const argument = map.defineComponent.arguments[1];
|
|
299
|
-
if (!argument) {
|
|
300
|
-
s.appendRight(
|
|
301
|
-
root.end,
|
|
302
|
-
`, {${hasRestProp ? "inheritAttrs: false," : ""} props: { ${propsString} } }`
|
|
303
|
-
);
|
|
304
|
-
} else if (argument.type === "ObjectExpression") {
|
|
305
|
-
prependObjectExpression(argument, "props", `{ ${propsString} }`, s);
|
|
306
|
-
if (hasRestProp) {
|
|
307
|
-
prependObjectExpression(argument, "inheritAttrs", "false", s);
|
|
308
|
-
}
|
|
309
|
-
}
|
|
310
|
-
}
|
|
311
|
-
transformAwait(root, s);
|
|
312
|
-
if (autoReturnFunction) {
|
|
313
|
-
transformReturn(root, s);
|
|
314
|
-
}
|
|
315
|
-
}
|
|
316
|
-
function prependObjectExpression(argument, name, value, s) {
|
|
317
|
-
if (!argument.properties?.find(
|
|
318
|
-
(prop) => prop.type === "ObjectProperty" && prop.key.type === "Identifier" && prop.key.name === name
|
|
319
|
-
)) {
|
|
320
|
-
s.appendRight(argument.start + 1, `${name}: ${value},`);
|
|
321
|
-
}
|
|
322
|
-
}
|
|
323
|
-
function getWalkedIds(root, propsName) {
|
|
324
|
-
const walkedIds = /* @__PURE__ */ new Set();
|
|
325
|
-
walkIdentifiers2(
|
|
326
|
-
root.body,
|
|
327
|
-
(id, parent) => {
|
|
328
|
-
if (id.name === propsName && (parent?.type === "MemberExpression" || parent?.type === "OptionalMemberExpression")) {
|
|
329
|
-
const prop = parent.property.type === "Identifier" ? parent.property.name : parent.property.type === "StringLiteral" ? parent.property.value : "";
|
|
330
|
-
if (prop) walkedIds.add(prop);
|
|
331
|
-
}
|
|
332
|
-
},
|
|
333
|
-
false
|
|
334
|
-
);
|
|
335
|
-
return walkedIds;
|
|
336
|
-
}
|
|
337
|
-
|
|
338
|
-
// src/core/define-expose.ts
|
|
339
|
-
import { importHelperFn as importHelperFn4 } from "@vue-macros/common";
|
|
340
|
-
function transformDefineExpose(node, s, version) {
|
|
341
|
-
s.overwriteNode(node.callee, ";");
|
|
342
|
-
s.appendRight(
|
|
343
|
-
node.arguments[0]?.start || node.end - 1,
|
|
344
|
-
version >= 3.6 ? `${importHelperFn4(s, 0, "currentInstance")}.exposed = ` : `${importHelperFn4(s, 0, "getCurrentInstance")}().exposed = `
|
|
345
|
-
);
|
|
346
|
-
}
|
|
347
|
-
|
|
348
|
-
// src/core/define-model.ts
|
|
349
|
-
import { importHelperFn as importHelperFn5 } from "@vue-macros/common";
|
|
350
|
-
function transformDefineModel(node, propsName, s) {
|
|
351
|
-
s.overwriteNode(
|
|
352
|
-
node.callee,
|
|
353
|
-
importHelperFn5(s, 0, "useModel", void 0, useModelHelperId)
|
|
354
|
-
);
|
|
355
|
-
s.appendRight(
|
|
356
|
-
node.arguments[0]?.start || node.end - 1,
|
|
357
|
-
`${propsName}, ${node.arguments[0]?.type !== "StringLiteral" ? `'modelValue',` : ""}`
|
|
358
|
-
);
|
|
359
|
-
}
|
|
360
|
-
|
|
361
|
-
// src/core/define-slots.ts
|
|
362
|
-
import { importHelperFn as importHelperFn6 } from "@vue-macros/common";
|
|
363
|
-
function transformDefineSlots(node, s) {
|
|
364
|
-
s.overwrite(
|
|
365
|
-
node.start,
|
|
366
|
-
node.arguments[0]?.start && node.arguments[0].start - 1 || node.typeArguments?.end || node.callee.end,
|
|
367
|
-
`Object.assign`
|
|
368
|
-
);
|
|
369
|
-
const slots = `${importHelperFn6(s, 0, "useSlots")}()`;
|
|
370
|
-
s.appendLeft(node.end - 1, `${node.arguments[0] ? "," : "{}, "}${slots}`);
|
|
371
|
-
}
|
|
372
|
-
|
|
373
|
-
// src/core/define-style.ts
|
|
374
|
-
import { walkAST as walkAST2 } from "@vue-macros/common";
|
|
375
|
-
import hash from "hash-sum";
|
|
376
|
-
function transformDefineStyle(defineStyle, index, root, s, importMap) {
|
|
377
|
-
const { expression, lang, isDeclaration } = defineStyle;
|
|
378
|
-
if (expression.arguments[0]?.type !== "TemplateLiteral") return;
|
|
379
|
-
let css = s.sliceNode(expression.arguments[0]).slice(1, -1);
|
|
380
|
-
const scopeId = hash(css);
|
|
381
|
-
const vars = /* @__PURE__ */ new Map();
|
|
382
|
-
expression.arguments[0].expressions.forEach((exp) => {
|
|
383
|
-
const cssVar = s.sliceNode(exp);
|
|
384
|
-
const cssVarId = toCssVarId(cssVar, `--${scopeId}-`);
|
|
385
|
-
s.overwrite(exp.start - 2, exp.end + 1, `var(${cssVarId})`);
|
|
386
|
-
vars.set(cssVarId, cssVar);
|
|
387
|
-
});
|
|
388
|
-
let returnExpression = root && getReturnStatement(root);
|
|
389
|
-
if (isFunctionalNode(returnExpression)) {
|
|
390
|
-
returnExpression = getReturnStatement(returnExpression);
|
|
391
|
-
}
|
|
392
|
-
if (vars.size && returnExpression) {
|
|
393
|
-
const children = returnExpression.type === "JSXElement" ? [returnExpression] : returnExpression.type === "JSXFragment" ? returnExpression.children : [];
|
|
394
|
-
const varString = Array.from(vars.entries()).map(([key, value]) => `'${key}': ${value}`).join(", ");
|
|
395
|
-
for (const child of children) {
|
|
396
|
-
if (child.type === "JSXElement") {
|
|
397
|
-
s.appendRight(
|
|
398
|
-
child.openingElement.name.end,
|
|
399
|
-
` {...{style:{${varString}}}}`
|
|
400
|
-
);
|
|
401
|
-
}
|
|
402
|
-
}
|
|
403
|
-
}
|
|
404
|
-
let scoped = !!root;
|
|
405
|
-
if (expression.arguments[1]?.type === "ObjectExpression") {
|
|
406
|
-
for (const prop of expression.arguments[1].properties) {
|
|
407
|
-
if (prop.type === "ObjectProperty" && prop.key.type === "Identifier" && prop.key.name === "scoped" && prop.value.type === "BooleanLiteral") {
|
|
408
|
-
scoped = prop.value.value;
|
|
409
|
-
}
|
|
410
|
-
}
|
|
411
|
-
}
|
|
412
|
-
if (scoped && returnExpression) {
|
|
413
|
-
walkAST2(returnExpression, {
|
|
414
|
-
enter(node) {
|
|
415
|
-
if (node.type === "JSXElement" && s.sliceNode(node.openingElement.name) !== "template") {
|
|
416
|
-
s.appendRight(node.openingElement.name.end, ` data-v-${scopeId}=""`);
|
|
417
|
-
}
|
|
418
|
-
}
|
|
419
|
-
});
|
|
420
|
-
}
|
|
421
|
-
css = s.sliceNode(expression.arguments[0]).slice(1, -1).replaceAll(/\/\/(.*)(?=\n)/g, "/*$1*/");
|
|
422
|
-
const module = isDeclaration ? "module." : "";
|
|
423
|
-
const importId = `${helperPrefix}/define-style/${index}?scopeId=${scopeId}&scoped=${scoped}&lang.${module}${lang}`;
|
|
424
|
-
importMap.set(importId, css);
|
|
425
|
-
s.appendLeft(
|
|
426
|
-
0,
|
|
427
|
-
isDeclaration ? `import style${index} from "${importId}";` : `import "${importId}";`
|
|
428
|
-
);
|
|
429
|
-
s.overwriteNode(expression, isDeclaration ? `style${index}` : "");
|
|
430
|
-
}
|
|
431
|
-
function getReturnStatement(root) {
|
|
432
|
-
if (root.body.type === "BlockStatement") {
|
|
433
|
-
const returnStatement = root.body.body.find(
|
|
434
|
-
(node) => node.type === "ReturnStatement"
|
|
435
|
-
);
|
|
436
|
-
if (returnStatement) {
|
|
437
|
-
return returnStatement.argument;
|
|
438
|
-
}
|
|
439
|
-
} else {
|
|
440
|
-
return root.body;
|
|
441
|
-
}
|
|
442
|
-
}
|
|
443
|
-
function toCssVarId(name, prefix = "") {
|
|
444
|
-
return prefix + name.replaceAll(/\W/g, (searchValue, replaceValue) => {
|
|
445
|
-
return searchValue === "." ? "-" : name.charCodeAt(replaceValue).toString();
|
|
446
|
-
});
|
|
447
|
-
}
|
|
448
|
-
|
|
449
|
-
// src/core/index.ts
|
|
450
|
-
function transformJsxMacros(code, id, importMap, options) {
|
|
451
|
-
const s = new MagicStringAST(code);
|
|
452
|
-
const ast = babelParse(s.original, getLang(id));
|
|
453
|
-
const rootMap = getRootMap(ast, s, options);
|
|
454
|
-
let defineStyleIndex = 0;
|
|
455
|
-
for (const [root, map] of rootMap) {
|
|
456
|
-
map.defineStyle?.forEach((defineStyle) => {
|
|
457
|
-
transformDefineStyle(defineStyle, defineStyleIndex++, root, s, importMap);
|
|
458
|
-
});
|
|
459
|
-
if (root === void 0) continue;
|
|
460
|
-
let propsName = `${HELPER_PREFIX2}props`;
|
|
461
|
-
if (root.params[0]) {
|
|
462
|
-
if (root.params[0].type === "Identifier") {
|
|
463
|
-
propsName = root.params[0].name;
|
|
464
|
-
} else if (root.params[0].type === "ObjectPattern") {
|
|
465
|
-
const lastProp = root.params[0].properties.at(-1);
|
|
466
|
-
if (!map.defineComponent && lastProp?.type === "RestElement" && lastProp.argument.type === "Identifier") {
|
|
467
|
-
propsName = lastProp.argument.name;
|
|
468
|
-
} else {
|
|
469
|
-
s.appendRight(
|
|
470
|
-
root.params[0].extra?.trailingComma ? root.params[0].extra?.trailingComma + 1 : lastProp?.end || root.params[0].end - 1,
|
|
471
|
-
`${!root.params[0].extra?.trailingComma && root.params[0].properties.length ? "," : ""} ...${HELPER_PREFIX2}props`
|
|
472
|
-
);
|
|
473
|
-
}
|
|
474
|
-
}
|
|
475
|
-
} else {
|
|
476
|
-
s.appendRight(getParamsStart(root, s.original), propsName);
|
|
477
|
-
}
|
|
478
|
-
if (map.defineComponent) {
|
|
479
|
-
transformDefineComponent(
|
|
480
|
-
root,
|
|
481
|
-
propsName,
|
|
482
|
-
map,
|
|
483
|
-
s,
|
|
484
|
-
options.defineComponent?.autoReturnFunction
|
|
485
|
-
);
|
|
486
|
-
}
|
|
487
|
-
if (map.defineModel?.length) {
|
|
488
|
-
map.defineModel.forEach(({ expression }) => {
|
|
489
|
-
transformDefineModel(expression, propsName, s);
|
|
490
|
-
});
|
|
491
|
-
}
|
|
492
|
-
if (map.defineSlots) {
|
|
493
|
-
transformDefineSlots(map.defineSlots, s);
|
|
494
|
-
}
|
|
495
|
-
if (map.defineExpose) {
|
|
496
|
-
transformDefineExpose(map.defineExpose, s, options.version);
|
|
497
|
-
}
|
|
498
|
-
}
|
|
499
|
-
return generateTransform(s, id);
|
|
500
|
-
}
|
|
501
|
-
function getRootMap(ast, s, options) {
|
|
502
|
-
const parents = [];
|
|
503
|
-
const rootMap = /* @__PURE__ */ new Map();
|
|
504
|
-
walkAST3(ast, {
|
|
505
|
-
enter(node, parent) {
|
|
506
|
-
parents.unshift(parent);
|
|
507
|
-
const root = isFunctionalNode(parents[1]) ? parents[1] : void 0;
|
|
508
|
-
if (root && parents[2]?.type === "CallExpression" && options.defineComponent.alias.includes(s.sliceNode(parents[2].callee))) {
|
|
509
|
-
if (!rootMap.has(root)) rootMap.set(root, {});
|
|
510
|
-
if (!rootMap.get(root).defineComponent) {
|
|
511
|
-
rootMap.get(root).defineComponent = parents[2];
|
|
512
|
-
}
|
|
513
|
-
}
|
|
514
|
-
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;
|
|
515
|
-
if (!expression) return;
|
|
516
|
-
const macroExpression = getMacroExpression(expression, options);
|
|
517
|
-
if (!macroExpression) return;
|
|
518
|
-
if (!rootMap.has(root)) rootMap.set(root, {});
|
|
519
|
-
const macroName = s.sliceNode(
|
|
520
|
-
macroExpression.callee.type === "MemberExpression" ? macroExpression.callee.object : macroExpression.callee
|
|
521
|
-
);
|
|
522
|
-
if (macroName) {
|
|
523
|
-
if (options.defineModel.alias.includes(macroName)) {
|
|
524
|
-
;
|
|
525
|
-
(rootMap.get(root).defineModel ??= []).push({
|
|
526
|
-
expression: macroExpression,
|
|
527
|
-
isRequired: expression.type === "TSNonNullExpression"
|
|
528
|
-
});
|
|
529
|
-
} else if (options.defineStyle.alias.includes(macroName)) {
|
|
530
|
-
const lang = macroExpression.callee.type === "MemberExpression" && macroExpression.callee.property.type === "Identifier" ? macroExpression.callee.property.name : "css";
|
|
531
|
-
(rootMap.get(root).defineStyle ??= []).push({
|
|
532
|
-
expression: macroExpression,
|
|
533
|
-
isDeclaration: node.type === "VariableDeclaration",
|
|
534
|
-
lang
|
|
535
|
-
});
|
|
536
|
-
} else if (options.defineSlots.alias.includes(macroName)) {
|
|
537
|
-
rootMap.get(root).defineSlots = macroExpression;
|
|
538
|
-
} else if (options.defineExpose.alias.includes(macroName)) {
|
|
539
|
-
rootMap.get(root).defineExpose = macroExpression;
|
|
540
|
-
}
|
|
541
|
-
}
|
|
542
|
-
},
|
|
543
|
-
leave() {
|
|
544
|
-
parents.shift();
|
|
545
|
-
}
|
|
546
|
-
});
|
|
547
|
-
return rootMap;
|
|
548
|
-
}
|
|
549
|
-
function isFunctionalNode(node) {
|
|
550
|
-
return !!(node && (node.type === "ArrowFunctionExpression" || node.type === "FunctionDeclaration" || node.type === "FunctionExpression"));
|
|
551
|
-
}
|
|
552
|
-
function getMacroExpression(node, options) {
|
|
553
|
-
if (node.type === "TSNonNullExpression") {
|
|
554
|
-
node = node.expression;
|
|
555
|
-
}
|
|
556
|
-
if (node.type === "CallExpression") {
|
|
557
|
-
if (node.callee.type === "MemberExpression" && node.callee.object.type === "Identifier" && node.callee.object.name === "defineStyle") {
|
|
558
|
-
return node;
|
|
559
|
-
} else if (node.callee.type === "Identifier" && [
|
|
560
|
-
...options.defineComponent.alias,
|
|
561
|
-
...options.defineSlots.alias,
|
|
562
|
-
...options.defineModel.alias,
|
|
563
|
-
...options.defineExpose.alias,
|
|
564
|
-
...options.defineStyle.alias
|
|
565
|
-
].includes(node.callee.name)) {
|
|
566
|
-
return node;
|
|
567
|
-
}
|
|
568
|
-
}
|
|
569
|
-
}
|
|
570
|
-
function getParamsStart(node, code) {
|
|
571
|
-
return node.params[0] ? node.params[0].start : node.start + (code.slice(node.start, node.body.start).match(/\(\s*\)/)?.index || 0) + 1;
|
|
572
|
-
}
|
|
573
|
-
|
|
574
|
-
export {
|
|
575
|
-
use_model_default,
|
|
576
|
-
with_defaults_default,
|
|
577
|
-
helperPrefix,
|
|
578
|
-
useModelHelperId,
|
|
579
|
-
withDefaultsHelperId,
|
|
580
|
-
restructure,
|
|
581
|
-
transformJsxMacros,
|
|
582
|
-
isFunctionalNode,
|
|
583
|
-
getMacroExpression,
|
|
584
|
-
getParamsStart
|
|
585
|
-
};
|
package/dist/chunk-UAWFIGPX.cjs
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); 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
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
var _chunkZQ4GVJKXcjs = require('./chunk-ZQ4GVJKX.cjs');
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
var _chunk53TNKVYDcjs = require('./chunk-53TNKVYD.cjs');
|
|
12
|
-
|
|
13
|
-
// src/raw.ts
|
|
14
|
-
var _common = require('@vue-macros/common');
|
|
15
|
-
|
|
16
|
-
// src/core/style.ts
|
|
17
|
-
var _compilersfc = require('@vue/compiler-sfc');
|
|
18
|
-
async function transformStyle(code, id, options) {
|
|
19
|
-
const query = new URLSearchParams(id.split("?")[1]);
|
|
20
|
-
const result = await _compilersfc.compileStyleAsync.call(void 0, {
|
|
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 = _chunk53TNKVYDcjs.resolveOptions.call(void 0, userOptions);
|
|
34
|
-
const filter = _common.createFilter.call(void 0, options);
|
|
35
|
-
const importMap = /* @__PURE__ */ new Map();
|
|
36
|
-
return {
|
|
37
|
-
name,
|
|
38
|
-
enforce: "pre",
|
|
39
|
-
resolveId(id) {
|
|
40
|
-
if (_common.normalizePath.call(void 0, id).startsWith(_chunkZQ4GVJKXcjs.helperPrefix)) return id;
|
|
41
|
-
},
|
|
42
|
-
loadInclude(id) {
|
|
43
|
-
return _common.normalizePath.call(void 0, id).startsWith(_chunkZQ4GVJKXcjs.helperPrefix);
|
|
44
|
-
},
|
|
45
|
-
load(_id) {
|
|
46
|
-
const id = _common.normalizePath.call(void 0, _id);
|
|
47
|
-
if (id === _chunkZQ4GVJKXcjs.useModelHelperId) return _chunkZQ4GVJKXcjs.use_model_default;
|
|
48
|
-
else if (id === _chunkZQ4GVJKXcjs.withDefaultsHelperId) return _chunkZQ4GVJKXcjs.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, opt) {
|
|
56
|
-
if (_optionalChain([opt, 'optionalAccess', _ => _.ssr])) {
|
|
57
|
-
options.defineComponent.autoReturnFunction = true;
|
|
58
|
-
}
|
|
59
|
-
if (importMap.get(id)) return transformStyle(code, id, options);
|
|
60
|
-
return _chunkZQ4GVJKXcjs.transformJsxMacros.call(void 0, code, id, importMap, options);
|
|
61
|
-
}
|
|
62
|
-
};
|
|
63
|
-
};
|
|
64
|
-
var raw_default = plugin;
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
exports.raw_default = raw_default;
|