@barefootjs/go-template 0.18.7 → 0.19.1
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/emit-context.d.ts +11 -5
- package/dist/adapter/emit-context.d.ts.map +1 -1
- package/dist/adapter/go-template-adapter.d.ts +45 -6
- package/dist/adapter/go-template-adapter.d.ts.map +1 -1
- package/dist/adapter/index.js +326 -38
- package/dist/adapter/lib/compile-state.d.ts +32 -0
- package/dist/adapter/lib/compile-state.d.ts.map +1 -1
- package/dist/adapter/lib/types.d.ts +9 -0
- package/dist/adapter/lib/types.d.ts.map +1 -1
- package/dist/adapter/memo/memo-compute.d.ts +8 -0
- package/dist/adapter/memo/memo-compute.d.ts.map +1 -1
- package/dist/adapter/props/prop-types.d.ts +97 -0
- package/dist/adapter/props/prop-types.d.ts.map +1 -1
- package/dist/adapter/value/value-lowering.d.ts +9 -1
- package/dist/adapter/value/value-lowering.d.ts.map +1 -1
- package/dist/build.js +326 -38
- package/dist/index.js +326 -38
- package/package.json +3 -3
- package/src/__tests__/derived-state-memo.test.ts +10 -3
- package/src/__tests__/go-template-adapter.test.ts +282 -23
- package/src/adapter/emit-context.ts +14 -5
- package/src/adapter/go-template-adapter.ts +291 -50
- package/src/adapter/lib/compile-state.ts +36 -0
- package/src/adapter/lib/types.ts +9 -0
- package/src/adapter/memo/memo-compute.ts +123 -9
- package/src/adapter/props/prop-types.ts +310 -1
- package/src/adapter/value/value-lowering.ts +58 -5
- package/src/test-render.ts +18 -4
package/dist/adapter/index.js
CHANGED
|
@@ -24,7 +24,7 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
|
|
|
24
24
|
// src/adapter/go-template-adapter.ts
|
|
25
25
|
import {
|
|
26
26
|
BaseAdapter,
|
|
27
|
-
isBooleanAttr,
|
|
27
|
+
isBooleanAttr as isBooleanAttr2,
|
|
28
28
|
parseExpression as parseExpression4,
|
|
29
29
|
stringifyParsedExpr as stringifyParsedExpr2,
|
|
30
30
|
parseStyleObjectEntries,
|
|
@@ -366,6 +366,10 @@ class CompileState {
|
|
|
366
366
|
hoistedMemoLocals = new Map;
|
|
367
367
|
loweringMatchers = [];
|
|
368
368
|
nillablePropNames = new Set;
|
|
369
|
+
nullishConsumedPropNames = new Set;
|
|
370
|
+
omittableAttrConsumedPropNames = new Set;
|
|
371
|
+
textConsumedPropNames = new Set;
|
|
372
|
+
presenceCheckedPropNames = new Set;
|
|
369
373
|
stringValueNames = new Set;
|
|
370
374
|
rootScopeNodes = new Set;
|
|
371
375
|
memoBackedLoopSlice = new Map;
|
|
@@ -1109,15 +1113,28 @@ function parsedLiteralToGo(ctx, expr, typeInfo) {
|
|
|
1109
1113
|
|
|
1110
1114
|
// src/adapter/value/value-lowering.ts
|
|
1111
1115
|
var EMPTY_PROP_FALLBACK_VARS = new Map;
|
|
1116
|
+
function nillableAwarePropRef(ctx, propName, expectedType) {
|
|
1117
|
+
const fieldRef = `in.${capitalizeFieldName(propName)}`;
|
|
1118
|
+
const scalar = expectedType.kind === "primitive" ? expectedType : expectedType.kind === "union" && expectedType.unionTypes?.length === 2 ? expectedType.unionTypes.find((t) => t.primitive !== "undefined" && t.primitive !== "null") : undefined;
|
|
1119
|
+
if (ctx.state.nillablePropNames.has(propName) && scalar?.kind === "primitive") {
|
|
1120
|
+
const goType = scalar.primitive === "boolean" ? "bool" : scalar.primitive === "number" ? "float64" : scalar.primitive === "string" ? "string" : null;
|
|
1121
|
+
if (goType) {
|
|
1122
|
+
const zero = goType === "bool" ? "false" : goType === "string" ? '""' : "0";
|
|
1123
|
+
return `func() ${goType} { if v, ok := ${fieldRef}.(${goType}); ok { return v }; return ${zero} }()`;
|
|
1124
|
+
}
|
|
1125
|
+
}
|
|
1126
|
+
return fieldRef;
|
|
1127
|
+
}
|
|
1112
1128
|
function convertInitialValue(ctx, value, typeInfo, propsParams, preParsed) {
|
|
1129
|
+
const propRef = (propName2) => nillableAwarePropRef(ctx, propName2, typeInfo);
|
|
1113
1130
|
if (/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(value)) {
|
|
1114
1131
|
if (propsParams?.some((p) => p.name === value)) {
|
|
1115
|
-
return
|
|
1132
|
+
return propRef(value);
|
|
1116
1133
|
}
|
|
1117
1134
|
}
|
|
1118
|
-
const propName = ctx.extractPropNameFromInitialValue(value);
|
|
1135
|
+
const propName = ctx.extractPropNameFromInitialValue(value, preParsed);
|
|
1119
1136
|
if (propName && propsParams?.some((p) => p.name === propName)) {
|
|
1120
|
-
return
|
|
1137
|
+
return propRef(propName);
|
|
1121
1138
|
}
|
|
1122
1139
|
if (typeInfo.kind === "primitive") {
|
|
1123
1140
|
if (typeInfo.primitive === "boolean") {
|
|
@@ -1184,19 +1201,20 @@ function objectLiteralToGoMap(ctx, expr) {
|
|
|
1184
1201
|
return null;
|
|
1185
1202
|
return `map[string]interface{}{${entries.join(", ")}}`;
|
|
1186
1203
|
}
|
|
1187
|
-
function getSignalInitialValueAsGo(ctx, initialValue, propsParams, propFallbackVars = EMPTY_PROP_FALLBACK_VARS) {
|
|
1204
|
+
function getSignalInitialValueAsGo(ctx, initialValue, propsParams, propFallbackVars = EMPTY_PROP_FALLBACK_VARS, signalType) {
|
|
1205
|
+
const propRef = (propName2) => signalType ? nillableAwarePropRef(ctx, propName2, signalType) : `in.${capitalizeFieldName(propName2)}`;
|
|
1188
1206
|
if (propsParams.some((p) => p.name === initialValue)) {
|
|
1189
1207
|
const hoisted = propFallbackVars.get(initialValue);
|
|
1190
1208
|
if (hoisted)
|
|
1191
1209
|
return hoisted.varName;
|
|
1192
|
-
return
|
|
1210
|
+
return propRef(initialValue);
|
|
1193
1211
|
}
|
|
1194
1212
|
const propName = ctx.extractPropNameFromInitialValue(initialValue);
|
|
1195
1213
|
if (propName && propsParams.some((p) => p.name === propName)) {
|
|
1196
1214
|
const hoisted = propFallbackVars.get(propName);
|
|
1197
1215
|
if (hoisted)
|
|
1198
1216
|
return hoisted.varName;
|
|
1199
|
-
return
|
|
1217
|
+
return propRef(propName);
|
|
1200
1218
|
}
|
|
1201
1219
|
if (/^-?\d+$/.test(initialValue)) {
|
|
1202
1220
|
return initialValue;
|
|
@@ -1666,9 +1684,34 @@ var EMPTY_PROP_FALLBACK_VARS2 = new Map;
|
|
|
1666
1684
|
function getterCallName(e) {
|
|
1667
1685
|
return e.kind === "call" && e.callee.kind === "identifier" && e.args.length === 0 ? e.callee.name : null;
|
|
1668
1686
|
}
|
|
1687
|
+
function isBooleanTypeInfo(t) {
|
|
1688
|
+
if (t.kind === "primitive")
|
|
1689
|
+
return t.primitive === "boolean";
|
|
1690
|
+
if (t.kind === "union" && t.unionTypes?.length === 2) {
|
|
1691
|
+
const scalar = t.unionTypes.find((u) => u.primitive !== "undefined" && u.primitive !== "null");
|
|
1692
|
+
return scalar?.kind === "primitive" && scalar.primitive === "boolean";
|
|
1693
|
+
}
|
|
1694
|
+
return false;
|
|
1695
|
+
}
|
|
1696
|
+
function isBooleanTypedGetter(ctx, name, signals) {
|
|
1697
|
+
const signal = signals.find((s) => s.getter === name);
|
|
1698
|
+
if (signal)
|
|
1699
|
+
return signal.type !== undefined && isBooleanTypeInfo(signal.type);
|
|
1700
|
+
const memo = (ctx.state.currentMemos ?? []).find((m) => m.name === name);
|
|
1701
|
+
return memo?.type !== undefined && isBooleanTypeInfo(memo.type);
|
|
1702
|
+
}
|
|
1669
1703
|
function propsMemberName(e) {
|
|
1670
1704
|
return e.kind === "member" && !e.computed && e.object.kind === "identifier" && e.object.name === "props" ? e.property : null;
|
|
1671
1705
|
}
|
|
1706
|
+
function propNameForPropsBinding(ctx, e) {
|
|
1707
|
+
const propsObject = ctx.state.propsObjectName;
|
|
1708
|
+
if (e.kind === "member" && !e.computed && e.object.kind === "identifier" && e.object.name === propsObject) {
|
|
1709
|
+
return e.property;
|
|
1710
|
+
}
|
|
1711
|
+
if (!propsObject && e.kind === "identifier")
|
|
1712
|
+
return e.name;
|
|
1713
|
+
return null;
|
|
1714
|
+
}
|
|
1672
1715
|
function matchFilterArmMemo(ctx, body, signals, propsParams) {
|
|
1673
1716
|
const cb = asCallbackMethodCall2(body);
|
|
1674
1717
|
if (!cb || cb.method !== "filter")
|
|
@@ -1807,6 +1850,17 @@ function memoInitialFromParsedBody(ctx, body, signals, propsParams, propFallback
|
|
|
1807
1850
|
if (propName)
|
|
1808
1851
|
return propRef(propName);
|
|
1809
1852
|
}
|
|
1853
|
+
if (body.kind === "binary" && (body.op === "!==" || body.op === "!=" || body.op === "===" || body.op === "==")) {
|
|
1854
|
+
const other = body.right.kind === "identifier" && body.right.name === "undefined" ? body.left : body.left.kind === "identifier" && body.left.name === "undefined" ? body.right : null;
|
|
1855
|
+
const propName = other ? propNameForPropsBinding(ctx, other) : null;
|
|
1856
|
+
if (propName) {
|
|
1857
|
+
const param = propsParams.find((p) => p.name === propName);
|
|
1858
|
+
if (param && ctx.state.nillablePropNames.has(propName)) {
|
|
1859
|
+
const isNe = body.op === "!==" || body.op === "!=";
|
|
1860
|
+
return `in.${capitalizeFieldName(propName)} ${isNe ? "!=" : "=="} nil`;
|
|
1861
|
+
}
|
|
1862
|
+
}
|
|
1863
|
+
}
|
|
1810
1864
|
if (body.kind === "conditional") {
|
|
1811
1865
|
const condName = getterCallName(body.test);
|
|
1812
1866
|
if (condName) {
|
|
@@ -1841,6 +1895,18 @@ function memoInitialFromParsedBody(ctx, body, signals, propsParams, propFallback
|
|
|
1841
1895
|
}
|
|
1842
1896
|
}
|
|
1843
1897
|
}
|
|
1898
|
+
if (condName) {
|
|
1899
|
+
const tName = getterCallName(body.consequent);
|
|
1900
|
+
const fName = getterCallName(body.alternate);
|
|
1901
|
+
if (tName && fName && isBooleanTypedGetter(ctx, tName, signals) && isBooleanTypedGetter(ctx, fName, signals)) {
|
|
1902
|
+
const condGo = resolveGetterValueAsGo(ctx, condName, signals, propsParams, propFallbackVars, resolving);
|
|
1903
|
+
const tGo = resolveGetterValueAsGo(ctx, tName, signals, propsParams, propFallbackVars, resolving);
|
|
1904
|
+
const fGo = resolveGetterValueAsGo(ctx, fName, signals, propsParams, propFallbackVars, resolving);
|
|
1905
|
+
if (condGo !== null && tGo !== null && fGo !== null) {
|
|
1906
|
+
return `func() bool { if ${condGo} { return ${tGo} }; return ${fGo} }()`;
|
|
1907
|
+
}
|
|
1908
|
+
}
|
|
1909
|
+
}
|
|
1844
1910
|
}
|
|
1845
1911
|
if (body.kind === "binary" && ["*", "+", "-", "/"].includes(body.op) && body.right.kind === "literal" && body.right.literalType === "number" && typeof body.right.value === "number" && Number.isInteger(body.right.value) && body.right.value >= 0) {
|
|
1846
1912
|
const operator = body.op;
|
|
@@ -1929,7 +1995,7 @@ function computeMemoInitialValueOrNull(ctx, memo, signals, propsParams, propFall
|
|
|
1929
1995
|
function resolveGetterValueAsGo(ctx, name, signals, propsParams, propFallbackVars, resolving = new Set) {
|
|
1930
1996
|
const signal = signals.find((s) => s.getter === name);
|
|
1931
1997
|
if (signal) {
|
|
1932
|
-
return getSignalInitialValueAsGo(ctx, signal.initialValue, propsParams, propFallbackVars);
|
|
1998
|
+
return getSignalInitialValueAsGo(ctx, signal.initialValue, propsParams, propFallbackVars, signal.type);
|
|
1933
1999
|
}
|
|
1934
2000
|
const memo = (ctx.state.currentMemos ?? []).find((m) => m.name === name);
|
|
1935
2001
|
if (memo) {
|
|
@@ -2259,11 +2325,12 @@ function recordIndexAccessToGoMap(ctx, val, ir) {
|
|
|
2259
2325
|
}
|
|
2260
2326
|
|
|
2261
2327
|
// src/adapter/props/prop-types.ts
|
|
2328
|
+
import { isBooleanAttr } from "@barefootjs/jsx";
|
|
2262
2329
|
function buildPropTypeOverrides(ctx, ir) {
|
|
2263
2330
|
const overrides = new Map;
|
|
2264
2331
|
for (const signal of ir.metadata.signals) {
|
|
2265
2332
|
const propNames = [signal.initialValue];
|
|
2266
|
-
const extracted = ctx.extractPropNameFromInitialValue(signal.initialValue);
|
|
2333
|
+
const extracted = ctx.extractPropNameFromInitialValue(signal.initialValue, signal.parsed);
|
|
2267
2334
|
if (extracted)
|
|
2268
2335
|
propNames.push(extracted);
|
|
2269
2336
|
for (const propName of propNames) {
|
|
@@ -2320,11 +2387,146 @@ function collectToFixedPropNames(root) {
|
|
|
2320
2387
|
walk(root);
|
|
2321
2388
|
return names;
|
|
2322
2389
|
}
|
|
2390
|
+
var NULLISH_SCALAR_GO_TYPES = new Set(["string", "int", "float64", "bool"]);
|
|
2391
|
+
function collectNullishConsumedPropNames(ctx, ir) {
|
|
2392
|
+
const names = new Set;
|
|
2393
|
+
const optionalParams = new Set(ir.metadata.propsParams.filter((p) => p.optional && p.defaultValue == null).map((p) => p.name));
|
|
2394
|
+
if (optionalParams.size === 0)
|
|
2395
|
+
return names;
|
|
2396
|
+
const propsObject = ctx.state.propsObjectName;
|
|
2397
|
+
const propNameOfLeft = (left) => {
|
|
2398
|
+
if (left.kind === "identifier")
|
|
2399
|
+
return left.name;
|
|
2400
|
+
if (left.kind === "member" && !left.computed && left.object.kind === "identifier") {
|
|
2401
|
+
if (left.object.name === propsObject)
|
|
2402
|
+
return left.property;
|
|
2403
|
+
return left.object.name;
|
|
2404
|
+
}
|
|
2405
|
+
return null;
|
|
2406
|
+
};
|
|
2407
|
+
const isZeroEquivalentLiteral = (right) => right.kind === "literal" && (right.value === "" || right.value === false || right.value === null || right.literalType === "number" && Number(right.value) === 0);
|
|
2408
|
+
const walk = (node) => {
|
|
2409
|
+
if (!node || typeof node !== "object")
|
|
2410
|
+
return;
|
|
2411
|
+
if (Array.isArray(node)) {
|
|
2412
|
+
for (const item of node)
|
|
2413
|
+
walk(item);
|
|
2414
|
+
return;
|
|
2415
|
+
}
|
|
2416
|
+
const rec = node;
|
|
2417
|
+
if (rec.kind === "logical" && rec.op === "??" && rec.left && rec.right) {
|
|
2418
|
+
const propName = propNameOfLeft(rec.left);
|
|
2419
|
+
if (propName && optionalParams.has(propName) && !isZeroEquivalentLiteral(rec.right)) {
|
|
2420
|
+
names.add(propName);
|
|
2421
|
+
}
|
|
2422
|
+
}
|
|
2423
|
+
for (const value of Object.values(rec))
|
|
2424
|
+
walk(value);
|
|
2425
|
+
};
|
|
2426
|
+
walk(ir.root);
|
|
2427
|
+
for (const signal of ir.metadata.signals) {
|
|
2428
|
+
const match = ctx.extractPropFallback(signal.initialValue, signal.parsed);
|
|
2429
|
+
if (!match || !optionalParams.has(match.propName))
|
|
2430
|
+
continue;
|
|
2431
|
+
const f = match.goFallback;
|
|
2432
|
+
if (f === '""' || f === "false" || f === "nil" || Number(f) === 0)
|
|
2433
|
+
continue;
|
|
2434
|
+
names.add(match.propName);
|
|
2435
|
+
}
|
|
2436
|
+
return names;
|
|
2437
|
+
}
|
|
2438
|
+
function collectOmittableAttrConsumedPropNames(ctx, ir) {
|
|
2439
|
+
const names = new Set;
|
|
2440
|
+
const optionalParams = new Set(ir.metadata.propsParams.filter((p) => p.optional && p.defaultValue == null).map((p) => p.name));
|
|
2441
|
+
if (optionalParams.size === 0)
|
|
2442
|
+
return names;
|
|
2443
|
+
const propsObject = ctx.state.propsObjectName;
|
|
2444
|
+
const walk = (node) => {
|
|
2445
|
+
if (!node || typeof node !== "object")
|
|
2446
|
+
return;
|
|
2447
|
+
if (Array.isArray(node)) {
|
|
2448
|
+
for (const item of node)
|
|
2449
|
+
walk(item);
|
|
2450
|
+
return;
|
|
2451
|
+
}
|
|
2452
|
+
const rec = node;
|
|
2453
|
+
if (rec.type === "element" && Array.isArray(rec.attrs)) {
|
|
2454
|
+
for (const attr of rec.attrs) {
|
|
2455
|
+
if (attr.name === "class" || attr.name === "className" || attr.name === "style")
|
|
2456
|
+
continue;
|
|
2457
|
+
if (isBooleanAttr(attr.name))
|
|
2458
|
+
continue;
|
|
2459
|
+
if (attr.value?.kind !== "expression" || attr.value.presenceOrUndefined)
|
|
2460
|
+
continue;
|
|
2461
|
+
const bareId = String(attr.value.expr ?? "").trim();
|
|
2462
|
+
const propName = propsObject && bareId.startsWith(`${propsObject}.`) ? bareId.slice(propsObject.length + 1) : bareId;
|
|
2463
|
+
if (/^[A-Za-z_$][\w$]*$/.test(propName) && optionalParams.has(propName)) {
|
|
2464
|
+
names.add(propName);
|
|
2465
|
+
}
|
|
2466
|
+
}
|
|
2467
|
+
}
|
|
2468
|
+
for (const value of Object.values(rec))
|
|
2469
|
+
walk(value);
|
|
2470
|
+
};
|
|
2471
|
+
walk(ir.root);
|
|
2472
|
+
return names;
|
|
2473
|
+
}
|
|
2474
|
+
function collectTextConsumedPropNames(ctx, ir) {
|
|
2475
|
+
const names = new Set;
|
|
2476
|
+
const optionalParams = new Set(ir.metadata.propsParams.filter((p) => p.optional && p.defaultValue == null && p.type.kind === "primitive").map((p) => p.name));
|
|
2477
|
+
if (optionalParams.size === 0)
|
|
2478
|
+
return names;
|
|
2479
|
+
const propsObject = ctx.state.propsObjectName;
|
|
2480
|
+
const walk = (node) => {
|
|
2481
|
+
if (!node || typeof node !== "object")
|
|
2482
|
+
return;
|
|
2483
|
+
if (Array.isArray(node)) {
|
|
2484
|
+
for (const item of node)
|
|
2485
|
+
walk(item);
|
|
2486
|
+
return;
|
|
2487
|
+
}
|
|
2488
|
+
const rec = node;
|
|
2489
|
+
if (rec.type === "expression") {
|
|
2490
|
+
const bareId = String(rec.expr ?? "").trim();
|
|
2491
|
+
const propName = propsObject && bareId.startsWith(`${propsObject}.`) ? bareId.slice(propsObject.length + 1) : bareId;
|
|
2492
|
+
if (/^[A-Za-z_$][\w$]*$/.test(propName) && optionalParams.has(propName)) {
|
|
2493
|
+
names.add(propName);
|
|
2494
|
+
}
|
|
2495
|
+
}
|
|
2496
|
+
for (const value of Object.values(rec))
|
|
2497
|
+
walk(value);
|
|
2498
|
+
};
|
|
2499
|
+
walk(ir.root);
|
|
2500
|
+
return names;
|
|
2501
|
+
}
|
|
2502
|
+
function collectPresenceCheckedPropNames(ctx, ir) {
|
|
2503
|
+
const names = new Set;
|
|
2504
|
+
const optionalParams = new Set(ir.metadata.propsParams.filter((p) => p.optional && p.defaultValue == null && p.type.kind === "primitive").map((p) => p.name));
|
|
2505
|
+
if (optionalParams.size === 0)
|
|
2506
|
+
return names;
|
|
2507
|
+
const propsObject = ctx.state.propsObjectName;
|
|
2508
|
+
const isUndefinedCheck = (op) => op === "!==" || op === "!=" || op === "===" || op === "==";
|
|
2509
|
+
for (const memo of ir.metadata.memos) {
|
|
2510
|
+
const body = memo.parsed;
|
|
2511
|
+
if (!body || body.kind !== "binary" || !isUndefinedCheck(body.op))
|
|
2512
|
+
continue;
|
|
2513
|
+
const other = body.right.kind === "identifier" && body.right.name === "undefined" ? body.left : body.left.kind === "identifier" && body.left.name === "undefined" ? body.right : null;
|
|
2514
|
+
if (!other)
|
|
2515
|
+
continue;
|
|
2516
|
+
const propName = other.kind === "member" && !other.computed && other.object.kind === "identifier" && other.object.name === propsObject ? other.property : !propsObject && other.kind === "identifier" ? other.name : null;
|
|
2517
|
+
if (propName && optionalParams.has(propName))
|
|
2518
|
+
names.add(propName);
|
|
2519
|
+
}
|
|
2520
|
+
return names;
|
|
2521
|
+
}
|
|
2323
2522
|
function resolvePropGoType(ctx, param, propTypeOverrides) {
|
|
2324
2523
|
const base = propTypeOverrides.get(param.name) ?? typeInfoToGo(ctx, param.type, param.defaultValue);
|
|
2325
2524
|
if (param.optional && ctx.state.localStructFields.has(base)) {
|
|
2326
2525
|
return "map[string]interface{}";
|
|
2327
2526
|
}
|
|
2527
|
+
if (param.optional && param.type.kind === "primitive" && (ctx.state.nullishConsumedPropNames.has(param.name) || ctx.state.omittableAttrConsumedPropNames.has(param.name) || ctx.state.textConsumedPropNames.has(param.name) || ctx.state.presenceCheckedPropNames.has(param.name)) && NULLISH_SCALAR_GO_TYPES.has(base)) {
|
|
2528
|
+
return "interface{}";
|
|
2529
|
+
}
|
|
2328
2530
|
return base;
|
|
2329
2531
|
}
|
|
2330
2532
|
function collectNillablePropNames(ctx, ir) {
|
|
@@ -2403,8 +2605,8 @@ class GoTemplateAdapter extends BaseAdapter {
|
|
|
2403
2605
|
state: this.state,
|
|
2404
2606
|
convertExpressionToGo: (jsExpr, out, preParsed) => this.convertExpressionToGo(jsExpr, out, preParsed),
|
|
2405
2607
|
convertConditionToGo: (jsCondition, preParsed) => this.convertConditionToGo(jsCondition, preParsed),
|
|
2406
|
-
extractPropNameFromInitialValue: (initialValue) => this.extractPropNameFromInitialValue(initialValue),
|
|
2407
|
-
extractPropFallback: (initialValue) => this.extractPropFallback(initialValue),
|
|
2608
|
+
extractPropNameFromInitialValue: (initialValue, preParsed) => this.extractPropNameFromInitialValue(initialValue, preParsed),
|
|
2609
|
+
extractPropFallback: (initialValue, preParsed) => this.extractPropFallback(initialValue, preParsed),
|
|
2408
2610
|
resolveModuleStringConst: (name) => this.resolveModuleStringConst(name)
|
|
2409
2611
|
};
|
|
2410
2612
|
get errors() {
|
|
@@ -2456,6 +2658,12 @@ class GoTemplateAdapter extends BaseAdapter {
|
|
|
2456
2658
|
}
|
|
2457
2659
|
this.state.loweringMatchers = prepareLoweringMatchers(ir.metadata);
|
|
2458
2660
|
augmentInheritedPropAccesses(ir);
|
|
2661
|
+
this.buildLocalTypeTables(ir, ir.metadata.componentName);
|
|
2662
|
+
this.state.nullishConsumedPropNames = collectNullishConsumedPropNames(this.emitCtx, ir);
|
|
2663
|
+
this.state.omittableAttrConsumedPropNames = collectOmittableAttrConsumedPropNames(this.emitCtx, ir);
|
|
2664
|
+
this.state.textConsumedPropNames = collectTextConsumedPropNames(this.emitCtx, ir);
|
|
2665
|
+
this.state.presenceCheckedPropNames = collectPresenceCheckedPropNames(this.emitCtx, ir);
|
|
2666
|
+
this.state.nillablePropNames = collectNillablePropNames(this.emitCtx, ir);
|
|
2459
2667
|
}
|
|
2460
2668
|
generate(ir, options) {
|
|
2461
2669
|
this.state.componentName = ir.metadata.componentName;
|
|
@@ -2464,7 +2672,6 @@ class GoTemplateAdapter extends BaseAdapter {
|
|
|
2464
2672
|
this.state.templateVarCounter = 0;
|
|
2465
2673
|
this.state.pendingChildrenDefines = [];
|
|
2466
2674
|
this.primeCompileState(ir);
|
|
2467
|
-
this.state.nillablePropNames = collectNillablePropNames(this.emitCtx, ir);
|
|
2468
2675
|
this.state.stringValueNames = collectStringValueNames(ir);
|
|
2469
2676
|
if (!options?.siblingTemplatesRegistered) {
|
|
2470
2677
|
this.checkImportedLoopChildComponents(ir);
|
|
@@ -2983,10 +3190,18 @@ ${goFields.join(`
|
|
|
2983
3190
|
this.emitStaticBodyWrappers(lines, ir, componentName, staticWithBody, emittedWrapperVars);
|
|
2984
3191
|
const propFallbackVars = this.collectPropFallbackVars(ir);
|
|
2985
3192
|
for (const [, info] of propFallbackVars) {
|
|
2986
|
-
|
|
2987
|
-
|
|
2988
|
-
|
|
2989
|
-
|
|
3193
|
+
if (info.assertType) {
|
|
3194
|
+
const deref = info.assertType === "int" ? `bf.ToInt(in.${info.fieldName})` : info.assertType === "float64" ? `bf.ToFloat64(in.${info.fieldName})` : `in.${info.fieldName}.(${info.assertType})`;
|
|
3195
|
+
lines.push(` var ${info.varName} ${info.assertType} = ${info.goFallback}`);
|
|
3196
|
+
lines.push(` if in.${info.fieldName} != nil {`);
|
|
3197
|
+
lines.push(` ${info.varName} = ${deref}`);
|
|
3198
|
+
lines.push(` }`);
|
|
3199
|
+
} else {
|
|
3200
|
+
lines.push(` ${info.varName} := in.${info.fieldName}`);
|
|
3201
|
+
lines.push(` if ${info.varName} == ${info.zeroLiteral} {`);
|
|
3202
|
+
lines.push(` ${info.varName} = ${info.goFallback}`);
|
|
3203
|
+
lines.push(` }`);
|
|
3204
|
+
}
|
|
2990
3205
|
}
|
|
2991
3206
|
if (propFallbackVars.size > 0)
|
|
2992
3207
|
lines.push("");
|
|
@@ -3066,7 +3281,7 @@ ${goFields.join(`
|
|
|
3066
3281
|
const fieldName = capitalizeFieldName(signal.getter);
|
|
3067
3282
|
if (propFieldNames.has(fieldName))
|
|
3068
3283
|
continue;
|
|
3069
|
-
const fallbackMatch = this.extractPropFallback(signal.initialValue);
|
|
3284
|
+
const fallbackMatch = this.extractPropFallback(signal.initialValue, signal.parsed);
|
|
3070
3285
|
const hoisted = fallbackMatch ? propFallbackVars.get(fallbackMatch.propName) : undefined;
|
|
3071
3286
|
if (hoisted) {
|
|
3072
3287
|
lines.push(` ${fieldName}: ${hoisted.varName},`);
|
|
@@ -3912,8 +4127,9 @@ ${goFields.join(`
|
|
|
3912
4127
|
for (const nested of findNestedComponents(ir.root)) {
|
|
3913
4128
|
localTaken.add(`${nested.name.charAt(0).toLowerCase()}${nested.name.slice(1)}s`);
|
|
3914
4129
|
}
|
|
4130
|
+
const propTypeOverrides = buildPropTypeOverrides(this.emitCtx, ir);
|
|
3915
4131
|
for (const signal of ir.metadata.signals) {
|
|
3916
|
-
const match = this.extractPropFallback(signal.initialValue);
|
|
4132
|
+
const match = this.extractPropFallback(signal.initialValue, signal.parsed);
|
|
3917
4133
|
if (!match)
|
|
3918
4134
|
continue;
|
|
3919
4135
|
if (result.has(match.propName))
|
|
@@ -3924,6 +4140,8 @@ ${goFields.join(`
|
|
|
3924
4140
|
if (goPropDefault(param.defaultValue) !== null)
|
|
3925
4141
|
continue;
|
|
3926
4142
|
const fieldName = capitalizeFieldName(match.propName);
|
|
4143
|
+
const concreteType = propTypeOverrides.get(param.name) ?? typeInfoToGo(this.emitCtx, param.type, param.defaultValue);
|
|
4144
|
+
const nullishLowered = NULLISH_SCALAR_GO_TYPES.has(concreteType) && resolvePropGoType(this.emitCtx, param, propTypeOverrides) === "interface{}";
|
|
3927
4145
|
let zeroLiteral;
|
|
3928
4146
|
if (match.goFallback === "true" || match.goFallback === "false") {
|
|
3929
4147
|
zeroLiteral = "false";
|
|
@@ -3934,20 +4152,31 @@ ${goFields.join(`
|
|
|
3934
4152
|
} else {
|
|
3935
4153
|
continue;
|
|
3936
4154
|
}
|
|
3937
|
-
if (
|
|
3938
|
-
|
|
3939
|
-
|
|
3940
|
-
|
|
4155
|
+
if (!nullishLowered) {
|
|
4156
|
+
if (match.goFallback === zeroLiteral)
|
|
4157
|
+
continue;
|
|
4158
|
+
if (zeroLiteral === "0" && Number(match.goFallback) === 0)
|
|
4159
|
+
continue;
|
|
4160
|
+
}
|
|
3941
4161
|
let varName = match.propName;
|
|
3942
4162
|
while (localTaken.has(varName) || GO_KEYWORDS.has(varName)) {
|
|
3943
4163
|
varName += "_";
|
|
3944
4164
|
}
|
|
3945
4165
|
localTaken.add(varName);
|
|
3946
|
-
result.set(match.propName, {
|
|
4166
|
+
result.set(match.propName, {
|
|
4167
|
+
varName,
|
|
4168
|
+
fieldName,
|
|
4169
|
+
goFallback: match.goFallback,
|
|
4170
|
+
zeroLiteral,
|
|
4171
|
+
...nullishLowered ? { assertType: concreteType } : {}
|
|
4172
|
+
});
|
|
3947
4173
|
}
|
|
3948
4174
|
return result;
|
|
3949
4175
|
}
|
|
3950
|
-
extractPropFallback(initialValue) {
|
|
4176
|
+
extractPropFallback(initialValue, preParsed) {
|
|
4177
|
+
const structural = preParsed ? this.extractPropFallbackFromParsed(preParsed) : null;
|
|
4178
|
+
if (structural)
|
|
4179
|
+
return structural;
|
|
3951
4180
|
if (!this.state.propsObjectName)
|
|
3952
4181
|
return null;
|
|
3953
4182
|
const trimmed = initialValue.trim();
|
|
@@ -3961,9 +4190,38 @@ ${goFields.join(`
|
|
|
3961
4190
|
return null;
|
|
3962
4191
|
return { propName: m[1], goFallback };
|
|
3963
4192
|
}
|
|
3964
|
-
|
|
3965
|
-
if (
|
|
4193
|
+
extractPropFallbackFromParsed(preParsed) {
|
|
4194
|
+
if (preParsed.kind !== "logical" || preParsed.op !== "??")
|
|
4195
|
+
return null;
|
|
4196
|
+
const left = preParsed.left;
|
|
4197
|
+
const propName = left.kind === "identifier" && !this.state.propsObjectName ? left.name : left.kind === "member" && !left.computed && left.object.kind === "identifier" && left.object.name === this.state.propsObjectName ? left.property : null;
|
|
4198
|
+
if (!propName)
|
|
4199
|
+
return null;
|
|
4200
|
+
let right = preParsed.right;
|
|
4201
|
+
let negate = "";
|
|
4202
|
+
if (right.kind === "unary" && right.op === "-") {
|
|
4203
|
+
negate = "-";
|
|
4204
|
+
right = right.argument;
|
|
4205
|
+
}
|
|
4206
|
+
if (right.kind !== "literal")
|
|
4207
|
+
return null;
|
|
4208
|
+
if (negate && right.literalType !== "number")
|
|
4209
|
+
return null;
|
|
4210
|
+
if (right.literalType === "string") {
|
|
4211
|
+
return { propName, goFallback: JSON.stringify(right.value) };
|
|
4212
|
+
}
|
|
4213
|
+
const goFallback = goPropDefault(negate + (right.raw ?? String(right.value)));
|
|
4214
|
+
if (goFallback === null)
|
|
4215
|
+
return null;
|
|
4216
|
+
return { propName, goFallback };
|
|
4217
|
+
}
|
|
4218
|
+
extractPropNameFromInitialValue(initialValue, preParsed) {
|
|
4219
|
+
if (!this.state.propsObjectName) {
|
|
4220
|
+
if (preParsed?.kind === "logical" && (preParsed.op === "??" || preParsed.op === "||") && preParsed.left.kind === "identifier") {
|
|
4221
|
+
return preParsed.left.name;
|
|
4222
|
+
}
|
|
3966
4223
|
return null;
|
|
4224
|
+
}
|
|
3967
4225
|
const trimmed = initialValue.trim();
|
|
3968
4226
|
const name = this.state.propsObjectName;
|
|
3969
4227
|
const direct = new RegExp(`^${name}\\.(\\w+)(?:\\s*(?:\\?\\?|\\|\\|)\\s*.+)?$`);
|
|
@@ -4087,10 +4345,22 @@ ${goFields.join(`
|
|
|
4087
4345
|
}
|
|
4088
4346
|
return goExpr;
|
|
4089
4347
|
}
|
|
4348
|
+
const finalExpr = this.textNillablePropNameOf(classify.parsed) !== null ? `bf_string ${wrapIfMultiToken(goExpr)}` : goExpr;
|
|
4090
4349
|
if (expr.slotId) {
|
|
4091
|
-
return `{{bfTextStart "${expr.slotId}"}}{{${
|
|
4350
|
+
return `{{bfTextStart "${expr.slotId}"}}{{${finalExpr}}}{{bfTextEnd}}`;
|
|
4092
4351
|
}
|
|
4093
|
-
return `{{${
|
|
4352
|
+
return `{{${finalExpr}}}`;
|
|
4353
|
+
}
|
|
4354
|
+
textNillablePropNameOf(expr) {
|
|
4355
|
+
if (!expr)
|
|
4356
|
+
return null;
|
|
4357
|
+
let name = null;
|
|
4358
|
+
if (expr.kind === "identifier") {
|
|
4359
|
+
name = expr.name;
|
|
4360
|
+
} else if (expr.kind === "member" && !expr.computed && expr.object.kind === "identifier" && expr.object.name === this.state.propsObjectName) {
|
|
4361
|
+
name = expr.property;
|
|
4362
|
+
}
|
|
4363
|
+
return name !== null && this.state.textConsumedPropNames.has(name) && this.state.nillablePropNames.has(name) ? name : null;
|
|
4094
4364
|
}
|
|
4095
4365
|
isTemplateFragment(go, kind) {
|
|
4096
4366
|
return go.startsWith("{{") || kind === "template-literal";
|
|
@@ -4306,7 +4576,7 @@ ${goFields.join(`
|
|
|
4306
4576
|
}
|
|
4307
4577
|
const obj = emit(object);
|
|
4308
4578
|
if (property === "length")
|
|
4309
|
-
return `
|
|
4579
|
+
return `bf_length ${wrapIfMultiToken(obj)}`;
|
|
4310
4580
|
if (optional) {
|
|
4311
4581
|
return `bf_get ${wrapIfMultiToken(obj)} ${JSON.stringify(goFieldNameForKey(property))}`;
|
|
4312
4582
|
}
|
|
@@ -4375,8 +4645,24 @@ ${goFields.join(`
|
|
|
4375
4645
|
const wrapRight = wrapIfMultiToken(emit(right));
|
|
4376
4646
|
if (op === "&&")
|
|
4377
4647
|
return `and ${wrapLeft} ${wrapRight}`;
|
|
4648
|
+
if (op === "??" && this.nillablePropNameOf(left) !== null) {
|
|
4649
|
+
return `bf_nullish ${wrapLeft} ${wrapRight}`;
|
|
4650
|
+
}
|
|
4378
4651
|
return `or ${wrapLeft} ${wrapRight}`;
|
|
4379
4652
|
}
|
|
4653
|
+
nillablePropNameOf(expr) {
|
|
4654
|
+
let name = null;
|
|
4655
|
+
if (expr.kind === "identifier") {
|
|
4656
|
+
name = expr.name;
|
|
4657
|
+
} else if (expr.kind === "member" && !expr.computed && expr.object.kind === "identifier") {
|
|
4658
|
+
if (expr.object.name === this.state.propsObjectName) {
|
|
4659
|
+
name = expr.property;
|
|
4660
|
+
} else {
|
|
4661
|
+
name = expr.object.name;
|
|
4662
|
+
}
|
|
4663
|
+
}
|
|
4664
|
+
return name !== null && this.state.nullishConsumedPropNames.has(name) && this.state.nillablePropNames.has(name) ? name : null;
|
|
4665
|
+
}
|
|
4380
4666
|
conditional(test, consequent, alternate, emit) {
|
|
4381
4667
|
const t = emit(test);
|
|
4382
4668
|
const c = this.renderConditionalBranch(consequent);
|
|
@@ -4808,9 +5094,6 @@ ${goFields.join(`
|
|
|
4808
5094
|
renderPredicateCondition(pred, param, datumField) {
|
|
4809
5095
|
return this.renderFilterExpr(pred, param, new Map, datumField ?? undefined);
|
|
4810
5096
|
}
|
|
4811
|
-
needsParens(expr) {
|
|
4812
|
-
return expr.kind === "logical" || expr.kind === "unary" || expr.kind === "conditional";
|
|
4813
|
-
}
|
|
4814
5097
|
splitPreamble(rendered) {
|
|
4815
5098
|
if (!rendered.includes("{{"))
|
|
4816
5099
|
return null;
|
|
@@ -5223,7 +5506,8 @@ ${goFields.join(`
|
|
|
5223
5506
|
return plain(this.rootFieldRef(expr.callee.name));
|
|
5224
5507
|
}
|
|
5225
5508
|
if (expr.callee.kind === "identifier" && (identifierPath(expr.callee) ?? expr.callee.name) === "isValidElement" && expr.args.length === 1) {
|
|
5226
|
-
|
|
5509
|
+
const inner = this.renderConditionExpr(expr.args[0]);
|
|
5510
|
+
return { preamble: inner.preamble, expr: `(bf_is_element ${wrapIfMultiToken(inner.expr)})` };
|
|
5227
5511
|
}
|
|
5228
5512
|
if (expr.callee.kind === "identifier" && !this.templatePrimitives[identifierPath(expr.callee) ?? ""]) {
|
|
5229
5513
|
const path = identifierPath(expr.callee) ?? expr.callee.name;
|
|
@@ -5340,9 +5624,9 @@ ${goFields.join(`
|
|
|
5340
5624
|
const leftResult = this.renderConditionExpr(expr.left);
|
|
5341
5625
|
const rightResult = this.renderConditionExpr(expr.right);
|
|
5342
5626
|
const preamble = leftResult.preamble + rightResult.preamble;
|
|
5343
|
-
const wrapLeft =
|
|
5344
|
-
const wrapRight =
|
|
5345
|
-
const result = expr.op === "&&" ? `and ${wrapLeft} ${wrapRight}` : `or ${wrapLeft} ${wrapRight}`;
|
|
5627
|
+
const wrapLeft = wrapIfMultiToken(leftResult.expr);
|
|
5628
|
+
const wrapRight = wrapIfMultiToken(rightResult.expr);
|
|
5629
|
+
const result = expr.op === "&&" ? `and ${wrapLeft} ${wrapRight}` : expr.op === "??" && this.nillablePropNameOf(expr.left) !== null ? `bf_nullish ${wrapLeft} ${wrapRight}` : `or ${wrapLeft} ${wrapRight}`;
|
|
5346
5630
|
return { preamble, expr: result };
|
|
5347
5631
|
}
|
|
5348
5632
|
case "conditional": {
|
|
@@ -5682,7 +5966,7 @@ ${children}`;
|
|
|
5682
5966
|
if (css !== null)
|
|
5683
5967
|
return `style="${css}"`;
|
|
5684
5968
|
}
|
|
5685
|
-
if (
|
|
5969
|
+
if (isBooleanAttr2(name) || value.presenceOrUndefined) {
|
|
5686
5970
|
const { condition: goCond, preamble } = this.convertConditionToGo(value.expr, value.parsed);
|
|
5687
5971
|
const body = name.startsWith("aria-") ? `${name}="true"` : name;
|
|
5688
5972
|
return `${preamble}{{if ${goCond}}}${body}{{end}}`;
|
|
@@ -5755,7 +6039,11 @@ ${children}`;
|
|
|
5755
6039
|
if (e.kind === "expr" && !isSupported(parseExpression4(e.expr)).supported)
|
|
5756
6040
|
return null;
|
|
5757
6041
|
}
|
|
5758
|
-
|
|
6042
|
+
const args = entries.flatMap((e) => [
|
|
6043
|
+
JSON.stringify(e.cssKey),
|
|
6044
|
+
e.kind === "literal" ? JSON.stringify(e.value) : wrapIfMultiToken(this.convertExpressionToGo(e.expr))
|
|
6045
|
+
]);
|
|
6046
|
+
return `{{bf_style_object ${args.join(" ")}}}`;
|
|
5759
6047
|
}
|
|
5760
6048
|
renderAttributes(element) {
|
|
5761
6049
|
const parts = [];
|
|
@@ -115,6 +115,38 @@ export declare class CompileState {
|
|
|
115
115
|
* whose value is a bare reference to such a prop when it's nil.
|
|
116
116
|
*/
|
|
117
117
|
nillablePropNames: Set<string>;
|
|
118
|
+
/**
|
|
119
|
+
* OPTIONAL prop names consumed nullish-sensitively (`??` left operand in a
|
|
120
|
+
* parsed expression tree, or a signal's `props.X ?? <literal>` seed) —
|
|
121
|
+
* #2248. Consulted by `resolvePropGoType` to flip an optional scalar to the
|
|
122
|
+
* nillable `interface{}` representation, so it MUST be populated before the
|
|
123
|
+
* first `resolvePropGoType` call of a compile (see `generate()`'s ordering
|
|
124
|
+
* against `collectNillablePropNames`).
|
|
125
|
+
*/
|
|
126
|
+
nullishConsumedPropNames: Set<string>;
|
|
127
|
+
/**
|
|
128
|
+
* OPTIONAL no-default prop names consumed as a BARE omittable-attribute
|
|
129
|
+
* value (`rows={rows}`) — #2259. Same `resolvePropGoType` flip and same
|
|
130
|
+
* populate-before-first-resolve ordering as `nullishConsumedPropNames`:
|
|
131
|
+
* the attribute-omission guard (`{{if ne .X nil}}`) needs a nillable field.
|
|
132
|
+
*/
|
|
133
|
+
omittableAttrConsumedPropNames: Set<string>;
|
|
134
|
+
/**
|
|
135
|
+
* OPTIONAL no-default prop names consumed as a BARE TEXT-position
|
|
136
|
+
* expression value (`{size}`) — #2267. Same `resolvePropGoType` flip and
|
|
137
|
+
* same populate-before-first-resolve ordering as
|
|
138
|
+
* `nullishConsumedPropNames`: the text emitter's nil-safe `bf_string`
|
|
139
|
+
* wrap needs a nillable field to have something to guard.
|
|
140
|
+
*/
|
|
141
|
+
textConsumedPropNames: Set<string>;
|
|
142
|
+
/**
|
|
143
|
+
* OPTIONAL no-default prop names whose PRESENCE is tested — `props.X !==
|
|
144
|
+
* undefined` (the "controlled component" idiom's `isControlled` memo) —
|
|
145
|
+
* #2260. Same `resolvePropGoType` flip and same populate-before-first-
|
|
146
|
+
* resolve ordering as `nullishConsumedPropNames`: distinguishing "caller
|
|
147
|
+
* passed a value" from "caller omitted the prop" needs a nillable field.
|
|
148
|
+
*/
|
|
149
|
+
presenceCheckedPropNames: Set<string>;
|
|
118
150
|
/**
|
|
119
151
|
* String-typed signal getter / prop names (#2168 string-concat-plus).
|
|
120
152
|
* Feeds `isStringName` for `isStringConcatBinary`, which decides whether a
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compile-state.d.ts","sourceRoot":"","sources":["../../../src/adapter/lib/compile-state.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EACV,aAAa,EACb,eAAe,EACf,eAAe,EACf,UAAU,EACV,MAAM,EACN,eAAe,EACf,QAAQ,EACR,WAAW,EACX,cAAc,EACd,QAAQ,EACT,MAAM,iBAAiB,CAAA;AAExB,qBAAa,YAAY;IAGvB,aAAa,EAAE,MAAM,CAAK;IAC1B,MAAM,EAAE,aAAa,EAAE,CAAK;IAE5B;;+CAE2C;IAC3C,uBAAuB,EAAE,GAAG,CAAC,MAAM,CAAC,CAAY;IAEhD,kBAAkB,EAAE,MAAM,CAAI;IAE9B;;;OAGG;IACH,sBAAsB,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC,CAAK;IAErE,eAAe,EAAE,MAAM,GAAG,IAAI,CAAO;IAErC;;;;OAIG;IACH,aAAa,EAAE,MAAM,GAAG,IAAI,CAAO;IAEnC;;;;;OAKG;IACH,kBAAkB,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAY;IAEnD;;;;OAIG;IACH,cAAc,EAAE,UAAU,CAAC,gBAAgB,CAAC,CAAK;IAEjD;;;;;;OAMG;IACH,0BAA0B,EAAE,GAAG,CAAC,MAAM,CAAC,CAAY;IAEnD;;;OAGG;IACH,gBAAgB,EAAE,GAAG,CAAC,MAAM,CAAC,CAAY;IAEzC;;qFAEiF;IACjF,YAAY,EAAE,QAAQ,EAAE,CAAK;IAE7B,0FAA0F;IAC1F,sBAAsB,EAAE,cAAc,EAAE,CAAK;IAE7C;;;OAGG;IACH,gBAAgB,EAAE,eAAe,EAAE,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,CAAC,CAAY;IAElD;;;;;;OAMG;IACH,gBAAgB,EAAE,eAAe,EAAE,CAAK;IAExC;;;;OAIG;IACH,iBAAiB,EAAE,GAAG,CAAC,MAAM,CAAC,CAAY;IAE1C;;;;;;;OAOG;IACH,wBAAwB,EAAE,GAAG,CAAC,MAAM,CAAC,CAAY;IAEjD;;;;;OAKG;IACH,8BAA8B,EAAE,GAAG,CAAC,MAAM,CAAC,CAAY;IAEvD;;;;;;OAMG;IACH,qBAAqB,EAAE,GAAG,CAAC,MAAM,CAAC,CAAY;IAE9C;;;;;;OAMG;IACH,wBAAwB,EAAE,GAAG,CAAC,MAAM,CAAC,CAAY;IAEjD;;;;;OAKG;IACH,gBAAgB,EAAE,GAAG,CAAC,MAAM,CAAC,CAAY;IAEzC;gBACY;IACZ,cAAc,EAAE,GAAG,CAAC,MAAM,CAAC,CAAY;IAEvC;;4DAEwD;IACxD,mBAAmB,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAY;IAIpD;sEACkE;IAClE,gBAAgB,EAAE,OAAO,CAAQ;IAEjC;sCACkC;IAClC,OAAO,EAAE,OAAO,CAAQ;IAExB,uFAAuF;IACvF,cAAc,EAAE,GAAG,CAAC,MAAM,CAAC,CAAY;IAEvC,mFAAmF;IACnF,gBAAgB,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAY;IAEjD;;;;OAIG;IACH,iBAAiB,EAAE,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAY;IAE/D;;;OAGG;IACH,gBAAgB,EAAE,GAAG,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAY;IAEnD;yEACqE;IACrE,kBAAkB,UAAQ;CAC3B"}
|
|
@@ -127,6 +127,15 @@ export interface PropFallbackVar {
|
|
|
127
127
|
goFallback: string;
|
|
128
128
|
/** Go zero literal for the prop's type (`0`, `""`, etc.). */
|
|
129
129
|
zeroLiteral: string;
|
|
130
|
+
/**
|
|
131
|
+
* Set when the prop lowered to the nillable `interface{}` representation
|
|
132
|
+
* (#2248): the concrete scalar Go type (`string`/`int`/`float64`/`bool`)
|
|
133
|
+
* the constructor materializes the hoisted local as. Presence switches
|
|
134
|
+
* the emission from the zero-value check (`if v == 0`) to a nil check
|
|
135
|
+
* (`if in.X != nil`), which is what makes an explicit `''`/`0` input
|
|
136
|
+
* distinguishable from an absent one.
|
|
137
|
+
*/
|
|
138
|
+
assertType?: string;
|
|
130
139
|
}
|
|
131
140
|
/**
|
|
132
141
|
* Scope for `lowerCtorExpr` — lowering a JS expression to Go in the
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/adapter/lib/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EACV,oBAAoB,EACpB,MAAM,EACN,MAAM,EACN,UAAU,EACV,QAAQ,EACT,MAAM,iBAAiB,CAAA;AAExB;;;;;GAKG;AACH,MAAM,MAAM,WAAW,GAAG;IACxB,uBAAuB,CAAC,EAAE,OAAO,CAAA;CAClC,CAAA;AAED;;;GAGG;AACH,MAAM,WAAW,mBAAoB,SAAQ,oBAAoB;IAC/D,SAAS,EAAE,OAAO,CAAA;IAClB,aAAa,EAAE,OAAO,CAAA;IACtB;+EAC2E;IAC3E,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB;0EACsE;IACtE,YAAY,CAAC,EAAE,MAAM,EAAE,CAAA;IACvB,mEAAmE;IACnE,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB;2EACuE;IACvE,eAAe,CAAC,EAAE,UAAU,CAAA;IAC5B,oEAAoE;IACpE,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB;8EAC0E;IAC1E,YAAY,CAAC,EAAE,QAAQ,GAAG,IAAI,CAAA;CAC/B;AAED,MAAM,WAAW,mBAAmB;IAClC,IAAI,EAAE,MAAM,CAAA;I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