Skip to content

Commit

Permalink
feat
Browse files Browse the repository at this point in the history
  • Loading branch information
liuxingbaoyu committed Jan 23, 2025
1 parent d9fa47d commit 053bc7b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 15 deletions.
34 changes: 20 additions & 14 deletions packages/babel-plugin-transform-typescript/src/enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,22 +175,28 @@ function ReferencedIdentifier(
const name = expr.node.name;

if (seen.has(name)) {
for (
let curScope = expr.scope;
curScope !== path.scope;
curScope = curScope.parent
) {
if (curScope.hasOwnBinding(name)) {
/* The name is declared inside enum:
enum Foo {
A,
B = (() => {
const A = 1;
return A;
})())
} */
/* The name is declared inside enum:
enum Foo {
A,
B = (() => {
const A = 1;
return A;
})())
} */
if (process.env.BABEL_8_BREAKING) {
if (expr.scope.hasBinding(name, { upToScope: path.scope })) {
return;
}
} else {
for (
let curScope = expr.scope;
curScope !== path.scope;
curScope = curScope.parent
) {
if (curScope.hasOwnBinding(name)) {
return;
}
}
}

expr.replaceWith(
Expand Down
8 changes: 7 additions & 1 deletion packages/babel-traverse/src/scope/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1204,11 +1204,17 @@ class Scope {
// was used to declare a variable in a different scope.
hasBinding(
name: string,
opts?: boolean | { noGlobals?: boolean; noUids?: boolean },
opts?:
| boolean
| { noGlobals?: boolean; noUids?: boolean; upToScope?: Scope },
) {
if (!name) return false;
const upToScope = (opts as { upToScope?: Scope })?.upToScope;
let scope: Scope = this;
do {
if (upToScope === scope) {
return false;
}
if (scope.hasOwnBinding(name)) {
return true;
}
Expand Down

0 comments on commit 053bc7b

Please sign in to comment.