Skip to content

Commit

Permalink
[ts] remove nested declare namespace (#14952)
Browse files Browse the repository at this point in the history
  • Loading branch information
liuxingbaoyu committed Sep 20, 2022
1 parent 40dfe9a commit 0e5571f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
21 changes: 9 additions & 12 deletions packages/babel-plugin-transform-typescript/src/namespace.ts
Expand Up @@ -81,14 +81,11 @@ function handleVariableDeclaration(
// `export const a = 1` transforms to `const a = N.a = 1`, the output
// is smaller than `const a = 1; N.a = a`;
for (const declarator of declarations) {
// `export declare const a`,the declarator.init would be null,
if (declarator.init) {
declarator.init = t.assignmentExpression(
"=",
getMemberExpression(name, declarator.id.name),
declarator.init,
);
}
declarator.init = t.assignmentExpression(
"=",
getMemberExpression(name, declarator.id.name),
declarator.init,
);
}
return [node];
}
Expand Down Expand Up @@ -183,15 +180,15 @@ function handleNested(
// Export declarations get parsed using the next switch.
}

if ("declare" in subNode.declaration && subNode.declaration.declare) {
continue;
}

// Transform the export declarations that occur inside of a namespace.
switch (subNode.declaration.type) {
case "TSEnumDeclaration":
case "FunctionDeclaration":
case "ClassDeclaration": {
if (subNode.declaration.declare) {
continue;
}

const itemName = subNode.declaration.id.name;
names.add(itemName);
namespaceTopLevel.splice(
Expand Down
Expand Up @@ -4,4 +4,7 @@ export namespace N {
export declare enum e { };
export declare function f(): void;
export declare const v: unknown;
}
export declare namespace B {
export interface C { }
}
}

0 comments on commit 0e5571f

Please sign in to comment.