solid-optimizer 0.3.0 → 0.4.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.
@@ -1,6 +1,6 @@
1
1
  import remapping from "@jridgewell/remapping";
2
2
  import MagicString from "magic-string";
3
- import { parseSync, visitorKeys } from "oxc-parser";
3
+ import { parseSync, rawTransferSupported, visitorKeys } from "oxc-parser";
4
4
  //#region src/ast.ts
5
5
  /**
6
6
  * Keys that only hold TypeScript types. Types never run, so no pass reads or rewrites them.
@@ -60,12 +60,19 @@ function collectParents(program) {
60
60
  visit(program);
61
61
  return parents;
62
62
  }
63
+ /**
64
+ * Raw transfer hands the AST over in shared memory instead of as JSON, which
65
+ * is several times faster to read. It is not in the options' type yet.
66
+ */
67
+ const RAW_TRANSFER = rawTransferSupported();
63
68
  function parse(filename, code) {
64
- const result = parseSync(filename, code, {
69
+ const options = {
65
70
  lang: languageOf(filename),
66
71
  sourceType: "module",
67
- preserveParens: true
68
- });
72
+ preserveParens: true,
73
+ experimentalRawTransfer: RAW_TRANSFER
74
+ };
75
+ const result = parseSync(filename, code, options);
69
76
  const error = result.errors.at(0);
70
77
  if (error) throw new SyntaxError(`[solid-optimizer] ${filename}: ${error.codeframe ?? error.message}`);
71
78
  return result.program;
@@ -202,6 +209,16 @@ function solidExport(binding, options) {
202
209
  if (binding.kind === "import" && binding.source !== void 0 && options.moduleSources.includes(binding.source)) return binding.imported;
203
210
  }
204
211
  /**
212
+ * Records that a pass left something alone, when the caller asked for a report.
213
+ */
214
+ function recordSkip(context, pass, reason, name) {
215
+ context.skips?.push({
216
+ pass,
217
+ reason,
218
+ name
219
+ });
220
+ }
221
+ /**
205
222
  * The current text of `node`, including the edits made inside it so far.
206
223
  */
207
224
  function textOf(context, node) {
@@ -1683,6 +1700,10 @@ function isAccessor(context, binding) {
1683
1700
  */
1684
1701
  function isClosed(context, root, options) {
1685
1702
  let closed = true;
1703
+ const open = (reason) => {
1704
+ closed = false;
1705
+ options.onOpen?.(reason);
1706
+ };
1686
1707
  const visit = (node) => {
1687
1708
  if (!closed) return;
1688
1709
  switch (node.type) {
@@ -1691,32 +1712,34 @@ function isClosed(context, root, options) {
1691
1712
  break;
1692
1713
  case "JSXSpreadAttribute":
1693
1714
  if (!isOwnView(context, node.argument, options.props, 0)) {
1694
- closed = false;
1715
+ open("open-spread");
1695
1716
  return;
1696
1717
  }
1697
1718
  break;
1698
- case "JSXSpreadChild":
1699
1719
  case "NewExpression":
1720
+ open("open-new");
1721
+ return;
1722
+ case "JSXSpreadChild":
1700
1723
  case "TaggedTemplateExpression":
1701
1724
  case "ImportExpression":
1702
- closed = false;
1725
+ open("open-other");
1703
1726
  return;
1704
1727
  case "JSXElement":
1705
1728
  if (!isVisibleElement(context, node, options)) {
1706
- closed = false;
1729
+ open("open-component");
1707
1730
  return;
1708
1731
  }
1709
1732
  break;
1710
1733
  case "CallExpression":
1711
1734
  if (!isVisibleCall(context, node, options)) {
1712
- closed = false;
1735
+ open("open-call");
1713
1736
  return;
1714
1737
  }
1715
1738
  break;
1716
1739
  case "Identifier": {
1717
1740
  const binding = context.scopes.references.get(node);
1718
1741
  if (binding && runsOutsideCode(context, binding, root, options, 0)) {
1719
- closed = false;
1742
+ open("open-outer");
1720
1743
  return;
1721
1744
  }
1722
1745
  break;
@@ -1948,25 +1971,63 @@ var ProviderRemover = class {
1948
1971
  run() {
1949
1972
  for (const provider of findProviders(this.context)) {
1950
1973
  const { element } = provider;
1951
- if (!this.removed.some((other) => element.start < other.end && other.start < element.end) && !hasNestedProvider(this.context, provider) && this.tryRemove(provider)) this.removed.push(element);
1974
+ if (this.removed.some((other) => element.start < other.end && other.start < element.end)) continue;
1975
+ if (hasNestedProvider(this.context, provider)) this.skip(provider, "provider-nested");
1976
+ else if (this.tryRemove(provider)) this.removed.push(element);
1952
1977
  }
1978
+ if (this.context.skips) this.reportShapes();
1979
+ }
1980
+ skip(provider, reason) {
1981
+ recordSkip(this.context, "contexts", reason, provider.context.name);
1982
+ }
1983
+ /**
1984
+ * Records each context tag that is not a provider this pass understands,
1985
+ * such as one with more attributes than `value`.
1986
+ */
1987
+ reportShapes() {
1988
+ const visit = (node) => {
1989
+ if (node.type === "JSXElement") {
1990
+ const binding = providerContext(this.context, node.openingElement.name);
1991
+ if (binding && !providerOf(this.context, node)) {
1992
+ const { attributes } = node.openingElement;
1993
+ const attribute = attributes.at(0);
1994
+ const onlyValue = attributes.length === 1 && attribute?.type === "JSXAttribute" && attribute.name.type === "JSXIdentifier" && attribute.name.name === "value";
1995
+ recordSkip(this.context, "contexts", onlyValue && !node.openingElement.selfClosing ? "provider-undefined" : "provider-shape", binding.name);
1996
+ }
1997
+ }
1998
+ forEachChild(node, visit);
1999
+ };
2000
+ visit(this.context.program);
1953
2001
  }
1954
2002
  tryRemove(provider) {
1955
2003
  const { element } = provider;
1956
2004
  const children = element.children;
2005
+ let reason = "open-other";
1957
2006
  if (!children.every((child) => isClosed(this.context, child, {
1958
2007
  component: () => false,
1959
- contextValue: (target) => target === provider.context ? provider.value : void 0
1960
- }))) return false;
2008
+ contextValue: (target) => target === provider.context ? provider.value : void 0,
2009
+ onOpen: (open) => {
2010
+ reason = open;
2011
+ }
2012
+ }))) {
2013
+ this.skip(provider, reason);
2014
+ return false;
2015
+ }
1961
2016
  const reads = children.flatMap((child) => contextReads(this.context, child, provider.context));
1962
2017
  const texts = [];
1963
2018
  for (const read of reads) {
1964
2019
  const text = stableValueText(this.context, provider, read);
1965
- if (text === void 0) return false;
2020
+ if (text === void 0) {
2021
+ this.skip(provider, "provider-value");
2022
+ return false;
2023
+ }
1966
2024
  texts.push(text);
1967
2025
  }
1968
2026
  if (reads.length === 0 && !isSideEffectFree(provider.value)) {
1969
- if (stableValueText(this.context, provider, element) === void 0) return false;
2027
+ if (stableValueText(this.context, provider, element) === void 0) {
2028
+ this.skip(provider, "provider-value");
2029
+ return false;
2030
+ }
1970
2031
  }
1971
2032
  const { s } = this.context;
1972
2033
  for (const [index, read] of reads.entries()) s.overwrite(read.start, read.end, texts[index] ?? "");
@@ -2170,7 +2231,8 @@ function copySize(filename, header, copy, inTemplate, options) {
2170
2231
  program,
2171
2232
  parents: collectParents(program),
2172
2233
  scopes: analyzeScopes(program),
2173
- options
2234
+ options,
2235
+ skips: void 0
2174
2236
  })) break;
2175
2237
  code = s.toString();
2176
2238
  }
@@ -2202,7 +2264,8 @@ function copySize(filename, header, copy, inTemplate, options) {
2202
2264
  *
2203
2265
  * - It is declared once at the top level of the module, with a capitalized
2204
2266
  * name, as a function declaration or a `const` bound to a function.
2205
- * - It takes no parameter, or one identifier that is only read as `props.name`.
2267
+ * - It takes no parameter, or one identifier that is only read as `props.name`,
2268
+ * or spread onto an element as `{...props}`.
2206
2269
  * - Its body is statements followed by one final `return` of JSX, or an arrow
2207
2270
  * function whose body is JSX.
2208
2271
  * - It does not use `this`, `arguments`, `new.target`, or `super`.
@@ -2431,6 +2494,20 @@ function attributesOf(element) {
2431
2494
  }
2432
2495
  return attributes;
2433
2496
  }
2497
+ /**
2498
+ * Why `attributesOf` turns down a call site, for the report.
2499
+ */
2500
+ function callSiteReason(element) {
2501
+ const names = /* @__PURE__ */ new Set();
2502
+ for (const attribute of element.openingElement.attributes) {
2503
+ if (attribute.type !== "JSXAttribute") return "call-spread";
2504
+ if (attribute.name.type !== "JSXIdentifier") return "call-namespace";
2505
+ if (attribute.name.name === "ref") return "call-ref";
2506
+ if (names.has(attribute.name.name)) break;
2507
+ names.add(attribute.name.name);
2508
+ }
2509
+ return "call-duplicate";
2510
+ }
2434
2511
  function isAssignmentTarget(context, node) {
2435
2512
  const parent = context.parents.get(node);
2436
2513
  if (!parent) return false;
@@ -2455,6 +2532,28 @@ var Inliner = class {
2455
2532
  this.changed = false;
2456
2533
  this.hosts = /* @__PURE__ */ new Map();
2457
2534
  this.transparent = /* @__PURE__ */ new Map();
2535
+ this.reason = "";
2536
+ }
2537
+ /**
2538
+ * Whether a binding holds a component made by Solid's `lazy`, for the
2539
+ * report. In a chunk, `lazy` can be a local declaration under another
2540
+ * name, so a call given a function with a dynamic import counts too.
2541
+ */
2542
+ isLazy(binding) {
2543
+ const { declaration } = binding;
2544
+ const init = declaration.type === "VariableDeclarator" && declaration.init ? unwrap(declaration.init) : void 0;
2545
+ if (init?.type !== "CallExpression" || init.callee.type !== "Identifier") return false;
2546
+ const callee = this.context.scopes.references.get(init.callee);
2547
+ if (callee && solidExport(callee, this.context.options) === "lazy") return true;
2548
+ const loader = init.arguments.at(0);
2549
+ if (!loader || !isFunctionNode(loader)) return false;
2550
+ let imports = false;
2551
+ const visit = (node) => {
2552
+ if (node.type === "ImportExpression") imports = true;
2553
+ if (!imports) forEachChild(node, visit);
2554
+ };
2555
+ visit(loader);
2556
+ return imports;
2458
2557
  }
2459
2558
  scopeOf(fn) {
2460
2559
  return this.context.scopes.scopes.get(fn);
@@ -2470,41 +2569,87 @@ var Inliner = class {
2470
2569
  if (statement?.type === "VariableDeclaration" && statement.declarations.length === 1 && this.context.parents.get(statement)?.type === "Program") return statement;
2471
2570
  }
2472
2571
  analyzeComponent(binding) {
2473
- if (!isCapitalized(binding.name) || binding.mutated) return;
2572
+ if (!isCapitalized(binding.name)) return;
2573
+ if (binding.mutated) {
2574
+ this.reason = "component-mutated";
2575
+ return;
2576
+ }
2474
2577
  const fn = functionOf(binding, this.context.options);
2475
- if (!fn || fn.async || fn.generator || !fn.body || fn.params.length > 1) return;
2578
+ if (!fn?.body) {
2579
+ this.reason = this.isLazy(binding) ? "lazy" : "not-a-function";
2580
+ return;
2581
+ }
2582
+ if (fn.async || fn.generator) {
2583
+ this.reason = "component-async";
2584
+ return;
2585
+ }
2586
+ if (fn.params.length > 1) {
2587
+ this.reason = "component-params";
2588
+ return;
2589
+ }
2476
2590
  const scope = this.scopeOf(fn);
2477
- if (!scope) return;
2591
+ if (!scope) {
2592
+ this.reason = "not-a-function";
2593
+ return;
2594
+ }
2478
2595
  let statements = [];
2479
2596
  let root;
2480
2597
  if (fn.body.type === "BlockStatement") {
2481
2598
  const body = fn.body.body;
2482
2599
  const last = body.at(-1);
2483
- if (last?.type !== "ReturnStatement" || !last.argument) return;
2600
+ if (last?.type !== "ReturnStatement" || !last.argument) {
2601
+ this.reason = "component-body";
2602
+ return;
2603
+ }
2484
2604
  const rest = [];
2485
2605
  for (const statement of body.slice(0, -1)) {
2486
- if (typeof ("directive" in statement ? statement.directive : null) === "string" || containsReturn(statement)) return;
2606
+ if (typeof ("directive" in statement ? statement.directive : null) === "string") {
2607
+ this.reason = "component-directive";
2608
+ return;
2609
+ }
2610
+ if (containsReturn(statement)) {
2611
+ this.reason = "component-return";
2612
+ return;
2613
+ }
2487
2614
  rest.push(statement);
2488
2615
  }
2489
2616
  statements = rest;
2490
2617
  root = unwrap(last.argument);
2491
2618
  } else root = unwrap(fn.body);
2492
- if (root.type !== "JSXElement" && root.type !== "JSXFragment") return;
2493
- if (usesFunctionContext(this.context, fn.body)) return;
2619
+ if (root.type !== "JSXElement" && root.type !== "JSXFragment") {
2620
+ this.reason = "component-body";
2621
+ return;
2622
+ }
2623
+ if (usesFunctionContext(this.context, fn.body)) {
2624
+ this.reason = "component-this";
2625
+ return;
2626
+ }
2494
2627
  const param = fn.params.at(0);
2495
2628
  let paramBinding;
2496
2629
  if (param) {
2497
- if (param.type !== "Identifier") return;
2630
+ if (param.type !== "Identifier") {
2631
+ this.reason = "component-params";
2632
+ return;
2633
+ }
2498
2634
  paramBinding = scope.bindings.get(param.name);
2499
- if (!paramBinding || paramBinding.mutated) return;
2635
+ if (!paramBinding || paramBinding.mutated) {
2636
+ this.reason = "props-use";
2637
+ return;
2638
+ }
2500
2639
  }
2501
2640
  const views = this.analyzeViews(fn, scope, statements, paramBinding);
2502
- if (!views) return;
2641
+ if (!views) {
2642
+ this.reason = "view-use";
2643
+ return;
2644
+ }
2503
2645
  const props = [];
2504
2646
  for (const reference of paramBinding?.references ?? []) {
2505
2647
  if (views.arguments.has(reference)) continue;
2506
2648
  const read = this.propRead(fn, reference);
2507
- if (!read) return;
2649
+ if (!read) {
2650
+ this.reason = "props-use";
2651
+ return;
2652
+ }
2508
2653
  props.push(read);
2509
2654
  }
2510
2655
  statements = statements.filter((statement) => !views.declarations.includes(statement));
@@ -2518,7 +2663,10 @@ var Inliner = class {
2518
2663
  const outer = [];
2519
2664
  for (const [reference, target] of this.context.scopes.references) {
2520
2665
  if (reference.start < fn.start || reference.end > fn.end) continue;
2521
- if (target === binding) return;
2666
+ if (target === binding) {
2667
+ this.reason = "component-recursive";
2668
+ return;
2669
+ }
2522
2670
  if (target && isWithinScope(target.scope, scope)) continue;
2523
2671
  if (reference.type === "Identifier" || reference.type === "JSXIdentifier") outer.push({
2524
2672
  name: reference.name,
@@ -2599,17 +2747,32 @@ var Inliner = class {
2599
2747
  }
2600
2748
  const reads = [];
2601
2749
  const spreads = [];
2750
+ const whole = { sources: [{
2751
+ defaults: void 0,
2752
+ hidden: /* @__PURE__ */ new Set(),
2753
+ only: void 0
2754
+ }] };
2755
+ for (const reference of param?.references ?? []) {
2756
+ const spread = this.spreadOnElement(reference);
2757
+ if (spread) {
2758
+ args.add(reference);
2759
+ spreads.push({
2760
+ attribute: spread.attribute,
2761
+ element: spread.element,
2762
+ view: whole,
2763
+ repeated: this.isRepeated(fn, spread.attribute)
2764
+ });
2765
+ }
2766
+ }
2602
2767
  for (const [binding, view] of views) for (const reference of binding.references) {
2603
2768
  if (args.has(reference)) continue;
2604
- const parent = this.context.parents.get(reference);
2605
- const opening = parent ? this.context.parents.get(parent) : void 0;
2606
- const element = opening ? this.context.parents.get(opening) : void 0;
2607
- if (parent?.type === "JSXSpreadAttribute" && opening?.type === "JSXOpeningElement" && element?.type === "JSXElement") {
2769
+ const spread = this.spreadOnElement(reference);
2770
+ if (spread) {
2608
2771
  spreads.push({
2609
- attribute: parent,
2610
- element,
2772
+ attribute: spread.attribute,
2773
+ element: spread.element,
2611
2774
  view,
2612
- repeated: this.isRepeated(fn, parent)
2775
+ repeated: this.isRepeated(fn, spread.attribute)
2613
2776
  });
2614
2777
  continue;
2615
2778
  }
@@ -2628,6 +2791,16 @@ var Inliner = class {
2628
2791
  spreads
2629
2792
  };
2630
2793
  }
2794
+ /** The spread a reference is the whole argument of, and the element it is on. */
2795
+ spreadOnElement(reference) {
2796
+ const parent = this.context.parents.get(reference);
2797
+ const opening = parent ? this.context.parents.get(parent) : void 0;
2798
+ const element = opening ? this.context.parents.get(opening) : void 0;
2799
+ return parent?.type === "JSXSpreadAttribute" && opening?.type === "JSXOpeningElement" && element?.type === "JSXElement" ? {
2800
+ attribute: parent,
2801
+ element
2802
+ } : void 0;
2803
+ }
2631
2804
  /**
2632
2805
  * The sources a view argument stands for: the props, a view, or a nested
2633
2806
  * `mergeProps()` call.
@@ -2902,13 +3075,28 @@ var Inliner = class {
2902
3075
  */
2903
3076
  prepare(component, element) {
2904
3077
  const attributes = attributesOf(element);
2905
- if (!attributes) return;
3078
+ if (!attributes) {
3079
+ this.reason = callSiteReason(element);
3080
+ return;
3081
+ }
2906
3082
  const hasChildren = element.children.some((child) => !isInsignificant(child));
2907
- if (hasChildren && attributes.has("children")) return;
2908
- for (const attribute of attributes.values()) if (attribute.value && usesFunctionContext(this.context, attribute.value)) return;
2909
- for (const child of element.children) if (usesFunctionContext(this.context, child)) return;
3083
+ if (hasChildren && attributes.has("children")) {
3084
+ this.reason = "call-children";
3085
+ return;
3086
+ }
3087
+ for (const attribute of attributes.values()) if (attribute.value && usesFunctionContext(this.context, attribute.value)) {
3088
+ this.reason = "call-this";
3089
+ return;
3090
+ }
3091
+ for (const child of element.children) if (usesFunctionContext(this.context, child)) {
3092
+ this.reason = "call-this";
3093
+ return;
3094
+ }
2910
3095
  const views = this.resolveViews(component, element, attributes, hasChildren);
2911
- if (!views) return;
3096
+ if (!views) {
3097
+ this.reason = "view-conflict";
3098
+ return;
3099
+ }
2912
3100
  const snapshots = [];
2913
3101
  const fresh = (base) => this.freshName(base);
2914
3102
  const readsByName = /* @__PURE__ */ new Map();
@@ -2925,16 +3113,28 @@ var Inliner = class {
2925
3113
  let value;
2926
3114
  if (name === "children" && !attributes.has("children")) value = this.childrenValue(element, reads, fresh, snapshots);
2927
3115
  else value = this.propValue(attributes.get(name), reads, fresh, snapshots);
2928
- if (!value) return;
3116
+ if (!value) {
3117
+ this.reason = "prop-value";
3118
+ return;
3119
+ }
2929
3120
  values.set(name, value);
2930
3121
  }
2931
3122
  const scope = scopeAt(this.context.scopes, this.context.parents, element);
2932
- for (const reference of component.outer) if (lookup(scope, reference.name) !== reference.binding) return;
3123
+ for (const reference of component.outer) if (lookup(scope, reference.name) !== reference.binding) {
3124
+ this.reason = "shadowed";
3125
+ return;
3126
+ }
2933
3127
  const hoisted = component.statements.length > 0 || snapshots.length > 0;
2934
3128
  const host = hoisted ? this.hostOf(element) : void 0;
2935
- if (hoisted && !host) return;
3129
+ if (hoisted && !host) {
3130
+ this.reason = "no-host";
3131
+ return;
3132
+ }
2936
3133
  const contextTexts = this.contextTexts(component, element);
2937
- if (!contextTexts) return;
3134
+ if (!contextTexts) {
3135
+ this.reason = "context-value";
3136
+ return;
3137
+ }
2938
3138
  const copy = new MagicString(this.context.code);
2939
3139
  this.renameLocals(copy, component, fresh);
2940
3140
  this.substituteProps(copy, views.propReads, values);
@@ -3356,11 +3556,18 @@ var Inliner = class {
3356
3556
  }
3357
3557
  run() {
3358
3558
  const components = [];
3559
+ const rejected = /* @__PURE__ */ new Map();
3359
3560
  for (const binding of this.context.scopes.root.bindings.values()) {
3561
+ this.reason = "not-a-function";
3360
3562
  const component = this.analyzeComponent(binding);
3361
3563
  if (component) components.push(component);
3564
+ else rejected.set(binding, this.reason);
3565
+ }
3566
+ const siteReasons = /* @__PURE__ */ new Map();
3567
+ if (components.length === 0) {
3568
+ this.report(rejected, siteReasons);
3569
+ return;
3362
3570
  }
3363
- if (components.length === 0) return;
3364
3571
  const sites = [];
3365
3572
  const otherUses = /* @__PURE__ */ new Map();
3366
3573
  for (const component of components) {
@@ -3391,12 +3598,16 @@ var Inliner = class {
3391
3598
  const elements = inlined.get(site.component) ?? [];
3392
3599
  elements.push(site.element);
3393
3600
  inlined.set(site.component, elements);
3394
- } else otherUses.set(site.component, (otherUses.get(site.component) ?? 0) + 1);
3601
+ } else {
3602
+ otherUses.set(site.component, (otherUses.get(site.component) ?? 0) + 1);
3603
+ if (this.context.skips && !postponed) siteReasons.set(site.element, this.siteReason(site, worthwhile));
3604
+ }
3395
3605
  if (done || postponed) {
3396
3606
  for (const component of components) if (isWithin(site.element, component.fn)) changedBodies.add(component);
3397
3607
  }
3398
3608
  }
3399
3609
  this.writeHosts();
3610
+ this.report(rejected, siteReasons);
3400
3611
  const copied = [...inlined.keys()];
3401
3612
  for (const [component, elements] of inlined) {
3402
3613
  const insideCopy = elements.some((element) => copied.some((other) => other !== component && element.start >= other.fn.start && element.end <= other.fn.end));
@@ -3404,6 +3615,66 @@ var Inliner = class {
3404
3615
  }
3405
3616
  }
3406
3617
  /**
3618
+ * Why a call site of a component was not inlined. A component that is
3619
+ * not worth inlining is only turned down for its size when the call site
3620
+ * could be inlined.
3621
+ */
3622
+ siteReason(site, worthwhile) {
3623
+ if (worthwhile.has(site.component)) return this.reason;
3624
+ this.scratchNames = new Set(this.context.scopes.names);
3625
+ try {
3626
+ return this.prepare(site.component, site.element) ? "size" : this.reason;
3627
+ } finally {
3628
+ this.scratchNames = void 0;
3629
+ }
3630
+ }
3631
+ /**
3632
+ * Records each component call that stays a call, and why. Solid's
3633
+ * built-ins and context providers are left out. The provider pass
3634
+ * reports providers.
3635
+ */
3636
+ report(rejected, siteReasons) {
3637
+ if (!this.context.skips) return;
3638
+ const visit = (node) => {
3639
+ if (node.type === "JSXElement") {
3640
+ const reason = this.callReason(node, rejected, siteReasons);
3641
+ if (reason) recordSkip(this.context, "inline", reason.reason, reason.name);
3642
+ }
3643
+ forEachChild(node, visit);
3644
+ };
3645
+ visit(this.context.program);
3646
+ }
3647
+ callReason(element, rejected, siteReasons) {
3648
+ const tag = element.openingElement.name;
3649
+ if (providerContext(this.context, tag)) return;
3650
+ if (tag.type === "JSXMemberExpression") return {
3651
+ reason: "member-tag",
3652
+ name: textOf(this.context, tag)
3653
+ };
3654
+ if (tag.type !== "JSXIdentifier" || !isCapitalized(tag.name)) return;
3655
+ const { name } = tag;
3656
+ const binding = this.context.scopes.references.get(tag);
3657
+ const identity = binding ? solidExport(binding, this.context.options) : name;
3658
+ if (identity !== void 0 && this.context.options.builtIns.has(identity)) return;
3659
+ if (!binding) return {
3660
+ reason: "global",
3661
+ name
3662
+ };
3663
+ if (binding.kind === "import") return {
3664
+ reason: "imported",
3665
+ name: `${name} (${(binding.source ?? "").replaceAll(/!~\{\w+\}~/g, "*")})`
3666
+ };
3667
+ if (binding.scope.parent !== void 0) return {
3668
+ reason: "nested",
3669
+ name
3670
+ };
3671
+ const reason = rejected.get(binding) ?? siteReasons.get(element);
3672
+ return reason === void 0 ? void 0 : {
3673
+ reason,
3674
+ name
3675
+ };
3676
+ }
3677
+ /**
3407
3678
  * The whitespace before `position` on its line.
3408
3679
  */
3409
3680
  indentationAt(position) {
@@ -3478,6 +3749,7 @@ var MemoInliner = class {
3478
3749
  constructor(context) {
3479
3750
  this.context = context;
3480
3751
  this.changed = false;
3752
+ this.reason = "";
3481
3753
  }
3482
3754
  isCreateMemo(callee) {
3483
3755
  if (callee.type !== "Identifier") return false;
@@ -3494,19 +3766,35 @@ var MemoInliner = class {
3494
3766
  const compute = args.at(0);
3495
3767
  const initialValue = args.at(1);
3496
3768
  const options = args.at(2);
3497
- if (args.length > 3 || compute === void 0 || compute.type === "SpreadElement" || initialValue?.type === "SpreadElement" || initialValue !== void 0 && !isSideEffectFree(initialValue)) return;
3769
+ if (args.length > 3 || compute === void 0 || compute.type === "SpreadElement" || initialValue?.type === "SpreadElement" || initialValue !== void 0 && !isSideEffectFree(initialValue)) {
3770
+ this.reason = "memo-computation";
3771
+ return;
3772
+ }
3498
3773
  const fn = unwrap(compute);
3499
- if (fn.type !== "ArrowFunctionExpression" && fn.type !== "FunctionExpression") return;
3774
+ if (fn.type !== "ArrowFunctionExpression" && fn.type !== "FunctionExpression") {
3775
+ this.reason = "memo-computation";
3776
+ return;
3777
+ }
3500
3778
  const expression = returnedExpression(fn);
3501
- if (!expression) return;
3779
+ if (!expression) {
3780
+ this.reason = "memo-computation";
3781
+ return;
3782
+ }
3502
3783
  let alwaysNotifies = false;
3503
3784
  if (options !== void 0) {
3504
- if (options.type !== "ObjectExpression" || options.properties.length !== 1) return;
3785
+ if (options.type !== "ObjectExpression" || options.properties.length !== 1) {
3786
+ this.reason = "memo-options";
3787
+ return;
3788
+ }
3505
3789
  const property = options.properties.at(0);
3506
- if (property?.type !== "Property" || property.computed || property.key.type !== "Identifier" || property.key.name !== "equals" || property.value.type !== "Literal" || property.value.value !== false) return;
3790
+ if (property?.type !== "Property" || property.computed || property.key.type !== "Identifier" || property.key.name !== "equals" || property.value.type !== "Literal" || property.value.value !== false) {
3791
+ this.reason = "memo-options";
3792
+ return;
3793
+ }
3507
3794
  alwaysNotifies = true;
3508
3795
  }
3509
- return alwaysNotifies || isFresh(expression) ? expression : void 0;
3796
+ if (alwaysNotifies || isFresh(expression)) return expression;
3797
+ if (unwrap(expression).type === "Literal") this.reason = "memo-constant";
3510
3798
  }
3511
3799
  /**
3512
3800
  * The function a node runs in.
@@ -3601,17 +3889,40 @@ var MemoInliner = class {
3601
3889
  return true;
3602
3890
  }
3603
3891
  tryInline(declarator, binding) {
3892
+ this.reason = "";
3893
+ if (this.inline(declarator, binding) === void 0 && this.reason !== "") recordSkip(this.context, "memos", this.reason, binding.name);
3894
+ }
3895
+ inline(declarator, binding) {
3604
3896
  const expression = this.unstableComputation(declarator);
3605
- if (!expression || binding.references.length !== 1) return;
3897
+ if (!expression) return;
3898
+ if (binding.references.length !== 1) {
3899
+ this.reason = "memo-reads";
3900
+ return;
3901
+ }
3606
3902
  const statement = this.context.parents.get(declarator);
3607
3903
  const fn = this.functionOf(declarator);
3608
- if (statement?.type !== "VariableDeclaration" || statement.declarations.length !== 1 || !fn) return;
3904
+ if (statement?.type !== "VariableDeclaration" || statement.declarations.length !== 1 || !fn) {
3905
+ this.reason = "memo-declaration";
3906
+ return;
3907
+ }
3609
3908
  const reference = binding.references.at(0);
3610
3909
  const call = reference ? this.context.parents.get(reference) : void 0;
3611
- if (call?.type !== "CallExpression" || call.callee !== reference || call.arguments.length > 0 || !this.isSingleTrackedRead(call, fn) || !this.resolvesSameAt(expression, call, binding) || usesFunctionContext(this.context, expression)) return;
3910
+ if (call?.type !== "CallExpression" || call.callee !== reference || call.arguments.length > 0) {
3911
+ this.reason = "memo-read";
3912
+ return;
3913
+ }
3914
+ if (!this.isSingleTrackedRead(call, fn)) {
3915
+ this.reason = "memo-read-place";
3916
+ return;
3917
+ }
3918
+ if (!this.resolvesSameAt(expression, call, binding) || usesFunctionContext(this.context, expression)) {
3919
+ this.reason = "memo-scope";
3920
+ return;
3921
+ }
3612
3922
  this.context.s.overwrite(call.start, call.end, textOf(this.context, expression));
3613
3923
  this.context.s.remove(statement.start, statement.end);
3614
3924
  this.changed = true;
3925
+ return true;
3615
3926
  }
3616
3927
  run() {
3617
3928
  for (const scope of new Set(this.context.scopes.scopes.values())) {
@@ -3819,16 +4130,29 @@ function resolveOptions(options) {
3819
4130
  alwaysInline: options.alwaysInline ?? false
3820
4131
  };
3821
4132
  }
3822
- function runPass(code, filename, options, sourceMap, pass) {
4133
+ function parseCode(code, filename) {
3823
4134
  const program = parse(filename, code);
4135
+ return {
4136
+ code,
4137
+ program,
4138
+ parents: collectParents(program),
4139
+ scopes: analyzeScopes(program)
4140
+ };
4141
+ }
4142
+ function runPass(parsed, filename, options, sourceMap, pass, skips) {
4143
+ const { code } = parsed;
3824
4144
  const context = {
3825
4145
  code,
3826
4146
  filename,
3827
4147
  s: new MagicString(code),
3828
- program,
3829
- parents: collectParents(program),
3830
- scopes: analyzeScopes(program),
3831
- options
4148
+ program: parsed.program,
4149
+ parents: parsed.parents,
4150
+ scopes: {
4151
+ ...parsed.scopes,
4152
+ names: new Set(parsed.scopes.names)
4153
+ },
4154
+ options,
4155
+ skips
3832
4156
  };
3833
4157
  if (!pass(context)) return;
3834
4158
  return {
@@ -3862,11 +4186,18 @@ function compile(code, options = {}) {
3862
4186
  if (options.memos ?? true) passes.push(inlineMemos);
3863
4187
  const maps = [];
3864
4188
  let current = code;
4189
+ let parsed;
4190
+ const parsedCurrent = () => {
4191
+ if (parsed?.code !== current) parsed = parseCode(current, filename);
4192
+ return parsed;
4193
+ };
3865
4194
  const maxPasses = options.maxPasses ?? 10;
4195
+ let skipped;
3866
4196
  for (let round = 0; round < maxPasses; round += 1) {
3867
4197
  let changed = false;
4198
+ skipped = options.report === true ? [] : void 0;
3868
4199
  for (const pass of passes) {
3869
- const result = runPass(current, filename, resolved, sourceMap, pass);
4200
+ const result = runPass(parsedCurrent(), filename, resolved, sourceMap, pass, skipped);
3870
4201
  if (result) {
3871
4202
  changed = true;
3872
4203
  current = result.code;
@@ -3876,19 +4207,22 @@ function compile(code, options = {}) {
3876
4207
  if (!changed) break;
3877
4208
  }
3878
4209
  if (options.server ?? false) {
3879
- const result = runPass(current, filename, resolved, sourceMap, simplifyServer);
4210
+ const result = runPass(parsedCurrent(), filename, resolved, sourceMap, simplifyServer, void 0);
3880
4211
  if (result) {
3881
4212
  current = result.code;
3882
4213
  if (result.map !== void 0) maps.push(result.map);
3883
4214
  }
3884
4215
  }
4216
+ const report = skipped ? { skipped } : {};
3885
4217
  if (maps.length === 0) return {
3886
4218
  code: current,
3887
- map: null
4219
+ map: null,
4220
+ ...report
3888
4221
  };
3889
4222
  return {
3890
4223
  code: current,
3891
- map: remapping(maps.reverse(), () => null)
4224
+ map: remapping(maps.reverse(), () => null),
4225
+ ...report
3892
4226
  };
3893
4227
  }
3894
4228
  /**
@@ -3905,6 +4239,6 @@ function readModuleConstants(code, options = {}) {
3905
4239
  };
3906
4240
  }
3907
4241
  //#endregion
3908
- export { lookup as a, forEachChild as c, analyzeScopes as i, parse as l, readModuleConstants as n, scopeAt as o, CONTEXT_SAFE_PRIMITIVES as r, collectParents as s, compile as t, unwrap as u };
4242
+ 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 };
3909
4243
 
3910
- //# sourceMappingURL=compile-ocDYvJUW.mjs.map
4244
+ //# sourceMappingURL=compile-D3caSUtw.mjs.map