@barefootjs/jsx 0.35.7 → 0.36.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/analyzer.d.ts.map +1 -1
- package/dist/directives.d.ts +70 -0
- package/dist/directives.d.ts.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +174 -120
- package/dist/ir-to-client-js/compute-inlinability.d.ts +10 -0
- package/dist/ir-to-client-js/compute-inlinability.d.ts.map +1 -1
- package/dist/ir-to-client-js/compute-scope.d.ts.map +1 -1
- package/dist/ir-to-client-js/csr-substitute.d.ts +25 -5
- package/dist/ir-to-client-js/csr-substitute.d.ts.map +1 -1
- package/dist/ir-to-client-js/emit-module-level.d.ts.map +1 -1
- package/dist/ir-to-client-js/imports.d.ts +2 -2
- package/dist/ir-to-client-js/imports.d.ts.map +1 -1
- package/dist/jsx-to-ir.d.ts.map +1 -1
- package/dist/preprocess-inline-jsx-callbacks.d.ts.map +1 -1
- package/dist/ssr-defaults.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/__tests__/csr-substitute-bare-getter.test.ts +117 -0
- package/src/__tests__/csr-template-scope-soundness.test.ts +125 -0
- package/src/__tests__/module-function-helper-chain-3000.test.ts +200 -0
- package/src/__tests__/module-helper-scope-2986.test.ts +296 -0
- package/src/__tests__/module-scope-arrow-const-2988.test.ts +180 -0
- package/src/__tests__/reactive-factory-cross-file.test.ts +37 -0
- package/src/__tests__/ssr-defaults.test.ts +24 -2
- package/src/analyzer.ts +48 -19
- package/src/directives.ts +75 -0
- package/src/index.ts +3 -0
- package/src/ir-to-client-js/compute-inlinability.ts +92 -16
- package/src/ir-to-client-js/compute-scope.ts +72 -18
- package/src/ir-to-client-js/csr-substitute.ts +61 -11
- package/src/ir-to-client-js/emit-module-level.ts +10 -1
- package/src/ir-to-client-js/imports.ts +5 -0
- package/src/jsx-to-ir.ts +1 -1
- package/src/preprocess-inline-jsx-callbacks.ts +2 -1
- package/src/ssr-defaults.ts +32 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compute-scope.d.ts","sourceRoot":"","sources":["../../src/ir-to-client-js/compute-scope.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAEV,gBAAgB,EAEhB,eAAe,EAChB,MAAM,aAAa,CAAA;AACpB,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAOjD,MAAM,WAAW,iBAAiB;IAChC,aAAa,EAAE,GAAG,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAA;IAC5C,aAAa,EAAE,GAAG,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAA;CAC7C;AAED,wBAAgB,wBAAwB,CACtC,GAAG,EAAE,eAAe,EACpB,KAAK,EAAE,eAAe,GACrB,iBAAiB,
|
|
1
|
+
{"version":3,"file":"compute-scope.d.ts","sourceRoot":"","sources":["../../src/ir-to-client-js/compute-scope.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAEV,gBAAgB,EAEhB,eAAe,EAChB,MAAM,aAAa,CAAA;AACpB,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAOjD,MAAM,WAAW,iBAAiB;IAChC,aAAa,EAAE,GAAG,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAA;IAC5C,aAAa,EAAE,GAAG,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAA;CAC7C;AAED,wBAAgB,wBAAwB,CACtC,GAAG,EAAE,eAAe,EACpB,KAAK,EAAE,eAAe,GACrB,iBAAiB,CAmInB"}
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
*
|
|
7
7
|
* - signal getter calls (`count()`) → `(initialValue)`
|
|
8
8
|
* - memo getter calls (`bars()`) → `(computationBody)`
|
|
9
|
+
* - bare signal/memo getter refs (`count`) → `(() => (initialValue))`
|
|
9
10
|
* - bare inlinable-const refs (`label`) → `(csrInlinable.rewrittenValue)`
|
|
10
11
|
* - bare source-level props refs (`props.x`) → `_p.x`
|
|
11
12
|
*
|
|
@@ -51,7 +52,25 @@ export type CsrInlinabilityMap = Map<string, CsrInlinableEntry | null>;
|
|
|
51
52
|
/**
|
|
52
53
|
* A single substitution: when the source expression mentions `name`
|
|
53
54
|
* (either bare or as a zero-arg call, depending on `kind`), the AST
|
|
54
|
-
* walker splices
|
|
55
|
+
* walker splices a replacement in place.
|
|
56
|
+
*
|
|
57
|
+
* `kind` says what `replacement` IS, not just where it matches:
|
|
58
|
+
*
|
|
59
|
+
* - `'call'`: `replacement` is the VALUE the zero-arg accessor `name()`
|
|
60
|
+
* produces (a signal's initial value, a memo's computation body). The
|
|
61
|
+
* call site `name()` substitutes to `(replacement)` directly. A BARE
|
|
62
|
+
* reference to `name` (uncalled — e.g. a getter passed as a component
|
|
63
|
+
* prop, `<Display value={count} />`, #2924) substitutes to
|
|
64
|
+
* `(() => (replacement))` instead: a thunk over the same value, which
|
|
65
|
+
* is the CSR-template mirror of the reference adapter's SSR shim
|
|
66
|
+
* (`const count = () => 5`, `packages/adapter-hono`) — the only
|
|
67
|
+
* reading that lets a bare accessor evaluate identically on SSR and on
|
|
68
|
+
* CSR-fresh-mount. Registered only by `buildSignalMemoEnv` below.
|
|
69
|
+
* - `'identifier'`: `replacement` is already the value a BARE reference
|
|
70
|
+
* to `name` should read as (e.g. an inlinable const's resolved value);
|
|
71
|
+
* there is no corresponding call form. Substitutes to `(replacement)`
|
|
72
|
+
* at both a bare reference and the (non-existent, for this kind) call
|
|
73
|
+
* position.
|
|
55
74
|
*/
|
|
56
75
|
export interface CsrSubstitution {
|
|
57
76
|
kind: 'call' | 'identifier';
|
|
@@ -62,10 +81,11 @@ export interface CsrSubstitution {
|
|
|
62
81
|
}
|
|
63
82
|
export interface CsrEnv {
|
|
64
83
|
/**
|
|
65
|
-
* Map of name → substitution. Call-kind entries match `name()`
|
|
66
|
-
* (zero-arg call with bare-ident callee
|
|
67
|
-
*
|
|
68
|
-
*
|
|
84
|
+
* Map of name → substitution. Call-kind entries match both `name()`
|
|
85
|
+
* (zero-arg call with bare-ident callee — replaced with the accessor's
|
|
86
|
+
* value) and bare uses of `name` (replaced with a thunk over that same
|
|
87
|
+
* value, #2924); identifier-kind entries match bare uses of `name`
|
|
88
|
+
* outside member-access tails.
|
|
69
89
|
*/
|
|
70
90
|
substitutions: Map<string, CsrSubstitution>;
|
|
71
91
|
/** Source-level props object name (`props`); null for destructured-args. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"csr-substitute.d.ts","sourceRoot":"","sources":["../../src/ir-to-client-js/csr-substitute.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"csr-substitute.d.ts","sourceRoot":"","sources":["../../src/ir-to-client-js/csr-substitute.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAKH,OAAO,KAAK,EAAE,YAAY,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AACrE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAA;AAG7D;;;;;;;;;;;GAWG;AACH,MAAM,WAAW,iBAAiB;IAChC,cAAc,EAAE,MAAM,CAAA;IACtB,eAAe,EAAE,WAAW,CAAC,MAAM,CAAC,CAAA;CACrC;AAED;;;;;GAKG;AACH,MAAM,MAAM,kBAAkB,GAAG,GAAG,CAAC,MAAM,EAAE,iBAAiB,GAAG,IAAI,CAAC,CAAA;AAEtE;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,MAAM,GAAG,YAAY,CAAA;IAC3B,sEAAsE;IACtE,WAAW,EAAE,MAAM,CAAA;IACnB,qFAAqF;IACrF,eAAe,EAAE,WAAW,CAAC,MAAM,CAAC,CAAA;CACrC;AAED,MAAM,WAAW,MAAM;IACrB;;;;;;OAMG;IACH,aAAa,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eAAe,EAAE,MAAM,GAAG,IAAI,EAC9B,cAAc,GAAE,SAAS,YAAY,EAAO,GAC3C,MAAM,CA6CR"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"emit-module-level.d.ts","sourceRoot":"","sources":["../../src/ir-to-client-js/emit-module-level.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,YAAY,EAAE,YAAY,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AAQhG;;;;;;;;;;GAUG;AACH,wBAAgB,2BAA2B,CACzC,oBAAoB,EAAE,SAAS,YAAY,EAAE,EAC7C,oBAAoB,EAAE,SAAS,YAAY,EAAE,EAC7C,kBAAkB,GAAE,SAAS,UAAU,EAAO,EAC9C,gBAAgB,GAAE,SAAS,QAAQ,EAAO,GACzC,MAAM,
|
|
1
|
+
{"version":3,"file":"emit-module-level.d.ts","sourceRoot":"","sources":["../../src/ir-to-client-js/emit-module-level.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,YAAY,EAAE,YAAY,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AAQhG;;;;;;;;;;GAUG;AACH,wBAAgB,2BAA2B,CACzC,oBAAoB,EAAE,SAAS,YAAY,EAAE,EAC7C,oBAAoB,EAAE,SAAS,YAAY,EAAE,EAC7C,kBAAkB,GAAE,SAAS,UAAU,EAAO,EAC9C,gBAAgB,GAAE,SAAS,QAAQ,EAAO,GACzC,MAAM,CA6CR;AAED;;;;;;;;GAQG;AACH,wBAAgB,mBAAmB,CACjC,aAAa,EAAE,MAAM,EACrB,EAAE,EAAE,WAAW,EACf,mBAAmB,EAAE,MAAM,EAAE,GAAG,SAAS,GACxC,MAAM,CAUR"}
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
* Import detection and DOM import management.
|
|
3
3
|
*/
|
|
4
4
|
import type { ComponentIR } from '../types.ts';
|
|
5
|
-
export declare const RUNTIME_IMPORT_CANDIDATES: readonly ['createSignal', 'createMemo', 'createEffect', 'onCleanup', 'onMount', 'hydrate', 'insert', 'getLoopChildren', 'getLoopNodes', 'mapArray', 'mapArrayAnchored', 'mapArrayLazy', 'patchLeaf', 'createDisposableEffect', 'findCondContainer', 'createComponent', 'renderChild', 'registerComponent', 'registerTemplate', 'initChild', 'upsertChild', 'mountRowRoot', 'withParentScope', 'createPortal', 'provideContext', 'createContext', 'useContext', 'forwardProps', 'applyRestAttrs', 'splitProps', 'spreadAttrs', 'styleToCss', 'escapeAttr', 'escapeText', 'escapeTextOrNode', 'escapeCommentText', 'bfMarkup', 'escapeTextOrMarkup', 'markupOrEmpty', 'qsa', 'qsaItem', 'qsaChildScope', 'qsaChildScopes', 'upsertChildItem', '__slot', '__bfSlot', '__bfText', 'claimSlots', 'lazySlots', 'lazyClaimSlots', 'textOrNode', 'beginTurn', 'endTurn', 'date', 'formatDate', 'ownScopeId'];
|
|
5
|
+
export declare const RUNTIME_IMPORT_CANDIDATES: readonly ['createSignal', 'createMemo', 'createEffect', 'onCleanup', 'onMount', 'batch', 'hydrate', 'insert', 'getLoopChildren', 'getLoopNodes', 'mapArray', 'mapArrayAnchored', 'mapArrayLazy', 'patchLeaf', 'createDisposableEffect', 'findCondContainer', 'createComponent', 'renderChild', 'registerComponent', 'registerTemplate', 'initChild', 'upsertChild', 'mountRowRoot', 'withParentScope', 'createPortal', 'provideContext', 'createContext', 'useContext', 'forwardProps', 'applyRestAttrs', 'splitProps', 'spreadAttrs', 'styleToCss', 'escapeAttr', 'escapeText', 'escapeTextOrNode', 'escapeCommentText', 'bfMarkup', 'escapeTextOrMarkup', 'markupOrEmpty', 'qsa', 'qsaItem', 'qsaChildScope', 'qsaChildScopes', 'upsertChildItem', '__slot', '__bfSlot', '__bfText', 'claimSlots', 'lazySlots', 'lazyClaimSlots', 'textOrNode', 'beginTurn', 'endTurn', 'date', 'formatDate', 'ownScopeId'];
|
|
6
6
|
/** @deprecated Use RUNTIME_IMPORT_CANDIDATES */
|
|
7
|
-
export declare const DOM_IMPORT_CANDIDATES: readonly ["createSignal", "createMemo", "createEffect", "onCleanup", "onMount", "hydrate", "insert", "getLoopChildren", "getLoopNodes", "mapArray", "mapArrayAnchored", "mapArrayLazy", "patchLeaf", "createDisposableEffect", "findCondContainer", "createComponent", "renderChild", "registerComponent", "registerTemplate", "initChild", "upsertChild", "mountRowRoot", "withParentScope", "createPortal", "provideContext", "createContext", "useContext", "forwardProps", "applyRestAttrs", "splitProps", "spreadAttrs", "styleToCss", "escapeAttr", "escapeText", "escapeTextOrNode", "escapeCommentText", "bfMarkup", "escapeTextOrMarkup", "markupOrEmpty", "qsa", "qsaItem", "qsaChildScope", "qsaChildScopes", "upsertChildItem", "__slot", "__bfSlot", "__bfText", "claimSlots", "lazySlots", "lazyClaimSlots", "textOrNode", "beginTurn", "endTurn", "date", "formatDate", "ownScopeId"];
|
|
7
|
+
export declare const DOM_IMPORT_CANDIDATES: readonly ["createSignal", "createMemo", "createEffect", "onCleanup", "onMount", "batch", "hydrate", "insert", "getLoopChildren", "getLoopNodes", "mapArray", "mapArrayAnchored", "mapArrayLazy", "patchLeaf", "createDisposableEffect", "findCondContainer", "createComponent", "renderChild", "registerComponent", "registerTemplate", "initChild", "upsertChild", "mountRowRoot", "withParentScope", "createPortal", "provideContext", "createContext", "useContext", "forwardProps", "applyRestAttrs", "splitProps", "spreadAttrs", "styleToCss", "escapeAttr", "escapeText", "escapeTextOrNode", "escapeCommentText", "bfMarkup", "escapeTextOrMarkup", "markupOrEmpty", "qsa", "qsaItem", "qsaChildScope", "qsaChildScopes", "upsertChildItem", "__slot", "__bfSlot", "__bfText", "claimSlots", "lazySlots", "lazyClaimSlots", "textOrNode", "beginTurn", "endTurn", "date", "formatDate", "ownScopeId"];
|
|
8
8
|
export declare const RUNTIME_MODULE = "@barefootjs/client/runtime";
|
|
9
9
|
export declare const IMPORT_PLACEHOLDER = "/* __BAREFOOTJS_DOM_IMPORTS__ */";
|
|
10
10
|
export declare const MODULE_CONSTANTS_PLACEHOLDER = "/* __MODULE_LEVEL_CONSTANTS__ */";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"imports.d.ts","sourceRoot":"","sources":["../../src/ir-to-client-js/imports.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,KAAK,EAAE,WAAW,EAAU,MAAM,aAAa,CAAA;AAMtD,eAAO,MAAM,yBAAyB,YACpC,cAAc,EAAE,YAAY,EAAE,cAAc,EAAE,WAAW,EAAE,SAAS,
|
|
1
|
+
{"version":3,"file":"imports.d.ts","sourceRoot":"","sources":["../../src/ir-to-client-js/imports.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,KAAK,EAAE,WAAW,EAAU,MAAM,aAAa,CAAA;AAMtD,eAAO,MAAM,yBAAyB,YACpC,cAAc,EAAE,YAAY,EAAE,cAAc,EAAE,WAAW,EAAE,SAAS,EAKpE,OAAO,EACP,SAAS,EAAE,QAAQ,EAAE,iBAAiB,EAAE,cAAc,EAAE,UAAU,EAAE,kBAAkB,EAAE,cAAc,EAAE,WAAW,EAAE,wBAAwB,EAK7I,mBAAmB,EACnB,iBAAiB,EAAE,aAAa,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,WAAW,EAAE,aAAa,EAKrG,cAAc,EAId,iBAAiB,EACjB,cAAc,EACd,gBAAgB,EAAE,eAAe,EAAE,YAAY,EAC/C,cAAc,EAAE,gBAAgB,EAAE,YAAY,EAAE,aAAa,EAAE,YAAY,EAAE,YAAY,EAAE,YAAY,EAAE,kBAAkB,EAG3H,mBAAmB,EAInB,UAAU,EAAE,oBAAoB,EAGhC,eAAe,EACf,KAAK,EAAE,SAAS,EAAE,eAAe,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,QAAQ,EAAE,UAAU,EAAE,UAAU,EAUxG,YAAY,EAAE,WAA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;;GAIG;
|
|
1
|
+
{"version":3,"file":"jsx-to-ir.d.ts","sourceRoot":"","sources":["../src/jsx-to-ir.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,OAAO,EACL,KAAK,MAAM,EAgCZ,MAAM,YAAY,CAAA;AACnB,OAAO,EAAE,KAAK,eAAe,EAA0E,MAAM,uBAAuB,CAAA;AA6jCpI,wBAAgB,OAAO,CAAC,QAAQ,EAAE,eAAe,GAAG,MAAM,GAAG,IAAI,CAOhE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"preprocess-inline-jsx-callbacks.d.ts","sourceRoot":"","sources":["../src/preprocess-inline-jsx-callbacks.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;
|
|
1
|
+
{"version":3,"file":"preprocess-inline-jsx-callbacks.d.ts","sourceRoot":"","sources":["../src/preprocess-inline-jsx-callbacks.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAIH,OAAO,KAAK,EAAE,aAAa,EAAkB,MAAM,YAAY,CAAA;AAG/D,MAAM,WAAW,gBAAgB;IAC/B,sFAAsF;IACtF,MAAM,EAAE,MAAM,CAAA;IACd,uEAAuE;IACvE,MAAM,EAAE,aAAa,EAAE,CAAA;IACvB,iEAAiE;IACjE,cAAc,EAAE,MAAM,EAAE,CAAA;CACzB;AAKD;;;;GAIG;AACH,wBAAgB,4BAA4B,CAC1C,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,MAAM,GACf,gBAAgB,CAqBlB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ssr-defaults.d.ts","sourceRoot":"","sources":["../src/ssr-defaults.ts"],"names":[],"mappings":"AAmCA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AAE5C;;;;;GAKG;AACH,MAAM,WAAW,UAAU;IACzB;;;;;OAKG;IACH,KAAK,EAAE,OA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json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@barefootjs/jsx",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.36.0",
|
|
4
4
|
"description": "JSX compiler for BarefootJS - transforms JSX to server HTML + client JS",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
"directory": "packages/jsx"
|
|
50
50
|
},
|
|
51
51
|
"dependencies": {
|
|
52
|
-
"@barefootjs/shared": "0.
|
|
52
|
+
"@barefootjs/shared": "0.36.0"
|
|
53
53
|
},
|
|
54
54
|
"peerDependencies": {
|
|
55
55
|
"@barefootjs/client": ">=0.2.0",
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* #2924 — a BARE (uncalled) reference to a `call`-kind `CsrSubstitution`
|
|
3
|
+
* entry (a signal/memo getter) must substitute as a thunk over the
|
|
4
|
+
* accessor's value, not the value itself.
|
|
5
|
+
*
|
|
6
|
+
* `buildSignalMemoEnv` registers signal getters and memos as `kind: 'call'`
|
|
7
|
+
* entries: the CALL SITE `count()` substitutes to the accessor's value
|
|
8
|
+
* directly (`(5)`), because calling the accessor IS reading the value. A
|
|
9
|
+
* BARE reference to the same name (`count`, uncalled — e.g. passed as a
|
|
10
|
+
* component prop, `<Display value={count} />`) is not a read: it's the
|
|
11
|
+
* accessor itself, which only exists as a real closure inside `initXxx`'s
|
|
12
|
+
* function scope. Before this fix, `csrSubstituteOnce`'s bare-identifier
|
|
13
|
+
* and shorthand-property branches only matched `kind === 'identifier'`, so
|
|
14
|
+
* a bare `count` fell through untouched and leaked into the module-scope
|
|
15
|
+
* `template` lambda as a genuine free identifier — a guaranteed
|
|
16
|
+
* `ReferenceError` on CSR-fresh-mount.
|
|
17
|
+
*
|
|
18
|
+
* The fix: a bare reference to a `call`-kind entry now substitutes to
|
|
19
|
+
* `(() => (value))` — a thunk over the same value the call form produces.
|
|
20
|
+
* This mirrors the reference adapter's (Hono's) SSR shim for the same
|
|
21
|
+
* shape (`const count = () => 5`), so the CSR template and SSR markup
|
|
22
|
+
* agree on what a bare accessor prop evaluates to.
|
|
23
|
+
*
|
|
24
|
+
* Direct unit coverage of `csrSubstitute` itself; `csr-template-scope-
|
|
25
|
+
* soundness.test.ts`'s case D exercises the same fix through the full
|
|
26
|
+
* compile pipeline.
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
import { describe, test, expect } from 'bun:test'
|
|
30
|
+
import { csrSubstitute, type CsrEnv } from '../ir-to-client-js/csr-substitute.ts'
|
|
31
|
+
import { BindingScope } from '../scope/binding-scope.ts'
|
|
32
|
+
|
|
33
|
+
function callEnv(name: string, replacement: string): CsrEnv {
|
|
34
|
+
return {
|
|
35
|
+
substitutions: new Map([[name, { kind: 'call', replacement, freeIdentifiers: new Set() }]]),
|
|
36
|
+
propsObjectName: null,
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
describe('csrSubstitute: bare reference to a call-kind entry (#2924)', () => {
|
|
41
|
+
test('a called reference still substitutes to the plain value', () => {
|
|
42
|
+
const { rewritten, freeIdentifiers } = csrSubstitute('count()', callEnv('count', '5'))
|
|
43
|
+
expect(rewritten).toBe('(5)')
|
|
44
|
+
expect(freeIdentifiers.size).toBe(0)
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
test('a bare reference substitutes to a thunk over the same value', () => {
|
|
48
|
+
const { rewritten, freeIdentifiers } = csrSubstitute('count', callEnv('count', '5'))
|
|
49
|
+
expect(rewritten).toBe('(() => (5))')
|
|
50
|
+
expect(freeIdentifiers.size).toBe(0)
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
test('a bare reference nested in an object literal value position substitutes to a thunk', () => {
|
|
54
|
+
const { rewritten } = csrSubstitute('{ v: count }', callEnv('count', '5'))
|
|
55
|
+
expect(rewritten).toBe('{ v: (() => (5)) }')
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
test('a bare reference in shorthand-property position substitutes to a thunk, keyed correctly', () => {
|
|
59
|
+
const { rewritten } = csrSubstitute('{ count }', callEnv('count', '5'))
|
|
60
|
+
expect(rewritten).toBe('{ count: (() => (5)) }')
|
|
61
|
+
})
|
|
62
|
+
|
|
63
|
+
test('member access on the bare name is untouched (structural protection, #1100)', () => {
|
|
64
|
+
const { rewritten, freeIdentifiers } = csrSubstitute('ctx.count', callEnv('count', '5'))
|
|
65
|
+
expect(rewritten).toBe('ctx.count')
|
|
66
|
+
expect(freeIdentifiers.has('ctx')).toBe(true)
|
|
67
|
+
expect(freeIdentifiers.has('count')).toBe(false)
|
|
68
|
+
})
|
|
69
|
+
|
|
70
|
+
test('a getter call INSIDE a memo body thunk still substitutes (fixed-point loop)', () => {
|
|
71
|
+
const env: CsrEnv = {
|
|
72
|
+
substitutions: new Map([
|
|
73
|
+
['count', { kind: 'call', replacement: '5', freeIdentifiers: new Set() }],
|
|
74
|
+
['doubled', { kind: 'call', replacement: 'count() * 2', freeIdentifiers: new Set(['count']) }],
|
|
75
|
+
]),
|
|
76
|
+
propsObjectName: null,
|
|
77
|
+
}
|
|
78
|
+
const { rewritten, freeIdentifiers } = csrSubstitute('doubled', env)
|
|
79
|
+
expect(rewritten).toBe('(() => ((5) * 2))')
|
|
80
|
+
expect(freeIdentifiers.size).toBe(0)
|
|
81
|
+
})
|
|
82
|
+
|
|
83
|
+
test('a .map() row parameter shadowing the getter name is not substituted', () => {
|
|
84
|
+
const scope = BindingScope.EMPTY.enterLoopRow({ param: 'count' })
|
|
85
|
+
const { rewritten } = csrSubstitute('count', callEnv('count', '5'), scope)
|
|
86
|
+
expect(rewritten).toBe('count')
|
|
87
|
+
})
|
|
88
|
+
|
|
89
|
+
test('an identifier-kind entry (inlinable const) is unaffected by the thunk rule', () => {
|
|
90
|
+
const env: CsrEnv = {
|
|
91
|
+
substitutions: new Map([['label', { kind: 'identifier', replacement: "'hi'", freeIdentifiers: new Set() }]]),
|
|
92
|
+
propsObjectName: null,
|
|
93
|
+
}
|
|
94
|
+
const { rewritten } = csrSubstitute('label', env)
|
|
95
|
+
expect(rewritten).toBe("('hi')")
|
|
96
|
+
})
|
|
97
|
+
})
|
|
98
|
+
|
|
99
|
+
describe('csrSubstitute: bare reference to a signal setter (#2924, setter-symmetric case)', () => {
|
|
100
|
+
function setterEnv(name: string): CsrEnv {
|
|
101
|
+
return {
|
|
102
|
+
substitutions: new Map([[name, { kind: 'identifier', replacement: '() => {}', freeIdentifiers: new Set() }]]),
|
|
103
|
+
propsObjectName: null,
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
test('a bare setter reference substitutes to the noop shim (identifier-kind, no thunk-wrapping)', () => {
|
|
108
|
+
const { rewritten, freeIdentifiers } = csrSubstitute('setCount', setterEnv('setCount'))
|
|
109
|
+
expect(rewritten).toBe('(() => {})')
|
|
110
|
+
expect(freeIdentifiers.size).toBe(0)
|
|
111
|
+
})
|
|
112
|
+
|
|
113
|
+
test('a setter reference nested in an object literal value position also substitutes', () => {
|
|
114
|
+
const { rewritten } = csrSubstitute('{ onChange: setCount }', setterEnv('setCount'))
|
|
115
|
+
expect(rewritten).toBe('{ onChange: (() => {}) }')
|
|
116
|
+
})
|
|
117
|
+
})
|
|
@@ -15,6 +15,14 @@
|
|
|
15
15
|
* C. a getter-elided signal (`const [, setActive] = createSignal(0)`)
|
|
16
16
|
* was dropped from init entirely while its setter stayed referenced
|
|
17
17
|
* by the emitted handler.
|
|
18
|
+
*
|
|
19
|
+
* D. a component prop whose value is (or contains) a BARE — uncalled —
|
|
20
|
+
* reference to a local signal/memo getter (`<Display value={count} />`,
|
|
21
|
+
* #2924) kept the bare source-level name in the `renderChild(...)`
|
|
22
|
+
* props literal instead of substituting a thunk over its value.
|
|
23
|
+
* E. the setter-symmetric case (`<Display update={setCount} />`, #2924):
|
|
24
|
+
* a bare reference to a signal SETTER hit the identical gap — no
|
|
25
|
+
* substitution entry existed for the setter's name at all.
|
|
18
26
|
*/
|
|
19
27
|
|
|
20
28
|
import { describe, test, expect } from 'bun:test'
|
|
@@ -93,6 +101,123 @@ export function Fire() {
|
|
|
93
101
|
// statement must exist in the emitted init.
|
|
94
102
|
expect(clientJs).toMatch(/setFlag\s*\]\s*=\s*createSignal\(0\)/)
|
|
95
103
|
})
|
|
104
|
+
|
|
105
|
+
test('D: a bare signal getter passed as a component prop substitutes a thunk in the template', () => {
|
|
106
|
+
const clientJs = clientJsOf(`
|
|
107
|
+
"use client"
|
|
108
|
+
import { createSignal } from '@barefootjs/client'
|
|
109
|
+
|
|
110
|
+
function Display(props: { value: () => number }) {
|
|
111
|
+
return <span class="value">{props.value()}</span>
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export function Counter() {
|
|
115
|
+
const [count, setCount] = createSignal(5)
|
|
116
|
+
return (
|
|
117
|
+
<div class="root">
|
|
118
|
+
<Display value={count} />
|
|
119
|
+
</div>
|
|
120
|
+
)
|
|
121
|
+
}
|
|
122
|
+
`)
|
|
123
|
+
const template = templateLambdaOf(clientJs, 'Counter')
|
|
124
|
+
expect(template).toContain('value: (() => (5))')
|
|
125
|
+
expect(template).not.toMatch(/value:\s*count\b/)
|
|
126
|
+
})
|
|
127
|
+
|
|
128
|
+
test('D: a bare memo getter passed as a component prop substitutes a thunk over its computation', () => {
|
|
129
|
+
const clientJs = clientJsOf(`
|
|
130
|
+
"use client"
|
|
131
|
+
import { createSignal, createMemo } from '@barefootjs/client'
|
|
132
|
+
|
|
133
|
+
function Display(props: { value: () => number }) {
|
|
134
|
+
return <span class="value">{props.value()}</span>
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
export function Counter() {
|
|
138
|
+
const [count] = createSignal(5)
|
|
139
|
+
const doubled = createMemo(() => count() * 2)
|
|
140
|
+
return (
|
|
141
|
+
<div class="root">
|
|
142
|
+
<Display value={doubled} />
|
|
143
|
+
</div>
|
|
144
|
+
)
|
|
145
|
+
}
|
|
146
|
+
`)
|
|
147
|
+
const template = templateLambdaOf(clientJs, 'Counter')
|
|
148
|
+
expect(template).toContain('value: (() => ((5) * 2))')
|
|
149
|
+
expect(template).not.toMatch(/value:\s*doubled\b/)
|
|
150
|
+
})
|
|
151
|
+
|
|
152
|
+
test('D: a bare getter wrapped in an object literal prop also substitutes a thunk (Context-Provider idiom)', () => {
|
|
153
|
+
const clientJs = clientJsOf(`
|
|
154
|
+
"use client"
|
|
155
|
+
import { createSignal } from '@barefootjs/client'
|
|
156
|
+
|
|
157
|
+
function Display(props: { value: { v: () => number } }) {
|
|
158
|
+
return <span class="value">{props.value.v()}</span>
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
export function Counter() {
|
|
162
|
+
const [count, setCount] = createSignal(5)
|
|
163
|
+
return (
|
|
164
|
+
<div class="root">
|
|
165
|
+
<Display value={{ v: count }} />
|
|
166
|
+
</div>
|
|
167
|
+
)
|
|
168
|
+
}
|
|
169
|
+
`)
|
|
170
|
+
const template = templateLambdaOf(clientJs, 'Counter')
|
|
171
|
+
expect(template).toContain('{ v: (() => (5)) }')
|
|
172
|
+
expect(template).not.toMatch(/\{\s*v:\s*count\s*\}/)
|
|
173
|
+
})
|
|
174
|
+
|
|
175
|
+
test('D: a getter-only const alias (e.g. `const c2 = count`) inlines the same thunk, not a deferred placeholder', () => {
|
|
176
|
+
const clientJs = clientJsOf(`
|
|
177
|
+
"use client"
|
|
178
|
+
import { createSignal } from '@barefootjs/client'
|
|
179
|
+
|
|
180
|
+
function Display(props: { value: () => number }) {
|
|
181
|
+
return <span class="value">{props.value()}</span>
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
export function Counter() {
|
|
185
|
+
const [count, setCount] = createSignal(5)
|
|
186
|
+
const c2 = count
|
|
187
|
+
return (
|
|
188
|
+
<div class="root">
|
|
189
|
+
<Display value={c2} />
|
|
190
|
+
</div>
|
|
191
|
+
)
|
|
192
|
+
}
|
|
193
|
+
`)
|
|
194
|
+
const template = templateLambdaOf(clientJs, 'Counter')
|
|
195
|
+
expect(template).toContain('value: (() => (5))')
|
|
196
|
+
expect(template).not.toContain('data-bf-ph')
|
|
197
|
+
})
|
|
198
|
+
|
|
199
|
+
test('E: a bare signal setter passed as a component prop substitutes the SSR noop shim', () => {
|
|
200
|
+
const clientJs = clientJsOf(`
|
|
201
|
+
"use client"
|
|
202
|
+
import { createSignal } from '@barefootjs/client'
|
|
203
|
+
|
|
204
|
+
function Display(props: { update: () => void }) {
|
|
205
|
+
return <button onClick={() => props.update()}>go</button>
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
export function Counter() {
|
|
209
|
+
const [count, setCount] = createSignal(5)
|
|
210
|
+
return (
|
|
211
|
+
<div class="root">
|
|
212
|
+
<Display update={setCount} />
|
|
213
|
+
</div>
|
|
214
|
+
)
|
|
215
|
+
}
|
|
216
|
+
`)
|
|
217
|
+
const template = templateLambdaOf(clientJs, 'Counter')
|
|
218
|
+
expect(template).toContain('update: (() => {})')
|
|
219
|
+
expect(template).not.toMatch(/update:\s*setCount\b/)
|
|
220
|
+
})
|
|
96
221
|
})
|
|
97
222
|
|
|
98
223
|
/**
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Regression tests for #3000: a module-top-level helper declared as
|
|
3
|
+
* `function name(params) { ... }` that calls ANOTHER module-top-level
|
|
4
|
+
* `function` helper (not itself, not any component-scope name) is safe to
|
|
5
|
+
* reference from a component's CSR template lambda by bare name. This is
|
|
6
|
+
* the function-declaration analog of #2988 (arrow-valued module consts).
|
|
7
|
+
*
|
|
8
|
+
* Pre-fix, `compute-inlinability.ts`'s `functionReferencesDeclaredName`
|
|
9
|
+
* flagged a module-scope function unsafe if it referenced ANY name in
|
|
10
|
+
* `graph.declaredNames` — every local const/function/signal/prop — not
|
|
11
|
+
* just names that are themselves unsafe. `fmt` calling `inner` (itself a
|
|
12
|
+
* safe module-scope helper) tripped that check even though both would
|
|
13
|
+
* correctly land at true module scope per `compute-scope.ts`'s own
|
|
14
|
+
* forward-reachability fixpoint — so the CSR-emitted template lambda
|
|
15
|
+
* substituted `${''}` for the `fmt(label)` slot instead of referencing
|
|
16
|
+
* `fmt` by name.
|
|
17
|
+
*
|
|
18
|
+
* The fix has `computeInlinability`'s function loop read `functionScope`
|
|
19
|
+
* from the same `computeDeclarationScopes(ctx, graph)` call #2998 already
|
|
20
|
+
* added for constants, instead of re-deriving an independent (and more
|
|
21
|
+
* conservative) verdict — closing out the "one producer, three
|
|
22
|
+
* consumers" restructuring #2988's issue body proposed for constants and
|
|
23
|
+
* functions alike.
|
|
24
|
+
*
|
|
25
|
+
* These tests exercise `compileJSX` — the same entry point
|
|
26
|
+
* `@barefootjs/vite`'s plugin and `packages/adapter-tests/src/csr-render.ts`
|
|
27
|
+
* call — and evaluate the extracted CSR template body as a real
|
|
28
|
+
* template-literal function, mirroring what `hydrate()` does at runtime
|
|
29
|
+
* (minus the DOM). This is the closest unit-level stand-in for the real
|
|
30
|
+
* pipeline: `compileJSX` performs the exact analysis → compute-scope →
|
|
31
|
+
* compute-inlinability → html-template sequence `generateClientJsWithSourceMap`
|
|
32
|
+
* runs in production (`packages/jsx/src/ir-to-client-js/generate-init.ts`
|
|
33
|
+
* L66-73), with nothing mocked.
|
|
34
|
+
*/
|
|
35
|
+
import { describe, test, expect } from 'bun:test'
|
|
36
|
+
import { compileJSX } from '../compiler'
|
|
37
|
+
import { HonoAdapter } from '../../../adapter-hono/src/adapter/hono-adapter'
|
|
38
|
+
import { extractTemplateBody } from './staged-ir/helpers'
|
|
39
|
+
import { RUNTIME_IMPORT_CANDIDATES } from '../ir-to-client-js/imports'
|
|
40
|
+
|
|
41
|
+
const onlyErrors = (errors: { severity?: string }[]) =>
|
|
42
|
+
errors.filter((e) => e.severity === 'error')
|
|
43
|
+
|
|
44
|
+
function compileTemplateBody(source: string, fileName: string): { templateBody: string; clientJs: string } {
|
|
45
|
+
const result = compileJSX(source, fileName, { adapter: new HonoAdapter() })
|
|
46
|
+
expect(onlyErrors(result.errors)).toHaveLength(0)
|
|
47
|
+
const clientJs = result.files.find((f) => f.type === 'clientJs')!.content
|
|
48
|
+
return { templateBody: extractTemplateBody(clientJs), clientJs }
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** Module-level declarations sit between the import line and
|
|
52
|
+
* `export function init<Name>` in the compiled bundle. The template
|
|
53
|
+
* lambda runs at real module scope in production, closing over these
|
|
54
|
+
* by normal JS scoping — reproduce that here instead of leaving them
|
|
55
|
+
* undeclared in the sandbox. */
|
|
56
|
+
function extractModulePreamble(clientJs: string): string {
|
|
57
|
+
const m = clientJs.match(/\n\n([\s\S]*?)\nexport function init\w+/)
|
|
58
|
+
return m ? m[1] : ''
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** Evaluate an extracted CSR template body as a real template-literal
|
|
62
|
+
* function, with every runtime helper the compiler might reference
|
|
63
|
+
* stubbed to identity/no-op, and the compiled bundle's module-level
|
|
64
|
+
* declarations (if any) in scope. Mirrors `hydrate()` minus the DOM. */
|
|
65
|
+
function evalTemplate(templateBody: string, props: Record<string, unknown>, modulePreamble = ''): string {
|
|
66
|
+
const helperNames = [...RUNTIME_IMPORT_CANDIDATES]
|
|
67
|
+
const stubs = helperNames.map((name) => {
|
|
68
|
+
if (name === 'escapeAttr' || name === 'escapeText' || name === 'escapeTextOrMarkup' || name === 'styleToCss') {
|
|
69
|
+
return (v: unknown) => String(v)
|
|
70
|
+
}
|
|
71
|
+
return (..._args: unknown[]) => ''
|
|
72
|
+
})
|
|
73
|
+
// eslint-disable-next-line no-new-func
|
|
74
|
+
const fn = new Function('_p', ...helperNames, `${modulePreamble}\nreturn \`${templateBody}\``)
|
|
75
|
+
return fn(props, ...stubs)
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
describe('CSR template: module-scope function calling another module-scope function (#3000)', () => {
|
|
79
|
+
test('a module function helper that calls another module function helper renders its real value, not an empty seed', () => {
|
|
80
|
+
const source = `
|
|
81
|
+
'use client'
|
|
82
|
+
import { createSignal } from '@barefootjs/client'
|
|
83
|
+
|
|
84
|
+
function inner(s: string) { return s.toUpperCase() }
|
|
85
|
+
function fmt(s: string) { return inner(s) }
|
|
86
|
+
|
|
87
|
+
export function Widget({ label }: { label: string }) {
|
|
88
|
+
const [count, setCount] = createSignal(0)
|
|
89
|
+
return (
|
|
90
|
+
<div>
|
|
91
|
+
<span>{fmt(label)}</span>
|
|
92
|
+
<button onClick={() => setCount(count() + 1)}>{count()}</button>
|
|
93
|
+
</div>
|
|
94
|
+
)
|
|
95
|
+
}
|
|
96
|
+
`
|
|
97
|
+
const { templateBody, clientJs } = compileTemplateBody(source, 'Widget.tsx')
|
|
98
|
+
|
|
99
|
+
// Both helpers are referenced by bare name in the template (wrapped
|
|
100
|
+
// in relocate/CSR-substitution parens, so match on the word boundary
|
|
101
|
+
// rather than the literal call-site text), not substituted away as
|
|
102
|
+
// an unsafe/empty fallback.
|
|
103
|
+
expect(/\bfmt\b/.test(templateBody)).toBe(true)
|
|
104
|
+
expect(templateBody).not.toBe('')
|
|
105
|
+
|
|
106
|
+
const html = evalTemplate(templateBody, { label: 'hi' }, extractModulePreamble(clientJs))
|
|
107
|
+
expect(html).toContain('HI')
|
|
108
|
+
expect(html).not.toContain('undefined')
|
|
109
|
+
})
|
|
110
|
+
|
|
111
|
+
test('the arrow-const form of the same two-hop helper chain renders identically (parity check with #2988)', () => {
|
|
112
|
+
const functionSource = `
|
|
113
|
+
'use client'
|
|
114
|
+
import { createSignal } from '@barefootjs/client'
|
|
115
|
+
function inner(s: string) { return s.toUpperCase() }
|
|
116
|
+
function fmt(s: string) { return inner(s) }
|
|
117
|
+
export function Widget({ label }: { label: string }) {
|
|
118
|
+
const [count] = createSignal(0)
|
|
119
|
+
return <div>{fmt(label)}{count()}</div>
|
|
120
|
+
}
|
|
121
|
+
`
|
|
122
|
+
const arrowSource = `
|
|
123
|
+
'use client'
|
|
124
|
+
import { createSignal } from '@barefootjs/client'
|
|
125
|
+
const inner = (s: string) => s.toUpperCase()
|
|
126
|
+
const fmt = (s: string) => inner(s)
|
|
127
|
+
export function Widget({ label }: { label: string }) {
|
|
128
|
+
const [count] = createSignal(0)
|
|
129
|
+
return <div>{fmt(label)}{count()}</div>
|
|
130
|
+
}
|
|
131
|
+
`
|
|
132
|
+
const fn = compileTemplateBody(functionSource, 'FunctionChainWidget.tsx')
|
|
133
|
+
const arrow = compileTemplateBody(arrowSource, 'ArrowChainWidget.tsx')
|
|
134
|
+
|
|
135
|
+
const fnHtml = evalTemplate(fn.templateBody, { label: 'hi' }, extractModulePreamble(fn.clientJs))
|
|
136
|
+
const arrowHtml = evalTemplate(arrow.templateBody, { label: 'hi' }, extractModulePreamble(arrow.clientJs))
|
|
137
|
+
|
|
138
|
+
expect(fnHtml).toBe(arrowHtml)
|
|
139
|
+
expect(fnHtml).toContain('HI')
|
|
140
|
+
})
|
|
141
|
+
|
|
142
|
+
test('a module function that calls a helper reading a signal stays template-unsafe (no over-widening)', () => {
|
|
143
|
+
// `fmt` here transitively references the module-scope-invisible
|
|
144
|
+
// signal getter `count` (via `inner`), so both must stay classified
|
|
145
|
+
// unsafe — the fixpoint must demote them to 'init' scope exactly
|
|
146
|
+
// like a single module-scope function that touches component
|
|
147
|
+
// internals directly already is.
|
|
148
|
+
const source = `
|
|
149
|
+
'use client'
|
|
150
|
+
import { createSignal } from '@barefootjs/client'
|
|
151
|
+
|
|
152
|
+
function inner(s: string) { return \`\${s}-\${count()}\` }
|
|
153
|
+
function fmt(s: string) { return inner(s) }
|
|
154
|
+
|
|
155
|
+
export function Widget({ label }: { label: string }) {
|
|
156
|
+
const [count, setCount] = createSignal(0)
|
|
157
|
+
return <div>{fmt(label)}</div>
|
|
158
|
+
}
|
|
159
|
+
`
|
|
160
|
+
const { templateBody } = compileTemplateBody(source, 'UnsafeChainWidget.tsx')
|
|
161
|
+
// Falls back to the empty-slot sentinel, same as the pre-existing
|
|
162
|
+
// behavior for any function that genuinely can't be hoisted to
|
|
163
|
+
// module scope — NOT a bare `fmt(...)` reference (which would
|
|
164
|
+
// ReferenceError: `fmt` never gets a module-level declaration for
|
|
165
|
+
// this shape).
|
|
166
|
+
expect(templateBody).not.toContain('fmt(')
|
|
167
|
+
})
|
|
168
|
+
|
|
169
|
+
test('a three-hop module function chain resolves the same fixpoint transitively', () => {
|
|
170
|
+
// `outer` -> `mid` -> `inner`, none touching component internals.
|
|
171
|
+
// Exercises resolve-by-name for a chain longer than one hop, not just
|
|
172
|
+
// the direct two-function case above. Since none of the three
|
|
173
|
+
// transitively reference an init-required name, all three land on
|
|
174
|
+
// `'module'` via the fixpoint's trailing "survivors are module"
|
|
175
|
+
// assignment on the very first pass (`changed` never flips `true`) —
|
|
176
|
+
// this is coverage for the 3-hop resolve-by-name behavior, not for
|
|
177
|
+
// multi-round fixpoint iteration specifically (that would need at
|
|
178
|
+
// least one hop to genuinely demote before a later pass re-checks a
|
|
179
|
+
// caller of it).
|
|
180
|
+
const source = `
|
|
181
|
+
'use client'
|
|
182
|
+
import { createSignal } from '@barefootjs/client'
|
|
183
|
+
|
|
184
|
+
function inner(s: string) { return s.toUpperCase() }
|
|
185
|
+
function mid(s: string) { return inner(s) }
|
|
186
|
+
function outer(s: string) { return mid(s) }
|
|
187
|
+
|
|
188
|
+
export function Widget({ label }: { label: string }) {
|
|
189
|
+
const [count] = createSignal(0)
|
|
190
|
+
return <div>{outer(label)}{count()}</div>
|
|
191
|
+
}
|
|
192
|
+
`
|
|
193
|
+
const { templateBody, clientJs } = compileTemplateBody(source, 'ThreeHopWidget.tsx')
|
|
194
|
+
expect(/\bouter\b/.test(templateBody)).toBe(true)
|
|
195
|
+
|
|
196
|
+
const html = evalTemplate(templateBody, { label: 'hi' }, extractModulePreamble(clientJs))
|
|
197
|
+
expect(html).toContain('HI')
|
|
198
|
+
expect(html).not.toContain('undefined')
|
|
199
|
+
})
|
|
200
|
+
})
|