--- source: crates/rome_formatter_test/src/snapshot_builder.rs info: test_file: js/throw_expressions/throw_expression.js --- # Input ```js function save(filename = throw new TypeError("Argument required")) {} lint(ast, { with: () => throw new Error("avoid using 'with' statements.") }); function getEncoder(encoding) { const encoder = encoding === "utf8" ? new UTF8Encoder() : encoding === "utf16le" ? new UTF16Encoder(false) : encoding === "utf16be" ? new UTF16Encoder(true) : throw new Error("Unsupported encoding"); } class Product { get id() { return this._id; } set id(value) { this._id = value || throw new Error("Invalid value"); } } ``` # Prettier differences ```diff --- Prettier +++ Rome @@ -1,18 +1,18 @@ -function save(filename = throw new TypeError("Argument required")) {} +function save(filename = throw new TypeError("Argument required") +) +{ +} lint(ast, { - with: () => throw new Error("avoid using 'with' statements."), + with: () => throw new Error("avoid using 'with' statements.") }); function getEncoder(encoding) { - const encoder = - encoding === "utf8" - ? new UTF8Encoder() - : encoding === "utf16le" - ? new UTF16Encoder(false) - : encoding === "utf16be" - ? new UTF16Encoder(true) - : throw new Error("Unsupported encoding"); + const encoder = encoding === "utf8" ? new UTF8Encoder() + : encoding === "utf16le" ? new UTF16Encoder(false) + : encoding === "utf16be" ? new UTF16Encoder(true) + : + throw new Error("Unsupported encoding"); } class Product { @@ -20,6 +20,7 @@ return this._id; } set id(value) { - this._id = value || throw new Error("Invalid value"); + this._id = value || + throw new Error("Invalid value"); } } ``` # Output ```js function save(filename = throw new TypeError("Argument required") ) { } lint(ast, { with: () => throw new Error("avoid using 'with' statements.") }); function getEncoder(encoding) { const encoder = encoding === "utf8" ? new UTF8Encoder() : encoding === "utf16le" ? new UTF16Encoder(false) : encoding === "utf16be" ? new UTF16Encoder(true) : throw new Error("Unsupported encoding"); } class Product { get id() { return this._id; } set id(value) { this._id = value || throw new Error("Invalid value"); } } ``` # Errors ``` throw_expression.js:1:26 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × expected an expression, or an assignment but instead found 'throw' > 1 │ function save(filename = throw new TypeError("Argument required")) {} │ ^^^^^ 2 │ 3 │ lint(ast, { i Expected an expression, or an assignment here > 1 │ function save(filename = throw new TypeError("Argument required")) {} │ ^^^^^ 2 │ 3 │ lint(ast, { throw_expression.js:1:36 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × expected `,` but instead found `TypeError` > 1 │ function save(filename = throw new TypeError("Argument required")) {} │ ^^^^^^^^^ 2 │ 3 │ lint(ast, { i Remove TypeError throw_expression.js:1:45 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × expected `,` but instead found `(` > 1 │ function save(filename = throw new TypeError("Argument required")) {} │ ^ 2 │ 3 │ lint(ast, { i Remove ( throw_expression.js:1:66 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × expected a function body but instead found ')' > 1 │ function save(filename = throw new TypeError("Argument required")) {} │ ^ 2 │ 3 │ lint(ast, { i Expected a function body here > 1 │ function save(filename = throw new TypeError("Argument required")) {} │ ^ 2 │ 3 │ lint(ast, { throw_expression.js:4:15 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × expected a function body, or an expression but instead found 'throw' 3 │ lint(ast, { > 4 │ with: () => throw new Error("avoid using 'with' statements.") │ ^^^^^ 5 │ }); 6 │ i Expected a function body, or an expression here 3 │ lint(ast, { > 4 │ with: () => throw new Error("avoid using 'with' statements.") │ ^^^^^ 5 │ }); 6 │ throw_expression.js:4:21 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × expected `:` but instead found `new` 3 │ lint(ast, { > 4 │ with: () => throw new Error("avoid using 'with' statements.") │ ^^^ 5 │ }); 6 │ i Remove new throw_expression.js:11:19 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × expected an expression, or an assignment but instead found 'throw' 9 │ : encoding === "utf16le" ? new UTF16Encoder(false) 10 │ : encoding === "utf16be" ? new UTF16Encoder(true) > 11 │ : throw new Error("Unsupported encoding"); │ ^^^^^ 12 │ } 13 │ i Expected an expression, or an assignment here 9 │ : encoding === "utf16le" ? new UTF16Encoder(false) 10 │ : encoding === "utf16be" ? new UTF16Encoder(true) > 11 │ : throw new Error("Unsupported encoding"); │ ^^^^^ 12 │ } 13 │ throw_expression.js:16:39 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × expected an expression but instead found 'throw' 14 │ class Product { 15 │ get id() { return this._id; } > 16 │ set id(value) { this._id = value || throw new Error("Invalid value"); } │ ^^^^^ 17 │ } 18 │ i Expected an expression here 14 │ class Product { 15 │ get id() { return this._id; } > 16 │ set id(value) { this._id = value || throw new Error("Invalid value"); } │ ^^^^^ 17 │ } 18 │ ```