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
@@ -68,22 +68,49 @@ function propKeyName(node: Node): string | undefined {
68
68
  return undefined
69
69
  }
70
70
 
71
- function staticString(node: Node): string | undefined {
72
- const inner = unwrapTsExpr(node)
71
+ /** Follows an identifier to the top-level `const` that holds it, so a config kept in a variable reads like an inline one. */
72
+ type ResolveConst = (node: Node) => Node
73
+
74
+ function topLevelConsts(program: Program): ResolveConst {
75
+ const consts = new Map<string, Node>()
76
+ for (const stmt of program.body) {
77
+ const decl = stmt.type === 'ExportNamedDeclaration' ? stmt.declaration : stmt
78
+ if (decl?.type !== 'VariableDeclaration' || decl.kind !== 'const')
79
+ continue
80
+ for (const d of decl.declarations) {
81
+ if (d.id.type === 'Identifier' && d.init !== null)
82
+ consts.set(d.id.name, d.init)
83
+ }
84
+ }
85
+ const resolve: ResolveConst = (node) => {
86
+ let inner = unwrapTsExpr(node)
87
+ for (let depth = 0; inner.type === 'Identifier' && depth < 8; depth++) {
88
+ const init = consts.get(inner.name)
89
+ if (init === undefined)
90
+ break
91
+ inner = unwrapTsExpr(init)
92
+ }
93
+ return inner
94
+ }
95
+ return resolve
96
+ }
97
+
98
+ function staticString(node: Node, resolve: ResolveConst): string | undefined {
99
+ const inner = resolve(node)
73
100
  if (inner.type === 'Literal' && typeof inner.value === 'string')
74
101
  return inner.value
75
102
  return undefined
76
103
  }
77
104
 
78
- function extractConfigObject(program: Program): Extract<Node, { type: 'ObjectExpression' }> | undefined {
105
+ function extractConfigObject(program: Program, resolve: ResolveConst): Extract<Node, { type: 'ObjectExpression' }> | undefined {
79
106
  for (const stmt of program.body) {
80
107
  if (stmt.type !== 'ExportDefaultDeclaration')
81
108
  continue
82
- const decl = unwrapTsExpr(stmt.declaration)
109
+ const decl = resolve(stmt.declaration)
83
110
  if (decl.type === 'ObjectExpression')
84
111
  return decl
85
112
  if (decl.type === 'CallExpression' && decl.arguments[0] !== undefined) {
86
- const arg = unwrapTsExpr(decl.arguments[0])
113
+ const arg = resolve(decl.arguments[0])
87
114
  if (arg.type === 'ObjectExpression')
88
115
  return arg
89
116
  }
@@ -91,8 +118,24 @@ function extractConfigObject(program: Program): Extract<Node, { type: 'ObjectExp
91
118
  return undefined
92
119
  }
93
120
 
94
- function parseStaticCompliance(node: Node): ComplianceConfig | undefined {
95
- const obj = unwrapTsExpr(node)
121
+ function collectIgnoredRules(array: Extract<Node, { type: 'ArrayExpression' }>, resolve: ResolveConst, rules: ComplianceRule[]): void {
122
+ for (const el of array.elements) {
123
+ if (el === null)
124
+ continue
125
+ if (el.type === 'SpreadElement') {
126
+ const spread = resolve(el.argument)
127
+ if (spread.type === 'ArrayExpression')
128
+ collectIgnoredRules(spread, resolve, rules)
129
+ continue
130
+ }
131
+ const s = staticString(el, resolve)
132
+ if (s !== undefined)
133
+ rules.push(s as ComplianceRule)
134
+ }
135
+ }
136
+
137
+ function parseStaticCompliance(node: Node, resolve: ResolveConst): ComplianceConfig | undefined {
138
+ const obj = resolve(node)
96
139
  if (obj.type !== 'ObjectExpression')
97
140
  return undefined
98
141
  const out: ComplianceConfig = {}
@@ -100,7 +143,7 @@ function parseStaticCompliance(node: Node): ComplianceConfig | undefined {
100
143
  if (prop.type !== 'Property')
101
144
  continue
102
145
  const key = propKeyName(prop.key)
103
- const val = unwrapTsExpr(prop.value)
146
+ const val = resolve(prop.value)
104
147
  if (key === 'publicBody' && val.type === 'Literal' && typeof val.value === 'boolean') {
105
148
  out.publicBody = val.value
106
149
  }
@@ -109,13 +152,7 @@ function parseStaticCompliance(node: Node): ComplianceConfig | undefined {
109
152
  }
110
153
  else if (key === 'ignore' && val.type === 'ArrayExpression') {
111
154
  const rules: ComplianceRule[] = []
112
- for (const el of val.elements) {
113
- if (el !== null && el.type !== 'SpreadElement') {
114
- const s = staticString(el)
115
- if (s !== undefined)
116
- rules.push(s as ComplianceRule)
117
- }
118
- }
155
+ collectIgnoredRules(val, resolve, rules)
119
156
  out.ignore = rules
120
157
  }
121
158
  }
@@ -145,16 +182,17 @@ export function readStaticProjectConfig(projectRoot: string | undefined): { site
145
182
  try {
146
183
  const code = readFileSync(cfgPath, 'utf8')
147
184
  const parsed = parseSync(cfgPath, code, { lang: 'ts', sourceType: 'module' })
148
- const obj = parsed.errors.length === 0 ? extractConfigObject(parsed.program) : undefined
185
+ const resolve = topLevelConsts(parsed.program)
186
+ const obj = parsed.errors.length === 0 ? extractConfigObject(parsed.program, resolve) : undefined
149
187
  if (obj !== undefined) {
150
188
  for (const prop of obj.properties) {
151
189
  if (prop.type !== 'Property')
152
190
  continue
153
191
  const key = propKeyName(prop.key)
154
192
  if (key === 'site')
155
- site = staticString(prop.value)
193
+ site = staticString(prop.value, resolve)
156
194
  else if (key === 'compliance')
157
- compliance = parseStaticCompliance(prop.value)
195
+ compliance = parseStaticCompliance(prop.value, resolve)
158
196
  }
159
197
  }
160
198
  }