Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/ninety-radios-smash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@marko/tsrx": patch
---

Member expression tag names map to dynamic tags
7 changes: 4 additions & 3 deletions packages/tsrx/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const { files } = compile(source, "App.tsrx");
| --------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------- |
| `component App(props: T) { ... }` | `export type Input = T;` + `<const/props=input/>` |
| `component App({ a, b }: T) { ... }` | `export type Input = T;` + `<const/{ a, b }=input/>` |
| `component App() { ... }` | (no Input type, no binding) |
| `component App() { ... }` | (no Input type, no binding) |
| `<div class="x">{expr}</div>` | `<div class="x">${expr}</div>` |
| `{text "safe string"}` | `safe string` (plain text when value contains none of `< > $ {`) |
| `{text expr}` | `${expr}` |
Expand All @@ -38,12 +38,13 @@ const { files } = compile(source, "App.tsrx");
| `<div {...rest}>` | `<div ...rest>` |
| `const name = expr` | `<const/name=expr/>` |
| `let name` / `let name = expr` | `<let/name/>` / `<let/name=expr/>` |
| `const title = <tsx><span class="x">{"Hi"}</span></tsx>;` | `<define/title><span class="x">${"Hi"}</span></define>` · use `{title}` → Marko `<${title}/>` |
| `const title = <tsx><span class="x">{"Hi"}</span></tsx>;` | `<define/title><span class="x">${"Hi"}</span></define>` · use `{title}` → Marko `<${title}/>` |
| `<input.content/>` | `<${input.content}/>` (member expression tag names map to dynamic tags) |
| `if / else if / else` | `<if=...>`, `<else if=...>`, `<else>` |
| `for (const x of xs; index i)` | `<for\|x, i\| of=xs>` |
| `for (const x of xs; key x.id)` | `<for\|x\| of=xs by=(x) => x.id>` |
| `switch (d) { case a: ...; default: ...; }` | chained `<if=d===a>` / `<else>` |
| `try { ... } pending { ... } catch (err) { ... }` | `<try>` … `<@placeholder>` … `<@catch|err|>` … `</try>` (catch param name replaces `err`) |
| `try { ... } pending { ... } catch (err) { ... }` | `<try>` … `<@placeholder>` … `<@catch\|err\|>` … `</try>` (catch param name replaces `err`) |
| `<style>...</style>` | `<style>...</style>` (passed through as CSS-modules-friendly; scoped hash is applied by the existing `@tsrx/core` pipeline) |

## Not yet supported (MVP)
Expand Down
5 changes: 3 additions & 2 deletions packages/tsrx/src/transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -433,8 +433,9 @@ export class Transformer {
}

const isDynamic =
el.id.type === "Identifier" &&
this.#defineNames.has((el.id as AST.Identifier).name);
el.id.type === "MemberExpression" ||
(el.id.type === "Identifier" &&
this.#defineNames.has((el.id as AST.Identifier).name));

const refAttr = el.attributes.find((a) => a.type === "RefAttribute") as
| (AST.BaseNode & { type: "RefAttribute"; argument: AST.Expression })
Expand Down
4 changes: 4 additions & 0 deletions packages/tsrx/tests/__snapshots__/volar-mappings.txt
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,10 @@

=== style-tag ===

=== tag-member-expression ===
src: 2 "div" -> "div"
src: 2 "input.content" -> "input.content"

=== top-level-text ===
src: 1 "{ count: number }" -> "{ count: number }"
src: 1 "{ count }" -> "{ count }"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<div><${input.content}/></div>
3 changes: 3 additions & 0 deletions packages/tsrx/tests/fixtures/tag-member-expression/index.tsrx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default component(input) {
<div><input.content/></div>
}