diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/arrays/preserve_empty_lines.js b/crates/rome_js_formatter/tests/specs/prettier/js/arrays/preserve_empty_lines.js index 0cd853eef8d..63bf3c725e7 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/js/arrays/preserve_empty_lines.js +++ b/crates/rome_js_formatter/tests/specs/prettier/js/arrays/preserve_empty_lines.js @@ -10,3 +10,84 @@ a = [ ] + +b = [ + 100, + + (200) + , + + 300 + , + + 1 + , + 2, 3 +] + +c = [ + "apple", + "banana", + "blueberry", + + "red", + "blue" + , + "yellow", + + "broccoli", + "celery", + "lettuce" + , + + "green" + , + "green", + "green", + + //an egg + "egg", + //a bigger egg + "big egg" + //the biggest egg + , + "huge egg" + , + + //not an egg + "lasagna" + +] + +_ = [ + a, + + b // +] + +_ = [ + (a), + + b, // +]; + +_ = [ + ((((( + a = b/* comment */))/* comment */))), + + c // +] + +_ = [ + ((((( + (a = b)/* comment */))/* comment */))), + + c // +] + +_ = [ + (a=b + + ), + b, // +]; diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/arrays/preserve_empty_lines.js.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/js/arrays/preserve_empty_lines.js.prettier-snap index a73ffffbfff..a1d3885e58f 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/js/arrays/preserve_empty_lines.js.prettier-snap +++ b/crates/rome_js_formatter/tests/specs/prettier/js/arrays/preserve_empty_lines.js.prettier-snap @@ -5,3 +5,70 @@ a = [ 4, ]; + +b = [ + 100, + + 200, + + 300, + + 1, 2, 3, +]; + +c = [ + "apple", + "banana", + "blueberry", + + "red", + "blue", + "yellow", + + "broccoli", + "celery", + "lettuce", + + "green", + "green", + "green", + + //an egg + "egg", + //a bigger egg + "big egg", + //the biggest egg + "huge egg", + + //not an egg + "lasagna", +]; + +_ = [ + a, + + b, // +]; + +_ = [ + a, + + b, // +]; + +_ = [ + (a = b) /* comment */ /* comment */, + + c, // +]; + +_ = [ + (a = b) /* comment */ /* comment */, + + c, // +]; + +_ = [ + (a = b), + b, // +]; diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/arrays/tuple-and-record.js b/crates/rome_js_formatter/tests/specs/prettier/js/arrays/tuple-and-record.js new file mode 100644 index 00000000000..984ee8f338b --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/arrays/tuple-and-record.js @@ -0,0 +1,19 @@ +a = [ + [1,2], + [1,2], +] + +a = [ + #[1,2], + #[1,2], +] + +a = [ + {a, b}, + {a, b}, +] + +a = [ + #{a, b}, + #{a, b}, +] diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/arrays/tuple-and-record.js.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/js/arrays/tuple-and-record.js.prettier-snap new file mode 100644 index 00000000000..4c0747505d5 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/arrays/tuple-and-record.js.prettier-snap @@ -0,0 +1,19 @@ +a = [ + [1, 2], + [1, 2], +]; + +a = [ + #[1, 2], + #[1, 2], +]; + +a = [ + { a, b }, + { a, b }, +]; + +a = [ + #{ a, b }, + #{ a, b }, +]; diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/arrays/tuple-and-record.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/arrays/tuple-and-record.js.snap new file mode 100644 index 00000000000..89ecee9896a --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/arrays/tuple-and-record.js.snap @@ -0,0 +1,259 @@ +--- +source: crates/rome_formatter_test/src/snapshot_builder.rs +info: js/arrays/tuple-and-record.js +--- + +# Input + +```js +a = [ + [1,2], + [1,2], +] + +a = [ + #[1,2], + #[1,2], +] + +a = [ + {a, b}, + {a, b}, +] + +a = [ + #{a, b}, + #{a, b}, +] + +``` + + +# Prettier differences + +```diff +--- Prettier ++++ Rome +@@ -4,9 +4,9 @@ + ]; + + a = [ +- #[1, 2], +- #[1, 2], +-]; ++ #[1,2], ++ #[1,2], ++] + + a = [ + { a, b }, +@@ -14,6 +14,6 @@ + ]; + + a = [ +- #{ a, b }, +- #{ a, b }, +-]; ++ #{a, b}, ++ #{a, b}, ++] +``` + +# Output + +```js +a = [ + [1, 2], + [1, 2], +]; + +a = [ + #[1,2], + #[1,2], +] + +a = [ + { a, b }, + { a, b }, +]; + +a = [ + #{a, b}, + #{a, b}, +] +``` + +# Errors +``` +tuple-and-record.js:7:4 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × expected an identifier but instead found '[' + + 6 │ a = [ + > 7 │ #[1,2], + │ ^ + 8 │ #[1,2], + 9 │ ] + + i Expected an identifier here + + 6 │ a = [ + > 7 │ #[1,2], + │ ^ + 8 │ #[1,2], + 9 │ ] + +tuple-and-record.js:7:3 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × Private names are only allowed on the left side of a 'in' expression + + 6 │ a = [ + > 7 │ #[1,2], + │ ^ + 8 │ #[1,2], + 9 │ ] + +tuple-and-record.js:7:4 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × expected `,` but instead found `[` + + 6 │ a = [ + > 7 │ #[1,2], + │ ^ + 8 │ #[1,2], + 9 │ ] + + i Remove [ + +tuple-and-record.js:8:4 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × expected an identifier but instead found '[' + + 6 │ a = [ + 7 │ #[1,2], + > 8 │ #[1,2], + │ ^ + 9 │ ] + 10 │ + + i Expected an identifier here + + 6 │ a = [ + 7 │ #[1,2], + > 8 │ #[1,2], + │ ^ + 9 │ ] + 10 │ + +tuple-and-record.js:8:3 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × Private names are only allowed on the left side of a 'in' expression + + 6 │ a = [ + 7 │ #[1,2], + > 8 │ #[1,2], + │ ^ + 9 │ ] + 10 │ + +tuple-and-record.js:8:4 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × expected `,` but instead found `[` + + 6 │ a = [ + 7 │ #[1,2], + > 8 │ #[1,2], + │ ^ + 9 │ ] + 10 │ + + i Remove [ + +tuple-and-record.js:17:4 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × expected an identifier but instead found '{' + + 16 │ a = [ + > 17 │ #{a, b}, + │ ^ + 18 │ #{a, b}, + 19 │ ] + + i Expected an identifier here + + 16 │ a = [ + > 17 │ #{a, b}, + │ ^ + 18 │ #{a, b}, + 19 │ ] + +tuple-and-record.js:17:3 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × Private names are only allowed on the left side of a 'in' expression + + 16 │ a = [ + > 17 │ #{a, b}, + │ ^ + 18 │ #{a, b}, + 19 │ ] + +tuple-and-record.js:17:4 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × expected `,` but instead found `{` + + 16 │ a = [ + > 17 │ #{a, b}, + │ ^ + 18 │ #{a, b}, + 19 │ ] + + i Remove { + +tuple-and-record.js:18:4 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × expected an identifier but instead found '{' + + 16 │ a = [ + 17 │ #{a, b}, + > 18 │ #{a, b}, + │ ^ + 19 │ ] + 20 │ + + i Expected an identifier here + + 16 │ a = [ + 17 │ #{a, b}, + > 18 │ #{a, b}, + │ ^ + 19 │ ] + 20 │ + +tuple-and-record.js:18:3 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × Private names are only allowed on the left side of a 'in' expression + + 16 │ a = [ + 17 │ #{a, b}, + > 18 │ #{a, b}, + │ ^ + 19 │ ] + 20 │ + +tuple-and-record.js:18:4 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × expected `,` but instead found `{` + + 16 │ a = [ + 17 │ #{a, b}, + > 18 │ #{a, b}, + │ ^ + 19 │ ] + 20 │ + + i Remove { + + +``` + + diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/arrows-bind/arrows-bind.js.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/js/arrows-bind/arrows-bind.js.prettier-snap index 3580170133c..bee48590fd4 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/js/arrows-bind/arrows-bind.js.prettier-snap +++ b/crates/rome_js_formatter/tests/specs/prettier/js/arrows-bind/arrows-bind.js.prettier-snap @@ -1,3 +1,3 @@ -(a) => ({}::b()``[""].c++ && 0 ? 0 : 0); +(a) => ({})::b()``[""].c++ && 0 ? 0 : 0; ((a) => b)::c; a::((b) => c); diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/arrows-bind/arrows-bind.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/arrows-bind/arrows-bind.js.snap index 025322a9cf5..9e0f52746fa 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/js/arrows-bind/arrows-bind.js.snap +++ b/crates/rome_js_formatter/tests/specs/prettier/js/arrows-bind/arrows-bind.js.snap @@ -1,6 +1,5 @@ --- source: crates/rome_formatter_test/src/snapshot_builder.rs -assertion_line: 212 info: js/arrows-bind/arrows-bind.js --- @@ -20,7 +19,7 @@ a::(b => c); --- Prettier +++ Rome @@ -1,3 +1,6 @@ --(a) => ({}::b()``[""].c++ && 0 ? 0 : 0); +-(a) => ({})::b()``[""].c++ && 0 ? 0 : 0; -((a) => b)::c; -a::((b) => c); +a => ({} diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/arrows/arrow_function_expression.js.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/js/arrows/arrow_function_expression.js.prettier-snap index b30b8e02c63..4d79ffee9f0 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/js/arrows/arrow_function_expression.js.prettier-snap +++ b/crates/rome_js_formatter/tests/specs/prettier/js/arrows/arrow_function_expression.js.prettier-snap @@ -6,24 +6,24 @@ export default (() => {})(); new (() => {})(); if ((() => {}) ? 1 : 0) { } -let f = () => ({}()); -let a = () => ({} instanceof a); -a = () => ({} && a); -a = () => ({}() && a); -a = () => ({} && a && b); -a = () => ({} + a); -a = () => ({}()() && a); -a = () => ({}.b && a); -a = () => ({}[b] && a); -a = () => ({}`` && a); +let f = () => ({})(); +let a = () => ({}) instanceof a; +a = () => ({}) && a; +a = () => ({})() && a; +a = () => ({}) && a && b; +a = () => ({}) + a; +a = () => ({})()() && a; +a = () => ({}).b && a; +a = () => ({})[b] && a; +a = () => ({})`` && a; a = () => ({} = 0); a = () => ({}, a); (a) => a instanceof {}; -(a) => ({}().b && 0); +(a) => ({})().b && 0; (a) => ({}().c = 0); -(x) => ({}()()); -(x) => ({}()``); -(x) => ({}().b); +(x) => ({})()(); +(x) => ({})()``; +(x) => ({})().b; a = (b) => c; (x) => (y = z); (x) => (y += z); diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/arrows/arrow_function_expression.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/arrows/arrow_function_expression.js.snap index 27fb7118aff..00abd833089 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/js/arrows/arrow_function_expression.js.snap +++ b/crates/rome_js_formatter/tests/specs/prettier/js/arrows/arrow_function_expression.js.snap @@ -1,6 +1,5 @@ --- source: crates/rome_formatter_test/src/snapshot_builder.rs -assertion_line: 212 info: js/arrows/arrow_function_expression.js --- @@ -50,47 +49,19 @@ a = b => { ```diff --- Prettier +++ Rome -@@ -6,24 +6,24 @@ - new (() => {})(); - if ((() => {}) ? 1 : 0) { - } --let f = () => ({}()); --let a = () => ({} instanceof a); --a = () => ({} && a); --a = () => ({}() && a); --a = () => ({} && a && b); --a = () => ({} + a); --a = () => ({}()() && a); --a = () => ({}.b && a); --a = () => ({}[b] && a); --a = () => ({}`` && a); -+let f = () => ({})(); -+let a = () => ({}) instanceof a; -+a = () => ({}) && a; -+a = () => ({})() && a; -+a = () => ({}) && a && b; -+a = () => ({}) + a; -+a = () => ({})()() && a; -+a = () => ({}).b && a; -+a = () => ({})[b] && a; -+a = () => ({})`` && a; +@@ -17,10 +17,10 @@ + a = () => ({})[b] && a; + a = () => ({})`` && a; a = () => ({} = 0); -a = () => ({}, a); +a = () => (({}), a); (a) => a instanceof {}; --(a) => ({}().b && 0); + (a) => ({})().b && 0; -(a) => ({}().c = 0); --(x) => ({}()()); --(x) => ({}()``); --(x) => ({}().b); -+(a) => ({})().b && 0; +(a) => (({})().c = 0); -+(x) => ({})()(); -+(x) => ({})()``; -+(x) => ({})().b; - a = (b) => c; - (x) => (y = z); - (x) => (y += z); + (x) => ({})()(); + (x) => ({})()``; + (x) => ({})().b; ``` # Output diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/arrows/chain-as-arg.js b/crates/rome_js_formatter/tests/specs/prettier/js/arrows/chain-as-arg.js new file mode 100644 index 00000000000..9614d9d8211 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/arrows/chain-as-arg.js @@ -0,0 +1,38 @@ +const w = a.b( + ( + c = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdef", + d = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdef" + ) => + (e) => + 0 +); + +const x = a.b( + ( + c = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdef", + d = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdef" + ) => + (e) => + 0 +)(x); + +const y = a.b( + 1, + ( + c = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdef", + d = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdef" + ) => + (e) => + 0 +)(x); + +const z = a.b( + ( + c = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdef", + d = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdef" + ) => + (e) => + 0, + 2 +)(x); + diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/arrows/chain-as-arg.js.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/js/arrows/chain-as-arg.js.prettier-snap new file mode 100644 index 00000000000..a1902e7d567 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/arrows/chain-as-arg.js.prettier-snap @@ -0,0 +1,37 @@ +const w = a.b( + ( + c = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdef", + d = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdef", + ) => + (e) => + 0, +); + +const x = a.b( + ( + c = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdef", + d = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdef", + ) => + (e) => + 0, +)(x); + +const y = a.b( + 1, + ( + c = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdef", + d = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdef", + ) => + (e) => + 0, +)(x); + +const z = a.b( + ( + c = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdef", + d = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdef", + ) => + (e) => + 0, + 2, +)(x); diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/arrows/chain-as-arg.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/arrows/chain-as-arg.js.snap new file mode 100644 index 00000000000..4512d935431 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/arrows/chain-as-arg.js.snap @@ -0,0 +1,149 @@ +--- +source: crates/rome_formatter_test/src/snapshot_builder.rs +info: js/arrows/chain-as-arg.js +--- + +# Input + +```js +const w = a.b( + ( + c = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdef", + d = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdef" + ) => + (e) => + 0 +); + +const x = a.b( + ( + c = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdef", + d = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdef" + ) => + (e) => + 0 +)(x); + +const y = a.b( + 1, + ( + c = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdef", + d = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdef" + ) => + (e) => + 0 +)(x); + +const z = a.b( + ( + c = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdef", + d = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdef" + ) => + (e) => + 0, + 2 +)(x); + + +``` + + +# Prettier differences + +```diff +--- Prettier ++++ Rome +@@ -1,17 +1,17 @@ + const w = a.b( + ( +- c = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdef", +- d = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdef", +- ) => ++ c = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdef", ++ d = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdef", ++ ) => + (e) => + 0, + ); + + const x = a.b( + ( +- c = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdef", +- d = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdef", +- ) => ++ c = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdef", ++ d = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdef", ++ ) => + (e) => + 0, + )(x); +@@ -19,18 +19,18 @@ + const y = a.b( + 1, + ( +- c = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdef", +- d = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdef", +- ) => ++ c = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdef", ++ d = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdef", ++ ) => + (e) => + 0, + )(x); + + const z = a.b( + ( +- c = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdef", +- d = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdef", +- ) => ++ c = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdef", ++ d = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdef", ++ ) => + (e) => + 0, + 2, +``` + +# Output + +```js +const w = a.b( + ( + c = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdef", + d = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdef", + ) => + (e) => + 0, +); + +const x = a.b( + ( + c = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdef", + d = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdef", + ) => + (e) => + 0, +)(x); + +const y = a.b( + 1, + ( + c = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdef", + d = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdef", + ) => + (e) => + 0, +)(x); + +const z = a.b( + ( + c = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdef", + d = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdef", + ) => + (e) => + 0, + 2, +)(x); +``` + + diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/arrows/chain-in-logical-expression.js b/crates/rome_js_formatter/tests/specs/prettier/js/arrows/chain-in-logical-expression.js new file mode 100644 index 00000000000..cc7ab253e62 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/arrows/chain-in-logical-expression.js @@ -0,0 +1,8 @@ +const x = a.b ?? ( + ( + c = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdef", + d = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdef" + ) => + (e) => + 0 +); diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/arrows/chain-in-logical-expression.js.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/js/arrows/chain-in-logical-expression.js.prettier-snap new file mode 100644 index 00000000000..2016988bc94 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/arrows/chain-in-logical-expression.js.prettier-snap @@ -0,0 +1,8 @@ +const x = + a.b ?? + (( + c = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdef", + d = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdef", + ) => + (e) => + 0); diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/arrows/chain-in-logical-expression.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/arrows/chain-in-logical-expression.js.snap new file mode 100644 index 00000000000..8316c7b0c6b --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/arrows/chain-in-logical-expression.js.snap @@ -0,0 +1,53 @@ +--- +source: crates/rome_formatter_test/src/snapshot_builder.rs +info: js/arrows/chain-in-logical-expression.js +--- + +# Input + +```js +const x = a.b ?? ( + ( + c = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdef", + d = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdef" + ) => + (e) => + 0 +); + +``` + + +# Prettier differences + +```diff +--- Prettier ++++ Rome +@@ -1,8 +1,8 @@ + const x = + a.b ?? + (( +- c = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdef", +- d = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdef", +- ) => ++ c = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdef", ++ d = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdef", ++ ) => + (e) => + 0); +``` + +# Output + +```js +const x = + a.b ?? + (( + c = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdef", + d = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdef", + ) => + (e) => + 0); +``` + + diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/arrows/comment.js b/crates/rome_js_formatter/tests/specs/prettier/js/arrows/comment.js index 66b10122963..fc0d1a06150 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/js/arrows/comment.js +++ b/crates/rome_js_formatter/tests/specs/prettier/js/arrows/comment.js @@ -28,3 +28,24 @@ export const bem = block => ) => {info.item.widget.missingProp}} data={data} /> + +func(() => // comment +a); +func(() => () => // comment +a); +func(() => () => () => // comment +a); + +func(() => // comment +a ? b : c); +func(() => () => // comment +a ? b : c); +func(() => () => () => // comment +a ? b : c); + +func(() => // comment +(a , b , c)) +func(() => () => // comment +(a , b , c)) +func(() => () => () => // comment +(a , b , c)) diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/arrows/comment.js.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/js/arrows/comment.js.prettier-snap index 2f1ac32f6e2..c6ba4d59fc7 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/js/arrows/comment.js.prettier-snap +++ b/crates/rome_js_formatter/tests/specs/prettier/js/arrows/comment.js.prettier-snap @@ -29,3 +29,56 @@ export const bem = ) => {info.item.widget.missingProp}} data={data} />; + +func( + () => + // comment + a, +); +func( + () => () => + // comment + a, +); +func( + () => () => () => + // comment + a, +); + +func(() => + // comment + a ? b : c, +); +func( + () => () => + // comment + a ? b : c, +); +func( + () => () => () => + // comment + a ? b : c, +); + +func( + () => + ( + // comment + a, b, c + ), +); +func( + () => () => + ( + // comment + a, b, c + ), +); +func( + () => () => () => + ( + // comment + a, b, c + ), +); diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/arrows/comment.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/arrows/comment.js.snap new file mode 100644 index 00000000000..299b0b971ec --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/arrows/comment.js.snap @@ -0,0 +1,242 @@ +--- +source: crates/rome_formatter_test/src/snapshot_builder.rs +info: js/arrows/comment.js +--- + +# Input + +```js +/** + * Curried function that ends with a BEM CSS Selector + * + * @param {String} block - the BEM Block you'd like to select. + * @returns {Function} + */ +export const bem = block => + /** + * @param {String} [element] - the BEM Element within that block; if undefined, selects the block itself. + * @returns {Function} + */ + element => + /** + * @param {?String} [modifier] - the BEM Modifier for the Block or Element; if undefined, selects the Block or Element unmodified. + * @returns {String} + */ + modifier => + [ + ".", + css(block), + element ? `__${css(element)}` : "", + modifier ? `--${css(modifier)}` : "" + ].join(""); + + {info.item.widget.missingProp}} + data={data} +/> + +func(() => // comment +a); +func(() => () => // comment +a); +func(() => () => () => // comment +a); + +func(() => // comment +a ? b : c); +func(() => () => // comment +a ? b : c); +func(() => () => () => // comment +a ? b : c); + +func(() => // comment +(a , b , c)) +func(() => () => // comment +(a , b , c)) +func(() => () => () => // comment +(a , b , c)) + +``` + + +# Prettier differences + +```diff +--- Prettier ++++ Rome +@@ -31,54 +31,50 @@ + />; + + func( +- () => +- // comment +- a, ++ () => a, // comment + ); + func( +- () => () => +- // comment +- a, ++ () => ++ () => // comment ++ a, + ); + func( +- () => () => () => +- // comment +- a, ++ () => ++ () => ++ () => // comment ++ a, + ); + +-func(() => +- // comment +- a ? b : c, ++func( ++ () => (a ? b : c), // comment + ); + func( +- () => () => +- // comment +- a ? b : c, ++ () => ++ () => // comment ++ a ? b : c, + ); + func( +- () => () => () => +- // comment +- a ? b : c, ++ () => ++ () => ++ () => // comment ++ a ? b : c, + ); + + func( +- () => +- ( +- // comment +- a, b, c +- ), ++ () => ( // comment ++ a, b, c ++ ), + ); + func( +- () => () => +- ( +- // comment ++ () => ++ () => ( // comment + a, b, c + ), + ); + func( +- () => () => () => +- ( +- // comment ++ () => ++ () => ++ () => ( // comment + a, b, c + ), + ); +``` + +# Output + +```js +/** + * Curried function that ends with a BEM CSS Selector + * + * @param {String} block - the BEM Block you'd like to select. + * @returns {Function} + */ +export const bem = + (block) => + /** + * @param {String} [element] - the BEM Element within that block; if undefined, selects the block itself. + * @returns {Function} + */ + (element) => + /** + * @param {?String} [modifier] - the BEM Modifier for the Block or Element; if undefined, selects the Block or Element unmodified. + * @returns {String} + */ + (modifier) => + [ + ".", + css(block), + element ? `__${css(element)}` : "", + modifier ? `--${css(modifier)}` : "", + ].join(""); + + {info.item.widget.missingProp}} + data={data} +/>; + +func( + () => a, // comment +); +func( + () => + () => // comment + a, +); +func( + () => + () => + () => // comment + a, +); + +func( + () => (a ? b : c), // comment +); +func( + () => + () => // comment + a ? b : c, +); +func( + () => + () => + () => // comment + a ? b : c, +); + +func( + () => ( // comment + a, b, c + ), +); +func( + () => + () => ( // comment + a, b, c + ), +); +func( + () => + () => + () => ( // comment + a, b, c + ), +); +``` + +# Lines exceeding max width of 80 characters +``` + 10: * @param {String} [element] - the BEM Element within that block; if undefined, selects the block itself. + 15: * @param {?String} [modifier] - the BEM Modifier for the Block or Element; if undefined, selects the Block or Element unmodified. +``` + + diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/arrows/currying-4.js b/crates/rome_js_formatter/tests/specs/prettier/js/arrows/currying-4.js new file mode 100644 index 00000000000..7aaaeef0aba --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/arrows/currying-4.js @@ -0,0 +1,60 @@ +Y(() => a ? b : c); + +Y(() => () => a ? b : c); + +Y(() => () => () => a ? b : c); + +Y(() => longlonglonglonglonglonglonglonglonglongCondition ? 'Prettier is an opinionated code formatter.' : 'Prettier takes your code and reprints it from scratch by taking the line length into account.') + +Y(() => () => longlonglonglonglonglonglonglonglonglongCondition ? 'Prettier is an opinionated code formatter.' : 'Prettier takes your code and reprints it from scratch by taking the line length into account.') + +Y(() => () => () => longlonglonglonglonglonglonglonglonglongCondition ? 'Prettier is an opinionated code formatter.' : 'Prettier takes your code and reprints it from scratch by taking the line length into account.') + +const x1 = (() => ['The', 'green', 'dragon', 'liked', 'to', 'knit', 'sweaters', 'for', 'the', 'fluffy', 'clouds', 'in', 'the', 'sky.']) + +const x2 = (() => () => ['The', 'green', 'dragon', 'liked', 'to', 'knit', 'sweaters', 'for', 'the', 'fluffy', 'clouds', 'in', 'the', 'sky.']) + +const x3 = (() => () => () => ['The', 'green', 'dragon', 'liked', 'to', 'knit', 'sweaters', 'for', 'the', 'fluffy', 'clouds', 'in', 'the', 'sky.']) + +f((a) => (1, 2, 3) /* a */); +f((a) => ( + (b) => (1, 2, 3) /* b */ +) /* a */); +f((a) => ( + (b) => ( + (c) => (1, 2, 3) /* c */ + ) /* b */ +) /* a */); + +f((a) => (1 ? 2 : 3) /* a */); +f((a) => ( + (b) => (1 ? 2 : 3) /* b */ +) /* a */); +f((a) => ( + (b) => ( + (c) => (1 ? 2 : 3) /* c */ + ) /* b */ +) /* a */); + +a( + "", + "", + ({}) => + () => + () => + () => + () => + () => + () => test, +); +a( + "", + "", + ({}) => + () => + () => + () => + () => + () => + () => (test ? 1 : 2), +); diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/arrows/currying-4.js.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/js/arrows/currying-4.js.prettier-snap new file mode 100644 index 00000000000..9619e96cba2 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/arrows/currying-4.js.prettier-snap @@ -0,0 +1,109 @@ +Y(() => (a ? b : c)); + +Y(() => () => (a ? b : c)); + +Y(() => () => () => (a ? b : c)); + +Y(() => + longlonglonglonglonglonglonglonglonglongCondition + ? "Prettier is an opinionated code formatter." + : "Prettier takes your code and reprints it from scratch by taking the line length into account.", +); + +Y( + () => () => + longlonglonglonglonglonglonglonglonglongCondition + ? "Prettier is an opinionated code formatter." + : "Prettier takes your code and reprints it from scratch by taking the line length into account.", +); + +Y( + () => () => () => + longlonglonglonglonglonglonglonglonglongCondition + ? "Prettier is an opinionated code formatter." + : "Prettier takes your code and reprints it from scratch by taking the line length into account.", +); + +const x1 = () => [ + "The", + "green", + "dragon", + "liked", + "to", + "knit", + "sweaters", + "for", + "the", + "fluffy", + "clouds", + "in", + "the", + "sky.", +]; + +const x2 = () => () => [ + "The", + "green", + "dragon", + "liked", + "to", + "knit", + "sweaters", + "for", + "the", + "fluffy", + "clouds", + "in", + "the", + "sky.", +]; + +const x3 = () => () => () => [ + "The", + "green", + "dragon", + "liked", + "to", + "knit", + "sweaters", + "for", + "the", + "fluffy", + "clouds", + "in", + "the", + "sky.", +]; + +f((a) => (1, 2, 3) /* a */); +f((a) => (b) => (1, 2, 3) /* b */ /* a */); +f((a) => (b) => (c) => (1, 2, 3) /* c */ /* b */ /* a */); + +f((a) => (1 ? 2 : 3) /* a */); +f((a) => (b) => (1 ? 2 : 3) /* b */ /* a */); +f((a) => (b) => (c) => (1 ? 2 : 3) /* c */ /* b */ /* a */); + +a( + "", + "", + ({}) => + () => + () => + () => + () => + () => + () => + test, +); +a( + "", + "", + ({}) => + () => + () => + () => + () => + () => + () => + test ? 1 : 2, +); diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/arrows/currying-4.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/arrows/currying-4.js.snap new file mode 100644 index 00000000000..17ed87d1cc8 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/arrows/currying-4.js.snap @@ -0,0 +1,299 @@ +--- +source: crates/rome_formatter_test/src/snapshot_builder.rs +info: js/arrows/currying-4.js +--- + +# Input + +```js +Y(() => a ? b : c); + +Y(() => () => a ? b : c); + +Y(() => () => () => a ? b : c); + +Y(() => longlonglonglonglonglonglonglonglonglongCondition ? 'Prettier is an opinionated code formatter.' : 'Prettier takes your code and reprints it from scratch by taking the line length into account.') + +Y(() => () => longlonglonglonglonglonglonglonglonglongCondition ? 'Prettier is an opinionated code formatter.' : 'Prettier takes your code and reprints it from scratch by taking the line length into account.') + +Y(() => () => () => longlonglonglonglonglonglonglonglonglongCondition ? 'Prettier is an opinionated code formatter.' : 'Prettier takes your code and reprints it from scratch by taking the line length into account.') + +const x1 = (() => ['The', 'green', 'dragon', 'liked', 'to', 'knit', 'sweaters', 'for', 'the', 'fluffy', 'clouds', 'in', 'the', 'sky.']) + +const x2 = (() => () => ['The', 'green', 'dragon', 'liked', 'to', 'knit', 'sweaters', 'for', 'the', 'fluffy', 'clouds', 'in', 'the', 'sky.']) + +const x3 = (() => () => () => ['The', 'green', 'dragon', 'liked', 'to', 'knit', 'sweaters', 'for', 'the', 'fluffy', 'clouds', 'in', 'the', 'sky.']) + +f((a) => (1, 2, 3) /* a */); +f((a) => ( + (b) => (1, 2, 3) /* b */ +) /* a */); +f((a) => ( + (b) => ( + (c) => (1, 2, 3) /* c */ + ) /* b */ +) /* a */); + +f((a) => (1 ? 2 : 3) /* a */); +f((a) => ( + (b) => (1 ? 2 : 3) /* b */ +) /* a */); +f((a) => ( + (b) => ( + (c) => (1 ? 2 : 3) /* c */ + ) /* b */ +) /* a */); + +a( + "", + "", + ({}) => + () => + () => + () => + () => + () => + () => test, +); +a( + "", + "", + ({}) => + () => + () => + () => + () => + () => + () => (test ? 1 : 2), +); + +``` + + +# Prettier differences + +```diff +--- Prettier ++++ Rome +@@ -1,8 +1,8 @@ + Y(() => (a ? b : c)); + +-Y(() => () => (a ? b : c)); ++Y(() => () => a ? b : c); + +-Y(() => () => () => (a ? b : c)); ++Y(() => () => () => a ? b : c); + + Y(() => + longlonglonglonglonglonglonglonglonglongCondition +@@ -41,47 +41,49 @@ + "sky.", + ]; + +-const x2 = () => () => [ +- "The", +- "green", +- "dragon", +- "liked", +- "to", +- "knit", +- "sweaters", +- "for", +- "the", +- "fluffy", +- "clouds", +- "in", +- "the", +- "sky.", +-]; ++const x2 = () => () => ++ [ ++ "The", ++ "green", ++ "dragon", ++ "liked", ++ "to", ++ "knit", ++ "sweaters", ++ "for", ++ "the", ++ "fluffy", ++ "clouds", ++ "in", ++ "the", ++ "sky.", ++ ]; + +-const x3 = () => () => () => [ +- "The", +- "green", +- "dragon", +- "liked", +- "to", +- "knit", +- "sweaters", +- "for", +- "the", +- "fluffy", +- "clouds", +- "in", +- "the", +- "sky.", +-]; ++const x3 = () => () => () => ++ [ ++ "The", ++ "green", ++ "dragon", ++ "liked", ++ "to", ++ "knit", ++ "sweaters", ++ "for", ++ "the", ++ "fluffy", ++ "clouds", ++ "in", ++ "the", ++ "sky.", ++ ]; + + f((a) => (1, 2, 3) /* a */); + f((a) => (b) => (1, 2, 3) /* b */ /* a */); +-f((a) => (b) => (c) => (1, 2, 3) /* c */ /* b */ /* a */); ++f((a) => (b) => (c) => (1, 2, 3) /* b */ /* c */ /* a */); + + f((a) => (1 ? 2 : 3) /* a */); +-f((a) => (b) => (1 ? 2 : 3) /* b */ /* a */); +-f((a) => (b) => (c) => (1 ? 2 : 3) /* c */ /* b */ /* a */); ++f((a) => (b) => 1 ? 2 : 3 /* b */ /* a */); ++f((a) => (b) => (c) => 1 ? 2 : 3 /* b */ /* c */ /* a */); + + a( + "", +``` + +# Output + +```js +Y(() => (a ? b : c)); + +Y(() => () => a ? b : c); + +Y(() => () => () => a ? b : c); + +Y(() => + longlonglonglonglonglonglonglonglonglongCondition + ? "Prettier is an opinionated code formatter." + : "Prettier takes your code and reprints it from scratch by taking the line length into account.", +); + +Y( + () => () => + longlonglonglonglonglonglonglonglonglongCondition + ? "Prettier is an opinionated code formatter." + : "Prettier takes your code and reprints it from scratch by taking the line length into account.", +); + +Y( + () => () => () => + longlonglonglonglonglonglonglonglonglongCondition + ? "Prettier is an opinionated code formatter." + : "Prettier takes your code and reprints it from scratch by taking the line length into account.", +); + +const x1 = () => [ + "The", + "green", + "dragon", + "liked", + "to", + "knit", + "sweaters", + "for", + "the", + "fluffy", + "clouds", + "in", + "the", + "sky.", +]; + +const x2 = () => () => + [ + "The", + "green", + "dragon", + "liked", + "to", + "knit", + "sweaters", + "for", + "the", + "fluffy", + "clouds", + "in", + "the", + "sky.", + ]; + +const x3 = () => () => () => + [ + "The", + "green", + "dragon", + "liked", + "to", + "knit", + "sweaters", + "for", + "the", + "fluffy", + "clouds", + "in", + "the", + "sky.", + ]; + +f((a) => (1, 2, 3) /* a */); +f((a) => (b) => (1, 2, 3) /* b */ /* a */); +f((a) => (b) => (c) => (1, 2, 3) /* b */ /* c */ /* a */); + +f((a) => (1 ? 2 : 3) /* a */); +f((a) => (b) => 1 ? 2 : 3 /* b */ /* a */); +f((a) => (b) => (c) => 1 ? 2 : 3 /* b */ /* c */ /* a */); + +a( + "", + "", + ({}) => + () => + () => + () => + () => + () => + () => + test, +); +a( + "", + "", + ({}) => + () => + () => + () => + () => + () => + () => + test ? 1 : 2, +); +``` + +# Lines exceeding max width of 80 characters +``` + 10: : "Prettier takes your code and reprints it from scratch by taking the line length into account.", + 17: : "Prettier takes your code and reprints it from scratch by taking the line length into account.", + 24: : "Prettier takes your code and reprints it from scratch by taking the line length into account.", +``` + + diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/arrows/parens.js b/crates/rome_js_formatter/tests/specs/prettier/js/arrows/parens.js index 33fc3771e0c..895b76af121 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/js/arrows/parens.js +++ b/crates/rome_js_formatter/tests/specs/prettier/js/arrows/parens.js @@ -16,3 +16,6 @@ foo(a => b, d) foo(a => (0, 1)); foo(a => b => (0, 1)); + +() => ({} ? 1 : 2); +() => () => ({} ? 1 : 2); diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/arrows/parens.js.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/js/arrows/parens.js.prettier-snap index 68cd57716e2..0300c096943 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/js/arrows/parens.js.prettier-snap +++ b/crates/rome_js_formatter/tests/specs/prettier/js/arrows/parens.js.prettier-snap @@ -24,3 +24,6 @@ foo((a) => b, d); foo((a) => (0, 1)); foo((a) => (b) => (0, 1)); + +() => ({}) ? 1 : 2; +() => () => ({}) ? 1 : 2; diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/arrows/tuple-and-record.js b/crates/rome_js_formatter/tests/specs/prettier/js/arrows/tuple-and-record.js new file mode 100644 index 00000000000..1865604fcb0 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/arrows/tuple-and-record.js @@ -0,0 +1,25 @@ +const fn12 = (a) => (b) => (c) => (d) => (e) => + ({ foo: bar, bar: baz, baz: foo }); + +const fn12 = (a) => (b) => (c) => (d) => (e) => + (#{ foo: bar, bar: baz, baz: foo }); + +map(() => ([ + // comment + foo +])); + +map(() => (#[ + // comment + foo +])); + +map(() => ({ + // comment + foo +})); + +map(() => (#{ + // comment + foo +})); diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/arrows/tuple-and-record.js.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/js/arrows/tuple-and-record.js.prettier-snap new file mode 100644 index 00000000000..53dc539bb09 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/arrows/tuple-and-record.js.prettier-snap @@ -0,0 +1,31 @@ +const fn12 = (a) => (b) => (c) => (d) => (e) => ({ + foo: bar, + bar: baz, + baz: foo, +}); + +const fn12 = (a) => (b) => (c) => (d) => (e) => #{ + foo: bar, + bar: baz, + baz: foo, +}; + +map(() => [ + // comment + foo, +]); + +map(() => #[ + // comment + foo, +]); + +map(() => ({ + // comment + foo, +})); + +map(() => #{ + // comment + foo, +}); diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/arrows/tuple-and-record.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/arrows/tuple-and-record.js.snap new file mode 100644 index 00000000000..e67c1a5f539 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/arrows/tuple-and-record.js.snap @@ -0,0 +1,369 @@ +--- +source: crates/rome_formatter_test/src/snapshot_builder.rs +info: js/arrows/tuple-and-record.js +--- + +# Input + +```js +const fn12 = (a) => (b) => (c) => (d) => (e) => + ({ foo: bar, bar: baz, baz: foo }); + +const fn12 = (a) => (b) => (c) => (d) => (e) => + (#{ foo: bar, bar: baz, baz: foo }); + +map(() => ([ + // comment + foo +])); + +map(() => (#[ + // comment + foo +])); + +map(() => ({ + // comment + foo +})); + +map(() => (#{ + // comment + foo +})); + +``` + + +# Prettier differences + +```diff +--- Prettier ++++ Rome +@@ -4,28 +4,32 @@ + baz: foo, + }); + +-const fn12 = (a) => (b) => (c) => (d) => (e) => #{ +- foo: bar, +- bar: baz, +- baz: foo, +-}; ++const fn12 = (a) => (b) => (c) => (d) => (e) => ++ (# ++{ ++ foo: bar, bar; ++ : baz, baz: foo ++} ++) + + map(() => [ + // comment + foo, + ]); + +-map(() => #[ ++map(() => (#[ + // comment +- foo, +-]); ++ foo ++]) ++) + + map(() => ({ + // comment + foo, + })); + +-map(() => #{ ++map(() => (#{ + // comment +- foo, +-}); ++ foo ++}) ++) +``` + +# Output + +```js +const fn12 = (a) => (b) => (c) => (d) => (e) => ({ + foo: bar, + bar: baz, + baz: foo, +}); + +const fn12 = (a) => (b) => (c) => (d) => (e) => + (# +{ + foo: bar, bar; + : baz, baz: foo +} +) + +map(() => [ + // comment + foo, +]); + +map(() => (#[ + // comment + foo +]) +) + +map(() => ({ + // comment + foo, +})); + +map(() => (#{ + // comment + foo +}) +) +``` + +# Errors +``` +tuple-and-record.js:5:5 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × expected an identifier but instead found '{' + + 4 │ const fn12 = (a) => (b) => (c) => (d) => (e) => + > 5 │ (#{ foo: bar, bar: baz, baz: foo }); + │ ^ + 6 │ + 7 │ map(() => ([ + + i Expected an identifier here + + 4 │ const fn12 = (a) => (b) => (c) => (d) => (e) => + > 5 │ (#{ foo: bar, bar: baz, baz: foo }); + │ ^ + 6 │ + 7 │ map(() => ([ + +tuple-and-record.js:5:4 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × Private names are only allowed on the left side of a 'in' expression + + 4 │ const fn12 = (a) => (b) => (c) => (d) => (e) => + > 5 │ (#{ foo: bar, bar: baz, baz: foo }); + │ ^ + 6 │ + 7 │ map(() => ([ + +tuple-and-record.js:5:5 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × expected `)` but instead found `{` + + 4 │ const fn12 = (a) => (b) => (c) => (d) => (e) => + > 5 │ (#{ foo: bar, bar: baz, baz: foo }); + │ ^ + 6 │ + 7 │ map(() => ([ + + i Remove { + +tuple-and-record.js:5:20 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × Expected a semicolon or an implicit semicolon after a statement, but found none + + 4 │ const fn12 = (a) => (b) => (c) => (d) => (e) => + > 5 │ (#{ foo: bar, bar: baz, baz: foo }); + │ ^ + 6 │ + 7 │ map(() => ([ + + i An explicit or implicit semicolon is expected here... + + 4 │ const fn12 = (a) => (b) => (c) => (d) => (e) => + > 5 │ (#{ foo: bar, bar: baz, baz: foo }); + │ ^ + 6 │ + 7 │ map(() => ([ + + i ...Which is required to end this statement + + 4 │ const fn12 = (a) => (b) => (c) => (d) => (e) => + > 5 │ (#{ foo: bar, bar: baz, baz: foo }); + │ ^^^^^^^^^ + 6 │ + 7 │ map(() => ([ + +tuple-and-record.js:5:37 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × expected a statement but instead found ')' + + 4 │ const fn12 = (a) => (b) => (c) => (d) => (e) => + > 5 │ (#{ foo: bar, bar: baz, baz: foo }); + │ ^ + 6 │ + 7 │ map(() => ([ + + i Expected a statement here + + 4 │ const fn12 = (a) => (b) => (c) => (d) => (e) => + > 5 │ (#{ foo: bar, bar: baz, baz: foo }); + │ ^ + 6 │ + 7 │ map(() => ([ + +tuple-and-record.js:12:13 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × expected an identifier but instead found '[' + + 10 │ ])); + 11 │ + > 12 │ map(() => (#[ + │ ^ + 13 │ // comment + 14 │ foo + + i Expected an identifier here + + 10 │ ])); + 11 │ + > 12 │ map(() => (#[ + │ ^ + 13 │ // comment + 14 │ foo + +tuple-and-record.js:12:12 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × Private names are only allowed on the left side of a 'in' expression + + 10 │ ])); + 11 │ + > 12 │ map(() => (#[ + │ ^ + 13 │ // comment + 14 │ foo + +tuple-and-record.js:12:13 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × expected `)` but instead found `[` + + 10 │ ])); + 11 │ + > 12 │ map(() => (#[ + │ ^ + 13 │ // comment + 14 │ foo + + i Remove [ + +tuple-and-record.js:15:3 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × Expected a semicolon or an implicit semicolon after a statement, but found none + + 13 │ // comment + 14 │ foo + > 15 │ ])); + │ ^ + 16 │ + 17 │ map(() => ({ + + i An explicit or implicit semicolon is expected here... + + 13 │ // comment + 14 │ foo + > 15 │ ])); + │ ^ + 16 │ + 17 │ map(() => ({ + + i ...Which is required to end this statement + + 10 │ ])); + 11 │ + > 12 │ map(() => (#[ + │ ^^^^^^^^^^^^^ + > 13 │ // comment + > 14 │ foo + > 15 │ ])); + │ ^^^ + 16 │ + 17 │ map(() => ({ + +tuple-and-record.js:22:13 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × expected an identifier but instead found '{' + + 20 │ })); + 21 │ + > 22 │ map(() => (#{ + │ ^ + 23 │ // comment + 24 │ foo + + i Expected an identifier here + + 20 │ })); + 21 │ + > 22 │ map(() => (#{ + │ ^ + 23 │ // comment + 24 │ foo + +tuple-and-record.js:22:12 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × Private names are only allowed on the left side of a 'in' expression + + 20 │ })); + 21 │ + > 22 │ map(() => (#{ + │ ^ + 23 │ // comment + 24 │ foo + +tuple-and-record.js:22:13 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × expected `)` but instead found `{` + + 20 │ })); + 21 │ + > 22 │ map(() => (#{ + │ ^ + 23 │ // comment + 24 │ foo + + i Remove { + +tuple-and-record.js:25:3 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × Expected a semicolon or an implicit semicolon after a statement, but found none + + 23 │ // comment + 24 │ foo + > 25 │ })); + │ ^ + 26 │ + + i An explicit or implicit semicolon is expected here... + + 23 │ // comment + 24 │ foo + > 25 │ })); + │ ^ + 26 │ + + i ...Which is required to end this statement + + 20 │ })); + 21 │ + > 22 │ map(() => (#{ + │ ^^^^^^^^^^^^^ + > 23 │ // comment + > 24 │ foo + > 25 │ })); + │ ^^^ + 26 │ + + +``` + + diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/async/nested2.js b/crates/rome_js_formatter/tests/specs/prettier/js/async/nested2.js new file mode 100644 index 00000000000..5b7ec8637b2 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/async/nested2.js @@ -0,0 +1,6 @@ +async function f() { +await Promise.all( + (await readdir("src")).map(async (path) => { + import(`./${path}`); + }) +);} diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/async/nested2.js.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/js/async/nested2.js.prettier-snap new file mode 100644 index 00000000000..804e96c7c2f --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/async/nested2.js.prettier-snap @@ -0,0 +1,7 @@ +async function f() { + await Promise.all( + (await readdir("src")).map(async (path) => { + import(`./${path}`); + }), + ); +} diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/async/nested2.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/async/nested2.js.snap new file mode 100644 index 00000000000..54cf0d1871a --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/async/nested2.js.snap @@ -0,0 +1,50 @@ +--- +source: crates/rome_formatter_test/src/snapshot_builder.rs +info: js/async/nested2.js +--- + +# Input + +```js +async function f() { +await Promise.all( + (await readdir("src")).map(async (path) => { + import(`./${path}`); + }) +);} + +``` + + +# Prettier differences + +```diff +--- Prettier ++++ Rome +@@ -1,6 +1,8 @@ + async function f() { + await Promise.all( +- (await readdir("src")).map(async (path) => { ++ ( ++ await readdir("src") ++ ).map(async (path) => { + import(`./${path}`); + }), + ); +``` + +# Output + +```js +async function f() { + await Promise.all( + ( + await readdir("src") + ).map(async (path) => { + import(`./${path}`); + }), + ); +} +``` + + diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/babel-plugins/explicit-resource-management.js b/crates/rome_js_formatter/tests/specs/prettier/js/babel-plugins/explicit-resource-management.js new file mode 100644 index 00000000000..1912ca64933 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/babel-plugins/explicit-resource-management.js @@ -0,0 +1,12 @@ +function * g() { + using handle = acquireFileHandle(); // block-scoped critical resource +} // cleanup + +{ + using obj = g(); // block-scoped declaration + const r = obj.next(); +} // calls finally blocks in `g` + +{ + await using obj = g(); +} diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/babel-plugins/explicit-resource-management.js.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/js/babel-plugins/explicit-resource-management.js.prettier-snap new file mode 100644 index 00000000000..0a4b07feb6e --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/babel-plugins/explicit-resource-management.js.prettier-snap @@ -0,0 +1,12 @@ +function* g() { + using handle = acquireFileHandle(); // block-scoped critical resource +} // cleanup + +{ + using obj = g(); // block-scoped declaration + const r = obj.next(); +} // calls finally blocks in `g` + +{ + await using obj = g(); +} diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/babel-plugins/explicit-resource-management.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/babel-plugins/explicit-resource-management.js.snap new file mode 100644 index 00000000000..039438e44a4 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/babel-plugins/explicit-resource-management.js.snap @@ -0,0 +1,154 @@ +--- +source: crates/rome_formatter_test/src/snapshot_builder.rs +info: js/babel-plugins/explicit-resource-management.js +--- + +# Input + +```js +function * g() { + using handle = acquireFileHandle(); // block-scoped critical resource +} // cleanup + +{ + using obj = g(); // block-scoped declaration + const r = obj.next(); +} // calls finally blocks in `g` + +{ + await using obj = g(); +} + +``` + + +# Prettier differences + +```diff +--- Prettier ++++ Rome +@@ -1,12 +1,15 @@ + function* g() { +- using handle = acquireFileHandle(); // block-scoped critical resource ++ using; ++ handle = acquireFileHandle(); // block-scoped critical resource + } // cleanup + + { +- using obj = g(); // block-scoped declaration ++ using; ++ obj = g(); // block-scoped declaration + const r = obj.next(); + } // calls finally blocks in `g` + + { +- await using obj = g(); ++ await using; ++ obj = g(); + } +``` + +# Output + +```js +function* g() { + using; + handle = acquireFileHandle(); // block-scoped critical resource +} // cleanup + +{ + using; + obj = g(); // block-scoped declaration + const r = obj.next(); +} // calls finally blocks in `g` + +{ + await using; + obj = g(); +} +``` + +# Errors +``` +explicit-resource-management.js:2:9 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × Expected a semicolon or an implicit semicolon after a statement, but found none + + 1 │ function * g() { + > 2 │ using handle = acquireFileHandle(); // block-scoped critical resource + │ ^^^^^^ + 3 │ } // cleanup + 4 │ + + i An explicit or implicit semicolon is expected here... + + 1 │ function * g() { + > 2 │ using handle = acquireFileHandle(); // block-scoped critical resource + │ ^^^^^^ + 3 │ } // cleanup + 4 │ + + i ...Which is required to end this statement + + 1 │ function * g() { + > 2 │ using handle = acquireFileHandle(); // block-scoped critical resource + │ ^^^^^^^^^^^^ + 3 │ } // cleanup + 4 │ + +explicit-resource-management.js:6:9 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × Expected a semicolon or an implicit semicolon after a statement, but found none + + 5 │ { + > 6 │ using obj = g(); // block-scoped declaration + │ ^^^ + 7 │ const r = obj.next(); + 8 │ } // calls finally blocks in `g` + + i An explicit or implicit semicolon is expected here... + + 5 │ { + > 6 │ using obj = g(); // block-scoped declaration + │ ^^^ + 7 │ const r = obj.next(); + 8 │ } // calls finally blocks in `g` + + i ...Which is required to end this statement + + 5 │ { + > 6 │ using obj = g(); // block-scoped declaration + │ ^^^^^^^^^ + 7 │ const r = obj.next(); + 8 │ } // calls finally blocks in `g` + +explicit-resource-management.js:11:15 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × Expected a semicolon or an implicit semicolon after a statement, but found none + + 10 │ { + > 11 │ await using obj = g(); + │ ^^^ + 12 │ } + 13 │ + + i An explicit or implicit semicolon is expected here... + + 10 │ { + > 11 │ await using obj = g(); + │ ^^^ + 12 │ } + 13 │ + + i ...Which is required to end this statement + + 10 │ { + > 11 │ await using obj = g(); + │ ^^^^^^^^^^^^^^^ + 12 │ } + 13 │ + + +``` + + diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/babel-plugins/import-attributes-dynamic.js b/crates/rome_js_formatter/tests/specs/prettier/js/babel-plugins/import-attributes-dynamic.js new file mode 100644 index 00000000000..717b72d4a84 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/babel-plugins/import-attributes-dynamic.js @@ -0,0 +1 @@ +import("./foo.json", { with: { type: "json" } }); diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/babel-plugins/import-attributes-dynamic.js.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/js/babel-plugins/import-attributes-dynamic.js.prettier-snap new file mode 100644 index 00000000000..717b72d4a84 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/babel-plugins/import-attributes-dynamic.js.prettier-snap @@ -0,0 +1 @@ +import("./foo.json", { with: { type: "json" } }); diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/babel-plugins/import-attributes-static.js b/crates/rome_js_formatter/tests/specs/prettier/js/babel-plugins/import-attributes-static.js new file mode 100644 index 00000000000..7770ae1f06b --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/babel-plugins/import-attributes-static.js @@ -0,0 +1 @@ +import json from "./foo.json" with { type: "json" }; diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/babel-plugins/import-attributes-static.js.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/js/babel-plugins/import-attributes-static.js.prettier-snap new file mode 100644 index 00000000000..7770ae1f06b --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/babel-plugins/import-attributes-static.js.prettier-snap @@ -0,0 +1 @@ +import json from "./foo.json" with { type: "json" }; diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/babel-plugins/import-reflection.js b/crates/rome_js_formatter/tests/specs/prettier/js/babel-plugins/import-reflection.js new file mode 100644 index 00000000000..0c84d385708 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/babel-plugins/import-reflection.js @@ -0,0 +1 @@ +import module foo from "./module.wasm"; diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/babel-plugins/import-reflection.js.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/js/babel-plugins/import-reflection.js.prettier-snap new file mode 100644 index 00000000000..0c84d385708 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/babel-plugins/import-reflection.js.prettier-snap @@ -0,0 +1 @@ +import module foo from "./module.wasm"; diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/babel-plugins/import-reflection.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/babel-plugins/import-reflection.js.snap new file mode 100644 index 00000000000..53cb2129d18 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/babel-plugins/import-reflection.js.snap @@ -0,0 +1,91 @@ +--- +source: crates/rome_formatter_test/src/snapshot_builder.rs +info: js/babel-plugins/import-reflection.js +--- + +# Input + +```js +import module foo from "./module.wasm"; + +``` + + +# Prettier differences + +```diff +--- Prettier ++++ Rome +@@ -1 +1,4 @@ +-import module foo from "./module.wasm"; ++import module ++foo; ++from; ++("./module.wasm"); +``` + +# Output + +```js +import module +foo; +from; +("./module.wasm"); +``` + +# Errors +``` +import-reflection.js:1:15 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × expected `from` but instead found `foo` + + > 1 │ import module foo from "./module.wasm"; + │ ^^^ + 2 │ + + i Remove foo + +import-reflection.js:1:19 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × Expected a semicolon or an implicit semicolon after a statement, but found none + + > 1 │ import module foo from "./module.wasm"; + │ ^^^^ + 2 │ + + i An explicit or implicit semicolon is expected here... + + > 1 │ import module foo from "./module.wasm"; + │ ^^^^ + 2 │ + + i ...Which is required to end this statement + + > 1 │ import module foo from "./module.wasm"; + │ ^^^^^^^^ + 2 │ + +import-reflection.js:1:24 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × Expected a semicolon or an implicit semicolon after a statement, but found none + + > 1 │ import module foo from "./module.wasm"; + │ ^^^^^^^^^^^^^^^ + 2 │ + + i An explicit or implicit semicolon is expected here... + + > 1 │ import module foo from "./module.wasm"; + │ ^^^^^^^^^^^^^^^ + 2 │ + + i ...Which is required to end this statement + + > 1 │ import module foo from "./module.wasm"; + │ ^^^^^^^^^^^^^^^^^^^^ + 2 │ + + +``` + + diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/babel-plugins/regexp-modifiers.js b/crates/rome_js_formatter/tests/specs/prettier/js/babel-plugins/regexp-modifiers.js new file mode 100644 index 00000000000..21cfd8487fe --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/babel-plugins/regexp-modifiers.js @@ -0,0 +1 @@ +const re = /^(?i:[a-z])[a-z]$/; diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/babel-plugins/regexp-modifiers.js.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/js/babel-plugins/regexp-modifiers.js.prettier-snap new file mode 100644 index 00000000000..21cfd8487fe --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/babel-plugins/regexp-modifiers.js.prettier-snap @@ -0,0 +1 @@ +const re = /^(?i:[a-z])[a-z]$/; diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/binary-expressions/tuple-and-record.js b/crates/rome_js_formatter/tests/specs/prettier/js/binary-expressions/tuple-and-record.js new file mode 100644 index 00000000000..6590e94e64b --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/binary-expressions/tuple-and-record.js @@ -0,0 +1,19 @@ +foo = foo || [ + // comment + a, +] + +foo = foo || #[ + // comment + a, +] + +foo = foo || { + // comment + a, +} + +foo = foo || #{ + // comment + a, +} diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/binary-expressions/tuple-and-record.js.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/js/binary-expressions/tuple-and-record.js.prettier-snap new file mode 100644 index 00000000000..3b179c5611b --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/binary-expressions/tuple-and-record.js.prettier-snap @@ -0,0 +1,19 @@ +foo = foo || [ + // comment + a, +]; + +foo = foo || #[ + // comment + a, +]; + +foo = foo || { + // comment + a, +}; + +foo = foo || #{ + // comment + a, +}; diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/binary-expressions/tuple-and-record.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/binary-expressions/tuple-and-record.js.snap new file mode 100644 index 00000000000..b6c43bab846 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/binary-expressions/tuple-and-record.js.snap @@ -0,0 +1,229 @@ +--- +source: crates/rome_formatter_test/src/snapshot_builder.rs +info: js/binary-expressions/tuple-and-record.js +--- + +# Input + +```js +foo = foo || [ + // comment + a, +] + +foo = foo || #[ + // comment + a, +] + +foo = foo || { + // comment + a, +} + +foo = foo || #{ + // comment + a, +} + +``` + + +# Prettier differences + +```diff +--- Prettier ++++ Rome +@@ -3,7 +3,8 @@ + a, + ]; + +-foo = foo || #[ ++foo = foo || #; ++[ + // comment + a, + ]; +@@ -13,7 +14,8 @@ + a, + }; + +-foo = foo || #{ ++foo = foo || #; ++{ + // comment + a, +-}; ++} +``` + +# Output + +```js +foo = foo || [ + // comment + a, +]; + +foo = foo || #; +[ + // comment + a, +]; + +foo = foo || { + // comment + a, +}; + +foo = foo || #; +{ + // comment + a, +} +``` + +# Errors +``` +tuple-and-record.js:6:15 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × expected an identifier but instead found '[' + + 4 │ ] + 5 │ + > 6 │ foo = foo || #[ + │ ^ + 7 │ // comment + 8 │ a, + + i Expected an identifier here + + 4 │ ] + 5 │ + > 6 │ foo = foo || #[ + │ ^ + 7 │ // comment + 8 │ a, + +tuple-and-record.js:6:14 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × Private names are only allowed on the left side of a 'in' expression + + 4 │ ] + 5 │ + > 6 │ foo = foo || #[ + │ ^ + 7 │ // comment + 8 │ a, + +tuple-and-record.js:6:15 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × Expected a semicolon or an implicit semicolon after a statement, but found none + + 4 │ ] + 5 │ + > 6 │ foo = foo || #[ + │ ^ + 7 │ // comment + 8 │ a, + + i An explicit or implicit semicolon is expected here... + + 4 │ ] + 5 │ + > 6 │ foo = foo || #[ + │ ^ + 7 │ // comment + 8 │ a, + + i ...Which is required to end this statement + + 4 │ ] + 5 │ + > 6 │ foo = foo || #[ + │ ^^^^^^^^^^^^^^^ + 7 │ // comment + 8 │ a, + +tuple-and-record.js:16:15 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × expected an identifier but instead found '{' + + 14 │ } + 15 │ + > 16 │ foo = foo || #{ + │ ^ + 17 │ // comment + 18 │ a, + + i Expected an identifier here + + 14 │ } + 15 │ + > 16 │ foo = foo || #{ + │ ^ + 17 │ // comment + 18 │ a, + +tuple-and-record.js:16:14 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × Private names are only allowed on the left side of a 'in' expression + + 14 │ } + 15 │ + > 16 │ foo = foo || #{ + │ ^ + 17 │ // comment + 18 │ a, + +tuple-and-record.js:16:15 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × Expected a semicolon or an implicit semicolon after a statement, but found none + + 14 │ } + 15 │ + > 16 │ foo = foo || #{ + │ ^ + 17 │ // comment + 18 │ a, + + i An explicit or implicit semicolon is expected here... + + 14 │ } + 15 │ + > 16 │ foo = foo || #{ + │ ^ + 17 │ // comment + 18 │ a, + + i ...Which is required to end this statement + + 14 │ } + 15 │ + > 16 │ foo = foo || #{ + │ ^^^^^^^^^^^^^^^ + 17 │ // comment + 18 │ a, + +tuple-and-record.js:19:1 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × expected an expression but instead found '}' + + 17 │ // comment + 18 │ a, + > 19 │ } + │ ^ + 20 │ + + i Expected an expression here + + 17 │ // comment + 18 │ a, + > 19 │ } + │ ^ + 20 │ + + +``` + + diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/call/first-argument-expansion/expression-2nd-arg.js b/crates/rome_js_formatter/tests/specs/prettier/js/call/first-argument-expansion/expression-2nd-arg.js new file mode 100644 index 00000000000..7b45856a28b --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/call/first-argument-expansion/expression-2nd-arg.js @@ -0,0 +1,20 @@ +call( + function() { + return 1; + }, + 200_000_000_000n * askTrovenaBeenaDependsRowans +); + +call( + function() { + return 1; + }, + 200_000_000_000n * askTrovenaBeenaDependsRowans / glimseGlyphsHazardNoopsTieTie +); + +call( + function() { + return 1; + }, + askTrovenaBeenaDependsRowans = glimseGlyphsHazardNoopsTieTie = 200_000_000_000n +); diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/call/first-argument-expansion/expression-2nd-arg.js.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/js/call/first-argument-expansion/expression-2nd-arg.js.prettier-snap new file mode 100644 index 00000000000..0f1ed4e44a0 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/call/first-argument-expansion/expression-2nd-arg.js.prettier-snap @@ -0,0 +1,19 @@ +call(function () { + return 1; +}, 200_000_000_000n * askTrovenaBeenaDependsRowans); + +call( + function () { + return 1; + }, + (200_000_000_000n * askTrovenaBeenaDependsRowans) / + glimseGlyphsHazardNoopsTieTie, +); + +call( + function () { + return 1; + }, + (askTrovenaBeenaDependsRowans = glimseGlyphsHazardNoopsTieTie = + 200_000_000_000n), +); diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/call/first-argument-expansion/expression-2nd-arg.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/call/first-argument-expansion/expression-2nd-arg.js.snap new file mode 100644 index 00000000000..f898296739c --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/call/first-argument-expansion/expression-2nd-arg.js.snap @@ -0,0 +1,85 @@ +--- +source: crates/rome_formatter_test/src/snapshot_builder.rs +info: js/call/first-argument-expansion/expression-2nd-arg.js +--- + +# Input + +```js +call( + function() { + return 1; + }, + 200_000_000_000n * askTrovenaBeenaDependsRowans +); + +call( + function() { + return 1; + }, + 200_000_000_000n * askTrovenaBeenaDependsRowans / glimseGlyphsHazardNoopsTieTie +); + +call( + function() { + return 1; + }, + askTrovenaBeenaDependsRowans = glimseGlyphsHazardNoopsTieTie = 200_000_000_000n +); + +``` + + +# Prettier differences + +```diff +--- Prettier ++++ Rome +@@ -2,18 +2,12 @@ + return 1; + }, 200_000_000_000n * askTrovenaBeenaDependsRowans); + +-call( +- function () { +- return 1; +- }, +- (200_000_000_000n * askTrovenaBeenaDependsRowans) / +- glimseGlyphsHazardNoopsTieTie, +-); ++call(function () { ++ return 1; ++}, (200_000_000_000n * askTrovenaBeenaDependsRowans) / ++ glimseGlyphsHazardNoopsTieTie); + +-call( +- function () { +- return 1; +- }, +- (askTrovenaBeenaDependsRowans = glimseGlyphsHazardNoopsTieTie = +- 200_000_000_000n), +-); ++call(function () { ++ return 1; ++}, (askTrovenaBeenaDependsRowans = glimseGlyphsHazardNoopsTieTie = ++ 200_000_000_000n)); +``` + +# Output + +```js +call(function () { + return 1; +}, 200_000_000_000n * askTrovenaBeenaDependsRowans); + +call(function () { + return 1; +}, (200_000_000_000n * askTrovenaBeenaDependsRowans) / + glimseGlyphsHazardNoopsTieTie); + +call(function () { + return 1; +}, (askTrovenaBeenaDependsRowans = glimseGlyphsHazardNoopsTieTie = + 200_000_000_000n)); +``` + + diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/call/first-argument-expansion/issue-12892.js b/crates/rome_js_formatter/tests/specs/prettier/js/call/first-argument-expansion/issue-12892.js new file mode 100644 index 00000000000..61b374de32a --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/call/first-argument-expansion/issue-12892.js @@ -0,0 +1,8 @@ +setTimeout(() => { + console.log('test'); +}, someFunctionCall( + veryLongParameterName1, + veryLongParameterName2, + veryLongParameterName3, + veryLongParameterName4, +)); diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/call/first-argument-expansion/issue-12892.js.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/js/call/first-argument-expansion/issue-12892.js.prettier-snap new file mode 100644 index 00000000000..78c4863aee2 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/call/first-argument-expansion/issue-12892.js.prettier-snap @@ -0,0 +1,11 @@ +setTimeout( + () => { + console.log("test"); + }, + someFunctionCall( + veryLongParameterName1, + veryLongParameterName2, + veryLongParameterName3, + veryLongParameterName4, + ), +); diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/call/first-argument-expansion/issue-12892.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/call/first-argument-expansion/issue-12892.js.snap new file mode 100644 index 00000000000..43e96bbe0e2 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/call/first-argument-expansion/issue-12892.js.snap @@ -0,0 +1,61 @@ +--- +source: crates/rome_formatter_test/src/snapshot_builder.rs +info: js/call/first-argument-expansion/issue-12892.js +--- + +# Input + +```js +setTimeout(() => { + console.log('test'); +}, someFunctionCall( + veryLongParameterName1, + veryLongParameterName2, + veryLongParameterName3, + veryLongParameterName4, +)); + +``` + + +# Prettier differences + +```diff +--- Prettier ++++ Rome +@@ -1,11 +1,8 @@ +-setTimeout( +- () => { +- console.log("test"); +- }, +- someFunctionCall( +- veryLongParameterName1, +- veryLongParameterName2, +- veryLongParameterName3, +- veryLongParameterName4, +- ), +-); ++setTimeout(() => { ++ console.log("test"); ++}, someFunctionCall( ++ veryLongParameterName1, ++ veryLongParameterName2, ++ veryLongParameterName3, ++ veryLongParameterName4, ++)); +``` + +# Output + +```js +setTimeout(() => { + console.log("test"); +}, someFunctionCall( + veryLongParameterName1, + veryLongParameterName2, + veryLongParameterName3, + veryLongParameterName4, +)); +``` + + diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/call/first-argument-expansion/issue-13237.js b/crates/rome_js_formatter/tests/specs/prettier/js/call/first-argument-expansion/issue-13237.js new file mode 100644 index 00000000000..a2b0664226e --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/call/first-argument-expansion/issue-13237.js @@ -0,0 +1,19 @@ +/* version 1 */ + +exportDefaultWhatever(function ( + aaaaaaaaaaaString, + bbbbbbbbbbbString, + cccccccccccString, +) { + return null; +}, "xyz"); + +/* version 2 (only difference is that `//`) */ + +exportDefaultWhatever(function ( + aaaaaaaaaaaString, // + bbbbbbbbbbbString, + cccccccccccString, +) { + return null; +}, "xyz"); diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/call/first-argument-expansion/issue-13237.js.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/js/call/first-argument-expansion/issue-13237.js.prettier-snap new file mode 100644 index 00000000000..21d215328d6 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/call/first-argument-expansion/issue-13237.js.prettier-snap @@ -0,0 +1,19 @@ +/* version 1 */ + +exportDefaultWhatever(function ( + aaaaaaaaaaaString, + bbbbbbbbbbbString, + cccccccccccString, +) { + return null; +}, "xyz"); + +/* version 2 (only difference is that `//`) */ + +exportDefaultWhatever(function ( + aaaaaaaaaaaString, // + bbbbbbbbbbbString, + cccccccccccString, +) { + return null; +}, "xyz"); diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/call/first-argument-expansion/issue-14454.js b/crates/rome_js_formatter/tests/specs/prettier/js/call/first-argument-expansion/issue-14454.js new file mode 100644 index 00000000000..2afbd7c3837 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/call/first-argument-expansion/issue-14454.js @@ -0,0 +1 @@ +f(() => {}, scroller.qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq) diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/call/first-argument-expansion/issue-14454.js.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/js/call/first-argument-expansion/issue-14454.js.prettier-snap new file mode 100644 index 00000000000..6d534ae77a5 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/call/first-argument-expansion/issue-14454.js.prettier-snap @@ -0,0 +1,4 @@ +f( + () => {}, + scroller.qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq, +); diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/call/first-argument-expansion/issue-2456.js b/crates/rome_js_formatter/tests/specs/prettier/js/call/first-argument-expansion/issue-2456.js new file mode 100644 index 00000000000..7d85a7ff7e2 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/call/first-argument-expansion/issue-2456.js @@ -0,0 +1,4 @@ +f(x => { y }, err.message.includes("asd") && err.message.includes("id") && + err.message.includes('"1"') && err.message.includes("Model") && + err.message.includes("/id") && err.message.includes("identifier(number)") +) diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/call/first-argument-expansion/issue-2456.js.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/js/call/first-argument-expansion/issue-2456.js.prettier-snap new file mode 100644 index 00000000000..995da421f9a --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/call/first-argument-expansion/issue-2456.js.prettier-snap @@ -0,0 +1,11 @@ +f( + (x) => { + y; + }, + err.message.includes("asd") && + err.message.includes("id") && + err.message.includes('"1"') && + err.message.includes("Model") && + err.message.includes("/id") && + err.message.includes("identifier(number)"), +); diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/call/first-argument-expansion/issue-2456.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/call/first-argument-expansion/issue-2456.js.snap new file mode 100644 index 00000000000..8ce176f880f --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/call/first-argument-expansion/issue-2456.js.snap @@ -0,0 +1,57 @@ +--- +source: crates/rome_formatter_test/src/snapshot_builder.rs +info: js/call/first-argument-expansion/issue-2456.js +--- + +# Input + +```js +f(x => { y }, err.message.includes("asd") && err.message.includes("id") && + err.message.includes('"1"') && err.message.includes("Model") && + err.message.includes("/id") && err.message.includes("identifier(number)") +) + +``` + + +# Prettier differences + +```diff +--- Prettier ++++ Rome +@@ -1,11 +1,8 @@ +-f( +- (x) => { +- y; +- }, +- err.message.includes("asd") && +- err.message.includes("id") && +- err.message.includes('"1"') && +- err.message.includes("Model") && +- err.message.includes("/id") && +- err.message.includes("identifier(number)"), +-); ++f((x) => { ++ y; ++}, err.message.includes("asd") && ++ err.message.includes("id") && ++ err.message.includes('"1"') && ++ err.message.includes("Model") && ++ err.message.includes("/id") && ++ err.message.includes("identifier(number)")); +``` + +# Output + +```js +f((x) => { + y; +}, err.message.includes("asd") && + err.message.includes("id") && + err.message.includes('"1"') && + err.message.includes("Model") && + err.message.includes("/id") && + err.message.includes("identifier(number)")); +``` + + diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/call/first-argument-expansion/issue-4401.js b/crates/rome_js_formatter/tests/specs/prettier/js/call/first-argument-expansion/issue-4401.js new file mode 100644 index 00000000000..054c6aedf26 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/call/first-argument-expansion/issue-4401.js @@ -0,0 +1,6 @@ +export function test() { + setTimeout( + () => { console.warn({}, 'Lambda approaching timeout.') }, + Math.max(context.getRemainingTimeInMillis() - WARN_TIMEOUT_MS, 0), + ); +} diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/call/first-argument-expansion/issue-4401.js.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/js/call/first-argument-expansion/issue-4401.js.prettier-snap new file mode 100644 index 00000000000..4235feebe34 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/call/first-argument-expansion/issue-4401.js.prettier-snap @@ -0,0 +1,8 @@ +export function test() { + setTimeout( + () => { + console.warn({}, "Lambda approaching timeout."); + }, + Math.max(context.getRemainingTimeInMillis() - WARN_TIMEOUT_MS, 0), + ); +} diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/call/first-argument-expansion/issue-4401.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/call/first-argument-expansion/issue-4401.js.snap new file mode 100644 index 00000000000..303920bd069 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/call/first-argument-expansion/issue-4401.js.snap @@ -0,0 +1,48 @@ +--- +source: crates/rome_formatter_test/src/snapshot_builder.rs +info: js/call/first-argument-expansion/issue-4401.js +--- + +# Input + +```js +export function test() { + setTimeout( + () => { console.warn({}, 'Lambda approaching timeout.') }, + Math.max(context.getRemainingTimeInMillis() - WARN_TIMEOUT_MS, 0), + ); +} + +``` + + +# Prettier differences + +```diff +--- Prettier ++++ Rome +@@ -1,8 +1,5 @@ + export function test() { +- setTimeout( +- () => { +- console.warn({}, "Lambda approaching timeout."); +- }, +- Math.max(context.getRemainingTimeInMillis() - WARN_TIMEOUT_MS, 0), +- ); ++ setTimeout(() => { ++ console.warn({}, "Lambda approaching timeout."); ++ }, Math.max(context.getRemainingTimeInMillis() - WARN_TIMEOUT_MS, 0)); + } +``` + +# Output + +```js +export function test() { + setTimeout(() => { + console.warn({}, "Lambda approaching timeout."); + }, Math.max(context.getRemainingTimeInMillis() - WARN_TIMEOUT_MS, 0)); +} +``` + + diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/call/first-argument-expansion/issue-5172.js b/crates/rome_js_formatter/tests/specs/prettier/js/call/first-argument-expansion/issue-5172.js new file mode 100644 index 00000000000..bf3941a81f8 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/call/first-argument-expansion/issue-5172.js @@ -0,0 +1,10 @@ +call( + function() { + return 1; + }, + $var ?? $var ?? $var ?? $var ?? $var ?? $var ?? $var ?? $var ?? $var ?? 'test' +); + +call(function () { + return 1; +}, $var || ($var ?? $var ?? $var ?? $var ?? $var ?? $var ?? $var ?? $var ?? "test")); diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/call/first-argument-expansion/issue-5172.js.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/js/call/first-argument-expansion/issue-5172.js.prettier-snap new file mode 100644 index 00000000000..42d79dac3a0 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/call/first-argument-expansion/issue-5172.js.prettier-snap @@ -0,0 +1,23 @@ +call( + function () { + return 1; + }, + $var ?? + $var ?? + $var ?? + $var ?? + $var ?? + $var ?? + $var ?? + $var ?? + $var ?? + "test", +); + +call( + function () { + return 1; + }, + $var || + ($var ?? $var ?? $var ?? $var ?? $var ?? $var ?? $var ?? $var ?? "test"), +); diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/call/first-argument-expansion/issue-5172.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/call/first-argument-expansion/issue-5172.js.snap new file mode 100644 index 00000000000..ffc7295e3a5 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/call/first-argument-expansion/issue-5172.js.snap @@ -0,0 +1,91 @@ +--- +source: crates/rome_formatter_test/src/snapshot_builder.rs +info: js/call/first-argument-expansion/issue-5172.js +--- + +# Input + +```js +call( + function() { + return 1; + }, + $var ?? $var ?? $var ?? $var ?? $var ?? $var ?? $var ?? $var ?? $var ?? 'test' +); + +call(function () { + return 1; +}, $var || ($var ?? $var ?? $var ?? $var ?? $var ?? $var ?? $var ?? $var ?? "test")); + +``` + + +# Prettier differences + +```diff +--- Prettier ++++ Rome +@@ -1,23 +1,17 @@ +-call( +- function () { +- return 1; +- }, ++call(function () { ++ return 1; ++}, $var ?? ++ $var ?? ++ $var ?? ++ $var ?? ++ $var ?? ++ $var ?? ++ $var ?? + $var ?? +- $var ?? +- $var ?? +- $var ?? +- $var ?? +- $var ?? +- $var ?? +- $var ?? +- $var ?? +- "test", +-); ++ $var ?? ++ "test"); + +-call( +- function () { +- return 1; +- }, +- $var || +- ($var ?? $var ?? $var ?? $var ?? $var ?? $var ?? $var ?? $var ?? "test"), +-); ++call(function () { ++ return 1; ++}, $var || ++ ($var ?? $var ?? $var ?? $var ?? $var ?? $var ?? $var ?? $var ?? "test")); +``` + +# Output + +```js +call(function () { + return 1; +}, $var ?? + $var ?? + $var ?? + $var ?? + $var ?? + $var ?? + $var ?? + $var ?? + $var ?? + "test"); + +call(function () { + return 1; +}, $var || + ($var ?? $var ?? $var ?? $var ?? $var ?? $var ?? $var ?? $var ?? "test")); +``` + + diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/call/first-argument-expansion/jsx.js b/crates/rome_js_formatter/tests/specs/prettier/js/call/first-argument-expansion/jsx.js new file mode 100644 index 00000000000..4bea0a84f46 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/call/first-argument-expansion/jsx.js @@ -0,0 +1 @@ +content diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/call/first-argument-expansion/jsx.js.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/js/call/first-argument-expansion/jsx.js.prettier-snap new file mode 100644 index 00000000000..c248fc144d6 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/call/first-argument-expansion/jsx.js.prettier-snap @@ -0,0 +1,7 @@ + + content +; diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/call/first-argument-expansion/test.js b/crates/rome_js_formatter/tests/specs/prettier/js/call/first-argument-expansion/test.js new file mode 100644 index 00000000000..12e57d4987f --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/call/first-argument-expansion/test.js @@ -0,0 +1,113 @@ +setTimeout(function() { + thing(); +}, 500); + +["a","b","c"].reduce(function(item, thing) { + return thing + " " + item; +}, "letters:") + +func(() => { + thing(); +}, identifier); + +func(function() { + thing(); +}, this.props.timeout * 1000); + +func((that) => { + thing(); +}, this.props.getTimeout()); + +func(() => { + thing(); +}, true); + +func(() => { + thing(); +}, null); + +func(() => { + thing(); +}, undefined); + +func(() => { + thing(); +}, /regex.*?/); + +func(() => { + thing(); +}, 1 ? 2 : 3); + +func(function() { + return thing() +}, 1 ? 2 : 3); + +func(() => { + thing(); +}, something() ? someOtherThing() : somethingElse(true, 0)); + + +func(() => { + thing(); +}, something(longArgumentName, anotherLongArgumentName) ? someOtherThing() : somethingElse(true, 0)); + + +func(() => { + thing(); +}, something(longArgumentName, anotherLongArgumentName, anotherLongArgumentName, anotherLongArgumentName) ? someOtherThing() : somethingElse(true, 0)); + +compose((a) => { + return a.thing; +}, b => b * b); + +somthing.reduce(function(item, thing) { + return thing.blah = item; +}, {}) + +somthing.reduce(function(item, thing) { + return thing.push(item); +}, []) + +reallyLongLongLongLongLongLongLongLongLongLongLongLongLongLongMethod((f, g, h) => { + return f.pop(); +}, true); + +// Don't do the rest of these + +func(function() { + thing(); +}, true, false); + +func(() => { + thing(); +}, {yes: true, cats: 5}); + +compose((a) => { + return a.thing; +}, b => { + return b + ""; +}); + +compose((a) => { + return a.thing; +}, b => [1, 2, 3, 4, 5]); + +renderThing(a => +
Content. So much to say. Oh my. Are we done yet?
+,args); + +setTimeout( + // Something + function() { + thing(); + }, + 500 +); + +setTimeout(/* blip */ function() { + thing(); +}, 500); + +func((args) => { + execute(args); +}, result => result && console.log("success")) diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/call/first-argument-expansion/test.js.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/js/call/first-argument-expansion/test.js.prettier-snap new file mode 100644 index 00000000000..af78b8a7398 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/call/first-argument-expansion/test.js.prettier-snap @@ -0,0 +1,161 @@ +setTimeout(function () { + thing(); +}, 500); + +["a", "b", "c"].reduce(function (item, thing) { + return thing + " " + item; +}, "letters:"); + +func(() => { + thing(); +}, identifier); + +func(function () { + thing(); +}, this.props.timeout * 1000); + +func((that) => { + thing(); +}, this.props.getTimeout()); + +func(() => { + thing(); +}, true); + +func(() => { + thing(); +}, null); + +func(() => { + thing(); +}, undefined); + +func(() => { + thing(); +}, /regex.*?/); + +func( + () => { + thing(); + }, + 1 ? 2 : 3, +); + +func( + function () { + return thing(); + }, + 1 ? 2 : 3, +); + +func( + () => { + thing(); + }, + something() ? someOtherThing() : somethingElse(true, 0), +); + +func( + () => { + thing(); + }, + something(longArgumentName, anotherLongArgumentName) + ? someOtherThing() + : somethingElse(true, 0), +); + +func( + () => { + thing(); + }, + something( + longArgumentName, + anotherLongArgumentName, + anotherLongArgumentName, + anotherLongArgumentName, + ) + ? someOtherThing() + : somethingElse(true, 0), +); + +compose( + (a) => { + return a.thing; + }, + (b) => b * b, +); + +somthing.reduce(function (item, thing) { + return (thing.blah = item); +}, {}); + +somthing.reduce(function (item, thing) { + return thing.push(item); +}, []); + +reallyLongLongLongLongLongLongLongLongLongLongLongLongLongLongMethod( + (f, g, h) => { + return f.pop(); + }, + true, +); + +// Don't do the rest of these + +func( + function () { + thing(); + }, + true, + false, +); + +func( + () => { + thing(); + }, + { yes: true, cats: 5 }, +); + +compose( + (a) => { + return a.thing; + }, + (b) => { + return b + ""; + }, +); + +compose( + (a) => { + return a.thing; + }, + (b) => [1, 2, 3, 4, 5], +); + +renderThing( + (a) =>
Content. So much to say. Oh my. Are we done yet?
, + args, +); + +setTimeout( + // Something + function () { + thing(); + }, + 500, +); + +setTimeout( + /* blip */ function () { + thing(); + }, + 500, +); + +func( + (args) => { + execute(args); + }, + (result) => result && console.log("success"), +); diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/chain-expression/test.js b/crates/rome_js_formatter/tests/specs/prettier/js/chain-expression/test.js new file mode 100644 index 00000000000..86b2e6bd9ac --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/chain-expression/test.js @@ -0,0 +1,8 @@ +(a?.b).c; +(a?.()).b; + +(a?.b)(); +(a?.())(); + +new (a?.b)(); +new (a?.())(); diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/chain-expression/test.js.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/js/chain-expression/test.js.prettier-snap new file mode 100644 index 00000000000..86b2e6bd9ac --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/chain-expression/test.js.prettier-snap @@ -0,0 +1,8 @@ +(a?.b).c; +(a?.()).b; + +(a?.b)(); +(a?.())(); + +new (a?.b)(); +new (a?.())(); diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/chain-expression/test.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/chain-expression/test.js.snap new file mode 100644 index 00000000000..8539bb3056c --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/chain-expression/test.js.snap @@ -0,0 +1,54 @@ +--- +source: crates/rome_formatter_test/src/snapshot_builder.rs +info: js/chain-expression/test.js +--- + +# Input + +```js +(a?.b).c; +(a?.()).b; + +(a?.b)(); +(a?.())(); + +new (a?.b)(); +new (a?.())(); + +``` + + +# Prettier differences + +```diff +--- Prettier ++++ Rome +@@ -1,8 +1,8 @@ +-(a?.b).c; +-(a?.()).b; ++a?.b.c; ++a?.().b; + +-(a?.b)(); +-(a?.())(); ++a?.b(); ++a?.()(); + + new (a?.b)(); + new (a?.())(); +``` + +# Output + +```js +a?.b.c; +a?.().b; + +a?.b(); +a?.()(); + +new (a?.b)(); +new (a?.())(); +``` + + diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/class-extends/tuple-and-record.js b/crates/rome_js_formatter/tests/specs/prettier/js/class-extends/tuple-and-record.js new file mode 100644 index 00000000000..2adf77c4033 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/class-extends/tuple-and-record.js @@ -0,0 +1,5 @@ +class A extends {} {} +class B extends #{} {} + +class C extends [] {} +class D extends #[] {} diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/class-extends/tuple-and-record.js.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/js/class-extends/tuple-and-record.js.prettier-snap new file mode 100644 index 00000000000..c5a2744acd1 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/class-extends/tuple-and-record.js.prettier-snap @@ -0,0 +1,5 @@ +class A extends ({}) {} +class B extends #{} {} + +class C extends [] {} +class D extends #[] {} diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/class-extends/tuple-and-record.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/class-extends/tuple-and-record.js.snap new file mode 100644 index 00000000000..c0f67afa7f2 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/class-extends/tuple-and-record.js.snap @@ -0,0 +1,205 @@ +--- +source: crates/rome_formatter_test/src/snapshot_builder.rs +info: js/class-extends/tuple-and-record.js +--- + +# Input + +```js +class A extends {} {} +class B extends #{} {} + +class C extends [] {} +class D extends #[] {} + +``` + + +# Prettier differences + +```diff +--- Prettier ++++ Rome +@@ -1,5 +1,7 @@ + class A extends ({}) {} +-class B extends #{} {} ++class B extends #{} ++{ ++} + + class C extends [] {} + class D extends #[] {} +``` + +# Output + +```js +class A extends ({}) {} +class B extends #{} +{ +} + +class C extends [] {} +class D extends #[] {} +``` + +# Errors +``` +tuple-and-record.js:2:16 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × 'extends' list cannot be empty. + + 1 │ class A extends {} {} + > 2 │ class B extends #{} {} + │ + 3 │ + 4 │ class C extends [] {} + +tuple-and-record.js:2:17 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × expected `{` but instead found `#` + + 1 │ class A extends {} {} + > 2 │ class B extends #{} {} + │ ^ + 3 │ + 4 │ class C extends [] {} + + i Remove # + +tuple-and-record.js:2:18 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × expected an identifier but instead found '{' + + 1 │ class A extends {} {} + > 2 │ class B extends #{} {} + │ ^ + 3 │ + 4 │ class C extends [] {} + + i Expected an identifier here + + 1 │ class A extends {} {} + > 2 │ class B extends #{} {} + │ ^ + 3 │ + 4 │ class C extends [] {} + +tuple-and-record.js:2:17 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × expected a semicolon to end the class property, but found none + + 1 │ class A extends {} {} + > 2 │ class B extends #{} {} + │ ^ + 3 │ + 4 │ class C extends [] {} + +tuple-and-record.js:2:18 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × expected an identifier, a string literal, a number literal, a private field name, or a computed name but instead found '{' + + 1 │ class A extends {} {} + > 2 │ class B extends #{} {} + │ ^ + 3 │ + 4 │ class C extends [] {} + + i Expected an identifier, a string literal, a number literal, a private field name, or a computed name here + + 1 │ class A extends {} {} + > 2 │ class B extends #{} {} + │ ^ + 3 │ + 4 │ class C extends [] {} + +tuple-and-record.js:5:16 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × 'extends' list cannot be empty. + + 4 │ class C extends [] {} + > 5 │ class D extends #[] {} + │ + 6 │ + +tuple-and-record.js:5:17 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × expected `{` but instead found `#` + + 4 │ class C extends [] {} + > 5 │ class D extends #[] {} + │ ^ + 6 │ + + i Remove # + +tuple-and-record.js:5:18 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × expected an identifier but instead found '[' + + 4 │ class C extends [] {} + > 5 │ class D extends #[] {} + │ ^ + 6 │ + + i Expected an identifier here + + 4 │ class C extends [] {} + > 5 │ class D extends #[] {} + │ ^ + 6 │ + +tuple-and-record.js:5:17 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × expected a semicolon to end the class property, but found none + + 4 │ class C extends [] {} + > 5 │ class D extends #[] {} + │ ^ + 6 │ + +tuple-and-record.js:5:19 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × expected an expression but instead found ']' + + 4 │ class C extends [] {} + > 5 │ class D extends #[] {} + │ ^ + 6 │ + + i Expected an expression here + + 4 │ class C extends [] {} + > 5 │ class D extends #[] {} + │ ^ + 6 │ + +tuple-and-record.js:5:18 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × expected a semicolon to end the class property, but found none + + 4 │ class C extends [] {} + > 5 │ class D extends #[] {} + │ ^^ + 6 │ + +tuple-and-record.js:5:21 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × expected an identifier, a string literal, a number literal, a private field name, or a computed name but instead found '{' + + 4 │ class C extends [] {} + > 5 │ class D extends #[] {} + │ ^ + 6 │ + + i Expected an identifier, a string literal, a number literal, a private field name, or a computed name here + + 4 │ class C extends [] {} + > 5 │ class D extends #[] {} + │ ^ + 6 │ + + +``` + + diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/comments-closure-typecast/tuple-and-record.js b/crates/rome_js_formatter/tests/specs/prettier/js/comments-closure-typecast/tuple-and-record.js new file mode 100644 index 00000000000..e7986be1f23 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/comments-closure-typecast/tuple-and-record.js @@ -0,0 +1,27 @@ +foo = /** @type A */ ({ + // comment + width, + height, + ...margins, +}); + +foo = /** @type A */ (#{ + // comment + width, + height, + ...margins, +}); + +foo = /** @type A */ ([ + // comment + width, + height, + ...margins, +]); + +foo = /** @type A */ (#[ + // comment + width, + height, + ...margins, +]); diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/comments-closure-typecast/tuple-and-record.js.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/js/comments-closure-typecast/tuple-and-record.js.prettier-snap new file mode 100644 index 00000000000..e7986be1f23 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/comments-closure-typecast/tuple-and-record.js.prettier-snap @@ -0,0 +1,27 @@ +foo = /** @type A */ ({ + // comment + width, + height, + ...margins, +}); + +foo = /** @type A */ (#{ + // comment + width, + height, + ...margins, +}); + +foo = /** @type A */ ([ + // comment + width, + height, + ...margins, +]); + +foo = /** @type A */ (#[ + // comment + width, + height, + ...margins, +]); diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/comments-closure-typecast/tuple-and-record.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/comments-closure-typecast/tuple-and-record.js.snap new file mode 100644 index 00000000000..a876ca0f8c9 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/comments-closure-typecast/tuple-and-record.js.snap @@ -0,0 +1,259 @@ +--- +source: crates/rome_formatter_test/src/snapshot_builder.rs +info: js/comments-closure-typecast/tuple-and-record.js +--- + +# Input + +```js +foo = /** @type A */ ({ + // comment + width, + height, + ...margins, +}); + +foo = /** @type A */ (#{ + // comment + width, + height, + ...margins, +}); + +foo = /** @type A */ ([ + // comment + width, + height, + ...margins, +]); + +foo = /** @type A */ (#[ + // comment + width, + height, + ...margins, +]); + +``` + + +# Prettier differences + +```diff +--- Prettier ++++ Rome +@@ -5,12 +5,14 @@ + ...margins, + }); + +-foo = /** @type A */ (#{ ++foo = /** @type A */ (# ++{ + // comment + width, + height, + ...margins, +-}); ++} ++) + + foo = /** @type A */ ([ + // comment +@@ -23,5 +25,5 @@ + // comment + width, + height, +- ...margins, +-]); ++...margins, ++]) +``` + +# Output + +```js +foo = /** @type A */ ({ + // comment + width, + height, + ...margins, +}); + +foo = /** @type A */ (# +{ + // comment + width, + height, + ...margins, +} +) + +foo = /** @type A */ ([ + // comment + width, + height, + ...margins, +]); + +foo = /** @type A */ (#[ + // comment + width, + height, +...margins, +]) +``` + +# Errors +``` +tuple-and-record.js:8:24 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × expected an identifier but instead found '{' + + 6 │ }); + 7 │ + > 8 │ foo = /** @type A */ (#{ + │ ^ + 9 │ // comment + 10 │ width, + + i Expected an identifier here + + 6 │ }); + 7 │ + > 8 │ foo = /** @type A */ (#{ + │ ^ + 9 │ // comment + 10 │ width, + +tuple-and-record.js:8:23 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × Private names are only allowed on the left side of a 'in' expression + + 6 │ }); + 7 │ + > 8 │ foo = /** @type A */ (#{ + │ ^ + 9 │ // comment + 10 │ width, + +tuple-and-record.js:8:24 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × expected `)` but instead found `{` + + 6 │ }); + 7 │ + > 8 │ foo = /** @type A */ (#{ + │ ^ + 9 │ // comment + 10 │ width, + + i Remove { + +tuple-and-record.js:12:3 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × expected an expression but instead found '...' + + 10 │ width, + 11 │ height, + > 12 │ ...margins, + │ ^^^ + 13 │ }); + 14 │ + + i Expected an expression here + + 10 │ width, + 11 │ height, + > 12 │ ...margins, + │ ^^^ + 13 │ }); + 14 │ + +tuple-and-record.js:13:2 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × expected a statement but instead found ')' + + 11 │ height, + 12 │ ...margins, + > 13 │ }); + │ ^ + 14 │ + 15 │ foo = /** @type A */ ([ + + i Expected a statement here + + 11 │ height, + 12 │ ...margins, + > 13 │ }); + │ ^ + 14 │ + 15 │ foo = /** @type A */ ([ + +tuple-and-record.js:22:24 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × expected an identifier but instead found '[' + + 20 │ ]); + 21 │ + > 22 │ foo = /** @type A */ (#[ + │ ^ + 23 │ // comment + 24 │ width, + + i Expected an identifier here + + 20 │ ]); + 21 │ + > 22 │ foo = /** @type A */ (#[ + │ ^ + 23 │ // comment + 24 │ width, + +tuple-and-record.js:22:23 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × Private names are only allowed on the left side of a 'in' expression + + 20 │ ]); + 21 │ + > 22 │ foo = /** @type A */ (#[ + │ ^ + 23 │ // comment + 24 │ width, + +tuple-and-record.js:22:24 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × expected `)` but instead found `[` + + 20 │ ]); + 21 │ + > 22 │ foo = /** @type A */ (#[ + │ ^ + 23 │ // comment + 24 │ width, + + i Remove [ + +tuple-and-record.js:26:3 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × expected an expression but instead found '...' + + 24 │ width, + 25 │ height, + > 26 │ ...margins, + │ ^^^ + 27 │ ]); + 28 │ + + i Expected an expression here + + 24 │ width, + 25 │ height, + > 26 │ ...margins, + │ ^^^ + 27 │ ]); + 28 │ + + +``` + + diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/comments/empty-statements.js b/crates/rome_js_formatter/tests/specs/prettier/js/comments/empty-statements.js new file mode 100644 index 00000000000..c2386508afa --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/comments/empty-statements.js @@ -0,0 +1,20 @@ +a; /* a */ // b +; /* c */ + +foo; // first +;// second +;// third + +function x() { +} // first +; // second + +a = ( + b // 1 + + // 2 + c // 3 + + // 4 + d // 5 + + /* 6 */ + e // 7 +); diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/comments/empty-statements.js.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/js/comments/empty-statements.js.prettier-snap new file mode 100644 index 00000000000..4ebf7dc6e22 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/comments/empty-statements.js.prettier-snap @@ -0,0 +1,15 @@ +a; /* a */ // b +/* c */ +foo; // first +// second +// third +function x() {} // first +// second +a = + b + // 1 + // 2 + c + // 3 + // 4 + d + // 5 + /* 6 */ + e; // 7 diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/comments/empty-statements.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/comments/empty-statements.js.snap new file mode 100644 index 00000000000..8c423af2860 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/comments/empty-statements.js.snap @@ -0,0 +1,81 @@ +--- +source: crates/rome_formatter_test/src/snapshot_builder.rs +info: js/comments/empty-statements.js +--- + +# Input + +```js +a; /* a */ // b +; /* c */ + +foo; // first +;// second +;// third + +function x() { +} // first +; // second + +a = ( + b // 1 + + // 2 + c // 3 + + // 4 + d // 5 + + /* 6 */ + e // 7 +); + +``` + + +# Prettier differences + +```diff +--- Prettier ++++ Rome +@@ -1,15 +1,11 @@ +-a; /* a */ // b +-/* c */ +-foo; // first +-// second +-// third +-function x() {} // first +-// second ++a; /* a */ /* c */ // b ++ ++foo; // first // second // third ++ ++function x() {} // first // second ++ + a = +- b + // 1 +- // 2 +- c + // 3 +- // 4 +- d + // 5 +- /* 6 */ ++ b + // 1 // 2 ++ c + // 3 // 4 ++ d /* 6 */ + // 5 + e; // 7 +``` + +# Output + +```js +a; /* a */ /* c */ // b + +foo; // first // second // third + +function x() {} // first // second + +a = + b + // 1 // 2 + c + // 3 // 4 + d /* 6 */ + // 5 + e; // 7 +``` + + diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/comments/jsdoc-nestled-dangling.js b/crates/rome_js_formatter/tests/specs/prettier/js/comments/jsdoc-nestled-dangling.js new file mode 100644 index 00000000000..6962ecef2ef --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/comments/jsdoc-nestled-dangling.js @@ -0,0 +1,10 @@ +{{{{{{{ +o={ + /** + * A + *//** + * B + */ + +} +}}}}}}} diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/comments/jsdoc-nestled-dangling.js.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/js/comments/jsdoc-nestled-dangling.js.prettier-snap new file mode 100644 index 00000000000..f974a6eb2c3 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/comments/jsdoc-nestled-dangling.js.prettier-snap @@ -0,0 +1,21 @@ +{ + { + { + { + { + { + { + o = { + /** + * A + *//** + * B + */ + }; + } + } + } + } + } + } +} diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/comments/jsdoc-nestled-dangling.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/comments/jsdoc-nestled-dangling.js.snap new file mode 100644 index 00000000000..37c41c09467 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/comments/jsdoc-nestled-dangling.js.snap @@ -0,0 +1,67 @@ +--- +source: crates/rome_formatter_test/src/snapshot_builder.rs +info: js/comments/jsdoc-nestled-dangling.js +--- + +# Input + +```js +{{{{{{{ +o={ + /** + * A + *//** + * B + */ + +} +}}}}}}} + +``` + + +# Prettier differences + +```diff +--- Prettier ++++ Rome +@@ -8,7 +8,8 @@ + o = { + /** + * A +- *//** ++ */ ++ /** + * B + */ + }; +``` + +# Output + +```js +{ + { + { + { + { + { + { + o = { + /** + * A + */ + /** + * B + */ + }; + } + } + } + } + } + } +} +``` + + diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/comments/jsdoc-nestled.js b/crates/rome_js_formatter/tests/specs/prettier/js/comments/jsdoc-nestled.js new file mode 100644 index 00000000000..9723175b504 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/comments/jsdoc-nestled.js @@ -0,0 +1,28 @@ +const issues = { + see: "#7724 and #12653" + /** Trailing comment 1 (not nestled as both comments should be multiline for that) *//** + * Trailing comment 2 + */ +}; + +/** + * @template T + * @param {Type} type + * @param {T} value + * @return {Value} + *//** + * @param {Type} type + * @return {Value} + */ +function value(type, value) { + if (arguments.length === 2) { + return new ConcreteValue(type, value); + } else { + return new Value(type); + } +} + +/** Trailing nestled comment 1 + *//** Trailing nestled comment 2 + *//** Trailing nestled comment 3 + */ diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/comments/jsdoc-nestled.js.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/js/comments/jsdoc-nestled.js.prettier-snap new file mode 100644 index 00000000000..eeac9a5e1f9 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/comments/jsdoc-nestled.js.prettier-snap @@ -0,0 +1,28 @@ +const issues = { + see: "#7724 and #12653", + /** Trailing comment 1 (not nestled as both comments should be multiline for that) */ /** + * Trailing comment 2 + */ +}; + +/** + * @template T + * @param {Type} type + * @param {T} value + * @return {Value} + *//** + * @param {Type} type + * @return {Value} + */ +function value(type, value) { + if (arguments.length === 2) { + return new ConcreteValue(type, value); + } else { + return new Value(type); + } +} + +/** Trailing nestled comment 1 + *//** Trailing nestled comment 2 + *//** Trailing nestled comment 3 + */ diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/comments/jsdoc-nestled.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/comments/jsdoc-nestled.js.snap new file mode 100644 index 00000000000..425b9fc4c72 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/comments/jsdoc-nestled.js.snap @@ -0,0 +1,118 @@ +--- +source: crates/rome_formatter_test/src/snapshot_builder.rs +info: js/comments/jsdoc-nestled.js +--- + +# Input + +```js +const issues = { + see: "#7724 and #12653" + /** Trailing comment 1 (not nestled as both comments should be multiline for that) *//** + * Trailing comment 2 + */ +}; + +/** + * @template T + * @param {Type} type + * @param {T} value + * @return {Value} + *//** + * @param {Type} type + * @return {Value} + */ +function value(type, value) { + if (arguments.length === 2) { + return new ConcreteValue(type, value); + } else { + return new Value(type); + } +} + +/** Trailing nestled comment 1 + *//** Trailing nestled comment 2 + *//** Trailing nestled comment 3 + */ + +``` + + +# Prettier differences + +```diff +--- Prettier ++++ Rome +@@ -1,6 +1,7 @@ + const issues = { + see: "#7724 and #12653", +- /** Trailing comment 1 (not nestled as both comments should be multiline for that) */ /** ++ /** Trailing comment 1 (not nestled as both comments should be multiline for that) */ ++ /** + * Trailing comment 2 + */ + }; +@@ -10,7 +11,7 @@ + * @param {Type} type + * @param {T} value + * @return {Value} +- *//** ++ */ /** + * @param {Type} type + * @return {Value} + */ +@@ -23,5 +24,8 @@ + } + + /** Trailing nestled comment 1 +- *//** Trailing nestled comment 2 +- *//** Trailing nestled comment 3 + */ ++/** Trailing nestled comment 2 ++ */ ++/** Trailing nestled comment 3 ++ */ +``` + +# Output + +```js +const issues = { + see: "#7724 and #12653", + /** Trailing comment 1 (not nestled as both comments should be multiline for that) */ + /** + * Trailing comment 2 + */ +}; + +/** + * @template T + * @param {Type} type + * @param {T} value + * @return {Value} + */ /** + * @param {Type} type + * @return {Value} + */ +function value(type, value) { + if (arguments.length === 2) { + return new ConcreteValue(type, value); + } else { + return new Value(type); + } +} + +/** Trailing nestled comment 1 + */ +/** Trailing nestled comment 2 + */ +/** Trailing nestled comment 3 + */ +``` + +# Lines exceeding max width of 80 characters +``` + 3: /** Trailing comment 1 (not nestled as both comments should be multiline for that) */ +``` + + diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/comments/jsx.js.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/js/comments/jsx.js.prettier-snap index c06ff16e7f9..6ad34bfddfd 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/js/comments/jsx.js.prettier-snap +++ b/crates/rome_js_formatter/tests/specs/prettier/js/comments/jsx.js.prettier-snap @@ -9,8 +9,7 @@
{ - a - /* comment + a /* comment */ }
; diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/comments/jsx.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/comments/jsx.js.snap deleted file mode 100644 index 1f518dfbfb7..00000000000 --- a/crates/rome_js_formatter/tests/specs/prettier/js/comments/jsx.js.snap +++ /dev/null @@ -1,270 +0,0 @@ ---- -source: crates/rome_formatter_test/src/snapshot_builder.rs -assertion_line: 212 -info: js/comments/jsx.js ---- - -# Input - -```js -
- { - /* comment */ - } -
; - -
- {/* comment */ - } -
; - -
- {/* comment -*/ - } -
; - -
- {a/* comment -*/ - } -
; - -
- {/* comment -*/ - a - } -
; - -
- {/* comment */ - } -
; - -
- {/* comment */} -
; - -
- { - // single line comment - } -
; - -
- { - // multiple line comments 1 - // multiple line comments 2 - } -
; - -
- { - // multiple mixed comments 1 - /* multiple mixed comments 2 */ - /* multiple mixed comments 3 */ - // multiple mixed comments 4 - } -
; - -
- { - // Some very v ery very very merry (xmas) very very long line to break line width limit - } -
; - -
{/*
Some very v ery very very long line to break line width limit
*/}
; - -
- {/** - * JSDoc-y comment in JSX. I wonder what will happen to it? - */} -
; - -
- { - /** - * Another JSDoc comment in JSX. - */ - } -
; - -
{}}> - -
; - -
- {foo} -
; - -
- {foo} -
; - -
- {foo} -
; - -
- {children} -
; - - - {} - - - -``` - - -# Prettier differences - -```diff ---- Prettier -+++ Rome -@@ -9,8 +9,7 @@ - -
- { -- a -- /* comment -+ a /* comment - */ - } -
; -``` - -# Output - -```js -
{/* comment */}
; - -
{/* comment */}
; - -
- {/* comment - */} -
; - -
- { - a /* comment - */ - } -
; - -
- { - /* comment - */ - a - } -
; - -
{/* comment */}
; - -
{/* comment */}
; - -
- { - // single line comment - } -
; - -
- { - // multiple line comments 1 - // multiple line comments 2 - } -
; - -
- { - // multiple mixed comments 1 - /* multiple mixed comments 2 */ - /* multiple mixed comments 3 */ - // multiple mixed comments 4 - } -
; - -
- { - // Some very v ery very very merry (xmas) very very long line to break line width limit - } -
; - -
- {/*
Some very v ery very very long line to break line width limit
*/} -
; - -
- {/** - * JSDoc-y comment in JSX. I wonder what will happen to it? - */} -
; - -
- {/** - * Another JSDoc comment in JSX. - */} -
; - -
{}} ->
; - -
- {foo} -
; - -
- {foo} -
; - -
- {foo} -
; - -
- {children} -
; - - - {} - -; -``` - -# Lines exceeding max width of 80 characters -``` - 53: // Some very v ery very very merry (xmas) very very long line to break line width limit - 58: {/*
Some very v ery very very long line to break line width limit
*/} -``` - - diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/comments/multi-comments-on-same-line.js.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/js/comments/multi-comments-on-same-line.js.prettier-snap index 02facde8a46..98533fd3583 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/js/comments/multi-comments-on-same-line.js.prettier-snap +++ b/crates/rome_js_formatter/tests/specs/prettier/js/comments/multi-comments-on-same-line.js.prettier-snap @@ -16,8 +16,7 @@ a; b; a; /* -1*/ /*2*/ -/*3 +1*/ /*2*/ /*3 */ b; diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/comments/multi-comments-on-same-line.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/comments/multi-comments-on-same-line.js.snap index b06408dc1b8..0aa7a06200d 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/js/comments/multi-comments-on-same-line.js.snap +++ b/crates/rome_js_formatter/tests/specs/prettier/js/comments/multi-comments-on-same-line.js.snap @@ -1,6 +1,5 @@ --- source: crates/rome_formatter_test/src/snapshot_builder.rs -assertion_line: 212 info: js/comments/multi-comments-on-same-line.js --- @@ -105,13 +104,7 @@ a;/* ```diff --- Prettier +++ Rome -@@ -16,15 +16,14 @@ - b; - - a; /* --1*/ /*2*/ --/*3 -+1*/ /*2*/ /*3 +@@ -20,10 +20,10 @@ */ b; diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/comments/trailing-jsdocs.js.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/js/comments/trailing-jsdocs.js.prettier-snap index c2a54b85adc..c19b4dd93c8 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/js/comments/trailing-jsdocs.js.prettier-snap +++ b/crates/rome_js_formatter/tests/specs/prettier/js/comments/trailing-jsdocs.js.prettier-snap @@ -5,11 +5,9 @@ const CONNECTION_STATUS = (exports.CONNECTION_STATUS = { NOT_CONNECTED: Object.freeze({ kind: "NOT_CONNECTED" }), }); -/* A comment */ -/** +/* A comment */ /** * A type that can be written to a buffer. - */ -/** + */ /** * Describes the connection status of a ReactiveSocket/DuplexConnection. * - NOT_CONNECTED: no connection established or pending. * - CONNECTING: when `connect()` has been called but a connection is not yet @@ -17,11 +15,9 @@ const CONNECTION_STATUS = (exports.CONNECTION_STATUS = { * - CONNECTED: when a connection is established. * - CLOSED: when the connection has been explicitly closed via `close()`. * - ERROR: when the connection has been closed for any other reason. - */ -/** + */ /** * A contract providing different interaction models per the [ReactiveSocket protocol] * (https://github.com/ReactiveSocket/reactivesocket/blob/master/Protocol.md). - */ -/** + */ /** * A single unit of data exchanged between the peers of a `ReactiveSocket`. */ diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/comments/trailing-jsdocs.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/comments/trailing-jsdocs.js.snap new file mode 100644 index 00000000000..d3414a95202 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/comments/trailing-jsdocs.js.snap @@ -0,0 +1,107 @@ +--- +source: crates/rome_formatter_test/src/snapshot_builder.rs +info: js/comments/trailing-jsdocs.js +--- + +# Input + +```js +const CONNECTION_STATUS = exports.CONNECTION_STATUS = { + CLOSED: Object.freeze({ kind: 'CLOSED' }), + CONNECTED: Object.freeze({ kind: 'CONNECTED' }), + CONNECTING: Object.freeze({ kind: 'CONNECTING' }), + NOT_CONNECTED: Object.freeze({ kind: 'NOT_CONNECTED' }) }; + +/* A comment */ /** +* A type that can be written to a buffer. +*/ /** +* Describes the connection status of a ReactiveSocket/DuplexConnection. +* - NOT_CONNECTED: no connection established or pending. +* - CONNECTING: when `connect()` has been called but a connection is not yet +* established. +* - CONNECTED: when a connection is established. +* - CLOSED: when the connection has been explicitly closed via `close()`. +* - ERROR: when the connection has been closed for any other reason. +*/ /** +* A contract providing different interaction models per the [ReactiveSocket protocol] +* (https://github.com/ReactiveSocket/reactivesocket/blob/master/Protocol.md). +*/ /** +* A single unit of data exchanged between the peers of a `ReactiveSocket`. +*/ + +``` + + +# Prettier differences + +```diff +--- Prettier ++++ Rome +@@ -5,9 +5,11 @@ + NOT_CONNECTED: Object.freeze({ kind: "NOT_CONNECTED" }), + }); + +-/* A comment */ /** ++/* A comment */ ++/** + * A type that can be written to a buffer. +- */ /** ++ */ ++/** + * Describes the connection status of a ReactiveSocket/DuplexConnection. + * - NOT_CONNECTED: no connection established or pending. + * - CONNECTING: when `connect()` has been called but a connection is not yet +@@ -15,9 +17,11 @@ + * - CONNECTED: when a connection is established. + * - CLOSED: when the connection has been explicitly closed via `close()`. + * - ERROR: when the connection has been closed for any other reason. +- */ /** ++ */ ++/** + * A contract providing different interaction models per the [ReactiveSocket protocol] + * (https://github.com/ReactiveSocket/reactivesocket/blob/master/Protocol.md). +- */ /** ++ */ ++/** + * A single unit of data exchanged between the peers of a `ReactiveSocket`. + */ +``` + +# Output + +```js +const CONNECTION_STATUS = (exports.CONNECTION_STATUS = { + CLOSED: Object.freeze({ kind: "CLOSED" }), + CONNECTED: Object.freeze({ kind: "CONNECTED" }), + CONNECTING: Object.freeze({ kind: "CONNECTING" }), + NOT_CONNECTED: Object.freeze({ kind: "NOT_CONNECTED" }), +}); + +/* A comment */ +/** + * A type that can be written to a buffer. + */ +/** + * Describes the connection status of a ReactiveSocket/DuplexConnection. + * - NOT_CONNECTED: no connection established or pending. + * - CONNECTING: when `connect()` has been called but a connection is not yet + * established. + * - CONNECTED: when a connection is established. + * - CLOSED: when the connection has been explicitly closed via `close()`. + * - ERROR: when the connection has been closed for any other reason. + */ +/** + * A contract providing different interaction models per the [ReactiveSocket protocol] + * (https://github.com/ReactiveSocket/reactivesocket/blob/master/Protocol.md). + */ +/** + * A single unit of data exchanged between the peers of a `ReactiveSocket`. + */ +``` + +# Lines exceeding max width of 80 characters +``` + 22: * A contract providing different interaction models per the [ReactiveSocket protocol] +``` + + diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/comments/tuple-and-record.js b/crates/rome_js_formatter/tests/specs/prettier/js/comments/tuple-and-record.js new file mode 100644 index 00000000000..cd560095f03 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/comments/tuple-and-record.js @@ -0,0 +1,19 @@ +let object = // Comment +{ + key: 'value' +} + +let record = // Comment +#{ + key: 'value' +} + +let array = // Comment +[ + 'value' +] + +let tuple = // Comment +#[ + 'value' +] diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/comments/tuple-and-record.js.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/js/comments/tuple-and-record.js.prettier-snap new file mode 100644 index 00000000000..8862538ad32 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/comments/tuple-and-record.js.prettier-snap @@ -0,0 +1,19 @@ +let object = + // Comment + { + key: "value", + }; + +let record = + // Comment + #{ + key: "value", + }; + +let array = + // Comment + ["value"]; + +let tuple = + // Comment + #["value"]; diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/comments/tuple-and-record.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/comments/tuple-and-record.js.snap new file mode 100644 index 00000000000..59f148392ae --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/comments/tuple-and-record.js.snap @@ -0,0 +1,207 @@ +--- +source: crates/rome_formatter_test/src/snapshot_builder.rs +info: js/comments/tuple-and-record.js +--- + +# Input + +```js +let object = // Comment +{ + key: 'value' +} + +let record = // Comment +#{ + key: 'value' +} + +let array = // Comment +[ + 'value' +] + +let tuple = // Comment +#[ + 'value' +] + +``` + + +# Prettier differences + +```diff +--- Prettier ++++ Rome +@@ -4,16 +4,16 @@ + key: "value", + }; + +-let record = +- // Comment +- #{ +- key: "value", +- }; ++let record = // Comment ++ #; ++{ ++ key: "value"; ++} + + let array = + // Comment + ["value"]; + +-let tuple = +- // Comment +- #["value"]; ++let tuple = // Comment ++ #; ++["value"]; +``` + +# Output + +```js +let object = + // Comment + { + key: "value", + }; + +let record = // Comment + #; +{ + key: "value"; +} + +let array = + // Comment + ["value"]; + +let tuple = // Comment + #; +["value"]; +``` + +# Errors +``` +tuple-and-record.js:7:2 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × expected an identifier but instead found '{' + + 6 │ let record = // Comment + > 7 │ #{ + │ ^ + 8 │ key: 'value' + 9 │ } + + i Expected an identifier here + + 6 │ let record = // Comment + > 7 │ #{ + │ ^ + 8 │ key: 'value' + 9 │ } + +tuple-and-record.js:7:1 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × Private names are only allowed on the left side of a 'in' expression + + 6 │ let record = // Comment + > 7 │ #{ + │ ^ + 8 │ key: 'value' + 9 │ } + +tuple-and-record.js:7:2 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × Expected a semicolon or an implicit semicolon after a statement, but found none + + 6 │ let record = // Comment + > 7 │ #{ + │ ^ + 8 │ key: 'value' + 9 │ } + + i An explicit or implicit semicolon is expected here... + + 6 │ let record = // Comment + > 7 │ #{ + │ ^ + 8 │ key: 'value' + 9 │ } + + i ...Which is required to end this statement + + 4 │ } + 5 │ + > 6 │ let record = // Comment + │ ^^^^^^^^^^^^^^^^^^^^^^^ + > 7 │ #{ + │ ^ + 8 │ key: 'value' + 9 │ } + +tuple-and-record.js:17:2 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × expected an identifier but instead found '[' + + 16 │ let tuple = // Comment + > 17 │ #[ + │ ^ + 18 │ 'value' + 19 │ ] + + i Expected an identifier here + + 16 │ let tuple = // Comment + > 17 │ #[ + │ ^ + 18 │ 'value' + 19 │ ] + +tuple-and-record.js:17:1 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × Private names are only allowed on the left side of a 'in' expression + + 16 │ let tuple = // Comment + > 17 │ #[ + │ ^ + 18 │ 'value' + 19 │ ] + +tuple-and-record.js:17:2 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × Expected a semicolon or an implicit semicolon after a statement, but found none + + 16 │ let tuple = // Comment + > 17 │ #[ + │ ^ + 18 │ 'value' + 19 │ ] + + i An explicit or implicit semicolon is expected here... + + 16 │ let tuple = // Comment + > 17 │ #[ + │ ^ + 18 │ 'value' + 19 │ ] + + i ...Which is required to end this statement + + 14 │ ] + 15 │ + > 16 │ let tuple = // Comment + │ ^^^^^^^^^^^^^^^^^^^^^^ + > 17 │ #[ + │ ^ + 18 │ 'value' + 19 │ ] + + +``` + + diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/cursor/cursor-emoji.js b/crates/rome_js_formatter/tests/specs/prettier/js/cursor/cursor-emoji.js new file mode 100644 index 00000000000..c1a8863d515 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/cursor/cursor-emoji.js @@ -0,0 +1 @@ +"😀😀😀😀<|>" diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/cursor/cursor-emoji.js.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/js/cursor/cursor-emoji.js.prettier-snap new file mode 100644 index 00000000000..c9442b05a0b --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/cursor/cursor-emoji.js.prettier-snap @@ -0,0 +1 @@ +"😀😀😀😀<|>"; diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/decorators/class-expression/arguments.js.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/js/decorators/class-expression/arguments.js.prettier-snap index 0c2170803f1..8ed29ec3615 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/js/decorators/class-expression/arguments.js.prettier-snap +++ b/crates/rome_js_formatter/tests/specs/prettier/js/decorators/class-expression/arguments.js.prettier-snap @@ -1,12 +1,8 @@ console.log( - ( - @deco - class Foo {} - ), + @deco + class Foo {}, ); console.log( - ( - @deco - class {} - ), + @deco + class {}, ); diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/decorators/class-expression/arguments.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/decorators/class-expression/arguments.js.snap new file mode 100644 index 00000000000..8c34cdac708 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/decorators/class-expression/arguments.js.snap @@ -0,0 +1,56 @@ +--- +source: crates/rome_formatter_test/src/snapshot_builder.rs +info: js/decorators/class-expression/arguments.js +--- + +# Input + +```js +console.log(@deco class Foo {}) +console.log(@deco class {}) + +``` + + +# Prettier differences + +```diff +--- Prettier ++++ Rome +@@ -1,8 +1,12 @@ + console.log( +- @deco +- class Foo {}, ++ ( ++ @deco ++ class Foo {} ++ ), + ); + console.log( +- @deco +- class {}, ++ ( ++ @deco ++ class {} ++ ), + ); +``` + +# Output + +```js +console.log( + ( + @deco + class Foo {} + ), +); +console.log( + ( + @deco + class {} + ), +); +``` + + diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/decorators/class-expression/class-expression.js.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/js/decorators/class-expression/class-expression.js.prettier-snap index 5711c5f3095..2a85b8156d4 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/js/decorators/class-expression/class-expression.js.prettier-snap +++ b/crates/rome_js_formatter/tests/specs/prettier/js/decorators/class-expression/class-expression.js.prettier-snap @@ -1,13 +1,9 @@ const a1 = - ( - @deco - class Foo {} - ); + @deco + class Foo {}; const a2 = - ( - @deco - class {} - ); + @deco + class {}; ( @deco diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/decorators/class-expression/class-expression.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/decorators/class-expression/class-expression.js.snap new file mode 100644 index 00000000000..0cd99f3a95b --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/decorators/class-expression/class-expression.js.snap @@ -0,0 +1,92 @@ +--- +source: crates/rome_formatter_test/src/snapshot_builder.rs +info: js/decorators/class-expression/class-expression.js +--- + +# Input + +```js +const a1 = (@deco class Foo {}); +const a2 = (@deco class {}); + +(@deco class Foo {}); +(@deco class {}); + +const b1 = [] +;(@deco class Foo {}) + +const b2 = [] +;(@deco class {}) + +// This is not a `ClassExpression` but `ClassDeclaration` +@deco class Foo {} + +``` + + +# Prettier differences + +```diff +--- Prettier ++++ Rome +@@ -1,9 +1,13 @@ + const a1 = +- @deco +- class Foo {}; ++ ( ++ @deco ++ class Foo {} ++ ); + const a2 = +- @deco +- class {}; ++ ( ++ @deco ++ class {} ++ ); + + ( + @deco +``` + +# Output + +```js +const a1 = + ( + @deco + class Foo {} + ); +const a2 = + ( + @deco + class {} + ); + +( + @deco + class Foo {} +); +( + @deco + class {} +); + +const b1 = []; +( + @deco + class Foo {} +); + +const b2 = []; +( + @deco + class {} +); + +// This is not a `ClassExpression` but `ClassDeclaration` +@deco +class Foo {} +``` + + diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/decorators/classes.js.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/js/decorators/classes.js.prettier-snap index 30987e5db7b..98d2ee13ef8 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/js/decorators/classes.js.prettier-snap +++ b/crates/rome_js_formatter/tests/specs/prettier/js/decorators/classes.js.prettier-snap @@ -8,17 +8,13 @@ export class Bar {} export default class Baz {} const foo = - ( - @deco - class { - // - } - ); + @deco + class { + // + }; const bar = - ( - @deco - class { - // - } - ); + @deco + class { + // + }; diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/decorators/classes.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/decorators/classes.js.snap new file mode 100644 index 00000000000..0daeb51e365 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/decorators/classes.js.snap @@ -0,0 +1,90 @@ +--- +source: crates/rome_formatter_test/src/snapshot_builder.rs +info: js/decorators/classes.js +--- + +# Input + +```js +@deco class Foo {} + +@deco export class Bar {} + +@deco export default class Baz {} + +const foo = @deco class { + // +}; + +const bar = + @deco + class { + // + }; + +``` + + +# Prettier differences + +```diff +--- Prettier ++++ Rome +@@ -8,13 +8,17 @@ + export default class Baz {} + + const foo = +- @deco +- class { +- // +- }; ++ ( ++ @deco ++ class { ++ // ++ } ++ ); + + const bar = +- @deco +- class { +- // +- }; ++ ( ++ @deco ++ class { ++ // ++ } ++ ); +``` + +# Output + +```js +@deco +class Foo {} + +@deco +export class Bar {} + +@deco +export default class Baz {} + +const foo = + ( + @deco + class { + // + } + ); + +const bar = + ( + @deco + class { + // + } + ); +``` + + diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/decorators/comments.js b/crates/rome_js_formatter/tests/specs/prettier/js/decorators/comments.js index 8aa68576c59..8a647cdcf91 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/js/decorators/comments.js +++ b/crates/rome_js_formatter/tests/specs/prettier/js/decorators/comments.js @@ -29,3 +29,8 @@ export class AppModule {} @Bar() // C export class Bar{} + +class Something { + @Annotateme() + property; +} diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/decorators/comments.js.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/js/decorators/comments.js.prettier-snap index 614664decd1..11471303c38 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/js/decorators/comments.js.prettier-snap +++ b/crates/rome_js_formatter/tests/specs/prettier/js/decorators/comments.js.prettier-snap @@ -26,3 +26,8 @@ export class AppModule {} @Bar() // C export class Bar {} + +class Something { + @Annotateme() + property; +} diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/decorators/member-expression.js.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/js/decorators/member-expression.js.prettier-snap index 4cd2681adc3..0614bd8faf1 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/js/decorators/member-expression.js.prettier-snap +++ b/crates/rome_js_formatter/tests/specs/prettier/js/decorators/member-expression.js.prettier-snap @@ -39,16 +39,12 @@ @(decorators["first"]) method() {} }, - ( - @(decorators[first]) - class { - method() {} - } - ), - ( - @(decorators[0]) - class { - method() {} - } - ), + @(decorators[first]) + class { + method() {} + }, + @(decorators[0]) + class { + method() {} + }, ]; diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/decorators/member-expression.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/decorators/member-expression.js.snap index 3d86037e90e..f1dd29ff978 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/js/decorators/member-expression.js.snap +++ b/crates/rome_js_formatter/tests/specs/prettier/js/decorators/member-expression.js.snap @@ -83,6 +83,31 @@ info: js/decorators/member-expression.js method() {} }, class { +@@ -39,12 +39,16 @@ + @(decorators["first"]) + method() {} + }, +- @(decorators[first]) +- class { +- method() {} +- }, +- @(decorators[0]) +- class { +- method() {} +- }, ++ ( ++ @(decorators[first]) ++ class { ++ method() {} ++ } ++ ), ++ ( ++ @(decorators[0]) ++ class { ++ method() {} ++ } ++ ), + ]; ``` # Output diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/decorators/mobx.js b/crates/rome_js_formatter/tests/specs/prettier/js/decorators/mobx.js index 8a497af8062..2974474a586 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/js/decorators/mobx.js +++ b/crates/rome_js_formatter/tests/specs/prettier/js/decorators/mobx.js @@ -1,8 +1,8 @@ import {observable} from "mobx"; @observer class OrderLine { - @observable price:number = 0; - @observable amount:number = 1; + @observable price = 0; + @observable amount = 1; constructor(price) { this.price = price; @@ -25,12 +25,12 @@ import {observable} from "mobx"; setPrice(price) { this.price = price; } - + @computed @computed @computed @computed @computed @computed @computed get total() { return this.price * this.amount; } - @action handleDecrease = (event: React.ChangeEvent) => this.count--; - - @action handleSomething = (event: React.ChangeEvent) => doSomething(); + @action handleDecrease = (event) => this.count--; + + @action handleSomething = (event) => doSomething(); } diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/decorators/mobx.js.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/js/decorators/mobx.js.prettier-snap index a1daee3b10a..ccfd4bf71f9 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/js/decorators/mobx.js.prettier-snap +++ b/crates/rome_js_formatter/tests/specs/prettier/js/decorators/mobx.js.prettier-snap @@ -2,8 +2,8 @@ import { observable } from "mobx"; @observer class OrderLine { - @observable price: number = 0; - @observable amount: number = 1; + @observable price = 0; + @observable amount = 1; constructor(price) { this.price = price; @@ -38,9 +38,7 @@ class OrderLine { return this.price * this.amount; } - @action handleDecrease = (event: React.ChangeEvent) => - this.count--; + @action handleDecrease = (event) => this.count--; - @action handleSomething = (event: React.ChangeEvent) => - doSomething(); + @action handleSomething = (event) => doSomething(); } diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/decorators/mobx.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/decorators/mobx.js.snap deleted file mode 100644 index 54489131594..00000000000 --- a/crates/rome_js_formatter/tests/specs/prettier/js/decorators/mobx.js.snap +++ /dev/null @@ -1,190 +0,0 @@ ---- -source: crates/rome_formatter_test/src/snapshot_builder.rs -info: js/decorators/mobx.js ---- - -# Input - -```js -import {observable} from "mobx"; - -@observer class OrderLine { - @observable price:number = 0; - @observable amount:number = 1; - - constructor(price) { - this.price = price; - } - - @computed get total() { - return this.price * this.amount; - } - - @action.bound setPrice(price) { - this.price = price; - } - - @computed - get total() { - return this.price * this.amount; - } - - @action.bound - setPrice(price) { - this.price = price; - } - - @computed @computed @computed @computed @computed @computed @computed get total() { - return this.price * this.amount; - } - - @action handleDecrease = (event: React.ChangeEvent) => this.count--; - - @action handleSomething = (event: React.ChangeEvent) => doSomething(); -} - -``` - - -# Prettier differences - -```diff ---- Prettier -+++ Rome -@@ -2,8 +2,8 @@ - - @observer - class OrderLine { -- @observable price: number = 0; -- @observable amount: number = 1; -+ @observable price:number = 0; -+ @observable amount:number = 1; - - constructor(price) { - this.price = price; -@@ -38,9 +38,7 @@ - return this.price * this.amount; - } - -- @action handleDecrease = (event: React.ChangeEvent) => -- this.count--; -+ @action handleDecrease = (event: React.ChangeEvent) => this.count--; - -- @action handleSomething = (event: React.ChangeEvent) => -- doSomething(); -+ @action handleSomething = (event: React.ChangeEvent) => doSomething(); - } -``` - -# Output - -```js -import { observable } from "mobx"; - -@observer -class OrderLine { - @observable price:number = 0; - @observable amount:number = 1; - - constructor(price) { - this.price = price; - } - - @computed get total() { - return this.price * this.amount; - } - - @action.bound setPrice(price) { - this.price = price; - } - - @computed - get total() { - return this.price * this.amount; - } - - @action.bound - setPrice(price) { - this.price = price; - } - - @computed - @computed - @computed - @computed - @computed - @computed - @computed - get total() { - return this.price * this.amount; - } - - @action handleDecrease = (event: React.ChangeEvent) => this.count--; - - @action handleSomething = (event: React.ChangeEvent) => doSomething(); -} -``` - -# Errors -``` -mobx.js:4:20 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - - × return types can only be used in TypeScript files - - 3 │ @observer class OrderLine { - > 4 │ @observable price:number = 0; - │ ^^^^^^^ - 5 │ @observable amount:number = 1; - 6 │ - - i remove this type annotation - -mobx.js:5:21 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - - × return types can only be used in TypeScript files - - 3 │ @observer class OrderLine { - 4 │ @observable price:number = 0; - > 5 │ @observable amount:number = 1; - │ ^^^^^^^ - 6 │ - 7 │ constructor(price) { - - i remove this type annotation - -mobx.js:33:34 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - - × Type annotations are a TypeScript only feature. Convert your file to a TypeScript file or remove the syntax. - - 31 │ } - 32 │ - > 33 │ @action handleDecrease = (event: React.ChangeEvent) => this.count--; - │ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - 34 │ - 35 │ @action handleSomething = (event: React.ChangeEvent) => doSomething(); - - i TypeScript only syntax - -mobx.js:35:35 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - - × Type annotations are a TypeScript only feature. Convert your file to a TypeScript file or remove the syntax. - - 33 │ @action handleDecrease = (event: React.ChangeEvent) => this.count--; - 34 │ - > 35 │ @action handleSomething = (event: React.ChangeEvent) => doSomething(); - │ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - 36 │ } - 37 │ - - i TypeScript only syntax - - -``` - -# Lines exceeding max width of 80 characters -``` - 41: @action handleDecrease = (event: React.ChangeEvent) => this.count--; - 43: @action handleSomething = (event: React.ChangeEvent) => doSomething(); -``` - - diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/decorators/multiple.js b/crates/rome_js_formatter/tests/specs/prettier/js/decorators/multiple.js index f35b7018f59..0a83753c91c 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/js/decorators/multiple.js +++ b/crates/rome_js_formatter/tests/specs/prettier/js/decorators/multiple.js @@ -1,15 +1,16 @@ -const dog = { +const dog = class { @readonly @nonenumerable @doubledValue - legs: 4, + legs = 4; @readonly @nonenumerable @doubledValue - eyes: 2 + eyes() {return 2} }; -const foo = { - @multipleDecorators @inline @theyWontAllFitInOneline aVeryLongPropName: "A very long string as value" +const foo = class { + @multipleDecorators @inline @theyWontAllFitInOneline aVeryLongPropName = "A very long string as value" + @multipleDecorators @inline @theyWontAllFitInOneline aVeryLongPropName() { "A very long string as value"} }; diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/decorators/multiple.js.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/js/decorators/multiple.js.prettier-snap index 725b9490942..8bcc0e87b9b 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/js/decorators/multiple.js.prettier-snap +++ b/crates/rome_js_formatter/tests/specs/prettier/js/decorators/multiple.js.prettier-snap @@ -1,18 +1,21 @@ -const dog = { +const dog = class { @readonly @nonenumerable @doubledValue - legs: 4, + legs = 4; @readonly @nonenumerable @doubledValue - eyes: 2, + eyes() { + return 2; + } }; -const foo = { - @multipleDecorators - @inline - @theyWontAllFitInOneline - aVeryLongPropName: "A very long string as value", +const foo = class { + @multipleDecorators @inline @theyWontAllFitInOneline aVeryLongPropName = + "A very long string as value"; + @multipleDecorators @inline @theyWontAllFitInOneline aVeryLongPropName() { + "A very long string as value"; + } }; diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/decorators/multiple.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/decorators/multiple.js.snap deleted file mode 100644 index a04cfa7e43d..00000000000 --- a/crates/rome_js_formatter/tests/specs/prettier/js/decorators/multiple.js.snap +++ /dev/null @@ -1,194 +0,0 @@ ---- -source: crates/rome_formatter_test/src/snapshot_builder.rs -info: js/decorators/multiple.js ---- - -# Input - -```js -const dog = { - @readonly - @nonenumerable - @doubledValue - legs: 4, - - @readonly - @nonenumerable - @doubledValue - eyes: 2 -}; - -const foo = { - @multipleDecorators @inline @theyWontAllFitInOneline aVeryLongPropName: "A very long string as value" -}; - -``` - - -# Prettier differences - -```diff ---- Prettier -+++ Rome -@@ -1,18 +1,17 @@ - const dog = { -- @readonly -+@readonly - @nonenumerable - @doubledValue -- legs: 4, -+legs: 4, - - @readonly - @nonenumerable - @doubledValue -- eyes: 2, --}; -+ eyes -+: 2 -+} - - const foo = { -- @multipleDecorators -- @inline -- @theyWontAllFitInOneline -- aVeryLongPropName: "A very long string as value", --}; -+@multipleDecorators @inline @theyWontAllFitInOneline -+aVeryLongPropName: "A very long string as value"; -+} -``` - -# Output - -```js -const dog = { -@readonly - @nonenumerable - @doubledValue -legs: 4, - - @readonly - @nonenumerable - @doubledValue - eyes -: 2 -} - -const foo = { -@multipleDecorators @inline @theyWontAllFitInOneline -aVeryLongPropName: "A very long string as value"; -} -``` - -# Errors -``` -multiple.js:2:3 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - - × expected a property, a shorthand property, a getter, a setter, or a method but instead found '@' - - 1 │ const dog = { - > 2 │ @readonly - │ ^ - 3 │ @nonenumerable - 4 │ @doubledValue - - i Expected a property, a shorthand property, a getter, a setter, or a method here - - 1 │ const dog = { - > 2 │ @readonly - │ ^ - 3 │ @nonenumerable - 4 │ @doubledValue - -multiple.js:7:3 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - - × Decorators are not valid here. - - 5 │ legs: 4, - 6 │ - > 7 │ @readonly - │ ^^^^^^^^^ - > 8 │ @nonenumerable - > 9 │ @doubledValue - │ ^^^^^^^^^^^^^ - 10 │ eyes: 2 - 11 │ }; - - i Decorators are only valid on class declarations, class expressions, and class methods. - -multiple.js:10:7 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - - × Expected a semicolon or an implicit semicolon after a statement, but found none - - 8 │ @nonenumerable - 9 │ @doubledValue - > 10 │ eyes: 2 - │ ^ - 11 │ }; - 12 │ - - i An explicit or implicit semicolon is expected here... - - 8 │ @nonenumerable - 9 │ @doubledValue - > 10 │ eyes: 2 - │ ^ - 11 │ }; - 12 │ - - i ...Which is required to end this statement - - 3 │ @nonenumerable - 4 │ @doubledValue - > 5 │ legs: 4, - │ ^^ - > 6 │ - > 7 │ @readonly - > 8 │ @nonenumerable - > 9 │ @doubledValue - > 10 │ eyes: 2 - │ ^^^^^ - 11 │ }; - 12 │ - -multiple.js:14:3 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - - × expected a property, a shorthand property, a getter, a setter, or a method but instead found '@' - - 13 │ const foo = { - > 14 │ @multipleDecorators @inline @theyWontAllFitInOneline aVeryLongPropName: "A very long string as value" - │ ^ - 15 │ }; - 16 │ - - i Expected a property, a shorthand property, a getter, a setter, or a method here - - 13 │ const foo = { - > 14 │ @multipleDecorators @inline @theyWontAllFitInOneline aVeryLongPropName: "A very long string as value" - │ ^ - 15 │ }; - 16 │ - -multiple.js:15:1 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - - × expected a statement but instead found '}' - - 13 │ const foo = { - 14 │ @multipleDecorators @inline @theyWontAllFitInOneline aVeryLongPropName: "A very long string as value" - > 15 │ }; - │ ^ - 16 │ - - i Expected a statement here - - 13 │ const foo = { - 14 │ @multipleDecorators @inline @theyWontAllFitInOneline aVeryLongPropName: "A very long string as value" - > 15 │ }; - │ ^ - 16 │ - - -``` - - diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/do/do.js b/crates/rome_js_formatter/tests/specs/prettier/js/do/do.js index e2b49710802..8e368c09d9c 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/js/do/do.js +++ b/crates/rome_js_formatter/tests/specs/prettier/js/do/do.js @@ -52,3 +52,17 @@ function foo() { obj[key]; } }; + +() => ( ) => do { + var obj = { foo: "bar", bar: "foo" }; + for (var key in obj) { + obj[key]; + } +}; + +a =>b=> c => do { + var obj = { foo: "bar", bar: "foo" }; + for (var key in obj) { + obj[key]; + } +}; diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/do/do.js.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/js/do/do.js.prettier-snap index 01179b75859..43f6bcb0bd2 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/js/do/do.js.prettier-snap +++ b/crates/rome_js_formatter/tests/specs/prettier/js/do/do.js.prettier-snap @@ -55,3 +55,17 @@ function foo() { obj[key]; } }; + +() => () => do { + var obj = { foo: "bar", bar: "foo" }; + for (var key in obj) { + obj[key]; + } +}; + +(a) => (b) => (c) => do { + var obj = { foo: "bar", bar: "foo" }; + for (var key in obj) { + obj[key]; + } +}; diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/do/do.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/do/do.js.snap index 57e5fa7ada7..39d2d4ecac6 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/js/do/do.js.snap +++ b/crates/rome_js_formatter/tests/specs/prettier/js/do/do.js.snap @@ -1,6 +1,5 @@ --- source: crates/rome_formatter_test/src/snapshot_builder.rs -assertion_line: 212 info: js/do/do.js --- @@ -62,6 +61,20 @@ function foo() { } }; +() => ( ) => do { + var obj = { foo: "bar", bar: "foo" }; + for (var key in obj) { + obj[key]; + } +}; + +a =>b=> c => do { + var obj = { foo: "bar", bar: "foo" }; + for (var key in obj) { + obj[key]; + } +}; + ``` @@ -70,7 +83,7 @@ function foo() { ```diff --- Prettier +++ Rome -@@ -1,55 +1,61 @@ +@@ -1,69 +1,77 @@ const envSpecific = { - domain: do { - if (env === "production") "https://abc.mno.com/"; @@ -160,6 +173,24 @@ function foo() { -() => do { +() => ++do { + var obj = { foo: "bar", bar: "foo" }; + for (var key in obj) { + obj[key]; + } + }; + +-() => () => do { ++() => ( ) => ++do { + var obj = { foo: "bar", bar: "foo" }; + for (var key in obj) { + obj[key]; + } + }; + +-(a) => (b) => (c) => do { ++a =>b=> c => +do { var obj = { foo: "bar", bar: "foo" }; for (var key in obj) { @@ -232,6 +263,22 @@ do { obj[key]; } }; + +() => ( ) => +do { + var obj = { foo: "bar", bar: "foo" }; + for (var key in obj) { + obj[key]; + } +}; + +a =>b=> c => +do { + var obj = { foo: "bar", bar: "foo" }; + for (var key in obj) { + obj[key]; + } +}; ``` # Errors @@ -645,6 +692,72 @@ do.js:54:2 parse ━━━━━━━━━━━━━━━━━━━━━ > 54 │ }; │ ^ 55 │ + 56 │ () => ( ) => do { + + i Remove ; + +do.js:56:17 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × expected a function body, or an expression but instead found 'do' + + 54 │ }; + 55 │ + > 56 │ () => ( ) => do { + │ ^^ + 57 │ var obj = { foo: "bar", bar: "foo" }; + 58 │ for (var key in obj) { + + i Expected a function body, or an expression here + + 54 │ }; + 55 │ + > 56 │ () => ( ) => do { + │ ^^ + 57 │ var obj = { foo: "bar", bar: "foo" }; + 58 │ for (var key in obj) { + +do.js:61:2 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × expected `while` but instead found `;` + + 59 │ obj[key]; + 60 │ } + > 61 │ }; + │ ^ + 62 │ + 63 │ a =>b=> c => do { + + i Remove ; + +do.js:63:18 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × expected a function body, or an expression but instead found 'do' + + 61 │ }; + 62 │ + > 63 │ a =>b=> c => do { + │ ^^ + 64 │ var obj = { foo: "bar", bar: "foo" }; + 65 │ for (var key in obj) { + + i Expected a function body, or an expression here + + 61 │ }; + 62 │ + > 63 │ a =>b=> c => do { + │ ^^ + 64 │ var obj = { foo: "bar", bar: "foo" }; + 65 │ for (var key in obj) { + +do.js:68:2 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × expected `while` but instead found `;` + + 66 │ obj[key]; + 67 │ } + > 68 │ }; + │ ^ + 69 │ i Remove ; diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/for-await-using-of-comments.js b/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/for-await-using-of-comments.js new file mode 100644 index 00000000000..97230845f53 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/for-await-using-of-comments.js @@ -0,0 +1 @@ +/*1*/ for /* 2 */ await /*3*/ ( /*4*/ using /*5*/ fo /*6*/ of /*7*/ of /*8*/) /*9*/; diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/for-await-using-of-comments.js.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/for-await-using-of-comments.js.prettier-snap new file mode 100644 index 00000000000..1998906c61d --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/for-await-using-of-comments.js.prettier-snap @@ -0,0 +1 @@ +/*1*/ for await (/* 2 */ /*3*/ /*4*/ using /*5*/ fo /*6*/ of /*7*/ of /*8*/ /*9*/); diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/for-await-using-of-comments.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/for-await-using-of-comments.js.snap new file mode 100644 index 00000000000..8c921795939 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/for-await-using-of-comments.js.snap @@ -0,0 +1,121 @@ +--- +source: crates/rome_formatter_test/src/snapshot_builder.rs +info: js/explicit-resource-management/for-await-using-of-comments.js +--- + +# Input + +```js +/*1*/ for /* 2 */ await /*3*/ ( /*4*/ using /*5*/ fo /*6*/ of /*7*/ of /*8*/) /*9*/; + +``` + + +# Prettier differences + +```diff +--- Prettier ++++ Rome +@@ -1 +1,2 @@ +-/*1*/ for await (/* 2 */ /*3*/ /*4*/ using /*5*/ fo /*6*/ of /*7*/ of /*8*/ /*9*/); ++/*1*/ for /* 2 */ await /*3*/ ( /*4*/ using /*5*/ fo /*6*/ of /*7*/ of /*8*/ ++) /*9*/ +``` + +# Output + +```js +/*1*/ for /* 2 */ await /*3*/ ( /*4*/ using /*5*/ fo /*6*/ of /*7*/ of /*8*/ +) /*9*/ +``` + +# Errors +``` +for-await-using-of-comments.js:1:51 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × expected `;` but instead found `fo` + + > 1 │ /*1*/ for /* 2 */ await /*3*/ ( /*4*/ using /*5*/ fo /*6*/ of /*7*/ of /*8*/) /*9*/; + │ ^^ + 2 │ + + i Remove fo + +for-await-using-of-comments.js:1:60 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × expected `;` but instead found `of` + + > 1 │ /*1*/ for /* 2 */ await /*3*/ ( /*4*/ using /*5*/ fo /*6*/ of /*7*/ of /*8*/) /*9*/; + │ ^^ + 2 │ + + i Remove of + +for-await-using-of-comments.js:1:69 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × expected `)` but instead found `of` + + > 1 │ /*1*/ for /* 2 */ await /*3*/ ( /*4*/ using /*5*/ fo /*6*/ of /*7*/ of /*8*/) /*9*/; + │ ^^ + 2 │ + + i Remove of + +for-await-using-of-comments.js:1:77 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × Expected a semicolon or an implicit semicolon after a statement, but found none + + > 1 │ /*1*/ for /* 2 */ await /*3*/ ( /*4*/ using /*5*/ fo /*6*/ of /*7*/ of /*8*/) /*9*/; + │ ^ + 2 │ + + i An explicit or implicit semicolon is expected here... + + > 1 │ /*1*/ for /* 2 */ await /*3*/ ( /*4*/ using /*5*/ fo /*6*/ of /*7*/ of /*8*/) /*9*/; + │ ^ + 2 │ + + i ...Which is required to end this statement + + > 1 │ /*1*/ for /* 2 */ await /*3*/ ( /*4*/ using /*5*/ fo /*6*/ of /*7*/ of /*8*/) /*9*/; + │ ^^^^^^^^^ + 2 │ + +for-await-using-of-comments.js:1:19 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × await can only be used in conjunction with `for...of` statements + + > 1 │ /*1*/ for /* 2 */ await /*3*/ ( /*4*/ using /*5*/ fo /*6*/ of /*7*/ of /*8*/) /*9*/; + │ ^^^^^ + 2 │ + + i Remove the await here + + > 1 │ /*1*/ for /* 2 */ await /*3*/ ( /*4*/ using /*5*/ fo /*6*/ of /*7*/ of /*8*/) /*9*/; + │ ^^^^^ + 2 │ + + i or convert this to a `for...of` statement + + > 1 │ /*1*/ for /* 2 */ await /*3*/ ( /*4*/ using /*5*/ fo /*6*/ of /*7*/ of /*8*/) /*9*/; + │ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + 2 │ + +for-await-using-of-comments.js:1:77 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × expected a statement but instead found ')' + + > 1 │ /*1*/ for /* 2 */ await /*3*/ ( /*4*/ using /*5*/ fo /*6*/ of /*7*/ of /*8*/) /*9*/; + │ ^ + 2 │ + + i Expected a statement here + + > 1 │ /*1*/ for /* 2 */ await /*3*/ ( /*4*/ using /*5*/ fo /*6*/ of /*7*/ of /*8*/) /*9*/; + │ ^ + 2 │ + + +``` + + diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/invalid-duplicate-using-bindings.js b/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/invalid-duplicate-using-bindings.js new file mode 100644 index 00000000000..d04dedd0e6b --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/invalid-duplicate-using-bindings.js @@ -0,0 +1,7 @@ +{ + using f, f = foo(); +} +{ + using g = foo(); + using g = foo(); +} diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/invalid-duplicate-using-bindings.js.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/invalid-duplicate-using-bindings.js.prettier-snap new file mode 100644 index 00000000000..6bb2b76a508 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/invalid-duplicate-using-bindings.js.prettier-snap @@ -0,0 +1,8 @@ +{ + using f, + f = foo(); +} +{ + using g = foo(); + using g = foo(); +} diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/invalid-duplicate-using-bindings.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/invalid-duplicate-using-bindings.js.snap new file mode 100644 index 00000000000..5668a7e595d --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/invalid-duplicate-using-bindings.js.snap @@ -0,0 +1,146 @@ +--- +source: crates/rome_formatter_test/src/snapshot_builder.rs +info: js/explicit-resource-management/invalid-duplicate-using-bindings.js +--- + +# Input + +```js +{ + using f, f = foo(); +} +{ + using g = foo(); + using g = foo(); +} + +``` + + +# Prettier differences + +```diff +--- Prettier ++++ Rome +@@ -1,8 +1,10 @@ + { +- using f, +- f = foo(); ++ using; ++ f, (f = foo()); + } + { +- using g = foo(); +- using g = foo(); ++ using; ++ g = foo(); ++ using; ++ g = foo(); + } +``` + +# Output + +```js +{ + using; + f, (f = foo()); +} +{ + using; + g = foo(); + using; + g = foo(); +} +``` + +# Errors +``` +invalid-duplicate-using-bindings.js:2:9 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × Expected a semicolon or an implicit semicolon after a statement, but found none + + 1 │ { + > 2 │ using f, f = foo(); + │ ^ + 3 │ } + 4 │ { + + i An explicit or implicit semicolon is expected here... + + 1 │ { + > 2 │ using f, f = foo(); + │ ^ + 3 │ } + 4 │ { + + i ...Which is required to end this statement + + 1 │ { + > 2 │ using f, f = foo(); + │ ^^^^^^^ + 3 │ } + 4 │ { + +invalid-duplicate-using-bindings.js:5:9 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × Expected a semicolon or an implicit semicolon after a statement, but found none + + 3 │ } + 4 │ { + > 5 │ using g = foo(); + │ ^ + 6 │ using g = foo(); + 7 │ } + + i An explicit or implicit semicolon is expected here... + + 3 │ } + 4 │ { + > 5 │ using g = foo(); + │ ^ + 6 │ using g = foo(); + 7 │ } + + i ...Which is required to end this statement + + 3 │ } + 4 │ { + > 5 │ using g = foo(); + │ ^^^^^^^ + 6 │ using g = foo(); + 7 │ } + +invalid-duplicate-using-bindings.js:6:9 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × Expected a semicolon or an implicit semicolon after a statement, but found none + + 4 │ { + 5 │ using g = foo(); + > 6 │ using g = foo(); + │ ^ + 7 │ } + 8 │ + + i An explicit or implicit semicolon is expected here... + + 4 │ { + 5 │ using g = foo(); + > 6 │ using g = foo(); + │ ^ + 7 │ } + 8 │ + + i ...Which is required to end this statement + + 4 │ { + 5 │ using g = foo(); + > 6 │ using g = foo(); + │ ^^^^^^^ + 7 │ } + 8 │ + + +``` + + diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/invalid-script-top-level-using-binding.js b/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/invalid-script-top-level-using-binding.js new file mode 100644 index 00000000000..e33689ba708 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/invalid-script-top-level-using-binding.js @@ -0,0 +1 @@ +using x = bar(); diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/invalid-script-top-level-using-binding.js.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/invalid-script-top-level-using-binding.js.prettier-snap new file mode 100644 index 00000000000..e33689ba708 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/invalid-script-top-level-using-binding.js.prettier-snap @@ -0,0 +1 @@ +using x = bar(); diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/invalid-script-top-level-using-binding.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/invalid-script-top-level-using-binding.js.snap new file mode 100644 index 00000000000..96005128f56 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/invalid-script-top-level-using-binding.js.snap @@ -0,0 +1,57 @@ +--- +source: crates/rome_formatter_test/src/snapshot_builder.rs +info: js/explicit-resource-management/invalid-script-top-level-using-binding.js +--- + +# Input + +```js +using x = bar(); + +``` + + +# Prettier differences + +```diff +--- Prettier ++++ Rome +@@ -1 +1,2 @@ +-using x = bar(); ++using; ++x = bar(); +``` + +# Output + +```js +using; +x = bar(); +``` + +# Errors +``` +invalid-script-top-level-using-binding.js:1:7 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × Expected a semicolon or an implicit semicolon after a statement, but found none + + > 1 │ using x = bar(); + │ ^ + 2 │ + + i An explicit or implicit semicolon is expected here... + + > 1 │ using x = bar(); + │ ^ + 2 │ + + i ...Which is required to end this statement + + > 1 │ using x = bar(); + │ ^^^^^^^ + 2 │ + + +``` + + diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/using-declarations.js b/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/using-declarations.js new file mode 100644 index 00000000000..508806aee5c --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/using-declarations.js @@ -0,0 +1,7 @@ +{ + using /* 1 */ a = foo(), /* 2 */ b = foo() +} + +for(using /* 1 */ a = foo(), /* 2 */ b = foo();;); + +for(using /* 1 */ foo of bar()); diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/using-declarations.js.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/using-declarations.js.prettier-snap new file mode 100644 index 00000000000..3d611cf61a6 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/using-declarations.js.prettier-snap @@ -0,0 +1,8 @@ +{ + using /* 1 */ a = foo(), + /* 2 */ b = foo(); +} + +for (using /* 1 */ a = foo(), /* 2 */ b = foo(); ; ); + +for (using /* 1 */ foo of bar()); diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/using-declarations.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/using-declarations.js.snap new file mode 100644 index 00000000000..81b290fa376 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/using-declarations.js.snap @@ -0,0 +1,203 @@ +--- +source: crates/rome_formatter_test/src/snapshot_builder.rs +info: js/explicit-resource-management/using-declarations.js +--- + +# Input + +```js +{ + using /* 1 */ a = foo(), /* 2 */ b = foo() +} + +for(using /* 1 */ a = foo(), /* 2 */ b = foo();;); + +for(using /* 1 */ foo of bar()); + +``` + + +# Prettier differences + +```diff +--- Prettier ++++ Rome +@@ -1,8 +1,10 @@ + { +- using /* 1 */ a = foo(), +- /* 2 */ b = foo(); ++ using; /* 1 */ ++ (a = foo()), /* 2 */ (b = foo()); + } + +-for (using /* 1 */ a = foo(), /* 2 */ b = foo(); ; ); ++for(using /* 1 */ a = foo(), /* 2 */ b = foo();; ++) + +-for (using /* 1 */ foo of bar()); ++for(using /* 1 */ foo of bar() ++) +``` + +# Output + +```js +{ + using; /* 1 */ + (a = foo()), /* 2 */ (b = foo()); +} + +for(using /* 1 */ a = foo(), /* 2 */ b = foo();; +) + +for(using /* 1 */ foo of bar() +) +``` + +# Errors +``` +using-declarations.js:2:17 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × Expected a semicolon or an implicit semicolon after a statement, but found none + + 1 │ { + > 2 │ using /* 1 */ a = foo(), /* 2 */ b = foo() + │ ^ + 3 │ } + 4 │ + + i An explicit or implicit semicolon is expected here... + + 1 │ { + > 2 │ using /* 1 */ a = foo(), /* 2 */ b = foo() + │ ^ + 3 │ } + 4 │ + + i ...Which is required to end this statement + + 1 │ { + > 2 │ using /* 1 */ a = foo(), /* 2 */ b = foo() + │ ^^^^^^^^^^^^^^^ + 3 │ } + 4 │ + +using-declarations.js:5:19 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × expected `;` but instead found `a` + + 3 │ } + 4 │ + > 5 │ for(using /* 1 */ a = foo(), /* 2 */ b = foo();;); + │ ^ + 6 │ + 7 │ for(using /* 1 */ foo of bar()); + + i Remove a + +using-declarations.js:5:48 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × expected an expression but instead found ';' + + 3 │ } + 4 │ + > 5 │ for(using /* 1 */ a = foo(), /* 2 */ b = foo();;); + │ ^ + 6 │ + 7 │ for(using /* 1 */ foo of bar()); + + i Expected an expression here + + 3 │ } + 4 │ + > 5 │ for(using /* 1 */ a = foo(), /* 2 */ b = foo();;); + │ ^ + 6 │ + 7 │ for(using /* 1 */ foo of bar()); + +using-declarations.js:5:49 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × expected a statement but instead found ')' + + 3 │ } + 4 │ + > 5 │ for(using /* 1 */ a = foo(), /* 2 */ b = foo();;); + │ ^ + 6 │ + 7 │ for(using /* 1 */ foo of bar()); + + i Expected a statement here + + 3 │ } + 4 │ + > 5 │ for(using /* 1 */ a = foo(), /* 2 */ b = foo();;); + │ ^ + 6 │ + 7 │ for(using /* 1 */ foo of bar()); + +using-declarations.js:7:19 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × expected `;` but instead found `foo` + + 5 │ for(using /* 1 */ a = foo(), /* 2 */ b = foo();;); + 6 │ + > 7 │ for(using /* 1 */ foo of bar()); + │ ^^^ + 8 │ + + i Remove foo + +using-declarations.js:7:23 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × expected `;` but instead found `of` + + 5 │ for(using /* 1 */ a = foo(), /* 2 */ b = foo();;); + 6 │ + > 7 │ for(using /* 1 */ foo of bar()); + │ ^^ + 8 │ + + i Remove of + +using-declarations.js:7:26 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × expected `)` but instead found `bar` + + 5 │ for(using /* 1 */ a = foo(), /* 2 */ b = foo();;); + 6 │ + > 7 │ for(using /* 1 */ foo of bar()); + │ ^^^ + 8 │ + + i Remove bar + +using-declarations.js:7:31 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × Expected a semicolon or an implicit semicolon after a statement, but found none + + 5 │ for(using /* 1 */ a = foo(), /* 2 */ b = foo();;); + 6 │ + > 7 │ for(using /* 1 */ foo of bar()); + │ ^ + 8 │ + + i An explicit or implicit semicolon is expected here... + + 5 │ for(using /* 1 */ a = foo(), /* 2 */ b = foo();;); + 6 │ + > 7 │ for(using /* 1 */ foo of bar()); + │ ^ + 8 │ + + i ...Which is required to end this statement + + 5 │ for(using /* 1 */ a = foo(), /* 2 */ b = foo();;); + 6 │ + > 7 │ for(using /* 1 */ foo of bar()); + │ ^^^^^^ + 8 │ + + +``` + + diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-await-expr-using-in.js b/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-await-expr-using-in.js new file mode 100644 index 00000000000..7dcf9e0239b --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-await-expr-using-in.js @@ -0,0 +1,3 @@ +async function f() { + await using in foo; +} diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-await-expr-using-in.js.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-await-expr-using-in.js.prettier-snap new file mode 100644 index 00000000000..79b06693268 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-await-expr-using-in.js.prettier-snap @@ -0,0 +1,3 @@ +async function f() { + (await using) in foo; +} diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-await-expr-using-instanceof.js b/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-await-expr-using-instanceof.js new file mode 100644 index 00000000000..1818647e476 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-await-expr-using-instanceof.js @@ -0,0 +1,3 @@ +async function f() { + await using instanceof foo; +} diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-await-expr-using-instanceof.js.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-await-expr-using-instanceof.js.prettier-snap new file mode 100644 index 00000000000..10939279c0f --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-await-expr-using-instanceof.js.prettier-snap @@ -0,0 +1,3 @@ +async function f() { + (await using) instanceof foo; +} diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-await-expr-using.js b/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-await-expr-using.js new file mode 100644 index 00000000000..f056de21db0 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-await-expr-using.js @@ -0,0 +1,4 @@ +async function f() { + await using[x]; + await using.x + await using(x) ? await using?.x : await using`x`; +} diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-await-expr-using.js.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-await-expr-using.js.prettier-snap new file mode 100644 index 00000000000..c641386fc21 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-await-expr-using.js.prettier-snap @@ -0,0 +1,4 @@ +async function f() { + await using[x]; + (await using.x) + (await using(x)) ? await using?.x : await using`x`; +} diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-await-using-asi-assignment.js b/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-await-using-asi-assignment.js new file mode 100644 index 00000000000..2dde3680d92 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-await-using-asi-assignment.js @@ -0,0 +1,4 @@ +async function f() { + await using + using = h(); +} diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-await-using-asi-assignment.js.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-await-using-asi-assignment.js.prettier-snap new file mode 100644 index 00000000000..81f8300f438 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-await-using-asi-assignment.js.prettier-snap @@ -0,0 +1,4 @@ +async function f() { + await using; + using = h(); +} diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-await-using-binding-basic.js b/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-await-using-binding-basic.js new file mode 100644 index 00000000000..321993e916c --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-await-using-binding-basic.js @@ -0,0 +1,3 @@ +async function f() { + await using basic = getReader(); +} diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-await-using-binding-basic.js.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-await-using-binding-basic.js.prettier-snap new file mode 100644 index 00000000000..321993e916c --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-await-using-binding-basic.js.prettier-snap @@ -0,0 +1,3 @@ +async function f() { + await using basic = getReader(); +} diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-await-using-binding-basic.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-await-using-binding-basic.js.snap new file mode 100644 index 00000000000..7caaf4d7beb --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-await-using-binding-basic.js.snap @@ -0,0 +1,69 @@ +--- +source: crates/rome_formatter_test/src/snapshot_builder.rs +info: js/explicit-resource-management/valid-await-using-binding-basic.js +--- + +# Input + +```js +async function f() { + await using basic = getReader(); +} + +``` + + +# Prettier differences + +```diff +--- Prettier ++++ Rome +@@ -1,3 +1,4 @@ + async function f() { +- await using basic = getReader(); ++ await using; ++ basic = getReader(); + } +``` + +# Output + +```js +async function f() { + await using; + basic = getReader(); +} +``` + +# Errors +``` +valid-await-using-binding-basic.js:2:15 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × Expected a semicolon or an implicit semicolon after a statement, but found none + + 1 │ async function f() { + > 2 │ await using basic = getReader(); + │ ^^^^^ + 3 │ } + 4 │ + + i An explicit or implicit semicolon is expected here... + + 1 │ async function f() { + > 2 │ await using basic = getReader(); + │ ^^^^^ + 3 │ } + 4 │ + + i ...Which is required to end this statement + + 1 │ async function f() { + > 2 │ await using basic = getReader(); + │ ^^^^^^^^^^^^^^^^^ + 3 │ } + 4 │ + + +``` + + diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-await-using-binding-escaped.js b/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-await-using-binding-escaped.js new file mode 100644 index 00000000000..76af5903fa7 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-await-using-binding-escaped.js @@ -0,0 +1,3 @@ +async function f() { + await using \u0061b = c; +} diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-await-using-binding-escaped.js.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-await-using-binding-escaped.js.prettier-snap new file mode 100644 index 00000000000..18af5d75ab9 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-await-using-binding-escaped.js.prettier-snap @@ -0,0 +1,3 @@ +async function f() { + await using ab = c; +} diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-await-using-binding-escaped.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-await-using-binding-escaped.js.snap new file mode 100644 index 00000000000..67d016a39b8 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-await-using-binding-escaped.js.snap @@ -0,0 +1,69 @@ +--- +source: crates/rome_formatter_test/src/snapshot_builder.rs +info: js/explicit-resource-management/valid-await-using-binding-escaped.js +--- + +# Input + +```js +async function f() { + await using \u0061b = c; +} + +``` + + +# Prettier differences + +```diff +--- Prettier ++++ Rome +@@ -1,3 +1,4 @@ + async function f() { +- await using ab = c; ++ await using; ++ \u0061b = c; + } +``` + +# Output + +```js +async function f() { + await using; + \u0061b = c; +} +``` + +# Errors +``` +valid-await-using-binding-escaped.js:2:15 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × Expected a semicolon or an implicit semicolon after a statement, but found none + + 1 │ async function f() { + > 2 │ await using \u0061b = c; + │ ^^^^^^^ + 3 │ } + 4 │ + + i An explicit or implicit semicolon is expected here... + + 1 │ async function f() { + > 2 │ await using \u0061b = c; + │ ^^^^^^^ + 3 │ } + 4 │ + + i ...Which is required to end this statement + + 1 │ async function f() { + > 2 │ await using \u0061b = c; + │ ^^^^^^^^^^^^^^^^^^^ + 3 │ } + 4 │ + + +``` + + diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-await-using-binding-non-bmp.js b/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-await-using-binding-non-bmp.js new file mode 100644 index 00000000000..cbf4ce25199 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-await-using-binding-non-bmp.js @@ -0,0 +1,3 @@ +async function f() { + await using 𠮷 = foo(); +} diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-await-using-binding-non-bmp.js.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-await-using-binding-non-bmp.js.prettier-snap new file mode 100644 index 00000000000..cbf4ce25199 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-await-using-binding-non-bmp.js.prettier-snap @@ -0,0 +1,3 @@ +async function f() { + await using 𠮷 = foo(); +} diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-await-using-binding-non-bmp.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-await-using-binding-non-bmp.js.snap new file mode 100644 index 00000000000..7b3be0333ea --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-await-using-binding-non-bmp.js.snap @@ -0,0 +1,69 @@ +--- +source: crates/rome_formatter_test/src/snapshot_builder.rs +info: js/explicit-resource-management/valid-await-using-binding-non-bmp.js +--- + +# Input + +```js +async function f() { + await using 𠮷 = foo(); +} + +``` + + +# Prettier differences + +```diff +--- Prettier ++++ Rome +@@ -1,3 +1,4 @@ + async function f() { +- await using 𠮷 = foo(); ++ await using; ++ 𠮷 = foo(); + } +``` + +# Output + +```js +async function f() { + await using; + 𠮷 = foo(); +} +``` + +# Errors +``` +valid-await-using-binding-non-bmp.js:2:15 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × Expected a semicolon or an implicit semicolon after a statement, but found none + + 1 │ async function f() { + > 2 │ await using 𠮷 = foo(); + │ ^^ + 3 │ } + 4 │ + + i An explicit or implicit semicolon is expected here... + + 1 │ async function f() { + > 2 │ await using 𠮷 = foo(); + │ ^^ + 3 │ } + 4 │ + + i ...Which is required to end this statement + + 1 │ async function f() { + > 2 │ await using 𠮷 = foo(); + │ ^^^^^^^^^^^^^^ + 3 │ } + 4 │ + + +``` + + diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-await-using-binding-using.js b/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-await-using-binding-using.js new file mode 100644 index 00000000000..fd4e32547db --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-await-using-binding-using.js @@ -0,0 +1,4 @@ +async function f() { + await using using = of; + for (await using using of of); +} diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-await-using-binding-using.js.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-await-using-binding-using.js.prettier-snap new file mode 100644 index 00000000000..fd4e32547db --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-await-using-binding-using.js.prettier-snap @@ -0,0 +1,4 @@ +async function f() { + await using using = of; + for (await using using of of); +} diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-await-using-binding-using.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-await-using-binding-using.js.snap new file mode 100644 index 00000000000..effec5fc5b1 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-await-using-binding-using.js.snap @@ -0,0 +1,143 @@ +--- +source: crates/rome_formatter_test/src/snapshot_builder.rs +info: js/explicit-resource-management/valid-await-using-binding-using.js +--- + +# Input + +```js +async function f() { + await using using = of; + for (await using using of of); +} + +``` + + +# Prettier differences + +```diff +--- Prettier ++++ Rome +@@ -1,4 +1,6 @@ + async function f() { +- await using using = of; +- for (await using using of of); ++ await using; ++ using = of; ++ for (await using using of of ++ ) + } +``` + +# Output + +```js +async function f() { + await using; + using = of; + for (await using using of of + ) +} +``` + +# Errors +``` +valid-await-using-binding-using.js:2:15 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × Expected a semicolon or an implicit semicolon after a statement, but found none + + 1 │ async function f() { + > 2 │ await using using = of; + │ ^^^^^ + 3 │ for (await using using of of); + 4 │ } + + i An explicit or implicit semicolon is expected here... + + 1 │ async function f() { + > 2 │ await using using = of; + │ ^^^^^ + 3 │ for (await using using of of); + 4 │ } + + i ...Which is required to end this statement + + 1 │ async function f() { + > 2 │ await using using = of; + │ ^^^^^^^^^^^^^^^^^ + 3 │ for (await using using of of); + 4 │ } + +valid-await-using-binding-using.js:3:20 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × expected `;` but instead found `using` + + 1 │ async function f() { + 2 │ await using using = of; + > 3 │ for (await using using of of); + │ ^^^^^ + 4 │ } + 5 │ + + i Remove using + +valid-await-using-binding-using.js:3:26 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × expected `;` but instead found `of` + + 1 │ async function f() { + 2 │ await using using = of; + > 3 │ for (await using using of of); + │ ^^ + 4 │ } + 5 │ + + i Remove of + +valid-await-using-binding-using.js:3:29 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × expected `)` but instead found `of` + + 1 │ async function f() { + 2 │ await using using = of; + > 3 │ for (await using using of of); + │ ^^ + 4 │ } + 5 │ + + i Remove of + +valid-await-using-binding-using.js:3:31 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × Expected a semicolon or an implicit semicolon after a statement, but found none + + 1 │ async function f() { + 2 │ await using using = of; + > 3 │ for (await using using of of); + │ ^ + 4 │ } + 5 │ + + i An explicit or implicit semicolon is expected here... + + 1 │ async function f() { + 2 │ await using using = of; + > 3 │ for (await using using of of); + │ ^ + 4 │ } + 5 │ + + i ...Which is required to end this statement + + 1 │ async function f() { + 2 │ await using using = of; + > 3 │ for (await using using of of); + │ ^^^ + 4 │ } + 5 │ + + +``` + + diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-await-using-comments.js b/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-await-using-comments.js new file mode 100644 index 00000000000..3ce48f45b7b --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-await-using-comments.js @@ -0,0 +1,14 @@ +async function f() { +{ + /*0*/await/*1*/using/*2*/b/*3*/=/*4*/f()/*5*/; +} +{ + /*0*/for/*1*/(/*2*/await/*3*/using/*4*/b/*5*/=/*6*/x/*7*/;/*8*/;/*9*/)/*10*/; +} +{ + /*0*/for/*1*/(/*2*/await/*3*/using/*4*/b/*5*/of/*6*/x/*7*/)/*8*/; +} +{ + /*0*/for/*1*/await/*2*/(/*3*/await/*4*/using/*5*/b/*6*/of/*7*/x/*8*/)/*9*/; +} +} diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-await-using-comments.js.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-await-using-comments.js.prettier-snap new file mode 100644 index 00000000000..c3447f172a9 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-await-using-comments.js.prettier-snap @@ -0,0 +1,19 @@ +async function f() { + { + /*0*/ await using /*1*/ /*2*/ b /*3*/ = /*4*/ f(); /*5*/ + } + { + /*0*/ for ( + /*1*/ /*2*/ await using /*3*/ /*4*/ b /*5*/ = + /*6*/ x /*7*/ /*8*/ /*9*/ /*10*/; + ; + + ); + } + { + /*0*/ for (/*1*/ /*2*/ await using /*3*/ /*4*/ b /*5*/ of /*6*/ x /*7*/ /*8*/); + } + { + /*0*/ for await (/*1*/ /*2*/ /*3*/ await using /*4*/ /*5*/ b /*6*/ of /*7*/ x /*8*/ /*9*/); + } +} diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-await-using-comments.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-await-using-comments.js.snap new file mode 100644 index 00000000000..361e5f66c1a --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-await-using-comments.js.snap @@ -0,0 +1,357 @@ +--- +source: crates/rome_formatter_test/src/snapshot_builder.rs +info: js/explicit-resource-management/valid-await-using-comments.js +--- + +# Input + +```js +async function f() { +{ + /*0*/await/*1*/using/*2*/b/*3*/=/*4*/f()/*5*/; +} +{ + /*0*/for/*1*/(/*2*/await/*3*/using/*4*/b/*5*/=/*6*/x/*7*/;/*8*/;/*9*/)/*10*/; +} +{ + /*0*/for/*1*/(/*2*/await/*3*/using/*4*/b/*5*/of/*6*/x/*7*/)/*8*/; +} +{ + /*0*/for/*1*/await/*2*/(/*3*/await/*4*/using/*5*/b/*6*/of/*7*/x/*8*/)/*9*/; +} +} + +``` + + +# Prettier differences + +```diff +--- Prettier ++++ Rome +@@ -1,19 +1,18 @@ + async function f() { + { +- /*0*/ await using /*1*/ /*2*/ b /*3*/ = /*4*/ f(); /*5*/ ++ /*0*/ await /*1*/ using; /*2*/ ++ b /*3*/ = /*4*/ f() /*5*/; + } + { +- /*0*/ for ( +- /*1*/ /*2*/ await using /*3*/ /*4*/ b /*5*/ = +- /*6*/ x /*7*/ /*8*/ /*9*/ /*10*/; +- ; +- +- ); ++ /*0*/ for/*1*/(/*2*/await/*3*/using/*4*/b/*5*/=/*6*/x/*7*/;/*8*/; /*9*/ ++ ) /*10*/ + } + { +- /*0*/ for (/*1*/ /*2*/ await using /*3*/ /*4*/ b /*5*/ of /*6*/ x /*7*/ /*8*/); ++ /*0*/ for/*1*/(/*2*/await/*3*/using/*4*/b/*5*/of/*6*/x /*7*/ ++ ) /*8*/ + } + { +- /*0*/ for await (/*1*/ /*2*/ /*3*/ await using /*4*/ /*5*/ b /*6*/ of /*7*/ x /*8*/ /*9*/); ++ /*0*/ for/*1*/await/*2*/(/*3*/await/*4*/using/*5*/b/*6*/of/*7*/x /*8*/ ++ ) /*9*/ + } + } +``` + +# Output + +```js +async function f() { + { + /*0*/ await /*1*/ using; /*2*/ + b /*3*/ = /*4*/ f() /*5*/; + } + { + /*0*/ for/*1*/(/*2*/await/*3*/using/*4*/b/*5*/=/*6*/x/*7*/;/*8*/; /*9*/ + ) /*10*/ + } + { + /*0*/ for/*1*/(/*2*/await/*3*/using/*4*/b/*5*/of/*6*/x /*7*/ + ) /*8*/ + } + { + /*0*/ for/*1*/await/*2*/(/*3*/await/*4*/using/*5*/b/*6*/of/*7*/x /*8*/ + ) /*9*/ + } +} +``` + +# Errors +``` +valid-await-using-comments.js:3:28 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × Expected a semicolon or an implicit semicolon after a statement, but found none + + 1 │ async function f() { + 2 │ { + > 3 │ /*0*/await/*1*/using/*2*/b/*3*/=/*4*/f()/*5*/; + │ ^ + 4 │ } + 5 │ { + + i An explicit or implicit semicolon is expected here... + + 1 │ async function f() { + 2 │ { + > 3 │ /*0*/await/*1*/using/*2*/b/*3*/=/*4*/f()/*5*/; + │ ^ + 4 │ } + 5 │ { + + i ...Which is required to end this statement + + 1 │ async function f() { + 2 │ { + > 3 │ /*0*/await/*1*/using/*2*/b/*3*/=/*4*/f()/*5*/; + │ ^^^^^^^^^^^^^^^^^^^^^ + 4 │ } + 5 │ { + +valid-await-using-comments.js:6:42 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × expected `;` but instead found `b` + + 4 │ } + 5 │ { + > 6 │ /*0*/for/*1*/(/*2*/await/*3*/using/*4*/b/*5*/=/*6*/x/*7*/;/*8*/;/*9*/)/*10*/; + │ ^ + 7 │ } + 8 │ { + + i Remove b + +valid-await-using-comments.js:6:66 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × expected an expression but instead found ';' + + 4 │ } + 5 │ { + > 6 │ /*0*/for/*1*/(/*2*/await/*3*/using/*4*/b/*5*/=/*6*/x/*7*/;/*8*/;/*9*/)/*10*/; + │ ^ + 7 │ } + 8 │ { + + i Expected an expression here + + 4 │ } + 5 │ { + > 6 │ /*0*/for/*1*/(/*2*/await/*3*/using/*4*/b/*5*/=/*6*/x/*7*/;/*8*/;/*9*/)/*10*/; + │ ^ + 7 │ } + 8 │ { + +valid-await-using-comments.js:6:72 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × expected a statement but instead found ')' + + 4 │ } + 5 │ { + > 6 │ /*0*/for/*1*/(/*2*/await/*3*/using/*4*/b/*5*/=/*6*/x/*7*/;/*8*/;/*9*/)/*10*/; + │ ^ + 7 │ } + 8 │ { + + i Expected a statement here + + 4 │ } + 5 │ { + > 6 │ /*0*/for/*1*/(/*2*/await/*3*/using/*4*/b/*5*/=/*6*/x/*7*/;/*8*/;/*9*/)/*10*/; + │ ^ + 7 │ } + 8 │ { + +valid-await-using-comments.js:9:42 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × expected `;` but instead found `b` + + 7 │ } + 8 │ { + > 9 │ /*0*/for/*1*/(/*2*/await/*3*/using/*4*/b/*5*/of/*6*/x/*7*/)/*8*/; + │ ^ + 10 │ } + 11 │ { + + i Remove b + +valid-await-using-comments.js:9:48 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × expected `;` but instead found `of` + + 7 │ } + 8 │ { + > 9 │ /*0*/for/*1*/(/*2*/await/*3*/using/*4*/b/*5*/of/*6*/x/*7*/)/*8*/; + │ ^^ + 10 │ } + 11 │ { + + i Remove of + +valid-await-using-comments.js:9:55 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × expected `)` but instead found `x` + + 7 │ } + 8 │ { + > 9 │ /*0*/for/*1*/(/*2*/await/*3*/using/*4*/b/*5*/of/*6*/x/*7*/)/*8*/; + │ ^ + 10 │ } + 11 │ { + + i Remove x + +valid-await-using-comments.js:9:61 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × Expected a semicolon or an implicit semicolon after a statement, but found none + + 7 │ } + 8 │ { + > 9 │ /*0*/for/*1*/(/*2*/await/*3*/using/*4*/b/*5*/of/*6*/x/*7*/)/*8*/; + │ ^ + 10 │ } + 11 │ { + + i An explicit or implicit semicolon is expected here... + + 7 │ } + 8 │ { + > 9 │ /*0*/for/*1*/(/*2*/await/*3*/using/*4*/b/*5*/of/*6*/x/*7*/)/*8*/; + │ ^ + 10 │ } + 11 │ { + + i ...Which is required to end this statement + + 7 │ } + 8 │ { + > 9 │ /*0*/for/*1*/(/*2*/await/*3*/using/*4*/b/*5*/of/*6*/x/*7*/)/*8*/; + │ ^^^^^^^ + 10 │ } + 11 │ { + +valid-await-using-comments.js:12:52 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × expected `;` but instead found `b` + + 10 │ } + 11 │ { + > 12 │ /*0*/for/*1*/await/*2*/(/*3*/await/*4*/using/*5*/b/*6*/of/*7*/x/*8*/)/*9*/; + │ ^ + 13 │ } + 14 │ } + + i Remove b + +valid-await-using-comments.js:12:58 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × expected `;` but instead found `of` + + 10 │ } + 11 │ { + > 12 │ /*0*/for/*1*/await/*2*/(/*3*/await/*4*/using/*5*/b/*6*/of/*7*/x/*8*/)/*9*/; + │ ^^ + 13 │ } + 14 │ } + + i Remove of + +valid-await-using-comments.js:12:65 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × expected `)` but instead found `x` + + 10 │ } + 11 │ { + > 12 │ /*0*/for/*1*/await/*2*/(/*3*/await/*4*/using/*5*/b/*6*/of/*7*/x/*8*/)/*9*/; + │ ^ + 13 │ } + 14 │ } + + i Remove x + +valid-await-using-comments.js:12:71 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × Expected a semicolon or an implicit semicolon after a statement, but found none + + 10 │ } + 11 │ { + > 12 │ /*0*/for/*1*/await/*2*/(/*3*/await/*4*/using/*5*/b/*6*/of/*7*/x/*8*/)/*9*/; + │ ^ + 13 │ } + 14 │ } + + i An explicit or implicit semicolon is expected here... + + 10 │ } + 11 │ { + > 12 │ /*0*/for/*1*/await/*2*/(/*3*/await/*4*/using/*5*/b/*6*/of/*7*/x/*8*/)/*9*/; + │ ^ + 13 │ } + 14 │ } + + i ...Which is required to end this statement + + 10 │ } + 11 │ { + > 12 │ /*0*/for/*1*/await/*2*/(/*3*/await/*4*/using/*5*/b/*6*/of/*7*/x/*8*/)/*9*/; + │ ^^^^^^^ + 13 │ } + 14 │ } + +valid-await-using-comments.js:12:16 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × await can only be used in conjunction with `for...of` statements + + 10 │ } + 11 │ { + > 12 │ /*0*/for/*1*/await/*2*/(/*3*/await/*4*/using/*5*/b/*6*/of/*7*/x/*8*/)/*9*/; + │ ^^^^^ + 13 │ } + 14 │ } + + i Remove the await here + + 10 │ } + 11 │ { + > 12 │ /*0*/for/*1*/await/*2*/(/*3*/await/*4*/using/*5*/b/*6*/of/*7*/x/*8*/)/*9*/; + │ ^^^^^ + 13 │ } + 14 │ } + + i or convert this to a `for...of` statement + + 10 │ } + 11 │ { + > 12 │ /*0*/for/*1*/await/*2*/(/*3*/await/*4*/using/*5*/b/*6*/of/*7*/x/*8*/)/*9*/; + │ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + 13 │ } + 14 │ } + +valid-await-using-comments.js:12:71 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × expected a statement but instead found ')' + + 10 │ } + 11 │ { + > 12 │ /*0*/for/*1*/await/*2*/(/*3*/await/*4*/using/*5*/b/*6*/of/*7*/x/*8*/)/*9*/; + │ ^ + 13 │ } + 14 │ } + + i Expected a statement here + + 10 │ } + 11 │ { + > 12 │ /*0*/for/*1*/await/*2*/(/*3*/await/*4*/using/*5*/b/*6*/of/*7*/x/*8*/)/*9*/; + │ ^ + 13 │ } + 14 │ } + + +``` + + diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-for-await-using-binding-escaped-of-of.js b/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-for-await-using-binding-escaped-of-of.js new file mode 100644 index 00000000000..a44a6abe349 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-for-await-using-binding-escaped-of-of.js @@ -0,0 +1,2 @@ +// TODO: Fix this test +// for await (using \u006ff of of); diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-for-await-using-binding-escaped-of-of.js.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-for-await-using-binding-escaped-of-of.js.prettier-snap new file mode 100644 index 00000000000..a44a6abe349 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-for-await-using-binding-escaped-of-of.js.prettier-snap @@ -0,0 +1,2 @@ +// TODO: Fix this test +// for await (using \u006ff of of); diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-for-using-binding-escaped-of-of.js b/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-for-using-binding-escaped-of-of.js new file mode 100644 index 00000000000..c4c021078a6 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-for-using-binding-escaped-of-of.js @@ -0,0 +1,2 @@ +// TODO: Fix this test +// for (using o\u0066 of of); diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-for-using-binding-escaped-of-of.js.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-for-using-binding-escaped-of-of.js.prettier-snap new file mode 100644 index 00000000000..c4c021078a6 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-for-using-binding-escaped-of-of.js.prettier-snap @@ -0,0 +1,2 @@ +// TODO: Fix this test +// for (using o\u0066 of of); diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-for-using-binding-of-of.js b/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-for-using-binding-of-of.js new file mode 100644 index 00000000000..4efb8f85a6f --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-for-using-binding-of-of.js @@ -0,0 +1,4 @@ +async function f() { + for (await using of of of); + for await (await using of of of); +} diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-for-using-binding-of-of.js.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-for-using-binding-of-of.js.prettier-snap new file mode 100644 index 00000000000..4efb8f85a6f --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-for-using-binding-of-of.js.prettier-snap @@ -0,0 +1,4 @@ +async function f() { + for (await using of of of); + for await (await using of of of); +} diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-for-using-binding-of-of.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-for-using-binding-of-of.js.snap new file mode 100644 index 00000000000..7485692e758 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-for-using-binding-of-of.js.snap @@ -0,0 +1,154 @@ +--- +source: crates/rome_formatter_test/src/snapshot_builder.rs +info: js/explicit-resource-management/valid-for-using-binding-of-of.js +--- + +# Input + +```js +async function f() { + for (await using of of of); + for await (await using of of of); +} + +``` + + +# Prettier differences + +```diff +--- Prettier ++++ Rome +@@ -1,4 +1,6 @@ + async function f() { +- for (await using of of of); +- for await (await using of of of); ++ for (await using of of of ++ ) ++ for await (await using of of of ++ ) + } +``` + +# Output + +```js +async function f() { + for (await using of of of + ) + for await (await using of of of + ) +} +``` + +# Errors +``` +valid-for-using-binding-of-of.js:2:8 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × Invalid assignment to `await using` + + 1 │ async function f() { + > 2 │ for (await using of of of); + │ ^^^^^^^^^^^ + 3 │ for await (await using of of of); + 4 │ } + + i This expression cannot be assigned to + +valid-for-using-binding-of-of.js:2:26 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × expected `)` but instead found `of` + + 1 │ async function f() { + > 2 │ for (await using of of of); + │ ^^ + 3 │ for await (await using of of of); + 4 │ } + + i Remove of + +valid-for-using-binding-of-of.js:2:28 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × Expected a semicolon or an implicit semicolon after a statement, but found none + + 1 │ async function f() { + > 2 │ for (await using of of of); + │ ^ + 3 │ for await (await using of of of); + 4 │ } + + i An explicit or implicit semicolon is expected here... + + 1 │ async function f() { + > 2 │ for (await using of of of); + │ ^ + 3 │ for await (await using of of of); + 4 │ } + + i ...Which is required to end this statement + + 1 │ async function f() { + > 2 │ for (await using of of of); + │ ^^^ + 3 │ for await (await using of of of); + 4 │ } + +valid-for-using-binding-of-of.js:3:14 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × Invalid assignment to `await using` + + 1 │ async function f() { + 2 │ for (await using of of of); + > 3 │ for await (await using of of of); + │ ^^^^^^^^^^^ + 4 │ } + 5 │ + + i This expression cannot be assigned to + +valid-for-using-binding-of-of.js:3:32 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × expected `)` but instead found `of` + + 1 │ async function f() { + 2 │ for (await using of of of); + > 3 │ for await (await using of of of); + │ ^^ + 4 │ } + 5 │ + + i Remove of + +valid-for-using-binding-of-of.js:3:34 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × Expected a semicolon or an implicit semicolon after a statement, but found none + + 1 │ async function f() { + 2 │ for (await using of of of); + > 3 │ for await (await using of of of); + │ ^ + 4 │ } + 5 │ + + i An explicit or implicit semicolon is expected here... + + 1 │ async function f() { + 2 │ for (await using of of of); + > 3 │ for await (await using of of of); + │ ^ + 4 │ } + 5 │ + + i ...Which is required to end this statement + + 1 │ async function f() { + 2 │ for (await using of of of); + > 3 │ for await (await using of of of); + │ ^^^ + 4 │ } + 5 │ + + +``` + + diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-for-using-declaration.js b/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-for-using-declaration.js new file mode 100644 index 00000000000..a13b51758dc --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-for-using-declaration.js @@ -0,0 +1,3 @@ +async function f() { + for (await using basic = reader();;); +} diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-for-using-declaration.js.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-for-using-declaration.js.prettier-snap new file mode 100644 index 00000000000..a0849041d56 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-for-using-declaration.js.prettier-snap @@ -0,0 +1,3 @@ +async function f() { + for (await using basic = reader(); ; ); +} diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-for-using-declaration.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-for-using-declaration.js.snap new file mode 100644 index 00000000000..c6177852b57 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-for-using-declaration.js.snap @@ -0,0 +1,91 @@ +--- +source: crates/rome_formatter_test/src/snapshot_builder.rs +info: js/explicit-resource-management/valid-for-using-declaration.js +--- + +# Input + +```js +async function f() { + for (await using basic = reader();;); +} + +``` + + +# Prettier differences + +```diff +--- Prettier ++++ Rome +@@ -1,3 +1,4 @@ + async function f() { +- for (await using basic = reader(); ; ); ++ for (await using basic = reader();; ++ ) + } +``` + +# Output + +```js +async function f() { + for (await using basic = reader();; + ) +} +``` + +# Errors +``` +valid-for-using-declaration.js:2:20 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × expected `;` but instead found `basic` + + 1 │ async function f() { + > 2 │ for (await using basic = reader();;); + │ ^^^^^ + 3 │ } + 4 │ + + i Remove basic + +valid-for-using-declaration.js:2:37 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × expected an expression but instead found ';' + + 1 │ async function f() { + > 2 │ for (await using basic = reader();;); + │ ^ + 3 │ } + 4 │ + + i Expected an expression here + + 1 │ async function f() { + > 2 │ for (await using basic = reader();;); + │ ^ + 3 │ } + 4 │ + +valid-for-using-declaration.js:2:38 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × expected a statement but instead found ')' + + 1 │ async function f() { + > 2 │ for (await using basic = reader();;); + │ ^ + 3 │ } + 4 │ + + i Expected a statement here + + 1 │ async function f() { + > 2 │ for (await using basic = reader();;); + │ ^ + 3 │ } + 4 │ + + +``` + + diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-module-block-top-level-await-using-binding.js b/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-module-block-top-level-await-using-binding.js new file mode 100644 index 00000000000..fffa04d7c7a --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-module-block-top-level-await-using-binding.js @@ -0,0 +1,3 @@ +const m = module { + await using foo = bar(); +} diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-module-block-top-level-await-using-binding.js.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-module-block-top-level-await-using-binding.js.prettier-snap new file mode 100644 index 00000000000..c9714f2ebff --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-module-block-top-level-await-using-binding.js.prettier-snap @@ -0,0 +1,3 @@ +const m = module { + await using foo = bar(); +}; diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-module-block-top-level-await-using-binding.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-module-block-top-level-await-using-binding.js.snap new file mode 100644 index 00000000000..08f41b3f365 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-module-block-top-level-await-using-binding.js.snap @@ -0,0 +1,96 @@ +--- +source: crates/rome_formatter_test/src/snapshot_builder.rs +info: js/explicit-resource-management/valid-module-block-top-level-await-using-binding.js +--- + +# Input + +```js +const m = module { + await using foo = bar(); +} + +``` + + +# Prettier differences + +```diff +--- Prettier ++++ Rome +@@ -1,3 +1,5 @@ +-const m = module { +- await using foo = bar(); +-}; ++const m = module; ++{ ++ await using; ++ foo = bar(); ++} +``` + +# Output + +```js +const m = module; +{ + await using; + foo = bar(); +} +``` + +# Errors +``` +valid-module-block-top-level-await-using-binding.js:1:18 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × Expected a semicolon or an implicit semicolon after a statement, but found none + + > 1 │ const m = module { + │ ^ + 2 │ await using foo = bar(); + 3 │ } + + i An explicit or implicit semicolon is expected here... + + > 1 │ const m = module { + │ ^ + 2 │ await using foo = bar(); + 3 │ } + + i ...Which is required to end this statement + + > 1 │ const m = module { + │ ^^^^^^^^^^^^^^^^^ + 2 │ await using foo = bar(); + 3 │ } + +valid-module-block-top-level-await-using-binding.js:2:15 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × Expected a semicolon or an implicit semicolon after a statement, but found none + + 1 │ const m = module { + > 2 │ await using foo = bar(); + │ ^^^ + 3 │ } + 4 │ + + i An explicit or implicit semicolon is expected here... + + 1 │ const m = module { + > 2 │ await using foo = bar(); + │ ^^^ + 3 │ } + 4 │ + + i ...Which is required to end this statement + + 1 │ const m = module { + > 2 │ await using foo = bar(); + │ ^^^^^^^^^^^^^^^ + 3 │ } + 4 │ + + +``` + + diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-module-block-top-level-using-binding.js b/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-module-block-top-level-using-binding.js new file mode 100644 index 00000000000..b9c213bf2e9 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-module-block-top-level-using-binding.js @@ -0,0 +1,3 @@ +module { + using foo = bar(); +} diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-module-block-top-level-using-binding.js.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-module-block-top-level-using-binding.js.prettier-snap new file mode 100644 index 00000000000..49449a7deaf --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-module-block-top-level-using-binding.js.prettier-snap @@ -0,0 +1,3 @@ +module { + using foo = bar(); +}; diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-module-block-top-level-using-binding.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-module-block-top-level-using-binding.js.snap new file mode 100644 index 00000000000..6e7b6961e08 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-module-block-top-level-using-binding.js.snap @@ -0,0 +1,96 @@ +--- +source: crates/rome_formatter_test/src/snapshot_builder.rs +info: js/explicit-resource-management/valid-module-block-top-level-using-binding.js +--- + +# Input + +```js +module { + using foo = bar(); +} + +``` + + +# Prettier differences + +```diff +--- Prettier ++++ Rome +@@ -1,3 +1,5 @@ +-module { +- using foo = bar(); +-}; ++module; ++{ ++ using; ++ foo = bar(); ++} +``` + +# Output + +```js +module; +{ + using; + foo = bar(); +} +``` + +# Errors +``` +valid-module-block-top-level-using-binding.js:1:8 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × Expected a semicolon or an implicit semicolon after a statement, but found none + + > 1 │ module { + │ ^ + 2 │ using foo = bar(); + 3 │ } + + i An explicit or implicit semicolon is expected here... + + > 1 │ module { + │ ^ + 2 │ using foo = bar(); + 3 │ } + + i ...Which is required to end this statement + + > 1 │ module { + │ ^^^^^^^^ + 2 │ using foo = bar(); + 3 │ } + +valid-module-block-top-level-using-binding.js:2:9 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × Expected a semicolon or an implicit semicolon after a statement, but found none + + 1 │ module { + > 2 │ using foo = bar(); + │ ^^^ + 3 │ } + 4 │ + + i An explicit or implicit semicolon is expected here... + + 1 │ module { + > 2 │ using foo = bar(); + │ ^^^ + 3 │ } + 4 │ + + i ...Which is required to end this statement + + 1 │ module { + > 2 │ using foo = bar(); + │ ^^^^^^^^^ + 3 │ } + 4 │ + + +``` + + diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-using-as-identifier-computed-member.js b/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-using-as-identifier-computed-member.js new file mode 100644 index 00000000000..76021eb0257 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-using-as-identifier-computed-member.js @@ -0,0 +1,2 @@ +using [x] = 0; +for (using [x] of []); diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-using-as-identifier-computed-member.js.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-using-as-identifier-computed-member.js.prettier-snap new file mode 100644 index 00000000000..34fb1308b87 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-using-as-identifier-computed-member.js.prettier-snap @@ -0,0 +1,2 @@ +using[x] = 0; +for (using[x] of []); diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-using-as-identifier-expression-statement.js b/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-using-as-identifier-expression-statement.js new file mode 100644 index 00000000000..8261b5a2e0b --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-using-as-identifier-expression-statement.js @@ -0,0 +1,2 @@ +using +reader = getReader() diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-using-as-identifier-expression-statement.js.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-using-as-identifier-expression-statement.js.prettier-snap new file mode 100644 index 00000000000..8372ce30f8e --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-using-as-identifier-expression-statement.js.prettier-snap @@ -0,0 +1,2 @@ +using; +reader = getReader(); diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-using-as-identifier-for-await-of.js b/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-using-as-identifier-for-await-of.js new file mode 100644 index 00000000000..9c1ceb473d7 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-using-as-identifier-for-await-of.js @@ -0,0 +1 @@ +for await (using of of); diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-using-as-identifier-for-await-of.js.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-using-as-identifier-for-await-of.js.prettier-snap new file mode 100644 index 00000000000..9c1ceb473d7 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-using-as-identifier-for-await-of.js.prettier-snap @@ -0,0 +1 @@ +for await (using of of); diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-using-as-identifier-for-in.js b/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-using-as-identifier-for-in.js new file mode 100644 index 00000000000..43f6861ee62 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-using-as-identifier-for-in.js @@ -0,0 +1,4 @@ +for (using in []); +for (using.foo in []); +for (using().foo in []); +for (using``.foo in []); diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-using-as-identifier-for-in.js.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-using-as-identifier-for-in.js.prettier-snap new file mode 100644 index 00000000000..43f6861ee62 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-using-as-identifier-for-in.js.prettier-snap @@ -0,0 +1,4 @@ +for (using in []); +for (using.foo in []); +for (using().foo in []); +for (using``.foo in []); diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-using-as-identifier-for-init.js b/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-using-as-identifier-for-init.js new file mode 100644 index 00000000000..e2115da2fea --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-using-as-identifier-for-init.js @@ -0,0 +1,3 @@ +for ( + using; + reader = getReader();); diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-using-as-identifier-for-init.js.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-using-as-identifier-for-init.js.prettier-snap new file mode 100644 index 00000000000..c5bb4f6ae62 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-using-as-identifier-for-init.js.prettier-snap @@ -0,0 +1 @@ +for (using; (reader = getReader()); ); diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-using-as-identifier-for-of.js b/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-using-as-identifier-for-of.js new file mode 100644 index 00000000000..098c11b0561 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-using-as-identifier-for-of.js @@ -0,0 +1,4 @@ +for (using of of); +for (using.foo of of); +for (using().foo of of); +for (using``.foo of of); diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-using-as-identifier-for-of.js.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-using-as-identifier-for-of.js.prettier-snap new file mode 100644 index 00000000000..098c11b0561 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-using-as-identifier-for-of.js.prettier-snap @@ -0,0 +1,4 @@ +for (using of of); +for (using.foo of of); +for (using().foo of of); +for (using``.foo of of); diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-using-as-identifier-in.js b/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-using-as-identifier-in.js new file mode 100644 index 00000000000..b7574f49047 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-using-as-identifier-in.js @@ -0,0 +1 @@ +using in using instanceof using; diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-using-as-identifier-in.js.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-using-as-identifier-in.js.prettier-snap new file mode 100644 index 00000000000..b7574f49047 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-using-as-identifier-in.js.prettier-snap @@ -0,0 +1 @@ +using in using instanceof using; diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-using-binding-basic.js b/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-using-binding-basic.js new file mode 100644 index 00000000000..9f8f2445bc6 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-using-binding-basic.js @@ -0,0 +1,3 @@ +{ + using basic = getReader(); +} diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-using-binding-basic.js.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-using-binding-basic.js.prettier-snap new file mode 100644 index 00000000000..9f8f2445bc6 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-using-binding-basic.js.prettier-snap @@ -0,0 +1,3 @@ +{ + using basic = getReader(); +} diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-using-binding-basic.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-using-binding-basic.js.snap new file mode 100644 index 00000000000..f93846ae677 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-using-binding-basic.js.snap @@ -0,0 +1,69 @@ +--- +source: crates/rome_formatter_test/src/snapshot_builder.rs +info: js/explicit-resource-management/valid-using-binding-basic.js +--- + +# Input + +```js +{ + using basic = getReader(); +} + +``` + + +# Prettier differences + +```diff +--- Prettier ++++ Rome +@@ -1,3 +1,4 @@ + { +- using basic = getReader(); ++ using; ++ basic = getReader(); + } +``` + +# Output + +```js +{ + using; + basic = getReader(); +} +``` + +# Errors +``` +valid-using-binding-basic.js:2:9 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × Expected a semicolon or an implicit semicolon after a statement, but found none + + 1 │ { + > 2 │ using basic = getReader(); + │ ^^^^^ + 3 │ } + 4 │ + + i An explicit or implicit semicolon is expected here... + + 1 │ { + > 2 │ using basic = getReader(); + │ ^^^^^ + 3 │ } + 4 │ + + i ...Which is required to end this statement + + 1 │ { + > 2 │ using basic = getReader(); + │ ^^^^^^^^^^^ + 3 │ } + 4 │ + + +``` + + diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-using-binding-escaped.js b/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-using-binding-escaped.js new file mode 100644 index 00000000000..475887f4dbd --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-using-binding-escaped.js @@ -0,0 +1 @@ +{ using \u0061b = c; } diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-using-binding-escaped.js.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-using-binding-escaped.js.prettier-snap new file mode 100644 index 00000000000..102208db652 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-using-binding-escaped.js.prettier-snap @@ -0,0 +1,3 @@ +{ + using ab = c; +} diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-using-binding-escaped.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-using-binding-escaped.js.snap new file mode 100644 index 00000000000..e4a6c104b3d --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-using-binding-escaped.js.snap @@ -0,0 +1,61 @@ +--- +source: crates/rome_formatter_test/src/snapshot_builder.rs +info: js/explicit-resource-management/valid-using-binding-escaped.js +--- + +# Input + +```js +{ using \u0061b = c; } + +``` + + +# Prettier differences + +```diff +--- Prettier ++++ Rome +@@ -1,3 +1,4 @@ + { +- using ab = c; ++ using; ++ \u0061b = c; + } +``` + +# Output + +```js +{ + using; + \u0061b = c; +} +``` + +# Errors +``` +valid-using-binding-escaped.js:1:9 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × Expected a semicolon or an implicit semicolon after a statement, but found none + + > 1 │ { using \u0061b = c; } + │ ^^^^^^^ + 2 │ + + i An explicit or implicit semicolon is expected here... + + > 1 │ { using \u0061b = c; } + │ ^^^^^^^ + 2 │ + + i ...Which is required to end this statement + + > 1 │ { using \u0061b = c; } + │ ^^^^^^^^^^^^^ + 2 │ + + +``` + + diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-using-binding-non-bmp.js b/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-using-binding-non-bmp.js new file mode 100644 index 00000000000..ff01e43dfd6 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-using-binding-non-bmp.js @@ -0,0 +1 @@ +{ using 𠮷 = foo(); } diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-using-binding-non-bmp.js.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-using-binding-non-bmp.js.prettier-snap new file mode 100644 index 00000000000..f3b8568cdaa --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-using-binding-non-bmp.js.prettier-snap @@ -0,0 +1,3 @@ +{ + using 𠮷 = foo(); +} diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-using-binding-non-bmp.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-using-binding-non-bmp.js.snap new file mode 100644 index 00000000000..c13065af8ce --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-using-binding-non-bmp.js.snap @@ -0,0 +1,61 @@ +--- +source: crates/rome_formatter_test/src/snapshot_builder.rs +info: js/explicit-resource-management/valid-using-binding-non-bmp.js +--- + +# Input + +```js +{ using 𠮷 = foo(); } + +``` + + +# Prettier differences + +```diff +--- Prettier ++++ Rome +@@ -1,3 +1,4 @@ + { +- using 𠮷 = foo(); ++ using; ++ 𠮷 = foo(); + } +``` + +# Output + +```js +{ + using; + 𠮷 = foo(); +} +``` + +# Errors +``` +valid-using-binding-non-bmp.js:1:9 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × Expected a semicolon or an implicit semicolon after a statement, but found none + + > 1 │ { using 𠮷 = foo(); } + │ ^^ + 2 │ + + i An explicit or implicit semicolon is expected here... + + > 1 │ { using 𠮷 = foo(); } + │ ^^ + 2 │ + + i ...Which is required to end this statement + + > 1 │ { using 𠮷 = foo(); } + │ ^^^^^^^^ + 2 │ + + +``` + + diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-using-binding-using.js b/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-using-binding-using.js new file mode 100644 index 00000000000..62baf2a5e64 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-using-binding-using.js @@ -0,0 +1,4 @@ +{ + using using = of; + for (using using of of); +} diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-using-binding-using.js.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-using-binding-using.js.prettier-snap new file mode 100644 index 00000000000..62baf2a5e64 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-using-binding-using.js.prettier-snap @@ -0,0 +1,4 @@ +{ + using using = of; + for (using using of of); +} diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-using-binding-using.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-using-binding-using.js.snap new file mode 100644 index 00000000000..6e012e92e65 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/explicit-resource-management/valid-using-binding-using.js.snap @@ -0,0 +1,143 @@ +--- +source: crates/rome_formatter_test/src/snapshot_builder.rs +info: js/explicit-resource-management/valid-using-binding-using.js +--- + +# Input + +```js +{ + using using = of; + for (using using of of); +} + +``` + + +# Prettier differences + +```diff +--- Prettier ++++ Rome +@@ -1,4 +1,6 @@ + { +- using using = of; +- for (using using of of); ++ using; ++ using = of; ++ for (using using of of ++ ) + } +``` + +# Output + +```js +{ + using; + using = of; + for (using using of of + ) +} +``` + +# Errors +``` +valid-using-binding-using.js:2:9 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × Expected a semicolon or an implicit semicolon after a statement, but found none + + 1 │ { + > 2 │ using using = of; + │ ^^^^^ + 3 │ for (using using of of); + 4 │ } + + i An explicit or implicit semicolon is expected here... + + 1 │ { + > 2 │ using using = of; + │ ^^^^^ + 3 │ for (using using of of); + 4 │ } + + i ...Which is required to end this statement + + 1 │ { + > 2 │ using using = of; + │ ^^^^^^^^^^^ + 3 │ for (using using of of); + 4 │ } + +valid-using-binding-using.js:3:14 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × expected `;` but instead found `using` + + 1 │ { + 2 │ using using = of; + > 3 │ for (using using of of); + │ ^^^^^ + 4 │ } + 5 │ + + i Remove using + +valid-using-binding-using.js:3:20 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × expected `;` but instead found `of` + + 1 │ { + 2 │ using using = of; + > 3 │ for (using using of of); + │ ^^ + 4 │ } + 5 │ + + i Remove of + +valid-using-binding-using.js:3:23 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × expected `)` but instead found `of` + + 1 │ { + 2 │ using using = of; + > 3 │ for (using using of of); + │ ^^ + 4 │ } + 5 │ + + i Remove of + +valid-using-binding-using.js:3:25 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × Expected a semicolon or an implicit semicolon after a statement, but found none + + 1 │ { + 2 │ using using = of; + > 3 │ for (using using of of); + │ ^ + 4 │ } + 5 │ + + i An explicit or implicit semicolon is expected here... + + 1 │ { + 2 │ using using = of; + > 3 │ for (using using of of); + │ ^ + 4 │ } + 5 │ + + i ...Which is required to end this statement + + 1 │ { + 2 │ using using = of; + > 3 │ for (using using of of); + │ ^^^ + 4 │ } + 5 │ + + +``` + + diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/function-comments/params-trail-comments.js b/crates/rome_js_formatter/tests/specs/prettier/js/function-comments/params-trail-comments.js new file mode 100644 index 00000000000..baac237b880 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/function-comments/params-trail-comments.js @@ -0,0 +1,24 @@ +function Foo( + bar + // Trailing comment +) {} + +function Foo( + {bar} + // Trailing comment +) {} + +function Foo( + [bar] + // Trailing comment +) {} + +function Foo( + bar = 1 + // Trailing comment +) {} + +function Foo( + ...bar + // Trailing comment +) {} diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/function-comments/params-trail-comments.js.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/js/function-comments/params-trail-comments.js.prettier-snap new file mode 100644 index 00000000000..4066784ef36 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/function-comments/params-trail-comments.js.prettier-snap @@ -0,0 +1,24 @@ +function Foo( + bar, + // Trailing comment +) {} + +function Foo( + { bar }, + // Trailing comment +) {} + +function Foo( + [bar], + // Trailing comment +) {} + +function Foo( + bar = 1, + // Trailing comment +) {} + +function Foo( + ...bar + // Trailing comment +) {} diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/function-single-destructuring/tuple-and-record.js b/crates/rome_js_formatter/tests/specs/prettier/js/function-single-destructuring/tuple-and-record.js new file mode 100644 index 00000000000..4fbf5bdd004 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/function-single-destructuring/tuple-and-record.js @@ -0,0 +1,47 @@ +function StatelessFunctionalComponent1({ + isActive = true, + onFiltersUpdated = () => null, + onSelect = () => null, + onSubmitAndDeselect = () => null, + onCancel = () => null, + searchFilters = null, + title = '', + items = [], +} = {}) { +} + +function StatelessFunctionalComponent2({ + isActive = true, + onFiltersUpdated = () => null, + onSelect = () => null, + onSubmitAndDeselect = () => null, + onCancel = () => null, + searchFilters = null, + title = '', + items = [], +} = #{}) { +} + +function StatelessFunctionalComponent3([ + isActive = true, + onFiltersUpdated = () => null, + onSelect = () => null, + onSubmitAndDeselect = () => null, + onCancel = () => null, + searchFilters = null, + title = '', + items = [], +] = []) { +} + +function StatelessFunctionalComponent4([ + isActive = true, + onFiltersUpdated = () => null, + onSelect = () => null, + onSubmitAndDeselect = () => null, + onCancel = () => null, + searchFilters = null, + title = '', + items = [], +] = #[]) { +} diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/function-single-destructuring/tuple-and-record.js.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/js/function-single-destructuring/tuple-and-record.js.prettier-snap new file mode 100644 index 00000000000..e9db6776760 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/function-single-destructuring/tuple-and-record.js.prettier-snap @@ -0,0 +1,43 @@ +function StatelessFunctionalComponent1({ + isActive = true, + onFiltersUpdated = () => null, + onSelect = () => null, + onSubmitAndDeselect = () => null, + onCancel = () => null, + searchFilters = null, + title = "", + items = [], +} = {}) {} + +function StatelessFunctionalComponent2({ + isActive = true, + onFiltersUpdated = () => null, + onSelect = () => null, + onSubmitAndDeselect = () => null, + onCancel = () => null, + searchFilters = null, + title = "", + items = [], +} = #{}) {} + +function StatelessFunctionalComponent3([ + isActive = true, + onFiltersUpdated = () => null, + onSelect = () => null, + onSubmitAndDeselect = () => null, + onCancel = () => null, + searchFilters = null, + title = "", + items = [], +] = []) {} + +function StatelessFunctionalComponent4([ + isActive = true, + onFiltersUpdated = () => null, + onSelect = () => null, + onSubmitAndDeselect = () => null, + onCancel = () => null, + searchFilters = null, + title = "", + items = [], +] = #[]) {} diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/function-single-destructuring/tuple-and-record.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/function-single-destructuring/tuple-and-record.js.snap new file mode 100644 index 00000000000..5aca42ee7a2 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/function-single-destructuring/tuple-and-record.js.snap @@ -0,0 +1,233 @@ +--- +source: crates/rome_formatter_test/src/snapshot_builder.rs +info: js/function-single-destructuring/tuple-and-record.js +--- + +# Input + +```js +function StatelessFunctionalComponent1({ + isActive = true, + onFiltersUpdated = () => null, + onSelect = () => null, + onSubmitAndDeselect = () => null, + onCancel = () => null, + searchFilters = null, + title = '', + items = [], +} = {}) { +} + +function StatelessFunctionalComponent2({ + isActive = true, + onFiltersUpdated = () => null, + onSelect = () => null, + onSubmitAndDeselect = () => null, + onCancel = () => null, + searchFilters = null, + title = '', + items = [], +} = #{}) { +} + +function StatelessFunctionalComponent3([ + isActive = true, + onFiltersUpdated = () => null, + onSelect = () => null, + onSubmitAndDeselect = () => null, + onCancel = () => null, + searchFilters = null, + title = '', + items = [], +] = []) { +} + +function StatelessFunctionalComponent4([ + isActive = true, + onFiltersUpdated = () => null, + onSelect = () => null, + onSubmitAndDeselect = () => null, + onCancel = () => null, + searchFilters = null, + title = '', + items = [], +] = #[]) { +} + +``` + + +# Prettier differences + +```diff +--- Prettier ++++ Rome +@@ -16,9 +16,10 @@ + onSubmitAndDeselect = () => null, + onCancel = () => null, + searchFilters = null, +- title = "", ++ title = '', + items = [], +-} = #{}) {} ++} = #{}) { ++} + + function StatelessFunctionalComponent3([ + isActive = true, +@@ -38,6 +39,7 @@ + onSubmitAndDeselect = () => null, + onCancel = () => null, + searchFilters = null, +- title = "", ++ title = '', + items = [], +-] = #[]) {} ++] = #[]) { ++} +``` + +# Output + +```js +function StatelessFunctionalComponent1({ + isActive = true, + onFiltersUpdated = () => null, + onSelect = () => null, + onSubmitAndDeselect = () => null, + onCancel = () => null, + searchFilters = null, + title = "", + items = [], +} = {}) {} + +function StatelessFunctionalComponent2({ + isActive = true, + onFiltersUpdated = () => null, + onSelect = () => null, + onSubmitAndDeselect = () => null, + onCancel = () => null, + searchFilters = null, + title = '', + items = [], +} = #{}) { +} + +function StatelessFunctionalComponent3([ + isActive = true, + onFiltersUpdated = () => null, + onSelect = () => null, + onSubmitAndDeselect = () => null, + onCancel = () => null, + searchFilters = null, + title = "", + items = [], +] = []) {} + +function StatelessFunctionalComponent4([ + isActive = true, + onFiltersUpdated = () => null, + onSelect = () => null, + onSubmitAndDeselect = () => null, + onCancel = () => null, + searchFilters = null, + title = '', + items = [], +] = #[]) { +} +``` + +# Errors +``` +tuple-and-record.js:22:6 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × expected an identifier but instead found '{' + + 20 │ title = '', + 21 │ items = [], + > 22 │ } = #{}) { + │ ^ + 23 │ } + 24 │ + + i Expected an identifier here + + 20 │ title = '', + 21 │ items = [], + > 22 │ } = #{}) { + │ ^ + 23 │ } + 24 │ + +tuple-and-record.js:22:5 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × Private names are only allowed on the left side of a 'in' expression + + 20 │ title = '', + 21 │ items = [], + > 22 │ } = #{}) { + │ ^ + 23 │ } + 24 │ + +tuple-and-record.js:22:6 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × expected `,` but instead found `{` + + 20 │ title = '', + 21 │ items = [], + > 22 │ } = #{}) { + │ ^ + 23 │ } + 24 │ + + i Remove { + +tuple-and-record.js:46:6 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × expected an identifier but instead found '[' + + 44 │ title = '', + 45 │ items = [], + > 46 │ ] = #[]) { + │ ^ + 47 │ } + 48 │ + + i Expected an identifier here + + 44 │ title = '', + 45 │ items = [], + > 46 │ ] = #[]) { + │ ^ + 47 │ } + 48 │ + +tuple-and-record.js:46:5 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × Private names are only allowed on the left side of a 'in' expression + + 44 │ title = '', + 45 │ items = [], + > 46 │ ] = #[]) { + │ ^ + 47 │ } + 48 │ + +tuple-and-record.js:46:6 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × expected `,` but instead found `[` + + 44 │ title = '', + 45 │ items = [], + > 46 │ ] = #[]) { + │ ^ + 47 │ } + 48 │ + + i Remove [ + + +``` + + diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/ignore/class-expression-decorator.js b/crates/rome_js_formatter/tests/specs/prettier/js/ignore/class-expression-decorator.js new file mode 100644 index 00000000000..8d6863350e9 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/ignore/class-expression-decorator.js @@ -0,0 +1,5 @@ +( + // prettier-ignore + @decorator + class {} +); diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/ignore/class-expression-decorator.js.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/js/ignore/class-expression-decorator.js.prettier-snap new file mode 100644 index 00000000000..d6dd4541c89 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/ignore/class-expression-decorator.js.prettier-snap @@ -0,0 +1,5 @@ +// prettier-ignore +( + @decorator + class {} +); diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/ignore/class-expression-decorator.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/ignore/class-expression-decorator.js.snap new file mode 100644 index 00000000000..86d0fd2f821 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/ignore/class-expression-decorator.js.snap @@ -0,0 +1,42 @@ +--- +source: crates/rome_formatter_test/src/snapshot_builder.rs +info: js/ignore/class-expression-decorator.js +--- + +# Input + +```js +( + // prettier-ignore + @decorator + class {} +); + +``` + + +# Prettier differences + +```diff +--- Prettier ++++ Rome +@@ -1,5 +1,5 @@ +-// prettier-ignore + ( ++ // prettier-ignore + @decorator + class {} + ); +``` + +# Output + +```js +( + // prettier-ignore + @decorator + class {} +); +``` + + diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/ignore/decorator.js b/crates/rome_js_formatter/tests/specs/prettier/js/ignore/decorator.js new file mode 100644 index 00000000000..7d2b146ff35 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/ignore/decorator.js @@ -0,0 +1,3 @@ +// prettier-ignore +@decorator +class A {} diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/ignore/decorator.js.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/js/ignore/decorator.js.prettier-snap new file mode 100644 index 00000000000..7d2b146ff35 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/ignore/decorator.js.prettier-snap @@ -0,0 +1,3 @@ +// prettier-ignore +@decorator +class A {} diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/ignore/issue-11077.js b/crates/rome_js_formatter/tests/specs/prettier/js/ignore/issue-11077.js new file mode 100644 index 00000000000..8f1367c1772 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/ignore/issue-11077.js @@ -0,0 +1,20 @@ +function HelloWorld(x) { + + ( + // prettier-ignore + // eslint-disable-next-line + x.a | + x.b + ).call(null) + +} + +function HelloWorld(x) { + // prettier-ignore + ( + // eslint-disable-next-line + x.a | + x.b + ).call(null) + +} diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/ignore/issue-11077.js.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/js/ignore/issue-11077.js.prettier-snap new file mode 100644 index 00000000000..09d43769f46 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/ignore/issue-11077.js.prettier-snap @@ -0,0 +1,15 @@ +function HelloWorld(x) { + // prettier-ignore + // eslint-disable-next-line + (x.a | + x.b).call(null); +} + +function HelloWorld(x) { + // prettier-ignore + ( + // eslint-disable-next-line + x.a | + x.b + ).call(null) +} diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/ignore/issue-11077.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/ignore/issue-11077.js.snap new file mode 100644 index 00000000000..d6cdaea9e8e --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/ignore/issue-11077.js.snap @@ -0,0 +1,83 @@ +--- +source: crates/rome_formatter_test/src/snapshot_builder.rs +info: js/ignore/issue-11077.js +--- + +# Input + +```js +function HelloWorld(x) { + + ( + // prettier-ignore + // eslint-disable-next-line + x.a | + x.b + ).call(null) + +} + +function HelloWorld(x) { + // prettier-ignore + ( + // eslint-disable-next-line + x.a | + x.b + ).call(null) + +} + +``` + + +# Prettier differences + +```diff +--- Prettier ++++ Rome +@@ -1,12 +1,15 @@ + function HelloWorld(x) { +- // prettier-ignore +- // eslint-disable-next-line +- (x.a | +- x.b).call(null); ++ ( ++ // prettier-ignore ++ // eslint-disable-next-line ++ x.a | ++ x.b ++ ).call(null) + } + + function HelloWorld(x) { + // prettier-ignore ++ + ( + // eslint-disable-next-line + x.a | +``` + +# Output + +```js +function HelloWorld(x) { + ( + // prettier-ignore + // eslint-disable-next-line + x.a | + x.b + ).call(null) +} + +function HelloWorld(x) { + // prettier-ignore + + ( + // eslint-disable-next-line + x.a | + x.b + ).call(null) +} +``` + + diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/ignore/issue-13737.js b/crates/rome_js_formatter/tests/specs/prettier/js/ignore/issue-13737.js new file mode 100644 index 00000000000..63bfb767b40 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/ignore/issue-13737.js @@ -0,0 +1,9 @@ +oneArgument( + // prettier-ignore + (0, 1) +) + +a=( + // prettier-ignore + (0, 1) +) diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/ignore/issue-13737.js.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/js/ignore/issue-13737.js.prettier-snap new file mode 100644 index 00000000000..8c8513d9a00 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/ignore/issue-13737.js.prettier-snap @@ -0,0 +1,8 @@ +oneArgument( + // prettier-ignore + (0, 1), +); + +a = + // prettier-ignore + (0, 1); diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/ignore/issue-13737.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/ignore/issue-13737.js.snap new file mode 100644 index 00000000000..9098a05ad0b --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/ignore/issue-13737.js.snap @@ -0,0 +1,54 @@ +--- +source: crates/rome_formatter_test/src/snapshot_builder.rs +info: js/ignore/issue-13737.js +--- + +# Input + +```js +oneArgument( + // prettier-ignore + (0, 1) +) + +a=( + // prettier-ignore + (0, 1) +) + +``` + + +# Prettier differences + +```diff +--- Prettier ++++ Rome +@@ -4,5 +4,7 @@ + ); + + a = +- // prettier-ignore +- (0, 1); ++ ( ++ // prettier-ignore ++ (0, 1) ++); +``` + +# Output + +```js +oneArgument( + // prettier-ignore + (0, 1), +); + +a = + ( + // prettier-ignore + (0, 1) +); +``` + + diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/ignore/issue-14404.js b/crates/rome_js_formatter/tests/specs/prettier/js/ignore/issue-14404.js new file mode 100644 index 00000000000..62ec236ce50 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/ignore/issue-14404.js @@ -0,0 +1,7 @@ +async function foo() { +( + // prettier-ignore + // b + await thing() +).blah +} diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/ignore/issue-14404.js.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/js/ignore/issue-14404.js.prettier-snap new file mode 100644 index 00000000000..b89f55e246b --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/ignore/issue-14404.js.prettier-snap @@ -0,0 +1,5 @@ +async function foo() { + // prettier-ignore + // b + (await thing()).blah; +} diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/ignore/issue-14404.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/ignore/issue-14404.js.snap new file mode 100644 index 00000000000..8ca03c7695f --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/ignore/issue-14404.js.snap @@ -0,0 +1,50 @@ +--- +source: crates/rome_formatter_test/src/snapshot_builder.rs +info: js/ignore/issue-14404.js +--- + +# Input + +```js +async function foo() { +( + // prettier-ignore + // b + await thing() +).blah +} + +``` + + +# Prettier differences + +```diff +--- Prettier ++++ Rome +@@ -1,5 +1,7 @@ + async function foo() { +- // prettier-ignore +- // b +- (await thing()).blah; ++ ( ++ // prettier-ignore ++ // b ++ await thing() ++).blah + } +``` + +# Output + +```js +async function foo() { + ( + // prettier-ignore + // b + await thing() +).blah +} +``` + + diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/ignore/issue-9335.js b/crates/rome_js_formatter/tests/specs/prettier/js/ignore/issue-9335.js new file mode 100644 index 00000000000..51be980f896 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/ignore/issue-9335.js @@ -0,0 +1,3 @@ +class foo extends + // prettier-ignore + f {} diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/ignore/issue-9335.js.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/js/ignore/issue-9335.js.prettier-snap new file mode 100644 index 00000000000..92aa99ddaba --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/ignore/issue-9335.js.prettier-snap @@ -0,0 +1,3 @@ +class foo + // prettier-ignore + extends f {} diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/ignore/issue-9877.js b/crates/rome_js_formatter/tests/specs/prettier/js/ignore/issue-9877.js new file mode 100644 index 00000000000..8a51508ad52 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/ignore/issue-9877.js @@ -0,0 +1,11 @@ +export default function test() { + return { + matrix: // prettier-ignore + new Float32Array([ + 0, 0, + 1, 0, + 1, 1, + 0, 1 + ]), + }; +} diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/ignore/issue-9877.js.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/js/ignore/issue-9877.js.prettier-snap new file mode 100644 index 00000000000..8a51508ad52 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/ignore/issue-9877.js.prettier-snap @@ -0,0 +1,11 @@ +export default function test() { + return { + matrix: // prettier-ignore + new Float32Array([ + 0, 0, + 1, 0, + 1, 1, + 0, 1 + ]), + }; +} diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/ignore/issue-9877.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/ignore/issue-9877.js.snap new file mode 100644 index 00000000000..8721e0b696f --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/ignore/issue-9877.js.snap @@ -0,0 +1,55 @@ +--- +source: crates/rome_formatter_test/src/snapshot_builder.rs +info: js/ignore/issue-9877.js +--- + +# Input + +```js +export default function test() { + return { + matrix: // prettier-ignore + new Float32Array([ + 0, 0, + 1, 0, + 1, 1, + 0, 1 + ]), + }; +} + +``` + + +# Prettier differences + +```diff +--- Prettier ++++ Rome +@@ -1,11 +1,6 @@ + export default function test() { + return { + matrix: // prettier-ignore +- new Float32Array([ +- 0, 0, +- 1, 0, +- 1, 1, +- 0, 1 +- ]), ++ new Float32Array([0, 0, 1, 0, 1, 1, 0, 1]), + }; + } +``` + +# Output + +```js +export default function test() { + return { + matrix: // prettier-ignore + new Float32Array([0, 0, 1, 0, 1, 1, 0, 1]), + }; +} +``` + + diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/ignore/semi/asi.js b/crates/rome_js_formatter/tests/specs/prettier/js/ignore/semi/asi.js new file mode 100644 index 00000000000..94cb77939ef --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/ignore/semi/asi.js @@ -0,0 +1,3 @@ +foo; +// prettier-ignore +[1].map(); diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/ignore/semi/asi.js.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/js/ignore/semi/asi.js.prettier-snap new file mode 100644 index 00000000000..94cb77939ef --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/ignore/semi/asi.js.prettier-snap @@ -0,0 +1,3 @@ +foo; +// prettier-ignore +[1].map(); diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/import-attributes/bracket-spacing/dynamic-import.js b/crates/rome_js_formatter/tests/specs/prettier/js/import-attributes/bracket-spacing/dynamic-import.js new file mode 100644 index 00000000000..717b72d4a84 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/import-attributes/bracket-spacing/dynamic-import.js @@ -0,0 +1 @@ +import("./foo.json", { with: { type: "json" } }); diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/import-attributes/bracket-spacing/dynamic-import.js.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/js/import-attributes/bracket-spacing/dynamic-import.js.prettier-snap new file mode 100644 index 00000000000..717b72d4a84 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/import-attributes/bracket-spacing/dynamic-import.js.prettier-snap @@ -0,0 +1 @@ +import("./foo.json", { with: { type: "json" } }); diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/import-attributes/bracket-spacing/empty.js b/crates/rome_js_formatter/tests/specs/prettier/js/import-attributes/bracket-spacing/empty.js new file mode 100644 index 00000000000..22cfde938db --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/import-attributes/bracket-spacing/empty.js @@ -0,0 +1 @@ +export * as bar from "bar.json" with { } \ No newline at end of file diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/import-attributes/bracket-spacing/empty.js.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/js/import-attributes/bracket-spacing/empty.js.prettier-snap new file mode 100644 index 00000000000..349c495478a --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/import-attributes/bracket-spacing/empty.js.prettier-snap @@ -0,0 +1 @@ +export * as bar from "bar.json"; diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/import-attributes/bracket-spacing/empty.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/import-attributes/bracket-spacing/empty.js.snap new file mode 100644 index 00000000000..f5949dd2e80 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/import-attributes/bracket-spacing/empty.js.snap @@ -0,0 +1,29 @@ +--- +source: crates/rome_formatter_test/src/snapshot_builder.rs +info: js/import-attributes/bracket-spacing/empty.js +--- + +# Input + +```js +export * as bar from "bar.json" with { } +``` + + +# Prettier differences + +```diff +--- Prettier ++++ Rome +@@ -1 +1 @@ +-export * as bar from "bar.json"; ++export * as bar from "bar.json" with {}; +``` + +# Output + +```js +export * as bar from "bar.json" with {}; +``` + + diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/import-attributes/bracket-spacing/re-export.js b/crates/rome_js_formatter/tests/specs/prettier/js/import-attributes/bracket-spacing/re-export.js new file mode 100644 index 00000000000..12b98b761f4 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/import-attributes/bracket-spacing/re-export.js @@ -0,0 +1 @@ +export { default as foo2 } from "foo.json" with { type: "json" }; diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/import-attributes/bracket-spacing/re-export.js.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/js/import-attributes/bracket-spacing/re-export.js.prettier-snap new file mode 100644 index 00000000000..12b98b761f4 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/import-attributes/bracket-spacing/re-export.js.prettier-snap @@ -0,0 +1 @@ +export { default as foo2 } from "foo.json" with { type: "json" }; diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/import-attributes/bracket-spacing/static-import.js b/crates/rome_js_formatter/tests/specs/prettier/js/import-attributes/bracket-spacing/static-import.js new file mode 100644 index 00000000000..7770ae1f06b --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/import-attributes/bracket-spacing/static-import.js @@ -0,0 +1 @@ +import json from "./foo.json" with { type: "json" }; diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/import-attributes/bracket-spacing/static-import.js.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/js/import-attributes/bracket-spacing/static-import.js.prettier-snap new file mode 100644 index 00000000000..7770ae1f06b --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/import-attributes/bracket-spacing/static-import.js.prettier-snap @@ -0,0 +1 @@ +import json from "./foo.json" with { type: "json" }; diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/import-attributes/dynamic-import.js b/crates/rome_js_formatter/tests/specs/prettier/js/import-attributes/dynamic-import.js new file mode 100644 index 00000000000..717b72d4a84 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/import-attributes/dynamic-import.js @@ -0,0 +1 @@ +import("./foo.json", { with: { type: "json" } }); diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/import-attributes/dynamic-import.js.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/js/import-attributes/dynamic-import.js.prettier-snap new file mode 100644 index 00000000000..717b72d4a84 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/import-attributes/dynamic-import.js.prettier-snap @@ -0,0 +1 @@ +import("./foo.json", { with: { type: "json" } }); diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/import-attributes/empty.js b/crates/rome_js_formatter/tests/specs/prettier/js/import-attributes/empty.js new file mode 100644 index 00000000000..ab1ee6f33e4 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/import-attributes/empty.js @@ -0,0 +1,7 @@ +export * as foo from "foo.json" +export * as bar from "bar.json" with { } +export * as baz from "baz.json" with { /* comment */ } + +import * as foo from "foo.json" +import * as bar from "bar.json" with { } +import * as baz from "baz.json" with { /* comment */ } diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/import-attributes/empty.js.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/js/import-attributes/empty.js.prettier-snap new file mode 100644 index 00000000000..6be0c7b7e06 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/import-attributes/empty.js.prettier-snap @@ -0,0 +1,7 @@ +export * as foo from "foo.json"; +export * as bar from "bar.json"; +export * as baz from "baz.json" /* comment */; + +import * as foo from "foo.json"; +import * as bar from "bar.json"; +import * as baz from "baz.json" /* comment */; diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/import-attributes/empty.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/import-attributes/empty.js.snap new file mode 100644 index 00000000000..222287bf5b1 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/import-attributes/empty.js.snap @@ -0,0 +1,51 @@ +--- +source: crates/rome_formatter_test/src/snapshot_builder.rs +info: js/import-attributes/empty.js +--- + +# Input + +```js +export * as foo from "foo.json" +export * as bar from "bar.json" with { } +export * as baz from "baz.json" with { /* comment */ } + +import * as foo from "foo.json" +import * as bar from "bar.json" with { } +import * as baz from "baz.json" with { /* comment */ } + +``` + + +# Prettier differences + +```diff +--- Prettier ++++ Rome +@@ -1,7 +1,7 @@ + export * as foo from "foo.json"; +-export * as bar from "bar.json"; +-export * as baz from "baz.json" /* comment */; ++export * as bar from "bar.json" with {}; ++export * as baz from "baz.json" with { /* comment */ }; + + import * as foo from "foo.json"; +-import * as bar from "bar.json"; +-import * as baz from "baz.json" /* comment */; ++import * as bar from "bar.json" with {}; ++import * as baz from "baz.json" with { /* comment */ }; +``` + +# Output + +```js +export * as foo from "foo.json"; +export * as bar from "bar.json" with {}; +export * as baz from "baz.json" with { /* comment */ }; + +import * as foo from "foo.json"; +import * as bar from "bar.json" with {}; +import * as baz from "baz.json" with { /* comment */ }; +``` + + diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/import-attributes/multi-types.js b/crates/rome_js_formatter/tests/specs/prettier/js/import-attributes/multi-types.js new file mode 100644 index 00000000000..0f0e7115f30 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/import-attributes/multi-types.js @@ -0,0 +1 @@ +import json from "./foo.json" with { type: "json", type: "bar" }; diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/import-attributes/multi-types.js.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/js/import-attributes/multi-types.js.prettier-snap new file mode 100644 index 00000000000..0f0e7115f30 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/import-attributes/multi-types.js.prettier-snap @@ -0,0 +1 @@ +import json from "./foo.json" with { type: "json", type: "bar" }; diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/import-attributes/non-type.js b/crates/rome_js_formatter/tests/specs/prettier/js/import-attributes/non-type.js new file mode 100644 index 00000000000..1858e49c202 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/import-attributes/non-type.js @@ -0,0 +1 @@ +import foo from "foo.json" with { lazy: "true" }; diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/import-attributes/non-type.js.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/js/import-attributes/non-type.js.prettier-snap new file mode 100644 index 00000000000..1858e49c202 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/import-attributes/non-type.js.prettier-snap @@ -0,0 +1 @@ +import foo from "foo.json" with { lazy: "true" }; diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/import-attributes/re-export.js b/crates/rome_js_formatter/tests/specs/prettier/js/import-attributes/re-export.js new file mode 100644 index 00000000000..8b7f8a81728 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/import-attributes/re-export.js @@ -0,0 +1,3 @@ +export { default as foo2 } from "foo.json" with { type: "json" }; +export * from "foo.json" with { type: "json" }; +export * as foo3 from "foo.json" with { type: "json" }; diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/import-attributes/re-export.js.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/js/import-attributes/re-export.js.prettier-snap new file mode 100644 index 00000000000..8b7f8a81728 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/import-attributes/re-export.js.prettier-snap @@ -0,0 +1,3 @@ +export { default as foo2 } from "foo.json" with { type: "json" }; +export * from "foo.json" with { type: "json" }; +export * as foo3 from "foo.json" with { type: "json" }; diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/import-attributes/static-import.js b/crates/rome_js_formatter/tests/specs/prettier/js/import-attributes/static-import.js new file mode 100644 index 00000000000..7770ae1f06b --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/import-attributes/static-import.js @@ -0,0 +1 @@ +import json from "./foo.json" with { type: "json" }; diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/import-attributes/static-import.js.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/js/import-attributes/static-import.js.prettier-snap new file mode 100644 index 00000000000..7770ae1f06b --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/import-attributes/static-import.js.prettier-snap @@ -0,0 +1 @@ +import json from "./foo.json" with { type: "json" }; diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/import-attributes/without-from.js b/crates/rome_js_formatter/tests/specs/prettier/js/import-attributes/without-from.js new file mode 100644 index 00000000000..5009c441a73 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/import-attributes/without-from.js @@ -0,0 +1 @@ +import "foo" with { type: "json" } diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/import-attributes/without-from.js.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/js/import-attributes/without-from.js.prettier-snap new file mode 100644 index 00000000000..97676575506 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/import-attributes/without-from.js.prettier-snap @@ -0,0 +1 @@ +import "foo" with { type: "json" }; diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/import-reflection/comments.js b/crates/rome_js_formatter/tests/specs/prettier/js/import-reflection/comments.js new file mode 100644 index 00000000000..225520995e5 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/import-reflection/comments.js @@ -0,0 +1 @@ +/* 0 */import /* 1 */module /* 2 */from /* 3 */from /* 4 */"./module.wasm"/* 5 */; diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/import-reflection/comments.js.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/js/import-reflection/comments.js.prettier-snap new file mode 100644 index 00000000000..4a8174ac878 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/import-reflection/comments.js.prettier-snap @@ -0,0 +1 @@ +/* 0 */ import module /* 1 */ /* 2 */ from /* 3 */ from /* 4 */ "./module.wasm" /* 5 */; diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/import-reflection/comments.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/import-reflection/comments.js.snap new file mode 100644 index 00000000000..dd027e23260 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/import-reflection/comments.js.snap @@ -0,0 +1,73 @@ +--- +source: crates/rome_formatter_test/src/snapshot_builder.rs +info: js/import-reflection/comments.js +--- + +# Input + +```js +/* 0 */import /* 1 */module /* 2 */from /* 3 */from /* 4 */"./module.wasm"/* 5 */; + +``` + + +# Prettier differences + +```diff +--- Prettier ++++ Rome +@@ -1 +1,3 @@ +-/* 0 */ import module /* 1 */ /* 2 */ from /* 3 */ from /* 4 */ "./module.wasm" /* 5 */; ++/* 0 */ import /* 1 */module /* 2 */from /* 3 */ ++from; /* 4 */ ++("./module.wasm") /* 5 */; +``` + +# Output + +```js +/* 0 */ import /* 1 */module /* 2 */from /* 3 */ +from; /* 4 */ +("./module.wasm") /* 5 */; +``` + +# Errors +``` +comments.js:1:48 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × expected a string literal but instead found 'from' + + > 1 │ /* 0 */import /* 1 */module /* 2 */from /* 3 */from /* 4 */"./module.wasm"/* 5 */; + │ ^^^^ + 2 │ + + i Expected a string literal here + + > 1 │ /* 0 */import /* 1 */module /* 2 */from /* 3 */from /* 4 */"./module.wasm"/* 5 */; + │ ^^^^ + 2 │ + +comments.js:1:60 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × Expected a semicolon or an implicit semicolon after a statement, but found none + + > 1 │ /* 0 */import /* 1 */module /* 2 */from /* 3 */from /* 4 */"./module.wasm"/* 5 */; + │ ^^^^^^^^^^^^^^^ + 2 │ + + i An explicit or implicit semicolon is expected here... + + > 1 │ /* 0 */import /* 1 */module /* 2 */from /* 3 */from /* 4 */"./module.wasm"/* 5 */; + │ ^^^^^^^^^^^^^^^ + 2 │ + + i ...Which is required to end this statement + + > 1 │ /* 0 */import /* 1 */module /* 2 */from /* 3 */from /* 4 */"./module.wasm"/* 5 */; + │ ^^^^^^^^^^^^^^^^^^^^^^^^^^^ + 2 │ + + +``` + + diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/import-reflection/import-reflection.js b/crates/rome_js_formatter/tests/specs/prettier/js/import-reflection/import-reflection.js new file mode 100644 index 00000000000..0c84d385708 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/import-reflection/import-reflection.js @@ -0,0 +1 @@ +import module foo from "./module.wasm"; diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/import-reflection/import-reflection.js.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/js/import-reflection/import-reflection.js.prettier-snap new file mode 100644 index 00000000000..0c84d385708 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/import-reflection/import-reflection.js.prettier-snap @@ -0,0 +1 @@ +import module foo from "./module.wasm"; diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/import-reflection/import-reflection.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/import-reflection/import-reflection.js.snap new file mode 100644 index 00000000000..9a33311d925 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/import-reflection/import-reflection.js.snap @@ -0,0 +1,91 @@ +--- +source: crates/rome_formatter_test/src/snapshot_builder.rs +info: js/import-reflection/import-reflection.js +--- + +# Input + +```js +import module foo from "./module.wasm"; + +``` + + +# Prettier differences + +```diff +--- Prettier ++++ Rome +@@ -1 +1,4 @@ +-import module foo from "./module.wasm"; ++import module ++foo; ++from; ++("./module.wasm"); +``` + +# Output + +```js +import module +foo; +from; +("./module.wasm"); +``` + +# Errors +``` +import-reflection.js:1:15 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × expected `from` but instead found `foo` + + > 1 │ import module foo from "./module.wasm"; + │ ^^^ + 2 │ + + i Remove foo + +import-reflection.js:1:19 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × Expected a semicolon or an implicit semicolon after a statement, but found none + + > 1 │ import module foo from "./module.wasm"; + │ ^^^^ + 2 │ + + i An explicit or implicit semicolon is expected here... + + > 1 │ import module foo from "./module.wasm"; + │ ^^^^ + 2 │ + + i ...Which is required to end this statement + + > 1 │ import module foo from "./module.wasm"; + │ ^^^^^^^^ + 2 │ + +import-reflection.js:1:24 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × Expected a semicolon or an implicit semicolon after a statement, but found none + + > 1 │ import module foo from "./module.wasm"; + │ ^^^^^^^^^^^^^^^ + 2 │ + + i An explicit or implicit semicolon is expected here... + + > 1 │ import module foo from "./module.wasm"; + │ ^^^^^^^^^^^^^^^ + 2 │ + + i ...Which is required to end this statement + + > 1 │ import module foo from "./module.wasm"; + │ ^^^^^^^^^^^^^^^^^^^^ + 2 │ + + +``` + + diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/import-reflection/valid-default-import.mjs b/crates/rome_js_formatter/tests/specs/prettier/js/import-reflection/valid-default-import.mjs new file mode 100644 index 00000000000..b0f11212d09 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/import-reflection/valid-default-import.mjs @@ -0,0 +1,2 @@ +import module foo from "./module.wasm"; +import bar from "./module.wasm"; diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/import-reflection/valid-default-import.mjs.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/js/import-reflection/valid-default-import.mjs.prettier-snap new file mode 100644 index 00000000000..b0f11212d09 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/import-reflection/valid-default-import.mjs.prettier-snap @@ -0,0 +1,2 @@ +import module foo from "./module.wasm"; +import bar from "./module.wasm"; diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/import-reflection/valid-from-as-default-module-binding-escaped.mjs b/crates/rome_js_formatter/tests/specs/prettier/js/import-reflection/valid-from-as-default-module-binding-escaped.mjs new file mode 100644 index 00000000000..6185d417527 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/import-reflection/valid-from-as-default-module-binding-escaped.mjs @@ -0,0 +1 @@ +import module \u0066rom from "./module.wasm"; diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/import-reflection/valid-from-as-default-module-binding-escaped.mjs.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/js/import-reflection/valid-from-as-default-module-binding-escaped.mjs.prettier-snap new file mode 100644 index 00000000000..bac2eb72208 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/import-reflection/valid-from-as-default-module-binding-escaped.mjs.prettier-snap @@ -0,0 +1 @@ +import module from from "./module.wasm"; diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/import-reflection/valid-from-as-default-module-binding.mjs b/crates/rome_js_formatter/tests/specs/prettier/js/import-reflection/valid-from-as-default-module-binding.mjs new file mode 100644 index 00000000000..bac2eb72208 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/import-reflection/valid-from-as-default-module-binding.mjs @@ -0,0 +1 @@ +import module from from "./module.wasm"; diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/import-reflection/valid-from-as-default-module-binding.mjs.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/js/import-reflection/valid-from-as-default-module-binding.mjs.prettier-snap new file mode 100644 index 00000000000..bac2eb72208 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/import-reflection/valid-from-as-default-module-binding.mjs.prettier-snap @@ -0,0 +1 @@ +import module from from "./module.wasm"; diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/import-reflection/valid-module-as-default-binding-2.mjs b/crates/rome_js_formatter/tests/specs/prettier/js/import-reflection/valid-module-as-default-binding-2.mjs new file mode 100644 index 00000000000..f3d7cb5f987 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/import-reflection/valid-module-as-default-binding-2.mjs @@ -0,0 +1 @@ +import module, { createRequire } from "node:module"; diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/import-reflection/valid-module-as-default-binding-2.mjs.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/js/import-reflection/valid-module-as-default-binding-2.mjs.prettier-snap new file mode 100644 index 00000000000..f3d7cb5f987 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/import-reflection/valid-module-as-default-binding-2.mjs.prettier-snap @@ -0,0 +1 @@ +import module, { createRequire } from "node:module"; diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/import-reflection/valid-module-as-default-binding.mjs b/crates/rome_js_formatter/tests/specs/prettier/js/import-reflection/valid-module-as-default-binding.mjs new file mode 100644 index 00000000000..bd14dd36b0c --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/import-reflection/valid-module-as-default-binding.mjs @@ -0,0 +1 @@ +import module from "./module.wasm"; diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/import-reflection/valid-module-as-default-binding.mjs.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/js/import-reflection/valid-module-as-default-binding.mjs.prettier-snap new file mode 100644 index 00000000000..bd14dd36b0c --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/import-reflection/valid-module-as-default-binding.mjs.prettier-snap @@ -0,0 +1 @@ +import module from "./module.wasm"; diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/last-argument-expansion/embed.js b/crates/rome_js_formatter/tests/specs/prettier/js/last-argument-expansion/embed.js new file mode 100644 index 00000000000..a8ba2c14905 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/last-argument-expansion/embed.js @@ -0,0 +1,8 @@ +foo(/* HTML */ ` bar `); +foo(/* HTML */ ` bar `); +foo(/* HTML */ `

bar

foo
`); +foo(/* HTML */ `

bar

foo
`); +foo(/* GraphQL */ `query { foo { bar } }`); +foo(/* ... */ css`color:magenta`); +const a = b => /* HTML */ ` bar ` +const c = b => /* HTML */ ` bar ` diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/last-argument-expansion/embed.js.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/js/last-argument-expansion/embed.js.prettier-snap new file mode 100644 index 00000000000..a4d6495e2fd --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/last-argument-expansion/embed.js.prettier-snap @@ -0,0 +1,36 @@ +foo(/* HTML */ ` + bar + `); +foo(/* HTML */ ` + + bar + +`); +foo(/* HTML */ `
+

bar

+ foo +
`); +foo(/* HTML */ ` +
+

bar

+ foo +
+`); +foo(/* GraphQL */ ` + query { + foo { + bar + } + } +`); +foo(/* ... */ css` + color: magenta; +`); +const a = (b) => /* HTML */ ` + bar + `; +const c = (b) => /* HTML */ ` + + bar + +`; diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/last-argument-expansion/embed.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/last-argument-expansion/embed.js.snap new file mode 100644 index 00000000000..b2cfee132da --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/last-argument-expansion/embed.js.snap @@ -0,0 +1,86 @@ +--- +source: crates/rome_formatter_test/src/snapshot_builder.rs +info: js/last-argument-expansion/embed.js +--- + +# Input + +```js +foo(/* HTML */ ` bar `); +foo(/* HTML */ ` bar `); +foo(/* HTML */ `

bar

foo
`); +foo(/* HTML */ `

bar

foo
`); +foo(/* GraphQL */ `query { foo { bar } }`); +foo(/* ... */ css`color:magenta`); +const a = b => /* HTML */ ` bar ` +const c = b => /* HTML */ ` bar ` + +``` + + +# Prettier differences + +```diff +--- Prettier ++++ Rome +@@ -1,36 +1,8 @@ +-foo(/* HTML */ ` +- bar +- `); +-foo(/* HTML */ ` +- +- bar +- +-`); +-foo(/* HTML */ `
+-

bar

+- foo +-
`); +-foo(/* HTML */ ` +-
+-

bar

+- foo +-
+-`); +-foo(/* GraphQL */ ` +- query { +- foo { +- bar +- } +- } +-`); +-foo(/* ... */ css` +- color: magenta; +-`); +-const a = (b) => /* HTML */ ` +- bar +- `; +-const c = (b) => /* HTML */ ` +- +- bar +- +-`; ++foo(/* HTML */ ` bar `); ++foo(/* HTML */ ` bar `); ++foo(/* HTML */ `

bar

foo
`); ++foo(/* HTML */ `

bar

foo
`); ++foo(/* GraphQL */ `query { foo { bar } }`); ++foo(/* ... */ css`color:magenta`); ++const a = (b) => /* HTML */ ` bar `; ++const c = (b) => /* HTML */ ` bar `; +``` + +# Output + +```js +foo(/* HTML */ ` bar `); +foo(/* HTML */ ` bar `); +foo(/* HTML */ `

bar

foo
`); +foo(/* HTML */ `

bar

foo
`); +foo(/* GraphQL */ `query { foo { bar } }`); +foo(/* ... */ css`color:magenta`); +const a = (b) => /* HTML */ ` bar `; +const c = (b) => /* HTML */ ` bar `; +``` + + diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/last-argument-expansion/function-body-in-mode-break.js b/crates/rome_js_formatter/tests/specs/prettier/js/last-argument-expansion/function-body-in-mode-break.js new file mode 100644 index 00000000000..feb86e80e5c --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/last-argument-expansion/function-body-in-mode-break.js @@ -0,0 +1,15 @@ +fs.readdirSync(suiteLoc).forEach(function (testName) { + (skip ? it.skip : it)( + testName, + buildTest(binName, testName, opts), + 2_000_000, + ); +}); + +{ + (skip ? it.skip : it)( + testName, + buildTest(binName, testName, opts), + 2_000_000, + ); +} diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/last-argument-expansion/function-body-in-mode-break.js.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/js/last-argument-expansion/function-body-in-mode-break.js.prettier-snap new file mode 100644 index 00000000000..feb86e80e5c --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/last-argument-expansion/function-body-in-mode-break.js.prettier-snap @@ -0,0 +1,15 @@ +fs.readdirSync(suiteLoc).forEach(function (testName) { + (skip ? it.skip : it)( + testName, + buildTest(binName, testName, opts), + 2_000_000, + ); +}); + +{ + (skip ? it.skip : it)( + testName, + buildTest(binName, testName, opts), + 2_000_000, + ); +} diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/last-argument-expansion/function-body-in-mode-break.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/last-argument-expansion/function-body-in-mode-break.js.snap new file mode 100644 index 00000000000..ee4dc6bf102 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/last-argument-expansion/function-body-in-mode-break.js.snap @@ -0,0 +1,66 @@ +--- +source: crates/rome_formatter_test/src/snapshot_builder.rs +info: js/last-argument-expansion/function-body-in-mode-break.js +--- + +# Input + +```js +fs.readdirSync(suiteLoc).forEach(function (testName) { + (skip ? it.skip : it)( + testName, + buildTest(binName, testName, opts), + 2_000_000, + ); +}); + +{ + (skip ? it.skip : it)( + testName, + buildTest(binName, testName, opts), + 2_000_000, + ); +} + +``` + + +# Prettier differences + +```diff +--- Prettier ++++ Rome +@@ -1,9 +1,7 @@ + fs.readdirSync(suiteLoc).forEach(function (testName) { +- (skip ? it.skip : it)( +- testName, +- buildTest(binName, testName, opts), +- 2_000_000, +- ); ++ (skip ++ ? it.skip ++ : it)(testName, buildTest(binName, testName, opts), 2_000_000); + }); + + { +``` + +# Output + +```js +fs.readdirSync(suiteLoc).forEach(function (testName) { + (skip + ? it.skip + : it)(testName, buildTest(binName, testName, opts), 2_000_000); +}); + +{ + (skip ? it.skip : it)( + testName, + buildTest(binName, testName, opts), + 2_000_000, + ); +} +``` + + diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/method-chain/tuple-and-record.js b/crates/rome_js_formatter/tests/specs/prettier/js/method-chain/tuple-and-record.js new file mode 100644 index 00000000000..b4dee6aa56a --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/method-chain/tuple-and-record.js @@ -0,0 +1,5 @@ +foo.a().b().c([n, o]) +foo.a().b().c(#[n, o]) + +foo.a().b().c({n, o}) +foo.a().b().c(#{n, o}) diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/method-chain/tuple-and-record.js.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/js/method-chain/tuple-and-record.js.prettier-snap new file mode 100644 index 00000000000..eb273b61718 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/method-chain/tuple-and-record.js.prettier-snap @@ -0,0 +1,5 @@ +foo.a().b().c([n, o]); +foo.a().b().c(#[n, o]); + +foo.a().b().c({ n, o }); +foo.a().b().c(#{ n, o }); diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/method-chain/tuple-and-record.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/method-chain/tuple-and-record.js.snap new file mode 100644 index 00000000000..0de3a801796 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/method-chain/tuple-and-record.js.snap @@ -0,0 +1,124 @@ +--- +source: crates/rome_formatter_test/src/snapshot_builder.rs +info: js/method-chain/tuple-and-record.js +--- + +# Input + +```js +foo.a().b().c([n, o]) +foo.a().b().c(#[n, o]) + +foo.a().b().c({n, o}) +foo.a().b().c(#{n, o}) + +``` + + +# Prettier differences + +```diff +--- Prettier ++++ Rome +@@ -1,5 +1,5 @@ + foo.a().b().c([n, o]); +-foo.a().b().c(#[n, o]); ++foo.a().b().c(#[n, o]) + + foo.a().b().c({ n, o }); +-foo.a().b().c(#{ n, o }); ++foo.a().b().c(#{n, o}) +``` + +# Output + +```js +foo.a().b().c([n, o]); +foo.a().b().c(#[n, o]) + +foo.a().b().c({ n, o }); +foo.a().b().c(#{n, o}) +``` + +# Errors +``` +tuple-and-record.js:2:16 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × expected an identifier but instead found '[' + + 1 │ foo.a().b().c([n, o]) + > 2 │ foo.a().b().c(#[n, o]) + │ ^ + 3 │ + 4 │ foo.a().b().c({n, o}) + + i Expected an identifier here + + 1 │ foo.a().b().c([n, o]) + > 2 │ foo.a().b().c(#[n, o]) + │ ^ + 3 │ + 4 │ foo.a().b().c({n, o}) + +tuple-and-record.js:2:15 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × Private names are only allowed on the left side of a 'in' expression + + 1 │ foo.a().b().c([n, o]) + > 2 │ foo.a().b().c(#[n, o]) + │ ^ + 3 │ + 4 │ foo.a().b().c({n, o}) + +tuple-and-record.js:2:16 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × expected `,` but instead found `[` + + 1 │ foo.a().b().c([n, o]) + > 2 │ foo.a().b().c(#[n, o]) + │ ^ + 3 │ + 4 │ foo.a().b().c({n, o}) + + i Remove [ + +tuple-and-record.js:5:16 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × expected an identifier but instead found '{' + + 4 │ foo.a().b().c({n, o}) + > 5 │ foo.a().b().c(#{n, o}) + │ ^ + 6 │ + + i Expected an identifier here + + 4 │ foo.a().b().c({n, o}) + > 5 │ foo.a().b().c(#{n, o}) + │ ^ + 6 │ + +tuple-and-record.js:5:15 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × Private names are only allowed on the left side of a 'in' expression + + 4 │ foo.a().b().c({n, o}) + > 5 │ foo.a().b().c(#{n, o}) + │ ^ + 6 │ + +tuple-and-record.js:5:16 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × expected `,` but instead found `{` + + 4 │ foo.a().b().c({n, o}) + > 5 │ foo.a().b().c(#{n, o}) + │ ^ + 6 │ + + i Remove { + + +``` + + diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/multiparser-comments/tagged.js b/crates/rome_js_formatter/tests/specs/prettier/js/multiparser-comments/tagged.js new file mode 100644 index 00000000000..49673589bac --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/multiparser-comments/tagged.js @@ -0,0 +1,2 @@ +foo(html // oops +`

bar

foo
`); diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/multiparser-comments/tagged.js.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/js/multiparser-comments/tagged.js.prettier-snap new file mode 100644 index 00000000000..3e8194f014c --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/multiparser-comments/tagged.js.prettier-snap @@ -0,0 +1,9 @@ +foo( + html // oops + ` +
+

bar

+ foo +
+ `, +); diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/multiparser-comments/tagged.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/multiparser-comments/tagged.js.snap new file mode 100644 index 00000000000..eafbbf1dc09 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/multiparser-comments/tagged.js.snap @@ -0,0 +1,42 @@ +--- +source: crates/rome_formatter_test/src/snapshot_builder.rs +info: js/multiparser-comments/tagged.js +--- + +# Input + +```js +foo(html // oops +`

bar

foo
`); + +``` + + +# Prettier differences + +```diff +--- Prettier ++++ Rome +@@ -1,9 +1,4 @@ + foo( + html // oops +- ` +-
+-

bar

+- foo +-
+- `, ++ `

bar

foo
`, + ); +``` + +# Output + +```js +foo( + html // oops + `

bar

foo
`, +); +``` + + diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/multiparser-html/issue-10691.js.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/js/multiparser-html/issue-10691.js.prettier-snap index 2f99703d18c..1bab33df273 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/js/multiparser-html/issue-10691.js.prettier-snap +++ b/crates/rome_js_formatter/tests/specs/prettier/js/multiparser-html/issue-10691.js.prettier-snap @@ -1,7 +1,7 @@ export default function include_photoswipe(gallery_selector = ".my-gallery") { return /* HTML */ ` `; } diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/multiparser-html/issue-10691.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/multiparser-html/issue-10691.js.snap index 01eff7b8717..44e27856ded 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/js/multiparser-html/issue-10691.js.snap +++ b/crates/rome_js_formatter/tests/specs/prettier/js/multiparser-html/issue-10691.js.snap @@ -1,6 +1,5 @@ --- source: crates/rome_formatter_test/src/snapshot_builder.rs -assertion_line: 212 info: js/multiparser-html/issue-10691.js --- @@ -30,7 +29,7 @@ export default function include_photoswipe( export default function include_photoswipe(gallery_selector = ".my-gallery") { - return /* HTML */ ` `; + return /* HTML */ ` diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/new-target/outside-functions.js b/crates/rome_js_formatter/tests/specs/prettier/js/new-target/outside-functions.js new file mode 100644 index 00000000000..85f7e483337 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/new-target/outside-functions.js @@ -0,0 +1 @@ +const x = new.target; diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/new-target/outside-functions.js.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/js/new-target/outside-functions.js.prettier-snap new file mode 100644 index 00000000000..85f7e483337 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/new-target/outside-functions.js.prettier-snap @@ -0,0 +1 @@ +const x = new.target; diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/new-target/range.js b/crates/rome_js_formatter/tests/specs/prettier/js/new-target/range.js new file mode 100644 index 00000000000..57c38b87701 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/new-target/range.js @@ -0,0 +1,6 @@ +class A { + constructor() { + const <<>>x = +new.target<<>>; + } +} diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/new-target/range.js.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/js/new-target/range.js.prettier-snap new file mode 100644 index 00000000000..024d76988f1 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/new-target/range.js.prettier-snap @@ -0,0 +1,5 @@ +class A { + constructor() { + const x = new.target; + } +} diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/objects/bigint-key.js b/crates/rome_js_formatter/tests/specs/prettier/js/objects/bigint-key.js new file mode 100644 index 00000000000..10ad3c5d10e --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/objects/bigint-key.js @@ -0,0 +1,3 @@ +a = {1n: ""} +a = {1n() {}} +a = {get 1n() {}} diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/objects/bigint-key.js.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/js/objects/bigint-key.js.prettier-snap new file mode 100644 index 00000000000..d91d3bf42f6 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/objects/bigint-key.js.prettier-snap @@ -0,0 +1,3 @@ +a = { 1n: "" }; +a = { 1n() {} }; +a = { get 1n() {} }; diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/objects/expression.js.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/js/objects/expression.js.prettier-snap index e6027fc4fc6..ca0ee527cd4 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/js/objects/expression.js.prettier-snap +++ b/crates/rome_js_formatter/tests/specs/prettier/js/objects/expression.js.prettier-snap @@ -1,6 +1,6 @@ -() => ({}``); +() => ({})``; ({})``; -a = () => ({}.x); +a = () => ({}).x; ({}) && a, b; ({})::b, 0; ({})::b()``[""].c++ && 0 ? 0 : 0, 0; diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/objects/expression.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/objects/expression.js.snap index 9c41dae43cd..3fd4cb39733 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/js/objects/expression.js.snap +++ b/crates/rome_js_formatter/tests/specs/prettier/js/objects/expression.js.snap @@ -1,6 +1,5 @@ --- source: crates/rome_formatter_test/src/snapshot_builder.rs -assertion_line: 212 info: js/objects/expression.js --- @@ -40,12 +39,9 @@ const a3 = { ```diff --- Prettier +++ Rome -@@ -1,9 +1,11 @@ --() => ({}``); -+() => ({})``; +@@ -2,8 +2,10 @@ ({})``; --a = () => ({}.x); -+a = () => ({}).x; + a = () => ({}).x; ({}) && a, b; -({})::b, 0; -({})::b()``[""].c++ && 0 ? 0 : 0, 0; diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/optional-chaining/chaining.js.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/js/optional-chaining/chaining.js.prettier-snap index e2db57b91dc..5abf64cb45a 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/js/optional-chaining/chaining.js.prettier-snap +++ b/crates/rome_js_formatter/tests/specs/prettier/js/optional-chaining/chaining.js.prettier-snap @@ -66,19 +66,19 @@ a?.[b ? c : d]; aaaaaaaaaaaaaaaaaaaaaaaa )?.(); -let f = () => ({}?.()); -let g = () => ({}?.b); -a = () => ({}?.() && a); -a = () => ({}?.()() && a); -a = () => ({}?.().b && a); -a = () => ({}?.b && a); -a = () => ({}?.b() && a); -(a) => ({}?.()?.b && 0); -(a) => ({}?.b?.b && 0); -(x) => ({}?.()()); -(x) => ({}?.().b); -(x) => ({}?.b()); -(x) => ({}?.b.b); +let f = () => ({})?.(); +let g = () => ({})?.b; +a = () => ({})?.() && a; +a = () => ({})?.()() && a; +a = () => ({})?.().b && a; +a = () => ({})?.b && a; +a = () => ({})?.b() && a; +(a) => ({})?.()?.b && 0; +(a) => ({})?.b?.b && 0; +(x) => ({})?.()(); +(x) => ({})?.().b; +(x) => ({})?.b(); +(x) => ({})?.b.b; ({})?.a().b(); ({ a: 1 })?.entries(); diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/optional-chaining/chaining.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/optional-chaining/chaining.js.snap index e17679c35bd..c8d771572b3 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/js/optional-chaining/chaining.js.snap +++ b/crates/rome_js_formatter/tests/specs/prettier/js/optional-chaining/chaining.js.snap @@ -1,6 +1,5 @@ --- source: crates/rome_formatter_test/src/snapshot_builder.rs -assertion_line: 212 info: js/optional-chaining/chaining.js --- @@ -142,7 +141,7 @@ new (foo?.())(); a?.[b ? c : d]; -@@ -59,26 +59,26 @@ +@@ -59,7 +59,7 @@ (function () {})?.(); (() => f)?.(); (() => f)?.x; @@ -151,38 +150,6 @@ new (foo?.())(); ( aaaaaaaaaaaaaaaaaaaaaaaa && aaaaaaaaaaaaaaaaaaaaaaaa && - aaaaaaaaaaaaaaaaaaaaaaaa - )?.(); - --let f = () => ({}?.()); --let g = () => ({}?.b); --a = () => ({}?.() && a); --a = () => ({}?.()() && a); --a = () => ({}?.().b && a); --a = () => ({}?.b && a); --a = () => ({}?.b() && a); --(a) => ({}?.()?.b && 0); --(a) => ({}?.b?.b && 0); --(x) => ({}?.()()); --(x) => ({}?.().b); --(x) => ({}?.b()); --(x) => ({}?.b.b); -+let f = () => ({})?.(); -+let g = () => ({})?.b; -+a = () => ({})?.() && a; -+a = () => ({})?.()() && a; -+a = () => ({})?.().b && a; -+a = () => ({})?.b && a; -+a = () => ({})?.b() && a; -+(a) => ({})?.()?.b && 0; -+(a) => ({})?.b?.b && 0; -+(x) => ({})?.()(); -+(x) => ({})?.().b; -+(x) => ({})?.b(); -+(x) => ({})?.b.b; - ({})?.a().b(); - ({ a: 1 })?.entries(); - ``` # Output diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/regex/regexp-modifiers.js b/crates/rome_js_formatter/tests/specs/prettier/js/regex/regexp-modifiers.js new file mode 100644 index 00000000000..6d1d5144bec --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/regex/regexp-modifiers.js @@ -0,0 +1,3 @@ +/(?ims:^[a-z])/u; +/(?-ims:^[a-z].)(^[a-z].)/uims; +/(?ims:^[a-z].1$)/; diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/regex/regexp-modifiers.js.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/js/regex/regexp-modifiers.js.prettier-snap new file mode 100644 index 00000000000..ec7a09a11b4 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/regex/regexp-modifiers.js.prettier-snap @@ -0,0 +1,3 @@ +/(?ims:^[a-z])/u; +/(?-ims:^[a-z].)(^[a-z].)/imsu; +/(?ims:^[a-z].1$)/; diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/rest/trailing-commas.js b/crates/rome_js_formatter/tests/specs/prettier/js/rest/trailing-commas.js index 594fa7e9376..c50492226b7 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/js/rest/trailing-commas.js +++ b/crates/rome_js_formatter/tests/specs/prettier/js/rest/trailing-commas.js @@ -1,8 +1,8 @@ -declare class C { +class C { f( superSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperLong, ...args - ): void, + ) {} } function f( @@ -10,7 +10,7 @@ function f( ...args ) {} -declare class C { f(...superSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperLong): void; } +class D { f(...superSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperLong) {}; } [superSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperLong,,]; diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/rest/trailing-commas.js.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/js/rest/trailing-commas.js.prettier-snap index 7168988943f..d616b53c48b 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/js/rest/trailing-commas.js.prettier-snap +++ b/crates/rome_js_formatter/tests/specs/prettier/js/rest/trailing-commas.js.prettier-snap @@ -1,8 +1,8 @@ -declare class C { +class C { f( superSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperLong, ...args - ): void; + ) {} } function f( @@ -10,10 +10,10 @@ function f( ...args ) {} -declare class C { +class D { f( ...superSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperLong - ): void; + ) {} } [ diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/rest/trailing-commas.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/rest/trailing-commas.js.snap deleted file mode 100644 index bdde77eb0b0..00000000000 --- a/crates/rome_js_formatter/tests/specs/prettier/js/rest/trailing-commas.js.snap +++ /dev/null @@ -1,125 +0,0 @@ ---- -source: crates/rome_formatter_test/src/snapshot_builder.rs -assertion_line: 212 -info: js/rest/trailing-commas.js ---- - -# Input - -```js -declare class C { - f( - superSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperLong, - ...args - ): void, -} - -function f( - superSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperLong, - ...args -) {} - -declare class C { f(...superSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperLong): void; } - -[superSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperLong,,]; - -[veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLong, ...a] = []; -var {veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLong, ...a} = {}; - - -``` - - -# Prettier differences - -```diff ---- Prettier -+++ Rome -@@ -2,7 +2,7 @@ - f( - superSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperLong, - ...args -- ): void; -+ ): void, - } - - function f( -@@ -10,11 +10,7 @@ - ...args - ) {} - --declare class C { -- f( -- ...superSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperLong -- ): void; --} -+declare class C { f(...superSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperLong): void; } - - [ - superSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperLong, -``` - -# Output - -```js -declare class C { - f( - superSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperLong, - ...args - ): void, -} - -function f( - superSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperLong, - ...args -) {} - -declare class C { f(...superSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperLong): void; } - -[ - superSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperLong, - , -]; - -[ - veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLong, - ...a -] = []; -var { - veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLong, - ...a -} = {}; -``` - -# Errors -``` -trailing-commas.js:1:1 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - - × The 'declare' modifier can only be used in TypeScript files. - - > 1 │ declare class C { - │ ^^^^^^^ - 2 │ f( - 3 │ superSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperLong, - -trailing-commas.js:13:1 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - - × The 'declare' modifier can only be used in TypeScript files. - - 11 │ ) {} - 12 │ - > 13 │ declare class C { f(...superSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperLong): void; } - │ ^^^^^^^ - 14 │ - 15 │ [superSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperLong,,]; - - -``` - -# Lines exceeding max width of 80 characters -``` - 13: declare class C { f(...superSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperLong): void; } - 16: superSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperLong, -``` - - diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/sequence-expression/export-default.js b/crates/rome_js_formatter/tests/specs/prettier/js/sequence-expression/export-default.js new file mode 100644 index 00000000000..a7aa3bf3f23 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/sequence-expression/export-default.js @@ -0,0 +1,2 @@ +export default (1, +2); diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/sequence-expression/export-default.js.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/js/sequence-expression/export-default.js.prettier-snap new file mode 100644 index 00000000000..939b016f240 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/sequence-expression/export-default.js.prettier-snap @@ -0,0 +1 @@ +export default (1, 2); diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/sequence-expression/ignore.js b/crates/rome_js_formatter/tests/specs/prettier/js/sequence-expression/ignore.js new file mode 100644 index 00000000000..585b2e5267c --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/sequence-expression/ignore.js @@ -0,0 +1,12 @@ ++ + // prettier-ignore + ( + ( + first + ) + , + ( + last + ) + ) +; diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/sequence-expression/ignore.js.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/js/sequence-expression/ignore.js.prettier-snap new file mode 100644 index 00000000000..1cf18fddb3c --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/sequence-expression/ignore.js.prettier-snap @@ -0,0 +1,10 @@ ++( + // prettier-ignore + (( + first + ) + , + ( + last + )) +); diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/sequence-expression/ignore.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/sequence-expression/ignore.js.snap new file mode 100644 index 00000000000..c8c49007879 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/sequence-expression/ignore.js.snap @@ -0,0 +1,63 @@ +--- +source: crates/rome_formatter_test/src/snapshot_builder.rs +info: js/sequence-expression/ignore.js +--- + +# Input + +```js ++ + // prettier-ignore + ( + ( + first + ) + , + ( + last + ) + ) +; + +``` + + +# Prettier differences + +```diff +--- Prettier ++++ Rome +@@ -1,10 +1,10 @@ +-+( +- // prettier-ignore +- (( +++// prettier-ignore ++( ++ ( + first + ) + , + ( + last +- )) +-); ++ ) ++ ); +``` + +# Output + +```js ++// prettier-ignore +( + ( + first + ) + , + ( + last + ) + ); +``` + + diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/template-literals/indention.js b/crates/rome_js_formatter/tests/specs/prettier/js/template-literals/indention.js new file mode 100644 index 00000000000..62a146f828a --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/template-literals/indention.js @@ -0,0 +1,82 @@ +[ + ` + 1. Go to "-{chalk.green.underline( + "https://www.example.com/drupedalKangarooTransformer" + )}" ${chalk.green.underline( + "https://www.example.com/drupedalKangarooTransformer" + )} + `, + ` + 2. Go to "${chalk.green.underline( + "https://www.example.com/drupedalKangarooTransformer" + )}" ${chalk.green.underline( + "https://www.example.com/drupedalKangarooTransformer" + )} + `, + ` + 1. Go to "-{chalk.green.underline( + "https://www.example.com/drupedalKangarooTransformer" + )}" ${chalk.green.underline( + "https://www.example.com/drupedalKangarooTransformer" + )} + 2. Go to "${chalk.green.underline( + "https://www.example.com/drupedalKangarooTransformer" + )}" ${chalk.green.underline( + "https://www.example.com/drupedalKangarooTransformer" + )} + `, + ` + 2. Go to "${chalk.green.underline( + "https://www.example.com/drupedalKangarooTransformer" + )}" ${chalk.green.underline( + "https://www.example.com/drupedalKangarooTransformer" + )} + 1. Go to "-{chalk.green.underline( + "https://www.example.com/drupedalKangarooTransformer" + )}" ${chalk.green.underline( + "https://www.example.com/drupedalKangarooTransformer" + )} + `, + ` + 1. Go to "-{chalk.green.underline( + "https://www.example.com/drupedalKangarooTransformer" + )}" ${chalk.green.underline( + "https://www.example.com/drupedalKangarooTransformer" + )} + 2. Go to "${chalk.green.underline( + "https://www.example.com/drupedalKangarooTransformer" + )}" ${chalk.green.underline( + "https://www.example.com/drupedalKangarooTransformer" + )} + `, + ` + 1. Go to "-{chalk.green.underline( + "https://www.example.com/drupedalKangarooTransformer" + )}" ${chalk.green.underline( + "https://www.example.com/drupedalKangarooTransformer" + )} + 2. Go to "${chalk.green.underline( + "https://www.example.com/drupedalKangarooTransformer" + )}" ${chalk.green.underline( + "https://www.example.com/drupedalKangarooTransformer" + )} + `, +` +# blabla ${a} ${chalk.green.underline("https://www.example.com/drupedalKangarooTransformer")} + + 2. Go to "${chalk.green.underline( + "https://www.example.com/drupedalKangarooTransformer", + )}" + +# blabla ${a} ${chalk.green.underline("https://www.example.com/drupedalKangarooTransformer")} +`, + ` + # blabla ${a} ${chalk.green.underline("https://www.example.com/drupedalKangarooTransformer")} + + 2. Go to "${chalk.green.underline( + "https://www.example.com/drupedalKangarooTransformer", + )}" + + # blabla ${a} ${chalk.green.underline("https://www.example.com/drupedalKangarooTransformer")} + `, +] diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/template-literals/indention.js.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/js/template-literals/indention.js.prettier-snap new file mode 100644 index 00000000000..ecbb820c475 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/template-literals/indention.js.prettier-snap @@ -0,0 +1,90 @@ +[ + ` + 1. Go to "-{chalk.green.underline( + "https://www.example.com/drupedalKangarooTransformer" + )}" ${chalk.green.underline( + "https://www.example.com/drupedalKangarooTransformer", + )} + `, + ` + 2. Go to "${chalk.green.underline( + "https://www.example.com/drupedalKangarooTransformer", + )}" ${chalk.green.underline( + "https://www.example.com/drupedalKangarooTransformer", + )} + `, + ` + 1. Go to "-{chalk.green.underline( + "https://www.example.com/drupedalKangarooTransformer" + )}" ${chalk.green.underline( + "https://www.example.com/drupedalKangarooTransformer", + )} + 2. Go to "${chalk.green.underline( + "https://www.example.com/drupedalKangarooTransformer", + )}" ${chalk.green.underline( + "https://www.example.com/drupedalKangarooTransformer", + )} + `, + ` + 2. Go to "${chalk.green.underline( + "https://www.example.com/drupedalKangarooTransformer", + )}" ${chalk.green.underline( + "https://www.example.com/drupedalKangarooTransformer", + )} + 1. Go to "-{chalk.green.underline( + "https://www.example.com/drupedalKangarooTransformer" + )}" ${chalk.green.underline( + "https://www.example.com/drupedalKangarooTransformer", + )} + `, + ` + 1. Go to "-{chalk.green.underline( + "https://www.example.com/drupedalKangarooTransformer" + )}" ${chalk.green.underline( + "https://www.example.com/drupedalKangarooTransformer", + )} + 2. Go to "${chalk.green.underline( + "https://www.example.com/drupedalKangarooTransformer", + )}" ${chalk.green.underline( + "https://www.example.com/drupedalKangarooTransformer", + )} + `, + ` + 1. Go to "-{chalk.green.underline( + "https://www.example.com/drupedalKangarooTransformer" + )}" ${chalk.green.underline( + "https://www.example.com/drupedalKangarooTransformer", + )} + 2. Go to "${chalk.green.underline( + "https://www.example.com/drupedalKangarooTransformer", + )}" ${chalk.green.underline( + "https://www.example.com/drupedalKangarooTransformer", + )} + `, + ` +# blabla ${a} ${chalk.green.underline( + "https://www.example.com/drupedalKangarooTransformer", + )} + + 2. Go to "${chalk.green.underline( + "https://www.example.com/drupedalKangarooTransformer", + )}" + +# blabla ${a} ${chalk.green.underline( + "https://www.example.com/drupedalKangarooTransformer", + )} +`, + ` + # blabla ${a} ${chalk.green.underline( + "https://www.example.com/drupedalKangarooTransformer", + )} + + 2. Go to "${chalk.green.underline( + "https://www.example.com/drupedalKangarooTransformer", + )}" + + # blabla ${a} ${chalk.green.underline( + "https://www.example.com/drupedalKangarooTransformer", + )} + `, +]; diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/template-literals/indention.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/template-literals/indention.js.snap new file mode 100644 index 00000000000..0614eff5e03 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/template-literals/indention.js.snap @@ -0,0 +1,250 @@ +--- +source: crates/rome_formatter_test/src/snapshot_builder.rs +info: js/template-literals/indention.js +--- + +# Input + +```js +[ + ` + 1. Go to "-{chalk.green.underline( + "https://www.example.com/drupedalKangarooTransformer" + )}" ${chalk.green.underline( + "https://www.example.com/drupedalKangarooTransformer" + )} + `, + ` + 2. Go to "${chalk.green.underline( + "https://www.example.com/drupedalKangarooTransformer" + )}" ${chalk.green.underline( + "https://www.example.com/drupedalKangarooTransformer" + )} + `, + ` + 1. Go to "-{chalk.green.underline( + "https://www.example.com/drupedalKangarooTransformer" + )}" ${chalk.green.underline( + "https://www.example.com/drupedalKangarooTransformer" + )} + 2. Go to "${chalk.green.underline( + "https://www.example.com/drupedalKangarooTransformer" + )}" ${chalk.green.underline( + "https://www.example.com/drupedalKangarooTransformer" + )} + `, + ` + 2. Go to "${chalk.green.underline( + "https://www.example.com/drupedalKangarooTransformer" + )}" ${chalk.green.underline( + "https://www.example.com/drupedalKangarooTransformer" + )} + 1. Go to "-{chalk.green.underline( + "https://www.example.com/drupedalKangarooTransformer" + )}" ${chalk.green.underline( + "https://www.example.com/drupedalKangarooTransformer" + )} + `, + ` + 1. Go to "-{chalk.green.underline( + "https://www.example.com/drupedalKangarooTransformer" + )}" ${chalk.green.underline( + "https://www.example.com/drupedalKangarooTransformer" + )} + 2. Go to "${chalk.green.underline( + "https://www.example.com/drupedalKangarooTransformer" + )}" ${chalk.green.underline( + "https://www.example.com/drupedalKangarooTransformer" + )} + `, + ` + 1. Go to "-{chalk.green.underline( + "https://www.example.com/drupedalKangarooTransformer" + )}" ${chalk.green.underline( + "https://www.example.com/drupedalKangarooTransformer" + )} + 2. Go to "${chalk.green.underline( + "https://www.example.com/drupedalKangarooTransformer" + )}" ${chalk.green.underline( + "https://www.example.com/drupedalKangarooTransformer" + )} + `, +` +# blabla ${a} ${chalk.green.underline("https://www.example.com/drupedalKangarooTransformer")} + + 2. Go to "${chalk.green.underline( + "https://www.example.com/drupedalKangarooTransformer", + )}" + +# blabla ${a} ${chalk.green.underline("https://www.example.com/drupedalKangarooTransformer")} +`, + ` + # blabla ${a} ${chalk.green.underline("https://www.example.com/drupedalKangarooTransformer")} + + 2. Go to "${chalk.green.underline( + "https://www.example.com/drupedalKangarooTransformer", + )}" + + # blabla ${a} ${chalk.green.underline("https://www.example.com/drupedalKangarooTransformer")} + `, +] + +``` + + +# Prettier differences + +```diff +--- Prettier ++++ Rome +@@ -10,8 +10,8 @@ + 2. Go to "${chalk.green.underline( + "https://www.example.com/drupedalKangarooTransformer", + )}" ${chalk.green.underline( +- "https://www.example.com/drupedalKangarooTransformer", +- )} ++ "https://www.example.com/drupedalKangarooTransformer", ++ )} + `, + ` + 1. Go to "-{chalk.green.underline( +@@ -22,15 +22,15 @@ + 2. Go to "${chalk.green.underline( + "https://www.example.com/drupedalKangarooTransformer", + )}" ${chalk.green.underline( +- "https://www.example.com/drupedalKangarooTransformer", +- )} ++ "https://www.example.com/drupedalKangarooTransformer", ++ )} + `, + ` + 2. Go to "${chalk.green.underline( + "https://www.example.com/drupedalKangarooTransformer", + )}" ${chalk.green.underline( +- "https://www.example.com/drupedalKangarooTransformer", +- )} ++ "https://www.example.com/drupedalKangarooTransformer", ++ )} + 1. Go to "-{chalk.green.underline( + "https://www.example.com/drupedalKangarooTransformer" + )}" ${chalk.green.underline( +@@ -46,8 +46,8 @@ + 2. Go to "${chalk.green.underline( + "https://www.example.com/drupedalKangarooTransformer", + )}" ${chalk.green.underline( +- "https://www.example.com/drupedalKangarooTransformer", +- )} ++ "https://www.example.com/drupedalKangarooTransformer", ++ )} + `, + ` + 1. Go to "-{chalk.green.underline( +@@ -58,8 +58,8 @@ + 2. Go to "${chalk.green.underline( + "https://www.example.com/drupedalKangarooTransformer", + )}" ${chalk.green.underline( +- "https://www.example.com/drupedalKangarooTransformer", +- )} ++ "https://www.example.com/drupedalKangarooTransformer", ++ )} + `, + ` + # blabla ${a} ${chalk.green.underline( +``` + +# Output + +```js +[ + ` + 1. Go to "-{chalk.green.underline( + "https://www.example.com/drupedalKangarooTransformer" + )}" ${chalk.green.underline( + "https://www.example.com/drupedalKangarooTransformer", + )} + `, + ` + 2. Go to "${chalk.green.underline( + "https://www.example.com/drupedalKangarooTransformer", + )}" ${chalk.green.underline( + "https://www.example.com/drupedalKangarooTransformer", + )} + `, + ` + 1. Go to "-{chalk.green.underline( + "https://www.example.com/drupedalKangarooTransformer" + )}" ${chalk.green.underline( + "https://www.example.com/drupedalKangarooTransformer", + )} + 2. Go to "${chalk.green.underline( + "https://www.example.com/drupedalKangarooTransformer", + )}" ${chalk.green.underline( + "https://www.example.com/drupedalKangarooTransformer", + )} + `, + ` + 2. Go to "${chalk.green.underline( + "https://www.example.com/drupedalKangarooTransformer", + )}" ${chalk.green.underline( + "https://www.example.com/drupedalKangarooTransformer", + )} + 1. Go to "-{chalk.green.underline( + "https://www.example.com/drupedalKangarooTransformer" + )}" ${chalk.green.underline( + "https://www.example.com/drupedalKangarooTransformer", + )} + `, + ` + 1. Go to "-{chalk.green.underline( + "https://www.example.com/drupedalKangarooTransformer" + )}" ${chalk.green.underline( + "https://www.example.com/drupedalKangarooTransformer", + )} + 2. Go to "${chalk.green.underline( + "https://www.example.com/drupedalKangarooTransformer", + )}" ${chalk.green.underline( + "https://www.example.com/drupedalKangarooTransformer", + )} + `, + ` + 1. Go to "-{chalk.green.underline( + "https://www.example.com/drupedalKangarooTransformer" + )}" ${chalk.green.underline( + "https://www.example.com/drupedalKangarooTransformer", + )} + 2. Go to "${chalk.green.underline( + "https://www.example.com/drupedalKangarooTransformer", + )}" ${chalk.green.underline( + "https://www.example.com/drupedalKangarooTransformer", + )} + `, + ` +# blabla ${a} ${chalk.green.underline( + "https://www.example.com/drupedalKangarooTransformer", + )} + + 2. Go to "${chalk.green.underline( + "https://www.example.com/drupedalKangarooTransformer", + )}" + +# blabla ${a} ${chalk.green.underline( + "https://www.example.com/drupedalKangarooTransformer", + )} +`, + ` + # blabla ${a} ${chalk.green.underline( + "https://www.example.com/drupedalKangarooTransformer", + )} + + 2. Go to "${chalk.green.underline( + "https://www.example.com/drupedalKangarooTransformer", + )}" + + # blabla ${a} ${chalk.green.underline( + "https://www.example.com/drupedalKangarooTransformer", + )} + `, +]; +``` + + diff --git a/crates/rome_js_formatter/tests/specs/prettier/jsx/cursor/in-jsx-text.js b/crates/rome_js_formatter/tests/specs/prettier/jsx/cursor/in-jsx-text.js new file mode 100644 index 00000000000..aaa114af6af --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/jsx/cursor/in-jsx-text.js @@ -0,0 +1,3 @@ +<>a<|> +
hi
+ diff --git a/crates/rome_js_formatter/tests/specs/prettier/jsx/cursor/in-jsx-text.js.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/jsx/cursor/in-jsx-text.js.prettier-snap new file mode 100644 index 00000000000..544116ab91a --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/jsx/cursor/in-jsx-text.js.prettier-snap @@ -0,0 +1,3 @@ +<> + a<|>
hi
+; diff --git a/crates/rome_js_formatter/tests/specs/prettier/jsx/cursor/in-jsx-text.js.snap b/crates/rome_js_formatter/tests/specs/prettier/jsx/cursor/in-jsx-text.js.snap new file mode 100644 index 00000000000..fc0eb724861 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/jsx/cursor/in-jsx-text.js.snap @@ -0,0 +1,38 @@ +--- +source: crates/rome_formatter_test/src/snapshot_builder.rs +info: jsx/cursor/in-jsx-text.js +--- + +# Input + +```js +<>a +
hi
+ + +``` + + +# Prettier differences + +```diff +--- Prettier ++++ Rome +@@ -1,3 +1,4 @@ + <> +- a
hi
++ a ++
hi
+ ; +``` + +# Output + +```js +<> + a +
hi
+; +``` + + diff --git a/crates/rome_js_formatter/tests/specs/prettier/jsx/jsx/arrow.js b/crates/rome_js_formatter/tests/specs/prettier/jsx/jsx/arrow.js new file mode 100644 index 00000000000..25d771dec9c --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/jsx/jsx/arrow.js @@ -0,0 +1,21 @@ +() => ; +() => () => ; +() => () => () => ; + +() =>
Some text here
; +() => () =>
Some text here
; +() => () => () =>
Some text here
; + +() =>
Long long long long long, very very long text. And more text. Another text.
; +() => () =>
Long long long long long, very very long text. And more text. Another text.
; +() => () => () =>
Long long long long long, very very long text. And more text. Another text.
; + + + {We => 'The purple monkey danced with a tambourine made of cheese.' + 'The robot chef cooked a cake that tasted like rainbows.' + 'The talking pineapple sang a lullaby to the sleepy giraffe.'} +; + + {We => love => 'The purple monkey danced with a tambourine made of cheese.' + 'The robot chef cooked a cake that tasted like rainbows.' + 'The talking pineapple sang a lullaby to the sleepy giraffe.'} +; + + {We => love => currying => 'The purple monkey danced with a tambourine made of cheese.' + 'The robot chef cooked a cake that tasted like rainbows.' + 'The talking pineapple sang a lullaby to the sleepy giraffe.'} +; diff --git a/crates/rome_js_formatter/tests/specs/prettier/jsx/jsx/arrow.js.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/jsx/jsx/arrow.js.prettier-snap new file mode 100644 index 00000000000..e75ed54a8ef --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/jsx/jsx/arrow.js.prettier-snap @@ -0,0 +1,57 @@ +() => ( + + + +); +() => () => ( + + + +); +() => () => () => ( + + + +); + +() =>
Some text here
; +() => () =>
Some text here
; +() => () => () =>
Some text here
; + +() => ( +
+ Long long long long long, very very long text. And more text. Another text. +
+); +() => () => ( +
+ Long long long long long, very very long text. And more text. Another text. +
+); +() => () => () => ( +
+ Long long long long long, very very long text. And more text. Another text. +
+); + + + {(We) => + "The purple monkey danced with a tambourine made of cheese." + + "The robot chef cooked a cake that tasted like rainbows." + + "The talking pineapple sang a lullaby to the sleepy giraffe." + } +; + + {(We) => (love) => + "The purple monkey danced with a tambourine made of cheese." + + "The robot chef cooked a cake that tasted like rainbows." + + "The talking pineapple sang a lullaby to the sleepy giraffe." + } +; + + {(We) => (love) => (currying) => + "The purple monkey danced with a tambourine made of cheese." + + "The robot chef cooked a cake that tasted like rainbows." + + "The talking pineapple sang a lullaby to the sleepy giraffe." + } +; diff --git a/crates/rome_js_formatter/tests/specs/prettier/jsx/jsx/arrow.js.snap b/crates/rome_js_formatter/tests/specs/prettier/jsx/jsx/arrow.js.snap new file mode 100644 index 00000000000..b58f10ba0b9 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/jsx/jsx/arrow.js.snap @@ -0,0 +1,183 @@ +--- +source: crates/rome_formatter_test/src/snapshot_builder.rs +info: jsx/jsx/arrow.js +--- + +# Input + +```js +() => ; +() => () => ; +() => () => () => ; + +() =>
Some text here
; +() => () =>
Some text here
; +() => () => () =>
Some text here
; + +() =>
Long long long long long, very very long text. And more text. Another text.
; +() => () =>
Long long long long long, very very long text. And more text. Another text.
; +() => () => () =>
Long long long long long, very very long text. And more text. Another text.
; + + + {We => 'The purple monkey danced with a tambourine made of cheese.' + 'The robot chef cooked a cake that tasted like rainbows.' + 'The talking pineapple sang a lullaby to the sleepy giraffe.'} +; + + {We => love => 'The purple monkey danced with a tambourine made of cheese.' + 'The robot chef cooked a cake that tasted like rainbows.' + 'The talking pineapple sang a lullaby to the sleepy giraffe.'} +; + + {We => love => currying => 'The purple monkey danced with a tambourine made of cheese.' + 'The robot chef cooked a cake that tasted like rainbows.' + 'The talking pineapple sang a lullaby to the sleepy giraffe.'} +; + +``` + + +# Prettier differences + +```diff +--- Prettier ++++ Rome +@@ -3,16 +3,18 @@ + + + ); +-() => () => ( +- +- +- +-); +-() => () => () => ( +- +- +- +-); ++() => () => ++ ( ++ ++ ++ ++ ); ++() => () => () => ++ ( ++ ++ ++ ++ ); + + () =>
Some text here
; + () => () =>
Some text here
; +@@ -23,16 +25,20 @@ + Long long long long long, very very long text. And more text. Another text. + + ); +-() => () => ( +-
+- Long long long long long, very very long text. And more text. Another text. +-
+-); +-() => () => () => ( +-
+- Long long long long long, very very long text. And more text. Another text. +-
+-); ++() => () => ++ ( ++
++ Long long long long long, very very long text. And more text. Another ++ text. ++
++ ); ++() => () => () => ++ ( ++
++ Long long long long long, very very long text. And more text. Another ++ text. ++
++ ); + + + {(We) => +@@ -45,13 +51,11 @@ + {(We) => (love) => + "The purple monkey danced with a tambourine made of cheese." + + "The robot chef cooked a cake that tasted like rainbows." + +- "The talking pineapple sang a lullaby to the sleepy giraffe." +- } ++ "The talking pineapple sang a lullaby to the sleepy giraffe."} + ; + + {(We) => (love) => (currying) => + "The purple monkey danced with a tambourine made of cheese." + + "The robot chef cooked a cake that tasted like rainbows." + +- "The talking pineapple sang a lullaby to the sleepy giraffe." +- } ++ "The talking pineapple sang a lullaby to the sleepy giraffe."} + ; +``` + +# Output + +```js +() => ( + + + +); +() => () => + ( + + + + ); +() => () => () => + ( + + + + ); + +() =>
Some text here
; +() => () =>
Some text here
; +() => () => () =>
Some text here
; + +() => ( +
+ Long long long long long, very very long text. And more text. Another text. +
+); +() => () => + ( +
+ Long long long long long, very very long text. And more text. Another + text. +
+ ); +() => () => () => + ( +
+ Long long long long long, very very long text. And more text. Another + text. +
+ ); + + + {(We) => + "The purple monkey danced with a tambourine made of cheese." + + "The robot chef cooked a cake that tasted like rainbows." + + "The talking pineapple sang a lullaby to the sleepy giraffe." + } +; + + {(We) => (love) => + "The purple monkey danced with a tambourine made of cheese." + + "The robot chef cooked a cake that tasted like rainbows." + + "The talking pineapple sang a lullaby to the sleepy giraffe."} +; + + {(We) => (love) => (currying) => + "The purple monkey danced with a tambourine made of cheese." + + "The robot chef cooked a cake that tasted like rainbows." + + "The talking pineapple sang a lullaby to the sleepy giraffe."} +; +``` + + diff --git a/crates/rome_js_formatter/tests/specs/prettier/jsx/jsx/expression.js b/crates/rome_js_formatter/tests/specs/prettier/jsx/jsx/expression.js index 0232f42fd99..55ef3acafb0 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/jsx/jsx/expression.js +++ b/crates/rome_js_formatter/tests/specs/prettier/jsx/jsx/expression.js @@ -82,17 +82,6 @@ }} />; -, - ) => { - this.setState({ - updatedTask: this.state.updatedTask.set(key, value) - }); - }} -/>; - {data => doLogClick("short", "short", data)} ; @@ -109,17 +98,6 @@ }} ; - - {( - key: "possible_key_1" | "possible_key_2" | "possible_key_3", - value: string | Immutable.List, - ) => { - this.setState({ - updatedTask: this.state.updatedTask.set(key, value) - }); - }} -; -
{Array(20) diff --git a/crates/rome_js_formatter/tests/specs/prettier/jsx/jsx/expression.js.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/jsx/jsx/expression.js.prettier-snap index c829ef7965d..724a20f22e9 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/jsx/jsx/expression.js.prettier-snap +++ b/crates/rome_js_formatter/tests/specs/prettier/jsx/jsx/expression.js.prettier-snap @@ -86,17 +86,6 @@ }} />; -, - ) => { - this.setState({ - updatedTask: this.state.updatedTask.set(key, value), - }); - }} -/>; - {(data) => doLogClick("short", "short", data)} ; @@ -121,17 +110,6 @@ }} ; - - {( - key: "possible_key_1" | "possible_key_2" | "possible_key_3", - value: string | Immutable.List, - ) => { - this.setState({ - updatedTask: this.state.updatedTask.set(key, value), - }); - }} -; -
{Array(20) diff --git a/crates/rome_js_formatter/tests/specs/prettier/jsx/optional-chaining/optional-chaining.jsx b/crates/rome_js_formatter/tests/specs/prettier/jsx/optional-chaining/optional-chaining.jsx new file mode 100644 index 00000000000..3d5ffd50a96 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/jsx/optional-chaining/optional-chaining.jsx @@ -0,0 +1,11 @@ +function foo() { + // https://github.com/marmelab/react-admin/blob/5ae855aa958ba54438b144bf0907b1437c5a5d77/examples/demo/src/orders/Totals.tsx#L38-L43 + return ( + + {record?.delivery_fees.toLocaleString(undefined, { + style: 'currency', + currency: 'USD', + })} + + ) +} diff --git a/crates/rome_js_formatter/tests/specs/prettier/jsx/optional-chaining/optional-chaining.jsx.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/jsx/optional-chaining/optional-chaining.jsx.prettier-snap new file mode 100644 index 00000000000..a6353ac92b8 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/jsx/optional-chaining/optional-chaining.jsx.prettier-snap @@ -0,0 +1,11 @@ +function foo() { + // https://github.com/marmelab/react-admin/blob/5ae855aa958ba54438b144bf0907b1437c5a5d77/examples/demo/src/orders/Totals.tsx#L38-L43 + return ( + + {record?.delivery_fees.toLocaleString(undefined, { + style: "currency", + currency: "USD", + })} + + ); +} diff --git a/crates/rome_js_formatter/tests/specs/prettier/jsx/tuple/tuple.js b/crates/rome_js_formatter/tests/specs/prettier/jsx/tuple/tuple.js new file mode 100644 index 00000000000..d9414e3befe --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/jsx/tuple/tuple.js @@ -0,0 +1,9 @@ +a = [ +
, +
, +] + +a = #[ +
, +
, +] diff --git a/crates/rome_js_formatter/tests/specs/prettier/jsx/tuple/tuple.js.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/jsx/tuple/tuple.js.prettier-snap new file mode 100644 index 00000000000..94d74d0871c --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/jsx/tuple/tuple.js.prettier-snap @@ -0,0 +1,3 @@ +a = [
,
]; + +a = #[
,
]; diff --git a/crates/rome_js_formatter/tests/specs/prettier/jsx/tuple/tuple.js.snap b/crates/rome_js_formatter/tests/specs/prettier/jsx/tuple/tuple.js.snap new file mode 100644 index 00000000000..cdae742cb3a --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/jsx/tuple/tuple.js.snap @@ -0,0 +1,109 @@ +--- +source: crates/rome_formatter_test/src/snapshot_builder.rs +info: jsx/tuple/tuple.js +--- + +# Input + +```js +a = [ +
, +
, +] + +a = #[ +
, +
, +] + +``` + + +# Prettier differences + +```diff +--- Prettier ++++ Rome +@@ -1,3 +1,4 @@ + a = [
,
]; + +-a = #[
,
]; ++a = #; ++[
,
]; +``` + +# Output + +```js +a = [
,
]; + +a = #; +[
,
]; +``` + +# Errors +``` +tuple.js:6:6 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × expected an identifier but instead found '[' + + 4 │ ] + 5 │ + > 6 │ a = #[ + │ ^ + 7 │
, + 8 │
, + + i Expected an identifier here + + 4 │ ] + 5 │ + > 6 │ a = #[ + │ ^ + 7 │
, + 8 │
, + +tuple.js:6:5 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × Private names are only allowed on the left side of a 'in' expression + + 4 │ ] + 5 │ + > 6 │ a = #[ + │ ^ + 7 │
, + 8 │
, + +tuple.js:6:6 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × Expected a semicolon or an implicit semicolon after a statement, but found none + + 4 │ ] + 5 │ + > 6 │ a = #[ + │ ^ + 7 │
, + 8 │
, + + i An explicit or implicit semicolon is expected here... + + 4 │ ] + 5 │ + > 6 │ a = #[ + │ ^ + 7 │
, + 8 │
, + + i ...Which is required to end this statement + + 4 │ ] + 5 │ + > 6 │ a = #[ + │ ^^^^^^ + 7 │
, + 8 │
, + + +``` + + diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/angular-component-examples/test.component.ts.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/typescript/angular-component-examples/test.component.ts.prettier-snap index 7f86e041048..ec4a1de1fe7 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/typescript/angular-component-examples/test.component.ts.prettier-snap +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/angular-component-examples/test.component.ts.prettier-snap @@ -1,17 +1,17 @@ @Component({ selector: "app-test", - template: `
    -
  • test
  • -
`, + template: `
  • test
  • +
+ `, styles: [ ` - :host { - color: red; - } - div { - background: blue; - } - `, + + :host { + color: red; + } + div { background: blue + } +`, ], }) class TestComponent {} diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/angular-component-examples/test.component.ts.snap b/crates/rome_js_formatter/tests/specs/prettier/typescript/angular-component-examples/test.component.ts.snap deleted file mode 100644 index f62146c7f0b..00000000000 --- a/crates/rome_js_formatter/tests/specs/prettier/typescript/angular-component-examples/test.component.ts.snap +++ /dev/null @@ -1,87 +0,0 @@ ---- -source: crates/rome_formatter_test/src/snapshot_builder.rs -info: typescript/angular-component-examples/test.component.ts ---- - -# Input - -```ts -@Component({ - selector: 'app-test', - template: `
  • test
  • -
- `, - styles: [ ` - - :host { - color: red; - } - div { background: blue - } -` - -] -}) -class TestComponent {} - -``` - - -# Prettier differences - -```diff ---- Prettier -+++ Rome -@@ -1,17 +1,17 @@ - @Component({ - selector: "app-test", -- template: `
    --
  • test
  • --
`, -+ template: `
  • test
  • -+
-+ `, - styles: [ - ` -- :host { -- color: red; -- } -- div { -- background: blue; -- } -- `, -+ -+ :host { -+ color: red; -+ } -+ div { background: blue -+ } -+`, - ], - }) - class TestComponent {} -``` - -# Output - -```ts -@Component({ - selector: "app-test", - template: `
  • test
  • -
- `, - styles: [ - ` - - :host { - color: red; - } - div { background: blue - } -`, - ], -}) -class TestComponent {} -``` - - diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/argument-expansion/argument_expansion.ts b/crates/rome_js_formatter/tests/specs/prettier/typescript/argument-expansion/argument_expansion.ts index 37f77d346e1..9230cac2756 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/typescript/argument-expansion/argument_expansion.ts +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/argument-expansion/argument_expansion.ts @@ -29,3 +29,7 @@ const bar7 = [1,2,3].reduce((carry, value) => { const bar8 = [1,2,3].reduce((carry, value) => { return {...carry, [value]: true}; }, <{[key: number]: boolean}>{1: true}); + +const bar9 = [1,2,3].reduce((carry, value) => { + return [...carry, value]; +}, [] as foo); diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/argument-expansion/argument_expansion.ts.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/typescript/argument-expansion/argument_expansion.ts.prettier-snap index cf62efbe853..3f1c8d0258b 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/typescript/argument-expansion/argument_expansion.ts.prettier-snap +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/argument-expansion/argument_expansion.ts.prettier-snap @@ -1,10 +1,16 @@ -const bar1 = [1, 2, 3].reduce((carry, value) => { - return [...carry, value]; -}, [] as unknown as number[]); +const bar1 = [1, 2, 3].reduce( + (carry, value) => { + return [...carry, value]; + }, + [] as unknown as number[], +); -const bar2 = [1, 2, 3].reduce((carry, value) => { - return [...carry, value]; -}, >[]); +const bar2 = [1, 2, 3].reduce( + (carry, value) => { + return [...carry, value]; + }, + >[], +); const bar3 = [1, 2, 3].reduce( (carry, value) => { @@ -20,13 +26,19 @@ const bar4 = [1, 2, 3].reduce( >[1, 2, 3], ); -const bar5 = [1, 2, 3].reduce((carry, value) => { - return { ...carry, [value]: true }; -}, {} as unknown as { [key: number]: boolean }); +const bar5 = [1, 2, 3].reduce( + (carry, value) => { + return { ...carry, [value]: true }; + }, + {} as unknown as { [key: number]: boolean }, +); -const bar6 = [1, 2, 3].reduce((carry, value) => { - return { ...carry, [value]: true }; -}, <{ [key: number]: boolean }>{}); +const bar6 = [1, 2, 3].reduce( + (carry, value) => { + return { ...carry, [value]: true }; + }, + <{ [key: number]: boolean }>{}, +); const bar7 = [1, 2, 3].reduce( (carry, value) => { @@ -41,3 +53,7 @@ const bar8 = [1, 2, 3].reduce( }, <{ [key: number]: boolean }>{ 1: true }, ); + +const bar9 = [1, 2, 3].reduce((carry, value) => { + return [...carry, value]; +}, [] as foo); diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/argument-expansion/argument_expansion.ts.snap b/crates/rome_js_formatter/tests/specs/prettier/typescript/argument-expansion/argument_expansion.ts.snap new file mode 100644 index 00000000000..77f445a6b7b --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/argument-expansion/argument_expansion.ts.snap @@ -0,0 +1,156 @@ +--- +source: crates/rome_formatter_test/src/snapshot_builder.rs +info: typescript/argument-expansion/argument_expansion.ts +--- + +# Input + +```ts +const bar1 = [1,2,3].reduce((carry, value) => { + return [...carry, value]; +}, ([] as unknown) as number[]); + +const bar2 = [1,2,3].reduce((carry, value) => { + return [...carry, value]; +}, >[]); + +const bar3 = [1,2,3].reduce((carry, value) => { + return [...carry, value]; +}, ([1, 2, 3] as unknown) as number[]); + +const bar4 = [1,2,3].reduce((carry, value) => { + return [...carry, value]; +}, >[1, 2, 3]); + +const bar5 = [1,2,3].reduce((carry, value) => { + return {...carry, [value]: true}; +}, ({} as unknown) as {[key: number]: boolean}); + +const bar6 = [1,2,3].reduce((carry, value) => { + return {...carry, [value]: true}; +}, <{[key: number]: boolean}>{}); + +const bar7 = [1,2,3].reduce((carry, value) => { + return {...carry, [value]: true}; +}, ({1: true} as unknown) as {[key: number]: boolean}); + +const bar8 = [1,2,3].reduce((carry, value) => { + return {...carry, [value]: true}; +}, <{[key: number]: boolean}>{1: true}); + +const bar9 = [1,2,3].reduce((carry, value) => { + return [...carry, value]; +}, [] as foo); + +``` + + +# Prettier differences + +```diff +--- Prettier ++++ Rome +@@ -1,16 +1,10 @@ +-const bar1 = [1, 2, 3].reduce( +- (carry, value) => { +- return [...carry, value]; +- }, +- [] as unknown as number[], +-); ++const bar1 = [1, 2, 3].reduce((carry, value) => { ++ return [...carry, value]; ++}, [] as unknown as number[]); + +-const bar2 = [1, 2, 3].reduce( +- (carry, value) => { +- return [...carry, value]; +- }, +- >[], +-); ++const bar2 = [1, 2, 3].reduce((carry, value) => { ++ return [...carry, value]; ++}, >[]); + + const bar3 = [1, 2, 3].reduce( + (carry, value) => { +@@ -26,19 +20,13 @@ + >[1, 2, 3], + ); + +-const bar5 = [1, 2, 3].reduce( +- (carry, value) => { +- return { ...carry, [value]: true }; +- }, +- {} as unknown as { [key: number]: boolean }, +-); ++const bar5 = [1, 2, 3].reduce((carry, value) => { ++ return { ...carry, [value]: true }; ++}, {} as unknown as { [key: number]: boolean }); + +-const bar6 = [1, 2, 3].reduce( +- (carry, value) => { +- return { ...carry, [value]: true }; +- }, +- <{ [key: number]: boolean }>{}, +-); ++const bar6 = [1, 2, 3].reduce((carry, value) => { ++ return { ...carry, [value]: true }; ++}, <{ [key: number]: boolean }>{}); + + const bar7 = [1, 2, 3].reduce( + (carry, value) => { +``` + +# Output + +```ts +const bar1 = [1, 2, 3].reduce((carry, value) => { + return [...carry, value]; +}, [] as unknown as number[]); + +const bar2 = [1, 2, 3].reduce((carry, value) => { + return [...carry, value]; +}, >[]); + +const bar3 = [1, 2, 3].reduce( + (carry, value) => { + return [...carry, value]; + }, + [1, 2, 3] as unknown as number[], +); + +const bar4 = [1, 2, 3].reduce( + (carry, value) => { + return [...carry, value]; + }, + >[1, 2, 3], +); + +const bar5 = [1, 2, 3].reduce((carry, value) => { + return { ...carry, [value]: true }; +}, {} as unknown as { [key: number]: boolean }); + +const bar6 = [1, 2, 3].reduce((carry, value) => { + return { ...carry, [value]: true }; +}, <{ [key: number]: boolean }>{}); + +const bar7 = [1, 2, 3].reduce( + (carry, value) => { + return { ...carry, [value]: true }; + }, + { 1: true } as unknown as { [key: number]: boolean }, +); + +const bar8 = [1, 2, 3].reduce( + (carry, value) => { + return { ...carry, [value]: true }; + }, + <{ [key: number]: boolean }>{ 1: true }, +); + +const bar9 = [1, 2, 3].reduce((carry, value) => { + return [...carry, value]; +}, [] as foo); +``` + + diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/arrows/type_params.ts.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/typescript/arrows/type_params.ts.prettier-snap index 37947b85db5..a965419760c 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/typescript/arrows/type_params.ts.prettier-snap +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/arrows/type_params.ts.prettier-snap @@ -1 +1 @@ -(a) => {}; +(a) => {}; diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/arrows/type_params.ts.snap b/crates/rome_js_formatter/tests/specs/prettier/typescript/arrows/type_params.ts.snap new file mode 100644 index 00000000000..85d44378fd0 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/arrows/type_params.ts.snap @@ -0,0 +1,30 @@ +--- +source: crates/rome_formatter_test/src/snapshot_builder.rs +info: typescript/arrows/type_params.ts +--- + +# Input + +```ts +(a) => { } + +``` + + +# Prettier differences + +```diff +--- Prettier ++++ Rome +@@ -1 +1 @@ +-(a) => {}; ++(a) => {}; +``` + +# Output + +```ts +(a) => {}; +``` + + diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/as/as.ts.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/typescript/as/as.ts.prettier-snap index e4e8d1608fe..c3e9e79bfc3 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/typescript/as/as.ts.prettier-snap +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/as/as.ts.prettier-snap @@ -25,7 +25,7 @@ async function g1() { const test = (await "foo") as number; } ({}) as X; -() => ({} as X); +() => ({}) as X; const state = JSON.stringify({ next: window.location.href, nonce, diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/as/as.ts.snap b/crates/rome_js_formatter/tests/specs/prettier/typescript/as/as.ts.snap deleted file mode 100644 index 111dd71f6ee..00000000000 --- a/crates/rome_js_formatter/tests/specs/prettier/typescript/as/as.ts.snap +++ /dev/null @@ -1,148 +0,0 @@ ---- -source: crates/rome_formatter_test/src/snapshot_builder.rs -assertion_line: 212 -info: typescript/as/as.ts ---- - -# Input - -```ts -const name = (description as DescriptionObject).name || (description as string); -this.isTabActionBar((e.target || e.srcElement) as HTMLElement); -(originalError ? wrappedError(errMsg, originalError) : Error(errMsg)) as InjectionError; -'current' in (props.pagination as Object); -('current' in props.pagination) as Object; -start + (yearSelectTotal as number); -(start + yearSelectTotal) as number; -scrollTop > (visibilityHeight as number); -(scrollTop > visibilityHeight) as number; -export default class Column extends (RcTable.Column as React.ComponentClass,ColumnProps,ColumnProps,ColumnProps>) {} -export const MobxTypedForm = class extends (Form as { new (): any }) {} -export abstract class MobxTypedForm1 extends (Form as { new (): any }) {} -({}) as {}; -function*g() { - const test = (yield 'foo') as number; -} -async function g1() { - const test = (await 'foo') as number; -} -({}) as X; -() => ({}) as X; -const state = JSON.stringify({ - next: window.location.href, - nonce, -} as State); - -(foo.bar as Baz) = [bar]; -(foo.bar as any)++; - -(bValue as boolean) ? 0 : -1; -bValue ? 0 : -1; - -const value1 = thisIsAReallyReallyReallyReallyReallyLongIdentifier as SomeInterface; -const value2 = thisIsAnIdentifier as thisIsAReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyLongInterface; -const value3 = thisIsAReallyLongIdentifier as (SomeInterface | SomeOtherInterface); -const value4 = thisIsAReallyLongIdentifier as { prop1: string, prop2: number, prop3: number }[]; -const value5 = thisIsAReallyReallyReallyReallyReallyReallyReallyReallyReallyLongIdentifier as [string, number]; - -const iter1 = createIterator(this.controller, child, this.tag as SyncFunctionComponent); -const iter2 = createIterator(self.controller, child, self.tag as SyncFunctionComponent); - -``` - - -# Prettier differences - -```diff ---- Prettier -+++ Rome -@@ -25,7 +25,7 @@ - const test = (await "foo") as number; - } - ({}) as X; --() => ({} as X); -+() => ({}) as X; - const state = JSON.stringify({ - next: window.location.href, - nonce, -``` - -# Output - -```ts -const name = (description as DescriptionObject).name || (description as string); -this.isTabActionBar((e.target || e.srcElement) as HTMLElement); -(originalError - ? wrappedError(errMsg, originalError) - : Error(errMsg)) as InjectionError; -"current" in (props.pagination as Object); -("current" in props.pagination) as Object; -start + (yearSelectTotal as number); -(start + yearSelectTotal) as number; -scrollTop > (visibilityHeight as number); -(scrollTop > visibilityHeight) as number; -export default class Column extends (RcTable.Column as React.ComponentClass< - ColumnProps, - ColumnProps, - ColumnProps, - ColumnProps ->) {} -export const MobxTypedForm = class extends (Form as { new (): any }) {}; -export abstract class MobxTypedForm1 extends (Form as { new (): any }) {} -({}) as {}; -function* g() { - const test = (yield "foo") as number; -} -async function g1() { - const test = (await "foo") as number; -} -({}) as X; -() => ({}) as X; -const state = JSON.stringify({ - next: window.location.href, - nonce, -} as State); - -(foo.bar as Baz) = [bar]; -(foo.bar as any)++; - -(bValue as boolean) ? 0 : -1; -bValue ? 0 : -1; - -const value1 = - thisIsAReallyReallyReallyReallyReallyLongIdentifier as SomeInterface; -const value2 = - thisIsAnIdentifier as thisIsAReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyLongInterface; -const value3 = thisIsAReallyLongIdentifier as - | SomeInterface - | SomeOtherInterface; -const value4 = thisIsAReallyLongIdentifier as { - prop1: string; - prop2: number; - prop3: number; -}[]; -const value5 = - thisIsAReallyReallyReallyReallyReallyReallyReallyReallyReallyLongIdentifier as [ - string, - number, - ]; - -const iter1 = createIterator( - this.controller, - child, - this.tag as SyncFunctionComponent, -); -const iter2 = createIterator( - self.controller, - child, - self.tag as SyncFunctionComponent, -); -``` - -# Lines exceeding max width of 80 characters -``` - 43: thisIsAnIdentifier as thisIsAReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyLongInterface; - 53: thisIsAReallyReallyReallyReallyReallyReallyReallyReallyReallyLongIdentifier as [ -``` - - diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/assert/comment.ts b/crates/rome_js_formatter/tests/specs/prettier/typescript/assert/comment.ts new file mode 100644 index 00000000000..553d9a5dbdf --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/assert/comment.ts @@ -0,0 +1,8 @@ +a = (x: any): asserts x is string/* comment */ => {} +a = (x: any): asserts x is /* comment */string => {} +a = (x: any): asserts x is/* comment */ string => {} +a = (x: any): asserts x /* comment */is string => {} +a = (x: any): asserts x/* comment */ is string => {} +a = (x: any): asserts /* comment */x is string => {} +a = (x: any): asserts/* comment */ x is string => {} +a = (x: any): /* comment */asserts x is string => {} diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/assert/comment.ts.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/typescript/assert/comment.ts.prettier-snap new file mode 100644 index 00000000000..b9f06f9cd90 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/assert/comment.ts.prettier-snap @@ -0,0 +1,8 @@ +a = (x: any): asserts x is string /* comment */ => {}; +a = (x: any): asserts x is /* comment */ string => {}; +a = (x: any): asserts x is /* comment */ string => {}; +a = (x: any): asserts x /* comment */ is string => {}; +a = (x: any): asserts x /* comment */ is string => {}; +a = (x: any): asserts /* comment */ x is string => {}; +a = (x: any): asserts /* comment */ x is string => {}; +a = (x: any): /* comment */ asserts x is string => {}; diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/call-signature/call-signature.ts b/crates/rome_js_formatter/tests/specs/prettier/typescript/call-signature/call-signature.ts new file mode 100644 index 00000000000..26a328f2fcb --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/call-signature/call-signature.ts @@ -0,0 +1,59 @@ +type T = { + (): void; + second: string; +}; + +type T = { + (): void; // prettier-ignore + second: string; +}; + +type T = { + (): void; // comment + second: string; +}; + +type T = { + first: string; + (): void; +}; + +type T = { + first: string; + (): void; // prettier-ignore +}; + +type T = { + first: string; + (): void; // comment +}; + +interface I { + (): void; + second: string; +} + +interface I { + (): void; // prettier-ignore + second: string; +} + +interface I { + (): void; // comment + second: string; +} + +interface I { + first: string; + (): void; +} + +interface I { + first: string; + (): void; // prettier-ignore +} + +interface I { + first: string; + (): void; // comment +} diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/call-signature/call-signature.ts.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/typescript/call-signature/call-signature.ts.prettier-snap new file mode 100644 index 00000000000..26a328f2fcb --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/call-signature/call-signature.ts.prettier-snap @@ -0,0 +1,59 @@ +type T = { + (): void; + second: string; +}; + +type T = { + (): void; // prettier-ignore + second: string; +}; + +type T = { + (): void; // comment + second: string; +}; + +type T = { + first: string; + (): void; +}; + +type T = { + first: string; + (): void; // prettier-ignore +}; + +type T = { + first: string; + (): void; // comment +}; + +interface I { + (): void; + second: string; +} + +interface I { + (): void; // prettier-ignore + second: string; +} + +interface I { + (): void; // comment + second: string; +} + +interface I { + first: string; + (): void; +} + +interface I { + first: string; + (): void; // prettier-ignore +} + +interface I { + first: string; + (): void; // comment +} diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/cast/tuple-and-record.ts b/crates/rome_js_formatter/tests/specs/prettier/typescript/cast/tuple-and-record.ts new file mode 100644 index 00000000000..5ca4db06c70 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/cast/tuple-and-record.ts @@ -0,0 +1,5 @@ +breakAfterCast = | undefined>(permissions)[receiverType]; +breakAfterCast = | undefined>(permissions)(#[receiverType]); + +testObjLiteral = | undefined>{ prop1: "myPropVal" }; +testObjLiteral = | undefined>#{ prop1: "myPropVal" }; diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/cast/tuple-and-record.ts.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/typescript/cast/tuple-and-record.ts.prettier-snap new file mode 100644 index 00000000000..07338eacd48 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/cast/tuple-and-record.ts.prettier-snap @@ -0,0 +1,9 @@ +breakAfterCast = | undefined>( + (permissions)[receiverType] +); +breakAfterCast = | undefined>( + (permissions)(#[receiverType]) +); + +testObjLiteral = | undefined>{ prop1: "myPropVal" }; +testObjLiteral = | undefined>#{ prop1: "myPropVal" }; diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/cast/tuple-and-record.ts.snap b/crates/rome_js_formatter/tests/specs/prettier/typescript/cast/tuple-and-record.ts.snap new file mode 100644 index 00000000000..5abfc06707b --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/cast/tuple-and-record.ts.snap @@ -0,0 +1,171 @@ +--- +source: crates/rome_formatter_test/src/snapshot_builder.rs +info: typescript/cast/tuple-and-record.ts +--- + +# Input + +```ts +breakAfterCast = | undefined>(permissions)[receiverType]; +breakAfterCast = | undefined>(permissions)(#[receiverType]); + +testObjLiteral = | undefined>{ prop1: "myPropVal" }; +testObjLiteral = | undefined>#{ prop1: "myPropVal" }; + +``` + + +# Prettier differences + +```diff +--- Prettier ++++ Rome +@@ -1,9 +1,11 @@ + breakAfterCast = | undefined>( + (permissions)[receiverType] + ); +-breakAfterCast = | undefined>( +- (permissions)(#[receiverType]) +-); ++breakAfterCast = | undefined>(permissions)(#[receiverType]); + + testObjLiteral = | undefined>{ prop1: "myPropVal" }; +-testObjLiteral = | undefined>#{ prop1: "myPropVal" }; ++testObjLiteral = | undefined> ++# ++{ ++ prop1: "myPropVal"; ++} +``` + +# Output + +```ts +breakAfterCast = | undefined>( + (permissions)[receiverType] +); +breakAfterCast = | undefined>(permissions)(#[receiverType]); + +testObjLiteral = | undefined>{ prop1: "myPropVal" }; +testObjLiteral = | undefined> +# +{ + prop1: "myPropVal"; +} +``` + +# Errors +``` +tuple-and-record.ts:2:75 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × expected an identifier but instead found '[' + + 1 │ breakAfterCast = | undefined>(permissions)[receiverType]; + > 2 │ breakAfterCast = | undefined>(permissions)(#[receiverType]); + │ ^ + 3 │ + 4 │ testObjLiteral = | undefined>{ prop1: "myPropVal" }; + + i Expected an identifier here + + 1 │ breakAfterCast = | undefined>(permissions)[receiverType]; + > 2 │ breakAfterCast = | undefined>(permissions)(#[receiverType]); + │ ^ + 3 │ + 4 │ testObjLiteral = | undefined>{ prop1: "myPropVal" }; + +tuple-and-record.ts:2:74 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × Private names are only allowed on the left side of a 'in' expression + + 1 │ breakAfterCast = | undefined>(permissions)[receiverType]; + > 2 │ breakAfterCast = | undefined>(permissions)(#[receiverType]); + │ ^ + 3 │ + 4 │ testObjLiteral = | undefined>{ prop1: "myPropVal" }; + +tuple-and-record.ts:2:75 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × expected `,` but instead found `[` + + 1 │ breakAfterCast = | undefined>(permissions)[receiverType]; + > 2 │ breakAfterCast = | undefined>(permissions)(#[receiverType]); + │ ^ + 3 │ + 4 │ testObjLiteral = | undefined>{ prop1: "myPropVal" }; + + i Remove [ + +tuple-and-record.ts:5:56 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × expected an expression but instead found '#' + + 4 │ testObjLiteral = | undefined>{ prop1: "myPropVal" }; + > 5 │ testObjLiteral = | undefined>#{ prop1: "myPropVal" }; + │ ^ + 6 │ + + i Expected an expression here + + 4 │ testObjLiteral = | undefined>{ prop1: "myPropVal" }; + > 5 │ testObjLiteral = | undefined>#{ prop1: "myPropVal" }; + │ ^ + 6 │ + +tuple-and-record.ts:5:57 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × expected an identifier but instead found '{' + + 4 │ testObjLiteral = | undefined>{ prop1: "myPropVal" }; + > 5 │ testObjLiteral = | undefined>#{ prop1: "myPropVal" }; + │ ^ + 6 │ + + i Expected an identifier here + + 4 │ testObjLiteral = | undefined>{ prop1: "myPropVal" }; + > 5 │ testObjLiteral = | undefined>#{ prop1: "myPropVal" }; + │ ^ + 6 │ + +tuple-and-record.ts:5:56 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × Private names are only allowed on the left side of a 'in' expression + + 4 │ testObjLiteral = | undefined>{ prop1: "myPropVal" }; + > 5 │ testObjLiteral = | undefined>#{ prop1: "myPropVal" }; + │ ^ + 6 │ + +tuple-and-record.ts:5:57 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × Expected a semicolon or an implicit semicolon after a statement, but found none + + 4 │ testObjLiteral = | undefined>{ prop1: "myPropVal" }; + > 5 │ testObjLiteral = | undefined>#{ prop1: "myPropVal" }; + │ ^ + 6 │ + + i An explicit or implicit semicolon is expected here... + + 4 │ testObjLiteral = | undefined>{ prop1: "myPropVal" }; + > 5 │ testObjLiteral = | undefined>#{ prop1: "myPropVal" }; + │ ^ + 6 │ + + i ...Which is required to end this statement + + 4 │ testObjLiteral = | undefined>{ prop1: "myPropVal" }; + > 5 │ testObjLiteral = | undefined>#{ prop1: "myPropVal" }; + │ ^^ + 6 │ + + +``` + +# Lines exceeding max width of 80 characters +``` + 4: breakAfterCast = | undefined>(permissions)(#[receiverType]); +``` + + diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/chain-expression/test.ts b/crates/rome_js_formatter/tests/specs/prettier/typescript/chain-expression/test.ts new file mode 100644 index 00000000000..e12dd65ee26 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/chain-expression/test.ts @@ -0,0 +1,4 @@ +(a?.b!).c; +(a?.()!).b; +(a?.b)!.c; +(a?.())!.b; diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/chain-expression/test.ts.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/typescript/chain-expression/test.ts.prettier-snap new file mode 100644 index 00000000000..d0a70dd5358 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/chain-expression/test.ts.prettier-snap @@ -0,0 +1,4 @@ +(a?.b)!.c; +(a?.())!.b; +(a?.b)!.c; +(a?.())!.b; diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/chain-expression/test.ts.snap b/crates/rome_js_formatter/tests/specs/prettier/typescript/chain-expression/test.ts.snap new file mode 100644 index 00000000000..9f64b262bcc --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/chain-expression/test.ts.snap @@ -0,0 +1,42 @@ +--- +source: crates/rome_formatter_test/src/snapshot_builder.rs +info: typescript/chain-expression/test.ts +--- + +# Input + +```ts +(a?.b!).c; +(a?.()!).b; +(a?.b)!.c; +(a?.())!.b; + +``` + + +# Prettier differences + +```diff +--- Prettier ++++ Rome +@@ -1,4 +1,4 @@ +-(a?.b)!.c; +-(a?.())!.b; +-(a?.b)!.c; +-(a?.())!.b; ++a?.b!.c; ++a?.()!.b; ++a?.b!.c; ++a?.()!.b; +``` + +# Output + +```ts +a?.b!.c; +a?.()!.b; +a?.b!.c; +a?.()!.b; +``` + + diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/class/constructor.ts b/crates/rome_js_formatter/tests/specs/prettier/typescript/class/constructor.ts index 9934c471ab5..3cb7582e2fb 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/typescript/class/constructor.ts +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/class/constructor.ts @@ -1,10 +1,8 @@ -class foo { - constructor(static a: number) {} -} - -class foo { - constructor(export a: number) {} -} +class C {constructor(override a: number) {}} +class D {constructor(private a: number) {}} +class E {constructor(protected a: number) {}} +class F {constructor(public a: number) {}} +class G {constructor(readonly a: number) {}} class A { 'constructor': typeof A diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/class/constructor.ts.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/typescript/class/constructor.ts.prettier-snap index 7d9a9e50a79..797a40a552e 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/typescript/class/constructor.ts.prettier-snap +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/class/constructor.ts.prettier-snap @@ -1,9 +1,17 @@ -class foo { - constructor(static a: number) {} +class C { + constructor(override a: number) {} } - -class foo { - constructor(export a: number) {} +class D { + constructor(private a: number) {} +} +class E { + constructor(protected a: number) {} +} +class F { + constructor(public a: number) {} +} +class G { + constructor(readonly a: number) {} } class A { diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/class/constructor.ts.snap b/crates/rome_js_formatter/tests/specs/prettier/typescript/class/constructor.ts.snap index 4211761b1fb..119c3e4e016 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/typescript/class/constructor.ts.snap +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/class/constructor.ts.snap @@ -1,19 +1,16 @@ --- source: crates/rome_formatter_test/src/snapshot_builder.rs -assertion_line: 212 info: typescript/class/constructor.ts --- # Input ```ts -class foo { - constructor(static a: number) {} -} - -class foo { - constructor(export a: number) {} -} +class C {constructor(override a: number) {}} +class D {constructor(private a: number) {}} +class E {constructor(protected a: number) {}} +class F {constructor(public a: number) {}} +class G {constructor(readonly a: number) {}} class A { 'constructor': typeof A @@ -34,7 +31,7 @@ class B { ```diff --- Prettier +++ Rome -@@ -7,7 +7,7 @@ +@@ -15,7 +15,7 @@ } class A { @@ -48,12 +45,20 @@ class B { # Output ```ts -class foo { - constructor(static a: number) {} +class C { + constructor(override a: number) {} } - -class foo { - constructor(export a: number) {} +class D { + constructor(private a: number) {} +} +class E { + constructor(protected a: number) {} +} +class F { + constructor(public a: number) {} +} +class G { + constructor(readonly a: number) {} } class A { @@ -70,83 +75,43 @@ class B { # Errors ``` -constructor.ts:2:15 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - - × 'static' cannot appear on a parameter. - - 1 │ class foo { - > 2 │ constructor(static a: number) {} - │ ^^^^^^ - 3 │ } - 4 │ - -constructor.ts:6:15 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - - × expected a parameter but instead found 'export' - - 5 │ class foo { - > 6 │ constructor(export a: number) {} - │ ^^^^^^ - 7 │ } - 8 │ - - i Expected a parameter here - - 5 │ class foo { - > 6 │ constructor(export a: number) {} - │ ^^^^^^ - 7 │ } - 8 │ - -constructor.ts:6:22 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - - × expected `,` but instead found `a` - - 5 │ class foo { - > 6 │ constructor(export a: number) {} - │ ^ - 7 │ } - 8 │ - - i Remove a - -constructor.ts:10:5 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ +constructor.ts:8:5 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × class properties may not be called `constructor` - 9 │ class A { - > 10 │ 'constructor': typeof A + 7 │ class A { + > 8 │ 'constructor': typeof A │ ^^^^^^^^^^^^^^^^^^^^^^^ - 11 │ static Foo() { - 12 │ return new A() + 9 │ static Foo() { + 10 │ return new A() -constructor.ts:17:15 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ +constructor.ts:15:15 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × expected a type parameter but instead found '>' - 16 │ class B { - > 17 │ constructor<>() {} + 14 │ class B { + > 15 │ constructor<>() {} │ ^ - 18 │ } - 19 │ + 16 │ } + 17 │ i Expected a type parameter here - 16 │ class B { - > 17 │ constructor<>() {} + 14 │ class B { + > 15 │ constructor<>() {} │ ^ - 18 │ } - 19 │ + 16 │ } + 17 │ -constructor.ts:17:14 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ +constructor.ts:15:14 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × constructors cannot have type parameters. - 16 │ class B { - > 17 │ constructor<>() {} + 14 │ class B { + > 15 │ constructor<>() {} │ ^^ - 18 │ } - 19 │ + 16 │ } + 17 │ ``` diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/class/declare-readonly-field-initializer-w-annotation.ts b/crates/rome_js_formatter/tests/specs/prettier/typescript/class/declare-readonly-field-initializer-w-annotation.ts new file mode 100644 index 00000000000..67ea8ae3d29 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/class/declare-readonly-field-initializer-w-annotation.ts @@ -0,0 +1,4 @@ +class A { + declare readonly bar: string = "test"; + declare baz: string = "test"; +} diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/class/declare-readonly-field-initializer-w-annotation.ts.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/typescript/class/declare-readonly-field-initializer-w-annotation.ts.prettier-snap new file mode 100644 index 00000000000..67ea8ae3d29 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/class/declare-readonly-field-initializer-w-annotation.ts.prettier-snap @@ -0,0 +1,4 @@ +class A { + declare readonly bar: string = "test"; + declare baz: string = "test"; +} diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/class/declare-readonly-field-initializer.ts b/crates/rome_js_formatter/tests/specs/prettier/typescript/class/declare-readonly-field-initializer.ts new file mode 100644 index 00000000000..aabe8896039 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/class/declare-readonly-field-initializer.ts @@ -0,0 +1,5 @@ +class A { + declare readonly bar = "test"; + declare readonly foo = 1; + declare readonly baz = a.b; +} diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/class/declare-readonly-field-initializer.ts.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/typescript/class/declare-readonly-field-initializer.ts.prettier-snap new file mode 100644 index 00000000000..aabe8896039 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/class/declare-readonly-field-initializer.ts.prettier-snap @@ -0,0 +1,5 @@ +class A { + declare readonly bar = "test"; + declare readonly foo = 1; + declare readonly baz = a.b; +} diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/class/methods.ts b/crates/rome_js_formatter/tests/specs/prettier/typescript/class/methods.ts index 799573c9c62..3b81dbedb7e 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/typescript/class/methods.ts +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/class/methods.ts @@ -3,7 +3,7 @@ class X { } interface Iterable { - export [Symbol.iterator](): Iterator; + [Symbol.iterator](): Iterator; } export class Check { diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/class/methods.ts.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/typescript/class/methods.ts.prettier-snap index c027a4d341a..53d4c4c6a17 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/typescript/class/methods.ts.prettier-snap +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/class/methods.ts.prettier-snap @@ -3,7 +3,7 @@ class X { } interface Iterable { - export [Symbol.iterator](): Iterator; + [Symbol.iterator](): Iterator; } export class Check { diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/class/methods.ts.snap b/crates/rome_js_formatter/tests/specs/prettier/typescript/class/methods.ts.snap deleted file mode 100644 index 2e21fbfb840..00000000000 --- a/crates/rome_js_formatter/tests/specs/prettier/typescript/class/methods.ts.snap +++ /dev/null @@ -1,76 +0,0 @@ ---- -source: crates/rome_formatter_test/src/snapshot_builder.rs -assertion_line: 212 -info: typescript/class/methods.ts ---- - -# Input - -```ts -class X { - optionalMethod?() {} -} - -interface Iterable { - export [Symbol.iterator](): Iterator; -} - -export class Check { - private static property = 'test'; -} - -``` - - -# Prettier differences - -```diff ---- Prettier -+++ Rome -@@ -3,7 +3,8 @@ - } - - interface Iterable { -- export [Symbol.iterator](): Iterator; -+ export; -+ [Symbol.iterator](): Iterator; - } - - export class Check { -``` - -# Output - -```ts -class X { - optionalMethod?() {} -} - -interface Iterable { - export; - [Symbol.iterator](): Iterator; -} - -export class Check { - private static property = "test"; -} -``` - -# Errors -``` -methods.ts:6:10 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - - × ';' expected' - - 5 │ interface Iterable { - > 6 │ export [Symbol.iterator](): Iterator; - │ ^ - 7 │ } - 8 │ - - i An explicit or implicit semicolon is expected here... - - -``` - - diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/class/parameter-properties.ts b/crates/rome_js_formatter/tests/specs/prettier/typescript/class/parameter-properties.ts new file mode 100644 index 00000000000..a488a14e209 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/class/parameter-properties.ts @@ -0,0 +1,21 @@ +class MyClass { + constructor(protected x: number, private y: string) { + } +} + +[ + class { + "constructor"(protected x: number, private y: string) { + } + }, +] + +class Mixed { + constructor(public a: number, b: unknown) { + } +} + +class OneParameterProperty { + constructor(public foobar: boolean) { + } +} diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/class/parameter-properties.ts.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/typescript/class/parameter-properties.ts.prettier-snap new file mode 100644 index 00000000000..bc9ec9a1e39 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/class/parameter-properties.ts.prettier-snap @@ -0,0 +1,26 @@ +class MyClass { + constructor( + protected x: number, + private y: string, + ) {} +} + +[ + class { + constructor( + protected x: number, + private y: string, + ) {} + }, +]; + +class Mixed { + constructor( + public a: number, + b: unknown, + ) {} +} + +class OneParameterProperty { + constructor(public foobar: boolean) {} +} diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/class/parameter-properties.ts.snap b/crates/rome_js_formatter/tests/specs/prettier/typescript/class/parameter-properties.ts.snap new file mode 100644 index 00000000000..8218f1bfa06 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/class/parameter-properties.ts.snap @@ -0,0 +1,91 @@ +--- +source: crates/rome_formatter_test/src/snapshot_builder.rs +info: typescript/class/parameter-properties.ts +--- + +# Input + +```ts +class MyClass { + constructor(protected x: number, private y: string) { + } +} + +[ + class { + "constructor"(protected x: number, private y: string) { + } + }, +] + +class Mixed { + constructor(public a: number, b: unknown) { + } +} + +class OneParameterProperty { + constructor(public foobar: boolean) { + } +} + +``` + + +# Prettier differences + +```diff +--- Prettier ++++ Rome +@@ -1,24 +1,15 @@ + class MyClass { +- constructor( +- protected x: number, +- private y: string, +- ) {} ++ constructor(protected x: number, private y: string) {} + } + + [ + class { +- constructor( +- protected x: number, +- private y: string, +- ) {} ++ constructor(protected x: number, private y: string) {} + }, + ]; + + class Mixed { +- constructor( +- public a: number, +- b: unknown, +- ) {} ++ constructor(public a: number, b: unknown) {} + } + + class OneParameterProperty { +``` + +# Output + +```ts +class MyClass { + constructor(protected x: number, private y: string) {} +} + +[ + class { + constructor(protected x: number, private y: string) {} + }, +]; + +class Mixed { + constructor(public a: number, b: unknown) {} +} + +class OneParameterProperty { + constructor(public foobar: boolean) {} +} +``` + + diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/comments/after_jsx_generic.tsx b/crates/rome_js_formatter/tests/specs/prettier/typescript/comments/after_jsx_generic.tsx new file mode 100644 index 00000000000..a3825662eac --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/comments/after_jsx_generic.tsx @@ -0,0 +1,25 @@ +let comp = ( + <> + /* comment1 */> + foo /* comment2 */> + /* comment3 */ bar> + foo /* comment4 */ bar> + + + // comment5 + > + + foo + // comment6 + > + + // comment7 + foo + > + + foo + // comment8 + bar + > + +); diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/comments/after_jsx_generic.tsx.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/typescript/comments/after_jsx_generic.tsx.prettier-snap new file mode 100644 index 00000000000..c178abb05ee --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/comments/after_jsx_generic.tsx.prettier-snap @@ -0,0 +1,25 @@ +let comp = ( + <> + /* comment1 */> + foo /* comment2 */> + /* comment3 */ bar> + foo /* comment4 */ bar> + + + // comment5 + > + + foo + // comment6 + > + + // comment7 + foo + > + + foo + // comment8 + bar + > + +); diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/comments/jsx.tsx b/crates/rome_js_formatter/tests/specs/prettier/typescript/comments/jsx.tsx new file mode 100644 index 00000000000..da5adae25b5 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/comments/jsx.tsx @@ -0,0 +1,7 @@ +var example1 =
+ https://test +
; + +var example2 =
+ /*test*/ +
; diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/comments/jsx.tsx.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/typescript/comments/jsx.tsx.prettier-snap new file mode 100644 index 00000000000..a400335ea46 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/comments/jsx.tsx.prettier-snap @@ -0,0 +1,3 @@ +var example1 =
https://test
; + +var example2 =
/*test*/
; diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/comments/method_types.ts.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/typescript/comments/method_types.ts.prettier-snap index c1bd0e8d550..948ac191312 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/typescript/comments/method_types.ts.prettier-snap +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/comments/method_types.ts.prettier-snap @@ -21,16 +21,16 @@ interface foo5 { } interface foo6 { - /* foo */ new (/* baz */): /* bar */ /* bat */ string; + /* foo */ new (/* baz */) /* bar */ : /* bat */ string; } -type foo7 = /* foo */ (/* bar */) => /* baz */ void; +type foo7 = /* foo */ (/* bar */) /* baz */ => void; -type foo8 = /* foo */ (a: /* bar */ string) => /* baz */ void; +type foo8 = /* foo */ (a: /* bar */ string) /* baz */ => void; -let foo9: new (/* bar */) => /* foo */ /* baz */ string; +let foo9: new (/* bar */) /* foo */ /* baz */ => string; -let foo10: new (/* foo */ a: /* bar */ string) => /* baz */ string; +let foo10: new (/* foo */ a: /* bar */ string) /* baz */ => string; abstract class Test { abstract foo12 /* foo */(a: /* bar */ string): /* baz */ void; diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/comments/method_types.ts.snap b/crates/rome_js_formatter/tests/specs/prettier/typescript/comments/method_types.ts.snap index 910fe6d214e..d798c6f7aef 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/typescript/comments/method_types.ts.snap +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/comments/method_types.ts.snap @@ -1,6 +1,5 @@ --- source: crates/rome_formatter_test/src/snapshot_builder.rs -assertion_line: 212 info: typescript/comments/method_types.ts --- @@ -78,20 +77,18 @@ abstract class Test { } interface foo6 { -- /* foo */ new (/* baz */): /* bar */ /* bat */ string; +- /* foo */ new (/* baz */) /* bar */ : /* bat */ string; + /* foo */ new /* bar */ (/* baz */): /* bat */ string; } --type foo7 = /* foo */ (/* bar */) => /* baz */ void; -+type foo7 = /* foo */ (/* bar */) /* baz */ => void; + type foo7 = /* foo */ (/* bar */) /* baz */ => void; --type foo8 = /* foo */ (a: /* bar */ string) => /* baz */ void; -+type foo8 = /* foo */ (a: /* bar */ string) /* baz */ => void; + type foo8 = /* foo */ (a: /* bar */ string) /* baz */ => void; --let foo9: new (/* bar */) => /* foo */ /* baz */ string; +-let foo9: new (/* bar */) /* foo */ /* baz */ => string; +let foo9: new /* foo */ (/* bar */) /* baz */ => string; --let foo10: new (/* foo */ a: /* bar */ string) => /* baz */ string; +-let foo10: new (/* foo */ a: /* bar */ string) /* baz */ => string; +let foo10: new /* foo */ (a: /* bar */ string) /* baz */ => string; abstract class Test { diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/compiler/contextualSignatureInstantiation2.ts.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/typescript/compiler/contextualSignatureInstantiation2.ts.prettier-snap index ef4ac9608e7..06c4ba7b701 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/typescript/compiler/contextualSignatureInstantiation2.ts.prettier-snap +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/compiler/contextualSignatureInstantiation2.ts.prettier-snap @@ -2,7 +2,7 @@ var dot: (f: (_: T) => S) => (g: (_: U) => T) => (_: U) => S; dot = (f: (_: T) => S) => - (g: (_: U) => T): ((r: U) => S) => + (g: (_: U) => T): ((r: U) => S) => (x) => f(g(x)); var id: (x: T) => T; diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/compiler/contextualSignatureInstantiation2.ts.snap b/crates/rome_js_formatter/tests/specs/prettier/typescript/compiler/contextualSignatureInstantiation2.ts.snap new file mode 100644 index 00000000000..618a074c56c --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/compiler/contextualSignatureInstantiation2.ts.snap @@ -0,0 +1,47 @@ +--- +source: crates/rome_formatter_test/src/snapshot_builder.rs +info: typescript/compiler/contextualSignatureInstantiation2.ts +--- + +# Input + +```ts +// dot f g x = f(g(x)) +var dot: (f: (_: T) => S) => (g: (_: U) => T) => (_: U) => S; +dot = (f: (_: T) => S) => (g: (_: U) => T): (r:U) => S => (x) => f(g(x)); +var id: (x:T) => T; +var r23 = dot(id)(id); +``` + + +# Prettier differences + +```diff +--- Prettier ++++ Rome +@@ -2,7 +2,7 @@ + var dot: (f: (_: T) => S) => (g: (_: U) => T) => (_: U) => S; + dot = + (f: (_: T) => S) => +- (g: (_: U) => T): ((r: U) => S) => ++ (g: (_: U) => T): ((r: U) => S) => + (x) => + f(g(x)); + var id: (x: T) => T; +``` + +# Output + +```ts +// dot f g x = f(g(x)) +var dot: (f: (_: T) => S) => (g: (_: U) => T) => (_: U) => S; +dot = + (f: (_: T) => S) => + (g: (_: U) => T): ((r: U) => S) => + (x) => + f(g(x)); +var id: (x: T) => T; +var r23 = dot(id)(id); +``` + + diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/compiler/modifiersOnInterfaceIndexSignature1.ts b/crates/rome_js_formatter/tests/specs/prettier/typescript/compiler/modifiersOnInterfaceIndexSignature1.ts index 212f82bca14..d6dc6783f92 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/typescript/compiler/modifiersOnInterfaceIndexSignature1.ts +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/compiler/modifiersOnInterfaceIndexSignature1.ts @@ -1,3 +1,3 @@ interface I { - public [a: string]: number; -} \ No newline at end of file + [a: string]: number; +} diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/compiler/modifiersOnInterfaceIndexSignature1.ts.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/typescript/compiler/modifiersOnInterfaceIndexSignature1.ts.prettier-snap index 4477daa7d0f..d6dc6783f92 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/typescript/compiler/modifiersOnInterfaceIndexSignature1.ts.prettier-snap +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/compiler/modifiersOnInterfaceIndexSignature1.ts.prettier-snap @@ -1,3 +1,3 @@ interface I { - public [a: string]: number; + [a: string]: number; } diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/conformance/classes/constructorDeclarations/constructorParameters/constructorImplementationWithDefaultValues2.ts.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/typescript/conformance/classes/constructorDeclarations/constructorParameters/constructorImplementationWithDefaultValues2.ts.prettier-snap index 9ef323f20ae..e4d504b1cac 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/typescript/conformance/classes/constructorDeclarations/constructorParameters/constructorImplementationWithDefaultValues2.ts.prettier-snap +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/conformance/classes/constructorDeclarations/constructorParameters/constructorImplementationWithDefaultValues2.ts.prettier-snap @@ -7,7 +7,10 @@ class C { class D { constructor(x: T, y: U); - constructor(x: T = 1, public y: U = x) { + constructor( + x: T = 1, + public y: U = x, + ) { var z = x; } } diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/conformance/classes/constructorDeclarations/constructorParameters/constructorImplementationWithDefaultValues2.ts.snap b/crates/rome_js_formatter/tests/specs/prettier/typescript/conformance/classes/constructorDeclarations/constructorParameters/constructorImplementationWithDefaultValues2.ts.snap new file mode 100644 index 00000000000..bb8e68a5ca5 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/conformance/classes/constructorDeclarations/constructorParameters/constructorImplementationWithDefaultValues2.ts.snap @@ -0,0 +1,76 @@ +--- +source: crates/rome_formatter_test/src/snapshot_builder.rs +info: typescript/conformance/classes/constructorDeclarations/constructorParameters/constructorImplementationWithDefaultValues2.ts +--- + +# Input + +```ts +class C { + constructor(x); + constructor(public x: string = 1) { + var y = x; + } +} + +class D { + constructor(x: T, y: U); + constructor(x: T = 1, public y: U = x) { + var z = x; + } +} + +class E { + constructor(x); + constructor(x: T = new Date()) { + var y = x; + } +} +``` + + +# Prettier differences + +```diff +--- Prettier ++++ Rome +@@ -7,10 +7,7 @@ + + class D { + constructor(x: T, y: U); +- constructor( +- x: T = 1, +- public y: U = x, +- ) { ++ constructor(x: T = 1, public y: U = x) { + var z = x; + } + } +``` + +# Output + +```ts +class C { + constructor(x); + constructor(public x: string = 1) { + var y = x; + } +} + +class D { + constructor(x: T, y: U); + constructor(x: T = 1, public y: U = x) { + var z = x; + } +} + +class E { + constructor(x); + constructor(x: T = new Date()) { + var y = x; + } +} +``` + + diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/conformance/classes/constructorDeclarations/constructorParameters/constructorParameterProperties.ts.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/typescript/conformance/classes/constructorDeclarations/constructorParameters/constructorParameterProperties.ts.prettier-snap index 70aa80cba8d..58c228da174 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/typescript/conformance/classes/constructorDeclarations/constructorParameters/constructorParameterProperties.ts.prettier-snap +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/conformance/classes/constructorDeclarations/constructorParameters/constructorParameterProperties.ts.prettier-snap @@ -1,6 +1,9 @@ class C { y: string; - constructor(private x: string, protected z: string) {} + constructor( + private x: string, + protected z: string, + ) {} } var c: C; @@ -10,7 +13,11 @@ var r3 = c.z; // error class D { y: T; - constructor(a: T, private x: T, protected z: T) {} + constructor( + a: T, + private x: T, + protected z: T, + ) {} } var d: D; diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/conformance/classes/constructorDeclarations/constructorParameters/constructorParameterProperties.ts.snap b/crates/rome_js_formatter/tests/specs/prettier/typescript/conformance/classes/constructorDeclarations/constructorParameters/constructorParameterProperties.ts.snap new file mode 100644 index 00000000000..227f2d5cb17 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/conformance/classes/constructorDeclarations/constructorParameters/constructorParameterProperties.ts.snap @@ -0,0 +1,89 @@ +--- +source: crates/rome_formatter_test/src/snapshot_builder.rs +info: typescript/conformance/classes/constructorDeclarations/constructorParameters/constructorParameterProperties.ts +--- + +# Input + +```ts +class C { + y: string; + constructor(private x: string, protected z: string) { } +} + +var c: C; +var r = c.y; +var r2 = c.x; // error +var r3 = c.z; // error + +class D { + y: T; + constructor(a: T, private x: T, protected z: T) { } +} + +var d: D; +var r = d.y; +var r2 = d.x; // error +var r3 = d.a; // error +var r4 = d.z; // error + +``` + + +# Prettier differences + +```diff +--- Prettier ++++ Rome +@@ -1,9 +1,6 @@ + class C { + y: string; +- constructor( +- private x: string, +- protected z: string, +- ) {} ++ constructor(private x: string, protected z: string) {} + } + + var c: C; +@@ -13,11 +10,7 @@ + + class D { + y: T; +- constructor( +- a: T, +- private x: T, +- protected z: T, +- ) {} ++ constructor(a: T, private x: T, protected z: T) {} + } + + var d: D; +``` + +# Output + +```ts +class C { + y: string; + constructor(private x: string, protected z: string) {} +} + +var c: C; +var r = c.y; +var r2 = c.x; // error +var r3 = c.z; // error + +class D { + y: T; + constructor(a: T, private x: T, protected z: T) {} +} + +var d: D; +var r = d.y; +var r2 = d.x; // error +var r3 = d.a; // error +var r4 = d.z; // error +``` + + diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/conformance/classes/mixinClassesAnnotated.ts.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/typescript/conformance/classes/mixinClassesAnnotated.ts.prettier-snap index eddc57c3991..c29ac725bd9 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/typescript/conformance/classes/mixinClassesAnnotated.ts.prettier-snap +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/conformance/classes/mixinClassesAnnotated.ts.prettier-snap @@ -3,11 +3,18 @@ type Constructor = new (...args: any[]) => T; class Base { - constructor(public x: number, public y: number) {} + constructor( + public x: number, + public y: number, + ) {} } class Derived extends Base { - constructor(x: number, y: number, public z: number) { + constructor( + x: number, + y: number, + public z: number, + ) { super(x, y); } } diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/conformance/classes/mixinClassesAnnotated.ts.snap b/crates/rome_js_formatter/tests/specs/prettier/typescript/conformance/classes/mixinClassesAnnotated.ts.snap new file mode 100644 index 00000000000..0c9f2a63e10 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/conformance/classes/mixinClassesAnnotated.ts.snap @@ -0,0 +1,169 @@ +--- +source: crates/rome_formatter_test/src/snapshot_builder.rs +info: typescript/conformance/classes/mixinClassesAnnotated.ts +--- + +# Input + +```ts +// @declaration: true + +type Constructor = new(...args: any[]) => T; + +class Base { + constructor(public x: number, public y: number) {} +} + +class Derived extends Base { + constructor(x: number, y: number, public z: number) { + super(x, y); + } +} + +const Printable = >(superClass: T): Constructor & { message: string } & T => + class extends superClass { + static message = "hello"; + print() { + const output = this.x + "," + this.y; + } + } + + +function Tagged>(superClass: T): Constructor & T { + class C extends superClass { + _tag: string; + constructor(...args: any[]) { + super(...args); + this._tag = "hello"; + } + } + return C; +} + +const Thing1 = Tagged(Derived); +const Thing2 = Tagged(Printable(Derived)); +Thing2.message; + +function f1() { + const thing = new Thing1(1, 2, 3); + thing.x; + thing._tag; +} + +function f2() { + const thing = new Thing2(1, 2, 3); + thing.x; + thing._tag; + thing.print(); +} + +class Thing3 extends Thing2 { + constructor(tag: string) { + super(10, 20, 30); + this._tag = tag; + } + test() { + this.print(); + } +} + +``` + + +# Prettier differences + +```diff +--- Prettier ++++ Rome +@@ -3,18 +3,11 @@ + type Constructor = new (...args: any[]) => T; + + class Base { +- constructor( +- public x: number, +- public y: number, +- ) {} ++ constructor(public x: number, public y: number) {} + } + + class Derived extends Base { +- constructor( +- x: number, +- y: number, +- public z: number, +- ) { ++ constructor(x: number, y: number, public z: number) { + super(x, y); + } + } +``` + +# Output + +```ts +// @declaration: true + +type Constructor = new (...args: any[]) => T; + +class Base { + constructor(public x: number, public y: number) {} +} + +class Derived extends Base { + constructor(x: number, y: number, public z: number) { + super(x, y); + } +} + +const Printable = >( + superClass: T, +): Constructor & { message: string } & T => + class extends superClass { + static message = "hello"; + print() { + const output = this.x + "," + this.y; + } + }; + +function Tagged>( + superClass: T, +): Constructor & T { + class C extends superClass { + _tag: string; + constructor(...args: any[]) { + super(...args); + this._tag = "hello"; + } + } + return C; +} + +const Thing1 = Tagged(Derived); +const Thing2 = Tagged(Printable(Derived)); +Thing2.message; + +function f1() { + const thing = new Thing1(1, 2, 3); + thing.x; + thing._tag; +} + +function f2() { + const thing = new Thing2(1, 2, 3); + thing.x; + thing._tag; + thing.print(); +} + +class Thing3 extends Thing2 { + constructor(tag: string) { + super(10, 20, 30); + this._tag = tag; + } + test() { + this.print(); + } +} +``` + + diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/conformance/classes/mixinClassesAnonymous.ts.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/typescript/conformance/classes/mixinClassesAnonymous.ts.prettier-snap index 4ca1c5279de..d07b59734fd 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/typescript/conformance/classes/mixinClassesAnonymous.ts.prettier-snap +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/conformance/classes/mixinClassesAnonymous.ts.prettier-snap @@ -1,11 +1,18 @@ type Constructor = new (...args: any[]) => T; class Base { - constructor(public x: number, public y: number) {} + constructor( + public x: number, + public y: number, + ) {} } class Derived extends Base { - constructor(x: number, y: number, public z: number) { + constructor( + x: number, + y: number, + public z: number, + ) { super(x, y); } } diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/conformance/classes/mixinClassesAnonymous.ts.snap b/crates/rome_js_formatter/tests/specs/prettier/typescript/conformance/classes/mixinClassesAnonymous.ts.snap new file mode 100644 index 00000000000..cb56e545505 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/conformance/classes/mixinClassesAnonymous.ts.snap @@ -0,0 +1,175 @@ +--- +source: crates/rome_formatter_test/src/snapshot_builder.rs +info: typescript/conformance/classes/mixinClassesAnonymous.ts +--- + +# Input + +```ts +type Constructor = new(...args: any[]) => T; + +class Base { + constructor(public x: number, public y: number) {} +} + +class Derived extends Base { + constructor(x: number, y: number, public z: number) { + super(x, y); + } +} + +const Printable = >(superClass: T) => class extends superClass { + static message = "hello"; + print() { + const output = this.x + "," + this.y; + } +} + +function Tagged>(superClass: T) { + class C extends superClass { + _tag: string; + constructor(...args: any[]) { + super(...args); + this._tag = "hello"; + } + } + return C; +} + +const Thing1 = Tagged(Derived); +const Thing2 = Tagged(Printable(Derived)); +Thing2.message; + +function f1() { + const thing = new Thing1(1, 2, 3); + thing.x; + thing._tag; +} + +function f2() { + const thing = new Thing2(1, 2, 3); + thing.x; + thing._tag; + thing.print(); +} + +class Thing3 extends Thing2 { + constructor(tag: string) { + super(10, 20, 30); + this._tag = tag; + } + test() { + this.print(); + } +} + +// Repro from #13805 + +const Timestamped = >(Base: CT) => { + return class extends Base { + timestamp = new Date(); + }; +} + +``` + + +# Prettier differences + +```diff +--- Prettier ++++ Rome +@@ -1,18 +1,11 @@ + type Constructor = new (...args: any[]) => T; + + class Base { +- constructor( +- public x: number, +- public y: number, +- ) {} ++ constructor(public x: number, public y: number) {} + } + + class Derived extends Base { +- constructor( +- x: number, +- y: number, +- public z: number, +- ) { ++ constructor(x: number, y: number, public z: number) { + super(x, y); + } + } +``` + +# Output + +```ts +type Constructor = new (...args: any[]) => T; + +class Base { + constructor(public x: number, public y: number) {} +} + +class Derived extends Base { + constructor(x: number, y: number, public z: number) { + super(x, y); + } +} + +const Printable = >(superClass: T) => + class extends superClass { + static message = "hello"; + print() { + const output = this.x + "," + this.y; + } + }; + +function Tagged>(superClass: T) { + class C extends superClass { + _tag: string; + constructor(...args: any[]) { + super(...args); + this._tag = "hello"; + } + } + return C; +} + +const Thing1 = Tagged(Derived); +const Thing2 = Tagged(Printable(Derived)); +Thing2.message; + +function f1() { + const thing = new Thing1(1, 2, 3); + thing.x; + thing._tag; +} + +function f2() { + const thing = new Thing2(1, 2, 3); + thing.x; + thing._tag; + thing.print(); +} + +class Thing3 extends Thing2 { + constructor(tag: string) { + super(10, 20, 30); + this._tag = tag; + } + test() { + this.print(); + } +} + +// Repro from #13805 + +const Timestamped = >(Base: CT) => { + return class extends Base { + timestamp = new Date(); + }; +}; +``` + + diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/conformance/internalModules/importDeclarations/exportImportAlias.ts.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/typescript/conformance/internalModules/importDeclarations/exportImportAlias.ts.prettier-snap index 77f51ffb4e7..0998bd9ba1e 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/typescript/conformance/internalModules/importDeclarations/exportImportAlias.ts.prettier-snap +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/conformance/internalModules/importDeclarations/exportImportAlias.ts.prettier-snap @@ -3,7 +3,10 @@ module A { export var x = "hello world"; export class Point { - constructor(public x: number, public y: number) {} + constructor( + public x: number, + public y: number, + ) {} } export module B { export interface Id { @@ -28,7 +31,10 @@ module X { export module Y { export class Point { - constructor(public x: number, public y: number) {} + constructor( + public x: number, + public y: number, + ) {} } } } diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/conformance/internalModules/importDeclarations/exportImportAlias.ts.snap b/crates/rome_js_formatter/tests/specs/prettier/typescript/conformance/internalModules/importDeclarations/exportImportAlias.ts.snap new file mode 100644 index 00000000000..5252ef7e3b5 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/conformance/internalModules/importDeclarations/exportImportAlias.ts.snap @@ -0,0 +1,182 @@ +--- +source: crates/rome_formatter_test/src/snapshot_builder.rs +info: typescript/conformance/internalModules/importDeclarations/exportImportAlias.ts +--- + +# Input + +```ts +// expect no errors here + +module A { + + export var x = 'hello world' + export class Point { + constructor(public x: number, public y: number) { } + } + export module B { + export interface Id { + name: string; + } + } +} + +module C { + export import a = A; +} + +var a: string = C.a.x; +var b: { x: number; y: number; } = new C.a.Point(0, 0); +var c: { name: string }; +var c: C.a.B.Id; + +module X { + export function Y() { + return 42; + } + + export module Y { + export class Point { + constructor(public x: number, public y: number) { } + } + } +} + +module Z { + + // 'y' should be a fundule here + export import y = X.Y; +} + +var m: number = Z.y(); +var n: { x: number; y: number; } = new Z.y.Point(0, 0); + +module K { + export class L { + constructor(public name: string) { } + } + + export module L { + export var y = 12; + export interface Point { + x: number; + y: number; + } + } +} + +module M { + export import D = K.L; +} + +var o: { name: string }; +var o = new M.D('Hello'); + +var p: { x: number; y: number; } +var p: M.D.Point; +``` + + +# Prettier differences + +```diff +--- Prettier ++++ Rome +@@ -3,10 +3,7 @@ + module A { + export var x = "hello world"; + export class Point { +- constructor( +- public x: number, +- public y: number, +- ) {} ++ constructor(public x: number, public y: number) {} + } + export module B { + export interface Id { +@@ -31,10 +28,7 @@ + + export module Y { + export class Point { +- constructor( +- public x: number, +- public y: number, +- ) {} ++ constructor(public x: number, public y: number) {} + } + } + } +``` + +# Output + +```ts +// expect no errors here + +module A { + export var x = "hello world"; + export class Point { + constructor(public x: number, public y: number) {} + } + export module B { + export interface Id { + name: string; + } + } +} + +module C { + export import a = A; +} + +var a: string = C.a.x; +var b: { x: number; y: number } = new C.a.Point(0, 0); +var c: { name: string }; +var c: C.a.B.Id; + +module X { + export function Y() { + return 42; + } + + export module Y { + export class Point { + constructor(public x: number, public y: number) {} + } + } +} + +module Z { + // 'y' should be a fundule here + export import y = X.Y; +} + +var m: number = Z.y(); +var n: { x: number; y: number } = new Z.y.Point(0, 0); + +module K { + export class L { + constructor(public name: string) {} + } + + export module L { + export var y = 12; + export interface Point { + x: number; + y: number; + } + } +} + +module M { + export import D = K.L; +} + +var o: { name: string }; +var o = new M.D("Hello"); + +var p: { x: number; y: number }; +var p: M.D.Point; +``` + + diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/conformance/internalModules/importDeclarations/importAliasIdentifiers.ts.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/typescript/conformance/internalModules/importDeclarations/importAliasIdentifiers.ts.prettier-snap index 4838d1c71e3..334f684c020 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/typescript/conformance/internalModules/importDeclarations/importAliasIdentifiers.ts.prettier-snap +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/conformance/internalModules/importDeclarations/importAliasIdentifiers.ts.prettier-snap @@ -1,6 +1,9 @@ module moduleA { export class Point { - constructor(public x: number, public y: number) {} + constructor( + public x: number, + public y: number, + ) {} } } diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/conformance/internalModules/importDeclarations/importAliasIdentifiers.ts.snap b/crates/rome_js_formatter/tests/specs/prettier/typescript/conformance/internalModules/importDeclarations/importAliasIdentifiers.ts.snap new file mode 100644 index 00000000000..04dc11a4c2c --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/conformance/internalModules/importDeclarations/importAliasIdentifiers.ts.snap @@ -0,0 +1,128 @@ +--- +source: crates/rome_formatter_test/src/snapshot_builder.rs +info: typescript/conformance/internalModules/importDeclarations/importAliasIdentifiers.ts +--- + +# Input + +```ts +module moduleA { + export class Point { + constructor(public x: number, public y: number) { } + } +} + +import alias = moduleA; + +var p: alias.Point; +var p: moduleA.Point; +var p: { x: number; y: number; }; + +class clodule { + name: string; +} + +module clodule { + export interface Point { + x: number; y: number; + } + var Point: Point = { x: 0, y: 0 }; +} + +import clolias = clodule; + +var p: clolias.Point; +var p: clodule.Point; +var p: { x: number; y: number; }; + + +function fundule() { + return { x: 0, y: 0 }; +} + +module fundule { + export interface Point { + x: number; y: number; + } + var Point: Point = { x: 0, y: 0 }; +} + +import funlias = fundule; + +var p: funlias.Point; +var p: fundule.Point; +var p: { x: number; y: number; }; +``` + + +# Prettier differences + +```diff +--- Prettier ++++ Rome +@@ -1,9 +1,6 @@ + module moduleA { + export class Point { +- constructor( +- public x: number, +- public y: number, +- ) {} ++ constructor(public x: number, public y: number) {} + } + } + +``` + +# Output + +```ts +module moduleA { + export class Point { + constructor(public x: number, public y: number) {} + } +} + +import alias = moduleA; + +var p: alias.Point; +var p: moduleA.Point; +var p: { x: number; y: number }; + +class clodule { + name: string; +} + +module clodule { + export interface Point { + x: number; + y: number; + } + var Point: Point = { x: 0, y: 0 }; +} + +import clolias = clodule; + +var p: clolias.Point; +var p: clodule.Point; +var p: { x: number; y: number }; + +function fundule() { + return { x: 0, y: 0 }; +} + +module fundule { + export interface Point { + x: number; + y: number; + } + var Point: Point = { x: 0, y: 0 }; +} + +import funlias = fundule; + +var p: funlias.Point; +var p: fundule.Point; +var p: { x: number; y: number }; +``` + + diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/conformance/types/moduleDeclaration/kind-detection.ts b/crates/rome_js_formatter/tests/specs/prettier/typescript/conformance/types/moduleDeclaration/kind-detection.ts new file mode 100644 index 00000000000..4796ce701ee --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/conformance/types/moduleDeclaration/kind-detection.ts @@ -0,0 +1 @@ +declare /* module */ namespace A {} diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/conformance/types/moduleDeclaration/kind-detection.ts.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/typescript/conformance/types/moduleDeclaration/kind-detection.ts.prettier-snap new file mode 100644 index 00000000000..26107ea4af6 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/conformance/types/moduleDeclaration/kind-detection.ts.prettier-snap @@ -0,0 +1 @@ +declare namespace /* module */ A {} diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/conformance/types/moduleDeclaration/kind-detection.ts.snap b/crates/rome_js_formatter/tests/specs/prettier/typescript/conformance/types/moduleDeclaration/kind-detection.ts.snap new file mode 100644 index 00000000000..c9b1a3ec7d6 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/conformance/types/moduleDeclaration/kind-detection.ts.snap @@ -0,0 +1,30 @@ +--- +source: crates/rome_formatter_test/src/snapshot_builder.rs +info: typescript/conformance/types/moduleDeclaration/kind-detection.ts +--- + +# Input + +```ts +declare /* module */ namespace A {} + +``` + + +# Prettier differences + +```diff +--- Prettier ++++ Rome +@@ -1 +1 @@ +-declare namespace /* module */ A {} ++declare /* module */ namespace A {} +``` + +# Output + +```ts +declare /* module */ namespace A {} +``` + + diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/conformance/types/parameterProperty/parameterProperty.ts b/crates/rome_js_formatter/tests/specs/prettier/typescript/conformance/types/parameterProperty/parameterProperty.ts index 56527665c17..da1dfa65f59 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/typescript/conformance/types/parameterProperty/parameterProperty.ts +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/conformance/types/parameterProperty/parameterProperty.ts @@ -1,7 +1,5 @@ -class c3 { +class A { constructor(public arg: number = 10) { // fails because of comment } - not_constructor(public arg: number = 10) { - } } diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/conformance/types/parameterProperty/parameterProperty.ts.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/typescript/conformance/types/parameterProperty/parameterProperty.ts.prettier-snap index 406728f653c..da1dfa65f59 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/typescript/conformance/types/parameterProperty/parameterProperty.ts.prettier-snap +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/conformance/types/parameterProperty/parameterProperty.ts.prettier-snap @@ -1,6 +1,5 @@ -class c3 { +class A { constructor(public arg: number = 10) { // fails because of comment } - not_constructor(public arg: number = 10) {} } diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/conformance/types/parameterProperty/parameterProperty.ts.snap b/crates/rome_js_formatter/tests/specs/prettier/typescript/conformance/types/parameterProperty/parameterProperty.ts.snap deleted file mode 100644 index a7fe8647cbd..00000000000 --- a/crates/rome_js_formatter/tests/specs/prettier/typescript/conformance/types/parameterProperty/parameterProperty.ts.snap +++ /dev/null @@ -1,77 +0,0 @@ ---- -source: crates/rome_formatter_test/src/snapshot_builder.rs -assertion_line: 212 -info: typescript/conformance/types/parameterProperty/parameterProperty.ts ---- - -# Input - -```ts -class c3 { - constructor(public arg: number = 10) { - // fails because of comment - } - not_constructor(public arg: number = 10) { - } -} - -``` - - -# Prettier differences - -```diff ---- Prettier -+++ Rome -@@ -2,5 +2,6 @@ - constructor(public arg: number = 10) { - // fails because of comment - } -- not_constructor(public arg: number = 10) {} -+ not_constructor(public arg: number = 10) { -+ } - } -``` - -# Output - -```ts -class c3 { - constructor(public arg: number = 10) { - // fails because of comment - } - not_constructor(public arg: number = 10) { - } -} -``` - -# Errors -``` -parameterProperty.ts:5:19 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - - × Illegal use of reserved keyword `public` as an identifier in strict mode - - 3 │ // fails because of comment - 4 │ } - > 5 │ not_constructor(public arg: number = 10) { - │ ^^^^^^ - 6 │ } - 7 │ } - -parameterProperty.ts:5:26 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - - × expected `,` but instead found `arg` - - 3 │ // fails because of comment - 4 │ } - > 5 │ not_constructor(public arg: number = 10) { - │ ^^^ - 6 │ } - 7 │ } - - i Remove arg - - -``` - - diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/const/initializer-ambient-context.ts b/crates/rome_js_formatter/tests/specs/prettier/typescript/const/initializer-ambient-context.ts new file mode 100644 index 00000000000..4571e8b96f0 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/const/initializer-ambient-context.ts @@ -0,0 +1,15 @@ +declare module N { + enum E { + ok = 0 + } + + export const string = "2"; + export const number = 1.; + export const bigint = 0n; + export const negative_bigint = -0n; + export const negative_number = -1; + export const template = `-2`; + export const False = false; + export const True = true; + export const E_ok = E.ok; +} diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/const/initializer-ambient-context.ts.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/typescript/const/initializer-ambient-context.ts.prettier-snap new file mode 100644 index 00000000000..587f1bad8de --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/const/initializer-ambient-context.ts.prettier-snap @@ -0,0 +1,15 @@ +declare module N { + enum E { + ok = 0, + } + + export const string = "2"; + export const number = 1; + export const bigint = 0n; + export const negative_bigint = -0n; + export const negative_number = -1; + export const template = `-2`; + export const False = false; + export const True = true; + export const E_ok = E.ok; +} diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/cursor/array-pattern.ts b/crates/rome_js_formatter/tests/specs/prettier/typescript/cursor/array-pattern.ts new file mode 100644 index 00000000000..66a13057742 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/cursor/array-pattern.ts @@ -0,0 +1 @@ +let []<|>: T = []; diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/cursor/array-pattern.ts.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/typescript/cursor/array-pattern.ts.prettier-snap new file mode 100644 index 00000000000..66a13057742 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/cursor/array-pattern.ts.prettier-snap @@ -0,0 +1 @@ +let []<|>: T = []; diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/cursor/arrow-function-type.ts b/crates/rome_js_formatter/tests/specs/prettier/typescript/cursor/arrow-function-type.ts new file mode 100644 index 00000000000..f01f75102b7 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/cursor/arrow-function-type.ts @@ -0,0 +1 @@ +type foo = () <|>=> boolean; diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/cursor/arrow-function-type.ts.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/typescript/cursor/arrow-function-type.ts.prettier-snap new file mode 100644 index 00000000000..f01f75102b7 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/cursor/arrow-function-type.ts.prettier-snap @@ -0,0 +1 @@ +type foo = () <|>=> boolean; diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/cursor/class-property.ts b/crates/rome_js_formatter/tests/specs/prettier/typescript/cursor/class-property.ts new file mode 100644 index 00000000000..a635c6b282e --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/cursor/class-property.ts @@ -0,0 +1,3 @@ +class A { + foo<|>: A +} diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/cursor/class-property.ts.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/typescript/cursor/class-property.ts.prettier-snap new file mode 100644 index 00000000000..af4d202e155 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/cursor/class-property.ts.prettier-snap @@ -0,0 +1,3 @@ +class A { + foo<|>: A; +} diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/cursor/function-return-type.ts b/crates/rome_js_formatter/tests/specs/prettier/typescript/cursor/function-return-type.ts new file mode 100644 index 00000000000..0681246bf6a --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/cursor/function-return-type.ts @@ -0,0 +1 @@ +function a()<|>: boolean {} diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/cursor/function-return-type.ts.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/typescript/cursor/function-return-type.ts.prettier-snap new file mode 100644 index 00000000000..0681246bf6a --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/cursor/function-return-type.ts.prettier-snap @@ -0,0 +1 @@ +function a()<|>: boolean {} diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/cursor/identifier-1.ts b/crates/rome_js_formatter/tests/specs/prettier/typescript/cursor/identifier-1.ts new file mode 100644 index 00000000000..0304fd3c7e3 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/cursor/identifier-1.ts @@ -0,0 +1 @@ +let i<|>: T; diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/cursor/identifier-1.ts.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/typescript/cursor/identifier-1.ts.prettier-snap new file mode 100644 index 00000000000..0304fd3c7e3 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/cursor/identifier-1.ts.prettier-snap @@ -0,0 +1 @@ +let i<|>: T; diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/cursor/identifier-2.ts b/crates/rome_js_formatter/tests/specs/prettier/typescript/cursor/identifier-2.ts new file mode 100644 index 00000000000..21f30ea35d2 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/cursor/identifier-2.ts @@ -0,0 +1 @@ +let i:<|> T; diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/cursor/identifier-2.ts.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/typescript/cursor/identifier-2.ts.prettier-snap new file mode 100644 index 00000000000..21f30ea35d2 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/cursor/identifier-2.ts.prettier-snap @@ -0,0 +1 @@ +let i:<|> T; diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/cursor/identifier-3.ts b/crates/rome_js_formatter/tests/specs/prettier/typescript/cursor/identifier-3.ts new file mode 100644 index 00000000000..5c58b23f452 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/cursor/identifier-3.ts @@ -0,0 +1 @@ +let i<|> : T; diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/cursor/identifier-3.ts.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/typescript/cursor/identifier-3.ts.prettier-snap new file mode 100644 index 00000000000..0304fd3c7e3 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/cursor/identifier-3.ts.prettier-snap @@ -0,0 +1 @@ +let i<|>: T; diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/cursor/method-signature.ts b/crates/rome_js_formatter/tests/specs/prettier/typescript/cursor/method-signature.ts new file mode 100644 index 00000000000..06c2aa95e0a --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/cursor/method-signature.ts @@ -0,0 +1,3 @@ +interface A { + foo()<|>: T; +} diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/cursor/method-signature.ts.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/typescript/cursor/method-signature.ts.prettier-snap new file mode 100644 index 00000000000..06c2aa95e0a --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/cursor/method-signature.ts.prettier-snap @@ -0,0 +1,3 @@ +interface A { + foo()<|>: T; +} diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/cursor/property-signature.ts b/crates/rome_js_formatter/tests/specs/prettier/typescript/cursor/property-signature.ts new file mode 100644 index 00000000000..4c9b7f8ed93 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/cursor/property-signature.ts @@ -0,0 +1,3 @@ +interface A { + foo<|>: T; +} diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/cursor/property-signature.ts.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/typescript/cursor/property-signature.ts.prettier-snap new file mode 100644 index 00000000000..4c9b7f8ed93 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/cursor/property-signature.ts.prettier-snap @@ -0,0 +1,3 @@ +interface A { + foo<|>: T; +} diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/cursor/rest.ts b/crates/rome_js_formatter/tests/specs/prettier/typescript/cursor/rest.ts new file mode 100644 index 00000000000..3e48a8041b4 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/cursor/rest.ts @@ -0,0 +1 @@ +function foo(...args<|>: any) { } diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/cursor/rest.ts.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/typescript/cursor/rest.ts.prettier-snap new file mode 100644 index 00000000000..62b046cb7ed --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/cursor/rest.ts.prettier-snap @@ -0,0 +1 @@ +function foo(...args<|>: any) {} diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/declare/object-type-in-declare-function.ts b/crates/rome_js_formatter/tests/specs/prettier/typescript/declare/object-type-in-declare-function.ts new file mode 100644 index 00000000000..b9c8b00db77 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/declare/object-type-in-declare-function.ts @@ -0,0 +1,11 @@ +declare function foo(this: { a: boolean, b: string, c: number }): + Promise> + +declare function bazFlip({ a: boolean, b: string, c: number }): + Promise> + +declare function bar(...{ a: boolean, b: string, c: number }): + Promise> + +declare function bar(...x: { a: boolean, b: string, c: number }): + Promise> diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/declare/object-type-in-declare-function.ts.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/typescript/declare/object-type-in-declare-function.ts.prettier-snap new file mode 100644 index 00000000000..2337ccc1b37 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/declare/object-type-in-declare-function.ts.prettier-snap @@ -0,0 +1,19 @@ +declare function foo(this: { + a: boolean; + b: string; + c: number; +}): Promise>; + +declare function bazFlip({ + a: boolean, + b: string, + c: number, +}): Promise>; + +declare function bar( + ...{ a: boolean, b: string, c: number } +): Promise>; + +declare function bar( + ...x: { a: boolean; b: string; c: number } +): Promise>; diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/declare/object-type-in-declare-function.ts.snap b/crates/rome_js_formatter/tests/specs/prettier/typescript/declare/object-type-in-declare-function.ts.snap new file mode 100644 index 00000000000..1a6cb5b88f4 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/declare/object-type-in-declare-function.ts.snap @@ -0,0 +1,65 @@ +--- +source: crates/rome_formatter_test/src/snapshot_builder.rs +info: typescript/declare/object-type-in-declare-function.ts +--- + +# Input + +```ts +declare function foo(this: { a: boolean, b: string, c: number }): + Promise> + +declare function bazFlip({ a: boolean, b: string, c: number }): + Promise> + +declare function bar(...{ a: boolean, b: string, c: number }): + Promise> + +declare function bar(...x: { a: boolean, b: string, c: number }): + Promise> + +``` + + +# Prettier differences + +```diff +--- Prettier ++++ Rome +@@ -1,8 +1,6 @@ +-declare function foo(this: { +- a: boolean; +- b: string; +- c: number; +-}): Promise>; ++declare function foo(this: { a: boolean; b: string; c: number }): Promise< ++ Array ++>; + + declare function bazFlip({ + a: boolean, +``` + +# Output + +```ts +declare function foo(this: { a: boolean; b: string; c: number }): Promise< + Array +>; + +declare function bazFlip({ + a: boolean, + b: string, + c: number, +}): Promise>; + +declare function bar( + ...{ a: boolean, b: string, c: number } +): Promise>; + +declare function bar( + ...x: { a: boolean; b: string; c: number } +): Promise>; +``` + + diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/decorator-auto-accessors/decorator-auto-accessors-new-line.ts b/crates/rome_js_formatter/tests/specs/prettier/typescript/decorator-auto-accessors/decorator-auto-accessors-new-line.ts new file mode 100644 index 00000000000..084a69a6023 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/decorator-auto-accessors/decorator-auto-accessors-new-line.ts @@ -0,0 +1,14 @@ +class Foo { + accessor + ["bar"]; +} + +class Foo { + static accessor + bar; +} + +class Foo { + accessor + bar; +} diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/decorator-auto-accessors/decorator-auto-accessors-new-line.ts.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/typescript/decorator-auto-accessors/decorator-auto-accessors-new-line.ts.prettier-snap new file mode 100644 index 00000000000..92737d96867 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/decorator-auto-accessors/decorator-auto-accessors-new-line.ts.prettier-snap @@ -0,0 +1,14 @@ +class Foo { + accessor; + ["bar"]; +} + +class Foo { + static accessor; + bar; +} + +class Foo { + accessor; + bar; +} diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/decorator-auto-accessors/no-semi/decorator-auto-accessor-like-property-name.ts b/crates/rome_js_formatter/tests/specs/prettier/typescript/decorator-auto-accessors/no-semi/decorator-auto-accessor-like-property-name.ts new file mode 100644 index 00000000000..e69e9775af7 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/decorator-auto-accessors/no-semi/decorator-auto-accessor-like-property-name.ts @@ -0,0 +1,4 @@ +class C { + accessor; + bar; +} diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/decorator-auto-accessors/no-semi/decorator-auto-accessor-like-property-name.ts.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/typescript/decorator-auto-accessors/no-semi/decorator-auto-accessor-like-property-name.ts.prettier-snap new file mode 100644 index 00000000000..e69e9775af7 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/decorator-auto-accessors/no-semi/decorator-auto-accessor-like-property-name.ts.prettier-snap @@ -0,0 +1,4 @@ +class C { + accessor; + bar; +} diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/decorators/legacy.ts.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/typescript/decorators/legacy.ts.prettier-snap index 131442a2bef..c39806ff86e 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/typescript/decorators/legacy.ts.prettier-snap +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/decorators/legacy.ts.prettier-snap @@ -1,12 +1,8 @@ [ - ( - @decorator() - class {} - ), - ( - @decorator() - class A {} - ), + @decorator() + class {}, + @decorator() + class A {}, ]; class A { diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/decorators/legacy.ts.snap b/crates/rome_js_formatter/tests/specs/prettier/typescript/decorators/legacy.ts.snap new file mode 100644 index 00000000000..6b60f6e796a --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/decorators/legacy.ts.snap @@ -0,0 +1,72 @@ +--- +source: crates/rome_formatter_test/src/snapshot_builder.rs +info: typescript/decorators/legacy.ts +--- + +# Input + +```ts +[ + @decorator() class {}, + @decorator() class A {}, +]; + +class A { + @decorator() accessor #field; +} + +class B { + @decorator() #field () {} +} + +``` + + +# Prettier differences + +```diff +--- Prettier ++++ Rome +@@ -1,8 +1,12 @@ + [ +- @decorator() +- class {}, +- @decorator() +- class A {}, ++ ( ++ @decorator() ++ class {} ++ ), ++ ( ++ @decorator() ++ class A {} ++ ), + ]; + + class A { +``` + +# Output + +```ts +[ + ( + @decorator() + class {} + ), + ( + @decorator() + class A {} + ), +]; + +class A { + @decorator() accessor #field; +} + +class B { + @decorator() #field() {} +} +``` + + diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/function-type/consistent.ts b/crates/rome_js_formatter/tests/specs/prettier/typescript/function-type/consistent.ts new file mode 100644 index 00000000000..bb661226cd8 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/function-type/consistent.ts @@ -0,0 +1,25 @@ +// TSFunctionType +type A = ( + tpl: TemplateStringsArray, + ...args: Array +) => (replacements?: PublicReplacements) => T; + +// TSConstructorType +type B = new ( + tpl: TemplateStringsArray, + ...args: Array +) => (replacements?: PublicReplacements) => T; + +type X = { + // TSCallSignatureDeclaration + ( + tpl: TemplateStringsArray, + ...args: Array + ): (replacements?: PublicReplacements) => T; + + // TSConstructSignatureDeclaration + new ( + tpl: TemplateStringsArray, + ...args: Array + ): (replacements?: PublicReplacements) => T; +}; diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/function-type/consistent.ts.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/typescript/function-type/consistent.ts.prettier-snap new file mode 100644 index 00000000000..bb661226cd8 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/function-type/consistent.ts.prettier-snap @@ -0,0 +1,25 @@ +// TSFunctionType +type A = ( + tpl: TemplateStringsArray, + ...args: Array +) => (replacements?: PublicReplacements) => T; + +// TSConstructorType +type B = new ( + tpl: TemplateStringsArray, + ...args: Array +) => (replacements?: PublicReplacements) => T; + +type X = { + // TSCallSignatureDeclaration + ( + tpl: TemplateStringsArray, + ...args: Array + ): (replacements?: PublicReplacements) => T; + + // TSConstructSignatureDeclaration + new ( + tpl: TemplateStringsArray, + ...args: Array + ): (replacements?: PublicReplacements) => T; +}; diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/function-type/consistent.ts.snap b/crates/rome_js_formatter/tests/specs/prettier/typescript/function-type/consistent.ts.snap new file mode 100644 index 00000000000..fda1f0a796d --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/function-type/consistent.ts.snap @@ -0,0 +1,94 @@ +--- +source: crates/rome_formatter_test/src/snapshot_builder.rs +info: typescript/function-type/consistent.ts +--- + +# Input + +```ts +// TSFunctionType +type A = ( + tpl: TemplateStringsArray, + ...args: Array +) => (replacements?: PublicReplacements) => T; + +// TSConstructorType +type B = new ( + tpl: TemplateStringsArray, + ...args: Array +) => (replacements?: PublicReplacements) => T; + +type X = { + // TSCallSignatureDeclaration + ( + tpl: TemplateStringsArray, + ...args: Array + ): (replacements?: PublicReplacements) => T; + + // TSConstructSignatureDeclaration + new ( + tpl: TemplateStringsArray, + ...args: Array + ): (replacements?: PublicReplacements) => T; +}; + +``` + + +# Prettier differences + +```diff +--- Prettier ++++ Rome +@@ -12,14 +12,12 @@ + + type X = { + // TSCallSignatureDeclaration +- ( +- tpl: TemplateStringsArray, +- ...args: Array +- ): (replacements?: PublicReplacements) => T; ++ (tpl: TemplateStringsArray, ...args: Array): ( ++ replacements?: PublicReplacements, ++ ) => T; + + // TSConstructSignatureDeclaration +- new ( +- tpl: TemplateStringsArray, +- ...args: Array +- ): (replacements?: PublicReplacements) => T; ++ new (tpl: TemplateStringsArray, ...args: Array): ( ++ replacements?: PublicReplacements, ++ ) => T; + }; +``` + +# Output + +```ts +// TSFunctionType +type A = ( + tpl: TemplateStringsArray, + ...args: Array +) => (replacements?: PublicReplacements) => T; + +// TSConstructorType +type B = new ( + tpl: TemplateStringsArray, + ...args: Array +) => (replacements?: PublicReplacements) => T; + +type X = { + // TSCallSignatureDeclaration + (tpl: TemplateStringsArray, ...args: Array): ( + replacements?: PublicReplacements, + ) => T; + + // TSConstructSignatureDeclaration + new (tpl: TemplateStringsArray, ...args: Array): ( + replacements?: PublicReplacements, + ) => T; +}; +``` + + diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/interface2/break/break.ts b/crates/rome_js_formatter/tests/specs/prettier/typescript/interface2/break/break.ts new file mode 100644 index 00000000000..3bf95b1df83 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/interface2/break/break.ts @@ -0,0 +1,66 @@ +export interface Environment1 extends GenericEnvironment< + SomeType, + AnotherType, + YetAnotherType, +> { + m(): void; +}; +export class Environment2 extends GenericEnvironment< + SomeType, + AnotherType, + YetAnotherType, + DifferentType1, + DifferentType2, + DifferentType3, + DifferentType4, +> { + m() {}; +}; + +// Declare Interface Break +declare interface ExtendsOne extends ASingleInterface { + x: string; +} + +declare interface ExtendsLarge extends ASingleInterfaceWithAReallyReallyReallyReallyLongName { + x: string; +} + +declare interface ExtendsMany extends Interface1, Interface2, Interface3, Interface4, Interface5, Interface6, Interface7 { + x: string; +} + +// Interface declaration break +interface ExtendsOne extends ASingleInterface { + x: string; +} + +interface ExtendsLarge extends ASingleInterfaceWithAReallyReallyReallyReallyLongName { + x: string; +} + +interface ExtendsMany extends Interface1, Interface2, Interface3, Interface4, Interface5, Interface6, Interface7 { + s: string; +} + +// Generic Types +interface ExtendsOne extends ASingleInterface { + x: string; +} + +interface ExtendsLarge extends ASingleInterfaceWithAReallyReallyReallyReallyLongName { + x: string; +} + +interface ExtendsMany + extends ASingleGenericInterface { + x: string; +} + +interface ExtendsManyWithGenerics + extends InterfaceOne, InterfaceTwo, ASingleGenericInterface, InterfaceThree { + + x: string; + } + +export interface ExtendsLongOneWithGenerics extends Bar< SomeLongTypeSomeLongTypeSomeLongTypeSomeLongType, ToBreakLineToBreakLineToBreakLine> {} diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/interface2/break/break.ts.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/typescript/interface2/break/break.ts.prettier-snap new file mode 100644 index 00000000000..494ce0478df --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/interface2/break/break.ts.prettier-snap @@ -0,0 +1,102 @@ +export interface Environment1 + extends GenericEnvironment { + m(): void; +} +export class Environment2 extends GenericEnvironment< + SomeType, + AnotherType, + YetAnotherType, + DifferentType1, + DifferentType2, + DifferentType3, + DifferentType4 +> { + m() {} +} + +// Declare Interface Break +declare interface ExtendsOne extends ASingleInterface { + x: string; +} + +declare interface ExtendsLarge + extends ASingleInterfaceWithAReallyReallyReallyReallyLongName { + x: string; +} + +declare interface ExtendsMany + extends Interface1, + Interface2, + Interface3, + Interface4, + Interface5, + Interface6, + Interface7 { + x: string; +} + +// Interface declaration break +interface ExtendsOne extends ASingleInterface { + x: string; +} + +interface ExtendsLarge + extends ASingleInterfaceWithAReallyReallyReallyReallyLongName { + x: string; +} + +interface ExtendsMany + extends Interface1, + Interface2, + Interface3, + Interface4, + Interface5, + Interface6, + Interface7 { + s: string; +} + +// Generic Types +interface ExtendsOne extends ASingleInterface { + x: string; +} + +interface ExtendsLarge + extends ASingleInterfaceWithAReallyReallyReallyReallyLongName { + x: string; +} + +interface ExtendsMany + extends ASingleGenericInterface< + Interface1, + Interface2, + Interface3, + Interface4, + Interface5, + Interface6, + Interface7 + > { + x: string; +} + +interface ExtendsManyWithGenerics + extends InterfaceOne, + InterfaceTwo, + ASingleGenericInterface< + Interface1, + Interface2, + Interface3, + Interface4, + Interface5, + Interface6, + Interface7 + >, + InterfaceThree { + x: string; +} + +export interface ExtendsLongOneWithGenerics + extends Bar< + SomeLongTypeSomeLongTypeSomeLongTypeSomeLongType, + ToBreakLineToBreakLineToBreakLine + > {} diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/interface2/break/break.ts.snap b/crates/rome_js_formatter/tests/specs/prettier/typescript/interface2/break/break.ts.snap new file mode 100644 index 00000000000..08731a495ba --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/interface2/break/break.ts.snap @@ -0,0 +1,264 @@ +--- +source: crates/rome_formatter_test/src/snapshot_builder.rs +info: typescript/interface2/break/break.ts +--- + +# Input + +```ts +export interface Environment1 extends GenericEnvironment< + SomeType, + AnotherType, + YetAnotherType, +> { + m(): void; +}; +export class Environment2 extends GenericEnvironment< + SomeType, + AnotherType, + YetAnotherType, + DifferentType1, + DifferentType2, + DifferentType3, + DifferentType4, +> { + m() {}; +}; + +// Declare Interface Break +declare interface ExtendsOne extends ASingleInterface { + x: string; +} + +declare interface ExtendsLarge extends ASingleInterfaceWithAReallyReallyReallyReallyLongName { + x: string; +} + +declare interface ExtendsMany extends Interface1, Interface2, Interface3, Interface4, Interface5, Interface6, Interface7 { + x: string; +} + +// Interface declaration break +interface ExtendsOne extends ASingleInterface { + x: string; +} + +interface ExtendsLarge extends ASingleInterfaceWithAReallyReallyReallyReallyLongName { + x: string; +} + +interface ExtendsMany extends Interface1, Interface2, Interface3, Interface4, Interface5, Interface6, Interface7 { + s: string; +} + +// Generic Types +interface ExtendsOne extends ASingleInterface { + x: string; +} + +interface ExtendsLarge extends ASingleInterfaceWithAReallyReallyReallyReallyLongName { + x: string; +} + +interface ExtendsMany + extends ASingleGenericInterface { + x: string; +} + +interface ExtendsManyWithGenerics + extends InterfaceOne, InterfaceTwo, ASingleGenericInterface, InterfaceThree { + + x: string; + } + +export interface ExtendsLongOneWithGenerics extends Bar< SomeLongTypeSomeLongTypeSomeLongTypeSomeLongType, ToBreakLineToBreakLineToBreakLine> {} + +``` + + +# Prettier differences + +```diff +--- Prettier ++++ Rome +@@ -1,5 +1,8 @@ +-export interface Environment1 +- extends GenericEnvironment { ++export interface Environment1 extends GenericEnvironment< ++ SomeType, ++ AnotherType, ++ YetAnotherType, ++> { + m(): void; + } + export class Environment2 extends GenericEnvironment< +@@ -9,9 +12,9 @@ + DifferentType1, + DifferentType2, + DifferentType3, +- DifferentType4 ++ DifferentType4, + > { +- m() {} ++ m() {}; + } + + // Declare Interface Break +``` + +# Output + +```ts +export interface Environment1 extends GenericEnvironment< + SomeType, + AnotherType, + YetAnotherType, +> { + m(): void; +} +export class Environment2 extends GenericEnvironment< + SomeType, + AnotherType, + YetAnotherType, + DifferentType1, + DifferentType2, + DifferentType3, + DifferentType4, +> { + m() {}; +} + +// Declare Interface Break +declare interface ExtendsOne extends ASingleInterface { + x: string; +} + +declare interface ExtendsLarge + extends ASingleInterfaceWithAReallyReallyReallyReallyLongName { + x: string; +} + +declare interface ExtendsMany + extends Interface1, + Interface2, + Interface3, + Interface4, + Interface5, + Interface6, + Interface7 { + x: string; +} + +// Interface declaration break +interface ExtendsOne extends ASingleInterface { + x: string; +} + +interface ExtendsLarge + extends ASingleInterfaceWithAReallyReallyReallyReallyLongName { + x: string; +} + +interface ExtendsMany + extends Interface1, + Interface2, + Interface3, + Interface4, + Interface5, + Interface6, + Interface7 { + s: string; +} + +// Generic Types +interface ExtendsOne extends ASingleInterface { + x: string; +} + +interface ExtendsLarge + extends ASingleInterfaceWithAReallyReallyReallyReallyLongName { + x: string; +} + +interface ExtendsMany + extends ASingleGenericInterface< + Interface1, + Interface2, + Interface3, + Interface4, + Interface5, + Interface6, + Interface7 + > { + x: string; +} + +interface ExtendsManyWithGenerics + extends InterfaceOne, + InterfaceTwo, + ASingleGenericInterface< + Interface1, + Interface2, + Interface3, + Interface4, + Interface5, + Interface6, + Interface7 + >, + InterfaceThree { + x: string; +} + +export interface ExtendsLongOneWithGenerics + extends Bar< + SomeLongTypeSomeLongTypeSomeLongTypeSomeLongType, + ToBreakLineToBreakLineToBreakLine + > {} +``` + +# Errors +``` +break.ts:5:1 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × expected a type parameter but instead found '>' + + 3 │ AnotherType, + 4 │ YetAnotherType, + > 5 │ > { + │ ^ + 6 │ m(): void; + 7 │ }; + + i Expected a type parameter here + + 3 │ AnotherType, + 4 │ YetAnotherType, + > 5 │ > { + │ ^ + 6 │ m(): void; + 7 │ }; + +break.ts:16:1 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × expected a type parameter but instead found '>' + + 14 │ DifferentType3, + 15 │ DifferentType4, + > 16 │ > { + │ ^ + 17 │ m() {}; + 18 │ }; + + i Expected a type parameter here + + 14 │ DifferentType3, + 15 │ DifferentType4, + > 16 │ > { + │ ^ + 17 │ m() {}; + 18 │ }; + + +``` + + diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/intersection/consistent-with-flow/comment.ts b/crates/rome_js_formatter/tests/specs/prettier/typescript/intersection/consistent-with-flow/comment.ts new file mode 100644 index 00000000000..ecc2f934ea0 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/intersection/consistent-with-flow/comment.ts @@ -0,0 +1,4 @@ +type A1 = /* 4 */ ( + & A + & B +)[] diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/intersection/consistent-with-flow/comment.ts.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/typescript/intersection/consistent-with-flow/comment.ts.prettier-snap new file mode 100644 index 00000000000..88704d3b064 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/intersection/consistent-with-flow/comment.ts.prettier-snap @@ -0,0 +1 @@ +type A1 = /* 4 */ (A & B)[]; diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/intersection/consistent-with-flow/intersection-parens.ts b/crates/rome_js_formatter/tests/specs/prettier/typescript/intersection/consistent-with-flow/intersection-parens.ts new file mode 100644 index 00000000000..b19671acd12 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/intersection/consistent-with-flow/intersection-parens.ts @@ -0,0 +1,43 @@ +type A = (number | string) & boolean; +type B = ((number | string)) & boolean; +type C = (((number | string))) & boolean; +type D = ((((number | string)))) & boolean; + +let b1 : C; +let b2 : & C; +let b3 : (& C); +let b4 : & (C); +let b5 : (& (C)); +let b6 : /*1*/ & C; +let b7 : /*1*/ & (C); +let b8 : /*1*/ (& C); +let b9 : (/*1*/ & C); +let b10: /*1*/ & /*2*/ C; +let b11: /*1*/ (& /*2*/ C); + +let bb1: /*1*/ & /*2*/ C & D; +let bb2: /*1*/ & /*2*/ C & /*3*/ D; +let bb3: /*1*/ & /*2*/ C & /*3*/ D /*5*/; + +type B2 = & C; +type B3 = (& C); +type B4 = & (C); +type B5 = (& (C)); +type B6 = /*1*/ & C; +type B7 = /*1*/ & (C); +type B8 = /*1*/ (& C); +type B9 = (/*1*/ & C); +type B10 = /*1*/ & /*2*/ C; +type B11 = /*1*/ (& /*2*/ C); +type B12 = /*1*/ & ( (C)); + +type Bb1 = /*1*/ & /*2*/ C & D; +type Bb2 = /*1*/ & /*2*/ C & /*3*/ D; +type Bb3 = /*1*/ & /*2*/ C & /*3*/ D /*4*/; + +type D1 = /*1*/ | a & b; +type D2 = /*1*/ | a & (b); +type D3 = /*1*/ | a & (| b); +type D4 = /*1*/ | (a & b); +type D5 = /*1*/ (| a & b); +type D6 /*0*/ = /*1*/ (| a & b); diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/intersection/consistent-with-flow/intersection-parens.ts.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/typescript/intersection/consistent-with-flow/intersection-parens.ts.prettier-snap new file mode 100644 index 00000000000..084d74d9a4a --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/intersection/consistent-with-flow/intersection-parens.ts.prettier-snap @@ -0,0 +1,43 @@ +type A = (number | string) & boolean; +type B = (number | string) & boolean; +type C = (number | string) & boolean; +type D = (number | string) & boolean; + +let b1: C; +let b2: C; +let b3: C; +let b4: C; +let b5: C; +let b6: /*1*/ C; +let b7: /*1*/ C; +let b8: /*1*/ C; +let b9: /*1*/ C; +let b10: /*1*/ /*2*/ C; +let b11: /*1*/ /*2*/ C; + +let bb1: /*1*/ /*2*/ C & D; +let bb2: /*1*/ /*2*/ C & /*3*/ D; +let bb3: /*1*/ /*2*/ C & /*3*/ D /*5*/; + +type B2 = C; +type B3 = C; +type B4 = C; +type B5 = C; +type B6 /*1*/ = C; +type B7 /*1*/ = C; +type B8 /*1*/ = C; +type B9 /*1*/ = C; +type B10 /*1*/ = /*2*/ C; +type B11 /*1*/ = /*2*/ C; +type B12 /*1*/ = C; + +type Bb1 = /*1*/ /*2*/ C & D; +type Bb2 = /*1*/ /*2*/ C & /*3*/ D; +type Bb3 = /*1*/ /*2*/ C & /*3*/ D /*4*/; + +type D1 /*1*/ = a & b; +type D2 /*1*/ = a & b; +type D3 /*1*/ = a & b; +type D4 /*1*/ = a & b; +type D5 /*1*/ = a & b; +type D6 /*0*/ /*1*/ = a & b; diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/intersection/consistent-with-flow/intersection-parens.ts.snap b/crates/rome_js_formatter/tests/specs/prettier/typescript/intersection/consistent-with-flow/intersection-parens.ts.snap new file mode 100644 index 00000000000..7035ddd4d2b --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/intersection/consistent-with-flow/intersection-parens.ts.snap @@ -0,0 +1,146 @@ +--- +source: crates/rome_formatter_test/src/snapshot_builder.rs +info: typescript/intersection/consistent-with-flow/intersection-parens.ts +--- + +# Input + +```ts +type A = (number | string) & boolean; +type B = ((number | string)) & boolean; +type C = (((number | string))) & boolean; +type D = ((((number | string)))) & boolean; + +let b1 : C; +let b2 : & C; +let b3 : (& C); +let b4 : & (C); +let b5 : (& (C)); +let b6 : /*1*/ & C; +let b7 : /*1*/ & (C); +let b8 : /*1*/ (& C); +let b9 : (/*1*/ & C); +let b10: /*1*/ & /*2*/ C; +let b11: /*1*/ (& /*2*/ C); + +let bb1: /*1*/ & /*2*/ C & D; +let bb2: /*1*/ & /*2*/ C & /*3*/ D; +let bb3: /*1*/ & /*2*/ C & /*3*/ D /*5*/; + +type B2 = & C; +type B3 = (& C); +type B4 = & (C); +type B5 = (& (C)); +type B6 = /*1*/ & C; +type B7 = /*1*/ & (C); +type B8 = /*1*/ (& C); +type B9 = (/*1*/ & C); +type B10 = /*1*/ & /*2*/ C; +type B11 = /*1*/ (& /*2*/ C); +type B12 = /*1*/ & ( (C)); + +type Bb1 = /*1*/ & /*2*/ C & D; +type Bb2 = /*1*/ & /*2*/ C & /*3*/ D; +type Bb3 = /*1*/ & /*2*/ C & /*3*/ D /*4*/; + +type D1 = /*1*/ | a & b; +type D2 = /*1*/ | a & (b); +type D3 = /*1*/ | a & (| b); +type D4 = /*1*/ | (a & b); +type D5 = /*1*/ (| a & b); +type D6 /*0*/ = /*1*/ (| a & b); + +``` + + +# Prettier differences + +```diff +--- Prettier ++++ Rome +@@ -23,21 +23,21 @@ + type B3 = C; + type B4 = C; + type B5 = C; +-type B6 /*1*/ = C; +-type B7 /*1*/ = C; +-type B8 /*1*/ = C; +-type B9 /*1*/ = C; +-type B10 /*1*/ = /*2*/ C; +-type B11 /*1*/ = /*2*/ C; +-type B12 /*1*/ = C; ++type B6 = /*1*/ C; ++type B7 = /*1*/ C; ++type B8 = /*1*/ C; ++type B9 = /*1*/ C; ++type B10 = /*1*/ /*2*/ C; ++type B11 = /*1*/ /*2*/ C; ++type B12 = /*1*/ C; + + type Bb1 = /*1*/ /*2*/ C & D; + type Bb2 = /*1*/ /*2*/ C & /*3*/ D; + type Bb3 = /*1*/ /*2*/ C & /*3*/ D /*4*/; + +-type D1 /*1*/ = a & b; +-type D2 /*1*/ = a & b; +-type D3 /*1*/ = a & b; +-type D4 /*1*/ = a & b; +-type D5 /*1*/ = a & b; +-type D6 /*0*/ /*1*/ = a & b; ++type D1 = /*1*/ a & b; ++type D2 = /*1*/ a & b; ++type D3 = /*1*/ a & b; ++type D4 = /*1*/ a & b; ++type D5 = /*1*/ a & b; ++type D6 /*0*/ = /*1*/ a & b; +``` + +# Output + +```ts +type A = (number | string) & boolean; +type B = (number | string) & boolean; +type C = (number | string) & boolean; +type D = (number | string) & boolean; + +let b1: C; +let b2: C; +let b3: C; +let b4: C; +let b5: C; +let b6: /*1*/ C; +let b7: /*1*/ C; +let b8: /*1*/ C; +let b9: /*1*/ C; +let b10: /*1*/ /*2*/ C; +let b11: /*1*/ /*2*/ C; + +let bb1: /*1*/ /*2*/ C & D; +let bb2: /*1*/ /*2*/ C & /*3*/ D; +let bb3: /*1*/ /*2*/ C & /*3*/ D /*5*/; + +type B2 = C; +type B3 = C; +type B4 = C; +type B5 = C; +type B6 = /*1*/ C; +type B7 = /*1*/ C; +type B8 = /*1*/ C; +type B9 = /*1*/ C; +type B10 = /*1*/ /*2*/ C; +type B11 = /*1*/ /*2*/ C; +type B12 = /*1*/ C; + +type Bb1 = /*1*/ /*2*/ C & D; +type Bb2 = /*1*/ /*2*/ C & /*3*/ D; +type Bb3 = /*1*/ /*2*/ C & /*3*/ D /*4*/; + +type D1 = /*1*/ a & b; +type D2 = /*1*/ a & b; +type D3 = /*1*/ a & b; +type D4 = /*1*/ a & b; +type D5 = /*1*/ a & b; +type D6 /*0*/ = /*1*/ a & b; +``` + + diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/keywords/keywords.ts b/crates/rome_js_formatter/tests/specs/prettier/typescript/keywords/keywords.ts index 9dd21028276..343303c6285 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/typescript/keywords/keywords.ts +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/keywords/keywords.ts @@ -1,38 +1,23 @@ -// All of these should be an error - -module Y3 { - public module Module { - class A { s: string } - } - - // Apparently this parses :P - export private public protected static readonly abstract async enum X { } - - interface x { - export private static readonly [x: any]: any; - } -} - module Y4 { - public enum Color { Blue, Red } + enum Color { Blue, Red } } module YY3 { - private module Module { + module Module { class A { s: string } } } module YY4 { - private enum Color { Blue, Red } + enum Color { Blue, Red } } module YYY3 { - static module Module { + module Module { class A { s: string } } } module YYY4 { - static enum Color { Blue, Red } + enum Color { Blue, Red } } diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/keywords/keywords.ts.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/typescript/keywords/keywords.ts.prettier-snap index 6fcbff6272e..5f336addf1f 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/typescript/keywords/keywords.ts.prettier-snap +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/keywords/keywords.ts.prettier-snap @@ -1,29 +1,12 @@ -// All of these should be an error - -module Y3 { - public module Module { - class A { - s: string; - } - } - - // Apparently this parses :P - export private public protected static readonly abstract async enum X {} - - interface x { - export private static readonly [x: any]: any; - } -} - module Y4 { - public enum Color { + enum Color { Blue, Red, } } module YY3 { - private module Module { + module Module { class A { s: string; } @@ -31,14 +14,14 @@ module YY3 { } module YY4 { - private enum Color { + enum Color { Blue, Red, } } module YYY3 { - static module Module { + module Module { class A { s: string; } @@ -46,7 +29,7 @@ module YYY3 { } module YYY4 { - static enum Color { + enum Color { Blue, Red, } diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/keywords/keywords.ts.snap b/crates/rome_js_formatter/tests/specs/prettier/typescript/keywords/keywords.ts.snap deleted file mode 100644 index 6c019cc64ec..00000000000 --- a/crates/rome_js_formatter/tests/specs/prettier/typescript/keywords/keywords.ts.snap +++ /dev/null @@ -1,650 +0,0 @@ ---- -source: crates/rome_formatter_test/src/snapshot_builder.rs -assertion_line: 212 -info: typescript/keywords/keywords.ts ---- - -# Input - -```ts -// All of these should be an error - -module Y3 { - public module Module { - class A { s: string } - } - - // Apparently this parses :P - export private public protected static readonly abstract async enum X { } - - interface x { - export private static readonly [x: any]: any; - } -} - -module Y4 { - public enum Color { Blue, Red } -} - -module YY3 { - private module Module { - class A { s: string } - } -} - -module YY4 { - private enum Color { Blue, Red } -} - -module YYY3 { - static module Module { - class A { s: string } - } -} - -module YYY4 { - static enum Color { Blue, Red } -} - -``` - - -# Prettier differences - -```diff ---- Prettier -+++ Rome -@@ -1,29 +1,40 @@ - // All of these should be an error - - module Y3 { -- public module Module { -+ public -+ module Module { - class A { - s: string; - } - } - - // Apparently this parses :P -- export private public protected static readonly abstract async enum X {} -+ export -+ private -+ public -+ protected -+ static -+ readonly; -+ abstract; -+ async; -+ enum X {} - - interface x { -- export private static readonly [x: any]: any; -- } -+ export private static readonly [x: any]: any; -+ } - } - - module Y4 { -- public enum Color { -+ public -+ enum Color { - Blue, - Red, - } - } - - module YY3 { -- private module Module { -+ private -+ module Module { - class A { - s: string; - } -@@ -31,14 +42,16 @@ - } - - module YY4 { -- private enum Color { -+ private -+ enum Color { - Blue, - Red, - } - } - - module YYY3 { -- static module Module { -+ static -+ module Module { - class A { - s: string; - } -@@ -46,7 +59,8 @@ - } - - module YYY4 { -- static enum Color { -+ static -+ enum Color { - Blue, - Red, - } -``` - -# Output - -```ts -// All of these should be an error - -module Y3 { - public - module Module { - class A { - s: string; - } - } - - // Apparently this parses :P - export - private - public - protected - static - readonly; - abstract; - async; - enum X {} - - interface x { - export private static readonly [x: any]: any; - } -} - -module Y4 { - public - enum Color { - Blue, - Red, - } -} - -module YY3 { - private - module Module { - class A { - s: string; - } - } -} - -module YY4 { - private - enum Color { - Blue, - Red, - } -} - -module YYY3 { - static - module Module { - class A { - s: string; - } - } -} - -module YYY4 { - static - enum Color { - Blue, - Red, - } -} -``` - -# Errors -``` -keywords.ts:4:5 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - - × Illegal use of reserved keyword `public` as an identifier in strict mode - - 3 │ module Y3 { - > 4 │ public module Module { - │ ^^^^^^ - 5 │ class A { s: string } - 6 │ } - -keywords.ts:4:12 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - - × Expected a semicolon or an implicit semicolon after a statement, but found none - - 3 │ module Y3 { - > 4 │ public module Module { - │ ^^^^^^ - 5 │ class A { s: string } - 6 │ } - - i An explicit or implicit semicolon is expected here... - - 3 │ module Y3 { - > 4 │ public module Module { - │ ^^^^^^ - 5 │ class A { s: string } - 6 │ } - - i ...Which is required to end this statement - - 3 │ module Y3 { - > 4 │ public module Module { - │ ^^^^^^^^^^^^^ - 5 │ class A { s: string } - 6 │ } - -keywords.ts:9:12 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - - × expected a class, a function, or a variable declaration but instead found 'private' - - 8 │ // Apparently this parses :P - > 9 │ export private public protected static readonly abstract async enum X { } - │ ^^^^^^^ - 10 │ - 11 │ interface x { - - i Expected a class, a function, or a variable declaration here - - 8 │ // Apparently this parses :P - > 9 │ export private public protected static readonly abstract async enum X { } - │ ^^^^^^^ - 10 │ - 11 │ interface x { - -keywords.ts:9:20 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - - × Expected a semicolon or an implicit semicolon after a statement, but found none - - 8 │ // Apparently this parses :P - > 9 │ export private public protected static readonly abstract async enum X { } - │ ^^^^^^ - 10 │ - 11 │ interface x { - - i An explicit or implicit semicolon is expected here... - - 8 │ // Apparently this parses :P - > 9 │ export private public protected static readonly abstract async enum X { } - │ ^^^^^^ - 10 │ - 11 │ interface x { - - i ...Which is required to end this statement - - 8 │ // Apparently this parses :P - > 9 │ export private public protected static readonly abstract async enum X { } - │ ^^^^^^^^^^^^^^ - 10 │ - 11 │ interface x { - -keywords.ts:9:27 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - - × Expected a semicolon or an implicit semicolon after a statement, but found none - - 8 │ // Apparently this parses :P - > 9 │ export private public protected static readonly abstract async enum X { } - │ ^^^^^^^^^ - 10 │ - 11 │ interface x { - - i An explicit or implicit semicolon is expected here... - - 8 │ // Apparently this parses :P - > 9 │ export private public protected static readonly abstract async enum X { } - │ ^^^^^^^^^ - 10 │ - 11 │ interface x { - - i ...Which is required to end this statement - - 8 │ // Apparently this parses :P - > 9 │ export private public protected static readonly abstract async enum X { } - │ ^^^^^^^^^^^^^^^^ - 10 │ - 11 │ interface x { - -keywords.ts:9:37 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - - × Expected a semicolon or an implicit semicolon after a statement, but found none - - 8 │ // Apparently this parses :P - > 9 │ export private public protected static readonly abstract async enum X { } - │ ^^^^^^ - 10 │ - 11 │ interface x { - - i An explicit or implicit semicolon is expected here... - - 8 │ // Apparently this parses :P - > 9 │ export private public protected static readonly abstract async enum X { } - │ ^^^^^^ - 10 │ - 11 │ interface x { - - i ...Which is required to end this statement - - 8 │ // Apparently this parses :P - > 9 │ export private public protected static readonly abstract async enum X { } - │ ^^^^^^^^^^^^^^^^ - 10 │ - 11 │ interface x { - -keywords.ts:9:44 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - - × Expected a semicolon or an implicit semicolon after a statement, but found none - - 8 │ // Apparently this parses :P - > 9 │ export private public protected static readonly abstract async enum X { } - │ ^^^^^^^^ - 10 │ - 11 │ interface x { - - i An explicit or implicit semicolon is expected here... - - 8 │ // Apparently this parses :P - > 9 │ export private public protected static readonly abstract async enum X { } - │ ^^^^^^^^ - 10 │ - 11 │ interface x { - - i ...Which is required to end this statement - - 8 │ // Apparently this parses :P - > 9 │ export private public protected static readonly abstract async enum X { } - │ ^^^^^^^^^^^^^^^ - 10 │ - 11 │ interface x { - -keywords.ts:9:53 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - - × Expected a semicolon or an implicit semicolon after a statement, but found none - - 8 │ // Apparently this parses :P - > 9 │ export private public protected static readonly abstract async enum X { } - │ ^^^^^^^^ - 10 │ - 11 │ interface x { - - i An explicit or implicit semicolon is expected here... - - 8 │ // Apparently this parses :P - > 9 │ export private public protected static readonly abstract async enum X { } - │ ^^^^^^^^ - 10 │ - 11 │ interface x { - - i ...Which is required to end this statement - - 8 │ // Apparently this parses :P - > 9 │ export private public protected static readonly abstract async enum X { } - │ ^^^^^^^^^^^^^^^^^ - 10 │ - 11 │ interface x { - -keywords.ts:9:62 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - - × Expected a semicolon or an implicit semicolon after a statement, but found none - - 8 │ // Apparently this parses :P - > 9 │ export private public protected static readonly abstract async enum X { } - │ ^^^^^ - 10 │ - 11 │ interface x { - - i An explicit or implicit semicolon is expected here... - - 8 │ // Apparently this parses :P - > 9 │ export private public protected static readonly abstract async enum X { } - │ ^^^^^ - 10 │ - 11 │ interface x { - - i ...Which is required to end this statement - - 8 │ // Apparently this parses :P - > 9 │ export private public protected static readonly abstract async enum X { } - │ ^^^^^^^^^^^^^^ - 10 │ - 11 │ interface x { - -keywords.ts:9:68 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - - × Expected a semicolon or an implicit semicolon after a statement, but found none - - 8 │ // Apparently this parses :P - > 9 │ export private public protected static readonly abstract async enum X { } - │ ^^^^ - 10 │ - 11 │ interface x { - - i An explicit or implicit semicolon is expected here... - - 8 │ // Apparently this parses :P - > 9 │ export private public protected static readonly abstract async enum X { } - │ ^^^^ - 10 │ - 11 │ interface x { - - i ...Which is required to end this statement - - 8 │ // Apparently this parses :P - > 9 │ export private public protected static readonly abstract async enum X { } - │ ^^^^^^^^^^ - 10 │ - 11 │ interface x { - -keywords.ts:12:16 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - - × ';' expected' - - 11 │ interface x { - > 12 │ export private static readonly [x: any]: any; - │ ^^^^^^^ - 13 │ } - 14 │ } - - i An explicit or implicit semicolon is expected here... - -keywords.ts:12:24 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - - × index signature members cannot be static - - 11 │ interface x { - > 12 │ export private static readonly [x: any]: any; - │ ^^^^^^ - 13 │ } - 14 │ } - -keywords.ts:17:5 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - - × Illegal use of reserved keyword `public` as an identifier in strict mode - - 16 │ module Y4 { - > 17 │ public enum Color { Blue, Red } - │ ^^^^^^ - 18 │ } - 19 │ - -keywords.ts:17:12 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - - × Expected a semicolon or an implicit semicolon after a statement, but found none - - 16 │ module Y4 { - > 17 │ public enum Color { Blue, Red } - │ ^^^^ - 18 │ } - 19 │ - - i An explicit or implicit semicolon is expected here... - - 16 │ module Y4 { - > 17 │ public enum Color { Blue, Red } - │ ^^^^ - 18 │ } - 19 │ - - i ...Which is required to end this statement - - 16 │ module Y4 { - > 17 │ public enum Color { Blue, Red } - │ ^^^^^^^^^^^ - 18 │ } - 19 │ - -keywords.ts:21:5 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - - × Illegal use of reserved keyword `private` as an identifier in strict mode - - 20 │ module YY3 { - > 21 │ private module Module { - │ ^^^^^^^ - 22 │ class A { s: string } - 23 │ } - -keywords.ts:21:13 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - - × Expected a semicolon or an implicit semicolon after a statement, but found none - - 20 │ module YY3 { - > 21 │ private module Module { - │ ^^^^^^ - 22 │ class A { s: string } - 23 │ } - - i An explicit or implicit semicolon is expected here... - - 20 │ module YY3 { - > 21 │ private module Module { - │ ^^^^^^ - 22 │ class A { s: string } - 23 │ } - - i ...Which is required to end this statement - - 20 │ module YY3 { - > 21 │ private module Module { - │ ^^^^^^^^^^^^^^ - 22 │ class A { s: string } - 23 │ } - -keywords.ts:27:5 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - - × Illegal use of reserved keyword `private` as an identifier in strict mode - - 26 │ module YY4 { - > 27 │ private enum Color { Blue, Red } - │ ^^^^^^^ - 28 │ } - 29 │ - -keywords.ts:27:13 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - - × Expected a semicolon or an implicit semicolon after a statement, but found none - - 26 │ module YY4 { - > 27 │ private enum Color { Blue, Red } - │ ^^^^ - 28 │ } - 29 │ - - i An explicit or implicit semicolon is expected here... - - 26 │ module YY4 { - > 27 │ private enum Color { Blue, Red } - │ ^^^^ - 28 │ } - 29 │ - - i ...Which is required to end this statement - - 26 │ module YY4 { - > 27 │ private enum Color { Blue, Red } - │ ^^^^^^^^^^^^ - 28 │ } - 29 │ - -keywords.ts:31:5 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - - × Illegal use of reserved keyword `static` as an identifier in strict mode - - 30 │ module YYY3 { - > 31 │ static module Module { - │ ^^^^^^ - 32 │ class A { s: string } - 33 │ } - -keywords.ts:31:12 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - - × Expected a semicolon or an implicit semicolon after a statement, but found none - - 30 │ module YYY3 { - > 31 │ static module Module { - │ ^^^^^^ - 32 │ class A { s: string } - 33 │ } - - i An explicit or implicit semicolon is expected here... - - 30 │ module YYY3 { - > 31 │ static module Module { - │ ^^^^^^ - 32 │ class A { s: string } - 33 │ } - - i ...Which is required to end this statement - - 30 │ module YYY3 { - > 31 │ static module Module { - │ ^^^^^^^^^^^^^ - 32 │ class A { s: string } - 33 │ } - -keywords.ts:37:5 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - - × Illegal use of reserved keyword `static` as an identifier in strict mode - - 36 │ module YYY4 { - > 37 │ static enum Color { Blue, Red } - │ ^^^^^^ - 38 │ } - 39 │ - -keywords.ts:37:12 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - - × Expected a semicolon or an implicit semicolon after a statement, but found none - - 36 │ module YYY4 { - > 37 │ static enum Color { Blue, Red } - │ ^^^^ - 38 │ } - 39 │ - - i An explicit or implicit semicolon is expected here... - - 36 │ module YYY4 { - > 37 │ static enum Color { Blue, Red } - │ ^^^^ - 38 │ } - 39 │ - - i ...Which is required to end this statement - - 36 │ module YYY4 { - > 37 │ static enum Color { Blue, Red } - │ ^^^^^^^^^^^ - 38 │ } - 39 │ - - -``` - - diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/keywords/module.ts b/crates/rome_js_formatter/tests/specs/prettier/typescript/keywords/module.ts index f4bd5c9f561..d9e253d35f3 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/typescript/keywords/module.ts +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/keywords/module.ts @@ -1,12 +1,11 @@ module Y3 { - public module Module { + module Module { class A { s: string } } - // Apparently this parses :P - export private public protected static readonly abstract async enum X { } + export enum X { } interface x { - export private static readonly [x: any]: any; + readonly [x: any]: any; } } diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/keywords/module.ts.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/typescript/keywords/module.ts.prettier-snap index f71aaa39e8e..5b24a77b52c 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/typescript/keywords/module.ts.prettier-snap +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/keywords/module.ts.prettier-snap @@ -1,14 +1,13 @@ module Y3 { - public module Module { + module Module { class A { s: string; } } - // Apparently this parses :P - export private public protected static readonly abstract async enum X {} + export enum X {} interface x { - export private static readonly [x: any]: any; + readonly [x: any]: any; } } diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/keywords/module.ts.snap b/crates/rome_js_formatter/tests/specs/prettier/typescript/keywords/module.ts.snap deleted file mode 100644 index 6c7c46173db..00000000000 --- a/crates/rome_js_formatter/tests/specs/prettier/typescript/keywords/module.ts.snap +++ /dev/null @@ -1,351 +0,0 @@ ---- -source: crates/rome_formatter_test/src/snapshot_builder.rs -assertion_line: 212 -info: typescript/keywords/module.ts ---- - -# Input - -```ts -module Y3 { - public module Module { - class A { s: string } - } - - // Apparently this parses :P - export private public protected static readonly abstract async enum X { } - - interface x { - export private static readonly [x: any]: any; - } -} - -``` - - -# Prettier differences - -```diff ---- Prettier -+++ Rome -@@ -1,14 +1,23 @@ - module Y3 { -- public module Module { -+ public -+ module Module { - class A { - s: string; - } - } - - // Apparently this parses :P -- export private public protected static readonly abstract async enum X {} -+ export -+ private -+ public -+ protected -+ static -+ readonly; -+ abstract; -+ async; -+ enum X {} - - interface x { -- export private static readonly [x: any]: any; -+ export private static readonly [x: any]: any; - } - } -``` - -# Output - -```ts -module Y3 { - public - module Module { - class A { - s: string; - } - } - - // Apparently this parses :P - export - private - public - protected - static - readonly; - abstract; - async; - enum X {} - - interface x { - export private static readonly [x: any]: any; - } -} -``` - -# Errors -``` -module.ts:2:3 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - - × Illegal use of reserved keyword `public` as an identifier in strict mode - - 1 │ module Y3 { - > 2 │ public module Module { - │ ^^^^^^ - 3 │ class A { s: string } - 4 │ } - -module.ts:2:10 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - - × Expected a semicolon or an implicit semicolon after a statement, but found none - - 1 │ module Y3 { - > 2 │ public module Module { - │ ^^^^^^ - 3 │ class A { s: string } - 4 │ } - - i An explicit or implicit semicolon is expected here... - - 1 │ module Y3 { - > 2 │ public module Module { - │ ^^^^^^ - 3 │ class A { s: string } - 4 │ } - - i ...Which is required to end this statement - - 1 │ module Y3 { - > 2 │ public module Module { - │ ^^^^^^^^^^^^^ - 3 │ class A { s: string } - 4 │ } - -module.ts:7:10 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - - × expected a class, a function, or a variable declaration but instead found 'private' - - 6 │ // Apparently this parses :P - > 7 │ export private public protected static readonly abstract async enum X { } - │ ^^^^^^^ - 8 │ - 9 │ interface x { - - i Expected a class, a function, or a variable declaration here - - 6 │ // Apparently this parses :P - > 7 │ export private public protected static readonly abstract async enum X { } - │ ^^^^^^^ - 8 │ - 9 │ interface x { - -module.ts:7:18 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - - × Expected a semicolon or an implicit semicolon after a statement, but found none - - 6 │ // Apparently this parses :P - > 7 │ export private public protected static readonly abstract async enum X { } - │ ^^^^^^ - 8 │ - 9 │ interface x { - - i An explicit or implicit semicolon is expected here... - - 6 │ // Apparently this parses :P - > 7 │ export private public protected static readonly abstract async enum X { } - │ ^^^^^^ - 8 │ - 9 │ interface x { - - i ...Which is required to end this statement - - 6 │ // Apparently this parses :P - > 7 │ export private public protected static readonly abstract async enum X { } - │ ^^^^^^^^^^^^^^ - 8 │ - 9 │ interface x { - -module.ts:7:25 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - - × Expected a semicolon or an implicit semicolon after a statement, but found none - - 6 │ // Apparently this parses :P - > 7 │ export private public protected static readonly abstract async enum X { } - │ ^^^^^^^^^ - 8 │ - 9 │ interface x { - - i An explicit or implicit semicolon is expected here... - - 6 │ // Apparently this parses :P - > 7 │ export private public protected static readonly abstract async enum X { } - │ ^^^^^^^^^ - 8 │ - 9 │ interface x { - - i ...Which is required to end this statement - - 6 │ // Apparently this parses :P - > 7 │ export private public protected static readonly abstract async enum X { } - │ ^^^^^^^^^^^^^^^^ - 8 │ - 9 │ interface x { - -module.ts:7:35 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - - × Expected a semicolon or an implicit semicolon after a statement, but found none - - 6 │ // Apparently this parses :P - > 7 │ export private public protected static readonly abstract async enum X { } - │ ^^^^^^ - 8 │ - 9 │ interface x { - - i An explicit or implicit semicolon is expected here... - - 6 │ // Apparently this parses :P - > 7 │ export private public protected static readonly abstract async enum X { } - │ ^^^^^^ - 8 │ - 9 │ interface x { - - i ...Which is required to end this statement - - 6 │ // Apparently this parses :P - > 7 │ export private public protected static readonly abstract async enum X { } - │ ^^^^^^^^^^^^^^^^ - 8 │ - 9 │ interface x { - -module.ts:7:42 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - - × Expected a semicolon or an implicit semicolon after a statement, but found none - - 6 │ // Apparently this parses :P - > 7 │ export private public protected static readonly abstract async enum X { } - │ ^^^^^^^^ - 8 │ - 9 │ interface x { - - i An explicit or implicit semicolon is expected here... - - 6 │ // Apparently this parses :P - > 7 │ export private public protected static readonly abstract async enum X { } - │ ^^^^^^^^ - 8 │ - 9 │ interface x { - - i ...Which is required to end this statement - - 6 │ // Apparently this parses :P - > 7 │ export private public protected static readonly abstract async enum X { } - │ ^^^^^^^^^^^^^^^ - 8 │ - 9 │ interface x { - -module.ts:7:51 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - - × Expected a semicolon or an implicit semicolon after a statement, but found none - - 6 │ // Apparently this parses :P - > 7 │ export private public protected static readonly abstract async enum X { } - │ ^^^^^^^^ - 8 │ - 9 │ interface x { - - i An explicit or implicit semicolon is expected here... - - 6 │ // Apparently this parses :P - > 7 │ export private public protected static readonly abstract async enum X { } - │ ^^^^^^^^ - 8 │ - 9 │ interface x { - - i ...Which is required to end this statement - - 6 │ // Apparently this parses :P - > 7 │ export private public protected static readonly abstract async enum X { } - │ ^^^^^^^^^^^^^^^^^ - 8 │ - 9 │ interface x { - -module.ts:7:60 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - - × Expected a semicolon or an implicit semicolon after a statement, but found none - - 6 │ // Apparently this parses :P - > 7 │ export private public protected static readonly abstract async enum X { } - │ ^^^^^ - 8 │ - 9 │ interface x { - - i An explicit or implicit semicolon is expected here... - - 6 │ // Apparently this parses :P - > 7 │ export private public protected static readonly abstract async enum X { } - │ ^^^^^ - 8 │ - 9 │ interface x { - - i ...Which is required to end this statement - - 6 │ // Apparently this parses :P - > 7 │ export private public protected static readonly abstract async enum X { } - │ ^^^^^^^^^^^^^^ - 8 │ - 9 │ interface x { - -module.ts:7:66 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - - × Expected a semicolon or an implicit semicolon after a statement, but found none - - 6 │ // Apparently this parses :P - > 7 │ export private public protected static readonly abstract async enum X { } - │ ^^^^ - 8 │ - 9 │ interface x { - - i An explicit or implicit semicolon is expected here... - - 6 │ // Apparently this parses :P - > 7 │ export private public protected static readonly abstract async enum X { } - │ ^^^^ - 8 │ - 9 │ interface x { - - i ...Which is required to end this statement - - 6 │ // Apparently this parses :P - > 7 │ export private public protected static readonly abstract async enum X { } - │ ^^^^^^^^^^ - 8 │ - 9 │ interface x { - -module.ts:10:14 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - - × ';' expected' - - 9 │ interface x { - > 10 │ export private static readonly [x: any]: any; - │ ^^^^^^^ - 11 │ } - 12 │ } - - i An explicit or implicit semicolon is expected here... - -module.ts:10:22 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - - × index signature members cannot be static - - 9 │ interface x { - > 10 │ export private static readonly [x: any]: any; - │ ^^^^^^ - 11 │ } - 12 │ } - - -``` - - diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/last-argument-expansion/decorated-function.tsx b/crates/rome_js_formatter/tests/specs/prettier/typescript/last-argument-expansion/decorated-function.tsx new file mode 100644 index 00000000000..125c2708cea --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/last-argument-expansion/decorated-function.tsx @@ -0,0 +1,55 @@ +const Counter = decorator("my-counter")( + (props: { initialCount?: number; label?: string }) => { + const p = useDefault(props, { + initialCount: 0, + label: "Counter", + }); + + const [s, set] = useState({ count: p.initialCount }); + const onClick = () => set("count", (it) => it + 1); + + return () => ( + + ); + } +); + +const Counter2 = decorators.decorator("my-counter")( + (props: { initialCount?: number; label?: string }) => { + return () => ( + + ); + } +); + +export default decorators.decorator("my-counter")( + (props: { initialCount?: number; label?: string }) => { + return foo; + } +); + +export = decorators.decorator("my-counter")( + (props: { initialCount?: number; label?: string }) => { + return foo; + } +); + +module.exports = decorators.decorator("my-counter")( + (props: { initialCount?: number; label?: string }) => { + return foo; + } +); + +const Counter = + decorator("foo")( + decorator("bar")( + (props: { + loremFoo1: Array>, + ipsumBarr2: Promise, + }) => { + return
; + })); diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/last-argument-expansion/decorated-function.tsx.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/typescript/last-argument-expansion/decorated-function.tsx.prettier-snap new file mode 100644 index 00000000000..e554b23c19b --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/last-argument-expansion/decorated-function.tsx.prettier-snap @@ -0,0 +1,61 @@ +const Counter = decorator("my-counter")((props: { + initialCount?: number; + label?: string; +}) => { + const p = useDefault(props, { + initialCount: 0, + label: "Counter", + }); + + const [s, set] = useState({ count: p.initialCount }); + const onClick = () => set("count", (it) => it + 1); + + return () => ( + + ); +}); + +const Counter2 = decorators.decorator("my-counter")((props: { + initialCount?: number; + label?: string; +}) => { + return () => ( + + ); +}); + +export default decorators.decorator("my-counter")((props: { + initialCount?: number; + label?: string; +}) => { + return foo; +}); + +export = decorators.decorator("my-counter")((props: { + initialCount?: number; + label?: string; +}) => { + return foo; +}); + +module.exports = decorators.decorator("my-counter")((props: { + initialCount?: number; + label?: string; +}) => { + return foo; +}); + +const Counter = decorator("foo")( + decorator("bar")( + (props: { + loremFoo1: Array>; + ipsumBarr2: Promise; + }) => { + return
; + }, + ), +); diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/last-argument-expansion/decorated-function.tsx.snap b/crates/rome_js_formatter/tests/specs/prettier/typescript/last-argument-expansion/decorated-function.tsx.snap new file mode 100644 index 00000000000..f59f1b77ca6 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/last-argument-expansion/decorated-function.tsx.snap @@ -0,0 +1,229 @@ +--- +source: crates/rome_formatter_test/src/snapshot_builder.rs +info: typescript/last-argument-expansion/decorated-function.tsx +--- + +# Input + +```tsx +const Counter = decorator("my-counter")( + (props: { initialCount?: number; label?: string }) => { + const p = useDefault(props, { + initialCount: 0, + label: "Counter", + }); + + const [s, set] = useState({ count: p.initialCount }); + const onClick = () => set("count", (it) => it + 1); + + return () => ( + + ); + } +); + +const Counter2 = decorators.decorator("my-counter")( + (props: { initialCount?: number; label?: string }) => { + return () => ( + + ); + } +); + +export default decorators.decorator("my-counter")( + (props: { initialCount?: number; label?: string }) => { + return foo; + } +); + +export = decorators.decorator("my-counter")( + (props: { initialCount?: number; label?: string }) => { + return foo; + } +); + +module.exports = decorators.decorator("my-counter")( + (props: { initialCount?: number; label?: string }) => { + return foo; + } +); + +const Counter = + decorator("foo")( + decorator("bar")( + (props: { + loremFoo1: Array>, + ipsumBarr2: Promise, + }) => { + return
; + })); + +``` + + +# Prettier differences + +```diff +--- Prettier ++++ Rome +@@ -1,53 +1,48 @@ +-const Counter = decorator("my-counter")((props: { +- initialCount?: number; +- label?: string; +-}) => { +- const p = useDefault(props, { +- initialCount: 0, +- label: "Counter", +- }); ++const Counter = decorator("my-counter")( ++ (props: { initialCount?: number; label?: string }) => { ++ const p = useDefault(props, { ++ initialCount: 0, ++ label: "Counter", ++ }); + +- const [s, set] = useState({ count: p.initialCount }); +- const onClick = () => set("count", (it) => it + 1); ++ const [s, set] = useState({ count: p.initialCount }); ++ const onClick = () => set("count", (it) => it + 1); + +- return () => ( +- +- ); +-}); ++ return () => ( ++ ++ ); ++ }, ++); + +-const Counter2 = decorators.decorator("my-counter")((props: { +- initialCount?: number; +- label?: string; +-}) => { +- return () => ( +- +- ); +-}); ++const Counter2 = decorators.decorator("my-counter")( ++ (props: { initialCount?: number; label?: string }) => { ++ return () => ( ++ ++ ); ++ }, ++); + +-export default decorators.decorator("my-counter")((props: { +- initialCount?: number; +- label?: string; +-}) => { +- return foo; +-}); ++export default decorators.decorator("my-counter")( ++ (props: { initialCount?: number; label?: string }) => { ++ return foo; ++ }, ++); + +-export = decorators.decorator("my-counter")((props: { +- initialCount?: number; +- label?: string; +-}) => { +- return foo; +-}); ++export = decorators.decorator("my-counter")( ++ (props: { initialCount?: number; label?: string }) => { ++ return foo; ++ }, ++); + +-module.exports = decorators.decorator("my-counter")((props: { +- initialCount?: number; +- label?: string; +-}) => { +- return foo; +-}); ++module.exports = decorators.decorator("my-counter")( ++ (props: { initialCount?: number; label?: string }) => { ++ return foo; ++ }, ++); + + const Counter = decorator("foo")( + decorator("bar")( +``` + +# Output + +```tsx +const Counter = decorator("my-counter")( + (props: { initialCount?: number; label?: string }) => { + const p = useDefault(props, { + initialCount: 0, + label: "Counter", + }); + + const [s, set] = useState({ count: p.initialCount }); + const onClick = () => set("count", (it) => it + 1); + + return () => ( + + ); + }, +); + +const Counter2 = decorators.decorator("my-counter")( + (props: { initialCount?: number; label?: string }) => { + return () => ( + + ); + }, +); + +export default decorators.decorator("my-counter")( + (props: { initialCount?: number; label?: string }) => { + return foo; + }, +); + +export = decorators.decorator("my-counter")( + (props: { initialCount?: number; label?: string }) => { + return foo; + }, +); + +module.exports = decorators.decorator("my-counter")( + (props: { initialCount?: number; label?: string }) => { + return foo; + }, +); + +const Counter = decorator("foo")( + decorator("bar")( + (props: { + loremFoo1: Array>; + ipsumBarr2: Promise; + }) => { + return
; + }, + ), +); +``` + + diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/last-argument-expansion/forward-ref.tsx b/crates/rome_js_formatter/tests/specs/prettier/typescript/last-argument-expansion/forward-ref.tsx new file mode 100644 index 00000000000..7cf00124d9c --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/last-argument-expansion/forward-ref.tsx @@ -0,0 +1,27 @@ +export const Link = forwardRef( + function Link(props, ref) { + return ; + } +); + +export const LinkWithLongName = forwardRef( + function Link(props, ref) { + return ; + } +); + +export const Arrow = forwardRef((props, ref) => { + return ; +}); + +export const ArrowWithLongName = forwardRef( + (props, ref) => { + return ; + } +); + +const Link = React.forwardRef( + function Link(props, ref) { + return ; + }, +); diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/last-argument-expansion/forward-ref.tsx.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/typescript/last-argument-expansion/forward-ref.tsx.prettier-snap new file mode 100644 index 00000000000..4814d525596 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/last-argument-expansion/forward-ref.tsx.prettier-snap @@ -0,0 +1,27 @@ +export const Link = forwardRef( + function Link(props, ref) { + return ; + }, +); + +export const LinkWithLongName = forwardRef( + function Link(props, ref) { + return ; + }, +); + +export const Arrow = forwardRef((props, ref) => { + return ; +}); + +export const ArrowWithLongName = forwardRef( + (props, ref) => { + return ; + }, +); + +const Link = React.forwardRef( + function Link(props, ref) { + return ; + }, +); diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/last-argument-expansion/forward-ref.tsx.snap b/crates/rome_js_formatter/tests/specs/prettier/typescript/last-argument-expansion/forward-ref.tsx.snap new file mode 100644 index 00000000000..fb3fcdd5657 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/last-argument-expansion/forward-ref.tsx.snap @@ -0,0 +1,111 @@ +--- +source: crates/rome_formatter_test/src/snapshot_builder.rs +info: typescript/last-argument-expansion/forward-ref.tsx +--- + +# Input + +```tsx +export const Link = forwardRef( + function Link(props, ref) { + return ; + } +); + +export const LinkWithLongName = forwardRef( + function Link(props, ref) { + return ; + } +); + +export const Arrow = forwardRef((props, ref) => { + return ; +}); + +export const ArrowWithLongName = forwardRef( + (props, ref) => { + return ; + } +); + +const Link = React.forwardRef( + function Link(props, ref) { + return ; + }, +); + +``` + + +# Prettier differences + +```diff +--- Prettier ++++ Rome +@@ -1,8 +1,9 @@ +-export const Link = forwardRef( +- function Link(props, ref) { +- return ; +- }, +-); ++export const Link = forwardRef(function Link( ++ props, ++ ref, ++) { ++ return ; ++}); + + export const LinkWithLongName = forwardRef( + function Link(props, ref) { +@@ -20,8 +21,9 @@ + }, + ); + +-const Link = React.forwardRef( +- function Link(props, ref) { +- return ; +- }, +-); ++const Link = React.forwardRef(function Link( ++ props, ++ ref, ++) { ++ return ; ++}); +``` + +# Output + +```tsx +export const Link = forwardRef(function Link( + props, + ref, +) { + return ; +}); + +export const LinkWithLongName = forwardRef( + function Link(props, ref) { + return ; + }, +); + +export const Arrow = forwardRef((props, ref) => { + return ; +}); + +export const ArrowWithLongName = forwardRef( + (props, ref) => { + return ; + }, +); + +const Link = React.forwardRef(function Link( + props, + ref, +) { + return ; +}); +``` + + diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/mapped-type/break-mode/break-mode.ts b/crates/rome_js_formatter/tests/specs/prettier/typescript/mapped-type/break-mode/break-mode.ts new file mode 100644 index 00000000000..3bada24aa1b --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/mapped-type/break-mode/break-mode.ts @@ -0,0 +1,13 @@ +type A1 = { readonly [A in B]: T} +type A2 = { +readonly [A in B]: T} +type A3 = { readonly + [A in B]: T} +type A4 = { readonly [ +A in B]: T} +type A5 = { readonly [A in B] +: T} +type A6 = { readonly [A in B]: +T} +type A7 = { readonly [A in B]: T +} diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/mapped-type/break-mode/break-mode.ts.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/typescript/mapped-type/break-mode/break-mode.ts.prettier-snap new file mode 100644 index 00000000000..3512541ffb0 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/mapped-type/break-mode/break-mode.ts.prettier-snap @@ -0,0 +1,13 @@ +type A1 = { readonly [A in B]: T }; +type A2 = { + readonly [A in B]: T; +}; +type A3 = { + readonly [A in B]: T; +}; +type A4 = { + readonly [A in B]: T; +}; +type A5 = { readonly [A in B]: T }; +type A6 = { readonly [A in B]: T }; +type A7 = { readonly [A in B]: T }; diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/mapped-type/break-mode/break-mode.ts.snap b/crates/rome_js_formatter/tests/specs/prettier/typescript/mapped-type/break-mode/break-mode.ts.snap new file mode 100644 index 00000000000..2773237dcc0 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/mapped-type/break-mode/break-mode.ts.snap @@ -0,0 +1,68 @@ +--- +source: crates/rome_formatter_test/src/snapshot_builder.rs +info: typescript/mapped-type/break-mode/break-mode.ts +--- + +# Input + +```ts +type A1 = { readonly [A in B]: T} +type A2 = { +readonly [A in B]: T} +type A3 = { readonly + [A in B]: T} +type A4 = { readonly [ +A in B]: T} +type A5 = { readonly [A in B] +: T} +type A6 = { readonly [A in B]: +T} +type A7 = { readonly [A in B]: T +} + +``` + + +# Prettier differences + +```diff +--- Prettier ++++ Rome +@@ -1,13 +1,11 @@ + type A1 = { readonly [A in B]: T }; +-type A2 = { +- readonly [A in B]: T; +-}; ++type A2 = { readonly [A in B]: T }; + type A3 = { + readonly [A in B]: T; + }; +-type A4 = { ++type A4 = { readonly [A in B]: T }; ++type A5 = { readonly [A in B]: T }; ++type A6 = { readonly [A in B]: T }; ++type A7 = { + readonly [A in B]: T; + }; +-type A5 = { readonly [A in B]: T }; +-type A6 = { readonly [A in B]: T }; +-type A7 = { readonly [A in B]: T }; +``` + +# Output + +```ts +type A1 = { readonly [A in B]: T }; +type A2 = { readonly [A in B]: T }; +type A3 = { + readonly [A in B]: T; +}; +type A4 = { readonly [A in B]: T }; +type A5 = { readonly [A in B]: T }; +type A6 = { readonly [A in B]: T }; +type A7 = { + readonly [A in B]: T; +}; +``` + + diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/module/global.ts b/crates/rome_js_formatter/tests/specs/prettier/typescript/module/global.ts index 24b44687f8c..e509f69e333 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/typescript/module/global.ts +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/module/global.ts @@ -2,3 +2,7 @@ namespace global {} module global {} global {} declare global {} +declare /* module */ global {} +declare /* namespace */ global {} +declare module global {} +declare namespace global {} diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/module/global.ts.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/typescript/module/global.ts.prettier-snap index 24b44687f8c..33726e3f172 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/typescript/module/global.ts.prettier-snap +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/module/global.ts.prettier-snap @@ -2,3 +2,7 @@ namespace global {} module global {} global {} declare global {} +declare /* module */ global {} +declare /* namespace */ global {} +declare module global {} +declare namespace global {} diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/non-null/braces.ts.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/typescript/non-null/braces.ts.prettier-snap index b21664c1907..70629a69b8b 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/typescript/non-null/braces.ts.prettier-snap +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/non-null/braces.ts.prettier-snap @@ -2,9 +2,9 @@ const myFunction2 = (key: string): number => ({ a: 42, b: 42, - }[key]!); + })[key]!; -const myFunction3 = (key) => ({}!.a); +const myFunction3 = (key) => ({})!.a; const f = ((a) => { log(a); diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/non-null/braces.ts.snap b/crates/rome_js_formatter/tests/specs/prettier/typescript/non-null/braces.ts.snap deleted file mode 100644 index f4d7f6ff8d3..00000000000 --- a/crates/rome_js_formatter/tests/specs/prettier/typescript/non-null/braces.ts.snap +++ /dev/null @@ -1,70 +0,0 @@ ---- -source: crates/rome_formatter_test/src/snapshot_builder.rs -assertion_line: 212 -info: typescript/non-null/braces.ts ---- - -# Input - -```ts -const myFunction2 = (key: string): number => - ({ - a: 42, - b: 42, - }[key]!) - -const myFunction3 = key => ({}!.a); - -const f = ((a) => {log(a)})!; - -if (a) ({ a, ...b }.a())!.c(); - -(function() {})!() - -class a extends ({}!) {} - -``` - - -# Prettier differences - -```diff ---- Prettier -+++ Rome -@@ -2,9 +2,9 @@ - ({ - a: 42, - b: 42, -- }[key]!); -+ })[key]!; - --const myFunction3 = (key) => ({}!.a); -+const myFunction3 = (key) => ({})!.a; - - const f = ((a) => { - log(a); -``` - -# Output - -```ts -const myFunction2 = (key: string): number => - ({ - a: 42, - b: 42, - })[key]!; - -const myFunction3 = (key) => ({})!.a; - -const f = ((a) => { - log(a); -})!; - -if (a) ({ a, ...b }).a()!.c(); - -(function () {})!(); - -class a extends ({}!) {} -``` - - diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/optional-variance/with-jsx.tsx b/crates/rome_js_formatter/tests/specs/prettier/typescript/optional-variance/with-jsx.tsx new file mode 100644 index 00000000000..9210edb034a --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/optional-variance/with-jsx.tsx @@ -0,0 +1,61 @@ +type Covariant = { + x: T; +} +type Contravariant = { + f: (x: T) => void; +} +type Invariant = { + f: (x: T) => T; +} +type T10 = T; +type T11 = keyof T; +type T12 = T[K]; +type T13 = T[keyof T]; + +type Covariant1 = { + x: T; +} + +type Contravariant1 = keyof T; + +type Contravariant2 = { + f: (x: T) => void; +} + +type Invariant1 = { + f: (x: T) => T; +} + +type Invariant2 = { + f: (x: T) => T; +} +type Foo1 = { + x: T; + f: FooFn1; +} + +type Foo2 = { + x: T; + f: FooFn2; +} + +type Foo3 = { + x: T; + f: FooFn3; +} + +type T21 = T; + +interface Baz {} +interface Baz {} + +interface Parent { + child: Child | null; + parent: Parent | null; +} + +declare class StateNode { + _storedEvent: TEvent; + _action: ActionObject; + _state: StateNode; +} diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/optional-variance/with-jsx.tsx.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/typescript/optional-variance/with-jsx.tsx.prettier-snap new file mode 100644 index 00000000000..c1043921d3d --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/optional-variance/with-jsx.tsx.prettier-snap @@ -0,0 +1,61 @@ +type Covariant = { + x: T; +}; +type Contravariant = { + f: (x: T) => void; +}; +type Invariant = { + f: (x: T) => T; +}; +type T10 = T; +type T11 = keyof T; +type T12 = T[K]; +type T13 = T[keyof T]; + +type Covariant1 = { + x: T; +}; + +type Contravariant1 = keyof T; + +type Contravariant2 = { + f: (x: T) => void; +}; + +type Invariant1 = { + f: (x: T) => T; +}; + +type Invariant2 = { + f: (x: T) => T; +}; +type Foo1 = { + x: T; + f: FooFn1; +}; + +type Foo2 = { + x: T; + f: FooFn2; +}; + +type Foo3 = { + x: T; + f: FooFn3; +}; + +type T21 = T; + +interface Baz {} +interface Baz {} + +interface Parent { + child: Child | null; + parent: Parent | null; +} + +declare class StateNode { + _storedEvent: TEvent; + _action: ActionObject; + _state: StateNode; +} diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/prettier-ignore/issue-14238.ts b/crates/rome_js_formatter/tests/specs/prettier/typescript/prettier-ignore/issue-14238.ts new file mode 100644 index 00000000000..4cdef795995 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/prettier-ignore/issue-14238.ts @@ -0,0 +1,4 @@ +export const foo = ( + // prettier-ignore + bar as Baz +).qux; diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/prettier-ignore/issue-14238.ts.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/typescript/prettier-ignore/issue-14238.ts.prettier-snap new file mode 100644 index 00000000000..7793157d91b --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/prettier-ignore/issue-14238.ts.prettier-snap @@ -0,0 +1,2 @@ +export const foo = // prettier-ignore + (bar as Baz).qux; diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/prettier-ignore/issue-14238.ts.snap b/crates/rome_js_formatter/tests/specs/prettier/typescript/prettier-ignore/issue-14238.ts.snap new file mode 100644 index 00000000000..c169c9b825a --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/prettier-ignore/issue-14238.ts.snap @@ -0,0 +1,42 @@ +--- +source: crates/rome_formatter_test/src/snapshot_builder.rs +info: typescript/prettier-ignore/issue-14238.ts +--- + +# Input + +```ts +export const foo = ( + // prettier-ignore + bar as Baz +).qux; + +``` + + +# Prettier differences + +```diff +--- Prettier ++++ Rome +@@ -1,2 +1,5 @@ +-export const foo = // prettier-ignore +- (bar as Baz).qux; ++export const foo = ++ ( ++ // prettier-ignore ++ bar as Baz ++).qux; +``` + +# Output + +```ts +export const foo = + ( + // prettier-ignore + bar as Baz +).qux; +``` + + diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/prettier-ignore/prettier-ignore-nested-unions.ts b/crates/rome_js_formatter/tests/specs/prettier/typescript/prettier-ignore/prettier-ignore-nested-unions.ts new file mode 100644 index 00000000000..335379e3a20 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/prettier-ignore/prettier-ignore-nested-unions.ts @@ -0,0 +1,27 @@ +export type a = + // foo + | foo1&foo2 + // bar + | bar1&bar2 + // prettier-ignore + | ( + | aaaaaaaaaaaaa&1 + // b + | bbbbbbbbbbbbb&2 + ) + // baz + | baz1&baz2; + +export type b = + // foo + | foo1&foo2 + // bar + | bar1&bar2 + | ( + // prettier-ignore + | aaaaaaaaaaaaa&1 + // b + | bbbbbbbbbbbbb&2 + ) + // baz + | baz1&baz2; diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/prettier-ignore/prettier-ignore-nested-unions.ts.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/typescript/prettier-ignore/prettier-ignore-nested-unions.ts.prettier-snap new file mode 100644 index 00000000000..80bbfb024ca --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/prettier-ignore/prettier-ignore-nested-unions.ts.prettier-snap @@ -0,0 +1,23 @@ +export type a = + // foo + | (foo1 & foo2) + // bar + | (bar1 & bar2) + // prettier-ignore + | (| aaaaaaaaaaaaa&1 + // b + | bbbbbbbbbbbbb&2) + // baz + | (baz1 & baz2); + +export type b = + // foo + | (foo1 & foo2) + // bar + | (bar1 & bar2) + // prettier-ignore + | (| aaaaaaaaaaaaa&1 + // b + | bbbbbbbbbbbbb&2) + // baz + | (baz1 & baz2); diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/prettier-ignore/prettier-ignore-nested-unions.ts.snap b/crates/rome_js_formatter/tests/specs/prettier/typescript/prettier-ignore/prettier-ignore-nested-unions.ts.snap new file mode 100644 index 00000000000..5f64f4fe5ca --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/prettier-ignore/prettier-ignore-nested-unions.ts.snap @@ -0,0 +1,108 @@ +--- +source: crates/rome_formatter_test/src/snapshot_builder.rs +info: typescript/prettier-ignore/prettier-ignore-nested-unions.ts +--- + +# Input + +```ts +export type a = + // foo + | foo1&foo2 + // bar + | bar1&bar2 + // prettier-ignore + | ( + | aaaaaaaaaaaaa&1 + // b + | bbbbbbbbbbbbb&2 + ) + // baz + | baz1&baz2; + +export type b = + // foo + | foo1&foo2 + // bar + | bar1&bar2 + | ( + // prettier-ignore + | aaaaaaaaaaaaa&1 + // b + | bbbbbbbbbbbbb&2 + ) + // baz + | baz1&baz2; + +``` + + +# Prettier differences + +```diff +--- Prettier ++++ Rome +@@ -4,9 +4,11 @@ + // bar + | (bar1 & bar2) + // prettier-ignore +- | (| aaaaaaaaaaaaa&1 +- // b +- | bbbbbbbbbbbbb&2) ++ | ( ++ | (aaaaaaaaaaaaa & 1) ++ // b ++ | (bbbbbbbbbbbbb & 2) ++ ) + // baz + | (baz1 & baz2); + +@@ -16,8 +18,10 @@ + // bar + | (bar1 & bar2) + // prettier-ignore +- | (| aaaaaaaaaaaaa&1 +- // b +- | bbbbbbbbbbbbb&2) ++ | ( ++ | (aaaaaaaaaaaaa & 1) ++ // b ++ | (bbbbbbbbbbbbb & 2) ++ ) + // baz + | (baz1 & baz2); +``` + +# Output + +```ts +export type a = + // foo + | (foo1 & foo2) + // bar + | (bar1 & bar2) + // prettier-ignore + | ( + | (aaaaaaaaaaaaa & 1) + // b + | (bbbbbbbbbbbbb & 2) + ) + // baz + | (baz1 & baz2); + +export type b = + // foo + | (foo1 & foo2) + // bar + | (bar1 & bar2) + // prettier-ignore + | ( + | (aaaaaaaaaaaaa & 1) + // b + | (bbbbbbbbbbbbb & 2) + ) + // baz + | (baz1 & baz2); +``` + + diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/prettier-ignore/prettier-ignore-parenthesized-type.ts b/crates/rome_js_formatter/tests/specs/prettier/typescript/prettier-ignore/prettier-ignore-parenthesized-type.ts new file mode 100644 index 00000000000..df2685e43ac --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/prettier-ignore/prettier-ignore-parenthesized-type.ts @@ -0,0 +1,5 @@ +type Foo = + // prettier-ignore + ( + aa + ); diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/prettier-ignore/prettier-ignore-parenthesized-type.ts.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/typescript/prettier-ignore/prettier-ignore-parenthesized-type.ts.prettier-snap new file mode 100644 index 00000000000..cdac1788600 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/prettier-ignore/prettier-ignore-parenthesized-type.ts.prettier-snap @@ -0,0 +1,3 @@ +type Foo = + // prettier-ignore + aa; diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/prettier-ignore/prettier-ignore-parenthesized-type.ts.snap b/crates/rome_js_formatter/tests/specs/prettier/typescript/prettier-ignore/prettier-ignore-parenthesized-type.ts.snap new file mode 100644 index 00000000000..40c178baa88 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/prettier-ignore/prettier-ignore-parenthesized-type.ts.snap @@ -0,0 +1,42 @@ +--- +source: crates/rome_formatter_test/src/snapshot_builder.rs +info: typescript/prettier-ignore/prettier-ignore-parenthesized-type.ts +--- + +# Input + +```ts +type Foo = + // prettier-ignore + ( + aa + ); + +``` + + +# Prettier differences + +```diff +--- Prettier ++++ Rome +@@ -1,3 +1,5 @@ + type Foo = + // prettier-ignore +- aa; ++ ( ++ aa ++ ); +``` + +# Output + +```ts +type Foo = + // prettier-ignore + ( + aa + ); +``` + + diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/satisfies-operators/argument-expansion.ts.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/typescript/satisfies-operators/argument-expansion.ts.prettier-snap index ecbc1c0439d..65a0c0e5705 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/typescript/satisfies-operators/argument-expansion.ts.prettier-snap +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/satisfies-operators/argument-expansion.ts.prettier-snap @@ -1,6 +1,9 @@ -const bar1 = [1, 2, 3].reduce((carry, value) => { - return [...carry, value]; -}, [] satisfies unknown satisfies number[]); +const bar1 = [1, 2, 3].reduce( + (carry, value) => { + return [...carry, value]; + }, + [] satisfies unknown satisfies number[], +); const bar2 = [1, 2, 3].reduce( (carry, value) => { @@ -9,9 +12,12 @@ const bar2 = [1, 2, 3].reduce( [1, 2, 3] satisfies unknown satisfies number[], ); -const bar3 = [1, 2, 3].reduce((carry, value) => { - return { ...carry, [value]: true }; -}, {} satisfies unknown satisfies { [key: number]: boolean }); +const bar3 = [1, 2, 3].reduce( + (carry, value) => { + return { ...carry, [value]: true }; + }, + {} satisfies unknown satisfies { [key: number]: boolean }, +); const bar4 = [1, 2, 3].reduce( (carry, value) => { diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/satisfies-operators/argument-expansion.ts.snap b/crates/rome_js_formatter/tests/specs/prettier/typescript/satisfies-operators/argument-expansion.ts.snap new file mode 100644 index 00000000000..24be235aff7 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/satisfies-operators/argument-expansion.ts.snap @@ -0,0 +1,98 @@ +--- +source: crates/rome_formatter_test/src/snapshot_builder.rs +info: typescript/satisfies-operators/argument-expansion.ts +--- + +# Input + +```ts +const bar1 = [1,2,3].reduce((carry, value) => { + return [...carry, value]; +}, ([] satisfies unknown) satisfies number[]); + +const bar2 = [1,2,3].reduce((carry, value) => { + return [...carry, value]; +}, ([1, 2, 3] satisfies unknown) satisfies number[]); + +const bar3 = [1,2,3].reduce((carry, value) => { + return {...carry, [value]: true}; +}, ({} satisfies unknown) satisfies {[key: number]: boolean}); + +const bar4 = [1,2,3].reduce((carry, value) => { + return {...carry, [value]: true}; +}, ({1: true} satisfies unknown) satisfies {[key: number]: boolean}); + +const bar5 = [1,2,3].reduce((carry, value) => { + return [...carry, value]; +}, [] satisfies foo); + +``` + + +# Prettier differences + +```diff +--- Prettier ++++ Rome +@@ -1,9 +1,6 @@ +-const bar1 = [1, 2, 3].reduce( +- (carry, value) => { +- return [...carry, value]; +- }, +- [] satisfies unknown satisfies number[], +-); ++const bar1 = [1, 2, 3].reduce((carry, value) => { ++ return [...carry, value]; ++}, [] satisfies unknown satisfies number[]); + + const bar2 = [1, 2, 3].reduce( + (carry, value) => { +@@ -12,12 +9,9 @@ + [1, 2, 3] satisfies unknown satisfies number[], + ); + +-const bar3 = [1, 2, 3].reduce( +- (carry, value) => { +- return { ...carry, [value]: true }; +- }, +- {} satisfies unknown satisfies { [key: number]: boolean }, +-); ++const bar3 = [1, 2, 3].reduce((carry, value) => { ++ return { ...carry, [value]: true }; ++}, {} satisfies unknown satisfies { [key: number]: boolean }); + + const bar4 = [1, 2, 3].reduce( + (carry, value) => { +``` + +# Output + +```ts +const bar1 = [1, 2, 3].reduce((carry, value) => { + return [...carry, value]; +}, [] satisfies unknown satisfies number[]); + +const bar2 = [1, 2, 3].reduce( + (carry, value) => { + return [...carry, value]; + }, + [1, 2, 3] satisfies unknown satisfies number[], +); + +const bar3 = [1, 2, 3].reduce((carry, value) => { + return { ...carry, [value]: true }; +}, {} satisfies unknown satisfies { [key: number]: boolean }); + +const bar4 = [1, 2, 3].reduce( + (carry, value) => { + return { ...carry, [value]: true }; + }, + { 1: true } satisfies unknown satisfies { [key: number]: boolean }, +); + +const bar5 = [1, 2, 3].reduce((carry, value) => { + return [...carry, value]; +}, [] satisfies foo); +``` + + diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/satisfies-operators/satisfies.ts.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/typescript/satisfies-operators/satisfies.ts.prettier-snap index c38ca45bc87..45c2ddba800 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/typescript/satisfies-operators/satisfies.ts.prettier-snap +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/satisfies-operators/satisfies.ts.prettier-snap @@ -1,6 +1,6 @@ ({}) satisfies {}; ({}) satisfies X; -() => ({} satisfies X); +() => ({}) satisfies X; this.isTabActionBar((e.target || e.srcElement) satisfies HTMLElement); "current" in (props.pagination satisfies Object); diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/satisfies-operators/satisfies.ts.snap b/crates/rome_js_formatter/tests/specs/prettier/typescript/satisfies-operators/satisfies.ts.snap deleted file mode 100644 index 0d964d8ffbe..00000000000 --- a/crates/rome_js_formatter/tests/specs/prettier/typescript/satisfies-operators/satisfies.ts.snap +++ /dev/null @@ -1,78 +0,0 @@ ---- -source: crates/rome_formatter_test/src/snapshot_builder.rs -assertion_line: 212 -info: typescript/satisfies-operators/satisfies.ts ---- - -# Input - -```ts -({}) satisfies {}; -({}) satisfies X; -() => ({}) satisfies X; -this.isTabActionBar((e.target || e.srcElement) satisfies HTMLElement); - -'current' in (props.pagination satisfies Object); -('current' in props.pagination) satisfies Object; -start + (yearSelectTotal satisfies number); -(start + yearSelectTotal) satisfies number; -scrollTop > (visibilityHeight satisfies number); -(scrollTop > visibilityHeight) satisfies number; -(bValue satisfies boolean) ? 0 : -1; - -async function g1() { - const test = (await 'foo') satisfies number; -} - -var x = (v => v) satisfies (x: number) => string; - -foo satisfies unknown satisfies Bar; -foo satisfies unknown as Bar; -foo as unknown satisfies Bar; - -``` - - -# Prettier differences - -```diff ---- Prettier -+++ Rome -@@ -1,6 +1,6 @@ - ({}) satisfies {}; - ({}) satisfies X; --() => ({} satisfies X); -+() => ({}) satisfies X; - this.isTabActionBar((e.target || e.srcElement) satisfies HTMLElement); - - "current" in (props.pagination satisfies Object); -``` - -# Output - -```ts -({}) satisfies {}; -({}) satisfies X; -() => ({}) satisfies X; -this.isTabActionBar((e.target || e.srcElement) satisfies HTMLElement); - -"current" in (props.pagination satisfies Object); -("current" in props.pagination) satisfies Object; -start + (yearSelectTotal satisfies number); -(start + yearSelectTotal) satisfies number; -scrollTop > (visibilityHeight satisfies number); -(scrollTop > visibilityHeight) satisfies number; -(bValue satisfies boolean) ? 0 : -1; - -async function g1() { - const test = (await "foo") satisfies number; -} - -var x = ((v) => v) satisfies (x: number) => string; - -foo satisfies unknown satisfies Bar; -foo satisfies unknown as Bar; -foo as unknown satisfies Bar; -``` - - diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/trailing-comma/arrow-functions.tsx.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/typescript/trailing-comma/arrow-functions.tsx.prettier-snap index a35bfe5a7c3..a1555939a25 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/typescript/trailing-comma/arrow-functions.tsx.prettier-snap +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/trailing-comma/arrow-functions.tsx.prettier-snap @@ -1,4 +1,4 @@ -const f1 = () => 1; +const f1 = () => 1; const f2 = < Tttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttt, >() => 1; diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/trailing-comma/arrow-functions.tsx.snap b/crates/rome_js_formatter/tests/specs/prettier/typescript/trailing-comma/arrow-functions.tsx.snap deleted file mode 100644 index 629c7886680..00000000000 --- a/crates/rome_js_formatter/tests/specs/prettier/typescript/trailing-comma/arrow-functions.tsx.snap +++ /dev/null @@ -1,40 +0,0 @@ ---- -source: crates/rome_formatter_test/src/snapshot_builder.rs -assertion_line: 212 -info: typescript/trailing-comma/arrow-functions.tsx ---- - -# Input - -```tsx -const f1 = () => 1; -const f2 = < - Tttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttt, ->() => 1; - -``` - - -# Prettier differences - -```diff ---- Prettier -+++ Rome -@@ -1,4 +1,4 @@ --const f1 = () => 1; -+const f1 = () => 1; - const f2 = < - Tttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttt, - >() => 1; -``` - -# Output - -```tsx -const f1 = () => 1; -const f2 = < - Tttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttt, ->() => 1; -``` - - diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/tsx/type-parameters.tsx.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/typescript/tsx/type-parameters.tsx.prettier-snap index 31e370c9a8b..0e1ed719e25 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/typescript/tsx/type-parameters.tsx.prettier-snap +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/tsx/type-parameters.tsx.prettier-snap @@ -1,4 +1,4 @@ -const functionName1 = (arg) => false; +const functionName1 = (arg) => false; const functionName2 = (arg) => false; const functionName3 = (arg) => false; diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/tsx/type-parameters.tsx.snap b/crates/rome_js_formatter/tests/specs/prettier/typescript/tsx/type-parameters.tsx.snap deleted file mode 100644 index 49e983b8ca1..00000000000 --- a/crates/rome_js_formatter/tests/specs/prettier/typescript/tsx/type-parameters.tsx.snap +++ /dev/null @@ -1,74 +0,0 @@ ---- -source: crates/rome_formatter_test/src/snapshot_builder.rs -assertion_line: 212 -info: typescript/tsx/type-parameters.tsx ---- - -# Input - -```tsx -const functionName1 = (arg) => false; -const functionName2 = (arg) => false; -const functionName3 = (arg) => false; - -function functionName4() { - return false; -} - -functionName5(); - -interface Interface1 { - one: "one"; -} - -interface Interface2 { - two: Two; -} - -type Type1 = "type1"; - -type Type2 = Two; - -``` - - -# Prettier differences - -```diff ---- Prettier -+++ Rome -@@ -1,4 +1,4 @@ --const functionName1 = (arg) => false; -+const functionName1 = (arg) => false; - const functionName2 = (arg) => false; - const functionName3 = (arg) => false; - -``` - -# Output - -```tsx -const functionName1 = (arg) => false; -const functionName2 = (arg) => false; -const functionName3 = (arg) => false; - -function functionName4() { - return false; -} - -functionName5(); - -interface Interface1 { - one: "one"; -} - -interface Interface2 { - two: Two; -} - -type Type1 = "type1"; - -type Type2 = Two; -``` - - diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/tuple/dangling-comments.ts b/crates/rome_js_formatter/tests/specs/prettier/typescript/tuple/dangling-comments.ts new file mode 100644 index 00000000000..9681fc1c6d3 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/tuple/dangling-comments.ts @@ -0,0 +1,27 @@ +type Foo1 = [/* comment */]; + +type Foo2 = [ + // comment +]; + +type Foo3 = [ + // comment1 + // comment2 +]; + +type Foo4 = [ + // comment1 + + // comment2 +]; + +type Foo5 = [ + /* comment1 */ +]; + +type Foo6 = [ + /* comment1 */ + + /* comment2 */ +]; + diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/tuple/dangling-comments.ts.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/typescript/tuple/dangling-comments.ts.prettier-snap new file mode 100644 index 00000000000..2c730f7d2e6 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/tuple/dangling-comments.ts.prettier-snap @@ -0,0 +1,26 @@ +type Foo1 = [ + /* comment */ +]; + +type Foo2 = [ + // comment +]; + +type Foo3 = [ + // comment1 + // comment2 +]; + +type Foo4 = [ + // comment1 + // comment2 +]; + +type Foo5 = [ + /* comment1 */ +]; + +type Foo6 = [ + /* comment1 */ + /* comment2 */ +]; diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/tuple/dangling-comments.ts.snap b/crates/rome_js_formatter/tests/specs/prettier/typescript/tuple/dangling-comments.ts.snap new file mode 100644 index 00000000000..f748e4d1e27 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/tuple/dangling-comments.ts.snap @@ -0,0 +1,93 @@ +--- +source: crates/rome_formatter_test/src/snapshot_builder.rs +info: typescript/tuple/dangling-comments.ts +--- + +# Input + +```ts +type Foo1 = [/* comment */]; + +type Foo2 = [ + // comment +]; + +type Foo3 = [ + // comment1 + // comment2 +]; + +type Foo4 = [ + // comment1 + + // comment2 +]; + +type Foo5 = [ + /* comment1 */ +]; + +type Foo6 = [ + /* comment1 */ + + /* comment2 */ +]; + + +``` + + +# Prettier differences + +```diff +--- Prettier ++++ Rome +@@ -1,6 +1,4 @@ +-type Foo1 = [ +- /* comment */ +-]; ++type Foo1 = [/* comment */]; + + type Foo2 = [ + // comment +@@ -16,9 +14,7 @@ + // comment2 + ]; + +-type Foo5 = [ +- /* comment1 */ +-]; ++type Foo5 = [/* comment1 */]; + + type Foo6 = [ + /* comment1 */ +``` + +# Output + +```ts +type Foo1 = [/* comment */]; + +type Foo2 = [ + // comment +]; + +type Foo3 = [ + // comment1 + // comment2 +]; + +type Foo4 = [ + // comment1 + // comment2 +]; + +type Foo5 = [/* comment1 */]; + +type Foo6 = [ + /* comment1 */ + /* comment2 */ +]; +``` + + diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/typeparams/const.ts.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/typescript/typeparams/const.ts.prettier-snap index b0f86aa9542..05f4f427370 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/typescript/typeparams/const.ts.prettier-snap +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/typeparams/const.ts.prettier-snap @@ -2,7 +2,7 @@ function a() {} function b() {} function c() {} declare function d(); -() => {}; +() => {}; () => {}; (function () {}); (function () {}); diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/typeparams/const.ts.snap b/crates/rome_js_formatter/tests/specs/prettier/typescript/typeparams/const.ts.snap index 76d649a9b23..943ca5c75c1 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/typescript/typeparams/const.ts.snap +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/typeparams/const.ts.snap @@ -47,6 +47,15 @@ class _ { ```diff --- Prettier +++ Rome +@@ -2,7 +2,7 @@ + function b() {} + function c() {} + declare function d(); +-() => {}; ++() => {}; + () => {}; + (function () {}); + (function () {}); @@ -11,18 +11,18 @@ class A {} class B {} @@ -57,9 +66,9 @@ class _ { (class {}); (class {}); (class {}); +-(class {}); +(class {}); (class {}); --(class {}); interface I {} interface J {} diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/typeparams/line-breaking-after-extends-2.ts b/crates/rome_js_formatter/tests/specs/prettier/typescript/typeparams/line-breaking-after-extends-2.ts new file mode 100644 index 00000000000..75922ce660e --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/typeparams/line-breaking-after-extends-2.ts @@ -0,0 +1,33 @@ +a = { + parseFunctionBodyAndFinish< + T extends + | N.Function + | N.TSDeclareMethod + | N.TSDeclareFunction + | N.ClassPrivateMethod, + >() {} +} + +function parseFunctionBodyAndFinish< + T extends + | N.Function + | N.TSDeclareMethod + | N.TSDeclareFunction + | N.ClassPrivateMethod + | Foo + | Bar + | Baz +>(); + +function parseFunctionBodyAndFinish< + T extends // comment + N.Function | N.TSDeclareMethod | Baz +>(); + +function makeChainWalker< + ArgT extends { + options: ValidatedOptions; + dirname: string; + filepath?: string; + }, +>() {} diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/typeparams/line-breaking-after-extends-2.ts.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/typescript/typeparams/line-breaking-after-extends-2.ts.prettier-snap new file mode 100644 index 00000000000..09c8494447e --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/typeparams/line-breaking-after-extends-2.ts.prettier-snap @@ -0,0 +1,33 @@ +a = { + parseFunctionBodyAndFinish< + T extends + | N.Function + | N.TSDeclareMethod + | N.TSDeclareFunction + | N.ClassPrivateMethod, + >() {}, +}; + +function parseFunctionBodyAndFinish< + T extends + | N.Function + | N.TSDeclareMethod + | N.TSDeclareFunction + | N.ClassPrivateMethod + | Foo + | Bar + | Baz, +>(); + +function parseFunctionBodyAndFinish< + T extends // comment + N.Function | N.TSDeclareMethod | Baz, +>(); + +function makeChainWalker< + ArgT extends { + options: ValidatedOptions; + dirname: string; + filepath?: string; + }, +>() {} diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/typeparams/line-breaking-after-extends-2.ts.snap b/crates/rome_js_formatter/tests/specs/prettier/typescript/typeparams/line-breaking-after-extends-2.ts.snap new file mode 100644 index 00000000000..41527c701a5 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/typeparams/line-breaking-after-extends-2.ts.snap @@ -0,0 +1,100 @@ +--- +source: crates/rome_formatter_test/src/snapshot_builder.rs +info: typescript/typeparams/line-breaking-after-extends-2.ts +--- + +# Input + +```ts +a = { + parseFunctionBodyAndFinish< + T extends + | N.Function + | N.TSDeclareMethod + | N.TSDeclareFunction + | N.ClassPrivateMethod, + >() {} +} + +function parseFunctionBodyAndFinish< + T extends + | N.Function + | N.TSDeclareMethod + | N.TSDeclareFunction + | N.ClassPrivateMethod + | Foo + | Bar + | Baz +>(); + +function parseFunctionBodyAndFinish< + T extends // comment + N.Function | N.TSDeclareMethod | Baz +>(); + +function makeChainWalker< + ArgT extends { + options: ValidatedOptions; + dirname: string; + filepath?: string; + }, +>() {} + +``` + + +# Prettier differences + +```diff +--- Prettier ++++ Rome +@@ -21,7 +21,7 @@ + + function parseFunctionBodyAndFinish< + T extends // comment +- N.Function | N.TSDeclareMethod | Baz, ++ N.Function | N.TSDeclareMethod | Baz, + >(); + + function makeChainWalker< +``` + +# Output + +```ts +a = { + parseFunctionBodyAndFinish< + T extends + | N.Function + | N.TSDeclareMethod + | N.TSDeclareFunction + | N.ClassPrivateMethod, + >() {}, +}; + +function parseFunctionBodyAndFinish< + T extends + | N.Function + | N.TSDeclareMethod + | N.TSDeclareFunction + | N.ClassPrivateMethod + | Foo + | Bar + | Baz, +>(); + +function parseFunctionBodyAndFinish< + T extends // comment + N.Function | N.TSDeclareMethod | Baz, +>(); + +function makeChainWalker< + ArgT extends { + options: ValidatedOptions; + dirname: string; + filepath?: string; + }, +>() {} +``` + + diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/typeparams/line-breaking-after-extends.ts b/crates/rome_js_formatter/tests/specs/prettier/typescript/typeparams/line-breaking-after-extends.ts new file mode 100644 index 00000000000..678990b4763 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/typeparams/line-breaking-after-extends.ts @@ -0,0 +1,17 @@ +export type OuterType1< + LongerLongerLongerLongerInnerType extends LongerLongerLongerLongerOtherType +> = { a: 1 }; + +export type OuterType2< + LongerLongerLongerLongerInnerType extends LongerLongerLongerLongerLongerLongerLongerLongerOtherType +> = { a: 1 }; + +export type OuterType3< + LongerLongerLongerLongerInnerType extends LongerLongerLongerLongerLongerLo.ngerLongerLongerOtherType +> = { a: 1 }; + +export type OuterType4< + LongerLongerLongerLongerInnerType extends + | LongerLongerLongerLongerLongerLo + | ngerLongerLongerOtherType +> = { a: 1 }; diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/typeparams/line-breaking-after-extends.ts.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/typescript/typeparams/line-breaking-after-extends.ts.prettier-snap new file mode 100644 index 00000000000..cc3ecc4b013 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/typeparams/line-breaking-after-extends.ts.prettier-snap @@ -0,0 +1,20 @@ +export type OuterType1< + LongerLongerLongerLongerInnerType extends + LongerLongerLongerLongerOtherType, +> = { a: 1 }; + +export type OuterType2< + LongerLongerLongerLongerInnerType extends + LongerLongerLongerLongerLongerLongerLongerLongerOtherType, +> = { a: 1 }; + +export type OuterType3< + LongerLongerLongerLongerInnerType extends + LongerLongerLongerLongerLongerLo.ngerLongerLongerOtherType, +> = { a: 1 }; + +export type OuterType4< + LongerLongerLongerLongerInnerType extends + | LongerLongerLongerLongerLongerLo + | ngerLongerLongerOtherType, +> = { a: 1 }; diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/typeparams/line-breaking-after-extends.ts.snap b/crates/rome_js_formatter/tests/specs/prettier/typescript/typeparams/line-breaking-after-extends.ts.snap new file mode 100644 index 00000000000..5c9880f0447 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/typeparams/line-breaking-after-extends.ts.snap @@ -0,0 +1,86 @@ +--- +source: crates/rome_formatter_test/src/snapshot_builder.rs +info: typescript/typeparams/line-breaking-after-extends.ts +--- + +# Input + +```ts +export type OuterType1< + LongerLongerLongerLongerInnerType extends LongerLongerLongerLongerOtherType +> = { a: 1 }; + +export type OuterType2< + LongerLongerLongerLongerInnerType extends LongerLongerLongerLongerLongerLongerLongerLongerOtherType +> = { a: 1 }; + +export type OuterType3< + LongerLongerLongerLongerInnerType extends LongerLongerLongerLongerLongerLo.ngerLongerLongerOtherType +> = { a: 1 }; + +export type OuterType4< + LongerLongerLongerLongerInnerType extends + | LongerLongerLongerLongerLongerLo + | ngerLongerLongerOtherType +> = { a: 1 }; + +``` + + +# Prettier differences + +```diff +--- Prettier ++++ Rome +@@ -1,16 +1,13 @@ + export type OuterType1< +- LongerLongerLongerLongerInnerType extends +- LongerLongerLongerLongerOtherType, ++ LongerLongerLongerLongerInnerType extends LongerLongerLongerLongerOtherType, + > = { a: 1 }; + + export type OuterType2< +- LongerLongerLongerLongerInnerType extends +- LongerLongerLongerLongerLongerLongerLongerLongerOtherType, ++ LongerLongerLongerLongerInnerType extends LongerLongerLongerLongerLongerLongerLongerLongerOtherType, + > = { a: 1 }; + + export type OuterType3< +- LongerLongerLongerLongerInnerType extends +- LongerLongerLongerLongerLongerLo.ngerLongerLongerOtherType, ++ LongerLongerLongerLongerInnerType extends LongerLongerLongerLongerLongerLo.ngerLongerLongerOtherType, + > = { a: 1 }; + + export type OuterType4< +``` + +# Output + +```ts +export type OuterType1< + LongerLongerLongerLongerInnerType extends LongerLongerLongerLongerOtherType, +> = { a: 1 }; + +export type OuterType2< + LongerLongerLongerLongerInnerType extends LongerLongerLongerLongerLongerLongerLongerLongerOtherType, +> = { a: 1 }; + +export type OuterType3< + LongerLongerLongerLongerInnerType extends LongerLongerLongerLongerLongerLo.ngerLongerLongerOtherType, +> = { a: 1 }; + +export type OuterType4< + LongerLongerLongerLongerInnerType extends + | LongerLongerLongerLongerLongerLo + | ngerLongerLongerOtherType, +> = { a: 1 }; +``` + +# Lines exceeding max width of 80 characters +``` + 2: LongerLongerLongerLongerInnerType extends LongerLongerLongerLongerOtherType, + 6: LongerLongerLongerLongerInnerType extends LongerLongerLongerLongerLongerLongerLongerLongerOtherType, + 10: LongerLongerLongerLongerInnerType extends LongerLongerLongerLongerLongerLo.ngerLongerLongerOtherType, +``` + + diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/typeparams/trailing-comma/type-paramters.ts b/crates/rome_js_formatter/tests/specs/prettier/typescript/typeparams/trailing-comma/type-paramters.ts new file mode 100644 index 00000000000..4d2c96c92a5 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/typeparams/trailing-comma/type-paramters.ts @@ -0,0 +1,2 @@ +type FooThisNameIsVeryLongSoThatItBreaksToTheNextLine = Something; +type ShortName = Something; diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/typeparams/trailing-comma/type-paramters.ts.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/typescript/typeparams/trailing-comma/type-paramters.ts.prettier-snap new file mode 100644 index 00000000000..e92378274bf --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/typeparams/trailing-comma/type-paramters.ts.prettier-snap @@ -0,0 +1,5 @@ +type FooThisNameIsVeryLongSoThatItBreaksToTheNextLine = Something< + FirstParam, + SecondParam +>; +type ShortName = Something; diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/union/consistent-with-flow/comment.ts b/crates/rome_js_formatter/tests/specs/prettier/typescript/union/consistent-with-flow/comment.ts new file mode 100644 index 00000000000..72ae3933979 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/union/consistent-with-flow/comment.ts @@ -0,0 +1,4 @@ +type A1 = /* 4 */ ( + | A + | B +)[] diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/union/consistent-with-flow/comment.ts.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/typescript/union/consistent-with-flow/comment.ts.prettier-snap new file mode 100644 index 00000000000..f0abd9a13eb --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/union/consistent-with-flow/comment.ts.prettier-snap @@ -0,0 +1 @@ +type A1 = /* 4 */ (A | B)[]; diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/union/consistent-with-flow/comments.ts b/crates/rome_js_formatter/tests/specs/prettier/typescript/union/consistent-with-flow/comments.ts new file mode 100644 index 00000000000..d3f32ddd12d --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/union/consistent-with-flow/comments.ts @@ -0,0 +1,10 @@ +type A1 = a /* 1 */ | b; +type A2 = a | /* 1 */ b; +type A3 = (a /* 1 */) | b; +type A4 = a | (/* 1 */ b); +type A5 = (a) /* 1 */ | b; +type A6 = a | /* 1 */ (b); + +type B1 = a /* 1 */ /* 2 */ | b; +type B2 = a /* 1 */ | /* 2 */ b; +type B3 = a | /* 1 */ /* 2 */ b; diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/union/consistent-with-flow/comments.ts.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/typescript/union/consistent-with-flow/comments.ts.prettier-snap new file mode 100644 index 00000000000..fda1eb38798 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/union/consistent-with-flow/comments.ts.prettier-snap @@ -0,0 +1,10 @@ +type A1 = a /* 1 */ | b; +type A2 = a | /* 1 */ b; +type A3 = a /* 1 */ | b; +type A4 = a | /* 1 */ b; +type A5 = a /* 1 */ | b; +type A6 = a | /* 1 */ b; + +type B1 = a /* 1 */ /* 2 */ | b; +type B2 = a /* 1 */ | /* 2 */ b; +type B3 = a | /* 1 */ /* 2 */ b; diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/union/consistent-with-flow/prettier-ignore.ts b/crates/rome_js_formatter/tests/specs/prettier/typescript/union/consistent-with-flow/prettier-ignore.ts new file mode 100644 index 00000000000..3927f292e6d --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/union/consistent-with-flow/prettier-ignore.ts @@ -0,0 +1,25 @@ +export type a = + // foo + | foo1&foo2 + // bar + | bar1&bar2 + // prettier-ignore + | qux1&qux2; + +export type b = + // foo + | foo1&foo2 + // bar + | bar1&bar2 + // prettier-ignore + | qux1&qux2 + // baz + | baz1&baz2; + +export type c = + // prettier-ignore + | foo1&foo2 + // bar + | bar1&bar2 + // qux + | qux1&qux2; diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/union/consistent-with-flow/prettier-ignore.ts.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/typescript/union/consistent-with-flow/prettier-ignore.ts.prettier-snap new file mode 100644 index 00000000000..2aff8a4bdb3 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/union/consistent-with-flow/prettier-ignore.ts.prettier-snap @@ -0,0 +1,25 @@ +export type a = + // foo + | (foo1 & foo2) + // bar + | (bar1 & bar2) + // prettier-ignore + | (qux1&qux2); + +export type b = + // foo + | (foo1 & foo2) + // bar + | (bar1 & bar2) + // prettier-ignore + | (qux1&qux2) + // baz + | (baz1 & baz2); + +export type c = + // prettier-ignore + | (foo1&foo2) + // bar + | (bar1 & bar2) + // qux + | (qux1 & qux2); diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/union/consistent-with-flow/prettier-ignore.ts.snap b/crates/rome_js_formatter/tests/specs/prettier/typescript/union/consistent-with-flow/prettier-ignore.ts.snap new file mode 100644 index 00000000000..b7bca6dc200 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/union/consistent-with-flow/prettier-ignore.ts.snap @@ -0,0 +1,100 @@ +--- +source: crates/rome_formatter_test/src/snapshot_builder.rs +info: typescript/union/consistent-with-flow/prettier-ignore.ts +--- + +# Input + +```ts +export type a = + // foo + | foo1&foo2 + // bar + | bar1&bar2 + // prettier-ignore + | qux1&qux2; + +export type b = + // foo + | foo1&foo2 + // bar + | bar1&bar2 + // prettier-ignore + | qux1&qux2 + // baz + | baz1&baz2; + +export type c = + // prettier-ignore + | foo1&foo2 + // bar + | bar1&bar2 + // qux + | qux1&qux2; + +``` + + +# Prettier differences + +```diff +--- Prettier ++++ Rome +@@ -4,7 +4,7 @@ + // bar + | (bar1 & bar2) + // prettier-ignore +- | (qux1&qux2); ++ | qux1&qux2; + + export type b = + // foo +@@ -12,13 +12,13 @@ + // bar + | (bar1 & bar2) + // prettier-ignore +- | (qux1&qux2) ++ | qux1&qux2 + // baz + | (baz1 & baz2); + + export type c = + // prettier-ignore +- | (foo1&foo2) ++ | foo1&foo2 + // bar + | (bar1 & bar2) + // qux +``` + +# Output + +```ts +export type a = + // foo + | (foo1 & foo2) + // bar + | (bar1 & bar2) + // prettier-ignore + | qux1&qux2; + +export type b = + // foo + | (foo1 & foo2) + // bar + | (bar1 & bar2) + // prettier-ignore + | qux1&qux2 + // baz + | (baz1 & baz2); + +export type c = + // prettier-ignore + | foo1&foo2 + // bar + | (bar1 & bar2) + // qux + | (qux1 & qux2); +``` + + diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/union/consistent-with-flow/within-tuple.ts b/crates/rome_js_formatter/tests/specs/prettier/typescript/union/consistent-with-flow/within-tuple.ts new file mode 100644 index 00000000000..7539bc9d786 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/union/consistent-with-flow/within-tuple.ts @@ -0,0 +1,64 @@ +type A = [AAAAAAAAAAAAAAAAAAAAAA | BBBBBBBBBBBBBBBBBBBBBB | CCCCCCCCCCCCCCCCCCCCCC | DDDDDDDDDDDDDDDDDDDDDD] + +type B = [ + | AAAAAAAAAAAAAAAAAAAAAA + | BBBBBBBBBBBBBBBBBBBBBB + | CCCCCCCCCCCCCCCCCCCCCC + | DDDDDDDDDDDDDDDDDDDDDD +] + +type B1 = [ + ( + | AAAAAAAAAAAAAAAAAAAAAA + | BBBBBBBBBBBBBBBBBBBBBB + | CCCCCCCCCCCCCCCCCCCCCC + | DDDDDDDDDDDDDDDDDDDDDD + ) +] + +type C = [ + | [AAAAAAAAAAAAAAAAAAAAAA | BBBBBBBBBBBBBBBBBBBBBB | CCCCCCCCCCCCCCCCCCCCCC | DDDDDDDDDDDDDDDDDDDDDD] + | [AAAAAAAAAAAAAAAAAAAAAA | BBBBBBBBBBBBBBBBBBBBBB | CCCCCCCCCCCCCCCCCCCCCC | DDDDDDDDDDDDDDDDDDDDDD] +] + +type D = [ + (AAAAAAAAAAAAAAAAAAAAAA | BBBBBBBBBBBBBBBBBBBBBB | CCCCCCCCCCCCCCCCCCCCCC | DDDDDDDDDDDDDDDDDDDDDD), + (AAAAAAAAAAAAAAAAAAAAAA | BBBBBBBBBBBBBBBBBBBBBB | CCCCCCCCCCCCCCCCCCCCCC | DDDDDDDDDDDDDDDDDDDDDD) +] + +type D1 = [ + ( + | AAAAAAAAAAAAAAAAAAAAAA + | BBBBBBBBBBBBBBBBBBBBBB + | CCCCCCCCCCCCCCCCCCCCCC + | DDDDDDDDDDDDDDDDDDDDDD + ), + ( + | AAAAAAAAAAAAAAAAAAAAAA + | BBBBBBBBBBBBBBBBBBBBBB + | CCCCCCCCCCCCCCCCCCCCCC + | DDDDDDDDDDDDDDDDDDDDDD + ) +] + +type D2 = [ + | AAAAAAAAAAAAAAAAAAAAAA + | BBBBBBBBBBBBBBBBBBBBBB + | CCCCCCCCCCCCCCCCCCCCCC + | DDDDDDDDDDDDDDDDDDDDDD, + | AAAAAAAAAAAAAAAAAAAAAA + | BBBBBBBBBBBBBBBBBBBBBB + | CCCCCCCCCCCCCCCCCCCCCC + | DDDDDDDDDDDDDDDDDDDDDD +] + +type E = [ AA | BB, AA | BB ] + +type F = [ + | AAAAAAAAAAAAAAAAAAAAAA + | BBBBBBBBBBBBBBBBBBBBBB + | CCCCCCCCCCCCCCCCCCCCCC + | DDDDDDDDDDDDDDDDDDDDDD, + | AAAAAAAAAAAAAAAAAAAAAA + | BBBBBBBBBBBBBBBBBBBBBB +] diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/union/consistent-with-flow/within-tuple.ts.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/typescript/union/consistent-with-flow/within-tuple.ts.prettier-snap new file mode 100644 index 00000000000..451e7b9383c --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/union/consistent-with-flow/within-tuple.ts.prettier-snap @@ -0,0 +1,92 @@ +type A = [ + | AAAAAAAAAAAAAAAAAAAAAA + | BBBBBBBBBBBBBBBBBBBBBB + | CCCCCCCCCCCCCCCCCCCCCC + | DDDDDDDDDDDDDDDDDDDDDD, +]; + +type B = [ + | AAAAAAAAAAAAAAAAAAAAAA + | BBBBBBBBBBBBBBBBBBBBBB + | CCCCCCCCCCCCCCCCCCCCCC + | DDDDDDDDDDDDDDDDDDDDDD, +]; + +type B1 = [ + | AAAAAAAAAAAAAAAAAAAAAA + | BBBBBBBBBBBBBBBBBBBBBB + | CCCCCCCCCCCCCCCCCCCCCC + | DDDDDDDDDDDDDDDDDDDDDD, +]; + +type C = [ + | [ + | AAAAAAAAAAAAAAAAAAAAAA + | BBBBBBBBBBBBBBBBBBBBBB + | CCCCCCCCCCCCCCCCCCCCCC + | DDDDDDDDDDDDDDDDDDDDDD, + ] + | [ + | AAAAAAAAAAAAAAAAAAAAAA + | BBBBBBBBBBBBBBBBBBBBBB + | CCCCCCCCCCCCCCCCCCCCCC + | DDDDDDDDDDDDDDDDDDDDDD, + ], +]; + +type D = [ + ( + | AAAAAAAAAAAAAAAAAAAAAA + | BBBBBBBBBBBBBBBBBBBBBB + | CCCCCCCCCCCCCCCCCCCCCC + | DDDDDDDDDDDDDDDDDDDDDD + ), + ( + | AAAAAAAAAAAAAAAAAAAAAA + | BBBBBBBBBBBBBBBBBBBBBB + | CCCCCCCCCCCCCCCCCCCCCC + | DDDDDDDDDDDDDDDDDDDDDD + ), +]; + +type D1 = [ + ( + | AAAAAAAAAAAAAAAAAAAAAA + | BBBBBBBBBBBBBBBBBBBBBB + | CCCCCCCCCCCCCCCCCCCCCC + | DDDDDDDDDDDDDDDDDDDDDD + ), + ( + | AAAAAAAAAAAAAAAAAAAAAA + | BBBBBBBBBBBBBBBBBBBBBB + | CCCCCCCCCCCCCCCCCCCCCC + | DDDDDDDDDDDDDDDDDDDDDD + ), +]; + +type D2 = [ + ( + | AAAAAAAAAAAAAAAAAAAAAA + | BBBBBBBBBBBBBBBBBBBBBB + | CCCCCCCCCCCCCCCCCCCCCC + | DDDDDDDDDDDDDDDDDDDDDD + ), + ( + | AAAAAAAAAAAAAAAAAAAAAA + | BBBBBBBBBBBBBBBBBBBBBB + | CCCCCCCCCCCCCCCCCCCCCC + | DDDDDDDDDDDDDDDDDDDDDD + ), +]; + +type E = [AA | BB, AA | BB]; + +type F = [ + ( + | AAAAAAAAAAAAAAAAAAAAAA + | BBBBBBBBBBBBBBBBBBBBBB + | CCCCCCCCCCCCCCCCCCCCCC + | DDDDDDDDDDDDDDDDDDDDDD + ), + AAAAAAAAAAAAAAAAAAAAAA | BBBBBBBBBBBBBBBBBBBBBB, +]; diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/union/inlining.ts b/crates/rome_js_formatter/tests/specs/prettier/typescript/union/inlining.ts deleted file mode 100644 index 76f7dfb1820..00000000000 --- a/crates/rome_js_formatter/tests/specs/prettier/typescript/union/inlining.ts +++ /dev/null @@ -1,41 +0,0 @@ -interface RelayProps { - articles: a | null, -} -interface RelayProps { - articles: Array<{ - __id: string, - } | null> | null | void, -} - -type UploadState - // The upload hasnt begun yet - = {type: "Not_begun"} - // The upload timed out - | {type: "Timed_out"} - // Failed somewhere on the line - | {type: "Failed", error: E, errorMsg: EM} - // Uploading to aws3 and CreatePostMutation succeeded - | {type: "Success", data: D}; - -type UploadState2 - // The upload hasnt begun yet - = A - // The upload timed out - | B - // Failed somewhere on the line - | C - // Uploading to aws3 and CreatePostMutation succeeded - | D; - -type window = Window & { - __REDUX_DEVTOOLS_EXTENSION_COMPOSE__: Function; -}; - -type T1 = (number | string)["toString"]; -type T2 = ((number | string))["toString"]; -type T3 = (((number | string)))["toString"]; -type T4 = ((((number | string))))["toString"]; -type T5 = number | ((arg: any) => void); -type T6 = number | (((arg: any) => void)); -type T7 = number | ((((arg: any) => void))); -type T8 = number | (((((arg: any) => void)))); diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/union/inlining.ts.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/typescript/union/inlining.ts.prettier-snap deleted file mode 100644 index 937fbea4e07..00000000000 --- a/crates/rome_js_formatter/tests/specs/prettier/typescript/union/inlining.ts.prettier-snap +++ /dev/null @@ -1,41 +0,0 @@ -interface RelayProps { - articles: a | null; -} -interface RelayProps { - articles: Array<{ - __id: string; - } | null> | null | void; -} - -type UploadState = - // The upload hasnt begun yet - | { type: "Not_begun" } - // The upload timed out - | { type: "Timed_out" } - // Failed somewhere on the line - | { type: "Failed"; error: E; errorMsg: EM } - // Uploading to aws3 and CreatePostMutation succeeded - | { type: "Success"; data: D }; - -type UploadState2 = - // The upload hasnt begun yet - | A - // The upload timed out - | B - // Failed somewhere on the line - | C - // Uploading to aws3 and CreatePostMutation succeeded - | D; - -type window = Window & { - __REDUX_DEVTOOLS_EXTENSION_COMPOSE__: Function; -}; - -type T1 = (number | string)["toString"]; -type T2 = (number | string)["toString"]; -type T3 = (number | string)["toString"]; -type T4 = (number | string)["toString"]; -type T5 = number | ((arg: any) => void); -type T6 = number | ((arg: any) => void); -type T7 = number | ((arg: any) => void); -type T8 = number | ((arg: any) => void); diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/union/union-parens.ts.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/typescript/union/union-parens.ts.prettier-snap index 1f60e04ad7b..da12fb2e46e 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/typescript/union/union-parens.ts.prettier-snap +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/union/union-parens.ts.prettier-snap @@ -85,13 +85,13 @@ type A2 = C; type A3 = C; type A4 = C; type A5 = C; -type A6 = /*1*/ C; -type A7 = /*1*/ C; -type A8 = /*1*/ C; -type A9 = /*1*/ C; -type A10 = /*1*/ /*2*/ C; -type A11 = /*1*/ /*2*/ C; -type A12 = /*1*/ C; +type A6 /*1*/ = C; +type A7 /*1*/ = C; +type A8 /*1*/ = C; +type A9 /*1*/ = C; +type A10 /*1*/ = /*2*/ C; +type A11 /*1*/ = /*2*/ C; +type A12 /*1*/ = C; type A13 = /*1*/ C; type Aa1 = /*1*/ /*2*/ C | D; @@ -101,7 +101,7 @@ type Aa3 = /*1*/ /*2*/ C | /*3*/ D /*4*/; type C1 = /*1*/ a | b; type C2 = /*1*/ a | b; type C3 = /*1*/ a | b; -type C4 = /*1*/ a | b; +type C4 /*1*/ = a | b; type C5 = /*1*/ a | b; type C6 /*0*/ = /*1*/ a | b; diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/union/union-parens.ts.snap b/crates/rome_js_formatter/tests/specs/prettier/typescript/union/union-parens.ts.snap new file mode 100644 index 00000000000..7764bbbc734 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/union/union-parens.ts.snap @@ -0,0 +1,274 @@ +--- +source: crates/rome_formatter_test/src/snapshot_builder.rs +info: typescript/union/union-parens.ts +--- + +# Input + +```ts + +export type A = ( + | aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + | bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb +); + +export type B = ( + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa | + bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb +); + +export type C = + | aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + | bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb; + +export type D = + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa | + bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb; + +export type Multi = (string | number)[]; + +function f(): (string | number) {} + +var x: (string | number); +var y: ((string | number)); + +class Foo {} + +interface Interface { + i: (X | Y) & Z; + j: Partial<(X | Y)>; +} + +type State = { + sharedProperty: any; +} & ( + | { discriminant: "FOO"; foo: any } + | { discriminant: "BAR"; bar: any } + | { discriminant: "BAZ"; baz: any } +); + +const foo1 = [abc, def, ghi, jkl, mno, pqr, stu, vwx, yz] as ( + | string + | undefined +)[]; + +const foo2: ( + | AAAAAAAAAAAAAAAAAAAAAA + | BBBBBBBBBBBBBBBBBBBBBB + | CCCCCCCCCCCCCCCCCCCCCC + | DDDDDDDDDDDDDDDDDDDDDD +)[] = []; + +const foo3: keyof ( + | AAAAAAAAAAAAAAAAAAAAAA + | BBBBBBBBBBBBBBBBBBBBBB + | CCCCCCCCCCCCCCCCCCCCCC + | DDDDDDDDDDDDDDDDDDDDDD +) = bar; + +const foo4: + | foo + | ( + | AAAAAAAAAAAAAAAAAAAAAA + | BBBBBBBBBBBBBBBBBBBBBB + | CCCCCCCCCCCCCCCCCCCCCC + | DDDDDDDDDDDDDDDDDDDDDD + ) = bar; + +let a1 : C; +let a2 : | C; +let a3 : (| C); +let a4 : | (C); +let a5 : (| (C)); +let a6 : /*1*/ | C; +let a7 : /*1*/ | (C); +let a8 : /*1*/ (| C); +let a9 : (/*1*/ | C); +let a10: /*1*/ | /*2*/ C; +let a11: /*1*/ (| /*2*/ C); + +let aa1: /*1*/ | /*2*/ C | D; +let aa2: /*1*/ | /*2*/ C | /*3*/ D; +let aa3: /*1*/ | /*2*/ C | /*3*/ D /*4*/; + +type A1 = C; +type A2 = | C; +type A3 = (| C); +type A4 = | (C); +type A5 = (| (C)); +type A6 = /*1*/ | C; +type A7 = /*1*/ | (C); +type A8 = /*1*/ (| C); +type A9 = (/*1*/ | C); +type A10 = /*1*/ | /*2*/ C; +type A11 = /*1*/ (| /*2*/ C); +type A12 = /*1*/ | ( (C)); +type A13 = /*1*/ ( (C)); + +type Aa1 = /*1*/ | /*2*/ C | D; +type Aa2 = /*1*/ | /*2*/ C | /*3*/ D; +type Aa3 = /*1*/ | /*2*/ C | /*3*/ D /*4*/; + +type C1 = /*1*/ & a | b; +type C2 = /*1*/ & a | (b); +type C3 = /*1*/ & a | (& b); +type C4 = /*1*/ & (a | b); +type C5 = /*1*/ (& a | b); +type C6 /*0*/ = /*1*/ (& a | b); + +type Ctor = (new () => X) | Y; + +``` + + +# Prettier differences + +```diff +--- Prettier ++++ Rome +@@ -85,13 +85,13 @@ + type A3 = C; + type A4 = C; + type A5 = C; +-type A6 /*1*/ = C; +-type A7 /*1*/ = C; +-type A8 /*1*/ = C; +-type A9 /*1*/ = C; +-type A10 /*1*/ = /*2*/ C; +-type A11 /*1*/ = /*2*/ C; +-type A12 /*1*/ = C; ++type A6 = /*1*/ C; ++type A7 = /*1*/ C; ++type A8 = /*1*/ C; ++type A9 = /*1*/ C; ++type A10 = /*1*/ /*2*/ C; ++type A11 = /*1*/ /*2*/ C; ++type A12 = /*1*/ C; + type A13 = /*1*/ C; + + type Aa1 = /*1*/ /*2*/ C | D; +@@ -101,7 +101,7 @@ + type C1 = /*1*/ a | b; + type C2 = /*1*/ a | b; + type C3 = /*1*/ a | b; +-type C4 /*1*/ = a | b; ++type C4 = /*1*/ a | b; + type C5 = /*1*/ a | b; + type C6 /*0*/ = /*1*/ a | b; + +``` + +# Output + +```ts +export type A = + | aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + | bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb; + +export type B = + | aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + | bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb; + +export type C = + | aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + | bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb; + +export type D = + | aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + | bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb; + +export type Multi = (string | number)[]; + +function f(): string | number {} + +var x: string | number; +var y: string | number; + +class Foo {} + +interface Interface { + i: (X | Y) & Z; + j: Partial; +} + +type State = { + sharedProperty: any; +} & ( + | { discriminant: "FOO"; foo: any } + | { discriminant: "BAR"; bar: any } + | { discriminant: "BAZ"; baz: any } +); + +const foo1 = [abc, def, ghi, jkl, mno, pqr, stu, vwx, yz] as ( + | string + | undefined +)[]; + +const foo2: ( + | AAAAAAAAAAAAAAAAAAAAAA + | BBBBBBBBBBBBBBBBBBBBBB + | CCCCCCCCCCCCCCCCCCCCCC + | DDDDDDDDDDDDDDDDDDDDDD +)[] = []; + +const foo3: keyof ( + | AAAAAAAAAAAAAAAAAAAAAA + | BBBBBBBBBBBBBBBBBBBBBB + | CCCCCCCCCCCCCCCCCCCCCC + | DDDDDDDDDDDDDDDDDDDDDD +) = bar; + +const foo4: + | foo + | ( + | AAAAAAAAAAAAAAAAAAAAAA + | BBBBBBBBBBBBBBBBBBBBBB + | CCCCCCCCCCCCCCCCCCCCCC + | DDDDDDDDDDDDDDDDDDDDDD + ) = bar; + +let a1: C; +let a2: C; +let a3: C; +let a4: C; +let a5: C; +let a6: /*1*/ C; +let a7: /*1*/ C; +let a8: /*1*/ C; +let a9: /*1*/ C; +let a10: /*1*/ /*2*/ C; +let a11: /*1*/ /*2*/ C; + +let aa1: /*1*/ /*2*/ C | D; +let aa2: /*1*/ /*2*/ C | /*3*/ D; +let aa3: /*1*/ /*2*/ C | /*3*/ D /*4*/; + +type A1 = C; +type A2 = C; +type A3 = C; +type A4 = C; +type A5 = C; +type A6 = /*1*/ C; +type A7 = /*1*/ C; +type A8 = /*1*/ C; +type A9 = /*1*/ C; +type A10 = /*1*/ /*2*/ C; +type A11 = /*1*/ /*2*/ C; +type A12 = /*1*/ C; +type A13 = /*1*/ C; + +type Aa1 = /*1*/ /*2*/ C | D; +type Aa2 = /*1*/ /*2*/ C | /*3*/ D; +type Aa3 = /*1*/ /*2*/ C | /*3*/ D /*4*/; + +type C1 = /*1*/ a | b; +type C2 = /*1*/ a | b; +type C3 = /*1*/ a | b; +type C4 = /*1*/ a | b; +type C5 = /*1*/ a | b; +type C6 /*0*/ = /*1*/ a | b; + +type Ctor = (new () => X) | Y; +``` + + diff --git a/crates/tests_macros/src/lib.rs b/crates/tests_macros/src/lib.rs index 3fd6210c5c1..ce9af666358 100644 --- a/crates/tests_macros/src/lib.rs +++ b/crates/tests_macros/src/lib.rs @@ -94,6 +94,7 @@ fn transform_file_name(input: &str) -> String { | "type" | "super" | "typeof" + | "const" ); let is_number = result