import { ASTType, parse } from "../../src/qweb/parser";
describe("qweb parser", () => {
// ---------------------------------------------------------------------------
// texts and basic stuff
// ---------------------------------------------------------------------------
test("simple text node", async () => {
expect(parse("foo")).toEqual({
type: ASTType.Text,
value: "foo",
});
});
test("text in t tag", async () => {
expect(parse("foo")).toEqual({
type: ASTType.Text,
value: "foo",
});
});
test("empty string", async () => {
expect(parse("")).toEqual({
type: ASTType.Text,
value: "",
});
});
test("white spaces are condensed into a single space", async () => {
expect(parse(" ")).toEqual({
type: ASTType.Text,
value: " ",
});
});
test("white spaces only text nodes with newlines are removed", async () => {
const template = `
`;
expect(parse(template)).toEqual({
type: ASTType.DomNode,
tag: "div",
content: [],
attrs: {},
on: {},
ref: null,
model: null,
});
});
test("empty string in t tag", async () => {
expect(parse("")).toEqual({
type: ASTType.Text,
value: "",
});
});
test("simple comment node", async () => {
expect(parse("")).toEqual({
type: ASTType.Comment,
value: " comment ",
});
});
test("empty div", async () => {
expect(parse("")).toEqual({
type: ASTType.DomNode,
tag: "div",
attrs: {},
on: {},
ref: null,
model: null,
content: [],
});
});
test("div with some text", async () => {
expect(parse("some text
")).toEqual({
type: ASTType.DomNode,
tag: "div",
attrs: {},
on: {},
ref: null,
model: null,
content: [{ type: ASTType.Text, value: "some text" }],
});
});
test("div with some more content", async () => {
expect(parse("some textinside
")).toEqual({
type: ASTType.DomNode,
tag: "div",
attrs: {},
on: {},
ref: null,
model: null,
content: [
{ type: ASTType.Text, value: "some text" },
{
type: ASTType.DomNode,
tag: "span",
attrs: {},
on: {},
ref: null,
model: null,
content: [{ type: ASTType.Text, value: "inside" }],
},
],
});
});
test("multiple root dom nodes", async () => {
expect(parse("")).toEqual({
type: ASTType.Multi,
content: [
{
type: ASTType.DomNode,
tag: "div",
attrs: {},
on: {},
ref: null,
model: null,
content: [],
},
{
type: ASTType.DomNode,
tag: "span",
attrs: {},
on: {},
ref: null,
model: null,
content: [],
},
],
});
});
test("dom node next to text node", async () => {
expect(parse("some text")).toEqual({
type: ASTType.Multi,
content: [
{ type: ASTType.Text, value: "some text" },
{
type: ASTType.DomNode,
tag: "span",
attrs: {},
on: {},
ref: null,
model: null,
content: [],
},
],
});
});
test("dom node with class attribute", async () => {
expect(parse(`foo
`)).toEqual({
type: ASTType.DomNode,
tag: "div",
attrs: { class: "abc" },
on: {},
ref: null,
model: null,
content: [{ type: ASTType.Text, value: "foo" }],
});
});
// ---------------------------------------------------------------------------
// t-esc
// ---------------------------------------------------------------------------
test("t-esc node", async () => {
expect(parse(``)).toEqual({
type: ASTType.TEsc,
expr: "text",
defaultValue: "",
});
expect(parse(``)).toEqual({
type: ASTType.TEsc,
expr: "text",
defaultValue: "",
});
});
test("dom node with t-esc", async () => {
expect(parse(``)).toEqual({
type: ASTType.DomNode,
tag: "span",
attrs: {},
on: {},
ref: null,
model: null,
content: [{ type: ASTType.TEsc, expr: "text", defaultValue: "" }],
});
});
test("t-esc node with default value", async () => {
expect(parse(`hey`)).toEqual({
type: ASTType.TEsc,
expr: "text",
defaultValue: "hey",
});
});
test("dom node with t-esc with default value", async () => {
expect(parse(`hey
`)).toEqual({
type: ASTType.DomNode,
tag: "div",
attrs: {},
on: {},
ref: null,
model: null,
content: [{ type: ASTType.TEsc, expr: "text", defaultValue: "hey" }],
});
});
// ---------------------------------------------------------------------------
// t-raw
// ---------------------------------------------------------------------------
test("t-raw node", async () => {
expect(parse(``)).toEqual({
type: ASTType.TRaw,
expr: "text",
body: null,
});
});
test("t-raw node on a dom node", async () => {
expect(parse(``)).toEqual({
type: ASTType.DomNode,
tag: "div",
attrs: {},
on: {},
ref: null,
model: null,
content: [{ type: ASTType.TRaw, expr: "text", body: null }],
});
});
test("t-raw node with body", async () => {
expect(parse(`body
`)).toEqual({
type: ASTType.DomNode,
tag: "div",
attrs: {},
on: {},
ref: null,
model: null,
content: [
{ type: ASTType.TRaw, expr: "text", body: [{ type: ASTType.Text, value: "body" }] },
],
});
});
// ---------------------------------------------------------------------------
// t-if
// ---------------------------------------------------------------------------
test("t-if", async () => {
expect(parse(`hey
`)).toEqual({
type: ASTType.DomNode,
tag: "div",
attrs: {},
on: {},
ref: null,
model: null,
content: [
{
type: ASTType.TIf,
condition: "condition",
content: {
type: ASTType.Text,
value: "hey",
},
tElif: null,
tElse: null,
},
],
});
});
test("t-if (on dom node", async () => {
expect(parse(`hey
`)).toEqual({
type: ASTType.TIf,
condition: "condition",
content: {
type: ASTType.DomNode,
tag: "div",
attrs: {},
on: {},
ref: null,
model: null,
content: [{ type: ASTType.Text, value: "hey" }],
},
tElif: null,
tElse: null,
});
});
test("t-if and t else", async () => {
expect(parse(`heyelse`)).toEqual({
type: ASTType.TIf,
condition: "condition",
content: {
type: ASTType.Text,
value: "hey",
},
tElif: null,
tElse: {
type: ASTType.Text,
value: "else",
},
});
});
test("t-if and t elif", async () => {
expect(parse(`heyelif`)).toEqual({
type: ASTType.TIf,
condition: "condition",
content: {
type: ASTType.Text,
value: "hey",
},
tElif: [
{
condition: "cond2",
content: { type: ASTType.Text, value: "elif" },
},
],
tElse: null,
});
});
test("t-if, t-elif and t-else", async () => {
expect(parse(`heyelifelse`)).toEqual({
type: ASTType.TIf,
condition: "c1",
content: {
type: ASTType.Text,
value: "hey",
},
tElif: [
{
condition: "c2",
content: { type: ASTType.Text, value: "elif" },
},
],
tElse: {
type: ASTType.Text,
value: "else",
},
});
});
test("t-if, t-elif and t-else on a node", async () => {
expect(
parse(`hey
elif
else
`)
).toEqual({
type: ASTType.TIf,
condition: "c1",
content: {
type: ASTType.DomNode,
tag: "div",
attrs: {},
on: {},
ref: null,
model: null,
content: [
{
type: ASTType.Text,
value: "hey",
},
],
},
tElif: [
{
condition: "c2",
content: {
type: ASTType.DomNode,
tag: "h1",
attrs: {},
on: {},
ref: null,
model: null,
content: [{ type: ASTType.Text, value: "elif" }],
},
},
],
tElse: {
type: ASTType.DomNode,
tag: "h2",
attrs: {},
on: {},
ref: null,
model: null,
content: [
{
type: ASTType.Text,
value: "else",
},
],
},
});
});
// ---------------------------------------------------------------------------
// t-set
// ---------------------------------------------------------------------------
test("simple t-set expression", async () => {
expect(parse(``)).toEqual({
type: ASTType.TSet,
name: "key",
value: "value",
defaultValue: null,
body: null,
});
});
test("t-set expression with body", async () => {
expect(parse(`ok`)).toEqual({
type: ASTType.TSet,
name: "key",
defaultValue: "ok",
value: null,
body: null,
});
expect(parse(`ok
`)).toEqual({
type: ASTType.TSet,
name: "v",
defaultValue: null,
value: null,
body: [
{
type: ASTType.DomNode,
attrs: {},
on: {},
tag: "div",
ref: null,
model: null,
content: [{ type: ASTType.Text, value: "ok" }],
},
],
});
expect(parse(`ok
abc`)).toEqual({
type: ASTType.TSet,
name: "v",
defaultValue: null,
value: null,
body: [
{
type: ASTType.DomNode,
attrs: {},
on: {},
tag: "div",
ref: null,
model: null,
content: [{ type: ASTType.Text, value: "ok" }],
},
{ type: ASTType.Text, value: "abc" },
],
});
});
test("t-if and t-set expression with body", async () => {
expect(parse(`ok`)).toEqual({
type: ASTType.TIf,
condition: "flag",
content: {
type: ASTType.TSet,
name: "key",
defaultValue: "ok",
value: null,
body: null,
},
tElif: null,
tElse: null,
});
});
test("t-if, t-else and t-set", async () => {
expect(
parse(`1
`)
).toEqual({
type: ASTType.DomNode,
tag: "div",
attrs: {},
on: {},
ref: null,
model: null,
content: [
{
type: ASTType.TIf,
condition: "flag",
content: { type: ASTType.Text, value: "1" },
tElif: null,
tElse: { type: ASTType.TSet, name: "ourvar", value: "0", defaultValue: null, body: null },
},
],
});
});
// ---------------------------------------------------------------------------
// t-foreach
// ---------------------------------------------------------------------------
test("simple t-foreach expression, t-key mandatory", async () => {
expect(() =>
parse(``)
).toThrowErrorMatchingSnapshot();
});
test("simple t-foreach expression", async () => {
expect(
parse(``)
).toEqual({
type: ASTType.TForEach,
collection: "list",
elem: "item",
key: "item_index",
hasNoComponent: true,
isOnlyChild: false,
body: { type: ASTType.TEsc, expr: "item", defaultValue: "" },
memo: "",
hasNoFirst: true,
hasNoIndex: false,
hasNoLast: true,
hasNoValue: true,
});
});
test("t-foreach expression with t-esc", async () => {
expect(parse(``)).toEqual({
type: ASTType.TForEach,
collection: "list",
elem: "item",
key: "item_index",
hasNoComponent: true,
isOnlyChild: false,
body: { type: ASTType.TEsc, expr: "item", defaultValue: "" },
memo: "",
hasNoFirst: true,
hasNoIndex: false,
hasNoLast: true,
hasNoValue: true,
});
});
test("t-foreach on a div expression with t-esc", async () => {
expect(parse(``)).toEqual({
type: ASTType.TForEach,
collection: "list",
elem: "item",
hasNoComponent: true,
isOnlyChild: false,
key: "item_index",
body: {
type: ASTType.DomNode,
tag: "div",
attrs: {},
on: {},
ref: null,
model: null,
content: [{ type: ASTType.TEsc, expr: "item", defaultValue: "" }],
},
memo: "",
hasNoFirst: true,
hasNoIndex: false,
hasNoLast: true,
hasNoValue: true,
});
});
test("simple keyed t-foreach expression", async () => {
expect(parse(``)).toEqual({
type: ASTType.TForEach,
collection: "list",
elem: "item",
hasNoComponent: true,
isOnlyChild: false,
key: "item.id",
body: { type: ASTType.TEsc, expr: "item", defaultValue: "" },
memo: "",
hasNoFirst: true,
hasNoIndex: true,
hasNoLast: true,
hasNoValue: true,
});
});
test("t-foreach expression on a span", async () => {
expect(
parse(``)
).toEqual({
type: ASTType.TForEach,
collection: "list",
elem: "item",
key: "item_index",
hasNoComponent: true,
isOnlyChild: false,
body: {
type: ASTType.DomNode,
tag: "span",
attrs: {},
on: {},
ref: null,
model: null,
content: [{ type: ASTType.TEsc, expr: "item", defaultValue: "" }],
},
memo: "",
hasNoFirst: true,
hasNoIndex: false,
hasNoLast: true,
hasNoValue: true,
});
});
test("t-foreach expression on a span", async () => {
expect(
parse(
``
)
).toEqual({
type: ASTType.TForEach,
collection: "list",
elem: "item",
key: "item_index",
hasNoComponent: true,
isOnlyChild: false,
body: {
type: ASTType.TIf,
condition: "condition",
tElif: null,
tElse: null,
content: {
type: ASTType.DomNode,
tag: "span",
attrs: {},
on: {},
ref: null,
model: null,
content: [{ type: ASTType.TEsc, expr: "item", defaultValue: "" }],
},
},
memo: "",
hasNoFirst: true,
hasNoIndex: false,
hasNoLast: true,
hasNoValue: true,
});
});
test("more complex t-foreach expression on an option", async () => {
expect(
parse(
``
)
).toEqual({
type: ASTType.TForEach,
collection: "categories",
elem: "category",
key: "category_index",
hasNoComponent: true,
isOnlyChild: false,
body: {
type: ASTType.DomNode,
tag: "option",
attrs: {
"t-att-selected": "category.id==options.active_category_id",
"t-att-value": "category.id",
},
on: {},
ref: null,
model: null,
content: [{ type: ASTType.TEsc, expr: "category.name", defaultValue: "" }],
},
memo: "",
hasNoFirst: true,
hasNoIndex: false,
hasNoLast: true,
hasNoValue: true,
});
});
test("t-foreach in a div", async () => {
expect(
parse(`
`)
).toEqual({
type: ASTType.DomNode,
attrs: {},
on: {},
ref: null,
model: null,
tag: "div",
content: [
{
type: ASTType.TForEach,
collection: "list",
elem: "item",
key: "item_index",
hasNoComponent: true,
isOnlyChild: true,
body: { type: ASTType.TEsc, expr: "item", defaultValue: "" },
memo: "",
hasNoFirst: true,
hasNoIndex: false,
hasNoLast: true,
hasNoValue: true,
},
],
});
});
test("simple t-key expression", async () => {
expect(parse(`abc`)).toEqual({
type: ASTType.TKey,
expr: "k",
content: { type: ASTType.Text, value: "abc" },
});
});
test("t-foreach expression on a span with a t-key", async () => {
expect(
parse(``)
).toEqual({
type: ASTType.TForEach,
collection: "list",
elem: "item",
key: "item_index",
hasNoComponent: true,
isOnlyChild: false,
body: {
type: ASTType.DomNode,
tag: "span",
on: {},
ref: null,
model: null,
attrs: {},
content: [{ type: ASTType.TEsc, expr: "item", defaultValue: "" }],
},
memo: "",
hasNoFirst: true,
hasNoIndex: false,
hasNoLast: true,
hasNoValue: true,
});
});
test("t-foreach expression with a component inside", async () => {
expect(parse(``)).toEqual({
type: ASTType.TForEach,
collection: "list",
elem: "item",
key: "item_index",
hasNoComponent: false,
isOnlyChild: false,
body: {
type: ASTType.TComponent,
isDynamic: false,
name: "Comp",
dynamicProps: null,
props: {},
slots: {},
},
memo: "",
hasNoFirst: true,
hasNoIndex: false,
hasNoLast: true,
hasNoValue: true,
});
});
test("t-foreach expression with a t-call inside", async () => {
expect(
parse(``)
).toEqual({
type: ASTType.TForEach,
collection: "list",
elem: "item",
key: "item_index",
hasNoComponent: false,
isOnlyChild: false,
body: {
type: ASTType.TCall,
name: "blap",
body: null,
},
memo: "",
hasNoFirst: false,
hasNoIndex: false,
hasNoLast: false,
hasNoValue: false,
});
});
test("t-foreach expression with t-memo", async () => {
expect(
parse(
``
)
).toEqual({
type: ASTType.TForEach,
collection: "list",
elem: "item",
key: "item_index",
hasNoComponent: true,
isOnlyChild: false,
body: { type: ASTType.TEsc, expr: "item", defaultValue: "" },
memo: "[row.x]",
hasNoFirst: true,
hasNoIndex: false,
hasNoLast: true,
hasNoValue: true,
});
});
// ---------------------------------------------------------------------------
// t-call
// ---------------------------------------------------------------------------
test("simple t-call expression", async () => {
expect(parse(``)).toEqual({
type: ASTType.TCall,
name: "blabla",
body: null,
});
});
test("t-call with body", async () => {
expect(parse(`ok`)).toEqual({
type: ASTType.TCall,
name: "sub",
body: [{ type: ASTType.Text, value: "ok" }],
});
});
test("t-call on a div node", async () => {
expect(parse(``)).toEqual({
type: ASTType.DomNode,
tag: "div",
attrs: {},
on: {},
ref: null,
model: null,
content: [
{
type: ASTType.TCall,
name: "blabla",
body: null,
},
],
});
});
test("t-call with t-if", async () => {
expect(parse(``)).toEqual({
type: ASTType.TIf,
condition: "condition",
tElif: null,
tElse: null,
content: {
type: ASTType.TCall,
name: "blabla",
body: null,
},
});
});
// ---------------------------------------------------------------------------
// t-on
// ---------------------------------------------------------------------------
test("simple t-on expression", async () => {
expect(parse(``)).toEqual({
type: ASTType.DomNode,
tag: "button",
attrs: {},
on: { click: "add" },
ref: null,
model: null,
content: [{ type: ASTType.Text, value: "Click" }],
});
});
// ---------------------------------------------------------------------------
// t-component
// ---------------------------------------------------------------------------
test("just a plain component", async () => {
expect(parse(``)).toEqual({
type: ASTType.TComponent,
name: "MyComponent",
dynamicProps: null,
props: {},
slots: {},
isDynamic: false,
});
});
test("component with props", async () => {
expect(parse(``)).toEqual({
type: ASTType.TComponent,
name: "MyComponent",
dynamicProps: null,
props: { a: "1", b: "'b'" },
isDynamic: false,
slots: {},
});
});
test("component with t-props", async () => {
expect(parse(``)).toEqual({
type: ASTType.TComponent,
name: "MyComponent",
dynamicProps: "state",
props: { a: "1" },
isDynamic: false,
slots: {},
});
});
test("component with event handler", async () => {
expect(() => parse(``)).toThrow(
"t-on is no longer supported on Component node. Consider passing a callback in props."
);
});
test("a component with a default slot", async () => {
expect(parse(`foo`)).toEqual({
type: ASTType.TComponent,
name: "MyComponent",
dynamicProps: null,
props: {},
isDynamic: false,
slots: { default: { type: ASTType.Text, value: "foo" } },
});
});
test("a component with a default multi root slot", async () => {
expect(parse(``)).toEqual({
type: ASTType.TComponent,
name: "MyComponent",
isDynamic: false,
dynamicProps: null,
props: {},
slots: {
default: {
type: ASTType.Multi,
content: [
{
type: ASTType.DomNode,
tag: "span",
attrs: {},
content: [],
ref: null,
model: null,
on: {},
},
{
type: ASTType.DomNode,
tag: "div",
attrs: {},
content: [],
ref: null,
model: null,
on: {},
},
],
},
},
});
});
test("a component with a named slot", async () => {
expect(parse(`foo`)).toEqual({
type: ASTType.TComponent,
name: "MyComponent",
isDynamic: false,
dynamicProps: null,
props: {},
slots: { name: { type: ASTType.Text, value: "foo" } },
});
});
test("a component with a named slot and some white space", async () => {
expect(parse(`foo `)).toEqual({
type: ASTType.TComponent,
name: "MyComponent",
dynamicProps: null,
props: {},
isDynamic: false,
slots: {
default: { type: ASTType.Text, value: " " },
name: { type: ASTType.Text, value: "foo" },
},
});
});
test("a component with two named slot and some white space", async () => {
const template = `
foo
bar
`;
expect(parse(template)).toEqual({
type: ASTType.TComponent,
name: "MyComponent",
dynamicProps: null,
props: {},
isDynamic: false,
slots: {
a: { type: ASTType.Text, value: "foo" },
b: { type: ASTType.Text, value: "bar" },
},
});
});
test("dynamic t-component", async () => {
expect(parse(``)).toEqual({
type: ASTType.TComponent,
name: "myComponent",
dynamicProps: null,
props: {},
isDynamic: true,
slots: {},
});
});
test("dynamic component with props", async () => {
expect(parse(``)).toEqual({
type: ASTType.TComponent,
name: "mycomponent",
dynamicProps: null,
props: { a: "1", b: "'b'" },
isDynamic: true,
slots: {},
});
});
test("dynamic component with t-props", async () => {
expect(parse(``)).toEqual({
type: ASTType.TComponent,
name: "mycomponent",
dynamicProps: "state",
props: { a: "1" },
isDynamic: true,
slots: {},
});
});
test("component with t-esc", async () => {
expect(parse(``)).toEqual({
type: ASTType.TComponent,
name: "MyComponent",
dynamicProps: null,
props: {},
isDynamic: false,
slots: { default: { defaultValue: "", expr: "someValue", type: ASTType.TEsc } },
});
});
test("component with t-call", async () => {
expect(parse(``)).toEqual({
type: ASTType.TComponent,
name: "MyComponent",
dynamicProps: null,
props: {},
isDynamic: false,
slots: { default: { body: null, name: "subTemplate", type: ASTType.TCall } },
});
});
test("component with t-set-slot inside component", async () => {
const template = `
coucou
`;
expect(parse(template)).toEqual({
type: ASTType.TComponent,
name: "MyComponent",
dynamicProps: null,
props: {},
isDynamic: false,
slots: {
default: {
type: ASTType.TComponent,
isDynamic: false,
name: "Child",
dynamicProps: null,
props: {},
slots: { brol: { type: ASTType.Text, value: "coucou" } },
},
},
});
});
test("component with t-set-slot inside component, with an extra ", async () => {
const template = `
coucou
`;
expect(parse(template)).toEqual({
type: ASTType.TComponent,
name: "MyComponent",
dynamicProps: null,
props: {},
isDynamic: false,
slots: {
default: {
type: ASTType.TComponent,
isDynamic: false,
name: "Child",
dynamicProps: null,
props: {},
slots: { brol: { type: ASTType.Text, value: "coucou" } },
},
},
});
});
// ---------------------------------------------------------------------------
// t-slot
// ---------------------------------------------------------------------------
test("a simple t-slot", async () => {
expect(parse(``)).toEqual({
type: ASTType.TSlot,
name: "default",
defaultContent: null,
});
});
test("a t-slot with default content", async () => {
expect(parse(`default content`)).toEqual({
type: ASTType.TSlot,
name: "header",
defaultContent: { type: ASTType.Text, value: "default content" },
});
});
// ---------------------------------------------------------------------------
// t-debug
// ---------------------------------------------------------------------------
test("a t-debug on a dom node", async () => {
expect(parse(`hey
`)).toEqual({
type: ASTType.TDebug,
content: {
type: ASTType.DomNode,
tag: "div",
attrs: {},
on: {},
ref: null,
model: null,
content: [{ type: ASTType.Text, value: "hey" }],
},
});
});
test("a t-log on a dom node", async () => {
expect(parse(`hey
`)).toEqual({
type: ASTType.TLog,
expr: "bla",
content: {
type: ASTType.DomNode,
tag: "div",
attrs: {},
on: {},
ref: null,
model: null,
content: [{ type: ASTType.Text, value: "hey" }],
},
});
});
// ---------------------------------------------------------------------------
// t-ref
// ---------------------------------------------------------------------------
test("a t-ref on a dom node", async () => {
expect(parse(`hey
`)).toEqual({
type: ASTType.DomNode,
tag: "div",
attrs: {},
on: {},
ref: "name",
model: null,
content: [{ type: ASTType.Text, value: "hey" }],
});
});
test("node with t-ref and t-raw", async () => {
expect(parse(`body
`)).toEqual({
type: ASTType.DomNode,
tag: "div",
attrs: {},
on: {},
ref: "name",
model: null,
content: [
{ type: ASTType.TRaw, expr: "text", body: [{ type: ASTType.Text, value: "body" }] },
],
});
});
test("node with t-ref and t-esc", async () => {
expect(parse(`body
`)).toEqual({
type: ASTType.DomNode,
tag: "div",
attrs: {},
on: {},
ref: "name",
model: null,
content: [{ type: ASTType.TEsc, expr: "text", defaultValue: "body" }],
});
});
// ---------------------------------------------------------------------------
// t-call-block
// ---------------------------------------------------------------------------
test("simple t-call-block", async () => {
expect(parse(``)).toEqual({
type: ASTType.TCallBlock,
name: "myBlock",
});
});
// ---------------------------------------------------------------------------
// t-translation
// ---------------------------------------------------------------------------
test('t-translation="off"', async () => {
expect(parse(`word`)).toEqual({
type: ASTType.TTranslation,
content: {
type: ASTType.Text,
value: "word",
},
});
expect(
parse(`word
`)
).toEqual({
body: {
content: {
attrs: {},
content: [
{
type: 0,
value: "word",
},
],
on: {},
ref: null,
model: null,
tag: "div",
type: 2,
},
type: 16,
},
collection: "list",
elem: "item",
hasNoComponent: true,
hasNoFirst: true,
hasNoIndex: false,
hasNoLast: true,
hasNoValue: true,
isOnlyChild: false,
key: "item_index",
memo: "",
type: 9,
});
});
// ---------------------------------------------------------------------------
// t-model
// ---------------------------------------------------------------------------
test("t-model", async () => {
expect(parse(``)).toEqual({
type: ASTType.DomNode,
attrs: {},
content: [],
on: {},
ref: null,
tag: "input",
model: {
baseExpr: "state",
expr: "'stuff'",
eventType: "input",
shouldNumberize: false,
shouldTrim: false,
targetAttr: "value",
specialInitTargetAttr: null,
},
});
expect(parse(``)).toEqual({
type: ASTType.DomNode,
attrs: {},
content: [],
on: {},
ref: null,
tag: "input",
model: {
baseExpr: "state",
expr: "'stuff'",
eventType: "input",
shouldNumberize: false,
shouldTrim: false,
targetAttr: "value",
specialInitTargetAttr: null,
},
});
expect(parse(``)).toEqual({
type: ASTType.DomNode,
attrs: {},
content: [],
on: {},
ref: null,
tag: "input",
model: {
baseExpr: "state",
expr: "'stuff'",
eventType: "change",
shouldNumberize: true,
shouldTrim: true,
targetAttr: "value",
specialInitTargetAttr: null,
},
});
});
expect(parse(``)).toEqual({
type: ASTType.DomNode,
attrs: {},
content: [],
on: {},
ref: null,
tag: "textarea",
model: {
baseExpr: "state",
expr: "'stuff'",
eventType: "input",
shouldNumberize: false,
shouldTrim: false,
targetAttr: "value",
specialInitTargetAttr: null,
},
});
expect(parse(``)).toEqual({
type: ASTType.DomNode,
attrs: { type: "checkbox" },
content: [],
on: {},
ref: null,
tag: "input",
model: {
baseExpr: "state",
expr: "'stuff'",
eventType: "input",
shouldNumberize: false,
shouldTrim: false,
targetAttr: "checked",
specialInitTargetAttr: null,
},
});
expect(parse(``)).toEqual({
type: ASTType.DomNode,
attrs: { type: "radio" },
content: [],
on: {},
ref: null,
tag: "input",
model: {
baseExpr: "state",
expr: "'stuff'",
eventType: "click",
shouldNumberize: false,
shouldTrim: false,
targetAttr: "value",
specialInitTargetAttr: "checked",
},
});
expect(parse(``)).toEqual({
type: ASTType.DomNode,
attrs: { type: "radio" },
content: [],
on: {},
ref: null,
tag: "input",
model: {
baseExpr: "state",
expr: "'stuff'",
eventType: "click",
shouldNumberize: false,
shouldTrim: false,
targetAttr: "value",
specialInitTargetAttr: "checked",
},
});
});