solid-optimizer 1.0.0-next.4 → 1.0.0-next.6
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 +8 -3
- package/dist/{compile-Dx577-sp.mjs → compile-DnfP-Quf.mjs} +720 -157
- package/dist/compile-DnfP-Quf.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 +135 -58
- package/src/inline.ts +274 -112
- package/src/jsx.ts +13 -9
- package/src/memo.ts +209 -26
- 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/README.md
CHANGED
|
@@ -49,6 +49,7 @@ The input and the output both keep their JSX. Run the JSX transform after `compi
|
|
|
49
49
|
- `sharedComponents` maps top-level components that other modules use too to the number of modules that use them, this one included. Inlining one only counts its share of the declaration. `0` keeps the declaration whatever is inlined.
|
|
50
50
|
- `contexts` turns context provider removal on or off. Defaults to `true`.
|
|
51
51
|
- `memos` turns memo inlining on or off. Defaults to `true`.
|
|
52
|
+
- `conditionals` turns `<Show>` and `<Switch>` lowering on or off. A `<Show>` without `keyed` becomes a ternary, which Solid's JSX transform compiles to one memo instead of a component and three memos. A callback child like `{(user) => <b>{user().name}</b>}` becomes its body, with `user()` read as `when` again, when `when` reads names, members, and signal or memo getters. A `<Switch>` of such `<Match>`es becomes a chain of ternaries. Defaults to `true`.
|
|
52
53
|
- `builtIns` lists the names of Solid's built-in components. A tag only folds when it is one of them. An empty list turns control-flow folding off.
|
|
53
54
|
- `moduleSources` lists the modules Solid's built-ins are imported from. Defaults to `['solid-js', '@solidjs/web']`.
|
|
54
55
|
- `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).
|
|
@@ -113,7 +114,7 @@ The optimizer is off while serving. Set `optimizer.dev` to run module mode in de
|
|
|
113
114
|
The plugin takes every option of `@solidjs/vite-plugin`, plus `optimizer`.
|
|
114
115
|
|
|
115
116
|
- `optimizer: false` uses `@solidjs/vite-plugin` as it is.
|
|
116
|
-
- `optimizer.fold`, `optimizer.inline`, `optimizer.alwaysInline`, `optimizer.contexts`, `optimizer.memos`, and `optimizer.maxPasses` work like the `compile` options.
|
|
117
|
+
- `optimizer.fold`, `optimizer.inline`, `optimizer.alwaysInline`, `optimizer.contexts`, `optimizer.memos`, `optimizer.conditionals`, and `optimizer.maxPasses` work like the `compile` options.
|
|
117
118
|
- `optimizer.mode` is `'auto'` by default. Set it to `'module'` to never keep JSX through bundling.
|
|
118
119
|
- `optimizer.dev` also optimizes while serving. Defaults to `false`.
|
|
119
120
|
- `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`.
|
|
@@ -141,7 +142,7 @@ Each line is a pass, a reason, how many times it happened, and the names it happ
|
|
|
141
142
|
- `lazy`, `imported`, `nested`, and `not-a-function` mean the tag is not a component declared at the top of the same module or chunk.
|
|
142
143
|
- A reason that starts with `copy-` is about copying a component from another module. `copy-package` means it comes from a package in `node_modules` that `optimizer.packages` does not list, `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.
|
|
143
144
|
|
|
144
|
-
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.
|
|
145
|
+
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, and `signal-constant` for a signal that nothing writes but that is used other than by calling it.
|
|
145
146
|
|
|
146
147
|
### Limits
|
|
147
148
|
|
|
@@ -305,6 +306,8 @@ becomes `<p style={{ color: color() }} />`. See [strategy.md](https://github.com
|
|
|
305
306
|
|
|
306
307
|
A memo whose computation folds to a literal never changes. Every call of it becomes the literal, however many there are, when each call comes after the declaration and nothing else uses the memo.
|
|
307
308
|
|
|
309
|
+
So does a signal that nothing writes: `const [size] = createSignal(3)`, or one whose setter nothing references. With a literal and no options, every call of the getter becomes the literal, under the same conditions. This also works outside a function, since a signal takes no owner.
|
|
310
|
+
|
|
308
311
|
```jsx
|
|
309
312
|
const size = createMemo(() => 1 + 2);
|
|
310
313
|
return <p>{size() * 2}</p>;
|
|
@@ -312,6 +315,8 @@ return <p>{size() * 2}</p>;
|
|
|
312
315
|
|
|
313
316
|
becomes `<p>{6}</p>`.
|
|
314
317
|
|
|
318
|
+
A plain arrow that only returns an expression, like `const label = () => (props.open ? 'Close' : 'Open')`, has no cache and no owner, so each call becomes its body. That needs every call to come after the declaration with no arguments, nothing else to use the arrow, and every name in the body to mean the same at the call. With more than one call, the body is copied only when the copies are no larger than the arrow and its calls, minified.
|
|
319
|
+
|
|
315
320
|
Solid's `children` helper over JSX, read once as an element's child, becomes that JSX. The helper resolves JSX the same way inserting it does, and nothing makes it run again.
|
|
316
321
|
|
|
317
322
|
```jsx
|
|
@@ -351,7 +356,7 @@ This follows the `optimize` option of `@solidjs/compiler` ([solidjs/solid#3231](
|
|
|
351
356
|
|
|
352
357
|
A built-in only folds when the tag resolves to Solid's component. The tag must bind to nothing, or be imported from one of `moduleSources`. A tag with a spread attribute or a function child never folds. `<Portal>`, `<Loading>`, `<Errored>`, and `<Reveal>` never fold.
|
|
353
358
|
|
|
354
|
-
A call to Solid's `lazy` is marked `/* @__PURE__ */`, so the bundler drops one that a folded branch left unused, along with its chunk.
|
|
359
|
+
A call to Solid's `lazy` is marked `/* @__PURE__ */`, so the bundler drops one that a folded branch left unused, along with its chunk. `createContext` is marked too, and so are `createSignal` and `createStore` whose first argument is a literal, an object, or an array.
|
|
355
360
|
|
|
356
361
|
A condition that is discarded but has side effects still runs. `[effect()] && value` becomes `([effect()], value)`.
|
|
357
362
|
|