diff --git a/changelog_unreleased/javascript/18736-2.md b/changelog_unreleased/javascript/18736-2.md new file mode 100644 index 000000000..ae85e93f2 --- /dev/null +++ b/changelog_unreleased/javascript/18736-2.md @@ -0,0 +1,28 @@ +#### Improve blank line detection between statements (#18736 by @fisker) + + +```jsx +// Input +const exports = text + .matchAll(/(?<=\n)exports\.(?\w+) = \k;/g) + .map((match) => match.groups.specifier) + .toArray() +; + +foo(); + +// Prettier stable (--no-semi) +const exports = text + .matchAll(/(?<=\n)exports\.(?\w+) = \k;/g) + .map((match) => match.groups.specifier) + .toArray(); +foo(); + +// Prettier main +const exports = text + .matchAll(/(?<=\n)exports\.(?\w+) = \k;/g) + .map((match) => match.groups.specifier) + .toArray(); + +foo(); +``` diff --git a/tests/format/js/no-semi/__snapshots__/format.test.js.snap b/tests/format/js/no-semi/__snapshots__/format.test.js.snap index f7c851cf4..9ce4cec39 100644 --- a/tests/format/js/no-semi/__snapshots__/format.test.js.snap +++ b/tests/format/js/no-semi/__snapshots__/format.test.js.snap @@ -1,5 +1,104 @@ // Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing +exports[`blank-lines.js - {"semi":false} format 1`] = ` +====================================options===================================== +parsers: ["babel", "typescript", "flow"] +semi: false + printWidth: 80 (default) | +=====================================input====================================== +const a1=foo + .bar() + ; + +bar(); + +const a2=foo + .bar() + ; + ++bar(); + +a=foo + .bar() + ; + +bar(); + +a=foo + .bar() + ; + ++bar(); + +=====================================output===================================== +const a1 = foo.bar() + +bar() + +const a2 = foo.bar() + +;+bar() + +a = foo.bar() + +bar() + +a = foo.bar() + +;+bar() + +================================================================================ +`; + +exports[`blank-lines.js format 1`] = ` +====================================options===================================== +parsers: ["babel", "typescript", "flow"] + printWidth: 80 (default) | +=====================================input====================================== +const a1=foo + .bar() + ; + +bar(); + +const a2=foo + .bar() + ; + ++bar(); + +a=foo + .bar() + ; + +bar(); + +a=foo + .bar() + ; + ++bar(); + +=====================================output===================================== +const a1 = foo.bar(); + +bar(); + +const a2 = foo.bar(); + ++bar(); + +a = foo.bar(); + +bar(); + +a = foo.bar(); + ++bar(); + +================================================================================ +`; + exports[`class.js - {"semi":false} format 1`] = ` ====================================options===================================== parsers: ["babel", "typescript", "flow"] diff --git a/tests/format/js/no-semi/blank-lines.js b/tests/format/js/no-semi/blank-lines.js new file mode 100644 index 000000000..c0a50d526 --- /dev/null +++ b/tests/format/js/no-semi/blank-lines.js @@ -0,0 +1,23 @@ +const a1=foo + .bar() + ; + +bar(); + +const a2=foo + .bar() + ; + ++bar(); + +a=foo + .bar() + ; + +bar(); + +a=foo + .bar() + ; + ++bar();