Skip to content

Commit 5748fef

Browse files
authored
Merge branch 'main' into main
2 parents c1d23c7 + f5ccf43 commit 5748fef

File tree

2,306 files changed

+21099
-21470
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

2,306 files changed

+21099
-21470
lines changed

src/compiler/checker.ts

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -31113,7 +31113,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
3111331113
// We only look for uninitialized variables in strict null checking mode, and only when we can analyze
3111431114
// the entire control flow graph from the variable's declaration (i.e. when the flow container and
3111531115
// declaration container are the same).
31116-
const isNeverInitialized = immediateDeclaration && isVariableDeclaration(immediateDeclaration) && !immediateDeclaration.initializer && !immediateDeclaration.exclamationToken && isMutableLocalVariableDeclaration(immediateDeclaration) && !isSymbolAssignedDefinitely(symbol);
31116+
const isNeverInitialized = immediateDeclaration && isVariableDeclaration(immediateDeclaration) && !isForInOrOfStatement(immediateDeclaration.parent.parent) && !immediateDeclaration.initializer && !immediateDeclaration.exclamationToken && isMutableLocalVariableDeclaration(immediateDeclaration) && !isSymbolAssignedDefinitely(symbol);
3111731117
const assumeInitialized = isParameter || isAlias ||
3111831118
(isOuterVariable && !isNeverInitialized) ||
3111931119
isSpreadDestructuringAssignmentTarget || isModuleExports || isSameScopedBindingElement(node, declaration) ||
@@ -40548,12 +40548,10 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
4054840548
}
4054940549
}
4055040550
checkNullishCoalesceOperandLeft(node);
40551-
checkNullishCoalesceOperandRight(node);
4055240551
}
4055340552

4055440553
function checkNullishCoalesceOperandLeft(node: BinaryExpression) {
4055540554
const leftTarget = skipOuterExpressions(node.left, OuterExpressionKinds.All);
40556-
4055740555
const nullishSemantics = getSyntacticNullishnessSemantics(leftTarget);
4055840556
if (nullishSemantics !== PredicateSemantics.Sometimes) {
4055940557
if (nullishSemantics === PredicateSemantics.Always) {
@@ -40565,25 +40563,6 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
4056540563
}
4056640564
}
4056740565

40568-
function checkNullishCoalesceOperandRight(node: BinaryExpression) {
40569-
const rightTarget = skipOuterExpressions(node.right, OuterExpressionKinds.All);
40570-
const nullishSemantics = getSyntacticNullishnessSemantics(rightTarget);
40571-
if (isNotWithinNullishCoalesceExpression(node)) {
40572-
return;
40573-
}
40574-
40575-
if (nullishSemantics === PredicateSemantics.Always) {
40576-
error(rightTarget, Diagnostics.This_expression_is_always_nullish);
40577-
}
40578-
else if (nullishSemantics === PredicateSemantics.Never) {
40579-
error(rightTarget, Diagnostics.This_expression_is_never_nullish);
40580-
}
40581-
}
40582-
40583-
function isNotWithinNullishCoalesceExpression(node: BinaryExpression) {
40584-
return !isBinaryExpression(node.parent) || node.parent.operatorToken.kind !== SyntaxKind.QuestionQuestionToken;
40585-
}
40586-
4058740566
function getSyntacticNullishnessSemantics(node: Node): PredicateSemantics {
4058840567
node = skipOuterExpressions(node);
4058940568
switch (node.kind) {
@@ -40601,15 +40580,16 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
4060140580
// List of operators that can produce null/undefined:
4060240581
// = ??= ?? || ||= && &&=
4060340582
switch ((node as BinaryExpression).operatorToken.kind) {
40604-
case SyntaxKind.EqualsToken:
40605-
case SyntaxKind.QuestionQuestionToken:
40606-
case SyntaxKind.QuestionQuestionEqualsToken:
4060740583
case SyntaxKind.BarBarToken:
4060840584
case SyntaxKind.BarBarEqualsToken:
4060940585
case SyntaxKind.AmpersandAmpersandToken:
4061040586
case SyntaxKind.AmpersandAmpersandEqualsToken:
4061140587
return PredicateSemantics.Sometimes;
40588+
// For these operator kinds, the right operand is effectively controlling
4061240589
case SyntaxKind.CommaToken:
40590+
case SyntaxKind.EqualsToken:
40591+
case SyntaxKind.QuestionQuestionToken:
40592+
case SyntaxKind.QuestionQuestionEqualsToken:
4061340593
return getSyntacticNullishnessSemantics((node as BinaryExpression).right);
4061440594
}
4061540595
return PredicateSemantics.Never;

tests/baselines/reference/ES5For-ofTypeCheck11.errors.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ ES5For-ofTypeCheck11.ts(3,6): error TS2322: Type 'string | number' is not assign
33

44

55
==== ES5For-ofTypeCheck11.ts (1 errors) ====
6-
var union: string | number[];
6+
declare var union: string | number[];
77
var v: string;
88
for (v of union) { }
99
~

tests/baselines/reference/ES5For-ofTypeCheck11.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
//// [tests/cases/conformance/statements/for-ofStatements/ES5For-ofTypeCheck11.ts] ////
22

33
//// [ES5For-ofTypeCheck11.ts]
4-
var union: string | number[];
4+
declare var union: string | number[];
55
var v: string;
66
for (v of union) { }
77

88
//// [ES5For-ofTypeCheck11.js]
9-
var union;
109
var v;
1110
for (var _i = 0, union_1 = union; _i < union_1.length; _i++) {
1211
v = union_1[_i];
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
//// [tests/cases/conformance/statements/for-ofStatements/ES5For-ofTypeCheck11.ts] ////
22

33
=== ES5For-ofTypeCheck11.ts ===
4-
var union: string | number[];
5-
>union : Symbol(union, Decl(ES5For-ofTypeCheck11.ts, 0, 3))
4+
declare var union: string | number[];
5+
>union : Symbol(union, Decl(ES5For-ofTypeCheck11.ts, 0, 11))
66

77
var v: string;
88
>v : Symbol(v, Decl(ES5For-ofTypeCheck11.ts, 1, 3))
99

1010
for (v of union) { }
1111
>v : Symbol(v, Decl(ES5For-ofTypeCheck11.ts, 1, 3))
12-
>union : Symbol(union, Decl(ES5For-ofTypeCheck11.ts, 0, 3))
12+
>union : Symbol(union, Decl(ES5For-ofTypeCheck11.ts, 0, 11))
1313

tests/baselines/reference/ES5For-ofTypeCheck11.types

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//// [tests/cases/conformance/statements/for-ofStatements/ES5For-ofTypeCheck11.ts] ////
22

33
=== ES5For-ofTypeCheck11.ts ===
4-
var union: string | number[];
4+
declare var union: string | number[];
55
>union : string | number[]
66
> : ^^^^^^^^^^^^^^^^^
77

tests/baselines/reference/ES5For-ofTypeCheck14.errors.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ ES5For-ofTypeCheck14.ts(2,17): error TS2802: Type 'Set<number>' can only be iter
22

33

44
==== ES5For-ofTypeCheck14.ts (1 errors) ====
5-
var union: string | Set<number>
5+
declare var union: string | Set<number>
66
for (const e of union) { }
77
~~~~~
88
!!! error TS2802: Type 'Set<number>' can only be iterated through when using the '--downlevelIteration' flag or with a '--target' of 'es2015' or higher.
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
//// [tests/cases/conformance/statements/for-ofStatements/ES5For-ofTypeCheck14.ts] ////
22

33
//// [ES5For-ofTypeCheck14.ts]
4-
var union: string | Set<number>
4+
declare var union: string | Set<number>
55
for (const e of union) { }
66

77
//// [ES5For-ofTypeCheck14.js]
8-
var union;
98
for (var _i = 0, union_1 = union; _i < union_1.length; _i++) {
109
var e = union_1[_i];
1110
}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
//// [tests/cases/conformance/statements/for-ofStatements/ES5For-ofTypeCheck14.ts] ////
22

33
=== ES5For-ofTypeCheck14.ts ===
4-
var union: string | Set<number>
5-
>union : Symbol(union, Decl(ES5For-ofTypeCheck14.ts, 0, 3))
4+
declare var union: string | Set<number>
5+
>union : Symbol(union, Decl(ES5For-ofTypeCheck14.ts, 0, 11))
66
>Set : Symbol(Set, Decl(lib.es2015.collection.d.ts, --, --), Decl(lib.es2015.collection.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --))
77

88
for (const e of union) { }
99
>e : Symbol(e, Decl(ES5For-ofTypeCheck14.ts, 1, 10))
10-
>union : Symbol(union, Decl(ES5For-ofTypeCheck14.ts, 0, 3))
10+
>union : Symbol(union, Decl(ES5For-ofTypeCheck14.ts, 0, 11))
1111

tests/baselines/reference/ES5For-ofTypeCheck14.types

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//// [tests/cases/conformance/statements/for-ofStatements/ES5For-ofTypeCheck14.ts] ////
22

33
=== ES5For-ofTypeCheck14.ts ===
4-
var union: string | Set<number>
4+
declare var union: string | Set<number>
55
>union : string | Set<number>
66
> : ^^^^^^^^^^^^^^^^^^^^
77

tests/baselines/reference/ES5For-ofTypeCheck7.errors.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ ES5For-ofTypeCheck7.ts(2,15): error TS2461: Type 'number' is not an array type.
22

33

44
==== ES5For-ofTypeCheck7.ts (1 errors) ====
5-
var union: string | number;
5+
declare var union: string | number;
66
for (var v of union) { }
77
~~~~~
88
!!! error TS2461: Type 'number' is not an array type.

0 commit comments

Comments
 (0)