release: WRNexusJS 0.2.77
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
import { describe, expect, test } from "bun:test";
|
||||
import { parse, type PropDecl } from "../src/parser.ts";
|
||||
|
||||
const compact = (source: string) =>
|
||||
parse(source).props.map(({ name, default: value }: PropDecl) => ({ name, value }));
|
||||
|
||||
describe("inline props", () => {
|
||||
test("parses multiple props declared on one line", () => {
|
||||
expect(
|
||||
compact(
|
||||
`component Example { props { eyebrow = "" title = "" description = "" align = "start" class = "" } view { <div></div> } }`,
|
||||
),
|
||||
).toEqual([
|
||||
{ name: "eyebrow", value: '""' },
|
||||
{ name: "title", value: '""' },
|
||||
{ name: "description", value: '""' },
|
||||
{ name: "align", value: '"start"' },
|
||||
{ name: "class", value: '""' },
|
||||
]);
|
||||
});
|
||||
|
||||
test("preserves nested object and array defaults", () => {
|
||||
expect(
|
||||
compact(
|
||||
`component Example { props { items = [{ label: "A" }, { label: "B" }] options = { gap: 4, dense: false } class = "" } view { <div></div> } }`,
|
||||
),
|
||||
).toEqual([
|
||||
{ name: "items", value: '[{ label: "A" }, { label: "B" }]' },
|
||||
{ name: "options", value: "{ gap: 4, dense: false }" },
|
||||
{ name: "class", value: '""' },
|
||||
]);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user