Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 30aff2f

Browse filesBrowse files
committed
Rename and simplify 'iterationMode' option
1 parent 6a737c8 commit 30aff2f
Copy full SHA for 30aff2f

23 files changed

+37-56Lines changed: 37 additions & 56 deletions
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎src/compiler/checker.ts‎

Copy file name to clipboardExpand all lines: src/compiler/checker.ts
+10-11Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ namespace ts {
5353

5454
const compilerOptions = host.getCompilerOptions();
5555
const languageVersion = getEmitScriptTarget(compilerOptions);
56-
const iterationMode = getEmitIterationMode(compilerOptions);
5756
const modulekind = getEmitModuleKind(compilerOptions);
5857
const noUnusedIdentifiers = !!compilerOptions.noUnusedLocals || !!compilerOptions.noUnusedParameters;
5958
const allowSyntheticDefaultImports = typeof compilerOptions.allowSyntheticDefaultImports !== "undefined" ? compilerOptions.allowSyntheticDefaultImports : modulekind === ModuleKind.System;
@@ -11444,7 +11443,7 @@ namespace ts {
1144411443
}
1144511444

1144611445
function checkSpreadExpression(node: SpreadElement, contextualMapper?: TypeMapper): Type {
11447-
if (languageVersion < ScriptTarget.ES2015 && iterationMode === IterationMode.Iterable) {
11446+
if (languageVersion < ScriptTarget.ES2015 && compilerOptions.downlevelIteration) {
1144811447
checkExternalEmitHelpers(node, ExternalEmitHelpers.SpreadIncludes);
1144911448
}
1145011449

@@ -14713,7 +14712,7 @@ namespace ts {
1471314712
}
1471414713

1471514714
function checkArrayLiteralAssignment(node: ArrayLiteralExpression, sourceType: Type, contextualMapper?: TypeMapper): Type {
14716-
if (languageVersion < ScriptTarget.ES2015 && iterationMode === IterationMode.Iterable) {
14715+
if (languageVersion < ScriptTarget.ES2015 && compilerOptions.downlevelIteration) {
1471714716
checkExternalEmitHelpers(node, ExternalEmitHelpers.Read);
1471814717
}
1471914718

@@ -15148,7 +15147,7 @@ namespace ts {
1514815147
checkExternalEmitHelpers(node, ExternalEmitHelpers.AsyncDelegator);
1514915148
}
1515015149
}
15151-
else if (languageVersion < ScriptTarget.ES2015 && iterationMode === IterationMode.Iterable) {
15150+
else if (languageVersion < ScriptTarget.ES2015 && compilerOptions.downlevelIteration) {
1515215151
checkExternalEmitHelpers(node, ExternalEmitHelpers.Values);
1515315152
}
1515415153
}
@@ -17440,7 +17439,7 @@ namespace ts {
1744017439

1744117440
// For a binding pattern, check contained binding elements
1744217441
if (isBindingPattern(node.name)) {
17443-
if (node.name.kind === SyntaxKind.ArrayBindingPattern && languageVersion < ScriptTarget.ES2015 && iterationMode === IterationMode.Iterable) {
17442+
if (node.name.kind === SyntaxKind.ArrayBindingPattern && languageVersion < ScriptTarget.ES2015 && compilerOptions.downlevelIteration) {
1744417443
checkExternalEmitHelpers(node, ExternalEmitHelpers.Read);
1744517444
}
1744617445

@@ -17622,7 +17621,7 @@ namespace ts {
1762217621
checkExternalEmitHelpers(node, ExternalEmitHelpers.ForAwaitOfIncludes);
1762317622
}
1762417623
}
17625-
else if (languageVersion < ScriptTarget.ES2015 && compilerOptions.iterationMode === IterationMode.Iterable) {
17624+
else if (languageVersion < ScriptTarget.ES2015 && compilerOptions.downlevelIteration) {
1762617625
checkExternalEmitHelpers(node, ExternalEmitHelpers.ForOfIncludes);
1762717626
}
1762817627
}
@@ -18061,7 +18060,7 @@ namespace ts {
1806118060
* 2. Some constituent is a string and target is less than ES5 (because in ES3 string is not indexable).
1806218061
*/
1806318062
function getIteratedTypeOfIterableOrElementTypeOfArrayOrString(arrayOrStringType: Type, errorNode: Node, checkAssignability: boolean): Type {
18064-
const iteratedType = iterationMode === IterationMode.Iterable && getIteratedTypeOfIterable(arrayOrStringType, /*errorNode*/ undefined);
18063+
const iteratedType = compilerOptions.downlevelIteration && getIteratedTypeOfIterable(arrayOrStringType, /*errorNode*/ undefined);
1806518064
if (iteratedType) {
1806618065
if (checkAssignability && errorNode) {
1806718066
checkTypeAssignableTo(arrayOrStringType, createIterableType(iteratedType), errorNode);
@@ -18108,10 +18107,10 @@ namespace ts {
1810818107
// But if the input was just number, we want to say that number is not an array type
1810918108
// or a string type.
1811018109
const diagnostic = hasStringConstituent
18111-
? iterationMode === IterationMode.Iterable
18110+
? compilerOptions.downlevelIteration
1811218111
? Diagnostics.Type_0_is_not_an_array_type_or_does_not_have_a_Symbol_iterator_method_that_returns_an_iterator
1811318112
: Diagnostics.Type_0_is_not_an_array_type
18114-
: iterationMode === IterationMode.Iterable
18113+
: compilerOptions.downlevelIteration
1811518114
? Diagnostics.Type_0_is_not_an_array_type_or_a_string_type_or_does_not_have_a_Symbol_iterator_method_that_returns_an_iterator
1811618115
: Diagnostics.Type_0_is_not_an_array_type_or_a_string_type;
1811718116
error(errorNode, diagnostic, typeToString(arrayType));
@@ -18134,7 +18133,7 @@ namespace ts {
1813418133
}
1813518134

1813618135
function getIteratedTypeOfIterableOrElementTypeOfArray(inputType: Type, errorNode: Node, checkAssignability: boolean): Type {
18137-
const iteratedType = iterationMode === IterationMode.Iterable && getIteratedTypeOfIterable(inputType, /*errorNode*/ undefined);
18136+
const iteratedType = compilerOptions.downlevelIteration && getIteratedTypeOfIterable(inputType, /*errorNode*/ undefined);
1813818137
if (iteratedType) {
1813918138
if (checkAssignability && errorNode) {
1814018139
checkTypeAssignableTo(inputType, createIterableType(iteratedType), errorNode);
@@ -18145,7 +18144,7 @@ namespace ts {
1814518144
return getIndexTypeOfType(inputType, IndexKind.Number);
1814618145
}
1814718146
if (errorNode) {
18148-
const diagnostic = iterationMode === IterationMode.Iterable
18147+
const diagnostic = compilerOptions.downlevelIteration
1814918148
? Diagnostics.Type_0_is_not_an_array_type_or_does_not_have_a_Symbol_iterator_method_that_returns_an_iterator
1815018149
: Diagnostics.Type_0_is_not_an_array_type;
1815118150
error(errorNode, diagnostic, typeToString(inputType));
Collapse file

‎src/compiler/commandLineParser.ts‎

Copy file name to clipboardExpand all lines: src/compiler/commandLineParser.ts
+3-7Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -333,13 +333,9 @@ namespace ts {
333333
description: Diagnostics.Disallow_inconsistently_cased_references_to_the_same_file
334334
},
335335
{
336-
name: "iterationMode",
337-
type: createMap({
338-
"array": IterationMode.Array,
339-
"iterable": IterationMode.Iterable
340-
}),
341-
description: Diagnostics.Specify_how_to_emit_for_of_spread_and_destructuring_in_ES5_Slash3_Colon_array_arrays_only_default_or_iterable_support_arrays_and_Symbol_iterator,
342-
paramType: Diagnostics.MODE
336+
name: "downlevelIteration",
337+
type: "boolean",
338+
description: Diagnostics.Use_full_down_level_iteration_for_iterables_and_arrays_for_for_of_spread_and_destructuring_in_ES5_Slash3
343339
},
344340
{
345341
name: "baseUrl",
Collapse file

‎src/compiler/core.ts‎

Copy file name to clipboardExpand all lines: src/compiler/core.ts
-4Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1373,10 +1373,6 @@ namespace ts {
13731373
getEmitScriptTarget(compilerOptions) >= ScriptTarget.ES2015 ? ModuleKind.ES2015 : ModuleKind.CommonJS;
13741374
}
13751375

1376-
export function getEmitIterationMode(compilerOptions: CompilerOptions) {
1377-
return getEmitScriptTarget(compilerOptions) >= ScriptTarget.ES2015 ? IterationMode.Iterable : compilerOptions.iterationMode || IterationMode.Array;
1378-
}
1379-
13801376
export function getEmitModuleResolutionKind(compilerOptions: CompilerOptions) {
13811377
let moduleResolution = compilerOptions.moduleResolution;
13821378
if (moduleResolution === undefined) {
Collapse file

‎src/compiler/diagnosticMessages.json‎

Copy file name to clipboardExpand all lines: src/compiler/diagnosticMessages.json
+1-5Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2597,10 +2597,6 @@
25972597
"category": "Message",
25982598
"code": 6039
25992599
},
2600-
"MODE": {
2601-
"category": "Message",
2602-
"code": 6040
2603-
},
26042600
"Compilation complete. Watching for file changes.": {
26052601
"category": "Message",
26062602
"code": 6042
@@ -3009,7 +3005,7 @@
30093005
"category": "Message",
30103006
"code": 6148
30113007
},
3012-
"Specify how to emit for-of, spread, and destructuring in ES5/3: 'array' (arrays only; default) or 'iterable' (support arrays and Symbol.iterator)": {
3008+
"Use full down-level iteration for iterables and arrays for 'for-of', spread, and destructuring in ES5/3.": {
30133009
"category": "Message",
30143010
"code": 6149
30153011
},
Collapse file

‎src/compiler/transformers/destructuring.ts‎

Copy file name to clipboardExpand all lines: src/compiler/transformers/destructuring.ts
+4-4Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ namespace ts {
66
interface FlattenContext {
77
context: TransformationContext;
88
level: FlattenLevel;
9-
iterationMode: IterationMode;
9+
downlevelIteration: boolean;
1010
hoistTempVariables: boolean;
1111
emitExpression: (value: Expression) => void;
1212
emitBindingOrAssignment: (target: BindingOrAssignmentElementTarget, value: Expression, location: TextRange, original: Node) => void;
@@ -58,7 +58,7 @@ namespace ts {
5858
const flattenContext: FlattenContext = {
5959
context,
6060
level,
61-
iterationMode: getEmitIterationMode(context.getCompilerOptions()),
61+
downlevelIteration: context.getCompilerOptions().downlevelIteration,
6262
hoistTempVariables: true,
6363
emitExpression,
6464
emitBindingOrAssignment,
@@ -145,7 +145,7 @@ namespace ts {
145145
const flattenContext: FlattenContext = {
146146
context,
147147
level,
148-
iterationMode: getEmitIterationMode(context.getCompilerOptions()),
148+
downlevelIteration: context.getCompilerOptions().downlevelIteration,
149149
hoistTempVariables,
150150
emitExpression,
151151
emitBindingOrAssignment,
@@ -311,7 +311,7 @@ namespace ts {
311311
function flattenArrayBindingOrAssignmentPattern(flattenContext: FlattenContext, parent: BindingOrAssignmentElement, pattern: ArrayBindingOrAssignmentPattern, value: Expression, location: TextRange) {
312312
const elements = getElementsOfBindingOrAssignmentPattern(pattern);
313313
const numElements = elements.length;
314-
if (flattenContext.level < FlattenLevel.ObjectRest && flattenContext.iterationMode === IterationMode.Iterable) {
314+
if (flattenContext.level < FlattenLevel.ObjectRest && flattenContext.downlevelIteration) {
315315
// Read the elements of the iterable into an array
316316
value = ensureIdentifier(
317317
flattenContext,
Collapse file

‎src/compiler/transformers/es2015.ts‎

Copy file name to clipboardExpand all lines: src/compiler/transformers/es2015.ts
+2-3Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,6 @@ namespace ts {
270270
} = context;
271271

272272
const compilerOptions = context.getCompilerOptions();
273-
const iterationMode = getEmitIterationMode(compilerOptions);
274273
const resolver = context.getEmitResolver();
275274
const previousOnSubstituteNode = context.onSubstituteNode;
276275
const previousOnEmitNode = context.onEmitNode;
@@ -2200,7 +2199,7 @@ namespace ts {
22002199
HierarchyFacts.ForInOrForOfStatementIncludes,
22012200
node,
22022201
outermostLabeledStatement,
2203-
iterationMode === IterationMode.Array ? convertForOfStatementForArray : convertForOfStatementForIterable);
2202+
compilerOptions.downlevelIteration ? convertForOfStatementForIterable : convertForOfStatementForArray);
22042203
}
22052204

22062205
function convertForOfStatementHead(statements: Statement[], node: ForOfStatement, boundValue: Expression, convertedLoopBodyStatements: Statement[]) {
@@ -3330,7 +3329,7 @@ namespace ts {
33303329
)
33313330
);
33323331

3333-
if (iterationMode === IterationMode.Iterable) {
3332+
if (compilerOptions.downlevelIteration) {
33343333
if (segments.length === 1) {
33353334
const firstSegment = segments[0];
33363335
if (isCallExpression(firstSegment)
Collapse file

‎src/compiler/types.ts‎

Copy file name to clipboardExpand all lines: src/compiler/types.ts
+1-6Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3151,11 +3151,6 @@ namespace ts {
31513151
NodeJs = 2
31523152
}
31533153

3154-
export enum IterationMode {
3155-
Array,
3156-
Iterable
3157-
}
3158-
31593154
export type CompilerOptionsValue = string | number | boolean | (string | number)[] | string[] | MapLike<string[]>;
31603155

31613156
export interface CompilerOptions {
@@ -3173,11 +3168,11 @@ namespace ts {
31733168
/* @internal */ diagnostics?: boolean;
31743169
/* @internal */ extendedDiagnostics?: boolean;
31753170
disableSizeLimit?: boolean;
3171+
downlevelIteration?: boolean;
31763172
emitBOM?: boolean;
31773173
emitDecoratorMetadata?: boolean;
31783174
experimentalDecorators?: boolean;
31793175
forceConsistentCasingInFileNames?: boolean;
3180-
iterationMode?: IterationMode;
31813176
/*@internal*/help?: boolean;
31823177
importHelpers?: boolean;
31833178
/*@internal*/init?: boolean;
Collapse file

‎tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment1ES5iterable.ts‎

Copy file name to clipboardExpand all lines: tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment1ES5iterable.ts
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// @iterationMode: iterable
1+
// @downlevelIteration: true
22
/* AssignmentPattern:
33
* ObjectAssignmentPattern
44
* ArrayAssignmentPattern
Collapse file

‎tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1ES5iterable.ts‎

Copy file name to clipboardExpand all lines: tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1ES5iterable.ts
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// @iterationMode: iterable
1+
// @downlevelIteration: true
22
// A parameter declaration may specify either an identifier or a binding pattern.
33
// The identifiers specified in parameter declarations and binding patterns
44
// in a parameter list must be unique within that parameter list.
Collapse file

‎tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration3ES5iterable.ts‎

Copy file name to clipboardExpand all lines: tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration3ES5iterable.ts
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// @target: es5
2-
// @iterationMode: iterable
2+
// @downlevelIteration: true
33

44
// If the parameter is a rest parameter, the parameter type is any[]
55
// A type annotation for a rest parameter must denote an array type.

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.