Skip to content
This repository has been archived by the owner on Aug 31, 2023. It is now read-only.

Commit

Permalink
feat(rome_js_parser): EcmaScript @decorators #4252
Browse files Browse the repository at this point in the history
  • Loading branch information
denbezrukov committed Apr 26, 2023
1 parent 22a789e commit 3a132e4
Show file tree
Hide file tree
Showing 15 changed files with 66 additions and 66 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ multiple.js:2:3 parse ━━━━━━━━━━━━━━━━━━━
multiple.js:7:3 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
× Decorators are not valid here
× Decorators are not valid here.
5 │ legs: 4,
6 │
Expand All @@ -115,7 +115,7 @@ multiple.js:7:3 parse ━━━━━━━━━━━━━━━━━━━
10 │ eyes: 2
11 │ };
i Decorators are only valid on class declarations, class expressions, and class methods
i Decorators are only valid on class declarations, class expressions, and class methods.
multiple.js:10:7 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Expand Down
4 changes: 2 additions & 2 deletions crates/rome_js_parser/src/syntax/js_parse_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ pub(crate) fn invalid_decorator_error(p: &JsParser, range: TextRange) -> ParseDi
}

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",
p.err_builder("Decorators are not valid here.", range).hint(
"Decorators are only valid on class declarations, class expressions, and class methods.",
)
}
4 changes: 2 additions & 2 deletions crates/rome_js_parser/src/syntax/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ pub(crate) fn parse_import_or_import_equals_declaration(p: &mut JsParser) -> Par

let start = p.cur_range().start();
let import = p.start();
p.expect(T![import]);
p.bump(T![import]);

debug_assert!(p.state().name_map.is_empty());
p.state_mut().duplicate_binding_parent = Some("import");
Expand Down Expand Up @@ -1182,7 +1182,7 @@ fn parse_export_default_clause(p: &mut JsParser) -> ParsedSyntax {

let start = p.cur_range().start();
let m = p.start();
p.expect(T![default]);
p.bump(T![default]);

let (clause, default_item_kind) = match p.cur() {
T![@] => {
Expand Down
48 changes: 24 additions & 24 deletions crates/rome_js_parser/test_data/inline/err/decorator.rast
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}
Expand All @@ -1162,7 +1162,7 @@ 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
i Decorators are only valid on class declarations, class expressions, and class methods.

--
decorator.ts:3:4 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Expand Down Expand Up @@ -1223,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 {}
Expand All @@ -1232,7 +1232,7 @@ decorator.ts:4:1 parse ━━━━━━━━━━━━━━━━━━━
5 │ @[] class MyClass {}
6 │ @() => {} class MyClass {}

i Decorators are only valid on class declarations, class expressions, and class methods
i Decorators are only valid on class declarations, class expressions, and class methods.

--
decorator.ts:4:5 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Expand Down Expand Up @@ -1284,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 {}
Expand All @@ -1293,7 +1293,7 @@ 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
i Decorators are only valid on class declarations, class expressions, and class methods.

--
decorator.ts:6:5 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Expand Down Expand Up @@ -1331,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 {}
Expand All @@ -1340,7 +1340,7 @@ 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
i Decorators are only valid on class declarations, class expressions, and class methods.

--
decorator.ts:7:4 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Expand Down Expand Up @@ -1378,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 {}
Expand All @@ -1387,7 +1387,7 @@ 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
i Decorators are only valid on class declarations, class expressions, and class methods.

--
decorator.ts:8:11 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Expand Down Expand Up @@ -1434,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 {}
Expand All @@ -1443,7 +1443,7 @@ 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
i Decorators are only valid on class declarations, class expressions, and class methods.

--
decorator.ts:10:6 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Expand Down Expand Up @@ -1481,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 {}
Expand All @@ -1490,7 +1490,7 @@ 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
i Decorators are only valid on class declarations, class expressions, and class methods.

--
decorator.ts:11:4 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Expand Down Expand Up @@ -1540,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 {}
Expand All @@ -1549,7 +1549,7 @@ 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
i Decorators are only valid on class declarations, class expressions, and class methods.

--
decorator.ts:14:6 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Expand All @@ -1568,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 {}
Expand All @@ -1577,7 +1577,7 @@ 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
i Decorators are only valid on class declarations, class expressions, and class methods.

--
decorator.ts:15:3 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Expand Down Expand Up @@ -1615,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 {}
Expand All @@ -1624,7 +1624,7 @@ decorator.ts:17:1 parse ━━━━━━━━━━━━━━━━━━
18 │ @<MyType>obj class MyClass {}
19 │ @obj satisfies MyType class MyClass {}

i Decorators are only valid on class declarations, class expressions, and class methods
i Decorators are only valid on class declarations, class expressions, and class methods.

--
decorator.ts:17:9 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Expand Down Expand Up @@ -1710,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 {}
Expand All @@ -1719,7 +1719,7 @@ 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
i Decorators are only valid on class declarations, class expressions, and class methods.

--
decorator.ts:18:14 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Expand Down Expand Up @@ -1754,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 │ @<MyType>obj class MyClass {}
Expand All @@ -1763,7 +1763,7 @@ decorator.ts:19:1 parse ━━━━━━━━━━━━━━━━━━
20 │ @obj! class MyClass {}
21 │

i Decorators are only valid on class declarations, class expressions, and class methods
i Decorators are only valid on class declarations, class expressions, and class methods.

--
decorator.ts:19:16 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,14 @@ JsModule {
--
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 │

i Decorators are only valid on class declarations, class expressions, and class methods
i Decorators are only valid on class declarations, class expressions, and class methods.

--
@decorator
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,20 +165,20 @@ JsModule {
--
decorator_class_declaration.js:2:6 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

× Decorators are not valid here
× Decorators are not valid here.

1 │ function bar() {
> 2 │ @decorator
│ ^^^^^^^^^^
3 │ let a;
4 │ @decorator @decorator2

i Decorators are only valid on class declarations, class expressions, and class methods
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;
Expand All @@ -187,7 +187,7 @@ decorator_class_declaration.js:4:6 parse ━━━━━━━━━━━━━
5 │ function Foo() { }
6 │ }

i Decorators are only valid on class declarations, class expressions, and class methods
i Decorators are only valid on class declarations, class expressions, and class methods.

--
function bar() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,19 +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
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;
Expand All @@ -147,7 +147,7 @@ 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
i Decorators are only valid on class declarations, class expressions, and class methods.

--
@decorator
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,14 @@ 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
i Decorators are only valid on class declarations, class expressions, and class methods.

--
decorator_enum_export_default_declaration_clause.ts:2:16 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Expand Down
Loading

0 comments on commit 3a132e4

Please sign in to comment.