From a0bd18e7089d80b9257502d2350842b598f6548c Mon Sep 17 00:00:00 2001 From: Sneh Khatri Date: Thu, 6 Jan 2022 22:10:44 +0530 Subject: [PATCH] Fix: typescript declare global conflict with TSModuleBlock declaration --- .../namespace/declare-global-nested-namespace/input.ts | 3 +++ .../namespace/declare-global-nested-namespace/output.mjs | 1 + packages/babel-traverse/src/scope/index.ts | 3 +++ 3 files changed, 7 insertions(+) create mode 100644 packages/babel-plugin-transform-typescript/test/fixtures/namespace/declare-global-nested-namespace/input.ts create mode 100644 packages/babel-plugin-transform-typescript/test/fixtures/namespace/declare-global-nested-namespace/output.mjs diff --git a/packages/babel-plugin-transform-typescript/test/fixtures/namespace/declare-global-nested-namespace/input.ts b/packages/babel-plugin-transform-typescript/test/fixtures/namespace/declare-global-nested-namespace/input.ts new file mode 100644 index 000000000000..13f0c52527b4 --- /dev/null +++ b/packages/babel-plugin-transform-typescript/test/fixtures/namespace/declare-global-nested-namespace/input.ts @@ -0,0 +1,3 @@ +declare global { namespace globalThis { var i18n: any; } } + +export class i18n {} \ No newline at end of file diff --git a/packages/babel-plugin-transform-typescript/test/fixtures/namespace/declare-global-nested-namespace/output.mjs b/packages/babel-plugin-transform-typescript/test/fixtures/namespace/declare-global-nested-namespace/output.mjs new file mode 100644 index 000000000000..2112258a3b74 --- /dev/null +++ b/packages/babel-plugin-transform-typescript/test/fixtures/namespace/declare-global-nested-namespace/output.mjs @@ -0,0 +1 @@ +export class i18n {} diff --git a/packages/babel-traverse/src/scope/index.ts b/packages/babel-traverse/src/scope/index.ts index e2eb17d8f724..100a7df6fa22 100644 --- a/packages/babel-traverse/src/scope/index.ts +++ b/packages/babel-traverse/src/scope/index.ts @@ -745,6 +745,9 @@ export default class Scope { path: NodePath, bindingPath: NodePath = path, ) { + if (path.isVariableDeclarator() && path.scope.path.isTSModuleBlock()) { + return; + } if (!kind) throw new ReferenceError("no `kind`"); if (path.isVariableDeclaration()) {