From d6cbbe723c79617f85ffdec3a41489364631f230 Mon Sep 17 00:00:00 2001 From: DonIsaac <22823424+DonIsaac@users.noreply.github.com> Date: Mon, 23 Sep 2024 02:44:01 +0000 Subject: [PATCH] test(isolated-declarations): arrow function unions in return signature (#5973) --- .../fixtures/arrow-function-return-type.ts | 4 ++++ .../tests/fixtures/function-signatures.ts | 24 +++++++++++++++++++ .../snapshots/arrow-function-return-type.snap | 1 + .../tests/snapshots/function-signatures.snap | 11 +++++++++ 4 files changed, 40 insertions(+) create mode 100644 crates/oxc_isolated_declarations/tests/fixtures/function-signatures.ts create mode 100644 crates/oxc_isolated_declarations/tests/snapshots/function-signatures.snap diff --git a/crates/oxc_isolated_declarations/tests/fixtures/arrow-function-return-type.ts b/crates/oxc_isolated_declarations/tests/fixtures/arrow-function-return-type.ts index 5367a3ac603ec..513ae87eddd1a 100644 --- a/crates/oxc_isolated_declarations/tests/fixtures/arrow-function-return-type.ts +++ b/crates/oxc_isolated_declarations/tests/fixtures/arrow-function-return-type.ts @@ -9,3 +9,7 @@ const B = () => { return B }; const C = function () {} const D = () => `${''}`; + +const E = (): (() => void) | undefined => { + return () => {}; +} diff --git a/crates/oxc_isolated_declarations/tests/fixtures/function-signatures.ts b/crates/oxc_isolated_declarations/tests/fixtures/function-signatures.ts new file mode 100644 index 0000000000000..17db28e3d402e --- /dev/null +++ b/crates/oxc_isolated_declarations/tests/fixtures/function-signatures.ts @@ -0,0 +1,24 @@ +// All of these are valid function signatures under isolatedDeclarations +export function A(): void { + return; +} + +export function B(): (() => void) | undefined { + return () => {}; +} + +// There should be no declaration for the implementation signature, just the +// two overloads. +export function C(x: string): void +export function C(x: number): void +export function C(x: string | number): void { + return; +} + +// private, not emitted +function D(a, b): void { + return; +} +function E(a: number, b: string) { + return `${a} ${b}`; +} diff --git a/crates/oxc_isolated_declarations/tests/snapshots/arrow-function-return-type.snap b/crates/oxc_isolated_declarations/tests/snapshots/arrow-function-return-type.snap index 4581ca0b4ad9d..520422b6bb735 100644 --- a/crates/oxc_isolated_declarations/tests/snapshots/arrow-function-return-type.snap +++ b/crates/oxc_isolated_declarations/tests/snapshots/arrow-function-return-type.snap @@ -9,6 +9,7 @@ declare function A(): unknown; declare const B: unknown; declare const C: unknown; declare const D: () => string; +declare const E: () => (() => void) | undefined; ==================== Errors ==================== diff --git a/crates/oxc_isolated_declarations/tests/snapshots/function-signatures.snap b/crates/oxc_isolated_declarations/tests/snapshots/function-signatures.snap new file mode 100644 index 0000000000000..c7998e7d279a1 --- /dev/null +++ b/crates/oxc_isolated_declarations/tests/snapshots/function-signatures.snap @@ -0,0 +1,11 @@ +--- +source: crates/oxc_isolated_declarations/tests/mod.rs +input_file: crates/oxc_isolated_declarations/tests/fixtures/function-signatures.ts +--- +``` +==================== .D.TS ==================== + +export declare function A(): void; +export declare function B(): (() => void) | undefined; +export declare function C(x: string): void; +export declare function C(x: number): void;