solid-optimizer 0.4.0 → 1.0.0-next.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 +74 -47
- package/dist/{compile-BQuBDA0Q.d.mts → compile-BRCj4UN7.d.mts} +15 -22
- package/dist/compile-BRCj4UN7.d.mts.map +1 -0
- package/dist/{compile-D3caSUtw.mjs → compile-Cz6hbiQv.mjs} +943 -670
- package/dist/compile-Cz6hbiQv.mjs.map +1 -0
- package/dist/index.d.mts +1 -1
- package/dist/index.mjs +1 -1
- package/dist/vite.d.mts +3 -10
- package/dist/vite.d.mts.map +1 -1
- package/dist/vite.mjs +305 -204
- package/dist/vite.mjs.map +1 -1
- package/package.json +10 -11
- package/src/compile.ts +16 -40
- package/src/constants.ts +42 -2
- package/src/context.ts +3 -0
- package/src/copy-size.ts +73 -0
- package/src/fold.ts +619 -17
- package/src/inline.ts +352 -292
- package/src/memo.ts +161 -30
- package/src/provider.ts +40 -75
- package/src/scope.ts +14 -1
- package/src/size.ts +35 -75
- package/src/vite/globals.ts +67 -0
- package/src/vite/index.ts +279 -264
- package/src/vite/inject.ts +14 -4
- package/src/vite/runtime.ts +23 -3
- package/dist/compile-BQuBDA0Q.d.mts.map +0 -1
- package/dist/compile-D3caSUtw.mjs.map +0 -1
- package/src/server.ts +0 -275
package/src/vite/inject.ts
CHANGED
|
@@ -222,9 +222,14 @@ export interface ExportedComponent {
|
|
|
222
222
|
|
|
223
223
|
/**
|
|
224
224
|
* Whether a function returns JSX whose root calls a component declared at
|
|
225
|
-
* the top of its own module.
|
|
225
|
+
* the top of its own module. A context's provider does not count, since the
|
|
226
|
+
* provider pass can remove it from a copy.
|
|
226
227
|
*/
|
|
227
|
-
function returnsLocalCall(
|
|
228
|
+
function returnsLocalCall(
|
|
229
|
+
fn: TopLevelFunction['fn'],
|
|
230
|
+
scopes: ScopeAnalysis,
|
|
231
|
+
moduleSources: readonly string[],
|
|
232
|
+
): boolean {
|
|
228
233
|
if (
|
|
229
234
|
fn.type !== 'FunctionDeclaration' &&
|
|
230
235
|
fn.type !== 'FunctionExpression' &&
|
|
@@ -251,7 +256,12 @@ function returnsLocalCall(fn: TopLevelFunction['fn'], scopes: ScopeAnalysis): bo
|
|
|
251
256
|
return false;
|
|
252
257
|
}
|
|
253
258
|
const binding = scopes.references.get(inner.openingElement.name);
|
|
254
|
-
return
|
|
259
|
+
return (
|
|
260
|
+
binding !== undefined &&
|
|
261
|
+
binding.scope === scopes.root &&
|
|
262
|
+
binding.kind !== 'import' &&
|
|
263
|
+
!isContext(binding, scopes, moduleSources)
|
|
264
|
+
);
|
|
255
265
|
}
|
|
256
266
|
|
|
257
267
|
/**
|
|
@@ -346,5 +356,5 @@ export function readExportedComponent(
|
|
|
346
356
|
}
|
|
347
357
|
return `const ${name} = ${s.slice(component.fn.start, component.fn.end)};`;
|
|
348
358
|
};
|
|
349
|
-
return { dependencies, copy, wrapsLocal: returnsLocalCall(component.fn, scopes) };
|
|
359
|
+
return { dependencies, copy, wrapsLocal: returnsLocalCall(component.fn, scopes, moduleSources) };
|
|
350
360
|
}
|
package/src/vite/runtime.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Keeps Solid's runtime helpers reachable while JSX waits in a bundled chunk.
|
|
3
3
|
*
|
|
4
4
|
* Solid's JSX transform imports helpers like `template` and `insert` from
|
|
5
|
-
*
|
|
5
|
+
* `@solidjs/web`. When the transform runs on a chunk, the bundle is already
|
|
6
6
|
* built, so a new bare import cannot be resolved or bundled anymore. Instead,
|
|
7
7
|
* every module imports the helpers it will need before bundling, and passes
|
|
8
8
|
* them to a marker call. The bundler keeps the call, since it could have side
|
|
@@ -70,8 +70,28 @@ function exportedName(specifier: ImportSpecifier): string {
|
|
|
70
70
|
return specifier.imported.type === 'Literal' ? specifier.imported.value : specifier.imported.name;
|
|
71
71
|
}
|
|
72
72
|
|
|
73
|
+
/**
|
|
74
|
+
* The helpers Solid's JSX transform imported from `source` into its output.
|
|
75
|
+
* The module's own imports, including type imports, are left out.
|
|
76
|
+
*/
|
|
77
|
+
export function generatedImports(code: string, filename: string, source: string): string[] {
|
|
78
|
+
const program = parse(filename, code);
|
|
79
|
+
const names: string[] = [];
|
|
80
|
+
for (const statement of program.body) {
|
|
81
|
+
if (statement.type !== 'ImportDeclaration' || statement.source.value !== source) {
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
for (const specifier of statement.specifiers) {
|
|
85
|
+
if (specifier.type === 'ImportSpecifier' && isGeneratedSpecifier(specifier)) {
|
|
86
|
+
names.push(exportedName(specifier));
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return names;
|
|
91
|
+
}
|
|
92
|
+
|
|
73
93
|
export interface MarkerOptions {
|
|
74
|
-
/** The module the helpers come from, usually
|
|
94
|
+
/** The module the helpers come from, usually `@solidjs/web`. */
|
|
75
95
|
readonly moduleName: string;
|
|
76
96
|
/** The helpers to keep. */
|
|
77
97
|
readonly helpers: ReadonlySet<string>;
|
|
@@ -238,7 +258,7 @@ export function repairJSXSequences(code: string, filename: string): EditResult |
|
|
|
238
258
|
}
|
|
239
259
|
|
|
240
260
|
export interface ChunkRuntime extends EditResult {
|
|
241
|
-
/** The chunk's name for each helper, keyed by the name
|
|
261
|
+
/** The chunk's name for each helper, keyed by the name `@solidjs/web` exports. */
|
|
242
262
|
readonly helpers: ReadonlyMap<string, string>;
|
|
243
263
|
/** The built-in each chunk binding refers to, keyed by the chunk's name for it. */
|
|
244
264
|
readonly builtInAliases: Record<string, string>;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"compile-BQuBDA0Q.d.mts","names":[],"sources":["../src/context.ts","../src/value.ts","../src/constants.ts","../src/compile.ts"],"mappings":";;;;;KAiEY;;;;;UAMK;WACN,MAAM;;WAEN;;WAEA;;;;KClEC;;;;;;;KCSA,oBAAoB,SAAS,eAAe,SAAS,eAAe;;;UCD/D;;;;;;;EAOf;;;;;;;EAOA;;;;;;EAMA;;;;;;;;;;;;;EAaA;;;;;;;EAOA;;;;;;;EAOA;;;;;;;EAOA;;;;;;;EAOA;;;;;;EAMA,iBAAiB,SAAS;;;;;;;EAO1B;;;;;;EAMA,oBAAoB;;;;;;EAMpB,mBAAmB,SAAS;;;;;;;;EAQ5B,mBAAmB,SAAS;;;;;;;;EAQ5B;;;;;;;;EAQA;;;;;;EAMA;;;;;;;EAOA;;UAGe;EACf;;EAEA,KAAK;;;;;EAKL,UAAU;;;;;;;;;;;;;iBAkGI,QAAQ,cAAc,UAAS,iBAAsB;UA2EpD;;;;;EAKf;;;;;;EAMA,SAAS,eAAe;;;;;;;;iBASV,oBACd,cACA,UAAS,KAAK,oDACb"}
|