Skip to content

Commit

Permalink
Unshadow class binding
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolo-ribaudo committed Apr 19, 2021
1 parent 6f7cfa8 commit 48415ba
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
Expand Up @@ -4,6 +4,13 @@ import { injectInitialization as injectConstructorInit } from "@babel/helper-cre
export default function pluginPrivateIn({ types: t, template }) {
const ids = new WeakMap();

function unshadow(name, targetScope, scope) {
while (scope !== targetScope) {
if (scope.hasOwnBinding(name)) scope.rename(name);
scope = scope.parent;
}
}

function injectInitialization(classPath, init) {
let firstFieldPath;
let consturctorPath;
Expand Down Expand Up @@ -68,7 +75,9 @@ export default function pluginPrivateIn({ types: t, template }) {
}

if (isStatic) {
if (!outerClass.node.id) {
if (outerClass.node.id) {
unshadow(outerClass.node.id.name, outerClass.scope, path.scope);
} else {
outerClass.set("id", path.scope.generateUidIdentifier("class"));
}
path.replaceWith(
Expand Down
@@ -0,0 +1,9 @@
class A {
static #foo;

test() {
let A = function fn(A) {
return #foo in A;
};
}
}
@@ -0,0 +1,10 @@
class A {
static #foo;

test() {
let _A2 = function fn(_A) {
return A === _A;
};
}

}

0 comments on commit 48415ba

Please sign in to comment.