prunelle 0.1.1 → 0.6.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.
- package/llms.txt +130 -38
- package/package.json +8 -2
- package/src/a11y/declaration.ts +335 -0
- package/src/a11y/index.ts +446 -0
- package/src/a11y/rgaa-map.ts +184 -0
- package/src/attrs.ts +11 -3
- package/src/build/bundle.ts +80 -36
- package/src/build/client-entries.ts +3 -2
- package/src/build/client-plugin.ts +8 -4
- package/src/build/client-prune.ts +56 -6
- package/src/build/compile.ts +11 -9
- package/src/build/ecoindex.ts +229 -0
- package/src/build/index.ts +174 -108
- package/src/build/islands.ts +2 -2
- package/src/build/manifest.ts +66 -5
- package/src/build/output.ts +2 -2
- package/src/build/plugin-host.ts +92 -33
- package/src/build/precompress.ts +15 -2
- package/src/build/prerender.ts +128 -46
- package/src/build/report.ts +23 -2
- package/src/build/resolve.ts +8 -6
- package/src/build/routes.ts +175 -10
- package/src/build/static.ts +137 -39
- package/src/build/status-pages.ts +127 -0
- package/src/build/style-bundles.ts +526 -0
- package/src/cli/check-forms.ts +561 -0
- package/src/cli/check-links.ts +632 -0
- package/src/cli/check.ts +75 -20
- package/src/cli/commands.ts +85 -4
- package/src/cli/docs.ts +402 -0
- package/src/cli/inspect.ts +103 -14
- package/src/cli/mcp-tools.ts +490 -0
- package/src/cli/mcp.ts +205 -0
- package/src/cli/new.ts +2 -2
- package/src/cli/render.ts +421 -0
- package/src/cli/upgrade-names.ts +73 -13
- package/src/cli/upgrade.ts +137 -16
- package/src/compiler/analyze.ts +42 -9
- package/src/compiler/browser-globals.ts +140 -17
- package/src/compiler/cacheability.ts +636 -0
- package/src/compiler/compliance-rgaa.ts +508 -0
- package/src/compiler/compliance.ts +241 -289
- package/src/compiler/data-keys.ts +199 -192
- package/src/compiler/dev-source.ts +87 -0
- package/src/compiler/dom-attrs.ts +138 -65
- package/src/compiler/dom.ts +517 -442
- package/src/compiler/expr-context.ts +167 -57
- package/src/compiler/mistakes.ts +4 -1
- package/src/compiler/props.ts +87 -36
- package/src/compiler/scope.ts +400 -333
- package/src/compiler/server-only.ts +190 -151
- package/src/compiler/shared.ts +40 -12
- package/src/compiler/signal-reads.ts +6 -2
- package/src/compiler/ssr-prunelle-tags.ts +27 -14
- package/src/compiler/ssr.ts +218 -87
- package/src/dev/error-log.ts +151 -0
- package/src/dev/index.ts +84 -34
- package/src/dev/open-editor.ts +204 -0
- package/src/dev/protocol.ts +1 -0
- package/src/dev/reload.ts +5 -3
- package/src/dev/supervisor.ts +42 -25
- package/src/dev/watchers.ts +47 -11
- package/src/dom/action.ts +43 -20
- package/src/dom/attrs.ts +15 -3
- package/src/dom/extras.ts +28 -12
- package/src/dom/index.ts +26 -8
- package/src/dom/island.ts +35 -28
- package/src/dom/loop.ts +10 -9
- package/src/plugins/config.ts +8 -7
- package/src/plugins/index.ts +2 -2
- package/src/plugins/load.ts +26 -7
- package/src/plugins/order.ts +38 -1
- package/src/plugins/public.ts +5 -2
- package/src/plugins/services.ts +81 -0
- package/src/plugins/types.ts +34 -0
- package/src/reactivity/graph.ts +10 -0
- package/src/reactivity/index.ts +24 -16
- package/src/reactivity/selector.ts +31 -4
- package/src/reactivity/store.ts +45 -13
- package/src/server/action-protect.ts +198 -0
- package/src/server/action-registry.ts +1 -1
- package/src/server/action.ts +82 -27
- package/src/server/assets.ts +34 -2
- package/src/server/compress.ts +91 -9
- package/src/server/document.ts +25 -10
- package/src/server/errors.ts +303 -65
- package/src/server/form-schema.ts +343 -0
- package/src/server/health.ts +244 -0
- package/src/server/http.ts +131 -32
- package/src/server/index.ts +231 -261
- package/src/server/loader.ts +5 -0
- package/src/server/param-matchers.ts +112 -0
- package/src/server/plugin-host.ts +123 -88
- package/src/server/public.ts +3 -3
- package/src/server/rate-limit.ts +58 -35
- package/src/server/request-body.ts +1 -1
- package/src/server/route-cache.ts +423 -0
- package/src/server/route-table.ts +339 -8
- package/src/server/router.ts +125 -40
- package/src/server/routing.ts +196 -63
- package/src/server/security.ts +208 -32
- package/src/server/serve-handlers.ts +21 -7
- package/src/server/start.ts +60 -16
- package/src/server/static-dir.ts +61 -8
- package/src/server/stream.ts +41 -22
- package/src/ssr/context.ts +85 -3
- package/src/ssr/index.ts +130 -3
- package/src/ssr/region.ts +31 -19
- package/src/test/browser.ts +28 -13
- package/src/test/index.ts +97 -12
- package/src/ts-plugin/diagnostics.ts +505 -0
- package/src/ts-plugin/fixes.ts +364 -0
- package/src/ts-plugin/index.ts +194 -0
- package/templates/_shared/AGENTS.md +2 -2
- package/templates/_shared/mcp.json +11 -0
- package/templates/_shared/src/routes/legal.tsx +5 -0
- package/templates/_shared/tsconfig.json +5 -0
- package/templates/blog/prunelle.config.ts +1 -1
- package/templates/blog/src/routes/index.tsx +4 -0
- package/ts-plugin.cjs +4277 -0
|
@@ -164,67 +164,151 @@ function emitDomExprAttr(
|
|
|
164
164
|
return ''
|
|
165
165
|
}
|
|
166
166
|
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
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
|
|
172
|
-
const
|
|
173
|
-
|
|
215
|
+
const entries: string[] = []
|
|
216
|
+
const preSpreadOps: string[] = []
|
|
217
|
+
let soleSpreadExpr: string | undefined
|
|
218
|
+
const { lastSpreadIdx, lastInnerHtmlIdx, lastRefIdx } = scanSpreadSpecialIndices(attrs)
|
|
174
219
|
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
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
|
-
|
|
190
|
-
|
|
191
|
-
continue
|
|
242
|
+
continue
|
|
243
|
+
}
|
|
192
244
|
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
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 (
|
|
198
|
-
const
|
|
199
|
-
|
|
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
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|