Skip to content

Commit

Permalink
Fix: properly scope variables in TSModuleBlock
Browse files Browse the repository at this point in the history
Co-authored-by: Nicol貌 Ribaudo <nicolo.ribaudo@gmail.com>
  • Loading branch information
The-x-Theorist and nicolo-ribaudo committed Oct 6, 2022
1 parent 367d4ed commit 346e812
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 4 deletions.
Expand Up @@ -7,5 +7,5 @@ export namespace Namespaced {
fileName: _jsxFileName,
lineNumber: 3,
columnNumber: 3
}, void 0);
}, this);
}
@@ -0,0 +1,5 @@
declare global { namespace globalThis { var i18n: any; } }

namespace X { var i18n: any; }

export class i18n {}
@@ -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
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
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
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

0 comments on commit 346e812

Please sign in to comment.