From 27f0531aac314d08d9bf549bcce01711666656fd Mon Sep 17 00:00:00 2001 From: Dunqing <29533304+Dunqing@users.noreply.github.com> Date: Wed, 26 Jun 2024 07:21:38 +0000 Subject: [PATCH] fix(isolated-declarations): private constructor reaching unreachable (#3921) fix: #3917 --- crates/oxc_isolated_declarations/src/class.rs | 5 +---- .../tests/fixtures/class.ts | 7 +++++++ .../tests/snapshots/class.snap | 12 ++++++++++++ 3 files changed, 20 insertions(+), 4 deletions(-) create mode 100644 crates/oxc_isolated_declarations/tests/fixtures/class.ts create mode 100644 crates/oxc_isolated_declarations/tests/snapshots/class.snap diff --git a/crates/oxc_isolated_declarations/src/class.rs b/crates/oxc_isolated_declarations/src/class.rs index b709f22dd9167..792bbbca7bcce 100644 --- a/crates/oxc_isolated_declarations/src/class.rs +++ b/crates/oxc_isolated_declarations/src/class.rs @@ -202,7 +202,7 @@ impl<'a> IsolatedDeclarations<'a> { self.transform_accessibility(method.accessibility), ) } - MethodDefinitionKind::Get => { + MethodDefinitionKind::Get | MethodDefinitionKind::Constructor => { let params = self.ast.formal_parameters( SPAN, FormalParameterKind::Signature, @@ -221,9 +221,6 @@ impl<'a> IsolatedDeclarations<'a> { ); self.transform_class_method_definition(method, params, None) } - MethodDefinitionKind::Constructor => { - unreachable!() - } } } diff --git a/crates/oxc_isolated_declarations/tests/fixtures/class.ts b/crates/oxc_isolated_declarations/tests/fixtures/class.ts new file mode 100644 index 0000000000000..3ad07e08f34b5 --- /dev/null +++ b/crates/oxc_isolated_declarations/tests/fixtures/class.ts @@ -0,0 +1,7 @@ +export class Foo { + private constructor(a: number = 0) {} +} + +export class Bar { + public constructor(a: number = 0) {} +} \ No newline at end of file diff --git a/crates/oxc_isolated_declarations/tests/snapshots/class.snap b/crates/oxc_isolated_declarations/tests/snapshots/class.snap new file mode 100644 index 0000000000000..ef3bc314585e4 --- /dev/null +++ b/crates/oxc_isolated_declarations/tests/snapshots/class.snap @@ -0,0 +1,12 @@ +--- +source: crates/oxc_isolated_declarations/tests/mod.rs +input_file: crates/oxc_isolated_declarations/tests/fixtures/class.ts +--- +==================== .D.TS ==================== + +export declare class Foo { + private constructor(); +} +export declare class Bar { + constructor(a?: number); +}