Skip to content

Commit

Permalink
fix: guess line ending before preprocess (#4957)
Browse files Browse the repository at this point in the history
  • Loading branch information
ikatyang committed Aug 9, 2018
1 parent 3842cbb commit 53c83f9
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
4 changes: 3 additions & 1 deletion src/main/core.js
Expand Up @@ -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) {
Expand All @@ -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);

Expand Down
5 changes: 1 addition & 4 deletions tests_integration/__tests__/__snapshots__/format.js.snap
Expand Up @@ -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\\""`;
5 changes: 4 additions & 1 deletion tests_integration/__tests__/format.js
Expand Up @@ -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", () => {
Expand Down

0 comments on commit 53c83f9

Please sign in to comment.