@barefootjs/blade 0.18.4 → 0.18.7
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/blade-adapter.d.ts +56 -0
- package/dist/adapter/blade-adapter.d.ts.map +1 -1
- package/dist/adapter/expr/array-method.d.ts.map +1 -1
- package/dist/adapter/expr/emitters.d.ts +2 -2
- package/dist/adapter/expr/emitters.d.ts.map +1 -1
- package/dist/adapter/index.js +129 -18
- package/dist/adapter/lib/constants.d.ts.map +1 -1
- package/dist/adapter/lib/static-value.d.ts +13 -0
- package/dist/adapter/lib/static-value.d.ts.map +1 -0
- package/dist/adapter/props/prop-classes.d.ts +26 -9
- package/dist/adapter/props/prop-classes.d.ts.map +1 -1
- package/dist/build.js +129 -18
- package/dist/conformance-pins.d.ts.map +1 -1
- package/dist/index.js +132 -38
- package/dist/render-divergences.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/__tests__/blade-adapter-unit.test.ts +141 -0
- package/src/adapter/blade-adapter.ts +180 -12
- package/src/adapter/expr/array-method.ts +19 -0
- package/src/adapter/expr/emitters.ts +2 -2
- package/src/adapter/lib/constants.ts +3 -0
- package/src/adapter/lib/static-value.ts +39 -0
- package/src/adapter/props/prop-classes.ts +30 -9
- package/src/conformance-pins.ts +25 -33
- package/src/render-divergences.ts +4 -16
- package/src/test-render.ts +10 -119
package/dist/index.js
CHANGED
|
@@ -187308,7 +187308,13 @@ import {
|
|
|
187308
187308
|
prepareLoweringMatchers,
|
|
187309
187309
|
queryHrefArgs,
|
|
187310
187310
|
sortComparatorFromArrow as sortComparatorFromArrow2,
|
|
187311
|
-
isValidHelperId
|
|
187311
|
+
isValidHelperId,
|
|
187312
|
+
isDangerousInnerHtmlAttr,
|
|
187313
|
+
resolveDangerousInnerHtml,
|
|
187314
|
+
dangerousInnerHtmlMetacharViolation,
|
|
187315
|
+
dangerousInnerHtmlDiagnostic,
|
|
187316
|
+
resolveStaticLoopSource,
|
|
187317
|
+
collectLoopBoundNames as collectLoopBoundNames2
|
|
187312
187318
|
} from "@barefootjs/jsx";
|
|
187313
187319
|
|
|
187314
187320
|
// src/adapter/boolean-result.ts
|
|
@@ -187369,7 +187375,7 @@ function isAriaBooleanAttr(name) {
|
|
|
187369
187375
|
}
|
|
187370
187376
|
|
|
187371
187377
|
// src/adapter/blade-adapter.ts
|
|
187372
|
-
import { BF_SLOT, BF_COND, BF_REGION } from "@barefootjs/shared";
|
|
187378
|
+
import { BF_SLOT, BF_COND, BF_REGION, escapeHtml } from "@barefootjs/shared";
|
|
187373
187379
|
|
|
187374
187380
|
// src/adapter/lib/constants.ts
|
|
187375
187381
|
var BLADE_TEMPLATE_PRIMITIVES = {
|
|
@@ -187378,7 +187384,10 @@ var BLADE_TEMPLATE_PRIMITIVES = {
|
|
|
187378
187384
|
Number: { arity: 1, emit: (args) => `$bf->number(${args[0]})` },
|
|
187379
187385
|
"Math.floor": { arity: 1, emit: (args) => `$bf->floor(${args[0]})` },
|
|
187380
187386
|
"Math.ceil": { arity: 1, emit: (args) => `$bf->ceil(${args[0]})` },
|
|
187381
|
-
"Math.round": { arity: 1, emit: (args) => `$bf->round(${args[0]})` }
|
|
187387
|
+
"Math.round": { arity: 1, emit: (args) => `$bf->round(${args[0]})` },
|
|
187388
|
+
"Math.min": { arity: 2, emit: (args) => `$bf->min(${args[0]}, ${args[1]})` },
|
|
187389
|
+
"Math.max": { arity: 2, emit: (args) => `$bf->max(${args[0]}, ${args[1]})` },
|
|
187390
|
+
"Math.abs": { arity: 1, emit: (args) => `$bf->abs(${args[0]})` }
|
|
187382
187391
|
};
|
|
187383
187392
|
var BLADE_PRIMITIVE_EMIT_MAP = Object.fromEntries(Object.entries(BLADE_TEMPLATE_PRIMITIVES).map(([k, v]) => [k, v.emit]));
|
|
187384
187393
|
|
|
@@ -187512,6 +187521,12 @@ function renderArrayMethod(method, object, args, emit) {
|
|
|
187512
187521
|
const recv = emit(object);
|
|
187513
187522
|
return `$bf->trim(${recv})`;
|
|
187514
187523
|
}
|
|
187524
|
+
case "trimStart":
|
|
187525
|
+
case "trimEnd": {
|
|
187526
|
+
const fn = method === "trimStart" ? "trim_start" : "trim_end";
|
|
187527
|
+
const recv = emit(object);
|
|
187528
|
+
return `$bf->${fn}(${recv})`;
|
|
187529
|
+
}
|
|
187515
187530
|
case "toFixed": {
|
|
187516
187531
|
const recv = emit(object);
|
|
187517
187532
|
const digits = args.length >= 1 ? emit(args[0]) : "0";
|
|
@@ -187545,6 +187560,12 @@ function renderArrayMethod(method, object, args, emit) {
|
|
|
187545
187560
|
const newS = emit(args[1]);
|
|
187546
187561
|
return `$bf->replace(${recv}, ${oldS}, ${newS})`;
|
|
187547
187562
|
}
|
|
187563
|
+
case "replaceAll": {
|
|
187564
|
+
const recv = emit(object);
|
|
187565
|
+
const oldS = emit(args[0]);
|
|
187566
|
+
const newS = emit(args[1]);
|
|
187567
|
+
return `$bf->replace_all(${recv}, ${oldS}, ${newS})`;
|
|
187568
|
+
}
|
|
187548
187569
|
case "repeat": {
|
|
187549
187570
|
const recv = emit(object);
|
|
187550
187571
|
const count = args.length === 0 ? "0" : emit(args[0]);
|
|
@@ -187639,6 +187660,39 @@ function renderFlatMethod(recv, depth, emit) {
|
|
|
187639
187660
|
return `$bf->flat(${recv}, ${d})`;
|
|
187640
187661
|
}
|
|
187641
187662
|
|
|
187663
|
+
// src/adapter/lib/static-value.ts
|
|
187664
|
+
function staticValueToBlade(value) {
|
|
187665
|
+
if (value === null || value === undefined)
|
|
187666
|
+
return "null";
|
|
187667
|
+
if (typeof value === "boolean")
|
|
187668
|
+
return value ? "true" : "false";
|
|
187669
|
+
if (typeof value === "number")
|
|
187670
|
+
return String(value);
|
|
187671
|
+
if (typeof value === "string")
|
|
187672
|
+
return `'${escapeBladeSingleQuoted(value)}'`;
|
|
187673
|
+
if (Array.isArray(value)) {
|
|
187674
|
+
const items = [];
|
|
187675
|
+
for (const el of value) {
|
|
187676
|
+
const serialized = staticValueToBlade(el);
|
|
187677
|
+
if (serialized === null)
|
|
187678
|
+
return null;
|
|
187679
|
+
items.push(serialized);
|
|
187680
|
+
}
|
|
187681
|
+
return `[${items.join(", ")}]`;
|
|
187682
|
+
}
|
|
187683
|
+
if (typeof value === "object") {
|
|
187684
|
+
const entries = [];
|
|
187685
|
+
for (const [key, val] of Object.entries(value)) {
|
|
187686
|
+
const serialized = staticValueToBlade(val);
|
|
187687
|
+
if (serialized === null)
|
|
187688
|
+
return null;
|
|
187689
|
+
entries.push(`${bladeHashKey(key)} => ${serialized}`);
|
|
187690
|
+
}
|
|
187691
|
+
return `[${entries.join(", ")}]`;
|
|
187692
|
+
}
|
|
187693
|
+
return null;
|
|
187694
|
+
}
|
|
187695
|
+
|
|
187642
187696
|
// src/adapter/expr/emitters.ts
|
|
187643
187697
|
import {
|
|
187644
187698
|
groupBinaryOperand,
|
|
@@ -187688,7 +187742,7 @@ class BladeFilterEmitter {
|
|
|
187688
187742
|
return "null";
|
|
187689
187743
|
return String(value);
|
|
187690
187744
|
}
|
|
187691
|
-
member(object, property, _computed, emit) {
|
|
187745
|
+
member(object, property, _computed, _optional, emit) {
|
|
187692
187746
|
if (property === "length") {
|
|
187693
187747
|
return `$bf->length(${emit(object)})`;
|
|
187694
187748
|
}
|
|
@@ -187799,7 +187853,7 @@ class BladeTopLevelEmitter {
|
|
|
187799
187853
|
return "null";
|
|
187800
187854
|
return String(value);
|
|
187801
187855
|
}
|
|
187802
|
-
member(object, property, _computed, emit) {
|
|
187856
|
+
member(object, property, _computed, _optional, emit) {
|
|
187803
187857
|
if (object.kind === "identifier" && object.name === "props") {
|
|
187804
187858
|
return bladeVar(property);
|
|
187805
187859
|
}
|
|
@@ -188178,6 +188232,9 @@ function generateDerivedMemoSeed(ctx, ir) {
|
|
|
188178
188232
|
` : "";
|
|
188179
188233
|
}
|
|
188180
188234
|
|
|
188235
|
+
// src/adapter/props/prop-classes.ts
|
|
188236
|
+
import { collectLoopBoundNames } from "@barefootjs/jsx";
|
|
188237
|
+
|
|
188181
188238
|
// src/adapter/value/parsed-literal.ts
|
|
188182
188239
|
import { evalStringArrayJoin } from "@barefootjs/jsx";
|
|
188183
188240
|
function isStringTypeInfo(type2) {
|
|
@@ -188208,6 +188265,12 @@ function collectStringValueNames(ir) {
|
|
|
188208
188265
|
if (isStringTypeInfo(p.type))
|
|
188209
188266
|
names.add(p.name);
|
|
188210
188267
|
}
|
|
188268
|
+
for (const c of ir.metadata.localConstants) {
|
|
188269
|
+
if (isStringTypeInfo(c.type ?? undefined) || isBareStringLiteral(c.value))
|
|
188270
|
+
names.add(c.name);
|
|
188271
|
+
}
|
|
188272
|
+
for (const bound of collectLoopBoundNames(ir))
|
|
188273
|
+
names.delete(bound);
|
|
188211
188274
|
return names;
|
|
188212
188275
|
}
|
|
188213
188276
|
|
|
@@ -188223,6 +188286,7 @@ class BladeAdapter extends BaseAdapter {
|
|
|
188223
188286
|
options;
|
|
188224
188287
|
errors = [];
|
|
188225
188288
|
inLoop = false;
|
|
188289
|
+
currentLoopKeyDepth = 0;
|
|
188226
188290
|
propsObjectName = null;
|
|
188227
188291
|
propsParams = [];
|
|
188228
188292
|
booleanTypedProps = new Set;
|
|
@@ -188231,6 +188295,7 @@ class BladeAdapter extends BaseAdapter {
|
|
|
188231
188295
|
_searchParamsLocals = new Set;
|
|
188232
188296
|
_loweringMatchers = [];
|
|
188233
188297
|
localConstants = [];
|
|
188298
|
+
staticLoopSourceBoundNames = new Set;
|
|
188234
188299
|
nullableOptionalProps = new Set;
|
|
188235
188300
|
constructor(options = {}) {
|
|
188236
188301
|
super();
|
|
@@ -188246,6 +188311,7 @@ class BladeAdapter extends BaseAdapter {
|
|
|
188246
188311
|
this.propsParams = ir.metadata.propsParams.map((p) => ({ name: p.name }));
|
|
188247
188312
|
this.booleanTypedProps = collectBooleanTypedProps(ir);
|
|
188248
188313
|
this.localConstants = ir.metadata.localConstants ?? [];
|
|
188314
|
+
this.staticLoopSourceBoundNames = collectLoopBoundNames2(ir);
|
|
188249
188315
|
this.nullableOptionalProps = collectNullableOptionalProps(ir);
|
|
188250
188316
|
this.stringValueNames = collectStringValueNames(ir);
|
|
188251
188317
|
this.moduleStringConsts = collectModuleStringConsts(ir.metadata.localConstants);
|
|
@@ -188299,7 +188365,7 @@ class BladeAdapter extends BaseAdapter {
|
|
|
188299
188365
|
return this.renderElement(node);
|
|
188300
188366
|
}
|
|
188301
188367
|
emitText(node) {
|
|
188302
|
-
return node.value;
|
|
188368
|
+
return escapeHtml(node.value);
|
|
188303
188369
|
}
|
|
188304
188370
|
emitExpression(node) {
|
|
188305
188371
|
return this.renderExpression(node);
|
|
@@ -188367,7 +188433,8 @@ class BladeAdapter extends BaseAdapter {
|
|
|
188367
188433
|
renderElement(element) {
|
|
188368
188434
|
const tag = element.tag;
|
|
188369
188435
|
const attrs = this.renderAttributes(element);
|
|
188370
|
-
const
|
|
188436
|
+
const dangerousHtml = this.renderDangerousInnerHtml(element);
|
|
188437
|
+
const children = dangerousHtml !== null ? dangerousHtml : this.renderChildren(element.children);
|
|
188371
188438
|
let hydrationAttrs = "";
|
|
188372
188439
|
if (element.needsScope) {
|
|
188373
188440
|
hydrationAttrs += ` ${this.renderScopeMarker("")}`;
|
|
@@ -188402,6 +188469,22 @@ class BladeAdapter extends BaseAdapter {
|
|
|
188402
188469
|
}
|
|
188403
188470
|
return `<${tag}${attrs}${hydrationAttrs}>${children}</${tag}>`;
|
|
188404
188471
|
}
|
|
188472
|
+
renderDangerousInnerHtml(element) {
|
|
188473
|
+
const resolution = resolveDangerousInnerHtml(element);
|
|
188474
|
+
if (!resolution)
|
|
188475
|
+
return null;
|
|
188476
|
+
if (resolution.kind === "dynamic") {
|
|
188477
|
+
this.errors.push(dangerousInnerHtmlDiagnostic(resolution.expr, resolution.loc));
|
|
188478
|
+
return "";
|
|
188479
|
+
}
|
|
188480
|
+
const violation = dangerousInnerHtmlMetacharViolation(resolution.html, this.name);
|
|
188481
|
+
if (violation) {
|
|
188482
|
+
const attr = element.attrs.find(isDangerousInnerHtmlAttr);
|
|
188483
|
+
this.errors.push(dangerousInnerHtmlDiagnostic(`{ __html: ${JSON.stringify(resolution.html)} }`, attr.loc, violation));
|
|
188484
|
+
return "";
|
|
188485
|
+
}
|
|
188486
|
+
return resolution.html;
|
|
188487
|
+
}
|
|
188405
188488
|
renderExpression(expr) {
|
|
188406
188489
|
if (expr.clientOnly) {
|
|
188407
188490
|
if (expr.slotId) {
|
|
@@ -188409,7 +188492,7 @@ class BladeAdapter extends BaseAdapter {
|
|
|
188409
188492
|
}
|
|
188410
188493
|
return "";
|
|
188411
188494
|
}
|
|
188412
|
-
const bladeExpr = `$bf->string(${this.convertExpressionToBlade(expr.expr)})`;
|
|
188495
|
+
const bladeExpr = `$bf->string(${this.convertExpressionToBlade(expr.expr, expr.parsed)})`;
|
|
188413
188496
|
if (expr.slotId) {
|
|
188414
188497
|
return `{!! $bf->text_start("${expr.slotId}") !!}{!! e(${bladeExpr}) !!}{!! $bf->text_end() !!}`;
|
|
188415
188498
|
}
|
|
@@ -188500,8 +188583,12 @@ ${whenTrue}
|
|
|
188500
188583
|
}
|
|
188501
188584
|
});
|
|
188502
188585
|
}
|
|
188586
|
+
const staticItems = resolveStaticLoopSource(loop.arrayParsed, this.localConstants, {
|
|
188587
|
+
isNameShadowed: (name) => this.staticLoopSourceBoundNames.has(name)
|
|
188588
|
+
});
|
|
188589
|
+
const staticArray = staticItems !== null ? staticValueToBlade(staticItems) : null;
|
|
188503
188590
|
const arrayName = loop.array.trim();
|
|
188504
|
-
if (/^[A-Za-z_$][\w$]*$/.test(arrayName)) {
|
|
188591
|
+
if (staticArray === null && /^[A-Za-z_$][\w$]*$/.test(arrayName)) {
|
|
188505
188592
|
const arrayConst = (this.localConstants ?? []).find((c) => c.name === arrayName);
|
|
188506
188593
|
if (arrayConst && !arrayConst.isModule && this._resolveLiteralConst(arrayName) === null) {
|
|
188507
188594
|
this.errors.push({
|
|
@@ -188515,7 +188602,7 @@ ${whenTrue}
|
|
|
188515
188602
|
});
|
|
188516
188603
|
}
|
|
188517
188604
|
}
|
|
188518
|
-
const rawArray = this.convertExpressionToBlade(loop.array);
|
|
188605
|
+
const rawArray = staticArray ?? this.convertExpressionToBlade(loop.array);
|
|
188519
188606
|
let array = rawArray;
|
|
188520
188607
|
if (loop.sortComparator) {
|
|
188521
188608
|
const sort = loop.sortComparator;
|
|
@@ -188529,7 +188616,7 @@ ${whenTrue}
|
|
|
188529
188616
|
const renderedChildren = this.renderChildren(loop.children);
|
|
188530
188617
|
const loopVar = loop.iterationShape === "keys" ? "__bf_item" : supportableDestructure ? "__bf_item" : param;
|
|
188531
188618
|
const indexLocalLines = [];
|
|
188532
|
-
if (loop.iterationShape === "keys") {
|
|
188619
|
+
if (loop.objectIteration) {} else if (loop.iterationShape === "keys") {
|
|
188533
188620
|
indexLocalLines.push(`@php(${bladeVar(param)} = $loop->index)`);
|
|
188534
188621
|
} else if (loop.index) {
|
|
188535
188622
|
indexLocalLines.push(`@php(${bladeVar(loop.index)} = $loop->index)`);
|
|
@@ -188550,13 +188637,17 @@ ${whenTrue}
|
|
|
188550
188637
|
}
|
|
188551
188638
|
const prevInLoop = this.inLoop;
|
|
188552
188639
|
this.inLoop = true;
|
|
188640
|
+
const prevLoopKeyDepth = this.currentLoopKeyDepth;
|
|
188641
|
+
this.currentLoopKeyDepth = loop.depth;
|
|
188553
188642
|
const childrenUnderLoop = this.renderChildren(loop.children);
|
|
188643
|
+
this.currentLoopKeyDepth = prevLoopKeyDepth;
|
|
188554
188644
|
this.inLoop = prevInLoop;
|
|
188555
188645
|
const bodyChildren = loop.bodyIsItemConditional && loop.key ? `{!! $bf->comment('loop-i:' . $bf->string(${this.convertExpressionToBlade(loop.key)})) !!}
|
|
188556
188646
|
${childrenUnderLoop}` : childrenUnderLoop;
|
|
188557
188647
|
const lines = [];
|
|
188558
188648
|
lines.push(`{!! $bf->comment("loop:${loop.markerId}") !!}`);
|
|
188559
|
-
|
|
188649
|
+
const forHeader = loop.objectIteration === "entries" ? `@foreach($bf->entries(${array} ?? []) as ${bladeVar(loop.index ?? param)} => ${bladeVar(param)})` : loop.objectIteration === "keys" ? `@foreach($bf->keys(${array} ?? []) as ${bladeVar(param)})` : loop.objectIteration === "values" ? `@foreach($bf->values(${array} ?? []) as ${bladeVar(param)})` : `@foreach((${array} ?? []) as ${bladeVar(loopVar)})`;
|
|
188650
|
+
lines.push(forHeader);
|
|
188560
188651
|
for (const il of indexLocalLines)
|
|
188561
188652
|
lines.push(il);
|
|
188562
188653
|
if (loop.filterPredicate) {
|
|
@@ -188626,9 +188717,22 @@ ${childrenUnderLoop}` : childrenUnderLoop;
|
|
|
188626
188717
|
renderComponent(comp) {
|
|
188627
188718
|
const segments = [{ kind: "entries", parts: [] }];
|
|
188628
188719
|
const currentEntries = () => this.componentPropSegmentEntries(segments);
|
|
188720
|
+
const namedSlotCaptures = [];
|
|
188629
188721
|
for (const p of comp.props) {
|
|
188630
188722
|
if ((p.name.match(/^on[A-Z]/) || p.name === "ref") && p.value.kind === "expression")
|
|
188631
188723
|
continue;
|
|
188724
|
+
if (p.value.kind === "jsx-children" && p.name !== "children") {
|
|
188725
|
+
const prevInLoop = this.inLoop;
|
|
188726
|
+
this.inLoop = false;
|
|
188727
|
+
const slotBody = this.renderChildren(p.value.children);
|
|
188728
|
+
this.inLoop = prevInLoop;
|
|
188729
|
+
const captureVar = bladeVar(`bf_prop_${this.childrenCaptureCounter++}`);
|
|
188730
|
+
namedSlotCaptures.push(`@php(ob_start())
|
|
188731
|
+
${slotBody}
|
|
188732
|
+
` + `@php(${captureVar} = $bf->backend->mark_raw(preg_replace('/\\n\\z/', '', ob_get_clean(), 1)))`);
|
|
188733
|
+
currentEntries().push(`${bladeHashKey(p.name)} => ${captureVar}`);
|
|
188734
|
+
continue;
|
|
188735
|
+
}
|
|
188632
188736
|
if (p.value.kind === "spread") {
|
|
188633
188737
|
const trimmed = p.value.expr.trim();
|
|
188634
188738
|
if (this.propsObjectName && this.propsObjectName === trimmed) {
|
|
@@ -188658,13 +188762,13 @@ ${childrenUnderLoop}` : childrenUnderLoop;
|
|
|
188658
188762
|
const captureVar = bladeVar(`bf_children_${comp.slotId ?? "c" + this.childrenCaptureCounter++}`);
|
|
188659
188763
|
currentEntries().push(`${bladeHashKey("children")} => ${captureVar}`);
|
|
188660
188764
|
const dict = this.combineComponentPropSegments(segments);
|
|
188661
|
-
return `@php(ob_start())
|
|
188765
|
+
return namedSlotCaptures.join("") + `@php(ob_start())
|
|
188662
188766
|
${childrenBody}
|
|
188663
188767
|
` + `@php(${captureVar} = $bf->backend->mark_raw(preg_replace('/\\n\\z/', '', ob_get_clean(), 1)))` + `{!! $bf->render_child('${tplName}', ${dict}) !!}`;
|
|
188664
188768
|
}
|
|
188665
188769
|
const isEmpty = segments.every((s) => s.kind === "entries" && s.parts.length === 0);
|
|
188666
188770
|
const dictEntries = isEmpty ? "" : `, ${this.combineComponentPropSegments(segments)}`;
|
|
188667
|
-
return
|
|
188771
|
+
return `${namedSlotCaptures.join("")}{!! $bf->render_child('${tplName}'${dictEntries}) !!}`;
|
|
188668
188772
|
}
|
|
188669
188773
|
childrenCaptureCounter = 0;
|
|
188670
188774
|
presenceVarCounter = 0;
|
|
@@ -188711,7 +188815,7 @@ ${fallback}
|
|
|
188711
188815
|
${children}`;
|
|
188712
188816
|
}
|
|
188713
188817
|
elementAttrEmitter = {
|
|
188714
|
-
emitLiteral: (value, name) => `${name}="${value.value}"`,
|
|
188818
|
+
emitLiteral: (value, name) => `${name}="${escapeHtml(value.value)}"`,
|
|
188715
188819
|
emitExpression: (value, name) => {
|
|
188716
188820
|
if (name === "style") {
|
|
188717
188821
|
const css = this.tryLowerStyleObject(value.expr);
|
|
@@ -188817,12 +188921,15 @@ ${name}="{!! e($bf->string(${val})) !!}"
|
|
|
188817
188921
|
for (const attr of element.attrs) {
|
|
188818
188922
|
if (attr.clientOnly)
|
|
188819
188923
|
continue;
|
|
188924
|
+
if (isDangerousInnerHtmlAttr(attr))
|
|
188925
|
+
continue;
|
|
188820
188926
|
let attrName;
|
|
188821
188927
|
if (attr.name === "className")
|
|
188822
188928
|
attrName = "class";
|
|
188823
|
-
else if (attr.name === "key")
|
|
188824
|
-
|
|
188825
|
-
|
|
188929
|
+
else if (attr.name === "key") {
|
|
188930
|
+
const depth = this.currentLoopKeyDepth;
|
|
188931
|
+
attrName = depth > 0 ? `data-key-${depth}` : "data-key";
|
|
188932
|
+
} else
|
|
188826
188933
|
attrName = attr.name;
|
|
188827
188934
|
const lowered = emitAttrValue(attr.value, this.elementAttrEmitter, attrName);
|
|
188828
188935
|
if (lowered)
|
|
@@ -189016,6 +189123,8 @@ Options:
|
|
|
189016
189123
|
return isBooleanResultExpr(expr) || isAriaBooleanAttr(name) || this.isBooleanTypedPropRef(expr);
|
|
189017
189124
|
}
|
|
189018
189125
|
_resolveLiteralConst(name) {
|
|
189126
|
+
if (this.staticLoopSourceBoundNames.has(name))
|
|
189127
|
+
return null;
|
|
189019
189128
|
const c = (this.localConstants ?? []).find((lc) => lc.name === name);
|
|
189020
189129
|
if (c?.value === undefined)
|
|
189021
189130
|
return null;
|
|
@@ -189028,6 +189137,8 @@ Options:
|
|
|
189028
189137
|
return null;
|
|
189029
189138
|
}
|
|
189030
189139
|
_resolveStaticRecordLiteral(objectName, key) {
|
|
189140
|
+
if (this.staticLoopSourceBoundNames.has(objectName))
|
|
189141
|
+
return null;
|
|
189031
189142
|
const hit = lookupStaticRecordLiteral(objectName, key, this.localConstants);
|
|
189032
189143
|
if (!hit)
|
|
189033
189144
|
return null;
|
|
@@ -189065,35 +189176,18 @@ Options:
|
|
|
189065
189176
|
var bladeAdapter = new BladeAdapter;
|
|
189066
189177
|
// src/conformance-pins.ts
|
|
189067
189178
|
var conformancePins = {
|
|
189068
|
-
"static-array-children": [{ code: "BF103", severity: "error" }],
|
|
189069
|
-
"todo-app": [{ code: "BF103", severity: "error" }],
|
|
189070
|
-
"todo-app-ssr": [{ code: "BF103", severity: "error" }],
|
|
189071
189179
|
"static-array-from-props": [{ code: "BF101", severity: "error" }],
|
|
189072
|
-
"static-array-from-props-with-component": [
|
|
189073
|
-
{ code: "BF103", severity: "error" },
|
|
189074
|
-
{ code: "BF101", severity: "error" }
|
|
189075
|
-
],
|
|
189180
|
+
"static-array-from-props-with-component": [{ code: "BF101", severity: "error" }],
|
|
189076
189181
|
"filter-nested-callback-predicate": [
|
|
189077
189182
|
{ code: "BF101", severity: "error", issue: "https://github.com/piconic-ai/barefootjs/issues/2038" }
|
|
189078
189183
|
],
|
|
189079
189184
|
"filter-nested-find-predicate": [
|
|
189080
189185
|
{ code: "BF101", severity: "error", issue: "https://github.com/piconic-ai/barefootjs/issues/2038" }
|
|
189081
189186
|
],
|
|
189082
|
-
"
|
|
189083
|
-
"dangerous-inner-html": [{ code: "BF101", severity: "error" }],
|
|
189084
|
-
"string-replaceall": [{ code: "BF101", severity: "error" }]
|
|
189187
|
+
"dangerous-inner-html-dynamic": [{ code: "BF101", severity: "error", issue: "https://github.com/piconic-ai/barefootjs/issues/2215" }]
|
|
189085
189188
|
};
|
|
189086
189189
|
// src/render-divergences.ts
|
|
189087
|
-
var renderDivergences = {
|
|
189088
|
-
"html-entity-text": "`©` in JSX literal text: Hono decodes to `©`, this adapter re-emits the raw entity — same DOM, different bytes",
|
|
189089
|
-
"math-methods": "Math.min/max/abs over a signal render empty (only Math.floor is in the template-primitive registry)",
|
|
189090
|
-
"static-attr-escape": 'static attribute values are not HTML-escaped (`title="Fish & Chips"` emitted raw; Hono escapes)',
|
|
189091
|
-
"object-entries-map": "`Object.entries(prop).map(([k, v]) => …)` renders an EMPTY list — the object-shaped prop silently produces zero iterations",
|
|
189092
|
-
"nested-loop-outer-binding": "nested-loop inner items carry `data-key` where the reference emits the depth-suffixed `data-key-1`",
|
|
189093
|
-
"jsx-element-prop": "a JSX element passed as a NON-children prop renders an empty slot — the element value is silently dropped",
|
|
189094
|
-
"string-slice": "`.slice()` on a STRING renders empty (array-slice helper misfires on strings)",
|
|
189095
|
-
"string-trim-sided": "`.trimStart()` / `.trimEnd()` render empty (no lowering)"
|
|
189096
|
-
};
|
|
189190
|
+
var renderDivergences = {};
|
|
189097
189191
|
export {
|
|
189098
189192
|
renderDivergences,
|
|
189099
189193
|
conformancePins,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"render-divergences.d.ts","sourceRoot":"","sources":["../src/render-divergences.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAA;AAExD,eAAO,MAAM,iBAAiB,EAAE,
|
|
1
|
+
{"version":3,"file":"render-divergences.d.ts","sourceRoot":"","sources":["../src/render-divergences.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAA;AAExD,eAAO,MAAM,iBAAiB,EAAE,iBAK/B,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@barefootjs/blade",
|
|
3
|
-
"version": "0.18.
|
|
3
|
+
"version": "0.18.7",
|
|
4
4
|
"description": "Laravel Blade (PHP) adapter for BarefootJS — compiles IR to .blade.php templates and ships the PHP BarefootJS rendering runtime on illuminate/view standalone",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -54,14 +54,14 @@
|
|
|
54
54
|
"directory": "packages/adapter-blade"
|
|
55
55
|
},
|
|
56
56
|
"dependencies": {
|
|
57
|
-
"@barefootjs/shared": "0.18.
|
|
57
|
+
"@barefootjs/shared": "0.18.7"
|
|
58
58
|
},
|
|
59
59
|
"peerDependencies": {
|
|
60
60
|
"@barefootjs/jsx": ">=0.2.0"
|
|
61
61
|
},
|
|
62
62
|
"devDependencies": {
|
|
63
63
|
"@barefootjs/adapter-tests": "0.1.0",
|
|
64
|
-
"@barefootjs/jsx": "0.18.
|
|
64
|
+
"@barefootjs/jsx": "0.18.7",
|
|
65
65
|
"typescript": "^5.0.0"
|
|
66
66
|
}
|
|
67
67
|
}
|
|
@@ -385,6 +385,147 @@ export function C(props: { count: number }) {
|
|
|
385
385
|
})
|
|
386
386
|
})
|
|
387
387
|
|
|
388
|
+
describe('BladeAdapter - named-slot capture identifier safety (#2168 jsx-element-prop)', () => {
|
|
389
|
+
// A JSX-valued prop under a hyphenated name (`data-slot`, a valid JSX
|
|
390
|
+
// attribute name) must not leak into the capture variable — `bladeIdent`
|
|
391
|
+
// only guards reserved words, not non-identifier characters like `-`, so
|
|
392
|
+
// a name-derived variable would emit invalid PHP. The capture variable is
|
|
393
|
+
// purely counter-based (never derived from the prop name); the hash KEY
|
|
394
|
+
// passed to `render_child` still carries the real name, quoted via
|
|
395
|
+
// `bladeHashKey`.
|
|
396
|
+
test('a hyphenated prop name does not appear in the capture variable', () => {
|
|
397
|
+
const { template } = compileAndGenerate(`
|
|
398
|
+
function Card(props) { return null }
|
|
399
|
+
export function Parent() {
|
|
400
|
+
return <Card data-slot={<strong>Title</strong>}>text</Card>
|
|
401
|
+
}
|
|
402
|
+
`)
|
|
403
|
+
expect(template).toContain('@php($bf_prop_0 = $bf->backend->mark_raw(')
|
|
404
|
+
expect(template).toContain("'data-slot' => $bf_prop_0")
|
|
405
|
+
expect(template).not.toContain('$bf_prop_data')
|
|
406
|
+
})
|
|
407
|
+
})
|
|
408
|
+
|
|
409
|
+
// #2221: `_resolveLiteralConst` is a flat name lookup against
|
|
410
|
+
// `ir.metadata.localConstants` with no notion of AST scope — it used to
|
|
411
|
+
// substitute an outer const's literal value even at an occurrence that is
|
|
412
|
+
// actually an enclosing loop callback's own (shadowing) parameter, so every
|
|
413
|
+
// iteration rendered the same hard-coded literal. Guarded with the same
|
|
414
|
+
// coarse `collectLoopBoundNames` exclusion as #2212: any name a loop binds
|
|
415
|
+
// anywhere in the component never inlines, falling back to the bare
|
|
416
|
+
// identifier.
|
|
417
|
+
describe('BladeAdapter - const inlining vs loop-param shadowing (#2221)', () => {
|
|
418
|
+
test('a loop param shadowing an outer literal const emits the identifier, not the const value', () => {
|
|
419
|
+
const { template } = compileAndGenerate(`
|
|
420
|
+
function Widget() {
|
|
421
|
+
const label: string = 'x'
|
|
422
|
+
return <ul>{[2, 5].map((label) => <li key={label}>{1 + label}</li>)}</ul>
|
|
423
|
+
}
|
|
424
|
+
`)
|
|
425
|
+
// The loop body must reference the per-iteration loop var...
|
|
426
|
+
expect(template).toContain('1 + $label')
|
|
427
|
+
// ...never the outer const's hard-coded value.
|
|
428
|
+
expect(template).not.toContain("1 + 'x'")
|
|
429
|
+
})
|
|
430
|
+
|
|
431
|
+
test('a numeric const shadowed by a loop param emits the identifier too', () => {
|
|
432
|
+
const { template } = compileAndGenerate(`
|
|
433
|
+
function Widget() {
|
|
434
|
+
const count = 7
|
|
435
|
+
return <ul>{[2, 5].map((count) => <li key={count}>{1 + count}</li>)}</ul>
|
|
436
|
+
}
|
|
437
|
+
`)
|
|
438
|
+
expect(template).toContain('1 + $count')
|
|
439
|
+
expect(template).not.toContain('1 + 7')
|
|
440
|
+
})
|
|
441
|
+
|
|
442
|
+
test('a literal const NOT shadowed by any loop still inlines (#1897 pin)', () => {
|
|
443
|
+
const { template } = compileAndGenerate(`
|
|
444
|
+
function Widget({ values }: { values: number[] }) {
|
|
445
|
+
const totalPages = 5
|
|
446
|
+
return <div>
|
|
447
|
+
<p>Page 1 of {1 + totalPages}</p>
|
|
448
|
+
<ul>{values.map((v) => <li key={v}>{v}</li>)}</ul>
|
|
449
|
+
</div>
|
|
450
|
+
}
|
|
451
|
+
`)
|
|
452
|
+
expect(template).toContain('1 + 5')
|
|
453
|
+
})
|
|
454
|
+
|
|
455
|
+
// The accepted coarse-exclusion trade-off (same as #2212): a name that is
|
|
456
|
+
// loop-bound ANYWHERE in the component never inlines, even at a genuinely
|
|
457
|
+
// non-shadowed occurrence outside the loop — the bare identifier is
|
|
458
|
+
// emitted instead of the value.
|
|
459
|
+
test('a const referenced outside the loop whose name is loop-bound elsewhere falls back to the identifier (accepted trade-off)', () => {
|
|
460
|
+
const { template } = compileAndGenerate(`
|
|
461
|
+
function Widget({ values }: { values: number[] }) {
|
|
462
|
+
const label: string = 'x'
|
|
463
|
+
return <div>
|
|
464
|
+
<p>{1 + label}</p>
|
|
465
|
+
<ul>{values.map((label) => <li key={label}>{2 + label}</li>)}</ul>
|
|
466
|
+
</div>
|
|
467
|
+
}
|
|
468
|
+
`)
|
|
469
|
+
expect(template).not.toContain("1 + 'x'")
|
|
470
|
+
expect(template).toContain('2 + $label')
|
|
471
|
+
})
|
|
472
|
+
})
|
|
473
|
+
|
|
474
|
+
// #2237: `_resolveStaticRecordLiteral` (`IDENT.key` on a module-scope
|
|
475
|
+
// object-literal const, e.g. `variantClasses.ghost` — #1896/#1897) is a
|
|
476
|
+
// flat name lookup on `objectName` with no notion of AST scope, the
|
|
477
|
+
// record-literal sibling of #2221's `_resolveLiteralConst` bug. It used to
|
|
478
|
+
// substitute the outer const's member value even at an occurrence that is
|
|
479
|
+
// actually an enclosing loop callback's own (shadowing) parameter, so every
|
|
480
|
+
// iteration rendered the same hard-coded literal instead of the per-item
|
|
481
|
+
// value. Guarded with the same coarse `staticLoopSourceBoundNames`
|
|
482
|
+
// exclusion as #2221: any name a loop binds anywhere in the component
|
|
483
|
+
// never inlines, falling back to the bare `data_get($cfg, 'x')` member
|
|
484
|
+
// expression.
|
|
485
|
+
describe('BladeAdapter - record-literal member lookup vs loop-param shadowing (#2237)', () => {
|
|
486
|
+
test('a loop param shadowing an outer module object const emits the member access, not the outer literal', () => {
|
|
487
|
+
const { template } = compileAndGenerate(`
|
|
488
|
+
const cfg = { x: 'outer-lit' }
|
|
489
|
+
function Widget({ rows }: { rows: { x: string }[] }) {
|
|
490
|
+
return <ul>{rows.map((cfg) => <li key={cfg.x}>{cfg.x}</li>)}</ul>
|
|
491
|
+
}
|
|
492
|
+
`)
|
|
493
|
+
// The loop body must reference the per-iteration member access...
|
|
494
|
+
expect(template).toContain("bf->string(data_get($cfg, 'x'))")
|
|
495
|
+
// ...never the outer const's hard-coded value.
|
|
496
|
+
expect(template).not.toContain("bf->string('outer-lit')")
|
|
497
|
+
})
|
|
498
|
+
|
|
499
|
+
test('a module object const NOT shadowed by any loop still inlines (variantClasses.ghost shape, #1896/#1897 pin)', () => {
|
|
500
|
+
const { template } = compileAndGenerate(`
|
|
501
|
+
const variantClasses = { solid: 'bg-solid', ghost: 'bg-ghost' }
|
|
502
|
+
function Widget({ variant }: { variant: 'solid' | 'ghost' }) {
|
|
503
|
+
return <div>{variantClasses.ghost}</div>
|
|
504
|
+
}
|
|
505
|
+
`)
|
|
506
|
+
expect(template).toContain("bf->string('bg-ghost')")
|
|
507
|
+
})
|
|
508
|
+
|
|
509
|
+
// The accepted coarse-exclusion trade-off (same as #2221/#2212): an
|
|
510
|
+
// object name that is loop-bound ANYWHERE in the component never
|
|
511
|
+
// inlines its member lookups, even at a genuinely non-shadowed
|
|
512
|
+
// occurrence outside the loop — the bare member expression is emitted
|
|
513
|
+
// instead of the value.
|
|
514
|
+
test('a record member referenced outside the loop whose object name is loop-bound elsewhere falls back to the member expression (accepted trade-off)', () => {
|
|
515
|
+
const { template } = compileAndGenerate(`
|
|
516
|
+
const cfg = { x: 'outer-lit' }
|
|
517
|
+
function Widget({ rows }: { rows: { x: string }[] }) {
|
|
518
|
+
return <div>
|
|
519
|
+
<p>{cfg.x}</p>
|
|
520
|
+
<ul>{rows.map((cfg) => <li key={cfg.x}>{cfg.x}</li>)}</ul>
|
|
521
|
+
</div>
|
|
522
|
+
}
|
|
523
|
+
`)
|
|
524
|
+
expect(template).not.toContain("bf->string('outer-lit')")
|
|
525
|
+
expect(template).toContain("bf->string(data_get($cfg, 'x'))")
|
|
526
|
+
})
|
|
527
|
+
})
|
|
528
|
+
|
|
388
529
|
// #2038 nested-callback-predicate loudness is pinned at the shared
|
|
389
530
|
// conformance layer (workstream C): `filter-nested-callback-predicate` /
|
|
390
531
|
// `filter-nested-find-predicate` (BF101 via `expectedDiagnostics`) and
|