From d8a38b8d7b35e5c4bfafac305163386e186df2b0 Mon Sep 17 00:00:00 2001 From: Justin Ridgewell Date: Thu, 12 Mar 2020 01:28:21 -0400 Subject: [PATCH 01/20] Handle private access chained on an optional chain See the resolution from https://github.com/tc39/proposal-class-fields/pull/301. --- .../src/fields.js | 53 +- .../src/index.js | 115 ++- .../babel-parser/src/parser/expression.js | 5 +- packages/babel-parser/src/parser/location.js | 2 + .../optional-chain-object/input.js | 14 + .../optional-chain-object/options.json | 3 + .../optional-chain-object/output.json | 969 ++++++++++++++++++ .../optional-chain-start-call/input.js | 7 + .../optional-chain-start-call/options.json | 3 + .../optional-chain-start-call/output.json | 326 ++++++ .../optional-chain-start-member-call/input.js | 7 + .../options.json | 3 + .../output.json | 365 +++++++ .../optional-chain-start-member/input.js | 7 + .../optional-chain-start-member/options.json | 3 + .../optional-chain-start-member/output.json | 328 ++++++ .../optional-chain-start-simple/input.js | 7 + .../optional-chain-start-simple/options.json | 3 + .../optional-chain-start-simple/output.json | 294 ++++++ .../optional-chain-with-transform/exec.js | 25 + .../optional-chain-with-transform/input.js | 25 + .../options.json | 6 + .../optional-chain-with-transform/output.js | 47 + .../private-loose/optional-chain/input.js | 25 + .../private-loose/optional-chain/options.json | 3 + .../private-loose/optional-chain/output.js | 47 + .../optional-chain-with-transform/exec.js | 25 + .../optional-chain-with-transform/input.js | 25 + .../options.json | 3 + .../optional-chain-with-transform/output.js | 43 + .../fixtures/private/optional-chain/input.js | 25 + .../private/optional-chain/options.json | 3 + .../fixtures/private/optional-chain/output.js | 43 + 33 files changed, 2827 insertions(+), 32 deletions(-) create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-properties/optional-chain-object/input.js create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-properties/optional-chain-object/options.json create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-properties/optional-chain-object/output.json create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-properties/optional-chain-start-call/input.js create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-properties/optional-chain-start-call/options.json create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-properties/optional-chain-start-call/output.json create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-properties/optional-chain-start-member-call/input.js create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-properties/optional-chain-start-member-call/options.json create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-properties/optional-chain-start-member-call/output.json create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-properties/optional-chain-start-member/input.js create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-properties/optional-chain-start-member/options.json create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-properties/optional-chain-start-member/output.json create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-properties/optional-chain-start-simple/input.js create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-properties/optional-chain-start-simple/options.json create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-properties/optional-chain-start-simple/output.json create mode 100644 packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-with-transform/exec.js create mode 100644 packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-with-transform/input.js create mode 100644 packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-with-transform/options.json create mode 100644 packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-with-transform/output.js create mode 100644 packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain/input.js create mode 100644 packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain/options.json create mode 100644 packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain/output.js create mode 100644 packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-with-transform/exec.js create mode 100644 packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-with-transform/input.js create mode 100644 packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-with-transform/options.json create mode 100644 packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-with-transform/output.js create mode 100644 packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain/input.js create mode 100644 packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain/options.json create mode 100644 packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain/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 566458b1c585..46d14f08a2bf 100644 --- a/packages/babel-helper-create-class-features-plugin/src/fields.js +++ b/packages/babel-helper-create-class-features-plugin/src/fields.js @@ -128,8 +128,12 @@ const privateNameVisitor = privateNameVisitorFactory({ const { privateNamesMap, redeclared } = this; const { node, parentPath } = path; - if (!parentPath.isMemberExpression({ property: node })) return; - + if ( + !parentPath.isMemberExpression({ property: node }) && + !parentPath.isOptionalMemberExpression({ property: node }) + ) { + return; + } const { name } = node.id; if (!privateNamesMap.has(name)) return; if (redeclared && redeclared.includes(name)) return; @@ -301,18 +305,28 @@ const privateNameHandlerSpec = { }; const privateNameHandlerLoose = { - handle(member) { + get(member) { const { privateNamesMap, file } = this; const { object } = member.node; const { name } = member.node.property.id; - member.replaceWith( - template.expression`BASE(REF, PROP)[PROP]`({ - BASE: file.addHelper("classPrivateFieldLooseBase"), - REF: object, - PROP: privateNamesMap.get(name).id, - }), - ); + return template.expression`BASE(REF, PROP)[PROP]`({ + BASE: file.addHelper("classPrivateFieldLooseBase"), + REF: object, + PROP: privateNamesMap.get(name).id, + }); + }, + + simpleSet(member) { + return this.get(member); + }, + + destructureSet(member) { + return this.get(member); + }, + + call(member, args) { + return t.callExpression(this.get(member), args); }, }; @@ -326,26 +340,13 @@ export function transformPrivateNamesUsage( if (!privateNamesMap.size) return; const body = path.get("body"); + const handler = loose ? privateNameHandlerLoose : privateNameHandlerSpec; - if (loose) { - body.traverse(privateNameVisitor, { - privateNamesMap, - file: state, - ...privateNameHandlerLoose, - }); - } else { - memberExpressionToFunctions(body, privateNameVisitor, { - privateNamesMap, - classRef: ref, - file: state, - ...privateNameHandlerSpec, - }); - } - body.traverse(privateInVisitor, { + memberExpressionToFunctions(body, privateNameVisitor, { privateNamesMap, classRef: ref, file: state, - loose, + ...handler, }); } 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 88b8514c2cdf..28d814df35df 100644 --- a/packages/babel-helper-member-expression-to-functions/src/index.js +++ b/packages/babel-helper-member-expression-to-functions/src/index.js @@ -37,9 +37,113 @@ const handle = { handle(member) { const { node, parent, parentPath } = member; + if (member.isOptionalMemberExpression()) { + const root = member.find(({ node, parent, parentPath }) => { + if (parentPath.isOptionalMemberExpression()) { + return parent.optional || parent.object !== node; + } + if (parentPath.isOptionalCallExpression()) { + return parent.optional || parent.callee !== node; + } + return true; + }); + + const rootParentPath = root.parentPath; + if ( + rootParentPath.isUpdateExpression({ argument: node }) || + rootParentPath.isAssignmentExpression({ left: node }) + ) { + throw member.buildCodeFrameError(`can't handle assignment`); + } + if (rootParentPath.isUnaryExpression({ operator: "delete" })) { + throw member.buildCodeFrameError(`can't handle delete`); + } + + if (node.optional) { + throw member.buildCodeFrameError( + `can't handle '?.' directly before ${node.property.type}`, + ); + } + + let nearestOptional = member; + for (;;) { + if (nearestOptional.isOptionalMemberExpression()) { + if (nearestOptional.node.optional) break; + nearestOptional = nearestOptional.get("object"); + continue; + } else if (nearestOptional.isOptionalCallExpression()) { + if (nearestOptional.node.optional) break; + nearestOptional = nearestOptional.get("object"); + continue; + } + + throw nearestOptional.buildCodeFrameError( + "failed to find nearest optional", + ); + } + + const { scope } = member; + const { object } = node; + const baseRef = scope.generateUidIdentifierBasedOnNode( + nearestOptional.node.object, + ); + const valueRef = scope.generateUidIdentifierBasedOnNode(object); + scope.push({ id: baseRef }); + scope.push({ id: valueRef }); + + nearestOptional + .get("object") + .replaceWith( + t.assignmentExpression("=", baseRef, nearestOptional.node.object), + ); + member.replaceWith(t.memberExpression(valueRef, node.property)); + + if (parentPath.isOptionalCallExpression({ callee: node })) { + parentPath.replaceWith(this.call(member, parent.arguments)); + } else { + member.replaceWith(this.get(member)); + } + + let regular = member.node; + for (let current = member; current !== root; ) { + const { parentPath, parent } = current; + if (parentPath.isOptionalMemberExpression()) { + regular = t.memberExpression( + regular, + parent.property, + parent.computed, + ); + } else { + regular = t.callExpression(regular, parent.arguments); + } + current = parentPath; + } + + root.replaceWith( + t.conditionalExpression( + t.sequenceExpression([ + t.assignmentExpression("=", valueRef, object), + t.logicalExpression( + "||", + t.binaryExpression("===", baseRef, scope.buildUndefinedNode()), + t.binaryExpression("===", baseRef, t.nullLiteral()), + ), + ]), + scope.buildUndefinedNode(), + regular, + ), + ); + return; + } + // MEMBER++ -> _set(MEMBER, (_ref = (+_get(MEMBER))) + 1), _ref // ++MEMBER -> _set(MEMBER, (+_get(MEMBER)) + 1) if (parentPath.isUpdateExpression({ argument: node })) { + if (this.simpleSet) { + member.replaceWith(this.simpleSet(member)); + return; + } + const { operator, prefix } = parent; // Give the state handler a chance to memoise the member, since we'll @@ -72,6 +176,11 @@ const handle = { // MEMBER = VALUE -> _set(MEMBER, VALUE) // MEMBER += VALUE -> _set(MEMBER, _get(MEMBER) + VALUE) if (parentPath.isAssignmentExpression({ left: node })) { + if (this.simpleSet) { + member.replaceWith(this.simpleSet(member)); + return; + } + const { operator, right } = parent; let value = right; @@ -92,11 +201,9 @@ const handle = { return; } - // MEMBER(ARGS) -> _call(MEMBER, ARGS) + // MEMBER(ARGS) -> _call(MEMBER, ARGS) if (parentPath.isCallExpression({ callee: node })) { - const { arguments: args } = parent; - - parentPath.replaceWith(this.call(member, args)); + parentPath.replaceWith(this.call(member, parent.arguments)); return; } diff --git a/packages/babel-parser/src/parser/expression.js b/packages/babel-parser/src/parser/expression.js index e4acf72cfdda..b05352d69b2b 100644 --- a/packages/babel-parser/src/parser/expression.js +++ b/packages/babel-parser/src/parser/expression.js @@ -616,8 +616,6 @@ export default class ExpressionParser extends LValParser { node.object = base; node.property = computed ? this.parseExpression() - : optional - ? this.parseIdentifier(true) : this.parseMaybePrivateName(true); node.computed = computed; @@ -625,6 +623,9 @@ export default class ExpressionParser extends LValParser { if (node.object.type === "Super") { this.raise(startPos, Errors.SuperPrivateField); } + if (optional) { + this.raise(node.property.start, Errors.OptionalChainingNoPrivate); + } this.classScope.usePrivateName( node.property.id.name, node.property.start, diff --git a/packages/babel-parser/src/parser/location.js b/packages/babel-parser/src/parser/location.js index a03f41af63cc..fc0352152578 100644 --- a/packages/babel-parser/src/parser/location.js +++ b/packages/babel-parser/src/parser/location.js @@ -108,6 +108,8 @@ export const Errors = Object.freeze({ "await* has been removed from the async functions proposal. Use Promise.all() instead.", OptionalChainingNoNew: "constructors in/after an Optional Chain are not allowed", + OptionalChainingNoPrivate: + "Private property access cannot immediately follow an optional chain's `?.`", OptionalChainingNoTemplate: "Tagged Template Literals are not allowed in optionalChain", ParamDupe: "Argument name clash", diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-properties/optional-chain-object/input.js b/packages/babel-parser/test/fixtures/experimental/class-private-properties/optional-chain-object/input.js new file mode 100644 index 000000000000..8f152088b2ef --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-properties/optional-chain-object/input.js @@ -0,0 +1,14 @@ +class Foo { + static #x = 1; + static #m = function() {}; + + static test() { + const o = { Foo: Foo }; + return [ + o?.Foo.#x, + o?.Foo.#x.toFixed, + o?.Foo.#x.toFixed(2), + o?.Foo.#m(), + ]; + } +} diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-properties/optional-chain-object/options.json b/packages/babel-parser/test/fixtures/experimental/class-private-properties/optional-chain-object/options.json new file mode 100644 index 000000000000..f26e916957c8 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-properties/optional-chain-object/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["classPrivateProperties"] +} diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-properties/optional-chain-object/output.json b/packages/babel-parser/test/fixtures/experimental/class-private-properties/optional-chain-object/output.json new file mode 100644 index 000000000000..26ce1f65e3a9 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-properties/optional-chain-object/output.json @@ -0,0 +1,969 @@ +{ + "type": "File", + "start": 0, + "end": 219, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 14, + "column": 1 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 219, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 14, + "column": 1 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ClassDeclaration", + "start": 0, + "end": 219, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 14, + "column": 1 + } + }, + "id": { + "type": "Identifier", + "start": 6, + "end": 9, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 9 + }, + "identifierName": "Foo" + }, + "name": "Foo" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start": 10, + "end": 219, + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 14, + "column": 1 + } + }, + "body": [ + { + "type": "ClassPrivateProperty", + "start": 14, + "end": 28, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 16 + } + }, + "static": true, + "key": { + "type": "PrivateName", + "start": 21, + "end": 23, + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 2, + "column": 11 + } + }, + "id": { + "type": "Identifier", + "start": 22, + "end": 23, + "loc": { + "start": { + "line": 2, + "column": 10 + }, + "end": { + "line": 2, + "column": 11 + }, + "identifierName": "x" + }, + "name": "x" + } + }, + "value": { + "type": "NumericLiteral", + "start": 26, + "end": 27, + "loc": { + "start": { + "line": 2, + "column": 14 + }, + "end": { + "line": 2, + "column": 15 + } + }, + "extra": { + "rawValue": 1, + "raw": "1" + }, + "value": 1 + } + }, + { + "type": "ClassPrivateProperty", + "start": 31, + "end": 57, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 28 + } + }, + "static": true, + "key": { + "type": "PrivateName", + "start": 38, + "end": 40, + "loc": { + "start": { + "line": 3, + "column": 9 + }, + "end": { + "line": 3, + "column": 11 + } + }, + "id": { + "type": "Identifier", + "start": 39, + "end": 40, + "loc": { + "start": { + "line": 3, + "column": 10 + }, + "end": { + "line": 3, + "column": 11 + }, + "identifierName": "m" + }, + "name": "m" + } + }, + "value": { + "type": "FunctionExpression", + "start": 43, + "end": 56, + "loc": { + "start": { + "line": 3, + "column": 14 + }, + "end": { + "line": 3, + "column": 27 + } + }, + "id": null, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 54, + "end": 56, + "loc": { + "start": { + "line": 3, + "column": 25 + }, + "end": { + "line": 3, + "column": 27 + } + }, + "body": [], + "directives": [] + } + } + }, + { + "type": "ClassMethod", + "start": 61, + "end": 217, + "loc": { + "start": { + "line": 5, + "column": 2 + }, + "end": { + "line": 13, + "column": 3 + } + }, + "static": true, + "key": { + "type": "Identifier", + "start": 68, + "end": 72, + "loc": { + "start": { + "line": 5, + "column": 9 + }, + "end": { + "line": 5, + "column": 13 + }, + "identifierName": "test" + }, + "name": "test" + }, + "computed": false, + "kind": "method", + "id": null, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 75, + "end": 217, + "loc": { + "start": { + "line": 5, + "column": 16 + }, + "end": { + "line": 13, + "column": 3 + } + }, + "body": [ + { + "type": "VariableDeclaration", + "start": 81, + "end": 104, + "loc": { + "start": { + "line": 6, + "column": 4 + }, + "end": { + "line": 6, + "column": 27 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 87, + "end": 103, + "loc": { + "start": { + "line": 6, + "column": 10 + }, + "end": { + "line": 6, + "column": 26 + } + }, + "id": { + "type": "Identifier", + "start": 87, + "end": 88, + "loc": { + "start": { + "line": 6, + "column": 10 + }, + "end": { + "line": 6, + "column": 11 + }, + "identifierName": "o" + }, + "name": "o" + }, + "init": { + "type": "ObjectExpression", + "start": 91, + "end": 103, + "loc": { + "start": { + "line": 6, + "column": 14 + }, + "end": { + "line": 6, + "column": 26 + } + }, + "properties": [ + { + "type": "ObjectProperty", + "start": 93, + "end": 101, + "loc": { + "start": { + "line": 6, + "column": 16 + }, + "end": { + "line": 6, + "column": 24 + } + }, + "method": false, + "key": { + "type": "Identifier", + "start": 93, + "end": 96, + "loc": { + "start": { + "line": 6, + "column": 16 + }, + "end": { + "line": 6, + "column": 19 + }, + "identifierName": "Foo" + }, + "name": "Foo" + }, + "computed": false, + "shorthand": false, + "value": { + "type": "Identifier", + "start": 98, + "end": 101, + "loc": { + "start": { + "line": 6, + "column": 21 + }, + "end": { + "line": 6, + "column": 24 + }, + "identifierName": "Foo" + }, + "name": "Foo" + } + } + ] + } + } + ], + "kind": "const" + }, + { + "type": "ReturnStatement", + "start": 109, + "end": 213, + "loc": { + "start": { + "line": 7, + "column": 4 + }, + "end": { + "line": 12, + "column": 6 + } + }, + "argument": { + "type": "ArrayExpression", + "start": 116, + "end": 212, + "loc": { + "start": { + "line": 7, + "column": 11 + }, + "end": { + "line": 12, + "column": 5 + } + }, + "extra": { + "trailingComma": 205 + }, + "elements": [ + { + "type": "OptionalMemberExpression", + "start": 124, + "end": 133, + "loc": { + "start": { + "line": 8, + "column": 6 + }, + "end": { + "line": 8, + "column": 15 + } + }, + "object": { + "type": "OptionalMemberExpression", + "start": 124, + "end": 130, + "loc": { + "start": { + "line": 8, + "column": 6 + }, + "end": { + "line": 8, + "column": 12 + } + }, + "object": { + "type": "Identifier", + "start": 124, + "end": 125, + "loc": { + "start": { + "line": 8, + "column": 6 + }, + "end": { + "line": 8, + "column": 7 + }, + "identifierName": "o" + }, + "name": "o" + }, + "property": { + "type": "Identifier", + "start": 127, + "end": 130, + "loc": { + "start": { + "line": 8, + "column": 9 + }, + "end": { + "line": 8, + "column": 12 + }, + "identifierName": "Foo" + }, + "name": "Foo" + }, + "computed": false, + "optional": true + }, + "property": { + "type": "PrivateName", + "start": 131, + "end": 133, + "loc": { + "start": { + "line": 8, + "column": 13 + }, + "end": { + "line": 8, + "column": 15 + } + }, + "id": { + "type": "Identifier", + "start": 132, + "end": 133, + "loc": { + "start": { + "line": 8, + "column": 14 + }, + "end": { + "line": 8, + "column": 15 + }, + "identifierName": "x" + }, + "name": "x" + } + }, + "computed": false, + "optional": false + }, + { + "type": "OptionalMemberExpression", + "start": 141, + "end": 158, + "loc": { + "start": { + "line": 9, + "column": 6 + }, + "end": { + "line": 9, + "column": 23 + } + }, + "object": { + "type": "OptionalMemberExpression", + "start": 141, + "end": 150, + "loc": { + "start": { + "line": 9, + "column": 6 + }, + "end": { + "line": 9, + "column": 15 + } + }, + "object": { + "type": "OptionalMemberExpression", + "start": 141, + "end": 147, + "loc": { + "start": { + "line": 9, + "column": 6 + }, + "end": { + "line": 9, + "column": 12 + } + }, + "object": { + "type": "Identifier", + "start": 141, + "end": 142, + "loc": { + "start": { + "line": 9, + "column": 6 + }, + "end": { + "line": 9, + "column": 7 + }, + "identifierName": "o" + }, + "name": "o" + }, + "property": { + "type": "Identifier", + "start": 144, + "end": 147, + "loc": { + "start": { + "line": 9, + "column": 9 + }, + "end": { + "line": 9, + "column": 12 + }, + "identifierName": "Foo" + }, + "name": "Foo" + }, + "computed": false, + "optional": true + }, + "property": { + "type": "PrivateName", + "start": 148, + "end": 150, + "loc": { + "start": { + "line": 9, + "column": 13 + }, + "end": { + "line": 9, + "column": 15 + } + }, + "id": { + "type": "Identifier", + "start": 149, + "end": 150, + "loc": { + "start": { + "line": 9, + "column": 14 + }, + "end": { + "line": 9, + "column": 15 + }, + "identifierName": "x" + }, + "name": "x" + } + }, + "computed": false, + "optional": false + }, + "property": { + "type": "Identifier", + "start": 151, + "end": 158, + "loc": { + "start": { + "line": 9, + "column": 16 + }, + "end": { + "line": 9, + "column": 23 + }, + "identifierName": "toFixed" + }, + "name": "toFixed" + }, + "computed": false, + "optional": false + }, + { + "type": "OptionalCallExpression", + "start": 166, + "end": 186, + "loc": { + "start": { + "line": 10, + "column": 6 + }, + "end": { + "line": 10, + "column": 26 + } + }, + "callee": { + "type": "OptionalMemberExpression", + "start": 166, + "end": 183, + "loc": { + "start": { + "line": 10, + "column": 6 + }, + "end": { + "line": 10, + "column": 23 + } + }, + "object": { + "type": "OptionalMemberExpression", + "start": 166, + "end": 175, + "loc": { + "start": { + "line": 10, + "column": 6 + }, + "end": { + "line": 10, + "column": 15 + } + }, + "object": { + "type": "OptionalMemberExpression", + "start": 166, + "end": 172, + "loc": { + "start": { + "line": 10, + "column": 6 + }, + "end": { + "line": 10, + "column": 12 + } + }, + "object": { + "type": "Identifier", + "start": 166, + "end": 167, + "loc": { + "start": { + "line": 10, + "column": 6 + }, + "end": { + "line": 10, + "column": 7 + }, + "identifierName": "o" + }, + "name": "o" + }, + "property": { + "type": "Identifier", + "start": 169, + "end": 172, + "loc": { + "start": { + "line": 10, + "column": 9 + }, + "end": { + "line": 10, + "column": 12 + }, + "identifierName": "Foo" + }, + "name": "Foo" + }, + "computed": false, + "optional": true + }, + "property": { + "type": "PrivateName", + "start": 173, + "end": 175, + "loc": { + "start": { + "line": 10, + "column": 13 + }, + "end": { + "line": 10, + "column": 15 + } + }, + "id": { + "type": "Identifier", + "start": 174, + "end": 175, + "loc": { + "start": { + "line": 10, + "column": 14 + }, + "end": { + "line": 10, + "column": 15 + }, + "identifierName": "x" + }, + "name": "x" + } + }, + "computed": false, + "optional": false + }, + "property": { + "type": "Identifier", + "start": 176, + "end": 183, + "loc": { + "start": { + "line": 10, + "column": 16 + }, + "end": { + "line": 10, + "column": 23 + }, + "identifierName": "toFixed" + }, + "name": "toFixed" + }, + "computed": false, + "optional": false + }, + "arguments": [ + { + "type": "NumericLiteral", + "start": 184, + "end": 185, + "loc": { + "start": { + "line": 10, + "column": 24 + }, + "end": { + "line": 10, + "column": 25 + } + }, + "extra": { + "rawValue": 2, + "raw": "2" + }, + "value": 2 + } + ] + }, + { + "type": "OptionalCallExpression", + "start": 194, + "end": 205, + "loc": { + "start": { + "line": 11, + "column": 6 + }, + "end": { + "line": 11, + "column": 17 + } + }, + "callee": { + "type": "OptionalMemberExpression", + "start": 194, + "end": 203, + "loc": { + "start": { + "line": 11, + "column": 6 + }, + "end": { + "line": 11, + "column": 15 + } + }, + "object": { + "type": "OptionalMemberExpression", + "start": 194, + "end": 200, + "loc": { + "start": { + "line": 11, + "column": 6 + }, + "end": { + "line": 11, + "column": 12 + } + }, + "object": { + "type": "Identifier", + "start": 194, + "end": 195, + "loc": { + "start": { + "line": 11, + "column": 6 + }, + "end": { + "line": 11, + "column": 7 + }, + "identifierName": "o" + }, + "name": "o" + }, + "property": { + "type": "Identifier", + "start": 197, + "end": 200, + "loc": { + "start": { + "line": 11, + "column": 9 + }, + "end": { + "line": 11, + "column": 12 + }, + "identifierName": "Foo" + }, + "name": "Foo" + }, + "computed": false, + "optional": true + }, + "property": { + "type": "PrivateName", + "start": 201, + "end": 203, + "loc": { + "start": { + "line": 11, + "column": 13 + }, + "end": { + "line": 11, + "column": 15 + } + }, + "id": { + "type": "Identifier", + "start": 202, + "end": 203, + "loc": { + "start": { + "line": 11, + "column": 14 + }, + "end": { + "line": 11, + "column": 15 + }, + "identifierName": "m" + }, + "name": "m" + } + }, + "computed": false, + "optional": false + }, + "arguments": [] + } + ] + } + } + ], + "directives": [] + } + } + ] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-properties/optional-chain-start-call/input.js b/packages/babel-parser/test/fixtures/experimental/class-private-properties/optional-chain-start-call/input.js new file mode 100644 index 000000000000..861a7c721195 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-properties/optional-chain-start-call/input.js @@ -0,0 +1,7 @@ +class Foo { + static #m = function() {}; + + static test() { + return Foo?.#m(); + } +} diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-properties/optional-chain-start-call/options.json b/packages/babel-parser/test/fixtures/experimental/class-private-properties/optional-chain-start-call/options.json new file mode 100644 index 000000000000..f26e916957c8 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-properties/optional-chain-start-call/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["classPrivateProperties"] +} diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-properties/optional-chain-start-call/output.json b/packages/babel-parser/test/fixtures/experimental/class-private-properties/optional-chain-start-call/output.json new file mode 100644 index 000000000000..3497b7a02ac3 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-properties/optional-chain-start-call/output.json @@ -0,0 +1,326 @@ +{ + "type": "File", + "start": 0, + "end": 87, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 7, + "column": 1 + } + }, + "errors": [ + "SyntaxError: Private property access cannot immediately follow an optional chain's `?.` (5:16)" + ], + "program": { + "type": "Program", + "start": 0, + "end": 87, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 7, + "column": 1 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ClassDeclaration", + "start": 0, + "end": 87, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 7, + "column": 1 + } + }, + "id": { + "type": "Identifier", + "start": 6, + "end": 9, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 9 + }, + "identifierName": "Foo" + }, + "name": "Foo" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start": 10, + "end": 87, + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 7, + "column": 1 + } + }, + "body": [ + { + "type": "ClassPrivateProperty", + "start": 14, + "end": 40, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 28 + } + }, + "static": true, + "key": { + "type": "PrivateName", + "start": 21, + "end": 23, + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 2, + "column": 11 + } + }, + "id": { + "type": "Identifier", + "start": 22, + "end": 23, + "loc": { + "start": { + "line": 2, + "column": 10 + }, + "end": { + "line": 2, + "column": 11 + }, + "identifierName": "m" + }, + "name": "m" + } + }, + "value": { + "type": "FunctionExpression", + "start": 26, + "end": 39, + "loc": { + "start": { + "line": 2, + "column": 14 + }, + "end": { + "line": 2, + "column": 27 + } + }, + "id": null, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 37, + "end": 39, + "loc": { + "start": { + "line": 2, + "column": 25 + }, + "end": { + "line": 2, + "column": 27 + } + }, + "body": [], + "directives": [] + } + } + }, + { + "type": "ClassMethod", + "start": 44, + "end": 85, + "loc": { + "start": { + "line": 4, + "column": 2 + }, + "end": { + "line": 6, + "column": 3 + } + }, + "static": true, + "key": { + "type": "Identifier", + "start": 51, + "end": 55, + "loc": { + "start": { + "line": 4, + "column": 9 + }, + "end": { + "line": 4, + "column": 13 + }, + "identifierName": "test" + }, + "name": "test" + }, + "computed": false, + "kind": "method", + "id": null, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 58, + "end": 85, + "loc": { + "start": { + "line": 4, + "column": 16 + }, + "end": { + "line": 6, + "column": 3 + } + }, + "body": [ + { + "type": "ReturnStatement", + "start": 64, + "end": 81, + "loc": { + "start": { + "line": 5, + "column": 4 + }, + "end": { + "line": 5, + "column": 21 + } + }, + "argument": { + "type": "OptionalCallExpression", + "start": 71, + "end": 80, + "loc": { + "start": { + "line": 5, + "column": 11 + }, + "end": { + "line": 5, + "column": 20 + } + }, + "callee": { + "type": "OptionalMemberExpression", + "start": 71, + "end": 78, + "loc": { + "start": { + "line": 5, + "column": 11 + }, + "end": { + "line": 5, + "column": 18 + } + }, + "object": { + "type": "Identifier", + "start": 71, + "end": 74, + "loc": { + "start": { + "line": 5, + "column": 11 + }, + "end": { + "line": 5, + "column": 14 + }, + "identifierName": "Foo" + }, + "name": "Foo" + }, + "property": { + "type": "PrivateName", + "start": 76, + "end": 78, + "loc": { + "start": { + "line": 5, + "column": 16 + }, + "end": { + "line": 5, + "column": 18 + } + }, + "id": { + "type": "Identifier", + "start": 77, + "end": 78, + "loc": { + "start": { + "line": 5, + "column": 17 + }, + "end": { + "line": 5, + "column": 18 + }, + "identifierName": "m" + }, + "name": "m" + } + }, + "computed": false, + "optional": true + }, + "arguments": [] + } + } + ], + "directives": [] + } + } + ] + } + } + ], + "directives": [] + } +} diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-properties/optional-chain-start-member-call/input.js b/packages/babel-parser/test/fixtures/experimental/class-private-properties/optional-chain-start-member-call/input.js new file mode 100644 index 000000000000..93e0a61c975b --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-properties/optional-chain-start-member-call/input.js @@ -0,0 +1,7 @@ +class Foo { + static #x = 1; + + static test() { + return Foo?.#x.toFixed(2); + } +} diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-properties/optional-chain-start-member-call/options.json b/packages/babel-parser/test/fixtures/experimental/class-private-properties/optional-chain-start-member-call/options.json new file mode 100644 index 000000000000..f26e916957c8 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-properties/optional-chain-start-member-call/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["classPrivateProperties"] +} diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-properties/optional-chain-start-member-call/output.json b/packages/babel-parser/test/fixtures/experimental/class-private-properties/optional-chain-start-member-call/output.json new file mode 100644 index 000000000000..61c1f6485f5c --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-properties/optional-chain-start-member-call/output.json @@ -0,0 +1,365 @@ +{ + "type": "File", + "start": 0, + "end": 84, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 7, + "column": 1 + } + }, + "errors": [ + "SyntaxError: Private property access cannot immediately follow an optional chain's `?.` (5:16)" + ], + "program": { + "type": "Program", + "start": 0, + "end": 84, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 7, + "column": 1 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ClassDeclaration", + "start": 0, + "end": 84, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 7, + "column": 1 + } + }, + "id": { + "type": "Identifier", + "start": 6, + "end": 9, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 9 + }, + "identifierName": "Foo" + }, + "name": "Foo" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start": 10, + "end": 84, + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 7, + "column": 1 + } + }, + "body": [ + { + "type": "ClassPrivateProperty", + "start": 14, + "end": 28, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 16 + } + }, + "static": true, + "key": { + "type": "PrivateName", + "start": 21, + "end": 23, + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 2, + "column": 11 + } + }, + "id": { + "type": "Identifier", + "start": 22, + "end": 23, + "loc": { + "start": { + "line": 2, + "column": 10 + }, + "end": { + "line": 2, + "column": 11 + }, + "identifierName": "x" + }, + "name": "x" + } + }, + "value": { + "type": "NumericLiteral", + "start": 26, + "end": 27, + "loc": { + "start": { + "line": 2, + "column": 14 + }, + "end": { + "line": 2, + "column": 15 + } + }, + "extra": { + "rawValue": 1, + "raw": "1" + }, + "value": 1 + } + }, + { + "type": "ClassMethod", + "start": 32, + "end": 82, + "loc": { + "start": { + "line": 4, + "column": 2 + }, + "end": { + "line": 6, + "column": 3 + } + }, + "static": true, + "key": { + "type": "Identifier", + "start": 39, + "end": 43, + "loc": { + "start": { + "line": 4, + "column": 9 + }, + "end": { + "line": 4, + "column": 13 + }, + "identifierName": "test" + }, + "name": "test" + }, + "computed": false, + "kind": "method", + "id": null, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 46, + "end": 82, + "loc": { + "start": { + "line": 4, + "column": 16 + }, + "end": { + "line": 6, + "column": 3 + } + }, + "body": [ + { + "type": "ReturnStatement", + "start": 52, + "end": 78, + "loc": { + "start": { + "line": 5, + "column": 4 + }, + "end": { + "line": 5, + "column": 30 + } + }, + "argument": { + "type": "OptionalCallExpression", + "start": 59, + "end": 77, + "loc": { + "start": { + "line": 5, + "column": 11 + }, + "end": { + "line": 5, + "column": 29 + } + }, + "callee": { + "type": "OptionalMemberExpression", + "start": 59, + "end": 74, + "loc": { + "start": { + "line": 5, + "column": 11 + }, + "end": { + "line": 5, + "column": 26 + } + }, + "object": { + "type": "OptionalMemberExpression", + "start": 59, + "end": 66, + "loc": { + "start": { + "line": 5, + "column": 11 + }, + "end": { + "line": 5, + "column": 18 + } + }, + "object": { + "type": "Identifier", + "start": 59, + "end": 62, + "loc": { + "start": { + "line": 5, + "column": 11 + }, + "end": { + "line": 5, + "column": 14 + }, + "identifierName": "Foo" + }, + "name": "Foo" + }, + "property": { + "type": "PrivateName", + "start": 64, + "end": 66, + "loc": { + "start": { + "line": 5, + "column": 16 + }, + "end": { + "line": 5, + "column": 18 + } + }, + "id": { + "type": "Identifier", + "start": 65, + "end": 66, + "loc": { + "start": { + "line": 5, + "column": 17 + }, + "end": { + "line": 5, + "column": 18 + }, + "identifierName": "x" + }, + "name": "x" + } + }, + "computed": false, + "optional": true + }, + "property": { + "type": "Identifier", + "start": 67, + "end": 74, + "loc": { + "start": { + "line": 5, + "column": 19 + }, + "end": { + "line": 5, + "column": 26 + }, + "identifierName": "toFixed" + }, + "name": "toFixed" + }, + "computed": false, + "optional": false + }, + "arguments": [ + { + "type": "NumericLiteral", + "start": 75, + "end": 76, + "loc": { + "start": { + "line": 5, + "column": 27 + }, + "end": { + "line": 5, + "column": 28 + } + }, + "extra": { + "rawValue": 2, + "raw": "2" + }, + "value": 2 + } + ] + } + } + ], + "directives": [] + } + } + ] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-properties/optional-chain-start-member/input.js b/packages/babel-parser/test/fixtures/experimental/class-private-properties/optional-chain-start-member/input.js new file mode 100644 index 000000000000..48bc5c3a3ffd --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-properties/optional-chain-start-member/input.js @@ -0,0 +1,7 @@ +class Foo { + static #x = 1; + + static test() { + return Foo?.#x.toFixed; + } +} diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-properties/optional-chain-start-member/options.json b/packages/babel-parser/test/fixtures/experimental/class-private-properties/optional-chain-start-member/options.json new file mode 100644 index 000000000000..f26e916957c8 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-properties/optional-chain-start-member/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["classPrivateProperties"] +} diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-properties/optional-chain-start-member/output.json b/packages/babel-parser/test/fixtures/experimental/class-private-properties/optional-chain-start-member/output.json new file mode 100644 index 000000000000..61d54387aff6 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-properties/optional-chain-start-member/output.json @@ -0,0 +1,328 @@ +{ + "type": "File", + "start": 0, + "end": 81, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 7, + "column": 1 + } + }, + "errors": [ + "SyntaxError: Private property access cannot immediately follow an optional chain's `?.` (5:16)" + ], + "program": { + "type": "Program", + "start": 0, + "end": 81, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 7, + "column": 1 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ClassDeclaration", + "start": 0, + "end": 81, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 7, + "column": 1 + } + }, + "id": { + "type": "Identifier", + "start": 6, + "end": 9, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 9 + }, + "identifierName": "Foo" + }, + "name": "Foo" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start": 10, + "end": 81, + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 7, + "column": 1 + } + }, + "body": [ + { + "type": "ClassPrivateProperty", + "start": 14, + "end": 28, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 16 + } + }, + "static": true, + "key": { + "type": "PrivateName", + "start": 21, + "end": 23, + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 2, + "column": 11 + } + }, + "id": { + "type": "Identifier", + "start": 22, + "end": 23, + "loc": { + "start": { + "line": 2, + "column": 10 + }, + "end": { + "line": 2, + "column": 11 + }, + "identifierName": "x" + }, + "name": "x" + } + }, + "value": { + "type": "NumericLiteral", + "start": 26, + "end": 27, + "loc": { + "start": { + "line": 2, + "column": 14 + }, + "end": { + "line": 2, + "column": 15 + } + }, + "extra": { + "rawValue": 1, + "raw": "1" + }, + "value": 1 + } + }, + { + "type": "ClassMethod", + "start": 32, + "end": 79, + "loc": { + "start": { + "line": 4, + "column": 2 + }, + "end": { + "line": 6, + "column": 3 + } + }, + "static": true, + "key": { + "type": "Identifier", + "start": 39, + "end": 43, + "loc": { + "start": { + "line": 4, + "column": 9 + }, + "end": { + "line": 4, + "column": 13 + }, + "identifierName": "test" + }, + "name": "test" + }, + "computed": false, + "kind": "method", + "id": null, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 46, + "end": 79, + "loc": { + "start": { + "line": 4, + "column": 16 + }, + "end": { + "line": 6, + "column": 3 + } + }, + "body": [ + { + "type": "ReturnStatement", + "start": 52, + "end": 75, + "loc": { + "start": { + "line": 5, + "column": 4 + }, + "end": { + "line": 5, + "column": 27 + } + }, + "argument": { + "type": "OptionalMemberExpression", + "start": 59, + "end": 74, + "loc": { + "start": { + "line": 5, + "column": 11 + }, + "end": { + "line": 5, + "column": 26 + } + }, + "object": { + "type": "OptionalMemberExpression", + "start": 59, + "end": 66, + "loc": { + "start": { + "line": 5, + "column": 11 + }, + "end": { + "line": 5, + "column": 18 + } + }, + "object": { + "type": "Identifier", + "start": 59, + "end": 62, + "loc": { + "start": { + "line": 5, + "column": 11 + }, + "end": { + "line": 5, + "column": 14 + }, + "identifierName": "Foo" + }, + "name": "Foo" + }, + "property": { + "type": "PrivateName", + "start": 64, + "end": 66, + "loc": { + "start": { + "line": 5, + "column": 16 + }, + "end": { + "line": 5, + "column": 18 + } + }, + "id": { + "type": "Identifier", + "start": 65, + "end": 66, + "loc": { + "start": { + "line": 5, + "column": 17 + }, + "end": { + "line": 5, + "column": 18 + }, + "identifierName": "x" + }, + "name": "x" + } + }, + "computed": false, + "optional": true + }, + "property": { + "type": "Identifier", + "start": 67, + "end": 74, + "loc": { + "start": { + "line": 5, + "column": 19 + }, + "end": { + "line": 5, + "column": 26 + }, + "identifierName": "toFixed" + }, + "name": "toFixed" + }, + "computed": false, + "optional": false + } + } + ], + "directives": [] + } + } + ] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-properties/optional-chain-start-simple/input.js b/packages/babel-parser/test/fixtures/experimental/class-private-properties/optional-chain-start-simple/input.js new file mode 100644 index 000000000000..4802298ea379 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-properties/optional-chain-start-simple/input.js @@ -0,0 +1,7 @@ +class Foo { + static #x = 1; + + static test() { + return Foo?.#x; + } +} diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-properties/optional-chain-start-simple/options.json b/packages/babel-parser/test/fixtures/experimental/class-private-properties/optional-chain-start-simple/options.json new file mode 100644 index 000000000000..f26e916957c8 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-properties/optional-chain-start-simple/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["classPrivateProperties"] +} diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-properties/optional-chain-start-simple/output.json b/packages/babel-parser/test/fixtures/experimental/class-private-properties/optional-chain-start-simple/output.json new file mode 100644 index 000000000000..8f9da5de5c11 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-properties/optional-chain-start-simple/output.json @@ -0,0 +1,294 @@ +{ + "type": "File", + "start": 0, + "end": 73, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 7, + "column": 1 + } + }, + "errors": [ + "SyntaxError: Private property access cannot immediately follow an optional chain's `?.` (5:16)" + ], + "program": { + "type": "Program", + "start": 0, + "end": 73, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 7, + "column": 1 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ClassDeclaration", + "start": 0, + "end": 73, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 7, + "column": 1 + } + }, + "id": { + "type": "Identifier", + "start": 6, + "end": 9, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 9 + }, + "identifierName": "Foo" + }, + "name": "Foo" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start": 10, + "end": 73, + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 7, + "column": 1 + } + }, + "body": [ + { + "type": "ClassPrivateProperty", + "start": 14, + "end": 28, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 16 + } + }, + "static": true, + "key": { + "type": "PrivateName", + "start": 21, + "end": 23, + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 2, + "column": 11 + } + }, + "id": { + "type": "Identifier", + "start": 22, + "end": 23, + "loc": { + "start": { + "line": 2, + "column": 10 + }, + "end": { + "line": 2, + "column": 11 + }, + "identifierName": "x" + }, + "name": "x" + } + }, + "value": { + "type": "NumericLiteral", + "start": 26, + "end": 27, + "loc": { + "start": { + "line": 2, + "column": 14 + }, + "end": { + "line": 2, + "column": 15 + } + }, + "extra": { + "rawValue": 1, + "raw": "1" + }, + "value": 1 + } + }, + { + "type": "ClassMethod", + "start": 32, + "end": 71, + "loc": { + "start": { + "line": 4, + "column": 2 + }, + "end": { + "line": 6, + "column": 3 + } + }, + "static": true, + "key": { + "type": "Identifier", + "start": 39, + "end": 43, + "loc": { + "start": { + "line": 4, + "column": 9 + }, + "end": { + "line": 4, + "column": 13 + }, + "identifierName": "test" + }, + "name": "test" + }, + "computed": false, + "kind": "method", + "id": null, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 46, + "end": 71, + "loc": { + "start": { + "line": 4, + "column": 16 + }, + "end": { + "line": 6, + "column": 3 + } + }, + "body": [ + { + "type": "ReturnStatement", + "start": 52, + "end": 67, + "loc": { + "start": { + "line": 5, + "column": 4 + }, + "end": { + "line": 5, + "column": 19 + } + }, + "argument": { + "type": "OptionalMemberExpression", + "start": 59, + "end": 66, + "loc": { + "start": { + "line": 5, + "column": 11 + }, + "end": { + "line": 5, + "column": 18 + } + }, + "object": { + "type": "Identifier", + "start": 59, + "end": 62, + "loc": { + "start": { + "line": 5, + "column": 11 + }, + "end": { + "line": 5, + "column": 14 + }, + "identifierName": "Foo" + }, + "name": "Foo" + }, + "property": { + "type": "PrivateName", + "start": 64, + "end": 66, + "loc": { + "start": { + "line": 5, + "column": 16 + }, + "end": { + "line": 5, + "column": 18 + } + }, + "id": { + "type": "Identifier", + "start": 65, + "end": 66, + "loc": { + "start": { + "line": 5, + "column": 17 + }, + "end": { + "line": 5, + "column": 18 + }, + "identifierName": "x" + }, + "name": "x" + } + }, + "computed": false, + "optional": true + } + } + ], + "directives": [] + } + } + ] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-with-transform/exec.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-with-transform/exec.js new file mode 100644 index 000000000000..215802ead54a --- /dev/null +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-with-transform/exec.js @@ -0,0 +1,25 @@ +class Foo { + static #x = 1; + static #self = Foo; + static self = Foo; + + static test() { + const o = { Foo: Foo }; + const deep = { very: { o } }; + expect(o?.Foo.#x).toEqual(1); + expect(o?.Foo.#x.toString).toEqual(1..toString); + expect(o?.Foo.#x.toString()).toEqual('1'); + + expect(deep?.very.o?.Foo.#x).toEqual(1); + expect(deep?.very.o?.Foo.#x.toString).toEqual(1..toString); + expect(deep?.very.o?.Foo.#x.toString()).toEqual('1'); + + expect(o?.Foo.#self.#x).toEqual(1); + expect(o?.Foo.#self.self.#x).toEqual(1); + expect(o?.Foo.#self?.self.#x).toEqual(1); + expect(o?.Foo.#self.self?.self.#x).toEqual(1); + expect(o?.Foo.#self?.self?.self.#x).toEqual(1); + } +} + +Foo.test(); diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-with-transform/input.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-with-transform/input.js new file mode 100644 index 000000000000..e8f18bd86f69 --- /dev/null +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-with-transform/input.js @@ -0,0 +1,25 @@ +class Foo { + static #x = 1; + static #self = Foo; + static self = Foo; + + static test() { + const o = { Foo: Foo }; + const deep = { very: { o } }; + o?.Foo.#x; + o?.Foo.#x.toString; + o?.Foo.#x.toString(); + + deep?.very.o?.Foo.#x; + deep?.very.o?.Foo.#x.toString; + deep?.very.o?.Foo.#x.toString(); + + o?.Foo.#self.#x; + o?.Foo.#self.self.#x; + o?.Foo.#self?.self.#x; + o?.Foo.#self.self?.self.#x; + o?.Foo.#self?.self?.self.#x; + } +} + +Foo.test(); diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-with-transform/options.json b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-with-transform/options.json new file mode 100644 index 000000000000..9a7eaaa890b3 --- /dev/null +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-with-transform/options.json @@ -0,0 +1,6 @@ +{ + "plugins": [ + "proposal-optional-chaining", + ["proposal-class-properties", { "loose": true }] + ] +} diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-with-transform/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-with-transform/output.js new file mode 100644 index 000000000000..458ddc1685e5 --- /dev/null +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-with-transform/output.js @@ -0,0 +1,47 @@ +function _classPrivateFieldLooseBase(receiver, privateKey) { if (!Object.prototype.hasOwnProperty.call(receiver, privateKey)) { throw new TypeError("attempted to use private field on non-instance"); } return receiver; } + +var id = 0; + +function _classPrivateFieldLooseKey(name) { return "__private_" + id++ + "_" + name; } + +class Foo { + static test() { + var _o, _ref, _o2, _ref2, _o3, _ref3, _ref4, _ref5, _ref6, _ref7, _ref8, _ref9, _o4, _ref10, _o5, _ref11, _o6, _ref12, _ref13, _ref14, _o7, _ref15, _ref16, _ref17, _o8, _ref18, _ref19, _ref20, _o9, _o10, _o11, _ref21, _ref22, _ref23, _o12, _o13, _ref24, _o14, _ref25, _o15, _ref26, _ref27, _o16; + + const o = { + Foo: Foo + }; + const deep = { + very: { + o + } + }; + (_ref = (_o9 = _o = o) === null || _o9 === void 0 ? void 0 : _o9.Foo, _o === void 0 || _o === null) ? void 0 : _classPrivateFieldLooseBase(_ref, _x)[_x]; + (_ref2 = (_o10 = _o2 = o) === null || _o10 === void 0 ? void 0 : _o10.Foo, _o2 === void 0 || _o2 === null) ? void 0 : _classPrivateFieldLooseBase(_ref2, _x)[_x].toString; + (_ref3 = (_o11 = _o3 = o) === null || _o11 === void 0 ? void 0 : _o11.Foo, _o3 === void 0 || _o3 === null) ? void 0 : _classPrivateFieldLooseBase(_ref3, _x)[_x].toString(); + (_ref5 = (_ref21 = _ref4 = deep === null || deep === void 0 ? void 0 : deep.very.o) === null || _ref21 === void 0 ? void 0 : _ref21.Foo, _ref4 === void 0 || _ref4 === null) ? void 0 : _classPrivateFieldLooseBase(_ref5, _x)[_x]; + (_ref7 = (_ref22 = _ref6 = deep === null || deep === void 0 ? void 0 : deep.very.o) === null || _ref22 === void 0 ? void 0 : _ref22.Foo, _ref6 === void 0 || _ref6 === null) ? void 0 : _classPrivateFieldLooseBase(_ref7, _x)[_x].toString; + (_ref9 = (_ref23 = _ref8 = deep === null || deep === void 0 ? void 0 : deep.very.o) === null || _ref23 === void 0 ? void 0 : _ref23.Foo, _ref8 === void 0 || _ref8 === null) ? void 0 : _classPrivateFieldLooseBase(_ref9, _x)[_x].toString(); + (_ref10 = (_o12 = _o4 = o) === null || _o12 === void 0 ? void 0 : _o12.Foo, _o4 === void 0 || _o4 === null) ? void 0 : _classPrivateFieldLooseBase(_classPrivateFieldLooseBase(_ref10, _self)[_self], _x)[_x]; + (_ref11 = (_o13 = _o5 = o) === null || _o13 === void 0 ? void 0 : _o13.Foo, _o5 === void 0 || _o5 === null) ? void 0 : _classPrivateFieldLooseBase(_classPrivateFieldLooseBase(_ref11, _self)[_self].self, _x)[_x]; + (_ref14 = (_ref24 = _ref13 = (_ref12 = (_o14 = _o6 = o) === null || _o14 === void 0 ? void 0 : _o14.Foo, _o6 === void 0 || _o6 === null) ? void 0 : _classPrivateFieldLooseBase(_ref12, _self)[_self]) === null || _ref24 === void 0 ? void 0 : _ref24.self, _ref13 === void 0 || _ref13 === null) ? void 0 : _classPrivateFieldLooseBase(_ref14, _x)[_x]; + (_ref17 = (_ref25 = _ref16 = (_ref15 = (_o15 = _o7 = o) === null || _o15 === void 0 ? void 0 : _o15.Foo, _o7 === void 0 || _o7 === null) ? void 0 : _classPrivateFieldLooseBase(_ref15, _self)[_self].self) === null || _ref25 === void 0 ? void 0 : _ref25.self, _ref16 === void 0 || _ref16 === null) ? void 0 : _classPrivateFieldLooseBase(_ref17, _x)[_x]; + (_ref20 = (_ref26 = _ref19 = (_ref27 = (_ref18 = (_o16 = _o8 = o) === null || _o16 === void 0 ? void 0 : _o16.Foo, _o8 === void 0 || _o8 === null) ? void 0 : _classPrivateFieldLooseBase(_ref18, _self)[_self]) === null || _ref27 === void 0 ? void 0 : _ref27.self) === null || _ref26 === void 0 ? void 0 : _ref26.self, _ref19 === void 0 || _ref19 === null) ? void 0 : _classPrivateFieldLooseBase(_ref20, _x)[_x]; + } + +} + +var _x = _classPrivateFieldLooseKey("x"); + +var _self = _classPrivateFieldLooseKey("self"); + +Object.defineProperty(Foo, _x, { + writable: true, + value: 1 +}); +Object.defineProperty(Foo, _self, { + writable: true, + value: Foo +}); +Foo.self = Foo; +Foo.test(); diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain/input.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain/input.js new file mode 100644 index 000000000000..e8f18bd86f69 --- /dev/null +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain/input.js @@ -0,0 +1,25 @@ +class Foo { + static #x = 1; + static #self = Foo; + static self = Foo; + + static test() { + const o = { Foo: Foo }; + const deep = { very: { o } }; + o?.Foo.#x; + o?.Foo.#x.toString; + o?.Foo.#x.toString(); + + deep?.very.o?.Foo.#x; + deep?.very.o?.Foo.#x.toString; + deep?.very.o?.Foo.#x.toString(); + + o?.Foo.#self.#x; + o?.Foo.#self.self.#x; + o?.Foo.#self?.self.#x; + o?.Foo.#self.self?.self.#x; + o?.Foo.#self?.self?.self.#x; + } +} + +Foo.test(); diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain/options.json b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain/options.json new file mode 100644 index 000000000000..693db86a79a0 --- /dev/null +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain/options.json @@ -0,0 +1,3 @@ +{ + "plugins": [["proposal-class-properties", { "loose": true }]] +} diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain/output.js new file mode 100644 index 000000000000..5d6339cd6a2f --- /dev/null +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain/output.js @@ -0,0 +1,47 @@ +function _classPrivateFieldLooseBase(receiver, privateKey) { if (!Object.prototype.hasOwnProperty.call(receiver, privateKey)) { throw new TypeError("attempted to use private field on non-instance"); } return receiver; } + +var id = 0; + +function _classPrivateFieldLooseKey(name) { return "__private_" + id++ + "_" + name; } + +class Foo { + static test() { + var _o, _ref, _o2, _ref2, _o3, _ref3, _ref4, _ref5, _ref6, _ref7, _ref8, _ref9, _o4, _ref10, _o5, _ref11, _o6, _ref12, _ref13, _ref14, _o7, _ref15, _ref16, _ref17, _o8, _ref18, _ref19, _ref20; + + const o = { + Foo: Foo + }; + const deep = { + very: { + o + } + }; + (_ref = (_o = o)?.Foo, _o === void 0 || _o === null) ? void 0 : _classPrivateFieldLooseBase(_ref, _x)[_x]; + (_ref2 = (_o2 = o)?.Foo, _o2 === void 0 || _o2 === null) ? void 0 : _classPrivateFieldLooseBase(_ref2, _x)[_x].toString; + (_ref3 = (_o3 = o)?.Foo, _o3 === void 0 || _o3 === null) ? void 0 : _classPrivateFieldLooseBase(_ref3, _x)[_x].toString(); + (_ref5 = (_ref4 = deep?.very.o)?.Foo, _ref4 === void 0 || _ref4 === null) ? void 0 : _classPrivateFieldLooseBase(_ref5, _x)[_x]; + (_ref7 = (_ref6 = deep?.very.o)?.Foo, _ref6 === void 0 || _ref6 === null) ? void 0 : _classPrivateFieldLooseBase(_ref7, _x)[_x].toString; + (_ref9 = (_ref8 = deep?.very.o)?.Foo, _ref8 === void 0 || _ref8 === null) ? void 0 : _classPrivateFieldLooseBase(_ref9, _x)[_x].toString(); + (_ref10 = (_o4 = o)?.Foo, _o4 === void 0 || _o4 === null) ? void 0 : _classPrivateFieldLooseBase(_classPrivateFieldLooseBase(_ref10, _self)[_self], _x)[_x]; + (_ref11 = (_o5 = o)?.Foo, _o5 === void 0 || _o5 === null) ? void 0 : _classPrivateFieldLooseBase(_classPrivateFieldLooseBase(_ref11, _self)[_self].self, _x)[_x]; + (_ref14 = (_ref13 = (_ref12 = (_o6 = o)?.Foo, _o6 === void 0 || _o6 === null) ? void 0 : _classPrivateFieldLooseBase(_ref12, _self)[_self])?.self, _ref13 === void 0 || _ref13 === null) ? void 0 : _classPrivateFieldLooseBase(_ref14, _x)[_x]; + (_ref17 = (_ref16 = (_ref15 = (_o7 = o)?.Foo, _o7 === void 0 || _o7 === null) ? void 0 : _classPrivateFieldLooseBase(_ref15, _self)[_self].self)?.self, _ref16 === void 0 || _ref16 === null) ? void 0 : _classPrivateFieldLooseBase(_ref17, _x)[_x]; + (_ref20 = (_ref19 = ((_ref18 = (_o8 = o)?.Foo, _o8 === void 0 || _o8 === null) ? void 0 : _classPrivateFieldLooseBase(_ref18, _self)[_self])?.self)?.self, _ref19 === void 0 || _ref19 === null) ? void 0 : _classPrivateFieldLooseBase(_ref20, _x)[_x]; + } + +} + +var _x = _classPrivateFieldLooseKey("x"); + +var _self = _classPrivateFieldLooseKey("self"); + +Object.defineProperty(Foo, _x, { + writable: true, + value: 1 +}); +Object.defineProperty(Foo, _self, { + writable: true, + value: Foo +}); +Foo.self = Foo; +Foo.test(); diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-with-transform/exec.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-with-transform/exec.js new file mode 100644 index 000000000000..215802ead54a --- /dev/null +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-with-transform/exec.js @@ -0,0 +1,25 @@ +class Foo { + static #x = 1; + static #self = Foo; + static self = Foo; + + static test() { + const o = { Foo: Foo }; + const deep = { very: { o } }; + expect(o?.Foo.#x).toEqual(1); + expect(o?.Foo.#x.toString).toEqual(1..toString); + expect(o?.Foo.#x.toString()).toEqual('1'); + + expect(deep?.very.o?.Foo.#x).toEqual(1); + expect(deep?.very.o?.Foo.#x.toString).toEqual(1..toString); + expect(deep?.very.o?.Foo.#x.toString()).toEqual('1'); + + expect(o?.Foo.#self.#x).toEqual(1); + expect(o?.Foo.#self.self.#x).toEqual(1); + expect(o?.Foo.#self?.self.#x).toEqual(1); + expect(o?.Foo.#self.self?.self.#x).toEqual(1); + expect(o?.Foo.#self?.self?.self.#x).toEqual(1); + } +} + +Foo.test(); diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-with-transform/input.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-with-transform/input.js new file mode 100644 index 000000000000..e8f18bd86f69 --- /dev/null +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-with-transform/input.js @@ -0,0 +1,25 @@ +class Foo { + static #x = 1; + static #self = Foo; + static self = Foo; + + static test() { + const o = { Foo: Foo }; + const deep = { very: { o } }; + o?.Foo.#x; + o?.Foo.#x.toString; + o?.Foo.#x.toString(); + + deep?.very.o?.Foo.#x; + deep?.very.o?.Foo.#x.toString; + deep?.very.o?.Foo.#x.toString(); + + o?.Foo.#self.#x; + o?.Foo.#self.self.#x; + o?.Foo.#self?.self.#x; + o?.Foo.#self.self?.self.#x; + o?.Foo.#self?.self?.self.#x; + } +} + +Foo.test(); diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-with-transform/options.json b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-with-transform/options.json new file mode 100644 index 000000000000..63b4c77cc8e8 --- /dev/null +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-with-transform/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["proposal-optional-chaining", "proposal-class-properties"] +} diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-with-transform/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-with-transform/output.js new file mode 100644 index 000000000000..845068af6faa --- /dev/null +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-with-transform/output.js @@ -0,0 +1,43 @@ +function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } + +function _classStaticPrivateFieldSpecGet(receiver, classConstructor, descriptor) { if (receiver !== classConstructor) { throw new TypeError("Private static access of wrong provenance"); } if (descriptor.get) { return descriptor.get.call(receiver); } return descriptor.value; } + +class Foo { + static test() { + var _o, _ref, _o2, _ref2, _o3, _ref3, _ref4, _ref5, _ref6, _ref7, _ref8, _ref9, _o4, _ref10, _o5, _ref11, _o6, _ref12, _ref13, _ref14, _o7, _ref15, _ref16, _ref17, _o8, _ref18, _ref19, _ref20, _o9, _o10, _o11, _ref21, _ref22, _ref23, _o12, _o13, _ref24, _o14, _ref25, _o15, _ref26, _ref27, _o16; + + const o = { + Foo: Foo + }; + const deep = { + very: { + o + } + }; + (_ref = (_o9 = _o = o) === null || _o9 === void 0 ? void 0 : _o9.Foo, _o === void 0 || _o === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref, Foo, _x); + (_ref2 = (_o10 = _o2 = o) === null || _o10 === void 0 ? void 0 : _o10.Foo, _o2 === void 0 || _o2 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref2, Foo, _x).toString; + (_ref3 = (_o11 = _o3 = o) === null || _o11 === void 0 ? void 0 : _o11.Foo, _o3 === void 0 || _o3 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref3, Foo, _x).toString(); + (_ref5 = (_ref21 = _ref4 = deep === null || deep === void 0 ? void 0 : deep.very.o) === null || _ref21 === void 0 ? void 0 : _ref21.Foo, _ref4 === void 0 || _ref4 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref5, Foo, _x); + (_ref7 = (_ref22 = _ref6 = deep === null || deep === void 0 ? void 0 : deep.very.o) === null || _ref22 === void 0 ? void 0 : _ref22.Foo, _ref6 === void 0 || _ref6 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref7, Foo, _x).toString; + (_ref9 = (_ref23 = _ref8 = deep === null || deep === void 0 ? void 0 : deep.very.o) === null || _ref23 === void 0 ? void 0 : _ref23.Foo, _ref8 === void 0 || _ref8 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref9, Foo, _x).toString(); + (_ref10 = (_o12 = _o4 = o) === null || _o12 === void 0 ? void 0 : _o12.Foo, _o4 === void 0 || _o4 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFieldSpecGet(_ref10, Foo, _self), Foo, _x); + (_ref11 = (_o13 = _o5 = o) === null || _o13 === void 0 ? void 0 : _o13.Foo, _o5 === void 0 || _o5 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFieldSpecGet(_ref11, Foo, _self).self, Foo, _x); + (_ref14 = (_ref24 = _ref13 = (_ref12 = (_o14 = _o6 = o) === null || _o14 === void 0 ? void 0 : _o14.Foo, _o6 === void 0 || _o6 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref12, Foo, _self)) === null || _ref24 === void 0 ? void 0 : _ref24.self, _ref13 === void 0 || _ref13 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref14, Foo, _x); + (_ref17 = (_ref25 = _ref16 = (_ref15 = (_o15 = _o7 = o) === null || _o15 === void 0 ? void 0 : _o15.Foo, _o7 === void 0 || _o7 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref15, Foo, _self).self) === null || _ref25 === void 0 ? void 0 : _ref25.self, _ref16 === void 0 || _ref16 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref17, Foo, _x); + (_ref20 = (_ref26 = _ref19 = (_ref27 = (_ref18 = (_o16 = _o8 = o) === null || _o16 === void 0 ? void 0 : _o16.Foo, _o8 === void 0 || _o8 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref18, Foo, _self)) === null || _ref27 === void 0 ? void 0 : _ref27.self) === null || _ref26 === void 0 ? void 0 : _ref26.self, _ref19 === void 0 || _ref19 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref20, Foo, _x); + } + +} + +var _x = { + writable: true, + value: 1 +}; +var _self = { + writable: true, + value: Foo +}; + +_defineProperty(Foo, "self", Foo); + +Foo.test(); diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain/input.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain/input.js new file mode 100644 index 000000000000..e8f18bd86f69 --- /dev/null +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain/input.js @@ -0,0 +1,25 @@ +class Foo { + static #x = 1; + static #self = Foo; + static self = Foo; + + static test() { + const o = { Foo: Foo }; + const deep = { very: { o } }; + o?.Foo.#x; + o?.Foo.#x.toString; + o?.Foo.#x.toString(); + + deep?.very.o?.Foo.#x; + deep?.very.o?.Foo.#x.toString; + deep?.very.o?.Foo.#x.toString(); + + o?.Foo.#self.#x; + o?.Foo.#self.self.#x; + o?.Foo.#self?.self.#x; + o?.Foo.#self.self?.self.#x; + o?.Foo.#self?.self?.self.#x; + } +} + +Foo.test(); diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain/options.json b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain/options.json new file mode 100644 index 000000000000..19ed5174f545 --- /dev/null +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["proposal-class-properties"] +} diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain/output.js new file mode 100644 index 000000000000..908d2cf6a3f3 --- /dev/null +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain/output.js @@ -0,0 +1,43 @@ +function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } + +function _classStaticPrivateFieldSpecGet(receiver, classConstructor, descriptor) { if (receiver !== classConstructor) { throw new TypeError("Private static access of wrong provenance"); } if (descriptor.get) { return descriptor.get.call(receiver); } return descriptor.value; } + +class Foo { + static test() { + var _o, _ref, _o2, _ref2, _o3, _ref3, _ref4, _ref5, _ref6, _ref7, _ref8, _ref9, _o4, _ref10, _o5, _ref11, _o6, _ref12, _ref13, _ref14, _o7, _ref15, _ref16, _ref17, _o8, _ref18, _ref19, _ref20; + + const o = { + Foo: Foo + }; + const deep = { + very: { + o + } + }; + (_ref = (_o = o)?.Foo, _o === void 0 || _o === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref, Foo, _x); + (_ref2 = (_o2 = o)?.Foo, _o2 === void 0 || _o2 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref2, Foo, _x).toString; + (_ref3 = (_o3 = o)?.Foo, _o3 === void 0 || _o3 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref3, Foo, _x).toString(); + (_ref5 = (_ref4 = deep?.very.o)?.Foo, _ref4 === void 0 || _ref4 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref5, Foo, _x); + (_ref7 = (_ref6 = deep?.very.o)?.Foo, _ref6 === void 0 || _ref6 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref7, Foo, _x).toString; + (_ref9 = (_ref8 = deep?.very.o)?.Foo, _ref8 === void 0 || _ref8 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref9, Foo, _x).toString(); + (_ref10 = (_o4 = o)?.Foo, _o4 === void 0 || _o4 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFieldSpecGet(_ref10, Foo, _self), Foo, _x); + (_ref11 = (_o5 = o)?.Foo, _o5 === void 0 || _o5 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFieldSpecGet(_ref11, Foo, _self).self, Foo, _x); + (_ref14 = (_ref13 = (_ref12 = (_o6 = o)?.Foo, _o6 === void 0 || _o6 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref12, Foo, _self))?.self, _ref13 === void 0 || _ref13 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref14, Foo, _x); + (_ref17 = (_ref16 = (_ref15 = (_o7 = o)?.Foo, _o7 === void 0 || _o7 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref15, Foo, _self).self)?.self, _ref16 === void 0 || _ref16 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref17, Foo, _x); + (_ref20 = (_ref19 = ((_ref18 = (_o8 = o)?.Foo, _o8 === void 0 || _o8 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref18, Foo, _self))?.self)?.self, _ref19 === void 0 || _ref19 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref20, Foo, _x); + } + +} + +var _x = { + writable: true, + value: 1 +}; +var _self = { + writable: true, + value: Foo +}; + +_defineProperty(Foo, "self", Foo); + +Foo.test(); From 844f4bdc000986df272f701177480bd4c447465c Mon Sep 17 00:00:00 2001 From: Justin Ridgewell Date: Fri, 13 Mar 2020 04:07:38 -0400 Subject: [PATCH 02/20] Comments, tests, and fixes --- .../src/index.js | 64 ++++++++++++------- .../optional-chain-with-transform/exec.js | 21 ++++++ .../optional-chain-with-transform/input.js | 21 ++++++ .../optional-chain-with-transform/output.js | 34 ++++++++-- .../private-loose/optional-chain/input.js | 21 ++++++ .../private-loose/optional-chain/output.js | 22 ++++++- .../optional-chain-with-transform/exec.js | 21 ++++++ .../optional-chain-with-transform/input.js | 21 ++++++ .../optional-chain-with-transform/output.js | 34 ++++++++-- .../fixtures/private/optional-chain/input.js | 21 ++++++ .../fixtures/private/optional-chain/output.js | 22 ++++++- 11 files changed, 263 insertions(+), 39 deletions(-) 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 28d814df35df..4b558f51055f 100644 --- a/packages/babel-helper-member-expression-to-functions/src/index.js +++ b/packages/babel-helper-member-expression-to-functions/src/index.js @@ -38,17 +38,31 @@ const handle = { const { node, parent, parentPath } = member; if (member.isOptionalMemberExpression()) { - const root = member.find(({ node, parent, parentPath }) => { + // We're looking for the end of _this_ optional chain, which is actually + // the "rightmost" property access of the chain. This is because + // everything up to that property access is "optional". + // + // Let's take the case of `FOO?.BAR.baz?.qux`, with `FOO?.BAR` being our + // member. The "end" to most users would be `qux` property access. + // Everything up to it could be skipped if it `FOO` were nullish. But + // actually, we can consider the `baz` access to be the end. So we're + // looking for the nearest optional chain that is `optional: true`. + const endPath = member.find(({ node, parent, parentPath }) => { if (parentPath.isOptionalMemberExpression()) { + // We need to check `parent.object` since we could be inside the + // computed expression of a `bad?.[FOO?.BAR]`. In this case, the + // endPath is the `FOO?.BAR` member itself. return parent.optional || parent.object !== node; } if (parentPath.isOptionalCallExpression()) { + // Checking `parent.callee` since we could be in the arguments, eg + // `bad?.(FOO?.BAR)`. return parent.optional || parent.callee !== node; } return true; }); - const rootParentPath = root.parentPath; + const rootParentPath = endPath.parentPath; if ( rootParentPath.isUpdateExpression({ argument: node }) || rootParentPath.isAssignmentExpression({ left: node }) @@ -65,37 +79,41 @@ const handle = { ); } - let nearestOptional = member; + // Now, we're looking for the start of this optional chain, which is + // optional to the left of this member. + // + // Let's take the case of `foo?.bar?.baz.QUX?.BAM`, with `QUX?.BAM` being + // our member. The "start" to most users would be `foo` object access. + // But actually, we can consider the `bar` access to be the start. So + // we're looking for the nearest optional chain that is `optional: true`, + // which is guaranteed to be somewhere in the object/callee tree. + let startingOptional = member; for (;;) { - if (nearestOptional.isOptionalMemberExpression()) { - if (nearestOptional.node.optional) break; - nearestOptional = nearestOptional.get("object"); + if (startingOptional.isOptionalMemberExpression()) { + if (startingOptional.node.optional) break; + startingOptional = startingOptional.get("object"); continue; - } else if (nearestOptional.isOptionalCallExpression()) { - if (nearestOptional.node.optional) break; - nearestOptional = nearestOptional.get("object"); + } else if (startingOptional.isOptionalCallExpression()) { + if (startingOptional.node.optional) break; + startingOptional = startingOptional.get("callee"); continue; } - - throw nearestOptional.buildCodeFrameError( - "failed to find nearest optional", - ); } const { scope } = member; const { object } = node; - const baseRef = scope.generateUidIdentifierBasedOnNode( - nearestOptional.node.object, - ); + const startingProp = startingOptional.isOptionalMemberExpression() + ? "object" + : "callee"; + const startingNode = startingOptional.node[startingProp]; + const baseRef = scope.generateUidIdentifierBasedOnNode(startingNode); const valueRef = scope.generateUidIdentifierBasedOnNode(object); scope.push({ id: baseRef }); scope.push({ id: valueRef }); - nearestOptional - .get("object") - .replaceWith( - t.assignmentExpression("=", baseRef, nearestOptional.node.object), - ); + startingOptional + .get(startingProp) + .replaceWith(t.assignmentExpression("=", baseRef, startingNode)); member.replaceWith(t.memberExpression(valueRef, node.property)); if (parentPath.isOptionalCallExpression({ callee: node })) { @@ -105,7 +123,7 @@ const handle = { } let regular = member.node; - for (let current = member; current !== root; ) { + for (let current = member; current !== endPath; ) { const { parentPath, parent } = current; if (parentPath.isOptionalMemberExpression()) { regular = t.memberExpression( @@ -119,7 +137,7 @@ const handle = { current = parentPath; } - root.replaceWith( + endPath.replaceWith( t.conditionalExpression( t.sequenceExpression([ t.assignmentExpression("=", valueRef, object), diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-with-transform/exec.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-with-transform/exec.js index 215802ead54a..dd3502ead93c 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-with-transform/exec.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-with-transform/exec.js @@ -6,6 +6,13 @@ class Foo { static test() { const o = { Foo: Foo }; const deep = { very: { o } }; + function fn() { + return o; + } + function fnDeep() { + return deep; + } + expect(o?.Foo.#x).toEqual(1); expect(o?.Foo.#x.toString).toEqual(1..toString); expect(o?.Foo.#x.toString()).toEqual('1'); @@ -19,6 +26,20 @@ class Foo { expect(o?.Foo.#self?.self.#x).toEqual(1); expect(o?.Foo.#self.self?.self.#x).toEqual(1); expect(o?.Foo.#self?.self?.self.#x).toEqual(1); + + expect(fn?.().Foo.#x).toEqual(1); + expect(fn?.().Foo.#x.toString).toEqual(1..toString); + expect(fn?.().Foo.#x.toString()).toEqual('1'); + + expect(fnDeep?.().very.o?.Foo.#x).toEqual(1); + expect(fnDeep?.().very.o?.Foo.#x.toString).toEqual(1..toString); + expect(fnDeep?.().very.o?.Foo.#x.toString()).toEqual('1'); + + expect(fn?.().Foo.#self.#x).toEqual(1); + expect(fn?.().Foo.#self.self.#x).toEqual(1); + expect(fn?.().Foo.#self?.self.#x).toEqual(1); + expect(fn?.().Foo.#self.self?.self.#x).toEqual(1); + expect(fn?.().Foo.#self?.self?.self.#x).toEqual(1); } } diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-with-transform/input.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-with-transform/input.js index e8f18bd86f69..c9c6e861fd9c 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-with-transform/input.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-with-transform/input.js @@ -6,6 +6,13 @@ class Foo { static test() { const o = { Foo: Foo }; const deep = { very: { o } }; + function fn() { + return o; + } + function fnDeep() { + return deep; + } + o?.Foo.#x; o?.Foo.#x.toString; o?.Foo.#x.toString(); @@ -19,6 +26,20 @@ class Foo { o?.Foo.#self?.self.#x; o?.Foo.#self.self?.self.#x; o?.Foo.#self?.self?.self.#x; + + fn?.().Foo.#x; + fn?.().Foo.#x.toString; + fn?.().Foo.#x.toString(); + + fnDeep?.().very.o?.Foo.#x; + fnDeep?.().very.o?.Foo.#x.toString; + fnDeep?.().very.o?.Foo.#x.toString(); + + fn?.().Foo.#self.#x; + fn?.().Foo.#self.self.#x; + fn?.().Foo.#self?.self.#x; + fn?.().Foo.#self.self?.self.#x; + fn?.().Foo.#self?.self?.self.#x; } } diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-with-transform/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-with-transform/output.js index 458ddc1685e5..456449f649bc 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-with-transform/output.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-with-transform/output.js @@ -6,7 +6,7 @@ function _classPrivateFieldLooseKey(name) { return "__private_" + id++ + "_" + n class Foo { static test() { - var _o, _ref, _o2, _ref2, _o3, _ref3, _ref4, _ref5, _ref6, _ref7, _ref8, _ref9, _o4, _ref10, _o5, _ref11, _o6, _ref12, _ref13, _ref14, _o7, _ref15, _ref16, _ref17, _o8, _ref18, _ref19, _ref20, _o9, _o10, _o11, _ref21, _ref22, _ref23, _o12, _o13, _ref24, _o14, _ref25, _o15, _ref26, _ref27, _o16; + var _o, _ref, _o2, _ref2, _o3, _ref3, _ref4, _ref5, _ref6, _ref7, _ref8, _ref9, _o4, _ref10, _o5, _ref11, _o6, _ref12, _ref13, _ref14, _o7, _ref15, _ref16, _ref17, _o8, _ref18, _ref19, _ref20, _fn, _ref21, _fn2, _ref22, _fn3, _ref23, _ref24, _ref25, _ref26, _ref27, _ref28, _ref29, _fn4, _ref30, _fn5, _ref31, _fn6, _ref32, _ref33, _ref34, _fn7, _ref35, _ref36, _ref37, _fn8, _ref38, _ref39, _ref40, _o9, _o10, _o11, _ref41, _ref42, _ref43, _o12, _o13, _ref44, _o14, _ref45, _o15, _ref46, _ref47, _o16, _fn9, _fn10, _fn11, _ref48, _ref49, _ref50, _fn12, _fn13, _ref51, _fn14, _ref52, _fn15, _ref53, _ref54, _fn16; const o = { Foo: Foo @@ -16,17 +16,37 @@ class Foo { o } }; + + function fn() { + return o; + } + + function fnDeep() { + return deep; + } + (_ref = (_o9 = _o = o) === null || _o9 === void 0 ? void 0 : _o9.Foo, _o === void 0 || _o === null) ? void 0 : _classPrivateFieldLooseBase(_ref, _x)[_x]; (_ref2 = (_o10 = _o2 = o) === null || _o10 === void 0 ? void 0 : _o10.Foo, _o2 === void 0 || _o2 === null) ? void 0 : _classPrivateFieldLooseBase(_ref2, _x)[_x].toString; (_ref3 = (_o11 = _o3 = o) === null || _o11 === void 0 ? void 0 : _o11.Foo, _o3 === void 0 || _o3 === null) ? void 0 : _classPrivateFieldLooseBase(_ref3, _x)[_x].toString(); - (_ref5 = (_ref21 = _ref4 = deep === null || deep === void 0 ? void 0 : deep.very.o) === null || _ref21 === void 0 ? void 0 : _ref21.Foo, _ref4 === void 0 || _ref4 === null) ? void 0 : _classPrivateFieldLooseBase(_ref5, _x)[_x]; - (_ref7 = (_ref22 = _ref6 = deep === null || deep === void 0 ? void 0 : deep.very.o) === null || _ref22 === void 0 ? void 0 : _ref22.Foo, _ref6 === void 0 || _ref6 === null) ? void 0 : _classPrivateFieldLooseBase(_ref7, _x)[_x].toString; - (_ref9 = (_ref23 = _ref8 = deep === null || deep === void 0 ? void 0 : deep.very.o) === null || _ref23 === void 0 ? void 0 : _ref23.Foo, _ref8 === void 0 || _ref8 === null) ? void 0 : _classPrivateFieldLooseBase(_ref9, _x)[_x].toString(); + (_ref5 = (_ref41 = _ref4 = deep === null || deep === void 0 ? void 0 : deep.very.o) === null || _ref41 === void 0 ? void 0 : _ref41.Foo, _ref4 === void 0 || _ref4 === null) ? void 0 : _classPrivateFieldLooseBase(_ref5, _x)[_x]; + (_ref7 = (_ref42 = _ref6 = deep === null || deep === void 0 ? void 0 : deep.very.o) === null || _ref42 === void 0 ? void 0 : _ref42.Foo, _ref6 === void 0 || _ref6 === null) ? void 0 : _classPrivateFieldLooseBase(_ref7, _x)[_x].toString; + (_ref9 = (_ref43 = _ref8 = deep === null || deep === void 0 ? void 0 : deep.very.o) === null || _ref43 === void 0 ? void 0 : _ref43.Foo, _ref8 === void 0 || _ref8 === null) ? void 0 : _classPrivateFieldLooseBase(_ref9, _x)[_x].toString(); (_ref10 = (_o12 = _o4 = o) === null || _o12 === void 0 ? void 0 : _o12.Foo, _o4 === void 0 || _o4 === null) ? void 0 : _classPrivateFieldLooseBase(_classPrivateFieldLooseBase(_ref10, _self)[_self], _x)[_x]; (_ref11 = (_o13 = _o5 = o) === null || _o13 === void 0 ? void 0 : _o13.Foo, _o5 === void 0 || _o5 === null) ? void 0 : _classPrivateFieldLooseBase(_classPrivateFieldLooseBase(_ref11, _self)[_self].self, _x)[_x]; - (_ref14 = (_ref24 = _ref13 = (_ref12 = (_o14 = _o6 = o) === null || _o14 === void 0 ? void 0 : _o14.Foo, _o6 === void 0 || _o6 === null) ? void 0 : _classPrivateFieldLooseBase(_ref12, _self)[_self]) === null || _ref24 === void 0 ? void 0 : _ref24.self, _ref13 === void 0 || _ref13 === null) ? void 0 : _classPrivateFieldLooseBase(_ref14, _x)[_x]; - (_ref17 = (_ref25 = _ref16 = (_ref15 = (_o15 = _o7 = o) === null || _o15 === void 0 ? void 0 : _o15.Foo, _o7 === void 0 || _o7 === null) ? void 0 : _classPrivateFieldLooseBase(_ref15, _self)[_self].self) === null || _ref25 === void 0 ? void 0 : _ref25.self, _ref16 === void 0 || _ref16 === null) ? void 0 : _classPrivateFieldLooseBase(_ref17, _x)[_x]; - (_ref20 = (_ref26 = _ref19 = (_ref27 = (_ref18 = (_o16 = _o8 = o) === null || _o16 === void 0 ? void 0 : _o16.Foo, _o8 === void 0 || _o8 === null) ? void 0 : _classPrivateFieldLooseBase(_ref18, _self)[_self]) === null || _ref27 === void 0 ? void 0 : _ref27.self) === null || _ref26 === void 0 ? void 0 : _ref26.self, _ref19 === void 0 || _ref19 === null) ? void 0 : _classPrivateFieldLooseBase(_ref20, _x)[_x]; + (_ref14 = (_ref44 = _ref13 = (_ref12 = (_o14 = _o6 = o) === null || _o14 === void 0 ? void 0 : _o14.Foo, _o6 === void 0 || _o6 === null) ? void 0 : _classPrivateFieldLooseBase(_ref12, _self)[_self]) === null || _ref44 === void 0 ? void 0 : _ref44.self, _ref13 === void 0 || _ref13 === null) ? void 0 : _classPrivateFieldLooseBase(_ref14, _x)[_x]; + (_ref17 = (_ref45 = _ref16 = (_ref15 = (_o15 = _o7 = o) === null || _o15 === void 0 ? void 0 : _o15.Foo, _o7 === void 0 || _o7 === null) ? void 0 : _classPrivateFieldLooseBase(_ref15, _self)[_self].self) === null || _ref45 === void 0 ? void 0 : _ref45.self, _ref16 === void 0 || _ref16 === null) ? void 0 : _classPrivateFieldLooseBase(_ref17, _x)[_x]; + (_ref20 = (_ref46 = _ref19 = (_ref47 = (_ref18 = (_o16 = _o8 = o) === null || _o16 === void 0 ? void 0 : _o16.Foo, _o8 === void 0 || _o8 === null) ? void 0 : _classPrivateFieldLooseBase(_ref18, _self)[_self]) === null || _ref47 === void 0 ? void 0 : _ref47.self) === null || _ref46 === void 0 ? void 0 : _ref46.self, _ref19 === void 0 || _ref19 === null) ? void 0 : _classPrivateFieldLooseBase(_ref20, _x)[_x]; + (_ref21 = (_fn9 = _fn = fn) === null || _fn9 === void 0 ? void 0 : _fn9().Foo, _fn === void 0 || _fn === null) ? void 0 : _classPrivateFieldLooseBase(_ref21, _x)[_x]; + (_ref22 = (_fn10 = _fn2 = fn) === null || _fn10 === void 0 ? void 0 : _fn10().Foo, _fn2 === void 0 || _fn2 === null) ? void 0 : _classPrivateFieldLooseBase(_ref22, _x)[_x].toString; + (_ref23 = (_fn11 = _fn3 = fn) === null || _fn11 === void 0 ? void 0 : _fn11().Foo, _fn3 === void 0 || _fn3 === null) ? void 0 : _classPrivateFieldLooseBase(_ref23, _x)[_x].toString(); + (_ref25 = (_ref48 = _ref24 = fnDeep === null || fnDeep === void 0 ? void 0 : fnDeep().very.o) === null || _ref48 === void 0 ? void 0 : _ref48.Foo, _ref24 === void 0 || _ref24 === null) ? void 0 : _classPrivateFieldLooseBase(_ref25, _x)[_x]; + (_ref27 = (_ref49 = _ref26 = fnDeep === null || fnDeep === void 0 ? void 0 : fnDeep().very.o) === null || _ref49 === void 0 ? void 0 : _ref49.Foo, _ref26 === void 0 || _ref26 === null) ? void 0 : _classPrivateFieldLooseBase(_ref27, _x)[_x].toString; + (_ref29 = (_ref50 = _ref28 = fnDeep === null || fnDeep === void 0 ? void 0 : fnDeep().very.o) === null || _ref50 === void 0 ? void 0 : _ref50.Foo, _ref28 === void 0 || _ref28 === null) ? void 0 : _classPrivateFieldLooseBase(_ref29, _x)[_x].toString(); + (_ref30 = (_fn12 = _fn4 = fn) === null || _fn12 === void 0 ? void 0 : _fn12().Foo, _fn4 === void 0 || _fn4 === null) ? void 0 : _classPrivateFieldLooseBase(_classPrivateFieldLooseBase(_ref30, _self)[_self], _x)[_x]; + (_ref31 = (_fn13 = _fn5 = fn) === null || _fn13 === void 0 ? void 0 : _fn13().Foo, _fn5 === void 0 || _fn5 === null) ? void 0 : _classPrivateFieldLooseBase(_classPrivateFieldLooseBase(_ref31, _self)[_self].self, _x)[_x]; + (_ref34 = (_ref51 = _ref33 = (_ref32 = (_fn14 = _fn6 = fn) === null || _fn14 === void 0 ? void 0 : _fn14().Foo, _fn6 === void 0 || _fn6 === null) ? void 0 : _classPrivateFieldLooseBase(_ref32, _self)[_self]) === null || _ref51 === void 0 ? void 0 : _ref51.self, _ref33 === void 0 || _ref33 === null) ? void 0 : _classPrivateFieldLooseBase(_ref34, _x)[_x]; + (_ref37 = (_ref52 = _ref36 = (_ref35 = (_fn15 = _fn7 = fn) === null || _fn15 === void 0 ? void 0 : _fn15().Foo, _fn7 === void 0 || _fn7 === null) ? void 0 : _classPrivateFieldLooseBase(_ref35, _self)[_self].self) === null || _ref52 === void 0 ? void 0 : _ref52.self, _ref36 === void 0 || _ref36 === null) ? void 0 : _classPrivateFieldLooseBase(_ref37, _x)[_x]; + (_ref40 = (_ref53 = _ref39 = (_ref54 = (_ref38 = (_fn16 = _fn8 = fn) === null || _fn16 === void 0 ? void 0 : _fn16().Foo, _fn8 === void 0 || _fn8 === null) ? void 0 : _classPrivateFieldLooseBase(_ref38, _self)[_self]) === null || _ref54 === void 0 ? void 0 : _ref54.self) === null || _ref53 === void 0 ? void 0 : _ref53.self, _ref39 === void 0 || _ref39 === null) ? void 0 : _classPrivateFieldLooseBase(_ref40, _x)[_x]; } } diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain/input.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain/input.js index e8f18bd86f69..c9c6e861fd9c 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain/input.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain/input.js @@ -6,6 +6,13 @@ class Foo { static test() { const o = { Foo: Foo }; const deep = { very: { o } }; + function fn() { + return o; + } + function fnDeep() { + return deep; + } + o?.Foo.#x; o?.Foo.#x.toString; o?.Foo.#x.toString(); @@ -19,6 +26,20 @@ class Foo { o?.Foo.#self?.self.#x; o?.Foo.#self.self?.self.#x; o?.Foo.#self?.self?.self.#x; + + fn?.().Foo.#x; + fn?.().Foo.#x.toString; + fn?.().Foo.#x.toString(); + + fnDeep?.().very.o?.Foo.#x; + fnDeep?.().very.o?.Foo.#x.toString; + fnDeep?.().very.o?.Foo.#x.toString(); + + fn?.().Foo.#self.#x; + fn?.().Foo.#self.self.#x; + fn?.().Foo.#self?.self.#x; + fn?.().Foo.#self.self?.self.#x; + fn?.().Foo.#self?.self?.self.#x; } } diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain/output.js index 5d6339cd6a2f..bdbb9035b179 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain/output.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain/output.js @@ -6,7 +6,7 @@ function _classPrivateFieldLooseKey(name) { return "__private_" + id++ + "_" + n class Foo { static test() { - var _o, _ref, _o2, _ref2, _o3, _ref3, _ref4, _ref5, _ref6, _ref7, _ref8, _ref9, _o4, _ref10, _o5, _ref11, _o6, _ref12, _ref13, _ref14, _o7, _ref15, _ref16, _ref17, _o8, _ref18, _ref19, _ref20; + var _o, _ref, _o2, _ref2, _o3, _ref3, _ref4, _ref5, _ref6, _ref7, _ref8, _ref9, _o4, _ref10, _o5, _ref11, _o6, _ref12, _ref13, _ref14, _o7, _ref15, _ref16, _ref17, _o8, _ref18, _ref19, _ref20, _fn, _ref21, _fn2, _ref22, _fn3, _ref23, _ref24, _ref25, _ref26, _ref27, _ref28, _ref29, _fn4, _ref30, _fn5, _ref31, _fn6, _ref32, _ref33, _ref34, _fn7, _ref35, _ref36, _ref37, _fn8, _ref38, _ref39, _ref40; const o = { Foo: Foo @@ -16,6 +16,15 @@ class Foo { o } }; + + function fn() { + return o; + } + + function fnDeep() { + return deep; + } + (_ref = (_o = o)?.Foo, _o === void 0 || _o === null) ? void 0 : _classPrivateFieldLooseBase(_ref, _x)[_x]; (_ref2 = (_o2 = o)?.Foo, _o2 === void 0 || _o2 === null) ? void 0 : _classPrivateFieldLooseBase(_ref2, _x)[_x].toString; (_ref3 = (_o3 = o)?.Foo, _o3 === void 0 || _o3 === null) ? void 0 : _classPrivateFieldLooseBase(_ref3, _x)[_x].toString(); @@ -27,6 +36,17 @@ class Foo { (_ref14 = (_ref13 = (_ref12 = (_o6 = o)?.Foo, _o6 === void 0 || _o6 === null) ? void 0 : _classPrivateFieldLooseBase(_ref12, _self)[_self])?.self, _ref13 === void 0 || _ref13 === null) ? void 0 : _classPrivateFieldLooseBase(_ref14, _x)[_x]; (_ref17 = (_ref16 = (_ref15 = (_o7 = o)?.Foo, _o7 === void 0 || _o7 === null) ? void 0 : _classPrivateFieldLooseBase(_ref15, _self)[_self].self)?.self, _ref16 === void 0 || _ref16 === null) ? void 0 : _classPrivateFieldLooseBase(_ref17, _x)[_x]; (_ref20 = (_ref19 = ((_ref18 = (_o8 = o)?.Foo, _o8 === void 0 || _o8 === null) ? void 0 : _classPrivateFieldLooseBase(_ref18, _self)[_self])?.self)?.self, _ref19 === void 0 || _ref19 === null) ? void 0 : _classPrivateFieldLooseBase(_ref20, _x)[_x]; + (_ref21 = (_fn = fn)?.().Foo, _fn === void 0 || _fn === null) ? void 0 : _classPrivateFieldLooseBase(_ref21, _x)[_x]; + (_ref22 = (_fn2 = fn)?.().Foo, _fn2 === void 0 || _fn2 === null) ? void 0 : _classPrivateFieldLooseBase(_ref22, _x)[_x].toString; + (_ref23 = (_fn3 = fn)?.().Foo, _fn3 === void 0 || _fn3 === null) ? void 0 : _classPrivateFieldLooseBase(_ref23, _x)[_x].toString(); + (_ref25 = (_ref24 = fnDeep?.().very.o)?.Foo, _ref24 === void 0 || _ref24 === null) ? void 0 : _classPrivateFieldLooseBase(_ref25, _x)[_x]; + (_ref27 = (_ref26 = fnDeep?.().very.o)?.Foo, _ref26 === void 0 || _ref26 === null) ? void 0 : _classPrivateFieldLooseBase(_ref27, _x)[_x].toString; + (_ref29 = (_ref28 = fnDeep?.().very.o)?.Foo, _ref28 === void 0 || _ref28 === null) ? void 0 : _classPrivateFieldLooseBase(_ref29, _x)[_x].toString(); + (_ref30 = (_fn4 = fn)?.().Foo, _fn4 === void 0 || _fn4 === null) ? void 0 : _classPrivateFieldLooseBase(_classPrivateFieldLooseBase(_ref30, _self)[_self], _x)[_x]; + (_ref31 = (_fn5 = fn)?.().Foo, _fn5 === void 0 || _fn5 === null) ? void 0 : _classPrivateFieldLooseBase(_classPrivateFieldLooseBase(_ref31, _self)[_self].self, _x)[_x]; + (_ref34 = (_ref33 = (_ref32 = (_fn6 = fn)?.().Foo, _fn6 === void 0 || _fn6 === null) ? void 0 : _classPrivateFieldLooseBase(_ref32, _self)[_self])?.self, _ref33 === void 0 || _ref33 === null) ? void 0 : _classPrivateFieldLooseBase(_ref34, _x)[_x]; + (_ref37 = (_ref36 = (_ref35 = (_fn7 = fn)?.().Foo, _fn7 === void 0 || _fn7 === null) ? void 0 : _classPrivateFieldLooseBase(_ref35, _self)[_self].self)?.self, _ref36 === void 0 || _ref36 === null) ? void 0 : _classPrivateFieldLooseBase(_ref37, _x)[_x]; + (_ref40 = (_ref39 = ((_ref38 = (_fn8 = fn)?.().Foo, _fn8 === void 0 || _fn8 === null) ? void 0 : _classPrivateFieldLooseBase(_ref38, _self)[_self])?.self)?.self, _ref39 === void 0 || _ref39 === null) ? void 0 : _classPrivateFieldLooseBase(_ref40, _x)[_x]; } } diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-with-transform/exec.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-with-transform/exec.js index 215802ead54a..dd3502ead93c 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-with-transform/exec.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-with-transform/exec.js @@ -6,6 +6,13 @@ class Foo { static test() { const o = { Foo: Foo }; const deep = { very: { o } }; + function fn() { + return o; + } + function fnDeep() { + return deep; + } + expect(o?.Foo.#x).toEqual(1); expect(o?.Foo.#x.toString).toEqual(1..toString); expect(o?.Foo.#x.toString()).toEqual('1'); @@ -19,6 +26,20 @@ class Foo { expect(o?.Foo.#self?.self.#x).toEqual(1); expect(o?.Foo.#self.self?.self.#x).toEqual(1); expect(o?.Foo.#self?.self?.self.#x).toEqual(1); + + expect(fn?.().Foo.#x).toEqual(1); + expect(fn?.().Foo.#x.toString).toEqual(1..toString); + expect(fn?.().Foo.#x.toString()).toEqual('1'); + + expect(fnDeep?.().very.o?.Foo.#x).toEqual(1); + expect(fnDeep?.().very.o?.Foo.#x.toString).toEqual(1..toString); + expect(fnDeep?.().very.o?.Foo.#x.toString()).toEqual('1'); + + expect(fn?.().Foo.#self.#x).toEqual(1); + expect(fn?.().Foo.#self.self.#x).toEqual(1); + expect(fn?.().Foo.#self?.self.#x).toEqual(1); + expect(fn?.().Foo.#self.self?.self.#x).toEqual(1); + expect(fn?.().Foo.#self?.self?.self.#x).toEqual(1); } } diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-with-transform/input.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-with-transform/input.js index e8f18bd86f69..c9c6e861fd9c 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-with-transform/input.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-with-transform/input.js @@ -6,6 +6,13 @@ class Foo { static test() { const o = { Foo: Foo }; const deep = { very: { o } }; + function fn() { + return o; + } + function fnDeep() { + return deep; + } + o?.Foo.#x; o?.Foo.#x.toString; o?.Foo.#x.toString(); @@ -19,6 +26,20 @@ class Foo { o?.Foo.#self?.self.#x; o?.Foo.#self.self?.self.#x; o?.Foo.#self?.self?.self.#x; + + fn?.().Foo.#x; + fn?.().Foo.#x.toString; + fn?.().Foo.#x.toString(); + + fnDeep?.().very.o?.Foo.#x; + fnDeep?.().very.o?.Foo.#x.toString; + fnDeep?.().very.o?.Foo.#x.toString(); + + fn?.().Foo.#self.#x; + fn?.().Foo.#self.self.#x; + fn?.().Foo.#self?.self.#x; + fn?.().Foo.#self.self?.self.#x; + fn?.().Foo.#self?.self?.self.#x; } } diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-with-transform/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-with-transform/output.js index 845068af6faa..b996ec70f87f 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-with-transform/output.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-with-transform/output.js @@ -4,7 +4,7 @@ function _classStaticPrivateFieldSpecGet(receiver, classConstructor, descriptor) class Foo { static test() { - var _o, _ref, _o2, _ref2, _o3, _ref3, _ref4, _ref5, _ref6, _ref7, _ref8, _ref9, _o4, _ref10, _o5, _ref11, _o6, _ref12, _ref13, _ref14, _o7, _ref15, _ref16, _ref17, _o8, _ref18, _ref19, _ref20, _o9, _o10, _o11, _ref21, _ref22, _ref23, _o12, _o13, _ref24, _o14, _ref25, _o15, _ref26, _ref27, _o16; + var _o, _ref, _o2, _ref2, _o3, _ref3, _ref4, _ref5, _ref6, _ref7, _ref8, _ref9, _o4, _ref10, _o5, _ref11, _o6, _ref12, _ref13, _ref14, _o7, _ref15, _ref16, _ref17, _o8, _ref18, _ref19, _ref20, _fn, _ref21, _fn2, _ref22, _fn3, _ref23, _ref24, _ref25, _ref26, _ref27, _ref28, _ref29, _fn4, _ref30, _fn5, _ref31, _fn6, _ref32, _ref33, _ref34, _fn7, _ref35, _ref36, _ref37, _fn8, _ref38, _ref39, _ref40, _o9, _o10, _o11, _ref41, _ref42, _ref43, _o12, _o13, _ref44, _o14, _ref45, _o15, _ref46, _ref47, _o16, _fn9, _fn10, _fn11, _ref48, _ref49, _ref50, _fn12, _fn13, _ref51, _fn14, _ref52, _fn15, _ref53, _ref54, _fn16; const o = { Foo: Foo @@ -14,17 +14,37 @@ class Foo { o } }; + + function fn() { + return o; + } + + function fnDeep() { + return deep; + } + (_ref = (_o9 = _o = o) === null || _o9 === void 0 ? void 0 : _o9.Foo, _o === void 0 || _o === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref, Foo, _x); (_ref2 = (_o10 = _o2 = o) === null || _o10 === void 0 ? void 0 : _o10.Foo, _o2 === void 0 || _o2 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref2, Foo, _x).toString; (_ref3 = (_o11 = _o3 = o) === null || _o11 === void 0 ? void 0 : _o11.Foo, _o3 === void 0 || _o3 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref3, Foo, _x).toString(); - (_ref5 = (_ref21 = _ref4 = deep === null || deep === void 0 ? void 0 : deep.very.o) === null || _ref21 === void 0 ? void 0 : _ref21.Foo, _ref4 === void 0 || _ref4 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref5, Foo, _x); - (_ref7 = (_ref22 = _ref6 = deep === null || deep === void 0 ? void 0 : deep.very.o) === null || _ref22 === void 0 ? void 0 : _ref22.Foo, _ref6 === void 0 || _ref6 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref7, Foo, _x).toString; - (_ref9 = (_ref23 = _ref8 = deep === null || deep === void 0 ? void 0 : deep.very.o) === null || _ref23 === void 0 ? void 0 : _ref23.Foo, _ref8 === void 0 || _ref8 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref9, Foo, _x).toString(); + (_ref5 = (_ref41 = _ref4 = deep === null || deep === void 0 ? void 0 : deep.very.o) === null || _ref41 === void 0 ? void 0 : _ref41.Foo, _ref4 === void 0 || _ref4 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref5, Foo, _x); + (_ref7 = (_ref42 = _ref6 = deep === null || deep === void 0 ? void 0 : deep.very.o) === null || _ref42 === void 0 ? void 0 : _ref42.Foo, _ref6 === void 0 || _ref6 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref7, Foo, _x).toString; + (_ref9 = (_ref43 = _ref8 = deep === null || deep === void 0 ? void 0 : deep.very.o) === null || _ref43 === void 0 ? void 0 : _ref43.Foo, _ref8 === void 0 || _ref8 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref9, Foo, _x).toString(); (_ref10 = (_o12 = _o4 = o) === null || _o12 === void 0 ? void 0 : _o12.Foo, _o4 === void 0 || _o4 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFieldSpecGet(_ref10, Foo, _self), Foo, _x); (_ref11 = (_o13 = _o5 = o) === null || _o13 === void 0 ? void 0 : _o13.Foo, _o5 === void 0 || _o5 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFieldSpecGet(_ref11, Foo, _self).self, Foo, _x); - (_ref14 = (_ref24 = _ref13 = (_ref12 = (_o14 = _o6 = o) === null || _o14 === void 0 ? void 0 : _o14.Foo, _o6 === void 0 || _o6 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref12, Foo, _self)) === null || _ref24 === void 0 ? void 0 : _ref24.self, _ref13 === void 0 || _ref13 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref14, Foo, _x); - (_ref17 = (_ref25 = _ref16 = (_ref15 = (_o15 = _o7 = o) === null || _o15 === void 0 ? void 0 : _o15.Foo, _o7 === void 0 || _o7 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref15, Foo, _self).self) === null || _ref25 === void 0 ? void 0 : _ref25.self, _ref16 === void 0 || _ref16 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref17, Foo, _x); - (_ref20 = (_ref26 = _ref19 = (_ref27 = (_ref18 = (_o16 = _o8 = o) === null || _o16 === void 0 ? void 0 : _o16.Foo, _o8 === void 0 || _o8 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref18, Foo, _self)) === null || _ref27 === void 0 ? void 0 : _ref27.self) === null || _ref26 === void 0 ? void 0 : _ref26.self, _ref19 === void 0 || _ref19 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref20, Foo, _x); + (_ref14 = (_ref44 = _ref13 = (_ref12 = (_o14 = _o6 = o) === null || _o14 === void 0 ? void 0 : _o14.Foo, _o6 === void 0 || _o6 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref12, Foo, _self)) === null || _ref44 === void 0 ? void 0 : _ref44.self, _ref13 === void 0 || _ref13 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref14, Foo, _x); + (_ref17 = (_ref45 = _ref16 = (_ref15 = (_o15 = _o7 = o) === null || _o15 === void 0 ? void 0 : _o15.Foo, _o7 === void 0 || _o7 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref15, Foo, _self).self) === null || _ref45 === void 0 ? void 0 : _ref45.self, _ref16 === void 0 || _ref16 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref17, Foo, _x); + (_ref20 = (_ref46 = _ref19 = (_ref47 = (_ref18 = (_o16 = _o8 = o) === null || _o16 === void 0 ? void 0 : _o16.Foo, _o8 === void 0 || _o8 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref18, Foo, _self)) === null || _ref47 === void 0 ? void 0 : _ref47.self) === null || _ref46 === void 0 ? void 0 : _ref46.self, _ref19 === void 0 || _ref19 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref20, Foo, _x); + (_ref21 = (_fn9 = _fn = fn) === null || _fn9 === void 0 ? void 0 : _fn9().Foo, _fn === void 0 || _fn === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref21, Foo, _x); + (_ref22 = (_fn10 = _fn2 = fn) === null || _fn10 === void 0 ? void 0 : _fn10().Foo, _fn2 === void 0 || _fn2 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref22, Foo, _x).toString; + (_ref23 = (_fn11 = _fn3 = fn) === null || _fn11 === void 0 ? void 0 : _fn11().Foo, _fn3 === void 0 || _fn3 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref23, Foo, _x).toString(); + (_ref25 = (_ref48 = _ref24 = fnDeep === null || fnDeep === void 0 ? void 0 : fnDeep().very.o) === null || _ref48 === void 0 ? void 0 : _ref48.Foo, _ref24 === void 0 || _ref24 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref25, Foo, _x); + (_ref27 = (_ref49 = _ref26 = fnDeep === null || fnDeep === void 0 ? void 0 : fnDeep().very.o) === null || _ref49 === void 0 ? void 0 : _ref49.Foo, _ref26 === void 0 || _ref26 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref27, Foo, _x).toString; + (_ref29 = (_ref50 = _ref28 = fnDeep === null || fnDeep === void 0 ? void 0 : fnDeep().very.o) === null || _ref50 === void 0 ? void 0 : _ref50.Foo, _ref28 === void 0 || _ref28 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref29, Foo, _x).toString(); + (_ref30 = (_fn12 = _fn4 = fn) === null || _fn12 === void 0 ? void 0 : _fn12().Foo, _fn4 === void 0 || _fn4 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFieldSpecGet(_ref30, Foo, _self), Foo, _x); + (_ref31 = (_fn13 = _fn5 = fn) === null || _fn13 === void 0 ? void 0 : _fn13().Foo, _fn5 === void 0 || _fn5 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFieldSpecGet(_ref31, Foo, _self).self, Foo, _x); + (_ref34 = (_ref51 = _ref33 = (_ref32 = (_fn14 = _fn6 = fn) === null || _fn14 === void 0 ? void 0 : _fn14().Foo, _fn6 === void 0 || _fn6 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref32, Foo, _self)) === null || _ref51 === void 0 ? void 0 : _ref51.self, _ref33 === void 0 || _ref33 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref34, Foo, _x); + (_ref37 = (_ref52 = _ref36 = (_ref35 = (_fn15 = _fn7 = fn) === null || _fn15 === void 0 ? void 0 : _fn15().Foo, _fn7 === void 0 || _fn7 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref35, Foo, _self).self) === null || _ref52 === void 0 ? void 0 : _ref52.self, _ref36 === void 0 || _ref36 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref37, Foo, _x); + (_ref40 = (_ref53 = _ref39 = (_ref54 = (_ref38 = (_fn16 = _fn8 = fn) === null || _fn16 === void 0 ? void 0 : _fn16().Foo, _fn8 === void 0 || _fn8 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref38, Foo, _self)) === null || _ref54 === void 0 ? void 0 : _ref54.self) === null || _ref53 === void 0 ? void 0 : _ref53.self, _ref39 === void 0 || _ref39 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref40, Foo, _x); } } diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain/input.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain/input.js index e8f18bd86f69..c9c6e861fd9c 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain/input.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain/input.js @@ -6,6 +6,13 @@ class Foo { static test() { const o = { Foo: Foo }; const deep = { very: { o } }; + function fn() { + return o; + } + function fnDeep() { + return deep; + } + o?.Foo.#x; o?.Foo.#x.toString; o?.Foo.#x.toString(); @@ -19,6 +26,20 @@ class Foo { o?.Foo.#self?.self.#x; o?.Foo.#self.self?.self.#x; o?.Foo.#self?.self?.self.#x; + + fn?.().Foo.#x; + fn?.().Foo.#x.toString; + fn?.().Foo.#x.toString(); + + fnDeep?.().very.o?.Foo.#x; + fnDeep?.().very.o?.Foo.#x.toString; + fnDeep?.().very.o?.Foo.#x.toString(); + + fn?.().Foo.#self.#x; + fn?.().Foo.#self.self.#x; + fn?.().Foo.#self?.self.#x; + fn?.().Foo.#self.self?.self.#x; + fn?.().Foo.#self?.self?.self.#x; } } diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain/output.js index 908d2cf6a3f3..0f4cf2619717 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain/output.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain/output.js @@ -4,7 +4,7 @@ function _classStaticPrivateFieldSpecGet(receiver, classConstructor, descriptor) class Foo { static test() { - var _o, _ref, _o2, _ref2, _o3, _ref3, _ref4, _ref5, _ref6, _ref7, _ref8, _ref9, _o4, _ref10, _o5, _ref11, _o6, _ref12, _ref13, _ref14, _o7, _ref15, _ref16, _ref17, _o8, _ref18, _ref19, _ref20; + var _o, _ref, _o2, _ref2, _o3, _ref3, _ref4, _ref5, _ref6, _ref7, _ref8, _ref9, _o4, _ref10, _o5, _ref11, _o6, _ref12, _ref13, _ref14, _o7, _ref15, _ref16, _ref17, _o8, _ref18, _ref19, _ref20, _fn, _ref21, _fn2, _ref22, _fn3, _ref23, _ref24, _ref25, _ref26, _ref27, _ref28, _ref29, _fn4, _ref30, _fn5, _ref31, _fn6, _ref32, _ref33, _ref34, _fn7, _ref35, _ref36, _ref37, _fn8, _ref38, _ref39, _ref40; const o = { Foo: Foo @@ -14,6 +14,15 @@ class Foo { o } }; + + function fn() { + return o; + } + + function fnDeep() { + return deep; + } + (_ref = (_o = o)?.Foo, _o === void 0 || _o === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref, Foo, _x); (_ref2 = (_o2 = o)?.Foo, _o2 === void 0 || _o2 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref2, Foo, _x).toString; (_ref3 = (_o3 = o)?.Foo, _o3 === void 0 || _o3 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref3, Foo, _x).toString(); @@ -25,6 +34,17 @@ class Foo { (_ref14 = (_ref13 = (_ref12 = (_o6 = o)?.Foo, _o6 === void 0 || _o6 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref12, Foo, _self))?.self, _ref13 === void 0 || _ref13 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref14, Foo, _x); (_ref17 = (_ref16 = (_ref15 = (_o7 = o)?.Foo, _o7 === void 0 || _o7 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref15, Foo, _self).self)?.self, _ref16 === void 0 || _ref16 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref17, Foo, _x); (_ref20 = (_ref19 = ((_ref18 = (_o8 = o)?.Foo, _o8 === void 0 || _o8 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref18, Foo, _self))?.self)?.self, _ref19 === void 0 || _ref19 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref20, Foo, _x); + (_ref21 = (_fn = fn)?.().Foo, _fn === void 0 || _fn === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref21, Foo, _x); + (_ref22 = (_fn2 = fn)?.().Foo, _fn2 === void 0 || _fn2 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref22, Foo, _x).toString; + (_ref23 = (_fn3 = fn)?.().Foo, _fn3 === void 0 || _fn3 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref23, Foo, _x).toString(); + (_ref25 = (_ref24 = fnDeep?.().very.o)?.Foo, _ref24 === void 0 || _ref24 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref25, Foo, _x); + (_ref27 = (_ref26 = fnDeep?.().very.o)?.Foo, _ref26 === void 0 || _ref26 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref27, Foo, _x).toString; + (_ref29 = (_ref28 = fnDeep?.().very.o)?.Foo, _ref28 === void 0 || _ref28 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref29, Foo, _x).toString(); + (_ref30 = (_fn4 = fn)?.().Foo, _fn4 === void 0 || _fn4 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFieldSpecGet(_ref30, Foo, _self), Foo, _x); + (_ref31 = (_fn5 = fn)?.().Foo, _fn5 === void 0 || _fn5 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFieldSpecGet(_ref31, Foo, _self).self, Foo, _x); + (_ref34 = (_ref33 = (_ref32 = (_fn6 = fn)?.().Foo, _fn6 === void 0 || _fn6 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref32, Foo, _self))?.self, _ref33 === void 0 || _ref33 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref34, Foo, _x); + (_ref37 = (_ref36 = (_ref35 = (_fn7 = fn)?.().Foo, _fn7 === void 0 || _fn7 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref35, Foo, _self).self)?.self, _ref36 === void 0 || _ref36 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref37, Foo, _x); + (_ref40 = (_ref39 = ((_ref38 = (_fn8 = fn)?.().Foo, _fn8 === void 0 || _fn8 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref38, Foo, _self))?.self)?.self, _ref39 === void 0 || _ref39 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref40, Foo, _x); } } From 327b046ed5ad53ed68afcc6fadb1d20ce8082f8c Mon Sep 17 00:00:00 2001 From: Justin Ridgewell Date: Sat, 14 Mar 2020 00:49:09 -0400 Subject: [PATCH 03/20] tmp --- .../src/index.js | 7 ++ .../private-loose/optional-chain/output.js | 16 ++-- .../optional-chain-private-call/input.js | 66 ++++++++++++++++ .../optional-chain-private-call/options.json | 3 + .../optional-chain-private-call/output.js | 63 +++++++++++++++ .../optional-chain-with-transform/exec.js | 76 +++++++++++++++++++ .../optional-chain-with-transform/input.js | 18 +++++ .../fixtures/private/optional-chain/input.js | 20 +++++ .../fixtures/private/optional-chain/output.js | 44 ++++++++--- 9 files changed, 293 insertions(+), 20 deletions(-) create mode 100644 packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-private-call/input.js create mode 100644 packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-private-call/options.json create mode 100644 packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-private-call/output.js 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 4b558f51055f..184d4be99aa7 100644 --- a/packages/babel-helper-member-expression-to-functions/src/index.js +++ b/packages/babel-helper-member-expression-to-functions/src/index.js @@ -98,8 +98,15 @@ const handle = { startingOptional = startingOptional.get("callee"); continue; } + + debugger; + console.error(startingOptional.toString()); + // throw startingOptional.buildCodeFrameError( + // "failed to find nearest optional", + // ); } + debugger; const { scope } = member; const { object } = node; const startingProp = startingOptional.isOptionalMemberExpression() diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain/output.js index bdbb9035b179..a5d7c7957797 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain/output.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain/output.js @@ -36,17 +36,17 @@ class Foo { (_ref14 = (_ref13 = (_ref12 = (_o6 = o)?.Foo, _o6 === void 0 || _o6 === null) ? void 0 : _classPrivateFieldLooseBase(_ref12, _self)[_self])?.self, _ref13 === void 0 || _ref13 === null) ? void 0 : _classPrivateFieldLooseBase(_ref14, _x)[_x]; (_ref17 = (_ref16 = (_ref15 = (_o7 = o)?.Foo, _o7 === void 0 || _o7 === null) ? void 0 : _classPrivateFieldLooseBase(_ref15, _self)[_self].self)?.self, _ref16 === void 0 || _ref16 === null) ? void 0 : _classPrivateFieldLooseBase(_ref17, _x)[_x]; (_ref20 = (_ref19 = ((_ref18 = (_o8 = o)?.Foo, _o8 === void 0 || _o8 === null) ? void 0 : _classPrivateFieldLooseBase(_ref18, _self)[_self])?.self)?.self, _ref19 === void 0 || _ref19 === null) ? void 0 : _classPrivateFieldLooseBase(_ref20, _x)[_x]; - (_ref21 = (_fn = fn)?.().Foo, _fn === void 0 || _fn === null) ? void 0 : _classPrivateFieldLooseBase(_ref21, _x)[_x]; - (_ref22 = (_fn2 = fn)?.().Foo, _fn2 === void 0 || _fn2 === null) ? void 0 : _classPrivateFieldLooseBase(_ref22, _x)[_x].toString; - (_ref23 = (_fn3 = fn)?.().Foo, _fn3 === void 0 || _fn3 === null) ? void 0 : _classPrivateFieldLooseBase(_ref23, _x)[_x].toString(); + (_ref21 = _fn = fn?.().Foo, _fn === void 0 || _fn === null) ? void 0 : _classPrivateFieldLooseBase(_ref21, _x)[_x]; + (_ref22 = _fn2 = fn?.().Foo, _fn2 === void 0 || _fn2 === null) ? void 0 : _classPrivateFieldLooseBase(_ref22, _x)[_x].toString; + (_ref23 = _fn3 = fn?.().Foo, _fn3 === void 0 || _fn3 === null) ? void 0 : _classPrivateFieldLooseBase(_ref23, _x)[_x].toString(); (_ref25 = (_ref24 = fnDeep?.().very.o)?.Foo, _ref24 === void 0 || _ref24 === null) ? void 0 : _classPrivateFieldLooseBase(_ref25, _x)[_x]; (_ref27 = (_ref26 = fnDeep?.().very.o)?.Foo, _ref26 === void 0 || _ref26 === null) ? void 0 : _classPrivateFieldLooseBase(_ref27, _x)[_x].toString; (_ref29 = (_ref28 = fnDeep?.().very.o)?.Foo, _ref28 === void 0 || _ref28 === null) ? void 0 : _classPrivateFieldLooseBase(_ref29, _x)[_x].toString(); - (_ref30 = (_fn4 = fn)?.().Foo, _fn4 === void 0 || _fn4 === null) ? void 0 : _classPrivateFieldLooseBase(_classPrivateFieldLooseBase(_ref30, _self)[_self], _x)[_x]; - (_ref31 = (_fn5 = fn)?.().Foo, _fn5 === void 0 || _fn5 === null) ? void 0 : _classPrivateFieldLooseBase(_classPrivateFieldLooseBase(_ref31, _self)[_self].self, _x)[_x]; - (_ref34 = (_ref33 = (_ref32 = (_fn6 = fn)?.().Foo, _fn6 === void 0 || _fn6 === null) ? void 0 : _classPrivateFieldLooseBase(_ref32, _self)[_self])?.self, _ref33 === void 0 || _ref33 === null) ? void 0 : _classPrivateFieldLooseBase(_ref34, _x)[_x]; - (_ref37 = (_ref36 = (_ref35 = (_fn7 = fn)?.().Foo, _fn7 === void 0 || _fn7 === null) ? void 0 : _classPrivateFieldLooseBase(_ref35, _self)[_self].self)?.self, _ref36 === void 0 || _ref36 === null) ? void 0 : _classPrivateFieldLooseBase(_ref37, _x)[_x]; - (_ref40 = (_ref39 = ((_ref38 = (_fn8 = fn)?.().Foo, _fn8 === void 0 || _fn8 === null) ? void 0 : _classPrivateFieldLooseBase(_ref38, _self)[_self])?.self)?.self, _ref39 === void 0 || _ref39 === null) ? void 0 : _classPrivateFieldLooseBase(_ref40, _x)[_x]; + (_ref30 = _fn4 = fn?.().Foo, _fn4 === void 0 || _fn4 === null) ? void 0 : _classPrivateFieldLooseBase(_classPrivateFieldLooseBase(_ref30, _self)[_self], _x)[_x]; + (_ref31 = _fn5 = fn?.().Foo, _fn5 === void 0 || _fn5 === null) ? void 0 : _classPrivateFieldLooseBase(_classPrivateFieldLooseBase(_ref31, _self)[_self].self, _x)[_x]; + (_ref34 = (_ref33 = (_ref32 = _fn6 = fn?.().Foo, _fn6 === void 0 || _fn6 === null) ? void 0 : _classPrivateFieldLooseBase(_ref32, _self)[_self])?.self, _ref33 === void 0 || _ref33 === null) ? void 0 : _classPrivateFieldLooseBase(_ref34, _x)[_x]; + (_ref37 = (_ref36 = (_ref35 = _fn7 = fn?.().Foo, _fn7 === void 0 || _fn7 === null) ? void 0 : _classPrivateFieldLooseBase(_ref35, _self)[_self].self)?.self, _ref36 === void 0 || _ref36 === null) ? void 0 : _classPrivateFieldLooseBase(_ref37, _x)[_x]; + (_ref40 = (_ref39 = ((_ref38 = _fn8 = fn?.().Foo, _fn8 === void 0 || _fn8 === null) ? void 0 : _classPrivateFieldLooseBase(_ref38, _self)[_self])?.self)?.self, _ref39 === void 0 || _ref39 === null) ? void 0 : _classPrivateFieldLooseBase(_ref40, _x)[_x]; } } diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-private-call/input.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-private-call/input.js new file mode 100644 index 000000000000..8829ac1dc0de --- /dev/null +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-private-call/input.js @@ -0,0 +1,66 @@ +class Foo { + static #x = 1; + static #m = function() { return this.#x; }; + static #self = Foo; + static self = Foo; + static getSelf() { return this } + + static test() { + const o = { Foo: Foo }; + const deep = { very: { o } }; + function fn() { + return o; + } + function fnDeep() { + return deep; + } + + // o?.Foo.#m(); + // o?.Foo.#m().toString; + // o?.Foo.#m().toString(); + + // deep?.very.o?.Foo.#m(); + // deep?.very.o?.Foo.#m().toString; + // deep?.very.o?.Foo.#m().toString(); + + o?.Foo.#self.#m(); + // o?.Foo.#self.self.#m(); + // o?.Foo.#self?.self.#m(); + // o?.Foo.#self.self?.self.#m(); + // o?.Foo.#self?.self?.self.#m(); + + // o?.Foo.#self.getSelf().#m(); + // o?.Foo.#self.getSelf?.().#m(); + // o?.Foo.#self?.getSelf().#m(); + // o?.Foo.#self?.getSelf?.().#m(); + // o?.Foo.#self.getSelf()?.self.#m(); + // o?.Foo.#self.getSelf?.()?.self.#m(); + // o?.Foo.#self?.getSelf()?.self.#m(); + // o?.Foo.#self?.getSelf?.()?.self.#m(); + + // fn?.().Foo.#m(); + // fn?.().Foo.#m().toString; + // fn?.().Foo.#m().toString(); + + // fnDeep?.().very.o?.Foo.#m(); + // fnDeep?.().very.o?.Foo.#m().toString; + // fnDeep?.().very.o?.Foo.#m().toString(); + + // fn?.().Foo.#self.#m(); + // fn?.().Foo.#self.self.#m(); + // fn?.().Foo.#self?.self.#m(); + // fn?.().Foo.#self.self?.self.#m(); + // fn?.().Foo.#self?.self?.self.#m(); + + // fn?.().Foo.#self.getSelf().#m(); + // fn?.().Foo.#self.getSelf?.().#m(); + // fn?.().Foo.#self?.getSelf().#m(); + // fn?.().Foo.#self?.getSelf?.().#m(); + // fn?.().Foo.#self.getSelf()?.self.#m(); + // fn?.().Foo.#self.getSelf?.()?.self.#m(); + // fn?.().Foo.#self?.getSelf()?.self.#m(); + // fn?.().Foo.#self?.getSelf?.()?.self.#m(); + } +} + +Foo.test(); diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-private-call/options.json b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-private-call/options.json new file mode 100644 index 000000000000..19ed5174f545 --- /dev/null +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-private-call/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["proposal-class-properties"] +} diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-private-call/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-private-call/output.js new file mode 100644 index 000000000000..0f4cf2619717 --- /dev/null +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-private-call/output.js @@ -0,0 +1,63 @@ +function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } + +function _classStaticPrivateFieldSpecGet(receiver, classConstructor, descriptor) { if (receiver !== classConstructor) { throw new TypeError("Private static access of wrong provenance"); } if (descriptor.get) { return descriptor.get.call(receiver); } return descriptor.value; } + +class Foo { + static test() { + var _o, _ref, _o2, _ref2, _o3, _ref3, _ref4, _ref5, _ref6, _ref7, _ref8, _ref9, _o4, _ref10, _o5, _ref11, _o6, _ref12, _ref13, _ref14, _o7, _ref15, _ref16, _ref17, _o8, _ref18, _ref19, _ref20, _fn, _ref21, _fn2, _ref22, _fn3, _ref23, _ref24, _ref25, _ref26, _ref27, _ref28, _ref29, _fn4, _ref30, _fn5, _ref31, _fn6, _ref32, _ref33, _ref34, _fn7, _ref35, _ref36, _ref37, _fn8, _ref38, _ref39, _ref40; + + const o = { + Foo: Foo + }; + const deep = { + very: { + o + } + }; + + function fn() { + return o; + } + + function fnDeep() { + return deep; + } + + (_ref = (_o = o)?.Foo, _o === void 0 || _o === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref, Foo, _x); + (_ref2 = (_o2 = o)?.Foo, _o2 === void 0 || _o2 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref2, Foo, _x).toString; + (_ref3 = (_o3 = o)?.Foo, _o3 === void 0 || _o3 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref3, Foo, _x).toString(); + (_ref5 = (_ref4 = deep?.very.o)?.Foo, _ref4 === void 0 || _ref4 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref5, Foo, _x); + (_ref7 = (_ref6 = deep?.very.o)?.Foo, _ref6 === void 0 || _ref6 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref7, Foo, _x).toString; + (_ref9 = (_ref8 = deep?.very.o)?.Foo, _ref8 === void 0 || _ref8 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref9, Foo, _x).toString(); + (_ref10 = (_o4 = o)?.Foo, _o4 === void 0 || _o4 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFieldSpecGet(_ref10, Foo, _self), Foo, _x); + (_ref11 = (_o5 = o)?.Foo, _o5 === void 0 || _o5 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFieldSpecGet(_ref11, Foo, _self).self, Foo, _x); + (_ref14 = (_ref13 = (_ref12 = (_o6 = o)?.Foo, _o6 === void 0 || _o6 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref12, Foo, _self))?.self, _ref13 === void 0 || _ref13 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref14, Foo, _x); + (_ref17 = (_ref16 = (_ref15 = (_o7 = o)?.Foo, _o7 === void 0 || _o7 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref15, Foo, _self).self)?.self, _ref16 === void 0 || _ref16 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref17, Foo, _x); + (_ref20 = (_ref19 = ((_ref18 = (_o8 = o)?.Foo, _o8 === void 0 || _o8 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref18, Foo, _self))?.self)?.self, _ref19 === void 0 || _ref19 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref20, Foo, _x); + (_ref21 = (_fn = fn)?.().Foo, _fn === void 0 || _fn === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref21, Foo, _x); + (_ref22 = (_fn2 = fn)?.().Foo, _fn2 === void 0 || _fn2 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref22, Foo, _x).toString; + (_ref23 = (_fn3 = fn)?.().Foo, _fn3 === void 0 || _fn3 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref23, Foo, _x).toString(); + (_ref25 = (_ref24 = fnDeep?.().very.o)?.Foo, _ref24 === void 0 || _ref24 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref25, Foo, _x); + (_ref27 = (_ref26 = fnDeep?.().very.o)?.Foo, _ref26 === void 0 || _ref26 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref27, Foo, _x).toString; + (_ref29 = (_ref28 = fnDeep?.().very.o)?.Foo, _ref28 === void 0 || _ref28 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref29, Foo, _x).toString(); + (_ref30 = (_fn4 = fn)?.().Foo, _fn4 === void 0 || _fn4 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFieldSpecGet(_ref30, Foo, _self), Foo, _x); + (_ref31 = (_fn5 = fn)?.().Foo, _fn5 === void 0 || _fn5 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFieldSpecGet(_ref31, Foo, _self).self, Foo, _x); + (_ref34 = (_ref33 = (_ref32 = (_fn6 = fn)?.().Foo, _fn6 === void 0 || _fn6 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref32, Foo, _self))?.self, _ref33 === void 0 || _ref33 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref34, Foo, _x); + (_ref37 = (_ref36 = (_ref35 = (_fn7 = fn)?.().Foo, _fn7 === void 0 || _fn7 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref35, Foo, _self).self)?.self, _ref36 === void 0 || _ref36 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref37, Foo, _x); + (_ref40 = (_ref39 = ((_ref38 = (_fn8 = fn)?.().Foo, _fn8 === void 0 || _fn8 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref38, Foo, _self))?.self)?.self, _ref39 === void 0 || _ref39 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref40, Foo, _x); + } + +} + +var _x = { + writable: true, + value: 1 +}; +var _self = { + writable: true, + value: Foo +}; + +_defineProperty(Foo, "self", Foo); + +Foo.test(); diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-with-transform/exec.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-with-transform/exec.js index dd3502ead93c..b3b2d67e9771 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-with-transform/exec.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-with-transform/exec.js @@ -13,6 +13,63 @@ class Foo { return deep; } + expect(o?.Foo.#x).toEqual(undefined); + expect(o?.Foo.#x.toString).toEqual(undefined); + expect(o?.Foo.#x.toString()).toEqual(undefined); + + expect(deep?.very.o?.Foo.#x).toEqual(undefined); + expect(deep?.very.o?.Foo.#x.toString).toEqual(undefined); + expect(deep?.very.o?.Foo.#x.toString()).toEqual(undefined); + + expect(o?.Foo.#self.#x).toEqual(undefined); + expect(o?.Foo.#self.self.#x).toEqual(undefined); + expect(o?.Foo.#self?.self.#x).toEqual(undefined); + expect(o?.Foo.#self.self?.self.#x).toEqual(undefined); + expect(o?.Foo.#self?.self?.self.#x).toEqual(undefined); + + expect(o?.Foo.#self.getSelf().#x).toEqual(undefined); + expect(o?.Foo.#self.getSelf?.().#x).toEqual(undefined); + expect(o?.Foo.#self?.getSelf().#x).toEqual(undefined); + expect(o?.Foo.#self?.getSelf?.().#x).toEqual(undefined); + expect(o?.Foo.#self.getSelf()?.self.#x).toEqual(undefined); + expect(o?.Foo.#self.getSelf?.()?.self.#x).toEqual(undefined); + expect(o?.Foo.#self?.getSelf()?.self.#x).toEqual(undefined); + expect(o?.Foo.#self?.getSelf?.()?.self.#x).toEqual(undefined); + + expect(fn?.().Foo.#x).toEqual(undefined); + expect(fn?.().Foo.#x.toString).toEqual(undefined); + expect(fn?.().Foo.#x.toString()).toEqual(undefined); + + expect(fnDeep?.().very.o?.Foo.#x).toEqual(undefined); + expect(fnDeep?.().very.o?.Foo.#x.toString).toEqual(undefined); + expect(fnDeep?.().very.o?.Foo.#x.toString()).toEqual(undefined); + + expect(fn?.().Foo.#self.#x).toEqual(undefined); + expect(fn?.().Foo.#self.self.#x).toEqual(undefined); + expect(fn?.().Foo.#self?.self.#x).toEqual(undefined); + expect(fn?.().Foo.#self.self?.self.#x).toEqual(undefined); + expect(fn?.().Foo.#self?.self?.self.#x).toEqual(undefined); + + expect(fn?.().Foo.#self.getSelf().#x).toEqual(undefined); + expect(fn?.().Foo.#self.getSelf?.().#x).toEqual(undefined); + expect(fn?.().Foo.#self?.getSelf().#x).toEqual(undefined); + expect(fn?.().Foo.#self?.getSelf?.().#x).toEqual(undefined); + expect(fn?.().Foo.#self.getSelf()?.self.#x).toEqual(undefined); + expect(fn?.().Foo.#self.getSelf?.()?.self.#x).toEqual(undefined); + expect(fn?.().Foo.#self?.getSelf()?.self.#x).toEqual(undefined); + expect(fn?.().Foo.#self?.getSelf?.()?.self.#x).toEqual(undefined); + } + + static testNull() { + const o = null;; + const deep = { very: { o } }; + function fn() { + return o; + } + function fnDeep() { + return deep; + } + expect(o?.Foo.#x).toEqual(1); expect(o?.Foo.#x.toString).toEqual(1..toString); expect(o?.Foo.#x.toString()).toEqual('1'); @@ -27,6 +84,15 @@ class Foo { expect(o?.Foo.#self.self?.self.#x).toEqual(1); expect(o?.Foo.#self?.self?.self.#x).toEqual(1); + expect(o?.Foo.#self.getSelf().#x).toEqual(1); + expect(o?.Foo.#self.getSelf?.().#x).toEqual(1); + expect(o?.Foo.#self?.getSelf().#x).toEqual(1); + expect(o?.Foo.#self?.getSelf?.().#x).toEqual(1); + expect(o?.Foo.#self.getSelf()?.self.#x).toEqual(1); + expect(o?.Foo.#self.getSelf?.()?.self.#x).toEqual(1); + expect(o?.Foo.#self?.getSelf()?.self.#x).toEqual(1); + expect(o?.Foo.#self?.getSelf?.()?.self.#x).toEqual(1); + expect(fn?.().Foo.#x).toEqual(1); expect(fn?.().Foo.#x.toString).toEqual(1..toString); expect(fn?.().Foo.#x.toString()).toEqual('1'); @@ -40,7 +106,17 @@ class Foo { expect(fn?.().Foo.#self?.self.#x).toEqual(1); expect(fn?.().Foo.#self.self?.self.#x).toEqual(1); expect(fn?.().Foo.#self?.self?.self.#x).toEqual(1); + + expect(fn?.().Foo.#self.getSelf().#x).toEqual(1); + expect(fn?.().Foo.#self.getSelf?.().#x).toEqual(1); + expect(fn?.().Foo.#self?.getSelf().#x).toEqual(1); + expect(fn?.().Foo.#self?.getSelf?.().#x).toEqual(1); + expect(fn?.().Foo.#self.getSelf()?.self.#x).toEqual(1); + expect(fn?.().Foo.#self.getSelf?.()?.self.#x).toEqual(1); + expect(fn?.().Foo.#self?.getSelf()?.self.#x).toEqual(1); + expect(fn?.().Foo.#self?.getSelf?.()?.self.#x).toEqual(1); } } Foo.test(); +Foo.testNull(); diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-with-transform/input.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-with-transform/input.js index c9c6e861fd9c..30b17a197a2a 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-with-transform/input.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-with-transform/input.js @@ -27,6 +27,15 @@ class Foo { o?.Foo.#self.self?.self.#x; o?.Foo.#self?.self?.self.#x; + o?.Foo.#self.getSelf().#x; + o?.Foo.#self.getSelf?.().#x; + o?.Foo.#self?.getSelf().#x; + o?.Foo.#self?.getSelf?.().#x; + o?.Foo.#self.getSelf()?.self.#x; + o?.Foo.#self.getSelf?.()?.self.#x; + o?.Foo.#self?.getSelf()?.self.#x; + o?.Foo.#self?.getSelf?.()?.self.#x; + fn?.().Foo.#x; fn?.().Foo.#x.toString; fn?.().Foo.#x.toString(); @@ -40,6 +49,15 @@ class Foo { fn?.().Foo.#self?.self.#x; fn?.().Foo.#self.self?.self.#x; fn?.().Foo.#self?.self?.self.#x; + + fn?.().Foo.#self.getSelf().#x; + fn?.().Foo.#self.getSelf?.().#x; + fn?.().Foo.#self?.getSelf().#x; + fn?.().Foo.#self?.getSelf?.().#x; + fn?.().Foo.#self.getSelf()?.self.#x; + fn?.().Foo.#self.getSelf?.()?.self.#x; + fn?.().Foo.#self?.getSelf()?.self.#x; + fn?.().Foo.#self?.getSelf?.()?.self.#x; } } diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain/input.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain/input.js index c9c6e861fd9c..cf001da081fc 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain/input.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain/input.js @@ -2,6 +2,7 @@ class Foo { static #x = 1; static #self = Foo; static self = Foo; + static getSelf() { return this } static test() { const o = { Foo: Foo }; @@ -27,6 +28,15 @@ class Foo { o?.Foo.#self.self?.self.#x; o?.Foo.#self?.self?.self.#x; + o?.Foo.#self.getSelf().#x; + o?.Foo.#self.getSelf?.().#x; + o?.Foo.#self?.getSelf().#x; + o?.Foo.#self?.getSelf?.().#x; + o?.Foo.#self.getSelf()?.self.#x; + o?.Foo.#self.getSelf?.()?.self.#x; + o?.Foo.#self?.getSelf()?.self.#x; + o?.Foo.#self?.getSelf?.()?.self.#x; + fn?.().Foo.#x; fn?.().Foo.#x.toString; fn?.().Foo.#x.toString(); @@ -40,6 +50,16 @@ class Foo { fn?.().Foo.#self?.self.#x; fn?.().Foo.#self.self?.self.#x; fn?.().Foo.#self?.self?.self.#x; + + fn?.().Foo.#self.getSelf().#x; + fn?.().Foo.#self.getSelf?.().#x; + fn?.().Foo.#self?.getSelf().#x; + fn?.().Foo.#self?.getSelf?.().#x; + fn?.().Foo.#self.getSelf()?.self.#x; + fn?.().Foo.#self.getSelf?.()?.self.#x; + fn?.().Foo.#self?.getSelf()?.self.#x; + fn?.().Foo.#self?.getSelf?.()?.self.#x; + } } diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain/output.js index 0f4cf2619717..2ab2242bfa56 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain/output.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain/output.js @@ -3,8 +3,12 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope function _classStaticPrivateFieldSpecGet(receiver, classConstructor, descriptor) { if (receiver !== classConstructor) { throw new TypeError("Private static access of wrong provenance"); } if (descriptor.get) { return descriptor.get.call(receiver); } return descriptor.value; } class Foo { + static getSelf() { + return this; + } + static test() { - var _o, _ref, _o2, _ref2, _o3, _ref3, _ref4, _ref5, _ref6, _ref7, _ref8, _ref9, _o4, _ref10, _o5, _ref11, _o6, _ref12, _ref13, _ref14, _o7, _ref15, _ref16, _ref17, _o8, _ref18, _ref19, _ref20, _fn, _ref21, _fn2, _ref22, _fn3, _ref23, _ref24, _ref25, _ref26, _ref27, _ref28, _ref29, _fn4, _ref30, _fn5, _ref31, _fn6, _ref32, _ref33, _ref34, _fn7, _ref35, _ref36, _ref37, _fn8, _ref38, _ref39, _ref40; + var _o, _ref, _o2, _ref2, _o3, _ref3, _ref4, _ref5, _ref6, _ref7, _ref8, _ref9, _o4, _ref10, _o5, _ref11, _o6, _ref12, _ref13, _ref14, _o7, _ref15, _ref16, _ref17, _o8, _ref18, _ref19, _ref20, _o9, _ref21, _o10, _ref22, _ref23, _ref24, _o11, _ref25, _ref26, _ref27, _o12, _ref28, _ref29, _ref30, _o13, _ref31, _ref32, _ref33, _o14, _ref34, _ref35, _ref36, _o15, _ref37, _ref38, _ref39, _o16, _ref40, _ref41, _ref42, _fn, _ref43, _fn2, _ref44, _fn3, _ref45, _ref46, _ref47, _ref48, _ref49, _ref50, _ref51, _fn4, _ref52, _fn5, _ref53, _fn6, _ref54, _ref55, _ref56, _fn7, _ref57, _ref58, _ref59, _fn8, _ref60, _ref61, _ref62, _fn9, _ref63, _fn10, _ref64, _ref65, _ref66, _fn11, _ref67, _ref68, _ref69, _fn12, _ref70, _ref71, _ref72, _fn13, _ref73, _ref74, _ref75, _fn14, _ref76, _ref77, _ref78, _fn15, _ref79, _ref80, _ref81, _fn16, _ref82, _ref83, _ref84; const o = { Foo: Foo @@ -34,17 +38,33 @@ class Foo { (_ref14 = (_ref13 = (_ref12 = (_o6 = o)?.Foo, _o6 === void 0 || _o6 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref12, Foo, _self))?.self, _ref13 === void 0 || _ref13 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref14, Foo, _x); (_ref17 = (_ref16 = (_ref15 = (_o7 = o)?.Foo, _o7 === void 0 || _o7 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref15, Foo, _self).self)?.self, _ref16 === void 0 || _ref16 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref17, Foo, _x); (_ref20 = (_ref19 = ((_ref18 = (_o8 = o)?.Foo, _o8 === void 0 || _o8 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref18, Foo, _self))?.self)?.self, _ref19 === void 0 || _ref19 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref20, Foo, _x); - (_ref21 = (_fn = fn)?.().Foo, _fn === void 0 || _fn === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref21, Foo, _x); - (_ref22 = (_fn2 = fn)?.().Foo, _fn2 === void 0 || _fn2 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref22, Foo, _x).toString; - (_ref23 = (_fn3 = fn)?.().Foo, _fn3 === void 0 || _fn3 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref23, Foo, _x).toString(); - (_ref25 = (_ref24 = fnDeep?.().very.o)?.Foo, _ref24 === void 0 || _ref24 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref25, Foo, _x); - (_ref27 = (_ref26 = fnDeep?.().very.o)?.Foo, _ref26 === void 0 || _ref26 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref27, Foo, _x).toString; - (_ref29 = (_ref28 = fnDeep?.().very.o)?.Foo, _ref28 === void 0 || _ref28 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref29, Foo, _x).toString(); - (_ref30 = (_fn4 = fn)?.().Foo, _fn4 === void 0 || _fn4 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFieldSpecGet(_ref30, Foo, _self), Foo, _x); - (_ref31 = (_fn5 = fn)?.().Foo, _fn5 === void 0 || _fn5 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFieldSpecGet(_ref31, Foo, _self).self, Foo, _x); - (_ref34 = (_ref33 = (_ref32 = (_fn6 = fn)?.().Foo, _fn6 === void 0 || _fn6 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref32, Foo, _self))?.self, _ref33 === void 0 || _ref33 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref34, Foo, _x); - (_ref37 = (_ref36 = (_ref35 = (_fn7 = fn)?.().Foo, _fn7 === void 0 || _fn7 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref35, Foo, _self).self)?.self, _ref36 === void 0 || _ref36 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref37, Foo, _x); - (_ref40 = (_ref39 = ((_ref38 = (_fn8 = fn)?.().Foo, _fn8 === void 0 || _fn8 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref38, Foo, _self))?.self)?.self, _ref39 === void 0 || _ref39 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref40, Foo, _x); + (_ref21 = (_o9 = o)?.Foo, _o9 === void 0 || _o9 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFieldSpecGet(_ref21, Foo, _self).getSelf(), Foo, _x); + (_ref24 = _ref23 = (_ref22 = (_o10 = o)?.Foo, _o10 === void 0 || _o10 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref22, Foo, _self).getSelf?.(), _ref23 === void 0 || _ref23 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref24, Foo, _x); + (_ref27 = (_ref26 = (_ref25 = (_o11 = o)?.Foo, _o11 === void 0 || _o11 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref25, Foo, _self))?.getSelf(), _ref26 === void 0 || _ref26 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref27, Foo, _x); + (_ref30 = _ref29 = ((_ref28 = (_o12 = o)?.Foo, _o12 === void 0 || _o12 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref28, Foo, _self))?.getSelf?.(), _ref29 === void 0 || _ref29 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref30, Foo, _x); + (_ref33 = (_ref32 = (_ref31 = (_o13 = o)?.Foo, _o13 === void 0 || _o13 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref31, Foo, _self).getSelf())?.self, _ref32 === void 0 || _ref32 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref33, Foo, _x); + (_ref36 = (_ref35 = (_ref34 = (_o14 = o)?.Foo, _o14 === void 0 || _o14 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref34, Foo, _self).getSelf?.())?.self, _ref35 === void 0 || _ref35 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref36, Foo, _x); + (_ref39 = (_ref38 = ((_ref37 = (_o15 = o)?.Foo, _o15 === void 0 || _o15 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref37, Foo, _self))?.getSelf())?.self, _ref38 === void 0 || _ref38 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref39, Foo, _x); + (_ref42 = (_ref41 = ((_ref40 = (_o16 = o)?.Foo, _o16 === void 0 || _o16 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref40, Foo, _self))?.getSelf?.())?.self, _ref41 === void 0 || _ref41 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref42, Foo, _x); + (_ref43 = _fn = fn?.().Foo, _fn === void 0 || _fn === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref43, Foo, _x); + (_ref44 = _fn2 = fn?.().Foo, _fn2 === void 0 || _fn2 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref44, Foo, _x).toString; + (_ref45 = _fn3 = fn?.().Foo, _fn3 === void 0 || _fn3 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref45, Foo, _x).toString(); + (_ref47 = (_ref46 = fnDeep?.().very.o)?.Foo, _ref46 === void 0 || _ref46 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref47, Foo, _x); + (_ref49 = (_ref48 = fnDeep?.().very.o)?.Foo, _ref48 === void 0 || _ref48 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref49, Foo, _x).toString; + (_ref51 = (_ref50 = fnDeep?.().very.o)?.Foo, _ref50 === void 0 || _ref50 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref51, Foo, _x).toString(); + (_ref52 = _fn4 = fn?.().Foo, _fn4 === void 0 || _fn4 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFieldSpecGet(_ref52, Foo, _self), Foo, _x); + (_ref53 = _fn5 = fn?.().Foo, _fn5 === void 0 || _fn5 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFieldSpecGet(_ref53, Foo, _self).self, Foo, _x); + (_ref56 = (_ref55 = (_ref54 = _fn6 = fn?.().Foo, _fn6 === void 0 || _fn6 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref54, Foo, _self))?.self, _ref55 === void 0 || _ref55 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref56, Foo, _x); + (_ref59 = (_ref58 = (_ref57 = _fn7 = fn?.().Foo, _fn7 === void 0 || _fn7 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref57, Foo, _self).self)?.self, _ref58 === void 0 || _ref58 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref59, Foo, _x); + (_ref62 = (_ref61 = ((_ref60 = _fn8 = fn?.().Foo, _fn8 === void 0 || _fn8 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref60, Foo, _self))?.self)?.self, _ref61 === void 0 || _ref61 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref62, Foo, _x); + (_ref63 = _fn9 = fn?.().Foo, _fn9 === void 0 || _fn9 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFieldSpecGet(_ref63, Foo, _self).getSelf(), Foo, _x); + (_ref66 = _ref65 = (_ref64 = _fn10 = fn?.().Foo, _fn10 === void 0 || _fn10 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref64, Foo, _self).getSelf?.(), _ref65 === void 0 || _ref65 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref66, Foo, _x); + (_ref69 = (_ref68 = (_ref67 = _fn11 = fn?.().Foo, _fn11 === void 0 || _fn11 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref67, Foo, _self))?.getSelf(), _ref68 === void 0 || _ref68 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref69, Foo, _x); + (_ref72 = _ref71 = ((_ref70 = _fn12 = fn?.().Foo, _fn12 === void 0 || _fn12 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref70, Foo, _self))?.getSelf?.(), _ref71 === void 0 || _ref71 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref72, Foo, _x); + (_ref75 = (_ref74 = (_ref73 = _fn13 = fn?.().Foo, _fn13 === void 0 || _fn13 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref73, Foo, _self).getSelf())?.self, _ref74 === void 0 || _ref74 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref75, Foo, _x); + (_ref78 = (_ref77 = (_ref76 = _fn14 = fn?.().Foo, _fn14 === void 0 || _fn14 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref76, Foo, _self).getSelf?.())?.self, _ref77 === void 0 || _ref77 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref78, Foo, _x); + (_ref81 = (_ref80 = ((_ref79 = _fn15 = fn?.().Foo, _fn15 === void 0 || _fn15 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref79, Foo, _self))?.getSelf())?.self, _ref80 === void 0 || _ref80 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref81, Foo, _x); + (_ref84 = (_ref83 = ((_ref82 = _fn16 = fn?.().Foo, _fn16 === void 0 || _fn16 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref82, Foo, _self))?.getSelf?.())?.self, _ref83 === void 0 || _ref83 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref84, Foo, _x); } } From d77facd12e1b99e2c45e565d5d41c1ea036bfa4c Mon Sep 17 00:00:00 2001 From: Justin Ridgewell Date: Sat, 14 Mar 2020 03:57:32 -0400 Subject: [PATCH 04/20] Reduce temporary variables --- .../src/index.js | 102 ++++++++++----- .../optional-chain-with-transform/exec.js | 121 ++++++++++++++++++ .../optional-chain-with-transform/input.js | 65 ++++++++++ .../options.json | 3 + .../optional-chain-with-transform/output.js | 83 ++++++++++++ .../optional-chain-with-transform/output.js | 46 +++---- .../optional-chain/optional-chain/input.js | 66 ++++++++++ .../optional-chain/options.json | 3 + .../optional-chain/optional-chain/output.js | 83 ++++++++++++ .../private-loose/optional-chain/output.js | 46 +++---- .../optional-chain-with-transform/exec.js | 115 +++++++++-------- .../optional-chain-with-transform/input.js | 1 + .../optional-chain-with-transform/output.js | 66 ++++++---- .../fixtures/private/optional-chain/output.js | 78 +++++------ 14 files changed, 680 insertions(+), 198 deletions(-) create mode 100644 packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-with-transform/optional-chain-with-transform/exec.js create mode 100644 packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-with-transform/optional-chain-with-transform/input.js create mode 100644 packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-with-transform/optional-chain-with-transform/options.json create mode 100644 packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-with-transform/optional-chain-with-transform/output.js create mode 100644 packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain/optional-chain/input.js create mode 100644 packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain/optional-chain/options.json create mode 100644 packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain/optional-chain/output.js 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 184d4be99aa7..fbb3f1d57fb9 100644 --- a/packages/babel-helper-member-expression-to-functions/src/index.js +++ b/packages/babel-helper-member-expression-to-functions/src/index.js @@ -29,6 +29,32 @@ class AssignmentMemoiser { } } +function toNonOptional(path, base) { + const { node } = path; + if (path.isOptionalMemberExpression()) { + return t.memberExpression(base, node.property, node.computed); + } + + if (path.isOptionalCallExpression()) { + const callee = path.get("callee"); + if (path.node.optional && callee.isOptionalMemberExpression()) { + const { object } = callee.node; + const context = path.scope.maybeGenerateMemoised(object) || object; + callee + .get("object") + .replaceWith(t.assignmentExpression("=", context, object)); + + return t.callExpression(t.memberExpression(base, t.identifier("call")), [ + context, + ...node.arguments, + ]); + } + + return t.callExpression(base, node.arguments); + } + throw path.buildCodeFrameError(`Cannot make ${path.type} non-optional`); +} + const handle = { memoise() { // noop. @@ -98,31 +124,17 @@ const handle = { startingOptional = startingOptional.get("callee"); continue; } - - debugger; - console.error(startingOptional.toString()); - // throw startingOptional.buildCodeFrameError( - // "failed to find nearest optional", - // ); } - debugger; const { scope } = member; - const { object } = node; const startingProp = startingOptional.isOptionalMemberExpression() ? "object" : "callee"; const startingNode = startingOptional.node[startingProp]; const baseRef = scope.generateUidIdentifierBasedOnNode(startingNode); - const valueRef = scope.generateUidIdentifierBasedOnNode(object); scope.push({ id: baseRef }); - scope.push({ id: valueRef }); - - startingOptional - .get(startingProp) - .replaceWith(t.assignmentExpression("=", baseRef, startingNode)); - member.replaceWith(t.memberExpression(valueRef, node.property)); + startingOptional.replaceWith(toNonOptional(startingOptional, baseRef)); if (parentPath.isOptionalCallExpression({ callee: node })) { parentPath.replaceWith(this.call(member, parent.arguments)); } else { @@ -131,33 +143,59 @@ const handle = { let regular = member.node; for (let current = member; current !== endPath; ) { - const { parentPath, parent } = current; - if (parentPath.isOptionalMemberExpression()) { - regular = t.memberExpression( - regular, - parent.property, - parent.computed, - ); - } else { - regular = t.callExpression(regular, parent.arguments); - } + const { parentPath } = current; + regular = toNonOptional(parentPath, regular); current = parentPath; } + let context; + const endParentPath = endPath.parentPath; + if ( + t.isMemberExpression(regular) && + endParentPath.isOptionalCallExpression({ + callee: endPath.node, + optional: true, + }) + ) { + const { object } = regular; + context = member.scope.maybeGenerateMemoised(object); + if (context) { + regular.object = t.assignmentExpression("=", context, object); + } + } + endPath.replaceWith( t.conditionalExpression( - t.sequenceExpression([ - t.assignmentExpression("=", valueRef, object), - t.logicalExpression( - "||", - t.binaryExpression("===", baseRef, scope.buildUndefinedNode()), - t.binaryExpression("===", baseRef, t.nullLiteral()), + t.logicalExpression( + "||", + t.binaryExpression( + "===", + t.assignmentExpression("=", baseRef, startingNode), + t.nullLiteral(), ), - ]), + t.binaryExpression("===", baseRef, scope.buildUndefinedNode()), + ), scope.buildUndefinedNode(), regular, ), ); + + if (context) { + const endParent = endParentPath.node; + endParentPath.replaceWith( + t.optionalCallExpression( + t.optionalMemberExpression( + endParent.callee, + t.identifier("call"), + endParent.computed, + true, + ), + [context, ...endParent.arguments], + false, + ), + ); + } + return; } diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-with-transform/optional-chain-with-transform/exec.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-with-transform/optional-chain-with-transform/exec.js new file mode 100644 index 000000000000..fc59ad1a86b9 --- /dev/null +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-with-transform/optional-chain-with-transform/exec.js @@ -0,0 +1,121 @@ +class Foo { + static #x = 1; + static #self = Foo; + static self = Foo; + static getSelf() { return this } + + static test() { + const o = { Foo: Foo }; + const deep = { very: { o } }; + function fn() { + return o; + } + function fnDeep() { + return deep; + } + + expect(o?.Foo.#x).toEqual(1); + expect(o?.Foo.#x.toString).toEqual(1..toString); + expect(o?.Foo.#x.toString()).toEqual('1'); + + expect(deep?.very.o?.Foo.#x).toEqual(1); + expect(deep?.very.o?.Foo.#x.toString).toEqual(1..toString); + expect(deep?.very.o?.Foo.#x.toString()).toEqual('1'); + + expect(o?.Foo.#self.#x).toEqual(1); + expect(o?.Foo.#self.self.#x).toEqual(1); + expect(o?.Foo.#self?.self.#x).toEqual(1); + expect(o?.Foo.#self.self?.self.#x).toEqual(1); + expect(o?.Foo.#self?.self?.self.#x).toEqual(1); + + expect(o?.Foo.#self.getSelf().#x).toEqual(1); + expect(o?.Foo.#self.getSelf?.().#x).toEqual(1); + expect(o?.Foo.#self?.getSelf().#x).toEqual(1); + expect(o?.Foo.#self?.getSelf?.().#x).toEqual(1); + expect(o?.Foo.#self.getSelf()?.self.#x).toEqual(1); + expect(o?.Foo.#self.getSelf?.()?.self.#x).toEqual(1); + expect(o?.Foo.#self?.getSelf()?.self.#x).toEqual(1); + expect(o?.Foo.#self?.getSelf?.()?.self.#x).toEqual(1); + + expect(fn?.().Foo.#x).toEqual(1); + expect(fn?.().Foo.#x.toString).toEqual(1..toString); + expect(fn?.().Foo.#x.toString()).toEqual('1'); + + expect(fnDeep?.().very.o?.Foo.#x).toEqual(1); + expect(fnDeep?.().very.o?.Foo.#x.toString).toEqual(1..toString); + expect(fnDeep?.().very.o?.Foo.#x.toString()).toEqual('1'); + + expect(fn?.().Foo.#self.#x).toEqual(1); + expect(fn?.().Foo.#self.self.#x).toEqual(1); + expect(fn?.().Foo.#self?.self.#x).toEqual(1); + expect(fn?.().Foo.#self.self?.self.#x).toEqual(1); + expect(fn?.().Foo.#self?.self?.self.#x).toEqual(1); + + expect(fn?.().Foo.#self.getSelf().#x).toEqual(1); + expect(fn?.().Foo.#self.getSelf?.().#x).toEqual(1); + expect(fn?.().Foo.#self?.getSelf().#x).toEqual(1); + expect(fn?.().Foo.#self?.getSelf?.().#x).toEqual(1); + expect(fn?.().Foo.#self.getSelf()?.self.#x).toEqual(1); + expect(fn?.().Foo.#self.getSelf?.()?.self.#x).toEqual(1); + expect(fn?.().Foo.#self?.getSelf()?.self.#x).toEqual(1); + expect(fn?.().Foo.#self?.getSelf?.()?.self.#x).toEqual(1); + } + + static testNull() { + const o = null;; + const deep = { very: { o } }; + const fn = null; + function fnDeep() { + return deep; + } + + expect(o?.Foo.#x).toEqual(undefined); + expect(o?.Foo.#x.toString).toEqual(undefined); + expect(o?.Foo.#x.toString()).toEqual(undefined); + + expect(deep?.very.o?.Foo.#x).toEqual(undefined); + expect(deep?.very.o?.Foo.#x.toString).toEqual(undefined); + expect(deep?.very.o?.Foo.#x.toString()).toEqual(undefined); + + expect(o?.Foo.#self.#x).toEqual(undefined); + expect(o?.Foo.#self.self.#x).toEqual(undefined); + expect(o?.Foo.#self?.self.#x).toEqual(undefined); + expect(o?.Foo.#self.self?.self.#x).toEqual(undefined); + expect(o?.Foo.#self?.self?.self.#x).toEqual(undefined); + + expect(o?.Foo.#self.getSelf().#x).toEqual(undefined); + expect(o?.Foo.#self.getSelf?.().#x).toEqual(undefined); + expect(o?.Foo.#self?.getSelf().#x).toEqual(undefined); + expect(o?.Foo.#self?.getSelf?.().#x).toEqual(undefined); + expect(o?.Foo.#self.getSelf()?.self.#x).toEqual(undefined); + expect(o?.Foo.#self.getSelf?.()?.self.#x).toEqual(undefined); + expect(o?.Foo.#self?.getSelf()?.self.#x).toEqual(undefined); + expect(o?.Foo.#self?.getSelf?.()?.self.#x).toEqual(undefined); + + expect(fn?.().Foo.#x).toEqual(undefined); + expect(fn?.().Foo.#x.toString).toEqual(undefined); + expect(fn?.().Foo.#x.toString()).toEqual(undefined); + + expect(fnDeep?.().very.o?.Foo.#x).toEqual(undefined); + expect(fnDeep?.().very.o?.Foo.#x.toString).toEqual(undefined); + expect(fnDeep?.().very.o?.Foo.#x.toString()).toEqual(undefined); + + expect(fn?.().Foo.#self.#x).toEqual(undefined); + expect(fn?.().Foo.#self.self.#x).toEqual(undefined); + expect(fn?.().Foo.#self?.self.#x).toEqual(undefined); + expect(fn?.().Foo.#self.self?.self.#x).toEqual(undefined); + expect(fn?.().Foo.#self?.self?.self.#x).toEqual(undefined); + + expect(fn?.().Foo.#self.getSelf().#x).toEqual(undefined); + expect(fn?.().Foo.#self.getSelf?.().#x).toEqual(undefined); + expect(fn?.().Foo.#self?.getSelf().#x).toEqual(undefined); + expect(fn?.().Foo.#self?.getSelf?.().#x).toEqual(undefined); + expect(fn?.().Foo.#self.getSelf()?.self.#x).toEqual(undefined); + expect(fn?.().Foo.#self.getSelf?.()?.self.#x).toEqual(undefined); + expect(fn?.().Foo.#self?.getSelf()?.self.#x).toEqual(undefined); + expect(fn?.().Foo.#self?.getSelf?.()?.self.#x).toEqual(undefined); + } +} + +// Foo.test(); +Foo.testNull(); diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-with-transform/optional-chain-with-transform/input.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-with-transform/optional-chain-with-transform/input.js new file mode 100644 index 000000000000..fad2504d95e6 --- /dev/null +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-with-transform/optional-chain-with-transform/input.js @@ -0,0 +1,65 @@ +class Foo { + static #x = 1; + static #self = Foo; + static self = Foo; + static getSelf() { return this } + + static test() { + const o = { Foo: Foo }; + const deep = { very: { o } }; + function fn() { + return o; + } + function fnDeep() { + return deep; + } + + o?.Foo.#x; + o?.Foo.#x.toString; + o?.Foo.#x.toString(); + + deep?.very.o?.Foo.#x; + deep?.very.o?.Foo.#x.toString; + deep?.very.o?.Foo.#x.toString(); + + o?.Foo.#self.#x; + o?.Foo.#self.self.#x; + o?.Foo.#self?.self.#x; + o?.Foo.#self.self?.self.#x; + o?.Foo.#self?.self?.self.#x; + + o?.Foo.#self.getSelf().#x; + o?.Foo.#self.getSelf?.().#x; + o?.Foo.#self?.getSelf().#x; + o?.Foo.#self?.getSelf?.().#x; + o?.Foo.#self.getSelf()?.self.#x; + o?.Foo.#self.getSelf?.()?.self.#x; + o?.Foo.#self?.getSelf()?.self.#x; + o?.Foo.#self?.getSelf?.()?.self.#x; + + fn?.().Foo.#x; + fn?.().Foo.#x.toString; + fn?.().Foo.#x.toString(); + + fnDeep?.().very.o?.Foo.#x; + fnDeep?.().very.o?.Foo.#x.toString; + fnDeep?.().very.o?.Foo.#x.toString(); + + fn?.().Foo.#self.#x; + fn?.().Foo.#self.self.#x; + fn?.().Foo.#self?.self.#x; + fn?.().Foo.#self.self?.self.#x; + fn?.().Foo.#self?.self?.self.#x; + + fn?.().Foo.#self.getSelf().#x; + fn?.().Foo.#self.getSelf?.().#x; + fn?.().Foo.#self?.getSelf().#x; + fn?.().Foo.#self?.getSelf?.().#x; + fn?.().Foo.#self.getSelf()?.self.#x; + fn?.().Foo.#self.getSelf?.()?.self.#x; + fn?.().Foo.#self?.getSelf()?.self.#x; + fn?.().Foo.#self?.getSelf?.()?.self.#x; + } +} + +Foo.test(); diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-with-transform/optional-chain-with-transform/options.json b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-with-transform/optional-chain-with-transform/options.json new file mode 100644 index 000000000000..63b4c77cc8e8 --- /dev/null +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-with-transform/optional-chain-with-transform/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["proposal-optional-chaining", "proposal-class-properties"] +} diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-with-transform/optional-chain-with-transform/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-with-transform/optional-chain-with-transform/output.js new file mode 100644 index 000000000000..1525a03dc3cd --- /dev/null +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-with-transform/optional-chain-with-transform/output.js @@ -0,0 +1,83 @@ +function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } + +function _classStaticPrivateFieldSpecGet(receiver, classConstructor, descriptor) { if (receiver !== classConstructor) { throw new TypeError("Private static access of wrong provenance"); } if (descriptor.get) { return descriptor.get.call(receiver); } return descriptor.value; } + +class Foo { + static getSelf() { + return this; + } + + static test() { + var _o, _o2, _o3, _ref, _ref2, _ref3, _o4, _o5, _o6, _ref4, _o7, _ref5, _o8, _ref6, _o9, _o10, _classStaticPrivateFi, _ref7, _o11, _ref8, _o12, _ref9, _ref10, _o13, _ref11, _o14, _classStaticPrivateFi2, _ref12, _o15, _ref13, _o16, _ref14, _fn, _fn2, _fn3, _ref15, _ref16, _ref17, _fn4, _fn5, _fn6, _ref18, _fn7, _ref19, _fn8, _ref20, _fn9, _fn10, _classStaticPrivateFi3, _ref21, _fn11, _ref22, _fn12, _ref23, _ref24, _fn13, _ref25, _fn14, _classStaticPrivateFi4, _ref26, _fn15, _ref27, _fn16, _ref28, _ref29, _ref30, _ref31, _ref32, _ref33, _ref33$getSelf, _ref34, _ref35, _ref36, _ref37, _ref38, _ref38$getSelf; + + const o = { + Foo: Foo + }; + const deep = { + very: { + o + } + }; + + function fn() { + return o; + } + + function fnDeep() { + return deep; + } + + (_o = o) === null || _o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o.Foo, Foo, _x); + (_o2 = o) === null || _o2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o2.Foo, Foo, _x).toString; + (_o3 = o) === null || _o3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o3.Foo, Foo, _x).toString(); + (_ref = deep === null || deep === void 0 ? void 0 : deep.very.o) === null || _ref === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref.Foo, Foo, _x); + (_ref2 = deep === null || deep === void 0 ? void 0 : deep.very.o) === null || _ref2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref2.Foo, Foo, _x).toString; + (_ref3 = deep === null || deep === void 0 ? void 0 : deep.very.o) === null || _ref3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref3.Foo, Foo, _x).toString(); + (_o4 = o) === null || _o4 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFieldSpecGet(_o4.Foo, Foo, _self), Foo, _x); + (_o5 = o) === null || _o5 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFieldSpecGet(_o5.Foo, Foo, _self).self, Foo, _x); + (_ref4 = (_o6 = o) === null || _o6 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o6.Foo, Foo, _self)) === null || _ref4 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref4.self, Foo, _x); + (_ref5 = (_o7 = o) === null || _o7 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o7.Foo, Foo, _self).self) === null || _ref5 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref5.self, Foo, _x); + (_ref6 = (_ref29 = (_o8 = o) === null || _o8 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o8.Foo, Foo, _self)) === null || _ref29 === void 0 ? void 0 : _ref29.self) === null || _ref6 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref6.self, Foo, _x); + (_o9 = o) === null || _o9 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFieldSpecGet(_o9.Foo, Foo, _self).getSelf(), Foo, _x); + (_ref7 = (_o10 = o) === null || _o10 === void 0 ? void 0 : (_classStaticPrivateFi = _classStaticPrivateFieldSpecGet(_o10.Foo, Foo, _self)).getSelf) === null || _ref7 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref7.call(_classStaticPrivateFi), Foo, _x); + (_ref8 = (_o11 = o) === null || _o11 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o11.Foo, Foo, _self)) === null || _ref8 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref8.getSelf(), Foo, _x); + (_ref9 = (_ref30 = _ref10 = (_o12 = o) === null || _o12 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o12.Foo, Foo, _self)) === null || _ref30 === void 0 ? void 0 : _ref30.getSelf) === null || _ref9 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref9.call(_ref10), Foo, _x); + (_ref11 = (_o13 = o) === null || _o13 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o13.Foo, Foo, _self).getSelf()) === null || _ref11 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref11.self, Foo, _x); + (_ref12 = (_ref31 = (_o14 = o) === null || _o14 === void 0 ? void 0 : (_classStaticPrivateFi2 = _classStaticPrivateFieldSpecGet(_o14.Foo, Foo, _self)).getSelf) === null || _ref31 === void 0 ? void 0 : _ref31.call(_classStaticPrivateFi2)) === null || _ref12 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref12.self, Foo, _x); + (_ref13 = (_ref32 = (_o15 = o) === null || _o15 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o15.Foo, Foo, _self)) === null || _ref32 === void 0 ? void 0 : _ref32.getSelf()) === null || _ref13 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref13.self, Foo, _x); + (_ref14 = (_ref33 = (_o16 = o) === null || _o16 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o16.Foo, Foo, _self)) === null || _ref33 === void 0 ? void 0 : (_ref33$getSelf = _ref33.getSelf) === null || _ref33$getSelf === void 0 ? void 0 : _ref33$getSelf.call(_ref33)) === null || _ref14 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref14.self, Foo, _x); + (_fn = fn) === null || _fn === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn().Foo, Foo, _x); + (_fn2 = fn) === null || _fn2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn2().Foo, Foo, _x).toString; + (_fn3 = fn) === null || _fn3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn3().Foo, Foo, _x).toString(); + (_ref15 = fnDeep === null || fnDeep === void 0 ? void 0 : fnDeep().very.o) === null || _ref15 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref15.Foo, Foo, _x); + (_ref16 = fnDeep === null || fnDeep === void 0 ? void 0 : fnDeep().very.o) === null || _ref16 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref16.Foo, Foo, _x).toString; + (_ref17 = fnDeep === null || fnDeep === void 0 ? void 0 : fnDeep().very.o) === null || _ref17 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref17.Foo, Foo, _x).toString(); + (_fn4 = fn) === null || _fn4 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFieldSpecGet(_fn4().Foo, Foo, _self), Foo, _x); + (_fn5 = fn) === null || _fn5 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFieldSpecGet(_fn5().Foo, Foo, _self).self, Foo, _x); + (_ref18 = (_fn6 = fn) === null || _fn6 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn6().Foo, Foo, _self)) === null || _ref18 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref18.self, Foo, _x); + (_ref19 = (_fn7 = fn) === null || _fn7 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn7().Foo, Foo, _self).self) === null || _ref19 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref19.self, Foo, _x); + (_ref20 = (_ref34 = (_fn8 = fn) === null || _fn8 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn8().Foo, Foo, _self)) === null || _ref34 === void 0 ? void 0 : _ref34.self) === null || _ref20 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref20.self, Foo, _x); + (_fn9 = fn) === null || _fn9 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFieldSpecGet(_fn9().Foo, Foo, _self).getSelf(), Foo, _x); + (_ref21 = (_fn10 = fn) === null || _fn10 === void 0 ? void 0 : (_classStaticPrivateFi3 = _classStaticPrivateFieldSpecGet(_fn10().Foo, Foo, _self)).getSelf) === null || _ref21 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref21.call(_classStaticPrivateFi3), Foo, _x); + (_ref22 = (_fn11 = fn) === null || _fn11 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn11().Foo, Foo, _self)) === null || _ref22 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref22.getSelf(), Foo, _x); + (_ref23 = (_ref35 = _ref24 = (_fn12 = fn) === null || _fn12 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn12().Foo, Foo, _self)) === null || _ref35 === void 0 ? void 0 : _ref35.getSelf) === null || _ref23 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref23.call(_ref24), Foo, _x); + (_ref25 = (_fn13 = fn) === null || _fn13 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn13().Foo, Foo, _self).getSelf()) === null || _ref25 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref25.self, Foo, _x); + (_ref26 = (_ref36 = (_fn14 = fn) === null || _fn14 === void 0 ? void 0 : (_classStaticPrivateFi4 = _classStaticPrivateFieldSpecGet(_fn14().Foo, Foo, _self)).getSelf) === null || _ref36 === void 0 ? void 0 : _ref36.call(_classStaticPrivateFi4)) === null || _ref26 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref26.self, Foo, _x); + (_ref27 = (_ref37 = (_fn15 = fn) === null || _fn15 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn15().Foo, Foo, _self)) === null || _ref37 === void 0 ? void 0 : _ref37.getSelf()) === null || _ref27 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref27.self, Foo, _x); + (_ref28 = (_ref38 = (_fn16 = fn) === null || _fn16 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn16().Foo, Foo, _self)) === null || _ref38 === void 0 ? void 0 : (_ref38$getSelf = _ref38.getSelf) === null || _ref38$getSelf === void 0 ? void 0 : _ref38$getSelf.call(_ref38)) === null || _ref28 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref28.self, Foo, _x); + } + +} + +var _x = { + writable: true, + value: 1 +}; +var _self = { + writable: true, + value: Foo +}; + +_defineProperty(Foo, "self", Foo); + +Foo.test(); diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-with-transform/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-with-transform/output.js index 456449f649bc..5ef3ddaa00bc 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-with-transform/output.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-with-transform/output.js @@ -6,7 +6,7 @@ function _classPrivateFieldLooseKey(name) { return "__private_" + id++ + "_" + n class Foo { static test() { - var _o, _ref, _o2, _ref2, _o3, _ref3, _ref4, _ref5, _ref6, _ref7, _ref8, _ref9, _o4, _ref10, _o5, _ref11, _o6, _ref12, _ref13, _ref14, _o7, _ref15, _ref16, _ref17, _o8, _ref18, _ref19, _ref20, _fn, _ref21, _fn2, _ref22, _fn3, _ref23, _ref24, _ref25, _ref26, _ref27, _ref28, _ref29, _fn4, _ref30, _fn5, _ref31, _fn6, _ref32, _ref33, _ref34, _fn7, _ref35, _ref36, _ref37, _fn8, _ref38, _ref39, _ref40, _o9, _o10, _o11, _ref41, _ref42, _ref43, _o12, _o13, _ref44, _o14, _ref45, _o15, _ref46, _ref47, _o16, _fn9, _fn10, _fn11, _ref48, _ref49, _ref50, _fn12, _fn13, _ref51, _fn14, _ref52, _fn15, _ref53, _ref54, _fn16; + var _o, _o2, _o3, _ref, _ref2, _ref3, _o4, _o5, _o6, _ref4, _o7, _ref5, _o8, _ref6, _fn, _fn2, _fn3, _ref7, _ref8, _ref9, _fn4, _fn5, _fn6, _ref10, _fn7, _ref11, _fn8, _ref12, _ref13, _ref14; const o = { Foo: Foo @@ -25,28 +25,28 @@ class Foo { return deep; } - (_ref = (_o9 = _o = o) === null || _o9 === void 0 ? void 0 : _o9.Foo, _o === void 0 || _o === null) ? void 0 : _classPrivateFieldLooseBase(_ref, _x)[_x]; - (_ref2 = (_o10 = _o2 = o) === null || _o10 === void 0 ? void 0 : _o10.Foo, _o2 === void 0 || _o2 === null) ? void 0 : _classPrivateFieldLooseBase(_ref2, _x)[_x].toString; - (_ref3 = (_o11 = _o3 = o) === null || _o11 === void 0 ? void 0 : _o11.Foo, _o3 === void 0 || _o3 === null) ? void 0 : _classPrivateFieldLooseBase(_ref3, _x)[_x].toString(); - (_ref5 = (_ref41 = _ref4 = deep === null || deep === void 0 ? void 0 : deep.very.o) === null || _ref41 === void 0 ? void 0 : _ref41.Foo, _ref4 === void 0 || _ref4 === null) ? void 0 : _classPrivateFieldLooseBase(_ref5, _x)[_x]; - (_ref7 = (_ref42 = _ref6 = deep === null || deep === void 0 ? void 0 : deep.very.o) === null || _ref42 === void 0 ? void 0 : _ref42.Foo, _ref6 === void 0 || _ref6 === null) ? void 0 : _classPrivateFieldLooseBase(_ref7, _x)[_x].toString; - (_ref9 = (_ref43 = _ref8 = deep === null || deep === void 0 ? void 0 : deep.very.o) === null || _ref43 === void 0 ? void 0 : _ref43.Foo, _ref8 === void 0 || _ref8 === null) ? void 0 : _classPrivateFieldLooseBase(_ref9, _x)[_x].toString(); - (_ref10 = (_o12 = _o4 = o) === null || _o12 === void 0 ? void 0 : _o12.Foo, _o4 === void 0 || _o4 === null) ? void 0 : _classPrivateFieldLooseBase(_classPrivateFieldLooseBase(_ref10, _self)[_self], _x)[_x]; - (_ref11 = (_o13 = _o5 = o) === null || _o13 === void 0 ? void 0 : _o13.Foo, _o5 === void 0 || _o5 === null) ? void 0 : _classPrivateFieldLooseBase(_classPrivateFieldLooseBase(_ref11, _self)[_self].self, _x)[_x]; - (_ref14 = (_ref44 = _ref13 = (_ref12 = (_o14 = _o6 = o) === null || _o14 === void 0 ? void 0 : _o14.Foo, _o6 === void 0 || _o6 === null) ? void 0 : _classPrivateFieldLooseBase(_ref12, _self)[_self]) === null || _ref44 === void 0 ? void 0 : _ref44.self, _ref13 === void 0 || _ref13 === null) ? void 0 : _classPrivateFieldLooseBase(_ref14, _x)[_x]; - (_ref17 = (_ref45 = _ref16 = (_ref15 = (_o15 = _o7 = o) === null || _o15 === void 0 ? void 0 : _o15.Foo, _o7 === void 0 || _o7 === null) ? void 0 : _classPrivateFieldLooseBase(_ref15, _self)[_self].self) === null || _ref45 === void 0 ? void 0 : _ref45.self, _ref16 === void 0 || _ref16 === null) ? void 0 : _classPrivateFieldLooseBase(_ref17, _x)[_x]; - (_ref20 = (_ref46 = _ref19 = (_ref47 = (_ref18 = (_o16 = _o8 = o) === null || _o16 === void 0 ? void 0 : _o16.Foo, _o8 === void 0 || _o8 === null) ? void 0 : _classPrivateFieldLooseBase(_ref18, _self)[_self]) === null || _ref47 === void 0 ? void 0 : _ref47.self) === null || _ref46 === void 0 ? void 0 : _ref46.self, _ref19 === void 0 || _ref19 === null) ? void 0 : _classPrivateFieldLooseBase(_ref20, _x)[_x]; - (_ref21 = (_fn9 = _fn = fn) === null || _fn9 === void 0 ? void 0 : _fn9().Foo, _fn === void 0 || _fn === null) ? void 0 : _classPrivateFieldLooseBase(_ref21, _x)[_x]; - (_ref22 = (_fn10 = _fn2 = fn) === null || _fn10 === void 0 ? void 0 : _fn10().Foo, _fn2 === void 0 || _fn2 === null) ? void 0 : _classPrivateFieldLooseBase(_ref22, _x)[_x].toString; - (_ref23 = (_fn11 = _fn3 = fn) === null || _fn11 === void 0 ? void 0 : _fn11().Foo, _fn3 === void 0 || _fn3 === null) ? void 0 : _classPrivateFieldLooseBase(_ref23, _x)[_x].toString(); - (_ref25 = (_ref48 = _ref24 = fnDeep === null || fnDeep === void 0 ? void 0 : fnDeep().very.o) === null || _ref48 === void 0 ? void 0 : _ref48.Foo, _ref24 === void 0 || _ref24 === null) ? void 0 : _classPrivateFieldLooseBase(_ref25, _x)[_x]; - (_ref27 = (_ref49 = _ref26 = fnDeep === null || fnDeep === void 0 ? void 0 : fnDeep().very.o) === null || _ref49 === void 0 ? void 0 : _ref49.Foo, _ref26 === void 0 || _ref26 === null) ? void 0 : _classPrivateFieldLooseBase(_ref27, _x)[_x].toString; - (_ref29 = (_ref50 = _ref28 = fnDeep === null || fnDeep === void 0 ? void 0 : fnDeep().very.o) === null || _ref50 === void 0 ? void 0 : _ref50.Foo, _ref28 === void 0 || _ref28 === null) ? void 0 : _classPrivateFieldLooseBase(_ref29, _x)[_x].toString(); - (_ref30 = (_fn12 = _fn4 = fn) === null || _fn12 === void 0 ? void 0 : _fn12().Foo, _fn4 === void 0 || _fn4 === null) ? void 0 : _classPrivateFieldLooseBase(_classPrivateFieldLooseBase(_ref30, _self)[_self], _x)[_x]; - (_ref31 = (_fn13 = _fn5 = fn) === null || _fn13 === void 0 ? void 0 : _fn13().Foo, _fn5 === void 0 || _fn5 === null) ? void 0 : _classPrivateFieldLooseBase(_classPrivateFieldLooseBase(_ref31, _self)[_self].self, _x)[_x]; - (_ref34 = (_ref51 = _ref33 = (_ref32 = (_fn14 = _fn6 = fn) === null || _fn14 === void 0 ? void 0 : _fn14().Foo, _fn6 === void 0 || _fn6 === null) ? void 0 : _classPrivateFieldLooseBase(_ref32, _self)[_self]) === null || _ref51 === void 0 ? void 0 : _ref51.self, _ref33 === void 0 || _ref33 === null) ? void 0 : _classPrivateFieldLooseBase(_ref34, _x)[_x]; - (_ref37 = (_ref52 = _ref36 = (_ref35 = (_fn15 = _fn7 = fn) === null || _fn15 === void 0 ? void 0 : _fn15().Foo, _fn7 === void 0 || _fn7 === null) ? void 0 : _classPrivateFieldLooseBase(_ref35, _self)[_self].self) === null || _ref52 === void 0 ? void 0 : _ref52.self, _ref36 === void 0 || _ref36 === null) ? void 0 : _classPrivateFieldLooseBase(_ref37, _x)[_x]; - (_ref40 = (_ref53 = _ref39 = (_ref54 = (_ref38 = (_fn16 = _fn8 = fn) === null || _fn16 === void 0 ? void 0 : _fn16().Foo, _fn8 === void 0 || _fn8 === null) ? void 0 : _classPrivateFieldLooseBase(_ref38, _self)[_self]) === null || _ref54 === void 0 ? void 0 : _ref54.self) === null || _ref53 === void 0 ? void 0 : _ref53.self, _ref39 === void 0 || _ref39 === null) ? void 0 : _classPrivateFieldLooseBase(_ref40, _x)[_x]; + (_o = o) === null || _o === void 0 ? void 0 : _classPrivateFieldLooseBase(_o.Foo, _x)[_x]; + (_o2 = o) === null || _o2 === void 0 ? void 0 : _classPrivateFieldLooseBase(_o2.Foo, _x)[_x].toString; + (_o3 = o) === null || _o3 === void 0 ? void 0 : _classPrivateFieldLooseBase(_o3.Foo, _x)[_x].toString(); + (_ref = deep === null || deep === void 0 ? void 0 : deep.very.o) === null || _ref === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref.Foo, _x)[_x]; + (_ref2 = deep === null || deep === void 0 ? void 0 : deep.very.o) === null || _ref2 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref2.Foo, _x)[_x].toString; + (_ref3 = deep === null || deep === void 0 ? void 0 : deep.very.o) === null || _ref3 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref3.Foo, _x)[_x].toString(); + (_o4 = o) === null || _o4 === void 0 ? void 0 : _classPrivateFieldLooseBase(_classPrivateFieldLooseBase(_o4.Foo, _self)[_self], _x)[_x]; + (_o5 = o) === null || _o5 === void 0 ? void 0 : _classPrivateFieldLooseBase(_classPrivateFieldLooseBase(_o5.Foo, _self)[_self].self, _x)[_x]; + (_ref4 = (_o6 = o) === null || _o6 === void 0 ? void 0 : _classPrivateFieldLooseBase(_o6.Foo, _self)[_self]) === null || _ref4 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref4.self, _x)[_x]; + (_ref5 = (_o7 = o) === null || _o7 === void 0 ? void 0 : _classPrivateFieldLooseBase(_o7.Foo, _self)[_self].self) === null || _ref5 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref5.self, _x)[_x]; + (_ref6 = (_ref13 = (_o8 = o) === null || _o8 === void 0 ? void 0 : _classPrivateFieldLooseBase(_o8.Foo, _self)[_self]) === null || _ref13 === void 0 ? void 0 : _ref13.self) === null || _ref6 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref6.self, _x)[_x]; + (_fn = fn) === null || _fn === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn().Foo, _x)[_x]; + (_fn2 = fn) === null || _fn2 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn2().Foo, _x)[_x].toString; + (_fn3 = fn) === null || _fn3 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn3().Foo, _x)[_x].toString(); + (_ref7 = fnDeep === null || fnDeep === void 0 ? void 0 : fnDeep().very.o) === null || _ref7 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref7.Foo, _x)[_x]; + (_ref8 = fnDeep === null || fnDeep === void 0 ? void 0 : fnDeep().very.o) === null || _ref8 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref8.Foo, _x)[_x].toString; + (_ref9 = fnDeep === null || fnDeep === void 0 ? void 0 : fnDeep().very.o) === null || _ref9 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref9.Foo, _x)[_x].toString(); + (_fn4 = fn) === null || _fn4 === void 0 ? void 0 : _classPrivateFieldLooseBase(_classPrivateFieldLooseBase(_fn4().Foo, _self)[_self], _x)[_x]; + (_fn5 = fn) === null || _fn5 === void 0 ? void 0 : _classPrivateFieldLooseBase(_classPrivateFieldLooseBase(_fn5().Foo, _self)[_self].self, _x)[_x]; + (_ref10 = (_fn6 = fn) === null || _fn6 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn6().Foo, _self)[_self]) === null || _ref10 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref10.self, _x)[_x]; + (_ref11 = (_fn7 = fn) === null || _fn7 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn7().Foo, _self)[_self].self) === null || _ref11 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref11.self, _x)[_x]; + (_ref12 = (_ref14 = (_fn8 = fn) === null || _fn8 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn8().Foo, _self)[_self]) === null || _ref14 === void 0 ? void 0 : _ref14.self) === null || _ref12 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref12.self, _x)[_x]; } } diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain/optional-chain/input.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain/optional-chain/input.js new file mode 100644 index 000000000000..cf001da081fc --- /dev/null +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain/optional-chain/input.js @@ -0,0 +1,66 @@ +class Foo { + static #x = 1; + static #self = Foo; + static self = Foo; + static getSelf() { return this } + + static test() { + const o = { Foo: Foo }; + const deep = { very: { o } }; + function fn() { + return o; + } + function fnDeep() { + return deep; + } + + o?.Foo.#x; + o?.Foo.#x.toString; + o?.Foo.#x.toString(); + + deep?.very.o?.Foo.#x; + deep?.very.o?.Foo.#x.toString; + deep?.very.o?.Foo.#x.toString(); + + o?.Foo.#self.#x; + o?.Foo.#self.self.#x; + o?.Foo.#self?.self.#x; + o?.Foo.#self.self?.self.#x; + o?.Foo.#self?.self?.self.#x; + + o?.Foo.#self.getSelf().#x; + o?.Foo.#self.getSelf?.().#x; + o?.Foo.#self?.getSelf().#x; + o?.Foo.#self?.getSelf?.().#x; + o?.Foo.#self.getSelf()?.self.#x; + o?.Foo.#self.getSelf?.()?.self.#x; + o?.Foo.#self?.getSelf()?.self.#x; + o?.Foo.#self?.getSelf?.()?.self.#x; + + fn?.().Foo.#x; + fn?.().Foo.#x.toString; + fn?.().Foo.#x.toString(); + + fnDeep?.().very.o?.Foo.#x; + fnDeep?.().very.o?.Foo.#x.toString; + fnDeep?.().very.o?.Foo.#x.toString(); + + fn?.().Foo.#self.#x; + fn?.().Foo.#self.self.#x; + fn?.().Foo.#self?.self.#x; + fn?.().Foo.#self.self?.self.#x; + fn?.().Foo.#self?.self?.self.#x; + + fn?.().Foo.#self.getSelf().#x; + fn?.().Foo.#self.getSelf?.().#x; + fn?.().Foo.#self?.getSelf().#x; + fn?.().Foo.#self?.getSelf?.().#x; + fn?.().Foo.#self.getSelf()?.self.#x; + fn?.().Foo.#self.getSelf?.()?.self.#x; + fn?.().Foo.#self?.getSelf()?.self.#x; + fn?.().Foo.#self?.getSelf?.()?.self.#x; + + } +} + +Foo.test(); diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain/optional-chain/options.json b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain/optional-chain/options.json new file mode 100644 index 000000000000..19ed5174f545 --- /dev/null +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain/optional-chain/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["proposal-class-properties"] +} diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain/optional-chain/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain/optional-chain/output.js new file mode 100644 index 000000000000..7ade58140926 --- /dev/null +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain/optional-chain/output.js @@ -0,0 +1,83 @@ +function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } + +function _classStaticPrivateFieldSpecGet(receiver, classConstructor, descriptor) { if (receiver !== classConstructor) { throw new TypeError("Private static access of wrong provenance"); } if (descriptor.get) { return descriptor.get.call(receiver); } return descriptor.value; } + +class Foo { + static getSelf() { + return this; + } + + static test() { + var _o, _o2, _o3, _ref, _ref2, _ref3, _o4, _o5, _o6, _ref4, _o7, _ref5, _o8, _ref6, _o9, _o10, _ref7, _o11, _ref8, _o12, _ref9, _o13, _ref10, _o14, _ref11, _o15, _ref12, _o16, _ref13, _fn, _fn2, _fn3, _ref14, _ref15, _ref16, _fn4, _fn5, _fn6, _ref17, _fn7, _ref18, _fn8, _ref19, _fn9, _fn10, _ref20, _fn11, _ref21, _fn12, _ref22, _fn13, _ref23, _fn14, _ref24, _fn15, _ref25, _fn16, _ref26; + + const o = { + Foo: Foo + }; + const deep = { + very: { + o + } + }; + + function fn() { + return o; + } + + function fnDeep() { + return deep; + } + + (_o = o) === null || _o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o?.Foo, Foo, _x); + (_o2 = o) === null || _o2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o2?.Foo, Foo, _x).toString; + (_o3 = o) === null || _o3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o3?.Foo, Foo, _x).toString(); + (_ref = deep?.very.o) === null || _ref === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref?.Foo, Foo, _x); + (_ref2 = deep?.very.o) === null || _ref2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref2?.Foo, Foo, _x).toString; + (_ref3 = deep?.very.o) === null || _ref3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref3?.Foo, Foo, _x).toString(); + (_o4 = o) === null || _o4 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFieldSpecGet(_o4?.Foo, Foo, _self), Foo, _x); + (_o5 = o) === null || _o5 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFieldSpecGet(_o5?.Foo, Foo, _self).self, Foo, _x); + (_ref4 = (_o6 = o) === null || _o6 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o6?.Foo, Foo, _self)) === null || _ref4 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref4?.self, Foo, _x); + (_ref5 = (_o7 = o) === null || _o7 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o7?.Foo, Foo, _self).self) === null || _ref5 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref5?.self, Foo, _x); + (_ref6 = ((_o8 = o) === null || _o8 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o8?.Foo, Foo, _self))?.self) === null || _ref6 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref6?.self, Foo, _x); + (_o9 = o) === null || _o9 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFieldSpecGet(_o9?.Foo, Foo, _self).getSelf(), Foo, _x); + (_ref7 = (_o10 = o) === null || _o10 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o10?.Foo, Foo, _self).getSelf) === null || _ref7 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref7?.(), Foo, _x); + (_ref8 = (_o11 = o) === null || _o11 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o11?.Foo, Foo, _self)) === null || _ref8 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref8?.getSelf(), Foo, _x); + (_ref9 = ((_o12 = o) === null || _o12 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o12?.Foo, Foo, _self))?.getSelf) === null || _ref9 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref9?.(), Foo, _x); + (_ref10 = (_o13 = o) === null || _o13 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o13?.Foo, Foo, _self).getSelf()) === null || _ref10 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref10?.self, Foo, _x); + (_ref11 = ((_o14 = o) === null || _o14 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o14?.Foo, Foo, _self).getSelf)?.()) === null || _ref11 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref11?.self, Foo, _x); + (_ref12 = ((_o15 = o) === null || _o15 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o15?.Foo, Foo, _self))?.getSelf()) === null || _ref12 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref12?.self, Foo, _x); + (_ref13 = ((_o16 = o) === null || _o16 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o16?.Foo, Foo, _self))?.getSelf?.()) === null || _ref13 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref13?.self, Foo, _x); + (_fn = fn) === null || _fn === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn?.().Foo, Foo, _x); + (_fn2 = fn) === null || _fn2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn2?.().Foo, Foo, _x).toString; + (_fn3 = fn) === null || _fn3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn3?.().Foo, Foo, _x).toString(); + (_ref14 = fnDeep?.().very.o) === null || _ref14 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref14?.Foo, Foo, _x); + (_ref15 = fnDeep?.().very.o) === null || _ref15 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref15?.Foo, Foo, _x).toString; + (_ref16 = fnDeep?.().very.o) === null || _ref16 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref16?.Foo, Foo, _x).toString(); + (_fn4 = fn) === null || _fn4 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFieldSpecGet(_fn4?.().Foo, Foo, _self), Foo, _x); + (_fn5 = fn) === null || _fn5 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFieldSpecGet(_fn5?.().Foo, Foo, _self).self, Foo, _x); + (_ref17 = (_fn6 = fn) === null || _fn6 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn6?.().Foo, Foo, _self)) === null || _ref17 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref17?.self, Foo, _x); + (_ref18 = (_fn7 = fn) === null || _fn7 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn7?.().Foo, Foo, _self).self) === null || _ref18 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref18?.self, Foo, _x); + (_ref19 = ((_fn8 = fn) === null || _fn8 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn8?.().Foo, Foo, _self))?.self) === null || _ref19 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref19?.self, Foo, _x); + (_fn9 = fn) === null || _fn9 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFieldSpecGet(_fn9?.().Foo, Foo, _self).getSelf(), Foo, _x); + (_ref20 = (_fn10 = fn) === null || _fn10 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn10?.().Foo, Foo, _self).getSelf) === null || _ref20 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref20?.(), Foo, _x); + (_ref21 = (_fn11 = fn) === null || _fn11 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn11?.().Foo, Foo, _self)) === null || _ref21 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref21?.getSelf(), Foo, _x); + (_ref22 = ((_fn12 = fn) === null || _fn12 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn12?.().Foo, Foo, _self))?.getSelf) === null || _ref22 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref22?.(), Foo, _x); + (_ref23 = (_fn13 = fn) === null || _fn13 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn13?.().Foo, Foo, _self).getSelf()) === null || _ref23 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref23?.self, Foo, _x); + (_ref24 = ((_fn14 = fn) === null || _fn14 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn14?.().Foo, Foo, _self).getSelf)?.()) === null || _ref24 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref24?.self, Foo, _x); + (_ref25 = ((_fn15 = fn) === null || _fn15 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn15?.().Foo, Foo, _self))?.getSelf()) === null || _ref25 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref25?.self, Foo, _x); + (_ref26 = ((_fn16 = fn) === null || _fn16 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn16?.().Foo, Foo, _self))?.getSelf?.()) === null || _ref26 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref26?.self, Foo, _x); + } + +} + +var _x = { + writable: true, + value: 1 +}; +var _self = { + writable: true, + value: Foo +}; + +_defineProperty(Foo, "self", Foo); + +Foo.test(); diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain/output.js index a5d7c7957797..5e31609d5128 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain/output.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain/output.js @@ -6,7 +6,7 @@ function _classPrivateFieldLooseKey(name) { return "__private_" + id++ + "_" + n class Foo { static test() { - var _o, _ref, _o2, _ref2, _o3, _ref3, _ref4, _ref5, _ref6, _ref7, _ref8, _ref9, _o4, _ref10, _o5, _ref11, _o6, _ref12, _ref13, _ref14, _o7, _ref15, _ref16, _ref17, _o8, _ref18, _ref19, _ref20, _fn, _ref21, _fn2, _ref22, _fn3, _ref23, _ref24, _ref25, _ref26, _ref27, _ref28, _ref29, _fn4, _ref30, _fn5, _ref31, _fn6, _ref32, _ref33, _ref34, _fn7, _ref35, _ref36, _ref37, _fn8, _ref38, _ref39, _ref40; + var _o, _o2, _o3, _ref, _ref2, _ref3, _o4, _o5, _o6, _ref4, _o7, _ref5, _o8, _ref6, _fn, _fn2, _fn3, _ref7, _ref8, _ref9, _fn4, _fn5, _fn6, _ref10, _fn7, _ref11, _fn8, _ref12; const o = { Foo: Foo @@ -25,28 +25,28 @@ class Foo { return deep; } - (_ref = (_o = o)?.Foo, _o === void 0 || _o === null) ? void 0 : _classPrivateFieldLooseBase(_ref, _x)[_x]; - (_ref2 = (_o2 = o)?.Foo, _o2 === void 0 || _o2 === null) ? void 0 : _classPrivateFieldLooseBase(_ref2, _x)[_x].toString; - (_ref3 = (_o3 = o)?.Foo, _o3 === void 0 || _o3 === null) ? void 0 : _classPrivateFieldLooseBase(_ref3, _x)[_x].toString(); - (_ref5 = (_ref4 = deep?.very.o)?.Foo, _ref4 === void 0 || _ref4 === null) ? void 0 : _classPrivateFieldLooseBase(_ref5, _x)[_x]; - (_ref7 = (_ref6 = deep?.very.o)?.Foo, _ref6 === void 0 || _ref6 === null) ? void 0 : _classPrivateFieldLooseBase(_ref7, _x)[_x].toString; - (_ref9 = (_ref8 = deep?.very.o)?.Foo, _ref8 === void 0 || _ref8 === null) ? void 0 : _classPrivateFieldLooseBase(_ref9, _x)[_x].toString(); - (_ref10 = (_o4 = o)?.Foo, _o4 === void 0 || _o4 === null) ? void 0 : _classPrivateFieldLooseBase(_classPrivateFieldLooseBase(_ref10, _self)[_self], _x)[_x]; - (_ref11 = (_o5 = o)?.Foo, _o5 === void 0 || _o5 === null) ? void 0 : _classPrivateFieldLooseBase(_classPrivateFieldLooseBase(_ref11, _self)[_self].self, _x)[_x]; - (_ref14 = (_ref13 = (_ref12 = (_o6 = o)?.Foo, _o6 === void 0 || _o6 === null) ? void 0 : _classPrivateFieldLooseBase(_ref12, _self)[_self])?.self, _ref13 === void 0 || _ref13 === null) ? void 0 : _classPrivateFieldLooseBase(_ref14, _x)[_x]; - (_ref17 = (_ref16 = (_ref15 = (_o7 = o)?.Foo, _o7 === void 0 || _o7 === null) ? void 0 : _classPrivateFieldLooseBase(_ref15, _self)[_self].self)?.self, _ref16 === void 0 || _ref16 === null) ? void 0 : _classPrivateFieldLooseBase(_ref17, _x)[_x]; - (_ref20 = (_ref19 = ((_ref18 = (_o8 = o)?.Foo, _o8 === void 0 || _o8 === null) ? void 0 : _classPrivateFieldLooseBase(_ref18, _self)[_self])?.self)?.self, _ref19 === void 0 || _ref19 === null) ? void 0 : _classPrivateFieldLooseBase(_ref20, _x)[_x]; - (_ref21 = _fn = fn?.().Foo, _fn === void 0 || _fn === null) ? void 0 : _classPrivateFieldLooseBase(_ref21, _x)[_x]; - (_ref22 = _fn2 = fn?.().Foo, _fn2 === void 0 || _fn2 === null) ? void 0 : _classPrivateFieldLooseBase(_ref22, _x)[_x].toString; - (_ref23 = _fn3 = fn?.().Foo, _fn3 === void 0 || _fn3 === null) ? void 0 : _classPrivateFieldLooseBase(_ref23, _x)[_x].toString(); - (_ref25 = (_ref24 = fnDeep?.().very.o)?.Foo, _ref24 === void 0 || _ref24 === null) ? void 0 : _classPrivateFieldLooseBase(_ref25, _x)[_x]; - (_ref27 = (_ref26 = fnDeep?.().very.o)?.Foo, _ref26 === void 0 || _ref26 === null) ? void 0 : _classPrivateFieldLooseBase(_ref27, _x)[_x].toString; - (_ref29 = (_ref28 = fnDeep?.().very.o)?.Foo, _ref28 === void 0 || _ref28 === null) ? void 0 : _classPrivateFieldLooseBase(_ref29, _x)[_x].toString(); - (_ref30 = _fn4 = fn?.().Foo, _fn4 === void 0 || _fn4 === null) ? void 0 : _classPrivateFieldLooseBase(_classPrivateFieldLooseBase(_ref30, _self)[_self], _x)[_x]; - (_ref31 = _fn5 = fn?.().Foo, _fn5 === void 0 || _fn5 === null) ? void 0 : _classPrivateFieldLooseBase(_classPrivateFieldLooseBase(_ref31, _self)[_self].self, _x)[_x]; - (_ref34 = (_ref33 = (_ref32 = _fn6 = fn?.().Foo, _fn6 === void 0 || _fn6 === null) ? void 0 : _classPrivateFieldLooseBase(_ref32, _self)[_self])?.self, _ref33 === void 0 || _ref33 === null) ? void 0 : _classPrivateFieldLooseBase(_ref34, _x)[_x]; - (_ref37 = (_ref36 = (_ref35 = _fn7 = fn?.().Foo, _fn7 === void 0 || _fn7 === null) ? void 0 : _classPrivateFieldLooseBase(_ref35, _self)[_self].self)?.self, _ref36 === void 0 || _ref36 === null) ? void 0 : _classPrivateFieldLooseBase(_ref37, _x)[_x]; - (_ref40 = (_ref39 = ((_ref38 = _fn8 = fn?.().Foo, _fn8 === void 0 || _fn8 === null) ? void 0 : _classPrivateFieldLooseBase(_ref38, _self)[_self])?.self)?.self, _ref39 === void 0 || _ref39 === null) ? void 0 : _classPrivateFieldLooseBase(_ref40, _x)[_x]; + (_o = o) === null || _o === void 0 ? void 0 : _classPrivateFieldLooseBase(_o.Foo, _x)[_x]; + (_o2 = o) === null || _o2 === void 0 ? void 0 : _classPrivateFieldLooseBase(_o2.Foo, _x)[_x].toString; + (_o3 = o) === null || _o3 === void 0 ? void 0 : _classPrivateFieldLooseBase(_o3.Foo, _x)[_x].toString(); + (_ref = deep?.very.o) === null || _ref === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref.Foo, _x)[_x]; + (_ref2 = deep?.very.o) === null || _ref2 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref2.Foo, _x)[_x].toString; + (_ref3 = deep?.very.o) === null || _ref3 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref3.Foo, _x)[_x].toString(); + (_o4 = o) === null || _o4 === void 0 ? void 0 : _classPrivateFieldLooseBase(_classPrivateFieldLooseBase(_o4.Foo, _self)[_self], _x)[_x]; + (_o5 = o) === null || _o5 === void 0 ? void 0 : _classPrivateFieldLooseBase(_classPrivateFieldLooseBase(_o5.Foo, _self)[_self].self, _x)[_x]; + (_ref4 = (_o6 = o) === null || _o6 === void 0 ? void 0 : _classPrivateFieldLooseBase(_o6.Foo, _self)[_self]) === null || _ref4 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref4.self, _x)[_x]; + (_ref5 = (_o7 = o) === null || _o7 === void 0 ? void 0 : _classPrivateFieldLooseBase(_o7.Foo, _self)[_self].self) === null || _ref5 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref5.self, _x)[_x]; + (_ref6 = ((_o8 = o) === null || _o8 === void 0 ? void 0 : _classPrivateFieldLooseBase(_o8.Foo, _self)[_self])?.self) === null || _ref6 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref6.self, _x)[_x]; + (_fn = fn) === null || _fn === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn().Foo, _x)[_x]; + (_fn2 = fn) === null || _fn2 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn2().Foo, _x)[_x].toString; + (_fn3 = fn) === null || _fn3 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn3().Foo, _x)[_x].toString(); + (_ref7 = fnDeep?.().very.o) === null || _ref7 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref7.Foo, _x)[_x]; + (_ref8 = fnDeep?.().very.o) === null || _ref8 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref8.Foo, _x)[_x].toString; + (_ref9 = fnDeep?.().very.o) === null || _ref9 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref9.Foo, _x)[_x].toString(); + (_fn4 = fn) === null || _fn4 === void 0 ? void 0 : _classPrivateFieldLooseBase(_classPrivateFieldLooseBase(_fn4().Foo, _self)[_self], _x)[_x]; + (_fn5 = fn) === null || _fn5 === void 0 ? void 0 : _classPrivateFieldLooseBase(_classPrivateFieldLooseBase(_fn5().Foo, _self)[_self].self, _x)[_x]; + (_ref10 = (_fn6 = fn) === null || _fn6 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn6().Foo, _self)[_self]) === null || _ref10 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref10.self, _x)[_x]; + (_ref11 = (_fn7 = fn) === null || _fn7 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn7().Foo, _self)[_self].self) === null || _ref11 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref11.self, _x)[_x]; + (_ref12 = ((_fn8 = fn) === null || _fn8 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn8().Foo, _self)[_self])?.self) === null || _ref12 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref12.self, _x)[_x]; } } diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-with-transform/exec.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-with-transform/exec.js index b3b2d67e9771..fc59ad1a86b9 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-with-transform/exec.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-with-transform/exec.js @@ -2,6 +2,7 @@ class Foo { static #x = 1; static #self = Foo; static self = Foo; + static getSelf() { return this } static test() { const o = { Foo: Foo }; @@ -13,63 +14,6 @@ class Foo { return deep; } - expect(o?.Foo.#x).toEqual(undefined); - expect(o?.Foo.#x.toString).toEqual(undefined); - expect(o?.Foo.#x.toString()).toEqual(undefined); - - expect(deep?.very.o?.Foo.#x).toEqual(undefined); - expect(deep?.very.o?.Foo.#x.toString).toEqual(undefined); - expect(deep?.very.o?.Foo.#x.toString()).toEqual(undefined); - - expect(o?.Foo.#self.#x).toEqual(undefined); - expect(o?.Foo.#self.self.#x).toEqual(undefined); - expect(o?.Foo.#self?.self.#x).toEqual(undefined); - expect(o?.Foo.#self.self?.self.#x).toEqual(undefined); - expect(o?.Foo.#self?.self?.self.#x).toEqual(undefined); - - expect(o?.Foo.#self.getSelf().#x).toEqual(undefined); - expect(o?.Foo.#self.getSelf?.().#x).toEqual(undefined); - expect(o?.Foo.#self?.getSelf().#x).toEqual(undefined); - expect(o?.Foo.#self?.getSelf?.().#x).toEqual(undefined); - expect(o?.Foo.#self.getSelf()?.self.#x).toEqual(undefined); - expect(o?.Foo.#self.getSelf?.()?.self.#x).toEqual(undefined); - expect(o?.Foo.#self?.getSelf()?.self.#x).toEqual(undefined); - expect(o?.Foo.#self?.getSelf?.()?.self.#x).toEqual(undefined); - - expect(fn?.().Foo.#x).toEqual(undefined); - expect(fn?.().Foo.#x.toString).toEqual(undefined); - expect(fn?.().Foo.#x.toString()).toEqual(undefined); - - expect(fnDeep?.().very.o?.Foo.#x).toEqual(undefined); - expect(fnDeep?.().very.o?.Foo.#x.toString).toEqual(undefined); - expect(fnDeep?.().very.o?.Foo.#x.toString()).toEqual(undefined); - - expect(fn?.().Foo.#self.#x).toEqual(undefined); - expect(fn?.().Foo.#self.self.#x).toEqual(undefined); - expect(fn?.().Foo.#self?.self.#x).toEqual(undefined); - expect(fn?.().Foo.#self.self?.self.#x).toEqual(undefined); - expect(fn?.().Foo.#self?.self?.self.#x).toEqual(undefined); - - expect(fn?.().Foo.#self.getSelf().#x).toEqual(undefined); - expect(fn?.().Foo.#self.getSelf?.().#x).toEqual(undefined); - expect(fn?.().Foo.#self?.getSelf().#x).toEqual(undefined); - expect(fn?.().Foo.#self?.getSelf?.().#x).toEqual(undefined); - expect(fn?.().Foo.#self.getSelf()?.self.#x).toEqual(undefined); - expect(fn?.().Foo.#self.getSelf?.()?.self.#x).toEqual(undefined); - expect(fn?.().Foo.#self?.getSelf()?.self.#x).toEqual(undefined); - expect(fn?.().Foo.#self?.getSelf?.()?.self.#x).toEqual(undefined); - } - - static testNull() { - const o = null;; - const deep = { very: { o } }; - function fn() { - return o; - } - function fnDeep() { - return deep; - } - expect(o?.Foo.#x).toEqual(1); expect(o?.Foo.#x.toString).toEqual(1..toString); expect(o?.Foo.#x.toString()).toEqual('1'); @@ -116,7 +60,62 @@ class Foo { expect(fn?.().Foo.#self?.getSelf()?.self.#x).toEqual(1); expect(fn?.().Foo.#self?.getSelf?.()?.self.#x).toEqual(1); } + + static testNull() { + const o = null;; + const deep = { very: { o } }; + const fn = null; + function fnDeep() { + return deep; + } + + expect(o?.Foo.#x).toEqual(undefined); + expect(o?.Foo.#x.toString).toEqual(undefined); + expect(o?.Foo.#x.toString()).toEqual(undefined); + + expect(deep?.very.o?.Foo.#x).toEqual(undefined); + expect(deep?.very.o?.Foo.#x.toString).toEqual(undefined); + expect(deep?.very.o?.Foo.#x.toString()).toEqual(undefined); + + expect(o?.Foo.#self.#x).toEqual(undefined); + expect(o?.Foo.#self.self.#x).toEqual(undefined); + expect(o?.Foo.#self?.self.#x).toEqual(undefined); + expect(o?.Foo.#self.self?.self.#x).toEqual(undefined); + expect(o?.Foo.#self?.self?.self.#x).toEqual(undefined); + + expect(o?.Foo.#self.getSelf().#x).toEqual(undefined); + expect(o?.Foo.#self.getSelf?.().#x).toEqual(undefined); + expect(o?.Foo.#self?.getSelf().#x).toEqual(undefined); + expect(o?.Foo.#self?.getSelf?.().#x).toEqual(undefined); + expect(o?.Foo.#self.getSelf()?.self.#x).toEqual(undefined); + expect(o?.Foo.#self.getSelf?.()?.self.#x).toEqual(undefined); + expect(o?.Foo.#self?.getSelf()?.self.#x).toEqual(undefined); + expect(o?.Foo.#self?.getSelf?.()?.self.#x).toEqual(undefined); + + expect(fn?.().Foo.#x).toEqual(undefined); + expect(fn?.().Foo.#x.toString).toEqual(undefined); + expect(fn?.().Foo.#x.toString()).toEqual(undefined); + + expect(fnDeep?.().very.o?.Foo.#x).toEqual(undefined); + expect(fnDeep?.().very.o?.Foo.#x.toString).toEqual(undefined); + expect(fnDeep?.().very.o?.Foo.#x.toString()).toEqual(undefined); + + expect(fn?.().Foo.#self.#x).toEqual(undefined); + expect(fn?.().Foo.#self.self.#x).toEqual(undefined); + expect(fn?.().Foo.#self?.self.#x).toEqual(undefined); + expect(fn?.().Foo.#self.self?.self.#x).toEqual(undefined); + expect(fn?.().Foo.#self?.self?.self.#x).toEqual(undefined); + + expect(fn?.().Foo.#self.getSelf().#x).toEqual(undefined); + expect(fn?.().Foo.#self.getSelf?.().#x).toEqual(undefined); + expect(fn?.().Foo.#self?.getSelf().#x).toEqual(undefined); + expect(fn?.().Foo.#self?.getSelf?.().#x).toEqual(undefined); + expect(fn?.().Foo.#self.getSelf()?.self.#x).toEqual(undefined); + expect(fn?.().Foo.#self.getSelf?.()?.self.#x).toEqual(undefined); + expect(fn?.().Foo.#self?.getSelf()?.self.#x).toEqual(undefined); + expect(fn?.().Foo.#self?.getSelf?.()?.self.#x).toEqual(undefined); + } } -Foo.test(); +// Foo.test(); Foo.testNull(); diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-with-transform/input.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-with-transform/input.js index 30b17a197a2a..fad2504d95e6 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-with-transform/input.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-with-transform/input.js @@ -2,6 +2,7 @@ class Foo { static #x = 1; static #self = Foo; static self = Foo; + static getSelf() { return this } static test() { const o = { Foo: Foo }; diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-with-transform/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-with-transform/output.js index b996ec70f87f..1525a03dc3cd 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-with-transform/output.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-with-transform/output.js @@ -3,8 +3,12 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope function _classStaticPrivateFieldSpecGet(receiver, classConstructor, descriptor) { if (receiver !== classConstructor) { throw new TypeError("Private static access of wrong provenance"); } if (descriptor.get) { return descriptor.get.call(receiver); } return descriptor.value; } class Foo { + static getSelf() { + return this; + } + static test() { - var _o, _ref, _o2, _ref2, _o3, _ref3, _ref4, _ref5, _ref6, _ref7, _ref8, _ref9, _o4, _ref10, _o5, _ref11, _o6, _ref12, _ref13, _ref14, _o7, _ref15, _ref16, _ref17, _o8, _ref18, _ref19, _ref20, _fn, _ref21, _fn2, _ref22, _fn3, _ref23, _ref24, _ref25, _ref26, _ref27, _ref28, _ref29, _fn4, _ref30, _fn5, _ref31, _fn6, _ref32, _ref33, _ref34, _fn7, _ref35, _ref36, _ref37, _fn8, _ref38, _ref39, _ref40, _o9, _o10, _o11, _ref41, _ref42, _ref43, _o12, _o13, _ref44, _o14, _ref45, _o15, _ref46, _ref47, _o16, _fn9, _fn10, _fn11, _ref48, _ref49, _ref50, _fn12, _fn13, _ref51, _fn14, _ref52, _fn15, _ref53, _ref54, _fn16; + var _o, _o2, _o3, _ref, _ref2, _ref3, _o4, _o5, _o6, _ref4, _o7, _ref5, _o8, _ref6, _o9, _o10, _classStaticPrivateFi, _ref7, _o11, _ref8, _o12, _ref9, _ref10, _o13, _ref11, _o14, _classStaticPrivateFi2, _ref12, _o15, _ref13, _o16, _ref14, _fn, _fn2, _fn3, _ref15, _ref16, _ref17, _fn4, _fn5, _fn6, _ref18, _fn7, _ref19, _fn8, _ref20, _fn9, _fn10, _classStaticPrivateFi3, _ref21, _fn11, _ref22, _fn12, _ref23, _ref24, _fn13, _ref25, _fn14, _classStaticPrivateFi4, _ref26, _fn15, _ref27, _fn16, _ref28, _ref29, _ref30, _ref31, _ref32, _ref33, _ref33$getSelf, _ref34, _ref35, _ref36, _ref37, _ref38, _ref38$getSelf; const o = { Foo: Foo @@ -23,28 +27,44 @@ class Foo { return deep; } - (_ref = (_o9 = _o = o) === null || _o9 === void 0 ? void 0 : _o9.Foo, _o === void 0 || _o === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref, Foo, _x); - (_ref2 = (_o10 = _o2 = o) === null || _o10 === void 0 ? void 0 : _o10.Foo, _o2 === void 0 || _o2 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref2, Foo, _x).toString; - (_ref3 = (_o11 = _o3 = o) === null || _o11 === void 0 ? void 0 : _o11.Foo, _o3 === void 0 || _o3 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref3, Foo, _x).toString(); - (_ref5 = (_ref41 = _ref4 = deep === null || deep === void 0 ? void 0 : deep.very.o) === null || _ref41 === void 0 ? void 0 : _ref41.Foo, _ref4 === void 0 || _ref4 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref5, Foo, _x); - (_ref7 = (_ref42 = _ref6 = deep === null || deep === void 0 ? void 0 : deep.very.o) === null || _ref42 === void 0 ? void 0 : _ref42.Foo, _ref6 === void 0 || _ref6 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref7, Foo, _x).toString; - (_ref9 = (_ref43 = _ref8 = deep === null || deep === void 0 ? void 0 : deep.very.o) === null || _ref43 === void 0 ? void 0 : _ref43.Foo, _ref8 === void 0 || _ref8 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref9, Foo, _x).toString(); - (_ref10 = (_o12 = _o4 = o) === null || _o12 === void 0 ? void 0 : _o12.Foo, _o4 === void 0 || _o4 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFieldSpecGet(_ref10, Foo, _self), Foo, _x); - (_ref11 = (_o13 = _o5 = o) === null || _o13 === void 0 ? void 0 : _o13.Foo, _o5 === void 0 || _o5 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFieldSpecGet(_ref11, Foo, _self).self, Foo, _x); - (_ref14 = (_ref44 = _ref13 = (_ref12 = (_o14 = _o6 = o) === null || _o14 === void 0 ? void 0 : _o14.Foo, _o6 === void 0 || _o6 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref12, Foo, _self)) === null || _ref44 === void 0 ? void 0 : _ref44.self, _ref13 === void 0 || _ref13 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref14, Foo, _x); - (_ref17 = (_ref45 = _ref16 = (_ref15 = (_o15 = _o7 = o) === null || _o15 === void 0 ? void 0 : _o15.Foo, _o7 === void 0 || _o7 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref15, Foo, _self).self) === null || _ref45 === void 0 ? void 0 : _ref45.self, _ref16 === void 0 || _ref16 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref17, Foo, _x); - (_ref20 = (_ref46 = _ref19 = (_ref47 = (_ref18 = (_o16 = _o8 = o) === null || _o16 === void 0 ? void 0 : _o16.Foo, _o8 === void 0 || _o8 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref18, Foo, _self)) === null || _ref47 === void 0 ? void 0 : _ref47.self) === null || _ref46 === void 0 ? void 0 : _ref46.self, _ref19 === void 0 || _ref19 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref20, Foo, _x); - (_ref21 = (_fn9 = _fn = fn) === null || _fn9 === void 0 ? void 0 : _fn9().Foo, _fn === void 0 || _fn === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref21, Foo, _x); - (_ref22 = (_fn10 = _fn2 = fn) === null || _fn10 === void 0 ? void 0 : _fn10().Foo, _fn2 === void 0 || _fn2 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref22, Foo, _x).toString; - (_ref23 = (_fn11 = _fn3 = fn) === null || _fn11 === void 0 ? void 0 : _fn11().Foo, _fn3 === void 0 || _fn3 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref23, Foo, _x).toString(); - (_ref25 = (_ref48 = _ref24 = fnDeep === null || fnDeep === void 0 ? void 0 : fnDeep().very.o) === null || _ref48 === void 0 ? void 0 : _ref48.Foo, _ref24 === void 0 || _ref24 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref25, Foo, _x); - (_ref27 = (_ref49 = _ref26 = fnDeep === null || fnDeep === void 0 ? void 0 : fnDeep().very.o) === null || _ref49 === void 0 ? void 0 : _ref49.Foo, _ref26 === void 0 || _ref26 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref27, Foo, _x).toString; - (_ref29 = (_ref50 = _ref28 = fnDeep === null || fnDeep === void 0 ? void 0 : fnDeep().very.o) === null || _ref50 === void 0 ? void 0 : _ref50.Foo, _ref28 === void 0 || _ref28 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref29, Foo, _x).toString(); - (_ref30 = (_fn12 = _fn4 = fn) === null || _fn12 === void 0 ? void 0 : _fn12().Foo, _fn4 === void 0 || _fn4 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFieldSpecGet(_ref30, Foo, _self), Foo, _x); - (_ref31 = (_fn13 = _fn5 = fn) === null || _fn13 === void 0 ? void 0 : _fn13().Foo, _fn5 === void 0 || _fn5 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFieldSpecGet(_ref31, Foo, _self).self, Foo, _x); - (_ref34 = (_ref51 = _ref33 = (_ref32 = (_fn14 = _fn6 = fn) === null || _fn14 === void 0 ? void 0 : _fn14().Foo, _fn6 === void 0 || _fn6 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref32, Foo, _self)) === null || _ref51 === void 0 ? void 0 : _ref51.self, _ref33 === void 0 || _ref33 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref34, Foo, _x); - (_ref37 = (_ref52 = _ref36 = (_ref35 = (_fn15 = _fn7 = fn) === null || _fn15 === void 0 ? void 0 : _fn15().Foo, _fn7 === void 0 || _fn7 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref35, Foo, _self).self) === null || _ref52 === void 0 ? void 0 : _ref52.self, _ref36 === void 0 || _ref36 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref37, Foo, _x); - (_ref40 = (_ref53 = _ref39 = (_ref54 = (_ref38 = (_fn16 = _fn8 = fn) === null || _fn16 === void 0 ? void 0 : _fn16().Foo, _fn8 === void 0 || _fn8 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref38, Foo, _self)) === null || _ref54 === void 0 ? void 0 : _ref54.self) === null || _ref53 === void 0 ? void 0 : _ref53.self, _ref39 === void 0 || _ref39 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref40, Foo, _x); + (_o = o) === null || _o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o.Foo, Foo, _x); + (_o2 = o) === null || _o2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o2.Foo, Foo, _x).toString; + (_o3 = o) === null || _o3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o3.Foo, Foo, _x).toString(); + (_ref = deep === null || deep === void 0 ? void 0 : deep.very.o) === null || _ref === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref.Foo, Foo, _x); + (_ref2 = deep === null || deep === void 0 ? void 0 : deep.very.o) === null || _ref2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref2.Foo, Foo, _x).toString; + (_ref3 = deep === null || deep === void 0 ? void 0 : deep.very.o) === null || _ref3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref3.Foo, Foo, _x).toString(); + (_o4 = o) === null || _o4 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFieldSpecGet(_o4.Foo, Foo, _self), Foo, _x); + (_o5 = o) === null || _o5 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFieldSpecGet(_o5.Foo, Foo, _self).self, Foo, _x); + (_ref4 = (_o6 = o) === null || _o6 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o6.Foo, Foo, _self)) === null || _ref4 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref4.self, Foo, _x); + (_ref5 = (_o7 = o) === null || _o7 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o7.Foo, Foo, _self).self) === null || _ref5 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref5.self, Foo, _x); + (_ref6 = (_ref29 = (_o8 = o) === null || _o8 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o8.Foo, Foo, _self)) === null || _ref29 === void 0 ? void 0 : _ref29.self) === null || _ref6 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref6.self, Foo, _x); + (_o9 = o) === null || _o9 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFieldSpecGet(_o9.Foo, Foo, _self).getSelf(), Foo, _x); + (_ref7 = (_o10 = o) === null || _o10 === void 0 ? void 0 : (_classStaticPrivateFi = _classStaticPrivateFieldSpecGet(_o10.Foo, Foo, _self)).getSelf) === null || _ref7 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref7.call(_classStaticPrivateFi), Foo, _x); + (_ref8 = (_o11 = o) === null || _o11 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o11.Foo, Foo, _self)) === null || _ref8 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref8.getSelf(), Foo, _x); + (_ref9 = (_ref30 = _ref10 = (_o12 = o) === null || _o12 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o12.Foo, Foo, _self)) === null || _ref30 === void 0 ? void 0 : _ref30.getSelf) === null || _ref9 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref9.call(_ref10), Foo, _x); + (_ref11 = (_o13 = o) === null || _o13 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o13.Foo, Foo, _self).getSelf()) === null || _ref11 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref11.self, Foo, _x); + (_ref12 = (_ref31 = (_o14 = o) === null || _o14 === void 0 ? void 0 : (_classStaticPrivateFi2 = _classStaticPrivateFieldSpecGet(_o14.Foo, Foo, _self)).getSelf) === null || _ref31 === void 0 ? void 0 : _ref31.call(_classStaticPrivateFi2)) === null || _ref12 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref12.self, Foo, _x); + (_ref13 = (_ref32 = (_o15 = o) === null || _o15 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o15.Foo, Foo, _self)) === null || _ref32 === void 0 ? void 0 : _ref32.getSelf()) === null || _ref13 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref13.self, Foo, _x); + (_ref14 = (_ref33 = (_o16 = o) === null || _o16 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o16.Foo, Foo, _self)) === null || _ref33 === void 0 ? void 0 : (_ref33$getSelf = _ref33.getSelf) === null || _ref33$getSelf === void 0 ? void 0 : _ref33$getSelf.call(_ref33)) === null || _ref14 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref14.self, Foo, _x); + (_fn = fn) === null || _fn === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn().Foo, Foo, _x); + (_fn2 = fn) === null || _fn2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn2().Foo, Foo, _x).toString; + (_fn3 = fn) === null || _fn3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn3().Foo, Foo, _x).toString(); + (_ref15 = fnDeep === null || fnDeep === void 0 ? void 0 : fnDeep().very.o) === null || _ref15 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref15.Foo, Foo, _x); + (_ref16 = fnDeep === null || fnDeep === void 0 ? void 0 : fnDeep().very.o) === null || _ref16 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref16.Foo, Foo, _x).toString; + (_ref17 = fnDeep === null || fnDeep === void 0 ? void 0 : fnDeep().very.o) === null || _ref17 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref17.Foo, Foo, _x).toString(); + (_fn4 = fn) === null || _fn4 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFieldSpecGet(_fn4().Foo, Foo, _self), Foo, _x); + (_fn5 = fn) === null || _fn5 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFieldSpecGet(_fn5().Foo, Foo, _self).self, Foo, _x); + (_ref18 = (_fn6 = fn) === null || _fn6 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn6().Foo, Foo, _self)) === null || _ref18 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref18.self, Foo, _x); + (_ref19 = (_fn7 = fn) === null || _fn7 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn7().Foo, Foo, _self).self) === null || _ref19 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref19.self, Foo, _x); + (_ref20 = (_ref34 = (_fn8 = fn) === null || _fn8 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn8().Foo, Foo, _self)) === null || _ref34 === void 0 ? void 0 : _ref34.self) === null || _ref20 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref20.self, Foo, _x); + (_fn9 = fn) === null || _fn9 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFieldSpecGet(_fn9().Foo, Foo, _self).getSelf(), Foo, _x); + (_ref21 = (_fn10 = fn) === null || _fn10 === void 0 ? void 0 : (_classStaticPrivateFi3 = _classStaticPrivateFieldSpecGet(_fn10().Foo, Foo, _self)).getSelf) === null || _ref21 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref21.call(_classStaticPrivateFi3), Foo, _x); + (_ref22 = (_fn11 = fn) === null || _fn11 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn11().Foo, Foo, _self)) === null || _ref22 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref22.getSelf(), Foo, _x); + (_ref23 = (_ref35 = _ref24 = (_fn12 = fn) === null || _fn12 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn12().Foo, Foo, _self)) === null || _ref35 === void 0 ? void 0 : _ref35.getSelf) === null || _ref23 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref23.call(_ref24), Foo, _x); + (_ref25 = (_fn13 = fn) === null || _fn13 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn13().Foo, Foo, _self).getSelf()) === null || _ref25 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref25.self, Foo, _x); + (_ref26 = (_ref36 = (_fn14 = fn) === null || _fn14 === void 0 ? void 0 : (_classStaticPrivateFi4 = _classStaticPrivateFieldSpecGet(_fn14().Foo, Foo, _self)).getSelf) === null || _ref36 === void 0 ? void 0 : _ref36.call(_classStaticPrivateFi4)) === null || _ref26 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref26.self, Foo, _x); + (_ref27 = (_ref37 = (_fn15 = fn) === null || _fn15 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn15().Foo, Foo, _self)) === null || _ref37 === void 0 ? void 0 : _ref37.getSelf()) === null || _ref27 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref27.self, Foo, _x); + (_ref28 = (_ref38 = (_fn16 = fn) === null || _fn16 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn16().Foo, Foo, _self)) === null || _ref38 === void 0 ? void 0 : (_ref38$getSelf = _ref38.getSelf) === null || _ref38$getSelf === void 0 ? void 0 : _ref38$getSelf.call(_ref38)) === null || _ref28 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref28.self, Foo, _x); } } diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain/output.js index 2ab2242bfa56..a60704cbf1e3 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain/output.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain/output.js @@ -8,7 +8,7 @@ class Foo { } static test() { - var _o, _ref, _o2, _ref2, _o3, _ref3, _ref4, _ref5, _ref6, _ref7, _ref8, _ref9, _o4, _ref10, _o5, _ref11, _o6, _ref12, _ref13, _ref14, _o7, _ref15, _ref16, _ref17, _o8, _ref18, _ref19, _ref20, _o9, _ref21, _o10, _ref22, _ref23, _ref24, _o11, _ref25, _ref26, _ref27, _o12, _ref28, _ref29, _ref30, _o13, _ref31, _ref32, _ref33, _o14, _ref34, _ref35, _ref36, _o15, _ref37, _ref38, _ref39, _o16, _ref40, _ref41, _ref42, _fn, _ref43, _fn2, _ref44, _fn3, _ref45, _ref46, _ref47, _ref48, _ref49, _ref50, _ref51, _fn4, _ref52, _fn5, _ref53, _fn6, _ref54, _ref55, _ref56, _fn7, _ref57, _ref58, _ref59, _fn8, _ref60, _ref61, _ref62, _fn9, _ref63, _fn10, _ref64, _ref65, _ref66, _fn11, _ref67, _ref68, _ref69, _fn12, _ref70, _ref71, _ref72, _fn13, _ref73, _ref74, _ref75, _fn14, _ref76, _ref77, _ref78, _fn15, _ref79, _ref80, _ref81, _fn16, _ref82, _ref83, _ref84; + var _o, _o2, _o3, _ref, _ref2, _ref3, _o4, _o5, _o6, _ref4, _o7, _ref5, _o8, _ref6, _o9, _o10, _classStaticPrivateFi, _ref7, _o11, _ref8, _o12, _ref9, _ref10, _o13, _ref11, _o14, _classStaticPrivateFi2, _ref12, _o15, _ref13, _o16, _ref14, _fn, _fn2, _fn3, _ref15, _ref16, _ref17, _fn4, _fn5, _fn6, _ref18, _fn7, _ref19, _fn8, _ref20, _fn9, _fn10, _classStaticPrivateFi3, _ref21, _fn11, _ref22, _fn12, _ref23, _ref24, _fn13, _ref25, _fn14, _classStaticPrivateFi4, _ref26, _fn15, _ref27, _fn16, _ref28; const o = { Foo: Foo @@ -27,44 +27,44 @@ class Foo { return deep; } - (_ref = (_o = o)?.Foo, _o === void 0 || _o === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref, Foo, _x); - (_ref2 = (_o2 = o)?.Foo, _o2 === void 0 || _o2 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref2, Foo, _x).toString; - (_ref3 = (_o3 = o)?.Foo, _o3 === void 0 || _o3 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref3, Foo, _x).toString(); - (_ref5 = (_ref4 = deep?.very.o)?.Foo, _ref4 === void 0 || _ref4 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref5, Foo, _x); - (_ref7 = (_ref6 = deep?.very.o)?.Foo, _ref6 === void 0 || _ref6 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref7, Foo, _x).toString; - (_ref9 = (_ref8 = deep?.very.o)?.Foo, _ref8 === void 0 || _ref8 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref9, Foo, _x).toString(); - (_ref10 = (_o4 = o)?.Foo, _o4 === void 0 || _o4 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFieldSpecGet(_ref10, Foo, _self), Foo, _x); - (_ref11 = (_o5 = o)?.Foo, _o5 === void 0 || _o5 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFieldSpecGet(_ref11, Foo, _self).self, Foo, _x); - (_ref14 = (_ref13 = (_ref12 = (_o6 = o)?.Foo, _o6 === void 0 || _o6 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref12, Foo, _self))?.self, _ref13 === void 0 || _ref13 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref14, Foo, _x); - (_ref17 = (_ref16 = (_ref15 = (_o7 = o)?.Foo, _o7 === void 0 || _o7 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref15, Foo, _self).self)?.self, _ref16 === void 0 || _ref16 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref17, Foo, _x); - (_ref20 = (_ref19 = ((_ref18 = (_o8 = o)?.Foo, _o8 === void 0 || _o8 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref18, Foo, _self))?.self)?.self, _ref19 === void 0 || _ref19 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref20, Foo, _x); - (_ref21 = (_o9 = o)?.Foo, _o9 === void 0 || _o9 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFieldSpecGet(_ref21, Foo, _self).getSelf(), Foo, _x); - (_ref24 = _ref23 = (_ref22 = (_o10 = o)?.Foo, _o10 === void 0 || _o10 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref22, Foo, _self).getSelf?.(), _ref23 === void 0 || _ref23 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref24, Foo, _x); - (_ref27 = (_ref26 = (_ref25 = (_o11 = o)?.Foo, _o11 === void 0 || _o11 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref25, Foo, _self))?.getSelf(), _ref26 === void 0 || _ref26 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref27, Foo, _x); - (_ref30 = _ref29 = ((_ref28 = (_o12 = o)?.Foo, _o12 === void 0 || _o12 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref28, Foo, _self))?.getSelf?.(), _ref29 === void 0 || _ref29 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref30, Foo, _x); - (_ref33 = (_ref32 = (_ref31 = (_o13 = o)?.Foo, _o13 === void 0 || _o13 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref31, Foo, _self).getSelf())?.self, _ref32 === void 0 || _ref32 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref33, Foo, _x); - (_ref36 = (_ref35 = (_ref34 = (_o14 = o)?.Foo, _o14 === void 0 || _o14 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref34, Foo, _self).getSelf?.())?.self, _ref35 === void 0 || _ref35 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref36, Foo, _x); - (_ref39 = (_ref38 = ((_ref37 = (_o15 = o)?.Foo, _o15 === void 0 || _o15 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref37, Foo, _self))?.getSelf())?.self, _ref38 === void 0 || _ref38 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref39, Foo, _x); - (_ref42 = (_ref41 = ((_ref40 = (_o16 = o)?.Foo, _o16 === void 0 || _o16 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref40, Foo, _self))?.getSelf?.())?.self, _ref41 === void 0 || _ref41 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref42, Foo, _x); - (_ref43 = _fn = fn?.().Foo, _fn === void 0 || _fn === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref43, Foo, _x); - (_ref44 = _fn2 = fn?.().Foo, _fn2 === void 0 || _fn2 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref44, Foo, _x).toString; - (_ref45 = _fn3 = fn?.().Foo, _fn3 === void 0 || _fn3 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref45, Foo, _x).toString(); - (_ref47 = (_ref46 = fnDeep?.().very.o)?.Foo, _ref46 === void 0 || _ref46 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref47, Foo, _x); - (_ref49 = (_ref48 = fnDeep?.().very.o)?.Foo, _ref48 === void 0 || _ref48 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref49, Foo, _x).toString; - (_ref51 = (_ref50 = fnDeep?.().very.o)?.Foo, _ref50 === void 0 || _ref50 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref51, Foo, _x).toString(); - (_ref52 = _fn4 = fn?.().Foo, _fn4 === void 0 || _fn4 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFieldSpecGet(_ref52, Foo, _self), Foo, _x); - (_ref53 = _fn5 = fn?.().Foo, _fn5 === void 0 || _fn5 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFieldSpecGet(_ref53, Foo, _self).self, Foo, _x); - (_ref56 = (_ref55 = (_ref54 = _fn6 = fn?.().Foo, _fn6 === void 0 || _fn6 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref54, Foo, _self))?.self, _ref55 === void 0 || _ref55 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref56, Foo, _x); - (_ref59 = (_ref58 = (_ref57 = _fn7 = fn?.().Foo, _fn7 === void 0 || _fn7 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref57, Foo, _self).self)?.self, _ref58 === void 0 || _ref58 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref59, Foo, _x); - (_ref62 = (_ref61 = ((_ref60 = _fn8 = fn?.().Foo, _fn8 === void 0 || _fn8 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref60, Foo, _self))?.self)?.self, _ref61 === void 0 || _ref61 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref62, Foo, _x); - (_ref63 = _fn9 = fn?.().Foo, _fn9 === void 0 || _fn9 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFieldSpecGet(_ref63, Foo, _self).getSelf(), Foo, _x); - (_ref66 = _ref65 = (_ref64 = _fn10 = fn?.().Foo, _fn10 === void 0 || _fn10 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref64, Foo, _self).getSelf?.(), _ref65 === void 0 || _ref65 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref66, Foo, _x); - (_ref69 = (_ref68 = (_ref67 = _fn11 = fn?.().Foo, _fn11 === void 0 || _fn11 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref67, Foo, _self))?.getSelf(), _ref68 === void 0 || _ref68 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref69, Foo, _x); - (_ref72 = _ref71 = ((_ref70 = _fn12 = fn?.().Foo, _fn12 === void 0 || _fn12 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref70, Foo, _self))?.getSelf?.(), _ref71 === void 0 || _ref71 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref72, Foo, _x); - (_ref75 = (_ref74 = (_ref73 = _fn13 = fn?.().Foo, _fn13 === void 0 || _fn13 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref73, Foo, _self).getSelf())?.self, _ref74 === void 0 || _ref74 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref75, Foo, _x); - (_ref78 = (_ref77 = (_ref76 = _fn14 = fn?.().Foo, _fn14 === void 0 || _fn14 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref76, Foo, _self).getSelf?.())?.self, _ref77 === void 0 || _ref77 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref78, Foo, _x); - (_ref81 = (_ref80 = ((_ref79 = _fn15 = fn?.().Foo, _fn15 === void 0 || _fn15 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref79, Foo, _self))?.getSelf())?.self, _ref80 === void 0 || _ref80 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref81, Foo, _x); - (_ref84 = (_ref83 = ((_ref82 = _fn16 = fn?.().Foo, _fn16 === void 0 || _fn16 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref82, Foo, _self))?.getSelf?.())?.self, _ref83 === void 0 || _ref83 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref84, Foo, _x); + (_o = o) === null || _o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o.Foo, Foo, _x); + (_o2 = o) === null || _o2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o2.Foo, Foo, _x).toString; + (_o3 = o) === null || _o3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o3.Foo, Foo, _x).toString(); + (_ref = deep?.very.o) === null || _ref === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref.Foo, Foo, _x); + (_ref2 = deep?.very.o) === null || _ref2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref2.Foo, Foo, _x).toString; + (_ref3 = deep?.very.o) === null || _ref3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref3.Foo, Foo, _x).toString(); + (_o4 = o) === null || _o4 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFieldSpecGet(_o4.Foo, Foo, _self), Foo, _x); + (_o5 = o) === null || _o5 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFieldSpecGet(_o5.Foo, Foo, _self).self, Foo, _x); + (_ref4 = (_o6 = o) === null || _o6 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o6.Foo, Foo, _self)) === null || _ref4 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref4.self, Foo, _x); + (_ref5 = (_o7 = o) === null || _o7 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o7.Foo, Foo, _self).self) === null || _ref5 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref5.self, Foo, _x); + (_ref6 = ((_o8 = o) === null || _o8 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o8.Foo, Foo, _self))?.self) === null || _ref6 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref6.self, Foo, _x); + (_o9 = o) === null || _o9 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFieldSpecGet(_o9.Foo, Foo, _self).getSelf(), Foo, _x); + (_ref7 = (_o10 = o) === null || _o10 === void 0 ? void 0 : (_classStaticPrivateFi = _classStaticPrivateFieldSpecGet(_o10.Foo, Foo, _self)).getSelf) === null || _ref7 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref7.call(_classStaticPrivateFi), Foo, _x); + (_ref8 = (_o11 = o) === null || _o11 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o11.Foo, Foo, _self)) === null || _ref8 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref8.getSelf(), Foo, _x); + (_ref9 = (_ref10 = (_o12 = o) === null || _o12 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o12.Foo, Foo, _self))?.getSelf) === null || _ref9 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref9.call(_ref10), Foo, _x); + (_ref11 = (_o13 = o) === null || _o13 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o13.Foo, Foo, _self).getSelf()) === null || _ref11 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref11.self, Foo, _x); + (_ref12 = ((_o14 = o) === null || _o14 === void 0 ? void 0 : (_classStaticPrivateFi2 = _classStaticPrivateFieldSpecGet(_o14.Foo, Foo, _self)).getSelf)?.call(_classStaticPrivateFi2)) === null || _ref12 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref12.self, Foo, _x); + (_ref13 = ((_o15 = o) === null || _o15 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o15.Foo, Foo, _self))?.getSelf()) === null || _ref13 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref13.self, Foo, _x); + (_ref14 = ((_o16 = o) === null || _o16 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o16.Foo, Foo, _self))?.getSelf?.()) === null || _ref14 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref14.self, Foo, _x); + (_fn = fn) === null || _fn === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn().Foo, Foo, _x); + (_fn2 = fn) === null || _fn2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn2().Foo, Foo, _x).toString; + (_fn3 = fn) === null || _fn3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn3().Foo, Foo, _x).toString(); + (_ref15 = fnDeep?.().very.o) === null || _ref15 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref15.Foo, Foo, _x); + (_ref16 = fnDeep?.().very.o) === null || _ref16 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref16.Foo, Foo, _x).toString; + (_ref17 = fnDeep?.().very.o) === null || _ref17 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref17.Foo, Foo, _x).toString(); + (_fn4 = fn) === null || _fn4 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFieldSpecGet(_fn4().Foo, Foo, _self), Foo, _x); + (_fn5 = fn) === null || _fn5 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFieldSpecGet(_fn5().Foo, Foo, _self).self, Foo, _x); + (_ref18 = (_fn6 = fn) === null || _fn6 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn6().Foo, Foo, _self)) === null || _ref18 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref18.self, Foo, _x); + (_ref19 = (_fn7 = fn) === null || _fn7 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn7().Foo, Foo, _self).self) === null || _ref19 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref19.self, Foo, _x); + (_ref20 = ((_fn8 = fn) === null || _fn8 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn8().Foo, Foo, _self))?.self) === null || _ref20 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref20.self, Foo, _x); + (_fn9 = fn) === null || _fn9 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFieldSpecGet(_fn9().Foo, Foo, _self).getSelf(), Foo, _x); + (_ref21 = (_fn10 = fn) === null || _fn10 === void 0 ? void 0 : (_classStaticPrivateFi3 = _classStaticPrivateFieldSpecGet(_fn10().Foo, Foo, _self)).getSelf) === null || _ref21 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref21.call(_classStaticPrivateFi3), Foo, _x); + (_ref22 = (_fn11 = fn) === null || _fn11 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn11().Foo, Foo, _self)) === null || _ref22 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref22.getSelf(), Foo, _x); + (_ref23 = (_ref24 = (_fn12 = fn) === null || _fn12 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn12().Foo, Foo, _self))?.getSelf) === null || _ref23 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref23.call(_ref24), Foo, _x); + (_ref25 = (_fn13 = fn) === null || _fn13 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn13().Foo, Foo, _self).getSelf()) === null || _ref25 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref25.self, Foo, _x); + (_ref26 = ((_fn14 = fn) === null || _fn14 === void 0 ? void 0 : (_classStaticPrivateFi4 = _classStaticPrivateFieldSpecGet(_fn14().Foo, Foo, _self)).getSelf)?.call(_classStaticPrivateFi4)) === null || _ref26 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref26.self, Foo, _x); + (_ref27 = ((_fn15 = fn) === null || _fn15 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn15().Foo, Foo, _self))?.getSelf()) === null || _ref27 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref27.self, Foo, _x); + (_ref28 = ((_fn16 = fn) === null || _fn16 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn16().Foo, Foo, _self))?.getSelf?.()) === null || _ref28 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref28.self, Foo, _x); } } From 5ec367fd89756dad95d1d861a18643e7ddf49469 Mon Sep 17 00:00:00 2001 From: Justin Ridgewell Date: Sat, 14 Mar 2020 05:50:22 -0400 Subject: [PATCH 05/20] Add private method tests --- .../src/index.js | 3 +- .../exec.js | 122 ++++++++++++++++++ .../input.js | 66 ++++++++++ .../options.json | 6 + .../output.js | 95 ++++++++++++++ .../optional-chain-private-call/input.js | 66 ++++++++++ .../optional-chain-private-call/options.json | 5 + .../optional-chain-private-call/output.js | 95 ++++++++++++++ .../optional-chain-with-transform/exec.js | 75 +++++++++++ .../optional-chain-with-transform/input.js | 19 +++ .../optional-chain-with-transform/exec.js | 121 ----------------- .../optional-chain-with-transform/input.js | 65 ---------- .../optional-chain-with-transform/output.js | 83 ------------ .../optional-chain-with-transform/output.js | 36 ++++-- .../private-loose/optional-chain/input.js | 20 +++ .../optional-chain/optional-chain/input.js | 66 ---------- .../optional-chain/options.json | 3 - .../optional-chain/optional-chain/output.js | 83 ------------ .../private-loose/optional-chain/options.json | 4 +- .../private-loose/optional-chain/output.js | 34 ++++- .../exec.js | 122 ++++++++++++++++++ .../input.js | 66 ++++++++++ .../options.json | 0 .../output.js | 89 +++++++++++++ .../optional-chain-private-call/input.js | 74 +++++------ .../optional-chain-private-call/output.js | 72 +++++++---- .../optional-chain-with-transform/exec.js | 2 +- 27 files changed, 993 insertions(+), 499 deletions(-) create mode 100644 packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-private-call-with-transform/exec.js create mode 100644 packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-private-call-with-transform/input.js create mode 100644 packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-private-call-with-transform/options.json create mode 100644 packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-private-call-with-transform/output.js create mode 100644 packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-private-call/input.js create mode 100644 packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-private-call/options.json create mode 100644 packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-private-call/output.js delete mode 100644 packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-with-transform/optional-chain-with-transform/exec.js delete mode 100644 packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-with-transform/optional-chain-with-transform/input.js delete mode 100644 packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-with-transform/optional-chain-with-transform/output.js delete mode 100644 packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain/optional-chain/input.js delete mode 100644 packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain/optional-chain/options.json delete mode 100644 packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain/optional-chain/output.js create mode 100644 packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-private-call-with-transform/exec.js create mode 100644 packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-private-call-with-transform/input.js rename packages/babel-plugin-proposal-class-properties/test/fixtures/{private-loose/optional-chain-with-transform/optional-chain-with-transform => private/optional-chain-private-call-with-transform}/options.json (100%) create mode 100644 packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-private-call-with-transform/output.js 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 fbb3f1d57fb9..258dc53d2554 100644 --- a/packages/babel-helper-member-expression-to-functions/src/index.js +++ b/packages/babel-helper-member-expression-to-functions/src/index.js @@ -52,7 +52,8 @@ function toNonOptional(path, base) { return t.callExpression(base, node.arguments); } - throw path.buildCodeFrameError(`Cannot make ${path.type} non-optional`); + + return path.node; } const handle = { diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-private-call-with-transform/exec.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-private-call-with-transform/exec.js new file mode 100644 index 000000000000..13cc95662d95 --- /dev/null +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-private-call-with-transform/exec.js @@ -0,0 +1,122 @@ +class Foo { + static #x = 1; + static #m = function() { return this.#x; }; + static #self = Foo; + static self = Foo; + static getSelf() { return this } + + static test() { + const o = { Foo: Foo }; + const deep = { very: { o } }; + function fn() { + return o; + } + function fnDeep() { + return deep; + } + + expect(o?.Foo.#m()).toEqual(1); + expect(o?.Foo.#m().toString).toEqual(1..toString); + expect(o?.Foo.#m().toString()).toEqual('1'); + + expect(deep?.very.o?.Foo.#m()).toEqual(1); + expect(deep?.very.o?.Foo.#m().toString).toEqual(1..toString); + expect(deep?.very.o?.Foo.#m().toString()).toEqual('1'); + + expect(o?.Foo.#self.#m()).toEqual(1); + expect(o?.Foo.#self.self.#m()).toEqual(1); + expect(o?.Foo.#self?.self.#m()).toEqual(1); + expect(o?.Foo.#self.self?.self.#m()).toEqual(1); + expect(o?.Foo.#self?.self?.self.#m()).toEqual(1); + + expect(o?.Foo.#self.getSelf().#m()).toEqual(1); + expect(o?.Foo.#self.getSelf?.().#m()).toEqual(1); + expect(o?.Foo.#self?.getSelf().#m()).toEqual(1); + expect(o?.Foo.#self?.getSelf?.().#m()).toEqual(1); + expect(o?.Foo.#self.getSelf()?.self.#m()).toEqual(1); + expect(o?.Foo.#self.getSelf?.()?.self.#m()).toEqual(1); + expect(o?.Foo.#self?.getSelf()?.self.#m()).toEqual(1); + expect(o?.Foo.#self?.getSelf?.()?.self.#m()).toEqual(1); + + expect(fn?.().Foo.#m()).toEqual(1); + expect(fn?.().Foo.#m().toString).toEqual(1..toString); + expect(fn?.().Foo.#m().toString()).toEqual('1'); + + expect(fnDeep?.().very.o?.Foo.#m()).toEqual(1); + expect(fnDeep?.().very.o?.Foo.#m().toString).toEqual(1..toString); + expect(fnDeep?.().very.o?.Foo.#m().toString()).toEqual('1'); + + expect(fn?.().Foo.#self.#m()).toEqual(1); + expect(fn?.().Foo.#self.self.#m()).toEqual(1); + expect(fn?.().Foo.#self?.self.#m()).toEqual(1); + expect(fn?.().Foo.#self.self?.self.#m()).toEqual(1); + expect(fn?.().Foo.#self?.self?.self.#m()).toEqual(1); + + expect(fn?.().Foo.#self.getSelf().#m()).toEqual(1); + expect(fn?.().Foo.#self.getSelf?.().#m()).toEqual(1); + expect(fn?.().Foo.#self?.getSelf().#m()).toEqual(1); + expect(fn?.().Foo.#self?.getSelf?.().#m()).toEqual(1); + expect(fn?.().Foo.#self.getSelf()?.self.#m()).toEqual(1); + expect(fn?.().Foo.#self.getSelf?.()?.self.#m()).toEqual(1); + expect(fn?.().Foo.#self?.getSelf()?.self.#m()).toEqual(1); + expect(fn?.().Foo.#self?.getSelf?.()?.self.#m()).toEqual(1); + } + + static testNull() { + const o = null;; + const deep = { very: { o } }; + const fn = null; + function fnDeep() { + return deep; + } + + expect(o?.Foo.#m()).toEqual(undefined); + expect(o?.Foo.#m().toString).toEqual(undefined); + expect(o?.Foo.#m().toString()).toEqual(undefined); + + expect(deep?.very.o?.Foo.#m()).toEqual(undefined); + expect(deep?.very.o?.Foo.#m().toString).toEqual(undefined); + expect(deep?.very.o?.Foo.#m().toString()).toEqual(undefined); + + expect(o?.Foo.#self.#m()).toEqual(undefined); + expect(o?.Foo.#self.self.#m()).toEqual(undefined); + expect(o?.Foo.#self?.self.#m()).toEqual(undefined); + expect(o?.Foo.#self.self?.self.#m()).toEqual(undefined); + expect(o?.Foo.#self?.self?.self.#m()).toEqual(undefined); + + expect(o?.Foo.#self.getSelf().#m()).toEqual(undefined); + expect(o?.Foo.#self.getSelf?.().#m()).toEqual(undefined); + expect(o?.Foo.#self?.getSelf().#m()).toEqual(undefined); + expect(o?.Foo.#self?.getSelf?.().#m()).toEqual(undefined); + expect(o?.Foo.#self.getSelf()?.self.#m()).toEqual(undefined); + expect(o?.Foo.#self.getSelf?.()?.self.#m()).toEqual(undefined); + expect(o?.Foo.#self?.getSelf()?.self.#m()).toEqual(undefined); + expect(o?.Foo.#self?.getSelf?.()?.self.#m()).toEqual(undefined); + + expect(fn?.().Foo.#m()).toEqual(undefined); + expect(fn?.().Foo.#m().toString).toEqual(undefined); + expect(fn?.().Foo.#m().toString()).toEqual(undefined); + + expect(fnDeep?.().very.o?.Foo.#m()).toEqual(undefined); + expect(fnDeep?.().very.o?.Foo.#m().toString).toEqual(undefined); + expect(fnDeep?.().very.o?.Foo.#m().toString()).toEqual(undefined); + + expect(fn?.().Foo.#self.#m()).toEqual(undefined); + expect(fn?.().Foo.#self.self.#m()).toEqual(undefined); + expect(fn?.().Foo.#self?.self.#m()).toEqual(undefined); + expect(fn?.().Foo.#self.self?.self.#m()).toEqual(undefined); + expect(fn?.().Foo.#self?.self?.self.#m()).toEqual(undefined); + + expect(fn?.().Foo.#self.getSelf().#m()).toEqual(undefined); + expect(fn?.().Foo.#self.getSelf?.().#m()).toEqual(undefined); + expect(fn?.().Foo.#self?.getSelf().#m()).toEqual(undefined); + expect(fn?.().Foo.#self?.getSelf?.().#m()).toEqual(undefined); + expect(fn?.().Foo.#self.getSelf()?.self.#m()).toEqual(undefined); + expect(fn?.().Foo.#self.getSelf?.()?.self.#m()).toEqual(undefined); + expect(fn?.().Foo.#self?.getSelf()?.self.#m()).toEqual(undefined); + expect(fn?.().Foo.#self?.getSelf?.()?.self.#m()).toEqual(undefined); + } +} + +Foo.test(); +Foo.testNull(); diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-private-call-with-transform/input.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-private-call-with-transform/input.js new file mode 100644 index 000000000000..d29585b51d60 --- /dev/null +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-private-call-with-transform/input.js @@ -0,0 +1,66 @@ +class Foo { + static #x = 1; + static #m = function() { return this.#x; }; + static #self = Foo; + static self = Foo; + static getSelf() { return this } + + static test() { + const o = { Foo: Foo }; + const deep = { very: { o } }; + function fn() { + return o; + } + function fnDeep() { + return deep; + } + + o?.Foo.#m(); + o?.Foo.#m().toString; + o?.Foo.#m().toString(); + + deep?.very.o?.Foo.#m(); + deep?.very.o?.Foo.#m().toString; + deep?.very.o?.Foo.#m().toString(); + + o?.Foo.#self.#m(); + o?.Foo.#self.self.#m(); + o?.Foo.#self?.self.#m(); + o?.Foo.#self.self?.self.#m(); + o?.Foo.#self?.self?.self.#m(); + + o?.Foo.#self.getSelf().#m(); + o?.Foo.#self.getSelf?.().#m(); + o?.Foo.#self?.getSelf().#m(); + o?.Foo.#self?.getSelf?.().#m(); + o?.Foo.#self.getSelf()?.self.#m(); + o?.Foo.#self.getSelf?.()?.self.#m(); + o?.Foo.#self?.getSelf()?.self.#m(); + o?.Foo.#self?.getSelf?.()?.self.#m(); + + fn?.().Foo.#m(); + fn?.().Foo.#m().toString; + fn?.().Foo.#m().toString(); + + fnDeep?.().very.o?.Foo.#m(); + fnDeep?.().very.o?.Foo.#m().toString; + fnDeep?.().very.o?.Foo.#m().toString(); + + fn?.().Foo.#self.#m(); + fn?.().Foo.#self.self.#m(); + fn?.().Foo.#self?.self.#m(); + fn?.().Foo.#self.self?.self.#m(); + fn?.().Foo.#self?.self?.self.#m(); + + fn?.().Foo.#self.getSelf().#m(); + fn?.().Foo.#self.getSelf?.().#m(); + fn?.().Foo.#self?.getSelf().#m(); + fn?.().Foo.#self?.getSelf?.().#m(); + fn?.().Foo.#self.getSelf()?.self.#m(); + fn?.().Foo.#self.getSelf?.()?.self.#m(); + fn?.().Foo.#self?.getSelf()?.self.#m(); + fn?.().Foo.#self?.getSelf?.()?.self.#m(); + } +} + +Foo.test(); diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-private-call-with-transform/options.json b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-private-call-with-transform/options.json new file mode 100644 index 000000000000..9a7eaaa890b3 --- /dev/null +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-private-call-with-transform/options.json @@ -0,0 +1,6 @@ +{ + "plugins": [ + "proposal-optional-chaining", + ["proposal-class-properties", { "loose": true }] + ] +} diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-private-call-with-transform/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-private-call-with-transform/output.js new file mode 100644 index 000000000000..9c70b9bc4b88 --- /dev/null +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-private-call-with-transform/output.js @@ -0,0 +1,95 @@ +function _classPrivateFieldLooseBase(receiver, privateKey) { if (!Object.prototype.hasOwnProperty.call(receiver, privateKey)) { throw new TypeError("attempted to use private field on non-instance"); } return receiver; } + +var id = 0; + +function _classPrivateFieldLooseKey(name) { return "__private_" + id++ + "_" + name; } + +class Foo { + static getSelf() { + return this; + } + + static test() { + var _o, _o2, _o3, _ref, _ref2, _ref3, _o4, _o5, _o6, _ref4, _o7, _ref5, _o8, _ref6, _o9, _o10, _classPrivateFieldLoo, _ref7, _o11, _ref8, _o12, _ref9, _ref10, _o13, _ref11, _o14, _classPrivateFieldLoo2, _ref12, _o15, _ref13, _o16, _ref14, _fn, _fn2, _fn3, _ref15, _ref16, _ref17, _fn4, _fn5, _fn6, _ref18, _fn7, _ref19, _fn8, _ref20, _fn9, _fn10, _classPrivateFieldLoo3, _ref21, _fn11, _ref22, _fn12, _ref23, _ref24, _fn13, _ref25, _fn14, _classPrivateFieldLoo4, _ref26, _fn15, _ref27, _fn16, _ref28, _ref29, _ref30, _ref31, _ref32, _ref33, _ref33$getSelf, _ref34, _ref35, _ref36, _ref37, _ref38, _ref38$getSelf; + + const o = { + Foo: Foo + }; + const deep = { + very: { + o + } + }; + + function fn() { + return o; + } + + function fnDeep() { + return deep; + } + + (_o = o) === null || _o === void 0 ? void 0 : _classPrivateFieldLooseBase(_o.Foo, _m)[_m](); + (_o2 = o) === null || _o2 === void 0 ? void 0 : _classPrivateFieldLooseBase(_o2.Foo, _m)[_m]().toString; + (_o3 = o) === null || _o3 === void 0 ? void 0 : _classPrivateFieldLooseBase(_o3.Foo, _m)[_m]().toString(); + (_ref = deep === null || deep === void 0 ? void 0 : deep.very.o) === null || _ref === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref.Foo, _m)[_m](); + (_ref2 = deep === null || deep === void 0 ? void 0 : deep.very.o) === null || _ref2 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref2.Foo, _m)[_m]().toString; + (_ref3 = deep === null || deep === void 0 ? void 0 : deep.very.o) === null || _ref3 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref3.Foo, _m)[_m]().toString(); + (_o4 = o) === null || _o4 === void 0 ? void 0 : _classPrivateFieldLooseBase(_classPrivateFieldLooseBase(_o4.Foo, _self)[_self], _m)[_m](); + (_o5 = o) === null || _o5 === void 0 ? void 0 : _classPrivateFieldLooseBase(_classPrivateFieldLooseBase(_o5.Foo, _self)[_self].self, _m)[_m](); + (_ref4 = (_o6 = o) === null || _o6 === void 0 ? void 0 : _classPrivateFieldLooseBase(_o6.Foo, _self)[_self]) === null || _ref4 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref4.self, _m)[_m](); + (_ref5 = (_o7 = o) === null || _o7 === void 0 ? void 0 : _classPrivateFieldLooseBase(_o7.Foo, _self)[_self].self) === null || _ref5 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref5.self, _m)[_m](); + (_ref6 = (_ref29 = (_o8 = o) === null || _o8 === void 0 ? void 0 : _classPrivateFieldLooseBase(_o8.Foo, _self)[_self]) === null || _ref29 === void 0 ? void 0 : _ref29.self) === null || _ref6 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref6.self, _m)[_m](); + (_o9 = o) === null || _o9 === void 0 ? void 0 : _classPrivateFieldLooseBase(_classPrivateFieldLooseBase(_o9.Foo, _self)[_self].getSelf(), _m)[_m](); + (_ref7 = (_o10 = o) === null || _o10 === void 0 ? void 0 : (_classPrivateFieldLoo = _classPrivateFieldLooseBase(_o10.Foo, _self)[_self]).getSelf) === null || _ref7 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref7.call(_classPrivateFieldLoo), _m)[_m](); + (_ref8 = (_o11 = o) === null || _o11 === void 0 ? void 0 : _classPrivateFieldLooseBase(_o11.Foo, _self)[_self]) === null || _ref8 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref8.getSelf(), _m)[_m](); + (_ref9 = (_ref30 = _ref10 = (_o12 = o) === null || _o12 === void 0 ? void 0 : _classPrivateFieldLooseBase(_o12.Foo, _self)[_self]) === null || _ref30 === void 0 ? void 0 : _ref30.getSelf) === null || _ref9 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref9.call(_ref10), _m)[_m](); + (_ref11 = (_o13 = o) === null || _o13 === void 0 ? void 0 : _classPrivateFieldLooseBase(_o13.Foo, _self)[_self].getSelf()) === null || _ref11 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref11.self, _m)[_m](); + (_ref12 = (_ref31 = (_o14 = o) === null || _o14 === void 0 ? void 0 : (_classPrivateFieldLoo2 = _classPrivateFieldLooseBase(_o14.Foo, _self)[_self]).getSelf) === null || _ref31 === void 0 ? void 0 : _ref31.call(_classPrivateFieldLoo2)) === null || _ref12 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref12.self, _m)[_m](); + (_ref13 = (_ref32 = (_o15 = o) === null || _o15 === void 0 ? void 0 : _classPrivateFieldLooseBase(_o15.Foo, _self)[_self]) === null || _ref32 === void 0 ? void 0 : _ref32.getSelf()) === null || _ref13 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref13.self, _m)[_m](); + (_ref14 = (_ref33 = (_o16 = o) === null || _o16 === void 0 ? void 0 : _classPrivateFieldLooseBase(_o16.Foo, _self)[_self]) === null || _ref33 === void 0 ? void 0 : (_ref33$getSelf = _ref33.getSelf) === null || _ref33$getSelf === void 0 ? void 0 : _ref33$getSelf.call(_ref33)) === null || _ref14 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref14.self, _m)[_m](); + (_fn = fn) === null || _fn === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn().Foo, _m)[_m](); + (_fn2 = fn) === null || _fn2 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn2().Foo, _m)[_m]().toString; + (_fn3 = fn) === null || _fn3 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn3().Foo, _m)[_m]().toString(); + (_ref15 = fnDeep === null || fnDeep === void 0 ? void 0 : fnDeep().very.o) === null || _ref15 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref15.Foo, _m)[_m](); + (_ref16 = fnDeep === null || fnDeep === void 0 ? void 0 : fnDeep().very.o) === null || _ref16 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref16.Foo, _m)[_m]().toString; + (_ref17 = fnDeep === null || fnDeep === void 0 ? void 0 : fnDeep().very.o) === null || _ref17 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref17.Foo, _m)[_m]().toString(); + (_fn4 = fn) === null || _fn4 === void 0 ? void 0 : _classPrivateFieldLooseBase(_classPrivateFieldLooseBase(_fn4().Foo, _self)[_self], _m)[_m](); + (_fn5 = fn) === null || _fn5 === void 0 ? void 0 : _classPrivateFieldLooseBase(_classPrivateFieldLooseBase(_fn5().Foo, _self)[_self].self, _m)[_m](); + (_ref18 = (_fn6 = fn) === null || _fn6 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn6().Foo, _self)[_self]) === null || _ref18 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref18.self, _m)[_m](); + (_ref19 = (_fn7 = fn) === null || _fn7 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn7().Foo, _self)[_self].self) === null || _ref19 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref19.self, _m)[_m](); + (_ref20 = (_ref34 = (_fn8 = fn) === null || _fn8 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn8().Foo, _self)[_self]) === null || _ref34 === void 0 ? void 0 : _ref34.self) === null || _ref20 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref20.self, _m)[_m](); + (_fn9 = fn) === null || _fn9 === void 0 ? void 0 : _classPrivateFieldLooseBase(_classPrivateFieldLooseBase(_fn9().Foo, _self)[_self].getSelf(), _m)[_m](); + (_ref21 = (_fn10 = fn) === null || _fn10 === void 0 ? void 0 : (_classPrivateFieldLoo3 = _classPrivateFieldLooseBase(_fn10().Foo, _self)[_self]).getSelf) === null || _ref21 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref21.call(_classPrivateFieldLoo3), _m)[_m](); + (_ref22 = (_fn11 = fn) === null || _fn11 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn11().Foo, _self)[_self]) === null || _ref22 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref22.getSelf(), _m)[_m](); + (_ref23 = (_ref35 = _ref24 = (_fn12 = fn) === null || _fn12 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn12().Foo, _self)[_self]) === null || _ref35 === void 0 ? void 0 : _ref35.getSelf) === null || _ref23 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref23.call(_ref24), _m)[_m](); + (_ref25 = (_fn13 = fn) === null || _fn13 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn13().Foo, _self)[_self].getSelf()) === null || _ref25 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref25.self, _m)[_m](); + (_ref26 = (_ref36 = (_fn14 = fn) === null || _fn14 === void 0 ? void 0 : (_classPrivateFieldLoo4 = _classPrivateFieldLooseBase(_fn14().Foo, _self)[_self]).getSelf) === null || _ref36 === void 0 ? void 0 : _ref36.call(_classPrivateFieldLoo4)) === null || _ref26 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref26.self, _m)[_m](); + (_ref27 = (_ref37 = (_fn15 = fn) === null || _fn15 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn15().Foo, _self)[_self]) === null || _ref37 === void 0 ? void 0 : _ref37.getSelf()) === null || _ref27 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref27.self, _m)[_m](); + (_ref28 = (_ref38 = (_fn16 = fn) === null || _fn16 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn16().Foo, _self)[_self]) === null || _ref38 === void 0 ? void 0 : (_ref38$getSelf = _ref38.getSelf) === null || _ref38$getSelf === void 0 ? void 0 : _ref38$getSelf.call(_ref38)) === null || _ref28 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref28.self, _m)[_m](); + } + +} + +var _x = _classPrivateFieldLooseKey("x"); + +var _m = _classPrivateFieldLooseKey("m"); + +var _self = _classPrivateFieldLooseKey("self"); + +Object.defineProperty(Foo, _x, { + writable: true, + value: 1 +}); +Object.defineProperty(Foo, _m, { + writable: true, + value: function () { + return _classPrivateFieldLooseBase(this, _x)[_x]; + } +}); +Object.defineProperty(Foo, _self, { + writable: true, + value: Foo +}); +Foo.self = Foo; +Foo.test(); diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-private-call/input.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-private-call/input.js new file mode 100644 index 000000000000..d29585b51d60 --- /dev/null +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-private-call/input.js @@ -0,0 +1,66 @@ +class Foo { + static #x = 1; + static #m = function() { return this.#x; }; + static #self = Foo; + static self = Foo; + static getSelf() { return this } + + static test() { + const o = { Foo: Foo }; + const deep = { very: { o } }; + function fn() { + return o; + } + function fnDeep() { + return deep; + } + + o?.Foo.#m(); + o?.Foo.#m().toString; + o?.Foo.#m().toString(); + + deep?.very.o?.Foo.#m(); + deep?.very.o?.Foo.#m().toString; + deep?.very.o?.Foo.#m().toString(); + + o?.Foo.#self.#m(); + o?.Foo.#self.self.#m(); + o?.Foo.#self?.self.#m(); + o?.Foo.#self.self?.self.#m(); + o?.Foo.#self?.self?.self.#m(); + + o?.Foo.#self.getSelf().#m(); + o?.Foo.#self.getSelf?.().#m(); + o?.Foo.#self?.getSelf().#m(); + o?.Foo.#self?.getSelf?.().#m(); + o?.Foo.#self.getSelf()?.self.#m(); + o?.Foo.#self.getSelf?.()?.self.#m(); + o?.Foo.#self?.getSelf()?.self.#m(); + o?.Foo.#self?.getSelf?.()?.self.#m(); + + fn?.().Foo.#m(); + fn?.().Foo.#m().toString; + fn?.().Foo.#m().toString(); + + fnDeep?.().very.o?.Foo.#m(); + fnDeep?.().very.o?.Foo.#m().toString; + fnDeep?.().very.o?.Foo.#m().toString(); + + fn?.().Foo.#self.#m(); + fn?.().Foo.#self.self.#m(); + fn?.().Foo.#self?.self.#m(); + fn?.().Foo.#self.self?.self.#m(); + fn?.().Foo.#self?.self?.self.#m(); + + fn?.().Foo.#self.getSelf().#m(); + fn?.().Foo.#self.getSelf?.().#m(); + fn?.().Foo.#self?.getSelf().#m(); + fn?.().Foo.#self?.getSelf?.().#m(); + fn?.().Foo.#self.getSelf()?.self.#m(); + fn?.().Foo.#self.getSelf?.()?.self.#m(); + fn?.().Foo.#self?.getSelf()?.self.#m(); + fn?.().Foo.#self?.getSelf?.()?.self.#m(); + } +} + +Foo.test(); diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-private-call/options.json b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-private-call/options.json new file mode 100644 index 000000000000..1d89a5dde92f --- /dev/null +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-private-call/options.json @@ -0,0 +1,5 @@ +{ + "plugins": [ + ["proposal-class-properties", { "loose": true }] + ] +} diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-private-call/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-private-call/output.js new file mode 100644 index 000000000000..c8df9a71bbdd --- /dev/null +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-private-call/output.js @@ -0,0 +1,95 @@ +function _classPrivateFieldLooseBase(receiver, privateKey) { if (!Object.prototype.hasOwnProperty.call(receiver, privateKey)) { throw new TypeError("attempted to use private field on non-instance"); } return receiver; } + +var id = 0; + +function _classPrivateFieldLooseKey(name) { return "__private_" + id++ + "_" + name; } + +class Foo { + static getSelf() { + return this; + } + + static test() { + var _o, _o2, _o3, _ref, _ref2, _ref3, _o4, _o5, _o6, _ref4, _o7, _ref5, _o8, _ref6, _o9, _o10, _classPrivateFieldLoo, _ref7, _o11, _ref8, _o12, _ref9, _ref10, _o13, _ref11, _o14, _classPrivateFieldLoo2, _ref12, _o15, _ref13, _o16, _ref14, _fn, _fn2, _fn3, _ref15, _ref16, _ref17, _fn4, _fn5, _fn6, _ref18, _fn7, _ref19, _fn8, _ref20, _fn9, _fn10, _classPrivateFieldLoo3, _ref21, _fn11, _ref22, _fn12, _ref23, _ref24, _fn13, _ref25, _fn14, _classPrivateFieldLoo4, _ref26, _fn15, _ref27, _fn16, _ref28; + + const o = { + Foo: Foo + }; + const deep = { + very: { + o + } + }; + + function fn() { + return o; + } + + function fnDeep() { + return deep; + } + + (_o = o) === null || _o === void 0 ? void 0 : _classPrivateFieldLooseBase(_o.Foo, _m)[_m](); + (_o2 = o) === null || _o2 === void 0 ? void 0 : _classPrivateFieldLooseBase(_o2.Foo, _m)[_m]().toString; + (_o3 = o) === null || _o3 === void 0 ? void 0 : _classPrivateFieldLooseBase(_o3.Foo, _m)[_m]().toString(); + (_ref = deep?.very.o) === null || _ref === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref.Foo, _m)[_m](); + (_ref2 = deep?.very.o) === null || _ref2 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref2.Foo, _m)[_m]().toString; + (_ref3 = deep?.very.o) === null || _ref3 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref3.Foo, _m)[_m]().toString(); + (_o4 = o) === null || _o4 === void 0 ? void 0 : _classPrivateFieldLooseBase(_classPrivateFieldLooseBase(_o4.Foo, _self)[_self], _m)[_m](); + (_o5 = o) === null || _o5 === void 0 ? void 0 : _classPrivateFieldLooseBase(_classPrivateFieldLooseBase(_o5.Foo, _self)[_self].self, _m)[_m](); + (_ref4 = (_o6 = o) === null || _o6 === void 0 ? void 0 : _classPrivateFieldLooseBase(_o6.Foo, _self)[_self]) === null || _ref4 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref4.self, _m)[_m](); + (_ref5 = (_o7 = o) === null || _o7 === void 0 ? void 0 : _classPrivateFieldLooseBase(_o7.Foo, _self)[_self].self) === null || _ref5 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref5.self, _m)[_m](); + (_ref6 = ((_o8 = o) === null || _o8 === void 0 ? void 0 : _classPrivateFieldLooseBase(_o8.Foo, _self)[_self])?.self) === null || _ref6 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref6.self, _m)[_m](); + (_o9 = o) === null || _o9 === void 0 ? void 0 : _classPrivateFieldLooseBase(_classPrivateFieldLooseBase(_o9.Foo, _self)[_self].getSelf(), _m)[_m](); + (_ref7 = (_o10 = o) === null || _o10 === void 0 ? void 0 : (_classPrivateFieldLoo = _classPrivateFieldLooseBase(_o10.Foo, _self)[_self]).getSelf) === null || _ref7 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref7.call(_classPrivateFieldLoo), _m)[_m](); + (_ref8 = (_o11 = o) === null || _o11 === void 0 ? void 0 : _classPrivateFieldLooseBase(_o11.Foo, _self)[_self]) === null || _ref8 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref8.getSelf(), _m)[_m](); + (_ref9 = (_ref10 = (_o12 = o) === null || _o12 === void 0 ? void 0 : _classPrivateFieldLooseBase(_o12.Foo, _self)[_self])?.getSelf) === null || _ref9 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref9.call(_ref10), _m)[_m](); + (_ref11 = (_o13 = o) === null || _o13 === void 0 ? void 0 : _classPrivateFieldLooseBase(_o13.Foo, _self)[_self].getSelf()) === null || _ref11 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref11.self, _m)[_m](); + (_ref12 = ((_o14 = o) === null || _o14 === void 0 ? void 0 : (_classPrivateFieldLoo2 = _classPrivateFieldLooseBase(_o14.Foo, _self)[_self]).getSelf)?.call(_classPrivateFieldLoo2)) === null || _ref12 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref12.self, _m)[_m](); + (_ref13 = ((_o15 = o) === null || _o15 === void 0 ? void 0 : _classPrivateFieldLooseBase(_o15.Foo, _self)[_self])?.getSelf()) === null || _ref13 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref13.self, _m)[_m](); + (_ref14 = ((_o16 = o) === null || _o16 === void 0 ? void 0 : _classPrivateFieldLooseBase(_o16.Foo, _self)[_self])?.getSelf?.()) === null || _ref14 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref14.self, _m)[_m](); + (_fn = fn) === null || _fn === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn().Foo, _m)[_m](); + (_fn2 = fn) === null || _fn2 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn2().Foo, _m)[_m]().toString; + (_fn3 = fn) === null || _fn3 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn3().Foo, _m)[_m]().toString(); + (_ref15 = fnDeep?.().very.o) === null || _ref15 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref15.Foo, _m)[_m](); + (_ref16 = fnDeep?.().very.o) === null || _ref16 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref16.Foo, _m)[_m]().toString; + (_ref17 = fnDeep?.().very.o) === null || _ref17 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref17.Foo, _m)[_m]().toString(); + (_fn4 = fn) === null || _fn4 === void 0 ? void 0 : _classPrivateFieldLooseBase(_classPrivateFieldLooseBase(_fn4().Foo, _self)[_self], _m)[_m](); + (_fn5 = fn) === null || _fn5 === void 0 ? void 0 : _classPrivateFieldLooseBase(_classPrivateFieldLooseBase(_fn5().Foo, _self)[_self].self, _m)[_m](); + (_ref18 = (_fn6 = fn) === null || _fn6 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn6().Foo, _self)[_self]) === null || _ref18 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref18.self, _m)[_m](); + (_ref19 = (_fn7 = fn) === null || _fn7 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn7().Foo, _self)[_self].self) === null || _ref19 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref19.self, _m)[_m](); + (_ref20 = ((_fn8 = fn) === null || _fn8 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn8().Foo, _self)[_self])?.self) === null || _ref20 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref20.self, _m)[_m](); + (_fn9 = fn) === null || _fn9 === void 0 ? void 0 : _classPrivateFieldLooseBase(_classPrivateFieldLooseBase(_fn9().Foo, _self)[_self].getSelf(), _m)[_m](); + (_ref21 = (_fn10 = fn) === null || _fn10 === void 0 ? void 0 : (_classPrivateFieldLoo3 = _classPrivateFieldLooseBase(_fn10().Foo, _self)[_self]).getSelf) === null || _ref21 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref21.call(_classPrivateFieldLoo3), _m)[_m](); + (_ref22 = (_fn11 = fn) === null || _fn11 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn11().Foo, _self)[_self]) === null || _ref22 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref22.getSelf(), _m)[_m](); + (_ref23 = (_ref24 = (_fn12 = fn) === null || _fn12 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn12().Foo, _self)[_self])?.getSelf) === null || _ref23 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref23.call(_ref24), _m)[_m](); + (_ref25 = (_fn13 = fn) === null || _fn13 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn13().Foo, _self)[_self].getSelf()) === null || _ref25 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref25.self, _m)[_m](); + (_ref26 = ((_fn14 = fn) === null || _fn14 === void 0 ? void 0 : (_classPrivateFieldLoo4 = _classPrivateFieldLooseBase(_fn14().Foo, _self)[_self]).getSelf)?.call(_classPrivateFieldLoo4)) === null || _ref26 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref26.self, _m)[_m](); + (_ref27 = ((_fn15 = fn) === null || _fn15 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn15().Foo, _self)[_self])?.getSelf()) === null || _ref27 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref27.self, _m)[_m](); + (_ref28 = ((_fn16 = fn) === null || _fn16 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn16().Foo, _self)[_self])?.getSelf?.()) === null || _ref28 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref28.self, _m)[_m](); + } + +} + +var _x = _classPrivateFieldLooseKey("x"); + +var _m = _classPrivateFieldLooseKey("m"); + +var _self = _classPrivateFieldLooseKey("self"); + +Object.defineProperty(Foo, _x, { + writable: true, + value: 1 +}); +Object.defineProperty(Foo, _m, { + writable: true, + value: function () { + return _classPrivateFieldLooseBase(this, _x)[_x]; + } +}); +Object.defineProperty(Foo, _self, { + writable: true, + value: Foo +}); +Foo.self = Foo; +Foo.test(); diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-with-transform/exec.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-with-transform/exec.js index dd3502ead93c..98ac8e7a7e12 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-with-transform/exec.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-with-transform/exec.js @@ -2,6 +2,7 @@ class Foo { static #x = 1; static #self = Foo; static self = Foo; + static getSelf() { return this } static test() { const o = { Foo: Foo }; @@ -27,6 +28,15 @@ class Foo { expect(o?.Foo.#self.self?.self.#x).toEqual(1); expect(o?.Foo.#self?.self?.self.#x).toEqual(1); + expect(o?.Foo.#self.getSelf().#x).toEqual(1); + expect(o?.Foo.#self.getSelf?.().#x).toEqual(1); + expect(o?.Foo.#self?.getSelf().#x).toEqual(1); + expect(o?.Foo.#self?.getSelf?.().#x).toEqual(1); + expect(o?.Foo.#self.getSelf()?.self.#x).toEqual(1); + expect(o?.Foo.#self.getSelf?.()?.self.#x).toEqual(1); + expect(o?.Foo.#self?.getSelf()?.self.#x).toEqual(1); + expect(o?.Foo.#self?.getSelf?.()?.self.#x).toEqual(1); + expect(fn?.().Foo.#x).toEqual(1); expect(fn?.().Foo.#x.toString).toEqual(1..toString); expect(fn?.().Foo.#x.toString()).toEqual('1'); @@ -40,7 +50,72 @@ class Foo { expect(fn?.().Foo.#self?.self.#x).toEqual(1); expect(fn?.().Foo.#self.self?.self.#x).toEqual(1); expect(fn?.().Foo.#self?.self?.self.#x).toEqual(1); + + expect(fn?.().Foo.#self.getSelf().#x).toEqual(1); + expect(fn?.().Foo.#self.getSelf?.().#x).toEqual(1); + expect(fn?.().Foo.#self?.getSelf().#x).toEqual(1); + expect(fn?.().Foo.#self?.getSelf?.().#x).toEqual(1); + expect(fn?.().Foo.#self.getSelf()?.self.#x).toEqual(1); + expect(fn?.().Foo.#self.getSelf?.()?.self.#x).toEqual(1); + expect(fn?.().Foo.#self?.getSelf()?.self.#x).toEqual(1); + expect(fn?.().Foo.#self?.getSelf?.()?.self.#x).toEqual(1); + } + + static testNull() { + const o = null;; + const deep = { very: { o } }; + const fn = null; + function fnDeep() { + return deep; + } + + expect(o?.Foo.#x).toEqual(undefined); + expect(o?.Foo.#x.toString).toEqual(undefined); + expect(o?.Foo.#x.toString()).toEqual(undefined); + + expect(deep?.very.o?.Foo.#x).toEqual(undefined); + expect(deep?.very.o?.Foo.#x.toString).toEqual(undefined); + expect(deep?.very.o?.Foo.#x.toString()).toEqual(undefined); + + expect(o?.Foo.#self.#x).toEqual(undefined); + expect(o?.Foo.#self.self.#x).toEqual(undefined); + expect(o?.Foo.#self?.self.#x).toEqual(undefined); + expect(o?.Foo.#self.self?.self.#x).toEqual(undefined); + expect(o?.Foo.#self?.self?.self.#x).toEqual(undefined); + + expect(o?.Foo.#self.getSelf().#x).toEqual(undefined); + expect(o?.Foo.#self.getSelf?.().#x).toEqual(undefined); + expect(o?.Foo.#self?.getSelf().#x).toEqual(undefined); + expect(o?.Foo.#self?.getSelf?.().#x).toEqual(undefined); + expect(o?.Foo.#self.getSelf()?.self.#x).toEqual(undefined); + expect(o?.Foo.#self.getSelf?.()?.self.#x).toEqual(undefined); + expect(o?.Foo.#self?.getSelf()?.self.#x).toEqual(undefined); + expect(o?.Foo.#self?.getSelf?.()?.self.#x).toEqual(undefined); + + expect(fn?.().Foo.#x).toEqual(undefined); + expect(fn?.().Foo.#x.toString).toEqual(undefined); + expect(fn?.().Foo.#x.toString()).toEqual(undefined); + + expect(fnDeep?.().very.o?.Foo.#x).toEqual(undefined); + expect(fnDeep?.().very.o?.Foo.#x.toString).toEqual(undefined); + expect(fnDeep?.().very.o?.Foo.#x.toString()).toEqual(undefined); + + expect(fn?.().Foo.#self.#x).toEqual(undefined); + expect(fn?.().Foo.#self.self.#x).toEqual(undefined); + expect(fn?.().Foo.#self?.self.#x).toEqual(undefined); + expect(fn?.().Foo.#self.self?.self.#x).toEqual(undefined); + expect(fn?.().Foo.#self?.self?.self.#x).toEqual(undefined); + + expect(fn?.().Foo.#self.getSelf().#x).toEqual(undefined); + expect(fn?.().Foo.#self.getSelf?.().#x).toEqual(undefined); + expect(fn?.().Foo.#self?.getSelf().#x).toEqual(undefined); + expect(fn?.().Foo.#self?.getSelf?.().#x).toEqual(undefined); + expect(fn?.().Foo.#self.getSelf()?.self.#x).toEqual(undefined); + expect(fn?.().Foo.#self.getSelf?.()?.self.#x).toEqual(undefined); + expect(fn?.().Foo.#self?.getSelf()?.self.#x).toEqual(undefined); + expect(fn?.().Foo.#self?.getSelf?.()?.self.#x).toEqual(undefined); } } Foo.test(); +Foo.testNull(); diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-with-transform/input.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-with-transform/input.js index c9c6e861fd9c..fad2504d95e6 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-with-transform/input.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-with-transform/input.js @@ -2,6 +2,7 @@ class Foo { static #x = 1; static #self = Foo; static self = Foo; + static getSelf() { return this } static test() { const o = { Foo: Foo }; @@ -27,6 +28,15 @@ class Foo { o?.Foo.#self.self?.self.#x; o?.Foo.#self?.self?.self.#x; + o?.Foo.#self.getSelf().#x; + o?.Foo.#self.getSelf?.().#x; + o?.Foo.#self?.getSelf().#x; + o?.Foo.#self?.getSelf?.().#x; + o?.Foo.#self.getSelf()?.self.#x; + o?.Foo.#self.getSelf?.()?.self.#x; + o?.Foo.#self?.getSelf()?.self.#x; + o?.Foo.#self?.getSelf?.()?.self.#x; + fn?.().Foo.#x; fn?.().Foo.#x.toString; fn?.().Foo.#x.toString(); @@ -40,6 +50,15 @@ class Foo { fn?.().Foo.#self?.self.#x; fn?.().Foo.#self.self?.self.#x; fn?.().Foo.#self?.self?.self.#x; + + fn?.().Foo.#self.getSelf().#x; + fn?.().Foo.#self.getSelf?.().#x; + fn?.().Foo.#self?.getSelf().#x; + fn?.().Foo.#self?.getSelf?.().#x; + fn?.().Foo.#self.getSelf()?.self.#x; + fn?.().Foo.#self.getSelf?.()?.self.#x; + fn?.().Foo.#self?.getSelf()?.self.#x; + fn?.().Foo.#self?.getSelf?.()?.self.#x; } } diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-with-transform/optional-chain-with-transform/exec.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-with-transform/optional-chain-with-transform/exec.js deleted file mode 100644 index fc59ad1a86b9..000000000000 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-with-transform/optional-chain-with-transform/exec.js +++ /dev/null @@ -1,121 +0,0 @@ -class Foo { - static #x = 1; - static #self = Foo; - static self = Foo; - static getSelf() { return this } - - static test() { - const o = { Foo: Foo }; - const deep = { very: { o } }; - function fn() { - return o; - } - function fnDeep() { - return deep; - } - - expect(o?.Foo.#x).toEqual(1); - expect(o?.Foo.#x.toString).toEqual(1..toString); - expect(o?.Foo.#x.toString()).toEqual('1'); - - expect(deep?.very.o?.Foo.#x).toEqual(1); - expect(deep?.very.o?.Foo.#x.toString).toEqual(1..toString); - expect(deep?.very.o?.Foo.#x.toString()).toEqual('1'); - - expect(o?.Foo.#self.#x).toEqual(1); - expect(o?.Foo.#self.self.#x).toEqual(1); - expect(o?.Foo.#self?.self.#x).toEqual(1); - expect(o?.Foo.#self.self?.self.#x).toEqual(1); - expect(o?.Foo.#self?.self?.self.#x).toEqual(1); - - expect(o?.Foo.#self.getSelf().#x).toEqual(1); - expect(o?.Foo.#self.getSelf?.().#x).toEqual(1); - expect(o?.Foo.#self?.getSelf().#x).toEqual(1); - expect(o?.Foo.#self?.getSelf?.().#x).toEqual(1); - expect(o?.Foo.#self.getSelf()?.self.#x).toEqual(1); - expect(o?.Foo.#self.getSelf?.()?.self.#x).toEqual(1); - expect(o?.Foo.#self?.getSelf()?.self.#x).toEqual(1); - expect(o?.Foo.#self?.getSelf?.()?.self.#x).toEqual(1); - - expect(fn?.().Foo.#x).toEqual(1); - expect(fn?.().Foo.#x.toString).toEqual(1..toString); - expect(fn?.().Foo.#x.toString()).toEqual('1'); - - expect(fnDeep?.().very.o?.Foo.#x).toEqual(1); - expect(fnDeep?.().very.o?.Foo.#x.toString).toEqual(1..toString); - expect(fnDeep?.().very.o?.Foo.#x.toString()).toEqual('1'); - - expect(fn?.().Foo.#self.#x).toEqual(1); - expect(fn?.().Foo.#self.self.#x).toEqual(1); - expect(fn?.().Foo.#self?.self.#x).toEqual(1); - expect(fn?.().Foo.#self.self?.self.#x).toEqual(1); - expect(fn?.().Foo.#self?.self?.self.#x).toEqual(1); - - expect(fn?.().Foo.#self.getSelf().#x).toEqual(1); - expect(fn?.().Foo.#self.getSelf?.().#x).toEqual(1); - expect(fn?.().Foo.#self?.getSelf().#x).toEqual(1); - expect(fn?.().Foo.#self?.getSelf?.().#x).toEqual(1); - expect(fn?.().Foo.#self.getSelf()?.self.#x).toEqual(1); - expect(fn?.().Foo.#self.getSelf?.()?.self.#x).toEqual(1); - expect(fn?.().Foo.#self?.getSelf()?.self.#x).toEqual(1); - expect(fn?.().Foo.#self?.getSelf?.()?.self.#x).toEqual(1); - } - - static testNull() { - const o = null;; - const deep = { very: { o } }; - const fn = null; - function fnDeep() { - return deep; - } - - expect(o?.Foo.#x).toEqual(undefined); - expect(o?.Foo.#x.toString).toEqual(undefined); - expect(o?.Foo.#x.toString()).toEqual(undefined); - - expect(deep?.very.o?.Foo.#x).toEqual(undefined); - expect(deep?.very.o?.Foo.#x.toString).toEqual(undefined); - expect(deep?.very.o?.Foo.#x.toString()).toEqual(undefined); - - expect(o?.Foo.#self.#x).toEqual(undefined); - expect(o?.Foo.#self.self.#x).toEqual(undefined); - expect(o?.Foo.#self?.self.#x).toEqual(undefined); - expect(o?.Foo.#self.self?.self.#x).toEqual(undefined); - expect(o?.Foo.#self?.self?.self.#x).toEqual(undefined); - - expect(o?.Foo.#self.getSelf().#x).toEqual(undefined); - expect(o?.Foo.#self.getSelf?.().#x).toEqual(undefined); - expect(o?.Foo.#self?.getSelf().#x).toEqual(undefined); - expect(o?.Foo.#self?.getSelf?.().#x).toEqual(undefined); - expect(o?.Foo.#self.getSelf()?.self.#x).toEqual(undefined); - expect(o?.Foo.#self.getSelf?.()?.self.#x).toEqual(undefined); - expect(o?.Foo.#self?.getSelf()?.self.#x).toEqual(undefined); - expect(o?.Foo.#self?.getSelf?.()?.self.#x).toEqual(undefined); - - expect(fn?.().Foo.#x).toEqual(undefined); - expect(fn?.().Foo.#x.toString).toEqual(undefined); - expect(fn?.().Foo.#x.toString()).toEqual(undefined); - - expect(fnDeep?.().very.o?.Foo.#x).toEqual(undefined); - expect(fnDeep?.().very.o?.Foo.#x.toString).toEqual(undefined); - expect(fnDeep?.().very.o?.Foo.#x.toString()).toEqual(undefined); - - expect(fn?.().Foo.#self.#x).toEqual(undefined); - expect(fn?.().Foo.#self.self.#x).toEqual(undefined); - expect(fn?.().Foo.#self?.self.#x).toEqual(undefined); - expect(fn?.().Foo.#self.self?.self.#x).toEqual(undefined); - expect(fn?.().Foo.#self?.self?.self.#x).toEqual(undefined); - - expect(fn?.().Foo.#self.getSelf().#x).toEqual(undefined); - expect(fn?.().Foo.#self.getSelf?.().#x).toEqual(undefined); - expect(fn?.().Foo.#self?.getSelf().#x).toEqual(undefined); - expect(fn?.().Foo.#self?.getSelf?.().#x).toEqual(undefined); - expect(fn?.().Foo.#self.getSelf()?.self.#x).toEqual(undefined); - expect(fn?.().Foo.#self.getSelf?.()?.self.#x).toEqual(undefined); - expect(fn?.().Foo.#self?.getSelf()?.self.#x).toEqual(undefined); - expect(fn?.().Foo.#self?.getSelf?.()?.self.#x).toEqual(undefined); - } -} - -// Foo.test(); -Foo.testNull(); diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-with-transform/optional-chain-with-transform/input.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-with-transform/optional-chain-with-transform/input.js deleted file mode 100644 index fad2504d95e6..000000000000 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-with-transform/optional-chain-with-transform/input.js +++ /dev/null @@ -1,65 +0,0 @@ -class Foo { - static #x = 1; - static #self = Foo; - static self = Foo; - static getSelf() { return this } - - static test() { - const o = { Foo: Foo }; - const deep = { very: { o } }; - function fn() { - return o; - } - function fnDeep() { - return deep; - } - - o?.Foo.#x; - o?.Foo.#x.toString; - o?.Foo.#x.toString(); - - deep?.very.o?.Foo.#x; - deep?.very.o?.Foo.#x.toString; - deep?.very.o?.Foo.#x.toString(); - - o?.Foo.#self.#x; - o?.Foo.#self.self.#x; - o?.Foo.#self?.self.#x; - o?.Foo.#self.self?.self.#x; - o?.Foo.#self?.self?.self.#x; - - o?.Foo.#self.getSelf().#x; - o?.Foo.#self.getSelf?.().#x; - o?.Foo.#self?.getSelf().#x; - o?.Foo.#self?.getSelf?.().#x; - o?.Foo.#self.getSelf()?.self.#x; - o?.Foo.#self.getSelf?.()?.self.#x; - o?.Foo.#self?.getSelf()?.self.#x; - o?.Foo.#self?.getSelf?.()?.self.#x; - - fn?.().Foo.#x; - fn?.().Foo.#x.toString; - fn?.().Foo.#x.toString(); - - fnDeep?.().very.o?.Foo.#x; - fnDeep?.().very.o?.Foo.#x.toString; - fnDeep?.().very.o?.Foo.#x.toString(); - - fn?.().Foo.#self.#x; - fn?.().Foo.#self.self.#x; - fn?.().Foo.#self?.self.#x; - fn?.().Foo.#self.self?.self.#x; - fn?.().Foo.#self?.self?.self.#x; - - fn?.().Foo.#self.getSelf().#x; - fn?.().Foo.#self.getSelf?.().#x; - fn?.().Foo.#self?.getSelf().#x; - fn?.().Foo.#self?.getSelf?.().#x; - fn?.().Foo.#self.getSelf()?.self.#x; - fn?.().Foo.#self.getSelf?.()?.self.#x; - fn?.().Foo.#self?.getSelf()?.self.#x; - fn?.().Foo.#self?.getSelf?.()?.self.#x; - } -} - -Foo.test(); diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-with-transform/optional-chain-with-transform/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-with-transform/optional-chain-with-transform/output.js deleted file mode 100644 index 1525a03dc3cd..000000000000 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-with-transform/optional-chain-with-transform/output.js +++ /dev/null @@ -1,83 +0,0 @@ -function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } - -function _classStaticPrivateFieldSpecGet(receiver, classConstructor, descriptor) { if (receiver !== classConstructor) { throw new TypeError("Private static access of wrong provenance"); } if (descriptor.get) { return descriptor.get.call(receiver); } return descriptor.value; } - -class Foo { - static getSelf() { - return this; - } - - static test() { - var _o, _o2, _o3, _ref, _ref2, _ref3, _o4, _o5, _o6, _ref4, _o7, _ref5, _o8, _ref6, _o9, _o10, _classStaticPrivateFi, _ref7, _o11, _ref8, _o12, _ref9, _ref10, _o13, _ref11, _o14, _classStaticPrivateFi2, _ref12, _o15, _ref13, _o16, _ref14, _fn, _fn2, _fn3, _ref15, _ref16, _ref17, _fn4, _fn5, _fn6, _ref18, _fn7, _ref19, _fn8, _ref20, _fn9, _fn10, _classStaticPrivateFi3, _ref21, _fn11, _ref22, _fn12, _ref23, _ref24, _fn13, _ref25, _fn14, _classStaticPrivateFi4, _ref26, _fn15, _ref27, _fn16, _ref28, _ref29, _ref30, _ref31, _ref32, _ref33, _ref33$getSelf, _ref34, _ref35, _ref36, _ref37, _ref38, _ref38$getSelf; - - const o = { - Foo: Foo - }; - const deep = { - very: { - o - } - }; - - function fn() { - return o; - } - - function fnDeep() { - return deep; - } - - (_o = o) === null || _o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o.Foo, Foo, _x); - (_o2 = o) === null || _o2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o2.Foo, Foo, _x).toString; - (_o3 = o) === null || _o3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o3.Foo, Foo, _x).toString(); - (_ref = deep === null || deep === void 0 ? void 0 : deep.very.o) === null || _ref === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref.Foo, Foo, _x); - (_ref2 = deep === null || deep === void 0 ? void 0 : deep.very.o) === null || _ref2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref2.Foo, Foo, _x).toString; - (_ref3 = deep === null || deep === void 0 ? void 0 : deep.very.o) === null || _ref3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref3.Foo, Foo, _x).toString(); - (_o4 = o) === null || _o4 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFieldSpecGet(_o4.Foo, Foo, _self), Foo, _x); - (_o5 = o) === null || _o5 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFieldSpecGet(_o5.Foo, Foo, _self).self, Foo, _x); - (_ref4 = (_o6 = o) === null || _o6 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o6.Foo, Foo, _self)) === null || _ref4 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref4.self, Foo, _x); - (_ref5 = (_o7 = o) === null || _o7 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o7.Foo, Foo, _self).self) === null || _ref5 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref5.self, Foo, _x); - (_ref6 = (_ref29 = (_o8 = o) === null || _o8 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o8.Foo, Foo, _self)) === null || _ref29 === void 0 ? void 0 : _ref29.self) === null || _ref6 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref6.self, Foo, _x); - (_o9 = o) === null || _o9 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFieldSpecGet(_o9.Foo, Foo, _self).getSelf(), Foo, _x); - (_ref7 = (_o10 = o) === null || _o10 === void 0 ? void 0 : (_classStaticPrivateFi = _classStaticPrivateFieldSpecGet(_o10.Foo, Foo, _self)).getSelf) === null || _ref7 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref7.call(_classStaticPrivateFi), Foo, _x); - (_ref8 = (_o11 = o) === null || _o11 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o11.Foo, Foo, _self)) === null || _ref8 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref8.getSelf(), Foo, _x); - (_ref9 = (_ref30 = _ref10 = (_o12 = o) === null || _o12 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o12.Foo, Foo, _self)) === null || _ref30 === void 0 ? void 0 : _ref30.getSelf) === null || _ref9 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref9.call(_ref10), Foo, _x); - (_ref11 = (_o13 = o) === null || _o13 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o13.Foo, Foo, _self).getSelf()) === null || _ref11 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref11.self, Foo, _x); - (_ref12 = (_ref31 = (_o14 = o) === null || _o14 === void 0 ? void 0 : (_classStaticPrivateFi2 = _classStaticPrivateFieldSpecGet(_o14.Foo, Foo, _self)).getSelf) === null || _ref31 === void 0 ? void 0 : _ref31.call(_classStaticPrivateFi2)) === null || _ref12 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref12.self, Foo, _x); - (_ref13 = (_ref32 = (_o15 = o) === null || _o15 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o15.Foo, Foo, _self)) === null || _ref32 === void 0 ? void 0 : _ref32.getSelf()) === null || _ref13 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref13.self, Foo, _x); - (_ref14 = (_ref33 = (_o16 = o) === null || _o16 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o16.Foo, Foo, _self)) === null || _ref33 === void 0 ? void 0 : (_ref33$getSelf = _ref33.getSelf) === null || _ref33$getSelf === void 0 ? void 0 : _ref33$getSelf.call(_ref33)) === null || _ref14 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref14.self, Foo, _x); - (_fn = fn) === null || _fn === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn().Foo, Foo, _x); - (_fn2 = fn) === null || _fn2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn2().Foo, Foo, _x).toString; - (_fn3 = fn) === null || _fn3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn3().Foo, Foo, _x).toString(); - (_ref15 = fnDeep === null || fnDeep === void 0 ? void 0 : fnDeep().very.o) === null || _ref15 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref15.Foo, Foo, _x); - (_ref16 = fnDeep === null || fnDeep === void 0 ? void 0 : fnDeep().very.o) === null || _ref16 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref16.Foo, Foo, _x).toString; - (_ref17 = fnDeep === null || fnDeep === void 0 ? void 0 : fnDeep().very.o) === null || _ref17 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref17.Foo, Foo, _x).toString(); - (_fn4 = fn) === null || _fn4 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFieldSpecGet(_fn4().Foo, Foo, _self), Foo, _x); - (_fn5 = fn) === null || _fn5 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFieldSpecGet(_fn5().Foo, Foo, _self).self, Foo, _x); - (_ref18 = (_fn6 = fn) === null || _fn6 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn6().Foo, Foo, _self)) === null || _ref18 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref18.self, Foo, _x); - (_ref19 = (_fn7 = fn) === null || _fn7 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn7().Foo, Foo, _self).self) === null || _ref19 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref19.self, Foo, _x); - (_ref20 = (_ref34 = (_fn8 = fn) === null || _fn8 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn8().Foo, Foo, _self)) === null || _ref34 === void 0 ? void 0 : _ref34.self) === null || _ref20 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref20.self, Foo, _x); - (_fn9 = fn) === null || _fn9 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFieldSpecGet(_fn9().Foo, Foo, _self).getSelf(), Foo, _x); - (_ref21 = (_fn10 = fn) === null || _fn10 === void 0 ? void 0 : (_classStaticPrivateFi3 = _classStaticPrivateFieldSpecGet(_fn10().Foo, Foo, _self)).getSelf) === null || _ref21 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref21.call(_classStaticPrivateFi3), Foo, _x); - (_ref22 = (_fn11 = fn) === null || _fn11 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn11().Foo, Foo, _self)) === null || _ref22 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref22.getSelf(), Foo, _x); - (_ref23 = (_ref35 = _ref24 = (_fn12 = fn) === null || _fn12 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn12().Foo, Foo, _self)) === null || _ref35 === void 0 ? void 0 : _ref35.getSelf) === null || _ref23 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref23.call(_ref24), Foo, _x); - (_ref25 = (_fn13 = fn) === null || _fn13 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn13().Foo, Foo, _self).getSelf()) === null || _ref25 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref25.self, Foo, _x); - (_ref26 = (_ref36 = (_fn14 = fn) === null || _fn14 === void 0 ? void 0 : (_classStaticPrivateFi4 = _classStaticPrivateFieldSpecGet(_fn14().Foo, Foo, _self)).getSelf) === null || _ref36 === void 0 ? void 0 : _ref36.call(_classStaticPrivateFi4)) === null || _ref26 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref26.self, Foo, _x); - (_ref27 = (_ref37 = (_fn15 = fn) === null || _fn15 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn15().Foo, Foo, _self)) === null || _ref37 === void 0 ? void 0 : _ref37.getSelf()) === null || _ref27 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref27.self, Foo, _x); - (_ref28 = (_ref38 = (_fn16 = fn) === null || _fn16 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn16().Foo, Foo, _self)) === null || _ref38 === void 0 ? void 0 : (_ref38$getSelf = _ref38.getSelf) === null || _ref38$getSelf === void 0 ? void 0 : _ref38$getSelf.call(_ref38)) === null || _ref28 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref28.self, Foo, _x); - } - -} - -var _x = { - writable: true, - value: 1 -}; -var _self = { - writable: true, - value: Foo -}; - -_defineProperty(Foo, "self", Foo); - -Foo.test(); diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-with-transform/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-with-transform/output.js index 5ef3ddaa00bc..f0f84e8fd25d 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-with-transform/output.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-with-transform/output.js @@ -5,8 +5,12 @@ var id = 0; function _classPrivateFieldLooseKey(name) { return "__private_" + id++ + "_" + name; } class Foo { + static getSelf() { + return this; + } + static test() { - var _o, _o2, _o3, _ref, _ref2, _ref3, _o4, _o5, _o6, _ref4, _o7, _ref5, _o8, _ref6, _fn, _fn2, _fn3, _ref7, _ref8, _ref9, _fn4, _fn5, _fn6, _ref10, _fn7, _ref11, _fn8, _ref12, _ref13, _ref14; + var _o, _o2, _o3, _ref, _ref2, _ref3, _o4, _o5, _o6, _ref4, _o7, _ref5, _o8, _ref6, _o9, _o10, _classPrivateFieldLoo, _ref7, _o11, _ref8, _o12, _ref9, _ref10, _o13, _ref11, _o14, _classPrivateFieldLoo2, _ref12, _o15, _ref13, _o16, _ref14, _fn, _fn2, _fn3, _ref15, _ref16, _ref17, _fn4, _fn5, _fn6, _ref18, _fn7, _ref19, _fn8, _ref20, _fn9, _fn10, _classPrivateFieldLoo3, _ref21, _fn11, _ref22, _fn12, _ref23, _ref24, _fn13, _ref25, _fn14, _classPrivateFieldLoo4, _ref26, _fn15, _ref27, _fn16, _ref28, _ref29, _ref30, _ref31, _ref32, _ref33, _ref33$getSelf, _ref34, _ref35, _ref36, _ref37, _ref38, _ref38$getSelf; const o = { Foo: Foo @@ -35,18 +39,34 @@ class Foo { (_o5 = o) === null || _o5 === void 0 ? void 0 : _classPrivateFieldLooseBase(_classPrivateFieldLooseBase(_o5.Foo, _self)[_self].self, _x)[_x]; (_ref4 = (_o6 = o) === null || _o6 === void 0 ? void 0 : _classPrivateFieldLooseBase(_o6.Foo, _self)[_self]) === null || _ref4 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref4.self, _x)[_x]; (_ref5 = (_o7 = o) === null || _o7 === void 0 ? void 0 : _classPrivateFieldLooseBase(_o7.Foo, _self)[_self].self) === null || _ref5 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref5.self, _x)[_x]; - (_ref6 = (_ref13 = (_o8 = o) === null || _o8 === void 0 ? void 0 : _classPrivateFieldLooseBase(_o8.Foo, _self)[_self]) === null || _ref13 === void 0 ? void 0 : _ref13.self) === null || _ref6 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref6.self, _x)[_x]; + (_ref6 = (_ref29 = (_o8 = o) === null || _o8 === void 0 ? void 0 : _classPrivateFieldLooseBase(_o8.Foo, _self)[_self]) === null || _ref29 === void 0 ? void 0 : _ref29.self) === null || _ref6 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref6.self, _x)[_x]; + (_o9 = o) === null || _o9 === void 0 ? void 0 : _classPrivateFieldLooseBase(_classPrivateFieldLooseBase(_o9.Foo, _self)[_self].getSelf(), _x)[_x]; + (_ref7 = (_o10 = o) === null || _o10 === void 0 ? void 0 : (_classPrivateFieldLoo = _classPrivateFieldLooseBase(_o10.Foo, _self)[_self]).getSelf) === null || _ref7 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref7.call(_classPrivateFieldLoo), _x)[_x]; + (_ref8 = (_o11 = o) === null || _o11 === void 0 ? void 0 : _classPrivateFieldLooseBase(_o11.Foo, _self)[_self]) === null || _ref8 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref8.getSelf(), _x)[_x]; + (_ref9 = (_ref30 = _ref10 = (_o12 = o) === null || _o12 === void 0 ? void 0 : _classPrivateFieldLooseBase(_o12.Foo, _self)[_self]) === null || _ref30 === void 0 ? void 0 : _ref30.getSelf) === null || _ref9 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref9.call(_ref10), _x)[_x]; + (_ref11 = (_o13 = o) === null || _o13 === void 0 ? void 0 : _classPrivateFieldLooseBase(_o13.Foo, _self)[_self].getSelf()) === null || _ref11 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref11.self, _x)[_x]; + (_ref12 = (_ref31 = (_o14 = o) === null || _o14 === void 0 ? void 0 : (_classPrivateFieldLoo2 = _classPrivateFieldLooseBase(_o14.Foo, _self)[_self]).getSelf) === null || _ref31 === void 0 ? void 0 : _ref31.call(_classPrivateFieldLoo2)) === null || _ref12 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref12.self, _x)[_x]; + (_ref13 = (_ref32 = (_o15 = o) === null || _o15 === void 0 ? void 0 : _classPrivateFieldLooseBase(_o15.Foo, _self)[_self]) === null || _ref32 === void 0 ? void 0 : _ref32.getSelf()) === null || _ref13 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref13.self, _x)[_x]; + (_ref14 = (_ref33 = (_o16 = o) === null || _o16 === void 0 ? void 0 : _classPrivateFieldLooseBase(_o16.Foo, _self)[_self]) === null || _ref33 === void 0 ? void 0 : (_ref33$getSelf = _ref33.getSelf) === null || _ref33$getSelf === void 0 ? void 0 : _ref33$getSelf.call(_ref33)) === null || _ref14 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref14.self, _x)[_x]; (_fn = fn) === null || _fn === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn().Foo, _x)[_x]; (_fn2 = fn) === null || _fn2 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn2().Foo, _x)[_x].toString; (_fn3 = fn) === null || _fn3 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn3().Foo, _x)[_x].toString(); - (_ref7 = fnDeep === null || fnDeep === void 0 ? void 0 : fnDeep().very.o) === null || _ref7 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref7.Foo, _x)[_x]; - (_ref8 = fnDeep === null || fnDeep === void 0 ? void 0 : fnDeep().very.o) === null || _ref8 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref8.Foo, _x)[_x].toString; - (_ref9 = fnDeep === null || fnDeep === void 0 ? void 0 : fnDeep().very.o) === null || _ref9 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref9.Foo, _x)[_x].toString(); + (_ref15 = fnDeep === null || fnDeep === void 0 ? void 0 : fnDeep().very.o) === null || _ref15 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref15.Foo, _x)[_x]; + (_ref16 = fnDeep === null || fnDeep === void 0 ? void 0 : fnDeep().very.o) === null || _ref16 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref16.Foo, _x)[_x].toString; + (_ref17 = fnDeep === null || fnDeep === void 0 ? void 0 : fnDeep().very.o) === null || _ref17 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref17.Foo, _x)[_x].toString(); (_fn4 = fn) === null || _fn4 === void 0 ? void 0 : _classPrivateFieldLooseBase(_classPrivateFieldLooseBase(_fn4().Foo, _self)[_self], _x)[_x]; (_fn5 = fn) === null || _fn5 === void 0 ? void 0 : _classPrivateFieldLooseBase(_classPrivateFieldLooseBase(_fn5().Foo, _self)[_self].self, _x)[_x]; - (_ref10 = (_fn6 = fn) === null || _fn6 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn6().Foo, _self)[_self]) === null || _ref10 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref10.self, _x)[_x]; - (_ref11 = (_fn7 = fn) === null || _fn7 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn7().Foo, _self)[_self].self) === null || _ref11 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref11.self, _x)[_x]; - (_ref12 = (_ref14 = (_fn8 = fn) === null || _fn8 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn8().Foo, _self)[_self]) === null || _ref14 === void 0 ? void 0 : _ref14.self) === null || _ref12 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref12.self, _x)[_x]; + (_ref18 = (_fn6 = fn) === null || _fn6 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn6().Foo, _self)[_self]) === null || _ref18 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref18.self, _x)[_x]; + (_ref19 = (_fn7 = fn) === null || _fn7 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn7().Foo, _self)[_self].self) === null || _ref19 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref19.self, _x)[_x]; + (_ref20 = (_ref34 = (_fn8 = fn) === null || _fn8 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn8().Foo, _self)[_self]) === null || _ref34 === void 0 ? void 0 : _ref34.self) === null || _ref20 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref20.self, _x)[_x]; + (_fn9 = fn) === null || _fn9 === void 0 ? void 0 : _classPrivateFieldLooseBase(_classPrivateFieldLooseBase(_fn9().Foo, _self)[_self].getSelf(), _x)[_x]; + (_ref21 = (_fn10 = fn) === null || _fn10 === void 0 ? void 0 : (_classPrivateFieldLoo3 = _classPrivateFieldLooseBase(_fn10().Foo, _self)[_self]).getSelf) === null || _ref21 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref21.call(_classPrivateFieldLoo3), _x)[_x]; + (_ref22 = (_fn11 = fn) === null || _fn11 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn11().Foo, _self)[_self]) === null || _ref22 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref22.getSelf(), _x)[_x]; + (_ref23 = (_ref35 = _ref24 = (_fn12 = fn) === null || _fn12 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn12().Foo, _self)[_self]) === null || _ref35 === void 0 ? void 0 : _ref35.getSelf) === null || _ref23 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref23.call(_ref24), _x)[_x]; + (_ref25 = (_fn13 = fn) === null || _fn13 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn13().Foo, _self)[_self].getSelf()) === null || _ref25 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref25.self, _x)[_x]; + (_ref26 = (_ref36 = (_fn14 = fn) === null || _fn14 === void 0 ? void 0 : (_classPrivateFieldLoo4 = _classPrivateFieldLooseBase(_fn14().Foo, _self)[_self]).getSelf) === null || _ref36 === void 0 ? void 0 : _ref36.call(_classPrivateFieldLoo4)) === null || _ref26 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref26.self, _x)[_x]; + (_ref27 = (_ref37 = (_fn15 = fn) === null || _fn15 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn15().Foo, _self)[_self]) === null || _ref37 === void 0 ? void 0 : _ref37.getSelf()) === null || _ref27 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref27.self, _x)[_x]; + (_ref28 = (_ref38 = (_fn16 = fn) === null || _fn16 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn16().Foo, _self)[_self]) === null || _ref38 === void 0 ? void 0 : (_ref38$getSelf = _ref38.getSelf) === null || _ref38$getSelf === void 0 ? void 0 : _ref38$getSelf.call(_ref38)) === null || _ref28 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref28.self, _x)[_x]; } } diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain/input.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain/input.js index c9c6e861fd9c..cf001da081fc 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain/input.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain/input.js @@ -2,6 +2,7 @@ class Foo { static #x = 1; static #self = Foo; static self = Foo; + static getSelf() { return this } static test() { const o = { Foo: Foo }; @@ -27,6 +28,15 @@ class Foo { o?.Foo.#self.self?.self.#x; o?.Foo.#self?.self?.self.#x; + o?.Foo.#self.getSelf().#x; + o?.Foo.#self.getSelf?.().#x; + o?.Foo.#self?.getSelf().#x; + o?.Foo.#self?.getSelf?.().#x; + o?.Foo.#self.getSelf()?.self.#x; + o?.Foo.#self.getSelf?.()?.self.#x; + o?.Foo.#self?.getSelf()?.self.#x; + o?.Foo.#self?.getSelf?.()?.self.#x; + fn?.().Foo.#x; fn?.().Foo.#x.toString; fn?.().Foo.#x.toString(); @@ -40,6 +50,16 @@ class Foo { fn?.().Foo.#self?.self.#x; fn?.().Foo.#self.self?.self.#x; fn?.().Foo.#self?.self?.self.#x; + + fn?.().Foo.#self.getSelf().#x; + fn?.().Foo.#self.getSelf?.().#x; + fn?.().Foo.#self?.getSelf().#x; + fn?.().Foo.#self?.getSelf?.().#x; + fn?.().Foo.#self.getSelf()?.self.#x; + fn?.().Foo.#self.getSelf?.()?.self.#x; + fn?.().Foo.#self?.getSelf()?.self.#x; + fn?.().Foo.#self?.getSelf?.()?.self.#x; + } } diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain/optional-chain/input.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain/optional-chain/input.js deleted file mode 100644 index cf001da081fc..000000000000 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain/optional-chain/input.js +++ /dev/null @@ -1,66 +0,0 @@ -class Foo { - static #x = 1; - static #self = Foo; - static self = Foo; - static getSelf() { return this } - - static test() { - const o = { Foo: Foo }; - const deep = { very: { o } }; - function fn() { - return o; - } - function fnDeep() { - return deep; - } - - o?.Foo.#x; - o?.Foo.#x.toString; - o?.Foo.#x.toString(); - - deep?.very.o?.Foo.#x; - deep?.very.o?.Foo.#x.toString; - deep?.very.o?.Foo.#x.toString(); - - o?.Foo.#self.#x; - o?.Foo.#self.self.#x; - o?.Foo.#self?.self.#x; - o?.Foo.#self.self?.self.#x; - o?.Foo.#self?.self?.self.#x; - - o?.Foo.#self.getSelf().#x; - o?.Foo.#self.getSelf?.().#x; - o?.Foo.#self?.getSelf().#x; - o?.Foo.#self?.getSelf?.().#x; - o?.Foo.#self.getSelf()?.self.#x; - o?.Foo.#self.getSelf?.()?.self.#x; - o?.Foo.#self?.getSelf()?.self.#x; - o?.Foo.#self?.getSelf?.()?.self.#x; - - fn?.().Foo.#x; - fn?.().Foo.#x.toString; - fn?.().Foo.#x.toString(); - - fnDeep?.().very.o?.Foo.#x; - fnDeep?.().very.o?.Foo.#x.toString; - fnDeep?.().very.o?.Foo.#x.toString(); - - fn?.().Foo.#self.#x; - fn?.().Foo.#self.self.#x; - fn?.().Foo.#self?.self.#x; - fn?.().Foo.#self.self?.self.#x; - fn?.().Foo.#self?.self?.self.#x; - - fn?.().Foo.#self.getSelf().#x; - fn?.().Foo.#self.getSelf?.().#x; - fn?.().Foo.#self?.getSelf().#x; - fn?.().Foo.#self?.getSelf?.().#x; - fn?.().Foo.#self.getSelf()?.self.#x; - fn?.().Foo.#self.getSelf?.()?.self.#x; - fn?.().Foo.#self?.getSelf()?.self.#x; - fn?.().Foo.#self?.getSelf?.()?.self.#x; - - } -} - -Foo.test(); diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain/optional-chain/options.json b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain/optional-chain/options.json deleted file mode 100644 index 19ed5174f545..000000000000 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain/optional-chain/options.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "plugins": ["proposal-class-properties"] -} diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain/optional-chain/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain/optional-chain/output.js deleted file mode 100644 index 7ade58140926..000000000000 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain/optional-chain/output.js +++ /dev/null @@ -1,83 +0,0 @@ -function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } - -function _classStaticPrivateFieldSpecGet(receiver, classConstructor, descriptor) { if (receiver !== classConstructor) { throw new TypeError("Private static access of wrong provenance"); } if (descriptor.get) { return descriptor.get.call(receiver); } return descriptor.value; } - -class Foo { - static getSelf() { - return this; - } - - static test() { - var _o, _o2, _o3, _ref, _ref2, _ref3, _o4, _o5, _o6, _ref4, _o7, _ref5, _o8, _ref6, _o9, _o10, _ref7, _o11, _ref8, _o12, _ref9, _o13, _ref10, _o14, _ref11, _o15, _ref12, _o16, _ref13, _fn, _fn2, _fn3, _ref14, _ref15, _ref16, _fn4, _fn5, _fn6, _ref17, _fn7, _ref18, _fn8, _ref19, _fn9, _fn10, _ref20, _fn11, _ref21, _fn12, _ref22, _fn13, _ref23, _fn14, _ref24, _fn15, _ref25, _fn16, _ref26; - - const o = { - Foo: Foo - }; - const deep = { - very: { - o - } - }; - - function fn() { - return o; - } - - function fnDeep() { - return deep; - } - - (_o = o) === null || _o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o?.Foo, Foo, _x); - (_o2 = o) === null || _o2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o2?.Foo, Foo, _x).toString; - (_o3 = o) === null || _o3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o3?.Foo, Foo, _x).toString(); - (_ref = deep?.very.o) === null || _ref === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref?.Foo, Foo, _x); - (_ref2 = deep?.very.o) === null || _ref2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref2?.Foo, Foo, _x).toString; - (_ref3 = deep?.very.o) === null || _ref3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref3?.Foo, Foo, _x).toString(); - (_o4 = o) === null || _o4 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFieldSpecGet(_o4?.Foo, Foo, _self), Foo, _x); - (_o5 = o) === null || _o5 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFieldSpecGet(_o5?.Foo, Foo, _self).self, Foo, _x); - (_ref4 = (_o6 = o) === null || _o6 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o6?.Foo, Foo, _self)) === null || _ref4 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref4?.self, Foo, _x); - (_ref5 = (_o7 = o) === null || _o7 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o7?.Foo, Foo, _self).self) === null || _ref5 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref5?.self, Foo, _x); - (_ref6 = ((_o8 = o) === null || _o8 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o8?.Foo, Foo, _self))?.self) === null || _ref6 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref6?.self, Foo, _x); - (_o9 = o) === null || _o9 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFieldSpecGet(_o9?.Foo, Foo, _self).getSelf(), Foo, _x); - (_ref7 = (_o10 = o) === null || _o10 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o10?.Foo, Foo, _self).getSelf) === null || _ref7 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref7?.(), Foo, _x); - (_ref8 = (_o11 = o) === null || _o11 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o11?.Foo, Foo, _self)) === null || _ref8 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref8?.getSelf(), Foo, _x); - (_ref9 = ((_o12 = o) === null || _o12 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o12?.Foo, Foo, _self))?.getSelf) === null || _ref9 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref9?.(), Foo, _x); - (_ref10 = (_o13 = o) === null || _o13 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o13?.Foo, Foo, _self).getSelf()) === null || _ref10 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref10?.self, Foo, _x); - (_ref11 = ((_o14 = o) === null || _o14 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o14?.Foo, Foo, _self).getSelf)?.()) === null || _ref11 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref11?.self, Foo, _x); - (_ref12 = ((_o15 = o) === null || _o15 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o15?.Foo, Foo, _self))?.getSelf()) === null || _ref12 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref12?.self, Foo, _x); - (_ref13 = ((_o16 = o) === null || _o16 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o16?.Foo, Foo, _self))?.getSelf?.()) === null || _ref13 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref13?.self, Foo, _x); - (_fn = fn) === null || _fn === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn?.().Foo, Foo, _x); - (_fn2 = fn) === null || _fn2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn2?.().Foo, Foo, _x).toString; - (_fn3 = fn) === null || _fn3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn3?.().Foo, Foo, _x).toString(); - (_ref14 = fnDeep?.().very.o) === null || _ref14 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref14?.Foo, Foo, _x); - (_ref15 = fnDeep?.().very.o) === null || _ref15 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref15?.Foo, Foo, _x).toString; - (_ref16 = fnDeep?.().very.o) === null || _ref16 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref16?.Foo, Foo, _x).toString(); - (_fn4 = fn) === null || _fn4 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFieldSpecGet(_fn4?.().Foo, Foo, _self), Foo, _x); - (_fn5 = fn) === null || _fn5 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFieldSpecGet(_fn5?.().Foo, Foo, _self).self, Foo, _x); - (_ref17 = (_fn6 = fn) === null || _fn6 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn6?.().Foo, Foo, _self)) === null || _ref17 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref17?.self, Foo, _x); - (_ref18 = (_fn7 = fn) === null || _fn7 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn7?.().Foo, Foo, _self).self) === null || _ref18 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref18?.self, Foo, _x); - (_ref19 = ((_fn8 = fn) === null || _fn8 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn8?.().Foo, Foo, _self))?.self) === null || _ref19 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref19?.self, Foo, _x); - (_fn9 = fn) === null || _fn9 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFieldSpecGet(_fn9?.().Foo, Foo, _self).getSelf(), Foo, _x); - (_ref20 = (_fn10 = fn) === null || _fn10 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn10?.().Foo, Foo, _self).getSelf) === null || _ref20 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref20?.(), Foo, _x); - (_ref21 = (_fn11 = fn) === null || _fn11 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn11?.().Foo, Foo, _self)) === null || _ref21 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref21?.getSelf(), Foo, _x); - (_ref22 = ((_fn12 = fn) === null || _fn12 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn12?.().Foo, Foo, _self))?.getSelf) === null || _ref22 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref22?.(), Foo, _x); - (_ref23 = (_fn13 = fn) === null || _fn13 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn13?.().Foo, Foo, _self).getSelf()) === null || _ref23 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref23?.self, Foo, _x); - (_ref24 = ((_fn14 = fn) === null || _fn14 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn14?.().Foo, Foo, _self).getSelf)?.()) === null || _ref24 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref24?.self, Foo, _x); - (_ref25 = ((_fn15 = fn) === null || _fn15 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn15?.().Foo, Foo, _self))?.getSelf()) === null || _ref25 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref25?.self, Foo, _x); - (_ref26 = ((_fn16 = fn) === null || _fn16 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn16?.().Foo, Foo, _self))?.getSelf?.()) === null || _ref26 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref26?.self, Foo, _x); - } - -} - -var _x = { - writable: true, - value: 1 -}; -var _self = { - writable: true, - value: Foo -}; - -_defineProperty(Foo, "self", Foo); - -Foo.test(); diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain/options.json b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain/options.json index 693db86a79a0..1d89a5dde92f 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain/options.json +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain/options.json @@ -1,3 +1,5 @@ { - "plugins": [["proposal-class-properties", { "loose": true }]] + "plugins": [ + ["proposal-class-properties", { "loose": true }] + ] } diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain/output.js index 5e31609d5128..a70ea420d62b 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain/output.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain/output.js @@ -5,8 +5,12 @@ var id = 0; function _classPrivateFieldLooseKey(name) { return "__private_" + id++ + "_" + name; } class Foo { + static getSelf() { + return this; + } + static test() { - var _o, _o2, _o3, _ref, _ref2, _ref3, _o4, _o5, _o6, _ref4, _o7, _ref5, _o8, _ref6, _fn, _fn2, _fn3, _ref7, _ref8, _ref9, _fn4, _fn5, _fn6, _ref10, _fn7, _ref11, _fn8, _ref12; + var _o, _o2, _o3, _ref, _ref2, _ref3, _o4, _o5, _o6, _ref4, _o7, _ref5, _o8, _ref6, _o9, _o10, _classPrivateFieldLoo, _ref7, _o11, _ref8, _o12, _ref9, _ref10, _o13, _ref11, _o14, _classPrivateFieldLoo2, _ref12, _o15, _ref13, _o16, _ref14, _fn, _fn2, _fn3, _ref15, _ref16, _ref17, _fn4, _fn5, _fn6, _ref18, _fn7, _ref19, _fn8, _ref20, _fn9, _fn10, _classPrivateFieldLoo3, _ref21, _fn11, _ref22, _fn12, _ref23, _ref24, _fn13, _ref25, _fn14, _classPrivateFieldLoo4, _ref26, _fn15, _ref27, _fn16, _ref28; const o = { Foo: Foo @@ -36,17 +40,33 @@ class Foo { (_ref4 = (_o6 = o) === null || _o6 === void 0 ? void 0 : _classPrivateFieldLooseBase(_o6.Foo, _self)[_self]) === null || _ref4 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref4.self, _x)[_x]; (_ref5 = (_o7 = o) === null || _o7 === void 0 ? void 0 : _classPrivateFieldLooseBase(_o7.Foo, _self)[_self].self) === null || _ref5 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref5.self, _x)[_x]; (_ref6 = ((_o8 = o) === null || _o8 === void 0 ? void 0 : _classPrivateFieldLooseBase(_o8.Foo, _self)[_self])?.self) === null || _ref6 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref6.self, _x)[_x]; + (_o9 = o) === null || _o9 === void 0 ? void 0 : _classPrivateFieldLooseBase(_classPrivateFieldLooseBase(_o9.Foo, _self)[_self].getSelf(), _x)[_x]; + (_ref7 = (_o10 = o) === null || _o10 === void 0 ? void 0 : (_classPrivateFieldLoo = _classPrivateFieldLooseBase(_o10.Foo, _self)[_self]).getSelf) === null || _ref7 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref7.call(_classPrivateFieldLoo), _x)[_x]; + (_ref8 = (_o11 = o) === null || _o11 === void 0 ? void 0 : _classPrivateFieldLooseBase(_o11.Foo, _self)[_self]) === null || _ref8 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref8.getSelf(), _x)[_x]; + (_ref9 = (_ref10 = (_o12 = o) === null || _o12 === void 0 ? void 0 : _classPrivateFieldLooseBase(_o12.Foo, _self)[_self])?.getSelf) === null || _ref9 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref9.call(_ref10), _x)[_x]; + (_ref11 = (_o13 = o) === null || _o13 === void 0 ? void 0 : _classPrivateFieldLooseBase(_o13.Foo, _self)[_self].getSelf()) === null || _ref11 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref11.self, _x)[_x]; + (_ref12 = ((_o14 = o) === null || _o14 === void 0 ? void 0 : (_classPrivateFieldLoo2 = _classPrivateFieldLooseBase(_o14.Foo, _self)[_self]).getSelf)?.call(_classPrivateFieldLoo2)) === null || _ref12 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref12.self, _x)[_x]; + (_ref13 = ((_o15 = o) === null || _o15 === void 0 ? void 0 : _classPrivateFieldLooseBase(_o15.Foo, _self)[_self])?.getSelf()) === null || _ref13 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref13.self, _x)[_x]; + (_ref14 = ((_o16 = o) === null || _o16 === void 0 ? void 0 : _classPrivateFieldLooseBase(_o16.Foo, _self)[_self])?.getSelf?.()) === null || _ref14 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref14.self, _x)[_x]; (_fn = fn) === null || _fn === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn().Foo, _x)[_x]; (_fn2 = fn) === null || _fn2 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn2().Foo, _x)[_x].toString; (_fn3 = fn) === null || _fn3 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn3().Foo, _x)[_x].toString(); - (_ref7 = fnDeep?.().very.o) === null || _ref7 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref7.Foo, _x)[_x]; - (_ref8 = fnDeep?.().very.o) === null || _ref8 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref8.Foo, _x)[_x].toString; - (_ref9 = fnDeep?.().very.o) === null || _ref9 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref9.Foo, _x)[_x].toString(); + (_ref15 = fnDeep?.().very.o) === null || _ref15 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref15.Foo, _x)[_x]; + (_ref16 = fnDeep?.().very.o) === null || _ref16 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref16.Foo, _x)[_x].toString; + (_ref17 = fnDeep?.().very.o) === null || _ref17 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref17.Foo, _x)[_x].toString(); (_fn4 = fn) === null || _fn4 === void 0 ? void 0 : _classPrivateFieldLooseBase(_classPrivateFieldLooseBase(_fn4().Foo, _self)[_self], _x)[_x]; (_fn5 = fn) === null || _fn5 === void 0 ? void 0 : _classPrivateFieldLooseBase(_classPrivateFieldLooseBase(_fn5().Foo, _self)[_self].self, _x)[_x]; - (_ref10 = (_fn6 = fn) === null || _fn6 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn6().Foo, _self)[_self]) === null || _ref10 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref10.self, _x)[_x]; - (_ref11 = (_fn7 = fn) === null || _fn7 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn7().Foo, _self)[_self].self) === null || _ref11 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref11.self, _x)[_x]; - (_ref12 = ((_fn8 = fn) === null || _fn8 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn8().Foo, _self)[_self])?.self) === null || _ref12 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref12.self, _x)[_x]; + (_ref18 = (_fn6 = fn) === null || _fn6 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn6().Foo, _self)[_self]) === null || _ref18 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref18.self, _x)[_x]; + (_ref19 = (_fn7 = fn) === null || _fn7 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn7().Foo, _self)[_self].self) === null || _ref19 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref19.self, _x)[_x]; + (_ref20 = ((_fn8 = fn) === null || _fn8 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn8().Foo, _self)[_self])?.self) === null || _ref20 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref20.self, _x)[_x]; + (_fn9 = fn) === null || _fn9 === void 0 ? void 0 : _classPrivateFieldLooseBase(_classPrivateFieldLooseBase(_fn9().Foo, _self)[_self].getSelf(), _x)[_x]; + (_ref21 = (_fn10 = fn) === null || _fn10 === void 0 ? void 0 : (_classPrivateFieldLoo3 = _classPrivateFieldLooseBase(_fn10().Foo, _self)[_self]).getSelf) === null || _ref21 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref21.call(_classPrivateFieldLoo3), _x)[_x]; + (_ref22 = (_fn11 = fn) === null || _fn11 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn11().Foo, _self)[_self]) === null || _ref22 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref22.getSelf(), _x)[_x]; + (_ref23 = (_ref24 = (_fn12 = fn) === null || _fn12 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn12().Foo, _self)[_self])?.getSelf) === null || _ref23 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref23.call(_ref24), _x)[_x]; + (_ref25 = (_fn13 = fn) === null || _fn13 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn13().Foo, _self)[_self].getSelf()) === null || _ref25 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref25.self, _x)[_x]; + (_ref26 = ((_fn14 = fn) === null || _fn14 === void 0 ? void 0 : (_classPrivateFieldLoo4 = _classPrivateFieldLooseBase(_fn14().Foo, _self)[_self]).getSelf)?.call(_classPrivateFieldLoo4)) === null || _ref26 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref26.self, _x)[_x]; + (_ref27 = ((_fn15 = fn) === null || _fn15 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn15().Foo, _self)[_self])?.getSelf()) === null || _ref27 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref27.self, _x)[_x]; + (_ref28 = ((_fn16 = fn) === null || _fn16 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn16().Foo, _self)[_self])?.getSelf?.()) === null || _ref28 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref28.self, _x)[_x]; } } diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-private-call-with-transform/exec.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-private-call-with-transform/exec.js new file mode 100644 index 000000000000..13cc95662d95 --- /dev/null +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-private-call-with-transform/exec.js @@ -0,0 +1,122 @@ +class Foo { + static #x = 1; + static #m = function() { return this.#x; }; + static #self = Foo; + static self = Foo; + static getSelf() { return this } + + static test() { + const o = { Foo: Foo }; + const deep = { very: { o } }; + function fn() { + return o; + } + function fnDeep() { + return deep; + } + + expect(o?.Foo.#m()).toEqual(1); + expect(o?.Foo.#m().toString).toEqual(1..toString); + expect(o?.Foo.#m().toString()).toEqual('1'); + + expect(deep?.very.o?.Foo.#m()).toEqual(1); + expect(deep?.very.o?.Foo.#m().toString).toEqual(1..toString); + expect(deep?.very.o?.Foo.#m().toString()).toEqual('1'); + + expect(o?.Foo.#self.#m()).toEqual(1); + expect(o?.Foo.#self.self.#m()).toEqual(1); + expect(o?.Foo.#self?.self.#m()).toEqual(1); + expect(o?.Foo.#self.self?.self.#m()).toEqual(1); + expect(o?.Foo.#self?.self?.self.#m()).toEqual(1); + + expect(o?.Foo.#self.getSelf().#m()).toEqual(1); + expect(o?.Foo.#self.getSelf?.().#m()).toEqual(1); + expect(o?.Foo.#self?.getSelf().#m()).toEqual(1); + expect(o?.Foo.#self?.getSelf?.().#m()).toEqual(1); + expect(o?.Foo.#self.getSelf()?.self.#m()).toEqual(1); + expect(o?.Foo.#self.getSelf?.()?.self.#m()).toEqual(1); + expect(o?.Foo.#self?.getSelf()?.self.#m()).toEqual(1); + expect(o?.Foo.#self?.getSelf?.()?.self.#m()).toEqual(1); + + expect(fn?.().Foo.#m()).toEqual(1); + expect(fn?.().Foo.#m().toString).toEqual(1..toString); + expect(fn?.().Foo.#m().toString()).toEqual('1'); + + expect(fnDeep?.().very.o?.Foo.#m()).toEqual(1); + expect(fnDeep?.().very.o?.Foo.#m().toString).toEqual(1..toString); + expect(fnDeep?.().very.o?.Foo.#m().toString()).toEqual('1'); + + expect(fn?.().Foo.#self.#m()).toEqual(1); + expect(fn?.().Foo.#self.self.#m()).toEqual(1); + expect(fn?.().Foo.#self?.self.#m()).toEqual(1); + expect(fn?.().Foo.#self.self?.self.#m()).toEqual(1); + expect(fn?.().Foo.#self?.self?.self.#m()).toEqual(1); + + expect(fn?.().Foo.#self.getSelf().#m()).toEqual(1); + expect(fn?.().Foo.#self.getSelf?.().#m()).toEqual(1); + expect(fn?.().Foo.#self?.getSelf().#m()).toEqual(1); + expect(fn?.().Foo.#self?.getSelf?.().#m()).toEqual(1); + expect(fn?.().Foo.#self.getSelf()?.self.#m()).toEqual(1); + expect(fn?.().Foo.#self.getSelf?.()?.self.#m()).toEqual(1); + expect(fn?.().Foo.#self?.getSelf()?.self.#m()).toEqual(1); + expect(fn?.().Foo.#self?.getSelf?.()?.self.#m()).toEqual(1); + } + + static testNull() { + const o = null;; + const deep = { very: { o } }; + const fn = null; + function fnDeep() { + return deep; + } + + expect(o?.Foo.#m()).toEqual(undefined); + expect(o?.Foo.#m().toString).toEqual(undefined); + expect(o?.Foo.#m().toString()).toEqual(undefined); + + expect(deep?.very.o?.Foo.#m()).toEqual(undefined); + expect(deep?.very.o?.Foo.#m().toString).toEqual(undefined); + expect(deep?.very.o?.Foo.#m().toString()).toEqual(undefined); + + expect(o?.Foo.#self.#m()).toEqual(undefined); + expect(o?.Foo.#self.self.#m()).toEqual(undefined); + expect(o?.Foo.#self?.self.#m()).toEqual(undefined); + expect(o?.Foo.#self.self?.self.#m()).toEqual(undefined); + expect(o?.Foo.#self?.self?.self.#m()).toEqual(undefined); + + expect(o?.Foo.#self.getSelf().#m()).toEqual(undefined); + expect(o?.Foo.#self.getSelf?.().#m()).toEqual(undefined); + expect(o?.Foo.#self?.getSelf().#m()).toEqual(undefined); + expect(o?.Foo.#self?.getSelf?.().#m()).toEqual(undefined); + expect(o?.Foo.#self.getSelf()?.self.#m()).toEqual(undefined); + expect(o?.Foo.#self.getSelf?.()?.self.#m()).toEqual(undefined); + expect(o?.Foo.#self?.getSelf()?.self.#m()).toEqual(undefined); + expect(o?.Foo.#self?.getSelf?.()?.self.#m()).toEqual(undefined); + + expect(fn?.().Foo.#m()).toEqual(undefined); + expect(fn?.().Foo.#m().toString).toEqual(undefined); + expect(fn?.().Foo.#m().toString()).toEqual(undefined); + + expect(fnDeep?.().very.o?.Foo.#m()).toEqual(undefined); + expect(fnDeep?.().very.o?.Foo.#m().toString).toEqual(undefined); + expect(fnDeep?.().very.o?.Foo.#m().toString()).toEqual(undefined); + + expect(fn?.().Foo.#self.#m()).toEqual(undefined); + expect(fn?.().Foo.#self.self.#m()).toEqual(undefined); + expect(fn?.().Foo.#self?.self.#m()).toEqual(undefined); + expect(fn?.().Foo.#self.self?.self.#m()).toEqual(undefined); + expect(fn?.().Foo.#self?.self?.self.#m()).toEqual(undefined); + + expect(fn?.().Foo.#self.getSelf().#m()).toEqual(undefined); + expect(fn?.().Foo.#self.getSelf?.().#m()).toEqual(undefined); + expect(fn?.().Foo.#self?.getSelf().#m()).toEqual(undefined); + expect(fn?.().Foo.#self?.getSelf?.().#m()).toEqual(undefined); + expect(fn?.().Foo.#self.getSelf()?.self.#m()).toEqual(undefined); + expect(fn?.().Foo.#self.getSelf?.()?.self.#m()).toEqual(undefined); + expect(fn?.().Foo.#self?.getSelf()?.self.#m()).toEqual(undefined); + expect(fn?.().Foo.#self?.getSelf?.()?.self.#m()).toEqual(undefined); + } +} + +Foo.test(); +Foo.testNull(); diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-private-call-with-transform/input.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-private-call-with-transform/input.js new file mode 100644 index 000000000000..d29585b51d60 --- /dev/null +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-private-call-with-transform/input.js @@ -0,0 +1,66 @@ +class Foo { + static #x = 1; + static #m = function() { return this.#x; }; + static #self = Foo; + static self = Foo; + static getSelf() { return this } + + static test() { + const o = { Foo: Foo }; + const deep = { very: { o } }; + function fn() { + return o; + } + function fnDeep() { + return deep; + } + + o?.Foo.#m(); + o?.Foo.#m().toString; + o?.Foo.#m().toString(); + + deep?.very.o?.Foo.#m(); + deep?.very.o?.Foo.#m().toString; + deep?.very.o?.Foo.#m().toString(); + + o?.Foo.#self.#m(); + o?.Foo.#self.self.#m(); + o?.Foo.#self?.self.#m(); + o?.Foo.#self.self?.self.#m(); + o?.Foo.#self?.self?.self.#m(); + + o?.Foo.#self.getSelf().#m(); + o?.Foo.#self.getSelf?.().#m(); + o?.Foo.#self?.getSelf().#m(); + o?.Foo.#self?.getSelf?.().#m(); + o?.Foo.#self.getSelf()?.self.#m(); + o?.Foo.#self.getSelf?.()?.self.#m(); + o?.Foo.#self?.getSelf()?.self.#m(); + o?.Foo.#self?.getSelf?.()?.self.#m(); + + fn?.().Foo.#m(); + fn?.().Foo.#m().toString; + fn?.().Foo.#m().toString(); + + fnDeep?.().very.o?.Foo.#m(); + fnDeep?.().very.o?.Foo.#m().toString; + fnDeep?.().very.o?.Foo.#m().toString(); + + fn?.().Foo.#self.#m(); + fn?.().Foo.#self.self.#m(); + fn?.().Foo.#self?.self.#m(); + fn?.().Foo.#self.self?.self.#m(); + fn?.().Foo.#self?.self?.self.#m(); + + fn?.().Foo.#self.getSelf().#m(); + fn?.().Foo.#self.getSelf?.().#m(); + fn?.().Foo.#self?.getSelf().#m(); + fn?.().Foo.#self?.getSelf?.().#m(); + fn?.().Foo.#self.getSelf()?.self.#m(); + fn?.().Foo.#self.getSelf?.()?.self.#m(); + fn?.().Foo.#self?.getSelf()?.self.#m(); + fn?.().Foo.#self?.getSelf?.()?.self.#m(); + } +} + +Foo.test(); diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-with-transform/optional-chain-with-transform/options.json b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-private-call-with-transform/options.json similarity index 100% rename from packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-with-transform/optional-chain-with-transform/options.json rename to packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-private-call-with-transform/options.json diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-private-call-with-transform/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-private-call-with-transform/output.js new file mode 100644 index 000000000000..89940c546c35 --- /dev/null +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-private-call-with-transform/output.js @@ -0,0 +1,89 @@ +function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } + +function _classStaticPrivateFieldSpecGet(receiver, classConstructor, descriptor) { if (receiver !== classConstructor) { throw new TypeError("Private static access of wrong provenance"); } if (descriptor.get) { return descriptor.get.call(receiver); } return descriptor.value; } + +class Foo { + static getSelf() { + return this; + } + + static test() { + var _o, _o$Foo, _o2, _o2$Foo, _o3, _o3$Foo, _ref, _ref$Foo, _ref2, _ref2$Foo, _ref3, _ref3$Foo, _o4, _classStaticPrivateFi, _o5, _classStaticPrivateFi2, _o6, _ref4, _ref4$self, _o7, _ref5, _ref5$self, _o8, _ref6, _ref6$self, _o9, _classStaticPrivateFi3, _o10, _classStaticPrivateFi4, _ref7, _ref8, _o11, _ref9, _ref10, _o12, _ref11, _ref12, _ref11$call, _o13, _ref13, _ref13$self, _o14, _classStaticPrivateFi5, _ref14, _ref14$self, _o15, _ref15, _ref15$self, _o16, _ref16, _ref16$self, _fn, _ref17, _fn2, _ref18, _fn3, _ref19, _ref20, _ref20$Foo, _ref21, _ref21$Foo, _ref22, _ref22$Foo, _fn4, _classStaticPrivateFi6, _fn5, _classStaticPrivateFi7, _fn6, _ref23, _ref23$self, _fn7, _ref24, _ref24$self, _fn8, _ref25, _ref25$self, _fn9, _classStaticPrivateFi8, _fn10, _classStaticPrivateFi9, _ref26, _ref27, _fn11, _ref28, _ref29, _fn12, _ref30, _ref31, _ref30$call, _fn13, _ref32, _ref32$self, _fn14, _classStaticPrivateFi10, _ref33, _ref33$self, _fn15, _ref34, _ref34$self, _fn16, _ref35, _ref35$self, _ref36, _ref37, _ref38, _ref39, _ref40, _ref40$getSelf, _ref41, _ref42, _ref43, _ref44, _ref45, _ref45$getSelf; + + const o = { + Foo: Foo + }; + const deep = { + very: { + o + } + }; + + function fn() { + return o; + } + + function fnDeep() { + return deep; + } + + (_o = o) === null || _o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o$Foo = _o.Foo, Foo, _m).call(_o$Foo); + (_o2 = o) === null || _o2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o2$Foo = _o2.Foo, Foo, _m).call(_o2$Foo).toString; + (_o3 = o) === null || _o3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o3$Foo = _o3.Foo, Foo, _m).call(_o3$Foo).toString(); + (_ref = deep === null || deep === void 0 ? void 0 : deep.very.o) === null || _ref === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref$Foo = _ref.Foo, Foo, _m).call(_ref$Foo); + (_ref2 = deep === null || deep === void 0 ? void 0 : deep.very.o) === null || _ref2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref2$Foo = _ref2.Foo, Foo, _m).call(_ref2$Foo).toString; + (_ref3 = deep === null || deep === void 0 ? void 0 : deep.very.o) === null || _ref3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref3$Foo = _ref3.Foo, Foo, _m).call(_ref3$Foo).toString(); + (_o4 = o) === null || _o4 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFi = _classStaticPrivateFieldSpecGet(_o4.Foo, Foo, _self), Foo, _m).call(_classStaticPrivateFi); + (_o5 = o) === null || _o5 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFi2 = _classStaticPrivateFieldSpecGet(_o5.Foo, Foo, _self).self, Foo, _m).call(_classStaticPrivateFi2); + (_ref4 = (_o6 = o) === null || _o6 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o6.Foo, Foo, _self)) === null || _ref4 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref4$self = _ref4.self, Foo, _m).call(_ref4$self); + (_ref5 = (_o7 = o) === null || _o7 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o7.Foo, Foo, _self).self) === null || _ref5 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref5$self = _ref5.self, Foo, _m).call(_ref5$self); + (_ref6 = (_ref36 = (_o8 = o) === null || _o8 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o8.Foo, Foo, _self)) === null || _ref36 === void 0 ? void 0 : _ref36.self) === null || _ref6 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref6$self = _ref6.self, Foo, _m).call(_ref6$self); + (_o9 = o) === null || _o9 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFi3 = _classStaticPrivateFieldSpecGet(_o9.Foo, Foo, _self).getSelf(), Foo, _m).call(_classStaticPrivateFi3); + (_ref7 = (_o10 = o) === null || _o10 === void 0 ? void 0 : (_classStaticPrivateFi4 = _classStaticPrivateFieldSpecGet(_o10.Foo, Foo, _self)).getSelf) === null || _ref7 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref8 = _ref7.call(_classStaticPrivateFi4), Foo, _m).call(_ref8); + (_ref9 = (_o11 = o) === null || _o11 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o11.Foo, Foo, _self)) === null || _ref9 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref10 = _ref9.getSelf(), Foo, _m).call(_ref10); + (_ref11 = (_ref37 = _ref12 = (_o12 = o) === null || _o12 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o12.Foo, Foo, _self)) === null || _ref37 === void 0 ? void 0 : _ref37.getSelf) === null || _ref11 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref11$call = _ref11.call(_ref12), Foo, _m).call(_ref11$call); + (_ref13 = (_o13 = o) === null || _o13 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o13.Foo, Foo, _self).getSelf()) === null || _ref13 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref13$self = _ref13.self, Foo, _m).call(_ref13$self); + (_ref14 = (_ref38 = (_o14 = o) === null || _o14 === void 0 ? void 0 : (_classStaticPrivateFi5 = _classStaticPrivateFieldSpecGet(_o14.Foo, Foo, _self)).getSelf) === null || _ref38 === void 0 ? void 0 : _ref38.call(_classStaticPrivateFi5)) === null || _ref14 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref14$self = _ref14.self, Foo, _m).call(_ref14$self); + (_ref15 = (_ref39 = (_o15 = o) === null || _o15 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o15.Foo, Foo, _self)) === null || _ref39 === void 0 ? void 0 : _ref39.getSelf()) === null || _ref15 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref15$self = _ref15.self, Foo, _m).call(_ref15$self); + (_ref16 = (_ref40 = (_o16 = o) === null || _o16 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o16.Foo, Foo, _self)) === null || _ref40 === void 0 ? void 0 : (_ref40$getSelf = _ref40.getSelf) === null || _ref40$getSelf === void 0 ? void 0 : _ref40$getSelf.call(_ref40)) === null || _ref16 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref16$self = _ref16.self, Foo, _m).call(_ref16$self); + (_fn = fn) === null || _fn === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref17 = _fn().Foo, Foo, _m).call(_ref17); + (_fn2 = fn) === null || _fn2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref18 = _fn2().Foo, Foo, _m).call(_ref18).toString; + (_fn3 = fn) === null || _fn3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref19 = _fn3().Foo, Foo, _m).call(_ref19).toString(); + (_ref20 = fnDeep === null || fnDeep === void 0 ? void 0 : fnDeep().very.o) === null || _ref20 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref20$Foo = _ref20.Foo, Foo, _m).call(_ref20$Foo); + (_ref21 = fnDeep === null || fnDeep === void 0 ? void 0 : fnDeep().very.o) === null || _ref21 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref21$Foo = _ref21.Foo, Foo, _m).call(_ref21$Foo).toString; + (_ref22 = fnDeep === null || fnDeep === void 0 ? void 0 : fnDeep().very.o) === null || _ref22 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref22$Foo = _ref22.Foo, Foo, _m).call(_ref22$Foo).toString(); + (_fn4 = fn) === null || _fn4 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFi6 = _classStaticPrivateFieldSpecGet(_fn4().Foo, Foo, _self), Foo, _m).call(_classStaticPrivateFi6); + (_fn5 = fn) === null || _fn5 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFi7 = _classStaticPrivateFieldSpecGet(_fn5().Foo, Foo, _self).self, Foo, _m).call(_classStaticPrivateFi7); + (_ref23 = (_fn6 = fn) === null || _fn6 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn6().Foo, Foo, _self)) === null || _ref23 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref23$self = _ref23.self, Foo, _m).call(_ref23$self); + (_ref24 = (_fn7 = fn) === null || _fn7 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn7().Foo, Foo, _self).self) === null || _ref24 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref24$self = _ref24.self, Foo, _m).call(_ref24$self); + (_ref25 = (_ref41 = (_fn8 = fn) === null || _fn8 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn8().Foo, Foo, _self)) === null || _ref41 === void 0 ? void 0 : _ref41.self) === null || _ref25 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref25$self = _ref25.self, Foo, _m).call(_ref25$self); + (_fn9 = fn) === null || _fn9 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFi8 = _classStaticPrivateFieldSpecGet(_fn9().Foo, Foo, _self).getSelf(), Foo, _m).call(_classStaticPrivateFi8); + (_ref26 = (_fn10 = fn) === null || _fn10 === void 0 ? void 0 : (_classStaticPrivateFi9 = _classStaticPrivateFieldSpecGet(_fn10().Foo, Foo, _self)).getSelf) === null || _ref26 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref27 = _ref26.call(_classStaticPrivateFi9), Foo, _m).call(_ref27); + (_ref28 = (_fn11 = fn) === null || _fn11 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn11().Foo, Foo, _self)) === null || _ref28 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref29 = _ref28.getSelf(), Foo, _m).call(_ref29); + (_ref30 = (_ref42 = _ref31 = (_fn12 = fn) === null || _fn12 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn12().Foo, Foo, _self)) === null || _ref42 === void 0 ? void 0 : _ref42.getSelf) === null || _ref30 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref30$call = _ref30.call(_ref31), Foo, _m).call(_ref30$call); + (_ref32 = (_fn13 = fn) === null || _fn13 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn13().Foo, Foo, _self).getSelf()) === null || _ref32 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref32$self = _ref32.self, Foo, _m).call(_ref32$self); + (_ref33 = (_ref43 = (_fn14 = fn) === null || _fn14 === void 0 ? void 0 : (_classStaticPrivateFi10 = _classStaticPrivateFieldSpecGet(_fn14().Foo, Foo, _self)).getSelf) === null || _ref43 === void 0 ? void 0 : _ref43.call(_classStaticPrivateFi10)) === null || _ref33 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref33$self = _ref33.self, Foo, _m).call(_ref33$self); + (_ref34 = (_ref44 = (_fn15 = fn) === null || _fn15 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn15().Foo, Foo, _self)) === null || _ref44 === void 0 ? void 0 : _ref44.getSelf()) === null || _ref34 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref34$self = _ref34.self, Foo, _m).call(_ref34$self); + (_ref35 = (_ref45 = (_fn16 = fn) === null || _fn16 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn16().Foo, Foo, _self)) === null || _ref45 === void 0 ? void 0 : (_ref45$getSelf = _ref45.getSelf) === null || _ref45$getSelf === void 0 ? void 0 : _ref45$getSelf.call(_ref45)) === null || _ref35 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref35$self = _ref35.self, Foo, _m).call(_ref35$self); + } + +} + +var _x = { + writable: true, + value: 1 +}; +var _m = { + writable: true, + value: function () { + return _classStaticPrivateFieldSpecGet(this, Foo, _x); + } +}; +var _self = { + writable: true, + value: Foo +}; + +_defineProperty(Foo, "self", Foo); + +Foo.test(); diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-private-call/input.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-private-call/input.js index 8829ac1dc0de..d29585b51d60 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-private-call/input.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-private-call/input.js @@ -15,51 +15,51 @@ class Foo { return deep; } - // o?.Foo.#m(); - // o?.Foo.#m().toString; - // o?.Foo.#m().toString(); + o?.Foo.#m(); + o?.Foo.#m().toString; + o?.Foo.#m().toString(); - // deep?.very.o?.Foo.#m(); - // deep?.very.o?.Foo.#m().toString; - // deep?.very.o?.Foo.#m().toString(); + deep?.very.o?.Foo.#m(); + deep?.very.o?.Foo.#m().toString; + deep?.very.o?.Foo.#m().toString(); o?.Foo.#self.#m(); - // o?.Foo.#self.self.#m(); - // o?.Foo.#self?.self.#m(); - // o?.Foo.#self.self?.self.#m(); - // o?.Foo.#self?.self?.self.#m(); + o?.Foo.#self.self.#m(); + o?.Foo.#self?.self.#m(); + o?.Foo.#self.self?.self.#m(); + o?.Foo.#self?.self?.self.#m(); - // o?.Foo.#self.getSelf().#m(); - // o?.Foo.#self.getSelf?.().#m(); - // o?.Foo.#self?.getSelf().#m(); - // o?.Foo.#self?.getSelf?.().#m(); - // o?.Foo.#self.getSelf()?.self.#m(); - // o?.Foo.#self.getSelf?.()?.self.#m(); - // o?.Foo.#self?.getSelf()?.self.#m(); - // o?.Foo.#self?.getSelf?.()?.self.#m(); + o?.Foo.#self.getSelf().#m(); + o?.Foo.#self.getSelf?.().#m(); + o?.Foo.#self?.getSelf().#m(); + o?.Foo.#self?.getSelf?.().#m(); + o?.Foo.#self.getSelf()?.self.#m(); + o?.Foo.#self.getSelf?.()?.self.#m(); + o?.Foo.#self?.getSelf()?.self.#m(); + o?.Foo.#self?.getSelf?.()?.self.#m(); - // fn?.().Foo.#m(); - // fn?.().Foo.#m().toString; - // fn?.().Foo.#m().toString(); + fn?.().Foo.#m(); + fn?.().Foo.#m().toString; + fn?.().Foo.#m().toString(); - // fnDeep?.().very.o?.Foo.#m(); - // fnDeep?.().very.o?.Foo.#m().toString; - // fnDeep?.().very.o?.Foo.#m().toString(); + fnDeep?.().very.o?.Foo.#m(); + fnDeep?.().very.o?.Foo.#m().toString; + fnDeep?.().very.o?.Foo.#m().toString(); - // fn?.().Foo.#self.#m(); - // fn?.().Foo.#self.self.#m(); - // fn?.().Foo.#self?.self.#m(); - // fn?.().Foo.#self.self?.self.#m(); - // fn?.().Foo.#self?.self?.self.#m(); + fn?.().Foo.#self.#m(); + fn?.().Foo.#self.self.#m(); + fn?.().Foo.#self?.self.#m(); + fn?.().Foo.#self.self?.self.#m(); + fn?.().Foo.#self?.self?.self.#m(); - // fn?.().Foo.#self.getSelf().#m(); - // fn?.().Foo.#self.getSelf?.().#m(); - // fn?.().Foo.#self?.getSelf().#m(); - // fn?.().Foo.#self?.getSelf?.().#m(); - // fn?.().Foo.#self.getSelf()?.self.#m(); - // fn?.().Foo.#self.getSelf?.()?.self.#m(); - // fn?.().Foo.#self?.getSelf()?.self.#m(); - // fn?.().Foo.#self?.getSelf?.()?.self.#m(); + fn?.().Foo.#self.getSelf().#m(); + fn?.().Foo.#self.getSelf?.().#m(); + fn?.().Foo.#self?.getSelf().#m(); + fn?.().Foo.#self?.getSelf?.().#m(); + fn?.().Foo.#self.getSelf()?.self.#m(); + fn?.().Foo.#self.getSelf?.()?.self.#m(); + fn?.().Foo.#self?.getSelf()?.self.#m(); + fn?.().Foo.#self?.getSelf?.()?.self.#m(); } } diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-private-call/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-private-call/output.js index 0f4cf2619717..8889372935c9 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-private-call/output.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-private-call/output.js @@ -3,8 +3,12 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope function _classStaticPrivateFieldSpecGet(receiver, classConstructor, descriptor) { if (receiver !== classConstructor) { throw new TypeError("Private static access of wrong provenance"); } if (descriptor.get) { return descriptor.get.call(receiver); } return descriptor.value; } class Foo { + static getSelf() { + return this; + } + static test() { - var _o, _ref, _o2, _ref2, _o3, _ref3, _ref4, _ref5, _ref6, _ref7, _ref8, _ref9, _o4, _ref10, _o5, _ref11, _o6, _ref12, _ref13, _ref14, _o7, _ref15, _ref16, _ref17, _o8, _ref18, _ref19, _ref20, _fn, _ref21, _fn2, _ref22, _fn3, _ref23, _ref24, _ref25, _ref26, _ref27, _ref28, _ref29, _fn4, _ref30, _fn5, _ref31, _fn6, _ref32, _ref33, _ref34, _fn7, _ref35, _ref36, _ref37, _fn8, _ref38, _ref39, _ref40; + var _o, _o$Foo, _o2, _o2$Foo, _o3, _o3$Foo, _ref, _ref$Foo, _ref2, _ref2$Foo, _ref3, _ref3$Foo, _o4, _classStaticPrivateFi, _o5, _classStaticPrivateFi2, _o6, _ref4, _ref4$self, _o7, _ref5, _ref5$self, _o8, _ref6, _ref6$self, _o9, _classStaticPrivateFi3, _o10, _classStaticPrivateFi4, _ref7, _ref8, _o11, _ref9, _ref10, _o12, _ref11, _ref12, _ref11$call, _o13, _ref13, _ref13$self, _o14, _classStaticPrivateFi5, _ref14, _ref14$self, _o15, _ref15, _ref15$self, _o16, _ref16, _ref16$self, _fn, _ref17, _fn2, _ref18, _fn3, _ref19, _ref20, _ref20$Foo, _ref21, _ref21$Foo, _ref22, _ref22$Foo, _fn4, _classStaticPrivateFi6, _fn5, _classStaticPrivateFi7, _fn6, _ref23, _ref23$self, _fn7, _ref24, _ref24$self, _fn8, _ref25, _ref25$self, _fn9, _classStaticPrivateFi8, _fn10, _classStaticPrivateFi9, _ref26, _ref27, _fn11, _ref28, _ref29, _fn12, _ref30, _ref31, _ref30$call, _fn13, _ref32, _ref32$self, _fn14, _classStaticPrivateFi10, _ref33, _ref33$self, _fn15, _ref34, _ref34$self, _fn16, _ref35, _ref35$self; const o = { Foo: Foo @@ -23,28 +27,44 @@ class Foo { return deep; } - (_ref = (_o = o)?.Foo, _o === void 0 || _o === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref, Foo, _x); - (_ref2 = (_o2 = o)?.Foo, _o2 === void 0 || _o2 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref2, Foo, _x).toString; - (_ref3 = (_o3 = o)?.Foo, _o3 === void 0 || _o3 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref3, Foo, _x).toString(); - (_ref5 = (_ref4 = deep?.very.o)?.Foo, _ref4 === void 0 || _ref4 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref5, Foo, _x); - (_ref7 = (_ref6 = deep?.very.o)?.Foo, _ref6 === void 0 || _ref6 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref7, Foo, _x).toString; - (_ref9 = (_ref8 = deep?.very.o)?.Foo, _ref8 === void 0 || _ref8 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref9, Foo, _x).toString(); - (_ref10 = (_o4 = o)?.Foo, _o4 === void 0 || _o4 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFieldSpecGet(_ref10, Foo, _self), Foo, _x); - (_ref11 = (_o5 = o)?.Foo, _o5 === void 0 || _o5 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFieldSpecGet(_ref11, Foo, _self).self, Foo, _x); - (_ref14 = (_ref13 = (_ref12 = (_o6 = o)?.Foo, _o6 === void 0 || _o6 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref12, Foo, _self))?.self, _ref13 === void 0 || _ref13 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref14, Foo, _x); - (_ref17 = (_ref16 = (_ref15 = (_o7 = o)?.Foo, _o7 === void 0 || _o7 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref15, Foo, _self).self)?.self, _ref16 === void 0 || _ref16 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref17, Foo, _x); - (_ref20 = (_ref19 = ((_ref18 = (_o8 = o)?.Foo, _o8 === void 0 || _o8 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref18, Foo, _self))?.self)?.self, _ref19 === void 0 || _ref19 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref20, Foo, _x); - (_ref21 = (_fn = fn)?.().Foo, _fn === void 0 || _fn === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref21, Foo, _x); - (_ref22 = (_fn2 = fn)?.().Foo, _fn2 === void 0 || _fn2 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref22, Foo, _x).toString; - (_ref23 = (_fn3 = fn)?.().Foo, _fn3 === void 0 || _fn3 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref23, Foo, _x).toString(); - (_ref25 = (_ref24 = fnDeep?.().very.o)?.Foo, _ref24 === void 0 || _ref24 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref25, Foo, _x); - (_ref27 = (_ref26 = fnDeep?.().very.o)?.Foo, _ref26 === void 0 || _ref26 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref27, Foo, _x).toString; - (_ref29 = (_ref28 = fnDeep?.().very.o)?.Foo, _ref28 === void 0 || _ref28 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref29, Foo, _x).toString(); - (_ref30 = (_fn4 = fn)?.().Foo, _fn4 === void 0 || _fn4 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFieldSpecGet(_ref30, Foo, _self), Foo, _x); - (_ref31 = (_fn5 = fn)?.().Foo, _fn5 === void 0 || _fn5 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFieldSpecGet(_ref31, Foo, _self).self, Foo, _x); - (_ref34 = (_ref33 = (_ref32 = (_fn6 = fn)?.().Foo, _fn6 === void 0 || _fn6 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref32, Foo, _self))?.self, _ref33 === void 0 || _ref33 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref34, Foo, _x); - (_ref37 = (_ref36 = (_ref35 = (_fn7 = fn)?.().Foo, _fn7 === void 0 || _fn7 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref35, Foo, _self).self)?.self, _ref36 === void 0 || _ref36 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref37, Foo, _x); - (_ref40 = (_ref39 = ((_ref38 = (_fn8 = fn)?.().Foo, _fn8 === void 0 || _fn8 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref38, Foo, _self))?.self)?.self, _ref39 === void 0 || _ref39 === null) ? void 0 : _classStaticPrivateFieldSpecGet(_ref40, Foo, _x); + (_o = o) === null || _o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o$Foo = _o.Foo, Foo, _m).call(_o$Foo); + (_o2 = o) === null || _o2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o2$Foo = _o2.Foo, Foo, _m).call(_o2$Foo).toString; + (_o3 = o) === null || _o3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o3$Foo = _o3.Foo, Foo, _m).call(_o3$Foo).toString(); + (_ref = deep?.very.o) === null || _ref === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref$Foo = _ref.Foo, Foo, _m).call(_ref$Foo); + (_ref2 = deep?.very.o) === null || _ref2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref2$Foo = _ref2.Foo, Foo, _m).call(_ref2$Foo).toString; + (_ref3 = deep?.very.o) === null || _ref3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref3$Foo = _ref3.Foo, Foo, _m).call(_ref3$Foo).toString(); + (_o4 = o) === null || _o4 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFi = _classStaticPrivateFieldSpecGet(_o4.Foo, Foo, _self), Foo, _m).call(_classStaticPrivateFi); + (_o5 = o) === null || _o5 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFi2 = _classStaticPrivateFieldSpecGet(_o5.Foo, Foo, _self).self, Foo, _m).call(_classStaticPrivateFi2); + (_ref4 = (_o6 = o) === null || _o6 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o6.Foo, Foo, _self)) === null || _ref4 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref4$self = _ref4.self, Foo, _m).call(_ref4$self); + (_ref5 = (_o7 = o) === null || _o7 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o7.Foo, Foo, _self).self) === null || _ref5 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref5$self = _ref5.self, Foo, _m).call(_ref5$self); + (_ref6 = ((_o8 = o) === null || _o8 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o8.Foo, Foo, _self))?.self) === null || _ref6 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref6$self = _ref6.self, Foo, _m).call(_ref6$self); + (_o9 = o) === null || _o9 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFi3 = _classStaticPrivateFieldSpecGet(_o9.Foo, Foo, _self).getSelf(), Foo, _m).call(_classStaticPrivateFi3); + (_ref7 = (_o10 = o) === null || _o10 === void 0 ? void 0 : (_classStaticPrivateFi4 = _classStaticPrivateFieldSpecGet(_o10.Foo, Foo, _self)).getSelf) === null || _ref7 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref8 = _ref7.call(_classStaticPrivateFi4), Foo, _m).call(_ref8); + (_ref9 = (_o11 = o) === null || _o11 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o11.Foo, Foo, _self)) === null || _ref9 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref10 = _ref9.getSelf(), Foo, _m).call(_ref10); + (_ref11 = (_ref12 = (_o12 = o) === null || _o12 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o12.Foo, Foo, _self))?.getSelf) === null || _ref11 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref11$call = _ref11.call(_ref12), Foo, _m).call(_ref11$call); + (_ref13 = (_o13 = o) === null || _o13 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o13.Foo, Foo, _self).getSelf()) === null || _ref13 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref13$self = _ref13.self, Foo, _m).call(_ref13$self); + (_ref14 = ((_o14 = o) === null || _o14 === void 0 ? void 0 : (_classStaticPrivateFi5 = _classStaticPrivateFieldSpecGet(_o14.Foo, Foo, _self)).getSelf)?.call(_classStaticPrivateFi5)) === null || _ref14 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref14$self = _ref14.self, Foo, _m).call(_ref14$self); + (_ref15 = ((_o15 = o) === null || _o15 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o15.Foo, Foo, _self))?.getSelf()) === null || _ref15 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref15$self = _ref15.self, Foo, _m).call(_ref15$self); + (_ref16 = ((_o16 = o) === null || _o16 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o16.Foo, Foo, _self))?.getSelf?.()) === null || _ref16 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref16$self = _ref16.self, Foo, _m).call(_ref16$self); + (_fn = fn) === null || _fn === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref17 = _fn().Foo, Foo, _m).call(_ref17); + (_fn2 = fn) === null || _fn2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref18 = _fn2().Foo, Foo, _m).call(_ref18).toString; + (_fn3 = fn) === null || _fn3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref19 = _fn3().Foo, Foo, _m).call(_ref19).toString(); + (_ref20 = fnDeep?.().very.o) === null || _ref20 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref20$Foo = _ref20.Foo, Foo, _m).call(_ref20$Foo); + (_ref21 = fnDeep?.().very.o) === null || _ref21 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref21$Foo = _ref21.Foo, Foo, _m).call(_ref21$Foo).toString; + (_ref22 = fnDeep?.().very.o) === null || _ref22 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref22$Foo = _ref22.Foo, Foo, _m).call(_ref22$Foo).toString(); + (_fn4 = fn) === null || _fn4 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFi6 = _classStaticPrivateFieldSpecGet(_fn4().Foo, Foo, _self), Foo, _m).call(_classStaticPrivateFi6); + (_fn5 = fn) === null || _fn5 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFi7 = _classStaticPrivateFieldSpecGet(_fn5().Foo, Foo, _self).self, Foo, _m).call(_classStaticPrivateFi7); + (_ref23 = (_fn6 = fn) === null || _fn6 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn6().Foo, Foo, _self)) === null || _ref23 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref23$self = _ref23.self, Foo, _m).call(_ref23$self); + (_ref24 = (_fn7 = fn) === null || _fn7 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn7().Foo, Foo, _self).self) === null || _ref24 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref24$self = _ref24.self, Foo, _m).call(_ref24$self); + (_ref25 = ((_fn8 = fn) === null || _fn8 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn8().Foo, Foo, _self))?.self) === null || _ref25 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref25$self = _ref25.self, Foo, _m).call(_ref25$self); + (_fn9 = fn) === null || _fn9 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFi8 = _classStaticPrivateFieldSpecGet(_fn9().Foo, Foo, _self).getSelf(), Foo, _m).call(_classStaticPrivateFi8); + (_ref26 = (_fn10 = fn) === null || _fn10 === void 0 ? void 0 : (_classStaticPrivateFi9 = _classStaticPrivateFieldSpecGet(_fn10().Foo, Foo, _self)).getSelf) === null || _ref26 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref27 = _ref26.call(_classStaticPrivateFi9), Foo, _m).call(_ref27); + (_ref28 = (_fn11 = fn) === null || _fn11 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn11().Foo, Foo, _self)) === null || _ref28 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref29 = _ref28.getSelf(), Foo, _m).call(_ref29); + (_ref30 = (_ref31 = (_fn12 = fn) === null || _fn12 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn12().Foo, Foo, _self))?.getSelf) === null || _ref30 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref30$call = _ref30.call(_ref31), Foo, _m).call(_ref30$call); + (_ref32 = (_fn13 = fn) === null || _fn13 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn13().Foo, Foo, _self).getSelf()) === null || _ref32 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref32$self = _ref32.self, Foo, _m).call(_ref32$self); + (_ref33 = ((_fn14 = fn) === null || _fn14 === void 0 ? void 0 : (_classStaticPrivateFi10 = _classStaticPrivateFieldSpecGet(_fn14().Foo, Foo, _self)).getSelf)?.call(_classStaticPrivateFi10)) === null || _ref33 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref33$self = _ref33.self, Foo, _m).call(_ref33$self); + (_ref34 = ((_fn15 = fn) === null || _fn15 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn15().Foo, Foo, _self))?.getSelf()) === null || _ref34 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref34$self = _ref34.self, Foo, _m).call(_ref34$self); + (_ref35 = ((_fn16 = fn) === null || _fn16 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn16().Foo, Foo, _self))?.getSelf?.()) === null || _ref35 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref35$self = _ref35.self, Foo, _m).call(_ref35$self); } } @@ -53,6 +73,12 @@ var _x = { writable: true, value: 1 }; +var _m = { + writable: true, + value: function () { + return _classStaticPrivateFieldSpecGet(this, Foo, _x); + } +}; var _self = { writable: true, value: Foo diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-with-transform/exec.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-with-transform/exec.js index fc59ad1a86b9..98ac8e7a7e12 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-with-transform/exec.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-with-transform/exec.js @@ -117,5 +117,5 @@ class Foo { } } -// Foo.test(); +Foo.test(); Foo.testNull(); From 827fd8eabeeb9d6ca80117434b64a5fe63e8e784 Mon Sep 17 00:00:00 2001 From: Justin Ridgewell Date: Sun, 15 Mar 2020 04:43:28 -0400 Subject: [PATCH 06/20] Fix bug with traversing detached node tree --- .../src/index.js | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) 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 258dc53d2554..b7482bcdd46c 100644 --- a/packages/babel-helper-member-expression-to-functions/src/index.js +++ b/packages/babel-helper-member-expression-to-functions/src/index.js @@ -56,6 +56,28 @@ function toNonOptional(path, base) { return path.node; } +// Determines if the current path is in a detached tree. This can happen when +// we are iterating on a path, and replace an ancestor with a new node. Babel +// doesn't always stop traversing the old node tree, and that can cause +// inconsistencies. +function isInDetachedTree(path) { + while (path) { + if (path.isProgram()) break; + + const { parentPath, container, listKey } = path; + const parentNode = parentPath.node; + if (listKey) { + if (container !== parentNode[listKey]) return true; + } else { + if (container !== parentNode) return true; + } + + path = parentPath; + } + + return false; +} + const handle = { memoise() { // noop. @@ -65,6 +87,9 @@ const handle = { const { node, parent, parentPath } = member; if (member.isOptionalMemberExpression()) { + // Transforming optional chaining requires we replace ancestors. + if (isInDetachedTree(member)) return; + // We're looking for the end of _this_ optional chain, which is actually // the "rightmost" property access of the chain. This is because // everything up to that property access is "optional". From e2ae2b43074c82f03db5b0c19e6dc67aca2f17e8 Mon Sep 17 00:00:00 2001 From: Justin Ridgewell Date: Sun, 15 Mar 2020 04:48:42 -0400 Subject: [PATCH 07/20] Update memoized names --- .../output.js | 54 ++++++++--------- .../optional-chain-private-call/output.js | 54 ++++++++--------- .../optional-chain-with-transform/output.js | 54 ++++++++--------- .../private-loose/optional-chain/output.js | 54 ++++++++--------- .../output.js | 60 +++++++++---------- .../optional-chain-private-call/output.js | 60 +++++++++---------- .../optional-chain-with-transform/output.js | 54 ++++++++--------- .../fixtures/private/optional-chain/output.js | 54 ++++++++--------- 8 files changed, 222 insertions(+), 222 deletions(-) diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-private-call-with-transform/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-private-call-with-transform/output.js index 9c70b9bc4b88..081433ff45e9 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-private-call-with-transform/output.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-private-call-with-transform/output.js @@ -10,7 +10,7 @@ class Foo { } static test() { - var _o, _o2, _o3, _ref, _ref2, _ref3, _o4, _o5, _o6, _ref4, _o7, _ref5, _o8, _ref6, _o9, _o10, _classPrivateFieldLoo, _ref7, _o11, _ref8, _o12, _ref9, _ref10, _o13, _ref11, _o14, _classPrivateFieldLoo2, _ref12, _o15, _ref13, _o16, _ref14, _fn, _fn2, _fn3, _ref15, _ref16, _ref17, _fn4, _fn5, _fn6, _ref18, _fn7, _ref19, _fn8, _ref20, _fn9, _fn10, _classPrivateFieldLoo3, _ref21, _fn11, _ref22, _fn12, _ref23, _ref24, _fn13, _ref25, _fn14, _classPrivateFieldLoo4, _ref26, _fn15, _ref27, _fn16, _ref28, _ref29, _ref30, _ref31, _ref32, _ref33, _ref33$getSelf, _ref34, _ref35, _ref36, _ref37, _ref38, _ref38$getSelf; + var _o, _o2, _o3, _deep$very$o, _deep$very$o2, _deep$very$o3, _o4, _o5, _o6, _ref, _o7, _ref2, _o8, _self2, _o9, _o10, _classPrivateFieldLoo, _ref3, _o11, _ref4, _o12, _getSelf, _ref5, _o13, _ref6, _o14, _classPrivateFieldLoo2, _call, _o15, _getSelf2, _o16, _getSelf3, _fn, _fn2, _fn3, _fnDeep$very$o, _fnDeep$very$o2, _fnDeep$very$o3, _fn4, _fn5, _fn6, _ref7, _fn7, _ref8, _fn8, _self3, _fn9, _fn10, _classPrivateFieldLoo3, _ref9, _fn11, _ref10, _fn12, _getSelf4, _ref11, _fn13, _ref12, _fn14, _classPrivateFieldLoo4, _call2, _fn15, _getSelf5, _fn16, _getSelf6, _ref13, _ref14, _ref15, _ref16, _ref17, _ref17$getSelf, _ref18, _ref19, _ref20, _ref21, _ref22, _ref22$getSelf; const o = { Foo: Foo @@ -32,41 +32,41 @@ class Foo { (_o = o) === null || _o === void 0 ? void 0 : _classPrivateFieldLooseBase(_o.Foo, _m)[_m](); (_o2 = o) === null || _o2 === void 0 ? void 0 : _classPrivateFieldLooseBase(_o2.Foo, _m)[_m]().toString; (_o3 = o) === null || _o3 === void 0 ? void 0 : _classPrivateFieldLooseBase(_o3.Foo, _m)[_m]().toString(); - (_ref = deep === null || deep === void 0 ? void 0 : deep.very.o) === null || _ref === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref.Foo, _m)[_m](); - (_ref2 = deep === null || deep === void 0 ? void 0 : deep.very.o) === null || _ref2 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref2.Foo, _m)[_m]().toString; - (_ref3 = deep === null || deep === void 0 ? void 0 : deep.very.o) === null || _ref3 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref3.Foo, _m)[_m]().toString(); + (_deep$very$o = deep === null || deep === void 0 ? void 0 : deep.very.o) === null || _deep$very$o === void 0 ? void 0 : _classPrivateFieldLooseBase(_deep$very$o.Foo, _m)[_m](); + (_deep$very$o2 = deep === null || deep === void 0 ? void 0 : deep.very.o) === null || _deep$very$o2 === void 0 ? void 0 : _classPrivateFieldLooseBase(_deep$very$o2.Foo, _m)[_m]().toString; + (_deep$very$o3 = deep === null || deep === void 0 ? void 0 : deep.very.o) === null || _deep$very$o3 === void 0 ? void 0 : _classPrivateFieldLooseBase(_deep$very$o3.Foo, _m)[_m]().toString(); (_o4 = o) === null || _o4 === void 0 ? void 0 : _classPrivateFieldLooseBase(_classPrivateFieldLooseBase(_o4.Foo, _self)[_self], _m)[_m](); (_o5 = o) === null || _o5 === void 0 ? void 0 : _classPrivateFieldLooseBase(_classPrivateFieldLooseBase(_o5.Foo, _self)[_self].self, _m)[_m](); - (_ref4 = (_o6 = o) === null || _o6 === void 0 ? void 0 : _classPrivateFieldLooseBase(_o6.Foo, _self)[_self]) === null || _ref4 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref4.self, _m)[_m](); - (_ref5 = (_o7 = o) === null || _o7 === void 0 ? void 0 : _classPrivateFieldLooseBase(_o7.Foo, _self)[_self].self) === null || _ref5 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref5.self, _m)[_m](); - (_ref6 = (_ref29 = (_o8 = o) === null || _o8 === void 0 ? void 0 : _classPrivateFieldLooseBase(_o8.Foo, _self)[_self]) === null || _ref29 === void 0 ? void 0 : _ref29.self) === null || _ref6 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref6.self, _m)[_m](); + (_ref = (_o6 = o) === null || _o6 === void 0 ? void 0 : _classPrivateFieldLooseBase(_o6.Foo, _self)[_self]) === null || _ref === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref.self, _m)[_m](); + (_ref2 = (_o7 = o) === null || _o7 === void 0 ? void 0 : _classPrivateFieldLooseBase(_o7.Foo, _self)[_self].self) === null || _ref2 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref2.self, _m)[_m](); + (_self2 = (_ref13 = (_o8 = o) === null || _o8 === void 0 ? void 0 : _classPrivateFieldLooseBase(_o8.Foo, _self)[_self]) === null || _ref13 === void 0 ? void 0 : _ref13.self) === null || _self2 === void 0 ? void 0 : _classPrivateFieldLooseBase(_self2.self, _m)[_m](); (_o9 = o) === null || _o9 === void 0 ? void 0 : _classPrivateFieldLooseBase(_classPrivateFieldLooseBase(_o9.Foo, _self)[_self].getSelf(), _m)[_m](); - (_ref7 = (_o10 = o) === null || _o10 === void 0 ? void 0 : (_classPrivateFieldLoo = _classPrivateFieldLooseBase(_o10.Foo, _self)[_self]).getSelf) === null || _ref7 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref7.call(_classPrivateFieldLoo), _m)[_m](); - (_ref8 = (_o11 = o) === null || _o11 === void 0 ? void 0 : _classPrivateFieldLooseBase(_o11.Foo, _self)[_self]) === null || _ref8 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref8.getSelf(), _m)[_m](); - (_ref9 = (_ref30 = _ref10 = (_o12 = o) === null || _o12 === void 0 ? void 0 : _classPrivateFieldLooseBase(_o12.Foo, _self)[_self]) === null || _ref30 === void 0 ? void 0 : _ref30.getSelf) === null || _ref9 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref9.call(_ref10), _m)[_m](); - (_ref11 = (_o13 = o) === null || _o13 === void 0 ? void 0 : _classPrivateFieldLooseBase(_o13.Foo, _self)[_self].getSelf()) === null || _ref11 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref11.self, _m)[_m](); - (_ref12 = (_ref31 = (_o14 = o) === null || _o14 === void 0 ? void 0 : (_classPrivateFieldLoo2 = _classPrivateFieldLooseBase(_o14.Foo, _self)[_self]).getSelf) === null || _ref31 === void 0 ? void 0 : _ref31.call(_classPrivateFieldLoo2)) === null || _ref12 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref12.self, _m)[_m](); - (_ref13 = (_ref32 = (_o15 = o) === null || _o15 === void 0 ? void 0 : _classPrivateFieldLooseBase(_o15.Foo, _self)[_self]) === null || _ref32 === void 0 ? void 0 : _ref32.getSelf()) === null || _ref13 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref13.self, _m)[_m](); - (_ref14 = (_ref33 = (_o16 = o) === null || _o16 === void 0 ? void 0 : _classPrivateFieldLooseBase(_o16.Foo, _self)[_self]) === null || _ref33 === void 0 ? void 0 : (_ref33$getSelf = _ref33.getSelf) === null || _ref33$getSelf === void 0 ? void 0 : _ref33$getSelf.call(_ref33)) === null || _ref14 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref14.self, _m)[_m](); + (_ref3 = (_o10 = o) === null || _o10 === void 0 ? void 0 : (_classPrivateFieldLoo = _classPrivateFieldLooseBase(_o10.Foo, _self)[_self]).getSelf) === null || _ref3 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref3.call(_classPrivateFieldLoo), _m)[_m](); + (_ref4 = (_o11 = o) === null || _o11 === void 0 ? void 0 : _classPrivateFieldLooseBase(_o11.Foo, _self)[_self]) === null || _ref4 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref4.getSelf(), _m)[_m](); + (_getSelf = (_ref14 = _ref5 = (_o12 = o) === null || _o12 === void 0 ? void 0 : _classPrivateFieldLooseBase(_o12.Foo, _self)[_self]) === null || _ref14 === void 0 ? void 0 : _ref14.getSelf) === null || _getSelf === void 0 ? void 0 : _classPrivateFieldLooseBase(_getSelf.call(_ref5), _m)[_m](); + (_ref6 = (_o13 = o) === null || _o13 === void 0 ? void 0 : _classPrivateFieldLooseBase(_o13.Foo, _self)[_self].getSelf()) === null || _ref6 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref6.self, _m)[_m](); + (_call = (_ref15 = (_o14 = o) === null || _o14 === void 0 ? void 0 : (_classPrivateFieldLoo2 = _classPrivateFieldLooseBase(_o14.Foo, _self)[_self]).getSelf) === null || _ref15 === void 0 ? void 0 : _ref15.call(_classPrivateFieldLoo2)) === null || _call === void 0 ? void 0 : _classPrivateFieldLooseBase(_call.self, _m)[_m](); + (_getSelf2 = (_ref16 = (_o15 = o) === null || _o15 === void 0 ? void 0 : _classPrivateFieldLooseBase(_o15.Foo, _self)[_self]) === null || _ref16 === void 0 ? void 0 : _ref16.getSelf()) === null || _getSelf2 === void 0 ? void 0 : _classPrivateFieldLooseBase(_getSelf2.self, _m)[_m](); + (_getSelf3 = (_ref17 = (_o16 = o) === null || _o16 === void 0 ? void 0 : _classPrivateFieldLooseBase(_o16.Foo, _self)[_self]) === null || _ref17 === void 0 ? void 0 : (_ref17$getSelf = _ref17.getSelf) === null || _ref17$getSelf === void 0 ? void 0 : _ref17$getSelf.call(_ref17)) === null || _getSelf3 === void 0 ? void 0 : _classPrivateFieldLooseBase(_getSelf3.self, _m)[_m](); (_fn = fn) === null || _fn === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn().Foo, _m)[_m](); (_fn2 = fn) === null || _fn2 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn2().Foo, _m)[_m]().toString; (_fn3 = fn) === null || _fn3 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn3().Foo, _m)[_m]().toString(); - (_ref15 = fnDeep === null || fnDeep === void 0 ? void 0 : fnDeep().very.o) === null || _ref15 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref15.Foo, _m)[_m](); - (_ref16 = fnDeep === null || fnDeep === void 0 ? void 0 : fnDeep().very.o) === null || _ref16 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref16.Foo, _m)[_m]().toString; - (_ref17 = fnDeep === null || fnDeep === void 0 ? void 0 : fnDeep().very.o) === null || _ref17 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref17.Foo, _m)[_m]().toString(); + (_fnDeep$very$o = fnDeep === null || fnDeep === void 0 ? void 0 : fnDeep().very.o) === null || _fnDeep$very$o === void 0 ? void 0 : _classPrivateFieldLooseBase(_fnDeep$very$o.Foo, _m)[_m](); + (_fnDeep$very$o2 = fnDeep === null || fnDeep === void 0 ? void 0 : fnDeep().very.o) === null || _fnDeep$very$o2 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fnDeep$very$o2.Foo, _m)[_m]().toString; + (_fnDeep$very$o3 = fnDeep === null || fnDeep === void 0 ? void 0 : fnDeep().very.o) === null || _fnDeep$very$o3 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fnDeep$very$o3.Foo, _m)[_m]().toString(); (_fn4 = fn) === null || _fn4 === void 0 ? void 0 : _classPrivateFieldLooseBase(_classPrivateFieldLooseBase(_fn4().Foo, _self)[_self], _m)[_m](); (_fn5 = fn) === null || _fn5 === void 0 ? void 0 : _classPrivateFieldLooseBase(_classPrivateFieldLooseBase(_fn5().Foo, _self)[_self].self, _m)[_m](); - (_ref18 = (_fn6 = fn) === null || _fn6 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn6().Foo, _self)[_self]) === null || _ref18 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref18.self, _m)[_m](); - (_ref19 = (_fn7 = fn) === null || _fn7 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn7().Foo, _self)[_self].self) === null || _ref19 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref19.self, _m)[_m](); - (_ref20 = (_ref34 = (_fn8 = fn) === null || _fn8 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn8().Foo, _self)[_self]) === null || _ref34 === void 0 ? void 0 : _ref34.self) === null || _ref20 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref20.self, _m)[_m](); + (_ref7 = (_fn6 = fn) === null || _fn6 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn6().Foo, _self)[_self]) === null || _ref7 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref7.self, _m)[_m](); + (_ref8 = (_fn7 = fn) === null || _fn7 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn7().Foo, _self)[_self].self) === null || _ref8 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref8.self, _m)[_m](); + (_self3 = (_ref18 = (_fn8 = fn) === null || _fn8 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn8().Foo, _self)[_self]) === null || _ref18 === void 0 ? void 0 : _ref18.self) === null || _self3 === void 0 ? void 0 : _classPrivateFieldLooseBase(_self3.self, _m)[_m](); (_fn9 = fn) === null || _fn9 === void 0 ? void 0 : _classPrivateFieldLooseBase(_classPrivateFieldLooseBase(_fn9().Foo, _self)[_self].getSelf(), _m)[_m](); - (_ref21 = (_fn10 = fn) === null || _fn10 === void 0 ? void 0 : (_classPrivateFieldLoo3 = _classPrivateFieldLooseBase(_fn10().Foo, _self)[_self]).getSelf) === null || _ref21 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref21.call(_classPrivateFieldLoo3), _m)[_m](); - (_ref22 = (_fn11 = fn) === null || _fn11 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn11().Foo, _self)[_self]) === null || _ref22 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref22.getSelf(), _m)[_m](); - (_ref23 = (_ref35 = _ref24 = (_fn12 = fn) === null || _fn12 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn12().Foo, _self)[_self]) === null || _ref35 === void 0 ? void 0 : _ref35.getSelf) === null || _ref23 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref23.call(_ref24), _m)[_m](); - (_ref25 = (_fn13 = fn) === null || _fn13 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn13().Foo, _self)[_self].getSelf()) === null || _ref25 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref25.self, _m)[_m](); - (_ref26 = (_ref36 = (_fn14 = fn) === null || _fn14 === void 0 ? void 0 : (_classPrivateFieldLoo4 = _classPrivateFieldLooseBase(_fn14().Foo, _self)[_self]).getSelf) === null || _ref36 === void 0 ? void 0 : _ref36.call(_classPrivateFieldLoo4)) === null || _ref26 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref26.self, _m)[_m](); - (_ref27 = (_ref37 = (_fn15 = fn) === null || _fn15 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn15().Foo, _self)[_self]) === null || _ref37 === void 0 ? void 0 : _ref37.getSelf()) === null || _ref27 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref27.self, _m)[_m](); - (_ref28 = (_ref38 = (_fn16 = fn) === null || _fn16 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn16().Foo, _self)[_self]) === null || _ref38 === void 0 ? void 0 : (_ref38$getSelf = _ref38.getSelf) === null || _ref38$getSelf === void 0 ? void 0 : _ref38$getSelf.call(_ref38)) === null || _ref28 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref28.self, _m)[_m](); + (_ref9 = (_fn10 = fn) === null || _fn10 === void 0 ? void 0 : (_classPrivateFieldLoo3 = _classPrivateFieldLooseBase(_fn10().Foo, _self)[_self]).getSelf) === null || _ref9 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref9.call(_classPrivateFieldLoo3), _m)[_m](); + (_ref10 = (_fn11 = fn) === null || _fn11 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn11().Foo, _self)[_self]) === null || _ref10 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref10.getSelf(), _m)[_m](); + (_getSelf4 = (_ref19 = _ref11 = (_fn12 = fn) === null || _fn12 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn12().Foo, _self)[_self]) === null || _ref19 === void 0 ? void 0 : _ref19.getSelf) === null || _getSelf4 === void 0 ? void 0 : _classPrivateFieldLooseBase(_getSelf4.call(_ref11), _m)[_m](); + (_ref12 = (_fn13 = fn) === null || _fn13 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn13().Foo, _self)[_self].getSelf()) === null || _ref12 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref12.self, _m)[_m](); + (_call2 = (_ref20 = (_fn14 = fn) === null || _fn14 === void 0 ? void 0 : (_classPrivateFieldLoo4 = _classPrivateFieldLooseBase(_fn14().Foo, _self)[_self]).getSelf) === null || _ref20 === void 0 ? void 0 : _ref20.call(_classPrivateFieldLoo4)) === null || _call2 === void 0 ? void 0 : _classPrivateFieldLooseBase(_call2.self, _m)[_m](); + (_getSelf5 = (_ref21 = (_fn15 = fn) === null || _fn15 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn15().Foo, _self)[_self]) === null || _ref21 === void 0 ? void 0 : _ref21.getSelf()) === null || _getSelf5 === void 0 ? void 0 : _classPrivateFieldLooseBase(_getSelf5.self, _m)[_m](); + (_getSelf6 = (_ref22 = (_fn16 = fn) === null || _fn16 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn16().Foo, _self)[_self]) === null || _ref22 === void 0 ? void 0 : (_ref22$getSelf = _ref22.getSelf) === null || _ref22$getSelf === void 0 ? void 0 : _ref22$getSelf.call(_ref22)) === null || _getSelf6 === void 0 ? void 0 : _classPrivateFieldLooseBase(_getSelf6.self, _m)[_m](); } } diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-private-call/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-private-call/output.js index c8df9a71bbdd..b4775daf8bd5 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-private-call/output.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-private-call/output.js @@ -10,7 +10,7 @@ class Foo { } static test() { - var _o, _o2, _o3, _ref, _ref2, _ref3, _o4, _o5, _o6, _ref4, _o7, _ref5, _o8, _ref6, _o9, _o10, _classPrivateFieldLoo, _ref7, _o11, _ref8, _o12, _ref9, _ref10, _o13, _ref11, _o14, _classPrivateFieldLoo2, _ref12, _o15, _ref13, _o16, _ref14, _fn, _fn2, _fn3, _ref15, _ref16, _ref17, _fn4, _fn5, _fn6, _ref18, _fn7, _ref19, _fn8, _ref20, _fn9, _fn10, _classPrivateFieldLoo3, _ref21, _fn11, _ref22, _fn12, _ref23, _ref24, _fn13, _ref25, _fn14, _classPrivateFieldLoo4, _ref26, _fn15, _ref27, _fn16, _ref28; + var _o, _o2, _o3, _deep$very$o, _deep$very$o2, _deep$very$o3, _o4, _o5, _o6, _ref, _o7, _ref2, _o8, _self2, _o9, _o10, _classPrivateFieldLoo, _ref3, _o11, _ref4, _o12, _getSelf, _ref5, _o13, _ref6, _o14, _classPrivateFieldLoo2, _call, _o15, _getSelf2, _o16, _getSelf3, _fn, _fn2, _fn3, _fnDeep$very$o, _fnDeep$very$o2, _fnDeep$very$o3, _fn4, _fn5, _fn6, _ref7, _fn7, _ref8, _fn8, _self3, _fn9, _fn10, _classPrivateFieldLoo3, _ref9, _fn11, _ref10, _fn12, _getSelf4, _ref11, _fn13, _ref12, _fn14, _classPrivateFieldLoo4, _call2, _fn15, _getSelf5, _fn16, _getSelf6; const o = { Foo: Foo @@ -32,41 +32,41 @@ class Foo { (_o = o) === null || _o === void 0 ? void 0 : _classPrivateFieldLooseBase(_o.Foo, _m)[_m](); (_o2 = o) === null || _o2 === void 0 ? void 0 : _classPrivateFieldLooseBase(_o2.Foo, _m)[_m]().toString; (_o3 = o) === null || _o3 === void 0 ? void 0 : _classPrivateFieldLooseBase(_o3.Foo, _m)[_m]().toString(); - (_ref = deep?.very.o) === null || _ref === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref.Foo, _m)[_m](); - (_ref2 = deep?.very.o) === null || _ref2 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref2.Foo, _m)[_m]().toString; - (_ref3 = deep?.very.o) === null || _ref3 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref3.Foo, _m)[_m]().toString(); + (_deep$very$o = deep?.very.o) === null || _deep$very$o === void 0 ? void 0 : _classPrivateFieldLooseBase(_deep$very$o.Foo, _m)[_m](); + (_deep$very$o2 = deep?.very.o) === null || _deep$very$o2 === void 0 ? void 0 : _classPrivateFieldLooseBase(_deep$very$o2.Foo, _m)[_m]().toString; + (_deep$very$o3 = deep?.very.o) === null || _deep$very$o3 === void 0 ? void 0 : _classPrivateFieldLooseBase(_deep$very$o3.Foo, _m)[_m]().toString(); (_o4 = o) === null || _o4 === void 0 ? void 0 : _classPrivateFieldLooseBase(_classPrivateFieldLooseBase(_o4.Foo, _self)[_self], _m)[_m](); (_o5 = o) === null || _o5 === void 0 ? void 0 : _classPrivateFieldLooseBase(_classPrivateFieldLooseBase(_o5.Foo, _self)[_self].self, _m)[_m](); - (_ref4 = (_o6 = o) === null || _o6 === void 0 ? void 0 : _classPrivateFieldLooseBase(_o6.Foo, _self)[_self]) === null || _ref4 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref4.self, _m)[_m](); - (_ref5 = (_o7 = o) === null || _o7 === void 0 ? void 0 : _classPrivateFieldLooseBase(_o7.Foo, _self)[_self].self) === null || _ref5 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref5.self, _m)[_m](); - (_ref6 = ((_o8 = o) === null || _o8 === void 0 ? void 0 : _classPrivateFieldLooseBase(_o8.Foo, _self)[_self])?.self) === null || _ref6 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref6.self, _m)[_m](); + (_ref = (_o6 = o) === null || _o6 === void 0 ? void 0 : _classPrivateFieldLooseBase(_o6.Foo, _self)[_self]) === null || _ref === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref.self, _m)[_m](); + (_ref2 = (_o7 = o) === null || _o7 === void 0 ? void 0 : _classPrivateFieldLooseBase(_o7.Foo, _self)[_self].self) === null || _ref2 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref2.self, _m)[_m](); + (_self2 = ((_o8 = o) === null || _o8 === void 0 ? void 0 : _classPrivateFieldLooseBase(_o8.Foo, _self)[_self])?.self) === null || _self2 === void 0 ? void 0 : _classPrivateFieldLooseBase(_self2.self, _m)[_m](); (_o9 = o) === null || _o9 === void 0 ? void 0 : _classPrivateFieldLooseBase(_classPrivateFieldLooseBase(_o9.Foo, _self)[_self].getSelf(), _m)[_m](); - (_ref7 = (_o10 = o) === null || _o10 === void 0 ? void 0 : (_classPrivateFieldLoo = _classPrivateFieldLooseBase(_o10.Foo, _self)[_self]).getSelf) === null || _ref7 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref7.call(_classPrivateFieldLoo), _m)[_m](); - (_ref8 = (_o11 = o) === null || _o11 === void 0 ? void 0 : _classPrivateFieldLooseBase(_o11.Foo, _self)[_self]) === null || _ref8 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref8.getSelf(), _m)[_m](); - (_ref9 = (_ref10 = (_o12 = o) === null || _o12 === void 0 ? void 0 : _classPrivateFieldLooseBase(_o12.Foo, _self)[_self])?.getSelf) === null || _ref9 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref9.call(_ref10), _m)[_m](); - (_ref11 = (_o13 = o) === null || _o13 === void 0 ? void 0 : _classPrivateFieldLooseBase(_o13.Foo, _self)[_self].getSelf()) === null || _ref11 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref11.self, _m)[_m](); - (_ref12 = ((_o14 = o) === null || _o14 === void 0 ? void 0 : (_classPrivateFieldLoo2 = _classPrivateFieldLooseBase(_o14.Foo, _self)[_self]).getSelf)?.call(_classPrivateFieldLoo2)) === null || _ref12 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref12.self, _m)[_m](); - (_ref13 = ((_o15 = o) === null || _o15 === void 0 ? void 0 : _classPrivateFieldLooseBase(_o15.Foo, _self)[_self])?.getSelf()) === null || _ref13 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref13.self, _m)[_m](); - (_ref14 = ((_o16 = o) === null || _o16 === void 0 ? void 0 : _classPrivateFieldLooseBase(_o16.Foo, _self)[_self])?.getSelf?.()) === null || _ref14 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref14.self, _m)[_m](); + (_ref3 = (_o10 = o) === null || _o10 === void 0 ? void 0 : (_classPrivateFieldLoo = _classPrivateFieldLooseBase(_o10.Foo, _self)[_self]).getSelf) === null || _ref3 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref3.call(_classPrivateFieldLoo), _m)[_m](); + (_ref4 = (_o11 = o) === null || _o11 === void 0 ? void 0 : _classPrivateFieldLooseBase(_o11.Foo, _self)[_self]) === null || _ref4 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref4.getSelf(), _m)[_m](); + (_getSelf = (_ref5 = (_o12 = o) === null || _o12 === void 0 ? void 0 : _classPrivateFieldLooseBase(_o12.Foo, _self)[_self])?.getSelf) === null || _getSelf === void 0 ? void 0 : _classPrivateFieldLooseBase(_getSelf.call(_ref5), _m)[_m](); + (_ref6 = (_o13 = o) === null || _o13 === void 0 ? void 0 : _classPrivateFieldLooseBase(_o13.Foo, _self)[_self].getSelf()) === null || _ref6 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref6.self, _m)[_m](); + (_call = ((_o14 = o) === null || _o14 === void 0 ? void 0 : (_classPrivateFieldLoo2 = _classPrivateFieldLooseBase(_o14.Foo, _self)[_self]).getSelf)?.call(_classPrivateFieldLoo2)) === null || _call === void 0 ? void 0 : _classPrivateFieldLooseBase(_call.self, _m)[_m](); + (_getSelf2 = ((_o15 = o) === null || _o15 === void 0 ? void 0 : _classPrivateFieldLooseBase(_o15.Foo, _self)[_self])?.getSelf()) === null || _getSelf2 === void 0 ? void 0 : _classPrivateFieldLooseBase(_getSelf2.self, _m)[_m](); + (_getSelf3 = ((_o16 = o) === null || _o16 === void 0 ? void 0 : _classPrivateFieldLooseBase(_o16.Foo, _self)[_self])?.getSelf?.()) === null || _getSelf3 === void 0 ? void 0 : _classPrivateFieldLooseBase(_getSelf3.self, _m)[_m](); (_fn = fn) === null || _fn === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn().Foo, _m)[_m](); (_fn2 = fn) === null || _fn2 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn2().Foo, _m)[_m]().toString; (_fn3 = fn) === null || _fn3 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn3().Foo, _m)[_m]().toString(); - (_ref15 = fnDeep?.().very.o) === null || _ref15 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref15.Foo, _m)[_m](); - (_ref16 = fnDeep?.().very.o) === null || _ref16 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref16.Foo, _m)[_m]().toString; - (_ref17 = fnDeep?.().very.o) === null || _ref17 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref17.Foo, _m)[_m]().toString(); + (_fnDeep$very$o = fnDeep?.().very.o) === null || _fnDeep$very$o === void 0 ? void 0 : _classPrivateFieldLooseBase(_fnDeep$very$o.Foo, _m)[_m](); + (_fnDeep$very$o2 = fnDeep?.().very.o) === null || _fnDeep$very$o2 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fnDeep$very$o2.Foo, _m)[_m]().toString; + (_fnDeep$very$o3 = fnDeep?.().very.o) === null || _fnDeep$very$o3 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fnDeep$very$o3.Foo, _m)[_m]().toString(); (_fn4 = fn) === null || _fn4 === void 0 ? void 0 : _classPrivateFieldLooseBase(_classPrivateFieldLooseBase(_fn4().Foo, _self)[_self], _m)[_m](); (_fn5 = fn) === null || _fn5 === void 0 ? void 0 : _classPrivateFieldLooseBase(_classPrivateFieldLooseBase(_fn5().Foo, _self)[_self].self, _m)[_m](); - (_ref18 = (_fn6 = fn) === null || _fn6 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn6().Foo, _self)[_self]) === null || _ref18 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref18.self, _m)[_m](); - (_ref19 = (_fn7 = fn) === null || _fn7 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn7().Foo, _self)[_self].self) === null || _ref19 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref19.self, _m)[_m](); - (_ref20 = ((_fn8 = fn) === null || _fn8 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn8().Foo, _self)[_self])?.self) === null || _ref20 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref20.self, _m)[_m](); + (_ref7 = (_fn6 = fn) === null || _fn6 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn6().Foo, _self)[_self]) === null || _ref7 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref7.self, _m)[_m](); + (_ref8 = (_fn7 = fn) === null || _fn7 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn7().Foo, _self)[_self].self) === null || _ref8 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref8.self, _m)[_m](); + (_self3 = ((_fn8 = fn) === null || _fn8 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn8().Foo, _self)[_self])?.self) === null || _self3 === void 0 ? void 0 : _classPrivateFieldLooseBase(_self3.self, _m)[_m](); (_fn9 = fn) === null || _fn9 === void 0 ? void 0 : _classPrivateFieldLooseBase(_classPrivateFieldLooseBase(_fn9().Foo, _self)[_self].getSelf(), _m)[_m](); - (_ref21 = (_fn10 = fn) === null || _fn10 === void 0 ? void 0 : (_classPrivateFieldLoo3 = _classPrivateFieldLooseBase(_fn10().Foo, _self)[_self]).getSelf) === null || _ref21 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref21.call(_classPrivateFieldLoo3), _m)[_m](); - (_ref22 = (_fn11 = fn) === null || _fn11 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn11().Foo, _self)[_self]) === null || _ref22 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref22.getSelf(), _m)[_m](); - (_ref23 = (_ref24 = (_fn12 = fn) === null || _fn12 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn12().Foo, _self)[_self])?.getSelf) === null || _ref23 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref23.call(_ref24), _m)[_m](); - (_ref25 = (_fn13 = fn) === null || _fn13 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn13().Foo, _self)[_self].getSelf()) === null || _ref25 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref25.self, _m)[_m](); - (_ref26 = ((_fn14 = fn) === null || _fn14 === void 0 ? void 0 : (_classPrivateFieldLoo4 = _classPrivateFieldLooseBase(_fn14().Foo, _self)[_self]).getSelf)?.call(_classPrivateFieldLoo4)) === null || _ref26 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref26.self, _m)[_m](); - (_ref27 = ((_fn15 = fn) === null || _fn15 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn15().Foo, _self)[_self])?.getSelf()) === null || _ref27 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref27.self, _m)[_m](); - (_ref28 = ((_fn16 = fn) === null || _fn16 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn16().Foo, _self)[_self])?.getSelf?.()) === null || _ref28 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref28.self, _m)[_m](); + (_ref9 = (_fn10 = fn) === null || _fn10 === void 0 ? void 0 : (_classPrivateFieldLoo3 = _classPrivateFieldLooseBase(_fn10().Foo, _self)[_self]).getSelf) === null || _ref9 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref9.call(_classPrivateFieldLoo3), _m)[_m](); + (_ref10 = (_fn11 = fn) === null || _fn11 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn11().Foo, _self)[_self]) === null || _ref10 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref10.getSelf(), _m)[_m](); + (_getSelf4 = (_ref11 = (_fn12 = fn) === null || _fn12 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn12().Foo, _self)[_self])?.getSelf) === null || _getSelf4 === void 0 ? void 0 : _classPrivateFieldLooseBase(_getSelf4.call(_ref11), _m)[_m](); + (_ref12 = (_fn13 = fn) === null || _fn13 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn13().Foo, _self)[_self].getSelf()) === null || _ref12 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref12.self, _m)[_m](); + (_call2 = ((_fn14 = fn) === null || _fn14 === void 0 ? void 0 : (_classPrivateFieldLoo4 = _classPrivateFieldLooseBase(_fn14().Foo, _self)[_self]).getSelf)?.call(_classPrivateFieldLoo4)) === null || _call2 === void 0 ? void 0 : _classPrivateFieldLooseBase(_call2.self, _m)[_m](); + (_getSelf5 = ((_fn15 = fn) === null || _fn15 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn15().Foo, _self)[_self])?.getSelf()) === null || _getSelf5 === void 0 ? void 0 : _classPrivateFieldLooseBase(_getSelf5.self, _m)[_m](); + (_getSelf6 = ((_fn16 = fn) === null || _fn16 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn16().Foo, _self)[_self])?.getSelf?.()) === null || _getSelf6 === void 0 ? void 0 : _classPrivateFieldLooseBase(_getSelf6.self, _m)[_m](); } } diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-with-transform/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-with-transform/output.js index f0f84e8fd25d..90cdc75d8598 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-with-transform/output.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-with-transform/output.js @@ -10,7 +10,7 @@ class Foo { } static test() { - var _o, _o2, _o3, _ref, _ref2, _ref3, _o4, _o5, _o6, _ref4, _o7, _ref5, _o8, _ref6, _o9, _o10, _classPrivateFieldLoo, _ref7, _o11, _ref8, _o12, _ref9, _ref10, _o13, _ref11, _o14, _classPrivateFieldLoo2, _ref12, _o15, _ref13, _o16, _ref14, _fn, _fn2, _fn3, _ref15, _ref16, _ref17, _fn4, _fn5, _fn6, _ref18, _fn7, _ref19, _fn8, _ref20, _fn9, _fn10, _classPrivateFieldLoo3, _ref21, _fn11, _ref22, _fn12, _ref23, _ref24, _fn13, _ref25, _fn14, _classPrivateFieldLoo4, _ref26, _fn15, _ref27, _fn16, _ref28, _ref29, _ref30, _ref31, _ref32, _ref33, _ref33$getSelf, _ref34, _ref35, _ref36, _ref37, _ref38, _ref38$getSelf; + var _o, _o2, _o3, _deep$very$o, _deep$very$o2, _deep$very$o3, _o4, _o5, _o6, _ref, _o7, _ref2, _o8, _self2, _o9, _o10, _classPrivateFieldLoo, _ref3, _o11, _ref4, _o12, _getSelf, _ref5, _o13, _ref6, _o14, _classPrivateFieldLoo2, _call, _o15, _getSelf2, _o16, _getSelf3, _fn, _fn2, _fn3, _fnDeep$very$o, _fnDeep$very$o2, _fnDeep$very$o3, _fn4, _fn5, _fn6, _ref7, _fn7, _ref8, _fn8, _self3, _fn9, _fn10, _classPrivateFieldLoo3, _ref9, _fn11, _ref10, _fn12, _getSelf4, _ref11, _fn13, _ref12, _fn14, _classPrivateFieldLoo4, _call2, _fn15, _getSelf5, _fn16, _getSelf6, _ref13, _ref14, _ref15, _ref16, _ref17, _ref17$getSelf, _ref18, _ref19, _ref20, _ref21, _ref22, _ref22$getSelf; const o = { Foo: Foo @@ -32,41 +32,41 @@ class Foo { (_o = o) === null || _o === void 0 ? void 0 : _classPrivateFieldLooseBase(_o.Foo, _x)[_x]; (_o2 = o) === null || _o2 === void 0 ? void 0 : _classPrivateFieldLooseBase(_o2.Foo, _x)[_x].toString; (_o3 = o) === null || _o3 === void 0 ? void 0 : _classPrivateFieldLooseBase(_o3.Foo, _x)[_x].toString(); - (_ref = deep === null || deep === void 0 ? void 0 : deep.very.o) === null || _ref === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref.Foo, _x)[_x]; - (_ref2 = deep === null || deep === void 0 ? void 0 : deep.very.o) === null || _ref2 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref2.Foo, _x)[_x].toString; - (_ref3 = deep === null || deep === void 0 ? void 0 : deep.very.o) === null || _ref3 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref3.Foo, _x)[_x].toString(); + (_deep$very$o = deep === null || deep === void 0 ? void 0 : deep.very.o) === null || _deep$very$o === void 0 ? void 0 : _classPrivateFieldLooseBase(_deep$very$o.Foo, _x)[_x]; + (_deep$very$o2 = deep === null || deep === void 0 ? void 0 : deep.very.o) === null || _deep$very$o2 === void 0 ? void 0 : _classPrivateFieldLooseBase(_deep$very$o2.Foo, _x)[_x].toString; + (_deep$very$o3 = deep === null || deep === void 0 ? void 0 : deep.very.o) === null || _deep$very$o3 === void 0 ? void 0 : _classPrivateFieldLooseBase(_deep$very$o3.Foo, _x)[_x].toString(); (_o4 = o) === null || _o4 === void 0 ? void 0 : _classPrivateFieldLooseBase(_classPrivateFieldLooseBase(_o4.Foo, _self)[_self], _x)[_x]; (_o5 = o) === null || _o5 === void 0 ? void 0 : _classPrivateFieldLooseBase(_classPrivateFieldLooseBase(_o5.Foo, _self)[_self].self, _x)[_x]; - (_ref4 = (_o6 = o) === null || _o6 === void 0 ? void 0 : _classPrivateFieldLooseBase(_o6.Foo, _self)[_self]) === null || _ref4 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref4.self, _x)[_x]; - (_ref5 = (_o7 = o) === null || _o7 === void 0 ? void 0 : _classPrivateFieldLooseBase(_o7.Foo, _self)[_self].self) === null || _ref5 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref5.self, _x)[_x]; - (_ref6 = (_ref29 = (_o8 = o) === null || _o8 === void 0 ? void 0 : _classPrivateFieldLooseBase(_o8.Foo, _self)[_self]) === null || _ref29 === void 0 ? void 0 : _ref29.self) === null || _ref6 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref6.self, _x)[_x]; + (_ref = (_o6 = o) === null || _o6 === void 0 ? void 0 : _classPrivateFieldLooseBase(_o6.Foo, _self)[_self]) === null || _ref === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref.self, _x)[_x]; + (_ref2 = (_o7 = o) === null || _o7 === void 0 ? void 0 : _classPrivateFieldLooseBase(_o7.Foo, _self)[_self].self) === null || _ref2 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref2.self, _x)[_x]; + (_self2 = (_ref13 = (_o8 = o) === null || _o8 === void 0 ? void 0 : _classPrivateFieldLooseBase(_o8.Foo, _self)[_self]) === null || _ref13 === void 0 ? void 0 : _ref13.self) === null || _self2 === void 0 ? void 0 : _classPrivateFieldLooseBase(_self2.self, _x)[_x]; (_o9 = o) === null || _o9 === void 0 ? void 0 : _classPrivateFieldLooseBase(_classPrivateFieldLooseBase(_o9.Foo, _self)[_self].getSelf(), _x)[_x]; - (_ref7 = (_o10 = o) === null || _o10 === void 0 ? void 0 : (_classPrivateFieldLoo = _classPrivateFieldLooseBase(_o10.Foo, _self)[_self]).getSelf) === null || _ref7 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref7.call(_classPrivateFieldLoo), _x)[_x]; - (_ref8 = (_o11 = o) === null || _o11 === void 0 ? void 0 : _classPrivateFieldLooseBase(_o11.Foo, _self)[_self]) === null || _ref8 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref8.getSelf(), _x)[_x]; - (_ref9 = (_ref30 = _ref10 = (_o12 = o) === null || _o12 === void 0 ? void 0 : _classPrivateFieldLooseBase(_o12.Foo, _self)[_self]) === null || _ref30 === void 0 ? void 0 : _ref30.getSelf) === null || _ref9 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref9.call(_ref10), _x)[_x]; - (_ref11 = (_o13 = o) === null || _o13 === void 0 ? void 0 : _classPrivateFieldLooseBase(_o13.Foo, _self)[_self].getSelf()) === null || _ref11 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref11.self, _x)[_x]; - (_ref12 = (_ref31 = (_o14 = o) === null || _o14 === void 0 ? void 0 : (_classPrivateFieldLoo2 = _classPrivateFieldLooseBase(_o14.Foo, _self)[_self]).getSelf) === null || _ref31 === void 0 ? void 0 : _ref31.call(_classPrivateFieldLoo2)) === null || _ref12 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref12.self, _x)[_x]; - (_ref13 = (_ref32 = (_o15 = o) === null || _o15 === void 0 ? void 0 : _classPrivateFieldLooseBase(_o15.Foo, _self)[_self]) === null || _ref32 === void 0 ? void 0 : _ref32.getSelf()) === null || _ref13 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref13.self, _x)[_x]; - (_ref14 = (_ref33 = (_o16 = o) === null || _o16 === void 0 ? void 0 : _classPrivateFieldLooseBase(_o16.Foo, _self)[_self]) === null || _ref33 === void 0 ? void 0 : (_ref33$getSelf = _ref33.getSelf) === null || _ref33$getSelf === void 0 ? void 0 : _ref33$getSelf.call(_ref33)) === null || _ref14 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref14.self, _x)[_x]; + (_ref3 = (_o10 = o) === null || _o10 === void 0 ? void 0 : (_classPrivateFieldLoo = _classPrivateFieldLooseBase(_o10.Foo, _self)[_self]).getSelf) === null || _ref3 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref3.call(_classPrivateFieldLoo), _x)[_x]; + (_ref4 = (_o11 = o) === null || _o11 === void 0 ? void 0 : _classPrivateFieldLooseBase(_o11.Foo, _self)[_self]) === null || _ref4 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref4.getSelf(), _x)[_x]; + (_getSelf = (_ref14 = _ref5 = (_o12 = o) === null || _o12 === void 0 ? void 0 : _classPrivateFieldLooseBase(_o12.Foo, _self)[_self]) === null || _ref14 === void 0 ? void 0 : _ref14.getSelf) === null || _getSelf === void 0 ? void 0 : _classPrivateFieldLooseBase(_getSelf.call(_ref5), _x)[_x]; + (_ref6 = (_o13 = o) === null || _o13 === void 0 ? void 0 : _classPrivateFieldLooseBase(_o13.Foo, _self)[_self].getSelf()) === null || _ref6 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref6.self, _x)[_x]; + (_call = (_ref15 = (_o14 = o) === null || _o14 === void 0 ? void 0 : (_classPrivateFieldLoo2 = _classPrivateFieldLooseBase(_o14.Foo, _self)[_self]).getSelf) === null || _ref15 === void 0 ? void 0 : _ref15.call(_classPrivateFieldLoo2)) === null || _call === void 0 ? void 0 : _classPrivateFieldLooseBase(_call.self, _x)[_x]; + (_getSelf2 = (_ref16 = (_o15 = o) === null || _o15 === void 0 ? void 0 : _classPrivateFieldLooseBase(_o15.Foo, _self)[_self]) === null || _ref16 === void 0 ? void 0 : _ref16.getSelf()) === null || _getSelf2 === void 0 ? void 0 : _classPrivateFieldLooseBase(_getSelf2.self, _x)[_x]; + (_getSelf3 = (_ref17 = (_o16 = o) === null || _o16 === void 0 ? void 0 : _classPrivateFieldLooseBase(_o16.Foo, _self)[_self]) === null || _ref17 === void 0 ? void 0 : (_ref17$getSelf = _ref17.getSelf) === null || _ref17$getSelf === void 0 ? void 0 : _ref17$getSelf.call(_ref17)) === null || _getSelf3 === void 0 ? void 0 : _classPrivateFieldLooseBase(_getSelf3.self, _x)[_x]; (_fn = fn) === null || _fn === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn().Foo, _x)[_x]; (_fn2 = fn) === null || _fn2 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn2().Foo, _x)[_x].toString; (_fn3 = fn) === null || _fn3 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn3().Foo, _x)[_x].toString(); - (_ref15 = fnDeep === null || fnDeep === void 0 ? void 0 : fnDeep().very.o) === null || _ref15 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref15.Foo, _x)[_x]; - (_ref16 = fnDeep === null || fnDeep === void 0 ? void 0 : fnDeep().very.o) === null || _ref16 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref16.Foo, _x)[_x].toString; - (_ref17 = fnDeep === null || fnDeep === void 0 ? void 0 : fnDeep().very.o) === null || _ref17 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref17.Foo, _x)[_x].toString(); + (_fnDeep$very$o = fnDeep === null || fnDeep === void 0 ? void 0 : fnDeep().very.o) === null || _fnDeep$very$o === void 0 ? void 0 : _classPrivateFieldLooseBase(_fnDeep$very$o.Foo, _x)[_x]; + (_fnDeep$very$o2 = fnDeep === null || fnDeep === void 0 ? void 0 : fnDeep().very.o) === null || _fnDeep$very$o2 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fnDeep$very$o2.Foo, _x)[_x].toString; + (_fnDeep$very$o3 = fnDeep === null || fnDeep === void 0 ? void 0 : fnDeep().very.o) === null || _fnDeep$very$o3 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fnDeep$very$o3.Foo, _x)[_x].toString(); (_fn4 = fn) === null || _fn4 === void 0 ? void 0 : _classPrivateFieldLooseBase(_classPrivateFieldLooseBase(_fn4().Foo, _self)[_self], _x)[_x]; (_fn5 = fn) === null || _fn5 === void 0 ? void 0 : _classPrivateFieldLooseBase(_classPrivateFieldLooseBase(_fn5().Foo, _self)[_self].self, _x)[_x]; - (_ref18 = (_fn6 = fn) === null || _fn6 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn6().Foo, _self)[_self]) === null || _ref18 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref18.self, _x)[_x]; - (_ref19 = (_fn7 = fn) === null || _fn7 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn7().Foo, _self)[_self].self) === null || _ref19 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref19.self, _x)[_x]; - (_ref20 = (_ref34 = (_fn8 = fn) === null || _fn8 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn8().Foo, _self)[_self]) === null || _ref34 === void 0 ? void 0 : _ref34.self) === null || _ref20 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref20.self, _x)[_x]; + (_ref7 = (_fn6 = fn) === null || _fn6 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn6().Foo, _self)[_self]) === null || _ref7 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref7.self, _x)[_x]; + (_ref8 = (_fn7 = fn) === null || _fn7 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn7().Foo, _self)[_self].self) === null || _ref8 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref8.self, _x)[_x]; + (_self3 = (_ref18 = (_fn8 = fn) === null || _fn8 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn8().Foo, _self)[_self]) === null || _ref18 === void 0 ? void 0 : _ref18.self) === null || _self3 === void 0 ? void 0 : _classPrivateFieldLooseBase(_self3.self, _x)[_x]; (_fn9 = fn) === null || _fn9 === void 0 ? void 0 : _classPrivateFieldLooseBase(_classPrivateFieldLooseBase(_fn9().Foo, _self)[_self].getSelf(), _x)[_x]; - (_ref21 = (_fn10 = fn) === null || _fn10 === void 0 ? void 0 : (_classPrivateFieldLoo3 = _classPrivateFieldLooseBase(_fn10().Foo, _self)[_self]).getSelf) === null || _ref21 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref21.call(_classPrivateFieldLoo3), _x)[_x]; - (_ref22 = (_fn11 = fn) === null || _fn11 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn11().Foo, _self)[_self]) === null || _ref22 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref22.getSelf(), _x)[_x]; - (_ref23 = (_ref35 = _ref24 = (_fn12 = fn) === null || _fn12 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn12().Foo, _self)[_self]) === null || _ref35 === void 0 ? void 0 : _ref35.getSelf) === null || _ref23 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref23.call(_ref24), _x)[_x]; - (_ref25 = (_fn13 = fn) === null || _fn13 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn13().Foo, _self)[_self].getSelf()) === null || _ref25 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref25.self, _x)[_x]; - (_ref26 = (_ref36 = (_fn14 = fn) === null || _fn14 === void 0 ? void 0 : (_classPrivateFieldLoo4 = _classPrivateFieldLooseBase(_fn14().Foo, _self)[_self]).getSelf) === null || _ref36 === void 0 ? void 0 : _ref36.call(_classPrivateFieldLoo4)) === null || _ref26 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref26.self, _x)[_x]; - (_ref27 = (_ref37 = (_fn15 = fn) === null || _fn15 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn15().Foo, _self)[_self]) === null || _ref37 === void 0 ? void 0 : _ref37.getSelf()) === null || _ref27 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref27.self, _x)[_x]; - (_ref28 = (_ref38 = (_fn16 = fn) === null || _fn16 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn16().Foo, _self)[_self]) === null || _ref38 === void 0 ? void 0 : (_ref38$getSelf = _ref38.getSelf) === null || _ref38$getSelf === void 0 ? void 0 : _ref38$getSelf.call(_ref38)) === null || _ref28 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref28.self, _x)[_x]; + (_ref9 = (_fn10 = fn) === null || _fn10 === void 0 ? void 0 : (_classPrivateFieldLoo3 = _classPrivateFieldLooseBase(_fn10().Foo, _self)[_self]).getSelf) === null || _ref9 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref9.call(_classPrivateFieldLoo3), _x)[_x]; + (_ref10 = (_fn11 = fn) === null || _fn11 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn11().Foo, _self)[_self]) === null || _ref10 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref10.getSelf(), _x)[_x]; + (_getSelf4 = (_ref19 = _ref11 = (_fn12 = fn) === null || _fn12 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn12().Foo, _self)[_self]) === null || _ref19 === void 0 ? void 0 : _ref19.getSelf) === null || _getSelf4 === void 0 ? void 0 : _classPrivateFieldLooseBase(_getSelf4.call(_ref11), _x)[_x]; + (_ref12 = (_fn13 = fn) === null || _fn13 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn13().Foo, _self)[_self].getSelf()) === null || _ref12 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref12.self, _x)[_x]; + (_call2 = (_ref20 = (_fn14 = fn) === null || _fn14 === void 0 ? void 0 : (_classPrivateFieldLoo4 = _classPrivateFieldLooseBase(_fn14().Foo, _self)[_self]).getSelf) === null || _ref20 === void 0 ? void 0 : _ref20.call(_classPrivateFieldLoo4)) === null || _call2 === void 0 ? void 0 : _classPrivateFieldLooseBase(_call2.self, _x)[_x]; + (_getSelf5 = (_ref21 = (_fn15 = fn) === null || _fn15 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn15().Foo, _self)[_self]) === null || _ref21 === void 0 ? void 0 : _ref21.getSelf()) === null || _getSelf5 === void 0 ? void 0 : _classPrivateFieldLooseBase(_getSelf5.self, _x)[_x]; + (_getSelf6 = (_ref22 = (_fn16 = fn) === null || _fn16 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn16().Foo, _self)[_self]) === null || _ref22 === void 0 ? void 0 : (_ref22$getSelf = _ref22.getSelf) === null || _ref22$getSelf === void 0 ? void 0 : _ref22$getSelf.call(_ref22)) === null || _getSelf6 === void 0 ? void 0 : _classPrivateFieldLooseBase(_getSelf6.self, _x)[_x]; } } diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain/output.js index a70ea420d62b..5b32ae955d9b 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain/output.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain/output.js @@ -10,7 +10,7 @@ class Foo { } static test() { - var _o, _o2, _o3, _ref, _ref2, _ref3, _o4, _o5, _o6, _ref4, _o7, _ref5, _o8, _ref6, _o9, _o10, _classPrivateFieldLoo, _ref7, _o11, _ref8, _o12, _ref9, _ref10, _o13, _ref11, _o14, _classPrivateFieldLoo2, _ref12, _o15, _ref13, _o16, _ref14, _fn, _fn2, _fn3, _ref15, _ref16, _ref17, _fn4, _fn5, _fn6, _ref18, _fn7, _ref19, _fn8, _ref20, _fn9, _fn10, _classPrivateFieldLoo3, _ref21, _fn11, _ref22, _fn12, _ref23, _ref24, _fn13, _ref25, _fn14, _classPrivateFieldLoo4, _ref26, _fn15, _ref27, _fn16, _ref28; + var _o, _o2, _o3, _deep$very$o, _deep$very$o2, _deep$very$o3, _o4, _o5, _o6, _ref, _o7, _ref2, _o8, _self2, _o9, _o10, _classPrivateFieldLoo, _ref3, _o11, _ref4, _o12, _getSelf, _ref5, _o13, _ref6, _o14, _classPrivateFieldLoo2, _call, _o15, _getSelf2, _o16, _getSelf3, _fn, _fn2, _fn3, _fnDeep$very$o, _fnDeep$very$o2, _fnDeep$very$o3, _fn4, _fn5, _fn6, _ref7, _fn7, _ref8, _fn8, _self3, _fn9, _fn10, _classPrivateFieldLoo3, _ref9, _fn11, _ref10, _fn12, _getSelf4, _ref11, _fn13, _ref12, _fn14, _classPrivateFieldLoo4, _call2, _fn15, _getSelf5, _fn16, _getSelf6; const o = { Foo: Foo @@ -32,41 +32,41 @@ class Foo { (_o = o) === null || _o === void 0 ? void 0 : _classPrivateFieldLooseBase(_o.Foo, _x)[_x]; (_o2 = o) === null || _o2 === void 0 ? void 0 : _classPrivateFieldLooseBase(_o2.Foo, _x)[_x].toString; (_o3 = o) === null || _o3 === void 0 ? void 0 : _classPrivateFieldLooseBase(_o3.Foo, _x)[_x].toString(); - (_ref = deep?.very.o) === null || _ref === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref.Foo, _x)[_x]; - (_ref2 = deep?.very.o) === null || _ref2 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref2.Foo, _x)[_x].toString; - (_ref3 = deep?.very.o) === null || _ref3 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref3.Foo, _x)[_x].toString(); + (_deep$very$o = deep?.very.o) === null || _deep$very$o === void 0 ? void 0 : _classPrivateFieldLooseBase(_deep$very$o.Foo, _x)[_x]; + (_deep$very$o2 = deep?.very.o) === null || _deep$very$o2 === void 0 ? void 0 : _classPrivateFieldLooseBase(_deep$very$o2.Foo, _x)[_x].toString; + (_deep$very$o3 = deep?.very.o) === null || _deep$very$o3 === void 0 ? void 0 : _classPrivateFieldLooseBase(_deep$very$o3.Foo, _x)[_x].toString(); (_o4 = o) === null || _o4 === void 0 ? void 0 : _classPrivateFieldLooseBase(_classPrivateFieldLooseBase(_o4.Foo, _self)[_self], _x)[_x]; (_o5 = o) === null || _o5 === void 0 ? void 0 : _classPrivateFieldLooseBase(_classPrivateFieldLooseBase(_o5.Foo, _self)[_self].self, _x)[_x]; - (_ref4 = (_o6 = o) === null || _o6 === void 0 ? void 0 : _classPrivateFieldLooseBase(_o6.Foo, _self)[_self]) === null || _ref4 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref4.self, _x)[_x]; - (_ref5 = (_o7 = o) === null || _o7 === void 0 ? void 0 : _classPrivateFieldLooseBase(_o7.Foo, _self)[_self].self) === null || _ref5 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref5.self, _x)[_x]; - (_ref6 = ((_o8 = o) === null || _o8 === void 0 ? void 0 : _classPrivateFieldLooseBase(_o8.Foo, _self)[_self])?.self) === null || _ref6 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref6.self, _x)[_x]; + (_ref = (_o6 = o) === null || _o6 === void 0 ? void 0 : _classPrivateFieldLooseBase(_o6.Foo, _self)[_self]) === null || _ref === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref.self, _x)[_x]; + (_ref2 = (_o7 = o) === null || _o7 === void 0 ? void 0 : _classPrivateFieldLooseBase(_o7.Foo, _self)[_self].self) === null || _ref2 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref2.self, _x)[_x]; + (_self2 = ((_o8 = o) === null || _o8 === void 0 ? void 0 : _classPrivateFieldLooseBase(_o8.Foo, _self)[_self])?.self) === null || _self2 === void 0 ? void 0 : _classPrivateFieldLooseBase(_self2.self, _x)[_x]; (_o9 = o) === null || _o9 === void 0 ? void 0 : _classPrivateFieldLooseBase(_classPrivateFieldLooseBase(_o9.Foo, _self)[_self].getSelf(), _x)[_x]; - (_ref7 = (_o10 = o) === null || _o10 === void 0 ? void 0 : (_classPrivateFieldLoo = _classPrivateFieldLooseBase(_o10.Foo, _self)[_self]).getSelf) === null || _ref7 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref7.call(_classPrivateFieldLoo), _x)[_x]; - (_ref8 = (_o11 = o) === null || _o11 === void 0 ? void 0 : _classPrivateFieldLooseBase(_o11.Foo, _self)[_self]) === null || _ref8 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref8.getSelf(), _x)[_x]; - (_ref9 = (_ref10 = (_o12 = o) === null || _o12 === void 0 ? void 0 : _classPrivateFieldLooseBase(_o12.Foo, _self)[_self])?.getSelf) === null || _ref9 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref9.call(_ref10), _x)[_x]; - (_ref11 = (_o13 = o) === null || _o13 === void 0 ? void 0 : _classPrivateFieldLooseBase(_o13.Foo, _self)[_self].getSelf()) === null || _ref11 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref11.self, _x)[_x]; - (_ref12 = ((_o14 = o) === null || _o14 === void 0 ? void 0 : (_classPrivateFieldLoo2 = _classPrivateFieldLooseBase(_o14.Foo, _self)[_self]).getSelf)?.call(_classPrivateFieldLoo2)) === null || _ref12 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref12.self, _x)[_x]; - (_ref13 = ((_o15 = o) === null || _o15 === void 0 ? void 0 : _classPrivateFieldLooseBase(_o15.Foo, _self)[_self])?.getSelf()) === null || _ref13 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref13.self, _x)[_x]; - (_ref14 = ((_o16 = o) === null || _o16 === void 0 ? void 0 : _classPrivateFieldLooseBase(_o16.Foo, _self)[_self])?.getSelf?.()) === null || _ref14 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref14.self, _x)[_x]; + (_ref3 = (_o10 = o) === null || _o10 === void 0 ? void 0 : (_classPrivateFieldLoo = _classPrivateFieldLooseBase(_o10.Foo, _self)[_self]).getSelf) === null || _ref3 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref3.call(_classPrivateFieldLoo), _x)[_x]; + (_ref4 = (_o11 = o) === null || _o11 === void 0 ? void 0 : _classPrivateFieldLooseBase(_o11.Foo, _self)[_self]) === null || _ref4 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref4.getSelf(), _x)[_x]; + (_getSelf = (_ref5 = (_o12 = o) === null || _o12 === void 0 ? void 0 : _classPrivateFieldLooseBase(_o12.Foo, _self)[_self])?.getSelf) === null || _getSelf === void 0 ? void 0 : _classPrivateFieldLooseBase(_getSelf.call(_ref5), _x)[_x]; + (_ref6 = (_o13 = o) === null || _o13 === void 0 ? void 0 : _classPrivateFieldLooseBase(_o13.Foo, _self)[_self].getSelf()) === null || _ref6 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref6.self, _x)[_x]; + (_call = ((_o14 = o) === null || _o14 === void 0 ? void 0 : (_classPrivateFieldLoo2 = _classPrivateFieldLooseBase(_o14.Foo, _self)[_self]).getSelf)?.call(_classPrivateFieldLoo2)) === null || _call === void 0 ? void 0 : _classPrivateFieldLooseBase(_call.self, _x)[_x]; + (_getSelf2 = ((_o15 = o) === null || _o15 === void 0 ? void 0 : _classPrivateFieldLooseBase(_o15.Foo, _self)[_self])?.getSelf()) === null || _getSelf2 === void 0 ? void 0 : _classPrivateFieldLooseBase(_getSelf2.self, _x)[_x]; + (_getSelf3 = ((_o16 = o) === null || _o16 === void 0 ? void 0 : _classPrivateFieldLooseBase(_o16.Foo, _self)[_self])?.getSelf?.()) === null || _getSelf3 === void 0 ? void 0 : _classPrivateFieldLooseBase(_getSelf3.self, _x)[_x]; (_fn = fn) === null || _fn === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn().Foo, _x)[_x]; (_fn2 = fn) === null || _fn2 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn2().Foo, _x)[_x].toString; (_fn3 = fn) === null || _fn3 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn3().Foo, _x)[_x].toString(); - (_ref15 = fnDeep?.().very.o) === null || _ref15 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref15.Foo, _x)[_x]; - (_ref16 = fnDeep?.().very.o) === null || _ref16 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref16.Foo, _x)[_x].toString; - (_ref17 = fnDeep?.().very.o) === null || _ref17 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref17.Foo, _x)[_x].toString(); + (_fnDeep$very$o = fnDeep?.().very.o) === null || _fnDeep$very$o === void 0 ? void 0 : _classPrivateFieldLooseBase(_fnDeep$very$o.Foo, _x)[_x]; + (_fnDeep$very$o2 = fnDeep?.().very.o) === null || _fnDeep$very$o2 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fnDeep$very$o2.Foo, _x)[_x].toString; + (_fnDeep$very$o3 = fnDeep?.().very.o) === null || _fnDeep$very$o3 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fnDeep$very$o3.Foo, _x)[_x].toString(); (_fn4 = fn) === null || _fn4 === void 0 ? void 0 : _classPrivateFieldLooseBase(_classPrivateFieldLooseBase(_fn4().Foo, _self)[_self], _x)[_x]; (_fn5 = fn) === null || _fn5 === void 0 ? void 0 : _classPrivateFieldLooseBase(_classPrivateFieldLooseBase(_fn5().Foo, _self)[_self].self, _x)[_x]; - (_ref18 = (_fn6 = fn) === null || _fn6 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn6().Foo, _self)[_self]) === null || _ref18 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref18.self, _x)[_x]; - (_ref19 = (_fn7 = fn) === null || _fn7 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn7().Foo, _self)[_self].self) === null || _ref19 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref19.self, _x)[_x]; - (_ref20 = ((_fn8 = fn) === null || _fn8 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn8().Foo, _self)[_self])?.self) === null || _ref20 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref20.self, _x)[_x]; + (_ref7 = (_fn6 = fn) === null || _fn6 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn6().Foo, _self)[_self]) === null || _ref7 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref7.self, _x)[_x]; + (_ref8 = (_fn7 = fn) === null || _fn7 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn7().Foo, _self)[_self].self) === null || _ref8 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref8.self, _x)[_x]; + (_self3 = ((_fn8 = fn) === null || _fn8 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn8().Foo, _self)[_self])?.self) === null || _self3 === void 0 ? void 0 : _classPrivateFieldLooseBase(_self3.self, _x)[_x]; (_fn9 = fn) === null || _fn9 === void 0 ? void 0 : _classPrivateFieldLooseBase(_classPrivateFieldLooseBase(_fn9().Foo, _self)[_self].getSelf(), _x)[_x]; - (_ref21 = (_fn10 = fn) === null || _fn10 === void 0 ? void 0 : (_classPrivateFieldLoo3 = _classPrivateFieldLooseBase(_fn10().Foo, _self)[_self]).getSelf) === null || _ref21 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref21.call(_classPrivateFieldLoo3), _x)[_x]; - (_ref22 = (_fn11 = fn) === null || _fn11 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn11().Foo, _self)[_self]) === null || _ref22 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref22.getSelf(), _x)[_x]; - (_ref23 = (_ref24 = (_fn12 = fn) === null || _fn12 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn12().Foo, _self)[_self])?.getSelf) === null || _ref23 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref23.call(_ref24), _x)[_x]; - (_ref25 = (_fn13 = fn) === null || _fn13 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn13().Foo, _self)[_self].getSelf()) === null || _ref25 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref25.self, _x)[_x]; - (_ref26 = ((_fn14 = fn) === null || _fn14 === void 0 ? void 0 : (_classPrivateFieldLoo4 = _classPrivateFieldLooseBase(_fn14().Foo, _self)[_self]).getSelf)?.call(_classPrivateFieldLoo4)) === null || _ref26 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref26.self, _x)[_x]; - (_ref27 = ((_fn15 = fn) === null || _fn15 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn15().Foo, _self)[_self])?.getSelf()) === null || _ref27 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref27.self, _x)[_x]; - (_ref28 = ((_fn16 = fn) === null || _fn16 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn16().Foo, _self)[_self])?.getSelf?.()) === null || _ref28 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref28.self, _x)[_x]; + (_ref9 = (_fn10 = fn) === null || _fn10 === void 0 ? void 0 : (_classPrivateFieldLoo3 = _classPrivateFieldLooseBase(_fn10().Foo, _self)[_self]).getSelf) === null || _ref9 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref9.call(_classPrivateFieldLoo3), _x)[_x]; + (_ref10 = (_fn11 = fn) === null || _fn11 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn11().Foo, _self)[_self]) === null || _ref10 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref10.getSelf(), _x)[_x]; + (_getSelf4 = (_ref11 = (_fn12 = fn) === null || _fn12 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn12().Foo, _self)[_self])?.getSelf) === null || _getSelf4 === void 0 ? void 0 : _classPrivateFieldLooseBase(_getSelf4.call(_ref11), _x)[_x]; + (_ref12 = (_fn13 = fn) === null || _fn13 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn13().Foo, _self)[_self].getSelf()) === null || _ref12 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref12.self, _x)[_x]; + (_call2 = ((_fn14 = fn) === null || _fn14 === void 0 ? void 0 : (_classPrivateFieldLoo4 = _classPrivateFieldLooseBase(_fn14().Foo, _self)[_self]).getSelf)?.call(_classPrivateFieldLoo4)) === null || _call2 === void 0 ? void 0 : _classPrivateFieldLooseBase(_call2.self, _x)[_x]; + (_getSelf5 = ((_fn15 = fn) === null || _fn15 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn15().Foo, _self)[_self])?.getSelf()) === null || _getSelf5 === void 0 ? void 0 : _classPrivateFieldLooseBase(_getSelf5.self, _x)[_x]; + (_getSelf6 = ((_fn16 = fn) === null || _fn16 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn16().Foo, _self)[_self])?.getSelf?.()) === null || _getSelf6 === void 0 ? void 0 : _classPrivateFieldLooseBase(_getSelf6.self, _x)[_x]; } } diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-private-call-with-transform/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-private-call-with-transform/output.js index 89940c546c35..79eb53816731 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-private-call-with-transform/output.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-private-call-with-transform/output.js @@ -8,7 +8,7 @@ class Foo { } static test() { - var _o, _o$Foo, _o2, _o2$Foo, _o3, _o3$Foo, _ref, _ref$Foo, _ref2, _ref2$Foo, _ref3, _ref3$Foo, _o4, _classStaticPrivateFi, _o5, _classStaticPrivateFi2, _o6, _ref4, _ref4$self, _o7, _ref5, _ref5$self, _o8, _ref6, _ref6$self, _o9, _classStaticPrivateFi3, _o10, _classStaticPrivateFi4, _ref7, _ref8, _o11, _ref9, _ref10, _o12, _ref11, _ref12, _ref11$call, _o13, _ref13, _ref13$self, _o14, _classStaticPrivateFi5, _ref14, _ref14$self, _o15, _ref15, _ref15$self, _o16, _ref16, _ref16$self, _fn, _ref17, _fn2, _ref18, _fn3, _ref19, _ref20, _ref20$Foo, _ref21, _ref21$Foo, _ref22, _ref22$Foo, _fn4, _classStaticPrivateFi6, _fn5, _classStaticPrivateFi7, _fn6, _ref23, _ref23$self, _fn7, _ref24, _ref24$self, _fn8, _ref25, _ref25$self, _fn9, _classStaticPrivateFi8, _fn10, _classStaticPrivateFi9, _ref26, _ref27, _fn11, _ref28, _ref29, _fn12, _ref30, _ref31, _ref30$call, _fn13, _ref32, _ref32$self, _fn14, _classStaticPrivateFi10, _ref33, _ref33$self, _fn15, _ref34, _ref34$self, _fn16, _ref35, _ref35$self, _ref36, _ref37, _ref38, _ref39, _ref40, _ref40$getSelf, _ref41, _ref42, _ref43, _ref44, _ref45, _ref45$getSelf; + var _o, _o$Foo, _o2, _o2$Foo, _o3, _o3$Foo, _deep$very$o, _deep$very$o$Foo, _deep$very$o2, _deep$very$o2$Foo, _deep$very$o3, _deep$very$o3$Foo, _o4, _classStaticPrivateFi, _o5, _classStaticPrivateFi2, _o6, _ref, _ref$self, _o7, _ref2, _ref2$self, _o8, _self2, _self2$self, _o9, _classStaticPrivateFi3, _o10, _classStaticPrivateFi4, _ref3, _ref3$call, _o11, _ref4, _ref4$getSelf, _o12, _getSelf, _ref5, _getSelf$call, _o13, _ref6, _ref6$self, _o14, _classStaticPrivateFi5, _call, _call$self, _o15, _getSelf2, _getSelf2$self, _o16, _getSelf3, _getSelf3$self, _fn, _fn$Foo, _fn2, _fn2$Foo, _fn3, _fn3$Foo, _fnDeep$very$o, _fnDeep$very$o$Foo, _fnDeep$very$o2, _fnDeep$very$o2$Foo, _fnDeep$very$o3, _fnDeep$very$o3$Foo, _fn4, _classStaticPrivateFi6, _fn5, _classStaticPrivateFi7, _fn6, _ref7, _ref7$self, _fn7, _ref8, _ref8$self, _fn8, _self3, _self3$self, _fn9, _classStaticPrivateFi8, _fn10, _classStaticPrivateFi9, _ref9, _ref9$call, _fn11, _ref10, _ref10$getSelf, _fn12, _getSelf4, _ref11, _getSelf4$call, _fn13, _ref12, _ref12$self, _fn14, _classStaticPrivateFi10, _call2, _call2$self, _fn15, _getSelf5, _getSelf5$self, _fn16, _getSelf6, _getSelf6$self, _ref13, _ref14, _ref15, _ref16, _ref17, _ref17$getSelf, _ref18, _ref19, _ref20, _ref21, _ref22, _ref22$getSelf; const o = { Foo: Foo @@ -30,41 +30,41 @@ class Foo { (_o = o) === null || _o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o$Foo = _o.Foo, Foo, _m).call(_o$Foo); (_o2 = o) === null || _o2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o2$Foo = _o2.Foo, Foo, _m).call(_o2$Foo).toString; (_o3 = o) === null || _o3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o3$Foo = _o3.Foo, Foo, _m).call(_o3$Foo).toString(); - (_ref = deep === null || deep === void 0 ? void 0 : deep.very.o) === null || _ref === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref$Foo = _ref.Foo, Foo, _m).call(_ref$Foo); - (_ref2 = deep === null || deep === void 0 ? void 0 : deep.very.o) === null || _ref2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref2$Foo = _ref2.Foo, Foo, _m).call(_ref2$Foo).toString; - (_ref3 = deep === null || deep === void 0 ? void 0 : deep.very.o) === null || _ref3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref3$Foo = _ref3.Foo, Foo, _m).call(_ref3$Foo).toString(); + (_deep$very$o = deep === null || deep === void 0 ? void 0 : deep.very.o) === null || _deep$very$o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_deep$very$o$Foo = _deep$very$o.Foo, Foo, _m).call(_deep$very$o$Foo); + (_deep$very$o2 = deep === null || deep === void 0 ? void 0 : deep.very.o) === null || _deep$very$o2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_deep$very$o2$Foo = _deep$very$o2.Foo, Foo, _m).call(_deep$very$o2$Foo).toString; + (_deep$very$o3 = deep === null || deep === void 0 ? void 0 : deep.very.o) === null || _deep$very$o3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_deep$very$o3$Foo = _deep$very$o3.Foo, Foo, _m).call(_deep$very$o3$Foo).toString(); (_o4 = o) === null || _o4 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFi = _classStaticPrivateFieldSpecGet(_o4.Foo, Foo, _self), Foo, _m).call(_classStaticPrivateFi); (_o5 = o) === null || _o5 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFi2 = _classStaticPrivateFieldSpecGet(_o5.Foo, Foo, _self).self, Foo, _m).call(_classStaticPrivateFi2); - (_ref4 = (_o6 = o) === null || _o6 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o6.Foo, Foo, _self)) === null || _ref4 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref4$self = _ref4.self, Foo, _m).call(_ref4$self); - (_ref5 = (_o7 = o) === null || _o7 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o7.Foo, Foo, _self).self) === null || _ref5 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref5$self = _ref5.self, Foo, _m).call(_ref5$self); - (_ref6 = (_ref36 = (_o8 = o) === null || _o8 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o8.Foo, Foo, _self)) === null || _ref36 === void 0 ? void 0 : _ref36.self) === null || _ref6 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref6$self = _ref6.self, Foo, _m).call(_ref6$self); + (_ref = (_o6 = o) === null || _o6 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o6.Foo, Foo, _self)) === null || _ref === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref$self = _ref.self, Foo, _m).call(_ref$self); + (_ref2 = (_o7 = o) === null || _o7 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o7.Foo, Foo, _self).self) === null || _ref2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref2$self = _ref2.self, Foo, _m).call(_ref2$self); + (_self2 = (_ref13 = (_o8 = o) === null || _o8 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o8.Foo, Foo, _self)) === null || _ref13 === void 0 ? void 0 : _ref13.self) === null || _self2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_self2$self = _self2.self, Foo, _m).call(_self2$self); (_o9 = o) === null || _o9 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFi3 = _classStaticPrivateFieldSpecGet(_o9.Foo, Foo, _self).getSelf(), Foo, _m).call(_classStaticPrivateFi3); - (_ref7 = (_o10 = o) === null || _o10 === void 0 ? void 0 : (_classStaticPrivateFi4 = _classStaticPrivateFieldSpecGet(_o10.Foo, Foo, _self)).getSelf) === null || _ref7 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref8 = _ref7.call(_classStaticPrivateFi4), Foo, _m).call(_ref8); - (_ref9 = (_o11 = o) === null || _o11 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o11.Foo, Foo, _self)) === null || _ref9 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref10 = _ref9.getSelf(), Foo, _m).call(_ref10); - (_ref11 = (_ref37 = _ref12 = (_o12 = o) === null || _o12 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o12.Foo, Foo, _self)) === null || _ref37 === void 0 ? void 0 : _ref37.getSelf) === null || _ref11 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref11$call = _ref11.call(_ref12), Foo, _m).call(_ref11$call); - (_ref13 = (_o13 = o) === null || _o13 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o13.Foo, Foo, _self).getSelf()) === null || _ref13 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref13$self = _ref13.self, Foo, _m).call(_ref13$self); - (_ref14 = (_ref38 = (_o14 = o) === null || _o14 === void 0 ? void 0 : (_classStaticPrivateFi5 = _classStaticPrivateFieldSpecGet(_o14.Foo, Foo, _self)).getSelf) === null || _ref38 === void 0 ? void 0 : _ref38.call(_classStaticPrivateFi5)) === null || _ref14 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref14$self = _ref14.self, Foo, _m).call(_ref14$self); - (_ref15 = (_ref39 = (_o15 = o) === null || _o15 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o15.Foo, Foo, _self)) === null || _ref39 === void 0 ? void 0 : _ref39.getSelf()) === null || _ref15 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref15$self = _ref15.self, Foo, _m).call(_ref15$self); - (_ref16 = (_ref40 = (_o16 = o) === null || _o16 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o16.Foo, Foo, _self)) === null || _ref40 === void 0 ? void 0 : (_ref40$getSelf = _ref40.getSelf) === null || _ref40$getSelf === void 0 ? void 0 : _ref40$getSelf.call(_ref40)) === null || _ref16 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref16$self = _ref16.self, Foo, _m).call(_ref16$self); - (_fn = fn) === null || _fn === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref17 = _fn().Foo, Foo, _m).call(_ref17); - (_fn2 = fn) === null || _fn2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref18 = _fn2().Foo, Foo, _m).call(_ref18).toString; - (_fn3 = fn) === null || _fn3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref19 = _fn3().Foo, Foo, _m).call(_ref19).toString(); - (_ref20 = fnDeep === null || fnDeep === void 0 ? void 0 : fnDeep().very.o) === null || _ref20 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref20$Foo = _ref20.Foo, Foo, _m).call(_ref20$Foo); - (_ref21 = fnDeep === null || fnDeep === void 0 ? void 0 : fnDeep().very.o) === null || _ref21 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref21$Foo = _ref21.Foo, Foo, _m).call(_ref21$Foo).toString; - (_ref22 = fnDeep === null || fnDeep === void 0 ? void 0 : fnDeep().very.o) === null || _ref22 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref22$Foo = _ref22.Foo, Foo, _m).call(_ref22$Foo).toString(); + (_ref3 = (_o10 = o) === null || _o10 === void 0 ? void 0 : (_classStaticPrivateFi4 = _classStaticPrivateFieldSpecGet(_o10.Foo, Foo, _self)).getSelf) === null || _ref3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref3$call = _ref3.call(_classStaticPrivateFi4), Foo, _m).call(_ref3$call); + (_ref4 = (_o11 = o) === null || _o11 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o11.Foo, Foo, _self)) === null || _ref4 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref4$getSelf = _ref4.getSelf(), Foo, _m).call(_ref4$getSelf); + (_getSelf = (_ref14 = _ref5 = (_o12 = o) === null || _o12 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o12.Foo, Foo, _self)) === null || _ref14 === void 0 ? void 0 : _ref14.getSelf) === null || _getSelf === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_getSelf$call = _getSelf.call(_ref5), Foo, _m).call(_getSelf$call); + (_ref6 = (_o13 = o) === null || _o13 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o13.Foo, Foo, _self).getSelf()) === null || _ref6 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref6$self = _ref6.self, Foo, _m).call(_ref6$self); + (_call = (_ref15 = (_o14 = o) === null || _o14 === void 0 ? void 0 : (_classStaticPrivateFi5 = _classStaticPrivateFieldSpecGet(_o14.Foo, Foo, _self)).getSelf) === null || _ref15 === void 0 ? void 0 : _ref15.call(_classStaticPrivateFi5)) === null || _call === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_call$self = _call.self, Foo, _m).call(_call$self); + (_getSelf2 = (_ref16 = (_o15 = o) === null || _o15 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o15.Foo, Foo, _self)) === null || _ref16 === void 0 ? void 0 : _ref16.getSelf()) === null || _getSelf2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_getSelf2$self = _getSelf2.self, Foo, _m).call(_getSelf2$self); + (_getSelf3 = (_ref17 = (_o16 = o) === null || _o16 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o16.Foo, Foo, _self)) === null || _ref17 === void 0 ? void 0 : (_ref17$getSelf = _ref17.getSelf) === null || _ref17$getSelf === void 0 ? void 0 : _ref17$getSelf.call(_ref17)) === null || _getSelf3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_getSelf3$self = _getSelf3.self, Foo, _m).call(_getSelf3$self); + (_fn = fn) === null || _fn === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn$Foo = _fn().Foo, Foo, _m).call(_fn$Foo); + (_fn2 = fn) === null || _fn2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn2$Foo = _fn2().Foo, Foo, _m).call(_fn2$Foo).toString; + (_fn3 = fn) === null || _fn3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn3$Foo = _fn3().Foo, Foo, _m).call(_fn3$Foo).toString(); + (_fnDeep$very$o = fnDeep === null || fnDeep === void 0 ? void 0 : fnDeep().very.o) === null || _fnDeep$very$o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fnDeep$very$o$Foo = _fnDeep$very$o.Foo, Foo, _m).call(_fnDeep$very$o$Foo); + (_fnDeep$very$o2 = fnDeep === null || fnDeep === void 0 ? void 0 : fnDeep().very.o) === null || _fnDeep$very$o2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fnDeep$very$o2$Foo = _fnDeep$very$o2.Foo, Foo, _m).call(_fnDeep$very$o2$Foo).toString; + (_fnDeep$very$o3 = fnDeep === null || fnDeep === void 0 ? void 0 : fnDeep().very.o) === null || _fnDeep$very$o3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fnDeep$very$o3$Foo = _fnDeep$very$o3.Foo, Foo, _m).call(_fnDeep$very$o3$Foo).toString(); (_fn4 = fn) === null || _fn4 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFi6 = _classStaticPrivateFieldSpecGet(_fn4().Foo, Foo, _self), Foo, _m).call(_classStaticPrivateFi6); (_fn5 = fn) === null || _fn5 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFi7 = _classStaticPrivateFieldSpecGet(_fn5().Foo, Foo, _self).self, Foo, _m).call(_classStaticPrivateFi7); - (_ref23 = (_fn6 = fn) === null || _fn6 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn6().Foo, Foo, _self)) === null || _ref23 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref23$self = _ref23.self, Foo, _m).call(_ref23$self); - (_ref24 = (_fn7 = fn) === null || _fn7 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn7().Foo, Foo, _self).self) === null || _ref24 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref24$self = _ref24.self, Foo, _m).call(_ref24$self); - (_ref25 = (_ref41 = (_fn8 = fn) === null || _fn8 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn8().Foo, Foo, _self)) === null || _ref41 === void 0 ? void 0 : _ref41.self) === null || _ref25 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref25$self = _ref25.self, Foo, _m).call(_ref25$self); + (_ref7 = (_fn6 = fn) === null || _fn6 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn6().Foo, Foo, _self)) === null || _ref7 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref7$self = _ref7.self, Foo, _m).call(_ref7$self); + (_ref8 = (_fn7 = fn) === null || _fn7 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn7().Foo, Foo, _self).self) === null || _ref8 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref8$self = _ref8.self, Foo, _m).call(_ref8$self); + (_self3 = (_ref18 = (_fn8 = fn) === null || _fn8 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn8().Foo, Foo, _self)) === null || _ref18 === void 0 ? void 0 : _ref18.self) === null || _self3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_self3$self = _self3.self, Foo, _m).call(_self3$self); (_fn9 = fn) === null || _fn9 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFi8 = _classStaticPrivateFieldSpecGet(_fn9().Foo, Foo, _self).getSelf(), Foo, _m).call(_classStaticPrivateFi8); - (_ref26 = (_fn10 = fn) === null || _fn10 === void 0 ? void 0 : (_classStaticPrivateFi9 = _classStaticPrivateFieldSpecGet(_fn10().Foo, Foo, _self)).getSelf) === null || _ref26 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref27 = _ref26.call(_classStaticPrivateFi9), Foo, _m).call(_ref27); - (_ref28 = (_fn11 = fn) === null || _fn11 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn11().Foo, Foo, _self)) === null || _ref28 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref29 = _ref28.getSelf(), Foo, _m).call(_ref29); - (_ref30 = (_ref42 = _ref31 = (_fn12 = fn) === null || _fn12 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn12().Foo, Foo, _self)) === null || _ref42 === void 0 ? void 0 : _ref42.getSelf) === null || _ref30 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref30$call = _ref30.call(_ref31), Foo, _m).call(_ref30$call); - (_ref32 = (_fn13 = fn) === null || _fn13 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn13().Foo, Foo, _self).getSelf()) === null || _ref32 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref32$self = _ref32.self, Foo, _m).call(_ref32$self); - (_ref33 = (_ref43 = (_fn14 = fn) === null || _fn14 === void 0 ? void 0 : (_classStaticPrivateFi10 = _classStaticPrivateFieldSpecGet(_fn14().Foo, Foo, _self)).getSelf) === null || _ref43 === void 0 ? void 0 : _ref43.call(_classStaticPrivateFi10)) === null || _ref33 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref33$self = _ref33.self, Foo, _m).call(_ref33$self); - (_ref34 = (_ref44 = (_fn15 = fn) === null || _fn15 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn15().Foo, Foo, _self)) === null || _ref44 === void 0 ? void 0 : _ref44.getSelf()) === null || _ref34 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref34$self = _ref34.self, Foo, _m).call(_ref34$self); - (_ref35 = (_ref45 = (_fn16 = fn) === null || _fn16 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn16().Foo, Foo, _self)) === null || _ref45 === void 0 ? void 0 : (_ref45$getSelf = _ref45.getSelf) === null || _ref45$getSelf === void 0 ? void 0 : _ref45$getSelf.call(_ref45)) === null || _ref35 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref35$self = _ref35.self, Foo, _m).call(_ref35$self); + (_ref9 = (_fn10 = fn) === null || _fn10 === void 0 ? void 0 : (_classStaticPrivateFi9 = _classStaticPrivateFieldSpecGet(_fn10().Foo, Foo, _self)).getSelf) === null || _ref9 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref9$call = _ref9.call(_classStaticPrivateFi9), Foo, _m).call(_ref9$call); + (_ref10 = (_fn11 = fn) === null || _fn11 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn11().Foo, Foo, _self)) === null || _ref10 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref10$getSelf = _ref10.getSelf(), Foo, _m).call(_ref10$getSelf); + (_getSelf4 = (_ref19 = _ref11 = (_fn12 = fn) === null || _fn12 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn12().Foo, Foo, _self)) === null || _ref19 === void 0 ? void 0 : _ref19.getSelf) === null || _getSelf4 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_getSelf4$call = _getSelf4.call(_ref11), Foo, _m).call(_getSelf4$call); + (_ref12 = (_fn13 = fn) === null || _fn13 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn13().Foo, Foo, _self).getSelf()) === null || _ref12 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref12$self = _ref12.self, Foo, _m).call(_ref12$self); + (_call2 = (_ref20 = (_fn14 = fn) === null || _fn14 === void 0 ? void 0 : (_classStaticPrivateFi10 = _classStaticPrivateFieldSpecGet(_fn14().Foo, Foo, _self)).getSelf) === null || _ref20 === void 0 ? void 0 : _ref20.call(_classStaticPrivateFi10)) === null || _call2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_call2$self = _call2.self, Foo, _m).call(_call2$self); + (_getSelf5 = (_ref21 = (_fn15 = fn) === null || _fn15 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn15().Foo, Foo, _self)) === null || _ref21 === void 0 ? void 0 : _ref21.getSelf()) === null || _getSelf5 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_getSelf5$self = _getSelf5.self, Foo, _m).call(_getSelf5$self); + (_getSelf6 = (_ref22 = (_fn16 = fn) === null || _fn16 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn16().Foo, Foo, _self)) === null || _ref22 === void 0 ? void 0 : (_ref22$getSelf = _ref22.getSelf) === null || _ref22$getSelf === void 0 ? void 0 : _ref22$getSelf.call(_ref22)) === null || _getSelf6 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_getSelf6$self = _getSelf6.self, Foo, _m).call(_getSelf6$self); } } diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-private-call/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-private-call/output.js index 8889372935c9..ccce528eeb79 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-private-call/output.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-private-call/output.js @@ -8,7 +8,7 @@ class Foo { } static test() { - var _o, _o$Foo, _o2, _o2$Foo, _o3, _o3$Foo, _ref, _ref$Foo, _ref2, _ref2$Foo, _ref3, _ref3$Foo, _o4, _classStaticPrivateFi, _o5, _classStaticPrivateFi2, _o6, _ref4, _ref4$self, _o7, _ref5, _ref5$self, _o8, _ref6, _ref6$self, _o9, _classStaticPrivateFi3, _o10, _classStaticPrivateFi4, _ref7, _ref8, _o11, _ref9, _ref10, _o12, _ref11, _ref12, _ref11$call, _o13, _ref13, _ref13$self, _o14, _classStaticPrivateFi5, _ref14, _ref14$self, _o15, _ref15, _ref15$self, _o16, _ref16, _ref16$self, _fn, _ref17, _fn2, _ref18, _fn3, _ref19, _ref20, _ref20$Foo, _ref21, _ref21$Foo, _ref22, _ref22$Foo, _fn4, _classStaticPrivateFi6, _fn5, _classStaticPrivateFi7, _fn6, _ref23, _ref23$self, _fn7, _ref24, _ref24$self, _fn8, _ref25, _ref25$self, _fn9, _classStaticPrivateFi8, _fn10, _classStaticPrivateFi9, _ref26, _ref27, _fn11, _ref28, _ref29, _fn12, _ref30, _ref31, _ref30$call, _fn13, _ref32, _ref32$self, _fn14, _classStaticPrivateFi10, _ref33, _ref33$self, _fn15, _ref34, _ref34$self, _fn16, _ref35, _ref35$self; + var _o, _o$Foo, _o2, _o2$Foo, _o3, _o3$Foo, _deep$very$o, _deep$very$o$Foo, _deep$very$o2, _deep$very$o2$Foo, _deep$very$o3, _deep$very$o3$Foo, _o4, _classStaticPrivateFi, _o5, _classStaticPrivateFi2, _o6, _ref, _ref$self, _o7, _ref2, _ref2$self, _o8, _self2, _self2$self, _o9, _classStaticPrivateFi3, _o10, _classStaticPrivateFi4, _ref3, _ref3$call, _o11, _ref4, _ref4$getSelf, _o12, _getSelf, _ref5, _getSelf$call, _o13, _ref6, _ref6$self, _o14, _classStaticPrivateFi5, _call, _call$self, _o15, _getSelf2, _getSelf2$self, _o16, _getSelf3, _getSelf3$self, _fn, _fn$Foo, _fn2, _fn2$Foo, _fn3, _fn3$Foo, _fnDeep$very$o, _fnDeep$very$o$Foo, _fnDeep$very$o2, _fnDeep$very$o2$Foo, _fnDeep$very$o3, _fnDeep$very$o3$Foo, _fn4, _classStaticPrivateFi6, _fn5, _classStaticPrivateFi7, _fn6, _ref7, _ref7$self, _fn7, _ref8, _ref8$self, _fn8, _self3, _self3$self, _fn9, _classStaticPrivateFi8, _fn10, _classStaticPrivateFi9, _ref9, _ref9$call, _fn11, _ref10, _ref10$getSelf, _fn12, _getSelf4, _ref11, _getSelf4$call, _fn13, _ref12, _ref12$self, _fn14, _classStaticPrivateFi10, _call2, _call2$self, _fn15, _getSelf5, _getSelf5$self, _fn16, _getSelf6, _getSelf6$self; const o = { Foo: Foo @@ -30,41 +30,41 @@ class Foo { (_o = o) === null || _o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o$Foo = _o.Foo, Foo, _m).call(_o$Foo); (_o2 = o) === null || _o2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o2$Foo = _o2.Foo, Foo, _m).call(_o2$Foo).toString; (_o3 = o) === null || _o3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o3$Foo = _o3.Foo, Foo, _m).call(_o3$Foo).toString(); - (_ref = deep?.very.o) === null || _ref === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref$Foo = _ref.Foo, Foo, _m).call(_ref$Foo); - (_ref2 = deep?.very.o) === null || _ref2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref2$Foo = _ref2.Foo, Foo, _m).call(_ref2$Foo).toString; - (_ref3 = deep?.very.o) === null || _ref3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref3$Foo = _ref3.Foo, Foo, _m).call(_ref3$Foo).toString(); + (_deep$very$o = deep?.very.o) === null || _deep$very$o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_deep$very$o$Foo = _deep$very$o.Foo, Foo, _m).call(_deep$very$o$Foo); + (_deep$very$o2 = deep?.very.o) === null || _deep$very$o2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_deep$very$o2$Foo = _deep$very$o2.Foo, Foo, _m).call(_deep$very$o2$Foo).toString; + (_deep$very$o3 = deep?.very.o) === null || _deep$very$o3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_deep$very$o3$Foo = _deep$very$o3.Foo, Foo, _m).call(_deep$very$o3$Foo).toString(); (_o4 = o) === null || _o4 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFi = _classStaticPrivateFieldSpecGet(_o4.Foo, Foo, _self), Foo, _m).call(_classStaticPrivateFi); (_o5 = o) === null || _o5 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFi2 = _classStaticPrivateFieldSpecGet(_o5.Foo, Foo, _self).self, Foo, _m).call(_classStaticPrivateFi2); - (_ref4 = (_o6 = o) === null || _o6 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o6.Foo, Foo, _self)) === null || _ref4 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref4$self = _ref4.self, Foo, _m).call(_ref4$self); - (_ref5 = (_o7 = o) === null || _o7 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o7.Foo, Foo, _self).self) === null || _ref5 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref5$self = _ref5.self, Foo, _m).call(_ref5$self); - (_ref6 = ((_o8 = o) === null || _o8 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o8.Foo, Foo, _self))?.self) === null || _ref6 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref6$self = _ref6.self, Foo, _m).call(_ref6$self); + (_ref = (_o6 = o) === null || _o6 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o6.Foo, Foo, _self)) === null || _ref === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref$self = _ref.self, Foo, _m).call(_ref$self); + (_ref2 = (_o7 = o) === null || _o7 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o7.Foo, Foo, _self).self) === null || _ref2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref2$self = _ref2.self, Foo, _m).call(_ref2$self); + (_self2 = ((_o8 = o) === null || _o8 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o8.Foo, Foo, _self))?.self) === null || _self2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_self2$self = _self2.self, Foo, _m).call(_self2$self); (_o9 = o) === null || _o9 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFi3 = _classStaticPrivateFieldSpecGet(_o9.Foo, Foo, _self).getSelf(), Foo, _m).call(_classStaticPrivateFi3); - (_ref7 = (_o10 = o) === null || _o10 === void 0 ? void 0 : (_classStaticPrivateFi4 = _classStaticPrivateFieldSpecGet(_o10.Foo, Foo, _self)).getSelf) === null || _ref7 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref8 = _ref7.call(_classStaticPrivateFi4), Foo, _m).call(_ref8); - (_ref9 = (_o11 = o) === null || _o11 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o11.Foo, Foo, _self)) === null || _ref9 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref10 = _ref9.getSelf(), Foo, _m).call(_ref10); - (_ref11 = (_ref12 = (_o12 = o) === null || _o12 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o12.Foo, Foo, _self))?.getSelf) === null || _ref11 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref11$call = _ref11.call(_ref12), Foo, _m).call(_ref11$call); - (_ref13 = (_o13 = o) === null || _o13 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o13.Foo, Foo, _self).getSelf()) === null || _ref13 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref13$self = _ref13.self, Foo, _m).call(_ref13$self); - (_ref14 = ((_o14 = o) === null || _o14 === void 0 ? void 0 : (_classStaticPrivateFi5 = _classStaticPrivateFieldSpecGet(_o14.Foo, Foo, _self)).getSelf)?.call(_classStaticPrivateFi5)) === null || _ref14 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref14$self = _ref14.self, Foo, _m).call(_ref14$self); - (_ref15 = ((_o15 = o) === null || _o15 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o15.Foo, Foo, _self))?.getSelf()) === null || _ref15 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref15$self = _ref15.self, Foo, _m).call(_ref15$self); - (_ref16 = ((_o16 = o) === null || _o16 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o16.Foo, Foo, _self))?.getSelf?.()) === null || _ref16 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref16$self = _ref16.self, Foo, _m).call(_ref16$self); - (_fn = fn) === null || _fn === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref17 = _fn().Foo, Foo, _m).call(_ref17); - (_fn2 = fn) === null || _fn2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref18 = _fn2().Foo, Foo, _m).call(_ref18).toString; - (_fn3 = fn) === null || _fn3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref19 = _fn3().Foo, Foo, _m).call(_ref19).toString(); - (_ref20 = fnDeep?.().very.o) === null || _ref20 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref20$Foo = _ref20.Foo, Foo, _m).call(_ref20$Foo); - (_ref21 = fnDeep?.().very.o) === null || _ref21 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref21$Foo = _ref21.Foo, Foo, _m).call(_ref21$Foo).toString; - (_ref22 = fnDeep?.().very.o) === null || _ref22 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref22$Foo = _ref22.Foo, Foo, _m).call(_ref22$Foo).toString(); + (_ref3 = (_o10 = o) === null || _o10 === void 0 ? void 0 : (_classStaticPrivateFi4 = _classStaticPrivateFieldSpecGet(_o10.Foo, Foo, _self)).getSelf) === null || _ref3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref3$call = _ref3.call(_classStaticPrivateFi4), Foo, _m).call(_ref3$call); + (_ref4 = (_o11 = o) === null || _o11 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o11.Foo, Foo, _self)) === null || _ref4 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref4$getSelf = _ref4.getSelf(), Foo, _m).call(_ref4$getSelf); + (_getSelf = (_ref5 = (_o12 = o) === null || _o12 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o12.Foo, Foo, _self))?.getSelf) === null || _getSelf === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_getSelf$call = _getSelf.call(_ref5), Foo, _m).call(_getSelf$call); + (_ref6 = (_o13 = o) === null || _o13 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o13.Foo, Foo, _self).getSelf()) === null || _ref6 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref6$self = _ref6.self, Foo, _m).call(_ref6$self); + (_call = ((_o14 = o) === null || _o14 === void 0 ? void 0 : (_classStaticPrivateFi5 = _classStaticPrivateFieldSpecGet(_o14.Foo, Foo, _self)).getSelf)?.call(_classStaticPrivateFi5)) === null || _call === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_call$self = _call.self, Foo, _m).call(_call$self); + (_getSelf2 = ((_o15 = o) === null || _o15 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o15.Foo, Foo, _self))?.getSelf()) === null || _getSelf2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_getSelf2$self = _getSelf2.self, Foo, _m).call(_getSelf2$self); + (_getSelf3 = ((_o16 = o) === null || _o16 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o16.Foo, Foo, _self))?.getSelf?.()) === null || _getSelf3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_getSelf3$self = _getSelf3.self, Foo, _m).call(_getSelf3$self); + (_fn = fn) === null || _fn === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn$Foo = _fn().Foo, Foo, _m).call(_fn$Foo); + (_fn2 = fn) === null || _fn2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn2$Foo = _fn2().Foo, Foo, _m).call(_fn2$Foo).toString; + (_fn3 = fn) === null || _fn3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn3$Foo = _fn3().Foo, Foo, _m).call(_fn3$Foo).toString(); + (_fnDeep$very$o = fnDeep?.().very.o) === null || _fnDeep$very$o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fnDeep$very$o$Foo = _fnDeep$very$o.Foo, Foo, _m).call(_fnDeep$very$o$Foo); + (_fnDeep$very$o2 = fnDeep?.().very.o) === null || _fnDeep$very$o2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fnDeep$very$o2$Foo = _fnDeep$very$o2.Foo, Foo, _m).call(_fnDeep$very$o2$Foo).toString; + (_fnDeep$very$o3 = fnDeep?.().very.o) === null || _fnDeep$very$o3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fnDeep$very$o3$Foo = _fnDeep$very$o3.Foo, Foo, _m).call(_fnDeep$very$o3$Foo).toString(); (_fn4 = fn) === null || _fn4 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFi6 = _classStaticPrivateFieldSpecGet(_fn4().Foo, Foo, _self), Foo, _m).call(_classStaticPrivateFi6); (_fn5 = fn) === null || _fn5 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFi7 = _classStaticPrivateFieldSpecGet(_fn5().Foo, Foo, _self).self, Foo, _m).call(_classStaticPrivateFi7); - (_ref23 = (_fn6 = fn) === null || _fn6 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn6().Foo, Foo, _self)) === null || _ref23 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref23$self = _ref23.self, Foo, _m).call(_ref23$self); - (_ref24 = (_fn7 = fn) === null || _fn7 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn7().Foo, Foo, _self).self) === null || _ref24 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref24$self = _ref24.self, Foo, _m).call(_ref24$self); - (_ref25 = ((_fn8 = fn) === null || _fn8 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn8().Foo, Foo, _self))?.self) === null || _ref25 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref25$self = _ref25.self, Foo, _m).call(_ref25$self); + (_ref7 = (_fn6 = fn) === null || _fn6 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn6().Foo, Foo, _self)) === null || _ref7 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref7$self = _ref7.self, Foo, _m).call(_ref7$self); + (_ref8 = (_fn7 = fn) === null || _fn7 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn7().Foo, Foo, _self).self) === null || _ref8 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref8$self = _ref8.self, Foo, _m).call(_ref8$self); + (_self3 = ((_fn8 = fn) === null || _fn8 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn8().Foo, Foo, _self))?.self) === null || _self3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_self3$self = _self3.self, Foo, _m).call(_self3$self); (_fn9 = fn) === null || _fn9 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFi8 = _classStaticPrivateFieldSpecGet(_fn9().Foo, Foo, _self).getSelf(), Foo, _m).call(_classStaticPrivateFi8); - (_ref26 = (_fn10 = fn) === null || _fn10 === void 0 ? void 0 : (_classStaticPrivateFi9 = _classStaticPrivateFieldSpecGet(_fn10().Foo, Foo, _self)).getSelf) === null || _ref26 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref27 = _ref26.call(_classStaticPrivateFi9), Foo, _m).call(_ref27); - (_ref28 = (_fn11 = fn) === null || _fn11 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn11().Foo, Foo, _self)) === null || _ref28 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref29 = _ref28.getSelf(), Foo, _m).call(_ref29); - (_ref30 = (_ref31 = (_fn12 = fn) === null || _fn12 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn12().Foo, Foo, _self))?.getSelf) === null || _ref30 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref30$call = _ref30.call(_ref31), Foo, _m).call(_ref30$call); - (_ref32 = (_fn13 = fn) === null || _fn13 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn13().Foo, Foo, _self).getSelf()) === null || _ref32 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref32$self = _ref32.self, Foo, _m).call(_ref32$self); - (_ref33 = ((_fn14 = fn) === null || _fn14 === void 0 ? void 0 : (_classStaticPrivateFi10 = _classStaticPrivateFieldSpecGet(_fn14().Foo, Foo, _self)).getSelf)?.call(_classStaticPrivateFi10)) === null || _ref33 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref33$self = _ref33.self, Foo, _m).call(_ref33$self); - (_ref34 = ((_fn15 = fn) === null || _fn15 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn15().Foo, Foo, _self))?.getSelf()) === null || _ref34 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref34$self = _ref34.self, Foo, _m).call(_ref34$self); - (_ref35 = ((_fn16 = fn) === null || _fn16 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn16().Foo, Foo, _self))?.getSelf?.()) === null || _ref35 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref35$self = _ref35.self, Foo, _m).call(_ref35$self); + (_ref9 = (_fn10 = fn) === null || _fn10 === void 0 ? void 0 : (_classStaticPrivateFi9 = _classStaticPrivateFieldSpecGet(_fn10().Foo, Foo, _self)).getSelf) === null || _ref9 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref9$call = _ref9.call(_classStaticPrivateFi9), Foo, _m).call(_ref9$call); + (_ref10 = (_fn11 = fn) === null || _fn11 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn11().Foo, Foo, _self)) === null || _ref10 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref10$getSelf = _ref10.getSelf(), Foo, _m).call(_ref10$getSelf); + (_getSelf4 = (_ref11 = (_fn12 = fn) === null || _fn12 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn12().Foo, Foo, _self))?.getSelf) === null || _getSelf4 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_getSelf4$call = _getSelf4.call(_ref11), Foo, _m).call(_getSelf4$call); + (_ref12 = (_fn13 = fn) === null || _fn13 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn13().Foo, Foo, _self).getSelf()) === null || _ref12 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref12$self = _ref12.self, Foo, _m).call(_ref12$self); + (_call2 = ((_fn14 = fn) === null || _fn14 === void 0 ? void 0 : (_classStaticPrivateFi10 = _classStaticPrivateFieldSpecGet(_fn14().Foo, Foo, _self)).getSelf)?.call(_classStaticPrivateFi10)) === null || _call2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_call2$self = _call2.self, Foo, _m).call(_call2$self); + (_getSelf5 = ((_fn15 = fn) === null || _fn15 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn15().Foo, Foo, _self))?.getSelf()) === null || _getSelf5 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_getSelf5$self = _getSelf5.self, Foo, _m).call(_getSelf5$self); + (_getSelf6 = ((_fn16 = fn) === null || _fn16 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn16().Foo, Foo, _self))?.getSelf?.()) === null || _getSelf6 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_getSelf6$self = _getSelf6.self, Foo, _m).call(_getSelf6$self); } } diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-with-transform/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-with-transform/output.js index 1525a03dc3cd..d5ef32b86918 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-with-transform/output.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-with-transform/output.js @@ -8,7 +8,7 @@ class Foo { } static test() { - var _o, _o2, _o3, _ref, _ref2, _ref3, _o4, _o5, _o6, _ref4, _o7, _ref5, _o8, _ref6, _o9, _o10, _classStaticPrivateFi, _ref7, _o11, _ref8, _o12, _ref9, _ref10, _o13, _ref11, _o14, _classStaticPrivateFi2, _ref12, _o15, _ref13, _o16, _ref14, _fn, _fn2, _fn3, _ref15, _ref16, _ref17, _fn4, _fn5, _fn6, _ref18, _fn7, _ref19, _fn8, _ref20, _fn9, _fn10, _classStaticPrivateFi3, _ref21, _fn11, _ref22, _fn12, _ref23, _ref24, _fn13, _ref25, _fn14, _classStaticPrivateFi4, _ref26, _fn15, _ref27, _fn16, _ref28, _ref29, _ref30, _ref31, _ref32, _ref33, _ref33$getSelf, _ref34, _ref35, _ref36, _ref37, _ref38, _ref38$getSelf; + var _o, _o2, _o3, _deep$very$o, _deep$very$o2, _deep$very$o3, _o4, _o5, _o6, _ref, _o7, _ref2, _o8, _self2, _o9, _o10, _classStaticPrivateFi, _ref3, _o11, _ref4, _o12, _getSelf, _ref5, _o13, _ref6, _o14, _classStaticPrivateFi2, _call, _o15, _getSelf2, _o16, _getSelf3, _fn, _fn2, _fn3, _fnDeep$very$o, _fnDeep$very$o2, _fnDeep$very$o3, _fn4, _fn5, _fn6, _ref7, _fn7, _ref8, _fn8, _self3, _fn9, _fn10, _classStaticPrivateFi3, _ref9, _fn11, _ref10, _fn12, _getSelf4, _ref11, _fn13, _ref12, _fn14, _classStaticPrivateFi4, _call2, _fn15, _getSelf5, _fn16, _getSelf6, _ref13, _ref14, _ref15, _ref16, _ref17, _ref17$getSelf, _ref18, _ref19, _ref20, _ref21, _ref22, _ref22$getSelf; const o = { Foo: Foo @@ -30,41 +30,41 @@ class Foo { (_o = o) === null || _o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o.Foo, Foo, _x); (_o2 = o) === null || _o2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o2.Foo, Foo, _x).toString; (_o3 = o) === null || _o3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o3.Foo, Foo, _x).toString(); - (_ref = deep === null || deep === void 0 ? void 0 : deep.very.o) === null || _ref === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref.Foo, Foo, _x); - (_ref2 = deep === null || deep === void 0 ? void 0 : deep.very.o) === null || _ref2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref2.Foo, Foo, _x).toString; - (_ref3 = deep === null || deep === void 0 ? void 0 : deep.very.o) === null || _ref3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref3.Foo, Foo, _x).toString(); + (_deep$very$o = deep === null || deep === void 0 ? void 0 : deep.very.o) === null || _deep$very$o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_deep$very$o.Foo, Foo, _x); + (_deep$very$o2 = deep === null || deep === void 0 ? void 0 : deep.very.o) === null || _deep$very$o2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_deep$very$o2.Foo, Foo, _x).toString; + (_deep$very$o3 = deep === null || deep === void 0 ? void 0 : deep.very.o) === null || _deep$very$o3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_deep$very$o3.Foo, Foo, _x).toString(); (_o4 = o) === null || _o4 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFieldSpecGet(_o4.Foo, Foo, _self), Foo, _x); (_o5 = o) === null || _o5 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFieldSpecGet(_o5.Foo, Foo, _self).self, Foo, _x); - (_ref4 = (_o6 = o) === null || _o6 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o6.Foo, Foo, _self)) === null || _ref4 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref4.self, Foo, _x); - (_ref5 = (_o7 = o) === null || _o7 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o7.Foo, Foo, _self).self) === null || _ref5 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref5.self, Foo, _x); - (_ref6 = (_ref29 = (_o8 = o) === null || _o8 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o8.Foo, Foo, _self)) === null || _ref29 === void 0 ? void 0 : _ref29.self) === null || _ref6 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref6.self, Foo, _x); + (_ref = (_o6 = o) === null || _o6 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o6.Foo, Foo, _self)) === null || _ref === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref.self, Foo, _x); + (_ref2 = (_o7 = o) === null || _o7 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o7.Foo, Foo, _self).self) === null || _ref2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref2.self, Foo, _x); + (_self2 = (_ref13 = (_o8 = o) === null || _o8 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o8.Foo, Foo, _self)) === null || _ref13 === void 0 ? void 0 : _ref13.self) === null || _self2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_self2.self, Foo, _x); (_o9 = o) === null || _o9 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFieldSpecGet(_o9.Foo, Foo, _self).getSelf(), Foo, _x); - (_ref7 = (_o10 = o) === null || _o10 === void 0 ? void 0 : (_classStaticPrivateFi = _classStaticPrivateFieldSpecGet(_o10.Foo, Foo, _self)).getSelf) === null || _ref7 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref7.call(_classStaticPrivateFi), Foo, _x); - (_ref8 = (_o11 = o) === null || _o11 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o11.Foo, Foo, _self)) === null || _ref8 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref8.getSelf(), Foo, _x); - (_ref9 = (_ref30 = _ref10 = (_o12 = o) === null || _o12 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o12.Foo, Foo, _self)) === null || _ref30 === void 0 ? void 0 : _ref30.getSelf) === null || _ref9 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref9.call(_ref10), Foo, _x); - (_ref11 = (_o13 = o) === null || _o13 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o13.Foo, Foo, _self).getSelf()) === null || _ref11 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref11.self, Foo, _x); - (_ref12 = (_ref31 = (_o14 = o) === null || _o14 === void 0 ? void 0 : (_classStaticPrivateFi2 = _classStaticPrivateFieldSpecGet(_o14.Foo, Foo, _self)).getSelf) === null || _ref31 === void 0 ? void 0 : _ref31.call(_classStaticPrivateFi2)) === null || _ref12 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref12.self, Foo, _x); - (_ref13 = (_ref32 = (_o15 = o) === null || _o15 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o15.Foo, Foo, _self)) === null || _ref32 === void 0 ? void 0 : _ref32.getSelf()) === null || _ref13 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref13.self, Foo, _x); - (_ref14 = (_ref33 = (_o16 = o) === null || _o16 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o16.Foo, Foo, _self)) === null || _ref33 === void 0 ? void 0 : (_ref33$getSelf = _ref33.getSelf) === null || _ref33$getSelf === void 0 ? void 0 : _ref33$getSelf.call(_ref33)) === null || _ref14 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref14.self, Foo, _x); + (_ref3 = (_o10 = o) === null || _o10 === void 0 ? void 0 : (_classStaticPrivateFi = _classStaticPrivateFieldSpecGet(_o10.Foo, Foo, _self)).getSelf) === null || _ref3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref3.call(_classStaticPrivateFi), Foo, _x); + (_ref4 = (_o11 = o) === null || _o11 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o11.Foo, Foo, _self)) === null || _ref4 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref4.getSelf(), Foo, _x); + (_getSelf = (_ref14 = _ref5 = (_o12 = o) === null || _o12 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o12.Foo, Foo, _self)) === null || _ref14 === void 0 ? void 0 : _ref14.getSelf) === null || _getSelf === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_getSelf.call(_ref5), Foo, _x); + (_ref6 = (_o13 = o) === null || _o13 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o13.Foo, Foo, _self).getSelf()) === null || _ref6 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref6.self, Foo, _x); + (_call = (_ref15 = (_o14 = o) === null || _o14 === void 0 ? void 0 : (_classStaticPrivateFi2 = _classStaticPrivateFieldSpecGet(_o14.Foo, Foo, _self)).getSelf) === null || _ref15 === void 0 ? void 0 : _ref15.call(_classStaticPrivateFi2)) === null || _call === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_call.self, Foo, _x); + (_getSelf2 = (_ref16 = (_o15 = o) === null || _o15 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o15.Foo, Foo, _self)) === null || _ref16 === void 0 ? void 0 : _ref16.getSelf()) === null || _getSelf2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_getSelf2.self, Foo, _x); + (_getSelf3 = (_ref17 = (_o16 = o) === null || _o16 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o16.Foo, Foo, _self)) === null || _ref17 === void 0 ? void 0 : (_ref17$getSelf = _ref17.getSelf) === null || _ref17$getSelf === void 0 ? void 0 : _ref17$getSelf.call(_ref17)) === null || _getSelf3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_getSelf3.self, Foo, _x); (_fn = fn) === null || _fn === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn().Foo, Foo, _x); (_fn2 = fn) === null || _fn2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn2().Foo, Foo, _x).toString; (_fn3 = fn) === null || _fn3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn3().Foo, Foo, _x).toString(); - (_ref15 = fnDeep === null || fnDeep === void 0 ? void 0 : fnDeep().very.o) === null || _ref15 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref15.Foo, Foo, _x); - (_ref16 = fnDeep === null || fnDeep === void 0 ? void 0 : fnDeep().very.o) === null || _ref16 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref16.Foo, Foo, _x).toString; - (_ref17 = fnDeep === null || fnDeep === void 0 ? void 0 : fnDeep().very.o) === null || _ref17 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref17.Foo, Foo, _x).toString(); + (_fnDeep$very$o = fnDeep === null || fnDeep === void 0 ? void 0 : fnDeep().very.o) === null || _fnDeep$very$o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fnDeep$very$o.Foo, Foo, _x); + (_fnDeep$very$o2 = fnDeep === null || fnDeep === void 0 ? void 0 : fnDeep().very.o) === null || _fnDeep$very$o2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fnDeep$very$o2.Foo, Foo, _x).toString; + (_fnDeep$very$o3 = fnDeep === null || fnDeep === void 0 ? void 0 : fnDeep().very.o) === null || _fnDeep$very$o3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fnDeep$very$o3.Foo, Foo, _x).toString(); (_fn4 = fn) === null || _fn4 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFieldSpecGet(_fn4().Foo, Foo, _self), Foo, _x); (_fn5 = fn) === null || _fn5 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFieldSpecGet(_fn5().Foo, Foo, _self).self, Foo, _x); - (_ref18 = (_fn6 = fn) === null || _fn6 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn6().Foo, Foo, _self)) === null || _ref18 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref18.self, Foo, _x); - (_ref19 = (_fn7 = fn) === null || _fn7 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn7().Foo, Foo, _self).self) === null || _ref19 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref19.self, Foo, _x); - (_ref20 = (_ref34 = (_fn8 = fn) === null || _fn8 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn8().Foo, Foo, _self)) === null || _ref34 === void 0 ? void 0 : _ref34.self) === null || _ref20 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref20.self, Foo, _x); + (_ref7 = (_fn6 = fn) === null || _fn6 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn6().Foo, Foo, _self)) === null || _ref7 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref7.self, Foo, _x); + (_ref8 = (_fn7 = fn) === null || _fn7 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn7().Foo, Foo, _self).self) === null || _ref8 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref8.self, Foo, _x); + (_self3 = (_ref18 = (_fn8 = fn) === null || _fn8 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn8().Foo, Foo, _self)) === null || _ref18 === void 0 ? void 0 : _ref18.self) === null || _self3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_self3.self, Foo, _x); (_fn9 = fn) === null || _fn9 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFieldSpecGet(_fn9().Foo, Foo, _self).getSelf(), Foo, _x); - (_ref21 = (_fn10 = fn) === null || _fn10 === void 0 ? void 0 : (_classStaticPrivateFi3 = _classStaticPrivateFieldSpecGet(_fn10().Foo, Foo, _self)).getSelf) === null || _ref21 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref21.call(_classStaticPrivateFi3), Foo, _x); - (_ref22 = (_fn11 = fn) === null || _fn11 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn11().Foo, Foo, _self)) === null || _ref22 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref22.getSelf(), Foo, _x); - (_ref23 = (_ref35 = _ref24 = (_fn12 = fn) === null || _fn12 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn12().Foo, Foo, _self)) === null || _ref35 === void 0 ? void 0 : _ref35.getSelf) === null || _ref23 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref23.call(_ref24), Foo, _x); - (_ref25 = (_fn13 = fn) === null || _fn13 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn13().Foo, Foo, _self).getSelf()) === null || _ref25 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref25.self, Foo, _x); - (_ref26 = (_ref36 = (_fn14 = fn) === null || _fn14 === void 0 ? void 0 : (_classStaticPrivateFi4 = _classStaticPrivateFieldSpecGet(_fn14().Foo, Foo, _self)).getSelf) === null || _ref36 === void 0 ? void 0 : _ref36.call(_classStaticPrivateFi4)) === null || _ref26 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref26.self, Foo, _x); - (_ref27 = (_ref37 = (_fn15 = fn) === null || _fn15 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn15().Foo, Foo, _self)) === null || _ref37 === void 0 ? void 0 : _ref37.getSelf()) === null || _ref27 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref27.self, Foo, _x); - (_ref28 = (_ref38 = (_fn16 = fn) === null || _fn16 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn16().Foo, Foo, _self)) === null || _ref38 === void 0 ? void 0 : (_ref38$getSelf = _ref38.getSelf) === null || _ref38$getSelf === void 0 ? void 0 : _ref38$getSelf.call(_ref38)) === null || _ref28 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref28.self, Foo, _x); + (_ref9 = (_fn10 = fn) === null || _fn10 === void 0 ? void 0 : (_classStaticPrivateFi3 = _classStaticPrivateFieldSpecGet(_fn10().Foo, Foo, _self)).getSelf) === null || _ref9 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref9.call(_classStaticPrivateFi3), Foo, _x); + (_ref10 = (_fn11 = fn) === null || _fn11 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn11().Foo, Foo, _self)) === null || _ref10 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref10.getSelf(), Foo, _x); + (_getSelf4 = (_ref19 = _ref11 = (_fn12 = fn) === null || _fn12 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn12().Foo, Foo, _self)) === null || _ref19 === void 0 ? void 0 : _ref19.getSelf) === null || _getSelf4 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_getSelf4.call(_ref11), Foo, _x); + (_ref12 = (_fn13 = fn) === null || _fn13 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn13().Foo, Foo, _self).getSelf()) === null || _ref12 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref12.self, Foo, _x); + (_call2 = (_ref20 = (_fn14 = fn) === null || _fn14 === void 0 ? void 0 : (_classStaticPrivateFi4 = _classStaticPrivateFieldSpecGet(_fn14().Foo, Foo, _self)).getSelf) === null || _ref20 === void 0 ? void 0 : _ref20.call(_classStaticPrivateFi4)) === null || _call2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_call2.self, Foo, _x); + (_getSelf5 = (_ref21 = (_fn15 = fn) === null || _fn15 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn15().Foo, Foo, _self)) === null || _ref21 === void 0 ? void 0 : _ref21.getSelf()) === null || _getSelf5 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_getSelf5.self, Foo, _x); + (_getSelf6 = (_ref22 = (_fn16 = fn) === null || _fn16 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn16().Foo, Foo, _self)) === null || _ref22 === void 0 ? void 0 : (_ref22$getSelf = _ref22.getSelf) === null || _ref22$getSelf === void 0 ? void 0 : _ref22$getSelf.call(_ref22)) === null || _getSelf6 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_getSelf6.self, Foo, _x); } } diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain/output.js index a60704cbf1e3..edac6bb1537f 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain/output.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain/output.js @@ -8,7 +8,7 @@ class Foo { } static test() { - var _o, _o2, _o3, _ref, _ref2, _ref3, _o4, _o5, _o6, _ref4, _o7, _ref5, _o8, _ref6, _o9, _o10, _classStaticPrivateFi, _ref7, _o11, _ref8, _o12, _ref9, _ref10, _o13, _ref11, _o14, _classStaticPrivateFi2, _ref12, _o15, _ref13, _o16, _ref14, _fn, _fn2, _fn3, _ref15, _ref16, _ref17, _fn4, _fn5, _fn6, _ref18, _fn7, _ref19, _fn8, _ref20, _fn9, _fn10, _classStaticPrivateFi3, _ref21, _fn11, _ref22, _fn12, _ref23, _ref24, _fn13, _ref25, _fn14, _classStaticPrivateFi4, _ref26, _fn15, _ref27, _fn16, _ref28; + var _o, _o2, _o3, _deep$very$o, _deep$very$o2, _deep$very$o3, _o4, _o5, _o6, _ref, _o7, _ref2, _o8, _self2, _o9, _o10, _classStaticPrivateFi, _ref3, _o11, _ref4, _o12, _getSelf, _ref5, _o13, _ref6, _o14, _classStaticPrivateFi2, _call, _o15, _getSelf2, _o16, _getSelf3, _fn, _fn2, _fn3, _fnDeep$very$o, _fnDeep$very$o2, _fnDeep$very$o3, _fn4, _fn5, _fn6, _ref7, _fn7, _ref8, _fn8, _self3, _fn9, _fn10, _classStaticPrivateFi3, _ref9, _fn11, _ref10, _fn12, _getSelf4, _ref11, _fn13, _ref12, _fn14, _classStaticPrivateFi4, _call2, _fn15, _getSelf5, _fn16, _getSelf6; const o = { Foo: Foo @@ -30,41 +30,41 @@ class Foo { (_o = o) === null || _o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o.Foo, Foo, _x); (_o2 = o) === null || _o2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o2.Foo, Foo, _x).toString; (_o3 = o) === null || _o3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o3.Foo, Foo, _x).toString(); - (_ref = deep?.very.o) === null || _ref === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref.Foo, Foo, _x); - (_ref2 = deep?.very.o) === null || _ref2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref2.Foo, Foo, _x).toString; - (_ref3 = deep?.very.o) === null || _ref3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref3.Foo, Foo, _x).toString(); + (_deep$very$o = deep?.very.o) === null || _deep$very$o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_deep$very$o.Foo, Foo, _x); + (_deep$very$o2 = deep?.very.o) === null || _deep$very$o2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_deep$very$o2.Foo, Foo, _x).toString; + (_deep$very$o3 = deep?.very.o) === null || _deep$very$o3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_deep$very$o3.Foo, Foo, _x).toString(); (_o4 = o) === null || _o4 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFieldSpecGet(_o4.Foo, Foo, _self), Foo, _x); (_o5 = o) === null || _o5 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFieldSpecGet(_o5.Foo, Foo, _self).self, Foo, _x); - (_ref4 = (_o6 = o) === null || _o6 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o6.Foo, Foo, _self)) === null || _ref4 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref4.self, Foo, _x); - (_ref5 = (_o7 = o) === null || _o7 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o7.Foo, Foo, _self).self) === null || _ref5 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref5.self, Foo, _x); - (_ref6 = ((_o8 = o) === null || _o8 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o8.Foo, Foo, _self))?.self) === null || _ref6 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref6.self, Foo, _x); + (_ref = (_o6 = o) === null || _o6 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o6.Foo, Foo, _self)) === null || _ref === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref.self, Foo, _x); + (_ref2 = (_o7 = o) === null || _o7 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o7.Foo, Foo, _self).self) === null || _ref2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref2.self, Foo, _x); + (_self2 = ((_o8 = o) === null || _o8 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o8.Foo, Foo, _self))?.self) === null || _self2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_self2.self, Foo, _x); (_o9 = o) === null || _o9 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFieldSpecGet(_o9.Foo, Foo, _self).getSelf(), Foo, _x); - (_ref7 = (_o10 = o) === null || _o10 === void 0 ? void 0 : (_classStaticPrivateFi = _classStaticPrivateFieldSpecGet(_o10.Foo, Foo, _self)).getSelf) === null || _ref7 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref7.call(_classStaticPrivateFi), Foo, _x); - (_ref8 = (_o11 = o) === null || _o11 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o11.Foo, Foo, _self)) === null || _ref8 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref8.getSelf(), Foo, _x); - (_ref9 = (_ref10 = (_o12 = o) === null || _o12 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o12.Foo, Foo, _self))?.getSelf) === null || _ref9 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref9.call(_ref10), Foo, _x); - (_ref11 = (_o13 = o) === null || _o13 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o13.Foo, Foo, _self).getSelf()) === null || _ref11 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref11.self, Foo, _x); - (_ref12 = ((_o14 = o) === null || _o14 === void 0 ? void 0 : (_classStaticPrivateFi2 = _classStaticPrivateFieldSpecGet(_o14.Foo, Foo, _self)).getSelf)?.call(_classStaticPrivateFi2)) === null || _ref12 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref12.self, Foo, _x); - (_ref13 = ((_o15 = o) === null || _o15 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o15.Foo, Foo, _self))?.getSelf()) === null || _ref13 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref13.self, Foo, _x); - (_ref14 = ((_o16 = o) === null || _o16 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o16.Foo, Foo, _self))?.getSelf?.()) === null || _ref14 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref14.self, Foo, _x); + (_ref3 = (_o10 = o) === null || _o10 === void 0 ? void 0 : (_classStaticPrivateFi = _classStaticPrivateFieldSpecGet(_o10.Foo, Foo, _self)).getSelf) === null || _ref3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref3.call(_classStaticPrivateFi), Foo, _x); + (_ref4 = (_o11 = o) === null || _o11 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o11.Foo, Foo, _self)) === null || _ref4 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref4.getSelf(), Foo, _x); + (_getSelf = (_ref5 = (_o12 = o) === null || _o12 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o12.Foo, Foo, _self))?.getSelf) === null || _getSelf === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_getSelf.call(_ref5), Foo, _x); + (_ref6 = (_o13 = o) === null || _o13 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o13.Foo, Foo, _self).getSelf()) === null || _ref6 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref6.self, Foo, _x); + (_call = ((_o14 = o) === null || _o14 === void 0 ? void 0 : (_classStaticPrivateFi2 = _classStaticPrivateFieldSpecGet(_o14.Foo, Foo, _self)).getSelf)?.call(_classStaticPrivateFi2)) === null || _call === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_call.self, Foo, _x); + (_getSelf2 = ((_o15 = o) === null || _o15 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o15.Foo, Foo, _self))?.getSelf()) === null || _getSelf2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_getSelf2.self, Foo, _x); + (_getSelf3 = ((_o16 = o) === null || _o16 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o16.Foo, Foo, _self))?.getSelf?.()) === null || _getSelf3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_getSelf3.self, Foo, _x); (_fn = fn) === null || _fn === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn().Foo, Foo, _x); (_fn2 = fn) === null || _fn2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn2().Foo, Foo, _x).toString; (_fn3 = fn) === null || _fn3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn3().Foo, Foo, _x).toString(); - (_ref15 = fnDeep?.().very.o) === null || _ref15 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref15.Foo, Foo, _x); - (_ref16 = fnDeep?.().very.o) === null || _ref16 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref16.Foo, Foo, _x).toString; - (_ref17 = fnDeep?.().very.o) === null || _ref17 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref17.Foo, Foo, _x).toString(); + (_fnDeep$very$o = fnDeep?.().very.o) === null || _fnDeep$very$o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fnDeep$very$o.Foo, Foo, _x); + (_fnDeep$very$o2 = fnDeep?.().very.o) === null || _fnDeep$very$o2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fnDeep$very$o2.Foo, Foo, _x).toString; + (_fnDeep$very$o3 = fnDeep?.().very.o) === null || _fnDeep$very$o3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fnDeep$very$o3.Foo, Foo, _x).toString(); (_fn4 = fn) === null || _fn4 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFieldSpecGet(_fn4().Foo, Foo, _self), Foo, _x); (_fn5 = fn) === null || _fn5 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFieldSpecGet(_fn5().Foo, Foo, _self).self, Foo, _x); - (_ref18 = (_fn6 = fn) === null || _fn6 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn6().Foo, Foo, _self)) === null || _ref18 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref18.self, Foo, _x); - (_ref19 = (_fn7 = fn) === null || _fn7 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn7().Foo, Foo, _self).self) === null || _ref19 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref19.self, Foo, _x); - (_ref20 = ((_fn8 = fn) === null || _fn8 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn8().Foo, Foo, _self))?.self) === null || _ref20 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref20.self, Foo, _x); + (_ref7 = (_fn6 = fn) === null || _fn6 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn6().Foo, Foo, _self)) === null || _ref7 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref7.self, Foo, _x); + (_ref8 = (_fn7 = fn) === null || _fn7 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn7().Foo, Foo, _self).self) === null || _ref8 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref8.self, Foo, _x); + (_self3 = ((_fn8 = fn) === null || _fn8 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn8().Foo, Foo, _self))?.self) === null || _self3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_self3.self, Foo, _x); (_fn9 = fn) === null || _fn9 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFieldSpecGet(_fn9().Foo, Foo, _self).getSelf(), Foo, _x); - (_ref21 = (_fn10 = fn) === null || _fn10 === void 0 ? void 0 : (_classStaticPrivateFi3 = _classStaticPrivateFieldSpecGet(_fn10().Foo, Foo, _self)).getSelf) === null || _ref21 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref21.call(_classStaticPrivateFi3), Foo, _x); - (_ref22 = (_fn11 = fn) === null || _fn11 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn11().Foo, Foo, _self)) === null || _ref22 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref22.getSelf(), Foo, _x); - (_ref23 = (_ref24 = (_fn12 = fn) === null || _fn12 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn12().Foo, Foo, _self))?.getSelf) === null || _ref23 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref23.call(_ref24), Foo, _x); - (_ref25 = (_fn13 = fn) === null || _fn13 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn13().Foo, Foo, _self).getSelf()) === null || _ref25 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref25.self, Foo, _x); - (_ref26 = ((_fn14 = fn) === null || _fn14 === void 0 ? void 0 : (_classStaticPrivateFi4 = _classStaticPrivateFieldSpecGet(_fn14().Foo, Foo, _self)).getSelf)?.call(_classStaticPrivateFi4)) === null || _ref26 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref26.self, Foo, _x); - (_ref27 = ((_fn15 = fn) === null || _fn15 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn15().Foo, Foo, _self))?.getSelf()) === null || _ref27 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref27.self, Foo, _x); - (_ref28 = ((_fn16 = fn) === null || _fn16 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn16().Foo, Foo, _self))?.getSelf?.()) === null || _ref28 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref28.self, Foo, _x); + (_ref9 = (_fn10 = fn) === null || _fn10 === void 0 ? void 0 : (_classStaticPrivateFi3 = _classStaticPrivateFieldSpecGet(_fn10().Foo, Foo, _self)).getSelf) === null || _ref9 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref9.call(_classStaticPrivateFi3), Foo, _x); + (_ref10 = (_fn11 = fn) === null || _fn11 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn11().Foo, Foo, _self)) === null || _ref10 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref10.getSelf(), Foo, _x); + (_getSelf4 = (_ref11 = (_fn12 = fn) === null || _fn12 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn12().Foo, Foo, _self))?.getSelf) === null || _getSelf4 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_getSelf4.call(_ref11), Foo, _x); + (_ref12 = (_fn13 = fn) === null || _fn13 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn13().Foo, Foo, _self).getSelf()) === null || _ref12 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref12.self, Foo, _x); + (_call2 = ((_fn14 = fn) === null || _fn14 === void 0 ? void 0 : (_classStaticPrivateFi4 = _classStaticPrivateFieldSpecGet(_fn14().Foo, Foo, _self)).getSelf)?.call(_classStaticPrivateFi4)) === null || _call2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_call2.self, Foo, _x); + (_getSelf5 = ((_fn15 = fn) === null || _fn15 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn15().Foo, Foo, _self))?.getSelf()) === null || _getSelf5 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_getSelf5.self, Foo, _x); + (_getSelf6 = ((_fn16 = fn) === null || _fn16 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn16().Foo, Foo, _self))?.getSelf?.()) === null || _getSelf6 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_getSelf6.self, Foo, _x); } } From d5b22f636e95530c2f02e8b4266b2e5de585e344 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hu=C3=A1ng=20J=C3=B9nli=C3=A0ng?= Date: Wed, 20 May 2020 14:39:35 -0400 Subject: [PATCH 08/20] chore: regenerate test fixtures --- .../optional-chain-object/output.json | 762 ++---------------- .../optional-chain-start-call/output.json | 254 +----- .../output.json | 279 +------ .../optional-chain-start-member/output.json | 253 +----- .../optional-chain-start-simple/output.json | 226 +----- 5 files changed, 134 insertions(+), 1640 deletions(-) diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-properties/optional-chain-object/output.json b/packages/babel-parser/test/fixtures/experimental/class-private-properties/optional-chain-object/output.json index 26ce1f65e3a9..a338c29398f2 100644 --- a/packages/babel-parser/test/fixtures/experimental/class-private-properties/optional-chain-object/output.json +++ b/packages/babel-parser/test/fixtures/experimental/class-private-properties/optional-chain-object/output.json @@ -1,142 +1,41 @@ { "type": "File", - "start": 0, - "end": 219, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 14, - "column": 1 - } - }, + "start":0,"end":219,"loc":{"start":{"line":1,"column":0},"end":{"line":14,"column":1}}, "program": { "type": "Program", - "start": 0, - "end": 219, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 14, - "column": 1 - } - }, + "start":0,"end":219,"loc":{"start":{"line":1,"column":0},"end":{"line":14,"column":1}}, "sourceType": "script", "interpreter": null, "body": [ { "type": "ClassDeclaration", - "start": 0, - "end": 219, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 14, - "column": 1 - } - }, + "start":0,"end":219,"loc":{"start":{"line":1,"column":0},"end":{"line":14,"column":1}}, "id": { "type": "Identifier", - "start": 6, - "end": 9, - "loc": { - "start": { - "line": 1, - "column": 6 - }, - "end": { - "line": 1, - "column": 9 - }, - "identifierName": "Foo" - }, + "start":6,"end":9,"loc":{"start":{"line":1,"column":6},"end":{"line":1,"column":9},"identifierName":"Foo"}, "name": "Foo" }, "superClass": null, "body": { "type": "ClassBody", - "start": 10, - "end": 219, - "loc": { - "start": { - "line": 1, - "column": 10 - }, - "end": { - "line": 14, - "column": 1 - } - }, + "start":10,"end":219,"loc":{"start":{"line":1,"column":10},"end":{"line":14,"column":1}}, "body": [ { "type": "ClassPrivateProperty", - "start": 14, - "end": 28, - "loc": { - "start": { - "line": 2, - "column": 2 - }, - "end": { - "line": 2, - "column": 16 - } - }, + "start":14,"end":28,"loc":{"start":{"line":2,"column":2},"end":{"line":2,"column":16}}, "static": true, "key": { "type": "PrivateName", - "start": 21, - "end": 23, - "loc": { - "start": { - "line": 2, - "column": 9 - }, - "end": { - "line": 2, - "column": 11 - } - }, + "start":21,"end":23,"loc":{"start":{"line":2,"column":9},"end":{"line":2,"column":11}}, "id": { "type": "Identifier", - "start": 22, - "end": 23, - "loc": { - "start": { - "line": 2, - "column": 10 - }, - "end": { - "line": 2, - "column": 11 - }, - "identifierName": "x" - }, + "start":22,"end":23,"loc":{"start":{"line":2,"column":10},"end":{"line":2,"column":11},"identifierName":"x"}, "name": "x" } }, "value": { "type": "NumericLiteral", - "start": 26, - "end": 27, - "loc": { - "start": { - "line": 2, - "column": 14 - }, - "end": { - "line": 2, - "column": 15 - } - }, + "start":26,"end":27,"loc":{"start":{"line":2,"column":14},"end":{"line":2,"column":15}}, "extra": { "rawValue": 1, "raw": "1" @@ -146,83 +45,27 @@ }, { "type": "ClassPrivateProperty", - "start": 31, - "end": 57, - "loc": { - "start": { - "line": 3, - "column": 2 - }, - "end": { - "line": 3, - "column": 28 - } - }, + "start":31,"end":57,"loc":{"start":{"line":3,"column":2},"end":{"line":3,"column":28}}, "static": true, "key": { "type": "PrivateName", - "start": 38, - "end": 40, - "loc": { - "start": { - "line": 3, - "column": 9 - }, - "end": { - "line": 3, - "column": 11 - } - }, + "start":38,"end":40,"loc":{"start":{"line":3,"column":9},"end":{"line":3,"column":11}}, "id": { "type": "Identifier", - "start": 39, - "end": 40, - "loc": { - "start": { - "line": 3, - "column": 10 - }, - "end": { - "line": 3, - "column": 11 - }, - "identifierName": "m" - }, + "start":39,"end":40,"loc":{"start":{"line":3,"column":10},"end":{"line":3,"column":11},"identifierName":"m"}, "name": "m" } }, "value": { "type": "FunctionExpression", - "start": 43, - "end": 56, - "loc": { - "start": { - "line": 3, - "column": 14 - }, - "end": { - "line": 3, - "column": 27 - } - }, + "start":43,"end":56,"loc":{"start":{"line":3,"column":14},"end":{"line":3,"column":27}}, "id": null, "generator": false, "async": false, "params": [], "body": { "type": "BlockStatement", - "start": 54, - "end": 56, - "loc": { - "start": { - "line": 3, - "column": 25 - }, - "end": { - "line": 3, - "column": 27 - } - }, + "start":54,"end":56,"loc":{"start":{"line":3,"column":25},"end":{"line":3,"column":27}}, "body": [], "directives": [] } @@ -230,34 +73,11 @@ }, { "type": "ClassMethod", - "start": 61, - "end": 217, - "loc": { - "start": { - "line": 5, - "column": 2 - }, - "end": { - "line": 13, - "column": 3 - } - }, + "start":61,"end":217,"loc":{"start":{"line":5,"column":2},"end":{"line":13,"column":3}}, "static": true, "key": { "type": "Identifier", - "start": 68, - "end": 72, - "loc": { - "start": { - "line": 5, - "column": 9 - }, - "end": { - "line": 5, - "column": 13 - }, - "identifierName": "test" - }, + "start":68,"end":72,"loc":{"start":{"line":5,"column":9},"end":{"line":5,"column":13},"identifierName":"test"}, "name": "test" }, "computed": false, @@ -268,129 +88,38 @@ "params": [], "body": { "type": "BlockStatement", - "start": 75, - "end": 217, - "loc": { - "start": { - "line": 5, - "column": 16 - }, - "end": { - "line": 13, - "column": 3 - } - }, + "start":75,"end":217,"loc":{"start":{"line":5,"column":16},"end":{"line":13,"column":3}}, "body": [ { "type": "VariableDeclaration", - "start": 81, - "end": 104, - "loc": { - "start": { - "line": 6, - "column": 4 - }, - "end": { - "line": 6, - "column": 27 - } - }, + "start":81,"end":104,"loc":{"start":{"line":6,"column":4},"end":{"line":6,"column":27}}, "declarations": [ { "type": "VariableDeclarator", - "start": 87, - "end": 103, - "loc": { - "start": { - "line": 6, - "column": 10 - }, - "end": { - "line": 6, - "column": 26 - } - }, + "start":87,"end":103,"loc":{"start":{"line":6,"column":10},"end":{"line":6,"column":26}}, "id": { "type": "Identifier", - "start": 87, - "end": 88, - "loc": { - "start": { - "line": 6, - "column": 10 - }, - "end": { - "line": 6, - "column": 11 - }, - "identifierName": "o" - }, + "start":87,"end":88,"loc":{"start":{"line":6,"column":10},"end":{"line":6,"column":11},"identifierName":"o"}, "name": "o" }, "init": { "type": "ObjectExpression", - "start": 91, - "end": 103, - "loc": { - "start": { - "line": 6, - "column": 14 - }, - "end": { - "line": 6, - "column": 26 - } - }, + "start":91,"end":103,"loc":{"start":{"line":6,"column":14},"end":{"line":6,"column":26}}, "properties": [ { "type": "ObjectProperty", - "start": 93, - "end": 101, - "loc": { - "start": { - "line": 6, - "column": 16 - }, - "end": { - "line": 6, - "column": 24 - } - }, + "start":93,"end":101,"loc":{"start":{"line":6,"column":16},"end":{"line":6,"column":24}}, "method": false, "key": { "type": "Identifier", - "start": 93, - "end": 96, - "loc": { - "start": { - "line": 6, - "column": 16 - }, - "end": { - "line": 6, - "column": 19 - }, - "identifierName": "Foo" - }, + "start":93,"end":96,"loc":{"start":{"line":6,"column":16},"end":{"line":6,"column":19},"identifierName":"Foo"}, "name": "Foo" }, "computed": false, "shorthand": false, "value": { "type": "Identifier", - "start": 98, - "end": 101, - "loc": { - "start": { - "line": 6, - "column": 21 - }, - "end": { - "line": 6, - "column": 24 - }, - "identifierName": "Foo" - }, + "start":98,"end":101,"loc":{"start":{"line":6,"column":21},"end":{"line":6,"column":24},"identifierName":"Foo"}, "name": "Foo" } } @@ -402,96 +131,28 @@ }, { "type": "ReturnStatement", - "start": 109, - "end": 213, - "loc": { - "start": { - "line": 7, - "column": 4 - }, - "end": { - "line": 12, - "column": 6 - } - }, + "start":109,"end":213,"loc":{"start":{"line":7,"column":4},"end":{"line":12,"column":6}}, "argument": { "type": "ArrayExpression", - "start": 116, - "end": 212, - "loc": { - "start": { - "line": 7, - "column": 11 - }, - "end": { - "line": 12, - "column": 5 - } - }, + "start":116,"end":212,"loc":{"start":{"line":7,"column":11},"end":{"line":12,"column":5}}, "extra": { "trailingComma": 205 }, "elements": [ { "type": "OptionalMemberExpression", - "start": 124, - "end": 133, - "loc": { - "start": { - "line": 8, - "column": 6 - }, - "end": { - "line": 8, - "column": 15 - } - }, + "start":124,"end":133,"loc":{"start":{"line":8,"column":6},"end":{"line":8,"column":15}}, "object": { "type": "OptionalMemberExpression", - "start": 124, - "end": 130, - "loc": { - "start": { - "line": 8, - "column": 6 - }, - "end": { - "line": 8, - "column": 12 - } - }, + "start":124,"end":130,"loc":{"start":{"line":8,"column":6},"end":{"line":8,"column":12}}, "object": { "type": "Identifier", - "start": 124, - "end": 125, - "loc": { - "start": { - "line": 8, - "column": 6 - }, - "end": { - "line": 8, - "column": 7 - }, - "identifierName": "o" - }, + "start":124,"end":125,"loc":{"start":{"line":8,"column":6},"end":{"line":8,"column":7},"identifierName":"o"}, "name": "o" }, "property": { "type": "Identifier", - "start": 127, - "end": 130, - "loc": { - "start": { - "line": 8, - "column": 9 - }, - "end": { - "line": 8, - "column": 12 - }, - "identifierName": "Foo" - }, + "start":127,"end":130,"loc":{"start":{"line":8,"column":9},"end":{"line":8,"column":12},"identifierName":"Foo"}, "name": "Foo" }, "computed": false, @@ -499,33 +160,10 @@ }, "property": { "type": "PrivateName", - "start": 131, - "end": 133, - "loc": { - "start": { - "line": 8, - "column": 13 - }, - "end": { - "line": 8, - "column": 15 - } - }, + "start":131,"end":133,"loc":{"start":{"line":8,"column":13},"end":{"line":8,"column":15}}, "id": { "type": "Identifier", - "start": 132, - "end": 133, - "loc": { - "start": { - "line": 8, - "column": 14 - }, - "end": { - "line": 8, - "column": 15 - }, - "identifierName": "x" - }, + "start":132,"end":133,"loc":{"start":{"line":8,"column":14},"end":{"line":8,"column":15},"identifierName":"x"}, "name": "x" } }, @@ -534,78 +172,21 @@ }, { "type": "OptionalMemberExpression", - "start": 141, - "end": 158, - "loc": { - "start": { - "line": 9, - "column": 6 - }, - "end": { - "line": 9, - "column": 23 - } - }, + "start":141,"end":158,"loc":{"start":{"line":9,"column":6},"end":{"line":9,"column":23}}, "object": { "type": "OptionalMemberExpression", - "start": 141, - "end": 150, - "loc": { - "start": { - "line": 9, - "column": 6 - }, - "end": { - "line": 9, - "column": 15 - } - }, + "start":141,"end":150,"loc":{"start":{"line":9,"column":6},"end":{"line":9,"column":15}}, "object": { "type": "OptionalMemberExpression", - "start": 141, - "end": 147, - "loc": { - "start": { - "line": 9, - "column": 6 - }, - "end": { - "line": 9, - "column": 12 - } - }, + "start":141,"end":147,"loc":{"start":{"line":9,"column":6},"end":{"line":9,"column":12}}, "object": { "type": "Identifier", - "start": 141, - "end": 142, - "loc": { - "start": { - "line": 9, - "column": 6 - }, - "end": { - "line": 9, - "column": 7 - }, - "identifierName": "o" - }, + "start":141,"end":142,"loc":{"start":{"line":9,"column":6},"end":{"line":9,"column":7},"identifierName":"o"}, "name": "o" }, "property": { "type": "Identifier", - "start": 144, - "end": 147, - "loc": { - "start": { - "line": 9, - "column": 9 - }, - "end": { - "line": 9, - "column": 12 - }, - "identifierName": "Foo" - }, + "start":144,"end":147,"loc":{"start":{"line":9,"column":9},"end":{"line":9,"column":12},"identifierName":"Foo"}, "name": "Foo" }, "computed": false, @@ -613,33 +194,10 @@ }, "property": { "type": "PrivateName", - "start": 148, - "end": 150, - "loc": { - "start": { - "line": 9, - "column": 13 - }, - "end": { - "line": 9, - "column": 15 - } - }, + "start":148,"end":150,"loc":{"start":{"line":9,"column":13},"end":{"line":9,"column":15}}, "id": { "type": "Identifier", - "start": 149, - "end": 150, - "loc": { - "start": { - "line": 9, - "column": 14 - }, - "end": { - "line": 9, - "column": 15 - }, - "identifierName": "x" - }, + "start":149,"end":150,"loc":{"start":{"line":9,"column":14},"end":{"line":9,"column":15},"identifierName":"x"}, "name": "x" } }, @@ -648,19 +206,7 @@ }, "property": { "type": "Identifier", - "start": 151, - "end": 158, - "loc": { - "start": { - "line": 9, - "column": 16 - }, - "end": { - "line": 9, - "column": 23 - }, - "identifierName": "toFixed" - }, + "start":151,"end":158,"loc":{"start":{"line":9,"column":16},"end":{"line":9,"column":23},"identifierName":"toFixed"}, "name": "toFixed" }, "computed": false, @@ -668,92 +214,24 @@ }, { "type": "OptionalCallExpression", - "start": 166, - "end": 186, - "loc": { - "start": { - "line": 10, - "column": 6 - }, - "end": { - "line": 10, - "column": 26 - } - }, + "start":166,"end":186,"loc":{"start":{"line":10,"column":6},"end":{"line":10,"column":26}}, "callee": { "type": "OptionalMemberExpression", - "start": 166, - "end": 183, - "loc": { - "start": { - "line": 10, - "column": 6 - }, - "end": { - "line": 10, - "column": 23 - } - }, + "start":166,"end":183,"loc":{"start":{"line":10,"column":6},"end":{"line":10,"column":23}}, "object": { "type": "OptionalMemberExpression", - "start": 166, - "end": 175, - "loc": { - "start": { - "line": 10, - "column": 6 - }, - "end": { - "line": 10, - "column": 15 - } - }, + "start":166,"end":175,"loc":{"start":{"line":10,"column":6},"end":{"line":10,"column":15}}, "object": { "type": "OptionalMemberExpression", - "start": 166, - "end": 172, - "loc": { - "start": { - "line": 10, - "column": 6 - }, - "end": { - "line": 10, - "column": 12 - } - }, + "start":166,"end":172,"loc":{"start":{"line":10,"column":6},"end":{"line":10,"column":12}}, "object": { "type": "Identifier", - "start": 166, - "end": 167, - "loc": { - "start": { - "line": 10, - "column": 6 - }, - "end": { - "line": 10, - "column": 7 - }, - "identifierName": "o" - }, + "start":166,"end":167,"loc":{"start":{"line":10,"column":6},"end":{"line":10,"column":7},"identifierName":"o"}, "name": "o" }, "property": { "type": "Identifier", - "start": 169, - "end": 172, - "loc": { - "start": { - "line": 10, - "column": 9 - }, - "end": { - "line": 10, - "column": 12 - }, - "identifierName": "Foo" - }, + "start":169,"end":172,"loc":{"start":{"line":10,"column":9},"end":{"line":10,"column":12},"identifierName":"Foo"}, "name": "Foo" }, "computed": false, @@ -761,33 +239,10 @@ }, "property": { "type": "PrivateName", - "start": 173, - "end": 175, - "loc": { - "start": { - "line": 10, - "column": 13 - }, - "end": { - "line": 10, - "column": 15 - } - }, + "start":173,"end":175,"loc":{"start":{"line":10,"column":13},"end":{"line":10,"column":15}}, "id": { "type": "Identifier", - "start": 174, - "end": 175, - "loc": { - "start": { - "line": 10, - "column": 14 - }, - "end": { - "line": 10, - "column": 15 - }, - "identifierName": "x" - }, + "start":174,"end":175,"loc":{"start":{"line":10,"column":14},"end":{"line":10,"column":15},"identifierName":"x"}, "name": "x" } }, @@ -796,19 +251,7 @@ }, "property": { "type": "Identifier", - "start": 176, - "end": 183, - "loc": { - "start": { - "line": 10, - "column": 16 - }, - "end": { - "line": 10, - "column": 23 - }, - "identifierName": "toFixed" - }, + "start":176,"end":183,"loc":{"start":{"line":10,"column":16},"end":{"line":10,"column":23},"identifierName":"toFixed"}, "name": "toFixed" }, "computed": false, @@ -817,18 +260,7 @@ "arguments": [ { "type": "NumericLiteral", - "start": 184, - "end": 185, - "loc": { - "start": { - "line": 10, - "column": 24 - }, - "end": { - "line": 10, - "column": 25 - } - }, + "start":184,"end":185,"loc":{"start":{"line":10,"column":24},"end":{"line":10,"column":25}}, "extra": { "rawValue": 2, "raw": "2" @@ -839,78 +271,21 @@ }, { "type": "OptionalCallExpression", - "start": 194, - "end": 205, - "loc": { - "start": { - "line": 11, - "column": 6 - }, - "end": { - "line": 11, - "column": 17 - } - }, + "start":194,"end":205,"loc":{"start":{"line":11,"column":6},"end":{"line":11,"column":17}}, "callee": { "type": "OptionalMemberExpression", - "start": 194, - "end": 203, - "loc": { - "start": { - "line": 11, - "column": 6 - }, - "end": { - "line": 11, - "column": 15 - } - }, + "start":194,"end":203,"loc":{"start":{"line":11,"column":6},"end":{"line":11,"column":15}}, "object": { "type": "OptionalMemberExpression", - "start": 194, - "end": 200, - "loc": { - "start": { - "line": 11, - "column": 6 - }, - "end": { - "line": 11, - "column": 12 - } - }, + "start":194,"end":200,"loc":{"start":{"line":11,"column":6},"end":{"line":11,"column":12}}, "object": { "type": "Identifier", - "start": 194, - "end": 195, - "loc": { - "start": { - "line": 11, - "column": 6 - }, - "end": { - "line": 11, - "column": 7 - }, - "identifierName": "o" - }, + "start":194,"end":195,"loc":{"start":{"line":11,"column":6},"end":{"line":11,"column":7},"identifierName":"o"}, "name": "o" }, "property": { "type": "Identifier", - "start": 197, - "end": 200, - "loc": { - "start": { - "line": 11, - "column": 9 - }, - "end": { - "line": 11, - "column": 12 - }, - "identifierName": "Foo" - }, + "start":197,"end":200,"loc":{"start":{"line":11,"column":9},"end":{"line":11,"column":12},"identifierName":"Foo"}, "name": "Foo" }, "computed": false, @@ -918,33 +293,10 @@ }, "property": { "type": "PrivateName", - "start": 201, - "end": 203, - "loc": { - "start": { - "line": 11, - "column": 13 - }, - "end": { - "line": 11, - "column": 15 - } - }, + "start":201,"end":203,"loc":{"start":{"line":11,"column":13},"end":{"line":11,"column":15}}, "id": { "type": "Identifier", - "start": 202, - "end": 203, - "loc": { - "start": { - "line": 11, - "column": 14 - }, - "end": { - "line": 11, - "column": 15 - }, - "identifierName": "m" - }, + "start":202,"end":203,"loc":{"start":{"line":11,"column":14},"end":{"line":11,"column":15},"identifierName":"m"}, "name": "m" } }, diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-properties/optional-chain-start-call/output.json b/packages/babel-parser/test/fixtures/experimental/class-private-properties/optional-chain-start-call/output.json index 3497b7a02ac3..0aa1b746c2aa 100644 --- a/packages/babel-parser/test/fixtures/experimental/class-private-properties/optional-chain-start-call/output.json +++ b/packages/babel-parser/test/fixtures/experimental/class-private-properties/optional-chain-start-call/output.json @@ -1,163 +1,51 @@ { "type": "File", - "start": 0, - "end": 87, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 7, - "column": 1 - } - }, + "start":0,"end":87,"loc":{"start":{"line":1,"column":0},"end":{"line":7,"column":1}}, "errors": [ "SyntaxError: Private property access cannot immediately follow an optional chain's `?.` (5:16)" ], "program": { "type": "Program", - "start": 0, - "end": 87, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 7, - "column": 1 - } - }, + "start":0,"end":87,"loc":{"start":{"line":1,"column":0},"end":{"line":7,"column":1}}, "sourceType": "script", "interpreter": null, "body": [ { "type": "ClassDeclaration", - "start": 0, - "end": 87, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 7, - "column": 1 - } - }, + "start":0,"end":87,"loc":{"start":{"line":1,"column":0},"end":{"line":7,"column":1}}, "id": { "type": "Identifier", - "start": 6, - "end": 9, - "loc": { - "start": { - "line": 1, - "column": 6 - }, - "end": { - "line": 1, - "column": 9 - }, - "identifierName": "Foo" - }, + "start":6,"end":9,"loc":{"start":{"line":1,"column":6},"end":{"line":1,"column":9},"identifierName":"Foo"}, "name": "Foo" }, "superClass": null, "body": { "type": "ClassBody", - "start": 10, - "end": 87, - "loc": { - "start": { - "line": 1, - "column": 10 - }, - "end": { - "line": 7, - "column": 1 - } - }, + "start":10,"end":87,"loc":{"start":{"line":1,"column":10},"end":{"line":7,"column":1}}, "body": [ { "type": "ClassPrivateProperty", - "start": 14, - "end": 40, - "loc": { - "start": { - "line": 2, - "column": 2 - }, - "end": { - "line": 2, - "column": 28 - } - }, + "start":14,"end":40,"loc":{"start":{"line":2,"column":2},"end":{"line":2,"column":28}}, "static": true, "key": { "type": "PrivateName", - "start": 21, - "end": 23, - "loc": { - "start": { - "line": 2, - "column": 9 - }, - "end": { - "line": 2, - "column": 11 - } - }, + "start":21,"end":23,"loc":{"start":{"line":2,"column":9},"end":{"line":2,"column":11}}, "id": { "type": "Identifier", - "start": 22, - "end": 23, - "loc": { - "start": { - "line": 2, - "column": 10 - }, - "end": { - "line": 2, - "column": 11 - }, - "identifierName": "m" - }, + "start":22,"end":23,"loc":{"start":{"line":2,"column":10},"end":{"line":2,"column":11},"identifierName":"m"}, "name": "m" } }, "value": { "type": "FunctionExpression", - "start": 26, - "end": 39, - "loc": { - "start": { - "line": 2, - "column": 14 - }, - "end": { - "line": 2, - "column": 27 - } - }, + "start":26,"end":39,"loc":{"start":{"line":2,"column":14},"end":{"line":2,"column":27}}, "id": null, "generator": false, "async": false, "params": [], "body": { "type": "BlockStatement", - "start": 37, - "end": 39, - "loc": { - "start": { - "line": 2, - "column": 25 - }, - "end": { - "line": 2, - "column": 27 - } - }, + "start":37,"end":39,"loc":{"start":{"line":2,"column":25},"end":{"line":2,"column":27}}, "body": [], "directives": [] } @@ -165,34 +53,11 @@ }, { "type": "ClassMethod", - "start": 44, - "end": 85, - "loc": { - "start": { - "line": 4, - "column": 2 - }, - "end": { - "line": 6, - "column": 3 - } - }, + "start":44,"end":85,"loc":{"start":{"line":4,"column":2},"end":{"line":6,"column":3}}, "static": true, "key": { "type": "Identifier", - "start": 51, - "end": 55, - "loc": { - "start": { - "line": 4, - "column": 9 - }, - "end": { - "line": 4, - "column": 13 - }, - "identifierName": "test" - }, + "start":51,"end":55,"loc":{"start":{"line":4,"column":9},"end":{"line":4,"column":13},"identifierName":"test"}, "name": "test" }, "computed": false, @@ -203,107 +68,28 @@ "params": [], "body": { "type": "BlockStatement", - "start": 58, - "end": 85, - "loc": { - "start": { - "line": 4, - "column": 16 - }, - "end": { - "line": 6, - "column": 3 - } - }, + "start":58,"end":85,"loc":{"start":{"line":4,"column":16},"end":{"line":6,"column":3}}, "body": [ { "type": "ReturnStatement", - "start": 64, - "end": 81, - "loc": { - "start": { - "line": 5, - "column": 4 - }, - "end": { - "line": 5, - "column": 21 - } - }, + "start":64,"end":81,"loc":{"start":{"line":5,"column":4},"end":{"line":5,"column":21}}, "argument": { "type": "OptionalCallExpression", - "start": 71, - "end": 80, - "loc": { - "start": { - "line": 5, - "column": 11 - }, - "end": { - "line": 5, - "column": 20 - } - }, + "start":71,"end":80,"loc":{"start":{"line":5,"column":11},"end":{"line":5,"column":20}}, "callee": { "type": "OptionalMemberExpression", - "start": 71, - "end": 78, - "loc": { - "start": { - "line": 5, - "column": 11 - }, - "end": { - "line": 5, - "column": 18 - } - }, + "start":71,"end":78,"loc":{"start":{"line":5,"column":11},"end":{"line":5,"column":18}}, "object": { "type": "Identifier", - "start": 71, - "end": 74, - "loc": { - "start": { - "line": 5, - "column": 11 - }, - "end": { - "line": 5, - "column": 14 - }, - "identifierName": "Foo" - }, + "start":71,"end":74,"loc":{"start":{"line":5,"column":11},"end":{"line":5,"column":14},"identifierName":"Foo"}, "name": "Foo" }, "property": { "type": "PrivateName", - "start": 76, - "end": 78, - "loc": { - "start": { - "line": 5, - "column": 16 - }, - "end": { - "line": 5, - "column": 18 - } - }, + "start":76,"end":78,"loc":{"start":{"line":5,"column":16},"end":{"line":5,"column":18}}, "id": { "type": "Identifier", - "start": 77, - "end": 78, - "loc": { - "start": { - "line": 5, - "column": 17 - }, - "end": { - "line": 5, - "column": 18 - }, - "identifierName": "m" - }, + "start":77,"end":78,"loc":{"start":{"line":5,"column":17},"end":{"line":5,"column":18},"identifierName":"m"}, "name": "m" } }, @@ -323,4 +109,4 @@ ], "directives": [] } -} +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-properties/optional-chain-start-member-call/output.json b/packages/babel-parser/test/fixtures/experimental/class-private-properties/optional-chain-start-member-call/output.json index 61c1f6485f5c..20ed4fa71a80 100644 --- a/packages/babel-parser/test/fixtures/experimental/class-private-properties/optional-chain-start-member-call/output.json +++ b/packages/babel-parser/test/fixtures/experimental/class-private-properties/optional-chain-start-member-call/output.json @@ -1,145 +1,44 @@ { "type": "File", - "start": 0, - "end": 84, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 7, - "column": 1 - } - }, + "start":0,"end":84,"loc":{"start":{"line":1,"column":0},"end":{"line":7,"column":1}}, "errors": [ "SyntaxError: Private property access cannot immediately follow an optional chain's `?.` (5:16)" ], "program": { "type": "Program", - "start": 0, - "end": 84, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 7, - "column": 1 - } - }, + "start":0,"end":84,"loc":{"start":{"line":1,"column":0},"end":{"line":7,"column":1}}, "sourceType": "script", "interpreter": null, "body": [ { "type": "ClassDeclaration", - "start": 0, - "end": 84, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 7, - "column": 1 - } - }, + "start":0,"end":84,"loc":{"start":{"line":1,"column":0},"end":{"line":7,"column":1}}, "id": { "type": "Identifier", - "start": 6, - "end": 9, - "loc": { - "start": { - "line": 1, - "column": 6 - }, - "end": { - "line": 1, - "column": 9 - }, - "identifierName": "Foo" - }, + "start":6,"end":9,"loc":{"start":{"line":1,"column":6},"end":{"line":1,"column":9},"identifierName":"Foo"}, "name": "Foo" }, "superClass": null, "body": { "type": "ClassBody", - "start": 10, - "end": 84, - "loc": { - "start": { - "line": 1, - "column": 10 - }, - "end": { - "line": 7, - "column": 1 - } - }, + "start":10,"end":84,"loc":{"start":{"line":1,"column":10},"end":{"line":7,"column":1}}, "body": [ { "type": "ClassPrivateProperty", - "start": 14, - "end": 28, - "loc": { - "start": { - "line": 2, - "column": 2 - }, - "end": { - "line": 2, - "column": 16 - } - }, + "start":14,"end":28,"loc":{"start":{"line":2,"column":2},"end":{"line":2,"column":16}}, "static": true, "key": { "type": "PrivateName", - "start": 21, - "end": 23, - "loc": { - "start": { - "line": 2, - "column": 9 - }, - "end": { - "line": 2, - "column": 11 - } - }, + "start":21,"end":23,"loc":{"start":{"line":2,"column":9},"end":{"line":2,"column":11}}, "id": { "type": "Identifier", - "start": 22, - "end": 23, - "loc": { - "start": { - "line": 2, - "column": 10 - }, - "end": { - "line": 2, - "column": 11 - }, - "identifierName": "x" - }, + "start":22,"end":23,"loc":{"start":{"line":2,"column":10},"end":{"line":2,"column":11},"identifierName":"x"}, "name": "x" } }, "value": { "type": "NumericLiteral", - "start": 26, - "end": 27, - "loc": { - "start": { - "line": 2, - "column": 14 - }, - "end": { - "line": 2, - "column": 15 - } - }, + "start":26,"end":27,"loc":{"start":{"line":2,"column":14},"end":{"line":2,"column":15}}, "extra": { "rawValue": 1, "raw": "1" @@ -149,34 +48,11 @@ }, { "type": "ClassMethod", - "start": 32, - "end": 82, - "loc": { - "start": { - "line": 4, - "column": 2 - }, - "end": { - "line": 6, - "column": 3 - } - }, + "start":32,"end":82,"loc":{"start":{"line":4,"column":2},"end":{"line":6,"column":3}}, "static": true, "key": { "type": "Identifier", - "start": 39, - "end": 43, - "loc": { - "start": { - "line": 4, - "column": 9 - }, - "end": { - "line": 4, - "column": 13 - }, - "identifierName": "test" - }, + "start":39,"end":43,"loc":{"start":{"line":4,"column":9},"end":{"line":4,"column":13},"identifierName":"test"}, "name": "test" }, "computed": false, @@ -187,121 +63,31 @@ "params": [], "body": { "type": "BlockStatement", - "start": 46, - "end": 82, - "loc": { - "start": { - "line": 4, - "column": 16 - }, - "end": { - "line": 6, - "column": 3 - } - }, + "start":46,"end":82,"loc":{"start":{"line":4,"column":16},"end":{"line":6,"column":3}}, "body": [ { "type": "ReturnStatement", - "start": 52, - "end": 78, - "loc": { - "start": { - "line": 5, - "column": 4 - }, - "end": { - "line": 5, - "column": 30 - } - }, + "start":52,"end":78,"loc":{"start":{"line":5,"column":4},"end":{"line":5,"column":30}}, "argument": { "type": "OptionalCallExpression", - "start": 59, - "end": 77, - "loc": { - "start": { - "line": 5, - "column": 11 - }, - "end": { - "line": 5, - "column": 29 - } - }, + "start":59,"end":77,"loc":{"start":{"line":5,"column":11},"end":{"line":5,"column":29}}, "callee": { "type": "OptionalMemberExpression", - "start": 59, - "end": 74, - "loc": { - "start": { - "line": 5, - "column": 11 - }, - "end": { - "line": 5, - "column": 26 - } - }, + "start":59,"end":74,"loc":{"start":{"line":5,"column":11},"end":{"line":5,"column":26}}, "object": { "type": "OptionalMemberExpression", - "start": 59, - "end": 66, - "loc": { - "start": { - "line": 5, - "column": 11 - }, - "end": { - "line": 5, - "column": 18 - } - }, + "start":59,"end":66,"loc":{"start":{"line":5,"column":11},"end":{"line":5,"column":18}}, "object": { "type": "Identifier", - "start": 59, - "end": 62, - "loc": { - "start": { - "line": 5, - "column": 11 - }, - "end": { - "line": 5, - "column": 14 - }, - "identifierName": "Foo" - }, + "start":59,"end":62,"loc":{"start":{"line":5,"column":11},"end":{"line":5,"column":14},"identifierName":"Foo"}, "name": "Foo" }, "property": { "type": "PrivateName", - "start": 64, - "end": 66, - "loc": { - "start": { - "line": 5, - "column": 16 - }, - "end": { - "line": 5, - "column": 18 - } - }, + "start":64,"end":66,"loc":{"start":{"line":5,"column":16},"end":{"line":5,"column":18}}, "id": { "type": "Identifier", - "start": 65, - "end": 66, - "loc": { - "start": { - "line": 5, - "column": 17 - }, - "end": { - "line": 5, - "column": 18 - }, - "identifierName": "x" - }, + "start":65,"end":66,"loc":{"start":{"line":5,"column":17},"end":{"line":5,"column":18},"identifierName":"x"}, "name": "x" } }, @@ -310,19 +96,7 @@ }, "property": { "type": "Identifier", - "start": 67, - "end": 74, - "loc": { - "start": { - "line": 5, - "column": 19 - }, - "end": { - "line": 5, - "column": 26 - }, - "identifierName": "toFixed" - }, + "start":67,"end":74,"loc":{"start":{"line":5,"column":19},"end":{"line":5,"column":26},"identifierName":"toFixed"}, "name": "toFixed" }, "computed": false, @@ -331,18 +105,7 @@ "arguments": [ { "type": "NumericLiteral", - "start": 75, - "end": 76, - "loc": { - "start": { - "line": 5, - "column": 27 - }, - "end": { - "line": 5, - "column": 28 - } - }, + "start":75,"end":76,"loc":{"start":{"line":5,"column":27},"end":{"line":5,"column":28}}, "extra": { "rawValue": 2, "raw": "2" diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-properties/optional-chain-start-member/output.json b/packages/babel-parser/test/fixtures/experimental/class-private-properties/optional-chain-start-member/output.json index 61d54387aff6..9b114be4a936 100644 --- a/packages/babel-parser/test/fixtures/experimental/class-private-properties/optional-chain-start-member/output.json +++ b/packages/babel-parser/test/fixtures/experimental/class-private-properties/optional-chain-start-member/output.json @@ -1,145 +1,44 @@ { "type": "File", - "start": 0, - "end": 81, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 7, - "column": 1 - } - }, + "start":0,"end":81,"loc":{"start":{"line":1,"column":0},"end":{"line":7,"column":1}}, "errors": [ "SyntaxError: Private property access cannot immediately follow an optional chain's `?.` (5:16)" ], "program": { "type": "Program", - "start": 0, - "end": 81, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 7, - "column": 1 - } - }, + "start":0,"end":81,"loc":{"start":{"line":1,"column":0},"end":{"line":7,"column":1}}, "sourceType": "script", "interpreter": null, "body": [ { "type": "ClassDeclaration", - "start": 0, - "end": 81, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 7, - "column": 1 - } - }, + "start":0,"end":81,"loc":{"start":{"line":1,"column":0},"end":{"line":7,"column":1}}, "id": { "type": "Identifier", - "start": 6, - "end": 9, - "loc": { - "start": { - "line": 1, - "column": 6 - }, - "end": { - "line": 1, - "column": 9 - }, - "identifierName": "Foo" - }, + "start":6,"end":9,"loc":{"start":{"line":1,"column":6},"end":{"line":1,"column":9},"identifierName":"Foo"}, "name": "Foo" }, "superClass": null, "body": { "type": "ClassBody", - "start": 10, - "end": 81, - "loc": { - "start": { - "line": 1, - "column": 10 - }, - "end": { - "line": 7, - "column": 1 - } - }, + "start":10,"end":81,"loc":{"start":{"line":1,"column":10},"end":{"line":7,"column":1}}, "body": [ { "type": "ClassPrivateProperty", - "start": 14, - "end": 28, - "loc": { - "start": { - "line": 2, - "column": 2 - }, - "end": { - "line": 2, - "column": 16 - } - }, + "start":14,"end":28,"loc":{"start":{"line":2,"column":2},"end":{"line":2,"column":16}}, "static": true, "key": { "type": "PrivateName", - "start": 21, - "end": 23, - "loc": { - "start": { - "line": 2, - "column": 9 - }, - "end": { - "line": 2, - "column": 11 - } - }, + "start":21,"end":23,"loc":{"start":{"line":2,"column":9},"end":{"line":2,"column":11}}, "id": { "type": "Identifier", - "start": 22, - "end": 23, - "loc": { - "start": { - "line": 2, - "column": 10 - }, - "end": { - "line": 2, - "column": 11 - }, - "identifierName": "x" - }, + "start":22,"end":23,"loc":{"start":{"line":2,"column":10},"end":{"line":2,"column":11},"identifierName":"x"}, "name": "x" } }, "value": { "type": "NumericLiteral", - "start": 26, - "end": 27, - "loc": { - "start": { - "line": 2, - "column": 14 - }, - "end": { - "line": 2, - "column": 15 - } - }, + "start":26,"end":27,"loc":{"start":{"line":2,"column":14},"end":{"line":2,"column":15}}, "extra": { "rawValue": 1, "raw": "1" @@ -149,34 +48,11 @@ }, { "type": "ClassMethod", - "start": 32, - "end": 79, - "loc": { - "start": { - "line": 4, - "column": 2 - }, - "end": { - "line": 6, - "column": 3 - } - }, + "start":32,"end":79,"loc":{"start":{"line":4,"column":2},"end":{"line":6,"column":3}}, "static": true, "key": { "type": "Identifier", - "start": 39, - "end": 43, - "loc": { - "start": { - "line": 4, - "column": 9 - }, - "end": { - "line": 4, - "column": 13 - }, - "identifierName": "test" - }, + "start":39,"end":43,"loc":{"start":{"line":4,"column":9},"end":{"line":4,"column":13},"identifierName":"test"}, "name": "test" }, "computed": false, @@ -187,107 +63,28 @@ "params": [], "body": { "type": "BlockStatement", - "start": 46, - "end": 79, - "loc": { - "start": { - "line": 4, - "column": 16 - }, - "end": { - "line": 6, - "column": 3 - } - }, + "start":46,"end":79,"loc":{"start":{"line":4,"column":16},"end":{"line":6,"column":3}}, "body": [ { "type": "ReturnStatement", - "start": 52, - "end": 75, - "loc": { - "start": { - "line": 5, - "column": 4 - }, - "end": { - "line": 5, - "column": 27 - } - }, + "start":52,"end":75,"loc":{"start":{"line":5,"column":4},"end":{"line":5,"column":27}}, "argument": { "type": "OptionalMemberExpression", - "start": 59, - "end": 74, - "loc": { - "start": { - "line": 5, - "column": 11 - }, - "end": { - "line": 5, - "column": 26 - } - }, + "start":59,"end":74,"loc":{"start":{"line":5,"column":11},"end":{"line":5,"column":26}}, "object": { "type": "OptionalMemberExpression", - "start": 59, - "end": 66, - "loc": { - "start": { - "line": 5, - "column": 11 - }, - "end": { - "line": 5, - "column": 18 - } - }, + "start":59,"end":66,"loc":{"start":{"line":5,"column":11},"end":{"line":5,"column":18}}, "object": { "type": "Identifier", - "start": 59, - "end": 62, - "loc": { - "start": { - "line": 5, - "column": 11 - }, - "end": { - "line": 5, - "column": 14 - }, - "identifierName": "Foo" - }, + "start":59,"end":62,"loc":{"start":{"line":5,"column":11},"end":{"line":5,"column":14},"identifierName":"Foo"}, "name": "Foo" }, "property": { "type": "PrivateName", - "start": 64, - "end": 66, - "loc": { - "start": { - "line": 5, - "column": 16 - }, - "end": { - "line": 5, - "column": 18 - } - }, + "start":64,"end":66,"loc":{"start":{"line":5,"column":16},"end":{"line":5,"column":18}}, "id": { "type": "Identifier", - "start": 65, - "end": 66, - "loc": { - "start": { - "line": 5, - "column": 17 - }, - "end": { - "line": 5, - "column": 18 - }, - "identifierName": "x" - }, + "start":65,"end":66,"loc":{"start":{"line":5,"column":17},"end":{"line":5,"column":18},"identifierName":"x"}, "name": "x" } }, @@ -296,19 +93,7 @@ }, "property": { "type": "Identifier", - "start": 67, - "end": 74, - "loc": { - "start": { - "line": 5, - "column": 19 - }, - "end": { - "line": 5, - "column": 26 - }, - "identifierName": "toFixed" - }, + "start":67,"end":74,"loc":{"start":{"line":5,"column":19},"end":{"line":5,"column":26},"identifierName":"toFixed"}, "name": "toFixed" }, "computed": false, diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-properties/optional-chain-start-simple/output.json b/packages/babel-parser/test/fixtures/experimental/class-private-properties/optional-chain-start-simple/output.json index 8f9da5de5c11..95887bcdde9d 100644 --- a/packages/babel-parser/test/fixtures/experimental/class-private-properties/optional-chain-start-simple/output.json +++ b/packages/babel-parser/test/fixtures/experimental/class-private-properties/optional-chain-start-simple/output.json @@ -1,145 +1,44 @@ { "type": "File", - "start": 0, - "end": 73, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 7, - "column": 1 - } - }, + "start":0,"end":73,"loc":{"start":{"line":1,"column":0},"end":{"line":7,"column":1}}, "errors": [ "SyntaxError: Private property access cannot immediately follow an optional chain's `?.` (5:16)" ], "program": { "type": "Program", - "start": 0, - "end": 73, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 7, - "column": 1 - } - }, + "start":0,"end":73,"loc":{"start":{"line":1,"column":0},"end":{"line":7,"column":1}}, "sourceType": "script", "interpreter": null, "body": [ { "type": "ClassDeclaration", - "start": 0, - "end": 73, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 7, - "column": 1 - } - }, + "start":0,"end":73,"loc":{"start":{"line":1,"column":0},"end":{"line":7,"column":1}}, "id": { "type": "Identifier", - "start": 6, - "end": 9, - "loc": { - "start": { - "line": 1, - "column": 6 - }, - "end": { - "line": 1, - "column": 9 - }, - "identifierName": "Foo" - }, + "start":6,"end":9,"loc":{"start":{"line":1,"column":6},"end":{"line":1,"column":9},"identifierName":"Foo"}, "name": "Foo" }, "superClass": null, "body": { "type": "ClassBody", - "start": 10, - "end": 73, - "loc": { - "start": { - "line": 1, - "column": 10 - }, - "end": { - "line": 7, - "column": 1 - } - }, + "start":10,"end":73,"loc":{"start":{"line":1,"column":10},"end":{"line":7,"column":1}}, "body": [ { "type": "ClassPrivateProperty", - "start": 14, - "end": 28, - "loc": { - "start": { - "line": 2, - "column": 2 - }, - "end": { - "line": 2, - "column": 16 - } - }, + "start":14,"end":28,"loc":{"start":{"line":2,"column":2},"end":{"line":2,"column":16}}, "static": true, "key": { "type": "PrivateName", - "start": 21, - "end": 23, - "loc": { - "start": { - "line": 2, - "column": 9 - }, - "end": { - "line": 2, - "column": 11 - } - }, + "start":21,"end":23,"loc":{"start":{"line":2,"column":9},"end":{"line":2,"column":11}}, "id": { "type": "Identifier", - "start": 22, - "end": 23, - "loc": { - "start": { - "line": 2, - "column": 10 - }, - "end": { - "line": 2, - "column": 11 - }, - "identifierName": "x" - }, + "start":22,"end":23,"loc":{"start":{"line":2,"column":10},"end":{"line":2,"column":11},"identifierName":"x"}, "name": "x" } }, "value": { "type": "NumericLiteral", - "start": 26, - "end": 27, - "loc": { - "start": { - "line": 2, - "column": 14 - }, - "end": { - "line": 2, - "column": 15 - } - }, + "start":26,"end":27,"loc":{"start":{"line":2,"column":14},"end":{"line":2,"column":15}}, "extra": { "rawValue": 1, "raw": "1" @@ -149,34 +48,11 @@ }, { "type": "ClassMethod", - "start": 32, - "end": 71, - "loc": { - "start": { - "line": 4, - "column": 2 - }, - "end": { - "line": 6, - "column": 3 - } - }, + "start":32,"end":71,"loc":{"start":{"line":4,"column":2},"end":{"line":6,"column":3}}, "static": true, "key": { "type": "Identifier", - "start": 39, - "end": 43, - "loc": { - "start": { - "line": 4, - "column": 9 - }, - "end": { - "line": 4, - "column": 13 - }, - "identifierName": "test" - }, + "start":39,"end":43,"loc":{"start":{"line":4,"column":9},"end":{"line":4,"column":13},"identifierName":"test"}, "name": "test" }, "computed": false, @@ -187,93 +63,25 @@ "params": [], "body": { "type": "BlockStatement", - "start": 46, - "end": 71, - "loc": { - "start": { - "line": 4, - "column": 16 - }, - "end": { - "line": 6, - "column": 3 - } - }, + "start":46,"end":71,"loc":{"start":{"line":4,"column":16},"end":{"line":6,"column":3}}, "body": [ { "type": "ReturnStatement", - "start": 52, - "end": 67, - "loc": { - "start": { - "line": 5, - "column": 4 - }, - "end": { - "line": 5, - "column": 19 - } - }, + "start":52,"end":67,"loc":{"start":{"line":5,"column":4},"end":{"line":5,"column":19}}, "argument": { "type": "OptionalMemberExpression", - "start": 59, - "end": 66, - "loc": { - "start": { - "line": 5, - "column": 11 - }, - "end": { - "line": 5, - "column": 18 - } - }, + "start":59,"end":66,"loc":{"start":{"line":5,"column":11},"end":{"line":5,"column":18}}, "object": { "type": "Identifier", - "start": 59, - "end": 62, - "loc": { - "start": { - "line": 5, - "column": 11 - }, - "end": { - "line": 5, - "column": 14 - }, - "identifierName": "Foo" - }, + "start":59,"end":62,"loc":{"start":{"line":5,"column":11},"end":{"line":5,"column":14},"identifierName":"Foo"}, "name": "Foo" }, "property": { "type": "PrivateName", - "start": 64, - "end": 66, - "loc": { - "start": { - "line": 5, - "column": 16 - }, - "end": { - "line": 5, - "column": 18 - } - }, + "start":64,"end":66,"loc":{"start":{"line":5,"column":16},"end":{"line":5,"column":18}}, "id": { "type": "Identifier", - "start": 65, - "end": 66, - "loc": { - "start": { - "line": 5, - "column": 17 - }, - "end": { - "line": 5, - "column": 18 - }, - "identifierName": "x" - }, + "start":65,"end":66,"loc":{"start":{"line":5,"column":17},"end":{"line":5,"column":18},"identifierName":"x"}, "name": "x" } }, From 381a6223087cb261e4adab5402421420ad6a7176 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hu=C3=A1ng=20J=C3=B9nli=C3=A0ng?= Date: Wed, 20 May 2020 14:56:51 -0400 Subject: [PATCH 09/20] feat: allow ?. PrivateIdentifier in parser --- packages/babel-parser/src/parser/expression.js | 3 --- packages/babel-parser/src/parser/location.js | 2 -- .../optional-chain-start-call/output.json | 3 --- .../optional-chain-start-member-call/output.json | 3 --- .../optional-chain-start-member/output.json | 5 +---- .../optional-chain-start-simple/output.json | 3 --- 6 files changed, 1 insertion(+), 18 deletions(-) diff --git a/packages/babel-parser/src/parser/expression.js b/packages/babel-parser/src/parser/expression.js index b05352d69b2b..2135404063c1 100644 --- a/packages/babel-parser/src/parser/expression.js +++ b/packages/babel-parser/src/parser/expression.js @@ -623,9 +623,6 @@ export default class ExpressionParser extends LValParser { if (node.object.type === "Super") { this.raise(startPos, Errors.SuperPrivateField); } - if (optional) { - this.raise(node.property.start, Errors.OptionalChainingNoPrivate); - } this.classScope.usePrivateName( node.property.id.name, node.property.start, diff --git a/packages/babel-parser/src/parser/location.js b/packages/babel-parser/src/parser/location.js index fc0352152578..a03f41af63cc 100644 --- a/packages/babel-parser/src/parser/location.js +++ b/packages/babel-parser/src/parser/location.js @@ -108,8 +108,6 @@ export const Errors = Object.freeze({ "await* has been removed from the async functions proposal. Use Promise.all() instead.", OptionalChainingNoNew: "constructors in/after an Optional Chain are not allowed", - OptionalChainingNoPrivate: - "Private property access cannot immediately follow an optional chain's `?.`", OptionalChainingNoTemplate: "Tagged Template Literals are not allowed in optionalChain", ParamDupe: "Argument name clash", diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-properties/optional-chain-start-call/output.json b/packages/babel-parser/test/fixtures/experimental/class-private-properties/optional-chain-start-call/output.json index 0aa1b746c2aa..fab6f81ebb0c 100644 --- a/packages/babel-parser/test/fixtures/experimental/class-private-properties/optional-chain-start-call/output.json +++ b/packages/babel-parser/test/fixtures/experimental/class-private-properties/optional-chain-start-call/output.json @@ -1,9 +1,6 @@ { "type": "File", "start":0,"end":87,"loc":{"start":{"line":1,"column":0},"end":{"line":7,"column":1}}, - "errors": [ - "SyntaxError: Private property access cannot immediately follow an optional chain's `?.` (5:16)" - ], "program": { "type": "Program", "start":0,"end":87,"loc":{"start":{"line":1,"column":0},"end":{"line":7,"column":1}}, diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-properties/optional-chain-start-member-call/output.json b/packages/babel-parser/test/fixtures/experimental/class-private-properties/optional-chain-start-member-call/output.json index 20ed4fa71a80..10b49c52f465 100644 --- a/packages/babel-parser/test/fixtures/experimental/class-private-properties/optional-chain-start-member-call/output.json +++ b/packages/babel-parser/test/fixtures/experimental/class-private-properties/optional-chain-start-member-call/output.json @@ -1,9 +1,6 @@ { "type": "File", "start":0,"end":84,"loc":{"start":{"line":1,"column":0},"end":{"line":7,"column":1}}, - "errors": [ - "SyntaxError: Private property access cannot immediately follow an optional chain's `?.` (5:16)" - ], "program": { "type": "Program", "start":0,"end":84,"loc":{"start":{"line":1,"column":0},"end":{"line":7,"column":1}}, diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-properties/optional-chain-start-member/output.json b/packages/babel-parser/test/fixtures/experimental/class-private-properties/optional-chain-start-member/output.json index 9b114be4a936..44f1a1d0548a 100644 --- a/packages/babel-parser/test/fixtures/experimental/class-private-properties/optional-chain-start-member/output.json +++ b/packages/babel-parser/test/fixtures/experimental/class-private-properties/optional-chain-start-member/output.json @@ -1,9 +1,6 @@ { "type": "File", "start":0,"end":81,"loc":{"start":{"line":1,"column":0},"end":{"line":7,"column":1}}, - "errors": [ - "SyntaxError: Private property access cannot immediately follow an optional chain's `?.` (5:16)" - ], "program": { "type": "Program", "start":0,"end":81,"loc":{"start":{"line":1,"column":0},"end":{"line":7,"column":1}}, @@ -110,4 +107,4 @@ ], "directives": [] } -} \ No newline at end of file +} diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-properties/optional-chain-start-simple/output.json b/packages/babel-parser/test/fixtures/experimental/class-private-properties/optional-chain-start-simple/output.json index 95887bcdde9d..bf77ed55e9a7 100644 --- a/packages/babel-parser/test/fixtures/experimental/class-private-properties/optional-chain-start-simple/output.json +++ b/packages/babel-parser/test/fixtures/experimental/class-private-properties/optional-chain-start-simple/output.json @@ -1,9 +1,6 @@ { "type": "File", "start":0,"end":73,"loc":{"start":{"line":1,"column":0},"end":{"line":7,"column":1}}, - "errors": [ - "SyntaxError: Private property access cannot immediately follow an optional chain's `?.` (5:16)" - ], "program": { "type": "Program", "start":0,"end":73,"loc":{"start":{"line":1,"column":0},"end":{"line":7,"column":1}}, From de86a3db6587facbc3f4d45a0dcd3420144abd86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hu=C3=A1ng=20J=C3=B9nli=C3=A0ng?= Date: Wed, 20 May 2020 16:04:43 -0400 Subject: [PATCH 10/20] fix: rebase error --- .../babel-helper-create-class-features-plugin/src/fields.js | 6 ++++++ 1 file changed, 6 insertions(+) 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 46d14f08a2bf..98babe2635b8 100644 --- a/packages/babel-helper-create-class-features-plugin/src/fields.js +++ b/packages/babel-helper-create-class-features-plugin/src/fields.js @@ -348,6 +348,12 @@ export function transformPrivateNamesUsage( file: state, ...handler, }); + body.traverse(privateInVisitor, { + privateNamesMap, + classRef: ref, + file: state, + loose, + }); } function buildPrivateFieldInitLoose(ref, prop, privateNamesMap) { From 0742d998127031313a9dae0a2c44101f3034f1b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hu=C3=A1ng=20J=C3=B9nli=C3=A0ng?= Date: Thu, 21 May 2020 13:54:38 -0400 Subject: [PATCH 11/20] update test262 whitelist --- scripts/parser-tests/test262/whitelist.txt | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/scripts/parser-tests/test262/whitelist.txt b/scripts/parser-tests/test262/whitelist.txt index 75b75ef96b23..8b137891791f 100644 --- a/scripts/parser-tests/test262/whitelist.txt +++ b/scripts/parser-tests/test262/whitelist.txt @@ -1,4 +1 @@ -language/expressions/class/elements/grammar-private-field-optional-chaining.js(default) -language/expressions/class/elements/grammar-private-field-optional-chaining.js(strict mode) -language/statements/class/elements/grammar-private-field-optional-chaining.js(default) -language/statements/class/elements/grammar-private-field-optional-chaining.js(strict mode) + From 785b6e8bde1419b3ea7d219cd8caf9dab043edfb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hu=C3=A1ng=20J=C3=B9nli=C3=A0ng?= Date: Fri, 22 May 2020 16:08:27 -0400 Subject: [PATCH 12/20] feat: support ?.#x and ?.#m() --- .../src/index.js | 15 ++- .../exec.js | 0 .../input.js | 0 .../options.json | 0 .../output.js | 0 .../optional-chain-before-member-call/exec.js | 122 +++++++++++++++++ .../input.js | 0 .../options.json | 0 .../output.js | 0 .../exec.js | 0 .../input.js | 0 .../options.json | 0 .../output.js | 0 .../optional-chain-before-property/exec.js | 121 +++++++++++++++++ .../input.js | 0 .../options.json | 0 .../output.js | 0 .../exec.js | 126 ++++++++++++++++++ .../input.js | 70 ++++++++++ .../options.json | 3 + .../output.js | 92 +++++++++++++ .../exec.js | 126 ++++++++++++++++++ .../input.js | 70 ++++++++++ .../options.json | 3 + .../output.js | 92 +++++++++++++ .../exec.js | 125 +++++++++++++++++ .../input.js | 69 ++++++++++ .../options.json | 3 + .../output.js | 86 ++++++++++++ .../optional-chain-optional-property/exec.js | 125 +++++++++++++++++ .../optional-chain-optional-property/input.js | 70 ++++++++++ .../options.json | 3 + .../output.js | 86 ++++++++++++ 33 files changed, 1400 insertions(+), 7 deletions(-) rename packages/babel-plugin-proposal-class-properties/test/fixtures/private/{optional-chain-private-call-with-transform => optional-chain-before-member-call-with-transform}/exec.js (100%) rename packages/babel-plugin-proposal-class-properties/test/fixtures/private/{optional-chain-private-call-with-transform => optional-chain-before-member-call-with-transform}/input.js (100%) rename packages/babel-plugin-proposal-class-properties/test/fixtures/private/{optional-chain-private-call-with-transform => optional-chain-before-member-call-with-transform}/options.json (100%) rename packages/babel-plugin-proposal-class-properties/test/fixtures/private/{optional-chain-private-call-with-transform => optional-chain-before-member-call-with-transform}/output.js (100%) create mode 100644 packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-before-member-call/exec.js rename packages/babel-plugin-proposal-class-properties/test/fixtures/private/{optional-chain-private-call => optional-chain-before-member-call}/input.js (100%) rename packages/babel-plugin-proposal-class-properties/test/fixtures/private/{optional-chain-private-call => optional-chain-before-member-call}/options.json (100%) rename packages/babel-plugin-proposal-class-properties/test/fixtures/private/{optional-chain-private-call => optional-chain-before-member-call}/output.js (100%) rename packages/babel-plugin-proposal-class-properties/test/fixtures/private/{optional-chain-with-transform => optional-chain-before-property-with-transform}/exec.js (100%) rename packages/babel-plugin-proposal-class-properties/test/fixtures/private/{optional-chain-with-transform => optional-chain-before-property-with-transform}/input.js (100%) rename packages/babel-plugin-proposal-class-properties/test/fixtures/private/{optional-chain-with-transform => optional-chain-before-property-with-transform}/options.json (100%) rename packages/babel-plugin-proposal-class-properties/test/fixtures/private/{optional-chain-with-transform => optional-chain-before-property-with-transform}/output.js (100%) create mode 100644 packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-before-property/exec.js rename packages/babel-plugin-proposal-class-properties/test/fixtures/private/{optional-chain => optional-chain-before-property}/input.js (100%) rename packages/babel-plugin-proposal-class-properties/test/fixtures/private/{optional-chain => optional-chain-before-property}/options.json (100%) rename packages/babel-plugin-proposal-class-properties/test/fixtures/private/{optional-chain => optional-chain-before-property}/output.js (100%) create mode 100644 packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-optional-member-call-with-transform/exec.js create mode 100644 packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-optional-member-call-with-transform/input.js create mode 100644 packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-optional-member-call-with-transform/options.json create mode 100644 packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-optional-member-call-with-transform/output.js create mode 100644 packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-optional-member-call/exec.js create mode 100644 packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-optional-member-call/input.js create mode 100644 packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-optional-member-call/options.json create mode 100644 packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-optional-member-call/output.js create mode 100644 packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-optional-property-with-transform/exec.js create mode 100644 packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-optional-property-with-transform/input.js create mode 100644 packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-optional-property-with-transform/options.json create mode 100644 packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-optional-property-with-transform/output.js create mode 100644 packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-optional-property/exec.js create mode 100644 packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-optional-property/input.js create mode 100644 packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-optional-property/options.json create mode 100644 packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-optional-property/output.js 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 b7482bcdd46c..fe3d22cadbd4 100644 --- a/packages/babel-helper-member-expression-to-functions/src/index.js +++ b/packages/babel-helper-member-expression-to-functions/src/index.js @@ -125,12 +125,6 @@ const handle = { throw member.buildCodeFrameError(`can't handle delete`); } - if (node.optional) { - throw member.buildCodeFrameError( - `can't handle '?.' directly before ${node.property.type}`, - ); - } - // Now, we're looking for the start of this optional chain, which is // optional to the left of this member. // @@ -150,6 +144,8 @@ const handle = { startingOptional = startingOptional.get("callee"); continue; } + // prevent infinite loop: unreachable if the AST is well-formed + throw new Error("Internal error"); } const { scope } = member; @@ -160,8 +156,13 @@ const handle = { const baseRef = scope.generateUidIdentifierBasedOnNode(startingNode); scope.push({ id: baseRef }); + // Compute parentIsOptionalCall before `startingOptional` is replaced + // as `node` may refer to `startingOptional.node` before replaced. + const parentIsOptionalCall = parentPath.isOptionalCallExpression({ + callee: node, + }); startingOptional.replaceWith(toNonOptional(startingOptional, baseRef)); - if (parentPath.isOptionalCallExpression({ callee: node })) { + if (parentIsOptionalCall) { parentPath.replaceWith(this.call(member, parent.arguments)); } else { member.replaceWith(this.get(member)); diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-private-call-with-transform/exec.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-before-member-call-with-transform/exec.js similarity index 100% rename from packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-private-call-with-transform/exec.js rename to packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-before-member-call-with-transform/exec.js diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-private-call-with-transform/input.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-before-member-call-with-transform/input.js similarity index 100% rename from packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-private-call-with-transform/input.js rename to packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-before-member-call-with-transform/input.js diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-private-call-with-transform/options.json b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-before-member-call-with-transform/options.json similarity index 100% rename from packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-private-call-with-transform/options.json rename to packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-before-member-call-with-transform/options.json diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-private-call-with-transform/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-before-member-call-with-transform/output.js similarity index 100% rename from packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-private-call-with-transform/output.js rename to packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-before-member-call-with-transform/output.js diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-before-member-call/exec.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-before-member-call/exec.js new file mode 100644 index 000000000000..13cc95662d95 --- /dev/null +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-before-member-call/exec.js @@ -0,0 +1,122 @@ +class Foo { + static #x = 1; + static #m = function() { return this.#x; }; + static #self = Foo; + static self = Foo; + static getSelf() { return this } + + static test() { + const o = { Foo: Foo }; + const deep = { very: { o } }; + function fn() { + return o; + } + function fnDeep() { + return deep; + } + + expect(o?.Foo.#m()).toEqual(1); + expect(o?.Foo.#m().toString).toEqual(1..toString); + expect(o?.Foo.#m().toString()).toEqual('1'); + + expect(deep?.very.o?.Foo.#m()).toEqual(1); + expect(deep?.very.o?.Foo.#m().toString).toEqual(1..toString); + expect(deep?.very.o?.Foo.#m().toString()).toEqual('1'); + + expect(o?.Foo.#self.#m()).toEqual(1); + expect(o?.Foo.#self.self.#m()).toEqual(1); + expect(o?.Foo.#self?.self.#m()).toEqual(1); + expect(o?.Foo.#self.self?.self.#m()).toEqual(1); + expect(o?.Foo.#self?.self?.self.#m()).toEqual(1); + + expect(o?.Foo.#self.getSelf().#m()).toEqual(1); + expect(o?.Foo.#self.getSelf?.().#m()).toEqual(1); + expect(o?.Foo.#self?.getSelf().#m()).toEqual(1); + expect(o?.Foo.#self?.getSelf?.().#m()).toEqual(1); + expect(o?.Foo.#self.getSelf()?.self.#m()).toEqual(1); + expect(o?.Foo.#self.getSelf?.()?.self.#m()).toEqual(1); + expect(o?.Foo.#self?.getSelf()?.self.#m()).toEqual(1); + expect(o?.Foo.#self?.getSelf?.()?.self.#m()).toEqual(1); + + expect(fn?.().Foo.#m()).toEqual(1); + expect(fn?.().Foo.#m().toString).toEqual(1..toString); + expect(fn?.().Foo.#m().toString()).toEqual('1'); + + expect(fnDeep?.().very.o?.Foo.#m()).toEqual(1); + expect(fnDeep?.().very.o?.Foo.#m().toString).toEqual(1..toString); + expect(fnDeep?.().very.o?.Foo.#m().toString()).toEqual('1'); + + expect(fn?.().Foo.#self.#m()).toEqual(1); + expect(fn?.().Foo.#self.self.#m()).toEqual(1); + expect(fn?.().Foo.#self?.self.#m()).toEqual(1); + expect(fn?.().Foo.#self.self?.self.#m()).toEqual(1); + expect(fn?.().Foo.#self?.self?.self.#m()).toEqual(1); + + expect(fn?.().Foo.#self.getSelf().#m()).toEqual(1); + expect(fn?.().Foo.#self.getSelf?.().#m()).toEqual(1); + expect(fn?.().Foo.#self?.getSelf().#m()).toEqual(1); + expect(fn?.().Foo.#self?.getSelf?.().#m()).toEqual(1); + expect(fn?.().Foo.#self.getSelf()?.self.#m()).toEqual(1); + expect(fn?.().Foo.#self.getSelf?.()?.self.#m()).toEqual(1); + expect(fn?.().Foo.#self?.getSelf()?.self.#m()).toEqual(1); + expect(fn?.().Foo.#self?.getSelf?.()?.self.#m()).toEqual(1); + } + + static testNull() { + const o = null;; + const deep = { very: { o } }; + const fn = null; + function fnDeep() { + return deep; + } + + expect(o?.Foo.#m()).toEqual(undefined); + expect(o?.Foo.#m().toString).toEqual(undefined); + expect(o?.Foo.#m().toString()).toEqual(undefined); + + expect(deep?.very.o?.Foo.#m()).toEqual(undefined); + expect(deep?.very.o?.Foo.#m().toString).toEqual(undefined); + expect(deep?.very.o?.Foo.#m().toString()).toEqual(undefined); + + expect(o?.Foo.#self.#m()).toEqual(undefined); + expect(o?.Foo.#self.self.#m()).toEqual(undefined); + expect(o?.Foo.#self?.self.#m()).toEqual(undefined); + expect(o?.Foo.#self.self?.self.#m()).toEqual(undefined); + expect(o?.Foo.#self?.self?.self.#m()).toEqual(undefined); + + expect(o?.Foo.#self.getSelf().#m()).toEqual(undefined); + expect(o?.Foo.#self.getSelf?.().#m()).toEqual(undefined); + expect(o?.Foo.#self?.getSelf().#m()).toEqual(undefined); + expect(o?.Foo.#self?.getSelf?.().#m()).toEqual(undefined); + expect(o?.Foo.#self.getSelf()?.self.#m()).toEqual(undefined); + expect(o?.Foo.#self.getSelf?.()?.self.#m()).toEqual(undefined); + expect(o?.Foo.#self?.getSelf()?.self.#m()).toEqual(undefined); + expect(o?.Foo.#self?.getSelf?.()?.self.#m()).toEqual(undefined); + + expect(fn?.().Foo.#m()).toEqual(undefined); + expect(fn?.().Foo.#m().toString).toEqual(undefined); + expect(fn?.().Foo.#m().toString()).toEqual(undefined); + + expect(fnDeep?.().very.o?.Foo.#m()).toEqual(undefined); + expect(fnDeep?.().very.o?.Foo.#m().toString).toEqual(undefined); + expect(fnDeep?.().very.o?.Foo.#m().toString()).toEqual(undefined); + + expect(fn?.().Foo.#self.#m()).toEqual(undefined); + expect(fn?.().Foo.#self.self.#m()).toEqual(undefined); + expect(fn?.().Foo.#self?.self.#m()).toEqual(undefined); + expect(fn?.().Foo.#self.self?.self.#m()).toEqual(undefined); + expect(fn?.().Foo.#self?.self?.self.#m()).toEqual(undefined); + + expect(fn?.().Foo.#self.getSelf().#m()).toEqual(undefined); + expect(fn?.().Foo.#self.getSelf?.().#m()).toEqual(undefined); + expect(fn?.().Foo.#self?.getSelf().#m()).toEqual(undefined); + expect(fn?.().Foo.#self?.getSelf?.().#m()).toEqual(undefined); + expect(fn?.().Foo.#self.getSelf()?.self.#m()).toEqual(undefined); + expect(fn?.().Foo.#self.getSelf?.()?.self.#m()).toEqual(undefined); + expect(fn?.().Foo.#self?.getSelf()?.self.#m()).toEqual(undefined); + expect(fn?.().Foo.#self?.getSelf?.()?.self.#m()).toEqual(undefined); + } +} + +Foo.test(); +Foo.testNull(); diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-private-call/input.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-before-member-call/input.js similarity index 100% rename from packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-private-call/input.js rename to packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-before-member-call/input.js diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-private-call/options.json b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-before-member-call/options.json similarity index 100% rename from packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-private-call/options.json rename to packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-before-member-call/options.json diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-private-call/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-before-member-call/output.js similarity index 100% rename from packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-private-call/output.js rename to packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-before-member-call/output.js diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-with-transform/exec.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-before-property-with-transform/exec.js similarity index 100% rename from packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-with-transform/exec.js rename to packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-before-property-with-transform/exec.js diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-with-transform/input.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-before-property-with-transform/input.js similarity index 100% rename from packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-with-transform/input.js rename to packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-before-property-with-transform/input.js diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-with-transform/options.json b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-before-property-with-transform/options.json similarity index 100% rename from packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-with-transform/options.json rename to packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-before-property-with-transform/options.json diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-with-transform/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-before-property-with-transform/output.js similarity index 100% rename from packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-with-transform/output.js rename to packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-before-property-with-transform/output.js diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-before-property/exec.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-before-property/exec.js new file mode 100644 index 000000000000..98ac8e7a7e12 --- /dev/null +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-before-property/exec.js @@ -0,0 +1,121 @@ +class Foo { + static #x = 1; + static #self = Foo; + static self = Foo; + static getSelf() { return this } + + static test() { + const o = { Foo: Foo }; + const deep = { very: { o } }; + function fn() { + return o; + } + function fnDeep() { + return deep; + } + + expect(o?.Foo.#x).toEqual(1); + expect(o?.Foo.#x.toString).toEqual(1..toString); + expect(o?.Foo.#x.toString()).toEqual('1'); + + expect(deep?.very.o?.Foo.#x).toEqual(1); + expect(deep?.very.o?.Foo.#x.toString).toEqual(1..toString); + expect(deep?.very.o?.Foo.#x.toString()).toEqual('1'); + + expect(o?.Foo.#self.#x).toEqual(1); + expect(o?.Foo.#self.self.#x).toEqual(1); + expect(o?.Foo.#self?.self.#x).toEqual(1); + expect(o?.Foo.#self.self?.self.#x).toEqual(1); + expect(o?.Foo.#self?.self?.self.#x).toEqual(1); + + expect(o?.Foo.#self.getSelf().#x).toEqual(1); + expect(o?.Foo.#self.getSelf?.().#x).toEqual(1); + expect(o?.Foo.#self?.getSelf().#x).toEqual(1); + expect(o?.Foo.#self?.getSelf?.().#x).toEqual(1); + expect(o?.Foo.#self.getSelf()?.self.#x).toEqual(1); + expect(o?.Foo.#self.getSelf?.()?.self.#x).toEqual(1); + expect(o?.Foo.#self?.getSelf()?.self.#x).toEqual(1); + expect(o?.Foo.#self?.getSelf?.()?.self.#x).toEqual(1); + + expect(fn?.().Foo.#x).toEqual(1); + expect(fn?.().Foo.#x.toString).toEqual(1..toString); + expect(fn?.().Foo.#x.toString()).toEqual('1'); + + expect(fnDeep?.().very.o?.Foo.#x).toEqual(1); + expect(fnDeep?.().very.o?.Foo.#x.toString).toEqual(1..toString); + expect(fnDeep?.().very.o?.Foo.#x.toString()).toEqual('1'); + + expect(fn?.().Foo.#self.#x).toEqual(1); + expect(fn?.().Foo.#self.self.#x).toEqual(1); + expect(fn?.().Foo.#self?.self.#x).toEqual(1); + expect(fn?.().Foo.#self.self?.self.#x).toEqual(1); + expect(fn?.().Foo.#self?.self?.self.#x).toEqual(1); + + expect(fn?.().Foo.#self.getSelf().#x).toEqual(1); + expect(fn?.().Foo.#self.getSelf?.().#x).toEqual(1); + expect(fn?.().Foo.#self?.getSelf().#x).toEqual(1); + expect(fn?.().Foo.#self?.getSelf?.().#x).toEqual(1); + expect(fn?.().Foo.#self.getSelf()?.self.#x).toEqual(1); + expect(fn?.().Foo.#self.getSelf?.()?.self.#x).toEqual(1); + expect(fn?.().Foo.#self?.getSelf()?.self.#x).toEqual(1); + expect(fn?.().Foo.#self?.getSelf?.()?.self.#x).toEqual(1); + } + + static testNull() { + const o = null;; + const deep = { very: { o } }; + const fn = null; + function fnDeep() { + return deep; + } + + expect(o?.Foo.#x).toEqual(undefined); + expect(o?.Foo.#x.toString).toEqual(undefined); + expect(o?.Foo.#x.toString()).toEqual(undefined); + + expect(deep?.very.o?.Foo.#x).toEqual(undefined); + expect(deep?.very.o?.Foo.#x.toString).toEqual(undefined); + expect(deep?.very.o?.Foo.#x.toString()).toEqual(undefined); + + expect(o?.Foo.#self.#x).toEqual(undefined); + expect(o?.Foo.#self.self.#x).toEqual(undefined); + expect(o?.Foo.#self?.self.#x).toEqual(undefined); + expect(o?.Foo.#self.self?.self.#x).toEqual(undefined); + expect(o?.Foo.#self?.self?.self.#x).toEqual(undefined); + + expect(o?.Foo.#self.getSelf().#x).toEqual(undefined); + expect(o?.Foo.#self.getSelf?.().#x).toEqual(undefined); + expect(o?.Foo.#self?.getSelf().#x).toEqual(undefined); + expect(o?.Foo.#self?.getSelf?.().#x).toEqual(undefined); + expect(o?.Foo.#self.getSelf()?.self.#x).toEqual(undefined); + expect(o?.Foo.#self.getSelf?.()?.self.#x).toEqual(undefined); + expect(o?.Foo.#self?.getSelf()?.self.#x).toEqual(undefined); + expect(o?.Foo.#self?.getSelf?.()?.self.#x).toEqual(undefined); + + expect(fn?.().Foo.#x).toEqual(undefined); + expect(fn?.().Foo.#x.toString).toEqual(undefined); + expect(fn?.().Foo.#x.toString()).toEqual(undefined); + + expect(fnDeep?.().very.o?.Foo.#x).toEqual(undefined); + expect(fnDeep?.().very.o?.Foo.#x.toString).toEqual(undefined); + expect(fnDeep?.().very.o?.Foo.#x.toString()).toEqual(undefined); + + expect(fn?.().Foo.#self.#x).toEqual(undefined); + expect(fn?.().Foo.#self.self.#x).toEqual(undefined); + expect(fn?.().Foo.#self?.self.#x).toEqual(undefined); + expect(fn?.().Foo.#self.self?.self.#x).toEqual(undefined); + expect(fn?.().Foo.#self?.self?.self.#x).toEqual(undefined); + + expect(fn?.().Foo.#self.getSelf().#x).toEqual(undefined); + expect(fn?.().Foo.#self.getSelf?.().#x).toEqual(undefined); + expect(fn?.().Foo.#self?.getSelf().#x).toEqual(undefined); + expect(fn?.().Foo.#self?.getSelf?.().#x).toEqual(undefined); + expect(fn?.().Foo.#self.getSelf()?.self.#x).toEqual(undefined); + expect(fn?.().Foo.#self.getSelf?.()?.self.#x).toEqual(undefined); + expect(fn?.().Foo.#self?.getSelf()?.self.#x).toEqual(undefined); + expect(fn?.().Foo.#self?.getSelf?.()?.self.#x).toEqual(undefined); + } +} + +Foo.test(); +Foo.testNull(); diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain/input.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-before-property/input.js similarity index 100% rename from packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain/input.js rename to packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-before-property/input.js diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain/options.json b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-before-property/options.json similarity index 100% rename from packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain/options.json rename to packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-before-property/options.json diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-before-property/output.js similarity index 100% rename from packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain/output.js rename to packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-before-property/output.js diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-optional-member-call-with-transform/exec.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-optional-member-call-with-transform/exec.js new file mode 100644 index 000000000000..df4319aff69b --- /dev/null +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-optional-member-call-with-transform/exec.js @@ -0,0 +1,126 @@ +class Foo { + static #x = 1; + static #m = function() { return this.#x; }; + static #self = Foo; + static self = Foo; + static getSelf() { return this } + + static test() { + 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(o?.Foo?.#m()).toEqual(1); + expect(o?.Foo?.#m().toString).toEqual(1..toString); + expect(o?.Foo?.#m().toString()).toEqual('1'); + + expect(deep?.very.o?.Foo?.#m()).toEqual(1); + expect(deep?.very.o?.Foo?.#m().toString).toEqual(1..toString); + expect(deep?.very.o?.Foo?.#m().toString()).toEqual('1'); + + expect(o?.Foo.#self?.#m()).toEqual(1); + expect(o?.Foo.#self.self?.#m()).toEqual(1); + expect(o?.Foo.#self?.self?.#m()).toEqual(1); + expect(o?.Foo.#self.self?.self?.#m()).toEqual(1); + expect(o?.Foo.#self?.self?.self?.#m()).toEqual(1); + + expect(o?.Foo.#self.getSelf()?.#m()).toEqual(1); + expect(o?.Foo.#self.getSelf?.()?.#m()).toEqual(1); + expect(o?.Foo.#self?.getSelf()?.#m()).toEqual(1); + expect(o?.Foo.#self?.getSelf?.()?.#m()).toEqual(1); + expect(o?.Foo.#self.getSelf()?.self?.#m()).toEqual(1); + expect(o?.Foo.#self.getSelf?.()?.self?.#m()).toEqual(1); + expect(o?.Foo.#self?.getSelf()?.self?.#m()).toEqual(1); + expect(o?.Foo.#self?.getSelf?.()?.self?.#m()).toEqual(1); + + expect(fn?.().Foo?.#m()).toEqual(1); + expect(fn?.().Foo?.#m().toString).toEqual(1..toString); + expect(fn?.().Foo?.#m().toString()).toEqual('1'); + + expect(fnDeep?.().very.o?.Foo?.#m()).toEqual(1); + expect(fnDeep?.().very.o?.Foo?.#m().toString).toEqual(1..toString); + expect(fnDeep?.().very.o?.Foo?.#m().toString()).toEqual('1'); + + expect(fn?.().Foo.#self?.#m()).toEqual(1); + expect(fn?.().Foo.#self.self?.#m()).toEqual(1); + expect(fn?.().Foo.#self?.self?.#m()).toEqual(1); + expect(fn?.().Foo.#self.self?.self?.#m()).toEqual(1); + expect(fn?.().Foo.#self?.self?.self?.#m()).toEqual(1); + + expect(fn?.().Foo.#self.getSelf()?.#m()).toEqual(1); + expect(fn?.().Foo.#self.getSelf?.()?.#m()).toEqual(1); + expect(fn?.().Foo.#self?.getSelf()?.#m()).toEqual(1); + expect(fn?.().Foo.#self?.getSelf?.()?.#m()).toEqual(1); + expect(fn?.().Foo.#self.getSelf()?.self?.#m()).toEqual(1); + expect(fn?.().Foo.#self.getSelf?.()?.self?.#m()).toEqual(1); + expect(fn?.().Foo.#self?.getSelf()?.self?.#m()).toEqual(1); + expect(fn?.().Foo.#self?.getSelf?.()?.self?.#m()).toEqual(1); + } + + static testNull() { + const o = null;; + const deep = { very: { o } }; + const fn = null; + function fnDeep() { + return deep; + } + + expect(o?.Foo?.#m()).toEqual(undefined); + expect(o?.Foo?.#m().toString).toEqual(undefined); + expect(o?.Foo?.#m().toString()).toEqual(undefined); + + expect(deep?.very.o?.Foo?.#m()).toEqual(undefined); + expect(deep?.very.o?.Foo?.#m().toString).toEqual(undefined); + expect(deep?.very.o?.Foo?.#m().toString()).toEqual(undefined); + + expect(o?.Foo.#self?.#m()).toEqual(undefined); + expect(o?.Foo.#self.self?.#m()).toEqual(undefined); + expect(o?.Foo.#self?.self?.#m()).toEqual(undefined); + expect(o?.Foo.#self.self?.self?.#m()).toEqual(undefined); + expect(o?.Foo.#self?.self?.self?.#m()).toEqual(undefined); + + expect(o?.Foo.#self.getSelf()?.#m()).toEqual(undefined); + expect(o?.Foo.#self.getSelf?.()?.#m()).toEqual(undefined); + expect(o?.Foo.#self?.getSelf()?.#m()).toEqual(undefined); + expect(o?.Foo.#self?.getSelf?.()?.#m()).toEqual(undefined); + expect(o?.Foo.#self.getSelf()?.self?.#m()).toEqual(undefined); + expect(o?.Foo.#self.getSelf?.()?.self?.#m()).toEqual(undefined); + expect(o?.Foo.#self?.getSelf()?.self?.#m()).toEqual(undefined); + expect(o?.Foo.#self?.getSelf?.()?.self?.#m()).toEqual(undefined); + + expect(fn?.().Foo?.#m()).toEqual(undefined); + expect(fn?.().Foo?.#m().toString).toEqual(undefined); + expect(fn?.().Foo?.#m().toString()).toEqual(undefined); + + expect(fnDeep?.().very.o?.Foo?.#m()).toEqual(undefined); + expect(fnDeep?.().very.o?.Foo?.#m().toString).toEqual(undefined); + expect(fnDeep?.().very.o?.Foo?.#m().toString()).toEqual(undefined); + + expect(fn?.().Foo.#self?.#m()).toEqual(undefined); + expect(fn?.().Foo.#self.self?.#m()).toEqual(undefined); + expect(fn?.().Foo.#self?.self?.#m()).toEqual(undefined); + expect(fn?.().Foo.#self.self?.self?.#m()).toEqual(undefined); + expect(fn?.().Foo.#self?.self?.self?.#m()).toEqual(undefined); + + expect(fn?.().Foo.#self.getSelf()?.#m()).toEqual(undefined); + expect(fn?.().Foo.#self.getSelf?.()?.#m()).toEqual(undefined); + expect(fn?.().Foo.#self?.getSelf()?.#m()).toEqual(undefined); + expect(fn?.().Foo.#self?.getSelf?.()?.#m()).toEqual(undefined); + expect(fn?.().Foo.#self.getSelf()?.self?.#m()).toEqual(undefined); + expect(fn?.().Foo.#self.getSelf?.()?.self?.#m()).toEqual(undefined); + expect(fn?.().Foo.#self?.getSelf()?.self?.#m()).toEqual(undefined); + expect(fn?.().Foo.#self?.getSelf?.()?.self?.#m()).toEqual(undefined); + } +} + +Foo.test(); +Foo.testNull(); diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-optional-member-call-with-transform/input.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-optional-member-call-with-transform/input.js new file mode 100644 index 000000000000..80f689342109 --- /dev/null +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-optional-member-call-with-transform/input.js @@ -0,0 +1,70 @@ +class Foo { + static #x = 1; + static #m = function() { return this.#x; }; + static #self = Foo; + static self = Foo; + static getSelf() { return this } + + static test() { + const o = { Foo: Foo }; + const deep = { very: { o } }; + function fn() { + return o; + } + function fnDeep() { + return deep; + } + + Foo?.#m(); + Foo?.#m().toString; + Foo?.#m().toString(); + + o?.Foo?.#m(); + o?.Foo?.#m().toString; + o?.Foo?.#m().toString(); + + deep?.very.o?.Foo?.#m(); + deep?.very.o?.Foo?.#m().toString; + deep?.very.o?.Foo?.#m().toString(); + + o?.Foo.#self?.#m(); + o?.Foo.#self.self?.#m(); + o?.Foo.#self?.self?.#m(); + o?.Foo.#self.self?.self?.#m(); + o?.Foo.#self?.self?.self?.#m(); + + o?.Foo.#self.getSelf()?.#m(); + o?.Foo.#self.getSelf?.()?.#m(); + o?.Foo.#self?.getSelf()?.#m(); + o?.Foo.#self?.getSelf?.()?.#m(); + o?.Foo.#self.getSelf()?.self?.#m(); + o?.Foo.#self.getSelf?.()?.self?.#m(); + o?.Foo.#self?.getSelf()?.self?.#m(); + o?.Foo.#self?.getSelf?.()?.self?.#m(); + + fn?.().Foo?.#m(); + fn?.().Foo?.#m().toString; + fn?.().Foo?.#m().toString(); + + fnDeep?.().very.o?.Foo?.#m(); + fnDeep?.().very.o?.Foo?.#m().toString; + fnDeep?.().very.o?.Foo?.#m().toString(); + + fn?.().Foo.#self?.#m(); + fn?.().Foo.#self.self?.#m(); + fn?.().Foo.#self?.self?.#m(); + fn?.().Foo.#self.self?.self?.#m(); + fn?.().Foo.#self?.self?.self?.#m(); + + fn?.().Foo.#self.getSelf()?.#m(); + fn?.().Foo.#self.getSelf?.()?.#m(); + fn?.().Foo.#self?.getSelf()?.#m(); + fn?.().Foo.#self?.getSelf?.()?.#m(); + fn?.().Foo.#self.getSelf()?.self?.#m(); + fn?.().Foo.#self.getSelf?.()?.self?.#m(); + fn?.().Foo.#self?.getSelf()?.self?.#m(); + fn?.().Foo.#self?.getSelf?.()?.self?.#m(); + } +} + +Foo.test(); diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-optional-member-call-with-transform/options.json b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-optional-member-call-with-transform/options.json new file mode 100644 index 000000000000..63b4c77cc8e8 --- /dev/null +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-optional-member-call-with-transform/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["proposal-optional-chaining", "proposal-class-properties"] +} diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-optional-member-call-with-transform/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-optional-member-call-with-transform/output.js new file mode 100644 index 000000000000..22ae2753c5d1 --- /dev/null +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-optional-member-call-with-transform/output.js @@ -0,0 +1,92 @@ +function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } + +function _classStaticPrivateFieldSpecGet(receiver, classConstructor, descriptor) { if (receiver !== classConstructor) { throw new TypeError("Private static access of wrong provenance"); } if (descriptor.get) { return descriptor.get.call(receiver); } return descriptor.value; } + +class Foo { + static getSelf() { + return this; + } + + static test() { + var _Foo, _Foo2, _Foo3, _o$Foo, _o$Foo2, _o$Foo3, _deep$very$o$Foo, _deep$very$o$Foo2, _deep$very$o$Foo3, _o, _ref, _o2, _ref2, _o3, _self2, _o4, _self3, _o5, _self$self, _o6, _ref3, _o7, _classStaticPrivateFi, _call, _o8, _getSelf, _o9, _getSelf2, _o10, _self4, _o11, _classStaticPrivateFi2, _call$self, _o12, _getSelf$self, _o13, _getSelf$self2, _fn$Foo, _fn$Foo2, _fn$Foo3, _fnDeep$very$o$Foo, _fnDeep$very$o$Foo2, _fnDeep$very$o$Foo3, _fn, _ref4, _fn2, _ref5, _fn3, _self5, _fn4, _self6, _fn5, _self$self2, _fn6, _ref6, _fn7, _classStaticPrivateFi3, _call2, _fn8, _getSelf3, _fn9, _getSelf4, _fn10, _self7, _fn11, _classStaticPrivateFi4, _call$self2, _fn12, _getSelf$self3, _fn13, _getSelf$self4, _deep$very$o, _deep$very$o2, _deep$very$o3, _ref7, _ref8, _ref9, _ref9$self, _ref10, _ref11, _ref12, _ref12$getSelf, _ref13, _ref14, _ref14$call, _ref15, _ref15$getSelf, _ref16, _ref16$getSelf, _ref16$getSelf$call, _fnDeep$very$o, _fnDeep$very$o2, _fnDeep$very$o3, _ref17, _ref18, _ref19, _ref19$self, _ref20, _ref21, _ref22, _ref22$getSelf, _ref23, _ref24, _ref24$call, _ref25, _ref25$getSelf, _ref26, _ref26$getSelf, _ref26$getSelf$call; + + const o = { + Foo: Foo + }; + const deep = { + very: { + o + } + }; + + function fn() { + return o; + } + + function fnDeep() { + return deep; + } + + (_Foo = Foo) === null || _Foo === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_Foo, Foo, _m).call(_Foo); + (_Foo2 = Foo) === null || _Foo2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_Foo2, Foo, _m).call(_Foo2).toString; + (_Foo3 = Foo) === null || _Foo3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_Foo3, Foo, _m).call(_Foo3).toString(); + (_o$Foo = o === null || o === void 0 ? void 0 : o.Foo) === null || _o$Foo === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o$Foo, Foo, _m).call(_o$Foo); + (_o$Foo2 = o === null || o === void 0 ? void 0 : o.Foo) === null || _o$Foo2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o$Foo2, Foo, _m).call(_o$Foo2).toString; + (_o$Foo3 = o === null || o === void 0 ? void 0 : o.Foo) === null || _o$Foo3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o$Foo3, Foo, _m).call(_o$Foo3).toString(); + (_deep$very$o$Foo = deep === null || deep === void 0 ? void 0 : (_deep$very$o = deep.very.o) === null || _deep$very$o === void 0 ? void 0 : _deep$very$o.Foo) === null || _deep$very$o$Foo === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_deep$very$o$Foo, Foo, _m).call(_deep$very$o$Foo); + (_deep$very$o$Foo2 = deep === null || deep === void 0 ? void 0 : (_deep$very$o2 = deep.very.o) === null || _deep$very$o2 === void 0 ? void 0 : _deep$very$o2.Foo) === null || _deep$very$o$Foo2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_deep$very$o$Foo2, Foo, _m).call(_deep$very$o$Foo2).toString; + (_deep$very$o$Foo3 = deep === null || deep === void 0 ? void 0 : (_deep$very$o3 = deep.very.o) === null || _deep$very$o3 === void 0 ? void 0 : _deep$very$o3.Foo) === null || _deep$very$o$Foo3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_deep$very$o$Foo3, Foo, _m).call(_deep$very$o$Foo3).toString(); + (_ref = (_o = o) === null || _o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o.Foo, Foo, _self)) === null || _ref === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref, Foo, _m).call(_ref); + (_ref2 = (_o2 = o) === null || _o2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o2.Foo, Foo, _self).self) === null || _ref2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref2, Foo, _m).call(_ref2); + (_self2 = (_ref7 = (_o3 = o) === null || _o3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o3.Foo, Foo, _self)) === null || _ref7 === void 0 ? void 0 : _ref7.self) === null || _self2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_self2, Foo, _m).call(_self2); + (_self3 = (_ref8 = (_o4 = o) === null || _o4 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o4.Foo, Foo, _self).self) === null || _ref8 === void 0 ? void 0 : _ref8.self) === null || _self3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_self3, Foo, _m).call(_self3); + (_self$self = (_ref9 = (_o5 = o) === null || _o5 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o5.Foo, Foo, _self)) === null || _ref9 === void 0 ? void 0 : (_ref9$self = _ref9.self) === null || _ref9$self === void 0 ? void 0 : _ref9$self.self) === null || _self$self === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_self$self, Foo, _m).call(_self$self); + (_ref3 = (_o6 = o) === null || _o6 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o6.Foo, Foo, _self).getSelf()) === null || _ref3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref3, Foo, _m).call(_ref3); + (_call = (_ref10 = (_o7 = o) === null || _o7 === void 0 ? void 0 : (_classStaticPrivateFi = _classStaticPrivateFieldSpecGet(_o7.Foo, Foo, _self)).getSelf) === null || _ref10 === void 0 ? void 0 : _ref10.call(_classStaticPrivateFi)) === null || _call === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_call, Foo, _m).call(_call); + (_getSelf = (_ref11 = (_o8 = o) === null || _o8 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o8.Foo, Foo, _self)) === null || _ref11 === void 0 ? void 0 : _ref11.getSelf()) === null || _getSelf === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_getSelf, Foo, _m).call(_getSelf); + (_getSelf2 = (_ref12 = (_o9 = o) === null || _o9 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o9.Foo, Foo, _self)) === null || _ref12 === void 0 ? void 0 : (_ref12$getSelf = _ref12.getSelf) === null || _ref12$getSelf === void 0 ? void 0 : _ref12$getSelf.call(_ref12)) === null || _getSelf2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_getSelf2, Foo, _m).call(_getSelf2); + (_self4 = (_ref13 = (_o10 = o) === null || _o10 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o10.Foo, Foo, _self).getSelf()) === null || _ref13 === void 0 ? void 0 : _ref13.self) === null || _self4 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_self4, Foo, _m).call(_self4); + (_call$self = (_ref14 = (_o11 = o) === null || _o11 === void 0 ? void 0 : (_classStaticPrivateFi2 = _classStaticPrivateFieldSpecGet(_o11.Foo, Foo, _self)).getSelf) === null || _ref14 === void 0 ? void 0 : (_ref14$call = _ref14.call(_classStaticPrivateFi2)) === null || _ref14$call === void 0 ? void 0 : _ref14$call.self) === null || _call$self === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_call$self, Foo, _m).call(_call$self); + (_getSelf$self = (_ref15 = (_o12 = o) === null || _o12 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o12.Foo, Foo, _self)) === null || _ref15 === void 0 ? void 0 : (_ref15$getSelf = _ref15.getSelf()) === null || _ref15$getSelf === void 0 ? void 0 : _ref15$getSelf.self) === null || _getSelf$self === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_getSelf$self, Foo, _m).call(_getSelf$self); + (_getSelf$self2 = (_ref16 = (_o13 = o) === null || _o13 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o13.Foo, Foo, _self)) === null || _ref16 === void 0 ? void 0 : (_ref16$getSelf = _ref16.getSelf) === null || _ref16$getSelf === void 0 ? void 0 : (_ref16$getSelf$call = _ref16$getSelf.call(_ref16)) === null || _ref16$getSelf$call === void 0 ? void 0 : _ref16$getSelf$call.self) === null || _getSelf$self2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_getSelf$self2, Foo, _m).call(_getSelf$self2); + (_fn$Foo = fn === null || fn === void 0 ? void 0 : fn().Foo) === null || _fn$Foo === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn$Foo, Foo, _m).call(_fn$Foo); + (_fn$Foo2 = fn === null || fn === void 0 ? void 0 : fn().Foo) === null || _fn$Foo2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn$Foo2, Foo, _m).call(_fn$Foo2).toString; + (_fn$Foo3 = fn === null || fn === void 0 ? void 0 : fn().Foo) === null || _fn$Foo3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn$Foo3, Foo, _m).call(_fn$Foo3).toString(); + (_fnDeep$very$o$Foo = fnDeep === null || fnDeep === void 0 ? void 0 : (_fnDeep$very$o = fnDeep().very.o) === null || _fnDeep$very$o === void 0 ? void 0 : _fnDeep$very$o.Foo) === null || _fnDeep$very$o$Foo === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fnDeep$very$o$Foo, Foo, _m).call(_fnDeep$very$o$Foo); + (_fnDeep$very$o$Foo2 = fnDeep === null || fnDeep === void 0 ? void 0 : (_fnDeep$very$o2 = fnDeep().very.o) === null || _fnDeep$very$o2 === void 0 ? void 0 : _fnDeep$very$o2.Foo) === null || _fnDeep$very$o$Foo2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fnDeep$very$o$Foo2, Foo, _m).call(_fnDeep$very$o$Foo2).toString; + (_fnDeep$very$o$Foo3 = fnDeep === null || fnDeep === void 0 ? void 0 : (_fnDeep$very$o3 = fnDeep().very.o) === null || _fnDeep$very$o3 === void 0 ? void 0 : _fnDeep$very$o3.Foo) === null || _fnDeep$very$o$Foo3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fnDeep$very$o$Foo3, Foo, _m).call(_fnDeep$very$o$Foo3).toString(); + (_ref4 = (_fn = fn) === null || _fn === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn().Foo, Foo, _self)) === null || _ref4 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref4, Foo, _m).call(_ref4); + (_ref5 = (_fn2 = fn) === null || _fn2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn2().Foo, Foo, _self).self) === null || _ref5 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref5, Foo, _m).call(_ref5); + (_self5 = (_ref17 = (_fn3 = fn) === null || _fn3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn3().Foo, Foo, _self)) === null || _ref17 === void 0 ? void 0 : _ref17.self) === null || _self5 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_self5, Foo, _m).call(_self5); + (_self6 = (_ref18 = (_fn4 = fn) === null || _fn4 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn4().Foo, Foo, _self).self) === null || _ref18 === void 0 ? void 0 : _ref18.self) === null || _self6 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_self6, Foo, _m).call(_self6); + (_self$self2 = (_ref19 = (_fn5 = fn) === null || _fn5 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn5().Foo, Foo, _self)) === null || _ref19 === void 0 ? void 0 : (_ref19$self = _ref19.self) === null || _ref19$self === void 0 ? void 0 : _ref19$self.self) === null || _self$self2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_self$self2, Foo, _m).call(_self$self2); + (_ref6 = (_fn6 = fn) === null || _fn6 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn6().Foo, Foo, _self).getSelf()) === null || _ref6 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref6, Foo, _m).call(_ref6); + (_call2 = (_ref20 = (_fn7 = fn) === null || _fn7 === void 0 ? void 0 : (_classStaticPrivateFi3 = _classStaticPrivateFieldSpecGet(_fn7().Foo, Foo, _self)).getSelf) === null || _ref20 === void 0 ? void 0 : _ref20.call(_classStaticPrivateFi3)) === null || _call2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_call2, Foo, _m).call(_call2); + (_getSelf3 = (_ref21 = (_fn8 = fn) === null || _fn8 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn8().Foo, Foo, _self)) === null || _ref21 === void 0 ? void 0 : _ref21.getSelf()) === null || _getSelf3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_getSelf3, Foo, _m).call(_getSelf3); + (_getSelf4 = (_ref22 = (_fn9 = fn) === null || _fn9 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn9().Foo, Foo, _self)) === null || _ref22 === void 0 ? void 0 : (_ref22$getSelf = _ref22.getSelf) === null || _ref22$getSelf === void 0 ? void 0 : _ref22$getSelf.call(_ref22)) === null || _getSelf4 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_getSelf4, Foo, _m).call(_getSelf4); + (_self7 = (_ref23 = (_fn10 = fn) === null || _fn10 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn10().Foo, Foo, _self).getSelf()) === null || _ref23 === void 0 ? void 0 : _ref23.self) === null || _self7 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_self7, Foo, _m).call(_self7); + (_call$self2 = (_ref24 = (_fn11 = fn) === null || _fn11 === void 0 ? void 0 : (_classStaticPrivateFi4 = _classStaticPrivateFieldSpecGet(_fn11().Foo, Foo, _self)).getSelf) === null || _ref24 === void 0 ? void 0 : (_ref24$call = _ref24.call(_classStaticPrivateFi4)) === null || _ref24$call === void 0 ? void 0 : _ref24$call.self) === null || _call$self2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_call$self2, Foo, _m).call(_call$self2); + (_getSelf$self3 = (_ref25 = (_fn12 = fn) === null || _fn12 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn12().Foo, Foo, _self)) === null || _ref25 === void 0 ? void 0 : (_ref25$getSelf = _ref25.getSelf()) === null || _ref25$getSelf === void 0 ? void 0 : _ref25$getSelf.self) === null || _getSelf$self3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_getSelf$self3, Foo, _m).call(_getSelf$self3); + (_getSelf$self4 = (_ref26 = (_fn13 = fn) === null || _fn13 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn13().Foo, Foo, _self)) === null || _ref26 === void 0 ? void 0 : (_ref26$getSelf = _ref26.getSelf) === null || _ref26$getSelf === void 0 ? void 0 : (_ref26$getSelf$call = _ref26$getSelf.call(_ref26)) === null || _ref26$getSelf$call === void 0 ? void 0 : _ref26$getSelf$call.self) === null || _getSelf$self4 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_getSelf$self4, Foo, _m).call(_getSelf$self4); + } + +} + +var _x = { + writable: true, + value: 1 +}; +var _m = { + writable: true, + value: function () { + return _classStaticPrivateFieldSpecGet(this, Foo, _x); + } +}; +var _self = { + writable: true, + value: Foo +}; + +_defineProperty(Foo, "self", Foo); + +Foo.test(); diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-optional-member-call/exec.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-optional-member-call/exec.js new file mode 100644 index 000000000000..df4319aff69b --- /dev/null +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-optional-member-call/exec.js @@ -0,0 +1,126 @@ +class Foo { + static #x = 1; + static #m = function() { return this.#x; }; + static #self = Foo; + static self = Foo; + static getSelf() { return this } + + static test() { + 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(o?.Foo?.#m()).toEqual(1); + expect(o?.Foo?.#m().toString).toEqual(1..toString); + expect(o?.Foo?.#m().toString()).toEqual('1'); + + expect(deep?.very.o?.Foo?.#m()).toEqual(1); + expect(deep?.very.o?.Foo?.#m().toString).toEqual(1..toString); + expect(deep?.very.o?.Foo?.#m().toString()).toEqual('1'); + + expect(o?.Foo.#self?.#m()).toEqual(1); + expect(o?.Foo.#self.self?.#m()).toEqual(1); + expect(o?.Foo.#self?.self?.#m()).toEqual(1); + expect(o?.Foo.#self.self?.self?.#m()).toEqual(1); + expect(o?.Foo.#self?.self?.self?.#m()).toEqual(1); + + expect(o?.Foo.#self.getSelf()?.#m()).toEqual(1); + expect(o?.Foo.#self.getSelf?.()?.#m()).toEqual(1); + expect(o?.Foo.#self?.getSelf()?.#m()).toEqual(1); + expect(o?.Foo.#self?.getSelf?.()?.#m()).toEqual(1); + expect(o?.Foo.#self.getSelf()?.self?.#m()).toEqual(1); + expect(o?.Foo.#self.getSelf?.()?.self?.#m()).toEqual(1); + expect(o?.Foo.#self?.getSelf()?.self?.#m()).toEqual(1); + expect(o?.Foo.#self?.getSelf?.()?.self?.#m()).toEqual(1); + + expect(fn?.().Foo?.#m()).toEqual(1); + expect(fn?.().Foo?.#m().toString).toEqual(1..toString); + expect(fn?.().Foo?.#m().toString()).toEqual('1'); + + expect(fnDeep?.().very.o?.Foo?.#m()).toEqual(1); + expect(fnDeep?.().very.o?.Foo?.#m().toString).toEqual(1..toString); + expect(fnDeep?.().very.o?.Foo?.#m().toString()).toEqual('1'); + + expect(fn?.().Foo.#self?.#m()).toEqual(1); + expect(fn?.().Foo.#self.self?.#m()).toEqual(1); + expect(fn?.().Foo.#self?.self?.#m()).toEqual(1); + expect(fn?.().Foo.#self.self?.self?.#m()).toEqual(1); + expect(fn?.().Foo.#self?.self?.self?.#m()).toEqual(1); + + expect(fn?.().Foo.#self.getSelf()?.#m()).toEqual(1); + expect(fn?.().Foo.#self.getSelf?.()?.#m()).toEqual(1); + expect(fn?.().Foo.#self?.getSelf()?.#m()).toEqual(1); + expect(fn?.().Foo.#self?.getSelf?.()?.#m()).toEqual(1); + expect(fn?.().Foo.#self.getSelf()?.self?.#m()).toEqual(1); + expect(fn?.().Foo.#self.getSelf?.()?.self?.#m()).toEqual(1); + expect(fn?.().Foo.#self?.getSelf()?.self?.#m()).toEqual(1); + expect(fn?.().Foo.#self?.getSelf?.()?.self?.#m()).toEqual(1); + } + + static testNull() { + const o = null;; + const deep = { very: { o } }; + const fn = null; + function fnDeep() { + return deep; + } + + expect(o?.Foo?.#m()).toEqual(undefined); + expect(o?.Foo?.#m().toString).toEqual(undefined); + expect(o?.Foo?.#m().toString()).toEqual(undefined); + + expect(deep?.very.o?.Foo?.#m()).toEqual(undefined); + expect(deep?.very.o?.Foo?.#m().toString).toEqual(undefined); + expect(deep?.very.o?.Foo?.#m().toString()).toEqual(undefined); + + expect(o?.Foo.#self?.#m()).toEqual(undefined); + expect(o?.Foo.#self.self?.#m()).toEqual(undefined); + expect(o?.Foo.#self?.self?.#m()).toEqual(undefined); + expect(o?.Foo.#self.self?.self?.#m()).toEqual(undefined); + expect(o?.Foo.#self?.self?.self?.#m()).toEqual(undefined); + + expect(o?.Foo.#self.getSelf()?.#m()).toEqual(undefined); + expect(o?.Foo.#self.getSelf?.()?.#m()).toEqual(undefined); + expect(o?.Foo.#self?.getSelf()?.#m()).toEqual(undefined); + expect(o?.Foo.#self?.getSelf?.()?.#m()).toEqual(undefined); + expect(o?.Foo.#self.getSelf()?.self?.#m()).toEqual(undefined); + expect(o?.Foo.#self.getSelf?.()?.self?.#m()).toEqual(undefined); + expect(o?.Foo.#self?.getSelf()?.self?.#m()).toEqual(undefined); + expect(o?.Foo.#self?.getSelf?.()?.self?.#m()).toEqual(undefined); + + expect(fn?.().Foo?.#m()).toEqual(undefined); + expect(fn?.().Foo?.#m().toString).toEqual(undefined); + expect(fn?.().Foo?.#m().toString()).toEqual(undefined); + + expect(fnDeep?.().very.o?.Foo?.#m()).toEqual(undefined); + expect(fnDeep?.().very.o?.Foo?.#m().toString).toEqual(undefined); + expect(fnDeep?.().very.o?.Foo?.#m().toString()).toEqual(undefined); + + expect(fn?.().Foo.#self?.#m()).toEqual(undefined); + expect(fn?.().Foo.#self.self?.#m()).toEqual(undefined); + expect(fn?.().Foo.#self?.self?.#m()).toEqual(undefined); + expect(fn?.().Foo.#self.self?.self?.#m()).toEqual(undefined); + expect(fn?.().Foo.#self?.self?.self?.#m()).toEqual(undefined); + + expect(fn?.().Foo.#self.getSelf()?.#m()).toEqual(undefined); + expect(fn?.().Foo.#self.getSelf?.()?.#m()).toEqual(undefined); + expect(fn?.().Foo.#self?.getSelf()?.#m()).toEqual(undefined); + expect(fn?.().Foo.#self?.getSelf?.()?.#m()).toEqual(undefined); + expect(fn?.().Foo.#self.getSelf()?.self?.#m()).toEqual(undefined); + expect(fn?.().Foo.#self.getSelf?.()?.self?.#m()).toEqual(undefined); + expect(fn?.().Foo.#self?.getSelf()?.self?.#m()).toEqual(undefined); + expect(fn?.().Foo.#self?.getSelf?.()?.self?.#m()).toEqual(undefined); + } +} + +Foo.test(); +Foo.testNull(); diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-optional-member-call/input.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-optional-member-call/input.js new file mode 100644 index 000000000000..a5c222687ee8 --- /dev/null +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-optional-member-call/input.js @@ -0,0 +1,70 @@ +class Foo { + static #x = 1; + static #m = function() { return this.#x; }; + static #self = Foo; + static self = Foo; + static getSelf() { return this } + + static test() { + const o = { Foo: Foo }; + const deep = { very: { o } }; + function fn() { + return o; + } + function fnDeep() { + return deep; + } + + Foo?.#m(); + Foo?.#m().toString; + Foo?.#m().toString(); + + o?.Foo.#m(); + o?.Foo.#m().toString; + o?.Foo.#m().toString(); + + deep?.very.o?.Foo.#m(); + deep?.very.o?.Foo.#m().toString; + deep?.very.o?.Foo.#m().toString(); + + o?.Foo.#self.#m(); + o?.Foo.#self.self.#m(); + o?.Foo.#self?.self.#m(); + o?.Foo.#self.self?.self.#m(); + o?.Foo.#self?.self?.self.#m(); + + o?.Foo.#self.getSelf().#m(); + o?.Foo.#self.getSelf?.().#m(); + o?.Foo.#self?.getSelf().#m(); + o?.Foo.#self?.getSelf?.().#m(); + o?.Foo.#self.getSelf()?.self.#m(); + o?.Foo.#self.getSelf?.()?.self.#m(); + o?.Foo.#self?.getSelf()?.self.#m(); + o?.Foo.#self?.getSelf?.()?.self.#m(); + + fn?.().Foo.#m(); + fn?.().Foo.#m().toString; + fn?.().Foo.#m().toString(); + + fnDeep?.().very.o?.Foo.#m(); + fnDeep?.().very.o?.Foo.#m().toString; + fnDeep?.().very.o?.Foo.#m().toString(); + + fn?.().Foo.#self.#m(); + fn?.().Foo.#self.self.#m(); + fn?.().Foo.#self?.self.#m(); + fn?.().Foo.#self.self?.self.#m(); + fn?.().Foo.#self?.self?.self.#m(); + + fn?.().Foo.#self.getSelf().#m(); + fn?.().Foo.#self.getSelf?.().#m(); + fn?.().Foo.#self?.getSelf().#m(); + fn?.().Foo.#self?.getSelf?.().#m(); + fn?.().Foo.#self.getSelf()?.self.#m(); + fn?.().Foo.#self.getSelf?.()?.self.#m(); + fn?.().Foo.#self?.getSelf()?.self.#m(); + fn?.().Foo.#self?.getSelf?.()?.self.#m(); + } +} + +Foo.test(); diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-optional-member-call/options.json b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-optional-member-call/options.json new file mode 100644 index 000000000000..19ed5174f545 --- /dev/null +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-optional-member-call/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["proposal-class-properties"] +} diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-optional-member-call/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-optional-member-call/output.js new file mode 100644 index 000000000000..bce199186f44 --- /dev/null +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-optional-member-call/output.js @@ -0,0 +1,92 @@ +function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } + +function _classStaticPrivateFieldSpecGet(receiver, classConstructor, descriptor) { if (receiver !== classConstructor) { throw new TypeError("Private static access of wrong provenance"); } if (descriptor.get) { return descriptor.get.call(receiver); } return descriptor.value; } + +class Foo { + static getSelf() { + return this; + } + + static test() { + var _Foo, _Foo2, _Foo3, _o, _o$Foo, _o2, _o2$Foo, _o3, _o3$Foo, _deep$very$o, _deep$very$o$Foo, _deep$very$o2, _deep$very$o2$Foo, _deep$very$o3, _deep$very$o3$Foo, _o4, _classStaticPrivateFi, _o5, _classStaticPrivateFi2, _o6, _ref, _ref$self, _o7, _ref2, _ref2$self, _o8, _self2, _self2$self, _o9, _classStaticPrivateFi3, _o10, _classStaticPrivateFi4, _ref3, _ref3$call, _o11, _ref4, _ref4$getSelf, _o12, _getSelf, _ref5, _getSelf$call, _o13, _ref6, _ref6$self, _o14, _classStaticPrivateFi5, _call, _call$self, _o15, _getSelf2, _getSelf2$self, _o16, _getSelf3, _getSelf3$self, _fn, _fn$Foo, _fn2, _fn2$Foo, _fn3, _fn3$Foo, _fnDeep$very$o, _fnDeep$very$o$Foo, _fnDeep$very$o2, _fnDeep$very$o2$Foo, _fnDeep$very$o3, _fnDeep$very$o3$Foo, _fn4, _classStaticPrivateFi6, _fn5, _classStaticPrivateFi7, _fn6, _ref7, _ref7$self, _fn7, _ref8, _ref8$self, _fn8, _self3, _self3$self, _fn9, _classStaticPrivateFi8, _fn10, _classStaticPrivateFi9, _ref9, _ref9$call, _fn11, _ref10, _ref10$getSelf, _fn12, _getSelf4, _ref11, _getSelf4$call, _fn13, _ref12, _ref12$self, _fn14, _classStaticPrivateFi10, _call2, _call2$self, _fn15, _getSelf5, _getSelf5$self, _fn16, _getSelf6, _getSelf6$self; + + const o = { + Foo: Foo + }; + const deep = { + very: { + o + } + }; + + function fn() { + return o; + } + + function fnDeep() { + return deep; + } + + (_Foo = Foo) === null || _Foo === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_Foo, Foo, _m).call(_Foo); + (_Foo2 = Foo) === null || _Foo2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_Foo2, Foo, _m).call(_Foo2).toString; + (_Foo3 = Foo) === null || _Foo3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_Foo3, Foo, _m).call(_Foo3).toString(); + (_o = o) === null || _o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o$Foo = _o.Foo, Foo, _m).call(_o$Foo); + (_o2 = o) === null || _o2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o2$Foo = _o2.Foo, Foo, _m).call(_o2$Foo).toString; + (_o3 = o) === null || _o3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o3$Foo = _o3.Foo, Foo, _m).call(_o3$Foo).toString(); + (_deep$very$o = deep?.very.o) === null || _deep$very$o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_deep$very$o$Foo = _deep$very$o.Foo, Foo, _m).call(_deep$very$o$Foo); + (_deep$very$o2 = deep?.very.o) === null || _deep$very$o2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_deep$very$o2$Foo = _deep$very$o2.Foo, Foo, _m).call(_deep$very$o2$Foo).toString; + (_deep$very$o3 = deep?.very.o) === null || _deep$very$o3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_deep$very$o3$Foo = _deep$very$o3.Foo, Foo, _m).call(_deep$very$o3$Foo).toString(); + (_o4 = o) === null || _o4 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFi = _classStaticPrivateFieldSpecGet(_o4.Foo, Foo, _self), Foo, _m).call(_classStaticPrivateFi); + (_o5 = o) === null || _o5 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFi2 = _classStaticPrivateFieldSpecGet(_o5.Foo, Foo, _self).self, Foo, _m).call(_classStaticPrivateFi2); + (_ref = (_o6 = o) === null || _o6 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o6.Foo, Foo, _self)) === null || _ref === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref$self = _ref.self, Foo, _m).call(_ref$self); + (_ref2 = (_o7 = o) === null || _o7 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o7.Foo, Foo, _self).self) === null || _ref2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref2$self = _ref2.self, Foo, _m).call(_ref2$self); + (_self2 = ((_o8 = o) === null || _o8 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o8.Foo, Foo, _self))?.self) === null || _self2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_self2$self = _self2.self, Foo, _m).call(_self2$self); + (_o9 = o) === null || _o9 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFi3 = _classStaticPrivateFieldSpecGet(_o9.Foo, Foo, _self).getSelf(), Foo, _m).call(_classStaticPrivateFi3); + (_ref3 = (_o10 = o) === null || _o10 === void 0 ? void 0 : (_classStaticPrivateFi4 = _classStaticPrivateFieldSpecGet(_o10.Foo, Foo, _self)).getSelf) === null || _ref3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref3$call = _ref3.call(_classStaticPrivateFi4), Foo, _m).call(_ref3$call); + (_ref4 = (_o11 = o) === null || _o11 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o11.Foo, Foo, _self)) === null || _ref4 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref4$getSelf = _ref4.getSelf(), Foo, _m).call(_ref4$getSelf); + (_getSelf = (_ref5 = (_o12 = o) === null || _o12 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o12.Foo, Foo, _self))?.getSelf) === null || _getSelf === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_getSelf$call = _getSelf.call(_ref5), Foo, _m).call(_getSelf$call); + (_ref6 = (_o13 = o) === null || _o13 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o13.Foo, Foo, _self).getSelf()) === null || _ref6 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref6$self = _ref6.self, Foo, _m).call(_ref6$self); + (_call = ((_o14 = o) === null || _o14 === void 0 ? void 0 : (_classStaticPrivateFi5 = _classStaticPrivateFieldSpecGet(_o14.Foo, Foo, _self)).getSelf)?.call(_classStaticPrivateFi5)) === null || _call === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_call$self = _call.self, Foo, _m).call(_call$self); + (_getSelf2 = ((_o15 = o) === null || _o15 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o15.Foo, Foo, _self))?.getSelf()) === null || _getSelf2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_getSelf2$self = _getSelf2.self, Foo, _m).call(_getSelf2$self); + (_getSelf3 = ((_o16 = o) === null || _o16 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o16.Foo, Foo, _self))?.getSelf?.()) === null || _getSelf3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_getSelf3$self = _getSelf3.self, Foo, _m).call(_getSelf3$self); + (_fn = fn) === null || _fn === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn$Foo = _fn().Foo, Foo, _m).call(_fn$Foo); + (_fn2 = fn) === null || _fn2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn2$Foo = _fn2().Foo, Foo, _m).call(_fn2$Foo).toString; + (_fn3 = fn) === null || _fn3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn3$Foo = _fn3().Foo, Foo, _m).call(_fn3$Foo).toString(); + (_fnDeep$very$o = fnDeep?.().very.o) === null || _fnDeep$very$o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fnDeep$very$o$Foo = _fnDeep$very$o.Foo, Foo, _m).call(_fnDeep$very$o$Foo); + (_fnDeep$very$o2 = fnDeep?.().very.o) === null || _fnDeep$very$o2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fnDeep$very$o2$Foo = _fnDeep$very$o2.Foo, Foo, _m).call(_fnDeep$very$o2$Foo).toString; + (_fnDeep$very$o3 = fnDeep?.().very.o) === null || _fnDeep$very$o3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fnDeep$very$o3$Foo = _fnDeep$very$o3.Foo, Foo, _m).call(_fnDeep$very$o3$Foo).toString(); + (_fn4 = fn) === null || _fn4 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFi6 = _classStaticPrivateFieldSpecGet(_fn4().Foo, Foo, _self), Foo, _m).call(_classStaticPrivateFi6); + (_fn5 = fn) === null || _fn5 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFi7 = _classStaticPrivateFieldSpecGet(_fn5().Foo, Foo, _self).self, Foo, _m).call(_classStaticPrivateFi7); + (_ref7 = (_fn6 = fn) === null || _fn6 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn6().Foo, Foo, _self)) === null || _ref7 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref7$self = _ref7.self, Foo, _m).call(_ref7$self); + (_ref8 = (_fn7 = fn) === null || _fn7 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn7().Foo, Foo, _self).self) === null || _ref8 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref8$self = _ref8.self, Foo, _m).call(_ref8$self); + (_self3 = ((_fn8 = fn) === null || _fn8 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn8().Foo, Foo, _self))?.self) === null || _self3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_self3$self = _self3.self, Foo, _m).call(_self3$self); + (_fn9 = fn) === null || _fn9 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFi8 = _classStaticPrivateFieldSpecGet(_fn9().Foo, Foo, _self).getSelf(), Foo, _m).call(_classStaticPrivateFi8); + (_ref9 = (_fn10 = fn) === null || _fn10 === void 0 ? void 0 : (_classStaticPrivateFi9 = _classStaticPrivateFieldSpecGet(_fn10().Foo, Foo, _self)).getSelf) === null || _ref9 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref9$call = _ref9.call(_classStaticPrivateFi9), Foo, _m).call(_ref9$call); + (_ref10 = (_fn11 = fn) === null || _fn11 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn11().Foo, Foo, _self)) === null || _ref10 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref10$getSelf = _ref10.getSelf(), Foo, _m).call(_ref10$getSelf); + (_getSelf4 = (_ref11 = (_fn12 = fn) === null || _fn12 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn12().Foo, Foo, _self))?.getSelf) === null || _getSelf4 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_getSelf4$call = _getSelf4.call(_ref11), Foo, _m).call(_getSelf4$call); + (_ref12 = (_fn13 = fn) === null || _fn13 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn13().Foo, Foo, _self).getSelf()) === null || _ref12 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref12$self = _ref12.self, Foo, _m).call(_ref12$self); + (_call2 = ((_fn14 = fn) === null || _fn14 === void 0 ? void 0 : (_classStaticPrivateFi10 = _classStaticPrivateFieldSpecGet(_fn14().Foo, Foo, _self)).getSelf)?.call(_classStaticPrivateFi10)) === null || _call2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_call2$self = _call2.self, Foo, _m).call(_call2$self); + (_getSelf5 = ((_fn15 = fn) === null || _fn15 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn15().Foo, Foo, _self))?.getSelf()) === null || _getSelf5 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_getSelf5$self = _getSelf5.self, Foo, _m).call(_getSelf5$self); + (_getSelf6 = ((_fn16 = fn) === null || _fn16 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn16().Foo, Foo, _self))?.getSelf?.()) === null || _getSelf6 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_getSelf6$self = _getSelf6.self, Foo, _m).call(_getSelf6$self); + } + +} + +var _x = { + writable: true, + value: 1 +}; +var _m = { + writable: true, + value: function () { + return _classStaticPrivateFieldSpecGet(this, Foo, _x); + } +}; +var _self = { + writable: true, + value: Foo +}; + +_defineProperty(Foo, "self", Foo); + +Foo.test(); diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-optional-property-with-transform/exec.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-optional-property-with-transform/exec.js new file mode 100644 index 000000000000..0d627ac9e0d4 --- /dev/null +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-optional-property-with-transform/exec.js @@ -0,0 +1,125 @@ +class Foo { + static #x = 1; + static #self = Foo; + static self = Foo; + static getSelf() { return this } + + static test() { + const o = { Foo: Foo }; + const deep = { very: { o } }; + function fn() { + return o; + } + function fnDeep() { + return deep; + } + + expect(Foo?.#x).toEqual(1); + expect(Foo?.#x.toString).toEqual(1..toString); + expect(Foo?.#x.toString()).toEqual('1'); + + expect(o?.Foo?.#x).toEqual(1); + expect(o?.Foo?.#x.toString).toEqual(1..toString); + expect(o?.Foo?.#x.toString()).toEqual('1'); + + expect(deep?.very.o?.Foo?.#x).toEqual(1); + expect(deep?.very.o?.Foo?.#x.toString).toEqual(1..toString); + expect(deep?.very.o?.Foo?.#x.toString()).toEqual('1'); + + expect(o?.Foo.#self?.#x).toEqual(1); + expect(o?.Foo.#self.self?.#x).toEqual(1); + expect(o?.Foo.#self?.self?.#x).toEqual(1); + expect(o?.Foo.#self.self?.self?.#x).toEqual(1); + expect(o?.Foo.#self?.self?.self?.#x).toEqual(1); + + expect(o?.Foo.#self.getSelf()?.#x).toEqual(1); + expect(o?.Foo.#self.getSelf?.()?.#x).toEqual(1); + expect(o?.Foo.#self?.getSelf()?.#x).toEqual(1); + expect(o?.Foo.#self?.getSelf?.()?.#x).toEqual(1); + expect(o?.Foo.#self.getSelf()?.self?.#x).toEqual(1); + expect(o?.Foo.#self.getSelf?.()?.self?.#x).toEqual(1); + expect(o?.Foo.#self?.getSelf()?.self?.#x).toEqual(1); + expect(o?.Foo.#self?.getSelf?.()?.self?.#x).toEqual(1); + + expect(fn?.().Foo?.#x).toEqual(1); + expect(fn?.().Foo?.#x.toString).toEqual(1..toString); + expect(fn?.().Foo?.#x.toString()).toEqual('1'); + + expect(fnDeep?.().very.o?.Foo?.#x).toEqual(1); + expect(fnDeep?.().very.o?.Foo?.#x.toString).toEqual(1..toString); + expect(fnDeep?.().very.o?.Foo?.#x.toString()).toEqual('1'); + + expect(fn?.().Foo.#self?.#x).toEqual(1); + expect(fn?.().Foo.#self.self?.#x).toEqual(1); + expect(fn?.().Foo.#self?.self?.#x).toEqual(1); + expect(fn?.().Foo.#self.self?.self?.#x).toEqual(1); + expect(fn?.().Foo.#self?.self?.self?.#x).toEqual(1); + + expect(fn?.().Foo.#self.getSelf()?.#x).toEqual(1); + expect(fn?.().Foo.#self.getSelf?.()?.#x).toEqual(1); + expect(fn?.().Foo.#self?.getSelf()?.#x).toEqual(1); + expect(fn?.().Foo.#self?.getSelf?.()?.#x).toEqual(1); + expect(fn?.().Foo.#self.getSelf()?.self?.#x).toEqual(1); + expect(fn?.().Foo.#self.getSelf?.()?.self?.#x).toEqual(1); + expect(fn?.().Foo.#self?.getSelf()?.self?.#x).toEqual(1); + expect(fn?.().Foo.#self?.getSelf?.()?.self?.#x).toEqual(1); + } + + static testNull() { + const o = null;; + const deep = { very: { o } }; + const fn = null; + function fnDeep() { + return deep; + } + + expect(o?.Foo?.#x).toEqual(undefined); + expect(o?.Foo?.#x.toString).toEqual(undefined); + expect(o?.Foo?.#x.toString()).toEqual(undefined); + + expect(deep?.very.o?.Foo?.#x).toEqual(undefined); + expect(deep?.very.o?.Foo?.#x.toString).toEqual(undefined); + expect(deep?.very.o?.Foo?.#x.toString()).toEqual(undefined); + + expect(o?.Foo.#self?.#x).toEqual(undefined); + expect(o?.Foo.#self.self?.#x).toEqual(undefined); + expect(o?.Foo.#self?.self?.#x).toEqual(undefined); + expect(o?.Foo.#self.self?.self?.#x).toEqual(undefined); + expect(o?.Foo.#self?.self?.self?.#x).toEqual(undefined); + + expect(o?.Foo.#self.getSelf()?.#x).toEqual(undefined); + expect(o?.Foo.#self.getSelf?.()?.#x).toEqual(undefined); + expect(o?.Foo.#self?.getSelf()?.#x).toEqual(undefined); + expect(o?.Foo.#self?.getSelf?.()?.#x).toEqual(undefined); + expect(o?.Foo.#self.getSelf()?.self?.#x).toEqual(undefined); + expect(o?.Foo.#self.getSelf?.()?.self?.#x).toEqual(undefined); + expect(o?.Foo.#self?.getSelf()?.self?.#x).toEqual(undefined); + expect(o?.Foo.#self?.getSelf?.()?.self?.#x).toEqual(undefined); + + expect(fn?.().Foo?.#x).toEqual(undefined); + expect(fn?.().Foo?.#x.toString).toEqual(undefined); + expect(fn?.().Foo?.#x.toString()).toEqual(undefined); + + expect(fnDeep?.().very.o?.Foo?.#x).toEqual(undefined); + expect(fnDeep?.().very.o?.Foo?.#x.toString).toEqual(undefined); + expect(fnDeep?.().very.o?.Foo?.#x.toString()).toEqual(undefined); + + expect(fn?.().Foo.#self?.#x).toEqual(undefined); + expect(fn?.().Foo.#self.self?.#x).toEqual(undefined); + expect(fn?.().Foo.#self?.self?.#x).toEqual(undefined); + expect(fn?.().Foo.#self.self?.self?.#x).toEqual(undefined); + expect(fn?.().Foo.#self?.self?.self?.#x).toEqual(undefined); + + expect(fn?.().Foo.#self.getSelf()?.#x).toEqual(undefined); + expect(fn?.().Foo.#self.getSelf?.()?.#x).toEqual(undefined); + expect(fn?.().Foo.#self?.getSelf()?.#x).toEqual(undefined); + expect(fn?.().Foo.#self?.getSelf?.()?.#x).toEqual(undefined); + expect(fn?.().Foo.#self.getSelf()?.self?.#x).toEqual(undefined); + expect(fn?.().Foo.#self.getSelf?.()?.self?.#x).toEqual(undefined); + expect(fn?.().Foo.#self?.getSelf()?.self?.#x).toEqual(undefined); + expect(fn?.().Foo.#self?.getSelf?.()?.self?.#x).toEqual(undefined); + } +} + +Foo.test(); +Foo.testNull(); diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-optional-property-with-transform/input.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-optional-property-with-transform/input.js new file mode 100644 index 000000000000..968eeaf3cb44 --- /dev/null +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-optional-property-with-transform/input.js @@ -0,0 +1,69 @@ +class Foo { + static #x = 1; + static #self = Foo; + static self = Foo; + static getSelf() { return this } + + static test() { + const o = { Foo: Foo }; + const deep = { very: { o } }; + function fn() { + return o; + } + function fnDeep() { + return deep; + } + + Foo?.#x; + Foo?.#x.toString; + Foo?.#x.toString(); + + o?.Foo?.#x; + o?.Foo?.#x.toString; + o?.Foo?.#x.toString(); + + deep?.very.o?.Foo?.#x; + deep?.very.o?.Foo?.#x.toString; + deep?.very.o?.Foo?.#x.toString(); + + o?.Foo.#self?.#x; + o?.Foo.#self.self?.#x; + o?.Foo.#self?.self?.#x; + o?.Foo.#self.self?.self?.#x; + o?.Foo.#self?.self?.self?.#x; + + o?.Foo.#self.getSelf()?.#x; + o?.Foo.#self.getSelf?.()?.#x; + o?.Foo.#self?.getSelf()?.#x; + o?.Foo.#self?.getSelf?.()?.#x; + o?.Foo.#self.getSelf()?.self?.#x; + o?.Foo.#self.getSelf?.()?.self?.#x; + o?.Foo.#self?.getSelf()?.self?.#x; + o?.Foo.#self?.getSelf?.()?.self?.#x; + + fn?.().Foo?.#x; + fn?.().Foo?.#x.toString; + fn?.().Foo?.#x.toString(); + + fnDeep?.().very.o?.Foo?.#x; + fnDeep?.().very.o?.Foo?.#x.toString; + fnDeep?.().very.o?.Foo?.#x.toString(); + + fn?.().Foo.#self?.#x; + fn?.().Foo.#self.self?.#x; + fn?.().Foo.#self?.self?.#x; + fn?.().Foo.#self.self?.self?.#x; + fn?.().Foo.#self?.self?.self?.#x; + + fn?.().Foo.#self.getSelf()?.#x; + fn?.().Foo.#self.getSelf?.()?.#x; + fn?.().Foo.#self?.getSelf()?.#x; + fn?.().Foo.#self?.getSelf?.()?.#x; + fn?.().Foo.#self.getSelf()?.self?.#x; + fn?.().Foo.#self.getSelf?.()?.self?.#x; + fn?.().Foo.#self?.getSelf()?.self?.#x; + fn?.().Foo.#self?.getSelf?.()?.self?.#x; + } +} + +Foo.test(); diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-optional-property-with-transform/options.json b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-optional-property-with-transform/options.json new file mode 100644 index 000000000000..63b4c77cc8e8 --- /dev/null +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-optional-property-with-transform/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["proposal-optional-chaining", "proposal-class-properties"] +} diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-optional-property-with-transform/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-optional-property-with-transform/output.js new file mode 100644 index 000000000000..71d124ad5550 --- /dev/null +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-optional-property-with-transform/output.js @@ -0,0 +1,86 @@ +function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } + +function _classStaticPrivateFieldSpecGet(receiver, classConstructor, descriptor) { if (receiver !== classConstructor) { throw new TypeError("Private static access of wrong provenance"); } if (descriptor.get) { return descriptor.get.call(receiver); } return descriptor.value; } + +class Foo { + static getSelf() { + return this; + } + + static test() { + var _Foo, _Foo2, _Foo3, _o$Foo, _o$Foo2, _o$Foo3, _deep$very$o$Foo, _deep$very$o$Foo2, _deep$very$o$Foo3, _o, _ref, _o2, _ref2, _o3, _self2, _o4, _self3, _o5, _self$self, _o6, _ref3, _o7, _classStaticPrivateFi, _call, _o8, _getSelf, _o9, _getSelf2, _o10, _self4, _o11, _classStaticPrivateFi2, _call$self, _o12, _getSelf$self, _o13, _getSelf$self2, _fn$Foo, _fn$Foo2, _fn$Foo3, _fnDeep$very$o$Foo, _fnDeep$very$o$Foo2, _fnDeep$very$o$Foo3, _fn, _ref4, _fn2, _ref5, _fn3, _self5, _fn4, _self6, _fn5, _self$self2, _fn6, _ref6, _fn7, _classStaticPrivateFi3, _call2, _fn8, _getSelf3, _fn9, _getSelf4, _fn10, _self7, _fn11, _classStaticPrivateFi4, _call$self2, _fn12, _getSelf$self3, _fn13, _getSelf$self4, _deep$very$o, _deep$very$o2, _deep$very$o3, _ref7, _ref8, _ref9, _ref9$self, _ref10, _ref11, _ref12, _ref12$getSelf, _ref13, _ref14, _ref14$call, _ref15, _ref15$getSelf, _ref16, _ref16$getSelf, _ref16$getSelf$call, _fnDeep$very$o, _fnDeep$very$o2, _fnDeep$very$o3, _ref17, _ref18, _ref19, _ref19$self, _ref20, _ref21, _ref22, _ref22$getSelf, _ref23, _ref24, _ref24$call, _ref25, _ref25$getSelf, _ref26, _ref26$getSelf, _ref26$getSelf$call; + + const o = { + Foo: Foo + }; + const deep = { + very: { + o + } + }; + + function fn() { + return o; + } + + function fnDeep() { + return deep; + } + + (_Foo = Foo) === null || _Foo === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_Foo, Foo, _x); + (_Foo2 = Foo) === null || _Foo2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_Foo2, Foo, _x).toString; + (_Foo3 = Foo) === null || _Foo3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_Foo3, Foo, _x).toString(); + (_o$Foo = o === null || o === void 0 ? void 0 : o.Foo) === null || _o$Foo === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o$Foo, Foo, _x); + (_o$Foo2 = o === null || o === void 0 ? void 0 : o.Foo) === null || _o$Foo2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o$Foo2, Foo, _x).toString; + (_o$Foo3 = o === null || o === void 0 ? void 0 : o.Foo) === null || _o$Foo3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o$Foo3, Foo, _x).toString(); + (_deep$very$o$Foo = deep === null || deep === void 0 ? void 0 : (_deep$very$o = deep.very.o) === null || _deep$very$o === void 0 ? void 0 : _deep$very$o.Foo) === null || _deep$very$o$Foo === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_deep$very$o$Foo, Foo, _x); + (_deep$very$o$Foo2 = deep === null || deep === void 0 ? void 0 : (_deep$very$o2 = deep.very.o) === null || _deep$very$o2 === void 0 ? void 0 : _deep$very$o2.Foo) === null || _deep$very$o$Foo2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_deep$very$o$Foo2, Foo, _x).toString; + (_deep$very$o$Foo3 = deep === null || deep === void 0 ? void 0 : (_deep$very$o3 = deep.very.o) === null || _deep$very$o3 === void 0 ? void 0 : _deep$very$o3.Foo) === null || _deep$very$o$Foo3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_deep$very$o$Foo3, Foo, _x).toString(); + (_ref = (_o = o) === null || _o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o.Foo, Foo, _self)) === null || _ref === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref, Foo, _x); + (_ref2 = (_o2 = o) === null || _o2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o2.Foo, Foo, _self).self) === null || _ref2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref2, Foo, _x); + (_self2 = (_ref7 = (_o3 = o) === null || _o3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o3.Foo, Foo, _self)) === null || _ref7 === void 0 ? void 0 : _ref7.self) === null || _self2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_self2, Foo, _x); + (_self3 = (_ref8 = (_o4 = o) === null || _o4 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o4.Foo, Foo, _self).self) === null || _ref8 === void 0 ? void 0 : _ref8.self) === null || _self3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_self3, Foo, _x); + (_self$self = (_ref9 = (_o5 = o) === null || _o5 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o5.Foo, Foo, _self)) === null || _ref9 === void 0 ? void 0 : (_ref9$self = _ref9.self) === null || _ref9$self === void 0 ? void 0 : _ref9$self.self) === null || _self$self === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_self$self, Foo, _x); + (_ref3 = (_o6 = o) === null || _o6 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o6.Foo, Foo, _self).getSelf()) === null || _ref3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref3, Foo, _x); + (_call = (_ref10 = (_o7 = o) === null || _o7 === void 0 ? void 0 : (_classStaticPrivateFi = _classStaticPrivateFieldSpecGet(_o7.Foo, Foo, _self)).getSelf) === null || _ref10 === void 0 ? void 0 : _ref10.call(_classStaticPrivateFi)) === null || _call === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_call, Foo, _x); + (_getSelf = (_ref11 = (_o8 = o) === null || _o8 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o8.Foo, Foo, _self)) === null || _ref11 === void 0 ? void 0 : _ref11.getSelf()) === null || _getSelf === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_getSelf, Foo, _x); + (_getSelf2 = (_ref12 = (_o9 = o) === null || _o9 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o9.Foo, Foo, _self)) === null || _ref12 === void 0 ? void 0 : (_ref12$getSelf = _ref12.getSelf) === null || _ref12$getSelf === void 0 ? void 0 : _ref12$getSelf.call(_ref12)) === null || _getSelf2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_getSelf2, Foo, _x); + (_self4 = (_ref13 = (_o10 = o) === null || _o10 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o10.Foo, Foo, _self).getSelf()) === null || _ref13 === void 0 ? void 0 : _ref13.self) === null || _self4 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_self4, Foo, _x); + (_call$self = (_ref14 = (_o11 = o) === null || _o11 === void 0 ? void 0 : (_classStaticPrivateFi2 = _classStaticPrivateFieldSpecGet(_o11.Foo, Foo, _self)).getSelf) === null || _ref14 === void 0 ? void 0 : (_ref14$call = _ref14.call(_classStaticPrivateFi2)) === null || _ref14$call === void 0 ? void 0 : _ref14$call.self) === null || _call$self === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_call$self, Foo, _x); + (_getSelf$self = (_ref15 = (_o12 = o) === null || _o12 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o12.Foo, Foo, _self)) === null || _ref15 === void 0 ? void 0 : (_ref15$getSelf = _ref15.getSelf()) === null || _ref15$getSelf === void 0 ? void 0 : _ref15$getSelf.self) === null || _getSelf$self === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_getSelf$self, Foo, _x); + (_getSelf$self2 = (_ref16 = (_o13 = o) === null || _o13 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o13.Foo, Foo, _self)) === null || _ref16 === void 0 ? void 0 : (_ref16$getSelf = _ref16.getSelf) === null || _ref16$getSelf === void 0 ? void 0 : (_ref16$getSelf$call = _ref16$getSelf.call(_ref16)) === null || _ref16$getSelf$call === void 0 ? void 0 : _ref16$getSelf$call.self) === null || _getSelf$self2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_getSelf$self2, Foo, _x); + (_fn$Foo = fn === null || fn === void 0 ? void 0 : fn().Foo) === null || _fn$Foo === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn$Foo, Foo, _x); + (_fn$Foo2 = fn === null || fn === void 0 ? void 0 : fn().Foo) === null || _fn$Foo2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn$Foo2, Foo, _x).toString; + (_fn$Foo3 = fn === null || fn === void 0 ? void 0 : fn().Foo) === null || _fn$Foo3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn$Foo3, Foo, _x).toString(); + (_fnDeep$very$o$Foo = fnDeep === null || fnDeep === void 0 ? void 0 : (_fnDeep$very$o = fnDeep().very.o) === null || _fnDeep$very$o === void 0 ? void 0 : _fnDeep$very$o.Foo) === null || _fnDeep$very$o$Foo === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fnDeep$very$o$Foo, Foo, _x); + (_fnDeep$very$o$Foo2 = fnDeep === null || fnDeep === void 0 ? void 0 : (_fnDeep$very$o2 = fnDeep().very.o) === null || _fnDeep$very$o2 === void 0 ? void 0 : _fnDeep$very$o2.Foo) === null || _fnDeep$very$o$Foo2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fnDeep$very$o$Foo2, Foo, _x).toString; + (_fnDeep$very$o$Foo3 = fnDeep === null || fnDeep === void 0 ? void 0 : (_fnDeep$very$o3 = fnDeep().very.o) === null || _fnDeep$very$o3 === void 0 ? void 0 : _fnDeep$very$o3.Foo) === null || _fnDeep$very$o$Foo3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fnDeep$very$o$Foo3, Foo, _x).toString(); + (_ref4 = (_fn = fn) === null || _fn === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn().Foo, Foo, _self)) === null || _ref4 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref4, Foo, _x); + (_ref5 = (_fn2 = fn) === null || _fn2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn2().Foo, Foo, _self).self) === null || _ref5 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref5, Foo, _x); + (_self5 = (_ref17 = (_fn3 = fn) === null || _fn3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn3().Foo, Foo, _self)) === null || _ref17 === void 0 ? void 0 : _ref17.self) === null || _self5 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_self5, Foo, _x); + (_self6 = (_ref18 = (_fn4 = fn) === null || _fn4 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn4().Foo, Foo, _self).self) === null || _ref18 === void 0 ? void 0 : _ref18.self) === null || _self6 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_self6, Foo, _x); + (_self$self2 = (_ref19 = (_fn5 = fn) === null || _fn5 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn5().Foo, Foo, _self)) === null || _ref19 === void 0 ? void 0 : (_ref19$self = _ref19.self) === null || _ref19$self === void 0 ? void 0 : _ref19$self.self) === null || _self$self2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_self$self2, Foo, _x); + (_ref6 = (_fn6 = fn) === null || _fn6 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn6().Foo, Foo, _self).getSelf()) === null || _ref6 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref6, Foo, _x); + (_call2 = (_ref20 = (_fn7 = fn) === null || _fn7 === void 0 ? void 0 : (_classStaticPrivateFi3 = _classStaticPrivateFieldSpecGet(_fn7().Foo, Foo, _self)).getSelf) === null || _ref20 === void 0 ? void 0 : _ref20.call(_classStaticPrivateFi3)) === null || _call2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_call2, Foo, _x); + (_getSelf3 = (_ref21 = (_fn8 = fn) === null || _fn8 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn8().Foo, Foo, _self)) === null || _ref21 === void 0 ? void 0 : _ref21.getSelf()) === null || _getSelf3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_getSelf3, Foo, _x); + (_getSelf4 = (_ref22 = (_fn9 = fn) === null || _fn9 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn9().Foo, Foo, _self)) === null || _ref22 === void 0 ? void 0 : (_ref22$getSelf = _ref22.getSelf) === null || _ref22$getSelf === void 0 ? void 0 : _ref22$getSelf.call(_ref22)) === null || _getSelf4 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_getSelf4, Foo, _x); + (_self7 = (_ref23 = (_fn10 = fn) === null || _fn10 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn10().Foo, Foo, _self).getSelf()) === null || _ref23 === void 0 ? void 0 : _ref23.self) === null || _self7 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_self7, Foo, _x); + (_call$self2 = (_ref24 = (_fn11 = fn) === null || _fn11 === void 0 ? void 0 : (_classStaticPrivateFi4 = _classStaticPrivateFieldSpecGet(_fn11().Foo, Foo, _self)).getSelf) === null || _ref24 === void 0 ? void 0 : (_ref24$call = _ref24.call(_classStaticPrivateFi4)) === null || _ref24$call === void 0 ? void 0 : _ref24$call.self) === null || _call$self2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_call$self2, Foo, _x); + (_getSelf$self3 = (_ref25 = (_fn12 = fn) === null || _fn12 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn12().Foo, Foo, _self)) === null || _ref25 === void 0 ? void 0 : (_ref25$getSelf = _ref25.getSelf()) === null || _ref25$getSelf === void 0 ? void 0 : _ref25$getSelf.self) === null || _getSelf$self3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_getSelf$self3, Foo, _x); + (_getSelf$self4 = (_ref26 = (_fn13 = fn) === null || _fn13 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn13().Foo, Foo, _self)) === null || _ref26 === void 0 ? void 0 : (_ref26$getSelf = _ref26.getSelf) === null || _ref26$getSelf === void 0 ? void 0 : (_ref26$getSelf$call = _ref26$getSelf.call(_ref26)) === null || _ref26$getSelf$call === void 0 ? void 0 : _ref26$getSelf$call.self) === null || _getSelf$self4 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_getSelf$self4, Foo, _x); + } + +} + +var _x = { + writable: true, + value: 1 +}; +var _self = { + writable: true, + value: Foo +}; + +_defineProperty(Foo, "self", Foo); + +Foo.test(); diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-optional-property/exec.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-optional-property/exec.js new file mode 100644 index 000000000000..0d627ac9e0d4 --- /dev/null +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-optional-property/exec.js @@ -0,0 +1,125 @@ +class Foo { + static #x = 1; + static #self = Foo; + static self = Foo; + static getSelf() { return this } + + static test() { + const o = { Foo: Foo }; + const deep = { very: { o } }; + function fn() { + return o; + } + function fnDeep() { + return deep; + } + + expect(Foo?.#x).toEqual(1); + expect(Foo?.#x.toString).toEqual(1..toString); + expect(Foo?.#x.toString()).toEqual('1'); + + expect(o?.Foo?.#x).toEqual(1); + expect(o?.Foo?.#x.toString).toEqual(1..toString); + expect(o?.Foo?.#x.toString()).toEqual('1'); + + expect(deep?.very.o?.Foo?.#x).toEqual(1); + expect(deep?.very.o?.Foo?.#x.toString).toEqual(1..toString); + expect(deep?.very.o?.Foo?.#x.toString()).toEqual('1'); + + expect(o?.Foo.#self?.#x).toEqual(1); + expect(o?.Foo.#self.self?.#x).toEqual(1); + expect(o?.Foo.#self?.self?.#x).toEqual(1); + expect(o?.Foo.#self.self?.self?.#x).toEqual(1); + expect(o?.Foo.#self?.self?.self?.#x).toEqual(1); + + expect(o?.Foo.#self.getSelf()?.#x).toEqual(1); + expect(o?.Foo.#self.getSelf?.()?.#x).toEqual(1); + expect(o?.Foo.#self?.getSelf()?.#x).toEqual(1); + expect(o?.Foo.#self?.getSelf?.()?.#x).toEqual(1); + expect(o?.Foo.#self.getSelf()?.self?.#x).toEqual(1); + expect(o?.Foo.#self.getSelf?.()?.self?.#x).toEqual(1); + expect(o?.Foo.#self?.getSelf()?.self?.#x).toEqual(1); + expect(o?.Foo.#self?.getSelf?.()?.self?.#x).toEqual(1); + + expect(fn?.().Foo?.#x).toEqual(1); + expect(fn?.().Foo?.#x.toString).toEqual(1..toString); + expect(fn?.().Foo?.#x.toString()).toEqual('1'); + + expect(fnDeep?.().very.o?.Foo?.#x).toEqual(1); + expect(fnDeep?.().very.o?.Foo?.#x.toString).toEqual(1..toString); + expect(fnDeep?.().very.o?.Foo?.#x.toString()).toEqual('1'); + + expect(fn?.().Foo.#self?.#x).toEqual(1); + expect(fn?.().Foo.#self.self?.#x).toEqual(1); + expect(fn?.().Foo.#self?.self?.#x).toEqual(1); + expect(fn?.().Foo.#self.self?.self?.#x).toEqual(1); + expect(fn?.().Foo.#self?.self?.self?.#x).toEqual(1); + + expect(fn?.().Foo.#self.getSelf()?.#x).toEqual(1); + expect(fn?.().Foo.#self.getSelf?.()?.#x).toEqual(1); + expect(fn?.().Foo.#self?.getSelf()?.#x).toEqual(1); + expect(fn?.().Foo.#self?.getSelf?.()?.#x).toEqual(1); + expect(fn?.().Foo.#self.getSelf()?.self?.#x).toEqual(1); + expect(fn?.().Foo.#self.getSelf?.()?.self?.#x).toEqual(1); + expect(fn?.().Foo.#self?.getSelf()?.self?.#x).toEqual(1); + expect(fn?.().Foo.#self?.getSelf?.()?.self?.#x).toEqual(1); + } + + static testNull() { + const o = null;; + const deep = { very: { o } }; + const fn = null; + function fnDeep() { + return deep; + } + + expect(o?.Foo?.#x).toEqual(undefined); + expect(o?.Foo?.#x.toString).toEqual(undefined); + expect(o?.Foo?.#x.toString()).toEqual(undefined); + + expect(deep?.very.o?.Foo?.#x).toEqual(undefined); + expect(deep?.very.o?.Foo?.#x.toString).toEqual(undefined); + expect(deep?.very.o?.Foo?.#x.toString()).toEqual(undefined); + + expect(o?.Foo.#self?.#x).toEqual(undefined); + expect(o?.Foo.#self.self?.#x).toEqual(undefined); + expect(o?.Foo.#self?.self?.#x).toEqual(undefined); + expect(o?.Foo.#self.self?.self?.#x).toEqual(undefined); + expect(o?.Foo.#self?.self?.self?.#x).toEqual(undefined); + + expect(o?.Foo.#self.getSelf()?.#x).toEqual(undefined); + expect(o?.Foo.#self.getSelf?.()?.#x).toEqual(undefined); + expect(o?.Foo.#self?.getSelf()?.#x).toEqual(undefined); + expect(o?.Foo.#self?.getSelf?.()?.#x).toEqual(undefined); + expect(o?.Foo.#self.getSelf()?.self?.#x).toEqual(undefined); + expect(o?.Foo.#self.getSelf?.()?.self?.#x).toEqual(undefined); + expect(o?.Foo.#self?.getSelf()?.self?.#x).toEqual(undefined); + expect(o?.Foo.#self?.getSelf?.()?.self?.#x).toEqual(undefined); + + expect(fn?.().Foo?.#x).toEqual(undefined); + expect(fn?.().Foo?.#x.toString).toEqual(undefined); + expect(fn?.().Foo?.#x.toString()).toEqual(undefined); + + expect(fnDeep?.().very.o?.Foo?.#x).toEqual(undefined); + expect(fnDeep?.().very.o?.Foo?.#x.toString).toEqual(undefined); + expect(fnDeep?.().very.o?.Foo?.#x.toString()).toEqual(undefined); + + expect(fn?.().Foo.#self?.#x).toEqual(undefined); + expect(fn?.().Foo.#self.self?.#x).toEqual(undefined); + expect(fn?.().Foo.#self?.self?.#x).toEqual(undefined); + expect(fn?.().Foo.#self.self?.self?.#x).toEqual(undefined); + expect(fn?.().Foo.#self?.self?.self?.#x).toEqual(undefined); + + expect(fn?.().Foo.#self.getSelf()?.#x).toEqual(undefined); + expect(fn?.().Foo.#self.getSelf?.()?.#x).toEqual(undefined); + expect(fn?.().Foo.#self?.getSelf()?.#x).toEqual(undefined); + expect(fn?.().Foo.#self?.getSelf?.()?.#x).toEqual(undefined); + expect(fn?.().Foo.#self.getSelf()?.self?.#x).toEqual(undefined); + expect(fn?.().Foo.#self.getSelf?.()?.self?.#x).toEqual(undefined); + expect(fn?.().Foo.#self?.getSelf()?.self?.#x).toEqual(undefined); + expect(fn?.().Foo.#self?.getSelf?.()?.self?.#x).toEqual(undefined); + } +} + +Foo.test(); +Foo.testNull(); diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-optional-property/input.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-optional-property/input.js new file mode 100644 index 000000000000..aecba329a27a --- /dev/null +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-optional-property/input.js @@ -0,0 +1,70 @@ +class Foo { + static #x = 1; + static #self = Foo; + static self = Foo; + static getSelf() { return this } + + static test() { + const o = { Foo: Foo }; + const deep = { very: { o } }; + function fn() { + return o; + } + function fnDeep() { + return deep; + } + + Foo?.#x; + Foo?.#x.toString; + Foo?.#x.toString(); + + o?.Foo?.#x; + o?.Foo?.#x.toString; + o?.Foo?.#x.toString(); + + deep?.very.o?.Foo?.#x; + deep?.very.o?.Foo?.#x.toString; + deep?.very.o?.Foo?.#x.toString(); + + o?.Foo.#self?.#x; + o?.Foo.#self.self?.#x; + o?.Foo.#self?.self?.#x; + o?.Foo.#self.self?.self?.#x; + o?.Foo.#self?.self?.self?.#x; + + o?.Foo.#self.getSelf()?.#x; + o?.Foo.#self.getSelf?.()?.#x; + o?.Foo.#self?.getSelf()?.#x; + o?.Foo.#self?.getSelf?.()?.#x; + o?.Foo.#self.getSelf()?.self?.#x; + o?.Foo.#self.getSelf?.()?.self?.#x; + o?.Foo.#self?.getSelf()?.self?.#x; + o?.Foo.#self?.getSelf?.()?.self?.#x; + + fn?.().Foo?.#x; + fn?.().Foo?.#x.toString; + fn?.().Foo?.#x.toString(); + + fnDeep?.().very.o?.Foo?.#x; + fnDeep?.().very.o?.Foo?.#x.toString; + fnDeep?.().very.o?.Foo?.#x.toString(); + + fn?.().Foo.#self?.#x; + fn?.().Foo.#self.self?.#x; + fn?.().Foo.#self?.self?.#x; + fn?.().Foo.#self.self?.self?.#x; + fn?.().Foo.#self?.self?.self?.#x; + + fn?.().Foo.#self.getSelf()?.#x; + fn?.().Foo.#self.getSelf?.()?.#x; + fn?.().Foo.#self?.getSelf()?.#x; + fn?.().Foo.#self?.getSelf?.()?.#x; + fn?.().Foo.#self.getSelf()?.self?.#x; + fn?.().Foo.#self.getSelf?.()?.self?.#x; + fn?.().Foo.#self?.getSelf()?.self?.#x; + fn?.().Foo.#self?.getSelf?.()?.self?.#x; + + } +} + +Foo.test(); diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-optional-property/options.json b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-optional-property/options.json new file mode 100644 index 000000000000..19ed5174f545 --- /dev/null +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-optional-property/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["proposal-class-properties"] +} diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-optional-property/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-optional-property/output.js new file mode 100644 index 000000000000..b095f6df78af --- /dev/null +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-optional-property/output.js @@ -0,0 +1,86 @@ +function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } + +function _classStaticPrivateFieldSpecGet(receiver, classConstructor, descriptor) { if (receiver !== classConstructor) { throw new TypeError("Private static access of wrong provenance"); } if (descriptor.get) { return descriptor.get.call(receiver); } return descriptor.value; } + +class Foo { + static getSelf() { + return this; + } + + static test() { + var _Foo, _Foo2, _Foo3, _o$Foo, _o$Foo2, _o$Foo3, _deep$very$o$Foo, _deep$very$o$Foo2, _deep$very$o$Foo3, _o, _ref, _o2, _ref2, _o3, _self2, _o4, _self3, _o5, _self$self, _o6, _ref3, _o7, _classStaticPrivateFi, _call, _o8, _getSelf, _o9, _getSelf2, _o10, _self4, _o11, _classStaticPrivateFi2, _call$self, _o12, _getSelf$self, _o13, _getSelf$self2, _fn$Foo, _fn$Foo2, _fn$Foo3, _fnDeep$very$o$Foo, _fnDeep$very$o$Foo2, _fnDeep$very$o$Foo3, _fn, _ref4, _fn2, _ref5, _fn3, _self5, _fn4, _self6, _fn5, _self$self2, _fn6, _ref6, _fn7, _classStaticPrivateFi3, _call2, _fn8, _getSelf3, _fn9, _getSelf4, _fn10, _self7, _fn11, _classStaticPrivateFi4, _call$self2, _fn12, _getSelf$self3, _fn13, _getSelf$self4; + + const o = { + Foo: Foo + }; + const deep = { + very: { + o + } + }; + + function fn() { + return o; + } + + function fnDeep() { + return deep; + } + + (_Foo = Foo) === null || _Foo === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_Foo, Foo, _x); + (_Foo2 = Foo) === null || _Foo2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_Foo2, Foo, _x).toString; + (_Foo3 = Foo) === null || _Foo3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_Foo3, Foo, _x).toString(); + (_o$Foo = o?.Foo) === null || _o$Foo === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o$Foo, Foo, _x); + (_o$Foo2 = o?.Foo) === null || _o$Foo2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o$Foo2, Foo, _x).toString; + (_o$Foo3 = o?.Foo) === null || _o$Foo3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o$Foo3, Foo, _x).toString(); + (_deep$very$o$Foo = deep?.very.o?.Foo) === null || _deep$very$o$Foo === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_deep$very$o$Foo, Foo, _x); + (_deep$very$o$Foo2 = deep?.very.o?.Foo) === null || _deep$very$o$Foo2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_deep$very$o$Foo2, Foo, _x).toString; + (_deep$very$o$Foo3 = deep?.very.o?.Foo) === null || _deep$very$o$Foo3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_deep$very$o$Foo3, Foo, _x).toString(); + (_ref = (_o = o) === null || _o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o.Foo, Foo, _self)) === null || _ref === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref, Foo, _x); + (_ref2 = (_o2 = o) === null || _o2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o2.Foo, Foo, _self).self) === null || _ref2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref2, Foo, _x); + (_self2 = ((_o3 = o) === null || _o3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o3.Foo, Foo, _self))?.self) === null || _self2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_self2, Foo, _x); + (_self3 = ((_o4 = o) === null || _o4 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o4.Foo, Foo, _self).self)?.self) === null || _self3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_self3, Foo, _x); + (_self$self = ((_o5 = o) === null || _o5 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o5.Foo, Foo, _self))?.self?.self) === null || _self$self === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_self$self, Foo, _x); + (_ref3 = (_o6 = o) === null || _o6 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o6.Foo, Foo, _self).getSelf()) === null || _ref3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref3, Foo, _x); + (_call = ((_o7 = o) === null || _o7 === void 0 ? void 0 : (_classStaticPrivateFi = _classStaticPrivateFieldSpecGet(_o7.Foo, Foo, _self)).getSelf)?.call(_classStaticPrivateFi)) === null || _call === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_call, Foo, _x); + (_getSelf = ((_o8 = o) === null || _o8 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o8.Foo, Foo, _self))?.getSelf()) === null || _getSelf === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_getSelf, Foo, _x); + (_getSelf2 = ((_o9 = o) === null || _o9 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o9.Foo, Foo, _self))?.getSelf?.()) === null || _getSelf2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_getSelf2, Foo, _x); + (_self4 = ((_o10 = o) === null || _o10 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o10.Foo, Foo, _self).getSelf())?.self) === null || _self4 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_self4, Foo, _x); + (_call$self = ((_o11 = o) === null || _o11 === void 0 ? void 0 : (_classStaticPrivateFi2 = _classStaticPrivateFieldSpecGet(_o11.Foo, Foo, _self)).getSelf)?.call(_classStaticPrivateFi2)?.self) === null || _call$self === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_call$self, Foo, _x); + (_getSelf$self = ((_o12 = o) === null || _o12 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o12.Foo, Foo, _self))?.getSelf()?.self) === null || _getSelf$self === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_getSelf$self, Foo, _x); + (_getSelf$self2 = ((_o13 = o) === null || _o13 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o13.Foo, Foo, _self))?.getSelf?.()?.self) === null || _getSelf$self2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_getSelf$self2, Foo, _x); + (_fn$Foo = fn?.().Foo) === null || _fn$Foo === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn$Foo, Foo, _x); + (_fn$Foo2 = fn?.().Foo) === null || _fn$Foo2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn$Foo2, Foo, _x).toString; + (_fn$Foo3 = fn?.().Foo) === null || _fn$Foo3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn$Foo3, Foo, _x).toString(); + (_fnDeep$very$o$Foo = fnDeep?.().very.o?.Foo) === null || _fnDeep$very$o$Foo === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fnDeep$very$o$Foo, Foo, _x); + (_fnDeep$very$o$Foo2 = fnDeep?.().very.o?.Foo) === null || _fnDeep$very$o$Foo2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fnDeep$very$o$Foo2, Foo, _x).toString; + (_fnDeep$very$o$Foo3 = fnDeep?.().very.o?.Foo) === null || _fnDeep$very$o$Foo3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fnDeep$very$o$Foo3, Foo, _x).toString(); + (_ref4 = (_fn = fn) === null || _fn === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn().Foo, Foo, _self)) === null || _ref4 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref4, Foo, _x); + (_ref5 = (_fn2 = fn) === null || _fn2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn2().Foo, Foo, _self).self) === null || _ref5 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref5, Foo, _x); + (_self5 = ((_fn3 = fn) === null || _fn3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn3().Foo, Foo, _self))?.self) === null || _self5 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_self5, Foo, _x); + (_self6 = ((_fn4 = fn) === null || _fn4 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn4().Foo, Foo, _self).self)?.self) === null || _self6 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_self6, Foo, _x); + (_self$self2 = ((_fn5 = fn) === null || _fn5 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn5().Foo, Foo, _self))?.self?.self) === null || _self$self2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_self$self2, Foo, _x); + (_ref6 = (_fn6 = fn) === null || _fn6 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn6().Foo, Foo, _self).getSelf()) === null || _ref6 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref6, Foo, _x); + (_call2 = ((_fn7 = fn) === null || _fn7 === void 0 ? void 0 : (_classStaticPrivateFi3 = _classStaticPrivateFieldSpecGet(_fn7().Foo, Foo, _self)).getSelf)?.call(_classStaticPrivateFi3)) === null || _call2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_call2, Foo, _x); + (_getSelf3 = ((_fn8 = fn) === null || _fn8 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn8().Foo, Foo, _self))?.getSelf()) === null || _getSelf3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_getSelf3, Foo, _x); + (_getSelf4 = ((_fn9 = fn) === null || _fn9 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn9().Foo, Foo, _self))?.getSelf?.()) === null || _getSelf4 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_getSelf4, Foo, _x); + (_self7 = ((_fn10 = fn) === null || _fn10 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn10().Foo, Foo, _self).getSelf())?.self) === null || _self7 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_self7, Foo, _x); + (_call$self2 = ((_fn11 = fn) === null || _fn11 === void 0 ? void 0 : (_classStaticPrivateFi4 = _classStaticPrivateFieldSpecGet(_fn11().Foo, Foo, _self)).getSelf)?.call(_classStaticPrivateFi4)?.self) === null || _call$self2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_call$self2, Foo, _x); + (_getSelf$self3 = ((_fn12 = fn) === null || _fn12 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn12().Foo, Foo, _self))?.getSelf()?.self) === null || _getSelf$self3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_getSelf$self3, Foo, _x); + (_getSelf$self4 = ((_fn13 = fn) === null || _fn13 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn13().Foo, Foo, _self))?.getSelf?.()?.self) === null || _getSelf$self4 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_getSelf$self4, Foo, _x); + } + +} + +var _x = { + writable: true, + value: 1 +}; +var _self = { + writable: true, + value: Foo +}; + +_defineProperty(Foo, "self", Foo); + +Foo.test(); From 1788e52f7162e3bcf9ed19d31f983b10f717dc46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hu=C3=A1ng=20J=C3=B9nli=C3=A0ng?= Date: Fri, 22 May 2020 20:50:27 -0400 Subject: [PATCH 13/20] chore: run test on node 14 --- .../private/optional-chain-before-member-call/options.json | 3 ++- .../private/optional-chain-before-property/options.json | 3 ++- .../private/optional-chain-optional-member-call/options.json | 3 ++- .../private/optional-chain-optional-property/options.json | 3 ++- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-before-member-call/options.json b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-before-member-call/options.json index 19ed5174f545..3b59e1bbfcc8 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-before-member-call/options.json +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-before-member-call/options.json @@ -1,3 +1,4 @@ { - "plugins": ["proposal-class-properties"] + "plugins": ["proposal-class-properties"], + "minNodeVersion": "14.0.0" } diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-before-property/options.json b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-before-property/options.json index 19ed5174f545..3b59e1bbfcc8 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-before-property/options.json +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-before-property/options.json @@ -1,3 +1,4 @@ { - "plugins": ["proposal-class-properties"] + "plugins": ["proposal-class-properties"], + "minNodeVersion": "14.0.0" } diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-optional-member-call/options.json b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-optional-member-call/options.json index 19ed5174f545..3b59e1bbfcc8 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-optional-member-call/options.json +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-optional-member-call/options.json @@ -1,3 +1,4 @@ { - "plugins": ["proposal-class-properties"] + "plugins": ["proposal-class-properties"], + "minNodeVersion": "14.0.0" } diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-optional-property/options.json b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-optional-property/options.json index 19ed5174f545..3b59e1bbfcc8 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-optional-property/options.json +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-optional-property/options.json @@ -1,3 +1,4 @@ { - "plugins": ["proposal-class-properties"] + "plugins": ["proposal-class-properties"], + "minNodeVersion": "14.0.0" } From f08975be3a7becf313d73af7c23826e5ee6e62d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hu=C3=A1ng=20J=C3=B9nli=C3=A0ng?= Date: Sun, 24 May 2020 16:23:14 -0400 Subject: [PATCH 14/20] =?UTF-8?q?fix:=20don=E2=80=99t=20memoise=20static?= =?UTF-8?q?=20base=20ref?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/index.js | 8 ++- .../output.js | 66 ++++++++--------- .../optional-chain-private-call/output.js | 66 ++++++++--------- .../optional-chain-with-transform/output.js | 66 ++++++++--------- .../private-loose/optional-chain/output.js | 66 ++++++++--------- .../output.js | 66 ++++++++--------- .../output.js | 66 ++++++++--------- .../output.js | 66 ++++++++--------- .../optional-chain-before-property/output.js | 66 ++++++++--------- .../output.js | 60 ++++++++-------- .../output.js | 72 +++++++++---------- .../output.js | 60 ++++++++-------- .../output.js | 60 ++++++++-------- 13 files changed, 395 insertions(+), 393 deletions(-) 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 fe3d22cadbd4..ae63cafaed67 100644 --- a/packages/babel-helper-member-expression-to-functions/src/index.js +++ b/packages/babel-helper-member-expression-to-functions/src/index.js @@ -153,8 +153,8 @@ const handle = { ? "object" : "callee"; const startingNode = startingOptional.node[startingProp]; - const baseRef = scope.generateUidIdentifierBasedOnNode(startingNode); - scope.push({ id: baseRef }); + const baseNeedsMemoised = scope.maybeGenerateMemoised(startingNode); + const baseRef = baseNeedsMemoised ?? startingNode; // Compute parentIsOptionalCall before `startingOptional` is replaced // as `node` may refer to `startingOptional.node` before replaced. @@ -197,7 +197,9 @@ const handle = { "||", t.binaryExpression( "===", - t.assignmentExpression("=", baseRef, startingNode), + baseNeedsMemoised + ? t.assignmentExpression("=", baseRef, startingNode) + : baseRef, t.nullLiteral(), ), t.binaryExpression("===", baseRef, scope.buildUndefinedNode()), diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-private-call-with-transform/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-private-call-with-transform/output.js index 081433ff45e9..9bd6511f49f6 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-private-call-with-transform/output.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-private-call-with-transform/output.js @@ -10,7 +10,7 @@ class Foo { } static test() { - var _o, _o2, _o3, _deep$very$o, _deep$very$o2, _deep$very$o3, _o4, _o5, _o6, _ref, _o7, _ref2, _o8, _self2, _o9, _o10, _classPrivateFieldLoo, _ref3, _o11, _ref4, _o12, _getSelf, _ref5, _o13, _ref6, _o14, _classPrivateFieldLoo2, _call, _o15, _getSelf2, _o16, _getSelf3, _fn, _fn2, _fn3, _fnDeep$very$o, _fnDeep$very$o2, _fnDeep$very$o3, _fn4, _fn5, _fn6, _ref7, _fn7, _ref8, _fn8, _self3, _fn9, _fn10, _classPrivateFieldLoo3, _ref9, _fn11, _ref10, _fn12, _getSelf4, _ref11, _fn13, _ref12, _fn14, _classPrivateFieldLoo4, _call2, _fn15, _getSelf5, _fn16, _getSelf6, _ref13, _ref14, _ref15, _ref16, _ref17, _ref17$getSelf, _ref18, _ref19, _ref20, _ref21, _ref22, _ref22$getSelf; + var _deep$very$o, _deep$very$o2, _deep$very$o3, _ref, _ref2, _self2, _classPrivateFieldLoo, _ref3, _ref4, _getSelf, _ref5, _ref6, _classPrivateFieldLoo2, _call, _getSelf2, _getSelf3, _fnDeep$very$o, _fnDeep$very$o2, _fnDeep$very$o3, _ref7, _ref8, _self3, _classPrivateFieldLoo3, _ref9, _ref10, _getSelf4, _ref11, _ref12, _classPrivateFieldLoo4, _call2, _getSelf5, _getSelf6, _ref13, _ref14, _ref15, _ref16, _ref17, _ref17$getSelf, _ref18, _ref19, _ref20, _ref21, _ref22, _ref22$getSelf; const o = { Foo: Foo @@ -29,44 +29,44 @@ class Foo { return deep; } - (_o = o) === null || _o === void 0 ? void 0 : _classPrivateFieldLooseBase(_o.Foo, _m)[_m](); - (_o2 = o) === null || _o2 === void 0 ? void 0 : _classPrivateFieldLooseBase(_o2.Foo, _m)[_m]().toString; - (_o3 = o) === null || _o3 === void 0 ? void 0 : _classPrivateFieldLooseBase(_o3.Foo, _m)[_m]().toString(); + o === null || o === void 0 ? void 0 : _classPrivateFieldLooseBase(o.Foo, _m)[_m](); + o === null || o === void 0 ? void 0 : _classPrivateFieldLooseBase(o.Foo, _m)[_m]().toString; + o === null || o === void 0 ? void 0 : _classPrivateFieldLooseBase(o.Foo, _m)[_m]().toString(); (_deep$very$o = deep === null || deep === void 0 ? void 0 : deep.very.o) === null || _deep$very$o === void 0 ? void 0 : _classPrivateFieldLooseBase(_deep$very$o.Foo, _m)[_m](); (_deep$very$o2 = deep === null || deep === void 0 ? void 0 : deep.very.o) === null || _deep$very$o2 === void 0 ? void 0 : _classPrivateFieldLooseBase(_deep$very$o2.Foo, _m)[_m]().toString; (_deep$very$o3 = deep === null || deep === void 0 ? void 0 : deep.very.o) === null || _deep$very$o3 === void 0 ? void 0 : _classPrivateFieldLooseBase(_deep$very$o3.Foo, _m)[_m]().toString(); - (_o4 = o) === null || _o4 === void 0 ? void 0 : _classPrivateFieldLooseBase(_classPrivateFieldLooseBase(_o4.Foo, _self)[_self], _m)[_m](); - (_o5 = o) === null || _o5 === void 0 ? void 0 : _classPrivateFieldLooseBase(_classPrivateFieldLooseBase(_o5.Foo, _self)[_self].self, _m)[_m](); - (_ref = (_o6 = o) === null || _o6 === void 0 ? void 0 : _classPrivateFieldLooseBase(_o6.Foo, _self)[_self]) === null || _ref === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref.self, _m)[_m](); - (_ref2 = (_o7 = o) === null || _o7 === void 0 ? void 0 : _classPrivateFieldLooseBase(_o7.Foo, _self)[_self].self) === null || _ref2 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref2.self, _m)[_m](); - (_self2 = (_ref13 = (_o8 = o) === null || _o8 === void 0 ? void 0 : _classPrivateFieldLooseBase(_o8.Foo, _self)[_self]) === null || _ref13 === void 0 ? void 0 : _ref13.self) === null || _self2 === void 0 ? void 0 : _classPrivateFieldLooseBase(_self2.self, _m)[_m](); - (_o9 = o) === null || _o9 === void 0 ? void 0 : _classPrivateFieldLooseBase(_classPrivateFieldLooseBase(_o9.Foo, _self)[_self].getSelf(), _m)[_m](); - (_ref3 = (_o10 = o) === null || _o10 === void 0 ? void 0 : (_classPrivateFieldLoo = _classPrivateFieldLooseBase(_o10.Foo, _self)[_self]).getSelf) === null || _ref3 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref3.call(_classPrivateFieldLoo), _m)[_m](); - (_ref4 = (_o11 = o) === null || _o11 === void 0 ? void 0 : _classPrivateFieldLooseBase(_o11.Foo, _self)[_self]) === null || _ref4 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref4.getSelf(), _m)[_m](); - (_getSelf = (_ref14 = _ref5 = (_o12 = o) === null || _o12 === void 0 ? void 0 : _classPrivateFieldLooseBase(_o12.Foo, _self)[_self]) === null || _ref14 === void 0 ? void 0 : _ref14.getSelf) === null || _getSelf === void 0 ? void 0 : _classPrivateFieldLooseBase(_getSelf.call(_ref5), _m)[_m](); - (_ref6 = (_o13 = o) === null || _o13 === void 0 ? void 0 : _classPrivateFieldLooseBase(_o13.Foo, _self)[_self].getSelf()) === null || _ref6 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref6.self, _m)[_m](); - (_call = (_ref15 = (_o14 = o) === null || _o14 === void 0 ? void 0 : (_classPrivateFieldLoo2 = _classPrivateFieldLooseBase(_o14.Foo, _self)[_self]).getSelf) === null || _ref15 === void 0 ? void 0 : _ref15.call(_classPrivateFieldLoo2)) === null || _call === void 0 ? void 0 : _classPrivateFieldLooseBase(_call.self, _m)[_m](); - (_getSelf2 = (_ref16 = (_o15 = o) === null || _o15 === void 0 ? void 0 : _classPrivateFieldLooseBase(_o15.Foo, _self)[_self]) === null || _ref16 === void 0 ? void 0 : _ref16.getSelf()) === null || _getSelf2 === void 0 ? void 0 : _classPrivateFieldLooseBase(_getSelf2.self, _m)[_m](); - (_getSelf3 = (_ref17 = (_o16 = o) === null || _o16 === void 0 ? void 0 : _classPrivateFieldLooseBase(_o16.Foo, _self)[_self]) === null || _ref17 === void 0 ? void 0 : (_ref17$getSelf = _ref17.getSelf) === null || _ref17$getSelf === void 0 ? void 0 : _ref17$getSelf.call(_ref17)) === null || _getSelf3 === void 0 ? void 0 : _classPrivateFieldLooseBase(_getSelf3.self, _m)[_m](); - (_fn = fn) === null || _fn === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn().Foo, _m)[_m](); - (_fn2 = fn) === null || _fn2 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn2().Foo, _m)[_m]().toString; - (_fn3 = fn) === null || _fn3 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn3().Foo, _m)[_m]().toString(); + o === null || o === void 0 ? void 0 : _classPrivateFieldLooseBase(_classPrivateFieldLooseBase(o.Foo, _self)[_self], _m)[_m](); + o === null || o === void 0 ? void 0 : _classPrivateFieldLooseBase(_classPrivateFieldLooseBase(o.Foo, _self)[_self].self, _m)[_m](); + (_ref = o === null || o === void 0 ? void 0 : _classPrivateFieldLooseBase(o.Foo, _self)[_self]) === null || _ref === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref.self, _m)[_m](); + (_ref2 = o === null || o === void 0 ? void 0 : _classPrivateFieldLooseBase(o.Foo, _self)[_self].self) === null || _ref2 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref2.self, _m)[_m](); + (_self2 = (_ref13 = o === null || o === void 0 ? void 0 : _classPrivateFieldLooseBase(o.Foo, _self)[_self]) === null || _ref13 === void 0 ? void 0 : _ref13.self) === null || _self2 === void 0 ? void 0 : _classPrivateFieldLooseBase(_self2.self, _m)[_m](); + o === null || o === void 0 ? void 0 : _classPrivateFieldLooseBase(_classPrivateFieldLooseBase(o.Foo, _self)[_self].getSelf(), _m)[_m](); + (_ref3 = o === null || o === void 0 ? void 0 : (_classPrivateFieldLoo = _classPrivateFieldLooseBase(o.Foo, _self)[_self]).getSelf) === null || _ref3 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref3.call(_classPrivateFieldLoo), _m)[_m](); + (_ref4 = o === null || o === void 0 ? void 0 : _classPrivateFieldLooseBase(o.Foo, _self)[_self]) === null || _ref4 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref4.getSelf(), _m)[_m](); + (_getSelf = (_ref14 = _ref5 = o === null || o === void 0 ? void 0 : _classPrivateFieldLooseBase(o.Foo, _self)[_self]) === null || _ref14 === void 0 ? void 0 : _ref14.getSelf) === null || _getSelf === void 0 ? void 0 : _classPrivateFieldLooseBase(_getSelf.call(_ref5), _m)[_m](); + (_ref6 = o === null || o === void 0 ? void 0 : _classPrivateFieldLooseBase(o.Foo, _self)[_self].getSelf()) === null || _ref6 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref6.self, _m)[_m](); + (_call = (_ref15 = o === null || o === void 0 ? void 0 : (_classPrivateFieldLoo2 = _classPrivateFieldLooseBase(o.Foo, _self)[_self]).getSelf) === null || _ref15 === void 0 ? void 0 : _ref15.call(_classPrivateFieldLoo2)) === null || _call === void 0 ? void 0 : _classPrivateFieldLooseBase(_call.self, _m)[_m](); + (_getSelf2 = (_ref16 = o === null || o === void 0 ? void 0 : _classPrivateFieldLooseBase(o.Foo, _self)[_self]) === null || _ref16 === void 0 ? void 0 : _ref16.getSelf()) === null || _getSelf2 === void 0 ? void 0 : _classPrivateFieldLooseBase(_getSelf2.self, _m)[_m](); + (_getSelf3 = (_ref17 = o === null || o === void 0 ? void 0 : _classPrivateFieldLooseBase(o.Foo, _self)[_self]) === null || _ref17 === void 0 ? void 0 : (_ref17$getSelf = _ref17.getSelf) === null || _ref17$getSelf === void 0 ? void 0 : _ref17$getSelf.call(_ref17)) === null || _getSelf3 === void 0 ? void 0 : _classPrivateFieldLooseBase(_getSelf3.self, _m)[_m](); + fn === null || fn === void 0 ? void 0 : _classPrivateFieldLooseBase(fn().Foo, _m)[_m](); + fn === null || fn === void 0 ? void 0 : _classPrivateFieldLooseBase(fn().Foo, _m)[_m]().toString; + fn === null || fn === void 0 ? void 0 : _classPrivateFieldLooseBase(fn().Foo, _m)[_m]().toString(); (_fnDeep$very$o = fnDeep === null || fnDeep === void 0 ? void 0 : fnDeep().very.o) === null || _fnDeep$very$o === void 0 ? void 0 : _classPrivateFieldLooseBase(_fnDeep$very$o.Foo, _m)[_m](); (_fnDeep$very$o2 = fnDeep === null || fnDeep === void 0 ? void 0 : fnDeep().very.o) === null || _fnDeep$very$o2 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fnDeep$very$o2.Foo, _m)[_m]().toString; (_fnDeep$very$o3 = fnDeep === null || fnDeep === void 0 ? void 0 : fnDeep().very.o) === null || _fnDeep$very$o3 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fnDeep$very$o3.Foo, _m)[_m]().toString(); - (_fn4 = fn) === null || _fn4 === void 0 ? void 0 : _classPrivateFieldLooseBase(_classPrivateFieldLooseBase(_fn4().Foo, _self)[_self], _m)[_m](); - (_fn5 = fn) === null || _fn5 === void 0 ? void 0 : _classPrivateFieldLooseBase(_classPrivateFieldLooseBase(_fn5().Foo, _self)[_self].self, _m)[_m](); - (_ref7 = (_fn6 = fn) === null || _fn6 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn6().Foo, _self)[_self]) === null || _ref7 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref7.self, _m)[_m](); - (_ref8 = (_fn7 = fn) === null || _fn7 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn7().Foo, _self)[_self].self) === null || _ref8 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref8.self, _m)[_m](); - (_self3 = (_ref18 = (_fn8 = fn) === null || _fn8 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn8().Foo, _self)[_self]) === null || _ref18 === void 0 ? void 0 : _ref18.self) === null || _self3 === void 0 ? void 0 : _classPrivateFieldLooseBase(_self3.self, _m)[_m](); - (_fn9 = fn) === null || _fn9 === void 0 ? void 0 : _classPrivateFieldLooseBase(_classPrivateFieldLooseBase(_fn9().Foo, _self)[_self].getSelf(), _m)[_m](); - (_ref9 = (_fn10 = fn) === null || _fn10 === void 0 ? void 0 : (_classPrivateFieldLoo3 = _classPrivateFieldLooseBase(_fn10().Foo, _self)[_self]).getSelf) === null || _ref9 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref9.call(_classPrivateFieldLoo3), _m)[_m](); - (_ref10 = (_fn11 = fn) === null || _fn11 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn11().Foo, _self)[_self]) === null || _ref10 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref10.getSelf(), _m)[_m](); - (_getSelf4 = (_ref19 = _ref11 = (_fn12 = fn) === null || _fn12 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn12().Foo, _self)[_self]) === null || _ref19 === void 0 ? void 0 : _ref19.getSelf) === null || _getSelf4 === void 0 ? void 0 : _classPrivateFieldLooseBase(_getSelf4.call(_ref11), _m)[_m](); - (_ref12 = (_fn13 = fn) === null || _fn13 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn13().Foo, _self)[_self].getSelf()) === null || _ref12 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref12.self, _m)[_m](); - (_call2 = (_ref20 = (_fn14 = fn) === null || _fn14 === void 0 ? void 0 : (_classPrivateFieldLoo4 = _classPrivateFieldLooseBase(_fn14().Foo, _self)[_self]).getSelf) === null || _ref20 === void 0 ? void 0 : _ref20.call(_classPrivateFieldLoo4)) === null || _call2 === void 0 ? void 0 : _classPrivateFieldLooseBase(_call2.self, _m)[_m](); - (_getSelf5 = (_ref21 = (_fn15 = fn) === null || _fn15 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn15().Foo, _self)[_self]) === null || _ref21 === void 0 ? void 0 : _ref21.getSelf()) === null || _getSelf5 === void 0 ? void 0 : _classPrivateFieldLooseBase(_getSelf5.self, _m)[_m](); - (_getSelf6 = (_ref22 = (_fn16 = fn) === null || _fn16 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn16().Foo, _self)[_self]) === null || _ref22 === void 0 ? void 0 : (_ref22$getSelf = _ref22.getSelf) === null || _ref22$getSelf === void 0 ? void 0 : _ref22$getSelf.call(_ref22)) === null || _getSelf6 === void 0 ? void 0 : _classPrivateFieldLooseBase(_getSelf6.self, _m)[_m](); + fn === null || fn === void 0 ? void 0 : _classPrivateFieldLooseBase(_classPrivateFieldLooseBase(fn().Foo, _self)[_self], _m)[_m](); + fn === null || fn === void 0 ? void 0 : _classPrivateFieldLooseBase(_classPrivateFieldLooseBase(fn().Foo, _self)[_self].self, _m)[_m](); + (_ref7 = fn === null || fn === void 0 ? void 0 : _classPrivateFieldLooseBase(fn().Foo, _self)[_self]) === null || _ref7 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref7.self, _m)[_m](); + (_ref8 = fn === null || fn === void 0 ? void 0 : _classPrivateFieldLooseBase(fn().Foo, _self)[_self].self) === null || _ref8 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref8.self, _m)[_m](); + (_self3 = (_ref18 = fn === null || fn === void 0 ? void 0 : _classPrivateFieldLooseBase(fn().Foo, _self)[_self]) === null || _ref18 === void 0 ? void 0 : _ref18.self) === null || _self3 === void 0 ? void 0 : _classPrivateFieldLooseBase(_self3.self, _m)[_m](); + fn === null || fn === void 0 ? void 0 : _classPrivateFieldLooseBase(_classPrivateFieldLooseBase(fn().Foo, _self)[_self].getSelf(), _m)[_m](); + (_ref9 = fn === null || fn === void 0 ? void 0 : (_classPrivateFieldLoo3 = _classPrivateFieldLooseBase(fn().Foo, _self)[_self]).getSelf) === null || _ref9 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref9.call(_classPrivateFieldLoo3), _m)[_m](); + (_ref10 = fn === null || fn === void 0 ? void 0 : _classPrivateFieldLooseBase(fn().Foo, _self)[_self]) === null || _ref10 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref10.getSelf(), _m)[_m](); + (_getSelf4 = (_ref19 = _ref11 = fn === null || fn === void 0 ? void 0 : _classPrivateFieldLooseBase(fn().Foo, _self)[_self]) === null || _ref19 === void 0 ? void 0 : _ref19.getSelf) === null || _getSelf4 === void 0 ? void 0 : _classPrivateFieldLooseBase(_getSelf4.call(_ref11), _m)[_m](); + (_ref12 = fn === null || fn === void 0 ? void 0 : _classPrivateFieldLooseBase(fn().Foo, _self)[_self].getSelf()) === null || _ref12 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref12.self, _m)[_m](); + (_call2 = (_ref20 = fn === null || fn === void 0 ? void 0 : (_classPrivateFieldLoo4 = _classPrivateFieldLooseBase(fn().Foo, _self)[_self]).getSelf) === null || _ref20 === void 0 ? void 0 : _ref20.call(_classPrivateFieldLoo4)) === null || _call2 === void 0 ? void 0 : _classPrivateFieldLooseBase(_call2.self, _m)[_m](); + (_getSelf5 = (_ref21 = fn === null || fn === void 0 ? void 0 : _classPrivateFieldLooseBase(fn().Foo, _self)[_self]) === null || _ref21 === void 0 ? void 0 : _ref21.getSelf()) === null || _getSelf5 === void 0 ? void 0 : _classPrivateFieldLooseBase(_getSelf5.self, _m)[_m](); + (_getSelf6 = (_ref22 = fn === null || fn === void 0 ? void 0 : _classPrivateFieldLooseBase(fn().Foo, _self)[_self]) === null || _ref22 === void 0 ? void 0 : (_ref22$getSelf = _ref22.getSelf) === null || _ref22$getSelf === void 0 ? void 0 : _ref22$getSelf.call(_ref22)) === null || _getSelf6 === void 0 ? void 0 : _classPrivateFieldLooseBase(_getSelf6.self, _m)[_m](); } } diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-private-call/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-private-call/output.js index b4775daf8bd5..4dfec699eef5 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-private-call/output.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-private-call/output.js @@ -10,7 +10,7 @@ class Foo { } static test() { - var _o, _o2, _o3, _deep$very$o, _deep$very$o2, _deep$very$o3, _o4, _o5, _o6, _ref, _o7, _ref2, _o8, _self2, _o9, _o10, _classPrivateFieldLoo, _ref3, _o11, _ref4, _o12, _getSelf, _ref5, _o13, _ref6, _o14, _classPrivateFieldLoo2, _call, _o15, _getSelf2, _o16, _getSelf3, _fn, _fn2, _fn3, _fnDeep$very$o, _fnDeep$very$o2, _fnDeep$very$o3, _fn4, _fn5, _fn6, _ref7, _fn7, _ref8, _fn8, _self3, _fn9, _fn10, _classPrivateFieldLoo3, _ref9, _fn11, _ref10, _fn12, _getSelf4, _ref11, _fn13, _ref12, _fn14, _classPrivateFieldLoo4, _call2, _fn15, _getSelf5, _fn16, _getSelf6; + var _deep$very$o, _deep$very$o2, _deep$very$o3, _ref, _ref2, _self2, _classPrivateFieldLoo, _ref3, _ref4, _getSelf, _ref5, _ref6, _classPrivateFieldLoo2, _call, _getSelf2, _getSelf3, _fnDeep$very$o, _fnDeep$very$o2, _fnDeep$very$o3, _ref7, _ref8, _self3, _classPrivateFieldLoo3, _ref9, _ref10, _getSelf4, _ref11, _ref12, _classPrivateFieldLoo4, _call2, _getSelf5, _getSelf6; const o = { Foo: Foo @@ -29,44 +29,44 @@ class Foo { return deep; } - (_o = o) === null || _o === void 0 ? void 0 : _classPrivateFieldLooseBase(_o.Foo, _m)[_m](); - (_o2 = o) === null || _o2 === void 0 ? void 0 : _classPrivateFieldLooseBase(_o2.Foo, _m)[_m]().toString; - (_o3 = o) === null || _o3 === void 0 ? void 0 : _classPrivateFieldLooseBase(_o3.Foo, _m)[_m]().toString(); + o === null || o === void 0 ? void 0 : _classPrivateFieldLooseBase(o.Foo, _m)[_m](); + o === null || o === void 0 ? void 0 : _classPrivateFieldLooseBase(o.Foo, _m)[_m]().toString; + o === null || o === void 0 ? void 0 : _classPrivateFieldLooseBase(o.Foo, _m)[_m]().toString(); (_deep$very$o = deep?.very.o) === null || _deep$very$o === void 0 ? void 0 : _classPrivateFieldLooseBase(_deep$very$o.Foo, _m)[_m](); (_deep$very$o2 = deep?.very.o) === null || _deep$very$o2 === void 0 ? void 0 : _classPrivateFieldLooseBase(_deep$very$o2.Foo, _m)[_m]().toString; (_deep$very$o3 = deep?.very.o) === null || _deep$very$o3 === void 0 ? void 0 : _classPrivateFieldLooseBase(_deep$very$o3.Foo, _m)[_m]().toString(); - (_o4 = o) === null || _o4 === void 0 ? void 0 : _classPrivateFieldLooseBase(_classPrivateFieldLooseBase(_o4.Foo, _self)[_self], _m)[_m](); - (_o5 = o) === null || _o5 === void 0 ? void 0 : _classPrivateFieldLooseBase(_classPrivateFieldLooseBase(_o5.Foo, _self)[_self].self, _m)[_m](); - (_ref = (_o6 = o) === null || _o6 === void 0 ? void 0 : _classPrivateFieldLooseBase(_o6.Foo, _self)[_self]) === null || _ref === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref.self, _m)[_m](); - (_ref2 = (_o7 = o) === null || _o7 === void 0 ? void 0 : _classPrivateFieldLooseBase(_o7.Foo, _self)[_self].self) === null || _ref2 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref2.self, _m)[_m](); - (_self2 = ((_o8 = o) === null || _o8 === void 0 ? void 0 : _classPrivateFieldLooseBase(_o8.Foo, _self)[_self])?.self) === null || _self2 === void 0 ? void 0 : _classPrivateFieldLooseBase(_self2.self, _m)[_m](); - (_o9 = o) === null || _o9 === void 0 ? void 0 : _classPrivateFieldLooseBase(_classPrivateFieldLooseBase(_o9.Foo, _self)[_self].getSelf(), _m)[_m](); - (_ref3 = (_o10 = o) === null || _o10 === void 0 ? void 0 : (_classPrivateFieldLoo = _classPrivateFieldLooseBase(_o10.Foo, _self)[_self]).getSelf) === null || _ref3 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref3.call(_classPrivateFieldLoo), _m)[_m](); - (_ref4 = (_o11 = o) === null || _o11 === void 0 ? void 0 : _classPrivateFieldLooseBase(_o11.Foo, _self)[_self]) === null || _ref4 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref4.getSelf(), _m)[_m](); - (_getSelf = (_ref5 = (_o12 = o) === null || _o12 === void 0 ? void 0 : _classPrivateFieldLooseBase(_o12.Foo, _self)[_self])?.getSelf) === null || _getSelf === void 0 ? void 0 : _classPrivateFieldLooseBase(_getSelf.call(_ref5), _m)[_m](); - (_ref6 = (_o13 = o) === null || _o13 === void 0 ? void 0 : _classPrivateFieldLooseBase(_o13.Foo, _self)[_self].getSelf()) === null || _ref6 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref6.self, _m)[_m](); - (_call = ((_o14 = o) === null || _o14 === void 0 ? void 0 : (_classPrivateFieldLoo2 = _classPrivateFieldLooseBase(_o14.Foo, _self)[_self]).getSelf)?.call(_classPrivateFieldLoo2)) === null || _call === void 0 ? void 0 : _classPrivateFieldLooseBase(_call.self, _m)[_m](); - (_getSelf2 = ((_o15 = o) === null || _o15 === void 0 ? void 0 : _classPrivateFieldLooseBase(_o15.Foo, _self)[_self])?.getSelf()) === null || _getSelf2 === void 0 ? void 0 : _classPrivateFieldLooseBase(_getSelf2.self, _m)[_m](); - (_getSelf3 = ((_o16 = o) === null || _o16 === void 0 ? void 0 : _classPrivateFieldLooseBase(_o16.Foo, _self)[_self])?.getSelf?.()) === null || _getSelf3 === void 0 ? void 0 : _classPrivateFieldLooseBase(_getSelf3.self, _m)[_m](); - (_fn = fn) === null || _fn === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn().Foo, _m)[_m](); - (_fn2 = fn) === null || _fn2 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn2().Foo, _m)[_m]().toString; - (_fn3 = fn) === null || _fn3 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn3().Foo, _m)[_m]().toString(); + o === null || o === void 0 ? void 0 : _classPrivateFieldLooseBase(_classPrivateFieldLooseBase(o.Foo, _self)[_self], _m)[_m](); + o === null || o === void 0 ? void 0 : _classPrivateFieldLooseBase(_classPrivateFieldLooseBase(o.Foo, _self)[_self].self, _m)[_m](); + (_ref = o === null || o === void 0 ? void 0 : _classPrivateFieldLooseBase(o.Foo, _self)[_self]) === null || _ref === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref.self, _m)[_m](); + (_ref2 = o === null || o === void 0 ? void 0 : _classPrivateFieldLooseBase(o.Foo, _self)[_self].self) === null || _ref2 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref2.self, _m)[_m](); + (_self2 = (o === null || o === void 0 ? void 0 : _classPrivateFieldLooseBase(o.Foo, _self)[_self])?.self) === null || _self2 === void 0 ? void 0 : _classPrivateFieldLooseBase(_self2.self, _m)[_m](); + o === null || o === void 0 ? void 0 : _classPrivateFieldLooseBase(_classPrivateFieldLooseBase(o.Foo, _self)[_self].getSelf(), _m)[_m](); + (_ref3 = o === null || o === void 0 ? void 0 : (_classPrivateFieldLoo = _classPrivateFieldLooseBase(o.Foo, _self)[_self]).getSelf) === null || _ref3 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref3.call(_classPrivateFieldLoo), _m)[_m](); + (_ref4 = o === null || o === void 0 ? void 0 : _classPrivateFieldLooseBase(o.Foo, _self)[_self]) === null || _ref4 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref4.getSelf(), _m)[_m](); + (_getSelf = (_ref5 = o === null || o === void 0 ? void 0 : _classPrivateFieldLooseBase(o.Foo, _self)[_self])?.getSelf) === null || _getSelf === void 0 ? void 0 : _classPrivateFieldLooseBase(_getSelf.call(_ref5), _m)[_m](); + (_ref6 = o === null || o === void 0 ? void 0 : _classPrivateFieldLooseBase(o.Foo, _self)[_self].getSelf()) === null || _ref6 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref6.self, _m)[_m](); + (_call = (o === null || o === void 0 ? void 0 : (_classPrivateFieldLoo2 = _classPrivateFieldLooseBase(o.Foo, _self)[_self]).getSelf)?.call(_classPrivateFieldLoo2)) === null || _call === void 0 ? void 0 : _classPrivateFieldLooseBase(_call.self, _m)[_m](); + (_getSelf2 = (o === null || o === void 0 ? void 0 : _classPrivateFieldLooseBase(o.Foo, _self)[_self])?.getSelf()) === null || _getSelf2 === void 0 ? void 0 : _classPrivateFieldLooseBase(_getSelf2.self, _m)[_m](); + (_getSelf3 = (o === null || o === void 0 ? void 0 : _classPrivateFieldLooseBase(o.Foo, _self)[_self])?.getSelf?.()) === null || _getSelf3 === void 0 ? void 0 : _classPrivateFieldLooseBase(_getSelf3.self, _m)[_m](); + fn === null || fn === void 0 ? void 0 : _classPrivateFieldLooseBase(fn().Foo, _m)[_m](); + fn === null || fn === void 0 ? void 0 : _classPrivateFieldLooseBase(fn().Foo, _m)[_m]().toString; + fn === null || fn === void 0 ? void 0 : _classPrivateFieldLooseBase(fn().Foo, _m)[_m]().toString(); (_fnDeep$very$o = fnDeep?.().very.o) === null || _fnDeep$very$o === void 0 ? void 0 : _classPrivateFieldLooseBase(_fnDeep$very$o.Foo, _m)[_m](); (_fnDeep$very$o2 = fnDeep?.().very.o) === null || _fnDeep$very$o2 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fnDeep$very$o2.Foo, _m)[_m]().toString; (_fnDeep$very$o3 = fnDeep?.().very.o) === null || _fnDeep$very$o3 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fnDeep$very$o3.Foo, _m)[_m]().toString(); - (_fn4 = fn) === null || _fn4 === void 0 ? void 0 : _classPrivateFieldLooseBase(_classPrivateFieldLooseBase(_fn4().Foo, _self)[_self], _m)[_m](); - (_fn5 = fn) === null || _fn5 === void 0 ? void 0 : _classPrivateFieldLooseBase(_classPrivateFieldLooseBase(_fn5().Foo, _self)[_self].self, _m)[_m](); - (_ref7 = (_fn6 = fn) === null || _fn6 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn6().Foo, _self)[_self]) === null || _ref7 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref7.self, _m)[_m](); - (_ref8 = (_fn7 = fn) === null || _fn7 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn7().Foo, _self)[_self].self) === null || _ref8 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref8.self, _m)[_m](); - (_self3 = ((_fn8 = fn) === null || _fn8 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn8().Foo, _self)[_self])?.self) === null || _self3 === void 0 ? void 0 : _classPrivateFieldLooseBase(_self3.self, _m)[_m](); - (_fn9 = fn) === null || _fn9 === void 0 ? void 0 : _classPrivateFieldLooseBase(_classPrivateFieldLooseBase(_fn9().Foo, _self)[_self].getSelf(), _m)[_m](); - (_ref9 = (_fn10 = fn) === null || _fn10 === void 0 ? void 0 : (_classPrivateFieldLoo3 = _classPrivateFieldLooseBase(_fn10().Foo, _self)[_self]).getSelf) === null || _ref9 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref9.call(_classPrivateFieldLoo3), _m)[_m](); - (_ref10 = (_fn11 = fn) === null || _fn11 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn11().Foo, _self)[_self]) === null || _ref10 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref10.getSelf(), _m)[_m](); - (_getSelf4 = (_ref11 = (_fn12 = fn) === null || _fn12 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn12().Foo, _self)[_self])?.getSelf) === null || _getSelf4 === void 0 ? void 0 : _classPrivateFieldLooseBase(_getSelf4.call(_ref11), _m)[_m](); - (_ref12 = (_fn13 = fn) === null || _fn13 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn13().Foo, _self)[_self].getSelf()) === null || _ref12 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref12.self, _m)[_m](); - (_call2 = ((_fn14 = fn) === null || _fn14 === void 0 ? void 0 : (_classPrivateFieldLoo4 = _classPrivateFieldLooseBase(_fn14().Foo, _self)[_self]).getSelf)?.call(_classPrivateFieldLoo4)) === null || _call2 === void 0 ? void 0 : _classPrivateFieldLooseBase(_call2.self, _m)[_m](); - (_getSelf5 = ((_fn15 = fn) === null || _fn15 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn15().Foo, _self)[_self])?.getSelf()) === null || _getSelf5 === void 0 ? void 0 : _classPrivateFieldLooseBase(_getSelf5.self, _m)[_m](); - (_getSelf6 = ((_fn16 = fn) === null || _fn16 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn16().Foo, _self)[_self])?.getSelf?.()) === null || _getSelf6 === void 0 ? void 0 : _classPrivateFieldLooseBase(_getSelf6.self, _m)[_m](); + fn === null || fn === void 0 ? void 0 : _classPrivateFieldLooseBase(_classPrivateFieldLooseBase(fn().Foo, _self)[_self], _m)[_m](); + fn === null || fn === void 0 ? void 0 : _classPrivateFieldLooseBase(_classPrivateFieldLooseBase(fn().Foo, _self)[_self].self, _m)[_m](); + (_ref7 = fn === null || fn === void 0 ? void 0 : _classPrivateFieldLooseBase(fn().Foo, _self)[_self]) === null || _ref7 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref7.self, _m)[_m](); + (_ref8 = fn === null || fn === void 0 ? void 0 : _classPrivateFieldLooseBase(fn().Foo, _self)[_self].self) === null || _ref8 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref8.self, _m)[_m](); + (_self3 = (fn === null || fn === void 0 ? void 0 : _classPrivateFieldLooseBase(fn().Foo, _self)[_self])?.self) === null || _self3 === void 0 ? void 0 : _classPrivateFieldLooseBase(_self3.self, _m)[_m](); + fn === null || fn === void 0 ? void 0 : _classPrivateFieldLooseBase(_classPrivateFieldLooseBase(fn().Foo, _self)[_self].getSelf(), _m)[_m](); + (_ref9 = fn === null || fn === void 0 ? void 0 : (_classPrivateFieldLoo3 = _classPrivateFieldLooseBase(fn().Foo, _self)[_self]).getSelf) === null || _ref9 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref9.call(_classPrivateFieldLoo3), _m)[_m](); + (_ref10 = fn === null || fn === void 0 ? void 0 : _classPrivateFieldLooseBase(fn().Foo, _self)[_self]) === null || _ref10 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref10.getSelf(), _m)[_m](); + (_getSelf4 = (_ref11 = fn === null || fn === void 0 ? void 0 : _classPrivateFieldLooseBase(fn().Foo, _self)[_self])?.getSelf) === null || _getSelf4 === void 0 ? void 0 : _classPrivateFieldLooseBase(_getSelf4.call(_ref11), _m)[_m](); + (_ref12 = fn === null || fn === void 0 ? void 0 : _classPrivateFieldLooseBase(fn().Foo, _self)[_self].getSelf()) === null || _ref12 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref12.self, _m)[_m](); + (_call2 = (fn === null || fn === void 0 ? void 0 : (_classPrivateFieldLoo4 = _classPrivateFieldLooseBase(fn().Foo, _self)[_self]).getSelf)?.call(_classPrivateFieldLoo4)) === null || _call2 === void 0 ? void 0 : _classPrivateFieldLooseBase(_call2.self, _m)[_m](); + (_getSelf5 = (fn === null || fn === void 0 ? void 0 : _classPrivateFieldLooseBase(fn().Foo, _self)[_self])?.getSelf()) === null || _getSelf5 === void 0 ? void 0 : _classPrivateFieldLooseBase(_getSelf5.self, _m)[_m](); + (_getSelf6 = (fn === null || fn === void 0 ? void 0 : _classPrivateFieldLooseBase(fn().Foo, _self)[_self])?.getSelf?.()) === null || _getSelf6 === void 0 ? void 0 : _classPrivateFieldLooseBase(_getSelf6.self, _m)[_m](); } } diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-with-transform/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-with-transform/output.js index 90cdc75d8598..e247de3d3c63 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-with-transform/output.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-with-transform/output.js @@ -10,7 +10,7 @@ class Foo { } static test() { - var _o, _o2, _o3, _deep$very$o, _deep$very$o2, _deep$very$o3, _o4, _o5, _o6, _ref, _o7, _ref2, _o8, _self2, _o9, _o10, _classPrivateFieldLoo, _ref3, _o11, _ref4, _o12, _getSelf, _ref5, _o13, _ref6, _o14, _classPrivateFieldLoo2, _call, _o15, _getSelf2, _o16, _getSelf3, _fn, _fn2, _fn3, _fnDeep$very$o, _fnDeep$very$o2, _fnDeep$very$o3, _fn4, _fn5, _fn6, _ref7, _fn7, _ref8, _fn8, _self3, _fn9, _fn10, _classPrivateFieldLoo3, _ref9, _fn11, _ref10, _fn12, _getSelf4, _ref11, _fn13, _ref12, _fn14, _classPrivateFieldLoo4, _call2, _fn15, _getSelf5, _fn16, _getSelf6, _ref13, _ref14, _ref15, _ref16, _ref17, _ref17$getSelf, _ref18, _ref19, _ref20, _ref21, _ref22, _ref22$getSelf; + var _deep$very$o, _deep$very$o2, _deep$very$o3, _ref, _ref2, _self2, _classPrivateFieldLoo, _ref3, _ref4, _getSelf, _ref5, _ref6, _classPrivateFieldLoo2, _call, _getSelf2, _getSelf3, _fnDeep$very$o, _fnDeep$very$o2, _fnDeep$very$o3, _ref7, _ref8, _self3, _classPrivateFieldLoo3, _ref9, _ref10, _getSelf4, _ref11, _ref12, _classPrivateFieldLoo4, _call2, _getSelf5, _getSelf6, _ref13, _ref14, _ref15, _ref16, _ref17, _ref17$getSelf, _ref18, _ref19, _ref20, _ref21, _ref22, _ref22$getSelf; const o = { Foo: Foo @@ -29,44 +29,44 @@ class Foo { return deep; } - (_o = o) === null || _o === void 0 ? void 0 : _classPrivateFieldLooseBase(_o.Foo, _x)[_x]; - (_o2 = o) === null || _o2 === void 0 ? void 0 : _classPrivateFieldLooseBase(_o2.Foo, _x)[_x].toString; - (_o3 = o) === null || _o3 === void 0 ? void 0 : _classPrivateFieldLooseBase(_o3.Foo, _x)[_x].toString(); + o === null || o === void 0 ? void 0 : _classPrivateFieldLooseBase(o.Foo, _x)[_x]; + o === null || o === void 0 ? void 0 : _classPrivateFieldLooseBase(o.Foo, _x)[_x].toString; + o === null || o === void 0 ? void 0 : _classPrivateFieldLooseBase(o.Foo, _x)[_x].toString(); (_deep$very$o = deep === null || deep === void 0 ? void 0 : deep.very.o) === null || _deep$very$o === void 0 ? void 0 : _classPrivateFieldLooseBase(_deep$very$o.Foo, _x)[_x]; (_deep$very$o2 = deep === null || deep === void 0 ? void 0 : deep.very.o) === null || _deep$very$o2 === void 0 ? void 0 : _classPrivateFieldLooseBase(_deep$very$o2.Foo, _x)[_x].toString; (_deep$very$o3 = deep === null || deep === void 0 ? void 0 : deep.very.o) === null || _deep$very$o3 === void 0 ? void 0 : _classPrivateFieldLooseBase(_deep$very$o3.Foo, _x)[_x].toString(); - (_o4 = o) === null || _o4 === void 0 ? void 0 : _classPrivateFieldLooseBase(_classPrivateFieldLooseBase(_o4.Foo, _self)[_self], _x)[_x]; - (_o5 = o) === null || _o5 === void 0 ? void 0 : _classPrivateFieldLooseBase(_classPrivateFieldLooseBase(_o5.Foo, _self)[_self].self, _x)[_x]; - (_ref = (_o6 = o) === null || _o6 === void 0 ? void 0 : _classPrivateFieldLooseBase(_o6.Foo, _self)[_self]) === null || _ref === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref.self, _x)[_x]; - (_ref2 = (_o7 = o) === null || _o7 === void 0 ? void 0 : _classPrivateFieldLooseBase(_o7.Foo, _self)[_self].self) === null || _ref2 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref2.self, _x)[_x]; - (_self2 = (_ref13 = (_o8 = o) === null || _o8 === void 0 ? void 0 : _classPrivateFieldLooseBase(_o8.Foo, _self)[_self]) === null || _ref13 === void 0 ? void 0 : _ref13.self) === null || _self2 === void 0 ? void 0 : _classPrivateFieldLooseBase(_self2.self, _x)[_x]; - (_o9 = o) === null || _o9 === void 0 ? void 0 : _classPrivateFieldLooseBase(_classPrivateFieldLooseBase(_o9.Foo, _self)[_self].getSelf(), _x)[_x]; - (_ref3 = (_o10 = o) === null || _o10 === void 0 ? void 0 : (_classPrivateFieldLoo = _classPrivateFieldLooseBase(_o10.Foo, _self)[_self]).getSelf) === null || _ref3 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref3.call(_classPrivateFieldLoo), _x)[_x]; - (_ref4 = (_o11 = o) === null || _o11 === void 0 ? void 0 : _classPrivateFieldLooseBase(_o11.Foo, _self)[_self]) === null || _ref4 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref4.getSelf(), _x)[_x]; - (_getSelf = (_ref14 = _ref5 = (_o12 = o) === null || _o12 === void 0 ? void 0 : _classPrivateFieldLooseBase(_o12.Foo, _self)[_self]) === null || _ref14 === void 0 ? void 0 : _ref14.getSelf) === null || _getSelf === void 0 ? void 0 : _classPrivateFieldLooseBase(_getSelf.call(_ref5), _x)[_x]; - (_ref6 = (_o13 = o) === null || _o13 === void 0 ? void 0 : _classPrivateFieldLooseBase(_o13.Foo, _self)[_self].getSelf()) === null || _ref6 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref6.self, _x)[_x]; - (_call = (_ref15 = (_o14 = o) === null || _o14 === void 0 ? void 0 : (_classPrivateFieldLoo2 = _classPrivateFieldLooseBase(_o14.Foo, _self)[_self]).getSelf) === null || _ref15 === void 0 ? void 0 : _ref15.call(_classPrivateFieldLoo2)) === null || _call === void 0 ? void 0 : _classPrivateFieldLooseBase(_call.self, _x)[_x]; - (_getSelf2 = (_ref16 = (_o15 = o) === null || _o15 === void 0 ? void 0 : _classPrivateFieldLooseBase(_o15.Foo, _self)[_self]) === null || _ref16 === void 0 ? void 0 : _ref16.getSelf()) === null || _getSelf2 === void 0 ? void 0 : _classPrivateFieldLooseBase(_getSelf2.self, _x)[_x]; - (_getSelf3 = (_ref17 = (_o16 = o) === null || _o16 === void 0 ? void 0 : _classPrivateFieldLooseBase(_o16.Foo, _self)[_self]) === null || _ref17 === void 0 ? void 0 : (_ref17$getSelf = _ref17.getSelf) === null || _ref17$getSelf === void 0 ? void 0 : _ref17$getSelf.call(_ref17)) === null || _getSelf3 === void 0 ? void 0 : _classPrivateFieldLooseBase(_getSelf3.self, _x)[_x]; - (_fn = fn) === null || _fn === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn().Foo, _x)[_x]; - (_fn2 = fn) === null || _fn2 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn2().Foo, _x)[_x].toString; - (_fn3 = fn) === null || _fn3 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn3().Foo, _x)[_x].toString(); + o === null || o === void 0 ? void 0 : _classPrivateFieldLooseBase(_classPrivateFieldLooseBase(o.Foo, _self)[_self], _x)[_x]; + o === null || o === void 0 ? void 0 : _classPrivateFieldLooseBase(_classPrivateFieldLooseBase(o.Foo, _self)[_self].self, _x)[_x]; + (_ref = o === null || o === void 0 ? void 0 : _classPrivateFieldLooseBase(o.Foo, _self)[_self]) === null || _ref === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref.self, _x)[_x]; + (_ref2 = o === null || o === void 0 ? void 0 : _classPrivateFieldLooseBase(o.Foo, _self)[_self].self) === null || _ref2 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref2.self, _x)[_x]; + (_self2 = (_ref13 = o === null || o === void 0 ? void 0 : _classPrivateFieldLooseBase(o.Foo, _self)[_self]) === null || _ref13 === void 0 ? void 0 : _ref13.self) === null || _self2 === void 0 ? void 0 : _classPrivateFieldLooseBase(_self2.self, _x)[_x]; + o === null || o === void 0 ? void 0 : _classPrivateFieldLooseBase(_classPrivateFieldLooseBase(o.Foo, _self)[_self].getSelf(), _x)[_x]; + (_ref3 = o === null || o === void 0 ? void 0 : (_classPrivateFieldLoo = _classPrivateFieldLooseBase(o.Foo, _self)[_self]).getSelf) === null || _ref3 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref3.call(_classPrivateFieldLoo), _x)[_x]; + (_ref4 = o === null || o === void 0 ? void 0 : _classPrivateFieldLooseBase(o.Foo, _self)[_self]) === null || _ref4 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref4.getSelf(), _x)[_x]; + (_getSelf = (_ref14 = _ref5 = o === null || o === void 0 ? void 0 : _classPrivateFieldLooseBase(o.Foo, _self)[_self]) === null || _ref14 === void 0 ? void 0 : _ref14.getSelf) === null || _getSelf === void 0 ? void 0 : _classPrivateFieldLooseBase(_getSelf.call(_ref5), _x)[_x]; + (_ref6 = o === null || o === void 0 ? void 0 : _classPrivateFieldLooseBase(o.Foo, _self)[_self].getSelf()) === null || _ref6 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref6.self, _x)[_x]; + (_call = (_ref15 = o === null || o === void 0 ? void 0 : (_classPrivateFieldLoo2 = _classPrivateFieldLooseBase(o.Foo, _self)[_self]).getSelf) === null || _ref15 === void 0 ? void 0 : _ref15.call(_classPrivateFieldLoo2)) === null || _call === void 0 ? void 0 : _classPrivateFieldLooseBase(_call.self, _x)[_x]; + (_getSelf2 = (_ref16 = o === null || o === void 0 ? void 0 : _classPrivateFieldLooseBase(o.Foo, _self)[_self]) === null || _ref16 === void 0 ? void 0 : _ref16.getSelf()) === null || _getSelf2 === void 0 ? void 0 : _classPrivateFieldLooseBase(_getSelf2.self, _x)[_x]; + (_getSelf3 = (_ref17 = o === null || o === void 0 ? void 0 : _classPrivateFieldLooseBase(o.Foo, _self)[_self]) === null || _ref17 === void 0 ? void 0 : (_ref17$getSelf = _ref17.getSelf) === null || _ref17$getSelf === void 0 ? void 0 : _ref17$getSelf.call(_ref17)) === null || _getSelf3 === void 0 ? void 0 : _classPrivateFieldLooseBase(_getSelf3.self, _x)[_x]; + fn === null || fn === void 0 ? void 0 : _classPrivateFieldLooseBase(fn().Foo, _x)[_x]; + fn === null || fn === void 0 ? void 0 : _classPrivateFieldLooseBase(fn().Foo, _x)[_x].toString; + fn === null || fn === void 0 ? void 0 : _classPrivateFieldLooseBase(fn().Foo, _x)[_x].toString(); (_fnDeep$very$o = fnDeep === null || fnDeep === void 0 ? void 0 : fnDeep().very.o) === null || _fnDeep$very$o === void 0 ? void 0 : _classPrivateFieldLooseBase(_fnDeep$very$o.Foo, _x)[_x]; (_fnDeep$very$o2 = fnDeep === null || fnDeep === void 0 ? void 0 : fnDeep().very.o) === null || _fnDeep$very$o2 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fnDeep$very$o2.Foo, _x)[_x].toString; (_fnDeep$very$o3 = fnDeep === null || fnDeep === void 0 ? void 0 : fnDeep().very.o) === null || _fnDeep$very$o3 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fnDeep$very$o3.Foo, _x)[_x].toString(); - (_fn4 = fn) === null || _fn4 === void 0 ? void 0 : _classPrivateFieldLooseBase(_classPrivateFieldLooseBase(_fn4().Foo, _self)[_self], _x)[_x]; - (_fn5 = fn) === null || _fn5 === void 0 ? void 0 : _classPrivateFieldLooseBase(_classPrivateFieldLooseBase(_fn5().Foo, _self)[_self].self, _x)[_x]; - (_ref7 = (_fn6 = fn) === null || _fn6 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn6().Foo, _self)[_self]) === null || _ref7 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref7.self, _x)[_x]; - (_ref8 = (_fn7 = fn) === null || _fn7 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn7().Foo, _self)[_self].self) === null || _ref8 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref8.self, _x)[_x]; - (_self3 = (_ref18 = (_fn8 = fn) === null || _fn8 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn8().Foo, _self)[_self]) === null || _ref18 === void 0 ? void 0 : _ref18.self) === null || _self3 === void 0 ? void 0 : _classPrivateFieldLooseBase(_self3.self, _x)[_x]; - (_fn9 = fn) === null || _fn9 === void 0 ? void 0 : _classPrivateFieldLooseBase(_classPrivateFieldLooseBase(_fn9().Foo, _self)[_self].getSelf(), _x)[_x]; - (_ref9 = (_fn10 = fn) === null || _fn10 === void 0 ? void 0 : (_classPrivateFieldLoo3 = _classPrivateFieldLooseBase(_fn10().Foo, _self)[_self]).getSelf) === null || _ref9 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref9.call(_classPrivateFieldLoo3), _x)[_x]; - (_ref10 = (_fn11 = fn) === null || _fn11 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn11().Foo, _self)[_self]) === null || _ref10 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref10.getSelf(), _x)[_x]; - (_getSelf4 = (_ref19 = _ref11 = (_fn12 = fn) === null || _fn12 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn12().Foo, _self)[_self]) === null || _ref19 === void 0 ? void 0 : _ref19.getSelf) === null || _getSelf4 === void 0 ? void 0 : _classPrivateFieldLooseBase(_getSelf4.call(_ref11), _x)[_x]; - (_ref12 = (_fn13 = fn) === null || _fn13 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn13().Foo, _self)[_self].getSelf()) === null || _ref12 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref12.self, _x)[_x]; - (_call2 = (_ref20 = (_fn14 = fn) === null || _fn14 === void 0 ? void 0 : (_classPrivateFieldLoo4 = _classPrivateFieldLooseBase(_fn14().Foo, _self)[_self]).getSelf) === null || _ref20 === void 0 ? void 0 : _ref20.call(_classPrivateFieldLoo4)) === null || _call2 === void 0 ? void 0 : _classPrivateFieldLooseBase(_call2.self, _x)[_x]; - (_getSelf5 = (_ref21 = (_fn15 = fn) === null || _fn15 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn15().Foo, _self)[_self]) === null || _ref21 === void 0 ? void 0 : _ref21.getSelf()) === null || _getSelf5 === void 0 ? void 0 : _classPrivateFieldLooseBase(_getSelf5.self, _x)[_x]; - (_getSelf6 = (_ref22 = (_fn16 = fn) === null || _fn16 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn16().Foo, _self)[_self]) === null || _ref22 === void 0 ? void 0 : (_ref22$getSelf = _ref22.getSelf) === null || _ref22$getSelf === void 0 ? void 0 : _ref22$getSelf.call(_ref22)) === null || _getSelf6 === void 0 ? void 0 : _classPrivateFieldLooseBase(_getSelf6.self, _x)[_x]; + fn === null || fn === void 0 ? void 0 : _classPrivateFieldLooseBase(_classPrivateFieldLooseBase(fn().Foo, _self)[_self], _x)[_x]; + fn === null || fn === void 0 ? void 0 : _classPrivateFieldLooseBase(_classPrivateFieldLooseBase(fn().Foo, _self)[_self].self, _x)[_x]; + (_ref7 = fn === null || fn === void 0 ? void 0 : _classPrivateFieldLooseBase(fn().Foo, _self)[_self]) === null || _ref7 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref7.self, _x)[_x]; + (_ref8 = fn === null || fn === void 0 ? void 0 : _classPrivateFieldLooseBase(fn().Foo, _self)[_self].self) === null || _ref8 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref8.self, _x)[_x]; + (_self3 = (_ref18 = fn === null || fn === void 0 ? void 0 : _classPrivateFieldLooseBase(fn().Foo, _self)[_self]) === null || _ref18 === void 0 ? void 0 : _ref18.self) === null || _self3 === void 0 ? void 0 : _classPrivateFieldLooseBase(_self3.self, _x)[_x]; + fn === null || fn === void 0 ? void 0 : _classPrivateFieldLooseBase(_classPrivateFieldLooseBase(fn().Foo, _self)[_self].getSelf(), _x)[_x]; + (_ref9 = fn === null || fn === void 0 ? void 0 : (_classPrivateFieldLoo3 = _classPrivateFieldLooseBase(fn().Foo, _self)[_self]).getSelf) === null || _ref9 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref9.call(_classPrivateFieldLoo3), _x)[_x]; + (_ref10 = fn === null || fn === void 0 ? void 0 : _classPrivateFieldLooseBase(fn().Foo, _self)[_self]) === null || _ref10 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref10.getSelf(), _x)[_x]; + (_getSelf4 = (_ref19 = _ref11 = fn === null || fn === void 0 ? void 0 : _classPrivateFieldLooseBase(fn().Foo, _self)[_self]) === null || _ref19 === void 0 ? void 0 : _ref19.getSelf) === null || _getSelf4 === void 0 ? void 0 : _classPrivateFieldLooseBase(_getSelf4.call(_ref11), _x)[_x]; + (_ref12 = fn === null || fn === void 0 ? void 0 : _classPrivateFieldLooseBase(fn().Foo, _self)[_self].getSelf()) === null || _ref12 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref12.self, _x)[_x]; + (_call2 = (_ref20 = fn === null || fn === void 0 ? void 0 : (_classPrivateFieldLoo4 = _classPrivateFieldLooseBase(fn().Foo, _self)[_self]).getSelf) === null || _ref20 === void 0 ? void 0 : _ref20.call(_classPrivateFieldLoo4)) === null || _call2 === void 0 ? void 0 : _classPrivateFieldLooseBase(_call2.self, _x)[_x]; + (_getSelf5 = (_ref21 = fn === null || fn === void 0 ? void 0 : _classPrivateFieldLooseBase(fn().Foo, _self)[_self]) === null || _ref21 === void 0 ? void 0 : _ref21.getSelf()) === null || _getSelf5 === void 0 ? void 0 : _classPrivateFieldLooseBase(_getSelf5.self, _x)[_x]; + (_getSelf6 = (_ref22 = fn === null || fn === void 0 ? void 0 : _classPrivateFieldLooseBase(fn().Foo, _self)[_self]) === null || _ref22 === void 0 ? void 0 : (_ref22$getSelf = _ref22.getSelf) === null || _ref22$getSelf === void 0 ? void 0 : _ref22$getSelf.call(_ref22)) === null || _getSelf6 === void 0 ? void 0 : _classPrivateFieldLooseBase(_getSelf6.self, _x)[_x]; } } diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain/output.js index 5b32ae955d9b..c79efa798a3e 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain/output.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain/output.js @@ -10,7 +10,7 @@ class Foo { } static test() { - var _o, _o2, _o3, _deep$very$o, _deep$very$o2, _deep$very$o3, _o4, _o5, _o6, _ref, _o7, _ref2, _o8, _self2, _o9, _o10, _classPrivateFieldLoo, _ref3, _o11, _ref4, _o12, _getSelf, _ref5, _o13, _ref6, _o14, _classPrivateFieldLoo2, _call, _o15, _getSelf2, _o16, _getSelf3, _fn, _fn2, _fn3, _fnDeep$very$o, _fnDeep$very$o2, _fnDeep$very$o3, _fn4, _fn5, _fn6, _ref7, _fn7, _ref8, _fn8, _self3, _fn9, _fn10, _classPrivateFieldLoo3, _ref9, _fn11, _ref10, _fn12, _getSelf4, _ref11, _fn13, _ref12, _fn14, _classPrivateFieldLoo4, _call2, _fn15, _getSelf5, _fn16, _getSelf6; + var _deep$very$o, _deep$very$o2, _deep$very$o3, _ref, _ref2, _self2, _classPrivateFieldLoo, _ref3, _ref4, _getSelf, _ref5, _ref6, _classPrivateFieldLoo2, _call, _getSelf2, _getSelf3, _fnDeep$very$o, _fnDeep$very$o2, _fnDeep$very$o3, _ref7, _ref8, _self3, _classPrivateFieldLoo3, _ref9, _ref10, _getSelf4, _ref11, _ref12, _classPrivateFieldLoo4, _call2, _getSelf5, _getSelf6; const o = { Foo: Foo @@ -29,44 +29,44 @@ class Foo { return deep; } - (_o = o) === null || _o === void 0 ? void 0 : _classPrivateFieldLooseBase(_o.Foo, _x)[_x]; - (_o2 = o) === null || _o2 === void 0 ? void 0 : _classPrivateFieldLooseBase(_o2.Foo, _x)[_x].toString; - (_o3 = o) === null || _o3 === void 0 ? void 0 : _classPrivateFieldLooseBase(_o3.Foo, _x)[_x].toString(); + o === null || o === void 0 ? void 0 : _classPrivateFieldLooseBase(o.Foo, _x)[_x]; + o === null || o === void 0 ? void 0 : _classPrivateFieldLooseBase(o.Foo, _x)[_x].toString; + o === null || o === void 0 ? void 0 : _classPrivateFieldLooseBase(o.Foo, _x)[_x].toString(); (_deep$very$o = deep?.very.o) === null || _deep$very$o === void 0 ? void 0 : _classPrivateFieldLooseBase(_deep$very$o.Foo, _x)[_x]; (_deep$very$o2 = deep?.very.o) === null || _deep$very$o2 === void 0 ? void 0 : _classPrivateFieldLooseBase(_deep$very$o2.Foo, _x)[_x].toString; (_deep$very$o3 = deep?.very.o) === null || _deep$very$o3 === void 0 ? void 0 : _classPrivateFieldLooseBase(_deep$very$o3.Foo, _x)[_x].toString(); - (_o4 = o) === null || _o4 === void 0 ? void 0 : _classPrivateFieldLooseBase(_classPrivateFieldLooseBase(_o4.Foo, _self)[_self], _x)[_x]; - (_o5 = o) === null || _o5 === void 0 ? void 0 : _classPrivateFieldLooseBase(_classPrivateFieldLooseBase(_o5.Foo, _self)[_self].self, _x)[_x]; - (_ref = (_o6 = o) === null || _o6 === void 0 ? void 0 : _classPrivateFieldLooseBase(_o6.Foo, _self)[_self]) === null || _ref === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref.self, _x)[_x]; - (_ref2 = (_o7 = o) === null || _o7 === void 0 ? void 0 : _classPrivateFieldLooseBase(_o7.Foo, _self)[_self].self) === null || _ref2 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref2.self, _x)[_x]; - (_self2 = ((_o8 = o) === null || _o8 === void 0 ? void 0 : _classPrivateFieldLooseBase(_o8.Foo, _self)[_self])?.self) === null || _self2 === void 0 ? void 0 : _classPrivateFieldLooseBase(_self2.self, _x)[_x]; - (_o9 = o) === null || _o9 === void 0 ? void 0 : _classPrivateFieldLooseBase(_classPrivateFieldLooseBase(_o9.Foo, _self)[_self].getSelf(), _x)[_x]; - (_ref3 = (_o10 = o) === null || _o10 === void 0 ? void 0 : (_classPrivateFieldLoo = _classPrivateFieldLooseBase(_o10.Foo, _self)[_self]).getSelf) === null || _ref3 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref3.call(_classPrivateFieldLoo), _x)[_x]; - (_ref4 = (_o11 = o) === null || _o11 === void 0 ? void 0 : _classPrivateFieldLooseBase(_o11.Foo, _self)[_self]) === null || _ref4 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref4.getSelf(), _x)[_x]; - (_getSelf = (_ref5 = (_o12 = o) === null || _o12 === void 0 ? void 0 : _classPrivateFieldLooseBase(_o12.Foo, _self)[_self])?.getSelf) === null || _getSelf === void 0 ? void 0 : _classPrivateFieldLooseBase(_getSelf.call(_ref5), _x)[_x]; - (_ref6 = (_o13 = o) === null || _o13 === void 0 ? void 0 : _classPrivateFieldLooseBase(_o13.Foo, _self)[_self].getSelf()) === null || _ref6 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref6.self, _x)[_x]; - (_call = ((_o14 = o) === null || _o14 === void 0 ? void 0 : (_classPrivateFieldLoo2 = _classPrivateFieldLooseBase(_o14.Foo, _self)[_self]).getSelf)?.call(_classPrivateFieldLoo2)) === null || _call === void 0 ? void 0 : _classPrivateFieldLooseBase(_call.self, _x)[_x]; - (_getSelf2 = ((_o15 = o) === null || _o15 === void 0 ? void 0 : _classPrivateFieldLooseBase(_o15.Foo, _self)[_self])?.getSelf()) === null || _getSelf2 === void 0 ? void 0 : _classPrivateFieldLooseBase(_getSelf2.self, _x)[_x]; - (_getSelf3 = ((_o16 = o) === null || _o16 === void 0 ? void 0 : _classPrivateFieldLooseBase(_o16.Foo, _self)[_self])?.getSelf?.()) === null || _getSelf3 === void 0 ? void 0 : _classPrivateFieldLooseBase(_getSelf3.self, _x)[_x]; - (_fn = fn) === null || _fn === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn().Foo, _x)[_x]; - (_fn2 = fn) === null || _fn2 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn2().Foo, _x)[_x].toString; - (_fn3 = fn) === null || _fn3 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn3().Foo, _x)[_x].toString(); + o === null || o === void 0 ? void 0 : _classPrivateFieldLooseBase(_classPrivateFieldLooseBase(o.Foo, _self)[_self], _x)[_x]; + o === null || o === void 0 ? void 0 : _classPrivateFieldLooseBase(_classPrivateFieldLooseBase(o.Foo, _self)[_self].self, _x)[_x]; + (_ref = o === null || o === void 0 ? void 0 : _classPrivateFieldLooseBase(o.Foo, _self)[_self]) === null || _ref === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref.self, _x)[_x]; + (_ref2 = o === null || o === void 0 ? void 0 : _classPrivateFieldLooseBase(o.Foo, _self)[_self].self) === null || _ref2 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref2.self, _x)[_x]; + (_self2 = (o === null || o === void 0 ? void 0 : _classPrivateFieldLooseBase(o.Foo, _self)[_self])?.self) === null || _self2 === void 0 ? void 0 : _classPrivateFieldLooseBase(_self2.self, _x)[_x]; + o === null || o === void 0 ? void 0 : _classPrivateFieldLooseBase(_classPrivateFieldLooseBase(o.Foo, _self)[_self].getSelf(), _x)[_x]; + (_ref3 = o === null || o === void 0 ? void 0 : (_classPrivateFieldLoo = _classPrivateFieldLooseBase(o.Foo, _self)[_self]).getSelf) === null || _ref3 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref3.call(_classPrivateFieldLoo), _x)[_x]; + (_ref4 = o === null || o === void 0 ? void 0 : _classPrivateFieldLooseBase(o.Foo, _self)[_self]) === null || _ref4 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref4.getSelf(), _x)[_x]; + (_getSelf = (_ref5 = o === null || o === void 0 ? void 0 : _classPrivateFieldLooseBase(o.Foo, _self)[_self])?.getSelf) === null || _getSelf === void 0 ? void 0 : _classPrivateFieldLooseBase(_getSelf.call(_ref5), _x)[_x]; + (_ref6 = o === null || o === void 0 ? void 0 : _classPrivateFieldLooseBase(o.Foo, _self)[_self].getSelf()) === null || _ref6 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref6.self, _x)[_x]; + (_call = (o === null || o === void 0 ? void 0 : (_classPrivateFieldLoo2 = _classPrivateFieldLooseBase(o.Foo, _self)[_self]).getSelf)?.call(_classPrivateFieldLoo2)) === null || _call === void 0 ? void 0 : _classPrivateFieldLooseBase(_call.self, _x)[_x]; + (_getSelf2 = (o === null || o === void 0 ? void 0 : _classPrivateFieldLooseBase(o.Foo, _self)[_self])?.getSelf()) === null || _getSelf2 === void 0 ? void 0 : _classPrivateFieldLooseBase(_getSelf2.self, _x)[_x]; + (_getSelf3 = (o === null || o === void 0 ? void 0 : _classPrivateFieldLooseBase(o.Foo, _self)[_self])?.getSelf?.()) === null || _getSelf3 === void 0 ? void 0 : _classPrivateFieldLooseBase(_getSelf3.self, _x)[_x]; + fn === null || fn === void 0 ? void 0 : _classPrivateFieldLooseBase(fn().Foo, _x)[_x]; + fn === null || fn === void 0 ? void 0 : _classPrivateFieldLooseBase(fn().Foo, _x)[_x].toString; + fn === null || fn === void 0 ? void 0 : _classPrivateFieldLooseBase(fn().Foo, _x)[_x].toString(); (_fnDeep$very$o = fnDeep?.().very.o) === null || _fnDeep$very$o === void 0 ? void 0 : _classPrivateFieldLooseBase(_fnDeep$very$o.Foo, _x)[_x]; (_fnDeep$very$o2 = fnDeep?.().very.o) === null || _fnDeep$very$o2 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fnDeep$very$o2.Foo, _x)[_x].toString; (_fnDeep$very$o3 = fnDeep?.().very.o) === null || _fnDeep$very$o3 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fnDeep$very$o3.Foo, _x)[_x].toString(); - (_fn4 = fn) === null || _fn4 === void 0 ? void 0 : _classPrivateFieldLooseBase(_classPrivateFieldLooseBase(_fn4().Foo, _self)[_self], _x)[_x]; - (_fn5 = fn) === null || _fn5 === void 0 ? void 0 : _classPrivateFieldLooseBase(_classPrivateFieldLooseBase(_fn5().Foo, _self)[_self].self, _x)[_x]; - (_ref7 = (_fn6 = fn) === null || _fn6 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn6().Foo, _self)[_self]) === null || _ref7 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref7.self, _x)[_x]; - (_ref8 = (_fn7 = fn) === null || _fn7 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn7().Foo, _self)[_self].self) === null || _ref8 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref8.self, _x)[_x]; - (_self3 = ((_fn8 = fn) === null || _fn8 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn8().Foo, _self)[_self])?.self) === null || _self3 === void 0 ? void 0 : _classPrivateFieldLooseBase(_self3.self, _x)[_x]; - (_fn9 = fn) === null || _fn9 === void 0 ? void 0 : _classPrivateFieldLooseBase(_classPrivateFieldLooseBase(_fn9().Foo, _self)[_self].getSelf(), _x)[_x]; - (_ref9 = (_fn10 = fn) === null || _fn10 === void 0 ? void 0 : (_classPrivateFieldLoo3 = _classPrivateFieldLooseBase(_fn10().Foo, _self)[_self]).getSelf) === null || _ref9 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref9.call(_classPrivateFieldLoo3), _x)[_x]; - (_ref10 = (_fn11 = fn) === null || _fn11 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn11().Foo, _self)[_self]) === null || _ref10 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref10.getSelf(), _x)[_x]; - (_getSelf4 = (_ref11 = (_fn12 = fn) === null || _fn12 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn12().Foo, _self)[_self])?.getSelf) === null || _getSelf4 === void 0 ? void 0 : _classPrivateFieldLooseBase(_getSelf4.call(_ref11), _x)[_x]; - (_ref12 = (_fn13 = fn) === null || _fn13 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn13().Foo, _self)[_self].getSelf()) === null || _ref12 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref12.self, _x)[_x]; - (_call2 = ((_fn14 = fn) === null || _fn14 === void 0 ? void 0 : (_classPrivateFieldLoo4 = _classPrivateFieldLooseBase(_fn14().Foo, _self)[_self]).getSelf)?.call(_classPrivateFieldLoo4)) === null || _call2 === void 0 ? void 0 : _classPrivateFieldLooseBase(_call2.self, _x)[_x]; - (_getSelf5 = ((_fn15 = fn) === null || _fn15 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn15().Foo, _self)[_self])?.getSelf()) === null || _getSelf5 === void 0 ? void 0 : _classPrivateFieldLooseBase(_getSelf5.self, _x)[_x]; - (_getSelf6 = ((_fn16 = fn) === null || _fn16 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn16().Foo, _self)[_self])?.getSelf?.()) === null || _getSelf6 === void 0 ? void 0 : _classPrivateFieldLooseBase(_getSelf6.self, _x)[_x]; + fn === null || fn === void 0 ? void 0 : _classPrivateFieldLooseBase(_classPrivateFieldLooseBase(fn().Foo, _self)[_self], _x)[_x]; + fn === null || fn === void 0 ? void 0 : _classPrivateFieldLooseBase(_classPrivateFieldLooseBase(fn().Foo, _self)[_self].self, _x)[_x]; + (_ref7 = fn === null || fn === void 0 ? void 0 : _classPrivateFieldLooseBase(fn().Foo, _self)[_self]) === null || _ref7 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref7.self, _x)[_x]; + (_ref8 = fn === null || fn === void 0 ? void 0 : _classPrivateFieldLooseBase(fn().Foo, _self)[_self].self) === null || _ref8 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref8.self, _x)[_x]; + (_self3 = (fn === null || fn === void 0 ? void 0 : _classPrivateFieldLooseBase(fn().Foo, _self)[_self])?.self) === null || _self3 === void 0 ? void 0 : _classPrivateFieldLooseBase(_self3.self, _x)[_x]; + fn === null || fn === void 0 ? void 0 : _classPrivateFieldLooseBase(_classPrivateFieldLooseBase(fn().Foo, _self)[_self].getSelf(), _x)[_x]; + (_ref9 = fn === null || fn === void 0 ? void 0 : (_classPrivateFieldLoo3 = _classPrivateFieldLooseBase(fn().Foo, _self)[_self]).getSelf) === null || _ref9 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref9.call(_classPrivateFieldLoo3), _x)[_x]; + (_ref10 = fn === null || fn === void 0 ? void 0 : _classPrivateFieldLooseBase(fn().Foo, _self)[_self]) === null || _ref10 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref10.getSelf(), _x)[_x]; + (_getSelf4 = (_ref11 = fn === null || fn === void 0 ? void 0 : _classPrivateFieldLooseBase(fn().Foo, _self)[_self])?.getSelf) === null || _getSelf4 === void 0 ? void 0 : _classPrivateFieldLooseBase(_getSelf4.call(_ref11), _x)[_x]; + (_ref12 = fn === null || fn === void 0 ? void 0 : _classPrivateFieldLooseBase(fn().Foo, _self)[_self].getSelf()) === null || _ref12 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref12.self, _x)[_x]; + (_call2 = (fn === null || fn === void 0 ? void 0 : (_classPrivateFieldLoo4 = _classPrivateFieldLooseBase(fn().Foo, _self)[_self]).getSelf)?.call(_classPrivateFieldLoo4)) === null || _call2 === void 0 ? void 0 : _classPrivateFieldLooseBase(_call2.self, _x)[_x]; + (_getSelf5 = (fn === null || fn === void 0 ? void 0 : _classPrivateFieldLooseBase(fn().Foo, _self)[_self])?.getSelf()) === null || _getSelf5 === void 0 ? void 0 : _classPrivateFieldLooseBase(_getSelf5.self, _x)[_x]; + (_getSelf6 = (fn === null || fn === void 0 ? void 0 : _classPrivateFieldLooseBase(fn().Foo, _self)[_self])?.getSelf?.()) === null || _getSelf6 === void 0 ? void 0 : _classPrivateFieldLooseBase(_getSelf6.self, _x)[_x]; } } diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-before-member-call-with-transform/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-before-member-call-with-transform/output.js index 79eb53816731..e754115aea72 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-before-member-call-with-transform/output.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-before-member-call-with-transform/output.js @@ -8,7 +8,7 @@ class Foo { } static test() { - var _o, _o$Foo, _o2, _o2$Foo, _o3, _o3$Foo, _deep$very$o, _deep$very$o$Foo, _deep$very$o2, _deep$very$o2$Foo, _deep$very$o3, _deep$very$o3$Foo, _o4, _classStaticPrivateFi, _o5, _classStaticPrivateFi2, _o6, _ref, _ref$self, _o7, _ref2, _ref2$self, _o8, _self2, _self2$self, _o9, _classStaticPrivateFi3, _o10, _classStaticPrivateFi4, _ref3, _ref3$call, _o11, _ref4, _ref4$getSelf, _o12, _getSelf, _ref5, _getSelf$call, _o13, _ref6, _ref6$self, _o14, _classStaticPrivateFi5, _call, _call$self, _o15, _getSelf2, _getSelf2$self, _o16, _getSelf3, _getSelf3$self, _fn, _fn$Foo, _fn2, _fn2$Foo, _fn3, _fn3$Foo, _fnDeep$very$o, _fnDeep$very$o$Foo, _fnDeep$very$o2, _fnDeep$very$o2$Foo, _fnDeep$very$o3, _fnDeep$very$o3$Foo, _fn4, _classStaticPrivateFi6, _fn5, _classStaticPrivateFi7, _fn6, _ref7, _ref7$self, _fn7, _ref8, _ref8$self, _fn8, _self3, _self3$self, _fn9, _classStaticPrivateFi8, _fn10, _classStaticPrivateFi9, _ref9, _ref9$call, _fn11, _ref10, _ref10$getSelf, _fn12, _getSelf4, _ref11, _getSelf4$call, _fn13, _ref12, _ref12$self, _fn14, _classStaticPrivateFi10, _call2, _call2$self, _fn15, _getSelf5, _getSelf5$self, _fn16, _getSelf6, _getSelf6$self, _ref13, _ref14, _ref15, _ref16, _ref17, _ref17$getSelf, _ref18, _ref19, _ref20, _ref21, _ref22, _ref22$getSelf; + var _o$Foo, _o$Foo2, _o$Foo3, _deep$very$o, _deep$very$o$Foo, _deep$very$o2, _deep$very$o2$Foo, _deep$very$o3, _deep$very$o3$Foo, _classStaticPrivateFi, _classStaticPrivateFi2, _ref, _ref$self, _ref2, _ref2$self, _self2, _self2$self, _classStaticPrivateFi3, _classStaticPrivateFi4, _ref3, _ref3$call, _ref4, _ref4$getSelf, _getSelf, _ref5, _getSelf$call, _ref6, _ref6$self, _classStaticPrivateFi5, _call, _call$self, _getSelf2, _getSelf2$self, _getSelf3, _getSelf3$self, _fn$Foo, _fn$Foo2, _fn$Foo3, _fnDeep$very$o, _fnDeep$very$o$Foo, _fnDeep$very$o2, _fnDeep$very$o2$Foo, _fnDeep$very$o3, _fnDeep$very$o3$Foo, _classStaticPrivateFi6, _classStaticPrivateFi7, _ref7, _ref7$self, _ref8, _ref8$self, _self3, _self3$self, _classStaticPrivateFi8, _classStaticPrivateFi9, _ref9, _ref9$call, _ref10, _ref10$getSelf, _getSelf4, _ref11, _getSelf4$call, _ref12, _ref12$self, _classStaticPrivateFi10, _call2, _call2$self, _getSelf5, _getSelf5$self, _getSelf6, _getSelf6$self, _ref13, _ref14, _ref15, _ref16, _ref17, _ref17$getSelf, _ref18, _ref19, _ref20, _ref21, _ref22, _ref22$getSelf; const o = { Foo: Foo @@ -27,44 +27,44 @@ class Foo { return deep; } - (_o = o) === null || _o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o$Foo = _o.Foo, Foo, _m).call(_o$Foo); - (_o2 = o) === null || _o2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o2$Foo = _o2.Foo, Foo, _m).call(_o2$Foo).toString; - (_o3 = o) === null || _o3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o3$Foo = _o3.Foo, Foo, _m).call(_o3$Foo).toString(); + o === null || o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o$Foo = o.Foo, Foo, _m).call(_o$Foo); + o === null || o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o$Foo2 = o.Foo, Foo, _m).call(_o$Foo2).toString; + o === null || o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o$Foo3 = o.Foo, Foo, _m).call(_o$Foo3).toString(); (_deep$very$o = deep === null || deep === void 0 ? void 0 : deep.very.o) === null || _deep$very$o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_deep$very$o$Foo = _deep$very$o.Foo, Foo, _m).call(_deep$very$o$Foo); (_deep$very$o2 = deep === null || deep === void 0 ? void 0 : deep.very.o) === null || _deep$very$o2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_deep$very$o2$Foo = _deep$very$o2.Foo, Foo, _m).call(_deep$very$o2$Foo).toString; (_deep$very$o3 = deep === null || deep === void 0 ? void 0 : deep.very.o) === null || _deep$very$o3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_deep$very$o3$Foo = _deep$very$o3.Foo, Foo, _m).call(_deep$very$o3$Foo).toString(); - (_o4 = o) === null || _o4 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFi = _classStaticPrivateFieldSpecGet(_o4.Foo, Foo, _self), Foo, _m).call(_classStaticPrivateFi); - (_o5 = o) === null || _o5 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFi2 = _classStaticPrivateFieldSpecGet(_o5.Foo, Foo, _self).self, Foo, _m).call(_classStaticPrivateFi2); - (_ref = (_o6 = o) === null || _o6 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o6.Foo, Foo, _self)) === null || _ref === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref$self = _ref.self, Foo, _m).call(_ref$self); - (_ref2 = (_o7 = o) === null || _o7 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o7.Foo, Foo, _self).self) === null || _ref2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref2$self = _ref2.self, Foo, _m).call(_ref2$self); - (_self2 = (_ref13 = (_o8 = o) === null || _o8 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o8.Foo, Foo, _self)) === null || _ref13 === void 0 ? void 0 : _ref13.self) === null || _self2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_self2$self = _self2.self, Foo, _m).call(_self2$self); - (_o9 = o) === null || _o9 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFi3 = _classStaticPrivateFieldSpecGet(_o9.Foo, Foo, _self).getSelf(), Foo, _m).call(_classStaticPrivateFi3); - (_ref3 = (_o10 = o) === null || _o10 === void 0 ? void 0 : (_classStaticPrivateFi4 = _classStaticPrivateFieldSpecGet(_o10.Foo, Foo, _self)).getSelf) === null || _ref3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref3$call = _ref3.call(_classStaticPrivateFi4), Foo, _m).call(_ref3$call); - (_ref4 = (_o11 = o) === null || _o11 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o11.Foo, Foo, _self)) === null || _ref4 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref4$getSelf = _ref4.getSelf(), Foo, _m).call(_ref4$getSelf); - (_getSelf = (_ref14 = _ref5 = (_o12 = o) === null || _o12 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o12.Foo, Foo, _self)) === null || _ref14 === void 0 ? void 0 : _ref14.getSelf) === null || _getSelf === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_getSelf$call = _getSelf.call(_ref5), Foo, _m).call(_getSelf$call); - (_ref6 = (_o13 = o) === null || _o13 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o13.Foo, Foo, _self).getSelf()) === null || _ref6 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref6$self = _ref6.self, Foo, _m).call(_ref6$self); - (_call = (_ref15 = (_o14 = o) === null || _o14 === void 0 ? void 0 : (_classStaticPrivateFi5 = _classStaticPrivateFieldSpecGet(_o14.Foo, Foo, _self)).getSelf) === null || _ref15 === void 0 ? void 0 : _ref15.call(_classStaticPrivateFi5)) === null || _call === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_call$self = _call.self, Foo, _m).call(_call$self); - (_getSelf2 = (_ref16 = (_o15 = o) === null || _o15 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o15.Foo, Foo, _self)) === null || _ref16 === void 0 ? void 0 : _ref16.getSelf()) === null || _getSelf2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_getSelf2$self = _getSelf2.self, Foo, _m).call(_getSelf2$self); - (_getSelf3 = (_ref17 = (_o16 = o) === null || _o16 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o16.Foo, Foo, _self)) === null || _ref17 === void 0 ? void 0 : (_ref17$getSelf = _ref17.getSelf) === null || _ref17$getSelf === void 0 ? void 0 : _ref17$getSelf.call(_ref17)) === null || _getSelf3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_getSelf3$self = _getSelf3.self, Foo, _m).call(_getSelf3$self); - (_fn = fn) === null || _fn === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn$Foo = _fn().Foo, Foo, _m).call(_fn$Foo); - (_fn2 = fn) === null || _fn2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn2$Foo = _fn2().Foo, Foo, _m).call(_fn2$Foo).toString; - (_fn3 = fn) === null || _fn3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn3$Foo = _fn3().Foo, Foo, _m).call(_fn3$Foo).toString(); + o === null || o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFi = _classStaticPrivateFieldSpecGet(o.Foo, Foo, _self), Foo, _m).call(_classStaticPrivateFi); + o === null || o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFi2 = _classStaticPrivateFieldSpecGet(o.Foo, Foo, _self).self, Foo, _m).call(_classStaticPrivateFi2); + (_ref = o === null || o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(o.Foo, Foo, _self)) === null || _ref === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref$self = _ref.self, Foo, _m).call(_ref$self); + (_ref2 = o === null || o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(o.Foo, Foo, _self).self) === null || _ref2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref2$self = _ref2.self, Foo, _m).call(_ref2$self); + (_self2 = (_ref13 = o === null || o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(o.Foo, Foo, _self)) === null || _ref13 === void 0 ? void 0 : _ref13.self) === null || _self2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_self2$self = _self2.self, Foo, _m).call(_self2$self); + o === null || o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFi3 = _classStaticPrivateFieldSpecGet(o.Foo, Foo, _self).getSelf(), Foo, _m).call(_classStaticPrivateFi3); + (_ref3 = o === null || o === void 0 ? void 0 : (_classStaticPrivateFi4 = _classStaticPrivateFieldSpecGet(o.Foo, Foo, _self)).getSelf) === null || _ref3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref3$call = _ref3.call(_classStaticPrivateFi4), Foo, _m).call(_ref3$call); + (_ref4 = o === null || o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(o.Foo, Foo, _self)) === null || _ref4 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref4$getSelf = _ref4.getSelf(), Foo, _m).call(_ref4$getSelf); + (_getSelf = (_ref14 = _ref5 = o === null || o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(o.Foo, Foo, _self)) === null || _ref14 === void 0 ? void 0 : _ref14.getSelf) === null || _getSelf === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_getSelf$call = _getSelf.call(_ref5), Foo, _m).call(_getSelf$call); + (_ref6 = o === null || o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(o.Foo, Foo, _self).getSelf()) === null || _ref6 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref6$self = _ref6.self, Foo, _m).call(_ref6$self); + (_call = (_ref15 = o === null || o === void 0 ? void 0 : (_classStaticPrivateFi5 = _classStaticPrivateFieldSpecGet(o.Foo, Foo, _self)).getSelf) === null || _ref15 === void 0 ? void 0 : _ref15.call(_classStaticPrivateFi5)) === null || _call === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_call$self = _call.self, Foo, _m).call(_call$self); + (_getSelf2 = (_ref16 = o === null || o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(o.Foo, Foo, _self)) === null || _ref16 === void 0 ? void 0 : _ref16.getSelf()) === null || _getSelf2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_getSelf2$self = _getSelf2.self, Foo, _m).call(_getSelf2$self); + (_getSelf3 = (_ref17 = o === null || o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(o.Foo, Foo, _self)) === null || _ref17 === void 0 ? void 0 : (_ref17$getSelf = _ref17.getSelf) === null || _ref17$getSelf === void 0 ? void 0 : _ref17$getSelf.call(_ref17)) === null || _getSelf3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_getSelf3$self = _getSelf3.self, Foo, _m).call(_getSelf3$self); + fn === null || fn === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn$Foo = fn().Foo, Foo, _m).call(_fn$Foo); + fn === null || fn === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn$Foo2 = fn().Foo, Foo, _m).call(_fn$Foo2).toString; + fn === null || fn === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn$Foo3 = fn().Foo, Foo, _m).call(_fn$Foo3).toString(); (_fnDeep$very$o = fnDeep === null || fnDeep === void 0 ? void 0 : fnDeep().very.o) === null || _fnDeep$very$o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fnDeep$very$o$Foo = _fnDeep$very$o.Foo, Foo, _m).call(_fnDeep$very$o$Foo); (_fnDeep$very$o2 = fnDeep === null || fnDeep === void 0 ? void 0 : fnDeep().very.o) === null || _fnDeep$very$o2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fnDeep$very$o2$Foo = _fnDeep$very$o2.Foo, Foo, _m).call(_fnDeep$very$o2$Foo).toString; (_fnDeep$very$o3 = fnDeep === null || fnDeep === void 0 ? void 0 : fnDeep().very.o) === null || _fnDeep$very$o3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fnDeep$very$o3$Foo = _fnDeep$very$o3.Foo, Foo, _m).call(_fnDeep$very$o3$Foo).toString(); - (_fn4 = fn) === null || _fn4 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFi6 = _classStaticPrivateFieldSpecGet(_fn4().Foo, Foo, _self), Foo, _m).call(_classStaticPrivateFi6); - (_fn5 = fn) === null || _fn5 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFi7 = _classStaticPrivateFieldSpecGet(_fn5().Foo, Foo, _self).self, Foo, _m).call(_classStaticPrivateFi7); - (_ref7 = (_fn6 = fn) === null || _fn6 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn6().Foo, Foo, _self)) === null || _ref7 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref7$self = _ref7.self, Foo, _m).call(_ref7$self); - (_ref8 = (_fn7 = fn) === null || _fn7 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn7().Foo, Foo, _self).self) === null || _ref8 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref8$self = _ref8.self, Foo, _m).call(_ref8$self); - (_self3 = (_ref18 = (_fn8 = fn) === null || _fn8 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn8().Foo, Foo, _self)) === null || _ref18 === void 0 ? void 0 : _ref18.self) === null || _self3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_self3$self = _self3.self, Foo, _m).call(_self3$self); - (_fn9 = fn) === null || _fn9 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFi8 = _classStaticPrivateFieldSpecGet(_fn9().Foo, Foo, _self).getSelf(), Foo, _m).call(_classStaticPrivateFi8); - (_ref9 = (_fn10 = fn) === null || _fn10 === void 0 ? void 0 : (_classStaticPrivateFi9 = _classStaticPrivateFieldSpecGet(_fn10().Foo, Foo, _self)).getSelf) === null || _ref9 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref9$call = _ref9.call(_classStaticPrivateFi9), Foo, _m).call(_ref9$call); - (_ref10 = (_fn11 = fn) === null || _fn11 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn11().Foo, Foo, _self)) === null || _ref10 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref10$getSelf = _ref10.getSelf(), Foo, _m).call(_ref10$getSelf); - (_getSelf4 = (_ref19 = _ref11 = (_fn12 = fn) === null || _fn12 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn12().Foo, Foo, _self)) === null || _ref19 === void 0 ? void 0 : _ref19.getSelf) === null || _getSelf4 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_getSelf4$call = _getSelf4.call(_ref11), Foo, _m).call(_getSelf4$call); - (_ref12 = (_fn13 = fn) === null || _fn13 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn13().Foo, Foo, _self).getSelf()) === null || _ref12 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref12$self = _ref12.self, Foo, _m).call(_ref12$self); - (_call2 = (_ref20 = (_fn14 = fn) === null || _fn14 === void 0 ? void 0 : (_classStaticPrivateFi10 = _classStaticPrivateFieldSpecGet(_fn14().Foo, Foo, _self)).getSelf) === null || _ref20 === void 0 ? void 0 : _ref20.call(_classStaticPrivateFi10)) === null || _call2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_call2$self = _call2.self, Foo, _m).call(_call2$self); - (_getSelf5 = (_ref21 = (_fn15 = fn) === null || _fn15 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn15().Foo, Foo, _self)) === null || _ref21 === void 0 ? void 0 : _ref21.getSelf()) === null || _getSelf5 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_getSelf5$self = _getSelf5.self, Foo, _m).call(_getSelf5$self); - (_getSelf6 = (_ref22 = (_fn16 = fn) === null || _fn16 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn16().Foo, Foo, _self)) === null || _ref22 === void 0 ? void 0 : (_ref22$getSelf = _ref22.getSelf) === null || _ref22$getSelf === void 0 ? void 0 : _ref22$getSelf.call(_ref22)) === null || _getSelf6 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_getSelf6$self = _getSelf6.self, Foo, _m).call(_getSelf6$self); + fn === null || fn === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFi6 = _classStaticPrivateFieldSpecGet(fn().Foo, Foo, _self), Foo, _m).call(_classStaticPrivateFi6); + fn === null || fn === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFi7 = _classStaticPrivateFieldSpecGet(fn().Foo, Foo, _self).self, Foo, _m).call(_classStaticPrivateFi7); + (_ref7 = fn === null || fn === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(fn().Foo, Foo, _self)) === null || _ref7 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref7$self = _ref7.self, Foo, _m).call(_ref7$self); + (_ref8 = fn === null || fn === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(fn().Foo, Foo, _self).self) === null || _ref8 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref8$self = _ref8.self, Foo, _m).call(_ref8$self); + (_self3 = (_ref18 = fn === null || fn === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(fn().Foo, Foo, _self)) === null || _ref18 === void 0 ? void 0 : _ref18.self) === null || _self3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_self3$self = _self3.self, Foo, _m).call(_self3$self); + fn === null || fn === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFi8 = _classStaticPrivateFieldSpecGet(fn().Foo, Foo, _self).getSelf(), Foo, _m).call(_classStaticPrivateFi8); + (_ref9 = fn === null || fn === void 0 ? void 0 : (_classStaticPrivateFi9 = _classStaticPrivateFieldSpecGet(fn().Foo, Foo, _self)).getSelf) === null || _ref9 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref9$call = _ref9.call(_classStaticPrivateFi9), Foo, _m).call(_ref9$call); + (_ref10 = fn === null || fn === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(fn().Foo, Foo, _self)) === null || _ref10 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref10$getSelf = _ref10.getSelf(), Foo, _m).call(_ref10$getSelf); + (_getSelf4 = (_ref19 = _ref11 = fn === null || fn === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(fn().Foo, Foo, _self)) === null || _ref19 === void 0 ? void 0 : _ref19.getSelf) === null || _getSelf4 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_getSelf4$call = _getSelf4.call(_ref11), Foo, _m).call(_getSelf4$call); + (_ref12 = fn === null || fn === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(fn().Foo, Foo, _self).getSelf()) === null || _ref12 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref12$self = _ref12.self, Foo, _m).call(_ref12$self); + (_call2 = (_ref20 = fn === null || fn === void 0 ? void 0 : (_classStaticPrivateFi10 = _classStaticPrivateFieldSpecGet(fn().Foo, Foo, _self)).getSelf) === null || _ref20 === void 0 ? void 0 : _ref20.call(_classStaticPrivateFi10)) === null || _call2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_call2$self = _call2.self, Foo, _m).call(_call2$self); + (_getSelf5 = (_ref21 = fn === null || fn === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(fn().Foo, Foo, _self)) === null || _ref21 === void 0 ? void 0 : _ref21.getSelf()) === null || _getSelf5 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_getSelf5$self = _getSelf5.self, Foo, _m).call(_getSelf5$self); + (_getSelf6 = (_ref22 = fn === null || fn === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(fn().Foo, Foo, _self)) === null || _ref22 === void 0 ? void 0 : (_ref22$getSelf = _ref22.getSelf) === null || _ref22$getSelf === void 0 ? void 0 : _ref22$getSelf.call(_ref22)) === null || _getSelf6 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_getSelf6$self = _getSelf6.self, Foo, _m).call(_getSelf6$self); } } diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-before-member-call/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-before-member-call/output.js index ccce528eeb79..f3282ff89c62 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-before-member-call/output.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-before-member-call/output.js @@ -8,7 +8,7 @@ class Foo { } static test() { - var _o, _o$Foo, _o2, _o2$Foo, _o3, _o3$Foo, _deep$very$o, _deep$very$o$Foo, _deep$very$o2, _deep$very$o2$Foo, _deep$very$o3, _deep$very$o3$Foo, _o4, _classStaticPrivateFi, _o5, _classStaticPrivateFi2, _o6, _ref, _ref$self, _o7, _ref2, _ref2$self, _o8, _self2, _self2$self, _o9, _classStaticPrivateFi3, _o10, _classStaticPrivateFi4, _ref3, _ref3$call, _o11, _ref4, _ref4$getSelf, _o12, _getSelf, _ref5, _getSelf$call, _o13, _ref6, _ref6$self, _o14, _classStaticPrivateFi5, _call, _call$self, _o15, _getSelf2, _getSelf2$self, _o16, _getSelf3, _getSelf3$self, _fn, _fn$Foo, _fn2, _fn2$Foo, _fn3, _fn3$Foo, _fnDeep$very$o, _fnDeep$very$o$Foo, _fnDeep$very$o2, _fnDeep$very$o2$Foo, _fnDeep$very$o3, _fnDeep$very$o3$Foo, _fn4, _classStaticPrivateFi6, _fn5, _classStaticPrivateFi7, _fn6, _ref7, _ref7$self, _fn7, _ref8, _ref8$self, _fn8, _self3, _self3$self, _fn9, _classStaticPrivateFi8, _fn10, _classStaticPrivateFi9, _ref9, _ref9$call, _fn11, _ref10, _ref10$getSelf, _fn12, _getSelf4, _ref11, _getSelf4$call, _fn13, _ref12, _ref12$self, _fn14, _classStaticPrivateFi10, _call2, _call2$self, _fn15, _getSelf5, _getSelf5$self, _fn16, _getSelf6, _getSelf6$self; + var _o$Foo, _o$Foo2, _o$Foo3, _deep$very$o, _deep$very$o$Foo, _deep$very$o2, _deep$very$o2$Foo, _deep$very$o3, _deep$very$o3$Foo, _classStaticPrivateFi, _classStaticPrivateFi2, _ref, _ref$self, _ref2, _ref2$self, _self2, _self2$self, _classStaticPrivateFi3, _classStaticPrivateFi4, _ref3, _ref3$call, _ref4, _ref4$getSelf, _getSelf, _ref5, _getSelf$call, _ref6, _ref6$self, _classStaticPrivateFi5, _call, _call$self, _getSelf2, _getSelf2$self, _getSelf3, _getSelf3$self, _fn$Foo, _fn$Foo2, _fn$Foo3, _fnDeep$very$o, _fnDeep$very$o$Foo, _fnDeep$very$o2, _fnDeep$very$o2$Foo, _fnDeep$very$o3, _fnDeep$very$o3$Foo, _classStaticPrivateFi6, _classStaticPrivateFi7, _ref7, _ref7$self, _ref8, _ref8$self, _self3, _self3$self, _classStaticPrivateFi8, _classStaticPrivateFi9, _ref9, _ref9$call, _ref10, _ref10$getSelf, _getSelf4, _ref11, _getSelf4$call, _ref12, _ref12$self, _classStaticPrivateFi10, _call2, _call2$self, _getSelf5, _getSelf5$self, _getSelf6, _getSelf6$self; const o = { Foo: Foo @@ -27,44 +27,44 @@ class Foo { return deep; } - (_o = o) === null || _o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o$Foo = _o.Foo, Foo, _m).call(_o$Foo); - (_o2 = o) === null || _o2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o2$Foo = _o2.Foo, Foo, _m).call(_o2$Foo).toString; - (_o3 = o) === null || _o3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o3$Foo = _o3.Foo, Foo, _m).call(_o3$Foo).toString(); + o === null || o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o$Foo = o.Foo, Foo, _m).call(_o$Foo); + o === null || o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o$Foo2 = o.Foo, Foo, _m).call(_o$Foo2).toString; + o === null || o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o$Foo3 = o.Foo, Foo, _m).call(_o$Foo3).toString(); (_deep$very$o = deep?.very.o) === null || _deep$very$o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_deep$very$o$Foo = _deep$very$o.Foo, Foo, _m).call(_deep$very$o$Foo); (_deep$very$o2 = deep?.very.o) === null || _deep$very$o2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_deep$very$o2$Foo = _deep$very$o2.Foo, Foo, _m).call(_deep$very$o2$Foo).toString; (_deep$very$o3 = deep?.very.o) === null || _deep$very$o3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_deep$very$o3$Foo = _deep$very$o3.Foo, Foo, _m).call(_deep$very$o3$Foo).toString(); - (_o4 = o) === null || _o4 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFi = _classStaticPrivateFieldSpecGet(_o4.Foo, Foo, _self), Foo, _m).call(_classStaticPrivateFi); - (_o5 = o) === null || _o5 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFi2 = _classStaticPrivateFieldSpecGet(_o5.Foo, Foo, _self).self, Foo, _m).call(_classStaticPrivateFi2); - (_ref = (_o6 = o) === null || _o6 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o6.Foo, Foo, _self)) === null || _ref === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref$self = _ref.self, Foo, _m).call(_ref$self); - (_ref2 = (_o7 = o) === null || _o7 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o7.Foo, Foo, _self).self) === null || _ref2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref2$self = _ref2.self, Foo, _m).call(_ref2$self); - (_self2 = ((_o8 = o) === null || _o8 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o8.Foo, Foo, _self))?.self) === null || _self2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_self2$self = _self2.self, Foo, _m).call(_self2$self); - (_o9 = o) === null || _o9 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFi3 = _classStaticPrivateFieldSpecGet(_o9.Foo, Foo, _self).getSelf(), Foo, _m).call(_classStaticPrivateFi3); - (_ref3 = (_o10 = o) === null || _o10 === void 0 ? void 0 : (_classStaticPrivateFi4 = _classStaticPrivateFieldSpecGet(_o10.Foo, Foo, _self)).getSelf) === null || _ref3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref3$call = _ref3.call(_classStaticPrivateFi4), Foo, _m).call(_ref3$call); - (_ref4 = (_o11 = o) === null || _o11 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o11.Foo, Foo, _self)) === null || _ref4 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref4$getSelf = _ref4.getSelf(), Foo, _m).call(_ref4$getSelf); - (_getSelf = (_ref5 = (_o12 = o) === null || _o12 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o12.Foo, Foo, _self))?.getSelf) === null || _getSelf === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_getSelf$call = _getSelf.call(_ref5), Foo, _m).call(_getSelf$call); - (_ref6 = (_o13 = o) === null || _o13 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o13.Foo, Foo, _self).getSelf()) === null || _ref6 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref6$self = _ref6.self, Foo, _m).call(_ref6$self); - (_call = ((_o14 = o) === null || _o14 === void 0 ? void 0 : (_classStaticPrivateFi5 = _classStaticPrivateFieldSpecGet(_o14.Foo, Foo, _self)).getSelf)?.call(_classStaticPrivateFi5)) === null || _call === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_call$self = _call.self, Foo, _m).call(_call$self); - (_getSelf2 = ((_o15 = o) === null || _o15 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o15.Foo, Foo, _self))?.getSelf()) === null || _getSelf2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_getSelf2$self = _getSelf2.self, Foo, _m).call(_getSelf2$self); - (_getSelf3 = ((_o16 = o) === null || _o16 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o16.Foo, Foo, _self))?.getSelf?.()) === null || _getSelf3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_getSelf3$self = _getSelf3.self, Foo, _m).call(_getSelf3$self); - (_fn = fn) === null || _fn === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn$Foo = _fn().Foo, Foo, _m).call(_fn$Foo); - (_fn2 = fn) === null || _fn2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn2$Foo = _fn2().Foo, Foo, _m).call(_fn2$Foo).toString; - (_fn3 = fn) === null || _fn3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn3$Foo = _fn3().Foo, Foo, _m).call(_fn3$Foo).toString(); + o === null || o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFi = _classStaticPrivateFieldSpecGet(o.Foo, Foo, _self), Foo, _m).call(_classStaticPrivateFi); + o === null || o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFi2 = _classStaticPrivateFieldSpecGet(o.Foo, Foo, _self).self, Foo, _m).call(_classStaticPrivateFi2); + (_ref = o === null || o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(o.Foo, Foo, _self)) === null || _ref === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref$self = _ref.self, Foo, _m).call(_ref$self); + (_ref2 = o === null || o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(o.Foo, Foo, _self).self) === null || _ref2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref2$self = _ref2.self, Foo, _m).call(_ref2$self); + (_self2 = (o === null || o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(o.Foo, Foo, _self))?.self) === null || _self2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_self2$self = _self2.self, Foo, _m).call(_self2$self); + o === null || o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFi3 = _classStaticPrivateFieldSpecGet(o.Foo, Foo, _self).getSelf(), Foo, _m).call(_classStaticPrivateFi3); + (_ref3 = o === null || o === void 0 ? void 0 : (_classStaticPrivateFi4 = _classStaticPrivateFieldSpecGet(o.Foo, Foo, _self)).getSelf) === null || _ref3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref3$call = _ref3.call(_classStaticPrivateFi4), Foo, _m).call(_ref3$call); + (_ref4 = o === null || o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(o.Foo, Foo, _self)) === null || _ref4 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref4$getSelf = _ref4.getSelf(), Foo, _m).call(_ref4$getSelf); + (_getSelf = (_ref5 = o === null || o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(o.Foo, Foo, _self))?.getSelf) === null || _getSelf === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_getSelf$call = _getSelf.call(_ref5), Foo, _m).call(_getSelf$call); + (_ref6 = o === null || o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(o.Foo, Foo, _self).getSelf()) === null || _ref6 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref6$self = _ref6.self, Foo, _m).call(_ref6$self); + (_call = (o === null || o === void 0 ? void 0 : (_classStaticPrivateFi5 = _classStaticPrivateFieldSpecGet(o.Foo, Foo, _self)).getSelf)?.call(_classStaticPrivateFi5)) === null || _call === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_call$self = _call.self, Foo, _m).call(_call$self); + (_getSelf2 = (o === null || o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(o.Foo, Foo, _self))?.getSelf()) === null || _getSelf2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_getSelf2$self = _getSelf2.self, Foo, _m).call(_getSelf2$self); + (_getSelf3 = (o === null || o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(o.Foo, Foo, _self))?.getSelf?.()) === null || _getSelf3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_getSelf3$self = _getSelf3.self, Foo, _m).call(_getSelf3$self); + fn === null || fn === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn$Foo = fn().Foo, Foo, _m).call(_fn$Foo); + fn === null || fn === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn$Foo2 = fn().Foo, Foo, _m).call(_fn$Foo2).toString; + fn === null || fn === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn$Foo3 = fn().Foo, Foo, _m).call(_fn$Foo3).toString(); (_fnDeep$very$o = fnDeep?.().very.o) === null || _fnDeep$very$o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fnDeep$very$o$Foo = _fnDeep$very$o.Foo, Foo, _m).call(_fnDeep$very$o$Foo); (_fnDeep$very$o2 = fnDeep?.().very.o) === null || _fnDeep$very$o2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fnDeep$very$o2$Foo = _fnDeep$very$o2.Foo, Foo, _m).call(_fnDeep$very$o2$Foo).toString; (_fnDeep$very$o3 = fnDeep?.().very.o) === null || _fnDeep$very$o3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fnDeep$very$o3$Foo = _fnDeep$very$o3.Foo, Foo, _m).call(_fnDeep$very$o3$Foo).toString(); - (_fn4 = fn) === null || _fn4 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFi6 = _classStaticPrivateFieldSpecGet(_fn4().Foo, Foo, _self), Foo, _m).call(_classStaticPrivateFi6); - (_fn5 = fn) === null || _fn5 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFi7 = _classStaticPrivateFieldSpecGet(_fn5().Foo, Foo, _self).self, Foo, _m).call(_classStaticPrivateFi7); - (_ref7 = (_fn6 = fn) === null || _fn6 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn6().Foo, Foo, _self)) === null || _ref7 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref7$self = _ref7.self, Foo, _m).call(_ref7$self); - (_ref8 = (_fn7 = fn) === null || _fn7 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn7().Foo, Foo, _self).self) === null || _ref8 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref8$self = _ref8.self, Foo, _m).call(_ref8$self); - (_self3 = ((_fn8 = fn) === null || _fn8 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn8().Foo, Foo, _self))?.self) === null || _self3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_self3$self = _self3.self, Foo, _m).call(_self3$self); - (_fn9 = fn) === null || _fn9 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFi8 = _classStaticPrivateFieldSpecGet(_fn9().Foo, Foo, _self).getSelf(), Foo, _m).call(_classStaticPrivateFi8); - (_ref9 = (_fn10 = fn) === null || _fn10 === void 0 ? void 0 : (_classStaticPrivateFi9 = _classStaticPrivateFieldSpecGet(_fn10().Foo, Foo, _self)).getSelf) === null || _ref9 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref9$call = _ref9.call(_classStaticPrivateFi9), Foo, _m).call(_ref9$call); - (_ref10 = (_fn11 = fn) === null || _fn11 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn11().Foo, Foo, _self)) === null || _ref10 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref10$getSelf = _ref10.getSelf(), Foo, _m).call(_ref10$getSelf); - (_getSelf4 = (_ref11 = (_fn12 = fn) === null || _fn12 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn12().Foo, Foo, _self))?.getSelf) === null || _getSelf4 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_getSelf4$call = _getSelf4.call(_ref11), Foo, _m).call(_getSelf4$call); - (_ref12 = (_fn13 = fn) === null || _fn13 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn13().Foo, Foo, _self).getSelf()) === null || _ref12 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref12$self = _ref12.self, Foo, _m).call(_ref12$self); - (_call2 = ((_fn14 = fn) === null || _fn14 === void 0 ? void 0 : (_classStaticPrivateFi10 = _classStaticPrivateFieldSpecGet(_fn14().Foo, Foo, _self)).getSelf)?.call(_classStaticPrivateFi10)) === null || _call2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_call2$self = _call2.self, Foo, _m).call(_call2$self); - (_getSelf5 = ((_fn15 = fn) === null || _fn15 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn15().Foo, Foo, _self))?.getSelf()) === null || _getSelf5 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_getSelf5$self = _getSelf5.self, Foo, _m).call(_getSelf5$self); - (_getSelf6 = ((_fn16 = fn) === null || _fn16 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn16().Foo, Foo, _self))?.getSelf?.()) === null || _getSelf6 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_getSelf6$self = _getSelf6.self, Foo, _m).call(_getSelf6$self); + fn === null || fn === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFi6 = _classStaticPrivateFieldSpecGet(fn().Foo, Foo, _self), Foo, _m).call(_classStaticPrivateFi6); + fn === null || fn === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFi7 = _classStaticPrivateFieldSpecGet(fn().Foo, Foo, _self).self, Foo, _m).call(_classStaticPrivateFi7); + (_ref7 = fn === null || fn === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(fn().Foo, Foo, _self)) === null || _ref7 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref7$self = _ref7.self, Foo, _m).call(_ref7$self); + (_ref8 = fn === null || fn === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(fn().Foo, Foo, _self).self) === null || _ref8 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref8$self = _ref8.self, Foo, _m).call(_ref8$self); + (_self3 = (fn === null || fn === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(fn().Foo, Foo, _self))?.self) === null || _self3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_self3$self = _self3.self, Foo, _m).call(_self3$self); + fn === null || fn === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFi8 = _classStaticPrivateFieldSpecGet(fn().Foo, Foo, _self).getSelf(), Foo, _m).call(_classStaticPrivateFi8); + (_ref9 = fn === null || fn === void 0 ? void 0 : (_classStaticPrivateFi9 = _classStaticPrivateFieldSpecGet(fn().Foo, Foo, _self)).getSelf) === null || _ref9 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref9$call = _ref9.call(_classStaticPrivateFi9), Foo, _m).call(_ref9$call); + (_ref10 = fn === null || fn === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(fn().Foo, Foo, _self)) === null || _ref10 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref10$getSelf = _ref10.getSelf(), Foo, _m).call(_ref10$getSelf); + (_getSelf4 = (_ref11 = fn === null || fn === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(fn().Foo, Foo, _self))?.getSelf) === null || _getSelf4 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_getSelf4$call = _getSelf4.call(_ref11), Foo, _m).call(_getSelf4$call); + (_ref12 = fn === null || fn === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(fn().Foo, Foo, _self).getSelf()) === null || _ref12 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref12$self = _ref12.self, Foo, _m).call(_ref12$self); + (_call2 = (fn === null || fn === void 0 ? void 0 : (_classStaticPrivateFi10 = _classStaticPrivateFieldSpecGet(fn().Foo, Foo, _self)).getSelf)?.call(_classStaticPrivateFi10)) === null || _call2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_call2$self = _call2.self, Foo, _m).call(_call2$self); + (_getSelf5 = (fn === null || fn === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(fn().Foo, Foo, _self))?.getSelf()) === null || _getSelf5 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_getSelf5$self = _getSelf5.self, Foo, _m).call(_getSelf5$self); + (_getSelf6 = (fn === null || fn === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(fn().Foo, Foo, _self))?.getSelf?.()) === null || _getSelf6 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_getSelf6$self = _getSelf6.self, Foo, _m).call(_getSelf6$self); } } diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-before-property-with-transform/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-before-property-with-transform/output.js index d5ef32b86918..1f754b075002 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-before-property-with-transform/output.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-before-property-with-transform/output.js @@ -8,7 +8,7 @@ class Foo { } static test() { - var _o, _o2, _o3, _deep$very$o, _deep$very$o2, _deep$very$o3, _o4, _o5, _o6, _ref, _o7, _ref2, _o8, _self2, _o9, _o10, _classStaticPrivateFi, _ref3, _o11, _ref4, _o12, _getSelf, _ref5, _o13, _ref6, _o14, _classStaticPrivateFi2, _call, _o15, _getSelf2, _o16, _getSelf3, _fn, _fn2, _fn3, _fnDeep$very$o, _fnDeep$very$o2, _fnDeep$very$o3, _fn4, _fn5, _fn6, _ref7, _fn7, _ref8, _fn8, _self3, _fn9, _fn10, _classStaticPrivateFi3, _ref9, _fn11, _ref10, _fn12, _getSelf4, _ref11, _fn13, _ref12, _fn14, _classStaticPrivateFi4, _call2, _fn15, _getSelf5, _fn16, _getSelf6, _ref13, _ref14, _ref15, _ref16, _ref17, _ref17$getSelf, _ref18, _ref19, _ref20, _ref21, _ref22, _ref22$getSelf; + var _deep$very$o, _deep$very$o2, _deep$very$o3, _ref, _ref2, _self2, _classStaticPrivateFi, _ref3, _ref4, _getSelf, _ref5, _ref6, _classStaticPrivateFi2, _call, _getSelf2, _getSelf3, _fnDeep$very$o, _fnDeep$very$o2, _fnDeep$very$o3, _ref7, _ref8, _self3, _classStaticPrivateFi3, _ref9, _ref10, _getSelf4, _ref11, _ref12, _classStaticPrivateFi4, _call2, _getSelf5, _getSelf6, _ref13, _ref14, _ref15, _ref16, _ref17, _ref17$getSelf, _ref18, _ref19, _ref20, _ref21, _ref22, _ref22$getSelf; const o = { Foo: Foo @@ -27,44 +27,44 @@ class Foo { return deep; } - (_o = o) === null || _o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o.Foo, Foo, _x); - (_o2 = o) === null || _o2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o2.Foo, Foo, _x).toString; - (_o3 = o) === null || _o3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o3.Foo, Foo, _x).toString(); + o === null || o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(o.Foo, Foo, _x); + o === null || o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(o.Foo, Foo, _x).toString; + o === null || o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(o.Foo, Foo, _x).toString(); (_deep$very$o = deep === null || deep === void 0 ? void 0 : deep.very.o) === null || _deep$very$o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_deep$very$o.Foo, Foo, _x); (_deep$very$o2 = deep === null || deep === void 0 ? void 0 : deep.very.o) === null || _deep$very$o2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_deep$very$o2.Foo, Foo, _x).toString; (_deep$very$o3 = deep === null || deep === void 0 ? void 0 : deep.very.o) === null || _deep$very$o3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_deep$very$o3.Foo, Foo, _x).toString(); - (_o4 = o) === null || _o4 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFieldSpecGet(_o4.Foo, Foo, _self), Foo, _x); - (_o5 = o) === null || _o5 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFieldSpecGet(_o5.Foo, Foo, _self).self, Foo, _x); - (_ref = (_o6 = o) === null || _o6 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o6.Foo, Foo, _self)) === null || _ref === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref.self, Foo, _x); - (_ref2 = (_o7 = o) === null || _o7 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o7.Foo, Foo, _self).self) === null || _ref2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref2.self, Foo, _x); - (_self2 = (_ref13 = (_o8 = o) === null || _o8 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o8.Foo, Foo, _self)) === null || _ref13 === void 0 ? void 0 : _ref13.self) === null || _self2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_self2.self, Foo, _x); - (_o9 = o) === null || _o9 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFieldSpecGet(_o9.Foo, Foo, _self).getSelf(), Foo, _x); - (_ref3 = (_o10 = o) === null || _o10 === void 0 ? void 0 : (_classStaticPrivateFi = _classStaticPrivateFieldSpecGet(_o10.Foo, Foo, _self)).getSelf) === null || _ref3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref3.call(_classStaticPrivateFi), Foo, _x); - (_ref4 = (_o11 = o) === null || _o11 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o11.Foo, Foo, _self)) === null || _ref4 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref4.getSelf(), Foo, _x); - (_getSelf = (_ref14 = _ref5 = (_o12 = o) === null || _o12 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o12.Foo, Foo, _self)) === null || _ref14 === void 0 ? void 0 : _ref14.getSelf) === null || _getSelf === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_getSelf.call(_ref5), Foo, _x); - (_ref6 = (_o13 = o) === null || _o13 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o13.Foo, Foo, _self).getSelf()) === null || _ref6 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref6.self, Foo, _x); - (_call = (_ref15 = (_o14 = o) === null || _o14 === void 0 ? void 0 : (_classStaticPrivateFi2 = _classStaticPrivateFieldSpecGet(_o14.Foo, Foo, _self)).getSelf) === null || _ref15 === void 0 ? void 0 : _ref15.call(_classStaticPrivateFi2)) === null || _call === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_call.self, Foo, _x); - (_getSelf2 = (_ref16 = (_o15 = o) === null || _o15 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o15.Foo, Foo, _self)) === null || _ref16 === void 0 ? void 0 : _ref16.getSelf()) === null || _getSelf2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_getSelf2.self, Foo, _x); - (_getSelf3 = (_ref17 = (_o16 = o) === null || _o16 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o16.Foo, Foo, _self)) === null || _ref17 === void 0 ? void 0 : (_ref17$getSelf = _ref17.getSelf) === null || _ref17$getSelf === void 0 ? void 0 : _ref17$getSelf.call(_ref17)) === null || _getSelf3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_getSelf3.self, Foo, _x); - (_fn = fn) === null || _fn === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn().Foo, Foo, _x); - (_fn2 = fn) === null || _fn2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn2().Foo, Foo, _x).toString; - (_fn3 = fn) === null || _fn3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn3().Foo, Foo, _x).toString(); + o === null || o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFieldSpecGet(o.Foo, Foo, _self), Foo, _x); + o === null || o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFieldSpecGet(o.Foo, Foo, _self).self, Foo, _x); + (_ref = o === null || o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(o.Foo, Foo, _self)) === null || _ref === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref.self, Foo, _x); + (_ref2 = o === null || o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(o.Foo, Foo, _self).self) === null || _ref2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref2.self, Foo, _x); + (_self2 = (_ref13 = o === null || o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(o.Foo, Foo, _self)) === null || _ref13 === void 0 ? void 0 : _ref13.self) === null || _self2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_self2.self, Foo, _x); + o === null || o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFieldSpecGet(o.Foo, Foo, _self).getSelf(), Foo, _x); + (_ref3 = o === null || o === void 0 ? void 0 : (_classStaticPrivateFi = _classStaticPrivateFieldSpecGet(o.Foo, Foo, _self)).getSelf) === null || _ref3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref3.call(_classStaticPrivateFi), Foo, _x); + (_ref4 = o === null || o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(o.Foo, Foo, _self)) === null || _ref4 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref4.getSelf(), Foo, _x); + (_getSelf = (_ref14 = _ref5 = o === null || o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(o.Foo, Foo, _self)) === null || _ref14 === void 0 ? void 0 : _ref14.getSelf) === null || _getSelf === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_getSelf.call(_ref5), Foo, _x); + (_ref6 = o === null || o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(o.Foo, Foo, _self).getSelf()) === null || _ref6 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref6.self, Foo, _x); + (_call = (_ref15 = o === null || o === void 0 ? void 0 : (_classStaticPrivateFi2 = _classStaticPrivateFieldSpecGet(o.Foo, Foo, _self)).getSelf) === null || _ref15 === void 0 ? void 0 : _ref15.call(_classStaticPrivateFi2)) === null || _call === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_call.self, Foo, _x); + (_getSelf2 = (_ref16 = o === null || o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(o.Foo, Foo, _self)) === null || _ref16 === void 0 ? void 0 : _ref16.getSelf()) === null || _getSelf2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_getSelf2.self, Foo, _x); + (_getSelf3 = (_ref17 = o === null || o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(o.Foo, Foo, _self)) === null || _ref17 === void 0 ? void 0 : (_ref17$getSelf = _ref17.getSelf) === null || _ref17$getSelf === void 0 ? void 0 : _ref17$getSelf.call(_ref17)) === null || _getSelf3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_getSelf3.self, Foo, _x); + fn === null || fn === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(fn().Foo, Foo, _x); + fn === null || fn === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(fn().Foo, Foo, _x).toString; + fn === null || fn === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(fn().Foo, Foo, _x).toString(); (_fnDeep$very$o = fnDeep === null || fnDeep === void 0 ? void 0 : fnDeep().very.o) === null || _fnDeep$very$o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fnDeep$very$o.Foo, Foo, _x); (_fnDeep$very$o2 = fnDeep === null || fnDeep === void 0 ? void 0 : fnDeep().very.o) === null || _fnDeep$very$o2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fnDeep$very$o2.Foo, Foo, _x).toString; (_fnDeep$very$o3 = fnDeep === null || fnDeep === void 0 ? void 0 : fnDeep().very.o) === null || _fnDeep$very$o3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fnDeep$very$o3.Foo, Foo, _x).toString(); - (_fn4 = fn) === null || _fn4 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFieldSpecGet(_fn4().Foo, Foo, _self), Foo, _x); - (_fn5 = fn) === null || _fn5 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFieldSpecGet(_fn5().Foo, Foo, _self).self, Foo, _x); - (_ref7 = (_fn6 = fn) === null || _fn6 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn6().Foo, Foo, _self)) === null || _ref7 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref7.self, Foo, _x); - (_ref8 = (_fn7 = fn) === null || _fn7 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn7().Foo, Foo, _self).self) === null || _ref8 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref8.self, Foo, _x); - (_self3 = (_ref18 = (_fn8 = fn) === null || _fn8 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn8().Foo, Foo, _self)) === null || _ref18 === void 0 ? void 0 : _ref18.self) === null || _self3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_self3.self, Foo, _x); - (_fn9 = fn) === null || _fn9 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFieldSpecGet(_fn9().Foo, Foo, _self).getSelf(), Foo, _x); - (_ref9 = (_fn10 = fn) === null || _fn10 === void 0 ? void 0 : (_classStaticPrivateFi3 = _classStaticPrivateFieldSpecGet(_fn10().Foo, Foo, _self)).getSelf) === null || _ref9 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref9.call(_classStaticPrivateFi3), Foo, _x); - (_ref10 = (_fn11 = fn) === null || _fn11 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn11().Foo, Foo, _self)) === null || _ref10 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref10.getSelf(), Foo, _x); - (_getSelf4 = (_ref19 = _ref11 = (_fn12 = fn) === null || _fn12 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn12().Foo, Foo, _self)) === null || _ref19 === void 0 ? void 0 : _ref19.getSelf) === null || _getSelf4 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_getSelf4.call(_ref11), Foo, _x); - (_ref12 = (_fn13 = fn) === null || _fn13 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn13().Foo, Foo, _self).getSelf()) === null || _ref12 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref12.self, Foo, _x); - (_call2 = (_ref20 = (_fn14 = fn) === null || _fn14 === void 0 ? void 0 : (_classStaticPrivateFi4 = _classStaticPrivateFieldSpecGet(_fn14().Foo, Foo, _self)).getSelf) === null || _ref20 === void 0 ? void 0 : _ref20.call(_classStaticPrivateFi4)) === null || _call2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_call2.self, Foo, _x); - (_getSelf5 = (_ref21 = (_fn15 = fn) === null || _fn15 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn15().Foo, Foo, _self)) === null || _ref21 === void 0 ? void 0 : _ref21.getSelf()) === null || _getSelf5 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_getSelf5.self, Foo, _x); - (_getSelf6 = (_ref22 = (_fn16 = fn) === null || _fn16 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn16().Foo, Foo, _self)) === null || _ref22 === void 0 ? void 0 : (_ref22$getSelf = _ref22.getSelf) === null || _ref22$getSelf === void 0 ? void 0 : _ref22$getSelf.call(_ref22)) === null || _getSelf6 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_getSelf6.self, Foo, _x); + fn === null || fn === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFieldSpecGet(fn().Foo, Foo, _self), Foo, _x); + fn === null || fn === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFieldSpecGet(fn().Foo, Foo, _self).self, Foo, _x); + (_ref7 = fn === null || fn === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(fn().Foo, Foo, _self)) === null || _ref7 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref7.self, Foo, _x); + (_ref8 = fn === null || fn === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(fn().Foo, Foo, _self).self) === null || _ref8 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref8.self, Foo, _x); + (_self3 = (_ref18 = fn === null || fn === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(fn().Foo, Foo, _self)) === null || _ref18 === void 0 ? void 0 : _ref18.self) === null || _self3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_self3.self, Foo, _x); + fn === null || fn === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFieldSpecGet(fn().Foo, Foo, _self).getSelf(), Foo, _x); + (_ref9 = fn === null || fn === void 0 ? void 0 : (_classStaticPrivateFi3 = _classStaticPrivateFieldSpecGet(fn().Foo, Foo, _self)).getSelf) === null || _ref9 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref9.call(_classStaticPrivateFi3), Foo, _x); + (_ref10 = fn === null || fn === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(fn().Foo, Foo, _self)) === null || _ref10 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref10.getSelf(), Foo, _x); + (_getSelf4 = (_ref19 = _ref11 = fn === null || fn === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(fn().Foo, Foo, _self)) === null || _ref19 === void 0 ? void 0 : _ref19.getSelf) === null || _getSelf4 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_getSelf4.call(_ref11), Foo, _x); + (_ref12 = fn === null || fn === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(fn().Foo, Foo, _self).getSelf()) === null || _ref12 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref12.self, Foo, _x); + (_call2 = (_ref20 = fn === null || fn === void 0 ? void 0 : (_classStaticPrivateFi4 = _classStaticPrivateFieldSpecGet(fn().Foo, Foo, _self)).getSelf) === null || _ref20 === void 0 ? void 0 : _ref20.call(_classStaticPrivateFi4)) === null || _call2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_call2.self, Foo, _x); + (_getSelf5 = (_ref21 = fn === null || fn === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(fn().Foo, Foo, _self)) === null || _ref21 === void 0 ? void 0 : _ref21.getSelf()) === null || _getSelf5 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_getSelf5.self, Foo, _x); + (_getSelf6 = (_ref22 = fn === null || fn === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(fn().Foo, Foo, _self)) === null || _ref22 === void 0 ? void 0 : (_ref22$getSelf = _ref22.getSelf) === null || _ref22$getSelf === void 0 ? void 0 : _ref22$getSelf.call(_ref22)) === null || _getSelf6 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_getSelf6.self, Foo, _x); } } diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-before-property/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-before-property/output.js index edac6bb1537f..0ba37b422f2a 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-before-property/output.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-before-property/output.js @@ -8,7 +8,7 @@ class Foo { } static test() { - var _o, _o2, _o3, _deep$very$o, _deep$very$o2, _deep$very$o3, _o4, _o5, _o6, _ref, _o7, _ref2, _o8, _self2, _o9, _o10, _classStaticPrivateFi, _ref3, _o11, _ref4, _o12, _getSelf, _ref5, _o13, _ref6, _o14, _classStaticPrivateFi2, _call, _o15, _getSelf2, _o16, _getSelf3, _fn, _fn2, _fn3, _fnDeep$very$o, _fnDeep$very$o2, _fnDeep$very$o3, _fn4, _fn5, _fn6, _ref7, _fn7, _ref8, _fn8, _self3, _fn9, _fn10, _classStaticPrivateFi3, _ref9, _fn11, _ref10, _fn12, _getSelf4, _ref11, _fn13, _ref12, _fn14, _classStaticPrivateFi4, _call2, _fn15, _getSelf5, _fn16, _getSelf6; + var _deep$very$o, _deep$very$o2, _deep$very$o3, _ref, _ref2, _self2, _classStaticPrivateFi, _ref3, _ref4, _getSelf, _ref5, _ref6, _classStaticPrivateFi2, _call, _getSelf2, _getSelf3, _fnDeep$very$o, _fnDeep$very$o2, _fnDeep$very$o3, _ref7, _ref8, _self3, _classStaticPrivateFi3, _ref9, _ref10, _getSelf4, _ref11, _ref12, _classStaticPrivateFi4, _call2, _getSelf5, _getSelf6; const o = { Foo: Foo @@ -27,44 +27,44 @@ class Foo { return deep; } - (_o = o) === null || _o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o.Foo, Foo, _x); - (_o2 = o) === null || _o2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o2.Foo, Foo, _x).toString; - (_o3 = o) === null || _o3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o3.Foo, Foo, _x).toString(); + o === null || o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(o.Foo, Foo, _x); + o === null || o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(o.Foo, Foo, _x).toString; + o === null || o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(o.Foo, Foo, _x).toString(); (_deep$very$o = deep?.very.o) === null || _deep$very$o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_deep$very$o.Foo, Foo, _x); (_deep$very$o2 = deep?.very.o) === null || _deep$very$o2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_deep$very$o2.Foo, Foo, _x).toString; (_deep$very$o3 = deep?.very.o) === null || _deep$very$o3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_deep$very$o3.Foo, Foo, _x).toString(); - (_o4 = o) === null || _o4 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFieldSpecGet(_o4.Foo, Foo, _self), Foo, _x); - (_o5 = o) === null || _o5 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFieldSpecGet(_o5.Foo, Foo, _self).self, Foo, _x); - (_ref = (_o6 = o) === null || _o6 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o6.Foo, Foo, _self)) === null || _ref === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref.self, Foo, _x); - (_ref2 = (_o7 = o) === null || _o7 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o7.Foo, Foo, _self).self) === null || _ref2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref2.self, Foo, _x); - (_self2 = ((_o8 = o) === null || _o8 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o8.Foo, Foo, _self))?.self) === null || _self2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_self2.self, Foo, _x); - (_o9 = o) === null || _o9 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFieldSpecGet(_o9.Foo, Foo, _self).getSelf(), Foo, _x); - (_ref3 = (_o10 = o) === null || _o10 === void 0 ? void 0 : (_classStaticPrivateFi = _classStaticPrivateFieldSpecGet(_o10.Foo, Foo, _self)).getSelf) === null || _ref3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref3.call(_classStaticPrivateFi), Foo, _x); - (_ref4 = (_o11 = o) === null || _o11 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o11.Foo, Foo, _self)) === null || _ref4 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref4.getSelf(), Foo, _x); - (_getSelf = (_ref5 = (_o12 = o) === null || _o12 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o12.Foo, Foo, _self))?.getSelf) === null || _getSelf === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_getSelf.call(_ref5), Foo, _x); - (_ref6 = (_o13 = o) === null || _o13 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o13.Foo, Foo, _self).getSelf()) === null || _ref6 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref6.self, Foo, _x); - (_call = ((_o14 = o) === null || _o14 === void 0 ? void 0 : (_classStaticPrivateFi2 = _classStaticPrivateFieldSpecGet(_o14.Foo, Foo, _self)).getSelf)?.call(_classStaticPrivateFi2)) === null || _call === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_call.self, Foo, _x); - (_getSelf2 = ((_o15 = o) === null || _o15 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o15.Foo, Foo, _self))?.getSelf()) === null || _getSelf2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_getSelf2.self, Foo, _x); - (_getSelf3 = ((_o16 = o) === null || _o16 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o16.Foo, Foo, _self))?.getSelf?.()) === null || _getSelf3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_getSelf3.self, Foo, _x); - (_fn = fn) === null || _fn === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn().Foo, Foo, _x); - (_fn2 = fn) === null || _fn2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn2().Foo, Foo, _x).toString; - (_fn3 = fn) === null || _fn3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn3().Foo, Foo, _x).toString(); + o === null || o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFieldSpecGet(o.Foo, Foo, _self), Foo, _x); + o === null || o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFieldSpecGet(o.Foo, Foo, _self).self, Foo, _x); + (_ref = o === null || o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(o.Foo, Foo, _self)) === null || _ref === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref.self, Foo, _x); + (_ref2 = o === null || o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(o.Foo, Foo, _self).self) === null || _ref2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref2.self, Foo, _x); + (_self2 = (o === null || o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(o.Foo, Foo, _self))?.self) === null || _self2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_self2.self, Foo, _x); + o === null || o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFieldSpecGet(o.Foo, Foo, _self).getSelf(), Foo, _x); + (_ref3 = o === null || o === void 0 ? void 0 : (_classStaticPrivateFi = _classStaticPrivateFieldSpecGet(o.Foo, Foo, _self)).getSelf) === null || _ref3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref3.call(_classStaticPrivateFi), Foo, _x); + (_ref4 = o === null || o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(o.Foo, Foo, _self)) === null || _ref4 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref4.getSelf(), Foo, _x); + (_getSelf = (_ref5 = o === null || o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(o.Foo, Foo, _self))?.getSelf) === null || _getSelf === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_getSelf.call(_ref5), Foo, _x); + (_ref6 = o === null || o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(o.Foo, Foo, _self).getSelf()) === null || _ref6 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref6.self, Foo, _x); + (_call = (o === null || o === void 0 ? void 0 : (_classStaticPrivateFi2 = _classStaticPrivateFieldSpecGet(o.Foo, Foo, _self)).getSelf)?.call(_classStaticPrivateFi2)) === null || _call === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_call.self, Foo, _x); + (_getSelf2 = (o === null || o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(o.Foo, Foo, _self))?.getSelf()) === null || _getSelf2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_getSelf2.self, Foo, _x); + (_getSelf3 = (o === null || o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(o.Foo, Foo, _self))?.getSelf?.()) === null || _getSelf3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_getSelf3.self, Foo, _x); + fn === null || fn === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(fn().Foo, Foo, _x); + fn === null || fn === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(fn().Foo, Foo, _x).toString; + fn === null || fn === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(fn().Foo, Foo, _x).toString(); (_fnDeep$very$o = fnDeep?.().very.o) === null || _fnDeep$very$o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fnDeep$very$o.Foo, Foo, _x); (_fnDeep$very$o2 = fnDeep?.().very.o) === null || _fnDeep$very$o2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fnDeep$very$o2.Foo, Foo, _x).toString; (_fnDeep$very$o3 = fnDeep?.().very.o) === null || _fnDeep$very$o3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fnDeep$very$o3.Foo, Foo, _x).toString(); - (_fn4 = fn) === null || _fn4 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFieldSpecGet(_fn4().Foo, Foo, _self), Foo, _x); - (_fn5 = fn) === null || _fn5 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFieldSpecGet(_fn5().Foo, Foo, _self).self, Foo, _x); - (_ref7 = (_fn6 = fn) === null || _fn6 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn6().Foo, Foo, _self)) === null || _ref7 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref7.self, Foo, _x); - (_ref8 = (_fn7 = fn) === null || _fn7 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn7().Foo, Foo, _self).self) === null || _ref8 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref8.self, Foo, _x); - (_self3 = ((_fn8 = fn) === null || _fn8 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn8().Foo, Foo, _self))?.self) === null || _self3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_self3.self, Foo, _x); - (_fn9 = fn) === null || _fn9 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFieldSpecGet(_fn9().Foo, Foo, _self).getSelf(), Foo, _x); - (_ref9 = (_fn10 = fn) === null || _fn10 === void 0 ? void 0 : (_classStaticPrivateFi3 = _classStaticPrivateFieldSpecGet(_fn10().Foo, Foo, _self)).getSelf) === null || _ref9 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref9.call(_classStaticPrivateFi3), Foo, _x); - (_ref10 = (_fn11 = fn) === null || _fn11 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn11().Foo, Foo, _self)) === null || _ref10 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref10.getSelf(), Foo, _x); - (_getSelf4 = (_ref11 = (_fn12 = fn) === null || _fn12 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn12().Foo, Foo, _self))?.getSelf) === null || _getSelf4 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_getSelf4.call(_ref11), Foo, _x); - (_ref12 = (_fn13 = fn) === null || _fn13 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn13().Foo, Foo, _self).getSelf()) === null || _ref12 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref12.self, Foo, _x); - (_call2 = ((_fn14 = fn) === null || _fn14 === void 0 ? void 0 : (_classStaticPrivateFi4 = _classStaticPrivateFieldSpecGet(_fn14().Foo, Foo, _self)).getSelf)?.call(_classStaticPrivateFi4)) === null || _call2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_call2.self, Foo, _x); - (_getSelf5 = ((_fn15 = fn) === null || _fn15 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn15().Foo, Foo, _self))?.getSelf()) === null || _getSelf5 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_getSelf5.self, Foo, _x); - (_getSelf6 = ((_fn16 = fn) === null || _fn16 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn16().Foo, Foo, _self))?.getSelf?.()) === null || _getSelf6 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_getSelf6.self, Foo, _x); + fn === null || fn === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFieldSpecGet(fn().Foo, Foo, _self), Foo, _x); + fn === null || fn === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFieldSpecGet(fn().Foo, Foo, _self).self, Foo, _x); + (_ref7 = fn === null || fn === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(fn().Foo, Foo, _self)) === null || _ref7 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref7.self, Foo, _x); + (_ref8 = fn === null || fn === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(fn().Foo, Foo, _self).self) === null || _ref8 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref8.self, Foo, _x); + (_self3 = (fn === null || fn === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(fn().Foo, Foo, _self))?.self) === null || _self3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_self3.self, Foo, _x); + fn === null || fn === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFieldSpecGet(fn().Foo, Foo, _self).getSelf(), Foo, _x); + (_ref9 = fn === null || fn === void 0 ? void 0 : (_classStaticPrivateFi3 = _classStaticPrivateFieldSpecGet(fn().Foo, Foo, _self)).getSelf) === null || _ref9 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref9.call(_classStaticPrivateFi3), Foo, _x); + (_ref10 = fn === null || fn === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(fn().Foo, Foo, _self)) === null || _ref10 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref10.getSelf(), Foo, _x); + (_getSelf4 = (_ref11 = fn === null || fn === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(fn().Foo, Foo, _self))?.getSelf) === null || _getSelf4 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_getSelf4.call(_ref11), Foo, _x); + (_ref12 = fn === null || fn === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(fn().Foo, Foo, _self).getSelf()) === null || _ref12 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref12.self, Foo, _x); + (_call2 = (fn === null || fn === void 0 ? void 0 : (_classStaticPrivateFi4 = _classStaticPrivateFieldSpecGet(fn().Foo, Foo, _self)).getSelf)?.call(_classStaticPrivateFi4)) === null || _call2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_call2.self, Foo, _x); + (_getSelf5 = (fn === null || fn === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(fn().Foo, Foo, _self))?.getSelf()) === null || _getSelf5 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_getSelf5.self, Foo, _x); + (_getSelf6 = (fn === null || fn === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(fn().Foo, Foo, _self))?.getSelf?.()) === null || _getSelf6 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_getSelf6.self, Foo, _x); } } diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-optional-member-call-with-transform/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-optional-member-call-with-transform/output.js index 22ae2753c5d1..a2c6eae6d3b4 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-optional-member-call-with-transform/output.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-optional-member-call-with-transform/output.js @@ -8,7 +8,7 @@ class Foo { } static test() { - var _Foo, _Foo2, _Foo3, _o$Foo, _o$Foo2, _o$Foo3, _deep$very$o$Foo, _deep$very$o$Foo2, _deep$very$o$Foo3, _o, _ref, _o2, _ref2, _o3, _self2, _o4, _self3, _o5, _self$self, _o6, _ref3, _o7, _classStaticPrivateFi, _call, _o8, _getSelf, _o9, _getSelf2, _o10, _self4, _o11, _classStaticPrivateFi2, _call$self, _o12, _getSelf$self, _o13, _getSelf$self2, _fn$Foo, _fn$Foo2, _fn$Foo3, _fnDeep$very$o$Foo, _fnDeep$very$o$Foo2, _fnDeep$very$o$Foo3, _fn, _ref4, _fn2, _ref5, _fn3, _self5, _fn4, _self6, _fn5, _self$self2, _fn6, _ref6, _fn7, _classStaticPrivateFi3, _call2, _fn8, _getSelf3, _fn9, _getSelf4, _fn10, _self7, _fn11, _classStaticPrivateFi4, _call$self2, _fn12, _getSelf$self3, _fn13, _getSelf$self4, _deep$very$o, _deep$very$o2, _deep$very$o3, _ref7, _ref8, _ref9, _ref9$self, _ref10, _ref11, _ref12, _ref12$getSelf, _ref13, _ref14, _ref14$call, _ref15, _ref15$getSelf, _ref16, _ref16$getSelf, _ref16$getSelf$call, _fnDeep$very$o, _fnDeep$very$o2, _fnDeep$very$o3, _ref17, _ref18, _ref19, _ref19$self, _ref20, _ref21, _ref22, _ref22$getSelf, _ref23, _ref24, _ref24$call, _ref25, _ref25$getSelf, _ref26, _ref26$getSelf, _ref26$getSelf$call; + var _o$Foo, _o$Foo2, _o$Foo3, _deep$very$o$Foo, _deep$very$o$Foo2, _deep$very$o$Foo3, _ref, _ref2, _self2, _self3, _self$self, _ref3, _classStaticPrivateFi, _call, _getSelf, _getSelf2, _self4, _classStaticPrivateFi2, _call$self, _getSelf$self, _getSelf$self2, _fn$Foo, _fn$Foo2, _fn$Foo3, _fnDeep$very$o$Foo, _fnDeep$very$o$Foo2, _fnDeep$very$o$Foo3, _ref4, _ref5, _self5, _self6, _self$self2, _ref6, _classStaticPrivateFi3, _call2, _getSelf3, _getSelf4, _self7, _classStaticPrivateFi4, _call$self2, _getSelf$self3, _getSelf$self4, _deep$very$o, _deep$very$o2, _deep$very$o3, _ref7, _ref8, _ref9, _ref9$self, _ref10, _ref11, _ref12, _ref12$getSelf, _ref13, _ref14, _ref14$call, _ref15, _ref15$getSelf, _ref16, _ref16$getSelf, _ref16$getSelf$call, _fnDeep$very$o, _fnDeep$very$o2, _fnDeep$very$o3, _ref17, _ref18, _ref19, _ref19$self, _ref20, _ref21, _ref22, _ref22$getSelf, _ref23, _ref24, _ref24$call, _ref25, _ref25$getSelf, _ref26, _ref26$getSelf, _ref26$getSelf$call; const o = { Foo: Foo @@ -27,47 +27,47 @@ class Foo { return deep; } - (_Foo = Foo) === null || _Foo === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_Foo, Foo, _m).call(_Foo); - (_Foo2 = Foo) === null || _Foo2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_Foo2, Foo, _m).call(_Foo2).toString; - (_Foo3 = Foo) === null || _Foo3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_Foo3, Foo, _m).call(_Foo3).toString(); + Foo === null || Foo === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(Foo, Foo, _m).call(Foo); + Foo === null || Foo === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(Foo, Foo, _m).call(Foo).toString; + Foo === null || Foo === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(Foo, Foo, _m).call(Foo).toString(); (_o$Foo = o === null || o === void 0 ? void 0 : o.Foo) === null || _o$Foo === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o$Foo, Foo, _m).call(_o$Foo); (_o$Foo2 = o === null || o === void 0 ? void 0 : o.Foo) === null || _o$Foo2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o$Foo2, Foo, _m).call(_o$Foo2).toString; (_o$Foo3 = o === null || o === void 0 ? void 0 : o.Foo) === null || _o$Foo3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o$Foo3, Foo, _m).call(_o$Foo3).toString(); (_deep$very$o$Foo = deep === null || deep === void 0 ? void 0 : (_deep$very$o = deep.very.o) === null || _deep$very$o === void 0 ? void 0 : _deep$very$o.Foo) === null || _deep$very$o$Foo === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_deep$very$o$Foo, Foo, _m).call(_deep$very$o$Foo); (_deep$very$o$Foo2 = deep === null || deep === void 0 ? void 0 : (_deep$very$o2 = deep.very.o) === null || _deep$very$o2 === void 0 ? void 0 : _deep$very$o2.Foo) === null || _deep$very$o$Foo2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_deep$very$o$Foo2, Foo, _m).call(_deep$very$o$Foo2).toString; (_deep$very$o$Foo3 = deep === null || deep === void 0 ? void 0 : (_deep$very$o3 = deep.very.o) === null || _deep$very$o3 === void 0 ? void 0 : _deep$very$o3.Foo) === null || _deep$very$o$Foo3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_deep$very$o$Foo3, Foo, _m).call(_deep$very$o$Foo3).toString(); - (_ref = (_o = o) === null || _o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o.Foo, Foo, _self)) === null || _ref === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref, Foo, _m).call(_ref); - (_ref2 = (_o2 = o) === null || _o2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o2.Foo, Foo, _self).self) === null || _ref2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref2, Foo, _m).call(_ref2); - (_self2 = (_ref7 = (_o3 = o) === null || _o3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o3.Foo, Foo, _self)) === null || _ref7 === void 0 ? void 0 : _ref7.self) === null || _self2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_self2, Foo, _m).call(_self2); - (_self3 = (_ref8 = (_o4 = o) === null || _o4 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o4.Foo, Foo, _self).self) === null || _ref8 === void 0 ? void 0 : _ref8.self) === null || _self3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_self3, Foo, _m).call(_self3); - (_self$self = (_ref9 = (_o5 = o) === null || _o5 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o5.Foo, Foo, _self)) === null || _ref9 === void 0 ? void 0 : (_ref9$self = _ref9.self) === null || _ref9$self === void 0 ? void 0 : _ref9$self.self) === null || _self$self === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_self$self, Foo, _m).call(_self$self); - (_ref3 = (_o6 = o) === null || _o6 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o6.Foo, Foo, _self).getSelf()) === null || _ref3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref3, Foo, _m).call(_ref3); - (_call = (_ref10 = (_o7 = o) === null || _o7 === void 0 ? void 0 : (_classStaticPrivateFi = _classStaticPrivateFieldSpecGet(_o7.Foo, Foo, _self)).getSelf) === null || _ref10 === void 0 ? void 0 : _ref10.call(_classStaticPrivateFi)) === null || _call === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_call, Foo, _m).call(_call); - (_getSelf = (_ref11 = (_o8 = o) === null || _o8 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o8.Foo, Foo, _self)) === null || _ref11 === void 0 ? void 0 : _ref11.getSelf()) === null || _getSelf === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_getSelf, Foo, _m).call(_getSelf); - (_getSelf2 = (_ref12 = (_o9 = o) === null || _o9 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o9.Foo, Foo, _self)) === null || _ref12 === void 0 ? void 0 : (_ref12$getSelf = _ref12.getSelf) === null || _ref12$getSelf === void 0 ? void 0 : _ref12$getSelf.call(_ref12)) === null || _getSelf2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_getSelf2, Foo, _m).call(_getSelf2); - (_self4 = (_ref13 = (_o10 = o) === null || _o10 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o10.Foo, Foo, _self).getSelf()) === null || _ref13 === void 0 ? void 0 : _ref13.self) === null || _self4 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_self4, Foo, _m).call(_self4); - (_call$self = (_ref14 = (_o11 = o) === null || _o11 === void 0 ? void 0 : (_classStaticPrivateFi2 = _classStaticPrivateFieldSpecGet(_o11.Foo, Foo, _self)).getSelf) === null || _ref14 === void 0 ? void 0 : (_ref14$call = _ref14.call(_classStaticPrivateFi2)) === null || _ref14$call === void 0 ? void 0 : _ref14$call.self) === null || _call$self === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_call$self, Foo, _m).call(_call$self); - (_getSelf$self = (_ref15 = (_o12 = o) === null || _o12 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o12.Foo, Foo, _self)) === null || _ref15 === void 0 ? void 0 : (_ref15$getSelf = _ref15.getSelf()) === null || _ref15$getSelf === void 0 ? void 0 : _ref15$getSelf.self) === null || _getSelf$self === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_getSelf$self, Foo, _m).call(_getSelf$self); - (_getSelf$self2 = (_ref16 = (_o13 = o) === null || _o13 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o13.Foo, Foo, _self)) === null || _ref16 === void 0 ? void 0 : (_ref16$getSelf = _ref16.getSelf) === null || _ref16$getSelf === void 0 ? void 0 : (_ref16$getSelf$call = _ref16$getSelf.call(_ref16)) === null || _ref16$getSelf$call === void 0 ? void 0 : _ref16$getSelf$call.self) === null || _getSelf$self2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_getSelf$self2, Foo, _m).call(_getSelf$self2); + (_ref = o === null || o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(o.Foo, Foo, _self)) === null || _ref === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref, Foo, _m).call(_ref); + (_ref2 = o === null || o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(o.Foo, Foo, _self).self) === null || _ref2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref2, Foo, _m).call(_ref2); + (_self2 = (_ref7 = o === null || o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(o.Foo, Foo, _self)) === null || _ref7 === void 0 ? void 0 : _ref7.self) === null || _self2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_self2, Foo, _m).call(_self2); + (_self3 = (_ref8 = o === null || o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(o.Foo, Foo, _self).self) === null || _ref8 === void 0 ? void 0 : _ref8.self) === null || _self3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_self3, Foo, _m).call(_self3); + (_self$self = (_ref9 = o === null || o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(o.Foo, Foo, _self)) === null || _ref9 === void 0 ? void 0 : (_ref9$self = _ref9.self) === null || _ref9$self === void 0 ? void 0 : _ref9$self.self) === null || _self$self === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_self$self, Foo, _m).call(_self$self); + (_ref3 = o === null || o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(o.Foo, Foo, _self).getSelf()) === null || _ref3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref3, Foo, _m).call(_ref3); + (_call = (_ref10 = o === null || o === void 0 ? void 0 : (_classStaticPrivateFi = _classStaticPrivateFieldSpecGet(o.Foo, Foo, _self)).getSelf) === null || _ref10 === void 0 ? void 0 : _ref10.call(_classStaticPrivateFi)) === null || _call === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_call, Foo, _m).call(_call); + (_getSelf = (_ref11 = o === null || o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(o.Foo, Foo, _self)) === null || _ref11 === void 0 ? void 0 : _ref11.getSelf()) === null || _getSelf === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_getSelf, Foo, _m).call(_getSelf); + (_getSelf2 = (_ref12 = o === null || o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(o.Foo, Foo, _self)) === null || _ref12 === void 0 ? void 0 : (_ref12$getSelf = _ref12.getSelf) === null || _ref12$getSelf === void 0 ? void 0 : _ref12$getSelf.call(_ref12)) === null || _getSelf2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_getSelf2, Foo, _m).call(_getSelf2); + (_self4 = (_ref13 = o === null || o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(o.Foo, Foo, _self).getSelf()) === null || _ref13 === void 0 ? void 0 : _ref13.self) === null || _self4 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_self4, Foo, _m).call(_self4); + (_call$self = (_ref14 = o === null || o === void 0 ? void 0 : (_classStaticPrivateFi2 = _classStaticPrivateFieldSpecGet(o.Foo, Foo, _self)).getSelf) === null || _ref14 === void 0 ? void 0 : (_ref14$call = _ref14.call(_classStaticPrivateFi2)) === null || _ref14$call === void 0 ? void 0 : _ref14$call.self) === null || _call$self === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_call$self, Foo, _m).call(_call$self); + (_getSelf$self = (_ref15 = o === null || o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(o.Foo, Foo, _self)) === null || _ref15 === void 0 ? void 0 : (_ref15$getSelf = _ref15.getSelf()) === null || _ref15$getSelf === void 0 ? void 0 : _ref15$getSelf.self) === null || _getSelf$self === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_getSelf$self, Foo, _m).call(_getSelf$self); + (_getSelf$self2 = (_ref16 = o === null || o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(o.Foo, Foo, _self)) === null || _ref16 === void 0 ? void 0 : (_ref16$getSelf = _ref16.getSelf) === null || _ref16$getSelf === void 0 ? void 0 : (_ref16$getSelf$call = _ref16$getSelf.call(_ref16)) === null || _ref16$getSelf$call === void 0 ? void 0 : _ref16$getSelf$call.self) === null || _getSelf$self2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_getSelf$self2, Foo, _m).call(_getSelf$self2); (_fn$Foo = fn === null || fn === void 0 ? void 0 : fn().Foo) === null || _fn$Foo === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn$Foo, Foo, _m).call(_fn$Foo); (_fn$Foo2 = fn === null || fn === void 0 ? void 0 : fn().Foo) === null || _fn$Foo2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn$Foo2, Foo, _m).call(_fn$Foo2).toString; (_fn$Foo3 = fn === null || fn === void 0 ? void 0 : fn().Foo) === null || _fn$Foo3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn$Foo3, Foo, _m).call(_fn$Foo3).toString(); (_fnDeep$very$o$Foo = fnDeep === null || fnDeep === void 0 ? void 0 : (_fnDeep$very$o = fnDeep().very.o) === null || _fnDeep$very$o === void 0 ? void 0 : _fnDeep$very$o.Foo) === null || _fnDeep$very$o$Foo === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fnDeep$very$o$Foo, Foo, _m).call(_fnDeep$very$o$Foo); (_fnDeep$very$o$Foo2 = fnDeep === null || fnDeep === void 0 ? void 0 : (_fnDeep$very$o2 = fnDeep().very.o) === null || _fnDeep$very$o2 === void 0 ? void 0 : _fnDeep$very$o2.Foo) === null || _fnDeep$very$o$Foo2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fnDeep$very$o$Foo2, Foo, _m).call(_fnDeep$very$o$Foo2).toString; (_fnDeep$very$o$Foo3 = fnDeep === null || fnDeep === void 0 ? void 0 : (_fnDeep$very$o3 = fnDeep().very.o) === null || _fnDeep$very$o3 === void 0 ? void 0 : _fnDeep$very$o3.Foo) === null || _fnDeep$very$o$Foo3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fnDeep$very$o$Foo3, Foo, _m).call(_fnDeep$very$o$Foo3).toString(); - (_ref4 = (_fn = fn) === null || _fn === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn().Foo, Foo, _self)) === null || _ref4 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref4, Foo, _m).call(_ref4); - (_ref5 = (_fn2 = fn) === null || _fn2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn2().Foo, Foo, _self).self) === null || _ref5 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref5, Foo, _m).call(_ref5); - (_self5 = (_ref17 = (_fn3 = fn) === null || _fn3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn3().Foo, Foo, _self)) === null || _ref17 === void 0 ? void 0 : _ref17.self) === null || _self5 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_self5, Foo, _m).call(_self5); - (_self6 = (_ref18 = (_fn4 = fn) === null || _fn4 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn4().Foo, Foo, _self).self) === null || _ref18 === void 0 ? void 0 : _ref18.self) === null || _self6 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_self6, Foo, _m).call(_self6); - (_self$self2 = (_ref19 = (_fn5 = fn) === null || _fn5 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn5().Foo, Foo, _self)) === null || _ref19 === void 0 ? void 0 : (_ref19$self = _ref19.self) === null || _ref19$self === void 0 ? void 0 : _ref19$self.self) === null || _self$self2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_self$self2, Foo, _m).call(_self$self2); - (_ref6 = (_fn6 = fn) === null || _fn6 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn6().Foo, Foo, _self).getSelf()) === null || _ref6 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref6, Foo, _m).call(_ref6); - (_call2 = (_ref20 = (_fn7 = fn) === null || _fn7 === void 0 ? void 0 : (_classStaticPrivateFi3 = _classStaticPrivateFieldSpecGet(_fn7().Foo, Foo, _self)).getSelf) === null || _ref20 === void 0 ? void 0 : _ref20.call(_classStaticPrivateFi3)) === null || _call2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_call2, Foo, _m).call(_call2); - (_getSelf3 = (_ref21 = (_fn8 = fn) === null || _fn8 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn8().Foo, Foo, _self)) === null || _ref21 === void 0 ? void 0 : _ref21.getSelf()) === null || _getSelf3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_getSelf3, Foo, _m).call(_getSelf3); - (_getSelf4 = (_ref22 = (_fn9 = fn) === null || _fn9 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn9().Foo, Foo, _self)) === null || _ref22 === void 0 ? void 0 : (_ref22$getSelf = _ref22.getSelf) === null || _ref22$getSelf === void 0 ? void 0 : _ref22$getSelf.call(_ref22)) === null || _getSelf4 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_getSelf4, Foo, _m).call(_getSelf4); - (_self7 = (_ref23 = (_fn10 = fn) === null || _fn10 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn10().Foo, Foo, _self).getSelf()) === null || _ref23 === void 0 ? void 0 : _ref23.self) === null || _self7 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_self7, Foo, _m).call(_self7); - (_call$self2 = (_ref24 = (_fn11 = fn) === null || _fn11 === void 0 ? void 0 : (_classStaticPrivateFi4 = _classStaticPrivateFieldSpecGet(_fn11().Foo, Foo, _self)).getSelf) === null || _ref24 === void 0 ? void 0 : (_ref24$call = _ref24.call(_classStaticPrivateFi4)) === null || _ref24$call === void 0 ? void 0 : _ref24$call.self) === null || _call$self2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_call$self2, Foo, _m).call(_call$self2); - (_getSelf$self3 = (_ref25 = (_fn12 = fn) === null || _fn12 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn12().Foo, Foo, _self)) === null || _ref25 === void 0 ? void 0 : (_ref25$getSelf = _ref25.getSelf()) === null || _ref25$getSelf === void 0 ? void 0 : _ref25$getSelf.self) === null || _getSelf$self3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_getSelf$self3, Foo, _m).call(_getSelf$self3); - (_getSelf$self4 = (_ref26 = (_fn13 = fn) === null || _fn13 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn13().Foo, Foo, _self)) === null || _ref26 === void 0 ? void 0 : (_ref26$getSelf = _ref26.getSelf) === null || _ref26$getSelf === void 0 ? void 0 : (_ref26$getSelf$call = _ref26$getSelf.call(_ref26)) === null || _ref26$getSelf$call === void 0 ? void 0 : _ref26$getSelf$call.self) === null || _getSelf$self4 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_getSelf$self4, Foo, _m).call(_getSelf$self4); + (_ref4 = fn === null || fn === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(fn().Foo, Foo, _self)) === null || _ref4 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref4, Foo, _m).call(_ref4); + (_ref5 = fn === null || fn === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(fn().Foo, Foo, _self).self) === null || _ref5 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref5, Foo, _m).call(_ref5); + (_self5 = (_ref17 = fn === null || fn === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(fn().Foo, Foo, _self)) === null || _ref17 === void 0 ? void 0 : _ref17.self) === null || _self5 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_self5, Foo, _m).call(_self5); + (_self6 = (_ref18 = fn === null || fn === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(fn().Foo, Foo, _self).self) === null || _ref18 === void 0 ? void 0 : _ref18.self) === null || _self6 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_self6, Foo, _m).call(_self6); + (_self$self2 = (_ref19 = fn === null || fn === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(fn().Foo, Foo, _self)) === null || _ref19 === void 0 ? void 0 : (_ref19$self = _ref19.self) === null || _ref19$self === void 0 ? void 0 : _ref19$self.self) === null || _self$self2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_self$self2, Foo, _m).call(_self$self2); + (_ref6 = fn === null || fn === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(fn().Foo, Foo, _self).getSelf()) === null || _ref6 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref6, Foo, _m).call(_ref6); + (_call2 = (_ref20 = fn === null || fn === void 0 ? void 0 : (_classStaticPrivateFi3 = _classStaticPrivateFieldSpecGet(fn().Foo, Foo, _self)).getSelf) === null || _ref20 === void 0 ? void 0 : _ref20.call(_classStaticPrivateFi3)) === null || _call2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_call2, Foo, _m).call(_call2); + (_getSelf3 = (_ref21 = fn === null || fn === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(fn().Foo, Foo, _self)) === null || _ref21 === void 0 ? void 0 : _ref21.getSelf()) === null || _getSelf3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_getSelf3, Foo, _m).call(_getSelf3); + (_getSelf4 = (_ref22 = fn === null || fn === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(fn().Foo, Foo, _self)) === null || _ref22 === void 0 ? void 0 : (_ref22$getSelf = _ref22.getSelf) === null || _ref22$getSelf === void 0 ? void 0 : _ref22$getSelf.call(_ref22)) === null || _getSelf4 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_getSelf4, Foo, _m).call(_getSelf4); + (_self7 = (_ref23 = fn === null || fn === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(fn().Foo, Foo, _self).getSelf()) === null || _ref23 === void 0 ? void 0 : _ref23.self) === null || _self7 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_self7, Foo, _m).call(_self7); + (_call$self2 = (_ref24 = fn === null || fn === void 0 ? void 0 : (_classStaticPrivateFi4 = _classStaticPrivateFieldSpecGet(fn().Foo, Foo, _self)).getSelf) === null || _ref24 === void 0 ? void 0 : (_ref24$call = _ref24.call(_classStaticPrivateFi4)) === null || _ref24$call === void 0 ? void 0 : _ref24$call.self) === null || _call$self2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_call$self2, Foo, _m).call(_call$self2); + (_getSelf$self3 = (_ref25 = fn === null || fn === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(fn().Foo, Foo, _self)) === null || _ref25 === void 0 ? void 0 : (_ref25$getSelf = _ref25.getSelf()) === null || _ref25$getSelf === void 0 ? void 0 : _ref25$getSelf.self) === null || _getSelf$self3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_getSelf$self3, Foo, _m).call(_getSelf$self3); + (_getSelf$self4 = (_ref26 = fn === null || fn === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(fn().Foo, Foo, _self)) === null || _ref26 === void 0 ? void 0 : (_ref26$getSelf = _ref26.getSelf) === null || _ref26$getSelf === void 0 ? void 0 : (_ref26$getSelf$call = _ref26$getSelf.call(_ref26)) === null || _ref26$getSelf$call === void 0 ? void 0 : _ref26$getSelf$call.self) === null || _getSelf$self4 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_getSelf$self4, Foo, _m).call(_getSelf$self4); } } diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-optional-member-call/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-optional-member-call/output.js index bce199186f44..c5d75bcaca63 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-optional-member-call/output.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-optional-member-call/output.js @@ -8,7 +8,7 @@ class Foo { } static test() { - var _Foo, _Foo2, _Foo3, _o, _o$Foo, _o2, _o2$Foo, _o3, _o3$Foo, _deep$very$o, _deep$very$o$Foo, _deep$very$o2, _deep$very$o2$Foo, _deep$very$o3, _deep$very$o3$Foo, _o4, _classStaticPrivateFi, _o5, _classStaticPrivateFi2, _o6, _ref, _ref$self, _o7, _ref2, _ref2$self, _o8, _self2, _self2$self, _o9, _classStaticPrivateFi3, _o10, _classStaticPrivateFi4, _ref3, _ref3$call, _o11, _ref4, _ref4$getSelf, _o12, _getSelf, _ref5, _getSelf$call, _o13, _ref6, _ref6$self, _o14, _classStaticPrivateFi5, _call, _call$self, _o15, _getSelf2, _getSelf2$self, _o16, _getSelf3, _getSelf3$self, _fn, _fn$Foo, _fn2, _fn2$Foo, _fn3, _fn3$Foo, _fnDeep$very$o, _fnDeep$very$o$Foo, _fnDeep$very$o2, _fnDeep$very$o2$Foo, _fnDeep$very$o3, _fnDeep$very$o3$Foo, _fn4, _classStaticPrivateFi6, _fn5, _classStaticPrivateFi7, _fn6, _ref7, _ref7$self, _fn7, _ref8, _ref8$self, _fn8, _self3, _self3$self, _fn9, _classStaticPrivateFi8, _fn10, _classStaticPrivateFi9, _ref9, _ref9$call, _fn11, _ref10, _ref10$getSelf, _fn12, _getSelf4, _ref11, _getSelf4$call, _fn13, _ref12, _ref12$self, _fn14, _classStaticPrivateFi10, _call2, _call2$self, _fn15, _getSelf5, _getSelf5$self, _fn16, _getSelf6, _getSelf6$self; + var _o$Foo, _o$Foo2, _o$Foo3, _deep$very$o, _deep$very$o$Foo, _deep$very$o2, _deep$very$o2$Foo, _deep$very$o3, _deep$very$o3$Foo, _classStaticPrivateFi, _classStaticPrivateFi2, _ref, _ref$self, _ref2, _ref2$self, _self2, _self2$self, _classStaticPrivateFi3, _classStaticPrivateFi4, _ref3, _ref3$call, _ref4, _ref4$getSelf, _getSelf, _ref5, _getSelf$call, _ref6, _ref6$self, _classStaticPrivateFi5, _call, _call$self, _getSelf2, _getSelf2$self, _getSelf3, _getSelf3$self, _fn$Foo, _fn$Foo2, _fn$Foo3, _fnDeep$very$o, _fnDeep$very$o$Foo, _fnDeep$very$o2, _fnDeep$very$o2$Foo, _fnDeep$very$o3, _fnDeep$very$o3$Foo, _classStaticPrivateFi6, _classStaticPrivateFi7, _ref7, _ref7$self, _ref8, _ref8$self, _self3, _self3$self, _classStaticPrivateFi8, _classStaticPrivateFi9, _ref9, _ref9$call, _ref10, _ref10$getSelf, _getSelf4, _ref11, _getSelf4$call, _ref12, _ref12$self, _classStaticPrivateFi10, _call2, _call2$self, _getSelf5, _getSelf5$self, _getSelf6, _getSelf6$self; const o = { Foo: Foo @@ -27,47 +27,47 @@ class Foo { return deep; } - (_Foo = Foo) === null || _Foo === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_Foo, Foo, _m).call(_Foo); - (_Foo2 = Foo) === null || _Foo2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_Foo2, Foo, _m).call(_Foo2).toString; - (_Foo3 = Foo) === null || _Foo3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_Foo3, Foo, _m).call(_Foo3).toString(); - (_o = o) === null || _o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o$Foo = _o.Foo, Foo, _m).call(_o$Foo); - (_o2 = o) === null || _o2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o2$Foo = _o2.Foo, Foo, _m).call(_o2$Foo).toString; - (_o3 = o) === null || _o3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o3$Foo = _o3.Foo, Foo, _m).call(_o3$Foo).toString(); + Foo === null || Foo === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(Foo, Foo, _m).call(Foo); + Foo === null || Foo === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(Foo, Foo, _m).call(Foo).toString; + Foo === null || Foo === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(Foo, Foo, _m).call(Foo).toString(); + o === null || o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o$Foo = o.Foo, Foo, _m).call(_o$Foo); + o === null || o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o$Foo2 = o.Foo, Foo, _m).call(_o$Foo2).toString; + o === null || o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o$Foo3 = o.Foo, Foo, _m).call(_o$Foo3).toString(); (_deep$very$o = deep?.very.o) === null || _deep$very$o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_deep$very$o$Foo = _deep$very$o.Foo, Foo, _m).call(_deep$very$o$Foo); (_deep$very$o2 = deep?.very.o) === null || _deep$very$o2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_deep$very$o2$Foo = _deep$very$o2.Foo, Foo, _m).call(_deep$very$o2$Foo).toString; (_deep$very$o3 = deep?.very.o) === null || _deep$very$o3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_deep$very$o3$Foo = _deep$very$o3.Foo, Foo, _m).call(_deep$very$o3$Foo).toString(); - (_o4 = o) === null || _o4 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFi = _classStaticPrivateFieldSpecGet(_o4.Foo, Foo, _self), Foo, _m).call(_classStaticPrivateFi); - (_o5 = o) === null || _o5 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFi2 = _classStaticPrivateFieldSpecGet(_o5.Foo, Foo, _self).self, Foo, _m).call(_classStaticPrivateFi2); - (_ref = (_o6 = o) === null || _o6 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o6.Foo, Foo, _self)) === null || _ref === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref$self = _ref.self, Foo, _m).call(_ref$self); - (_ref2 = (_o7 = o) === null || _o7 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o7.Foo, Foo, _self).self) === null || _ref2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref2$self = _ref2.self, Foo, _m).call(_ref2$self); - (_self2 = ((_o8 = o) === null || _o8 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o8.Foo, Foo, _self))?.self) === null || _self2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_self2$self = _self2.self, Foo, _m).call(_self2$self); - (_o9 = o) === null || _o9 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFi3 = _classStaticPrivateFieldSpecGet(_o9.Foo, Foo, _self).getSelf(), Foo, _m).call(_classStaticPrivateFi3); - (_ref3 = (_o10 = o) === null || _o10 === void 0 ? void 0 : (_classStaticPrivateFi4 = _classStaticPrivateFieldSpecGet(_o10.Foo, Foo, _self)).getSelf) === null || _ref3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref3$call = _ref3.call(_classStaticPrivateFi4), Foo, _m).call(_ref3$call); - (_ref4 = (_o11 = o) === null || _o11 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o11.Foo, Foo, _self)) === null || _ref4 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref4$getSelf = _ref4.getSelf(), Foo, _m).call(_ref4$getSelf); - (_getSelf = (_ref5 = (_o12 = o) === null || _o12 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o12.Foo, Foo, _self))?.getSelf) === null || _getSelf === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_getSelf$call = _getSelf.call(_ref5), Foo, _m).call(_getSelf$call); - (_ref6 = (_o13 = o) === null || _o13 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o13.Foo, Foo, _self).getSelf()) === null || _ref6 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref6$self = _ref6.self, Foo, _m).call(_ref6$self); - (_call = ((_o14 = o) === null || _o14 === void 0 ? void 0 : (_classStaticPrivateFi5 = _classStaticPrivateFieldSpecGet(_o14.Foo, Foo, _self)).getSelf)?.call(_classStaticPrivateFi5)) === null || _call === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_call$self = _call.self, Foo, _m).call(_call$self); - (_getSelf2 = ((_o15 = o) === null || _o15 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o15.Foo, Foo, _self))?.getSelf()) === null || _getSelf2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_getSelf2$self = _getSelf2.self, Foo, _m).call(_getSelf2$self); - (_getSelf3 = ((_o16 = o) === null || _o16 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o16.Foo, Foo, _self))?.getSelf?.()) === null || _getSelf3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_getSelf3$self = _getSelf3.self, Foo, _m).call(_getSelf3$self); - (_fn = fn) === null || _fn === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn$Foo = _fn().Foo, Foo, _m).call(_fn$Foo); - (_fn2 = fn) === null || _fn2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn2$Foo = _fn2().Foo, Foo, _m).call(_fn2$Foo).toString; - (_fn3 = fn) === null || _fn3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn3$Foo = _fn3().Foo, Foo, _m).call(_fn3$Foo).toString(); + o === null || o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFi = _classStaticPrivateFieldSpecGet(o.Foo, Foo, _self), Foo, _m).call(_classStaticPrivateFi); + o === null || o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFi2 = _classStaticPrivateFieldSpecGet(o.Foo, Foo, _self).self, Foo, _m).call(_classStaticPrivateFi2); + (_ref = o === null || o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(o.Foo, Foo, _self)) === null || _ref === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref$self = _ref.self, Foo, _m).call(_ref$self); + (_ref2 = o === null || o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(o.Foo, Foo, _self).self) === null || _ref2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref2$self = _ref2.self, Foo, _m).call(_ref2$self); + (_self2 = (o === null || o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(o.Foo, Foo, _self))?.self) === null || _self2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_self2$self = _self2.self, Foo, _m).call(_self2$self); + o === null || o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFi3 = _classStaticPrivateFieldSpecGet(o.Foo, Foo, _self).getSelf(), Foo, _m).call(_classStaticPrivateFi3); + (_ref3 = o === null || o === void 0 ? void 0 : (_classStaticPrivateFi4 = _classStaticPrivateFieldSpecGet(o.Foo, Foo, _self)).getSelf) === null || _ref3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref3$call = _ref3.call(_classStaticPrivateFi4), Foo, _m).call(_ref3$call); + (_ref4 = o === null || o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(o.Foo, Foo, _self)) === null || _ref4 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref4$getSelf = _ref4.getSelf(), Foo, _m).call(_ref4$getSelf); + (_getSelf = (_ref5 = o === null || o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(o.Foo, Foo, _self))?.getSelf) === null || _getSelf === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_getSelf$call = _getSelf.call(_ref5), Foo, _m).call(_getSelf$call); + (_ref6 = o === null || o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(o.Foo, Foo, _self).getSelf()) === null || _ref6 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref6$self = _ref6.self, Foo, _m).call(_ref6$self); + (_call = (o === null || o === void 0 ? void 0 : (_classStaticPrivateFi5 = _classStaticPrivateFieldSpecGet(o.Foo, Foo, _self)).getSelf)?.call(_classStaticPrivateFi5)) === null || _call === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_call$self = _call.self, Foo, _m).call(_call$self); + (_getSelf2 = (o === null || o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(o.Foo, Foo, _self))?.getSelf()) === null || _getSelf2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_getSelf2$self = _getSelf2.self, Foo, _m).call(_getSelf2$self); + (_getSelf3 = (o === null || o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(o.Foo, Foo, _self))?.getSelf?.()) === null || _getSelf3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_getSelf3$self = _getSelf3.self, Foo, _m).call(_getSelf3$self); + fn === null || fn === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn$Foo = fn().Foo, Foo, _m).call(_fn$Foo); + fn === null || fn === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn$Foo2 = fn().Foo, Foo, _m).call(_fn$Foo2).toString; + fn === null || fn === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn$Foo3 = fn().Foo, Foo, _m).call(_fn$Foo3).toString(); (_fnDeep$very$o = fnDeep?.().very.o) === null || _fnDeep$very$o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fnDeep$very$o$Foo = _fnDeep$very$o.Foo, Foo, _m).call(_fnDeep$very$o$Foo); (_fnDeep$very$o2 = fnDeep?.().very.o) === null || _fnDeep$very$o2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fnDeep$very$o2$Foo = _fnDeep$very$o2.Foo, Foo, _m).call(_fnDeep$very$o2$Foo).toString; (_fnDeep$very$o3 = fnDeep?.().very.o) === null || _fnDeep$very$o3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fnDeep$very$o3$Foo = _fnDeep$very$o3.Foo, Foo, _m).call(_fnDeep$very$o3$Foo).toString(); - (_fn4 = fn) === null || _fn4 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFi6 = _classStaticPrivateFieldSpecGet(_fn4().Foo, Foo, _self), Foo, _m).call(_classStaticPrivateFi6); - (_fn5 = fn) === null || _fn5 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFi7 = _classStaticPrivateFieldSpecGet(_fn5().Foo, Foo, _self).self, Foo, _m).call(_classStaticPrivateFi7); - (_ref7 = (_fn6 = fn) === null || _fn6 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn6().Foo, Foo, _self)) === null || _ref7 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref7$self = _ref7.self, Foo, _m).call(_ref7$self); - (_ref8 = (_fn7 = fn) === null || _fn7 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn7().Foo, Foo, _self).self) === null || _ref8 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref8$self = _ref8.self, Foo, _m).call(_ref8$self); - (_self3 = ((_fn8 = fn) === null || _fn8 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn8().Foo, Foo, _self))?.self) === null || _self3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_self3$self = _self3.self, Foo, _m).call(_self3$self); - (_fn9 = fn) === null || _fn9 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFi8 = _classStaticPrivateFieldSpecGet(_fn9().Foo, Foo, _self).getSelf(), Foo, _m).call(_classStaticPrivateFi8); - (_ref9 = (_fn10 = fn) === null || _fn10 === void 0 ? void 0 : (_classStaticPrivateFi9 = _classStaticPrivateFieldSpecGet(_fn10().Foo, Foo, _self)).getSelf) === null || _ref9 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref9$call = _ref9.call(_classStaticPrivateFi9), Foo, _m).call(_ref9$call); - (_ref10 = (_fn11 = fn) === null || _fn11 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn11().Foo, Foo, _self)) === null || _ref10 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref10$getSelf = _ref10.getSelf(), Foo, _m).call(_ref10$getSelf); - (_getSelf4 = (_ref11 = (_fn12 = fn) === null || _fn12 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn12().Foo, Foo, _self))?.getSelf) === null || _getSelf4 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_getSelf4$call = _getSelf4.call(_ref11), Foo, _m).call(_getSelf4$call); - (_ref12 = (_fn13 = fn) === null || _fn13 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn13().Foo, Foo, _self).getSelf()) === null || _ref12 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref12$self = _ref12.self, Foo, _m).call(_ref12$self); - (_call2 = ((_fn14 = fn) === null || _fn14 === void 0 ? void 0 : (_classStaticPrivateFi10 = _classStaticPrivateFieldSpecGet(_fn14().Foo, Foo, _self)).getSelf)?.call(_classStaticPrivateFi10)) === null || _call2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_call2$self = _call2.self, Foo, _m).call(_call2$self); - (_getSelf5 = ((_fn15 = fn) === null || _fn15 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn15().Foo, Foo, _self))?.getSelf()) === null || _getSelf5 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_getSelf5$self = _getSelf5.self, Foo, _m).call(_getSelf5$self); - (_getSelf6 = ((_fn16 = fn) === null || _fn16 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn16().Foo, Foo, _self))?.getSelf?.()) === null || _getSelf6 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_getSelf6$self = _getSelf6.self, Foo, _m).call(_getSelf6$self); + fn === null || fn === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFi6 = _classStaticPrivateFieldSpecGet(fn().Foo, Foo, _self), Foo, _m).call(_classStaticPrivateFi6); + fn === null || fn === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFi7 = _classStaticPrivateFieldSpecGet(fn().Foo, Foo, _self).self, Foo, _m).call(_classStaticPrivateFi7); + (_ref7 = fn === null || fn === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(fn().Foo, Foo, _self)) === null || _ref7 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref7$self = _ref7.self, Foo, _m).call(_ref7$self); + (_ref8 = fn === null || fn === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(fn().Foo, Foo, _self).self) === null || _ref8 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref8$self = _ref8.self, Foo, _m).call(_ref8$self); + (_self3 = (fn === null || fn === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(fn().Foo, Foo, _self))?.self) === null || _self3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_self3$self = _self3.self, Foo, _m).call(_self3$self); + fn === null || fn === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFi8 = _classStaticPrivateFieldSpecGet(fn().Foo, Foo, _self).getSelf(), Foo, _m).call(_classStaticPrivateFi8); + (_ref9 = fn === null || fn === void 0 ? void 0 : (_classStaticPrivateFi9 = _classStaticPrivateFieldSpecGet(fn().Foo, Foo, _self)).getSelf) === null || _ref9 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref9$call = _ref9.call(_classStaticPrivateFi9), Foo, _m).call(_ref9$call); + (_ref10 = fn === null || fn === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(fn().Foo, Foo, _self)) === null || _ref10 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref10$getSelf = _ref10.getSelf(), Foo, _m).call(_ref10$getSelf); + (_getSelf4 = (_ref11 = fn === null || fn === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(fn().Foo, Foo, _self))?.getSelf) === null || _getSelf4 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_getSelf4$call = _getSelf4.call(_ref11), Foo, _m).call(_getSelf4$call); + (_ref12 = fn === null || fn === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(fn().Foo, Foo, _self).getSelf()) === null || _ref12 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref12$self = _ref12.self, Foo, _m).call(_ref12$self); + (_call2 = (fn === null || fn === void 0 ? void 0 : (_classStaticPrivateFi10 = _classStaticPrivateFieldSpecGet(fn().Foo, Foo, _self)).getSelf)?.call(_classStaticPrivateFi10)) === null || _call2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_call2$self = _call2.self, Foo, _m).call(_call2$self); + (_getSelf5 = (fn === null || fn === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(fn().Foo, Foo, _self))?.getSelf()) === null || _getSelf5 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_getSelf5$self = _getSelf5.self, Foo, _m).call(_getSelf5$self); + (_getSelf6 = (fn === null || fn === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(fn().Foo, Foo, _self))?.getSelf?.()) === null || _getSelf6 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_getSelf6$self = _getSelf6.self, Foo, _m).call(_getSelf6$self); } } diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-optional-property-with-transform/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-optional-property-with-transform/output.js index 71d124ad5550..be682ce43b57 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-optional-property-with-transform/output.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-optional-property-with-transform/output.js @@ -8,7 +8,7 @@ class Foo { } static test() { - var _Foo, _Foo2, _Foo3, _o$Foo, _o$Foo2, _o$Foo3, _deep$very$o$Foo, _deep$very$o$Foo2, _deep$very$o$Foo3, _o, _ref, _o2, _ref2, _o3, _self2, _o4, _self3, _o5, _self$self, _o6, _ref3, _o7, _classStaticPrivateFi, _call, _o8, _getSelf, _o9, _getSelf2, _o10, _self4, _o11, _classStaticPrivateFi2, _call$self, _o12, _getSelf$self, _o13, _getSelf$self2, _fn$Foo, _fn$Foo2, _fn$Foo3, _fnDeep$very$o$Foo, _fnDeep$very$o$Foo2, _fnDeep$very$o$Foo3, _fn, _ref4, _fn2, _ref5, _fn3, _self5, _fn4, _self6, _fn5, _self$self2, _fn6, _ref6, _fn7, _classStaticPrivateFi3, _call2, _fn8, _getSelf3, _fn9, _getSelf4, _fn10, _self7, _fn11, _classStaticPrivateFi4, _call$self2, _fn12, _getSelf$self3, _fn13, _getSelf$self4, _deep$very$o, _deep$very$o2, _deep$very$o3, _ref7, _ref8, _ref9, _ref9$self, _ref10, _ref11, _ref12, _ref12$getSelf, _ref13, _ref14, _ref14$call, _ref15, _ref15$getSelf, _ref16, _ref16$getSelf, _ref16$getSelf$call, _fnDeep$very$o, _fnDeep$very$o2, _fnDeep$very$o3, _ref17, _ref18, _ref19, _ref19$self, _ref20, _ref21, _ref22, _ref22$getSelf, _ref23, _ref24, _ref24$call, _ref25, _ref25$getSelf, _ref26, _ref26$getSelf, _ref26$getSelf$call; + var _o$Foo, _o$Foo2, _o$Foo3, _deep$very$o$Foo, _deep$very$o$Foo2, _deep$very$o$Foo3, _ref, _ref2, _self2, _self3, _self$self, _ref3, _classStaticPrivateFi, _call, _getSelf, _getSelf2, _self4, _classStaticPrivateFi2, _call$self, _getSelf$self, _getSelf$self2, _fn$Foo, _fn$Foo2, _fn$Foo3, _fnDeep$very$o$Foo, _fnDeep$very$o$Foo2, _fnDeep$very$o$Foo3, _ref4, _ref5, _self5, _self6, _self$self2, _ref6, _classStaticPrivateFi3, _call2, _getSelf3, _getSelf4, _self7, _classStaticPrivateFi4, _call$self2, _getSelf$self3, _getSelf$self4, _deep$very$o, _deep$very$o2, _deep$very$o3, _ref7, _ref8, _ref9, _ref9$self, _ref10, _ref11, _ref12, _ref12$getSelf, _ref13, _ref14, _ref14$call, _ref15, _ref15$getSelf, _ref16, _ref16$getSelf, _ref16$getSelf$call, _fnDeep$very$o, _fnDeep$very$o2, _fnDeep$very$o3, _ref17, _ref18, _ref19, _ref19$self, _ref20, _ref21, _ref22, _ref22$getSelf, _ref23, _ref24, _ref24$call, _ref25, _ref25$getSelf, _ref26, _ref26$getSelf, _ref26$getSelf$call; const o = { Foo: Foo @@ -27,47 +27,47 @@ class Foo { return deep; } - (_Foo = Foo) === null || _Foo === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_Foo, Foo, _x); - (_Foo2 = Foo) === null || _Foo2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_Foo2, Foo, _x).toString; - (_Foo3 = Foo) === null || _Foo3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_Foo3, Foo, _x).toString(); + Foo === null || Foo === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(Foo, Foo, _x); + Foo === null || Foo === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(Foo, Foo, _x).toString; + Foo === null || Foo === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(Foo, Foo, _x).toString(); (_o$Foo = o === null || o === void 0 ? void 0 : o.Foo) === null || _o$Foo === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o$Foo, Foo, _x); (_o$Foo2 = o === null || o === void 0 ? void 0 : o.Foo) === null || _o$Foo2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o$Foo2, Foo, _x).toString; (_o$Foo3 = o === null || o === void 0 ? void 0 : o.Foo) === null || _o$Foo3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o$Foo3, Foo, _x).toString(); (_deep$very$o$Foo = deep === null || deep === void 0 ? void 0 : (_deep$very$o = deep.very.o) === null || _deep$very$o === void 0 ? void 0 : _deep$very$o.Foo) === null || _deep$very$o$Foo === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_deep$very$o$Foo, Foo, _x); (_deep$very$o$Foo2 = deep === null || deep === void 0 ? void 0 : (_deep$very$o2 = deep.very.o) === null || _deep$very$o2 === void 0 ? void 0 : _deep$very$o2.Foo) === null || _deep$very$o$Foo2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_deep$very$o$Foo2, Foo, _x).toString; (_deep$very$o$Foo3 = deep === null || deep === void 0 ? void 0 : (_deep$very$o3 = deep.very.o) === null || _deep$very$o3 === void 0 ? void 0 : _deep$very$o3.Foo) === null || _deep$very$o$Foo3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_deep$very$o$Foo3, Foo, _x).toString(); - (_ref = (_o = o) === null || _o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o.Foo, Foo, _self)) === null || _ref === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref, Foo, _x); - (_ref2 = (_o2 = o) === null || _o2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o2.Foo, Foo, _self).self) === null || _ref2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref2, Foo, _x); - (_self2 = (_ref7 = (_o3 = o) === null || _o3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o3.Foo, Foo, _self)) === null || _ref7 === void 0 ? void 0 : _ref7.self) === null || _self2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_self2, Foo, _x); - (_self3 = (_ref8 = (_o4 = o) === null || _o4 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o4.Foo, Foo, _self).self) === null || _ref8 === void 0 ? void 0 : _ref8.self) === null || _self3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_self3, Foo, _x); - (_self$self = (_ref9 = (_o5 = o) === null || _o5 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o5.Foo, Foo, _self)) === null || _ref9 === void 0 ? void 0 : (_ref9$self = _ref9.self) === null || _ref9$self === void 0 ? void 0 : _ref9$self.self) === null || _self$self === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_self$self, Foo, _x); - (_ref3 = (_o6 = o) === null || _o6 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o6.Foo, Foo, _self).getSelf()) === null || _ref3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref3, Foo, _x); - (_call = (_ref10 = (_o7 = o) === null || _o7 === void 0 ? void 0 : (_classStaticPrivateFi = _classStaticPrivateFieldSpecGet(_o7.Foo, Foo, _self)).getSelf) === null || _ref10 === void 0 ? void 0 : _ref10.call(_classStaticPrivateFi)) === null || _call === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_call, Foo, _x); - (_getSelf = (_ref11 = (_o8 = o) === null || _o8 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o8.Foo, Foo, _self)) === null || _ref11 === void 0 ? void 0 : _ref11.getSelf()) === null || _getSelf === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_getSelf, Foo, _x); - (_getSelf2 = (_ref12 = (_o9 = o) === null || _o9 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o9.Foo, Foo, _self)) === null || _ref12 === void 0 ? void 0 : (_ref12$getSelf = _ref12.getSelf) === null || _ref12$getSelf === void 0 ? void 0 : _ref12$getSelf.call(_ref12)) === null || _getSelf2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_getSelf2, Foo, _x); - (_self4 = (_ref13 = (_o10 = o) === null || _o10 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o10.Foo, Foo, _self).getSelf()) === null || _ref13 === void 0 ? void 0 : _ref13.self) === null || _self4 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_self4, Foo, _x); - (_call$self = (_ref14 = (_o11 = o) === null || _o11 === void 0 ? void 0 : (_classStaticPrivateFi2 = _classStaticPrivateFieldSpecGet(_o11.Foo, Foo, _self)).getSelf) === null || _ref14 === void 0 ? void 0 : (_ref14$call = _ref14.call(_classStaticPrivateFi2)) === null || _ref14$call === void 0 ? void 0 : _ref14$call.self) === null || _call$self === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_call$self, Foo, _x); - (_getSelf$self = (_ref15 = (_o12 = o) === null || _o12 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o12.Foo, Foo, _self)) === null || _ref15 === void 0 ? void 0 : (_ref15$getSelf = _ref15.getSelf()) === null || _ref15$getSelf === void 0 ? void 0 : _ref15$getSelf.self) === null || _getSelf$self === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_getSelf$self, Foo, _x); - (_getSelf$self2 = (_ref16 = (_o13 = o) === null || _o13 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o13.Foo, Foo, _self)) === null || _ref16 === void 0 ? void 0 : (_ref16$getSelf = _ref16.getSelf) === null || _ref16$getSelf === void 0 ? void 0 : (_ref16$getSelf$call = _ref16$getSelf.call(_ref16)) === null || _ref16$getSelf$call === void 0 ? void 0 : _ref16$getSelf$call.self) === null || _getSelf$self2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_getSelf$self2, Foo, _x); + (_ref = o === null || o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(o.Foo, Foo, _self)) === null || _ref === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref, Foo, _x); + (_ref2 = o === null || o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(o.Foo, Foo, _self).self) === null || _ref2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref2, Foo, _x); + (_self2 = (_ref7 = o === null || o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(o.Foo, Foo, _self)) === null || _ref7 === void 0 ? void 0 : _ref7.self) === null || _self2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_self2, Foo, _x); + (_self3 = (_ref8 = o === null || o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(o.Foo, Foo, _self).self) === null || _ref8 === void 0 ? void 0 : _ref8.self) === null || _self3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_self3, Foo, _x); + (_self$self = (_ref9 = o === null || o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(o.Foo, Foo, _self)) === null || _ref9 === void 0 ? void 0 : (_ref9$self = _ref9.self) === null || _ref9$self === void 0 ? void 0 : _ref9$self.self) === null || _self$self === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_self$self, Foo, _x); + (_ref3 = o === null || o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(o.Foo, Foo, _self).getSelf()) === null || _ref3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref3, Foo, _x); + (_call = (_ref10 = o === null || o === void 0 ? void 0 : (_classStaticPrivateFi = _classStaticPrivateFieldSpecGet(o.Foo, Foo, _self)).getSelf) === null || _ref10 === void 0 ? void 0 : _ref10.call(_classStaticPrivateFi)) === null || _call === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_call, Foo, _x); + (_getSelf = (_ref11 = o === null || o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(o.Foo, Foo, _self)) === null || _ref11 === void 0 ? void 0 : _ref11.getSelf()) === null || _getSelf === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_getSelf, Foo, _x); + (_getSelf2 = (_ref12 = o === null || o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(o.Foo, Foo, _self)) === null || _ref12 === void 0 ? void 0 : (_ref12$getSelf = _ref12.getSelf) === null || _ref12$getSelf === void 0 ? void 0 : _ref12$getSelf.call(_ref12)) === null || _getSelf2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_getSelf2, Foo, _x); + (_self4 = (_ref13 = o === null || o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(o.Foo, Foo, _self).getSelf()) === null || _ref13 === void 0 ? void 0 : _ref13.self) === null || _self4 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_self4, Foo, _x); + (_call$self = (_ref14 = o === null || o === void 0 ? void 0 : (_classStaticPrivateFi2 = _classStaticPrivateFieldSpecGet(o.Foo, Foo, _self)).getSelf) === null || _ref14 === void 0 ? void 0 : (_ref14$call = _ref14.call(_classStaticPrivateFi2)) === null || _ref14$call === void 0 ? void 0 : _ref14$call.self) === null || _call$self === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_call$self, Foo, _x); + (_getSelf$self = (_ref15 = o === null || o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(o.Foo, Foo, _self)) === null || _ref15 === void 0 ? void 0 : (_ref15$getSelf = _ref15.getSelf()) === null || _ref15$getSelf === void 0 ? void 0 : _ref15$getSelf.self) === null || _getSelf$self === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_getSelf$self, Foo, _x); + (_getSelf$self2 = (_ref16 = o === null || o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(o.Foo, Foo, _self)) === null || _ref16 === void 0 ? void 0 : (_ref16$getSelf = _ref16.getSelf) === null || _ref16$getSelf === void 0 ? void 0 : (_ref16$getSelf$call = _ref16$getSelf.call(_ref16)) === null || _ref16$getSelf$call === void 0 ? void 0 : _ref16$getSelf$call.self) === null || _getSelf$self2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_getSelf$self2, Foo, _x); (_fn$Foo = fn === null || fn === void 0 ? void 0 : fn().Foo) === null || _fn$Foo === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn$Foo, Foo, _x); (_fn$Foo2 = fn === null || fn === void 0 ? void 0 : fn().Foo) === null || _fn$Foo2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn$Foo2, Foo, _x).toString; (_fn$Foo3 = fn === null || fn === void 0 ? void 0 : fn().Foo) === null || _fn$Foo3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn$Foo3, Foo, _x).toString(); (_fnDeep$very$o$Foo = fnDeep === null || fnDeep === void 0 ? void 0 : (_fnDeep$very$o = fnDeep().very.o) === null || _fnDeep$very$o === void 0 ? void 0 : _fnDeep$very$o.Foo) === null || _fnDeep$very$o$Foo === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fnDeep$very$o$Foo, Foo, _x); (_fnDeep$very$o$Foo2 = fnDeep === null || fnDeep === void 0 ? void 0 : (_fnDeep$very$o2 = fnDeep().very.o) === null || _fnDeep$very$o2 === void 0 ? void 0 : _fnDeep$very$o2.Foo) === null || _fnDeep$very$o$Foo2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fnDeep$very$o$Foo2, Foo, _x).toString; (_fnDeep$very$o$Foo3 = fnDeep === null || fnDeep === void 0 ? void 0 : (_fnDeep$very$o3 = fnDeep().very.o) === null || _fnDeep$very$o3 === void 0 ? void 0 : _fnDeep$very$o3.Foo) === null || _fnDeep$very$o$Foo3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fnDeep$very$o$Foo3, Foo, _x).toString(); - (_ref4 = (_fn = fn) === null || _fn === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn().Foo, Foo, _self)) === null || _ref4 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref4, Foo, _x); - (_ref5 = (_fn2 = fn) === null || _fn2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn2().Foo, Foo, _self).self) === null || _ref5 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref5, Foo, _x); - (_self5 = (_ref17 = (_fn3 = fn) === null || _fn3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn3().Foo, Foo, _self)) === null || _ref17 === void 0 ? void 0 : _ref17.self) === null || _self5 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_self5, Foo, _x); - (_self6 = (_ref18 = (_fn4 = fn) === null || _fn4 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn4().Foo, Foo, _self).self) === null || _ref18 === void 0 ? void 0 : _ref18.self) === null || _self6 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_self6, Foo, _x); - (_self$self2 = (_ref19 = (_fn5 = fn) === null || _fn5 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn5().Foo, Foo, _self)) === null || _ref19 === void 0 ? void 0 : (_ref19$self = _ref19.self) === null || _ref19$self === void 0 ? void 0 : _ref19$self.self) === null || _self$self2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_self$self2, Foo, _x); - (_ref6 = (_fn6 = fn) === null || _fn6 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn6().Foo, Foo, _self).getSelf()) === null || _ref6 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref6, Foo, _x); - (_call2 = (_ref20 = (_fn7 = fn) === null || _fn7 === void 0 ? void 0 : (_classStaticPrivateFi3 = _classStaticPrivateFieldSpecGet(_fn7().Foo, Foo, _self)).getSelf) === null || _ref20 === void 0 ? void 0 : _ref20.call(_classStaticPrivateFi3)) === null || _call2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_call2, Foo, _x); - (_getSelf3 = (_ref21 = (_fn8 = fn) === null || _fn8 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn8().Foo, Foo, _self)) === null || _ref21 === void 0 ? void 0 : _ref21.getSelf()) === null || _getSelf3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_getSelf3, Foo, _x); - (_getSelf4 = (_ref22 = (_fn9 = fn) === null || _fn9 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn9().Foo, Foo, _self)) === null || _ref22 === void 0 ? void 0 : (_ref22$getSelf = _ref22.getSelf) === null || _ref22$getSelf === void 0 ? void 0 : _ref22$getSelf.call(_ref22)) === null || _getSelf4 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_getSelf4, Foo, _x); - (_self7 = (_ref23 = (_fn10 = fn) === null || _fn10 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn10().Foo, Foo, _self).getSelf()) === null || _ref23 === void 0 ? void 0 : _ref23.self) === null || _self7 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_self7, Foo, _x); - (_call$self2 = (_ref24 = (_fn11 = fn) === null || _fn11 === void 0 ? void 0 : (_classStaticPrivateFi4 = _classStaticPrivateFieldSpecGet(_fn11().Foo, Foo, _self)).getSelf) === null || _ref24 === void 0 ? void 0 : (_ref24$call = _ref24.call(_classStaticPrivateFi4)) === null || _ref24$call === void 0 ? void 0 : _ref24$call.self) === null || _call$self2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_call$self2, Foo, _x); - (_getSelf$self3 = (_ref25 = (_fn12 = fn) === null || _fn12 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn12().Foo, Foo, _self)) === null || _ref25 === void 0 ? void 0 : (_ref25$getSelf = _ref25.getSelf()) === null || _ref25$getSelf === void 0 ? void 0 : _ref25$getSelf.self) === null || _getSelf$self3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_getSelf$self3, Foo, _x); - (_getSelf$self4 = (_ref26 = (_fn13 = fn) === null || _fn13 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn13().Foo, Foo, _self)) === null || _ref26 === void 0 ? void 0 : (_ref26$getSelf = _ref26.getSelf) === null || _ref26$getSelf === void 0 ? void 0 : (_ref26$getSelf$call = _ref26$getSelf.call(_ref26)) === null || _ref26$getSelf$call === void 0 ? void 0 : _ref26$getSelf$call.self) === null || _getSelf$self4 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_getSelf$self4, Foo, _x); + (_ref4 = fn === null || fn === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(fn().Foo, Foo, _self)) === null || _ref4 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref4, Foo, _x); + (_ref5 = fn === null || fn === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(fn().Foo, Foo, _self).self) === null || _ref5 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref5, Foo, _x); + (_self5 = (_ref17 = fn === null || fn === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(fn().Foo, Foo, _self)) === null || _ref17 === void 0 ? void 0 : _ref17.self) === null || _self5 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_self5, Foo, _x); + (_self6 = (_ref18 = fn === null || fn === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(fn().Foo, Foo, _self).self) === null || _ref18 === void 0 ? void 0 : _ref18.self) === null || _self6 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_self6, Foo, _x); + (_self$self2 = (_ref19 = fn === null || fn === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(fn().Foo, Foo, _self)) === null || _ref19 === void 0 ? void 0 : (_ref19$self = _ref19.self) === null || _ref19$self === void 0 ? void 0 : _ref19$self.self) === null || _self$self2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_self$self2, Foo, _x); + (_ref6 = fn === null || fn === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(fn().Foo, Foo, _self).getSelf()) === null || _ref6 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref6, Foo, _x); + (_call2 = (_ref20 = fn === null || fn === void 0 ? void 0 : (_classStaticPrivateFi3 = _classStaticPrivateFieldSpecGet(fn().Foo, Foo, _self)).getSelf) === null || _ref20 === void 0 ? void 0 : _ref20.call(_classStaticPrivateFi3)) === null || _call2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_call2, Foo, _x); + (_getSelf3 = (_ref21 = fn === null || fn === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(fn().Foo, Foo, _self)) === null || _ref21 === void 0 ? void 0 : _ref21.getSelf()) === null || _getSelf3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_getSelf3, Foo, _x); + (_getSelf4 = (_ref22 = fn === null || fn === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(fn().Foo, Foo, _self)) === null || _ref22 === void 0 ? void 0 : (_ref22$getSelf = _ref22.getSelf) === null || _ref22$getSelf === void 0 ? void 0 : _ref22$getSelf.call(_ref22)) === null || _getSelf4 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_getSelf4, Foo, _x); + (_self7 = (_ref23 = fn === null || fn === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(fn().Foo, Foo, _self).getSelf()) === null || _ref23 === void 0 ? void 0 : _ref23.self) === null || _self7 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_self7, Foo, _x); + (_call$self2 = (_ref24 = fn === null || fn === void 0 ? void 0 : (_classStaticPrivateFi4 = _classStaticPrivateFieldSpecGet(fn().Foo, Foo, _self)).getSelf) === null || _ref24 === void 0 ? void 0 : (_ref24$call = _ref24.call(_classStaticPrivateFi4)) === null || _ref24$call === void 0 ? void 0 : _ref24$call.self) === null || _call$self2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_call$self2, Foo, _x); + (_getSelf$self3 = (_ref25 = fn === null || fn === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(fn().Foo, Foo, _self)) === null || _ref25 === void 0 ? void 0 : (_ref25$getSelf = _ref25.getSelf()) === null || _ref25$getSelf === void 0 ? void 0 : _ref25$getSelf.self) === null || _getSelf$self3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_getSelf$self3, Foo, _x); + (_getSelf$self4 = (_ref26 = fn === null || fn === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(fn().Foo, Foo, _self)) === null || _ref26 === void 0 ? void 0 : (_ref26$getSelf = _ref26.getSelf) === null || _ref26$getSelf === void 0 ? void 0 : (_ref26$getSelf$call = _ref26$getSelf.call(_ref26)) === null || _ref26$getSelf$call === void 0 ? void 0 : _ref26$getSelf$call.self) === null || _getSelf$self4 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_getSelf$self4, Foo, _x); } } diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-optional-property/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-optional-property/output.js index b095f6df78af..de6a92dd23e0 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-optional-property/output.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-optional-property/output.js @@ -8,7 +8,7 @@ class Foo { } static test() { - var _Foo, _Foo2, _Foo3, _o$Foo, _o$Foo2, _o$Foo3, _deep$very$o$Foo, _deep$very$o$Foo2, _deep$very$o$Foo3, _o, _ref, _o2, _ref2, _o3, _self2, _o4, _self3, _o5, _self$self, _o6, _ref3, _o7, _classStaticPrivateFi, _call, _o8, _getSelf, _o9, _getSelf2, _o10, _self4, _o11, _classStaticPrivateFi2, _call$self, _o12, _getSelf$self, _o13, _getSelf$self2, _fn$Foo, _fn$Foo2, _fn$Foo3, _fnDeep$very$o$Foo, _fnDeep$very$o$Foo2, _fnDeep$very$o$Foo3, _fn, _ref4, _fn2, _ref5, _fn3, _self5, _fn4, _self6, _fn5, _self$self2, _fn6, _ref6, _fn7, _classStaticPrivateFi3, _call2, _fn8, _getSelf3, _fn9, _getSelf4, _fn10, _self7, _fn11, _classStaticPrivateFi4, _call$self2, _fn12, _getSelf$self3, _fn13, _getSelf$self4; + var _o$Foo, _o$Foo2, _o$Foo3, _deep$very$o$Foo, _deep$very$o$Foo2, _deep$very$o$Foo3, _ref, _ref2, _self2, _self3, _self$self, _ref3, _classStaticPrivateFi, _call, _getSelf, _getSelf2, _self4, _classStaticPrivateFi2, _call$self, _getSelf$self, _getSelf$self2, _fn$Foo, _fn$Foo2, _fn$Foo3, _fnDeep$very$o$Foo, _fnDeep$very$o$Foo2, _fnDeep$very$o$Foo3, _ref4, _ref5, _self5, _self6, _self$self2, _ref6, _classStaticPrivateFi3, _call2, _getSelf3, _getSelf4, _self7, _classStaticPrivateFi4, _call$self2, _getSelf$self3, _getSelf$self4; const o = { Foo: Foo @@ -27,47 +27,47 @@ class Foo { return deep; } - (_Foo = Foo) === null || _Foo === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_Foo, Foo, _x); - (_Foo2 = Foo) === null || _Foo2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_Foo2, Foo, _x).toString; - (_Foo3 = Foo) === null || _Foo3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_Foo3, Foo, _x).toString(); + Foo === null || Foo === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(Foo, Foo, _x); + Foo === null || Foo === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(Foo, Foo, _x).toString; + Foo === null || Foo === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(Foo, Foo, _x).toString(); (_o$Foo = o?.Foo) === null || _o$Foo === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o$Foo, Foo, _x); (_o$Foo2 = o?.Foo) === null || _o$Foo2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o$Foo2, Foo, _x).toString; (_o$Foo3 = o?.Foo) === null || _o$Foo3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o$Foo3, Foo, _x).toString(); (_deep$very$o$Foo = deep?.very.o?.Foo) === null || _deep$very$o$Foo === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_deep$very$o$Foo, Foo, _x); (_deep$very$o$Foo2 = deep?.very.o?.Foo) === null || _deep$very$o$Foo2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_deep$very$o$Foo2, Foo, _x).toString; (_deep$very$o$Foo3 = deep?.very.o?.Foo) === null || _deep$very$o$Foo3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_deep$very$o$Foo3, Foo, _x).toString(); - (_ref = (_o = o) === null || _o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o.Foo, Foo, _self)) === null || _ref === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref, Foo, _x); - (_ref2 = (_o2 = o) === null || _o2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o2.Foo, Foo, _self).self) === null || _ref2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref2, Foo, _x); - (_self2 = ((_o3 = o) === null || _o3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o3.Foo, Foo, _self))?.self) === null || _self2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_self2, Foo, _x); - (_self3 = ((_o4 = o) === null || _o4 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o4.Foo, Foo, _self).self)?.self) === null || _self3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_self3, Foo, _x); - (_self$self = ((_o5 = o) === null || _o5 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o5.Foo, Foo, _self))?.self?.self) === null || _self$self === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_self$self, Foo, _x); - (_ref3 = (_o6 = o) === null || _o6 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o6.Foo, Foo, _self).getSelf()) === null || _ref3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref3, Foo, _x); - (_call = ((_o7 = o) === null || _o7 === void 0 ? void 0 : (_classStaticPrivateFi = _classStaticPrivateFieldSpecGet(_o7.Foo, Foo, _self)).getSelf)?.call(_classStaticPrivateFi)) === null || _call === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_call, Foo, _x); - (_getSelf = ((_o8 = o) === null || _o8 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o8.Foo, Foo, _self))?.getSelf()) === null || _getSelf === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_getSelf, Foo, _x); - (_getSelf2 = ((_o9 = o) === null || _o9 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o9.Foo, Foo, _self))?.getSelf?.()) === null || _getSelf2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_getSelf2, Foo, _x); - (_self4 = ((_o10 = o) === null || _o10 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o10.Foo, Foo, _self).getSelf())?.self) === null || _self4 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_self4, Foo, _x); - (_call$self = ((_o11 = o) === null || _o11 === void 0 ? void 0 : (_classStaticPrivateFi2 = _classStaticPrivateFieldSpecGet(_o11.Foo, Foo, _self)).getSelf)?.call(_classStaticPrivateFi2)?.self) === null || _call$self === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_call$self, Foo, _x); - (_getSelf$self = ((_o12 = o) === null || _o12 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o12.Foo, Foo, _self))?.getSelf()?.self) === null || _getSelf$self === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_getSelf$self, Foo, _x); - (_getSelf$self2 = ((_o13 = o) === null || _o13 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o13.Foo, Foo, _self))?.getSelf?.()?.self) === null || _getSelf$self2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_getSelf$self2, Foo, _x); + (_ref = o === null || o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(o.Foo, Foo, _self)) === null || _ref === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref, Foo, _x); + (_ref2 = o === null || o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(o.Foo, Foo, _self).self) === null || _ref2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref2, Foo, _x); + (_self2 = (o === null || o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(o.Foo, Foo, _self))?.self) === null || _self2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_self2, Foo, _x); + (_self3 = (o === null || o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(o.Foo, Foo, _self).self)?.self) === null || _self3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_self3, Foo, _x); + (_self$self = (o === null || o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(o.Foo, Foo, _self))?.self?.self) === null || _self$self === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_self$self, Foo, _x); + (_ref3 = o === null || o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(o.Foo, Foo, _self).getSelf()) === null || _ref3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref3, Foo, _x); + (_call = (o === null || o === void 0 ? void 0 : (_classStaticPrivateFi = _classStaticPrivateFieldSpecGet(o.Foo, Foo, _self)).getSelf)?.call(_classStaticPrivateFi)) === null || _call === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_call, Foo, _x); + (_getSelf = (o === null || o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(o.Foo, Foo, _self))?.getSelf()) === null || _getSelf === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_getSelf, Foo, _x); + (_getSelf2 = (o === null || o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(o.Foo, Foo, _self))?.getSelf?.()) === null || _getSelf2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_getSelf2, Foo, _x); + (_self4 = (o === null || o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(o.Foo, Foo, _self).getSelf())?.self) === null || _self4 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_self4, Foo, _x); + (_call$self = (o === null || o === void 0 ? void 0 : (_classStaticPrivateFi2 = _classStaticPrivateFieldSpecGet(o.Foo, Foo, _self)).getSelf)?.call(_classStaticPrivateFi2)?.self) === null || _call$self === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_call$self, Foo, _x); + (_getSelf$self = (o === null || o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(o.Foo, Foo, _self))?.getSelf()?.self) === null || _getSelf$self === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_getSelf$self, Foo, _x); + (_getSelf$self2 = (o === null || o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(o.Foo, Foo, _self))?.getSelf?.()?.self) === null || _getSelf$self2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_getSelf$self2, Foo, _x); (_fn$Foo = fn?.().Foo) === null || _fn$Foo === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn$Foo, Foo, _x); (_fn$Foo2 = fn?.().Foo) === null || _fn$Foo2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn$Foo2, Foo, _x).toString; (_fn$Foo3 = fn?.().Foo) === null || _fn$Foo3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn$Foo3, Foo, _x).toString(); (_fnDeep$very$o$Foo = fnDeep?.().very.o?.Foo) === null || _fnDeep$very$o$Foo === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fnDeep$very$o$Foo, Foo, _x); (_fnDeep$very$o$Foo2 = fnDeep?.().very.o?.Foo) === null || _fnDeep$very$o$Foo2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fnDeep$very$o$Foo2, Foo, _x).toString; (_fnDeep$very$o$Foo3 = fnDeep?.().very.o?.Foo) === null || _fnDeep$very$o$Foo3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fnDeep$very$o$Foo3, Foo, _x).toString(); - (_ref4 = (_fn = fn) === null || _fn === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn().Foo, Foo, _self)) === null || _ref4 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref4, Foo, _x); - (_ref5 = (_fn2 = fn) === null || _fn2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn2().Foo, Foo, _self).self) === null || _ref5 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref5, Foo, _x); - (_self5 = ((_fn3 = fn) === null || _fn3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn3().Foo, Foo, _self))?.self) === null || _self5 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_self5, Foo, _x); - (_self6 = ((_fn4 = fn) === null || _fn4 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn4().Foo, Foo, _self).self)?.self) === null || _self6 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_self6, Foo, _x); - (_self$self2 = ((_fn5 = fn) === null || _fn5 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn5().Foo, Foo, _self))?.self?.self) === null || _self$self2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_self$self2, Foo, _x); - (_ref6 = (_fn6 = fn) === null || _fn6 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn6().Foo, Foo, _self).getSelf()) === null || _ref6 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref6, Foo, _x); - (_call2 = ((_fn7 = fn) === null || _fn7 === void 0 ? void 0 : (_classStaticPrivateFi3 = _classStaticPrivateFieldSpecGet(_fn7().Foo, Foo, _self)).getSelf)?.call(_classStaticPrivateFi3)) === null || _call2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_call2, Foo, _x); - (_getSelf3 = ((_fn8 = fn) === null || _fn8 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn8().Foo, Foo, _self))?.getSelf()) === null || _getSelf3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_getSelf3, Foo, _x); - (_getSelf4 = ((_fn9 = fn) === null || _fn9 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn9().Foo, Foo, _self))?.getSelf?.()) === null || _getSelf4 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_getSelf4, Foo, _x); - (_self7 = ((_fn10 = fn) === null || _fn10 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn10().Foo, Foo, _self).getSelf())?.self) === null || _self7 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_self7, Foo, _x); - (_call$self2 = ((_fn11 = fn) === null || _fn11 === void 0 ? void 0 : (_classStaticPrivateFi4 = _classStaticPrivateFieldSpecGet(_fn11().Foo, Foo, _self)).getSelf)?.call(_classStaticPrivateFi4)?.self) === null || _call$self2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_call$self2, Foo, _x); - (_getSelf$self3 = ((_fn12 = fn) === null || _fn12 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn12().Foo, Foo, _self))?.getSelf()?.self) === null || _getSelf$self3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_getSelf$self3, Foo, _x); - (_getSelf$self4 = ((_fn13 = fn) === null || _fn13 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn13().Foo, Foo, _self))?.getSelf?.()?.self) === null || _getSelf$self4 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_getSelf$self4, Foo, _x); + (_ref4 = fn === null || fn === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(fn().Foo, Foo, _self)) === null || _ref4 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref4, Foo, _x); + (_ref5 = fn === null || fn === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(fn().Foo, Foo, _self).self) === null || _ref5 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref5, Foo, _x); + (_self5 = (fn === null || fn === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(fn().Foo, Foo, _self))?.self) === null || _self5 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_self5, Foo, _x); + (_self6 = (fn === null || fn === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(fn().Foo, Foo, _self).self)?.self) === null || _self6 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_self6, Foo, _x); + (_self$self2 = (fn === null || fn === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(fn().Foo, Foo, _self))?.self?.self) === null || _self$self2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_self$self2, Foo, _x); + (_ref6 = fn === null || fn === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(fn().Foo, Foo, _self).getSelf()) === null || _ref6 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref6, Foo, _x); + (_call2 = (fn === null || fn === void 0 ? void 0 : (_classStaticPrivateFi3 = _classStaticPrivateFieldSpecGet(fn().Foo, Foo, _self)).getSelf)?.call(_classStaticPrivateFi3)) === null || _call2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_call2, Foo, _x); + (_getSelf3 = (fn === null || fn === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(fn().Foo, Foo, _self))?.getSelf()) === null || _getSelf3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_getSelf3, Foo, _x); + (_getSelf4 = (fn === null || fn === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(fn().Foo, Foo, _self))?.getSelf?.()) === null || _getSelf4 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_getSelf4, Foo, _x); + (_self7 = (fn === null || fn === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(fn().Foo, Foo, _self).getSelf())?.self) === null || _self7 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_self7, Foo, _x); + (_call$self2 = (fn === null || fn === void 0 ? void 0 : (_classStaticPrivateFi4 = _classStaticPrivateFieldSpecGet(fn().Foo, Foo, _self)).getSelf)?.call(_classStaticPrivateFi4)?.self) === null || _call$self2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_call$self2, Foo, _x); + (_getSelf$self3 = (fn === null || fn === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(fn().Foo, Foo, _self))?.getSelf()?.self) === null || _getSelf$self3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_getSelf$self3, Foo, _x); + (_getSelf$self4 = (fn === null || fn === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(fn().Foo, Foo, _self))?.getSelf?.()?.self) === null || _getSelf$self4 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_getSelf$self4, Foo, _x); } } From 55bdc001c06c17b5cc5807c62bf29d7150912eb0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hu=C3=A1ng=20J=C3=B9nli=C3=A0ng?= Date: Sun, 24 May 2020 18:05:17 -0400 Subject: [PATCH 15/20] test: add test cases for `#m?.()` --- .../exec.js | 126 +++++++++++++++++ .../input.js | 74 ++++++++++ .../options.json | 3 + .../output.js | 128 ++++++++++++++++++ .../exec.js | 126 +++++++++++++++++ .../input.js | 74 ++++++++++ .../options.json | 4 + .../output.js | 128 ++++++++++++++++++ 8 files changed, 663 insertions(+) create mode 100644 packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-member-optional-call-with-transform/exec.js create mode 100644 packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-member-optional-call-with-transform/input.js create mode 100644 packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-member-optional-call-with-transform/options.json create mode 100644 packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-member-optional-call-with-transform/output.js create mode 100644 packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-member-optional-call/exec.js create mode 100644 packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-member-optional-call/input.js create mode 100644 packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-member-optional-call/options.json create mode 100644 packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-member-optional-call/output.js diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-member-optional-call-with-transform/exec.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-member-optional-call-with-transform/exec.js new file mode 100644 index 000000000000..6e82fc8d6543 --- /dev/null +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-member-optional-call-with-transform/exec.js @@ -0,0 +1,126 @@ +class Foo { + static #x = 1; + static #m = function() { return this.#x; }; + static #self = Foo; + static self = Foo; + static getSelf() { return this } + + static test() { + 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(o?.Foo.#m?.()).toEqual(1); + expect(o?.Foo.#m?.().toString).toEqual(1..toString); + expect(o?.Foo.#m?.().toString()).toEqual('1'); + + expect(deep?.very.o?.Foo.#m?.()).toEqual(1); + expect(deep?.very.o?.Foo.#m?.().toString).toEqual(1..toString); + expect(deep?.very.o?.Foo.#m?.().toString()).toEqual('1'); + + expect(o?.Foo.#self.#m?.()).toEqual(1); + expect(o?.Foo.#self.self.#m?.()).toEqual(1); + expect(o?.Foo.#self?.self.#m?.()).toEqual(1); + expect(o?.Foo.#self.self?.self.#m?.()).toEqual(1); + expect(o?.Foo.#self?.self?.self.#m?.()).toEqual(1); + + expect(o?.Foo.#self.getSelf().#m?.()).toEqual(1); + expect(o?.Foo.#self.getSelf?.().#m?.()).toEqual(1); + expect(o?.Foo.#self?.getSelf().#m?.()).toEqual(1); + expect(o?.Foo.#self?.getSelf?.().#m?.()).toEqual(1); + expect(o?.Foo.#self.getSelf()?.self.#m?.()).toEqual(1); + expect(o?.Foo.#self.getSelf?.()?.self.#m?.()).toEqual(1); + expect(o?.Foo.#self?.getSelf()?.self.#m?.()).toEqual(1); + expect(o?.Foo.#self?.getSelf?.()?.self.#m?.()).toEqual(1); + + expect(fn?.().Foo.#m?.()).toEqual(1); + expect(fn?.().Foo.#m?.().toString).toEqual(1..toString); + expect(fn?.().Foo.#m?.().toString()).toEqual('1'); + + expect(fnDeep?.().very.o?.Foo.#m?.()).toEqual(1); + expect(fnDeep?.().very.o?.Foo.#m?.().toString).toEqual(1..toString); + expect(fnDeep?.().very.o?.Foo.#m?.().toString()).toEqual('1'); + + expect(fn?.().Foo.#self.#m?.()).toEqual(1); + expect(fn?.().Foo.#self.self.#m?.()).toEqual(1); + expect(fn?.().Foo.#self?.self.#m?.()).toEqual(1); + expect(fn?.().Foo.#self.self?.self.#m?.()).toEqual(1); + expect(fn?.().Foo.#self?.self?.self.#m?.()).toEqual(1); + + expect(fn?.().Foo.#self.getSelf().#m?.()).toEqual(1); + expect(fn?.().Foo.#self.getSelf?.().#m?.()).toEqual(1); + expect(fn?.().Foo.#self?.getSelf().#m?.()).toEqual(1); + expect(fn?.().Foo.#self?.getSelf?.().#m?.()).toEqual(1); + expect(fn?.().Foo.#self.getSelf()?.self.#m?.()).toEqual(1); + expect(fn?.().Foo.#self.getSelf?.()?.self.#m?.()).toEqual(1); + expect(fn?.().Foo.#self?.getSelf()?.self.#m?.()).toEqual(1); + expect(fn?.().Foo.#self?.getSelf?.()?.self.#m?.()).toEqual(1); + } + + static testNull() { + const o = null;; + const deep = { very: { o } }; + const fn = null; + function fnDeep() { + return deep; + } + + expect(o?.Foo.#m?.()).toEqual(undefined); + expect(o?.Foo.#m?.().toString).toEqual(undefined); + expect(o?.Foo.#m?.().toString()).toEqual(undefined); + + expect(deep?.very.o?.Foo.#m?.()).toEqual(undefined); + expect(deep?.very.o?.Foo.#m?.().toString).toEqual(undefined); + expect(deep?.very.o?.Foo.#m?.().toString()).toEqual(undefined); + + expect(o?.Foo.#self.#m?.()).toEqual(undefined); + expect(o?.Foo.#self.self.#m?.()).toEqual(undefined); + expect(o?.Foo.#self?.self.#m?.()).toEqual(undefined); + expect(o?.Foo.#self.self?.self.#m?.()).toEqual(undefined); + expect(o?.Foo.#self?.self?.self.#m?.()).toEqual(undefined); + + expect(o?.Foo.#self.getSelf().#m?.()).toEqual(undefined); + expect(o?.Foo.#self.getSelf?.().#m?.()).toEqual(undefined); + expect(o?.Foo.#self?.getSelf().#m?.()).toEqual(undefined); + expect(o?.Foo.#self?.getSelf?.().#m?.()).toEqual(undefined); + expect(o?.Foo.#self.getSelf()?.self.#m?.()).toEqual(undefined); + expect(o?.Foo.#self.getSelf?.()?.self.#m?.()).toEqual(undefined); + expect(o?.Foo.#self?.getSelf()?.self.#m?.()).toEqual(undefined); + expect(o?.Foo.#self?.getSelf?.()?.self.#m?.()).toEqual(undefined); + + expect(fn?.().Foo.#m?.()).toEqual(undefined); + expect(fn?.().Foo.#m?.().toString).toEqual(undefined); + expect(fn?.().Foo.#m?.().toString()).toEqual(undefined); + + expect(fnDeep?.().very.o?.Foo.#m?.()).toEqual(undefined); + expect(fnDeep?.().very.o?.Foo.#m?.().toString).toEqual(undefined); + expect(fnDeep?.().very.o?.Foo.#m?.().toString()).toEqual(undefined); + + expect(fn?.().Foo.#self.#m?.()).toEqual(undefined); + expect(fn?.().Foo.#self.self.#m?.()).toEqual(undefined); + expect(fn?.().Foo.#self?.self.#m?.()).toEqual(undefined); + expect(fn?.().Foo.#self.self?.self.#m?.()).toEqual(undefined); + expect(fn?.().Foo.#self?.self?.self.#m?.()).toEqual(undefined); + + expect(fn?.().Foo.#self.getSelf().#m?.()).toEqual(undefined); + expect(fn?.().Foo.#self.getSelf?.().#m?.()).toEqual(undefined); + expect(fn?.().Foo.#self?.getSelf().#m?.()).toEqual(undefined); + expect(fn?.().Foo.#self?.getSelf?.().#m?.()).toEqual(undefined); + expect(fn?.().Foo.#self.getSelf()?.self.#m?.()).toEqual(undefined); + expect(fn?.().Foo.#self.getSelf?.()?.self.#m?.()).toEqual(undefined); + expect(fn?.().Foo.#self?.getSelf()?.self.#m?.()).toEqual(undefined); + expect(fn?.().Foo.#self?.getSelf?.()?.self.#m?.()).toEqual(undefined); + } +} + +Foo.test(); +Foo.testNull(); diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-member-optional-call-with-transform/input.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-member-optional-call-with-transform/input.js new file mode 100644 index 000000000000..42d692812e9a --- /dev/null +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-member-optional-call-with-transform/input.js @@ -0,0 +1,74 @@ +class Foo { + static #x = 1; + static #m = function() { return this.#x; }; + static #self = Foo; + static self = Foo; + static getSelf() { return this } + + static test() { + const o = { Foo: Foo }; + const deep = { very: { o } }; + function fn() { + return o; + } + function fnDeep() { + return deep; + } + + Foo.#m?.(); + Foo.#m?.().toString; + Foo.#m?.().toString(); + + o?.Foo.#m?.(); + o?.Foo.#m?.().toString; + o?.Foo.#m?.().toString(); + + deep?.very.o?.Foo.#m?.(); + deep?.very.o?.Foo.#m?.().toString; + deep?.very.o?.Foo.#m?.().toString(); + + o?.Foo.#self.#m?.(); + o?.Foo.#self.self.#m?.(); + o?.Foo.#self?.self.#m?.(); + o?.Foo.#self.self?.self.#m?.(); + o?.Foo.#self?.self?.self.#m?.(); + + o?.Foo.#self.getSelf().#m?.(); + o?.Foo.#self.getSelf?.().#m?.(); + o?.Foo.#self?.getSelf().#m?.(); + o?.Foo.#self?.getSelf?.().#m?.(); + o?.Foo.#self.getSelf()?.self.#m?.(); + o?.Foo.#self.getSelf?.()?.self.#m?.(); + o?.Foo.#self?.getSelf()?.self.#m?.(); + o?.Foo.#self?.getSelf?.()?.self.#m?.(); + + fn?.().Foo.#m?.(); + fn?.().Foo.#m?.().toString; + fn?.().Foo.#m?.().toString(); + + fnDeep?.().very.o?.Foo.#m?.(); + fnDeep?.().very.o?.Foo.#m?.().toString; + fnDeep?.().very.o?.Foo.#m?.().toString(); + + fn?.().Foo.#self.#m?.(); + fn?.().Foo.#self.self.#m?.(); + fn?.().Foo.#self?.self.#m?.(); + fn?.().Foo.#self.self?.self.#m?.(); + fn?.().Foo.#self?.self?.self.#m?.(); + + fn?.().Foo.#self.getSelf().#m?.(); + fn?.().Foo.#self.getSelf?.().#m?.(); + fn?.().Foo.#self?.getSelf().#m?.(); + fn?.().Foo.#self?.getSelf?.().#m?.(); + fn?.().Foo.#self.getSelf()?.self.#m?.(); + fn?.().Foo.#self.getSelf?.()?.self.#m?.(); + fn?.().Foo.#self?.getSelf()?.self.#m?.(); + fn?.().Foo.#self?.getSelf?.()?.self.#m?.(); + } + + static testtest() { + fn?.().Foo.#self.getSelf?.().#m?.(); + } +} + +Foo.test(); diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-member-optional-call-with-transform/options.json b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-member-optional-call-with-transform/options.json new file mode 100644 index 000000000000..63b4c77cc8e8 --- /dev/null +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-member-optional-call-with-transform/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["proposal-optional-chaining", "proposal-class-properties"] +} diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-member-optional-call-with-transform/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-member-optional-call-with-transform/output.js new file mode 100644 index 000000000000..3eb9ff618c8a --- /dev/null +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-member-optional-call-with-transform/output.js @@ -0,0 +1,128 @@ +function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } + +function _classStaticPrivateFieldSpecGet(receiver, classConstructor, descriptor) { if (receiver !== classConstructor) { throw new TypeError("Private static access of wrong provenance"); } if (descriptor.get) { return descriptor.get.call(receiver); } return descriptor.value; } + +class Foo { + static getSelf() { + return this; + } + + static test() { + var _o$Foo, _o$Foo2, _o$Foo3, _deep$very$o, _deep$very$o$Foo, _deep$very$o2, _deep$very$o2$Foo, _deep$very$o3, _deep$very$o3$Foo, _classStaticPrivateFi, _classStaticPrivateFi2, _ref, _ref$self, _ref2, _ref2$self, _self2, _self2$self, _classStaticPrivateFi3, _classStaticPrivateFi4, _ref3, _ref3$call, _ref4, _ref4$getSelf, _getSelf, _ref5, _getSelf$call, _ref6, _ref6$self, _classStaticPrivateFi5, _call, _call$self, _getSelf2, _getSelf2$self, _getSelf3, _getSelf3$self, _fn$Foo, _fn$Foo2, _fn$Foo3, _fnDeep$very$o, _fnDeep$very$o$Foo, _fnDeep$very$o2, _fnDeep$very$o2$Foo, _fnDeep$very$o3, _fnDeep$very$o3$Foo, _classStaticPrivateFi6, _classStaticPrivateFi7, _ref7, _ref7$self, _ref8, _ref8$self, _self3, _self3$self, _classStaticPrivateFi8, _classStaticPrivateFi9, _ref9, _ref9$call, _ref10, _ref10$getSelf, _getSelf4, _ref11, _getSelf4$call, _ref12, _ref12$self, _classStaticPrivateFi10, _call2, _call2$self, _getSelf5, _getSelf5$self, _getSelf6, _getSelf6$self; + + const o = { + Foo: Foo + }; + const deep = { + very: { + o + } + }; + + function fn() { + return o; + } + + function fnDeep() { + return deep; + } + + _classStaticPrivateFieldSpecGet(Foo, Foo, _m)?.(); + _classStaticPrivateFieldSpecGet(Foo, Foo, _m)?.().toString; + _classStaticPrivateFieldSpecGet(Foo, Foo, _m)?.().toString(); + + _classStaticPrivateFieldSpecGet(_o$Foo = o.Foo, Foo, _m).call(_o$Foo); + + _classStaticPrivateFieldSpecGet(_o$Foo2 = o.Foo, Foo, _m).call(_o$Foo2).toString; + _classStaticPrivateFieldSpecGet(_o$Foo3 = o.Foo, Foo, _m).call(_o$Foo3).toString(); + + _classStaticPrivateFieldSpecGet(_deep$very$o$Foo = _deep$very$o.Foo, Foo, _m).call(_deep$very$o$Foo); + + _classStaticPrivateFieldSpecGet(_deep$very$o2$Foo = _deep$very$o2.Foo, Foo, _m).call(_deep$very$o2$Foo).toString; + _classStaticPrivateFieldSpecGet(_deep$very$o3$Foo = _deep$very$o3.Foo, Foo, _m).call(_deep$very$o3$Foo).toString(); + (o === null || o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFi = _classStaticPrivateFieldSpecGet(o.Foo, Foo, _self), Foo, _m))?.call(_classStaticPrivateFi); + (o === null || o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFi2 = _classStaticPrivateFieldSpecGet(o.Foo, Foo, _self).self, Foo, _m))?.call(_classStaticPrivateFi2); + + _classStaticPrivateFieldSpecGet(_ref$self = _ref.self, Foo, _m).call(_ref$self); + + _classStaticPrivateFieldSpecGet(_ref2$self = _ref2.self, Foo, _m).call(_ref2$self); + + _classStaticPrivateFieldSpecGet(_self2$self = _self2.self, Foo, _m).call(_self2$self); + + (o === null || o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFi3 = _classStaticPrivateFieldSpecGet(o.Foo, Foo, _self).getSelf(), Foo, _m))?.call(_classStaticPrivateFi3); + + _classStaticPrivateFieldSpecGet(_ref3$call = _ref3.call(_classStaticPrivateFi4), Foo, _m).call(_ref3$call); + + _classStaticPrivateFieldSpecGet(_ref4$getSelf = _ref4.getSelf(), Foo, _m).call(_ref4$getSelf); + + _classStaticPrivateFieldSpecGet(_getSelf$call = _getSelf.call(_ref5), Foo, _m).call(_getSelf$call); + + _classStaticPrivateFieldSpecGet(_ref6$self = _ref6.self, Foo, _m).call(_ref6$self); + + _classStaticPrivateFieldSpecGet(_call$self = _call.self, Foo, _m).call(_call$self); + + _classStaticPrivateFieldSpecGet(_getSelf2$self = _getSelf2.self, Foo, _m).call(_getSelf2$self); + + _classStaticPrivateFieldSpecGet(_getSelf3$self = _getSelf3.self, Foo, _m).call(_getSelf3$self); + + _classStaticPrivateFieldSpecGet(_fn$Foo = fn().Foo, Foo, _m).call(_fn$Foo); + + _classStaticPrivateFieldSpecGet(_fn$Foo2 = fn().Foo, Foo, _m).call(_fn$Foo2).toString; + _classStaticPrivateFieldSpecGet(_fn$Foo3 = fn().Foo, Foo, _m).call(_fn$Foo3).toString(); + + _classStaticPrivateFieldSpecGet(_fnDeep$very$o$Foo = _fnDeep$very$o.Foo, Foo, _m).call(_fnDeep$very$o$Foo); + + _classStaticPrivateFieldSpecGet(_fnDeep$very$o2$Foo = _fnDeep$very$o2.Foo, Foo, _m).call(_fnDeep$very$o2$Foo).toString; + _classStaticPrivateFieldSpecGet(_fnDeep$very$o3$Foo = _fnDeep$very$o3.Foo, Foo, _m).call(_fnDeep$very$o3$Foo).toString(); + (fn === null || fn === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFi6 = _classStaticPrivateFieldSpecGet(fn().Foo, Foo, _self), Foo, _m))?.call(_classStaticPrivateFi6); + (fn === null || fn === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFi7 = _classStaticPrivateFieldSpecGet(fn().Foo, Foo, _self).self, Foo, _m))?.call(_classStaticPrivateFi7); + + _classStaticPrivateFieldSpecGet(_ref7$self = _ref7.self, Foo, _m).call(_ref7$self); + + _classStaticPrivateFieldSpecGet(_ref8$self = _ref8.self, Foo, _m).call(_ref8$self); + + _classStaticPrivateFieldSpecGet(_self3$self = _self3.self, Foo, _m).call(_self3$self); + + (fn === null || fn === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFi8 = _classStaticPrivateFieldSpecGet(fn().Foo, Foo, _self).getSelf(), Foo, _m))?.call(_classStaticPrivateFi8); + + _classStaticPrivateFieldSpecGet(_ref9$call = _ref9.call(_classStaticPrivateFi9), Foo, _m).call(_ref9$call); + + _classStaticPrivateFieldSpecGet(_ref10$getSelf = _ref10.getSelf(), Foo, _m).call(_ref10$getSelf); + + _classStaticPrivateFieldSpecGet(_getSelf4$call = _getSelf4.call(_ref11), Foo, _m).call(_getSelf4$call); + + _classStaticPrivateFieldSpecGet(_ref12$self = _ref12.self, Foo, _m).call(_ref12$self); + + _classStaticPrivateFieldSpecGet(_call2$self = _call2.self, Foo, _m).call(_call2$self); + + _classStaticPrivateFieldSpecGet(_getSelf5$self = _getSelf5.self, Foo, _m).call(_getSelf5$self); + + _classStaticPrivateFieldSpecGet(_getSelf6$self = _getSelf6.self, Foo, _m).call(_getSelf6$self); + } + + static testtest() { + var _fn, _classStaticPrivateFi11, _ref13, _ref13$call; + + _classStaticPrivateFieldSpecGet(_ref13$call = _ref13.call(_classStaticPrivateFi11), Foo, _m).call(_ref13$call); + } + +} + +var _x = { + writable: true, + value: 1 +}; +var _m = { + writable: true, + value: function () { + return _classStaticPrivateFieldSpecGet(this, Foo, _x); + } +}; +var _self = { + writable: true, + value: Foo +}; + +_defineProperty(Foo, "self", Foo); + +Foo.test(); diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-member-optional-call/exec.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-member-optional-call/exec.js new file mode 100644 index 000000000000..6e82fc8d6543 --- /dev/null +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-member-optional-call/exec.js @@ -0,0 +1,126 @@ +class Foo { + static #x = 1; + static #m = function() { return this.#x; }; + static #self = Foo; + static self = Foo; + static getSelf() { return this } + + static test() { + 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(o?.Foo.#m?.()).toEqual(1); + expect(o?.Foo.#m?.().toString).toEqual(1..toString); + expect(o?.Foo.#m?.().toString()).toEqual('1'); + + expect(deep?.very.o?.Foo.#m?.()).toEqual(1); + expect(deep?.very.o?.Foo.#m?.().toString).toEqual(1..toString); + expect(deep?.very.o?.Foo.#m?.().toString()).toEqual('1'); + + expect(o?.Foo.#self.#m?.()).toEqual(1); + expect(o?.Foo.#self.self.#m?.()).toEqual(1); + expect(o?.Foo.#self?.self.#m?.()).toEqual(1); + expect(o?.Foo.#self.self?.self.#m?.()).toEqual(1); + expect(o?.Foo.#self?.self?.self.#m?.()).toEqual(1); + + expect(o?.Foo.#self.getSelf().#m?.()).toEqual(1); + expect(o?.Foo.#self.getSelf?.().#m?.()).toEqual(1); + expect(o?.Foo.#self?.getSelf().#m?.()).toEqual(1); + expect(o?.Foo.#self?.getSelf?.().#m?.()).toEqual(1); + expect(o?.Foo.#self.getSelf()?.self.#m?.()).toEqual(1); + expect(o?.Foo.#self.getSelf?.()?.self.#m?.()).toEqual(1); + expect(o?.Foo.#self?.getSelf()?.self.#m?.()).toEqual(1); + expect(o?.Foo.#self?.getSelf?.()?.self.#m?.()).toEqual(1); + + expect(fn?.().Foo.#m?.()).toEqual(1); + expect(fn?.().Foo.#m?.().toString).toEqual(1..toString); + expect(fn?.().Foo.#m?.().toString()).toEqual('1'); + + expect(fnDeep?.().very.o?.Foo.#m?.()).toEqual(1); + expect(fnDeep?.().very.o?.Foo.#m?.().toString).toEqual(1..toString); + expect(fnDeep?.().very.o?.Foo.#m?.().toString()).toEqual('1'); + + expect(fn?.().Foo.#self.#m?.()).toEqual(1); + expect(fn?.().Foo.#self.self.#m?.()).toEqual(1); + expect(fn?.().Foo.#self?.self.#m?.()).toEqual(1); + expect(fn?.().Foo.#self.self?.self.#m?.()).toEqual(1); + expect(fn?.().Foo.#self?.self?.self.#m?.()).toEqual(1); + + expect(fn?.().Foo.#self.getSelf().#m?.()).toEqual(1); + expect(fn?.().Foo.#self.getSelf?.().#m?.()).toEqual(1); + expect(fn?.().Foo.#self?.getSelf().#m?.()).toEqual(1); + expect(fn?.().Foo.#self?.getSelf?.().#m?.()).toEqual(1); + expect(fn?.().Foo.#self.getSelf()?.self.#m?.()).toEqual(1); + expect(fn?.().Foo.#self.getSelf?.()?.self.#m?.()).toEqual(1); + expect(fn?.().Foo.#self?.getSelf()?.self.#m?.()).toEqual(1); + expect(fn?.().Foo.#self?.getSelf?.()?.self.#m?.()).toEqual(1); + } + + static testNull() { + const o = null;; + const deep = { very: { o } }; + const fn = null; + function fnDeep() { + return deep; + } + + expect(o?.Foo.#m?.()).toEqual(undefined); + expect(o?.Foo.#m?.().toString).toEqual(undefined); + expect(o?.Foo.#m?.().toString()).toEqual(undefined); + + expect(deep?.very.o?.Foo.#m?.()).toEqual(undefined); + expect(deep?.very.o?.Foo.#m?.().toString).toEqual(undefined); + expect(deep?.very.o?.Foo.#m?.().toString()).toEqual(undefined); + + expect(o?.Foo.#self.#m?.()).toEqual(undefined); + expect(o?.Foo.#self.self.#m?.()).toEqual(undefined); + expect(o?.Foo.#self?.self.#m?.()).toEqual(undefined); + expect(o?.Foo.#self.self?.self.#m?.()).toEqual(undefined); + expect(o?.Foo.#self?.self?.self.#m?.()).toEqual(undefined); + + expect(o?.Foo.#self.getSelf().#m?.()).toEqual(undefined); + expect(o?.Foo.#self.getSelf?.().#m?.()).toEqual(undefined); + expect(o?.Foo.#self?.getSelf().#m?.()).toEqual(undefined); + expect(o?.Foo.#self?.getSelf?.().#m?.()).toEqual(undefined); + expect(o?.Foo.#self.getSelf()?.self.#m?.()).toEqual(undefined); + expect(o?.Foo.#self.getSelf?.()?.self.#m?.()).toEqual(undefined); + expect(o?.Foo.#self?.getSelf()?.self.#m?.()).toEqual(undefined); + expect(o?.Foo.#self?.getSelf?.()?.self.#m?.()).toEqual(undefined); + + expect(fn?.().Foo.#m?.()).toEqual(undefined); + expect(fn?.().Foo.#m?.().toString).toEqual(undefined); + expect(fn?.().Foo.#m?.().toString()).toEqual(undefined); + + expect(fnDeep?.().very.o?.Foo.#m?.()).toEqual(undefined); + expect(fnDeep?.().very.o?.Foo.#m?.().toString).toEqual(undefined); + expect(fnDeep?.().very.o?.Foo.#m?.().toString()).toEqual(undefined); + + expect(fn?.().Foo.#self.#m?.()).toEqual(undefined); + expect(fn?.().Foo.#self.self.#m?.()).toEqual(undefined); + expect(fn?.().Foo.#self?.self.#m?.()).toEqual(undefined); + expect(fn?.().Foo.#self.self?.self.#m?.()).toEqual(undefined); + expect(fn?.().Foo.#self?.self?.self.#m?.()).toEqual(undefined); + + expect(fn?.().Foo.#self.getSelf().#m?.()).toEqual(undefined); + expect(fn?.().Foo.#self.getSelf?.().#m?.()).toEqual(undefined); + expect(fn?.().Foo.#self?.getSelf().#m?.()).toEqual(undefined); + expect(fn?.().Foo.#self?.getSelf?.().#m?.()).toEqual(undefined); + expect(fn?.().Foo.#self.getSelf()?.self.#m?.()).toEqual(undefined); + expect(fn?.().Foo.#self.getSelf?.()?.self.#m?.()).toEqual(undefined); + expect(fn?.().Foo.#self?.getSelf()?.self.#m?.()).toEqual(undefined); + expect(fn?.().Foo.#self?.getSelf?.()?.self.#m?.()).toEqual(undefined); + } +} + +Foo.test(); +Foo.testNull(); diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-member-optional-call/input.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-member-optional-call/input.js new file mode 100644 index 000000000000..42d692812e9a --- /dev/null +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-member-optional-call/input.js @@ -0,0 +1,74 @@ +class Foo { + static #x = 1; + static #m = function() { return this.#x; }; + static #self = Foo; + static self = Foo; + static getSelf() { return this } + + static test() { + const o = { Foo: Foo }; + const deep = { very: { o } }; + function fn() { + return o; + } + function fnDeep() { + return deep; + } + + Foo.#m?.(); + Foo.#m?.().toString; + Foo.#m?.().toString(); + + o?.Foo.#m?.(); + o?.Foo.#m?.().toString; + o?.Foo.#m?.().toString(); + + deep?.very.o?.Foo.#m?.(); + deep?.very.o?.Foo.#m?.().toString; + deep?.very.o?.Foo.#m?.().toString(); + + o?.Foo.#self.#m?.(); + o?.Foo.#self.self.#m?.(); + o?.Foo.#self?.self.#m?.(); + o?.Foo.#self.self?.self.#m?.(); + o?.Foo.#self?.self?.self.#m?.(); + + o?.Foo.#self.getSelf().#m?.(); + o?.Foo.#self.getSelf?.().#m?.(); + o?.Foo.#self?.getSelf().#m?.(); + o?.Foo.#self?.getSelf?.().#m?.(); + o?.Foo.#self.getSelf()?.self.#m?.(); + o?.Foo.#self.getSelf?.()?.self.#m?.(); + o?.Foo.#self?.getSelf()?.self.#m?.(); + o?.Foo.#self?.getSelf?.()?.self.#m?.(); + + fn?.().Foo.#m?.(); + fn?.().Foo.#m?.().toString; + fn?.().Foo.#m?.().toString(); + + fnDeep?.().very.o?.Foo.#m?.(); + fnDeep?.().very.o?.Foo.#m?.().toString; + fnDeep?.().very.o?.Foo.#m?.().toString(); + + fn?.().Foo.#self.#m?.(); + fn?.().Foo.#self.self.#m?.(); + fn?.().Foo.#self?.self.#m?.(); + fn?.().Foo.#self.self?.self.#m?.(); + fn?.().Foo.#self?.self?.self.#m?.(); + + fn?.().Foo.#self.getSelf().#m?.(); + fn?.().Foo.#self.getSelf?.().#m?.(); + fn?.().Foo.#self?.getSelf().#m?.(); + fn?.().Foo.#self?.getSelf?.().#m?.(); + fn?.().Foo.#self.getSelf()?.self.#m?.(); + fn?.().Foo.#self.getSelf?.()?.self.#m?.(); + fn?.().Foo.#self?.getSelf()?.self.#m?.(); + fn?.().Foo.#self?.getSelf?.()?.self.#m?.(); + } + + static testtest() { + fn?.().Foo.#self.getSelf?.().#m?.(); + } +} + +Foo.test(); diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-member-optional-call/options.json b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-member-optional-call/options.json new file mode 100644 index 000000000000..3b59e1bbfcc8 --- /dev/null +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-member-optional-call/options.json @@ -0,0 +1,4 @@ +{ + "plugins": ["proposal-class-properties"], + "minNodeVersion": "14.0.0" +} diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-member-optional-call/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-member-optional-call/output.js new file mode 100644 index 000000000000..3eb9ff618c8a --- /dev/null +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-member-optional-call/output.js @@ -0,0 +1,128 @@ +function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } + +function _classStaticPrivateFieldSpecGet(receiver, classConstructor, descriptor) { if (receiver !== classConstructor) { throw new TypeError("Private static access of wrong provenance"); } if (descriptor.get) { return descriptor.get.call(receiver); } return descriptor.value; } + +class Foo { + static getSelf() { + return this; + } + + static test() { + var _o$Foo, _o$Foo2, _o$Foo3, _deep$very$o, _deep$very$o$Foo, _deep$very$o2, _deep$very$o2$Foo, _deep$very$o3, _deep$very$o3$Foo, _classStaticPrivateFi, _classStaticPrivateFi2, _ref, _ref$self, _ref2, _ref2$self, _self2, _self2$self, _classStaticPrivateFi3, _classStaticPrivateFi4, _ref3, _ref3$call, _ref4, _ref4$getSelf, _getSelf, _ref5, _getSelf$call, _ref6, _ref6$self, _classStaticPrivateFi5, _call, _call$self, _getSelf2, _getSelf2$self, _getSelf3, _getSelf3$self, _fn$Foo, _fn$Foo2, _fn$Foo3, _fnDeep$very$o, _fnDeep$very$o$Foo, _fnDeep$very$o2, _fnDeep$very$o2$Foo, _fnDeep$very$o3, _fnDeep$very$o3$Foo, _classStaticPrivateFi6, _classStaticPrivateFi7, _ref7, _ref7$self, _ref8, _ref8$self, _self3, _self3$self, _classStaticPrivateFi8, _classStaticPrivateFi9, _ref9, _ref9$call, _ref10, _ref10$getSelf, _getSelf4, _ref11, _getSelf4$call, _ref12, _ref12$self, _classStaticPrivateFi10, _call2, _call2$self, _getSelf5, _getSelf5$self, _getSelf6, _getSelf6$self; + + const o = { + Foo: Foo + }; + const deep = { + very: { + o + } + }; + + function fn() { + return o; + } + + function fnDeep() { + return deep; + } + + _classStaticPrivateFieldSpecGet(Foo, Foo, _m)?.(); + _classStaticPrivateFieldSpecGet(Foo, Foo, _m)?.().toString; + _classStaticPrivateFieldSpecGet(Foo, Foo, _m)?.().toString(); + + _classStaticPrivateFieldSpecGet(_o$Foo = o.Foo, Foo, _m).call(_o$Foo); + + _classStaticPrivateFieldSpecGet(_o$Foo2 = o.Foo, Foo, _m).call(_o$Foo2).toString; + _classStaticPrivateFieldSpecGet(_o$Foo3 = o.Foo, Foo, _m).call(_o$Foo3).toString(); + + _classStaticPrivateFieldSpecGet(_deep$very$o$Foo = _deep$very$o.Foo, Foo, _m).call(_deep$very$o$Foo); + + _classStaticPrivateFieldSpecGet(_deep$very$o2$Foo = _deep$very$o2.Foo, Foo, _m).call(_deep$very$o2$Foo).toString; + _classStaticPrivateFieldSpecGet(_deep$very$o3$Foo = _deep$very$o3.Foo, Foo, _m).call(_deep$very$o3$Foo).toString(); + (o === null || o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFi = _classStaticPrivateFieldSpecGet(o.Foo, Foo, _self), Foo, _m))?.call(_classStaticPrivateFi); + (o === null || o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFi2 = _classStaticPrivateFieldSpecGet(o.Foo, Foo, _self).self, Foo, _m))?.call(_classStaticPrivateFi2); + + _classStaticPrivateFieldSpecGet(_ref$self = _ref.self, Foo, _m).call(_ref$self); + + _classStaticPrivateFieldSpecGet(_ref2$self = _ref2.self, Foo, _m).call(_ref2$self); + + _classStaticPrivateFieldSpecGet(_self2$self = _self2.self, Foo, _m).call(_self2$self); + + (o === null || o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFi3 = _classStaticPrivateFieldSpecGet(o.Foo, Foo, _self).getSelf(), Foo, _m))?.call(_classStaticPrivateFi3); + + _classStaticPrivateFieldSpecGet(_ref3$call = _ref3.call(_classStaticPrivateFi4), Foo, _m).call(_ref3$call); + + _classStaticPrivateFieldSpecGet(_ref4$getSelf = _ref4.getSelf(), Foo, _m).call(_ref4$getSelf); + + _classStaticPrivateFieldSpecGet(_getSelf$call = _getSelf.call(_ref5), Foo, _m).call(_getSelf$call); + + _classStaticPrivateFieldSpecGet(_ref6$self = _ref6.self, Foo, _m).call(_ref6$self); + + _classStaticPrivateFieldSpecGet(_call$self = _call.self, Foo, _m).call(_call$self); + + _classStaticPrivateFieldSpecGet(_getSelf2$self = _getSelf2.self, Foo, _m).call(_getSelf2$self); + + _classStaticPrivateFieldSpecGet(_getSelf3$self = _getSelf3.self, Foo, _m).call(_getSelf3$self); + + _classStaticPrivateFieldSpecGet(_fn$Foo = fn().Foo, Foo, _m).call(_fn$Foo); + + _classStaticPrivateFieldSpecGet(_fn$Foo2 = fn().Foo, Foo, _m).call(_fn$Foo2).toString; + _classStaticPrivateFieldSpecGet(_fn$Foo3 = fn().Foo, Foo, _m).call(_fn$Foo3).toString(); + + _classStaticPrivateFieldSpecGet(_fnDeep$very$o$Foo = _fnDeep$very$o.Foo, Foo, _m).call(_fnDeep$very$o$Foo); + + _classStaticPrivateFieldSpecGet(_fnDeep$very$o2$Foo = _fnDeep$very$o2.Foo, Foo, _m).call(_fnDeep$very$o2$Foo).toString; + _classStaticPrivateFieldSpecGet(_fnDeep$very$o3$Foo = _fnDeep$very$o3.Foo, Foo, _m).call(_fnDeep$very$o3$Foo).toString(); + (fn === null || fn === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFi6 = _classStaticPrivateFieldSpecGet(fn().Foo, Foo, _self), Foo, _m))?.call(_classStaticPrivateFi6); + (fn === null || fn === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFi7 = _classStaticPrivateFieldSpecGet(fn().Foo, Foo, _self).self, Foo, _m))?.call(_classStaticPrivateFi7); + + _classStaticPrivateFieldSpecGet(_ref7$self = _ref7.self, Foo, _m).call(_ref7$self); + + _classStaticPrivateFieldSpecGet(_ref8$self = _ref8.self, Foo, _m).call(_ref8$self); + + _classStaticPrivateFieldSpecGet(_self3$self = _self3.self, Foo, _m).call(_self3$self); + + (fn === null || fn === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFi8 = _classStaticPrivateFieldSpecGet(fn().Foo, Foo, _self).getSelf(), Foo, _m))?.call(_classStaticPrivateFi8); + + _classStaticPrivateFieldSpecGet(_ref9$call = _ref9.call(_classStaticPrivateFi9), Foo, _m).call(_ref9$call); + + _classStaticPrivateFieldSpecGet(_ref10$getSelf = _ref10.getSelf(), Foo, _m).call(_ref10$getSelf); + + _classStaticPrivateFieldSpecGet(_getSelf4$call = _getSelf4.call(_ref11), Foo, _m).call(_getSelf4$call); + + _classStaticPrivateFieldSpecGet(_ref12$self = _ref12.self, Foo, _m).call(_ref12$self); + + _classStaticPrivateFieldSpecGet(_call2$self = _call2.self, Foo, _m).call(_call2$self); + + _classStaticPrivateFieldSpecGet(_getSelf5$self = _getSelf5.self, Foo, _m).call(_getSelf5$self); + + _classStaticPrivateFieldSpecGet(_getSelf6$self = _getSelf6.self, Foo, _m).call(_getSelf6$self); + } + + static testtest() { + var _fn, _classStaticPrivateFi11, _ref13, _ref13$call; + + _classStaticPrivateFieldSpecGet(_ref13$call = _ref13.call(_classStaticPrivateFi11), Foo, _m).call(_ref13$call); + } + +} + +var _x = { + writable: true, + value: 1 +}; +var _m = { + writable: true, + value: function () { + return _classStaticPrivateFieldSpecGet(this, Foo, _x); + } +}; +var _self = { + writable: true, + value: Foo +}; + +_defineProperty(Foo, "self", Foo); + +Foo.test(); From 12eb77ba9d48958c351b6a25a2546dab2390e5ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hu=C3=A1ng=20J=C3=B9nli=C3=A0ng?= Date: Mon, 25 May 2020 12:37:19 -0400 Subject: [PATCH 16/20] add `#m?.()` support MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Nicolò Ribaudo --- .../src/fields.js | 12 +- .../src/index.js | 27 +++- .../src/index.js | 9 +- .../babel-helper-replace-supers/src/index.js | 3 +- .../input.js | 3 - .../output.js | 120 ++++++------------ .../input.js | 3 - .../output.js | 106 +++++----------- 8 files changed, 122 insertions(+), 161 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 98babe2635b8..76bc96b6d662 100644 --- a/packages/babel-helper-create-class-features-plugin/src/fields.js +++ b/packages/babel-helper-create-class-features-plugin/src/fields.js @@ -300,7 +300,13 @@ const privateNameHandlerSpec = { // The first access (the get) should do the memo assignment. this.memoise(member, 1); - return optimiseCall(this.get(member), this.receiver(member), args); + return optimiseCall(this.get(member), this.receiver(member), args, false); + }, + + optionalCall(member, args) { + this.memoise(member, 1); + + return optimiseCall(this.get(member), this.receiver(member), args, true); }, }; @@ -328,6 +334,10 @@ const privateNameHandlerLoose = { call(member, args) { return t.callExpression(this.get(member), args); }, + + optionalCall(member, args) { + return t.optionalCallExpression(this.get(member), args, true); + }, }; export function transformPrivateNamesUsage( 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 ae63cafaed67..48f23fb3bb46 100644 --- a/packages/babel-helper-member-expression-to-functions/src/index.js +++ b/packages/babel-helper-member-expression-to-functions/src/index.js @@ -109,7 +109,11 @@ const handle = { if (parentPath.isOptionalCallExpression()) { // Checking `parent.callee` since we could be in the arguments, eg // `bad?.(FOO?.BAR)`. - return parent.optional || parent.callee !== node; + // Also skip `FOO?.BAR` in `FOO?.BAR?.()` since we need to transform the optional call to ensure proper this + return ( + // In FOO?.#BAR?.(), endPath points the optional call expression so we skip FOO?.#BAR + (node !== member.node && parent.optional) || parent.callee !== node + ); } return true; }); @@ -145,7 +149,9 @@ const handle = { continue; } // prevent infinite loop: unreachable if the AST is well-formed - throw new Error("Internal error"); + throw new Error( + `Internal error: unexpected ${startingOptional.node.type}`, + ); } const { scope } = member; @@ -163,7 +169,11 @@ const handle = { }); startingOptional.replaceWith(toNonOptional(startingOptional, baseRef)); if (parentIsOptionalCall) { - parentPath.replaceWith(this.call(member, parent.arguments)); + if (parent.optional) { + parentPath.replaceWith(this.optionalCall(member, parent.arguments)); + } else { + parentPath.replaceWith(this.call(member, parent.arguments)); + } } else { member.replaceWith(this.get(member)); } @@ -171,6 +181,11 @@ const handle = { let regular = member.node; for (let current = member; current !== endPath; ) { const { parentPath } = current; + // skip transforming `Foo.#BAR?.call(FOO)` + if (parentPath === endPath && parentIsOptionalCall && parent.optional) { + regular = parentPath.node; + break; + } regular = toNonOptional(parentPath, regular); current = parentPath; } @@ -299,6 +314,12 @@ const handle = { return; } + // MEMBER?.(ARGS) -> _optionalCall(MEMBER, ARGS) + if (parentPath.isOptionalCallExpression({ callee: node })) { + parentPath.replaceWith(this.optionalCall(member, parent.arguments)); + return; + } + // { KEY: MEMBER } = OBJ -> { KEY: _destructureSet(MEMBER) } = OBJ // { KEY: MEMBER = _VALUE } = OBJ -> { KEY: _destructureSet(MEMBER) = _VALUE } = OBJ // {...MEMBER} -> {..._destructureSet(MEMBER)} diff --git a/packages/babel-helper-optimise-call-expression/src/index.js b/packages/babel-helper-optimise-call-expression/src/index.js index 56f9b2991bde..2dcfd29ec852 100644 --- a/packages/babel-helper-optimise-call-expression/src/index.js +++ b/packages/babel-helper-optimise-call-expression/src/index.js @@ -1,6 +1,6 @@ import * as t from "@babel/types"; -export default function(callee, thisNode, args) { +export default function(callee, thisNode, args, optional) { if ( args.length === 1 && t.isSpreadElement(args[0]) && @@ -12,6 +12,13 @@ export default function(callee, thisNode, args) { args[0].argument, ]); } else { + if (optional) { + return t.optionalCallExpression( + t.optionalMemberExpression(callee, t.identifier("call"), false, true), + [thisNode, ...args], + false, + ); + } return t.callExpression(t.memberExpression(callee, t.identifier("call")), [ thisNode, ...args, diff --git a/packages/babel-helper-replace-supers/src/index.js b/packages/babel-helper-replace-supers/src/index.js index 804d4251805b..0bf1d50c3d35 100644 --- a/packages/babel-helper-replace-supers/src/index.js +++ b/packages/babel-helper-replace-supers/src/index.js @@ -158,6 +158,7 @@ const specHandlers = { this._get(superMember, thisRefs), t.cloneNode(thisRefs.this), args, + false, ); }, }; @@ -215,7 +216,7 @@ const looseHandlers = { }, call(superMember, args) { - return optimiseCall(this.get(superMember), t.thisExpression(), args); + return optimiseCall(this.get(superMember), t.thisExpression(), args, false); }, }; diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-member-optional-call-with-transform/input.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-member-optional-call-with-transform/input.js index 42d692812e9a..11dd4a57060d 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-member-optional-call-with-transform/input.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-member-optional-call-with-transform/input.js @@ -66,9 +66,6 @@ class Foo { fn?.().Foo.#self?.getSelf?.()?.self.#m?.(); } - static testtest() { - fn?.().Foo.#self.getSelf?.().#m?.(); - } } Foo.test(); diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-member-optional-call-with-transform/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-member-optional-call-with-transform/output.js index 3eb9ff618c8a..349cb4e9e213 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-member-optional-call-with-transform/output.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-member-optional-call-with-transform/output.js @@ -8,7 +8,7 @@ class Foo { } static test() { - var _o$Foo, _o$Foo2, _o$Foo3, _deep$very$o, _deep$very$o$Foo, _deep$very$o2, _deep$very$o2$Foo, _deep$very$o3, _deep$very$o3$Foo, _classStaticPrivateFi, _classStaticPrivateFi2, _ref, _ref$self, _ref2, _ref2$self, _self2, _self2$self, _classStaticPrivateFi3, _classStaticPrivateFi4, _ref3, _ref3$call, _ref4, _ref4$getSelf, _getSelf, _ref5, _getSelf$call, _ref6, _ref6$self, _classStaticPrivateFi5, _call, _call$self, _getSelf2, _getSelf2$self, _getSelf3, _getSelf3$self, _fn$Foo, _fn$Foo2, _fn$Foo3, _fnDeep$very$o, _fnDeep$very$o$Foo, _fnDeep$very$o2, _fnDeep$very$o2$Foo, _fnDeep$very$o3, _fnDeep$very$o3$Foo, _classStaticPrivateFi6, _classStaticPrivateFi7, _ref7, _ref7$self, _ref8, _ref8$self, _self3, _self3$self, _classStaticPrivateFi8, _classStaticPrivateFi9, _ref9, _ref9$call, _ref10, _ref10$getSelf, _getSelf4, _ref11, _getSelf4$call, _ref12, _ref12$self, _classStaticPrivateFi10, _call2, _call2$self, _getSelf5, _getSelf5$self, _getSelf6, _getSelf6$self; + var _o$Foo, _o$Foo2, _o$Foo3, _deep$very$o, _deep$very$o$Foo, _deep$very$o2, _deep$very$o2$Foo, _deep$very$o3, _deep$very$o3$Foo, _classStaticPrivateFi, _classStaticPrivateFi2, _ref, _ref$self, _ref2, _ref2$self, _self2, _self2$self, _classStaticPrivateFi3, _classStaticPrivateFi4, _ref3, _ref3$call, _ref4, _ref4$getSelf, _getSelf, _ref5, _getSelf$call, _ref6, _ref6$self, _classStaticPrivateFi5, _call, _call$self, _getSelf2, _getSelf2$self, _getSelf3, _getSelf3$self, _fn$Foo, _fn$Foo2, _fn$Foo3, _fnDeep$very$o, _fnDeep$very$o$Foo, _fnDeep$very$o2, _fnDeep$very$o2$Foo, _fnDeep$very$o3, _fnDeep$very$o3$Foo, _classStaticPrivateFi6, _classStaticPrivateFi7, _ref7, _ref7$self, _ref8, _ref8$self, _self3, _self3$self, _classStaticPrivateFi8, _classStaticPrivateFi9, _ref9, _ref9$call, _ref10, _ref10$getSelf, _getSelf4, _ref11, _getSelf4$call, _ref12, _ref12$self, _classStaticPrivateFi10, _call2, _call2$self, _getSelf5, _getSelf5$self, _getSelf6, _getSelf6$self, _classStaticPrivateFi11, _classStaticPrivateFi12, _classStaticPrivateFi13, _classStaticPrivateFi14, _classStaticPrivateFi15, _classStaticPrivateFi16, _classStaticPrivateFi17, _classStaticPrivateFi18, _classStaticPrivateFi19, _ref13, _ref14, _classStaticPrivateFi20, _classStaticPrivateFi21, _ref15, _classStaticPrivateFi22, _ref16, _classStaticPrivateFi23, _classStaticPrivateFi24, _ref17, _classStaticPrivateFi25, _classStaticPrivateFi26, _ref18, _classStaticPrivateFi27, _ref19, _classStaticPrivateFi28, _ref20, _ref20$getSelf, _classStaticPrivateFi29, _classStaticPrivateFi30, _classStaticPrivateFi31, _classStaticPrivateFi32, _classStaticPrivateFi33, _classStaticPrivateFi34, _classStaticPrivateFi35, _ref21, _ref22, _classStaticPrivateFi36, _classStaticPrivateFi37, _ref23, _classStaticPrivateFi38, _ref24, _classStaticPrivateFi39, _classStaticPrivateFi40, _ref25, _classStaticPrivateFi41, _classStaticPrivateFi42, _ref26, _classStaticPrivateFi43, _ref27, _classStaticPrivateFi44, _ref28, _ref28$getSelf, _classStaticPrivateFi45; const o = { Foo: Foo @@ -27,83 +27,47 @@ class Foo { return deep; } - _classStaticPrivateFieldSpecGet(Foo, Foo, _m)?.(); - _classStaticPrivateFieldSpecGet(Foo, Foo, _m)?.().toString; - _classStaticPrivateFieldSpecGet(Foo, Foo, _m)?.().toString(); - - _classStaticPrivateFieldSpecGet(_o$Foo = o.Foo, Foo, _m).call(_o$Foo); - - _classStaticPrivateFieldSpecGet(_o$Foo2 = o.Foo, Foo, _m).call(_o$Foo2).toString; - _classStaticPrivateFieldSpecGet(_o$Foo3 = o.Foo, Foo, _m).call(_o$Foo3).toString(); - - _classStaticPrivateFieldSpecGet(_deep$very$o$Foo = _deep$very$o.Foo, Foo, _m).call(_deep$very$o$Foo); - - _classStaticPrivateFieldSpecGet(_deep$very$o2$Foo = _deep$very$o2.Foo, Foo, _m).call(_deep$very$o2$Foo).toString; - _classStaticPrivateFieldSpecGet(_deep$very$o3$Foo = _deep$very$o3.Foo, Foo, _m).call(_deep$very$o3$Foo).toString(); - (o === null || o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFi = _classStaticPrivateFieldSpecGet(o.Foo, Foo, _self), Foo, _m))?.call(_classStaticPrivateFi); - (o === null || o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFi2 = _classStaticPrivateFieldSpecGet(o.Foo, Foo, _self).self, Foo, _m))?.call(_classStaticPrivateFi2); - - _classStaticPrivateFieldSpecGet(_ref$self = _ref.self, Foo, _m).call(_ref$self); - - _classStaticPrivateFieldSpecGet(_ref2$self = _ref2.self, Foo, _m).call(_ref2$self); - - _classStaticPrivateFieldSpecGet(_self2$self = _self2.self, Foo, _m).call(_self2$self); - - (o === null || o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFi3 = _classStaticPrivateFieldSpecGet(o.Foo, Foo, _self).getSelf(), Foo, _m))?.call(_classStaticPrivateFi3); - - _classStaticPrivateFieldSpecGet(_ref3$call = _ref3.call(_classStaticPrivateFi4), Foo, _m).call(_ref3$call); - - _classStaticPrivateFieldSpecGet(_ref4$getSelf = _ref4.getSelf(), Foo, _m).call(_ref4$getSelf); - - _classStaticPrivateFieldSpecGet(_getSelf$call = _getSelf.call(_ref5), Foo, _m).call(_getSelf$call); - - _classStaticPrivateFieldSpecGet(_ref6$self = _ref6.self, Foo, _m).call(_ref6$self); - - _classStaticPrivateFieldSpecGet(_call$self = _call.self, Foo, _m).call(_call$self); - - _classStaticPrivateFieldSpecGet(_getSelf2$self = _getSelf2.self, Foo, _m).call(_getSelf2$self); - - _classStaticPrivateFieldSpecGet(_getSelf3$self = _getSelf3.self, Foo, _m).call(_getSelf3$self); - - _classStaticPrivateFieldSpecGet(_fn$Foo = fn().Foo, Foo, _m).call(_fn$Foo); - - _classStaticPrivateFieldSpecGet(_fn$Foo2 = fn().Foo, Foo, _m).call(_fn$Foo2).toString; - _classStaticPrivateFieldSpecGet(_fn$Foo3 = fn().Foo, Foo, _m).call(_fn$Foo3).toString(); - - _classStaticPrivateFieldSpecGet(_fnDeep$very$o$Foo = _fnDeep$very$o.Foo, Foo, _m).call(_fnDeep$very$o$Foo); - - _classStaticPrivateFieldSpecGet(_fnDeep$very$o2$Foo = _fnDeep$very$o2.Foo, Foo, _m).call(_fnDeep$very$o2$Foo).toString; - _classStaticPrivateFieldSpecGet(_fnDeep$very$o3$Foo = _fnDeep$very$o3.Foo, Foo, _m).call(_fnDeep$very$o3$Foo).toString(); - (fn === null || fn === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFi6 = _classStaticPrivateFieldSpecGet(fn().Foo, Foo, _self), Foo, _m))?.call(_classStaticPrivateFi6); - (fn === null || fn === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFi7 = _classStaticPrivateFieldSpecGet(fn().Foo, Foo, _self).self, Foo, _m))?.call(_classStaticPrivateFi7); - - _classStaticPrivateFieldSpecGet(_ref7$self = _ref7.self, Foo, _m).call(_ref7$self); - - _classStaticPrivateFieldSpecGet(_ref8$self = _ref8.self, Foo, _m).call(_ref8$self); - - _classStaticPrivateFieldSpecGet(_self3$self = _self3.self, Foo, _m).call(_self3$self); - - (fn === null || fn === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFi8 = _classStaticPrivateFieldSpecGet(fn().Foo, Foo, _self).getSelf(), Foo, _m))?.call(_classStaticPrivateFi8); - - _classStaticPrivateFieldSpecGet(_ref9$call = _ref9.call(_classStaticPrivateFi9), Foo, _m).call(_ref9$call); - - _classStaticPrivateFieldSpecGet(_ref10$getSelf = _ref10.getSelf(), Foo, _m).call(_ref10$getSelf); - - _classStaticPrivateFieldSpecGet(_getSelf4$call = _getSelf4.call(_ref11), Foo, _m).call(_getSelf4$call); - - _classStaticPrivateFieldSpecGet(_ref12$self = _ref12.self, Foo, _m).call(_ref12$self); - - _classStaticPrivateFieldSpecGet(_call2$self = _call2.self, Foo, _m).call(_call2$self); - - _classStaticPrivateFieldSpecGet(_getSelf5$self = _getSelf5.self, Foo, _m).call(_getSelf5$self); - - _classStaticPrivateFieldSpecGet(_getSelf6$self = _getSelf6.self, Foo, _m).call(_getSelf6$self); - } - - static testtest() { - var _fn, _classStaticPrivateFi11, _ref13, _ref13$call; - - _classStaticPrivateFieldSpecGet(_ref13$call = _ref13.call(_classStaticPrivateFi11), Foo, _m).call(_ref13$call); + (_classStaticPrivateFi11 = _classStaticPrivateFieldSpecGet(Foo, Foo, _m)) === null || _classStaticPrivateFi11 === void 0 ? void 0 : _classStaticPrivateFi11.call(Foo); + (_classStaticPrivateFi12 = _classStaticPrivateFieldSpecGet(Foo, Foo, _m)) === null || _classStaticPrivateFi12 === void 0 ? void 0 : _classStaticPrivateFi12.call(Foo).toString; + (_classStaticPrivateFi13 = _classStaticPrivateFieldSpecGet(Foo, Foo, _m)) === null || _classStaticPrivateFi13 === void 0 ? void 0 : _classStaticPrivateFi13.call(Foo).toString(); + o === null || o === void 0 ? void 0 : (_classStaticPrivateFi14 = _classStaticPrivateFieldSpecGet(_o$Foo = o.Foo, Foo, _m)) === null || _classStaticPrivateFi14 === void 0 ? void 0 : _classStaticPrivateFi14.call(_o$Foo); + o === null || o === void 0 ? void 0 : (_classStaticPrivateFi15 = _classStaticPrivateFieldSpecGet(_o$Foo2 = o.Foo, Foo, _m)) === null || _classStaticPrivateFi15 === void 0 ? void 0 : _classStaticPrivateFi15.call(_o$Foo2).toString; + o === null || o === void 0 ? void 0 : (_classStaticPrivateFi16 = _classStaticPrivateFieldSpecGet(_o$Foo3 = o.Foo, Foo, _m)) === null || _classStaticPrivateFi16 === void 0 ? void 0 : _classStaticPrivateFi16.call(_o$Foo3).toString(); + (_deep$very$o = deep === null || deep === void 0 ? void 0 : deep.very.o) === null || _deep$very$o === void 0 ? void 0 : (_classStaticPrivateFi17 = _classStaticPrivateFieldSpecGet(_deep$very$o$Foo = _deep$very$o.Foo, Foo, _m)) === null || _classStaticPrivateFi17 === void 0 ? void 0 : _classStaticPrivateFi17.call(_deep$very$o$Foo); + (_deep$very$o2 = deep === null || deep === void 0 ? void 0 : deep.very.o) === null || _deep$very$o2 === void 0 ? void 0 : (_classStaticPrivateFi18 = _classStaticPrivateFieldSpecGet(_deep$very$o2$Foo = _deep$very$o2.Foo, Foo, _m)) === null || _classStaticPrivateFi18 === void 0 ? void 0 : _classStaticPrivateFi18.call(_deep$very$o2$Foo).toString; + (_deep$very$o3 = deep === null || deep === void 0 ? void 0 : deep.very.o) === null || _deep$very$o3 === void 0 ? void 0 : (_classStaticPrivateFi19 = _classStaticPrivateFieldSpecGet(_deep$very$o3$Foo = _deep$very$o3.Foo, Foo, _m)) === null || _classStaticPrivateFi19 === void 0 ? void 0 : _classStaticPrivateFi19.call(_deep$very$o3$Foo).toString(); + (_ref13 = o === null || o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFi = _classStaticPrivateFieldSpecGet(o.Foo, Foo, _self), Foo, _m)) === null || _ref13 === void 0 ? void 0 : _ref13.call(_classStaticPrivateFi); + (_ref14 = o === null || o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFi2 = _classStaticPrivateFieldSpecGet(o.Foo, Foo, _self).self, Foo, _m)) === null || _ref14 === void 0 ? void 0 : _ref14.call(_classStaticPrivateFi2); + (_ref = o === null || o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(o.Foo, Foo, _self)) === null || _ref === void 0 ? void 0 : (_classStaticPrivateFi20 = _classStaticPrivateFieldSpecGet(_ref$self = _ref.self, Foo, _m)) === null || _classStaticPrivateFi20 === void 0 ? void 0 : _classStaticPrivateFi20.call(_ref$self); + (_ref2 = o === null || o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(o.Foo, Foo, _self).self) === null || _ref2 === void 0 ? void 0 : (_classStaticPrivateFi21 = _classStaticPrivateFieldSpecGet(_ref2$self = _ref2.self, Foo, _m)) === null || _classStaticPrivateFi21 === void 0 ? void 0 : _classStaticPrivateFi21.call(_ref2$self); + (_self2 = (_ref15 = o === null || o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(o.Foo, Foo, _self)) === null || _ref15 === void 0 ? void 0 : _ref15.self) === null || _self2 === void 0 ? void 0 : (_classStaticPrivateFi22 = _classStaticPrivateFieldSpecGet(_self2$self = _self2.self, Foo, _m)) === null || _classStaticPrivateFi22 === void 0 ? void 0 : _classStaticPrivateFi22.call(_self2$self); + (_ref16 = o === null || o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFi3 = _classStaticPrivateFieldSpecGet(o.Foo, Foo, _self).getSelf(), Foo, _m)) === null || _ref16 === void 0 ? void 0 : _ref16.call(_classStaticPrivateFi3); + (_ref3 = o === null || o === void 0 ? void 0 : (_classStaticPrivateFi4 = _classStaticPrivateFieldSpecGet(o.Foo, Foo, _self)).getSelf) === null || _ref3 === void 0 ? void 0 : (_classStaticPrivateFi23 = _classStaticPrivateFieldSpecGet(_ref3$call = _ref3.call(_classStaticPrivateFi4), Foo, _m)) === null || _classStaticPrivateFi23 === void 0 ? void 0 : _classStaticPrivateFi23.call(_ref3$call); + (_ref4 = o === null || o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(o.Foo, Foo, _self)) === null || _ref4 === void 0 ? void 0 : (_classStaticPrivateFi24 = _classStaticPrivateFieldSpecGet(_ref4$getSelf = _ref4.getSelf(), Foo, _m)) === null || _classStaticPrivateFi24 === void 0 ? void 0 : _classStaticPrivateFi24.call(_ref4$getSelf); + (_getSelf = (_ref17 = _ref5 = o === null || o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(o.Foo, Foo, _self)) === null || _ref17 === void 0 ? void 0 : _ref17.getSelf) === null || _getSelf === void 0 ? void 0 : (_classStaticPrivateFi25 = _classStaticPrivateFieldSpecGet(_getSelf$call = _getSelf.call(_ref5), Foo, _m)) === null || _classStaticPrivateFi25 === void 0 ? void 0 : _classStaticPrivateFi25.call(_getSelf$call); + (_ref6 = o === null || o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(o.Foo, Foo, _self).getSelf()) === null || _ref6 === void 0 ? void 0 : (_classStaticPrivateFi26 = _classStaticPrivateFieldSpecGet(_ref6$self = _ref6.self, Foo, _m)) === null || _classStaticPrivateFi26 === void 0 ? void 0 : _classStaticPrivateFi26.call(_ref6$self); + (_call = (_ref18 = o === null || o === void 0 ? void 0 : (_classStaticPrivateFi5 = _classStaticPrivateFieldSpecGet(o.Foo, Foo, _self)).getSelf) === null || _ref18 === void 0 ? void 0 : _ref18.call(_classStaticPrivateFi5)) === null || _call === void 0 ? void 0 : (_classStaticPrivateFi27 = _classStaticPrivateFieldSpecGet(_call$self = _call.self, Foo, _m)) === null || _classStaticPrivateFi27 === void 0 ? void 0 : _classStaticPrivateFi27.call(_call$self); + (_getSelf2 = (_ref19 = o === null || o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(o.Foo, Foo, _self)) === null || _ref19 === void 0 ? void 0 : _ref19.getSelf()) === null || _getSelf2 === void 0 ? void 0 : (_classStaticPrivateFi28 = _classStaticPrivateFieldSpecGet(_getSelf2$self = _getSelf2.self, Foo, _m)) === null || _classStaticPrivateFi28 === void 0 ? void 0 : _classStaticPrivateFi28.call(_getSelf2$self); + (_getSelf3 = (_ref20 = o === null || o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(o.Foo, Foo, _self)) === null || _ref20 === void 0 ? void 0 : (_ref20$getSelf = _ref20.getSelf) === null || _ref20$getSelf === void 0 ? void 0 : _ref20$getSelf.call(_ref20)) === null || _getSelf3 === void 0 ? void 0 : (_classStaticPrivateFi29 = _classStaticPrivateFieldSpecGet(_getSelf3$self = _getSelf3.self, Foo, _m)) === null || _classStaticPrivateFi29 === void 0 ? void 0 : _classStaticPrivateFi29.call(_getSelf3$self); + fn === null || fn === void 0 ? void 0 : (_classStaticPrivateFi30 = _classStaticPrivateFieldSpecGet(_fn$Foo = fn().Foo, Foo, _m)) === null || _classStaticPrivateFi30 === void 0 ? void 0 : _classStaticPrivateFi30.call(_fn$Foo); + fn === null || fn === void 0 ? void 0 : (_classStaticPrivateFi31 = _classStaticPrivateFieldSpecGet(_fn$Foo2 = fn().Foo, Foo, _m)) === null || _classStaticPrivateFi31 === void 0 ? void 0 : _classStaticPrivateFi31.call(_fn$Foo2).toString; + fn === null || fn === void 0 ? void 0 : (_classStaticPrivateFi32 = _classStaticPrivateFieldSpecGet(_fn$Foo3 = fn().Foo, Foo, _m)) === null || _classStaticPrivateFi32 === void 0 ? void 0 : _classStaticPrivateFi32.call(_fn$Foo3).toString(); + (_fnDeep$very$o = fnDeep === null || fnDeep === void 0 ? void 0 : fnDeep().very.o) === null || _fnDeep$very$o === void 0 ? void 0 : (_classStaticPrivateFi33 = _classStaticPrivateFieldSpecGet(_fnDeep$very$o$Foo = _fnDeep$very$o.Foo, Foo, _m)) === null || _classStaticPrivateFi33 === void 0 ? void 0 : _classStaticPrivateFi33.call(_fnDeep$very$o$Foo); + (_fnDeep$very$o2 = fnDeep === null || fnDeep === void 0 ? void 0 : fnDeep().very.o) === null || _fnDeep$very$o2 === void 0 ? void 0 : (_classStaticPrivateFi34 = _classStaticPrivateFieldSpecGet(_fnDeep$very$o2$Foo = _fnDeep$very$o2.Foo, Foo, _m)) === null || _classStaticPrivateFi34 === void 0 ? void 0 : _classStaticPrivateFi34.call(_fnDeep$very$o2$Foo).toString; + (_fnDeep$very$o3 = fnDeep === null || fnDeep === void 0 ? void 0 : fnDeep().very.o) === null || _fnDeep$very$o3 === void 0 ? void 0 : (_classStaticPrivateFi35 = _classStaticPrivateFieldSpecGet(_fnDeep$very$o3$Foo = _fnDeep$very$o3.Foo, Foo, _m)) === null || _classStaticPrivateFi35 === void 0 ? void 0 : _classStaticPrivateFi35.call(_fnDeep$very$o3$Foo).toString(); + (_ref21 = fn === null || fn === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFi6 = _classStaticPrivateFieldSpecGet(fn().Foo, Foo, _self), Foo, _m)) === null || _ref21 === void 0 ? void 0 : _ref21.call(_classStaticPrivateFi6); + (_ref22 = fn === null || fn === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFi7 = _classStaticPrivateFieldSpecGet(fn().Foo, Foo, _self).self, Foo, _m)) === null || _ref22 === void 0 ? void 0 : _ref22.call(_classStaticPrivateFi7); + (_ref7 = fn === null || fn === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(fn().Foo, Foo, _self)) === null || _ref7 === void 0 ? void 0 : (_classStaticPrivateFi36 = _classStaticPrivateFieldSpecGet(_ref7$self = _ref7.self, Foo, _m)) === null || _classStaticPrivateFi36 === void 0 ? void 0 : _classStaticPrivateFi36.call(_ref7$self); + (_ref8 = fn === null || fn === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(fn().Foo, Foo, _self).self) === null || _ref8 === void 0 ? void 0 : (_classStaticPrivateFi37 = _classStaticPrivateFieldSpecGet(_ref8$self = _ref8.self, Foo, _m)) === null || _classStaticPrivateFi37 === void 0 ? void 0 : _classStaticPrivateFi37.call(_ref8$self); + (_self3 = (_ref23 = fn === null || fn === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(fn().Foo, Foo, _self)) === null || _ref23 === void 0 ? void 0 : _ref23.self) === null || _self3 === void 0 ? void 0 : (_classStaticPrivateFi38 = _classStaticPrivateFieldSpecGet(_self3$self = _self3.self, Foo, _m)) === null || _classStaticPrivateFi38 === void 0 ? void 0 : _classStaticPrivateFi38.call(_self3$self); + (_ref24 = fn === null || fn === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFi8 = _classStaticPrivateFieldSpecGet(fn().Foo, Foo, _self).getSelf(), Foo, _m)) === null || _ref24 === void 0 ? void 0 : _ref24.call(_classStaticPrivateFi8); + (_ref9 = fn === null || fn === void 0 ? void 0 : (_classStaticPrivateFi9 = _classStaticPrivateFieldSpecGet(fn().Foo, Foo, _self)).getSelf) === null || _ref9 === void 0 ? void 0 : (_classStaticPrivateFi39 = _classStaticPrivateFieldSpecGet(_ref9$call = _ref9.call(_classStaticPrivateFi9), Foo, _m)) === null || _classStaticPrivateFi39 === void 0 ? void 0 : _classStaticPrivateFi39.call(_ref9$call); + (_ref10 = fn === null || fn === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(fn().Foo, Foo, _self)) === null || _ref10 === void 0 ? void 0 : (_classStaticPrivateFi40 = _classStaticPrivateFieldSpecGet(_ref10$getSelf = _ref10.getSelf(), Foo, _m)) === null || _classStaticPrivateFi40 === void 0 ? void 0 : _classStaticPrivateFi40.call(_ref10$getSelf); + (_getSelf4 = (_ref25 = _ref11 = fn === null || fn === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(fn().Foo, Foo, _self)) === null || _ref25 === void 0 ? void 0 : _ref25.getSelf) === null || _getSelf4 === void 0 ? void 0 : (_classStaticPrivateFi41 = _classStaticPrivateFieldSpecGet(_getSelf4$call = _getSelf4.call(_ref11), Foo, _m)) === null || _classStaticPrivateFi41 === void 0 ? void 0 : _classStaticPrivateFi41.call(_getSelf4$call); + (_ref12 = fn === null || fn === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(fn().Foo, Foo, _self).getSelf()) === null || _ref12 === void 0 ? void 0 : (_classStaticPrivateFi42 = _classStaticPrivateFieldSpecGet(_ref12$self = _ref12.self, Foo, _m)) === null || _classStaticPrivateFi42 === void 0 ? void 0 : _classStaticPrivateFi42.call(_ref12$self); + (_call2 = (_ref26 = fn === null || fn === void 0 ? void 0 : (_classStaticPrivateFi10 = _classStaticPrivateFieldSpecGet(fn().Foo, Foo, _self)).getSelf) === null || _ref26 === void 0 ? void 0 : _ref26.call(_classStaticPrivateFi10)) === null || _call2 === void 0 ? void 0 : (_classStaticPrivateFi43 = _classStaticPrivateFieldSpecGet(_call2$self = _call2.self, Foo, _m)) === null || _classStaticPrivateFi43 === void 0 ? void 0 : _classStaticPrivateFi43.call(_call2$self); + (_getSelf5 = (_ref27 = fn === null || fn === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(fn().Foo, Foo, _self)) === null || _ref27 === void 0 ? void 0 : _ref27.getSelf()) === null || _getSelf5 === void 0 ? void 0 : (_classStaticPrivateFi44 = _classStaticPrivateFieldSpecGet(_getSelf5$self = _getSelf5.self, Foo, _m)) === null || _classStaticPrivateFi44 === void 0 ? void 0 : _classStaticPrivateFi44.call(_getSelf5$self); + (_getSelf6 = (_ref28 = fn === null || fn === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(fn().Foo, Foo, _self)) === null || _ref28 === void 0 ? void 0 : (_ref28$getSelf = _ref28.getSelf) === null || _ref28$getSelf === void 0 ? void 0 : _ref28$getSelf.call(_ref28)) === null || _getSelf6 === void 0 ? void 0 : (_classStaticPrivateFi45 = _classStaticPrivateFieldSpecGet(_getSelf6$self = _getSelf6.self, Foo, _m)) === null || _classStaticPrivateFi45 === void 0 ? void 0 : _classStaticPrivateFi45.call(_getSelf6$self); } } diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-member-optional-call/input.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-member-optional-call/input.js index 42d692812e9a..11dd4a57060d 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-member-optional-call/input.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-member-optional-call/input.js @@ -66,9 +66,6 @@ class Foo { fn?.().Foo.#self?.getSelf?.()?.self.#m?.(); } - static testtest() { - fn?.().Foo.#self.getSelf?.().#m?.(); - } } Foo.test(); diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-member-optional-call/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-member-optional-call/output.js index 3eb9ff618c8a..c9e4dcb46a81 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-member-optional-call/output.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-member-optional-call/output.js @@ -27,83 +27,47 @@ class Foo { return deep; } - _classStaticPrivateFieldSpecGet(Foo, Foo, _m)?.(); - _classStaticPrivateFieldSpecGet(Foo, Foo, _m)?.().toString; - _classStaticPrivateFieldSpecGet(Foo, Foo, _m)?.().toString(); - - _classStaticPrivateFieldSpecGet(_o$Foo = o.Foo, Foo, _m).call(_o$Foo); - - _classStaticPrivateFieldSpecGet(_o$Foo2 = o.Foo, Foo, _m).call(_o$Foo2).toString; - _classStaticPrivateFieldSpecGet(_o$Foo3 = o.Foo, Foo, _m).call(_o$Foo3).toString(); - - _classStaticPrivateFieldSpecGet(_deep$very$o$Foo = _deep$very$o.Foo, Foo, _m).call(_deep$very$o$Foo); - - _classStaticPrivateFieldSpecGet(_deep$very$o2$Foo = _deep$very$o2.Foo, Foo, _m).call(_deep$very$o2$Foo).toString; - _classStaticPrivateFieldSpecGet(_deep$very$o3$Foo = _deep$very$o3.Foo, Foo, _m).call(_deep$very$o3$Foo).toString(); + _classStaticPrivateFieldSpecGet(Foo, Foo, _m)?.call(Foo); + _classStaticPrivateFieldSpecGet(Foo, Foo, _m)?.call(Foo).toString; + _classStaticPrivateFieldSpecGet(Foo, Foo, _m)?.call(Foo).toString(); + o === null || o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o$Foo = o.Foo, Foo, _m)?.call(_o$Foo); + o === null || o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o$Foo2 = o.Foo, Foo, _m)?.call(_o$Foo2).toString; + o === null || o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o$Foo3 = o.Foo, Foo, _m)?.call(_o$Foo3).toString(); + (_deep$very$o = deep?.very.o) === null || _deep$very$o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_deep$very$o$Foo = _deep$very$o.Foo, Foo, _m)?.call(_deep$very$o$Foo); + (_deep$very$o2 = deep?.very.o) === null || _deep$very$o2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_deep$very$o2$Foo = _deep$very$o2.Foo, Foo, _m)?.call(_deep$very$o2$Foo).toString; + (_deep$very$o3 = deep?.very.o) === null || _deep$very$o3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_deep$very$o3$Foo = _deep$very$o3.Foo, Foo, _m)?.call(_deep$very$o3$Foo).toString(); (o === null || o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFi = _classStaticPrivateFieldSpecGet(o.Foo, Foo, _self), Foo, _m))?.call(_classStaticPrivateFi); (o === null || o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFi2 = _classStaticPrivateFieldSpecGet(o.Foo, Foo, _self).self, Foo, _m))?.call(_classStaticPrivateFi2); - - _classStaticPrivateFieldSpecGet(_ref$self = _ref.self, Foo, _m).call(_ref$self); - - _classStaticPrivateFieldSpecGet(_ref2$self = _ref2.self, Foo, _m).call(_ref2$self); - - _classStaticPrivateFieldSpecGet(_self2$self = _self2.self, Foo, _m).call(_self2$self); - + (_ref = o === null || o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(o.Foo, Foo, _self)) === null || _ref === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref$self = _ref.self, Foo, _m)?.call(_ref$self); + (_ref2 = o === null || o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(o.Foo, Foo, _self).self) === null || _ref2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref2$self = _ref2.self, Foo, _m)?.call(_ref2$self); + (_self2 = (o === null || o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(o.Foo, Foo, _self))?.self) === null || _self2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_self2$self = _self2.self, Foo, _m)?.call(_self2$self); (o === null || o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFi3 = _classStaticPrivateFieldSpecGet(o.Foo, Foo, _self).getSelf(), Foo, _m))?.call(_classStaticPrivateFi3); - - _classStaticPrivateFieldSpecGet(_ref3$call = _ref3.call(_classStaticPrivateFi4), Foo, _m).call(_ref3$call); - - _classStaticPrivateFieldSpecGet(_ref4$getSelf = _ref4.getSelf(), Foo, _m).call(_ref4$getSelf); - - _classStaticPrivateFieldSpecGet(_getSelf$call = _getSelf.call(_ref5), Foo, _m).call(_getSelf$call); - - _classStaticPrivateFieldSpecGet(_ref6$self = _ref6.self, Foo, _m).call(_ref6$self); - - _classStaticPrivateFieldSpecGet(_call$self = _call.self, Foo, _m).call(_call$self); - - _classStaticPrivateFieldSpecGet(_getSelf2$self = _getSelf2.self, Foo, _m).call(_getSelf2$self); - - _classStaticPrivateFieldSpecGet(_getSelf3$self = _getSelf3.self, Foo, _m).call(_getSelf3$self); - - _classStaticPrivateFieldSpecGet(_fn$Foo = fn().Foo, Foo, _m).call(_fn$Foo); - - _classStaticPrivateFieldSpecGet(_fn$Foo2 = fn().Foo, Foo, _m).call(_fn$Foo2).toString; - _classStaticPrivateFieldSpecGet(_fn$Foo3 = fn().Foo, Foo, _m).call(_fn$Foo3).toString(); - - _classStaticPrivateFieldSpecGet(_fnDeep$very$o$Foo = _fnDeep$very$o.Foo, Foo, _m).call(_fnDeep$very$o$Foo); - - _classStaticPrivateFieldSpecGet(_fnDeep$very$o2$Foo = _fnDeep$very$o2.Foo, Foo, _m).call(_fnDeep$very$o2$Foo).toString; - _classStaticPrivateFieldSpecGet(_fnDeep$very$o3$Foo = _fnDeep$very$o3.Foo, Foo, _m).call(_fnDeep$very$o3$Foo).toString(); + (_ref3 = o === null || o === void 0 ? void 0 : (_classStaticPrivateFi4 = _classStaticPrivateFieldSpecGet(o.Foo, Foo, _self)).getSelf) === null || _ref3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref3$call = _ref3.call(_classStaticPrivateFi4), Foo, _m)?.call(_ref3$call); + (_ref4 = o === null || o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(o.Foo, Foo, _self)) === null || _ref4 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref4$getSelf = _ref4.getSelf(), Foo, _m)?.call(_ref4$getSelf); + (_getSelf = (_ref5 = o === null || o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(o.Foo, Foo, _self))?.getSelf) === null || _getSelf === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_getSelf$call = _getSelf.call(_ref5), Foo, _m)?.call(_getSelf$call); + (_ref6 = o === null || o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(o.Foo, Foo, _self).getSelf()) === null || _ref6 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref6$self = _ref6.self, Foo, _m)?.call(_ref6$self); + (_call = (o === null || o === void 0 ? void 0 : (_classStaticPrivateFi5 = _classStaticPrivateFieldSpecGet(o.Foo, Foo, _self)).getSelf)?.call(_classStaticPrivateFi5)) === null || _call === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_call$self = _call.self, Foo, _m)?.call(_call$self); + (_getSelf2 = (o === null || o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(o.Foo, Foo, _self))?.getSelf()) === null || _getSelf2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_getSelf2$self = _getSelf2.self, Foo, _m)?.call(_getSelf2$self); + (_getSelf3 = (o === null || o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(o.Foo, Foo, _self))?.getSelf?.()) === null || _getSelf3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_getSelf3$self = _getSelf3.self, Foo, _m)?.call(_getSelf3$self); + fn === null || fn === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn$Foo = fn().Foo, Foo, _m)?.call(_fn$Foo); + fn === null || fn === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn$Foo2 = fn().Foo, Foo, _m)?.call(_fn$Foo2).toString; + fn === null || fn === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fn$Foo3 = fn().Foo, Foo, _m)?.call(_fn$Foo3).toString(); + (_fnDeep$very$o = fnDeep?.().very.o) === null || _fnDeep$very$o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fnDeep$very$o$Foo = _fnDeep$very$o.Foo, Foo, _m)?.call(_fnDeep$very$o$Foo); + (_fnDeep$very$o2 = fnDeep?.().very.o) === null || _fnDeep$very$o2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fnDeep$very$o2$Foo = _fnDeep$very$o2.Foo, Foo, _m)?.call(_fnDeep$very$o2$Foo).toString; + (_fnDeep$very$o3 = fnDeep?.().very.o) === null || _fnDeep$very$o3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fnDeep$very$o3$Foo = _fnDeep$very$o3.Foo, Foo, _m)?.call(_fnDeep$very$o3$Foo).toString(); (fn === null || fn === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFi6 = _classStaticPrivateFieldSpecGet(fn().Foo, Foo, _self), Foo, _m))?.call(_classStaticPrivateFi6); (fn === null || fn === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFi7 = _classStaticPrivateFieldSpecGet(fn().Foo, Foo, _self).self, Foo, _m))?.call(_classStaticPrivateFi7); - - _classStaticPrivateFieldSpecGet(_ref7$self = _ref7.self, Foo, _m).call(_ref7$self); - - _classStaticPrivateFieldSpecGet(_ref8$self = _ref8.self, Foo, _m).call(_ref8$self); - - _classStaticPrivateFieldSpecGet(_self3$self = _self3.self, Foo, _m).call(_self3$self); - + (_ref7 = fn === null || fn === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(fn().Foo, Foo, _self)) === null || _ref7 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref7$self = _ref7.self, Foo, _m)?.call(_ref7$self); + (_ref8 = fn === null || fn === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(fn().Foo, Foo, _self).self) === null || _ref8 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref8$self = _ref8.self, Foo, _m)?.call(_ref8$self); + (_self3 = (fn === null || fn === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(fn().Foo, Foo, _self))?.self) === null || _self3 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_self3$self = _self3.self, Foo, _m)?.call(_self3$self); (fn === null || fn === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFi8 = _classStaticPrivateFieldSpecGet(fn().Foo, Foo, _self).getSelf(), Foo, _m))?.call(_classStaticPrivateFi8); - - _classStaticPrivateFieldSpecGet(_ref9$call = _ref9.call(_classStaticPrivateFi9), Foo, _m).call(_ref9$call); - - _classStaticPrivateFieldSpecGet(_ref10$getSelf = _ref10.getSelf(), Foo, _m).call(_ref10$getSelf); - - _classStaticPrivateFieldSpecGet(_getSelf4$call = _getSelf4.call(_ref11), Foo, _m).call(_getSelf4$call); - - _classStaticPrivateFieldSpecGet(_ref12$self = _ref12.self, Foo, _m).call(_ref12$self); - - _classStaticPrivateFieldSpecGet(_call2$self = _call2.self, Foo, _m).call(_call2$self); - - _classStaticPrivateFieldSpecGet(_getSelf5$self = _getSelf5.self, Foo, _m).call(_getSelf5$self); - - _classStaticPrivateFieldSpecGet(_getSelf6$self = _getSelf6.self, Foo, _m).call(_getSelf6$self); - } - - static testtest() { - var _fn, _classStaticPrivateFi11, _ref13, _ref13$call; - - _classStaticPrivateFieldSpecGet(_ref13$call = _ref13.call(_classStaticPrivateFi11), Foo, _m).call(_ref13$call); + (_ref9 = fn === null || fn === void 0 ? void 0 : (_classStaticPrivateFi9 = _classStaticPrivateFieldSpecGet(fn().Foo, Foo, _self)).getSelf) === null || _ref9 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref9$call = _ref9.call(_classStaticPrivateFi9), Foo, _m)?.call(_ref9$call); + (_ref10 = fn === null || fn === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(fn().Foo, Foo, _self)) === null || _ref10 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref10$getSelf = _ref10.getSelf(), Foo, _m)?.call(_ref10$getSelf); + (_getSelf4 = (_ref11 = fn === null || fn === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(fn().Foo, Foo, _self))?.getSelf) === null || _getSelf4 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_getSelf4$call = _getSelf4.call(_ref11), Foo, _m)?.call(_getSelf4$call); + (_ref12 = fn === null || fn === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(fn().Foo, Foo, _self).getSelf()) === null || _ref12 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_ref12$self = _ref12.self, Foo, _m)?.call(_ref12$self); + (_call2 = (fn === null || fn === void 0 ? void 0 : (_classStaticPrivateFi10 = _classStaticPrivateFieldSpecGet(fn().Foo, Foo, _self)).getSelf)?.call(_classStaticPrivateFi10)) === null || _call2 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_call2$self = _call2.self, Foo, _m)?.call(_call2$self); + (_getSelf5 = (fn === null || fn === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(fn().Foo, Foo, _self))?.getSelf()) === null || _getSelf5 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_getSelf5$self = _getSelf5.self, Foo, _m)?.call(_getSelf5$self); + (_getSelf6 = (fn === null || fn === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(fn().Foo, Foo, _self))?.getSelf?.()) === null || _getSelf6 === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_getSelf6$self = _getSelf6.self, Foo, _m)?.call(_getSelf6$self); } } From aee43de94789086d40c30db9d148a33c238282cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hu=C3=A1ng=20J=C3=B9nli=C3=A0ng?= Date: Mon, 25 May 2020 13:15:29 -0400 Subject: [PATCH 17/20] add loose test cases --- .../exec.js | 0 .../input.js | 0 .../options.json | 2 +- .../output.js | 34 ++--- .../optional-chain-before-member-call/exec.js | 122 +++++++++++++++++ .../input.js | 0 .../options.json | 4 + .../output.js | 0 .../exec.js | 0 .../input.js | 0 .../options.json | 1 + .../output.js | 34 ++--- .../optional-chain-before-property/exec.js | 121 +++++++++++++++++ .../input.js | 0 .../options.json | 4 + .../output.js | 0 .../exec.js | 126 ++++++++++++++++++ .../input.js | 71 ++++++++++ .../options.json | 1 + .../output.js | 98 ++++++++++++++ .../exec.js | 126 ++++++++++++++++++ .../input.js | 71 ++++++++++ .../options.json | 4 + .../output.js | 98 ++++++++++++++ .../exec.js | 126 ++++++++++++++++++ .../input.js | 70 ++++++++++ .../options.json | 2 +- .../output.js | 98 ++++++++++++++ .../exec.js | 126 ++++++++++++++++++ .../input.js | 70 ++++++++++ .../options.json | 4 + .../output.js | 98 ++++++++++++++ .../exec.js | 125 +++++++++++++++++ .../input.js | 69 ++++++++++ .../options.json | 6 + .../output.js | 90 +++++++++++++ .../optional-chain-optional-property/exec.js | 125 +++++++++++++++++ .../optional-chain-optional-property/input.js | 70 ++++++++++ .../options.json | 4 + .../output.js | 90 +++++++++++++ 40 files changed, 2054 insertions(+), 36 deletions(-) rename packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/{optional-chain-private-call-with-transform => optional-chain-before-member-call-with-transform}/exec.js (100%) rename packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/{optional-chain-private-call-with-transform => optional-chain-before-member-call-with-transform}/input.js (100%) rename packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/{optional-chain-private-call-with-transform => optional-chain-before-member-call-with-transform}/options.json (58%) rename packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/{optional-chain-private-call-with-transform => optional-chain-before-member-call-with-transform}/output.js (62%) create mode 100644 packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-before-member-call/exec.js rename packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/{optional-chain-private-call => optional-chain-before-member-call}/input.js (100%) create mode 100644 packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-before-member-call/options.json rename packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/{optional-chain-private-call => optional-chain-before-member-call}/output.js (100%) rename packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/{optional-chain-with-transform => optional-chain-before-property-with-transform}/exec.js (100%) rename packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/{optional-chain-with-transform => optional-chain-before-property-with-transform}/input.js (100%) rename packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/{optional-chain => optional-chain-before-property-with-transform}/options.json (58%) rename packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/{optional-chain-with-transform => optional-chain-before-property-with-transform}/output.js (61%) create mode 100644 packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-before-property/exec.js rename packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/{optional-chain => optional-chain-before-property}/input.js (100%) create mode 100644 packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-before-property/options.json rename packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/{optional-chain => optional-chain-before-property}/output.js (100%) create mode 100644 packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-member-optional-call-with-transform/exec.js create mode 100644 packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-member-optional-call-with-transform/input.js rename packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/{optional-chain-private-call => optional-chain-member-optional-call-with-transform}/options.json (58%) create mode 100644 packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-member-optional-call-with-transform/output.js create mode 100644 packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-member-optional-call/exec.js create mode 100644 packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-member-optional-call/input.js create mode 100644 packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-member-optional-call/options.json create mode 100644 packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-member-optional-call/output.js create mode 100644 packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-optional-member-call-with-transform/exec.js create mode 100644 packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-optional-member-call-with-transform/input.js rename packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/{optional-chain-with-transform => optional-chain-optional-member-call-with-transform}/options.json (58%) create mode 100644 packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-optional-member-call-with-transform/output.js create mode 100644 packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-optional-member-call/exec.js create mode 100644 packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-optional-member-call/input.js create mode 100644 packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-optional-member-call/options.json create mode 100644 packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-optional-member-call/output.js create mode 100644 packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-optional-property-with-transform/exec.js create mode 100644 packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-optional-property-with-transform/input.js create mode 100644 packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-optional-property-with-transform/options.json create mode 100644 packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-optional-property-with-transform/output.js create mode 100644 packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-optional-property/exec.js create mode 100644 packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-optional-property/input.js create mode 100644 packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-optional-property/options.json create mode 100644 packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-optional-property/output.js diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-private-call-with-transform/exec.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-before-member-call-with-transform/exec.js similarity index 100% rename from packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-private-call-with-transform/exec.js rename to packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-before-member-call-with-transform/exec.js diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-private-call-with-transform/input.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-before-member-call-with-transform/input.js similarity index 100% rename from packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-private-call-with-transform/input.js rename to packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-before-member-call-with-transform/input.js diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-private-call-with-transform/options.json b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-before-member-call-with-transform/options.json similarity index 58% rename from packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-private-call-with-transform/options.json rename to packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-before-member-call-with-transform/options.json index 9a7eaaa890b3..124133b5af2b 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-private-call-with-transform/options.json +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-before-member-call-with-transform/options.json @@ -1,6 +1,6 @@ { "plugins": [ - "proposal-optional-chaining", + ["proposal-optional-chaining", { "loose": true }], ["proposal-class-properties", { "loose": true }] ] } diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-private-call-with-transform/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-before-member-call-with-transform/output.js similarity index 62% rename from packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-private-call-with-transform/output.js rename to packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-before-member-call-with-transform/output.js index 9bd6511f49f6..a7f5c767a7b2 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-private-call-with-transform/output.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-before-member-call-with-transform/output.js @@ -10,7 +10,7 @@ class Foo { } static test() { - var _deep$very$o, _deep$very$o2, _deep$very$o3, _ref, _ref2, _self2, _classPrivateFieldLoo, _ref3, _ref4, _getSelf, _ref5, _ref6, _classPrivateFieldLoo2, _call, _getSelf2, _getSelf3, _fnDeep$very$o, _fnDeep$very$o2, _fnDeep$very$o3, _ref7, _ref8, _self3, _classPrivateFieldLoo3, _ref9, _ref10, _getSelf4, _ref11, _ref12, _classPrivateFieldLoo4, _call2, _getSelf5, _getSelf6, _ref13, _ref14, _ref15, _ref16, _ref17, _ref17$getSelf, _ref18, _ref19, _ref20, _ref21, _ref22, _ref22$getSelf; + var _deep$very$o, _deep$very$o2, _deep$very$o3, _ref, _ref2, _self2, _classPrivateFieldLoo, _ref3, _ref4, _getSelf, _ref5, _ref6, _classPrivateFieldLoo2, _call, _getSelf2, _getSelf3, _fnDeep$very$o, _fnDeep$very$o2, _fnDeep$very$o3, _ref7, _ref8, _self3, _classPrivateFieldLoo3, _ref9, _ref10, _getSelf4, _ref11, _ref12, _classPrivateFieldLoo4, _call2, _getSelf5, _getSelf6, _ref13, _ref14, _ref15, _ref16, _ref17, _ref18, _ref19, _ref20, _ref21, _ref22; const o = { Foo: Foo @@ -32,41 +32,41 @@ class Foo { o === null || o === void 0 ? void 0 : _classPrivateFieldLooseBase(o.Foo, _m)[_m](); o === null || o === void 0 ? void 0 : _classPrivateFieldLooseBase(o.Foo, _m)[_m]().toString; o === null || o === void 0 ? void 0 : _classPrivateFieldLooseBase(o.Foo, _m)[_m]().toString(); - (_deep$very$o = deep === null || deep === void 0 ? void 0 : deep.very.o) === null || _deep$very$o === void 0 ? void 0 : _classPrivateFieldLooseBase(_deep$very$o.Foo, _m)[_m](); - (_deep$very$o2 = deep === null || deep === void 0 ? void 0 : deep.very.o) === null || _deep$very$o2 === void 0 ? void 0 : _classPrivateFieldLooseBase(_deep$very$o2.Foo, _m)[_m]().toString; - (_deep$very$o3 = deep === null || deep === void 0 ? void 0 : deep.very.o) === null || _deep$very$o3 === void 0 ? void 0 : _classPrivateFieldLooseBase(_deep$very$o3.Foo, _m)[_m]().toString(); + (_deep$very$o = deep == null ? void 0 : deep.very.o) === null || _deep$very$o === void 0 ? void 0 : _classPrivateFieldLooseBase(_deep$very$o.Foo, _m)[_m](); + (_deep$very$o2 = deep == null ? void 0 : deep.very.o) === null || _deep$very$o2 === void 0 ? void 0 : _classPrivateFieldLooseBase(_deep$very$o2.Foo, _m)[_m]().toString; + (_deep$very$o3 = deep == null ? void 0 : deep.very.o) === null || _deep$very$o3 === void 0 ? void 0 : _classPrivateFieldLooseBase(_deep$very$o3.Foo, _m)[_m]().toString(); o === null || o === void 0 ? void 0 : _classPrivateFieldLooseBase(_classPrivateFieldLooseBase(o.Foo, _self)[_self], _m)[_m](); o === null || o === void 0 ? void 0 : _classPrivateFieldLooseBase(_classPrivateFieldLooseBase(o.Foo, _self)[_self].self, _m)[_m](); (_ref = o === null || o === void 0 ? void 0 : _classPrivateFieldLooseBase(o.Foo, _self)[_self]) === null || _ref === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref.self, _m)[_m](); (_ref2 = o === null || o === void 0 ? void 0 : _classPrivateFieldLooseBase(o.Foo, _self)[_self].self) === null || _ref2 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref2.self, _m)[_m](); - (_self2 = (_ref13 = o === null || o === void 0 ? void 0 : _classPrivateFieldLooseBase(o.Foo, _self)[_self]) === null || _ref13 === void 0 ? void 0 : _ref13.self) === null || _self2 === void 0 ? void 0 : _classPrivateFieldLooseBase(_self2.self, _m)[_m](); + (_self2 = (_ref13 = o === null || o === void 0 ? void 0 : _classPrivateFieldLooseBase(o.Foo, _self)[_self]) == null ? void 0 : _ref13.self) === null || _self2 === void 0 ? void 0 : _classPrivateFieldLooseBase(_self2.self, _m)[_m](); o === null || o === void 0 ? void 0 : _classPrivateFieldLooseBase(_classPrivateFieldLooseBase(o.Foo, _self)[_self].getSelf(), _m)[_m](); (_ref3 = o === null || o === void 0 ? void 0 : (_classPrivateFieldLoo = _classPrivateFieldLooseBase(o.Foo, _self)[_self]).getSelf) === null || _ref3 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref3.call(_classPrivateFieldLoo), _m)[_m](); (_ref4 = o === null || o === void 0 ? void 0 : _classPrivateFieldLooseBase(o.Foo, _self)[_self]) === null || _ref4 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref4.getSelf(), _m)[_m](); - (_getSelf = (_ref14 = _ref5 = o === null || o === void 0 ? void 0 : _classPrivateFieldLooseBase(o.Foo, _self)[_self]) === null || _ref14 === void 0 ? void 0 : _ref14.getSelf) === null || _getSelf === void 0 ? void 0 : _classPrivateFieldLooseBase(_getSelf.call(_ref5), _m)[_m](); + (_getSelf = (_ref14 = _ref5 = o === null || o === void 0 ? void 0 : _classPrivateFieldLooseBase(o.Foo, _self)[_self]) == null ? void 0 : _ref14.getSelf) === null || _getSelf === void 0 ? void 0 : _classPrivateFieldLooseBase(_getSelf.call(_ref5), _m)[_m](); (_ref6 = o === null || o === void 0 ? void 0 : _classPrivateFieldLooseBase(o.Foo, _self)[_self].getSelf()) === null || _ref6 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref6.self, _m)[_m](); - (_call = (_ref15 = o === null || o === void 0 ? void 0 : (_classPrivateFieldLoo2 = _classPrivateFieldLooseBase(o.Foo, _self)[_self]).getSelf) === null || _ref15 === void 0 ? void 0 : _ref15.call(_classPrivateFieldLoo2)) === null || _call === void 0 ? void 0 : _classPrivateFieldLooseBase(_call.self, _m)[_m](); - (_getSelf2 = (_ref16 = o === null || o === void 0 ? void 0 : _classPrivateFieldLooseBase(o.Foo, _self)[_self]) === null || _ref16 === void 0 ? void 0 : _ref16.getSelf()) === null || _getSelf2 === void 0 ? void 0 : _classPrivateFieldLooseBase(_getSelf2.self, _m)[_m](); - (_getSelf3 = (_ref17 = o === null || o === void 0 ? void 0 : _classPrivateFieldLooseBase(o.Foo, _self)[_self]) === null || _ref17 === void 0 ? void 0 : (_ref17$getSelf = _ref17.getSelf) === null || _ref17$getSelf === void 0 ? void 0 : _ref17$getSelf.call(_ref17)) === null || _getSelf3 === void 0 ? void 0 : _classPrivateFieldLooseBase(_getSelf3.self, _m)[_m](); + (_call = (_ref15 = o === null || o === void 0 ? void 0 : (_classPrivateFieldLoo2 = _classPrivateFieldLooseBase(o.Foo, _self)[_self]).getSelf) == null ? void 0 : _ref15.call(_classPrivateFieldLoo2)) === null || _call === void 0 ? void 0 : _classPrivateFieldLooseBase(_call.self, _m)[_m](); + (_getSelf2 = (_ref16 = o === null || o === void 0 ? void 0 : _classPrivateFieldLooseBase(o.Foo, _self)[_self]) == null ? void 0 : _ref16.getSelf()) === null || _getSelf2 === void 0 ? void 0 : _classPrivateFieldLooseBase(_getSelf2.self, _m)[_m](); + (_getSelf3 = (_ref17 = o === null || o === void 0 ? void 0 : _classPrivateFieldLooseBase(o.Foo, _self)[_self]) == null ? void 0 : _ref17.getSelf == null ? void 0 : _ref17.getSelf()) === null || _getSelf3 === void 0 ? void 0 : _classPrivateFieldLooseBase(_getSelf3.self, _m)[_m](); fn === null || fn === void 0 ? void 0 : _classPrivateFieldLooseBase(fn().Foo, _m)[_m](); fn === null || fn === void 0 ? void 0 : _classPrivateFieldLooseBase(fn().Foo, _m)[_m]().toString; fn === null || fn === void 0 ? void 0 : _classPrivateFieldLooseBase(fn().Foo, _m)[_m]().toString(); - (_fnDeep$very$o = fnDeep === null || fnDeep === void 0 ? void 0 : fnDeep().very.o) === null || _fnDeep$very$o === void 0 ? void 0 : _classPrivateFieldLooseBase(_fnDeep$very$o.Foo, _m)[_m](); - (_fnDeep$very$o2 = fnDeep === null || fnDeep === void 0 ? void 0 : fnDeep().very.o) === null || _fnDeep$very$o2 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fnDeep$very$o2.Foo, _m)[_m]().toString; - (_fnDeep$very$o3 = fnDeep === null || fnDeep === void 0 ? void 0 : fnDeep().very.o) === null || _fnDeep$very$o3 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fnDeep$very$o3.Foo, _m)[_m]().toString(); + (_fnDeep$very$o = fnDeep == null ? void 0 : fnDeep().very.o) === null || _fnDeep$very$o === void 0 ? void 0 : _classPrivateFieldLooseBase(_fnDeep$very$o.Foo, _m)[_m](); + (_fnDeep$very$o2 = fnDeep == null ? void 0 : fnDeep().very.o) === null || _fnDeep$very$o2 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fnDeep$very$o2.Foo, _m)[_m]().toString; + (_fnDeep$very$o3 = fnDeep == null ? void 0 : fnDeep().very.o) === null || _fnDeep$very$o3 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fnDeep$very$o3.Foo, _m)[_m]().toString(); fn === null || fn === void 0 ? void 0 : _classPrivateFieldLooseBase(_classPrivateFieldLooseBase(fn().Foo, _self)[_self], _m)[_m](); fn === null || fn === void 0 ? void 0 : _classPrivateFieldLooseBase(_classPrivateFieldLooseBase(fn().Foo, _self)[_self].self, _m)[_m](); (_ref7 = fn === null || fn === void 0 ? void 0 : _classPrivateFieldLooseBase(fn().Foo, _self)[_self]) === null || _ref7 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref7.self, _m)[_m](); (_ref8 = fn === null || fn === void 0 ? void 0 : _classPrivateFieldLooseBase(fn().Foo, _self)[_self].self) === null || _ref8 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref8.self, _m)[_m](); - (_self3 = (_ref18 = fn === null || fn === void 0 ? void 0 : _classPrivateFieldLooseBase(fn().Foo, _self)[_self]) === null || _ref18 === void 0 ? void 0 : _ref18.self) === null || _self3 === void 0 ? void 0 : _classPrivateFieldLooseBase(_self3.self, _m)[_m](); + (_self3 = (_ref18 = fn === null || fn === void 0 ? void 0 : _classPrivateFieldLooseBase(fn().Foo, _self)[_self]) == null ? void 0 : _ref18.self) === null || _self3 === void 0 ? void 0 : _classPrivateFieldLooseBase(_self3.self, _m)[_m](); fn === null || fn === void 0 ? void 0 : _classPrivateFieldLooseBase(_classPrivateFieldLooseBase(fn().Foo, _self)[_self].getSelf(), _m)[_m](); (_ref9 = fn === null || fn === void 0 ? void 0 : (_classPrivateFieldLoo3 = _classPrivateFieldLooseBase(fn().Foo, _self)[_self]).getSelf) === null || _ref9 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref9.call(_classPrivateFieldLoo3), _m)[_m](); (_ref10 = fn === null || fn === void 0 ? void 0 : _classPrivateFieldLooseBase(fn().Foo, _self)[_self]) === null || _ref10 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref10.getSelf(), _m)[_m](); - (_getSelf4 = (_ref19 = _ref11 = fn === null || fn === void 0 ? void 0 : _classPrivateFieldLooseBase(fn().Foo, _self)[_self]) === null || _ref19 === void 0 ? void 0 : _ref19.getSelf) === null || _getSelf4 === void 0 ? void 0 : _classPrivateFieldLooseBase(_getSelf4.call(_ref11), _m)[_m](); + (_getSelf4 = (_ref19 = _ref11 = fn === null || fn === void 0 ? void 0 : _classPrivateFieldLooseBase(fn().Foo, _self)[_self]) == null ? void 0 : _ref19.getSelf) === null || _getSelf4 === void 0 ? void 0 : _classPrivateFieldLooseBase(_getSelf4.call(_ref11), _m)[_m](); (_ref12 = fn === null || fn === void 0 ? void 0 : _classPrivateFieldLooseBase(fn().Foo, _self)[_self].getSelf()) === null || _ref12 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref12.self, _m)[_m](); - (_call2 = (_ref20 = fn === null || fn === void 0 ? void 0 : (_classPrivateFieldLoo4 = _classPrivateFieldLooseBase(fn().Foo, _self)[_self]).getSelf) === null || _ref20 === void 0 ? void 0 : _ref20.call(_classPrivateFieldLoo4)) === null || _call2 === void 0 ? void 0 : _classPrivateFieldLooseBase(_call2.self, _m)[_m](); - (_getSelf5 = (_ref21 = fn === null || fn === void 0 ? void 0 : _classPrivateFieldLooseBase(fn().Foo, _self)[_self]) === null || _ref21 === void 0 ? void 0 : _ref21.getSelf()) === null || _getSelf5 === void 0 ? void 0 : _classPrivateFieldLooseBase(_getSelf5.self, _m)[_m](); - (_getSelf6 = (_ref22 = fn === null || fn === void 0 ? void 0 : _classPrivateFieldLooseBase(fn().Foo, _self)[_self]) === null || _ref22 === void 0 ? void 0 : (_ref22$getSelf = _ref22.getSelf) === null || _ref22$getSelf === void 0 ? void 0 : _ref22$getSelf.call(_ref22)) === null || _getSelf6 === void 0 ? void 0 : _classPrivateFieldLooseBase(_getSelf6.self, _m)[_m](); + (_call2 = (_ref20 = fn === null || fn === void 0 ? void 0 : (_classPrivateFieldLoo4 = _classPrivateFieldLooseBase(fn().Foo, _self)[_self]).getSelf) == null ? void 0 : _ref20.call(_classPrivateFieldLoo4)) === null || _call2 === void 0 ? void 0 : _classPrivateFieldLooseBase(_call2.self, _m)[_m](); + (_getSelf5 = (_ref21 = fn === null || fn === void 0 ? void 0 : _classPrivateFieldLooseBase(fn().Foo, _self)[_self]) == null ? void 0 : _ref21.getSelf()) === null || _getSelf5 === void 0 ? void 0 : _classPrivateFieldLooseBase(_getSelf5.self, _m)[_m](); + (_getSelf6 = (_ref22 = fn === null || fn === void 0 ? void 0 : _classPrivateFieldLooseBase(fn().Foo, _self)[_self]) == null ? void 0 : _ref22.getSelf == null ? void 0 : _ref22.getSelf()) === null || _getSelf6 === void 0 ? void 0 : _classPrivateFieldLooseBase(_getSelf6.self, _m)[_m](); } } diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-before-member-call/exec.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-before-member-call/exec.js new file mode 100644 index 000000000000..13cc95662d95 --- /dev/null +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-before-member-call/exec.js @@ -0,0 +1,122 @@ +class Foo { + static #x = 1; + static #m = function() { return this.#x; }; + static #self = Foo; + static self = Foo; + static getSelf() { return this } + + static test() { + const o = { Foo: Foo }; + const deep = { very: { o } }; + function fn() { + return o; + } + function fnDeep() { + return deep; + } + + expect(o?.Foo.#m()).toEqual(1); + expect(o?.Foo.#m().toString).toEqual(1..toString); + expect(o?.Foo.#m().toString()).toEqual('1'); + + expect(deep?.very.o?.Foo.#m()).toEqual(1); + expect(deep?.very.o?.Foo.#m().toString).toEqual(1..toString); + expect(deep?.very.o?.Foo.#m().toString()).toEqual('1'); + + expect(o?.Foo.#self.#m()).toEqual(1); + expect(o?.Foo.#self.self.#m()).toEqual(1); + expect(o?.Foo.#self?.self.#m()).toEqual(1); + expect(o?.Foo.#self.self?.self.#m()).toEqual(1); + expect(o?.Foo.#self?.self?.self.#m()).toEqual(1); + + expect(o?.Foo.#self.getSelf().#m()).toEqual(1); + expect(o?.Foo.#self.getSelf?.().#m()).toEqual(1); + expect(o?.Foo.#self?.getSelf().#m()).toEqual(1); + expect(o?.Foo.#self?.getSelf?.().#m()).toEqual(1); + expect(o?.Foo.#self.getSelf()?.self.#m()).toEqual(1); + expect(o?.Foo.#self.getSelf?.()?.self.#m()).toEqual(1); + expect(o?.Foo.#self?.getSelf()?.self.#m()).toEqual(1); + expect(o?.Foo.#self?.getSelf?.()?.self.#m()).toEqual(1); + + expect(fn?.().Foo.#m()).toEqual(1); + expect(fn?.().Foo.#m().toString).toEqual(1..toString); + expect(fn?.().Foo.#m().toString()).toEqual('1'); + + expect(fnDeep?.().very.o?.Foo.#m()).toEqual(1); + expect(fnDeep?.().very.o?.Foo.#m().toString).toEqual(1..toString); + expect(fnDeep?.().very.o?.Foo.#m().toString()).toEqual('1'); + + expect(fn?.().Foo.#self.#m()).toEqual(1); + expect(fn?.().Foo.#self.self.#m()).toEqual(1); + expect(fn?.().Foo.#self?.self.#m()).toEqual(1); + expect(fn?.().Foo.#self.self?.self.#m()).toEqual(1); + expect(fn?.().Foo.#self?.self?.self.#m()).toEqual(1); + + expect(fn?.().Foo.#self.getSelf().#m()).toEqual(1); + expect(fn?.().Foo.#self.getSelf?.().#m()).toEqual(1); + expect(fn?.().Foo.#self?.getSelf().#m()).toEqual(1); + expect(fn?.().Foo.#self?.getSelf?.().#m()).toEqual(1); + expect(fn?.().Foo.#self.getSelf()?.self.#m()).toEqual(1); + expect(fn?.().Foo.#self.getSelf?.()?.self.#m()).toEqual(1); + expect(fn?.().Foo.#self?.getSelf()?.self.#m()).toEqual(1); + expect(fn?.().Foo.#self?.getSelf?.()?.self.#m()).toEqual(1); + } + + static testNull() { + const o = null;; + const deep = { very: { o } }; + const fn = null; + function fnDeep() { + return deep; + } + + expect(o?.Foo.#m()).toEqual(undefined); + expect(o?.Foo.#m().toString).toEqual(undefined); + expect(o?.Foo.#m().toString()).toEqual(undefined); + + expect(deep?.very.o?.Foo.#m()).toEqual(undefined); + expect(deep?.very.o?.Foo.#m().toString).toEqual(undefined); + expect(deep?.very.o?.Foo.#m().toString()).toEqual(undefined); + + expect(o?.Foo.#self.#m()).toEqual(undefined); + expect(o?.Foo.#self.self.#m()).toEqual(undefined); + expect(o?.Foo.#self?.self.#m()).toEqual(undefined); + expect(o?.Foo.#self.self?.self.#m()).toEqual(undefined); + expect(o?.Foo.#self?.self?.self.#m()).toEqual(undefined); + + expect(o?.Foo.#self.getSelf().#m()).toEqual(undefined); + expect(o?.Foo.#self.getSelf?.().#m()).toEqual(undefined); + expect(o?.Foo.#self?.getSelf().#m()).toEqual(undefined); + expect(o?.Foo.#self?.getSelf?.().#m()).toEqual(undefined); + expect(o?.Foo.#self.getSelf()?.self.#m()).toEqual(undefined); + expect(o?.Foo.#self.getSelf?.()?.self.#m()).toEqual(undefined); + expect(o?.Foo.#self?.getSelf()?.self.#m()).toEqual(undefined); + expect(o?.Foo.#self?.getSelf?.()?.self.#m()).toEqual(undefined); + + expect(fn?.().Foo.#m()).toEqual(undefined); + expect(fn?.().Foo.#m().toString).toEqual(undefined); + expect(fn?.().Foo.#m().toString()).toEqual(undefined); + + expect(fnDeep?.().very.o?.Foo.#m()).toEqual(undefined); + expect(fnDeep?.().very.o?.Foo.#m().toString).toEqual(undefined); + expect(fnDeep?.().very.o?.Foo.#m().toString()).toEqual(undefined); + + expect(fn?.().Foo.#self.#m()).toEqual(undefined); + expect(fn?.().Foo.#self.self.#m()).toEqual(undefined); + expect(fn?.().Foo.#self?.self.#m()).toEqual(undefined); + expect(fn?.().Foo.#self.self?.self.#m()).toEqual(undefined); + expect(fn?.().Foo.#self?.self?.self.#m()).toEqual(undefined); + + expect(fn?.().Foo.#self.getSelf().#m()).toEqual(undefined); + expect(fn?.().Foo.#self.getSelf?.().#m()).toEqual(undefined); + expect(fn?.().Foo.#self?.getSelf().#m()).toEqual(undefined); + expect(fn?.().Foo.#self?.getSelf?.().#m()).toEqual(undefined); + expect(fn?.().Foo.#self.getSelf()?.self.#m()).toEqual(undefined); + expect(fn?.().Foo.#self.getSelf?.()?.self.#m()).toEqual(undefined); + expect(fn?.().Foo.#self?.getSelf()?.self.#m()).toEqual(undefined); + expect(fn?.().Foo.#self?.getSelf?.()?.self.#m()).toEqual(undefined); + } +} + +Foo.test(); +Foo.testNull(); diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-private-call/input.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-before-member-call/input.js similarity index 100% rename from packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-private-call/input.js rename to packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-before-member-call/input.js diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-before-member-call/options.json b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-before-member-call/options.json new file mode 100644 index 000000000000..2d5cfe8e8095 --- /dev/null +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-before-member-call/options.json @@ -0,0 +1,4 @@ +{ + "plugins": [["proposal-class-properties", { "loose": true }]], + "minNodeVersion": "14.0.0" +} diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-private-call/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-before-member-call/output.js similarity index 100% rename from packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-private-call/output.js rename to packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-before-member-call/output.js diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-with-transform/exec.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-before-property-with-transform/exec.js similarity index 100% rename from packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-with-transform/exec.js rename to packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-before-property-with-transform/exec.js diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-with-transform/input.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-before-property-with-transform/input.js similarity index 100% rename from packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-with-transform/input.js rename to packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-before-property-with-transform/input.js diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain/options.json b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-before-property-with-transform/options.json similarity index 58% rename from packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain/options.json rename to packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-before-property-with-transform/options.json index 1d89a5dde92f..124133b5af2b 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain/options.json +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-before-property-with-transform/options.json @@ -1,5 +1,6 @@ { "plugins": [ + ["proposal-optional-chaining", { "loose": true }], ["proposal-class-properties", { "loose": true }] ] } diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-with-transform/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-before-property-with-transform/output.js similarity index 61% rename from packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-with-transform/output.js rename to packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-before-property-with-transform/output.js index e247de3d3c63..c48dfe3de5a9 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-with-transform/output.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-before-property-with-transform/output.js @@ -10,7 +10,7 @@ class Foo { } static test() { - var _deep$very$o, _deep$very$o2, _deep$very$o3, _ref, _ref2, _self2, _classPrivateFieldLoo, _ref3, _ref4, _getSelf, _ref5, _ref6, _classPrivateFieldLoo2, _call, _getSelf2, _getSelf3, _fnDeep$very$o, _fnDeep$very$o2, _fnDeep$very$o3, _ref7, _ref8, _self3, _classPrivateFieldLoo3, _ref9, _ref10, _getSelf4, _ref11, _ref12, _classPrivateFieldLoo4, _call2, _getSelf5, _getSelf6, _ref13, _ref14, _ref15, _ref16, _ref17, _ref17$getSelf, _ref18, _ref19, _ref20, _ref21, _ref22, _ref22$getSelf; + var _deep$very$o, _deep$very$o2, _deep$very$o3, _ref, _ref2, _self2, _classPrivateFieldLoo, _ref3, _ref4, _getSelf, _ref5, _ref6, _classPrivateFieldLoo2, _call, _getSelf2, _getSelf3, _fnDeep$very$o, _fnDeep$very$o2, _fnDeep$very$o3, _ref7, _ref8, _self3, _classPrivateFieldLoo3, _ref9, _ref10, _getSelf4, _ref11, _ref12, _classPrivateFieldLoo4, _call2, _getSelf5, _getSelf6, _ref13, _ref14, _ref15, _ref16, _ref17, _ref18, _ref19, _ref20, _ref21, _ref22; const o = { Foo: Foo @@ -32,41 +32,41 @@ class Foo { o === null || o === void 0 ? void 0 : _classPrivateFieldLooseBase(o.Foo, _x)[_x]; o === null || o === void 0 ? void 0 : _classPrivateFieldLooseBase(o.Foo, _x)[_x].toString; o === null || o === void 0 ? void 0 : _classPrivateFieldLooseBase(o.Foo, _x)[_x].toString(); - (_deep$very$o = deep === null || deep === void 0 ? void 0 : deep.very.o) === null || _deep$very$o === void 0 ? void 0 : _classPrivateFieldLooseBase(_deep$very$o.Foo, _x)[_x]; - (_deep$very$o2 = deep === null || deep === void 0 ? void 0 : deep.very.o) === null || _deep$very$o2 === void 0 ? void 0 : _classPrivateFieldLooseBase(_deep$very$o2.Foo, _x)[_x].toString; - (_deep$very$o3 = deep === null || deep === void 0 ? void 0 : deep.very.o) === null || _deep$very$o3 === void 0 ? void 0 : _classPrivateFieldLooseBase(_deep$very$o3.Foo, _x)[_x].toString(); + (_deep$very$o = deep == null ? void 0 : deep.very.o) === null || _deep$very$o === void 0 ? void 0 : _classPrivateFieldLooseBase(_deep$very$o.Foo, _x)[_x]; + (_deep$very$o2 = deep == null ? void 0 : deep.very.o) === null || _deep$very$o2 === void 0 ? void 0 : _classPrivateFieldLooseBase(_deep$very$o2.Foo, _x)[_x].toString; + (_deep$very$o3 = deep == null ? void 0 : deep.very.o) === null || _deep$very$o3 === void 0 ? void 0 : _classPrivateFieldLooseBase(_deep$very$o3.Foo, _x)[_x].toString(); o === null || o === void 0 ? void 0 : _classPrivateFieldLooseBase(_classPrivateFieldLooseBase(o.Foo, _self)[_self], _x)[_x]; o === null || o === void 0 ? void 0 : _classPrivateFieldLooseBase(_classPrivateFieldLooseBase(o.Foo, _self)[_self].self, _x)[_x]; (_ref = o === null || o === void 0 ? void 0 : _classPrivateFieldLooseBase(o.Foo, _self)[_self]) === null || _ref === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref.self, _x)[_x]; (_ref2 = o === null || o === void 0 ? void 0 : _classPrivateFieldLooseBase(o.Foo, _self)[_self].self) === null || _ref2 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref2.self, _x)[_x]; - (_self2 = (_ref13 = o === null || o === void 0 ? void 0 : _classPrivateFieldLooseBase(o.Foo, _self)[_self]) === null || _ref13 === void 0 ? void 0 : _ref13.self) === null || _self2 === void 0 ? void 0 : _classPrivateFieldLooseBase(_self2.self, _x)[_x]; + (_self2 = (_ref13 = o === null || o === void 0 ? void 0 : _classPrivateFieldLooseBase(o.Foo, _self)[_self]) == null ? void 0 : _ref13.self) === null || _self2 === void 0 ? void 0 : _classPrivateFieldLooseBase(_self2.self, _x)[_x]; o === null || o === void 0 ? void 0 : _classPrivateFieldLooseBase(_classPrivateFieldLooseBase(o.Foo, _self)[_self].getSelf(), _x)[_x]; (_ref3 = o === null || o === void 0 ? void 0 : (_classPrivateFieldLoo = _classPrivateFieldLooseBase(o.Foo, _self)[_self]).getSelf) === null || _ref3 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref3.call(_classPrivateFieldLoo), _x)[_x]; (_ref4 = o === null || o === void 0 ? void 0 : _classPrivateFieldLooseBase(o.Foo, _self)[_self]) === null || _ref4 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref4.getSelf(), _x)[_x]; - (_getSelf = (_ref14 = _ref5 = o === null || o === void 0 ? void 0 : _classPrivateFieldLooseBase(o.Foo, _self)[_self]) === null || _ref14 === void 0 ? void 0 : _ref14.getSelf) === null || _getSelf === void 0 ? void 0 : _classPrivateFieldLooseBase(_getSelf.call(_ref5), _x)[_x]; + (_getSelf = (_ref14 = _ref5 = o === null || o === void 0 ? void 0 : _classPrivateFieldLooseBase(o.Foo, _self)[_self]) == null ? void 0 : _ref14.getSelf) === null || _getSelf === void 0 ? void 0 : _classPrivateFieldLooseBase(_getSelf.call(_ref5), _x)[_x]; (_ref6 = o === null || o === void 0 ? void 0 : _classPrivateFieldLooseBase(o.Foo, _self)[_self].getSelf()) === null || _ref6 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref6.self, _x)[_x]; - (_call = (_ref15 = o === null || o === void 0 ? void 0 : (_classPrivateFieldLoo2 = _classPrivateFieldLooseBase(o.Foo, _self)[_self]).getSelf) === null || _ref15 === void 0 ? void 0 : _ref15.call(_classPrivateFieldLoo2)) === null || _call === void 0 ? void 0 : _classPrivateFieldLooseBase(_call.self, _x)[_x]; - (_getSelf2 = (_ref16 = o === null || o === void 0 ? void 0 : _classPrivateFieldLooseBase(o.Foo, _self)[_self]) === null || _ref16 === void 0 ? void 0 : _ref16.getSelf()) === null || _getSelf2 === void 0 ? void 0 : _classPrivateFieldLooseBase(_getSelf2.self, _x)[_x]; - (_getSelf3 = (_ref17 = o === null || o === void 0 ? void 0 : _classPrivateFieldLooseBase(o.Foo, _self)[_self]) === null || _ref17 === void 0 ? void 0 : (_ref17$getSelf = _ref17.getSelf) === null || _ref17$getSelf === void 0 ? void 0 : _ref17$getSelf.call(_ref17)) === null || _getSelf3 === void 0 ? void 0 : _classPrivateFieldLooseBase(_getSelf3.self, _x)[_x]; + (_call = (_ref15 = o === null || o === void 0 ? void 0 : (_classPrivateFieldLoo2 = _classPrivateFieldLooseBase(o.Foo, _self)[_self]).getSelf) == null ? void 0 : _ref15.call(_classPrivateFieldLoo2)) === null || _call === void 0 ? void 0 : _classPrivateFieldLooseBase(_call.self, _x)[_x]; + (_getSelf2 = (_ref16 = o === null || o === void 0 ? void 0 : _classPrivateFieldLooseBase(o.Foo, _self)[_self]) == null ? void 0 : _ref16.getSelf()) === null || _getSelf2 === void 0 ? void 0 : _classPrivateFieldLooseBase(_getSelf2.self, _x)[_x]; + (_getSelf3 = (_ref17 = o === null || o === void 0 ? void 0 : _classPrivateFieldLooseBase(o.Foo, _self)[_self]) == null ? void 0 : _ref17.getSelf == null ? void 0 : _ref17.getSelf()) === null || _getSelf3 === void 0 ? void 0 : _classPrivateFieldLooseBase(_getSelf3.self, _x)[_x]; fn === null || fn === void 0 ? void 0 : _classPrivateFieldLooseBase(fn().Foo, _x)[_x]; fn === null || fn === void 0 ? void 0 : _classPrivateFieldLooseBase(fn().Foo, _x)[_x].toString; fn === null || fn === void 0 ? void 0 : _classPrivateFieldLooseBase(fn().Foo, _x)[_x].toString(); - (_fnDeep$very$o = fnDeep === null || fnDeep === void 0 ? void 0 : fnDeep().very.o) === null || _fnDeep$very$o === void 0 ? void 0 : _classPrivateFieldLooseBase(_fnDeep$very$o.Foo, _x)[_x]; - (_fnDeep$very$o2 = fnDeep === null || fnDeep === void 0 ? void 0 : fnDeep().very.o) === null || _fnDeep$very$o2 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fnDeep$very$o2.Foo, _x)[_x].toString; - (_fnDeep$very$o3 = fnDeep === null || fnDeep === void 0 ? void 0 : fnDeep().very.o) === null || _fnDeep$very$o3 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fnDeep$very$o3.Foo, _x)[_x].toString(); + (_fnDeep$very$o = fnDeep == null ? void 0 : fnDeep().very.o) === null || _fnDeep$very$o === void 0 ? void 0 : _classPrivateFieldLooseBase(_fnDeep$very$o.Foo, _x)[_x]; + (_fnDeep$very$o2 = fnDeep == null ? void 0 : fnDeep().very.o) === null || _fnDeep$very$o2 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fnDeep$very$o2.Foo, _x)[_x].toString; + (_fnDeep$very$o3 = fnDeep == null ? void 0 : fnDeep().very.o) === null || _fnDeep$very$o3 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fnDeep$very$o3.Foo, _x)[_x].toString(); fn === null || fn === void 0 ? void 0 : _classPrivateFieldLooseBase(_classPrivateFieldLooseBase(fn().Foo, _self)[_self], _x)[_x]; fn === null || fn === void 0 ? void 0 : _classPrivateFieldLooseBase(_classPrivateFieldLooseBase(fn().Foo, _self)[_self].self, _x)[_x]; (_ref7 = fn === null || fn === void 0 ? void 0 : _classPrivateFieldLooseBase(fn().Foo, _self)[_self]) === null || _ref7 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref7.self, _x)[_x]; (_ref8 = fn === null || fn === void 0 ? void 0 : _classPrivateFieldLooseBase(fn().Foo, _self)[_self].self) === null || _ref8 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref8.self, _x)[_x]; - (_self3 = (_ref18 = fn === null || fn === void 0 ? void 0 : _classPrivateFieldLooseBase(fn().Foo, _self)[_self]) === null || _ref18 === void 0 ? void 0 : _ref18.self) === null || _self3 === void 0 ? void 0 : _classPrivateFieldLooseBase(_self3.self, _x)[_x]; + (_self3 = (_ref18 = fn === null || fn === void 0 ? void 0 : _classPrivateFieldLooseBase(fn().Foo, _self)[_self]) == null ? void 0 : _ref18.self) === null || _self3 === void 0 ? void 0 : _classPrivateFieldLooseBase(_self3.self, _x)[_x]; fn === null || fn === void 0 ? void 0 : _classPrivateFieldLooseBase(_classPrivateFieldLooseBase(fn().Foo, _self)[_self].getSelf(), _x)[_x]; (_ref9 = fn === null || fn === void 0 ? void 0 : (_classPrivateFieldLoo3 = _classPrivateFieldLooseBase(fn().Foo, _self)[_self]).getSelf) === null || _ref9 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref9.call(_classPrivateFieldLoo3), _x)[_x]; (_ref10 = fn === null || fn === void 0 ? void 0 : _classPrivateFieldLooseBase(fn().Foo, _self)[_self]) === null || _ref10 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref10.getSelf(), _x)[_x]; - (_getSelf4 = (_ref19 = _ref11 = fn === null || fn === void 0 ? void 0 : _classPrivateFieldLooseBase(fn().Foo, _self)[_self]) === null || _ref19 === void 0 ? void 0 : _ref19.getSelf) === null || _getSelf4 === void 0 ? void 0 : _classPrivateFieldLooseBase(_getSelf4.call(_ref11), _x)[_x]; + (_getSelf4 = (_ref19 = _ref11 = fn === null || fn === void 0 ? void 0 : _classPrivateFieldLooseBase(fn().Foo, _self)[_self]) == null ? void 0 : _ref19.getSelf) === null || _getSelf4 === void 0 ? void 0 : _classPrivateFieldLooseBase(_getSelf4.call(_ref11), _x)[_x]; (_ref12 = fn === null || fn === void 0 ? void 0 : _classPrivateFieldLooseBase(fn().Foo, _self)[_self].getSelf()) === null || _ref12 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref12.self, _x)[_x]; - (_call2 = (_ref20 = fn === null || fn === void 0 ? void 0 : (_classPrivateFieldLoo4 = _classPrivateFieldLooseBase(fn().Foo, _self)[_self]).getSelf) === null || _ref20 === void 0 ? void 0 : _ref20.call(_classPrivateFieldLoo4)) === null || _call2 === void 0 ? void 0 : _classPrivateFieldLooseBase(_call2.self, _x)[_x]; - (_getSelf5 = (_ref21 = fn === null || fn === void 0 ? void 0 : _classPrivateFieldLooseBase(fn().Foo, _self)[_self]) === null || _ref21 === void 0 ? void 0 : _ref21.getSelf()) === null || _getSelf5 === void 0 ? void 0 : _classPrivateFieldLooseBase(_getSelf5.self, _x)[_x]; - (_getSelf6 = (_ref22 = fn === null || fn === void 0 ? void 0 : _classPrivateFieldLooseBase(fn().Foo, _self)[_self]) === null || _ref22 === void 0 ? void 0 : (_ref22$getSelf = _ref22.getSelf) === null || _ref22$getSelf === void 0 ? void 0 : _ref22$getSelf.call(_ref22)) === null || _getSelf6 === void 0 ? void 0 : _classPrivateFieldLooseBase(_getSelf6.self, _x)[_x]; + (_call2 = (_ref20 = fn === null || fn === void 0 ? void 0 : (_classPrivateFieldLoo4 = _classPrivateFieldLooseBase(fn().Foo, _self)[_self]).getSelf) == null ? void 0 : _ref20.call(_classPrivateFieldLoo4)) === null || _call2 === void 0 ? void 0 : _classPrivateFieldLooseBase(_call2.self, _x)[_x]; + (_getSelf5 = (_ref21 = fn === null || fn === void 0 ? void 0 : _classPrivateFieldLooseBase(fn().Foo, _self)[_self]) == null ? void 0 : _ref21.getSelf()) === null || _getSelf5 === void 0 ? void 0 : _classPrivateFieldLooseBase(_getSelf5.self, _x)[_x]; + (_getSelf6 = (_ref22 = fn === null || fn === void 0 ? void 0 : _classPrivateFieldLooseBase(fn().Foo, _self)[_self]) == null ? void 0 : _ref22.getSelf == null ? void 0 : _ref22.getSelf()) === null || _getSelf6 === void 0 ? void 0 : _classPrivateFieldLooseBase(_getSelf6.self, _x)[_x]; } } diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-before-property/exec.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-before-property/exec.js new file mode 100644 index 000000000000..98ac8e7a7e12 --- /dev/null +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-before-property/exec.js @@ -0,0 +1,121 @@ +class Foo { + static #x = 1; + static #self = Foo; + static self = Foo; + static getSelf() { return this } + + static test() { + const o = { Foo: Foo }; + const deep = { very: { o } }; + function fn() { + return o; + } + function fnDeep() { + return deep; + } + + expect(o?.Foo.#x).toEqual(1); + expect(o?.Foo.#x.toString).toEqual(1..toString); + expect(o?.Foo.#x.toString()).toEqual('1'); + + expect(deep?.very.o?.Foo.#x).toEqual(1); + expect(deep?.very.o?.Foo.#x.toString).toEqual(1..toString); + expect(deep?.very.o?.Foo.#x.toString()).toEqual('1'); + + expect(o?.Foo.#self.#x).toEqual(1); + expect(o?.Foo.#self.self.#x).toEqual(1); + expect(o?.Foo.#self?.self.#x).toEqual(1); + expect(o?.Foo.#self.self?.self.#x).toEqual(1); + expect(o?.Foo.#self?.self?.self.#x).toEqual(1); + + expect(o?.Foo.#self.getSelf().#x).toEqual(1); + expect(o?.Foo.#self.getSelf?.().#x).toEqual(1); + expect(o?.Foo.#self?.getSelf().#x).toEqual(1); + expect(o?.Foo.#self?.getSelf?.().#x).toEqual(1); + expect(o?.Foo.#self.getSelf()?.self.#x).toEqual(1); + expect(o?.Foo.#self.getSelf?.()?.self.#x).toEqual(1); + expect(o?.Foo.#self?.getSelf()?.self.#x).toEqual(1); + expect(o?.Foo.#self?.getSelf?.()?.self.#x).toEqual(1); + + expect(fn?.().Foo.#x).toEqual(1); + expect(fn?.().Foo.#x.toString).toEqual(1..toString); + expect(fn?.().Foo.#x.toString()).toEqual('1'); + + expect(fnDeep?.().very.o?.Foo.#x).toEqual(1); + expect(fnDeep?.().very.o?.Foo.#x.toString).toEqual(1..toString); + expect(fnDeep?.().very.o?.Foo.#x.toString()).toEqual('1'); + + expect(fn?.().Foo.#self.#x).toEqual(1); + expect(fn?.().Foo.#self.self.#x).toEqual(1); + expect(fn?.().Foo.#self?.self.#x).toEqual(1); + expect(fn?.().Foo.#self.self?.self.#x).toEqual(1); + expect(fn?.().Foo.#self?.self?.self.#x).toEqual(1); + + expect(fn?.().Foo.#self.getSelf().#x).toEqual(1); + expect(fn?.().Foo.#self.getSelf?.().#x).toEqual(1); + expect(fn?.().Foo.#self?.getSelf().#x).toEqual(1); + expect(fn?.().Foo.#self?.getSelf?.().#x).toEqual(1); + expect(fn?.().Foo.#self.getSelf()?.self.#x).toEqual(1); + expect(fn?.().Foo.#self.getSelf?.()?.self.#x).toEqual(1); + expect(fn?.().Foo.#self?.getSelf()?.self.#x).toEqual(1); + expect(fn?.().Foo.#self?.getSelf?.()?.self.#x).toEqual(1); + } + + static testNull() { + const o = null;; + const deep = { very: { o } }; + const fn = null; + function fnDeep() { + return deep; + } + + expect(o?.Foo.#x).toEqual(undefined); + expect(o?.Foo.#x.toString).toEqual(undefined); + expect(o?.Foo.#x.toString()).toEqual(undefined); + + expect(deep?.very.o?.Foo.#x).toEqual(undefined); + expect(deep?.very.o?.Foo.#x.toString).toEqual(undefined); + expect(deep?.very.o?.Foo.#x.toString()).toEqual(undefined); + + expect(o?.Foo.#self.#x).toEqual(undefined); + expect(o?.Foo.#self.self.#x).toEqual(undefined); + expect(o?.Foo.#self?.self.#x).toEqual(undefined); + expect(o?.Foo.#self.self?.self.#x).toEqual(undefined); + expect(o?.Foo.#self?.self?.self.#x).toEqual(undefined); + + expect(o?.Foo.#self.getSelf().#x).toEqual(undefined); + expect(o?.Foo.#self.getSelf?.().#x).toEqual(undefined); + expect(o?.Foo.#self?.getSelf().#x).toEqual(undefined); + expect(o?.Foo.#self?.getSelf?.().#x).toEqual(undefined); + expect(o?.Foo.#self.getSelf()?.self.#x).toEqual(undefined); + expect(o?.Foo.#self.getSelf?.()?.self.#x).toEqual(undefined); + expect(o?.Foo.#self?.getSelf()?.self.#x).toEqual(undefined); + expect(o?.Foo.#self?.getSelf?.()?.self.#x).toEqual(undefined); + + expect(fn?.().Foo.#x).toEqual(undefined); + expect(fn?.().Foo.#x.toString).toEqual(undefined); + expect(fn?.().Foo.#x.toString()).toEqual(undefined); + + expect(fnDeep?.().very.o?.Foo.#x).toEqual(undefined); + expect(fnDeep?.().very.o?.Foo.#x.toString).toEqual(undefined); + expect(fnDeep?.().very.o?.Foo.#x.toString()).toEqual(undefined); + + expect(fn?.().Foo.#self.#x).toEqual(undefined); + expect(fn?.().Foo.#self.self.#x).toEqual(undefined); + expect(fn?.().Foo.#self?.self.#x).toEqual(undefined); + expect(fn?.().Foo.#self.self?.self.#x).toEqual(undefined); + expect(fn?.().Foo.#self?.self?.self.#x).toEqual(undefined); + + expect(fn?.().Foo.#self.getSelf().#x).toEqual(undefined); + expect(fn?.().Foo.#self.getSelf?.().#x).toEqual(undefined); + expect(fn?.().Foo.#self?.getSelf().#x).toEqual(undefined); + expect(fn?.().Foo.#self?.getSelf?.().#x).toEqual(undefined); + expect(fn?.().Foo.#self.getSelf()?.self.#x).toEqual(undefined); + expect(fn?.().Foo.#self.getSelf?.()?.self.#x).toEqual(undefined); + expect(fn?.().Foo.#self?.getSelf()?.self.#x).toEqual(undefined); + expect(fn?.().Foo.#self?.getSelf?.()?.self.#x).toEqual(undefined); + } +} + +Foo.test(); +Foo.testNull(); diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain/input.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-before-property/input.js similarity index 100% rename from packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain/input.js rename to packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-before-property/input.js diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-before-property/options.json b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-before-property/options.json new file mode 100644 index 000000000000..2d5cfe8e8095 --- /dev/null +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-before-property/options.json @@ -0,0 +1,4 @@ +{ + "plugins": [["proposal-class-properties", { "loose": true }]], + "minNodeVersion": "14.0.0" +} diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-before-property/output.js similarity index 100% rename from packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain/output.js rename to packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-before-property/output.js diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-member-optional-call-with-transform/exec.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-member-optional-call-with-transform/exec.js new file mode 100644 index 000000000000..6e82fc8d6543 --- /dev/null +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-member-optional-call-with-transform/exec.js @@ -0,0 +1,126 @@ +class Foo { + static #x = 1; + static #m = function() { return this.#x; }; + static #self = Foo; + static self = Foo; + static getSelf() { return this } + + static test() { + 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(o?.Foo.#m?.()).toEqual(1); + expect(o?.Foo.#m?.().toString).toEqual(1..toString); + expect(o?.Foo.#m?.().toString()).toEqual('1'); + + expect(deep?.very.o?.Foo.#m?.()).toEqual(1); + expect(deep?.very.o?.Foo.#m?.().toString).toEqual(1..toString); + expect(deep?.very.o?.Foo.#m?.().toString()).toEqual('1'); + + expect(o?.Foo.#self.#m?.()).toEqual(1); + expect(o?.Foo.#self.self.#m?.()).toEqual(1); + expect(o?.Foo.#self?.self.#m?.()).toEqual(1); + expect(o?.Foo.#self.self?.self.#m?.()).toEqual(1); + expect(o?.Foo.#self?.self?.self.#m?.()).toEqual(1); + + expect(o?.Foo.#self.getSelf().#m?.()).toEqual(1); + expect(o?.Foo.#self.getSelf?.().#m?.()).toEqual(1); + expect(o?.Foo.#self?.getSelf().#m?.()).toEqual(1); + expect(o?.Foo.#self?.getSelf?.().#m?.()).toEqual(1); + expect(o?.Foo.#self.getSelf()?.self.#m?.()).toEqual(1); + expect(o?.Foo.#self.getSelf?.()?.self.#m?.()).toEqual(1); + expect(o?.Foo.#self?.getSelf()?.self.#m?.()).toEqual(1); + expect(o?.Foo.#self?.getSelf?.()?.self.#m?.()).toEqual(1); + + expect(fn?.().Foo.#m?.()).toEqual(1); + expect(fn?.().Foo.#m?.().toString).toEqual(1..toString); + expect(fn?.().Foo.#m?.().toString()).toEqual('1'); + + expect(fnDeep?.().very.o?.Foo.#m?.()).toEqual(1); + expect(fnDeep?.().very.o?.Foo.#m?.().toString).toEqual(1..toString); + expect(fnDeep?.().very.o?.Foo.#m?.().toString()).toEqual('1'); + + expect(fn?.().Foo.#self.#m?.()).toEqual(1); + expect(fn?.().Foo.#self.self.#m?.()).toEqual(1); + expect(fn?.().Foo.#self?.self.#m?.()).toEqual(1); + expect(fn?.().Foo.#self.self?.self.#m?.()).toEqual(1); + expect(fn?.().Foo.#self?.self?.self.#m?.()).toEqual(1); + + expect(fn?.().Foo.#self.getSelf().#m?.()).toEqual(1); + expect(fn?.().Foo.#self.getSelf?.().#m?.()).toEqual(1); + expect(fn?.().Foo.#self?.getSelf().#m?.()).toEqual(1); + expect(fn?.().Foo.#self?.getSelf?.().#m?.()).toEqual(1); + expect(fn?.().Foo.#self.getSelf()?.self.#m?.()).toEqual(1); + expect(fn?.().Foo.#self.getSelf?.()?.self.#m?.()).toEqual(1); + expect(fn?.().Foo.#self?.getSelf()?.self.#m?.()).toEqual(1); + expect(fn?.().Foo.#self?.getSelf?.()?.self.#m?.()).toEqual(1); + } + + static testNull() { + const o = null;; + const deep = { very: { o } }; + const fn = null; + function fnDeep() { + return deep; + } + + expect(o?.Foo.#m?.()).toEqual(undefined); + expect(o?.Foo.#m?.().toString).toEqual(undefined); + expect(o?.Foo.#m?.().toString()).toEqual(undefined); + + expect(deep?.very.o?.Foo.#m?.()).toEqual(undefined); + expect(deep?.very.o?.Foo.#m?.().toString).toEqual(undefined); + expect(deep?.very.o?.Foo.#m?.().toString()).toEqual(undefined); + + expect(o?.Foo.#self.#m?.()).toEqual(undefined); + expect(o?.Foo.#self.self.#m?.()).toEqual(undefined); + expect(o?.Foo.#self?.self.#m?.()).toEqual(undefined); + expect(o?.Foo.#self.self?.self.#m?.()).toEqual(undefined); + expect(o?.Foo.#self?.self?.self.#m?.()).toEqual(undefined); + + expect(o?.Foo.#self.getSelf().#m?.()).toEqual(undefined); + expect(o?.Foo.#self.getSelf?.().#m?.()).toEqual(undefined); + expect(o?.Foo.#self?.getSelf().#m?.()).toEqual(undefined); + expect(o?.Foo.#self?.getSelf?.().#m?.()).toEqual(undefined); + expect(o?.Foo.#self.getSelf()?.self.#m?.()).toEqual(undefined); + expect(o?.Foo.#self.getSelf?.()?.self.#m?.()).toEqual(undefined); + expect(o?.Foo.#self?.getSelf()?.self.#m?.()).toEqual(undefined); + expect(o?.Foo.#self?.getSelf?.()?.self.#m?.()).toEqual(undefined); + + expect(fn?.().Foo.#m?.()).toEqual(undefined); + expect(fn?.().Foo.#m?.().toString).toEqual(undefined); + expect(fn?.().Foo.#m?.().toString()).toEqual(undefined); + + expect(fnDeep?.().very.o?.Foo.#m?.()).toEqual(undefined); + expect(fnDeep?.().very.o?.Foo.#m?.().toString).toEqual(undefined); + expect(fnDeep?.().very.o?.Foo.#m?.().toString()).toEqual(undefined); + + expect(fn?.().Foo.#self.#m?.()).toEqual(undefined); + expect(fn?.().Foo.#self.self.#m?.()).toEqual(undefined); + expect(fn?.().Foo.#self?.self.#m?.()).toEqual(undefined); + expect(fn?.().Foo.#self.self?.self.#m?.()).toEqual(undefined); + expect(fn?.().Foo.#self?.self?.self.#m?.()).toEqual(undefined); + + expect(fn?.().Foo.#self.getSelf().#m?.()).toEqual(undefined); + expect(fn?.().Foo.#self.getSelf?.().#m?.()).toEqual(undefined); + expect(fn?.().Foo.#self?.getSelf().#m?.()).toEqual(undefined); + expect(fn?.().Foo.#self?.getSelf?.().#m?.()).toEqual(undefined); + expect(fn?.().Foo.#self.getSelf()?.self.#m?.()).toEqual(undefined); + expect(fn?.().Foo.#self.getSelf?.()?.self.#m?.()).toEqual(undefined); + expect(fn?.().Foo.#self?.getSelf()?.self.#m?.()).toEqual(undefined); + expect(fn?.().Foo.#self?.getSelf?.()?.self.#m?.()).toEqual(undefined); + } +} + +Foo.test(); +Foo.testNull(); diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-member-optional-call-with-transform/input.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-member-optional-call-with-transform/input.js new file mode 100644 index 000000000000..11dd4a57060d --- /dev/null +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-member-optional-call-with-transform/input.js @@ -0,0 +1,71 @@ +class Foo { + static #x = 1; + static #m = function() { return this.#x; }; + static #self = Foo; + static self = Foo; + static getSelf() { return this } + + static test() { + const o = { Foo: Foo }; + const deep = { very: { o } }; + function fn() { + return o; + } + function fnDeep() { + return deep; + } + + Foo.#m?.(); + Foo.#m?.().toString; + Foo.#m?.().toString(); + + o?.Foo.#m?.(); + o?.Foo.#m?.().toString; + o?.Foo.#m?.().toString(); + + deep?.very.o?.Foo.#m?.(); + deep?.very.o?.Foo.#m?.().toString; + deep?.very.o?.Foo.#m?.().toString(); + + o?.Foo.#self.#m?.(); + o?.Foo.#self.self.#m?.(); + o?.Foo.#self?.self.#m?.(); + o?.Foo.#self.self?.self.#m?.(); + o?.Foo.#self?.self?.self.#m?.(); + + o?.Foo.#self.getSelf().#m?.(); + o?.Foo.#self.getSelf?.().#m?.(); + o?.Foo.#self?.getSelf().#m?.(); + o?.Foo.#self?.getSelf?.().#m?.(); + o?.Foo.#self.getSelf()?.self.#m?.(); + o?.Foo.#self.getSelf?.()?.self.#m?.(); + o?.Foo.#self?.getSelf()?.self.#m?.(); + o?.Foo.#self?.getSelf?.()?.self.#m?.(); + + fn?.().Foo.#m?.(); + fn?.().Foo.#m?.().toString; + fn?.().Foo.#m?.().toString(); + + fnDeep?.().very.o?.Foo.#m?.(); + fnDeep?.().very.o?.Foo.#m?.().toString; + fnDeep?.().very.o?.Foo.#m?.().toString(); + + fn?.().Foo.#self.#m?.(); + fn?.().Foo.#self.self.#m?.(); + fn?.().Foo.#self?.self.#m?.(); + fn?.().Foo.#self.self?.self.#m?.(); + fn?.().Foo.#self?.self?.self.#m?.(); + + fn?.().Foo.#self.getSelf().#m?.(); + fn?.().Foo.#self.getSelf?.().#m?.(); + fn?.().Foo.#self?.getSelf().#m?.(); + fn?.().Foo.#self?.getSelf?.().#m?.(); + fn?.().Foo.#self.getSelf()?.self.#m?.(); + fn?.().Foo.#self.getSelf?.()?.self.#m?.(); + fn?.().Foo.#self?.getSelf()?.self.#m?.(); + fn?.().Foo.#self?.getSelf?.()?.self.#m?.(); + } + +} + +Foo.test(); diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-private-call/options.json b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-member-optional-call-with-transform/options.json similarity index 58% rename from packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-private-call/options.json rename to packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-member-optional-call-with-transform/options.json index 1d89a5dde92f..124133b5af2b 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-private-call/options.json +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-member-optional-call-with-transform/options.json @@ -1,5 +1,6 @@ { "plugins": [ + ["proposal-optional-chaining", { "loose": true }], ["proposal-class-properties", { "loose": true }] ] } diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-member-optional-call-with-transform/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-member-optional-call-with-transform/output.js new file mode 100644 index 000000000000..c51884d907f3 --- /dev/null +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-member-optional-call-with-transform/output.js @@ -0,0 +1,98 @@ +function _classPrivateFieldLooseBase(receiver, privateKey) { if (!Object.prototype.hasOwnProperty.call(receiver, privateKey)) { throw new TypeError("attempted to use private field on non-instance"); } return receiver; } + +var id = 0; + +function _classPrivateFieldLooseKey(name) { return "__private_" + id++ + "_" + name; } + +class Foo { + static getSelf() { + return this; + } + + static test() { + var _deep$very$o, _deep$very$o2, _deep$very$o3, _classPrivateFieldLoo, _classPrivateFieldLoo2, _ref, _ref2, _self2, _classPrivateFieldLoo3, _classPrivateFieldLoo4, _ref3, _ref4, _getSelf, _ref5, _ref6, _classPrivateFieldLoo5, _call, _getSelf2, _getSelf3, _fnDeep$very$o, _fnDeep$very$o2, _fnDeep$very$o3, _classPrivateFieldLoo6, _classPrivateFieldLoo7, _ref7, _ref8, _self3, _classPrivateFieldLoo8, _classPrivateFieldLoo9, _ref9, _ref10, _getSelf4, _ref11, _ref12, _classPrivateFieldLoo10, _call2, _getSelf5, _getSelf6, _classPrivateFieldLoo11, _classPrivateFieldLoo12, _classPrivateFieldLoo13, _classPrivateFieldLoo14, _classPrivateFieldLoo15, _classPrivateFieldLoo16, _classPrivateFieldLoo17, _classPrivateFieldLoo18, _classPrivateFieldLoo19, _classPrivateFieldLoo20, _classPrivateFieldLoo21, _classPrivateFieldLoo22, _classPrivateFieldLoo23, _classPrivateFieldLoo24, _classPrivateFieldLoo25, _classPrivateFieldLoo26, _classPrivateFieldLoo27, _classPrivateFieldLoo28, _ref13, _ref14, _classPrivateFieldLoo29, _classPrivateFieldLoo30, _classPrivateFieldLoo31, _classPrivateFieldLoo32, _ref15, _classPrivateFieldLoo33, _classPrivateFieldLoo34, _ref16, _classPrivateFieldLoo35, _classPrivateFieldLoo36, _classPrivateFieldLoo37, _classPrivateFieldLoo38, _ref17, _classPrivateFieldLoo39, _classPrivateFieldLoo40, _classPrivateFieldLoo41, _classPrivateFieldLoo42, _ref18, _classPrivateFieldLoo43, _classPrivateFieldLoo44, _ref19, _classPrivateFieldLoo45, _classPrivateFieldLoo46, _ref20, _classPrivateFieldLoo47, _classPrivateFieldLoo48, _classPrivateFieldLoo49, _classPrivateFieldLoo50, _classPrivateFieldLoo51, _classPrivateFieldLoo52, _classPrivateFieldLoo53, _classPrivateFieldLoo54, _classPrivateFieldLoo55, _classPrivateFieldLoo56, _classPrivateFieldLoo57, _classPrivateFieldLoo58, _classPrivateFieldLoo59, _classPrivateFieldLoo60, _ref21, _ref22, _classPrivateFieldLoo61, _classPrivateFieldLoo62, _classPrivateFieldLoo63, _classPrivateFieldLoo64, _ref23, _classPrivateFieldLoo65, _classPrivateFieldLoo66, _ref24, _classPrivateFieldLoo67, _classPrivateFieldLoo68, _classPrivateFieldLoo69, _classPrivateFieldLoo70, _ref25, _classPrivateFieldLoo71, _classPrivateFieldLoo72, _classPrivateFieldLoo73, _classPrivateFieldLoo74, _ref26, _classPrivateFieldLoo75, _classPrivateFieldLoo76, _ref27, _classPrivateFieldLoo77, _classPrivateFieldLoo78, _ref28, _classPrivateFieldLoo79, _classPrivateFieldLoo80; + + const o = { + Foo: Foo + }; + const deep = { + very: { + o + } + }; + + function fn() { + return o; + } + + function fnDeep() { + return deep; + } + + (_classPrivateFieldLoo11 = (_classPrivateFieldLoo12 = _classPrivateFieldLooseBase(Foo, _m))[_m]) == null ? void 0 : _classPrivateFieldLoo11.call(_classPrivateFieldLoo12); + (_classPrivateFieldLoo13 = (_classPrivateFieldLoo14 = _classPrivateFieldLooseBase(Foo, _m))[_m]) == null ? void 0 : _classPrivateFieldLoo13.call(_classPrivateFieldLoo14).toString; + (_classPrivateFieldLoo15 = (_classPrivateFieldLoo16 = _classPrivateFieldLooseBase(Foo, _m))[_m]) == null ? void 0 : _classPrivateFieldLoo15.call(_classPrivateFieldLoo16).toString(); + o === null || o === void 0 ? void 0 : (_classPrivateFieldLoo17 = (_classPrivateFieldLoo18 = _classPrivateFieldLooseBase(o.Foo, _m))[_m]) == null ? void 0 : _classPrivateFieldLoo17.call(_classPrivateFieldLoo18); + o === null || o === void 0 ? void 0 : (_classPrivateFieldLoo19 = (_classPrivateFieldLoo20 = _classPrivateFieldLooseBase(o.Foo, _m))[_m]) == null ? void 0 : _classPrivateFieldLoo19.call(_classPrivateFieldLoo20).toString; + o === null || o === void 0 ? void 0 : (_classPrivateFieldLoo21 = (_classPrivateFieldLoo22 = _classPrivateFieldLooseBase(o.Foo, _m))[_m]) == null ? void 0 : _classPrivateFieldLoo21.call(_classPrivateFieldLoo22).toString(); + (_deep$very$o = deep == null ? void 0 : deep.very.o) === null || _deep$very$o === void 0 ? void 0 : (_classPrivateFieldLoo23 = (_classPrivateFieldLoo24 = _classPrivateFieldLooseBase(_deep$very$o.Foo, _m))[_m]) == null ? void 0 : _classPrivateFieldLoo23.call(_classPrivateFieldLoo24); + (_deep$very$o2 = deep == null ? void 0 : deep.very.o) === null || _deep$very$o2 === void 0 ? void 0 : (_classPrivateFieldLoo25 = (_classPrivateFieldLoo26 = _classPrivateFieldLooseBase(_deep$very$o2.Foo, _m))[_m]) == null ? void 0 : _classPrivateFieldLoo25.call(_classPrivateFieldLoo26).toString; + (_deep$very$o3 = deep == null ? void 0 : deep.very.o) === null || _deep$very$o3 === void 0 ? void 0 : (_classPrivateFieldLoo27 = (_classPrivateFieldLoo28 = _classPrivateFieldLooseBase(_deep$very$o3.Foo, _m))[_m]) == null ? void 0 : _classPrivateFieldLoo27.call(_classPrivateFieldLoo28).toString(); + (_ref13 = o === null || o === void 0 ? void 0 : _classPrivateFieldLooseBase(_classPrivateFieldLoo = _classPrivateFieldLooseBase(o.Foo, _self)[_self], _m)[_m]) == null ? void 0 : _ref13.call(_classPrivateFieldLoo); + (_ref14 = o === null || o === void 0 ? void 0 : _classPrivateFieldLooseBase(_classPrivateFieldLoo2 = _classPrivateFieldLooseBase(o.Foo, _self)[_self].self, _m)[_m]) == null ? void 0 : _ref14.call(_classPrivateFieldLoo2); + (_ref = o === null || o === void 0 ? void 0 : _classPrivateFieldLooseBase(o.Foo, _self)[_self]) === null || _ref === void 0 ? void 0 : (_classPrivateFieldLoo29 = (_classPrivateFieldLoo30 = _classPrivateFieldLooseBase(_ref.self, _m))[_m]) == null ? void 0 : _classPrivateFieldLoo29.call(_classPrivateFieldLoo30); + (_ref2 = o === null || o === void 0 ? void 0 : _classPrivateFieldLooseBase(o.Foo, _self)[_self].self) === null || _ref2 === void 0 ? void 0 : (_classPrivateFieldLoo31 = (_classPrivateFieldLoo32 = _classPrivateFieldLooseBase(_ref2.self, _m))[_m]) == null ? void 0 : _classPrivateFieldLoo31.call(_classPrivateFieldLoo32); + (_self2 = (_ref15 = o === null || o === void 0 ? void 0 : _classPrivateFieldLooseBase(o.Foo, _self)[_self]) == null ? void 0 : _ref15.self) === null || _self2 === void 0 ? void 0 : (_classPrivateFieldLoo33 = (_classPrivateFieldLoo34 = _classPrivateFieldLooseBase(_self2.self, _m))[_m]) == null ? void 0 : _classPrivateFieldLoo33.call(_classPrivateFieldLoo34); + (_ref16 = o === null || o === void 0 ? void 0 : _classPrivateFieldLooseBase(_classPrivateFieldLoo3 = _classPrivateFieldLooseBase(o.Foo, _self)[_self].getSelf(), _m)[_m]) == null ? void 0 : _ref16.call(_classPrivateFieldLoo3); + (_ref3 = o === null || o === void 0 ? void 0 : (_classPrivateFieldLoo4 = _classPrivateFieldLooseBase(o.Foo, _self)[_self]).getSelf) === null || _ref3 === void 0 ? void 0 : (_classPrivateFieldLoo35 = (_classPrivateFieldLoo36 = _classPrivateFieldLooseBase(_ref3.call(_classPrivateFieldLoo4), _m))[_m]) == null ? void 0 : _classPrivateFieldLoo35.call(_classPrivateFieldLoo36); + (_ref4 = o === null || o === void 0 ? void 0 : _classPrivateFieldLooseBase(o.Foo, _self)[_self]) === null || _ref4 === void 0 ? void 0 : (_classPrivateFieldLoo37 = (_classPrivateFieldLoo38 = _classPrivateFieldLooseBase(_ref4.getSelf(), _m))[_m]) == null ? void 0 : _classPrivateFieldLoo37.call(_classPrivateFieldLoo38); + (_getSelf = (_ref17 = _ref5 = o === null || o === void 0 ? void 0 : _classPrivateFieldLooseBase(o.Foo, _self)[_self]) == null ? void 0 : _ref17.getSelf) === null || _getSelf === void 0 ? void 0 : (_classPrivateFieldLoo39 = (_classPrivateFieldLoo40 = _classPrivateFieldLooseBase(_getSelf.call(_ref5), _m))[_m]) == null ? void 0 : _classPrivateFieldLoo39.call(_classPrivateFieldLoo40); + (_ref6 = o === null || o === void 0 ? void 0 : _classPrivateFieldLooseBase(o.Foo, _self)[_self].getSelf()) === null || _ref6 === void 0 ? void 0 : (_classPrivateFieldLoo41 = (_classPrivateFieldLoo42 = _classPrivateFieldLooseBase(_ref6.self, _m))[_m]) == null ? void 0 : _classPrivateFieldLoo41.call(_classPrivateFieldLoo42); + (_call = (_ref18 = o === null || o === void 0 ? void 0 : (_classPrivateFieldLoo5 = _classPrivateFieldLooseBase(o.Foo, _self)[_self]).getSelf) == null ? void 0 : _ref18.call(_classPrivateFieldLoo5)) === null || _call === void 0 ? void 0 : (_classPrivateFieldLoo43 = (_classPrivateFieldLoo44 = _classPrivateFieldLooseBase(_call.self, _m))[_m]) == null ? void 0 : _classPrivateFieldLoo43.call(_classPrivateFieldLoo44); + (_getSelf2 = (_ref19 = o === null || o === void 0 ? void 0 : _classPrivateFieldLooseBase(o.Foo, _self)[_self]) == null ? void 0 : _ref19.getSelf()) === null || _getSelf2 === void 0 ? void 0 : (_classPrivateFieldLoo45 = (_classPrivateFieldLoo46 = _classPrivateFieldLooseBase(_getSelf2.self, _m))[_m]) == null ? void 0 : _classPrivateFieldLoo45.call(_classPrivateFieldLoo46); + (_getSelf3 = (_ref20 = o === null || o === void 0 ? void 0 : _classPrivateFieldLooseBase(o.Foo, _self)[_self]) == null ? void 0 : _ref20.getSelf == null ? void 0 : _ref20.getSelf()) === null || _getSelf3 === void 0 ? void 0 : (_classPrivateFieldLoo47 = (_classPrivateFieldLoo48 = _classPrivateFieldLooseBase(_getSelf3.self, _m))[_m]) == null ? void 0 : _classPrivateFieldLoo47.call(_classPrivateFieldLoo48); + fn === null || fn === void 0 ? void 0 : (_classPrivateFieldLoo49 = (_classPrivateFieldLoo50 = _classPrivateFieldLooseBase(fn().Foo, _m))[_m]) == null ? void 0 : _classPrivateFieldLoo49.call(_classPrivateFieldLoo50); + fn === null || fn === void 0 ? void 0 : (_classPrivateFieldLoo51 = (_classPrivateFieldLoo52 = _classPrivateFieldLooseBase(fn().Foo, _m))[_m]) == null ? void 0 : _classPrivateFieldLoo51.call(_classPrivateFieldLoo52).toString; + fn === null || fn === void 0 ? void 0 : (_classPrivateFieldLoo53 = (_classPrivateFieldLoo54 = _classPrivateFieldLooseBase(fn().Foo, _m))[_m]) == null ? void 0 : _classPrivateFieldLoo53.call(_classPrivateFieldLoo54).toString(); + (_fnDeep$very$o = fnDeep == null ? void 0 : fnDeep().very.o) === null || _fnDeep$very$o === void 0 ? void 0 : (_classPrivateFieldLoo55 = (_classPrivateFieldLoo56 = _classPrivateFieldLooseBase(_fnDeep$very$o.Foo, _m))[_m]) == null ? void 0 : _classPrivateFieldLoo55.call(_classPrivateFieldLoo56); + (_fnDeep$very$o2 = fnDeep == null ? void 0 : fnDeep().very.o) === null || _fnDeep$very$o2 === void 0 ? void 0 : (_classPrivateFieldLoo57 = (_classPrivateFieldLoo58 = _classPrivateFieldLooseBase(_fnDeep$very$o2.Foo, _m))[_m]) == null ? void 0 : _classPrivateFieldLoo57.call(_classPrivateFieldLoo58).toString; + (_fnDeep$very$o3 = fnDeep == null ? void 0 : fnDeep().very.o) === null || _fnDeep$very$o3 === void 0 ? void 0 : (_classPrivateFieldLoo59 = (_classPrivateFieldLoo60 = _classPrivateFieldLooseBase(_fnDeep$very$o3.Foo, _m))[_m]) == null ? void 0 : _classPrivateFieldLoo59.call(_classPrivateFieldLoo60).toString(); + (_ref21 = fn === null || fn === void 0 ? void 0 : _classPrivateFieldLooseBase(_classPrivateFieldLoo6 = _classPrivateFieldLooseBase(fn().Foo, _self)[_self], _m)[_m]) == null ? void 0 : _ref21.call(_classPrivateFieldLoo6); + (_ref22 = fn === null || fn === void 0 ? void 0 : _classPrivateFieldLooseBase(_classPrivateFieldLoo7 = _classPrivateFieldLooseBase(fn().Foo, _self)[_self].self, _m)[_m]) == null ? void 0 : _ref22.call(_classPrivateFieldLoo7); + (_ref7 = fn === null || fn === void 0 ? void 0 : _classPrivateFieldLooseBase(fn().Foo, _self)[_self]) === null || _ref7 === void 0 ? void 0 : (_classPrivateFieldLoo61 = (_classPrivateFieldLoo62 = _classPrivateFieldLooseBase(_ref7.self, _m))[_m]) == null ? void 0 : _classPrivateFieldLoo61.call(_classPrivateFieldLoo62); + (_ref8 = fn === null || fn === void 0 ? void 0 : _classPrivateFieldLooseBase(fn().Foo, _self)[_self].self) === null || _ref8 === void 0 ? void 0 : (_classPrivateFieldLoo63 = (_classPrivateFieldLoo64 = _classPrivateFieldLooseBase(_ref8.self, _m))[_m]) == null ? void 0 : _classPrivateFieldLoo63.call(_classPrivateFieldLoo64); + (_self3 = (_ref23 = fn === null || fn === void 0 ? void 0 : _classPrivateFieldLooseBase(fn().Foo, _self)[_self]) == null ? void 0 : _ref23.self) === null || _self3 === void 0 ? void 0 : (_classPrivateFieldLoo65 = (_classPrivateFieldLoo66 = _classPrivateFieldLooseBase(_self3.self, _m))[_m]) == null ? void 0 : _classPrivateFieldLoo65.call(_classPrivateFieldLoo66); + (_ref24 = fn === null || fn === void 0 ? void 0 : _classPrivateFieldLooseBase(_classPrivateFieldLoo8 = _classPrivateFieldLooseBase(fn().Foo, _self)[_self].getSelf(), _m)[_m]) == null ? void 0 : _ref24.call(_classPrivateFieldLoo8); + (_ref9 = fn === null || fn === void 0 ? void 0 : (_classPrivateFieldLoo9 = _classPrivateFieldLooseBase(fn().Foo, _self)[_self]).getSelf) === null || _ref9 === void 0 ? void 0 : (_classPrivateFieldLoo67 = (_classPrivateFieldLoo68 = _classPrivateFieldLooseBase(_ref9.call(_classPrivateFieldLoo9), _m))[_m]) == null ? void 0 : _classPrivateFieldLoo67.call(_classPrivateFieldLoo68); + (_ref10 = fn === null || fn === void 0 ? void 0 : _classPrivateFieldLooseBase(fn().Foo, _self)[_self]) === null || _ref10 === void 0 ? void 0 : (_classPrivateFieldLoo69 = (_classPrivateFieldLoo70 = _classPrivateFieldLooseBase(_ref10.getSelf(), _m))[_m]) == null ? void 0 : _classPrivateFieldLoo69.call(_classPrivateFieldLoo70); + (_getSelf4 = (_ref25 = _ref11 = fn === null || fn === void 0 ? void 0 : _classPrivateFieldLooseBase(fn().Foo, _self)[_self]) == null ? void 0 : _ref25.getSelf) === null || _getSelf4 === void 0 ? void 0 : (_classPrivateFieldLoo71 = (_classPrivateFieldLoo72 = _classPrivateFieldLooseBase(_getSelf4.call(_ref11), _m))[_m]) == null ? void 0 : _classPrivateFieldLoo71.call(_classPrivateFieldLoo72); + (_ref12 = fn === null || fn === void 0 ? void 0 : _classPrivateFieldLooseBase(fn().Foo, _self)[_self].getSelf()) === null || _ref12 === void 0 ? void 0 : (_classPrivateFieldLoo73 = (_classPrivateFieldLoo74 = _classPrivateFieldLooseBase(_ref12.self, _m))[_m]) == null ? void 0 : _classPrivateFieldLoo73.call(_classPrivateFieldLoo74); + (_call2 = (_ref26 = fn === null || fn === void 0 ? void 0 : (_classPrivateFieldLoo10 = _classPrivateFieldLooseBase(fn().Foo, _self)[_self]).getSelf) == null ? void 0 : _ref26.call(_classPrivateFieldLoo10)) === null || _call2 === void 0 ? void 0 : (_classPrivateFieldLoo75 = (_classPrivateFieldLoo76 = _classPrivateFieldLooseBase(_call2.self, _m))[_m]) == null ? void 0 : _classPrivateFieldLoo75.call(_classPrivateFieldLoo76); + (_getSelf5 = (_ref27 = fn === null || fn === void 0 ? void 0 : _classPrivateFieldLooseBase(fn().Foo, _self)[_self]) == null ? void 0 : _ref27.getSelf()) === null || _getSelf5 === void 0 ? void 0 : (_classPrivateFieldLoo77 = (_classPrivateFieldLoo78 = _classPrivateFieldLooseBase(_getSelf5.self, _m))[_m]) == null ? void 0 : _classPrivateFieldLoo77.call(_classPrivateFieldLoo78); + (_getSelf6 = (_ref28 = fn === null || fn === void 0 ? void 0 : _classPrivateFieldLooseBase(fn().Foo, _self)[_self]) == null ? void 0 : _ref28.getSelf == null ? void 0 : _ref28.getSelf()) === null || _getSelf6 === void 0 ? void 0 : (_classPrivateFieldLoo79 = (_classPrivateFieldLoo80 = _classPrivateFieldLooseBase(_getSelf6.self, _m))[_m]) == null ? void 0 : _classPrivateFieldLoo79.call(_classPrivateFieldLoo80); + } + +} + +var _x = _classPrivateFieldLooseKey("x"); + +var _m = _classPrivateFieldLooseKey("m"); + +var _self = _classPrivateFieldLooseKey("self"); + +Object.defineProperty(Foo, _x, { + writable: true, + value: 1 +}); +Object.defineProperty(Foo, _m, { + writable: true, + value: function () { + return _classPrivateFieldLooseBase(this, _x)[_x]; + } +}); +Object.defineProperty(Foo, _self, { + writable: true, + value: Foo +}); +Foo.self = Foo; +Foo.test(); diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-member-optional-call/exec.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-member-optional-call/exec.js new file mode 100644 index 000000000000..6e82fc8d6543 --- /dev/null +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-member-optional-call/exec.js @@ -0,0 +1,126 @@ +class Foo { + static #x = 1; + static #m = function() { return this.#x; }; + static #self = Foo; + static self = Foo; + static getSelf() { return this } + + static test() { + 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(o?.Foo.#m?.()).toEqual(1); + expect(o?.Foo.#m?.().toString).toEqual(1..toString); + expect(o?.Foo.#m?.().toString()).toEqual('1'); + + expect(deep?.very.o?.Foo.#m?.()).toEqual(1); + expect(deep?.very.o?.Foo.#m?.().toString).toEqual(1..toString); + expect(deep?.very.o?.Foo.#m?.().toString()).toEqual('1'); + + expect(o?.Foo.#self.#m?.()).toEqual(1); + expect(o?.Foo.#self.self.#m?.()).toEqual(1); + expect(o?.Foo.#self?.self.#m?.()).toEqual(1); + expect(o?.Foo.#self.self?.self.#m?.()).toEqual(1); + expect(o?.Foo.#self?.self?.self.#m?.()).toEqual(1); + + expect(o?.Foo.#self.getSelf().#m?.()).toEqual(1); + expect(o?.Foo.#self.getSelf?.().#m?.()).toEqual(1); + expect(o?.Foo.#self?.getSelf().#m?.()).toEqual(1); + expect(o?.Foo.#self?.getSelf?.().#m?.()).toEqual(1); + expect(o?.Foo.#self.getSelf()?.self.#m?.()).toEqual(1); + expect(o?.Foo.#self.getSelf?.()?.self.#m?.()).toEqual(1); + expect(o?.Foo.#self?.getSelf()?.self.#m?.()).toEqual(1); + expect(o?.Foo.#self?.getSelf?.()?.self.#m?.()).toEqual(1); + + expect(fn?.().Foo.#m?.()).toEqual(1); + expect(fn?.().Foo.#m?.().toString).toEqual(1..toString); + expect(fn?.().Foo.#m?.().toString()).toEqual('1'); + + expect(fnDeep?.().very.o?.Foo.#m?.()).toEqual(1); + expect(fnDeep?.().very.o?.Foo.#m?.().toString).toEqual(1..toString); + expect(fnDeep?.().very.o?.Foo.#m?.().toString()).toEqual('1'); + + expect(fn?.().Foo.#self.#m?.()).toEqual(1); + expect(fn?.().Foo.#self.self.#m?.()).toEqual(1); + expect(fn?.().Foo.#self?.self.#m?.()).toEqual(1); + expect(fn?.().Foo.#self.self?.self.#m?.()).toEqual(1); + expect(fn?.().Foo.#self?.self?.self.#m?.()).toEqual(1); + + expect(fn?.().Foo.#self.getSelf().#m?.()).toEqual(1); + expect(fn?.().Foo.#self.getSelf?.().#m?.()).toEqual(1); + expect(fn?.().Foo.#self?.getSelf().#m?.()).toEqual(1); + expect(fn?.().Foo.#self?.getSelf?.().#m?.()).toEqual(1); + expect(fn?.().Foo.#self.getSelf()?.self.#m?.()).toEqual(1); + expect(fn?.().Foo.#self.getSelf?.()?.self.#m?.()).toEqual(1); + expect(fn?.().Foo.#self?.getSelf()?.self.#m?.()).toEqual(1); + expect(fn?.().Foo.#self?.getSelf?.()?.self.#m?.()).toEqual(1); + } + + static testNull() { + const o = null;; + const deep = { very: { o } }; + const fn = null; + function fnDeep() { + return deep; + } + + expect(o?.Foo.#m?.()).toEqual(undefined); + expect(o?.Foo.#m?.().toString).toEqual(undefined); + expect(o?.Foo.#m?.().toString()).toEqual(undefined); + + expect(deep?.very.o?.Foo.#m?.()).toEqual(undefined); + expect(deep?.very.o?.Foo.#m?.().toString).toEqual(undefined); + expect(deep?.very.o?.Foo.#m?.().toString()).toEqual(undefined); + + expect(o?.Foo.#self.#m?.()).toEqual(undefined); + expect(o?.Foo.#self.self.#m?.()).toEqual(undefined); + expect(o?.Foo.#self?.self.#m?.()).toEqual(undefined); + expect(o?.Foo.#self.self?.self.#m?.()).toEqual(undefined); + expect(o?.Foo.#self?.self?.self.#m?.()).toEqual(undefined); + + expect(o?.Foo.#self.getSelf().#m?.()).toEqual(undefined); + expect(o?.Foo.#self.getSelf?.().#m?.()).toEqual(undefined); + expect(o?.Foo.#self?.getSelf().#m?.()).toEqual(undefined); + expect(o?.Foo.#self?.getSelf?.().#m?.()).toEqual(undefined); + expect(o?.Foo.#self.getSelf()?.self.#m?.()).toEqual(undefined); + expect(o?.Foo.#self.getSelf?.()?.self.#m?.()).toEqual(undefined); + expect(o?.Foo.#self?.getSelf()?.self.#m?.()).toEqual(undefined); + expect(o?.Foo.#self?.getSelf?.()?.self.#m?.()).toEqual(undefined); + + expect(fn?.().Foo.#m?.()).toEqual(undefined); + expect(fn?.().Foo.#m?.().toString).toEqual(undefined); + expect(fn?.().Foo.#m?.().toString()).toEqual(undefined); + + expect(fnDeep?.().very.o?.Foo.#m?.()).toEqual(undefined); + expect(fnDeep?.().very.o?.Foo.#m?.().toString).toEqual(undefined); + expect(fnDeep?.().very.o?.Foo.#m?.().toString()).toEqual(undefined); + + expect(fn?.().Foo.#self.#m?.()).toEqual(undefined); + expect(fn?.().Foo.#self.self.#m?.()).toEqual(undefined); + expect(fn?.().Foo.#self?.self.#m?.()).toEqual(undefined); + expect(fn?.().Foo.#self.self?.self.#m?.()).toEqual(undefined); + expect(fn?.().Foo.#self?.self?.self.#m?.()).toEqual(undefined); + + expect(fn?.().Foo.#self.getSelf().#m?.()).toEqual(undefined); + expect(fn?.().Foo.#self.getSelf?.().#m?.()).toEqual(undefined); + expect(fn?.().Foo.#self?.getSelf().#m?.()).toEqual(undefined); + expect(fn?.().Foo.#self?.getSelf?.().#m?.()).toEqual(undefined); + expect(fn?.().Foo.#self.getSelf()?.self.#m?.()).toEqual(undefined); + expect(fn?.().Foo.#self.getSelf?.()?.self.#m?.()).toEqual(undefined); + expect(fn?.().Foo.#self?.getSelf()?.self.#m?.()).toEqual(undefined); + expect(fn?.().Foo.#self?.getSelf?.()?.self.#m?.()).toEqual(undefined); + } +} + +Foo.test(); +Foo.testNull(); diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-member-optional-call/input.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-member-optional-call/input.js new file mode 100644 index 000000000000..11dd4a57060d --- /dev/null +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-member-optional-call/input.js @@ -0,0 +1,71 @@ +class Foo { + static #x = 1; + static #m = function() { return this.#x; }; + static #self = Foo; + static self = Foo; + static getSelf() { return this } + + static test() { + const o = { Foo: Foo }; + const deep = { very: { o } }; + function fn() { + return o; + } + function fnDeep() { + return deep; + } + + Foo.#m?.(); + Foo.#m?.().toString; + Foo.#m?.().toString(); + + o?.Foo.#m?.(); + o?.Foo.#m?.().toString; + o?.Foo.#m?.().toString(); + + deep?.very.o?.Foo.#m?.(); + deep?.very.o?.Foo.#m?.().toString; + deep?.very.o?.Foo.#m?.().toString(); + + o?.Foo.#self.#m?.(); + o?.Foo.#self.self.#m?.(); + o?.Foo.#self?.self.#m?.(); + o?.Foo.#self.self?.self.#m?.(); + o?.Foo.#self?.self?.self.#m?.(); + + o?.Foo.#self.getSelf().#m?.(); + o?.Foo.#self.getSelf?.().#m?.(); + o?.Foo.#self?.getSelf().#m?.(); + o?.Foo.#self?.getSelf?.().#m?.(); + o?.Foo.#self.getSelf()?.self.#m?.(); + o?.Foo.#self.getSelf?.()?.self.#m?.(); + o?.Foo.#self?.getSelf()?.self.#m?.(); + o?.Foo.#self?.getSelf?.()?.self.#m?.(); + + fn?.().Foo.#m?.(); + fn?.().Foo.#m?.().toString; + fn?.().Foo.#m?.().toString(); + + fnDeep?.().very.o?.Foo.#m?.(); + fnDeep?.().very.o?.Foo.#m?.().toString; + fnDeep?.().very.o?.Foo.#m?.().toString(); + + fn?.().Foo.#self.#m?.(); + fn?.().Foo.#self.self.#m?.(); + fn?.().Foo.#self?.self.#m?.(); + fn?.().Foo.#self.self?.self.#m?.(); + fn?.().Foo.#self?.self?.self.#m?.(); + + fn?.().Foo.#self.getSelf().#m?.(); + fn?.().Foo.#self.getSelf?.().#m?.(); + fn?.().Foo.#self?.getSelf().#m?.(); + fn?.().Foo.#self?.getSelf?.().#m?.(); + fn?.().Foo.#self.getSelf()?.self.#m?.(); + fn?.().Foo.#self.getSelf?.()?.self.#m?.(); + fn?.().Foo.#self?.getSelf()?.self.#m?.(); + fn?.().Foo.#self?.getSelf?.()?.self.#m?.(); + } + +} + +Foo.test(); diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-member-optional-call/options.json b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-member-optional-call/options.json new file mode 100644 index 000000000000..2d5cfe8e8095 --- /dev/null +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-member-optional-call/options.json @@ -0,0 +1,4 @@ +{ + "plugins": [["proposal-class-properties", { "loose": true }]], + "minNodeVersion": "14.0.0" +} diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-member-optional-call/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-member-optional-call/output.js new file mode 100644 index 000000000000..16be28736749 --- /dev/null +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-member-optional-call/output.js @@ -0,0 +1,98 @@ +function _classPrivateFieldLooseBase(receiver, privateKey) { if (!Object.prototype.hasOwnProperty.call(receiver, privateKey)) { throw new TypeError("attempted to use private field on non-instance"); } return receiver; } + +var id = 0; + +function _classPrivateFieldLooseKey(name) { return "__private_" + id++ + "_" + name; } + +class Foo { + static getSelf() { + return this; + } + + static test() { + var _deep$very$o, _deep$very$o2, _deep$very$o3, _classPrivateFieldLoo, _classPrivateFieldLoo2, _ref, _ref2, _self2, _classPrivateFieldLoo3, _classPrivateFieldLoo4, _ref3, _ref4, _getSelf, _ref5, _ref6, _classPrivateFieldLoo5, _call, _getSelf2, _getSelf3, _fnDeep$very$o, _fnDeep$very$o2, _fnDeep$very$o3, _classPrivateFieldLoo6, _classPrivateFieldLoo7, _ref7, _ref8, _self3, _classPrivateFieldLoo8, _classPrivateFieldLoo9, _ref9, _ref10, _getSelf4, _ref11, _ref12, _classPrivateFieldLoo10, _call2, _getSelf5, _getSelf6; + + const o = { + Foo: Foo + }; + const deep = { + very: { + o + } + }; + + function fn() { + return o; + } + + function fnDeep() { + return deep; + } + + _classPrivateFieldLooseBase(Foo, _m)[_m]?.(); + _classPrivateFieldLooseBase(Foo, _m)[_m]?.().toString; + _classPrivateFieldLooseBase(Foo, _m)[_m]?.().toString(); + o === null || o === void 0 ? void 0 : _classPrivateFieldLooseBase(o.Foo, _m)[_m]?.(); + o === null || o === void 0 ? void 0 : _classPrivateFieldLooseBase(o.Foo, _m)[_m]?.().toString; + o === null || o === void 0 ? void 0 : _classPrivateFieldLooseBase(o.Foo, _m)[_m]?.().toString(); + (_deep$very$o = deep?.very.o) === null || _deep$very$o === void 0 ? void 0 : _classPrivateFieldLooseBase(_deep$very$o.Foo, _m)[_m]?.(); + (_deep$very$o2 = deep?.very.o) === null || _deep$very$o2 === void 0 ? void 0 : _classPrivateFieldLooseBase(_deep$very$o2.Foo, _m)[_m]?.().toString; + (_deep$very$o3 = deep?.very.o) === null || _deep$very$o3 === void 0 ? void 0 : _classPrivateFieldLooseBase(_deep$very$o3.Foo, _m)[_m]?.().toString(); + (o === null || o === void 0 ? void 0 : _classPrivateFieldLooseBase(_classPrivateFieldLoo = _classPrivateFieldLooseBase(o.Foo, _self)[_self], _m)[_m])?.call(_classPrivateFieldLoo); + (o === null || o === void 0 ? void 0 : _classPrivateFieldLooseBase(_classPrivateFieldLoo2 = _classPrivateFieldLooseBase(o.Foo, _self)[_self].self, _m)[_m])?.call(_classPrivateFieldLoo2); + (_ref = o === null || o === void 0 ? void 0 : _classPrivateFieldLooseBase(o.Foo, _self)[_self]) === null || _ref === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref.self, _m)[_m]?.(); + (_ref2 = o === null || o === void 0 ? void 0 : _classPrivateFieldLooseBase(o.Foo, _self)[_self].self) === null || _ref2 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref2.self, _m)[_m]?.(); + (_self2 = (o === null || o === void 0 ? void 0 : _classPrivateFieldLooseBase(o.Foo, _self)[_self])?.self) === null || _self2 === void 0 ? void 0 : _classPrivateFieldLooseBase(_self2.self, _m)[_m]?.(); + (o === null || o === void 0 ? void 0 : _classPrivateFieldLooseBase(_classPrivateFieldLoo3 = _classPrivateFieldLooseBase(o.Foo, _self)[_self].getSelf(), _m)[_m])?.call(_classPrivateFieldLoo3); + (_ref3 = o === null || o === void 0 ? void 0 : (_classPrivateFieldLoo4 = _classPrivateFieldLooseBase(o.Foo, _self)[_self]).getSelf) === null || _ref3 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref3.call(_classPrivateFieldLoo4), _m)[_m]?.(); + (_ref4 = o === null || o === void 0 ? void 0 : _classPrivateFieldLooseBase(o.Foo, _self)[_self]) === null || _ref4 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref4.getSelf(), _m)[_m]?.(); + (_getSelf = (_ref5 = o === null || o === void 0 ? void 0 : _classPrivateFieldLooseBase(o.Foo, _self)[_self])?.getSelf) === null || _getSelf === void 0 ? void 0 : _classPrivateFieldLooseBase(_getSelf.call(_ref5), _m)[_m]?.(); + (_ref6 = o === null || o === void 0 ? void 0 : _classPrivateFieldLooseBase(o.Foo, _self)[_self].getSelf()) === null || _ref6 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref6.self, _m)[_m]?.(); + (_call = (o === null || o === void 0 ? void 0 : (_classPrivateFieldLoo5 = _classPrivateFieldLooseBase(o.Foo, _self)[_self]).getSelf)?.call(_classPrivateFieldLoo5)) === null || _call === void 0 ? void 0 : _classPrivateFieldLooseBase(_call.self, _m)[_m]?.(); + (_getSelf2 = (o === null || o === void 0 ? void 0 : _classPrivateFieldLooseBase(o.Foo, _self)[_self])?.getSelf()) === null || _getSelf2 === void 0 ? void 0 : _classPrivateFieldLooseBase(_getSelf2.self, _m)[_m]?.(); + (_getSelf3 = (o === null || o === void 0 ? void 0 : _classPrivateFieldLooseBase(o.Foo, _self)[_self])?.getSelf?.()) === null || _getSelf3 === void 0 ? void 0 : _classPrivateFieldLooseBase(_getSelf3.self, _m)[_m]?.(); + fn === null || fn === void 0 ? void 0 : _classPrivateFieldLooseBase(fn().Foo, _m)[_m]?.(); + fn === null || fn === void 0 ? void 0 : _classPrivateFieldLooseBase(fn().Foo, _m)[_m]?.().toString; + fn === null || fn === void 0 ? void 0 : _classPrivateFieldLooseBase(fn().Foo, _m)[_m]?.().toString(); + (_fnDeep$very$o = fnDeep?.().very.o) === null || _fnDeep$very$o === void 0 ? void 0 : _classPrivateFieldLooseBase(_fnDeep$very$o.Foo, _m)[_m]?.(); + (_fnDeep$very$o2 = fnDeep?.().very.o) === null || _fnDeep$very$o2 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fnDeep$very$o2.Foo, _m)[_m]?.().toString; + (_fnDeep$very$o3 = fnDeep?.().very.o) === null || _fnDeep$very$o3 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fnDeep$very$o3.Foo, _m)[_m]?.().toString(); + (fn === null || fn === void 0 ? void 0 : _classPrivateFieldLooseBase(_classPrivateFieldLoo6 = _classPrivateFieldLooseBase(fn().Foo, _self)[_self], _m)[_m])?.call(_classPrivateFieldLoo6); + (fn === null || fn === void 0 ? void 0 : _classPrivateFieldLooseBase(_classPrivateFieldLoo7 = _classPrivateFieldLooseBase(fn().Foo, _self)[_self].self, _m)[_m])?.call(_classPrivateFieldLoo7); + (_ref7 = fn === null || fn === void 0 ? void 0 : _classPrivateFieldLooseBase(fn().Foo, _self)[_self]) === null || _ref7 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref7.self, _m)[_m]?.(); + (_ref8 = fn === null || fn === void 0 ? void 0 : _classPrivateFieldLooseBase(fn().Foo, _self)[_self].self) === null || _ref8 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref8.self, _m)[_m]?.(); + (_self3 = (fn === null || fn === void 0 ? void 0 : _classPrivateFieldLooseBase(fn().Foo, _self)[_self])?.self) === null || _self3 === void 0 ? void 0 : _classPrivateFieldLooseBase(_self3.self, _m)[_m]?.(); + (fn === null || fn === void 0 ? void 0 : _classPrivateFieldLooseBase(_classPrivateFieldLoo8 = _classPrivateFieldLooseBase(fn().Foo, _self)[_self].getSelf(), _m)[_m])?.call(_classPrivateFieldLoo8); + (_ref9 = fn === null || fn === void 0 ? void 0 : (_classPrivateFieldLoo9 = _classPrivateFieldLooseBase(fn().Foo, _self)[_self]).getSelf) === null || _ref9 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref9.call(_classPrivateFieldLoo9), _m)[_m]?.(); + (_ref10 = fn === null || fn === void 0 ? void 0 : _classPrivateFieldLooseBase(fn().Foo, _self)[_self]) === null || _ref10 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref10.getSelf(), _m)[_m]?.(); + (_getSelf4 = (_ref11 = fn === null || fn === void 0 ? void 0 : _classPrivateFieldLooseBase(fn().Foo, _self)[_self])?.getSelf) === null || _getSelf4 === void 0 ? void 0 : _classPrivateFieldLooseBase(_getSelf4.call(_ref11), _m)[_m]?.(); + (_ref12 = fn === null || fn === void 0 ? void 0 : _classPrivateFieldLooseBase(fn().Foo, _self)[_self].getSelf()) === null || _ref12 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref12.self, _m)[_m]?.(); + (_call2 = (fn === null || fn === void 0 ? void 0 : (_classPrivateFieldLoo10 = _classPrivateFieldLooseBase(fn().Foo, _self)[_self]).getSelf)?.call(_classPrivateFieldLoo10)) === null || _call2 === void 0 ? void 0 : _classPrivateFieldLooseBase(_call2.self, _m)[_m]?.(); + (_getSelf5 = (fn === null || fn === void 0 ? void 0 : _classPrivateFieldLooseBase(fn().Foo, _self)[_self])?.getSelf()) === null || _getSelf5 === void 0 ? void 0 : _classPrivateFieldLooseBase(_getSelf5.self, _m)[_m]?.(); + (_getSelf6 = (fn === null || fn === void 0 ? void 0 : _classPrivateFieldLooseBase(fn().Foo, _self)[_self])?.getSelf?.()) === null || _getSelf6 === void 0 ? void 0 : _classPrivateFieldLooseBase(_getSelf6.self, _m)[_m]?.(); + } + +} + +var _x = _classPrivateFieldLooseKey("x"); + +var _m = _classPrivateFieldLooseKey("m"); + +var _self = _classPrivateFieldLooseKey("self"); + +Object.defineProperty(Foo, _x, { + writable: true, + value: 1 +}); +Object.defineProperty(Foo, _m, { + writable: true, + value: function () { + return _classPrivateFieldLooseBase(this, _x)[_x]; + } +}); +Object.defineProperty(Foo, _self, { + writable: true, + value: Foo +}); +Foo.self = Foo; +Foo.test(); diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-optional-member-call-with-transform/exec.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-optional-member-call-with-transform/exec.js new file mode 100644 index 000000000000..df4319aff69b --- /dev/null +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-optional-member-call-with-transform/exec.js @@ -0,0 +1,126 @@ +class Foo { + static #x = 1; + static #m = function() { return this.#x; }; + static #self = Foo; + static self = Foo; + static getSelf() { return this } + + static test() { + 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(o?.Foo?.#m()).toEqual(1); + expect(o?.Foo?.#m().toString).toEqual(1..toString); + expect(o?.Foo?.#m().toString()).toEqual('1'); + + expect(deep?.very.o?.Foo?.#m()).toEqual(1); + expect(deep?.very.o?.Foo?.#m().toString).toEqual(1..toString); + expect(deep?.very.o?.Foo?.#m().toString()).toEqual('1'); + + expect(o?.Foo.#self?.#m()).toEqual(1); + expect(o?.Foo.#self.self?.#m()).toEqual(1); + expect(o?.Foo.#self?.self?.#m()).toEqual(1); + expect(o?.Foo.#self.self?.self?.#m()).toEqual(1); + expect(o?.Foo.#self?.self?.self?.#m()).toEqual(1); + + expect(o?.Foo.#self.getSelf()?.#m()).toEqual(1); + expect(o?.Foo.#self.getSelf?.()?.#m()).toEqual(1); + expect(o?.Foo.#self?.getSelf()?.#m()).toEqual(1); + expect(o?.Foo.#self?.getSelf?.()?.#m()).toEqual(1); + expect(o?.Foo.#self.getSelf()?.self?.#m()).toEqual(1); + expect(o?.Foo.#self.getSelf?.()?.self?.#m()).toEqual(1); + expect(o?.Foo.#self?.getSelf()?.self?.#m()).toEqual(1); + expect(o?.Foo.#self?.getSelf?.()?.self?.#m()).toEqual(1); + + expect(fn?.().Foo?.#m()).toEqual(1); + expect(fn?.().Foo?.#m().toString).toEqual(1..toString); + expect(fn?.().Foo?.#m().toString()).toEqual('1'); + + expect(fnDeep?.().very.o?.Foo?.#m()).toEqual(1); + expect(fnDeep?.().very.o?.Foo?.#m().toString).toEqual(1..toString); + expect(fnDeep?.().very.o?.Foo?.#m().toString()).toEqual('1'); + + expect(fn?.().Foo.#self?.#m()).toEqual(1); + expect(fn?.().Foo.#self.self?.#m()).toEqual(1); + expect(fn?.().Foo.#self?.self?.#m()).toEqual(1); + expect(fn?.().Foo.#self.self?.self?.#m()).toEqual(1); + expect(fn?.().Foo.#self?.self?.self?.#m()).toEqual(1); + + expect(fn?.().Foo.#self.getSelf()?.#m()).toEqual(1); + expect(fn?.().Foo.#self.getSelf?.()?.#m()).toEqual(1); + expect(fn?.().Foo.#self?.getSelf()?.#m()).toEqual(1); + expect(fn?.().Foo.#self?.getSelf?.()?.#m()).toEqual(1); + expect(fn?.().Foo.#self.getSelf()?.self?.#m()).toEqual(1); + expect(fn?.().Foo.#self.getSelf?.()?.self?.#m()).toEqual(1); + expect(fn?.().Foo.#self?.getSelf()?.self?.#m()).toEqual(1); + expect(fn?.().Foo.#self?.getSelf?.()?.self?.#m()).toEqual(1); + } + + static testNull() { + const o = null;; + const deep = { very: { o } }; + const fn = null; + function fnDeep() { + return deep; + } + + expect(o?.Foo?.#m()).toEqual(undefined); + expect(o?.Foo?.#m().toString).toEqual(undefined); + expect(o?.Foo?.#m().toString()).toEqual(undefined); + + expect(deep?.very.o?.Foo?.#m()).toEqual(undefined); + expect(deep?.very.o?.Foo?.#m().toString).toEqual(undefined); + expect(deep?.very.o?.Foo?.#m().toString()).toEqual(undefined); + + expect(o?.Foo.#self?.#m()).toEqual(undefined); + expect(o?.Foo.#self.self?.#m()).toEqual(undefined); + expect(o?.Foo.#self?.self?.#m()).toEqual(undefined); + expect(o?.Foo.#self.self?.self?.#m()).toEqual(undefined); + expect(o?.Foo.#self?.self?.self?.#m()).toEqual(undefined); + + expect(o?.Foo.#self.getSelf()?.#m()).toEqual(undefined); + expect(o?.Foo.#self.getSelf?.()?.#m()).toEqual(undefined); + expect(o?.Foo.#self?.getSelf()?.#m()).toEqual(undefined); + expect(o?.Foo.#self?.getSelf?.()?.#m()).toEqual(undefined); + expect(o?.Foo.#self.getSelf()?.self?.#m()).toEqual(undefined); + expect(o?.Foo.#self.getSelf?.()?.self?.#m()).toEqual(undefined); + expect(o?.Foo.#self?.getSelf()?.self?.#m()).toEqual(undefined); + expect(o?.Foo.#self?.getSelf?.()?.self?.#m()).toEqual(undefined); + + expect(fn?.().Foo?.#m()).toEqual(undefined); + expect(fn?.().Foo?.#m().toString).toEqual(undefined); + expect(fn?.().Foo?.#m().toString()).toEqual(undefined); + + expect(fnDeep?.().very.o?.Foo?.#m()).toEqual(undefined); + expect(fnDeep?.().very.o?.Foo?.#m().toString).toEqual(undefined); + expect(fnDeep?.().very.o?.Foo?.#m().toString()).toEqual(undefined); + + expect(fn?.().Foo.#self?.#m()).toEqual(undefined); + expect(fn?.().Foo.#self.self?.#m()).toEqual(undefined); + expect(fn?.().Foo.#self?.self?.#m()).toEqual(undefined); + expect(fn?.().Foo.#self.self?.self?.#m()).toEqual(undefined); + expect(fn?.().Foo.#self?.self?.self?.#m()).toEqual(undefined); + + expect(fn?.().Foo.#self.getSelf()?.#m()).toEqual(undefined); + expect(fn?.().Foo.#self.getSelf?.()?.#m()).toEqual(undefined); + expect(fn?.().Foo.#self?.getSelf()?.#m()).toEqual(undefined); + expect(fn?.().Foo.#self?.getSelf?.()?.#m()).toEqual(undefined); + expect(fn?.().Foo.#self.getSelf()?.self?.#m()).toEqual(undefined); + expect(fn?.().Foo.#self.getSelf?.()?.self?.#m()).toEqual(undefined); + expect(fn?.().Foo.#self?.getSelf()?.self?.#m()).toEqual(undefined); + expect(fn?.().Foo.#self?.getSelf?.()?.self?.#m()).toEqual(undefined); + } +} + +Foo.test(); +Foo.testNull(); diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-optional-member-call-with-transform/input.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-optional-member-call-with-transform/input.js new file mode 100644 index 000000000000..80f689342109 --- /dev/null +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-optional-member-call-with-transform/input.js @@ -0,0 +1,70 @@ +class Foo { + static #x = 1; + static #m = function() { return this.#x; }; + static #self = Foo; + static self = Foo; + static getSelf() { return this } + + static test() { + const o = { Foo: Foo }; + const deep = { very: { o } }; + function fn() { + return o; + } + function fnDeep() { + return deep; + } + + Foo?.#m(); + Foo?.#m().toString; + Foo?.#m().toString(); + + o?.Foo?.#m(); + o?.Foo?.#m().toString; + o?.Foo?.#m().toString(); + + deep?.very.o?.Foo?.#m(); + deep?.very.o?.Foo?.#m().toString; + deep?.very.o?.Foo?.#m().toString(); + + o?.Foo.#self?.#m(); + o?.Foo.#self.self?.#m(); + o?.Foo.#self?.self?.#m(); + o?.Foo.#self.self?.self?.#m(); + o?.Foo.#self?.self?.self?.#m(); + + o?.Foo.#self.getSelf()?.#m(); + o?.Foo.#self.getSelf?.()?.#m(); + o?.Foo.#self?.getSelf()?.#m(); + o?.Foo.#self?.getSelf?.()?.#m(); + o?.Foo.#self.getSelf()?.self?.#m(); + o?.Foo.#self.getSelf?.()?.self?.#m(); + o?.Foo.#self?.getSelf()?.self?.#m(); + o?.Foo.#self?.getSelf?.()?.self?.#m(); + + fn?.().Foo?.#m(); + fn?.().Foo?.#m().toString; + fn?.().Foo?.#m().toString(); + + fnDeep?.().very.o?.Foo?.#m(); + fnDeep?.().very.o?.Foo?.#m().toString; + fnDeep?.().very.o?.Foo?.#m().toString(); + + fn?.().Foo.#self?.#m(); + fn?.().Foo.#self.self?.#m(); + fn?.().Foo.#self?.self?.#m(); + fn?.().Foo.#self.self?.self?.#m(); + fn?.().Foo.#self?.self?.self?.#m(); + + fn?.().Foo.#self.getSelf()?.#m(); + fn?.().Foo.#self.getSelf?.()?.#m(); + fn?.().Foo.#self?.getSelf()?.#m(); + fn?.().Foo.#self?.getSelf?.()?.#m(); + fn?.().Foo.#self.getSelf()?.self?.#m(); + fn?.().Foo.#self.getSelf?.()?.self?.#m(); + fn?.().Foo.#self?.getSelf()?.self?.#m(); + fn?.().Foo.#self?.getSelf?.()?.self?.#m(); + } +} + +Foo.test(); diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-with-transform/options.json b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-optional-member-call-with-transform/options.json similarity index 58% rename from packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-with-transform/options.json rename to packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-optional-member-call-with-transform/options.json index 9a7eaaa890b3..124133b5af2b 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-with-transform/options.json +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-optional-member-call-with-transform/options.json @@ -1,6 +1,6 @@ { "plugins": [ - "proposal-optional-chaining", + ["proposal-optional-chaining", { "loose": true }], ["proposal-class-properties", { "loose": true }] ] } diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-optional-member-call-with-transform/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-optional-member-call-with-transform/output.js new file mode 100644 index 000000000000..b4f91f63bf6c --- /dev/null +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-optional-member-call-with-transform/output.js @@ -0,0 +1,98 @@ +function _classPrivateFieldLooseBase(receiver, privateKey) { if (!Object.prototype.hasOwnProperty.call(receiver, privateKey)) { throw new TypeError("attempted to use private field on non-instance"); } return receiver; } + +var id = 0; + +function _classPrivateFieldLooseKey(name) { return "__private_" + id++ + "_" + name; } + +class Foo { + static getSelf() { + return this; + } + + static test() { + var _o$Foo, _o$Foo2, _o$Foo3, _deep$very$o$Foo, _deep$very$o$Foo2, _deep$very$o$Foo3, _ref, _ref2, _self2, _self3, _self$self, _ref3, _classPrivateFieldLoo, _call, _getSelf, _getSelf2, _self4, _classPrivateFieldLoo2, _call$self, _getSelf$self, _getSelf$self2, _fn$Foo, _fn$Foo2, _fn$Foo3, _fnDeep$very$o$Foo, _fnDeep$very$o$Foo2, _fnDeep$very$o$Foo3, _ref4, _ref5, _self5, _self6, _self$self2, _ref6, _classPrivateFieldLoo3, _call2, _getSelf3, _getSelf4, _self7, _classPrivateFieldLoo4, _call$self2, _getSelf$self3, _getSelf$self4, _deep$very$o, _deep$very$o2, _deep$very$o3, _ref7, _ref8, _ref9, _ref9$self, _ref10, _ref11, _ref12, _ref13, _ref14, _ref14$call, _ref15, _ref15$getSelf, _ref16, _ref16$getSelf, _fnDeep$very$o, _fnDeep$very$o2, _fnDeep$very$o3, _ref17, _ref18, _ref19, _ref19$self, _ref20, _ref21, _ref22, _ref23, _ref24, _ref24$call, _ref25, _ref25$getSelf, _ref26, _ref26$getSelf; + + const o = { + Foo: Foo + }; + const deep = { + very: { + o + } + }; + + function fn() { + return o; + } + + function fnDeep() { + return deep; + } + + Foo === null || Foo === void 0 ? void 0 : _classPrivateFieldLooseBase(Foo, _m)[_m](); + Foo === null || Foo === void 0 ? void 0 : _classPrivateFieldLooseBase(Foo, _m)[_m]().toString; + Foo === null || Foo === void 0 ? void 0 : _classPrivateFieldLooseBase(Foo, _m)[_m]().toString(); + (_o$Foo = o == null ? void 0 : o.Foo) === null || _o$Foo === void 0 ? void 0 : _classPrivateFieldLooseBase(_o$Foo, _m)[_m](); + (_o$Foo2 = o == null ? void 0 : o.Foo) === null || _o$Foo2 === void 0 ? void 0 : _classPrivateFieldLooseBase(_o$Foo2, _m)[_m]().toString; + (_o$Foo3 = o == null ? void 0 : o.Foo) === null || _o$Foo3 === void 0 ? void 0 : _classPrivateFieldLooseBase(_o$Foo3, _m)[_m]().toString(); + (_deep$very$o$Foo = deep == null ? void 0 : (_deep$very$o = deep.very.o) == null ? void 0 : _deep$very$o.Foo) === null || _deep$very$o$Foo === void 0 ? void 0 : _classPrivateFieldLooseBase(_deep$very$o$Foo, _m)[_m](); + (_deep$very$o$Foo2 = deep == null ? void 0 : (_deep$very$o2 = deep.very.o) == null ? void 0 : _deep$very$o2.Foo) === null || _deep$very$o$Foo2 === void 0 ? void 0 : _classPrivateFieldLooseBase(_deep$very$o$Foo2, _m)[_m]().toString; + (_deep$very$o$Foo3 = deep == null ? void 0 : (_deep$very$o3 = deep.very.o) == null ? void 0 : _deep$very$o3.Foo) === null || _deep$very$o$Foo3 === void 0 ? void 0 : _classPrivateFieldLooseBase(_deep$very$o$Foo3, _m)[_m]().toString(); + (_ref = o === null || o === void 0 ? void 0 : _classPrivateFieldLooseBase(o.Foo, _self)[_self]) === null || _ref === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref, _m)[_m](); + (_ref2 = o === null || o === void 0 ? void 0 : _classPrivateFieldLooseBase(o.Foo, _self)[_self].self) === null || _ref2 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref2, _m)[_m](); + (_self2 = (_ref7 = o === null || o === void 0 ? void 0 : _classPrivateFieldLooseBase(o.Foo, _self)[_self]) == null ? void 0 : _ref7.self) === null || _self2 === void 0 ? void 0 : _classPrivateFieldLooseBase(_self2, _m)[_m](); + (_self3 = (_ref8 = o === null || o === void 0 ? void 0 : _classPrivateFieldLooseBase(o.Foo, _self)[_self].self) == null ? void 0 : _ref8.self) === null || _self3 === void 0 ? void 0 : _classPrivateFieldLooseBase(_self3, _m)[_m](); + (_self$self = (_ref9 = o === null || o === void 0 ? void 0 : _classPrivateFieldLooseBase(o.Foo, _self)[_self]) == null ? void 0 : (_ref9$self = _ref9.self) == null ? void 0 : _ref9$self.self) === null || _self$self === void 0 ? void 0 : _classPrivateFieldLooseBase(_self$self, _m)[_m](); + (_ref3 = o === null || o === void 0 ? void 0 : _classPrivateFieldLooseBase(o.Foo, _self)[_self].getSelf()) === null || _ref3 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref3, _m)[_m](); + (_call = (_ref10 = o === null || o === void 0 ? void 0 : (_classPrivateFieldLoo = _classPrivateFieldLooseBase(o.Foo, _self)[_self]).getSelf) == null ? void 0 : _ref10.call(_classPrivateFieldLoo)) === null || _call === void 0 ? void 0 : _classPrivateFieldLooseBase(_call, _m)[_m](); + (_getSelf = (_ref11 = o === null || o === void 0 ? void 0 : _classPrivateFieldLooseBase(o.Foo, _self)[_self]) == null ? void 0 : _ref11.getSelf()) === null || _getSelf === void 0 ? void 0 : _classPrivateFieldLooseBase(_getSelf, _m)[_m](); + (_getSelf2 = (_ref12 = o === null || o === void 0 ? void 0 : _classPrivateFieldLooseBase(o.Foo, _self)[_self]) == null ? void 0 : _ref12.getSelf == null ? void 0 : _ref12.getSelf()) === null || _getSelf2 === void 0 ? void 0 : _classPrivateFieldLooseBase(_getSelf2, _m)[_m](); + (_self4 = (_ref13 = o === null || o === void 0 ? void 0 : _classPrivateFieldLooseBase(o.Foo, _self)[_self].getSelf()) == null ? void 0 : _ref13.self) === null || _self4 === void 0 ? void 0 : _classPrivateFieldLooseBase(_self4, _m)[_m](); + (_call$self = (_ref14 = o === null || o === void 0 ? void 0 : (_classPrivateFieldLoo2 = _classPrivateFieldLooseBase(o.Foo, _self)[_self]).getSelf) == null ? void 0 : (_ref14$call = _ref14.call(_classPrivateFieldLoo2)) == null ? void 0 : _ref14$call.self) === null || _call$self === void 0 ? void 0 : _classPrivateFieldLooseBase(_call$self, _m)[_m](); + (_getSelf$self = (_ref15 = o === null || o === void 0 ? void 0 : _classPrivateFieldLooseBase(o.Foo, _self)[_self]) == null ? void 0 : (_ref15$getSelf = _ref15.getSelf()) == null ? void 0 : _ref15$getSelf.self) === null || _getSelf$self === void 0 ? void 0 : _classPrivateFieldLooseBase(_getSelf$self, _m)[_m](); + (_getSelf$self2 = (_ref16 = o === null || o === void 0 ? void 0 : _classPrivateFieldLooseBase(o.Foo, _self)[_self]) == null ? void 0 : _ref16.getSelf == null ? void 0 : (_ref16$getSelf = _ref16.getSelf()) == null ? void 0 : _ref16$getSelf.self) === null || _getSelf$self2 === void 0 ? void 0 : _classPrivateFieldLooseBase(_getSelf$self2, _m)[_m](); + (_fn$Foo = fn == null ? void 0 : fn().Foo) === null || _fn$Foo === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn$Foo, _m)[_m](); + (_fn$Foo2 = fn == null ? void 0 : fn().Foo) === null || _fn$Foo2 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn$Foo2, _m)[_m]().toString; + (_fn$Foo3 = fn == null ? void 0 : fn().Foo) === null || _fn$Foo3 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn$Foo3, _m)[_m]().toString(); + (_fnDeep$very$o$Foo = fnDeep == null ? void 0 : (_fnDeep$very$o = fnDeep().very.o) == null ? void 0 : _fnDeep$very$o.Foo) === null || _fnDeep$very$o$Foo === void 0 ? void 0 : _classPrivateFieldLooseBase(_fnDeep$very$o$Foo, _m)[_m](); + (_fnDeep$very$o$Foo2 = fnDeep == null ? void 0 : (_fnDeep$very$o2 = fnDeep().very.o) == null ? void 0 : _fnDeep$very$o2.Foo) === null || _fnDeep$very$o$Foo2 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fnDeep$very$o$Foo2, _m)[_m]().toString; + (_fnDeep$very$o$Foo3 = fnDeep == null ? void 0 : (_fnDeep$very$o3 = fnDeep().very.o) == null ? void 0 : _fnDeep$very$o3.Foo) === null || _fnDeep$very$o$Foo3 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fnDeep$very$o$Foo3, _m)[_m]().toString(); + (_ref4 = fn === null || fn === void 0 ? void 0 : _classPrivateFieldLooseBase(fn().Foo, _self)[_self]) === null || _ref4 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref4, _m)[_m](); + (_ref5 = fn === null || fn === void 0 ? void 0 : _classPrivateFieldLooseBase(fn().Foo, _self)[_self].self) === null || _ref5 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref5, _m)[_m](); + (_self5 = (_ref17 = fn === null || fn === void 0 ? void 0 : _classPrivateFieldLooseBase(fn().Foo, _self)[_self]) == null ? void 0 : _ref17.self) === null || _self5 === void 0 ? void 0 : _classPrivateFieldLooseBase(_self5, _m)[_m](); + (_self6 = (_ref18 = fn === null || fn === void 0 ? void 0 : _classPrivateFieldLooseBase(fn().Foo, _self)[_self].self) == null ? void 0 : _ref18.self) === null || _self6 === void 0 ? void 0 : _classPrivateFieldLooseBase(_self6, _m)[_m](); + (_self$self2 = (_ref19 = fn === null || fn === void 0 ? void 0 : _classPrivateFieldLooseBase(fn().Foo, _self)[_self]) == null ? void 0 : (_ref19$self = _ref19.self) == null ? void 0 : _ref19$self.self) === null || _self$self2 === void 0 ? void 0 : _classPrivateFieldLooseBase(_self$self2, _m)[_m](); + (_ref6 = fn === null || fn === void 0 ? void 0 : _classPrivateFieldLooseBase(fn().Foo, _self)[_self].getSelf()) === null || _ref6 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref6, _m)[_m](); + (_call2 = (_ref20 = fn === null || fn === void 0 ? void 0 : (_classPrivateFieldLoo3 = _classPrivateFieldLooseBase(fn().Foo, _self)[_self]).getSelf) == null ? void 0 : _ref20.call(_classPrivateFieldLoo3)) === null || _call2 === void 0 ? void 0 : _classPrivateFieldLooseBase(_call2, _m)[_m](); + (_getSelf3 = (_ref21 = fn === null || fn === void 0 ? void 0 : _classPrivateFieldLooseBase(fn().Foo, _self)[_self]) == null ? void 0 : _ref21.getSelf()) === null || _getSelf3 === void 0 ? void 0 : _classPrivateFieldLooseBase(_getSelf3, _m)[_m](); + (_getSelf4 = (_ref22 = fn === null || fn === void 0 ? void 0 : _classPrivateFieldLooseBase(fn().Foo, _self)[_self]) == null ? void 0 : _ref22.getSelf == null ? void 0 : _ref22.getSelf()) === null || _getSelf4 === void 0 ? void 0 : _classPrivateFieldLooseBase(_getSelf4, _m)[_m](); + (_self7 = (_ref23 = fn === null || fn === void 0 ? void 0 : _classPrivateFieldLooseBase(fn().Foo, _self)[_self].getSelf()) == null ? void 0 : _ref23.self) === null || _self7 === void 0 ? void 0 : _classPrivateFieldLooseBase(_self7, _m)[_m](); + (_call$self2 = (_ref24 = fn === null || fn === void 0 ? void 0 : (_classPrivateFieldLoo4 = _classPrivateFieldLooseBase(fn().Foo, _self)[_self]).getSelf) == null ? void 0 : (_ref24$call = _ref24.call(_classPrivateFieldLoo4)) == null ? void 0 : _ref24$call.self) === null || _call$self2 === void 0 ? void 0 : _classPrivateFieldLooseBase(_call$self2, _m)[_m](); + (_getSelf$self3 = (_ref25 = fn === null || fn === void 0 ? void 0 : _classPrivateFieldLooseBase(fn().Foo, _self)[_self]) == null ? void 0 : (_ref25$getSelf = _ref25.getSelf()) == null ? void 0 : _ref25$getSelf.self) === null || _getSelf$self3 === void 0 ? void 0 : _classPrivateFieldLooseBase(_getSelf$self3, _m)[_m](); + (_getSelf$self4 = (_ref26 = fn === null || fn === void 0 ? void 0 : _classPrivateFieldLooseBase(fn().Foo, _self)[_self]) == null ? void 0 : _ref26.getSelf == null ? void 0 : (_ref26$getSelf = _ref26.getSelf()) == null ? void 0 : _ref26$getSelf.self) === null || _getSelf$self4 === void 0 ? void 0 : _classPrivateFieldLooseBase(_getSelf$self4, _m)[_m](); + } + +} + +var _x = _classPrivateFieldLooseKey("x"); + +var _m = _classPrivateFieldLooseKey("m"); + +var _self = _classPrivateFieldLooseKey("self"); + +Object.defineProperty(Foo, _x, { + writable: true, + value: 1 +}); +Object.defineProperty(Foo, _m, { + writable: true, + value: function () { + return _classPrivateFieldLooseBase(this, _x)[_x]; + } +}); +Object.defineProperty(Foo, _self, { + writable: true, + value: Foo +}); +Foo.self = Foo; +Foo.test(); diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-optional-member-call/exec.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-optional-member-call/exec.js new file mode 100644 index 000000000000..df4319aff69b --- /dev/null +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-optional-member-call/exec.js @@ -0,0 +1,126 @@ +class Foo { + static #x = 1; + static #m = function() { return this.#x; }; + static #self = Foo; + static self = Foo; + static getSelf() { return this } + + static test() { + 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(o?.Foo?.#m()).toEqual(1); + expect(o?.Foo?.#m().toString).toEqual(1..toString); + expect(o?.Foo?.#m().toString()).toEqual('1'); + + expect(deep?.very.o?.Foo?.#m()).toEqual(1); + expect(deep?.very.o?.Foo?.#m().toString).toEqual(1..toString); + expect(deep?.very.o?.Foo?.#m().toString()).toEqual('1'); + + expect(o?.Foo.#self?.#m()).toEqual(1); + expect(o?.Foo.#self.self?.#m()).toEqual(1); + expect(o?.Foo.#self?.self?.#m()).toEqual(1); + expect(o?.Foo.#self.self?.self?.#m()).toEqual(1); + expect(o?.Foo.#self?.self?.self?.#m()).toEqual(1); + + expect(o?.Foo.#self.getSelf()?.#m()).toEqual(1); + expect(o?.Foo.#self.getSelf?.()?.#m()).toEqual(1); + expect(o?.Foo.#self?.getSelf()?.#m()).toEqual(1); + expect(o?.Foo.#self?.getSelf?.()?.#m()).toEqual(1); + expect(o?.Foo.#self.getSelf()?.self?.#m()).toEqual(1); + expect(o?.Foo.#self.getSelf?.()?.self?.#m()).toEqual(1); + expect(o?.Foo.#self?.getSelf()?.self?.#m()).toEqual(1); + expect(o?.Foo.#self?.getSelf?.()?.self?.#m()).toEqual(1); + + expect(fn?.().Foo?.#m()).toEqual(1); + expect(fn?.().Foo?.#m().toString).toEqual(1..toString); + expect(fn?.().Foo?.#m().toString()).toEqual('1'); + + expect(fnDeep?.().very.o?.Foo?.#m()).toEqual(1); + expect(fnDeep?.().very.o?.Foo?.#m().toString).toEqual(1..toString); + expect(fnDeep?.().very.o?.Foo?.#m().toString()).toEqual('1'); + + expect(fn?.().Foo.#self?.#m()).toEqual(1); + expect(fn?.().Foo.#self.self?.#m()).toEqual(1); + expect(fn?.().Foo.#self?.self?.#m()).toEqual(1); + expect(fn?.().Foo.#self.self?.self?.#m()).toEqual(1); + expect(fn?.().Foo.#self?.self?.self?.#m()).toEqual(1); + + expect(fn?.().Foo.#self.getSelf()?.#m()).toEqual(1); + expect(fn?.().Foo.#self.getSelf?.()?.#m()).toEqual(1); + expect(fn?.().Foo.#self?.getSelf()?.#m()).toEqual(1); + expect(fn?.().Foo.#self?.getSelf?.()?.#m()).toEqual(1); + expect(fn?.().Foo.#self.getSelf()?.self?.#m()).toEqual(1); + expect(fn?.().Foo.#self.getSelf?.()?.self?.#m()).toEqual(1); + expect(fn?.().Foo.#self?.getSelf()?.self?.#m()).toEqual(1); + expect(fn?.().Foo.#self?.getSelf?.()?.self?.#m()).toEqual(1); + } + + static testNull() { + const o = null;; + const deep = { very: { o } }; + const fn = null; + function fnDeep() { + return deep; + } + + expect(o?.Foo?.#m()).toEqual(undefined); + expect(o?.Foo?.#m().toString).toEqual(undefined); + expect(o?.Foo?.#m().toString()).toEqual(undefined); + + expect(deep?.very.o?.Foo?.#m()).toEqual(undefined); + expect(deep?.very.o?.Foo?.#m().toString).toEqual(undefined); + expect(deep?.very.o?.Foo?.#m().toString()).toEqual(undefined); + + expect(o?.Foo.#self?.#m()).toEqual(undefined); + expect(o?.Foo.#self.self?.#m()).toEqual(undefined); + expect(o?.Foo.#self?.self?.#m()).toEqual(undefined); + expect(o?.Foo.#self.self?.self?.#m()).toEqual(undefined); + expect(o?.Foo.#self?.self?.self?.#m()).toEqual(undefined); + + expect(o?.Foo.#self.getSelf()?.#m()).toEqual(undefined); + expect(o?.Foo.#self.getSelf?.()?.#m()).toEqual(undefined); + expect(o?.Foo.#self?.getSelf()?.#m()).toEqual(undefined); + expect(o?.Foo.#self?.getSelf?.()?.#m()).toEqual(undefined); + expect(o?.Foo.#self.getSelf()?.self?.#m()).toEqual(undefined); + expect(o?.Foo.#self.getSelf?.()?.self?.#m()).toEqual(undefined); + expect(o?.Foo.#self?.getSelf()?.self?.#m()).toEqual(undefined); + expect(o?.Foo.#self?.getSelf?.()?.self?.#m()).toEqual(undefined); + + expect(fn?.().Foo?.#m()).toEqual(undefined); + expect(fn?.().Foo?.#m().toString).toEqual(undefined); + expect(fn?.().Foo?.#m().toString()).toEqual(undefined); + + expect(fnDeep?.().very.o?.Foo?.#m()).toEqual(undefined); + expect(fnDeep?.().very.o?.Foo?.#m().toString).toEqual(undefined); + expect(fnDeep?.().very.o?.Foo?.#m().toString()).toEqual(undefined); + + expect(fn?.().Foo.#self?.#m()).toEqual(undefined); + expect(fn?.().Foo.#self.self?.#m()).toEqual(undefined); + expect(fn?.().Foo.#self?.self?.#m()).toEqual(undefined); + expect(fn?.().Foo.#self.self?.self?.#m()).toEqual(undefined); + expect(fn?.().Foo.#self?.self?.self?.#m()).toEqual(undefined); + + expect(fn?.().Foo.#self.getSelf()?.#m()).toEqual(undefined); + expect(fn?.().Foo.#self.getSelf?.()?.#m()).toEqual(undefined); + expect(fn?.().Foo.#self?.getSelf()?.#m()).toEqual(undefined); + expect(fn?.().Foo.#self?.getSelf?.()?.#m()).toEqual(undefined); + expect(fn?.().Foo.#self.getSelf()?.self?.#m()).toEqual(undefined); + expect(fn?.().Foo.#self.getSelf?.()?.self?.#m()).toEqual(undefined); + expect(fn?.().Foo.#self?.getSelf()?.self?.#m()).toEqual(undefined); + expect(fn?.().Foo.#self?.getSelf?.()?.self?.#m()).toEqual(undefined); + } +} + +Foo.test(); +Foo.testNull(); diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-optional-member-call/input.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-optional-member-call/input.js new file mode 100644 index 000000000000..a5c222687ee8 --- /dev/null +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-optional-member-call/input.js @@ -0,0 +1,70 @@ +class Foo { + static #x = 1; + static #m = function() { return this.#x; }; + static #self = Foo; + static self = Foo; + static getSelf() { return this } + + static test() { + const o = { Foo: Foo }; + const deep = { very: { o } }; + function fn() { + return o; + } + function fnDeep() { + return deep; + } + + Foo?.#m(); + Foo?.#m().toString; + Foo?.#m().toString(); + + o?.Foo.#m(); + o?.Foo.#m().toString; + o?.Foo.#m().toString(); + + deep?.very.o?.Foo.#m(); + deep?.very.o?.Foo.#m().toString; + deep?.very.o?.Foo.#m().toString(); + + o?.Foo.#self.#m(); + o?.Foo.#self.self.#m(); + o?.Foo.#self?.self.#m(); + o?.Foo.#self.self?.self.#m(); + o?.Foo.#self?.self?.self.#m(); + + o?.Foo.#self.getSelf().#m(); + o?.Foo.#self.getSelf?.().#m(); + o?.Foo.#self?.getSelf().#m(); + o?.Foo.#self?.getSelf?.().#m(); + o?.Foo.#self.getSelf()?.self.#m(); + o?.Foo.#self.getSelf?.()?.self.#m(); + o?.Foo.#self?.getSelf()?.self.#m(); + o?.Foo.#self?.getSelf?.()?.self.#m(); + + fn?.().Foo.#m(); + fn?.().Foo.#m().toString; + fn?.().Foo.#m().toString(); + + fnDeep?.().very.o?.Foo.#m(); + fnDeep?.().very.o?.Foo.#m().toString; + fnDeep?.().very.o?.Foo.#m().toString(); + + fn?.().Foo.#self.#m(); + fn?.().Foo.#self.self.#m(); + fn?.().Foo.#self?.self.#m(); + fn?.().Foo.#self.self?.self.#m(); + fn?.().Foo.#self?.self?.self.#m(); + + fn?.().Foo.#self.getSelf().#m(); + fn?.().Foo.#self.getSelf?.().#m(); + fn?.().Foo.#self?.getSelf().#m(); + fn?.().Foo.#self?.getSelf?.().#m(); + fn?.().Foo.#self.getSelf()?.self.#m(); + fn?.().Foo.#self.getSelf?.()?.self.#m(); + fn?.().Foo.#self?.getSelf()?.self.#m(); + fn?.().Foo.#self?.getSelf?.()?.self.#m(); + } +} + +Foo.test(); diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-optional-member-call/options.json b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-optional-member-call/options.json new file mode 100644 index 000000000000..2d5cfe8e8095 --- /dev/null +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-optional-member-call/options.json @@ -0,0 +1,4 @@ +{ + "plugins": [["proposal-class-properties", { "loose": true }]], + "minNodeVersion": "14.0.0" +} diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-optional-member-call/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-optional-member-call/output.js new file mode 100644 index 000000000000..dfb6357ed971 --- /dev/null +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-optional-member-call/output.js @@ -0,0 +1,98 @@ +function _classPrivateFieldLooseBase(receiver, privateKey) { if (!Object.prototype.hasOwnProperty.call(receiver, privateKey)) { throw new TypeError("attempted to use private field on non-instance"); } return receiver; } + +var id = 0; + +function _classPrivateFieldLooseKey(name) { return "__private_" + id++ + "_" + name; } + +class Foo { + static getSelf() { + return this; + } + + static test() { + var _deep$very$o, _deep$very$o2, _deep$very$o3, _ref, _ref2, _self2, _classPrivateFieldLoo, _ref3, _ref4, _getSelf, _ref5, _ref6, _classPrivateFieldLoo2, _call, _getSelf2, _getSelf3, _fnDeep$very$o, _fnDeep$very$o2, _fnDeep$very$o3, _ref7, _ref8, _self3, _classPrivateFieldLoo3, _ref9, _ref10, _getSelf4, _ref11, _ref12, _classPrivateFieldLoo4, _call2, _getSelf5, _getSelf6; + + const o = { + Foo: Foo + }; + const deep = { + very: { + o + } + }; + + function fn() { + return o; + } + + function fnDeep() { + return deep; + } + + Foo === null || Foo === void 0 ? void 0 : _classPrivateFieldLooseBase(Foo, _m)[_m](); + Foo === null || Foo === void 0 ? void 0 : _classPrivateFieldLooseBase(Foo, _m)[_m]().toString; + Foo === null || Foo === void 0 ? void 0 : _classPrivateFieldLooseBase(Foo, _m)[_m]().toString(); + o === null || o === void 0 ? void 0 : _classPrivateFieldLooseBase(o.Foo, _m)[_m](); + o === null || o === void 0 ? void 0 : _classPrivateFieldLooseBase(o.Foo, _m)[_m]().toString; + o === null || o === void 0 ? void 0 : _classPrivateFieldLooseBase(o.Foo, _m)[_m]().toString(); + (_deep$very$o = deep?.very.o) === null || _deep$very$o === void 0 ? void 0 : _classPrivateFieldLooseBase(_deep$very$o.Foo, _m)[_m](); + (_deep$very$o2 = deep?.very.o) === null || _deep$very$o2 === void 0 ? void 0 : _classPrivateFieldLooseBase(_deep$very$o2.Foo, _m)[_m]().toString; + (_deep$very$o3 = deep?.very.o) === null || _deep$very$o3 === void 0 ? void 0 : _classPrivateFieldLooseBase(_deep$very$o3.Foo, _m)[_m]().toString(); + o === null || o === void 0 ? void 0 : _classPrivateFieldLooseBase(_classPrivateFieldLooseBase(o.Foo, _self)[_self], _m)[_m](); + o === null || o === void 0 ? void 0 : _classPrivateFieldLooseBase(_classPrivateFieldLooseBase(o.Foo, _self)[_self].self, _m)[_m](); + (_ref = o === null || o === void 0 ? void 0 : _classPrivateFieldLooseBase(o.Foo, _self)[_self]) === null || _ref === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref.self, _m)[_m](); + (_ref2 = o === null || o === void 0 ? void 0 : _classPrivateFieldLooseBase(o.Foo, _self)[_self].self) === null || _ref2 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref2.self, _m)[_m](); + (_self2 = (o === null || o === void 0 ? void 0 : _classPrivateFieldLooseBase(o.Foo, _self)[_self])?.self) === null || _self2 === void 0 ? void 0 : _classPrivateFieldLooseBase(_self2.self, _m)[_m](); + o === null || o === void 0 ? void 0 : _classPrivateFieldLooseBase(_classPrivateFieldLooseBase(o.Foo, _self)[_self].getSelf(), _m)[_m](); + (_ref3 = o === null || o === void 0 ? void 0 : (_classPrivateFieldLoo = _classPrivateFieldLooseBase(o.Foo, _self)[_self]).getSelf) === null || _ref3 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref3.call(_classPrivateFieldLoo), _m)[_m](); + (_ref4 = o === null || o === void 0 ? void 0 : _classPrivateFieldLooseBase(o.Foo, _self)[_self]) === null || _ref4 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref4.getSelf(), _m)[_m](); + (_getSelf = (_ref5 = o === null || o === void 0 ? void 0 : _classPrivateFieldLooseBase(o.Foo, _self)[_self])?.getSelf) === null || _getSelf === void 0 ? void 0 : _classPrivateFieldLooseBase(_getSelf.call(_ref5), _m)[_m](); + (_ref6 = o === null || o === void 0 ? void 0 : _classPrivateFieldLooseBase(o.Foo, _self)[_self].getSelf()) === null || _ref6 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref6.self, _m)[_m](); + (_call = (o === null || o === void 0 ? void 0 : (_classPrivateFieldLoo2 = _classPrivateFieldLooseBase(o.Foo, _self)[_self]).getSelf)?.call(_classPrivateFieldLoo2)) === null || _call === void 0 ? void 0 : _classPrivateFieldLooseBase(_call.self, _m)[_m](); + (_getSelf2 = (o === null || o === void 0 ? void 0 : _classPrivateFieldLooseBase(o.Foo, _self)[_self])?.getSelf()) === null || _getSelf2 === void 0 ? void 0 : _classPrivateFieldLooseBase(_getSelf2.self, _m)[_m](); + (_getSelf3 = (o === null || o === void 0 ? void 0 : _classPrivateFieldLooseBase(o.Foo, _self)[_self])?.getSelf?.()) === null || _getSelf3 === void 0 ? void 0 : _classPrivateFieldLooseBase(_getSelf3.self, _m)[_m](); + fn === null || fn === void 0 ? void 0 : _classPrivateFieldLooseBase(fn().Foo, _m)[_m](); + fn === null || fn === void 0 ? void 0 : _classPrivateFieldLooseBase(fn().Foo, _m)[_m]().toString; + fn === null || fn === void 0 ? void 0 : _classPrivateFieldLooseBase(fn().Foo, _m)[_m]().toString(); + (_fnDeep$very$o = fnDeep?.().very.o) === null || _fnDeep$very$o === void 0 ? void 0 : _classPrivateFieldLooseBase(_fnDeep$very$o.Foo, _m)[_m](); + (_fnDeep$very$o2 = fnDeep?.().very.o) === null || _fnDeep$very$o2 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fnDeep$very$o2.Foo, _m)[_m]().toString; + (_fnDeep$very$o3 = fnDeep?.().very.o) === null || _fnDeep$very$o3 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fnDeep$very$o3.Foo, _m)[_m]().toString(); + fn === null || fn === void 0 ? void 0 : _classPrivateFieldLooseBase(_classPrivateFieldLooseBase(fn().Foo, _self)[_self], _m)[_m](); + fn === null || fn === void 0 ? void 0 : _classPrivateFieldLooseBase(_classPrivateFieldLooseBase(fn().Foo, _self)[_self].self, _m)[_m](); + (_ref7 = fn === null || fn === void 0 ? void 0 : _classPrivateFieldLooseBase(fn().Foo, _self)[_self]) === null || _ref7 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref7.self, _m)[_m](); + (_ref8 = fn === null || fn === void 0 ? void 0 : _classPrivateFieldLooseBase(fn().Foo, _self)[_self].self) === null || _ref8 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref8.self, _m)[_m](); + (_self3 = (fn === null || fn === void 0 ? void 0 : _classPrivateFieldLooseBase(fn().Foo, _self)[_self])?.self) === null || _self3 === void 0 ? void 0 : _classPrivateFieldLooseBase(_self3.self, _m)[_m](); + fn === null || fn === void 0 ? void 0 : _classPrivateFieldLooseBase(_classPrivateFieldLooseBase(fn().Foo, _self)[_self].getSelf(), _m)[_m](); + (_ref9 = fn === null || fn === void 0 ? void 0 : (_classPrivateFieldLoo3 = _classPrivateFieldLooseBase(fn().Foo, _self)[_self]).getSelf) === null || _ref9 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref9.call(_classPrivateFieldLoo3), _m)[_m](); + (_ref10 = fn === null || fn === void 0 ? void 0 : _classPrivateFieldLooseBase(fn().Foo, _self)[_self]) === null || _ref10 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref10.getSelf(), _m)[_m](); + (_getSelf4 = (_ref11 = fn === null || fn === void 0 ? void 0 : _classPrivateFieldLooseBase(fn().Foo, _self)[_self])?.getSelf) === null || _getSelf4 === void 0 ? void 0 : _classPrivateFieldLooseBase(_getSelf4.call(_ref11), _m)[_m](); + (_ref12 = fn === null || fn === void 0 ? void 0 : _classPrivateFieldLooseBase(fn().Foo, _self)[_self].getSelf()) === null || _ref12 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref12.self, _m)[_m](); + (_call2 = (fn === null || fn === void 0 ? void 0 : (_classPrivateFieldLoo4 = _classPrivateFieldLooseBase(fn().Foo, _self)[_self]).getSelf)?.call(_classPrivateFieldLoo4)) === null || _call2 === void 0 ? void 0 : _classPrivateFieldLooseBase(_call2.self, _m)[_m](); + (_getSelf5 = (fn === null || fn === void 0 ? void 0 : _classPrivateFieldLooseBase(fn().Foo, _self)[_self])?.getSelf()) === null || _getSelf5 === void 0 ? void 0 : _classPrivateFieldLooseBase(_getSelf5.self, _m)[_m](); + (_getSelf6 = (fn === null || fn === void 0 ? void 0 : _classPrivateFieldLooseBase(fn().Foo, _self)[_self])?.getSelf?.()) === null || _getSelf6 === void 0 ? void 0 : _classPrivateFieldLooseBase(_getSelf6.self, _m)[_m](); + } + +} + +var _x = _classPrivateFieldLooseKey("x"); + +var _m = _classPrivateFieldLooseKey("m"); + +var _self = _classPrivateFieldLooseKey("self"); + +Object.defineProperty(Foo, _x, { + writable: true, + value: 1 +}); +Object.defineProperty(Foo, _m, { + writable: true, + value: function () { + return _classPrivateFieldLooseBase(this, _x)[_x]; + } +}); +Object.defineProperty(Foo, _self, { + writable: true, + value: Foo +}); +Foo.self = Foo; +Foo.test(); diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-optional-property-with-transform/exec.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-optional-property-with-transform/exec.js new file mode 100644 index 000000000000..0d627ac9e0d4 --- /dev/null +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-optional-property-with-transform/exec.js @@ -0,0 +1,125 @@ +class Foo { + static #x = 1; + static #self = Foo; + static self = Foo; + static getSelf() { return this } + + static test() { + const o = { Foo: Foo }; + const deep = { very: { o } }; + function fn() { + return o; + } + function fnDeep() { + return deep; + } + + expect(Foo?.#x).toEqual(1); + expect(Foo?.#x.toString).toEqual(1..toString); + expect(Foo?.#x.toString()).toEqual('1'); + + expect(o?.Foo?.#x).toEqual(1); + expect(o?.Foo?.#x.toString).toEqual(1..toString); + expect(o?.Foo?.#x.toString()).toEqual('1'); + + expect(deep?.very.o?.Foo?.#x).toEqual(1); + expect(deep?.very.o?.Foo?.#x.toString).toEqual(1..toString); + expect(deep?.very.o?.Foo?.#x.toString()).toEqual('1'); + + expect(o?.Foo.#self?.#x).toEqual(1); + expect(o?.Foo.#self.self?.#x).toEqual(1); + expect(o?.Foo.#self?.self?.#x).toEqual(1); + expect(o?.Foo.#self.self?.self?.#x).toEqual(1); + expect(o?.Foo.#self?.self?.self?.#x).toEqual(1); + + expect(o?.Foo.#self.getSelf()?.#x).toEqual(1); + expect(o?.Foo.#self.getSelf?.()?.#x).toEqual(1); + expect(o?.Foo.#self?.getSelf()?.#x).toEqual(1); + expect(o?.Foo.#self?.getSelf?.()?.#x).toEqual(1); + expect(o?.Foo.#self.getSelf()?.self?.#x).toEqual(1); + expect(o?.Foo.#self.getSelf?.()?.self?.#x).toEqual(1); + expect(o?.Foo.#self?.getSelf()?.self?.#x).toEqual(1); + expect(o?.Foo.#self?.getSelf?.()?.self?.#x).toEqual(1); + + expect(fn?.().Foo?.#x).toEqual(1); + expect(fn?.().Foo?.#x.toString).toEqual(1..toString); + expect(fn?.().Foo?.#x.toString()).toEqual('1'); + + expect(fnDeep?.().very.o?.Foo?.#x).toEqual(1); + expect(fnDeep?.().very.o?.Foo?.#x.toString).toEqual(1..toString); + expect(fnDeep?.().very.o?.Foo?.#x.toString()).toEqual('1'); + + expect(fn?.().Foo.#self?.#x).toEqual(1); + expect(fn?.().Foo.#self.self?.#x).toEqual(1); + expect(fn?.().Foo.#self?.self?.#x).toEqual(1); + expect(fn?.().Foo.#self.self?.self?.#x).toEqual(1); + expect(fn?.().Foo.#self?.self?.self?.#x).toEqual(1); + + expect(fn?.().Foo.#self.getSelf()?.#x).toEqual(1); + expect(fn?.().Foo.#self.getSelf?.()?.#x).toEqual(1); + expect(fn?.().Foo.#self?.getSelf()?.#x).toEqual(1); + expect(fn?.().Foo.#self?.getSelf?.()?.#x).toEqual(1); + expect(fn?.().Foo.#self.getSelf()?.self?.#x).toEqual(1); + expect(fn?.().Foo.#self.getSelf?.()?.self?.#x).toEqual(1); + expect(fn?.().Foo.#self?.getSelf()?.self?.#x).toEqual(1); + expect(fn?.().Foo.#self?.getSelf?.()?.self?.#x).toEqual(1); + } + + static testNull() { + const o = null;; + const deep = { very: { o } }; + const fn = null; + function fnDeep() { + return deep; + } + + expect(o?.Foo?.#x).toEqual(undefined); + expect(o?.Foo?.#x.toString).toEqual(undefined); + expect(o?.Foo?.#x.toString()).toEqual(undefined); + + expect(deep?.very.o?.Foo?.#x).toEqual(undefined); + expect(deep?.very.o?.Foo?.#x.toString).toEqual(undefined); + expect(deep?.very.o?.Foo?.#x.toString()).toEqual(undefined); + + expect(o?.Foo.#self?.#x).toEqual(undefined); + expect(o?.Foo.#self.self?.#x).toEqual(undefined); + expect(o?.Foo.#self?.self?.#x).toEqual(undefined); + expect(o?.Foo.#self.self?.self?.#x).toEqual(undefined); + expect(o?.Foo.#self?.self?.self?.#x).toEqual(undefined); + + expect(o?.Foo.#self.getSelf()?.#x).toEqual(undefined); + expect(o?.Foo.#self.getSelf?.()?.#x).toEqual(undefined); + expect(o?.Foo.#self?.getSelf()?.#x).toEqual(undefined); + expect(o?.Foo.#self?.getSelf?.()?.#x).toEqual(undefined); + expect(o?.Foo.#self.getSelf()?.self?.#x).toEqual(undefined); + expect(o?.Foo.#self.getSelf?.()?.self?.#x).toEqual(undefined); + expect(o?.Foo.#self?.getSelf()?.self?.#x).toEqual(undefined); + expect(o?.Foo.#self?.getSelf?.()?.self?.#x).toEqual(undefined); + + expect(fn?.().Foo?.#x).toEqual(undefined); + expect(fn?.().Foo?.#x.toString).toEqual(undefined); + expect(fn?.().Foo?.#x.toString()).toEqual(undefined); + + expect(fnDeep?.().very.o?.Foo?.#x).toEqual(undefined); + expect(fnDeep?.().very.o?.Foo?.#x.toString).toEqual(undefined); + expect(fnDeep?.().very.o?.Foo?.#x.toString()).toEqual(undefined); + + expect(fn?.().Foo.#self?.#x).toEqual(undefined); + expect(fn?.().Foo.#self.self?.#x).toEqual(undefined); + expect(fn?.().Foo.#self?.self?.#x).toEqual(undefined); + expect(fn?.().Foo.#self.self?.self?.#x).toEqual(undefined); + expect(fn?.().Foo.#self?.self?.self?.#x).toEqual(undefined); + + expect(fn?.().Foo.#self.getSelf()?.#x).toEqual(undefined); + expect(fn?.().Foo.#self.getSelf?.()?.#x).toEqual(undefined); + expect(fn?.().Foo.#self?.getSelf()?.#x).toEqual(undefined); + expect(fn?.().Foo.#self?.getSelf?.()?.#x).toEqual(undefined); + expect(fn?.().Foo.#self.getSelf()?.self?.#x).toEqual(undefined); + expect(fn?.().Foo.#self.getSelf?.()?.self?.#x).toEqual(undefined); + expect(fn?.().Foo.#self?.getSelf()?.self?.#x).toEqual(undefined); + expect(fn?.().Foo.#self?.getSelf?.()?.self?.#x).toEqual(undefined); + } +} + +Foo.test(); +Foo.testNull(); diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-optional-property-with-transform/input.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-optional-property-with-transform/input.js new file mode 100644 index 000000000000..968eeaf3cb44 --- /dev/null +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-optional-property-with-transform/input.js @@ -0,0 +1,69 @@ +class Foo { + static #x = 1; + static #self = Foo; + static self = Foo; + static getSelf() { return this } + + static test() { + const o = { Foo: Foo }; + const deep = { very: { o } }; + function fn() { + return o; + } + function fnDeep() { + return deep; + } + + Foo?.#x; + Foo?.#x.toString; + Foo?.#x.toString(); + + o?.Foo?.#x; + o?.Foo?.#x.toString; + o?.Foo?.#x.toString(); + + deep?.very.o?.Foo?.#x; + deep?.very.o?.Foo?.#x.toString; + deep?.very.o?.Foo?.#x.toString(); + + o?.Foo.#self?.#x; + o?.Foo.#self.self?.#x; + o?.Foo.#self?.self?.#x; + o?.Foo.#self.self?.self?.#x; + o?.Foo.#self?.self?.self?.#x; + + o?.Foo.#self.getSelf()?.#x; + o?.Foo.#self.getSelf?.()?.#x; + o?.Foo.#self?.getSelf()?.#x; + o?.Foo.#self?.getSelf?.()?.#x; + o?.Foo.#self.getSelf()?.self?.#x; + o?.Foo.#self.getSelf?.()?.self?.#x; + o?.Foo.#self?.getSelf()?.self?.#x; + o?.Foo.#self?.getSelf?.()?.self?.#x; + + fn?.().Foo?.#x; + fn?.().Foo?.#x.toString; + fn?.().Foo?.#x.toString(); + + fnDeep?.().very.o?.Foo?.#x; + fnDeep?.().very.o?.Foo?.#x.toString; + fnDeep?.().very.o?.Foo?.#x.toString(); + + fn?.().Foo.#self?.#x; + fn?.().Foo.#self.self?.#x; + fn?.().Foo.#self?.self?.#x; + fn?.().Foo.#self.self?.self?.#x; + fn?.().Foo.#self?.self?.self?.#x; + + fn?.().Foo.#self.getSelf()?.#x; + fn?.().Foo.#self.getSelf?.()?.#x; + fn?.().Foo.#self?.getSelf()?.#x; + fn?.().Foo.#self?.getSelf?.()?.#x; + fn?.().Foo.#self.getSelf()?.self?.#x; + fn?.().Foo.#self.getSelf?.()?.self?.#x; + fn?.().Foo.#self?.getSelf()?.self?.#x; + fn?.().Foo.#self?.getSelf?.()?.self?.#x; + } +} + +Foo.test(); diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-optional-property-with-transform/options.json b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-optional-property-with-transform/options.json new file mode 100644 index 000000000000..124133b5af2b --- /dev/null +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-optional-property-with-transform/options.json @@ -0,0 +1,6 @@ +{ + "plugins": [ + ["proposal-optional-chaining", { "loose": true }], + ["proposal-class-properties", { "loose": true }] + ] +} diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-optional-property-with-transform/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-optional-property-with-transform/output.js new file mode 100644 index 000000000000..b1ede3a8c4c9 --- /dev/null +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-optional-property-with-transform/output.js @@ -0,0 +1,90 @@ +function _classPrivateFieldLooseBase(receiver, privateKey) { if (!Object.prototype.hasOwnProperty.call(receiver, privateKey)) { throw new TypeError("attempted to use private field on non-instance"); } return receiver; } + +var id = 0; + +function _classPrivateFieldLooseKey(name) { return "__private_" + id++ + "_" + name; } + +class Foo { + static getSelf() { + return this; + } + + static test() { + var _o$Foo, _o$Foo2, _o$Foo3, _deep$very$o$Foo, _deep$very$o$Foo2, _deep$very$o$Foo3, _ref, _ref2, _self2, _self3, _self$self, _ref3, _classPrivateFieldLoo, _call, _getSelf, _getSelf2, _self4, _classPrivateFieldLoo2, _call$self, _getSelf$self, _getSelf$self2, _fn$Foo, _fn$Foo2, _fn$Foo3, _fnDeep$very$o$Foo, _fnDeep$very$o$Foo2, _fnDeep$very$o$Foo3, _ref4, _ref5, _self5, _self6, _self$self2, _ref6, _classPrivateFieldLoo3, _call2, _getSelf3, _getSelf4, _self7, _classPrivateFieldLoo4, _call$self2, _getSelf$self3, _getSelf$self4, _deep$very$o, _deep$very$o2, _deep$very$o3, _ref7, _ref8, _ref9, _ref9$self, _ref10, _ref11, _ref12, _ref13, _ref14, _ref14$call, _ref15, _ref15$getSelf, _ref16, _ref16$getSelf, _fnDeep$very$o, _fnDeep$very$o2, _fnDeep$very$o3, _ref17, _ref18, _ref19, _ref19$self, _ref20, _ref21, _ref22, _ref23, _ref24, _ref24$call, _ref25, _ref25$getSelf, _ref26, _ref26$getSelf; + + const o = { + Foo: Foo + }; + const deep = { + very: { + o + } + }; + + function fn() { + return o; + } + + function fnDeep() { + return deep; + } + + Foo === null || Foo === void 0 ? void 0 : _classPrivateFieldLooseBase(Foo, _x)[_x]; + Foo === null || Foo === void 0 ? void 0 : _classPrivateFieldLooseBase(Foo, _x)[_x].toString; + Foo === null || Foo === void 0 ? void 0 : _classPrivateFieldLooseBase(Foo, _x)[_x].toString(); + (_o$Foo = o == null ? void 0 : o.Foo) === null || _o$Foo === void 0 ? void 0 : _classPrivateFieldLooseBase(_o$Foo, _x)[_x]; + (_o$Foo2 = o == null ? void 0 : o.Foo) === null || _o$Foo2 === void 0 ? void 0 : _classPrivateFieldLooseBase(_o$Foo2, _x)[_x].toString; + (_o$Foo3 = o == null ? void 0 : o.Foo) === null || _o$Foo3 === void 0 ? void 0 : _classPrivateFieldLooseBase(_o$Foo3, _x)[_x].toString(); + (_deep$very$o$Foo = deep == null ? void 0 : (_deep$very$o = deep.very.o) == null ? void 0 : _deep$very$o.Foo) === null || _deep$very$o$Foo === void 0 ? void 0 : _classPrivateFieldLooseBase(_deep$very$o$Foo, _x)[_x]; + (_deep$very$o$Foo2 = deep == null ? void 0 : (_deep$very$o2 = deep.very.o) == null ? void 0 : _deep$very$o2.Foo) === null || _deep$very$o$Foo2 === void 0 ? void 0 : _classPrivateFieldLooseBase(_deep$very$o$Foo2, _x)[_x].toString; + (_deep$very$o$Foo3 = deep == null ? void 0 : (_deep$very$o3 = deep.very.o) == null ? void 0 : _deep$very$o3.Foo) === null || _deep$very$o$Foo3 === void 0 ? void 0 : _classPrivateFieldLooseBase(_deep$very$o$Foo3, _x)[_x].toString(); + (_ref = o === null || o === void 0 ? void 0 : _classPrivateFieldLooseBase(o.Foo, _self)[_self]) === null || _ref === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref, _x)[_x]; + (_ref2 = o === null || o === void 0 ? void 0 : _classPrivateFieldLooseBase(o.Foo, _self)[_self].self) === null || _ref2 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref2, _x)[_x]; + (_self2 = (_ref7 = o === null || o === void 0 ? void 0 : _classPrivateFieldLooseBase(o.Foo, _self)[_self]) == null ? void 0 : _ref7.self) === null || _self2 === void 0 ? void 0 : _classPrivateFieldLooseBase(_self2, _x)[_x]; + (_self3 = (_ref8 = o === null || o === void 0 ? void 0 : _classPrivateFieldLooseBase(o.Foo, _self)[_self].self) == null ? void 0 : _ref8.self) === null || _self3 === void 0 ? void 0 : _classPrivateFieldLooseBase(_self3, _x)[_x]; + (_self$self = (_ref9 = o === null || o === void 0 ? void 0 : _classPrivateFieldLooseBase(o.Foo, _self)[_self]) == null ? void 0 : (_ref9$self = _ref9.self) == null ? void 0 : _ref9$self.self) === null || _self$self === void 0 ? void 0 : _classPrivateFieldLooseBase(_self$self, _x)[_x]; + (_ref3 = o === null || o === void 0 ? void 0 : _classPrivateFieldLooseBase(o.Foo, _self)[_self].getSelf()) === null || _ref3 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref3, _x)[_x]; + (_call = (_ref10 = o === null || o === void 0 ? void 0 : (_classPrivateFieldLoo = _classPrivateFieldLooseBase(o.Foo, _self)[_self]).getSelf) == null ? void 0 : _ref10.call(_classPrivateFieldLoo)) === null || _call === void 0 ? void 0 : _classPrivateFieldLooseBase(_call, _x)[_x]; + (_getSelf = (_ref11 = o === null || o === void 0 ? void 0 : _classPrivateFieldLooseBase(o.Foo, _self)[_self]) == null ? void 0 : _ref11.getSelf()) === null || _getSelf === void 0 ? void 0 : _classPrivateFieldLooseBase(_getSelf, _x)[_x]; + (_getSelf2 = (_ref12 = o === null || o === void 0 ? void 0 : _classPrivateFieldLooseBase(o.Foo, _self)[_self]) == null ? void 0 : _ref12.getSelf == null ? void 0 : _ref12.getSelf()) === null || _getSelf2 === void 0 ? void 0 : _classPrivateFieldLooseBase(_getSelf2, _x)[_x]; + (_self4 = (_ref13 = o === null || o === void 0 ? void 0 : _classPrivateFieldLooseBase(o.Foo, _self)[_self].getSelf()) == null ? void 0 : _ref13.self) === null || _self4 === void 0 ? void 0 : _classPrivateFieldLooseBase(_self4, _x)[_x]; + (_call$self = (_ref14 = o === null || o === void 0 ? void 0 : (_classPrivateFieldLoo2 = _classPrivateFieldLooseBase(o.Foo, _self)[_self]).getSelf) == null ? void 0 : (_ref14$call = _ref14.call(_classPrivateFieldLoo2)) == null ? void 0 : _ref14$call.self) === null || _call$self === void 0 ? void 0 : _classPrivateFieldLooseBase(_call$self, _x)[_x]; + (_getSelf$self = (_ref15 = o === null || o === void 0 ? void 0 : _classPrivateFieldLooseBase(o.Foo, _self)[_self]) == null ? void 0 : (_ref15$getSelf = _ref15.getSelf()) == null ? void 0 : _ref15$getSelf.self) === null || _getSelf$self === void 0 ? void 0 : _classPrivateFieldLooseBase(_getSelf$self, _x)[_x]; + (_getSelf$self2 = (_ref16 = o === null || o === void 0 ? void 0 : _classPrivateFieldLooseBase(o.Foo, _self)[_self]) == null ? void 0 : _ref16.getSelf == null ? void 0 : (_ref16$getSelf = _ref16.getSelf()) == null ? void 0 : _ref16$getSelf.self) === null || _getSelf$self2 === void 0 ? void 0 : _classPrivateFieldLooseBase(_getSelf$self2, _x)[_x]; + (_fn$Foo = fn == null ? void 0 : fn().Foo) === null || _fn$Foo === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn$Foo, _x)[_x]; + (_fn$Foo2 = fn == null ? void 0 : fn().Foo) === null || _fn$Foo2 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn$Foo2, _x)[_x].toString; + (_fn$Foo3 = fn == null ? void 0 : fn().Foo) === null || _fn$Foo3 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn$Foo3, _x)[_x].toString(); + (_fnDeep$very$o$Foo = fnDeep == null ? void 0 : (_fnDeep$very$o = fnDeep().very.o) == null ? void 0 : _fnDeep$very$o.Foo) === null || _fnDeep$very$o$Foo === void 0 ? void 0 : _classPrivateFieldLooseBase(_fnDeep$very$o$Foo, _x)[_x]; + (_fnDeep$very$o$Foo2 = fnDeep == null ? void 0 : (_fnDeep$very$o2 = fnDeep().very.o) == null ? void 0 : _fnDeep$very$o2.Foo) === null || _fnDeep$very$o$Foo2 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fnDeep$very$o$Foo2, _x)[_x].toString; + (_fnDeep$very$o$Foo3 = fnDeep == null ? void 0 : (_fnDeep$very$o3 = fnDeep().very.o) == null ? void 0 : _fnDeep$very$o3.Foo) === null || _fnDeep$very$o$Foo3 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fnDeep$very$o$Foo3, _x)[_x].toString(); + (_ref4 = fn === null || fn === void 0 ? void 0 : _classPrivateFieldLooseBase(fn().Foo, _self)[_self]) === null || _ref4 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref4, _x)[_x]; + (_ref5 = fn === null || fn === void 0 ? void 0 : _classPrivateFieldLooseBase(fn().Foo, _self)[_self].self) === null || _ref5 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref5, _x)[_x]; + (_self5 = (_ref17 = fn === null || fn === void 0 ? void 0 : _classPrivateFieldLooseBase(fn().Foo, _self)[_self]) == null ? void 0 : _ref17.self) === null || _self5 === void 0 ? void 0 : _classPrivateFieldLooseBase(_self5, _x)[_x]; + (_self6 = (_ref18 = fn === null || fn === void 0 ? void 0 : _classPrivateFieldLooseBase(fn().Foo, _self)[_self].self) == null ? void 0 : _ref18.self) === null || _self6 === void 0 ? void 0 : _classPrivateFieldLooseBase(_self6, _x)[_x]; + (_self$self2 = (_ref19 = fn === null || fn === void 0 ? void 0 : _classPrivateFieldLooseBase(fn().Foo, _self)[_self]) == null ? void 0 : (_ref19$self = _ref19.self) == null ? void 0 : _ref19$self.self) === null || _self$self2 === void 0 ? void 0 : _classPrivateFieldLooseBase(_self$self2, _x)[_x]; + (_ref6 = fn === null || fn === void 0 ? void 0 : _classPrivateFieldLooseBase(fn().Foo, _self)[_self].getSelf()) === null || _ref6 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref6, _x)[_x]; + (_call2 = (_ref20 = fn === null || fn === void 0 ? void 0 : (_classPrivateFieldLoo3 = _classPrivateFieldLooseBase(fn().Foo, _self)[_self]).getSelf) == null ? void 0 : _ref20.call(_classPrivateFieldLoo3)) === null || _call2 === void 0 ? void 0 : _classPrivateFieldLooseBase(_call2, _x)[_x]; + (_getSelf3 = (_ref21 = fn === null || fn === void 0 ? void 0 : _classPrivateFieldLooseBase(fn().Foo, _self)[_self]) == null ? void 0 : _ref21.getSelf()) === null || _getSelf3 === void 0 ? void 0 : _classPrivateFieldLooseBase(_getSelf3, _x)[_x]; + (_getSelf4 = (_ref22 = fn === null || fn === void 0 ? void 0 : _classPrivateFieldLooseBase(fn().Foo, _self)[_self]) == null ? void 0 : _ref22.getSelf == null ? void 0 : _ref22.getSelf()) === null || _getSelf4 === void 0 ? void 0 : _classPrivateFieldLooseBase(_getSelf4, _x)[_x]; + (_self7 = (_ref23 = fn === null || fn === void 0 ? void 0 : _classPrivateFieldLooseBase(fn().Foo, _self)[_self].getSelf()) == null ? void 0 : _ref23.self) === null || _self7 === void 0 ? void 0 : _classPrivateFieldLooseBase(_self7, _x)[_x]; + (_call$self2 = (_ref24 = fn === null || fn === void 0 ? void 0 : (_classPrivateFieldLoo4 = _classPrivateFieldLooseBase(fn().Foo, _self)[_self]).getSelf) == null ? void 0 : (_ref24$call = _ref24.call(_classPrivateFieldLoo4)) == null ? void 0 : _ref24$call.self) === null || _call$self2 === void 0 ? void 0 : _classPrivateFieldLooseBase(_call$self2, _x)[_x]; + (_getSelf$self3 = (_ref25 = fn === null || fn === void 0 ? void 0 : _classPrivateFieldLooseBase(fn().Foo, _self)[_self]) == null ? void 0 : (_ref25$getSelf = _ref25.getSelf()) == null ? void 0 : _ref25$getSelf.self) === null || _getSelf$self3 === void 0 ? void 0 : _classPrivateFieldLooseBase(_getSelf$self3, _x)[_x]; + (_getSelf$self4 = (_ref26 = fn === null || fn === void 0 ? void 0 : _classPrivateFieldLooseBase(fn().Foo, _self)[_self]) == null ? void 0 : _ref26.getSelf == null ? void 0 : (_ref26$getSelf = _ref26.getSelf()) == null ? void 0 : _ref26$getSelf.self) === null || _getSelf$self4 === void 0 ? void 0 : _classPrivateFieldLooseBase(_getSelf$self4, _x)[_x]; + } + +} + +var _x = _classPrivateFieldLooseKey("x"); + +var _self = _classPrivateFieldLooseKey("self"); + +Object.defineProperty(Foo, _x, { + writable: true, + value: 1 +}); +Object.defineProperty(Foo, _self, { + writable: true, + value: Foo +}); +Foo.self = Foo; +Foo.test(); diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-optional-property/exec.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-optional-property/exec.js new file mode 100644 index 000000000000..0d627ac9e0d4 --- /dev/null +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-optional-property/exec.js @@ -0,0 +1,125 @@ +class Foo { + static #x = 1; + static #self = Foo; + static self = Foo; + static getSelf() { return this } + + static test() { + const o = { Foo: Foo }; + const deep = { very: { o } }; + function fn() { + return o; + } + function fnDeep() { + return deep; + } + + expect(Foo?.#x).toEqual(1); + expect(Foo?.#x.toString).toEqual(1..toString); + expect(Foo?.#x.toString()).toEqual('1'); + + expect(o?.Foo?.#x).toEqual(1); + expect(o?.Foo?.#x.toString).toEqual(1..toString); + expect(o?.Foo?.#x.toString()).toEqual('1'); + + expect(deep?.very.o?.Foo?.#x).toEqual(1); + expect(deep?.very.o?.Foo?.#x.toString).toEqual(1..toString); + expect(deep?.very.o?.Foo?.#x.toString()).toEqual('1'); + + expect(o?.Foo.#self?.#x).toEqual(1); + expect(o?.Foo.#self.self?.#x).toEqual(1); + expect(o?.Foo.#self?.self?.#x).toEqual(1); + expect(o?.Foo.#self.self?.self?.#x).toEqual(1); + expect(o?.Foo.#self?.self?.self?.#x).toEqual(1); + + expect(o?.Foo.#self.getSelf()?.#x).toEqual(1); + expect(o?.Foo.#self.getSelf?.()?.#x).toEqual(1); + expect(o?.Foo.#self?.getSelf()?.#x).toEqual(1); + expect(o?.Foo.#self?.getSelf?.()?.#x).toEqual(1); + expect(o?.Foo.#self.getSelf()?.self?.#x).toEqual(1); + expect(o?.Foo.#self.getSelf?.()?.self?.#x).toEqual(1); + expect(o?.Foo.#self?.getSelf()?.self?.#x).toEqual(1); + expect(o?.Foo.#self?.getSelf?.()?.self?.#x).toEqual(1); + + expect(fn?.().Foo?.#x).toEqual(1); + expect(fn?.().Foo?.#x.toString).toEqual(1..toString); + expect(fn?.().Foo?.#x.toString()).toEqual('1'); + + expect(fnDeep?.().very.o?.Foo?.#x).toEqual(1); + expect(fnDeep?.().very.o?.Foo?.#x.toString).toEqual(1..toString); + expect(fnDeep?.().very.o?.Foo?.#x.toString()).toEqual('1'); + + expect(fn?.().Foo.#self?.#x).toEqual(1); + expect(fn?.().Foo.#self.self?.#x).toEqual(1); + expect(fn?.().Foo.#self?.self?.#x).toEqual(1); + expect(fn?.().Foo.#self.self?.self?.#x).toEqual(1); + expect(fn?.().Foo.#self?.self?.self?.#x).toEqual(1); + + expect(fn?.().Foo.#self.getSelf()?.#x).toEqual(1); + expect(fn?.().Foo.#self.getSelf?.()?.#x).toEqual(1); + expect(fn?.().Foo.#self?.getSelf()?.#x).toEqual(1); + expect(fn?.().Foo.#self?.getSelf?.()?.#x).toEqual(1); + expect(fn?.().Foo.#self.getSelf()?.self?.#x).toEqual(1); + expect(fn?.().Foo.#self.getSelf?.()?.self?.#x).toEqual(1); + expect(fn?.().Foo.#self?.getSelf()?.self?.#x).toEqual(1); + expect(fn?.().Foo.#self?.getSelf?.()?.self?.#x).toEqual(1); + } + + static testNull() { + const o = null;; + const deep = { very: { o } }; + const fn = null; + function fnDeep() { + return deep; + } + + expect(o?.Foo?.#x).toEqual(undefined); + expect(o?.Foo?.#x.toString).toEqual(undefined); + expect(o?.Foo?.#x.toString()).toEqual(undefined); + + expect(deep?.very.o?.Foo?.#x).toEqual(undefined); + expect(deep?.very.o?.Foo?.#x.toString).toEqual(undefined); + expect(deep?.very.o?.Foo?.#x.toString()).toEqual(undefined); + + expect(o?.Foo.#self?.#x).toEqual(undefined); + expect(o?.Foo.#self.self?.#x).toEqual(undefined); + expect(o?.Foo.#self?.self?.#x).toEqual(undefined); + expect(o?.Foo.#self.self?.self?.#x).toEqual(undefined); + expect(o?.Foo.#self?.self?.self?.#x).toEqual(undefined); + + expect(o?.Foo.#self.getSelf()?.#x).toEqual(undefined); + expect(o?.Foo.#self.getSelf?.()?.#x).toEqual(undefined); + expect(o?.Foo.#self?.getSelf()?.#x).toEqual(undefined); + expect(o?.Foo.#self?.getSelf?.()?.#x).toEqual(undefined); + expect(o?.Foo.#self.getSelf()?.self?.#x).toEqual(undefined); + expect(o?.Foo.#self.getSelf?.()?.self?.#x).toEqual(undefined); + expect(o?.Foo.#self?.getSelf()?.self?.#x).toEqual(undefined); + expect(o?.Foo.#self?.getSelf?.()?.self?.#x).toEqual(undefined); + + expect(fn?.().Foo?.#x).toEqual(undefined); + expect(fn?.().Foo?.#x.toString).toEqual(undefined); + expect(fn?.().Foo?.#x.toString()).toEqual(undefined); + + expect(fnDeep?.().very.o?.Foo?.#x).toEqual(undefined); + expect(fnDeep?.().very.o?.Foo?.#x.toString).toEqual(undefined); + expect(fnDeep?.().very.o?.Foo?.#x.toString()).toEqual(undefined); + + expect(fn?.().Foo.#self?.#x).toEqual(undefined); + expect(fn?.().Foo.#self.self?.#x).toEqual(undefined); + expect(fn?.().Foo.#self?.self?.#x).toEqual(undefined); + expect(fn?.().Foo.#self.self?.self?.#x).toEqual(undefined); + expect(fn?.().Foo.#self?.self?.self?.#x).toEqual(undefined); + + expect(fn?.().Foo.#self.getSelf()?.#x).toEqual(undefined); + expect(fn?.().Foo.#self.getSelf?.()?.#x).toEqual(undefined); + expect(fn?.().Foo.#self?.getSelf()?.#x).toEqual(undefined); + expect(fn?.().Foo.#self?.getSelf?.()?.#x).toEqual(undefined); + expect(fn?.().Foo.#self.getSelf()?.self?.#x).toEqual(undefined); + expect(fn?.().Foo.#self.getSelf?.()?.self?.#x).toEqual(undefined); + expect(fn?.().Foo.#self?.getSelf()?.self?.#x).toEqual(undefined); + expect(fn?.().Foo.#self?.getSelf?.()?.self?.#x).toEqual(undefined); + } +} + +Foo.test(); +Foo.testNull(); diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-optional-property/input.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-optional-property/input.js new file mode 100644 index 000000000000..aecba329a27a --- /dev/null +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-optional-property/input.js @@ -0,0 +1,70 @@ +class Foo { + static #x = 1; + static #self = Foo; + static self = Foo; + static getSelf() { return this } + + static test() { + const o = { Foo: Foo }; + const deep = { very: { o } }; + function fn() { + return o; + } + function fnDeep() { + return deep; + } + + Foo?.#x; + Foo?.#x.toString; + Foo?.#x.toString(); + + o?.Foo?.#x; + o?.Foo?.#x.toString; + o?.Foo?.#x.toString(); + + deep?.very.o?.Foo?.#x; + deep?.very.o?.Foo?.#x.toString; + deep?.very.o?.Foo?.#x.toString(); + + o?.Foo.#self?.#x; + o?.Foo.#self.self?.#x; + o?.Foo.#self?.self?.#x; + o?.Foo.#self.self?.self?.#x; + o?.Foo.#self?.self?.self?.#x; + + o?.Foo.#self.getSelf()?.#x; + o?.Foo.#self.getSelf?.()?.#x; + o?.Foo.#self?.getSelf()?.#x; + o?.Foo.#self?.getSelf?.()?.#x; + o?.Foo.#self.getSelf()?.self?.#x; + o?.Foo.#self.getSelf?.()?.self?.#x; + o?.Foo.#self?.getSelf()?.self?.#x; + o?.Foo.#self?.getSelf?.()?.self?.#x; + + fn?.().Foo?.#x; + fn?.().Foo?.#x.toString; + fn?.().Foo?.#x.toString(); + + fnDeep?.().very.o?.Foo?.#x; + fnDeep?.().very.o?.Foo?.#x.toString; + fnDeep?.().very.o?.Foo?.#x.toString(); + + fn?.().Foo.#self?.#x; + fn?.().Foo.#self.self?.#x; + fn?.().Foo.#self?.self?.#x; + fn?.().Foo.#self.self?.self?.#x; + fn?.().Foo.#self?.self?.self?.#x; + + fn?.().Foo.#self.getSelf()?.#x; + fn?.().Foo.#self.getSelf?.()?.#x; + fn?.().Foo.#self?.getSelf()?.#x; + fn?.().Foo.#self?.getSelf?.()?.#x; + fn?.().Foo.#self.getSelf()?.self?.#x; + fn?.().Foo.#self.getSelf?.()?.self?.#x; + fn?.().Foo.#self?.getSelf()?.self?.#x; + fn?.().Foo.#self?.getSelf?.()?.self?.#x; + + } +} + +Foo.test(); diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-optional-property/options.json b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-optional-property/options.json new file mode 100644 index 000000000000..2d5cfe8e8095 --- /dev/null +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-optional-property/options.json @@ -0,0 +1,4 @@ +{ + "plugins": [["proposal-class-properties", { "loose": true }]], + "minNodeVersion": "14.0.0" +} diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-optional-property/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-optional-property/output.js new file mode 100644 index 000000000000..d3912701eb1a --- /dev/null +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-optional-property/output.js @@ -0,0 +1,90 @@ +function _classPrivateFieldLooseBase(receiver, privateKey) { if (!Object.prototype.hasOwnProperty.call(receiver, privateKey)) { throw new TypeError("attempted to use private field on non-instance"); } return receiver; } + +var id = 0; + +function _classPrivateFieldLooseKey(name) { return "__private_" + id++ + "_" + name; } + +class Foo { + static getSelf() { + return this; + } + + static test() { + var _o$Foo, _o$Foo2, _o$Foo3, _deep$very$o$Foo, _deep$very$o$Foo2, _deep$very$o$Foo3, _ref, _ref2, _self2, _self3, _self$self, _ref3, _classPrivateFieldLoo, _call, _getSelf, _getSelf2, _self4, _classPrivateFieldLoo2, _call$self, _getSelf$self, _getSelf$self2, _fn$Foo, _fn$Foo2, _fn$Foo3, _fnDeep$very$o$Foo, _fnDeep$very$o$Foo2, _fnDeep$very$o$Foo3, _ref4, _ref5, _self5, _self6, _self$self2, _ref6, _classPrivateFieldLoo3, _call2, _getSelf3, _getSelf4, _self7, _classPrivateFieldLoo4, _call$self2, _getSelf$self3, _getSelf$self4; + + const o = { + Foo: Foo + }; + const deep = { + very: { + o + } + }; + + function fn() { + return o; + } + + function fnDeep() { + return deep; + } + + Foo === null || Foo === void 0 ? void 0 : _classPrivateFieldLooseBase(Foo, _x)[_x]; + Foo === null || Foo === void 0 ? void 0 : _classPrivateFieldLooseBase(Foo, _x)[_x].toString; + Foo === null || Foo === void 0 ? void 0 : _classPrivateFieldLooseBase(Foo, _x)[_x].toString(); + (_o$Foo = o?.Foo) === null || _o$Foo === void 0 ? void 0 : _classPrivateFieldLooseBase(_o$Foo, _x)[_x]; + (_o$Foo2 = o?.Foo) === null || _o$Foo2 === void 0 ? void 0 : _classPrivateFieldLooseBase(_o$Foo2, _x)[_x].toString; + (_o$Foo3 = o?.Foo) === null || _o$Foo3 === void 0 ? void 0 : _classPrivateFieldLooseBase(_o$Foo3, _x)[_x].toString(); + (_deep$very$o$Foo = deep?.very.o?.Foo) === null || _deep$very$o$Foo === void 0 ? void 0 : _classPrivateFieldLooseBase(_deep$very$o$Foo, _x)[_x]; + (_deep$very$o$Foo2 = deep?.very.o?.Foo) === null || _deep$very$o$Foo2 === void 0 ? void 0 : _classPrivateFieldLooseBase(_deep$very$o$Foo2, _x)[_x].toString; + (_deep$very$o$Foo3 = deep?.very.o?.Foo) === null || _deep$very$o$Foo3 === void 0 ? void 0 : _classPrivateFieldLooseBase(_deep$very$o$Foo3, _x)[_x].toString(); + (_ref = o === null || o === void 0 ? void 0 : _classPrivateFieldLooseBase(o.Foo, _self)[_self]) === null || _ref === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref, _x)[_x]; + (_ref2 = o === null || o === void 0 ? void 0 : _classPrivateFieldLooseBase(o.Foo, _self)[_self].self) === null || _ref2 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref2, _x)[_x]; + (_self2 = (o === null || o === void 0 ? void 0 : _classPrivateFieldLooseBase(o.Foo, _self)[_self])?.self) === null || _self2 === void 0 ? void 0 : _classPrivateFieldLooseBase(_self2, _x)[_x]; + (_self3 = (o === null || o === void 0 ? void 0 : _classPrivateFieldLooseBase(o.Foo, _self)[_self].self)?.self) === null || _self3 === void 0 ? void 0 : _classPrivateFieldLooseBase(_self3, _x)[_x]; + (_self$self = (o === null || o === void 0 ? void 0 : _classPrivateFieldLooseBase(o.Foo, _self)[_self])?.self?.self) === null || _self$self === void 0 ? void 0 : _classPrivateFieldLooseBase(_self$self, _x)[_x]; + (_ref3 = o === null || o === void 0 ? void 0 : _classPrivateFieldLooseBase(o.Foo, _self)[_self].getSelf()) === null || _ref3 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref3, _x)[_x]; + (_call = (o === null || o === void 0 ? void 0 : (_classPrivateFieldLoo = _classPrivateFieldLooseBase(o.Foo, _self)[_self]).getSelf)?.call(_classPrivateFieldLoo)) === null || _call === void 0 ? void 0 : _classPrivateFieldLooseBase(_call, _x)[_x]; + (_getSelf = (o === null || o === void 0 ? void 0 : _classPrivateFieldLooseBase(o.Foo, _self)[_self])?.getSelf()) === null || _getSelf === void 0 ? void 0 : _classPrivateFieldLooseBase(_getSelf, _x)[_x]; + (_getSelf2 = (o === null || o === void 0 ? void 0 : _classPrivateFieldLooseBase(o.Foo, _self)[_self])?.getSelf?.()) === null || _getSelf2 === void 0 ? void 0 : _classPrivateFieldLooseBase(_getSelf2, _x)[_x]; + (_self4 = (o === null || o === void 0 ? void 0 : _classPrivateFieldLooseBase(o.Foo, _self)[_self].getSelf())?.self) === null || _self4 === void 0 ? void 0 : _classPrivateFieldLooseBase(_self4, _x)[_x]; + (_call$self = (o === null || o === void 0 ? void 0 : (_classPrivateFieldLoo2 = _classPrivateFieldLooseBase(o.Foo, _self)[_self]).getSelf)?.call(_classPrivateFieldLoo2)?.self) === null || _call$self === void 0 ? void 0 : _classPrivateFieldLooseBase(_call$self, _x)[_x]; + (_getSelf$self = (o === null || o === void 0 ? void 0 : _classPrivateFieldLooseBase(o.Foo, _self)[_self])?.getSelf()?.self) === null || _getSelf$self === void 0 ? void 0 : _classPrivateFieldLooseBase(_getSelf$self, _x)[_x]; + (_getSelf$self2 = (o === null || o === void 0 ? void 0 : _classPrivateFieldLooseBase(o.Foo, _self)[_self])?.getSelf?.()?.self) === null || _getSelf$self2 === void 0 ? void 0 : _classPrivateFieldLooseBase(_getSelf$self2, _x)[_x]; + (_fn$Foo = fn?.().Foo) === null || _fn$Foo === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn$Foo, _x)[_x]; + (_fn$Foo2 = fn?.().Foo) === null || _fn$Foo2 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn$Foo2, _x)[_x].toString; + (_fn$Foo3 = fn?.().Foo) === null || _fn$Foo3 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fn$Foo3, _x)[_x].toString(); + (_fnDeep$very$o$Foo = fnDeep?.().very.o?.Foo) === null || _fnDeep$very$o$Foo === void 0 ? void 0 : _classPrivateFieldLooseBase(_fnDeep$very$o$Foo, _x)[_x]; + (_fnDeep$very$o$Foo2 = fnDeep?.().very.o?.Foo) === null || _fnDeep$very$o$Foo2 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fnDeep$very$o$Foo2, _x)[_x].toString; + (_fnDeep$very$o$Foo3 = fnDeep?.().very.o?.Foo) === null || _fnDeep$very$o$Foo3 === void 0 ? void 0 : _classPrivateFieldLooseBase(_fnDeep$very$o$Foo3, _x)[_x].toString(); + (_ref4 = fn === null || fn === void 0 ? void 0 : _classPrivateFieldLooseBase(fn().Foo, _self)[_self]) === null || _ref4 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref4, _x)[_x]; + (_ref5 = fn === null || fn === void 0 ? void 0 : _classPrivateFieldLooseBase(fn().Foo, _self)[_self].self) === null || _ref5 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref5, _x)[_x]; + (_self5 = (fn === null || fn === void 0 ? void 0 : _classPrivateFieldLooseBase(fn().Foo, _self)[_self])?.self) === null || _self5 === void 0 ? void 0 : _classPrivateFieldLooseBase(_self5, _x)[_x]; + (_self6 = (fn === null || fn === void 0 ? void 0 : _classPrivateFieldLooseBase(fn().Foo, _self)[_self].self)?.self) === null || _self6 === void 0 ? void 0 : _classPrivateFieldLooseBase(_self6, _x)[_x]; + (_self$self2 = (fn === null || fn === void 0 ? void 0 : _classPrivateFieldLooseBase(fn().Foo, _self)[_self])?.self?.self) === null || _self$self2 === void 0 ? void 0 : _classPrivateFieldLooseBase(_self$self2, _x)[_x]; + (_ref6 = fn === null || fn === void 0 ? void 0 : _classPrivateFieldLooseBase(fn().Foo, _self)[_self].getSelf()) === null || _ref6 === void 0 ? void 0 : _classPrivateFieldLooseBase(_ref6, _x)[_x]; + (_call2 = (fn === null || fn === void 0 ? void 0 : (_classPrivateFieldLoo3 = _classPrivateFieldLooseBase(fn().Foo, _self)[_self]).getSelf)?.call(_classPrivateFieldLoo3)) === null || _call2 === void 0 ? void 0 : _classPrivateFieldLooseBase(_call2, _x)[_x]; + (_getSelf3 = (fn === null || fn === void 0 ? void 0 : _classPrivateFieldLooseBase(fn().Foo, _self)[_self])?.getSelf()) === null || _getSelf3 === void 0 ? void 0 : _classPrivateFieldLooseBase(_getSelf3, _x)[_x]; + (_getSelf4 = (fn === null || fn === void 0 ? void 0 : _classPrivateFieldLooseBase(fn().Foo, _self)[_self])?.getSelf?.()) === null || _getSelf4 === void 0 ? void 0 : _classPrivateFieldLooseBase(_getSelf4, _x)[_x]; + (_self7 = (fn === null || fn === void 0 ? void 0 : _classPrivateFieldLooseBase(fn().Foo, _self)[_self].getSelf())?.self) === null || _self7 === void 0 ? void 0 : _classPrivateFieldLooseBase(_self7, _x)[_x]; + (_call$self2 = (fn === null || fn === void 0 ? void 0 : (_classPrivateFieldLoo4 = _classPrivateFieldLooseBase(fn().Foo, _self)[_self]).getSelf)?.call(_classPrivateFieldLoo4)?.self) === null || _call$self2 === void 0 ? void 0 : _classPrivateFieldLooseBase(_call$self2, _x)[_x]; + (_getSelf$self3 = (fn === null || fn === void 0 ? void 0 : _classPrivateFieldLooseBase(fn().Foo, _self)[_self])?.getSelf()?.self) === null || _getSelf$self3 === void 0 ? void 0 : _classPrivateFieldLooseBase(_getSelf$self3, _x)[_x]; + (_getSelf$self4 = (fn === null || fn === void 0 ? void 0 : _classPrivateFieldLooseBase(fn().Foo, _self)[_self])?.getSelf?.()?.self) === null || _getSelf$self4 === void 0 ? void 0 : _classPrivateFieldLooseBase(_getSelf$self4, _x)[_x]; + } + +} + +var _x = _classPrivateFieldLooseKey("x"); + +var _self = _classPrivateFieldLooseKey("self"); + +Object.defineProperty(Foo, _x, { + writable: true, + value: 1 +}); +Object.defineProperty(Foo, _self, { + writable: true, + value: Foo +}); +Foo.self = Foo; +Foo.test(); From 970a5a16a8dce41f5bb752f4c6ad524a7050a518 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hu=C3=A1ng=20J=C3=B9nli=C3=A0ng?= Date: Mon, 25 May 2020 14:51:40 -0400 Subject: [PATCH 18/20] nit: .call is always computed: false --- .../babel-helper-member-expression-to-functions/src/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 48f23fb3bb46..5bc7a85df623 100644 --- a/packages/babel-helper-member-expression-to-functions/src/index.js +++ b/packages/babel-helper-member-expression-to-functions/src/index.js @@ -231,7 +231,7 @@ const handle = { t.optionalMemberExpression( endParent.callee, t.identifier("call"), - endParent.computed, + false, true, ), [context, ...endParent.arguments], From 08160d84b0f11498519696a06c09587e1818189d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hu=C3=A1ng=20J=C3=B9nli=C3=A0ng?= Date: Tue, 26 May 2020 11:58:04 -0400 Subject: [PATCH 19/20] fix: avoid reuse ast node --- .../src/index.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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 5bc7a85df623..67d3621debc6 100644 --- a/packages/babel-helper-member-expression-to-functions/src/index.js +++ b/packages/babel-helper-member-expression-to-functions/src/index.js @@ -217,7 +217,11 @@ const handle = { : baseRef, t.nullLiteral(), ), - t.binaryExpression("===", baseRef, scope.buildUndefinedNode()), + t.binaryExpression( + "===", + t.cloneNode(baseRef), + scope.buildUndefinedNode(), + ), ), scope.buildUndefinedNode(), regular, From 6c4486f0bd45471de3737019d3184ef8c5af5dca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hu=C3=A1ng=20J=C3=B9nli=C3=A0ng?= Date: Tue, 26 May 2020 13:48:33 -0400 Subject: [PATCH 20/20] fix: throw early error for `delete this?.#x` --- .../babel-parser/src/parser/expression.js | 3 +- .../input.js | 6 ++ .../options.json | 3 + .../output.json | 99 +++++++++++++++++++ 4 files changed, 110 insertions(+), 1 deletion(-) create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-properties/failure-delete-optional-private-property/input.js create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-properties/failure-delete-optional-private-property/options.json create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-properties/failure-delete-optional-private-property/output.json diff --git a/packages/babel-parser/src/parser/expression.js b/packages/babel-parser/src/parser/expression.js index 2135404063c1..43612d9c924c 100644 --- a/packages/babel-parser/src/parser/expression.js +++ b/packages/babel-parser/src/parser/expression.js @@ -502,7 +502,8 @@ export default class ExpressionParser extends LValParser { if (arg.type === "Identifier") { this.raise(node.start, Errors.StrictDelete); } else if ( - arg.type === "MemberExpression" && + (arg.type === "MemberExpression" || + arg.type === "OptionalMemberExpression") && arg.property.type === "PrivateName" ) { this.raise(node.start, Errors.DeletePrivateField); diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-properties/failure-delete-optional-private-property/input.js b/packages/babel-parser/test/fixtures/experimental/class-private-properties/failure-delete-optional-private-property/input.js new file mode 100644 index 000000000000..d555f86d05a1 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-properties/failure-delete-optional-private-property/input.js @@ -0,0 +1,6 @@ +class Foo { + #x; + constructor() { + delete this?.#x; + } +} diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-properties/failure-delete-optional-private-property/options.json b/packages/babel-parser/test/fixtures/experimental/class-private-properties/failure-delete-optional-private-property/options.json new file mode 100644 index 000000000000..f26e916957c8 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-properties/failure-delete-optional-private-property/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["classPrivateProperties"] +} diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-properties/failure-delete-optional-private-property/output.json b/packages/babel-parser/test/fixtures/experimental/class-private-properties/failure-delete-optional-private-property/output.json new file mode 100644 index 000000000000..c616eec20ec0 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-properties/failure-delete-optional-private-property/output.json @@ -0,0 +1,99 @@ +{ + "type": "File", + "start":0,"end":62,"loc":{"start":{"line":1,"column":0},"end":{"line":6,"column":1}}, + "errors": [ + "SyntaxError: Deleting a private field is not allowed (4:4)" + ], + "program": { + "type": "Program", + "start":0,"end":62,"loc":{"start":{"line":1,"column":0},"end":{"line":6,"column":1}}, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ClassDeclaration", + "start":0,"end":62,"loc":{"start":{"line":1,"column":0},"end":{"line":6,"column":1}}, + "id": { + "type": "Identifier", + "start":6,"end":9,"loc":{"start":{"line":1,"column":6},"end":{"line":1,"column":9},"identifierName":"Foo"}, + "name": "Foo" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start":10,"end":62,"loc":{"start":{"line":1,"column":10},"end":{"line":6,"column":1}}, + "body": [ + { + "type": "ClassPrivateProperty", + "start":14,"end":17,"loc":{"start":{"line":2,"column":2},"end":{"line":2,"column":5}}, + "static": false, + "key": { + "type": "PrivateName", + "start":14,"end":16,"loc":{"start":{"line":2,"column":2},"end":{"line":2,"column":4}}, + "id": { + "type": "Identifier", + "start":15,"end":16,"loc":{"start":{"line":2,"column":3},"end":{"line":2,"column":4},"identifierName":"x"}, + "name": "x" + } + }, + "value": null + }, + { + "type": "ClassMethod", + "start":20,"end":60,"loc":{"start":{"line":3,"column":2},"end":{"line":5,"column":3}}, + "static": false, + "key": { + "type": "Identifier", + "start":20,"end":31,"loc":{"start":{"line":3,"column":2},"end":{"line":3,"column":13},"identifierName":"constructor"}, + "name": "constructor" + }, + "computed": false, + "kind": "constructor", + "id": null, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start":34,"end":60,"loc":{"start":{"line":3,"column":16},"end":{"line":5,"column":3}}, + "body": [ + { + "type": "ExpressionStatement", + "start":40,"end":56,"loc":{"start":{"line":4,"column":4},"end":{"line":4,"column":20}}, + "expression": { + "type": "UnaryExpression", + "start":40,"end":55,"loc":{"start":{"line":4,"column":4},"end":{"line":4,"column":19}}, + "operator": "delete", + "prefix": true, + "argument": { + "type": "OptionalMemberExpression", + "start":47,"end":55,"loc":{"start":{"line":4,"column":11},"end":{"line":4,"column":19}}, + "object": { + "type": "ThisExpression", + "start":47,"end":51,"loc":{"start":{"line":4,"column":11},"end":{"line":4,"column":15}} + }, + "property": { + "type": "PrivateName", + "start":53,"end":55,"loc":{"start":{"line":4,"column":17},"end":{"line":4,"column":19}}, + "id": { + "type": "Identifier", + "start":54,"end":55,"loc":{"start":{"line":4,"column":18},"end":{"line":4,"column":19},"identifierName":"x"}, + "name": "x" + } + }, + "computed": false, + "optional": true + } + } + } + ], + "directives": [] + } + } + ] + } + } + ], + "directives": [] + } +} \ No newline at end of file