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

Fix: properly scope variables in TSModuleBlock #14109

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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ export namespace Namespaced {
fileName: _jsxFileName,
lineNumber: 3,
columnNumber: 3
}, void 0);
}, this);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tsc produces the same output, with this

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ export namespace Namespaced {
fileName: _jsxFileName,
lineNumber: 3,
columnNumber: 3
}, void 0);
}, this);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
declare global { namespace globalThis { var i18n: any; } }

namespace X { var i18n: any; }

export class i18n {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
let X;

(function (_X) {
var i18n;
})(X || (X = {}));

export class i18n {}
3 changes: 2 additions & 1 deletion packages/babel-types/src/ast-types/generated/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2336,7 +2336,8 @@ export type FunctionParent =
| ArrowFunctionExpression
| ClassMethod
| ClassPrivateMethod
| StaticBlock;
| StaticBlock
| TSModuleBlock;
export type Pureish =
| FunctionDeclaration
| FunctionExpression
Expand Down
2 changes: 1 addition & 1 deletion packages/babel-types/src/definitions/typescript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,7 @@ defineType("TSModuleDeclaration", {
});

defineType("TSModuleBlock", {
aliases: ["Scopable", "Block", "BlockParent"],
aliases: ["Scopable", "Block", "BlockParent", "FunctionParent"],
visitor: ["body"],
fields: {
body: validateArrayOfType("Statement"),
Expand Down
3 changes: 2 additions & 1 deletion packages/babel-types/src/validators/generated/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4788,7 +4788,8 @@ export function isFunctionParent(
"ArrowFunctionExpression" === nodeType ||
"ClassMethod" === nodeType ||
"ClassPrivateMethod" === nodeType ||
"StaticBlock" === nodeType
"StaticBlock" === nodeType ||
"TSModuleBlock" === nodeType
) {
if (typeof opts === "undefined") {
return true;
Expand Down