solid-optimizer 0.3.0 → 0.4.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 +26 -1
- package/dist/{compile-BroGlagZ.d.mts → compile-BQuBDA0Q.d.mts} +29 -2
- package/dist/compile-BQuBDA0Q.d.mts.map +1 -0
- package/dist/{compile-ocDYvJUW.mjs → compile-D3caSUtw.mjs} +401 -67
- package/dist/compile-D3caSUtw.mjs.map +1 -0
- package/dist/index.d.mts +2 -2
- package/dist/index.mjs +1 -1
- package/dist/vite.d.mts +19 -1
- package/dist/vite.d.mts.map +1 -1
- package/dist/vite.mjs +419 -141
- package/dist/vite.mjs.map +1 -1
- package/package.json +1 -1
- package/src/ast.ts +12 -4
- package/src/compile.ts +61 -10
- package/src/context.ts +29 -0
- package/src/index.ts +1 -0
- package/src/inline.ts +225 -16
- package/src/memo.ts +43 -10
- package/src/provider.ts +65 -8
- package/src/size.ts +2 -0
- package/src/vite/index.ts +277 -34
- package/src/vite/inject.ts +41 -2
- package/src/vite/refs.ts +99 -0
- package/src/vite/report.ts +74 -0
- package/src/vite/runtime.ts +0 -20
- package/dist/compile-BroGlagZ.d.mts.map +0 -1
- package/dist/compile-ocDYvJUW.mjs.map +0 -1
package/README.md
CHANGED
|
@@ -50,6 +50,7 @@ The input and the output both keep their JSX. Run the JSX transform after `compi
|
|
|
50
50
|
- `importedConstants` holds the constants of imported modules, keyed by the import specifier as the code writes it, then by export name. An import of one of them folds like a local `const`. See [Constants from other modules](#constants-from-other-modules).
|
|
51
51
|
- `maxPasses` limits how many rounds run. Compilation stops early once a round changes nothing. Defaults to `10`.
|
|
52
52
|
- `sourceMap` turns the source map on or off. Defaults to `true`.
|
|
53
|
+
- `report` records what the inline, provider, and memo passes leave alone, and why. The result lists them in `skipped`, each with its pass, a reason code, and a name. Defaults to `false`.
|
|
53
54
|
|
|
54
55
|
### Constants from other modules
|
|
55
56
|
|
|
@@ -111,6 +112,30 @@ The plugin takes every option of `vite-plugin-solid`, plus `optimizer`.
|
|
|
111
112
|
- `optimizer.mode` is `'auto'` by default. Set it to `'module'` to never keep JSX through bundling.
|
|
112
113
|
- `optimizer.dev` also optimizes while serving. Defaults to `false`.
|
|
113
114
|
- `optimizer.server` applies the `server` option in server builds. Defaults to `true`.
|
|
115
|
+
- `optimizer.report` reports what stays as written in each build, and why. `true` prints it. A function receives it instead, once per build environment. Defaults to `false`.
|
|
116
|
+
|
|
117
|
+
### Report
|
|
118
|
+
|
|
119
|
+
`optimizer.report` lists each component call, provider, and memo the optimizer left alone, grouped by reason:
|
|
120
|
+
|
|
121
|
+
```
|
|
122
|
+
solid-optimizer: what stays as written in client
|
|
123
|
+
inline copy-size 3 Table (../components/Table)×2, Card (../components/Card)
|
|
124
|
+
inline imported 2 Table (./Table-*.js)×2
|
|
125
|
+
inline no-host 2 App, Home
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
Each line is a pass, a reason, how many times it happened, and the names it happened to. The reasons for the inline pass:
|
|
129
|
+
|
|
130
|
+
- `props-use` and `view-use` mean the component uses its props in a way other than `props.name`, a spread onto an element, or a `merge()` or `omit()` view, such as passing them to a function.
|
|
131
|
+
- `component-params`, `component-body`, `component-return`, `component-async`, `component-recursive`, and `component-this` mean the component's own shape is not supported.
|
|
132
|
+
- `call-spread`, `call-ref`, and `call-namespace` mean the call site passes a spread, a `ref`, or a namespaced attribute.
|
|
133
|
+
- `no-host` means the component has statements, and the call is not in JSX a component returns, such as a `<For>` callback.
|
|
134
|
+
- `size` means the copies would be larger than the calls.
|
|
135
|
+
- `lazy`, `imported`, `nested`, and `not-a-function` mean the tag is not a component declared at the top of the same module or chunk.
|
|
136
|
+
- A reason that starts with `copy-` is about copying a component from another module. `copy-package` means it comes from `node_modules`, `copy-cycle` means the two modules import each other, `copy-wrapper` means the component only returns a call of another component in its module, and `copy-size` means the copy was larger.
|
|
137
|
+
|
|
138
|
+
The provider pass reports `open-component`, `open-call`, `open-new`, `open-spread`, and `open-outer` for code under the provider that it cannot see into, and `provider-value`, `provider-undefined`, and `provider-shape` for a value or provider it cannot handle. The memo pass reports `memo-reads`, `memo-read-place`, `memo-constant`, and a few more for a memo it keeps.
|
|
114
139
|
|
|
115
140
|
### Limits
|
|
116
141
|
|
|
@@ -164,7 +189,7 @@ Solid then creates one template for `<main>` instead of two.
|
|
|
164
189
|
A component inlines when all of these hold:
|
|
165
190
|
|
|
166
191
|
- It is declared once at the top level, with a capitalized name.
|
|
167
|
-
- Its parameter is one identifier that is only read as `props.name`, or passed to `mergeProps()` and `splitProps()`. See below.
|
|
192
|
+
- Its parameter is one identifier that is only read as `props.name`, spread onto an element as `{...props}`, or passed to `mergeProps()` and `splitProps()`. See below.
|
|
168
193
|
- Its body ends in the only `return`, and that `return` returns JSX.
|
|
169
194
|
- It does not use `this`, `arguments`, `super`, or `new.target`.
|
|
170
195
|
- The call site has no spread attribute, no `ref`, and no namespaced attribute.
|
|
@@ -1,6 +1,21 @@
|
|
|
1
1
|
import { SourceMap } from "@jridgewell/remapping";
|
|
2
2
|
import MagicString from "magic-string";
|
|
3
3
|
import "oxc-parser";
|
|
4
|
+
//#region src/context.d.ts
|
|
5
|
+
/** The passes that record what they leave alone. */
|
|
6
|
+
type SkipPass = 'inline' | 'contexts' | 'memos';
|
|
7
|
+
/**
|
|
8
|
+
* Something a pass left alone, and why. The `compile` option `report`
|
|
9
|
+
* collects them.
|
|
10
|
+
*/
|
|
11
|
+
interface Skip {
|
|
12
|
+
readonly pass: SkipPass;
|
|
13
|
+
/** A short code for the reason, like `call-spread`. */
|
|
14
|
+
readonly reason: string;
|
|
15
|
+
/** The component, context, or memo it is about. */
|
|
16
|
+
readonly name: string;
|
|
17
|
+
}
|
|
18
|
+
//#endregion
|
|
4
19
|
//#region src/value.d.ts
|
|
5
20
|
type Primitive = string | number | boolean | null | undefined;
|
|
6
21
|
//#endregion
|
|
@@ -129,11 +144,23 @@ interface CompileOptions {
|
|
|
129
144
|
* @default true
|
|
130
145
|
*/
|
|
131
146
|
sourceMap?: boolean;
|
|
147
|
+
/**
|
|
148
|
+
* Record what the inline, provider, and memo passes leave alone, and why.
|
|
149
|
+
* The result lists them in `skipped`.
|
|
150
|
+
*
|
|
151
|
+
* @default false
|
|
152
|
+
*/
|
|
153
|
+
report?: boolean;
|
|
132
154
|
}
|
|
133
155
|
interface CompileResult {
|
|
134
156
|
code: string;
|
|
135
157
|
/** The map from the output back to the input, or `null` when nothing changed or maps are off. */
|
|
136
158
|
map: SourceMap | null;
|
|
159
|
+
/**
|
|
160
|
+
* What the last round left alone, and why, when `report` is set. The last
|
|
161
|
+
* round changes nothing, unless `maxPasses` stopped the rounds first.
|
|
162
|
+
*/
|
|
163
|
+
skipped?: Skip[];
|
|
137
164
|
}
|
|
138
165
|
/**
|
|
139
166
|
* Optimizes JSX before it is lowered by Solid's JSX transform.
|
|
@@ -168,5 +195,5 @@ interface ModuleConstants {
|
|
|
168
195
|
*/
|
|
169
196
|
declare function readModuleConstants(code: string, options?: Pick<CompileOptions, 'filename' | 'importedConstants'>): ModuleConstants;
|
|
170
197
|
//#endregion
|
|
171
|
-
export { readModuleConstants as a, compile as i, CompileResult as n, ImportedConstants as o, ModuleConstants as r, Primitive as s, CompileOptions as t };
|
|
172
|
-
//# sourceMappingURL=compile-
|
|
198
|
+
export { readModuleConstants as a, Skip as c, compile as i, SkipPass as l, CompileResult as n, ImportedConstants as o, ModuleConstants as r, Primitive as s, CompileOptions as t };
|
|
199
|
+
//# sourceMappingURL=compile-BQuBDA0Q.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|