diff --git a/packages/babel-plugin-proposal-private-methods/test/fixtures/private-method/scopable/exec.js b/packages/babel-plugin-proposal-private-methods/test/fixtures/private-method/scopable/exec.js new file mode 100644 index 0000000000..874b970d15 --- /dev/null +++ b/packages/babel-plugin-proposal-private-methods/test/fixtures/private-method/scopable/exec.js @@ -0,0 +1,17 @@ +class Foo { + #privateMethodA() { + const i = 40; + return i; + } + + #privateMethodB() { + const i = 2; + return i; + } + + publicMethod() { + return this.#privateMethodA() + this.#privateMethodB(); + } +} + +expect((new Foo).publicMethod()).toEqual(42); \ No newline at end of file diff --git a/packages/babel-types/src/definitions/experimental.js b/packages/babel-types/src/definitions/experimental.js index 6bf4a476cc..6498e9c329 100644 --- a/packages/babel-types/src/definitions/experimental.js +++ b/packages/babel-types/src/definitions/experimental.js @@ -168,7 +168,14 @@ defineType("ClassPrivateMethod", { "returnType", "typeParameters", ], - aliases: ["Method", "Private", "Function"], + aliases: [ + "Function", + "Scopable", + "BlockParent", + "FunctionParent", + "Method", + "Private", + ], fields: { ...classMethodOrDeclareMethodCommon, key: { diff --git a/packages/babel-types/src/validators/generated/index.js b/packages/babel-types/src/validators/generated/index.js index a93ccb5ce1..31d6a747c3 100644 --- a/packages/babel-types/src/validators/generated/index.js +++ b/packages/babel-types/src/validators/generated/index.js @@ -3283,7 +3283,8 @@ export function isScopable(node: Object, opts?: Object): boolean { "ClassDeclaration" === nodeType || "ClassExpression" === nodeType || "ForOfStatement" === nodeType || - "ClassMethod" === nodeType + "ClassMethod" === nodeType || + "ClassPrivateMethod" === nodeType ) { if (typeof opts === "undefined") { return true; @@ -3313,7 +3314,8 @@ export function isBlockParent(node: Object, opts?: Object): boolean { "WhileStatement" === nodeType || "ArrowFunctionExpression" === nodeType || "ForOfStatement" === nodeType || - "ClassMethod" === nodeType + "ClassMethod" === nodeType || + "ClassPrivateMethod" === nodeType ) { if (typeof opts === "undefined") { return true; @@ -3591,7 +3593,8 @@ export function isFunctionParent(node: Object, opts?: Object): boolean { "FunctionExpression" === nodeType || "ObjectMethod" === nodeType || "ArrowFunctionExpression" === nodeType || - "ClassMethod" === nodeType + "ClassMethod" === nodeType || + "ClassPrivateMethod" === nodeType ) { if (typeof opts === "undefined") { return true;