Fix lineSuffixBoundary (#10122)
This commit is contained in:
1 parent
bba719283d
commit
53b59d2d39
4 files changed
+126
-4
No files matched your search
@@ -0,0 +1,41 @@
|
||||
"use strict";
|
||||
|
||||
/** @type {import('prettier')} */
|
||||
const prettier = require("prettier-local");
|
||||
|
||||
const {
|
||||
group,
|
||||
indent,
|
||||
line,
|
||||
lineSuffix,
|
||||
lineSuffixBoundary,
|
||||
softline,
|
||||
} = prettier.doc.builders;
|
||||
|
||||
const printDoc = require("../printDoc");
|
||||
|
||||
describe("lineSuffixBoundary", () => {
|
||||
test("should be correctly treated as a potential line break in `fits`", () => {
|
||||
const doc = group([
|
||||
"let foo = [",
|
||||
indent([
|
||||
softline,
|
||||
[lineSuffixBoundary, "item1,"],
|
||||
line,
|
||||
[lineSuffixBoundary, "item2,", lineSuffix(" // comment")],
|
||||
line,
|
||||
[lineSuffixBoundary, "item3"],
|
||||
]),
|
||||
softline,
|
||||
"];",
|
||||
]);
|
||||
|
||||
const expected = `let foo = [
|
||||
item1,
|
||||
item2, // comment
|
||||
item3
|
||||
];`;
|
||||
|
||||
expect(printDoc(doc)).toBe(expected);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,30 @@
|
||||
"use strict";
|
||||
|
||||
/** @type {import('prettier')} */
|
||||
const prettier = require("prettier-local");
|
||||
|
||||
function printDoc(doc) {
|
||||
// This dummy plugin ignores the input and simply returns the given doc.
|
||||
// This is to make sure that the doc will go through all the stages a real doc
|
||||
// returned by a real plugin would go (e.g. `propagateBreaks`).
|
||||
const dummyPlugin = {
|
||||
parsers: {
|
||||
dummy: {
|
||||
parse: () => ({}),
|
||||
astFormat: "dummy",
|
||||
},
|
||||
},
|
||||
printers: {
|
||||
dummy: {
|
||||
print: () => doc,
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
return prettier.format("_", {
|
||||
plugins: [dummyPlugin],
|
||||
parser: "dummy",
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = printDoc;
|
||||
Reference in new issue
Block a user