fix(rome_js_analyze): add missing control flow root nodes
MODIFY
crates/rome_js_analyze/src/control_flow/visitor.rs
crates/rome_js_analyze/src/control_flow/visitor.rs
use std::{any::TypeId, ops::ControlFlow};
use rome_analyze::{merge_node_visitors, QueryMatch, Visitor, VisitorContext};
-use rome_js_syntax::{JsAnyFunction, JsLanguage, JsModule, JsScript};
+use rome_js_syntax::{
+ JsAnyFunction, JsConstructorClassMember, JsGetterClassMember, JsGetterObjectMember, JsLanguage,
+ JsMethodClassMember, JsMethodObjectMember, JsModule, JsScript, JsSetterClassMember,
+ JsSetterObjectMember,
+};
use rome_rowan::{declare_node_union, AstNode, SyntaxError, SyntaxResult};
use super::{nodes::*, FunctionBuilder};
@@ -131,7 +135,16 @@ pub(super) struct FunctionVisitor {
}
declare_node_union! {
- JsAnyControlFlowRoot = JsModule | JsScript | JsAnyFunction
+ JsAnyControlFlowRoot = JsModule
+ | JsScript
+ | JsAnyFunction
+ | JsGetterObjectMember
+ | JsSetterObjectMember
+ | JsMethodObjectMember
+ | JsConstructorClassMember
+ | JsMethodClassMember
+ | JsGetterClassMember
+ | JsSetterClassMember
}
impl<B> rome_analyze::NodeVisitor<ControlFlowVisitor<B>, B> for FunctionVisitor {

ADD
crates/rome_js_analyze/tests/specs/noDeadCode/NestedFunctions.js
+const JsFunctionExpression = function () {
+ return;
+}
+
+function JsFunctionDeclaration() {
+ return;
+}
+
+const JsArrowFunctionExpression = function () {
+ return;
+}
+
+export default function JsFunctionExportDefaultDeclaration() {
+ return;
+}
+
+const object = {
+ get JsGetterObjectMember() {
+ return;
+ },
+
+ set JsSetterObjectMember(value) {
+ return;
+ },
+
+ JsMethodObjectMember() {
+ return;
+ },
+};
+
+class Class {
+ // JsConstructorClassMember
+ constructor() {
+ return;
+ }
+
+ JsMethodClassMember() {
+ return;
+ }
+
+ get JsGetterClassMember() {
+ return;
+ }
+
+ set JsSetterClassMember(value) {
+ return;
+ }
+}
+
+statement();

ADD
crates/rome_js_analyze/tests/specs/noDeadCode/NestedFunctions.js.snap
+---
+source: crates/rome_js_analyze/tests/spec_tests.rs
+expression: NestedFunctions.js
+---
+# Input
+```js
+const JsFunctionExpression = function () {
+ return;
+}
+
+function JsFunctionDeclaration() {
+ return;
+}
+
+const JsArrowFunctionExpression = function () {
+ return;
+}
+
+export default function JsFunctionExportDefaultDeclaration() {
+ return;
+}
+
+const object = {
+ get JsGetterObjectMember() {
+ return;
+ },
+
+ set JsSetterObjectMember(value) {
+ return;
+ },
+
+ JsMethodObjectMember() {
+ return;
+ },
+};
+
+class Class {
+ // JsConstructorClassMember
+ constructor() {
+ return;
+ }
+
+ JsMethodClassMember() {
+ return;
+ }
+
+ get JsGetterClassMember() {
+ return;
+ }
+
+ set JsSetterClassMember(value) {
+ return;
+ }
+}
+
+statement();
+
+```
+
+

fix(rome_js_analyze): add missing control flow root nodes (#2832)