solid-optimizer 1.0.0-next.4 → 1.0.0-next.5
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 +2 -1
- package/dist/{compile-Dx577-sp.mjs → compile-By9Fecbx.mjs} +611 -147
- package/dist/compile-By9Fecbx.mjs.map +1 -0
- package/dist/{compile-CwH9mvHD.d.mts → compile-X_SMDFr2.d.mts} +9 -1
- package/dist/compile-X_SMDFr2.d.mts.map +1 -0
- package/dist/index.d.mts +1 -1
- package/dist/index.mjs +1 -1
- package/dist/vite.d.mts +2 -2
- package/dist/vite.d.mts.map +1 -1
- package/dist/vite.mjs +195 -74
- package/dist/vite.mjs.map +1 -1
- package/package.json +1 -1
- package/src/ast.ts +4 -3
- package/src/compile.ts +39 -6
- package/src/conditional.ts +540 -0
- package/src/constants.ts +9 -5
- package/src/context.ts +1 -1
- package/src/fold.ts +109 -57
- package/src/inline.ts +274 -112
- package/src/jsx.ts +13 -9
- package/src/memo.ts +13 -13
- package/src/provider.ts +62 -40
- package/src/size.ts +6 -1
- package/src/value.ts +32 -15
- package/src/vite/globals.ts +26 -11
- package/src/vite/index.ts +169 -66
- package/src/vite/inject.ts +27 -15
- package/src/vite/report.ts +21 -12
- package/src/vite/runtime.ts +32 -6
- package/src/vite/usage.ts +89 -48
- package/dist/compile-CwH9mvHD.d.mts.map +0 -1
- package/dist/compile-Dx577-sp.mjs.map +0 -1
package/src/vite/usage.ts
CHANGED
|
@@ -123,12 +123,26 @@ class Usage implements UsageIndex {
|
|
|
123
123
|
const users = new Set([user]);
|
|
124
124
|
for (const [importer, containers] of usage.importers) {
|
|
125
125
|
const moved = absorbed.get(importer);
|
|
126
|
-
users.add(
|
|
126
|
+
users.add(hasEvery(containers, moved) ? user : importer);
|
|
127
127
|
}
|
|
128
128
|
// A module the component's module imports never gets a copy of it, so
|
|
129
129
|
// the original stays for it.
|
|
130
|
-
|
|
130
|
+
for (const id of users) {
|
|
131
|
+
if (this.reaches(module, id)) {
|
|
132
|
+
return 0;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
return users.size;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
function hasEvery(names: Iterable<string>, set: ReadonlySet<string> | undefined): boolean {
|
|
140
|
+
for (const name of names) {
|
|
141
|
+
if (set?.has(name) !== true) {
|
|
142
|
+
return false;
|
|
143
|
+
}
|
|
131
144
|
}
|
|
145
|
+
return true;
|
|
132
146
|
}
|
|
133
147
|
|
|
134
148
|
function isTagName(reference: Node, parents: Parents): boolean {
|
|
@@ -147,9 +161,13 @@ function declaredNames(declaration: Node | null | undefined): string[] {
|
|
|
147
161
|
return [declaration.id.name];
|
|
148
162
|
}
|
|
149
163
|
if (declaration?.type === 'VariableDeclaration') {
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
164
|
+
const names: string[] = [];
|
|
165
|
+
for (const declarator of declaration.declarations) {
|
|
166
|
+
if (declarator.id.type === 'Identifier') {
|
|
167
|
+
names.push(declarator.id.name);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
return names;
|
|
153
171
|
}
|
|
154
172
|
return [];
|
|
155
173
|
}
|
|
@@ -206,7 +224,7 @@ function recordModule(
|
|
|
206
224
|
// A module that uses its own export keeps it, whoever else copies it.
|
|
207
225
|
const exported = exportedBindings(program, scopes);
|
|
208
226
|
// The export names of the top-level declaration a use sits in.
|
|
209
|
-
const
|
|
227
|
+
const findContainers = (reference: Node): string[] => {
|
|
210
228
|
let node: Node = reference;
|
|
211
229
|
let parent = parents.get(node);
|
|
212
230
|
while (parent && parent.type !== 'Program') {
|
|
@@ -232,7 +250,12 @@ function recordModule(
|
|
|
232
250
|
}
|
|
233
251
|
}
|
|
234
252
|
}
|
|
235
|
-
const names
|
|
253
|
+
const names: string[] = [];
|
|
254
|
+
for (const binding of bindings) {
|
|
255
|
+
if (binding) {
|
|
256
|
+
names.push(...(exported.get(binding) ?? []));
|
|
257
|
+
}
|
|
258
|
+
}
|
|
236
259
|
return names.length > 0 ? names : [UNEXPORTED];
|
|
237
260
|
};
|
|
238
261
|
|
|
@@ -244,7 +267,7 @@ function recordModule(
|
|
|
244
267
|
}
|
|
245
268
|
if (imported !== '*') {
|
|
246
269
|
if (isTagName(reference, parents)) {
|
|
247
|
-
usage.tag(target, imported, id,
|
|
270
|
+
usage.tag(target, imported, id, findContainers(reference));
|
|
248
271
|
} else {
|
|
249
272
|
usage.other(target, imported);
|
|
250
273
|
}
|
|
@@ -254,7 +277,7 @@ function recordModule(
|
|
|
254
277
|
const member = parents.get(reference);
|
|
255
278
|
if (member?.type === 'JSXMemberExpression' && member.object === reference) {
|
|
256
279
|
if (isTagName(member, parents)) {
|
|
257
|
-
usage.tag(target, member.property.name, id,
|
|
280
|
+
usage.tag(target, member.property.name, id, findContainers(reference));
|
|
258
281
|
} else {
|
|
259
282
|
usage.other(target, member.property.name);
|
|
260
283
|
}
|
|
@@ -299,14 +322,18 @@ function recordModule(
|
|
|
299
322
|
}
|
|
300
323
|
|
|
301
324
|
for (const [binding, names] of exported) {
|
|
302
|
-
|
|
325
|
+
let used = false;
|
|
326
|
+
for (const reference of binding.references) {
|
|
303
327
|
const parent = parents.get(reference);
|
|
304
|
-
|
|
328
|
+
if (
|
|
305
329
|
parent?.type !== 'ExportSpecifier' &&
|
|
306
330
|
parent?.type !== 'ExportDefaultDeclaration' &&
|
|
307
331
|
!isClosingTagName(reference, parents)
|
|
308
|
-
)
|
|
309
|
-
|
|
332
|
+
) {
|
|
333
|
+
used = true;
|
|
334
|
+
break;
|
|
335
|
+
}
|
|
336
|
+
}
|
|
310
337
|
if (used) {
|
|
311
338
|
for (const name of names) {
|
|
312
339
|
usage.other(id, name);
|
|
@@ -316,7 +343,7 @@ function recordModule(
|
|
|
316
343
|
}
|
|
317
344
|
|
|
318
345
|
/** The import specifiers a module loads, statically or with `import()`. */
|
|
319
|
-
function
|
|
346
|
+
function collectSpecifiers(program: Program): { static: Set<string>; dynamic: Set<string> } {
|
|
320
347
|
const statics = new Set<string>();
|
|
321
348
|
const dynamics = new Set<string>();
|
|
322
349
|
for (const statement of program.body) {
|
|
@@ -360,46 +387,60 @@ export async function buildUsageIndex(
|
|
|
360
387
|
usage.all(entry);
|
|
361
388
|
}
|
|
362
389
|
const seen = new Set<string>();
|
|
363
|
-
let frontier =
|
|
390
|
+
let frontier: string[] = [];
|
|
391
|
+
for (const id of entries) {
|
|
392
|
+
if (SCRIPT.test(id.replace(/\?.*$/, ''))) {
|
|
393
|
+
frontier.push(id);
|
|
394
|
+
}
|
|
395
|
+
}
|
|
364
396
|
while (frontier.length > 0) {
|
|
365
397
|
for (const id of frontier) {
|
|
366
398
|
seen.add(id);
|
|
367
399
|
}
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
400
|
+
async function readModule(id: string): Promise<string[]> {
|
|
401
|
+
const code = await host.read(id);
|
|
402
|
+
let program: Program;
|
|
403
|
+
try {
|
|
404
|
+
program = parse(id.replace(/\?.*$/, ''), code ?? '');
|
|
405
|
+
} catch {
|
|
406
|
+
return [];
|
|
407
|
+
}
|
|
408
|
+
const { static: statics, dynamic } = collectSpecifiers(program);
|
|
409
|
+
const targets = new Map<string, string>();
|
|
410
|
+
async function resolveSource(source: string): Promise<void> {
|
|
411
|
+
const target = await host.resolve(source, id);
|
|
412
|
+
if (target !== undefined) {
|
|
413
|
+
targets.set(source, target);
|
|
377
414
|
}
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
)
|
|
388
|
-
|
|
389
|
-
for (const source of dynamic) {
|
|
390
|
-
const target = targets.get(source);
|
|
391
|
-
if (target !== undefined) {
|
|
392
|
-
usage.all(target);
|
|
393
|
-
}
|
|
415
|
+
}
|
|
416
|
+
const resolving: Promise<void>[] = [];
|
|
417
|
+
for (const source of [...statics, ...dynamic]) {
|
|
418
|
+
resolving.push(resolveSource(source));
|
|
419
|
+
}
|
|
420
|
+
await Promise.all(resolving);
|
|
421
|
+
// A module loaded with `import()` is used as a whole.
|
|
422
|
+
for (const source of dynamic) {
|
|
423
|
+
const target = targets.get(source);
|
|
424
|
+
if (target !== undefined) {
|
|
425
|
+
usage.all(target);
|
|
394
426
|
}
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
427
|
+
}
|
|
428
|
+
recordModule(usage, id, program, targets);
|
|
429
|
+
usage.imports.set(id, [...targets.values()]);
|
|
430
|
+
return [...targets.values()];
|
|
431
|
+
}
|
|
432
|
+
const reading: Promise<string[]>[] = [];
|
|
433
|
+
for (const id of frontier) {
|
|
434
|
+
reading.push(readModule(id));
|
|
435
|
+
}
|
|
436
|
+
// oxlint-disable-next-line no-await-in-loop
|
|
437
|
+
const next = await Promise.all(reading);
|
|
438
|
+
frontier = [];
|
|
439
|
+
for (const id of new Set(next.flat())) {
|
|
440
|
+
if (!seen.has(id) && SCRIPT.test(id.replace(/\?.*$/, ''))) {
|
|
441
|
+
frontier.push(id);
|
|
442
|
+
}
|
|
443
|
+
}
|
|
403
444
|
}
|
|
404
445
|
return usage;
|
|
405
446
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"compile-CwH9mvHD.d.mts","names":[],"sources":["../src/value.ts","../src/context.ts","../src/constants.ts","../src/compile.ts"],"mappings":";;;;KAUY;;;;KC4DA;;;;;UAMK;WACN,MAAM;;WAEN;;WAEA;;;;;;;;KC9DC,oBAAoB,SAAS,eAAe,SAAS,eAAe;;;UCF/D;;;;;;;EAOf;;;;;;;EAOA;;;;;;EAMA;;;;;;;EAOA;;;;;;;EAOA;;;;;;;EAOA;;;;;;;EAOA;;;;;;EAMA,iBAAiB,SAAS;;;;;;;EAO1B;;;;;;EAMA,oBAAoB;;;;;;EAMpB,kBAAkB,SAAS,eAAe;;;;;;EAM1C,mBAAmB,SAAS;;;;;;;;EAQ5B,mBAAmB,SAAS;;;;;;;;EAQ5B;;;;;;EAMA;;;;;;;;EAQA;;;;;;EAMA;;;;;;;EAOA;;UAGe;EACf;;EAEA,KAAK;;;;;EAKL,UAAU;;;;;;;;;;;;;iBAoGI,QAAQ,cAAc,UAAS,iBAAsB;UA0DpD;;;;;EAKf;;;;;;EAMA,SAAS,eAAe;;;;;;;;iBASV,oBACd,cACA,UAAS,KAAK,wEACb"}
|