diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index 93a3bc5538d..5e570020941 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -1041,6 +1041,17 @@ namespace ts { } } + function isLogicalAssignmentExpressioin(node: Node) { + while (true) { + if (isParenthesizedExpression(node)) { + node = node.expression + } + else { + return isBinaryExpression(node) && isLogicalAssignmentOperator(node.operatorToken.kind); + } + } + } + function isTopLevelLogicalExpression(node: Node): boolean { while (isParenthesizedExpression(node.parent) || isPrefixUnaryExpression(node.parent) && node.parent.operator === SyntaxKind.ExclamationToken) { @@ -1063,7 +1074,7 @@ namespace ts { function bindCondition(node: Expression | undefined, trueTarget: FlowLabel, falseTarget: FlowLabel) { doWithConditionalBranches(bind, node, trueTarget, falseTarget); - if (!node || !isLogicalExpression(node) && !(isOptionalChain(node) && isOutermostOptionalChain(node))) { + if (!node || !isLogicalAssignmentExpressioin(node) && !isLogicalExpression(node) && !(isOptionalChain(node) && isOutermostOptionalChain(node))) { addAntecedent(trueTarget, createFlowCondition(FlowFlags.TrueCondition, currentFlow, node)); addAntecedent(falseTarget, createFlowCondition(FlowFlags.FalseCondition, currentFlow, node)); } @@ -1163,6 +1174,25 @@ namespace ts { currentFlow = finishFlowLabel(postIfLabel); } + function bindLogicalAssignmentExpression(node: BinaryExpression) { + const preRightLabel = createBranchLabel(); + const postExpressionLabel = createBranchLabel(); + + if (node.operatorToken.kind === SyntaxKind.AmpersandAmpersandEqualsToken) { + bindCondition(node.left, preRightLabel, postExpressionLabel); + } + else { + bindCondition(node.left, postExpressionLabel, preRightLabel); + } + + currentFlow = finishFlowLabel(preRightLabel); + bind(node.operatorToken); + bind(node.right); + bindAssignmentTargetFlow(node.left); + + currentFlow = finishFlowLabel(postExpressionLabel); + } + function bindReturnOrThrow(node: ReturnStatement | ThrowStatement): void { bind(node.expression); if (node.kind === SyntaxKind.ReturnStatement) { @@ -1450,6 +1480,10 @@ namespace ts { } function bindBinaryExpressionFlow(node: BinaryExpression) { + const flow = currentFlow + if (flow) { + + } const workStacks: { expr: BinaryExpression[], state: BindBinaryExpressionFlowState[], @@ -1511,6 +1545,10 @@ namespace ts { } completeNode(); } + else if(isLogicalAssignmentOperator(operator)) { + bindLogicalAssignmentExpression(node); + completeNode(); + } else { advanceState(BindBinaryExpressionFlowState.BindToken); maybeBind(node.left); diff --git a/tests/baselines/reference/logicalAssignment4(target=es2015).errors.txt b/tests/baselines/reference/logicalAssignment4(target=es2015).errors.txt new file mode 100644 index 00000000000..939c5699f6a --- /dev/null +++ b/tests/baselines/reference/logicalAssignment4(target=es2015).errors.txt @@ -0,0 +1,33 @@ +tests/cases/conformance/esnext/logicalAssignment/logicalAssignment4.ts(25,21): error TS2532: Object is possibly 'undefined'. + + +==== tests/cases/conformance/esnext/logicalAssignment/logicalAssignment4.ts (1 errors) ==== + function foo1(results: number[] | undefined) { + (results ||= []).push(100); + } + + function foo2(results: number[] | undefined) { + (results ??= []).push(100); + } + + function foo3(results: number[] | undefined) { + results ||= []; + results.push(100); + } + + function foo4(results: number[] | undefined) { + results ||= []; + results.push(100); + } + + interface ThingWithOriginal { + name: string; + original?: ThingWithOriginal + } + function doSomethingWithAlias(thing?: ThingWithOriginal | undefined) { + if (thing &&= thing.original) { + console.log(thing.name); + ~~~~~ +!!! error TS2532: Object is possibly 'undefined'. + } + } \ No newline at end of file diff --git a/tests/baselines/reference/logicalAssignment4(target=es2015).js b/tests/baselines/reference/logicalAssignment4(target=es2015).js index 57478da71ac..1a69ceeb70a 100644 --- a/tests/baselines/reference/logicalAssignment4(target=es2015).js +++ b/tests/baselines/reference/logicalAssignment4(target=es2015).js @@ -5,6 +5,26 @@ function foo1(results: number[] | undefined) { function foo2(results: number[] | undefined) { (results ??= []).push(100); +} + +function foo3(results: number[] | undefined) { + results ||= []; + results.push(100); +} + +function foo4(results: number[] | undefined) { + results ||= []; + results.push(100); +} + +interface ThingWithOriginal { + name: string; + original?: ThingWithOriginal +} +function doSomethingWithAlias(thing?: ThingWithOriginal | undefined) { + if (thing &&= thing.original) { + console.log(thing.name); + } } //// [logicalAssignment4.js] @@ -15,3 +35,16 @@ function foo1(results) { function foo2(results) { (results !== null && results !== void 0 ? results : (results = [])).push(100); } +function foo3(results) { + results || (results = []); + results.push(100); +} +function foo4(results) { + results || (results = []); + results.push(100); +} +function doSomethingWithAlias(thing) { + if (thing && (thing = thing.original)) { + console.log(thing.name); + } +} diff --git a/tests/baselines/reference/logicalAssignment4(target=es2015).symbols b/tests/baselines/reference/logicalAssignment4(target=es2015).symbols index 7d114427014..4f25669f53e 100644 --- a/tests/baselines/reference/logicalAssignment4(target=es2015).symbols +++ b/tests/baselines/reference/logicalAssignment4(target=es2015).symbols @@ -18,3 +18,60 @@ function foo2(results: number[] | undefined) { >results : Symbol(results, Decl(logicalAssignment4.ts, 4, 14)) >push : Symbol(Array.push, Decl(lib.es5.d.ts, --, --)) } + +function foo3(results: number[] | undefined) { +>foo3 : Symbol(foo3, Decl(logicalAssignment4.ts, 6, 1)) +>results : Symbol(results, Decl(logicalAssignment4.ts, 8, 14)) + + results ||= []; +>results : Symbol(results, Decl(logicalAssignment4.ts, 8, 14)) + + results.push(100); +>results.push : Symbol(Array.push, Decl(lib.es5.d.ts, --, --)) +>results : Symbol(results, Decl(logicalAssignment4.ts, 8, 14)) +>push : Symbol(Array.push, Decl(lib.es5.d.ts, --, --)) +} + +function foo4(results: number[] | undefined) { +>foo4 : Symbol(foo4, Decl(logicalAssignment4.ts, 11, 1)) +>results : Symbol(results, Decl(logicalAssignment4.ts, 13, 14)) + + results ||= []; +>results : Symbol(results, Decl(logicalAssignment4.ts, 13, 14)) + + results.push(100); +>results.push : Symbol(Array.push, Decl(lib.es5.d.ts, --, --)) +>results : Symbol(results, Decl(logicalAssignment4.ts, 13, 14)) +>push : Symbol(Array.push, Decl(lib.es5.d.ts, --, --)) +} + +interface ThingWithOriginal { +>ThingWithOriginal : Symbol(ThingWithOriginal, Decl(logicalAssignment4.ts, 16, 1)) + + name: string; +>name : Symbol(ThingWithOriginal.name, Decl(logicalAssignment4.ts, 18, 29)) + + original?: ThingWithOriginal +>original : Symbol(ThingWithOriginal.original, Decl(logicalAssignment4.ts, 19, 17)) +>ThingWithOriginal : Symbol(ThingWithOriginal, Decl(logicalAssignment4.ts, 16, 1)) +} +function doSomethingWithAlias(thing?: ThingWithOriginal | undefined) { +>doSomethingWithAlias : Symbol(doSomethingWithAlias, Decl(logicalAssignment4.ts, 21, 1)) +>thing : Symbol(thing, Decl(logicalAssignment4.ts, 22, 30)) +>ThingWithOriginal : Symbol(ThingWithOriginal, Decl(logicalAssignment4.ts, 16, 1)) + + if (thing &&= thing.original) { +>thing : Symbol(thing, Decl(logicalAssignment4.ts, 22, 30)) +>thing.original : Symbol(ThingWithOriginal.original, Decl(logicalAssignment4.ts, 19, 17)) +>thing : Symbol(thing, Decl(logicalAssignment4.ts, 22, 30)) +>original : Symbol(ThingWithOriginal.original, Decl(logicalAssignment4.ts, 19, 17)) + + console.log(thing.name); +>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) +>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>thing.name : Symbol(ThingWithOriginal.name, Decl(logicalAssignment4.ts, 18, 29)) +>thing : Symbol(thing, Decl(logicalAssignment4.ts, 22, 30)) +>name : Symbol(ThingWithOriginal.name, Decl(logicalAssignment4.ts, 18, 29)) + } +} diff --git a/tests/baselines/reference/logicalAssignment4(target=es2015).types b/tests/baselines/reference/logicalAssignment4(target=es2015).types index da48e3848b8..a2669aa6f28 100644 --- a/tests/baselines/reference/logicalAssignment4(target=es2015).types +++ b/tests/baselines/reference/logicalAssignment4(target=es2015).types @@ -28,3 +28,66 @@ function foo2(results: number[] | undefined) { >push : (...items: number[]) => number >100 : 100 } + +function foo3(results: number[] | undefined) { +>foo3 : (results: number[] | undefined) => void +>results : number[] | undefined + + results ||= []; +>results ||= [] : number[] +>results : number[] | undefined +>[] : never[] + + results.push(100); +>results.push(100) : number +>results.push : (...items: number[]) => number +>results : number[] +>push : (...items: number[]) => number +>100 : 100 +} + +function foo4(results: number[] | undefined) { +>foo4 : (results: number[] | undefined) => void +>results : number[] | undefined + + results ||= []; +>results ||= [] : number[] +>results : number[] | undefined +>[] : never[] + + results.push(100); +>results.push(100) : number +>results.push : (...items: number[]) => number +>results : number[] +>push : (...items: number[]) => number +>100 : 100 +} + +interface ThingWithOriginal { + name: string; +>name : string + + original?: ThingWithOriginal +>original : ThingWithOriginal | undefined +} +function doSomethingWithAlias(thing?: ThingWithOriginal | undefined) { +>doSomethingWithAlias : (thing?: ThingWithOriginal | undefined) => void +>thing : ThingWithOriginal | undefined + + if (thing &&= thing.original) { +>thing &&= thing.original : ThingWithOriginal | undefined +>thing : ThingWithOriginal | undefined +>thing.original : ThingWithOriginal | undefined +>thing : ThingWithOriginal +>original : ThingWithOriginal | undefined + + console.log(thing.name); +>console.log(thing.name) : void +>console.log : (...data: any[]) => void +>console : Console +>log : (...data: any[]) => void +>thing.name : string +>thing : ThingWithOriginal | undefined +>name : string + } +} diff --git a/tests/baselines/reference/logicalAssignment4(target=es2020).errors.txt b/tests/baselines/reference/logicalAssignment4(target=es2020).errors.txt new file mode 100644 index 00000000000..939c5699f6a --- /dev/null +++ b/tests/baselines/reference/logicalAssignment4(target=es2020).errors.txt @@ -0,0 +1,33 @@ +tests/cases/conformance/esnext/logicalAssignment/logicalAssignment4.ts(25,21): error TS2532: Object is possibly 'undefined'. + + +==== tests/cases/conformance/esnext/logicalAssignment/logicalAssignment4.ts (1 errors) ==== + function foo1(results: number[] | undefined) { + (results ||= []).push(100); + } + + function foo2(results: number[] | undefined) { + (results ??= []).push(100); + } + + function foo3(results: number[] | undefined) { + results ||= []; + results.push(100); + } + + function foo4(results: number[] | undefined) { + results ||= []; + results.push(100); + } + + interface ThingWithOriginal { + name: string; + original?: ThingWithOriginal + } + function doSomethingWithAlias(thing?: ThingWithOriginal | undefined) { + if (thing &&= thing.original) { + console.log(thing.name); + ~~~~~ +!!! error TS2532: Object is possibly 'undefined'. + } + } \ No newline at end of file diff --git a/tests/baselines/reference/logicalAssignment4(target=es2020).js b/tests/baselines/reference/logicalAssignment4(target=es2020).js index 91d60e88aa9..f2dfaa8e3c9 100644 --- a/tests/baselines/reference/logicalAssignment4(target=es2020).js +++ b/tests/baselines/reference/logicalAssignment4(target=es2020).js @@ -5,6 +5,26 @@ function foo1(results: number[] | undefined) { function foo2(results: number[] | undefined) { (results ??= []).push(100); +} + +function foo3(results: number[] | undefined) { + results ||= []; + results.push(100); +} + +function foo4(results: number[] | undefined) { + results ||= []; + results.push(100); +} + +interface ThingWithOriginal { + name: string; + original?: ThingWithOriginal +} +function doSomethingWithAlias(thing?: ThingWithOriginal | undefined) { + if (thing &&= thing.original) { + console.log(thing.name); + } } //// [logicalAssignment4.js] @@ -15,3 +35,16 @@ function foo1(results) { function foo2(results) { (results ?? (results = [])).push(100); } +function foo3(results) { + results || (results = []); + results.push(100); +} +function foo4(results) { + results || (results = []); + results.push(100); +} +function doSomethingWithAlias(thing) { + if (thing && (thing = thing.original)) { + console.log(thing.name); + } +} diff --git a/tests/baselines/reference/logicalAssignment4(target=es2020).symbols b/tests/baselines/reference/logicalAssignment4(target=es2020).symbols index 7d114427014..4f25669f53e 100644 --- a/tests/baselines/reference/logicalAssignment4(target=es2020).symbols +++ b/tests/baselines/reference/logicalAssignment4(target=es2020).symbols @@ -18,3 +18,60 @@ function foo2(results: number[] | undefined) { >results : Symbol(results, Decl(logicalAssignment4.ts, 4, 14)) >push : Symbol(Array.push, Decl(lib.es5.d.ts, --, --)) } + +function foo3(results: number[] | undefined) { +>foo3 : Symbol(foo3, Decl(logicalAssignment4.ts, 6, 1)) +>results : Symbol(results, Decl(logicalAssignment4.ts, 8, 14)) + + results ||= []; +>results : Symbol(results, Decl(logicalAssignment4.ts, 8, 14)) + + results.push(100); +>results.push : Symbol(Array.push, Decl(lib.es5.d.ts, --, --)) +>results : Symbol(results, Decl(logicalAssignment4.ts, 8, 14)) +>push : Symbol(Array.push, Decl(lib.es5.d.ts, --, --)) +} + +function foo4(results: number[] | undefined) { +>foo4 : Symbol(foo4, Decl(logicalAssignment4.ts, 11, 1)) +>results : Symbol(results, Decl(logicalAssignment4.ts, 13, 14)) + + results ||= []; +>results : Symbol(results, Decl(logicalAssignment4.ts, 13, 14)) + + results.push(100); +>results.push : Symbol(Array.push, Decl(lib.es5.d.ts, --, --)) +>results : Symbol(results, Decl(logicalAssignment4.ts, 13, 14)) +>push : Symbol(Array.push, Decl(lib.es5.d.ts, --, --)) +} + +interface ThingWithOriginal { +>ThingWithOriginal : Symbol(ThingWithOriginal, Decl(logicalAssignment4.ts, 16, 1)) + + name: string; +>name : Symbol(ThingWithOriginal.name, Decl(logicalAssignment4.ts, 18, 29)) + + original?: ThingWithOriginal +>original : Symbol(ThingWithOriginal.original, Decl(logicalAssignment4.ts, 19, 17)) +>ThingWithOriginal : Symbol(ThingWithOriginal, Decl(logicalAssignment4.ts, 16, 1)) +} +function doSomethingWithAlias(thing?: ThingWithOriginal | undefined) { +>doSomethingWithAlias : Symbol(doSomethingWithAlias, Decl(logicalAssignment4.ts, 21, 1)) +>thing : Symbol(thing, Decl(logicalAssignment4.ts, 22, 30)) +>ThingWithOriginal : Symbol(ThingWithOriginal, Decl(logicalAssignment4.ts, 16, 1)) + + if (thing &&= thing.original) { +>thing : Symbol(thing, Decl(logicalAssignment4.ts, 22, 30)) +>thing.original : Symbol(ThingWithOriginal.original, Decl(logicalAssignment4.ts, 19, 17)) +>thing : Symbol(thing, Decl(logicalAssignment4.ts, 22, 30)) +>original : Symbol(ThingWithOriginal.original, Decl(logicalAssignment4.ts, 19, 17)) + + console.log(thing.name); +>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) +>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>thing.name : Symbol(ThingWithOriginal.name, Decl(logicalAssignment4.ts, 18, 29)) +>thing : Symbol(thing, Decl(logicalAssignment4.ts, 22, 30)) +>name : Symbol(ThingWithOriginal.name, Decl(logicalAssignment4.ts, 18, 29)) + } +} diff --git a/tests/baselines/reference/logicalAssignment4(target=es2020).types b/tests/baselines/reference/logicalAssignment4(target=es2020).types index da48e3848b8..a2669aa6f28 100644 --- a/tests/baselines/reference/logicalAssignment4(target=es2020).types +++ b/tests/baselines/reference/logicalAssignment4(target=es2020).types @@ -28,3 +28,66 @@ function foo2(results: number[] | undefined) { >push : (...items: number[]) => number >100 : 100 } + +function foo3(results: number[] | undefined) { +>foo3 : (results: number[] | undefined) => void +>results : number[] | undefined + + results ||= []; +>results ||= [] : number[] +>results : number[] | undefined +>[] : never[] + + results.push(100); +>results.push(100) : number +>results.push : (...items: number[]) => number +>results : number[] +>push : (...items: number[]) => number +>100 : 100 +} + +function foo4(results: number[] | undefined) { +>foo4 : (results: number[] | undefined) => void +>results : number[] | undefined + + results ||= []; +>results ||= [] : number[] +>results : number[] | undefined +>[] : never[] + + results.push(100); +>results.push(100) : number +>results.push : (...items: number[]) => number +>results : number[] +>push : (...items: number[]) => number +>100 : 100 +} + +interface ThingWithOriginal { + name: string; +>name : string + + original?: ThingWithOriginal +>original : ThingWithOriginal | undefined +} +function doSomethingWithAlias(thing?: ThingWithOriginal | undefined) { +>doSomethingWithAlias : (thing?: ThingWithOriginal | undefined) => void +>thing : ThingWithOriginal | undefined + + if (thing &&= thing.original) { +>thing &&= thing.original : ThingWithOriginal | undefined +>thing : ThingWithOriginal | undefined +>thing.original : ThingWithOriginal | undefined +>thing : ThingWithOriginal +>original : ThingWithOriginal | undefined + + console.log(thing.name); +>console.log(thing.name) : void +>console.log : (...data: any[]) => void +>console : Console +>log : (...data: any[]) => void +>thing.name : string +>thing : ThingWithOriginal | undefined +>name : string + } +} diff --git a/tests/baselines/reference/logicalAssignment4(target=esnext).errors.txt b/tests/baselines/reference/logicalAssignment4(target=esnext).errors.txt new file mode 100644 index 00000000000..939c5699f6a --- /dev/null +++ b/tests/baselines/reference/logicalAssignment4(target=esnext).errors.txt @@ -0,0 +1,33 @@ +tests/cases/conformance/esnext/logicalAssignment/logicalAssignment4.ts(25,21): error TS2532: Object is possibly 'undefined'. + + +==== tests/cases/conformance/esnext/logicalAssignment/logicalAssignment4.ts (1 errors) ==== + function foo1(results: number[] | undefined) { + (results ||= []).push(100); + } + + function foo2(results: number[] | undefined) { + (results ??= []).push(100); + } + + function foo3(results: number[] | undefined) { + results ||= []; + results.push(100); + } + + function foo4(results: number[] | undefined) { + results ||= []; + results.push(100); + } + + interface ThingWithOriginal { + name: string; + original?: ThingWithOriginal + } + function doSomethingWithAlias(thing?: ThingWithOriginal | undefined) { + if (thing &&= thing.original) { + console.log(thing.name); + ~~~~~ +!!! error TS2532: Object is possibly 'undefined'. + } + } \ No newline at end of file diff --git a/tests/baselines/reference/logicalAssignment4(target=esnext).js b/tests/baselines/reference/logicalAssignment4(target=esnext).js index 3b749b6d8c7..b9c254e9778 100644 --- a/tests/baselines/reference/logicalAssignment4(target=esnext).js +++ b/tests/baselines/reference/logicalAssignment4(target=esnext).js @@ -5,6 +5,26 @@ function foo1(results: number[] | undefined) { function foo2(results: number[] | undefined) { (results ??= []).push(100); +} + +function foo3(results: number[] | undefined) { + results ||= []; + results.push(100); +} + +function foo4(results: number[] | undefined) { + results ||= []; + results.push(100); +} + +interface ThingWithOriginal { + name: string; + original?: ThingWithOriginal +} +function doSomethingWithAlias(thing?: ThingWithOriginal | undefined) { + if (thing &&= thing.original) { + console.log(thing.name); + } } //// [logicalAssignment4.js] @@ -15,3 +35,16 @@ function foo1(results) { function foo2(results) { (results ??= []).push(100); } +function foo3(results) { + results ||= []; + results.push(100); +} +function foo4(results) { + results ||= []; + results.push(100); +} +function doSomethingWithAlias(thing) { + if (thing &&= thing.original) { + console.log(thing.name); + } +} diff --git a/tests/baselines/reference/logicalAssignment4(target=esnext).symbols b/tests/baselines/reference/logicalAssignment4(target=esnext).symbols index 7d114427014..4f25669f53e 100644 --- a/tests/baselines/reference/logicalAssignment4(target=esnext).symbols +++ b/tests/baselines/reference/logicalAssignment4(target=esnext).symbols @@ -18,3 +18,60 @@ function foo2(results: number[] | undefined) { >results : Symbol(results, Decl(logicalAssignment4.ts, 4, 14)) >push : Symbol(Array.push, Decl(lib.es5.d.ts, --, --)) } + +function foo3(results: number[] | undefined) { +>foo3 : Symbol(foo3, Decl(logicalAssignment4.ts, 6, 1)) +>results : Symbol(results, Decl(logicalAssignment4.ts, 8, 14)) + + results ||= []; +>results : Symbol(results, Decl(logicalAssignment4.ts, 8, 14)) + + results.push(100); +>results.push : Symbol(Array.push, Decl(lib.es5.d.ts, --, --)) +>results : Symbol(results, Decl(logicalAssignment4.ts, 8, 14)) +>push : Symbol(Array.push, Decl(lib.es5.d.ts, --, --)) +} + +function foo4(results: number[] | undefined) { +>foo4 : Symbol(foo4, Decl(logicalAssignment4.ts, 11, 1)) +>results : Symbol(results, Decl(logicalAssignment4.ts, 13, 14)) + + results ||= []; +>results : Symbol(results, Decl(logicalAssignment4.ts, 13, 14)) + + results.push(100); +>results.push : Symbol(Array.push, Decl(lib.es5.d.ts, --, --)) +>results : Symbol(results, Decl(logicalAssignment4.ts, 13, 14)) +>push : Symbol(Array.push, Decl(lib.es5.d.ts, --, --)) +} + +interface ThingWithOriginal { +>ThingWithOriginal : Symbol(ThingWithOriginal, Decl(logicalAssignment4.ts, 16, 1)) + + name: string; +>name : Symbol(ThingWithOriginal.name, Decl(logicalAssignment4.ts, 18, 29)) + + original?: ThingWithOriginal +>original : Symbol(ThingWithOriginal.original, Decl(logicalAssignment4.ts, 19, 17)) +>ThingWithOriginal : Symbol(ThingWithOriginal, Decl(logicalAssignment4.ts, 16, 1)) +} +function doSomethingWithAlias(thing?: ThingWithOriginal | undefined) { +>doSomethingWithAlias : Symbol(doSomethingWithAlias, Decl(logicalAssignment4.ts, 21, 1)) +>thing : Symbol(thing, Decl(logicalAssignment4.ts, 22, 30)) +>ThingWithOriginal : Symbol(ThingWithOriginal, Decl(logicalAssignment4.ts, 16, 1)) + + if (thing &&= thing.original) { +>thing : Symbol(thing, Decl(logicalAssignment4.ts, 22, 30)) +>thing.original : Symbol(ThingWithOriginal.original, Decl(logicalAssignment4.ts, 19, 17)) +>thing : Symbol(thing, Decl(logicalAssignment4.ts, 22, 30)) +>original : Symbol(ThingWithOriginal.original, Decl(logicalAssignment4.ts, 19, 17)) + + console.log(thing.name); +>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) +>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>thing.name : Symbol(ThingWithOriginal.name, Decl(logicalAssignment4.ts, 18, 29)) +>thing : Symbol(thing, Decl(logicalAssignment4.ts, 22, 30)) +>name : Symbol(ThingWithOriginal.name, Decl(logicalAssignment4.ts, 18, 29)) + } +} diff --git a/tests/baselines/reference/logicalAssignment4(target=esnext).types b/tests/baselines/reference/logicalAssignment4(target=esnext).types index da48e3848b8..a2669aa6f28 100644 --- a/tests/baselines/reference/logicalAssignment4(target=esnext).types +++ b/tests/baselines/reference/logicalAssignment4(target=esnext).types @@ -28,3 +28,66 @@ function foo2(results: number[] | undefined) { >push : (...items: number[]) => number >100 : 100 } + +function foo3(results: number[] | undefined) { +>foo3 : (results: number[] | undefined) => void +>results : number[] | undefined + + results ||= []; +>results ||= [] : number[] +>results : number[] | undefined +>[] : never[] + + results.push(100); +>results.push(100) : number +>results.push : (...items: number[]) => number +>results : number[] +>push : (...items: number[]) => number +>100 : 100 +} + +function foo4(results: number[] | undefined) { +>foo4 : (results: number[] | undefined) => void +>results : number[] | undefined + + results ||= []; +>results ||= [] : number[] +>results : number[] | undefined +>[] : never[] + + results.push(100); +>results.push(100) : number +>results.push : (...items: number[]) => number +>results : number[] +>push : (...items: number[]) => number +>100 : 100 +} + +interface ThingWithOriginal { + name: string; +>name : string + + original?: ThingWithOriginal +>original : ThingWithOriginal | undefined +} +function doSomethingWithAlias(thing?: ThingWithOriginal | undefined) { +>doSomethingWithAlias : (thing?: ThingWithOriginal | undefined) => void +>thing : ThingWithOriginal | undefined + + if (thing &&= thing.original) { +>thing &&= thing.original : ThingWithOriginal | undefined +>thing : ThingWithOriginal | undefined +>thing.original : ThingWithOriginal | undefined +>thing : ThingWithOriginal +>original : ThingWithOriginal | undefined + + console.log(thing.name); +>console.log(thing.name) : void +>console.log : (...data: any[]) => void +>console : Console +>log : (...data: any[]) => void +>thing.name : string +>thing : ThingWithOriginal | undefined +>name : string + } +} diff --git a/tests/baselines/reference/logicalAssignment5(target=es2015).errors.txt b/tests/baselines/reference/logicalAssignment5(target=es2015).errors.txt new file mode 100644 index 00000000000..663162e9165 --- /dev/null +++ b/tests/baselines/reference/logicalAssignment5(target=es2015).errors.txt @@ -0,0 +1,51 @@ +tests/cases/conformance/esnext/logicalAssignment/logicalAssignment5.ts(12,12): error TS7006: Parameter 'a' implicitly has an 'any' type. +tests/cases/conformance/esnext/logicalAssignment/logicalAssignment5.ts(13,5): error TS2722: Cannot invoke an object which is possibly 'undefined'. +tests/cases/conformance/esnext/logicalAssignment/logicalAssignment5.ts(17,12): error TS2532: Object is possibly 'undefined'. +tests/cases/conformance/esnext/logicalAssignment/logicalAssignment5.ts(22,12): error TS2532: Object is possibly 'undefined'. +tests/cases/conformance/esnext/logicalAssignment/logicalAssignment5.ts(27,27): error TS7006: Parameter 'a' implicitly has an 'any' type. +tests/cases/conformance/esnext/logicalAssignment/logicalAssignment5.ts(28,5): error TS2722: Cannot invoke an object which is possibly 'undefined'. + + +==== tests/cases/conformance/esnext/logicalAssignment/logicalAssignment5.ts (6 errors) ==== + function foo1 (f?: (a: number) => void) { + f ??= (a => a) + f(42) + } + + function foo2 (f?: (a: number) => void) { + f ||= (a => a) + f(42) + } + + function foo3 (f?: (a: number) => void) { + f &&= (a => a) + ~ +!!! error TS7006: Parameter 'a' implicitly has an 'any' type. + f(42) + ~ +!!! error TS2722: Cannot invoke an object which is possibly 'undefined'. + } + + function bar1 (f?: (a: number) => void) { + f ??= (f.toString(), (a => a)) + ~ +!!! error TS2532: Object is possibly 'undefined'. + f(42) + } + + function bar2 (f?: (a: number) => void) { + f ||= (f.toString(), (a => a)) + ~ +!!! error TS2532: Object is possibly 'undefined'. + f(42) + } + + function bar3 (f?: (a: number) => void) { + f &&= (f.toString(), (a => a)) + ~ +!!! error TS7006: Parameter 'a' implicitly has an 'any' type. + f(42) + ~ +!!! error TS2722: Cannot invoke an object which is possibly 'undefined'. + } + \ No newline at end of file diff --git a/tests/baselines/reference/logicalAssignment5(target=es2015).js b/tests/baselines/reference/logicalAssignment5(target=es2015).js new file mode 100644 index 00000000000..f42fd755c1d --- /dev/null +++ b/tests/baselines/reference/logicalAssignment5(target=es2015).js @@ -0,0 +1,58 @@ +//// [logicalAssignment5.ts] +function foo1 (f?: (a: number) => void) { + f ??= (a => a) + f(42) +} + +function foo2 (f?: (a: number) => void) { + f ||= (a => a) + f(42) +} + +function foo3 (f?: (a: number) => void) { + f &&= (a => a) + f(42) +} + +function bar1 (f?: (a: number) => void) { + f ??= (f.toString(), (a => a)) + f(42) +} + +function bar2 (f?: (a: number) => void) { + f ||= (f.toString(), (a => a)) + f(42) +} + +function bar3 (f?: (a: number) => void) { + f &&= (f.toString(), (a => a)) + f(42) +} + + +//// [logicalAssignment5.js] +"use strict"; +function foo1(f) { + f !== null && f !== void 0 ? f : (f = (a => a)); + f(42); +} +function foo2(f) { + f || (f = (a => a)); + f(42); +} +function foo3(f) { + f && (f = (a => a)); + f(42); +} +function bar1(f) { + f !== null && f !== void 0 ? f : (f = (f.toString(), (a => a))); + f(42); +} +function bar2(f) { + f || (f = (f.toString(), (a => a))); + f(42); +} +function bar3(f) { + f && (f = (f.toString(), (a => a))); + f(42); +} diff --git a/tests/baselines/reference/logicalAssignment5(target=es2015).symbols b/tests/baselines/reference/logicalAssignment5(target=es2015).symbols new file mode 100644 index 00000000000..5862d6b68d4 --- /dev/null +++ b/tests/baselines/reference/logicalAssignment5(target=es2015).symbols @@ -0,0 +1,90 @@ +=== tests/cases/conformance/esnext/logicalAssignment/logicalAssignment5.ts === +function foo1 (f?: (a: number) => void) { +>foo1 : Symbol(foo1, Decl(logicalAssignment5.ts, 0, 0)) +>f : Symbol(f, Decl(logicalAssignment5.ts, 0, 15)) +>a : Symbol(a, Decl(logicalAssignment5.ts, 0, 20)) + + f ??= (a => a) +>f : Symbol(f, Decl(logicalAssignment5.ts, 0, 15)) +>a : Symbol(a, Decl(logicalAssignment5.ts, 1, 11)) +>a : Symbol(a, Decl(logicalAssignment5.ts, 1, 11)) + + f(42) +>f : Symbol(f, Decl(logicalAssignment5.ts, 0, 15)) +} + +function foo2 (f?: (a: number) => void) { +>foo2 : Symbol(foo2, Decl(logicalAssignment5.ts, 3, 1)) +>f : Symbol(f, Decl(logicalAssignment5.ts, 5, 15)) +>a : Symbol(a, Decl(logicalAssignment5.ts, 5, 20)) + + f ||= (a => a) +>f : Symbol(f, Decl(logicalAssignment5.ts, 5, 15)) +>a : Symbol(a, Decl(logicalAssignment5.ts, 6, 11)) +>a : Symbol(a, Decl(logicalAssignment5.ts, 6, 11)) + + f(42) +>f : Symbol(f, Decl(logicalAssignment5.ts, 5, 15)) +} + +function foo3 (f?: (a: number) => void) { +>foo3 : Symbol(foo3, Decl(logicalAssignment5.ts, 8, 1)) +>f : Symbol(f, Decl(logicalAssignment5.ts, 10, 15)) +>a : Symbol(a, Decl(logicalAssignment5.ts, 10, 20)) + + f &&= (a => a) +>f : Symbol(f, Decl(logicalAssignment5.ts, 10, 15)) +>a : Symbol(a, Decl(logicalAssignment5.ts, 11, 11)) +>a : Symbol(a, Decl(logicalAssignment5.ts, 11, 11)) + + f(42) +>f : Symbol(f, Decl(logicalAssignment5.ts, 10, 15)) +} + +function bar1 (f?: (a: number) => void) { +>bar1 : Symbol(bar1, Decl(logicalAssignment5.ts, 13, 1)) +>f : Symbol(f, Decl(logicalAssignment5.ts, 15, 15)) +>a : Symbol(a, Decl(logicalAssignment5.ts, 15, 20)) + + f ??= (f.toString(), (a => a)) +>f : Symbol(f, Decl(logicalAssignment5.ts, 15, 15)) +>f : Symbol(f, Decl(logicalAssignment5.ts, 15, 15)) +>a : Symbol(a, Decl(logicalAssignment5.ts, 16, 26)) +>a : Symbol(a, Decl(logicalAssignment5.ts, 16, 26)) + + f(42) +>f : Symbol(f, Decl(logicalAssignment5.ts, 15, 15)) +} + +function bar2 (f?: (a: number) => void) { +>bar2 : Symbol(bar2, Decl(logicalAssignment5.ts, 18, 1)) +>f : Symbol(f, Decl(logicalAssignment5.ts, 20, 15)) +>a : Symbol(a, Decl(logicalAssignment5.ts, 20, 20)) + + f ||= (f.toString(), (a => a)) +>f : Symbol(f, Decl(logicalAssignment5.ts, 20, 15)) +>f : Symbol(f, Decl(logicalAssignment5.ts, 20, 15)) +>a : Symbol(a, Decl(logicalAssignment5.ts, 21, 26)) +>a : Symbol(a, Decl(logicalAssignment5.ts, 21, 26)) + + f(42) +>f : Symbol(f, Decl(logicalAssignment5.ts, 20, 15)) +} + +function bar3 (f?: (a: number) => void) { +>bar3 : Symbol(bar3, Decl(logicalAssignment5.ts, 23, 1)) +>f : Symbol(f, Decl(logicalAssignment5.ts, 25, 15)) +>a : Symbol(a, Decl(logicalAssignment5.ts, 25, 20)) + + f &&= (f.toString(), (a => a)) +>f : Symbol(f, Decl(logicalAssignment5.ts, 25, 15)) +>f.toString : Symbol(Function.toString, Decl(lib.es5.d.ts, --, --)) +>f : Symbol(f, Decl(logicalAssignment5.ts, 25, 15)) +>toString : Symbol(Function.toString, Decl(lib.es5.d.ts, --, --)) +>a : Symbol(a, Decl(logicalAssignment5.ts, 26, 26)) +>a : Symbol(a, Decl(logicalAssignment5.ts, 26, 26)) + + f(42) +>f : Symbol(f, Decl(logicalAssignment5.ts, 25, 15)) +} + diff --git a/tests/baselines/reference/logicalAssignment5(target=es2015).types b/tests/baselines/reference/logicalAssignment5(target=es2015).types new file mode 100644 index 00000000000..694c3db90a5 --- /dev/null +++ b/tests/baselines/reference/logicalAssignment5(target=es2015).types @@ -0,0 +1,133 @@ +=== tests/cases/conformance/esnext/logicalAssignment/logicalAssignment5.ts === +function foo1 (f?: (a: number) => void) { +>foo1 : (f?: ((a: number) => void) | undefined) => void +>f : ((a: number) => void) | undefined +>a : number + + f ??= (a => a) +>f ??= (a => a) : (a: number) => void +>f : ((a: number) => void) | undefined +>(a => a) : (a: number) => number +>a => a : (a: number) => number +>a : number +>a : number + + f(42) +>f(42) : void +>f : (a: number) => void +>42 : 42 +} + +function foo2 (f?: (a: number) => void) { +>foo2 : (f?: ((a: number) => void) | undefined) => void +>f : ((a: number) => void) | undefined +>a : number + + f ||= (a => a) +>f ||= (a => a) : (a: number) => void +>f : ((a: number) => void) | undefined +>(a => a) : (a: number) => number +>a => a : (a: number) => number +>a : number +>a : number + + f(42) +>f(42) : void +>f : (a: number) => void +>42 : 42 +} + +function foo3 (f?: (a: number) => void) { +>foo3 : (f?: ((a: number) => void) | undefined) => void +>f : ((a: number) => void) | undefined +>a : number + + f &&= (a => a) +>f &&= (a => a) : ((a: any) => any) | undefined +>f : ((a: number) => void) | undefined +>(a => a) : (a: any) => any +>a => a : (a: any) => any +>a : any +>a : any + + f(42) +>f(42) : any +>f : undefined +>42 : 42 +} + +function bar1 (f?: (a: number) => void) { +>bar1 : (f?: ((a: number) => void) | undefined) => void +>f : ((a: number) => void) | undefined +>a : number + + f ??= (f.toString(), (a => a)) +>f ??= (f.toString(), (a => a)) : (a: number) => void +>f : ((a: number) => void) | undefined +>(f.toString(), (a => a)) : (a: number) => number +>f.toString(), (a => a) : (a: number) => number +>f.toString() : any +>f.toString : any +>f : undefined +>toString : any +>(a => a) : (a: number) => number +>a => a : (a: number) => number +>a : number +>a : number + + f(42) +>f(42) : void +>f : (a: number) => void +>42 : 42 +} + +function bar2 (f?: (a: number) => void) { +>bar2 : (f?: ((a: number) => void) | undefined) => void +>f : ((a: number) => void) | undefined +>a : number + + f ||= (f.toString(), (a => a)) +>f ||= (f.toString(), (a => a)) : (a: number) => void +>f : ((a: number) => void) | undefined +>(f.toString(), (a => a)) : (a: number) => number +>f.toString(), (a => a) : (a: number) => number +>f.toString() : any +>f.toString : any +>f : undefined +>toString : any +>(a => a) : (a: number) => number +>a => a : (a: number) => number +>a : number +>a : number + + f(42) +>f(42) : void +>f : (a: number) => void +>42 : 42 +} + +function bar3 (f?: (a: number) => void) { +>bar3 : (f?: ((a: number) => void) | undefined) => void +>f : ((a: number) => void) | undefined +>a : number + + f &&= (f.toString(), (a => a)) +>f &&= (f.toString(), (a => a)) : ((a: any) => any) | undefined +>f : ((a: number) => void) | undefined +>(f.toString(), (a => a)) : (a: any) => any +>f.toString(), (a => a) : (a: any) => any +>f.toString() : string +>f.toString : () => string +>f : (a: number) => void +>toString : () => string +>(a => a) : (a: any) => any +>a => a : (a: any) => any +>a : any +>a : any + + f(42) +>f(42) : any +>f : undefined +>42 : 42 +} + diff --git a/tests/baselines/reference/logicalAssignment5(target=es2020).errors.txt b/tests/baselines/reference/logicalAssignment5(target=es2020).errors.txt new file mode 100644 index 00000000000..663162e9165 --- /dev/null +++ b/tests/baselines/reference/logicalAssignment5(target=es2020).errors.txt @@ -0,0 +1,51 @@ +tests/cases/conformance/esnext/logicalAssignment/logicalAssignment5.ts(12,12): error TS7006: Parameter 'a' implicitly has an 'any' type. +tests/cases/conformance/esnext/logicalAssignment/logicalAssignment5.ts(13,5): error TS2722: Cannot invoke an object which is possibly 'undefined'. +tests/cases/conformance/esnext/logicalAssignment/logicalAssignment5.ts(17,12): error TS2532: Object is possibly 'undefined'. +tests/cases/conformance/esnext/logicalAssignment/logicalAssignment5.ts(22,12): error TS2532: Object is possibly 'undefined'. +tests/cases/conformance/esnext/logicalAssignment/logicalAssignment5.ts(27,27): error TS7006: Parameter 'a' implicitly has an 'any' type. +tests/cases/conformance/esnext/logicalAssignment/logicalAssignment5.ts(28,5): error TS2722: Cannot invoke an object which is possibly 'undefined'. + + +==== tests/cases/conformance/esnext/logicalAssignment/logicalAssignment5.ts (6 errors) ==== + function foo1 (f?: (a: number) => void) { + f ??= (a => a) + f(42) + } + + function foo2 (f?: (a: number) => void) { + f ||= (a => a) + f(42) + } + + function foo3 (f?: (a: number) => void) { + f &&= (a => a) + ~ +!!! error TS7006: Parameter 'a' implicitly has an 'any' type. + f(42) + ~ +!!! error TS2722: Cannot invoke an object which is possibly 'undefined'. + } + + function bar1 (f?: (a: number) => void) { + f ??= (f.toString(), (a => a)) + ~ +!!! error TS2532: Object is possibly 'undefined'. + f(42) + } + + function bar2 (f?: (a: number) => void) { + f ||= (f.toString(), (a => a)) + ~ +!!! error TS2532: Object is possibly 'undefined'. + f(42) + } + + function bar3 (f?: (a: number) => void) { + f &&= (f.toString(), (a => a)) + ~ +!!! error TS7006: Parameter 'a' implicitly has an 'any' type. + f(42) + ~ +!!! error TS2722: Cannot invoke an object which is possibly 'undefined'. + } + \ No newline at end of file diff --git a/tests/baselines/reference/logicalAssignment5(target=es2020).js b/tests/baselines/reference/logicalAssignment5(target=es2020).js new file mode 100644 index 00000000000..58f3a4553dd --- /dev/null +++ b/tests/baselines/reference/logicalAssignment5(target=es2020).js @@ -0,0 +1,58 @@ +//// [logicalAssignment5.ts] +function foo1 (f?: (a: number) => void) { + f ??= (a => a) + f(42) +} + +function foo2 (f?: (a: number) => void) { + f ||= (a => a) + f(42) +} + +function foo3 (f?: (a: number) => void) { + f &&= (a => a) + f(42) +} + +function bar1 (f?: (a: number) => void) { + f ??= (f.toString(), (a => a)) + f(42) +} + +function bar2 (f?: (a: number) => void) { + f ||= (f.toString(), (a => a)) + f(42) +} + +function bar3 (f?: (a: number) => void) { + f &&= (f.toString(), (a => a)) + f(42) +} + + +//// [logicalAssignment5.js] +"use strict"; +function foo1(f) { + f ?? (f = (a => a)); + f(42); +} +function foo2(f) { + f || (f = (a => a)); + f(42); +} +function foo3(f) { + f && (f = (a => a)); + f(42); +} +function bar1(f) { + f ?? (f = (f.toString(), (a => a))); + f(42); +} +function bar2(f) { + f || (f = (f.toString(), (a => a))); + f(42); +} +function bar3(f) { + f && (f = (f.toString(), (a => a))); + f(42); +} diff --git a/tests/baselines/reference/logicalAssignment5(target=es2020).symbols b/tests/baselines/reference/logicalAssignment5(target=es2020).symbols new file mode 100644 index 00000000000..5862d6b68d4 --- /dev/null +++ b/tests/baselines/reference/logicalAssignment5(target=es2020).symbols @@ -0,0 +1,90 @@ +=== tests/cases/conformance/esnext/logicalAssignment/logicalAssignment5.ts === +function foo1 (f?: (a: number) => void) { +>foo1 : Symbol(foo1, Decl(logicalAssignment5.ts, 0, 0)) +>f : Symbol(f, Decl(logicalAssignment5.ts, 0, 15)) +>a : Symbol(a, Decl(logicalAssignment5.ts, 0, 20)) + + f ??= (a => a) +>f : Symbol(f, Decl(logicalAssignment5.ts, 0, 15)) +>a : Symbol(a, Decl(logicalAssignment5.ts, 1, 11)) +>a : Symbol(a, Decl(logicalAssignment5.ts, 1, 11)) + + f(42) +>f : Symbol(f, Decl(logicalAssignment5.ts, 0, 15)) +} + +function foo2 (f?: (a: number) => void) { +>foo2 : Symbol(foo2, Decl(logicalAssignment5.ts, 3, 1)) +>f : Symbol(f, Decl(logicalAssignment5.ts, 5, 15)) +>a : Symbol(a, Decl(logicalAssignment5.ts, 5, 20)) + + f ||= (a => a) +>f : Symbol(f, Decl(logicalAssignment5.ts, 5, 15)) +>a : Symbol(a, Decl(logicalAssignment5.ts, 6, 11)) +>a : Symbol(a, Decl(logicalAssignment5.ts, 6, 11)) + + f(42) +>f : Symbol(f, Decl(logicalAssignment5.ts, 5, 15)) +} + +function foo3 (f?: (a: number) => void) { +>foo3 : Symbol(foo3, Decl(logicalAssignment5.ts, 8, 1)) +>f : Symbol(f, Decl(logicalAssignment5.ts, 10, 15)) +>a : Symbol(a, Decl(logicalAssignment5.ts, 10, 20)) + + f &&= (a => a) +>f : Symbol(f, Decl(logicalAssignment5.ts, 10, 15)) +>a : Symbol(a, Decl(logicalAssignment5.ts, 11, 11)) +>a : Symbol(a, Decl(logicalAssignment5.ts, 11, 11)) + + f(42) +>f : Symbol(f, Decl(logicalAssignment5.ts, 10, 15)) +} + +function bar1 (f?: (a: number) => void) { +>bar1 : Symbol(bar1, Decl(logicalAssignment5.ts, 13, 1)) +>f : Symbol(f, Decl(logicalAssignment5.ts, 15, 15)) +>a : Symbol(a, Decl(logicalAssignment5.ts, 15, 20)) + + f ??= (f.toString(), (a => a)) +>f : Symbol(f, Decl(logicalAssignment5.ts, 15, 15)) +>f : Symbol(f, Decl(logicalAssignment5.ts, 15, 15)) +>a : Symbol(a, Decl(logicalAssignment5.ts, 16, 26)) +>a : Symbol(a, Decl(logicalAssignment5.ts, 16, 26)) + + f(42) +>f : Symbol(f, Decl(logicalAssignment5.ts, 15, 15)) +} + +function bar2 (f?: (a: number) => void) { +>bar2 : Symbol(bar2, Decl(logicalAssignment5.ts, 18, 1)) +>f : Symbol(f, Decl(logicalAssignment5.ts, 20, 15)) +>a : Symbol(a, Decl(logicalAssignment5.ts, 20, 20)) + + f ||= (f.toString(), (a => a)) +>f : Symbol(f, Decl(logicalAssignment5.ts, 20, 15)) +>f : Symbol(f, Decl(logicalAssignment5.ts, 20, 15)) +>a : Symbol(a, Decl(logicalAssignment5.ts, 21, 26)) +>a : Symbol(a, Decl(logicalAssignment5.ts, 21, 26)) + + f(42) +>f : Symbol(f, Decl(logicalAssignment5.ts, 20, 15)) +} + +function bar3 (f?: (a: number) => void) { +>bar3 : Symbol(bar3, Decl(logicalAssignment5.ts, 23, 1)) +>f : Symbol(f, Decl(logicalAssignment5.ts, 25, 15)) +>a : Symbol(a, Decl(logicalAssignment5.ts, 25, 20)) + + f &&= (f.toString(), (a => a)) +>f : Symbol(f, Decl(logicalAssignment5.ts, 25, 15)) +>f.toString : Symbol(Function.toString, Decl(lib.es5.d.ts, --, --)) +>f : Symbol(f, Decl(logicalAssignment5.ts, 25, 15)) +>toString : Symbol(Function.toString, Decl(lib.es5.d.ts, --, --)) +>a : Symbol(a, Decl(logicalAssignment5.ts, 26, 26)) +>a : Symbol(a, Decl(logicalAssignment5.ts, 26, 26)) + + f(42) +>f : Symbol(f, Decl(logicalAssignment5.ts, 25, 15)) +} + diff --git a/tests/baselines/reference/logicalAssignment5(target=es2020).types b/tests/baselines/reference/logicalAssignment5(target=es2020).types new file mode 100644 index 00000000000..694c3db90a5 --- /dev/null +++ b/tests/baselines/reference/logicalAssignment5(target=es2020).types @@ -0,0 +1,133 @@ +=== tests/cases/conformance/esnext/logicalAssignment/logicalAssignment5.ts === +function foo1 (f?: (a: number) => void) { +>foo1 : (f?: ((a: number) => void) | undefined) => void +>f : ((a: number) => void) | undefined +>a : number + + f ??= (a => a) +>f ??= (a => a) : (a: number) => void +>f : ((a: number) => void) | undefined +>(a => a) : (a: number) => number +>a => a : (a: number) => number +>a : number +>a : number + + f(42) +>f(42) : void +>f : (a: number) => void +>42 : 42 +} + +function foo2 (f?: (a: number) => void) { +>foo2 : (f?: ((a: number) => void) | undefined) => void +>f : ((a: number) => void) | undefined +>a : number + + f ||= (a => a) +>f ||= (a => a) : (a: number) => void +>f : ((a: number) => void) | undefined +>(a => a) : (a: number) => number +>a => a : (a: number) => number +>a : number +>a : number + + f(42) +>f(42) : void +>f : (a: number) => void +>42 : 42 +} + +function foo3 (f?: (a: number) => void) { +>foo3 : (f?: ((a: number) => void) | undefined) => void +>f : ((a: number) => void) | undefined +>a : number + + f &&= (a => a) +>f &&= (a => a) : ((a: any) => any) | undefined +>f : ((a: number) => void) | undefined +>(a => a) : (a: any) => any +>a => a : (a: any) => any +>a : any +>a : any + + f(42) +>f(42) : any +>f : undefined +>42 : 42 +} + +function bar1 (f?: (a: number) => void) { +>bar1 : (f?: ((a: number) => void) | undefined) => void +>f : ((a: number) => void) | undefined +>a : number + + f ??= (f.toString(), (a => a)) +>f ??= (f.toString(), (a => a)) : (a: number) => void +>f : ((a: number) => void) | undefined +>(f.toString(), (a => a)) : (a: number) => number +>f.toString(), (a => a) : (a: number) => number +>f.toString() : any +>f.toString : any +>f : undefined +>toString : any +>(a => a) : (a: number) => number +>a => a : (a: number) => number +>a : number +>a : number + + f(42) +>f(42) : void +>f : (a: number) => void +>42 : 42 +} + +function bar2 (f?: (a: number) => void) { +>bar2 : (f?: ((a: number) => void) | undefined) => void +>f : ((a: number) => void) | undefined +>a : number + + f ||= (f.toString(), (a => a)) +>f ||= (f.toString(), (a => a)) : (a: number) => void +>f : ((a: number) => void) | undefined +>(f.toString(), (a => a)) : (a: number) => number +>f.toString(), (a => a) : (a: number) => number +>f.toString() : any +>f.toString : any +>f : undefined +>toString : any +>(a => a) : (a: number) => number +>a => a : (a: number) => number +>a : number +>a : number + + f(42) +>f(42) : void +>f : (a: number) => void +>42 : 42 +} + +function bar3 (f?: (a: number) => void) { +>bar3 : (f?: ((a: number) => void) | undefined) => void +>f : ((a: number) => void) | undefined +>a : number + + f &&= (f.toString(), (a => a)) +>f &&= (f.toString(), (a => a)) : ((a: any) => any) | undefined +>f : ((a: number) => void) | undefined +>(f.toString(), (a => a)) : (a: any) => any +>f.toString(), (a => a) : (a: any) => any +>f.toString() : string +>f.toString : () => string +>f : (a: number) => void +>toString : () => string +>(a => a) : (a: any) => any +>a => a : (a: any) => any +>a : any +>a : any + + f(42) +>f(42) : any +>f : undefined +>42 : 42 +} + diff --git a/tests/baselines/reference/logicalAssignment5(target=esnext).errors.txt b/tests/baselines/reference/logicalAssignment5(target=esnext).errors.txt new file mode 100644 index 00000000000..663162e9165 --- /dev/null +++ b/tests/baselines/reference/logicalAssignment5(target=esnext).errors.txt @@ -0,0 +1,51 @@ +tests/cases/conformance/esnext/logicalAssignment/logicalAssignment5.ts(12,12): error TS7006: Parameter 'a' implicitly has an 'any' type. +tests/cases/conformance/esnext/logicalAssignment/logicalAssignment5.ts(13,5): error TS2722: Cannot invoke an object which is possibly 'undefined'. +tests/cases/conformance/esnext/logicalAssignment/logicalAssignment5.ts(17,12): error TS2532: Object is possibly 'undefined'. +tests/cases/conformance/esnext/logicalAssignment/logicalAssignment5.ts(22,12): error TS2532: Object is possibly 'undefined'. +tests/cases/conformance/esnext/logicalAssignment/logicalAssignment5.ts(27,27): error TS7006: Parameter 'a' implicitly has an 'any' type. +tests/cases/conformance/esnext/logicalAssignment/logicalAssignment5.ts(28,5): error TS2722: Cannot invoke an object which is possibly 'undefined'. + + +==== tests/cases/conformance/esnext/logicalAssignment/logicalAssignment5.ts (6 errors) ==== + function foo1 (f?: (a: number) => void) { + f ??= (a => a) + f(42) + } + + function foo2 (f?: (a: number) => void) { + f ||= (a => a) + f(42) + } + + function foo3 (f?: (a: number) => void) { + f &&= (a => a) + ~ +!!! error TS7006: Parameter 'a' implicitly has an 'any' type. + f(42) + ~ +!!! error TS2722: Cannot invoke an object which is possibly 'undefined'. + } + + function bar1 (f?: (a: number) => void) { + f ??= (f.toString(), (a => a)) + ~ +!!! error TS2532: Object is possibly 'undefined'. + f(42) + } + + function bar2 (f?: (a: number) => void) { + f ||= (f.toString(), (a => a)) + ~ +!!! error TS2532: Object is possibly 'undefined'. + f(42) + } + + function bar3 (f?: (a: number) => void) { + f &&= (f.toString(), (a => a)) + ~ +!!! error TS7006: Parameter 'a' implicitly has an 'any' type. + f(42) + ~ +!!! error TS2722: Cannot invoke an object which is possibly 'undefined'. + } + \ No newline at end of file diff --git a/tests/baselines/reference/logicalAssignment5(target=esnext).js b/tests/baselines/reference/logicalAssignment5(target=esnext).js new file mode 100644 index 00000000000..21d965459dc --- /dev/null +++ b/tests/baselines/reference/logicalAssignment5(target=esnext).js @@ -0,0 +1,58 @@ +//// [logicalAssignment5.ts] +function foo1 (f?: (a: number) => void) { + f ??= (a => a) + f(42) +} + +function foo2 (f?: (a: number) => void) { + f ||= (a => a) + f(42) +} + +function foo3 (f?: (a: number) => void) { + f &&= (a => a) + f(42) +} + +function bar1 (f?: (a: number) => void) { + f ??= (f.toString(), (a => a)) + f(42) +} + +function bar2 (f?: (a: number) => void) { + f ||= (f.toString(), (a => a)) + f(42) +} + +function bar3 (f?: (a: number) => void) { + f &&= (f.toString(), (a => a)) + f(42) +} + + +//// [logicalAssignment5.js] +"use strict"; +function foo1(f) { + f ??= (a => a); + f(42); +} +function foo2(f) { + f ||= (a => a); + f(42); +} +function foo3(f) { + f &&= (a => a); + f(42); +} +function bar1(f) { + f ??= (f.toString(), (a => a)); + f(42); +} +function bar2(f) { + f ||= (f.toString(), (a => a)); + f(42); +} +function bar3(f) { + f &&= (f.toString(), (a => a)); + f(42); +} diff --git a/tests/baselines/reference/logicalAssignment5(target=esnext).symbols b/tests/baselines/reference/logicalAssignment5(target=esnext).symbols new file mode 100644 index 00000000000..5862d6b68d4 --- /dev/null +++ b/tests/baselines/reference/logicalAssignment5(target=esnext).symbols @@ -0,0 +1,90 @@ +=== tests/cases/conformance/esnext/logicalAssignment/logicalAssignment5.ts === +function foo1 (f?: (a: number) => void) { +>foo1 : Symbol(foo1, Decl(logicalAssignment5.ts, 0, 0)) +>f : Symbol(f, Decl(logicalAssignment5.ts, 0, 15)) +>a : Symbol(a, Decl(logicalAssignment5.ts, 0, 20)) + + f ??= (a => a) +>f : Symbol(f, Decl(logicalAssignment5.ts, 0, 15)) +>a : Symbol(a, Decl(logicalAssignment5.ts, 1, 11)) +>a : Symbol(a, Decl(logicalAssignment5.ts, 1, 11)) + + f(42) +>f : Symbol(f, Decl(logicalAssignment5.ts, 0, 15)) +} + +function foo2 (f?: (a: number) => void) { +>foo2 : Symbol(foo2, Decl(logicalAssignment5.ts, 3, 1)) +>f : Symbol(f, Decl(logicalAssignment5.ts, 5, 15)) +>a : Symbol(a, Decl(logicalAssignment5.ts, 5, 20)) + + f ||= (a => a) +>f : Symbol(f, Decl(logicalAssignment5.ts, 5, 15)) +>a : Symbol(a, Decl(logicalAssignment5.ts, 6, 11)) +>a : Symbol(a, Decl(logicalAssignment5.ts, 6, 11)) + + f(42) +>f : Symbol(f, Decl(logicalAssignment5.ts, 5, 15)) +} + +function foo3 (f?: (a: number) => void) { +>foo3 : Symbol(foo3, Decl(logicalAssignment5.ts, 8, 1)) +>f : Symbol(f, Decl(logicalAssignment5.ts, 10, 15)) +>a : Symbol(a, Decl(logicalAssignment5.ts, 10, 20)) + + f &&= (a => a) +>f : Symbol(f, Decl(logicalAssignment5.ts, 10, 15)) +>a : Symbol(a, Decl(logicalAssignment5.ts, 11, 11)) +>a : Symbol(a, Decl(logicalAssignment5.ts, 11, 11)) + + f(42) +>f : Symbol(f, Decl(logicalAssignment5.ts, 10, 15)) +} + +function bar1 (f?: (a: number) => void) { +>bar1 : Symbol(bar1, Decl(logicalAssignment5.ts, 13, 1)) +>f : Symbol(f, Decl(logicalAssignment5.ts, 15, 15)) +>a : Symbol(a, Decl(logicalAssignment5.ts, 15, 20)) + + f ??= (f.toString(), (a => a)) +>f : Symbol(f, Decl(logicalAssignment5.ts, 15, 15)) +>f : Symbol(f, Decl(logicalAssignment5.ts, 15, 15)) +>a : Symbol(a, Decl(logicalAssignment5.ts, 16, 26)) +>a : Symbol(a, Decl(logicalAssignment5.ts, 16, 26)) + + f(42) +>f : Symbol(f, Decl(logicalAssignment5.ts, 15, 15)) +} + +function bar2 (f?: (a: number) => void) { +>bar2 : Symbol(bar2, Decl(logicalAssignment5.ts, 18, 1)) +>f : Symbol(f, Decl(logicalAssignment5.ts, 20, 15)) +>a : Symbol(a, Decl(logicalAssignment5.ts, 20, 20)) + + f ||= (f.toString(), (a => a)) +>f : Symbol(f, Decl(logicalAssignment5.ts, 20, 15)) +>f : Symbol(f, Decl(logicalAssignment5.ts, 20, 15)) +>a : Symbol(a, Decl(logicalAssignment5.ts, 21, 26)) +>a : Symbol(a, Decl(logicalAssignment5.ts, 21, 26)) + + f(42) +>f : Symbol(f, Decl(logicalAssignment5.ts, 20, 15)) +} + +function bar3 (f?: (a: number) => void) { +>bar3 : Symbol(bar3, Decl(logicalAssignment5.ts, 23, 1)) +>f : Symbol(f, Decl(logicalAssignment5.ts, 25, 15)) +>a : Symbol(a, Decl(logicalAssignment5.ts, 25, 20)) + + f &&= (f.toString(), (a => a)) +>f : Symbol(f, Decl(logicalAssignment5.ts, 25, 15)) +>f.toString : Symbol(Function.toString, Decl(lib.es5.d.ts, --, --)) +>f : Symbol(f, Decl(logicalAssignment5.ts, 25, 15)) +>toString : Symbol(Function.toString, Decl(lib.es5.d.ts, --, --)) +>a : Symbol(a, Decl(logicalAssignment5.ts, 26, 26)) +>a : Symbol(a, Decl(logicalAssignment5.ts, 26, 26)) + + f(42) +>f : Symbol(f, Decl(logicalAssignment5.ts, 25, 15)) +} + diff --git a/tests/baselines/reference/logicalAssignment5(target=esnext).types b/tests/baselines/reference/logicalAssignment5(target=esnext).types new file mode 100644 index 00000000000..694c3db90a5 --- /dev/null +++ b/tests/baselines/reference/logicalAssignment5(target=esnext).types @@ -0,0 +1,133 @@ +=== tests/cases/conformance/esnext/logicalAssignment/logicalAssignment5.ts === +function foo1 (f?: (a: number) => void) { +>foo1 : (f?: ((a: number) => void) | undefined) => void +>f : ((a: number) => void) | undefined +>a : number + + f ??= (a => a) +>f ??= (a => a) : (a: number) => void +>f : ((a: number) => void) | undefined +>(a => a) : (a: number) => number +>a => a : (a: number) => number +>a : number +>a : number + + f(42) +>f(42) : void +>f : (a: number) => void +>42 : 42 +} + +function foo2 (f?: (a: number) => void) { +>foo2 : (f?: ((a: number) => void) | undefined) => void +>f : ((a: number) => void) | undefined +>a : number + + f ||= (a => a) +>f ||= (a => a) : (a: number) => void +>f : ((a: number) => void) | undefined +>(a => a) : (a: number) => number +>a => a : (a: number) => number +>a : number +>a : number + + f(42) +>f(42) : void +>f : (a: number) => void +>42 : 42 +} + +function foo3 (f?: (a: number) => void) { +>foo3 : (f?: ((a: number) => void) | undefined) => void +>f : ((a: number) => void) | undefined +>a : number + + f &&= (a => a) +>f &&= (a => a) : ((a: any) => any) | undefined +>f : ((a: number) => void) | undefined +>(a => a) : (a: any) => any +>a => a : (a: any) => any +>a : any +>a : any + + f(42) +>f(42) : any +>f : undefined +>42 : 42 +} + +function bar1 (f?: (a: number) => void) { +>bar1 : (f?: ((a: number) => void) | undefined) => void +>f : ((a: number) => void) | undefined +>a : number + + f ??= (f.toString(), (a => a)) +>f ??= (f.toString(), (a => a)) : (a: number) => void +>f : ((a: number) => void) | undefined +>(f.toString(), (a => a)) : (a: number) => number +>f.toString(), (a => a) : (a: number) => number +>f.toString() : any +>f.toString : any +>f : undefined +>toString : any +>(a => a) : (a: number) => number +>a => a : (a: number) => number +>a : number +>a : number + + f(42) +>f(42) : void +>f : (a: number) => void +>42 : 42 +} + +function bar2 (f?: (a: number) => void) { +>bar2 : (f?: ((a: number) => void) | undefined) => void +>f : ((a: number) => void) | undefined +>a : number + + f ||= (f.toString(), (a => a)) +>f ||= (f.toString(), (a => a)) : (a: number) => void +>f : ((a: number) => void) | undefined +>(f.toString(), (a => a)) : (a: number) => number +>f.toString(), (a => a) : (a: number) => number +>f.toString() : any +>f.toString : any +>f : undefined +>toString : any +>(a => a) : (a: number) => number +>a => a : (a: number) => number +>a : number +>a : number + + f(42) +>f(42) : void +>f : (a: number) => void +>42 : 42 +} + +function bar3 (f?: (a: number) => void) { +>bar3 : (f?: ((a: number) => void) | undefined) => void +>f : ((a: number) => void) | undefined +>a : number + + f &&= (f.toString(), (a => a)) +>f &&= (f.toString(), (a => a)) : ((a: any) => any) | undefined +>f : ((a: number) => void) | undefined +>(f.toString(), (a => a)) : (a: any) => any +>f.toString(), (a => a) : (a: any) => any +>f.toString() : string +>f.toString : () => string +>f : (a: number) => void +>toString : () => string +>(a => a) : (a: any) => any +>a => a : (a: any) => any +>a : any +>a : any + + f(42) +>f(42) : any +>f : undefined +>42 : 42 +} + diff --git a/tests/baselines/reference/logicalAssignment6(target=es2015).errors.txt b/tests/baselines/reference/logicalAssignment6(target=es2015).errors.txt new file mode 100644 index 00000000000..0af71a2ba4e --- /dev/null +++ b/tests/baselines/reference/logicalAssignment6(target=es2015).errors.txt @@ -0,0 +1,20 @@ +tests/cases/conformance/esnext/logicalAssignment/logicalAssignment6.ts(10,5): error TS2532: Object is possibly 'undefined'. +tests/cases/conformance/esnext/logicalAssignment/logicalAssignment6.ts(10,42): error TS2345: Argument of type '100' is not assignable to parameter of type 'never'. + + +==== tests/cases/conformance/esnext/logicalAssignment/logicalAssignment6.ts (2 errors) ==== + function foo1(results: number[] | undefined, results1: number[] | undefined) { + (results ||= (results1 ||= [])).push(100); + } + + function foo2(results: number[] | undefined, results1: number[] | undefined) { + (results ??= (results1 ??= [])).push(100); + } + + function foo3(results: number[] | undefined, results1: number[] | undefined) { + (results &&= (results1 &&= [])).push(100); + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2532: Object is possibly 'undefined'. + ~~~ +!!! error TS2345: Argument of type '100' is not assignable to parameter of type 'never'. + } \ No newline at end of file diff --git a/tests/baselines/reference/logicalAssignment6(target=es2015).js b/tests/baselines/reference/logicalAssignment6(target=es2015).js new file mode 100644 index 00000000000..a0424da1778 --- /dev/null +++ b/tests/baselines/reference/logicalAssignment6(target=es2015).js @@ -0,0 +1,24 @@ +//// [logicalAssignment6.ts] +function foo1(results: number[] | undefined, results1: number[] | undefined) { + (results ||= (results1 ||= [])).push(100); +} + +function foo2(results: number[] | undefined, results1: number[] | undefined) { + (results ??= (results1 ??= [])).push(100); +} + +function foo3(results: number[] | undefined, results1: number[] | undefined) { + (results &&= (results1 &&= [])).push(100); +} + +//// [logicalAssignment6.js] +"use strict"; +function foo1(results, results1) { + (results || (results = (results1 || (results1 = [])))).push(100); +} +function foo2(results, results1) { + (results !== null && results !== void 0 ? results : (results = (results1 !== null && results1 !== void 0 ? results1 : (results1 = [])))).push(100); +} +function foo3(results, results1) { + (results && (results = (results1 && (results1 = [])))).push(100); +} diff --git a/tests/baselines/reference/logicalAssignment6(target=es2015).symbols b/tests/baselines/reference/logicalAssignment6(target=es2015).symbols new file mode 100644 index 00000000000..d91ebbaa450 --- /dev/null +++ b/tests/baselines/reference/logicalAssignment6(target=es2015).symbols @@ -0,0 +1,36 @@ +=== tests/cases/conformance/esnext/logicalAssignment/logicalAssignment6.ts === +function foo1(results: number[] | undefined, results1: number[] | undefined) { +>foo1 : Symbol(foo1, Decl(logicalAssignment6.ts, 0, 0)) +>results : Symbol(results, Decl(logicalAssignment6.ts, 0, 14)) +>results1 : Symbol(results1, Decl(logicalAssignment6.ts, 0, 44)) + + (results ||= (results1 ||= [])).push(100); +>(results ||= (results1 ||= [])).push : Symbol(Array.push, Decl(lib.es5.d.ts, --, --)) +>results : Symbol(results, Decl(logicalAssignment6.ts, 0, 14)) +>results1 : Symbol(results1, Decl(logicalAssignment6.ts, 0, 44)) +>push : Symbol(Array.push, Decl(lib.es5.d.ts, --, --)) +} + +function foo2(results: number[] | undefined, results1: number[] | undefined) { +>foo2 : Symbol(foo2, Decl(logicalAssignment6.ts, 2, 1)) +>results : Symbol(results, Decl(logicalAssignment6.ts, 4, 14)) +>results1 : Symbol(results1, Decl(logicalAssignment6.ts, 4, 44)) + + (results ??= (results1 ??= [])).push(100); +>(results ??= (results1 ??= [])).push : Symbol(Array.push, Decl(lib.es5.d.ts, --, --)) +>results : Symbol(results, Decl(logicalAssignment6.ts, 4, 14)) +>results1 : Symbol(results1, Decl(logicalAssignment6.ts, 4, 44)) +>push : Symbol(Array.push, Decl(lib.es5.d.ts, --, --)) +} + +function foo3(results: number[] | undefined, results1: number[] | undefined) { +>foo3 : Symbol(foo3, Decl(logicalAssignment6.ts, 6, 1)) +>results : Symbol(results, Decl(logicalAssignment6.ts, 8, 14)) +>results1 : Symbol(results1, Decl(logicalAssignment6.ts, 8, 44)) + + (results &&= (results1 &&= [])).push(100); +>(results &&= (results1 &&= [])).push : Symbol(Array.push, Decl(lib.es5.d.ts, --, --)) +>results : Symbol(results, Decl(logicalAssignment6.ts, 8, 14)) +>results1 : Symbol(results1, Decl(logicalAssignment6.ts, 8, 44)) +>push : Symbol(Array.push, Decl(lib.es5.d.ts, --, --)) +} diff --git a/tests/baselines/reference/logicalAssignment6(target=es2015).types b/tests/baselines/reference/logicalAssignment6(target=es2015).types new file mode 100644 index 00000000000..3cf295045a6 --- /dev/null +++ b/tests/baselines/reference/logicalAssignment6(target=es2015).types @@ -0,0 +1,57 @@ +=== tests/cases/conformance/esnext/logicalAssignment/logicalAssignment6.ts === +function foo1(results: number[] | undefined, results1: number[] | undefined) { +>foo1 : (results: number[] | undefined, results1: number[] | undefined) => void +>results : number[] | undefined +>results1 : number[] | undefined + + (results ||= (results1 ||= [])).push(100); +>(results ||= (results1 ||= [])).push(100) : number +>(results ||= (results1 ||= [])).push : (...items: number[]) => number +>(results ||= (results1 ||= [])) : number[] +>results ||= (results1 ||= []) : number[] +>results : number[] | undefined +>(results1 ||= []) : number[] +>results1 ||= [] : number[] +>results1 : number[] | undefined +>[] : never[] +>push : (...items: number[]) => number +>100 : 100 +} + +function foo2(results: number[] | undefined, results1: number[] | undefined) { +>foo2 : (results: number[] | undefined, results1: number[] | undefined) => void +>results : number[] | undefined +>results1 : number[] | undefined + + (results ??= (results1 ??= [])).push(100); +>(results ??= (results1 ??= [])).push(100) : number +>(results ??= (results1 ??= [])).push : (...items: number[]) => number +>(results ??= (results1 ??= [])) : number[] +>results ??= (results1 ??= []) : number[] +>results : number[] | undefined +>(results1 ??= []) : number[] +>results1 ??= [] : number[] +>results1 : number[] | undefined +>[] : never[] +>push : (...items: number[]) => number +>100 : 100 +} + +function foo3(results: number[] | undefined, results1: number[] | undefined) { +>foo3 : (results: number[] | undefined, results1: number[] | undefined) => void +>results : number[] | undefined +>results1 : number[] | undefined + + (results &&= (results1 &&= [])).push(100); +>(results &&= (results1 &&= [])).push(100) : number +>(results &&= (results1 &&= [])).push : (...items: never[]) => number +>(results &&= (results1 &&= [])) : never[] | undefined +>results &&= (results1 &&= []) : never[] | undefined +>results : number[] | undefined +>(results1 &&= []) : never[] | undefined +>results1 &&= [] : never[] | undefined +>results1 : number[] | undefined +>[] : never[] +>push : (...items: never[]) => number +>100 : 100 +} diff --git a/tests/baselines/reference/logicalAssignment6(target=es2020).errors.txt b/tests/baselines/reference/logicalAssignment6(target=es2020).errors.txt new file mode 100644 index 00000000000..0af71a2ba4e --- /dev/null +++ b/tests/baselines/reference/logicalAssignment6(target=es2020).errors.txt @@ -0,0 +1,20 @@ +tests/cases/conformance/esnext/logicalAssignment/logicalAssignment6.ts(10,5): error TS2532: Object is possibly 'undefined'. +tests/cases/conformance/esnext/logicalAssignment/logicalAssignment6.ts(10,42): error TS2345: Argument of type '100' is not assignable to parameter of type 'never'. + + +==== tests/cases/conformance/esnext/logicalAssignment/logicalAssignment6.ts (2 errors) ==== + function foo1(results: number[] | undefined, results1: number[] | undefined) { + (results ||= (results1 ||= [])).push(100); + } + + function foo2(results: number[] | undefined, results1: number[] | undefined) { + (results ??= (results1 ??= [])).push(100); + } + + function foo3(results: number[] | undefined, results1: number[] | undefined) { + (results &&= (results1 &&= [])).push(100); + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2532: Object is possibly 'undefined'. + ~~~ +!!! error TS2345: Argument of type '100' is not assignable to parameter of type 'never'. + } \ No newline at end of file diff --git a/tests/baselines/reference/logicalAssignment6(target=es2020).js b/tests/baselines/reference/logicalAssignment6(target=es2020).js new file mode 100644 index 00000000000..66852828bee --- /dev/null +++ b/tests/baselines/reference/logicalAssignment6(target=es2020).js @@ -0,0 +1,24 @@ +//// [logicalAssignment6.ts] +function foo1(results: number[] | undefined, results1: number[] | undefined) { + (results ||= (results1 ||= [])).push(100); +} + +function foo2(results: number[] | undefined, results1: number[] | undefined) { + (results ??= (results1 ??= [])).push(100); +} + +function foo3(results: number[] | undefined, results1: number[] | undefined) { + (results &&= (results1 &&= [])).push(100); +} + +//// [logicalAssignment6.js] +"use strict"; +function foo1(results, results1) { + (results || (results = (results1 || (results1 = [])))).push(100); +} +function foo2(results, results1) { + (results ?? (results = (results1 ?? (results1 = [])))).push(100); +} +function foo3(results, results1) { + (results && (results = (results1 && (results1 = [])))).push(100); +} diff --git a/tests/baselines/reference/logicalAssignment6(target=es2020).symbols b/tests/baselines/reference/logicalAssignment6(target=es2020).symbols new file mode 100644 index 00000000000..d91ebbaa450 --- /dev/null +++ b/tests/baselines/reference/logicalAssignment6(target=es2020).symbols @@ -0,0 +1,36 @@ +=== tests/cases/conformance/esnext/logicalAssignment/logicalAssignment6.ts === +function foo1(results: number[] | undefined, results1: number[] | undefined) { +>foo1 : Symbol(foo1, Decl(logicalAssignment6.ts, 0, 0)) +>results : Symbol(results, Decl(logicalAssignment6.ts, 0, 14)) +>results1 : Symbol(results1, Decl(logicalAssignment6.ts, 0, 44)) + + (results ||= (results1 ||= [])).push(100); +>(results ||= (results1 ||= [])).push : Symbol(Array.push, Decl(lib.es5.d.ts, --, --)) +>results : Symbol(results, Decl(logicalAssignment6.ts, 0, 14)) +>results1 : Symbol(results1, Decl(logicalAssignment6.ts, 0, 44)) +>push : Symbol(Array.push, Decl(lib.es5.d.ts, --, --)) +} + +function foo2(results: number[] | undefined, results1: number[] | undefined) { +>foo2 : Symbol(foo2, Decl(logicalAssignment6.ts, 2, 1)) +>results : Symbol(results, Decl(logicalAssignment6.ts, 4, 14)) +>results1 : Symbol(results1, Decl(logicalAssignment6.ts, 4, 44)) + + (results ??= (results1 ??= [])).push(100); +>(results ??= (results1 ??= [])).push : Symbol(Array.push, Decl(lib.es5.d.ts, --, --)) +>results : Symbol(results, Decl(logicalAssignment6.ts, 4, 14)) +>results1 : Symbol(results1, Decl(logicalAssignment6.ts, 4, 44)) +>push : Symbol(Array.push, Decl(lib.es5.d.ts, --, --)) +} + +function foo3(results: number[] | undefined, results1: number[] | undefined) { +>foo3 : Symbol(foo3, Decl(logicalAssignment6.ts, 6, 1)) +>results : Symbol(results, Decl(logicalAssignment6.ts, 8, 14)) +>results1 : Symbol(results1, Decl(logicalAssignment6.ts, 8, 44)) + + (results &&= (results1 &&= [])).push(100); +>(results &&= (results1 &&= [])).push : Symbol(Array.push, Decl(lib.es5.d.ts, --, --)) +>results : Symbol(results, Decl(logicalAssignment6.ts, 8, 14)) +>results1 : Symbol(results1, Decl(logicalAssignment6.ts, 8, 44)) +>push : Symbol(Array.push, Decl(lib.es5.d.ts, --, --)) +} diff --git a/tests/baselines/reference/logicalAssignment6(target=es2020).types b/tests/baselines/reference/logicalAssignment6(target=es2020).types new file mode 100644 index 00000000000..3cf295045a6 --- /dev/null +++ b/tests/baselines/reference/logicalAssignment6(target=es2020).types @@ -0,0 +1,57 @@ +=== tests/cases/conformance/esnext/logicalAssignment/logicalAssignment6.ts === +function foo1(results: number[] | undefined, results1: number[] | undefined) { +>foo1 : (results: number[] | undefined, results1: number[] | undefined) => void +>results : number[] | undefined +>results1 : number[] | undefined + + (results ||= (results1 ||= [])).push(100); +>(results ||= (results1 ||= [])).push(100) : number +>(results ||= (results1 ||= [])).push : (...items: number[]) => number +>(results ||= (results1 ||= [])) : number[] +>results ||= (results1 ||= []) : number[] +>results : number[] | undefined +>(results1 ||= []) : number[] +>results1 ||= [] : number[] +>results1 : number[] | undefined +>[] : never[] +>push : (...items: number[]) => number +>100 : 100 +} + +function foo2(results: number[] | undefined, results1: number[] | undefined) { +>foo2 : (results: number[] | undefined, results1: number[] | undefined) => void +>results : number[] | undefined +>results1 : number[] | undefined + + (results ??= (results1 ??= [])).push(100); +>(results ??= (results1 ??= [])).push(100) : number +>(results ??= (results1 ??= [])).push : (...items: number[]) => number +>(results ??= (results1 ??= [])) : number[] +>results ??= (results1 ??= []) : number[] +>results : number[] | undefined +>(results1 ??= []) : number[] +>results1 ??= [] : number[] +>results1 : number[] | undefined +>[] : never[] +>push : (...items: number[]) => number +>100 : 100 +} + +function foo3(results: number[] | undefined, results1: number[] | undefined) { +>foo3 : (results: number[] | undefined, results1: number[] | undefined) => void +>results : number[] | undefined +>results1 : number[] | undefined + + (results &&= (results1 &&= [])).push(100); +>(results &&= (results1 &&= [])).push(100) : number +>(results &&= (results1 &&= [])).push : (...items: never[]) => number +>(results &&= (results1 &&= [])) : never[] | undefined +>results &&= (results1 &&= []) : never[] | undefined +>results : number[] | undefined +>(results1 &&= []) : never[] | undefined +>results1 &&= [] : never[] | undefined +>results1 : number[] | undefined +>[] : never[] +>push : (...items: never[]) => number +>100 : 100 +} diff --git a/tests/baselines/reference/logicalAssignment6(target=esnext).errors.txt b/tests/baselines/reference/logicalAssignment6(target=esnext).errors.txt new file mode 100644 index 00000000000..0af71a2ba4e --- /dev/null +++ b/tests/baselines/reference/logicalAssignment6(target=esnext).errors.txt @@ -0,0 +1,20 @@ +tests/cases/conformance/esnext/logicalAssignment/logicalAssignment6.ts(10,5): error TS2532: Object is possibly 'undefined'. +tests/cases/conformance/esnext/logicalAssignment/logicalAssignment6.ts(10,42): error TS2345: Argument of type '100' is not assignable to parameter of type 'never'. + + +==== tests/cases/conformance/esnext/logicalAssignment/logicalAssignment6.ts (2 errors) ==== + function foo1(results: number[] | undefined, results1: number[] | undefined) { + (results ||= (results1 ||= [])).push(100); + } + + function foo2(results: number[] | undefined, results1: number[] | undefined) { + (results ??= (results1 ??= [])).push(100); + } + + function foo3(results: number[] | undefined, results1: number[] | undefined) { + (results &&= (results1 &&= [])).push(100); + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2532: Object is possibly 'undefined'. + ~~~ +!!! error TS2345: Argument of type '100' is not assignable to parameter of type 'never'. + } \ No newline at end of file diff --git a/tests/baselines/reference/logicalAssignment6(target=esnext).js b/tests/baselines/reference/logicalAssignment6(target=esnext).js new file mode 100644 index 00000000000..9d209c9e301 --- /dev/null +++ b/tests/baselines/reference/logicalAssignment6(target=esnext).js @@ -0,0 +1,24 @@ +//// [logicalAssignment6.ts] +function foo1(results: number[] | undefined, results1: number[] | undefined) { + (results ||= (results1 ||= [])).push(100); +} + +function foo2(results: number[] | undefined, results1: number[] | undefined) { + (results ??= (results1 ??= [])).push(100); +} + +function foo3(results: number[] | undefined, results1: number[] | undefined) { + (results &&= (results1 &&= [])).push(100); +} + +//// [logicalAssignment6.js] +"use strict"; +function foo1(results, results1) { + (results ||= (results1 ||= [])).push(100); +} +function foo2(results, results1) { + (results ??= (results1 ??= [])).push(100); +} +function foo3(results, results1) { + (results &&= (results1 &&= [])).push(100); +} diff --git a/tests/baselines/reference/logicalAssignment6(target=esnext).symbols b/tests/baselines/reference/logicalAssignment6(target=esnext).symbols new file mode 100644 index 00000000000..d91ebbaa450 --- /dev/null +++ b/tests/baselines/reference/logicalAssignment6(target=esnext).symbols @@ -0,0 +1,36 @@ +=== tests/cases/conformance/esnext/logicalAssignment/logicalAssignment6.ts === +function foo1(results: number[] | undefined, results1: number[] | undefined) { +>foo1 : Symbol(foo1, Decl(logicalAssignment6.ts, 0, 0)) +>results : Symbol(results, Decl(logicalAssignment6.ts, 0, 14)) +>results1 : Symbol(results1, Decl(logicalAssignment6.ts, 0, 44)) + + (results ||= (results1 ||= [])).push(100); +>(results ||= (results1 ||= [])).push : Symbol(Array.push, Decl(lib.es5.d.ts, --, --)) +>results : Symbol(results, Decl(logicalAssignment6.ts, 0, 14)) +>results1 : Symbol(results1, Decl(logicalAssignment6.ts, 0, 44)) +>push : Symbol(Array.push, Decl(lib.es5.d.ts, --, --)) +} + +function foo2(results: number[] | undefined, results1: number[] | undefined) { +>foo2 : Symbol(foo2, Decl(logicalAssignment6.ts, 2, 1)) +>results : Symbol(results, Decl(logicalAssignment6.ts, 4, 14)) +>results1 : Symbol(results1, Decl(logicalAssignment6.ts, 4, 44)) + + (results ??= (results1 ??= [])).push(100); +>(results ??= (results1 ??= [])).push : Symbol(Array.push, Decl(lib.es5.d.ts, --, --)) +>results : Symbol(results, Decl(logicalAssignment6.ts, 4, 14)) +>results1 : Symbol(results1, Decl(logicalAssignment6.ts, 4, 44)) +>push : Symbol(Array.push, Decl(lib.es5.d.ts, --, --)) +} + +function foo3(results: number[] | undefined, results1: number[] | undefined) { +>foo3 : Symbol(foo3, Decl(logicalAssignment6.ts, 6, 1)) +>results : Symbol(results, Decl(logicalAssignment6.ts, 8, 14)) +>results1 : Symbol(results1, Decl(logicalAssignment6.ts, 8, 44)) + + (results &&= (results1 &&= [])).push(100); +>(results &&= (results1 &&= [])).push : Symbol(Array.push, Decl(lib.es5.d.ts, --, --)) +>results : Symbol(results, Decl(logicalAssignment6.ts, 8, 14)) +>results1 : Symbol(results1, Decl(logicalAssignment6.ts, 8, 44)) +>push : Symbol(Array.push, Decl(lib.es5.d.ts, --, --)) +} diff --git a/tests/baselines/reference/logicalAssignment6(target=esnext).types b/tests/baselines/reference/logicalAssignment6(target=esnext).types new file mode 100644 index 00000000000..3cf295045a6 --- /dev/null +++ b/tests/baselines/reference/logicalAssignment6(target=esnext).types @@ -0,0 +1,57 @@ +=== tests/cases/conformance/esnext/logicalAssignment/logicalAssignment6.ts === +function foo1(results: number[] | undefined, results1: number[] | undefined) { +>foo1 : (results: number[] | undefined, results1: number[] | undefined) => void +>results : number[] | undefined +>results1 : number[] | undefined + + (results ||= (results1 ||= [])).push(100); +>(results ||= (results1 ||= [])).push(100) : number +>(results ||= (results1 ||= [])).push : (...items: number[]) => number +>(results ||= (results1 ||= [])) : number[] +>results ||= (results1 ||= []) : number[] +>results : number[] | undefined +>(results1 ||= []) : number[] +>results1 ||= [] : number[] +>results1 : number[] | undefined +>[] : never[] +>push : (...items: number[]) => number +>100 : 100 +} + +function foo2(results: number[] | undefined, results1: number[] | undefined) { +>foo2 : (results: number[] | undefined, results1: number[] | undefined) => void +>results : number[] | undefined +>results1 : number[] | undefined + + (results ??= (results1 ??= [])).push(100); +>(results ??= (results1 ??= [])).push(100) : number +>(results ??= (results1 ??= [])).push : (...items: number[]) => number +>(results ??= (results1 ??= [])) : number[] +>results ??= (results1 ??= []) : number[] +>results : number[] | undefined +>(results1 ??= []) : number[] +>results1 ??= [] : number[] +>results1 : number[] | undefined +>[] : never[] +>push : (...items: number[]) => number +>100 : 100 +} + +function foo3(results: number[] | undefined, results1: number[] | undefined) { +>foo3 : (results: number[] | undefined, results1: number[] | undefined) => void +>results : number[] | undefined +>results1 : number[] | undefined + + (results &&= (results1 &&= [])).push(100); +>(results &&= (results1 &&= [])).push(100) : number +>(results &&= (results1 &&= [])).push : (...items: never[]) => number +>(results &&= (results1 &&= [])) : never[] | undefined +>results &&= (results1 &&= []) : never[] | undefined +>results : number[] | undefined +>(results1 &&= []) : never[] | undefined +>results1 &&= [] : never[] | undefined +>results1 : number[] | undefined +>[] : never[] +>push : (...items: never[]) => number +>100 : 100 +} diff --git a/tests/baselines/reference/logicalAssignment7(target=es2015).errors.txt b/tests/baselines/reference/logicalAssignment7(target=es2015).errors.txt new file mode 100644 index 00000000000..4eec0ce2d11 --- /dev/null +++ b/tests/baselines/reference/logicalAssignment7(target=es2015).errors.txt @@ -0,0 +1,29 @@ +tests/cases/conformance/esnext/logicalAssignment/logicalAssignment7.ts(2,6): error TS2364: The left-hand side of an assignment expression must be a variable or a property access. +tests/cases/conformance/esnext/logicalAssignment/logicalAssignment7.ts(6,6): error TS2364: The left-hand side of an assignment expression must be a variable or a property access. +tests/cases/conformance/esnext/logicalAssignment/logicalAssignment7.ts(10,5): error TS2532: Object is possibly 'undefined'. +tests/cases/conformance/esnext/logicalAssignment/logicalAssignment7.ts(10,6): error TS2364: The left-hand side of an assignment expression must be a variable or a property access. +tests/cases/conformance/esnext/logicalAssignment/logicalAssignment7.ts(10,40): error TS2345: Argument of type '100' is not assignable to parameter of type 'never'. + + +==== tests/cases/conformance/esnext/logicalAssignment/logicalAssignment7.ts (5 errors) ==== + function foo1(results: number[] | undefined, results1: number[] | undefined) { + (results ||= results1 ||= []).push(100); + ~~~~~~~~~~~~~~~~~~~~ +!!! error TS2364: The left-hand side of an assignment expression must be a variable or a property access. + } + + function foo2(results: number[] | undefined, results1: number[] | undefined) { + (results ??= results1 ??= []).push(100); + ~~~~~~~~~~~~~~~~~~~~ +!!! error TS2364: The left-hand side of an assignment expression must be a variable or a property access. + } + + function foo3(results: number[] | undefined, results1: number[] | undefined) { + (results &&= results1 &&= []).push(100); + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2532: Object is possibly 'undefined'. + ~~~~~~~~~~~~~~~~~~~~ +!!! error TS2364: The left-hand side of an assignment expression must be a variable or a property access. + ~~~ +!!! error TS2345: Argument of type '100' is not assignable to parameter of type 'never'. + } \ No newline at end of file diff --git a/tests/baselines/reference/logicalAssignment7(target=es2015).js b/tests/baselines/reference/logicalAssignment7(target=es2015).js new file mode 100644 index 00000000000..4ac2a4159b7 --- /dev/null +++ b/tests/baselines/reference/logicalAssignment7(target=es2015).js @@ -0,0 +1,25 @@ +//// [logicalAssignment7.ts] +function foo1(results: number[] | undefined, results1: number[] | undefined) { + (results ||= results1 ||= []).push(100); +} + +function foo2(results: number[] | undefined, results1: number[] | undefined) { + (results ??= results1 ??= []).push(100); +} + +function foo3(results: number[] | undefined, results1: number[] | undefined) { + (results &&= results1 &&= []).push(100); +} + +//// [logicalAssignment7.js] +"use strict"; +function foo1(results, results1) { + (results || (results = results1) || (results || (results = results1) = [])).push(100); +} +function foo2(results, results1) { + var _a; + ((_a = results !== null && results !== void 0 ? results : (results = results1)) !== null && _a !== void 0 ? _a : (results !== null && results !== void 0 ? results : (results = results1) = [])).push(100); +} +function foo3(results, results1) { + (results && (results = results1) && (results && (results = results1) = [])).push(100); +} diff --git a/tests/baselines/reference/logicalAssignment7(target=es2015).symbols b/tests/baselines/reference/logicalAssignment7(target=es2015).symbols new file mode 100644 index 00000000000..7bde5161df5 --- /dev/null +++ b/tests/baselines/reference/logicalAssignment7(target=es2015).symbols @@ -0,0 +1,36 @@ +=== tests/cases/conformance/esnext/logicalAssignment/logicalAssignment7.ts === +function foo1(results: number[] | undefined, results1: number[] | undefined) { +>foo1 : Symbol(foo1, Decl(logicalAssignment7.ts, 0, 0)) +>results : Symbol(results, Decl(logicalAssignment7.ts, 0, 14)) +>results1 : Symbol(results1, Decl(logicalAssignment7.ts, 0, 44)) + + (results ||= results1 ||= []).push(100); +>(results ||= results1 ||= []).push : Symbol(Array.push, Decl(lib.es5.d.ts, --, --)) +>results : Symbol(results, Decl(logicalAssignment7.ts, 0, 14)) +>results1 : Symbol(results1, Decl(logicalAssignment7.ts, 0, 44)) +>push : Symbol(Array.push, Decl(lib.es5.d.ts, --, --)) +} + +function foo2(results: number[] | undefined, results1: number[] | undefined) { +>foo2 : Symbol(foo2, Decl(logicalAssignment7.ts, 2, 1)) +>results : Symbol(results, Decl(logicalAssignment7.ts, 4, 14)) +>results1 : Symbol(results1, Decl(logicalAssignment7.ts, 4, 44)) + + (results ??= results1 ??= []).push(100); +>(results ??= results1 ??= []).push : Symbol(Array.push, Decl(lib.es5.d.ts, --, --)) +>results : Symbol(results, Decl(logicalAssignment7.ts, 4, 14)) +>results1 : Symbol(results1, Decl(logicalAssignment7.ts, 4, 44)) +>push : Symbol(Array.push, Decl(lib.es5.d.ts, --, --)) +} + +function foo3(results: number[] | undefined, results1: number[] | undefined) { +>foo3 : Symbol(foo3, Decl(logicalAssignment7.ts, 6, 1)) +>results : Symbol(results, Decl(logicalAssignment7.ts, 8, 14)) +>results1 : Symbol(results1, Decl(logicalAssignment7.ts, 8, 44)) + + (results &&= results1 &&= []).push(100); +>(results &&= results1 &&= []).push : Symbol(Array.push, Decl(lib.es5.d.ts, --, --)) +>results : Symbol(results, Decl(logicalAssignment7.ts, 8, 14)) +>results1 : Symbol(results1, Decl(logicalAssignment7.ts, 8, 44)) +>push : Symbol(Array.push, Decl(lib.es5.d.ts, --, --)) +} diff --git a/tests/baselines/reference/logicalAssignment7(target=es2015).types b/tests/baselines/reference/logicalAssignment7(target=es2015).types new file mode 100644 index 00000000000..b46c67c14bb --- /dev/null +++ b/tests/baselines/reference/logicalAssignment7(target=es2015).types @@ -0,0 +1,54 @@ +=== tests/cases/conformance/esnext/logicalAssignment/logicalAssignment7.ts === +function foo1(results: number[] | undefined, results1: number[] | undefined) { +>foo1 : (results: number[] | undefined, results1: number[] | undefined) => void +>results : number[] | undefined +>results1 : number[] | undefined + + (results ||= results1 ||= []).push(100); +>(results ||= results1 ||= []).push(100) : number +>(results ||= results1 ||= []).push : (...items: number[]) => number +>(results ||= results1 ||= []) : number[] +>results ||= results1 ||= [] : number[] +>results ||= results1 : number[] | undefined +>results : number[] | undefined +>results1 : number[] | undefined +>[] : never[] +>push : (...items: number[]) => number +>100 : 100 +} + +function foo2(results: number[] | undefined, results1: number[] | undefined) { +>foo2 : (results: number[] | undefined, results1: number[] | undefined) => void +>results : number[] | undefined +>results1 : number[] | undefined + + (results ??= results1 ??= []).push(100); +>(results ??= results1 ??= []).push(100) : number +>(results ??= results1 ??= []).push : (...items: number[]) => number +>(results ??= results1 ??= []) : number[] +>results ??= results1 ??= [] : number[] +>results ??= results1 : number[] | undefined +>results : number[] | undefined +>results1 : number[] | undefined +>[] : never[] +>push : (...items: number[]) => number +>100 : 100 +} + +function foo3(results: number[] | undefined, results1: number[] | undefined) { +>foo3 : (results: number[] | undefined, results1: number[] | undefined) => void +>results : number[] | undefined +>results1 : number[] | undefined + + (results &&= results1 &&= []).push(100); +>(results &&= results1 &&= []).push(100) : number +>(results &&= results1 &&= []).push : (...items: never[]) => number +>(results &&= results1 &&= []) : never[] | undefined +>results &&= results1 &&= [] : never[] | undefined +>results &&= results1 : number[] | undefined +>results : number[] | undefined +>results1 : number[] | undefined +>[] : never[] +>push : (...items: never[]) => number +>100 : 100 +} diff --git a/tests/baselines/reference/logicalAssignment7(target=es2020).errors.txt b/tests/baselines/reference/logicalAssignment7(target=es2020).errors.txt new file mode 100644 index 00000000000..4eec0ce2d11 --- /dev/null +++ b/tests/baselines/reference/logicalAssignment7(target=es2020).errors.txt @@ -0,0 +1,29 @@ +tests/cases/conformance/esnext/logicalAssignment/logicalAssignment7.ts(2,6): error TS2364: The left-hand side of an assignment expression must be a variable or a property access. +tests/cases/conformance/esnext/logicalAssignment/logicalAssignment7.ts(6,6): error TS2364: The left-hand side of an assignment expression must be a variable or a property access. +tests/cases/conformance/esnext/logicalAssignment/logicalAssignment7.ts(10,5): error TS2532: Object is possibly 'undefined'. +tests/cases/conformance/esnext/logicalAssignment/logicalAssignment7.ts(10,6): error TS2364: The left-hand side of an assignment expression must be a variable or a property access. +tests/cases/conformance/esnext/logicalAssignment/logicalAssignment7.ts(10,40): error TS2345: Argument of type '100' is not assignable to parameter of type 'never'. + + +==== tests/cases/conformance/esnext/logicalAssignment/logicalAssignment7.ts (5 errors) ==== + function foo1(results: number[] | undefined, results1: number[] | undefined) { + (results ||= results1 ||= []).push(100); + ~~~~~~~~~~~~~~~~~~~~ +!!! error TS2364: The left-hand side of an assignment expression must be a variable or a property access. + } + + function foo2(results: number[] | undefined, results1: number[] | undefined) { + (results ??= results1 ??= []).push(100); + ~~~~~~~~~~~~~~~~~~~~ +!!! error TS2364: The left-hand side of an assignment expression must be a variable or a property access. + } + + function foo3(results: number[] | undefined, results1: number[] | undefined) { + (results &&= results1 &&= []).push(100); + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2532: Object is possibly 'undefined'. + ~~~~~~~~~~~~~~~~~~~~ +!!! error TS2364: The left-hand side of an assignment expression must be a variable or a property access. + ~~~ +!!! error TS2345: Argument of type '100' is not assignable to parameter of type 'never'. + } \ No newline at end of file diff --git a/tests/baselines/reference/logicalAssignment7(target=es2020).js b/tests/baselines/reference/logicalAssignment7(target=es2020).js new file mode 100644 index 00000000000..8c0438acca6 --- /dev/null +++ b/tests/baselines/reference/logicalAssignment7(target=es2020).js @@ -0,0 +1,24 @@ +//// [logicalAssignment7.ts] +function foo1(results: number[] | undefined, results1: number[] | undefined) { + (results ||= results1 ||= []).push(100); +} + +function foo2(results: number[] | undefined, results1: number[] | undefined) { + (results ??= results1 ??= []).push(100); +} + +function foo3(results: number[] | undefined, results1: number[] | undefined) { + (results &&= results1 &&= []).push(100); +} + +//// [logicalAssignment7.js] +"use strict"; +function foo1(results, results1) { + (results || (results = results1) || (results || (results = results1) = [])).push(100); +} +function foo2(results, results1) { + (results ?? (results = results1) ?? (results ?? (results = results1) = [])).push(100); +} +function foo3(results, results1) { + (results && (results = results1) && (results && (results = results1) = [])).push(100); +} diff --git a/tests/baselines/reference/logicalAssignment7(target=es2020).symbols b/tests/baselines/reference/logicalAssignment7(target=es2020).symbols new file mode 100644 index 00000000000..7bde5161df5 --- /dev/null +++ b/tests/baselines/reference/logicalAssignment7(target=es2020).symbols @@ -0,0 +1,36 @@ +=== tests/cases/conformance/esnext/logicalAssignment/logicalAssignment7.ts === +function foo1(results: number[] | undefined, results1: number[] | undefined) { +>foo1 : Symbol(foo1, Decl(logicalAssignment7.ts, 0, 0)) +>results : Symbol(results, Decl(logicalAssignment7.ts, 0, 14)) +>results1 : Symbol(results1, Decl(logicalAssignment7.ts, 0, 44)) + + (results ||= results1 ||= []).push(100); +>(results ||= results1 ||= []).push : Symbol(Array.push, Decl(lib.es5.d.ts, --, --)) +>results : Symbol(results, Decl(logicalAssignment7.ts, 0, 14)) +>results1 : Symbol(results1, Decl(logicalAssignment7.ts, 0, 44)) +>push : Symbol(Array.push, Decl(lib.es5.d.ts, --, --)) +} + +function foo2(results: number[] | undefined, results1: number[] | undefined) { +>foo2 : Symbol(foo2, Decl(logicalAssignment7.ts, 2, 1)) +>results : Symbol(results, Decl(logicalAssignment7.ts, 4, 14)) +>results1 : Symbol(results1, Decl(logicalAssignment7.ts, 4, 44)) + + (results ??= results1 ??= []).push(100); +>(results ??= results1 ??= []).push : Symbol(Array.push, Decl(lib.es5.d.ts, --, --)) +>results : Symbol(results, Decl(logicalAssignment7.ts, 4, 14)) +>results1 : Symbol(results1, Decl(logicalAssignment7.ts, 4, 44)) +>push : Symbol(Array.push, Decl(lib.es5.d.ts, --, --)) +} + +function foo3(results: number[] | undefined, results1: number[] | undefined) { +>foo3 : Symbol(foo3, Decl(logicalAssignment7.ts, 6, 1)) +>results : Symbol(results, Decl(logicalAssignment7.ts, 8, 14)) +>results1 : Symbol(results1, Decl(logicalAssignment7.ts, 8, 44)) + + (results &&= results1 &&= []).push(100); +>(results &&= results1 &&= []).push : Symbol(Array.push, Decl(lib.es5.d.ts, --, --)) +>results : Symbol(results, Decl(logicalAssignment7.ts, 8, 14)) +>results1 : Symbol(results1, Decl(logicalAssignment7.ts, 8, 44)) +>push : Symbol(Array.push, Decl(lib.es5.d.ts, --, --)) +} diff --git a/tests/baselines/reference/logicalAssignment7(target=es2020).types b/tests/baselines/reference/logicalAssignment7(target=es2020).types new file mode 100644 index 00000000000..b46c67c14bb --- /dev/null +++ b/tests/baselines/reference/logicalAssignment7(target=es2020).types @@ -0,0 +1,54 @@ +=== tests/cases/conformance/esnext/logicalAssignment/logicalAssignment7.ts === +function foo1(results: number[] | undefined, results1: number[] | undefined) { +>foo1 : (results: number[] | undefined, results1: number[] | undefined) => void +>results : number[] | undefined +>results1 : number[] | undefined + + (results ||= results1 ||= []).push(100); +>(results ||= results1 ||= []).push(100) : number +>(results ||= results1 ||= []).push : (...items: number[]) => number +>(results ||= results1 ||= []) : number[] +>results ||= results1 ||= [] : number[] +>results ||= results1 : number[] | undefined +>results : number[] | undefined +>results1 : number[] | undefined +>[] : never[] +>push : (...items: number[]) => number +>100 : 100 +} + +function foo2(results: number[] | undefined, results1: number[] | undefined) { +>foo2 : (results: number[] | undefined, results1: number[] | undefined) => void +>results : number[] | undefined +>results1 : number[] | undefined + + (results ??= results1 ??= []).push(100); +>(results ??= results1 ??= []).push(100) : number +>(results ??= results1 ??= []).push : (...items: number[]) => number +>(results ??= results1 ??= []) : number[] +>results ??= results1 ??= [] : number[] +>results ??= results1 : number[] | undefined +>results : number[] | undefined +>results1 : number[] | undefined +>[] : never[] +>push : (...items: number[]) => number +>100 : 100 +} + +function foo3(results: number[] | undefined, results1: number[] | undefined) { +>foo3 : (results: number[] | undefined, results1: number[] | undefined) => void +>results : number[] | undefined +>results1 : number[] | undefined + + (results &&= results1 &&= []).push(100); +>(results &&= results1 &&= []).push(100) : number +>(results &&= results1 &&= []).push : (...items: never[]) => number +>(results &&= results1 &&= []) : never[] | undefined +>results &&= results1 &&= [] : never[] | undefined +>results &&= results1 : number[] | undefined +>results : number[] | undefined +>results1 : number[] | undefined +>[] : never[] +>push : (...items: never[]) => number +>100 : 100 +} diff --git a/tests/baselines/reference/logicalAssignment7(target=esnext).errors.txt b/tests/baselines/reference/logicalAssignment7(target=esnext).errors.txt new file mode 100644 index 00000000000..4eec0ce2d11 --- /dev/null +++ b/tests/baselines/reference/logicalAssignment7(target=esnext).errors.txt @@ -0,0 +1,29 @@ +tests/cases/conformance/esnext/logicalAssignment/logicalAssignment7.ts(2,6): error TS2364: The left-hand side of an assignment expression must be a variable or a property access. +tests/cases/conformance/esnext/logicalAssignment/logicalAssignment7.ts(6,6): error TS2364: The left-hand side of an assignment expression must be a variable or a property access. +tests/cases/conformance/esnext/logicalAssignment/logicalAssignment7.ts(10,5): error TS2532: Object is possibly 'undefined'. +tests/cases/conformance/esnext/logicalAssignment/logicalAssignment7.ts(10,6): error TS2364: The left-hand side of an assignment expression must be a variable or a property access. +tests/cases/conformance/esnext/logicalAssignment/logicalAssignment7.ts(10,40): error TS2345: Argument of type '100' is not assignable to parameter of type 'never'. + + +==== tests/cases/conformance/esnext/logicalAssignment/logicalAssignment7.ts (5 errors) ==== + function foo1(results: number[] | undefined, results1: number[] | undefined) { + (results ||= results1 ||= []).push(100); + ~~~~~~~~~~~~~~~~~~~~ +!!! error TS2364: The left-hand side of an assignment expression must be a variable or a property access. + } + + function foo2(results: number[] | undefined, results1: number[] | undefined) { + (results ??= results1 ??= []).push(100); + ~~~~~~~~~~~~~~~~~~~~ +!!! error TS2364: The left-hand side of an assignment expression must be a variable or a property access. + } + + function foo3(results: number[] | undefined, results1: number[] | undefined) { + (results &&= results1 &&= []).push(100); + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2532: Object is possibly 'undefined'. + ~~~~~~~~~~~~~~~~~~~~ +!!! error TS2364: The left-hand side of an assignment expression must be a variable or a property access. + ~~~ +!!! error TS2345: Argument of type '100' is not assignable to parameter of type 'never'. + } \ No newline at end of file diff --git a/tests/baselines/reference/logicalAssignment7(target=esnext).js b/tests/baselines/reference/logicalAssignment7(target=esnext).js new file mode 100644 index 00000000000..1b83f24c7af --- /dev/null +++ b/tests/baselines/reference/logicalAssignment7(target=esnext).js @@ -0,0 +1,24 @@ +//// [logicalAssignment7.ts] +function foo1(results: number[] | undefined, results1: number[] | undefined) { + (results ||= results1 ||= []).push(100); +} + +function foo2(results: number[] | undefined, results1: number[] | undefined) { + (results ??= results1 ??= []).push(100); +} + +function foo3(results: number[] | undefined, results1: number[] | undefined) { + (results &&= results1 &&= []).push(100); +} + +//// [logicalAssignment7.js] +"use strict"; +function foo1(results, results1) { + (results ||= results1 ||= []).push(100); +} +function foo2(results, results1) { + (results ??= results1 ??= []).push(100); +} +function foo3(results, results1) { + (results &&= results1 &&= []).push(100); +} diff --git a/tests/baselines/reference/logicalAssignment7(target=esnext).symbols b/tests/baselines/reference/logicalAssignment7(target=esnext).symbols new file mode 100644 index 00000000000..7bde5161df5 --- /dev/null +++ b/tests/baselines/reference/logicalAssignment7(target=esnext).symbols @@ -0,0 +1,36 @@ +=== tests/cases/conformance/esnext/logicalAssignment/logicalAssignment7.ts === +function foo1(results: number[] | undefined, results1: number[] | undefined) { +>foo1 : Symbol(foo1, Decl(logicalAssignment7.ts, 0, 0)) +>results : Symbol(results, Decl(logicalAssignment7.ts, 0, 14)) +>results1 : Symbol(results1, Decl(logicalAssignment7.ts, 0, 44)) + + (results ||= results1 ||= []).push(100); +>(results ||= results1 ||= []).push : Symbol(Array.push, Decl(lib.es5.d.ts, --, --)) +>results : Symbol(results, Decl(logicalAssignment7.ts, 0, 14)) +>results1 : Symbol(results1, Decl(logicalAssignment7.ts, 0, 44)) +>push : Symbol(Array.push, Decl(lib.es5.d.ts, --, --)) +} + +function foo2(results: number[] | undefined, results1: number[] | undefined) { +>foo2 : Symbol(foo2, Decl(logicalAssignment7.ts, 2, 1)) +>results : Symbol(results, Decl(logicalAssignment7.ts, 4, 14)) +>results1 : Symbol(results1, Decl(logicalAssignment7.ts, 4, 44)) + + (results ??= results1 ??= []).push(100); +>(results ??= results1 ??= []).push : Symbol(Array.push, Decl(lib.es5.d.ts, --, --)) +>results : Symbol(results, Decl(logicalAssignment7.ts, 4, 14)) +>results1 : Symbol(results1, Decl(logicalAssignment7.ts, 4, 44)) +>push : Symbol(Array.push, Decl(lib.es5.d.ts, --, --)) +} + +function foo3(results: number[] | undefined, results1: number[] | undefined) { +>foo3 : Symbol(foo3, Decl(logicalAssignment7.ts, 6, 1)) +>results : Symbol(results, Decl(logicalAssignment7.ts, 8, 14)) +>results1 : Symbol(results1, Decl(logicalAssignment7.ts, 8, 44)) + + (results &&= results1 &&= []).push(100); +>(results &&= results1 &&= []).push : Symbol(Array.push, Decl(lib.es5.d.ts, --, --)) +>results : Symbol(results, Decl(logicalAssignment7.ts, 8, 14)) +>results1 : Symbol(results1, Decl(logicalAssignment7.ts, 8, 44)) +>push : Symbol(Array.push, Decl(lib.es5.d.ts, --, --)) +} diff --git a/tests/baselines/reference/logicalAssignment7(target=esnext).types b/tests/baselines/reference/logicalAssignment7(target=esnext).types new file mode 100644 index 00000000000..b46c67c14bb --- /dev/null +++ b/tests/baselines/reference/logicalAssignment7(target=esnext).types @@ -0,0 +1,54 @@ +=== tests/cases/conformance/esnext/logicalAssignment/logicalAssignment7.ts === +function foo1(results: number[] | undefined, results1: number[] | undefined) { +>foo1 : (results: number[] | undefined, results1: number[] | undefined) => void +>results : number[] | undefined +>results1 : number[] | undefined + + (results ||= results1 ||= []).push(100); +>(results ||= results1 ||= []).push(100) : number +>(results ||= results1 ||= []).push : (...items: number[]) => number +>(results ||= results1 ||= []) : number[] +>results ||= results1 ||= [] : number[] +>results ||= results1 : number[] | undefined +>results : number[] | undefined +>results1 : number[] | undefined +>[] : never[] +>push : (...items: number[]) => number +>100 : 100 +} + +function foo2(results: number[] | undefined, results1: number[] | undefined) { +>foo2 : (results: number[] | undefined, results1: number[] | undefined) => void +>results : number[] | undefined +>results1 : number[] | undefined + + (results ??= results1 ??= []).push(100); +>(results ??= results1 ??= []).push(100) : number +>(results ??= results1 ??= []).push : (...items: number[]) => number +>(results ??= results1 ??= []) : number[] +>results ??= results1 ??= [] : number[] +>results ??= results1 : number[] | undefined +>results : number[] | undefined +>results1 : number[] | undefined +>[] : never[] +>push : (...items: number[]) => number +>100 : 100 +} + +function foo3(results: number[] | undefined, results1: number[] | undefined) { +>foo3 : (results: number[] | undefined, results1: number[] | undefined) => void +>results : number[] | undefined +>results1 : number[] | undefined + + (results &&= results1 &&= []).push(100); +>(results &&= results1 &&= []).push(100) : number +>(results &&= results1 &&= []).push : (...items: never[]) => number +>(results &&= results1 &&= []) : never[] | undefined +>results &&= results1 &&= [] : never[] | undefined +>results &&= results1 : number[] | undefined +>results : number[] | undefined +>results1 : number[] | undefined +>[] : never[] +>push : (...items: never[]) => number +>100 : 100 +} diff --git a/tests/cases/conformance/esnext/logicalAssignment/logicalAssignment4.ts b/tests/cases/conformance/esnext/logicalAssignment/logicalAssignment4.ts index 69cd3aad50b..b142f0ece1d 100644 --- a/tests/cases/conformance/esnext/logicalAssignment/logicalAssignment4.ts +++ b/tests/cases/conformance/esnext/logicalAssignment/logicalAssignment4.ts @@ -7,4 +7,24 @@ function foo1(results: number[] | undefined) { function foo2(results: number[] | undefined) { (results ??= []).push(100); +} + +function foo3(results: number[] | undefined) { + results ||= []; + results.push(100); +} + +function foo4(results: number[] | undefined) { + results ||= []; + results.push(100); +} + +interface ThingWithOriginal { + name: string; + original?: ThingWithOriginal +} +function doSomethingWithAlias(thing?: ThingWithOriginal | undefined) { + if (thing &&= thing.original) { + console.log(thing.name); + } } \ No newline at end of file diff --git a/tests/cases/conformance/esnext/logicalAssignment/logicalAssignment5.ts b/tests/cases/conformance/esnext/logicalAssignment/logicalAssignment5.ts index 08176cce75b..f9e4317b8ee 100644 --- a/tests/cases/conformance/esnext/logicalAssignment/logicalAssignment5.ts +++ b/tests/cases/conformance/esnext/logicalAssignment/logicalAssignment5.ts @@ -1,7 +1,32 @@ // @strict: true // @target: esnext, es2020, es2015 -function foo (f: (a: number) => void | undefined) { - f ??= (a => a++) - f ||= (a => a++) +function foo1 (f?: (a: number) => void) { + f ??= (a => a) + f(42) +} + +function foo2 (f?: (a: number) => void) { + f ||= (a => a) + f(42) +} + +function foo3 (f?: (a: number) => void) { + f &&= (a => a) + f(42) +} + +function bar1 (f?: (a: number) => void) { + f ??= (f.toString(), (a => a)) + f(42) +} + +function bar2 (f?: (a: number) => void) { + f ||= (f.toString(), (a => a)) + f(42) +} + +function bar3 (f?: (a: number) => void) { + f &&= (f.toString(), (a => a)) + f(42) } diff --git a/tests/cases/conformance/esnext/logicalAssignment/logicalAssignment6.ts b/tests/cases/conformance/esnext/logicalAssignment/logicalAssignment6.ts new file mode 100644 index 00000000000..3fa7987f720 --- /dev/null +++ b/tests/cases/conformance/esnext/logicalAssignment/logicalAssignment6.ts @@ -0,0 +1,14 @@ +// @strict: true +// @target: esnext, es2020, es2015 + +function foo1(results: number[] | undefined, results1: number[] | undefined) { + (results ||= (results1 ||= [])).push(100); +} + +function foo2(results: number[] | undefined, results1: number[] | undefined) { + (results ??= (results1 ??= [])).push(100); +} + +function foo3(results: number[] | undefined, results1: number[] | undefined) { + (results &&= (results1 &&= [])).push(100); +} \ No newline at end of file diff --git a/tests/cases/conformance/esnext/logicalAssignment/logicalAssignment7.ts b/tests/cases/conformance/esnext/logicalAssignment/logicalAssignment7.ts new file mode 100644 index 00000000000..78812fa0b73 --- /dev/null +++ b/tests/cases/conformance/esnext/logicalAssignment/logicalAssignment7.ts @@ -0,0 +1,14 @@ +// @strict: true +// @target: esnext, es2020, es2015 + +function foo1(results: number[] | undefined, results1: number[] | undefined) { + (results ||= results1 ||= []).push(100); +} + +function foo2(results: number[] | undefined, results1: number[] | undefined) { + (results ??= results1 ??= []).push(100); +} + +function foo3(results: number[] | undefined, results1: number[] | undefined) { + (results &&= results1 &&= []).push(100); +} \ No newline at end of file