diff --git a/src/compiler/transformers/esnext.ts b/src/compiler/transformers/esnext.ts index a138907e236..ab3ecdc9228 100644 --- a/src/compiler/transformers/esnext.ts +++ b/src/compiler/transformers/esnext.ts @@ -58,43 +58,29 @@ namespace ts { return updateParen(node, expression); } - function visitNonOptionalPropertyAccessExpression(node: PropertyAccessExpression, captureThisArg: boolean): Expression { + function visitNonOptionalPropertyOrElementAccessExpression(node: AccessExpression, captureThisArg: boolean): Expression { if (isOptionalChain(node)) { // If `node` is an optional chain, then it is the outermost chain of an optional expression. return visitOptionalExpression(node, captureThisArg); } - let expression = visitNode(node.expression, visitor, isExpression); + let expression: Expression = visitNode(node.expression, visitor, isExpression); Debug.assertNotNode(expression, isSyntheticReference); let thisArg: Expression | undefined; if (captureThisArg) { - // `a.b` -> { expression: `(_a = a).b`, thisArg: `_a` } - thisArg = createTempVariable(hoistVariableDeclaration); - expression = createParen(createAssignment(thisArg, expression)); + if (shouldCaptureInTempVariable(expression)) { + thisArg = createTempVariable(hoistVariableDeclaration); + expression = createAssignment(thisArg, expression); + } + else { + thisArg = expression; + } } - expression = updatePropertyAccess(node, expression, visitNode(node.name, visitor, isIdentifier)); - return thisArg ? createSyntheticReferenceExpression(expression, thisArg) : expression; - } - - function visitNonOptionalElementAccessExpression(node: ElementAccessExpression, captureThisArg: boolean): Expression { - if (isOptionalChain(node)) { - // If `node` is an optional chain, then it is the outermost chain of an optional expression. - return visitOptionalExpression(node, captureThisArg); - } - - let expression = visitNode(node.expression, visitor, isExpression); - Debug.assertNotNode(expression, isSyntheticReference); - - let thisArg: Expression | undefined; - if (captureThisArg) { - // `a[b]` -> { expression: `(_a = a)[b]`, thisArg: `_a` } - thisArg = createTempVariable(hoistVariableDeclaration); - expression = createParen(createAssignment(thisArg, expression)); - } - - expression = updateElementAccess(node, expression, visitNode(node.argumentExpression, visitor, isExpression)); + expression = node.kind === SyntaxKind.PropertyAccessExpression + ? updatePropertyAccess(node, expression, visitNode(node.name, visitor, isIdentifier)) + : updateElementAccess(node, expression, visitNode(node.argumentExpression, visitor, isExpression)); return thisArg ? createSyntheticReferenceExpression(expression, thisArg) : expression; } @@ -109,8 +95,8 @@ namespace ts { function visitNonOptionalExpression(node: Expression, captureThisArg: boolean): Expression { switch (node.kind) { case SyntaxKind.ParenthesizedExpression: return visitNonOptionalParenthesizedExpression(node as ParenthesizedExpression, captureThisArg); - case SyntaxKind.PropertyAccessExpression: return visitNonOptionalPropertyAccessExpression(node as PropertyAccessExpression, captureThisArg); - case SyntaxKind.ElementAccessExpression: return visitNonOptionalElementAccessExpression(node as ElementAccessExpression, captureThisArg); + case SyntaxKind.PropertyAccessExpression: + case SyntaxKind.ElementAccessExpression: return visitNonOptionalPropertyOrElementAccessExpression(node as AccessExpression, captureThisArg); case SyntaxKind.CallExpression: return visitNonOptionalCallExpression(node as CallExpression, captureThisArg); default: return visitNode(node, visitor, isExpression); } @@ -119,39 +105,38 @@ namespace ts { function visitOptionalExpression(node: OptionalChain, captureThisArg: boolean): Expression { const { expression, chain } = flattenChain(node); const left = visitNonOptionalExpression(expression, isCallChain(chain[0])); - const temp = createTempVariable(hoistVariableDeclaration); const leftThisArg = isSyntheticReference(left) ? left.thisArg : undefined; - const leftExpression = isSyntheticReference(left) ? left.expression : left; - let rightExpression: Expression = temp; + let leftExpression = isSyntheticReference(left) ? left.expression : left; + let capturedLeft: Expression = leftExpression; + if (shouldCaptureInTempVariable(leftExpression)) { + capturedLeft = createTempVariable(hoistVariableDeclaration); + leftExpression = createAssignment(capturedLeft, leftExpression); + } + let rightExpression = capturedLeft; let thisArg: Expression | undefined; for (let i = 0; i < chain.length; i++) { const segment = chain[i]; switch (segment.kind) { case SyntaxKind.PropertyAccessExpression: - if (i === chain.length - 1 && captureThisArg) { - thisArg = createTempVariable(hoistVariableDeclaration); - rightExpression = createParen(createAssignment(thisArg, rightExpression)); - } - rightExpression = createPropertyAccess( - rightExpression, - visitNode(segment.name, visitor, isIdentifier) - ); - break; case SyntaxKind.ElementAccessExpression: if (i === chain.length - 1 && captureThisArg) { - thisArg = createTempVariable(hoistVariableDeclaration); - rightExpression = createParen(createAssignment(thisArg, rightExpression)); + if (shouldCaptureInTempVariable(rightExpression)) { + thisArg = createTempVariable(hoistVariableDeclaration); + rightExpression = createAssignment(thisArg, rightExpression); + } + else { + thisArg = rightExpression; + } } - rightExpression = createElementAccess( - rightExpression, - visitNode(segment.argumentExpression, visitor, isExpression) - ); + rightExpression = segment.kind === SyntaxKind.PropertyAccessExpression + ? createPropertyAccess(rightExpression, visitNode(segment.name, visitor, isIdentifier)) + : createElementAccess(rightExpression, visitNode(segment.argumentExpression, visitor, isExpression)); break; case SyntaxKind.CallExpression: if (i === 0 && leftThisArg) { rightExpression = createFunctionCall( rightExpression, - leftThisArg, + leftThisArg.kind === SyntaxKind.SuperKeyword ? createThis() : leftThisArg, visitNodes(segment.arguments, visitor, isExpression) ); } @@ -168,48 +153,49 @@ namespace ts { } const target = createConditional( - createLogicalOr( - createStrictEquality(createAssignment(temp, leftExpression), createNull()), - createStrictEquality(temp, createVoidZero()) - ), + createNotNullCondition(leftExpression, capturedLeft, /*invert*/ true), createVoidZero(), - rightExpression + rightExpression, ); return thisArg ? createSyntheticReferenceExpression(target, thisArg) : target; } - function createNotNullCondition(node: Expression) { + function createNotNullCondition(left: Expression, right: Expression, invert?: boolean) { return createBinary( createBinary( - node, - createToken(SyntaxKind.ExclamationEqualsEqualsToken), + left, + createToken(invert ? SyntaxKind.EqualsEqualsEqualsToken : SyntaxKind.ExclamationEqualsEqualsToken), createNull() ), - createToken(SyntaxKind.AmpersandAmpersandToken), + createToken(invert ? SyntaxKind.BarBarToken : SyntaxKind.AmpersandAmpersandToken), createBinary( - node, - createToken(SyntaxKind.ExclamationEqualsEqualsToken), + right, + createToken(invert ? SyntaxKind.EqualsEqualsEqualsToken : SyntaxKind.ExclamationEqualsEqualsToken), createVoidZero() ) ); } function transformNullishCoalescingExpression(node: BinaryExpression) { - const expressions: Expression[] = []; let left = visitNode(node.left, visitor, isExpression); - if (!isIdentifier(left)) { - const temp = createTempVariable(hoistVariableDeclaration); - expressions.push(createAssignment(temp, left)); - left = temp; + let right = left; + if (shouldCaptureInTempVariable(left)) { + right = createTempVariable(hoistVariableDeclaration); + left = createAssignment(right, left); } - expressions.push( - createParen( - createConditional( - createNotNullCondition(left), - left, - visitNode(node.right, visitor, isExpression))) - ); - return inlineExpressions(expressions); + return createConditional( + createNotNullCondition(left, right), + right, + visitNode(node.right, visitor, isExpression), + ); + } + + function shouldCaptureInTempVariable(expression: Expression): boolean { + // don't capture identifiers and `this` in a temporary variable + // `super` cannot be captured as it's no real variable + return !isIdentifier(expression) && + expression.kind !== SyntaxKind.ThisKeyword && + expression.kind !== SyntaxKind.SuperKeyword; } } } diff --git a/tests/baselines/reference/callChain.2.js b/tests/baselines/reference/callChain.2.js index a44115ef916..89070f41003 100644 --- a/tests/baselines/reference/callChain.2.js +++ b/tests/baselines/reference/callChain.2.js @@ -10,7 +10,7 @@ o3.b?.().c; //// [callChain.2.js] -var _a, _b, _c, _d; -(_a = o1) === null || _a === void 0 ? void 0 : _a(); -(_b = o2) === null || _b === void 0 ? void 0 : _b.b(); -(_d = (_c = o3).b) === null || _d === void 0 ? void 0 : _d.call(_c).c; +var _a; +o1 === null || o1 === void 0 ? void 0 : o1(); +o2 === null || o2 === void 0 ? void 0 : o2.b(); +(_a = o3.b) === null || _a === void 0 ? void 0 : _a.call(o3).c; diff --git a/tests/baselines/reference/callChain.3.js b/tests/baselines/reference/callChain.3.js index 2a6685d0d53..b34458a26e7 100644 --- a/tests/baselines/reference/callChain.3.js +++ b/tests/baselines/reference/callChain.3.js @@ -12,11 +12,11 @@ t1 = a!.m!({x: 12}); //// [callChain.3.js] "use strict"; -var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q; -var n1 = (_c = (_a = a) === null || _a === void 0 ? void 0 : (_b = _a).m) === null || _c === void 0 ? void 0 : _c.call(_b, { x: 12 }); // should be an error (`undefined` is not assignable to `number`) -var n2 = (_f = (_d = a) === null || _d === void 0 ? void 0 : (_e = _d).m) === null || _f === void 0 ? void 0 : _f.call(_e, { x: absorb() }); // likewise -var n3 = (_j = (_g = a) === null || _g === void 0 ? void 0 : (_h = _g).m) === null || _j === void 0 ? void 0 : _j.call(_h, { x: 12 }); // should be ok -var n4 = (_m = (_k = a) === null || _k === void 0 ? void 0 : (_l = _k).m) === null || _m === void 0 ? void 0 : _m.call(_l, { x: absorb() }); // likewise +var _a, _b, _c, _d, _e; +var n1 = (_a = a === null || a === void 0 ? void 0 : a.m) === null || _a === void 0 ? void 0 : _a.call(a, { x: 12 }); // should be an error (`undefined` is not assignable to `number`) +var n2 = (_b = a === null || a === void 0 ? void 0 : a.m) === null || _b === void 0 ? void 0 : _b.call(a, { x: absorb() }); // likewise +var n3 = (_c = a === null || a === void 0 ? void 0 : a.m) === null || _c === void 0 ? void 0 : _c.call(a, { x: 12 }); // should be ok +var n4 = (_d = a === null || a === void 0 ? void 0 : a.m) === null || _d === void 0 ? void 0 : _d.call(a, { x: absorb() }); // likewise // Also a test showing `!` vs `?` for good measure -var t1 = (_q = (_o = a) === null || _o === void 0 ? void 0 : (_p = _o).m) === null || _q === void 0 ? void 0 : _q.call(_p, { x: 12 }); +var t1 = (_e = a === null || a === void 0 ? void 0 : a.m) === null || _e === void 0 ? void 0 : _e.call(a, { x: 12 }); t1 = a.m({ x: 12 }); diff --git a/tests/baselines/reference/callChain.js b/tests/baselines/reference/callChain.js index 439c38e8b83..f67166dcde3 100644 --- a/tests/baselines/reference/callChain.js +++ b/tests/baselines/reference/callChain.js @@ -46,30 +46,30 @@ var __spreadArrays = (this && this.__spreadArrays) || function () { r[k] = a[j]; return r; }; -var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13; -(_a = o1) === null || _a === void 0 ? void 0 : _a(); -(_b = o1) === null || _b === void 0 ? void 0 : _b(1); -(_c = o1) === null || _c === void 0 ? void 0 : _c.apply(void 0, [1, 2]); -(_d = o1) === null || _d === void 0 ? void 0 : _d.apply(void 0, __spreadArrays([1], [2, 3], [4])); -(_e = o2) === null || _e === void 0 ? void 0 : _e.b(); -(_f = o2) === null || _f === void 0 ? void 0 : _f.b(1); -(_g = o2) === null || _g === void 0 ? void 0 : _g.b.apply(_g, [1, 2]); -(_h = o2) === null || _h === void 0 ? void 0 : _h.b.apply(_h, __spreadArrays([1], [2, 3], [4])); -(_j = o2) === null || _j === void 0 ? void 0 : _j["b"](); -(_k = o2) === null || _k === void 0 ? void 0 : _k["b"](1); -(_l = o2) === null || _l === void 0 ? void 0 : _l["b"].apply(_l, [1, 2]); -(_m = o2) === null || _m === void 0 ? void 0 : _m["b"].apply(_m, __spreadArrays([1], [2, 3], [4])); -(_p = (_o = o3).b) === null || _p === void 0 ? void 0 : _p.call(_o).c; -(_r = (_q = o3).b) === null || _r === void 0 ? void 0 : _r.call(_q, 1).c; -(_t = (_s = o3).b) === null || _t === void 0 ? void 0 : _t.call.apply(_t, __spreadArrays([_s], [1, 2])).c; -(_v = (_u = o3).b) === null || _v === void 0 ? void 0 : _v.call.apply(_v, __spreadArrays([_u, 1], [2, 3], [4])).c; -(_x = (_w = o3).b) === null || _x === void 0 ? void 0 : _x.call(_w)["c"]; -(_z = (_y = o3).b) === null || _z === void 0 ? void 0 : _z.call(_y, 1)["c"]; -(_1 = (_0 = o3).b) === null || _1 === void 0 ? void 0 : _1.call.apply(_1, __spreadArrays([_0], [1, 2]))["c"]; -(_3 = (_2 = o3).b) === null || _3 === void 0 ? void 0 : _3.call.apply(_3, __spreadArrays([_2, 1], [2, 3], [4]))["c"]; -(_5 = (_4 = o3)["b"]) === null || _5 === void 0 ? void 0 : _5.call(_4).c; -(_7 = (_6 = o3)["b"]) === null || _7 === void 0 ? void 0 : _7.call(_6, 1).c; -(_9 = (_8 = o3)["b"]) === null || _9 === void 0 ? void 0 : _9.call.apply(_9, __spreadArrays([_8], [1, 2])).c; -(_11 = (_10 = o3)["b"]) === null || _11 === void 0 ? void 0 : _11.call.apply(_11, __spreadArrays([_10, 1], [2, 3], [4])).c; -var v = (_12 = o4) === null || _12 === void 0 ? void 0 : _12(incr); -(_13 = o5()) === null || _13 === void 0 ? void 0 : _13(); +var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o; +o1 === null || o1 === void 0 ? void 0 : o1(); +o1 === null || o1 === void 0 ? void 0 : o1(1); +o1 === null || o1 === void 0 ? void 0 : o1.apply(void 0, [1, 2]); +o1 === null || o1 === void 0 ? void 0 : o1.apply(void 0, __spreadArrays([1], [2, 3], [4])); +o2 === null || o2 === void 0 ? void 0 : o2.b(); +o2 === null || o2 === void 0 ? void 0 : o2.b(1); +o2 === null || o2 === void 0 ? void 0 : o2.b.apply(o2, [1, 2]); +o2 === null || o2 === void 0 ? void 0 : o2.b.apply(o2, __spreadArrays([1], [2, 3], [4])); +o2 === null || o2 === void 0 ? void 0 : o2["b"](); +o2 === null || o2 === void 0 ? void 0 : o2["b"](1); +o2 === null || o2 === void 0 ? void 0 : o2["b"].apply(o2, [1, 2]); +o2 === null || o2 === void 0 ? void 0 : o2["b"].apply(o2, __spreadArrays([1], [2, 3], [4])); +(_a = o3.b) === null || _a === void 0 ? void 0 : _a.call(o3).c; +(_b = o3.b) === null || _b === void 0 ? void 0 : _b.call(o3, 1).c; +(_c = o3.b) === null || _c === void 0 ? void 0 : _c.call.apply(_c, __spreadArrays([o3], [1, 2])).c; +(_d = o3.b) === null || _d === void 0 ? void 0 : _d.call.apply(_d, __spreadArrays([o3, 1], [2, 3], [4])).c; +(_e = o3.b) === null || _e === void 0 ? void 0 : _e.call(o3)["c"]; +(_f = o3.b) === null || _f === void 0 ? void 0 : _f.call(o3, 1)["c"]; +(_g = o3.b) === null || _g === void 0 ? void 0 : _g.call.apply(_g, __spreadArrays([o3], [1, 2]))["c"]; +(_h = o3.b) === null || _h === void 0 ? void 0 : _h.call.apply(_h, __spreadArrays([o3, 1], [2, 3], [4]))["c"]; +(_j = o3["b"]) === null || _j === void 0 ? void 0 : _j.call(o3).c; +(_k = o3["b"]) === null || _k === void 0 ? void 0 : _k.call(o3, 1).c; +(_l = o3["b"]) === null || _l === void 0 ? void 0 : _l.call.apply(_l, __spreadArrays([o3], [1, 2])).c; +(_m = o3["b"]) === null || _m === void 0 ? void 0 : _m.call.apply(_m, __spreadArrays([o3, 1], [2, 3], [4])).c; +var v = o4 === null || o4 === void 0 ? void 0 : o4(incr); +(_o = o5()) === null || _o === void 0 ? void 0 : _o(); diff --git a/tests/baselines/reference/controlFlowNullishCoalesce.js b/tests/baselines/reference/controlFlowNullishCoalesce.js index f49414771d3..75dfcfcc03f 100644 --- a/tests/baselines/reference/controlFlowNullishCoalesce.js +++ b/tests/baselines/reference/controlFlowNullishCoalesce.js @@ -17,9 +17,9 @@ if (x = o ?? true) { "use strict"; // assignments in shortcutting rhs var a; -(o !== null && o !== void 0 ? o : (a = 1)); +o !== null && o !== void 0 ? o : (a = 1); a.toString(); var x; -if (x = (o !== null && o !== void 0 ? o : true)) { +if (x = o !== null && o !== void 0 ? o : true) { x; } diff --git a/tests/baselines/reference/controlFlowOptionalChain.js b/tests/baselines/reference/controlFlowOptionalChain.js index 3bb2bab1c0d..a3ab92334a9 100644 --- a/tests/baselines/reference/controlFlowOptionalChain.js +++ b/tests/baselines/reference/controlFlowOptionalChain.js @@ -530,20 +530,20 @@ function extractCoordinates(f: Feature): number[] { //// [controlFlowOptionalChain.js] "use strict"; -var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10; +var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t; var a; -(_a = o) === null || _a === void 0 ? void 0 : _a[a = 1]; +o === null || o === void 0 ? void 0 : o[a = 1]; a.toString(); var b; -(_b = o) === null || _b === void 0 ? void 0 : _b.x[b = 1]; +o === null || o === void 0 ? void 0 : o.x[b = 1]; b.toString(); var c; -(_c = o) === null || _c === void 0 ? void 0 : _c(c = 1); +o === null || o === void 0 ? void 0 : o(c = 1); c.toString(); var d; -(_d = o) === null || _d === void 0 ? void 0 : _d.x(d = 1); +o === null || o === void 0 ? void 0 : o.x(d = 1); d.toString(); -if ((_e = f) === null || _e === void 0 ? void 0 : _e(x)) { +if (f === null || f === void 0 ? void 0 : f(x)) { x; // number f; // (x: any) => x is number f(x); @@ -556,262 +556,253 @@ else { x; f; f(x); -if ((_f = o2) === null || _f === void 0 ? void 0 : _f.f(x)) { +if (o2 === null || o2 === void 0 ? void 0 : o2.f(x)) { x; // number o2.f; // (x: any) => x is number - (_g = o2) === null || _g === void 0 ? void 0 : _g.f; - (_h = o2) === null || _h === void 0 ? void 0 : _h.f(x); + o2 === null || o2 === void 0 ? void 0 : o2.f; + o2 === null || o2 === void 0 ? void 0 : o2.f(x); } else { x; o2; - (_j = o2) === null || _j === void 0 ? void 0 : _j.f; + o2 === null || o2 === void 0 ? void 0 : o2.f; o2.f; } x; o2; -(_k = o2) === null || _k === void 0 ? void 0 : _k.f; +o2 === null || o2 === void 0 ? void 0 : o2.f; o2.f; -if (((_l = o3) === null || _l === void 0 ? void 0 : _l.x) === 1) { +if ((o3 === null || o3 === void 0 ? void 0 : o3.x) === 1) { o3; o3.x; - (_m = o3) === null || _m === void 0 ? void 0 : _m.x; + o3 === null || o3 === void 0 ? void 0 : o3.x; } else { o3; - (_o = o3) === null || _o === void 0 ? void 0 : _o.x; + o3 === null || o3 === void 0 ? void 0 : o3.x; o3.x; } o3; -(_p = o3) === null || _p === void 0 ? void 0 : _p.x; +o3 === null || o3 === void 0 ? void 0 : o3.x; o3.x; -if ((_q = o4.x) === null || _q === void 0 ? void 0 : _q.y) { +if ((_a = o4.x) === null || _a === void 0 ? void 0 : _a.y) { o4.x; // { y: boolean } o4.x.y; // true - (_r = o4.x) === null || _r === void 0 ? void 0 : _r.y; // true + (_b = o4.x) === null || _b === void 0 ? void 0 : _b.y; // true } else { o4.x; - (_s = o4.x) === null || _s === void 0 ? void 0 : _s.y; + (_c = o4.x) === null || _c === void 0 ? void 0 : _c.y; o4.x.y; } o4.x; -(_t = o4.x) === null || _t === void 0 ? void 0 : _t.y; +(_d = o4.x) === null || _d === void 0 ? void 0 : _d.y; o4.x.y; -if ((_v = (_u = o5.x) === null || _u === void 0 ? void 0 : _u.y.z) === null || _v === void 0 ? void 0 : _v.w) { +if ((_f = (_e = o5.x) === null || _e === void 0 ? void 0 : _e.y.z) === null || _f === void 0 ? void 0 : _f.w) { o5.x; o5.x.y; o5.x.y.z; o5.x.y.z.w; // true - (_w = o5.x.y.z) === null || _w === void 0 ? void 0 : _w.w; // true - (_x = o5.x) === null || _x === void 0 ? void 0 : _x.y.z.w; // true - (_z = (_y = o5.x) === null || _y === void 0 ? void 0 : _y.y.z) === null || _z === void 0 ? void 0 : _z.w; // true + (_g = o5.x.y.z) === null || _g === void 0 ? void 0 : _g.w; // true + (_h = o5.x) === null || _h === void 0 ? void 0 : _h.y.z.w; // true + (_k = (_j = o5.x) === null || _j === void 0 ? void 0 : _j.y.z) === null || _k === void 0 ? void 0 : _k.w; // true } else { o5.x; - (_0 = o5.x) === null || _0 === void 0 ? void 0 : _0.y; - (_1 = o5.x) === null || _1 === void 0 ? void 0 : _1.y.z; - (_3 = (_2 = o5.x) === null || _2 === void 0 ? void 0 : _2.y.z) === null || _3 === void 0 ? void 0 : _3.w; + (_l = o5.x) === null || _l === void 0 ? void 0 : _l.y; + (_m = o5.x) === null || _m === void 0 ? void 0 : _m.y.z; + (_p = (_o = o5.x) === null || _o === void 0 ? void 0 : _o.y.z) === null || _p === void 0 ? void 0 : _p.w; o5.x.y; o5.x.y.z.w; } o5.x; -(_4 = o5.x) === null || _4 === void 0 ? void 0 : _4.y; -(_5 = o5.x) === null || _5 === void 0 ? void 0 : _5.y.z; -(_7 = (_6 = o5.x) === null || _6 === void 0 ? void 0 : _6.y.z) === null || _7 === void 0 ? void 0 : _7.w; +(_q = o5.x) === null || _q === void 0 ? void 0 : _q.y; +(_r = o5.x) === null || _r === void 0 ? void 0 : _r.y.z; +(_t = (_s = o5.x) === null || _s === void 0 ? void 0 : _s.y.z) === null || _t === void 0 ? void 0 : _t.w; o5.x.y; o5.x.y.z.w; -if ((_8 = o6) === null || _8 === void 0 ? void 0 : _8.f()) { +if (o6 === null || o6 === void 0 ? void 0 : o6.f()) { o6; // Derived o6.f; } else { o6; - (_9 = o6) === null || _9 === void 0 ? void 0 : _9.f; + o6 === null || o6 === void 0 ? void 0 : o6.f; o6.f; } o6; -(_10 = o6) === null || _10 === void 0 ? void 0 : _10.f; +o6 === null || o6 === void 0 ? void 0 : o6.f; o6.f; function f01(x) { - var _a, _b, _c, _d; if (!!true) { - (_a = isString) === null || _a === void 0 ? void 0 : _a(x); + isString === null || isString === void 0 ? void 0 : isString(x); x; } if (!!true) { - (_b = maybeIsString) === null || _b === void 0 ? void 0 : _b(x); + maybeIsString === null || maybeIsString === void 0 ? void 0 : maybeIsString(x); x; } if (!!true) { isDefined(maybeIsString); - (_c = maybeIsString) === null || _c === void 0 ? void 0 : _c(x); + maybeIsString === null || maybeIsString === void 0 ? void 0 : maybeIsString(x); x; } if (!!true) { - (_d = maybeNever) === null || _d === void 0 ? void 0 : _d(); + maybeNever === null || maybeNever === void 0 ? void 0 : maybeNever(); x; } } function f10(o, value) { - var _a, _b, _c, _d, _e, _f; - if (((_a = o) === null || _a === void 0 ? void 0 : _a.foo) === value) { + if ((o === null || o === void 0 ? void 0 : o.foo) === value) { o.foo; } - if (((_b = o) === null || _b === void 0 ? void 0 : _b["foo"]) === value) { + if ((o === null || o === void 0 ? void 0 : o["foo"]) === value) { o["foo"]; } - if (((_c = o) === null || _c === void 0 ? void 0 : _c.bar()) === value) { + if ((o === null || o === void 0 ? void 0 : o.bar()) === value) { o.bar; } - if (((_d = o) === null || _d === void 0 ? void 0 : _d.foo) == value) { + if ((o === null || o === void 0 ? void 0 : o.foo) == value) { o.foo; } - if (((_e = o) === null || _e === void 0 ? void 0 : _e["foo"]) == value) { + if ((o === null || o === void 0 ? void 0 : o["foo"]) == value) { o["foo"]; } - if (((_f = o) === null || _f === void 0 ? void 0 : _f.bar()) == value) { + if ((o === null || o === void 0 ? void 0 : o.bar()) == value) { o.bar; } } function f11(o, value) { - var _a, _b, _c, _d, _e, _f; - if (((_a = o) === null || _a === void 0 ? void 0 : _a.foo) === value) { + if ((o === null || o === void 0 ? void 0 : o.foo) === value) { o.foo; } - if (((_b = o) === null || _b === void 0 ? void 0 : _b["foo"]) === value) { + if ((o === null || o === void 0 ? void 0 : o["foo"]) === value) { o["foo"]; } - if (((_c = o) === null || _c === void 0 ? void 0 : _c.bar()) === value) { + if ((o === null || o === void 0 ? void 0 : o.bar()) === value) { o.bar; } - if (((_d = o) === null || _d === void 0 ? void 0 : _d.foo) == value) { + if ((o === null || o === void 0 ? void 0 : o.foo) == value) { o.foo; } - if (((_e = o) === null || _e === void 0 ? void 0 : _e["foo"]) == value) { + if ((o === null || o === void 0 ? void 0 : o["foo"]) == value) { o["foo"]; } - if (((_f = o) === null || _f === void 0 ? void 0 : _f.bar()) == value) { + if ((o === null || o === void 0 ? void 0 : o.bar()) == value) { o.bar; } } function f12(o, value) { - var _a, _b, _c, _d, _e, _f; - if (((_a = o) === null || _a === void 0 ? void 0 : _a.foo) === value) { + if ((o === null || o === void 0 ? void 0 : o.foo) === value) { o.foo; // Error } - if (((_b = o) === null || _b === void 0 ? void 0 : _b["foo"]) === value) { + if ((o === null || o === void 0 ? void 0 : o["foo"]) === value) { o["foo"]; // Error } - if (((_c = o) === null || _c === void 0 ? void 0 : _c.bar()) === value) { + if ((o === null || o === void 0 ? void 0 : o.bar()) === value) { o.bar; // Error } - if (((_d = o) === null || _d === void 0 ? void 0 : _d.foo) == value) { + if ((o === null || o === void 0 ? void 0 : o.foo) == value) { o.foo; // Error } - if (((_e = o) === null || _e === void 0 ? void 0 : _e["foo"]) == value) { + if ((o === null || o === void 0 ? void 0 : o["foo"]) == value) { o["foo"]; // Error } - if (((_f = o) === null || _f === void 0 ? void 0 : _f.bar()) == value) { + if ((o === null || o === void 0 ? void 0 : o.bar()) == value) { o.bar; // Error } } function f12a(o, value) { - var _a, _b, _c, _d, _e, _f; - if (((_a = o) === null || _a === void 0 ? void 0 : _a.foo) === value) { + if ((o === null || o === void 0 ? void 0 : o.foo) === value) { o.foo; } - if (((_b = o) === null || _b === void 0 ? void 0 : _b["foo"]) === value) { + if ((o === null || o === void 0 ? void 0 : o["foo"]) === value) { o["foo"]; } - if (((_c = o) === null || _c === void 0 ? void 0 : _c.bar()) === value) { + if ((o === null || o === void 0 ? void 0 : o.bar()) === value) { o.bar; } - if (((_d = o) === null || _d === void 0 ? void 0 : _d.foo) == value) { + if ((o === null || o === void 0 ? void 0 : o.foo) == value) { o.foo; // Error } - if (((_e = o) === null || _e === void 0 ? void 0 : _e["foo"]) == value) { + if ((o === null || o === void 0 ? void 0 : o["foo"]) == value) { o["foo"]; // Error } - if (((_f = o) === null || _f === void 0 ? void 0 : _f.bar()) == value) { + if ((o === null || o === void 0 ? void 0 : o.bar()) == value) { o.bar; // Error } } function f13(o) { - var _a, _b, _c, _d, _e, _f; - if (((_a = o) === null || _a === void 0 ? void 0 : _a.foo) !== undefined) { + if ((o === null || o === void 0 ? void 0 : o.foo) !== undefined) { o.foo; } - if (((_b = o) === null || _b === void 0 ? void 0 : _b["foo"]) !== undefined) { + if ((o === null || o === void 0 ? void 0 : o["foo"]) !== undefined) { o["foo"]; } - if (((_c = o) === null || _c === void 0 ? void 0 : _c.bar()) !== undefined) { + if ((o === null || o === void 0 ? void 0 : o.bar()) !== undefined) { o.bar; } - if (((_d = o) === null || _d === void 0 ? void 0 : _d.foo) != undefined) { + if ((o === null || o === void 0 ? void 0 : o.foo) != undefined) { o.foo; } - if (((_e = o) === null || _e === void 0 ? void 0 : _e["foo"]) != undefined) { + if ((o === null || o === void 0 ? void 0 : o["foo"]) != undefined) { o["foo"]; } - if (((_f = o) === null || _f === void 0 ? void 0 : _f.bar()) != undefined) { + if ((o === null || o === void 0 ? void 0 : o.bar()) != undefined) { o.bar; } } function f13a(o) { - var _a, _b, _c, _d, _e, _f; - if (((_a = o) === null || _a === void 0 ? void 0 : _a.foo) !== null) { + if ((o === null || o === void 0 ? void 0 : o.foo) !== null) { o.foo; // Error } - if (((_b = o) === null || _b === void 0 ? void 0 : _b["foo"]) !== null) { + if ((o === null || o === void 0 ? void 0 : o["foo"]) !== null) { o["foo"]; // Error } - if (((_c = o) === null || _c === void 0 ? void 0 : _c.bar()) !== null) { + if ((o === null || o === void 0 ? void 0 : o.bar()) !== null) { o.bar; // Error } - if (((_d = o) === null || _d === void 0 ? void 0 : _d.foo) != null) { + if ((o === null || o === void 0 ? void 0 : o.foo) != null) { o.foo; } - if (((_e = o) === null || _e === void 0 ? void 0 : _e["foo"]) != null) { + if ((o === null || o === void 0 ? void 0 : o["foo"]) != null) { o["foo"]; } - if (((_f = o) === null || _f === void 0 ? void 0 : _f.bar()) != null) { + if ((o === null || o === void 0 ? void 0 : o.bar()) != null) { o.bar; } } function f14(o) { - var _a, _b, _c; - if (((_a = o) === null || _a === void 0 ? void 0 : _a.foo) !== undefined) { + if ((o === null || o === void 0 ? void 0 : o.foo) !== undefined) { o.foo; } - if (((_b = o) === null || _b === void 0 ? void 0 : _b["foo"]) !== undefined) { + if ((o === null || o === void 0 ? void 0 : o["foo"]) !== undefined) { o["foo"]; } - if (((_c = o) === null || _c === void 0 ? void 0 : _c.bar()) !== undefined) { + if ((o === null || o === void 0 ? void 0 : o.bar()) !== undefined) { o.bar; } } function f15(o, value) { - var _a, _b, _c, _d; - if (((_a = o) === null || _a === void 0 ? void 0 : _a.foo) === value) { + if ((o === null || o === void 0 ? void 0 : o.foo) === value) { o.foo; } else { o.foo; // Error } - if (((_b = o) === null || _b === void 0 ? void 0 : _b.foo) !== value) { + if ((o === null || o === void 0 ? void 0 : o.foo) !== value) { o.foo; // Error } else { o.foo; } - if (((_c = o) === null || _c === void 0 ? void 0 : _c.foo) == value) { + if ((o === null || o === void 0 ? void 0 : o.foo) == value) { o.foo; } else { o.foo; // Error } - if (((_d = o) === null || _d === void 0 ? void 0 : _d.foo) != value) { + if ((o === null || o === void 0 ? void 0 : o.foo) != value) { o.foo; // Error } else { @@ -819,26 +810,25 @@ function f15(o, value) { } } function f16(o) { - var _a, _b, _c, _d; - if (((_a = o) === null || _a === void 0 ? void 0 : _a.foo) === undefined) { + if ((o === null || o === void 0 ? void 0 : o.foo) === undefined) { o.foo; // Error } else { o.foo; } - if (((_b = o) === null || _b === void 0 ? void 0 : _b.foo) !== undefined) { + if ((o === null || o === void 0 ? void 0 : o.foo) !== undefined) { o.foo; } else { o.foo; // Error } - if (((_c = o) === null || _c === void 0 ? void 0 : _c.foo) == undefined) { + if ((o === null || o === void 0 ? void 0 : o.foo) == undefined) { o.foo; // Error } else { o.foo; } - if (((_d = o) === null || _d === void 0 ? void 0 : _d.foo) != undefined) { + if ((o === null || o === void 0 ? void 0 : o.foo) != undefined) { o.foo; } else { @@ -846,56 +836,53 @@ function f16(o) { } } function f20(o) { - var _a, _b, _c, _d; - if (typeof ((_a = o) === null || _a === void 0 ? void 0 : _a.foo) === "number") { + if (typeof (o === null || o === void 0 ? void 0 : o.foo) === "number") { o.foo; } - if (typeof ((_b = o) === null || _b === void 0 ? void 0 : _b["foo"]) === "number") { + if (typeof (o === null || o === void 0 ? void 0 : o["foo"]) === "number") { o["foo"]; } - if (typeof ((_c = o) === null || _c === void 0 ? void 0 : _c.bar()) === "number") { + if (typeof (o === null || o === void 0 ? void 0 : o.bar()) === "number") { o.bar; } - if (((_d = o) === null || _d === void 0 ? void 0 : _d.baz) instanceof Error) { + if ((o === null || o === void 0 ? void 0 : o.baz) instanceof Error) { o.baz; } } function f21(o) { - var _a, _b, _c, _d; - if (typeof ((_a = o) === null || _a === void 0 ? void 0 : _a.foo) === "number") { + if (typeof (o === null || o === void 0 ? void 0 : o.foo) === "number") { o.foo; } - if (typeof ((_b = o) === null || _b === void 0 ? void 0 : _b["foo"]) === "number") { + if (typeof (o === null || o === void 0 ? void 0 : o["foo"]) === "number") { o["foo"]; } - if (typeof ((_c = o) === null || _c === void 0 ? void 0 : _c.bar()) === "number") { + if (typeof (o === null || o === void 0 ? void 0 : o.bar()) === "number") { o.bar; } - if (((_d = o) === null || _d === void 0 ? void 0 : _d.baz) instanceof Error) { + if ((o === null || o === void 0 ? void 0 : o.baz) instanceof Error) { o.baz; } } function f22(o) { - var _a, _b, _c, _d; - if (typeof ((_a = o) === null || _a === void 0 ? void 0 : _a.foo) === "number") { + if (typeof (o === null || o === void 0 ? void 0 : o.foo) === "number") { o.foo; } else { o.foo; // Error } - if (typeof ((_b = o) === null || _b === void 0 ? void 0 : _b.foo) !== "number") { + if (typeof (o === null || o === void 0 ? void 0 : o.foo) !== "number") { o.foo; // Error } else { o.foo; } - if (typeof ((_c = o) === null || _c === void 0 ? void 0 : _c.foo) == "number") { + if (typeof (o === null || o === void 0 ? void 0 : o.foo) == "number") { o.foo; } else { o.foo; // Error } - if (typeof ((_d = o) === null || _d === void 0 ? void 0 : _d.foo) != "number") { + if (typeof (o === null || o === void 0 ? void 0 : o.foo) != "number") { o.foo; // Error } else { @@ -903,26 +890,25 @@ function f22(o) { } } function f23(o) { - var _a, _b, _c, _d; - if (typeof ((_a = o) === null || _a === void 0 ? void 0 : _a.foo) === "undefined") { + if (typeof (o === null || o === void 0 ? void 0 : o.foo) === "undefined") { o.foo; // Error } else { o.foo; } - if (typeof ((_b = o) === null || _b === void 0 ? void 0 : _b.foo) !== "undefined") { + if (typeof (o === null || o === void 0 ? void 0 : o.foo) !== "undefined") { o.foo; } else { o.foo; // Error } - if (typeof ((_c = o) === null || _c === void 0 ? void 0 : _c.foo) == "undefined") { + if (typeof (o === null || o === void 0 ? void 0 : o.foo) == "undefined") { o.foo; // Error } else { o.foo; } - if (typeof ((_d = o) === null || _d === void 0 ? void 0 : _d.foo) != "undefined") { + if (typeof (o === null || o === void 0 ? void 0 : o.foo) != "undefined") { o.foo; } else { @@ -930,27 +916,25 @@ function f23(o) { } } function f30(o) { - var _a, _b, _c, _d; if (!!true) { - assert((_a = o) === null || _a === void 0 ? void 0 : _a.foo); + assert(o === null || o === void 0 ? void 0 : o.foo); o.foo; } if (!!true) { - assert(((_b = o) === null || _b === void 0 ? void 0 : _b.foo) === 42); + assert((o === null || o === void 0 ? void 0 : o.foo) === 42); o.foo; } if (!!true) { - assert(typeof ((_c = o) === null || _c === void 0 ? void 0 : _c.foo) === "number"); + assert(typeof (o === null || o === void 0 ? void 0 : o.foo) === "number"); o.foo; } if (!!true) { - assertNonNull((_d = o) === null || _d === void 0 ? void 0 : _d.foo); + assertNonNull(o === null || o === void 0 ? void 0 : o.foo); o.foo; } } function f40(o) { - var _a; - switch ((_a = o) === null || _a === void 0 ? void 0 : _a.foo) { + switch (o === null || o === void 0 ? void 0 : o.foo) { case "abc": o.foo; break; @@ -966,8 +950,7 @@ function f40(o) { } } function f41(o) { - var _a; - switch (typeof ((_a = o) === null || _a === void 0 ? void 0 : _a.foo)) { + switch (typeof (o === null || o === void 0 ? void 0 : o.foo)) { case "string": o.foo; break; @@ -983,8 +966,7 @@ function f41(o) { } } function getArea(shape) { - var _a; - switch ((_a = shape) === null || _a === void 0 ? void 0 : _a.type) { + switch (shape === null || shape === void 0 ? void 0 : shape.type) { case 'circle': return Math.PI * Math.pow(shape.radius, 2); case 'rectangle': diff --git a/tests/baselines/reference/elementAccessChain.2.js b/tests/baselines/reference/elementAccessChain.2.js index 4212e5a20b1..5683b736dc3 100644 --- a/tests/baselines/reference/elementAccessChain.2.js +++ b/tests/baselines/reference/elementAccessChain.2.js @@ -12,9 +12,9 @@ o3.b?.["c"]; //// [elementAccessChain.2.js] -var _a, _b, _c, _d, _e; -(_a = o1) === null || _a === void 0 ? void 0 : _a["b"]; -(_b = o2) === null || _b === void 0 ? void 0 : _b["b"].c; -(_c = o2) === null || _c === void 0 ? void 0 : _c.b["c"]; -(_d = o3["b"]) === null || _d === void 0 ? void 0 : _d.c; -(_e = o3.b) === null || _e === void 0 ? void 0 : _e["c"]; +var _a, _b; +o1 === null || o1 === void 0 ? void 0 : o1["b"]; +o2 === null || o2 === void 0 ? void 0 : o2["b"].c; +o2 === null || o2 === void 0 ? void 0 : o2.b["c"]; +(_a = o3["b"]) === null || _a === void 0 ? void 0 : _a.c; +(_b = o3.b) === null || _b === void 0 ? void 0 : _b["c"]; diff --git a/tests/baselines/reference/elementAccessChain.3.js b/tests/baselines/reference/elementAccessChain.3.js index 4d0dd250157..53e002ef3bf 100644 --- a/tests/baselines/reference/elementAccessChain.3.js +++ b/tests/baselines/reference/elementAccessChain.3.js @@ -42,34 +42,33 @@ var __rest = (this && this.__rest) || function (s, e) { } return t; }; -var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x; -((_a = obj) === null || _a === void 0 ? void 0 : _a["a"])++; -((_b = obj) === null || _b === void 0 ? void 0 : _b.a["b"])++; -((_c = obj) === null || _c === void 0 ? void 0 : _c["a"])--; -((_d = obj) === null || _d === void 0 ? void 0 : _d.a["b"])--; -++((_e = obj) === null || _e === void 0 ? void 0 : _e["a"]); -++((_f = obj) === null || _f === void 0 ? void 0 : _f.a["b"]); ---((_g = obj) === null || _g === void 0 ? void 0 : _g["a"]); ---((_h = obj) === null || _h === void 0 ? void 0 : _h.a["b"]); -(_j = obj) === null || _j === void 0 ? void 0 : _j["a"] = 1; -(_k = obj) === null || _k === void 0 ? void 0 : _k.a["b"] = 1; -(_l = obj) === null || _l === void 0 ? void 0 : _l["a"] += 1; -(_m = obj) === null || _m === void 0 ? void 0 : _m.a["b"] += 1; -for ((_o = obj) === null || _o === void 0 ? void 0 : _o["a"] in {}) +(obj === null || obj === void 0 ? void 0 : obj["a"])++; +(obj === null || obj === void 0 ? void 0 : obj.a["b"])++; +(obj === null || obj === void 0 ? void 0 : obj["a"])--; +(obj === null || obj === void 0 ? void 0 : obj.a["b"])--; +++(obj === null || obj === void 0 ? void 0 : obj["a"]); +++(obj === null || obj === void 0 ? void 0 : obj.a["b"]); +--(obj === null || obj === void 0 ? void 0 : obj["a"]); +--(obj === null || obj === void 0 ? void 0 : obj.a["b"]); +obj === null || obj === void 0 ? void 0 : obj["a"] = 1; +obj === null || obj === void 0 ? void 0 : obj.a["b"] = 1; +obj === null || obj === void 0 ? void 0 : obj["a"] += 1; +obj === null || obj === void 0 ? void 0 : obj.a["b"] += 1; +for (obj === null || obj === void 0 ? void 0 : obj["a"] in {}) ; -for ((_p = obj) === null || _p === void 0 ? void 0 : _p.a["b"] in {}) +for (obj === null || obj === void 0 ? void 0 : obj.a["b"] in {}) ; -for (var _i = 0, _y = []; _i < _y.length; _i++) { - (_q = obj) === null || _q === void 0 ? void 0 : _q["a"] = _y[_i]; +for (var _i = 0, _a = []; _i < _a.length; _i++) { + obj === null || obj === void 0 ? void 0 : obj["a"] = _a[_i]; ; } -for (var _z = 0, _0 = []; _z < _0.length; _z++) { - (_r = obj) === null || _r === void 0 ? void 0 : _r.a["b"] = _0[_z]; +for (var _b = 0, _c = []; _b < _c.length; _b++) { + obj === null || obj === void 0 ? void 0 : obj.a["b"] = _c[_b]; ; } -((_s = obj) === null || _s === void 0 ? void 0 : _s["a"] = { a: 1 }.a); -((_t = obj) === null || _t === void 0 ? void 0 : _t.a["b"] = { a: 1 }.a); -((_u = obj) === null || _u === void 0 ? void 0 : _u["a"] = __rest({ a: 1 }, [])); -((_v = obj) === null || _v === void 0 ? void 0 : _v.a["b"] = __rest({ a: 1 }, [])); -(_w = obj) === null || _w === void 0 ? void 0 : _w["a"] = [].slice(0); -(_x = obj) === null || _x === void 0 ? void 0 : _x.a["b"] = [].slice(0); +(obj === null || obj === void 0 ? void 0 : obj["a"] = { a: 1 }.a); +(obj === null || obj === void 0 ? void 0 : obj.a["b"] = { a: 1 }.a); +(obj === null || obj === void 0 ? void 0 : obj["a"] = __rest({ a: 1 }, [])); +(obj === null || obj === void 0 ? void 0 : obj.a["b"] = __rest({ a: 1 }, [])); +obj === null || obj === void 0 ? void 0 : obj["a"] = [].slice(0); +obj === null || obj === void 0 ? void 0 : obj.a["b"] = [].slice(0); diff --git a/tests/baselines/reference/elementAccessChain.js b/tests/baselines/reference/elementAccessChain.js index e01480eb68b..5dd4e79b918 100644 --- a/tests/baselines/reference/elementAccessChain.js +++ b/tests/baselines/reference/elementAccessChain.js @@ -26,16 +26,16 @@ o6()?.["x"]; //// [elementAccessChain.js] "use strict"; -var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x; -(_a = o1) === null || _a === void 0 ? void 0 : _a["b"]; -(_b = o2) === null || _b === void 0 ? void 0 : _b["b"].c; -(_c = o2) === null || _c === void 0 ? void 0 : _c.b["c"]; -(_d = o3["b"]) === null || _d === void 0 ? void 0 : _d.c; -(_e = o3.b) === null || _e === void 0 ? void 0 : _e["c"]; -(_g = (_f = o4.b) === null || _f === void 0 ? void 0 : _f["c"].d) === null || _g === void 0 ? void 0 : _g.e; -(_j = (_h = o4.b) === null || _h === void 0 ? void 0 : _h["c"].d) === null || _j === void 0 ? void 0 : _j["e"]; -(_m = (_l = (_k = o5).b) === null || _l === void 0 ? void 0 : _l.call(_k)["c"].d) === null || _m === void 0 ? void 0 : _m.e; -(_q = (_p = (_o = o5).b) === null || _p === void 0 ? void 0 : _p.call(_o)["c"].d) === null || _q === void 0 ? void 0 : _q["e"]; -(_t = (_s = (_r = o5)["b"]) === null || _s === void 0 ? void 0 : _s.call(_r)["c"].d) === null || _t === void 0 ? void 0 : _t.e; -(_w = (_v = (_u = o5)["b"]) === null || _v === void 0 ? void 0 : _v.call(_u)["c"].d) === null || _w === void 0 ? void 0 : _w["e"]; -(_x = o6()) === null || _x === void 0 ? void 0 : _x["x"]; +var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q; +o1 === null || o1 === void 0 ? void 0 : o1["b"]; +o2 === null || o2 === void 0 ? void 0 : o2["b"].c; +o2 === null || o2 === void 0 ? void 0 : o2.b["c"]; +(_a = o3["b"]) === null || _a === void 0 ? void 0 : _a.c; +(_b = o3.b) === null || _b === void 0 ? void 0 : _b["c"]; +(_d = (_c = o4.b) === null || _c === void 0 ? void 0 : _c["c"].d) === null || _d === void 0 ? void 0 : _d.e; +(_f = (_e = o4.b) === null || _e === void 0 ? void 0 : _e["c"].d) === null || _f === void 0 ? void 0 : _f["e"]; +(_h = (_g = o5.b) === null || _g === void 0 ? void 0 : _g.call(o5)["c"].d) === null || _h === void 0 ? void 0 : _h.e; +(_k = (_j = o5.b) === null || _j === void 0 ? void 0 : _j.call(o5)["c"].d) === null || _k === void 0 ? void 0 : _k["e"]; +(_m = (_l = o5["b"]) === null || _l === void 0 ? void 0 : _l.call(o5)["c"].d) === null || _m === void 0 ? void 0 : _m.e; +(_p = (_o = o5["b"]) === null || _o === void 0 ? void 0 : _o.call(o5)["c"].d) === null || _p === void 0 ? void 0 : _p["e"]; +(_q = o6()) === null || _q === void 0 ? void 0 : _q["x"]; diff --git a/tests/baselines/reference/exhaustiveSwitchStatements1.js b/tests/baselines/reference/exhaustiveSwitchStatements1.js index e2287cd4f81..d172b00b847 100644 --- a/tests/baselines/reference/exhaustiveSwitchStatements1.js +++ b/tests/baselines/reference/exhaustiveSwitchStatements1.js @@ -428,8 +428,8 @@ var Animal; Animal[Animal["CAT"] = 1] = "CAT"; })(Animal || (Animal = {})); function expression() { - var _a, _b; - switch ((_b = (_a = zoo) === null || _a === void 0 ? void 0 : _a.animal, (_b !== null && _b !== void 0 ? _b : Animal.DOG))) { + var _a; + switch ((_a = zoo === null || zoo === void 0 ? void 0 : zoo.animal) !== null && _a !== void 0 ? _a : Animal.DOG) { case Animal.DOG: return Animal.DOG; case Animal.CAT: return Animal.CAT; } diff --git a/tests/baselines/reference/nullishCoalescingOperator1.js b/tests/baselines/reference/nullishCoalescingOperator1.js index 9b857a1473d..c138222970c 100644 --- a/tests/baselines/reference/nullishCoalescingOperator1.js +++ b/tests/baselines/reference/nullishCoalescingOperator1.js @@ -68,33 +68,33 @@ else { //// [nullishCoalescingOperator1.js] "use strict"; var _a; -var aa1 = (a1 !== null && a1 !== void 0 ? a1 : 'whatever'); -var aa2 = (a2 !== null && a2 !== void 0 ? a2 : 'whatever'); -var aa3 = (a3 !== null && a3 !== void 0 ? a3 : 'whatever'); -var aa4 = (a4 !== null && a4 !== void 0 ? a4 : 'whatever'); -var bb1 = (b1 !== null && b1 !== void 0 ? b1 : 1); -var bb2 = (b2 !== null && b2 !== void 0 ? b2 : 1); -var bb3 = (b3 !== null && b3 !== void 0 ? b3 : 1); -var bb4 = (b4 !== null && b4 !== void 0 ? b4 : 1); -var cc1 = (c1 !== null && c1 !== void 0 ? c1 : true); -var cc2 = (c2 !== null && c2 !== void 0 ? c2 : true); -var cc3 = (c3 !== null && c3 !== void 0 ? c3 : true); -var cc4 = (c4 !== null && c4 !== void 0 ? c4 : true); -var dd1 = (d1 !== null && d1 !== void 0 ? d1 : { b: 1 }); -var dd2 = (d2 !== null && d2 !== void 0 ? d2 : { b: 1 }); -var dd3 = (d3 !== null && d3 !== void 0 ? d3 : { b: 1 }); -var dd4 = (d4 !== null && d4 !== void 0 ? d4 : { b: 1 }); +var aa1 = a1 !== null && a1 !== void 0 ? a1 : 'whatever'; +var aa2 = a2 !== null && a2 !== void 0 ? a2 : 'whatever'; +var aa3 = a3 !== null && a3 !== void 0 ? a3 : 'whatever'; +var aa4 = a4 !== null && a4 !== void 0 ? a4 : 'whatever'; +var bb1 = b1 !== null && b1 !== void 0 ? b1 : 1; +var bb2 = b2 !== null && b2 !== void 0 ? b2 : 1; +var bb3 = b3 !== null && b3 !== void 0 ? b3 : 1; +var bb4 = b4 !== null && b4 !== void 0 ? b4 : 1; +var cc1 = c1 !== null && c1 !== void 0 ? c1 : true; +var cc2 = c2 !== null && c2 !== void 0 ? c2 : true; +var cc3 = c3 !== null && c3 !== void 0 ? c3 : true; +var cc4 = c4 !== null && c4 !== void 0 ? c4 : true; +var dd1 = d1 !== null && d1 !== void 0 ? d1 : { b: 1 }; +var dd2 = d2 !== null && d2 !== void 0 ? d2 : { b: 1 }; +var dd3 = d3 !== null && d3 !== void 0 ? d3 : { b: 1 }; +var dd4 = d4 !== null && d4 !== void 0 ? d4 : { b: 1 }; var maybeBool = false; -if (!((maybeBool !== null && maybeBool !== void 0 ? maybeBool : true))) { +if (!(maybeBool !== null && maybeBool !== void 0 ? maybeBool : true)) { foo(); } -if ((maybeBool !== null && maybeBool !== void 0 ? maybeBool : true)) { +if (maybeBool !== null && maybeBool !== void 0 ? maybeBool : true) { foo(); } else { foo(); } -if (_a = false, (_a !== null && _a !== void 0 ? _a : true)) { +if ((_a = false) !== null && _a !== void 0 ? _a : true) { foo(); } else { diff --git a/tests/baselines/reference/nullishCoalescingOperator10.js b/tests/baselines/reference/nullishCoalescingOperator10.js index 60556609fb5..d68dea5e960 100644 --- a/tests/baselines/reference/nullishCoalescingOperator10.js +++ b/tests/baselines/reference/nullishCoalescingOperator10.js @@ -8,4 +8,4 @@ let gg = f() ?? 'foo' //// [nullishCoalescingOperator10.js] "use strict"; var _a; -var gg = (_a = f(), (_a !== null && _a !== void 0 ? _a : 'foo')); +var gg = (_a = f()) !== null && _a !== void 0 ? _a : 'foo'; diff --git a/tests/baselines/reference/nullishCoalescingOperator11.js b/tests/baselines/reference/nullishCoalescingOperator11.js index c716d1ce88b..fbe6db295d9 100644 --- a/tests/baselines/reference/nullishCoalescingOperator11.js +++ b/tests/baselines/reference/nullishCoalescingOperator11.js @@ -8,4 +8,4 @@ let g11 = f11 ?? f11.toFixed() //// [nullishCoalescingOperator11.js] "use strict"; -var g11 = (f11 !== null && f11 !== void 0 ? f11 : f11.toFixed()); +var g11 = f11 !== null && f11 !== void 0 ? f11 : f11.toFixed(); diff --git a/tests/baselines/reference/nullishCoalescingOperator12.js b/tests/baselines/reference/nullishCoalescingOperator12.js index f648af8e0b7..4e59366d899 100644 --- a/tests/baselines/reference/nullishCoalescingOperator12.js +++ b/tests/baselines/reference/nullishCoalescingOperator12.js @@ -5,6 +5,6 @@ for (const i of obj?.arr ?? []) { } //// [nullishCoalescingOperator12.js] "use strict"; -var _a, _b; +var _a; const obj = { arr: [] }; -for (const i of (_b = (_a = obj) === null || _a === void 0 ? void 0 : _a.arr, (_b !== null && _b !== void 0 ? _b : []))) { } +for (const i of (_a = obj === null || obj === void 0 ? void 0 : obj.arr) !== null && _a !== void 0 ? _a : []) { } diff --git a/tests/baselines/reference/nullishCoalescingOperator2.js b/tests/baselines/reference/nullishCoalescingOperator2.js index e36a526c048..ee54c55b53b 100644 --- a/tests/baselines/reference/nullishCoalescingOperator2.js +++ b/tests/baselines/reference/nullishCoalescingOperator2.js @@ -22,12 +22,12 @@ const aa9 = a9 ?? 'whatever' //// [nullishCoalescingOperator2.js] "use strict"; -var aa1 = (a1 !== null && a1 !== void 0 ? a1 : 'whatever'); -var aa2 = (a2 !== null && a2 !== void 0 ? a2 : 'whatever'); -var aa3 = (a3 !== null && a3 !== void 0 ? a3 : 'whatever'); -var aa4 = (a4 !== null && a4 !== void 0 ? a4 : 'whatever'); -var aa5 = (a5 !== null && a5 !== void 0 ? a5 : 'whatever'); -var aa6 = (a6 !== null && a6 !== void 0 ? a6 : 'whatever'); -var aa7 = (a7 !== null && a7 !== void 0 ? a7 : 'whatever'); -var aa8 = (a8 !== null && a8 !== void 0 ? a8 : 'whatever'); -var aa9 = (a9 !== null && a9 !== void 0 ? a9 : 'whatever'); +var aa1 = a1 !== null && a1 !== void 0 ? a1 : 'whatever'; +var aa2 = a2 !== null && a2 !== void 0 ? a2 : 'whatever'; +var aa3 = a3 !== null && a3 !== void 0 ? a3 : 'whatever'; +var aa4 = a4 !== null && a4 !== void 0 ? a4 : 'whatever'; +var aa5 = a5 !== null && a5 !== void 0 ? a5 : 'whatever'; +var aa6 = a6 !== null && a6 !== void 0 ? a6 : 'whatever'; +var aa7 = a7 !== null && a7 !== void 0 ? a7 : 'whatever'; +var aa8 = a8 !== null && a8 !== void 0 ? a8 : 'whatever'; +var aa9 = a9 !== null && a9 !== void 0 ? a9 : 'whatever'; diff --git a/tests/baselines/reference/nullishCoalescingOperator3.js b/tests/baselines/reference/nullishCoalescingOperator3.js index c0f56552433..d444afaf591 100644 --- a/tests/baselines/reference/nullishCoalescingOperator3.js +++ b/tests/baselines/reference/nullishCoalescingOperator3.js @@ -13,4 +13,4 @@ const aa1 = a1 ?? a2 ?? a3 ?? a4 ?? a5 ?? a6 ?? 'whatever' //// [nullishCoalescingOperator3.js] "use strict"; var _a, _b, _c, _d, _e; -var aa1 = (_e = (_d = (_c = (_b = (_a = (a1 !== null && a1 !== void 0 ? a1 : a2), (_a !== null && _a !== void 0 ? _a : a3)), (_b !== null && _b !== void 0 ? _b : a4)), (_c !== null && _c !== void 0 ? _c : a5)), (_d !== null && _d !== void 0 ? _d : a6)), (_e !== null && _e !== void 0 ? _e : 'whatever')); +var aa1 = (_e = (_d = (_c = (_b = (_a = a1 !== null && a1 !== void 0 ? a1 : a2) !== null && _a !== void 0 ? _a : a3) !== null && _b !== void 0 ? _b : a4) !== null && _c !== void 0 ? _c : a5) !== null && _d !== void 0 ? _d : a6) !== null && _e !== void 0 ? _e : 'whatever'; diff --git a/tests/baselines/reference/nullishCoalescingOperator4.js b/tests/baselines/reference/nullishCoalescingOperator4.js index 0018a3880cf..e580f24ce98 100644 --- a/tests/baselines/reference/nullishCoalescingOperator4.js +++ b/tests/baselines/reference/nullishCoalescingOperator4.js @@ -6,5 +6,5 @@ const aa2 = a1 || a1.toLocaleUpperCase() //// [nullishCoalescingOperator4.js] "use strict"; -var aa1 = (a1 !== null && a1 !== void 0 ? a1 : a1.toLowerCase()); +var aa1 = a1 !== null && a1 !== void 0 ? a1 : a1.toLowerCase(); var aa2 = a1 || a1.toLocaleUpperCase(); diff --git a/tests/baselines/reference/nullishCoalescingOperator5.js b/tests/baselines/reference/nullishCoalescingOperator5.js index c74f3da0827..ff739639cac 100644 --- a/tests/baselines/reference/nullishCoalescingOperator5.js +++ b/tests/baselines/reference/nullishCoalescingOperator5.js @@ -44,26 +44,26 @@ a && (b ?? c); "use strict"; var _a, _b, _c, _d; // should be a syntax error -(a !== null && a !== void 0 ? a : b || c); +a !== null && a !== void 0 ? a : b || c; // should be a syntax error -_a = a || b, (_a !== null && _a !== void 0 ? _a : c); +(_a = a || b) !== null && _a !== void 0 ? _a : c; // should be a syntax error -(a !== null && a !== void 0 ? a : b && c); +a !== null && a !== void 0 ? a : b && c; // should be a syntax error -_b = a && b, (_b !== null && _b !== void 0 ? _b : c); +(_b = a && b) !== null && _b !== void 0 ? _b : c; // Valid according to spec -(a !== null && a !== void 0 ? a : (b || c)); +a !== null && a !== void 0 ? a : (b || c); // Valid according to spec -((a !== null && a !== void 0 ? a : b)) || c; +(a !== null && a !== void 0 ? a : b) || c; // Valid according to spec -_c = (a || b), (_c !== null && _c !== void 0 ? _c : c); +(_c = (a || b)) !== null && _c !== void 0 ? _c : c; // Valid according to spec -a || ((b !== null && b !== void 0 ? b : c)); +a || (b !== null && b !== void 0 ? b : c); // Valid according to spec -(a !== null && a !== void 0 ? a : (b && c)); +a !== null && a !== void 0 ? a : (b && c); // Valid according to spec -((a !== null && a !== void 0 ? a : b)) && c; +(a !== null && a !== void 0 ? a : b) && c; // Valid according to spec -_d = (a && b), (_d !== null && _d !== void 0 ? _d : c); +(_d = (a && b)) !== null && _d !== void 0 ? _d : c; // Valid according to spec -a && ((b !== null && b !== void 0 ? b : c)); +a && (b !== null && b !== void 0 ? b : c); diff --git a/tests/baselines/reference/nullishCoalescingOperator6.js b/tests/baselines/reference/nullishCoalescingOperator6.js index 698ccb311b6..f304a2ed682 100644 --- a/tests/baselines/reference/nullishCoalescingOperator6.js +++ b/tests/baselines/reference/nullishCoalescingOperator6.js @@ -5,5 +5,5 @@ function foo(foo: string, bar = foo ?? "bar") { } //// [nullishCoalescingOperator6.js] "use strict"; function foo(foo, bar) { - if (bar === void 0) { bar = (foo !== null && foo !== void 0 ? foo : "bar"); } + if (bar === void 0) { bar = foo !== null && foo !== void 0 ? foo : "bar"; } } diff --git a/tests/baselines/reference/nullishCoalescingOperator7.js b/tests/baselines/reference/nullishCoalescingOperator7.js index 443ec066ea5..688e0d920d6 100644 --- a/tests/baselines/reference/nullishCoalescingOperator7.js +++ b/tests/baselines/reference/nullishCoalescingOperator7.js @@ -16,7 +16,7 @@ function f () { "use strict"; var foo1 = a ? 1 : 2; var foo2 = (a !== null && a !== void 0 ? a : 'foo') ? 1 : 2; -var foo3 = (a !== null && a !== void 0 ? a : 'foo') ? ((b !== null && b !== void 0 ? b : 'bar')) : ((c !== null && c !== void 0 ? c : 'baz')); +var foo3 = (a !== null && a !== void 0 ? a : 'foo') ? (b !== null && b !== void 0 ? b : 'bar') : (c !== null && c !== void 0 ? c : 'baz'); function f() { - var foo4 = (a !== null && a !== void 0 ? a : 'foo') ? (b !== null && b !== void 0 ? b : 'bar') : (c !== null && c !== void 0 ? c : 'baz'); + var foo4 = (a !== null && a !== void 0 ? a : 'foo') ? b !== null && b !== void 0 ? b : 'bar' : c !== null && c !== void 0 ? c : 'baz'; } diff --git a/tests/baselines/reference/nullishCoalescingOperator8.js b/tests/baselines/reference/nullishCoalescingOperator8.js index 3b56a1de010..3e93fccc179 100644 --- a/tests/baselines/reference/nullishCoalescingOperator8.js +++ b/tests/baselines/reference/nullishCoalescingOperator8.js @@ -10,7 +10,7 @@ const n3 = a.m() ?? b.p ?? b.m() ?? "default";; //// [nullishCoalescingOperator8.js] "use strict"; var _a, _b, _c, _d, _e; -var n1 = (_a = a.p, (_a !== null && _a !== void 0 ? _a : "default")); -var n2 = (_b = a.m(), (_b !== null && _b !== void 0 ? _b : "default")); -var n3 = (_e = (_d = (_c = a.m(), (_c !== null && _c !== void 0 ? _c : b.p)), (_d !== null && _d !== void 0 ? _d : b.m())), (_e !== null && _e !== void 0 ? _e : "default")); +var n1 = (_a = a.p) !== null && _a !== void 0 ? _a : "default"; +var n2 = (_b = a.m()) !== null && _b !== void 0 ? _b : "default"; +var n3 = (_e = (_d = (_c = a.m()) !== null && _c !== void 0 ? _c : b.p) !== null && _d !== void 0 ? _d : b.m()) !== null && _e !== void 0 ? _e : "default"; ; diff --git a/tests/baselines/reference/nullishCoalescingOperator9.js b/tests/baselines/reference/nullishCoalescingOperator9.js index a547d28911a..7f97e10283b 100644 --- a/tests/baselines/reference/nullishCoalescingOperator9.js +++ b/tests/baselines/reference/nullishCoalescingOperator9.js @@ -8,4 +8,4 @@ let gg = f ?? (abc => { void abc.toLowerCase() }) //// [nullishCoalescingOperator9.js] "use strict"; var g = f || (function (abc) { void abc.toLowerCase(); }); -var gg = (f !== null && f !== void 0 ? f : (function (abc) { void abc.toLowerCase(); })); +var gg = f !== null && f !== void 0 ? f : (function (abc) { void abc.toLowerCase(); }); diff --git a/tests/baselines/reference/nullishCoalescingOperator_not_strict.js b/tests/baselines/reference/nullishCoalescingOperator_not_strict.js index e8e6d41291d..bc0336417e1 100644 --- a/tests/baselines/reference/nullishCoalescingOperator_not_strict.js +++ b/tests/baselines/reference/nullishCoalescingOperator_not_strict.js @@ -21,12 +21,12 @@ const aa8 = a8 ?? 'whatever' const aa9 = a9 ?? 'whatever' //// [nullishCoalescingOperator_not_strict.js] -var aa1 = (a1 !== null && a1 !== void 0 ? a1 : 'whatever'); -var aa2 = (a2 !== null && a2 !== void 0 ? a2 : 'whatever'); -var aa3 = (a3 !== null && a3 !== void 0 ? a3 : 'whatever'); -var aa4 = (a4 !== null && a4 !== void 0 ? a4 : 'whatever'); -var aa5 = (a5 !== null && a5 !== void 0 ? a5 : 'whatever'); -var aa6 = (a6 !== null && a6 !== void 0 ? a6 : 'whatever'); -var aa7 = (a7 !== null && a7 !== void 0 ? a7 : 'whatever'); -var aa8 = (a8 !== null && a8 !== void 0 ? a8 : 'whatever'); -var aa9 = (a9 !== null && a9 !== void 0 ? a9 : 'whatever'); +var aa1 = a1 !== null && a1 !== void 0 ? a1 : 'whatever'; +var aa2 = a2 !== null && a2 !== void 0 ? a2 : 'whatever'; +var aa3 = a3 !== null && a3 !== void 0 ? a3 : 'whatever'; +var aa4 = a4 !== null && a4 !== void 0 ? a4 : 'whatever'; +var aa5 = a5 !== null && a5 !== void 0 ? a5 : 'whatever'; +var aa6 = a6 !== null && a6 !== void 0 ? a6 : 'whatever'; +var aa7 = a7 !== null && a7 !== void 0 ? a7 : 'whatever'; +var aa8 = a8 !== null && a8 !== void 0 ? a8 : 'whatever'; +var aa9 = a9 !== null && a9 !== void 0 ? a9 : 'whatever'; diff --git a/tests/baselines/reference/optionalChainingInference.js b/tests/baselines/reference/optionalChainingInference.js index 2f17129d701..ab007fd5448 100644 --- a/tests/baselines/reference/optionalChainingInference.js +++ b/tests/baselines/reference/optionalChainingInference.js @@ -33,20 +33,19 @@ const v8: number = unbox(b8); //// [optionalChainingInference.js] -var _a, _b, _c, _d, _e, _f, _g, _h; -var b1 = { value: (_a = su) === null || _a === void 0 ? void 0 : _a.length }; +var b1 = { value: su === null || su === void 0 ? void 0 : su.length }; var v1 = unbox(b1); -var b2 = { value: (_b = su) === null || _b === void 0 ? void 0 : _b.length }; +var b2 = { value: su === null || su === void 0 ? void 0 : su.length }; var v2 = unbox(b2); -var b3 = { value: (_c = su) === null || _c === void 0 ? void 0 : _c.length }; +var b3 = { value: su === null || su === void 0 ? void 0 : su.length }; var v3 = unbox(b3); -var b4 = { value: (_d = fnu) === null || _d === void 0 ? void 0 : _d() }; +var b4 = { value: fnu === null || fnu === void 0 ? void 0 : fnu() }; var v4 = unbox(b4); -var b5 = { value: (_e = su) === null || _e === void 0 ? void 0 : _e["length"] }; +var b5 = { value: su === null || su === void 0 ? void 0 : su["length"] }; var v5 = unbox(b5); -var b6 = { value: (_f = osu) === null || _f === void 0 ? void 0 : _f.prop.length }; +var b6 = { value: osu === null || osu === void 0 ? void 0 : osu.prop.length }; var v6 = unbox(b6); -var b7 = { value: (_g = osu) === null || _g === void 0 ? void 0 : _g.prop["length"] }; +var b7 = { value: osu === null || osu === void 0 ? void 0 : osu.prop["length"] }; var v7 = unbox(b7); -var b8 = { value: (_h = ofnu) === null || _h === void 0 ? void 0 : _h.prop() }; +var b8 = { value: ofnu === null || ofnu === void 0 ? void 0 : ofnu.prop() }; var v8 = unbox(b8); diff --git a/tests/baselines/reference/propertyAccessChain.2.js b/tests/baselines/reference/propertyAccessChain.2.js index 939e9830b54..870f54c386b 100644 --- a/tests/baselines/reference/propertyAccessChain.2.js +++ b/tests/baselines/reference/propertyAccessChain.2.js @@ -10,7 +10,7 @@ o3.b?.c; //// [propertyAccessChain.2.js] -var _a, _b, _c; -(_a = o1) === null || _a === void 0 ? void 0 : _a.b; -(_b = o2) === null || _b === void 0 ? void 0 : _b.b.c; -(_c = o3.b) === null || _c === void 0 ? void 0 : _c.c; +var _a; +o1 === null || o1 === void 0 ? void 0 : o1.b; +o2 === null || o2 === void 0 ? void 0 : o2.b.c; +(_a = o3.b) === null || _a === void 0 ? void 0 : _a.c; diff --git a/tests/baselines/reference/propertyAccessChain.3.js b/tests/baselines/reference/propertyAccessChain.3.js index 3eedf7c2b22..6daa30bc1bf 100644 --- a/tests/baselines/reference/propertyAccessChain.3.js +++ b/tests/baselines/reference/propertyAccessChain.3.js @@ -42,34 +42,33 @@ var __rest = (this && this.__rest) || function (s, e) { } return t; }; -var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x; -((_a = obj) === null || _a === void 0 ? void 0 : _a.a)++; -((_b = obj) === null || _b === void 0 ? void 0 : _b.a.b)++; -((_c = obj) === null || _c === void 0 ? void 0 : _c.a)--; -((_d = obj) === null || _d === void 0 ? void 0 : _d.a.b)--; -++((_e = obj) === null || _e === void 0 ? void 0 : _e.a); -++((_f = obj) === null || _f === void 0 ? void 0 : _f.a.b); ---((_g = obj) === null || _g === void 0 ? void 0 : _g.a); ---((_h = obj) === null || _h === void 0 ? void 0 : _h.a.b); -(_j = obj) === null || _j === void 0 ? void 0 : _j.a = 1; -(_k = obj) === null || _k === void 0 ? void 0 : _k.a.b = 1; -(_l = obj) === null || _l === void 0 ? void 0 : _l.a += 1; -(_m = obj) === null || _m === void 0 ? void 0 : _m.a.b += 1; -for ((_o = obj) === null || _o === void 0 ? void 0 : _o.a in {}) +(obj === null || obj === void 0 ? void 0 : obj.a)++; +(obj === null || obj === void 0 ? void 0 : obj.a.b)++; +(obj === null || obj === void 0 ? void 0 : obj.a)--; +(obj === null || obj === void 0 ? void 0 : obj.a.b)--; +++(obj === null || obj === void 0 ? void 0 : obj.a); +++(obj === null || obj === void 0 ? void 0 : obj.a.b); +--(obj === null || obj === void 0 ? void 0 : obj.a); +--(obj === null || obj === void 0 ? void 0 : obj.a.b); +obj === null || obj === void 0 ? void 0 : obj.a = 1; +obj === null || obj === void 0 ? void 0 : obj.a.b = 1; +obj === null || obj === void 0 ? void 0 : obj.a += 1; +obj === null || obj === void 0 ? void 0 : obj.a.b += 1; +for (obj === null || obj === void 0 ? void 0 : obj.a in {}) ; -for ((_p = obj) === null || _p === void 0 ? void 0 : _p.a.b in {}) +for (obj === null || obj === void 0 ? void 0 : obj.a.b in {}) ; -for (var _i = 0, _y = []; _i < _y.length; _i++) { - (_q = obj) === null || _q === void 0 ? void 0 : _q.a = _y[_i]; +for (var _i = 0, _a = []; _i < _a.length; _i++) { + obj === null || obj === void 0 ? void 0 : obj.a = _a[_i]; ; } -for (var _z = 0, _0 = []; _z < _0.length; _z++) { - (_r = obj) === null || _r === void 0 ? void 0 : _r.a.b = _0[_z]; +for (var _b = 0, _c = []; _b < _c.length; _b++) { + obj === null || obj === void 0 ? void 0 : obj.a.b = _c[_b]; ; } -((_s = obj) === null || _s === void 0 ? void 0 : _s.a = { a: 1 }.a); -((_t = obj) === null || _t === void 0 ? void 0 : _t.a.b = { a: 1 }.a); -((_u = obj) === null || _u === void 0 ? void 0 : _u.a = __rest({ a: 1 }, [])); -((_v = obj) === null || _v === void 0 ? void 0 : _v.a.b = __rest({ a: 1 }, [])); -(_w = obj) === null || _w === void 0 ? void 0 : _w.a = [].slice(0); -(_x = obj) === null || _x === void 0 ? void 0 : _x.a.b = [].slice(0); +(obj === null || obj === void 0 ? void 0 : obj.a = { a: 1 }.a); +(obj === null || obj === void 0 ? void 0 : obj.a.b = { a: 1 }.a); +(obj === null || obj === void 0 ? void 0 : obj.a = __rest({ a: 1 }, [])); +(obj === null || obj === void 0 ? void 0 : obj.a.b = __rest({ a: 1 }, [])); +obj === null || obj === void 0 ? void 0 : obj.a = [].slice(0); +obj === null || obj === void 0 ? void 0 : obj.a.b = [].slice(0); diff --git a/tests/baselines/reference/propertyAccessChain.js b/tests/baselines/reference/propertyAccessChain.js index 47f4aa1c334..a2ece64f986 100644 --- a/tests/baselines/reference/propertyAccessChain.js +++ b/tests/baselines/reference/propertyAccessChain.js @@ -23,12 +23,12 @@ o1?.b ? 1 : 0; //// [propertyAccessChain.js] "use strict"; -var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k; -(_a = o1) === null || _a === void 0 ? void 0 : _a.b; -(_b = o2) === null || _b === void 0 ? void 0 : _b.b.c; -(_c = o3.b) === null || _c === void 0 ? void 0 : _c.c; -(_e = (_d = o4.b) === null || _d === void 0 ? void 0 : _d.c.d) === null || _e === void 0 ? void 0 : _e.e; -(_h = (_g = (_f = o5).b) === null || _g === void 0 ? void 0 : _g.call(_f).c.d) === null || _h === void 0 ? void 0 : _h.e; -(_j = o6()) === null || _j === void 0 ? void 0 : _j.x; +var _a, _b, _c, _d, _e, _f; +o1 === null || o1 === void 0 ? void 0 : o1.b; +o2 === null || o2 === void 0 ? void 0 : o2.b.c; +(_a = o3.b) === null || _a === void 0 ? void 0 : _a.c; +(_c = (_b = o4.b) === null || _b === void 0 ? void 0 : _b.c.d) === null || _c === void 0 ? void 0 : _c.e; +(_e = (_d = o5.b) === null || _d === void 0 ? void 0 : _d.call(o5).c.d) === null || _e === void 0 ? void 0 : _e.e; +(_f = o6()) === null || _f === void 0 ? void 0 : _f.x; // GH#34109 -((_k = o1) === null || _k === void 0 ? void 0 : _k.b) ? 1 : 0; +(o1 === null || o1 === void 0 ? void 0 : o1.b) ? 1 : 0; diff --git a/tests/baselines/reference/superMethodCall.js b/tests/baselines/reference/superMethodCall.js new file mode 100644 index 00000000000..ce9af2dff00 --- /dev/null +++ b/tests/baselines/reference/superMethodCall.js @@ -0,0 +1,44 @@ +//// [superMethodCall.ts] +class Base { + method?() { } +} + +class Derived extends Base { + method() { + return super.method?.(); + } + + async asyncMethod() { + return super.method?.(); + } +} + +//// [superMethodCall.js] +"use strict"; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +class Base { + method() { } +} +class Derived extends Base { + method() { + var _a; + return (_a = super.method) === null || _a === void 0 ? void 0 : _a.call(this); + } + asyncMethod() { + const _super = Object.create(null, { + method: { get: () => super.method } + }); + var _a; + return __awaiter(this, void 0, void 0, function* () { + return (_a = _super.method) === null || _a === void 0 ? void 0 : _a.call(this); + }); + } +} diff --git a/tests/baselines/reference/superMethodCall.symbols b/tests/baselines/reference/superMethodCall.symbols new file mode 100644 index 00000000000..b35a813cd88 --- /dev/null +++ b/tests/baselines/reference/superMethodCall.symbols @@ -0,0 +1,30 @@ +=== tests/cases/conformance/expressions/optionalChaining/callChain/superMethodCall.ts === +class Base { +>Base : Symbol(Base, Decl(superMethodCall.ts, 0, 0)) + + method?() { } +>method : Symbol(Base.method, Decl(superMethodCall.ts, 0, 12)) +} + +class Derived extends Base { +>Derived : Symbol(Derived, Decl(superMethodCall.ts, 2, 1)) +>Base : Symbol(Base, Decl(superMethodCall.ts, 0, 0)) + + method() { +>method : Symbol(Derived.method, Decl(superMethodCall.ts, 4, 28)) + + return super.method?.(); +>super.method : Symbol(Base.method, Decl(superMethodCall.ts, 0, 12)) +>super : Symbol(Base, Decl(superMethodCall.ts, 0, 0)) +>method : Symbol(Base.method, Decl(superMethodCall.ts, 0, 12)) + } + + async asyncMethod() { +>asyncMethod : Symbol(Derived.asyncMethod, Decl(superMethodCall.ts, 7, 5)) + + return super.method?.(); +>super.method : Symbol(Base.method, Decl(superMethodCall.ts, 0, 12)) +>super : Symbol(Base, Decl(superMethodCall.ts, 0, 0)) +>method : Symbol(Base.method, Decl(superMethodCall.ts, 0, 12)) + } +} diff --git a/tests/baselines/reference/superMethodCall.types b/tests/baselines/reference/superMethodCall.types new file mode 100644 index 00000000000..16d40d19ded --- /dev/null +++ b/tests/baselines/reference/superMethodCall.types @@ -0,0 +1,32 @@ +=== tests/cases/conformance/expressions/optionalChaining/callChain/superMethodCall.ts === +class Base { +>Base : Base + + method?() { } +>method : (() => void) | undefined +} + +class Derived extends Base { +>Derived : Derived +>Base : Base + + method() { +>method : () => void | undefined + + return super.method?.(); +>super.method?.() : void | undefined +>super.method : (() => void) | undefined +>super : Base +>method : (() => void) | undefined + } + + async asyncMethod() { +>asyncMethod : () => Promise + + return super.method?.(); +>super.method?.() : void | undefined +>super.method : (() => void) | undefined +>super : Base +>method : (() => void) | undefined + } +} diff --git a/tests/baselines/reference/thisMethodCall.js b/tests/baselines/reference/thisMethodCall.js new file mode 100644 index 00000000000..d05b9dbec95 --- /dev/null +++ b/tests/baselines/reference/thisMethodCall.js @@ -0,0 +1,17 @@ +//// [thisMethodCall.ts] +class C { + method?() {} + other() { + this.method?.(); + } +} + +//// [thisMethodCall.js] +"use strict"; +class C { + method() { } + other() { + var _a; + (_a = this.method) === null || _a === void 0 ? void 0 : _a.call(this); + } +} diff --git a/tests/baselines/reference/thisMethodCall.symbols b/tests/baselines/reference/thisMethodCall.symbols new file mode 100644 index 00000000000..d4d40af3fa4 --- /dev/null +++ b/tests/baselines/reference/thisMethodCall.symbols @@ -0,0 +1,16 @@ +=== tests/cases/conformance/expressions/optionalChaining/callChain/thisMethodCall.ts === +class C { +>C : Symbol(C, Decl(thisMethodCall.ts, 0, 0)) + + method?() {} +>method : Symbol(C.method, Decl(thisMethodCall.ts, 0, 9)) + + other() { +>other : Symbol(C.other, Decl(thisMethodCall.ts, 1, 16)) + + this.method?.(); +>this.method : Symbol(C.method, Decl(thisMethodCall.ts, 0, 9)) +>this : Symbol(C, Decl(thisMethodCall.ts, 0, 0)) +>method : Symbol(C.method, Decl(thisMethodCall.ts, 0, 9)) + } +} diff --git a/tests/baselines/reference/thisMethodCall.types b/tests/baselines/reference/thisMethodCall.types new file mode 100644 index 00000000000..08e023a44d2 --- /dev/null +++ b/tests/baselines/reference/thisMethodCall.types @@ -0,0 +1,17 @@ +=== tests/cases/conformance/expressions/optionalChaining/callChain/thisMethodCall.ts === +class C { +>C : C + + method?() {} +>method : (() => void) | undefined + + other() { +>other : () => void + + this.method?.(); +>this.method?.() : void | undefined +>this.method : (() => void) | undefined +>this : this +>method : (() => void) | undefined + } +} diff --git a/tests/baselines/reference/thisTypeOptionalCall.js b/tests/baselines/reference/thisTypeOptionalCall.js index 2a7a24d6eeb..56f7e585c0f 100644 --- a/tests/baselines/reference/thisTypeOptionalCall.js +++ b/tests/baselines/reference/thisTypeOptionalCall.js @@ -5,6 +5,5 @@ function maybeBind(obj: T, fn: ((this: T, ...args: A) => //// [thisTypeOptionalCall.js] function maybeBind(obj, fn) { - var _a; - return (_a = fn) === null || _a === void 0 ? void 0 : _a.bind(obj); + return fn === null || fn === void 0 ? void 0 : fn.bind(obj); } diff --git a/tests/cases/conformance/expressions/optionalChaining/callChain/superMethodCall.ts b/tests/cases/conformance/expressions/optionalChaining/callChain/superMethodCall.ts new file mode 100644 index 00000000000..86c273d0ee2 --- /dev/null +++ b/tests/cases/conformance/expressions/optionalChaining/callChain/superMethodCall.ts @@ -0,0 +1,15 @@ +// @strict: true +// @target: ES6 +class Base { + method?() { } +} + +class Derived extends Base { + method() { + return super.method?.(); + } + + async asyncMethod() { + return super.method?.(); + } +} \ No newline at end of file diff --git a/tests/cases/conformance/expressions/optionalChaining/callChain/thisMethodCall.ts b/tests/cases/conformance/expressions/optionalChaining/callChain/thisMethodCall.ts new file mode 100644 index 00000000000..ffbbd1f31a7 --- /dev/null +++ b/tests/cases/conformance/expressions/optionalChaining/callChain/thisMethodCall.ts @@ -0,0 +1,8 @@ +// @strict: true +// @target: es6 +class C { + method?() {} + other() { + this.method?.(); + } +} \ No newline at end of file