From 76d571e285df2e442a50fc8b7fb8280970cfcd68 Mon Sep 17 00:00:00 2001 From: uhyo Date: Tue, 25 Aug 2020 02:35:31 +0900 Subject: [PATCH] fix(plugin-proposal-function-bind): fix invalid code emitted for `::super.foo` (#12000) --- packages/babel-plugin-proposal-function-bind/src/index.js | 5 ++++- .../test/fixtures/function-bind/super/input.js | 6 ++++++ .../test/fixtures/function-bind/super/output.js | 7 +++++++ 3 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 packages/babel-plugin-proposal-function-bind/test/fixtures/function-bind/super/input.js create mode 100644 packages/babel-plugin-proposal-function-bind/test/fixtures/function-bind/super/output.js diff --git a/packages/babel-plugin-proposal-function-bind/src/index.js b/packages/babel-plugin-proposal-function-bind/src/index.js index 0dea27804a..4a26c705cf 100644 --- a/packages/babel-plugin-proposal-function-bind/src/index.js +++ b/packages/babel-plugin-proposal-function-bind/src/index.js @@ -15,7 +15,10 @@ export default declare(api => { function getStaticContext(bind, scope) { const object = bind.object || bind.callee.object; - return scope.isStatic(object) && object; + return ( + scope.isStatic(object) && + (t.isSuper(object) ? t.thisExpression() : object) + ); } function inferBindContext(bind, scope) { diff --git a/packages/babel-plugin-proposal-function-bind/test/fixtures/function-bind/super/input.js b/packages/babel-plugin-proposal-function-bind/test/fixtures/function-bind/super/input.js new file mode 100644 index 0000000000..5faf8f6f93 --- /dev/null +++ b/packages/babel-plugin-proposal-function-bind/test/fixtures/function-bind/super/input.js @@ -0,0 +1,6 @@ +class C { + foo() { + ::super.bar; + ::super.baz(123); + } +} diff --git a/packages/babel-plugin-proposal-function-bind/test/fixtures/function-bind/super/output.js b/packages/babel-plugin-proposal-function-bind/test/fixtures/function-bind/super/output.js new file mode 100644 index 0000000000..b249ce7a39 --- /dev/null +++ b/packages/babel-plugin-proposal-function-bind/test/fixtures/function-bind/super/output.js @@ -0,0 +1,7 @@ +class C { + foo() { + super.bar.bind(this); + super.baz.call(this, 123); + } + +}