From 799c0c1f0ffa4932c77ef0cab02b413c07ce42b8 Mon Sep 17 00:00:00 2001 From: Ming Date: Wed, 20 Jul 2022 17:52:25 +0800 Subject: [PATCH] Declare class in namespace should be removed --- packages/babel-plugin-transform-typescript/src/namespace.ts | 4 ++++ .../test/fixtures/namespace/declare-class/input.ts | 4 ++++ .../test/fixtures/namespace/declare-class/output.mjs | 3 +++ 3 files changed, 11 insertions(+) create mode 100644 packages/babel-plugin-transform-typescript/test/fixtures/namespace/declare-class/input.ts create mode 100644 packages/babel-plugin-transform-typescript/test/fixtures/namespace/declare-class/output.mjs diff --git a/packages/babel-plugin-transform-typescript/src/namespace.ts b/packages/babel-plugin-transform-typescript/src/namespace.ts index 74532eca9412..7d26dec320c1 100644 --- a/packages/babel-plugin-transform-typescript/src/namespace.ts +++ b/packages/babel-plugin-transform-typescript/src/namespace.ts @@ -185,6 +185,10 @@ function handleNested( case "TSEnumDeclaration": case "FunctionDeclaration": case "ClassDeclaration": { + if (subNode.declaration.declare) { + continue; + } + const itemName = subNode.declaration.id.name; names.add(itemName); namespaceTopLevel.splice( diff --git a/packages/babel-plugin-transform-typescript/test/fixtures/namespace/declare-class/input.ts b/packages/babel-plugin-transform-typescript/test/fixtures/namespace/declare-class/input.ts new file mode 100644 index 000000000000..ab6316e99249 --- /dev/null +++ b/packages/babel-plugin-transform-typescript/test/fixtures/namespace/declare-class/input.ts @@ -0,0 +1,4 @@ +export namespace A { + export declare class B { + } +} \ No newline at end of file diff --git a/packages/babel-plugin-transform-typescript/test/fixtures/namespace/declare-class/output.mjs b/packages/babel-plugin-transform-typescript/test/fixtures/namespace/declare-class/output.mjs new file mode 100644 index 000000000000..d4cc47055d31 --- /dev/null +++ b/packages/babel-plugin-transform-typescript/test/fixtures/namespace/declare-class/output.mjs @@ -0,0 +1,3 @@ +export let A; + +(function (_A) {})(A || (A = {}));