From df71bcdbae9f5a545651a2a139b6b8e23afa5b07 Mon Sep 17 00:00:00 2001 From: Luke Lonas Date: Wed, 25 Oct 2023 11:43:43 -0700 Subject: [PATCH] [FIX] t-model expression allow '$' in dot format Fixes #1322 --- src/compiler/parser.ts | 2 +- .../__snapshots__/t_model.test.ts.snap | 19 +++++++++++++++++++ tests/components/t_model.test.ts | 19 +++++++++++++++++++ 3 files changed, 39 insertions(+), 1 deletion(-) diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 3a4cbb0ed..7f1fff8c1 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -304,7 +304,7 @@ function parseTDebugLog(node: Element, ctx: ParsingContext): AST | null { // ----------------------------------------------------------------------------- // Regular dom node // ----------------------------------------------------------------------------- -const hasDotAtTheEnd = /\.[\w_]+\s*$/; +const hasDotAtTheEnd = /\.[\w$_]+\s*$/; const hasBracketsAtTheEnd = /\[[^\[]+\]\s*$/; const ROOT_SVG_TAGS = new Set(["svg", "g", "path"]); diff --git a/tests/components/__snapshots__/t_model.test.ts.snap b/tests/components/__snapshots__/t_model.test.ts.snap index 1d1e0e902..9c6456eb7 100644 --- a/tests/components/__snapshots__/t_model.test.ts.snap +++ b/tests/components/__snapshots__/t_model.test.ts.snap @@ -76,6 +76,25 @@ exports[`t-model directive basic use, on an input 1`] = ` }" `; +exports[`t-model directive basic use, on an input with $ 1`] = ` +"function anonymous(app, bdom, helpers +) { + let { text, createBlock, list, multi, html, toggler, comment } = bdom; + let { toNumber } = helpers; + + let block1 = createBlock(\`
\`); + + return function template(ctx, node, key = \\"\\") { + const bExpr1 = ctx['state']; + const expr1 = '$text'; + let prop1 = bExpr1[expr1]; + let hdlr1 = [(ev) => { bExpr1[expr1] = ev.target.value; }]; + let txt1 = ctx['state'].$text; + return block1([prop1, hdlr1, txt1]); + } +}" +`; + exports[`t-model directive basic use, on an input with bracket expression 1`] = ` "function anonymous(app, bdom, helpers ) { diff --git a/tests/components/t_model.test.ts b/tests/components/t_model.test.ts index 2d6fd0bcc..07ca5c111 100644 --- a/tests/components/t_model.test.ts +++ b/tests/components/t_model.test.ts @@ -30,6 +30,25 @@ describe("t-model directive", () => { expect(fixture.innerHTML).toBe("
test
"); }); + test("basic use, on an input with $", async () => { + class SomeComponent extends Component { + static template = xml` +
+ + +
`; + state = useState({ $text: "" }); + } + const comp = await mount(SomeComponent, fixture); + + expect(fixture.innerHTML).toBe("
"); + + const input = fixture.querySelector("input")!; + await editInput(input, "test"); + expect(comp.state.$text).toBe("test"); + expect(fixture.innerHTML).toBe("
test
"); + }); + test("t-model on an input with an undefined value", async () => { class SomeComponent extends Component { static template = xml``;