Resolve rule of fill violation in JSX and add assertion. (#16700)

* add stricter assertion into fill()

* resolve rule of fill issue. some comments and naming can be problematic.

* cleanup

* update comments

* rename printWhitespace -> printStringOrLine

* refine isValidSeparator() a bit

* remove FIXME comment for fixed issue

* fix idempotency problem in MDX

* add changelog

* rename assertDocFill() -> assertDocFillParts()

* add test for assertDocFillParts()

* replace cleanDoc(doc) === "" by isEmptyDoc(doc)

* Update src/document/utils/assert-doc.js

Co-authored-by: fisker Cheung <lionkay@gmail.com>

---------

Co-authored-by: fisker Cheung <lionkay@gmail.com>
This commit is contained in:
Seiyaandfisker Cheung authored and GitHub committed 2025-01-21 13:09:32 +09:00
1 parent 9c5ca0dd6b
commit 97d8115d18
10 files changed
+238 -46

No files matched your search

+5
View File
@@ -11,6 +11,7 @@ import {
indentIfBreak,
join,
label,
line,
lineSuffix,
markAsRoot,
} from "../../src/document/builders.js";
@@ -49,6 +50,10 @@ describe("doc builders", () => {
[() => fill(), TypeError],
[() => fill(notArray), TypeError],
() => fill([invalidDoc]),
[() => fill(["abc", "abc"]), Error],
[() => fill(["abc", line, "def", "ghi"]), Error],
[() => fill(["abc", [line, "def"], "ghi"]), Error],
[() => fill(["abc", "", "def"]), Error],
() => ifBreak(),
() => ifBreak(invalidDoc),
+30
View File
@@ -0,0 +1,30 @@
import {
breakParent,
fill,
group,
line,
lineSuffix,
} from "../../src/document/builders.js";
import { cleanDoc, isEmptyDoc } from "../../src/document/utils.js";
it.each([
{ name: "empty string", doc: "" },
{ name: "non-empty string", doc: "a" },
{ name: "empty array", doc: [] },
{ name: "nested empty array", doc: [[[]]] },
{ name: "array with empty string", doc: [""] },
{ name: "non-empty array", doc: ["", "a", ""] },
{ name: "empty group", doc: group([]) },
{ name: "nested empty group", doc: group([group([])]) },
{ name: "group with empty string", doc: group([""]) },
{ name: "non-empty group", doc: group(["a"]) },
{ name: "empty fill", doc: fill([]) },
{ name: "fill with empty content", doc: fill([["", ""]]) },
{ name: "non-empty fill", doc: fill(["", line]) },
{ name: "empty line", doc: line },
{ name: "empty lineSuffix", doc: lineSuffix([]) },
{ name: "breakParent", doc: breakParent },
])("isEmptyDoc: $name", ({ doc }) => {
const expected = cleanDoc(doc) === "";
expect(isEmptyDoc(doc)).toBe(expected);
});