mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-17 11:24:29 -05:00
Rename and simplify 'iterationMode' option
This commit is contained in:
@@ -53,7 +53,6 @@ namespace ts {
|
||||
|
||||
const compilerOptions = host.getCompilerOptions();
|
||||
const languageVersion = getEmitScriptTarget(compilerOptions);
|
||||
const iterationMode = getEmitIterationMode(compilerOptions);
|
||||
const modulekind = getEmitModuleKind(compilerOptions);
|
||||
const noUnusedIdentifiers = !!compilerOptions.noUnusedLocals || !!compilerOptions.noUnusedParameters;
|
||||
const allowSyntheticDefaultImports = typeof compilerOptions.allowSyntheticDefaultImports !== "undefined" ? compilerOptions.allowSyntheticDefaultImports : modulekind === ModuleKind.System;
|
||||
@@ -11444,7 +11443,7 @@ namespace ts {
|
||||
}
|
||||
|
||||
function checkSpreadExpression(node: SpreadElement, contextualMapper?: TypeMapper): Type {
|
||||
if (languageVersion < ScriptTarget.ES2015 && iterationMode === IterationMode.Iterable) {
|
||||
if (languageVersion < ScriptTarget.ES2015 && compilerOptions.downlevelIteration) {
|
||||
checkExternalEmitHelpers(node, ExternalEmitHelpers.SpreadIncludes);
|
||||
}
|
||||
|
||||
@@ -14713,7 +14712,7 @@ namespace ts {
|
||||
}
|
||||
|
||||
function checkArrayLiteralAssignment(node: ArrayLiteralExpression, sourceType: Type, contextualMapper?: TypeMapper): Type {
|
||||
if (languageVersion < ScriptTarget.ES2015 && iterationMode === IterationMode.Iterable) {
|
||||
if (languageVersion < ScriptTarget.ES2015 && compilerOptions.downlevelIteration) {
|
||||
checkExternalEmitHelpers(node, ExternalEmitHelpers.Read);
|
||||
}
|
||||
|
||||
@@ -15148,7 +15147,7 @@ namespace ts {
|
||||
checkExternalEmitHelpers(node, ExternalEmitHelpers.AsyncDelegator);
|
||||
}
|
||||
}
|
||||
else if (languageVersion < ScriptTarget.ES2015 && iterationMode === IterationMode.Iterable) {
|
||||
else if (languageVersion < ScriptTarget.ES2015 && compilerOptions.downlevelIteration) {
|
||||
checkExternalEmitHelpers(node, ExternalEmitHelpers.Values);
|
||||
}
|
||||
}
|
||||
@@ -17440,7 +17439,7 @@ namespace ts {
|
||||
|
||||
// For a binding pattern, check contained binding elements
|
||||
if (isBindingPattern(node.name)) {
|
||||
if (node.name.kind === SyntaxKind.ArrayBindingPattern && languageVersion < ScriptTarget.ES2015 && iterationMode === IterationMode.Iterable) {
|
||||
if (node.name.kind === SyntaxKind.ArrayBindingPattern && languageVersion < ScriptTarget.ES2015 && compilerOptions.downlevelIteration) {
|
||||
checkExternalEmitHelpers(node, ExternalEmitHelpers.Read);
|
||||
}
|
||||
|
||||
@@ -17622,7 +17621,7 @@ namespace ts {
|
||||
checkExternalEmitHelpers(node, ExternalEmitHelpers.ForAwaitOfIncludes);
|
||||
}
|
||||
}
|
||||
else if (languageVersion < ScriptTarget.ES2015 && compilerOptions.iterationMode === IterationMode.Iterable) {
|
||||
else if (languageVersion < ScriptTarget.ES2015 && compilerOptions.downlevelIteration) {
|
||||
checkExternalEmitHelpers(node, ExternalEmitHelpers.ForOfIncludes);
|
||||
}
|
||||
}
|
||||
@@ -18061,7 +18060,7 @@ namespace ts {
|
||||
* 2. Some constituent is a string and target is less than ES5 (because in ES3 string is not indexable).
|
||||
*/
|
||||
function getIteratedTypeOfIterableOrElementTypeOfArrayOrString(arrayOrStringType: Type, errorNode: Node, checkAssignability: boolean): Type {
|
||||
const iteratedType = iterationMode === IterationMode.Iterable && getIteratedTypeOfIterable(arrayOrStringType, /*errorNode*/ undefined);
|
||||
const iteratedType = compilerOptions.downlevelIteration && getIteratedTypeOfIterable(arrayOrStringType, /*errorNode*/ undefined);
|
||||
if (iteratedType) {
|
||||
if (checkAssignability && errorNode) {
|
||||
checkTypeAssignableTo(arrayOrStringType, createIterableType(iteratedType), errorNode);
|
||||
@@ -18108,10 +18107,10 @@ namespace ts {
|
||||
// But if the input was just number, we want to say that number is not an array type
|
||||
// or a string type.
|
||||
const diagnostic = hasStringConstituent
|
||||
? iterationMode === IterationMode.Iterable
|
||||
? compilerOptions.downlevelIteration
|
||||
? Diagnostics.Type_0_is_not_an_array_type_or_does_not_have_a_Symbol_iterator_method_that_returns_an_iterator
|
||||
: Diagnostics.Type_0_is_not_an_array_type
|
||||
: iterationMode === IterationMode.Iterable
|
||||
: compilerOptions.downlevelIteration
|
||||
? Diagnostics.Type_0_is_not_an_array_type_or_a_string_type_or_does_not_have_a_Symbol_iterator_method_that_returns_an_iterator
|
||||
: Diagnostics.Type_0_is_not_an_array_type_or_a_string_type;
|
||||
error(errorNode, diagnostic, typeToString(arrayType));
|
||||
@@ -18134,7 +18133,7 @@ namespace ts {
|
||||
}
|
||||
|
||||
function getIteratedTypeOfIterableOrElementTypeOfArray(inputType: Type, errorNode: Node, checkAssignability: boolean): Type {
|
||||
const iteratedType = iterationMode === IterationMode.Iterable && getIteratedTypeOfIterable(inputType, /*errorNode*/ undefined);
|
||||
const iteratedType = compilerOptions.downlevelIteration && getIteratedTypeOfIterable(inputType, /*errorNode*/ undefined);
|
||||
if (iteratedType) {
|
||||
if (checkAssignability && errorNode) {
|
||||
checkTypeAssignableTo(inputType, createIterableType(iteratedType), errorNode);
|
||||
@@ -18145,7 +18144,7 @@ namespace ts {
|
||||
return getIndexTypeOfType(inputType, IndexKind.Number);
|
||||
}
|
||||
if (errorNode) {
|
||||
const diagnostic = iterationMode === IterationMode.Iterable
|
||||
const diagnostic = compilerOptions.downlevelIteration
|
||||
? Diagnostics.Type_0_is_not_an_array_type_or_does_not_have_a_Symbol_iterator_method_that_returns_an_iterator
|
||||
: Diagnostics.Type_0_is_not_an_array_type;
|
||||
error(errorNode, diagnostic, typeToString(inputType));
|
||||
|
||||
@@ -333,13 +333,9 @@ namespace ts {
|
||||
description: Diagnostics.Disallow_inconsistently_cased_references_to_the_same_file
|
||||
},
|
||||
{
|
||||
name: "iterationMode",
|
||||
type: createMap({
|
||||
"array": IterationMode.Array,
|
||||
"iterable": IterationMode.Iterable
|
||||
}),
|
||||
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,
|
||||
paramType: Diagnostics.MODE
|
||||
name: "downlevelIteration",
|
||||
type: "boolean",
|
||||
description: Diagnostics.Use_full_down_level_iteration_for_iterables_and_arrays_for_for_of_spread_and_destructuring_in_ES5_Slash3
|
||||
},
|
||||
{
|
||||
name: "baseUrl",
|
||||
|
||||
@@ -1373,10 +1373,6 @@ namespace ts {
|
||||
getEmitScriptTarget(compilerOptions) >= ScriptTarget.ES2015 ? ModuleKind.ES2015 : ModuleKind.CommonJS;
|
||||
}
|
||||
|
||||
export function getEmitIterationMode(compilerOptions: CompilerOptions) {
|
||||
return getEmitScriptTarget(compilerOptions) >= ScriptTarget.ES2015 ? IterationMode.Iterable : compilerOptions.iterationMode || IterationMode.Array;
|
||||
}
|
||||
|
||||
export function getEmitModuleResolutionKind(compilerOptions: CompilerOptions) {
|
||||
let moduleResolution = compilerOptions.moduleResolution;
|
||||
if (moduleResolution === undefined) {
|
||||
|
||||
@@ -2597,10 +2597,6 @@
|
||||
"category": "Message",
|
||||
"code": 6039
|
||||
},
|
||||
"MODE": {
|
||||
"category": "Message",
|
||||
"code": 6040
|
||||
},
|
||||
"Compilation complete. Watching for file changes.": {
|
||||
"category": "Message",
|
||||
"code": 6042
|
||||
@@ -3009,7 +3005,7 @@
|
||||
"category": "Message",
|
||||
"code": 6148
|
||||
},
|
||||
"Specify how to emit for-of, spread, and destructuring in ES5/3: 'array' (arrays only; default) or 'iterable' (support arrays and Symbol.iterator)": {
|
||||
"Use full down-level iteration for iterables and arrays for 'for-of', spread, and destructuring in ES5/3.": {
|
||||
"category": "Message",
|
||||
"code": 6149
|
||||
},
|
||||
|
||||
@@ -6,7 +6,7 @@ namespace ts {
|
||||
interface FlattenContext {
|
||||
context: TransformationContext;
|
||||
level: FlattenLevel;
|
||||
iterationMode: IterationMode;
|
||||
downlevelIteration: boolean;
|
||||
hoistTempVariables: boolean;
|
||||
emitExpression: (value: Expression) => void;
|
||||
emitBindingOrAssignment: (target: BindingOrAssignmentElementTarget, value: Expression, location: TextRange, original: Node) => void;
|
||||
@@ -58,7 +58,7 @@ namespace ts {
|
||||
const flattenContext: FlattenContext = {
|
||||
context,
|
||||
level,
|
||||
iterationMode: getEmitIterationMode(context.getCompilerOptions()),
|
||||
downlevelIteration: context.getCompilerOptions().downlevelIteration,
|
||||
hoistTempVariables: true,
|
||||
emitExpression,
|
||||
emitBindingOrAssignment,
|
||||
@@ -145,7 +145,7 @@ namespace ts {
|
||||
const flattenContext: FlattenContext = {
|
||||
context,
|
||||
level,
|
||||
iterationMode: getEmitIterationMode(context.getCompilerOptions()),
|
||||
downlevelIteration: context.getCompilerOptions().downlevelIteration,
|
||||
hoistTempVariables,
|
||||
emitExpression,
|
||||
emitBindingOrAssignment,
|
||||
@@ -311,7 +311,7 @@ namespace ts {
|
||||
function flattenArrayBindingOrAssignmentPattern(flattenContext: FlattenContext, parent: BindingOrAssignmentElement, pattern: ArrayBindingOrAssignmentPattern, value: Expression, location: TextRange) {
|
||||
const elements = getElementsOfBindingOrAssignmentPattern(pattern);
|
||||
const numElements = elements.length;
|
||||
if (flattenContext.level < FlattenLevel.ObjectRest && flattenContext.iterationMode === IterationMode.Iterable) {
|
||||
if (flattenContext.level < FlattenLevel.ObjectRest && flattenContext.downlevelIteration) {
|
||||
// Read the elements of the iterable into an array
|
||||
value = ensureIdentifier(
|
||||
flattenContext,
|
||||
|
||||
@@ -270,7 +270,6 @@ namespace ts {
|
||||
} = context;
|
||||
|
||||
const compilerOptions = context.getCompilerOptions();
|
||||
const iterationMode = getEmitIterationMode(compilerOptions);
|
||||
const resolver = context.getEmitResolver();
|
||||
const previousOnSubstituteNode = context.onSubstituteNode;
|
||||
const previousOnEmitNode = context.onEmitNode;
|
||||
@@ -2200,7 +2199,7 @@ namespace ts {
|
||||
HierarchyFacts.ForInOrForOfStatementIncludes,
|
||||
node,
|
||||
outermostLabeledStatement,
|
||||
iterationMode === IterationMode.Array ? convertForOfStatementForArray : convertForOfStatementForIterable);
|
||||
compilerOptions.downlevelIteration ? convertForOfStatementForIterable : convertForOfStatementForArray);
|
||||
}
|
||||
|
||||
function convertForOfStatementHead(statements: Statement[], node: ForOfStatement, boundValue: Expression, convertedLoopBodyStatements: Statement[]) {
|
||||
@@ -3330,7 +3329,7 @@ namespace ts {
|
||||
)
|
||||
);
|
||||
|
||||
if (iterationMode === IterationMode.Iterable) {
|
||||
if (compilerOptions.downlevelIteration) {
|
||||
if (segments.length === 1) {
|
||||
const firstSegment = segments[0];
|
||||
if (isCallExpression(firstSegment)
|
||||
|
||||
@@ -3151,11 +3151,6 @@ namespace ts {
|
||||
NodeJs = 2
|
||||
}
|
||||
|
||||
export enum IterationMode {
|
||||
Array,
|
||||
Iterable
|
||||
}
|
||||
|
||||
export type CompilerOptionsValue = string | number | boolean | (string | number)[] | string[] | MapLike<string[]>;
|
||||
|
||||
export interface CompilerOptions {
|
||||
@@ -3173,11 +3168,11 @@ namespace ts {
|
||||
/* @internal */ diagnostics?: boolean;
|
||||
/* @internal */ extendedDiagnostics?: boolean;
|
||||
disableSizeLimit?: boolean;
|
||||
downlevelIteration?: boolean;
|
||||
emitBOM?: boolean;
|
||||
emitDecoratorMetadata?: boolean;
|
||||
experimentalDecorators?: boolean;
|
||||
forceConsistentCasingInFileNames?: boolean;
|
||||
iterationMode?: IterationMode;
|
||||
/*@internal*/help?: boolean;
|
||||
importHelpers?: boolean;
|
||||
/*@internal*/init?: boolean;
|
||||
|
||||
Reference in New Issue
Block a user