prunelle 0.1.1 → 0.7.2
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/LICENSE +21 -0
- package/llms.txt +137 -40
- package/package.json +11 -2
- package/src/a11y/declaration.ts +373 -0
- package/src/a11y/index.ts +477 -0
- package/src/a11y/rgaa-map.ts +230 -0
- package/src/attrs.ts +11 -3
- package/src/build/bundle.ts +89 -41
- package/src/build/byte-size.ts +11 -0
- package/src/build/client-entries.ts +3 -2
- package/src/build/client-plugin.ts +11 -5
- package/src/build/client-prune.ts +56 -6
- package/src/build/compile.ts +13 -10
- package/src/build/ecoindex.ts +238 -0
- package/src/build/files.ts +15 -0
- package/src/build/first-load.ts +85 -14
- package/src/build/graph.ts +29 -39
- package/src/build/index.ts +225 -122
- package/src/build/island-promote.ts +311 -0
- package/src/build/islands.ts +14 -203
- package/src/build/manifest.ts +56 -116
- package/src/build/output.ts +3 -6
- package/src/build/plugin-host.ts +115 -41
- package/src/build/precompress.ts +16 -3
- package/src/build/prerender.ts +177 -39
- package/src/build/reach.ts +200 -0
- package/src/build/render-rules.ts +2 -2
- package/src/build/report.ts +48 -5
- package/src/build/resolve.ts +8 -6
- package/src/build/routes.ts +175 -10
- package/src/build/static-headers.ts +112 -0
- package/src/build/static.ts +139 -39
- package/src/build/status-pages.ts +127 -0
- package/src/build/style-bundles.ts +526 -0
- package/src/cli/check-forms.ts +636 -0
- package/src/cli/check-imports.ts +31 -0
- package/src/cli/check-links.ts +632 -0
- package/src/cli/check-security.ts +64 -0
- package/src/cli/check.ts +101 -26
- package/src/cli/commands.ts +120 -11
- package/src/cli/docs.ts +403 -0
- package/src/cli/inspect.ts +105 -15
- package/src/cli/mcp-tools.ts +492 -0
- package/src/cli/mcp.ts +205 -0
- package/src/cli/new.ts +16 -5
- package/src/cli/render.ts +416 -0
- package/src/cli/upgrade-names.ts +73 -13
- package/src/cli/upgrade.ts +156 -22
- package/src/compiler/analyze.ts +87 -54
- package/src/compiler/browser-globals.ts +140 -17
- package/src/compiler/cacheability-private.ts +566 -0
- package/src/compiler/cacheability.ts +335 -0
- package/src/compiler/compliance-eco.ts +71 -0
- package/src/compiler/compliance-rgaa.ts +614 -0
- package/src/compiler/compliance-urls.ts +148 -0
- package/src/compiler/compliance.ts +407 -352
- 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 +260 -81
- package/src/compiler/foreign-imports.ts +88 -0
- package/src/compiler/mistakes.ts +23 -2
- package/src/compiler/props-body.ts +60 -0
- 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 +42 -14
- package/src/compiler/signal-reads.ts +6 -2
- package/src/compiler/spread-handlers.ts +295 -0
- package/src/compiler/ssr-prunelle-tags.ts +27 -14
- package/src/compiler/ssr.ts +220 -89
- package/src/context.ts +34 -0
- package/src/dev/error-log.ts +177 -0
- package/src/dev/host-check.ts +32 -0
- package/src/dev/index.ts +94 -34
- package/src/dev/open-editor.ts +228 -0
- package/src/dev/protocol.ts +3 -0
- package/src/dev/reload.ts +5 -3
- package/src/dev/supervisor.ts +50 -25
- package/src/dev/watchers.ts +74 -13
- package/src/dom/action.ts +47 -21
- package/src/dom/attrs.ts +15 -3
- package/src/dom/extras.ts +57 -40
- package/src/dom/index.ts +54 -14
- package/src/dom/island.ts +102 -68
- package/src/dom/loop.ts +66 -32
- package/src/eco/declaration.ts +328 -0
- package/src/eco/index.ts +69 -0
- package/src/index.ts +2 -2
- package/src/jsx-runtime.ts +2 -2
- package/src/plugins/config.ts +18 -12
- package/src/plugins/context.ts +44 -1
- package/src/plugins/index.ts +2 -2
- package/src/plugins/load.ts +30 -10
- package/src/plugins/order.ts +38 -1
- package/src/plugins/public.ts +6 -3
- package/src/plugins/services.ts +84 -0
- package/src/plugins/types.ts +51 -2
- 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 +64 -20
- package/src/server/action-flash.ts +158 -0
- package/src/server/action-protect.ts +199 -0
- package/src/server/action-registry.ts +1 -1
- package/src/server/action.ts +188 -152
- package/src/server/app-secret.ts +63 -0
- package/src/server/assets.ts +34 -2
- package/src/server/compress.ts +96 -10
- package/src/server/consent.ts +59 -22
- package/src/server/cookies.ts +16 -2
- package/src/server/document.ts +25 -10
- package/src/server/env.ts +14 -0
- package/src/server/errors.ts +308 -65
- package/src/server/form-schema.ts +337 -0
- package/src/server/health.ts +275 -0
- package/src/server/http.ts +186 -39
- package/src/server/index.ts +272 -273
- package/src/server/loader.ts +15 -2
- package/src/server/page.ts +15 -0
- package/src/server/param-matchers.ts +112 -0
- package/src/server/plugin-host.ts +125 -88
- package/src/server/public.ts +6 -5
- package/src/server/rate-limit.ts +102 -36
- package/src/server/request-body.ts +1 -1
- package/src/server/route-cache.ts +541 -0
- package/src/server/route-table.ts +356 -11
- package/src/server/router.ts +125 -40
- package/src/server/routing.ts +112 -63
- package/src/server/sanitize-html.ts +309 -0
- package/src/server/security.ts +279 -52
- package/src/server/serve-handlers.ts +31 -7
- package/src/server/standard-schema.ts +17 -0
- package/src/server/start.ts +60 -16
- package/src/server/static-dir.ts +91 -12
- package/src/server/stream.ts +68 -27
- package/src/ssr/consent-banner.ts +58 -0
- package/src/ssr/context.ts +106 -8
- package/src/ssr/index.ts +151 -4
- package/src/ssr/navigation.ts +2 -2
- package/src/ssr/region.ts +40 -19
- package/src/style.ts +64 -1
- 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/gitignore +5 -0
- package/templates/_shared/mcp.json +11 -0
- package/templates/_shared/src/routes/legal.tsx +15 -1
- package/templates/_shared/tsconfig.json +5 -0
- package/templates/app/.env.example +4 -0
- package/templates/app/package.json +2 -1
- package/templates/app/prunelle.config.ts +2 -0
- package/templates/app/src/auth.ts +4 -6
- package/templates/app/src/mail.ts +4 -0
- package/templates/app/src/routes/_layout.tsx +9 -1
- package/templates/app/src/routes/dashboard/index.tsx +42 -8
- package/templates/app/src/routes/login.tsx +49 -30
- package/templates/app/src/routes/privacy.tsx +25 -0
- package/templates/app/src/styles/app.css +8 -1
- package/templates/app/tests/app.test.ts +44 -3
- package/templates/blog/package.json +1 -1
- package/templates/blog/prunelle.config.ts +1 -1
- package/templates/blog/src/routes/_layout.tsx +6 -1
- package/templates/blog/src/routes/index.tsx +5 -1
- package/templates/blog/src/styles/app.css +6 -1
- package/templates/fullstack/package.json +1 -1
- package/templates/fullstack/src/components/GreetForm.tsx +2 -1
- package/templates/fullstack/src/routes/_layout.tsx +4 -0
- package/templates/fullstack/src/styles/app.css +11 -1
- package/templates/minimal/package.json +1 -1
- package/templates/minimal/src/routes/_layout.tsx +4 -0
- package/templates/minimal/src/styles/app.css +11 -1
- package/ts-plugin.cjs +4277 -0
package/src/compiler/props.ts
CHANGED
|
@@ -1,10 +1,92 @@
|
|
|
1
1
|
// Compiles a component's destructured props: reads stay reactive through `__p`, and the function is rewritten around it.
|
|
2
2
|
|
|
3
3
|
import type { ArrowFunctionExpression, Function as OxcFunction, Node, ObjectPattern, ParamPattern } from 'oxc-parser'
|
|
4
|
+
import { walk } from './ast'
|
|
4
5
|
import { SourceEditor } from './patch'
|
|
5
|
-
import { collectMutatedNames, isSafeLazyJsxRef } from './scope'
|
|
6
|
+
import { collectMutatedNames, isSafeLazyJsxRef, referencesAny } from './scope'
|
|
6
7
|
import { collectPatternNames, containsJsx, isJsxNode, unwrapParens, unwrapTsExpr } from './shared'
|
|
7
8
|
|
|
9
|
+
function isReactiveDefault(node: Node, running: ReadonlyMap<string, string>): boolean {
|
|
10
|
+
if (running.size > 0 && referencesAny(node, new Set(running.keys())))
|
|
11
|
+
return true
|
|
12
|
+
let readsValue = false
|
|
13
|
+
walk(node, (child) => {
|
|
14
|
+
if (readsValue)
|
|
15
|
+
return false
|
|
16
|
+
if (child.type === 'ArrowFunctionExpression' || child.type === 'FunctionExpression' || child.type === 'FunctionDeclaration')
|
|
17
|
+
return false
|
|
18
|
+
if (child.type === 'MemberExpression' && !child.computed && child.property.type === 'Identifier' && child.property.name === 'value') {
|
|
19
|
+
readsValue = true
|
|
20
|
+
return false
|
|
21
|
+
}
|
|
22
|
+
return undefined
|
|
23
|
+
})
|
|
24
|
+
return readsValue
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function patchParamDefaults(
|
|
28
|
+
param: Node | null | undefined,
|
|
29
|
+
rewrites: ReadonlyMap<string, string>,
|
|
30
|
+
targetEditor: SourceEditor,
|
|
31
|
+
offset: number,
|
|
32
|
+
compileExpression: (node: Node, rewrites: ReadonlyMap<string, string>) => string,
|
|
33
|
+
): void {
|
|
34
|
+
if (param === null || param === undefined)
|
|
35
|
+
return
|
|
36
|
+
switch (param.type) {
|
|
37
|
+
case 'AssignmentPattern':
|
|
38
|
+
patchParamDefaults(param.left, rewrites, targetEditor, offset, compileExpression)
|
|
39
|
+
targetEditor.replace(param.right.start - offset, param.right.end - offset, compileExpression(param.right, rewrites))
|
|
40
|
+
return
|
|
41
|
+
case 'RestElement':
|
|
42
|
+
patchParamDefaults(param.argument, rewrites, targetEditor, offset, compileExpression)
|
|
43
|
+
return
|
|
44
|
+
case 'TSParameterProperty':
|
|
45
|
+
patchParamDefaults(param.parameter, rewrites, targetEditor, offset, compileExpression)
|
|
46
|
+
return
|
|
47
|
+
case 'ArrayPattern': {
|
|
48
|
+
let cur = rewrites
|
|
49
|
+
for (const el of param.elements) {
|
|
50
|
+
patchParamDefaults(el, cur, targetEditor, offset, compileExpression)
|
|
51
|
+
if (el !== null)
|
|
52
|
+
cur = withoutBindings(cur, [el])
|
|
53
|
+
}
|
|
54
|
+
return
|
|
55
|
+
}
|
|
56
|
+
case 'ObjectPattern': {
|
|
57
|
+
let cur = rewrites
|
|
58
|
+
for (const prop of param.properties) {
|
|
59
|
+
if (prop.type === 'RestElement') {
|
|
60
|
+
patchParamDefaults(prop.argument, cur, targetEditor, offset, compileExpression)
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
if (prop.computed)
|
|
64
|
+
targetEditor.replace(prop.key.start - offset, prop.key.end - offset, compileExpression(prop.key, cur))
|
|
65
|
+
patchParamDefaults(prop.value, cur, targetEditor, offset, compileExpression)
|
|
66
|
+
}
|
|
67
|
+
cur = withoutBindings(cur, [prop])
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export function compileParamList(
|
|
74
|
+
code: string,
|
|
75
|
+
params: readonly ParamPattern[],
|
|
76
|
+
scopeRewrites: ReadonlyMap<string, string>,
|
|
77
|
+
compileExpression: (node: Node, rewrites: ReadonlyMap<string, string>) => string,
|
|
78
|
+
): string {
|
|
79
|
+
let cur = scopeRewrites
|
|
80
|
+
const out: string[] = []
|
|
81
|
+
for (const p of params) {
|
|
82
|
+
const sub = new SourceEditor(code.slice(p.start, p.end))
|
|
83
|
+
patchParamDefaults(p, cur, sub, p.start, compileExpression)
|
|
84
|
+
out.push(sub.toString())
|
|
85
|
+
cur = withoutBindings(cur, [p])
|
|
86
|
+
}
|
|
87
|
+
return out.join(', ')
|
|
88
|
+
}
|
|
89
|
+
|
|
8
90
|
export function withoutBindings(rewrites: ReadonlyMap<string, string>, patterns: readonly Node[]): Map<string, string> {
|
|
9
91
|
const names = new Set<string>()
|
|
10
92
|
for (const pattern of patterns)
|
|
@@ -101,8 +183,9 @@ export function createPropCompiler(ctx: PropCompilerContext): PropCompiler {
|
|
|
101
183
|
if (pat.type === 'AssignmentPattern') {
|
|
102
184
|
const defExpr = compileExpression(pat.right, running)
|
|
103
185
|
const simpleDef = pat.right.type === 'Literal' || pat.right.type === 'Identifier'
|
|
186
|
+
const reactiveDef = !simpleDef && !containsJsx(pat.right, jsxNodes) && isReactiveDefault(pat.right, running)
|
|
104
187
|
let fallback = simpleDef ? defExpr : `(${defExpr})`
|
|
105
|
-
if (!simpleDef && hoisted !== undefined)
|
|
188
|
+
if (!simpleDef && !reactiveDef && hoisted !== undefined)
|
|
106
189
|
fallback = `${hoist(`${use('propDefault')}(() => (${defExpr}), ${src} === undefined)`)}()`
|
|
107
190
|
let nextSrc: string
|
|
108
191
|
if (pat.left.type !== 'Identifier' && hoisted !== undefined) {
|
|
@@ -252,38 +335,6 @@ export function createPropCompiler(ctx: PropCompilerContext): PropCompiler {
|
|
|
252
335
|
return undefined
|
|
253
336
|
}
|
|
254
337
|
|
|
255
|
-
function patchParamDefaults(param: Node | null | undefined, rewrites: ReadonlyMap<string, string>, targetEditor: SourceEditor, offset: number): void {
|
|
256
|
-
if (param === null || param === undefined)
|
|
257
|
-
return
|
|
258
|
-
switch (param.type) {
|
|
259
|
-
case 'AssignmentPattern':
|
|
260
|
-
patchParamDefaults(param.left, rewrites, targetEditor, offset)
|
|
261
|
-
targetEditor.replace(param.right.start - offset, param.right.end - offset, compileExpression(param.right, rewrites))
|
|
262
|
-
return
|
|
263
|
-
case 'RestElement':
|
|
264
|
-
patchParamDefaults(param.argument, rewrites, targetEditor, offset)
|
|
265
|
-
return
|
|
266
|
-
case 'TSParameterProperty':
|
|
267
|
-
patchParamDefaults(param.parameter, rewrites, targetEditor, offset)
|
|
268
|
-
return
|
|
269
|
-
case 'ArrayPattern':
|
|
270
|
-
for (const el of param.elements)
|
|
271
|
-
patchParamDefaults(el, rewrites, targetEditor, offset)
|
|
272
|
-
return
|
|
273
|
-
case 'ObjectPattern':
|
|
274
|
-
for (const prop of param.properties) {
|
|
275
|
-
if (prop.type === 'RestElement') {
|
|
276
|
-
patchParamDefaults(prop.argument, rewrites, targetEditor, offset)
|
|
277
|
-
}
|
|
278
|
-
else {
|
|
279
|
-
if (prop.computed)
|
|
280
|
-
targetEditor.replace(prop.key.start - offset, prop.key.end - offset, compileExpression(prop.key, rewrites))
|
|
281
|
-
patchParamDefaults(prop.value, rewrites, targetEditor, offset)
|
|
282
|
-
}
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
}
|
|
286
|
-
|
|
287
338
|
function computePropRewrites(
|
|
288
339
|
destructured: { pattern: ObjectPattern, defaultExpr: Node | undefined },
|
|
289
340
|
pVar: string,
|
|
@@ -335,7 +386,7 @@ export function createPropCompiler(ctx: PropCompilerContext): PropCompiler {
|
|
|
335
386
|
|
|
336
387
|
for (let i = 1; i < fn.params.length; i++) {
|
|
337
388
|
const extraParam = fn.params[i]!
|
|
338
|
-
patchParamDefaults(extraParam, propRewrites, fnEditor, offset)
|
|
389
|
+
patchParamDefaults(extraParam, propRewrites, fnEditor, offset, compileExpression)
|
|
339
390
|
propRewrites = withoutBindings(propRewrites, [extraParam])
|
|
340
391
|
}
|
|
341
392
|
|
|
@@ -364,7 +415,7 @@ export function createPropCompiler(ctx: PropCompilerContext): PropCompiler {
|
|
|
364
415
|
|
|
365
416
|
for (let i = 1; i < fn.params.length; i++) {
|
|
366
417
|
const extraParam = fn.params[i]!
|
|
367
|
-
patchParamDefaults(extraParam, propRewrites, editor, 0)
|
|
418
|
+
patchParamDefaults(extraParam, propRewrites, editor, 0, compileExpression)
|
|
368
419
|
propRewrites = withoutBindings(propRewrites, [extraParam])
|
|
369
420
|
}
|
|
370
421
|
|