prunelle 0.1.1 → 0.5.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/llms.txt +23 -19
- 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 +91 -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 +654 -0
- package/src/cli/check-links.ts +619 -0
- package/src/cli/check.ts +52 -5
- package/src/cli/commands.ts +86 -4
- package/src/cli/docs.ts +402 -0
- package/src/cli/inspect.ts +31 -2
- package/src/cli/mcp-tools.ts +480 -0
- package/src/cli/mcp.ts +205 -0
- package/src/cli/new.ts +2 -2
- package/src/cli/render.ts +261 -0
- package/src/cli/upgrade-names.ts +73 -13
- package/src/cli/upgrade.ts +137 -16
- package/src/compiler/analyze.ts +20 -6
- package/src/compiler/cacheability.ts +592 -0
- package/src/compiler/compliance-rgaa.ts +502 -0
- package/src/compiler/compliance.ts +120 -221
- package/src/compiler/dev-source.ts +87 -0
- package/src/compiler/dom-attrs.ts +138 -65
- package/src/compiler/dom.ts +12 -11
- package/src/compiler/expr-context.ts +167 -57
- package/src/compiler/props.ts +87 -36
- package/src/compiler/scope.ts +56 -17
- package/src/compiler/ssr-prunelle-tags.ts +27 -14
- package/src/compiler/ssr.ts +216 -84
- 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 +4 -1
- package/src/dom/attrs.ts +15 -3
- package/src/dom/extras.ts +2 -2
- package/src/dom/island.ts +11 -10
- package/src/plugins/config.ts +4 -4
- package/src/plugins/index.ts +2 -2
- package/src/plugins/public.ts +5 -2
- package/src/plugins/services.ts +62 -0
- package/src/plugins/types.ts +32 -0
- 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/errors.ts +303 -65
- package/src/server/form-schema.ts +343 -0
- package/src/server/health.ts +244 -0
- package/src/server/http.ts +128 -31
- package/src/server/index.ts +230 -260
- 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 +120 -1
- package/src/ssr/region.ts +31 -19
- package/src/test/browser.ts +6 -0
- package/src/test/index.ts +17 -3
- package/src/ts-plugin/diagnostics.ts +378 -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
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
|
|
package/src/compiler/scope.ts
CHANGED
|
@@ -4,7 +4,7 @@ import type { ArrowFunctionExpression, BlockStatement, Function as OxcFunction,
|
|
|
4
4
|
import { visitorKeys } from 'oxc-parser'
|
|
5
5
|
import { walk } from './ast'
|
|
6
6
|
import { SourceEditor } from './patch'
|
|
7
|
-
import { collectPatternNames, containsJsx, isJsxNode, unwrapParens, unwrapTsExpr } from './shared'
|
|
7
|
+
import { collectPatternNames, containsJsx, isComponentTag, isJsxNode, jsxTagName, unwrapParens, unwrapTsExpr } from './shared'
|
|
8
8
|
|
|
9
9
|
// Names whose every binding in the file is a `const` holding an array literal: only those can be looped once without tracking.
|
|
10
10
|
export function literalArrayConsts(program: Program): Set<string> {
|
|
@@ -336,24 +336,63 @@ export function walkScoped(rootNode: Node, callbacks: ScopedWalkCallbacks): void
|
|
|
336
336
|
visit(rootNode, new Set())
|
|
337
337
|
}
|
|
338
338
|
|
|
339
|
-
|
|
339
|
+
const LOOP_OR_FN_ANCESTORS = new Set([
|
|
340
|
+
'ArrowFunctionExpression',
|
|
341
|
+
'FunctionExpression',
|
|
342
|
+
'FunctionDeclaration',
|
|
343
|
+
'ForStatement',
|
|
344
|
+
'ForInStatement',
|
|
345
|
+
'ForOfStatement',
|
|
346
|
+
'WhileStatement',
|
|
347
|
+
'DoWhileStatement',
|
|
348
|
+
])
|
|
349
|
+
|
|
350
|
+
function isLazySlotContext(node: Node, ancestors: readonly Node[]): boolean {
|
|
351
|
+
let slotIdx = -1
|
|
352
|
+
let child: Node = node
|
|
353
|
+
for (let i = ancestors.length - 1; i >= 0; i--) {
|
|
354
|
+
const p = ancestors[i]!
|
|
355
|
+
if (p.type === 'ParenthesizedExpression') {
|
|
356
|
+
child = p
|
|
357
|
+
continue
|
|
358
|
+
}
|
|
359
|
+
if (p.type === 'LogicalExpression') {
|
|
360
|
+
if (p.right !== child)
|
|
361
|
+
return false
|
|
362
|
+
child = p
|
|
363
|
+
continue
|
|
364
|
+
}
|
|
365
|
+
if (p.type === 'ConditionalExpression') {
|
|
366
|
+
if (p.test === child)
|
|
367
|
+
return false
|
|
368
|
+
child = p
|
|
369
|
+
continue
|
|
370
|
+
}
|
|
371
|
+
if (p.type === 'JSXExpressionContainer') {
|
|
372
|
+
const holder = ancestors[i - 1]
|
|
373
|
+
if (holder === undefined || (holder.type !== 'JSXElement' && holder.type !== 'JSXFragment'))
|
|
374
|
+
return false
|
|
375
|
+
if (holder.type === 'JSXElement' && isComponentTag(jsxTagName(holder.openingElement.name)))
|
|
376
|
+
return false
|
|
377
|
+
slotIdx = i - 1
|
|
378
|
+
break
|
|
379
|
+
}
|
|
380
|
+
return false
|
|
381
|
+
}
|
|
382
|
+
if (slotIdx < 0)
|
|
383
|
+
return false
|
|
384
|
+
for (let i = slotIdx - 1; i >= 0; i--) {
|
|
385
|
+
if (LOOP_OR_FN_ANCESTORS.has(ancestors[i]!.type))
|
|
386
|
+
return false
|
|
387
|
+
}
|
|
388
|
+
return true
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
/** Returns true if the sole free reference to `name` in `stmts` sits directly in an element/fragment JSX child slot (never a component prop, test position, or repeated use), so deferring `const name = <jsx>` to `() => <jsx>` is observationally equivalent and preserves hydration order. */
|
|
340
392
|
export function isSafeLazyJsxRef(name: string, stmts: readonly Node[]): boolean {
|
|
341
393
|
let safe = true
|
|
342
394
|
let uses = 0
|
|
343
395
|
const ancestors: Node[] = []
|
|
344
|
-
const isSlotContext = (): boolean => {
|
|
345
|
-
for (let i = ancestors.length - 1; i >= 0; i--) {
|
|
346
|
-
const p = ancestors[i]!
|
|
347
|
-
if (p.type === 'ParenthesizedExpression' || p.type === 'LogicalExpression' || p.type === 'ConditionalExpression')
|
|
348
|
-
continue
|
|
349
|
-
if (p.type === 'JSXExpressionContainer') {
|
|
350
|
-
const holder = ancestors[i - 1]
|
|
351
|
-
return holder !== undefined && (holder.type === 'JSXElement' || holder.type === 'JSXFragment' || holder.type === 'JSXAttribute')
|
|
352
|
-
}
|
|
353
|
-
return false
|
|
354
|
-
}
|
|
355
|
-
return false
|
|
356
|
-
}
|
|
357
396
|
const visit = (node: Node | null | undefined, shadowed: Set<string>): void => {
|
|
358
397
|
if (!safe || node === null || node === undefined)
|
|
359
398
|
return
|
|
@@ -369,7 +408,7 @@ export function isSafeLazyJsxRef(name: string, stmts: readonly Node[]): boolean
|
|
|
369
408
|
return
|
|
370
409
|
}
|
|
371
410
|
uses++
|
|
372
|
-
if (!
|
|
411
|
+
if (!isLazySlotContext(node, ancestors))
|
|
373
412
|
safe = false
|
|
374
413
|
return
|
|
375
414
|
}
|
|
@@ -438,7 +477,7 @@ export function isSafeLazyJsxRef(name: string, stmts: readonly Node[]): boolean
|
|
|
438
477
|
visit(s, topShadow)
|
|
439
478
|
}
|
|
440
479
|
}
|
|
441
|
-
return safe && uses
|
|
480
|
+
return safe && uses === 1
|
|
442
481
|
}
|
|
443
482
|
|
|
444
483
|
/** Returns true if `rootNode` contains any free identifier reference to a name in `names`. */
|
|
@@ -2,8 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import type { JSXChild, JSXElement, JSXFragment, Node } from 'oxc-parser'
|
|
4
4
|
import type { StringParts } from './ssr-helpers'
|
|
5
|
-
import { cleanJsxText, decodeHtmlEntities, filterMeaningfulChildren, isComponentTag, isJsxNode, jsxTagName } from './shared'
|
|
6
|
-
import { serializeComponentProps } from './ssr-helpers'
|
|
5
|
+
import { cleanJsxText, decodeHtmlEntities, filterMeaningfulChildren, isComponentTag, isJsxNode, jsxTagName, matchJsxMapCall } from './shared'
|
|
7
6
|
|
|
8
7
|
/** What the two emitters borrow from the running `compileSsr()`. */
|
|
9
8
|
export interface PrunelleTagEmitter {
|
|
@@ -11,20 +10,18 @@ export interface PrunelleTagEmitter {
|
|
|
11
10
|
compileSubExpression: (node: Node) => string
|
|
12
11
|
compileChildren: (children: readonly JSXChild[], slotMarkers?: boolean, inFragment?: boolean) => string
|
|
13
12
|
compileJsx: (node: JSXElement | JSXFragment) => string
|
|
13
|
+
compileComponentRaw: (node: JSXElement, tag: string) => string
|
|
14
14
|
markersAt: (offset: number) => boolean
|
|
15
15
|
directAwaitNodes: WeakSet<Node>
|
|
16
|
+
jsxNodes: WeakSet<Node>
|
|
16
17
|
}
|
|
17
18
|
|
|
18
19
|
// `<Suspense fallback={...}><AsyncComp .../></Suspense>` passes the raw component call or Promise.
|
|
19
|
-
export function emitSuspense(em: PrunelleTagEmitter, node: JSXElement, tag: string, propEntries: string[], parts: StringParts): void {
|
|
20
|
+
export function emitSuspense(em: PrunelleTagEmitter, node: JSXElement, tag: string, propEntries: string[], parts: StringParts, onRaw?: (expr: string) => void): void {
|
|
20
21
|
const meaningful = filterMeaningfulChildren(node.children)
|
|
21
22
|
const only = meaningful.length === 1 ? meaningful[0]! : undefined
|
|
22
23
|
if (only?.type === 'JSXElement' && isComponentTag(jsxTagName(only.openingElement.name))) {
|
|
23
|
-
|
|
24
|
-
if (filterMeaningfulChildren(only.children).length > 0)
|
|
25
|
-
inner.propEntries.push(`children: ${em.use('raw')}(${em.compileChildren(only.children)})`)
|
|
26
|
-
const innerObj = inner.propEntries.length > 0 ? `{ ${inner.propEntries.join(', ')} }` : '{}'
|
|
27
|
-
propEntries.push(`children: ${jsxTagName(only.openingElement.name)}(${innerObj})`)
|
|
24
|
+
propEntries.push(`children: ${em.compileComponentRaw(only, jsxTagName(only.openingElement.name))}`)
|
|
28
25
|
}
|
|
29
26
|
else if (only?.type === 'JSXExpressionContainer' && only.expression.type !== 'JSXEmptyExpression') {
|
|
30
27
|
propEntries.push(`children: ${em.compileSubExpression(only.expression)}`)
|
|
@@ -36,21 +33,37 @@ export function emitSuspense(em: PrunelleTagEmitter, node: JSXElement, tag: stri
|
|
|
36
33
|
propEntries.push(`children: ${em.use('raw')}(${em.compileJsx(only)})`)
|
|
37
34
|
}
|
|
38
35
|
const propsObj = propEntries.length > 0 ? `{ ${propEntries.join(', ')} }` : '{}'
|
|
39
|
-
|
|
36
|
+
const callExpr = `${tag}(${propsObj})`
|
|
37
|
+
if (onRaw !== undefined)
|
|
38
|
+
onRaw(callExpr)
|
|
39
|
+
else
|
|
40
|
+
parts.pushExpr(`${em.use('ssrChild')}(${callExpr})`)
|
|
40
41
|
}
|
|
41
42
|
|
|
42
43
|
// `<Catch>` reads its children inside a try, so they reach it as a getter even when static; in an island it renders in a range of its own, which the browser swaps.
|
|
43
|
-
export function emitCatch(em: PrunelleTagEmitter, node: JSXElement, tag: string, propEntries: string[], parts: StringParts): void {
|
|
44
|
+
export function emitCatch(em: PrunelleTagEmitter, node: JSXElement, tag: string, propEntries: string[], parts: StringParts, onRaw?: (expr: string) => void): void {
|
|
44
45
|
const meaningful = filterMeaningfulChildren(node.children)
|
|
45
46
|
const awaits = node.children.some(c => em.directAwaitNodes.has(c))
|
|
46
|
-
const markers = em.markersAt(node.start)
|
|
47
|
+
const markers = onRaw === undefined && em.markersAt(node.start)
|
|
47
48
|
if (meaningful.length > 0) {
|
|
48
|
-
const
|
|
49
|
-
|
|
49
|
+
const only = meaningful.length === 1 ? meaningful[0]! : undefined
|
|
50
|
+
let childExpr: string
|
|
51
|
+
if (onRaw !== undefined && only?.type === 'JSXElement' && isComponentTag(jsxTagName(only.openingElement.name))) {
|
|
52
|
+
childExpr = em.compileComponentRaw(only, jsxTagName(only.openingElement.name))
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
const singleLoop = only?.type === 'JSXExpressionContainer' && only.expression.type !== 'JSXEmptyExpression' && matchJsxMapCall(only.expression, em.jsxNodes) !== undefined
|
|
56
|
+
childExpr = `${em.use('raw')}(${em.compileChildren(node.children, markers, markers && (meaningful.length > 1 || singleLoop))})`
|
|
57
|
+
}
|
|
58
|
+
propEntries.push(`get children() { return (${awaits ? `(async () => ${childExpr})()` : childExpr}) }`)
|
|
50
59
|
}
|
|
51
60
|
if (markers)
|
|
52
61
|
parts.pushStatic('<!--k[-->')
|
|
53
|
-
|
|
62
|
+
const callExpr = `${awaits ? 'await ' : ''}${tag}({ ${propEntries.join(', ')} })`
|
|
63
|
+
if (onRaw !== undefined)
|
|
64
|
+
onRaw(callExpr)
|
|
65
|
+
else
|
|
66
|
+
parts.pushExpr(`${em.use('ssrChild')}(${callExpr})`)
|
|
54
67
|
if (markers)
|
|
55
68
|
parts.pushStatic('<!--k]-->')
|
|
56
69
|
}
|