Skip to content

Commit

Permalink
feat(rome_js_parser): EcmaScript @decorators rome#4252
Browse files Browse the repository at this point in the history
export default
  • Loading branch information
denbezrukov committed Apr 18, 2023
1 parent e2ce865 commit 6ac9407
Show file tree
Hide file tree
Showing 81 changed files with 2,377 additions and 570 deletions.
7 changes: 6 additions & 1 deletion crates/rome_js_factory/src/generated/node_factory.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion crates/rome_js_factory/src/generated/syntax_factory.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 10 additions & 1 deletion crates/rome_js_formatter/src/js/module/export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,19 @@ pub(crate) struct FormatJsExport;
impl FormatNodeRule<JsExport> for FormatJsExport {
fn fmt_fields(&self, node: &JsExport, f: &mut JsFormatter) -> FormatResult<()> {
let JsExportFields {
decorators,
export_token,
export_clause,
} = node.as_fields();

write![f, [export_token.format(), space(), export_clause.format()]]
write![
f,
[
decorators.format(),
export_token.format(),
space(),
export_clause.format()
]
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const bar =
@@ -7,18 +7,12 @@
@deco
export default class Baz {}

-const foo =
- (
- @deco
Expand All @@ -45,7 +45,7 @@ const bar =
+class {
+ //
+};

-const bar =
- (
- @deco
Expand Down Expand Up @@ -84,28 +84,17 @@ class {

# Errors
```
classes.js:3:1 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
× Decorators are not valid here.
1 │ @deco class Foo {}
2 │
> 3 │ @deco export class Bar {}
│ ^^^^^
4 │
5 │ @deco export default class Baz {}
classes.js:5:1 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
× Decorators are not valid here.
3 │ @deco export class Bar {}
4 │
4 │
> 5 │ @deco export default class Baz {}
│ ^^^^^
6 │
6 │
7 │ const foo = @deco class {
```

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
---
source: crates/rome_formatter_test/src/snapshot_builder.rs
assertion_line: 212
info: js/decorators/classes.js
---

# Input

```js
@deco class Foo {}

@deco export class Bar {}

@deco export default class Baz {}

const foo = @deco class {
//
};

const bar =
@deco
class {
//
};

```


# Prettier differences

```diff
--- Prettier
+++ Rome
@@ -7,18 +7,12 @@
@deco
export default class Baz {}

-const foo =
- (
- @deco
- class {
- //
- }
- );
+const foo = @deco
+class {
+ //
+};

-const bar =
- (
- @deco
- class {
- //
- }
- );
+const bar = @deco
+class {
+ //
+};
```

# Output

```js
@deco
class Foo {}

@deco
export class Bar {}

@deco
export default class Baz {}

const foo = @deco
class {
//
};

const bar = @deco
class {
//
};
```


Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export class Home extends React.Component {}
@@ -1,5 +1,5 @@
@connect(mapStateToProps, mapDispatchToProps)
export class MyApp extends React.Component {}

-@connect((state) => ({ todos: state.todos }))
+@connect(state => ({ todos: state.todos }))
export class Home extends React.Component {}
Expand All @@ -39,29 +39,4 @@ export class MyApp extends React.Component {}
export class Home extends React.Component {}
```

# Errors
```
redux.js:1:1 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
× Decorators are not valid here.
> 1 │ @connect(mapStateToProps, mapDispatchToProps)
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2 │ export class MyApp extends React.Component {}
3 │
redux.js:4:1 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
× Decorators are not valid here.
2 │ export class MyApp extends React.Component {}
3 │
> 4 │ @connect(state => ({ todos: state.todos }))
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5 │ export class Home extends React.Component {}
6 │
```


Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
---
source: crates/rome_formatter_test/src/snapshot_builder.rs
assertion_line: 212
info: js/decorators/redux.js
---

# Input

```js
@connect(mapStateToProps, mapDispatchToProps)
export class MyApp extends React.Component {}

@connect(state => ({ todos: state.todos }))
export class Home extends React.Component {}

```


# Prettier differences

```diff
--- Prettier
+++ Rome
@@ -1,5 +1,5 @@
@connect(mapStateToProps, mapDispatchToProps)
export class MyApp extends React.Component {}

-@connect((state) => ({ todos: state.todos }))
+@connect(state => ({ todos: state.todos }))
export class Home extends React.Component {}
```

# Output

```js
@connect(mapStateToProps, mapDispatchToProps)
export class MyApp extends React.Component {}

@connect(state => ({ todos: state.todos }))
export class Home extends React.Component {}
```


Original file line number Diff line number Diff line change
Expand Up @@ -47,22 +47,4 @@ export class HeroButtonComponent {
}
```

# Errors
```
angular.ts:1:1 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
× Decorators are not valid here.
> 1 │ @Component({
│ ^^^^^^^^^^^^
> 2 │ selector: 'toh-hero-button',
> 3 │ template: `<button>{{label}}</button>`
> 4 │ })
│ ^^
5 │ export class HeroButtonComponent {
6 │ @Output() change = new EventEmitter<any>();
```


Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export class Board {
@@ -15,6 +15,6 @@
@Column()
description: string;

- @OneToMany((type) => Topic, (topic) => topic.board)
+ @OneToMany(type => Topic, topic => topic.board)
topics: Topic[];
Expand Down Expand Up @@ -72,18 +72,4 @@ export class Board {
}
```

# Errors
```
typeorm.ts:1:1 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
× Decorators are not valid here.
> 1 │ @Entity()
│ ^^^^^^^^^
2 │ export class Board {
3 │
```


Loading

0 comments on commit 6ac9407

Please sign in to comment.