--- source: crates/rome_formatter_test/src/snapshot_builder.rs info: test_file: js/do/do.js --- # Input ```js const envSpecific = { domain: do { if(env === 'production') 'https://abc.mno.com/'; else if(env === 'development') 'http://localhost:4000'; } }; let x = do { let tmp = f(); tmp * tmp + 1 }; let y = do { if (foo()) { f() } else if (bar()) { g() } else { h() } }; function foo() { return ( ); } (do {}); (do {} + 1); (1 + do {}); () => do {}; (do { switch(0) { case 0: "foo"; case 1: break; } }); () => do { var obj = { foo: "bar", bar: "foo" }; for (var key in obj) { obj[key]; } }; ``` # Prettier differences ```diff --- Prettier +++ Rome @@ -1,55 +1,61 @@ const envSpecific = { - domain: do { - if (env === "production") "https://abc.mno.com/"; - else if (env === "development") "http://localhost:4000"; - }, -}; + domain: + do { + if(env === 'production') 'https://abc.mno.com/'; +else +if (env === "development") "http://localhost:4000"; +} +} -let x = do { +let x = +do { let tmp = f(); - tmp * tmp + 1; + tmp * tmp + 1 }; -let y = do { - if (foo()) { - f(); - } else if (bar()) { - g(); - } else { - h(); - } +let y = +do { + if (foo()) { f() } + else if (bar()) { g() } + else { h() } }; function foo() { return ( ); } -(do {}); -(do {} + 1); -1 + do {}; -() => do {}; +( +do {}); +( +do {} + 1); +(1 + +do {}); +() => +do {}; -(do { - switch (0) { - case 0: - "foo"; - case 1: - break; +( +do { + switch(0) { + case 0: "foo"; + case 1: break; } }); -() => do { +() => +do { var obj = { foo: "bar", bar: "foo" }; for (var key in obj) { obj[key]; ``` # Output ```js const envSpecific = { domain: do { if(env === 'production') 'https://abc.mno.com/'; else if (env === "development") "http://localhost:4000"; } } let x = do { let tmp = f(); tmp * tmp + 1 }; let y = do { if (foo()) { f() } else if (bar()) { g() } else { h() } }; function foo() { return ( ); } ( do {}); ( do {} + 1); (1 + do {}); () => do {}; ( do { switch(0) { case 0: "foo"; case 1: break; } }); () => do { var obj = { foo: "bar", bar: "foo" }; for (var key in obj) { obj[key]; } }; ``` # Errors ``` do.js:3:5 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × expected an expression, or an assignment but instead found 'do' 1 │ const envSpecific = { 2 │ domain: > 3 │ do { │ ^^ 4 │ if(env === 'production') 'https://abc.mno.com/'; 5 │ else if(env === 'development') 'http://localhost:4000'; i Expected an expression, or an assignment here 1 │ const envSpecific = { 2 │ domain: > 3 │ do { │ ^^ 4 │ if(env === 'production') 'https://abc.mno.com/'; 5 │ else if(env === 'development') 'http://localhost:4000'; do.js:3:8 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × expected `:` but instead found `{` 1 │ const envSpecific = { 2 │ domain: > 3 │ do { │ ^ 4 │ if(env === 'production') 'https://abc.mno.com/'; 5 │ else if(env === 'development') 'http://localhost:4000'; i Remove { do.js:4:14 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × expected `,` but instead found `===` 2 │ domain: 3 │ do { > 4 │ if(env === 'production') 'https://abc.mno.com/'; │ ^^^ 5 │ else if(env === 'development') 'http://localhost:4000'; 6 │ } i Remove === do.js:4:32 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × expected a function body but instead found ''https://abc.mno.com/'' 2 │ domain: 3 │ do { > 4 │ if(env === 'production') 'https://abc.mno.com/'; │ ^^^^^^^^^^^^^^^^^^^^^^ 5 │ else if(env === 'development') 'http://localhost:4000'; 6 │ } i Expected a function body here 2 │ domain: 3 │ do { > 4 │ if(env === 'production') 'https://abc.mno.com/'; │ ^^^^^^^^^^^^^^^^^^^^^^ 5 │ else if(env === 'development') 'http://localhost:4000'; 6 │ } do.js:4:54 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × expected `:` but instead found `;` 2 │ domain: 3 │ do { > 4 │ if(env === 'production') 'https://abc.mno.com/'; │ ^ 5 │ else if(env === 'development') 'http://localhost:4000'; 6 │ } i Remove ; do.js:5:7 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × expected a statement but instead found 'else' 3 │ do { 4 │ if(env === 'production') 'https://abc.mno.com/'; > 5 │ else if(env === 'development') 'http://localhost:4000'; │ ^^^^ 6 │ } 7 │ }; i Expected a statement here 3 │ do { 4 │ if(env === 'production') 'https://abc.mno.com/'; > 5 │ else if(env === 'development') 'http://localhost:4000'; │ ^^^^ 6 │ } 7 │ }; do.js:6:5 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × expected a statement but instead found '} }' 4 │ if(env === 'production') 'https://abc.mno.com/'; 5 │ else if(env === 'development') 'http://localhost:4000'; > 6 │ } │ ^ > 7 │ }; │ ^ 8 │ 9 │ let x = do { i Expected a statement here 4 │ if(env === 'production') 'https://abc.mno.com/'; 5 │ else if(env === 'development') 'http://localhost:4000'; > 6 │ } │ ^ > 7 │ }; │ ^ 8 │ 9 │ let x = do { do.js:9:9 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × expected an expression, or an assignment but instead found 'do' 7 │ }; 8 │ > 9 │ let x = do { │ ^^ 10 │ let tmp = f(); 11 │ tmp * tmp + 1 i Expected an expression, or an assignment here 7 │ }; 8 │ > 9 │ let x = do { │ ^^ 10 │ let tmp = f(); 11 │ tmp * tmp + 1 do.js:12:2 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × expected `while` but instead found `;` 10 │ let tmp = f(); 11 │ tmp * tmp + 1 > 12 │ }; │ ^ 13 │ 14 │ let y = do { i Remove ; do.js:14:9 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × expected an expression, or an assignment but instead found 'do' 12 │ }; 13 │ > 14 │ let y = do { │ ^^ 15 │ if (foo()) { f() } 16 │ else if (bar()) { g() } i Expected an expression, or an assignment here 12 │ }; 13 │ > 14 │ let y = do { │ ^^ 15 │ if (foo()) { f() } 16 │ else if (bar()) { g() } do.js:18:2 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × expected `while` but instead found `;` 16 │ else if (bar()) { g() } 17 │ else { h() } > 18 │ }; │ ^ 19 │ 20 │ function foo() { i Remove ; do.js:25:9 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × expected `}` but instead found `do` 23 │ 24 │ { > 25 │ do { │ ^^ 26 │ if (loggedIn) { 27 │ i Remove do do.js:26:11 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × expected `}` but instead found `if` 24 │ { 25 │ do { > 26 │ if (loggedIn) { │ ^^ 27 │ 28 │ } else { i Remove if do.js:31:9 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × Unexpected token. Did you mean `{'}'}` or `}`? 29 │ 30 │ } > 31 │ } │ ^ 32 │ } 33 │ do.js:32:7 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × Unexpected token. Did you mean `{'}'}` or `}`? 30 │ } 31 │ } > 32 │ } │ ^ 33 │ 34 │ ); do.js:37:2 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × expected `)` but instead found `do` 35 │ } 36 │ > 37 │ (do {}); │ ^^ 38 │ (do {} + 1); 39 │ (1 + do {}); i Remove do do.js:37:7 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × expected `while` but instead found `)` 35 │ } 36 │ > 37 │ (do {}); │ ^ 38 │ (do {} + 1); 39 │ (1 + do {}); i Remove ) do.js:38:2 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × expected `)` but instead found `do` 37 │ (do {}); > 38 │ (do {} + 1); │ ^^ 39 │ (1 + do {}); 40 │ () => do {}; i Remove do do.js:38:8 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × expected `while` but instead found `+` 37 │ (do {}); > 38 │ (do {} + 1); │ ^ 39 │ (1 + do {}); 40 │ () => do {}; i Remove + do.js:39:6 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × expected an expression but instead found 'do' 37 │ (do {}); 38 │ (do {} + 1); > 39 │ (1 + do {}); │ ^^ 40 │ () => do {}; 41 │ i Expected an expression here 37 │ (do {}); 38 │ (do {} + 1); > 39 │ (1 + do {}); │ ^^ 40 │ () => do {}; 41 │ do.js:39:11 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × expected `while` but instead found `)` 37 │ (do {}); 38 │ (do {} + 1); > 39 │ (1 + do {}); │ ^ 40 │ () => do {}; 41 │ i Remove ) do.js:40:7 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × expected a function body, or an expression but instead found 'do' 38 │ (do {} + 1); 39 │ (1 + do {}); > 40 │ () => do {}; │ ^^ 41 │ 42 │ (do { i Expected a function body, or an expression here 38 │ (do {} + 1); 39 │ (1 + do {}); > 40 │ () => do {}; │ ^^ 41 │ 42 │ (do { do.js:40:12 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × expected `while` but instead found `;` 38 │ (do {} + 1); 39 │ (1 + do {}); > 40 │ () => do {}; │ ^ 41 │ 42 │ (do { i Remove ; do.js:42:2 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × expected `)` but instead found `do` 40 │ () => do {}; 41 │ > 42 │ (do { │ ^^ 43 │ switch(0) { 44 │ case 0: "foo"; i Remove do do.js:47:2 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × expected `while` but instead found `)` 45 │ case 1: break; 46 │ } > 47 │ }); │ ^ 48 │ 49 │ () => do { i Remove ) do.js:49:7 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × expected a function body, or an expression but instead found 'do' 47 │ }); 48 │ > 49 │ () => do { │ ^^ 50 │ var obj = { foo: "bar", bar: "foo" }; 51 │ for (var key in obj) { i Expected a function body, or an expression here 47 │ }); 48 │ > 49 │ () => do { │ ^^ 50 │ var obj = { foo: "bar", bar: "foo" }; 51 │ for (var key in obj) { do.js:54:2 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × expected `while` but instead found `;` 52 │ obj[key]; 53 │ } > 54 │ }; │ ^ 55 │ i Remove ; ```