diff --git a/src/ast/e.rs b/src/ast/e.rs index 7ae43d52aae1..cbf679f726a7 100644 --- a/src/ast/e.rs +++ b/src/ast/e.rs @@ -41,6 +41,8 @@ impl Default for NameOfSymbol { pub struct Array { pub items: ExprNodeList, pub comma_after_spread: crate::Loc, + /// `[(a = 1)]`: an error only if this literal is a pattern. + pub parenthesized_assign: crate::Loc, pub is_single_line: bool, pub is_parenthesized: bool, pub was_originally_macro: bool, @@ -51,6 +53,7 @@ impl Default for Array { Self { items: bun_alloc::AstAlloc::vec(), comma_after_spread: crate::Loc::EMPTY, + parenthesized_assign: crate::Loc::EMPTY, is_single_line: false, is_parenthesized: false, was_originally_macro: false, @@ -1274,6 +1277,8 @@ impl ArrayJSON { pub struct Object { pub properties: G::PropertyList, pub comma_after_spread: crate::Loc, + /// `{ x: (a = 1) }`: see `Array::parenthesized_assign`. + pub parenthesized_assign: crate::Loc, pub is_single_line: bool, pub is_parenthesized: bool, pub was_originally_macro: bool, @@ -1285,6 +1290,7 @@ impl Default for Object { Self { properties: bun_alloc::AstAlloc::vec(), comma_after_spread: crate::Loc::EMPTY, + parenthesized_assign: crate::Loc::EMPTY, is_single_line: false, is_parenthesized: false, was_originally_macro: false, @@ -1351,6 +1357,7 @@ impl Object { pub const EMPTY: Object = Object { properties: bun_alloc::AstAlloc::vec(), comma_after_spread: crate::Loc::EMPTY, + parenthesized_assign: crate::Loc::EMPTY, is_single_line: false, is_parenthesized: false, was_originally_macro: false, diff --git a/src/ast/expr.rs b/src/ast/expr.rs index cfedeb4f9bf8..25e4f22a3cd8 100644 --- a/src/ast/expr.rs +++ b/src/ast/expr.rs @@ -1878,6 +1878,7 @@ impl Data { let item = bump.alloc(E::Array { items, comma_after_spread: el.comma_after_spread, + parenthesized_assign: el.parenthesized_assign, was_originally_macro: el.was_originally_macro, is_single_line: el.is_single_line, is_parenthesized: el.is_parenthesized, @@ -2065,6 +2066,7 @@ impl Data { let item = bump.alloc(E::Object { properties: el.properties.try_deep_clone_with(|p| p.deep_clone(bump))?, comma_after_spread: el.comma_after_spread, + parenthesized_assign: el.parenthesized_assign, is_single_line: el.is_single_line, is_parenthesized: el.is_parenthesized, was_originally_macro: el.was_originally_macro, diff --git a/src/js_parser/fold.rs b/src/js_parser/fold.rs index ac17087f399a..523dff1299d6 100644 --- a/src/js_parser/fold.rs +++ b/src/js_parser/fold.rs @@ -924,6 +924,13 @@ impl<'a, const TYPESCRIPT: bool, const SCAN_ONLY: bool> P<'a, TYPESCRIPT, SCAN_O )) } + pub(crate) fn maybe_parenthesized_assign_error(&mut self, parenthesized_assign: bun_ast::Loc) { + if let Some(loc) = parenthesized_assign.to_nullable() { + self.log() + .add_error(Some(self.source), loc, b"Invalid assignment target"); + } + } + pub(crate) fn maybe_comma_spread_error(&mut self, comma_after_spread: bun_ast::Loc) { let p = self; if comma_after_spread.is_empty() { diff --git a/src/js_parser/p.rs b/src/js_parser/p.rs index 7aba6f7d8d38..1c9100328d69 100644 --- a/src/js_parser/p.rs +++ b/src/js_parser/p.rs @@ -3959,6 +3959,12 @@ impl<'a, const TYPESCRIPT: bool, const SCAN_ONLY: bool> P<'a, TYPESCRIPT, SCAN_O kind: crate::parser::InvalidLocTag::Spread, }); } + if let Some(paren) = ex.parenthesized_assign.to_nullable() { + invalid_loc.push(InvalidLoc { + loc: paren, + kind: crate::parser::InvalidLocTag::Parentheses, + }); + } if ex.is_parenthesized { invalid_loc.push(InvalidLoc { @@ -4014,6 +4020,12 @@ impl<'a, const TYPESCRIPT: bool, const SCAN_ONLY: bool> P<'a, TYPESCRIPT, SCAN_O kind: crate::parser::InvalidLocTag::Spread, }); } + if let Some(paren) = ex.parenthesized_assign.to_nullable() { + invalid_loc.push(InvalidLoc { + loc: paren, + kind: crate::parser::InvalidLocTag::Parentheses, + }); + } if ex.is_parenthesized { invalid_loc.push(InvalidLoc { @@ -4043,11 +4055,24 @@ impl<'a, const TYPESCRIPT: bool, const SCAN_ONLY: bool> P<'a, TYPESCRIPT, SCAN_O continue; } let value = item.value.as_mut().unwrap(); - let tup = - self.convert_expr_to_binding_and_initializer(value, invalid_loc, false); - let initializer = tup.expr.or(item.initializer); let is_spread = item.kind == js_ast::g::PropertyKind::Spread || item.flags.contains(Flags::Property::IsSpread); + let tup = + self.convert_expr_to_binding_and_initializer(value, invalid_loc, is_spread); + // "({ ...[a] }) => 0" + if is_spread + && let Some(binding) = &tup.binding + && matches!( + binding.data, + js_ast::b::B::BArray(_) | js_ast::b::B::BObject(_) + ) + { + invalid_loc.push(InvalidLoc { + loc: binding.loc, + kind: crate::parser::InvalidLocTag::Unknown, + }); + } + let initializer = tup.expr.or(item.initializer); let mut flags = Flags::PropertySet::empty(); if is_spread { flags |= Flags::Property::IsSpread; @@ -4104,17 +4129,11 @@ impl<'a, const TYPESCRIPT: bool, const SCAN_ONLY: bool> P<'a, TYPESCRIPT, SCAN_O } let bind = self.convert_expr_to_binding(expr, invalid_log); - if let Some(initial) = initializer { - let equals_range = self.source.range_of_operator_before(initial.loc, b"="); - if is_spread { - self.log().add_range_error( - Some(self.source), - equals_range, - b"A rest argument cannot have a default initializer", - ); - } else { - // p.markSyntaxFeature(); - } + if is_spread && let Some(initial) = initializer { + invalid_log.push(InvalidLoc { + loc: self.source.range_of_operator_before(initial.loc, b"=").loc, + kind: crate::parser::InvalidLocTag::RestInitializer, + }); } ExprBindingTuple { binding: bind, diff --git a/src/js_parser/parse/mod.rs b/src/js_parser/parse/mod.rs index e31557ff2656..ef5cfb2dd0d6 100644 --- a/src/js_parser/parse/mod.rs +++ b/src/js_parser/parse/mod.rs @@ -74,7 +74,16 @@ impl<'a, const TYPESCRIPT: bool, const SCAN_ONLY: bool> P<'a, TYPESCRIPT, SCAN_O let had_pure_comment_before = self.lexer.has_pure_comment_before && !self.options.ignore_dce_annotations; + let paren_assign_before = errors + .as_deref() + .and_then(|errors| errors.parenthesized_assign); *expr = self.parse_prefix(level, errors.as_deref_mut(), flags)?; + let paren_assign_prefix = match errors.as_deref() { + Some(errors) if errors.parenthesized_assign != paren_assign_before => { + Self::assign_ptr(expr) + } + _ => None, + }; // `errors` is reborrowed via as_deref_mut for each call site. // There is no formal spec for "__PURE__" comments but from reverse- @@ -95,10 +104,26 @@ impl<'a, const TYPESCRIPT: bool, const SCAN_ONLY: bool> P<'a, TYPESCRIPT, SCAN_O } } - self.parse_suffix(expr, level, errors, flags)?; + self.parse_suffix(expr, level, errors.as_deref_mut(), flags)?; + + // Only a bare "(a = 1)" item counts: "[(a = {}).b] = [1]" is valid. + if let (Some(errors), Some(prefix)) = (errors, paren_assign_prefix) + && Self::assign_ptr(expr) != Some(prefix) + { + errors.parenthesized_assign = paren_assign_before; + } Ok(()) } + fn assign_ptr(expr: &Expr) -> Option<*const E::Binary> { + match &expr.data { + js_ast::ExprData::EBinary(e) if e.op == js_ast::OpCode::BinAssign => { + Some(e.as_ptr().cast_const()) + } + _ => None, + } + } + pub(crate) fn parse_yield_expr(&mut self, loc: bun_ast::Loc) -> Result { let p = self; // Parse a yield-from expression, which yields from an iterator @@ -449,9 +474,12 @@ impl<'a, const TYPESCRIPT: bool, const SCAN_ONLY: bool> P<'a, TYPESCRIPT, SCAN_O p.latest_arrow_arg_loc = p.lexer.loc(); let mut item = Expr::EMPTY; + let parenthesized_assign = errors.parenthesized_assign; p.parse_expr_or_bindings(Level::Comma, Some(&mut errors), &mut item)?; if is_spread { + // "...(a = 1)" is already an invalid rest argument without the parentheses + errors.parenthesized_assign = parenthesized_assign; item = p.new_expr(E::Spread { value: item }, loc); } @@ -577,6 +605,13 @@ impl<'a, const TYPESCRIPT: bool, const SCAN_ONLY: bool> P<'a, TYPESCRIPT, SCAN_O if is_arrow_fn || opts.force_arrow_fn { p.maybe_comma_spread_error(comma_after_spread); p.log_arrow_arg_errors(&mut arrow_arg_errors); + if let Some(paren) = errors.parenthesized_assign { + p.log().add_error( + Some(p.source), + paren, + b"Unexpected parentheses in binding pattern", + ); + } // Now that we've decided we're an arrow function, report binding pattern // conversion errors diff --git a/src/js_parser/parse/parse_prefix.rs b/src/js_parser/parse/parse_prefix.rs index ea2ea1003e22..d62358cf8e2f 100644 --- a/src/js_parser/parse/parse_prefix.rs +++ b/src/js_parser/parse/parse_prefix.rs @@ -44,12 +44,17 @@ impl<'a, const TYPESCRIPT: bool, const SCAN_ONLY: bool> P<'a, TYPESCRIPT, SCAN_O Ok(p.new_expr(E::Super {}, loc)) } - fn pfx_t_open_paren(p: &mut Self, level: Level, flags: EFlags) -> PResult { + fn pfx_t_open_paren( + p: &mut Self, + level: Level, + errors: Option<&mut DeferredErrors>, + flags: EFlags, + ) -> PResult { let loc = p.lexer.loc(); p.lexer.next()?; // Arrow functions aren't allowed in the middle of expressions - if level.gt(Level::Assign) { + let value = if level.gt(Level::Assign) { // Allow "in" inside parentheses let old_allow_in = p.allow_in; p.allow_in = true; @@ -59,17 +64,28 @@ impl<'a, const TYPESCRIPT: bool, const SCAN_ONLY: bool> P<'a, TYPESCRIPT, SCAN_O p.lexer.expect(T::TCloseParen)?; p.allow_in = old_allow_in; - return Ok(value); + value + } else { + p.parse_paren_expr( + loc, + level, + ParenExprOpts { + is_after_question_and_before_colon: flags + == EFlags::AfterQuestionAndBeforeColon, + ..Default::default() + }, + )? + }; + + // "[(a = 1)] = []" is not the pattern "[a = 1] = []". + if let Some(errors) = errors + && let ExprData::EBinary(bin) = &value.data + && bin.op == OpCode::BinAssign + { + errors.parenthesized_assign = Some(loc); } - p.parse_paren_expr( - loc, - level, - ParenExprOpts { - is_after_question_and_before_colon: flags == EFlags::AfterQuestionAndBeforeColon, - ..Default::default() - }, - ) + Ok(value) } #[inline] @@ -741,7 +757,10 @@ impl<'a, const TYPESCRIPT: bool, const SCAN_ONLY: bool> P<'a, TYPESCRIPT, SCAN_O p.lexer.next()?; // Parse into a local then push. let mut value = Expr::EMPTY; + let parenthesized_assign = self_errors.parenthesized_assign; p.parse_expr_or_bindings(Level::Comma, Some(&mut self_errors), &mut value)?; + // "...(a = 1)" is already an invalid rest target without the parentheses + self_errors.parenthesized_assign = parenthesized_assign; items.push(p.new_expr(E::Spread { value }, dots_loc)); // Commas are not allowed here when destructuring @@ -794,6 +813,9 @@ impl<'a, const TYPESCRIPT: bool, const SCAN_ONLY: bool> P<'a, TYPESCRIPT, SCAN_O E::Array { items: items_list, comma_after_spread, + parenthesized_assign: self_errors + .parenthesized_assign + .unwrap_or(bun_ast::Loc::EMPTY), is_single_line, close_bracket_loc, ..Default::default() @@ -819,7 +841,9 @@ impl<'a, const TYPESCRIPT: bool, const SCAN_ONLY: bool> P<'a, TYPESCRIPT, SCAN_O if p.lexer.token == T::TDotDotDot { p.lexer.next()?; let mut value = Expr::EMPTY; + let parenthesized_assign = self_errors.parenthesized_assign; p.parse_expr_or_bindings(Level::Comma, Some(&mut self_errors), &mut value)?; + self_errors.parenthesized_assign = parenthesized_assign; properties.push(G::Property { kind: PropertyKind::Spread, value: Some(value), @@ -882,6 +906,9 @@ impl<'a, const TYPESCRIPT: bool, const SCAN_ONLY: bool> P<'a, TYPESCRIPT, SCAN_O E::Object { properties: properties_list, comma_after_spread, + parenthesized_assign: self_errors + .parenthesized_assign + .unwrap_or(bun_ast::Loc::EMPTY), is_single_line, close_brace_loc, ..Default::default() @@ -1010,7 +1037,7 @@ impl<'a, const TYPESCRIPT: bool, const SCAN_ONLY: bool> P<'a, TYPESCRIPT, SCAN_O T::TOpenBrace => Self::pfx_t_open_brace(p, errors), T::TLessThan => Self::pfx_t_less_than(p, level, errors, flags), T::TImport => Self::pfx_t_import(p, level), - T::TOpenParen => Self::pfx_t_open_paren(p, level, flags), + T::TOpenParen => Self::pfx_t_open_paren(p, level, errors, flags), T::TPrivateIdentifier => Self::pfx_t_private_identifier(p, level), T::TIdentifier => Self::pfx_t_identifier(p, level, flags), T::TFalse => Self::pfx_t_false(p), diff --git a/src/js_parser/parser.rs b/src/js_parser/parser.rs index 1911d609651d..20093cc542c1 100644 --- a/src/js_parser/parser.rs +++ b/src/js_parser/parser.rs @@ -1093,6 +1093,7 @@ pub struct InvalidLoc { #[derive(Clone, Copy, PartialEq, Eq, Default)] pub enum InvalidLocTag { Spread, + RestInitializer, Parentheses, Getter, Setter, @@ -1106,6 +1107,7 @@ impl InvalidLoc { pub(crate) fn add_error(self, log: &mut bun_ast::Log, source: &bun_ast::Source) { let text: &'static [u8] = match self.kind { InvalidLocTag::Spread => b"Unexpected trailing comma after rest element", + InvalidLocTag::RestInitializer => b"A rest argument cannot have a default initializer", InvalidLocTag::Parentheses => b"Unexpected parentheses in binding pattern", InvalidLocTag::Getter => b"Unexpected getter in binding pattern", InvalidLocTag::Setter => b"Unexpected setter in binding pattern", @@ -1312,6 +1314,9 @@ pub struct DeferredErrors { /// These are errors for expressions pub(crate) invalid_expr_default_value: Option, pub(crate) invalid_expr_after_question: Option, + + /// `[(a = 1)]`: stored on the enclosing literal, not merged upward. + pub(crate) parenthesized_assign: Option, } impl DeferredErrors { diff --git a/src/js_parser/visit/visit_expr.rs b/src/js_parser/visit/visit_expr.rs index a5f851dc0728..4605ca0e4f19 100644 --- a/src/js_parser/visit/visit_expr.rs +++ b/src/js_parser/visit/visit_expr.rs @@ -1578,6 +1578,7 @@ impl<'a, const TYPESCRIPT: bool, const SCAN_ONLY: bool> P<'a, TYPESCRIPT, SCAN_O let mut e_ = e.data.e_array().expect("infallible: variant checked"); if in_.assign_target != js_ast::AssignTarget::None { p.maybe_comma_spread_error(e_.comma_after_spread); + p.maybe_parenthesized_assign_error(e_.parenthesized_assign); } let items = e_.items.slice_mut(); let mut spread_item_count: usize = 0; @@ -1687,6 +1688,7 @@ impl<'a, const TYPESCRIPT: bool, const SCAN_ONLY: bool> P<'a, TYPESCRIPT, SCAN_O let mut e_ = e.data.e_object().expect("infallible: variant checked"); if in_.assign_target != js_ast::AssignTarget::None { p.maybe_comma_spread_error(e_.comma_after_spread); + p.maybe_parenthesized_assign_error(e_.parenthesized_assign); } let mut has_spread = false; @@ -1726,8 +1728,9 @@ impl<'a, const TYPESCRIPT: bool, const SCAN_ONLY: bool> P<'a, TYPESCRIPT, SCAN_O has_spread = true; } - // Extract the initializer for expressions like "({ a: b = c } = d)" + // Extract the initializer for "({ a: b = c } = d)". A rest property takes none. if in_.assign_target != js_ast::AssignTarget::None + && property.kind != G::PropertyKind::Spread && property.initializer.is_none() && property.value.is_some() { @@ -1741,6 +1744,16 @@ impl<'a, const TYPESCRIPT: bool, const SCAN_ONLY: bool> P<'a, TYPESCRIPT, SCAN_O } } + // "({ ...[a] } = d)" is a syntax error. + if in_.assign_target != js_ast::AssignTarget::None + && property.kind == G::PropertyKind::Spread + && let Some(value) = &property.value + && matches!(value.data, Data::EArray(..) | Data::EObject(..)) + { + p.log() + .add_error(Some(p.source), value.loc, b"Invalid assignment target"); + } + if let Some(value) = &mut property.value { // Propagate name from property key for decorated anonymous class expressions // e.g., { Foo: @dec class {} } should give the class .name = "Foo" diff --git a/test/bundler/transpiler/transpiler.test.js b/test/bundler/transpiler/transpiler.test.js index 6ef742958718..4235f510d29f 100644 --- a/test/bundler/transpiler/transpiler.test.js +++ b/test/bundler/transpiler/transpiler.test.js @@ -2989,6 +2989,96 @@ console.log(
);`), // ); }); + it("parenthesized assignment in a destructuring pattern", () => { + // A parenthesized simple target may take a default value + expectPrinted_("[(a)] = [1]", "[a] = [1]"); + expectPrinted_("[(a) = 1] = []", "[a = 1] = []"); + expectPrinted_("[(o.b) = 1] = []", "[o.b = 1] = []"); + expectPrinted_("({ x: (a) = 1 } = {})", "({ x: a = 1 } = {})"); + expectPrinted_("({ x: (o.b) = 1 } = {})", "({ x: o.b = 1 } = {})"); + expectPrinted_("[...(o.r)] = []", "[...o.r] = []"); + expectPrinted_("[...[a]] = [[1]]", "[...[a]] = [[1]]"); + expectPrinted_("({ ...(a) } = {})", "({ ...a } = {})"); + expectPrinted_("({ ...(o.b) } = {})", "({ ...o.b } = {})"); + + // A member expression on a parenthesized assignment is a simple target + expectPrinted_("[(a = {}).b] = [1]", "[(a = {}).b] = [1]"); + expectPrinted_("[(a = [])[0]] = [1]", "[(a = [])[0]] = [1]"); + expectPrinted_("[(a = {}).b = 1] = []", "[(a = {}).b = 1] = []"); + expectPrinted_("({ x: (a = {}).b } = {})", "({ x: (a = {}).b } = {})"); + expectPrinted_("({ ...(a = {}).b } = {})", "({ ...(a = {}).b } = {})"); + expectPrinted_("[[(a = 1)].x] = []", "[[a = 1].x] = []"); + + // A default value is an arbitrary expression + expectPrinted_("[x = (a = 1)] = []", "[x = a = 1] = []"); + expectPrinted_("({ x = (a = 1) } = {})", "({ x = a = 1 } = {})"); + expectPrinted_("x = (y = (a = 1)) => 0", "x = (y = a = 1) => 0"); + + // Outside a pattern the parentheses mean nothing + expectPrinted_("x = [(a = 1)]", "x = [a = 1]"); + expectPrinted_("x = [[(a = 1)]]", "x = [[a = 1]]"); + expectPrinted_("x = { y: (a = 1) }", "x = { y: a = 1 }"); + expectPrinted_("x = { ...(a = 1) }", "x = { ...a = 1 }"); + expectPrinted_("f([(a = 1)])", "f([a = 1])"); + expectPrinted_("x = ([(a = 1)])", "x = [a = 1]"); + expectPrinted_("x = ((a = 1))", "x = a = 1"); + expectPrinted_("x = (y = [(a = 1)]) => 0", "x = (y = [a = 1]) => 0"); + + // A parenthesized assignment is not a valid destructuring target + const message = "Invalid assignment target"; + expectParseError("[(a = 1)] = []", message); + expectParseError("[[(a = 1)]] = [[]]", message); + expectParseError("[[(a = 1)] = 2] = []", message); + expectParseError("[{ x: (a = 1) }] = [{}]", message); + expectParseError("[...(a = 1)] = []", message); + expectParseError("[((a = 1))] = []", message); + expectParseError("[(a = 1) = 2] = []", message); + expectParseError("({ x: (a = 1) = 2 } = {})", message); + expectParseError("({ x: (a = 2) } = {})", message); + expectParseError("({ ...(a = 3) } = {})", message); + expectParseError("for ([(a = 1)] of x);", message); + expectParseError("for ([(a = 1)] in x);", message); + + // The target of an object rest property is a simple target with no initializer + expectParseError("({ ...a = 4 } = {})", message); + expectParseError("({ ...[a] } = {})", message); + expectParseError("({ ...{ a } } = {})", message); + expectParseError("[{ ...[a] }] = [{}]", message); + + // Several items share one pattern, in either order + expectParseError("[(a = 1), (b = 2).c] = []", message); + expectParseError("[(a = 1).c, (b = 2)] = []", message); + expectPrinted_("[(a = 1).c, (b = 2).d] = []", "[(a = 1).c, (b = 2).d] = []"); + expectParseError("({ x: (a = 1), y: (b = 2).c } = {})", message); + expectParseError("({ x: (a = 1).c, y: (b = 2) } = {})", message); + expectPrinted_("({ x: (a = 1).c, y: (b = 2).d } = {})", "({ x: (a = 1).c, y: (b = 2).d } = {})"); + expectParseError("[x, [(a = 1).c], (b = 2)] = []", message); + expectPrinted_("[x, [(a = 1)].c, (b = 2).d] = []", "[x, [a = 1].c, (b = 2).d] = []"); + + // A literal in a for-in initializer (Annex B) is not a pattern + expectPrinted_("for (var x = [(a = 1)] in o);", "x = [a = 1];\nfor (x in o)\n ;\nvar x;\n"); + expectPrinted_("for (var x = { y: (a = 1) } in o);", "x = { y: a = 1 };\nfor (x in o)\n ;\nvar x;\n"); + + // The same forms are not valid arrow parameters either + const arrowMessage = "Unexpected parentheses in binding pattern"; + expectParseError("((a = 1)) => 0", arrowMessage); + expectParseError("([(a = 1)]) => 0", arrowMessage); + expectParseError("([(a = 1)] = []) => 0", arrowMessage); + expectParseError("async ((a = 1)) => 0", arrowMessage); + expectParseError("(...(a = 1)) => 0", "A rest argument cannot have a default initializer"); + expectParseError("([...(a = 1)]) => 0", "A rest argument cannot have a default initializer"); + expectParseError("(x, (b = 2)) => 0", arrowMessage); + expectParseError("((a = 1), x) => 0", arrowMessage); + expectPrinted_("x = ((a = 1).c, (b = 2))", "x = ((a = 1).c, b = 2)"); + expectPrinted_("x = ({ ...a }) => a", "x = ({ ...a }) => a"); + ts.expectPrinted_("x = c ? ({ ...a = 1 }) : b", "x = c ? { ...a = 1 } : b"); + ts.expectPrinted_("x = c ? ([...a = 1]) : b", "x = c ? [...a = 1] : b"); + ts.expectPrinted_("x = c ? ([(a = 1)]) : b", "x = c ? [a = 1] : b"); + expectParseError("({ ...a = 1 }) => 0", "A rest argument cannot have a default initializer"); + expectParseError("({ ...[a] }) => 0", "Invalid binding pattern"); + expectParseError("({ ...{ a } }) => 0", "Invalid binding pattern"); + }); + it("import assert", () => { expectPrinted_(`import json from "./foo.json" assert { type: "json" };`, `import json from "./foo.json"`); expectPrinted_(`import json from "./foo.json";`, `import json from "./foo.json"`);