fix: guess line ending before preprocess (#4957)
parent
3842cbb118
commit
53c83f97f5
|
@ -71,6 +71,8 @@ function coreFormat(text, opts, addAlignmentSize) {
|
|||
|
||||
const parsed = parser.parse(text, opts);
|
||||
const ast = parsed.ast;
|
||||
|
||||
const originalText = text;
|
||||
text = parsed.text;
|
||||
|
||||
if (opts.cursorOffset >= 0) {
|
||||
|
@ -82,7 +84,7 @@ function coreFormat(text, opts, addAlignmentSize) {
|
|||
|
||||
const astComments = attachComments(text, ast, opts);
|
||||
const doc = printAstToDoc(ast, opts, addAlignmentSize);
|
||||
opts.newLine = guessLineEnding(text);
|
||||
opts.newLine = guessLineEnding(originalText);
|
||||
|
||||
const result = printDocToString(doc, opts);
|
||||
|
||||
|
|
|
@ -9,7 +9,4 @@ exports[`typescript parser should throw the first error when both JSX and non-JS
|
|||
10 | "
|
||||
`;
|
||||
|
||||
exports[`yaml parser should handle CRLF correctly 1`] = `
|
||||
"a: 123
|
||||
"
|
||||
`;
|
||||
exports[`yaml parser should handle CRLF correctly 1`] = `"\\"a: 123\\\\r\\\\n\\""`;
|
||||
|
|
|
@ -4,7 +4,10 @@ const prettier = require("prettier/local");
|
|||
|
||||
test("yaml parser should handle CRLF correctly", () => {
|
||||
const input = "a:\r\n 123\r\n";
|
||||
expect(prettier.format(input, { parser: "yaml" })).toMatchSnapshot();
|
||||
expect(
|
||||
// use JSON.stringify to observe CRLF
|
||||
JSON.stringify(prettier.format(input, { parser: "yaml" }))
|
||||
).toMatchSnapshot();
|
||||
});
|
||||
|
||||
test("typescript parser should throw the first error when both JSX and non-JSX mode failed", () => {
|
||||
|
|
Loading…
Reference in New Issue