From 9f69855ff7cc718baec1508063b38e0d3365d4c6 Mon Sep 17 00:00:00 2001 From: Julien TASSIN Date: Tue, 8 Dec 2020 17:28:10 +0100 Subject: [PATCH] fix(namespace): same import in multiple namespaces --- test/namespace-export.test.ts | 67 +++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) diff --git a/test/namespace-export.test.ts b/test/namespace-export.test.ts index 7e88c738..1bbe19d1 100644 --- a/test/namespace-export.test.ts +++ b/test/namespace-export.test.ts @@ -149,3 +149,70 @@ test("Handles namespace exports. #3", async (t, {typescript}) => { } = bundle; t.deepEqual(formatCode(file.code), formatCode(`export * as Foo from "ava";`)); }); + +test("Handles namespace exports. #4", async (t, {typescript}) => { + if (lt(typescript.version, "3.8.0")) { + t.pass(`Current TypeScript version (${typescript.version} does not support 'export * as Foo from "..."' syntax. Skipping...`); + return; + } + + const bundle = await generateRollupBundle( + [ + { + entry: true, + fileName: "index.ts", + text: `\ + export * as Foo from "./foo"; + export * as Bar from "./bar"; + ` + }, + { + entry: false, + fileName: "foo.ts", + text: `\ + import { Subscribable } from 'ava'; + + export interface Foo extends Subscribable { + a: number + } + ` + }, + { + entry: false, + fileName: "bar.ts", + text: `\ + import { Subscribable } from 'ava'; + + export interface Bar extends Subscribable { + b: number; + } + ` + } + ], + { + typescript, + debug: false + } + ); + const { + declarations: [file] + } = bundle; + t.deepEqual( + formatCode(file.code), + formatCode(`\ + import { Subscribable } from "ava"; + + declare namespace Foo { + interface Foo extends Subscribable { + a: number; + } + } + declare namespace Bar { + interface Bar extends Subscribable { + b: number; + } + } + export { Foo, Bar }; + `) + ); +});