Skip to content

Commit

Permalink
[FIX] t-model expression allow '$' in dot format
Browse files Browse the repository at this point in the history
Fixes odoo#1322
  • Loading branch information
LukeLonas committed Oct 25, 2023
1 parent 398df54 commit df71bcd
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
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

0 comments on commit df71bcd

Please sign in to comment.