Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ts] remove nested declare namespace #14952

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 { }
}
}