@vue-jsx-vapor/macros 2.3.2 → 2.3.4
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 +1 -1
- package/dist/api.d.cts +4 -4
- package/dist/api.d.ts +4 -4
- package/dist/api.js +1 -1
- package/dist/astro.cjs +4 -4
- package/dist/astro.d.cts +1 -1
- package/dist/astro.d.ts +1 -1
- package/dist/astro.js +4 -4
- package/dist/{core-cHgZBgtA.js → core-B_EM_kTA.js} +126 -50
- package/dist/{core-B1Tt-ieP.cjs → core-CdPKEM79.cjs} +126 -50
- package/dist/esbuild.cjs +4 -4
- package/dist/esbuild.d.cts +1 -1
- package/dist/esbuild.d.ts +1 -1
- package/dist/esbuild.js +4 -4
- package/dist/index.cjs +4 -4
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +4 -4
- package/dist/nuxt.cjs +6 -6
- package/dist/nuxt.d.cts +1 -1
- package/dist/nuxt.d.ts +1 -1
- package/dist/nuxt.js +6 -6
- package/dist/{options-CNIhAQHD.cjs → options-BSX_vMxh.cjs} +8 -5
- package/dist/options-BWRkHmm5.js +23 -0
- package/dist/options.cjs +1 -1
- package/dist/options.d-CXMsJZSo.d.cts +37 -0
- package/dist/options.d-DNWXuL_g.d.ts +37 -0
- package/dist/options.d.cts +1 -1
- package/dist/options.d.ts +1 -1
- package/dist/options.js +1 -1
- package/dist/{raw-9SXDNxBH.js → raw-BKMhH7EF.js} +2 -2
- package/dist/{raw-3ZelnSQR.cjs → raw-CgNsul_i.cjs} +2 -2
- package/dist/raw.cjs +3 -3
- package/dist/raw.d.cts +1 -1
- package/dist/raw.d.ts +1 -1
- package/dist/raw.js +3 -3
- package/dist/rolldown.cjs +4 -4
- package/dist/rolldown.d.cts +1 -1
- package/dist/rolldown.d.ts +1 -1
- package/dist/rolldown.js +4 -4
- package/dist/rollup.cjs +4 -4
- package/dist/rollup.d.cts +1 -1
- package/dist/rollup.d.ts +1 -1
- package/dist/rollup.js +4 -4
- package/dist/rspack.cjs +4 -4
- package/dist/rspack.d.cts +1 -1
- package/dist/rspack.d.ts +1 -1
- package/dist/rspack.js +4 -4
- package/dist/{src-DwQLomPw.cjs → src-BSxhhMQG.cjs} +1 -1
- package/dist/{src-BfZoaRPY.js → src-Biftgb4Y.js} +1 -1
- package/dist/{vite-DPLCEtsm.js → vite-BOk2nx8R.js} +1 -1
- package/dist/{vite-C5QxH0B9.cjs → vite-DduBOkgt.cjs} +1 -1
- package/dist/vite.cjs +5 -5
- package/dist/vite.d.cts +1 -1
- package/dist/vite.d.ts +1 -1
- package/dist/vite.js +5 -5
- package/dist/volar.cjs +1 -1
- package/dist/volar.d.cts +1 -1
- package/dist/volar.d.ts +1 -1
- package/dist/volar.js +1 -1
- package/dist/{webpack-1cYmRdvx.js → webpack-D_e7IjTv.js} +1 -1
- package/dist/{webpack-B-EPKx0G.cjs → webpack-DoGvibWq.cjs} +1 -1
- package/dist/webpack.cjs +5 -5
- package/dist/webpack.d.cts +1 -1
- package/dist/webpack.d.ts +1 -1
- package/dist/webpack.js +5 -5
- package/package.json +1 -1
- package/dist/options-pbSvpKdV.js +0 -20
- package/dist/options.d-B3WOiT_L.d.cts +0 -26
- package/dist/options.d-DtyRfe-9.d.ts +0 -26
package/dist/api.cjs
CHANGED
package/dist/api.d.cts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { OptionsResolved } from "./options.d-
|
|
2
|
-
import { CodeTransform,
|
|
1
|
+
import { OptionsResolved } from "./options.d-CXMsJZSo.cjs";
|
|
2
|
+
import { CodeTransform, MagicStringAST } from "@vue-macros/common";
|
|
3
3
|
import { ArrowFunctionExpression, CallExpression, FunctionDeclaration, FunctionExpression, Node } from "@babel/types";
|
|
4
4
|
|
|
5
5
|
//#region src/core/restructure.d.ts
|
|
6
6
|
type Options = {
|
|
7
7
|
withDefaultsFrom?: string;
|
|
8
|
+
skipDefaultProps?: boolean;
|
|
8
9
|
generateRestProps?: (restPropsName: string, index: number, list: Prop[]) => string | undefined;
|
|
9
10
|
};
|
|
10
11
|
type Prop = {
|
|
@@ -13,9 +14,8 @@ type Prop = {
|
|
|
13
14
|
value: string;
|
|
14
15
|
defaultValue?: string;
|
|
15
16
|
isRest?: boolean;
|
|
16
|
-
isRequired?: boolean;
|
|
17
17
|
};
|
|
18
|
-
declare function restructure(s:
|
|
18
|
+
declare function restructure(s: MagicStringAST, node: FunctionalNode, options?: Options): Prop[];
|
|
19
19
|
|
|
20
20
|
//#endregion
|
|
21
21
|
//#region src/core/index.d.ts
|
package/dist/api.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { OptionsResolved } from "./options.d-
|
|
2
|
-
import { CodeTransform,
|
|
1
|
+
import { OptionsResolved } from "./options.d-DNWXuL_g.js";
|
|
2
|
+
import { CodeTransform, MagicStringAST } from "@vue-macros/common";
|
|
3
3
|
import { ArrowFunctionExpression, CallExpression, FunctionDeclaration, FunctionExpression, Node } from "@babel/types";
|
|
4
4
|
|
|
5
5
|
//#region src/core/restructure.d.ts
|
|
6
6
|
type Options = {
|
|
7
7
|
withDefaultsFrom?: string;
|
|
8
|
+
skipDefaultProps?: boolean;
|
|
8
9
|
generateRestProps?: (restPropsName: string, index: number, list: Prop[]) => string | undefined;
|
|
9
10
|
};
|
|
10
11
|
type Prop = {
|
|
@@ -13,9 +14,8 @@ type Prop = {
|
|
|
13
14
|
value: string;
|
|
14
15
|
defaultValue?: string;
|
|
15
16
|
isRest?: boolean;
|
|
16
|
-
isRequired?: boolean;
|
|
17
17
|
};
|
|
18
|
-
declare function restructure(s:
|
|
18
|
+
declare function restructure(s: MagicStringAST, node: FunctionalNode, options?: Options): Prop[];
|
|
19
19
|
|
|
20
20
|
//#endregion
|
|
21
21
|
//#region src/core/index.d.ts
|
package/dist/api.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { getMacroExpression, getParamsStart, isFunctionalNode, restructure, transformJsxMacros } from "./core-
|
|
1
|
+
import { getMacroExpression, getParamsStart, isFunctionalNode, restructure, transformJsxMacros } from "./core-B_EM_kTA.js";
|
|
2
2
|
|
|
3
3
|
export { getMacroExpression, getParamsStart, isFunctionalNode, restructure, transformJsxMacros };
|
package/dist/astro.cjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
3
|
-
require('./core-
|
|
4
|
-
require('./raw-
|
|
5
|
-
require('./options-
|
|
6
|
-
const require_src = require('./src-
|
|
3
|
+
require('./core-CdPKEM79.cjs');
|
|
4
|
+
require('./raw-CgNsul_i.cjs');
|
|
5
|
+
require('./options-BSX_vMxh.cjs');
|
|
6
|
+
const require_src = require('./src-BSxhhMQG.cjs');
|
|
7
7
|
|
|
8
8
|
//#region src/astro.ts
|
|
9
9
|
var astro_default = (options) => ({
|
package/dist/astro.d.cts
CHANGED
package/dist/astro.d.ts
CHANGED
package/dist/astro.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import "./core-
|
|
2
|
-
import "./raw-
|
|
3
|
-
import "./options-
|
|
4
|
-
import { src_default } from "./src-
|
|
1
|
+
import "./core-B_EM_kTA.js";
|
|
2
|
+
import "./raw-BKMhH7EF.js";
|
|
3
|
+
import "./options-BWRkHmm5.js";
|
|
4
|
+
import { src_default } from "./src-Biftgb4Y.js";
|
|
5
5
|
|
|
6
6
|
//#region src/astro.ts
|
|
7
7
|
var astro_default = (options) => ({
|
|
@@ -22,33 +22,28 @@ function restructure(s, node, options = {}) {
|
|
|
22
22
|
const propList = [];
|
|
23
23
|
for (const param of node.params) {
|
|
24
24
|
const path = `${HELPER_PREFIX}props${index++ || ""}`;
|
|
25
|
-
const props = getProps(
|
|
25
|
+
const props = getProps(s, options, param, path);
|
|
26
26
|
if (props) {
|
|
27
|
-
const hasDefaultValue = props.some((i) => i.defaultValue);
|
|
28
27
|
s.overwrite(param.start, param.end, path);
|
|
29
|
-
propList.push(...
|
|
30
|
-
...i,
|
|
31
|
-
path: i.path.replace(HELPER_PREFIX, `${HELPER_PREFIX}default_`)
|
|
32
|
-
})) : props);
|
|
28
|
+
propList.push(...props);
|
|
33
29
|
}
|
|
34
30
|
}
|
|
35
31
|
if (propList.length) {
|
|
36
32
|
const defaultValues = {};
|
|
37
33
|
const rests = [];
|
|
38
34
|
for (const prop of propList) {
|
|
35
|
+
if (prop.isRest) rests.push(prop);
|
|
39
36
|
if (prop.defaultValue) {
|
|
40
|
-
const
|
|
41
|
-
(defaultValues[
|
|
37
|
+
const paths = prop.path.split(/\.|\[/);
|
|
38
|
+
if (!options.skipDefaultProps || paths.length !== 1) (defaultValues[paths[0]] ??= []).push(prop);
|
|
42
39
|
}
|
|
43
|
-
if (prop.isRest) rests.push(prop);
|
|
44
40
|
}
|
|
41
|
+
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}])`);
|
|
45
42
|
for (const [path, values] of Object.entries(defaultValues)) {
|
|
46
43
|
const createPropsDefaultProxy = importHelperFn(s, 0, "createPropsDefaultProxy", void 0, options.withDefaultsFrom ?? withDefaultsHelperId);
|
|
47
|
-
const resolvedPath = path.replace(`${HELPER_PREFIX}default_`, HELPER_PREFIX);
|
|
48
44
|
const resolvedValues = values.map((i) => `'${i.path.replace(path, "")}${i.value}': ${i.defaultValue}`).join(", ");
|
|
49
|
-
prependFunctionalNode(node, s, `\
|
|
45
|
+
prependFunctionalNode(node, s, `\n${path} = ${createPropsDefaultProxy}(${path}, {${resolvedValues}})`);
|
|
50
46
|
}
|
|
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
47
|
walkIdentifiers(node.body, (id, parent) => {
|
|
53
48
|
const prop = propList.find((i) => i.name === id.name);
|
|
54
49
|
if (prop && !prop.isRest) s.overwrite(id.start, id.end, `${parent?.type === "ObjectProperty" && parent.shorthand ? `${id.name}: ` : ""}${prop.path}${prop.value}`);
|
|
@@ -56,7 +51,7 @@ function restructure(s, node, options = {}) {
|
|
|
56
51
|
}
|
|
57
52
|
return propList;
|
|
58
53
|
}
|
|
59
|
-
function getProps(node, path = "",
|
|
54
|
+
function getProps(s, options, node, path = "", props = []) {
|
|
60
55
|
const properties = node.type === "ObjectPattern" ? node.properties : node.type === "ArrayPattern" ? node.elements : [];
|
|
61
56
|
if (!properties.length) return;
|
|
62
57
|
const propNames = [];
|
|
@@ -73,22 +68,25 @@ function getProps(node, path = "", s, props = [], options) {
|
|
|
73
68
|
path,
|
|
74
69
|
name: prop.left.name,
|
|
75
70
|
value: `[${index}]`,
|
|
76
|
-
defaultValue: s.
|
|
71
|
+
defaultValue: s.sliceNode(getDefaultValue(prop.right))
|
|
77
72
|
});
|
|
78
73
|
propNames.push(`'${prop.left.name}'`);
|
|
79
74
|
} else if (prop?.type === "ObjectProperty" && prop.key.type === "Identifier") {
|
|
80
|
-
if (prop.value.type === "AssignmentPattern"
|
|
75
|
+
if (prop.value.type === "AssignmentPattern") if (prop.value.left.type === "Identifier") props.push({
|
|
81
76
|
path,
|
|
82
77
|
name: prop.value.left.name,
|
|
83
78
|
value: `.${prop.key.name}`,
|
|
84
|
-
defaultValue: s.
|
|
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}`
|
|
79
|
+
defaultValue: s.sliceNode(getDefaultValue(prop.value.right))
|
|
91
80
|
});
|
|
81
|
+
else getProps(s, options, prop.value.left, `${path}.${prop.key.name}`, props);
|
|
82
|
+
else if (!getProps(s, options, prop.value, `${path}.${prop.key.name}`, props)) {
|
|
83
|
+
const name = prop.value.type === "Identifier" ? prop.value.name : prop.key.name;
|
|
84
|
+
props.push({
|
|
85
|
+
path,
|
|
86
|
+
name,
|
|
87
|
+
value: `.${prop.key.name}`
|
|
88
|
+
});
|
|
89
|
+
}
|
|
92
90
|
propNames.push(`'${prop.key.name}'`);
|
|
93
91
|
} else if (prop?.type === "RestElement" && prop.argument.type === "Identifier" && !prop.argument.name.startsWith(`${HELPER_PREFIX}props`)) props.push({
|
|
94
92
|
path,
|
|
@@ -96,10 +94,15 @@ function getProps(node, path = "", s, props = [], options) {
|
|
|
96
94
|
value: propNames.join(", "),
|
|
97
95
|
isRest: true
|
|
98
96
|
});
|
|
99
|
-
else if (prop) getProps(prop, `${path}[${index}]`,
|
|
97
|
+
else if (prop) getProps(s, options, prop, `${path}[${index}]`, props);
|
|
100
98
|
});
|
|
101
99
|
return props.length ? props : void 0;
|
|
102
100
|
}
|
|
101
|
+
function getDefaultValue(node) {
|
|
102
|
+
if (node.type === "TSNonNullExpression") return getDefaultValue(node.expression);
|
|
103
|
+
if (node.type === "TSAsExpression") return getDefaultValue(node.expression);
|
|
104
|
+
return node;
|
|
105
|
+
}
|
|
103
106
|
function prependFunctionalNode(node, s, result) {
|
|
104
107
|
const isBlockStatement = node.body.type === "BlockStatement";
|
|
105
108
|
const start = node.body.extra?.parenthesized ? node.body.extra.parenStart : node.body.start;
|
|
@@ -164,37 +167,49 @@ function transformDefineComponent(root, propsName, map, s, autoReturnFunction =
|
|
|
164
167
|
if (defineComponentName && !["defineComponent", "defineVaporComponent"].includes(defineComponentName)) importHelperFn(s, 0, "defineComponent", defineComponentName);
|
|
165
168
|
let hasRestProp = false;
|
|
166
169
|
const props = {};
|
|
167
|
-
if (root.params[0])
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
170
|
+
if (root.params[0]) {
|
|
171
|
+
if (root.params[0].type === "Identifier") getWalkedIds(root, propsName).forEach((id) => props[id] = null);
|
|
172
|
+
else if (root.params[0].type === "ObjectPattern") {
|
|
173
|
+
const restructuredProps = root.params[0];
|
|
174
|
+
for (const prop of restructuredProps.properties) {
|
|
175
|
+
if (prop.type !== "ObjectProperty" || prop.key.type !== "Identifier") continue;
|
|
176
|
+
const propName = prop.key.name;
|
|
177
|
+
if (prop.value.type !== "AssignmentPattern") {
|
|
178
|
+
props[propName] = null;
|
|
179
|
+
continue;
|
|
180
|
+
}
|
|
181
|
+
const defaultValue = getDefaultValue(prop.value.right);
|
|
182
|
+
const isRequired = prop.value.right.type === "TSNonNullExpression";
|
|
183
|
+
const propOptions = [];
|
|
184
|
+
if (isRequired) propOptions.push("required: true");
|
|
185
|
+
if (defaultValue) {
|
|
186
|
+
const { value, type, skipFactory } = getTypeAndValue(s, defaultValue);
|
|
187
|
+
if (type) propOptions.push(`type: ${type}`);
|
|
188
|
+
if (value) propOptions.push(`default: ${value}`);
|
|
189
|
+
if (skipFactory) propOptions.push("skipFactory: true");
|
|
190
|
+
}
|
|
191
|
+
if (propOptions.length) props[propName] = `{ ${propOptions.join(", ")} }`;
|
|
192
|
+
else props[propName] = null;
|
|
174
193
|
}
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
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;
|
|
194
|
+
restructure(s, root, {
|
|
195
|
+
skipDefaultProps: true,
|
|
196
|
+
generateRestProps: (restPropsName, index, list) => {
|
|
197
|
+
if (index === list.length - 1) {
|
|
198
|
+
hasRestProp = true;
|
|
199
|
+
const useAttrs = importHelperFn(s, 0, "useAttrs");
|
|
200
|
+
return `const ${restPropsName} = ${useAttrs}()`;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
});
|
|
204
|
+
}
|
|
191
205
|
}
|
|
192
|
-
|
|
206
|
+
transformDefineModel$1(s, map.defineModel, props);
|
|
207
|
+
const propsString = Object.entries(props).map(([key, value]) => `'${key}': ${value}`).join(", \n");
|
|
193
208
|
if (propsString) {
|
|
194
209
|
const argument = map.defineComponent.arguments[1];
|
|
195
|
-
if (!argument) s.appendRight(root.end, `, {${hasRestProp ? "inheritAttrs: false," : ""} props: {
|
|
210
|
+
if (!argument) s.appendRight(root.end, `, {${hasRestProp ? "inheritAttrs: false," : ""} props: {\n${propsString}\n} }`);
|
|
196
211
|
else if (argument.type === "ObjectExpression") {
|
|
197
|
-
prependObjectExpression(argument, "props", `{
|
|
212
|
+
prependObjectExpression(argument, "props", `{\n${propsString}\n}`, s);
|
|
198
213
|
if (hasRestProp) prependObjectExpression(argument, "inheritAttrs", "false", s);
|
|
199
214
|
}
|
|
200
215
|
}
|
|
@@ -211,9 +226,70 @@ function getWalkedIds(root, propsName) {
|
|
|
211
226
|
const prop = parent.property.type === "Identifier" ? parent.property.name : parent.property.type === "StringLiteral" ? parent.property.value : "";
|
|
212
227
|
if (prop) walkedIds.add(prop);
|
|
213
228
|
}
|
|
214
|
-
}
|
|
229
|
+
});
|
|
215
230
|
return walkedIds;
|
|
216
231
|
}
|
|
232
|
+
function transformDefineModel$1(s, defineModel, props) {
|
|
233
|
+
for (const { expression, isRequired } of defineModel || []) {
|
|
234
|
+
const modelOptions = expression.arguments[0]?.type === "ObjectExpression" ? expression.arguments[0] : expression.arguments[1]?.type === "ObjectExpression" ? expression.arguments[1] : void 0;
|
|
235
|
+
const options = {};
|
|
236
|
+
if (isRequired) options.required = true;
|
|
237
|
+
let defaultValueNode;
|
|
238
|
+
for (const prop of modelOptions?.properties || []) if (prop.type === "ObjectProperty" && prop.key.type === "Identifier" && [
|
|
239
|
+
"validator",
|
|
240
|
+
"type",
|
|
241
|
+
"required",
|
|
242
|
+
"default"
|
|
243
|
+
].includes(prop.key.name)) {
|
|
244
|
+
if (prop.key.name === "default") defaultValueNode = prop.value;
|
|
245
|
+
options[prop.key.name] = s.sliceNode(prop.value);
|
|
246
|
+
}
|
|
247
|
+
if (defaultValueNode && !options.type) {
|
|
248
|
+
const { value, type, skipFactory } = getTypeAndValue(s, defaultValueNode);
|
|
249
|
+
if (type) options.type = type;
|
|
250
|
+
if (value) options.default = value;
|
|
251
|
+
if (skipFactory) options.skipFactory = "true";
|
|
252
|
+
}
|
|
253
|
+
const propName = expression.arguments[0]?.type === "StringLiteral" ? expression.arguments[0].value : "modelValue";
|
|
254
|
+
props[propName] = Object.keys(options).length ? `{ ${Object.entries(options).map(([key, value]) => `${key}: ${value}`).join(", ")} }` : null;
|
|
255
|
+
props[`onUpdate:${propName}`] = null;
|
|
256
|
+
props[`${propName === "modelValue" ? "model" : propName}Modifiers`] = null;
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
function getTypeAndValue(s, node) {
|
|
260
|
+
let value = "";
|
|
261
|
+
let type = "";
|
|
262
|
+
let skipFactory = false;
|
|
263
|
+
if (node.type === "StringLiteral") {
|
|
264
|
+
type = "String";
|
|
265
|
+
value = `'${node.value}'`;
|
|
266
|
+
} else if (node.type === "BooleanLiteral") {
|
|
267
|
+
type = "Boolean";
|
|
268
|
+
value = String(node.value);
|
|
269
|
+
} else if (node.type === "NumericLiteral") {
|
|
270
|
+
type = "Number";
|
|
271
|
+
value = String(node.value);
|
|
272
|
+
} else if (node.type === "ObjectExpression") {
|
|
273
|
+
type = "Object";
|
|
274
|
+
value = `() => (${s.sliceNode(node)})`;
|
|
275
|
+
} else if (node.type === "ArrayExpression") {
|
|
276
|
+
type = "Array";
|
|
277
|
+
value = `() => (${s.sliceNode(node)})`;
|
|
278
|
+
} else if (isFunctionalNode(node)) {
|
|
279
|
+
type = "Function";
|
|
280
|
+
value = s.sliceNode(node);
|
|
281
|
+
} else if (node.type === "Identifier") if (node.name === "undefined") value = "undefined";
|
|
282
|
+
else {
|
|
283
|
+
skipFactory = true;
|
|
284
|
+
value = s.sliceNode(node);
|
|
285
|
+
}
|
|
286
|
+
else if (node.type === "NullLiteral") value = "null";
|
|
287
|
+
return {
|
|
288
|
+
value,
|
|
289
|
+
type,
|
|
290
|
+
skipFactory
|
|
291
|
+
};
|
|
292
|
+
}
|
|
217
293
|
|
|
218
294
|
//#endregion
|
|
219
295
|
//#region src/core/define-expose.ts
|
|
@@ -24,33 +24,28 @@ function restructure(s, node, options = {}) {
|
|
|
24
24
|
const propList = [];
|
|
25
25
|
for (const param of node.params) {
|
|
26
26
|
const path = `${__vue_macros_common.HELPER_PREFIX}props${index++ || ""}`;
|
|
27
|
-
const props = getProps(
|
|
27
|
+
const props = getProps(s, options, param, path);
|
|
28
28
|
if (props) {
|
|
29
|
-
const hasDefaultValue = props.some((i) => i.defaultValue);
|
|
30
29
|
s.overwrite(param.start, param.end, path);
|
|
31
|
-
propList.push(...
|
|
32
|
-
...i,
|
|
33
|
-
path: i.path.replace(__vue_macros_common.HELPER_PREFIX, `${__vue_macros_common.HELPER_PREFIX}default_`)
|
|
34
|
-
})) : props);
|
|
30
|
+
propList.push(...props);
|
|
35
31
|
}
|
|
36
32
|
}
|
|
37
33
|
if (propList.length) {
|
|
38
34
|
const defaultValues = {};
|
|
39
35
|
const rests = [];
|
|
40
36
|
for (const prop of propList) {
|
|
37
|
+
if (prop.isRest) rests.push(prop);
|
|
41
38
|
if (prop.defaultValue) {
|
|
42
|
-
const
|
|
43
|
-
(defaultValues[
|
|
39
|
+
const paths = prop.path.split(/\.|\[/);
|
|
40
|
+
if (!options.skipDefaultProps || paths.length !== 1) (defaultValues[paths[0]] ??= []).push(prop);
|
|
44
41
|
}
|
|
45
|
-
if (prop.isRest) rests.push(prop);
|
|
46
42
|
}
|
|
43
|
+
for (const [index$1, rest] of rests.entries()) prependFunctionalNode(node, s, options.generateRestProps?.(rest.name, index$1, rests) ?? `\nconst ${rest.name} = ${(0, __vue_macros_common.importHelperFn)(s, 0, "createPropsRestProxy")}(${rest.path}, [${rest.value}])`);
|
|
47
44
|
for (const [path, values] of Object.entries(defaultValues)) {
|
|
48
45
|
const createPropsDefaultProxy = (0, __vue_macros_common.importHelperFn)(s, 0, "createPropsDefaultProxy", void 0, options.withDefaultsFrom ?? withDefaultsHelperId);
|
|
49
|
-
const resolvedPath = path.replace(`${__vue_macros_common.HELPER_PREFIX}default_`, __vue_macros_common.HELPER_PREFIX);
|
|
50
46
|
const resolvedValues = values.map((i) => `'${i.path.replace(path, "")}${i.value}': ${i.defaultValue}`).join(", ");
|
|
51
|
-
prependFunctionalNode(node, s, `\
|
|
47
|
+
prependFunctionalNode(node, s, `\n${path} = ${createPropsDefaultProxy}(${path}, {${resolvedValues}})`);
|
|
52
48
|
}
|
|
53
|
-
for (const [index$1, rest] of rests.entries()) prependFunctionalNode(node, s, options.generateRestProps?.(rest.name, index$1, rests) ?? `\nconst ${rest.name} = ${(0, __vue_macros_common.importHelperFn)(s, 0, "createPropsRestProxy")}(${rest.path}, [${rest.value}])`);
|
|
54
49
|
(0, __vue_compiler_sfc.walkIdentifiers)(node.body, (id, parent) => {
|
|
55
50
|
const prop = propList.find((i) => i.name === id.name);
|
|
56
51
|
if (prop && !prop.isRest) s.overwrite(id.start, id.end, `${parent?.type === "ObjectProperty" && parent.shorthand ? `${id.name}: ` : ""}${prop.path}${prop.value}`);
|
|
@@ -58,7 +53,7 @@ function restructure(s, node, options = {}) {
|
|
|
58
53
|
}
|
|
59
54
|
return propList;
|
|
60
55
|
}
|
|
61
|
-
function getProps(node, path = "",
|
|
56
|
+
function getProps(s, options, node, path = "", props = []) {
|
|
62
57
|
const properties = node.type === "ObjectPattern" ? node.properties : node.type === "ArrayPattern" ? node.elements : [];
|
|
63
58
|
if (!properties.length) return;
|
|
64
59
|
const propNames = [];
|
|
@@ -75,22 +70,25 @@ function getProps(node, path = "", s, props = [], options) {
|
|
|
75
70
|
path,
|
|
76
71
|
name: prop.left.name,
|
|
77
72
|
value: `[${index}]`,
|
|
78
|
-
defaultValue: s.
|
|
73
|
+
defaultValue: s.sliceNode(getDefaultValue(prop.right))
|
|
79
74
|
});
|
|
80
75
|
propNames.push(`'${prop.left.name}'`);
|
|
81
76
|
} else if (prop?.type === "ObjectProperty" && prop.key.type === "Identifier") {
|
|
82
|
-
if (prop.value.type === "AssignmentPattern"
|
|
77
|
+
if (prop.value.type === "AssignmentPattern") if (prop.value.left.type === "Identifier") props.push({
|
|
83
78
|
path,
|
|
84
79
|
name: prop.value.left.name,
|
|
85
80
|
value: `.${prop.key.name}`,
|
|
86
|
-
defaultValue: s.
|
|
87
|
-
isRequired: prop.value.right.type === "TSNonNullExpression"
|
|
88
|
-
});
|
|
89
|
-
else if (!getProps(prop.value, `${path}.${prop.key.name}`, s, props, options)) props.push({
|
|
90
|
-
path,
|
|
91
|
-
name: prop.value.type === "Identifier" ? prop.value.name : prop.key.name,
|
|
92
|
-
value: `.${prop.key.name}`
|
|
81
|
+
defaultValue: s.sliceNode(getDefaultValue(prop.value.right))
|
|
93
82
|
});
|
|
83
|
+
else getProps(s, options, prop.value.left, `${path}.${prop.key.name}`, props);
|
|
84
|
+
else if (!getProps(s, options, prop.value, `${path}.${prop.key.name}`, props)) {
|
|
85
|
+
const name = prop.value.type === "Identifier" ? prop.value.name : prop.key.name;
|
|
86
|
+
props.push({
|
|
87
|
+
path,
|
|
88
|
+
name,
|
|
89
|
+
value: `.${prop.key.name}`
|
|
90
|
+
});
|
|
91
|
+
}
|
|
94
92
|
propNames.push(`'${prop.key.name}'`);
|
|
95
93
|
} else if (prop?.type === "RestElement" && prop.argument.type === "Identifier" && !prop.argument.name.startsWith(`${__vue_macros_common.HELPER_PREFIX}props`)) props.push({
|
|
96
94
|
path,
|
|
@@ -98,10 +96,15 @@ function getProps(node, path = "", s, props = [], options) {
|
|
|
98
96
|
value: propNames.join(", "),
|
|
99
97
|
isRest: true
|
|
100
98
|
});
|
|
101
|
-
else if (prop) getProps(prop, `${path}[${index}]`,
|
|
99
|
+
else if (prop) getProps(s, options, prop, `${path}[${index}]`, props);
|
|
102
100
|
});
|
|
103
101
|
return props.length ? props : void 0;
|
|
104
102
|
}
|
|
103
|
+
function getDefaultValue(node) {
|
|
104
|
+
if (node.type === "TSNonNullExpression") return getDefaultValue(node.expression);
|
|
105
|
+
if (node.type === "TSAsExpression") return getDefaultValue(node.expression);
|
|
106
|
+
return node;
|
|
107
|
+
}
|
|
105
108
|
function prependFunctionalNode(node, s, result) {
|
|
106
109
|
const isBlockStatement = node.body.type === "BlockStatement";
|
|
107
110
|
const start = node.body.extra?.parenthesized ? node.body.extra.parenStart : node.body.start;
|
|
@@ -166,37 +169,49 @@ function transformDefineComponent(root, propsName, map, s, autoReturnFunction =
|
|
|
166
169
|
if (defineComponentName && !["defineComponent", "defineVaporComponent"].includes(defineComponentName)) (0, __vue_macros_common.importHelperFn)(s, 0, "defineComponent", defineComponentName);
|
|
167
170
|
let hasRestProp = false;
|
|
168
171
|
const props = {};
|
|
169
|
-
if (root.params[0])
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
172
|
+
if (root.params[0]) {
|
|
173
|
+
if (root.params[0].type === "Identifier") getWalkedIds(root, propsName).forEach((id) => props[id] = null);
|
|
174
|
+
else if (root.params[0].type === "ObjectPattern") {
|
|
175
|
+
const restructuredProps = root.params[0];
|
|
176
|
+
for (const prop of restructuredProps.properties) {
|
|
177
|
+
if (prop.type !== "ObjectProperty" || prop.key.type !== "Identifier") continue;
|
|
178
|
+
const propName = prop.key.name;
|
|
179
|
+
if (prop.value.type !== "AssignmentPattern") {
|
|
180
|
+
props[propName] = null;
|
|
181
|
+
continue;
|
|
182
|
+
}
|
|
183
|
+
const defaultValue = getDefaultValue(prop.value.right);
|
|
184
|
+
const isRequired = prop.value.right.type === "TSNonNullExpression";
|
|
185
|
+
const propOptions = [];
|
|
186
|
+
if (isRequired) propOptions.push("required: true");
|
|
187
|
+
if (defaultValue) {
|
|
188
|
+
const { value, type, skipFactory } = getTypeAndValue(s, defaultValue);
|
|
189
|
+
if (type) propOptions.push(`type: ${type}`);
|
|
190
|
+
if (value) propOptions.push(`default: ${value}`);
|
|
191
|
+
if (skipFactory) propOptions.push("skipFactory: true");
|
|
192
|
+
}
|
|
193
|
+
if (propOptions.length) props[propName] = `{ ${propOptions.join(", ")} }`;
|
|
194
|
+
else props[propName] = null;
|
|
176
195
|
}
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
].includes(prop.key.name)) options[prop.key.name] = s.sliceNode(prop.value);
|
|
189
|
-
const propName = expression.arguments[0]?.type === "StringLiteral" ? expression.arguments[0].value : "modelValue";
|
|
190
|
-
props[propName] = Object.keys(options).length ? `{ ${Object.entries(options).map(([key, value]) => `${key}: ${value}`).join(", ")} }` : null;
|
|
191
|
-
props[`onUpdate:${propName}`] = null;
|
|
192
|
-
props[`${propName === "modelValue" ? "model" : propName}Modifiers`] = null;
|
|
196
|
+
restructure(s, root, {
|
|
197
|
+
skipDefaultProps: true,
|
|
198
|
+
generateRestProps: (restPropsName, index, list) => {
|
|
199
|
+
if (index === list.length - 1) {
|
|
200
|
+
hasRestProp = true;
|
|
201
|
+
const useAttrs = (0, __vue_macros_common.importHelperFn)(s, 0, "useAttrs");
|
|
202
|
+
return `const ${restPropsName} = ${useAttrs}()`;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
});
|
|
206
|
+
}
|
|
193
207
|
}
|
|
194
|
-
|
|
208
|
+
transformDefineModel$1(s, map.defineModel, props);
|
|
209
|
+
const propsString = Object.entries(props).map(([key, value]) => `'${key}': ${value}`).join(", \n");
|
|
195
210
|
if (propsString) {
|
|
196
211
|
const argument = map.defineComponent.arguments[1];
|
|
197
|
-
if (!argument) s.appendRight(root.end, `, {${hasRestProp ? "inheritAttrs: false," : ""} props: {
|
|
212
|
+
if (!argument) s.appendRight(root.end, `, {${hasRestProp ? "inheritAttrs: false," : ""} props: {\n${propsString}\n} }`);
|
|
198
213
|
else if (argument.type === "ObjectExpression") {
|
|
199
|
-
prependObjectExpression(argument, "props", `{
|
|
214
|
+
prependObjectExpression(argument, "props", `{\n${propsString}\n}`, s);
|
|
200
215
|
if (hasRestProp) prependObjectExpression(argument, "inheritAttrs", "false", s);
|
|
201
216
|
}
|
|
202
217
|
}
|
|
@@ -213,9 +228,70 @@ function getWalkedIds(root, propsName) {
|
|
|
213
228
|
const prop = parent.property.type === "Identifier" ? parent.property.name : parent.property.type === "StringLiteral" ? parent.property.value : "";
|
|
214
229
|
if (prop) walkedIds.add(prop);
|
|
215
230
|
}
|
|
216
|
-
}
|
|
231
|
+
});
|
|
217
232
|
return walkedIds;
|
|
218
233
|
}
|
|
234
|
+
function transformDefineModel$1(s, defineModel, props) {
|
|
235
|
+
for (const { expression, isRequired } of defineModel || []) {
|
|
236
|
+
const modelOptions = expression.arguments[0]?.type === "ObjectExpression" ? expression.arguments[0] : expression.arguments[1]?.type === "ObjectExpression" ? expression.arguments[1] : void 0;
|
|
237
|
+
const options = {};
|
|
238
|
+
if (isRequired) options.required = true;
|
|
239
|
+
let defaultValueNode;
|
|
240
|
+
for (const prop of modelOptions?.properties || []) if (prop.type === "ObjectProperty" && prop.key.type === "Identifier" && [
|
|
241
|
+
"validator",
|
|
242
|
+
"type",
|
|
243
|
+
"required",
|
|
244
|
+
"default"
|
|
245
|
+
].includes(prop.key.name)) {
|
|
246
|
+
if (prop.key.name === "default") defaultValueNode = prop.value;
|
|
247
|
+
options[prop.key.name] = s.sliceNode(prop.value);
|
|
248
|
+
}
|
|
249
|
+
if (defaultValueNode && !options.type) {
|
|
250
|
+
const { value, type, skipFactory } = getTypeAndValue(s, defaultValueNode);
|
|
251
|
+
if (type) options.type = type;
|
|
252
|
+
if (value) options.default = value;
|
|
253
|
+
if (skipFactory) options.skipFactory = "true";
|
|
254
|
+
}
|
|
255
|
+
const propName = expression.arguments[0]?.type === "StringLiteral" ? expression.arguments[0].value : "modelValue";
|
|
256
|
+
props[propName] = Object.keys(options).length ? `{ ${Object.entries(options).map(([key, value]) => `${key}: ${value}`).join(", ")} }` : null;
|
|
257
|
+
props[`onUpdate:${propName}`] = null;
|
|
258
|
+
props[`${propName === "modelValue" ? "model" : propName}Modifiers`] = null;
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
function getTypeAndValue(s, node) {
|
|
262
|
+
let value = "";
|
|
263
|
+
let type = "";
|
|
264
|
+
let skipFactory = false;
|
|
265
|
+
if (node.type === "StringLiteral") {
|
|
266
|
+
type = "String";
|
|
267
|
+
value = `'${node.value}'`;
|
|
268
|
+
} else if (node.type === "BooleanLiteral") {
|
|
269
|
+
type = "Boolean";
|
|
270
|
+
value = String(node.value);
|
|
271
|
+
} else if (node.type === "NumericLiteral") {
|
|
272
|
+
type = "Number";
|
|
273
|
+
value = String(node.value);
|
|
274
|
+
} else if (node.type === "ObjectExpression") {
|
|
275
|
+
type = "Object";
|
|
276
|
+
value = `() => (${s.sliceNode(node)})`;
|
|
277
|
+
} else if (node.type === "ArrayExpression") {
|
|
278
|
+
type = "Array";
|
|
279
|
+
value = `() => (${s.sliceNode(node)})`;
|
|
280
|
+
} else if (isFunctionalNode(node)) {
|
|
281
|
+
type = "Function";
|
|
282
|
+
value = s.sliceNode(node);
|
|
283
|
+
} else if (node.type === "Identifier") if (node.name === "undefined") value = "undefined";
|
|
284
|
+
else {
|
|
285
|
+
skipFactory = true;
|
|
286
|
+
value = s.sliceNode(node);
|
|
287
|
+
}
|
|
288
|
+
else if (node.type === "NullLiteral") value = "null";
|
|
289
|
+
return {
|
|
290
|
+
value,
|
|
291
|
+
type,
|
|
292
|
+
skipFactory
|
|
293
|
+
};
|
|
294
|
+
}
|
|
219
295
|
|
|
220
296
|
//#endregion
|
|
221
297
|
//#region src/core/define-expose.ts
|
package/dist/esbuild.cjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
3
|
-
require('./core-
|
|
4
|
-
require('./raw-
|
|
5
|
-
require('./options-
|
|
6
|
-
const require_src = require('./src-
|
|
3
|
+
require('./core-CdPKEM79.cjs');
|
|
4
|
+
require('./raw-CgNsul_i.cjs');
|
|
5
|
+
require('./options-BSX_vMxh.cjs');
|
|
6
|
+
const require_src = require('./src-BSxhhMQG.cjs');
|
|
7
7
|
|
|
8
8
|
//#region src/esbuild.ts
|
|
9
9
|
var esbuild_default = require_src.src_default.esbuild;
|
package/dist/esbuild.d.cts
CHANGED
package/dist/esbuild.d.ts
CHANGED
package/dist/esbuild.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import "./core-
|
|
2
|
-
import "./raw-
|
|
3
|
-
import "./options-
|
|
4
|
-
import { src_default } from "./src-
|
|
1
|
+
import "./core-B_EM_kTA.js";
|
|
2
|
+
import "./raw-BKMhH7EF.js";
|
|
3
|
+
import "./options-BWRkHmm5.js";
|
|
4
|
+
import { src_default } from "./src-Biftgb4Y.js";
|
|
5
5
|
|
|
6
6
|
//#region src/esbuild.ts
|
|
7
7
|
var esbuild_default = src_default.esbuild;
|