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

Commit

Permalink
fix(rome_js_semantic): do not hoist classes and TS declarations
Browse files Browse the repository at this point in the history
  • Loading branch information
Conaclos committed Jul 28, 2023
1 parent 8d511f7 commit f5220d8
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,29 @@ invalid.ts:9:11 lint/nursery/noUnsafeDeclarationMerging ━━━━━━━━
```

```
invalid.ts:14:11 lint/nursery/noUnsafeDeclarationMerging ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
! This class is unsafely merged with an interface.
12 │ {
13 │ interface Foo4 {}
> 14 │ class Foo4 {}
│ ^^^^
15 │ }
16 │
i The interface is declared here.
12 │ {
> 13 │ interface Foo4 {}
│ ^^^^
14 │ class Foo4 {}
15 │ }
i The TypeScript compiler doesn't check whether properties defined in the interface are initialized in the class.
```


32 changes: 9 additions & 23 deletions crates/rome_js_semantic/src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -398,9 +398,15 @@ impl SemanticEventExtractor {
self.push_binding_into_scope(None, &name_token, &parent_kind);
self.export_function_expression(node, &parent);
}
JS_CLASS_DECLARATION | JS_CLASS_EXPORT_DEFAULT_DECLARATION => {
let hoisted_scope_id = self.scope_index_to_hoist_declarations(1);
self.push_binding_into_scope(hoisted_scope_id, &name_token, &parent_kind);
JS_CLASS_DECLARATION
| JS_CLASS_EXPORT_DEFAULT_DECLARATION
| TS_ENUM_DECLARATION
| TS_INTERFACE_DECLARATION
| TS_MODULE_DECLARATION
| TS_TYPE_ALIAS_DECLARATION => {
let parent_scope = self.scopes.get(self.scopes.len() - 2);
let parent_scope = parent_scope.map(|scope| scope.scope_id);
self.push_binding_into_scope(parent_scope, &name_token, &parent_kind);
self.export_declaration(node, &parent);
}
JS_CLASS_EXPRESSION => {
Expand Down Expand Up @@ -437,26 +443,6 @@ impl SemanticEventExtractor {
self.export_variable_declarator(node, &possible_declarator);
}
}
TS_TYPE_ALIAS_DECLARATION => {
let hoisted_scope_id = self.scope_index_to_hoist_declarations(1);
self.push_binding_into_scope(hoisted_scope_id, &name_token, &parent_kind);
self.export_declaration(node, &parent);
}
TS_ENUM_DECLARATION => {
let hoisted_scope_id = self.scope_index_to_hoist_declarations(1);
self.push_binding_into_scope(hoisted_scope_id, &name_token, &parent_kind);
self.export_declaration(node, &parent);
}
TS_INTERFACE_DECLARATION => {
let hoisted_scope_id = self.scope_index_to_hoist_declarations(1);
self.push_binding_into_scope(hoisted_scope_id, &name_token, &parent_kind);
self.export_declaration(node, &parent);
}
TS_MODULE_DECLARATION => {
let hoisted_scope_id = self.scope_index_to_hoist_declarations(1);
self.push_binding_into_scope(hoisted_scope_id, &name_token, &parent_kind);
self.export_declaration(node, &parent);
}
_ => {
self.push_binding_into_scope(None, &name_token, &parent_kind);
}
Expand Down

0 comments on commit f5220d8

Please sign in to comment.