Skip to content

Commit a927780

Browse files
authored
Alias as wire (#135)
* Tests and docs * Syntax change * Changeset
1 parent 06ecf9d commit a927780

33 files changed

Lines changed: 405 additions & 132 deletions

.changeset/sharp-badgers-switch.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
"@stackables/bridge-compiler": minor
3+
"@stackables/bridge-parser": minor
4+
"@stackables/bridge-core": minor
5+
"@stackables/bridge": minor
6+
---
7+
8+
New alias syntax alias name <- source.from ?? "full syntax" catch "supported"

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ The `.bridge` language is designed to be scannable.
8282
| **Null Coalesce** | `o.name <- i.name \|\| "N/A"` | Alternative used if the current source resolves to `null`. |
8383
| **Error Guard** | `o.price <- api.price catch 0` | Alternative used if the current source **throws** an exception. |
8484
| **Ternary** | `o.val <- i.isPro ? a : b` | Evaluates condition; strictly pulls only the chosen branch. |
85-
| **Node Alias** | `alias uc:i.name as name` | Evaluates an expression once and caches it as a local graph node. |
85+
| **Node Alias** | `alias name <- uc:i.name` | Evaluates an expression once and caches it as a local graph node. |
8686
| **Arrays** | `o <- items[] as it { }` | Iterates over an array, creating a local shadow scope for each element. |
8787

8888
**[Read the Full Language Guide](https://bridge.sdk42.com/reference/10-core-concepts/)**

examples/without-graphql/should_i_go_outside.bridge

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ bridge Query.should_i_go_outside {
2727
g.q <- i.cityName
2828
g.format = "json"
2929

30-
alias first:g as f
30+
alias f <- first:g
3131

3232
w.latitude <- f.lat
3333
w.longitude <- f.lon

packages/bridge-compiler/src/codegen.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3454,7 +3454,7 @@ class CodegenContext {
34543454
return this.elementWireToExpr(w, elVar);
34553455
}
34563456
}
3457-
// Check if this is a pipe tool call (alias tool:source as name)
3457+
// Check if this is a pipe tool call (alias name <- tool:source)
34583458
if (isPull(w) && w.pipe) {
34593459
return this.elementWireToExpr(w, elVar);
34603460
}

packages/bridge-compiler/test/codegen.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2021,7 +2021,7 @@ describe("AOT codegen: async array mapping", () => {
20212021
with output as o
20222022
20232023
o.items <- api.results[] as item {
2024-
alias enricher:item as e
2024+
alias e <- enricher:item
20252025
.name <- item.name ?? continue
20262026
.extra <- e.data
20272027
}
@@ -2107,7 +2107,7 @@ describe("AOT codegen: async array mapping", () => {
21072107
o <- api.groups[] as g {
21082108
.label <- g.name
21092109
.items <- g.items[] as sub {
2110-
alias enricher:sub as e
2110+
alias e <- enricher:sub
21112111
.value <- e.data
21122112
}
21132113
}
@@ -2145,7 +2145,7 @@ describe("AOT codegen: async array mapping", () => {
21452145
with output as o
21462146
21472147
o.items <- api.results[] as item {
2148-
alias enricher:item as e
2148+
alias e <- enricher:item
21492149
.name <- item.name ?? continue
21502150
.extra <- e.data catch "n/a"
21512151
}
@@ -2178,7 +2178,7 @@ describe("AOT codegen: async array mapping", () => {
21782178
21792179
o.title <- api.title
21802180
o.items <- api.items[] as item {
2181-
alias enricher:item as e
2181+
alias e <- enricher:item
21822182
.name <- item.name ?? continue
21832183
.extra <- e.data
21842184
}
@@ -2279,7 +2279,7 @@ bridge Query.catalog {
22792279
with output as o
22802280
22812281
o <- src.items[] as it {
2282-
alias enrich:it as e
2282+
alias e <- enrich:it
22832283
.id <- it.item_id
22842284
.label <- e.name
22852285
}

packages/bridge-core/test/traversal-manifest-locations.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ describe("buildTraversalManifest source locations", () => {
4343
bridge Query.test {
4444
with input as i
4545
with output as o
46-
alias i.empty.array.error catch i.empty.array.error as clean
46+
alias clean <- i.empty.array.error catch i.empty.array.error
4747
o.message <- i.empty.array?.error ?? i.empty.array.error catch clean
4848
}
4949
`);

packages/bridge-parser/src/bridge-format.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1650,7 +1650,7 @@ function serializeBridgeBlock(bridge: Bridge): string {
16501650
}
16511651
}
16521652

1653-
// Emit block-scoped local bindings: alias <source> as <name>
1653+
// Emit block-scoped local bindings: alias <name> <- <source>
16541654
for (const [alias, info] of localBindingsByAlias) {
16551655
// Ternary alias in element scope
16561656
if (info.ternaryWire) {
@@ -1679,7 +1679,7 @@ function serializeBridgeBlock(bridge: Bridge): string {
16791679
const fallbackStr = serFallbacks(tw, sPipeOrRef);
16801680
const errf = serCatch(tw, sPipeOrRef);
16811681
lines.push(
1682-
`${indent}alias ${condStr} ? ${thenStr} : ${elseStr}${fallbackStr}${errf} as ${alias}`,
1682+
`${indent}alias ${alias} <- ${condStr} ? ${thenStr} : ${elseStr}${fallbackStr}${errf}`,
16831683
);
16841684
continue;
16851685
}
@@ -1769,7 +1769,11 @@ function serializeBridgeBlock(bridge: Bridge): string {
17691769
sourcePart = sRef(fromRef, true);
17701770
}
17711771
}
1772-
lines.push(`${indent}alias ${sourcePart} as ${alias}`);
1772+
const elemFb = serFallbacks(srcWire, sPipeOrRef);
1773+
const elemErrf = serCatch(srcWire, sPipeOrRef);
1774+
lines.push(
1775+
`${indent}alias ${alias} <- ${sourcePart}${elemFb}${elemErrf}`,
1776+
);
17731777
}
17741778

17751779
// Emit element-scoped tool declarations: with <tool> as <handle>
@@ -2219,7 +2223,7 @@ function serializeBridgeBlock(bridge: Bridge): string {
22192223
}
22202224

22212225
// ── Top-level alias declarations ─────────────────────────────────────
2222-
// Emit `alias <source> as <name>` for __local bindings that are NOT
2226+
// Emit `alias <name> <- <source>` for __local bindings that are NOT
22232227
// element-scoped (those are handled inside serializeArrayElements).
22242228
for (const [alias, info] of localBindingsByAlias) {
22252229
// Ternary alias: emit `alias <cond> ? <then> : <else> [fallbacks] as <name>`
@@ -2237,7 +2241,7 @@ function serializeBridgeBlock(bridge: Bridge): string {
22372241
const fallbackStr = serFallbacks(tw, sPipeOrRef);
22382242
const errf = serCatch(tw, sPipeOrRef);
22392243
lines.push(
2240-
`alias ${condStr} ? ${thenStr} : ${elseStr}${fallbackStr}${errf} as ${alias}`,
2244+
`alias ${alias} <- ${condStr} ? ${thenStr} : ${elseStr}${fallbackStr}${errf}`,
22412245
);
22422246
continue;
22432247
}
@@ -2294,7 +2298,7 @@ function serializeBridgeBlock(bridge: Bridge): string {
22942298
}
22952299
const aliasFb = serFallbacks(srcWire, sPipeOrRef);
22962300
const aliasErrf = serCatch(srcWire, sPipeOrRef);
2297-
lines.push(`alias ${sourcePart}${aliasFb}${aliasErrf} as ${alias}`);
2301+
lines.push(`alias ${alias} <- ${sourcePart}${aliasFb}${aliasErrf}`);
22982302
}
22992303
// Also emit wires reading from top-level __local bindings
23002304
for (const lw of localReadWires) {

0 commit comments

Comments
 (0)