Skip to content

Commit fe0f97b

Browse files
Copilotjakebailey
andauthored
Port TypeScript#63071: Mark downlevelIteration as removed (#2820)
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: jakebailey <5341706+jakebailey@users.noreply.github.com>
1 parent ab7acb4 commit fe0f97b

49 files changed

Lines changed: 383 additions & 215 deletions

File tree

Some content is hidden

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

internal/checker/checker.go

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5918,17 +5918,10 @@ func (c *Checker) getIteratedTypeOrElementType(use IterationUse, inputType *Type
59185918
}
59195919
return nil
59205920
}
5921-
// TODO: remove ScriptTargetES2015
59225921
iterableExists := c.getGlobalIterableType() != c.emptyGenericType
5923-
uplevelIteration := c.languageVersion >= core.ScriptTargetES2015 && iterableExists
5924-
downlevelIteration := !uplevelIteration && c.compilerOptions.DownlevelIteration == core.TSTrue
59255922
possibleOutOfBounds := c.compilerOptions.NoUncheckedIndexedAccess == core.TSTrue && use&IterationUsePossiblyOutOfBounds != 0
5926-
// Get the iterated type of an `Iterable<T>` or `IterableIterator<T>` only in ES2015
5927-
// or higher, when inside of an async generator or for-await-if, or when
5928-
// downlevelIteration is requested.
5929-
if uplevelIteration || downlevelIteration || allowAsyncIterables {
5930-
// We only report errors for an invalid iterable type in ES2015 or higher.
5931-
iterationTypes := c.getIterationTypesOfIterable(inputType, use, core.IfElse(uplevelIteration, errorNode, nil))
5923+
if iterableExists || allowAsyncIterables {
5924+
iterationTypes := c.getIterationTypesOfIterable(inputType, use, core.IfElse(iterableExists, errorNode, nil))
59325925
if checkAssignability {
59335926
if iterationTypes.nextType != nil {
59345927
var diagnostic *diagnostics.Message
@@ -5947,7 +5940,7 @@ func (c *Checker) getIteratedTypeOrElementType(use IterationUse, inputType *Type
59475940
}
59485941
}
59495942
}
5950-
if iterationTypes.yieldType != nil || uplevelIteration {
5943+
if iterationTypes.yieldType != nil || iterableExists {
59515944
if iterationTypes.yieldType == nil {
59525945
return nil
59535946
}
@@ -5996,7 +5989,7 @@ func (c *Checker) getIteratedTypeOrElementType(use IterationUse, inputType *Type
59965989
// number and string input is allowed, we want to say that number is not an
59975990
// array type or a string type.
59985991
allowsStrings := use&IterationUseAllowsStringInputFlag != 0 && !hasStringConstituent
5999-
defaultDiagnostic, maybeMissingAwait := c.getIterationDiagnosticDetails(use, inputType, allowsStrings, downlevelIteration)
5992+
defaultDiagnostic, maybeMissingAwait := c.getIterationDiagnosticDetails(use, inputType, allowsStrings)
60005993
c.errorAndMaybeSuggestAwait(errorNode, maybeMissingAwait && c.getAwaitedTypeOfPromise(arrayType) != nil, defaultDiagnostic, c.TypeToString(arrayType))
60015994
}
60025995
if hasStringConstituent {
@@ -6512,13 +6505,7 @@ func (c *Checker) reportTypeNotIterableError(errorNode *ast.Node, t *Type, allow
65126505
return c.errorAndMaybeSuggestAwait(errorNode, suggestAwait, message, c.TypeToString(t))
65136506
}
65146507

6515-
func (c *Checker) getIterationDiagnosticDetails(use IterationUse, inputType *Type, allowsStrings bool, downlevelIteration bool) (*diagnostics.Message, bool) {
6516-
if downlevelIteration {
6517-
if allowsStrings {
6518-
return diagnostics.Type_0_is_not_an_array_type_or_a_string_type_or_does_not_have_a_Symbol_iterator_method_that_returns_an_iterator, true
6519-
}
6520-
return diagnostics.Type_0_is_not_an_array_type_or_does_not_have_a_Symbol_iterator_method_that_returns_an_iterator, true
6521-
}
6508+
func (c *Checker) getIterationDiagnosticDetails(use IterationUse, inputType *Type, allowsStrings bool) (*diagnostics.Message, bool) {
65226509
yieldType := c.getIterationTypeOfIterable(use, IterationTypeKindYield, inputType, nil /*errorNode*/)
65236510
if yieldType != nil {
65246511
return diagnostics.Type_0_can_only_be_iterated_through_when_using_the_downlevelIteration_flag_or_with_a_target_of_es2015_or_higher, false

internal/compiler/program.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -825,6 +825,10 @@ func (p *Program) verifyCompilerOptions() {
825825
createRemovedOptionDiagnostic("moduleResolution", "node10", "")
826826
}
827827

828+
if !options.DownlevelIteration.IsUnknown() {
829+
createRemovedOptionDiagnostic("downlevelIteration", "", "")
830+
}
831+
828832
if options.StrictPropertyInitialization.IsTrue() && !options.GetStrictOptionValue(options.StrictNullChecks) {
829833
createDiagnosticForOptionName(diagnostics.Option_0_cannot_be_specified_without_specifying_option_1, "strictPropertyInitialization", "strictNullChecks")
830834
}

internal/core/compileroptions.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ type CompilerOptions struct {
3030
EmitDeclarationOnly Tristate `json:"emitDeclarationOnly,omitzero"`
3131
EmitBOM Tristate `json:"emitBOM,omitzero"`
3232
EmitDecoratorMetadata Tristate `json:"emitDecoratorMetadata,omitzero"`
33-
DownlevelIteration Tristate `json:"downlevelIteration,omitzero"`
3433
Declaration Tristate `json:"declaration,omitzero"`
3534
DeclarationDir string `json:"declarationDir,omitzero"`
3635
DeclarationMap Tristate `json:"declarationMap,omitzero"`
@@ -125,6 +124,8 @@ type CompilerOptions struct {
125124
// Deprecated: Do not use outside of options parsing and validation.
126125
BaseUrl string `json:"baseUrl,omitzero"`
127126
// Deprecated: Do not use outside of options parsing and validation.
127+
DownlevelIteration Tristate `json:"downlevelIteration,omitzero"`
128+
// Deprecated: Do not use outside of options parsing and validation.
128129
ESModuleInterop Tristate `json:"esModuleInterop,omitzero"`
129130
// Deprecated: Do not use outside of options parsing and validation.
130131
OutFile string `json:"outFile,omitzero"`
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
error TS5102: Option 'downlevelIteration' has been removed. Please remove it from your configuration.
2+
3+
4+
!!! error TS5102: Option 'downlevelIteration' has been removed. Please remove it from your configuration.
5+
==== blockScopedBindingsInDownlevelGenerator.ts (0 errors) ====
6+
function* a() {
7+
for (const i of [1,2,3]) {
8+
(() => i)()
9+
yield i
10+
}
11+
}

testdata/baselines/reference/submodule/compiler/blockScopedBindingsInDownlevelGenerator(target=es2015).errors.txt.diff

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,10 @@
55
-
66
-
77
-!!! error TS5101: Option 'downlevelIteration' is deprecated and will stop functioning in TypeScript 7.0. Specify compilerOption '"ignoreDeprecations": "6.0"' to silence this error.
8-
-==== blockScopedBindingsInDownlevelGenerator.ts (0 errors) ====
9-
- function* a() {
10-
- for (const i of [1,2,3]) {
11-
- (() => i)()
12-
- yield i
13-
- }
14-
- }
15-
+<no content>
8+
+error TS5102: Option 'downlevelIteration' has been removed. Please remove it from your configuration.
9+
+
10+
+
11+
+!!! error TS5102: Option 'downlevelIteration' has been removed. Please remove it from your configuration.
12+
==== blockScopedBindingsInDownlevelGenerator.ts (0 errors) ====
13+
function* a() {
14+
for (const i of [1,2,3]) {
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
error TS5102: Option 'downlevelIteration' has been removed. Please remove it from your configuration.
2+
3+
4+
!!! error TS5102: Option 'downlevelIteration' has been removed. Please remove it from your configuration.
5+
==== sourceMapValidationVarInDownLevelGenerator.ts (0 errors) ====
6+
function * f() {
7+
var x = 1, y;
8+
}

testdata/baselines/reference/submodule/compiler/sourceMapValidationVarInDownLevelGenerator(target=es2015).errors.txt.diff

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55
-
66
-
77
-!!! error TS5101: Option 'downlevelIteration' is deprecated and will stop functioning in TypeScript 7.0. Specify compilerOption '"ignoreDeprecations": "6.0"' to silence this error.
8-
-==== sourceMapValidationVarInDownLevelGenerator.ts (0 errors) ====
9-
- function * f() {
10-
- var x = 1, y;
11-
- }
12-
+<no content>
8+
+error TS5102: Option 'downlevelIteration' has been removed. Please remove it from your configuration.
9+
+
10+
+
11+
+!!! error TS5102: Option 'downlevelIteration' has been removed. Please remove it from your configuration.
12+
==== sourceMapValidationVarInDownLevelGenerator.ts (0 errors) ====
13+
function * f() {
14+
var x = 1, y;
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
error TS5102: Option 'downlevelIteration' has been removed. Please remove it from your configuration.
2+
3+
4+
!!! error TS5102: Option 'downlevelIteration' has been removed. Please remove it from your configuration.
5+
==== ES5For-of33.ts (0 errors) ====
6+
for (var v of ['a', 'b', 'c']) {
7+
console.log(v);
8+
}

testdata/baselines/reference/submodule/conformance/ES5For-of33(target=es2015).errors.txt.diff

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55
-
66
-
77
-!!! error TS5101: Option 'downlevelIteration' is deprecated and will stop functioning in TypeScript 7.0. Specify compilerOption '"ignoreDeprecations": "6.0"' to silence this error.
8-
-==== ES5For-of33.ts (0 errors) ====
9-
- for (var v of ['a', 'b', 'c']) {
10-
- console.log(v);
11-
- }
12-
+<no content>
8+
+error TS5102: Option 'downlevelIteration' has been removed. Please remove it from your configuration.
9+
+
10+
+
11+
+!!! error TS5102: Option 'downlevelIteration' has been removed. Please remove it from your configuration.
12+
==== ES5For-of33.ts (0 errors) ====
13+
for (var v of ['a', 'b', 'c']) {
14+
console.log(v);

testdata/baselines/reference/submodule/conformance/ES5For-of34(target=es2015).errors.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
error TS5102: Option 'downlevelIteration' has been removed. Please remove it from your configuration.
12
ES5For-of34.ts(4,6): error TS2322: Type 'string' is not assignable to type 'number'.
23

34

5+
!!! error TS5102: Option 'downlevelIteration' has been removed. Please remove it from your configuration.
46
==== ES5For-of34.ts (1 errors) ====
57
function foo() {
68
return { x: 0 };

0 commit comments

Comments
 (0)