--- source: crates/rome_formatter_test/src/snapshot_builder.rs info: test_file: js/do/call-arguments.js --- # Input ```js // from https://github.com/babel/babel/pull/13122/ expect( do { var bar = "foo"; if (!bar) throw new Error( "unreachable" ) bar; } ).toBe("foo"); expect(bar).toBe("foo"); var x = do { var bar = "foo"; if (!bar) throw new Error( "unreachable" ) bar; }; expect( do { var bar = "foo"; bar; } ).toBe("foo"); expect(bar).toBe("foo"); var x = do { var bar = "foo"; bar; }; expect( () => do { () => { var bar = "foo"; }; bar; } ).toThrow(ReferenceError); ``` # Prettier differences ```diff --- Prettier +++ Rome @@ -1,24 +1,36 @@ // from https://github.com/babel/babel/pull/13122/ -expect(do { - var bar = "foo"; - if (!bar) throw new Error("unreachable"); - bar; -}).toBe("foo"); +expect( +do { + var bar = "foo"; + if (!bar) throw new Error( + "unreachable" + ) + bar; + } +) +.toBe("foo") expect(bar).toBe("foo"); -var x = do { +var x = +do { var bar = "foo"; - if (!bar) throw new Error("unreachable"); + if (!bar) throw new Error( + "unreachable" + ) bar; }; -expect(do { - var bar = "foo"; - bar; -}).toBe("foo"); +expect( +do { + var bar = "foo"; + bar; + } +) +.toBe("foo") expect(bar).toBe("foo"); -var x = do { +var x = +do { var bar = "foo"; bar; }; @@ -28,6 +40,6 @@ () => { var bar = "foo"; }; - bar; - }, -).toThrow(ReferenceError); +bar; +} +).toThrow(ReferenceError) ``` # Output ```js // from https://github.com/babel/babel/pull/13122/ expect( do { var bar = "foo"; if (!bar) throw new Error( "unreachable" ) bar; } ) .toBe("foo") expect(bar).toBe("foo"); var x = do { var bar = "foo"; if (!bar) throw new Error( "unreachable" ) bar; }; expect( do { var bar = "foo"; bar; } ) .toBe("foo") expect(bar).toBe("foo"); var x = do { var bar = "foo"; bar; }; expect( () => do { () => { var bar = "foo"; }; bar; } ).toThrow(ReferenceError) ``` # Errors ``` call-arguments.js:3:3 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × expected an expression but instead found 'do' 1 │ // from https://github.com/babel/babel/pull/13122/ 2 │ expect( > 3 │ do { │ ^^ 4 │ var bar = "foo"; 5 │ if (!bar) throw new Error( i Expected an expression here 1 │ // from https://github.com/babel/babel/pull/13122/ 2 │ expect( > 3 │ do { │ ^^ 4 │ var bar = "foo"; 5 │ if (!bar) throw new Error( call-arguments.js:10:1 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × expected `while` but instead found `)` 8 │ bar; 9 │ } > 10 │ ).toBe("foo"); │ ^ 11 │ expect(bar).toBe("foo"); 12 │ i Remove ) call-arguments.js:10:2 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × expected a statement but instead found '.toBe("foo")' 8 │ bar; 9 │ } > 10 │ ).toBe("foo"); │ ^^^^^^^^^^^^ 11 │ expect(bar).toBe("foo"); 12 │ i Expected a statement here 8 │ bar; 9 │ } > 10 │ ).toBe("foo"); │ ^^^^^^^^^^^^ 11 │ expect(bar).toBe("foo"); 12 │ call-arguments.js:13:9 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × expected an expression, or an assignment but instead found 'do' 11 │ expect(bar).toBe("foo"); 12 │ > 13 │ var x = do { │ ^^ 14 │ var bar = "foo"; 15 │ if (!bar) throw new Error( i Expected an expression, or an assignment here 11 │ expect(bar).toBe("foo"); 12 │ > 13 │ var x = do { │ ^^ 14 │ var bar = "foo"; 15 │ if (!bar) throw new Error( call-arguments.js:19:2 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × expected `while` but instead found `;` 17 │ ) 18 │ bar; > 19 │ }; │ ^ 20 │ 21 │ expect( i Remove ; call-arguments.js:22:3 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × expected an expression but instead found 'do' 21 │ expect( > 22 │ do { │ ^^ 23 │ var bar = "foo"; 24 │ bar; i Expected an expression here 21 │ expect( > 22 │ do { │ ^^ 23 │ var bar = "foo"; 24 │ bar; call-arguments.js:26:1 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × expected `while` but instead found `)` 24 │ bar; 25 │ } > 26 │ ).toBe("foo"); │ ^ 27 │ expect(bar).toBe("foo"); 28 │ i Remove ) call-arguments.js:26:2 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × expected a statement but instead found '.toBe("foo")' 24 │ bar; 25 │ } > 26 │ ).toBe("foo"); │ ^^^^^^^^^^^^ 27 │ expect(bar).toBe("foo"); 28 │ i Expected a statement here 24 │ bar; 25 │ } > 26 │ ).toBe("foo"); │ ^^^^^^^^^^^^ 27 │ expect(bar).toBe("foo"); 28 │ call-arguments.js:29:9 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × expected an expression, or an assignment but instead found 'do' 27 │ expect(bar).toBe("foo"); 28 │ > 29 │ var x = do { │ ^^ 30 │ var bar = "foo"; 31 │ bar; i Expected an expression, or an assignment here 27 │ expect(bar).toBe("foo"); 28 │ > 29 │ var x = do { │ ^^ 30 │ var bar = "foo"; 31 │ bar; call-arguments.js:32:2 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × expected `while` but instead found `;` 30 │ var bar = "foo"; 31 │ bar; > 32 │ }; │ ^ 33 │ 34 │ expect( i Remove ; call-arguments.js:35:9 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × expected a function body, or an expression but instead found 'do' 34 │ expect( > 35 │ () => do { │ ^^ 36 │ () => { 37 │ var bar = "foo"; i Expected a function body, or an expression here 34 │ expect( > 35 │ () => do { │ ^^ 36 │ () => { 37 │ var bar = "foo"; call-arguments.js:36:5 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × expected `,` but instead found `(` 34 │ expect( 35 │ () => do { > 36 │ () => { │ ^ 37 │ var bar = "foo"; 38 │ }; i Remove ( call-arguments.js:38:6 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × expected `,` but instead found `;` 36 │ () => { 37 │ var bar = "foo"; > 38 │ }; │ ^ 39 │ bar; 40 │ } i Remove ; call-arguments.js:40:3 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × expected a statement but instead found '} ).toThrow(ReferenceError)' 38 │ }; 39 │ bar; > 40 │ } │ ^ > 41 │ ).toThrow(ReferenceError); │ ^^^^^^^^^^^^^^^^^^^^^^^^^ 42 │ i Expected a statement here 38 │ }; 39 │ bar; > 40 │ } │ ^ > 41 │ ).toThrow(ReferenceError); │ ^^^^^^^^^^^^^^^^^^^^^^^^^ 42 │ ```