@vixt/react 0.11.2 → 0.12.0

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.
@@ -1,370 +0,0 @@
1
- import { y as parse$1 } from "./dist-CoEoJGXV.mjs";
2
- import { n as getMagicString } from "./components-Dsb3rw2n.mjs";
3
- //#region ../../node_modules/.pnpm/estree-walker@3.0.3/node_modules/estree-walker/src/walker.js
4
- /**
5
- * @typedef { import('estree').Node} Node
6
- * @typedef {{
7
- * skip: () => void;
8
- * remove: () => void;
9
- * replace: (node: Node) => void;
10
- * }} WalkerContext
11
- */
12
- var WalkerBase = class {
13
- constructor() {
14
- /** @type {boolean} */
15
- this.should_skip = false;
16
- /** @type {boolean} */
17
- this.should_remove = false;
18
- /** @type {Node | null} */
19
- this.replacement = null;
20
- /** @type {WalkerContext} */
21
- this.context = {
22
- skip: () => this.should_skip = true,
23
- remove: () => this.should_remove = true,
24
- replace: (node) => this.replacement = node
25
- };
26
- }
27
- /**
28
- * @template {Node} Parent
29
- * @param {Parent | null | undefined} parent
30
- * @param {keyof Parent | null | undefined} prop
31
- * @param {number | null | undefined} index
32
- * @param {Node} node
33
- */
34
- replace(parent, prop, index, node) {
35
- if (parent && prop) if (index != null)
36
- /** @type {Array<Node>} */ parent[prop][index] = node;
37
- else
38
- /** @type {Node} */ parent[prop] = node;
39
- }
40
- /**
41
- * @template {Node} Parent
42
- * @param {Parent | null | undefined} parent
43
- * @param {keyof Parent | null | undefined} prop
44
- * @param {number | null | undefined} index
45
- */
46
- remove(parent, prop, index) {
47
- if (parent && prop) if (index !== null && index !== void 0)
48
- /** @type {Array<Node>} */ parent[prop].splice(index, 1);
49
- else delete parent[prop];
50
- }
51
- };
52
- //#endregion
53
- //#region ../../node_modules/.pnpm/estree-walker@3.0.3/node_modules/estree-walker/src/sync.js
54
- /**
55
- * @typedef { import('estree').Node} Node
56
- * @typedef { import('./walker.js').WalkerContext} WalkerContext
57
- * @typedef {(
58
- * this: WalkerContext,
59
- * node: Node,
60
- * parent: Node | null,
61
- * key: string | number | symbol | null | undefined,
62
- * index: number | null | undefined
63
- * ) => void} SyncHandler
64
- */
65
- var SyncWalker = class extends WalkerBase {
66
- /**
67
- *
68
- * @param {SyncHandler} [enter]
69
- * @param {SyncHandler} [leave]
70
- */
71
- constructor(enter, leave) {
72
- super();
73
- /** @type {boolean} */
74
- this.should_skip = false;
75
- /** @type {boolean} */
76
- this.should_remove = false;
77
- /** @type {Node | null} */
78
- this.replacement = null;
79
- /** @type {WalkerContext} */
80
- this.context = {
81
- skip: () => this.should_skip = true,
82
- remove: () => this.should_remove = true,
83
- replace: (node) => this.replacement = node
84
- };
85
- /** @type {SyncHandler | undefined} */
86
- this.enter = enter;
87
- /** @type {SyncHandler | undefined} */
88
- this.leave = leave;
89
- }
90
- /**
91
- * @template {Node} Parent
92
- * @param {Node} node
93
- * @param {Parent | null} parent
94
- * @param {keyof Parent} [prop]
95
- * @param {number | null} [index]
96
- * @returns {Node | null}
97
- */
98
- visit(node, parent, prop, index) {
99
- if (node) {
100
- if (this.enter) {
101
- const _should_skip = this.should_skip;
102
- const _should_remove = this.should_remove;
103
- const _replacement = this.replacement;
104
- this.should_skip = false;
105
- this.should_remove = false;
106
- this.replacement = null;
107
- this.enter.call(this.context, node, parent, prop, index);
108
- if (this.replacement) {
109
- node = this.replacement;
110
- this.replace(parent, prop, index, node);
111
- }
112
- if (this.should_remove) this.remove(parent, prop, index);
113
- const skipped = this.should_skip;
114
- const removed = this.should_remove;
115
- this.should_skip = _should_skip;
116
- this.should_remove = _should_remove;
117
- this.replacement = _replacement;
118
- if (skipped) return node;
119
- if (removed) return null;
120
- }
121
- /** @type {keyof Node} */
122
- let key;
123
- for (key in node) {
124
- /** @type {unknown} */
125
- const value = node[key];
126
- if (value && typeof value === "object") {
127
- if (Array.isArray(value)) {
128
- const nodes = value;
129
- for (let i = 0; i < nodes.length; i += 1) {
130
- const item = nodes[i];
131
- if (isNode(item)) {
132
- if (!this.visit(item, node, key, i)) i--;
133
- }
134
- }
135
- } else if (isNode(value)) this.visit(value, node, key, null);
136
- }
137
- }
138
- if (this.leave) {
139
- const _replacement = this.replacement;
140
- const _should_remove = this.should_remove;
141
- this.replacement = null;
142
- this.should_remove = false;
143
- this.leave.call(this.context, node, parent, prop, index);
144
- if (this.replacement) {
145
- node = this.replacement;
146
- this.replace(parent, prop, index, node);
147
- }
148
- if (this.should_remove) this.remove(parent, prop, index);
149
- const removed = this.should_remove;
150
- this.replacement = _replacement;
151
- this.should_remove = _should_remove;
152
- if (removed) return null;
153
- }
154
- }
155
- return node;
156
- }
157
- };
158
- /**
159
- * Ducktype a node.
160
- *
161
- * @param {unknown} value
162
- * @returns {value is Node}
163
- */
164
- function isNode(value) {
165
- return value !== null && typeof value === "object" && "type" in value && typeof value.type === "string";
166
- }
167
- //#endregion
168
- //#region ../../node_modules/.pnpm/estree-walker@3.0.3/node_modules/estree-walker/src/index.js
169
- /**
170
- * @typedef {import('estree').Node} Node
171
- * @typedef {import('./sync.js').SyncHandler} SyncHandler
172
- * @typedef {import('./async.js').AsyncHandler} AsyncHandler
173
- */
174
- /**
175
- * @param {Node} ast
176
- * @param {{
177
- * enter?: SyncHandler
178
- * leave?: SyncHandler
179
- * }} walker
180
- * @returns {Node | null}
181
- */
182
- function walk(ast, { enter, leave }) {
183
- return new SyncWalker(enter, leave).visit(ast, null);
184
- }
185
- //#endregion
186
- //#region ../../node_modules/.pnpm/unimport@5.6.0/node_modules/unimport/dist/chunks/detect-acorn.mjs
187
- async function detectImportsAcorn(code, ctx, options) {
188
- const s = getMagicString(code);
189
- const map = await ctx.getImportMap();
190
- let matchedImports = [];
191
- const enableAutoImport = options?.autoImport !== false;
192
- const enableTransformVirtualImports = options?.transformVirtualImports !== false && ctx.options.virtualImports?.length;
193
- if (enableAutoImport || enableTransformVirtualImports) {
194
- const ast = parse$1(s.original, {
195
- sourceType: "module",
196
- ecmaVersion: "latest",
197
- locations: true
198
- });
199
- const virtualImports = createVirtualImportsAcronWalker(map, ctx.options.virtualImports);
200
- const scopes = traveseScopes(ast, enableTransformVirtualImports ? virtualImports.walk : {});
201
- if (enableAutoImport) {
202
- const identifiers = scopes.unmatched;
203
- matchedImports.push(...Array.from(identifiers).map((name) => {
204
- const item = map.get(name);
205
- if (item && !item.disabled) return item;
206
- return null;
207
- }).filter(Boolean));
208
- for (const addon of ctx.addons) matchedImports = await addon.matchImports?.call(ctx, identifiers, matchedImports) || matchedImports;
209
- }
210
- virtualImports.ranges.forEach(([start, end]) => {
211
- s.remove(start, end);
212
- });
213
- matchedImports.push(...virtualImports.imports);
214
- }
215
- return {
216
- s,
217
- strippedCode: code.toString(),
218
- matchedImports,
219
- isCJSContext: false,
220
- firstOccurrence: 0
221
- };
222
- }
223
- function traveseScopes(ast, additionalWalk) {
224
- const scopes = [];
225
- let scopeCurrent = void 0;
226
- const scopesStack = [];
227
- function pushScope(node) {
228
- scopeCurrent = {
229
- node,
230
- parent: scopeCurrent,
231
- declarations: /* @__PURE__ */ new Set(),
232
- references: /* @__PURE__ */ new Set()
233
- };
234
- scopes.push(scopeCurrent);
235
- scopesStack.push(scopeCurrent);
236
- }
237
- function popScope(node) {
238
- if (scopesStack.pop()?.node !== node) throw new Error("Scope mismatch");
239
- scopeCurrent = scopesStack[scopesStack.length - 1];
240
- }
241
- pushScope(void 0);
242
- walk(ast, {
243
- enter(node, parent, prop, index) {
244
- additionalWalk?.enter?.call(this, node, parent, prop, index);
245
- switch (node.type) {
246
- case "ImportSpecifier":
247
- case "ImportDefaultSpecifier":
248
- case "ImportNamespaceSpecifier":
249
- scopeCurrent.declarations.add(node.local.name);
250
- return;
251
- case "FunctionDeclaration":
252
- case "ClassDeclaration":
253
- if (node.id) scopeCurrent.declarations.add(node.id.name);
254
- return;
255
- case "VariableDeclarator":
256
- if (node.id.type === "Identifier") scopeCurrent.declarations.add(node.id.name);
257
- else walk(node.id, { enter(node2) {
258
- if (node2.type === "ObjectPattern") node2.properties.forEach((i) => {
259
- if (i.type === "Property" && i.value.type === "Identifier") scopeCurrent.declarations.add(i.value.name);
260
- else if (i.type === "RestElement" && i.argument.type === "Identifier") scopeCurrent.declarations.add(i.argument.name);
261
- });
262
- else if (node2.type === "ArrayPattern") node2.elements.forEach((i) => {
263
- if (i?.type === "Identifier") scopeCurrent.declarations.add(i.name);
264
- if (i?.type === "RestElement" && i.argument.type === "Identifier") scopeCurrent.declarations.add(i.argument.name);
265
- });
266
- } });
267
- return;
268
- case "BlockStatement":
269
- switch (parent?.type) {
270
- case "FunctionDeclaration":
271
- case "ArrowFunctionExpression":
272
- case "FunctionExpression": {
273
- const parameterIdentifiers = parent.params.filter((p) => p.type === "Identifier");
274
- for (const id of parameterIdentifiers) scopeCurrent.declarations.add(id.name);
275
- break;
276
- }
277
- }
278
- pushScope(node);
279
- return;
280
- case "Identifier":
281
- switch (parent?.type) {
282
- case "CallExpression":
283
- if (parent.callee === node || parent.arguments.includes(node)) scopeCurrent.references.add(node.name);
284
- return;
285
- case "MemberExpression":
286
- if (parent.object === node) scopeCurrent.references.add(node.name);
287
- return;
288
- case "VariableDeclarator":
289
- if (parent.init === node) scopeCurrent.references.add(node.name);
290
- return;
291
- case "SpreadElement":
292
- if (parent.argument === node) scopeCurrent.references.add(node.name);
293
- return;
294
- case "ClassDeclaration":
295
- if (parent.superClass === node) scopeCurrent.references.add(node.name);
296
- return;
297
- case "Property":
298
- if (parent.value === node) scopeCurrent.references.add(node.name);
299
- return;
300
- case "TemplateLiteral":
301
- if (parent.expressions.includes(node)) scopeCurrent.references.add(node.name);
302
- return;
303
- case "AssignmentExpression":
304
- if (parent.right === node) scopeCurrent.references.add(node.name);
305
- return;
306
- case "IfStatement":
307
- case "WhileStatement":
308
- case "DoWhileStatement":
309
- if (parent.test === node) scopeCurrent.references.add(node.name);
310
- return;
311
- case "SwitchStatement":
312
- if (parent.discriminant === node) scopeCurrent.references.add(node.name);
313
- return;
314
- }
315
- if (parent?.type.includes("Expression")) scopeCurrent.references.add(node.name);
316
- }
317
- },
318
- leave(node, parent, prop, index) {
319
- additionalWalk?.leave?.call(this, node, parent, prop, index);
320
- switch (node.type) {
321
- case "BlockStatement": popScope(node);
322
- }
323
- }
324
- });
325
- const unmatched = /* @__PURE__ */ new Set();
326
- for (const scope of scopes) for (const name of scope.references) {
327
- let defined = false;
328
- let parent = scope;
329
- while (parent) {
330
- if (parent.declarations.has(name)) {
331
- defined = true;
332
- break;
333
- }
334
- parent = parent?.parent;
335
- }
336
- if (!defined) unmatched.add(name);
337
- }
338
- return {
339
- unmatched,
340
- scopes
341
- };
342
- }
343
- function createVirtualImportsAcronWalker(importMap, virtualImports = []) {
344
- const imports = [];
345
- const ranges = [];
346
- return {
347
- imports,
348
- ranges,
349
- walk: { enter(node) {
350
- if (node.type === "ImportDeclaration") {
351
- if (virtualImports.includes(node.source.value)) {
352
- ranges.push([node.start, node.end]);
353
- node.specifiers.forEach((i) => {
354
- if (i.type === "ImportSpecifier" && i.imported.type === "Identifier") {
355
- const original = importMap.get(i.imported.name);
356
- if (!original) throw new Error(`[unimport] failed to find "${i.imported.name}" imported from "${node.source.value}"`);
357
- imports.push({
358
- from: original.from,
359
- name: original.name,
360
- as: i.local.name
361
- });
362
- }
363
- });
364
- }
365
- }
366
- } }
367
- };
368
- }
369
- //#endregion
370
- export { detectImportsAcorn };