-
Notifications
You must be signed in to change notification settings - Fork 12.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve binding element type inference using CheckMode (rebased) (#56753
) Signed-off-by: Babak K. Shandiz <[email protected]>
- Loading branch information
Showing
10 changed files
with
500 additions
and
16 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
48 changes: 48 additions & 0 deletions
48
...s/baselines/reference/destructuringArrayBindingPatternAndAssignment5SiblingInitializer.js
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,48 @@ | ||
//// [tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment5SiblingInitializer.ts] //// | ||
|
||
//// [destructuringArrayBindingPatternAndAssignment5SiblingInitializer.ts] | ||
// To be inferred as `number` | ||
function f1() { | ||
const [a1, b1 = a1] = [1]; | ||
const [a2, b2 = 1 + a2] = [1]; | ||
} | ||
|
||
// To be inferred as `string` | ||
function f2() { | ||
const [a1, b1 = a1] = ['hi']; | ||
const [a2, b2 = a2 + '!'] = ['hi']; | ||
} | ||
|
||
// To be inferred as `string | number` | ||
function f3() { | ||
const [a1, b1 = a1] = ['hi', 1]; | ||
const [a2, b2 = a2 + '!'] = ['hi', 1]; | ||
} | ||
|
||
// Based on comment: | ||
// - https://github.com/microsoft/TypeScript/issues/49989#issuecomment-1852694486 | ||
declare const yadda: [number, number] | undefined | ||
function f4() { | ||
const [ a, b = a ] = yadda ?? []; | ||
} | ||
|
||
|
||
//// [destructuringArrayBindingPatternAndAssignment5SiblingInitializer.js] | ||
// To be inferred as `number` | ||
function f1() { | ||
var _a = [1], a1 = _a[0], _b = _a[1], b1 = _b === void 0 ? a1 : _b; | ||
var _c = [1], a2 = _c[0], _d = _c[1], b2 = _d === void 0 ? 1 + a2 : _d; | ||
} | ||
// To be inferred as `string` | ||
function f2() { | ||
var _a = ['hi'], a1 = _a[0], _b = _a[1], b1 = _b === void 0 ? a1 : _b; | ||
var _c = ['hi'], a2 = _c[0], _d = _c[1], b2 = _d === void 0 ? a2 + '!' : _d; | ||
} | ||
// To be inferred as `string | number` | ||
function f3() { | ||
var _a = ['hi', 1], a1 = _a[0], _b = _a[1], b1 = _b === void 0 ? a1 : _b; | ||
var _c = ['hi', 1], a2 = _c[0], _d = _c[1], b2 = _d === void 0 ? a2 + '!' : _d; | ||
} | ||
function f4() { | ||
var _a = yadda !== null && yadda !== void 0 ? yadda : [], a = _a[0], _b = _a[1], b = _b === void 0 ? a : _b; | ||
} |
63 changes: 63 additions & 0 deletions
63
...elines/reference/destructuringArrayBindingPatternAndAssignment5SiblingInitializer.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,63 @@ | ||
//// [tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment5SiblingInitializer.ts] //// | ||
|
||
=== destructuringArrayBindingPatternAndAssignment5SiblingInitializer.ts === | ||
// To be inferred as `number` | ||
function f1() { | ||
>f1 : Symbol(f1, Decl(destructuringArrayBindingPatternAndAssignment5SiblingInitializer.ts, 0, 0)) | ||
|
||
const [a1, b1 = a1] = [1]; | ||
>a1 : Symbol(a1, Decl(destructuringArrayBindingPatternAndAssignment5SiblingInitializer.ts, 2, 11)) | ||
>b1 : Symbol(b1, Decl(destructuringArrayBindingPatternAndAssignment5SiblingInitializer.ts, 2, 14)) | ||
>a1 : Symbol(a1, Decl(destructuringArrayBindingPatternAndAssignment5SiblingInitializer.ts, 2, 11)) | ||
|
||
const [a2, b2 = 1 + a2] = [1]; | ||
>a2 : Symbol(a2, Decl(destructuringArrayBindingPatternAndAssignment5SiblingInitializer.ts, 3, 11)) | ||
>b2 : Symbol(b2, Decl(destructuringArrayBindingPatternAndAssignment5SiblingInitializer.ts, 3, 14)) | ||
>a2 : Symbol(a2, Decl(destructuringArrayBindingPatternAndAssignment5SiblingInitializer.ts, 3, 11)) | ||
} | ||
|
||
// To be inferred as `string` | ||
function f2() { | ||
>f2 : Symbol(f2, Decl(destructuringArrayBindingPatternAndAssignment5SiblingInitializer.ts, 4, 1)) | ||
|
||
const [a1, b1 = a1] = ['hi']; | ||
>a1 : Symbol(a1, Decl(destructuringArrayBindingPatternAndAssignment5SiblingInitializer.ts, 8, 11)) | ||
>b1 : Symbol(b1, Decl(destructuringArrayBindingPatternAndAssignment5SiblingInitializer.ts, 8, 14)) | ||
>a1 : Symbol(a1, Decl(destructuringArrayBindingPatternAndAssignment5SiblingInitializer.ts, 8, 11)) | ||
|
||
const [a2, b2 = a2 + '!'] = ['hi']; | ||
>a2 : Symbol(a2, Decl(destructuringArrayBindingPatternAndAssignment5SiblingInitializer.ts, 9, 11)) | ||
>b2 : Symbol(b2, Decl(destructuringArrayBindingPatternAndAssignment5SiblingInitializer.ts, 9, 14)) | ||
>a2 : Symbol(a2, Decl(destructuringArrayBindingPatternAndAssignment5SiblingInitializer.ts, 9, 11)) | ||
} | ||
|
||
// To be inferred as `string | number` | ||
function f3() { | ||
>f3 : Symbol(f3, Decl(destructuringArrayBindingPatternAndAssignment5SiblingInitializer.ts, 10, 1)) | ||
|
||
const [a1, b1 = a1] = ['hi', 1]; | ||
>a1 : Symbol(a1, Decl(destructuringArrayBindingPatternAndAssignment5SiblingInitializer.ts, 14, 11)) | ||
>b1 : Symbol(b1, Decl(destructuringArrayBindingPatternAndAssignment5SiblingInitializer.ts, 14, 14)) | ||
>a1 : Symbol(a1, Decl(destructuringArrayBindingPatternAndAssignment5SiblingInitializer.ts, 14, 11)) | ||
|
||
const [a2, b2 = a2 + '!'] = ['hi', 1]; | ||
>a2 : Symbol(a2, Decl(destructuringArrayBindingPatternAndAssignment5SiblingInitializer.ts, 15, 11)) | ||
>b2 : Symbol(b2, Decl(destructuringArrayBindingPatternAndAssignment5SiblingInitializer.ts, 15, 14)) | ||
>a2 : Symbol(a2, Decl(destructuringArrayBindingPatternAndAssignment5SiblingInitializer.ts, 15, 11)) | ||
} | ||
|
||
// Based on comment: | ||
// - https://github.com/microsoft/TypeScript/issues/49989#issuecomment-1852694486 | ||
declare const yadda: [number, number] | undefined | ||
>yadda : Symbol(yadda, Decl(destructuringArrayBindingPatternAndAssignment5SiblingInitializer.ts, 20, 13)) | ||
|
||
function f4() { | ||
>f4 : Symbol(f4, Decl(destructuringArrayBindingPatternAndAssignment5SiblingInitializer.ts, 20, 49)) | ||
|
||
const [ a, b = a ] = yadda ?? []; | ||
>a : Symbol(a, Decl(destructuringArrayBindingPatternAndAssignment5SiblingInitializer.ts, 22, 11)) | ||
>b : Symbol(b, Decl(destructuringArrayBindingPatternAndAssignment5SiblingInitializer.ts, 22, 14)) | ||
>a : Symbol(a, Decl(destructuringArrayBindingPatternAndAssignment5SiblingInitializer.ts, 22, 11)) | ||
>yadda : Symbol(yadda, Decl(destructuringArrayBindingPatternAndAssignment5SiblingInitializer.ts, 20, 13)) | ||
} | ||
|
85 changes: 85 additions & 0 deletions
85
...aselines/reference/destructuringArrayBindingPatternAndAssignment5SiblingInitializer.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,85 @@ | ||
//// [tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment5SiblingInitializer.ts] //// | ||
|
||
=== destructuringArrayBindingPatternAndAssignment5SiblingInitializer.ts === | ||
// To be inferred as `number` | ||
function f1() { | ||
>f1 : () => void | ||
|
||
const [a1, b1 = a1] = [1]; | ||
>a1 : number | ||
>b1 : number | ||
>a1 : number | ||
>[1] : [number] | ||
>1 : 1 | ||
|
||
const [a2, b2 = 1 + a2] = [1]; | ||
>a2 : number | ||
>b2 : number | ||
>1 + a2 : number | ||
>1 : 1 | ||
>a2 : number | ||
>[1] : [number] | ||
>1 : 1 | ||
} | ||
|
||
// To be inferred as `string` | ||
function f2() { | ||
>f2 : () => void | ||
|
||
const [a1, b1 = a1] = ['hi']; | ||
>a1 : string | ||
>b1 : string | ||
>a1 : string | ||
>['hi'] : [string] | ||
>'hi' : "hi" | ||
|
||
const [a2, b2 = a2 + '!'] = ['hi']; | ||
>a2 : string | ||
>b2 : string | ||
>a2 + '!' : string | ||
>a2 : string | ||
>'!' : "!" | ||
>['hi'] : [string] | ||
>'hi' : "hi" | ||
} | ||
|
||
// To be inferred as `string | number` | ||
function f3() { | ||
>f3 : () => void | ||
|
||
const [a1, b1 = a1] = ['hi', 1]; | ||
>a1 : string | ||
>b1 : string | number | ||
>a1 : string | ||
>['hi', 1] : [string, number] | ||
>'hi' : "hi" | ||
>1 : 1 | ||
|
||
const [a2, b2 = a2 + '!'] = ['hi', 1]; | ||
>a2 : string | ||
>b2 : string | number | ||
>a2 + '!' : string | ||
>a2 : string | ||
>'!' : "!" | ||
>['hi', 1] : [string, number] | ||
>'hi' : "hi" | ||
>1 : 1 | ||
} | ||
|
||
// Based on comment: | ||
// - https://github.com/microsoft/TypeScript/issues/49989#issuecomment-1852694486 | ||
declare const yadda: [number, number] | undefined | ||
>yadda : [number, number] | ||
|
||
function f4() { | ||
>f4 : () => void | ||
|
||
const [ a, b = a ] = yadda ?? []; | ||
>a : number | ||
>b : number | ||
>a : number | ||
>yadda ?? [] : [number, number] | [] | ||
>yadda : [number, number] | ||
>[] : [] | ||
} | ||
|
48 changes: 48 additions & 0 deletions
48
.../baselines/reference/destructuringObjectBindingPatternAndAssignment9SiblingInitializer.js
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,48 @@ | ||
//// [tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment9SiblingInitializer.ts] //// | ||
|
||
//// [destructuringObjectBindingPatternAndAssignment9SiblingInitializer.ts] | ||
// To be inferred as `number` | ||
function f1() { | ||
const { a1, b1 = a1 } = { a1: 1 }; | ||
const { a2, b2 = 1 + a2 } = { a2: 1 }; | ||
} | ||
|
||
// To be inferred as `string` | ||
function f2() { | ||
const { a1, b1 = a1 } = { a1: 'hi' }; | ||
const { a2, b2 = a2 + '!' } = { a2: 'hi' }; | ||
} | ||
|
||
// To be inferred as `string | number` | ||
function f3() { | ||
const { a1, b1 = a1 } = { a1: 'hi', b1: 1 }; | ||
const { a2, b2 = a2 + '!' } = { a2: 'hi', b2: 1 }; | ||
} | ||
|
||
// Based on comment: | ||
// - https://github.com/microsoft/TypeScript/issues/49989#issuecomment-1852694486 | ||
declare const yadda: { a?: number, b?: number } | undefined | ||
function f4() { | ||
const { a, b = a } = yadda ?? {}; | ||
} | ||
|
||
|
||
//// [destructuringObjectBindingPatternAndAssignment9SiblingInitializer.js] | ||
// To be inferred as `number` | ||
function f1() { | ||
var _a = { a1: 1 }, a1 = _a.a1, _b = _a.b1, b1 = _b === void 0 ? a1 : _b; | ||
var _c = { a2: 1 }, a2 = _c.a2, _d = _c.b2, b2 = _d === void 0 ? 1 + a2 : _d; | ||
} | ||
// To be inferred as `string` | ||
function f2() { | ||
var _a = { a1: 'hi' }, a1 = _a.a1, _b = _a.b1, b1 = _b === void 0 ? a1 : _b; | ||
var _c = { a2: 'hi' }, a2 = _c.a2, _d = _c.b2, b2 = _d === void 0 ? a2 + '!' : _d; | ||
} | ||
// To be inferred as `string | number` | ||
function f3() { | ||
var _a = { a1: 'hi', b1: 1 }, a1 = _a.a1, _b = _a.b1, b1 = _b === void 0 ? a1 : _b; | ||
var _c = { a2: 'hi', b2: 1 }, a2 = _c.a2, _d = _c.b2, b2 = _d === void 0 ? a2 + '!' : _d; | ||
} | ||
function f4() { | ||
var _a = yadda !== null && yadda !== void 0 ? yadda : {}, a = _a.a, _b = _a.b, b = _b === void 0 ? a : _b; | ||
} |
Oops, something went wrong.