solid-optimizer 0.3.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 +94 -42
- package/dist/{compile-BroGlagZ.d.mts → compile-BRCj4UN7.d.mts} +39 -19
- package/dist/compile-BRCj4UN7.d.mts.map +1 -0
- package/dist/{compile-ocDYvJUW.mjs → compile-Cz6hbiQv.mjs} +1312 -705
- package/dist/compile-Cz6hbiQv.mjs.map +1 -0
- package/dist/index.d.mts +2 -2
- package/dist/index.mjs +1 -1
- package/dist/vite.d.mts +21 -10
- package/dist/vite.d.mts.map +1 -1
- package/dist/vite.mjs +648 -269
- package/dist/vite.mjs.map +1 -1
- package/package.json +10 -11
- package/src/ast.ts +12 -4
- package/src/compile.ts +69 -42
- package/src/constants.ts +42 -2
- package/src/context.ts +32 -0
- package/src/copy-size.ts +73 -0
- package/src/fold.ts +619 -17
- package/src/index.ts +1 -0
- package/src/inline.ts +568 -299
- package/src/memo.ts +197 -33
- package/src/provider.ts +104 -82
- package/src/scope.ts +14 -1
- package/src/size.ts +35 -73
- package/src/vite/globals.ts +67 -0
- package/src/vite/index.ts +475 -217
- package/src/vite/inject.ts +51 -2
- package/src/vite/refs.ts +99 -0
- package/src/vite/report.ts +74 -0
- package/src/vite/runtime.ts +3 -3
- package/dist/compile-BroGlagZ.d.mts.map +0 -1
- package/dist/compile-ocDYvJUW.mjs.map +0 -1
- package/src/server.ts +0 -275
package/README.md
CHANGED
|
@@ -1,23 +1,27 @@
|
|
|
1
1
|
# solid-optimizer
|
|
2
2
|
|
|
3
|
-
> Experimental compile-time optimizer for SolidJS
|
|
3
|
+
> Experimental compile-time optimizer for SolidJS 2.0
|
|
4
4
|
|
|
5
5
|
[](https://www.npmjs.com/package/solid-optimizer)
|
|
6
6
|
|
|
7
7
|
`solid-optimizer` rewrites JSX before Solid's JSX transform lowers it. It inlines components and resolves control flow whose outcome is known at build time, so more markup lands in fewer templates.
|
|
8
8
|
|
|
9
|
+

|
|
10
|
+
|
|
9
11
|
## Install
|
|
10
12
|
|
|
13
|
+
The Solid 2.0 version is published under the `next` tag. The `latest` version is for Solid 1.x.
|
|
14
|
+
|
|
11
15
|
```bash
|
|
12
|
-
npm i -D solid-optimizer
|
|
16
|
+
npm i -D solid-optimizer@next
|
|
13
17
|
```
|
|
14
18
|
|
|
15
19
|
```bash
|
|
16
|
-
yarn add -D solid-optimizer
|
|
20
|
+
yarn add -D solid-optimizer@next
|
|
17
21
|
```
|
|
18
22
|
|
|
19
23
|
```bash
|
|
20
|
-
pnpm add -D solid-optimizer
|
|
24
|
+
pnpm add -D solid-optimizer@next
|
|
21
25
|
```
|
|
22
26
|
|
|
23
27
|
## Usage
|
|
@@ -44,12 +48,13 @@ The input and the output both keep their JSX. Run the JSX transform after `compi
|
|
|
44
48
|
- `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.
|
|
45
49
|
- `contexts` turns context provider removal on or off. Defaults to `true`.
|
|
46
50
|
- `memos` turns memo inlining on or off. Defaults to `true`.
|
|
47
|
-
- `server` compiles for the server. It removes `createEffect` and `onMount`, and reduces `untrack`, `batch`, `startTransition`, `createDeferred`, `getListener`, `createMemo`, `createRenderEffect`, and `createComputed` to what they do on the server. Defaults to `false`.
|
|
48
51
|
- `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.
|
|
49
|
-
- `moduleSources` lists the modules Solid's built-ins are imported from. Defaults to `['solid-js', '
|
|
52
|
+
- `moduleSources` lists the modules Solid's built-ins are imported from. Defaults to `['solid-js', '@solidjs/web']`.
|
|
50
53
|
- `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).
|
|
54
|
+
- `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.
|
|
51
55
|
- `maxPasses` limits how many rounds run. Compilation stops early once a round changes nothing. Defaults to `10`.
|
|
52
56
|
- `sourceMap` turns the source map on or off. Defaults to `true`.
|
|
57
|
+
- `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
58
|
|
|
54
59
|
### Constants from other modules
|
|
55
60
|
|
|
@@ -74,7 +79,7 @@ It keeps `export const` bindings whose value folds, a `let` the module never wri
|
|
|
74
79
|
|
|
75
80
|
## Vite
|
|
76
81
|
|
|
77
|
-
`solid-optimizer/vite` replaces
|
|
82
|
+
`solid-optimizer/vite` replaces `@solidjs/vite-plugin`. It takes the same options and wraps the official plugin, so SSR, server functions, and HMR keep working.
|
|
78
83
|
|
|
79
84
|
```js
|
|
80
85
|
// vite.config.js
|
|
@@ -86,7 +91,7 @@ export default defineConfig({
|
|
|
86
91
|
});
|
|
87
92
|
```
|
|
88
93
|
|
|
89
|
-
|
|
94
|
+
`@solidjs/vite-plugin` and `vite` are peer dependencies.
|
|
90
95
|
|
|
91
96
|
The plugin optimizes in one of two modes.
|
|
92
97
|
|
|
@@ -96,29 +101,52 @@ The plugin optimizes in one of two modes.
|
|
|
96
101
|
Both modes fold constants imported from other modules in the project.
|
|
97
102
|
|
|
98
103
|
- Each import is resolved and loaded by the bundler, so aliases, virtual modules, and plugins that rewrite the module are respected.
|
|
99
|
-
- A module with JSX is
|
|
100
|
-
- `define` and `import.meta.env` values
|
|
104
|
+
- A module with JSX is read from this plugin's own output for it. It is skipped when it imports the importer, directly or through other modules of the project, since the two transforms would wait for each other.
|
|
105
|
+
- `define` entries and `import.meta.env` values fold in both modes, when every build environment gives them the same primitive value. `import.meta.env.SSR` never folds, since the server and client builds differ on it.
|
|
101
106
|
- Dependencies are not read, and nothing is read while serving.
|
|
102
107
|
|
|
103
108
|
The optimizer is off while serving. Set `optimizer.dev` to run module mode in dev too.
|
|
104
109
|
|
|
105
110
|
### Options
|
|
106
111
|
|
|
107
|
-
The plugin takes every option of
|
|
112
|
+
The plugin takes every option of `@solidjs/vite-plugin`, plus `optimizer`.
|
|
108
113
|
|
|
109
|
-
- `optimizer: false` uses
|
|
114
|
+
- `optimizer: false` uses `@solidjs/vite-plugin` as it is.
|
|
110
115
|
- `optimizer.fold`, `optimizer.inline`, `optimizer.alwaysInline`, `optimizer.contexts`, `optimizer.memos`, and `optimizer.maxPasses` work like the `compile` options.
|
|
111
116
|
- `optimizer.mode` is `'auto'` by default. Set it to `'module'` to never keep JSX through bundling.
|
|
112
117
|
- `optimizer.dev` also optimizes while serving. Defaults to `false`.
|
|
113
|
-
- `optimizer.
|
|
118
|
+
- `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`.
|
|
119
|
+
|
|
120
|
+
### Report
|
|
121
|
+
|
|
122
|
+
`optimizer.report` lists each component call, provider, and memo the optimizer left alone, grouped by reason:
|
|
123
|
+
|
|
124
|
+
```
|
|
125
|
+
solid-optimizer: what stays as written in client
|
|
126
|
+
inline lazy 4 About, Chart, Dashboard, Settings
|
|
127
|
+
inline copy-no-host 1 Home (./pages/Home)
|
|
128
|
+
inline no-host 1 Home
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
Each line is a pass, a reason, how many times it happened, and the names it happened to. The reasons for the inline pass:
|
|
132
|
+
|
|
133
|
+
- `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.
|
|
134
|
+
- `component-params`, `component-body`, `component-return`, `component-async`, `component-recursive`, and `component-this` mean the component's own shape is not supported.
|
|
135
|
+
- `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 or a function, and `ref-use` means the component uses `props.ref` other than as a `ref`.
|
|
136
|
+
- `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.
|
|
137
|
+
- `size` means the copies would be larger than the calls.
|
|
138
|
+
- `lazy`, `imported`, `nested`, and `not-a-function` mean the tag is not a component declared at the top of the same module or chunk.
|
|
139
|
+
- 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.
|
|
140
|
+
|
|
141
|
+
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
142
|
|
|
115
143
|
### Limits
|
|
116
144
|
|
|
117
|
-
- Chunk mode is skipped when the `babel` option is set
|
|
145
|
+
- Chunk mode is skipped when the `babel` option is set or `compiler` is `'babel'`, since those passes need each module.
|
|
118
146
|
- 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.
|
|
119
147
|
- A component used in several chunks is copied into each of them, where each copy is no larger than its call.
|
|
120
148
|
- Components from dependencies in `node_modules` are not copied.
|
|
121
|
-
-
|
|
149
|
+
- `.tsrx` modules are lowered by the official plugin and are not optimized.
|
|
122
150
|
|
|
123
151
|
## Features
|
|
124
152
|
|
|
@@ -157,36 +185,40 @@ Solid then creates one template for `<main>` instead of two.
|
|
|
157
185
|
- A read of `props.name` becomes the attribute's expression. Solid passes dynamic props as getters, so the expression runs at every read, as before.
|
|
158
186
|
- A static prop that must be evaluated once, like a function read twice, is stored in a `const` first.
|
|
159
187
|
- `{props.children}`, and a prop whose value is JSX, splice their JSX in place so it joins the template.
|
|
160
|
-
- Statements in the component body move into the
|
|
188
|
+
- Statements in the component body move into the function whose returned JSX holds the call. The call must sit directly in that JSX, with only intrinsic elements and fragments around it. The function must run untracked, once each time it creates that JSX:
|
|
189
|
+
- a component;
|
|
190
|
+
- the child callback of `<For>` or `<Repeat>`;
|
|
191
|
+
- the child callback of `<Show>` or `<Match>`, when it takes the value;
|
|
192
|
+
- the callback given to `render`.
|
|
161
193
|
- Bindings declared in the component get fresh names in every copy.
|
|
162
194
|
- A component nothing else uses is removed.
|
|
163
195
|
|
|
164
196
|
A component inlines when all of these hold:
|
|
165
197
|
|
|
166
198
|
- 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 `
|
|
199
|
+
- Its parameter is one identifier that is only read as `props.name`, spread onto an element as `{...props}`, or passed to `merge()` and `omit()`. See below.
|
|
168
200
|
- Its body ends in the only `return`, and that `return` returns JSX.
|
|
169
201
|
- It does not use `this`, `arguments`, `super`, or `new.target`.
|
|
170
|
-
- The call site has no spread attribute
|
|
202
|
+
- The call site has no spread attribute and no namespaced attribute.
|
|
203
|
+
- A `ref` at the call site moves to the element the component gives `props.ref` to, when its value is a name, a function, or an array of them, and the component only uses `props.ref` as the `ref` of an element, of another component, or in a spread. Both run while the element is made, untracked, so the element gets the same ref.
|
|
171
204
|
|
|
172
|
-
The props can go through `
|
|
205
|
+
The props can go through `merge()` and `omit()` first, declared as a `const` in the component:
|
|
173
206
|
|
|
174
207
|
```jsx
|
|
175
208
|
function Button(props) {
|
|
176
|
-
const merged =
|
|
177
|
-
const
|
|
209
|
+
const merged = merge({ type: 'button' }, props);
|
|
210
|
+
const rest = omit(merged, 'label');
|
|
178
211
|
return (
|
|
179
212
|
<button type={merged.type} {...rest}>
|
|
180
|
-
{
|
|
213
|
+
{props.label}
|
|
181
214
|
</button>
|
|
182
215
|
);
|
|
183
216
|
}
|
|
184
217
|
```
|
|
185
218
|
|
|
186
219
|
- A default has to be a literal, like `'button'`, `0`, or `false`.
|
|
187
|
-
- `
|
|
188
|
-
- A view can only be read as `view.name`, spread onto an element, or passed to another `
|
|
189
|
-
- A prop that can be `undefined` falls back to the default behind it, the way `mergeProps()` reads it.
|
|
220
|
+
- `omit()` has to name its keys as string literals.
|
|
221
|
+
- A view can only be read as `view.name`, spread onto an element, or passed to another `merge()` or `omit()`.
|
|
190
222
|
- A spread becomes the attributes the call site passes, and it cannot repeat an attribute the element already has. Its `children` become the element's children, so the element must have none of its own.
|
|
191
223
|
|
|
192
224
|
Inlining accepts two differences:
|
|
@@ -213,7 +245,7 @@ Set `alwaysInline` to inline every component that can be.
|
|
|
213
245
|
|
|
214
246
|
### Context inlining
|
|
215
247
|
|
|
216
|
-
A context provider
|
|
248
|
+
A context provider whose readers are all visible is removed, and each read gets the provider's value.
|
|
217
249
|
|
|
218
250
|
```jsx
|
|
219
251
|
const Theme = createContext();
|
|
@@ -226,9 +258,9 @@ function Label() {
|
|
|
226
258
|
export function App() {
|
|
227
259
|
return (
|
|
228
260
|
<main>
|
|
229
|
-
<Theme
|
|
261
|
+
<Theme value="dark">
|
|
230
262
|
<Label />
|
|
231
|
-
</Theme
|
|
263
|
+
</Theme>
|
|
232
264
|
</main>
|
|
233
265
|
);
|
|
234
266
|
}
|
|
@@ -256,41 +288,61 @@ See [strategy.md](https://github.com/lxsmnsyc/solid-optimizer/blob/main/strategy
|
|
|
256
288
|
|
|
257
289
|
### Memo inlining
|
|
258
290
|
|
|
259
|
-
A `createMemo` whose result is new on every run,
|
|
291
|
+
A `createMemo` whose result is new on every run, such as an object, array, or JSX, never stops an update. When it is also read once, as the whole of a tracked JSX expression, the read runs the computation itself.
|
|
260
292
|
|
|
261
293
|
```jsx
|
|
262
294
|
const style = createMemo(() => ({ color: color() }));
|
|
263
295
|
return <p style={style()} />;
|
|
264
296
|
```
|
|
265
297
|
|
|
266
|
-
becomes `<p style={{ color: color() }} />`.
|
|
298
|
+
becomes `<p style={{ color: color() }} />`. See [strategy.md](https://github.com/lxsmnsyc/solid-optimizer/blob/main/strategy.md) for the exact rules.
|
|
267
299
|
|
|
268
|
-
|
|
300
|
+
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.
|
|
269
301
|
|
|
270
|
-
|
|
302
|
+
```jsx
|
|
303
|
+
const size = createMemo(() => 1 + 2);
|
|
304
|
+
return <p>{size() * 2}</p>;
|
|
305
|
+
```
|
|
271
306
|
|
|
272
|
-
|
|
273
|
-
- `untrack(fn)` and `batch(fn)` become `fn()`, and `startTransition(fn)` calls `fn()` and returns nothing.
|
|
274
|
-
- `createDeferred(source)` becomes `source`, and `getListener()` becomes `null`.
|
|
275
|
-
- `createMemo`, `createRenderEffect`, and `createComputed` run their function once, in place.
|
|
307
|
+
becomes `<p>{6}</p>`.
|
|
276
308
|
|
|
277
|
-
|
|
309
|
+
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.
|
|
278
310
|
|
|
279
|
-
|
|
311
|
+
```jsx
|
|
312
|
+
const c = children(() => <b>x</b>);
|
|
313
|
+
return <div>{c()}</div>;
|
|
314
|
+
```
|
|
315
|
+
|
|
316
|
+
becomes `<div><b>x</b></div>`. This is what a component that calls `children(() => props.children)` leaves once it is inlined with JSX children.
|
|
280
317
|
|
|
281
318
|
### Constant folding and control flow
|
|
282
319
|
|
|
283
|
-
This follows the `optimize` option of
|
|
320
|
+
This follows the `optimize` option of `@solidjs/compiler` ([solidjs/solid#3231](https://github.com/solidjs/solid/pull/3231)).
|
|
284
321
|
|
|
285
322
|
- Constant expressions fold, including `const` bindings and `let` bindings nothing writes to, at any scope.
|
|
286
323
|
- Branches that a constant condition never takes are removed. So are statements after a `return`, `throw`, `break`, or `continue`.
|
|
287
324
|
- `<Show when>` becomes its children or its `fallback`.
|
|
288
325
|
- `<For each>` becomes its `fallback` when `each` is an empty array literal or a falsy constant.
|
|
289
|
-
- `<
|
|
326
|
+
- `<For>` over a constant list becomes one copy of its row per item, when the copies are estimated to be no larger than the loop. The list is an array literal, or a `const` of one that only `<For>` reads and that is not exported. Each item is a primitive literal, or an object literal of them. The row has to be an arrow function whose body is JSX without a `ref` or a spread, and read the item as `item.key`, or as itself when it is a primitive.
|
|
327
|
+
|
|
328
|
+
```jsx
|
|
329
|
+
const LINKS = [
|
|
330
|
+
{ href: '/', label: 'Home' },
|
|
331
|
+
{ href: '/docs', label: 'Docs' },
|
|
332
|
+
];
|
|
333
|
+
<nav>
|
|
334
|
+
<For each={LINKS}>{(link) => <a href={link.href}>{link.label}</a>}</For>
|
|
335
|
+
</nav>;
|
|
336
|
+
```
|
|
337
|
+
|
|
338
|
+
becomes `<nav><a href={'/'}>{'Home'}</a><a href={'/docs'}>{'Docs'}</a></nav>`, which lowers to one template. Each row had its own owner, so this shifts the hydration keys after it.
|
|
339
|
+
|
|
340
|
+
- `<Repeat count>` becomes its `fallback` when `count` is below one.
|
|
290
341
|
- `<Switch>` drops each `<Match>` that is always false, and becomes the first `<Match>` that is always true.
|
|
291
|
-
- `<Dynamic component="div">` becomes `<div>`.
|
|
342
|
+
- `<Dynamic component="div">` becomes `<div>`. `<Dynamic component={Card}>` becomes `<Card>` when `Card` is a capitalized component declared at the top level, as a function or with `lazy`, that nothing reassigns. An imported component stays, since an import could hold a tag name.
|
|
343
|
+
- A call of an arrow function whose body is JSX, such as a render prop left by inlining, becomes the JSX when it is an element's child and each argument is a constant or a binding nothing reassigns. `{((n) => <li>{n}</li>)(1)}` becomes `<li>{1}</li>`. A `ref` or a spread in the JSX keeps the call, since both run while the JSX is made.
|
|
292
344
|
|
|
293
|
-
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>`, `<
|
|
345
|
+
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.
|
|
294
346
|
|
|
295
347
|
A call to Solid's `lazy` is marked `/* @__PURE__ */`, so the bundler drops one that a folded branch left unused, along with its chunk.
|
|
296
348
|
|
|
@@ -4,6 +4,21 @@ import "oxc-parser";
|
|
|
4
4
|
//#region src/value.d.ts
|
|
5
5
|
type Primitive = string | number | boolean | null | undefined;
|
|
6
6
|
//#endregion
|
|
7
|
+
//#region src/context.d.ts
|
|
8
|
+
/** The passes that record what they leave alone. */
|
|
9
|
+
type SkipPass = 'inline' | 'contexts' | 'memos';
|
|
10
|
+
/**
|
|
11
|
+
* Something a pass left alone, and why. The `compile` option `report`
|
|
12
|
+
* collects them.
|
|
13
|
+
*/
|
|
14
|
+
interface Skip {
|
|
15
|
+
readonly pass: SkipPass;
|
|
16
|
+
/** A short code for the reason, like `call-spread`. */
|
|
17
|
+
readonly reason: string;
|
|
18
|
+
/** The component, context, or memo it is about. */
|
|
19
|
+
readonly name: string;
|
|
20
|
+
}
|
|
21
|
+
//#endregion
|
|
7
22
|
//#region src/constants.d.ts
|
|
8
23
|
/**
|
|
9
24
|
* The constants each imported module exports, keyed by the import specifier
|
|
@@ -33,19 +48,6 @@ interface CompileOptions {
|
|
|
33
48
|
* @default true
|
|
34
49
|
*/
|
|
35
50
|
inline?: boolean;
|
|
36
|
-
/**
|
|
37
|
-
* Compile for the server: remove `createEffect` and `onMount`, and reduce
|
|
38
|
-
* `untrack`, `batch`, `startTransition`, `createDeferred`, `getListener`,
|
|
39
|
-
* `createMemo`, `createRenderEffect`, and `createComputed` to what they do
|
|
40
|
-
* on the server.
|
|
41
|
-
*
|
|
42
|
-
* This runs once, after the other passes. The server and client build
|
|
43
|
-
* make the same folding and inlining decisions from the same code, so the
|
|
44
|
-
* server renders the tree the client hydrates.
|
|
45
|
-
*
|
|
46
|
-
* @default false
|
|
47
|
-
*/
|
|
48
|
-
server?: boolean;
|
|
49
51
|
/**
|
|
50
52
|
* Remove context providers whose reads are all visible, and give each
|
|
51
53
|
* read the provider's value.
|
|
@@ -64,14 +66,14 @@ interface CompileOptions {
|
|
|
64
66
|
* The names of Solid's built-in components. A tag only folds when it is
|
|
65
67
|
* one of these, and an empty list turns control-flow folding off.
|
|
66
68
|
*
|
|
67
|
-
* @default ['For', 'Show', 'Switch', 'Match', '
|
|
69
|
+
* @default ['For', 'Show', 'Switch', 'Match', 'Loading', 'Reveal', 'Portal', 'Repeat', 'Dynamic', 'Errored']
|
|
68
70
|
*/
|
|
69
71
|
builtIns?: readonly string[];
|
|
70
72
|
/**
|
|
71
73
|
* The modules that export Solid's built-in components. A tag imported from
|
|
72
74
|
* anywhere else is a different component.
|
|
73
75
|
*
|
|
74
|
-
* @default ['solid-js', '
|
|
76
|
+
* @default ['solid-js', '@solidjs/web']
|
|
75
77
|
*/
|
|
76
78
|
moduleSources?: readonly string[];
|
|
77
79
|
/**
|
|
@@ -93,6 +95,12 @@ interface CompileOptions {
|
|
|
93
95
|
* like a local `const`. `constantExports` reads them from a module.
|
|
94
96
|
*/
|
|
95
97
|
importedConstants?: ImportedConstants;
|
|
98
|
+
/**
|
|
99
|
+
* Values of global names and paths that fold like constants, such as the
|
|
100
|
+
* `define` entries of a bundler: `{ __DEV__: false, 'import.meta.env.MODE': 'production' }`.
|
|
101
|
+
* A path starts at `import.meta` or at a name the module does not declare.
|
|
102
|
+
*/
|
|
103
|
+
globalConstants?: Readonly<Record<string, Primitive>>;
|
|
96
104
|
/**
|
|
97
105
|
* The exports of imported modules that are contexts made by Solid's
|
|
98
106
|
* `createContext`, keyed by the import specifier as the code writes it.
|
|
@@ -129,11 +137,23 @@ interface CompileOptions {
|
|
|
129
137
|
* @default true
|
|
130
138
|
*/
|
|
131
139
|
sourceMap?: boolean;
|
|
140
|
+
/**
|
|
141
|
+
* Record what the inline, provider, and memo passes leave alone, and why.
|
|
142
|
+
* The result lists them in `skipped`.
|
|
143
|
+
*
|
|
144
|
+
* @default false
|
|
145
|
+
*/
|
|
146
|
+
report?: boolean;
|
|
132
147
|
}
|
|
133
148
|
interface CompileResult {
|
|
134
149
|
code: string;
|
|
135
150
|
/** The map from the output back to the input, or `null` when nothing changed or maps are off. */
|
|
136
151
|
map: SourceMap | null;
|
|
152
|
+
/**
|
|
153
|
+
* What the last round left alone, and why, when `report` is set. The last
|
|
154
|
+
* round changes nothing, unless `maxPasses` stopped the rounds first.
|
|
155
|
+
*/
|
|
156
|
+
skipped?: Skip[];
|
|
137
157
|
}
|
|
138
158
|
/**
|
|
139
159
|
* Optimizes JSX before it is lowered by Solid's JSX transform.
|
|
@@ -164,9 +184,9 @@ interface ModuleConstants {
|
|
|
164
184
|
* Reads what a module imports and the constants it exports, so that
|
|
165
185
|
* `compile` can fold them in the modules that import it.
|
|
166
186
|
*
|
|
167
|
-
* Only `filename` and `
|
|
187
|
+
* Only `filename`, `importedConstants`, and `globalConstants` of the options are used.
|
|
168
188
|
*/
|
|
169
|
-
declare function readModuleConstants(code: string, options?: Pick<CompileOptions, 'filename' | 'importedConstants'>): ModuleConstants;
|
|
189
|
+
declare function readModuleConstants(code: string, options?: Pick<CompileOptions, 'filename' | 'importedConstants' | 'globalConstants'>): ModuleConstants;
|
|
170
190
|
//#endregion
|
|
171
|
-
export { readModuleConstants as a, compile as i, CompileResult as n, ImportedConstants as o, ModuleConstants as r,
|
|
172
|
-
//# sourceMappingURL=compile-
|
|
191
|
+
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 };
|
|
192
|
+
//# sourceMappingURL=compile-BRCj4UN7.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compile-BRCj4UN7.d.mts","names":[],"sources":["../src/value.ts","../src/context.ts","../src/constants.ts","../src/compile.ts"],"mappings":";;;;KAUY;;;;KC0DA;;;;;UAMK;WACN,MAAM;;WAEN;;WAEA;;;;;;;;KC5DC,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;;;;;;;;EAQA;;;;;;EAMA;;;;;;;EAOA;;UAGe;EACf;;EAEA,KAAK;;;;;EAKL,UAAU;;;;;;;;;;;;;iBAmGI,QAAQ,cAAc,UAAS,iBAAsB;UA0DpD;;;;;EAKf;;;;;;EAMA,SAAS,eAAe;;;;;;;;iBASV,oBACd,cACA,UAAS,KAAK,wEACb"}
|