@vureact/compiler-core 1.1.1 → 1.2.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/README.md +4 -0
- package/README.zh.md +4 -0
- package/lib/{chunk-2ESB4I6I.esm.js → chunk-7FIMRVQS.esm.js} +1106 -775
- package/lib/{chunk-GWLPQNHN.js → chunk-SQRJUILR.js} +1217 -886
- package/lib/cli.esm.js +2 -2
- package/lib/cli.js +9 -9
- package/lib/compiler-core.d.cts +19 -2
- package/lib/compiler-core.d.ts +19 -2
- package/lib/compiler-core.esm.js +2 -2
- package/lib/compiler-core.js +3 -3
- package/package.json +2 -2
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } var _class; var _class2; var _class3; var _class4; var _class5; var _class6; var _class7; var _class8; var _class9; var _class10;/**
|
|
2
|
-
* @vureact/compiler-core v1.
|
|
2
|
+
* @vureact/compiler-core v1.2.1
|
|
3
3
|
* (c) 2025-present Ruihong Zhong (Ryan John)
|
|
4
4
|
* @license MIT
|
|
5
5
|
*/
|
|
@@ -24,95 +24,417 @@ function executePlugins(map, result, ctx) {
|
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
// src/core/codegen/component/jsx/syntax-processor/postprocess/build-ctx-provider.ts
|
|
27
|
-
var _types = require('@babel/types'); var t10 = _interopRequireWildcard(_types); var t = _interopRequireWildcard(_types); var t9 = _interopRequireWildcard(_types); var t2 = _interopRequireWildcard(_types); var t4 = _interopRequireWildcard(_types); var t3 = _interopRequireWildcard(_types); var t5 = _interopRequireWildcard(_types); var t6 = _interopRequireWildcard(_types); var t8 = _interopRequireWildcard(_types); var t7 = _interopRequireWildcard(_types); var t13 = _interopRequireWildcard(_types); var t11 = _interopRequireWildcard(_types); var t12 = _interopRequireWildcard(_types); var t14 = _interopRequireWildcard(_types); var t15 = _interopRequireWildcard(_types); var t16 = _interopRequireWildcard(_types); var t17 = _interopRequireWildcard(_types); var t19 = _interopRequireWildcard(_types); var t18 = _interopRequireWildcard(_types); var t20 = _interopRequireWildcard(_types); var
|
|
27
|
+
var _types = require('@babel/types'); var t10 = _interopRequireWildcard(_types); var t = _interopRequireWildcard(_types); var t9 = _interopRequireWildcard(_types); var t2 = _interopRequireWildcard(_types); var t4 = _interopRequireWildcard(_types); var t3 = _interopRequireWildcard(_types); var t5 = _interopRequireWildcard(_types); var t6 = _interopRequireWildcard(_types); var t8 = _interopRequireWildcard(_types); var t7 = _interopRequireWildcard(_types); var t13 = _interopRequireWildcard(_types); var t11 = _interopRequireWildcard(_types); var t12 = _interopRequireWildcard(_types); var t14 = _interopRequireWildcard(_types); var t15 = _interopRequireWildcard(_types); var t16 = _interopRequireWildcard(_types); var t17 = _interopRequireWildcard(_types); var t19 = _interopRequireWildcard(_types); var t18 = _interopRequireWildcard(_types); var t20 = _interopRequireWildcard(_types); var t22 = _interopRequireWildcard(_types); var t21 = _interopRequireWildcard(_types); var t23 = _interopRequireWildcard(_types); var t24 = _interopRequireWildcard(_types); var t29 = _interopRequireWildcard(_types); var t26 = _interopRequireWildcard(_types); var t25 = _interopRequireWildcard(_types); var t27 = _interopRequireWildcard(_types); var t28 = _interopRequireWildcard(_types); var t31 = _interopRequireWildcard(_types); var t30 = _interopRequireWildcard(_types); var t32 = _interopRequireWildcard(_types); var t33 = _interopRequireWildcard(_types); var t34 = _interopRequireWildcard(_types); var t35 = _interopRequireWildcard(_types); var t36 = _interopRequireWildcard(_types); var t39 = _interopRequireWildcard(_types); var t37 = _interopRequireWildcard(_types); var t38 = _interopRequireWildcard(_types); var t40 = _interopRequireWildcard(_types);
|
|
28
28
|
|
|
29
|
-
// src/consts/
|
|
30
|
-
var
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
Component: "Component",
|
|
35
|
-
Provider: "Provider",
|
|
36
|
-
// 实际是 Vue 的 provide 方法,为了命名统一采用 Provide
|
|
37
|
-
Transition: "Transition",
|
|
38
|
-
TransitionGroup: "TransitionGroup"
|
|
39
|
-
};
|
|
40
|
-
var ADAPTER_UTILS_MAP = {
|
|
41
|
-
dir: "dir",
|
|
42
|
-
dirCls: "dir.cls",
|
|
43
|
-
dirKeyless: "dir.keyless",
|
|
44
|
-
dirOn: "dir.on",
|
|
45
|
-
dirStyle: "dir.style",
|
|
46
|
-
nextTick: "nextTick"
|
|
29
|
+
// src/consts/other.ts
|
|
30
|
+
var PACKAGE_NAME = {
|
|
31
|
+
react: "react",
|
|
32
|
+
runtime: "@vureact/runtime-core",
|
|
33
|
+
router: "@vureact/router"
|
|
47
34
|
};
|
|
48
|
-
var
|
|
49
|
-
|
|
50
|
-
|
|
35
|
+
var STYLE_MODULE_NAME = "$style";
|
|
36
|
+
var MACRO_API_NAMES = {
|
|
37
|
+
props: "defineProps",
|
|
38
|
+
emits: "defineEmits",
|
|
39
|
+
slots: "defineSlots",
|
|
40
|
+
options: "defineOptions",
|
|
41
|
+
expose: "defineExpose"
|
|
51
42
|
};
|
|
52
|
-
var
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
43
|
+
var DOLLAR_IDENTIFIERS = [
|
|
44
|
+
"$data",
|
|
45
|
+
"$props",
|
|
46
|
+
"$el",
|
|
47
|
+
"$options",
|
|
48
|
+
"$parent",
|
|
49
|
+
"$root",
|
|
50
|
+
"$slots",
|
|
51
|
+
"$refs",
|
|
52
|
+
"$attrs",
|
|
53
|
+
"$emit",
|
|
54
|
+
"$watch",
|
|
55
|
+
"$forceUpdate",
|
|
56
|
+
"$nextTick",
|
|
57
|
+
"$router",
|
|
58
|
+
"$route",
|
|
59
|
+
"$store",
|
|
60
|
+
"$pinia",
|
|
61
|
+
"$event"
|
|
62
|
+
];
|
|
63
|
+
var VUE_PACKAGES = [
|
|
64
|
+
"vue",
|
|
65
|
+
"vite",
|
|
66
|
+
"pinia",
|
|
67
|
+
"nuxt",
|
|
68
|
+
// 不需要带到 React 项目中
|
|
69
|
+
"@vureact/compiler-core"
|
|
70
|
+
];
|
|
71
|
+
|
|
72
|
+
// src/consts/adapters-map.ts
|
|
73
|
+
var ADAPTER_RULES = {
|
|
74
|
+
// =============== [React] ===============
|
|
75
|
+
react: {
|
|
76
|
+
// =============== Hooks ===============
|
|
77
|
+
useTemplateRef: {
|
|
78
|
+
target: "useRef",
|
|
79
|
+
package: PACKAGE_NAME.react,
|
|
80
|
+
type: "none"
|
|
61
81
|
},
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
readonly: "useReadonly",
|
|
67
|
-
toRef: "useToVRef",
|
|
68
|
-
toRefs: "useToVRefs",
|
|
69
|
-
toRaw: "useToRaw",
|
|
70
|
-
inject: "useInject",
|
|
71
|
-
watch: "useWatch",
|
|
72
|
-
shallowRef: "useShallowRef",
|
|
73
|
-
shallowReactive: "useShallowReactive",
|
|
74
|
-
shallowReadonly: "useShallowReadonly",
|
|
75
|
-
isRef: "isRef",
|
|
76
|
-
isProxy: "isProxy",
|
|
77
|
-
isReactive: "isReactive"
|
|
82
|
+
defineExpose: {
|
|
83
|
+
target: "useImperativeHandle",
|
|
84
|
+
package: PACKAGE_NAME.react,
|
|
85
|
+
type: "none"
|
|
78
86
|
}
|
|
79
87
|
},
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
},
|
|
88
|
-
lifecycle: {
|
|
89
|
-
onBeforeUpdate: "useBeforeUpdate",
|
|
90
|
-
onUpdated: "useUpdated"
|
|
91
|
-
}
|
|
88
|
+
// ============== [VuReact Runtime Core] ===============
|
|
89
|
+
runtime: {
|
|
90
|
+
// =============== Components ===============
|
|
91
|
+
KeepAlive: {
|
|
92
|
+
target: "KeepAlive",
|
|
93
|
+
package: PACKAGE_NAME.runtime,
|
|
94
|
+
type: "rename"
|
|
92
95
|
},
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
96
|
+
Suspense: {
|
|
97
|
+
target: "Suspense",
|
|
98
|
+
package: PACKAGE_NAME.runtime,
|
|
99
|
+
type: "rename"
|
|
100
|
+
},
|
|
101
|
+
Teleport: {
|
|
102
|
+
target: "Teleport",
|
|
103
|
+
package: PACKAGE_NAME.runtime,
|
|
104
|
+
type: "rename"
|
|
105
|
+
},
|
|
106
|
+
Component: {
|
|
107
|
+
target: "Component",
|
|
108
|
+
package: PACKAGE_NAME.runtime,
|
|
109
|
+
type: "rename"
|
|
110
|
+
},
|
|
111
|
+
provide: {
|
|
112
|
+
target: "Provider",
|
|
113
|
+
package: PACKAGE_NAME.runtime,
|
|
114
|
+
type: "rename"
|
|
115
|
+
},
|
|
116
|
+
Transition: {
|
|
117
|
+
target: "Transition",
|
|
118
|
+
package: PACKAGE_NAME.runtime,
|
|
119
|
+
type: "rename"
|
|
120
|
+
},
|
|
121
|
+
TransitionGroup: {
|
|
122
|
+
target: "TransitionGroup",
|
|
123
|
+
package: PACKAGE_NAME.runtime,
|
|
124
|
+
type: "rename"
|
|
125
|
+
},
|
|
126
|
+
// =============== Hooks ===============
|
|
127
|
+
useActived: {
|
|
128
|
+
target: "useActived",
|
|
129
|
+
package: PACKAGE_NAME.runtime,
|
|
130
|
+
type: "rename"
|
|
131
|
+
},
|
|
132
|
+
useDeactivated: {
|
|
133
|
+
target: "useDeactivated",
|
|
134
|
+
package: PACKAGE_NAME.runtime,
|
|
135
|
+
type: "rename"
|
|
103
136
|
},
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
137
|
+
onBeforeMount: {
|
|
138
|
+
target: "useBeforeMount",
|
|
139
|
+
package: PACKAGE_NAME.runtime,
|
|
140
|
+
type: "rename"
|
|
141
|
+
},
|
|
142
|
+
onBeforeUnMount: {
|
|
143
|
+
target: "useBeforeUnMount",
|
|
144
|
+
package: PACKAGE_NAME.runtime,
|
|
145
|
+
type: "rename"
|
|
146
|
+
},
|
|
147
|
+
onMounted: {
|
|
148
|
+
target: "useMounted",
|
|
149
|
+
package: PACKAGE_NAME.runtime,
|
|
150
|
+
type: "rename"
|
|
151
|
+
},
|
|
152
|
+
onUnmounted: {
|
|
153
|
+
target: "useUnmounted",
|
|
154
|
+
package: PACKAGE_NAME.runtime,
|
|
155
|
+
type: "rename"
|
|
156
|
+
},
|
|
157
|
+
onBeforeUpdate: {
|
|
158
|
+
target: "useBeforeUpdate",
|
|
159
|
+
package: PACKAGE_NAME.runtime,
|
|
160
|
+
type: "analyzed-deps"
|
|
161
|
+
},
|
|
162
|
+
onUpdated: {
|
|
163
|
+
target: "useUpdated",
|
|
164
|
+
package: PACKAGE_NAME.runtime,
|
|
165
|
+
type: "analyzed-deps"
|
|
166
|
+
},
|
|
167
|
+
ref: {
|
|
168
|
+
target: "useVRef",
|
|
169
|
+
package: PACKAGE_NAME.runtime,
|
|
170
|
+
type: "rename",
|
|
171
|
+
isTrackable: true
|
|
172
|
+
},
|
|
173
|
+
reactive: {
|
|
174
|
+
target: "useReactive",
|
|
175
|
+
package: PACKAGE_NAME.runtime,
|
|
176
|
+
type: "rename",
|
|
177
|
+
isTrackable: true
|
|
178
|
+
},
|
|
179
|
+
computed: {
|
|
180
|
+
target: "useComputed",
|
|
181
|
+
package: PACKAGE_NAME.runtime,
|
|
182
|
+
type: "rename",
|
|
183
|
+
isTrackable: true
|
|
184
|
+
},
|
|
185
|
+
readonly: {
|
|
186
|
+
target: "useReadonly",
|
|
187
|
+
package: PACKAGE_NAME.runtime,
|
|
188
|
+
type: "rename",
|
|
189
|
+
isTrackable: true
|
|
190
|
+
},
|
|
191
|
+
toRef: {
|
|
192
|
+
target: "useToVRef",
|
|
193
|
+
package: PACKAGE_NAME.runtime,
|
|
194
|
+
type: "rename",
|
|
195
|
+
isTrackable: true
|
|
196
|
+
},
|
|
197
|
+
toRefs: {
|
|
198
|
+
target: "useToVRefs",
|
|
199
|
+
package: PACKAGE_NAME.runtime,
|
|
200
|
+
type: "rename",
|
|
201
|
+
isTrackable: true
|
|
202
|
+
},
|
|
203
|
+
toRaw: {
|
|
204
|
+
target: "useToRaw",
|
|
205
|
+
package: PACKAGE_NAME.runtime,
|
|
206
|
+
type: "rename"
|
|
207
|
+
},
|
|
208
|
+
inject: {
|
|
209
|
+
target: "useInject",
|
|
210
|
+
package: PACKAGE_NAME.runtime,
|
|
211
|
+
type: "rename",
|
|
212
|
+
isTrackable: true
|
|
213
|
+
},
|
|
214
|
+
shallowRef: {
|
|
215
|
+
target: "useShallowRef",
|
|
216
|
+
package: PACKAGE_NAME.runtime,
|
|
217
|
+
type: "rename",
|
|
218
|
+
isTrackable: true
|
|
219
|
+
},
|
|
220
|
+
shallowReactive: {
|
|
221
|
+
target: "useShallowReactive",
|
|
222
|
+
package: PACKAGE_NAME.runtime,
|
|
223
|
+
type: "rename",
|
|
224
|
+
isTrackable: true
|
|
225
|
+
},
|
|
226
|
+
shallowReadonly: {
|
|
227
|
+
target: "useShallowReadonly",
|
|
228
|
+
package: PACKAGE_NAME.runtime,
|
|
229
|
+
type: "rename",
|
|
230
|
+
isTrackable: true
|
|
231
|
+
},
|
|
232
|
+
isRef: {
|
|
233
|
+
target: "isRef",
|
|
234
|
+
package: PACKAGE_NAME.runtime,
|
|
235
|
+
type: "rename",
|
|
236
|
+
isTrackable: true
|
|
237
|
+
},
|
|
238
|
+
isProxy: {
|
|
239
|
+
target: "isProxy",
|
|
240
|
+
package: PACKAGE_NAME.runtime,
|
|
241
|
+
type: "rename",
|
|
242
|
+
isTrackable: true
|
|
243
|
+
},
|
|
244
|
+
isReactive: {
|
|
245
|
+
target: "isReactive",
|
|
246
|
+
package: PACKAGE_NAME.runtime,
|
|
247
|
+
type: "rename",
|
|
248
|
+
isTrackable: true
|
|
249
|
+
},
|
|
250
|
+
watch: {
|
|
251
|
+
target: "useWatch",
|
|
252
|
+
package: PACKAGE_NAME.runtime,
|
|
253
|
+
type: "rename"
|
|
254
|
+
},
|
|
255
|
+
watchEffect: {
|
|
256
|
+
target: "useWatchEffect",
|
|
257
|
+
package: PACKAGE_NAME.runtime,
|
|
258
|
+
type: "analyzed-deps"
|
|
259
|
+
},
|
|
260
|
+
watchPostEffect: {
|
|
261
|
+
target: "useWatchPostEffect",
|
|
262
|
+
package: PACKAGE_NAME.runtime,
|
|
263
|
+
type: "analyzed-deps"
|
|
264
|
+
},
|
|
265
|
+
watchSyncEffect: {
|
|
266
|
+
target: "useWatchSyncEffect",
|
|
267
|
+
package: PACKAGE_NAME.runtime,
|
|
268
|
+
type: "analyzed-deps"
|
|
269
|
+
},
|
|
270
|
+
// =============== Directive Utils ===============
|
|
271
|
+
dir: {
|
|
272
|
+
target: "dir",
|
|
273
|
+
package: PACKAGE_NAME.runtime,
|
|
274
|
+
type: "rename"
|
|
275
|
+
},
|
|
276
|
+
dirCls: {
|
|
277
|
+
target: "dir.cls",
|
|
278
|
+
package: PACKAGE_NAME.runtime,
|
|
279
|
+
type: "rename"
|
|
280
|
+
},
|
|
281
|
+
dirKeyless: {
|
|
282
|
+
target: "dir.keyless",
|
|
283
|
+
package: PACKAGE_NAME.runtime,
|
|
284
|
+
type: "rename"
|
|
285
|
+
},
|
|
286
|
+
dirOn: {
|
|
287
|
+
target: "dir.On",
|
|
288
|
+
package: PACKAGE_NAME.runtime,
|
|
289
|
+
type: "rename"
|
|
290
|
+
},
|
|
291
|
+
dirStyle: {
|
|
292
|
+
target: "dir.style",
|
|
293
|
+
package: PACKAGE_NAME.runtime,
|
|
294
|
+
type: "rename"
|
|
295
|
+
},
|
|
296
|
+
nextTick: {
|
|
297
|
+
target: "nextTick",
|
|
298
|
+
package: PACKAGE_NAME.runtime,
|
|
299
|
+
type: "rename"
|
|
108
300
|
}
|
|
109
301
|
},
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
302
|
+
// =================== [VuReact Router] ===================
|
|
303
|
+
router: {
|
|
304
|
+
// =============== Components ===============
|
|
305
|
+
RouterLink: {
|
|
306
|
+
target: "RouterLink",
|
|
307
|
+
package: PACKAGE_NAME.router,
|
|
308
|
+
type: "rename"
|
|
309
|
+
},
|
|
310
|
+
RouterView: {
|
|
311
|
+
target: "RouterView",
|
|
312
|
+
package: PACKAGE_NAME.router,
|
|
313
|
+
type: "rename"
|
|
314
|
+
},
|
|
315
|
+
// =============== Methods ===============
|
|
316
|
+
createRouter: {
|
|
317
|
+
target: "createRouter",
|
|
318
|
+
package: PACKAGE_NAME.router,
|
|
319
|
+
type: "rename"
|
|
320
|
+
},
|
|
321
|
+
createWebHistory: {
|
|
322
|
+
target: "createWebHistory",
|
|
323
|
+
package: PACKAGE_NAME.router,
|
|
324
|
+
type: "rename"
|
|
325
|
+
},
|
|
326
|
+
createWebHashHistory: {
|
|
327
|
+
target: "createWebHashHistory",
|
|
328
|
+
package: PACKAGE_NAME.router,
|
|
329
|
+
type: "rename"
|
|
330
|
+
},
|
|
331
|
+
createMemoryHistory: {
|
|
332
|
+
target: "createMemoryHistory",
|
|
333
|
+
package: PACKAGE_NAME.router,
|
|
334
|
+
type: "rename"
|
|
335
|
+
},
|
|
336
|
+
// =============== Hooks ===============
|
|
337
|
+
useRoute: {
|
|
338
|
+
target: "useRoute",
|
|
339
|
+
package: PACKAGE_NAME.router,
|
|
340
|
+
type: "rename",
|
|
341
|
+
isTrackable: true
|
|
342
|
+
},
|
|
343
|
+
useRouter: {
|
|
344
|
+
target: "useRouter",
|
|
345
|
+
package: PACKAGE_NAME.router,
|
|
346
|
+
type: "rename",
|
|
347
|
+
isTrackable: true
|
|
348
|
+
},
|
|
349
|
+
useLink: {
|
|
350
|
+
target: "useLink",
|
|
351
|
+
package: PACKAGE_NAME.router,
|
|
352
|
+
type: "rename",
|
|
353
|
+
isTrackable: true
|
|
354
|
+
},
|
|
355
|
+
onBeforeRouteLeave: {
|
|
356
|
+
target: "useBeforeRouteLeave",
|
|
357
|
+
package: PACKAGE_NAME.router,
|
|
358
|
+
type: "rename"
|
|
359
|
+
},
|
|
360
|
+
onBeforeRouteUpdate: {
|
|
361
|
+
target: "useBeforeRouteUpdate",
|
|
362
|
+
package: PACKAGE_NAME.router,
|
|
363
|
+
type: "rename"
|
|
364
|
+
},
|
|
365
|
+
onBeforeRouteEnter: {
|
|
366
|
+
target: "useBeforeRouteEnter",
|
|
367
|
+
package: PACKAGE_NAME.router,
|
|
368
|
+
type: "rename"
|
|
369
|
+
}
|
|
113
370
|
}
|
|
114
371
|
};
|
|
115
372
|
|
|
373
|
+
// src/consts/vue-api-map.ts
|
|
374
|
+
var VUE_API_MAP = {
|
|
375
|
+
ref: "ref",
|
|
376
|
+
provide: "provide",
|
|
377
|
+
watch: "watch",
|
|
378
|
+
watchEffect: "watchEffect",
|
|
379
|
+
watchPostEffect: "watchPostEffect",
|
|
380
|
+
watchSyncEffect: "watchSyncEffect",
|
|
381
|
+
useTemplateRef: "useTemplateRef",
|
|
382
|
+
defineAsyncComponent: "defineAsyncComponent",
|
|
383
|
+
DynamicComponent: "Component",
|
|
384
|
+
Transition: "Transition",
|
|
385
|
+
RouterLink: "RouterLink"
|
|
386
|
+
};
|
|
387
|
+
|
|
388
|
+
// src/shared/babel-utils.ts
|
|
389
|
+
var _parser = require('@babel/parser');
|
|
390
|
+
function getBabelParseOptions(lang = "js", context = "script", filename) {
|
|
391
|
+
const baseOptions = {
|
|
392
|
+
sourceType: "module",
|
|
393
|
+
sourceFilename: _nullishCoalesce(filename, () => ( "anonymous")),
|
|
394
|
+
errorRecovery: true
|
|
395
|
+
// 容错模式
|
|
396
|
+
};
|
|
397
|
+
const plugins = [];
|
|
398
|
+
if (lang.includes("ts")) {
|
|
399
|
+
plugins.push("typescript");
|
|
400
|
+
}
|
|
401
|
+
if (lang.endsWith("sx")) {
|
|
402
|
+
if (lang.startsWith("t")) plugins.push("typescript");
|
|
403
|
+
plugins.push("jsx");
|
|
404
|
+
}
|
|
405
|
+
if (context === "vueTemplate") {
|
|
406
|
+
plugins.push("decorators-legacy");
|
|
407
|
+
} else if (context === "expression") {
|
|
408
|
+
baseOptions.sourceType = "script";
|
|
409
|
+
baseOptions.allowReturnOutsideFunction = true;
|
|
410
|
+
baseOptions.allowSuperOutsideMethod = true;
|
|
411
|
+
}
|
|
412
|
+
plugins.push("classProperties", "objectRestSpread", "asyncGenerators");
|
|
413
|
+
return {
|
|
414
|
+
...baseOptions,
|
|
415
|
+
plugins: [...new Set(plugins)]
|
|
416
|
+
};
|
|
417
|
+
}
|
|
418
|
+
function stringToExpr(input, lang, filename = "") {
|
|
419
|
+
return _parser.parseExpression.call(void 0, input, getBabelParseOptions(lang, "expression", filename));
|
|
420
|
+
}
|
|
421
|
+
function atComponentOrHookRoot(path7, rootScope, inScriptFile = false) {
|
|
422
|
+
const { parentPath, scope } = path7;
|
|
423
|
+
const parentBlock = scope.block;
|
|
424
|
+
if (!parentPath) return !inScriptFile;
|
|
425
|
+
if (parentBlock === rootScope) {
|
|
426
|
+
if (inScriptFile) return false;
|
|
427
|
+
if (parentPath.isBlockStatement() && parentPath.node !== rootScope) {
|
|
428
|
+
return false;
|
|
429
|
+
}
|
|
430
|
+
if (parentPath.isCallExpression() || parentPath.isNewExpression()) {
|
|
431
|
+
return false;
|
|
432
|
+
}
|
|
433
|
+
return true;
|
|
434
|
+
}
|
|
435
|
+
return false;
|
|
436
|
+
}
|
|
437
|
+
|
|
116
438
|
// src/core/codegen/component/jsx/utils/jsx-element-utils.ts
|
|
117
439
|
|
|
118
440
|
function createJsxElement(tag, props, children, selfClosing) {
|
|
@@ -292,7 +614,7 @@ function buildMemoNode(nodeIR, ctx) {
|
|
|
292
614
|
|
|
293
615
|
|
|
294
616
|
// src/core/codegen/component/jsx/syntax-processor/process/build-slot-prop.ts
|
|
295
|
-
|
|
617
|
+
|
|
296
618
|
|
|
297
619
|
|
|
298
620
|
// src/shared/logger.ts
|
|
@@ -696,16 +1018,25 @@ function buildCtxProviderNode(nodeIR, ctx, children) {
|
|
|
696
1018
|
if (_optionalChain([nextProvide, 'optionalAccess', _25 => _25.isOccupied])) {
|
|
697
1019
|
childNodes = [buildCtxProviderNode(nextProvide, ctx, children)];
|
|
698
1020
|
}
|
|
699
|
-
const
|
|
700
|
-
t10.
|
|
701
|
-
|
|
1021
|
+
const parseProviderExpr = (raw) => {
|
|
1022
|
+
if (!raw) return t10.stringLiteral("");
|
|
1023
|
+
try {
|
|
1024
|
+
return stringToExpr(raw, ctx.scriptData.lang, ctx.filename);
|
|
1025
|
+
} catch (e4) {
|
|
1026
|
+
return t10.stringLiteral(raw);
|
|
1027
|
+
}
|
|
1028
|
+
};
|
|
1029
|
+
const nameProp = t10.jsxAttribute(
|
|
1030
|
+
t10.jsxIdentifier("name"),
|
|
1031
|
+
buildJsxExpressionNode(parseProviderExpr(name))
|
|
702
1032
|
);
|
|
703
1033
|
const valueProp = t10.jsxAttribute(
|
|
704
1034
|
t10.jsxIdentifier("value"),
|
|
705
|
-
buildJsxExpressionNode(
|
|
1035
|
+
buildJsxExpressionNode(parseProviderExpr(value))
|
|
706
1036
|
);
|
|
707
1037
|
void ctx;
|
|
708
|
-
|
|
1038
|
+
const adpater = ADAPTER_RULES.runtime[VUE_API_MAP.provide];
|
|
1039
|
+
return createJsxElement(adpater.target, [nameProp, valueProp], childNodes);
|
|
709
1040
|
}
|
|
710
1041
|
|
|
711
1042
|
// src/core/codegen/component/jsx/syntax-processor/postprocess/build-root-jsx.ts
|
|
@@ -783,9 +1114,11 @@ var REACT_API_MAP = {
|
|
|
783
1114
|
lazy: "lazy",
|
|
784
1115
|
memo: "memo",
|
|
785
1116
|
useRef: "useRef",
|
|
786
|
-
useCallback: "useCallback",
|
|
787
1117
|
useMemo: "useMemo",
|
|
788
|
-
ReactNode: "ReactNode"
|
|
1118
|
+
ReactNode: "ReactNode",
|
|
1119
|
+
forwardRef: "forwardRef",
|
|
1120
|
+
useCallback: "useCallback",
|
|
1121
|
+
useImperativeHandle: "useImperativeHandle"
|
|
789
1122
|
};
|
|
790
1123
|
|
|
791
1124
|
// src/utils/camelCase.ts
|
|
@@ -825,10 +1158,13 @@ function buildComponent(scriptIR, ctx, state) {
|
|
|
825
1158
|
const hasProps = getHasProps(propsTSIface.propsTypes) || getHasProps(propsTSIface.emitTypes) || getHasProps(propsTSIface.slotTypes);
|
|
826
1159
|
const shouldMemo = scriptIR !== null || hasProps;
|
|
827
1160
|
const jsxStatement = t12.returnStatement(state.jsx || t12.nullLiteral());
|
|
828
|
-
const component = !shouldMemo ?
|
|
1161
|
+
const component = !shouldMemo ? resolvePureUIComponent(jsxStatement, ctx) : resolveMemoComponent(scriptIR.statement.local, jsxStatement, ctx);
|
|
829
1162
|
state.component = component;
|
|
830
1163
|
}
|
|
831
|
-
function
|
|
1164
|
+
function getHasProps(list) {
|
|
1165
|
+
return list.length > 0;
|
|
1166
|
+
}
|
|
1167
|
+
function resolvePureUIComponent(jsxStmt, ctx) {
|
|
832
1168
|
return t12.variableDeclaration("const", [
|
|
833
1169
|
t12.variableDeclarator(
|
|
834
1170
|
resolveComponentName(ctx),
|
|
@@ -838,12 +1174,14 @@ function resolveComponent(jsxStmt, ctx) {
|
|
|
838
1174
|
}
|
|
839
1175
|
function resolveMemoComponent(local, jsxStmt, ctx) {
|
|
840
1176
|
const name = resolveComponentName(ctx);
|
|
841
|
-
const param =
|
|
842
|
-
const
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
)
|
|
846
|
-
|
|
1177
|
+
const param = resolvePropsParam(ctx);
|
|
1178
|
+
const body = t12.blockStatement(resolveLocalStatements(local, jsxStmt));
|
|
1179
|
+
const component = resolveComponent(param, body, ctx);
|
|
1180
|
+
let compFn = component;
|
|
1181
|
+
if (ctx.scriptData.forwardRef.enabled) {
|
|
1182
|
+
compFn = resolveForwardRef(body, ctx);
|
|
1183
|
+
}
|
|
1184
|
+
const memoCall = t12.callExpression(t12.identifier(REACT_API_MAP.memo), [compFn]);
|
|
847
1185
|
return t12.variableDeclaration("const", [t12.variableDeclarator(name, memoCall)]);
|
|
848
1186
|
}
|
|
849
1187
|
function resolveComponentName(ctx) {
|
|
@@ -860,7 +1198,52 @@ function resolveComponentName(ctx) {
|
|
|
860
1198
|
}
|
|
861
1199
|
return t12.identifier(name);
|
|
862
1200
|
}
|
|
863
|
-
function
|
|
1201
|
+
function resolveLocalStatements(local, jsx) {
|
|
1202
|
+
const stmts = [jsx];
|
|
1203
|
+
if (!local) return stmts;
|
|
1204
|
+
if (typeof local === "object" && "program" in local) {
|
|
1205
|
+
const program3 = local.program;
|
|
1206
|
+
if (_optionalChain([program3, 'optionalAccess', _28 => _28.body, 'optionalAccess', _29 => _29.length])) {
|
|
1207
|
+
return [...program3.body, jsx];
|
|
1208
|
+
}
|
|
1209
|
+
}
|
|
1210
|
+
return stmts;
|
|
1211
|
+
}
|
|
1212
|
+
function resolveComponent(param, body, ctx) {
|
|
1213
|
+
const {
|
|
1214
|
+
scriptData: { forwardRef }
|
|
1215
|
+
} = ctx;
|
|
1216
|
+
if (forwardRef.enabled) {
|
|
1217
|
+
return resolveForwardRef(body, ctx);
|
|
1218
|
+
}
|
|
1219
|
+
const baseComponent = t12.arrowFunctionExpression(!param ? [] : [param], body);
|
|
1220
|
+
return baseComponent;
|
|
1221
|
+
}
|
|
1222
|
+
function resolveForwardRef(body, ctx) {
|
|
1223
|
+
const {
|
|
1224
|
+
propField,
|
|
1225
|
+
scriptData: { forwardRef, lang }
|
|
1226
|
+
} = ctx;
|
|
1227
|
+
const params = [t12.identifier(forwardRef.refField)];
|
|
1228
|
+
const propsId = resolvePropsParam(ctx);
|
|
1229
|
+
const callExpr = t12.callExpression(t12.identifier(REACT_API_MAP.forwardRef), [
|
|
1230
|
+
t12.arrowFunctionExpression(params, body)
|
|
1231
|
+
]);
|
|
1232
|
+
if (lang.startsWith("ts")) {
|
|
1233
|
+
const types = [t12.tsAnyKeyword()];
|
|
1234
|
+
if (propsId) {
|
|
1235
|
+
const propsType = _optionalChain([propsId, 'optionalAccess', _30 => _30.typeAnnotation, 'optionalAccess', _31 => _31.typeAnnotation]);
|
|
1236
|
+
types.push(propsType || t12.tsAnyKeyword());
|
|
1237
|
+
}
|
|
1238
|
+
callExpr.typeParameters = t12.tsTypeParameterInstantiation(types);
|
|
1239
|
+
}
|
|
1240
|
+
if (propsId) {
|
|
1241
|
+
propsId.typeAnnotation = null;
|
|
1242
|
+
params.unshift(propsId);
|
|
1243
|
+
}
|
|
1244
|
+
return callExpr;
|
|
1245
|
+
}
|
|
1246
|
+
function resolvePropsParam(ctx) {
|
|
864
1247
|
const { propField, scriptData } = ctx;
|
|
865
1248
|
const { propsTSIface } = scriptData;
|
|
866
1249
|
const propsIdentifier = t12.identifier(propField);
|
|
@@ -877,24 +1260,10 @@ function resolveParam(ctx) {
|
|
|
877
1260
|
propsIdentifier.typeAnnotation = t12.tsTypeAnnotation(t12.tsTypeReference(typeIdentifier));
|
|
878
1261
|
return propsIdentifier;
|
|
879
1262
|
}
|
|
880
|
-
function resolveStatements(local, jsx) {
|
|
881
|
-
const stmts = [jsx];
|
|
882
|
-
if (!local) return stmts;
|
|
883
|
-
if (typeof local === "object" && "program" in local) {
|
|
884
|
-
const program3 = local.program;
|
|
885
|
-
if (_optionalChain([program3, 'optionalAccess', _28 => _28.body, 'optionalAccess', _29 => _29.length])) {
|
|
886
|
-
return [...program3.body, jsx];
|
|
887
|
-
}
|
|
888
|
-
}
|
|
889
|
-
return stmts;
|
|
890
|
-
}
|
|
891
|
-
function getHasProps(list) {
|
|
892
|
-
return list.length > 0;
|
|
893
|
-
}
|
|
894
1263
|
|
|
895
1264
|
// src/core/codegen/component/script/syntax-processor/process/build-program-preamble.ts
|
|
896
1265
|
function buildProgramPreamble(nodeIR, ctx, state) {
|
|
897
|
-
const statements = [_optionalChain([nodeIR, 'optionalAccess',
|
|
1266
|
+
const statements = [_optionalChain([nodeIR, 'optionalAccess', _32 => _32.imports]), _optionalChain([nodeIR, 'optionalAccess', _33 => _33.tsTypes]), _optionalChain([nodeIR, 'optionalAccess', _34 => _34.exports]), _optionalChain([nodeIR, 'optionalAccess', _35 => _35.statement, 'access', _36 => _36.global])].flat().filter(Boolean);
|
|
898
1267
|
state.preambleStatements = statements;
|
|
899
1268
|
void ctx;
|
|
900
1269
|
}
|
|
@@ -949,7 +1318,7 @@ function generateComponent(ir, ctx, options) {
|
|
|
949
1318
|
code,
|
|
950
1319
|
source: ctx.source
|
|
951
1320
|
};
|
|
952
|
-
executePlugins(_optionalChain([options, 'optionalAccess',
|
|
1321
|
+
executePlugins(_optionalChain([options, 'optionalAccess', _37 => _37.plugins]), result, ctx);
|
|
953
1322
|
return result;
|
|
954
1323
|
}
|
|
955
1324
|
|
|
@@ -963,7 +1332,7 @@ function generateOnlyScript(ir, ctx, options) {
|
|
|
963
1332
|
code,
|
|
964
1333
|
source: ctx.source
|
|
965
1334
|
};
|
|
966
|
-
executePlugins(_optionalChain([options, 'optionalAccess',
|
|
1335
|
+
executePlugins(_optionalChain([options, 'optionalAccess', _38 => _38.plugins]), result, ctx);
|
|
967
1336
|
return result;
|
|
968
1337
|
}
|
|
969
1338
|
|
|
@@ -975,58 +1344,6 @@ function generate(ir, ctx, options) {
|
|
|
975
1344
|
|
|
976
1345
|
// src/core/parse/script-only.ts
|
|
977
1346
|
|
|
978
|
-
|
|
979
|
-
// src/shared/babel-utils.ts
|
|
980
|
-
|
|
981
|
-
function getBabelParseOptions(lang = "js", context = "script", filename) {
|
|
982
|
-
const baseOptions = {
|
|
983
|
-
sourceType: "module",
|
|
984
|
-
sourceFilename: _nullishCoalesce(filename, () => ( "anonymous")),
|
|
985
|
-
errorRecovery: true
|
|
986
|
-
// 容错模式
|
|
987
|
-
};
|
|
988
|
-
const plugins = [];
|
|
989
|
-
if (lang.includes("ts")) {
|
|
990
|
-
plugins.push("typescript");
|
|
991
|
-
}
|
|
992
|
-
if (lang.endsWith("sx")) {
|
|
993
|
-
if (lang.startsWith("t")) plugins.push("typescript");
|
|
994
|
-
plugins.push("jsx");
|
|
995
|
-
}
|
|
996
|
-
if (context === "vueTemplate") {
|
|
997
|
-
plugins.push("decorators-legacy");
|
|
998
|
-
} else if (context === "expression") {
|
|
999
|
-
baseOptions.sourceType = "script";
|
|
1000
|
-
baseOptions.allowReturnOutsideFunction = true;
|
|
1001
|
-
baseOptions.allowSuperOutsideMethod = true;
|
|
1002
|
-
}
|
|
1003
|
-
plugins.push("classProperties", "objectRestSpread", "asyncGenerators");
|
|
1004
|
-
return {
|
|
1005
|
-
...baseOptions,
|
|
1006
|
-
plugins: [...new Set(plugins)]
|
|
1007
|
-
};
|
|
1008
|
-
}
|
|
1009
|
-
function stringToExpr(input, lang, filename = "") {
|
|
1010
|
-
return _parser.parseExpression.call(void 0, input, getBabelParseOptions(lang, "expression", filename));
|
|
1011
|
-
}
|
|
1012
|
-
function atComponentOrHookRoot(path7, rootScope, inScriptFile = false) {
|
|
1013
|
-
const { parentPath, scope } = path7;
|
|
1014
|
-
const parentBlock = scope.block;
|
|
1015
|
-
if (!parentPath) return !inScriptFile;
|
|
1016
|
-
if (parentBlock === rootScope) {
|
|
1017
|
-
if (inScriptFile) return false;
|
|
1018
|
-
if (parentPath.isBlockStatement() && parentPath.node !== rootScope) {
|
|
1019
|
-
return false;
|
|
1020
|
-
}
|
|
1021
|
-
if (parentPath.isCallExpression() || parentPath.isNewExpression()) {
|
|
1022
|
-
return false;
|
|
1023
|
-
}
|
|
1024
|
-
return true;
|
|
1025
|
-
}
|
|
1026
|
-
return false;
|
|
1027
|
-
}
|
|
1028
|
-
|
|
1029
|
-
// src/core/parse/script-only.ts
|
|
1030
1347
|
function parseOnlyScript(source, ctx, options) {
|
|
1031
1348
|
const lang = ctx.inputType.split("-")[1];
|
|
1032
1349
|
const ast = _parser.parse.call(void 0, source, getBabelParseOptions(lang, "script", ctx.filename));
|
|
@@ -1048,7 +1365,7 @@ function parseOnlyScript(source, ctx, options) {
|
|
|
1048
1365
|
};
|
|
1049
1366
|
ctx.scriptData.lang = lang;
|
|
1050
1367
|
ctx.scriptData.source = source;
|
|
1051
|
-
executePlugins(_optionalChain([options, 'optionalAccess',
|
|
1368
|
+
executePlugins(_optionalChain([options, 'optionalAccess', _39 => _39.plugins]), result, ctx);
|
|
1052
1369
|
return result;
|
|
1053
1370
|
}
|
|
1054
1371
|
|
|
@@ -1083,8 +1400,8 @@ function resolveScript(descriptor, ctx, pResult) {
|
|
|
1083
1400
|
} else {
|
|
1084
1401
|
result.ast = _parser.parse.call(void 0, result.source.content, options);
|
|
1085
1402
|
}
|
|
1086
|
-
if (_optionalChain([scriptBlock, 'optionalAccess',
|
|
1087
|
-
_optionalChain([scriptBlock, 'optionalAccess',
|
|
1403
|
+
if (_optionalChain([scriptBlock, 'optionalAccess', _40 => _40.warnings])) {
|
|
1404
|
+
_optionalChain([scriptBlock, 'optionalAccess', _41 => _41.warnings, 'access', _42 => _42.forEach, 'call', _43 => _43((msg) => {
|
|
1088
1405
|
logger.warn(msg, { file: ctx.filename });
|
|
1089
1406
|
})]);
|
|
1090
1407
|
}
|
|
@@ -1159,7 +1476,7 @@ function extractSetupBodyToTopLevel(content, options) {
|
|
|
1159
1476
|
}
|
|
1160
1477
|
function extractCompName(source) {
|
|
1161
1478
|
const nameMatch = source.match(/@vr-name:\s*(\w+)/);
|
|
1162
|
-
return _optionalChain([nameMatch, 'optionalAccess',
|
|
1479
|
+
return _optionalChain([nameMatch, 'optionalAccess', _44 => _44[1], 'optionalAccess', _45 => _45.trim, 'call', _46 => _46()]) || "";
|
|
1163
1480
|
}
|
|
1164
1481
|
|
|
1165
1482
|
// src/core/parse/sfc/process/resolve-script-meta.ts
|
|
@@ -1234,11 +1551,6 @@ var HTML_TAG_TYPES = {
|
|
|
1234
1551
|
frame: "HTMLFrameElement"
|
|
1235
1552
|
};
|
|
1236
1553
|
|
|
1237
|
-
// src/consts/vue-api-map.ts
|
|
1238
|
-
var VUE_API_MAP = {
|
|
1239
|
-
useTemplateRef: "useTemplateRef"
|
|
1240
|
-
};
|
|
1241
|
-
|
|
1242
1554
|
// src/consts/reactive-type-map.ts
|
|
1243
1555
|
var REACTIVE_TYPE_MAP = {
|
|
1244
1556
|
ref: "ref",
|
|
@@ -1270,7 +1582,7 @@ function getReactiveStateApis() {
|
|
|
1270
1582
|
|
|
1271
1583
|
// src/core/parse/sfc/process/resolve-script-meta.ts
|
|
1272
1584
|
function resolveScriptMeta(result, ctx) {
|
|
1273
|
-
const scriptAST = _optionalChain([result, 'access',
|
|
1585
|
+
const scriptAST = _optionalChain([result, 'access', _47 => _47.script, 'optionalAccess', _48 => _48.ast]);
|
|
1274
1586
|
if (!scriptAST) return;
|
|
1275
1587
|
_core.traverse.call(void 0, scriptAST, {
|
|
1276
1588
|
VariableDeclarator(path7) {
|
|
@@ -1294,7 +1606,7 @@ function collectReactiveBindings(node, ctx) {
|
|
|
1294
1606
|
if (!reactiveStateApis.has(source)) return;
|
|
1295
1607
|
const varName = node.id.name;
|
|
1296
1608
|
const value = init.arguments[0];
|
|
1297
|
-
if (source ===
|
|
1609
|
+
if (source === MACRO_API_NAMES.props) {
|
|
1298
1610
|
ctx.propField = varName;
|
|
1299
1611
|
}
|
|
1300
1612
|
reactiveBindings[varName] = {
|
|
@@ -1310,56 +1622,14 @@ function collectRefBindings(node, ctx) {
|
|
|
1310
1622
|
const callee = init.callee;
|
|
1311
1623
|
if (callee.name !== VUE_API_MAP.useTemplateRef) return;
|
|
1312
1624
|
const idName = node.id.name;
|
|
1313
|
-
const tag = _optionalChain([init, 'access',
|
|
1314
|
-
refBindings[idName] = {
|
|
1625
|
+
const tag = _optionalChain([init, 'access', _49 => _49.arguments, 'access', _50 => _50[0], 'optionalAccess', _51 => _51.value]);
|
|
1626
|
+
refBindings.domRefs[idName] = {
|
|
1315
1627
|
tag,
|
|
1316
1628
|
htmlType: HTML_TAG_TYPES[tag] || "HTMLElement",
|
|
1317
1629
|
name: idName
|
|
1318
1630
|
};
|
|
1319
1631
|
}
|
|
1320
1632
|
|
|
1321
|
-
// src/consts/other.ts
|
|
1322
|
-
var PACKAGE_NAME = {
|
|
1323
|
-
react: "react",
|
|
1324
|
-
runtime: "@vureact/runtime-core",
|
|
1325
|
-
router: "@vureact/router"
|
|
1326
|
-
};
|
|
1327
|
-
var STYLE_MODULE_NAME = "$style";
|
|
1328
|
-
var MACRO_API_NAMES = {
|
|
1329
|
-
props: "defineProps",
|
|
1330
|
-
emits: "defineEmits",
|
|
1331
|
-
slots: "defineSlots",
|
|
1332
|
-
options: "defineOptions"
|
|
1333
|
-
};
|
|
1334
|
-
var DOLLAR_IDENTIFIERS = [
|
|
1335
|
-
"$data",
|
|
1336
|
-
"$props",
|
|
1337
|
-
"$el",
|
|
1338
|
-
"$options",
|
|
1339
|
-
"$parent",
|
|
1340
|
-
"$root",
|
|
1341
|
-
"$slots",
|
|
1342
|
-
"$refs",
|
|
1343
|
-
"$attrs",
|
|
1344
|
-
"$emit",
|
|
1345
|
-
"$watch",
|
|
1346
|
-
"$forceUpdate",
|
|
1347
|
-
"$nextTick",
|
|
1348
|
-
"$router",
|
|
1349
|
-
"$route",
|
|
1350
|
-
"$store",
|
|
1351
|
-
"$pinia",
|
|
1352
|
-
"$event"
|
|
1353
|
-
];
|
|
1354
|
-
var VUE_PACKAGES = [
|
|
1355
|
-
"vue",
|
|
1356
|
-
"vite",
|
|
1357
|
-
"pinia",
|
|
1358
|
-
"nuxt",
|
|
1359
|
-
// 不需要带到 React 项目中
|
|
1360
|
-
"@vureact/compiler-core"
|
|
1361
|
-
];
|
|
1362
|
-
|
|
1363
1633
|
// src/plugins/postcss.ts
|
|
1364
1634
|
var _postcss = require('postcss'); var _postcss2 = _interopRequireDefault(_postcss);
|
|
1365
1635
|
function processScopedWithPostCss(input, hash) {
|
|
@@ -1526,7 +1796,7 @@ function resolveStyles(descriptor, ctx, result) {
|
|
|
1526
1796
|
var _compilercore = require('@vue/compiler-core');
|
|
1527
1797
|
function resolveTemplate(descriptor, _, result) {
|
|
1528
1798
|
const block = descriptor.template;
|
|
1529
|
-
if (!_optionalChain([block, 'optionalAccess',
|
|
1799
|
+
if (!_optionalChain([block, 'optionalAccess', _52 => _52.content])) return null;
|
|
1530
1800
|
result.template = {
|
|
1531
1801
|
ast: _compilercore.baseParse.call(void 0, block.content),
|
|
1532
1802
|
source: block
|
|
@@ -1543,7 +1813,7 @@ function processVueSyntax(descriptor, ctx, result) {
|
|
|
1543
1813
|
}
|
|
1544
1814
|
function vueSyntaxProcessor(descriptor, ctx, result, options) {
|
|
1545
1815
|
const run = (p, type) => {
|
|
1546
|
-
_optionalChain([p, 'optionalAccess',
|
|
1816
|
+
_optionalChain([p, 'optionalAccess', _53 => _53.forEach, 'call', _54 => _54((handler) => {
|
|
1547
1817
|
if (type === "post") {
|
|
1548
1818
|
handler(result, ctx);
|
|
1549
1819
|
return;
|
|
@@ -1567,7 +1837,7 @@ function parseSFC(source, ctx, options) {
|
|
|
1567
1837
|
};
|
|
1568
1838
|
collectErrs(descriptor, errors);
|
|
1569
1839
|
processVueSyntax(descriptor, ctx, result);
|
|
1570
|
-
executePlugins(_optionalChain([options, 'optionalAccess',
|
|
1840
|
+
executePlugins(_optionalChain([options, 'optionalAccess', _55 => _55.plugins]), result, ctx);
|
|
1571
1841
|
return result;
|
|
1572
1842
|
}
|
|
1573
1843
|
function collectErrs(descriptor, errors) {
|
|
@@ -1575,7 +1845,7 @@ function collectErrs(descriptor, errors) {
|
|
|
1575
1845
|
logger.error(err.message, {
|
|
1576
1846
|
source: descriptor.source,
|
|
1577
1847
|
file: descriptor.filename,
|
|
1578
|
-
loc: _optionalChain([err, 'optionalAccess',
|
|
1848
|
+
loc: _optionalChain([err, 'optionalAccess', _56 => _56.loc])
|
|
1579
1849
|
});
|
|
1580
1850
|
}
|
|
1581
1851
|
if (descriptor.cssVars.length) {
|
|
@@ -1620,6 +1890,9 @@ function insertCSSImport(ctx) {
|
|
|
1620
1890
|
// src/core/transform/shared.ts
|
|
1621
1891
|
function recordImport(ctx, pkg, name, onDemand = true) {
|
|
1622
1892
|
const { imports } = ctx;
|
|
1893
|
+
if (isTypeOnlyImport(name)) {
|
|
1894
|
+
name = `type ${name}`;
|
|
1895
|
+
}
|
|
1623
1896
|
if (imports.has(pkg)) {
|
|
1624
1897
|
const list = imports.get(pkg);
|
|
1625
1898
|
const foundItem = list.find((item) => item.name === name);
|
|
@@ -1630,6 +1903,10 @@ function recordImport(ctx, pkg, name, onDemand = true) {
|
|
|
1630
1903
|
}
|
|
1631
1904
|
imports.set(pkg, [{ name, onDemand }]);
|
|
1632
1905
|
}
|
|
1906
|
+
function isTypeOnlyImport(name) {
|
|
1907
|
+
const arr = [REACT_API_MAP.ReactNode];
|
|
1908
|
+
return arr.includes(name);
|
|
1909
|
+
}
|
|
1633
1910
|
|
|
1634
1911
|
// src/core/transform/sfc/script/shared/replace-vue-suffix.ts
|
|
1635
1912
|
function replaceVueSuffix(ctx, node) {
|
|
@@ -1713,7 +1990,7 @@ function isVueEcosystemPackage(moduleName) {
|
|
|
1713
1990
|
function mergeImports(currentNode, ctx) {
|
|
1714
1991
|
const moduleName = currentNode.source.value.toLowerCase();
|
|
1715
1992
|
const ctxImportItems = ctx.imports.get(moduleName);
|
|
1716
|
-
if (!_optionalChain([ctxImportItems, 'optionalAccess',
|
|
1993
|
+
if (!_optionalChain([ctxImportItems, 'optionalAccess', _57 => _57.length])) {
|
|
1717
1994
|
return;
|
|
1718
1995
|
}
|
|
1719
1996
|
const currentImports = /* @__PURE__ */ new Set();
|
|
@@ -1767,7 +2044,7 @@ function createRequiredImports(ctx) {
|
|
|
1767
2044
|
|
|
1768
2045
|
function findRootVariablePath(path7) {
|
|
1769
2046
|
const rootId = findRootIdentifier(path7.node);
|
|
1770
|
-
if (!_optionalChain([rootId, 'optionalAccess',
|
|
2047
|
+
if (!_optionalChain([rootId, 'optionalAccess', _58 => _58.name])) return null;
|
|
1771
2048
|
const binding = path7.scope.getBinding(rootId.name);
|
|
1772
2049
|
if (!binding) return null;
|
|
1773
2050
|
const rootPath = getVariableDeclaratorPath(binding.path);
|
|
@@ -1998,66 +2275,13 @@ function collectLocalStatements(ctx, ast) {
|
|
|
1998
2275
|
scriptIR.statement.local = ast;
|
|
1999
2276
|
}
|
|
2000
2277
|
|
|
2001
|
-
// src/core/transform/sfc/script/syntax-processor/
|
|
2278
|
+
// src/core/transform/sfc/script/syntax-processor/preprocess/resolve-define-async-component.ts
|
|
2002
2279
|
|
|
2003
|
-
function
|
|
2004
|
-
if (ctx.inputType !== "sfc") return {};
|
|
2280
|
+
function resolveDefineAsyncComponent(ctx) {
|
|
2005
2281
|
return {
|
|
2006
2282
|
CallExpression(path7) {
|
|
2007
2283
|
const { node } = path7;
|
|
2008
|
-
if (!isCalleeNamed(node, VUE_API_MAP.
|
|
2009
|
-
addTypeParam(ctx, path7);
|
|
2010
|
-
replaceValue(node);
|
|
2011
|
-
replaceCallName(node, REACT_API_MAP.useRef);
|
|
2012
|
-
recordImport(ctx, PACKAGE_NAME.react, REACT_API_MAP.useRef);
|
|
2013
|
-
},
|
|
2014
|
-
MemberExpression(path7) {
|
|
2015
|
-
const { node } = path7;
|
|
2016
|
-
if (node.computed || !t20.isIdentifier(node.property) || node.property.name !== "value") {
|
|
2017
|
-
return;
|
|
2018
|
-
}
|
|
2019
|
-
const rootPath = findRootVariablePath(path7);
|
|
2020
|
-
if (!_optionalChain([rootPath, 'optionalAccess', _57 => _57.node]) || !t20.isCallExpression(rootPath.node.init) || !isCalleeNamed(rootPath.node.init, REACT_API_MAP.useRef)) {
|
|
2021
|
-
return;
|
|
2022
|
-
}
|
|
2023
|
-
const rootId = findRootIdentifier(node);
|
|
2024
|
-
if (!t20.isIdentifier(node.object) || node.object.name !== _optionalChain([rootId, 'optionalAccess', _58 => _58.name])) {
|
|
2025
|
-
return;
|
|
2026
|
-
}
|
|
2027
|
-
node.property.name = "current";
|
|
2028
|
-
}
|
|
2029
|
-
};
|
|
2030
|
-
}
|
|
2031
|
-
function replaceValue(node) {
|
|
2032
|
-
const initVal = node.arguments[0];
|
|
2033
|
-
const newVal = t20.identifier("null");
|
|
2034
|
-
newVal.start = _optionalChain([initVal, 'optionalAccess', _59 => _59.start]);
|
|
2035
|
-
newVal.end = _optionalChain([initVal, 'optionalAccess', _60 => _60.end]);
|
|
2036
|
-
newVal.loc = _optionalChain([initVal, 'optionalAccess', _61 => _61.loc]);
|
|
2037
|
-
node.arguments[0] = newVal;
|
|
2038
|
-
}
|
|
2039
|
-
function addTypeParam(ctx, path7) {
|
|
2040
|
-
const { templateData, scriptData } = ctx;
|
|
2041
|
-
const { node, parent } = path7;
|
|
2042
|
-
if (!scriptData.lang.startsWith("ts") && !t20.isVariableDeclarator(parent)) {
|
|
2043
|
-
return;
|
|
2044
|
-
}
|
|
2045
|
-
const idName = parent.id.name;
|
|
2046
|
-
const bindingMeta = templateData.refBindings[idName];
|
|
2047
|
-
if (!node.typeParameters && bindingMeta) {
|
|
2048
|
-
node.typeParameters = t20.tsTypeParameterInstantiation([
|
|
2049
|
-
t20.tsTypeReference(t20.identifier(bindingMeta.htmlType))
|
|
2050
|
-
]);
|
|
2051
|
-
}
|
|
2052
|
-
}
|
|
2053
|
-
|
|
2054
|
-
// src/core/transform/sfc/script/syntax-processor/preprocess/resolve-async-component.ts
|
|
2055
|
-
|
|
2056
|
-
function resolveAsyncComponent(ctx) {
|
|
2057
|
-
return {
|
|
2058
|
-
CallExpression(path7) {
|
|
2059
|
-
const { node } = path7;
|
|
2060
|
-
if (!isCalleeNamed(node, "defineAsyncComponent")) {
|
|
2284
|
+
if (!isCalleeNamed(node, VUE_API_MAP.defineAsyncComponent)) {
|
|
2061
2285
|
return;
|
|
2062
2286
|
}
|
|
2063
2287
|
const [arg] = node.arguments;
|
|
@@ -2068,11 +2292,11 @@ function resolveAsyncComponent(ctx) {
|
|
|
2068
2292
|
};
|
|
2069
2293
|
}
|
|
2070
2294
|
function checkIsUnsupported(ctx, arg) {
|
|
2071
|
-
if (
|
|
2295
|
+
if (t20.isFunction(arg)) {
|
|
2072
2296
|
checkIsDynamicImport(ctx, arg);
|
|
2073
|
-
} else if (
|
|
2297
|
+
} else if (t20.isObjectExpression(arg)) {
|
|
2074
2298
|
const { value } = arg.properties.find(
|
|
2075
|
-
(p) =>
|
|
2299
|
+
(p) => t20.isObjectProperty(p) && t20.isIdentifier(p.key) && p.key.name === "loader"
|
|
2076
2300
|
);
|
|
2077
2301
|
checkIsDynamicImport(ctx, value);
|
|
2078
2302
|
if (arg.properties.length > 1) {
|
|
@@ -2083,31 +2307,31 @@ function checkIsUnsupported(ctx, arg) {
|
|
|
2083
2307
|
function checkIsDynamicImport(ctx, node) {
|
|
2084
2308
|
const { scriptData, filename } = ctx;
|
|
2085
2309
|
const warnIsNotImport = (target) => {
|
|
2086
|
-
if (!target || !
|
|
2310
|
+
if (!target || !t20.isImport(target)) {
|
|
2087
2311
|
logger.error(
|
|
2088
2312
|
`Only ES module dynamic imports are supported. You must use and return import('...').`,
|
|
2089
2313
|
{
|
|
2090
2314
|
source: scriptData.source,
|
|
2091
2315
|
file: filename,
|
|
2092
|
-
loc: _optionalChain([target, 'optionalAccess',
|
|
2316
|
+
loc: _optionalChain([target, 'optionalAccess', _59 => _59.loc]) || {}
|
|
2093
2317
|
}
|
|
2094
2318
|
);
|
|
2095
2319
|
}
|
|
2096
2320
|
};
|
|
2097
|
-
if (
|
|
2321
|
+
if (t20.isFunction(node)) {
|
|
2098
2322
|
checkIsDynamicImport(ctx, node.body);
|
|
2099
2323
|
return;
|
|
2100
2324
|
}
|
|
2101
|
-
if (
|
|
2325
|
+
if (t20.isBlockStatement(node)) {
|
|
2102
2326
|
const [returnSmt] = node.body;
|
|
2103
|
-
if (
|
|
2327
|
+
if (t20.isReturnStatement(returnSmt)) {
|
|
2104
2328
|
warnIsNotImport(returnSmt.argument);
|
|
2105
2329
|
}
|
|
2106
2330
|
return;
|
|
2107
2331
|
}
|
|
2108
|
-
if (
|
|
2332
|
+
if (t20.isCallExpression(node)) {
|
|
2109
2333
|
warnIsNotImport(node.callee);
|
|
2110
|
-
if (
|
|
2334
|
+
if (t20.isStringLiteral(node.arguments[0])) {
|
|
2111
2335
|
replaceVueSuffix(ctx, node.arguments[0]);
|
|
2112
2336
|
}
|
|
2113
2337
|
return;
|
|
@@ -2141,7 +2365,7 @@ function pushToGlobalScope(path7, ctx) {
|
|
|
2141
2365
|
declarationPath = declarationPath.parentPath;
|
|
2142
2366
|
}
|
|
2143
2367
|
let fullNode;
|
|
2144
|
-
if (_optionalChain([declarationPath, 'optionalAccess',
|
|
2368
|
+
if (_optionalChain([declarationPath, 'optionalAccess', _60 => _60.isVariableDeclaration, 'call', _61 => _61()])) {
|
|
2145
2369
|
fullNode = declarationPath.node;
|
|
2146
2370
|
declarationPath.remove();
|
|
2147
2371
|
} else if (path7.parentPath.isVariableDeclarator()) {
|
|
@@ -2155,61 +2379,64 @@ function pushToGlobalScope(path7, ctx) {
|
|
|
2155
2379
|
scriptIR.statement.global.push(fullNode);
|
|
2156
2380
|
}
|
|
2157
2381
|
|
|
2158
|
-
// src/core/transform/sfc/script/syntax-processor/preprocess/resolve-
|
|
2382
|
+
// src/core/transform/sfc/script/syntax-processor/preprocess/resolve-define-expose.ts
|
|
2159
2383
|
|
|
2160
|
-
|
|
2384
|
+
|
|
2385
|
+
// src/core/transform/sfc/script/shared/hook-creator.ts
|
|
2386
|
+
|
|
2387
|
+
function createUseCallback(body, deps) {
|
|
2388
|
+
return t21.callExpression(t21.identifier(REACT_API_MAP.useCallback), [
|
|
2389
|
+
body,
|
|
2390
|
+
_nullishCoalesce(deps, () => ( t21.arrayExpression([])))
|
|
2391
|
+
]);
|
|
2392
|
+
}
|
|
2393
|
+
function createUseMemo(body, deps) {
|
|
2394
|
+
return t21.callExpression(t21.identifier(REACT_API_MAP.useMemo), [
|
|
2395
|
+
t21.arrowFunctionExpression([], body),
|
|
2396
|
+
_nullishCoalesce(deps, () => ( t21.arrayExpression([])))
|
|
2397
|
+
]);
|
|
2398
|
+
}
|
|
2399
|
+
function createUseImperativeHandle(refId, init) {
|
|
2400
|
+
return t21.callExpression(t21.identifier(REACT_API_MAP.useImperativeHandle), [refId, init]);
|
|
2401
|
+
}
|
|
2402
|
+
|
|
2403
|
+
// src/core/transform/sfc/script/syntax-processor/preprocess/resolve-define-expose.ts
|
|
2404
|
+
function resolveDefineExpose(ctx) {
|
|
2405
|
+
if (ctx.inputType !== "sfc") return {};
|
|
2161
2406
|
return {
|
|
2162
2407
|
CallExpression(path7) {
|
|
2163
2408
|
const { node } = path7;
|
|
2164
|
-
const { filename,
|
|
2165
|
-
if (!
|
|
2166
|
-
|
|
2167
|
-
|
|
2168
|
-
|
|
2169
|
-
|
|
2170
|
-
if (meta) {
|
|
2171
|
-
result = meta.source === MACRO_API_NAMES.emits;
|
|
2172
|
-
}
|
|
2173
|
-
if (!result) {
|
|
2174
|
-
const binding = path7.scope.getBinding(name);
|
|
2175
|
-
if (binding) {
|
|
2176
|
-
const parent = binding.path.node;
|
|
2177
|
-
if (t22.isVariableDeclarator(parent) && t22.isCallExpression(parent.init) && t22.isIdentifier(parent.init.callee)) {
|
|
2178
|
-
result = parent.init.callee.name === MACRO_API_NAMES.emits;
|
|
2179
|
-
}
|
|
2180
|
-
}
|
|
2181
|
-
}
|
|
2182
|
-
return result;
|
|
2183
|
-
};
|
|
2184
|
-
if (!checkIfFromDefineEmits()) return;
|
|
2185
|
-
const [callee, ...args] = node.arguments;
|
|
2186
|
-
const eventName = t22.isStringLiteral(callee) ? `on${capitalize(camelCase(callee.value))}` : void 0;
|
|
2187
|
-
if (!eventName) {
|
|
2188
|
-
logger.warn(`Expected String type but got ${_optionalChain([callee, 'optionalAccess', _65 => _65.type])}, expression will be removed`, {
|
|
2189
|
-
file: filename,
|
|
2190
|
-
source: scriptData.source,
|
|
2191
|
-
loc: _optionalChain([callee, 'optionalAccess', _66 => _66.loc])
|
|
2192
|
-
});
|
|
2409
|
+
const { filename, scriptData } = ctx;
|
|
2410
|
+
if (!isCalleeNamed(node, MACRO_API_NAMES.expose)) {
|
|
2411
|
+
return;
|
|
2412
|
+
}
|
|
2413
|
+
const [expose] = node.arguments;
|
|
2414
|
+
if (!expose) {
|
|
2193
2415
|
path7.remove();
|
|
2194
2416
|
return;
|
|
2195
2417
|
}
|
|
2196
|
-
const
|
|
2197
|
-
|
|
2198
|
-
|
|
2199
|
-
|
|
2200
|
-
|
|
2201
|
-
|
|
2202
|
-
|
|
2203
|
-
|
|
2204
|
-
|
|
2205
|
-
|
|
2418
|
+
const adapter = ADAPTER_RULES.react[MACRO_API_NAMES.expose];
|
|
2419
|
+
recordImport(ctx, adapter.package, REACT_API_MAP.forwardRef);
|
|
2420
|
+
recordImport(ctx, adapter.package, adapter.target);
|
|
2421
|
+
if (!t22.isObjectExpression(expose) && !t22.isFunction(expose)) {
|
|
2422
|
+
logger.warn("Non-deterministic object literal may cause unknown risks.", {
|
|
2423
|
+
file: filename,
|
|
2424
|
+
loc: expose.loc,
|
|
2425
|
+
source: scriptData.source
|
|
2426
|
+
});
|
|
2427
|
+
}
|
|
2428
|
+
const init = !t22.isFunction(expose) ? t22.arrowFunctionExpression([], expose) : expose;
|
|
2429
|
+
const { forwardRef } = scriptData;
|
|
2430
|
+
const newNode = createUseImperativeHandle(t22.identifier(forwardRef.refField), init);
|
|
2431
|
+
forwardRef.enabled = true;
|
|
2432
|
+
path7.replaceWith(newNode);
|
|
2206
2433
|
}
|
|
2207
2434
|
};
|
|
2208
2435
|
}
|
|
2209
2436
|
|
|
2210
|
-
// src/core/transform/sfc/script/syntax-processor/preprocess/resolve-options.ts
|
|
2437
|
+
// src/core/transform/sfc/script/syntax-processor/preprocess/resolve-define-options.ts
|
|
2211
2438
|
|
|
2212
|
-
function
|
|
2439
|
+
function resolveDefineOptions(ctx) {
|
|
2213
2440
|
return {
|
|
2214
2441
|
CallExpression(path7) {
|
|
2215
2442
|
const { node } = path7;
|
|
@@ -2222,7 +2449,7 @@ function resolveOptions(ctx) {
|
|
|
2222
2449
|
logger.warn("defineOptions was found, but no options were provided.", {
|
|
2223
2450
|
source: scriptData.source,
|
|
2224
2451
|
file: filename,
|
|
2225
|
-
loc: _optionalChain([node, 'optionalAccess',
|
|
2452
|
+
loc: _optionalChain([node, 'optionalAccess', _62 => _62.loc])
|
|
2226
2453
|
});
|
|
2227
2454
|
path7.remove();
|
|
2228
2455
|
return;
|
|
@@ -2231,7 +2458,7 @@ function resolveOptions(ctx) {
|
|
|
2231
2458
|
logger.warn("Argument for defineOptions must be an object expression.", {
|
|
2232
2459
|
source: scriptData.source,
|
|
2233
2460
|
file: filename,
|
|
2234
|
-
loc: _optionalChain([options, 'optionalAccess',
|
|
2461
|
+
loc: _optionalChain([options, 'optionalAccess', _63 => _63.loc])
|
|
2235
2462
|
});
|
|
2236
2463
|
} else {
|
|
2237
2464
|
for (const prop of options.properties) {
|
|
@@ -2245,21 +2472,81 @@ function resolveOptions(ctx) {
|
|
|
2245
2472
|
}
|
|
2246
2473
|
};
|
|
2247
2474
|
}
|
|
2248
|
-
function extractName(prop, ctx) {
|
|
2249
|
-
if (ctx.compName) return;
|
|
2250
|
-
const { filename, scriptData } = ctx;
|
|
2251
|
-
if (!prop.computed && prop.key.name === "name") {
|
|
2252
|
-
if (t23.isStringLiteral(prop.value)) {
|
|
2253
|
-
ctx.compName = prop.value.value;
|
|
2254
|
-
return;
|
|
2255
|
-
}
|
|
2256
|
-
logger.error(`name must be a string type, but got ${prop.value.type}`, {
|
|
2257
|
-
source: scriptData.source,
|
|
2258
|
-
file: filename,
|
|
2259
|
-
loc: _optionalChain([prop, 'access',
|
|
2260
|
-
});
|
|
2261
|
-
}
|
|
2262
|
-
}
|
|
2475
|
+
function extractName(prop, ctx) {
|
|
2476
|
+
if (ctx.compName) return;
|
|
2477
|
+
const { filename, scriptData } = ctx;
|
|
2478
|
+
if (!prop.computed && prop.key.name === "name") {
|
|
2479
|
+
if (t23.isStringLiteral(prop.value)) {
|
|
2480
|
+
ctx.compName = prop.value.value;
|
|
2481
|
+
return;
|
|
2482
|
+
}
|
|
2483
|
+
logger.error(`name must be a string type, but got ${prop.value.type}`, {
|
|
2484
|
+
source: scriptData.source,
|
|
2485
|
+
file: filename,
|
|
2486
|
+
loc: _optionalChain([prop, 'access', _64 => _64.key, 'optionalAccess', _65 => _65.loc])
|
|
2487
|
+
});
|
|
2488
|
+
}
|
|
2489
|
+
}
|
|
2490
|
+
|
|
2491
|
+
// src/core/transform/sfc/script/syntax-processor/preprocess/resolve-emit-calls.ts
|
|
2492
|
+
|
|
2493
|
+
function resolveEmitCalls(ctx) {
|
|
2494
|
+
const formatEmitEventName = (raw) => {
|
|
2495
|
+
if (raw.startsWith("update:")) {
|
|
2496
|
+
const modelKey = raw.slice("update:".length);
|
|
2497
|
+
return `onUpdate${capitalize(camelCase(modelKey))}`;
|
|
2498
|
+
}
|
|
2499
|
+
const normalized = raw.includes(":") ? raw.replace(/:/g, "-") : raw;
|
|
2500
|
+
return `on${capitalize(camelCase(normalized))}`;
|
|
2501
|
+
};
|
|
2502
|
+
return {
|
|
2503
|
+
CallExpression(path7) {
|
|
2504
|
+
const { node } = path7;
|
|
2505
|
+
const { filename, templateData, scriptData } = ctx;
|
|
2506
|
+
if (!t24.isIdentifier(node.callee)) return;
|
|
2507
|
+
const { name } = node.callee;
|
|
2508
|
+
const checkIfFromDefineEmits = () => {
|
|
2509
|
+
let result = false;
|
|
2510
|
+
const meta = templateData.reactiveBindings[name];
|
|
2511
|
+
if (meta) {
|
|
2512
|
+
result = meta.source === MACRO_API_NAMES.emits;
|
|
2513
|
+
}
|
|
2514
|
+
if (!result) {
|
|
2515
|
+
const binding = path7.scope.getBinding(name);
|
|
2516
|
+
if (binding) {
|
|
2517
|
+
const parent = binding.path.node;
|
|
2518
|
+
if (t24.isVariableDeclarator(parent) && t24.isCallExpression(parent.init) && t24.isIdentifier(parent.init.callee)) {
|
|
2519
|
+
result = parent.init.callee.name === MACRO_API_NAMES.emits;
|
|
2520
|
+
}
|
|
2521
|
+
}
|
|
2522
|
+
}
|
|
2523
|
+
return result;
|
|
2524
|
+
};
|
|
2525
|
+
if (!checkIfFromDefineEmits()) return;
|
|
2526
|
+
const [callee, ...args] = node.arguments;
|
|
2527
|
+
const eventName = t24.isStringLiteral(callee) ? formatEmitEventName(callee.value) : void 0;
|
|
2528
|
+
if (!eventName) {
|
|
2529
|
+
logger.warn(`Expected String type but got ${_optionalChain([callee, 'optionalAccess', _66 => _66.type])}, expression will be removed`, {
|
|
2530
|
+
file: filename,
|
|
2531
|
+
source: scriptData.source,
|
|
2532
|
+
loc: _optionalChain([callee, 'optionalAccess', _67 => _67.loc])
|
|
2533
|
+
});
|
|
2534
|
+
path7.remove();
|
|
2535
|
+
return;
|
|
2536
|
+
}
|
|
2537
|
+
const propCall = t24.callExpression(
|
|
2538
|
+
t24.optionalMemberExpression(
|
|
2539
|
+
t24.identifier(ctx.propField),
|
|
2540
|
+
t24.identifier(eventName),
|
|
2541
|
+
false,
|
|
2542
|
+
true
|
|
2543
|
+
),
|
|
2544
|
+
args
|
|
2545
|
+
);
|
|
2546
|
+
path7.replaceWith(propCall);
|
|
2547
|
+
}
|
|
2548
|
+
};
|
|
2549
|
+
}
|
|
2263
2550
|
|
|
2264
2551
|
// src/core/transform/sfc/script/syntax-processor/preprocess/resolve-props-interface/index.ts
|
|
2265
2552
|
|
|
@@ -2271,21 +2558,21 @@ function extractName(prop, ctx) {
|
|
|
2271
2558
|
|
|
2272
2559
|
function cloneCallableParams(params) {
|
|
2273
2560
|
const cloneCallableParam = (param, index) => {
|
|
2274
|
-
if (
|
|
2561
|
+
if (t25.isRestElement(param)) {
|
|
2275
2562
|
const arg = param.argument;
|
|
2276
|
-
const name =
|
|
2277
|
-
const rest =
|
|
2278
|
-
rest.typeAnnotation = param.typeAnnotation || (
|
|
2563
|
+
const name = t25.isIdentifier(arg) ? arg.name : `args${index}`;
|
|
2564
|
+
const rest = t25.restElement(t25.identifier(name));
|
|
2565
|
+
rest.typeAnnotation = param.typeAnnotation || (t25.isIdentifier(arg) ? arg.typeAnnotation : null) || t25.tsTypeAnnotation(t25.tsArrayType(t25.tsAnyKeyword()));
|
|
2279
2566
|
return rest;
|
|
2280
2567
|
}
|
|
2281
|
-
if (
|
|
2282
|
-
const id =
|
|
2568
|
+
if (t25.isIdentifier(param)) {
|
|
2569
|
+
const id = t25.identifier(param.name || `arg${index}`);
|
|
2283
2570
|
id.optional = param.optional;
|
|
2284
|
-
id.typeAnnotation = param.typeAnnotation ||
|
|
2571
|
+
id.typeAnnotation = param.typeAnnotation || t25.tsTypeAnnotation(t25.tsAnyKeyword());
|
|
2285
2572
|
return id;
|
|
2286
2573
|
}
|
|
2287
|
-
const fallback =
|
|
2288
|
-
fallback.typeAnnotation =
|
|
2574
|
+
const fallback = t25.identifier(`arg${index}`);
|
|
2575
|
+
fallback.typeAnnotation = t25.tsTypeAnnotation(t25.tsAnyKeyword());
|
|
2289
2576
|
return fallback;
|
|
2290
2577
|
};
|
|
2291
2578
|
return params.map(cloneCallableParam);
|
|
@@ -2295,18 +2582,18 @@ function cloneCallableParams(params) {
|
|
|
2295
2582
|
function resolveEmitsTopLevelTypes(ctx) {
|
|
2296
2583
|
return {
|
|
2297
2584
|
"TSInterfaceDeclaration|TSTypeAliasDeclaration"(path7) {
|
|
2298
|
-
if (!
|
|
2585
|
+
if (!t26.isProgram(path7.parent)) return;
|
|
2299
2586
|
const { node } = path7;
|
|
2300
|
-
if (
|
|
2301
|
-
const typeLiteral =
|
|
2587
|
+
if (t26.isTSInterfaceDeclaration(node)) {
|
|
2588
|
+
const typeLiteral = t26.tsTypeLiteral(node.body.body);
|
|
2302
2589
|
if (!hasEmitsSignatureInType(typeLiteral)) return;
|
|
2303
2590
|
const resolved = resolveTopLevelEmitType(typeLiteral);
|
|
2304
|
-
if (resolved &&
|
|
2591
|
+
if (resolved && t26.isTSTypeLiteral(resolved)) {
|
|
2305
2592
|
node.body.body = resolved.members;
|
|
2306
2593
|
}
|
|
2307
2594
|
return;
|
|
2308
2595
|
}
|
|
2309
|
-
if (
|
|
2596
|
+
if (t26.isTSTypeAliasDeclaration(node)) {
|
|
2310
2597
|
if (!hasEmitsSignatureInType(node.typeAnnotation)) return;
|
|
2311
2598
|
const resolved = resolveTopLevelEmitType(node.typeAnnotation);
|
|
2312
2599
|
if (resolved) {
|
|
@@ -2317,55 +2604,55 @@ function resolveEmitsTopLevelTypes(ctx) {
|
|
|
2317
2604
|
};
|
|
2318
2605
|
}
|
|
2319
2606
|
function resolveTopLevelEmitType(tsType) {
|
|
2320
|
-
if (
|
|
2607
|
+
if (t26.isTSParenthesizedType(tsType)) {
|
|
2321
2608
|
return resolveTopLevelEmitType(tsType.typeAnnotation);
|
|
2322
2609
|
}
|
|
2323
|
-
if (
|
|
2610
|
+
if (t26.isTSTypeReference(tsType)) {
|
|
2324
2611
|
if (!tsType.typeParameters || !tsType.typeParameters.params.length) {
|
|
2325
2612
|
return tsType;
|
|
2326
2613
|
}
|
|
2327
2614
|
const params = tsType.typeParameters.params.map((param) => resolveTopLevelEmitType(param)).filter(Boolean);
|
|
2328
|
-
return
|
|
2615
|
+
return t26.tsTypeReference(
|
|
2329
2616
|
tsType.typeName,
|
|
2330
|
-
|
|
2617
|
+
t26.tsTypeParameterInstantiation(params.length ? params : tsType.typeParameters.params)
|
|
2331
2618
|
);
|
|
2332
2619
|
}
|
|
2333
|
-
if (
|
|
2620
|
+
if (t26.isTSIntersectionType(tsType)) {
|
|
2334
2621
|
const types = tsType.types.map(resolveTopLevelEmitType).filter(Boolean);
|
|
2335
2622
|
if (!types.length) return null;
|
|
2336
2623
|
if (types.length === 1) return types[0];
|
|
2337
|
-
return
|
|
2624
|
+
return t26.tsIntersectionType(types);
|
|
2338
2625
|
}
|
|
2339
|
-
if (
|
|
2626
|
+
if (t26.isTSUnionType(tsType)) {
|
|
2340
2627
|
const types = tsType.types.map(resolveTopLevelEmitType).filter(Boolean);
|
|
2341
2628
|
if (!types.length) return null;
|
|
2342
2629
|
if (types.length === 1) return types[0];
|
|
2343
|
-
return
|
|
2630
|
+
return t26.tsUnionType(types);
|
|
2344
2631
|
}
|
|
2345
|
-
if (
|
|
2632
|
+
if (t26.isTSTypeLiteral(tsType)) {
|
|
2346
2633
|
const members = [];
|
|
2347
2634
|
for (const member of tsType.members) {
|
|
2348
|
-
if (
|
|
2635
|
+
if (t26.isTSCallSignatureDeclaration(member)) {
|
|
2349
2636
|
members.push(...resolveEmitPropsFromCallSignature(member));
|
|
2350
2637
|
continue;
|
|
2351
2638
|
}
|
|
2352
2639
|
members.push(member);
|
|
2353
2640
|
}
|
|
2354
2641
|
if (!members.length) return null;
|
|
2355
|
-
return
|
|
2642
|
+
return t26.tsTypeLiteral(members);
|
|
2356
2643
|
}
|
|
2357
|
-
if (
|
|
2644
|
+
if (t26.isTSFunctionType(tsType)) {
|
|
2358
2645
|
const props = resolveEmitPropsFromCallable(tsType.parameters, tsType.typeAnnotation);
|
|
2359
2646
|
if (!props.length) return null;
|
|
2360
|
-
return
|
|
2647
|
+
return t26.tsTypeLiteral(props);
|
|
2361
2648
|
}
|
|
2362
2649
|
return tsType;
|
|
2363
2650
|
}
|
|
2364
2651
|
function resolveDefineEmitsIface(path7, ctx) {
|
|
2365
2652
|
const { node } = path7;
|
|
2366
2653
|
const [runtimeArg] = node.arguments;
|
|
2367
|
-
const tsParams = _optionalChain([node, 'access',
|
|
2368
|
-
if (_optionalChain([tsParams, 'optionalAccess',
|
|
2654
|
+
const tsParams = _optionalChain([node, 'access', _68 => _68.typeParameters, 'optionalAccess', _69 => _69.params]);
|
|
2655
|
+
if (_optionalChain([tsParams, 'optionalAccess', _70 => _70.length])) {
|
|
2369
2656
|
processExplicitType(ctx, tsParams);
|
|
2370
2657
|
return;
|
|
2371
2658
|
}
|
|
@@ -2378,41 +2665,41 @@ function processInferredTypes(ctx, runtimeArg) {
|
|
|
2378
2665
|
propsTSIface: { emitTypes }
|
|
2379
2666
|
} = ctx.scriptData;
|
|
2380
2667
|
const members = [];
|
|
2381
|
-
if (
|
|
2668
|
+
if (t26.isArrayExpression(runtimeArg)) {
|
|
2382
2669
|
for (const element of runtimeArg.elements) {
|
|
2383
|
-
if (!element || !
|
|
2670
|
+
if (!element || !t26.isStringLiteral(element)) continue;
|
|
2384
2671
|
const handlerName = resolveEmitHandlerName(element.value);
|
|
2385
2672
|
const key = buildKey(handlerName);
|
|
2386
|
-
const fnType =
|
|
2673
|
+
const fnType = t26.tsFunctionType(
|
|
2387
2674
|
null,
|
|
2388
2675
|
[createRestAnyParam("args")],
|
|
2389
|
-
|
|
2676
|
+
t26.tsTypeAnnotation(t26.tsAnyKeyword())
|
|
2390
2677
|
);
|
|
2391
|
-
const prop =
|
|
2678
|
+
const prop = t26.tsPropertySignature(key, t26.tsTypeAnnotation(fnType));
|
|
2392
2679
|
prop.optional = true;
|
|
2393
2680
|
members.push(prop);
|
|
2394
2681
|
}
|
|
2395
2682
|
if (members.length) {
|
|
2396
|
-
emitTypes.push(
|
|
2683
|
+
emitTypes.push(t26.tsTypeLiteral(members));
|
|
2397
2684
|
}
|
|
2398
2685
|
return;
|
|
2399
2686
|
}
|
|
2400
|
-
if (
|
|
2687
|
+
if (t26.isObjectExpression(runtimeArg)) {
|
|
2401
2688
|
for (const prop of runtimeArg.properties) {
|
|
2402
|
-
if (!
|
|
2403
|
-
if (
|
|
2689
|
+
if (!t26.isObjectProperty(prop)) continue;
|
|
2690
|
+
if (t26.isSpreadElement(prop)) continue;
|
|
2404
2691
|
const rawName = resolvePropName(prop.key);
|
|
2405
2692
|
if (!rawName) continue;
|
|
2406
2693
|
const handlerName = resolveEmitHandlerName(rawName);
|
|
2407
2694
|
const key = buildKey(handlerName);
|
|
2408
|
-
const params =
|
|
2409
|
-
const fnType =
|
|
2410
|
-
const propSig =
|
|
2695
|
+
const params = t26.isArrayExpression(prop.value) ? resolveRuntimeTupleParams(prop.value) : [createRestAnyParam("args")];
|
|
2696
|
+
const fnType = t26.tsFunctionType(null, params, t26.tsTypeAnnotation(t26.tsAnyKeyword()));
|
|
2697
|
+
const propSig = t26.tsPropertySignature(key, t26.tsTypeAnnotation(fnType));
|
|
2411
2698
|
propSig.optional = true;
|
|
2412
2699
|
members.push(propSig);
|
|
2413
2700
|
}
|
|
2414
2701
|
if (members.length) {
|
|
2415
|
-
emitTypes.push(
|
|
2702
|
+
emitTypes.push(t26.tsTypeLiteral(members));
|
|
2416
2703
|
}
|
|
2417
2704
|
}
|
|
2418
2705
|
}
|
|
@@ -2433,129 +2720,129 @@ function resolveEmitHandlerName(rawName) {
|
|
|
2433
2720
|
return `on${name}`;
|
|
2434
2721
|
}
|
|
2435
2722
|
function resolvePropName(key) {
|
|
2436
|
-
if (
|
|
2437
|
-
if (
|
|
2438
|
-
if (
|
|
2723
|
+
if (t26.isIdentifier(key)) return key.name;
|
|
2724
|
+
if (t26.isStringLiteral(key)) return key.value;
|
|
2725
|
+
if (t26.isNumericLiteral(key)) return String(key.value);
|
|
2439
2726
|
return null;
|
|
2440
2727
|
}
|
|
2441
2728
|
function buildKey(name) {
|
|
2442
|
-
return
|
|
2729
|
+
return t26.isValidIdentifier(name) ? t26.identifier(name) : t26.stringLiteral(name);
|
|
2443
2730
|
}
|
|
2444
2731
|
function createRestAnyParam(name) {
|
|
2445
|
-
const id =
|
|
2446
|
-
const rest =
|
|
2447
|
-
rest.typeAnnotation =
|
|
2732
|
+
const id = t26.identifier(name);
|
|
2733
|
+
const rest = t26.restElement(id);
|
|
2734
|
+
rest.typeAnnotation = t26.tsTypeAnnotation(t26.tsArrayType(t26.tsAnyKeyword()));
|
|
2448
2735
|
return rest;
|
|
2449
2736
|
}
|
|
2450
2737
|
function resolveRuntimeTupleParams(value) {
|
|
2451
2738
|
const params = [];
|
|
2452
2739
|
value.elements.forEach((element, index) => {
|
|
2453
2740
|
if (!element) return;
|
|
2454
|
-
if (
|
|
2741
|
+
if (t26.isSpreadElement(element)) {
|
|
2455
2742
|
params.push(createRestAnyParam(`args${index}`));
|
|
2456
2743
|
return;
|
|
2457
2744
|
}
|
|
2458
|
-
if (
|
|
2459
|
-
const id =
|
|
2460
|
-
id.typeAnnotation = element.typeAnnotation ||
|
|
2745
|
+
if (t26.isIdentifier(element)) {
|
|
2746
|
+
const id = t26.identifier(element.name);
|
|
2747
|
+
id.typeAnnotation = element.typeAnnotation || t26.tsTypeAnnotation(t26.tsAnyKeyword());
|
|
2461
2748
|
params.push(id);
|
|
2462
2749
|
return;
|
|
2463
2750
|
}
|
|
2464
|
-
if (
|
|
2465
|
-
const id =
|
|
2466
|
-
id.typeAnnotation =
|
|
2751
|
+
if (t26.isTSAsExpression(element)) {
|
|
2752
|
+
const id = t26.identifier(`arg${index}`);
|
|
2753
|
+
id.typeAnnotation = t26.tsTypeAnnotation(element.typeAnnotation);
|
|
2467
2754
|
params.push(id);
|
|
2468
2755
|
return;
|
|
2469
2756
|
}
|
|
2470
|
-
const fallback =
|
|
2471
|
-
fallback.typeAnnotation =
|
|
2757
|
+
const fallback = t26.identifier(`arg${index}`);
|
|
2758
|
+
fallback.typeAnnotation = t26.tsTypeAnnotation(t26.tsAnyKeyword());
|
|
2472
2759
|
params.push(fallback);
|
|
2473
2760
|
});
|
|
2474
2761
|
return params;
|
|
2475
2762
|
}
|
|
2476
2763
|
function resolveExplicitEmitType(tsType) {
|
|
2477
|
-
if (
|
|
2764
|
+
if (t26.isTSParenthesizedType(tsType)) {
|
|
2478
2765
|
return resolveExplicitEmitType(tsType.typeAnnotation);
|
|
2479
2766
|
}
|
|
2480
|
-
if (
|
|
2767
|
+
if (t26.isTSTypeReference(tsType)) {
|
|
2481
2768
|
if (!tsType.typeParameters || !tsType.typeParameters.params.length) {
|
|
2482
2769
|
return tsType;
|
|
2483
2770
|
}
|
|
2484
2771
|
const params = tsType.typeParameters.params.map((param) => resolveExplicitEmitType(param)).filter(Boolean);
|
|
2485
|
-
return
|
|
2772
|
+
return t26.tsTypeReference(
|
|
2486
2773
|
tsType.typeName,
|
|
2487
|
-
|
|
2774
|
+
t26.tsTypeParameterInstantiation(params.length ? params : tsType.typeParameters.params)
|
|
2488
2775
|
);
|
|
2489
2776
|
}
|
|
2490
|
-
if (
|
|
2777
|
+
if (t26.isTSIntersectionType(tsType)) {
|
|
2491
2778
|
const types = tsType.types.map(resolveExplicitEmitType).filter(Boolean);
|
|
2492
2779
|
if (!types.length) return null;
|
|
2493
2780
|
if (types.length === 1) return types[0];
|
|
2494
|
-
return
|
|
2781
|
+
return t26.tsIntersectionType(types);
|
|
2495
2782
|
}
|
|
2496
|
-
if (
|
|
2783
|
+
if (t26.isTSUnionType(tsType)) {
|
|
2497
2784
|
const types = tsType.types.map(resolveExplicitEmitType).filter(Boolean);
|
|
2498
2785
|
if (!types.length) return null;
|
|
2499
2786
|
if (types.length === 1) return types[0];
|
|
2500
|
-
return
|
|
2787
|
+
return t26.tsUnionType(types);
|
|
2501
2788
|
}
|
|
2502
|
-
if (
|
|
2789
|
+
if (t26.isTSTypeLiteral(tsType)) {
|
|
2503
2790
|
const members = [];
|
|
2504
2791
|
for (const member of tsType.members) {
|
|
2505
|
-
if (
|
|
2792
|
+
if (t26.isTSPropertySignature(member)) {
|
|
2506
2793
|
const prop = resolveEmitPropFromPropertySignature(member);
|
|
2507
2794
|
if (prop) members.push(prop);
|
|
2508
2795
|
continue;
|
|
2509
2796
|
}
|
|
2510
|
-
if (
|
|
2797
|
+
if (t26.isTSCallSignatureDeclaration(member)) {
|
|
2511
2798
|
members.push(...resolveEmitPropsFromCallSignature(member));
|
|
2512
2799
|
continue;
|
|
2513
2800
|
}
|
|
2514
2801
|
}
|
|
2515
2802
|
if (!members.length) return null;
|
|
2516
|
-
return
|
|
2803
|
+
return t26.tsTypeLiteral(members);
|
|
2517
2804
|
}
|
|
2518
|
-
if (
|
|
2805
|
+
if (t26.isTSFunctionType(tsType)) {
|
|
2519
2806
|
const props = resolveEmitPropsFromCallable(tsType.parameters, tsType.typeAnnotation);
|
|
2520
2807
|
if (!props.length) return null;
|
|
2521
|
-
return
|
|
2808
|
+
return t26.tsTypeLiteral(props);
|
|
2522
2809
|
}
|
|
2523
2810
|
return tsType;
|
|
2524
2811
|
}
|
|
2525
2812
|
function hasEmitsSignatureInType(tsType) {
|
|
2526
|
-
if (
|
|
2813
|
+
if (t26.isTSParenthesizedType(tsType)) {
|
|
2527
2814
|
return hasEmitsSignatureInType(tsType.typeAnnotation);
|
|
2528
2815
|
}
|
|
2529
|
-
if (
|
|
2816
|
+
if (t26.isTSTypeReference(tsType)) {
|
|
2530
2817
|
if (!tsType.typeParameters || !tsType.typeParameters.params.length) {
|
|
2531
2818
|
return false;
|
|
2532
2819
|
}
|
|
2533
2820
|
return tsType.typeParameters.params.some(hasEmitsSignatureInType);
|
|
2534
2821
|
}
|
|
2535
|
-
if (
|
|
2822
|
+
if (t26.isTSIntersectionType(tsType) || t26.isTSUnionType(tsType)) {
|
|
2536
2823
|
return tsType.types.some(hasEmitsSignatureInType);
|
|
2537
2824
|
}
|
|
2538
|
-
if (
|
|
2825
|
+
if (t26.isTSTypeLiteral(tsType)) {
|
|
2539
2826
|
return tsType.members.some(hasEmitsSignatureInMember);
|
|
2540
2827
|
}
|
|
2541
|
-
if (
|
|
2828
|
+
if (t26.isTSFunctionType(tsType)) {
|
|
2542
2829
|
return isEmitsCallable(tsType.parameters);
|
|
2543
2830
|
}
|
|
2544
2831
|
return false;
|
|
2545
2832
|
}
|
|
2546
2833
|
function hasEmitsSignatureInMember(member) {
|
|
2547
|
-
if (
|
|
2834
|
+
if (t26.isTSCallSignatureDeclaration(member)) {
|
|
2548
2835
|
return isEmitsCallable(member.parameters);
|
|
2549
2836
|
}
|
|
2550
2837
|
return false;
|
|
2551
2838
|
}
|
|
2552
2839
|
function isEmitsCallable(parameters) {
|
|
2553
2840
|
const [eventParam] = parameters;
|
|
2554
|
-
if (!eventParam || !
|
|
2841
|
+
if (!eventParam || !t26.isIdentifier(eventParam) || !eventParam.typeAnnotation) {
|
|
2555
2842
|
return false;
|
|
2556
2843
|
}
|
|
2557
2844
|
const { typeAnnotation } = eventParam;
|
|
2558
|
-
if (
|
|
2845
|
+
if (t26.isNoop(typeAnnotation)) return false;
|
|
2559
2846
|
return resolveEventNames(typeAnnotation.typeAnnotation).length > 0;
|
|
2560
2847
|
}
|
|
2561
2848
|
function resolveEmitPropFromPropertySignature(member) {
|
|
@@ -2563,21 +2850,21 @@ function resolveEmitPropFromPropertySignature(member) {
|
|
|
2563
2850
|
if (!rawName) return null;
|
|
2564
2851
|
const handlerName = resolveEmitHandlerName(rawName);
|
|
2565
2852
|
const key = buildKey(handlerName);
|
|
2566
|
-
const typeAnnotation = _optionalChain([member, 'access',
|
|
2853
|
+
const typeAnnotation = _optionalChain([member, 'access', _71 => _71.typeAnnotation, 'optionalAccess', _72 => _72.typeAnnotation]);
|
|
2567
2854
|
let params = [];
|
|
2568
|
-
let returnType =
|
|
2569
|
-
if (typeAnnotation &&
|
|
2855
|
+
let returnType = t26.tsAnyKeyword();
|
|
2856
|
+
if (typeAnnotation && t26.isTSFunctionType(typeAnnotation)) {
|
|
2570
2857
|
params = cloneCallableParams(typeAnnotation.parameters);
|
|
2571
|
-
returnType = _nullishCoalesce(_optionalChain([typeAnnotation, 'access',
|
|
2572
|
-
} else if (typeAnnotation &&
|
|
2858
|
+
returnType = _nullishCoalesce(_optionalChain([typeAnnotation, 'access', _73 => _73.typeAnnotation, 'optionalAccess', _74 => _74.typeAnnotation]), () => ( returnType));
|
|
2859
|
+
} else if (typeAnnotation && t26.isTSTupleType(typeAnnotation)) {
|
|
2573
2860
|
params = resolveTupleTypeParams(typeAnnotation);
|
|
2574
2861
|
} else if (typeAnnotation) {
|
|
2575
|
-
const id =
|
|
2576
|
-
id.typeAnnotation =
|
|
2862
|
+
const id = t26.identifier("value");
|
|
2863
|
+
id.typeAnnotation = t26.tsTypeAnnotation(typeAnnotation);
|
|
2577
2864
|
params = [id];
|
|
2578
2865
|
}
|
|
2579
|
-
const fnType =
|
|
2580
|
-
const prop =
|
|
2866
|
+
const fnType = t26.tsFunctionType(null, params, t26.tsTypeAnnotation(returnType));
|
|
2867
|
+
const prop = t26.tsPropertySignature(key, t26.tsTypeAnnotation(fnType));
|
|
2581
2868
|
prop.optional = !!member.optional;
|
|
2582
2869
|
return prop;
|
|
2583
2870
|
}
|
|
@@ -2586,32 +2873,32 @@ function resolveEmitPropsFromCallSignature(member) {
|
|
|
2586
2873
|
}
|
|
2587
2874
|
function resolveEmitPropsFromCallable(parameters, typeAnnotation) {
|
|
2588
2875
|
const [eventParam, ...restParams] = parameters;
|
|
2589
|
-
if (!eventParam || !
|
|
2876
|
+
if (!eventParam || !t26.isIdentifier(eventParam) || !eventParam.typeAnnotation) {
|
|
2590
2877
|
return [];
|
|
2591
2878
|
}
|
|
2592
2879
|
const { typeAnnotation: paramTypeAnnotation } = eventParam;
|
|
2593
|
-
if (
|
|
2880
|
+
if (t26.isNoop(paramTypeAnnotation)) return [];
|
|
2594
2881
|
const eventNames = resolveEventNames(paramTypeAnnotation.typeAnnotation);
|
|
2595
2882
|
if (!eventNames.length) return [];
|
|
2596
|
-
const returnType = _nullishCoalesce(_optionalChain([typeAnnotation, 'optionalAccess',
|
|
2883
|
+
const returnType = _nullishCoalesce(_optionalChain([typeAnnotation, 'optionalAccess', _75 => _75.typeAnnotation]), () => ( t26.tsAnyKeyword()));
|
|
2597
2884
|
return eventNames.map((eventName) => {
|
|
2598
2885
|
const handlerName = resolveEmitHandlerName(eventName);
|
|
2599
2886
|
const key = buildKey(handlerName);
|
|
2600
2887
|
const params = cloneCallableParams(restParams);
|
|
2601
|
-
const fnType =
|
|
2602
|
-
const prop =
|
|
2888
|
+
const fnType = t26.tsFunctionType(null, params, t26.tsTypeAnnotation(returnType));
|
|
2889
|
+
const prop = t26.tsPropertySignature(key, t26.tsTypeAnnotation(fnType));
|
|
2603
2890
|
prop.optional = true;
|
|
2604
2891
|
return prop;
|
|
2605
2892
|
});
|
|
2606
2893
|
}
|
|
2607
2894
|
function resolveEventNames(type) {
|
|
2608
|
-
if (
|
|
2895
|
+
if (t26.isTSLiteralType(type) && t26.isStringLiteral(type.literal)) {
|
|
2609
2896
|
return [type.literal.value];
|
|
2610
2897
|
}
|
|
2611
|
-
if (
|
|
2898
|
+
if (t26.isTSUnionType(type)) {
|
|
2612
2899
|
return type.types.flatMap(resolveEventNames);
|
|
2613
2900
|
}
|
|
2614
|
-
if (
|
|
2901
|
+
if (t26.isTSParenthesizedType(type)) {
|
|
2615
2902
|
return resolveEventNames(type.typeAnnotation);
|
|
2616
2903
|
}
|
|
2617
2904
|
return [];
|
|
@@ -2624,39 +2911,39 @@ function resolveTupleTypeParams(tuple) {
|
|
|
2624
2911
|
return params;
|
|
2625
2912
|
}
|
|
2626
2913
|
function resolveTupleElementParam(element, index) {
|
|
2627
|
-
const isNamedTuple = typeof
|
|
2914
|
+
const isNamedTuple = typeof t26.isTSNamedTupleMember === "function" && t26.isTSNamedTupleMember(element);
|
|
2628
2915
|
if (isNamedTuple) {
|
|
2629
2916
|
const tupleMember = element;
|
|
2630
|
-
const name = _optionalChain([tupleMember, 'access',
|
|
2917
|
+
const name = _optionalChain([tupleMember, 'access', _76 => _76.label, 'optionalAccess', _77 => _77.name]) || `arg${index}`;
|
|
2631
2918
|
let innerType = tupleMember.elementType;
|
|
2632
2919
|
let optional = tupleMember.optional;
|
|
2633
|
-
if (
|
|
2920
|
+
if (t26.isTSOptionalType(innerType)) {
|
|
2634
2921
|
optional = true;
|
|
2635
2922
|
innerType = innerType.typeAnnotation;
|
|
2636
2923
|
}
|
|
2637
|
-
if (
|
|
2638
|
-
const rest =
|
|
2639
|
-
rest.typeAnnotation =
|
|
2924
|
+
if (t26.isTSRestType(innerType)) {
|
|
2925
|
+
const rest = t26.restElement(t26.identifier(name));
|
|
2926
|
+
rest.typeAnnotation = t26.tsTypeAnnotation(innerType.typeAnnotation);
|
|
2640
2927
|
return rest;
|
|
2641
2928
|
}
|
|
2642
|
-
const id2 =
|
|
2929
|
+
const id2 = t26.identifier(name);
|
|
2643
2930
|
id2.optional = optional;
|
|
2644
|
-
id2.typeAnnotation =
|
|
2931
|
+
id2.typeAnnotation = t26.tsTypeAnnotation(innerType);
|
|
2645
2932
|
return id2;
|
|
2646
2933
|
}
|
|
2647
|
-
if (
|
|
2648
|
-
const rest =
|
|
2649
|
-
rest.typeAnnotation =
|
|
2934
|
+
if (t26.isTSRestType(element)) {
|
|
2935
|
+
const rest = t26.restElement(t26.identifier(`args${index}`));
|
|
2936
|
+
rest.typeAnnotation = t26.tsTypeAnnotation(element.typeAnnotation);
|
|
2650
2937
|
return rest;
|
|
2651
2938
|
}
|
|
2652
|
-
if (
|
|
2653
|
-
const id2 =
|
|
2939
|
+
if (t26.isTSOptionalType(element)) {
|
|
2940
|
+
const id2 = t26.identifier(`arg${index}`);
|
|
2654
2941
|
id2.optional = true;
|
|
2655
|
-
id2.typeAnnotation =
|
|
2942
|
+
id2.typeAnnotation = t26.tsTypeAnnotation(element.typeAnnotation);
|
|
2656
2943
|
return id2;
|
|
2657
2944
|
}
|
|
2658
|
-
const id =
|
|
2659
|
-
id.typeAnnotation =
|
|
2945
|
+
const id = t26.identifier(`arg${index}`);
|
|
2946
|
+
id.typeAnnotation = t26.tsTypeAnnotation(element);
|
|
2660
2947
|
return id;
|
|
2661
2948
|
}
|
|
2662
2949
|
|
|
@@ -2665,8 +2952,8 @@ function resolveTupleElementParam(element, index) {
|
|
|
2665
2952
|
function resolveDefinePropsIface(path7, ctx) {
|
|
2666
2953
|
const { node } = path7;
|
|
2667
2954
|
const [runtimeArg] = node.arguments;
|
|
2668
|
-
const tsParams = _optionalChain([node, 'access',
|
|
2669
|
-
if (_optionalChain([tsParams, 'optionalAccess',
|
|
2955
|
+
const tsParams = _optionalChain([node, 'access', _78 => _78.typeParameters, 'optionalAccess', _79 => _79.params]);
|
|
2956
|
+
if (_optionalChain([tsParams, 'optionalAccess', _80 => _80.length])) {
|
|
2670
2957
|
const { propsTSIface } = ctx.scriptData;
|
|
2671
2958
|
propsTSIface.propsTypes = tsParams;
|
|
2672
2959
|
return;
|
|
@@ -2681,38 +2968,38 @@ function processInferredTypes2(ctx, runtimeArg) {
|
|
|
2681
2968
|
} = scriptData;
|
|
2682
2969
|
if (!runtimeArg) return;
|
|
2683
2970
|
const members = [];
|
|
2684
|
-
if (
|
|
2971
|
+
if (t27.isArrayExpression(runtimeArg)) {
|
|
2685
2972
|
for (const element of runtimeArg.elements) {
|
|
2686
|
-
if (!element || !
|
|
2687
|
-
const key =
|
|
2688
|
-
const prop =
|
|
2973
|
+
if (!element || !t27.isStringLiteral(element)) continue;
|
|
2974
|
+
const key = t27.isValidIdentifier(element.value) ? t27.identifier(element.value) : t27.stringLiteral(element.value);
|
|
2975
|
+
const prop = t27.tsPropertySignature(key, t27.tsTypeAnnotation(t27.tsAnyKeyword()));
|
|
2689
2976
|
prop.optional = true;
|
|
2690
2977
|
members.push(prop);
|
|
2691
2978
|
}
|
|
2692
2979
|
if (members.length) {
|
|
2693
|
-
propsTypes.push(
|
|
2980
|
+
propsTypes.push(t27.tsTypeLiteral(members));
|
|
2694
2981
|
}
|
|
2695
2982
|
return;
|
|
2696
2983
|
}
|
|
2697
|
-
if (
|
|
2984
|
+
if (t27.isObjectExpression(runtimeArg)) {
|
|
2698
2985
|
for (const prop of runtimeArg.properties) {
|
|
2699
|
-
if (!
|
|
2700
|
-
if (
|
|
2986
|
+
if (!t27.isObjectProperty(prop)) continue;
|
|
2987
|
+
if (t27.isSpreadElement(prop)) continue;
|
|
2701
2988
|
const key = prop.key;
|
|
2702
2989
|
let propName = null;
|
|
2703
|
-
if (
|
|
2704
|
-
if (
|
|
2705
|
-
if (
|
|
2990
|
+
if (t27.isIdentifier(key)) propName = key.name;
|
|
2991
|
+
if (t27.isStringLiteral(key)) propName = key.value;
|
|
2992
|
+
if (t27.isNumericLiteral(key)) propName = String(key.value);
|
|
2706
2993
|
if (!propName) continue;
|
|
2707
2994
|
const { type, required } = resolveRuntimePropMeta(prop.value);
|
|
2708
|
-
const tsType = _nullishCoalesce(type, () => (
|
|
2709
|
-
const tsKey =
|
|
2710
|
-
const tsProp =
|
|
2995
|
+
const tsType = _nullishCoalesce(type, () => ( t27.tsAnyKeyword()));
|
|
2996
|
+
const tsKey = t27.isValidIdentifier(propName) ? t27.identifier(propName) : t27.stringLiteral(propName);
|
|
2997
|
+
const tsProp = t27.tsPropertySignature(tsKey, t27.tsTypeAnnotation(tsType));
|
|
2711
2998
|
tsProp.optional = !required;
|
|
2712
2999
|
members.push(tsProp);
|
|
2713
3000
|
}
|
|
2714
3001
|
if (members.length) {
|
|
2715
|
-
propsTypes.push(
|
|
3002
|
+
propsTypes.push(t27.tsTypeLiteral(members));
|
|
2716
3003
|
}
|
|
2717
3004
|
return;
|
|
2718
3005
|
}
|
|
@@ -2721,47 +3008,47 @@ function processInferredTypes2(ctx, runtimeArg) {
|
|
|
2721
3008
|
{
|
|
2722
3009
|
source,
|
|
2723
3010
|
file: filename,
|
|
2724
|
-
loc: _optionalChain([runtimeArg, 'optionalAccess',
|
|
3011
|
+
loc: _optionalChain([runtimeArg, 'optionalAccess', _81 => _81.loc])
|
|
2725
3012
|
}
|
|
2726
3013
|
);
|
|
2727
3014
|
}
|
|
2728
3015
|
function resolveRuntimePropMeta(value) {
|
|
2729
|
-
if (
|
|
3016
|
+
if (t27.isIdentifier(value)) {
|
|
2730
3017
|
return {
|
|
2731
3018
|
type: mapRuntimeTypeToTSType(value),
|
|
2732
3019
|
required: false
|
|
2733
3020
|
};
|
|
2734
3021
|
}
|
|
2735
|
-
if (
|
|
3022
|
+
if (t27.isArrayExpression(value)) {
|
|
2736
3023
|
return {
|
|
2737
3024
|
type: resolveRuntimeUnionType(value),
|
|
2738
3025
|
required: false
|
|
2739
3026
|
};
|
|
2740
3027
|
}
|
|
2741
|
-
if (!
|
|
3028
|
+
if (!t27.isObjectExpression(value)) {
|
|
2742
3029
|
return { required: false };
|
|
2743
3030
|
}
|
|
2744
3031
|
let type;
|
|
2745
3032
|
let required = false;
|
|
2746
3033
|
for (const prop of value.properties) {
|
|
2747
|
-
if (!
|
|
2748
|
-
if (
|
|
3034
|
+
if (!t27.isObjectProperty(prop)) continue;
|
|
3035
|
+
if (t27.isSpreadElement(prop)) continue;
|
|
2749
3036
|
const key = prop.key;
|
|
2750
|
-
const propName =
|
|
3037
|
+
const propName = t27.isIdentifier(key) ? key.name : t27.isStringLiteral(key) ? key.value : null;
|
|
2751
3038
|
if (!propName) continue;
|
|
2752
3039
|
if (propName === "type") {
|
|
2753
3040
|
const valueNode = prop.value;
|
|
2754
|
-
if (
|
|
3041
|
+
if (t27.isArrayExpression(valueNode)) {
|
|
2755
3042
|
type = resolveRuntimeUnionType(valueNode);
|
|
2756
3043
|
continue;
|
|
2757
3044
|
}
|
|
2758
|
-
if (
|
|
3045
|
+
if (t27.isIdentifier(valueNode)) {
|
|
2759
3046
|
type = mapRuntimeTypeToTSType(valueNode);
|
|
2760
3047
|
continue;
|
|
2761
3048
|
}
|
|
2762
3049
|
}
|
|
2763
3050
|
if (propName === "required") {
|
|
2764
|
-
if (
|
|
3051
|
+
if (t27.isBooleanLiteral(prop.value)) {
|
|
2765
3052
|
required = prop.value.value;
|
|
2766
3053
|
}
|
|
2767
3054
|
}
|
|
@@ -2771,34 +3058,34 @@ function resolveRuntimePropMeta(value) {
|
|
|
2771
3058
|
function resolveRuntimeUnionType(value) {
|
|
2772
3059
|
const types = [];
|
|
2773
3060
|
for (const element of value.elements) {
|
|
2774
|
-
if (!element || !
|
|
3061
|
+
if (!element || !t27.isIdentifier(element)) continue;
|
|
2775
3062
|
const resolved = mapRuntimeTypeToTSType(element);
|
|
2776
3063
|
if (resolved) types.push(resolved);
|
|
2777
3064
|
}
|
|
2778
|
-
if (!types.length) return
|
|
3065
|
+
if (!types.length) return t27.tsAnyKeyword();
|
|
2779
3066
|
if (types.length === 1) return types[0];
|
|
2780
|
-
return
|
|
3067
|
+
return t27.tsUnionType(types);
|
|
2781
3068
|
}
|
|
2782
3069
|
function mapRuntimeTypeToTSType(value) {
|
|
2783
3070
|
switch (value.name) {
|
|
2784
3071
|
case "String":
|
|
2785
|
-
return
|
|
3072
|
+
return t27.tsStringKeyword();
|
|
2786
3073
|
case "Number":
|
|
2787
|
-
return
|
|
3074
|
+
return t27.tsNumberKeyword();
|
|
2788
3075
|
case "Boolean":
|
|
2789
|
-
return
|
|
3076
|
+
return t27.tsBooleanKeyword();
|
|
2790
3077
|
case "Object":
|
|
2791
|
-
return
|
|
3078
|
+
return t27.tsTypeLiteral([]);
|
|
2792
3079
|
case "Array":
|
|
2793
|
-
return
|
|
3080
|
+
return t27.tsArrayType(t27.tsAnyKeyword());
|
|
2794
3081
|
case "Function":
|
|
2795
|
-
return
|
|
3082
|
+
return t27.tsFunctionType(null, [], t27.tsTypeAnnotation(t27.tsAnyKeyword()));
|
|
2796
3083
|
case "Symbol":
|
|
2797
|
-
return
|
|
3084
|
+
return t27.tsSymbolKeyword();
|
|
2798
3085
|
case "BigInt":
|
|
2799
|
-
return
|
|
3086
|
+
return t27.tsBigIntKeyword();
|
|
2800
3087
|
default:
|
|
2801
|
-
return
|
|
3088
|
+
return t27.tsAnyKeyword();
|
|
2802
3089
|
}
|
|
2803
3090
|
}
|
|
2804
3091
|
|
|
@@ -2810,19 +3097,19 @@ var SLOT_FN_PARAM_NAME = "props";
|
|
|
2810
3097
|
function resolveSlotsTopLevelTypes(ctx) {
|
|
2811
3098
|
return {
|
|
2812
3099
|
"TSInterfaceDeclaration|TSTypeAliasDeclaration"(path7) {
|
|
2813
|
-
if (!
|
|
3100
|
+
if (!t28.isProgram(path7.parent)) return;
|
|
2814
3101
|
const { node } = path7;
|
|
2815
|
-
if (
|
|
2816
|
-
const typeLiteral =
|
|
3102
|
+
if (t28.isTSInterfaceDeclaration(node)) {
|
|
3103
|
+
const typeLiteral = t28.tsTypeLiteral(node.body.body);
|
|
2817
3104
|
if (!hasSlotsSignatureInType(typeLiteral)) return;
|
|
2818
3105
|
const resolved = resolveSlotType(typeLiteral);
|
|
2819
|
-
if (resolved &&
|
|
3106
|
+
if (resolved && t28.isTSTypeLiteral(resolved)) {
|
|
2820
3107
|
node.body.body = resolved.members;
|
|
2821
3108
|
recordReactNode(ctx);
|
|
2822
3109
|
}
|
|
2823
3110
|
return;
|
|
2824
3111
|
}
|
|
2825
|
-
if (
|
|
3112
|
+
if (t28.isTSTypeAliasDeclaration(node)) {
|
|
2826
3113
|
if (!hasSlotsSignatureInType(node.typeAnnotation)) return;
|
|
2827
3114
|
const resolved = resolveSlotType(node.typeAnnotation);
|
|
2828
3115
|
if (resolved) {
|
|
@@ -2835,8 +3122,8 @@ function resolveSlotsTopLevelTypes(ctx) {
|
|
|
2835
3122
|
}
|
|
2836
3123
|
function resolveDefineSlotsIface(path7, ctx) {
|
|
2837
3124
|
const { node } = path7;
|
|
2838
|
-
const tsParams = _optionalChain([node, 'access',
|
|
2839
|
-
if (!_optionalChain([tsParams, 'optionalAccess',
|
|
3125
|
+
const tsParams = _optionalChain([node, 'access', _82 => _82.typeParameters, 'optionalAccess', _83 => _83.params]);
|
|
3126
|
+
if (!_optionalChain([tsParams, 'optionalAccess', _84 => _84.length])) return;
|
|
2840
3127
|
const {
|
|
2841
3128
|
propsTSIface: { slotTypes }
|
|
2842
3129
|
} = ctx.scriptData;
|
|
@@ -2867,7 +3154,7 @@ function resolveTemplateSlotIface(ctx) {
|
|
|
2867
3154
|
}
|
|
2868
3155
|
if (tsMembers.length) {
|
|
2869
3156
|
recordReactNode(ctx);
|
|
2870
|
-
slotTypes.push(
|
|
3157
|
+
slotTypes.push(t28.tsTypeLiteral(tsMembers));
|
|
2871
3158
|
}
|
|
2872
3159
|
}
|
|
2873
3160
|
function recordReactNode(ctx) {
|
|
@@ -2877,32 +3164,32 @@ function recordReactNode(ctx) {
|
|
|
2877
3164
|
recordImport(ctx, PACKAGE_NAME.react, REACT_API_MAP.ReactNode);
|
|
2878
3165
|
}
|
|
2879
3166
|
function resolveSlotType(tsType) {
|
|
2880
|
-
if (
|
|
3167
|
+
if (t28.isTSParenthesizedType(tsType)) {
|
|
2881
3168
|
return resolveSlotType(tsType.typeAnnotation);
|
|
2882
3169
|
}
|
|
2883
|
-
if (
|
|
3170
|
+
if (t28.isTSTypeReference(tsType)) {
|
|
2884
3171
|
if (!tsType.typeParameters || !tsType.typeParameters.params.length) {
|
|
2885
3172
|
return tsType;
|
|
2886
3173
|
}
|
|
2887
3174
|
const params = tsType.typeParameters.params.map((param) => resolveSlotType(param)).filter(Boolean);
|
|
2888
|
-
return
|
|
3175
|
+
return t28.tsTypeReference(
|
|
2889
3176
|
tsType.typeName,
|
|
2890
|
-
|
|
3177
|
+
t28.tsTypeParameterInstantiation(params.length ? params : tsType.typeParameters.params)
|
|
2891
3178
|
);
|
|
2892
3179
|
}
|
|
2893
|
-
if (
|
|
3180
|
+
if (t28.isTSIntersectionType(tsType)) {
|
|
2894
3181
|
const types = tsType.types.map(resolveSlotType).filter(Boolean);
|
|
2895
3182
|
if (!types.length) return null;
|
|
2896
3183
|
if (types.length === 1) return types[0];
|
|
2897
|
-
return
|
|
3184
|
+
return t28.tsIntersectionType(types);
|
|
2898
3185
|
}
|
|
2899
|
-
if (
|
|
3186
|
+
if (t28.isTSUnionType(tsType)) {
|
|
2900
3187
|
const types = tsType.types.map(resolveSlotType).filter(Boolean);
|
|
2901
3188
|
if (!types.length) return null;
|
|
2902
3189
|
if (types.length === 1) return types[0];
|
|
2903
|
-
return
|
|
3190
|
+
return t28.tsUnionType(types);
|
|
2904
3191
|
}
|
|
2905
|
-
if (
|
|
3192
|
+
if (t28.isTSTypeLiteral(tsType)) {
|
|
2906
3193
|
const members = [];
|
|
2907
3194
|
for (const member of tsType.members) {
|
|
2908
3195
|
const resolved = resolveSlotPropFromMember(member);
|
|
@@ -2913,110 +3200,111 @@ function resolveSlotType(tsType) {
|
|
|
2913
3200
|
members.push(member);
|
|
2914
3201
|
}
|
|
2915
3202
|
if (!members.length) return null;
|
|
2916
|
-
return
|
|
3203
|
+
return t28.tsTypeLiteral(members);
|
|
2917
3204
|
}
|
|
2918
|
-
if (
|
|
3205
|
+
if (t28.isTSFunctionType(tsType)) {
|
|
2919
3206
|
const props = buildSlotPropSignature(
|
|
2920
3207
|
SLOT_DEFAULT_NAME,
|
|
2921
3208
|
cloneCallableParams(tsType.parameters),
|
|
2922
3209
|
false
|
|
2923
3210
|
);
|
|
2924
|
-
return
|
|
3211
|
+
return t28.tsTypeLiteral([props]);
|
|
2925
3212
|
}
|
|
2926
3213
|
return tsType;
|
|
2927
3214
|
}
|
|
2928
3215
|
function hasSlotsSignatureInType(tsType) {
|
|
2929
|
-
if (
|
|
3216
|
+
if (t28.isTSParenthesizedType(tsType)) {
|
|
2930
3217
|
return hasSlotsSignatureInType(tsType.typeAnnotation);
|
|
2931
3218
|
}
|
|
2932
|
-
if (
|
|
3219
|
+
if (t28.isTSTypeReference(tsType)) {
|
|
2933
3220
|
if (!tsType.typeParameters || !tsType.typeParameters.params.length) {
|
|
2934
3221
|
return false;
|
|
2935
3222
|
}
|
|
2936
3223
|
return tsType.typeParameters.params.some(hasSlotsSignatureInType);
|
|
2937
3224
|
}
|
|
2938
|
-
if (
|
|
3225
|
+
if (t28.isTSIntersectionType(tsType) || t28.isTSUnionType(tsType)) {
|
|
2939
3226
|
return tsType.types.some(hasSlotsSignatureInType);
|
|
2940
3227
|
}
|
|
2941
|
-
if (
|
|
3228
|
+
if (t28.isTSTypeLiteral(tsType)) {
|
|
2942
3229
|
return tsType.members.some(hasSlotsSignatureInMember);
|
|
2943
3230
|
}
|
|
2944
|
-
if (
|
|
3231
|
+
if (t28.isTSFunctionType(tsType)) {
|
|
2945
3232
|
return true;
|
|
2946
3233
|
}
|
|
2947
3234
|
return false;
|
|
2948
3235
|
}
|
|
2949
3236
|
function hasSlotsSignatureInMember(member) {
|
|
2950
|
-
if (
|
|
2951
|
-
if (
|
|
2952
|
-
if (
|
|
2953
|
-
const typeAnnotation = _optionalChain([member, 'access',
|
|
3237
|
+
if (t28.isTSMethodSignature(member)) return true;
|
|
3238
|
+
if (t28.isTSCallSignatureDeclaration(member)) return true;
|
|
3239
|
+
if (t28.isTSPropertySignature(member)) {
|
|
3240
|
+
const typeAnnotation = _optionalChain([member, 'access', _85 => _85.typeAnnotation, 'optionalAccess', _86 => _86.typeAnnotation]);
|
|
2954
3241
|
return !!(typeAnnotation && resolveCallableType(typeAnnotation));
|
|
2955
3242
|
}
|
|
2956
3243
|
return false;
|
|
2957
3244
|
}
|
|
2958
3245
|
function resolveSlotPropFromMember(member) {
|
|
2959
|
-
if (
|
|
3246
|
+
if (t28.isTSMethodSignature(member)) {
|
|
2960
3247
|
const rawName = resolvePropName2(member.key);
|
|
2961
3248
|
if (!rawName) return null;
|
|
2962
3249
|
const params = cloneCallableParams(member.parameters);
|
|
2963
3250
|
return buildSlotPropSignature(rawName, params, !!member.optional);
|
|
2964
3251
|
}
|
|
2965
|
-
if (
|
|
3252
|
+
if (t28.isTSPropertySignature(member)) {
|
|
2966
3253
|
const rawName = resolvePropName2(member.key);
|
|
2967
3254
|
if (!rawName) return null;
|
|
2968
|
-
const typeAnnotation = _optionalChain([member, 'access',
|
|
3255
|
+
const typeAnnotation = _optionalChain([member, 'access', _87 => _87.typeAnnotation, 'optionalAccess', _88 => _88.typeAnnotation]);
|
|
2969
3256
|
const callable = typeAnnotation ? resolveCallableType(typeAnnotation) : null;
|
|
2970
3257
|
if (!callable) return null;
|
|
2971
3258
|
const params = cloneCallableParams(callable.parameters);
|
|
2972
3259
|
return buildSlotPropSignature(rawName, params, !!member.optional);
|
|
2973
3260
|
}
|
|
2974
|
-
if (
|
|
3261
|
+
if (t28.isTSCallSignatureDeclaration(member)) {
|
|
2975
3262
|
const params = cloneCallableParams(member.parameters);
|
|
2976
3263
|
return buildSlotPropSignature(SLOT_DEFAULT_NAME, params, true);
|
|
2977
3264
|
}
|
|
2978
3265
|
return null;
|
|
2979
3266
|
}
|
|
2980
3267
|
function resolveCallableType(tsType) {
|
|
2981
|
-
if (
|
|
2982
|
-
if (
|
|
3268
|
+
if (t28.isTSFunctionType(tsType)) return tsType;
|
|
3269
|
+
if (t28.isTSParenthesizedType(tsType)) return resolveCallableType(tsType.typeAnnotation);
|
|
2983
3270
|
return null;
|
|
2984
3271
|
}
|
|
2985
3272
|
function buildSlotPropSignature(rawName, params, optional) {
|
|
2986
3273
|
const propName = rawName === SLOT_DEFAULT_NAME ? SLOT_CHILDREN_NAME : rawName;
|
|
2987
|
-
const key =
|
|
2988
|
-
const reactNodeType =
|
|
2989
|
-
|
|
3274
|
+
const key = t28.isValidIdentifier(propName) ? t28.identifier(propName) : t28.stringLiteral(propName);
|
|
3275
|
+
const reactNodeType = t28.tsTypeAnnotation(
|
|
3276
|
+
t28.tsTypeReference(t28.identifier(REACT_API_MAP.ReactNode))
|
|
2990
3277
|
);
|
|
2991
3278
|
let typeAnnotation;
|
|
2992
3279
|
if (rawName === SLOT_DEFAULT_NAME && params.length === 0 || params.length === 0) {
|
|
2993
3280
|
typeAnnotation = reactNodeType;
|
|
2994
3281
|
} else {
|
|
2995
|
-
const fnType =
|
|
2996
|
-
typeAnnotation =
|
|
3282
|
+
const fnType = t28.tsFunctionType(null, params, reactNodeType);
|
|
3283
|
+
typeAnnotation = t28.tsTypeAnnotation(fnType);
|
|
2997
3284
|
}
|
|
2998
|
-
const prop =
|
|
3285
|
+
const prop = t28.tsPropertySignature(key, typeAnnotation);
|
|
2999
3286
|
prop.optional = optional;
|
|
3000
3287
|
return prop;
|
|
3001
3288
|
}
|
|
3002
3289
|
function createSlotScopeParam(props, ctx) {
|
|
3003
|
-
const paramId =
|
|
3290
|
+
const paramId = t28.identifier(SLOT_FN_PARAM_NAME);
|
|
3004
3291
|
const propsSigns = [];
|
|
3005
3292
|
const { reactiveBindings } = ctx.templateData;
|
|
3006
3293
|
props.forEach(({ prop, tsType }) => {
|
|
3007
|
-
const foundBindingValue = _optionalChain([reactiveBindings, 'access',
|
|
3294
|
+
const foundBindingValue = _optionalChain([reactiveBindings, 'access', _89 => _89[prop], 'optionalAccess', _90 => _90.value]);
|
|
3008
3295
|
const foundBindingTypes = foundBindingValue ? expressionToTSType(foundBindingValue) : null;
|
|
3009
|
-
const typeAnnotation = foundBindingTypes ?
|
|
3010
|
-
const
|
|
3296
|
+
const typeAnnotation = foundBindingTypes ? t28.tsTypeAnnotation(foundBindingTypes) : tsType;
|
|
3297
|
+
const key = t28.isValidIdentifier(prop) ? t28.identifier(prop) : t28.stringLiteral(prop);
|
|
3298
|
+
const propSign = t28.tsPropertySignature(key, typeAnnotation);
|
|
3011
3299
|
propsSigns.push(propSign);
|
|
3012
3300
|
});
|
|
3013
|
-
paramId.typeAnnotation =
|
|
3301
|
+
paramId.typeAnnotation = t28.tsTypeAnnotation(t28.tsTypeLiteral(propsSigns));
|
|
3014
3302
|
return paramId;
|
|
3015
3303
|
}
|
|
3016
3304
|
function resolvePropName2(key) {
|
|
3017
|
-
if (
|
|
3018
|
-
if (
|
|
3019
|
-
if (
|
|
3305
|
+
if (t28.isIdentifier(key)) return key.name;
|
|
3306
|
+
if (t28.isStringLiteral(key)) return key.value;
|
|
3307
|
+
if (t28.isNumericLiteral(key)) return String(key.value);
|
|
3020
3308
|
return null;
|
|
3021
3309
|
}
|
|
3022
3310
|
|
|
@@ -3068,65 +3356,17 @@ function resolveCompIProps(ctx, ast) {
|
|
|
3068
3356
|
}
|
|
3069
3357
|
const n = ctx.compName || "Comp";
|
|
3070
3358
|
const ns = `I${camelCase(capitalize(n))}Props`;
|
|
3071
|
-
const typeNode =
|
|
3072
|
-
const typeAliasDecl =
|
|
3073
|
-
const exportDecl =
|
|
3359
|
+
const typeNode = t29.tsIntersectionType(tsTypes);
|
|
3360
|
+
const typeAliasDecl = t29.tsTypeAliasDeclaration(t29.identifier(ns), null, typeNode);
|
|
3361
|
+
const exportDecl = t29.exportNamedDeclaration(typeAliasDecl);
|
|
3074
3362
|
propsTSIface.name = ns;
|
|
3075
3363
|
const scriptIR = getScriptIR(ctx);
|
|
3076
3364
|
scriptIR.exports.push(exportDecl);
|
|
3077
3365
|
void ast;
|
|
3078
3366
|
}
|
|
3079
3367
|
|
|
3080
|
-
// src/core/transform/sfc/script/syntax-processor/process/
|
|
3368
|
+
// src/core/transform/sfc/script/syntax-processor/process/resolve-analysis-only-adapter.ts
|
|
3081
3369
|
|
|
3082
|
-
function lintRules(ctx, ast) {
|
|
3083
|
-
const inScriptFile = ctx.inputType !== "sfc";
|
|
3084
|
-
return {
|
|
3085
|
-
CallExpression(path7) {
|
|
3086
|
-
const { node, parentPath } = path7;
|
|
3087
|
-
if (!t29.isIdentifier(node.callee)) return;
|
|
3088
|
-
const { name: callName } = node.callee;
|
|
3089
|
-
const addLog = (t40) => {
|
|
3090
|
-
logger.error(t40, {
|
|
3091
|
-
file: ctx.filename,
|
|
3092
|
-
source: ctx.scriptData.source,
|
|
3093
|
-
loc: node.loc
|
|
3094
|
-
});
|
|
3095
|
-
};
|
|
3096
|
-
const lintMacros = () => {
|
|
3097
|
-
const macro = Object.values(MACRO_API_NAMES).find((v) => v === callName);
|
|
3098
|
-
if (!macro) return;
|
|
3099
|
-
if (inScriptFile) {
|
|
3100
|
-
addLog(
|
|
3101
|
-
`The ${macro} can only be used inside Vue SFC <script> blocks, not in separate script files.`
|
|
3102
|
-
);
|
|
3103
|
-
return;
|
|
3104
|
-
}
|
|
3105
|
-
if (!atComponentOrHookRoot(path7, ast.program)) {
|
|
3106
|
-
addLog(
|
|
3107
|
-
`The ${macro} must be defined at the top level of the component, not inside blocks or functions.`
|
|
3108
|
-
);
|
|
3109
|
-
return;
|
|
3110
|
-
}
|
|
3111
|
-
if (!parentPath.isVariableDeclarator()) {
|
|
3112
|
-
addLog(
|
|
3113
|
-
`The ${macro} macro must be assigned to a variable (e.g., const props = defineProps(...)).`
|
|
3114
|
-
);
|
|
3115
|
-
}
|
|
3116
|
-
};
|
|
3117
|
-
const lintHooks = () => {
|
|
3118
|
-
if (!callName.startsWith("use")) return;
|
|
3119
|
-
if (!atComponentOrHookRoot(path7, ast.program, inScriptFile)) {
|
|
3120
|
-
addLog(
|
|
3121
|
-
`The ${callName} hook must be called at the top level, not inside loops, conditions, or nested functions.`
|
|
3122
|
-
);
|
|
3123
|
-
}
|
|
3124
|
-
};
|
|
3125
|
-
lintMacros();
|
|
3126
|
-
lintHooks();
|
|
3127
|
-
}
|
|
3128
|
-
};
|
|
3129
|
-
}
|
|
3130
3370
|
|
|
3131
3371
|
// src/core/transform/sfc/script/shared/dependency-analyzer.ts
|
|
3132
3372
|
|
|
@@ -3252,7 +3492,7 @@ function analyzeDeps(node, ctx, parentPath) {
|
|
|
3252
3492
|
const declaratorPath = getVariableDeclaratorPath(bindingPath);
|
|
3253
3493
|
const isImportBinding = bindingPath.isImportSpecifier() || bindingPath.isImportDefaultSpecifier() || bindingPath.isImportNamespaceSpecifier();
|
|
3254
3494
|
const isReactiveVarBinding = !!declaratorPath && isReactiveBinding(declaratorPath.node);
|
|
3255
|
-
const nodeInit = _optionalChain([declaratorPath, 'optionalAccess',
|
|
3495
|
+
const nodeInit = _optionalChain([declaratorPath, 'optionalAccess', _91 => _91.node, 'access', _92 => _92.init]);
|
|
3256
3496
|
const isReactiveApiCallVarBinding = !!declaratorPath && t30.isCallExpression(nodeInit) && t30.isIdentifier(nodeInit.callee) && reactiveStateApis.has(nodeInit.callee.name);
|
|
3257
3497
|
const isHookCallVarBinding = !!declaratorPath && t30.isCallExpression(nodeInit) && isHookLikeCallee(nodeInit.callee);
|
|
3258
3498
|
const isFunctionBinding = bindingPath.isFunctionDeclaration() || !!declaratorPath && !!nodeInit && (t30.isArrowFunctionExpression(nodeInit) || t30.isFunctionExpression(nodeInit));
|
|
@@ -3365,7 +3605,7 @@ function isNestedMemberObject(path7) {
|
|
|
3365
3605
|
}
|
|
3366
3606
|
function isReactiveBinding(node) {
|
|
3367
3607
|
if (!node) return false;
|
|
3368
|
-
return !!_optionalChain([getScriptNodeMeta, 'call',
|
|
3608
|
+
return !!_optionalChain([getScriptNodeMeta, 'call', _93 => _93(node), 'optionalAccess', _94 => _94.is_reactive]);
|
|
3369
3609
|
}
|
|
3370
3610
|
function markAsAnalyzed(node, flag = true) {
|
|
3371
3611
|
const analyzed = getIsAnalyzed(node);
|
|
@@ -3373,22 +3613,51 @@ function markAsAnalyzed(node, flag = true) {
|
|
|
3373
3613
|
setScriptNodeMeta(node, { is_deps_analyzed: flag });
|
|
3374
3614
|
}
|
|
3375
3615
|
function getIsAnalyzed(node) {
|
|
3376
|
-
return _optionalChain([getScriptNodeMeta, 'call',
|
|
3616
|
+
return _optionalChain([getScriptNodeMeta, 'call', _95 => _95(node), 'optionalAccess', _96 => _96.is_deps_analyzed]);
|
|
3377
3617
|
}
|
|
3378
3618
|
|
|
3379
|
-
// src/core/transform/sfc/script/
|
|
3380
|
-
|
|
3381
|
-
|
|
3382
|
-
|
|
3383
|
-
|
|
3384
|
-
|
|
3385
|
-
|
|
3619
|
+
// src/core/transform/sfc/script/syntax-processor/process/resolve-analysis-only-adapter.ts
|
|
3620
|
+
function resolveAnalysisOnlyAdapter(ctx) {
|
|
3621
|
+
return {
|
|
3622
|
+
"CallExpression|Identifier"(path7) {
|
|
3623
|
+
const node = path7.node;
|
|
3624
|
+
const apiName = getApiName(node);
|
|
3625
|
+
const adapter = ADAPTER_RULES.runtime[apiName];
|
|
3626
|
+
if (!adapter || adapter.type !== "analyzed-deps") {
|
|
3627
|
+
return;
|
|
3628
|
+
}
|
|
3629
|
+
if (t31.isCallExpression(node)) {
|
|
3630
|
+
resolveCallNode(path7, adapter, ctx);
|
|
3631
|
+
} else {
|
|
3632
|
+
replaceIdName(node, adapter.target);
|
|
3633
|
+
}
|
|
3634
|
+
recordImport(ctx, adapter.package, adapter.target);
|
|
3635
|
+
}
|
|
3636
|
+
};
|
|
3386
3637
|
}
|
|
3387
|
-
function
|
|
3388
|
-
|
|
3389
|
-
|
|
3390
|
-
|
|
3391
|
-
|
|
3638
|
+
function getApiName(node) {
|
|
3639
|
+
const isCallNode = t31.isCallExpression(node);
|
|
3640
|
+
let apiName = "";
|
|
3641
|
+
if (t31.isIdentifier(node)) {
|
|
3642
|
+
apiName = node.name;
|
|
3643
|
+
} else if (isCallNode && t31.isIdentifier(node.callee)) {
|
|
3644
|
+
apiName = node.callee.name;
|
|
3645
|
+
}
|
|
3646
|
+
return apiName;
|
|
3647
|
+
}
|
|
3648
|
+
function resolveCallNode(path7, adapter, ctx) {
|
|
3649
|
+
const { node } = path7;
|
|
3650
|
+
const { arguments: args } = node;
|
|
3651
|
+
if (!args.length) return;
|
|
3652
|
+
const fn = args[0];
|
|
3653
|
+
if (!t31.isArrowFunctionExpression(fn) && !t31.isFunctionExpression(fn)) {
|
|
3654
|
+
return;
|
|
3655
|
+
}
|
|
3656
|
+
const fnPath = path7.get("arguments")[0];
|
|
3657
|
+
const deps = analyzeDeps(fn, ctx, fnPath);
|
|
3658
|
+
args.push(deps);
|
|
3659
|
+
replaceCallName(node, adapter.target);
|
|
3660
|
+
recordImport(ctx, adapter.package, adapter.target);
|
|
3392
3661
|
}
|
|
3393
3662
|
|
|
3394
3663
|
// src/core/transform/sfc/script/syntax-processor/process/resolve-arrow-deps.ts
|
|
@@ -3405,7 +3674,7 @@ function resolveArrowFnDeps(ctx, ast) {
|
|
|
3405
3674
|
const declaratorPath = getVariableDeclaratorPath(path7);
|
|
3406
3675
|
markAsAnalyzed(newNode.arguments[0]);
|
|
3407
3676
|
recordImport(ctx, PACKAGE_NAME.react, REACT_API_MAP.useCallback);
|
|
3408
|
-
setScriptNodeMeta(_optionalChain([declaratorPath, 'optionalAccess',
|
|
3677
|
+
setScriptNodeMeta(_optionalChain([declaratorPath, 'optionalAccess', _97 => _97.node]), { is_reactive: true, reactive_type: "indirect" });
|
|
3409
3678
|
path7.replaceWith(newNode);
|
|
3410
3679
|
}
|
|
3411
3680
|
};
|
|
@@ -3418,7 +3687,7 @@ function resolveUnanalyzedArrow(ctx) {
|
|
|
3418
3687
|
if (typeof analyzed === "undefined" || analyzed) return;
|
|
3419
3688
|
const newNode = createUseCallback(node);
|
|
3420
3689
|
const declaratorPath = getVariableDeclaratorPath(path7);
|
|
3421
|
-
if (_optionalChain([declaratorPath, 'optionalAccess',
|
|
3690
|
+
if (_optionalChain([declaratorPath, 'optionalAccess', _98 => _98.node])) {
|
|
3422
3691
|
setScriptNodeMeta(declaratorPath.node, { is_reactive: true, reactive_type: "indirect" });
|
|
3423
3692
|
}
|
|
3424
3693
|
markAsAnalyzed(newNode.arguments[0]);
|
|
@@ -3462,6 +3731,76 @@ function isSkip(path7) {
|
|
|
3462
3731
|
return (isCallback() || isMethod() || !isVariableDecl()) && !isReturnFunc();
|
|
3463
3732
|
}
|
|
3464
3733
|
|
|
3734
|
+
// src/core/transform/sfc/script/syntax-processor/process/resolve-element-ref.ts
|
|
3735
|
+
|
|
3736
|
+
function resolveElementRef(ctx) {
|
|
3737
|
+
return {
|
|
3738
|
+
CallExpression(path7) {
|
|
3739
|
+
const {
|
|
3740
|
+
inputType,
|
|
3741
|
+
templateData: { refBindings }
|
|
3742
|
+
} = ctx;
|
|
3743
|
+
if (inputType !== "sfc") return;
|
|
3744
|
+
const { node } = path7;
|
|
3745
|
+
const isUseTemplateRef = isCalleeNamed(node, VUE_API_MAP.useTemplateRef);
|
|
3746
|
+
const isCompRefBindings = Object.keys(refBindings.componentRefs).length > 0 && isCalleeNamed(node, VUE_API_MAP.ref);
|
|
3747
|
+
const shouldProcess = isUseTemplateRef || isCompRefBindings;
|
|
3748
|
+
if (!shouldProcess) {
|
|
3749
|
+
return;
|
|
3750
|
+
}
|
|
3751
|
+
if (isCompRefBindings) {
|
|
3752
|
+
const varDeclaratorPath = _optionalChain([getVariableDeclaratorPath, 'call', _99 => _99(path7), 'optionalAccess', _100 => _100.node]);
|
|
3753
|
+
if (!t32.isIdentifier(_optionalChain([varDeclaratorPath, 'optionalAccess', _101 => _101.id]))) {
|
|
3754
|
+
return;
|
|
3755
|
+
}
|
|
3756
|
+
const varName = varDeclaratorPath.id.name;
|
|
3757
|
+
const compRef = refBindings.componentRefs[varName];
|
|
3758
|
+
if (!compRef) return;
|
|
3759
|
+
}
|
|
3760
|
+
node.arguments[0] = t32.identifier("null");
|
|
3761
|
+
resolveTypeParameters(ctx, path7);
|
|
3762
|
+
replaceCallName(node, REACT_API_MAP.useRef);
|
|
3763
|
+
recordImport(ctx, PACKAGE_NAME.react, REACT_API_MAP.useRef);
|
|
3764
|
+
},
|
|
3765
|
+
MemberExpression(path7) {
|
|
3766
|
+
resolveRefValueToCurrent(path7);
|
|
3767
|
+
}
|
|
3768
|
+
};
|
|
3769
|
+
}
|
|
3770
|
+
function resolveTypeParameters(ctx, path7) {
|
|
3771
|
+
const {
|
|
3772
|
+
templateData: { refBindings },
|
|
3773
|
+
scriptData
|
|
3774
|
+
} = ctx;
|
|
3775
|
+
const { node } = path7;
|
|
3776
|
+
const varDeclaratorNode = _optionalChain([getVariableDeclaratorPath, 'call', _102 => _102(path7), 'optionalAccess', _103 => _103.node]);
|
|
3777
|
+
if (!scriptData.lang.startsWith("ts") || !varDeclaratorNode) {
|
|
3778
|
+
return;
|
|
3779
|
+
}
|
|
3780
|
+
const idName = varDeclaratorNode.id.name;
|
|
3781
|
+
const domBindingMeta = refBindings.domRefs[idName];
|
|
3782
|
+
const compBindingMeta = refBindings.componentRefs[idName];
|
|
3783
|
+
if (!node.typeParameters && (domBindingMeta || compBindingMeta)) {
|
|
3784
|
+
const type = compBindingMeta ? "any" : domBindingMeta.htmlType;
|
|
3785
|
+
node.typeParameters = t32.tsTypeParameterInstantiation([t32.tsTypeReference(t32.identifier(type))]);
|
|
3786
|
+
}
|
|
3787
|
+
}
|
|
3788
|
+
function resolveRefValueToCurrent(path7) {
|
|
3789
|
+
const { node } = path7;
|
|
3790
|
+
if (node.computed || !t32.isIdentifier(node.property) || node.property.name !== "value") {
|
|
3791
|
+
return;
|
|
3792
|
+
}
|
|
3793
|
+
const rootPath = findRootVariablePath(path7);
|
|
3794
|
+
if (!_optionalChain([rootPath, 'optionalAccess', _104 => _104.node]) || !t32.isCallExpression(rootPath.node.init) || !isCalleeNamed(rootPath.node.init, REACT_API_MAP.useRef)) {
|
|
3795
|
+
return;
|
|
3796
|
+
}
|
|
3797
|
+
const rootId = findRootIdentifier(node);
|
|
3798
|
+
if (!t32.isIdentifier(node.object) || node.object.name !== _optionalChain([rootId, 'optionalAccess', _105 => _105.name])) {
|
|
3799
|
+
return;
|
|
3800
|
+
}
|
|
3801
|
+
node.property.name = "current";
|
|
3802
|
+
}
|
|
3803
|
+
|
|
3465
3804
|
// src/core/transform/sfc/script/syntax-processor/process/resolve-expression-memo.ts
|
|
3466
3805
|
|
|
3467
3806
|
function resolveExprMemo(ctx, ast) {
|
|
@@ -3475,7 +3814,7 @@ function resolveExprMemo(ctx, ast) {
|
|
|
3475
3814
|
if (!atComponentOrHookRoot(path7, ast.program, isScriptFile)) {
|
|
3476
3815
|
return false;
|
|
3477
3816
|
}
|
|
3478
|
-
if (
|
|
3817
|
+
if (t33.isCallExpression(init) && t33.isIdentifier(init.callee) && init.callee.name.startsWith("use")) {
|
|
3479
3818
|
return false;
|
|
3480
3819
|
}
|
|
3481
3820
|
return true;
|
|
@@ -3492,20 +3831,76 @@ function resolveExprMemo(ctx, ast) {
|
|
|
3492
3831
|
};
|
|
3493
3832
|
}
|
|
3494
3833
|
|
|
3834
|
+
// src/core/transform/sfc/script/syntax-processor/process/resolve-lint-rules.ts
|
|
3835
|
+
|
|
3836
|
+
function resolveLintRules(ctx, ast) {
|
|
3837
|
+
const inScriptFile = ctx.inputType !== "sfc";
|
|
3838
|
+
return {
|
|
3839
|
+
CallExpression(path7) {
|
|
3840
|
+
const { node, parentPath } = path7;
|
|
3841
|
+
if (!t34.isIdentifier(node.callee)) return;
|
|
3842
|
+
const { name: callName } = node.callee;
|
|
3843
|
+
const addLog = (t41) => {
|
|
3844
|
+
logger.error(t41, {
|
|
3845
|
+
file: ctx.filename,
|
|
3846
|
+
source: ctx.scriptData.source,
|
|
3847
|
+
loc: node.loc
|
|
3848
|
+
});
|
|
3849
|
+
};
|
|
3850
|
+
const lintMacros = () => {
|
|
3851
|
+
const macro = Object.values(MACRO_API_NAMES).find((v) => v === callName);
|
|
3852
|
+
if (!macro) return;
|
|
3853
|
+
if (inScriptFile) {
|
|
3854
|
+
addLog(
|
|
3855
|
+
`The ${macro} can only be used inside Vue SFC <script> blocks, not in separate script files.`
|
|
3856
|
+
);
|
|
3857
|
+
return;
|
|
3858
|
+
}
|
|
3859
|
+
if (!atComponentOrHookRoot(path7, ast.program)) {
|
|
3860
|
+
addLog(
|
|
3861
|
+
`The ${macro} must be defined at the top level of the component, not inside blocks or functions.`
|
|
3862
|
+
);
|
|
3863
|
+
return;
|
|
3864
|
+
}
|
|
3865
|
+
if (!parentPath.isVariableDeclarator()) {
|
|
3866
|
+
if (macro === MACRO_API_NAMES.props || macro === MACRO_API_NAMES.emits) {
|
|
3867
|
+
addLog(
|
|
3868
|
+
`The ${macro} macro must be assigned to a variable (e.g., const props = defineProps(...)).`
|
|
3869
|
+
);
|
|
3870
|
+
}
|
|
3871
|
+
}
|
|
3872
|
+
};
|
|
3873
|
+
const lintHooks = () => {
|
|
3874
|
+
if (!callName.startsWith("use")) return;
|
|
3875
|
+
if (!atComponentOrHookRoot(path7, ast.program, inScriptFile)) {
|
|
3876
|
+
addLog(
|
|
3877
|
+
`The ${callName} hook must be called at the top level, not inside loops, conditions, or nested functions.`
|
|
3878
|
+
);
|
|
3879
|
+
}
|
|
3880
|
+
};
|
|
3881
|
+
lintMacros();
|
|
3882
|
+
lintHooks();
|
|
3883
|
+
}
|
|
3884
|
+
};
|
|
3885
|
+
}
|
|
3886
|
+
|
|
3495
3887
|
// src/core/transform/sfc/script/syntax-processor/process/resolve-provide.ts
|
|
3496
3888
|
|
|
3497
3889
|
|
|
3498
3890
|
function resolveProvide(ctx) {
|
|
3499
|
-
if (ctx.inputType
|
|
3891
|
+
if (ctx.inputType === "style") return {};
|
|
3500
3892
|
return {
|
|
3501
3893
|
CallExpression(path7) {
|
|
3502
3894
|
const { node } = path7;
|
|
3503
|
-
|
|
3895
|
+
const providerTarget = _optionalChain([ADAPTER_RULES, 'access', _106 => _106.runtime, 'access', _107 => _107[VUE_API_MAP.provide], 'optionalAccess', _108 => _108.target]);
|
|
3896
|
+
const isProvideCall = isCalleeNamed(node, VUE_API_MAP.provide) || providerTarget && isCalleeNamed(node, providerTarget);
|
|
3897
|
+
if (!isProvideCall) return;
|
|
3504
3898
|
const { provide } = ctx.scriptData;
|
|
3505
3899
|
const [key, value] = node.arguments;
|
|
3506
3900
|
const target = findOrCreateCtxProvider(provide);
|
|
3901
|
+
const adapter = ADAPTER_RULES.runtime[VUE_API_MAP.provide];
|
|
3507
3902
|
assignProviderValue(target, key, value);
|
|
3508
|
-
recordImport(ctx,
|
|
3903
|
+
recordImport(ctx, adapter.package, adapter.target);
|
|
3509
3904
|
path7.parentPath.remove();
|
|
3510
3905
|
}
|
|
3511
3906
|
};
|
|
@@ -3515,7 +3910,7 @@ function findOrCreateCtxProvider(root) {
|
|
|
3515
3910
|
return root;
|
|
3516
3911
|
}
|
|
3517
3912
|
let cur = root.provide;
|
|
3518
|
-
while (_optionalChain([cur, 'optionalAccess',
|
|
3913
|
+
while (_optionalChain([cur, 'optionalAccess', _109 => _109.isOccupied])) {
|
|
3519
3914
|
cur = _nullishCoalesce(cur.provide, () => ( {}));
|
|
3520
3915
|
}
|
|
3521
3916
|
return cur || (root.provide = {});
|
|
@@ -3523,18 +3918,18 @@ function findOrCreateCtxProvider(root) {
|
|
|
3523
3918
|
function assignProviderValue(target, key, value) {
|
|
3524
3919
|
const getRawExp = (exp) => {
|
|
3525
3920
|
if (!exp) return "''";
|
|
3526
|
-
if (
|
|
3527
|
-
return
|
|
3921
|
+
if (t35.isStringLiteral(exp)) {
|
|
3922
|
+
return JSON.stringify(exp.value);
|
|
3528
3923
|
}
|
|
3529
|
-
if (
|
|
3924
|
+
if (t35.isNumericLiteral(exp)) {
|
|
3530
3925
|
return exp.value.toString();
|
|
3531
3926
|
}
|
|
3532
|
-
if (
|
|
3927
|
+
if (t35.isIdentifier(exp)) {
|
|
3533
3928
|
return exp.name;
|
|
3534
3929
|
}
|
|
3535
3930
|
try {
|
|
3536
3931
|
return _generator.generate.call(void 0, exp).code;
|
|
3537
|
-
} catch (
|
|
3932
|
+
} catch (e5) {
|
|
3538
3933
|
return "null";
|
|
3539
3934
|
}
|
|
3540
3935
|
};
|
|
@@ -3544,165 +3939,71 @@ function assignProviderValue(target, key, value) {
|
|
|
3544
3939
|
target.provide = {};
|
|
3545
3940
|
}
|
|
3546
3941
|
|
|
3547
|
-
// src/core/transform/sfc/script/syntax-processor/process/resolve-rename-
|
|
3548
|
-
|
|
3549
|
-
function resolveRenameOnlyAdapter(ctx) {
|
|
3550
|
-
return {
|
|
3551
|
-
"Identifier|CallExpression"(path7) {
|
|
3552
|
-
resolveAdapterRules(PACKAGE_NAME.runtime, ADAPTER_HOOKS, path7, ctx);
|
|
3553
|
-
resolveAdapterRules(PACKAGE_NAME.router, ADAPTER_ROUTER_APIS, path7, ctx);
|
|
3554
|
-
}
|
|
3555
|
-
};
|
|
3556
|
-
}
|
|
3557
|
-
function resolveAdapterRules(pkgName, rules, path7, ctx) {
|
|
3558
|
-
const node = path7.node;
|
|
3559
|
-
const isCallExpr = t34.isCallExpression(node);
|
|
3560
|
-
let sourceName = "";
|
|
3561
|
-
if (t34.isIdentifier(node)) {
|
|
3562
|
-
sourceName = node.name;
|
|
3563
|
-
} else if (isCallExpr && t34.isIdentifier(node.callee)) {
|
|
3564
|
-
sourceName = node.callee.name;
|
|
3565
|
-
}
|
|
3566
|
-
const { pure, effectful } = rules.renameOnly;
|
|
3567
|
-
const pureApi = pure[sourceName];
|
|
3568
|
-
const effectfulApi = effectful[sourceName];
|
|
3569
|
-
const adapter = pureApi || effectfulApi;
|
|
3570
|
-
if (!adapter) return;
|
|
3571
|
-
if (effectfulApi) {
|
|
3572
|
-
const reactiveType = getReactiveType(sourceName);
|
|
3573
|
-
const declaratorPath = getVariableDeclaratorPath(path7);
|
|
3574
|
-
setScriptNodeMeta(_optionalChain([declaratorPath, 'optionalAccess', _103 => _103.node]), {
|
|
3575
|
-
is_reactive: true,
|
|
3576
|
-
reactive_type: reactiveType
|
|
3577
|
-
});
|
|
3578
|
-
}
|
|
3579
|
-
if (isCallExpr) {
|
|
3580
|
-
replaceCallName(node, adapter);
|
|
3581
|
-
} else {
|
|
3582
|
-
replaceIdName(node, adapter);
|
|
3583
|
-
}
|
|
3584
|
-
recordImport(ctx, pkgName, adapter);
|
|
3585
|
-
if (pkgName === PACKAGE_NAME.router && !ctx.route) {
|
|
3586
|
-
ctx.route = true;
|
|
3587
|
-
}
|
|
3588
|
-
}
|
|
3589
|
-
|
|
3590
|
-
// src/core/transform/sfc/script/syntax-processor/process/resolve-transform-adapter.ts
|
|
3942
|
+
// src/core/transform/sfc/script/syntax-processor/process/resolve-rename-adapter.ts
|
|
3591
3943
|
|
|
3592
|
-
function
|
|
3944
|
+
function resolveRenameAdapter(ctx) {
|
|
3593
3945
|
return {
|
|
3594
|
-
"Identifier
|
|
3595
|
-
|
|
3596
|
-
|
|
3946
|
+
"CallExpression|Identifier"(path7) {
|
|
3947
|
+
const node = path7.node;
|
|
3948
|
+
const isCallNode = t36.isCallExpression(node);
|
|
3949
|
+
let apiName = "";
|
|
3950
|
+
if (t36.isIdentifier(node)) {
|
|
3951
|
+
apiName = node.name;
|
|
3952
|
+
} else if (isCallNode && t36.isIdentifier(node.callee)) {
|
|
3953
|
+
apiName = node.callee.name;
|
|
3954
|
+
}
|
|
3955
|
+
const runtimeAdapter = ADAPTER_RULES.runtime[apiName];
|
|
3956
|
+
const routerAdapter = ADAPTER_RULES.router[apiName];
|
|
3957
|
+
const adapter = runtimeAdapter || routerAdapter;
|
|
3958
|
+
if (!adapter || adapter.type !== "rename") {
|
|
3959
|
+
return;
|
|
3960
|
+
}
|
|
3961
|
+
if (adapter.isTrackable) {
|
|
3962
|
+
const reactiveType = getReactiveType(apiName);
|
|
3963
|
+
const declaratorPath = getVariableDeclaratorPath(path7);
|
|
3964
|
+
setScriptNodeMeta(_optionalChain([declaratorPath, 'optionalAccess', _110 => _110.node]), {
|
|
3965
|
+
is_reactive: true,
|
|
3966
|
+
reactive_type: reactiveType
|
|
3967
|
+
});
|
|
3968
|
+
}
|
|
3969
|
+
if (isCallNode) {
|
|
3970
|
+
replaceCallName(node, adapter.target);
|
|
3971
|
+
} else {
|
|
3972
|
+
replaceIdName(node, adapter.target);
|
|
3973
|
+
}
|
|
3974
|
+
if (adapter.package === PACKAGE_NAME.router && !ctx.route) {
|
|
3975
|
+
ctx.route = true;
|
|
3976
|
+
}
|
|
3977
|
+
recordImport(ctx, adapter.package, adapter.target);
|
|
3597
3978
|
}
|
|
3598
3979
|
};
|
|
3599
3980
|
}
|
|
3600
|
-
function resolveTransformAdapterRules(pkgName, rules, path7, ctx) {
|
|
3601
|
-
const node = path7.node;
|
|
3602
|
-
const isCallExpr = t35.isCallExpression(node);
|
|
3603
|
-
let sourceName = "";
|
|
3604
|
-
if (t35.isIdentifier(node)) {
|
|
3605
|
-
sourceName = node.name;
|
|
3606
|
-
} else if (isCallExpr && t35.isIdentifier(node.callee)) {
|
|
3607
|
-
sourceName = node.callee.name;
|
|
3608
|
-
}
|
|
3609
|
-
const { pure, effectful } = rules.transform;
|
|
3610
|
-
const watchEffectAdapter = findNestedAdapter(sourceName, pure.watchEffect);
|
|
3611
|
-
if (watchEffectAdapter) {
|
|
3612
|
-
if (isCallExpr) {
|
|
3613
|
-
handleDependencyAnalysisAPI(
|
|
3614
|
-
path7,
|
|
3615
|
-
ctx,
|
|
3616
|
-
watchEffectAdapter,
|
|
3617
|
-
pkgName
|
|
3618
|
-
);
|
|
3619
|
-
} else {
|
|
3620
|
-
replaceIdName(node, watchEffectAdapter);
|
|
3621
|
-
recordImport(ctx, pkgName, watchEffectAdapter);
|
|
3622
|
-
}
|
|
3623
|
-
return;
|
|
3624
|
-
}
|
|
3625
|
-
const lifecycleAdapter = findNestedAdapter(sourceName, pure.lifecycle);
|
|
3626
|
-
if (lifecycleAdapter) {
|
|
3627
|
-
if (isCallExpr) {
|
|
3628
|
-
handleDependencyAnalysisAPI(
|
|
3629
|
-
path7,
|
|
3630
|
-
ctx,
|
|
3631
|
-
lifecycleAdapter,
|
|
3632
|
-
pkgName
|
|
3633
|
-
);
|
|
3634
|
-
} else {
|
|
3635
|
-
replaceIdName(node, lifecycleAdapter);
|
|
3636
|
-
recordImport(ctx, pkgName, lifecycleAdapter);
|
|
3637
|
-
}
|
|
3638
|
-
return;
|
|
3639
|
-
}
|
|
3640
|
-
const pureApi = pure[sourceName];
|
|
3641
|
-
if (pureApi) {
|
|
3642
|
-
if (isCallExpr) {
|
|
3643
|
-
replaceCallName(node, pureApi);
|
|
3644
|
-
} else {
|
|
3645
|
-
replaceIdName(node, pureApi);
|
|
3646
|
-
}
|
|
3647
|
-
recordImport(ctx, pkgName, pureApi);
|
|
3648
|
-
return;
|
|
3649
|
-
}
|
|
3650
|
-
const effectfulApi = effectful[sourceName];
|
|
3651
|
-
if (effectfulApi) {
|
|
3652
|
-
if (isCallExpr) {
|
|
3653
|
-
replaceCallName(node, effectfulApi);
|
|
3654
|
-
} else {
|
|
3655
|
-
replaceIdName(node, effectfulApi);
|
|
3656
|
-
}
|
|
3657
|
-
recordImport(ctx, pkgName, effectfulApi);
|
|
3658
|
-
return;
|
|
3659
|
-
}
|
|
3660
|
-
}
|
|
3661
|
-
function findNestedAdapter(sourceName, nestedMap) {
|
|
3662
|
-
if (!nestedMap) return void 0;
|
|
3663
|
-
if (typeof nestedMap === "string") {
|
|
3664
|
-
return nestedMap;
|
|
3665
|
-
}
|
|
3666
|
-
return nestedMap[sourceName];
|
|
3667
|
-
}
|
|
3668
|
-
function handleDependencyAnalysisAPI(path7, ctx, adapter, pkgName) {
|
|
3669
|
-
const { node } = path7;
|
|
3670
|
-
const { arguments: args } = node;
|
|
3671
|
-
if (args.length === 0) return;
|
|
3672
|
-
const fn = args[0];
|
|
3673
|
-
if (!t35.isArrowFunctionExpression(fn) && !t35.isFunctionExpression(fn)) {
|
|
3674
|
-
return;
|
|
3675
|
-
}
|
|
3676
|
-
const fnPath = path7.get("arguments")[0];
|
|
3677
|
-
const deps = analyzeDeps(fn, ctx, fnPath);
|
|
3678
|
-
args.push(deps);
|
|
3679
|
-
replaceCallName(node, adapter);
|
|
3680
|
-
recordImport(ctx, pkgName, adapter);
|
|
3681
|
-
}
|
|
3682
3981
|
|
|
3683
3982
|
// src/core/transform/sfc/script/syntax-processor/index.ts
|
|
3684
3983
|
function processVueSyntax2(ast, ctx) {
|
|
3685
3984
|
vueSyntaxProcessor2(ast, ctx, {
|
|
3686
3985
|
preprocess: {
|
|
3687
3986
|
applyBabel: [
|
|
3688
|
-
|
|
3987
|
+
resolvePropsIface,
|
|
3689
3988
|
resolveEmitsTopLevelTypes,
|
|
3690
3989
|
resolveSlotsTopLevelTypes,
|
|
3691
|
-
|
|
3692
|
-
|
|
3990
|
+
resolveDefineOptions,
|
|
3991
|
+
resolveDefineExpose,
|
|
3992
|
+
resolveDefineAsyncComponent,
|
|
3693
3993
|
resolveEmitCalls
|
|
3694
3994
|
]
|
|
3695
3995
|
},
|
|
3696
3996
|
process: {
|
|
3697
3997
|
applyBabel: [
|
|
3698
|
-
|
|
3998
|
+
resolveElementRef,
|
|
3999
|
+
// provide 需要在 rename 之前收集并移除原始调用,避免被重命名后失配
|
|
4000
|
+
resolveProvide,
|
|
4001
|
+
resolveRenameAdapter,
|
|
3699
4002
|
resolveArrowFnDeps,
|
|
3700
4003
|
resolveUnanalyzedArrow,
|
|
3701
|
-
|
|
3702
|
-
resolveTemplateRef,
|
|
3703
|
-
resolveProvide,
|
|
4004
|
+
resolveAnalysisOnlyAdapter,
|
|
3704
4005
|
resolveExprMemo,
|
|
3705
|
-
|
|
4006
|
+
resolveLintRules
|
|
3706
4007
|
],
|
|
3707
4008
|
excludeBabel: [resolveTemplateSlotIface, resolveCompIProps]
|
|
3708
4009
|
},
|
|
@@ -3714,12 +4015,12 @@ function processVueSyntax2(ast, ctx) {
|
|
|
3714
4015
|
}
|
|
3715
4016
|
function vueSyntaxProcessor2(ast, ctx, options) {
|
|
3716
4017
|
const runExcludeThenApply = (cfg) => {
|
|
3717
|
-
_optionalChain([cfg, 'access',
|
|
3718
|
-
_optionalChain([cfg, 'access',
|
|
4018
|
+
_optionalChain([cfg, 'access', _111 => _111.excludeBabel, 'optionalAccess', _112 => _112.forEach, 'call', _113 => _113((fn) => fn(ctx, ast))]);
|
|
4019
|
+
_optionalChain([cfg, 'access', _114 => _114.applyBabel, 'optionalAccess', _115 => _115.forEach, 'call', _116 => _116((fn) => _core.traverse.call(void 0, ast, fn(ctx, ast)))]);
|
|
3719
4020
|
};
|
|
3720
4021
|
const runApplyThenExclude = (cfg) => {
|
|
3721
|
-
_optionalChain([cfg, 'access',
|
|
3722
|
-
_optionalChain([cfg, 'access',
|
|
4022
|
+
_optionalChain([cfg, 'access', _117 => _117.applyBabel, 'optionalAccess', _118 => _118.forEach, 'call', _119 => _119((fn) => _core.traverse.call(void 0, ast, fn(ctx, ast)))]);
|
|
4023
|
+
_optionalChain([cfg, 'access', _120 => _120.excludeBabel, 'optionalAccess', _121 => _121.forEach, 'call', _122 => _122((fn) => fn(ctx, ast))]);
|
|
3723
4024
|
};
|
|
3724
4025
|
runExcludeThenApply(options.preprocess);
|
|
3725
4026
|
runExcludeThenApply(options.process);
|
|
@@ -3814,25 +4115,25 @@ function isSimpleExpression(code, excludeVar = false) {
|
|
|
3814
4115
|
let node;
|
|
3815
4116
|
try {
|
|
3816
4117
|
node = _parser.parseExpression.call(void 0, code);
|
|
3817
|
-
} catch (
|
|
4118
|
+
} catch (e6) {
|
|
3818
4119
|
return false;
|
|
3819
4120
|
}
|
|
3820
|
-
if (
|
|
4121
|
+
if (t37.isLiteral(node)) {
|
|
3821
4122
|
return true;
|
|
3822
4123
|
}
|
|
3823
|
-
if (!excludeVar &&
|
|
4124
|
+
if (!excludeVar && t37.isIdentifier(node)) {
|
|
3824
4125
|
return true;
|
|
3825
4126
|
}
|
|
3826
|
-
if (
|
|
3827
|
-
return isSimpleExpression(node.object) &&
|
|
4127
|
+
if (t37.isMemberExpression(node)) {
|
|
4128
|
+
return isSimpleExpression(node.object) && t37.isIdentifier(node.property);
|
|
3828
4129
|
}
|
|
3829
|
-
if (
|
|
4130
|
+
if (t37.isObjectExpression(node) || t37.isArrayExpression(node)) {
|
|
3830
4131
|
return false;
|
|
3831
4132
|
}
|
|
3832
|
-
if (
|
|
4133
|
+
if (t37.isCallExpression(node) || t37.isAssignmentExpression(node)) {
|
|
3833
4134
|
return false;
|
|
3834
4135
|
}
|
|
3835
|
-
if (
|
|
4136
|
+
if (t37.isBinaryExpression(node) || t37.isUnaryExpression(node)) {
|
|
3836
4137
|
return true;
|
|
3837
4138
|
}
|
|
3838
4139
|
return false;
|
|
@@ -3840,16 +4141,16 @@ function isSimpleExpression(code, excludeVar = false) {
|
|
|
3840
4141
|
function isIdentifier20(code) {
|
|
3841
4142
|
try {
|
|
3842
4143
|
const node = _parser.parseExpression.call(void 0, code);
|
|
3843
|
-
return
|
|
3844
|
-
} catch (
|
|
4144
|
+
return t37.isIdentifier(node);
|
|
4145
|
+
} catch (e7) {
|
|
3845
4146
|
return false;
|
|
3846
4147
|
}
|
|
3847
4148
|
}
|
|
3848
4149
|
function isStringLiteral12(code) {
|
|
3849
4150
|
try {
|
|
3850
4151
|
const node = _parser.parseExpression.call(void 0, code);
|
|
3851
|
-
return
|
|
3852
|
-
} catch (
|
|
4152
|
+
return t37.isStringLiteral(node) || t37.isTemplateLiteral(node);
|
|
4153
|
+
} catch (e8) {
|
|
3853
4154
|
return false;
|
|
3854
4155
|
}
|
|
3855
4156
|
}
|
|
@@ -3868,7 +4169,7 @@ function resolveEmitsCalls(input, ctx) {
|
|
|
3868
4169
|
if (!result) return input;
|
|
3869
4170
|
const [, , eventName, args] = result;
|
|
3870
4171
|
const callee = eventName.split(/[:\-]/).map((part) => capitalize(camelCase(part))).join("");
|
|
3871
|
-
const event = args ? `on${callee}(${args})` : `on${callee}()`;
|
|
4172
|
+
const event = args ? `on${callee}?.(${args})` : `on${callee}?.()`;
|
|
3872
4173
|
return `${ctx.propField}?.${event}`;
|
|
3873
4174
|
}
|
|
3874
4175
|
function matchEmitCalls(input, ctx) {
|
|
@@ -3893,7 +4194,7 @@ function resolveRefVariable(input, ctx) {
|
|
|
3893
4194
|
};
|
|
3894
4195
|
for (const name in reactiveBindings) {
|
|
3895
4196
|
const binding = reactiveBindings[name];
|
|
3896
|
-
if (_optionalChain([binding, 'optionalAccess',
|
|
4197
|
+
if (_optionalChain([binding, 'optionalAccess', _123 => _123.reactiveType]) !== "ref") continue;
|
|
3897
4198
|
input = addValueProperty(input, name);
|
|
3898
4199
|
}
|
|
3899
4200
|
return input;
|
|
@@ -3901,13 +4202,13 @@ function resolveRefVariable(input, ctx) {
|
|
|
3901
4202
|
|
|
3902
4203
|
// src/core/transform/sfc/template/shared/resolve-string-expression/index.ts
|
|
3903
4204
|
function resolveStringExpr(input, ctx, toStrLiteral = false) {
|
|
3904
|
-
if (toStrLiteral) return
|
|
4205
|
+
if (toStrLiteral) return t38.stringLiteral(input);
|
|
3905
4206
|
const { filename, scriptData } = ctx;
|
|
3906
4207
|
const newContent = resolveSpecialExpressions(input, ctx);
|
|
3907
4208
|
try {
|
|
3908
4209
|
return stringToExpr(newContent, scriptData.lang, filename);
|
|
3909
|
-
} catch (
|
|
3910
|
-
return
|
|
4210
|
+
} catch (e9) {
|
|
4211
|
+
return t38.identifier(newContent);
|
|
3911
4212
|
}
|
|
3912
4213
|
}
|
|
3913
4214
|
|
|
@@ -4012,12 +4313,12 @@ function wrapSingleQuotes(content, condition) {
|
|
|
4012
4313
|
return condition || strCodeTypes.isStringLiteral(content) ? `'${content}'` : content;
|
|
4013
4314
|
}
|
|
4014
4315
|
function checkPropIsDynamicKey(ctx, node) {
|
|
4015
|
-
const isKeyStatic = _optionalChain([node, 'access',
|
|
4316
|
+
const isKeyStatic = _optionalChain([node, 'access', _124 => _124.arg, 'optionalAccess', _125 => _125.isStatic]);
|
|
4016
4317
|
const { source, filename } = ctx;
|
|
4017
4318
|
if (node.rawName === "v-bind" && !node.name) {
|
|
4018
4319
|
logger.warn("Keyless v-bind will overwrite all previously declared props at runtime.", {
|
|
4019
4320
|
source,
|
|
4020
|
-
loc: _optionalChain([node, 'access',
|
|
4321
|
+
loc: _optionalChain([node, 'access', _126 => _126.arg, 'optionalAccess', _127 => _127.loc]),
|
|
4021
4322
|
file: filename
|
|
4022
4323
|
});
|
|
4023
4324
|
return;
|
|
@@ -4025,7 +4326,7 @@ function checkPropIsDynamicKey(ctx, node) {
|
|
|
4025
4326
|
if (isKeyStatic === false) {
|
|
4026
4327
|
logger.warn("Avoid using dynamic slot names, as they generate complex JSX prop expressions.", {
|
|
4027
4328
|
source,
|
|
4028
|
-
loc: _optionalChain([node, 'access',
|
|
4329
|
+
loc: _optionalChain([node, 'access', _128 => _128.arg, 'optionalAccess', _129 => _129.loc]),
|
|
4029
4330
|
file: filename
|
|
4030
4331
|
});
|
|
4031
4332
|
}
|
|
@@ -4044,7 +4345,7 @@ function resolvePropAsBabelExp(ir, ctx) {
|
|
|
4044
4345
|
const mergedItems = value.merge;
|
|
4045
4346
|
const setNameIdentifier = (target, valueName) => {
|
|
4046
4347
|
target.content = valueName;
|
|
4047
|
-
target.ast =
|
|
4348
|
+
target.ast = t39.jsxIdentifier(valueName);
|
|
4048
4349
|
};
|
|
4049
4350
|
const setValueExpression = (target, content, isStringLiteral13) => {
|
|
4050
4351
|
target.content = content;
|
|
@@ -4058,29 +4359,34 @@ function resolvePropAsBabelExp(ir, ctx) {
|
|
|
4058
4359
|
if (setName && nameIdentifier) {
|
|
4059
4360
|
setNameIdentifier(nameExp, nameIdentifier);
|
|
4060
4361
|
}
|
|
4362
|
+
const dir = ADAPTER_RULES.runtime.dir;
|
|
4363
|
+
recordImport(ctx, dir.package, dir.target);
|
|
4061
4364
|
setValueExpression(value.babelExp, expression, isStringLiteral13);
|
|
4062
|
-
recordImport(ctx, PACKAGE_NAME.runtime, ADAPTER_UTILS_MAP.dir);
|
|
4063
4365
|
};
|
|
4064
4366
|
if (ir.isKeyLessVBind) {
|
|
4065
|
-
const
|
|
4367
|
+
const dirKeyless = ADAPTER_RULES.runtime.dirKeyless;
|
|
4368
|
+
const expression = createRuntimeCall(dirKeyless.target, [valueContent]);
|
|
4066
4369
|
applyRuntimeExpression(expression, false);
|
|
4067
4370
|
return;
|
|
4068
4371
|
}
|
|
4069
4372
|
if (isClassAttr(name) && !value.isStringLiteral && !valueContent.startsWith(STYLE_MODULE_NAME)) {
|
|
4070
|
-
const
|
|
4071
|
-
const
|
|
4373
|
+
const dirCls = ADAPTER_RULES.runtime.dirCls;
|
|
4374
|
+
const arg = _optionalChain([mergedItems, 'optionalAccess', _130 => _130.join, 'call', _131 => _131(",")]) || wrapSingleQuotes(valueContent);
|
|
4375
|
+
const expression = createRuntimeCall(dirCls.target, [arg]);
|
|
4072
4376
|
applyRuntimeExpression(expression, true, name);
|
|
4073
4377
|
return;
|
|
4074
4378
|
}
|
|
4075
|
-
if (isStyleAttr(name) && (!isSimpleStyle(valueContent) || _optionalChain([mergedItems, 'optionalAccess',
|
|
4076
|
-
const
|
|
4077
|
-
const
|
|
4379
|
+
if (isStyleAttr(name) && (!isSimpleStyle(valueContent) || _optionalChain([mergedItems, 'optionalAccess', _132 => _132.some, 'call', _133 => _133((item) => !isSimpleStyle(item))]))) {
|
|
4380
|
+
const dirStyle = ADAPTER_RULES.runtime.dirStyle;
|
|
4381
|
+
const arg = _optionalChain([mergedItems, 'optionalAccess', _134 => _134.join, 'call', _135 => _135(",")]) || valueContent;
|
|
4382
|
+
const expression = createRuntimeCall(dirStyle.target, [arg]);
|
|
4078
4383
|
applyRuntimeExpression(expression, true, name);
|
|
4079
4384
|
return;
|
|
4080
4385
|
}
|
|
4081
|
-
if (ir.type === 3 /* EVENT */ && _optionalChain([ir, 'access',
|
|
4386
|
+
if (ir.type === 3 /* EVENT */ && _optionalChain([ir, 'access', _136 => _136.modifiers, 'optionalAccess', _137 => _137.length])) {
|
|
4387
|
+
const dirOn = ADAPTER_RULES.runtime.dirOn;
|
|
4082
4388
|
const eventName = wrapSingleQuotes(ir.__vOnEvName || name, ir.isStatic);
|
|
4083
|
-
const expression = createRuntimeCall(
|
|
4389
|
+
const expression = createRuntimeCall(dirOn.target, [eventName, valueContent]);
|
|
4084
4390
|
applyRuntimeExpression(expression, true, name);
|
|
4085
4391
|
return;
|
|
4086
4392
|
}
|
|
@@ -4132,13 +4438,13 @@ function resolveElementChildrenRules(children, ctx, parentIR, ir) {
|
|
|
4132
4438
|
continue;
|
|
4133
4439
|
}
|
|
4134
4440
|
const nodeIR = child;
|
|
4135
|
-
if (_optionalChain([parentIR, 'optionalAccess',
|
|
4136
|
-
if (parentIR.tag ==
|
|
4441
|
+
if (_optionalChain([parentIR, 'optionalAccess', _138 => _138.isBuiltIn])) {
|
|
4442
|
+
if (parentIR.tag == VUE_API_MAP.Transition) {
|
|
4137
4443
|
resolveTransitionRules(nodeIR, parentIR, ir, ctx);
|
|
4138
4444
|
}
|
|
4139
4445
|
}
|
|
4140
4446
|
if (nodeIR.isRoute) {
|
|
4141
|
-
if (nodeIR.tag ===
|
|
4447
|
+
if (nodeIR.tag === VUE_API_MAP.RouterLink) {
|
|
4142
4448
|
resolveRouterLinkRules(nodeIR, ctx);
|
|
4143
4449
|
}
|
|
4144
4450
|
}
|
|
@@ -4173,7 +4479,7 @@ function walkElementNodes(node, onElement) {
|
|
|
4173
4479
|
}
|
|
4174
4480
|
function resolveDefaultStyleModuleName(node) {
|
|
4175
4481
|
const { exp } = node;
|
|
4176
|
-
if (_optionalChain([exp, 'optionalAccess',
|
|
4482
|
+
if (_optionalChain([exp, 'optionalAccess', _139 => _139.type]) !== _compilercore.NodeTypes.SIMPLE_EXPRESSION) {
|
|
4177
4483
|
return;
|
|
4178
4484
|
}
|
|
4179
4485
|
if (exp.content.includes("$style")) {
|
|
@@ -4186,6 +4492,8 @@ function resolveDefaultStyleModuleName(node) {
|
|
|
4186
4492
|
|
|
4187
4493
|
|
|
4188
4494
|
|
|
4495
|
+
|
|
4496
|
+
|
|
4189
4497
|
function resolveStyleScopeAttribute(node, _ir, ctx) {
|
|
4190
4498
|
if (!ctx.styleData.scopeId) {
|
|
4191
4499
|
return;
|
|
@@ -4205,11 +4513,11 @@ function walkElementNodes2(node, onElement) {
|
|
|
4205
4513
|
}
|
|
4206
4514
|
function injectStyleScopeAttribute(node, ctx) {
|
|
4207
4515
|
const { scopeId } = ctx.styleData;
|
|
4208
|
-
if (!scopeId || isComponentElement(node)) {
|
|
4516
|
+
if (!scopeId || isComponentElement(node) || _compilercore.isSlotOutlet.call(void 0, node) || _compilercore.isTemplateNode.call(void 0, node)) {
|
|
4209
4517
|
return;
|
|
4210
4518
|
}
|
|
4211
4519
|
const hasDynamicIs = node.props.some((prop) => {
|
|
4212
|
-
if (prop.type !== _compilercore.NodeTypes.DIRECTIVE || _optionalChain([prop, 'access',
|
|
4520
|
+
if (prop.type !== _compilercore.NodeTypes.DIRECTIVE || _optionalChain([prop, 'access', _140 => _140.arg, 'optionalAccess', _141 => _141.type]) !== _compilercore.NodeTypes.SIMPLE_EXPRESSION) {
|
|
4213
4521
|
return false;
|
|
4214
4522
|
}
|
|
4215
4523
|
return prop.arg.content === "is";
|
|
@@ -4275,7 +4583,7 @@ function mergeStyleProps(oldAttr, newAttr) {
|
|
|
4275
4583
|
const oldStyle = oldAttr.value.content;
|
|
4276
4584
|
const newStyle = parseStyleString(newAttr.value.content);
|
|
4277
4585
|
let merged = oldAttr.value.merge;
|
|
4278
|
-
if (!_optionalChain([merged, 'optionalAccess',
|
|
4586
|
+
if (!_optionalChain([merged, 'optionalAccess', _142 => _142.length])) {
|
|
4279
4587
|
merged = oldAttr.value.merge = [oldStyle, newStyle];
|
|
4280
4588
|
} else {
|
|
4281
4589
|
merged.push(newStyle);
|
|
@@ -4305,7 +4613,7 @@ function warnUnsupportedVueDollarVar(ctx, node) {
|
|
|
4305
4613
|
const { source, filename } = ctx;
|
|
4306
4614
|
let value = "";
|
|
4307
4615
|
let loc;
|
|
4308
|
-
if (node.type === _compilercore.NodeTypes.DIRECTIVE && _optionalChain([node, 'access',
|
|
4616
|
+
if (node.type === _compilercore.NodeTypes.DIRECTIVE && _optionalChain([node, 'access', _143 => _143.exp, 'optionalAccess', _144 => _144.type]) === _compilercore.NodeTypes.SIMPLE_EXPRESSION) {
|
|
4309
4617
|
value = node.exp.content;
|
|
4310
4618
|
loc = node.exp.loc;
|
|
4311
4619
|
} else if (node.type === _compilercore.NodeTypes.INTERPOLATION && node.content.type === _compilercore.NodeTypes.SIMPLE_EXPRESSION) {
|
|
@@ -4345,7 +4653,7 @@ function resolveDynamicIsProp(node, ir, ctx, nodeIR) {
|
|
|
4345
4653
|
}
|
|
4346
4654
|
const propIR = createPropsIR("is", "is", content);
|
|
4347
4655
|
resolvePropAsBabelExp(propIR, ctx);
|
|
4348
|
-
nodeIR.tag =
|
|
4656
|
+
nodeIR.tag = VUE_API_MAP.DynamicComponent;
|
|
4349
4657
|
nodeIR.isComponent = true;
|
|
4350
4658
|
nodeIR.props.push(propIR);
|
|
4351
4659
|
recordImport(ctx, PACKAGE_NAME.runtime, nodeIR.tag);
|
|
@@ -4354,15 +4662,20 @@ function resolveDynamicIsProp(node, ir, ctx, nodeIR) {
|
|
|
4354
4662
|
// src/core/transform/sfc/template/syntax-processor/process/props/resolve-ref-prop.ts
|
|
4355
4663
|
|
|
4356
4664
|
function resolveRefProp(node, ctx, nodeIR) {
|
|
4357
|
-
const {
|
|
4665
|
+
const {
|
|
4666
|
+
templateData: { refBindings }
|
|
4667
|
+
} = ctx;
|
|
4358
4668
|
let propIR;
|
|
4359
4669
|
if (node.type === _compilercore.NodeTypes.ATTRIBUTE) {
|
|
4360
|
-
const
|
|
4361
|
-
|
|
4362
|
-
|
|
4670
|
+
const tag = _optionalChain([node, 'access', _145 => _145.value, 'optionalAccess', _146 => _146.content]);
|
|
4671
|
+
if (!tag) return;
|
|
4672
|
+
collectComponentRef(tag, ctx);
|
|
4673
|
+
const domRefBinding = Object.values(refBindings.domRefs).find((r) => r.tag === tag);
|
|
4674
|
+
const refVar = _optionalChain([domRefBinding, 'optionalAccess', _147 => _147.name]) || _optionalChain([refBindings, 'access', _148 => _148.componentRefs, 'access', _149 => _149[tag], 'optionalAccess', _150 => _150.name]);
|
|
4675
|
+
propIR = createPropsIR("ref", "ref", refVar || "null");
|
|
4363
4676
|
} else {
|
|
4364
4677
|
const exp = node.exp;
|
|
4365
|
-
for (const name in
|
|
4678
|
+
for (const name in refBindings.domRefs) {
|
|
4366
4679
|
const newName = `${name}.current`;
|
|
4367
4680
|
const regex = new RegExp(`${name}(?!\\.current)`, "g");
|
|
4368
4681
|
exp.content = exp.content.replace(regex, newName);
|
|
@@ -4372,13 +4685,29 @@ function resolveRefProp(node, ctx, nodeIR) {
|
|
|
4372
4685
|
resolvePropAsBabelExp(propIR, ctx);
|
|
4373
4686
|
nodeIR.props.push(propIR);
|
|
4374
4687
|
}
|
|
4688
|
+
function collectComponentRef(tag, ctx) {
|
|
4689
|
+
if (tag in HTML_TAG_TYPES) {
|
|
4690
|
+
return;
|
|
4691
|
+
}
|
|
4692
|
+
const { refBindings, reactiveBindings } = ctx.templateData;
|
|
4693
|
+
refBindings.componentRefs[tag] = {
|
|
4694
|
+
tag,
|
|
4695
|
+
// 对应的标签名(随便填,不影响)
|
|
4696
|
+
htmlType: "",
|
|
4697
|
+
name: tag
|
|
4698
|
+
// 对应的变量名(随便填,不影响)
|
|
4699
|
+
};
|
|
4700
|
+
if (reactiveBindings[tag]) {
|
|
4701
|
+
delete reactiveBindings[tag];
|
|
4702
|
+
}
|
|
4703
|
+
}
|
|
4375
4704
|
|
|
4376
4705
|
// src/core/transform/sfc/template/syntax-processor/process/props/resolve-dynamic-attribute-prop.ts
|
|
4377
4706
|
function resolveDynamicAttributeProp(node, ir, ctx, nodeIR) {
|
|
4378
4707
|
const arg = node.arg;
|
|
4379
4708
|
const exp = node.exp;
|
|
4380
|
-
const name = _nullishCoalesce(_optionalChain([arg, 'optionalAccess',
|
|
4381
|
-
const content = _nullishCoalesce(_optionalChain([exp, 'optionalAccess',
|
|
4709
|
+
const name = _nullishCoalesce(_optionalChain([arg, 'optionalAccess', _151 => _151.content]), () => ( ""));
|
|
4710
|
+
const content = _nullishCoalesce(_optionalChain([exp, 'optionalAccess', _152 => _152.content]), () => ( "true"));
|
|
4382
4711
|
warnUnsupportedVueDollarVar(ctx, node);
|
|
4383
4712
|
if (name === "is") {
|
|
4384
4713
|
resolveDynamicIsProp(node, ir, ctx, nodeIR);
|
|
@@ -4389,7 +4718,7 @@ function resolveDynamicAttributeProp(node, ir, ctx, nodeIR) {
|
|
|
4389
4718
|
return;
|
|
4390
4719
|
}
|
|
4391
4720
|
const dynamicPropIR = createPropsIR(node.rawName, name, content);
|
|
4392
|
-
dynamicPropIR.isStatic = _nullishCoalesce(_optionalChain([arg, 'optionalAccess',
|
|
4721
|
+
dynamicPropIR.isStatic = _nullishCoalesce(_optionalChain([arg, 'optionalAccess', _153 => _153.isStatic]), () => ( true));
|
|
4393
4722
|
checkPropIsDynamicKey(ctx, node);
|
|
4394
4723
|
resolvePropertyIR(dynamicPropIR, ir, ctx, nodeIR, true);
|
|
4395
4724
|
}
|
|
@@ -4417,7 +4746,7 @@ function resolvePropertyIR(node, ir, ctx, nodeIR, isDynamic = false) {
|
|
|
4417
4746
|
// src/core/transform/sfc/template/syntax-processor/process/props/resolve-attribute-prop.ts
|
|
4418
4747
|
function resolveAttributeProp(node, ir, ctx, nodeIR) {
|
|
4419
4748
|
const name = node.name;
|
|
4420
|
-
const content = _nullishCoalesce(_optionalChain([node, 'access',
|
|
4749
|
+
const content = _nullishCoalesce(_optionalChain([node, 'access', _154 => _154.value, 'optionalAccess', _155 => _155.content]), () => ( "true"));
|
|
4421
4750
|
if (name === "is") {
|
|
4422
4751
|
resolveStaticIsProp(content, ir, ctx, nodeIR);
|
|
4423
4752
|
return;
|
|
@@ -4441,10 +4770,10 @@ function resolveRouterLinkVSlotProp(node, nodeIR, ctx) {
|
|
|
4441
4770
|
type: 2 /* SLOT */,
|
|
4442
4771
|
name: "customRender",
|
|
4443
4772
|
rawName: _nullishCoalesce(node.rawName, () => ( "v-slot")),
|
|
4444
|
-
isStatic: _nullishCoalesce(_optionalChain([arg, 'optionalAccess',
|
|
4773
|
+
isStatic: _nullishCoalesce(_optionalChain([arg, 'optionalAccess', _156 => _156.isStatic]), () => ( true)),
|
|
4445
4774
|
isScoped: true,
|
|
4446
4775
|
callback: {
|
|
4447
|
-
arg: _nullishCoalesce(_optionalChain([exp, 'optionalAccess',
|
|
4776
|
+
arg: _nullishCoalesce(_optionalChain([exp, 'optionalAccess', _157 => _157.content, 'optionalAccess', _158 => _158.trim, 'call', _159 => _159()]), () => ( "")),
|
|
4448
4777
|
exp: []
|
|
4449
4778
|
}
|
|
4450
4779
|
};
|
|
@@ -4460,10 +4789,10 @@ function resolveVFor(node, _ir, _ctx, nodeIR) {
|
|
|
4460
4789
|
};
|
|
4461
4790
|
}
|
|
4462
4791
|
function resolveForResult(forParseResult) {
|
|
4463
|
-
const source = _optionalChain([forParseResult, 'access',
|
|
4464
|
-
const value = _optionalChain([forParseResult, 'access',
|
|
4465
|
-
const index = _optionalChain([forParseResult, 'access',
|
|
4466
|
-
const key = _optionalChain([forParseResult, 'access',
|
|
4792
|
+
const source = _optionalChain([forParseResult, 'access', _160 => _160.source, 'optionalAccess', _161 => _161.content]);
|
|
4793
|
+
const value = _optionalChain([forParseResult, 'access', _162 => _162.value, 'optionalAccess', _163 => _163.content]);
|
|
4794
|
+
const index = _optionalChain([forParseResult, 'access', _164 => _164.index, 'optionalAccess', _165 => _165.content]);
|
|
4795
|
+
const key = _optionalChain([forParseResult, 'access', _166 => _166.key, 'optionalAccess', _167 => _167.content]);
|
|
4467
4796
|
return {
|
|
4468
4797
|
source,
|
|
4469
4798
|
value,
|
|
@@ -4483,7 +4812,7 @@ function resolveVHtml(node, ir, ctx, nodeIR) {
|
|
|
4483
4812
|
// src/core/transform/sfc/template/syntax-processor/process/props/resolve-v-if.ts
|
|
4484
4813
|
function resolveVIf(node, _ir, ctx, nodeIR, siblingNodesIR) {
|
|
4485
4814
|
const name = node.name === "else-if" ? "elseIf" : node.name;
|
|
4486
|
-
const value = _nullishCoalesce(_optionalChain([node, 'access',
|
|
4815
|
+
const value = _nullishCoalesce(_optionalChain([node, 'access', _168 => _168.exp, 'optionalAccess', _169 => _169.content]), () => ( "true"));
|
|
4487
4816
|
const prevNode = siblingNodesIR[siblingNodesIR.length - 1];
|
|
4488
4817
|
const isElseBranch = name === "else" || name === "elseIf";
|
|
4489
4818
|
let hasError = false;
|
|
@@ -4522,7 +4851,7 @@ function resolveVIf(node, _ir, ctx, nodeIR, siblingNodesIR) {
|
|
|
4522
4851
|
// src/core/transform/sfc/template/syntax-processor/process/props/resolve-v-memo.ts
|
|
4523
4852
|
function resolveVMemo(node, _ir, ctx, nodeIR) {
|
|
4524
4853
|
const exp = node.exp;
|
|
4525
|
-
let value = _optionalChain([exp, 'optionalAccess',
|
|
4854
|
+
let value = _optionalChain([exp, 'optionalAccess', _170 => _170.content]);
|
|
4526
4855
|
if (value !== void 0) {
|
|
4527
4856
|
if (!value.trim() || !value.startsWith("[") && !value.endsWith("]")) {
|
|
4528
4857
|
const { source, filename } = ctx;
|
|
@@ -4562,15 +4891,14 @@ function resolveVModel(node, _ir, ctx, elementNode, nodeIR) {
|
|
|
4562
4891
|
const getterName = exp.content;
|
|
4563
4892
|
const isComponent = elementNode.tagType === _compilercore.ElementTypes.COMPONENT;
|
|
4564
4893
|
const inputType = resolveHtmlInput(elementNode, isComponent);
|
|
4565
|
-
const propName = _nullishCoalesce(_optionalChain([arg, 'optionalAccess',
|
|
4894
|
+
const propName = _nullishCoalesce(_optionalChain([arg, 'optionalAccess', _171 => _171.content]), () => ( resolveModelPropName(inputType, isComponent)));
|
|
4566
4895
|
let valuePropIR;
|
|
4567
4896
|
let eventPropIR;
|
|
4568
4897
|
if (isComponent) {
|
|
4569
4898
|
valuePropIR = createPropsIR("v-model", propName, getterName);
|
|
4570
|
-
const
|
|
4571
|
-
const
|
|
4572
|
-
const
|
|
4573
|
-
const isTS = _optionalChain([ctx, 'access', _162 => _162.scriptData, 'optionalAccess', _163 => _163.lang, 'optionalAccess', _164 => _164.startsWith, 'call', _165 => _165("ts")]);
|
|
4899
|
+
const eventReactName = `onUpdate${capitalize(camelCase(propName))}`;
|
|
4900
|
+
const eventVueName = `update:${propName}`;
|
|
4901
|
+
const isTS = _optionalChain([ctx, 'access', _172 => _172.scriptData, 'optionalAccess', _173 => _173.lang, 'optionalAccess', _174 => _174.startsWith, 'call', _175 => _175("ts")]);
|
|
4574
4902
|
const valueArg = isTS ? "value: any" : "value";
|
|
4575
4903
|
const processedValue = applyValueModifiers("value", modifiers);
|
|
4576
4904
|
const handlerBody = `(${valueArg}) => { ${getterName} = ${processedValue} }`;
|
|
@@ -4608,7 +4936,7 @@ function getRadioValue(elementNode) {
|
|
|
4608
4936
|
const valueAttr = elementNode.props.find(
|
|
4609
4937
|
(prop) => prop.type === _compilercore.NodeTypes.ATTRIBUTE && prop.name === "value"
|
|
4610
4938
|
);
|
|
4611
|
-
if (!_optionalChain([valueAttr, 'optionalAccess',
|
|
4939
|
+
if (!_optionalChain([valueAttr, 'optionalAccess', _176 => _176.value, 'optionalAccess', _177 => _177.content])) return '""';
|
|
4612
4940
|
const content = valueAttr.value.content;
|
|
4613
4941
|
return /^['"]/.test(content) ? content : `"${content}"`;
|
|
4614
4942
|
}
|
|
@@ -4618,7 +4946,7 @@ function resolveHtmlInput(node, isComponent) {
|
|
|
4618
4946
|
const typeProp = node.props.find(
|
|
4619
4947
|
(prop) => prop.type === _compilercore.NodeTypes.ATTRIBUTE && prop.name === "type"
|
|
4620
4948
|
);
|
|
4621
|
-
return _optionalChain([typeProp, 'optionalAccess',
|
|
4949
|
+
return _optionalChain([typeProp, 'optionalAccess', _178 => _178.value, 'optionalAccess', _179 => _179.content, 'optionalAccess', _180 => _180.toLowerCase, 'call', _181 => _181()]);
|
|
4622
4950
|
}
|
|
4623
4951
|
function applyValueModifiers(valueExp, modifiers) {
|
|
4624
4952
|
let result = valueExp;
|
|
@@ -4630,12 +4958,6 @@ function applyValueModifiers(valueExp, modifiers) {
|
|
|
4630
4958
|
}
|
|
4631
4959
|
return result;
|
|
4632
4960
|
}
|
|
4633
|
-
function getRootIdName(expr) {
|
|
4634
|
-
if (typeof expr !== "string") return;
|
|
4635
|
-
const pattern = /^([a-zA-Z_$][a-zA-Z0-9_$]*)(?:[\.\?\.\[\(].*)?$/;
|
|
4636
|
-
const match = pattern.exec(expr.trim());
|
|
4637
|
-
return _optionalChain([match, 'optionalAccess', _172 => _172[1]]);
|
|
4638
|
-
}
|
|
4639
4961
|
|
|
4640
4962
|
// src/core/transform/sfc/template/syntax-processor/process/props/resolve-v-on.ts
|
|
4641
4963
|
|
|
@@ -4655,7 +4977,7 @@ function resolveVOn(node, _ir, ctx, nodeIR) {
|
|
|
4655
4977
|
originalVueEventName = `${arg.content}.${modifiers.join(".")}`;
|
|
4656
4978
|
} else {
|
|
4657
4979
|
const expr = stringToExpr(handler);
|
|
4658
|
-
if (!
|
|
4980
|
+
if (!t40.isFunctionExpression(expr) && !t40.isIdentifier(expr)) {
|
|
4659
4981
|
handler = `() => {${handler}}`;
|
|
4660
4982
|
}
|
|
4661
4983
|
}
|
|
@@ -4782,7 +5104,7 @@ function resolveDirectiveProp(node, ir, ctx, elementNode, nodeIR, siblingNodesIR
|
|
|
4782
5104
|
return resolveVOn(node, ir, ctx, nodeIR);
|
|
4783
5105
|
}
|
|
4784
5106
|
if (isVSlot(rawName2)) {
|
|
4785
|
-
if (nodeIR.tag ===
|
|
5107
|
+
if (nodeIR.tag === VUE_API_MAP.RouterLink) {
|
|
4786
5108
|
resolveRouterLinkVSlotProp(node, nodeIR, ctx);
|
|
4787
5109
|
}
|
|
4788
5110
|
return true;
|
|
@@ -4823,7 +5145,7 @@ function resolveVSlotProp(node, _ir, ctx) {
|
|
|
4823
5145
|
const name = !arg || arg.content === "default" ? "children" : arg.content;
|
|
4824
5146
|
const content = !isScoped ? [] : void 0;
|
|
4825
5147
|
const callback = isScoped ? {
|
|
4826
|
-
arg: _nullishCoalesce(_optionalChain([exp, 'optionalAccess',
|
|
5148
|
+
arg: _nullishCoalesce(_optionalChain([exp, 'optionalAccess', _182 => _182.content, 'optionalAccess', _183 => _183.trim, 'call', _184 => _184()]), () => ( "")),
|
|
4827
5149
|
exp: []
|
|
4828
5150
|
} : void 0;
|
|
4829
5151
|
checkPropIsDynamicKey(ctx, node);
|
|
@@ -4831,7 +5153,7 @@ function resolveVSlotProp(node, _ir, ctx) {
|
|
|
4831
5153
|
type: 2 /* SLOT */,
|
|
4832
5154
|
name,
|
|
4833
5155
|
rawName: _nullishCoalesce(node.rawName, () => ( "default")),
|
|
4834
|
-
isStatic: _nullishCoalesce(_optionalChain([arg, 'optionalAccess',
|
|
5156
|
+
isStatic: _nullishCoalesce(_optionalChain([arg, 'optionalAccess', _185 => _185.isStatic]), () => ( true)),
|
|
4835
5157
|
isScoped,
|
|
4836
5158
|
content,
|
|
4837
5159
|
callback
|
|
@@ -4856,14 +5178,16 @@ function resolveElementNode(node, ir, ctx, siblingNodesIR) {
|
|
|
4856
5178
|
isSelfClosing: node.isSelfClosing,
|
|
4857
5179
|
loc: node.loc
|
|
4858
5180
|
});
|
|
4859
|
-
|
|
5181
|
+
const routerAdapter = ADAPTER_RULES.router[tag];
|
|
5182
|
+
const runtimeAdapter = ADAPTER_RULES.runtime[tag];
|
|
5183
|
+
if (runtimeAdapter) {
|
|
4860
5184
|
nodeIR.isBuiltIn = true;
|
|
4861
|
-
recordImport(ctx,
|
|
5185
|
+
recordImport(ctx, runtimeAdapter.package, runtimeAdapter.target);
|
|
4862
5186
|
}
|
|
4863
|
-
if (
|
|
5187
|
+
if (routerAdapter) {
|
|
4864
5188
|
if (!ctx.route) ctx.route = true;
|
|
4865
5189
|
nodeIR.isRoute = true;
|
|
4866
|
-
recordImport(ctx,
|
|
5190
|
+
recordImport(ctx, _optionalChain([routerAdapter, 'optionalAccess', _186 => _186.package]), routerAdapter.target);
|
|
4867
5191
|
}
|
|
4868
5192
|
resolveProps(node, ir, ctx, nodeIR, siblingNodesIR);
|
|
4869
5193
|
return nodeIR;
|
|
@@ -4999,7 +5323,7 @@ function resolveSlotProps(node, ctx) {
|
|
|
4999
5323
|
for (const prop of node.props) {
|
|
5000
5324
|
if (prop.type === _compilercore.NodeTypes.ATTRIBUTE) {
|
|
5001
5325
|
const attr = prop.name;
|
|
5002
|
-
const value = _optionalChain([prop, 'access',
|
|
5326
|
+
const value = _optionalChain([prop, 'access', _187 => _187.value, 'optionalAccess', _188 => _188.content, 'access', _189 => _189.trim, 'call', _190 => _190()]);
|
|
5003
5327
|
if (attr === "name" && value) {
|
|
5004
5328
|
result.name = camelCase(value);
|
|
5005
5329
|
} else {
|
|
@@ -5089,19 +5413,19 @@ function resolveTemplate2(root, ctx) {
|
|
|
5089
5413
|
// src/core/transform/sfc/index.ts
|
|
5090
5414
|
function transform(ast, ctx, options) {
|
|
5091
5415
|
const { template, script, style } = ast;
|
|
5092
|
-
const templateIR = resolveTemplate2(_optionalChain([template, 'optionalAccess',
|
|
5093
|
-
const scriptIR = resolveScript2(_optionalChain([script, 'optionalAccess',
|
|
5416
|
+
const templateIR = resolveTemplate2(_optionalChain([template, 'optionalAccess', _191 => _191.ast]), ctx);
|
|
5417
|
+
const scriptIR = resolveScript2(_optionalChain([script, 'optionalAccess', _192 => _192.ast]), ctx);
|
|
5094
5418
|
const result = {
|
|
5095
5419
|
template: templateIR,
|
|
5096
5420
|
script: scriptIR,
|
|
5097
|
-
style: _optionalChain([style, 'optionalAccess',
|
|
5421
|
+
style: _optionalChain([style, 'optionalAccess', _193 => _193.source, 'optionalAccess', _194 => _194.content])
|
|
5098
5422
|
};
|
|
5099
|
-
executePlugins(_optionalChain([options, 'optionalAccess',
|
|
5423
|
+
executePlugins(_optionalChain([options, 'optionalAccess', _195 => _195.plugins]), result, ctx);
|
|
5100
5424
|
return result;
|
|
5101
5425
|
}
|
|
5102
5426
|
|
|
5103
5427
|
// package.json
|
|
5104
|
-
var version = "1.
|
|
5428
|
+
var version = "1.2.1";
|
|
5105
5429
|
var bin = {
|
|
5106
5430
|
vureact: "./bin/vureact.js"
|
|
5107
5431
|
};
|
|
@@ -5134,7 +5458,7 @@ async function formatWithPrettier(code, lang, opts) {
|
|
|
5134
5458
|
...opts,
|
|
5135
5459
|
parser
|
|
5136
5460
|
});
|
|
5137
|
-
} catch (
|
|
5461
|
+
} catch (e10) {
|
|
5138
5462
|
logger.info("Prettier is unavailable; the built-in simple formatter is used.");
|
|
5139
5463
|
return simpleFormat(code);
|
|
5140
5464
|
}
|
|
@@ -5159,7 +5483,7 @@ var Helper = (_class3 = class {
|
|
|
5159
5483
|
__init6() {this.outDir = "react-app"}
|
|
5160
5484
|
constructor(opts) {;_class3.prototype.__init5.call(this);_class3.prototype.__init6.call(this);
|
|
5161
5485
|
this.compilerOpts = opts;
|
|
5162
|
-
if (_optionalChain([opts, 'access',
|
|
5486
|
+
if (_optionalChain([opts, 'access', _196 => _196.output, 'optionalAccess', _197 => _197.workspace])) {
|
|
5163
5487
|
this.workspaceDir = opts.output.workspace;
|
|
5164
5488
|
}
|
|
5165
5489
|
const excludePatterns = PathFilter.withDefaults(opts.exclude || []);
|
|
@@ -5194,7 +5518,7 @@ var Helper = (_class3 = class {
|
|
|
5194
5518
|
}
|
|
5195
5519
|
getOutDirName() {
|
|
5196
5520
|
const { output } = this.compilerOpts;
|
|
5197
|
-
return _optionalChain([output, 'optionalAccess',
|
|
5521
|
+
return _optionalChain([output, 'optionalAccess', _198 => _198.outDir]) || this.outDir;
|
|
5198
5522
|
}
|
|
5199
5523
|
getWorkspaceDir() {
|
|
5200
5524
|
return _path2.default.resolve(this.getProjectRoot(), this.workspaceDir);
|
|
@@ -5208,7 +5532,7 @@ var Helper = (_class3 = class {
|
|
|
5208
5532
|
}
|
|
5209
5533
|
getIgnoreAssets() {
|
|
5210
5534
|
const { output } = this.compilerOpts;
|
|
5211
|
-
if (_optionalChain([output, 'optionalAccess',
|
|
5535
|
+
if (_optionalChain([output, 'optionalAccess', _199 => _199.ignoreAssets])) {
|
|
5212
5536
|
return new Set(output.ignoreAssets.map(normalizePath));
|
|
5213
5537
|
}
|
|
5214
5538
|
return /* @__PURE__ */ new Set([
|
|
@@ -5289,12 +5613,12 @@ var Helper = (_class3 = class {
|
|
|
5289
5613
|
*/
|
|
5290
5614
|
async formatCode({ code, fileInfo }) {
|
|
5291
5615
|
const { format } = this.compilerOpts;
|
|
5292
|
-
if (!_optionalChain([format, 'optionalAccess',
|
|
5293
|
-
if (_optionalChain([format, 'optionalAccess',
|
|
5616
|
+
if (!_optionalChain([format, 'optionalAccess', _200 => _200.enabled])) return code;
|
|
5617
|
+
if (_optionalChain([format, 'optionalAccess', _201 => _201.formatter]) === "builtin") {
|
|
5294
5618
|
return simpleFormat(code);
|
|
5295
5619
|
}
|
|
5296
|
-
const { lang } = _nullishCoalesce(_optionalChain([fileInfo, 'optionalAccess',
|
|
5297
|
-
return await formatWithPrettier(code, lang, _optionalChain([format, 'optionalAccess',
|
|
5620
|
+
const { lang } = _nullishCoalesce(_optionalChain([fileInfo, 'optionalAccess', _202 => _202.jsx]), () => ( _optionalChain([fileInfo, 'optionalAccess', _203 => _203.script])));
|
|
5621
|
+
return await formatWithPrettier(code, lang, _optionalChain([format, 'optionalAccess', _204 => _204.prettierOptions]));
|
|
5298
5622
|
}
|
|
5299
5623
|
/**
|
|
5300
5624
|
* 通用的缓存校验工具函数
|
|
@@ -5341,7 +5665,7 @@ var Helper = (_class3 = class {
|
|
|
5341
5665
|
target: data[key] || [],
|
|
5342
5666
|
source: data
|
|
5343
5667
|
};
|
|
5344
|
-
} catch (
|
|
5668
|
+
} catch (e11) {
|
|
5345
5669
|
return defaultData;
|
|
5346
5670
|
}
|
|
5347
5671
|
}
|
|
@@ -5427,7 +5751,7 @@ var Helper = (_class3 = class {
|
|
|
5427
5751
|
}
|
|
5428
5752
|
resolveViteCreateApp() {
|
|
5429
5753
|
const { output } = this.compilerOpts;
|
|
5430
|
-
const config = _optionalChain([output, 'optionalAccess',
|
|
5754
|
+
const config = _optionalChain([output, 'optionalAccess', _205 => _205.bootstrapVite]);
|
|
5431
5755
|
const template = typeof config === "object" ? config.template : "react-ts";
|
|
5432
5756
|
const outDirName = this.getOutDirName();
|
|
5433
5757
|
const cmd = `npm create vite@latest ${outDirName} -- --template ${template}`;
|
|
@@ -5441,7 +5765,7 @@ var Helper = (_class3 = class {
|
|
|
5441
5765
|
* 获取需要排除编译的文件
|
|
5442
5766
|
*/
|
|
5443
5767
|
getExcludes() {
|
|
5444
|
-
if (!_optionalChain([this, 'access',
|
|
5768
|
+
if (!_optionalChain([this, 'access', _206 => _206.compilerOpts, 'access', _207 => _207.exclude, 'optionalAccess', _208 => _208.length])) {
|
|
5445
5769
|
return PathFilter.withDefaults();
|
|
5446
5770
|
}
|
|
5447
5771
|
return this.compilerOpts.exclude;
|
|
@@ -5522,7 +5846,7 @@ function parseOnlyStyle(source, ctx, options) {
|
|
|
5522
5846
|
ast: void 0
|
|
5523
5847
|
}
|
|
5524
5848
|
};
|
|
5525
|
-
executePlugins(_optionalChain([options, 'optionalAccess',
|
|
5849
|
+
executePlugins(_optionalChain([options, 'optionalAccess', _209 => _209.plugins]), result, ctx);
|
|
5526
5850
|
return result;
|
|
5527
5851
|
}
|
|
5528
5852
|
|
|
@@ -5556,7 +5880,10 @@ var CompilationContext = (_class4 = class {constructor() { _class4.prototype.__i
|
|
|
5556
5880
|
propField: "$props",
|
|
5557
5881
|
templateData: {
|
|
5558
5882
|
slots: {},
|
|
5559
|
-
refBindings: {
|
|
5883
|
+
refBindings: {
|
|
5884
|
+
domRefs: {},
|
|
5885
|
+
componentRefs: {}
|
|
5886
|
+
},
|
|
5560
5887
|
reactiveBindings: {}
|
|
5561
5888
|
},
|
|
5562
5889
|
scriptData: {
|
|
@@ -5573,6 +5900,10 @@ var CompilationContext = (_class4 = class {constructor() { _class4.prototype.__i
|
|
|
5573
5900
|
emitTypes: [],
|
|
5574
5901
|
slotTypes: []
|
|
5575
5902
|
},
|
|
5903
|
+
forwardRef: {
|
|
5904
|
+
enabled: false,
|
|
5905
|
+
refField: "expose"
|
|
5906
|
+
},
|
|
5576
5907
|
source: ""
|
|
5577
5908
|
},
|
|
5578
5909
|
styleData: {
|
|
@@ -5701,16 +6032,16 @@ var BaseCompiler = (_class5 = class extends Helper {
|
|
|
5701
6032
|
});
|
|
5702
6033
|
const genOptions = this.prepareGenerateOptions(filename);
|
|
5703
6034
|
const resolveSFCAndScriptFile = () => {
|
|
5704
|
-
const ast = parse(source, ctx.data, { plugins: _optionalChain([plugins, 'optionalAccess',
|
|
5705
|
-
const ir = transform(ast, ctx.data, { plugins: _optionalChain([plugins, 'optionalAccess',
|
|
6035
|
+
const ast = parse(source, ctx.data, { plugins: _optionalChain([plugins, 'optionalAccess', _210 => _210.parser]) });
|
|
6036
|
+
const ir = transform(ast, ctx.data, { plugins: _optionalChain([plugins, 'optionalAccess', _211 => _211.transformer]) });
|
|
5706
6037
|
const gen = generate(ir, ctx.data, {
|
|
5707
6038
|
...genOptions,
|
|
5708
|
-
plugins: _optionalChain([plugins, 'optionalAccess',
|
|
6039
|
+
plugins: _optionalChain([plugins, 'optionalAccess', _212 => _212.codegen])
|
|
5709
6040
|
});
|
|
5710
6041
|
return this.resolveMainResult(ir, gen, ctx.data);
|
|
5711
6042
|
};
|
|
5712
6043
|
const resolveStyleFile = () => {
|
|
5713
|
-
const result = parseOnlyStyle(source, ctx.data, { plugins: _optionalChain([plugins, 'optionalAccess',
|
|
6044
|
+
const result = parseOnlyStyle(source, ctx.data, { plugins: _optionalChain([plugins, 'optionalAccess', _213 => _213.parser]) });
|
|
5714
6045
|
return this.resolveStyleResult(result, ctx.data);
|
|
5715
6046
|
};
|
|
5716
6047
|
try {
|
|
@@ -5837,9 +6168,9 @@ var BaseCompiler = (_class5 = class extends Helper {
|
|
|
5837
6168
|
lang
|
|
5838
6169
|
},
|
|
5839
6170
|
css: {
|
|
5840
|
-
file: _optionalChain([styleData, 'optionalAccess',
|
|
5841
|
-
hash: _optionalChain([styleData, 'optionalAccess',
|
|
5842
|
-
code: _optionalChain([ir, 'optionalAccess',
|
|
6171
|
+
file: _optionalChain([styleData, 'optionalAccess', _214 => _214.filePath]),
|
|
6172
|
+
hash: _optionalChain([styleData, 'optionalAccess', _215 => _215.scopeId]),
|
|
6173
|
+
code: _optionalChain([ir, 'optionalAccess', _216 => _216.style])
|
|
5843
6174
|
}
|
|
5844
6175
|
},
|
|
5845
6176
|
...base
|
|
@@ -5913,7 +6244,7 @@ var AssetManager = (_class6 = class {
|
|
|
5913
6244
|
const relativeToRoot = normalizePath(this.fileCompiler.relativePath(p));
|
|
5914
6245
|
const filename = _path2.default.basename(p).toLowerCase();
|
|
5915
6246
|
const ext = _path2.default.extname(p).toLowerCase();
|
|
5916
|
-
if (!_optionalChain([this, 'access',
|
|
6247
|
+
if (!_optionalChain([this, 'access', _217 => _217.fileCompiler, 'access', _218 => _218.options, 'access', _219 => _219.output, 'optionalAccess', _220 => _220.ignoreAssets])) {
|
|
5917
6248
|
const shouldExclude = Array.from(exclusions).some((pattern) => {
|
|
5918
6249
|
if (pattern.endsWith(".")) {
|
|
5919
6250
|
return filename.startsWith(pattern);
|
|
@@ -6050,10 +6381,10 @@ var CleanupManager = class {
|
|
|
6050
6381
|
const removeFn = async (m) => {
|
|
6051
6382
|
if (key === "sfc" /* SFC */) {
|
|
6052
6383
|
const meta = m;
|
|
6053
|
-
if (!_optionalChain([meta, 'optionalAccess',
|
|
6384
|
+
if (!_optionalChain([meta, 'optionalAccess', _221 => _221.output])) return;
|
|
6054
6385
|
const { jsx, css } = meta.output;
|
|
6055
6386
|
await this.fileCompiler.removeOutputFile(jsx.file);
|
|
6056
|
-
if (_optionalChain([css, 'optionalAccess',
|
|
6387
|
+
if (_optionalChain([css, 'optionalAccess', _222 => _222.file])) {
|
|
6057
6388
|
await this.fileCompiler.removeOutputFile(css.file);
|
|
6058
6389
|
}
|
|
6059
6390
|
} else if (key === "script" /* SCRIPT */ || key === "copied" /* ASSET */) {
|
|
@@ -6097,7 +6428,7 @@ var CompilationUnitProcessor = class {
|
|
|
6097
6428
|
const isScriptFile = key === "script" /* SCRIPT */;
|
|
6098
6429
|
const isStyleFile = key === "style" /* STYLE */;
|
|
6099
6430
|
if (isSFC || isScriptFile) {
|
|
6100
|
-
unit.hasRoute = _optionalChain([result, 'optionalAccess',
|
|
6431
|
+
unit.hasRoute = _optionalChain([result, 'optionalAccess', _223 => _223.hasRoute]);
|
|
6101
6432
|
}
|
|
6102
6433
|
const resolveFileInfo = () => {
|
|
6103
6434
|
if (isSFC) {
|
|
@@ -6117,7 +6448,7 @@ var CompilationUnitProcessor = class {
|
|
|
6117
6448
|
const { script } = result.fileInfo;
|
|
6118
6449
|
unit.output = {
|
|
6119
6450
|
script: {
|
|
6120
|
-
file: _optionalChain([script, 'optionalAccess',
|
|
6451
|
+
file: _optionalChain([script, 'optionalAccess', _224 => _224.file]),
|
|
6121
6452
|
code
|
|
6122
6453
|
}
|
|
6123
6454
|
};
|
|
@@ -6197,7 +6528,7 @@ var FileProcessor = (_class7 = class {
|
|
|
6197
6528
|
const absPath = this.fileCompiler.getAbsPath(filePath);
|
|
6198
6529
|
const fileMeta = await this.fileCompiler.getFileMeta(absPath);
|
|
6199
6530
|
const cache = (this.fileCompiler.getIsCache() ? existingCache : void 0) || await this.fileCompiler.loadCache(key);
|
|
6200
|
-
const record = _optionalChain([cache, 'optionalAccess',
|
|
6531
|
+
const record = _optionalChain([cache, 'optionalAccess', _225 => _225.target, 'access', _226 => _226.find, 'call', _227 => _227((c) => c.file === absPath)]);
|
|
6201
6532
|
const { shouldCompile, hash } = await this.fileCompiler.checkCacheStatus(
|
|
6202
6533
|
fileMeta,
|
|
6203
6534
|
record,
|
|
@@ -6216,10 +6547,10 @@ var FileProcessor = (_class7 = class {
|
|
|
6216
6547
|
hash: hash || this.fileCompiler.genHash(source)
|
|
6217
6548
|
};
|
|
6218
6549
|
const processed = await this.compilationUnitProcessor.resolve(initUnit, key);
|
|
6219
|
-
if (_optionalChain([processed, 'optionalAccess',
|
|
6550
|
+
if (_optionalChain([processed, 'optionalAccess', _228 => _228.output])) {
|
|
6220
6551
|
await this.compilationUnitProcessor.saveCompiledFiles(processed, key);
|
|
6221
6552
|
if (key === "sfc" /* SFC */ || key === "script" /* SCRIPT */) {
|
|
6222
|
-
if (_optionalChain([processed, 'optionalAccess',
|
|
6553
|
+
if (_optionalChain([processed, 'optionalAccess', _229 => _229.hasRoute])) {
|
|
6223
6554
|
await this.injectVuReactRouteDep();
|
|
6224
6555
|
}
|
|
6225
6556
|
}
|
|
@@ -6409,7 +6740,7 @@ var ViteBootstrapper = (_class9 = class {
|
|
|
6409
6740
|
*/
|
|
6410
6741
|
resolveViteCreateApp() {
|
|
6411
6742
|
const { output } = this.options;
|
|
6412
|
-
const config = _optionalChain([output, 'optionalAccess',
|
|
6743
|
+
const config = _optionalChain([output, 'optionalAccess', _230 => _230.bootstrapVite]);
|
|
6413
6744
|
const template = typeof config === "object" ? config.template : "react-ts";
|
|
6414
6745
|
const outDirName = this.fileCompiler.getOutDirName();
|
|
6415
6746
|
const cmd = `npm create vite@latest ${outDirName} -- --template ${template}`;
|
|
@@ -6497,7 +6828,7 @@ var FileCompiler = (_class10 = class extends BaseCompiler {
|
|
|
6497
6828
|
this.spinner.start("Copying assets...");
|
|
6498
6829
|
const assetCount = await this.assetManager.runAssetPipeline();
|
|
6499
6830
|
this.spinner.stop();
|
|
6500
|
-
await _optionalChain([this, 'access',
|
|
6831
|
+
await _optionalChain([this, 'access', _231 => _231.options, 'access', _232 => _232.onSuccess, 'optionalCall', _233 => _233()]);
|
|
6501
6832
|
const endTime = calcElapsedTime(startTime);
|
|
6502
6833
|
this.printCoreLogs();
|
|
6503
6834
|
this.showCompileStats(endTime, sfcCount, scriptCount, styleCount, assetCount);
|