solid-optimizer 1.0.0-next.0 → 1.0.0-next.1

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/dist/index.mjs CHANGED
@@ -1,2 +1,2 @@
1
- import { n as readModuleConstants, t as compile } from "./compile-Cz6hbiQv.mjs";
1
+ import { n as readModuleConstants, t as compile } from "./compile-BpoiBa6b.mjs";
2
2
  export { compile, readModuleConstants };
package/dist/vite.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { a as lookup, c as forEachChild, d as unwrap, i as analyzeScopes, l as isIntrinsicTag, n as readModuleConstants, o as scopeAt, r as CONTEXT_SAFE_PRIMITIVES, s as collectParents, t as compile, u as parse } from "./compile-Cz6hbiQv.mjs";
1
+ import { a as lookup, c as forEachChild, d as unwrap, i as analyzeScopes, l as isIntrinsicTag, n as readModuleConstants, o as scopeAt, r as CONTEXT_SAFE_PRIMITIVES, s as collectParents, t as compile, u as parse } from "./compile-BpoiBa6b.mjs";
2
2
  import { createRequire } from "node:module";
3
3
  import remapping from "@jridgewell/remapping";
4
4
  import MagicString from "magic-string";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "solid-optimizer",
3
- "version": "1.0.0-next.0",
3
+ "version": "1.0.0-next.1",
4
4
  "description": "Experimental compile-time optimizer for SolidJS",
5
5
  "keywords": [
6
6
  "compiler",
@@ -40,13 +40,13 @@
40
40
  },
41
41
  "devDependencies": {
42
42
  "@jridgewell/trace-mapping": "^0.3.31",
43
- "@solidjs/compiler": "2.0.0-rc.16",
43
+ "@solidjs/compiler": "2.0.0-rc.21",
44
44
  "@solidjs/vite-plugin": "3.0.0-next.50",
45
- "@solidjs/web": "2.0.0-rc.16",
45
+ "@solidjs/web": "2.0.0-rc.21",
46
46
  "@types/node": "^26.6.3",
47
47
  "happy-dom": "^20.14.5",
48
48
  "publint": "^0.3.24",
49
- "solid-js": "2.0.0-rc.16",
49
+ "solid-js": "2.0.0-rc.21",
50
50
  "tsdown": "^0.23.0",
51
51
  "typescript": "^7.0.2",
52
52
  "vite": "^8.3.1",
package/src/compile.ts CHANGED
@@ -324,8 +324,9 @@ export function readModuleConstants(
324
324
  options: Pick<CompileOptions, 'filename' | 'importedConstants' | 'globalConstants'> = {},
325
325
  ): ModuleConstants {
326
326
  const program = parse(options.filename ?? 'input.jsx', code);
327
+ const scopes = analyzeScopes(program);
327
328
  return {
328
- imports: namedImportSources(program),
329
- exports: constantExports(program, resolveOptions(options)),
329
+ imports: namedImportSources(program, scopes),
330
+ exports: constantExports(program, resolveOptions(options), scopes),
330
331
  };
331
332
  }
package/src/constants.ts CHANGED
@@ -5,7 +5,7 @@
5
5
  * from `importedConstants`, which a caller fills with `constantExports` of
6
6
  * each imported module.
7
7
  */
8
- import type { MemberExpression, Node, Program } from 'oxc-parser';
8
+ import type { ImportDeclaration, MemberExpression, Node, Program } from 'oxc-parser';
9
9
  import type { ResolvedOptions } from './context';
10
10
  import { isConstantDeclaration } from './context';
11
11
  import type { Binding, ScopeAnalysis } from './scope';
@@ -171,17 +171,19 @@ export class ConstantTable {
171
171
  /**
172
172
  * The modules `program` imports or re-exports bindings from. Their
173
173
  * constant exports are what `importedConstants` can hold.
174
+ *
175
+ * An import counts only when one of its bindings is read as a value. A
176
+ * binding read only in types has no constant to fold, and TypeScript drops its
177
+ * import, so the module it names may not even build for this target.
174
178
  */
175
- export function namedImportSources(program: Program): string[] {
179
+ export function namedImportSources(
180
+ program: Program,
181
+ scopes: ScopeAnalysis = analyzeScopes(program),
182
+ ): string[] {
176
183
  const sources = new Set<string>();
177
184
  for (const statement of program.body) {
178
185
  if (statement.type === 'ImportDeclaration') {
179
- if (
180
- statement.importKind !== 'type' &&
181
- statement.specifiers.some(
182
- (specifier) => !(specifier.type === 'ImportSpecifier' && specifier.importKind === 'type'),
183
- )
184
- ) {
186
+ if (statement.importKind !== 'type' && readsAsValue(statement.specifiers, scopes)) {
185
187
  sources.add(statement.source.value);
186
188
  }
187
189
  } else if (
@@ -196,6 +198,23 @@ export function namedImportSources(program: Program): string[] {
196
198
  return [...sources];
197
199
  }
198
200
 
201
+ /**
202
+ * Whether the module reads one of these import bindings as a value. Scope
203
+ * analysis skips type positions, so a binding used only in types has no
204
+ * references.
205
+ */
206
+ function readsAsValue(specifiers: ImportDeclaration['specifiers'], scopes: ScopeAnalysis): boolean {
207
+ for (const specifier of specifiers) {
208
+ if (specifier.type === 'ImportSpecifier' && specifier.importKind === 'type') {
209
+ continue;
210
+ }
211
+ if (scopes.root.bindings.get(specifier.local.name)?.references.length) {
212
+ return true;
213
+ }
214
+ }
215
+ return false;
216
+ }
217
+
199
218
  function exportName(node: Node): string | undefined {
200
219
  if (node.type === 'Identifier') {
201
220
  return node.name;