From e8b4108ab98e44c6e592382c213442473347f2d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hu=C3=A1ng=20J=C3=B9nli=C3=A0ng?= Date: Tue, 12 May 2020 16:53:49 -0400 Subject: [PATCH 01/12] fix: ensure (a?.b)() has proper this --- .../src/index.js | 29 +++++++++++++++++-- .../general/parenthesized-member-call/exec.js | 25 ++++++++++++++++ .../parenthesized-member-call/input.js | 7 +++++ .../parenthesized-member-call/output.js | 6 ++++ 4 files changed, 65 insertions(+), 2 deletions(-) create mode 100644 packages/babel-plugin-proposal-optional-chaining/test/fixtures/general/parenthesized-member-call/exec.js create mode 100644 packages/babel-plugin-proposal-optional-chaining/test/fixtures/general/parenthesized-member-call/input.js create mode 100644 packages/babel-plugin-proposal-optional-chaining/test/fixtures/general/parenthesized-member-call/output.js diff --git a/packages/babel-plugin-proposal-optional-chaining/src/index.js b/packages/babel-plugin-proposal-optional-chaining/src/index.js index 604f5a4fe8f4..6567e13ea8c4 100644 --- a/packages/babel-plugin-proposal-optional-chaining/src/index.js +++ b/packages/babel-plugin-proposal-optional-chaining/src/index.js @@ -113,7 +113,32 @@ export default declare((api, options) => { ); } } - + let replacement = replacementPath.node; + // Ensure (a?.b)() has proper `this` + if ( + t.isMemberExpression(replacement) && + replacement.extra?.parenthesized && + replacementPath.parentPath.isCallExpression() + ) { + // `(a?.b)()` to `(a == null ? undefined : a.b.bind(a))()` + const { object, property } = replacement; + let memoisedObject; + if (!loose) { + // memoize the context object in non-loose mode + // `(a?.b.c)()` to `(a == null ? undefined : (_a$b = a.b).c.bind(_a$b))()` + const context = scope.maybeGenerateMemoised(object); + if (context) { + memoisedObject = t.assignmentExpression("=", context, object); + } + } + replacement = t.callExpression( + t.memberExpression( + t.memberExpression(memoisedObject ?? object, property), + t.identifier("bind"), + ), + [t.cloneNode(memoisedObject?.left ?? object)], + ); + } replacementPath.replaceWith( t.conditionalExpression( loose @@ -134,7 +159,7 @@ export default declare((api, options) => { isDeleteOperation ? t.booleanLiteral(true) : scope.buildUndefinedNode(), - replacementPath.node, + replacement, ), ); diff --git a/packages/babel-plugin-proposal-optional-chaining/test/fixtures/general/parenthesized-member-call/exec.js b/packages/babel-plugin-proposal-optional-chaining/test/fixtures/general/parenthesized-member-call/exec.js new file mode 100644 index 000000000000..cb88b0174abd --- /dev/null +++ b/packages/babel-plugin-proposal-optional-chaining/test/fixtures/general/parenthesized-member-call/exec.js @@ -0,0 +1,25 @@ +let count = 0; + +const foo = { + get a() { + count++; + return { + b() { + return "b" in this; + } + } + }, + b() { + return "b" in this && "a" in this; + } +} + +expect((foo?.b)()).toBe(true); +expect((foo?.b)?.()).toBe(true); +expect(() => (undefined?.b)()).toThrow(); + +expect((foo?.a.b)()).toBe(true); +expect(count).toBe(1); + +expect((foo?.a.b)?.()).toBe(true); +expect(count).toBe(2); diff --git a/packages/babel-plugin-proposal-optional-chaining/test/fixtures/general/parenthesized-member-call/input.js b/packages/babel-plugin-proposal-optional-chaining/test/fixtures/general/parenthesized-member-call/input.js new file mode 100644 index 000000000000..2249a045542a --- /dev/null +++ b/packages/babel-plugin-proposal-optional-chaining/test/fixtures/general/parenthesized-member-call/input.js @@ -0,0 +1,7 @@ +(foo?.bar)(); + +(foo?.bar)?.(); + +(foo?.bar.baz)(); + +(foo?.bar.baz)?.(); diff --git a/packages/babel-plugin-proposal-optional-chaining/test/fixtures/general/parenthesized-member-call/output.js b/packages/babel-plugin-proposal-optional-chaining/test/fixtures/general/parenthesized-member-call/output.js new file mode 100644 index 000000000000..1c931915b01d --- /dev/null +++ b/packages/babel-plugin-proposal-optional-chaining/test/fixtures/general/parenthesized-member-call/output.js @@ -0,0 +1,6 @@ +var _foo, _foo2, _foo2$bar, _foo3, _foo3$bar, _foo4, _foo4$bar$baz, _foo4$bar; + +((_foo = foo) === null || _foo === void 0 ? void 0 : _foo.bar.bind(_foo))(); +(_foo2 = foo) === null || _foo2 === void 0 ? void 0 : (_foo2$bar = _foo2.bar) === null || _foo2$bar === void 0 ? void 0 : _foo2$bar.call(_foo2); +((_foo3 = foo) === null || _foo3 === void 0 ? void 0 : (_foo3$bar = _foo3.bar).baz.bind(_foo3$bar))(); +(_foo4 = foo) === null || _foo4 === void 0 ? void 0 : (_foo4$bar$baz = (_foo4$bar = _foo4.bar).baz) === null || _foo4$bar$baz === void 0 ? void 0 : _foo4$bar$baz.call(_foo4$bar); From a351a4b835de7f655fc1cb2a7e67bf0d35b1d409 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hu=C3=A1ng=20J=C3=B9nli=C3=A0ng?= Date: Tue, 12 May 2020 17:11:37 -0400 Subject: [PATCH 02/12] let test be more restrictive --- .../test/fixtures/general/parenthesized-member-call/exec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/babel-plugin-proposal-optional-chaining/test/fixtures/general/parenthesized-member-call/exec.js b/packages/babel-plugin-proposal-optional-chaining/test/fixtures/general/parenthesized-member-call/exec.js index cb88b0174abd..9d273587595e 100644 --- a/packages/babel-plugin-proposal-optional-chaining/test/fixtures/general/parenthesized-member-call/exec.js +++ b/packages/babel-plugin-proposal-optional-chaining/test/fixtures/general/parenthesized-member-call/exec.js @@ -5,7 +5,7 @@ const foo = { count++; return { b() { - return "b" in this; + return "b" in this && !("a" in this); } } }, From a487e9bfcf1359c6704edf3266761bf7b8c94d12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hu=C3=A1ng=20J=C3=B9nli=C3=A0ng?= Date: Tue, 26 May 2020 23:16:49 -0400 Subject: [PATCH 03/12] fix: transformed member call should preserve computed --- .../babel-plugin-proposal-optional-chaining/src/index.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/babel-plugin-proposal-optional-chaining/src/index.js b/packages/babel-plugin-proposal-optional-chaining/src/index.js index 6567e13ea8c4..b1c95e4d7e17 100644 --- a/packages/babel-plugin-proposal-optional-chaining/src/index.js +++ b/packages/babel-plugin-proposal-optional-chaining/src/index.js @@ -121,7 +121,7 @@ export default declare((api, options) => { replacementPath.parentPath.isCallExpression() ) { // `(a?.b)()` to `(a == null ? undefined : a.b.bind(a))()` - const { object, property } = replacement; + const { object, property, computed } = replacement; let memoisedObject; if (!loose) { // memoize the context object in non-loose mode @@ -133,7 +133,11 @@ export default declare((api, options) => { } replacement = t.callExpression( t.memberExpression( - t.memberExpression(memoisedObject ?? object, property), + t.memberExpression( + memoisedObject ?? object, + property, + computed, + ), t.identifier("bind"), ), [t.cloneNode(memoisedObject?.left ?? object)], From 4f3369f8f91e352a17d903e1b59e3822f30d0c48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hu=C3=A1ng=20J=C3=B9nli=C3=A0ng?= Date: Tue, 26 May 2020 23:17:08 -0400 Subject: [PATCH 04/12] chore: revamp test files --- .../general/parenthesized-member-call/exec.js | 60 ++++++++++++------- .../parenthesized-member-call/input.js | 27 +++++++-- .../parenthesized-member-call/output.js | 38 ++++++++++-- 3 files changed, 96 insertions(+), 29 deletions(-) diff --git a/packages/babel-plugin-proposal-optional-chaining/test/fixtures/general/parenthesized-member-call/exec.js b/packages/babel-plugin-proposal-optional-chaining/test/fixtures/general/parenthesized-member-call/exec.js index 9d273587595e..bfb53e693b08 100644 --- a/packages/babel-plugin-proposal-optional-chaining/test/fixtures/general/parenthesized-member-call/exec.js +++ b/packages/babel-plugin-proposal-optional-chaining/test/fixtures/general/parenthesized-member-call/exec.js @@ -1,25 +1,45 @@ -let count = 0; - -const foo = { - get a() { - count++; - return { - b() { - return "b" in this && !("a" in this); - } +class Foo { + constructor() { + this.x = 1; + this.self = this; + } + m() { return this.x; }; + getSelf() { return this } + + test() { + const Foo = this; + const o = { Foo: Foo }; + const deep = { very: { o } }; + function fn() { + return o; + } + function fnDeep() { + return deep; } - }, - b() { - return "b" in this && "a" in this; + + expect((Foo?.["m"])()).toEqual(1); + expect((Foo?.["m"])().toString).toEqual(1..toString); + expect((Foo?.["m"])().toString()).toEqual('1'); + + expect((o?.Foo.m)()).toEqual(1); + expect((o?.Foo.m)().toString).toEqual(1..toString); + expect((o?.Foo.m)().toString()).toEqual('1'); + + expect((((o.Foo?.self.getSelf)())?.m)()).toEqual(1); + expect((((o.Foo.self?.getSelf)())?.m)()).toEqual(1); } -} -expect((foo?.b)()).toBe(true); -expect((foo?.b)?.()).toBe(true); -expect(() => (undefined?.b)()).toThrow(); + testNull() { + const o = null; + + expect(() => { (o?.Foo.m)() }).toThrow(); + expect(() => { (o?.Foo.m)().toString }).toThrow(); + expect(() => { (o?.Foo.m)().toString() }).toThrow(); -expect((foo?.a.b)()).toBe(true); -expect(count).toBe(1); + expect(() => { (((o.Foo?.self.getSelf)())?.m)() }).toThrow(); + expect(() => { (((o.Foo.self?.getSelf)())?.m)() }).toThrow(); + } +} -expect((foo?.a.b)?.()).toBe(true); -expect(count).toBe(2); +(new Foo).test(); +(new Foo).testNull(); diff --git a/packages/babel-plugin-proposal-optional-chaining/test/fixtures/general/parenthesized-member-call/input.js b/packages/babel-plugin-proposal-optional-chaining/test/fixtures/general/parenthesized-member-call/input.js index 2249a045542a..1bdce5676802 100644 --- a/packages/babel-plugin-proposal-optional-chaining/test/fixtures/general/parenthesized-member-call/input.js +++ b/packages/babel-plugin-proposal-optional-chaining/test/fixtures/general/parenthesized-member-call/input.js @@ -1,7 +1,26 @@ -(foo?.bar)(); +class Foo { + constructor() { + this.x = 1; + this.self = this; + } + m() { return this.x; }; + getSelf() { return this } -(foo?.bar)?.(); + test() { + const Foo = this; + const o = { Foo: Foo }; -(foo?.bar.baz)(); + (Foo?.["m"])(); + (Foo?.["m"])().toString; + (Foo?.["m"])().toString(); -(foo?.bar.baz)?.(); + (o?.Foo.m)(); + (o?.Foo.m)().toString; + (o?.Foo.m)().toString(); + + (((o.Foo?.self.getSelf)())?.m)(); + (((o.Foo.self?.getSelf)())?.m)(); + } +} + +(new Foo).test(); diff --git a/packages/babel-plugin-proposal-optional-chaining/test/fixtures/general/parenthesized-member-call/output.js b/packages/babel-plugin-proposal-optional-chaining/test/fixtures/general/parenthesized-member-call/output.js index 1c931915b01d..d298c6342ac2 100644 --- a/packages/babel-plugin-proposal-optional-chaining/test/fixtures/general/parenthesized-member-call/output.js +++ b/packages/babel-plugin-proposal-optional-chaining/test/fixtures/general/parenthesized-member-call/output.js @@ -1,6 +1,34 @@ -var _foo, _foo2, _foo2$bar, _foo3, _foo3$bar, _foo4, _foo4$bar$baz, _foo4$bar; +class Foo { + constructor() { + this.x = 1; + this.self = this; + } -((_foo = foo) === null || _foo === void 0 ? void 0 : _foo.bar.bind(_foo))(); -(_foo2 = foo) === null || _foo2 === void 0 ? void 0 : (_foo2$bar = _foo2.bar) === null || _foo2$bar === void 0 ? void 0 : _foo2$bar.call(_foo2); -((_foo3 = foo) === null || _foo3 === void 0 ? void 0 : (_foo3$bar = _foo3.bar).baz.bind(_foo3$bar))(); -(_foo4 = foo) === null || _foo4 === void 0 ? void 0 : (_foo4$bar$baz = (_foo4$bar = _foo4.bar).baz) === null || _foo4$bar$baz === void 0 ? void 0 : _foo4$bar$baz.call(_foo4$bar); + m() { + return this.x; + } + + getSelf() { + return this; + } + + test() { + var _o$Foo, _o$Foo2, _o$Foo3, _o$Foo$self$getSelf, _o$Foo4, _o$Foo4$self, _o$Foo$self$getSelf2, _o$Foo$self; + + const Foo = this; + const o = { + Foo: Foo + }; + (Foo === null || Foo === void 0 ? void 0 : Foo["m"].bind(Foo))(); + (Foo === null || Foo === void 0 ? void 0 : Foo["m"].bind(Foo))().toString; + (Foo === null || Foo === void 0 ? void 0 : Foo["m"].bind(Foo))().toString(); + (o === null || o === void 0 ? void 0 : (_o$Foo = o.Foo).m.bind(_o$Foo))(); + (o === null || o === void 0 ? void 0 : (_o$Foo2 = o.Foo).m.bind(_o$Foo2))().toString; + (o === null || o === void 0 ? void 0 : (_o$Foo3 = o.Foo).m.bind(_o$Foo3))().toString(); + ((_o$Foo$self$getSelf = ((_o$Foo4 = o.Foo) === null || _o$Foo4 === void 0 ? void 0 : (_o$Foo4$self = _o$Foo4.self).getSelf.bind(_o$Foo4$self))()) === null || _o$Foo$self$getSelf === void 0 ? void 0 : _o$Foo$self$getSelf.m.bind(_o$Foo$self$getSelf))(); + ((_o$Foo$self$getSelf2 = ((_o$Foo$self = o.Foo.self) === null || _o$Foo$self === void 0 ? void 0 : _o$Foo$self.getSelf.bind(_o$Foo$self))()) === null || _o$Foo$self$getSelf2 === void 0 ? void 0 : _o$Foo$self$getSelf2.m.bind(_o$Foo$self$getSelf2))(); + } + +} + +new Foo().test(); From 3672f7fdd2f46bf216d60063ecd47a2a463c25c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hu=C3=A1ng=20J=C3=B9nli=C3=A0ng?= Date: Tue, 26 May 2020 23:32:13 -0400 Subject: [PATCH 05/12] refactor: simplify --- .../src/index.js | 25 ++++++++----------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/packages/babel-plugin-proposal-optional-chaining/src/index.js b/packages/babel-plugin-proposal-optional-chaining/src/index.js index b1c95e4d7e17..76a9b1ba438f 100644 --- a/packages/babel-plugin-proposal-optional-chaining/src/index.js +++ b/packages/babel-plugin-proposal-optional-chaining/src/index.js @@ -121,26 +121,23 @@ export default declare((api, options) => { replacementPath.parentPath.isCallExpression() ) { // `(a?.b)()` to `(a == null ? undefined : a.b.bind(a))()` - const { object, property, computed } = replacement; - let memoisedObject; + const { object } = replacement; + let baseRef; if (!loose) { // memoize the context object in non-loose mode // `(a?.b.c)()` to `(a == null ? undefined : (_a$b = a.b).c.bind(_a$b))()` - const context = scope.maybeGenerateMemoised(object); - if (context) { - memoisedObject = t.assignmentExpression("=", context, object); + baseRef = scope.maybeGenerateMemoised(object); + if (baseRef) { + replacement.object = t.assignmentExpression( + "=", + baseRef, + object, + ); } } replacement = t.callExpression( - t.memberExpression( - t.memberExpression( - memoisedObject ?? object, - property, - computed, - ), - t.identifier("bind"), - ), - [t.cloneNode(memoisedObject?.left ?? object)], + t.memberExpression(replacement, t.identifier("bind")), + [t.cloneNode(baseRef ?? object)], ); } replacementPath.replaceWith( From 30b485229d211551aed4b3bb5a521cdc296aa186 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hu=C3=A1ng=20J=C3=B9nli=C3=A0ng?= Date: Wed, 27 May 2020 10:07:58 -0400 Subject: [PATCH 06/12] fix: unwrap parthenthesizedExpression --- .../src/index.js | 26 +++++++--- .../exec.js | 49 +++++++++++++++++++ .../options.json | 6 +++ 3 files changed, 73 insertions(+), 8 deletions(-) create mode 100644 packages/babel-plugin-proposal-optional-chaining/test/fixtures/general/parenthesized-expression-member-call/exec.js create mode 100644 packages/babel-plugin-proposal-optional-chaining/test/fixtures/general/parenthesized-expression-member-call/options.json diff --git a/packages/babel-plugin-proposal-optional-chaining/src/index.js b/packages/babel-plugin-proposal-optional-chaining/src/index.js index 76a9b1ba438f..cca75eb2c25f 100644 --- a/packages/babel-plugin-proposal-optional-chaining/src/index.js +++ b/packages/babel-plugin-proposal-optional-chaining/src/index.js @@ -23,14 +23,23 @@ export default declare((api, options) => { visitor: { "OptionalCallExpression|OptionalMemberExpression"(path) { - const { parentPath, scope } = path; + const { scope } = path; + let parentPath; + // unwrap parenthesis around parent path + for ( + { parentPath } = path; + parentPath.type === "ParenthesizedExpression"; + { parentPath } = parentPath + ); let isDeleteOperation = false; const optionals = []; let optionalPath = path; while ( optionalPath.isOptionalMemberExpression() || - optionalPath.isOptionalCallExpression() + optionalPath.isOptionalCallExpression() || + optionalPath.isParenthesizedExpression() || + optionalPath.isTSNonNullExpression() ) { const { node } = optionalPath; if (node.optional) { @@ -43,10 +52,8 @@ export default declare((api, options) => { } else if (optionalPath.isOptionalCallExpression()) { optionalPath.node.type = "CallExpression"; optionalPath = optionalPath.get("callee"); - } - - // unwrap a TSNonNullExpression if need - if (optionalPath.isTSNonNullExpression()) { + } else { + // unwrap TSNonNullExpression/ParenthesizedExpression if needed optionalPath = optionalPath.get("expression"); } } @@ -117,8 +124,11 @@ export default declare((api, options) => { // Ensure (a?.b)() has proper `this` if ( t.isMemberExpression(replacement) && - replacement.extra?.parenthesized && - replacementPath.parentPath.isCallExpression() + (replacement.extra?.parenthesized || + // if replacementPath.parentPath does not equal parentPath, + // it must be unwrapped from parenthesized expression. + replacementPath.parentPath !== parentPath) && + parentPath.isCallExpression() ) { // `(a?.b)()` to `(a == null ? undefined : a.b.bind(a))()` const { object } = replacement; diff --git a/packages/babel-plugin-proposal-optional-chaining/test/fixtures/general/parenthesized-expression-member-call/exec.js b/packages/babel-plugin-proposal-optional-chaining/test/fixtures/general/parenthesized-expression-member-call/exec.js new file mode 100644 index 000000000000..949e1bc78316 --- /dev/null +++ b/packages/babel-plugin-proposal-optional-chaining/test/fixtures/general/parenthesized-expression-member-call/exec.js @@ -0,0 +1,49 @@ +class Foo { + constructor() { + this.x = 1; + this.self = this; + } + m() { return this.x; }; + getSelf() { return this } + + test() { + const Foo = this; + const o = { Foo: Foo }; + const deep = { very: { o } }; + function fn() { + return o; + } + function fnDeep() { + return deep; + } + + expect((Foo?.["m"])()).toEqual(1); + expect((Foo?.["m"])().toString).toEqual(1..toString); + expect((Foo?.["m"])().toString()).toEqual('1'); + + expect(((Foo?.["m"]))()).toEqual(1); + expect(((Foo?.["m"]))().toString).toEqual(1..toString); + expect(((Foo?.["m"]))().toString()).toEqual('1'); + + expect((o?.Foo.m)()).toEqual(1); + expect((o?.Foo.m)().toString).toEqual(1..toString); + expect((o?.Foo.m)().toString()).toEqual('1'); + + expect((((o.Foo?.self.getSelf)())?.m)()).toEqual(1); + expect((((o.Foo.self?.getSelf)())?.m)()).toEqual(1); + } + + testNull() { + const o = null; + + expect(() => { (o?.Foo.m)() }).toThrow(); + expect(() => { (o?.Foo.m)().toString }).toThrow(); + expect(() => { (o?.Foo.m)().toString() }).toThrow(); + + expect(() => { (((o.Foo?.self.getSelf)())?.m)() }).toThrow(); + expect(() => { (((o.Foo.self?.getSelf)())?.m)() }).toThrow(); + } +} + +(new Foo).test(); +(new Foo).testNull(); diff --git a/packages/babel-plugin-proposal-optional-chaining/test/fixtures/general/parenthesized-expression-member-call/options.json b/packages/babel-plugin-proposal-optional-chaining/test/fixtures/general/parenthesized-expression-member-call/options.json new file mode 100644 index 000000000000..eae39736acf4 --- /dev/null +++ b/packages/babel-plugin-proposal-optional-chaining/test/fixtures/general/parenthesized-expression-member-call/options.json @@ -0,0 +1,6 @@ +{ + "plugins": ["proposal-optional-chaining"], + "parserOpts": { + "createParenthesizedExpressions": true + } +} From 792b5bd3944fc85fc1735cb8325a51d7f36b71f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hu=C3=A1ng=20J=C3=B9nli=C3=A0ng?= Date: Wed, 27 May 2020 14:22:36 -0400 Subject: [PATCH 07/12] add loose test cases --- .../exec.js | 42 +++++++++++++++++++ .../options.json | 6 +++ .../exec.js | 7 ---- .../parenthesized-member-call-loose/exec.js | 38 +++++++++++++++++ .../parenthesized-member-call-loose/input.js | 26 ++++++++++++ .../options.json | 3 ++ .../parenthesized-member-call-loose/output.js | 34 +++++++++++++++ .../general/parenthesized-member-call/exec.js | 7 ---- 8 files changed, 149 insertions(+), 14 deletions(-) create mode 100644 packages/babel-plugin-proposal-optional-chaining/test/fixtures/general/parenthesized-expression-member-call-loose/exec.js create mode 100644 packages/babel-plugin-proposal-optional-chaining/test/fixtures/general/parenthesized-expression-member-call-loose/options.json create mode 100644 packages/babel-plugin-proposal-optional-chaining/test/fixtures/general/parenthesized-member-call-loose/exec.js create mode 100644 packages/babel-plugin-proposal-optional-chaining/test/fixtures/general/parenthesized-member-call-loose/input.js create mode 100644 packages/babel-plugin-proposal-optional-chaining/test/fixtures/general/parenthesized-member-call-loose/options.json create mode 100644 packages/babel-plugin-proposal-optional-chaining/test/fixtures/general/parenthesized-member-call-loose/output.js diff --git a/packages/babel-plugin-proposal-optional-chaining/test/fixtures/general/parenthesized-expression-member-call-loose/exec.js b/packages/babel-plugin-proposal-optional-chaining/test/fixtures/general/parenthesized-expression-member-call-loose/exec.js new file mode 100644 index 000000000000..eb3b1e5d67c8 --- /dev/null +++ b/packages/babel-plugin-proposal-optional-chaining/test/fixtures/general/parenthesized-expression-member-call-loose/exec.js @@ -0,0 +1,42 @@ +class Foo { + constructor() { + this.x = 1; + this.self = this; + } + m() { return this.x; }; + getSelf() { return this } + + test() { + const Foo = this; + const o = { Foo: Foo }; + + expect((Foo?.["m"])()).toEqual(1); + expect((Foo?.["m"])().toString).toEqual(1..toString); + expect((Foo?.["m"])().toString()).toEqual('1'); + + expect(((Foo?.["m"]))()).toEqual(1); + expect(((Foo?.["m"]))().toString).toEqual(1..toString); + expect(((Foo?.["m"]))().toString()).toEqual('1'); + + expect((o?.Foo.m)()).toEqual(1); + expect((o?.Foo.m)().toString).toEqual(1..toString); + expect((o?.Foo.m)().toString()).toEqual('1'); + + expect((((o.Foo?.self.getSelf)())?.m)()).toEqual(1); + expect((((o.Foo.self?.getSelf)())?.m)()).toEqual(1); + } + + testNull() { + const o = null; + + expect(() => { (o?.Foo.m)() }).toThrow(); + expect(() => { (o?.Foo.m)().toString }).toThrow(); + expect(() => { (o?.Foo.m)().toString() }).toThrow(); + + expect(() => { (((o.Foo?.self.getSelf)())?.m)() }).toThrow(); + expect(() => { (((o.Foo.self?.getSelf)())?.m)() }).toThrow(); + } +} + +(new Foo).test(); +(new Foo).testNull(); diff --git a/packages/babel-plugin-proposal-optional-chaining/test/fixtures/general/parenthesized-expression-member-call-loose/options.json b/packages/babel-plugin-proposal-optional-chaining/test/fixtures/general/parenthesized-expression-member-call-loose/options.json new file mode 100644 index 000000000000..fe05dbf3f58c --- /dev/null +++ b/packages/babel-plugin-proposal-optional-chaining/test/fixtures/general/parenthesized-expression-member-call-loose/options.json @@ -0,0 +1,6 @@ +{ + "plugins": [["proposal-optional-chaining", { "loose": true }]], + "parserOpts": { + "createParenthesizedExpressions": true + } +} diff --git a/packages/babel-plugin-proposal-optional-chaining/test/fixtures/general/parenthesized-expression-member-call/exec.js b/packages/babel-plugin-proposal-optional-chaining/test/fixtures/general/parenthesized-expression-member-call/exec.js index 949e1bc78316..eb3b1e5d67c8 100644 --- a/packages/babel-plugin-proposal-optional-chaining/test/fixtures/general/parenthesized-expression-member-call/exec.js +++ b/packages/babel-plugin-proposal-optional-chaining/test/fixtures/general/parenthesized-expression-member-call/exec.js @@ -9,13 +9,6 @@ class Foo { test() { const Foo = this; const o = { Foo: Foo }; - const deep = { very: { o } }; - function fn() { - return o; - } - function fnDeep() { - return deep; - } expect((Foo?.["m"])()).toEqual(1); expect((Foo?.["m"])().toString).toEqual(1..toString); diff --git a/packages/babel-plugin-proposal-optional-chaining/test/fixtures/general/parenthesized-member-call-loose/exec.js b/packages/babel-plugin-proposal-optional-chaining/test/fixtures/general/parenthesized-member-call-loose/exec.js new file mode 100644 index 000000000000..0e0cb2055604 --- /dev/null +++ b/packages/babel-plugin-proposal-optional-chaining/test/fixtures/general/parenthesized-member-call-loose/exec.js @@ -0,0 +1,38 @@ +class Foo { + constructor() { + this.x = 1; + this.self = this; + } + m() { return this.x; }; + getSelf() { return this } + + test() { + const Foo = this; + const o = { Foo: Foo }; + + expect((Foo?.["m"])()).toEqual(1); + expect((Foo?.["m"])().toString).toEqual(1..toString); + expect((Foo?.["m"])().toString()).toEqual('1'); + + expect((o?.Foo.m)()).toEqual(1); + expect((o?.Foo.m)().toString).toEqual(1..toString); + expect((o?.Foo.m)().toString()).toEqual('1'); + + expect((((o.Foo?.self.getSelf)())?.m)()).toEqual(1); + expect((((o.Foo.self?.getSelf)())?.m)()).toEqual(1); + } + + testNull() { + const o = null; + + expect(() => { (o?.Foo.m)() }).toThrow(); + expect(() => { (o?.Foo.m)().toString }).toThrow(); + expect(() => { (o?.Foo.m)().toString() }).toThrow(); + + expect(() => { (((o.Foo?.self.getSelf)())?.m)() }).toThrow(); + expect(() => { (((o.Foo.self?.getSelf)())?.m)() }).toThrow(); + } +} + +(new Foo).test(); +(new Foo).testNull(); diff --git a/packages/babel-plugin-proposal-optional-chaining/test/fixtures/general/parenthesized-member-call-loose/input.js b/packages/babel-plugin-proposal-optional-chaining/test/fixtures/general/parenthesized-member-call-loose/input.js new file mode 100644 index 000000000000..1bdce5676802 --- /dev/null +++ b/packages/babel-plugin-proposal-optional-chaining/test/fixtures/general/parenthesized-member-call-loose/input.js @@ -0,0 +1,26 @@ +class Foo { + constructor() { + this.x = 1; + this.self = this; + } + m() { return this.x; }; + getSelf() { return this } + + test() { + const Foo = this; + const o = { Foo: Foo }; + + (Foo?.["m"])(); + (Foo?.["m"])().toString; + (Foo?.["m"])().toString(); + + (o?.Foo.m)(); + (o?.Foo.m)().toString; + (o?.Foo.m)().toString(); + + (((o.Foo?.self.getSelf)())?.m)(); + (((o.Foo.self?.getSelf)())?.m)(); + } +} + +(new Foo).test(); diff --git a/packages/babel-plugin-proposal-optional-chaining/test/fixtures/general/parenthesized-member-call-loose/options.json b/packages/babel-plugin-proposal-optional-chaining/test/fixtures/general/parenthesized-member-call-loose/options.json new file mode 100644 index 000000000000..39ea3f99c7ff --- /dev/null +++ b/packages/babel-plugin-proposal-optional-chaining/test/fixtures/general/parenthesized-member-call-loose/options.json @@ -0,0 +1,3 @@ +{ + "plugins": [["proposal-optional-chaining", { "loose": true }]] +} diff --git a/packages/babel-plugin-proposal-optional-chaining/test/fixtures/general/parenthesized-member-call-loose/output.js b/packages/babel-plugin-proposal-optional-chaining/test/fixtures/general/parenthesized-member-call-loose/output.js new file mode 100644 index 000000000000..3f79a4007881 --- /dev/null +++ b/packages/babel-plugin-proposal-optional-chaining/test/fixtures/general/parenthesized-member-call-loose/output.js @@ -0,0 +1,34 @@ +class Foo { + constructor() { + this.x = 1; + this.self = this; + } + + m() { + return this.x; + } + + getSelf() { + return this; + } + + test() { + var _o$Foo$self$getSelf, _o$Foo, _o$Foo$self$getSelf2, _o$Foo$self; + + const Foo = this; + const o = { + Foo: Foo + }; + (Foo == null ? void 0 : Foo["m"].bind(Foo))(); + (Foo == null ? void 0 : Foo["m"].bind(Foo))().toString; + (Foo == null ? void 0 : Foo["m"].bind(Foo))().toString(); + (o == null ? void 0 : o.Foo.m.bind(o.Foo))(); + (o == null ? void 0 : o.Foo.m.bind(o.Foo))().toString; + (o == null ? void 0 : o.Foo.m.bind(o.Foo))().toString(); + ((_o$Foo$self$getSelf = ((_o$Foo = o.Foo) == null ? void 0 : _o$Foo.self.getSelf.bind(_o$Foo.self))()) == null ? void 0 : _o$Foo$self$getSelf.m.bind(_o$Foo$self$getSelf))(); + ((_o$Foo$self$getSelf2 = ((_o$Foo$self = o.Foo.self) == null ? void 0 : _o$Foo$self.getSelf.bind(_o$Foo$self))()) == null ? void 0 : _o$Foo$self$getSelf2.m.bind(_o$Foo$self$getSelf2))(); + } + +} + +new Foo().test(); diff --git a/packages/babel-plugin-proposal-optional-chaining/test/fixtures/general/parenthesized-member-call/exec.js b/packages/babel-plugin-proposal-optional-chaining/test/fixtures/general/parenthesized-member-call/exec.js index bfb53e693b08..0e0cb2055604 100644 --- a/packages/babel-plugin-proposal-optional-chaining/test/fixtures/general/parenthesized-member-call/exec.js +++ b/packages/babel-plugin-proposal-optional-chaining/test/fixtures/general/parenthesized-member-call/exec.js @@ -9,13 +9,6 @@ class Foo { test() { const Foo = this; const o = { Foo: Foo }; - const deep = { very: { o } }; - function fn() { - return o; - } - function fnDeep() { - return deep; - } expect((Foo?.["m"])()).toEqual(1); expect((Foo?.["m"])().toString).toEqual(1..toString); From bd78255ac2dc7f38d457fba1cb2deb8057f43948 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hu=C3=A1ng=20J=C3=B9nli=C3=A0ng?= Date: Wed, 27 May 2020 21:19:42 -0400 Subject: [PATCH 08/12] add `(a?.#b)()` support --- .../src/fields.js | 14 ++++++ .../src/index.js | 6 +++ .../exec.js | 36 ++++++++++++++ .../input.js | 24 +++++++++ .../options.json | 8 +++ .../output.js | 49 +++++++++++++++++++ .../exec.js | 36 ++++++++++++++ .../input.js | 24 +++++++++ .../options.json | 8 +++ .../output.js | 45 +++++++++++++++++ 10 files changed, 250 insertions(+) create mode 100644 packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/parenthesized-optional-member-call/exec.js create mode 100644 packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/parenthesized-optional-member-call/input.js create mode 100644 packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/parenthesized-optional-member-call/options.json create mode 100644 packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/parenthesized-optional-member-call/output.js create mode 100644 packages/babel-plugin-proposal-class-properties/test/fixtures/private/parenthesized-optional-member-call/exec.js create mode 100644 packages/babel-plugin-proposal-class-properties/test/fixtures/private/parenthesized-optional-member-call/input.js create mode 100644 packages/babel-plugin-proposal-class-properties/test/fixtures/private/parenthesized-optional-member-call/options.json create mode 100644 packages/babel-plugin-proposal-class-properties/test/fixtures/private/parenthesized-optional-member-call/output.js diff --git a/packages/babel-helper-create-class-features-plugin/src/fields.js b/packages/babel-helper-create-class-features-plugin/src/fields.js index 76bc96b6d662..6e5062ea698a 100644 --- a/packages/babel-helper-create-class-features-plugin/src/fields.js +++ b/packages/babel-helper-create-class-features-plugin/src/fields.js @@ -241,6 +241,13 @@ const privateNameHandlerSpec = { ]); }, + boundGet(member) { + return t.callExpression( + t.memberExpression(this.get(member), t.identifier("bind")), + [this.receiver(member)], + ); + }, + set(member, value) { const { classRef, privateNamesMap, file } = this; const { name } = member.node.property.id; @@ -323,6 +330,13 @@ const privateNameHandlerLoose = { }); }, + boundGet(member) { + return t.callExpression( + t.memberExpression(this.get(member), t.identifier("bind")), + [member.node.object], + ); + }, + simpleSet(member) { return this.get(member); }, diff --git a/packages/babel-helper-member-expression-to-functions/src/index.js b/packages/babel-helper-member-expression-to-functions/src/index.js index 67d3621debc6..1d8114a94d85 100644 --- a/packages/babel-helper-member-expression-to-functions/src/index.js +++ b/packages/babel-helper-member-expression-to-functions/src/index.js @@ -167,6 +167,9 @@ const handle = { const parentIsOptionalCall = parentPath.isOptionalCallExpression({ callee: node, }); + const isParenthesizedMemberCall = + parentPath.isCallExpression({ callee: node }) && + node.extra?.parenthesized; startingOptional.replaceWith(toNonOptional(startingOptional, baseRef)); if (parentIsOptionalCall) { if (parent.optional) { @@ -174,6 +177,9 @@ const handle = { } else { parentPath.replaceWith(this.call(member, parent.arguments)); } + } else if (isParenthesizedMemberCall) { + // `(a?.#b)()` to `(a == null ? void 0 : a.#b.bind(a))()` + member.replaceWith(this.boundGet(member)); } else { member.replaceWith(this.get(member)); } diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/parenthesized-optional-member-call/exec.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/parenthesized-optional-member-call/exec.js new file mode 100644 index 000000000000..a6fb131dbd3f --- /dev/null +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/parenthesized-optional-member-call/exec.js @@ -0,0 +1,36 @@ +class Foo { + static #x = 1; + + static self = Foo; + static #m = function() { return this.#x; }; + static getSelf() { return Foo } + + test() { + const o = { Foo: Foo }; + + expect((Foo?.#m)()).toEqual(1); + expect((Foo?.#m)().toString).toEqual(1..toString); + expect((Foo?.#m)().toString()).toEqual('1'); + + expect((o?.Foo.#m)()).toEqual(1); + expect((o?.Foo.#m)().toString).toEqual(1..toString); + expect((o?.Foo.#m)().toString()).toEqual('1'); + + expect((((o.Foo?.self.getSelf)())?.#m)()).toEqual(1); + expect((((o.Foo.self?.getSelf)())?.#m)()).toEqual(1); + } + + testNull() { + const o = null; + + expect(() => { (o?.Foo.#m)() }).toThrow(); + expect(() => { (o?.Foo.#m)().toString }).toThrow(); + expect(() => { (o?.Foo.#m)().toString() }).toThrow(); + + expect(() => { (((o.Foo?.self.getSelf)())?.#m)() }).toThrow(); + expect(() => { (((o.Foo.self?.getSelf)())?.#m)() }).toThrow(); + } +} + +(new Foo).test(); +(new Foo).testNull(); diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/parenthesized-optional-member-call/input.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/parenthesized-optional-member-call/input.js new file mode 100644 index 000000000000..a2231680adfa --- /dev/null +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/parenthesized-optional-member-call/input.js @@ -0,0 +1,24 @@ +class Foo { + static #x = 1; + + static self = Foo; + static #m = function() { return this.#x; }; + static getSelf() { return Foo } + + test() { + const o = { Foo: Foo }; + + (Foo?.#m)(); + (Foo?.#m)().toString; + (Foo?.#m)().toString(); + + (o?.Foo.#m)(); + (o?.Foo.#m)().toString; + (o?.Foo.#m)().toString(); + + (((o.Foo?.self.getSelf)())?.#m)(); + (((o.Foo.self?.getSelf)())?.#m)(); + } +} + +(new Foo).test(); diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/parenthesized-optional-member-call/options.json b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/parenthesized-optional-member-call/options.json new file mode 100644 index 000000000000..5ef7bf85a640 --- /dev/null +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/parenthesized-optional-member-call/options.json @@ -0,0 +1,8 @@ +{ + "plugins": [ + ["external-helpers", { "helperVersion": "7.100.0" }], + ["proposal-class-properties", { "loose": true }], + "transform-classes", + "transform-block-scoping" + ] +} diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/parenthesized-optional-member-call/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/parenthesized-optional-member-call/output.js new file mode 100644 index 000000000000..2732e841ac91 --- /dev/null +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/parenthesized-optional-member-call/output.js @@ -0,0 +1,49 @@ +var Foo = /*#__PURE__*/function () { + "use strict"; + + function Foo() { + babelHelpers.classCallCheck(this, Foo); + } + + babelHelpers.createClass(Foo, [{ + key: "test", + value: function test() { + var _o$Foo$self$getSelf, _o$Foo$self$getSelf2; + + var o = { + Foo: Foo + }; + (Foo === null || Foo === void 0 ? void 0 : babelHelpers.classPrivateFieldLooseBase(Foo, _m)[_m].bind(Foo))(); + (Foo === null || Foo === void 0 ? void 0 : babelHelpers.classPrivateFieldLooseBase(Foo, _m)[_m].bind(Foo))().toString; + (Foo === null || Foo === void 0 ? void 0 : babelHelpers.classPrivateFieldLooseBase(Foo, _m)[_m].bind(Foo))().toString(); + (o === null || o === void 0 ? void 0 : babelHelpers.classPrivateFieldLooseBase(o.Foo, _m)[_m].bind(o.Foo))(); + (o === null || o === void 0 ? void 0 : babelHelpers.classPrivateFieldLooseBase(o.Foo, _m)[_m].bind(o.Foo))().toString; + (o === null || o === void 0 ? void 0 : babelHelpers.classPrivateFieldLooseBase(o.Foo, _m)[_m].bind(o.Foo))().toString(); + ((_o$Foo$self$getSelf = (o.Foo?.self.getSelf)()) === null || _o$Foo$self$getSelf === void 0 ? void 0 : babelHelpers.classPrivateFieldLooseBase(_o$Foo$self$getSelf, _m)[_m].bind(_o$Foo$self$getSelf))(); + ((_o$Foo$self$getSelf2 = (o.Foo.self?.getSelf)()) === null || _o$Foo$self$getSelf2 === void 0 ? void 0 : babelHelpers.classPrivateFieldLooseBase(_o$Foo$self$getSelf2, _m)[_m].bind(_o$Foo$self$getSelf2))(); + } + }], [{ + key: "getSelf", + value: function getSelf() { + return Foo; + } + }]); + return Foo; +}(); + +var _x = babelHelpers.classPrivateFieldLooseKey("x"); + +var _m = babelHelpers.classPrivateFieldLooseKey("m"); + +Object.defineProperty(Foo, _x, { + writable: true, + value: 1 +}); +Foo.self = Foo; +Object.defineProperty(Foo, _m, { + writable: true, + value: function () { + return babelHelpers.classPrivateFieldLooseBase(this, _x)[_x]; + } +}); +new Foo().test(); diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/parenthesized-optional-member-call/exec.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/parenthesized-optional-member-call/exec.js new file mode 100644 index 000000000000..a6fb131dbd3f --- /dev/null +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/parenthesized-optional-member-call/exec.js @@ -0,0 +1,36 @@ +class Foo { + static #x = 1; + + static self = Foo; + static #m = function() { return this.#x; }; + static getSelf() { return Foo } + + test() { + const o = { Foo: Foo }; + + expect((Foo?.#m)()).toEqual(1); + expect((Foo?.#m)().toString).toEqual(1..toString); + expect((Foo?.#m)().toString()).toEqual('1'); + + expect((o?.Foo.#m)()).toEqual(1); + expect((o?.Foo.#m)().toString).toEqual(1..toString); + expect((o?.Foo.#m)().toString()).toEqual('1'); + + expect((((o.Foo?.self.getSelf)())?.#m)()).toEqual(1); + expect((((o.Foo.self?.getSelf)())?.#m)()).toEqual(1); + } + + testNull() { + const o = null; + + expect(() => { (o?.Foo.#m)() }).toThrow(); + expect(() => { (o?.Foo.#m)().toString }).toThrow(); + expect(() => { (o?.Foo.#m)().toString() }).toThrow(); + + expect(() => { (((o.Foo?.self.getSelf)())?.#m)() }).toThrow(); + expect(() => { (((o.Foo.self?.getSelf)())?.#m)() }).toThrow(); + } +} + +(new Foo).test(); +(new Foo).testNull(); diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/parenthesized-optional-member-call/input.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/parenthesized-optional-member-call/input.js new file mode 100644 index 000000000000..a2231680adfa --- /dev/null +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/parenthesized-optional-member-call/input.js @@ -0,0 +1,24 @@ +class Foo { + static #x = 1; + + static self = Foo; + static #m = function() { return this.#x; }; + static getSelf() { return Foo } + + test() { + const o = { Foo: Foo }; + + (Foo?.#m)(); + (Foo?.#m)().toString; + (Foo?.#m)().toString(); + + (o?.Foo.#m)(); + (o?.Foo.#m)().toString; + (o?.Foo.#m)().toString(); + + (((o.Foo?.self.getSelf)())?.#m)(); + (((o.Foo.self?.getSelf)())?.#m)(); + } +} + +(new Foo).test(); diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/parenthesized-optional-member-call/options.json b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/parenthesized-optional-member-call/options.json new file mode 100644 index 000000000000..2b19921774d7 --- /dev/null +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/parenthesized-optional-member-call/options.json @@ -0,0 +1,8 @@ +{ + "plugins": [ + ["external-helpers", { "helperVersion": "7.100.0" }], + "proposal-class-properties", + "transform-classes", + "transform-block-scoping" + ] +} diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/parenthesized-optional-member-call/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/parenthesized-optional-member-call/output.js new file mode 100644 index 000000000000..4965554f479e --- /dev/null +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/parenthesized-optional-member-call/output.js @@ -0,0 +1,45 @@ +var Foo = /*#__PURE__*/function () { + "use strict"; + + function Foo() { + babelHelpers.classCallCheck(this, Foo); + } + + babelHelpers.createClass(Foo, [{ + key: "test", + value: function test() { + var _o$Foo$self$getSelf, _o$Foo$self$getSelf2; + + var o = { + Foo: Foo + }; + (Foo === null || Foo === void 0 ? void 0 : babelHelpers.classStaticPrivateFieldSpecGet(Foo, Foo, _m).bind(Foo))(); + (Foo === null || Foo === void 0 ? void 0 : babelHelpers.classStaticPrivateFieldSpecGet(Foo, Foo, _m).bind(Foo))().toString; + (Foo === null || Foo === void 0 ? void 0 : babelHelpers.classStaticPrivateFieldSpecGet(Foo, Foo, _m).bind(Foo))().toString(); + (o === null || o === void 0 ? void 0 : babelHelpers.classStaticPrivateFieldSpecGet(o.Foo, Foo, _m).bind(o.Foo))(); + (o === null || o === void 0 ? void 0 : babelHelpers.classStaticPrivateFieldSpecGet(o.Foo, Foo, _m).bind(o.Foo))().toString; + (o === null || o === void 0 ? void 0 : babelHelpers.classStaticPrivateFieldSpecGet(o.Foo, Foo, _m).bind(o.Foo))().toString(); + ((_o$Foo$self$getSelf = (o.Foo?.self.getSelf)()) === null || _o$Foo$self$getSelf === void 0 ? void 0 : babelHelpers.classStaticPrivateFieldSpecGet(_o$Foo$self$getSelf, Foo, _m).bind(_o$Foo$self$getSelf))(); + ((_o$Foo$self$getSelf2 = (o.Foo.self?.getSelf)()) === null || _o$Foo$self$getSelf2 === void 0 ? void 0 : babelHelpers.classStaticPrivateFieldSpecGet(_o$Foo$self$getSelf2, Foo, _m).bind(_o$Foo$self$getSelf2))(); + } + }], [{ + key: "getSelf", + value: function getSelf() { + return Foo; + } + }]); + return Foo; +}(); + +var _x = { + writable: true, + value: 1 +}; +babelHelpers.defineProperty(Foo, "self", Foo); +var _m = { + writable: true, + value: function () { + return babelHelpers.classStaticPrivateFieldSpecGet(this, Foo, _x); + } +}; +new Foo().test(); From 7691248433caca89e247d876238e0f4fbc67dd32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hu=C3=A1ng=20J=C3=B9nli=C3=A0ng?= Date: Wed, 27 May 2020 22:39:23 -0400 Subject: [PATCH 09/12] add with-transform test cases --- .../exec.js | 36 +++++++++++ .../input.js | 24 +++++++ .../options.json | 7 +++ .../output.js | 39 ++++++++++++ .../options.json | 7 +-- .../output.js | 62 +++++++------------ .../exec.js | 36 +++++++++++ .../input.js | 24 +++++++ .../options.json | 7 +++ .../output.js | 35 +++++++++++ .../options.json | 7 +-- .../output.js | 48 ++++++-------- 12 files changed, 257 insertions(+), 75 deletions(-) create mode 100644 packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/parenthesized-optional-member-call-with-transform/exec.js create mode 100644 packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/parenthesized-optional-member-call-with-transform/input.js create mode 100644 packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/parenthesized-optional-member-call-with-transform/options.json create mode 100644 packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/parenthesized-optional-member-call-with-transform/output.js create mode 100644 packages/babel-plugin-proposal-class-properties/test/fixtures/private/parenthesized-optional-member-call-with-transform/exec.js create mode 100644 packages/babel-plugin-proposal-class-properties/test/fixtures/private/parenthesized-optional-member-call-with-transform/input.js create mode 100644 packages/babel-plugin-proposal-class-properties/test/fixtures/private/parenthesized-optional-member-call-with-transform/options.json create mode 100644 packages/babel-plugin-proposal-class-properties/test/fixtures/private/parenthesized-optional-member-call-with-transform/output.js diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/parenthesized-optional-member-call-with-transform/exec.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/parenthesized-optional-member-call-with-transform/exec.js new file mode 100644 index 000000000000..a6fb131dbd3f --- /dev/null +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/parenthesized-optional-member-call-with-transform/exec.js @@ -0,0 +1,36 @@ +class Foo { + static #x = 1; + + static self = Foo; + static #m = function() { return this.#x; }; + static getSelf() { return Foo } + + test() { + const o = { Foo: Foo }; + + expect((Foo?.#m)()).toEqual(1); + expect((Foo?.#m)().toString).toEqual(1..toString); + expect((Foo?.#m)().toString()).toEqual('1'); + + expect((o?.Foo.#m)()).toEqual(1); + expect((o?.Foo.#m)().toString).toEqual(1..toString); + expect((o?.Foo.#m)().toString()).toEqual('1'); + + expect((((o.Foo?.self.getSelf)())?.#m)()).toEqual(1); + expect((((o.Foo.self?.getSelf)())?.#m)()).toEqual(1); + } + + testNull() { + const o = null; + + expect(() => { (o?.Foo.#m)() }).toThrow(); + expect(() => { (o?.Foo.#m)().toString }).toThrow(); + expect(() => { (o?.Foo.#m)().toString() }).toThrow(); + + expect(() => { (((o.Foo?.self.getSelf)())?.#m)() }).toThrow(); + expect(() => { (((o.Foo.self?.getSelf)())?.#m)() }).toThrow(); + } +} + +(new Foo).test(); +(new Foo).testNull(); diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/parenthesized-optional-member-call-with-transform/input.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/parenthesized-optional-member-call-with-transform/input.js new file mode 100644 index 000000000000..a2231680adfa --- /dev/null +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/parenthesized-optional-member-call-with-transform/input.js @@ -0,0 +1,24 @@ +class Foo { + static #x = 1; + + static self = Foo; + static #m = function() { return this.#x; }; + static getSelf() { return Foo } + + test() { + const o = { Foo: Foo }; + + (Foo?.#m)(); + (Foo?.#m)().toString; + (Foo?.#m)().toString(); + + (o?.Foo.#m)(); + (o?.Foo.#m)().toString; + (o?.Foo.#m)().toString(); + + (((o.Foo?.self.getSelf)())?.#m)(); + (((o.Foo.self?.getSelf)())?.#m)(); + } +} + +(new Foo).test(); diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/parenthesized-optional-member-call-with-transform/options.json b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/parenthesized-optional-member-call-with-transform/options.json new file mode 100644 index 000000000000..14f4e86be551 --- /dev/null +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/parenthesized-optional-member-call-with-transform/options.json @@ -0,0 +1,7 @@ +{ + "plugins": [ + ["external-helpers", { "helperVersion": "7.100.0" }], + ["proposal-class-properties", { "loose": true }], + ["proposal-optional-chaining", { "loose": true }] + ] +} diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/parenthesized-optional-member-call-with-transform/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/parenthesized-optional-member-call-with-transform/output.js new file mode 100644 index 000000000000..811bbc1bbfae --- /dev/null +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/parenthesized-optional-member-call-with-transform/output.js @@ -0,0 +1,39 @@ +class Foo { + static getSelf() { + return Foo; + } + + test() { + var _o$Foo$self$getSelf, _o$Foo$self$getSelf2, _o$Foo, _o$Foo$self; + + const o = { + Foo: Foo + }; + (Foo === null || Foo === void 0 ? void 0 : babelHelpers.classPrivateFieldLooseBase(Foo, _m)[_m].bind(Foo))(); + (Foo === null || Foo === void 0 ? void 0 : babelHelpers.classPrivateFieldLooseBase(Foo, _m)[_m].bind(Foo))().toString; + (Foo === null || Foo === void 0 ? void 0 : babelHelpers.classPrivateFieldLooseBase(Foo, _m)[_m].bind(Foo))().toString(); + (o === null || o === void 0 ? void 0 : babelHelpers.classPrivateFieldLooseBase(o.Foo, _m)[_m].bind(o.Foo))(); + (o === null || o === void 0 ? void 0 : babelHelpers.classPrivateFieldLooseBase(o.Foo, _m)[_m].bind(o.Foo))().toString; + (o === null || o === void 0 ? void 0 : babelHelpers.classPrivateFieldLooseBase(o.Foo, _m)[_m].bind(o.Foo))().toString(); + ((_o$Foo$self$getSelf = ((_o$Foo = o.Foo) == null ? void 0 : _o$Foo.self.getSelf.bind(_o$Foo.self))()) === null || _o$Foo$self$getSelf === void 0 ? void 0 : babelHelpers.classPrivateFieldLooseBase(_o$Foo$self$getSelf, _m)[_m].bind(_o$Foo$self$getSelf))(); + ((_o$Foo$self$getSelf2 = ((_o$Foo$self = o.Foo.self) == null ? void 0 : _o$Foo$self.getSelf.bind(_o$Foo$self))()) === null || _o$Foo$self$getSelf2 === void 0 ? void 0 : babelHelpers.classPrivateFieldLooseBase(_o$Foo$self$getSelf2, _m)[_m].bind(_o$Foo$self$getSelf2))(); + } + +} + +var _x = babelHelpers.classPrivateFieldLooseKey("x"); + +var _m = babelHelpers.classPrivateFieldLooseKey("m"); + +Object.defineProperty(Foo, _x, { + writable: true, + value: 1 +}); +Foo.self = Foo; +Object.defineProperty(Foo, _m, { + writable: true, + value: function () { + return babelHelpers.classPrivateFieldLooseBase(this, _x)[_x]; + } +}); +new Foo().test(); diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/parenthesized-optional-member-call/options.json b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/parenthesized-optional-member-call/options.json index 5ef7bf85a640..88c37f66eeb8 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/parenthesized-optional-member-call/options.json +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/parenthesized-optional-member-call/options.json @@ -1,8 +1,7 @@ { "plugins": [ ["external-helpers", { "helperVersion": "7.100.0" }], - ["proposal-class-properties", { "loose": true }], - "transform-classes", - "transform-block-scoping" - ] + "proposal-class-properties" + ], + "minNodeVersion": "14.0.0" } diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/parenthesized-optional-member-call/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/parenthesized-optional-member-call/output.js index 2732e841ac91..c72d057815f7 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/parenthesized-optional-member-call/output.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/parenthesized-optional-member-call/output.js @@ -1,49 +1,35 @@ -var Foo = /*#__PURE__*/function () { - "use strict"; - - function Foo() { - babelHelpers.classCallCheck(this, Foo); +class Foo { + static getSelf() { + return Foo; } - babelHelpers.createClass(Foo, [{ - key: "test", - value: function test() { - var _o$Foo$self$getSelf, _o$Foo$self$getSelf2; - - var o = { - Foo: Foo - }; - (Foo === null || Foo === void 0 ? void 0 : babelHelpers.classPrivateFieldLooseBase(Foo, _m)[_m].bind(Foo))(); - (Foo === null || Foo === void 0 ? void 0 : babelHelpers.classPrivateFieldLooseBase(Foo, _m)[_m].bind(Foo))().toString; - (Foo === null || Foo === void 0 ? void 0 : babelHelpers.classPrivateFieldLooseBase(Foo, _m)[_m].bind(Foo))().toString(); - (o === null || o === void 0 ? void 0 : babelHelpers.classPrivateFieldLooseBase(o.Foo, _m)[_m].bind(o.Foo))(); - (o === null || o === void 0 ? void 0 : babelHelpers.classPrivateFieldLooseBase(o.Foo, _m)[_m].bind(o.Foo))().toString; - (o === null || o === void 0 ? void 0 : babelHelpers.classPrivateFieldLooseBase(o.Foo, _m)[_m].bind(o.Foo))().toString(); - ((_o$Foo$self$getSelf = (o.Foo?.self.getSelf)()) === null || _o$Foo$self$getSelf === void 0 ? void 0 : babelHelpers.classPrivateFieldLooseBase(_o$Foo$self$getSelf, _m)[_m].bind(_o$Foo$self$getSelf))(); - ((_o$Foo$self$getSelf2 = (o.Foo.self?.getSelf)()) === null || _o$Foo$self$getSelf2 === void 0 ? void 0 : babelHelpers.classPrivateFieldLooseBase(_o$Foo$self$getSelf2, _m)[_m].bind(_o$Foo$self$getSelf2))(); - } - }], [{ - key: "getSelf", - value: function getSelf() { - return Foo; - } - }]); - return Foo; -}(); + test() { + var _o$Foo$self$getSelf, _o$Foo$self$getSelf2; -var _x = babelHelpers.classPrivateFieldLooseKey("x"); + const o = { + Foo: Foo + }; + (Foo === null || Foo === void 0 ? void 0 : babelHelpers.classStaticPrivateFieldSpecGet(Foo, Foo, _m).bind(Foo))(); + (Foo === null || Foo === void 0 ? void 0 : babelHelpers.classStaticPrivateFieldSpecGet(Foo, Foo, _m).bind(Foo))().toString; + (Foo === null || Foo === void 0 ? void 0 : babelHelpers.classStaticPrivateFieldSpecGet(Foo, Foo, _m).bind(Foo))().toString(); + (o === null || o === void 0 ? void 0 : babelHelpers.classStaticPrivateFieldSpecGet(o.Foo, Foo, _m).bind(o.Foo))(); + (o === null || o === void 0 ? void 0 : babelHelpers.classStaticPrivateFieldSpecGet(o.Foo, Foo, _m).bind(o.Foo))().toString; + (o === null || o === void 0 ? void 0 : babelHelpers.classStaticPrivateFieldSpecGet(o.Foo, Foo, _m).bind(o.Foo))().toString(); + ((_o$Foo$self$getSelf = (o.Foo?.self.getSelf)()) === null || _o$Foo$self$getSelf === void 0 ? void 0 : babelHelpers.classStaticPrivateFieldSpecGet(_o$Foo$self$getSelf, Foo, _m).bind(_o$Foo$self$getSelf))(); + ((_o$Foo$self$getSelf2 = (o.Foo.self?.getSelf)()) === null || _o$Foo$self$getSelf2 === void 0 ? void 0 : babelHelpers.classStaticPrivateFieldSpecGet(_o$Foo$self$getSelf2, Foo, _m).bind(_o$Foo$self$getSelf2))(); + } -var _m = babelHelpers.classPrivateFieldLooseKey("m"); +} -Object.defineProperty(Foo, _x, { +var _x = { writable: true, value: 1 -}); -Foo.self = Foo; -Object.defineProperty(Foo, _m, { +}; +babelHelpers.defineProperty(Foo, "self", Foo); +var _m = { writable: true, value: function () { - return babelHelpers.classPrivateFieldLooseBase(this, _x)[_x]; + return babelHelpers.classStaticPrivateFieldSpecGet(this, Foo, _x); } -}); +}; new Foo().test(); diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/parenthesized-optional-member-call-with-transform/exec.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/parenthesized-optional-member-call-with-transform/exec.js new file mode 100644 index 000000000000..a6fb131dbd3f --- /dev/null +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/parenthesized-optional-member-call-with-transform/exec.js @@ -0,0 +1,36 @@ +class Foo { + static #x = 1; + + static self = Foo; + static #m = function() { return this.#x; }; + static getSelf() { return Foo } + + test() { + const o = { Foo: Foo }; + + expect((Foo?.#m)()).toEqual(1); + expect((Foo?.#m)().toString).toEqual(1..toString); + expect((Foo?.#m)().toString()).toEqual('1'); + + expect((o?.Foo.#m)()).toEqual(1); + expect((o?.Foo.#m)().toString).toEqual(1..toString); + expect((o?.Foo.#m)().toString()).toEqual('1'); + + expect((((o.Foo?.self.getSelf)())?.#m)()).toEqual(1); + expect((((o.Foo.self?.getSelf)())?.#m)()).toEqual(1); + } + + testNull() { + const o = null; + + expect(() => { (o?.Foo.#m)() }).toThrow(); + expect(() => { (o?.Foo.#m)().toString }).toThrow(); + expect(() => { (o?.Foo.#m)().toString() }).toThrow(); + + expect(() => { (((o.Foo?.self.getSelf)())?.#m)() }).toThrow(); + expect(() => { (((o.Foo.self?.getSelf)())?.#m)() }).toThrow(); + } +} + +(new Foo).test(); +(new Foo).testNull(); diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/parenthesized-optional-member-call-with-transform/input.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/parenthesized-optional-member-call-with-transform/input.js new file mode 100644 index 000000000000..a2231680adfa --- /dev/null +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/parenthesized-optional-member-call-with-transform/input.js @@ -0,0 +1,24 @@ +class Foo { + static #x = 1; + + static self = Foo; + static #m = function() { return this.#x; }; + static getSelf() { return Foo } + + test() { + const o = { Foo: Foo }; + + (Foo?.#m)(); + (Foo?.#m)().toString; + (Foo?.#m)().toString(); + + (o?.Foo.#m)(); + (o?.Foo.#m)().toString; + (o?.Foo.#m)().toString(); + + (((o.Foo?.self.getSelf)())?.#m)(); + (((o.Foo.self?.getSelf)())?.#m)(); + } +} + +(new Foo).test(); diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/parenthesized-optional-member-call-with-transform/options.json b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/parenthesized-optional-member-call-with-transform/options.json new file mode 100644 index 000000000000..6dbfa5c4c844 --- /dev/null +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/parenthesized-optional-member-call-with-transform/options.json @@ -0,0 +1,7 @@ +{ + "plugins": [ + ["external-helpers", { "helperVersion": "7.100.0" }], + "proposal-class-properties", + "proposal-optional-chaining" + ] +} diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/parenthesized-optional-member-call-with-transform/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/parenthesized-optional-member-call-with-transform/output.js new file mode 100644 index 000000000000..4cbdb0f7dc58 --- /dev/null +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/parenthesized-optional-member-call-with-transform/output.js @@ -0,0 +1,35 @@ +class Foo { + static getSelf() { + return Foo; + } + + test() { + var _o$Foo$self$getSelf, _o$Foo$self$getSelf2, _o$Foo, _o$Foo$self, _o$Foo$self2; + + const o = { + Foo: Foo + }; + (Foo === null || Foo === void 0 ? void 0 : babelHelpers.classStaticPrivateFieldSpecGet(Foo, Foo, _m).bind(Foo))(); + (Foo === null || Foo === void 0 ? void 0 : babelHelpers.classStaticPrivateFieldSpecGet(Foo, Foo, _m).bind(Foo))().toString; + (Foo === null || Foo === void 0 ? void 0 : babelHelpers.classStaticPrivateFieldSpecGet(Foo, Foo, _m).bind(Foo))().toString(); + (o === null || o === void 0 ? void 0 : babelHelpers.classStaticPrivateFieldSpecGet(o.Foo, Foo, _m).bind(o.Foo))(); + (o === null || o === void 0 ? void 0 : babelHelpers.classStaticPrivateFieldSpecGet(o.Foo, Foo, _m).bind(o.Foo))().toString; + (o === null || o === void 0 ? void 0 : babelHelpers.classStaticPrivateFieldSpecGet(o.Foo, Foo, _m).bind(o.Foo))().toString(); + ((_o$Foo$self$getSelf = ((_o$Foo = o.Foo) === null || _o$Foo === void 0 ? void 0 : (_o$Foo$self = _o$Foo.self).getSelf.bind(_o$Foo$self))()) === null || _o$Foo$self$getSelf === void 0 ? void 0 : babelHelpers.classStaticPrivateFieldSpecGet(_o$Foo$self$getSelf, Foo, _m).bind(_o$Foo$self$getSelf))(); + ((_o$Foo$self$getSelf2 = ((_o$Foo$self2 = o.Foo.self) === null || _o$Foo$self2 === void 0 ? void 0 : _o$Foo$self2.getSelf.bind(_o$Foo$self2))()) === null || _o$Foo$self$getSelf2 === void 0 ? void 0 : babelHelpers.classStaticPrivateFieldSpecGet(_o$Foo$self$getSelf2, Foo, _m).bind(_o$Foo$self$getSelf2))(); + } + +} + +var _x = { + writable: true, + value: 1 +}; +babelHelpers.defineProperty(Foo, "self", Foo); +var _m = { + writable: true, + value: function () { + return babelHelpers.classStaticPrivateFieldSpecGet(this, Foo, _x); + } +}; +new Foo().test(); diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/parenthesized-optional-member-call/options.json b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/parenthesized-optional-member-call/options.json index 2b19921774d7..88c37f66eeb8 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/parenthesized-optional-member-call/options.json +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/parenthesized-optional-member-call/options.json @@ -1,8 +1,7 @@ { "plugins": [ ["external-helpers", { "helperVersion": "7.100.0" }], - "proposal-class-properties", - "transform-classes", - "transform-block-scoping" - ] + "proposal-class-properties" + ], + "minNodeVersion": "14.0.0" } diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/parenthesized-optional-member-call/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/parenthesized-optional-member-call/output.js index 4965554f479e..c72d057815f7 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/parenthesized-optional-member-call/output.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/parenthesized-optional-member-call/output.js @@ -1,35 +1,25 @@ -var Foo = /*#__PURE__*/function () { - "use strict"; - - function Foo() { - babelHelpers.classCallCheck(this, Foo); +class Foo { + static getSelf() { + return Foo; } - babelHelpers.createClass(Foo, [{ - key: "test", - value: function test() { - var _o$Foo$self$getSelf, _o$Foo$self$getSelf2; + test() { + var _o$Foo$self$getSelf, _o$Foo$self$getSelf2; + + const o = { + Foo: Foo + }; + (Foo === null || Foo === void 0 ? void 0 : babelHelpers.classStaticPrivateFieldSpecGet(Foo, Foo, _m).bind(Foo))(); + (Foo === null || Foo === void 0 ? void 0 : babelHelpers.classStaticPrivateFieldSpecGet(Foo, Foo, _m).bind(Foo))().toString; + (Foo === null || Foo === void 0 ? void 0 : babelHelpers.classStaticPrivateFieldSpecGet(Foo, Foo, _m).bind(Foo))().toString(); + (o === null || o === void 0 ? void 0 : babelHelpers.classStaticPrivateFieldSpecGet(o.Foo, Foo, _m).bind(o.Foo))(); + (o === null || o === void 0 ? void 0 : babelHelpers.classStaticPrivateFieldSpecGet(o.Foo, Foo, _m).bind(o.Foo))().toString; + (o === null || o === void 0 ? void 0 : babelHelpers.classStaticPrivateFieldSpecGet(o.Foo, Foo, _m).bind(o.Foo))().toString(); + ((_o$Foo$self$getSelf = (o.Foo?.self.getSelf)()) === null || _o$Foo$self$getSelf === void 0 ? void 0 : babelHelpers.classStaticPrivateFieldSpecGet(_o$Foo$self$getSelf, Foo, _m).bind(_o$Foo$self$getSelf))(); + ((_o$Foo$self$getSelf2 = (o.Foo.self?.getSelf)()) === null || _o$Foo$self$getSelf2 === void 0 ? void 0 : babelHelpers.classStaticPrivateFieldSpecGet(_o$Foo$self$getSelf2, Foo, _m).bind(_o$Foo$self$getSelf2))(); + } - var o = { - Foo: Foo - }; - (Foo === null || Foo === void 0 ? void 0 : babelHelpers.classStaticPrivateFieldSpecGet(Foo, Foo, _m).bind(Foo))(); - (Foo === null || Foo === void 0 ? void 0 : babelHelpers.classStaticPrivateFieldSpecGet(Foo, Foo, _m).bind(Foo))().toString; - (Foo === null || Foo === void 0 ? void 0 : babelHelpers.classStaticPrivateFieldSpecGet(Foo, Foo, _m).bind(Foo))().toString(); - (o === null || o === void 0 ? void 0 : babelHelpers.classStaticPrivateFieldSpecGet(o.Foo, Foo, _m).bind(o.Foo))(); - (o === null || o === void 0 ? void 0 : babelHelpers.classStaticPrivateFieldSpecGet(o.Foo, Foo, _m).bind(o.Foo))().toString; - (o === null || o === void 0 ? void 0 : babelHelpers.classStaticPrivateFieldSpecGet(o.Foo, Foo, _m).bind(o.Foo))().toString(); - ((_o$Foo$self$getSelf = (o.Foo?.self.getSelf)()) === null || _o$Foo$self$getSelf === void 0 ? void 0 : babelHelpers.classStaticPrivateFieldSpecGet(_o$Foo$self$getSelf, Foo, _m).bind(_o$Foo$self$getSelf))(); - ((_o$Foo$self$getSelf2 = (o.Foo.self?.getSelf)()) === null || _o$Foo$self$getSelf2 === void 0 ? void 0 : babelHelpers.classStaticPrivateFieldSpecGet(_o$Foo$self$getSelf2, Foo, _m).bind(_o$Foo$self$getSelf2))(); - } - }], [{ - key: "getSelf", - value: function getSelf() { - return Foo; - } - }]); - return Foo; -}(); +} var _x = { writable: true, From 0c6759b170ca6d60f4dd2097a14785968261500f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hu=C3=A1ng=20J=C3=B9nli=C3=A0ng?= Date: Fri, 29 May 2020 22:59:04 -0400 Subject: [PATCH 10/12] Update packages/babel-plugin-proposal-optional-chaining/src/index.js Co-authored-by: Justin Ridgewell --- .../babel-plugin-proposal-optional-chaining/src/index.js | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/packages/babel-plugin-proposal-optional-chaining/src/index.js b/packages/babel-plugin-proposal-optional-chaining/src/index.js index cca75eb2c25f..fe21895035dc 100644 --- a/packages/babel-plugin-proposal-optional-chaining/src/index.js +++ b/packages/babel-plugin-proposal-optional-chaining/src/index.js @@ -24,13 +24,7 @@ export default declare((api, options) => { visitor: { "OptionalCallExpression|OptionalMemberExpression"(path) { const { scope } = path; - let parentPath; - // unwrap parenthesis around parent path - for ( - { parentPath } = path; - parentPath.type === "ParenthesizedExpression"; - { parentPath } = parentPath - ); + const parentPath = path.findParent(p => !p.isParenthesizedExpression()); let isDeleteOperation = false; const optionals = []; From 44e02e94c24fe484e4708e8c65d741e739043d37 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hu=C3=A1ng=20J=C3=B9nli=C3=A0ng?= Date: Sat, 30 May 2020 09:10:11 -0400 Subject: [PATCH 11/12] address review comments --- .../src/fields.js | 4 +++- .../exec.js | 12 ++++++++++++ .../input.js | 6 ++++++ .../output.js | 9 ++++++++- .../exec.js | 12 ++++++++++++ .../input.js | 6 ++++++ .../output.js | 15 +++++++++++---- .../exec.js | 12 ++++++++++++ .../input.js | 6 ++++++ .../output.js | 19 +++++++++++++------ .../exec.js | 12 ++++++++++++ .../input.js | 6 ++++++ .../output.js | 15 +++++++++++---- .../src/index.js | 2 +- .../exec.js | 9 +++++++++ .../exec.js | 9 +++++++++ .../parenthesized-member-call-loose/exec.js | 9 +++++++++ .../parenthesized-member-call-loose/input.js | 6 ++++++ .../parenthesized-member-call-loose/output.js | 9 ++++++++- .../general/parenthesized-member-call/exec.js | 9 +++++++++ .../parenthesized-member-call/input.js | 6 ++++++ .../parenthesized-member-call/output.js | 9 ++++++++- 22 files changed, 183 insertions(+), 19 deletions(-) diff --git a/packages/babel-helper-create-class-features-plugin/src/fields.js b/packages/babel-helper-create-class-features-plugin/src/fields.js index 6e5062ea698a..848b0033b675 100644 --- a/packages/babel-helper-create-class-features-plugin/src/fields.js +++ b/packages/babel-helper-create-class-features-plugin/src/fields.js @@ -242,6 +242,8 @@ const privateNameHandlerSpec = { }, boundGet(member) { + this.memoise(member, 1); + return t.callExpression( t.memberExpression(this.get(member), t.identifier("bind")), [this.receiver(member)], @@ -333,7 +335,7 @@ const privateNameHandlerLoose = { boundGet(member) { return t.callExpression( t.memberExpression(this.get(member), t.identifier("bind")), - [member.node.object], + [t.cloneNode(member.node.object)], ); }, diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/parenthesized-optional-member-call-with-transform/exec.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/parenthesized-optional-member-call-with-transform/exec.js index a6fb131dbd3f..ae7bf5d636e3 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/parenthesized-optional-member-call-with-transform/exec.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/parenthesized-optional-member-call-with-transform/exec.js @@ -7,6 +7,9 @@ class Foo { test() { const o = { Foo: Foo }; + const fn = function () { + return o; + }; expect((Foo?.#m)()).toEqual(1); expect((Foo?.#m)().toString).toEqual(1..toString); @@ -18,10 +21,16 @@ class Foo { expect((((o.Foo?.self.getSelf)())?.#m)()).toEqual(1); expect((((o.Foo.self?.getSelf)())?.#m)()).toEqual(1); + + expect((((fn()?.Foo?.self.getSelf)())?.#m)()).toEqual(1); + expect((((fn?.().Foo.self?.getSelf)())?.#m)()).toEqual(1); } testNull() { const o = null; + const fn = function () { + return { o }; + } expect(() => { (o?.Foo.#m)() }).toThrow(); expect(() => { (o?.Foo.#m)().toString }).toThrow(); @@ -29,6 +38,9 @@ class Foo { expect(() => { (((o.Foo?.self.getSelf)())?.#m)() }).toThrow(); expect(() => { (((o.Foo.self?.getSelf)())?.#m)() }).toThrow(); + + expect(() => (((fn()?.Foo?.self.getSelf)())?.#m)()).toThrow(); + expect(() => (((fn?.().Foo.self?.getSelf)())?.#m)()).toThrow(); } } diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/parenthesized-optional-member-call-with-transform/input.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/parenthesized-optional-member-call-with-transform/input.js index a2231680adfa..0d9a4d608b78 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/parenthesized-optional-member-call-with-transform/input.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/parenthesized-optional-member-call-with-transform/input.js @@ -7,6 +7,9 @@ class Foo { test() { const o = { Foo: Foo }; + const fn = function () { + return o; + }; (Foo?.#m)(); (Foo?.#m)().toString; @@ -18,6 +21,9 @@ class Foo { (((o.Foo?.self.getSelf)())?.#m)(); (((o.Foo.self?.getSelf)())?.#m)(); + + (((fn()?.Foo?.self.getSelf)())?.#m)(); + (((fn?.().Foo.self?.getSelf)())?.#m)(); } } diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/parenthesized-optional-member-call-with-transform/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/parenthesized-optional-member-call-with-transform/output.js index 811bbc1bbfae..5987a54474c7 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/parenthesized-optional-member-call-with-transform/output.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/parenthesized-optional-member-call-with-transform/output.js @@ -4,11 +4,16 @@ class Foo { } test() { - var _o$Foo$self$getSelf, _o$Foo$self$getSelf2, _o$Foo, _o$Foo$self; + var _o$Foo$self$getSelf, _o$Foo$self$getSelf2, _fn$Foo$self$getSelf, _fn$Foo$self$getSelf2, _o$Foo, _o$Foo$self, _fn, _fn$Foo, _fn$Foo$self; const o = { Foo: Foo }; + + const fn = function () { + return o; + }; + (Foo === null || Foo === void 0 ? void 0 : babelHelpers.classPrivateFieldLooseBase(Foo, _m)[_m].bind(Foo))(); (Foo === null || Foo === void 0 ? void 0 : babelHelpers.classPrivateFieldLooseBase(Foo, _m)[_m].bind(Foo))().toString; (Foo === null || Foo === void 0 ? void 0 : babelHelpers.classPrivateFieldLooseBase(Foo, _m)[_m].bind(Foo))().toString(); @@ -17,6 +22,8 @@ class Foo { (o === null || o === void 0 ? void 0 : babelHelpers.classPrivateFieldLooseBase(o.Foo, _m)[_m].bind(o.Foo))().toString(); ((_o$Foo$self$getSelf = ((_o$Foo = o.Foo) == null ? void 0 : _o$Foo.self.getSelf.bind(_o$Foo.self))()) === null || _o$Foo$self$getSelf === void 0 ? void 0 : babelHelpers.classPrivateFieldLooseBase(_o$Foo$self$getSelf, _m)[_m].bind(_o$Foo$self$getSelf))(); ((_o$Foo$self$getSelf2 = ((_o$Foo$self = o.Foo.self) == null ? void 0 : _o$Foo$self.getSelf.bind(_o$Foo$self))()) === null || _o$Foo$self$getSelf2 === void 0 ? void 0 : babelHelpers.classPrivateFieldLooseBase(_o$Foo$self$getSelf2, _m)[_m].bind(_o$Foo$self$getSelf2))(); + ((_fn$Foo$self$getSelf = ((_fn = fn()) == null ? void 0 : (_fn$Foo = _fn.Foo) == null ? void 0 : _fn$Foo.self.getSelf.bind(_fn.Foo.self))()) === null || _fn$Foo$self$getSelf === void 0 ? void 0 : babelHelpers.classPrivateFieldLooseBase(_fn$Foo$self$getSelf, _m)[_m].bind(_fn$Foo$self$getSelf))(); + ((_fn$Foo$self$getSelf2 = (fn == null ? void 0 : (_fn$Foo$self = fn().Foo.self) == null ? void 0 : _fn$Foo$self.getSelf.bind(fn().Foo.self))()) === null || _fn$Foo$self$getSelf2 === void 0 ? void 0 : babelHelpers.classPrivateFieldLooseBase(_fn$Foo$self$getSelf2, _m)[_m].bind(_fn$Foo$self$getSelf2))(); } } diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/parenthesized-optional-member-call/exec.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/parenthesized-optional-member-call/exec.js index a6fb131dbd3f..ae7bf5d636e3 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/parenthesized-optional-member-call/exec.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/parenthesized-optional-member-call/exec.js @@ -7,6 +7,9 @@ class Foo { test() { const o = { Foo: Foo }; + const fn = function () { + return o; + }; expect((Foo?.#m)()).toEqual(1); expect((Foo?.#m)().toString).toEqual(1..toString); @@ -18,10 +21,16 @@ class Foo { expect((((o.Foo?.self.getSelf)())?.#m)()).toEqual(1); expect((((o.Foo.self?.getSelf)())?.#m)()).toEqual(1); + + expect((((fn()?.Foo?.self.getSelf)())?.#m)()).toEqual(1); + expect((((fn?.().Foo.self?.getSelf)())?.#m)()).toEqual(1); } testNull() { const o = null; + const fn = function () { + return { o }; + } expect(() => { (o?.Foo.#m)() }).toThrow(); expect(() => { (o?.Foo.#m)().toString }).toThrow(); @@ -29,6 +38,9 @@ class Foo { expect(() => { (((o.Foo?.self.getSelf)())?.#m)() }).toThrow(); expect(() => { (((o.Foo.self?.getSelf)())?.#m)() }).toThrow(); + + expect(() => (((fn()?.Foo?.self.getSelf)())?.#m)()).toThrow(); + expect(() => (((fn?.().Foo.self?.getSelf)())?.#m)()).toThrow(); } } diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/parenthesized-optional-member-call/input.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/parenthesized-optional-member-call/input.js index a2231680adfa..0d9a4d608b78 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/parenthesized-optional-member-call/input.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/parenthesized-optional-member-call/input.js @@ -7,6 +7,9 @@ class Foo { test() { const o = { Foo: Foo }; + const fn = function () { + return o; + }; (Foo?.#m)(); (Foo?.#m)().toString; @@ -18,6 +21,9 @@ class Foo { (((o.Foo?.self.getSelf)())?.#m)(); (((o.Foo.self?.getSelf)())?.#m)(); + + (((fn()?.Foo?.self.getSelf)())?.#m)(); + (((fn?.().Foo.self?.getSelf)())?.#m)(); } } diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/parenthesized-optional-member-call/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/parenthesized-optional-member-call/output.js index c72d057815f7..23b4f4b6d24f 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/parenthesized-optional-member-call/output.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/parenthesized-optional-member-call/output.js @@ -4,19 +4,26 @@ class Foo { } test() { - var _o$Foo$self$getSelf, _o$Foo$self$getSelf2; + var _o$Foo, _o$Foo2, _o$Foo3, _o$Foo$self$getSelf, _o$Foo$self$getSelf2, _fn$Foo$self$getSelf, _fn$Foo$self$getSelf2; const o = { Foo: Foo }; + + const fn = function () { + return o; + }; + (Foo === null || Foo === void 0 ? void 0 : babelHelpers.classStaticPrivateFieldSpecGet(Foo, Foo, _m).bind(Foo))(); (Foo === null || Foo === void 0 ? void 0 : babelHelpers.classStaticPrivateFieldSpecGet(Foo, Foo, _m).bind(Foo))().toString; (Foo === null || Foo === void 0 ? void 0 : babelHelpers.classStaticPrivateFieldSpecGet(Foo, Foo, _m).bind(Foo))().toString(); - (o === null || o === void 0 ? void 0 : babelHelpers.classStaticPrivateFieldSpecGet(o.Foo, Foo, _m).bind(o.Foo))(); - (o === null || o === void 0 ? void 0 : babelHelpers.classStaticPrivateFieldSpecGet(o.Foo, Foo, _m).bind(o.Foo))().toString; - (o === null || o === void 0 ? void 0 : babelHelpers.classStaticPrivateFieldSpecGet(o.Foo, Foo, _m).bind(o.Foo))().toString(); + (o === null || o === void 0 ? void 0 : babelHelpers.classStaticPrivateFieldSpecGet(_o$Foo = o.Foo, Foo, _m).bind(_o$Foo))(); + (o === null || o === void 0 ? void 0 : babelHelpers.classStaticPrivateFieldSpecGet(_o$Foo2 = o.Foo, Foo, _m).bind(_o$Foo2))().toString; + (o === null || o === void 0 ? void 0 : babelHelpers.classStaticPrivateFieldSpecGet(_o$Foo3 = o.Foo, Foo, _m).bind(_o$Foo3))().toString(); ((_o$Foo$self$getSelf = (o.Foo?.self.getSelf)()) === null || _o$Foo$self$getSelf === void 0 ? void 0 : babelHelpers.classStaticPrivateFieldSpecGet(_o$Foo$self$getSelf, Foo, _m).bind(_o$Foo$self$getSelf))(); ((_o$Foo$self$getSelf2 = (o.Foo.self?.getSelf)()) === null || _o$Foo$self$getSelf2 === void 0 ? void 0 : babelHelpers.classStaticPrivateFieldSpecGet(_o$Foo$self$getSelf2, Foo, _m).bind(_o$Foo$self$getSelf2))(); + ((_fn$Foo$self$getSelf = (fn()?.Foo?.self.getSelf)()) === null || _fn$Foo$self$getSelf === void 0 ? void 0 : babelHelpers.classStaticPrivateFieldSpecGet(_fn$Foo$self$getSelf, Foo, _m).bind(_fn$Foo$self$getSelf))(); + ((_fn$Foo$self$getSelf2 = (fn?.().Foo.self?.getSelf)()) === null || _fn$Foo$self$getSelf2 === void 0 ? void 0 : babelHelpers.classStaticPrivateFieldSpecGet(_fn$Foo$self$getSelf2, Foo, _m).bind(_fn$Foo$self$getSelf2))(); } } diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/parenthesized-optional-member-call-with-transform/exec.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/parenthesized-optional-member-call-with-transform/exec.js index a6fb131dbd3f..ae7bf5d636e3 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/parenthesized-optional-member-call-with-transform/exec.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/parenthesized-optional-member-call-with-transform/exec.js @@ -7,6 +7,9 @@ class Foo { test() { const o = { Foo: Foo }; + const fn = function () { + return o; + }; expect((Foo?.#m)()).toEqual(1); expect((Foo?.#m)().toString).toEqual(1..toString); @@ -18,10 +21,16 @@ class Foo { expect((((o.Foo?.self.getSelf)())?.#m)()).toEqual(1); expect((((o.Foo.self?.getSelf)())?.#m)()).toEqual(1); + + expect((((fn()?.Foo?.self.getSelf)())?.#m)()).toEqual(1); + expect((((fn?.().Foo.self?.getSelf)())?.#m)()).toEqual(1); } testNull() { const o = null; + const fn = function () { + return { o }; + } expect(() => { (o?.Foo.#m)() }).toThrow(); expect(() => { (o?.Foo.#m)().toString }).toThrow(); @@ -29,6 +38,9 @@ class Foo { expect(() => { (((o.Foo?.self.getSelf)())?.#m)() }).toThrow(); expect(() => { (((o.Foo.self?.getSelf)())?.#m)() }).toThrow(); + + expect(() => (((fn()?.Foo?.self.getSelf)())?.#m)()).toThrow(); + expect(() => (((fn?.().Foo.self?.getSelf)())?.#m)()).toThrow(); } } diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/parenthesized-optional-member-call-with-transform/input.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/parenthesized-optional-member-call-with-transform/input.js index a2231680adfa..0d9a4d608b78 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/parenthesized-optional-member-call-with-transform/input.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/parenthesized-optional-member-call-with-transform/input.js @@ -7,6 +7,9 @@ class Foo { test() { const o = { Foo: Foo }; + const fn = function () { + return o; + }; (Foo?.#m)(); (Foo?.#m)().toString; @@ -18,6 +21,9 @@ class Foo { (((o.Foo?.self.getSelf)())?.#m)(); (((o.Foo.self?.getSelf)())?.#m)(); + + (((fn()?.Foo?.self.getSelf)())?.#m)(); + (((fn?.().Foo.self?.getSelf)())?.#m)(); } } diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/parenthesized-optional-member-call-with-transform/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/parenthesized-optional-member-call-with-transform/output.js index 4cbdb0f7dc58..7f51bfebb3cb 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/parenthesized-optional-member-call-with-transform/output.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/parenthesized-optional-member-call-with-transform/output.js @@ -4,19 +4,26 @@ class Foo { } test() { - var _o$Foo$self$getSelf, _o$Foo$self$getSelf2, _o$Foo, _o$Foo$self, _o$Foo$self2; + var _o$Foo, _o$Foo2, _o$Foo3, _o$Foo$self$getSelf, _o$Foo$self$getSelf2, _fn$Foo$self$getSelf, _fn$Foo$self$getSelf2, _o$Foo4, _o$Foo4$self, _o$Foo$self, _fn, _fn$Foo$self, _fn$Foo, _fn$Foo$self2, _fn$Foo$self3; const o = { Foo: Foo }; + + const fn = function () { + return o; + }; + (Foo === null || Foo === void 0 ? void 0 : babelHelpers.classStaticPrivateFieldSpecGet(Foo, Foo, _m).bind(Foo))(); (Foo === null || Foo === void 0 ? void 0 : babelHelpers.classStaticPrivateFieldSpecGet(Foo, Foo, _m).bind(Foo))().toString; (Foo === null || Foo === void 0 ? void 0 : babelHelpers.classStaticPrivateFieldSpecGet(Foo, Foo, _m).bind(Foo))().toString(); - (o === null || o === void 0 ? void 0 : babelHelpers.classStaticPrivateFieldSpecGet(o.Foo, Foo, _m).bind(o.Foo))(); - (o === null || o === void 0 ? void 0 : babelHelpers.classStaticPrivateFieldSpecGet(o.Foo, Foo, _m).bind(o.Foo))().toString; - (o === null || o === void 0 ? void 0 : babelHelpers.classStaticPrivateFieldSpecGet(o.Foo, Foo, _m).bind(o.Foo))().toString(); - ((_o$Foo$self$getSelf = ((_o$Foo = o.Foo) === null || _o$Foo === void 0 ? void 0 : (_o$Foo$self = _o$Foo.self).getSelf.bind(_o$Foo$self))()) === null || _o$Foo$self$getSelf === void 0 ? void 0 : babelHelpers.classStaticPrivateFieldSpecGet(_o$Foo$self$getSelf, Foo, _m).bind(_o$Foo$self$getSelf))(); - ((_o$Foo$self$getSelf2 = ((_o$Foo$self2 = o.Foo.self) === null || _o$Foo$self2 === void 0 ? void 0 : _o$Foo$self2.getSelf.bind(_o$Foo$self2))()) === null || _o$Foo$self$getSelf2 === void 0 ? void 0 : babelHelpers.classStaticPrivateFieldSpecGet(_o$Foo$self$getSelf2, Foo, _m).bind(_o$Foo$self$getSelf2))(); + (o === null || o === void 0 ? void 0 : babelHelpers.classStaticPrivateFieldSpecGet(_o$Foo = o.Foo, Foo, _m).bind(_o$Foo))(); + (o === null || o === void 0 ? void 0 : babelHelpers.classStaticPrivateFieldSpecGet(_o$Foo2 = o.Foo, Foo, _m).bind(_o$Foo2))().toString; + (o === null || o === void 0 ? void 0 : babelHelpers.classStaticPrivateFieldSpecGet(_o$Foo3 = o.Foo, Foo, _m).bind(_o$Foo3))().toString(); + ((_o$Foo$self$getSelf = ((_o$Foo4 = o.Foo) === null || _o$Foo4 === void 0 ? void 0 : (_o$Foo4$self = _o$Foo4.self).getSelf.bind(_o$Foo4$self))()) === null || _o$Foo$self$getSelf === void 0 ? void 0 : babelHelpers.classStaticPrivateFieldSpecGet(_o$Foo$self$getSelf, Foo, _m).bind(_o$Foo$self$getSelf))(); + ((_o$Foo$self$getSelf2 = ((_o$Foo$self = o.Foo.self) === null || _o$Foo$self === void 0 ? void 0 : _o$Foo$self.getSelf.bind(_o$Foo$self))()) === null || _o$Foo$self$getSelf2 === void 0 ? void 0 : babelHelpers.classStaticPrivateFieldSpecGet(_o$Foo$self$getSelf2, Foo, _m).bind(_o$Foo$self$getSelf2))(); + ((_fn$Foo$self$getSelf = ((_fn = fn()) === null || _fn === void 0 ? void 0 : (_fn$Foo = _fn.Foo) === null || _fn$Foo === void 0 ? void 0 : (_fn$Foo$self = _fn$Foo.self).getSelf.bind(_fn$Foo$self))()) === null || _fn$Foo$self$getSelf === void 0 ? void 0 : babelHelpers.classStaticPrivateFieldSpecGet(_fn$Foo$self$getSelf, Foo, _m).bind(_fn$Foo$self$getSelf))(); + ((_fn$Foo$self$getSelf2 = (fn === null || fn === void 0 ? void 0 : (_fn$Foo$self3 = _fn$Foo$self2 = fn().Foo.self) === null || _fn$Foo$self3 === void 0 ? void 0 : _fn$Foo$self3.getSelf.bind(_fn$Foo$self2))()) === null || _fn$Foo$self$getSelf2 === void 0 ? void 0 : babelHelpers.classStaticPrivateFieldSpecGet(_fn$Foo$self$getSelf2, Foo, _m).bind(_fn$Foo$self$getSelf2))(); } } diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/parenthesized-optional-member-call/exec.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/parenthesized-optional-member-call/exec.js index a6fb131dbd3f..ae7bf5d636e3 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/parenthesized-optional-member-call/exec.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/parenthesized-optional-member-call/exec.js @@ -7,6 +7,9 @@ class Foo { test() { const o = { Foo: Foo }; + const fn = function () { + return o; + }; expect((Foo?.#m)()).toEqual(1); expect((Foo?.#m)().toString).toEqual(1..toString); @@ -18,10 +21,16 @@ class Foo { expect((((o.Foo?.self.getSelf)())?.#m)()).toEqual(1); expect((((o.Foo.self?.getSelf)())?.#m)()).toEqual(1); + + expect((((fn()?.Foo?.self.getSelf)())?.#m)()).toEqual(1); + expect((((fn?.().Foo.self?.getSelf)())?.#m)()).toEqual(1); } testNull() { const o = null; + const fn = function () { + return { o }; + } expect(() => { (o?.Foo.#m)() }).toThrow(); expect(() => { (o?.Foo.#m)().toString }).toThrow(); @@ -29,6 +38,9 @@ class Foo { expect(() => { (((o.Foo?.self.getSelf)())?.#m)() }).toThrow(); expect(() => { (((o.Foo.self?.getSelf)())?.#m)() }).toThrow(); + + expect(() => (((fn()?.Foo?.self.getSelf)())?.#m)()).toThrow(); + expect(() => (((fn?.().Foo.self?.getSelf)())?.#m)()).toThrow(); } } diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/parenthesized-optional-member-call/input.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/parenthesized-optional-member-call/input.js index a2231680adfa..0d9a4d608b78 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/parenthesized-optional-member-call/input.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/parenthesized-optional-member-call/input.js @@ -7,6 +7,9 @@ class Foo { test() { const o = { Foo: Foo }; + const fn = function () { + return o; + }; (Foo?.#m)(); (Foo?.#m)().toString; @@ -18,6 +21,9 @@ class Foo { (((o.Foo?.self.getSelf)())?.#m)(); (((o.Foo.self?.getSelf)())?.#m)(); + + (((fn()?.Foo?.self.getSelf)())?.#m)(); + (((fn?.().Foo.self?.getSelf)())?.#m)(); } } diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/parenthesized-optional-member-call/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/parenthesized-optional-member-call/output.js index c72d057815f7..23b4f4b6d24f 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/parenthesized-optional-member-call/output.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/parenthesized-optional-member-call/output.js @@ -4,19 +4,26 @@ class Foo { } test() { - var _o$Foo$self$getSelf, _o$Foo$self$getSelf2; + var _o$Foo, _o$Foo2, _o$Foo3, _o$Foo$self$getSelf, _o$Foo$self$getSelf2, _fn$Foo$self$getSelf, _fn$Foo$self$getSelf2; const o = { Foo: Foo }; + + const fn = function () { + return o; + }; + (Foo === null || Foo === void 0 ? void 0 : babelHelpers.classStaticPrivateFieldSpecGet(Foo, Foo, _m).bind(Foo))(); (Foo === null || Foo === void 0 ? void 0 : babelHelpers.classStaticPrivateFieldSpecGet(Foo, Foo, _m).bind(Foo))().toString; (Foo === null || Foo === void 0 ? void 0 : babelHelpers.classStaticPrivateFieldSpecGet(Foo, Foo, _m).bind(Foo))().toString(); - (o === null || o === void 0 ? void 0 : babelHelpers.classStaticPrivateFieldSpecGet(o.Foo, Foo, _m).bind(o.Foo))(); - (o === null || o === void 0 ? void 0 : babelHelpers.classStaticPrivateFieldSpecGet(o.Foo, Foo, _m).bind(o.Foo))().toString; - (o === null || o === void 0 ? void 0 : babelHelpers.classStaticPrivateFieldSpecGet(o.Foo, Foo, _m).bind(o.Foo))().toString(); + (o === null || o === void 0 ? void 0 : babelHelpers.classStaticPrivateFieldSpecGet(_o$Foo = o.Foo, Foo, _m).bind(_o$Foo))(); + (o === null || o === void 0 ? void 0 : babelHelpers.classStaticPrivateFieldSpecGet(_o$Foo2 = o.Foo, Foo, _m).bind(_o$Foo2))().toString; + (o === null || o === void 0 ? void 0 : babelHelpers.classStaticPrivateFieldSpecGet(_o$Foo3 = o.Foo, Foo, _m).bind(_o$Foo3))().toString(); ((_o$Foo$self$getSelf = (o.Foo?.self.getSelf)()) === null || _o$Foo$self$getSelf === void 0 ? void 0 : babelHelpers.classStaticPrivateFieldSpecGet(_o$Foo$self$getSelf, Foo, _m).bind(_o$Foo$self$getSelf))(); ((_o$Foo$self$getSelf2 = (o.Foo.self?.getSelf)()) === null || _o$Foo$self$getSelf2 === void 0 ? void 0 : babelHelpers.classStaticPrivateFieldSpecGet(_o$Foo$self$getSelf2, Foo, _m).bind(_o$Foo$self$getSelf2))(); + ((_fn$Foo$self$getSelf = (fn()?.Foo?.self.getSelf)()) === null || _fn$Foo$self$getSelf === void 0 ? void 0 : babelHelpers.classStaticPrivateFieldSpecGet(_fn$Foo$self$getSelf, Foo, _m).bind(_fn$Foo$self$getSelf))(); + ((_fn$Foo$self$getSelf2 = (fn?.().Foo.self?.getSelf)()) === null || _fn$Foo$self$getSelf2 === void 0 ? void 0 : babelHelpers.classStaticPrivateFieldSpecGet(_fn$Foo$self$getSelf2, Foo, _m).bind(_fn$Foo$self$getSelf2))(); } } diff --git a/packages/babel-plugin-proposal-optional-chaining/src/index.js b/packages/babel-plugin-proposal-optional-chaining/src/index.js index fe21895035dc..c7346891244a 100644 --- a/packages/babel-plugin-proposal-optional-chaining/src/index.js +++ b/packages/babel-plugin-proposal-optional-chaining/src/index.js @@ -127,7 +127,7 @@ export default declare((api, options) => { // `(a?.b)()` to `(a == null ? undefined : a.b.bind(a))()` const { object } = replacement; let baseRef; - if (!loose) { + if (!loose || !isSimpleMemberExpression(object)) { // memoize the context object in non-loose mode // `(a?.b.c)()` to `(a == null ? undefined : (_a$b = a.b).c.bind(_a$b))()` baseRef = scope.maybeGenerateMemoised(object); diff --git a/packages/babel-plugin-proposal-optional-chaining/test/fixtures/general/parenthesized-expression-member-call-loose/exec.js b/packages/babel-plugin-proposal-optional-chaining/test/fixtures/general/parenthesized-expression-member-call-loose/exec.js index eb3b1e5d67c8..2af236e11a8b 100644 --- a/packages/babel-plugin-proposal-optional-chaining/test/fixtures/general/parenthesized-expression-member-call-loose/exec.js +++ b/packages/babel-plugin-proposal-optional-chaining/test/fixtures/general/parenthesized-expression-member-call-loose/exec.js @@ -9,6 +9,9 @@ class Foo { test() { const Foo = this; const o = { Foo: Foo }; + const fn = function () { + return o; + }; expect((Foo?.["m"])()).toEqual(1); expect((Foo?.["m"])().toString).toEqual(1..toString); @@ -24,6 +27,9 @@ class Foo { expect((((o.Foo?.self.getSelf)())?.m)()).toEqual(1); expect((((o.Foo.self?.getSelf)())?.m)()).toEqual(1); + + expect((((fn()?.Foo?.self.getSelf)())?.m)()).toEqual(1); + expect((((fn?.().Foo.self?.getSelf)())?.m)()).toEqual(1); } testNull() { @@ -35,6 +41,9 @@ class Foo { expect(() => { (((o.Foo?.self.getSelf)())?.m)() }).toThrow(); expect(() => { (((o.Foo.self?.getSelf)())?.m)() }).toThrow(); + + expect(() => (((fn()?.Foo?.self.getSelf)())?.m)()).toThrow(); + expect(() => (((fn?.().Foo.self?.getSelf)())?.m)()).toThrow(); } } diff --git a/packages/babel-plugin-proposal-optional-chaining/test/fixtures/general/parenthesized-expression-member-call/exec.js b/packages/babel-plugin-proposal-optional-chaining/test/fixtures/general/parenthesized-expression-member-call/exec.js index eb3b1e5d67c8..2af236e11a8b 100644 --- a/packages/babel-plugin-proposal-optional-chaining/test/fixtures/general/parenthesized-expression-member-call/exec.js +++ b/packages/babel-plugin-proposal-optional-chaining/test/fixtures/general/parenthesized-expression-member-call/exec.js @@ -9,6 +9,9 @@ class Foo { test() { const Foo = this; const o = { Foo: Foo }; + const fn = function () { + return o; + }; expect((Foo?.["m"])()).toEqual(1); expect((Foo?.["m"])().toString).toEqual(1..toString); @@ -24,6 +27,9 @@ class Foo { expect((((o.Foo?.self.getSelf)())?.m)()).toEqual(1); expect((((o.Foo.self?.getSelf)())?.m)()).toEqual(1); + + expect((((fn()?.Foo?.self.getSelf)())?.m)()).toEqual(1); + expect((((fn?.().Foo.self?.getSelf)())?.m)()).toEqual(1); } testNull() { @@ -35,6 +41,9 @@ class Foo { expect(() => { (((o.Foo?.self.getSelf)())?.m)() }).toThrow(); expect(() => { (((o.Foo.self?.getSelf)())?.m)() }).toThrow(); + + expect(() => (((fn()?.Foo?.self.getSelf)())?.m)()).toThrow(); + expect(() => (((fn?.().Foo.self?.getSelf)())?.m)()).toThrow(); } } diff --git a/packages/babel-plugin-proposal-optional-chaining/test/fixtures/general/parenthesized-member-call-loose/exec.js b/packages/babel-plugin-proposal-optional-chaining/test/fixtures/general/parenthesized-member-call-loose/exec.js index 0e0cb2055604..e6728cdc3119 100644 --- a/packages/babel-plugin-proposal-optional-chaining/test/fixtures/general/parenthesized-member-call-loose/exec.js +++ b/packages/babel-plugin-proposal-optional-chaining/test/fixtures/general/parenthesized-member-call-loose/exec.js @@ -9,6 +9,9 @@ class Foo { test() { const Foo = this; const o = { Foo: Foo }; + const fn = function () { + return o; + }; expect((Foo?.["m"])()).toEqual(1); expect((Foo?.["m"])().toString).toEqual(1..toString); @@ -20,6 +23,9 @@ class Foo { expect((((o.Foo?.self.getSelf)())?.m)()).toEqual(1); expect((((o.Foo.self?.getSelf)())?.m)()).toEqual(1); + + expect((((fn()?.Foo?.self.getSelf)())?.m)()).toEqual(1); + expect((((fn?.().Foo.self?.getSelf)())?.m)()).toEqual(1); } testNull() { @@ -31,6 +37,9 @@ class Foo { expect(() => { (((o.Foo?.self.getSelf)())?.m)() }).toThrow(); expect(() => { (((o.Foo.self?.getSelf)())?.m)() }).toThrow(); + + expect(() => (((fn()?.Foo?.self.getSelf)())?.m)()).toThrow(); + expect(() => (((fn?.().Foo.self?.getSelf)())?.m)()).toThrow(); } } diff --git a/packages/babel-plugin-proposal-optional-chaining/test/fixtures/general/parenthesized-member-call-loose/input.js b/packages/babel-plugin-proposal-optional-chaining/test/fixtures/general/parenthesized-member-call-loose/input.js index 1bdce5676802..d552bd7d544a 100644 --- a/packages/babel-plugin-proposal-optional-chaining/test/fixtures/general/parenthesized-member-call-loose/input.js +++ b/packages/babel-plugin-proposal-optional-chaining/test/fixtures/general/parenthesized-member-call-loose/input.js @@ -9,6 +9,9 @@ class Foo { test() { const Foo = this; const o = { Foo: Foo }; + const fn = function () { + return o; + }; (Foo?.["m"])(); (Foo?.["m"])().toString; @@ -20,6 +23,9 @@ class Foo { (((o.Foo?.self.getSelf)())?.m)(); (((o.Foo.self?.getSelf)())?.m)(); + + (((fn()?.Foo?.self.getSelf)())?.m)(); + (((fn?.().Foo.self?.getSelf)())?.m)(); } } diff --git a/packages/babel-plugin-proposal-optional-chaining/test/fixtures/general/parenthesized-member-call-loose/output.js b/packages/babel-plugin-proposal-optional-chaining/test/fixtures/general/parenthesized-member-call-loose/output.js index 3f79a4007881..80c198711db7 100644 --- a/packages/babel-plugin-proposal-optional-chaining/test/fixtures/general/parenthesized-member-call-loose/output.js +++ b/packages/babel-plugin-proposal-optional-chaining/test/fixtures/general/parenthesized-member-call-loose/output.js @@ -13,12 +13,17 @@ class Foo { } test() { - var _o$Foo$self$getSelf, _o$Foo, _o$Foo$self$getSelf2, _o$Foo$self; + var _o$Foo$self$getSelf, _o$Foo, _o$Foo$self$getSelf2, _o$Foo$self, _fn$Foo$self$getSelf, _fn, _fn$Foo, _fn$Foo$self$getSelf2, _fn$Foo$self, _fn$Foo$self2; const Foo = this; const o = { Foo: Foo }; + + const fn = function () { + return o; + }; + (Foo == null ? void 0 : Foo["m"].bind(Foo))(); (Foo == null ? void 0 : Foo["m"].bind(Foo))().toString; (Foo == null ? void 0 : Foo["m"].bind(Foo))().toString(); @@ -27,6 +32,8 @@ class Foo { (o == null ? void 0 : o.Foo.m.bind(o.Foo))().toString(); ((_o$Foo$self$getSelf = ((_o$Foo = o.Foo) == null ? void 0 : _o$Foo.self.getSelf.bind(_o$Foo.self))()) == null ? void 0 : _o$Foo$self$getSelf.m.bind(_o$Foo$self$getSelf))(); ((_o$Foo$self$getSelf2 = ((_o$Foo$self = o.Foo.self) == null ? void 0 : _o$Foo$self.getSelf.bind(_o$Foo$self))()) == null ? void 0 : _o$Foo$self$getSelf2.m.bind(_o$Foo$self$getSelf2))(); + ((_fn$Foo$self$getSelf = ((_fn = fn()) == null ? void 0 : (_fn$Foo = _fn.Foo) == null ? void 0 : _fn$Foo.self.getSelf.bind(_fn.Foo.self))()) == null ? void 0 : _fn$Foo$self$getSelf.m.bind(_fn$Foo$self$getSelf))(); + ((_fn$Foo$self$getSelf2 = (fn == null ? void 0 : (_fn$Foo$self2 = _fn$Foo$self = fn().Foo.self) == null ? void 0 : _fn$Foo$self2.getSelf.bind(_fn$Foo$self))()) == null ? void 0 : _fn$Foo$self$getSelf2.m.bind(_fn$Foo$self$getSelf2))(); } } diff --git a/packages/babel-plugin-proposal-optional-chaining/test/fixtures/general/parenthesized-member-call/exec.js b/packages/babel-plugin-proposal-optional-chaining/test/fixtures/general/parenthesized-member-call/exec.js index 0e0cb2055604..e6728cdc3119 100644 --- a/packages/babel-plugin-proposal-optional-chaining/test/fixtures/general/parenthesized-member-call/exec.js +++ b/packages/babel-plugin-proposal-optional-chaining/test/fixtures/general/parenthesized-member-call/exec.js @@ -9,6 +9,9 @@ class Foo { test() { const Foo = this; const o = { Foo: Foo }; + const fn = function () { + return o; + }; expect((Foo?.["m"])()).toEqual(1); expect((Foo?.["m"])().toString).toEqual(1..toString); @@ -20,6 +23,9 @@ class Foo { expect((((o.Foo?.self.getSelf)())?.m)()).toEqual(1); expect((((o.Foo.self?.getSelf)())?.m)()).toEqual(1); + + expect((((fn()?.Foo?.self.getSelf)())?.m)()).toEqual(1); + expect((((fn?.().Foo.self?.getSelf)())?.m)()).toEqual(1); } testNull() { @@ -31,6 +37,9 @@ class Foo { expect(() => { (((o.Foo?.self.getSelf)())?.m)() }).toThrow(); expect(() => { (((o.Foo.self?.getSelf)())?.m)() }).toThrow(); + + expect(() => (((fn()?.Foo?.self.getSelf)())?.m)()).toThrow(); + expect(() => (((fn?.().Foo.self?.getSelf)())?.m)()).toThrow(); } } diff --git a/packages/babel-plugin-proposal-optional-chaining/test/fixtures/general/parenthesized-member-call/input.js b/packages/babel-plugin-proposal-optional-chaining/test/fixtures/general/parenthesized-member-call/input.js index 1bdce5676802..d552bd7d544a 100644 --- a/packages/babel-plugin-proposal-optional-chaining/test/fixtures/general/parenthesized-member-call/input.js +++ b/packages/babel-plugin-proposal-optional-chaining/test/fixtures/general/parenthesized-member-call/input.js @@ -9,6 +9,9 @@ class Foo { test() { const Foo = this; const o = { Foo: Foo }; + const fn = function () { + return o; + }; (Foo?.["m"])(); (Foo?.["m"])().toString; @@ -20,6 +23,9 @@ class Foo { (((o.Foo?.self.getSelf)())?.m)(); (((o.Foo.self?.getSelf)())?.m)(); + + (((fn()?.Foo?.self.getSelf)())?.m)(); + (((fn?.().Foo.self?.getSelf)())?.m)(); } } diff --git a/packages/babel-plugin-proposal-optional-chaining/test/fixtures/general/parenthesized-member-call/output.js b/packages/babel-plugin-proposal-optional-chaining/test/fixtures/general/parenthesized-member-call/output.js index d298c6342ac2..a41ae311d626 100644 --- a/packages/babel-plugin-proposal-optional-chaining/test/fixtures/general/parenthesized-member-call/output.js +++ b/packages/babel-plugin-proposal-optional-chaining/test/fixtures/general/parenthesized-member-call/output.js @@ -13,12 +13,17 @@ class Foo { } test() { - var _o$Foo, _o$Foo2, _o$Foo3, _o$Foo$self$getSelf, _o$Foo4, _o$Foo4$self, _o$Foo$self$getSelf2, _o$Foo$self; + var _o$Foo, _o$Foo2, _o$Foo3, _o$Foo$self$getSelf, _o$Foo4, _o$Foo4$self, _o$Foo$self$getSelf2, _o$Foo$self, _fn$Foo$self$getSelf, _fn, _fn$Foo$self, _fn$Foo, _fn$Foo$self$getSelf2, _fn$Foo$self2, _fn$Foo$self3; const Foo = this; const o = { Foo: Foo }; + + const fn = function () { + return o; + }; + (Foo === null || Foo === void 0 ? void 0 : Foo["m"].bind(Foo))(); (Foo === null || Foo === void 0 ? void 0 : Foo["m"].bind(Foo))().toString; (Foo === null || Foo === void 0 ? void 0 : Foo["m"].bind(Foo))().toString(); @@ -27,6 +32,8 @@ class Foo { (o === null || o === void 0 ? void 0 : (_o$Foo3 = o.Foo).m.bind(_o$Foo3))().toString(); ((_o$Foo$self$getSelf = ((_o$Foo4 = o.Foo) === null || _o$Foo4 === void 0 ? void 0 : (_o$Foo4$self = _o$Foo4.self).getSelf.bind(_o$Foo4$self))()) === null || _o$Foo$self$getSelf === void 0 ? void 0 : _o$Foo$self$getSelf.m.bind(_o$Foo$self$getSelf))(); ((_o$Foo$self$getSelf2 = ((_o$Foo$self = o.Foo.self) === null || _o$Foo$self === void 0 ? void 0 : _o$Foo$self.getSelf.bind(_o$Foo$self))()) === null || _o$Foo$self$getSelf2 === void 0 ? void 0 : _o$Foo$self$getSelf2.m.bind(_o$Foo$self$getSelf2))(); + ((_fn$Foo$self$getSelf = ((_fn = fn()) === null || _fn === void 0 ? void 0 : (_fn$Foo = _fn.Foo) === null || _fn$Foo === void 0 ? void 0 : (_fn$Foo$self = _fn$Foo.self).getSelf.bind(_fn$Foo$self))()) === null || _fn$Foo$self$getSelf === void 0 ? void 0 : _fn$Foo$self$getSelf.m.bind(_fn$Foo$self$getSelf))(); + ((_fn$Foo$self$getSelf2 = (fn === null || fn === void 0 ? void 0 : (_fn$Foo$self3 = _fn$Foo$self2 = fn().Foo.self) === null || _fn$Foo$self3 === void 0 ? void 0 : _fn$Foo$self3.getSelf.bind(_fn$Foo$self2))()) === null || _fn$Foo$self$getSelf2 === void 0 ? void 0 : _fn$Foo$self$getSelf2.m.bind(_fn$Foo$self$getSelf2))(); } } From a2d565772f30fbc22f6d09ad24e158ea047bf4d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hu=C3=A1ng=20J=C3=B9nli=C3=A0ng?= Date: Sat, 30 May 2020 16:19:33 -0400 Subject: [PATCH 12/12] update test fixtures --- .../output.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/parenthesized-optional-member-call-with-transform/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/parenthesized-optional-member-call-with-transform/output.js index 5987a54474c7..30952e1dbb81 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/parenthesized-optional-member-call-with-transform/output.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/parenthesized-optional-member-call-with-transform/output.js @@ -4,7 +4,7 @@ class Foo { } test() { - var _o$Foo$self$getSelf, _o$Foo$self$getSelf2, _fn$Foo$self$getSelf, _fn$Foo$self$getSelf2, _o$Foo, _o$Foo$self, _fn, _fn$Foo, _fn$Foo$self; + var _o$Foo$self$getSelf, _o$Foo$self$getSelf2, _fn$Foo$self$getSelf, _fn$Foo$self$getSelf2, _o$Foo, _o$Foo$self, _fn, _fn$Foo, _fn$Foo$self, _fn$Foo$self2; const o = { Foo: Foo @@ -23,7 +23,7 @@ class Foo { ((_o$Foo$self$getSelf = ((_o$Foo = o.Foo) == null ? void 0 : _o$Foo.self.getSelf.bind(_o$Foo.self))()) === null || _o$Foo$self$getSelf === void 0 ? void 0 : babelHelpers.classPrivateFieldLooseBase(_o$Foo$self$getSelf, _m)[_m].bind(_o$Foo$self$getSelf))(); ((_o$Foo$self$getSelf2 = ((_o$Foo$self = o.Foo.self) == null ? void 0 : _o$Foo$self.getSelf.bind(_o$Foo$self))()) === null || _o$Foo$self$getSelf2 === void 0 ? void 0 : babelHelpers.classPrivateFieldLooseBase(_o$Foo$self$getSelf2, _m)[_m].bind(_o$Foo$self$getSelf2))(); ((_fn$Foo$self$getSelf = ((_fn = fn()) == null ? void 0 : (_fn$Foo = _fn.Foo) == null ? void 0 : _fn$Foo.self.getSelf.bind(_fn.Foo.self))()) === null || _fn$Foo$self$getSelf === void 0 ? void 0 : babelHelpers.classPrivateFieldLooseBase(_fn$Foo$self$getSelf, _m)[_m].bind(_fn$Foo$self$getSelf))(); - ((_fn$Foo$self$getSelf2 = (fn == null ? void 0 : (_fn$Foo$self = fn().Foo.self) == null ? void 0 : _fn$Foo$self.getSelf.bind(fn().Foo.self))()) === null || _fn$Foo$self$getSelf2 === void 0 ? void 0 : babelHelpers.classPrivateFieldLooseBase(_fn$Foo$self$getSelf2, _m)[_m].bind(_fn$Foo$self$getSelf2))(); + ((_fn$Foo$self$getSelf2 = (fn == null ? void 0 : (_fn$Foo$self2 = _fn$Foo$self = fn().Foo.self) == null ? void 0 : _fn$Foo$self2.getSelf.bind(_fn$Foo$self))()) === null || _fn$Foo$self$getSelf2 === void 0 ? void 0 : babelHelpers.classPrivateFieldLooseBase(_fn$Foo$self$getSelf2, _m)[_m].bind(_fn$Foo$self$getSelf2))(); } }