Fix duplicate definition error in private class methods (#9453)
This commit is contained in:
parent
d37c958637
commit
65cbbc1ef8
17
packages/babel-plugin-proposal-private-methods/test/fixtures/private-method/scopable/exec.js
vendored
Normal file
17
packages/babel-plugin-proposal-private-methods/test/fixtures/private-method/scopable/exec.js
vendored
Normal file
@ -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);
|
||||||
@ -168,7 +168,14 @@ defineType("ClassPrivateMethod", {
|
|||||||
"returnType",
|
"returnType",
|
||||||
"typeParameters",
|
"typeParameters",
|
||||||
],
|
],
|
||||||
aliases: ["Method", "Private", "Function"],
|
aliases: [
|
||||||
|
"Function",
|
||||||
|
"Scopable",
|
||||||
|
"BlockParent",
|
||||||
|
"FunctionParent",
|
||||||
|
"Method",
|
||||||
|
"Private",
|
||||||
|
],
|
||||||
fields: {
|
fields: {
|
||||||
...classMethodOrDeclareMethodCommon,
|
...classMethodOrDeclareMethodCommon,
|
||||||
key: {
|
key: {
|
||||||
|
|||||||
@ -3283,7 +3283,8 @@ export function isScopable(node: Object, opts?: Object): boolean {
|
|||||||
"ClassDeclaration" === nodeType ||
|
"ClassDeclaration" === nodeType ||
|
||||||
"ClassExpression" === nodeType ||
|
"ClassExpression" === nodeType ||
|
||||||
"ForOfStatement" === nodeType ||
|
"ForOfStatement" === nodeType ||
|
||||||
"ClassMethod" === nodeType
|
"ClassMethod" === nodeType ||
|
||||||
|
"ClassPrivateMethod" === nodeType
|
||||||
) {
|
) {
|
||||||
if (typeof opts === "undefined") {
|
if (typeof opts === "undefined") {
|
||||||
return true;
|
return true;
|
||||||
@ -3313,7 +3314,8 @@ export function isBlockParent(node: Object, opts?: Object): boolean {
|
|||||||
"WhileStatement" === nodeType ||
|
"WhileStatement" === nodeType ||
|
||||||
"ArrowFunctionExpression" === nodeType ||
|
"ArrowFunctionExpression" === nodeType ||
|
||||||
"ForOfStatement" === nodeType ||
|
"ForOfStatement" === nodeType ||
|
||||||
"ClassMethod" === nodeType
|
"ClassMethod" === nodeType ||
|
||||||
|
"ClassPrivateMethod" === nodeType
|
||||||
) {
|
) {
|
||||||
if (typeof opts === "undefined") {
|
if (typeof opts === "undefined") {
|
||||||
return true;
|
return true;
|
||||||
@ -3591,7 +3593,8 @@ export function isFunctionParent(node: Object, opts?: Object): boolean {
|
|||||||
"FunctionExpression" === nodeType ||
|
"FunctionExpression" === nodeType ||
|
||||||
"ObjectMethod" === nodeType ||
|
"ObjectMethod" === nodeType ||
|
||||||
"ArrowFunctionExpression" === nodeType ||
|
"ArrowFunctionExpression" === nodeType ||
|
||||||
"ClassMethod" === nodeType
|
"ClassMethod" === nodeType ||
|
||||||
|
"ClassPrivateMethod" === nodeType
|
||||||
) {
|
) {
|
||||||
if (typeof opts === "undefined") {
|
if (typeof opts === "undefined") {
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user