--- source: crates/rome_formatter_test/src/snapshot_builder.rs info: test_file: js/module-blocks/worker.js --- # Input ```js let worker = new Worker(module { onmessage = function({data}) { let mod = import(data); postMessage(mod.fn()); } }, {type: "module"}); let worker = new Worker(module { onmessage = function({data}) { let mod = import(data); postMessage(mod.fn()); } }, {type: "module", foo: "bar" }); worker.postMessage(module { export function fn() { return "hello!" } }); ``` # Prettier differences ```diff --- Prettier +++ Rome @@ -1,22 +1,15 @@ let worker = new Worker(module { - onmessage = function ({ data }) { + onmessage = function({data}) { let mod = import(data); postMessage(mod.fn()); - }; -}, { type: "module" }); - -let worker = new Worker( - module { - onmessage = function ({ data }) { - let mod = import(data); - postMessage(mod.fn()); - }; - }, - { type: "module", foo: "bar" }, -); + } +}, {type: "module"}); -worker.postMessage(module { - export function fn() { - return "hello!"; +let worker = new Worker(module { + onmessage = function({data}) { + let mod = import(data); + postMessage(mod.fn()); } -}); +}, {type: "module", foo: "bar" }); + +worker.postMessage(module { export function fn() { return "hello!" } }); ``` # Output ```js let worker = new Worker(module { onmessage = function({data}) { let mod = import(data); postMessage(mod.fn()); } }, {type: "module"}); let worker = new Worker(module { onmessage = function({data}) { let mod = import(data); postMessage(mod.fn()); } }, {type: "module", foo: "bar" }); worker.postMessage(module { export function fn() { return "hello!" } }); ``` # Errors ``` worker.js:1:32 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × expected `,` but instead found `{` > 1 │ let worker = new Worker(module { │ ^ 2 │ onmessage = function({data}) { 3 │ let mod = import(data); i Remove { worker.js:2:13 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × Did you mean to use a `:`? An `=` can only follow a property name when the containing object literal is part of a destructuring pattern. 1 │ let worker = new Worker(module { > 2 │ onmessage = function({data}) { │ ^ 3 │ let mod = import(data); 4 │ postMessage(mod.fn()); worker.js:8:32 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × expected `,` but instead found `{` 6 │ }, {type: "module"}); 7 │ > 8 │ let worker = new Worker(module { │ ^ 9 │ onmessage = function({data}) { 10 │ let mod = import(data); i Remove { worker.js:9:13 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × Did you mean to use a `:`? An `=` can only follow a property name when the containing object literal is part of a destructuring pattern. 8 │ let worker = new Worker(module { > 9 │ onmessage = function({data}) { │ ^ 10 │ let mod = import(data); 11 │ postMessage(mod.fn()); worker.js:15:27 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × expected `,` but instead found `{` 13 │ }, {type: "module", foo: "bar" }); 14 │ > 15 │ worker.postMessage(module { export function fn() { return "hello!" } }); │ ^ 16 │ i Remove { worker.js:15:36 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × expected `:` but instead found `function` 13 │ }, {type: "module", foo: "bar" }); 14 │ > 15 │ worker.postMessage(module { export function fn() { return "hello!" } }); │ ^^^^^^^^ 16 │ i Remove function ```