Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] t-model expression allow '$' in dot format #1551

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion src/compiler/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"]);
Expand Down
19 changes: 19 additions & 0 deletions tests/components/__snapshots__/t_model.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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(\`<div><input block-property-0=\\"value\\" block-handler-1=\\"input\\"/><span><block-text-2/></span></div>\`);

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
) {
Expand Down
19 changes: 19 additions & 0 deletions tests/components/t_model.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,25 @@ describe("t-model directive", () => {
expect(fixture.innerHTML).toBe("<div><input><span>test</span></div>");
});

test("basic use, on an input with $", async () => {
class SomeComponent extends Component {
static template = xml`
<div>
<input t-model="state.$text"/>
<span><t t-esc="state.$text"/></span>
</div>`;
state = useState({ $text: "" });
}
const comp = await mount(SomeComponent, fixture);

expect(fixture.innerHTML).toBe("<div><input><span></span></div>");

const input = fixture.querySelector("input")!;
await editInput(input, "test");
expect(comp.state.$text).toBe("test");
expect(fixture.innerHTML).toBe("<div><input><span>test</span></div>");
});

test("t-model on an input with an undefined value", async () => {
class SomeComponent extends Component {
static template = xml`<input t-model="state.text"/>`;
Expand Down