solid-optimizer 1.0.0-next.9 → 1.1.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 +14 -19
- package/dist/{compile-X_SMDFr2.d.mts → compile-BKA77zb8.d.mts} +10 -2
- package/dist/compile-BKA77zb8.d.mts.map +1 -0
- package/dist/{compile-DptOANJi.mjs → compile-D2f8eXFk.mjs} +548 -161
- package/dist/compile-D2f8eXFk.mjs.map +1 -0
- package/dist/index.d.mts +1 -1
- package/dist/index.mjs +1 -1
- package/dist/vite.d.mts +1 -1
- package/dist/vite.d.mts.map +1 -1
- package/dist/vite.mjs +55 -14
- package/dist/vite.mjs.map +1 -1
- package/package.json +6 -6
- package/src/compile.ts +29 -8
- package/src/conditional.ts +29 -22
- package/src/context.ts +3 -3
- package/src/copy-size.ts +6 -5
- package/src/fold.ts +57 -53
- package/src/inline.ts +67 -59
- package/src/jsx.ts +16 -14
- package/src/memo.ts +12 -6
- package/src/text.ts +297 -0
- package/src/tidy.ts +390 -0
- package/src/vite/index.ts +66 -12
- package/dist/compile-DptOANJi.mjs.map +0 -1
- package/dist/compile-X_SMDFr2.d.mts.map +0 -1
package/README.md
CHANGED
|
@@ -12,18 +12,18 @@ The website, [solid-optimizer.vercel.app](https://solid-optimizer.vercel.app), s
|
|
|
12
12
|
|
|
13
13
|
## Install
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
This version is for Solid 2.0. Solid 1.x users stay on `solid-optimizer@0`, which only gets fixes now, from the [`0.x` branch](https://github.com/lxsmnsyc/solid-optimizer/tree/0.x).
|
|
16
16
|
|
|
17
17
|
```bash
|
|
18
|
-
npm i -D solid-optimizer
|
|
18
|
+
npm i -D solid-optimizer
|
|
19
19
|
```
|
|
20
20
|
|
|
21
21
|
```bash
|
|
22
|
-
yarn add -D solid-optimizer
|
|
22
|
+
yarn add -D solid-optimizer
|
|
23
23
|
```
|
|
24
24
|
|
|
25
25
|
```bash
|
|
26
|
-
pnpm add -D solid-optimizer
|
|
26
|
+
pnpm add -D solid-optimizer
|
|
27
27
|
```
|
|
28
28
|
|
|
29
29
|
## Usage
|
|
@@ -43,7 +43,7 @@ The input and the output both keep their JSX. Run the JSX transform after `compi
|
|
|
43
43
|
|
|
44
44
|
### Options
|
|
45
45
|
|
|
46
|
-
- `filename` sets the parser and the source map source. `.ts
|
|
46
|
+
- `filename` sets the parser and the source map source. `.ts`, `.tsx`, `.mts`, and `.cts` parse as TypeScript. Anything else parses as JSX. Defaults to `input.jsx`.
|
|
47
47
|
- `fold` turns constant folding and control-flow resolution on or off. Defaults to `true`.
|
|
48
48
|
- `inline` turns component inlining on or off. Defaults to `true`.
|
|
49
49
|
- `alwaysInline` inlines every component that can be, even where the copies are larger than the calls they replace. Defaults to `false`. See [Only where it is smaller](#only-where-it-is-smaller).
|
|
@@ -54,9 +54,13 @@ The input and the output both keep their JSX. Run the JSX transform after `compi
|
|
|
54
54
|
- `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`.
|
|
55
55
|
- `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.
|
|
56
56
|
- `moduleSources` lists the modules Solid's built-ins are imported from. Defaults to `['solid-js', '@solidjs/web']`.
|
|
57
|
+
- `builtInAliases` maps top-level names that refer to Solid's built-ins to the built-in's name, like `{ Show$1: 'Show' }`. A bundler can rename a built-in in a chunk, or declare it instead of importing it.
|
|
58
|
+
- `constantVars` treats a top-level `var` that nothing writes to as a constant. Bundlers turn top-level `const` into `var`, so turn this on for bundled chunks. Defaults to `false`.
|
|
57
59
|
- `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).
|
|
60
|
+
- `importedContexts` lists the exports of imported modules that are contexts made by `createContext`, keyed by the import specifier as the code writes it. A provider of an imported context can then be removed like a local one.
|
|
58
61
|
- `globalConstants` holds values of global names and paths, such as `{ __DEV__: false, 'import.meta.env.MODE': 'production' }`. A path starts at `import.meta` or at a name the module does not declare, and folds like a constant.
|
|
59
62
|
- `maxPasses` limits how many rounds run. Compilation stops early once a round changes nothing. Defaults to `10`.
|
|
63
|
+
- `tidy` tidies the output JSX: it drops empty `{}` children, writes strings in braces such as `class={'card'}` as plain JSX, and unwraps a fragment that holds one element in a branch of `? :`, `&&`, `||` or `??`. The tests lower the tidied and untidied JSX with Solid's JSX transform and expect the same code. It only runs on a module the passes changed. Defaults to `true`.
|
|
60
64
|
- `sourceMap` turns the source map on or off. Defaults to `true`.
|
|
61
65
|
- `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`.
|
|
62
66
|
|
|
@@ -95,7 +99,7 @@ export default defineConfig({
|
|
|
95
99
|
});
|
|
96
100
|
```
|
|
97
101
|
|
|
98
|
-
`@solidjs/vite-plugin` and `vite` are peer dependencies.
|
|
102
|
+
`@solidjs/vite-plugin` and `vite` are optional peer dependencies. Only `solid-optimizer/vite` needs them.
|
|
99
103
|
|
|
100
104
|
The plugin optimizes in one of two modes.
|
|
101
105
|
|
|
@@ -133,18 +137,9 @@ solid-optimizer: what stays as written in client
|
|
|
133
137
|
inline no-host 1 Home
|
|
134
138
|
```
|
|
135
139
|
|
|
136
|
-
Each line is a pass, a reason, how many times it happened, and the names it happened to. A package's own modules are compiled too, but what they leave alone is not reported, since the app cannot change it. The app's calls of a package's components are. In chunk mode, a chunk is reported as a whole, so it also lists the package code bundled into it.
|
|
140
|
+
Each line is a pass, a reason, how many times it happened, and the names it happened to. A package's own modules are compiled too, but what they leave alone is not reported, since the app cannot change it. The app's calls of a package's components are. In chunk mode, a chunk is reported as a whole, so it also lists the package code bundled into it.
|
|
137
141
|
|
|
138
|
-
|
|
139
|
-
- `component-params`, `component-body`, `component-return`, `component-async`, `component-recursive`, and `component-this` mean the component's own shape is not supported.
|
|
140
|
-
- `component-write` means the component's statements assign to something declared outside it, like a counter at the top of the module. A copy's statements run before the JSX around the call, so that JSX would see the write too early.
|
|
141
|
-
- `call-spread` and `call-namespace` mean the call site passes a spread or a namespaced attribute. `call-ref` means its `ref` is an expression other than a name, a function, or an array of them, and `ref-use` means the component uses `props.ref` other than as a `ref`.
|
|
142
|
-
- `no-host` means the component has statements, and the call is not in JSX that a component or one of Solid's callbacks returns. A `<Show>` child or a `fallback` is one such place.
|
|
143
|
-
- `size` means the copies would be larger than the calls.
|
|
144
|
-
- `lazy`, `imported`, `nested`, and `not-a-function` mean the tag is not a component declared at the top of the same module or chunk.
|
|
145
|
-
- 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 component's module imports the importer back, directly or through other modules, a listed package, or a virtual module, `copy-virtual` means the copy would import a virtual module that its specifier does not reach from the importer, `copy-wrapper` means the component only returns a call of another component in its module, and `copy-size` means the copy was larger.
|
|
146
|
-
|
|
147
|
-
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.
|
|
142
|
+
`skip.pass` is `'inline'`, `'contexts'` for the provider pass, or `'memos'`. The [Report reasons](https://solid-optimizer.vercel.app/docs/reference/reasons/) page of the docs lists every reason code and what it means.
|
|
148
143
|
|
|
149
144
|
### Limits
|
|
150
145
|
|
|
@@ -152,7 +147,7 @@ The provider pass reports `open-component`, `open-call`, `open-new`, `open-sprea
|
|
|
152
147
|
- An export named `__so_local$name` is added to a module for each local binding its exported components need, so a copy in another module can import it. In chunk mode, entry modules get none.
|
|
153
148
|
- A component used in several chunks is copied into each of them, where each copy is no larger than its call.
|
|
154
149
|
- Components from dependencies in `node_modules` are only copied from the packages `optimizer.packages` lists.
|
|
155
|
-
- `.tsrx` modules are
|
|
150
|
+
- The plugin optimizes the modules the official plugin lowers: `.jsx` and `.tsx` (with their `.m` and `.c` forms), plus the `extensions` it registers, such as `.mdx`, filtered by `include` and `exclude`. `.tsrx` modules are the exception: the official plugin lowers them on its own path, and they are not optimized.
|
|
156
151
|
|
|
157
152
|
## Features
|
|
158
153
|
|
|
@@ -232,7 +227,7 @@ Inlining accepts two differences:
|
|
|
232
227
|
- A prop called as `props.name()` runs with its own receiver as `this`, not the props object.
|
|
233
228
|
- Moved statements run before the host's JSX is created. The order of effect registration between siblings can change.
|
|
234
229
|
|
|
235
|
-
|
|
230
|
+
The source map points each copied character at the one it copies, so inlined JSX maps to the component's own JSX and a prop value to the call site's attribute. Code a pass writes itself, such as a folded constant or a renamed local, maps to what it replaces.
|
|
236
231
|
|
|
237
232
|
#### Only where it is smaller
|
|
238
233
|
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { SourceMap } from "@jridgewell/remapping";
|
|
2
|
-
import MagicString from "magic-string";
|
|
3
2
|
import "oxc-parser";
|
|
4
3
|
//#region src/value.d.ts
|
|
5
4
|
type Primitive = string | number | boolean | null | undefined;
|
|
@@ -145,6 +144,15 @@ interface CompileOptions {
|
|
|
145
144
|
* @default 10
|
|
146
145
|
*/
|
|
147
146
|
maxPasses?: number;
|
|
147
|
+
/**
|
|
148
|
+
* Tidy the JSX the passes write: drop empty braces, write strings in
|
|
149
|
+
* braces as plain JSX, and unwrap fragments that hold one element. It only
|
|
150
|
+
* changes how the output reads: Solid's JSX transform lowers it to the same
|
|
151
|
+
* code. It runs only on a module the passes changed.
|
|
152
|
+
*
|
|
153
|
+
* @default true
|
|
154
|
+
*/
|
|
155
|
+
tidy?: boolean;
|
|
148
156
|
/**
|
|
149
157
|
* Generate a source map.
|
|
150
158
|
*
|
|
@@ -203,4 +211,4 @@ interface ModuleConstants {
|
|
|
203
211
|
declare function readModuleConstants(code: string, options?: Pick<CompileOptions, 'filename' | 'importedConstants' | 'globalConstants'>): ModuleConstants;
|
|
204
212
|
//#endregion
|
|
205
213
|
export { readModuleConstants as a, SkipPass as c, compile as i, Primitive as l, CompileResult as n, ImportedConstants as o, ModuleConstants as r, Skip as s, CompileOptions as t };
|
|
206
|
-
//# sourceMappingURL=compile-
|
|
214
|
+
//# sourceMappingURL=compile-BKA77zb8.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compile-BKA77zb8.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;;;UCE/D;;;;;;;EAOf;;;;;;;EAOA;;;;;;EAMA;;;;;;;EAOA;;;;;;;EAOA;;;;;;;;EAQA;;;;;;;EAOA;;;;;;;EAOA;;;;;;EAMA,iBAAiB,SAAS;;;;;;;EAO1B;;;;;;EAMA,oBAAoB;;;;;;EAMpB,kBAAkB,SAAS,eAAe;;;;;;EAM1C,mBAAmB,SAAS;;;;;;;;EAQ5B,mBAAmB,SAAS;;;;;;;;EAQ5B;;;;;;EAMA;;;;;;;;EAQA;;;;;;;;;EASA;;;;;;EAMA;;;;;;;EAOA;;UAGe;EACf;;EAEA,KAAK;;;;;EAKL,UAAU;;;;;;;;;;;;;iBAmGI,QAAQ,cAAc,UAAS,iBAAsB;UAqIpD;;;;;EAKf;;;;;;EAMA,SAAS,eAAe;;;;;;;;iBASV,oBACd,cACA,UAAS,KAAK,wEACb"}
|