prunelle 0.9.0 → 0.10.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 (96) hide show
  1. package/llms.txt +18 -18
  2. package/package.json +2 -2
  3. package/src/a11y/declaration.ts +4 -7
  4. package/src/build/bundle.ts +6 -2
  5. package/src/build/index.ts +3 -1
  6. package/src/build/island-promote.ts +42 -2
  7. package/src/build/islands.ts +59 -8
  8. package/src/build/manifest.ts +98 -0
  9. package/src/build/plugin-host.ts +11 -1
  10. package/src/build/prerender.ts +6 -1
  11. package/src/build/reach.ts +4 -3
  12. package/src/build/resolve.ts +5 -1
  13. package/src/build/routes.ts +18 -0
  14. package/src/cli/check-forms.ts +8 -0
  15. package/src/cli/check-links.ts +14 -5
  16. package/src/cli/check.ts +12 -6
  17. package/src/cli/commands.ts +5 -3
  18. package/src/cli/form-opaque-children.ts +40 -0
  19. package/src/compiler/analyze.ts +20 -14
  20. package/src/compiler/cacheability-private.ts +13 -3
  21. package/src/compiler/compliance-contrast.ts +48 -10
  22. package/src/compiler/compliance-rules.ts +72 -0
  23. package/src/compiler/compliance.ts +6 -66
  24. package/src/compiler/dom-attrs.ts +178 -22
  25. package/src/compiler/dom.ts +31 -44
  26. package/src/compiler/emit.ts +17 -6
  27. package/src/compiler/expr-context.ts +260 -207
  28. package/src/compiler/props-body.ts +263 -21
  29. package/src/compiler/props.ts +155 -5
  30. package/src/compiler/signal-reads.ts +142 -29
  31. package/src/compiler/spread-handlers.ts +25 -13
  32. package/src/compiler/ssr-emit.ts +3 -3
  33. package/src/compiler/ssr-helpers.ts +0 -5
  34. package/src/compiler/ssr.ts +4 -2
  35. package/src/dev/host-check.ts +2 -1
  36. package/src/dev/reload.ts +4 -1
  37. package/src/dom/attrs.ts +93 -25
  38. package/src/dom/extras.ts +89 -49
  39. package/src/dom/field-marks.ts +9 -1
  40. package/src/dom/index.ts +19 -13
  41. package/src/dom/loop.ts +259 -188
  42. package/src/dom/prefetch.ts +4 -1
  43. package/src/dom/regions.ts +25 -8
  44. package/src/dom/swap.ts +11 -10
  45. package/src/dom/trusted.ts +4 -4
  46. package/src/eco/declaration.ts +5 -1
  47. package/src/eco/index.ts +3 -0
  48. package/src/index.ts +3 -2
  49. package/src/plugins/config.ts +1 -1
  50. package/src/plugins/public.ts +4 -0
  51. package/src/plugins/types.ts +8 -1
  52. package/src/reactivity/graph.ts +244 -41
  53. package/src/reactivity/hmr.ts +14 -3
  54. package/src/reactivity/index.ts +219 -235
  55. package/src/reactivity/resource.ts +17 -3
  56. package/src/reactivity/seed.ts +118 -16
  57. package/src/reactivity/selector.ts +85 -47
  58. package/src/reactivity/server-seed.ts +31 -23
  59. package/src/reactivity/store.ts +316 -136
  60. package/src/server/action-protect.ts +3 -0
  61. package/src/server/action-registry.ts +5 -1
  62. package/src/server/cache-invalidation.ts +4 -3
  63. package/src/server/compress.ts +52 -17
  64. package/src/server/consent.ts +5 -3
  65. package/src/server/cookies.ts +27 -8
  66. package/src/server/cors.ts +98 -0
  67. package/src/server/csp-report.ts +8 -4
  68. package/src/server/health.ts +9 -0
  69. package/src/server/http.ts +3 -1
  70. package/src/server/index.ts +25 -13
  71. package/src/server/loader.ts +1 -0
  72. package/src/server/plugin-host.ts +41 -9
  73. package/src/server/plugin-route-shadow.ts +24 -0
  74. package/src/server/rate-limit.ts +13 -3
  75. package/src/server/region.ts +19 -2
  76. package/src/server/request-handler.ts +58 -22
  77. package/src/server/request-log.ts +1 -1
  78. package/src/server/route-cache.ts +14 -2
  79. package/src/server/route-table.ts +21 -11
  80. package/src/server/router.ts +2 -1
  81. package/src/server/routing.ts +100 -42
  82. package/src/server/sanitize-html.ts +3 -1
  83. package/src/server/serve-handlers.ts +10 -4
  84. package/src/server/served-file.ts +19 -14
  85. package/src/server/shared-store.ts +10 -1
  86. package/src/server/static-dir.ts +21 -3
  87. package/src/server/webhook.ts +6 -4
  88. package/src/ssr/context.ts +149 -51
  89. package/src/ssr/index.ts +41 -46
  90. package/src/ssr/region.ts +9 -3
  91. package/src/style.ts +12 -5
  92. package/src/test/browser.ts +3 -1
  93. package/src/test/build-reuse.ts +22 -7
  94. package/src/test/index.ts +7 -3
  95. package/src/ts-plugin/diagnostics.ts +56 -18
  96. package/ts-plugin.cjs +465 -131
package/ts-plugin.cjs CHANGED
@@ -1576,6 +1576,18 @@ var LOOP_OR_FN_ANCESTORS = new Set([
1576
1576
  "WhileStatement",
1577
1577
  "DoWhileStatement"
1578
1578
  ]);
1579
+ function collectMutatedNames(rootNode, candidates) {
1580
+ const mutated = new Set;
1581
+ if (rootNode === null || rootNode === undefined || candidates.size === 0)
1582
+ return mutated;
1583
+ walkScoped(rootNode, {
1584
+ onWrite(name) {
1585
+ if (candidates.has(name))
1586
+ mutated.add(name);
1587
+ }
1588
+ });
1589
+ return mutated;
1590
+ }
1579
1591
 
1580
1592
  // packages/prunelle/src/compiler/browser-globals.ts
1581
1593
  var BROWSER_GLOBALS = new Set([
@@ -1842,6 +1854,7 @@ function buildRouteCacheSpec(maxAgeMs, swrMs = maxAgeMs, tags = []) {
1842
1854
  }
1843
1855
  var PRIVATE_HEADER_NAMES = new Set(["cookie", "authorization"]);
1844
1856
  var BULK_HEADER_KEYS = new Set(["entries", "values", "keys", "forEach", "toJSON", "getSetCookie", Symbol.iterator]);
1857
+ var urlDerivedLocals = new WeakMap;
1845
1858
 
1846
1859
  // packages/prunelle/src/compiler/cacheability-private.ts
1847
1860
  var import_oxc_parser4 = require("oxc-parser");
@@ -2884,6 +2897,34 @@ function checkEcoElement(element, tag, ctx) {
2884
2897
  emit(ctx, "rgesn/img-size", element.start, `[rgesn/img-size] <img> in ${ctx.filename} has no width and height, so the browser cannot reserve its box and the page shifts as it loads: give its intrinsic width and height, or use <Img> from @prunellejs/images, which sets them.`);
2885
2898
  }
2886
2899
 
2900
+ // packages/prunelle/src/compiler/compliance-rules.ts
2901
+ var COMPLIANCE_RULES = new Set([
2902
+ ...RGAA_JSX_RULES,
2903
+ ...ECO_JSX_RULES,
2904
+ "rgesn/large-public-file",
2905
+ "rgesn/declaration",
2906
+ "rgesn/island-by-value",
2907
+ "rgpd/third-party-url",
2908
+ "rgpd/consent-retention",
2909
+ "rgpd/consent-preferences",
2910
+ "rgpd/cookie-category",
2911
+ "rgpd/cookie-purpose",
2912
+ "rgpd/privacy-notice",
2913
+ "lcen/legal-notice",
2914
+ "rgaa/document-lang",
2915
+ "rgaa/accessibility-statement",
2916
+ "rgaa/skip-link",
2917
+ "rgaa/page-title",
2918
+ "rgaa/contrast",
2919
+ "security/csrf-off",
2920
+ "security/proxy-no-site",
2921
+ "security/html-sink",
2922
+ "action/unguarded-public-form",
2923
+ "form/invalid-option",
2924
+ "form/schema-unsupported",
2925
+ "form/unchecked"
2926
+ ]);
2927
+
2887
2928
  // packages/prunelle/src/compiler/compliance-urls.ts
2888
2929
  var LOCAL_HOSTS = new Set(["localhost", "127.0.0.1", "::1", "[::1]", "0.0.0.0"]);
2889
2930
  var EXPR_PLACEHOLDER = "__prunelle_expr__";
@@ -3082,32 +3123,6 @@ function checkThirdPartyComponent(element, tag, filename, isIgnored, warnings) {
3082
3123
  }
3083
3124
 
3084
3125
  // packages/prunelle/src/compiler/compliance.ts
3085
- var COMPLIANCE_RULES = new Set([
3086
- ...RGAA_JSX_RULES,
3087
- ...ECO_JSX_RULES,
3088
- "rgesn/large-public-file",
3089
- "rgesn/declaration",
3090
- "rgesn/island-by-value",
3091
- "rgpd/third-party-url",
3092
- "rgpd/consent-retention",
3093
- "rgpd/consent-preferences",
3094
- "rgpd/cookie-category",
3095
- "rgpd/cookie-purpose",
3096
- "rgpd/privacy-notice",
3097
- "lcen/legal-notice",
3098
- "rgaa/document-lang",
3099
- "rgaa/accessibility-statement",
3100
- "rgaa/skip-link",
3101
- "rgaa/page-title",
3102
- "rgaa/contrast",
3103
- "security/csrf-off",
3104
- "security/proxy-no-site",
3105
- "security/html-sink",
3106
- "action/unguarded-public-form",
3107
- "form/invalid-option",
3108
- "form/schema-unsupported",
3109
- "form/unchecked"
3110
- ]);
3111
3126
  var INLINE_MAP_METHODS = new Set(["map", "flatMap"]);
3112
3127
  var DEFAULT_LEGAL_PATHS = new Set(["/mentions-legales", "/legal", "/legal-notice", "/imprint", "/impressum"]);
3113
3128
  var DEFAULT_PRIVACY_PATHS = new Set(["/privacy", "/privacy-policy", "/confidentialite", "/politique-de-confidentialite", "/donnees-personnelles", "/datenschutz"]);
@@ -3635,63 +3650,90 @@ function findNodeEnvReads(program, code) {
3635
3650
  return reads;
3636
3651
  }
3637
3652
 
3638
- // packages/prunelle/src/compiler/props-body.ts
3639
- function isFunction(node) {
3640
- return node !== null && node !== undefined && (node.type === "FunctionDeclaration" || node.type === "FunctionExpression" || node.type === "ArrowFunctionExpression");
3641
- }
3642
- function declaredFunctions(stmt) {
3643
- const decl = stmt.type === "ExportNamedDeclaration" || stmt.type === "ExportDefaultDeclaration" ? stmt.declaration : stmt;
3644
- if (decl === null || decl === undefined)
3645
- return [];
3646
- if (isFunction(decl))
3647
- return [decl];
3648
- if (decl.type !== "VariableDeclaration")
3649
- return [];
3650
- const found = [];
3651
- for (const d of decl.declarations) {
3652
- const init = d.init === null ? undefined : unwrapTsExpr(d.init);
3653
- if (isFunction(init))
3654
- found.push(init);
3655
- }
3656
- return found;
3657
- }
3658
- function checkBodyPropsDestructure(program, code, browserSpans, jsxNodes, filename, warnings) {
3659
- if (browserSpans.length === 0)
3660
- return;
3653
+ // packages/prunelle/src/compiler/signal-reads.ts
3654
+ var import_oxc_parser7 = require("oxc-parser");
3655
+ var RESOURCE_SIGNAL_FIELDS = new Set(["loading", "error"]);
3656
+ var USE_ACTION_SIGNAL_FIELDS = new Set(["pending", "error", "fieldErrors", "data", "progress"]);
3657
+ var USE_LIVE_SIGNAL_FIELDS = new Set(["status", "last", "error"]);
3658
+ var USE_NAVIGATION_SIGNAL_FIELDS = new Set(["url", "pathname", "navigating"]);
3659
+ var CLIENT_FIELD_HOOKS = new Map([
3660
+ ["@prunellejs/live/client", new Map([["useLive", USE_LIVE_SIGNAL_FIELDS]])],
3661
+ ["@prunellejs/spa/client", new Map([["useNavigation", USE_NAVIGATION_SIGNAL_FIELDS]])]
3662
+ ]);
3663
+ var EMPTY_FIELD_MAP = new Map;
3664
+ function collectReactiveImportCallees(program) {
3665
+ const signalCallees = new Set;
3666
+ const signalFieldCallees = new Map;
3667
+ const storeCallees = new Set;
3661
3668
  for (const stmt of program.body) {
3662
- for (const fn of declaredFunctions(stmt)) {
3663
- if (!browserSpans.some(([s, e]) => fn.start >= s && fn.end <= e))
3664
- continue;
3665
- const rawParam = fn.params[0];
3666
- const param = rawParam?.type === "AssignmentPattern" ? rawParam.left : rawParam;
3667
- if (param?.type !== "Identifier" || fn.body?.type !== "BlockStatement" || !containsJsx(fn.body, jsxNodes))
3668
- continue;
3669
- for (const inner of fn.body.body) {
3670
- if (inner.type !== "VariableDeclaration")
3669
+ if (stmt.type !== "ImportDeclaration" || stmt.importKind === "type")
3670
+ continue;
3671
+ const src = stmt.source.value;
3672
+ const clientHooks = CLIENT_FIELD_HOOKS.get(src);
3673
+ if (src !== "prunelle" && clientHooks === undefined)
3674
+ continue;
3675
+ for (const spec of stmt.specifiers) {
3676
+ if (spec.type === "ImportSpecifier") {
3677
+ if (spec.importKind === "type")
3671
3678
  continue;
3672
- for (const d of inner.declarations) {
3673
- const init = d.init === null ? undefined : unwrapTsExpr(d.init);
3674
- if (d.id.type !== "ObjectPattern" || init?.type !== "Identifier" || init.name !== param.name)
3675
- continue;
3676
- warnings.push({ start: d.start, message: `prunelle compiler: \`${inner.kind} ${code.slice(d.start, d.end)}\` in ${filename} reads the props once, so a change to them never reaches this component: destructure in the parameter list, (${code.slice(d.id.start, d.id.end)}), which stays reactive, or read props.<name> where it is used.` });
3679
+ const imported = spec.imported.type === "Identifier" ? spec.imported.name : spec.imported.value;
3680
+ const local = spec.local.name;
3681
+ if (src === "prunelle") {
3682
+ if (imported === "signal" || imported === "computed" || imported === "resource")
3683
+ signalCallees.add(local);
3684
+ if (imported === "resource")
3685
+ signalFieldCallees.set(local, RESOURCE_SIGNAL_FIELDS);
3686
+ else if (imported === "useAction")
3687
+ signalFieldCallees.set(local, USE_ACTION_SIGNAL_FIELDS);
3688
+ else if (imported === "store")
3689
+ storeCallees.add(local);
3690
+ } else {
3691
+ const fields = clientHooks?.get(imported);
3692
+ if (fields !== undefined)
3693
+ signalFieldCallees.set(local, fields);
3694
+ }
3695
+ } else if (spec.type === "ImportNamespaceSpecifier") {
3696
+ const ns = spec.local.name;
3697
+ if (src === "prunelle") {
3698
+ signalCallees.add(`${ns}.signal`);
3699
+ signalCallees.add(`${ns}.computed`);
3700
+ signalCallees.add(`${ns}.resource`);
3701
+ signalFieldCallees.set(`${ns}.resource`, RESOURCE_SIGNAL_FIELDS);
3702
+ signalFieldCallees.set(`${ns}.useAction`, USE_ACTION_SIGNAL_FIELDS);
3703
+ storeCallees.add(`${ns}.store`);
3704
+ } else if (clientHooks !== undefined) {
3705
+ for (const [hook, fields] of clientHooks)
3706
+ signalFieldCallees.set(`${ns}.${hook}`, fields);
3677
3707
  }
3678
3708
  }
3679
3709
  }
3680
3710
  }
3711
+ return { signalCallees, signalFieldCallees, storeCallees };
3681
3712
  }
3682
-
3683
- // packages/prunelle/src/compiler/signal-reads.ts
3684
- var import_oxc_parser7 = require("oxc-parser");
3685
- function bindPattern(scope, pattern, isSignal = false) {
3713
+ var PLAIN_ENTRY = { isSignal: false };
3714
+ var SIGNAL_ENTRY = { isSignal: true };
3715
+ function bindPattern(scope, pattern, entry = PLAIN_ENTRY) {
3686
3716
  if (pattern === null || pattern === undefined)
3687
3717
  return;
3688
3718
  if (pattern.type === "Identifier") {
3689
- scope.set(pattern.name, isSignal);
3719
+ scope.set(pattern.name, entry);
3720
+ return;
3721
+ }
3722
+ if (pattern.type === "ObjectPattern" && entry.fields !== undefined) {
3723
+ for (const prop of pattern.properties) {
3724
+ if (prop.type === "RestElement") {
3725
+ bindPattern(scope, prop.argument);
3726
+ continue;
3727
+ }
3728
+ const key = !prop.computed ? prop.key.type === "Identifier" ? prop.key.name : prop.key.type === "Literal" ? String(prop.key.value) : undefined : undefined;
3729
+ const target = prop.value.type === "AssignmentPattern" ? prop.value.left : prop.value;
3730
+ bindPattern(scope, target, key !== undefined && entry.fields.has(key) ? SIGNAL_ENTRY : PLAIN_ENTRY);
3731
+ }
3690
3732
  return;
3691
3733
  }
3692
3734
  walk(pattern, (node) => {
3693
3735
  if (node.type === "Identifier")
3694
- scope.set(node.name, false);
3736
+ scope.set(node.name, PLAIN_ENTRY);
3695
3737
  if (node.type === "AssignmentPattern")
3696
3738
  bindPattern(scope, node.left);
3697
3739
  else if (node.type === "Property")
@@ -3699,37 +3741,40 @@ function bindPattern(scope, pattern, isSignal = false) {
3699
3741
  return node.type !== "AssignmentPattern" && node.type !== "Property";
3700
3742
  });
3701
3743
  }
3702
- function bindStatements(scope, statements, signalCallees, importedSignals) {
3744
+ function bindStatements(scope, statements, signalCallees, signalFieldCallees, importedSignals) {
3703
3745
  for (const stmt of statements) {
3704
3746
  const decl = stmt.type === "ExportNamedDeclaration" || stmt.type === "ExportDefaultDeclaration" ? stmt.declaration : stmt;
3705
3747
  if (decl?.type === "VariableDeclaration") {
3706
3748
  for (const d of decl.declarations) {
3707
3749
  const init = d.init === null ? undefined : unwrapTsExpr(d.init);
3708
- bindPattern(scope, d.id, init?.type === "CallExpression" && signalCallees.has(calleeName(init.callee)));
3750
+ const callee = init?.type === "CallExpression" ? calleeName(init.callee) : "";
3751
+ const isSignal = callee !== "" && signalCallees.has(callee);
3752
+ const fields = callee !== "" ? signalFieldCallees.get(callee) : undefined;
3753
+ bindPattern(scope, d.id, isSignal || fields !== undefined ? { isSignal, fields } : PLAIN_ENTRY);
3709
3754
  }
3710
3755
  } else if ((decl?.type === "FunctionDeclaration" || decl?.type === "ClassDeclaration") && decl.id !== null) {
3711
- scope.set(decl.id.name, false);
3756
+ scope.set(decl.id.name, PLAIN_ENTRY);
3712
3757
  } else if (decl?.type === "ImportDeclaration") {
3713
3758
  for (const spec of decl.specifiers)
3714
- scope.set(spec.local.name, importedSignals?.has(spec.local.name) === true);
3759
+ scope.set(spec.local.name, importedSignals?.has(spec.local.name) === true ? SIGNAL_ENTRY : PLAIN_ENTRY);
3715
3760
  }
3716
3761
  }
3717
3762
  }
3718
- function scopeOf(node, signalCallees, importedSignals) {
3763
+ function scopeOf(node, signalCallees, signalFieldCallees, importedSignals) {
3719
3764
  const scope = new Map;
3720
3765
  switch (node.type) {
3721
3766
  case "Program":
3722
- bindStatements(scope, node.body, signalCallees, importedSignals);
3767
+ bindStatements(scope, node.body, signalCallees, signalFieldCallees, importedSignals);
3723
3768
  return scope;
3724
3769
  case "BlockStatement":
3725
3770
  case "StaticBlock":
3726
- bindStatements(scope, node.body, signalCallees);
3771
+ bindStatements(scope, node.body, signalCallees, signalFieldCallees);
3727
3772
  return scope;
3728
3773
  case "FunctionDeclaration":
3729
3774
  case "FunctionExpression":
3730
3775
  case "ArrowFunctionExpression":
3731
3776
  if (node.type === "FunctionExpression" && node.id !== null)
3732
- scope.set(node.id.name, false);
3777
+ scope.set(node.id.name, PLAIN_ENTRY);
3733
3778
  for (const param of node.params)
3734
3779
  bindPattern(scope, param);
3735
3780
  return scope;
@@ -3738,7 +3783,7 @@ function scopeOf(node, signalCallees, importedSignals) {
3738
3783
  case "ForOfStatement": {
3739
3784
  const head = node.type === "ForStatement" ? node.init : node.left;
3740
3785
  if (head?.type === "VariableDeclaration")
3741
- bindStatements(scope, [head], signalCallees);
3786
+ bindStatements(scope, [head], signalCallees, signalFieldCallees);
3742
3787
  return scope;
3743
3788
  }
3744
3789
  case "CatchClause":
@@ -3746,37 +3791,40 @@ function scopeOf(node, signalCallees, importedSignals) {
3746
3791
  return scope;
3747
3792
  case "SwitchStatement":
3748
3793
  for (const c of node.cases)
3749
- bindStatements(scope, c.consequent, signalCallees);
3794
+ bindStatements(scope, c.consequent, signalCallees, signalFieldCallees);
3750
3795
  return scope;
3751
3796
  default:
3752
3797
  return;
3753
3798
  }
3754
3799
  }
3755
- function walkWithSignals(program, signalCallees, importedSignals, importedSignalMembers, visit) {
3800
+ function walkWithSignals(program, signalCallees, signalFieldCallees, importedSignals, importedSignalMembers, visit) {
3756
3801
  const scopes = [];
3757
3802
  const lookup = {
3758
3803
  isSignal(name) {
3759
3804
  for (let i = scopes.length - 1;i >= 0; i--) {
3760
3805
  const found = scopes[i].get(name);
3761
3806
  if (found !== undefined)
3762
- return found;
3807
+ return found.isSignal;
3763
3808
  }
3764
3809
  return false;
3765
3810
  },
3766
3811
  isSignalMember(obj, prop) {
3767
- const members = importedSignalMembers.get(obj);
3768
- if (members === undefined || !members.has(prop))
3769
- return false;
3770
- for (let i = scopes.length - 1;i >= 1; i--) {
3771
- if (scopes[i].has(obj))
3772
- return false;
3812
+ for (let i = scopes.length - 1;i >= 0; i--) {
3813
+ const found = scopes[i].get(obj);
3814
+ if (found !== undefined) {
3815
+ if (found.fields !== undefined)
3816
+ return found.fields.has(prop);
3817
+ if (i > 0)
3818
+ return false;
3819
+ break;
3820
+ }
3773
3821
  }
3774
- return true;
3822
+ return importedSignalMembers.get(obj)?.has(prop) === true;
3775
3823
  }
3776
3824
  };
3777
3825
  const visitor = (node) => {
3778
3826
  visit(node, lookup);
3779
- const scope = scopeOf(node, signalCallees, importedSignals);
3827
+ const scope = scopeOf(node, signalCallees, signalFieldCallees, importedSignals);
3780
3828
  if (scope === undefined)
3781
3829
  return;
3782
3830
  scopes.push(scope);
@@ -3860,10 +3908,12 @@ function destructuredSignal(node, lookup) {
3860
3908
  return takesValue ? name : undefined;
3861
3909
  }
3862
3910
  function checkBareSignals(program, signalCallees, filename, importedSignals = new Set, importedSignalMembers = new Map) {
3863
- if (signalCallees.size === 0 && importedSignals.size === 0 && importedSignalMembers.size === 0)
3911
+ const checkLocal = importedSignals.size === 0 && importedSignalMembers.size === 0;
3912
+ const signalFieldCallees = checkLocal ? collectReactiveImportCallees(program).signalFieldCallees : EMPTY_FIELD_MAP;
3913
+ if (signalCallees.size === 0 && signalFieldCallees.size === 0 && importedSignals.size === 0 && importedSignalMembers.size === 0)
3864
3914
  return;
3865
3915
  const reported = new Set;
3866
- walkWithSignals(program, signalCallees, importedSignals, importedSignalMembers, (node, lookup) => {
3916
+ walkWithSignals(program, signalCallees, signalFieldCallees, importedSignals, importedSignalMembers, (node, lookup) => {
3867
3917
  for (const expr of [...jsxReads(node), ...codeTests(node)]) {
3868
3918
  const found = bareSignal(expr, lookup);
3869
3919
  if (found === undefined || reported.has(found.start))
@@ -3881,6 +3931,243 @@ function checkBareSignals(program, signalCallees, filename, importedSignals = ne
3881
3931
  });
3882
3932
  }
3883
3933
 
3934
+ // packages/prunelle/src/compiler/props-body.ts
3935
+ function isFunction(node) {
3936
+ return node !== null && node !== undefined && (node.type === "FunctionDeclaration" || node.type === "FunctionExpression" || node.type === "ArrowFunctionExpression");
3937
+ }
3938
+ function declaredFunctions(stmt) {
3939
+ const decl = stmt.type === "ExportNamedDeclaration" || stmt.type === "ExportDefaultDeclaration" ? stmt.declaration : stmt;
3940
+ if (decl === null || decl === undefined)
3941
+ return [];
3942
+ if (isFunction(decl))
3943
+ return [decl];
3944
+ if (decl.type !== "VariableDeclaration")
3945
+ return [];
3946
+ const found = [];
3947
+ for (const d of decl.declarations) {
3948
+ const init = d.init === null ? undefined : unwrapTsExpr(d.init);
3949
+ if (isFunction(init))
3950
+ found.push(init);
3951
+ }
3952
+ return found;
3953
+ }
3954
+ function shadowNames(scope, names, snapshots) {
3955
+ for (const name of names) {
3956
+ scope.signals.delete(name);
3957
+ scope.fieldObjs.delete(name);
3958
+ scope.stores.delete(name);
3959
+ snapshots?.delete(name);
3960
+ }
3961
+ }
3962
+ function recordDeclaratorBinding(d, callees, scope, snapshots, isConst = false) {
3963
+ const init = d.init === null ? undefined : unwrapTsExpr(d.init);
3964
+ if (d.id.type === "Identifier") {
3965
+ const name = d.id.name;
3966
+ shadowNames(scope, [name], snapshots);
3967
+ if (init === undefined)
3968
+ return;
3969
+ if (init.type === "CallExpression") {
3970
+ const callee = calleeName(init.callee);
3971
+ if (callees.storeCallees.has(callee)) {
3972
+ scope.stores.add(name);
3973
+ return;
3974
+ }
3975
+ if (callees.signalCallees.has(callee))
3976
+ scope.signals.add(name);
3977
+ const fields = callees.signalFieldCallees.get(callee);
3978
+ if (fields !== undefined)
3979
+ scope.fieldObjs.set(name, fields);
3980
+ return;
3981
+ }
3982
+ if (isConst && snapshots !== undefined && init.type === "MemberExpression" && !init.computed && init.property.type === "Identifier" && init.property.name === "value") {
3983
+ const obj = unwrapTsExpr(init.object);
3984
+ if (obj.type === "Identifier" && scope.signals.has(obj.name))
3985
+ snapshots.set(name, { source: `${obj.name}.value`, start: d.start });
3986
+ else if (obj.type === "MemberExpression" && !obj.computed && obj.object.type === "Identifier" && obj.property.type === "Identifier" && scope.fieldObjs.get(obj.object.name)?.has(obj.property.name))
3987
+ snapshots.set(name, { source: `${obj.object.name}.${obj.property.name}.value`, start: d.start });
3988
+ }
3989
+ return;
3990
+ }
3991
+ const bound = new Set;
3992
+ collectPatternNames(d.id, bound);
3993
+ shadowNames(scope, bound, snapshots);
3994
+ if (d.id.type === "ObjectPattern" && init?.type === "CallExpression") {
3995
+ const fields = callees.signalFieldCallees.get(calleeName(init.callee));
3996
+ if (fields === undefined)
3997
+ return;
3998
+ for (const prop of d.id.properties) {
3999
+ if (prop.type !== "Property" || prop.computed)
4000
+ continue;
4001
+ const key = prop.key.type === "Identifier" ? prop.key.name : prop.key.type === "Literal" ? String(prop.key.value) : undefined;
4002
+ const target = prop.value.type === "AssignmentPattern" ? prop.value.left : prop.value;
4003
+ if (key !== undefined && fields.has(key) && target.type === "Identifier")
4004
+ scope.signals.add(target.name);
4005
+ }
4006
+ }
4007
+ }
4008
+ function collectModuleReactiveScope(program, callees) {
4009
+ const scope = { signals: new Set, fieldObjs: new Map, stores: new Set };
4010
+ for (const stmt of program.body) {
4011
+ const decl = stmt.type === "ExportNamedDeclaration" ? stmt.declaration : stmt;
4012
+ if (decl?.type === "VariableDeclaration") {
4013
+ for (const d of decl.declarations)
4014
+ recordDeclaratorBinding(d, callees, scope);
4015
+ }
4016
+ }
4017
+ return scope;
4018
+ }
4019
+ function collectPatternIdentifierStarts(pattern, out) {
4020
+ walk(pattern, (node) => {
4021
+ if (node.type === "Identifier") {
4022
+ if (!out.has(node.name))
4023
+ out.set(node.name, node.start);
4024
+ return false;
4025
+ }
4026
+ if (node.type === "AssignmentPattern") {
4027
+ collectPatternIdentifierStarts(node.left, out);
4028
+ return false;
4029
+ }
4030
+ if (node.type === "Property") {
4031
+ collectPatternIdentifierStarts(node.value, out);
4032
+ return false;
4033
+ }
4034
+ return;
4035
+ });
4036
+ }
4037
+ function scanJsxNodeReads(jsxNode, outerShadowed, snapshots, jsxNodes, found) {
4038
+ const scanExpr = (expr) => {
4039
+ walkScoped(expr, {
4040
+ onIdentifier(id, innerShadowed) {
4041
+ const snap = snapshots.get(id.name);
4042
+ if (snap !== undefined && id.start > snap.start && !outerShadowed.has(id.name) && !innerShadowed.has(id.name))
4043
+ found.add(id.name);
4044
+ },
4045
+ onFunction(fn) {
4046
+ return !containsJsx(fn.body, jsxNodes);
4047
+ },
4048
+ onJsx(nested, innerShadowed) {
4049
+ const combined = innerShadowed.size === 0 ? outerShadowed : new Set([...outerShadowed, ...innerShadowed]);
4050
+ scanJsxNodeReads(nested, combined, snapshots, jsxNodes, found);
4051
+ }
4052
+ });
4053
+ };
4054
+ if (jsxNode.type === "JSXElement") {
4055
+ for (const attr of jsxNode.openingElement.attributes) {
4056
+ if (attr.type === "JSXSpreadAttribute") {
4057
+ scanExpr(attr.argument);
4058
+ continue;
4059
+ }
4060
+ const attrName = jsxTagName(attr.name);
4061
+ if (EVENT_ATTR.test(attrName) || attrName === "ref")
4062
+ continue;
4063
+ if (attr.value?.type === "JSXExpressionContainer" && attr.value.expression.type !== "JSXEmptyExpression")
4064
+ scanExpr(attr.value.expression);
4065
+ }
4066
+ }
4067
+ for (const child of jsxNode.children) {
4068
+ if (child.type === "JSXElement" || child.type === "JSXFragment")
4069
+ scanJsxNodeReads(child, outerShadowed, snapshots, jsxNodes, found);
4070
+ else if (child.type === "JSXExpressionContainer" && child.expression.type !== "JSXEmptyExpression")
4071
+ scanExpr(child.expression);
4072
+ }
4073
+ }
4074
+ function findDirectJsxSnapshotReads(body, snapshots, jsxNodes) {
4075
+ const found = new Set;
4076
+ for (const stmt of body.body) {
4077
+ walkScoped(stmt, {
4078
+ onFunction(fn) {
4079
+ return !containsJsx(fn.body, jsxNodes);
4080
+ },
4081
+ onJsx(node, shadowed) {
4082
+ scanJsxNodeReads(node, shadowed, snapshots, jsxNodes, found);
4083
+ }
4084
+ });
4085
+ }
4086
+ return found;
4087
+ }
4088
+ function checkComponentBody(fn, code, callees, moduleScope, jsxNodes, filename, warnings, isBrowser) {
4089
+ if (fn.body === null || !containsJsx(fn.body, jsxNodes))
4090
+ return;
4091
+ const rawParam = fn.params[0];
4092
+ const param = rawParam?.type === "AssignmentPattern" ? rawParam.left : rawParam;
4093
+ if (isBrowser && param?.type === "ObjectPattern") {
4094
+ const propNames = new Set;
4095
+ collectPatternNames(param, propNames);
4096
+ const mutated = collectMutatedNames(fn.body, propNames);
4097
+ if (mutated.size > 0) {
4098
+ const starts = new Map;
4099
+ collectPatternIdentifierStarts(param, starts);
4100
+ for (const name of mutated) {
4101
+ warnings.push({
4102
+ start: starts.get(name) ?? param.start,
4103
+ message: `prunelle compiler: reassigning destructured prop \`${name}\` in ${filename} copies it once at mount and breaks reactivity: keep props read-only, or copy into a local \`signal(${name})\` or \`let\` variable.`
4104
+ });
4105
+ }
4106
+ }
4107
+ }
4108
+ if (fn.body.type !== "BlockStatement")
4109
+ return;
4110
+ const propsParamName = isBrowser && param?.type === "Identifier" ? param.name : undefined;
4111
+ const scope = {
4112
+ signals: new Set(moduleScope.signals),
4113
+ fieldObjs: new Map(moduleScope.fieldObjs),
4114
+ stores: new Set(moduleScope.stores)
4115
+ };
4116
+ const paramNames = new Set;
4117
+ for (const p of fn.params)
4118
+ collectPatternNames(p, paramNames);
4119
+ shadowNames(scope, paramNames);
4120
+ const snapshots = new Map;
4121
+ for (const inner of fn.body.body) {
4122
+ if ((inner.type === "FunctionDeclaration" || inner.type === "ClassDeclaration") && inner.id !== null) {
4123
+ shadowNames(scope, [inner.id.name], snapshots);
4124
+ continue;
4125
+ }
4126
+ if (inner.type !== "VariableDeclaration")
4127
+ continue;
4128
+ for (const d of inner.declarations) {
4129
+ const init = d.init === null ? undefined : unwrapTsExpr(d.init);
4130
+ if (propsParamName !== undefined && d.id.type === "ObjectPattern" && init?.type === "Identifier" && init.name === propsParamName) {
4131
+ warnings.push({
4132
+ start: d.start,
4133
+ message: `prunelle compiler: \`${inner.kind} ${code.slice(d.start, d.end)}\` in ${filename} reads the props once, so a change to them never reaches this component: destructure in the parameter list, (${code.slice(d.id.start, d.id.end)}), which stays reactive, or read props.<name> where it is used.`
4134
+ });
4135
+ } else if ((d.id.type === "ObjectPattern" || d.id.type === "ArrayPattern") && init?.type === "Identifier" && scope.stores.has(init.name)) {
4136
+ warnings.push({
4137
+ start: d.start,
4138
+ message: `prunelle compiler: \`${inner.kind} ${code.slice(d.start, d.end)}\` in ${filename} reads store properties once at mount, so updates never reach it: read \`${init.name}.<prop>\` where it is used, or use \`snapshot(${init.name})\` if a one-time copy is intended.`
4139
+ });
4140
+ }
4141
+ recordDeclaratorBinding(d, callees, scope, snapshots, inner.kind === "const");
4142
+ }
4143
+ }
4144
+ if (snapshots.size > 0) {
4145
+ const jsxUsed = findDirectJsxSnapshotReads(fn.body, snapshots, jsxNodes);
4146
+ for (const [name, snap] of snapshots) {
4147
+ if (jsxUsed.has(name)) {
4148
+ warnings.push({
4149
+ start: snap.start,
4150
+ message: `prunelle compiler: \`const ${name} = ${snap.source}\` in ${filename} snapshots \`${snap.source}\` once at mount and never updates in JSX: read \`${snap.source}\` directly in JSX, or wrap it in \`computed(() => ...)\`.`
4151
+ });
4152
+ }
4153
+ }
4154
+ }
4155
+ }
4156
+ function checkBodyPropsDestructure(program, code, browserSpans, jsxNodes, filename, warnings) {
4157
+ const callees = collectReactiveImportCallees(program);
4158
+ const hasReactiveHooks = callees.signalCallees.size > 0 || callees.signalFieldCallees.size > 0 || callees.storeCallees.size > 0;
4159
+ if (browserSpans.length === 0 && !hasReactiveHooks)
4160
+ return;
4161
+ const moduleScope = collectModuleReactiveScope(program, callees);
4162
+ for (const stmt of program.body) {
4163
+ for (const fn of declaredFunctions(stmt)) {
4164
+ const isBrowser = browserSpans.some(([s, e]) => fn.start >= s && fn.end <= e);
4165
+ if (isBrowser || hasReactiveHooks)
4166
+ checkComponentBody(fn, code, callees, moduleScope, jsxNodes, filename, warnings, isBrowser);
4167
+ }
4168
+ }
4169
+ }
4170
+
3884
4171
  // packages/prunelle/src/compiler/spread-handlers.ts
3885
4172
  function bindingUnits(program) {
3886
4173
  const units = [];
@@ -3993,9 +4280,10 @@ function unwrapComponentFn(node) {
3993
4280
  }
3994
4281
  function collectPropVars(fn) {
3995
4282
  const vars = new Set;
4283
+ const excluded = new Set;
3996
4284
  const p0 = fn.params[0];
3997
4285
  if (p0 === undefined)
3998
- return vars;
4286
+ return { vars, excluded };
3999
4287
  const pat = p0.type === "AssignmentPattern" ? p0.left : p0;
4000
4288
  if (pat.type === "Identifier") {
4001
4289
  vars.add(pat.name);
@@ -4003,10 +4291,15 @@ function collectPropVars(fn) {
4003
4291
  for (const prop of pat.properties) {
4004
4292
  if (prop.type === "RestElement" && prop.argument.type === "Identifier")
4005
4293
  vars.add(prop.argument.name);
4294
+ else if (prop.type === "Property" && !prop.computed) {
4295
+ const key = propKeyName2(prop.key);
4296
+ if (key !== undefined)
4297
+ excluded.add(key);
4298
+ }
4006
4299
  }
4007
4300
  }
4008
4301
  if (vars.size === 0 || fn.body === null)
4009
- return vars;
4302
+ return { vars, excluded };
4010
4303
  walk(fn.body, (node) => {
4011
4304
  if (node.type !== "VariableDeclarator" || node.init === null)
4012
4305
  return;
@@ -4023,7 +4316,7 @@ function collectPropVars(fn) {
4023
4316
  }
4024
4317
  }
4025
4318
  });
4026
- return vars;
4319
+ return { vars, excluded };
4027
4320
  }
4028
4321
  function exprCarriesPropVar(expr, propVars) {
4029
4322
  const cur = unwrapTsExpr(expr);
@@ -4040,7 +4333,8 @@ function exprCarriesPropVar(expr, propVars) {
4040
4333
  return false;
4041
4334
  }
4042
4335
  function findStaticPropSpreaders(units, inIsland) {
4043
- const direct = new Set;
4336
+ const direct = new Map;
4337
+ const own = new Map;
4044
4338
  const forwardsTo = new Map;
4045
4339
  const staticNames = new Set;
4046
4340
  for (const unit of units) {
@@ -4050,9 +4344,10 @@ function findStaticPropSpreaders(units, inIsland) {
4050
4344
  if (fn === undefined || fn.body === null)
4051
4345
  continue;
4052
4346
  staticNames.add(unit.name);
4053
- const propVars = collectPropVars(fn);
4347
+ const { vars: propVars, excluded } = collectPropVars(fn);
4054
4348
  if (propVars.size === 0)
4055
4349
  continue;
4350
+ own.set(unit.name, excluded);
4056
4351
  walk(fn.body, (node) => {
4057
4352
  if (node.type !== "JSXOpeningElement")
4058
4353
  return;
@@ -4063,7 +4358,7 @@ function findStaticPropSpreaders(units, inIsland) {
4063
4358
  if (!spreadsProps)
4064
4359
  return;
4065
4360
  if (!isComponentTag(tag)) {
4066
- direct.add(unit.name);
4361
+ direct.set(unit.name, excluded);
4067
4362
  } else if (!tag.includes(".")) {
4068
4363
  const set = forwardsTo.get(unit.name) ?? new Set;
4069
4364
  set.add(tag);
@@ -4077,8 +4372,9 @@ function findStaticPropSpreaders(units, inIsland) {
4077
4372
  if (direct.has(name) || !staticNames.has(name))
4078
4373
  continue;
4079
4374
  for (const target of targets) {
4080
- if (direct.has(target)) {
4081
- direct.add(name);
4375
+ const through = direct.get(target);
4376
+ if (through !== undefined) {
4377
+ direct.set(name, new Set([...own.get(name) ?? [], ...through]));
4082
4378
  changed = true;
4083
4379
  break;
4084
4380
  }
@@ -4100,12 +4396,13 @@ function checkStaticSpreadHandlers(units, topInits, interactivity, filename, war
4100
4396
  if (node.type !== "JSXOpeningElement")
4101
4397
  return;
4102
4398
  const tag = jsxTagName(node.name);
4103
- if (!spreaders.has(tag))
4399
+ const excluded = spreaders.get(tag);
4400
+ if (excluded === undefined)
4104
4401
  return;
4105
4402
  for (const attr of node.attributes) {
4106
4403
  if (attr.type === "JSXAttribute" && attr.name.type === "JSXIdentifier") {
4107
4404
  const name = attr.name.name;
4108
- if (isInteractiveKey(name) && !isOmittedHandlerValue(attr.value)) {
4405
+ if (isInteractiveKey(name) && !excluded.has(name) && !isOmittedHandlerValue(attr.value)) {
4109
4406
  warnings.push({
4110
4407
  start: attr.start,
4111
4408
  message: `prunelle compiler: "${name}" passed to <${tag}> in ${filename} will not bind because <${tag}> is static and its caller is not an island: move the handler inside <${tag}>, or render <${tag}> from an island.`
@@ -4113,7 +4410,7 @@ function checkStaticSpreadHandlers(units, topInits, interactivity, filename, war
4113
4410
  }
4114
4411
  } else if (attr.type === "JSXSpreadAttribute") {
4115
4412
  const found = findSpreadInteractiveAttr(attr.argument, inits);
4116
- if (found !== undefined) {
4413
+ if (found !== undefined && !excluded.has(found)) {
4117
4414
  warnings.push({
4118
4415
  start: attr.start,
4119
4416
  message: `prunelle compiler: "${found}" spread into <${tag}> in ${filename} will not bind because <${tag}> is static and its caller is not an island: move the handler inside <${tag}>, or render <${tag}> from an island.`
@@ -4127,7 +4424,7 @@ function checkStaticSpreadHandlers(units, topInits, interactivity, filename, war
4127
4424
 
4128
4425
  // packages/prunelle/src/compiler/analyze.ts
4129
4426
  var REACTIVE_IMPORTS = new Set(["signal", "computed", "effect", "onMount", "onCleanup", "selector", "store", "useAction", "resource"]);
4130
- var STATE_PRIMITIVES = new Set(["signal", "computed", "selector", "store"]);
4427
+ var STATE_PRIMITIVES = new Set(["signal", "computed", "selector", "store", "resource"]);
4131
4428
  var PRUNELLE_SOURCES = new Set(["prunelle"]);
4132
4429
  var PRUNELLE_SSR_SOURCES = new Set(["prunelle", "prunelle/internal/ssr"]);
4133
4430
  var PRUNELLE_SERVER_SOURCES = new Set(["prunelle/server"]);
@@ -4273,7 +4570,7 @@ function scanPrunelleImport(scan, source, imported, local, filename, start) {
4273
4570
  });
4274
4571
  if (STATE_PRIMITIVES.has(imported))
4275
4572
  scan.stateCallees.add(local);
4276
- if (imported === "signal" || imported === "computed")
4573
+ if (imported === "signal" || imported === "computed" || imported === "resource")
4277
4574
  scan.signalCallees.add(local);
4278
4575
  if (imported === "effect")
4279
4576
  scan.effectCallees.add(local);
@@ -4295,7 +4592,7 @@ function scanDeclarations(program, filename, imports) {
4295
4592
  };
4296
4593
  const reexportImported = (exported, local, start) => {
4297
4594
  for (const imp of imports.imports) {
4298
- const spec = imp.specifiers.find((s) => s.local === local && s.imported !== "*");
4595
+ const spec = imp.specifiers.find((s) => s.local === local);
4299
4596
  if (spec !== undefined) {
4300
4597
  scan.reexports.push({ exported, local: spec.imported, source: imp.source, start });
4301
4598
  return;
@@ -4319,7 +4616,7 @@ function scanDeclarations(program, filename, imports) {
4319
4616
  scan.asyncLocals.add(stmt.id.name);
4320
4617
  } else if (stmt.type === "ExportAllDeclaration") {
4321
4618
  if (stmt.exportKind !== "type")
4322
- scan.reexports.push({ exported: "*", local: "*", source: stmt.source.value, start: stmt.start });
4619
+ scan.reexports.push({ exported: (stmt.exported === null ? undefined : exportedName(stmt.exported)) ?? "*", local: "*", source: stmt.source.value, start: stmt.start });
4323
4620
  } else if (stmt.type === "ExportDefaultDeclaration") {
4324
4621
  const decl = unwrapTsExpr(stmt.declaration);
4325
4622
  const named = decl.type === "FunctionDeclaration" || decl.type === "ClassDeclaration" ? decl.id?.name : undefined;
@@ -4346,7 +4643,7 @@ function scanDeclarations(program, filename, imports) {
4346
4643
  scan.defaultLocal = local;
4347
4644
  }
4348
4645
  if (stmt.declaration !== null)
4349
- scanExportedDeclaration(scan, stmt.declaration, filename, imports, collectInits, addExport);
4646
+ scanExportedDeclaration(scan, stmt.declaration, filename, imports, collectInits, addExport, reexportImported);
4350
4647
  }
4351
4648
  }
4352
4649
  const hydrateLocal = scan.defaultHydrate === undefined ? scan.exportLocals.get("hydrate") : undefined;
@@ -4354,7 +4651,7 @@ function scanDeclarations(program, filename, imports) {
4354
4651
  scan.defaultHydrate = checkExportHydrate(scan.localInits.get(hydrateLocal), filename);
4355
4652
  return scan;
4356
4653
  }
4357
- function scanExportedDeclaration(scan, decl, filename, imports, collectInits, addExport) {
4654
+ function scanExportedDeclaration(scan, decl, filename, imports, collectInits, addExport, reexportImported) {
4358
4655
  if (decl.type === "FunctionDeclaration" && decl.id !== null) {
4359
4656
  if (decl.async === true)
4360
4657
  scan.asyncLocals.add(decl.id.name);
@@ -4368,6 +4665,8 @@ function scanExportedDeclaration(scan, decl, filename, imports, collectInits, ad
4368
4665
  continue;
4369
4666
  const name = d.id.name;
4370
4667
  addExport(name, name);
4668
+ if (d.init?.type === "Identifier")
4669
+ reexportImported(name, d.init.name, d.start);
4371
4670
  if (name === "prerender" && d.init?.type === "Literal") {
4372
4671
  if (d.init.value === true)
4373
4672
  scan.hasPrerender = true;
@@ -4386,7 +4685,7 @@ function scanExportedDeclaration(scan, decl, filename, imports, collectInits, ad
4386
4685
  var TS_EXPR_WRAPPERS4 = new Set(["TSAsExpression", "TSNonNullExpression", "TSSatisfiesExpression", "TSTypeAssertion", "TSInstantiationExpression"]);
4387
4686
  function scanBody(program, filename, code, imports, decls, warnings, loadCode) {
4388
4687
  const units = bindingUnits(program);
4389
- const body = { hasJsx: false, usesRenderContext: imports.usesRenderContext, deferredIslandTags: new Set, hydrateModes: new Set, jsxTags: new Set, dynamicImports: [], bindings: [], units };
4688
+ const body = { hasJsx: false, usesRenderContext: imports.usesRenderContext, hydrateUses: new Map, hydrateModes: new Set, jsxTags: new Set, dynamicImports: [], bindings: [], units };
4390
4689
  const tracked = new Set(units.map((u) => u.name));
4391
4690
  for (const imp of imports.imports) {
4392
4691
  for (const spec of imp.specifiers)
@@ -4472,6 +4771,7 @@ function scanOpeningElement(node, binding, body, imports, unitInits, filename) {
4472
4771
  binding.serverOnlyTag ??= member;
4473
4772
  }
4474
4773
  }
4774
+ let useMode = "";
4475
4775
  for (const attr of node.attributes) {
4476
4776
  if (attr.type === "JSXSpreadAttribute") {
4477
4777
  if (!isComponent && tag !== "") {
@@ -4488,12 +4788,13 @@ function scanOpeningElement(node, binding, body, imports, unitInits, filename) {
4488
4788
  const mode = hydrateMode(attr.value);
4489
4789
  guarded(attr.start, () => checkHydrateMode(mode, `$hydrate="${mode}"`, filename));
4490
4790
  body.hydrateModes.add(mode);
4491
- if (mode !== "load")
4492
- body.deferredIslandTags.add(tag);
4791
+ useMode = mode;
4493
4792
  }
4494
4793
  if (!isComponent && tag !== "" && (EVENT_ATTR.test(attrName) || attrName === "ref"))
4495
4794
  binding.fact ??= { reason: `uses ${attrName}`, offset: attr.start };
4496
4795
  }
4796
+ if (isComponent)
4797
+ body.hydrateUses.set(tag, (body.hydrateUses.get(tag) ?? new Set).add(useMode));
4497
4798
  }
4498
4799
  function scanPrunelleMember(node, binding, body, imports, filename) {
4499
4800
  if (node.computed || node.object.type !== "Identifier" || !imports.prunelleNamespaces.has(node.object.name) || node.property.type !== "Identifier")
@@ -4508,7 +4809,7 @@ function scanPrunelleMember(node, binding, body, imports, filename) {
4508
4809
  binding.fact ??= { reason: `calls ${callee}`, offset: node.start };
4509
4810
  if (STATE_PRIMITIVES.has(member))
4510
4811
  imports.stateCallees.add(callee);
4511
- if (member === "signal" || member === "computed")
4812
+ if (member === "signal" || member === "computed" || member === "resource")
4512
4813
  imports.signalCallees.add(callee);
4513
4814
  if (RENDER_CONTEXT_IMPORTS.has(member))
4514
4815
  body.usesRenderContext = true;
@@ -4586,7 +4887,7 @@ function analyzeModule(filename, code, program = parseTsx(filename, code)) {
4586
4887
  hasPaths: decls.hasPaths,
4587
4888
  usesRenderContext: body.usesRenderContext,
4588
4889
  defaultHydrate: decls.defaultHydrate,
4589
- deferredIslandTags: body.deferredIslandTags,
4890
+ hydrateUses: body.hydrateUses,
4590
4891
  hydrateModes: body.hydrateModes,
4591
4892
  jsxTags: body.jsxTags,
4592
4893
  asyncLocals: decls.hasAsyncDefault ? new Set([...decls.asyncLocals, decls.exportLocals.get("default") ?? "default"]) : decls.asyncLocals,
@@ -5241,29 +5542,67 @@ function propKeyName4(node) {
5241
5542
  return node.value;
5242
5543
  return;
5243
5544
  }
5244
- function staticString(node) {
5245
- const inner = unwrapTsExpr(node);
5545
+ function topLevelConsts(program) {
5546
+ const consts = new Map;
5547
+ for (const stmt of program.body) {
5548
+ const decl = stmt.type === "ExportNamedDeclaration" ? stmt.declaration : stmt;
5549
+ if (decl?.type !== "VariableDeclaration" || decl.kind !== "const")
5550
+ continue;
5551
+ for (const d of decl.declarations) {
5552
+ if (d.id.type === "Identifier" && d.init !== null)
5553
+ consts.set(d.id.name, d.init);
5554
+ }
5555
+ }
5556
+ const resolve = (node) => {
5557
+ let inner = unwrapTsExpr(node);
5558
+ for (let depth = 0;inner.type === "Identifier" && depth < 8; depth++) {
5559
+ const init = consts.get(inner.name);
5560
+ if (init === undefined)
5561
+ break;
5562
+ inner = unwrapTsExpr(init);
5563
+ }
5564
+ return inner;
5565
+ };
5566
+ return resolve;
5567
+ }
5568
+ function staticString(node, resolve) {
5569
+ const inner = resolve(node);
5246
5570
  if (inner.type === "Literal" && typeof inner.value === "string")
5247
5571
  return inner.value;
5248
5572
  return;
5249
5573
  }
5250
- function extractConfigObject(program) {
5574
+ function extractConfigObject(program, resolve) {
5251
5575
  for (const stmt of program.body) {
5252
5576
  if (stmt.type !== "ExportDefaultDeclaration")
5253
5577
  continue;
5254
- const decl = unwrapTsExpr(stmt.declaration);
5578
+ const decl = resolve(stmt.declaration);
5255
5579
  if (decl.type === "ObjectExpression")
5256
5580
  return decl;
5257
5581
  if (decl.type === "CallExpression" && decl.arguments[0] !== undefined) {
5258
- const arg = unwrapTsExpr(decl.arguments[0]);
5582
+ const arg = resolve(decl.arguments[0]);
5259
5583
  if (arg.type === "ObjectExpression")
5260
5584
  return arg;
5261
5585
  }
5262
5586
  }
5263
5587
  return;
5264
5588
  }
5265
- function parseStaticCompliance(node) {
5266
- const obj = unwrapTsExpr(node);
5589
+ function collectIgnoredRules(array, resolve, rules) {
5590
+ for (const el of array.elements) {
5591
+ if (el === null)
5592
+ continue;
5593
+ if (el.type === "SpreadElement") {
5594
+ const spread = resolve(el.argument);
5595
+ if (spread.type === "ArrayExpression")
5596
+ collectIgnoredRules(spread, resolve, rules);
5597
+ continue;
5598
+ }
5599
+ const s = staticString(el, resolve);
5600
+ if (s !== undefined)
5601
+ rules.push(s);
5602
+ }
5603
+ }
5604
+ function parseStaticCompliance(node, resolve) {
5605
+ const obj = resolve(node);
5267
5606
  if (obj.type !== "ObjectExpression")
5268
5607
  return;
5269
5608
  const out = {};
@@ -5271,20 +5610,14 @@ function parseStaticCompliance(node) {
5271
5610
  if (prop.type !== "Property")
5272
5611
  continue;
5273
5612
  const key = propKeyName4(prop.key);
5274
- const val = unwrapTsExpr(prop.value);
5613
+ const val = resolve(prop.value);
5275
5614
  if (key === "publicBody" && val.type === "Literal" && typeof val.value === "boolean") {
5276
5615
  out.publicBody = val.value;
5277
5616
  } else if (key === "legalNotice" && val.type === "Literal" && (val.value === false || typeof val.value === "string")) {
5278
5617
  out.legalNotice = val.value;
5279
5618
  } else if (key === "ignore" && val.type === "ArrayExpression") {
5280
5619
  const rules = [];
5281
- for (const el of val.elements) {
5282
- if (el !== null && el.type !== "SpreadElement") {
5283
- const s = staticString(el);
5284
- if (s !== undefined)
5285
- rules.push(s);
5286
- }
5287
- }
5620
+ collectIgnoredRules(val, resolve, rules);
5288
5621
  out.ignore = rules;
5289
5622
  }
5290
5623
  }
@@ -5310,16 +5643,17 @@ function readStaticProjectConfig(projectRoot) {
5310
5643
  try {
5311
5644
  const code = import_node_fs.readFileSync(cfgPath, "utf8");
5312
5645
  const parsed = import_oxc_parser10.parseSync(cfgPath, code, { lang: "ts", sourceType: "module" });
5313
- const obj = parsed.errors.length === 0 ? extractConfigObject(parsed.program) : undefined;
5646
+ const resolve = topLevelConsts(parsed.program);
5647
+ const obj = parsed.errors.length === 0 ? extractConfigObject(parsed.program, resolve) : undefined;
5314
5648
  if (obj !== undefined) {
5315
5649
  for (const prop of obj.properties) {
5316
5650
  if (prop.type !== "Property")
5317
5651
  continue;
5318
5652
  const key = propKeyName4(prop.key);
5319
5653
  if (key === "site")
5320
- site = staticString(prop.value);
5654
+ site = staticString(prop.value, resolve);
5321
5655
  else if (key === "compliance")
5322
- compliance = parseStaticCompliance(prop.value);
5656
+ compliance = parseStaticCompliance(prop.value, resolve);
5323
5657
  }
5324
5658
  }
5325
5659
  } catch {