From a9cd0945b7161ca3cdd1e037bb2ae2ebc82b3e6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hu=C3=A1ng=20J=C3=B9nli=C3=A0ng?= Date: Fri, 16 Oct 2020 10:12:50 -0400 Subject: [PATCH] fix: properly wrap private class methods (#12192) --- .../babel-helper-wrap-function/src/index.js | 2 +- .../class-private-method/input.js | 8 ++++++++ .../class-private-method/options.json | 3 +++ .../class-private-method/output.js | 19 +++++++++++++++++++ 4 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 packages/babel-plugin-proposal-async-generator-functions/test/fixtures/async-generators/class-private-method/input.js create mode 100644 packages/babel-plugin-proposal-async-generator-functions/test/fixtures/async-generators/class-private-method/options.json create mode 100644 packages/babel-plugin-proposal-async-generator-functions/test/fixtures/async-generators/class-private-method/output.js diff --git a/packages/babel-helper-wrap-function/src/index.js b/packages/babel-helper-wrap-function/src/index.js index d36e9d267700..e1ff0d37ac81 100644 --- a/packages/babel-helper-wrap-function/src/index.js +++ b/packages/babel-helper-wrap-function/src/index.js @@ -124,7 +124,7 @@ function plainFunction(path: NodePath, callId: Object) { } export default function wrapFunction(path: NodePath, callId: Object) { - if (path.isClassMethod() || path.isObjectMethod()) { + if (path.isMethod()) { classOrObjectMethod(path, callId); } else { plainFunction(path, callId); diff --git a/packages/babel-plugin-proposal-async-generator-functions/test/fixtures/async-generators/class-private-method/input.js b/packages/babel-plugin-proposal-async-generator-functions/test/fixtures/async-generators/class-private-method/input.js new file mode 100644 index 000000000000..667708223ade --- /dev/null +++ b/packages/babel-plugin-proposal-async-generator-functions/test/fixtures/async-generators/class-private-method/input.js @@ -0,0 +1,8 @@ +class C { + async * #g() { + this; + await 1; + yield 2; + return 3; + } +} diff --git a/packages/babel-plugin-proposal-async-generator-functions/test/fixtures/async-generators/class-private-method/options.json b/packages/babel-plugin-proposal-async-generator-functions/test/fixtures/async-generators/class-private-method/options.json new file mode 100644 index 000000000000..b1d145063af9 --- /dev/null +++ b/packages/babel-plugin-proposal-async-generator-functions/test/fixtures/async-generators/class-private-method/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["external-helpers", "proposal-private-methods", "proposal-async-generator-functions"] +} diff --git a/packages/babel-plugin-proposal-async-generator-functions/test/fixtures/async-generators/class-private-method/output.js b/packages/babel-plugin-proposal-async-generator-functions/test/fixtures/async-generators/class-private-method/output.js new file mode 100644 index 000000000000..e7d3cfbe5627 --- /dev/null +++ b/packages/babel-plugin-proposal-async-generator-functions/test/fixtures/async-generators/class-private-method/output.js @@ -0,0 +1,19 @@ +var _g = new WeakSet(); + +class C { + constructor() { + _g.add(this); + } + +} + +var _g2 = function _g2() { + var _this = this; + + return babelHelpers.wrapAsyncGenerator(function* () { + _this; + yield babelHelpers.awaitAsyncGenerator(1); + yield 2; + return 3; + })(); +};