@vue-jsx-vapor/macros 2.2.0 → 2.3.1
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 -22
- package/dist/options.d.ts +2 -22
- 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 +220 -371
- package/dist/volar.d.cts +5 -4
- package/dist/volar.d.ts +5 -4
- package/dist/volar.js +217 -369
- 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 +3 -3
- package/dist/chunk-35H4MC4N.cjs +0 -65
- package/dist/chunk-53TNKVYD.cjs +0 -29
- package/dist/chunk-DANY2WQD.js +0 -29
- package/dist/chunk-JWJVYLYI.cjs +0 -12
- package/dist/chunk-LPH34H6O.cjs +0 -566
- package/dist/chunk-LVZNHMZC.js +0 -12
- package/dist/chunk-NL4CWOW2.cjs +0 -10
- package/dist/chunk-RC5ZHWIN.js +0 -10
- package/dist/chunk-TWP2JCYQ.js +0 -566
- package/dist/chunk-WOWB5VHY.js +0 -65
- package/dist/chunk-WZIZSQGW.js +0 -10
- package/dist/chunk-YCL7HGD4.cjs +0 -10
package/dist/volar.js
CHANGED
|
@@ -1,401 +1,249 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
} from "
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
import { createFilter } from "@vue-macros/common";
|
|
7
|
-
import { createPlugin } from "ts-macro";
|
|
8
|
-
|
|
9
|
-
// src/volar/index.ts
|
|
10
|
-
import {
|
|
11
|
-
HELPER_PREFIX as HELPER_PREFIX4
|
|
12
|
-
} from "@vue-macros/common";
|
|
13
|
-
import { replaceRange as replaceRange4 } from "ts-macro";
|
|
1
|
+
import { resolveOptions } from "./options-pbSvpKdV.js";
|
|
2
|
+
import { HELPER_PREFIX, createFilter } from "@vue-macros/common";
|
|
3
|
+
import { allCodeFeatures, createPlugin, replaceRange } from "ts-macro";
|
|
4
|
+
import { generateClassProperty } from "@vue/language-core/lib/codegen/style/classProperty.js";
|
|
5
|
+
import { parseCssClassNames } from "@vue/language-core/lib/utils/parseCssClassNames.js";
|
|
14
6
|
|
|
15
|
-
|
|
16
|
-
import { allCodeFeatures, replaceRange } from "ts-macro";
|
|
7
|
+
//#region src/volar/define-component.ts
|
|
17
8
|
function transformDefineComponent(node, options) {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
allCodeFeatures
|
|
33
|
-
] : "",
|
|
34
|
-
"), "
|
|
35
|
-
);
|
|
9
|
+
const { codes, source, ast } = options;
|
|
10
|
+
replaceRange(codes, node.arguments[0].end, node.end - 1);
|
|
11
|
+
const componentOptions = node.arguments[1];
|
|
12
|
+
replaceRange(codes, node.getStart(ast), node.expression.end + 1, "(", [
|
|
13
|
+
node.expression.getText(ast),
|
|
14
|
+
source,
|
|
15
|
+
node.getStart(ast),
|
|
16
|
+
allCodeFeatures
|
|
17
|
+
], "(() => ({}) as any, ", componentOptions ? [
|
|
18
|
+
componentOptions.getText(ast),
|
|
19
|
+
source,
|
|
20
|
+
componentOptions.getStart(ast),
|
|
21
|
+
allCodeFeatures
|
|
22
|
+
] : "", "), ");
|
|
36
23
|
}
|
|
37
24
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
import { replaceRange as replaceRange3 } from "ts-macro";
|
|
41
|
-
|
|
42
|
-
// src/volar/define-style.ts
|
|
43
|
-
import { HELPER_PREFIX } from "@vue-macros/common";
|
|
44
|
-
import { generateClassProperty } from "@vue/language-core/lib/codegen/style/classProperty.js";
|
|
45
|
-
import { parseCssClassNames } from "@vue/language-core/lib/utils/parseCssClassNames.js";
|
|
46
|
-
import { replaceRange as replaceRange2 } from "ts-macro";
|
|
25
|
+
//#endregion
|
|
26
|
+
//#region src/volar/define-style.ts
|
|
47
27
|
function transformDefineStyle(defineStyles, options) {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
expression.arguments.pos - 1,
|
|
55
|
-
expression.arguments.pos - 1,
|
|
56
|
-
`<${HELPER_PREFIX}PrettifyLocal<{}`,
|
|
57
|
-
...generateCssClassesType(
|
|
58
|
-
expression.arguments[0].getText(ast).slice(1, -1),
|
|
59
|
-
expression.arguments[0].getStart(ast) + 1,
|
|
60
|
-
index
|
|
61
|
-
),
|
|
62
|
-
">>"
|
|
63
|
-
);
|
|
64
|
-
}
|
|
65
|
-
addEmbeddedCode(expression, index, options);
|
|
66
|
-
});
|
|
28
|
+
if (!defineStyles?.length) return;
|
|
29
|
+
const { ts, codes, ast } = options;
|
|
30
|
+
defineStyles.forEach(({ expression, isCssModules }, index) => {
|
|
31
|
+
if (isCssModules && expression?.arguments[0] && !expression.typeArguments && ts.isTemplateLiteral(expression.arguments[0])) replaceRange(codes, expression.arguments.pos - 1, expression.arguments.pos - 1, `<${HELPER_PREFIX}PrettifyLocal<{}`, ...generateCssClassesType(expression.arguments[0].getText(ast).slice(1, -1), expression.arguments[0].getStart(ast) + 1, index), ">>");
|
|
32
|
+
addEmbeddedCode(expression, index, options);
|
|
33
|
+
});
|
|
67
34
|
}
|
|
68
35
|
function* generateCssClassesType(css, offset, index) {
|
|
69
|
-
|
|
70
|
-
yield* generateClassProperty(
|
|
71
|
-
index,
|
|
72
|
-
className.text,
|
|
73
|
-
className.offset + offset,
|
|
74
|
-
"string"
|
|
75
|
-
);
|
|
76
|
-
}
|
|
36
|
+
for (const className of [...parseCssClassNames(css)]) yield* generateClassProperty(index, className.text, className.offset + offset, "string");
|
|
77
37
|
}
|
|
78
38
|
function addEmbeddedCode(expression, index, options) {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
embeddedCodes: []
|
|
107
|
-
});
|
|
39
|
+
const { ts, ast } = options;
|
|
40
|
+
const languageId = ts.isPropertyAccessExpression(expression.expression) && ts.isIdentifier(expression.expression.name) ? expression.expression.name.text : "css";
|
|
41
|
+
const style = expression.arguments[0];
|
|
42
|
+
const styleText = style.getText(ast).slice(1, -1).replaceAll(/\$\{.*\}/g, (str) => "_".repeat(str.length));
|
|
43
|
+
options.embeddedCodes.push({
|
|
44
|
+
id: `style_${index}`,
|
|
45
|
+
languageId,
|
|
46
|
+
snapshot: {
|
|
47
|
+
getText: (start, end) => styleText.slice(start, end),
|
|
48
|
+
getLength: () => styleText.length,
|
|
49
|
+
getChangeRange: () => void 0
|
|
50
|
+
},
|
|
51
|
+
mappings: [{
|
|
52
|
+
sourceOffsets: [style.getStart(ast) + 1],
|
|
53
|
+
generatedOffsets: [0],
|
|
54
|
+
lengths: [styleText.length],
|
|
55
|
+
data: {
|
|
56
|
+
completion: true,
|
|
57
|
+
format: true,
|
|
58
|
+
navigation: true,
|
|
59
|
+
semantic: true,
|
|
60
|
+
structure: true,
|
|
61
|
+
verification: true
|
|
62
|
+
}
|
|
63
|
+
}],
|
|
64
|
+
embeddedCodes: []
|
|
65
|
+
});
|
|
108
66
|
}
|
|
109
67
|
|
|
110
|
-
|
|
68
|
+
//#endregion
|
|
69
|
+
//#region src/volar/transform.ts
|
|
111
70
|
function transformJsxMacros(rootMap, options) {
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
codes,
|
|
144
|
-
root.body.getStart(ast),
|
|
145
|
-
root.body.getStart(ast),
|
|
146
|
-
"=>"
|
|
147
|
-
);
|
|
148
|
-
replaceRange3(codes, root.end, root.end, `)){ return `, result, "}");
|
|
149
|
-
}
|
|
150
|
-
ts.forEachChild(root.body, (node) => {
|
|
151
|
-
if (ts.isReturnStatement(node) && node.expression) {
|
|
152
|
-
const props = [...map.defineModel ?? []];
|
|
153
|
-
const elements = root.parameters[0] && !root.parameters[0].type && ts.isObjectBindingPattern(root.parameters[0].name) ? root.parameters[0].name.elements : [];
|
|
154
|
-
for (const element of elements) {
|
|
155
|
-
if (ts.isIdentifier(element.name))
|
|
156
|
-
props.push(
|
|
157
|
-
`${element.name.escapedText}${element.initializer && ts.isNonNullExpression(element.initializer) ? ":" : "?:"} typeof ${element.name.escapedText}`
|
|
158
|
-
);
|
|
159
|
-
}
|
|
160
|
-
const shouldWrapByCall = (ts.isArrowFunction(node.expression) || ts.isFunctionExpression(node.expression)) && map.defineComponent;
|
|
161
|
-
replaceRange3(
|
|
162
|
-
codes,
|
|
163
|
-
node.getStart(ast),
|
|
164
|
-
node.expression.getStart(ast),
|
|
165
|
-
`return {
|
|
166
|
-
props: {} as { ${props.join(", ")} }`,
|
|
167
|
-
`,
|
|
168
|
-
slots: {} as ${map.defineSlots ?? "{}"}`,
|
|
169
|
-
`,
|
|
170
|
-
expose: (exposed: import('vue').ShallowUnwrapRef<${map.defineExpose ?? "{}"}>) => {}`,
|
|
171
|
-
`,
|
|
172
|
-
render: `,
|
|
173
|
-
shouldWrapByCall ? "(" : ""
|
|
174
|
-
);
|
|
175
|
-
replaceRange3(
|
|
176
|
-
codes,
|
|
177
|
-
node.expression.end,
|
|
178
|
-
node.expression.end,
|
|
179
|
-
shouldWrapByCall ? ")()" : "",
|
|
180
|
-
`
|
|
181
|
-
}`
|
|
182
|
-
);
|
|
183
|
-
}
|
|
184
|
-
});
|
|
185
|
-
}
|
|
71
|
+
const { ts, codes, ast } = options;
|
|
72
|
+
for (const [root, map] of rootMap) {
|
|
73
|
+
transformDefineStyle(map.defineStyle, options);
|
|
74
|
+
if (!root?.body) continue;
|
|
75
|
+
const asyncModifier = root.modifiers?.find((modifier) => modifier.kind === ts.SyntaxKind.AsyncKeyword);
|
|
76
|
+
if (asyncModifier && map.defineComponent) replaceRange(codes, asyncModifier.pos, asyncModifier.end);
|
|
77
|
+
const result = `({}) as __VLS_PickNotAny<typeof ${HELPER_PREFIX}ctx.render, {}> & { __ctx: typeof ${HELPER_PREFIX}ctx }`;
|
|
78
|
+
const propsType = root.parameters[0]?.type ? String(root.parameters[0].type.getText(ast)) : "{}";
|
|
79
|
+
replaceRange(codes, root.parameters.pos, root.parameters.pos, ts.isArrowFunction(root) && root.parameters.pos === root.pos ? "(" : "", `${HELPER_PREFIX}props: typeof ${HELPER_PREFIX}ctx.props & ${propsType}, `, `${HELPER_PREFIX}placeholder?: {}, `, `${HELPER_PREFIX}ctx = {} as Awaited<ReturnType<typeof ${HELPER_PREFIX}setup>>, `, `${HELPER_PREFIX}setup = (${asyncModifier ? "async" : ""}(`);
|
|
80
|
+
if (ts.isArrowFunction(root)) replaceRange(codes, root.end, root.end, `))${root.pos === root.parameters.pos ? ")" : ""} => `, result);
|
|
81
|
+
else {
|
|
82
|
+
replaceRange(codes, root.body.getStart(ast), root.body.getStart(ast), "=>");
|
|
83
|
+
replaceRange(codes, root.end, root.end, `)){ return `, result, "}");
|
|
84
|
+
}
|
|
85
|
+
ts.forEachChild(root.body, (node) => {
|
|
86
|
+
if (ts.isReturnStatement(node) && node.expression) {
|
|
87
|
+
const props = [...map.defineModel ?? []];
|
|
88
|
+
const elements = root.parameters[0] && !root.parameters[0].type && ts.isObjectBindingPattern(root.parameters[0].name) ? root.parameters[0].name.elements : [];
|
|
89
|
+
for (const element of elements) if (ts.isIdentifier(element.name)) props.push(`${element.name.escapedText}${element.initializer && ts.isNonNullExpression(element.initializer) ? ":" : "?:"} typeof ${element.name.escapedText}`);
|
|
90
|
+
const shouldWrapByCall = (ts.isArrowFunction(node.expression) || ts.isFunctionExpression(node.expression)) && map.defineComponent;
|
|
91
|
+
replaceRange(codes, node.getStart(ast), node.expression.getStart(ast), `const ${HELPER_PREFIX}render = `, shouldWrapByCall ? "(" : "");
|
|
92
|
+
replaceRange(codes, node.expression.end, node.expression.end, shouldWrapByCall ? ")()" : "", `
|
|
93
|
+
return {
|
|
94
|
+
props: {} as {${props.join(", ")}},
|
|
95
|
+
slots: {} as ${map.defineSlots ?? "{}"},
|
|
96
|
+
expose: (exposed: import('vue').ShallowUnwrapRef<${map.defineExpose ?? "{}"}>) => {},
|
|
97
|
+
render: ${HELPER_PREFIX}render,
|
|
98
|
+
}`);
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
}
|
|
186
102
|
}
|
|
187
103
|
|
|
188
|
-
|
|
189
|
-
|
|
104
|
+
//#endregion
|
|
105
|
+
//#region src/volar/global-types.ts
|
|
190
106
|
function getGlobalTypes(options) {
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
`
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
(alias) => `declare function ${alias}<Exposed extends Record<string, any> = Record<string, any>>(exposed?: Exposed): Exposed;`
|
|
198
|
-
).join("");
|
|
199
|
-
const defineStyle = options.defineStyle.alias.map(
|
|
200
|
-
(alias) => `declare const ${alias}: { <T>(...args: ${HELPER_PREFIX3}StyleArgs): T; scss: <T>(...args: ${HELPER_PREFIX3}StyleArgs)=> T; sass: <T>(...args: ${HELPER_PREFIX3}StyleArgs)=> T; stylus: <T>(...args: ${HELPER_PREFIX3}StyleArgs)=> T; less: <T>(...args: ${HELPER_PREFIX3}StyleArgs)=> T; postcss: <T>(...args: ${HELPER_PREFIX3}StyleArgs)=> T };
|
|
201
|
-
`
|
|
202
|
-
).join("");
|
|
203
|
-
const defineModel = options.defineModel.alias.map(
|
|
204
|
-
(alias) => alias === "defineModel" ? "defineModel" : `defineModel: ${alias}`
|
|
205
|
-
).join(", ");
|
|
206
|
-
const defineComponent = options.defineComponent.alias.map(
|
|
207
|
-
(alias) => ["defineComponent", "defineVaporComponent"].includes(alias) ? "" : `defineComponent: ${alias}`
|
|
208
|
-
).filter(Boolean).join(", ");
|
|
209
|
-
return `
|
|
107
|
+
const defineSlots = options.defineSlots.alias.flatMap((alias) => [`declare function ${alias}<T extends Record<string, any>>(): Partial<T>;`, `declare function ${alias}<T extends Record<string, any>>(slots: T): T;\n`]).join("");
|
|
108
|
+
const defineExpose = options.defineExpose.alias.map((alias) => `declare function ${alias}<Exposed extends Record<string, any> = Record<string, any>>(exposed?: Exposed): Exposed;`).join("");
|
|
109
|
+
const defineStyle = options.defineStyle.alias.map((alias) => `declare const ${alias}: { <T>(...args: ${HELPER_PREFIX}StyleArgs): T; scss: <T>(...args: ${HELPER_PREFIX}StyleArgs)=> T; sass: <T>(...args: ${HELPER_PREFIX}StyleArgs)=> T; stylus: <T>(...args: ${HELPER_PREFIX}StyleArgs)=> T; less: <T>(...args: ${HELPER_PREFIX}StyleArgs)=> T; postcss: <T>(...args: ${HELPER_PREFIX}StyleArgs)=> T };\n`).join("");
|
|
110
|
+
const defineModel = options.defineModel.alias.map((alias) => alias === "defineModel" ? "defineModel" : `defineModel: ${alias}`).join(", ");
|
|
111
|
+
const defineComponent = options.defineComponent.alias.map((alias) => ["defineComponent", "defineVaporComponent"].includes(alias) ? "" : `defineComponent: ${alias}`).filter(Boolean).join(", ");
|
|
112
|
+
return `
|
|
210
113
|
declare const { ${defineModel}, ${defineComponent} }: typeof import('vue')
|
|
211
114
|
${defineSlots}
|
|
212
115
|
${defineExpose}
|
|
213
116
|
${defineStyle}
|
|
214
|
-
type ${
|
|
215
|
-
type ${
|
|
117
|
+
type ${HELPER_PREFIX}StyleArgs = [style: string, options?: { scoped?: boolean }];
|
|
118
|
+
type ${HELPER_PREFIX}PrettifyLocal<T> = { [K in keyof T]: T[K]; } & {};
|
|
216
119
|
// @ts-ignore
|
|
217
120
|
type __VLS_IsAny<T> = 0 extends 1 & T ? true : false; type __VLS_PickNotAny<A, B> = __VLS_IsAny<A> extends true ? B : A;
|
|
218
121
|
`;
|
|
219
122
|
}
|
|
220
123
|
|
|
221
|
-
|
|
124
|
+
//#endregion
|
|
125
|
+
//#region src/volar/index.ts
|
|
222
126
|
function getMacro(node, ts, options) {
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
return ts.isIdentifier(expression.expression) && [
|
|
257
|
-
...options.defineModel.alias,
|
|
258
|
-
...options.defineSlots.alias,
|
|
259
|
-
...options.defineStyle.alias,
|
|
260
|
-
...options.defineExpose.alias,
|
|
261
|
-
...options.defineComponent.alias
|
|
262
|
-
].includes(expression.expression.escapedText) && node2;
|
|
263
|
-
}
|
|
127
|
+
if (!node) return;
|
|
128
|
+
if (ts.isVariableStatement(node)) return ts.forEachChild(node.declarationList, (decl) => getExpression(decl));
|
|
129
|
+
else return getExpression(node);
|
|
130
|
+
function getExpression(decl) {
|
|
131
|
+
if (ts.isVariableDeclaration(decl) && decl.initializer) {
|
|
132
|
+
const initializer = ts.isCallExpression(decl.initializer) && ts.isIdentifier(decl.initializer.expression) && decl.initializer.expression.escapedText === "$" && decl.initializer.arguments[0] ? decl.initializer.arguments[0] : decl.initializer;
|
|
133
|
+
const expression = getMacroExpression(initializer);
|
|
134
|
+
if (expression) return {
|
|
135
|
+
expression,
|
|
136
|
+
initializer: decl.initializer,
|
|
137
|
+
isRequired: ts.isNonNullExpression(initializer)
|
|
138
|
+
};
|
|
139
|
+
} else if (ts.isExpressionStatement(decl)) {
|
|
140
|
+
const expression = getMacroExpression(decl.expression);
|
|
141
|
+
if (expression) return {
|
|
142
|
+
expression,
|
|
143
|
+
initializer: decl.expression,
|
|
144
|
+
isRequired: ts.isNonNullExpression(decl.expression)
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
function getMacroExpression(node$1) {
|
|
149
|
+
if (ts.isNonNullExpression(node$1)) node$1 = node$1.expression;
|
|
150
|
+
if (!ts.isCallExpression(node$1)) return;
|
|
151
|
+
const expression = ts.isPropertyAccessExpression(node$1.expression) ? node$1.expression : node$1;
|
|
152
|
+
return ts.isIdentifier(expression.expression) && [
|
|
153
|
+
...options.defineModel.alias,
|
|
154
|
+
...options.defineSlots.alias,
|
|
155
|
+
...options.defineStyle.alias,
|
|
156
|
+
...options.defineExpose.alias,
|
|
157
|
+
...options.defineComponent.alias
|
|
158
|
+
].includes(expression.expression.escapedText) && node$1;
|
|
159
|
+
}
|
|
264
160
|
}
|
|
265
161
|
function getRootMap(options) {
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
`${!expression.arguments.hasTrailingComma && expression.arguments.length ? "," : ""} { required: true }`
|
|
321
|
-
);
|
|
322
|
-
}
|
|
323
|
-
const id = toValidAssetId(modelName, `${HELPER_PREFIX4}model`);
|
|
324
|
-
const typeString = `import('vue').UnwrapRef<typeof ${id}>`;
|
|
325
|
-
const defineModel = rootMap.get(root).defineModel ??= [];
|
|
326
|
-
defineModel.push(
|
|
327
|
-
`${modelName.includes("-") ? `'${modelName}'` : modelName}${isRequired ? ":" : "?:"} ${typeString}`,
|
|
328
|
-
`'onUpdate:${modelName}'?: ($event: ${typeString}) => any`
|
|
329
|
-
);
|
|
330
|
-
if (expression.typeArguments?.[1]) {
|
|
331
|
-
defineModel.push(
|
|
332
|
-
`${modelName}Modifiers?: Partial<Record<${expression.typeArguments[1].getText(ast)}, boolean>>`
|
|
333
|
-
);
|
|
334
|
-
}
|
|
335
|
-
replaceRange4(
|
|
336
|
-
codes,
|
|
337
|
-
initializer.getStart(ast),
|
|
338
|
-
initializer.getStart(ast),
|
|
339
|
-
`// @ts-ignore
|
|
340
|
-
${id};
|
|
341
|
-
let ${id} = `
|
|
342
|
-
);
|
|
343
|
-
} else if (options.defineSlots.alias.includes(macroName)) {
|
|
344
|
-
replaceRange4(
|
|
345
|
-
codes,
|
|
346
|
-
expression.getStart(ast),
|
|
347
|
-
expression.getStart(ast),
|
|
348
|
-
`// @ts-ignore
|
|
349
|
-
${HELPER_PREFIX4}slots;
|
|
350
|
-
const ${HELPER_PREFIX4}slots = `
|
|
351
|
-
);
|
|
352
|
-
rootMap.get(root).defineSlots = `Partial<typeof ${HELPER_PREFIX4}slots>`;
|
|
353
|
-
} else if (options.defineExpose.alias.includes(macroName)) {
|
|
354
|
-
replaceRange4(
|
|
355
|
-
codes,
|
|
356
|
-
expression.getStart(ast),
|
|
357
|
-
expression.getStart(ast),
|
|
358
|
-
`// @ts-ignore
|
|
359
|
-
${HELPER_PREFIX4}exposed;
|
|
360
|
-
const ${HELPER_PREFIX4}exposed = `
|
|
361
|
-
);
|
|
362
|
-
rootMap.get(root).defineExpose = `typeof ${HELPER_PREFIX4}exposed`;
|
|
363
|
-
}
|
|
364
|
-
}
|
|
365
|
-
ts.forEachChild(ast, (node) => walk(node, []));
|
|
366
|
-
return rootMap;
|
|
162
|
+
const { ts, ast, codes } = options;
|
|
163
|
+
const rootMap = new Map();
|
|
164
|
+
function walk(node, parents) {
|
|
165
|
+
ts.forEachChild(node, (child) => {
|
|
166
|
+
parents.unshift(node);
|
|
167
|
+
walk(child, parents);
|
|
168
|
+
parents.shift();
|
|
169
|
+
});
|
|
170
|
+
const root = parents[1] && (ts.isArrowFunction(parents[1]) || ts.isFunctionExpression(parents[1]) || ts.isFunctionDeclaration(parents[1])) ? parents[1] : void 0;
|
|
171
|
+
if (root && parents[2] && ts.isCallExpression(parents[2]) && !parents[2].typeArguments && options.defineComponent.alias.includes(parents[2].expression.getText(ast))) {
|
|
172
|
+
if (!rootMap.has(root)) rootMap.set(root, {});
|
|
173
|
+
if (!rootMap.get(root).defineComponent) {
|
|
174
|
+
rootMap.get(root).defineComponent = true;
|
|
175
|
+
transformDefineComponent(parents[2], options);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
const macro = getMacro(node, ts, options);
|
|
179
|
+
if (!macro) return;
|
|
180
|
+
const { expression, initializer } = macro;
|
|
181
|
+
let isRequired = macro.isRequired;
|
|
182
|
+
if (!rootMap.has(root)) rootMap.set(root, {});
|
|
183
|
+
const macroName = expression.expression.getText(ast);
|
|
184
|
+
if (macroName.startsWith("defineStyle")) (rootMap.get(root).defineStyle ??= []).push({
|
|
185
|
+
expression,
|
|
186
|
+
isCssModules: !!ts.isVariableStatement(node)
|
|
187
|
+
});
|
|
188
|
+
if (!root) return;
|
|
189
|
+
if (options.defineModel.alias.includes(macroName)) {
|
|
190
|
+
const modelName = expression.arguments[0] && ts.isStringLiteralLike(expression.arguments[0]) ? expression.arguments[0].text : "modelValue";
|
|
191
|
+
const modelOptions = expression.arguments[0] && ts.isStringLiteralLike(expression.arguments[0]) ? expression.arguments[1] : expression.arguments[0];
|
|
192
|
+
if (modelOptions && ts.isObjectLiteralExpression(modelOptions)) {
|
|
193
|
+
let hasRequired = false;
|
|
194
|
+
for (const prop of modelOptions.properties) if (ts.isPropertyAssignment(prop) && prop.name.getText(ast) === "required") {
|
|
195
|
+
hasRequired = true;
|
|
196
|
+
isRequired = prop.initializer.kind === ts.SyntaxKind.TrueKeyword;
|
|
197
|
+
}
|
|
198
|
+
if (!hasRequired && isRequired) replaceRange(codes, modelOptions.end - 1, modelOptions.end - 1, `${!modelOptions.properties.hasTrailingComma && modelOptions.properties.length ? "," : ""} required: true`);
|
|
199
|
+
} else if (isRequired) replaceRange(codes, expression.arguments.end, expression.arguments.end, `${!expression.arguments.hasTrailingComma && expression.arguments.length ? "," : ""} { required: true }`);
|
|
200
|
+
const id = toValidAssetId(modelName, `${HELPER_PREFIX}model`);
|
|
201
|
+
const typeString = `import('vue').UnwrapRef<typeof ${id}>`;
|
|
202
|
+
const defineModel = rootMap.get(root).defineModel ??= [];
|
|
203
|
+
defineModel.push(`${modelName.includes("-") ? `'${modelName}'` : modelName}${isRequired ? ":" : "?:"} ${typeString}`, `'onUpdate:${modelName}'?: ($event: ${typeString}) => any`);
|
|
204
|
+
if (expression.typeArguments?.[1]) defineModel.push(`${modelName}Modifiers?: Partial<Record<${expression.typeArguments[1].getText(ast)}, boolean>>`);
|
|
205
|
+
replaceRange(codes, initializer.getStart(ast), initializer.getStart(ast), `// @ts-ignore\n${id};\nlet ${id} = `);
|
|
206
|
+
} else if (options.defineSlots.alias.includes(macroName)) {
|
|
207
|
+
replaceRange(codes, expression.getStart(ast), expression.getStart(ast), `// @ts-ignore\n${HELPER_PREFIX}slots;\nconst ${HELPER_PREFIX}slots = `);
|
|
208
|
+
rootMap.get(root).defineSlots = `Partial<typeof ${HELPER_PREFIX}slots>`;
|
|
209
|
+
} else if (options.defineExpose.alias.includes(macroName)) {
|
|
210
|
+
replaceRange(codes, expression.getStart(ast), expression.getStart(ast), `// @ts-ignore\n${HELPER_PREFIX}exposed;\nconst ${HELPER_PREFIX}exposed = `);
|
|
211
|
+
rootMap.get(root).defineExpose = `typeof ${HELPER_PREFIX}exposed`;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
ts.forEachChild(ast, (node) => walk(node, []));
|
|
215
|
+
return rootMap;
|
|
367
216
|
}
|
|
368
217
|
function toValidAssetId(name, type) {
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
218
|
+
return `_${type}_${name.replaceAll(/\W/g, (searchValue, replaceValue) => {
|
|
219
|
+
return searchValue === "-" ? "_" : name.charCodeAt(replaceValue).toString();
|
|
220
|
+
})}`;
|
|
372
221
|
}
|
|
373
222
|
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
);
|
|
223
|
+
//#endregion
|
|
224
|
+
//#region src/volar.ts
|
|
225
|
+
const plugin = createPlugin(({ ts }, userOptions = {}) => {
|
|
226
|
+
const resolvedOptions = resolveOptions(userOptions);
|
|
227
|
+
const filter = createFilter(resolvedOptions);
|
|
228
|
+
return {
|
|
229
|
+
name: "@vue-jsx-vapor/macros",
|
|
230
|
+
resolveVirtualCode(virtualCode) {
|
|
231
|
+
const { filePath, codes } = virtualCode;
|
|
232
|
+
if (!filter(filePath)) return;
|
|
233
|
+
const options = {
|
|
234
|
+
ts,
|
|
235
|
+
...virtualCode,
|
|
236
|
+
...resolvedOptions
|
|
237
|
+
};
|
|
238
|
+
const rootMap = getRootMap(options);
|
|
239
|
+
if (rootMap.size) {
|
|
240
|
+
transformJsxMacros(rootMap, options);
|
|
241
|
+
codes.push(getGlobalTypes(options));
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
};
|
|
245
|
+
});
|
|
398
246
|
var volar_default = plugin;
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
};
|
|
247
|
+
|
|
248
|
+
//#endregion
|
|
249
|
+
export { volar_default as default };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const require_src = require('./src-DwQLomPw.cjs');
|
|
3
|
+
|
|
4
|
+
//#region src/webpack.ts
|
|
5
|
+
var webpack_default = require_src.src_default.webpack;
|
|
6
|
+
|
|
7
|
+
//#endregion
|
|
8
|
+
Object.defineProperty(exports, 'webpack_default', {
|
|
9
|
+
enumerable: true,
|
|
10
|
+
get: function () {
|
|
11
|
+
return webpack_default;
|
|
12
|
+
}
|
|
13
|
+
});
|