solid-optimizer 0.2.0 → 0.3.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.
- package/README.md +269 -14
- package/dist/compile-BroGlagZ.d.mts +172 -0
- package/dist/compile-BroGlagZ.d.mts.map +1 -0
- package/dist/compile-ocDYvJUW.mjs +3910 -0
- package/dist/compile-ocDYvJUW.mjs.map +1 -0
- package/dist/index.d.mts +2 -0
- package/dist/index.mjs +2 -0
- package/dist/vite.d.mts +35 -0
- package/dist/vite.d.mts.map +1 -0
- package/dist/vite.mjs +1465 -0
- package/dist/vite.mjs.map +1 -0
- package/package.json +60 -58
- package/src/ast.ts +263 -0
- package/src/compile.ts +304 -0
- package/src/constants.ts +249 -0
- package/src/context.ts +87 -0
- package/src/fold.ts +850 -0
- package/src/index.ts +4 -107
- package/src/inline.ts +2028 -0
- package/src/jsx.ts +170 -0
- package/src/memo.ts +383 -0
- package/src/provider.ts +842 -0
- package/src/scope.ts +588 -0
- package/src/server.ts +275 -0
- package/src/size.ts +307 -0
- package/src/value.ts +386 -0
- package/src/vite/index.ts +1135 -0
- package/src/vite/inject.ts +311 -0
- package/src/vite/namespace.ts +66 -0
- package/src/vite/runtime.ts +390 -0
- package/src/vite/usage.ts +405 -0
- package/dist/cjs/development/index.cjs +0 -228
- package/dist/cjs/development/index.cjs.map +0 -7
- package/dist/cjs/production/index.cjs +0 -1
- package/dist/esm/development/index.mjs +0 -197
- package/dist/esm/development/index.mjs.map +0 -7
- package/dist/esm/production/index.mjs +0 -1
- package/dist/types/checks.d.ts +0 -9
- package/dist/types/checks.d.ts.map +0 -1
- package/dist/types/index.d.ts +0 -3
- package/dist/types/index.d.ts.map +0 -1
- package/dist/types/path-references-import.d.ts +0 -3
- package/dist/types/path-references-import.d.ts.map +0 -1
- package/dist/types/unwrap-node.d.ts +0 -7
- package/dist/types/unwrap-node.d.ts.map +0 -1
- package/dist/types/unwrap-path.d.ts +0 -6
- package/dist/types/unwrap-path.d.ts.map +0 -1
- package/src/checks.ts +0 -42
- package/src/path-references-import.ts +0 -82
- package/src/unwrap-node.ts +0 -27
- package/src/unwrap-path.ts +0 -18
|
@@ -0,0 +1,405 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Which modules use each export of the app, read from the files on disk.
|
|
3
|
+
*
|
|
4
|
+
* A component copied into the module that uses it is only smaller overall
|
|
5
|
+
* when the original goes away, which takes that module being its only user.
|
|
6
|
+
* The index answers that from the whole module graph, so it does not depend
|
|
7
|
+
* on the order the bundler transforms modules in, and a server build and its
|
|
8
|
+
* client build make the same decisions.
|
|
9
|
+
*
|
|
10
|
+
* Anything the index cannot follow counts as another use: a re-export, a
|
|
11
|
+
* dynamic import, a namespace used as a value, or a use inside the module
|
|
12
|
+
* that declares the export.
|
|
13
|
+
*/
|
|
14
|
+
import type { Node, Program } from 'oxc-parser';
|
|
15
|
+
import { collectParents, forEachChild, parse } from '../ast';
|
|
16
|
+
import type { Parents } from '../ast';
|
|
17
|
+
import type { Binding, ScopeAnalysis } from '../scope';
|
|
18
|
+
import { analyzeScopes } from '../scope';
|
|
19
|
+
|
|
20
|
+
export interface UsageIndex {
|
|
21
|
+
/**
|
|
22
|
+
* How many modules use `exportName` of `module`, counting `user`, when
|
|
23
|
+
* they only use it as JSX tags. `0` when anything else uses it, which
|
|
24
|
+
* keeps it whoever copies it. `absorbed` holds, by module, the exported
|
|
25
|
+
* components that were copied into `user` and leave their module, so the
|
|
26
|
+
* uses inside them count as uses in `user`.
|
|
27
|
+
*/
|
|
28
|
+
users(
|
|
29
|
+
module: string,
|
|
30
|
+
exportName: string,
|
|
31
|
+
user: string,
|
|
32
|
+
absorbed: ReadonlyMap<string, ReadonlySet<string>>,
|
|
33
|
+
): number;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export interface UsageHost {
|
|
37
|
+
/** The id `source` resolves to from `importer`, or `undefined` outside the app. */
|
|
38
|
+
resolve(source: string, importer: string): Promise<string | undefined>;
|
|
39
|
+
/** The code of a module, or `undefined` when it cannot be read. */
|
|
40
|
+
read(id: string): Promise<string | undefined>;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** The name a use counts under when it is not inside an exported declaration. */
|
|
44
|
+
const UNEXPORTED = '';
|
|
45
|
+
|
|
46
|
+
interface ExportUsage {
|
|
47
|
+
/**
|
|
48
|
+
* The modules that use the export as a JSX tag, each with the export
|
|
49
|
+
* names of the top-level declarations the uses sit in.
|
|
50
|
+
*/
|
|
51
|
+
readonly importers: Map<string, Set<string>>;
|
|
52
|
+
/** Whether anything uses it other than as a tag. */
|
|
53
|
+
other: boolean;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const SCRIPT = /\.[mc]?[jt]sx?$/;
|
|
57
|
+
|
|
58
|
+
class Usage implements UsageIndex {
|
|
59
|
+
private readonly exports = new Map<string, ExportUsage>();
|
|
60
|
+
|
|
61
|
+
/** Modules any of whose exports can be used in a way the index does not follow. */
|
|
62
|
+
private readonly opaque = new Set<string>();
|
|
63
|
+
|
|
64
|
+
/** The modules each module imports. */
|
|
65
|
+
readonly imports = new Map<string, readonly string[]>();
|
|
66
|
+
|
|
67
|
+
/** Whether `from` imports `to`, directly or through other modules. */
|
|
68
|
+
private reaches(from: string, to: string): boolean {
|
|
69
|
+
const seen = new Set<string>();
|
|
70
|
+
const stack = [from];
|
|
71
|
+
for (let id = stack.pop(); id !== undefined; id = stack.pop()) {
|
|
72
|
+
if (id === to) {
|
|
73
|
+
return true;
|
|
74
|
+
}
|
|
75
|
+
if (!seen.has(id)) {
|
|
76
|
+
seen.add(id);
|
|
77
|
+
stack.push(...(this.imports.get(id) ?? []));
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return false;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
private entry(module: string, name: string): ExportUsage {
|
|
84
|
+
const key = `${module}\0${name}`;
|
|
85
|
+
let usage = this.exports.get(key);
|
|
86
|
+
if (!usage) {
|
|
87
|
+
usage = { importers: new Map(), other: false };
|
|
88
|
+
this.exports.set(key, usage);
|
|
89
|
+
}
|
|
90
|
+
return usage;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
tag(module: string, name: string, importer: string, containers: readonly string[]): void {
|
|
94
|
+
const { importers } = this.entry(module, name);
|
|
95
|
+
const known = importers.get(importer) ?? new Set();
|
|
96
|
+
for (const container of containers) {
|
|
97
|
+
known.add(container);
|
|
98
|
+
}
|
|
99
|
+
importers.set(importer, known);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
other(module: string, name: string): void {
|
|
103
|
+
this.entry(module, name).other = true;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
all(module: string): void {
|
|
107
|
+
this.opaque.add(module);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
users(
|
|
111
|
+
module: string,
|
|
112
|
+
exportName: string,
|
|
113
|
+
user: string,
|
|
114
|
+
absorbed: ReadonlyMap<string, ReadonlySet<string>>,
|
|
115
|
+
): number {
|
|
116
|
+
if (this.opaque.has(module)) {
|
|
117
|
+
return 0;
|
|
118
|
+
}
|
|
119
|
+
const usage = this.exports.get(`${module}\0${exportName}`);
|
|
120
|
+
if (!usage || usage.other || usage.importers.size === 0) {
|
|
121
|
+
return 0;
|
|
122
|
+
}
|
|
123
|
+
const users = new Set([user]);
|
|
124
|
+
for (const [importer, containers] of usage.importers) {
|
|
125
|
+
const moved = absorbed.get(importer);
|
|
126
|
+
users.add([...containers].every((name) => moved?.has(name) === true) ? user : importer);
|
|
127
|
+
}
|
|
128
|
+
// A module the component's module imports never gets a copy of it, so
|
|
129
|
+
// the original stays for it.
|
|
130
|
+
return [...users].some((id) => this.reaches(module, id)) ? 0 : users.size;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
function isTagName(reference: Node, parents: Parents): boolean {
|
|
135
|
+
const parent = parents.get(reference);
|
|
136
|
+
return parent?.type === 'JSXOpeningElement' && parent.name === reference;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
function isClosingTagName(reference: Node, parents: Parents): boolean {
|
|
140
|
+
const parent = parents.get(reference);
|
|
141
|
+
return parent?.type === 'JSXClosingElement' && parent.name === reference;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/** The names a declaration exported with `export` declares. */
|
|
145
|
+
function declaredNames(declaration: Node | null | undefined): string[] {
|
|
146
|
+
if (declaration?.type === 'FunctionDeclaration' && declaration.id) {
|
|
147
|
+
return [declaration.id.name];
|
|
148
|
+
}
|
|
149
|
+
if (declaration?.type === 'VariableDeclaration') {
|
|
150
|
+
return declaration.declarations.flatMap((declarator) =>
|
|
151
|
+
declarator.id.type === 'Identifier' ? [declarator.id.name] : [],
|
|
152
|
+
);
|
|
153
|
+
}
|
|
154
|
+
return [];
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/** The top-level bindings a module exports, each with its export names. */
|
|
158
|
+
function exportedBindings(program: Program, scopes: ScopeAnalysis): Map<Binding, string[]> {
|
|
159
|
+
const exported = new Map<Binding, string[]>();
|
|
160
|
+
const add = (local: string, name: string): void => {
|
|
161
|
+
const binding = scopes.root.bindings.get(local);
|
|
162
|
+
if (binding) {
|
|
163
|
+
exported.set(binding, [...(exported.get(binding) ?? []), name]);
|
|
164
|
+
}
|
|
165
|
+
};
|
|
166
|
+
for (const statement of program.body) {
|
|
167
|
+
if (statement.type === 'ExportNamedDeclaration' && !statement.source) {
|
|
168
|
+
for (const name of declaredNames(statement.declaration)) {
|
|
169
|
+
add(name, name);
|
|
170
|
+
}
|
|
171
|
+
for (const specifier of statement.specifiers) {
|
|
172
|
+
if (specifier.local.type === 'Identifier') {
|
|
173
|
+
add(
|
|
174
|
+
specifier.local.name,
|
|
175
|
+
specifier.exported.type === 'Identifier'
|
|
176
|
+
? specifier.exported.name
|
|
177
|
+
: specifier.exported.value,
|
|
178
|
+
);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
} else if (statement.type === 'ExportDefaultDeclaration') {
|
|
182
|
+
const { declaration } = statement;
|
|
183
|
+
if (declaration.type === 'FunctionDeclaration' && declaration.id) {
|
|
184
|
+
add(declaration.id.name, 'default');
|
|
185
|
+
} else if (declaration.type === 'Identifier') {
|
|
186
|
+
add(declaration.name, 'default');
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
return exported;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* Records how a module uses what it imports, and the uses of its own
|
|
195
|
+
* exports inside it.
|
|
196
|
+
*/
|
|
197
|
+
function recordModule(
|
|
198
|
+
usage: Usage,
|
|
199
|
+
id: string,
|
|
200
|
+
program: Program,
|
|
201
|
+
targets: ReadonlyMap<string, string>,
|
|
202
|
+
): void {
|
|
203
|
+
const scopes = analyzeScopes(program);
|
|
204
|
+
const parents = collectParents(program);
|
|
205
|
+
|
|
206
|
+
// A module that uses its own export keeps it, whoever else copies it.
|
|
207
|
+
const exported = exportedBindings(program, scopes);
|
|
208
|
+
// The export names of the top-level declaration a use sits in.
|
|
209
|
+
const containersOf = (reference: Node): string[] => {
|
|
210
|
+
let node: Node = reference;
|
|
211
|
+
let parent = parents.get(node);
|
|
212
|
+
while (parent && parent.type !== 'Program') {
|
|
213
|
+
node = parent;
|
|
214
|
+
parent = parents.get(node);
|
|
215
|
+
}
|
|
216
|
+
const declaration =
|
|
217
|
+
(node.type === 'ExportNamedDeclaration' || node.type === 'ExportDefaultDeclaration') &&
|
|
218
|
+
node.declaration
|
|
219
|
+
? node.declaration
|
|
220
|
+
: node;
|
|
221
|
+
const bindings: (Binding | undefined)[] = [];
|
|
222
|
+
if (declaration.type === 'FunctionDeclaration' && declaration.id) {
|
|
223
|
+
bindings.push(scopes.root.bindings.get(declaration.id.name));
|
|
224
|
+
} else if (declaration.type === 'VariableDeclaration') {
|
|
225
|
+
for (const declarator of declaration.declarations) {
|
|
226
|
+
if (
|
|
227
|
+
declarator.id.type === 'Identifier' &&
|
|
228
|
+
reference.start >= declarator.start &&
|
|
229
|
+
reference.end <= declarator.end
|
|
230
|
+
) {
|
|
231
|
+
bindings.push(scopes.root.bindings.get(declarator.id.name));
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
const names = bindings.flatMap((binding) => (binding ? (exported.get(binding) ?? []) : []));
|
|
236
|
+
return names.length > 0 ? names : [UNEXPORTED];
|
|
237
|
+
};
|
|
238
|
+
|
|
239
|
+
const record = (binding: Binding, target: string): void => {
|
|
240
|
+
const imported = binding.imported ?? '*';
|
|
241
|
+
for (const reference of binding.references) {
|
|
242
|
+
if (isClosingTagName(reference, parents)) {
|
|
243
|
+
continue;
|
|
244
|
+
}
|
|
245
|
+
if (imported !== '*') {
|
|
246
|
+
if (isTagName(reference, parents)) {
|
|
247
|
+
usage.tag(target, imported, id, containersOf(reference));
|
|
248
|
+
} else {
|
|
249
|
+
usage.other(target, imported);
|
|
250
|
+
}
|
|
251
|
+
continue;
|
|
252
|
+
}
|
|
253
|
+
// `<Ns.Member>` and `Ns.member` use one export. Anything else may use any.
|
|
254
|
+
const member = parents.get(reference);
|
|
255
|
+
if (member?.type === 'JSXMemberExpression' && member.object === reference) {
|
|
256
|
+
if (isTagName(member, parents)) {
|
|
257
|
+
usage.tag(target, member.property.name, id, containersOf(reference));
|
|
258
|
+
} else {
|
|
259
|
+
usage.other(target, member.property.name);
|
|
260
|
+
}
|
|
261
|
+
} else if (
|
|
262
|
+
member?.type === 'MemberExpression' &&
|
|
263
|
+
member.object === reference &&
|
|
264
|
+
!member.computed &&
|
|
265
|
+
member.property.type === 'Identifier'
|
|
266
|
+
) {
|
|
267
|
+
usage.other(target, member.property.name);
|
|
268
|
+
} else {
|
|
269
|
+
usage.all(target);
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
};
|
|
273
|
+
for (const binding of scopes.root.bindings.values()) {
|
|
274
|
+
if (binding.kind === 'import' && binding.source !== undefined) {
|
|
275
|
+
const target = targets.get(binding.source);
|
|
276
|
+
if (target !== undefined) {
|
|
277
|
+
record(binding, target);
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
// Re-exports pass an export on, which the index does not follow.
|
|
283
|
+
for (const statement of program.body) {
|
|
284
|
+
if (statement.type === 'ExportAllDeclaration') {
|
|
285
|
+
const target = targets.get(statement.source.value);
|
|
286
|
+
if (target !== undefined) {
|
|
287
|
+
usage.all(target);
|
|
288
|
+
}
|
|
289
|
+
} else if (statement.type === 'ExportNamedDeclaration' && statement.source) {
|
|
290
|
+
const target = targets.get(statement.source.value);
|
|
291
|
+
for (const specifier of statement.specifiers) {
|
|
292
|
+
const name =
|
|
293
|
+
specifier.local.type === 'Identifier' ? specifier.local.name : specifier.local.value;
|
|
294
|
+
if (target !== undefined) {
|
|
295
|
+
usage.other(target, name);
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
for (const [binding, names] of exported) {
|
|
302
|
+
const used = binding.references.some((reference) => {
|
|
303
|
+
const parent = parents.get(reference);
|
|
304
|
+
return (
|
|
305
|
+
parent?.type !== 'ExportSpecifier' &&
|
|
306
|
+
parent?.type !== 'ExportDefaultDeclaration' &&
|
|
307
|
+
!isClosingTagName(reference, parents)
|
|
308
|
+
);
|
|
309
|
+
});
|
|
310
|
+
if (used) {
|
|
311
|
+
for (const name of names) {
|
|
312
|
+
usage.other(id, name);
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
/** The import specifiers a module loads, statically or with `import()`. */
|
|
319
|
+
function specifiersOf(program: Program): { static: Set<string>; dynamic: Set<string> } {
|
|
320
|
+
const statics = new Set<string>();
|
|
321
|
+
const dynamics = new Set<string>();
|
|
322
|
+
for (const statement of program.body) {
|
|
323
|
+
if (
|
|
324
|
+
(statement.type === 'ImportDeclaration' && statement.importKind !== 'type') ||
|
|
325
|
+
((statement.type === 'ExportNamedDeclaration' || statement.type === 'ExportAllDeclaration') &&
|
|
326
|
+
statement.source &&
|
|
327
|
+
statement.exportKind !== 'type')
|
|
328
|
+
) {
|
|
329
|
+
const value = statement.source?.value;
|
|
330
|
+
if (value !== undefined) {
|
|
331
|
+
statics.add(value);
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
const visit = (node: Node): void => {
|
|
336
|
+
if (
|
|
337
|
+
node.type === 'ImportExpression' &&
|
|
338
|
+
node.source.type === 'Literal' &&
|
|
339
|
+
typeof node.source.value === 'string'
|
|
340
|
+
) {
|
|
341
|
+
dynamics.add(node.source.value);
|
|
342
|
+
}
|
|
343
|
+
forEachChild(node, visit);
|
|
344
|
+
};
|
|
345
|
+
visit(program);
|
|
346
|
+
return { static: statics, dynamic: dynamics };
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
/**
|
|
350
|
+
* Reads every module reachable from `entries` and records how each export
|
|
351
|
+
* is used.
|
|
352
|
+
*/
|
|
353
|
+
export async function buildUsageIndex(
|
|
354
|
+
entries: readonly string[],
|
|
355
|
+
host: UsageHost,
|
|
356
|
+
): Promise<UsageIndex> {
|
|
357
|
+
const usage = new Usage();
|
|
358
|
+
// An entry's exports are its public API.
|
|
359
|
+
for (const entry of entries) {
|
|
360
|
+
usage.all(entry);
|
|
361
|
+
}
|
|
362
|
+
const seen = new Set<string>();
|
|
363
|
+
let frontier = entries.filter((id) => SCRIPT.test(id.replace(/\?.*$/, '')));
|
|
364
|
+
while (frontier.length > 0) {
|
|
365
|
+
for (const id of frontier) {
|
|
366
|
+
seen.add(id);
|
|
367
|
+
}
|
|
368
|
+
// oxlint-disable-next-line no-await-in-loop
|
|
369
|
+
const next = await Promise.all(
|
|
370
|
+
frontier.map(async (id) => {
|
|
371
|
+
const code = await host.read(id);
|
|
372
|
+
let program: Program;
|
|
373
|
+
try {
|
|
374
|
+
program = parse(id.replace(/\?.*$/, ''), code ?? '');
|
|
375
|
+
} catch {
|
|
376
|
+
return [];
|
|
377
|
+
}
|
|
378
|
+
const { static: statics, dynamic } = specifiersOf(program);
|
|
379
|
+
const targets = new Map<string, string>();
|
|
380
|
+
await Promise.all(
|
|
381
|
+
[...statics, ...dynamic].map(async (source) => {
|
|
382
|
+
const target = await host.resolve(source, id);
|
|
383
|
+
if (target !== undefined) {
|
|
384
|
+
targets.set(source, target);
|
|
385
|
+
}
|
|
386
|
+
}),
|
|
387
|
+
);
|
|
388
|
+
// A module loaded with `import()` is used as a whole.
|
|
389
|
+
for (const source of dynamic) {
|
|
390
|
+
const target = targets.get(source);
|
|
391
|
+
if (target !== undefined) {
|
|
392
|
+
usage.all(target);
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
recordModule(usage, id, program, targets);
|
|
396
|
+
usage.imports.set(id, [...targets.values()]);
|
|
397
|
+
return [...targets.values()];
|
|
398
|
+
}),
|
|
399
|
+
);
|
|
400
|
+
frontier = [...new Set(next.flat())].filter(
|
|
401
|
+
(id) => !seen.has(id) && SCRIPT.test(id.replace(/\?.*$/, '')),
|
|
402
|
+
);
|
|
403
|
+
}
|
|
404
|
+
return usage;
|
|
405
|
+
}
|
|
@@ -1,228 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
-
for (let key of __getOwnPropNames(from))
|
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
|
|
30
|
-
// src/index.ts
|
|
31
|
-
var src_exports = {};
|
|
32
|
-
__export(src_exports, {
|
|
33
|
-
default: () => solidOptimizerPlugin
|
|
34
|
-
});
|
|
35
|
-
module.exports = __toCommonJS(src_exports);
|
|
36
|
-
var t2 = __toESM(require("@babel/types"), 1);
|
|
37
|
-
|
|
38
|
-
// src/path-references-import.ts
|
|
39
|
-
var t = __toESM(require("@babel/types"), 1);
|
|
40
|
-
|
|
41
|
-
// src/checks.ts
|
|
42
|
-
function isPathValid(path, key) {
|
|
43
|
-
return key(path.node);
|
|
44
|
-
}
|
|
45
|
-
function isNestedExpression(node) {
|
|
46
|
-
switch (node.type) {
|
|
47
|
-
case "ParenthesizedExpression":
|
|
48
|
-
case "TypeCastExpression":
|
|
49
|
-
case "TSAsExpression":
|
|
50
|
-
case "TSSatisfiesExpression":
|
|
51
|
-
case "TSNonNullExpression":
|
|
52
|
-
case "TSTypeAssertion":
|
|
53
|
-
case "TSInstantiationExpression":
|
|
54
|
-
return true;
|
|
55
|
-
default:
|
|
56
|
-
return false;
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
// src/unwrap-path.ts
|
|
61
|
-
function unwrapPath(path, key) {
|
|
62
|
-
if (isPathValid(path, key)) {
|
|
63
|
-
return path;
|
|
64
|
-
}
|
|
65
|
-
if (isPathValid(path, isNestedExpression)) {
|
|
66
|
-
return unwrapPath(path.get("expression"), key);
|
|
67
|
-
}
|
|
68
|
-
return void 0;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
// src/path-references-import.ts
|
|
72
|
-
function pathReferencesImportIdentifier(path, moduleSources, importNames) {
|
|
73
|
-
const identifier = unwrapPath(path, t.isIdentifier);
|
|
74
|
-
if (!identifier) {
|
|
75
|
-
return false;
|
|
76
|
-
}
|
|
77
|
-
const binding = path.scope.getBinding(identifier.node.name);
|
|
78
|
-
if (!binding || binding.kind !== "module") {
|
|
79
|
-
return false;
|
|
80
|
-
}
|
|
81
|
-
const importPath = binding.path;
|
|
82
|
-
const importParent = importPath.parentPath;
|
|
83
|
-
if (isPathValid(importParent, t.isImportDeclaration) && moduleSources.includes(importParent.node.source.value)) {
|
|
84
|
-
if (isPathValid(importPath, t.isImportSpecifier)) {
|
|
85
|
-
const key = t.isIdentifier(importPath.node.imported) ? importPath.node.imported.name : importPath.node.imported.value;
|
|
86
|
-
return importNames.includes(key);
|
|
87
|
-
}
|
|
88
|
-
if (isPathValid(importPath, t.isImportDefaultSpecifier)) {
|
|
89
|
-
return importNames.includes("default");
|
|
90
|
-
}
|
|
91
|
-
if (isPathValid(importPath, t.isImportNamespaceSpecifier)) {
|
|
92
|
-
return importNames.includes("*");
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
return false;
|
|
96
|
-
}
|
|
97
|
-
var IMPORT_NAMESPACE = ["*"];
|
|
98
|
-
function pathReferencesImportMember(path, moduleSources, importNames) {
|
|
99
|
-
const memberExpr = unwrapPath(path, t.isMemberExpression) || unwrapPath(path, t.isOptionalMemberExpression);
|
|
100
|
-
if (memberExpr) {
|
|
101
|
-
const object = unwrapPath(memberExpr.get("object"), t.isIdentifier);
|
|
102
|
-
if (!object) {
|
|
103
|
-
return false;
|
|
104
|
-
}
|
|
105
|
-
const property = memberExpr.get("property");
|
|
106
|
-
if (isPathValid(property, t.isIdentifier)) {
|
|
107
|
-
return importNames.includes(property.node.name) && pathReferencesImport(object, moduleSources, IMPORT_NAMESPACE);
|
|
108
|
-
}
|
|
109
|
-
if (isPathValid(property, t.isStringLiteral)) {
|
|
110
|
-
return importNames.includes(property.node.value) && pathReferencesImport(object, moduleSources, IMPORT_NAMESPACE);
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
return false;
|
|
114
|
-
}
|
|
115
|
-
function pathReferencesImport(path, moduleSources, importNames) {
|
|
116
|
-
return pathReferencesImportIdentifier(path, moduleSources, importNames) || pathReferencesImportMember(path, moduleSources, importNames);
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
// src/unwrap-node.ts
|
|
120
|
-
function unwrapNode(node, key) {
|
|
121
|
-
if (key(node)) {
|
|
122
|
-
return node;
|
|
123
|
-
}
|
|
124
|
-
switch (node.type) {
|
|
125
|
-
case "ParenthesizedExpression":
|
|
126
|
-
case "TypeCastExpression":
|
|
127
|
-
case "TSAsExpression":
|
|
128
|
-
case "TSSatisfiesExpression":
|
|
129
|
-
case "TSNonNullExpression":
|
|
130
|
-
case "TSTypeAssertion":
|
|
131
|
-
case "TSInstantiationExpression":
|
|
132
|
-
return unwrapNode(node.expression, key);
|
|
133
|
-
default:
|
|
134
|
-
return void 0;
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
// src/index.ts
|
|
139
|
-
function transformUntrackAndBatch(path) {
|
|
140
|
-
const arg = path.node.arguments[0];
|
|
141
|
-
if (t2.isExpression(arg)) {
|
|
142
|
-
const trueArrow = unwrapNode(arg, t2.isArrowFunctionExpression);
|
|
143
|
-
if (trueArrow) {
|
|
144
|
-
if (t2.isExpression(trueArrow.body)) {
|
|
145
|
-
path.replaceWith(trueArrow.body);
|
|
146
|
-
} else {
|
|
147
|
-
path.replaceWith(t2.callExpression(trueArrow, []));
|
|
148
|
-
}
|
|
149
|
-
return;
|
|
150
|
-
}
|
|
151
|
-
const trueFunc = unwrapNode(arg, t2.isFunctionExpression);
|
|
152
|
-
if (trueFunc) {
|
|
153
|
-
path.replaceWith(trueFunc.body);
|
|
154
|
-
}
|
|
155
|
-
} else if (t2.isSpreadElement(arg)) {
|
|
156
|
-
path.replaceWith(
|
|
157
|
-
t2.callExpression(
|
|
158
|
-
t2.memberExpression(arg.argument, t2.numericLiteral(0), true),
|
|
159
|
-
[]
|
|
160
|
-
)
|
|
161
|
-
);
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
function transformStartTransition(path) {
|
|
165
|
-
const arg = path.node.arguments[0];
|
|
166
|
-
if (t2.isExpression(arg)) {
|
|
167
|
-
const trueArrow = unwrapNode(arg, t2.isArrowFunctionExpression);
|
|
168
|
-
if (trueArrow) {
|
|
169
|
-
if (t2.isExpression(trueArrow.body)) {
|
|
170
|
-
path.replaceWith(trueArrow.body);
|
|
171
|
-
} else {
|
|
172
|
-
path.replaceWith(t2.callExpression(trueArrow, []));
|
|
173
|
-
}
|
|
174
|
-
return;
|
|
175
|
-
}
|
|
176
|
-
const trueFunc = unwrapNode(arg, t2.isFunctionExpression);
|
|
177
|
-
if (trueFunc) {
|
|
178
|
-
path.replaceWith(trueFunc.body);
|
|
179
|
-
}
|
|
180
|
-
} else if (t2.isSpreadElement(arg)) {
|
|
181
|
-
path.replaceWith(
|
|
182
|
-
t2.callExpression(
|
|
183
|
-
t2.memberExpression(arg.argument, t2.numericLiteral(0), true),
|
|
184
|
-
[]
|
|
185
|
-
)
|
|
186
|
-
);
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
function transformCreateDeferred(path) {
|
|
190
|
-
const arg = path.node.arguments[0];
|
|
191
|
-
if (t2.isExpression(arg)) {
|
|
192
|
-
path.replaceWith(arg);
|
|
193
|
-
} else if (t2.isSpreadElement(arg)) {
|
|
194
|
-
path.replaceWith(
|
|
195
|
-
t2.memberExpression(arg.argument, t2.numericLiteral(0), true)
|
|
196
|
-
);
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
var MODULES = ["solid-js", "solid-js/web"];
|
|
200
|
-
function transformCallExpression(path) {
|
|
201
|
-
const callee = path.get("callee");
|
|
202
|
-
if (pathReferencesImport(callee, MODULES, ["createEffect", "onMount"])) {
|
|
203
|
-
path.remove();
|
|
204
|
-
} else if (pathReferencesImport(callee, MODULES, ["getListener"])) {
|
|
205
|
-
path.replaceWith(t2.nullLiteral());
|
|
206
|
-
} else if (pathReferencesImport(callee, MODULES, ["untrack", "batch"])) {
|
|
207
|
-
transformUntrackAndBatch(path);
|
|
208
|
-
} else if (pathReferencesImport(callee, MODULES, ["startTransition"])) {
|
|
209
|
-
transformStartTransition(path);
|
|
210
|
-
} else if (pathReferencesImport(callee, MODULES, ["createDeferred"])) {
|
|
211
|
-
transformCreateDeferred(path);
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
function solidOptimizerPlugin() {
|
|
215
|
-
return {
|
|
216
|
-
name: "solid-optimizer",
|
|
217
|
-
visitor: {
|
|
218
|
-
Program(program) {
|
|
219
|
-
program.traverse({
|
|
220
|
-
CallExpression(path) {
|
|
221
|
-
transformCallExpression(path);
|
|
222
|
-
}
|
|
223
|
-
});
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
};
|
|
227
|
-
}
|
|
228
|
-
//# sourceMappingURL=index.cjs.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../src/index.ts", "../../../src/path-references-import.ts", "../../../src/checks.ts", "../../../src/unwrap-path.ts", "../../../src/unwrap-node.ts"],
|
|
4
|
-
"sourcesContent": ["import type { NodePath, PluginObj } from '@babel/core';\nimport * as t from '@babel/types';\nimport { pathReferencesImport } from './path-references-import';\nimport unwrapNode from './unwrap-node';\n\nfunction transformUntrackAndBatch(path: NodePath<t.CallExpression>): void {\n // https://github.com/solidjs/solid/blob/41fa6c14b4bf71eed593303cd63b32d53e3515e9/packages/solid/src/server/reactive.ts#L130-L134\n const arg = path.node.arguments[0];\n if (t.isExpression(arg)) {\n const trueArrow = unwrapNode(arg, t.isArrowFunctionExpression);\n if (trueArrow) {\n if (t.isExpression(trueArrow.body)) {\n path.replaceWith(trueArrow.body);\n } else {\n path.replaceWith(t.callExpression(trueArrow, []));\n }\n return;\n }\n const trueFunc = unwrapNode(arg, t.isFunctionExpression);\n if (trueFunc) {\n path.replaceWith(trueFunc.body);\n }\n } else if (t.isSpreadElement(arg)) {\n path.replaceWith(\n t.callExpression(\n t.memberExpression(arg.argument, t.numericLiteral(0), true),\n [],\n ),\n );\n }\n}\n\nfunction transformStartTransition(path: NodePath<t.CallExpression>): void {\n // https://github.com/solidjs/solid/blob/main/packages/solid/src/server/rendering.ts#L488\n const arg = path.node.arguments[0];\n if (t.isExpression(arg)) {\n const trueArrow = unwrapNode(arg, t.isArrowFunctionExpression);\n if (trueArrow) {\n if (t.isExpression(trueArrow.body)) {\n path.replaceWith(trueArrow.body);\n } else {\n path.replaceWith(t.callExpression(trueArrow, []));\n }\n return;\n }\n const trueFunc = unwrapNode(arg, t.isFunctionExpression);\n if (trueFunc) {\n path.replaceWith(trueFunc.body);\n }\n } else if (t.isSpreadElement(arg)) {\n path.replaceWith(\n t.callExpression(\n t.memberExpression(arg.argument, t.numericLiteral(0), true),\n [],\n ),\n );\n }\n}\n\nfunction transformCreateDeferred(path: NodePath<t.CallExpression>): void {\n // https://github.com/solidjs/solid/blob/main/packages/solid/src/server/reactive.ts#L99\n const arg = path.node.arguments[0];\n if (t.isExpression(arg)) {\n path.replaceWith(arg);\n } else if (t.isSpreadElement(arg)) {\n path.replaceWith(\n t.memberExpression(arg.argument, t.numericLiteral(0), true),\n );\n }\n}\n\nconst MODULES = ['solid-js', 'solid-js/web'];\n\nfunction transformCallExpression(path: NodePath<t.CallExpression>): void {\n const callee = path.get('callee');\n\n if (pathReferencesImport(callee, MODULES, ['createEffect', 'onMount'])) {\n // https://github.com/solidjs/solid/blob/41fa6c14b4bf71eed593303cd63b32d53e3515e9/packages/solid/src/server/reactive.ts#L101\n // https://github.com/solidjs/solid/blob/41fa6c14b4bf71eed593303cd63b32d53e3515e9/packages/solid/src/server/reactive.ts#L154\n // Just remove it\n path.remove();\n } else if (pathReferencesImport(callee, MODULES, ['getListener'])) {\n // https://github.com/solidjs/solid/blob/41fa6c14b4bf71eed593303cd63b32d53e3515e9/packages/solid/src/server/reactive.ts#L188\n path.replaceWith(t.nullLiteral());\n } else if (pathReferencesImport(callee, MODULES, ['untrack', 'batch'])) {\n transformUntrackAndBatch(path);\n } else if (pathReferencesImport(callee, MODULES, ['startTransition'])) {\n transformStartTransition(path);\n } else if (pathReferencesImport(callee, MODULES, ['createDeferred'])) {\n transformCreateDeferred(path);\n }\n}\n\nexport default function solidOptimizerPlugin(): PluginObj {\n return {\n name: 'solid-optimizer',\n visitor: {\n Program(program) {\n program.traverse({\n CallExpression(path): void {\n transformCallExpression(path);\n },\n });\n },\n },\n };\n}\n", "import type { NodePath } from '@babel/core';\nimport * as t from '@babel/types';\nimport { isPathValid } from './checks';\nimport unwrapPath from './unwrap-path';\n\nfunction pathReferencesImportIdentifier(\n path: NodePath,\n moduleSources: string[],\n importNames: string[],\n): boolean {\n const identifier = unwrapPath(path, t.isIdentifier);\n if (!identifier) {\n return false;\n }\n const binding = path.scope.getBinding(identifier.node.name);\n if (!binding || binding.kind !== 'module') {\n return false;\n }\n const importPath = binding.path;\n const importParent = importPath.parentPath;\n if (\n isPathValid(importParent, t.isImportDeclaration) &&\n moduleSources.includes(importParent.node.source.value)\n ) {\n if (isPathValid(importPath, t.isImportSpecifier)) {\n const key = t.isIdentifier(importPath.node.imported)\n ? importPath.node.imported.name\n : importPath.node.imported.value;\n return importNames.includes(key);\n }\n if (isPathValid(importPath, t.isImportDefaultSpecifier)) {\n return importNames.includes('default');\n }\n if (isPathValid(importPath, t.isImportNamespaceSpecifier)) {\n return importNames.includes('*');\n }\n }\n return false;\n}\n\nconst IMPORT_NAMESPACE = ['*'];\n\nfunction pathReferencesImportMember(\n path: NodePath,\n moduleSources: string[],\n importNames: string[],\n): boolean {\n const memberExpr =\n unwrapPath(path, t.isMemberExpression) ||\n unwrapPath(path, t.isOptionalMemberExpression);\n if (memberExpr) {\n const object = unwrapPath(memberExpr.get('object'), t.isIdentifier);\n if (!object) {\n return false;\n }\n const property = memberExpr.get('property');\n if (isPathValid(property, t.isIdentifier)) {\n return (\n importNames.includes(property.node.name) &&\n pathReferencesImport(object, moduleSources, IMPORT_NAMESPACE)\n );\n }\n if (isPathValid(property, t.isStringLiteral)) {\n return (\n importNames.includes(property.node.value) &&\n pathReferencesImport(object, moduleSources, IMPORT_NAMESPACE)\n );\n }\n }\n return false;\n}\n\nexport function pathReferencesImport(\n path: NodePath,\n moduleSources: string[],\n importNames: string[],\n): boolean {\n return (\n pathReferencesImportIdentifier(path, moduleSources, importNames) ||\n pathReferencesImportMember(path, moduleSources, importNames)\n );\n}\n", "import type * as babel from '@babel/core';\nimport type * as t from '@babel/types';\n\nexport function getImportSpecifierKey(specifier: t.ImportSpecifier): string {\n if (specifier.imported.type === 'Identifier') {\n return specifier.imported.name;\n }\n return specifier.imported.value;\n}\n\ntype TypeFilter<V extends t.Node> = (node: t.Node) => node is V;\n\nexport function isPathValid<V extends t.Node>(\n path: unknown,\n key: TypeFilter<V>,\n): path is babel.NodePath<V> {\n return key((path as babel.NodePath).node);\n}\n\nexport type NestedExpression =\n | t.ParenthesizedExpression\n | t.TypeCastExpression\n | t.TSAsExpression\n | t.TSSatisfiesExpression\n | t.TSNonNullExpression\n | t.TSInstantiationExpression\n | t.TSTypeAssertion;\n\nexport function isNestedExpression(node: t.Node): node is NestedExpression {\n switch (node.type) {\n case 'ParenthesizedExpression':\n case 'TypeCastExpression':\n case 'TSAsExpression':\n case 'TSSatisfiesExpression':\n case 'TSNonNullExpression':\n case 'TSTypeAssertion':\n case 'TSInstantiationExpression':\n return true;\n default:\n return false;\n }\n}", "import type * as babel from '@babel/core';\nimport type * as t from '@babel/types';\nimport { isNestedExpression, isPathValid } from './checks';\n\ntype TypeFilter<V extends t.Node> = (node: t.Node) => node is V;\n\nexport default function unwrapPath<V extends t.Node>(\n path: unknown,\n key: TypeFilter<V>,\n): babel.NodePath<V> | undefined {\n if (isPathValid(path, key)) {\n return path;\n }\n if (isPathValid(path, isNestedExpression)) {\n return unwrapPath(path.get('expression'), key);\n }\n return undefined;\n}\n", "import type * as t from '@babel/types';\n\ntype BroadTypeFilter<K extends t.Node> = (node: t.Node) => node is K;\ntype TypeCheck<K> = K extends BroadTypeFilter<infer U> ? U : never;\n\ntype TypeFilter = (node: t.Node) => boolean;\n\nexport default function unwrapNode<K extends TypeFilter>(\n node: t.Node,\n key: K,\n): TypeCheck<K> | undefined {\n if (key(node)) {\n return node as TypeCheck<K>;\n }\n switch (node.type) {\n case 'ParenthesizedExpression':\n case 'TypeCastExpression':\n case 'TSAsExpression':\n case 'TSSatisfiesExpression':\n case 'TSNonNullExpression':\n case 'TSTypeAssertion':\n case 'TSInstantiationExpression':\n return unwrapNode(node.expression, key);\n default:\n return undefined;\n }\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,IAAAA,KAAmB;;;ACAnB,QAAmB;;;ACWZ,SAAS,YACd,MACA,KAC2B;AAC3B,SAAO,IAAK,KAAwB,IAAI;AAC1C;AAWO,SAAS,mBAAmB,MAAwC;AACzE,UAAQ,KAAK,MAAM;AAAA,IACjB,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK;AACH,aAAO;AAAA,IACT;AACE,aAAO;AAAA,E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C,WAAW,OAAO,CAAC,GAAG;AACtE,6BAAyB,IAAI;AAAA,EAC/B,WAAW,qBAAqB,QAAQ,SAAS,CAAC,iBAAiB,CAAC,GAAG;AACrE,6BAAyB,IAAI;AAAA,EAC/B,WAAW,qBAAqB,QAAQ,SAAS,CAAC,gBAAgB,CAAC,GAAG;AACpE,4BAAwB,IAAI;AAAA,EAC9B;AACF;AAEe,SAAR,uBAAmD;AACxD,SAAO;AAAA,IACL,MAAM;AAAA,IACN,SAAS;AAAA,MACP,QAAQ,SAAS;AACf,gBAAQ,SAAS;AAAA,UACf,eAAe,MAAY;AACzB,oCAAwB,IAAI;AAAA,UAC9B;AAAA,QACF,CAAC;AAAA,MACH;AAAA,IACF;AAAA,EACF;AACF;",
|
|
6
|
-
"names": ["t"]
|
|
7
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";var g=Object.create;var u=Object.defineProperty;var P=Object.getOwnPropertyDescriptor;var S=Object.getOwnPropertyNames;var h=Object.getPrototypeOf,I=Object.prototype.hasOwnProperty;var C=(e,t)=>{for(var i in t)u(e,i,{get:t[i],enumerable:!0})},x=(e,t,i,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of S(t))!I.call(e,o)&&o!==i&&u(e,o,{get:()=>t[o],enumerable:!(s=P(t,o))||s.enumerable});return e};var E=(e,t,i)=>(i=e!=null?g(h(e)):{},x(t||!e||!e.__esModule?u(i,"default",{value:e,enumerable:!0}):i,e)),F=e=>x(u({},"__esModule",{value:!0}),e);var k={};C(k,{default:()=>T});module.exports=F(k);var r=E(require("@babel/types"),1);var n=E(require("@babel/types"),1);function p(e,t){return t(e.node)}function b(e){switch(e.type){case"ParenthesizedExpression":case"TypeCastExpression":case"TSAsExpression":case"TSSatisfiesExpression":case"TSNonNullExpression":case"TSTypeAssertion":case"TSInstantiationExpression":return!0;default:return!1}}function d(e,t){if(p(e,t))return e;if(p(e,b))return d(e.get("expression"),t)}function v(e,t,i){let s=d(e,n.isIdentifier);if(!s)return!1;let o=e.scope.getBinding(s.node.name);if(!o||o.kind!=="module")return!1;let a=o.path,m=a.parentPath;if(p(m,n.isImportDeclaration)&&t.includes(m.node.source.value)){if(p(a,n.isImportSpecifier)){let N=n.isIdentifier(a.node.imported)?a.node.imported.name:a.node.imported.value;return i.includes(N)}if(p(a,n.isImportDefaultSpecifier))return i.includes("default");if(p(a,n.isImportNamespaceSpecifier))return i.includes("*")}return!1}var y=["*"];function w(e,t,i){let s=d(e,n.isMemberExpression)||d(e,n.isOptionalMemberExpression);if(s){let o=d(s.get("object"),n.isIdentifier);if(!o)return!1;let a=s.get("property");if(p(a,n.isIdentifier))return i.includes(a.node.name)&&l(o,t,y);if(p(a,n.isStringLiteral))return i.includes(a.node.value)&&l(o,t,y)}return!1}function l(e,t,i){return v(e,t,i)||w(e,t,i)}function c(e,t){if(t(e))return e;switch(e.type){case"ParenthesizedExpression":case"TypeCastExpression":case"TSAsExpression":case"TSSatisfiesExpression":case"TSNonNullExpression":case"TSTypeAssertion":case"TSInstantiationExpression":return c(e.expression,t);default:return}}function A(e){let t=e.node.arguments[0];if(r.isExpression(t)){let i=c(t,r.isArrowFunctionExpression);if(i){r.isExpression(i.body)?e.replaceWith(i.body):e.replaceWith(r.callExpression(i,[]));return}let s=c(t,r.isFunctionExpression);s&&e.replaceWith(s.body)}else r.isSpreadElement(t)&&e.replaceWith(r.callExpression(r.memberExpression(t.argument,r.numericLiteral(0),!0),[]))}function V(e){let t=e.node.arguments[0];if(r.isExpression(t)){let i=c(t,r.isArrowFunctionExpression);if(i){r.isExpression(i.body)?e.replaceWith(i.body):e.replaceWith(r.callExpression(i,[]));return}let s=c(t,r.isFunctionExpression);s&&e.replaceWith(s.body)}else r.isSpreadElement(t)&&e.replaceWith(r.callExpression(r.memberExpression(t.argument,r.numericLiteral(0),!0),[]))}function W(e){let t=e.node.arguments[0];r.isExpression(t)?e.replaceWith(t):r.isSpreadElement(t)&&e.replaceWith(r.memberExpression(t.argument,r.numericLiteral(0),!0))}var f=["solid-js","solid-js/web"];function K(e){let t=e.get("callee");l(t,f,["createEffect","onMount"])?e.remove():l(t,f,["getListener"])?e.replaceWith(r.nullLiteral()):l(t,f,["untrack","batch"])?A(e):l(t,f,["startTransition"])?V(e):l(t,f,["createDeferred"])&&W(e)}function T(){return{name:"solid-optimizer",visitor:{Program(e){e.traverse({CallExpression(t){K(t)}})}}}}
|