From 6d509e74e93433f628ccb2fe6d46ac5791bf7ad3 Mon Sep 17 00:00:00 2001 From: Denis Bezrukov <6227442+denbezrukov@users.noreply.github.com> Date: Tue, 25 Apr 2023 21:15:03 +0300 Subject: [PATCH] feat(rome_js_parser): EcmaScript @decorators #4252 --- crates/rome_js_parser/src/syntax/auxiliary.rs | 5 +- crates/rome_js_parser/src/syntax/class.rs | 7 - crates/rome_js_parser/src/syntax/expr.rs | 8 +- .../src/syntax/js_parse_error.rs | 6 + crates/rome_js_parser/src/syntax/module.rs | 18 +- crates/rome_js_parser/src/syntax/stmt.rs | 6 +- .../test_data/inline/err/decorator.rast | 48 +++-- ...ion_export_default_declaration_clause.rast | 68 +++---- ...ction_export_default_declaration_clause.ts | 2 +- .../err/decorator_class_declaration.rast | 8 +- ...decorator_class_declaration_top_level.rast | 8 +- ...num_export_default_declaration_clause.rast | 4 +- .../err/decorator_export_class_clause.rast | 8 +- ...ator_export_default_expression_clause.rast | 4 +- .../inline/err/decorator_expression_class.js | 2 +- .../err/decorator_expression_class.rast | 182 +++++++++--------- ...ion_export_default_declaration_clause.rast | 68 +++---- ...ction_export_default_declaration_clause.ts | 2 +- ...ace_export_default_declaration_clause.rast | 4 +- .../err/ts_declare_const_initializer.rast | 8 +- .../inline/err/ts_export_declare.rast | 8 +- .../inline/ok/ts_class_decorator.rast | 177 ----------------- .../test_data/inline/ok/ts_class_decorator.ts | 5 - 23 files changed, 246 insertions(+), 410 deletions(-) delete mode 100644 crates/rome_js_parser/test_data/inline/ok/ts_class_decorator.rast delete mode 100644 crates/rome_js_parser/test_data/inline/ok/ts_class_decorator.ts diff --git a/crates/rome_js_parser/src/syntax/auxiliary.rs b/crates/rome_js_parser/src/syntax/auxiliary.rs index 6932f72a7f9..c12cfefbe88 100644 --- a/crates/rome_js_parser/src/syntax/auxiliary.rs +++ b/crates/rome_js_parser/src/syntax/auxiliary.rs @@ -1,6 +1,7 @@ use crate::prelude::*; use crate::syntax::class::{parse_class_declaration, parse_decorators}; use crate::syntax::function::parse_function_declaration; +use crate::syntax::js_parse_error::decorators_not_allowed; use crate::syntax::module::parse_import_or_import_equals_declaration; use crate::syntax::stmt::{ is_nth_at_variable_declarations, parse_variable_declaration, semi, StatementContext, @@ -101,9 +102,7 @@ pub(crate) fn parse_declaration_clause(p: &mut JsParser, stmt_start_pos: TextSiz // @decorator1 @decorator2 // export function Foo() { } decorator_list - .add_diagnostic_if_present(p, |p, range| { - p.err_builder("Decorators are not valid here.", range) - }) + .add_diagnostic_if_present(p, decorators_not_allowed) .map(|mut marker| { marker.change_kind(p, JS_BOGUS_STATEMENT); marker diff --git a/crates/rome_js_parser/src/syntax/class.rs b/crates/rome_js_parser/src/syntax/class.rs index 7dd88aa47f1..7e8b891e361 100644 --- a/crates/rome_js_parser/src/syntax/class.rs +++ b/crates/rome_js_parser/src/syntax/class.rs @@ -2497,13 +2497,6 @@ fn parse_decorator(p: &mut JsParser) -> ParsedSyntax { Present(m.complete(p, JS_DECORATOR)) } -// test ts ts_class_decorator -// function test() {} -// @test -// class Test {} -// @test.a?.c @test @test -// class Test2{} - /// Skips over any TypeScript decorator syntax. pub(crate) fn skip_ts_decorators(p: &mut JsParser) { if !p.at(T![@]) { diff --git a/crates/rome_js_parser/src/syntax/expr.rs b/crates/rome_js_parser/src/syntax/expr.rs index b869e2936e9..6418acd82ef 100644 --- a/crates/rome_js_parser/src/syntax/expr.rs +++ b/crates/rome_js_parser/src/syntax/expr.rs @@ -18,7 +18,7 @@ use crate::syntax::function::{ is_at_async_function, parse_arrow_function_expression, parse_function_expression, LineBreak, }; use crate::syntax::js_parse_error; -use crate::syntax::js_parse_error::expected_simple_assignment_target; +use crate::syntax::js_parse_error::{decorators_not_allowed, expected_simple_assignment_target}; use crate::syntax::js_parse_error::{ expected_expression, expected_identifier, invalid_assignment_error, private_names_only_allowed_on_left_side_of_in_expression, @@ -1292,12 +1292,10 @@ fn parse_primary_expression(p: &mut JsParser, context: ExpressionContext) -> Par _ => { // test_err decorator_expression_class // let a = @decorator () => {}; - // let b = @first @second function foo {} + // let b = @first @second function foo() {} // let a = @decorator ( () => {} ) decorator_list - .add_diagnostic_if_present(p, |p, range| { - p.err_builder("Decorators are not valid here.", range) - }) + .add_diagnostic_if_present(p, decorators_not_allowed) .map(|mut marker| { marker.change_kind(p, JS_BOGUS_EXPRESSION); marker diff --git a/crates/rome_js_parser/src/syntax/js_parse_error.rs b/crates/rome_js_parser/src/syntax/js_parse_error.rs index 70940d07cd3..80796c06576 100644 --- a/crates/rome_js_parser/src/syntax/js_parse_error.rs +++ b/crates/rome_js_parser/src/syntax/js_parse_error.rs @@ -282,3 +282,9 @@ pub(crate) fn invalid_decorator_error(p: &JsParser, range: TextRange) -> ParseDi range, ) } + +pub(crate) fn decorators_not_allowed(p: &JsParser, range: TextRange) -> ParseDiagnostic { + p.err_builder("Decorators are not valid here", range).hint( + "Decorators are only valid on class declarations, class expressions, and class methods", + ) +} diff --git a/crates/rome_js_parser/src/syntax/module.rs b/crates/rome_js_parser/src/syntax/module.rs index c6f99cf0001..08993f85b96 100644 --- a/crates/rome_js_parser/src/syntax/module.rs +++ b/crates/rome_js_parser/src/syntax/module.rs @@ -15,9 +15,9 @@ use crate::syntax::expr::{ }; use crate::syntax::function::{parse_function_export_default_declaration, LineBreak}; use crate::syntax::js_parse_error::{ - duplicate_assertion_keys_error, expected_binding, expected_declaration, expected_export_clause, - expected_export_default_declaration, expected_export_name_specifier, expected_expression, - expected_identifier, expected_literal_export_name, expected_module_source, + decorators_not_allowed, duplicate_assertion_keys_error, expected_binding, expected_declaration, + expected_export_clause, expected_export_default_declaration, expected_export_name_specifier, + expected_expression, expected_identifier, expected_literal_export_name, expected_module_source, expected_named_import, expected_named_import_specifier, expected_statement, }; use crate::syntax::stmt::{parse_statement, semi, StatementContext, STMT_RECOVERY_SET}; @@ -193,9 +193,7 @@ fn parse_module_item(p: &mut JsParser) -> ParsedSyntax { // @decorator1 @decorator2 // function Foo() { } decorator_list - .add_diagnostic_if_present(p, |p, range| { - p.err_builder("Decorators are not valid here.", range) - }) + .add_diagnostic_if_present(p, decorators_not_allowed) .map(|mut marker| { marker.change_kind(p, JS_BOGUS_STATEMENT); marker @@ -1203,9 +1201,7 @@ fn parse_export_default_clause(p: &mut JsParser) -> ParsedSyntax { } _ => { decorator_list - .add_diagnostic_if_present(p, |p, range| { - p.err_builder("Decorators are not valid here.", range) - }) + .add_diagnostic_if_present(p, decorators_not_allowed) .map(|mut marker| { marker.change_kind(p, JS_BOGUS_STATEMENT); marker @@ -1214,11 +1210,11 @@ fn parse_export_default_clause(p: &mut JsParser) -> ParsedSyntax { match p.cur() { // test_err ts decorator_function_export_default_declaration_clause // @decorator - // export default function foo { } + // export default function foo() { } T![function] => parse_function_export_default_declaration_clause(p, m), // test_err ts decorator_async_function_export_default_declaration_clause // @decorator - // export default async function foo { } + // export default async function foo() { } T![async] if p.nth_at(1, T![function]) => { parse_function_export_default_declaration_clause(p, m) } diff --git a/crates/rome_js_parser/src/syntax/stmt.rs b/crates/rome_js_parser/src/syntax/stmt.rs index 18904ef78b5..2614bd88f47 100644 --- a/crates/rome_js_parser/src/syntax/stmt.rs +++ b/crates/rome_js_parser/src/syntax/stmt.rs @@ -22,7 +22,7 @@ use crate::syntax::expr::{ }; use crate::syntax::function::{is_at_async_function, parse_function_declaration, LineBreak}; use crate::syntax::js_parse_error; -use crate::syntax::js_parse_error::{expected_binding, expected_statement}; +use crate::syntax::js_parse_error::{decorators_not_allowed, expected_binding, expected_statement}; use crate::syntax::module::parse_import_or_import_equals_declaration; use crate::syntax::typescript::ts_parse_error::{expected_ts_type, ts_only_syntax_error}; @@ -270,9 +270,7 @@ pub(crate) fn parse_statement(p: &mut JsParser, context: StatementContext) -> Pa // function Foo() { } // } decorator_list - .add_diagnostic_if_present(p, |p, range| { - p.err_builder("Decorators are not valid here.", range) - }) + .add_diagnostic_if_present(p, decorators_not_allowed) .map(|mut marker| { marker.change_kind(p, JS_BOGUS_STATEMENT); marker diff --git a/crates/rome_js_parser/test_data/inline/err/decorator.rast b/crates/rome_js_parser/test_data/inline/err/decorator.rast index 66622f336d0..1baa3890ba1 100644 --- a/crates/rome_js_parser/test_data/inline/err/decorator.rast +++ b/crates/rome_js_parser/test_data/inline/err/decorator.rast @@ -1153,7 +1153,7 @@ decorator.ts:3:2 parse ━━━━━━━━━━━━━━━━━━━ -- decorator.ts:3:1 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - × Decorators are not valid here. + × Decorators are not valid here 1 │ @'dsads' class MyClass {} 2 │ @1 class MyClass {} @@ -1162,6 +1162,8 @@ decorator.ts:3:1 parse ━━━━━━━━━━━━━━━━━━━ 4 │ @[] in 1 class MyClass {} 5 │ @[] class MyClass {} + i Decorators are only valid on class declarations, class expressions, and class methods + -- decorator.ts:3:4 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ @@ -1221,7 +1223,7 @@ decorator.ts:4:2 parse ━━━━━━━━━━━━━━━━━━━ -- decorator.ts:4:1 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - × Decorators are not valid here. + × Decorators are not valid here 2 │ @1 class MyClass {} 3 │ @++1 class MyClass {} @@ -1230,6 +1232,8 @@ decorator.ts:4:1 parse ━━━━━━━━━━━━━━━━━━━ 5 │ @[] class MyClass {} 6 │ @() => {} class MyClass {} + i Decorators are only valid on class declarations, class expressions, and class methods + -- decorator.ts:4:5 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ @@ -1280,7 +1284,7 @@ decorator.ts:6:3 parse ━━━━━━━━━━━━━━━━━━━ -- decorator.ts:6:1 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - × Decorators are not valid here. + × Decorators are not valid here 4 │ @[] in 1 class MyClass {} 5 │ @[] class MyClass {} @@ -1289,6 +1293,8 @@ decorator.ts:6:1 parse ━━━━━━━━━━━━━━━━━━━ 7 │ @1 == 2 ? true : false class MyClass {} 8 │ @await fn class MyClass {} + i Decorators are only valid on class declarations, class expressions, and class methods + -- decorator.ts:6:5 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ @@ -1325,7 +1331,7 @@ decorator.ts:7:2 parse ━━━━━━━━━━━━━━━━━━━ -- decorator.ts:7:1 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - × Decorators are not valid here. + × Decorators are not valid here 5 │ @[] class MyClass {} 6 │ @() => {} class MyClass {} @@ -1334,6 +1340,8 @@ decorator.ts:7:1 parse ━━━━━━━━━━━━━━━━━━━ 8 │ @await fn class MyClass {} 9 │ @function(){} class MyClass {} + i Decorators are only valid on class declarations, class expressions, and class methods + -- decorator.ts:7:4 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ @@ -1370,7 +1378,7 @@ decorator.ts:8:2 parse ━━━━━━━━━━━━━━━━━━━ -- decorator.ts:8:1 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - × Decorators are not valid here. + × Decorators are not valid here 6 │ @() => {} class MyClass {} 7 │ @1 == 2 ? true : false class MyClass {} @@ -1379,6 +1387,8 @@ decorator.ts:8:1 parse ━━━━━━━━━━━━━━━━━━━ 9 │ @function(){} class MyClass {} 10 │ @obj instanceof Object class MyClass {} + i Decorators are only valid on class declarations, class expressions, and class methods + -- decorator.ts:8:11 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ @@ -1424,7 +1434,7 @@ decorator.ts:9:2 parse ━━━━━━━━━━━━━━━━━━━ -- decorator.ts:10:1 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - × Decorators are not valid here. + × Decorators are not valid here 8 │ @await fn class MyClass {} 9 │ @function(){} class MyClass {} @@ -1433,6 +1443,8 @@ decorator.ts:10:1 parse ━━━━━━━━━━━━━━━━━━ 11 │ @1 === 2 class MyClass {} 12 │ @new Object() class MyClass {} + i Decorators are only valid on class declarations, class expressions, and class methods + -- decorator.ts:10:6 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ @@ -1469,7 +1481,7 @@ decorator.ts:11:2 parse ━━━━━━━━━━━━━━━━━━ -- decorator.ts:11:1 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - × Decorators are not valid here. + × Decorators are not valid here 9 │ @function(){} class MyClass {} 10 │ @obj instanceof Object class MyClass {} @@ -1478,6 +1490,8 @@ decorator.ts:11:1 parse ━━━━━━━━━━━━━━━━━━ 12 │ @new Object() class MyClass {} 13 │ @{} class MyClass {} + i Decorators are only valid on class declarations, class expressions, and class methods + -- decorator.ts:11:4 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ @@ -1526,7 +1540,7 @@ decorator.ts:13:2 parse ━━━━━━━━━━━━━━━━━━ -- decorator.ts:14:1 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - × Decorators are not valid here. + × Decorators are not valid here 12 │ @new Object() class MyClass {} 13 │ @{} class MyClass {} @@ -1535,6 +1549,8 @@ decorator.ts:14:1 parse ━━━━━━━━━━━━━━━━━━ 15 │ @a,b class MyClass {} 16 │ @`${d}foo` class MyClass {} + i Decorators are only valid on class declarations, class expressions, and class methods + -- decorator.ts:14:6 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ @@ -1552,7 +1568,7 @@ decorator.ts:14:6 parse ━━━━━━━━━━━━━━━━━━ -- decorator.ts:15:1 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - × Decorators are not valid here. + × Decorators are not valid here 13 │ @{} class MyClass {} 14 │ @a++ class MyClass {} @@ -1561,6 +1577,8 @@ decorator.ts:15:1 parse ━━━━━━━━━━━━━━━━━━ 16 │ @`${d}foo` class MyClass {} 17 │ @obj as MyType class MyClass {} + i Decorators are only valid on class declarations, class expressions, and class methods + -- decorator.ts:15:3 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ @@ -1597,7 +1615,7 @@ decorator.ts:16:2 parse ━━━━━━━━━━━━━━━━━━ -- decorator.ts:17:1 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - × Decorators are not valid here. + × Decorators are not valid here 15 │ @a,b class MyClass {} 16 │ @`${d}foo` class MyClass {} @@ -1606,6 +1624,8 @@ decorator.ts:17:1 parse ━━━━━━━━━━━━━━━━━━ 18 │ @obj class MyClass {} 19 │ @obj satisfies MyType class MyClass {} + i Decorators are only valid on class declarations, class expressions, and class methods + -- decorator.ts:17:9 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ @@ -1690,7 +1710,7 @@ decorator.ts:18:2 parse ━━━━━━━━━━━━━━━━━━ -- decorator.ts:18:1 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - × Decorators are not valid here. + × Decorators are not valid here 16 │ @`${d}foo` class MyClass {} 17 │ @obj as MyType class MyClass {} @@ -1699,6 +1719,8 @@ decorator.ts:18:1 parse ━━━━━━━━━━━━━━━━━━ 19 │ @obj satisfies MyType class MyClass {} 20 │ @obj! class MyClass {} + i Decorators are only valid on class declarations, class expressions, and class methods + -- decorator.ts:18:14 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ @@ -1732,7 +1754,7 @@ decorator.ts:18:14 parse ━━━━━━━━━━━━━━━━━━ -- decorator.ts:19:1 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - × Decorators are not valid here. + × Decorators are not valid here 17 │ @obj as MyType class MyClass {} 18 │ @obj class MyClass {} @@ -1741,6 +1763,8 @@ decorator.ts:19:1 parse ━━━━━━━━━━━━━━━━━━ 20 │ @obj! class MyClass {} 21 │ + i Decorators are only valid on class declarations, class expressions, and class methods + -- decorator.ts:19:16 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ diff --git a/crates/rome_js_parser/test_data/inline/err/decorator_async_function_export_default_declaration_clause.rast b/crates/rome_js_parser/test_data/inline/err/decorator_async_function_export_default_declaration_clause.rast index 493d0075750..e55cda8b3c1 100644 --- a/crates/rome_js_parser/test_data/inline/err/decorator_async_function_export_default_declaration_clause.rast +++ b/crates/rome_js_parser/test_data/inline/err/decorator_async_function_export_default_declaration_clause.rast @@ -24,83 +24,75 @@ JsModule { function_token: FUNCTION_KW@32..41 "function" [] [Whitespace(" ")], star_token: missing (optional), id: JsIdentifierBinding { - name_token: IDENT@41..45 "foo" [] [Whitespace(" ")], + name_token: IDENT@41..44 "foo" [] [], }, type_parameters: missing (optional), - parameters: missing (required), + parameters: JsParameters { + l_paren_token: L_PAREN@44..45 "(" [] [], + items: JsParameterList [], + r_paren_token: R_PAREN@45..47 ")" [] [Whitespace(" ")], + }, return_type_annotation: missing (optional), body: JsFunctionBody { - l_curly_token: L_CURLY@45..47 "{" [] [Whitespace(" ")], + l_curly_token: L_CURLY@47..49 "{" [] [Whitespace(" ")], directives: JsDirectiveList [], statements: JsStatementList [], - r_curly_token: R_CURLY@47..48 "}" [] [], + r_curly_token: R_CURLY@49..50 "}" [] [], }, }, semicolon_token: missing (optional), }, }, ], - eof_token: EOF@48..49 "" [Newline("\n")] [], + eof_token: EOF@50..51 "" [Newline("\n")] [], } -0: JS_MODULE@0..49 +0: JS_MODULE@0..51 0: (empty) 1: JS_DIRECTIVE_LIST@0..0 - 2: JS_MODULE_ITEM_LIST@0..48 + 2: JS_MODULE_ITEM_LIST@0..50 0: JS_BOGUS_STATEMENT@0..10 0: JS_DECORATOR@0..10 0: AT@0..1 "@" [] [] 1: JS_IDENTIFIER_EXPRESSION@1..10 0: JS_REFERENCE_IDENTIFIER@1..10 0: IDENT@1..10 "decorator" [] [] - 1: JS_EXPORT@10..48 + 1: JS_EXPORT@10..50 0: JS_DECORATOR_LIST@10..10 1: EXPORT_KW@10..18 "export" [Newline("\n")] [Whitespace(" ")] - 2: JS_EXPORT_DEFAULT_DECLARATION_CLAUSE@18..48 + 2: JS_EXPORT_DEFAULT_DECLARATION_CLAUSE@18..50 0: DEFAULT_KW@18..26 "default" [] [Whitespace(" ")] - 1: JS_FUNCTION_EXPORT_DEFAULT_DECLARATION@26..48 + 1: JS_FUNCTION_EXPORT_DEFAULT_DECLARATION@26..50 0: ASYNC_KW@26..32 "async" [] [Whitespace(" ")] 1: FUNCTION_KW@32..41 "function" [] [Whitespace(" ")] 2: (empty) - 3: JS_IDENTIFIER_BINDING@41..45 - 0: IDENT@41..45 "foo" [] [Whitespace(" ")] + 3: JS_IDENTIFIER_BINDING@41..44 + 0: IDENT@41..44 "foo" [] [] 4: (empty) - 5: (empty) + 5: JS_PARAMETERS@44..47 + 0: L_PAREN@44..45 "(" [] [] + 1: JS_PARAMETER_LIST@45..45 + 2: R_PAREN@45..47 ")" [] [Whitespace(" ")] 6: (empty) - 7: JS_FUNCTION_BODY@45..48 - 0: L_CURLY@45..47 "{" [] [Whitespace(" ")] - 1: JS_DIRECTIVE_LIST@47..47 - 2: JS_STATEMENT_LIST@47..47 - 3: R_CURLY@47..48 "}" [] [] + 7: JS_FUNCTION_BODY@47..50 + 0: L_CURLY@47..49 "{" [] [Whitespace(" ")] + 1: JS_DIRECTIVE_LIST@49..49 + 2: JS_STATEMENT_LIST@49..49 + 3: R_CURLY@49..50 "}" [] [] 2: (empty) - 3: EOF@48..49 "" [Newline("\n")] [] + 3: EOF@50..51 "" [Newline("\n")] [] -- decorator_async_function_export_default_declaration_clause.ts:1:1 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - × Decorators are not valid here. + × Decorators are not valid here > 1 │ @decorator │ ^^^^^^^^^^ - 2 │ export default async function foo { } - 3 │ - --- -decorator_async_function_export_default_declaration_clause.ts:2:35 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━ - - × expected a parenthesis '(' but instead found '{' - - 1 │ @decorator - > 2 │ export default async function foo { } - │ ^ + 2 │ export default async function foo() { } 3 │ - i Expected a parenthesis '(' here - - 1 │ @decorator - > 2 │ export default async function foo { } - │ ^ - 3 │ + i Decorators are only valid on class declarations, class expressions, and class methods -- @decorator -export default async function foo { } +export default async function foo() { } diff --git a/crates/rome_js_parser/test_data/inline/err/decorator_async_function_export_default_declaration_clause.ts b/crates/rome_js_parser/test_data/inline/err/decorator_async_function_export_default_declaration_clause.ts index a842fad172b..f4ca3bb0470 100644 --- a/crates/rome_js_parser/test_data/inline/err/decorator_async_function_export_default_declaration_clause.ts +++ b/crates/rome_js_parser/test_data/inline/err/decorator_async_function_export_default_declaration_clause.ts @@ -1,2 +1,2 @@ @decorator -export default async function foo { } +export default async function foo() { } diff --git a/crates/rome_js_parser/test_data/inline/err/decorator_class_declaration.rast b/crates/rome_js_parser/test_data/inline/err/decorator_class_declaration.rast index b29e008143e..e0877e859d6 100644 --- a/crates/rome_js_parser/test_data/inline/err/decorator_class_declaration.rast +++ b/crates/rome_js_parser/test_data/inline/err/decorator_class_declaration.rast @@ -165,7 +165,7 @@ JsModule { -- decorator_class_declaration.js:2:6 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - × Decorators are not valid here. + × Decorators are not valid here 1 │ function bar() { > 2 │ @decorator @@ -173,10 +173,12 @@ decorator_class_declaration.js:2:6 parse ━━━━━━━━━━━━━ 3 │ let a; 4 │ @decorator @decorator2 + i Decorators are only valid on class declarations, class expressions, and class methods + -- decorator_class_declaration.js:4:6 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - × Decorators are not valid here. + × Decorators are not valid here 2 │ @decorator 3 │ let a; @@ -185,6 +187,8 @@ decorator_class_declaration.js:4:6 parse ━━━━━━━━━━━━━ 5 │ function Foo() { } 6 │ } + i Decorators are only valid on class declarations, class expressions, and class methods + -- function bar() { @decorator diff --git a/crates/rome_js_parser/test_data/inline/err/decorator_class_declaration_top_level.rast b/crates/rome_js_parser/test_data/inline/err/decorator_class_declaration_top_level.rast index 2c7b9b9bfff..2a43ef15d1d 100644 --- a/crates/rome_js_parser/test_data/inline/err/decorator_class_declaration_top_level.rast +++ b/crates/rome_js_parser/test_data/inline/err/decorator_class_declaration_top_level.rast @@ -126,17 +126,19 @@ JsModule { -- decorator_class_declaration_top_level.js:1:1 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - × Decorators are not valid here. + × Decorators are not valid here > 1 │ @decorator │ ^^^^^^^^^^ 2 │ let a; 3 │ @decorator1 @decorator2 + i Decorators are only valid on class declarations, class expressions, and class methods + -- decorator_class_declaration_top_level.js:3:1 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - × Decorators are not valid here. + × Decorators are not valid here 1 │ @decorator 2 │ let a; @@ -145,6 +147,8 @@ decorator_class_declaration_top_level.js:3:1 parse ━━━━━━━━━ 4 │ function Foo() { } 5 │ + i Decorators are only valid on class declarations, class expressions, and class methods + -- @decorator let a; diff --git a/crates/rome_js_parser/test_data/inline/err/decorator_enum_export_default_declaration_clause.rast b/crates/rome_js_parser/test_data/inline/err/decorator_enum_export_default_declaration_clause.rast index 29eab8a2036..6eafeedcdf3 100644 --- a/crates/rome_js_parser/test_data/inline/err/decorator_enum_export_default_declaration_clause.rast +++ b/crates/rome_js_parser/test_data/inline/err/decorator_enum_export_default_declaration_clause.rast @@ -101,13 +101,15 @@ JsModule { -- decorator_enum_export_default_declaration_clause.ts:1:1 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - × Decorators are not valid here. + × Decorators are not valid here > 1 │ @decorator │ ^^^^^^^^^^ 2 │ export default enum A { X, Y, Z } 3 │ + i Decorators are only valid on class declarations, class expressions, and class methods + -- decorator_enum_export_default_declaration_clause.ts:2:16 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ diff --git a/crates/rome_js_parser/test_data/inline/err/decorator_export_class_clause.rast b/crates/rome_js_parser/test_data/inline/err/decorator_export_class_clause.rast index f392a423763..e59d0d2c525 100644 --- a/crates/rome_js_parser/test_data/inline/err/decorator_export_class_clause.rast +++ b/crates/rome_js_parser/test_data/inline/err/decorator_export_class_clause.rast @@ -140,17 +140,19 @@ JsModule { -- decorator_export_class_clause.js:1:1 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - × Decorators are not valid here. + × Decorators are not valid here > 1 │ @decorator │ ^^^^^^^^^^ 2 │ export let a; 3 │ @decorator1 @decorator2 + i Decorators are only valid on class declarations, class expressions, and class methods + -- decorator_export_class_clause.js:3:1 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - × Decorators are not valid here. + × Decorators are not valid here 1 │ @decorator 2 │ export let a; @@ -159,6 +161,8 @@ decorator_export_class_clause.js:3:1 parse ━━━━━━━━━━━━ 4 │ export function Foo() { } 5 │ + i Decorators are only valid on class declarations, class expressions, and class methods + -- @decorator export let a; diff --git a/crates/rome_js_parser/test_data/inline/err/decorator_export_default_expression_clause.rast b/crates/rome_js_parser/test_data/inline/err/decorator_export_default_expression_clause.rast index 8f82021ca9b..c2f154a21e8 100644 --- a/crates/rome_js_parser/test_data/inline/err/decorator_export_default_expression_clause.rast +++ b/crates/rome_js_parser/test_data/inline/err/decorator_export_default_expression_clause.rast @@ -54,13 +54,15 @@ JsModule { -- decorator_export_default_expression_clause.ts:1:1 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - × Decorators are not valid here. + × Decorators are not valid here > 1 │ @decorator │ ^^^^^^^^^^ 2 │ export default a; 3 │ + i Decorators are only valid on class declarations, class expressions, and class methods + -- @decorator export default a; diff --git a/crates/rome_js_parser/test_data/inline/err/decorator_expression_class.js b/crates/rome_js_parser/test_data/inline/err/decorator_expression_class.js index b714579375d..d4aa5804954 100644 --- a/crates/rome_js_parser/test_data/inline/err/decorator_expression_class.js +++ b/crates/rome_js_parser/test_data/inline/err/decorator_expression_class.js @@ -1,3 +1,3 @@ let a = @decorator () => {}; -let b = @first @second function foo {} +let b = @first @second function foo() {} let a = @decorator ( () => {} ) diff --git a/crates/rome_js_parser/test_data/inline/err/decorator_expression_class.rast b/crates/rome_js_parser/test_data/inline/err/decorator_expression_class.rast index 0915406adc7..4dff1823dc7 100644 --- a/crates/rome_js_parser/test_data/inline/err/decorator_expression_class.rast +++ b/crates/rome_js_parser/test_data/inline/err/decorator_expression_class.rast @@ -102,16 +102,20 @@ JsModule { function_token: FUNCTION_KW@52..61 "function" [] [Whitespace(" ")], star_token: missing (optional), id: JsIdentifierBinding { - name_token: IDENT@61..65 "foo" [] [Whitespace(" ")], + name_token: IDENT@61..64 "foo" [] [], }, type_parameters: missing (optional), - parameters: missing (required), + parameters: JsParameters { + l_paren_token: L_PAREN@64..65 "(" [] [], + items: JsParameterList [], + r_paren_token: R_PAREN@65..67 ")" [] [Whitespace(" ")], + }, return_type_annotation: missing (optional), body: JsFunctionBody { - l_curly_token: L_CURLY@65..66 "{" [] [], + l_curly_token: L_CURLY@67..68 "{" [] [], directives: JsDirectiveList [], statements: JsStatementList [], - r_curly_token: R_CURLY@66..67 "}" [] [], + r_curly_token: R_CURLY@68..69 "}" [] [], }, }, ], @@ -126,49 +130,49 @@ JsModule { }, JsVariableStatement { declaration: JsVariableDeclaration { - kind: LET_KW@67..72 "let" [Newline("\n")] [Whitespace(" ")], + kind: LET_KW@69..74 "let" [Newline("\n")] [Whitespace(" ")], declarators: JsVariableDeclaratorList [ JsVariableDeclarator { id: JsIdentifierBinding { - name_token: IDENT@72..74 "a" [] [Whitespace(" ")], + name_token: IDENT@74..76 "a" [] [Whitespace(" ")], }, variable_annotation: missing (optional), initializer: JsInitializerClause { - eq_token: EQ@74..76 "=" [] [Whitespace(" ")], + eq_token: EQ@76..78 "=" [] [Whitespace(" ")], expression: JsBogusExpression { items: [ JsDecorator { - at_token: AT@76..77 "@" [] [], + at_token: AT@78..79 "@" [] [], expression: JsCallExpression { callee: JsIdentifierExpression { name: JsReferenceIdentifier { - value_token: IDENT@77..87 "decorator" [] [Whitespace(" ")], + value_token: IDENT@79..89 "decorator" [] [Whitespace(" ")], }, }, optional_chain_token: missing (optional), type_arguments: missing (optional), arguments: JsCallArguments { - l_paren_token: L_PAREN@87..89 "(" [] [Whitespace(" ")], + l_paren_token: L_PAREN@89..91 "(" [] [Whitespace(" ")], args: JsCallArgumentList [ JsArrowFunctionExpression { async_token: missing (optional), type_parameters: missing (optional), parameters: JsParameters { - l_paren_token: L_PAREN@89..90 "(" [] [], + l_paren_token: L_PAREN@91..92 "(" [] [], items: JsParameterList [], - r_paren_token: R_PAREN@90..92 ")" [] [Whitespace(" ")], + r_paren_token: R_PAREN@92..94 ")" [] [Whitespace(" ")], }, return_type_annotation: missing (optional), - fat_arrow_token: FAT_ARROW@92..95 "=>" [] [Whitespace(" ")], + fat_arrow_token: FAT_ARROW@94..97 "=>" [] [Whitespace(" ")], body: JsFunctionBody { - l_curly_token: L_CURLY@95..96 "{" [] [], + l_curly_token: L_CURLY@97..98 "{" [] [], directives: JsDirectiveList [], statements: JsStatementList [], - r_curly_token: R_CURLY@96..98 "}" [] [Whitespace(" ")], + r_curly_token: R_CURLY@98..100 "}" [] [Whitespace(" ")], }, }, ], - r_paren_token: R_PAREN@98..99 ")" [] [], + r_paren_token: R_PAREN@100..101 ")" [] [], }, }, }, @@ -181,13 +185,13 @@ JsModule { semicolon_token: missing (optional), }, ], - eof_token: EOF@99..100 "" [Newline("\n")] [], + eof_token: EOF@101..102 "" [Newline("\n")] [], } -0: JS_MODULE@0..100 +0: JS_MODULE@0..102 0: (empty) 1: JS_DIRECTIVE_LIST@0..0 - 2: JS_MODULE_ITEM_LIST@0..99 + 2: JS_MODULE_ITEM_LIST@0..101 0: JS_BOGUS_STATEMENT@0..28 0: JS_BOGUS@0..27 0: LET_KW@0..4 "let" [] [Whitespace(" ")] @@ -222,14 +226,14 @@ JsModule { 2: JS_STATEMENT_LIST@26..26 3: R_CURLY@26..27 "}" [] [] 1: SEMICOLON@27..28 ";" [] [] - 1: JS_BOGUS_STATEMENT@28..67 - 0: JS_BOGUS@28..67 + 1: JS_BOGUS_STATEMENT@28..69 + 0: JS_BOGUS@28..69 0: LET_KW@28..33 "let" [Newline("\n")] [Whitespace(" ")] - 1: JS_BOGUS@33..67 - 0: JS_BOGUS@33..67 + 1: JS_BOGUS@33..69 + 0: JS_BOGUS@33..69 0: JS_IDENTIFIER_BINDING@33..35 0: IDENT@33..35 "b" [] [Whitespace(" ")] - 1: JS_BOGUS@35..67 + 1: JS_BOGUS@35..69 0: EQ@35..37 "=" [] [Whitespace(" ")] 1: JS_BOGUS_EXPRESSION@37..52 0: JS_DECORATOR@37..44 @@ -242,69 +246,74 @@ JsModule { 1: JS_IDENTIFIER_EXPRESSION@45..52 0: JS_REFERENCE_IDENTIFIER@45..52 0: IDENT@45..52 "second" [] [Whitespace(" ")] - 2: JS_FUNCTION_EXPRESSION@52..67 + 2: JS_FUNCTION_EXPRESSION@52..69 0: (empty) 1: FUNCTION_KW@52..61 "function" [] [Whitespace(" ")] 2: (empty) - 3: JS_IDENTIFIER_BINDING@61..65 - 0: IDENT@61..65 "foo" [] [Whitespace(" ")] + 3: JS_IDENTIFIER_BINDING@61..64 + 0: IDENT@61..64 "foo" [] [] 4: (empty) - 5: (empty) + 5: JS_PARAMETERS@64..67 + 0: L_PAREN@64..65 "(" [] [] + 1: JS_PARAMETER_LIST@65..65 + 2: R_PAREN@65..67 ")" [] [Whitespace(" ")] 6: (empty) - 7: JS_FUNCTION_BODY@65..67 - 0: L_CURLY@65..66 "{" [] [] - 1: JS_DIRECTIVE_LIST@66..66 - 2: JS_STATEMENT_LIST@66..66 - 3: R_CURLY@66..67 "}" [] [] - 2: JS_VARIABLE_STATEMENT@67..99 - 0: JS_VARIABLE_DECLARATION@67..99 - 0: LET_KW@67..72 "let" [Newline("\n")] [Whitespace(" ")] - 1: JS_VARIABLE_DECLARATOR_LIST@72..99 - 0: JS_VARIABLE_DECLARATOR@72..99 - 0: JS_IDENTIFIER_BINDING@72..74 - 0: IDENT@72..74 "a" [] [Whitespace(" ")] + 7: JS_FUNCTION_BODY@67..69 + 0: L_CURLY@67..68 "{" [] [] + 1: JS_DIRECTIVE_LIST@68..68 + 2: JS_STATEMENT_LIST@68..68 + 3: R_CURLY@68..69 "}" [] [] + 2: JS_VARIABLE_STATEMENT@69..101 + 0: JS_VARIABLE_DECLARATION@69..101 + 0: LET_KW@69..74 "let" [Newline("\n")] [Whitespace(" ")] + 1: JS_VARIABLE_DECLARATOR_LIST@74..101 + 0: JS_VARIABLE_DECLARATOR@74..101 + 0: JS_IDENTIFIER_BINDING@74..76 + 0: IDENT@74..76 "a" [] [Whitespace(" ")] 1: (empty) - 2: JS_INITIALIZER_CLAUSE@74..99 - 0: EQ@74..76 "=" [] [Whitespace(" ")] - 1: JS_BOGUS_EXPRESSION@76..99 - 0: JS_DECORATOR@76..99 - 0: AT@76..77 "@" [] [] - 1: JS_CALL_EXPRESSION@77..99 - 0: JS_IDENTIFIER_EXPRESSION@77..87 - 0: JS_REFERENCE_IDENTIFIER@77..87 - 0: IDENT@77..87 "decorator" [] [Whitespace(" ")] + 2: JS_INITIALIZER_CLAUSE@76..101 + 0: EQ@76..78 "=" [] [Whitespace(" ")] + 1: JS_BOGUS_EXPRESSION@78..101 + 0: JS_DECORATOR@78..101 + 0: AT@78..79 "@" [] [] + 1: JS_CALL_EXPRESSION@79..101 + 0: JS_IDENTIFIER_EXPRESSION@79..89 + 0: JS_REFERENCE_IDENTIFIER@79..89 + 0: IDENT@79..89 "decorator" [] [Whitespace(" ")] 1: (empty) 2: (empty) - 3: JS_CALL_ARGUMENTS@87..99 - 0: L_PAREN@87..89 "(" [] [Whitespace(" ")] - 1: JS_CALL_ARGUMENT_LIST@89..98 - 0: JS_ARROW_FUNCTION_EXPRESSION@89..98 + 3: JS_CALL_ARGUMENTS@89..101 + 0: L_PAREN@89..91 "(" [] [Whitespace(" ")] + 1: JS_CALL_ARGUMENT_LIST@91..100 + 0: JS_ARROW_FUNCTION_EXPRESSION@91..100 0: (empty) 1: (empty) - 2: JS_PARAMETERS@89..92 - 0: L_PAREN@89..90 "(" [] [] - 1: JS_PARAMETER_LIST@90..90 - 2: R_PAREN@90..92 ")" [] [Whitespace(" ")] + 2: JS_PARAMETERS@91..94 + 0: L_PAREN@91..92 "(" [] [] + 1: JS_PARAMETER_LIST@92..92 + 2: R_PAREN@92..94 ")" [] [Whitespace(" ")] 3: (empty) - 4: FAT_ARROW@92..95 "=>" [] [Whitespace(" ")] - 5: JS_FUNCTION_BODY@95..98 - 0: L_CURLY@95..96 "{" [] [] - 1: JS_DIRECTIVE_LIST@96..96 - 2: JS_STATEMENT_LIST@96..96 - 3: R_CURLY@96..98 "}" [] [Whitespace(" ")] - 2: R_PAREN@98..99 ")" [] [] + 4: FAT_ARROW@94..97 "=>" [] [Whitespace(" ")] + 5: JS_FUNCTION_BODY@97..100 + 0: L_CURLY@97..98 "{" [] [] + 1: JS_DIRECTIVE_LIST@98..98 + 2: JS_STATEMENT_LIST@98..98 + 3: R_CURLY@98..100 "}" [] [Whitespace(" ")] + 2: R_PAREN@100..101 ")" [] [] 1: (empty) - 3: EOF@99..100 "" [Newline("\n")] [] + 3: EOF@101..102 "" [Newline("\n")] [] -- decorator_expression_class.js:1:9 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - × Decorators are not valid here. + × Decorators are not valid here > 1 │ let a = @decorator () => {}; │ ^^^^^^^^^^^^^ - 2 │ let b = @first @second function foo {} + 2 │ let b = @first @second function foo() {} 3 │ let a = @decorator ( () => {} ) + i Decorators are only valid on class declarations, class expressions, and class methods + -- decorator_expression_class.js:1:23 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ @@ -312,75 +321,60 @@ decorator_expression_class.js:1:23 parse ━━━━━━━━━━━━━ > 1 │ let a = @decorator () => {}; │ ^^ - 2 │ let b = @first @second function foo {} + 2 │ let b = @first @second function foo() {} 3 │ let a = @decorator ( () => {} ) i Expected a parenthesis '(' here > 1 │ let a = @decorator () => {}; │ ^^ - 2 │ let b = @first @second function foo {} + 2 │ let b = @first @second function foo() {} 3 │ let a = @decorator ( () => {} ) -- decorator_expression_class.js:2:9 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - × Decorators are not valid here. + × Decorators are not valid here 1 │ let a = @decorator () => {}; - > 2 │ let b = @first @second function foo {} + > 2 │ let b = @first @second function foo() {} │ ^^^^^^^^^^^^^^ 3 │ let a = @decorator ( () => {} ) 4 │ --- -decorator_expression_class.js:2:37 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - - × expected a parenthesis '(' but instead found '{' - - 1 │ let a = @decorator () => {}; - > 2 │ let b = @first @second function foo {} - │ ^ - 3 │ let a = @decorator ( () => {} ) - 4 │ - - i Expected a parenthesis '(' here - - 1 │ let a = @decorator () => {}; - > 2 │ let b = @first @second function foo {} - │ ^ - 3 │ let a = @decorator ( () => {} ) - 4 │ + i Decorators are only valid on class declarations, class expressions, and class methods -- decorator_expression_class.js:3:9 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - × Decorators are not valid here. + × Decorators are not valid here 1 │ let a = @decorator () => {}; - 2 │ let b = @first @second function foo {} + 2 │ let b = @first @second function foo() {} > 3 │ let a = @decorator ( () => {} ) │ ^^^^^^^^^^^^^^^^^^^^^^^ 4 │ + i Decorators are only valid on class declarations, class expressions, and class methods + -- decorator_expression_class.js:4:1 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × expected an expression, or an assignment but instead found the end of the file - 2 │ let b = @first @second function foo {} + 2 │ let b = @first @second function foo() {} 3 │ let a = @decorator ( () => {} ) > 4 │ │ i Expected an expression, or an assignment here - 2 │ let b = @first @second function foo {} + 2 │ let b = @first @second function foo() {} 3 │ let a = @decorator ( () => {} ) > 4 │ │ -- let a = @decorator () => {}; -let b = @first @second function foo {} +let b = @first @second function foo() {} let a = @decorator ( () => {} ) diff --git a/crates/rome_js_parser/test_data/inline/err/decorator_function_export_default_declaration_clause.rast b/crates/rome_js_parser/test_data/inline/err/decorator_function_export_default_declaration_clause.rast index 3b482c13ea9..71e9a24f6d7 100644 --- a/crates/rome_js_parser/test_data/inline/err/decorator_function_export_default_declaration_clause.rast +++ b/crates/rome_js_parser/test_data/inline/err/decorator_function_export_default_declaration_clause.rast @@ -24,83 +24,75 @@ JsModule { function_token: FUNCTION_KW@26..35 "function" [] [Whitespace(" ")], star_token: missing (optional), id: JsIdentifierBinding { - name_token: IDENT@35..39 "foo" [] [Whitespace(" ")], + name_token: IDENT@35..38 "foo" [] [], }, type_parameters: missing (optional), - parameters: missing (required), + parameters: JsParameters { + l_paren_token: L_PAREN@38..39 "(" [] [], + items: JsParameterList [], + r_paren_token: R_PAREN@39..41 ")" [] [Whitespace(" ")], + }, return_type_annotation: missing (optional), body: JsFunctionBody { - l_curly_token: L_CURLY@39..41 "{" [] [Whitespace(" ")], + l_curly_token: L_CURLY@41..43 "{" [] [Whitespace(" ")], directives: JsDirectiveList [], statements: JsStatementList [], - r_curly_token: R_CURLY@41..42 "}" [] [], + r_curly_token: R_CURLY@43..44 "}" [] [], }, }, semicolon_token: missing (optional), }, }, ], - eof_token: EOF@42..43 "" [Newline("\n")] [], + eof_token: EOF@44..45 "" [Newline("\n")] [], } -0: JS_MODULE@0..43 +0: JS_MODULE@0..45 0: (empty) 1: JS_DIRECTIVE_LIST@0..0 - 2: JS_MODULE_ITEM_LIST@0..42 + 2: JS_MODULE_ITEM_LIST@0..44 0: JS_BOGUS_STATEMENT@0..10 0: JS_DECORATOR@0..10 0: AT@0..1 "@" [] [] 1: JS_IDENTIFIER_EXPRESSION@1..10 0: JS_REFERENCE_IDENTIFIER@1..10 0: IDENT@1..10 "decorator" [] [] - 1: JS_EXPORT@10..42 + 1: JS_EXPORT@10..44 0: JS_DECORATOR_LIST@10..10 1: EXPORT_KW@10..18 "export" [Newline("\n")] [Whitespace(" ")] - 2: JS_EXPORT_DEFAULT_DECLARATION_CLAUSE@18..42 + 2: JS_EXPORT_DEFAULT_DECLARATION_CLAUSE@18..44 0: DEFAULT_KW@18..26 "default" [] [Whitespace(" ")] - 1: JS_FUNCTION_EXPORT_DEFAULT_DECLARATION@26..42 + 1: JS_FUNCTION_EXPORT_DEFAULT_DECLARATION@26..44 0: (empty) 1: FUNCTION_KW@26..35 "function" [] [Whitespace(" ")] 2: (empty) - 3: JS_IDENTIFIER_BINDING@35..39 - 0: IDENT@35..39 "foo" [] [Whitespace(" ")] + 3: JS_IDENTIFIER_BINDING@35..38 + 0: IDENT@35..38 "foo" [] [] 4: (empty) - 5: (empty) + 5: JS_PARAMETERS@38..41 + 0: L_PAREN@38..39 "(" [] [] + 1: JS_PARAMETER_LIST@39..39 + 2: R_PAREN@39..41 ")" [] [Whitespace(" ")] 6: (empty) - 7: JS_FUNCTION_BODY@39..42 - 0: L_CURLY@39..41 "{" [] [Whitespace(" ")] - 1: JS_DIRECTIVE_LIST@41..41 - 2: JS_STATEMENT_LIST@41..41 - 3: R_CURLY@41..42 "}" [] [] + 7: JS_FUNCTION_BODY@41..44 + 0: L_CURLY@41..43 "{" [] [Whitespace(" ")] + 1: JS_DIRECTIVE_LIST@43..43 + 2: JS_STATEMENT_LIST@43..43 + 3: R_CURLY@43..44 "}" [] [] 2: (empty) - 3: EOF@42..43 "" [Newline("\n")] [] + 3: EOF@44..45 "" [Newline("\n")] [] -- decorator_function_export_default_declaration_clause.ts:1:1 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - × Decorators are not valid here. + × Decorators are not valid here > 1 │ @decorator │ ^^^^^^^^^^ - 2 │ export default function foo { } - 3 │ - --- -decorator_function_export_default_declaration_clause.ts:2:29 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - - × expected a parenthesis '(' but instead found '{' - - 1 │ @decorator - > 2 │ export default function foo { } - │ ^ + 2 │ export default function foo() { } 3 │ - i Expected a parenthesis '(' here - - 1 │ @decorator - > 2 │ export default function foo { } - │ ^ - 3 │ + i Decorators are only valid on class declarations, class expressions, and class methods -- @decorator -export default function foo { } +export default function foo() { } diff --git a/crates/rome_js_parser/test_data/inline/err/decorator_function_export_default_declaration_clause.ts b/crates/rome_js_parser/test_data/inline/err/decorator_function_export_default_declaration_clause.ts index 5a2e24fa694..a5e37b52d8b 100644 --- a/crates/rome_js_parser/test_data/inline/err/decorator_function_export_default_declaration_clause.ts +++ b/crates/rome_js_parser/test_data/inline/err/decorator_function_export_default_declaration_clause.ts @@ -1,2 +1,2 @@ @decorator -export default function foo { } +export default function foo() { } diff --git a/crates/rome_js_parser/test_data/inline/err/decorator_interface_export_default_declaration_clause.rast b/crates/rome_js_parser/test_data/inline/err/decorator_interface_export_default_declaration_clause.rast index 04b4cecf32c..e8523e900be 100644 --- a/crates/rome_js_parser/test_data/inline/err/decorator_interface_export_default_declaration_clause.rast +++ b/crates/rome_js_parser/test_data/inline/err/decorator_interface_export_default_declaration_clause.rast @@ -66,13 +66,15 @@ JsModule { -- decorator_interface_export_default_declaration_clause.ts:1:1 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - × Decorators are not valid here. + × Decorators are not valid here > 1 │ @decorator │ ^^^^^^^^^^ 2 │ export default interface A { } 3 │ + i Decorators are only valid on class declarations, class expressions, and class methods + -- @decorator export default interface A { } diff --git a/crates/rome_js_parser/test_data/inline/err/ts_declare_const_initializer.rast b/crates/rome_js_parser/test_data/inline/err/ts_declare_const_initializer.rast index f3661725601..0a3398a7ade 100644 --- a/crates/rome_js_parser/test_data/inline/err/ts_declare_const_initializer.rast +++ b/crates/rome_js_parser/test_data/inline/err/ts_declare_const_initializer.rast @@ -116,23 +116,27 @@ JsModule { -- ts_declare_const_initializer.ts:1:9 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - × Decorators are not valid here. + × Decorators are not valid here > 1 │ declare @decorator class D {} │ ^^^^^^^^^^ 2 │ declare @decorator abstract class D {} 3 │ + i Decorators are only valid on class declarations, class expressions, and class methods + -- ts_declare_const_initializer.ts:2:9 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - × Decorators are not valid here. + × Decorators are not valid here 1 │ declare @decorator class D {} > 2 │ declare @decorator abstract class D {} │ ^^^^^^^^^^ 3 │ + i Decorators are only valid on class declarations, class expressions, and class methods + -- declare @decorator class D {} declare @decorator abstract class D {} diff --git a/crates/rome_js_parser/test_data/inline/err/ts_export_declare.rast b/crates/rome_js_parser/test_data/inline/err/ts_export_declare.rast index b407b9d6668..cdbd442315d 100644 --- a/crates/rome_js_parser/test_data/inline/err/ts_export_declare.rast +++ b/crates/rome_js_parser/test_data/inline/err/ts_export_declare.rast @@ -134,23 +134,27 @@ JsModule { -- ts_export_declare.ts:1:16 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - × Decorators are not valid here. + × Decorators are not valid here > 1 │ export declare @decorator class D {} │ ^^^^^^^^^^ 2 │ export declare @decorator abstract class D {} 3 │ + i Decorators are only valid on class declarations, class expressions, and class methods + -- ts_export_declare.ts:2:16 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - × Decorators are not valid here. + × Decorators are not valid here 1 │ export declare @decorator class D {} > 2 │ export declare @decorator abstract class D {} │ ^^^^^^^^^^ 3 │ + i Decorators are only valid on class declarations, class expressions, and class methods + -- export declare @decorator class D {} export declare @decorator abstract class D {} diff --git a/crates/rome_js_parser/test_data/inline/ok/ts_class_decorator.rast b/crates/rome_js_parser/test_data/inline/ok/ts_class_decorator.rast deleted file mode 100644 index 57fb87f85e7..00000000000 --- a/crates/rome_js_parser/test_data/inline/ok/ts_class_decorator.rast +++ /dev/null @@ -1,177 +0,0 @@ -JsModule { - interpreter_token: missing (optional), - directives: JsDirectiveList [], - items: JsModuleItemList [ - JsFunctionDeclaration { - async_token: missing (optional), - function_token: FUNCTION_KW@0..9 "function" [] [Whitespace(" ")], - star_token: missing (optional), - id: JsIdentifierBinding { - name_token: IDENT@9..13 "test" [] [], - }, - type_parameters: missing (optional), - parameters: JsParameters { - l_paren_token: L_PAREN@13..14 "(" [] [], - items: JsParameterList [], - r_paren_token: R_PAREN@14..16 ")" [] [Whitespace(" ")], - }, - return_type_annotation: missing (optional), - body: JsFunctionBody { - l_curly_token: L_CURLY@16..17 "{" [] [], - directives: JsDirectiveList [], - statements: JsStatementList [], - r_curly_token: R_CURLY@17..18 "}" [] [], - }, - }, - JsClassDeclaration { - decorators: JsDecoratorList [ - JsDecorator { - at_token: AT@18..20 "@" [Newline("\n")] [], - expression: JsIdentifierExpression { - name: JsReferenceIdentifier { - value_token: IDENT@20..24 "test" [] [], - }, - }, - }, - ], - abstract_token: missing (optional), - class_token: CLASS_KW@24..31 "class" [Newline("\n")] [Whitespace(" ")], - id: JsIdentifierBinding { - name_token: IDENT@31..36 "Test" [] [Whitespace(" ")], - }, - type_parameters: missing (optional), - extends_clause: missing (optional), - implements_clause: missing (optional), - l_curly_token: L_CURLY@36..37 "{" [] [], - members: JsClassMemberList [], - r_curly_token: R_CURLY@37..38 "}" [] [], - }, - JsClassDeclaration { - decorators: JsDecoratorList [ - JsDecorator { - at_token: AT@38..40 "@" [Newline("\n")] [], - expression: JsStaticMemberExpression { - object: JsStaticMemberExpression { - object: JsIdentifierExpression { - name: JsReferenceIdentifier { - value_token: IDENT@40..44 "test" [] [], - }, - }, - operator_token: DOT@44..45 "." [] [], - member: JsName { - value_token: IDENT@45..46 "a" [] [], - }, - }, - operator_token: QUESTIONDOT@46..48 "?." [] [], - member: JsName { - value_token: IDENT@48..50 "c" [] [Whitespace(" ")], - }, - }, - }, - JsDecorator { - at_token: AT@50..51 "@" [] [], - expression: JsIdentifierExpression { - name: JsReferenceIdentifier { - value_token: IDENT@51..56 "test" [] [Whitespace(" ")], - }, - }, - }, - JsDecorator { - at_token: AT@56..57 "@" [] [], - expression: JsIdentifierExpression { - name: JsReferenceIdentifier { - value_token: IDENT@57..61 "test" [] [], - }, - }, - }, - ], - abstract_token: missing (optional), - class_token: CLASS_KW@61..68 "class" [Newline("\n")] [Whitespace(" ")], - id: JsIdentifierBinding { - name_token: IDENT@68..73 "Test2" [] [], - }, - type_parameters: missing (optional), - extends_clause: missing (optional), - implements_clause: missing (optional), - l_curly_token: L_CURLY@73..74 "{" [] [], - members: JsClassMemberList [], - r_curly_token: R_CURLY@74..75 "}" [] [], - }, - ], - eof_token: EOF@75..76 "" [Newline("\n")] [], -} - -0: JS_MODULE@0..76 - 0: (empty) - 1: JS_DIRECTIVE_LIST@0..0 - 2: JS_MODULE_ITEM_LIST@0..75 - 0: JS_FUNCTION_DECLARATION@0..18 - 0: (empty) - 1: FUNCTION_KW@0..9 "function" [] [Whitespace(" ")] - 2: (empty) - 3: JS_IDENTIFIER_BINDING@9..13 - 0: IDENT@9..13 "test" [] [] - 4: (empty) - 5: JS_PARAMETERS@13..16 - 0: L_PAREN@13..14 "(" [] [] - 1: JS_PARAMETER_LIST@14..14 - 2: R_PAREN@14..16 ")" [] [Whitespace(" ")] - 6: (empty) - 7: JS_FUNCTION_BODY@16..18 - 0: L_CURLY@16..17 "{" [] [] - 1: JS_DIRECTIVE_LIST@17..17 - 2: JS_STATEMENT_LIST@17..17 - 3: R_CURLY@17..18 "}" [] [] - 1: JS_CLASS_DECLARATION@18..38 - 0: JS_DECORATOR_LIST@18..24 - 0: JS_DECORATOR@18..24 - 0: AT@18..20 "@" [Newline("\n")] [] - 1: JS_IDENTIFIER_EXPRESSION@20..24 - 0: JS_REFERENCE_IDENTIFIER@20..24 - 0: IDENT@20..24 "test" [] [] - 1: (empty) - 2: CLASS_KW@24..31 "class" [Newline("\n")] [Whitespace(" ")] - 3: JS_IDENTIFIER_BINDING@31..36 - 0: IDENT@31..36 "Test" [] [Whitespace(" ")] - 4: (empty) - 5: (empty) - 6: (empty) - 7: L_CURLY@36..37 "{" [] [] - 8: JS_CLASS_MEMBER_LIST@37..37 - 9: R_CURLY@37..38 "}" [] [] - 2: JS_CLASS_DECLARATION@38..75 - 0: JS_DECORATOR_LIST@38..61 - 0: JS_DECORATOR@38..50 - 0: AT@38..40 "@" [Newline("\n")] [] - 1: JS_STATIC_MEMBER_EXPRESSION@40..50 - 0: JS_STATIC_MEMBER_EXPRESSION@40..46 - 0: JS_IDENTIFIER_EXPRESSION@40..44 - 0: JS_REFERENCE_IDENTIFIER@40..44 - 0: IDENT@40..44 "test" [] [] - 1: DOT@44..45 "." [] [] - 2: JS_NAME@45..46 - 0: IDENT@45..46 "a" [] [] - 1: QUESTIONDOT@46..48 "?." [] [] - 2: JS_NAME@48..50 - 0: IDENT@48..50 "c" [] [Whitespace(" ")] - 1: JS_DECORATOR@50..56 - 0: AT@50..51 "@" [] [] - 1: JS_IDENTIFIER_EXPRESSION@51..56 - 0: JS_REFERENCE_IDENTIFIER@51..56 - 0: IDENT@51..56 "test" [] [Whitespace(" ")] - 2: JS_DECORATOR@56..61 - 0: AT@56..57 "@" [] [] - 1: JS_IDENTIFIER_EXPRESSION@57..61 - 0: JS_REFERENCE_IDENTIFIER@57..61 - 0: IDENT@57..61 "test" [] [] - 1: (empty) - 2: CLASS_KW@61..68 "class" [Newline("\n")] [Whitespace(" ")] - 3: JS_IDENTIFIER_BINDING@68..73 - 0: IDENT@68..73 "Test2" [] [] - 4: (empty) - 5: (empty) - 6: (empty) - 7: L_CURLY@73..74 "{" [] [] - 8: JS_CLASS_MEMBER_LIST@74..74 - 9: R_CURLY@74..75 "}" [] [] - 3: EOF@75..76 "" [Newline("\n")] [] diff --git a/crates/rome_js_parser/test_data/inline/ok/ts_class_decorator.ts b/crates/rome_js_parser/test_data/inline/ok/ts_class_decorator.ts deleted file mode 100644 index 065a262049e..00000000000 --- a/crates/rome_js_parser/test_data/inline/ok/ts_class_decorator.ts +++ /dev/null @@ -1,5 +0,0 @@ -function test() {} -@test -class Test {} -@test.a?.c @test @test -class Test2{}