solid-optimizer 0.1.2 → 0.3.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.
Files changed (43) hide show
  1. package/LICENSE +18 -4
  2. package/README.md +269 -14
  3. package/dist/compile-BroGlagZ.d.mts +172 -0
  4. package/dist/compile-BroGlagZ.d.mts.map +1 -0
  5. package/dist/compile-ocDYvJUW.mjs +3910 -0
  6. package/dist/compile-ocDYvJUW.mjs.map +1 -0
  7. package/dist/index.d.mts +2 -0
  8. package/dist/index.mjs +2 -0
  9. package/dist/vite.d.mts +35 -0
  10. package/dist/vite.d.mts.map +1 -0
  11. package/dist/vite.mjs +1465 -0
  12. package/dist/vite.mjs.map +1 -0
  13. package/package.json +60 -58
  14. package/src/ast.ts +263 -0
  15. package/src/compile.ts +304 -0
  16. package/src/constants.ts +249 -0
  17. package/src/context.ts +87 -0
  18. package/src/fold.ts +850 -0
  19. package/src/index.ts +4 -319
  20. package/src/inline.ts +2028 -0
  21. package/src/jsx.ts +170 -0
  22. package/src/memo.ts +383 -0
  23. package/src/provider.ts +842 -0
  24. package/src/scope.ts +588 -0
  25. package/src/server.ts +275 -0
  26. package/src/size.ts +307 -0
  27. package/src/value.ts +386 -0
  28. package/src/vite/index.ts +1135 -0
  29. package/src/vite/inject.ts +311 -0
  30. package/src/vite/namespace.ts +66 -0
  31. package/src/vite/runtime.ts +390 -0
  32. package/src/vite/usage.ts +405 -0
  33. package/dist/cjs/development/index.cjs +0 -316
  34. package/dist/cjs/development/index.cjs.map +0 -7
  35. package/dist/cjs/production/index.cjs +0 -1
  36. package/dist/esm/development/index.mjs +0 -285
  37. package/dist/esm/development/index.mjs.map +0 -7
  38. package/dist/esm/production/index.mjs +0 -1
  39. package/dist/types/index.d.ts +0 -12
  40. package/dist/types/index.d.ts.map +0 -1
  41. package/dist/types/unwrap-node.d.ts +0 -7
  42. package/dist/types/unwrap-node.d.ts.map +0 -1
  43. package/src/unwrap-node.ts +0 -27
package/LICENSE CHANGED
@@ -1,7 +1,21 @@
1
- MIT License Copyright (c) 2022 <author>
1
+ MIT License
2
2
 
3
- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
3
+ Copyright (c) 2025 Alexis Munsayac
4
4
 
5
- The above copyright notice and this permission notice (including the next paragraph) shall be included in all copies or substantial portions of the Software.
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
6
11
 
7
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,8 +1,10 @@
1
1
  # solid-optimizer
2
2
 
3
- > Experimental compile-time optimizer for SolidJS
3
+ > Experimental compile-time optimizer for SolidJS 1.x
4
4
 
5
- [![NPM](https://img.shields.io/npm/v/solid-optimizer.svg)](https://www.npmjs.com/package/solid-optimizer) [![JavaScript Style Guide](https://badgen.net/badge/code%20style/airbnb/ff5a5f?icon=airbnb)](https://github.com/airbnb/javascript)
5
+ [![NPM](https://img.shields.io/npm/v/solid-optimizer.svg)](https://www.npmjs.com/package/solid-optimizer)
6
+
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.
6
8
 
7
9
  ## Install
8
10
 
@@ -18,33 +20,286 @@ yarn add -D solid-optimizer
18
20
  pnpm add -D solid-optimizer
19
21
  ```
20
22
 
21
- ## Features
23
+ ## Usage
24
+
25
+ ```js
26
+ import { compile } from 'solid-optimizer';
27
+
28
+ const result = compile(code, { filename: 'app.jsx' });
29
+
30
+ result.code; // JSX, ready for Solid's JSX transform
31
+ result.map; // a source map, or `null` when nothing changed
32
+ ```
33
+
34
+ The input and the output both keep their JSX. Run the JSX transform after `compile`.
35
+
36
+ `compile` works on a single module or on a bundled chunk that kept its JSX. A chunk holds more components in one scope, so more of them inline.
37
+
38
+ ### Options
39
+
40
+ - `filename` sets the parser and the source map source. `.ts` and `.tsx` parse as TypeScript. Anything else parses as JSX. Defaults to `input.jsx`.
41
+ - `fold` turns constant folding and control-flow resolution on or off. Defaults to `true`.
42
+ - `inline` turns component inlining on or off. Defaults to `true`.
43
+ - `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).
44
+ - `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
+ - `contexts` turns context provider removal on or off. Defaults to `true`.
46
+ - `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
+ - `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', 'solid-js/web']`.
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
+ - `maxPasses` limits how many rounds run. Compilation stops early once a round changes nothing. Defaults to `10`.
52
+ - `sourceMap` turns the source map on or off. Defaults to `true`.
53
+
54
+ ### Constants from other modules
55
+
56
+ `readModuleConstants` reads the constants a module exports, and the modules it imports from.
57
+
58
+ ```js
59
+ import { compile, readModuleConstants } from 'solid-optimizer';
60
+
61
+ const config = readModuleConstants(configCode, { filename: 'config.ts' });
62
+ config.exports; // { SHOW_BANNER: true, THEME: 'light' }
63
+
64
+ compile(appCode, {
65
+ filename: 'app.tsx',
66
+ importedConstants: { './config': config.exports },
67
+ });
68
+ ```
69
+
70
+ It keeps `export const` bindings whose value folds, a `let` the module never writes to, `export default` of a constant, and names exported from them. `import * as config` also works, as `config.NAME`. A module that re-exports constants from another module takes that module's constants in its own `importedConstants`.
22
71
 
23
72
  > **Warning**
24
- > The following features are only for SSR
73
+ > The output changes the shape of the rendered tree, and with it the hydration keys. Compile a server build and its client build from the same code with the same options.
74
+
75
+ ## Vite
76
+
77
+ `solid-optimizer/vite` replaces `vite-plugin-solid`. It takes the same options and wraps the official plugin, so SSR and HMR keep working.
78
+
79
+ ```js
80
+ // vite.config.js
81
+ import { defineConfig } from 'vite';
82
+ import solid from 'solid-optimizer/vite';
25
83
 
26
- ### Trimming no-op
84
+ export default defineConfig({
85
+ plugins: [solid({ ssr: true })],
86
+ });
87
+ ```
88
+
89
+ `vite-plugin-solid` and `vite` are peer dependencies.
90
+
91
+ The plugin optimizes in one of two modes.
92
+
93
+ - **Chunk mode** is for client builds that do not hydrate. Constants fold and memos inline in each module first, so a branch that folds away takes its imports and `lazy()` chunks out of the bundle. Components imported from other modules are inlined there too, so the bundler drops them and the runtime code only they used. JSX is then kept through bundling. Each chunk is optimized as a whole and then lowered by Solid's JSX transform, so a component inlines anywhere in its chunk.
94
+ - **Module mode** is for everything else. Each module is optimized before the official plugin lowers it, with the components it imports from other modules copied in first. A server build and its client build split chunks differently, and hydration needs both to render the same tree, so every decision depends only on the modules. Two modules that import each other do not copy each other's components.
95
+
96
+ Both modes fold constants imported from other modules in the project.
97
+
98
+ - 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 not loaded, since its transform could be waiting for the importer. Its constants still fold in chunk mode.
100
+ - `define` and `import.meta.env` values only fold in chunk mode.
101
+ - Dependencies are not read, and nothing is read while serving.
102
+
103
+ The optimizer is off while serving. Set `optimizer.dev` to run module mode in dev too.
104
+
105
+ ### Options
106
+
107
+ The plugin takes every option of `vite-plugin-solid`, plus `optimizer`.
108
+
109
+ - `optimizer: false` uses `vite-plugin-solid` as it is.
110
+ - `optimizer.fold`, `optimizer.inline`, `optimizer.alwaysInline`, `optimizer.contexts`, `optimizer.memos`, and `optimizer.maxPasses` work like the `compile` options.
111
+ - `optimizer.mode` is `'auto'` by default. Set it to `'module'` to never keep JSX through bundling.
112
+ - `optimizer.dev` also optimizes while serving. Defaults to `false`.
113
+ - `optimizer.server` applies the `server` option in server builds. Defaults to `true`.
27
114
 
28
- The following are no-op functions in SSR, their calls are removed to enable tree-shaking unwanted code.
115
+ ### Limits
29
116
 
30
- - `createEffect`
31
- - `onMount`
117
+ - Chunk mode is skipped when the `babel` option is set, since those Babel plugins need each module.
118
+ - 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
+ - A component used in several chunks is copied into each of them, where each copy is no larger than its call.
120
+ - Components from dependencies in `node_modules` are not copied.
121
+ - Modules matched by the `extensions` option are lowered by the official plugin and are not optimized.
32
122
 
33
- ### `untrack`, `batch` and `startTransition`
123
+ ## Features
124
+
125
+ ### Component inlining
126
+
127
+ A component call is replaced with the component's JSX.
128
+
129
+ ```jsx
130
+ function Title(props) {
131
+ return <h1 class="title">{props.label}</h1>;
132
+ }
133
+
134
+ export function App() {
135
+ return (
136
+ <main>
137
+ <Title label="Hello" />
138
+ </main>
139
+ );
140
+ }
141
+ ```
142
+
143
+ becomes
34
144
 
35
- Passed argument is inlined and called synchronously. For arrow functions, if the function doesn't have the body, it's return expression is inlined instead.
145
+ ```jsx
146
+ export function App() {
147
+ return (
148
+ <main>
149
+ <h1 class="title">{'Hello'}</h1>
150
+ </main>
151
+ );
152
+ }
153
+ ```
36
154
 
37
- ### `createDeferred`
155
+ Solid then creates one template for `<main>` instead of two.
38
156
 
39
- Passed argument is inlined.
157
+ - 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
+ - A static prop that must be evaluated once, like a function read twice, is stored in a `const` first.
159
+ - `{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 component whose returned JSX holds the call. The call must sit directly in that JSX, with only intrinsic elements and fragments around it.
161
+ - Bindings declared in the component get fresh names in every copy.
162
+ - A component nothing else uses is removed.
40
163
 
41
- ### `getListener`
164
+ A component inlines when all of these hold:
42
165
 
43
- `getListener` calls are replaced with `null`.
166
+ - 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.
168
+ - Its body ends in the only `return`, and that `return` returns JSX.
169
+ - It does not use `this`, `arguments`, `super`, or `new.target`.
170
+ - The call site has no spread attribute, no `ref`, and no namespaced attribute.
171
+
172
+ The props can go through `mergeProps()` and `splitProps()` first, declared as a `const` in the component:
173
+
174
+ ```jsx
175
+ function Button(props) {
176
+ const merged = mergeProps({ type: 'button' }, props);
177
+ const [local, rest] = splitProps(merged, ['label']);
178
+ return (
179
+ <button type={merged.type} {...rest}>
180
+ {local.label}
181
+ </button>
182
+ );
183
+ }
184
+ ```
185
+
186
+ - A default has to be a literal, like `'button'`, `0`, or `false`.
187
+ - `splitProps()` has to name its keys in array literals.
188
+ - A view can only be read as `view.name`, spread onto an element, or passed to another `mergeProps()` or `splitProps()`.
189
+ - A prop that can be `undefined` falls back to the default behind it, the way `mergeProps()` reads it.
190
+ - 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
+
192
+ Inlining accepts two differences:
193
+
194
+ - A prop called as `props.name()` runs with its own receiver as `this`, not the props object.
195
+ - Moved statements run before the host's JSX is created. The order of effect registration between siblings can change.
196
+
197
+ Inlined JSX is a copy, so its source map points at the call site it replaced.
198
+
199
+ #### Only where it is smaller
200
+
201
+ Every copy repeats the component's own code, so inlining a component at many calls can make the output larger than the calls were. Before inlining, each component's copies are compared with what they replace, as Solid's JSX transform would lower them:
202
+
203
+ - A copy saves the component call, and the getters of its props. Elements it puts directly in another element join that element's template.
204
+ - A copy costs the component's statements, its dynamic attributes and children, and the elements that cannot join a template. Constant props are folded first, so a branch they rule out costs nothing.
205
+ - When every call inlines and nothing else uses the component, its declaration goes away too.
206
+ - A call in its children that can only inline once it does, because that component has statements to hoist, counts too.
207
+
208
+ A component inlines only when its copies are no larger. A small component, or one used once, inlines at every call. A wrapper used many times, whose root is another component, like most wrappers of a component library, stays a component.
209
+
210
+ In the Vite plugin, a component copied from another module counts the module's share of its declaration: all of it when the importer is its only user, and one part in n when n modules use it, since it goes away once every one of them copies it. The plugin reads which modules use each export from the files the entries reach, and from the module scripts of an HTML entry. A re-export, a dynamic import, a use as a value, or a user the component's module imports back keeps the declaration whole.
211
+
212
+ Set `alwaysInline` to inline every component that can be.
213
+
214
+ ### Context inlining
215
+
216
+ A context provider, `<Ctx.Provider>`, whose readers are all visible is removed, and each read gets the provider's value.
217
+
218
+ ```jsx
219
+ const Theme = createContext();
220
+
221
+ function Label() {
222
+ const theme = useContext(Theme);
223
+ return <span class={theme}>label</span>;
224
+ }
225
+
226
+ export function App() {
227
+ return (
228
+ <main>
229
+ <Theme.Provider value="dark">
230
+ <Label />
231
+ </Theme.Provider>
232
+ </main>
233
+ );
234
+ }
235
+ ```
236
+
237
+ becomes
238
+
239
+ ```jsx
240
+ export function App() {
241
+ const theme$1 = 'dark';
242
+ return (
243
+ <main>
244
+ <span class={'dark'}>label</span>
245
+ </main>
246
+ );
247
+ }
248
+ ```
249
+
250
+ - Everything under the provider has to be visible: intrinsic elements, Solid's built-ins, and components that inline. A call to an unknown function, or a read of a component's `props`, keeps the provider.
251
+ - An object value is stored in a `const` once, so every reader gets the same object.
252
+ - The value must never be `undefined`.
253
+ - Removing the provider removes its owner, so the hydration keys change. Compile a server build and its client build with the same options.
254
+
255
+ See [strategy.md](https://github.com/lxsmnsyc/solid-optimizer/blob/main/strategy.md) for the exact rules.
256
+
257
+ ### Memo inlining
258
+
259
+ A `createMemo` whose result is new on every run, or that sets `equals: false` in its options,, 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
+
261
+ ```jsx
262
+ const style = createMemo(() => ({ color: color() }));
263
+ return <p style={style()} />;
264
+ ```
265
+
266
+ becomes `<p style={{ color: color() }} />`. The computation must take no `prev` parameter, so an initial value, the second argument in Solid 1, is ignored.
267
+
268
+ ### Server builds
269
+
270
+ On the server, Solid renders once and never updates, so its reactive primitives reduce to plain calls.
271
+
272
+ - `createEffect` and `onMount` are removed. Whatever only they used, like a charting library, drops out of the server bundle.
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.
276
+
277
+ This runs after the other optimizations, while modules are transformed. The server and client build then make the same inlining decisions, so hydration still matches.
278
+
279
+ Two differences are accepted. A function passed to `createMemo`, `createRenderEffect`, or `createComputed` no longer gets its own owner, so an `onCleanup` inside it registers on the enclosing one. Inside `catchError` or `<ErrorBoundary>`, an error it throws stops the component instead of leaving the memo `undefined`.
280
+
281
+ ### Constant folding and control flow
282
+
283
+ This follows the `optimize` option of Solid 2.0's `@solidjs/compiler` ([solidjs/solid#3231](https://github.com/solidjs/solid/pull/3231)), applied to Solid 1's components.
284
+
285
+ - Constant expressions fold, including `const` bindings and `let` bindings nothing writes to, at any scope.
286
+ - Branches that a constant condition never takes are removed. So are statements after a `return`, `throw`, `break`, or `continue`.
287
+ - `<Show when>` becomes its children or its `fallback`.
288
+ - `<For each>` becomes its `fallback` when `each` is an empty array literal or a falsy constant.
289
+ - `<Index each>` becomes its `fallback` under the same conditions as `<For each>`.
290
+ - `<Switch>` drops each `<Match>` that is always false, and becomes the first `<Match>` that is always true.
291
+ - `<Dynamic component="div">` becomes `<div>`.
292
+
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>`, `<Suspense>`, `<SuspenseList>`, and `<ErrorBoundary>` never fold.
294
+
295
+ 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
+
297
+ A condition that is discarded but has side effects still runs. `[effect()] && value` becomes `([effect()], value)`.
44
298
 
45
299
  ## Sponsors
46
300
 
47
301
  ![Sponsors](https://github.com/lxsmnsyc/sponsors/blob/main/sponsors.svg?raw=true)
302
+
48
303
  ## License
49
304
 
50
305
  MIT © [lxsmnsyc](https://github.com/lxsmnsyc)
@@ -0,0 +1,172 @@
1
+ import { SourceMap } from "@jridgewell/remapping";
2
+ import MagicString from "magic-string";
3
+ import "oxc-parser";
4
+ //#region src/value.d.ts
5
+ type Primitive = string | number | boolean | null | undefined;
6
+ //#endregion
7
+ //#region src/constants.d.ts
8
+ /**
9
+ * The constants each imported module exports, keyed by the import specifier
10
+ * as the module writes it, then by export name.
11
+ */
12
+ type ImportedConstants = Readonly<Record<string, Readonly<Record<string, Primitive>>>>;
13
+ //#endregion
14
+ //#region src/compile.d.ts
15
+ interface CompileOptions {
16
+ /**
17
+ * The file name, used to pick the parser (`.ts` and `.tsx` parse as
18
+ * TypeScript, anything else as JSX) and as the source in the source map.
19
+ *
20
+ * @default 'input.jsx'
21
+ */
22
+ filename?: string;
23
+ /**
24
+ * Fold constants, remove unreachable code, and resolve control-flow
25
+ * components whose props are constants.
26
+ *
27
+ * @default true
28
+ */
29
+ fold?: boolean;
30
+ /**
31
+ * Replace component calls with the component's body.
32
+ *
33
+ * @default true
34
+ */
35
+ 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
+ /**
50
+ * Remove context providers whose reads are all visible, and give each
51
+ * read the provider's value.
52
+ *
53
+ * @default true
54
+ */
55
+ contexts?: boolean;
56
+ /**
57
+ * Replace a `createMemo` that always produces a new value and is read once
58
+ * with its computation.
59
+ *
60
+ * @default true
61
+ */
62
+ memos?: boolean;
63
+ /**
64
+ * The names of Solid's built-in components. A tag only folds when it is
65
+ * one of these, and an empty list turns control-flow folding off.
66
+ *
67
+ * @default ['For', 'Show', 'Switch', 'Match', 'Suspense', 'SuspenseList', 'Portal', 'Index', 'Dynamic', 'ErrorBoundary']
68
+ */
69
+ builtIns?: readonly string[];
70
+ /**
71
+ * The modules that export Solid's built-in components. A tag imported from
72
+ * anywhere else is a different component.
73
+ *
74
+ * @default ['solid-js', 'solid-js/web']
75
+ */
76
+ moduleSources?: readonly string[];
77
+ /**
78
+ * Top-level names that refer to Solid's built-in components, mapped to the
79
+ * built-in's name. A bundler renames bindings, so a chunk can call `Show`
80
+ * something else, or declare it instead of importing it.
81
+ */
82
+ builtInAliases?: Readonly<Record<string, string>>;
83
+ /**
84
+ * Treat a top-level `var` that nothing writes to as a constant. Bundlers
85
+ * turn top-level `const` into `var`, so this is on for bundled chunks.
86
+ *
87
+ * @default false
88
+ */
89
+ constantVars?: boolean;
90
+ /**
91
+ * The constants imported modules export, keyed by the import specifier as
92
+ * the code writes it, then by export name. An import of one of them folds
93
+ * like a local `const`. `constantExports` reads them from a module.
94
+ */
95
+ importedConstants?: ImportedConstants;
96
+ /**
97
+ * The exports of imported modules that are contexts made by Solid's
98
+ * `createContext`, keyed by the import specifier as the code writes it.
99
+ * A provider of an imported context can be removed like a local one.
100
+ */
101
+ importedContexts?: Readonly<Record<string, readonly string[]>>;
102
+ /**
103
+ * Top-level components that other modules use too, by the number of
104
+ * modules that use them, this one included. Inlining one here only counts
105
+ * its share of the declaration, which goes away once every one of them
106
+ * inlines it. `0` keeps it whatever is inlined, like a component that is
107
+ * also passed as a value.
108
+ */
109
+ sharedComponents?: Readonly<Record<string, number>>;
110
+ /**
111
+ * Inline every component that can be, even where the copies are larger
112
+ * than the calls and declaration they replace. By default, a component is
113
+ * only inlined where its copies are estimated to be no larger.
114
+ *
115
+ * @default false
116
+ */
117
+ alwaysInline?: boolean;
118
+ /**
119
+ * The most passes to run. One pass can expose work for the next, such as
120
+ * an inlined component whose props now fold. Compilation stops early once
121
+ * a pass changes nothing.
122
+ *
123
+ * @default 10
124
+ */
125
+ maxPasses?: number;
126
+ /**
127
+ * Generate a source map.
128
+ *
129
+ * @default true
130
+ */
131
+ sourceMap?: boolean;
132
+ }
133
+ interface CompileResult {
134
+ code: string;
135
+ /** The map from the output back to the input, or `null` when nothing changed or maps are off. */
136
+ map: SourceMap | null;
137
+ }
138
+ /**
139
+ * Optimizes JSX before it is lowered by Solid's JSX transform.
140
+ *
141
+ * The input is JavaScript or TypeScript with JSX, such as a module, or a
142
+ * bundled chunk that kept its JSX. The output keeps JSX too, so the JSX
143
+ * transform runs after this.
144
+ *
145
+ * The output changes the shape of the rendered tree, and with it the
146
+ * hydration keys. A server build and its client build must compile the same
147
+ * code with the same options.
148
+ */
149
+ declare function compile(code: string, options?: CompileOptions): CompileResult;
150
+ interface ModuleConstants {
151
+ /**
152
+ * The modules this module imports or re-exports named bindings from, as
153
+ * written. `importedConstants` of `compile` takes their constants.
154
+ */
155
+ imports: string[];
156
+ /**
157
+ * The constants this module exports, by export name: `export const`
158
+ * bindings whose value folds, names exported from them, and names
159
+ * re-exported from `importedConstants`.
160
+ */
161
+ exports: Record<string, Primitive>;
162
+ }
163
+ /**
164
+ * Reads what a module imports and the constants it exports, so that
165
+ * `compile` can fold them in the modules that import it.
166
+ *
167
+ * Only `filename` and `importedConstants` of the options are used.
168
+ */
169
+ declare function readModuleConstants(code: string, options?: Pick<CompileOptions, 'filename' | 'importedConstants'>): ModuleConstants;
170
+ //#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-BroGlagZ.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compile-BroGlagZ.d.mts","names":[],"sources":["../src/value.ts","../src/constants.ts","../src/compile.ts"],"mappings":";;;;KAUY;;;;;;;KCSA,oBAAoB,SAAS,eAAe,SAAS,eAAe;;;UCJ/D;;;;;;;EAOf;;;;;;;EAOA;;;;;;EAMA;;;;;;;;;;;;;EAaA;;;;;;;EAOA;;;;;;;EAOA;;;;;;;EAOA;;;;;;;EAOA;;;;;;EAMA,iBAAiB,SAAS;;;;;;;EAO1B;;;;;;EAMA,oBAAoB;;;;;;EAMpB,mBAAmB,SAAS;;;;;;;;EAQ5B,mBAAmB,SAAS;;;;;;;;EAQ5B;;;;;;;;EAQA;;;;;;EAMA;;UAGe;EACf;;EAEA,KAAK;;;;;;;;;;;;;iBAkFS,QAAQ,cAAc,UAAS,iBAAsB;UAuDpD;;;;;EAKf;;;;;;EAMA,SAAS,eAAe;;;;;;;;iBASV,oBACd,cACA,UAAS,KAAK,oDACb"}