prunelle 0.1.1 → 0.5.3

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 (120) hide show
  1. package/llms.txt +23 -19
  2. package/package.json +8 -2
  3. package/src/a11y/declaration.ts +335 -0
  4. package/src/a11y/index.ts +446 -0
  5. package/src/a11y/rgaa-map.ts +184 -0
  6. package/src/attrs.ts +11 -3
  7. package/src/build/bundle.ts +80 -36
  8. package/src/build/client-entries.ts +3 -2
  9. package/src/build/client-plugin.ts +8 -4
  10. package/src/build/client-prune.ts +56 -6
  11. package/src/build/compile.ts +11 -9
  12. package/src/build/ecoindex.ts +229 -0
  13. package/src/build/index.ts +174 -108
  14. package/src/build/islands.ts +2 -2
  15. package/src/build/manifest.ts +66 -5
  16. package/src/build/output.ts +2 -2
  17. package/src/build/plugin-host.ts +91 -33
  18. package/src/build/precompress.ts +15 -2
  19. package/src/build/prerender.ts +128 -46
  20. package/src/build/report.ts +23 -2
  21. package/src/build/resolve.ts +8 -6
  22. package/src/build/routes.ts +175 -10
  23. package/src/build/static.ts +137 -39
  24. package/src/build/status-pages.ts +127 -0
  25. package/src/build/style-bundles.ts +526 -0
  26. package/src/cli/check-forms.ts +561 -0
  27. package/src/cli/check-links.ts +632 -0
  28. package/src/cli/check.ts +75 -20
  29. package/src/cli/commands.ts +85 -4
  30. package/src/cli/docs.ts +402 -0
  31. package/src/cli/inspect.ts +103 -14
  32. package/src/cli/mcp-tools.ts +490 -0
  33. package/src/cli/mcp.ts +205 -0
  34. package/src/cli/new.ts +2 -2
  35. package/src/cli/render.ts +421 -0
  36. package/src/cli/upgrade-names.ts +73 -13
  37. package/src/cli/upgrade.ts +137 -16
  38. package/src/compiler/analyze.ts +42 -9
  39. package/src/compiler/browser-globals.ts +140 -17
  40. package/src/compiler/cacheability.ts +636 -0
  41. package/src/compiler/compliance-rgaa.ts +508 -0
  42. package/src/compiler/compliance.ts +241 -289
  43. package/src/compiler/data-keys.ts +199 -192
  44. package/src/compiler/dev-source.ts +87 -0
  45. package/src/compiler/dom-attrs.ts +138 -65
  46. package/src/compiler/dom.ts +517 -442
  47. package/src/compiler/expr-context.ts +167 -57
  48. package/src/compiler/mistakes.ts +4 -1
  49. package/src/compiler/props.ts +87 -36
  50. package/src/compiler/scope.ts +400 -333
  51. package/src/compiler/server-only.ts +190 -151
  52. package/src/compiler/shared.ts +40 -12
  53. package/src/compiler/signal-reads.ts +6 -2
  54. package/src/compiler/ssr-prunelle-tags.ts +27 -14
  55. package/src/compiler/ssr.ts +218 -87
  56. package/src/dev/error-log.ts +151 -0
  57. package/src/dev/index.ts +84 -34
  58. package/src/dev/open-editor.ts +204 -0
  59. package/src/dev/protocol.ts +1 -0
  60. package/src/dev/reload.ts +5 -3
  61. package/src/dev/supervisor.ts +42 -25
  62. package/src/dev/watchers.ts +47 -11
  63. package/src/dom/action.ts +43 -20
  64. package/src/dom/attrs.ts +15 -3
  65. package/src/dom/extras.ts +28 -12
  66. package/src/dom/index.ts +26 -8
  67. package/src/dom/island.ts +35 -28
  68. package/src/dom/loop.ts +10 -9
  69. package/src/plugins/config.ts +8 -7
  70. package/src/plugins/index.ts +2 -2
  71. package/src/plugins/load.ts +26 -7
  72. package/src/plugins/order.ts +38 -1
  73. package/src/plugins/public.ts +5 -2
  74. package/src/plugins/services.ts +62 -0
  75. package/src/plugins/types.ts +32 -0
  76. package/src/reactivity/graph.ts +10 -0
  77. package/src/reactivity/index.ts +24 -16
  78. package/src/reactivity/selector.ts +31 -4
  79. package/src/reactivity/store.ts +45 -13
  80. package/src/server/action-protect.ts +198 -0
  81. package/src/server/action-registry.ts +1 -1
  82. package/src/server/action.ts +82 -27
  83. package/src/server/assets.ts +34 -2
  84. package/src/server/compress.ts +91 -9
  85. package/src/server/document.ts +25 -10
  86. package/src/server/errors.ts +303 -65
  87. package/src/server/form-schema.ts +343 -0
  88. package/src/server/health.ts +244 -0
  89. package/src/server/http.ts +128 -31
  90. package/src/server/index.ts +230 -260
  91. package/src/server/loader.ts +5 -0
  92. package/src/server/param-matchers.ts +112 -0
  93. package/src/server/plugin-host.ts +123 -88
  94. package/src/server/public.ts +3 -3
  95. package/src/server/rate-limit.ts +58 -35
  96. package/src/server/request-body.ts +1 -1
  97. package/src/server/route-cache.ts +423 -0
  98. package/src/server/route-table.ts +339 -8
  99. package/src/server/router.ts +125 -40
  100. package/src/server/routing.ts +196 -63
  101. package/src/server/security.ts +208 -32
  102. package/src/server/serve-handlers.ts +21 -7
  103. package/src/server/start.ts +60 -16
  104. package/src/server/static-dir.ts +61 -8
  105. package/src/server/stream.ts +41 -22
  106. package/src/ssr/context.ts +85 -3
  107. package/src/ssr/index.ts +130 -3
  108. package/src/ssr/region.ts +31 -19
  109. package/src/test/browser.ts +28 -13
  110. package/src/test/index.ts +97 -12
  111. package/src/ts-plugin/diagnostics.ts +505 -0
  112. package/src/ts-plugin/fixes.ts +364 -0
  113. package/src/ts-plugin/index.ts +194 -0
  114. package/templates/_shared/AGENTS.md +2 -2
  115. package/templates/_shared/mcp.json +11 -0
  116. package/templates/_shared/src/routes/legal.tsx +5 -0
  117. package/templates/_shared/tsconfig.json +5 -0
  118. package/templates/blog/prunelle.config.ts +1 -1
  119. package/templates/blog/src/routes/index.tsx +4 -0
  120. package/ts-plugin.cjs +4277 -0
@@ -164,67 +164,151 @@ function emitDomExprAttr(
164
164
  return ''
165
165
  }
166
166
 
167
- /** Compiles an HTML/SVG element's attributes, returning the static attribute HTML fragment and pushing DOM ops. */
168
- export function compileElementAttributes(ctx: ElementAttrCompileContext): string {
169
- const { el, tag, elVar, scopeRewrites, ops, postChildOps, delegatedEvents, use, freshVar, compileExpression } = ctx
167
+ function emitInnerHtmlOp(ctx: ElementAttrCompileContext, attr: Extract<Node, { type: 'JSXAttribute' }>, targetOps: string[]): void {
168
+ const { elVar, scopeRewrites, use, compileExpression } = ctx
169
+ if (attr.value?.type === 'Literal') {
170
+ targetOps.push(`${use('setInnerHtml')}(${elVar}, ${JSON.stringify(String(attr.value.value))});`)
171
+ }
172
+ else if (attr.value?.type === 'JSXExpressionContainer' && attr.value.expression.type !== 'JSXEmptyExpression') {
173
+ const expr = attr.value.expression
174
+ targetOps.push(wrapDomOp(`${use('setInnerHtml')}(${elVar}, ${compileExpression(expr, scopeRewrites)})`, isStaticDomExpr(expr, scopeRewrites), use))
175
+ }
176
+ }
177
+
178
+ function emitRefOp(ctx: ElementAttrCompileContext, expr: Node, targetOps: string[]): void {
179
+ const { elVar, scopeRewrites, compileExpression } = ctx
180
+ const refCode = compileExpression(expr, scopeRewrites)
181
+ const unwrapped = unwrapTsExpr(expr)
182
+ if (unwrapped.type === 'ArrowFunctionExpression' || unwrapped.type === 'FunctionExpression')
183
+ targetOps.push(`(${refCode})(${elVar});`)
184
+ else
185
+ targetOps.push(`(${refCode})?.(${elVar});`)
186
+ }
187
+
188
+ function scanSpreadSpecialIndices(attrs: readonly JSXElement['openingElement']['attributes'][number][]): {
189
+ lastSpreadIdx: number
190
+ lastInnerHtmlIdx: number
191
+ lastRefIdx: number
192
+ } {
193
+ let lastSpreadIdx = -1
194
+ let lastInnerHtmlIdx = -1
195
+ let lastRefIdx = -1
196
+ for (let i = 0; i < attrs.length; i++) {
197
+ const attr = attrs[i]!
198
+ if (attr.type === 'JSXSpreadAttribute') {
199
+ lastSpreadIdx = i
200
+ }
201
+ else {
202
+ const rawName = jsxTagName(attr.name)
203
+ if (rawName === 'innerHTML')
204
+ lastInnerHtmlIdx = i
205
+ else if (rawName === 'ref')
206
+ lastRefIdx = i
207
+ }
208
+ }
209
+ return { lastSpreadIdx, lastInnerHtmlIdx, lastRefIdx }
210
+ }
211
+
212
+ function compileSpreadAttributes(ctx: ElementAttrCompileContext, isSelect: boolean): string {
213
+ const { el, elVar, scopeRewrites, ops, postChildOps, use, freshVar, compileExpression } = ctx
170
214
  const attrs = el.openingElement.attributes
171
- const hasSpread = attrs.some(a => a.type === 'JSXSpreadAttribute')
172
- const isFormValueEl = tag === 'textarea' || tag === 'select'
173
- const isSelect = tag === 'select'
215
+ const entries: string[] = []
216
+ const preSpreadOps: string[] = []
217
+ let soleSpreadExpr: string | undefined
218
+ const { lastSpreadIdx, lastInnerHtmlIdx, lastRefIdx } = scanSpreadSpecialIndices(attrs)
174
219
 
175
- if (hasSpread) {
176
- // Plain object spread inside `spread()`'s reactive effect preserves JSX right-to-left precedence,
177
- // tracks reactive props/getters, avoids double-binding events, and avoids pulling in `mergeProps`.
178
- const entries: string[] = []
179
- let soleSpreadExpr: string | undefined
180
-
181
- for (const attr of attrs) {
182
- if (attr.type === 'JSXSpreadAttribute') {
183
- const argCode = compileExpression(attr.argument, scopeRewrites)
184
- if (attrs.length === 1)
185
- soleSpreadExpr = argCode
186
- entries.push(`...(${argCode})`)
187
- continue
220
+ let innerHtmlAttr: Extract<Node, { type: 'JSXAttribute' }> | undefined
221
+ let innerHtmlAfterSpread = false
222
+ let postSpreadRef: Node | undefined
223
+
224
+ for (let i = 0; i < attrs.length; i++) {
225
+ const attr = attrs[i]!
226
+ if (attr.type === 'JSXSpreadAttribute') {
227
+ const argCode = compileExpression(attr.argument, scopeRewrites)
228
+ if (attrs.length === 1)
229
+ soleSpreadExpr = argCode
230
+ entries.push(`...(${argCode})`)
231
+ continue
232
+ }
233
+ const rawName = jsxTagName(attr.name)
234
+ if (rawName === 'key' || rawName === '$hydrate')
235
+ continue
236
+
237
+ if (rawName === 'innerHTML') {
238
+ if (i === lastInnerHtmlIdx) {
239
+ innerHtmlAttr = attr
240
+ innerHtmlAfterSpread = i > lastSpreadIdx
188
241
  }
189
- const rawName = jsxTagName(attr.name)
190
- if (rawName === 'key' || rawName === '$hydrate')
191
- continue
242
+ continue
243
+ }
192
244
 
193
- if (rawName === 'innerHTML') {
194
- if (attr.value?.type === 'Literal') {
195
- ops.push(`${use('setInnerHtml')}(${elVar}, ${JSON.stringify(String(attr.value.value))});`)
245
+ if (rawName === 'ref') {
246
+ if (i !== lastRefIdx && lastRefIdx > lastSpreadIdx)
247
+ continue
248
+ if (attr.value?.type === 'JSXExpressionContainer' && attr.value.expression.type !== 'JSXEmptyExpression') {
249
+ const expr = attr.value.expression
250
+ const unwrapped = unwrapTsExpr(expr)
251
+ const isInlineFn = unwrapped.type === 'ArrowFunctionExpression' || unwrapped.type === 'FunctionExpression'
252
+ if (i > lastSpreadIdx && (isInlineFn || isStaticPropExpr(expr, scopeRewrites))) {
253
+ entries.push('ref: undefined')
254
+ postSpreadRef = expr
196
255
  }
197
- else if (attr.value?.type === 'JSXExpressionContainer' && attr.value.expression.type !== 'JSXEmptyExpression') {
198
- const expr = attr.value.expression
199
- ops.push(wrapDomOp(`${use('setInnerHtml')}(${elVar}, ${compileExpression(expr, scopeRewrites)})`, isStaticDomExpr(expr, scopeRewrites), use))
256
+ else if (isInlineFn) {
257
+ const refVar = freshVar('_r')
258
+ preSpreadOps.push(`const ${refVar} = ${compileExpression(expr, scopeRewrites)};`)
259
+ entries.push(`ref: ${refVar}`)
260
+ }
261
+ else {
262
+ entries.push(`ref: ${compileExpression(expr, scopeRewrites)}`)
200
263
  }
201
- continue
202
264
  }
203
-
204
- const name = rawName === 'className' ? 'class' : rawName === 'htmlFor' ? 'for' : rawName
205
- const isEvent = EVENT_ATTR.test(rawName)
206
- if (!isEvent && rawName !== 'ref' && isBlockedAttr(name))
207
- continue
208
-
209
- const propName = isEvent || rawName === 'ref' ? rawName : name
210
- const propKey = /^[A-Za-z_$][\w$]*$/.test(propName) ? propName : JSON.stringify(propName)
211
- if (attr.value === null)
212
- entries.push(`${propKey}: true`)
213
- else if (attr.value.type === 'Literal')
214
- entries.push(`${propKey}: ${JSON.stringify(attr.value.value)}`)
215
- else if (attr.value.type === 'JSXExpressionContainer' && attr.value.expression.type !== 'JSXEmptyExpression')
216
- entries.push(`${propKey}: ${compileExpression(attr.value.expression, scopeRewrites)}`)
265
+ continue
217
266
  }
218
267
 
219
- const targetOps = isSelect ? postChildOps : ops
220
- if (soleSpreadExpr !== undefined)
221
- targetOps.push(`${use('spread')}(${elVar}, () => (${soleSpreadExpr}));`)
222
- else if (entries.length > 0)
223
- targetOps.push(`${use('spread')}(${elVar}, () => ({ ${entries.join(', ')} }));`)
224
- return ''
268
+ const name = rawName === 'className' ? 'class' : rawName === 'htmlFor' ? 'for' : rawName
269
+ const isEvent = EVENT_ATTR.test(rawName)
270
+ if (!isEvent && isBlockedAttr(name))
271
+ continue
272
+
273
+ const propName = isEvent ? rawName : name
274
+ const propKey = /^[A-Za-z_$][\w$]*$/.test(propName) ? propName : JSON.stringify(propName)
275
+ if (attr.value === null)
276
+ entries.push(`${propKey}: true`)
277
+ else if (attr.value.type === 'Literal')
278
+ entries.push(`${propKey}: ${JSON.stringify(attr.value.value)}`)
279
+ else if (attr.value.type === 'JSXExpressionContainer' && attr.value.expression.type !== 'JSXEmptyExpression')
280
+ entries.push(`${propKey}: ${compileExpression(attr.value.expression, scopeRewrites)}`)
225
281
  }
226
282
 
283
+ const targetOps = isSelect ? postChildOps : ops
284
+ for (const op of preSpreadOps)
285
+ targetOps.push(op)
286
+ if (innerHtmlAttr !== undefined && !innerHtmlAfterSpread)
287
+ emitInnerHtmlOp(ctx, innerHtmlAttr, targetOps)
288
+ if (soleSpreadExpr !== undefined)
289
+ targetOps.push(`${use('spread')}(${elVar}, () => (${soleSpreadExpr}));`)
290
+ else if (entries.length > 0)
291
+ targetOps.push(`${use('spread')}(${elVar}, () => ({ ${entries.join(', ')} }));`)
292
+ if (innerHtmlAttr !== undefined && innerHtmlAfterSpread)
293
+ emitInnerHtmlOp(ctx, innerHtmlAttr, targetOps)
294
+ if (postSpreadRef !== undefined)
295
+ emitRefOp(ctx, postSpreadRef, targetOps)
296
+ return ''
297
+ }
298
+
299
+ /** Compiles an HTML/SVG element's attributes, returning the static attribute HTML fragment and pushing DOM ops. */
300
+ export function compileElementAttributes(ctx: ElementAttrCompileContext): string {
301
+ const { el, tag, elVar, scopeRewrites, ops, postChildOps, delegatedEvents, use, freshVar, compileExpression } = ctx
302
+ const attrs = el.openingElement.attributes
303
+ const hasSpread = attrs.some(a => a.type === 'JSXSpreadAttribute')
304
+ const isFormValueEl = tag === 'textarea' || tag === 'select'
305
+ const isSelect = tag === 'select'
306
+
307
+ if (hasSpread)
308
+ return compileSpreadAttributes(ctx, isSelect)
309
+
227
310
  let html = ''
311
+ let lastInnerHtml: Extract<Node, { type: 'JSXAttribute' }> | undefined
228
312
  for (const attr of attrs) {
229
313
  if (attr.type === 'JSXSpreadAttribute')
230
314
  continue
@@ -233,26 +317,13 @@ export function compileElementAttributes(ctx: ElementAttrCompileContext): string
233
317
  continue
234
318
 
235
319
  if (rawName === 'ref') {
236
- if (attr.value?.type === 'JSXExpressionContainer' && attr.value.expression.type !== 'JSXEmptyExpression') {
237
- const expr = attr.value.expression
238
- const refCode = compileExpression(expr, scopeRewrites)
239
- const unwrapped = unwrapTsExpr(expr)
240
- if (unwrapped.type === 'ArrowFunctionExpression' || unwrapped.type === 'FunctionExpression')
241
- ops.push(`(${refCode})(${elVar});`)
242
- else
243
- ops.push(`(${refCode})?.(${elVar});`)
244
- }
320
+ if (attr.value?.type === 'JSXExpressionContainer' && attr.value.expression.type !== 'JSXEmptyExpression')
321
+ emitRefOp(ctx, attr.value.expression, ops)
245
322
  continue
246
323
  }
247
324
 
248
325
  if (rawName === 'innerHTML') {
249
- if (attr.value?.type === 'Literal') {
250
- ops.push(`${use('setInnerHtml')}(${elVar}, ${JSON.stringify(String(attr.value.value))});`)
251
- }
252
- else if (attr.value?.type === 'JSXExpressionContainer' && attr.value.expression.type !== 'JSXEmptyExpression') {
253
- const expr = attr.value.expression
254
- ops.push(wrapDomOp(`${use('setInnerHtml')}(${elVar}, ${compileExpression(expr, scopeRewrites)})`, isStaticDomExpr(expr, scopeRewrites), use))
255
- }
326
+ lastInnerHtml = attr
256
327
  continue
257
328
  }
258
329
 
@@ -305,6 +376,8 @@ export function compileElementAttributes(ctx: ElementAttrCompileContext): string
305
376
  html += emitDomExprAttr(ctx, name, attr.value.expression, isSelect)
306
377
  }
307
378
  }
379
+ if (lastInnerHtml !== undefined)
380
+ emitInnerHtmlOp(ctx, lastInnerHtml, ops)
308
381
  return html
309
382
  }
310
383