fix(rome_js_parser): Allow super in constructor parameter
Fix
MODIFY
crates/rome_js_parser/src/syntax/class.rs
crates/rome_js_parser/src/syntax/class.rs
@@ -1445,9 +1445,17 @@ fn parse_constructor_class_member_body(
fn parse_constructor_parameter_list(p: &mut Parser) -> ParsedSyntax {
let m = p.start();
+
+ // test super_expression_in_constructor_parameter_list
+ // class A extends B { constructor(c = super()) {} }
+ //
+ // test_err super_expression_in_constructor_parameter_list
+ // class A extends B { constructor(super()) {} }
+ let flags = SignatureFlags::CONSTRUCTOR;
+
parse_parameters_list(
p,
- SignatureFlags::empty(),
+ flags,
parse_constructor_parameter,
JS_CONSTRUCTOR_PARAMETER_LIST,
);

ADD
crates/rome_js_parser/test_data/inline/err/super_expression_in_constructor_parameter_list.js
+class A extends B { constructor(super()) {} }

ADD
crates/rome_js_parser/test_data/inline/ok/super_expression_in_constructor_parameter_list.js
+class A extends B { constructor(c = super()) {} }

ADD
crates/rome_js_parser/test_data/inline/ok/super_expression_in_constructor_parameter_list.rast
+JsModule {
+ interpreter_token: missing (optional),
+ directives: JsDirectiveList [],
+ items: JsModuleItemList [
+ JsClassDeclaration {
+ abstract_token: missing (optional),
+ class_token: CLASS_KW@0..6 "class" [] [Whitespace(" ")],
+ id: JsIdentifierBinding {
+ name_token: IDENT@6..8 "A" [] [Whitespace(" ")],
+ },
+ type_parameters: missing (optional),
+ extends_clause: JsExtendsClause {
+ extends_token: EXTENDS_KW@8..16 "extends" [] [Whitespace(" ")],
+ super_class: JsIdentifierExpression {
+ name: JsReferenceIdentifier {
+ value_token: IDENT@16..18 "B" [] [Whitespace(" ")],
+ },
+ },
+ type_arguments: missing (optional),
+ },
+ implements_clause: missing (optional),
+ l_curly_token: L_CURLY@18..20 "{" [] [Whitespace(" ")],
+ members: JsClassMemberList [
+ JsConstructorClassMember {
+ modifiers: JsConstructorModifierList [],
+ name: JsLiteralMemberName {
+ value: IDENT@20..31 "constructor" [] [],
+ },
+ parameters: JsConstructorParameters {
+ l_paren_token: L_PAREN@31..32 "(" [] [],
+ parameters: JsConstructorParameterList [
+ JsFormalParameter {
+ binding: JsIdentifierBinding {
+ name_token: IDENT@32..34 "c" [] [Whitespace(" ")],
+ },
+ question_mark_token: missing (optional),
+ type_annotation: missing (optional),
+ initializer: JsInitializerClause {
+ eq_token: EQ@34..36 "=" [] [Whitespace(" ")],
+ expression: JsCallExpression {
+ callee: JsSuperExpression {
+ super_token: SUPER_KW@36..41 "super" [] [],
+ },
+ optional_chain_token: missing (optional),
+ type_arguments: missing (optional),
+ arguments: JsCallArguments {
+ l_paren_token: L_PAREN@41..42 "(" [] [],
+ args: JsCallArgumentList [],
+ r_paren_token: R_PAREN@42..43 ")" [] [],
+ },
+ },
+ },
+ },
+ ],
+ r_paren_token: R_PAREN@43..45 ")" [] [Whitespace(" ")],
+ },
+ body: JsFunctionBody {
+ l_curly_token: L_CURLY@45..46 "{" [] [],
+ directives: JsDirectiveList [],
+ statements: JsStatementList [],
+ r_curly_token: R_CURLY@46..48 "}" [] [Whitespace(" ")],
+ },
+ },
+ ],
+ r_curly_token: R_CURLY@48..49 "}" [] [],
+ },
+ ],
+ eof_token: EOF@49..50 "" [Newline("\n")] [],
+}
+
+0: JS_MODULE@0..50
+ 0: (empty)
+ 1: JS_DIRECTIVE_LIST@0..0
+ 2: JS_MODULE_ITEM_LIST@0..49
+ 0: JS_CLASS_DECLARATION@0..49
+ 0: (empty)
+ 1: CLASS_KW@0..6 "class" [] [Whitespace(" ")]
+ 2: JS_IDENTIFIER_BINDING@6..8
+ 0: IDENT@6..8 "A" [] [Whitespace(" ")]
+ 3: (empty)
+ 4: JS_EXTENDS_CLAUSE@8..18
+ 0: EXTENDS_KW@8..16 "extends" [] [Whitespace(" ")]
+ 1: JS_IDENTIFIER_EXPRESSION@16..18
+ 0: JS_REFERENCE_IDENTIFIER@16..18
+ 0: IDENT@16..18 "B" [] [Whitespace(" ")]
+ 2: (empty)
+ 5: (empty)
+ 6: L_CURLY@18..20 "{" [] [Whitespace(" ")]
+ 7: JS_CLASS_MEMBER_LIST@20..48
+ 0: JS_CONSTRUCTOR_CLASS_MEMBER@20..48
+ 0: JS_CONSTRUCTOR_MODIFIER_LIST@20..20
+ 1: JS_LITERAL_MEMBER_NAME@20..31
+ 0: IDENT@20..31 "constructor" [] []
+ 2: JS_CONSTRUCTOR_PARAMETERS@31..45
+ 0: L_PAREN@31..32 "(" [] []
+ 1: JS_CONSTRUCTOR_PARAMETER_LIST@32..43
+ 0: JS_FORMAL_PARAMETER@32..43
+ 0: JS_IDENTIFIER_BINDING@32..34
+ 0: IDENT@32..34 "c" [] [Whitespace(" ")]
+ 1: (empty)
+ 2: (empty)
+ 3: JS_INITIALIZER_CLAUSE@34..43
+ 0: EQ@34..36 "=" [] [Whitespace(" ")]
+ 1: JS_CALL_EXPRESSION@36..43
+ 0: JS_SUPER_EXPRESSION@36..41
+ 0: SUPER_KW@36..41 "super" [] []
+ 1: (empty)
+ 2: (empty)
+ 3: JS_CALL_ARGUMENTS@41..43
+ 0: L_PAREN@41..42 "(" [] []
+ 1: JS_CALL_ARGUMENT_LIST@42..42
+ 2: R_PAREN@42..43 ")" [] []
+ 2: R_PAREN@43..45 ")" [] [Whitespace(" ")]
+ 3: JS_FUNCTION_BODY@45..48
+ 0: L_CURLY@45..46 "{" [] []
+ 1: JS_DIRECTIVE_LIST@46..46
+ 2: JS_STATEMENT_LIST@46..46
+ 3: R_CURLY@46..48 "}" [] [Whitespace(" ")]
+ 8: R_CURLY@48..49 "}" [] []
+ 3: EOF@49..50 "" [Newline("\n")] []

fix(rome_js_parser): Allow super in constructor parameter #3613 (#3678)

Fix https://github.com/rome/tools/issues/3613