@barefootjs/xslate 0.35.1 → 0.35.3
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/adapter/expr/emitters.d.ts.map +1 -1
- package/dist/adapter/index.js +16 -4
- package/dist/adapter/props/prop-classes.d.ts +14 -0
- package/dist/adapter/props/prop-classes.d.ts.map +1 -1
- package/dist/index.js +16 -4
- package/dist/vite.js +33 -7
- package/lib/BarefootJS/Backend/Xslate.pm +1 -1
- package/package.json +5 -5
- package/src/__tests__/xslate-adapter.test.ts +30 -0
- package/src/adapter/expr/emitters.ts +19 -5
- package/src/adapter/props/prop-classes.ts +21 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"emitters.d.ts","sourceRoot":"","sources":["../../../src/adapter/expr/emitters.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAGL,KAAK,iBAAiB,EACtB,KAAK,eAAe,EAGpB,KAAK,WAAW,EAChB,KAAK,WAAW,EAChB,KAAK,UAAU,EACf,KAAK,qBAAqB,EAC1B,KAAK,SAAS,EACd,KAAK,YAAY,EAMlB,MAAM,iBAAiB,CAAA;AAExB,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAA;
|
|
1
|
+
{"version":3,"file":"emitters.d.ts","sourceRoot":"","sources":["../../../src/adapter/expr/emitters.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAGL,KAAK,iBAAiB,EACtB,KAAK,eAAe,EAGpB,KAAK,WAAW,EAChB,KAAK,WAAW,EAChB,KAAK,UAAU,EACf,KAAK,qBAAqB,EAC1B,KAAK,SAAS,EACd,KAAK,YAAY,EAMlB,MAAM,iBAAiB,CAAA;AAExB,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAA;AAgD3D;;;;;;;;;;GAUG;AACH,qBAAa,mBAAoB,YAAW,iBAAiB;IAS3D,OAA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AC,KAAK,EAAE,YAAY,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,UAAU,KAAK,MAAM,GAAG,MAAM,CAoB9E;IAED,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE,KAAK,EAAE,UAAU,GAAG,MAAM,CAKlD;IAED,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAG1B;IAED,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CAEjD;IAED,aAAa,CAAC,UAAU,EAAE,qBAAqB,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,UAAU,KAAK,MAAM,GAAG,MAAM,CAoBxG;CACF"}
|
package/dist/adapter/index.js
CHANGED
|
@@ -187651,6 +187651,11 @@ var PREDICATE_METHODS = new Set([
|
|
|
187651
187651
|
"every",
|
|
187652
187652
|
"some"
|
|
187653
187653
|
]);
|
|
187654
|
+
function flattenPropsMember(object, property) {
|
|
187655
|
+
if (object.kind === "identifier" && object.name === "props")
|
|
187656
|
+
return `$${property}`;
|
|
187657
|
+
return null;
|
|
187658
|
+
}
|
|
187654
187659
|
|
|
187655
187660
|
class XslateFilterEmitter {
|
|
187656
187661
|
param;
|
|
@@ -187681,6 +187686,9 @@ class XslateFilterEmitter {
|
|
|
187681
187686
|
return String(value);
|
|
187682
187687
|
}
|
|
187683
187688
|
member(object, property, _computed, _optional, emit) {
|
|
187689
|
+
const flat = flattenPropsMember(object, property);
|
|
187690
|
+
if (flat !== null)
|
|
187691
|
+
return flat;
|
|
187684
187692
|
if (property === "length") {
|
|
187685
187693
|
return `$bf.length(${emit(object)})`;
|
|
187686
187694
|
}
|
|
@@ -187808,9 +187816,9 @@ class XslateTopLevelEmitter {
|
|
|
187808
187816
|
return String(value);
|
|
187809
187817
|
}
|
|
187810
187818
|
member(object, property, _computed, _optional, emit) {
|
|
187811
|
-
|
|
187812
|
-
|
|
187813
|
-
|
|
187819
|
+
const flat = flattenPropsMember(object, property);
|
|
187820
|
+
if (flat !== null)
|
|
187821
|
+
return flat;
|
|
187814
187822
|
if (object.kind === "identifier") {
|
|
187815
187823
|
const staticValue = this.ctx._resolveStaticRecordLiteral(object.name, property);
|
|
187816
187824
|
if (staticValue !== null)
|
|
@@ -188206,7 +188214,7 @@ function generateDerivedMemoSeed(ctx, ir) {
|
|
|
188206
188214
|
}
|
|
188207
188215
|
|
|
188208
188216
|
// src/adapter/props/prop-classes.ts
|
|
188209
|
-
import { collectLoopBoundNames } from "@barefootjs/jsx";
|
|
188217
|
+
import { collectLoopBoundNames, resolveBodyDestructuredPropAliases } from "@barefootjs/jsx";
|
|
188210
188218
|
|
|
188211
188219
|
// src/adapter/value/parsed-literal.ts
|
|
188212
188220
|
import { evalStringArrayJoin } from "@barefootjs/jsx";
|
|
@@ -188238,6 +188246,10 @@ function collectStringValueNames(ir) {
|
|
|
188238
188246
|
if (isStringTypeInfo(p.type))
|
|
188239
188247
|
names.add(p.name);
|
|
188240
188248
|
}
|
|
188249
|
+
for (const [local, callerKey] of resolveBodyDestructuredPropAliases(ir.metadata.localConstants ?? [], ir.metadata.propsObjectName)) {
|
|
188250
|
+
if (names.has(callerKey))
|
|
188251
|
+
names.add(local);
|
|
188252
|
+
}
|
|
188241
188253
|
for (const c of ir.metadata.localConstants) {
|
|
188242
188254
|
if (isStringTypeInfo(c.type ?? undefined) || isBareStringLiteral(c.value))
|
|
188243
188255
|
names.add(c.name);
|
|
@@ -46,6 +46,20 @@ export declare function collectNullableOptionalProps(ir: ComponentIR): Set<strin
|
|
|
46
46
|
* elsewhere in the component) but safe: the suppressed case just falls
|
|
47
47
|
* back to today's numeric `+` — the same, already-accepted residual as an
|
|
48
48
|
* unresolvable operand — never silently-wrong output.
|
|
49
|
+
*
|
|
50
|
+
* A bare-props-form component's BODY-destructured, RENAMED prop (`const {
|
|
51
|
+
* fallbackLabel: skipLabel } = props`, the #2788 alias family) has no
|
|
52
|
+
* `propsParams` entry of its own — `propsParams` only carries the TYPE-level,
|
|
53
|
+
* caller-facing names, and the local alias never appears there. Without the
|
|
54
|
+
* alias resolved here too, a string-typed prop referenced only under its
|
|
55
|
+
* local rename in a `+` concat (`greeting + skipLabel`) is invisible to this
|
|
56
|
+
* witness, so `isStringConcatBinary` falls through to numeric `+` instead of
|
|
57
|
+
* Kolon's `~` (#2894 sibling gap, surfaced by the `string-concat-plus-
|
|
58
|
+
* renamed-prop` fixture — same bug class as #2883/go-template's fix).
|
|
59
|
+
* `resolveBodyDestructuredPropAliases` already recognizes this exact
|
|
60
|
+
* destructuring shape; reusing it here keeps this one witness the single
|
|
61
|
+
* source of truth `_isStringValueName` reads, rather than growing a second,
|
|
62
|
+
* adapter-local alias lookup.
|
|
49
63
|
*/
|
|
50
64
|
export declare function collectStringValueNames(ir: ComponentIR): Set<string>;
|
|
51
65
|
//# sourceMappingURL=prop-classes.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prop-classes.d.ts","sourceRoot":"","sources":["../../../src/adapter/props/prop-classes.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,
|
|
1
|
+
{"version":3,"file":"prop-classes.d.ts","sourceRoot":"","sources":["../../../src/adapter/props/prop-classes.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAA6D,KAAK,WAAW,EAAE,MAAM,iBAAiB,CAAA;AAG7G;;;;;GAKG;AACH,wBAAgB,wBAAwB,CAAC,EAAE,EAAE,WAAW,GAAG,GAAG,CAAC,MAAM,CAAC,CAMrE;AAED;;;;;GAKG;AACH,wBAAgB,4BAA4B,CAAC,EAAE,EAAE,WAAW,GAAG,GAAG,CAAC,MAAM,CAAC,CAWzE;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AACH,wBAAgB,uBAAuB,CAAC,EAAE,EAAE,WAAW,GAAG,GAAG,CAAC,MAAM,CAAC,CAqBpE"}
|
package/dist/index.js
CHANGED
|
@@ -187651,6 +187651,11 @@ var PREDICATE_METHODS = new Set([
|
|
|
187651
187651
|
"every",
|
|
187652
187652
|
"some"
|
|
187653
187653
|
]);
|
|
187654
|
+
function flattenPropsMember(object, property) {
|
|
187655
|
+
if (object.kind === "identifier" && object.name === "props")
|
|
187656
|
+
return `$${property}`;
|
|
187657
|
+
return null;
|
|
187658
|
+
}
|
|
187654
187659
|
|
|
187655
187660
|
class XslateFilterEmitter {
|
|
187656
187661
|
param;
|
|
@@ -187681,6 +187686,9 @@ class XslateFilterEmitter {
|
|
|
187681
187686
|
return String(value);
|
|
187682
187687
|
}
|
|
187683
187688
|
member(object, property, _computed, _optional, emit) {
|
|
187689
|
+
const flat = flattenPropsMember(object, property);
|
|
187690
|
+
if (flat !== null)
|
|
187691
|
+
return flat;
|
|
187684
187692
|
if (property === "length") {
|
|
187685
187693
|
return `$bf.length(${emit(object)})`;
|
|
187686
187694
|
}
|
|
@@ -187808,9 +187816,9 @@ class XslateTopLevelEmitter {
|
|
|
187808
187816
|
return String(value);
|
|
187809
187817
|
}
|
|
187810
187818
|
member(object, property, _computed, _optional, emit) {
|
|
187811
|
-
|
|
187812
|
-
|
|
187813
|
-
|
|
187819
|
+
const flat = flattenPropsMember(object, property);
|
|
187820
|
+
if (flat !== null)
|
|
187821
|
+
return flat;
|
|
187814
187822
|
if (object.kind === "identifier") {
|
|
187815
187823
|
const staticValue = this.ctx._resolveStaticRecordLiteral(object.name, property);
|
|
187816
187824
|
if (staticValue !== null)
|
|
@@ -188206,7 +188214,7 @@ function generateDerivedMemoSeed(ctx, ir) {
|
|
|
188206
188214
|
}
|
|
188207
188215
|
|
|
188208
188216
|
// src/adapter/props/prop-classes.ts
|
|
188209
|
-
import { collectLoopBoundNames } from "@barefootjs/jsx";
|
|
188217
|
+
import { collectLoopBoundNames, resolveBodyDestructuredPropAliases } from "@barefootjs/jsx";
|
|
188210
188218
|
|
|
188211
188219
|
// src/adapter/value/parsed-literal.ts
|
|
188212
188220
|
import { evalStringArrayJoin } from "@barefootjs/jsx";
|
|
@@ -188238,6 +188246,10 @@ function collectStringValueNames(ir) {
|
|
|
188238
188246
|
if (isStringTypeInfo(p.type))
|
|
188239
188247
|
names.add(p.name);
|
|
188240
188248
|
}
|
|
188249
|
+
for (const [local, callerKey] of resolveBodyDestructuredPropAliases(ir.metadata.localConstants ?? [], ir.metadata.propsObjectName)) {
|
|
188250
|
+
if (names.has(callerKey))
|
|
188251
|
+
names.add(local);
|
|
188252
|
+
}
|
|
188241
188253
|
for (const c of ir.metadata.localConstants) {
|
|
188242
188254
|
if (isStringTypeInfo(c.type ?? undefined) || isBareStringLiteral(c.value))
|
|
188243
188255
|
names.add(c.name);
|
package/dist/vite.js
CHANGED
|
@@ -2175,6 +2175,20 @@ function propsDestructureBinding(p) {
|
|
|
2175
2175
|
const binding = callerKey === localName ? localName : `${isIdentifierName(callerKey) ? callerKey : JSON.stringify(callerKey)}: ${localName}`;
|
|
2176
2176
|
return p.defaultValue ? `${binding} = ${p.defaultValue}` : binding;
|
|
2177
2177
|
}
|
|
2178
|
+
function resolveBodyDestructuredPropAliases(localConstants, propsObjectName) {
|
|
2179
|
+
const aliases = new Map;
|
|
2180
|
+
if (propsObjectName === null)
|
|
2181
|
+
return aliases;
|
|
2182
|
+
for (const c of localConstants) {
|
|
2183
|
+
if (c.isModule)
|
|
2184
|
+
continue;
|
|
2185
|
+
const m = c.parsed;
|
|
2186
|
+
if (m?.kind === "member" && !m.computed && m.object.kind === "identifier" && m.object.name === propsObjectName) {
|
|
2187
|
+
aliases.set(c.name, m.property);
|
|
2188
|
+
}
|
|
2189
|
+
}
|
|
2190
|
+
return aliases;
|
|
2191
|
+
}
|
|
2178
2192
|
var EMPTY_SET = new Set;
|
|
2179
2193
|
|
|
2180
2194
|
// ../jsx/src/ir-to-client-js/csr-substitute.ts
|
|
@@ -3421,8 +3435,11 @@ function matchSearchParamsMethodCall(callee, args, localNames) {
|
|
|
3421
3435
|
// ../jsx/src/ir-to-client-js/prune-unused-prop-extractions.ts
|
|
3422
3436
|
import ts19 from "typescript";
|
|
3423
3437
|
|
|
3424
|
-
// ../jsx/src/ir-to-client-js/
|
|
3438
|
+
// ../jsx/src/ir-to-client-js/emit-reactive.ts
|
|
3425
3439
|
import ts20 from "typescript";
|
|
3440
|
+
|
|
3441
|
+
// ../jsx/src/ir-to-client-js/control-flow/plan/lazy-preamble.ts
|
|
3442
|
+
import ts21 from "typescript";
|
|
3426
3443
|
var NO_PREAMBLE = {
|
|
3427
3444
|
lazySafe: true,
|
|
3428
3445
|
facts: { declaredNames: new Set, freeNames: new Set }
|
|
@@ -3471,9 +3488,6 @@ var INERT_BINDING_GLOBALS = new Set([
|
|
|
3471
3488
|
"decodeURI"
|
|
3472
3489
|
]);
|
|
3473
3490
|
|
|
3474
|
-
// ../jsx/src/ir-to-client-js/emit-reactive.ts
|
|
3475
|
-
import ts21 from "typescript";
|
|
3476
|
-
|
|
3477
3491
|
// ../jsx/src/ir-to-client-js/control-flow/stringify/event-delegation.ts
|
|
3478
3492
|
var NON_BUBBLING_EVENTS = new Set([
|
|
3479
3493
|
"blur",
|
|
@@ -5629,6 +5643,11 @@ var PREDICATE_METHODS = new Set([
|
|
|
5629
5643
|
"every",
|
|
5630
5644
|
"some"
|
|
5631
5645
|
]);
|
|
5646
|
+
function flattenPropsMember(object, property) {
|
|
5647
|
+
if (object.kind === "identifier" && object.name === "props")
|
|
5648
|
+
return `$${property}`;
|
|
5649
|
+
return null;
|
|
5650
|
+
}
|
|
5632
5651
|
|
|
5633
5652
|
class XslateFilterEmitter {
|
|
5634
5653
|
param;
|
|
@@ -5659,6 +5678,9 @@ class XslateFilterEmitter {
|
|
|
5659
5678
|
return String(value);
|
|
5660
5679
|
}
|
|
5661
5680
|
member(object, property, _computed, _optional, emit) {
|
|
5681
|
+
const flat = flattenPropsMember(object, property);
|
|
5682
|
+
if (flat !== null)
|
|
5683
|
+
return flat;
|
|
5662
5684
|
if (property === "length") {
|
|
5663
5685
|
return `$bf.length(${emit(object)})`;
|
|
5664
5686
|
}
|
|
@@ -5786,9 +5808,9 @@ class XslateTopLevelEmitter {
|
|
|
5786
5808
|
return String(value);
|
|
5787
5809
|
}
|
|
5788
5810
|
member(object, property, _computed, _optional, emit) {
|
|
5789
|
-
|
|
5790
|
-
|
|
5791
|
-
|
|
5811
|
+
const flat = flattenPropsMember(object, property);
|
|
5812
|
+
if (flat !== null)
|
|
5813
|
+
return flat;
|
|
5792
5814
|
if (object.kind === "identifier") {
|
|
5793
5815
|
const staticValue = this.ctx._resolveStaticRecordLiteral(object.name, property);
|
|
5794
5816
|
if (staticValue !== null)
|
|
@@ -6207,6 +6229,10 @@ function collectStringValueNames(ir) {
|
|
|
6207
6229
|
if (isStringTypeInfo(p.type))
|
|
6208
6230
|
names.add(p.name);
|
|
6209
6231
|
}
|
|
6232
|
+
for (const [local, callerKey] of resolveBodyDestructuredPropAliases(ir.metadata.localConstants ?? [], ir.metadata.propsObjectName)) {
|
|
6233
|
+
if (names.has(callerKey))
|
|
6234
|
+
names.add(local);
|
|
6235
|
+
}
|
|
6210
6236
|
for (const c of ir.metadata.localConstants) {
|
|
6211
6237
|
if (isStringTypeInfo(c.type ?? undefined) || isBareStringLiteral(c.value))
|
|
6212
6238
|
names.add(c.name);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@barefootjs/xslate",
|
|
3
|
-
"version": "0.35.
|
|
3
|
+
"version": "0.35.3",
|
|
4
4
|
"description": "Text::Xslate (Kolon) adapter for BarefootJS — compiles IR to .tx templates and ships the Xslate rendering backend; runs under any PSGI/Plack app",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -55,7 +55,7 @@
|
|
|
55
55
|
"directory": "packages/adapter-xslate"
|
|
56
56
|
},
|
|
57
57
|
"dependencies": {
|
|
58
|
-
"@barefootjs/shared": "0.35.
|
|
58
|
+
"@barefootjs/shared": "0.35.3"
|
|
59
59
|
},
|
|
60
60
|
"peerDependencies": {
|
|
61
61
|
"@barefootjs/jsx": ">=0.2.0",
|
|
@@ -72,9 +72,9 @@
|
|
|
72
72
|
},
|
|
73
73
|
"devDependencies": {
|
|
74
74
|
"@barefootjs/adapter-tests": "0.1.0",
|
|
75
|
-
"@barefootjs/jsx": "0.35.
|
|
76
|
-
"@barefootjs/vite": "0.35.
|
|
77
|
-
"@barefootjs/client": "0.35.
|
|
75
|
+
"@barefootjs/jsx": "0.35.3",
|
|
76
|
+
"@barefootjs/vite": "0.35.3",
|
|
77
|
+
"@barefootjs/client": "0.35.3",
|
|
78
78
|
"typescript": "^5.0.0",
|
|
79
79
|
"vite": "^6.0.0"
|
|
80
80
|
}
|
|
@@ -759,3 +759,33 @@ export function Counter() {
|
|
|
759
759
|
expect(template).not.toContain('<link')
|
|
760
760
|
})
|
|
761
761
|
})
|
|
762
|
+
|
|
763
|
+
describe('XslateAdapter - collectStringValueNames resolves renamed body-destructured prop aliases (#2894)', () => {
|
|
764
|
+
// Sibling gap to #2883 (Mojolicious) and this same PR's go-template fix:
|
|
765
|
+
// a `+` concat against a bare-props-form BODY-destructured, RENAMED prop
|
|
766
|
+
// (`const { fallbackLabel: skipLabel } = props`, the #2788 alias family)
|
|
767
|
+
// had no witness in `collectStringValueNames`, so `isStringConcatBinary`
|
|
768
|
+
// fell through to Kolon's numeric `+` instead of `~` — Kolon's `+`
|
|
769
|
+
// coerces a non-numeric string operand to `0` (#2176).
|
|
770
|
+
test('a `+` concat against a renamed body-destructured prop lowers to ~, not numeric +', () => {
|
|
771
|
+
const result = compileAndGenerate(`
|
|
772
|
+
'use client'
|
|
773
|
+
import { createSignal } from '@barefootjs/client'
|
|
774
|
+
|
|
775
|
+
type Todo = { id: number; label: string }
|
|
776
|
+
|
|
777
|
+
export function ConcatRenamedProp(props: { fallbackLabel: string }) {
|
|
778
|
+
const { fallbackLabel: skipLabel } = props
|
|
779
|
+
const [todos] = createSignal<Todo[]>([{ id: 1, label: 'Alpha' }])
|
|
780
|
+
return (
|
|
781
|
+
<ul>
|
|
782
|
+
{todos().map(t => (
|
|
783
|
+
<li key={t.id}>{t.label + skipLabel}</li>
|
|
784
|
+
))}
|
|
785
|
+
</ul>
|
|
786
|
+
)
|
|
787
|
+
}
|
|
788
|
+
`)
|
|
789
|
+
expect(result.template).toContain('$t.label ~ $skipLabel')
|
|
790
|
+
})
|
|
791
|
+
})
|
|
@@ -64,6 +64,21 @@ const PREDICATE_METHODS = new Set<HigherOrderMethod>([
|
|
|
64
64
|
'filter', 'find', 'findIndex', 'findLast', 'findLastIndex', 'every', 'some',
|
|
65
65
|
])
|
|
66
66
|
|
|
67
|
+
/**
|
|
68
|
+
* `props.x` on a bare-props-form component flattens to the bare `$x` the
|
|
69
|
+
* SSR caller binds each prop to (props arrive as individual top-level vars,
|
|
70
|
+
* not a `$props` hashref). Single door for BOTH `member()` emitters below
|
|
71
|
+
* (#2886) — `XslateFilterEmitter` lacked this decision entirely (#2879's
|
|
72
|
+
* cross-adapter follow-up), silently reaching `$props.x`, and `$props` is
|
|
73
|
+
* nil at runtime (silent — every row is kept instead of filtered). Returns
|
|
74
|
+
* null for any other receiver so callers fall through to their generic
|
|
75
|
+
* member lowering — `props.a.b` flattens only the inner hop.
|
|
76
|
+
*/
|
|
77
|
+
function flattenPropsMember(object: ParsedExpr, property: string): string | null {
|
|
78
|
+
if (object.kind === 'identifier' && object.name === 'props') return `$${property}`
|
|
79
|
+
return null
|
|
80
|
+
}
|
|
81
|
+
|
|
67
82
|
/**
|
|
68
83
|
* Lowering for the predicate body of a filter / every / some / find, plus the
|
|
69
84
|
* same shape used by `renderBlockBodyCondition` for complex block-body
|
|
@@ -119,6 +134,8 @@ export class XslateFilterEmitter implements ParsedExprEmitter {
|
|
|
119
134
|
}
|
|
120
135
|
|
|
121
136
|
member(object: ParsedExpr, property: string, _computed: boolean, _optional: boolean, emit: (e: ParsedExpr) => string): string {
|
|
137
|
+
const flat = flattenPropsMember(object, property)
|
|
138
|
+
if (flat !== null) return flat
|
|
122
139
|
// `.length` — route through `$bf.length` (handles both array element
|
|
123
140
|
// count and string char count, JS-compatibly). Kolon's builtin `.size()`
|
|
124
141
|
// is array-only and faults on a string.
|
|
@@ -323,11 +340,8 @@ export class XslateTopLevelEmitter implements ParsedExprEmitter {
|
|
|
323
340
|
}
|
|
324
341
|
|
|
325
342
|
member(object: ParsedExpr, property: string, _computed: boolean, _optional: boolean, emit: (e: ParsedExpr) => string): string {
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
if (object.kind === 'identifier' && object.name === 'props') {
|
|
329
|
-
return `$${property}`
|
|
330
|
-
}
|
|
343
|
+
const flat = flattenPropsMember(object, property)
|
|
344
|
+
if (flat !== null) return flat
|
|
331
345
|
// Static property access on a module object-literal const
|
|
332
346
|
// (`variantClasses.ghost`, #1897) resolves at compile time — the
|
|
333
347
|
// generic dot lowering below would reference a Kolon var that
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* adapter's `props/prop-types.ts`. No adapter instance state.
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
import { collectLoopBoundNames, type ComponentIR } from '@barefootjs/jsx'
|
|
10
|
+
import { collectLoopBoundNames, resolveBodyDestructuredPropAliases, type ComponentIR } from '@barefootjs/jsx'
|
|
11
11
|
import { isStringTypeInfo, isBareStringLiteral } from '../value/parsed-literal.ts'
|
|
12
12
|
|
|
13
13
|
/**
|
|
@@ -68,6 +68,20 @@ export function collectNullableOptionalProps(ir: ComponentIR): Set<string> {
|
|
|
68
68
|
* elsewhere in the component) but safe: the suppressed case just falls
|
|
69
69
|
* back to today's numeric `+` — the same, already-accepted residual as an
|
|
70
70
|
* unresolvable operand — never silently-wrong output.
|
|
71
|
+
*
|
|
72
|
+
* A bare-props-form component's BODY-destructured, RENAMED prop (`const {
|
|
73
|
+
* fallbackLabel: skipLabel } = props`, the #2788 alias family) has no
|
|
74
|
+
* `propsParams` entry of its own — `propsParams` only carries the TYPE-level,
|
|
75
|
+
* caller-facing names, and the local alias never appears there. Without the
|
|
76
|
+
* alias resolved here too, a string-typed prop referenced only under its
|
|
77
|
+
* local rename in a `+` concat (`greeting + skipLabel`) is invisible to this
|
|
78
|
+
* witness, so `isStringConcatBinary` falls through to numeric `+` instead of
|
|
79
|
+
* Kolon's `~` (#2894 sibling gap, surfaced by the `string-concat-plus-
|
|
80
|
+
* renamed-prop` fixture — same bug class as #2883/go-template's fix).
|
|
81
|
+
* `resolveBodyDestructuredPropAliases` already recognizes this exact
|
|
82
|
+
* destructuring shape; reusing it here keeps this one witness the single
|
|
83
|
+
* source of truth `_isStringValueName` reads, rather than growing a second,
|
|
84
|
+
* adapter-local alias lookup.
|
|
71
85
|
*/
|
|
72
86
|
export function collectStringValueNames(ir: ComponentIR): Set<string> {
|
|
73
87
|
const names = new Set<string>()
|
|
@@ -79,6 +93,12 @@ export function collectStringValueNames(ir: ComponentIR): Set<string> {
|
|
|
79
93
|
for (const p of ir.metadata.propsParams) {
|
|
80
94
|
if (isStringTypeInfo(p.type)) names.add(p.name)
|
|
81
95
|
}
|
|
96
|
+
for (const [local, callerKey] of resolveBodyDestructuredPropAliases(
|
|
97
|
+
ir.metadata.localConstants ?? [],
|
|
98
|
+
ir.metadata.propsObjectName,
|
|
99
|
+
)) {
|
|
100
|
+
if (names.has(callerKey)) names.add(local)
|
|
101
|
+
}
|
|
82
102
|
for (const c of ir.metadata.localConstants) {
|
|
83
103
|
if (isStringTypeInfo(c.type ?? undefined) || isBareStringLiteral(c.value)) names.add(c.name)
|
|
84
104
|
}
|