diff --git a/crates/rome_js_analyze/tests/specs/nursery/noUnsafeDeclarationMerging/invalid.ts.snap b/crates/rome_js_analyze/tests/specs/nursery/noUnsafeDeclarationMerging/invalid.ts.snap index ea49b405800..d0ca656af37 100644 --- a/crates/rome_js_analyze/tests/specs/nursery/noUnsafeDeclarationMerging/invalid.ts.snap +++ b/crates/rome_js_analyze/tests/specs/nursery/noUnsafeDeclarationMerging/invalid.ts.snap @@ -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. + + +``` + diff --git a/crates/rome_js_semantic/src/events.rs b/crates/rome_js_semantic/src/events.rs index d24f5a8aa08..690dab01357 100644 --- a/crates/rome_js_semantic/src/events.rs +++ b/crates/rome_js_semantic/src/events.rs @@ -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 => { @@ -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); }