@pithyjs/core 0.1.0-beta.0 → 0.1.0-beta.10
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 +37 -6
- package/dist/a11y/focus-trap.d.ts.map +1 -1
- package/dist/a11y/focus-trap.js +2 -0
- package/dist/a11y/focus-trap.js.map +1 -1
- package/dist/a11y/index.d.ts +4 -4
- package/dist/a11y/index.js +4 -4
- package/dist/a11y/index.js.map +1 -1
- package/dist/a11y/keyboard-utils.js.map +1 -1
- package/dist/a11y/roving-tabindex.js.map +1 -1
- package/dist/a11y/skip-link.js.map +1 -1
- package/dist/compile/bindSwitchCases.d.ts +8 -3
- package/dist/compile/bindSwitchCases.d.ts.map +1 -1
- package/dist/compile/bindSwitchCases.js +113 -177
- package/dist/compile/bindSwitchCases.js.map +1 -1
- package/dist/compile/binds/bindBoundAttributes.d.ts +1 -0
- package/dist/compile/binds/bindBoundAttributes.d.ts.map +1 -1
- package/dist/compile/binds/bindBoundAttributes.js +24 -2
- package/dist/compile/binds/bindBoundAttributes.js.map +1 -1
- package/dist/compile/binds/bindClassDirectives.d.ts +3 -0
- package/dist/compile/binds/bindClassDirectives.d.ts.map +1 -1
- package/dist/compile/binds/bindClassDirectives.js +59 -21
- package/dist/compile/binds/bindClassDirectives.js.map +1 -1
- package/dist/compile/binds/bindComponentsTags.d.ts +2 -0
- package/dist/compile/binds/bindComponentsTags.d.ts.map +1 -1
- package/dist/compile/binds/bindComponentsTags.js +171 -74
- package/dist/compile/binds/bindComponentsTags.js.map +1 -1
- package/dist/compile/binds/bindConditionals.d.ts +2 -2
- package/dist/compile/binds/bindConditionals.d.ts.map +1 -1
- package/dist/compile/binds/bindConditionals.js +22 -5
- package/dist/compile/binds/bindConditionals.js.map +1 -1
- package/dist/compile/binds/bindDefaultTwoWay.d.ts.map +1 -1
- package/dist/compile/binds/bindDefaultTwoWay.js +2 -1
- package/dist/compile/binds/bindDefaultTwoWay.js.map +1 -1
- package/dist/compile/binds/bindDeferDirectives.d.ts.map +1 -1
- package/dist/compile/binds/bindDeferDirectives.js +45 -15
- package/dist/compile/binds/bindDeferDirectives.js.map +1 -1
- package/dist/compile/binds/bindErrorBoundary.d.ts +13 -2
- package/dist/compile/binds/bindErrorBoundary.d.ts.map +1 -1
- package/dist/compile/binds/bindErrorBoundary.js +25 -10
- package/dist/compile/binds/bindErrorBoundary.js.map +1 -1
- package/dist/compile/binds/bindEventHandlers.js +2 -2
- package/dist/compile/binds/bindEventHandlers.js.map +1 -1
- package/dist/compile/binds/bindRefDirectives.js.map +1 -1
- package/dist/compile/binds/bindStyleDirectives.d.ts +17 -0
- package/dist/compile/binds/bindStyleDirectives.d.ts.map +1 -0
- package/dist/compile/binds/bindStyleDirectives.js +47 -0
- package/dist/compile/binds/bindStyleDirectives.js.map +1 -0
- package/dist/compile/binds/bindTextInterpolations.d.ts +2 -1
- package/dist/compile/binds/bindTextInterpolations.d.ts.map +1 -1
- package/dist/compile/binds/bindTextInterpolations.js +55 -17
- package/dist/compile/binds/bindTextInterpolations.js.map +1 -1
- package/dist/compile/binds/directiveRegistry.js.map +1 -1
- package/dist/compile/binds/forwardedAttrs.d.ts +22 -0
- package/dist/compile/binds/forwardedAttrs.d.ts.map +1 -0
- package/dist/compile/binds/forwardedAttrs.js +66 -0
- package/dist/compile/binds/forwardedAttrs.js.map +1 -0
- package/dist/compile/binds/propNames.d.ts +14 -0
- package/dist/compile/binds/propNames.d.ts.map +1 -0
- package/dist/compile/binds/propNames.js +116 -0
- package/dist/compile/binds/propNames.js.map +1 -0
- package/dist/compile/compileExpression.js.map +1 -1
- package/dist/compile/compileNodes.d.ts.map +1 -1
- package/dist/compile/compileNodes.js +6 -3
- package/dist/compile/compileNodes.js.map +1 -1
- package/dist/compile/compileTemplate.d.ts +3 -4
- package/dist/compile/compileTemplate.d.ts.map +1 -1
- package/dist/compile/compileTemplate.js +28 -31
- package/dist/compile/compileTemplate.js.map +1 -1
- package/dist/compile/componentResult.d.ts +100 -0
- package/dist/compile/componentResult.d.ts.map +1 -0
- package/dist/compile/componentResult.js +138 -0
- package/dist/compile/componentResult.js.map +1 -0
- package/dist/compile/contentProjection.d.ts +1 -1
- package/dist/compile/contentProjection.d.ts.map +1 -1
- package/dist/compile/contentProjection.js +32 -15
- package/dist/compile/contentProjection.js.map +1 -1
- package/dist/compile/forLoops/bindForLoops.d.ts +2 -2
- package/dist/compile/forLoops/bindForLoops.d.ts.map +1 -1
- package/dist/compile/forLoops/bindForLoops.js +9 -22
- package/dist/compile/forLoops/bindForLoops.js.map +1 -1
- package/dist/compile/forLoops/createLoopManager.d.ts +6 -3
- package/dist/compile/forLoops/createLoopManager.d.ts.map +1 -1
- package/dist/compile/forLoops/createLoopManager.js +144 -114
- package/dist/compile/forLoops/createLoopManager.js.map +1 -1
- package/dist/compile/forLoops/index.d.ts +5 -5
- package/dist/compile/forLoops/index.js +5 -5
- package/dist/compile/forLoops/index.js.map +1 -1
- package/dist/compile/forLoops/loopHelpers.d.ts +6 -0
- package/dist/compile/forLoops/loopHelpers.d.ts.map +1 -1
- package/dist/compile/forLoops/loopHelpers.js +17 -0
- package/dist/compile/forLoops/loopHelpers.js.map +1 -1
- package/dist/compile/forLoops/loopSignals.js +2 -2
- package/dist/compile/forLoops/loopSignals.js.map +1 -1
- package/dist/compile/forLoops/loopTraversal.js +2 -2
- package/dist/compile/forLoops/loopTraversal.js.map +1 -1
- package/dist/compile/handleConditionalChain.d.ts +2 -2
- package/dist/compile/handleConditionalChain.d.ts.map +1 -1
- package/dist/compile/handleConditionalChain.js +21 -83
- package/dist/compile/handleConditionalChain.js.map +1 -1
- package/dist/compile/index.d.ts +17 -14
- package/dist/compile/index.d.ts.map +1 -1
- package/dist/compile/index.js +28 -12
- package/dist/compile/index.js.map +1 -1
- package/dist/compile/injectScopedStyle.js.map +1 -1
- package/dist/compile/nodeExpando.d.ts +6 -0
- package/dist/compile/nodeExpando.d.ts.map +1 -1
- package/dist/compile/nodeExpando.js.map +1 -1
- package/dist/compile/parseHtml.d.ts.map +1 -1
- package/dist/compile/parseHtml.js +2 -2
- package/dist/compile/parseHtml.js.map +1 -1
- package/dist/compile/pithyTreeToDom.js +1 -1
- package/dist/compile/pithyTreeToDom.js.map +1 -1
- package/dist/compile/renderBranch.d.ts +13 -0
- package/dist/compile/renderBranch.d.ts.map +1 -0
- package/dist/compile/renderBranch.js +65 -0
- package/dist/compile/renderBranch.js.map +1 -0
- package/dist/compile/renderChildren.d.ts +17 -0
- package/dist/compile/renderChildren.d.ts.map +1 -1
- package/dist/compile/renderChildren.js +22 -3
- package/dist/compile/renderChildren.js.map +1 -1
- package/dist/compile/ssrCrashes.d.ts +116 -0
- package/dist/compile/ssrCrashes.d.ts.map +1 -0
- package/dist/compile/ssrCrashes.js +173 -0
- package/dist/compile/ssrCrashes.js.map +1 -0
- package/dist/compile/ssrMode.js +1 -1
- package/dist/compile/ssrMode.js.map +1 -1
- package/dist/compile/textValue.js.map +1 -1
- package/dist/compile/trimBlankEdges.d.ts +2 -0
- package/dist/compile/trimBlankEdges.d.ts.map +1 -0
- package/dist/compile/trimBlankEdges.js +15 -0
- package/dist/compile/trimBlankEdges.js.map +1 -0
- package/dist/config/index.js.map +1 -1
- package/dist/index.d.ts +6 -6
- package/dist/index.js +6 -6
- package/dist/index.js.map +1 -1
- package/dist/interfaces/index.d.ts +2 -2
- package/dist/interfaces/index.js +2 -2
- package/dist/interfaces/index.js.map +1 -1
- package/dist/interfaces/ref-signal.interface.js.map +1 -1
- package/dist/interfaces/ref.interface.js.map +1 -1
- package/dist/runtime/applyBindings.d.ts +5 -5
- package/dist/runtime/applyBindings.d.ts.map +1 -1
- package/dist/runtime/applyBindings.js +97 -21
- package/dist/runtime/applyBindings.js.map +1 -1
- package/dist/runtime/bindings/applyComponent.d.ts +2 -2
- package/dist/runtime/bindings/applyComponent.d.ts.map +1 -1
- package/dist/runtime/bindings/applyComponent.js +137 -39
- package/dist/runtime/bindings/applyComponent.js.map +1 -1
- package/dist/runtime/bindings/applyDefer.d.ts +1 -1
- package/dist/runtime/bindings/applyDefer.d.ts.map +1 -1
- package/dist/runtime/bindings/applyDefer.js +46 -18
- package/dist/runtime/bindings/applyDefer.js.map +1 -1
- package/dist/runtime/bindings/applySimple.d.ts +2 -1
- package/dist/runtime/bindings/applySimple.d.ts.map +1 -1
- package/dist/runtime/bindings/applySimple.js +70 -14
- package/dist/runtime/bindings/applySimple.js.map +1 -1
- package/dist/runtime/bindings/applyStructural.d.ts +1 -1
- package/dist/runtime/bindings/applyStructural.d.ts.map +1 -1
- package/dist/runtime/bindings/applyStructural.js +58 -68
- package/dist/runtime/bindings/applyStructural.js.map +1 -1
- package/dist/runtime/bindings/helpers.d.ts +1 -1
- package/dist/runtime/bindings/helpers.js +1 -1
- package/dist/runtime/bindings/helpers.js.map +1 -1
- package/dist/runtime/bindings/index.d.ts +6 -6
- package/dist/runtime/bindings/index.d.ts.map +1 -1
- package/dist/runtime/bindings/index.js +5 -5
- package/dist/runtime/bindings/index.js.map +1 -1
- package/dist/runtime/bindings/types.d.ts +12 -1
- package/dist/runtime/bindings/types.d.ts.map +1 -1
- package/dist/runtime/bindings/types.js.map +1 -1
- package/dist/runtime/bootstrap.d.ts +1 -1
- package/dist/runtime/bootstrap.js +1 -1
- package/dist/runtime/bootstrap.js.map +1 -1
- package/dist/runtime/createContextProxy.js.map +1 -1
- package/dist/runtime/deferHelpers.d.ts +1 -1
- package/dist/runtime/deferHelpers.js.map +1 -1
- package/dist/runtime/html.d.ts.map +1 -1
- package/dist/runtime/html.js +6 -5
- package/dist/runtime/html.js.map +1 -1
- package/dist/runtime/index.d.ts +6 -5
- package/dist/runtime/index.d.ts.map +1 -1
- package/dist/runtime/index.js +7 -5
- package/dist/runtime/index.js.map +1 -1
- package/dist/runtime/lazy.js +1 -1
- package/dist/runtime/lazy.js.map +1 -1
- package/dist/runtime/module-cache.js.map +1 -1
- package/dist/runtime/onDestroy.d.ts +7 -0
- package/dist/runtime/onDestroy.d.ts.map +1 -1
- package/dist/runtime/onDestroy.js +16 -1
- package/dist/runtime/onDestroy.js.map +1 -1
- package/dist/runtime/parseIdentifiersFromTemplate.js +1 -1
- package/dist/runtime/parseIdentifiersFromTemplate.js.map +1 -1
- package/dist/runtime/resource/createAction.d.ts +44 -0
- package/dist/runtime/resource/createAction.d.ts.map +1 -0
- package/dist/runtime/resource/createAction.js +102 -0
- package/dist/runtime/resource/createAction.js.map +1 -0
- package/dist/runtime/resource/createResource.d.ts +56 -0
- package/dist/runtime/resource/createResource.d.ts.map +1 -0
- package/dist/runtime/resource/createResource.js +102 -0
- package/dist/runtime/resource/createResource.js.map +1 -0
- package/dist/runtime/resource/engine.d.ts +136 -0
- package/dist/runtime/resource/engine.d.ts.map +1 -0
- package/dist/runtime/resource/engine.js +363 -0
- package/dist/runtime/resource/engine.js.map +1 -0
- package/dist/runtime/resource/index.d.ts +19 -0
- package/dist/runtime/resource/index.d.ts.map +1 -0
- package/dist/runtime/resource/index.js +18 -0
- package/dist/runtime/resource/index.js.map +1 -0
- package/dist/runtime/resource/types.d.ts +240 -0
- package/dist/runtime/resource/types.d.ts.map +1 -0
- package/dist/runtime/resource/types.js +9 -0
- package/dist/runtime/resource/types.js.map +1 -0
- package/dist/types/globals.d.ts +10 -1
- package/dist/types/globals.d.ts.map +1 -1
- package/dist/types/globals.js.map +1 -1
- package/dist/types/index.d.ts +15 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js.map +1 -1
- package/dist/utilities/index.d.ts +2 -2
- package/dist/utilities/index.js +2 -2
- package/dist/utilities/index.js.map +1 -1
- package/dist/utilities/ref-signal.utility.d.ts +1 -1
- package/dist/utilities/ref-signal.utility.js.map +1 -1
- package/dist/utilities/ref.untility.d.ts +1 -1
- package/dist/utilities/ref.untility.js.map +1 -1
- package/package.json +14 -9
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/** @codex
|
|
2
|
+
{
|
|
3
|
+
"id": "pithy.runtime.components",
|
|
4
|
+
"title": "Component Tag Binding System",
|
|
5
|
+
"category": "runtime"
|
|
6
|
+
}
|
|
7
|
+
*/
|
|
8
|
+
/** Collect the `data-*` attributes to carry from a component tag to its rendered root. */
|
|
9
|
+
export declare function collectForwardedAttrs(el: Element): Array<[string, string]>;
|
|
10
|
+
/**
|
|
11
|
+
* Write collected attributes onto the rendered root.
|
|
12
|
+
*
|
|
13
|
+
* A forwarded `data-*` REPLACES the component's own value, where a forwarded
|
|
14
|
+
* `class` merges into it — the asymmetry is invisible at the call site, and
|
|
15
|
+
* ui-kit drives styling from `data-variant`/`data-color`/`data-size`, so an
|
|
16
|
+
* author who copies one out of devtools silently overrides the prop that set
|
|
17
|
+
* it. The DEV warning surfaces that collision without picking a winner.
|
|
18
|
+
*
|
|
19
|
+
* Shared by both binders so the two paths cannot drift.
|
|
20
|
+
*/
|
|
21
|
+
export declare function applyForwardedAttrs(target: Element, forwarded: Array<[string, string]>, tag: string): void;
|
|
22
|
+
//# sourceMappingURL=forwardedAttrs.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"forwardedAttrs.d.ts","sourceRoot":"","sources":["../../../src/compile/binds/forwardedAttrs.ts"],"names":[],"mappings":"AAAA;;;;;;EAME;AA6BF,0FAA0F;AAC1F,wBAAgB,qBAAqB,CAAC,EAAE,EAAE,OAAO,GAAG,KAAK,CAAC,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAQ1E;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,OAAO,EACf,SAAS,EAAE,KAAK,CAAC,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,EAClC,GAAG,EAAE,MAAM,GACV,IAAI,CAaN"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/** @codex
|
|
2
|
+
{
|
|
3
|
+
"id": "pithy.runtime.components",
|
|
4
|
+
"title": "Component Tag Binding System",
|
|
5
|
+
"category": "runtime"
|
|
6
|
+
}
|
|
7
|
+
*/
|
|
8
|
+
import { DIRECTIVE_ATTR_PREFIXES, isDirectiveAttr } from '@pithyjs/compiler';
|
|
9
|
+
const FORWARDED_DIRECTIVE_ATTRS = new Set(['data-classes']);
|
|
10
|
+
// Runtime-owned attributes: forwarding them would give the rendered root the
|
|
11
|
+
// component tag's node identity, its parent's style scope, or its loop/defer state.
|
|
12
|
+
const RUNTIME_ATTRS = new Set(['data-pid', 'data-for']);
|
|
13
|
+
const RUNTIME_ATTR_PREFIXES = ['data-scope-', 'data-defer-', 'data-loop-'];
|
|
14
|
+
/**
|
|
15
|
+
* Whether a `data-*` attribute on a component tag belongs on the rendered root.
|
|
16
|
+
*
|
|
17
|
+
* Shared by both compilation paths — the JIT binder (`bindComponentTags`) and
|
|
18
|
+
* the AOT binder (`applyComponent`) — so a plain `data-testid` cannot survive
|
|
19
|
+
* `pnpm dev` and vanish in a production build.
|
|
20
|
+
*/
|
|
21
|
+
function isForwardableAttr(name) {
|
|
22
|
+
if (!name.startsWith('data-') || name.length === 'data-'.length)
|
|
23
|
+
return false;
|
|
24
|
+
if (DIRECTIVE_ATTR_PREFIXES.some(prefix => name.startsWith(prefix))) {
|
|
25
|
+
return true;
|
|
26
|
+
}
|
|
27
|
+
if (FORWARDED_DIRECTIVE_ATTRS.has(name))
|
|
28
|
+
return true;
|
|
29
|
+
if (isDirectiveAttr(name))
|
|
30
|
+
return false;
|
|
31
|
+
if (RUNTIME_ATTRS.has(name))
|
|
32
|
+
return false;
|
|
33
|
+
return !RUNTIME_ATTR_PREFIXES.some(prefix => name.startsWith(prefix));
|
|
34
|
+
}
|
|
35
|
+
/** Collect the `data-*` attributes to carry from a component tag to its rendered root. */
|
|
36
|
+
export function collectForwardedAttrs(el) {
|
|
37
|
+
const forwarded = [];
|
|
38
|
+
for (const attr of Array.from(el.attributes)) {
|
|
39
|
+
if (isForwardableAttr(attr.name)) {
|
|
40
|
+
forwarded.push([attr.name, attr.value]);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return forwarded;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Write collected attributes onto the rendered root.
|
|
47
|
+
*
|
|
48
|
+
* A forwarded `data-*` REPLACES the component's own value, where a forwarded
|
|
49
|
+
* `class` merges into it — the asymmetry is invisible at the call site, and
|
|
50
|
+
* ui-kit drives styling from `data-variant`/`data-color`/`data-size`, so an
|
|
51
|
+
* author who copies one out of devtools silently overrides the prop that set
|
|
52
|
+
* it. The DEV warning surfaces that collision without picking a winner.
|
|
53
|
+
*
|
|
54
|
+
* Shared by both binders so the two paths cannot drift.
|
|
55
|
+
*/
|
|
56
|
+
export function applyForwardedAttrs(target, forwarded, tag) {
|
|
57
|
+
for (const [name, value] of forwarded) {
|
|
58
|
+
if (import.meta.env?.DEV &&
|
|
59
|
+
target.hasAttribute(name) &&
|
|
60
|
+
target.getAttribute(name) !== value) {
|
|
61
|
+
console.warn(`[PithyJS] <${tag}> forwarded ${name}="${value}" over the component's own "${target.getAttribute(name)}".`);
|
|
62
|
+
}
|
|
63
|
+
target.setAttribute(name, value);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=forwardedAttrs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"forwardedAttrs.js","sourceRoot":"","sources":["../../../src/compile/binds/forwardedAttrs.ts"],"names":[],"mappings":"AAAA;;;;;;EAME;AAEF,OAAO,EAAE,uBAAuB,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAE7E,MAAM,yBAAyB,GAAG,IAAI,GAAG,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC;AAE5D,6EAA6E;AAC7E,oFAAoF;AACpF,MAAM,aAAa,GAAG,IAAI,GAAG,CAAC,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC,CAAC;AACxD,MAAM,qBAAqB,GAAG,CAAC,aAAa,EAAE,aAAa,EAAE,YAAY,CAAC,CAAC;AAE3E;;;;;;GAMG;AACH,SA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AAG,EAAE,GAAG;YACpB,MAAM,CAAC,YAAY,CAAC,IAAI,CAAC;YACzB,MAAM,CAAC,YAAY,CAAC,IAAI,CAAC,KAAK,KAAK,EACnC,CAAC;YACD,OAAO,CAAC,IAAI,CACV,cAAc,GAAG,eAAe,IAAI,KAAK,KAAK,+BAA+B,MAAM,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,CAC3G,CAAC;QACJ,CAAC;QACD,MAAM,CAAC,YAAY,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IACnC,CAAC;AACH,CAAC","sourcesContent":["/** @codex\n{\n \"id\": \"pithy.runtime.components\",\n \"title\": \"Component Tag Binding System\",\n \"category\": \"runtime\"\n}\n*/\n\nimport { DIRECTIVE_ATTR_PREFIXES, isDirectiveAttr } from '@pithyjs/compiler';\n\nconst FORWARDED_DIRECTIVE_ATTRS = new Set(['data-classes']);\n\n// Runtime-owned attributes: forwarding them would give the rendered root the\n// component tag's node identity, its parent's style scope, or its loop/defer state.\nconst RUNTIME_ATTRS = new Set(['data-pid', 'data-for']);\nconst RUNTIME_ATTR_PREFIXES = ['data-scope-', 'data-defer-', 'data-loop-'];\n\n/**\n * Whether a `data-*` attribute on a component tag belongs on the rendered root.\n *\n * Shared by both compilation paths — the JIT binder (`bindComponentTags`) and\n * the AOT binder (`applyComponent`) — so a plain `data-testid` cannot survive\n * `pnpm dev` and vanish in a production build.\n */\nfunction isForwardableAttr(name: string): boolean {\n if (!name.startsWith('data-') || name.length === 'data-'.length) return false;\n if (DIRECTIVE_ATTR_PREFIXES.some(prefix => name.startsWith(prefix))) {\n return true;\n }\n if (FORWARDED_DIRECTIVE_ATTRS.has(name)) return true;\n if (isDirectiveAttr(name)) return false;\n if (RUNTIME_ATTRS.has(name)) return false;\n return !RUNTIME_ATTR_PREFIXES.some(prefix => name.startsWith(prefix));\n}\n\n/** Collect the `data-*` attributes to carry from a component tag to its rendered root. */\nexport function collectForwardedAttrs(el: Element): Array<[string, string]> {\n const forwarded: Array<[string, string]> = [];\n for (const attr of Array.from(el.attributes)) {\n if (isForwardableAttr(attr.name)) {\n forwarded.push([attr.name, attr.value]);\n }\n }\n return forwarded;\n}\n\n/**\n * Write collected attributes onto the rendered root.\n *\n * A forwarded `data-*` REPLACES the component's own value, where a forwarded\n * `class` merges into it — the asymmetry is invisible at the call site, and\n * ui-kit drives styling from `data-variant`/`data-color`/`data-size`, so an\n * author who copies one out of devtools silently overrides the prop that set\n * it. The DEV warning surfaces that collision without picking a winner.\n *\n * Shared by both binders so the two paths cannot drift.\n */\nexport function applyForwardedAttrs(\n target: Element,\n forwarded: Array<[string, string]>,\n tag: string\n): void {\n for (const [name, value] of forwarded) {\n if (\n import.meta.env?.DEV &&\n target.hasAttribute(name) &&\n target.getAttribute(name) !== value\n ) {\n console.warn(\n `[PithyJS] <${tag}> forwarded ${name}=\"${value}\" over the component's own \"${target.getAttribute(name)}\".`\n );\n }\n target.setAttribute(name, value);\n }\n}\n"]}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/** @codex
|
|
2
|
+
{
|
|
3
|
+
"id": "pithy.runtime.components",
|
|
4
|
+
"title": "Component Tag Binding System",
|
|
5
|
+
"category": "runtime"
|
|
6
|
+
}
|
|
7
|
+
*/
|
|
8
|
+
export interface PropNames {
|
|
9
|
+
names: string[];
|
|
10
|
+
fromParam: boolean;
|
|
11
|
+
exhaustive: boolean;
|
|
12
|
+
}
|
|
13
|
+
export declare function parsePropNames(src: string): PropNames;
|
|
14
|
+
//# sourceMappingURL=propNames.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"propNames.d.ts","sourceRoot":"","sources":["../../../src/compile/binds/propNames.ts"],"names":[],"mappings":"AAAA;;;;;;EAME;AAEF,MAAM,WAAW,SAAS;IACxB,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,SAAS,EAAE,OAAO,CAAC;IACnB,UAAU,EAAE,OAAO,CAAC;CACrB;AAID,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,CAgDrD"}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
/** @codex
|
|
2
|
+
{
|
|
3
|
+
"id": "pithy.runtime.components",
|
|
4
|
+
"title": "Component Tag Binding System",
|
|
5
|
+
"category": "runtime"
|
|
6
|
+
}
|
|
7
|
+
*/
|
|
8
|
+
const NONE = { names: [], fromParam: false, exhaustive: false };
|
|
9
|
+
export function parsePropNames(src) {
|
|
10
|
+
const arrow = /^\s*(?:async\s+)?([A-Za-z_$][\w$]*)\s*=>/.exec(src);
|
|
11
|
+
let head;
|
|
12
|
+
if (arrow) {
|
|
13
|
+
head = arrow[1];
|
|
14
|
+
}
|
|
15
|
+
else {
|
|
16
|
+
const open = src.indexOf('(');
|
|
17
|
+
if (open < 0 ||
|
|
18
|
+
!/^\s*(?:async\b\s*)?(?:function\b[^(]*|[A-Za-z_$][\w$]*\s*)?$/.test(src.slice(0, open))) {
|
|
19
|
+
return NONE;
|
|
20
|
+
}
|
|
21
|
+
head = src.slice(open + 1).trimStart();
|
|
22
|
+
}
|
|
23
|
+
if (head.startsWith('{')) {
|
|
24
|
+
const body = balanced(head, 0);
|
|
25
|
+
if (body === null)
|
|
26
|
+
return NONE;
|
|
27
|
+
const entries = topLevelEntries(body);
|
|
28
|
+
return {
|
|
29
|
+
names: keyNames(entries),
|
|
30
|
+
fromParam: true,
|
|
31
|
+
exhaustive: !entries.some(e => e.startsWith('...')),
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
const param = /^([A-Za-z_$][\w$]*)/.exec(head)?.[1]?.replace(/\$/g, '\\$');
|
|
35
|
+
if (!param)
|
|
36
|
+
return NONE;
|
|
37
|
+
const names = new Set();
|
|
38
|
+
const destructure = /\b(?:const|let|var)\s*\{/g;
|
|
39
|
+
let m;
|
|
40
|
+
while ((m = destructure.exec(src))) {
|
|
41
|
+
const start = m.index + m[0].length - 1;
|
|
42
|
+
const body = balanced(src, start);
|
|
43
|
+
if (body === null)
|
|
44
|
+
break;
|
|
45
|
+
const rest = src.slice(start + body.length + 2);
|
|
46
|
+
if (new RegExp(`^\\s*=\\s*${param}\\b(?!\\s*\\.)`).test(rest)) {
|
|
47
|
+
for (const name of keyNames(topLevelEntries(body)))
|
|
48
|
+
names.add(name);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
for (const access of src.matchAll(new RegExp(`\\b${param}\\.([A-Za-z_$][\\w$]*)`, 'g'))) {
|
|
52
|
+
names.add(access[1]);
|
|
53
|
+
}
|
|
54
|
+
return { names: [...names], fromParam: false, exhaustive: false };
|
|
55
|
+
}
|
|
56
|
+
function balanced(src, start) {
|
|
57
|
+
let depth = 0;
|
|
58
|
+
let quote = '';
|
|
59
|
+
for (let i = start; i < src.length; i++) {
|
|
60
|
+
const c = src[i];
|
|
61
|
+
if (quote) {
|
|
62
|
+
if (c === '\\')
|
|
63
|
+
i++;
|
|
64
|
+
else if (c === quote)
|
|
65
|
+
quote = '';
|
|
66
|
+
}
|
|
67
|
+
else if (c === '"' || c === "'" || c === '`') {
|
|
68
|
+
quote = c;
|
|
69
|
+
}
|
|
70
|
+
else if (c === '{' || c === '[' || c === '(') {
|
|
71
|
+
depth++;
|
|
72
|
+
}
|
|
73
|
+
else if (c === '}' || c === ']' || c === ')') {
|
|
74
|
+
if (--depth === 0)
|
|
75
|
+
return src.slice(start + 1, i);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return null;
|
|
79
|
+
}
|
|
80
|
+
function topLevelEntries(body) {
|
|
81
|
+
const entries = [];
|
|
82
|
+
let depth = 0;
|
|
83
|
+
let quote = '';
|
|
84
|
+
let from = 0;
|
|
85
|
+
for (let i = 0; i < body.length; i++) {
|
|
86
|
+
const c = body[i];
|
|
87
|
+
if (quote) {
|
|
88
|
+
if (c === '\\')
|
|
89
|
+
i++;
|
|
90
|
+
else if (c === quote)
|
|
91
|
+
quote = '';
|
|
92
|
+
}
|
|
93
|
+
else if (c === '"' || c === "'" || c === '`') {
|
|
94
|
+
quote = c;
|
|
95
|
+
}
|
|
96
|
+
else if (c === '{' || c === '[' || c === '(') {
|
|
97
|
+
depth++;
|
|
98
|
+
}
|
|
99
|
+
else if (c === '}' || c === ']' || c === ')') {
|
|
100
|
+
depth--;
|
|
101
|
+
}
|
|
102
|
+
else if (c === ',' && depth === 0) {
|
|
103
|
+
entries.push(body.slice(from, i));
|
|
104
|
+
from = i + 1;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
entries.push(body.slice(from));
|
|
108
|
+
return entries.map(s => s.trim()).filter(Boolean);
|
|
109
|
+
}
|
|
110
|
+
function keyNames(entries) {
|
|
111
|
+
return entries
|
|
112
|
+
.filter(s => !s.startsWith('...'))
|
|
113
|
+
.map(s => s.split(/[:=]/)[0].trim())
|
|
114
|
+
.filter(s => /^[A-Za-z_$][\w$]*$/.test(s));
|
|
115
|
+
}
|
|
116
|
+
//# sourceMappingURL=propNames.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"propNames.js","sourceRoot":"","sources":["../../../src/compile/binds/propNames.ts"],"names":[],"mappings":"AAAA;;;;;;EAME;AAQF,MAAM,IAAI,GAAc,EAAE,KAAK,EAAE,EAAE,EAAE,SAAS,EAAE,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE,CAAC;AAE3E,MAAM,UAAU,cAAc,CAAC,GAAW;IACxC,MAAM,KAAK,GAAG,0CAA0C,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACnE,IAAI,IAAY,CAAC;IACjB,IAAI,KAAK,EAAE,CAAC;QACV,IAAI,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;SAAM,CAAC;QACN,MAAM,IAAI,GAAG,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;QAC9B,IACE,IAAI,GAAG,CAAC;YACR,CAAC,8DAA8D,CAAC,IAAI,CAClE,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,IAAI,CAAC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C;aAAM,IAAI,CAAC,KAAK,GAAG,IAAI,KAAK,KAAK,CAAC,EAAE,CAAC;YACpC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;YAClC,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC;QACf,CAAC;IACH,CAAC;IACD,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC;IAC/B,OAAO,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;AACpD,CAAC;AAED,SAAS,QAAQ,CAAC,OAAiB;IACjC,OAAO,OAAO;SACX,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;SACjC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;SACnC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,oBAAoB,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;AAC/C,CAAC","sourcesContent":["/** @codex\n{\n \"id\": \"pithy.runtime.components\",\n \"title\": \"Component Tag Binding System\",\n \"category\": \"runtime\"\n}\n*/\n\nexport interface PropNames {\n names: string[];\n fromParam: boolean;\n exhaustive: boolean;\n}\n\nconst NONE: PropNames = { names: [], fromParam: false, exhaustive: false };\n\nexport function parsePropNames(src: string): PropNames {\n const arrow = /^\\s*(?:async\\s+)?([A-Za-z_$][\\w$]*)\\s*=>/.exec(src);\n let head: string;\n if (arrow) {\n head = arrow[1];\n } else {\n const open = src.indexOf('(');\n if (\n open < 0 ||\n !/^\\s*(?:async\\b\\s*)?(?:function\\b[^(]*|[A-Za-z_$][\\w$]*\\s*)?$/.test(\n src.slice(0, open)\n )\n ) {\n return NONE;\n }\n head = src.slice(open + 1).trimStart();\n }\n if (head.startsWith('{')) {\n const body = balanced(head, 0);\n if (body === null) return NONE;\n const entries = topLevelEntries(body);\n return {\n names: keyNames(entries),\n fromParam: true,\n exhaustive: !entries.some(e => e.startsWith('...')),\n };\n }\n\n const param = /^([A-Za-z_$][\\w$]*)/.exec(head)?.[1]?.replace(/\\$/g, '\\\\$');\n if (!param) return NONE;\n const names = new Set<string>();\n const destructure = /\\b(?:const|let|var)\\s*\\{/g;\n let m: RegExpExecArray | null;\n while ((m = destructure.exec(src))) {\n const start = m.index + m[0].length - 1;\n const body = balanced(src, start);\n if (body === null) break;\n const rest = src.slice(start + body.length + 2);\n if (new RegExp(`^\\\\s*=\\\\s*${param}\\\\b(?!\\\\s*\\\\.)`).test(rest)) {\n for (const name of keyNames(topLevelEntries(body))) names.add(name);\n }\n }\n for (const access of src.matchAll(\n new RegExp(`\\\\b${param}\\\\.([A-Za-z_$][\\\\w$]*)`, 'g')\n )) {\n names.add(access[1]);\n }\n return { names: [...names], fromParam: false, exhaustive: false };\n}\n\nfunction balanced(src: string, start: number): string | null {\n let depth = 0;\n let quote = '';\n for (let i = start; i < src.length; i++) {\n const c = src[i];\n if (quote) {\n if (c === '\\\\') i++;\n else if (c === quote) quote = '';\n } else if (c === '\"' || c === \"'\" || c === '`') {\n quote = c;\n } else if (c === '{' || c === '[' || c === '(') {\n depth++;\n } else if (c === '}' || c === ']' || c === ')') {\n if (--depth === 0) return src.slice(start + 1, i);\n }\n }\n return null;\n}\n\nfunction topLevelEntries(body: string): string[] {\n const entries: string[] = [];\n let depth = 0;\n let quote = '';\n let from = 0;\n for (let i = 0; i < body.length; i++) {\n const c = body[i];\n if (quote) {\n if (c === '\\\\') i++;\n else if (c === quote) quote = '';\n } else if (c === '\"' || c === \"'\" || c === '`') {\n quote = c;\n } else if (c === '{' || c === '[' || c === '(') {\n depth++;\n } else if (c === '}' || c === ']' || c === ')') {\n depth--;\n } else if (c === ',' && depth === 0) {\n entries.push(body.slice(from, i));\n from = i + 1;\n }\n }\n entries.push(body.slice(from));\n return entries.map(s => s.trim()).filter(Boolean);\n}\n\nfunction keyNames(entries: string[]): string[] {\n return entries\n .filter(s => !s.startsWith('...'))\n .map(s => s.split(/[:=]/)[0].trim())\n .filter(s => /^[A-Za-z_$][\\w$]*$/.test(s));\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compileExpression.js","sourceRoot":"","sources":["../../src/compile/compileExpression.ts"],"names":[],"mappings":"AAAA;;;;;;EAME;AAEF,wMAAwM;AACxM,MAAM,UAAU,iBAAiB,CAC/B,IAAY,EACZ,GAA4B,EAC5B,QAAY;IAEZ,2BAA2B;IAC3B,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC;QAChC,OAAO,GAAG,EAAE,CAAC,QAAa,CAAC;IAC7B,CAAC;IAED,IAAI,CAAC;QACH,yGAAyG;QACzG,MAAM,EAAE,GAAG,IAAI,QAAQ,CAAC,KAAK,EAAE,uBAAuB,IAAI,KAAK,CAEzD,CAAC;QACP,OAAO,GAAG,EAAE,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC;IACvB,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,IAAI,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,EAAE,CAAC;YACzB,OAAO,CAAC,IAAI,CAAC,6CAA6C,IAAI,IAAI,EAAE,GAAG,CAAC,CAAC;QAC3E,CAAC;QACD,OAAO,GAAG,EAAE,CAAC,QAAa,CAAC;IAC7B,CAAC;AACH,CAAC"}
|
|
1
|
+
{"version":3,"file":"compileExpression.js","sourceRoot":"","sources":["../../src/compile/compileExpression.ts"],"names":[],"mappings":"AAAA;;;;;;EAME;AAEF,wMAAwM;AACxM,MAAM,UAAU,iBAAiB,CAC/B,IAAY,EACZ,GAA4B,EAC5B,QAAY;IAEZ,2BAA2B;IAC3B,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC;QAChC,OAAO,GAAG,EAAE,CAAC,QAAa,CAAC;IAC7B,CAAC;IAED,IAAI,CAAC;QACH,yGAAyG;QACzG,MAAM,EAAE,GAAG,IAAI,QAAQ,CAAC,KAAK,EAAE,uBAAuB,IAAI,KAAK,CAEzD,CAAC;QACP,OAAO,GAAG,EAAE,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC;IACvB,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,IAAI,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,EAAE,CAAC;YACzB,OAAO,CAAC,IAAI,CAAC,6CAA6C,IAAI,IAAI,EAAE,GAAG,CAAC,CAAC;QAC3E,CAAC;QACD,OAAO,GAAG,EAAE,CAAC,QAAa,CAAC;IAC7B,CAAC;AACH,CAAC","sourcesContent":["/** @codex\n{\n \"id\": \"pithy.compiler.expression\",\n \"title\": \"Expression Compiler\",\n \"category\": \"compiler\"\n}\n*/\n\n/** @codexApi {\"parent\":\"pithy.compiler.expression\",\"name\":\"compileExpression\",\"stability\":\"stable\",\"signature\":\"<T = unknown>(expr: string, ctx: Record<string, unknown>, fallback?: T) => () => T\"} */\nexport function compileExpression<T = unknown>(\n expr: string,\n ctx: Record<string, unknown>,\n fallback?: T\n): () => T {\n // Handle empty expressions\n if (!expr || expr.trim() === '') {\n return () => fallback as T;\n }\n\n try {\n // eslint-disable-next-line no-new-func -- JIT template expression evaluation is a core framework feature\n const fn = new Function('ctx', `with(ctx) { return (${expr}) }`) as (\n ctx: Record<string, unknown>\n ) => T;\n return () => fn(ctx);\n } catch (err) {\n if (import.meta.env?.DEV) {\n console.warn(`[PithyJS] ❌ Failed to compile expression \"${expr}\":`, err);\n }\n return () => fallback as T;\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compileNodes.d.ts","sourceRoot":"","sources":["../../src/compile/compileNodes.ts"],"names":[],"mappings":"AAAA;;;;;;EAME;AAEF,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAQnD;;;;;;;;;;;;;;;;;GAiBG;AACH,0NAA0N;AAC1N,wBAAgB,YAAY,CAC1B,KAAK,EAAE,SAAS,EAAE,EAClB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC/B;IAAE,EAAE,EAAE,gBAAgB,CAAC;IAAC,OAAO,EAAE,MAAM,IAAI,CAAA;CAAE,
|
|
1
|
+
{"version":3,"file":"compileNodes.d.ts","sourceRoot":"","sources":["../../src/compile/compileNodes.ts"],"names":[],"mappings":"AAAA;;;;;;EAME;AAEF,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAQnD;;;;;;;;;;;;;;;;;GAiBG;AACH,0NAA0N;AAC1N,wBAAgB,YAAY,CAC1B,KAAK,EAAE,SAAS,EAAE,EAClB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC/B;IAAE,EAAE,EAAE,gBAAgB,CAAC;IAAC,OAAO,EAAE,MAAM,IAAI,CAAA;CAAE,CA2E/C"}
|
|
@@ -5,9 +5,9 @@
|
|
|
5
5
|
"category": "runtime"
|
|
6
6
|
}
|
|
7
7
|
*/
|
|
8
|
-
import { pithyTreeToDom } from './pithyTreeToDom';
|
|
9
|
-
import { bindStructuralDirectives, bindTemplateDirectives, } from './compileTemplate';
|
|
10
|
-
import { drainDestroyCallbacks } from '../runtime/onDestroy';
|
|
8
|
+
import { pithyTreeToDom } from './pithyTreeToDom.js';
|
|
9
|
+
import { bindStructuralDirectives, bindTemplateDirectives, } from './compileTemplate.js';
|
|
10
|
+
import { drainDestroyCallbacks } from '../runtime/onDestroy.js';
|
|
11
11
|
/**
|
|
12
12
|
* Compiles an array of PithyNode AST nodes into live DOM with full binding pipeline.
|
|
13
13
|
*
|
|
@@ -76,6 +76,7 @@ export function compileNodes(nodes, context) {
|
|
|
76
76
|
/* ignore */
|
|
77
77
|
}
|
|
78
78
|
}
|
|
79
|
+
disposers.length = 0;
|
|
79
80
|
},
|
|
80
81
|
};
|
|
81
82
|
}
|
|
@@ -90,6 +91,7 @@ export function compileNodes(nodes, context) {
|
|
|
90
91
|
/* ignore */
|
|
91
92
|
}
|
|
92
93
|
}
|
|
94
|
+
disposers.length = 0;
|
|
93
95
|
for (let i = destroyCallbacks.length - 1; i >= 0; i--) {
|
|
94
96
|
try {
|
|
95
97
|
destroyCallbacks[i]();
|
|
@@ -98,6 +100,7 @@ export function compileNodes(nodes, context) {
|
|
|
98
100
|
/* ignore */
|
|
99
101
|
}
|
|
100
102
|
}
|
|
103
|
+
destroyCallbacks.length = 0;
|
|
101
104
|
},
|
|
102
105
|
};
|
|
103
106
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compileNodes.js","sourceRoot":"","sources":["../../src/compile/compileNodes.ts"],"names":[],"mappings":"AAAA;;;;;;EAME;AAGF,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EACL,wBAAwB,EACxB,sBAAsB,GACvB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAE7D;;;;;;;;;;;;;;;;;GAiBG;AACH,0NAA0N;AAC1N,MAAM,UAAU,YAAY,CAC1B,KAAkB,EAClB,OAAgC;IAEhC,yEAAyE;IACzE,+DAA+D;IAC/D,MAAM,gBAAgB,GAAG,qBAAqB,EAAE,CAAC;IACjD,MAAM,SAAS,GAAmB,EAAE,CAAC;IAErC,IAAI,QAA0B,CAAC;IAC/B,IAAI,CAAC;QACH,uBAAuB;QACvB,QAAQ,GAAG,cAAc,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;QAE1C,sDAAsD;QACtD,wBAAwB,CAAC,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,SAAS,CAAC,CAAC;Q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,KAAK,CAAC,EAAE,CAAC;QAClC,OAAO;YACL,EAAE,EAAE,QAAQ;YACZ,OAAO;gBACL,KAAK,IAAI,CAAC,GAAG,SAAS,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;oBAC/C,IAAI,CAAC;wBACH,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC;oBACjB,CAAC;oBAAC,MAAM,CAAC;wBACP,YAAY;oBACd,CAAC;gBACH,CAAC;gBACD,SAAS,CAAC,MAAM,GAAG,CAAC,CAAC;YACvB,CAAC;SACF,CAAC;IACJ,CAAC;IAED,OAAO;QACL,EAAE,EAAE,QAAQ;QACZ,OAAO;YACL,KAAK,IAAI,CAAC,GAAG,SAAS,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;gBAC/C,IAAI,CAAC;oBACH,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC;gBACjB,CAAC;gBAAC,MAAM,CAAC;oBACP,YAAY;gBACd,CAAC;YACH,CAAC;YACD,SAAS,CAAC,MAAM,GAAG,CAAC,CAAC;YACrB,KAAK,IAAI,CAAC,GAAG,gBAAgB,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;gBACtD,IAAI,CAAC;oBACH,gBAAgB,CAAC,CAAC,CAAC,EAAE,CAAC;gBACxB,CAAC;gBAAC,MAAM,CAAC;oBACP,YAAY;gBACd,CAAC;YACH,CAAC;YACD,gBAAgB,CAAC,MAAM,GAAG,CAAC,CAAC;QAC9B,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["/** @codex\n{\n \"id\": \"pithy.runtime.compile-nodes\",\n \"title\": \"AST Node Compiler\",\n \"category\": \"runtime\"\n}\n*/\n\nimport type { PithyNode } from '@pithyjs/compiler';\nimport { pithyTreeToDom } from './pithyTreeToDom';\nimport {\n bindStructuralDirectives,\n bindTemplateDirectives,\n} from './compileTemplate';\nimport { drainDestroyCallbacks } from '../runtime/onDestroy';\n\n/**\n * Compiles an array of PithyNode AST nodes into live DOM with full binding pipeline.\n *\n * This is the AST counterpart to `compileTemplate`:\n * - `compileTemplate`: HTML string → parse → AST → DOM → structural → non-structural\n * - `compileNodes`: AST → DOM → structural → non-structural\n *\n * Use when you already have AST nodes (e.g. from `__childAstNodes` in component context)\n * and need the full compilation pipeline including structural directives (@if, @switch, @for).\n *\n * @example\n * ```ts\n * import { compileNodes } from \"@pithyjs/core\";\n * const { el, destroy } = compileNodes(astNodes, context);\n * document.body.appendChild(el);\n * // later: destroy();\n * ```\n */\n/** @codexApi {\"parent\":\"pithy.runtime.compile-nodes\",\"name\":\"compileNodes\",\"stability\":\"stable\",\"signature\":\"(nodes: PithyNode[], context: Record<string, unknown>) => { el: DocumentFragment; destroy: () => void }\"} */\nexport function compileNodes(\n nodes: PithyNode[],\n context: Record<string, unknown>\n): { el: DocumentFragment; destroy: () => void } {\n // Drain onDestroy() callbacks — prevents leaks when compileNodes is used\n // as a standalone entry point (renderChildren, ErrorBoundary).\n const destroyCallbacks = drainDestroyCallbacks();\n const disposers: (() => void)[] = [];\n\n let fragment: DocumentFragment;\n try {\n // 1. AST → unbound DOM\n fragment = pithyTreeToDom(nodes, context);\n\n // 2. Structural directives (@switch, @if/@else, @for)\n bindStructuralDirectives(nodes, fragment, context, disposers);\n\n // 3. Non-structural bindings (refs, error boundaries, components, text, events, etc.)\n bindTemplateDirectives(fragment, context, disposers);\n } catch (err) {\n // Clean up any disposers already registered during partial compilation\n for (let i = disposers.length - 1; i >= 0; i--) {\n try {\n disposers[i]();\n } catch {\n /* ignore */\n }\n }\n // Run drained callbacks LIFO before rethrowing so partially-initialized\n // resources are still cleaned up.\n for (let i = destroyCallbacks.length - 1; i >= 0; i--) {\n try {\n destroyCallbacks[i]();\n } catch {\n /* ignore */\n }\n }\n throw err;\n }\n\n // Fast path when no onDestroy was called\n if (destroyCallbacks.length === 0) {\n return {\n el: fragment,\n destroy() {\n for (let i = disposers.length - 1; i >= 0; i--) {\n try {\n disposers[i]();\n } catch {\n /* ignore */\n }\n }\n disposers.length = 0;\n },\n };\n }\n\n return {\n el: fragment,\n destroy() {\n for (let i = disposers.length - 1; i >= 0; i--) {\n try {\n disposers[i]();\n } catch {\n /* ignore */\n }\n }\n disposers.length = 0;\n for (let i = destroyCallbacks.length - 1; i >= 0; i--) {\n try {\n destroyCallbacks[i]();\n } catch {\n /* ignore */\n }\n }\n destroyCallbacks.length = 0;\n },\n };\n}\n"]}
|
|
@@ -9,10 +9,9 @@
|
|
|
9
9
|
* Runs all structural directive bindings on a fragment.
|
|
10
10
|
*
|
|
11
11
|
* Ordering:
|
|
12
|
-
* 1) Switch cases first — they
|
|
13
|
-
* 2) Conditionals (@if/@else) —
|
|
14
|
-
* 3)
|
|
15
|
-
* 4) For loops — skips nodes already processed by conditionals
|
|
12
|
+
* 1) Switch cases first — they claim their case subtrees before conditionals walk the DOM
|
|
13
|
+
* 2) Conditionals (@if/@else) — each branch binds its own nested switches
|
|
14
|
+
* 3) For loops — skips nodes already processed by switches and conditionals
|
|
16
15
|
*/
|
|
17
16
|
export declare function bindStructuralDirectives(nodes: import('@pithyjs/compiler').PithyNode[], fragment: DocumentFragment, context: Record<string, unknown>, disposers: (() => void)[]): void;
|
|
18
17
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compileTemplate.d.ts","sourceRoot":"","sources":["../../src/compile/compileTemplate.ts"],"names":[],"mappings":"AAAA;;;;;;EAME;AAuBF
|
|
1
|
+
{"version":3,"file":"compileTemplate.d.ts","sourceRoot":"","sources":["../../src/compile/compileTemplate.ts"],"names":[],"mappings":"AAAA;;;;;;EAME;AAuBF;;;;;;;GAOG;AACH,wBAAgB,wBAAwB,CACtC,KAAK,EAAE,OAAO,mBAAmB,EAAE,SAAS,EAAE,EAC9C,QAAQ,EAAE,gBAAgB,EAC1B,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAChC,SAAS,EAAE,CAAC,MAAM,IAAI,CAAC,EAAE,GACxB,IAAI,CAUN;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,+RAA+R;AAC/R,wBAAgB,eAAe,CAC7B,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAChC,GAAG,CAAC,EAAE,MAAM,EACZ,OAAO,CAAC,EAAE,MAAM,EAChB,mBAAmB,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,GAChC;IAAE,EAAE,EAAE,WAAW,GAAG,gBAAgB,CAAC;IAAC,OAAO,EAAE,MAAM,IAAI,CAAA;CAAE,CA6C7D;AAED;;;;;;;;;;;;;;;GAeG;AACH,qNAAqN;AACrN,wBAAgB,sBAAsB,CACpC,QAAQ,EAAE,gBAAgB,EAC1B,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAChC,SAAS,EAAE,CAAC,MAAM,IAAI,CAAC,EAAE,GACxB,IAAI,CA2CN"}
|
|
@@ -5,36 +5,34 @@
|
|
|
5
5
|
"category": "runtime"
|
|
6
6
|
}
|
|
7
7
|
*/
|
|
8
|
-
import { parseHtml } from './parseHtml';
|
|
9
|
-
import { injectScopedStyle } from './injectScopedStyle';
|
|
10
|
-
import { bindTextInterpolations } from './binds/bindTextInterpolations';
|
|
11
|
-
import { bindEventHandlers } from './binds/bindEventHandlers';
|
|
12
|
-
import { bindClassDirectives } from './binds/bindClassDirectives';
|
|
13
|
-
import { bindComponentTags } from './binds/bindComponentsTags';
|
|
14
|
-
import { bindConditionals } from './binds/bindConditionals';
|
|
15
|
-
import { bindBoundAttributes } from './binds/bindBoundAttributes';
|
|
16
|
-
import { bindRefDirectives } from './binds/bindRefDirectives';
|
|
17
|
-
import { bindDefaultTwoWay } from './binds/bindDefaultTwoWay';
|
|
18
|
-
import { bindErrorBoundary } from './binds/bindErrorBoundary';
|
|
19
|
-
import { bindDeferDirectives } from './binds/bindDeferDirectives';
|
|
20
|
-
import { bindForLoops } from './forLoops/bindForLoops';
|
|
21
|
-
import { bindSwitchCases } from './bindSwitchCases';
|
|
22
|
-
import { extractSlotDefs, mountProjection, } from './contentProjection';
|
|
23
|
-
import { executeCustomDirectiveBinders } from './binds/directiveRegistry';
|
|
8
|
+
import { parseHtml } from './parseHtml.js';
|
|
9
|
+
import { injectScopedStyle } from './injectScopedStyle.js';
|
|
10
|
+
import { bindTextInterpolations } from './binds/bindTextInterpolations.js';
|
|
11
|
+
import { bindEventHandlers } from './binds/bindEventHandlers.js';
|
|
12
|
+
import { bindClassDirectives } from './binds/bindClassDirectives.js';
|
|
13
|
+
import { bindComponentTags } from './binds/bindComponentsTags.js';
|
|
14
|
+
import { bindConditionals } from './binds/bindConditionals.js';
|
|
15
|
+
import { bindBoundAttributes } from './binds/bindBoundAttributes.js';
|
|
16
|
+
import { bindRefDirectives } from './binds/bindRefDirectives.js';
|
|
17
|
+
import { bindDefaultTwoWay } from './binds/bindDefaultTwoWay.js';
|
|
18
|
+
import { bindErrorBoundary } from './binds/bindErrorBoundary.js';
|
|
19
|
+
import { bindDeferDirectives } from './binds/bindDeferDirectives.js';
|
|
20
|
+
import { bindForLoops } from './forLoops/bindForLoops.js';
|
|
21
|
+
import { bindSwitchCases } from './bindSwitchCases.js';
|
|
22
|
+
import { extractSlotDefs, mountProjection, } from './contentProjection.js';
|
|
23
|
+
import { executeCustomDirectiveBinders } from './binds/directiveRegistry.js';
|
|
24
24
|
/**
|
|
25
25
|
* Runs all structural directive bindings on a fragment.
|
|
26
26
|
*
|
|
27
27
|
* Ordering:
|
|
28
|
-
* 1) Switch cases first — they
|
|
29
|
-
* 2) Conditionals (@if/@else) —
|
|
30
|
-
* 3)
|
|
31
|
-
* 4) For loops — skips nodes already processed by conditionals
|
|
28
|
+
* 1) Switch cases first — they claim their case subtrees before conditionals walk the DOM
|
|
29
|
+
* 2) Conditionals (@if/@else) — each branch binds its own nested switches
|
|
30
|
+
* 3) For loops — skips nodes already processed by switches and conditionals
|
|
32
31
|
*/
|
|
33
32
|
export function bindStructuralDirectives(nodes, fragment, context, disposers) {
|
|
34
|
-
bindSwitchCases(nodes, fragment, context, new Set(), disposers);
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
bindForLoops(nodes, fragment, context, disposers, conditionalProcessedIds);
|
|
33
|
+
const processed = bindSwitchCases(nodes, fragment, context, new Set(), disposers);
|
|
34
|
+
bindConditionals(nodes, fragment, context, processed, disposers);
|
|
35
|
+
bindForLoops(nodes, fragment, context, disposers, processed);
|
|
38
36
|
}
|
|
39
37
|
/**
|
|
40
38
|
* Compiles a raw HTML template into live DOM nodes with signal bindings,
|
|
@@ -100,6 +98,7 @@ export function compileTemplate(html, context, css, scopeId, importedIdentifiers
|
|
|
100
98
|
/* ignore */
|
|
101
99
|
}
|
|
102
100
|
}
|
|
101
|
+
disposers.length = 0;
|
|
103
102
|
},
|
|
104
103
|
};
|
|
105
104
|
}
|
|
@@ -128,14 +127,12 @@ export function bindTemplateDirectives(fragment, context, disposers) {
|
|
|
128
127
|
// 3) content projection — mount projected content into slot anchors BEFORE components.
|
|
129
128
|
// Projected content may contain component tags (e.g., nested <Show> inside <Show>).
|
|
130
129
|
// If components ran first, those nested component tags would never be processed.
|
|
131
|
-
//
|
|
130
|
+
// Without a SlotMap (a component called directly) slots still get their fallback.
|
|
132
131
|
// Use 'in' operator to check via Proxy's has() trap without triggering the get() warning
|
|
133
132
|
const slotMap = ('__slotMap' in context ? context.__slotMap : undefined);
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
mountProjection(slotDefs, slotMap, disposers);
|
|
138
|
-
}
|
|
133
|
+
const slotDefs = extractSlotDefs(fragment);
|
|
134
|
+
if (slotDefs.length > 0) {
|
|
135
|
+
mountProjection(slotDefs, slotMap ?? new Map(), disposers);
|
|
139
136
|
}
|
|
140
137
|
// 4) components — materialize custom tags, including those in projected content
|
|
141
138
|
bindComponentTags(fragment, context, disposers);
|
|
@@ -145,7 +142,7 @@ export function bindTemplateDirectives(fragment, context, disposers) {
|
|
|
145
142
|
bindTextInterpolations(fragment, context, disposers);
|
|
146
143
|
// 7) events (idempotent; supports modifiers; nearest ctx; $event/$el)
|
|
147
144
|
bindEventHandlers(fragment, context, disposers);
|
|
148
|
-
// 8) classes
|
|
145
|
+
// 8) classes and style properties
|
|
149
146
|
bindClassDirectives(fragment, context, disposers);
|
|
150
147
|
// 9) bound attributes
|
|
151
148
|
bindBoundAttributes(fragment, context, disposers);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compileTemplate.js","sourceRoot":"","sources":["../../src/compile/compileTemplate.ts"],"names":[],"mappings":"AAAA;;;;;;EAME;AAEF,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,sBAAsB,EAAE,MAAM,gCAAgC,CAAC;AACxE,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAC9D,OAAO,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AAClE,OAAO,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAC/D,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAC5D,OAAO,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AAClE,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAC9D,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAC9D,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAC9D,OAAO,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AAClE,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OA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CAAC,QAAQ,EAAE,OAAO,EAAE,SAAS,CAAC,CAAC;IAElD,sFAAsF;IACtF,6BAA6B,CAAC,QAAQ,EAAE,OAAO,EAAE,SAAS,CAAC,CAAC;IAE5D,uEAAuE;IACvE,mBAAmB,CAAC,QAAQ,EAAE,OAAO,EAAE,SAAS,CAAC,CAAC;AACpD,CAAC","sourcesContent":["/** @codex\n{\n \"id\": \"pithy.runtime.renderer\",\n \"title\": \"Template Compiler & Renderer\",\n \"category\": \"runtime\"\n}\n*/\n\nimport { parseHtml } from './parseHtml';\nimport { injectScopedStyle } from './injectScopedStyle';\nimport { bindTextInterpolations } from './binds/bindTextInterpolations';\nimport { bindEventHandlers } from './binds/bindEventHandlers';\nimport { bindClassDirectives } from './binds/bindClassDirectives';\nimport { bindComponentTags } from './binds/bindComponentsTags';\nimport { bindConditionals } from './binds/bindConditionals';\nimport { bindBoundAttributes } from './binds/bindBoundAttributes';\nimport { bindRefDirectives } from './binds/bindRefDirectives';\nimport { bindDefaultTwoWay } from './binds/bindDefaultTwoWay';\nimport { bindErrorBoundary } from './binds/bindErrorBoundary';\nimport { bindDeferDirectives } from './binds/bindDeferDirectives';\nimport { bindForLoops } from './forLoops/bindForLoops';\nimport { bindSwitchCases } from './bindSwitchCases';\nimport {\n extractSlotDefs,\n mountProjection,\n type SlotMap,\n} from './contentProjection';\nimport { executeCustomDirectiveBinders } from './binds/directiveRegistry';\n\n/**\n * Runs all structural directive bindings on a fragment.\n *\n * Ordering:\n * 1) Switch cases first — they claim their case subtrees before conditionals walk the DOM\n * 2) Conditionals (@if/@else) — each branch binds its own nested switches\n * 3) For loops — skips nodes already processed by switches and conditionals\n */\nexport function bindStructuralDirectives(\n nodes: import('@pithyjs/compiler').PithyNode[],\n fragment: DocumentFragment,\n context: Record<string, unknown>,\n disposers: (() => void)[]\n): void {\n const processed = bindSwitchCases(\n nodes,\n fragment,\n context,\n new Set(),\n disposers\n );\n bindConditionals(nodes, fragment, context, processed, disposers);\n bindForLoops(nodes, fragment, context, disposers, processed);\n}\n\n/**\n * Compiles a raw HTML template into live DOM nodes with signal bindings,\n * event handlers, and optional styles.\n *\n * Pipeline overview:\n * 1) parseHtml → returns a DocumentFragment + AST nodes (pithyNodes)\n * 2) structural directives first: @if/@else, @switch, @for (they shape the DOM)\n * 3) inject CSS (scoped)\n * 4) run remaining binders in an order that avoids double-binding and cross-contamination:\n * - refs (so later passes can access refs if needed)\n * - components (instantiate/replace custom tags BEFORE binding into their subtree)\n * - two-way (default model bindings for inputs)\n * - text interpolations\n * - events\n * - classes\n * - bound attributes\n *\n * @param html - Raw HTML template string\n * @param context - Reactive context object (signals, methods, components)\n * @param css - Optional CSS string to scope and inject\n * @param scopeId - Optional scope id for CSS scoping\n * @param importedIdentifiers - Optional set of ids exposed to expressions\n */\n/** @codexApi {\"parent\":\"pithy.runtime.renderer\",\"name\":\"compileTemplate\",\"stability\":\"stable\",\"signature\":\"(html: string, context: Record<string, any>, css?: string, scopeId?: string, importedIdentifiers?: Set<string>) => { el: HTMLElement | DocumentFragment; destroy: () => void }\"} */\nexport function compileTemplate(\n html: string,\n context: Record<string, unknown>,\n css?: string,\n scopeId?: string,\n importedIdentifiers?: Set<string>\n): { el: HTMLElement | DocumentFragment; destroy: () => void } {\n const id = scopeId ?? `pithy-${Math.random().toString(36).slice(2, 8)}`;\n const disposers: (() => void)[] = [];\n\n let fragment: DocumentFragment;\n try {\n // Parse into fragment + AST\n const parsed = parseHtml(html, id, context, importedIdentifiers);\n fragment = parsed.fragment;\n\n // Structural transforms first (they change the DOM shape and add anchors)\n bindStructuralDirectives(parsed.pithyNodes, fragment, context, disposers);\n\n // Scoped CSS after structure is stable\n if (css) {\n injectScopedStyle(css, id);\n }\n\n // Remaining directives/bindings in carefully chosen order\n bindTemplateDirectives(fragment, context, disposers);\n } catch (err) {\n // Clean up any disposers registered during partial compilation\n for (let i = disposers.length - 1; i >= 0; i--) {\n try {\n disposers[i]();\n } catch {\n /* ignore */\n }\n }\n throw err;\n }\n\n return {\n el: fragment,\n destroy() {\n for (let i = disposers.length - 1; i >= 0; i--) {\n try {\n disposers[i]();\n } catch {\n /* ignore */\n }\n }\n disposers.length = 0;\n },\n };\n}\n\n/**\n * Applies all non-structural bindings to the compiled fragment.\n *\n * Ordering rationale:\n * - refs: collected early, sometimes needed by subsequent binders\n * - error boundaries: register boundaries before components render (enables error capture)\n * - projection: mount projected content into slot anchors BEFORE component binding,\n * so nested component tags in projected content get processed\n * - components: instantiate/replace custom tags (including those in projected content);\n * prevents parent binders from walking into raw component tags\n * - two-way: attach default v-model-ish behavior on real inputs (not inside components)\n * - text: {{ ... }} bindings (skips nested loops / component subtrees via flags)\n * - events: add listeners (idempotent; supports modifiers; nearest ctx; $event/$el)\n * - classes: dynamic class toggles\n * - attributes: remaining [attr]=\"...\" bindings\n */\n/** @codexApi {\"parent\":\"pithy.runtime.renderer\",\"name\":\"bindTemplateDirectives\",\"stability\":\"stable\",\"signature\":\"(fragment: DocumentFragment, context: Record<string, any>, disposers: (() => void)[]) => void\"} */\nexport function bindTemplateDirectives(\n fragment: DocumentFragment,\n context: Record<string, unknown>,\n disposers: (() => void)[]\n): void {\n // 1) refs first — enables grabbing component roots/elements if needed\n bindRefDirectives(fragment, context, disposers);\n\n // 2) error boundaries — register before components so they can catch component errors\n bindErrorBoundary(fragment, context, disposers);\n\n // 3) content projection — mount projected content into slot anchors BEFORE components.\n // Projected content may contain component tags (e.g., nested <Show> inside <Show>).\n // If components ran first, those nested component tags would never be processed.\n // Without a SlotMap (a component called directly) slots still get their fallback.\n // Use 'in' operator to check via Proxy's has() trap without triggering the get() warning\n const slotMap = ('__slotMap' in context ? context.__slotMap : undefined) as\n | SlotMap\n | undefined;\n const slotDefs = extractSlotDefs(fragment);\n if (slotDefs.length > 0) {\n mountProjection(slotDefs, slotMap ?? new Map(), disposers);\n }\n\n // 4) components — materialize custom tags, including those in projected content\n bindComponentTags(fragment, context, disposers);\n\n // 5) two-way model bindings for native controls at this level\n bindDefaultTwoWay(fragment, context, disposers);\n\n // 6) text interpolations — our binder already skips nested loops & component roots\n bindTextInterpolations(fragment, context, disposers);\n\n // 7) events (idempotent; supports modifiers; nearest ctx; $event/$el)\n bindEventHandlers(fragment, context, disposers);\n\n // 8) classes and style properties\n bindClassDirectives(fragment, context, disposers);\n\n // 9) bound attributes\n bindBoundAttributes(fragment, context, disposers);\n\n // 10) custom directives — allows external packages (router, etc.) to register binders\n executeCustomDirectiveBinders(fragment, context, disposers);\n\n // 11) defer directives — lazy loading with @defer, @load, @placeholder\n bindDeferDirectives(fragment, context, disposers);\n}\n"]}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/** @codex
|
|
2
|
+
{
|
|
3
|
+
"id": "pithy.compile.component-result",
|
|
4
|
+
"title": "Component Result Validation",
|
|
5
|
+
"category": "compiler",
|
|
6
|
+
"risk": "high"
|
|
7
|
+
}
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Is `value` something a binder can actually put into the document?
|
|
11
|
+
*
|
|
12
|
+
* A component contract is `{ el, destroy }`, and both binders used to accept it
|
|
13
|
+
* on the strength of `'el' in out` alone. That is a presence check, not a type
|
|
14
|
+
* check: `{ el: null }` satisfies it, and `el.replaceWith(null)` does not throw
|
|
15
|
+
* — the DOM stringifies the argument, so the page ships the literal text
|
|
16
|
+
* `null` where the component should have been.
|
|
17
|
+
*
|
|
18
|
+
* Measured before this guard existed, in SSR:
|
|
19
|
+
*
|
|
20
|
+
* ```
|
|
21
|
+
* records = 0 html = <div ...>null</div>
|
|
22
|
+
* ```
|
|
23
|
+
*
|
|
24
|
+
* Zero crashes reported, exit 0, and visible garbage in the output — worse than
|
|
25
|
+
* the raw unrendered tag BUG-018 was about, because that at least renders as
|
|
26
|
+
* nothing. TypeScript does not help: an app can be JavaScript, or can cast.
|
|
27
|
+
*
|
|
28
|
+
* `nodeType` alone is not enough, because it is just a property any object can
|
|
29
|
+
* have. `{ nodeType: 1, toString: () => 'BROKEN' }` passed an earlier version of
|
|
30
|
+
* this guard, and `replaceWith` then stringified it into the page exactly like
|
|
31
|
+
* `null` did:
|
|
32
|
+
*
|
|
33
|
+
* ```
|
|
34
|
+
* records = 0 html = <div ...>BROKEN</div>
|
|
35
|
+
* ```
|
|
36
|
+
*
|
|
37
|
+
* So the value must also really be a `Node`. That check has to work ACROSS
|
|
38
|
+
* realms, because a component may legitimately return a node built by another
|
|
39
|
+
* `Window` — an iframe's `contentDocument`, or a module-level `document`
|
|
40
|
+
* captured under a previous route's happy-dom window. A plain
|
|
41
|
+
* `instanceof Node` rejects those, and since both binders run this guard in the
|
|
42
|
+
* browser too, that would turn working components into "invalid render result".
|
|
43
|
+
*
|
|
44
|
+
* Two checks, in order of strength:
|
|
45
|
+
*
|
|
46
|
+
* 1. `instanceof` against the `Node` of `reference`'s realm — the placeholder
|
|
47
|
+
* the binder is replacing, which is by construction a real node in the
|
|
48
|
+
* document being rendered. This is the common case and the strongest
|
|
49
|
+
* signal. The realm comes from `reference` and NEVER from `value`: an
|
|
50
|
+
* earlier version read `value.ownerDocument.defaultView.Node`, which let the
|
|
51
|
+
* candidate nominate its own validator (`{ Node: Object }` passes trivially).
|
|
52
|
+
*
|
|
53
|
+
* 2. Failing that, a structural brand that survives realm boundaries. Real
|
|
54
|
+
* nodes expose `nodeType`, `nodeName` and `cloneNode` through their
|
|
55
|
+
* prototype; a hand-made object carries them as OWN properties, which is
|
|
56
|
+
* what separates a foreign `HTMLSpanElement` from
|
|
57
|
+
* `{ nodeType: 1, toString: () => 'BROKEN' }` — measured, both branches are
|
|
58
|
+
* tested.
|
|
59
|
+
*
|
|
60
|
+
* KNOWN LIMIT, stated rather than glossed: this is defeated by a deliberate
|
|
61
|
+
* forgery. `Object.create({ nodeType: 1, nodeName: 'SPAN', cloneNode() {} })`
|
|
62
|
+
* puts the whole shape on the prototype, so the own-vs-inherited test says
|
|
63
|
+
* "real node", and `replaceWith` then stringifies it into the page.
|
|
64
|
+
*
|
|
65
|
+
* The guard is not escalated further because every stronger static test is
|
|
66
|
+
* worse: `instanceof` alone rejects genuine foreign nodes, and `Symbol.toStringTag`
|
|
67
|
+
* defeats a `[object HTMLDivElement]` brand just as easily. The one check that
|
|
68
|
+
* cannot be forged is observing whether the node actually landed after
|
|
69
|
+
* `replaceWith` — that was implemented and REVERTED, because the JIT binds a
|
|
70
|
+
* structural branch on a detached tree first, where `replaceWith` legitimately
|
|
71
|
+
* does nothing and the retry does the real work: the observation could not tell
|
|
72
|
+
* that apart from stringification and failed `apps/gliora-dashboard`'s `/login`
|
|
73
|
+
* route, whose emitted HTML is in fact complete (4 form-field elements, 2 labels,
|
|
74
|
+
* 2 inputs, no raw tags).
|
|
75
|
+
*
|
|
76
|
+
* So the scope here is ACCIDENT, not adversary: a component returning the wrong
|
|
77
|
+
* shape by mistake — `{ el: null }`, `{ el: undefined }`, a bare options object —
|
|
78
|
+
* which is the failure that actually occurs. A component in your own app that
|
|
79
|
+
* deliberately forges DOM internals is not a threat this layer can address, and
|
|
80
|
+
* pretending otherwise would cost working pages. Tracked in docs/BACKLOG.md.
|
|
81
|
+
*
|
|
82
|
+
* Deliberately **not** an allowlist of node types. The question here is "is this
|
|
83
|
+
* a node at all", not "is it a node I like": a component returning
|
|
84
|
+
* `document.createTextNode('hi')` renders correctly through `replaceWith`, and
|
|
85
|
+
* an earlier version that admitted only elements and fragments silently narrowed
|
|
86
|
+
* the contract and dropped such a subtree. Anything that is a real node but
|
|
87
|
+
* cannot actually be inserted — a `Document`, say — throws inside `replaceWith`,
|
|
88
|
+
* which is already recorded as a failed replacement and gives a truthful error.
|
|
89
|
+
*
|
|
90
|
+
* Fails **open** when nothing can be resolved to check against. A guard that
|
|
91
|
+
* cannot check must not reject everything: with neither a realm on `reference`
|
|
92
|
+
* nor an ambient `Node`, rejecting would record a crash for every component and
|
|
93
|
+
* fail every route — far worse than the malformed output this guards against.
|
|
94
|
+
*
|
|
95
|
+
* @param value - the `el` a component returned
|
|
96
|
+
* @param reference - a node known to be real, whose realm defines `Node`
|
|
97
|
+
*/
|
|
98
|
+
/** @codexApi {"parent":"pithy.compile.component-result","name":"isRenderableComponentEl","stability":"internal","signature":"(value: unknown, reference?: Node | null) => boolean"} */
|
|
99
|
+
export declare function isRenderableComponentEl(value: unknown, reference?: Node | null): boolean;
|
|
100
|
+
//# sourceMappingURL=componentResult.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"componentResult.d.ts","sourceRoot":"","sources":["../../src/compile/componentResult.ts"],"names":[],"mappings":"AAAA;;;;;;;EAOE;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwFG;AACH,uLAAuL;AACvL,wBAAgB,uBAAuB,CACrC,KAAK,EAAE,OAAO,EACd,SAAS,CAAC,EAAE,IAAI,GAAG,IAAI,GACtB,OAAO,CAWT"}
|