@pithyjs/core 0.1.0-beta.17 → 0.1.0-beta.19
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/README.md +4 -0
- package/dist/compile/binds/bindBoundAttributes.d.ts +4 -1
- package/dist/compile/binds/bindBoundAttributes.d.ts.map +1 -1
- package/dist/compile/binds/bindBoundAttributes.js +130 -32
- package/dist/compile/binds/bindBoundAttributes.js.map +1 -1
- package/dist/compile/binds/bindClassDirectives.d.ts.map +1 -1
- package/dist/compile/binds/bindClassDirectives.js +1 -1
- package/dist/compile/binds/bindClassDirectives.js.map +1 -1
- package/dist/compile/binds/bindComponentsTags.d.ts.map +1 -1
- package/dist/compile/binds/bindComponentsTags.js +2 -1
- package/dist/compile/binds/bindComponentsTags.js.map +1 -1
- package/dist/compile/binds/bindEventHandlers.d.ts.map +1 -1
- package/dist/compile/binds/bindEventHandlers.js +12 -3
- package/dist/compile/binds/bindEventHandlers.js.map +1 -1
- package/dist/compile/nodeExpando.d.ts +14 -0
- package/dist/compile/nodeExpando.d.ts.map +1 -1
- package/dist/compile/nodeExpando.js +12 -0
- package/dist/compile/nodeExpando.js.map +1 -1
- package/dist/compile/parseHtml.js +2 -1
- package/dist/compile/parseHtml.js.map +1 -1
- package/dist/runtime/bindings/applyComponent.d.ts.map +1 -1
- package/dist/runtime/bindings/applyComponent.js +3 -2
- package/dist/runtime/bindings/applyComponent.js.map +1 -1
- package/dist/runtime/bindings/applySimple.d.ts.map +1 -1
- package/dist/runtime/bindings/applySimple.js +19 -33
- package/dist/runtime/bindings/applySimple.js.map +1 -1
- package/package.json +2 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bindEventHandlers.d.ts","sourceRoot":"","sources":["../../../src/compile/binds/bindEventHandlers.ts"],"names":[],"mappings":"AAAA;;;;;;EAME;AA0GF;;;;;;GAMG;AACH,wNAAwN;AACxN,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,OAAO,GAAG,gBAAgB,EAChC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAChC,SAAS,EAAE,CAAC,MAAM,IAAI,CAAC,EAAE,GACxB,IAAI,
|
|
1
|
+
{"version":3,"file":"bindEventHandlers.d.ts","sourceRoot":"","sources":["../../../src/compile/binds/bindEventHandlers.ts"],"names":[],"mappings":"AAAA;;;;;;EAME;AA0GF;;;;;;GAMG;AACH,wNAAwN;AACxN,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,OAAO,GAAG,gBAAgB,EAChC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAChC,SAAS,EAAE,CAAC,MAAM,IAAI,CAAC,EAAE,GACxB,IAAI,CAyFN"}
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
*/
|
|
8
8
|
import { isDeclaredDirective } from './declaredDirective.js';
|
|
9
9
|
import { boundaryForElement, setBoundaryError } from './bindErrorBoundary.js';
|
|
10
|
-
import { nodeExpando } from '../nodeExpando.js';
|
|
10
|
+
import { forwardEventKey, nodeExpando } from '../nodeExpando.js';
|
|
11
11
|
/**
|
|
12
12
|
* Walk up the DOM to find the nearest local PithyJS context attached by loops/components.
|
|
13
13
|
* Falls back to the provided root context.
|
|
@@ -106,10 +106,15 @@ export function bindEventHandlers(root, rootCtx, disposers) {
|
|
|
106
106
|
continue;
|
|
107
107
|
// Idempotency key includes attr name (mods) + expression
|
|
108
108
|
const boundSet = getBoundSet(el, eventName);
|
|
109
|
-
const
|
|
109
|
+
const plainKey = `${attr.name}=${handlerExpr}`;
|
|
110
|
+
const fwdCtx = nodeExpando(el).__pithyForwardCtx;
|
|
111
|
+
const forwarded = !!fwdCtx && !!nodeExpando(el).__pithyForwardAttrs?.has(attr.name);
|
|
112
|
+
const boundKey = forwarded ? forwardEventKey(el, plainKey) : plainKey;
|
|
110
113
|
if (boundSet.has(boundKey))
|
|
111
114
|
continue;
|
|
112
|
-
|
|
115
|
+
// An outer level's pass must not rebind this forwarded value as its own.
|
|
116
|
+
const claimsPlain = forwarded && !boundSet.has(plainKey);
|
|
117
|
+
const ctx = forwarded ? fwdCtx : nearestCtx(el, rootCtx);
|
|
113
118
|
const isSimpleIdentifier = /^[a-zA-Z_][a-zA-Z0-9_]*$/.test(handlerExpr);
|
|
114
119
|
// If the expression is a bare identifier and resolves to a function on ctx,
|
|
115
120
|
// we'll call it directly (browser passes the event), preserving 'this' as ctx.
|
|
@@ -162,12 +167,16 @@ export function bindEventHandlers(root, rootCtx, disposers) {
|
|
|
162
167
|
};
|
|
163
168
|
el.addEventListener(eventName, listener, options);
|
|
164
169
|
boundSet.add(boundKey);
|
|
170
|
+
if (claimsPlain)
|
|
171
|
+
boundSet.add(plainKey);
|
|
165
172
|
disposers.push(() => {
|
|
166
173
|
// Note: removeEventListener only considers `capture`; `once`/`passive` are ignored here.
|
|
167
174
|
el.removeEventListener(eventName, listener, {
|
|
168
175
|
capture: !!mods.capture,
|
|
169
176
|
});
|
|
170
177
|
boundSet.delete(boundKey);
|
|
178
|
+
if (claimsPlain)
|
|
179
|
+
boundSet.delete(plainKey);
|
|
171
180
|
});
|
|
172
181
|
}
|
|
173
182
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bindEventHandlers.js","sourceRoot":"","sources":["../../../src/compile/binds/bindEventHandlers.ts"],"names":[],"mappings":"AAAA;;;;;;EAME;AAEF,OAAO,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAC1D,OAAO,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAC3E,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C;;;GAGG;AACH,SAAS,UAAU,CACjB,EAAW,EACX,OAAgC;IAEhC,IAAI,CAAC,GAAmB,EAAE,CAAC;IAC3B,OAAO,CAAC,EAAE,CAAC;QACT,MAAM,KAAK,GAAG,WAAW,CAAC,CAAC,CAAC,CAAC,UAAU,CAA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kC;YAClC,MAAM,OAAO,GAAG;gBACd,OAAO,EAAE,CAAC,CAAC,IAAI,CAAC,OAAO;gBACvB,OAAO,EAAE,CAAC,CAAC,IAAI,CAAC,OAAO;gBACvB,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI;aACS,CAAC;YAE7B,EAAE,CAAC,gBAAgB,CAAC,SAAS,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC;YAElD,QAAQ,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;YACvB,SAAS,CAAC,IAAI,CAAC,GAAG,EAAE;gBAClB,yFAAyF;gBACzF,EAAE,CAAC,mBAAmB,CAAC,SAAS,EAAE,QAAQ,EAAE;oBAC1C,OAAO,EAAE,CAAC,CAAC,IAAI,CAAC,OAAO;iBACxB,CAAC,CAAC;gBACH,QAAQ,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;YAC5B,CAAC,CAAC,CAAC;QACL,CAAC;IACH,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["/** @codex\n{\n \"id\": \"pithy.runtime.events\",\n \"title\": \"Event Handler Binding System\",\n \"category\": \"runtime\"\n}\n*/\n\nimport { isDeclaredDirective } from './declaredDirective';\nimport { boundaryForElement, setBoundaryError } from './bindErrorBoundary';\nimport { nodeExpando } from '../nodeExpando';\n\n/**\n * Walk up the DOM to find the nearest local PithyJS context attached by loops/components.\n * Falls back to the provided root context.\n */\nfunction nearestCtx(\n el: Element,\n rootCtx: Record<string, unknown>\n): Record<string, unknown> {\n let n: Element | null = el;\n while (n) {\n const local = nodeExpando(n).__pithyCtx;\n if (local) return local;\n n = n.parentElement;\n }\n return rootCtx;\n}\n\ntype Mods = {\n once?: boolean;\n prevent?: boolean;\n stop?: boolean;\n self?: boolean;\n capture?: boolean;\n passive?: boolean;\n};\n\nfunction parseEventAttr(name: string): { type: string; mods: Mods } {\n // \"data-on-click\" or \"data-on-click.once.prevent\"\n const raw = name.slice('data-on-'.length);\n const parts = raw.split('.');\n const type = parts[0];\n const mods: Mods = {};\n for (let i = 1; i < parts.length; i++) {\n const p = parts[i];\n if (p === 'once') mods.once = true;\n else if (p === 'prevent') mods.prevent = true;\n else if (p === 'stop') mods.stop = true;\n else if (p === 'self') mods.self = true;\n else if (p === 'capture') mods.capture = true;\n else if (p === 'passive') mods.passive = true;\n }\n return { type, mods };\n}\n\n/**\n * Per-element, per-event registry of bound expressions,\n * so we don't double-attach listeners when DOM is moved or reprocessed.\n */\nconst BOUND_KEY: unique symbol = Symbol('pithy:bound');\n\nfunction getBoundSet(el: Element, type: string) {\n const host = el as Element & { [BOUND_KEY]?: Record<string, Set<string>> };\n const store =\n host[BOUND_KEY] ??\n (host[BOUND_KEY] = Object.create(null) as Record<string, Set<string>>);\n return (store[type] ??= new Set<string>());\n}\n\n/**\n * Compile an expression so it can see ctx + $event + $el.\n * We intentionally do not use compileExpression here so we can inject $event/$el.\n */\nfunction compileWithEvent(\n expr: string,\n ctx: Record<string, unknown>\n): (ev: Event, el: Element) => unknown {\n try {\n // Build a function that accepts (ctx, $event, $el) and returns the expression result.\n // `with(ctx)` makes identifiers resolve against the provided context object.\n // eslint-disable-next-line no-new-func -- JIT event-handler expression evaluation is a core framework feature\n const fn = new Function(\n 'ctx',\n '$event',\n '$el',\n `with (ctx) { return (${expr}); }`\n ) as (ctx: Record<string, unknown>, ev: Event, el: Element) => unknown;\n return (ev: Event, el: Element) => fn(ctx, ev, el);\n } catch (err) {\n if (import.meta.env?.DEV) {\n console.warn(`[bindEventHandlers] ❌ Failed to compile \"${expr}\"`, err);\n }\n // Return a noop runner\n return (_ev: Event, _el: Element) => undefined;\n }\n}\n\n/**\n * Traverse all elements under `root` (Element or DocumentFragment) using a TreeWalker.\n */\nfunction forEachElement(\n root: Element | DocumentFragment,\n cb: (el: Element) => void\n) {\n const walker = document.createTreeWalker(root, NodeFilter.SHOW_ELEMENT);\n let node: Node | null;\n while ((node = walker.nextNode())) {\n cb(node as Element);\n }\n}\n\n/**\n * Binds DOM event handlers within `root`.\n * - Uses nearest element context (e.g., loop item ctx) when present.\n * - Idempotent: won't re-bind the same element/event/expression+modifiers combo.\n * - Supports modifiers: .once .prevent .stop .self .capture .passive\n * - Injects `$event` and `$el` for expression handlers (e.g., @click=\"doThing($event)\")\n */\n/** @codexApi {\"parent\":\"pithy.runtime.events\",\"name\":\"bindEventHandlers\",\"stability\":\"stable\",\"signature\":\"(root: Element | DocumentFragment, rootCtx: Record<string, unknown>, disposers: (() => void)[]) => void\"} */\nexport function bindEventHandlers(\n root: Element | DocumentFragment,\n rootCtx: Record<string, unknown>,\n disposers: (() => void)[]\n): void {\n forEachElement(root, el => {\n // Iterate attributes once; bind any data-on-* handlers\n for (const attr of Array.from(el.attributes)) {\n if (!attr.name.startsWith('data-on-') || !isDeclaredDirective(attr))\n continue;\n\n const { type: eventName, mods } = parseEventAttr(attr.name);\n const handlerExpr = attr.value.trim();\n if (!handlerExpr) continue;\n\n // Idempotency key includes attr name (mods) + expression\n const boundSet = getBoundSet(el, eventName);\n const boundKey = `${attr.name}=${handlerExpr}`;\n if (boundSet.has(boundKey)) continue;\n\n const ctx = nearestCtx(el, rootCtx);\n const isSimpleIdentifier = /^[a-zA-Z_][a-zA-Z0-9_]*$/.test(handlerExpr);\n\n // If the expression is a bare identifier and resolves to a function on ctx,\n // we'll call it directly (browser passes the event), preserving 'this' as ctx.\n const directFn =\n isSimpleIdentifier && typeof ctx[handlerExpr] === 'function'\n ? (ctx[handlerExpr] as EventListener)\n : null;\n\n // Otherwise, compile an event-aware evaluator that can see `$event` & `$el`.\n const runWithEvent = directFn ? null : compileWithEvent(handlerExpr, ctx);\n\n // Final listener with modifiers + $event/$el support + error boundary capture\n const listener: EventListener = (ev: Event) => {\n if (mods.self && ev.target !== el) return;\n if (mods.prevent) ev.preventDefault();\n if (mods.stop) ev.stopPropagation();\n\n try {\n if (directFn) {\n // Call the function from ctx with ctx as 'this'\n return directFn.call(ctx, ev);\n } else if (runWithEvent) {\n const out = runWithEvent(ev, el);\n // If expression returns a function, treat that as a handler and pass the event\n if (typeof out === 'function') {\n return (out as (e: Event) => unknown).call(ctx, ev);\n }\n return out;\n }\n } catch (error) {\n // Find the nearest error boundary and set its error signal with escalation\n const boundaryEl = el.closest('[data-error]') as Element | null;\n const boundary = boundaryForElement(boundaryEl);\n if (boundary) {\n const err =\n error instanceof Error ? error : new Error(String(error));\n setBoundaryError(boundary, err);\n } else {\n // No boundary found, re-throw to maintain original behavior\n throw error;\n }\n }\n };\n\n // Attach with appropriate options\n const options = {\n capture: !!mods.capture,\n passive: !!mods.passive,\n once: !!mods.once,\n } as AddEventListenerOptions;\n\n el.addEventListener(eventName, listener, options);\n\n boundSet.add(boundKey);\n disposers.push(() => {\n // Note: removeEventListener only considers `capture`; `once`/`passive` are ignored here.\n el.removeEventListener(eventName, listener, {\n capture: !!mods.capture,\n });\n boundSet.delete(boundKey);\n });\n }\n });\n}\n"]}
|
|
1
|
+
{"version":3,"file":"bindEventHandlers.js","sourceRoot":"","sources":["../../../src/compile/binds/bindEventHandlers.ts"],"names":[],"mappings":"AAAA;;;;;;EAME;AAEF,OAAO,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAC1D,OAAO,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAC3E,OAAO,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE9D;;;GAGG;AACH,SAAS,UAAU,CACjB,EAAW,EACX,OAAgC;IAEhC,IAAI,CAAC,GAAmB,EAAE,CAAC;IAC3B,OAAO,CAAC,EAAE,CAAC;QACT,MAAM,KAAK,GAAG,WAAW,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC;QACxC,IAAI,KAAK;YAAE,OAAO,KAAK,CAAC;QACxB,CAAC,GAAG,CAAC,CAAC,aAAa,CAAC;IACtB,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC;AAWD,SAAS,cAAc,CAAC,IAAY;IAClC,kDAAkD;IAClD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,GAAG,GACP,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;wBAC5D,gBAAgB,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC;oBAClC,CAAC;yBAAM,CAAC;wBACN,4DAA4D;wBAC5D,MAAM,KAAK,CAAC;oBACd,CAAC;gBACH,CAAC;YACH,CAAC,CAAC;YAEF,kCAAkC;YAClC,MAAM,OAAO,GAAG;gBACd,OAAO,EAAE,CAAC,CAAC,IAAI,CAAC,OAAO;gBACvB,OAAO,EAAE,CAAC,CAAC,IAAI,CAAC,OAAO;gBACvB,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI;aACS,CAAC;YAE7B,EAAE,CAAC,gBAAgB,CAAC,SAAS,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC;YAElD,QAAQ,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;YACvB,IAAI,WAAW;gBAAE,QAAQ,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;YACxC,SAAS,CAAC,IAAI,CAAC,GAAG,EAAE;gBAClB,yFAAyF;gBACzF,EAAE,CAAC,mBAAmB,CAAC,SAAS,EAAE,QAAQ,EAAE;oBAC1C,OAAO,EAAE,CAAC,CAAC,IAAI,CAAC,OAAO;iBACxB,CAAC,CAAC;gBACH,QAAQ,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;gBAC1B,IAAI,WAAW;oBAAE,QAAQ,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;YAC7C,CAAC,CAAC,CAAC;QACL,CAAC;IACH,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["/** @codex\n{\n \"id\": \"pithy.runtime.events\",\n \"title\": \"Event Handler Binding System\",\n \"category\": \"runtime\"\n}\n*/\n\nimport { isDeclaredDirective } from './declaredDirective';\nimport { boundaryForElement, setBoundaryError } from './bindErrorBoundary';\nimport { forwardEventKey, nodeExpando } from '../nodeExpando';\n\n/**\n * Walk up the DOM to find the nearest local PithyJS context attached by loops/components.\n * Falls back to the provided root context.\n */\nfunction nearestCtx(\n el: Element,\n rootCtx: Record<string, unknown>\n): Record<string, unknown> {\n let n: Element | null = el;\n while (n) {\n const local = nodeExpando(n).__pithyCtx;\n if (local) return local;\n n = n.parentElement;\n }\n return rootCtx;\n}\n\ntype Mods = {\n once?: boolean;\n prevent?: boolean;\n stop?: boolean;\n self?: boolean;\n capture?: boolean;\n passive?: boolean;\n};\n\nfunction parseEventAttr(name: string): { type: string; mods: Mods } {\n // \"data-on-click\" or \"data-on-click.once.prevent\"\n const raw = name.slice('data-on-'.length);\n const parts = raw.split('.');\n const type = parts[0];\n const mods: Mods = {};\n for (let i = 1; i < parts.length; i++) {\n const p = parts[i];\n if (p === 'once') mods.once = true;\n else if (p === 'prevent') mods.prevent = true;\n else if (p === 'stop') mods.stop = true;\n else if (p === 'self') mods.self = true;\n else if (p === 'capture') mods.capture = true;\n else if (p === 'passive') mods.passive = true;\n }\n return { type, mods };\n}\n\n/**\n * Per-element, per-event registry of bound expressions,\n * so we don't double-attach listeners when DOM is moved or reprocessed.\n */\nconst BOUND_KEY: unique symbol = Symbol('pithy:bound');\n\nfunction getBoundSet(el: Element, type: string) {\n const host = el as Element & { [BOUND_KEY]?: Record<string, Set<string>> };\n const store =\n host[BOUND_KEY] ??\n (host[BOUND_KEY] = Object.create(null) as Record<string, Set<string>>);\n return (store[type] ??= new Set<string>());\n}\n\n/**\n * Compile an expression so it can see ctx + $event + $el.\n * We intentionally do not use compileExpression here so we can inject $event/$el.\n */\nfunction compileWithEvent(\n expr: string,\n ctx: Record<string, unknown>\n): (ev: Event, el: Element) => unknown {\n try {\n // Build a function that accepts (ctx, $event, $el) and returns the expression result.\n // `with(ctx)` makes identifiers resolve against the provided context object.\n // eslint-disable-next-line no-new-func -- JIT event-handler expression evaluation is a core framework feature\n const fn = new Function(\n 'ctx',\n '$event',\n '$el',\n `with (ctx) { return (${expr}); }`\n ) as (ctx: Record<string, unknown>, ev: Event, el: Element) => unknown;\n return (ev: Event, el: Element) => fn(ctx, ev, el);\n } catch (err) {\n if (import.meta.env?.DEV) {\n console.warn(`[bindEventHandlers] ❌ Failed to compile \"${expr}\"`, err);\n }\n // Return a noop runner\n return (_ev: Event, _el: Element) => undefined;\n }\n}\n\n/**\n * Traverse all elements under `root` (Element or DocumentFragment) using a TreeWalker.\n */\nfunction forEachElement(\n root: Element | DocumentFragment,\n cb: (el: Element) => void\n) {\n const walker = document.createTreeWalker(root, NodeFilter.SHOW_ELEMENT);\n let node: Node | null;\n while ((node = walker.nextNode())) {\n cb(node as Element);\n }\n}\n\n/**\n * Binds DOM event handlers within `root`.\n * - Uses nearest element context (e.g., loop item ctx) when present.\n * - Idempotent: won't re-bind the same element/event/expression+modifiers combo.\n * - Supports modifiers: .once .prevent .stop .self .capture .passive\n * - Injects `$event` and `$el` for expression handlers (e.g., @click=\"doThing($event)\")\n */\n/** @codexApi {\"parent\":\"pithy.runtime.events\",\"name\":\"bindEventHandlers\",\"stability\":\"stable\",\"signature\":\"(root: Element | DocumentFragment, rootCtx: Record<string, unknown>, disposers: (() => void)[]) => void\"} */\nexport function bindEventHandlers(\n root: Element | DocumentFragment,\n rootCtx: Record<string, unknown>,\n disposers: (() => void)[]\n): void {\n forEachElement(root, el => {\n // Iterate attributes once; bind any data-on-* handlers\n for (const attr of Array.from(el.attributes)) {\n if (!attr.name.startsWith('data-on-') || !isDeclaredDirective(attr))\n continue;\n\n const { type: eventName, mods } = parseEventAttr(attr.name);\n const handlerExpr = attr.value.trim();\n if (!handlerExpr) continue;\n\n // Idempotency key includes attr name (mods) + expression\n const boundSet = getBoundSet(el, eventName);\n const plainKey = `${attr.name}=${handlerExpr}`;\n const fwdCtx = nodeExpando(el).__pithyForwardCtx;\n const forwarded =\n !!fwdCtx && !!nodeExpando(el).__pithyForwardAttrs?.has(attr.name);\n const boundKey = forwarded ? forwardEventKey(el, plainKey) : plainKey;\n if (boundSet.has(boundKey)) continue;\n // An outer level's pass must not rebind this forwarded value as its own.\n const claimsPlain = forwarded && !boundSet.has(plainKey);\n\n const ctx = forwarded ? fwdCtx : nearestCtx(el, rootCtx);\n const isSimpleIdentifier = /^[a-zA-Z_][a-zA-Z0-9_]*$/.test(handlerExpr);\n\n // If the expression is a bare identifier and resolves to a function on ctx,\n // we'll call it directly (browser passes the event), preserving 'this' as ctx.\n const directFn =\n isSimpleIdentifier && typeof ctx[handlerExpr] === 'function'\n ? (ctx[handlerExpr] as EventListener)\n : null;\n\n // Otherwise, compile an event-aware evaluator that can see `$event` & `$el`.\n const runWithEvent = directFn ? null : compileWithEvent(handlerExpr, ctx);\n\n // Final listener with modifiers + $event/$el support + error boundary capture\n const listener: EventListener = (ev: Event) => {\n if (mods.self && ev.target !== el) return;\n if (mods.prevent) ev.preventDefault();\n if (mods.stop) ev.stopPropagation();\n\n try {\n if (directFn) {\n // Call the function from ctx with ctx as 'this'\n return directFn.call(ctx, ev);\n } else if (runWithEvent) {\n const out = runWithEvent(ev, el);\n // If expression returns a function, treat that as a handler and pass the event\n if (typeof out === 'function') {\n return (out as (e: Event) => unknown).call(ctx, ev);\n }\n return out;\n }\n } catch (error) {\n // Find the nearest error boundary and set its error signal with escalation\n const boundaryEl = el.closest('[data-error]') as Element | null;\n const boundary = boundaryForElement(boundaryEl);\n if (boundary) {\n const err =\n error instanceof Error ? error : new Error(String(error));\n setBoundaryError(boundary, err);\n } else {\n // No boundary found, re-throw to maintain original behavior\n throw error;\n }\n }\n };\n\n // Attach with appropriate options\n const options = {\n capture: !!mods.capture,\n passive: !!mods.passive,\n once: !!mods.once,\n } as AddEventListenerOptions;\n\n el.addEventListener(eventName, listener, options);\n\n boundSet.add(boundKey);\n if (claimsPlain) boundSet.add(plainKey);\n disposers.push(() => {\n // Note: removeEventListener only considers `capture`; `once`/`passive` are ignored here.\n el.removeEventListener(eventName, listener, {\n capture: !!mods.capture,\n });\n boundSet.delete(boundKey);\n if (claimsPlain) boundSet.delete(plainKey);\n });\n }\n });\n}\n"]}
|
|
@@ -17,8 +17,22 @@ export interface NodeExpando {
|
|
|
17
17
|
__pithyAotMount?: (disposers: (() => void)[]) => Node[];
|
|
18
18
|
__styleProps?: string[];
|
|
19
19
|
__styleOwners?: StyleOwners;
|
|
20
|
+
__selectValue?: {
|
|
21
|
+
text: string;
|
|
22
|
+
picks: Set<string> | null;
|
|
23
|
+
};
|
|
20
24
|
__classToggles?: string[];
|
|
21
25
|
__forwardedDirectives?: Map<string, string>;
|
|
26
|
+
/** A component root's forwarded bindings evaluate in the tag's template. */
|
|
27
|
+
__pithyForwardCtx?: Record<string, unknown>;
|
|
28
|
+
/** The attributes the tag that set `__pithyForwardCtx` forwarded. */
|
|
29
|
+
__pithyForwardAttrs?: Set<string>;
|
|
30
|
+
/** Identifies that forwarding, so two tags in one scope stay two bindings. */
|
|
31
|
+
__pithyForwardId?: number;
|
|
22
32
|
}
|
|
33
|
+
/** Records that `ctx`'s tag forwarded `names` onto `root`. */
|
|
34
|
+
export declare function markForwardTarget(root: Element, ctx: Record<string, unknown>, names: Set<string>): void;
|
|
35
|
+
/** Keys a forwarded event by the forwarding that put it on `el`. */
|
|
36
|
+
export declare function forwardEventKey(el: Element, key: string): string;
|
|
23
37
|
export declare function nodeExpando<T extends Node>(node: T): T & NodeExpando;
|
|
24
38
|
//# sourceMappingURL=nodeExpando.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nodeExpando.d.ts","sourceRoot":"","sources":["../../src/compile/nodeExpando.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAEnD,MAAM,WAAW,WAAW;IAC1B,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAC,CAAC;CACvD;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
|
2
|
+
/** Records that `ctx`'s tag forwarded `names` onto `root`. */
|
|
3
|
+
export function markForwardTarget(root, ctx, names) {
|
|
4
|
+
const x = nodeExpando(root);
|
|
5
|
+
x.__pithyForwardCtx = ctx;
|
|
6
|
+
x.__pithyForwardAttrs = names;
|
|
7
|
+
x.__pithyForwardId = ++nextForwardId;
|
|
8
|
+
}
|
|
9
|
+
/** Keys a forwarded event by the forwarding that put it on `el`. */
|
|
10
|
+
export function forwardEventKey(el, key) {
|
|
11
|
+
return `${nodeExpando(el).__pithyForwardId}|${key}`;
|
|
12
|
+
}
|
|
1
13
|
export function nodeExpando(node) {
|
|
2
14
|
return node;
|
|
3
15
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nodeExpando.js","sourceRoot":"","sources":["../../src/compile/nodeExpando.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"nodeExpando.js","sourceRoot":"","sources":["../../src/compile/nodeExpando.ts"],"names":[],"mappings":"AAgCA,IAAI,aAAa,GAAG,CAAC,CAAC;AAEtB,8DAA8D;AAC9D,MAAM,UAAU,iBAAiB,CAC/B,IAAa,EACb,GAA4B,EAC5B,KAAkB;IAElB,MAAM,CAAC,GAAG,WAAW,CAAC,IAAI,CAAC,CAAC;IAC5B,CAAC,CAAC,iBAAiB,GAAG,GAAG,CAAC;IAC1B,CAAC,CAAC,mBAAmB,GAAG,KAAK,CAAC;IAC9B,CAAC,CAAC,gBAAgB,GAAG,EAAE,aAAa,CAAC;AACvC,CAAC;AAED,oEAAoE;AACpE,MAAM,UAAU,eAAe,CAAC,EAAW,EAAE,GAAW;IACtD,OAAO,GAAG,WAAW,CAAC,EAAE,CAAC,CAAC,gBAAgB,IAAI,GAAG,EAAE,CAAC;AACtD,CAAC;AAED,MAAM,UAAU,WAAW,CAAiB,IAAO;IACjD,OAAO,IAAuB,CAAC;AACjC,CAAC","sourcesContent":["import type { PithyNode } from '@pithyjs/compiler';\n\nexport interface StyleOwners {\n strings: string[];\n props: Map<string, [value: string, priority: string]>;\n}\n\nexport interface NodeExpando {\n __pithyCtx?: Record<string, unknown>;\n __pithyNode?: PithyNode;\n __nodeId?: string;\n __slotName?: string;\n __fallbackFactory?: () => DocumentFragment;\n __nested?: boolean;\n __pithySkipText?: boolean;\n __pithyComponentDom?: boolean;\n /** A build's component placeholder: renders it through the AOT binder. */\n /** Renders a build's placeholder; returns the nodes that replaced it. */\n __pithyAotMount?: (disposers: (() => void)[]) => Node[];\n __styleProps?: string[];\n __styleOwners?: StyleOwners;\n __selectValue?: { text: string; picks: Set<string> | null };\n __classToggles?: string[];\n __forwardedDirectives?: Map<string, string>;\n /** A component root's forwarded bindings evaluate in the tag's template. */\n __pithyForwardCtx?: Record<string, unknown>;\n /** The attributes the tag that set `__pithyForwardCtx` forwarded. */\n __pithyForwardAttrs?: Set<string>;\n /** Identifies that forwarding, so two tags in one scope stay two bindings. */\n __pithyForwardId?: number;\n}\n\nlet nextForwardId = 0;\n\n/** Records that `ctx`'s tag forwarded `names` onto `root`. */\nexport function markForwardTarget(\n root: Element,\n ctx: Record<string, unknown>,\n names: Set<string>\n): void {\n const x = nodeExpando(root);\n x.__pithyForwardCtx = ctx;\n x.__pithyForwardAttrs = names;\n x.__pithyForwardId = ++nextForwardId;\n}\n\n/** Keys a forwarded event by the forwarding that put it on `el`. */\nexport function forwardEventKey(el: Element, key: string): string {\n return `${nodeExpando(el).__pithyForwardId}|${key}`;\n}\n\nexport function nodeExpando<T extends Node>(node: T): T & NodeExpando {\n return node as T & NodeExpando;\n}\n"]}
|
|
@@ -152,7 +152,8 @@ function preprocessSelfClosingComponents(html, importedIdentifiers) {
|
|
|
152
152
|
// Matches: <ComponentName /> or <ComponentName/>
|
|
153
153
|
// IMPORTANT: Use 'g' flag only (NOT 'gi') - case-sensitive matching is required
|
|
154
154
|
// to avoid converting native elements like <input /> to <Input></Input>
|
|
155
|
-
|
|
155
|
+
// Quoted values may hold `>` (an arrow-function prop), so skip them whole.
|
|
156
|
+
const selfClosingRegex = new RegExp(`<${componentName}(\\s(?:[^>"']|"[^"]*"|'[^']*')*?)?\\s*\\/\\s*>`, 'g');
|
|
156
157
|
// Replace with regular opening and closing tags
|
|
157
158
|
processedHtml = processedHtml.replace(selfClosingRegex, (match, attributes) => {
|
|
158
159
|
const attrs = attributes || '';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parseHtml.js","sourceRoot":"","sources":["../../src/compile/parseHtml.ts"],"names":[],"mappings":"AAAA;;;;;;EAME;AAEF,OAAO,EACL,iBAAiB,EACjB,mBAAmB,EACnB,uBAAuB,EACvB,6BAA6B,GAE9B,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAclD,IAAI,cAAc,GAA2B,IAAI,CAAC;AAClD,IAAI,YAAY,GAAyB,IAAI,CAAC;AAE9C;;;;;;;;GAQG;AACH,wIAAwI;AACxI,MAAM,UAAU,eAAe;IAC7B,IAAI,cAAc;QAAE,OAAO,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC,iBAAiB;IAC/D,IAAI,YAAY;QAAE,OAAO,YAAY,CAAC,CAAC,2CAA2C;IAElF,YAAY,GAAG,MAAM,CAAC,QAAQ,CAAC;SAC5B,IAAI,CAAC,GAAG,CAAC,EAAE;QACV,cAAc,GAAG,GAAG,CAAC,aAAa,CAAC;QACnC,YAAY,GAAG,IAAI,CAAC;IACtB,CAAC,CAAC;SACD,KAAK,CAAC,GAAG,CAAC,EAAE;QACX,oEAAoE;QACpE,YAAY,GAAG,IAAI,CAAC;QACpB,oEAAoE;QACpE,wEAAwE;QACxE,MAAM,OAAO,GAAG,IAAI,KAAK,CACvB,gHAAgH,CACjH,CAAC;QACD,OAAuC,CAAC,KAAK,GAAG,GAAG,CAAC;QACrD,MAAM,OAAO,CAAC;IAChB,CAAC,CAAC,CAAC;IAEL,OAAO,YAAY,CAAC;AACtB,CAAC;AAED;;;;GAIG;AACH,gIAAgI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J,CAAC;IAED,OAAO,aAAa,CAAC;AACvB,CAAC","sourcesContent":["/** @codex\n{\n \"id\": \"pithy.compiler.html-parser\",\n \"title\": \"HTML Template Parser\",\n \"category\": \"compiler\"\n}\n*/\n\nimport {\n parse5ToPithyTree,\n escapeComponentTags,\n extractOriginalTagNames,\n extractOriginalAttributeNames,\n type PithyNode,\n} from '@pithyjs/compiler';\nimport { pithyTreeToDom } from './pithyTreeToDom';\n\n// ─── Dynamic parse5 loading ──────────────────────────────────────────────────\n// parse5 is no longer statically imported. It is loaded on demand via\n// loadJITCompiler() and cached in this module-level variable.\n// This ensures parse5 (45.6 KB gzip) is tree-shaken from production bundles\n// when all templates are AOT-compiled.\n\n/** Structural type matching parse5's parseFragment — avoids leaking parse5 into .d.ts */\ntype ParseFragmentFn = (\n html: string,\n options?: { sourceCodeLocationInfo?: boolean }\n) => unknown;\n\nlet _parseFragment: ParseFragmentFn | null = null;\nlet _loadPromise: Promise<void> | null = null;\n\n/**\n * Dynamically import parse5 and cache the parseFragment function.\n * Must be called before using html() for runtime template compilation.\n *\n * If all templates are AOT-compiled, this function never needs to be called\n * and parse5 will be completely absent from the production bundle.\n *\n * @returns Promise that resolves when parse5 is ready\n */\n/** @codexApi {\"parent\":\"pithy.compiler.html-parser\",\"name\":\"loadJITCompiler\",\"stability\":\"stable\",\"signature\":\"() => Promise<void>\"} */\nexport function loadJITCompiler(): Promise<void> {\n if (_parseFragment) return Promise.resolve(); // Already loaded\n if (_loadPromise) return _loadPromise; // Loading in progress — reuse same promise\n\n _loadPromise = import('parse5')\n .then(mod => {\n _parseFragment = mod.parseFragment;\n _loadPromise = null;\n })\n .catch(err => {\n // Reset so a retry can be attempted (e.g., after installing parse5)\n _loadPromise = null;\n // Manual `.cause` assignment instead of `new Error(msg, { cause })`\n // because the project targets ES2020 which doesn't support Error cause.\n const loadErr = new Error(\n 'Failed to load parse5. Install it (`pnpm add parse5`) or enable AOT compilation to avoid the runtime compiler.'\n );\n (loadErr as Error & { cause?: unknown }).cause = err;\n throw loadErr;\n });\n\n return _loadPromise;\n}\n\n/**\n * Check if the JIT compiler (parse5) has been loaded.\n * Used internally by parseHtml to provide a clear error message.\n * @returns `true` if parse5 parseFragment is cached\n */\n/** @codexApi {\"parent\":\"pithy.compiler.html-parser\",\"name\":\"isJITLoaded\",\"stability\":\"internal\",\"signature\":\"() => boolean\"} */\nexport function isJITLoaded(): boolean {\n return _parseFragment !== null;\n}\n\n/**\n * Get the cached parseFragment function, throwing if not loaded.\n * @internal\n */\nfunction getParseFragment(): ParseFragmentFn {\n if (!_parseFragment) {\n throw new Error(\n 'Runtime template compiler not loaded. Enable AOT compilation (recommended) ' +\n 'or call loadJITCompiler() at startup.'\n );\n }\n return _parseFragment;\n}\n\n/**\n * Reset JIT compiler state. For testing only.\n * @internal\n */\n/** @codexApi {\"parent\":\"pithy.compiler.html-parser\",\"name\":\"resetJITState\",\"stability\":\"internal\",\"signature\":\"() => void\"} */\nexport function resetJITState(): void {\n _parseFragment = null;\n _loadPromise = null;\n}\n\n/**\n * Pre-load parse5 synchronously for environments where it's already available\n * (e.g., Node.js test environments, SSR). This is a convenience for the\n * transition period — production code should use loadJITCompiler().\n * @internal\n */\n/** @codexApi {\"parent\":\"pithy.compiler.html-parser\",\"name\":\"setParseFragment\",\"stability\":\"internal\",\"signature\":\"(fn: ParseFragmentFn) => void\"} */\nexport function setParseFragment(fn: ParseFragmentFn): void {\n _parseFragment = fn;\n}\n\n/**\n * Return the cached parseFragment function (or null if not loaded).\n * Used by parseIdentifiersFromTemplate to reuse the same parse5 instance\n * loaded via loadJITCompiler(), avoiding a separate dynamic import.\n * @internal\n */\n/** @codexApi {\"parent\":\"pithy.compiler.html-parser\",\"name\":\"getParseFragmentFn\",\"stability\":\"internal\",\"signature\":\"() => ParseFragmentFn | null\"} */\nexport function getParseFragmentFn(): ParseFragmentFn | null {\n return _parseFragment;\n}\n\n// ─── Main API ────────────────────────────────────────────────────────────────\n\n/**\n * Parse an HTML template string into a DOM fragment with PithyNode metadata.\n * Requires parse5 to be loaded first via `loadJITCompiler()` or `setParseFragment()`.\n * Throws if the runtime compiler has not been loaded.\n *\n * @param html - Raw HTML template string\n * @param scopeId - Unique scope identifier for style scoping\n * @param context - Reactive context for expression evaluation\n * @param importedIdentifiers - Set of imported component names for self-closing tag handling\n * @returns Object with `fragment` (live DOM) and `pithyNodes` (AST metadata)\n */\n/** @codexApi {\"parent\":\"pithy.compiler.html-parser\",\"name\":\"parseHtml\",\"stability\":\"stable\",\"signature\":\"(html: string, scopeId: string, context: Record<string, unknown>, importedIdentifiers?: Set<string>) => { fragment: DocumentFragment; pithyNodes: PithyNode[] }\"} */\nexport function parseHtml(\n html: string,\n scopeId: string,\n context: Record<string, unknown>,\n importedIdentifiers: Set<string> = new Set()\n): {\n fragment: DocumentFragment;\n pithyNodes: PithyNode[];\n} {\n const parseFragment = getParseFragment();\n\n // 1. Pre-process HTML to convert self-closing component tags to regular tags\n const processedHtml = preprocessSelfClosingComponents(\n html,\n importedIdentifiers\n );\n\n // 2. Escape PascalCase component tags so parse5 doesn't enter special\n // insertion modes (e.g., \"in select\", \"in table\") that corrupt the tree.\n const escapedHtml = escapeComponentTags(processedHtml);\n\n // 3. Parse HTML into parse5 tree\n const parsed = parseFragment(escapedHtml, {\n sourceCodeLocationInfo: true,\n }) as {\n childNodes: unknown[];\n };\n\n // 4. Restore casing and tag type via your parser\n // IMPORTANT: Use escapedHtml (not raw html) because parse5 reports\n // sourceCodeLocation offsets based on escapedHtml. If we used raw html,\n // self-closing tag expansion (e.g. <Foo/> → <Foo></Foo>) and escape\n // prefixing would shift all subsequent offsets, causing casing map\n // lookups to miss for components that appear after other components.\n const tagNameCasingMap = extractOriginalTagNames(escapedHtml);\n const attributeNameCasingMap = extractOriginalAttributeNames(escapedHtml);\n\n const pithyNodes = parsed.childNodes\n .map((n: unknown) =>\n parse5ToPithyTree(\n n as Parameters<typeof parse5ToPithyTree>[0],\n importedIdentifiers,\n tagNameCasingMap,\n undefined,\n attributeNameCasingMap,\n undefined,\n escapedHtml\n )\n )\n .filter((n): n is PithyNode => n != null);\n\n // 3. Compile DOM tree from PithyNodes\n const fragment = pithyTreeToDom(pithyNodes, context);\n\n // 4. Add data-scope attribute to all elements\n fragment.querySelectorAll?.('*').forEach(el => {\n el.setAttribute(`data-scope-${scopeId}`, '');\n });\n\n return {\n fragment,\n pithyNodes,\n };\n}\n\n/**\n * Pre-processes HTML to convert self-closing component tags to regular tags.\n * This works around parse5's limitation with self-closing custom elements.\n *\n * @param html - The HTML template string\n * @param importedIdentifiers - Set of imported component names\n * @returns Processed HTML with self-closing components converted to regular tags\n */\n/** @codexApi {\"parent\":\"pithy.compiler.html-parser\",\"name\":\"preprocessSelfClosingComponents\",\"stability\":\"stable\",\"signature\":\"(html: string, importedIdentifiers: Set<string>) => string\"} */\nfunction preprocessSelfClosingComponents(\n html: string,\n importedIdentifiers: Set<string>\n): string {\n let processedHtml = html;\n\n // Convert each imported component from self-closing to regular tag\n for (const componentName of importedIdentifiers) {\n // Create regex to match self-closing component tags\n // Matches: <ComponentName /> or <ComponentName/>\n // IMPORTANT: Use 'g' flag only (NOT 'gi') - case-sensitive matching is required\n // to avoid converting native elements like <input /> to <Input></Input>\n const selfClosingRegex = new RegExp(\n `<${componentName}(\\\\s[^>]*)?\\\\s*\\\\/\\\\s*>`,\n 'g'\n );\n\n // Replace with regular opening and closing tags\n processedHtml = processedHtml.replace(\n selfClosingRegex,\n (match, attributes) => {\n const attrs = attributes || '';\n return `<${componentName}${attrs}></${componentName}>`;\n }\n );\n }\n\n return processedHtml;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"parseHtml.js","sourceRoot":"","sources":["../../src/compile/parseHtml.ts"],"names":[],"mappings":"AAAA;;;;;;EAME;AAEF,OAAO,EACL,iBAAiB,EACjB,mBAAmB,EACnB,uBAAuB,EACvB,6BAA6B,GAE9B,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB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,CAAC,OAAO,CAAC,EAAE,CAAC,EAAE;QAC5C,EAAE,CAAC,YAAY,CAAC,cAAc,OAAO,EAAE,EAAE,EAAE,CAAC,CAAC;IAC/C,CAAC,CAAC,CAAC;IAEH,OAAO;QACL,QAAQ;QACR,UAAU;KACX,CAAC;AACJ,CAAC;AAED;;;;;;;GAOG;AACH,+LAA+L;AAC/L,SAAS,+BAA+B,CACtC,IAAY,EACZ,mBAAgC;IAEhC,IAAI,aAAa,GAAG,IAAI,CAAC;IAEzB,mEAAmE;IACnE,KAAK,MAAM,aAAa,IAAI,mBAAmB,EAAE,CAAC;QAChD,oDAAoD;QACpD,iDAAiD;QACjD,gFAAgF;QAChF,wEAAwE;QACxE,2EAA2E;QAC3E,MAAM,gBAAgB,GAAG,IAAI,MAAM,CACjC,IAAI,aAAa,gDAAgD,EACjE,GAAG,CACJ,CAAC;QAEF,gDAAgD;QAChD,aAAa,GAAG,aAAa,CAAC,OAAO,CACnC,gBAAgB,EAChB,CAAC,KAAK,EAAE,UAAU,EAAE,EAAE;YACpB,MAAM,KAAK,GAAG,UAAU,IAAI,EAAE,CAAC;YAC/B,OAAO,IAAI,aAAa,GAAG,KAAK,MAAM,aAAa,GAAG,CAAC;QACzD,CAAC,CACF,CAAC;IACJ,CAAC;IAED,OAAO,aAAa,CAAC;AACvB,CAAC","sourcesContent":["/** @codex\n{\n \"id\": \"pithy.compiler.html-parser\",\n \"title\": \"HTML Template Parser\",\n \"category\": \"compiler\"\n}\n*/\n\nimport {\n parse5ToPithyTree,\n escapeComponentTags,\n extractOriginalTagNames,\n extractOriginalAttributeNames,\n type PithyNode,\n} from '@pithyjs/compiler';\nimport { pithyTreeToDom } from './pithyTreeToDom';\n\n// ─── Dynamic parse5 loading ──────────────────────────────────────────────────\n// parse5 is no longer statically imported. It is loaded on demand via\n// loadJITCompiler() and cached in this module-level variable.\n// This ensures parse5 (45.6 KB gzip) is tree-shaken from production bundles\n// when all templates are AOT-compiled.\n\n/** Structural type matching parse5's parseFragment — avoids leaking parse5 into .d.ts */\ntype ParseFragmentFn = (\n html: string,\n options?: { sourceCodeLocationInfo?: boolean }\n) => unknown;\n\nlet _parseFragment: ParseFragmentFn | null = null;\nlet _loadPromise: Promise<void> | null = null;\n\n/**\n * Dynamically import parse5 and cache the parseFragment function.\n * Must be called before using html() for runtime template compilation.\n *\n * If all templates are AOT-compiled, this function never needs to be called\n * and parse5 will be completely absent from the production bundle.\n *\n * @returns Promise that resolves when parse5 is ready\n */\n/** @codexApi {\"parent\":\"pithy.compiler.html-parser\",\"name\":\"loadJITCompiler\",\"stability\":\"stable\",\"signature\":\"() => Promise<void>\"} */\nexport function loadJITCompiler(): Promise<void> {\n if (_parseFragment) return Promise.resolve(); // Already loaded\n if (_loadPromise) return _loadPromise; // Loading in progress — reuse same promise\n\n _loadPromise = import('parse5')\n .then(mod => {\n _parseFragment = mod.parseFragment;\n _loadPromise = null;\n })\n .catch(err => {\n // Reset so a retry can be attempted (e.g., after installing parse5)\n _loadPromise = null;\n // Manual `.cause` assignment instead of `new Error(msg, { cause })`\n // because the project targets ES2020 which doesn't support Error cause.\n const loadErr = new Error(\n 'Failed to load parse5. Install it (`pnpm add parse5`) or enable AOT compilation to avoid the runtime compiler.'\n );\n (loadErr as Error & { cause?: unknown }).cause = err;\n throw loadErr;\n });\n\n return _loadPromise;\n}\n\n/**\n * Check if the JIT compiler (parse5) has been loaded.\n * Used internally by parseHtml to provide a clear error message.\n * @returns `true` if parse5 parseFragment is cached\n */\n/** @codexApi {\"parent\":\"pithy.compiler.html-parser\",\"name\":\"isJITLoaded\",\"stability\":\"internal\",\"signature\":\"() => boolean\"} */\nexport function isJITLoaded(): boolean {\n return _parseFragment !== null;\n}\n\n/**\n * Get the cached parseFragment function, throwing if not loaded.\n * @internal\n */\nfunction getParseFragment(): ParseFragmentFn {\n if (!_parseFragment) {\n throw new Error(\n 'Runtime template compiler not loaded. Enable AOT compilation (recommended) ' +\n 'or call loadJITCompiler() at startup.'\n );\n }\n return _parseFragment;\n}\n\n/**\n * Reset JIT compiler state. For testing only.\n * @internal\n */\n/** @codexApi {\"parent\":\"pithy.compiler.html-parser\",\"name\":\"resetJITState\",\"stability\":\"internal\",\"signature\":\"() => void\"} */\nexport function resetJITState(): void {\n _parseFragment = null;\n _loadPromise = null;\n}\n\n/**\n * Pre-load parse5 synchronously for environments where it's already available\n * (e.g., Node.js test environments, SSR). This is a convenience for the\n * transition period — production code should use loadJITCompiler().\n * @internal\n */\n/** @codexApi {\"parent\":\"pithy.compiler.html-parser\",\"name\":\"setParseFragment\",\"stability\":\"internal\",\"signature\":\"(fn: ParseFragmentFn) => void\"} */\nexport function setParseFragment(fn: ParseFragmentFn): void {\n _parseFragment = fn;\n}\n\n/**\n * Return the cached parseFragment function (or null if not loaded).\n * Used by parseIdentifiersFromTemplate to reuse the same parse5 instance\n * loaded via loadJITCompiler(), avoiding a separate dynamic import.\n * @internal\n */\n/** @codexApi {\"parent\":\"pithy.compiler.html-parser\",\"name\":\"getParseFragmentFn\",\"stability\":\"internal\",\"signature\":\"() => ParseFragmentFn | null\"} */\nexport function getParseFragmentFn(): ParseFragmentFn | null {\n return _parseFragment;\n}\n\n// ─── Main API ────────────────────────────────────────────────────────────────\n\n/**\n * Parse an HTML template string into a DOM fragment with PithyNode metadata.\n * Requires parse5 to be loaded first via `loadJITCompiler()` or `setParseFragment()`.\n * Throws if the runtime compiler has not been loaded.\n *\n * @param html - Raw HTML template string\n * @param scopeId - Unique scope identifier for style scoping\n * @param context - Reactive context for expression evaluation\n * @param importedIdentifiers - Set of imported component names for self-closing tag handling\n * @returns Object with `fragment` (live DOM) and `pithyNodes` (AST metadata)\n */\n/** @codexApi {\"parent\":\"pithy.compiler.html-parser\",\"name\":\"parseHtml\",\"stability\":\"stable\",\"signature\":\"(html: string, scopeId: string, context: Record<string, unknown>, importedIdentifiers?: Set<string>) => { fragment: DocumentFragment; pithyNodes: PithyNode[] }\"} */\nexport function parseHtml(\n html: string,\n scopeId: string,\n context: Record<string, unknown>,\n importedIdentifiers: Set<string> = new Set()\n): {\n fragment: DocumentFragment;\n pithyNodes: PithyNode[];\n} {\n const parseFragment = getParseFragment();\n\n // 1. Pre-process HTML to convert self-closing component tags to regular tags\n const processedHtml = preprocessSelfClosingComponents(\n html,\n importedIdentifiers\n );\n\n // 2. Escape PascalCase component tags so parse5 doesn't enter special\n // insertion modes (e.g., \"in select\", \"in table\") that corrupt the tree.\n const escapedHtml = escapeComponentTags(processedHtml);\n\n // 3. Parse HTML into parse5 tree\n const parsed = parseFragment(escapedHtml, {\n sourceCodeLocationInfo: true,\n }) as {\n childNodes: unknown[];\n };\n\n // 4. Restore casing and tag type via your parser\n // IMPORTANT: Use escapedHtml (not raw html) because parse5 reports\n // sourceCodeLocation offsets based on escapedHtml. If we used raw html,\n // self-closing tag expansion (e.g. <Foo/> → <Foo></Foo>) and escape\n // prefixing would shift all subsequent offsets, causing casing map\n // lookups to miss for components that appear after other components.\n const tagNameCasingMap = extractOriginalTagNames(escapedHtml);\n const attributeNameCasingMap = extractOriginalAttributeNames(escapedHtml);\n\n const pithyNodes = parsed.childNodes\n .map((n: unknown) =>\n parse5ToPithyTree(\n n as Parameters<typeof parse5ToPithyTree>[0],\n importedIdentifiers,\n tagNameCasingMap,\n undefined,\n attributeNameCasingMap,\n undefined,\n escapedHtml\n )\n )\n .filter((n): n is PithyNode => n != null);\n\n // 3. Compile DOM tree from PithyNodes\n const fragment = pithyTreeToDom(pithyNodes, context);\n\n // 4. Add data-scope attribute to all elements\n fragment.querySelectorAll?.('*').forEach(el => {\n el.setAttribute(`data-scope-${scopeId}`, '');\n });\n\n return {\n fragment,\n pithyNodes,\n };\n}\n\n/**\n * Pre-processes HTML to convert self-closing component tags to regular tags.\n * This works around parse5's limitation with self-closing custom elements.\n *\n * @param html - The HTML template string\n * @param importedIdentifiers - Set of imported component names\n * @returns Processed HTML with self-closing components converted to regular tags\n */\n/** @codexApi {\"parent\":\"pithy.compiler.html-parser\",\"name\":\"preprocessSelfClosingComponents\",\"stability\":\"stable\",\"signature\":\"(html: string, importedIdentifiers: Set<string>) => string\"} */\nfunction preprocessSelfClosingComponents(\n html: string,\n importedIdentifiers: Set<string>\n): string {\n let processedHtml = html;\n\n // Convert each imported component from self-closing to regular tag\n for (const componentName of importedIdentifiers) {\n // Create regex to match self-closing component tags\n // Matches: <ComponentName /> or <ComponentName/>\n // IMPORTANT: Use 'g' flag only (NOT 'gi') - case-sensitive matching is required\n // to avoid converting native elements like <input /> to <Input></Input>\n // Quoted values may hold `>` (an arrow-function prop), so skip them whole.\n const selfClosingRegex = new RegExp(\n `<${componentName}(\\\\s(?:[^>\"']|\"[^\"]*\"|'[^']*')*?)?\\\\s*\\\\/\\\\s*>`,\n 'g'\n );\n\n // Replace with regular opening and closing tags\n processedHtml = processedHtml.replace(\n selfClosingRegex,\n (match, attributes) => {\n const attrs = attributes || '';\n return `<${componentName}${attrs}></${componentName}>`;\n }\n );\n }\n\n return processedHtml;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"applyComponent.d.ts","sourceRoot":"","sources":["../../../src/runtime/bindings/applyComponent.ts"],"names":[],"mappings":"AAkBA,OAAO,KAAK,EAAE,QAAQ,EAAE,cAAc,EAAgB,MAAM,SAAS,CAAC;AAyItE,wBAAgB,cAAc,CAC5B,CAAC,EAAE,QAAQ,EACX,EAAE,EAAE,OAAO,EACX,GAAG,EAAE,cAAc,EACnB,SAAS,EAAE,CAAC,MAAM,IAAI,CAAC,EAAE,EACzB,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,EAC5B,KAAK,CAAC,EAAE,cAAc,GACrB,IAAI,EAAE,GAAG,SAAS,
|
|
1
|
+
{"version":3,"file":"applyComponent.d.ts","sourceRoot":"","sources":["../../../src/runtime/bindings/applyComponent.ts"],"names":[],"mappings":"AAkBA,OAAO,KAAK,EAAE,QAAQ,EAAE,cAAc,EAAgB,MAAM,SAAS,CAAC;AAyItE,wBAAgB,cAAc,CAC5B,CAAC,EAAE,QAAQ,EACX,EAAE,EAAE,OAAO,EACX,GAAG,EAAE,cAAc,EACnB,SAAS,EAAE,CAAC,MAAM,IAAI,CAAC,EAAE,EACzB,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,EAC5B,KAAK,CAAC,EAAE,cAAc,GACrB,IAAI,EAAE,GAAG,SAAS,CA6QpB"}
|
|
@@ -13,7 +13,7 @@ import { clearSSRRenderCrash, reportComponentFailure, } from '../../compile/ssrC
|
|
|
13
13
|
import { isolateDestroyCallbacks } from '../onDestroy.js';
|
|
14
14
|
import { parsePropNames } from '../../compile/binds/propNames.js';
|
|
15
15
|
import { watchStaleRowProp } from '../../compile/binds/staleRowProps.js';
|
|
16
|
-
import { nodeExpando } from '../../compile/nodeExpando.js';
|
|
16
|
+
import { markForwardTarget, nodeExpando } from '../../compile/nodeExpando.js';
|
|
17
17
|
import { anchorDisposer, componentDisposer } from '../../compile/disposeOrder.js';
|
|
18
18
|
/** Map kebab-case or lowered DOM attr name to expected camelCase prop name. */
|
|
19
19
|
function normalizePropName(authored, expectedProps) {
|
|
@@ -272,7 +272,7 @@ export function applyComponent(d, el, ctx, disposers, pidMap, scope) {
|
|
|
272
272
|
const forwardedAttrs = collectForwardedAttrs(el);
|
|
273
273
|
const renderedRoot = renderedEl instanceof DocumentFragment
|
|
274
274
|
? renderedEl.firstElementChild
|
|
275
|
-
: renderedEl instanceof
|
|
275
|
+
: renderedEl instanceof Element
|
|
276
276
|
? renderedEl
|
|
277
277
|
: null;
|
|
278
278
|
const nodes = renderedEl instanceof DocumentFragment
|
|
@@ -311,6 +311,7 @@ export function applyComponent(d, el, ctx, disposers, pidMap, scope) {
|
|
|
311
311
|
// forwarded from the placeholder to the rendered root.
|
|
312
312
|
if (renderedRoot) {
|
|
313
313
|
pidMap.set(d.pid, renderedRoot);
|
|
314
|
+
markForwardTarget(renderedRoot, localCtx, new Set(forwardedAttrs.map(([name]) => name)));
|
|
314
315
|
}
|
|
315
316
|
else {
|
|
316
317
|
if (import.meta.env?.DEV &&
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"applyComponent.js","sourceRoot":"","sources":["../../../src/runtime/bindings/applyComponent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAC;AACpE,OAAO,EACL,kBAAkB,EAClB,aAAa,EACb,eAAe,EACf,gBAAgB,EAChB,iBAAiB,GAClB,MAAM,uCAAuC,CAAC;AAC/C,OAAO,EACL,gBAAgB,GAEjB,MAAM,iCAAiC,CAAC;AACzC,OAAO,EACL,qBAAqB,EACrB,mBAAmB,GACpB,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAEvD,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AACvC,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAC9D,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAClD,OAAO,EAAE,uBAAuB,EAAE,MAAM,+BAA+B,CAAC;AACxE,OAAO,EACL,mBAAmB,EACnB,sBAAsB,GACvB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,uBAAuB,EAAE,MAAM,cAAc,CAAC;AACvD,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAC/D,OAAO,EAAE,iBAAiB,EAAE,MAAM,mCAAmC,CAAC;AACtE,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AACxD,OAAO,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAS/E,+EAA+E;AAC/E,SAAS,iBAAiB,CAAC,QAAgB,EAAE,aAAuB;IAClE,IAAI,aAAa,CAAC,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,CAAC;QACjB,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,YAAY,CAAC,CAAC;IAClC,CAAC;SAAM,CAAC;QACN,IACE,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG;YACpB,CAAC,cAAc;gBACb,cAAc,CAAC,MAAM,GAAG,CAAC;gBACzB,CAAC,CAAC,CAAC,KAAK,IAAI,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,EAC/C,CAAC;YACD,OAAO,CAAC,IAAI,CACV,UAAU,CAAC,CAAC,GAAG,qGAAqG,CACrH,CAAC;QACJ,CAAC;QACD,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;IACvB,CAAC;IAED,IAAI,QAAQ;QAAE,KAAK,MAAM,KAAK,IAAI,aAAa;YAAE,KAAK,EAAE,CAAC;IAEzD,MAAM,QAAQ,GAAG,iBAAiB,CAChC,OAAO,EACP,YAAY,EACZ,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CACnC,CAAC;IACF,IAAI,QAAQ;QAAE,SAAS,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IACvC,OAAO,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC;AACtC,CAAC","sourcesContent":["import { compileExpression } from '../../compile/compileExpression';\nimport {\n boundaryForElement,\n replaceHidden,\n runWithBoundary,\n withSlotBoundary,\n slotContentHidden,\n} from '../../compile/binds/bindErrorBoundary';\nimport {\n linkOuterSlotMap,\n type SlotMap,\n} from '../../compile/contentProjection';\nimport {\n collectForwardedAttrs,\n applyForwardedAttrs,\n} from '../../compile/binds/forwardedAttrs';\nimport { nativeTags } from '@pithyjs/compiler';\nimport { createRoot, untrack } from '@pithyjs/signals';\nimport type { CompDesc, BindingContext, ChildFactory } from './types';\nimport { nearestCtx } from './helpers';\nimport { trimBlankEdges } from '../../compile/trimBlankEdges';\nimport { pithyGlobals } from '../../types/globals';\nimport { isSSRMode } from '../../compile/ssrMode';\nimport { isRenderableComponentEl } from '../../compile/componentResult';\nimport {\n clearSSRRenderCrash,\n reportComponentFailure,\n} from '../../compile/ssrCrashes';\nimport { isolateDestroyCallbacks } from '../onDestroy';\nimport { parsePropNames } from '../../compile/binds/propNames';\nimport { watchStaleRowProp } from '../../compile/binds/staleRowProps';\nimport { nodeExpando } from '../../compile/nodeExpando';\nimport { anchorDisposer, componentDisposer } from '../../compile/disposeOrder';\n\ninterface ComponentResult {\n /** Any DOM node — see the `Component` type for why this is not narrower. */\n el: Node;\n destroy?: () => void;\n}\ntype ComponentFn = (props: Record<string, unknown>) => ComponentResult;\n\n/** Map kebab-case or lowered DOM attr name to expected camelCase prop name. */\nfunction normalizePropName(authored: string, expectedProps: string[]): string {\n if (expectedProps.includes(authored)) return authored;\n const lower = authored.toLowerCase();\n const matches = expectedProps.filter(p => p.toLowerCase() === lower);\n return matches.length === 1 ? matches[0] : authored;\n}\n\n/** Cache for extractExpectedPropNames to avoid re-parsing the same function. */\nconst propNamesCache = new WeakMap<ComponentFn, string[]>();\n\n/**\n * Extract destructured prop names from component function signature.\n * NOTE: Uses fn.toString() which may return mangled names under aggressive\n * minification (Terser). In that case, prop name normalization becomes a\n * no-op and props are passed as-is (kebab/lowered). This is acceptable\n * because Vite's default esbuild minifier preserves parameter names.\n */\nfunction extractExpectedPropNames(fn: ComponentFn): string[] {\n const cached = propNamesCache.get(fn);\n if (cached) return cached;\n try {\n const parsed = parsePropNames(fn.toString());\n const names = parsed.fromParam ? parsed.names : [];\n // Detect likely minification: single-char names suggest mangled output\n if (\n import.meta.env?.DEV &&\n names.length > 0 &&\n names.every(n => n.length === 1)\n ) {\n console.warn(\n `[AOT] extractExpectedPropNames: detected single-char names (${names.join(',')}) — prop normalization may not work under minification`\n );\n }\n propNamesCache.set(fn, names);\n return names;\n } catch {\n return [];\n }\n}\n\n/** Runs a slot factory against the parent's context, owned by the mount's disposers. */\nfunction renderSlot(\n factory: ChildFactory,\n ctx: BindingContext,\n disposers: (() => void)[],\n anchor?: Node,\n host?: Element\n): DocumentFragment {\n const g = pithyGlobals();\n const rendering = g.__pithyComponentContext;\n // Otherwise mergeContexts would read the child's names into the slot's context.\n g.__pithyComponentContext = undefined;\n try {\n const { el, destroy } = withSlotBoundary(anchor, host, () =>\n isolateDestroyCallbacks(() => factory(ctx))\n );\n disposers.push(anchorDisposer(destroy, anchor ?? el.firstChild));\n // Bound already: a runtime-compiled child's binders must not bind it again.\n el.childNodes.forEach(\n node => (nodeExpando(node).__pithyComponentDom = true)\n );\n return el;\n } finally {\n g.__pithyComponentContext = rendering;\n }\n}\n\n/**\n * Slot content serialized into the placeholder, from a descriptor without\n * `slots`. The nodes are moved, so each slot can be mounted only once.\n */\nfunction slotsFromChildren(\n el: Element,\n slotMap: SlotMap\n): DocumentFragment | undefined {\n const slotGroups = new Map<string, Node[]>();\n for (const child of Array.from(el.childNodes)) {\n const slotName =\n child.nodeType === Node.ELEMENT_NODE\n ? (child as Element).getAttribute('slot') || ''\n : '';\n const group = slotGroups.get(slotName);\n if (group) group.push(child);\n else slotGroups.set(slotName, [child]);\n }\n const defaultSlot = slotGroups.get('');\n if (defaultSlot) {\n const content = trimBlankEdges(defaultSlot, node =>\n node.nodeType === Node.TEXT_NODE ? node.textContent : null\n );\n if (content.length) slotGroups.set('', content);\n else slotGroups.delete('');\n }\n // `renderChildren()` and `<slot>` must share one fragment, or the later\n // consumer steals the nodes out of the first.\n let injection: DocumentFragment | undefined;\n for (const [slotName, nodes] of slotGroups) {\n if (slotName === '') {\n injection = document.createDocumentFragment();\n for (const node of nodes) injection.appendChild(node);\n const shared = injection;\n slotMap.set('', () => shared);\n continue;\n }\n slotMap.set(slotName, () => {\n const frag = document.createDocumentFragment();\n for (const node of nodes) frag.appendChild(node);\n return frag;\n });\n }\n return injection;\n}\n\nexport function applyComponent(\n d: CompDesc,\n el: Element,\n ctx: BindingContext,\n disposers: (() => void)[],\n pidMap: Map<string, Element>,\n scope?: BindingContext\n): Node[] | undefined {\n // Skip native HTML elements — prevents <div> matching a `div` in context.\n // Only apply when the authored tag is already lowercase; PascalCase tags like\n // <Button> are valid components even though \"button\" is a native tag.\n const tagLower = d.tag.toLowerCase();\n if (d.tag === tagLower && nativeTags.has(tagLower)) return;\n\n // Exact case first: the context holds the template's own locals alongside its\n // components, so a prop named `icon` sits next to the `Icon` component and\n // collides case-insensitively. The JIT path lowercases into a Map, where the\n // components — appended last — overwrite the locals; matching that ordering is\n // why `<Icon>` resolves in dev, and breaking on the first match is why it did\n // not in a build. Falling back last-wins keeps the two paths agreeing.\n let candidate: unknown = Object.prototype.hasOwnProperty.call(ctx, d.tag)\n ? ctx[d.tag]\n : undefined;\n if (candidate === undefined) {\n for (const key of Object.keys(ctx)) {\n if (key.toLowerCase() === tagLower) candidate = ctx[key];\n }\n }\n if (!candidate) return;\n\n // Support default exports\n if (\n candidate &&\n typeof candidate === 'object' &&\n 'default' in candidate &&\n typeof candidate.default === 'function'\n ) {\n candidate = candidate.default;\n }\n if (typeof candidate !== 'function') return;\n // Hidden like a sibling an activated boundary detached: never rendered.\n if (slotContentHidden(el)) return;\n\n const componentFn = candidate as ComponentFn;\n const localCtx = scope ?? nearestCtx(el, ctx);\n\n // Extract expected props for case-insensitive normalization\n const expectedProps = extractExpectedPropNames(componentFn);\n\n // Evaluate prop expressions with prop name normalization\n const props: Record<string, unknown> = {};\n const staleWatchers: (() => void)[] = [];\n for (const [rawName, expr] of Object.entries(d.props)) {\n const propName = normalizePropName(rawName, expectedProps);\n try {\n const fn = compileExpression(expr, localCtx);\n props[propName] = untrack(fn);\n if (import.meta.env?.DEV) {\n const value = props[propName];\n staleWatchers.push(() =>\n watchStaleRowProp(\n localCtx,\n d,\n d.tag,\n propName,\n expr,\n value,\n fn,\n disposers\n )\n );\n }\n } catch {\n // Leave undefined — child uses defaults\n }\n }\n\n const slotMap: SlotMap = new Map();\n linkOuterSlotMap(slotMap, localCtx);\n let injection: DocumentFragment | undefined;\n if (d.slots) {\n for (const [name, factory] of Object.entries(d.slots))\n slotMap.set(name, (ds = disposers, at) =>\n renderSlot(factory, localCtx, ds, at, el)\n );\n } else {\n injection = slotsFromChildren(el, slotMap);\n }\n\n let invoking = true;\n const childrenFactory = d.children;\n const childFactory: ChildFactory | undefined = childrenFactory\n ? (ctx, wrap) =>\n invoking\n ? childrenFactory(ctx, wrap)\n : isolateDestroyCallbacks(() => childrenFactory(ctx, wrap))\n : undefined;\n\n const componentContext = {\n ...localCtx,\n __slotMap: slotMap,\n __childAstNodes: undefined,\n __childFactory: childFactory,\n __slotHost: el,\n };\n\n // Find nearest error boundary\n const boundaryEl = el.closest('[data-error]') as Element | null;\n const boundary = boundaryForElement(boundaryEl);\n\n let out: ComponentResult | undefined;\n let disposeSetup: (() => void) | undefined;\n try {\n out = runWithBoundary(boundary, () => {\n const g = pithyGlobals();\n const originalContext = g.__pithyComponentContext;\n const wasRendering = g.__pithyRenderingComponent;\n const prevInjection = g.__pithyProjectedChildren;\n g.__pithyComponentContext = componentContext;\n g.__pithyRenderingComponent = true;\n g.__pithyProjectedChildren = injection;\n try {\n return createRoot(disposeRoot => {\n disposeSetup = disposeRoot;\n return componentFn(props);\n });\n } finally {\n g.__pithyComponentContext = originalContext;\n g.__pithyRenderingComponent = wasRendering;\n g.__pithyProjectedChildren = prevInjection;\n invoking = false;\n }\n });\n } catch (err) {\n if (boundary) {\n const error = err instanceof Error ? err : new Error(String(err));\n // See `setBoundaryError`: an already-active boundary with no free ancestor\n // drops the error rather than taking it, which is the normal case for a\n // component rendering inside that boundary's `@fallback`.\n reportComponentFailure(el, d.tag, error, boundary);\n return;\n }\n\n // No boundary in scope *yet*. Degrade in both modes — an AOT branch\n // factory renders detached, so `closest()` here cannot see a boundary the\n // element will sit under once the branch is inserted, and throwing would\n // only be swallowed by the structural handler's own catch\n // (`applyStructural.ts`) anyway.\n //\n // A static/server render records the crash instead: dropping the component\n // silently shipped HTML with <${d.tag}> left raw while `pithy-ssg` counted\n // the route as rendered and exited 0 (BUG-018). Anything still recorded\n // when the render finishes fails the route.\n //\n // Note this path cannot reach a boundary at all when the element is inside\n // a detached structural branch: `el.closest('[data-error]')` above found\n // nothing, and no later pass re-binds it, so the boundary never receives\n // the error even though the nodes are inserted underneath it. That is\n // BUG-023; recording is what stops it from shipping silently.\n reportComponentFailure(\n el,\n d.tag,\n err instanceof Error ? err : new Error(String(err)),\n null\n );\n\n console.error(`[AOT] Component <${d.tag}> crashed:`, err);\n return;\n }\n\n if (\n !out ||\n typeof out !== 'object' ||\n !('el' in out) ||\n !isRenderableComponentEl(out.el, el)\n ) {\n // Not a throw, but the same outcome: the raw <${d.tag}> is left in place\n // and the subtree never renders, which under SSR is content silently\n // missing from the emitted HTML. Recorded exactly like a crash (BUG-018).\n // Same funnel as a throw — see `bindComponentTags`. Recording without\n // offering it to the boundary left an AOT component under `@error-boundary`\n // failing its route with the boundary signal unset.\n reportComponentFailure(\n el,\n d.tag,\n new Error(\n `Invalid render result from <${d.tag}>; expected { el, destroy }`\n ),\n boundary\n );\n disposeSetup?.();\n return;\n }\n\n const { el: renderedEl, destroy } = out;\n\n // Capture rendered root element before fragment is consumed by replaceWith\n const forwardedClass = el.getAttribute('class');\n const forwardedAttrs = collectForwardedAttrs(el);\n const renderedRoot: HTMLElement | null =\n renderedEl instanceof DocumentFragment\n ? (renderedEl.firstElementChild as HTMLElement | null)\n : renderedEl instanceof HTMLElement\n ? renderedEl\n : null;\n\n const nodes =\n renderedEl instanceof DocumentFragment\n ? Array.from(renderedEl.childNodes)\n : [renderedEl];\n let replaced = true;\n try {\n // A boundary that caught a crash in this render may have hidden `el`.\n if (!replaceHidden(el, nodes)) el.replaceWith(...nodes);\n } catch (err) {\n // The raw <${d.tag}> is left exactly where a crash would have left it, so\n // this is the same content loss and is recorded the same way.\n replaced = false;\n reportComponentFailure(\n el,\n d.tag,\n err instanceof Error ? err : new Error(String(err)),\n boundary\n );\n console.error(`[AOT] Failed to replace <${d.tag}>:`, err);\n }\n\n // Retracted only here, and in the boundary catch above. This is the point at\n // which the component is known to have produced a usable node AND to have\n // reached the document.\n if (isSSRMode() && replaced) clearSSRRenderCrash(el);\n\n if (forwardedClass && renderedRoot) {\n for (const cls of forwardedClass.split(/\\s+/)) {\n if (cls) renderedRoot.classList.add(cls);\n }\n }\n\n if (forwardedAttrs.length > 0 && renderedRoot) {\n applyForwardedAttrs(renderedRoot, forwardedAttrs, d.tag);\n }\n\n // Re-target the component pid to the rendered root so subsequent binding\n // passes (event, bound, class, style) apply to the component's actual DOM\n // element. This matches the JIT path where data-on-* attributes are\n // forwarded from the placeholder to the rendered root.\n if (renderedRoot) {\n pidMap.set(d.pid, renderedRoot);\n } else {\n if (\n import.meta.env?.DEV &&\n (forwardedClass ||\n forwardedAttrs.length > 0 ||\n (d.props && Object.keys(d.props).length > 0))\n ) {\n console.warn(\n `[AOT] <${d.tag}> has forwarded attributes but returns a fragment with no single root element — forwarding skipped.`\n );\n }\n pidMap.delete(d.pid);\n }\n\n if (replaced) for (const watch of staleWatchers) watch();\n\n const teardown = componentDisposer(\n destroy,\n disposeSetup,\n nodes[0] ?? (replaced ? null : el)\n );\n if (teardown) disposers.push(teardown);\n return replaced ? nodes : undefined;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"applyComponent.js","sourceRoot":"","sources":["../../../src/runtime/bindings/applyComponent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAC;AACpE,OAAO,EACL,kBAAkB,EAClB,aAAa,EACb,eAAe,EACf,gBAAgB,EAChB,iBAAiB,GAClB,MAAM,uCAAuC,CAAC;AAC/C,OAAO,EACL,gBAAgB,GAEjB,MAAM,iCAAiC,CAAC;AACzC,OAAO,EACL,qBAAqB,EACrB,mBAAmB,GACpB,MAAM,oCAAoC,CAAC;AAC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,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,EAC/C,CAAC;YACD,OAAO,CAAC,IAAI,CACV,UAAU,CAAC,CAAC,GAAG,qGAAqG,CACrH,CAAC;QACJ,CAAC;QACD,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;IACvB,CAAC;IAED,IAAI,QAAQ;QAAE,KAAK,MAAM,KAAK,IAAI,aAAa;YAAE,KAAK,EAAE,CAAC;IAEzD,MAAM,QAAQ,GAAG,iBAAiB,CAChC,OAAO,EACP,YAAY,EACZ,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CACnC,CAAC;IACF,IAAI,QAAQ;QAAE,SAAS,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IACvC,OAAO,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC;AACtC,CAAC","sourcesContent":["import { compileExpression } from '../../compile/compileExpression';\nimport {\n boundaryForElement,\n replaceHidden,\n runWithBoundary,\n withSlotBoundary,\n slotContentHidden,\n} from '../../compile/binds/bindErrorBoundary';\nimport {\n linkOuterSlotMap,\n type SlotMap,\n} from '../../compile/contentProjection';\nimport {\n collectForwardedAttrs,\n applyForwardedAttrs,\n} from '../../compile/binds/forwardedAttrs';\nimport { nativeTags } from '@pithyjs/compiler';\nimport { createRoot, untrack } from '@pithyjs/signals';\nimport type { CompDesc, BindingContext, ChildFactory } from './types';\nimport { nearestCtx } from './helpers';\nimport { trimBlankEdges } from '../../compile/trimBlankEdges';\nimport { pithyGlobals } from '../../types/globals';\nimport { isSSRMode } from '../../compile/ssrMode';\nimport { isRenderableComponentEl } from '../../compile/componentResult';\nimport {\n clearSSRRenderCrash,\n reportComponentFailure,\n} from '../../compile/ssrCrashes';\nimport { isolateDestroyCallbacks } from '../onDestroy';\nimport { parsePropNames } from '../../compile/binds/propNames';\nimport { watchStaleRowProp } from '../../compile/binds/staleRowProps';\nimport { markForwardTarget, nodeExpando } from '../../compile/nodeExpando';\nimport { anchorDisposer, componentDisposer } from '../../compile/disposeOrder';\n\ninterface ComponentResult {\n /** Any DOM node — see the `Component` type for why this is not narrower. */\n el: Node;\n destroy?: () => void;\n}\ntype ComponentFn = (props: Record<string, unknown>) => ComponentResult;\n\n/** Map kebab-case or lowered DOM attr name to expected camelCase prop name. */\nfunction normalizePropName(authored: string, expectedProps: string[]): string {\n if (expectedProps.includes(authored)) return authored;\n const lower = authored.toLowerCase();\n const matches = expectedProps.filter(p => p.toLowerCase() === lower);\n return matches.length === 1 ? matches[0] : authored;\n}\n\n/** Cache for extractExpectedPropNames to avoid re-parsing the same function. */\nconst propNamesCache = new WeakMap<ComponentFn, string[]>();\n\n/**\n * Extract destructured prop names from component function signature.\n * NOTE: Uses fn.toString() which may return mangled names under aggressive\n * minification (Terser). In that case, prop name normalization becomes a\n * no-op and props are passed as-is (kebab/lowered). This is acceptable\n * because Vite's default esbuild minifier preserves parameter names.\n */\nfunction extractExpectedPropNames(fn: ComponentFn): string[] {\n const cached = propNamesCache.get(fn);\n if (cached) return cached;\n try {\n const parsed = parsePropNames(fn.toString());\n const names = parsed.fromParam ? parsed.names : [];\n // Detect likely minification: single-char names suggest mangled output\n if (\n import.meta.env?.DEV &&\n names.length > 0 &&\n names.every(n => n.length === 1)\n ) {\n console.warn(\n `[AOT] extractExpectedPropNames: detected single-char names (${names.join(',')}) — prop normalization may not work under minification`\n );\n }\n propNamesCache.set(fn, names);\n return names;\n } catch {\n return [];\n }\n}\n\n/** Runs a slot factory against the parent's context, owned by the mount's disposers. */\nfunction renderSlot(\n factory: ChildFactory,\n ctx: BindingContext,\n disposers: (() => void)[],\n anchor?: Node,\n host?: Element\n): DocumentFragment {\n const g = pithyGlobals();\n const rendering = g.__pithyComponentContext;\n // Otherwise mergeContexts would read the child's names into the slot's context.\n g.__pithyComponentContext = undefined;\n try {\n const { el, destroy } = withSlotBoundary(anchor, host, () =>\n isolateDestroyCallbacks(() => factory(ctx))\n );\n disposers.push(anchorDisposer(destroy, anchor ?? el.firstChild));\n // Bound already: a runtime-compiled child's binders must not bind it again.\n el.childNodes.forEach(\n node => (nodeExpando(node).__pithyComponentDom = true)\n );\n return el;\n } finally {\n g.__pithyComponentContext = rendering;\n }\n}\n\n/**\n * Slot content serialized into the placeholder, from a descriptor without\n * `slots`. The nodes are moved, so each slot can be mounted only once.\n */\nfunction slotsFromChildren(\n el: Element,\n slotMap: SlotMap\n): DocumentFragment | undefined {\n const slotGroups = new Map<string, Node[]>();\n for (const child of Array.from(el.childNodes)) {\n const slotName =\n child.nodeType === Node.ELEMENT_NODE\n ? (child as Element).getAttribute('slot') || ''\n : '';\n const group = slotGroups.get(slotName);\n if (group) group.push(child);\n else slotGroups.set(slotName, [child]);\n }\n const defaultSlot = slotGroups.get('');\n if (defaultSlot) {\n const content = trimBlankEdges(defaultSlot, node =>\n node.nodeType === Node.TEXT_NODE ? node.textContent : null\n );\n if (content.length) slotGroups.set('', content);\n else slotGroups.delete('');\n }\n // `renderChildren()` and `<slot>` must share one fragment, or the later\n // consumer steals the nodes out of the first.\n let injection: DocumentFragment | undefined;\n for (const [slotName, nodes] of slotGroups) {\n if (slotName === '') {\n injection = document.createDocumentFragment();\n for (const node of nodes) injection.appendChild(node);\n const shared = injection;\n slotMap.set('', () => shared);\n continue;\n }\n slotMap.set(slotName, () => {\n const frag = document.createDocumentFragment();\n for (const node of nodes) frag.appendChild(node);\n return frag;\n });\n }\n return injection;\n}\n\nexport function applyComponent(\n d: CompDesc,\n el: Element,\n ctx: BindingContext,\n disposers: (() => void)[],\n pidMap: Map<string, Element>,\n scope?: BindingContext\n): Node[] | undefined {\n // Skip native HTML elements — prevents <div> matching a `div` in context.\n // Only apply when the authored tag is already lowercase; PascalCase tags like\n // <Button> are valid components even though \"button\" is a native tag.\n const tagLower = d.tag.toLowerCase();\n if (d.tag === tagLower && nativeTags.has(tagLower)) return;\n\n // Exact case first: the context holds the template's own locals alongside its\n // components, so a prop named `icon` sits next to the `Icon` component and\n // collides case-insensitively. The JIT path lowercases into a Map, where the\n // components — appended last — overwrite the locals; matching that ordering is\n // why `<Icon>` resolves in dev, and breaking on the first match is why it did\n // not in a build. Falling back last-wins keeps the two paths agreeing.\n let candidate: unknown = Object.prototype.hasOwnProperty.call(ctx, d.tag)\n ? ctx[d.tag]\n : undefined;\n if (candidate === undefined) {\n for (const key of Object.keys(ctx)) {\n if (key.toLowerCase() === tagLower) candidate = ctx[key];\n }\n }\n if (!candidate) return;\n\n // Support default exports\n if (\n candidate &&\n typeof candidate === 'object' &&\n 'default' in candidate &&\n typeof candidate.default === 'function'\n ) {\n candidate = candidate.default;\n }\n if (typeof candidate !== 'function') return;\n // Hidden like a sibling an activated boundary detached: never rendered.\n if (slotContentHidden(el)) return;\n\n const componentFn = candidate as ComponentFn;\n const localCtx = scope ?? nearestCtx(el, ctx);\n\n // Extract expected props for case-insensitive normalization\n const expectedProps = extractExpectedPropNames(componentFn);\n\n // Evaluate prop expressions with prop name normalization\n const props: Record<string, unknown> = {};\n const staleWatchers: (() => void)[] = [];\n for (const [rawName, expr] of Object.entries(d.props)) {\n const propName = normalizePropName(rawName, expectedProps);\n try {\n const fn = compileExpression(expr, localCtx);\n props[propName] = untrack(fn);\n if (import.meta.env?.DEV) {\n const value = props[propName];\n staleWatchers.push(() =>\n watchStaleRowProp(\n localCtx,\n d,\n d.tag,\n propName,\n expr,\n value,\n fn,\n disposers\n )\n );\n }\n } catch {\n // Leave undefined — child uses defaults\n }\n }\n\n const slotMap: SlotMap = new Map();\n linkOuterSlotMap(slotMap, localCtx);\n let injection: DocumentFragment | undefined;\n if (d.slots) {\n for (const [name, factory] of Object.entries(d.slots))\n slotMap.set(name, (ds = disposers, at) =>\n renderSlot(factory, localCtx, ds, at, el)\n );\n } else {\n injection = slotsFromChildren(el, slotMap);\n }\n\n let invoking = true;\n const childrenFactory = d.children;\n const childFactory: ChildFactory | undefined = childrenFactory\n ? (ctx, wrap) =>\n invoking\n ? childrenFactory(ctx, wrap)\n : isolateDestroyCallbacks(() => childrenFactory(ctx, wrap))\n : undefined;\n\n const componentContext = {\n ...localCtx,\n __slotMap: slotMap,\n __childAstNodes: undefined,\n __childFactory: childFactory,\n __slotHost: el,\n };\n\n // Find nearest error boundary\n const boundaryEl = el.closest('[data-error]') as Element | null;\n const boundary = boundaryForElement(boundaryEl);\n\n let out: ComponentResult | undefined;\n let disposeSetup: (() => void) | undefined;\n try {\n out = runWithBoundary(boundary, () => {\n const g = pithyGlobals();\n const originalContext = g.__pithyComponentContext;\n const wasRendering = g.__pithyRenderingComponent;\n const prevInjection = g.__pithyProjectedChildren;\n g.__pithyComponentContext = componentContext;\n g.__pithyRenderingComponent = true;\n g.__pithyProjectedChildren = injection;\n try {\n return createRoot(disposeRoot => {\n disposeSetup = disposeRoot;\n return componentFn(props);\n });\n } finally {\n g.__pithyComponentContext = originalContext;\n g.__pithyRenderingComponent = wasRendering;\n g.__pithyProjectedChildren = prevInjection;\n invoking = false;\n }\n });\n } catch (err) {\n if (boundary) {\n const error = err instanceof Error ? err : new Error(String(err));\n // See `setBoundaryError`: an already-active boundary with no free ancestor\n // drops the error rather than taking it, which is the normal case for a\n // component rendering inside that boundary's `@fallback`.\n reportComponentFailure(el, d.tag, error, boundary);\n return;\n }\n\n // No boundary in scope *yet*. Degrade in both modes — an AOT branch\n // factory renders detached, so `closest()` here cannot see a boundary the\n // element will sit under once the branch is inserted, and throwing would\n // only be swallowed by the structural handler's own catch\n // (`applyStructural.ts`) anyway.\n //\n // A static/server render records the crash instead: dropping the component\n // silently shipped HTML with <${d.tag}> left raw while `pithy-ssg` counted\n // the route as rendered and exited 0 (BUG-018). Anything still recorded\n // when the render finishes fails the route.\n //\n // Note this path cannot reach a boundary at all when the element is inside\n // a detached structural branch: `el.closest('[data-error]')` above found\n // nothing, and no later pass re-binds it, so the boundary never receives\n // the error even though the nodes are inserted underneath it. That is\n // BUG-023; recording is what stops it from shipping silently.\n reportComponentFailure(\n el,\n d.tag,\n err instanceof Error ? err : new Error(String(err)),\n null\n );\n\n console.error(`[AOT] Component <${d.tag}> crashed:`, err);\n return;\n }\n\n if (\n !out ||\n typeof out !== 'object' ||\n !('el' in out) ||\n !isRenderableComponentEl(out.el, el)\n ) {\n // Not a throw, but the same outcome: the raw <${d.tag}> is left in place\n // and the subtree never renders, which under SSR is content silently\n // missing from the emitted HTML. Recorded exactly like a crash (BUG-018).\n // Same funnel as a throw — see `bindComponentTags`. Recording without\n // offering it to the boundary left an AOT component under `@error-boundary`\n // failing its route with the boundary signal unset.\n reportComponentFailure(\n el,\n d.tag,\n new Error(\n `Invalid render result from <${d.tag}>; expected { el, destroy }`\n ),\n boundary\n );\n disposeSetup?.();\n return;\n }\n\n const { el: renderedEl, destroy } = out;\n\n // Capture rendered root element before fragment is consumed by replaceWith\n const forwardedClass = el.getAttribute('class');\n const forwardedAttrs = collectForwardedAttrs(el);\n const renderedRoot: Element | null =\n renderedEl instanceof DocumentFragment\n ? renderedEl.firstElementChild\n : renderedEl instanceof Element\n ? renderedEl\n : null;\n\n const nodes =\n renderedEl instanceof DocumentFragment\n ? Array.from(renderedEl.childNodes)\n : [renderedEl];\n let replaced = true;\n try {\n // A boundary that caught a crash in this render may have hidden `el`.\n if (!replaceHidden(el, nodes)) el.replaceWith(...nodes);\n } catch (err) {\n // The raw <${d.tag}> is left exactly where a crash would have left it, so\n // this is the same content loss and is recorded the same way.\n replaced = false;\n reportComponentFailure(\n el,\n d.tag,\n err instanceof Error ? err : new Error(String(err)),\n boundary\n );\n console.error(`[AOT] Failed to replace <${d.tag}>:`, err);\n }\n\n // Retracted only here, and in the boundary catch above. This is the point at\n // which the component is known to have produced a usable node AND to have\n // reached the document.\n if (isSSRMode() && replaced) clearSSRRenderCrash(el);\n\n if (forwardedClass && renderedRoot) {\n for (const cls of forwardedClass.split(/\\s+/)) {\n if (cls) renderedRoot.classList.add(cls);\n }\n }\n\n if (forwardedAttrs.length > 0 && renderedRoot) {\n applyForwardedAttrs(renderedRoot, forwardedAttrs, d.tag);\n }\n\n // Re-target the component pid to the rendered root so subsequent binding\n // passes (event, bound, class, style) apply to the component's actual DOM\n // element. This matches the JIT path where data-on-* attributes are\n // forwarded from the placeholder to the rendered root.\n if (renderedRoot) {\n pidMap.set(d.pid, renderedRoot);\n markForwardTarget(\n renderedRoot,\n localCtx,\n new Set(forwardedAttrs.map(([name]) => name))\n );\n } else {\n if (\n import.meta.env?.DEV &&\n (forwardedClass ||\n forwardedAttrs.length > 0 ||\n (d.props && Object.keys(d.props).length > 0))\n ) {\n console.warn(\n `[AOT] <${d.tag}> has forwarded attributes but returns a fragment with no single root element — forwarding skipped.`\n );\n }\n pidMap.delete(d.pid);\n }\n\n if (replaced) for (const watch of staleWatchers) watch();\n\n const teardown = componentDisposer(\n destroy,\n disposeSetup,\n nodes[0] ?? (replaced ? null : el)\n );\n if (teardown) disposers.push(teardown);\n return replaced ? nodes : undefined;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"applySimple.d.ts","sourceRoot":"","sources":["../../../src/runtime/bindings/applySimple.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"applySimple.d.ts","sourceRoot":"","sources":["../../../src/runtime/bindings/applySimple.ts"],"names":[],"mappings":"AAoBA,OAAO,KAAK,EACV,OAAO,EACP,SAAS,EACT,QAAQ,EACR,QAAQ,EACR,UAAU,EACV,SAAS,EACT,SAAS,EACT,WAAW,EACX,SAAS,EACT,SAAS,EACT,cAAc,EACf,MAAM,SAAS,CAAC;AAKjB,wBAAgB,QAAQ,CACtB,CAAC,EAAE,OAAO,EACV,EAAE,EAAE,OAAO,EACX,GAAG,EAAE,cAAc,EACnB,SAAS,EAAE,CAAC,MAAM,IAAI,CAAC,EAAE,GACxB,IAAI,CAQN;AAED,wBAAgB,UAAU,CACxB,CAAC,EAAE,SAAS,EACZ,EAAE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ACZ,EAAE,EAAE,OAAO,EACX,GAAG,EAAE,cAAc,EACnB,SAAS,EAAE,CAAC,MAAM,IAAI,CAAC,EAAE,GACxB,IAAI,CAoCN;AAED,wBAAgB,UAAU,CACxB,CAAC,EAAE,SAAS,EACZ,EAAE,EAAE,OAAO,EACX,GAAG,EAAE,cAAc,EACnB,SAAS,EAAE,CAAC,MAAM,IAAI,CAAC,EAAE,GACxB,IAAI,CAmBN"}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { effect, isSignal } from '@pithyjs/signals';
|
|
2
2
|
import { compileExpression } from '../../compile/compileExpression.js';
|
|
3
|
-
import {
|
|
3
|
+
import { UNCOMPILED, writeBound, setStyleProp, styleWriter, } from '../../compile/binds/bindBoundAttributes.js';
|
|
4
4
|
import { toTextValue } from '../../compile/textValue.js';
|
|
5
5
|
import { isSSRMode } from '../../compile/ssrMode.js';
|
|
6
6
|
import { registerBoundary, boundaryForElement, setBoundaryError, withSlotBoundary, } from '../../compile/binds/bindErrorBoundary.js';
|
|
7
7
|
import { applyClassGroup } from '../../compile/binds/bindClassDirectives.js';
|
|
8
8
|
import { mountProjection } from '../../compile/contentProjection.js';
|
|
9
9
|
import { bindAfterProjection } from '../../compile/binds/bindAfterProjection.js';
|
|
10
|
-
import { nodeExpando } from '../../compile/nodeExpando.js';
|
|
10
|
+
import { forwardEventKey, nodeExpando } from '../../compile/nodeExpando.js';
|
|
11
11
|
import { nearestCtx, compileWithEvent } from './helpers.js';
|
|
12
12
|
// ─── Individual binding handlers ──────────────────────────────────────────────
|
|
13
13
|
export function applyRef(d, el, ctx, disposers) {
|
|
@@ -265,10 +265,13 @@ function getAotBoundSet(el, eventName) {
|
|
|
265
265
|
export function applyEvent(d, el, ctx, disposers) {
|
|
266
266
|
// Idempotency: skip if this exact event+expr combo was already bound
|
|
267
267
|
const boundSet = getAotBoundSet(el, d.event);
|
|
268
|
-
const
|
|
268
|
+
const key = `${d.event}${d.mods ? '.' + d.mods.join('.') : ''}=${d.expr}`;
|
|
269
|
+
const fwdCtx = nodeExpando(el).__pithyForwardCtx;
|
|
270
|
+
// A root is marked only after the child bound its own events.
|
|
271
|
+
const boundKey = fwdCtx ? forwardEventKey(el, key) : key;
|
|
269
272
|
if (boundSet.has(boundKey))
|
|
270
273
|
return;
|
|
271
|
-
const localCtx = nearestCtx(el, ctx);
|
|
274
|
+
const localCtx = fwdCtx ?? nearestCtx(el, ctx);
|
|
272
275
|
const mods = parseMods(d.mods);
|
|
273
276
|
const handlerExpr = d.expr;
|
|
274
277
|
const isSimpleIdentifier = /^[a-zA-Z_][a-zA-Z0-9_]*$/.test(handlerExpr);
|
|
@@ -326,7 +329,7 @@ function parseMods(mods) {
|
|
|
326
329
|
return m;
|
|
327
330
|
}
|
|
328
331
|
export function applyClass(d, el, ctx, disposers) {
|
|
329
|
-
const localCtx = nearestCtx(el, ctx);
|
|
332
|
+
const localCtx = nodeExpando(el).__pithyForwardCtx ?? nearestCtx(el, ctx);
|
|
330
333
|
try {
|
|
331
334
|
const evaluate = compileExpression(d.expr, localCtx);
|
|
332
335
|
const stop = effect(() => {
|
|
@@ -344,7 +347,7 @@ export function applyClass(d, el, ctx, disposers) {
|
|
|
344
347
|
}
|
|
345
348
|
}
|
|
346
349
|
export function applyClasses(d, el, ctx, disposers) {
|
|
347
|
-
const localCtx = nearestCtx(el, ctx);
|
|
350
|
+
const localCtx = nodeExpando(el).__pithyForwardCtx ?? nearestCtx(el, ctx);
|
|
348
351
|
try {
|
|
349
352
|
const evaluate = compileExpression(d.expr, localCtx);
|
|
350
353
|
const owned = new Set();
|
|
@@ -371,7 +374,7 @@ export function applyStyle(d, el, ctx, disposers) {
|
|
|
371
374
|
const style = el.style;
|
|
372
375
|
if (!style)
|
|
373
376
|
return;
|
|
374
|
-
const localCtx = nearestCtx(el, ctx);
|
|
377
|
+
const localCtx = nodeExpando(el).__pithyForwardCtx ?? nearestCtx(el, ctx);
|
|
375
378
|
// setProperty requires kebab-case; codegen may emit camelCase (e.g. fontSize)
|
|
376
379
|
const cssProp = d.prop.includes('-') ? d.prop : toKebabCase(d.prop);
|
|
377
380
|
try {
|
|
@@ -403,36 +406,19 @@ export function applyStyle(d, el, ctx, disposers) {
|
|
|
403
406
|
}
|
|
404
407
|
}
|
|
405
408
|
export function applyBound(d, el, ctx, disposers) {
|
|
406
|
-
const localCtx = nearestCtx(el, ctx);
|
|
409
|
+
const localCtx = nodeExpando(el).__pithyForwardCtx ?? nearestCtx(el, ctx);
|
|
407
410
|
// Compile once outside effect via compileExpression (consistent with applyClass/applyStyle).
|
|
408
411
|
try {
|
|
409
|
-
const evaluate = compileExpression(d.expr, localCtx);
|
|
412
|
+
const evaluate = compileExpression(d.expr, localCtx, UNCOMPILED);
|
|
413
|
+
const read = () => {
|
|
414
|
+
const value = evaluate();
|
|
415
|
+
if (value !== UNCOMPILED)
|
|
416
|
+
return value;
|
|
417
|
+
throw d.expr.trim() ? UNCOMPILED : new SyntaxError('Empty expression');
|
|
418
|
+
};
|
|
410
419
|
const writeStyle = d.attr === 'style' ? styleWriter(el) : null;
|
|
411
420
|
const stop = effect(() => {
|
|
412
|
-
|
|
413
|
-
const value = evaluate();
|
|
414
|
-
if (writeStyle && typeof value === 'boolean') {
|
|
415
|
-
writeStyle('');
|
|
416
|
-
}
|
|
417
|
-
else if (typeof value === 'boolean') {
|
|
418
|
-
if (value)
|
|
419
|
-
el.setAttribute(d.attr, '');
|
|
420
|
-
else
|
|
421
|
-
el.removeAttribute(d.attr);
|
|
422
|
-
}
|
|
423
|
-
else {
|
|
424
|
-
const text = String(value ?? '');
|
|
425
|
-
if (writeStyle)
|
|
426
|
-
writeStyle(text);
|
|
427
|
-
else if (rejectsScriptSink(el, d.attr, text))
|
|
428
|
-
el.removeAttribute(d.attr);
|
|
429
|
-
else
|
|
430
|
-
el.setAttribute(d.attr, text);
|
|
431
|
-
}
|
|
432
|
-
}
|
|
433
|
-
catch {
|
|
434
|
-
/* ignore */
|
|
435
|
-
}
|
|
421
|
+
writeBound(el, d.attr, d.expr, writeStyle, read);
|
|
436
422
|
});
|
|
437
423
|
disposers.push(stop);
|
|
438
424
|
}
|