prunelle 0.8.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.
- package/llms.txt +68 -51
- package/package.json +7 -2
- package/src/a11y/declaration.ts +10 -17
- package/src/a11y/index.ts +69 -125
- package/src/animate.ts +127 -0
- package/src/build/asides.ts +51 -0
- package/src/build/bundle.ts +94 -136
- package/src/build/client-entries.ts +6 -6
- package/src/build/client-outputs.ts +75 -0
- package/src/build/client-plugin.ts +9 -4
- package/src/build/ecoindex.ts +4 -2
- package/src/build/files.ts +18 -0
- package/src/build/graph.ts +14 -6
- package/src/build/index.ts +23 -11
- package/src/build/island-promote.ts +42 -2
- package/src/build/islands.ts +63 -9
- package/src/build/key-types.ts +31 -0
- package/src/build/manifest.ts +117 -1
- package/src/build/plugin-host.ts +13 -1
- package/src/build/prerender.ts +8 -3
- package/src/build/reach.ts +18 -4
- package/src/build/report.ts +1 -1
- package/src/build/resolve.ts +5 -1
- package/src/build/route-types.ts +16 -0
- package/src/build/routes.ts +42 -15
- package/src/build/seed-ids.ts +65 -0
- package/src/build/seed-writes.ts +111 -0
- package/src/build/static-headers.ts +2 -2
- package/src/build/static.ts +1 -1
- package/src/cli/check-cache.ts +51 -0
- package/src/cli/check-consent.ts +95 -0
- package/src/cli/check-forms.ts +10 -2
- package/src/cli/check-links-patterns.ts +101 -0
- package/src/cli/check-links.ts +30 -105
- package/src/cli/check-regions.ts +185 -0
- package/src/cli/check-security.ts +50 -6
- package/src/cli/check.ts +49 -21
- package/src/cli/commands.ts +138 -16
- package/src/cli/docs.ts +21 -2
- package/src/cli/form-opaque-children.ts +40 -0
- package/src/cli/index.ts +1 -1
- package/src/cli/inspect.ts +2 -0
- package/src/cli/mcp-tools.ts +2 -2
- package/src/cli/new.ts +9 -5
- package/src/cli/upgrade-names.ts +14 -2
- package/src/cli/upgrade.ts +3 -0
- package/src/compiler/analyze.ts +22 -16
- package/src/compiler/cacheability-private.ts +13 -3
- package/src/compiler/cacheability.ts +24 -2
- package/src/compiler/compliance-contrast.ts +322 -0
- package/src/compiler/compliance-empty.ts +24 -0
- package/src/compiler/compliance-rgaa-content.ts +95 -0
- package/src/compiler/compliance-rgaa-criteria.ts +45 -0
- package/src/compiler/compliance-rgaa-pages.ts +140 -0
- package/src/compiler/compliance-rgaa.ts +19 -0
- package/src/compiler/compliance-rules.ts +72 -0
- package/src/compiler/compliance-third-party.ts +59 -0
- package/src/compiler/compliance-urls.ts +52 -0
- package/src/compiler/compliance.ts +61 -93
- package/src/compiler/cookie-inventory.ts +119 -0
- package/src/compiler/dom-attrs.ts +178 -22
- package/src/compiler/dom.ts +31 -44
- package/src/compiler/emit.ts +17 -6
- package/src/compiler/expr-context.ts +260 -207
- package/src/compiler/foreign-imports.ts +5 -3
- package/src/compiler/mistakes.ts +18 -9
- package/src/compiler/props-body.ts +263 -21
- package/src/compiler/props-pattern.ts +211 -0
- package/src/compiler/props.ts +324 -343
- package/src/compiler/signal-reads.ts +142 -29
- package/src/compiler/spread-handlers.ts +25 -13
- package/src/compiler/ssr-emit.ts +510 -0
- package/src/compiler/ssr-helpers.ts +165 -121
- package/src/compiler/ssr.ts +28 -441
- package/src/context.ts +14 -1
- package/src/dev/child.ts +1 -1
- package/src/dev/host-check.ts +2 -1
- package/src/dev/hot-islands.ts +71 -0
- package/src/dev/index.ts +31 -18
- package/src/dev/protocol.ts +1 -1
- package/src/dev/queue.ts +3 -2
- package/src/dev/reload.ts +5 -2
- package/src/dev/supervisor.ts +3 -1
- package/src/dev/watchers.ts +6 -2
- package/src/dom/action.ts +97 -14
- package/src/dom/attrs.ts +93 -25
- package/src/dom/extras.ts +91 -50
- package/src/dom/field-marks.ts +32 -0
- package/src/dom/hot.ts +9 -0
- package/src/dom/index.ts +44 -18
- package/src/dom/island-hot.ts +29 -0
- package/src/dom/island.ts +13 -2
- package/src/dom/loop.ts +259 -188
- package/src/dom/prefetch.ts +135 -0
- package/src/dom/regions.ts +515 -0
- package/src/dom/swap.ts +246 -0
- package/src/dom/trusted.ts +22 -0
- package/src/dom/upload.ts +44 -0
- package/src/eco/declaration.ts +44 -41
- package/src/eco/index.ts +8 -5
- package/src/href.ts +31 -0
- package/src/index.ts +12 -5
- package/src/plugins/config.ts +1 -1
- package/src/plugins/context.ts +7 -1
- package/src/plugins/daily.ts +27 -0
- package/src/plugins/index.ts +3 -3
- package/src/plugins/order.ts +1 -1
- package/src/plugins/public.ts +12 -5
- package/src/plugins/services.ts +88 -14
- package/src/plugins/types.ts +128 -10
- package/src/reactivity/graph.ts +244 -41
- package/src/reactivity/hmr.ts +101 -0
- package/src/reactivity/index.ts +243 -239
- package/src/reactivity/resource.ts +129 -0
- package/src/reactivity/seed.ts +141 -0
- package/src/reactivity/selector.ts +85 -47
- package/src/reactivity/server-seed.ts +202 -0
- package/src/reactivity/store.ts +331 -97
- package/src/rgpd/draft.ts +171 -0
- package/src/rgpd/forms.ts +85 -0
- package/src/rgpd/index.ts +57 -0
- package/src/server/action-flash.ts +1 -0
- package/src/server/action-protect.ts +3 -0
- package/src/server/action-registry.ts +11 -9
- package/src/server/action.ts +51 -19
- package/src/server/app-secret.ts +14 -8
- package/src/server/cache-invalidation.ts +97 -0
- package/src/server/compress.ts +55 -18
- package/src/server/consent.ts +21 -5
- package/src/server/cookie-inventory.ts +78 -0
- package/src/server/cookies.ts +77 -8
- package/src/server/cors.ts +98 -0
- package/src/server/csp-report.ts +90 -0
- package/src/server/discard.ts +13 -0
- package/src/server/document.ts +2 -2
- package/src/server/env.ts +1 -1
- package/src/server/errors.ts +9 -2
- package/src/server/field-errors.ts +91 -0
- package/src/server/form-schema.ts +16 -11
- package/src/server/health.ts +41 -11
- package/src/server/http.ts +28 -11
- package/src/server/index.ts +122 -307
- package/src/server/loader.ts +2 -0
- package/src/server/page.ts +3 -9
- package/src/server/plugin-host.ts +66 -16
- package/src/server/plugin-route-shadow.ts +24 -0
- package/src/server/public.ts +14 -3
- package/src/server/rate-limit.ts +49 -10
- package/src/server/region.ts +22 -2
- package/src/server/request-handler.ts +406 -0
- package/src/server/request-log.ts +94 -0
- package/src/server/route-cache.ts +55 -8
- package/src/server/route-input.ts +54 -0
- package/src/server/route-table.ts +53 -27
- package/src/server/router.ts +2 -1
- package/src/server/routing.ts +104 -45
- package/src/server/sanitize-html.ts +4 -2
- package/src/server/security.ts +38 -8
- package/src/server/serve-handlers.ts +16 -6
- package/src/server/served-file.ts +19 -14
- package/src/server/shared-store.ts +323 -0
- package/src/server/start.ts +12 -5
- package/src/server/static-dir.ts +34 -12
- package/src/server/stream.ts +2 -1
- package/src/server/surface.ts +39 -0
- package/src/server/webhook.ts +50 -0
- package/src/server/workers.ts +168 -0
- package/src/ssr/consent-banner.ts +20 -16
- package/src/ssr/consent-texts.ts +40 -0
- package/src/ssr/context.ts +174 -53
- package/src/ssr/cookie-table.ts +75 -0
- package/src/ssr/index.ts +63 -58
- package/src/ssr/navigation.ts +161 -14
- package/src/ssr/region.ts +9 -3
- package/src/style.ts +12 -5
- package/src/test/browser.ts +53 -23
- package/src/test/build-reuse.ts +85 -0
- package/src/test/index.ts +51 -8
- package/src/test/mount.ts +53 -0
- package/src/test/outside.ts +94 -0
- package/src/ts-plugin/diagnostics.ts +56 -18
- package/templates/_shared/AGENTS.md +1 -1
- package/templates/_shared/Dockerfile +22 -0
- package/templates/_shared/dockerignore +9 -0
- package/templates/_shared/gitignore +2 -0
- package/templates/app/.env.example +3 -1
- package/templates/app/compose.yaml +32 -0
- package/templates/app/db/migrations/001_notes.sql +7 -0
- package/templates/app/db/schema.ts +11 -0
- package/templates/app/package.json +1 -0
- package/templates/app/prunelle.config.ts +6 -0
- package/templates/app/src/actions/notes.ts +26 -0
- package/templates/app/src/auth.ts +4 -2
- package/templates/app/src/db.ts +5 -0
- package/templates/app/src/routes/dashboard/index.tsx +26 -1
- package/templates/app/src/routes/privacy.tsx +6 -2
- package/templates/app/tests/app.test.ts +14 -3
- package/templates/plugin/AGENTS.md +11 -0
- package/templates/plugin/CLAUDE.md +1 -0
- package/templates/plugin/README.md +27 -0
- package/templates/plugin/gitignore +2 -0
- package/templates/plugin/llms.txt +19 -0
- package/templates/plugin/package.json +33 -0
- package/templates/plugin/src/index.ts +40 -0
- package/templates/plugin/tests/fixture/prunelle.config.ts +4 -0
- package/templates/plugin/tests/fixture/src/routes/index.tsx +11 -0
- package/templates/plugin/tests/plugin.test.ts +42 -0
- package/templates/plugin/tsconfig.json +19 -0
- package/ts-plugin.cjs +4058 -2246
package/src/compiler/dom.ts
CHANGED
|
@@ -17,8 +17,8 @@ import type { ExprContext, HydrationMarker, MapCallMatch } from './shared'
|
|
|
17
17
|
import { analyzeModule, getExprContext, loadDeclarations, parseTsx } from './analyze'
|
|
18
18
|
import { walk } from './ast'
|
|
19
19
|
import { createDevSourceAttr } from './dev-source'
|
|
20
|
-
import { collectStaticStyleNames, compileElementAttributes, compileRawTextChildren, formatSetTextOp, resolveComponentCallee } from './dom-attrs'
|
|
21
|
-
import { emitWalkStatements, moduleHeader, SVG_CHILD_TAGS } from './emit'
|
|
20
|
+
import { coalesceLeafEffects, collectStaticStyleNames, compileElementAttributes, compileRawTextChildren, formatSetTextOp, pushTextSlotOp, resolveComponentCallee } from './dom-attrs'
|
|
21
|
+
import { emitWalkStatements, moduleHeader, runtimeAlias, SVG_CHILD_TAGS } from './emit'
|
|
22
22
|
import { SourceEditor } from './patch'
|
|
23
23
|
import { compileParamList, createPropCompiler, isStaticPropExpr, withoutBindings } from './props'
|
|
24
24
|
import { extractBlockKeyExpr, extractKeyExpr, literalArrayConsts, rewriteFreeIdentifiers } from './scope'
|
|
@@ -62,6 +62,7 @@ interface DomCompilerCtx {
|
|
|
62
62
|
templates: { name: string, html: string, isSvg?: boolean }[]
|
|
63
63
|
delegatedEvents: Set<string>
|
|
64
64
|
svgDepth: number
|
|
65
|
+
alias: (name: string) => string
|
|
65
66
|
use: (name: string) => string
|
|
66
67
|
freshVar: (prefix?: string) => string
|
|
67
68
|
nextVarId: () => number
|
|
@@ -72,6 +73,7 @@ interface DomCompilerCtx {
|
|
|
72
73
|
|
|
73
74
|
interface ElementTreeState {
|
|
74
75
|
ops: string[]
|
|
76
|
+
depKeys: Map<number, string>
|
|
75
77
|
walkPlan: WalkItem[]
|
|
76
78
|
childRefs: Map<string, string>
|
|
77
79
|
textSlotsByParent: Map<string, Set<number>>
|
|
@@ -239,7 +241,7 @@ function compileLoopCall(
|
|
|
239
241
|
rowRewrites.set(idxParam, `${idxSig}.value`)
|
|
240
242
|
|
|
241
243
|
const rawRowBody = match.isJsxBody ? compileRootJsx(ctx, match.body as JSXElement | JSXFragment, rowRewrites) : ctx.compileExpression(match.body, rowRewrites)
|
|
242
|
-
const rowBody = ctx.withPrelude(rawRowBody, match.body, prelude)
|
|
244
|
+
const rowBody = staticKeyInserts(ctx, ctx.withPrelude(rawRowBody, match.body, prelude))
|
|
243
245
|
const rowParams = idxSig !== undefined ? `${rowSig}, ${idxSig}` : rowSig
|
|
244
246
|
return {
|
|
245
247
|
isStatic: false,
|
|
@@ -247,6 +249,14 @@ function compileLoopCall(
|
|
|
247
249
|
}
|
|
248
250
|
}
|
|
249
251
|
|
|
252
|
+
// The key rewrite leaves `insert(el, () => _k0, ...)` where a child reads only the hoisted key: a bare name tracks nothing, so it is inserted once.
|
|
253
|
+
function staticKeyInserts(ctx: DomCompilerCtx, rowBody: string): string {
|
|
254
|
+
const insertName = ctx.alias('insert')
|
|
255
|
+
if (!rowBody.includes(`${insertName}(`))
|
|
256
|
+
return rowBody
|
|
257
|
+
return rowBody.replace(new RegExp(`\\b${insertName}\\((\\w+), \\(\\) => ([A-Za-z_$][\\w$]*), `, 'g'), (_, el: string, name: string) => `${ctx.use('insertStatic')}(${el}, ${name}, `)
|
|
258
|
+
}
|
|
259
|
+
|
|
250
260
|
function emitTextSlotOp(
|
|
251
261
|
ctx: DomCompilerCtx,
|
|
252
262
|
tree: ElementTreeState,
|
|
@@ -280,7 +290,7 @@ function emitTextSlotOp(
|
|
|
280
290
|
}
|
|
281
291
|
tree.ops.push(`const ${txtVar} = ${ctx.use('textAfter')}(${markerVar});`)
|
|
282
292
|
}
|
|
283
|
-
tree.ops.
|
|
293
|
+
pushTextSlotOp(tree.ops, tree.depKeys, txtVar, exprCode, expr, scopeRewrites, ctx.use)
|
|
284
294
|
return { html, nextIndex }
|
|
285
295
|
}
|
|
286
296
|
|
|
@@ -295,17 +305,8 @@ function buildElementHtml(
|
|
|
295
305
|
const rawTextTag = RAW_TEXT_ELEMENTS.has(tag) ? tag as 'style' | 'script' : undefined
|
|
296
306
|
const postChildOps: string[] = []
|
|
297
307
|
const attrHtml = compileElementAttributes({
|
|
298
|
-
el,
|
|
299
|
-
|
|
300
|
-
elVar,
|
|
301
|
-
scopeRewrites,
|
|
302
|
-
staticStyleNames: ctx.staticStyleNames,
|
|
303
|
-
ops: tree.ops,
|
|
304
|
-
postChildOps,
|
|
305
|
-
delegatedEvents: ctx.delegatedEvents,
|
|
306
|
-
use: ctx.use,
|
|
307
|
-
freshVar: ctx.freshVar,
|
|
308
|
-
compileExpression: ctx.compileExpression,
|
|
308
|
+
el, tag, elVar, scopeRewrites, staticStyleNames: ctx.staticStyleNames, ops: tree.ops, depKeys: tree.depKeys,
|
|
309
|
+
postChildOps, delegatedEvents: ctx.delegatedEvents, use: ctx.use, freshVar: ctx.freshVar, compileExpression: ctx.compileExpression,
|
|
309
310
|
})
|
|
310
311
|
|
|
311
312
|
let html = `<${tag}${ctx.devSrc(el, tag)}${attrHtml}>`
|
|
@@ -331,15 +332,17 @@ function buildElementHtml(
|
|
|
331
332
|
return v
|
|
332
333
|
}
|
|
333
334
|
|
|
334
|
-
|
|
335
|
+
// A value that reads no signal is inserted once, without an effect.
|
|
336
|
+
const emitInsert = (valueCode: string, marker: HydrationMarker, open: string, close: string, isStatic = false): void => {
|
|
337
|
+
const call = isStatic ? `${ctx.use('insertStatic')}(${elVar}, ${valueCode}` : `${ctx.use('insert')}(${elVar}, () => ${valueCode}`
|
|
335
338
|
if (marker === 'none') {
|
|
336
|
-
tree.ops.push(`${
|
|
339
|
+
tree.ops.push(`${call}, null, null);`)
|
|
337
340
|
}
|
|
338
341
|
else if (marker === 'range-open') {
|
|
339
342
|
const startVar = requestTreeChild(ctx, tree, elVar, domIndex)
|
|
340
343
|
html += open
|
|
341
344
|
domIndex++
|
|
342
|
-
tree.ops.push(`${
|
|
345
|
+
tree.ops.push(`${call}, null, ${startVar});`)
|
|
343
346
|
}
|
|
344
347
|
else {
|
|
345
348
|
const startVar = requestTreeChild(ctx, tree, elVar, domIndex)
|
|
@@ -347,7 +350,7 @@ function buildElementHtml(
|
|
|
347
350
|
html += open + close
|
|
348
351
|
addSlot(tree.rangeSlotsByParent, elVar, domIndex + 1)
|
|
349
352
|
domIndex += 2
|
|
350
|
-
tree.ops.push(`${
|
|
353
|
+
tree.ops.push(`${call}, ${endVar}, ${startVar});`)
|
|
351
354
|
}
|
|
352
355
|
}
|
|
353
356
|
|
|
@@ -417,7 +420,7 @@ function buildElementHtml(
|
|
|
417
420
|
|
|
418
421
|
const exprCode = ctx.compileExpression(slot.expr, scopeRewrites)
|
|
419
422
|
if (nodeCapable) {
|
|
420
|
-
emitInsert(exprCode, marker, open, close)
|
|
423
|
+
emitInsert(exprCode, marker, open, close, isStaticPropExpr(slot.expr, scopeRewrites))
|
|
421
424
|
}
|
|
422
425
|
else {
|
|
423
426
|
const res = emitTextSlotOp(ctx, tree, elVar, domIndex, marker, open, close, exprCode, slot.expr, scopeRewrites)
|
|
@@ -439,16 +442,13 @@ function buildElementHtml(
|
|
|
439
442
|
function compileElementTree(ctx: DomCompilerCtx, rootEl: JSXElement, scopeRewrites: ReadonlyMap<string, string>): string {
|
|
440
443
|
const rootVar = ctx.freshVar('_e')
|
|
441
444
|
const tree: ElementTreeState = {
|
|
442
|
-
ops: [],
|
|
443
|
-
|
|
444
|
-
childRefs: new Map(),
|
|
445
|
-
textSlotsByParent: new Map(),
|
|
446
|
-
rangeSlotsByParent: new Map(),
|
|
447
|
-
varAliases: new Map(),
|
|
445
|
+
ops: [], depKeys: new Map(), walkPlan: [], childRefs: new Map(),
|
|
446
|
+
textSlotsByParent: new Map(), rangeSlotsByParent: new Map(), varAliases: new Map(),
|
|
448
447
|
}
|
|
449
448
|
|
|
450
449
|
const html = buildElementHtml(ctx, tree, rootEl, rootVar, scopeRewrites)
|
|
451
450
|
resolveElementAliases(tree)
|
|
451
|
+
coalesceLeafEffects(tree.ops, tree.depKeys, ctx.alias)
|
|
452
452
|
|
|
453
453
|
const rootTag = jsxTagName(rootEl.openingElement.name)
|
|
454
454
|
const tmplName = ctx.freshVar('_t')
|
|
@@ -582,9 +582,10 @@ export function compileDom(filename: string, code: string, options: CompileDomOp
|
|
|
582
582
|
const counters = new Map<string, number>()
|
|
583
583
|
let varCounter = 0
|
|
584
584
|
|
|
585
|
+
const alias = runtimeAlias(code)
|
|
585
586
|
const use = (name: string): string => {
|
|
586
587
|
used.add(name)
|
|
587
|
-
return
|
|
588
|
+
return alias(name)
|
|
588
589
|
}
|
|
589
590
|
const freshVar = (prefix = '_e'): string => {
|
|
590
591
|
let n = counters.get(prefix) ?? 0
|
|
@@ -627,22 +628,8 @@ export function compileDom(filename: string, code: string, options: CompileDomOp
|
|
|
627
628
|
}
|
|
628
629
|
|
|
629
630
|
const ctx: DomCompilerCtx = {
|
|
630
|
-
code,
|
|
631
|
-
|
|
632
|
-
jsxNodes,
|
|
633
|
-
exprContext,
|
|
634
|
-
staticArrays,
|
|
635
|
-
staticStyleNames,
|
|
636
|
-
devSrc,
|
|
637
|
-
templates,
|
|
638
|
-
delegatedEvents,
|
|
639
|
-
svgDepth: 0,
|
|
640
|
-
use,
|
|
641
|
-
freshVar,
|
|
642
|
-
nextVarId: () => varCounter++,
|
|
643
|
-
compileExpression,
|
|
644
|
-
compileLoopRow,
|
|
645
|
-
withPrelude,
|
|
631
|
+
code, analysis, jsxNodes, exprContext, staticArrays, staticStyleNames, devSrc, templates, delegatedEvents,
|
|
632
|
+
svgDepth: 0, alias, use, freshVar, nextVarId: () => varCounter++, compileExpression, compileLoopRow, withPrelude,
|
|
646
633
|
}
|
|
647
634
|
|
|
648
635
|
walk(program, (node) => {
|
|
@@ -659,7 +646,7 @@ export function compileDom(filename: string, code: string, options: CompileDomOp
|
|
|
659
646
|
return undefined
|
|
660
647
|
})
|
|
661
648
|
|
|
662
|
-
const header = moduleHeader(used, templates, delegatedEvents)
|
|
649
|
+
const header = moduleHeader(used, templates, delegatedEvents, alias)
|
|
663
650
|
if (header !== '')
|
|
664
651
|
editor.prepend(header)
|
|
665
652
|
|
package/src/compiler/emit.ts
CHANGED
|
@@ -22,14 +22,25 @@ export const DELEGATED_EVENTS = new Set([
|
|
|
22
22
|
// Helpers kept out of the dom core, which every island loads: a page pays for them only when one of its islands binds them.
|
|
23
23
|
const ATTR_HELPERS = ['setAttr', 'setClass', 'setProp', 'setSelectValues', 'setStyle']
|
|
24
24
|
const CLAIM_HELPERS = ['eachStatic']
|
|
25
|
-
const EXTRA_HELPERS = ['catchBoundary', 'fragInsert', 'insert', 'mergeProps', 'omit', 'propDefault', 'setInnerHtml', 'show', 'spread']
|
|
25
|
+
const EXTRA_HELPERS = ['catchBoundary', 'fragInsert', 'insert', 'insertStatic', 'mergeProps', 'omit', 'propDefault', 'setInnerHtml', 'show', 'spread']
|
|
26
26
|
|
|
27
27
|
function takeHelpers(used: Set<string>, names: readonly string[]): string[] {
|
|
28
28
|
return names.filter(name => used.delete(name))
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
+
/** The local name a runtime helper is imported under: `__esc`, with underscores added when the app's own source already uses that name. */
|
|
32
|
+
export function runtimeAlias(code: string): (name: string) => string {
|
|
33
|
+
const mentioned = new Set(code.match(/__[\w$]+/g))
|
|
34
|
+
return (name) => {
|
|
35
|
+
let alias = `__${name}`
|
|
36
|
+
while (mentioned.has(alias))
|
|
37
|
+
alias += '_'
|
|
38
|
+
return alias
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
31
42
|
/** The import lines, hoisted templates and delegation call a compiled module starts with. Marks the helpers it needs in `used`. */
|
|
32
|
-
export function moduleHeader(used: Set<string>, templates: readonly { name: string, html: string, isSvg?: boolean }[], delegatedEvents: ReadonlySet<string
|
|
43
|
+
export function moduleHeader(used: Set<string>, templates: readonly { name: string, html: string, isSvg?: boolean }[], delegatedEvents: ReadonlySet<string>, alias: (name: string) => string = name => `__${name}`): string {
|
|
33
44
|
let header = ''
|
|
34
45
|
if (templates.length > 0)
|
|
35
46
|
used.add('template')
|
|
@@ -43,18 +54,18 @@ export function moduleHeader(used: Set<string>, templates: readonly { name: stri
|
|
|
43
54
|
const usedExtras = takeHelpers(used, EXTRA_HELPERS)
|
|
44
55
|
for (const [names, module] of [[[...used].sort(), 'dom'], [usedAttrs, 'dom-attrs'], [usedClaims, 'dom-claim'], [usedExtras, 'dom-extras']] as const) {
|
|
45
56
|
if (names.length > 0)
|
|
46
|
-
header += `import { ${names.map(name => `${name} as
|
|
57
|
+
header += `import { ${names.map(name => `${name} as ${alias(name)}`).join(', ')} } from 'prunelle/internal/${module}';\n`
|
|
47
58
|
}
|
|
48
59
|
// Bun groups modules by the islands reaching them: an island binding attributes or claims reaches the extras too, so the extras other islands use share that chunk instead of costing the page a request of their own (#3683).
|
|
49
60
|
if (usedExtras.length === 0 && usedAttrs.length + usedClaims.length > 0)
|
|
50
61
|
header += `import 'prunelle/internal/dom-extras';\n`
|
|
51
62
|
if (hasLoop)
|
|
52
|
-
header += `import { loop as
|
|
63
|
+
header += `import { loop as ${alias('loop')} } from 'prunelle/internal/dom-loop';\n`
|
|
53
64
|
}
|
|
54
65
|
for (const t of templates)
|
|
55
|
-
header += `const ${t.name} = /* @__PURE__ */
|
|
66
|
+
header += `const ${t.name} = /* @__PURE__ */ ${alias('template')}(${JSON.stringify(t.html)}${t.isSvg ? ', true' : ''});\n`
|
|
56
67
|
if (delegatedEvents.size > 0)
|
|
57
|
-
header +=
|
|
68
|
+
header += `${alias('delegate')}(${JSON.stringify([...delegatedEvents].sort())});\n`
|
|
58
69
|
return header
|
|
59
70
|
}
|
|
60
71
|
|