-
Notifications
You must be signed in to change notification settings - Fork 12.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
137 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
tests/baselines/reference/controlFlowNullishCoalesce.errors.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
tests/cases/conformance/controlFlow/controlFlowNullishCoalesce.ts(4,1): error TS2454: Variable 'a' is used before being assigned. | ||
|
||
|
||
==== tests/cases/conformance/controlFlow/controlFlowNullishCoalesce.ts (1 errors) ==== | ||
// assignments in shortcutting rhs | ||
let a: number; | ||
o ?? (a = 1); | ||
a.toString(); | ||
~ | ||
!!! error TS2454: Variable 'a' is used before being assigned. | ||
|
||
// assignment flow | ||
declare const o: { x: number } | undefined; | ||
let x: { x: number } | boolean; | ||
if (x = o ?? true) { | ||
x; | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
//// [controlFlowNullishCoalesce.ts] | ||
// assignments in shortcutting rhs | ||
let a: number; | ||
o ?? (a = 1); | ||
a.toString(); | ||
|
||
// assignment flow | ||
declare const o: { x: number } | undefined; | ||
let x: { x: number } | boolean; | ||
if (x = o ?? true) { | ||
x; | ||
} | ||
|
||
|
||
|
||
//// [controlFlowNullishCoalesce.js] | ||
"use strict"; | ||
// assignments in shortcutting rhs | ||
var a; | ||
(o !== null && o !== void 0 ? o : (a = 1)); | ||
a.toString(); | ||
var x; | ||
if (x = (o !== null && o !== void 0 ? o : true)) { | ||
x; | ||
} |
32 changes: 32 additions & 0 deletions
32
tests/baselines/reference/controlFlowNullishCoalesce.symbols
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
=== tests/cases/conformance/controlFlow/controlFlowNullishCoalesce.ts === | ||
// assignments in shortcutting rhs | ||
let a: number; | ||
>a : Symbol(a, Decl(controlFlowNullishCoalesce.ts, 1, 3)) | ||
|
||
o ?? (a = 1); | ||
>o : Symbol(o, Decl(controlFlowNullishCoalesce.ts, 6, 13)) | ||
>a : Symbol(a, Decl(controlFlowNullishCoalesce.ts, 1, 3)) | ||
|
||
a.toString(); | ||
>a.toString : Symbol(Number.toString, Decl(lib.es5.d.ts, --, --)) | ||
>a : Symbol(a, Decl(controlFlowNullishCoalesce.ts, 1, 3)) | ||
>toString : Symbol(Number.toString, Decl(lib.es5.d.ts, --, --)) | ||
|
||
// assignment flow | ||
declare const o: { x: number } | undefined; | ||
>o : Symbol(o, Decl(controlFlowNullishCoalesce.ts, 6, 13)) | ||
>x : Symbol(x, Decl(controlFlowNullishCoalesce.ts, 6, 18)) | ||
|
||
let x: { x: number } | boolean; | ||
>x : Symbol(x, Decl(controlFlowNullishCoalesce.ts, 7, 3)) | ||
>x : Symbol(x, Decl(controlFlowNullishCoalesce.ts, 7, 8)) | ||
|
||
if (x = o ?? true) { | ||
>x : Symbol(x, Decl(controlFlowNullishCoalesce.ts, 7, 3)) | ||
>o : Symbol(o, Decl(controlFlowNullishCoalesce.ts, 6, 13)) | ||
|
||
x; | ||
>x : Symbol(x, Decl(controlFlowNullishCoalesce.ts, 7, 3)) | ||
} | ||
|
||
|
40 changes: 40 additions & 0 deletions
40
tests/baselines/reference/controlFlowNullishCoalesce.types
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
=== tests/cases/conformance/controlFlow/controlFlowNullishCoalesce.ts === | ||
// assignments in shortcutting rhs | ||
let a: number; | ||
>a : number | ||
|
||
o ?? (a = 1); | ||
>o ?? (a = 1) : { x: number; } | 1 | ||
>o : { x: number; } | undefined | ||
>(a = 1) : 1 | ||
>a = 1 : 1 | ||
>a : number | ||
>1 : 1 | ||
|
||
a.toString(); | ||
>a.toString() : string | ||
>a.toString : (radix?: number | undefined) => string | ||
>a : number | ||
>toString : (radix?: number | undefined) => string | ||
|
||
// assignment flow | ||
declare const o: { x: number } | undefined; | ||
>o : { x: number; } | undefined | ||
>x : number | ||
|
||
let x: { x: number } | boolean; | ||
>x : boolean | { x: number; } | ||
>x : number | ||
|
||
if (x = o ?? true) { | ||
>x = o ?? true : true | { x: number; } | ||
>x : boolean | { x: number; } | ||
>o ?? true : true | { x: number; } | ||
>o : { x: number; } | undefined | ||
>true : true | ||
|
||
x; | ||
>x : true | { x: number; } | ||
} | ||
|
||
|
7 changes: 1 addition & 6 deletions
7
tests/baselines/reference/nullishCoalescingOperator11.errors.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,12 @@ | ||
tests/cases/conformance/expressions/nullishCoalescingOperator/nullishCoalescingOperator11.ts(3,18): error TS2533: Object is possibly 'null' or 'undefined'. | ||
tests/cases/conformance/expressions/nullishCoalescingOperator/nullishCoalescingOperator11.ts(3,22): error TS2339: Property 'toFixed' does not exist on type '"" | 0'. | ||
Property 'toFixed' does not exist on type '""'. | ||
|
||
|
||
==== tests/cases/conformance/expressions/nullishCoalescingOperator/nullishCoalescingOperator11.ts (2 errors) ==== | ||
==== tests/cases/conformance/expressions/nullishCoalescingOperator/nullishCoalescingOperator11.ts (1 errors) ==== | ||
declare const f11: 1 | 0 | '' | null | undefined; | ||
|
||
let g11 = f11 ?? f11.toFixed() | ||
~~~ | ||
!!! error TS2533: Object is possibly 'null' or 'undefined'. | ||
~~~~~~~ | ||
!!! error TS2339: Property 'toFixed' does not exist on type '"" | 0'. | ||
!!! error TS2339: Property 'toFixed' does not exist on type '""'. | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
tests/cases/conformance/controlFlow/controlFlowNullishCoalesce.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// @strict: true | ||
|
||
// assignments in shortcutting rhs | ||
let a: number; | ||
o ?? (a = 1); | ||
a.toString(); | ||
|
||
// assignment flow | ||
declare const o: { x: number } | undefined; | ||
let x: { x: number } | boolean; | ||
if (x = o ?? true) { | ||
x; | ||
} | ||
|
b030f73
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh......Thanks