@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
|
@@ -0,0 +1,377 @@
|
|
|
1
|
+
import { HELPER_PREFIX, MagicStringAST, babelParse, generateTransform, getLang, importHelperFn, walkAST } from "@vue-macros/common";
|
|
2
|
+
import { walkIdentifiers } from "@vue/compiler-sfc";
|
|
3
|
+
import hash from "hash-sum";
|
|
4
|
+
|
|
5
|
+
//#region src/core/helper/use-model.ts?raw
|
|
6
|
+
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";
|
|
7
|
+
|
|
8
|
+
//#endregion
|
|
9
|
+
//#region src/core/helper/with-defaults.ts?raw
|
|
10
|
+
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";
|
|
11
|
+
|
|
12
|
+
//#endregion
|
|
13
|
+
//#region src/core/helper/index.ts
|
|
14
|
+
const helperPrefix = "vue-jsx-vapor/macros";
|
|
15
|
+
const useModelHelperId = `${helperPrefix}/use-model`;
|
|
16
|
+
const withDefaultsHelperId = `${helperPrefix}/with-defaults`;
|
|
17
|
+
|
|
18
|
+
//#endregion
|
|
19
|
+
//#region src/core/restructure.ts
|
|
20
|
+
function restructure(s, node, options = {}) {
|
|
21
|
+
let index = 0;
|
|
22
|
+
const propList = [];
|
|
23
|
+
for (const param of node.params) {
|
|
24
|
+
const path = `${HELPER_PREFIX}props${index++ || ""}`;
|
|
25
|
+
const props = getProps(param, path, s, [], options);
|
|
26
|
+
if (props) {
|
|
27
|
+
const hasDefaultValue = props.some((i) => i.defaultValue);
|
|
28
|
+
s.overwrite(param.start, param.end, path);
|
|
29
|
+
propList.push(...hasDefaultValue ? props.map((i) => ({
|
|
30
|
+
...i,
|
|
31
|
+
path: i.path.replace(HELPER_PREFIX, `${HELPER_PREFIX}default_`)
|
|
32
|
+
})) : props);
|
|
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) rests.push(prop);
|
|
44
|
+
}
|
|
45
|
+
for (const [path, values] of Object.entries(defaultValues)) {
|
|
46
|
+
const createPropsDefaultProxy = importHelperFn(s, 0, "createPropsDefaultProxy", void 0, options.withDefaultsFrom ?? withDefaultsHelperId);
|
|
47
|
+
const resolvedPath = path.replace(`${HELPER_PREFIX}default_`, HELPER_PREFIX);
|
|
48
|
+
const resolvedValues = values.map((i) => `'${i.path.replace(path, "")}${i.value}': ${i.defaultValue}`).join(", ");
|
|
49
|
+
prependFunctionalNode(node, s, `\nconst ${path} = ${createPropsDefaultProxy}(${resolvedPath}, {${resolvedValues}})`);
|
|
50
|
+
}
|
|
51
|
+
for (const [index$1, rest] of rests.entries()) prependFunctionalNode(node, s, options.generateRestProps?.(rest.name, index$1, rests) ?? `\nconst ${rest.name} = ${importHelperFn(s, 0, "createPropsRestProxy")}(${rest.path}, [${rest.value}])`);
|
|
52
|
+
walkIdentifiers(node.body, (id, parent) => {
|
|
53
|
+
const prop = propList.find((i) => i.name === id.name);
|
|
54
|
+
if (prop && !prop.isRest) s.overwrite(id.start, id.end, `${parent?.type === "ObjectProperty" && parent.shorthand ? `${id.name}: ` : ""}${prop.path}${prop.value}`);
|
|
55
|
+
}, false);
|
|
56
|
+
}
|
|
57
|
+
return propList;
|
|
58
|
+
}
|
|
59
|
+
function getProps(node, path = "", s, props = [], options) {
|
|
60
|
+
const properties = node.type === "ObjectPattern" ? node.properties : node.type === "ArrayPattern" ? node.elements : [];
|
|
61
|
+
if (!properties.length) return;
|
|
62
|
+
const propNames = [];
|
|
63
|
+
properties.forEach((prop, index) => {
|
|
64
|
+
if (prop?.type === "Identifier") {
|
|
65
|
+
props.push({
|
|
66
|
+
name: prop.name,
|
|
67
|
+
path,
|
|
68
|
+
value: `[${index}]`
|
|
69
|
+
});
|
|
70
|
+
propNames.push(`'${prop.name}'`);
|
|
71
|
+
} else if (prop?.type === "AssignmentPattern" && prop.left.type === "Identifier") {
|
|
72
|
+
props.push({
|
|
73
|
+
path,
|
|
74
|
+
name: prop.left.name,
|
|
75
|
+
value: `[${index}]`,
|
|
76
|
+
defaultValue: s.slice(prop.right.start, prop.right.end)
|
|
77
|
+
});
|
|
78
|
+
propNames.push(`'${prop.left.name}'`);
|
|
79
|
+
} else if (prop?.type === "ObjectProperty" && prop.key.type === "Identifier") {
|
|
80
|
+
if (prop.value.type === "AssignmentPattern" && prop.value.left.type === "Identifier") props.push({
|
|
81
|
+
path,
|
|
82
|
+
name: prop.value.left.name,
|
|
83
|
+
value: `.${prop.key.name}`,
|
|
84
|
+
defaultValue: s.slice(prop.value.right.start, prop.value.right.end),
|
|
85
|
+
isRequired: prop.value.right.type === "TSNonNullExpression"
|
|
86
|
+
});
|
|
87
|
+
else if (!getProps(prop.value, `${path}.${prop.key.name}`, s, props, options)) props.push({
|
|
88
|
+
path,
|
|
89
|
+
name: prop.value.type === "Identifier" ? prop.value.name : prop.key.name,
|
|
90
|
+
value: `.${prop.key.name}`
|
|
91
|
+
});
|
|
92
|
+
propNames.push(`'${prop.key.name}'`);
|
|
93
|
+
} else if (prop?.type === "RestElement" && prop.argument.type === "Identifier" && !prop.argument.name.startsWith(`${HELPER_PREFIX}props`)) props.push({
|
|
94
|
+
path,
|
|
95
|
+
name: prop.argument.name,
|
|
96
|
+
value: propNames.join(", "),
|
|
97
|
+
isRest: true
|
|
98
|
+
});
|
|
99
|
+
else if (prop) getProps(prop, `${path}[${index}]`, s, props, options);
|
|
100
|
+
});
|
|
101
|
+
return props.length ? props : void 0;
|
|
102
|
+
}
|
|
103
|
+
function prependFunctionalNode(node, s, result) {
|
|
104
|
+
const isBlockStatement = node.body.type === "BlockStatement";
|
|
105
|
+
const start = node.body.extra?.parenthesized ? node.body.extra.parenStart : node.body.start;
|
|
106
|
+
s.appendRight(start + (isBlockStatement ? 1 : 0), `${result};${!isBlockStatement ? "return " : ""}`);
|
|
107
|
+
if (!isBlockStatement) {
|
|
108
|
+
s.appendLeft(start, "{");
|
|
109
|
+
s.appendRight(node.end, "}");
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
//#endregion
|
|
114
|
+
//#region src/core/define-component/await.ts
|
|
115
|
+
const isFunctionType = (node) => {
|
|
116
|
+
return /Function(?:Expression|Declaration)$|Method$/.test(node.type);
|
|
117
|
+
};
|
|
118
|
+
function transformAwait(root, s) {
|
|
119
|
+
if (root.body.type !== "BlockStatement") return;
|
|
120
|
+
let hasAwait = false;
|
|
121
|
+
for (const node of root.body.body) if (node.type === "VariableDeclaration" && !node.declare || node.type.endsWith("Statement")) {
|
|
122
|
+
const scope = [root.body.body];
|
|
123
|
+
walkAST(node, {
|
|
124
|
+
enter(child, parent) {
|
|
125
|
+
if (isFunctionType(child)) this.skip();
|
|
126
|
+
if (child.type === "BlockStatement") scope.push(child.body);
|
|
127
|
+
if (child.type === "AwaitExpression") {
|
|
128
|
+
hasAwait = true;
|
|
129
|
+
const currentScope = scope.at(-1);
|
|
130
|
+
const needsSemi = !!currentScope?.some((n, i) => {
|
|
131
|
+
return (scope.length === 1 || i > 0) && n.type === "ExpressionStatement" && n.start === child.start;
|
|
132
|
+
});
|
|
133
|
+
processAwait(s, child, needsSemi, parent.type === "ExpressionStatement");
|
|
134
|
+
}
|
|
135
|
+
},
|
|
136
|
+
leave(node$1) {
|
|
137
|
+
if (node$1.type === "BlockStatement") scope.pop();
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
if (hasAwait) s.prependLeft(root.body.start + 1, `\nlet __temp, __restore\n`);
|
|
142
|
+
}
|
|
143
|
+
function processAwait(s, node, needSemi, isStatement) {
|
|
144
|
+
const argumentStart = node.argument.extra && node.argument.extra.parenthesized ? node.argument.extra.parenStart : node.argument.start;
|
|
145
|
+
const argumentStr = s.slice(argumentStart, node.argument.end);
|
|
146
|
+
const containsNestedAwait = /\bawait\b/.test(argumentStr);
|
|
147
|
+
s.overwrite(node.start, argumentStart, `${needSemi ? `;` : ``}(\n ([__temp,__restore] = ${importHelperFn(s, 0, `withAsyncContext`)}(${containsNestedAwait ? `async ` : ``}() => `);
|
|
148
|
+
s.appendLeft(node.end, `)),\n ${isStatement ? `` : `__temp = `}await __temp,\n __restore()${isStatement ? `` : `,\n __temp`}\n)`);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
//#endregion
|
|
152
|
+
//#region src/core/define-component/return.ts
|
|
153
|
+
function transformReturn(root, s) {
|
|
154
|
+
const node = root.body.type === "BlockStatement" ? root.body.body.find((node$1) => node$1.type === "ReturnStatement")?.argument : root.body;
|
|
155
|
+
if (!node || isFunctionalNode(node)) return;
|
|
156
|
+
s.appendRight(node.extra?.parenthesized ? node.extra.parenStart : node.start, "() => ");
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
//#endregion
|
|
160
|
+
//#region src/core/define-component/index.ts
|
|
161
|
+
function transformDefineComponent(root, propsName, map, s, autoReturnFunction = false) {
|
|
162
|
+
if (!map.defineComponent) return;
|
|
163
|
+
const defineComponentName = s.sliceNode(map.defineComponent.callee);
|
|
164
|
+
if (defineComponentName && !["defineComponent", "defineVaporComponent"].includes(defineComponentName)) importHelperFn(s, 0, "defineComponent", defineComponentName);
|
|
165
|
+
let hasRestProp = false;
|
|
166
|
+
const props = {};
|
|
167
|
+
if (root.params[0]) if (root.params[0].type === "Identifier") getWalkedIds(root, propsName).forEach((id) => props[id] = null);
|
|
168
|
+
else {
|
|
169
|
+
const restructuredProps = restructure(s, root, { generateRestProps: (restPropsName, index, list) => {
|
|
170
|
+
if (index === list.length - 1) {
|
|
171
|
+
hasRestProp = true;
|
|
172
|
+
const useAttrs = importHelperFn(s, 0, "useAttrs");
|
|
173
|
+
return `const ${restPropsName} = ${useAttrs}()`;
|
|
174
|
+
}
|
|
175
|
+
} });
|
|
176
|
+
for (const prop of restructuredProps) if (prop.path.endsWith("props") && !prop.isRest) props[prop.name] = prop.isRequired ? "{ required: true }" : null;
|
|
177
|
+
}
|
|
178
|
+
for (const { expression, isRequired } of map.defineModel || []) {
|
|
179
|
+
const modelOptions = expression.arguments[0]?.type === "ObjectExpression" ? expression.arguments[0] : expression.arguments[1]?.type === "ObjectExpression" ? expression.arguments[1] : void 0;
|
|
180
|
+
const options = {};
|
|
181
|
+
if (isRequired) options.required = true;
|
|
182
|
+
for (const prop of modelOptions?.properties || []) if (prop.type === "ObjectProperty" && prop.key.type === "Identifier" && [
|
|
183
|
+
"validator",
|
|
184
|
+
"type",
|
|
185
|
+
"required"
|
|
186
|
+
].includes(prop.key.name)) options[prop.key.name] = s.sliceNode(prop.value);
|
|
187
|
+
const propName = expression.arguments[0]?.type === "StringLiteral" ? expression.arguments[0].value : "modelValue";
|
|
188
|
+
props[propName] = Object.keys(options).length ? `{ ${Object.entries(options).map(([key, value]) => `${key}: ${value}`).join(", ")} }` : null;
|
|
189
|
+
props[`onUpdate:${propName}`] = null;
|
|
190
|
+
props[`${propName === "modelValue" ? "model" : propName}Modifiers`] = null;
|
|
191
|
+
}
|
|
192
|
+
const propsString = Object.entries(props).map(([key, value]) => `'${key}': ${value}`).join(", ");
|
|
193
|
+
if (propsString) {
|
|
194
|
+
const argument = map.defineComponent.arguments[1];
|
|
195
|
+
if (!argument) s.appendRight(root.end, `, {${hasRestProp ? "inheritAttrs: false," : ""} props: { ${propsString} } }`);
|
|
196
|
+
else if (argument.type === "ObjectExpression") {
|
|
197
|
+
prependObjectExpression(argument, "props", `{ ${propsString} }`, s);
|
|
198
|
+
if (hasRestProp) prependObjectExpression(argument, "inheritAttrs", "false", s);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
transformAwait(root, s);
|
|
202
|
+
if (autoReturnFunction) transformReturn(root, s);
|
|
203
|
+
}
|
|
204
|
+
function prependObjectExpression(argument, name, value, s) {
|
|
205
|
+
if (!argument.properties?.find((prop) => prop.type === "ObjectProperty" && prop.key.type === "Identifier" && prop.key.name === name)) s.appendRight(argument.start + 1, `${name}: ${value},`);
|
|
206
|
+
}
|
|
207
|
+
function getWalkedIds(root, propsName) {
|
|
208
|
+
const walkedIds = new Set();
|
|
209
|
+
walkIdentifiers(root.body, (id, parent) => {
|
|
210
|
+
if (id.name === propsName && (parent?.type === "MemberExpression" || parent?.type === "OptionalMemberExpression")) {
|
|
211
|
+
const prop = parent.property.type === "Identifier" ? parent.property.name : parent.property.type === "StringLiteral" ? parent.property.value : "";
|
|
212
|
+
if (prop) walkedIds.add(prop);
|
|
213
|
+
}
|
|
214
|
+
}, false);
|
|
215
|
+
return walkedIds;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
//#endregion
|
|
219
|
+
//#region src/core/define-expose.ts
|
|
220
|
+
function transformDefineExpose(node, s, version) {
|
|
221
|
+
s.overwriteNode(node.callee, ";");
|
|
222
|
+
s.appendRight(node.arguments[0]?.start || node.end - 1, version >= 3.6 ? `${importHelperFn(s, 0, "currentInstance")}.exposed = ` : `${importHelperFn(s, 0, "getCurrentInstance")}().exposed = `);
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
//#endregion
|
|
226
|
+
//#region src/core/define-model.ts
|
|
227
|
+
function transformDefineModel(node, propsName, s) {
|
|
228
|
+
s.overwriteNode(node.callee, importHelperFn(s, 0, "useModel", void 0, useModelHelperId));
|
|
229
|
+
s.appendRight(node.arguments[0]?.start || node.end - 1, `${propsName}, ${node.arguments[0]?.type !== "StringLiteral" ? `'modelValue',` : ""}`);
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
//#endregion
|
|
233
|
+
//#region src/core/define-slots.ts
|
|
234
|
+
function transformDefineSlots(node, s) {
|
|
235
|
+
s.overwrite(node.start, node.arguments[0]?.start && node.arguments[0].start - 1 || node.typeArguments?.end || node.callee.end, `Object.assign`);
|
|
236
|
+
const slots = `${importHelperFn(s, 0, "useSlots")}()`;
|
|
237
|
+
s.appendLeft(node.end - 1, `${node.arguments[0] ? "," : "{}, "}${slots}`);
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
//#endregion
|
|
241
|
+
//#region src/core/define-style.ts
|
|
242
|
+
function transformDefineStyle(defineStyle, index, root, s, importMap) {
|
|
243
|
+
const { expression, lang, isDeclaration } = defineStyle;
|
|
244
|
+
if (expression.arguments[0]?.type !== "TemplateLiteral") return;
|
|
245
|
+
let css = s.sliceNode(expression.arguments[0]).slice(1, -1);
|
|
246
|
+
const scopeId = hash(css);
|
|
247
|
+
const vars = new Map();
|
|
248
|
+
expression.arguments[0].expressions.forEach((exp) => {
|
|
249
|
+
const cssVar = s.sliceNode(exp);
|
|
250
|
+
const cssVarId = toCssVarId(cssVar, `--${scopeId}-`);
|
|
251
|
+
s.overwrite(exp.start - 2, exp.end + 1, `var(${cssVarId})`);
|
|
252
|
+
vars.set(cssVarId, cssVar);
|
|
253
|
+
});
|
|
254
|
+
let returnExpression = root && getReturnStatement(root);
|
|
255
|
+
if (isFunctionalNode(returnExpression)) returnExpression = getReturnStatement(returnExpression);
|
|
256
|
+
if (vars.size && returnExpression) {
|
|
257
|
+
const children = returnExpression.type === "JSXElement" ? [returnExpression] : returnExpression.type === "JSXFragment" ? returnExpression.children : [];
|
|
258
|
+
const varString = Array.from(vars.entries()).map(([key, value]) => `'${key}': ${value}`).join(", ");
|
|
259
|
+
for (const child of children) if (child.type === "JSXElement") s.appendRight(child.openingElement.name.end, ` {...{style:{${varString}}}}`);
|
|
260
|
+
}
|
|
261
|
+
let scoped = !!root;
|
|
262
|
+
if (expression.arguments[1]?.type === "ObjectExpression") {
|
|
263
|
+
for (const prop of expression.arguments[1].properties) if (prop.type === "ObjectProperty" && prop.key.type === "Identifier" && prop.key.name === "scoped" && prop.value.type === "BooleanLiteral") scoped = prop.value.value;
|
|
264
|
+
}
|
|
265
|
+
if (scoped && returnExpression) walkAST(returnExpression, { enter(node) {
|
|
266
|
+
if (node.type === "JSXElement" && s.sliceNode(node.openingElement.name) !== "template") s.appendRight(node.openingElement.name.end, ` data-v-${scopeId}=""`);
|
|
267
|
+
} });
|
|
268
|
+
css = s.sliceNode(expression.arguments[0]).slice(1, -1).replaceAll(/\/\/(.*)(?=\n)/g, "/*$1*/");
|
|
269
|
+
const module = isDeclaration ? "module." : "";
|
|
270
|
+
const importId = `${helperPrefix}/define-style/${index}?scopeId=${scopeId}&scoped=${scoped}&lang.${module}${lang}`;
|
|
271
|
+
importMap.set(importId, css);
|
|
272
|
+
s.appendLeft(0, isDeclaration ? `import style${index} from "${importId}";` : `import "${importId}";`);
|
|
273
|
+
s.overwriteNode(expression, isDeclaration ? `style${index}` : "");
|
|
274
|
+
}
|
|
275
|
+
function getReturnStatement(root) {
|
|
276
|
+
if (root.body.type === "BlockStatement") {
|
|
277
|
+
const returnStatement = root.body.body.find((node) => node.type === "ReturnStatement");
|
|
278
|
+
if (returnStatement) return returnStatement.argument;
|
|
279
|
+
} else return root.body;
|
|
280
|
+
}
|
|
281
|
+
function toCssVarId(name, prefix = "") {
|
|
282
|
+
return prefix + name.replaceAll(/\W/g, (searchValue, replaceValue) => {
|
|
283
|
+
return searchValue === "." ? "-" : name.charCodeAt(replaceValue).toString();
|
|
284
|
+
});
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
//#endregion
|
|
288
|
+
//#region src/core/index.ts
|
|
289
|
+
function transformJsxMacros(code, id, importMap, options) {
|
|
290
|
+
const s = new MagicStringAST(code);
|
|
291
|
+
const ast = babelParse(s.original, getLang(id));
|
|
292
|
+
const rootMap = getRootMap(ast, s, options);
|
|
293
|
+
let defineStyleIndex = 0;
|
|
294
|
+
for (const [root, map] of rootMap) {
|
|
295
|
+
map.defineStyle?.forEach((defineStyle) => {
|
|
296
|
+
transformDefineStyle(defineStyle, defineStyleIndex++, root, s, importMap);
|
|
297
|
+
});
|
|
298
|
+
if (root === void 0) continue;
|
|
299
|
+
let propsName = `${HELPER_PREFIX}props`;
|
|
300
|
+
if (root.params[0]) {
|
|
301
|
+
if (root.params[0].type === "Identifier") propsName = root.params[0].name;
|
|
302
|
+
else if (root.params[0].type === "ObjectPattern") {
|
|
303
|
+
const lastProp = root.params[0].properties.at(-1);
|
|
304
|
+
if (!map.defineComponent && lastProp?.type === "RestElement" && lastProp.argument.type === "Identifier") propsName = lastProp.argument.name;
|
|
305
|
+
else s.appendRight(root.params[0].extra?.trailingComma ? root.params[0].extra?.trailingComma + 1 : lastProp?.end || root.params[0].end - 1, `${!root.params[0].extra?.trailingComma && root.params[0].properties.length ? "," : ""} ...${HELPER_PREFIX}props`);
|
|
306
|
+
}
|
|
307
|
+
} else s.appendRight(getParamsStart(root, s.original), propsName);
|
|
308
|
+
if (map.defineComponent) transformDefineComponent(root, propsName, map, s, options.defineComponent?.autoReturnFunction);
|
|
309
|
+
if (map.defineModel?.length) map.defineModel.forEach(({ expression }) => {
|
|
310
|
+
transformDefineModel(expression, propsName, s);
|
|
311
|
+
});
|
|
312
|
+
if (map.defineSlots) transformDefineSlots(map.defineSlots, s);
|
|
313
|
+
if (map.defineExpose) transformDefineExpose(map.defineExpose, s, options.version);
|
|
314
|
+
}
|
|
315
|
+
return generateTransform(s, id);
|
|
316
|
+
}
|
|
317
|
+
function getRootMap(ast, s, options) {
|
|
318
|
+
const parents = [];
|
|
319
|
+
const rootMap = new Map();
|
|
320
|
+
walkAST(ast, {
|
|
321
|
+
enter(node, parent) {
|
|
322
|
+
parents.unshift(parent);
|
|
323
|
+
const root = isFunctionalNode(parents[1]) ? parents[1] : void 0;
|
|
324
|
+
if (root && parents[2]?.type === "CallExpression" && options.defineComponent.alias.includes(s.sliceNode(parents[2].callee))) {
|
|
325
|
+
if (!rootMap.has(root)) rootMap.set(root, {});
|
|
326
|
+
if (!rootMap.get(root).defineComponent) rootMap.get(root).defineComponent = parents[2];
|
|
327
|
+
}
|
|
328
|
+
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;
|
|
329
|
+
if (!expression) return;
|
|
330
|
+
const macroExpression = getMacroExpression(expression, options);
|
|
331
|
+
if (!macroExpression) return;
|
|
332
|
+
if (!rootMap.has(root)) rootMap.set(root, {});
|
|
333
|
+
const macroName = s.sliceNode(macroExpression.callee.type === "MemberExpression" ? macroExpression.callee.object : macroExpression.callee);
|
|
334
|
+
if (macroName) {
|
|
335
|
+
if (options.defineModel.alias.includes(macroName)) (rootMap.get(root).defineModel ??= []).push({
|
|
336
|
+
expression: macroExpression,
|
|
337
|
+
isRequired: expression.type === "TSNonNullExpression"
|
|
338
|
+
});
|
|
339
|
+
else if (options.defineStyle.alias.includes(macroName)) {
|
|
340
|
+
const lang = macroExpression.callee.type === "MemberExpression" && macroExpression.callee.property.type === "Identifier" ? macroExpression.callee.property.name : "css";
|
|
341
|
+
(rootMap.get(root).defineStyle ??= []).push({
|
|
342
|
+
expression: macroExpression,
|
|
343
|
+
isDeclaration: node.type === "VariableDeclaration",
|
|
344
|
+
lang
|
|
345
|
+
});
|
|
346
|
+
} else if (options.defineSlots.alias.includes(macroName)) rootMap.get(root).defineSlots = macroExpression;
|
|
347
|
+
else if (options.defineExpose.alias.includes(macroName)) rootMap.get(root).defineExpose = macroExpression;
|
|
348
|
+
}
|
|
349
|
+
},
|
|
350
|
+
leave() {
|
|
351
|
+
parents.shift();
|
|
352
|
+
}
|
|
353
|
+
});
|
|
354
|
+
return rootMap;
|
|
355
|
+
}
|
|
356
|
+
function isFunctionalNode(node) {
|
|
357
|
+
return !!(node && (node.type === "ArrowFunctionExpression" || node.type === "FunctionDeclaration" || node.type === "FunctionExpression"));
|
|
358
|
+
}
|
|
359
|
+
function getMacroExpression(node, options) {
|
|
360
|
+
if (node.type === "TSNonNullExpression") node = node.expression;
|
|
361
|
+
if (node.type === "CallExpression") {
|
|
362
|
+
if (node.callee.type === "MemberExpression" && node.callee.object.type === "Identifier" && node.callee.object.name === "defineStyle") return node;
|
|
363
|
+
else if (node.callee.type === "Identifier" && [
|
|
364
|
+
...options.defineComponent.alias,
|
|
365
|
+
...options.defineSlots.alias,
|
|
366
|
+
...options.defineModel.alias,
|
|
367
|
+
...options.defineExpose.alias,
|
|
368
|
+
...options.defineStyle.alias
|
|
369
|
+
].includes(node.callee.name)) return node;
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
function getParamsStart(node, code) {
|
|
373
|
+
return node.params[0] ? node.params[0].start : node.start + (code.slice(node.start, node.body.start).match(/\(\s*\)/)?.index || 0) + 1;
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
//#endregion
|
|
377
|
+
export { getMacroExpression, getParamsStart, helperPrefix, isFunctionalNode, restructure, transformJsxMacros, useModelHelperId, use_model_default, withDefaultsHelperId, with_defaults_default };
|
package/dist/esbuild.cjs
CHANGED
|
@@ -1,14 +1,12 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
require('./
|
|
5
|
-
require('./
|
|
6
|
-
require('./
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
var esbuild_default =
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
exports.default = esbuild_default
|
|
13
|
-
|
|
14
|
-
module.exports = exports.default;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
3
|
+
require('./core-B1Tt-ieP.cjs');
|
|
4
|
+
require('./raw-3ZelnSQR.cjs');
|
|
5
|
+
require('./options-CNIhAQHD.cjs');
|
|
6
|
+
const require_src = require('./src-DwQLomPw.cjs');
|
|
7
|
+
|
|
8
|
+
//#region src/esbuild.ts
|
|
9
|
+
var esbuild_default = require_src.src_default.esbuild;
|
|
10
|
+
|
|
11
|
+
//#endregion
|
|
12
|
+
exports.default = esbuild_default
|
package/dist/esbuild.d.cts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import '@vue-macros/common';
|
|
1
|
+
import { Options } from "./options.d-B3WOiT_L.cjs";
|
|
2
|
+
import { Plugin } from "esbuild";
|
|
4
3
|
|
|
5
|
-
|
|
4
|
+
//#region src/esbuild.d.ts
|
|
5
|
+
declare const _default: (options?: Options | undefined) => Plugin;
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
//#endregion
|
|
8
|
+
export { _default as default };
|
package/dist/esbuild.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import '@vue-macros/common';
|
|
1
|
+
import { Options } from "./options.d-DtyRfe-9.js";
|
|
2
|
+
import { Plugin } from "esbuild";
|
|
4
3
|
|
|
5
|
-
|
|
4
|
+
//#region src/esbuild.d.ts
|
|
5
|
+
declare const _default: (options?: Options | undefined) => Plugin;
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
//#endregion
|
|
8
|
+
export { _default as default };
|
package/dist/esbuild.js
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import "./
|
|
5
|
-
import "./chunk-SMWNQXL7.js";
|
|
6
|
-
import "./chunk-DANY2WQD.js";
|
|
1
|
+
import "./core-cHgZBgtA.js";
|
|
2
|
+
import "./raw-9SXDNxBH.js";
|
|
3
|
+
import "./options-pbSvpKdV.js";
|
|
4
|
+
import { src_default } from "./src-BfZoaRPY.js";
|
|
7
5
|
|
|
8
|
-
|
|
9
|
-
var esbuild_default =
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
};
|
|
6
|
+
//#region src/esbuild.ts
|
|
7
|
+
var esbuild_default = src_default.esbuild;
|
|
8
|
+
|
|
9
|
+
//#endregion
|
|
10
|
+
export { esbuild_default as default };
|
package/dist/index.cjs
CHANGED
|
@@ -1,12 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
require('./
|
|
5
|
-
require('./
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
exports.default = _chunkL26STXZKcjs.index_default; exports.resolveOptions = _chunk53TNKVYDcjs.resolveOptions;
|
|
1
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
2
|
+
require('./core-B1Tt-ieP.cjs');
|
|
3
|
+
require('./raw-3ZelnSQR.cjs');
|
|
4
|
+
const require_options = require('./options-CNIhAQHD.cjs');
|
|
5
|
+
const require_src = require('./src-DwQLomPw.cjs');
|
|
6
|
+
|
|
7
|
+
exports.default = require_src.src_default
|
|
8
|
+
exports.resolveOptions = require_options.resolveOptions
|
package/dist/index.d.cts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
export { OptionsResolved, resolveOptions } from './options.cjs';
|
|
4
|
-
import '@vue-macros/common';
|
|
1
|
+
import { Options, OptionsResolved, resolveOptions } from "./options.d-B3WOiT_L.cjs";
|
|
2
|
+
import { UnpluginInstance } from "unplugin";
|
|
5
3
|
|
|
4
|
+
//#region src/index.d.ts
|
|
6
5
|
declare const unplugin: UnpluginInstance<Options | undefined>;
|
|
7
6
|
|
|
8
|
-
|
|
7
|
+
//#endregion
|
|
8
|
+
export { Options, OptionsResolved, unplugin as default, resolveOptions };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
export { OptionsResolved, resolveOptions } from './options.js';
|
|
4
|
-
import '@vue-macros/common';
|
|
1
|
+
import { Options, OptionsResolved, resolveOptions$1 as resolveOptions } from "./options.d-DtyRfe-9.js";
|
|
2
|
+
import { UnpluginInstance } from "unplugin";
|
|
5
3
|
|
|
4
|
+
//#region src/index.d.ts
|
|
6
5
|
declare const unplugin: UnpluginInstance<Options | undefined>;
|
|
7
6
|
|
|
8
|
-
|
|
7
|
+
//#endregion
|
|
8
|
+
export { Options, OptionsResolved, unplugin as default, resolveOptions };
|
package/dist/index.js
CHANGED
|
@@ -1,12 +1,6 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
} from "./
|
|
4
|
-
import "./
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
resolveOptions
|
|
8
|
-
} from "./chunk-DANY2WQD.js";
|
|
9
|
-
export {
|
|
10
|
-
index_default as default,
|
|
11
|
-
resolveOptions
|
|
12
|
-
};
|
|
1
|
+
import "./core-cHgZBgtA.js";
|
|
2
|
+
import "./raw-9SXDNxBH.js";
|
|
3
|
+
import { resolveOptions } from "./options-pbSvpKdV.js";
|
|
4
|
+
import { src_default } from "./src-BfZoaRPY.js";
|
|
5
|
+
|
|
6
|
+
export { src_default as default, resolveOptions };
|
package/dist/nuxt.cjs
CHANGED
|
@@ -1,29 +1,26 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
3
|
+
const require_chunk = require('./chunk-BCwAaXi7.cjs');
|
|
4
|
+
require('./core-B1Tt-ieP.cjs');
|
|
5
|
+
require('./raw-3ZelnSQR.cjs');
|
|
6
|
+
require('./options-CNIhAQHD.cjs');
|
|
7
|
+
require('./src-DwQLomPw.cjs');
|
|
8
|
+
const require_vite = require('./vite-C5QxH0B9.cjs');
|
|
9
|
+
const require_webpack = require('./webpack-B-EPKx0G.cjs');
|
|
10
|
+
const __nuxt_kit = require_chunk.__toESM(require("@nuxt/kit"));
|
|
11
|
+
require("@nuxt/schema");
|
|
2
12
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
var _kit = require('@nuxt/kit');
|
|
14
|
-
require('@nuxt/schema');
|
|
15
|
-
var nuxt_default = _kit.defineNuxtModule.call(void 0, {
|
|
16
|
-
meta: {
|
|
17
|
-
name: "nuxt-vue-jsx-vapor",
|
|
18
|
-
configKey: "unpluginStarter"
|
|
19
|
-
},
|
|
20
|
-
setup(options) {
|
|
21
|
-
_kit.addVitePlugin.call(void 0, () => _chunkKUKYWPEKcjs.vite_default.call(void 0, options));
|
|
22
|
-
_kit.addWebpackPlugin.call(void 0, () => _chunkPWA6BBMQcjs.webpack_default.call(void 0, options));
|
|
23
|
-
}
|
|
13
|
+
//#region src/nuxt.ts
|
|
14
|
+
var nuxt_default = (0, __nuxt_kit.defineNuxtModule)({
|
|
15
|
+
meta: {
|
|
16
|
+
name: "nuxt-vue-jsx-vapor",
|
|
17
|
+
configKey: "unpluginStarter"
|
|
18
|
+
},
|
|
19
|
+
setup(options) {
|
|
20
|
+
(0, __nuxt_kit.addVitePlugin)(() => require_vite.vite_default(options));
|
|
21
|
+
(0, __nuxt_kit.addWebpackPlugin)(() => require_webpack.webpack_default(options));
|
|
22
|
+
}
|
|
24
23
|
});
|
|
25
24
|
|
|
26
|
-
|
|
27
|
-
exports.default = nuxt_default
|
|
28
|
-
|
|
29
|
-
module.exports = exports.default;
|
|
25
|
+
//#endregion
|
|
26
|
+
exports.default = nuxt_default
|
package/dist/nuxt.d.cts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import '@vue-macros/common';
|
|
1
|
+
import { Options } from "./options.d-B3WOiT_L.cjs";
|
|
2
|
+
import { NuxtModule } from "@nuxt/schema";
|
|
4
3
|
|
|
4
|
+
//#region src/nuxt.d.ts
|
|
5
5
|
interface ModuleOptions extends Options {
|
|
6
6
|
}
|
|
7
|
-
declare const _default:
|
|
7
|
+
declare const _default: NuxtModule<ModuleOptions, ModuleOptions, false>;
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
//#endregion
|
|
10
|
+
export { ModuleOptions, _default as default };
|
package/dist/nuxt.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import '@vue-macros/common';
|
|
1
|
+
import { Options } from "./options.d-DtyRfe-9.js";
|
|
2
|
+
import { NuxtModule } from "@nuxt/schema";
|
|
4
3
|
|
|
4
|
+
//#region src/nuxt.d.ts
|
|
5
5
|
interface ModuleOptions extends Options {
|
|
6
6
|
}
|
|
7
|
-
declare const _default:
|
|
7
|
+
declare const _default: NuxtModule<ModuleOptions, ModuleOptions, false>;
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
//#endregion
|
|
10
|
+
export { ModuleOptions, _default as default };
|