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.
@@ -896,16 +896,32 @@ var ConstantTable = class {
896
896
  /**
897
897
  * The modules `program` imports or re-exports bindings from. Their
898
898
  * constant exports are what `importedConstants` can hold.
899
+ *
900
+ * An import counts only when one of its bindings is read as a value. A
901
+ * binding read only in types has no constant to fold, and TypeScript drops its
902
+ * import, so the module it names may not even build for this target.
899
903
  */
900
- function namedImportSources(program) {
904
+ function namedImportSources(program, scopes = analyzeScopes(program)) {
901
905
  const sources = /* @__PURE__ */ new Set();
902
906
  for (const statement of program.body) if (statement.type === "ImportDeclaration") {
903
- if (statement.importKind !== "type" && statement.specifiers.some((specifier) => !(specifier.type === "ImportSpecifier" && specifier.importKind === "type"))) sources.add(statement.source.value);
907
+ if (statement.importKind !== "type" && readsAsValue(statement.specifiers, scopes)) sources.add(statement.source.value);
904
908
  } else if (statement.type === "ExportNamedDeclaration" && statement.source || statement.type === "ExportAllDeclaration" && !statement.exported) {
905
909
  if (statement.exportKind !== "type" && statement.source) sources.add(statement.source.value);
906
910
  }
907
911
  return [...sources];
908
912
  }
913
+ /**
914
+ * Whether the module reads one of these import bindings as a value. Scope
915
+ * analysis skips type positions, so a binding used only in types has no
916
+ * references.
917
+ */
918
+ function readsAsValue(specifiers, scopes) {
919
+ for (const specifier of specifiers) {
920
+ if (specifier.type === "ImportSpecifier" && specifier.importKind === "type") continue;
921
+ if (scopes.root.bindings.get(specifier.local.name)?.references.length) return true;
922
+ }
923
+ return false;
924
+ }
909
925
  function exportName(node) {
910
926
  if (node.type === "Identifier") return node.name;
911
927
  if (node.type === "Literal" && typeof node.value === "string") return node.value;
@@ -4506,12 +4522,13 @@ function compile(code, options = {}) {
4506
4522
  */
4507
4523
  function readModuleConstants(code, options = {}) {
4508
4524
  const program = parse(options.filename ?? "input.jsx", code);
4525
+ const scopes = analyzeScopes(program);
4509
4526
  return {
4510
- imports: namedImportSources(program),
4511
- exports: constantExports(program, resolveOptions(options))
4527
+ imports: namedImportSources(program, scopes),
4528
+ exports: constantExports(program, resolveOptions(options), scopes)
4512
4529
  };
4513
4530
  }
4514
4531
  //#endregion
4515
4532
  export { lookup as a, forEachChild as c, unwrap as d, analyzeScopes as i, isIntrinsicTag as l, readModuleConstants as n, scopeAt as o, CONTEXT_SAFE_PRIMITIVES as r, collectParents as s, compile as t, parse as u };
4516
4533
 
4517
- //# sourceMappingURL=compile-Cz6hbiQv.mjs.map
4534
+ //# sourceMappingURL=compile-BpoiBa6b.mjs.map