diff --git a/Jakefile.js b/Jakefile.js
index 2640f8a1225..14bf047cf21 100644
--- a/Jakefile.js
+++ b/Jakefile.js
@@ -859,6 +859,7 @@ var tslintRuleDir = "scripts/tslint";
var tslintRules = ([
"nextLineRule",
"noNullRule",
+ "preferConstRule",
"booleanTriviaRule",
"typeOperatorSpacingRule"
]);
diff --git a/scripts/tslint/preferConstRule.ts b/scripts/tslint/preferConstRule.ts
new file mode 100644
index 00000000000..29160a9c634
--- /dev/null
+++ b/scripts/tslint/preferConstRule.ts
@@ -0,0 +1,228 @@
+///
+///
+
+
+export class Rule extends Lint.Rules.AbstractRule {
+ public static FAILURE_STRING_FACTORY = (identifier: string) => `Identifier '${identifier}' never appears on the LHS of an assignment - use const instead of let for its declaration.`;
+
+ public apply(sourceFile: ts.SourceFile): Lint.RuleFailure[] {
+ return this.applyWithWalker(new PreferConstWalker(sourceFile, this.getOptions()));
+ }
+}
+
+function isBindingPattern(node: ts.Node): node is ts.BindingPattern {
+ return !!node && (node.kind === ts.SyntaxKind.ArrayBindingPattern || node.kind === ts.SyntaxKind.ObjectBindingPattern);
+}
+
+function walkUpBindingElementsAndPatterns(node: ts.Node): ts.Node {
+ while (node && (node.kind === ts.SyntaxKind.BindingElement || isBindingPattern(node))) {
+ node = node.parent;
+ }
+
+ return node;
+}
+
+function getCombinedNodeFlags(node: ts.Node): ts.NodeFlags {
+ node = walkUpBindingElementsAndPatterns(node);
+
+ let flags = node.flags;
+ if (node.kind === ts.SyntaxKind.VariableDeclaration) {
+ node = node.parent;
+ }
+
+ if (node && node.kind === ts.SyntaxKind.VariableDeclarationList) {
+ flags |= node.flags;
+ node = node.parent;
+ }
+
+ if (node && node.kind === ts.SyntaxKind.VariableStatement) {
+ flags |= node.flags;
+ }
+
+ return flags;
+}
+
+function isLet(node: ts.Node) {
+ return !!(getCombinedNodeFlags(node) & ts.NodeFlags.Let);
+}
+
+function isExported(node: ts.Node) {
+ return !!(getCombinedNodeFlags(node) & ts.NodeFlags.Export);
+}
+
+function isAssignmentOperator(token: ts.SyntaxKind): boolean {
+ return token >= ts.SyntaxKind.FirstAssignment && token <= ts.SyntaxKind.LastAssignment;
+}
+
+function isBindingLiteralExpression(node: ts.Node): node is (ts.ArrayLiteralExpression | ts.ObjectLiteralExpression) {
+ return (!!node) && (node.kind === ts.SyntaxKind.ObjectLiteralExpression || node.kind === ts.SyntaxKind.ArrayLiteralExpression);
+}
+
+interface DeclarationUsages {
+ declaration: ts.VariableDeclaration;
+ usages: number;
+}
+
+class PreferConstWalker extends Lint.RuleWalker {
+ private inScopeLetDeclarations: ts.Map[] = [];
+ private errors: Lint.RuleFailure[] = [];
+ private markAssignment(identifier: ts.Identifier) {
+ const name = identifier.text;
+ for (let i = this.inScopeLetDeclarations.length - 1; i >= 0; i--) {
+ const declarations = this.inScopeLetDeclarations[i];
+ if (declarations[name]) {
+ declarations[name].usages++;
+ break;
+ }
+ }
+ }
+
+ visitSourceFile(node: ts.SourceFile) {
+ super.visitSourceFile(node);
+ // Sort errors by position because tslint doesn't
+ this.errors.sort((a, b) => a.getStartPosition().getPosition() - b.getStartPosition().getPosition()).forEach(e => this.addFailure(e));
+ }
+
+ visitBinaryExpression(node: ts.BinaryExpression) {
+ if (isAssignmentOperator(node.operatorToken.kind)) {
+ this.visitLHSExpressions(node.left);
+ }
+ super.visitBinaryExpression(node);
+ }
+
+ private visitLHSExpressions(node: ts.Expression) {
+ while (node.kind === ts.SyntaxKind.ParenthesizedExpression) {
+ node = (node as ts.ParenthesizedExpression).expression;
+ }
+ if (node.kind === ts.SyntaxKind.Identifier) {
+ this.markAssignment(node as ts.Identifier);
+ }
+ else if (isBindingLiteralExpression(node)) {
+ this.visitBindingLiteralExpression(node as (ts.ArrayLiteralExpression | ts.ObjectLiteralExpression));
+ }
+ }
+
+ private visitBindingLiteralExpression(node: ts.ArrayLiteralExpression | ts.ObjectLiteralExpression) {
+ if (node.kind === ts.SyntaxKind.ObjectLiteralExpression) {
+ const pattern = node as ts.ObjectLiteralExpression;
+ for (const element of pattern.properties) {
+ if (element.name.kind === ts.SyntaxKind.Identifier) {
+ this.markAssignment(element.name as ts.Identifier)
+ }
+ else if (isBindingPattern(element.name)) {
+ this.visitBindingPatternIdentifiers(element.name as ts.BindingPattern);
+ }
+ }
+ }
+ else if (node.kind === ts.SyntaxKind.ArrayLiteralExpression) {
+ const pattern = node as ts.ArrayLiteralExpression;
+ for (const element of pattern.elements) {
+ this.visitLHSExpressions(element);
+ }
+ }
+ }
+
+ private visitBindingPatternIdentifiers(pattern: ts.BindingPattern) {
+ for (const element of pattern.elements) {
+ if (element.name.kind === ts.SyntaxKind.Identifier) {
+ this.markAssignment(element.name as ts.Identifier);
+ }
+ else {
+ this.visitBindingPatternIdentifiers(element.name as ts.BindingPattern);
+ }
+ }
+ }
+
+ visitPrefixUnaryExpression(node: ts.PrefixUnaryExpression) {
+ this.visitAnyUnaryExpression(node);
+ super.visitPrefixUnaryExpression(node);
+ }
+
+ visitPostfixUnaryExpression(node: ts.PostfixUnaryExpression) {
+ this.visitAnyUnaryExpression(node);
+ super.visitPostfixUnaryExpression(node);
+ }
+
+ private visitAnyUnaryExpression(node: ts.PrefixUnaryExpression | ts.PostfixUnaryExpression) {
+ if (node.operator === ts.SyntaxKind.PlusPlusToken || node.operator === ts.SyntaxKind.MinusMinusToken) {
+ this.visitLHSExpressions(node.operand);
+ }
+ }
+
+ visitModuleDeclaration(node: ts.ModuleDeclaration) {
+ if (node.body.kind === ts.SyntaxKind.ModuleBlock) {
+ // For some reason module blocks are left out of the visit block traversal
+ this.visitBlock(node.body as ts.ModuleBlock);
+ }
+ super.visitModuleDeclaration(node);
+ }
+
+ visitForOfStatement(node: ts.ForOfStatement) {
+ this.visitAnyForStatement(node);
+ super.visitForOfStatement(node);
+ this.popDeclarations();
+ }
+
+ visitForInStatement(node: ts.ForInStatement) {
+ this.visitAnyForStatement(node);
+ super.visitForInStatement(node);
+ this.popDeclarations();
+ }
+
+ private visitAnyForStatement(node: ts.ForOfStatement | ts.ForInStatement) {
+ const names: ts.Map = {};
+ if (isLet(node.initializer)) {
+ if (node.initializer.kind === ts.SyntaxKind.VariableDeclarationList) {
+ this.collectLetIdentifiers(node.initializer as ts.VariableDeclarationList, names);
+ }
+ }
+ this.inScopeLetDeclarations.push(names);
+ }
+
+ private popDeclarations() {
+ const completed = this.inScopeLetDeclarations.pop();
+ for (const name in completed) {
+ if (Object.hasOwnProperty.call(completed, name)) {
+ const element = completed[name];
+ if (element.usages === 0) {
+ this.errors.push(this.createFailure(element.declaration.getStart(this.getSourceFile()), element.declaration.getWidth(this.getSourceFile()), Rule.FAILURE_STRING_FACTORY(name)));
+ }
+ }
+ }
+ }
+
+ visitBlock(node: ts.Block) {
+ const names: ts.Map = {};
+ for (const statement of node.statements) {
+ if (statement.kind === ts.SyntaxKind.VariableStatement) {
+ this.collectLetIdentifiers((statement as ts.VariableStatement).declarationList, names);
+ }
+ }
+ this.inScopeLetDeclarations.push(names);
+ super.visitBlock(node);
+ this.popDeclarations();
+ }
+
+ private collectLetIdentifiers(list: ts.VariableDeclarationList, ret: ts.Map) {
+ for (const node of list.declarations) {
+ if (isLet(node) && !isExported(node)) {
+ this.collectNameIdentifiers(node, node.name, ret);
+ }
+ }
+ }
+
+ private collectNameIdentifiers(value: ts.VariableDeclaration, node: ts.Identifier | ts.BindingPattern, table: ts.Map) {
+ if (node.kind === ts.SyntaxKind.Identifier) {
+ table[(node as ts.Identifier).text] = {declaration: value, usages: 0};
+ }
+ else {
+ this.collectBindingPatternIdentifiers(value, node as ts.BindingPattern, table);
+ }
+ }
+
+ private collectBindingPatternIdentifiers(value: ts.VariableDeclaration, pattern: ts.BindingPattern, table: ts.Map) {
+ for (const element of pattern.elements) {
+ this.collectNameIdentifiers(value, element.name, table);
+ }
+ }
+}
diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts
index 8a986d40435..2a5b7e4409c 100644
--- a/src/compiler/binder.ts
+++ b/src/compiler/binder.ts
@@ -95,7 +95,7 @@ namespace ts {
const binder = createBinder();
export function bindSourceFile(file: SourceFile, options: CompilerOptions) {
- let start = new Date().getTime();
+ const start = new Date().getTime();
binder(file, options);
bindTime += new Date().getTime() - start;
}
@@ -187,7 +187,7 @@ namespace ts {
return `"${(node.name).text}"`;
}
if (node.name.kind === SyntaxKind.ComputedPropertyName) {
- let nameExpression = (node.name).expression;
+ const nameExpression = (node.name).expression;
// treat computed property names where expression is string/numeric literal as just string/numeric literal
if (isStringOrNumericLiteral(nameExpression.kind)) {
return (nameExpression).text;
@@ -234,9 +234,9 @@ namespace ts {
function declareSymbol(symbolTable: SymbolTable, parent: Symbol, node: Declaration, includes: SymbolFlags, excludes: SymbolFlags): Symbol {
Debug.assert(!hasDynamicName(node));
- let isDefaultExport = node.flags & NodeFlags.Default;
+ const isDefaultExport = node.flags & NodeFlags.Default;
// The exported symbol for an export default function/class node is always named "default"
- let name = isDefaultExport && parent ? "default" : getDeclarationName(node);
+ const name = isDefaultExport && parent ? "default" : getDeclarationName(node);
let symbol: Symbol;
if (name !== undefined) {
@@ -303,7 +303,7 @@ namespace ts {
}
function declareModuleMember(node: Declaration, symbolFlags: SymbolFlags, symbolExcludes: SymbolFlags): Symbol {
- let hasExportModifier = getCombinedNodeFlags(node) & NodeFlags.Export;
+ const hasExportModifier = getCombinedNodeFlags(node) & NodeFlags.Export;
if (symbolFlags & SymbolFlags.Alias) {
if (node.kind === SyntaxKind.ExportSpecifier || (node.kind === SyntaxKind.ImportEqualsDeclaration && hasExportModifier)) {
return declareSymbol(container.symbol.exports, container.symbol, node, symbolFlags, symbolExcludes);
@@ -325,11 +325,11 @@ namespace ts {
// but return the export symbol (by calling getExportSymbolOfValueSymbolIfExported). That way
// when the emitter comes back to it, it knows not to qualify the name if it was found in a containing scope.
if (hasExportModifier || container.flags & NodeFlags.ExportContext) {
- let exportKind =
+ const exportKind =
(symbolFlags & SymbolFlags.Value ? SymbolFlags.ExportValue : 0) |
(symbolFlags & SymbolFlags.Type ? SymbolFlags.ExportType : 0) |
(symbolFlags & SymbolFlags.Namespace ? SymbolFlags.ExportNamespace : 0);
- let local = declareSymbol(container.locals, undefined, node, exportKind, symbolExcludes);
+ const local = declareSymbol(container.locals, undefined, node, exportKind, symbolExcludes);
local.exportSymbol = declareSymbol(container.symbol.exports, container.symbol, node, symbolFlags, symbolExcludes);
node.localSymbol = local;
return local;
@@ -347,9 +347,9 @@ namespace ts {
// Before we recurse into a node's chilren, we first save the existing parent, container
// and block-container. Then after we pop out of processing the children, we restore
// these saved values.
- let saveParent = parent;
- let saveContainer = container;
- let savedBlockScopeContainer = blockScopeContainer;
+ const saveParent = parent;
+ const saveContainer = container;
+ const savedBlockScopeContainer = blockScopeContainer;
// This node will now be set as the parent of all of its children as we recurse into them.
parent = node;
@@ -371,7 +371,7 @@ namespace ts {
// reusing a node from a previous compilation, that node may have had 'locals' created
// for it. We must clear this so we don't accidently move any stale data forward from
// a previous compilation.
- let containerFlags = getContainerFlags(node);
+ const containerFlags = getContainerFlags(node);
if (containerFlags & ContainerFlags.IsContainer) {
container = blockScopeContainer = node;
@@ -403,7 +403,7 @@ namespace ts {
seenThisKeyword = false;
}
- let saveState = kind === SyntaxKind.SourceFile || kind === SyntaxKind.ModuleBlock || isFunctionLikeKind(kind);
+ const saveState = kind === SyntaxKind.SourceFile || kind === SyntaxKind.ModuleBlock || isFunctionLikeKind(kind);
if (saveState) {
savedReachabilityState = currentReachabilityState;
savedLabelStack = labelStack;
@@ -638,7 +638,7 @@ namespace ts {
function bindCaseBlock(n: CaseBlock): void {
const startState = currentReachabilityState;
- for (let clause of n.clauses) {
+ for (const clause of n.clauses) {
currentReachabilityState = startState;
bind(clause);
if (clause.statements.length && currentReachabilityState === Reachability.Reachable && options.noFallthroughCasesInSwitch) {
@@ -795,9 +795,9 @@ namespace ts {
}
function hasExportDeclarations(node: ModuleDeclaration | SourceFile): boolean {
- let body = node.kind === SyntaxKind.SourceFile ? node : (node).body;
+ const body = node.kind === SyntaxKind.SourceFile ? node : (node).body;
if (body.kind === SyntaxKind.SourceFile || body.kind === SyntaxKind.ModuleBlock) {
- for (let stat of (body).statements) {
+ for (const stat of (body).statements) {
if (stat.kind === SyntaxKind.ExportDeclaration || stat.kind === SyntaxKind.ExportAssignment) {
return true;
}
@@ -823,7 +823,7 @@ namespace ts {
declareSymbolAndAddToSymbolTable(node, SymbolFlags.ValueModule, SymbolFlags.ValueModuleExcludes);
}
else {
- let state = getModuleInstanceState(node);
+ const state = getModuleInstanceState(node);
if (state === ModuleInstanceState.NonInstantiated) {
declareSymbolAndAddToSymbolTable(node, SymbolFlags.NamespaceModule, SymbolFlags.NamespaceModuleExcludes);
}
@@ -835,7 +835,7 @@ namespace ts {
node.symbol.constEnumOnlyModule = false;
}
else {
- let currentModuleIsConstEnumOnly = state === ModuleInstanceState.ConstEnumOnly;
+ const currentModuleIsConstEnumOnly = state === ModuleInstanceState.ConstEnumOnly;
if (node.symbol.constEnumOnlyModule === undefined) {
// non-merged case - use the current state
node.symbol.constEnumOnlyModule = currentModuleIsConstEnumOnly;
@@ -856,10 +856,10 @@ namespace ts {
// We do that by making an anonymous type literal symbol, and then setting the function
// symbol as its sole member. To the rest of the system, this symbol will be indistinguishable
// from an actual type literal symbol you would have gotten had you used the long form.
- let symbol = createSymbol(SymbolFlags.Signature, getDeclarationName(node));
+ const symbol = createSymbol(SymbolFlags.Signature, getDeclarationName(node));
addDeclarationToSymbol(symbol, node, SymbolFlags.Signature);
- let typeLiteralSymbol = createSymbol(SymbolFlags.TypeLiteral, "__type");
+ const typeLiteralSymbol = createSymbol(SymbolFlags.TypeLiteral, "__type");
addDeclarationToSymbol(typeLiteralSymbol, node, SymbolFlags.TypeLiteral);
typeLiteralSymbol.members = { [symbol.name]: symbol };
}
@@ -871,14 +871,14 @@ namespace ts {
}
if (inStrictMode) {
- let seen: Map = {};
+ const seen: Map = {};
- for (let prop of node.properties) {
+ for (const prop of node.properties) {
if (prop.name.kind !== SyntaxKind.Identifier) {
continue;
}
- let identifier = prop.name;
+ const identifier = prop.name;
// ECMA-262 11.1.5 Object Initialiser
// If previous is not undefined then throw a SyntaxError exception if any of the following conditions are true
@@ -888,18 +888,18 @@ namespace ts {
// c.IsAccessorDescriptor(previous) is true and IsDataDescriptor(propId.descriptor) is true.
// d.IsAccessorDescriptor(previous) is true and IsAccessorDescriptor(propId.descriptor) is true
// and either both previous and propId.descriptor have[[Get]] fields or both previous and propId.descriptor have[[Set]] fields
- let currentKind = prop.kind === SyntaxKind.PropertyAssignment || prop.kind === SyntaxKind.ShorthandPropertyAssignment || prop.kind === SyntaxKind.MethodDeclaration
+ const currentKind = prop.kind === SyntaxKind.PropertyAssignment || prop.kind === SyntaxKind.ShorthandPropertyAssignment || prop.kind === SyntaxKind.MethodDeclaration
? ElementKind.Property
: ElementKind.Accessor;
- let existingKind = seen[identifier.text];
+ const existingKind = seen[identifier.text];
if (!existingKind) {
seen[identifier.text] = currentKind;
continue;
}
if (currentKind === ElementKind.Property && existingKind === ElementKind.Property) {
- let span = getErrorSpanForNode(file, identifier);
+ const span = getErrorSpanForNode(file, identifier);
file.bindDiagnostics.push(createFileDiagnostic(file, span.start, span.length,
Diagnostics.An_object_literal_cannot_have_multiple_properties_with_the_same_name_in_strict_mode));
}
@@ -910,7 +910,7 @@ namespace ts {
}
function bindAnonymousDeclaration(node: Declaration, symbolFlags: SymbolFlags, name: string) {
- let symbol = createSymbol(symbolFlags, name);
+ const symbol = createSymbol(symbolFlags, name);
addDeclarationToSymbol(symbol, node, symbolFlags);
}
@@ -989,7 +989,7 @@ namespace ts {
if (inStrictMode && node.expression.kind === SyntaxKind.Identifier) {
// When a delete operator occurs within strict mode code, a SyntaxError is thrown if its
// UnaryExpression is a direct reference to a variable, function argument, or function name
- let span = getErrorSpanForNode(file, node.expression);
+ const span = getErrorSpanForNode(file, node.expression);
file.bindDiagnostics.push(createFileDiagnostic(file, span.start, span.length, Diagnostics.delete_cannot_be_called_on_an_identifier_in_strict_mode));
}
}
@@ -1001,11 +1001,11 @@ namespace ts {
function checkStrictModeEvalOrArguments(contextNode: Node, name: Node) {
if (name && name.kind === SyntaxKind.Identifier) {
- let identifier = name;
+ const identifier = name;
if (isEvalOrArgumentsIdentifier(identifier)) {
// We check first if the name is inside class declaration or class expression; if so give explicit message
// otherwise report generic error message.
- let span = getErrorSpanForNode(file, name);
+ const span = getErrorSpanForNode(file, name);
file.bindDiagnostics.push(createFileDiagnostic(file, span.start, span.length,
getStrictModeEvalOrArgumentsMessage(contextNode), identifier.text));
}
@@ -1066,7 +1066,7 @@ namespace ts {
}
function errorOnFirstToken(node: Node, message: DiagnosticMessage, arg0?: any, arg1?: any, arg2?: any) {
- let span = getSpanOfTokenAtPosition(file, node.pos);
+ const span = getSpanOfTokenAtPosition(file, node.pos);
file.bindDiagnostics.push(createFileDiagnostic(file, span.start, span.length, message, arg0, arg1, arg2));
}
@@ -1081,7 +1081,7 @@ namespace ts {
node.parent = parent;
- let savedInStrictMode = inStrictMode;
+ const savedInStrictMode = inStrictMode;
if (!savedInStrictMode) {
updateStrictMode(node);
}
@@ -1127,7 +1127,7 @@ namespace ts {
}
function updateStrictModeStatementList(statements: NodeArray) {
- for (let statement of statements) {
+ for (const statement of statements) {
if (!isPrologueDirective(statement)) {
return;
}
@@ -1141,7 +1141,7 @@ namespace ts {
/// Should be called only on prologue directives (isPrologueDirective(node) should be true)
function isUseStrictPrologueDirective(node: ExpressionStatement): boolean {
- let nodeText = getTextOfNodeFromSourceText(file.text, node.expression);
+ const nodeText = getTextOfNodeFromSourceText(file.text, node.expression);
// Note: the node text must be exactly "use strict" or 'use strict'. It is not ok for the
// string to contain unicode escapes (as per ES5).
@@ -1216,7 +1216,7 @@ namespace ts {
case SyntaxKind.FunctionExpression:
case SyntaxKind.ArrowFunction:
checkStrictModeFunctionName(node);
- let bindingName = (node).name ? (node).name.text : "__function";
+ const bindingName = (node).name ? (node).name.text : "__function";
return bindAnonymousDeclaration(node, SymbolFlags.Function, bindingName);
case SyntaxKind.ClassExpression:
case SyntaxKind.ClassDeclaration:
@@ -1289,7 +1289,7 @@ namespace ts {
bindBlockScopedDeclaration(node, SymbolFlags.Class, SymbolFlags.ClassExcludes);
}
else {
- let bindingName = node.name ? node.name.text : "__class";
+ const bindingName = node.name ? node.name.text : "__class";
bindAnonymousDeclaration(node, SymbolFlags.Class, bindingName);
// Add name of class expression into the map for semantic classifier
if (node.name) {
@@ -1297,7 +1297,7 @@ namespace ts {
}
}
- let symbol = node.symbol;
+ const symbol = node.symbol;
// TypeScript 1.0 spec (April 2014): 8.4
// Every class automatically contains a static property member named 'prototype', the
@@ -1308,7 +1308,7 @@ namespace ts {
// Note: we check for this here because this class may be merging into a module. The
// module might have an exported variable called 'prototype'. We can't allow that as
// that would clash with the built-in 'prototype' for the class.
- let prototypeSymbol = createSymbol(SymbolFlags.Property | SymbolFlags.Prototype, "prototype");
+ const prototypeSymbol = createSymbol(SymbolFlags.Property | SymbolFlags.Prototype, "prototype");
if (hasProperty(symbol.exports, prototypeSymbol.name)) {
if (node.name) {
node.name.parent = node;
@@ -1373,7 +1373,7 @@ namespace ts {
node.parent.kind === SyntaxKind.Constructor &&
isClassLike(node.parent.parent)) {
- let classDeclaration = node.parent.parent;
+ const classDeclaration = node.parent.parent;
declareSymbol(classDeclaration.symbol.members, classDeclaration.symbol, node, SymbolFlags.Property, SymbolFlags.PropertyExcludes);
}
}
@@ -1399,13 +1399,13 @@ namespace ts {
function pushImplicitLabel(): number {
initializeReachabilityStateIfNecessary();
- let index = labelStack.push(Reachability.Unintialized) - 1;
+ const index = labelStack.push(Reachability.Unintialized) - 1;
implicitLabels.push(index);
return index;
}
function popNamedLabel(label: Identifier, outerState: Reachability): void {
- let index = labelIndexMap[label.text];
+ const index = labelIndexMap[label.text];
Debug.assert(index !== undefined);
Debug.assert(labelStack.length == index + 1);
@@ -1419,7 +1419,7 @@ namespace ts {
Debug.assert(false, `Label stack: ${labelStack.length}, index:${implicitLabelIndex}`);
}
- let i = implicitLabels.pop();
+ const i = implicitLabels.pop();
if (implicitLabelIndex !== i) {
Debug.assert(false, `i: ${i}, index: ${implicitLabelIndex}`);
diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts
index dffb360fca8..cb15d6d9401 100644
--- a/src/compiler/checker.ts
+++ b/src/compiler/checker.ts
@@ -33,26 +33,26 @@ namespace ts {
// they no longer need the information (for example, if the user started editing again).
let cancellationToken: CancellationToken;
- let Symbol = objectAllocator.getSymbolConstructor();
- let Type = objectAllocator.getTypeConstructor();
- let Signature = objectAllocator.getSignatureConstructor();
+ const Symbol = objectAllocator.getSymbolConstructor();
+ const Type = objectAllocator.getTypeConstructor();
+ const Signature = objectAllocator.getSignatureConstructor();
let typeCount = 0;
let symbolCount = 0;
- let emptyArray: any[] = [];
- let emptySymbols: SymbolTable = {};
+ const emptyArray: any[] = [];
+ const emptySymbols: SymbolTable = {};
- let compilerOptions = host.getCompilerOptions();
- let languageVersion = compilerOptions.target || ScriptTarget.ES3;
- let modulekind = compilerOptions.module ? compilerOptions.module : languageVersion === ScriptTarget.ES6 ? ModuleKind.ES6 : ModuleKind.None;
+ const compilerOptions = host.getCompilerOptions();
+ const languageVersion = compilerOptions.target || ScriptTarget.ES3;
+ const modulekind = compilerOptions.module ? compilerOptions.module : languageVersion === ScriptTarget.ES6 ? ModuleKind.ES6 : ModuleKind.None;
- let emitResolver = createResolver();
+ const emitResolver = createResolver();
- let undefinedSymbol = createSymbol(SymbolFlags.Property | SymbolFlags.Transient, "undefined");
- let argumentsSymbol = createSymbol(SymbolFlags.Property | SymbolFlags.Transient, "arguments");
+ const undefinedSymbol = createSymbol(SymbolFlags.Property | SymbolFlags.Transient, "undefined");
+ const argumentsSymbol = createSymbol(SymbolFlags.Property | SymbolFlags.Transient, "arguments");
- let checker: TypeChecker = {
+ const checker: TypeChecker = {
getNodeCount: () => sum(host.getSourceFiles(), "nodeCount"),
getIdentifierCount: () => sum(host.getSourceFiles(), "identifierCount"),
getSymbolCount: () => sum(host.getSourceFiles(), "symbolCount") + symbolCount,
@@ -97,35 +97,35 @@ namespace ts {
isOptionalParameter
};
- let unknownSymbol = createSymbol(SymbolFlags.Property | SymbolFlags.Transient, "unknown");
- let resolvingSymbol = createSymbol(SymbolFlags.Transient, "__resolving__");
+ const unknownSymbol = createSymbol(SymbolFlags.Property | SymbolFlags.Transient, "unknown");
+ const resolvingSymbol = createSymbol(SymbolFlags.Transient, "__resolving__");
- let anyType = createIntrinsicType(TypeFlags.Any, "any");
- let stringType = createIntrinsicType(TypeFlags.String, "string");
- let numberType = createIntrinsicType(TypeFlags.Number, "number");
- let booleanType = createIntrinsicType(TypeFlags.Boolean, "boolean");
- let esSymbolType = createIntrinsicType(TypeFlags.ESSymbol, "symbol");
- let voidType = createIntrinsicType(TypeFlags.Void, "void");
- let undefinedType = createIntrinsicType(TypeFlags.Undefined | TypeFlags.ContainsUndefinedOrNull, "undefined");
- let nullType = createIntrinsicType(TypeFlags.Null | TypeFlags.ContainsUndefinedOrNull, "null");
- let unknownType = createIntrinsicType(TypeFlags.Any, "unknown");
- let circularType = createIntrinsicType(TypeFlags.Any, "__circular__");
+ const anyType = createIntrinsicType(TypeFlags.Any, "any");
+ const stringType = createIntrinsicType(TypeFlags.String, "string");
+ const numberType = createIntrinsicType(TypeFlags.Number, "number");
+ const booleanType = createIntrinsicType(TypeFlags.Boolean, "boolean");
+ const esSymbolType = createIntrinsicType(TypeFlags.ESSymbol, "symbol");
+ const voidType = createIntrinsicType(TypeFlags.Void, "void");
+ const undefinedType = createIntrinsicType(TypeFlags.Undefined | TypeFlags.ContainsUndefinedOrNull, "undefined");
+ const nullType = createIntrinsicType(TypeFlags.Null | TypeFlags.ContainsUndefinedOrNull, "null");
+ const unknownType = createIntrinsicType(TypeFlags.Any, "unknown");
+ const circularType = createIntrinsicType(TypeFlags.Any, "__circular__");
- let emptyObjectType = createAnonymousType(undefined, emptySymbols, emptyArray, emptyArray, undefined, undefined);
- let emptyGenericType = createAnonymousType(undefined, emptySymbols, emptyArray, emptyArray, undefined, undefined);
+ const emptyObjectType = createAnonymousType(undefined, emptySymbols, emptyArray, emptyArray, undefined, undefined);
+ const emptyGenericType = createAnonymousType(undefined, emptySymbols, emptyArray, emptyArray, undefined, undefined);
emptyGenericType.instantiations = {};
- let anyFunctionType = createAnonymousType(undefined, emptySymbols, emptyArray, emptyArray, undefined, undefined);
+ const anyFunctionType = createAnonymousType(undefined, emptySymbols, emptyArray, emptyArray, undefined, undefined);
// The anyFunctionType contains the anyFunctionType by definition. The flag is further propagated
// in getPropagatingFlagsOfTypes, and it is checked in inferFromTypes.
anyFunctionType.flags |= TypeFlags.ContainsAnyFunctionType;
- let noConstraintType = createAnonymousType(undefined, emptySymbols, emptyArray, emptyArray, undefined, undefined);
+ const noConstraintType = createAnonymousType(undefined, emptySymbols, emptyArray, emptyArray, undefined, undefined);
- let anySignature = createSignature(undefined, undefined, emptyArray, anyType, undefined, 0, false, false);
- let unknownSignature = createSignature(undefined, undefined, emptyArray, unknownType, undefined, 0, false, false);
+ const anySignature = createSignature(undefined, undefined, emptyArray, anyType, undefined, 0, false, false);
+ const unknownSignature = createSignature(undefined, undefined, emptyArray, unknownType, undefined, 0, false, false);
- let globals: SymbolTable = {};
+ const globals: SymbolTable = {};
let globalESSymbolConstructorSymbol: Symbol;
@@ -162,29 +162,29 @@ namespace ts {
let jsxElementClassType: Type;
- let tupleTypes: Map = {};
- let unionTypes: Map = {};
- let intersectionTypes: Map = {};
- let stringLiteralTypes: Map = {};
+ const tupleTypes: Map = {};
+ const unionTypes: Map = {};
+ const intersectionTypes: Map = {};
+ const stringLiteralTypes: Map = {};
let emitExtends = false;
let emitDecorate = false;
let emitParam = false;
let emitAwaiter = false;
- let emitGenerator = false;
+ const emitGenerator = false;
- let resolutionTargets: TypeSystemEntity[] = [];
- let resolutionResults: boolean[] = [];
- let resolutionPropertyNames: TypeSystemPropertyName[] = [];
+ const resolutionTargets: TypeSystemEntity[] = [];
+ const resolutionResults: boolean[] = [];
+ const resolutionPropertyNames: TypeSystemPropertyName[] = [];
- let mergedSymbols: Symbol[] = [];
- let symbolLinks: SymbolLinks[] = [];
- let nodeLinks: NodeLinks[] = [];
- let potentialThisCollisions: Node[] = [];
- let awaitedTypeStack: number[] = [];
+ const mergedSymbols: Symbol[] = [];
+ const symbolLinks: SymbolLinks[] = [];
+ const nodeLinks: NodeLinks[] = [];
+ const potentialThisCollisions: Node[] = [];
+ const awaitedTypeStack: number[] = [];
- let diagnostics = createDiagnosticCollection();
+ const diagnostics = createDiagnosticCollection();
- let primitiveTypeInfo: Map<{ type: Type; flags: TypeFlags }> = {
+ const primitiveTypeInfo: Map<{ type: Type; flags: TypeFlags }> = {
"string": {
type: stringType,
flags: TypeFlags.StringLike
@@ -211,9 +211,9 @@ namespace ts {
Element: "Element"
};
- let subtypeRelation: Map = {};
- let assignableRelation: Map = {};
- let identityRelation: Map = {};
+ const subtypeRelation: Map = {};
+ const assignableRelation: Map = {};
+ const identityRelation: Map = {};
// This is for caching the result of getSymbolDisplayBuilder. Do not access directly.
let _displayBuilder: SymbolDisplayBuilder;
@@ -239,7 +239,7 @@ namespace ts {
}
function error(location: Node, message: DiagnosticMessage, arg0?: any, arg1?: any, arg2?: any): void {
- let diagnostic = location
+ const diagnostic = location
? createDiagnosticForNode(location, message, arg0, arg1, arg2)
: createCompilerDiagnostic(message, arg0, arg1, arg2);
diagnostics.add(diagnostic);
@@ -277,7 +277,7 @@ namespace ts {
}
function cloneSymbol(symbol: Symbol): Symbol {
- let result = createSymbol(symbol.flags | SymbolFlags.Merged, symbol.name);
+ const result = createSymbol(symbol.flags | SymbolFlags.Merged, symbol.name);
result.declarations = symbol.declarations.slice(0);
result.parent = symbol.parent;
if (symbol.valueDeclaration) result.valueDeclaration = symbol.valueDeclaration;
@@ -310,7 +310,7 @@ namespace ts {
recordMergedSymbol(target, source);
}
else {
- let message = target.flags & SymbolFlags.BlockScopedVariable || source.flags & SymbolFlags.BlockScopedVariable
+ const message = target.flags & SymbolFlags.BlockScopedVariable || source.flags & SymbolFlags.BlockScopedVariable
? Diagnostics.Cannot_redeclare_block_scoped_variable_0 : Diagnostics.Duplicate_identifier_0;
forEach(source.declarations, node => {
error(node.name ? node.name : node, message, symbolToString(source));
@@ -322,8 +322,8 @@ namespace ts {
}
function cloneSymbolTable(symbolTable: SymbolTable): SymbolTable {
- let result: SymbolTable = {};
- for (let id in symbolTable) {
+ const result: SymbolTable = {};
+ for (const id in symbolTable) {
if (hasProperty(symbolTable, id)) {
result[id] = symbolTable[id];
}
@@ -332,7 +332,7 @@ namespace ts {
}
function mergeSymbolTable(target: SymbolTable, source: SymbolTable) {
- for (let id in source) {
+ for (const id in source) {
if (hasProperty(source, id)) {
if (!hasProperty(target, id)) {
target[id] = source[id];
@@ -350,12 +350,12 @@ namespace ts {
function getSymbolLinks(symbol: Symbol): SymbolLinks {
if (symbol.flags & SymbolFlags.Transient) return symbol;
- let id = getSymbolId(symbol);
+ const id = getSymbolId(symbol);
return symbolLinks[id] || (symbolLinks[id] = {});
}
function getNodeLinks(node: Node): NodeLinks {
- let nodeId = getNodeId(node);
+ const nodeId = getNodeId(node);
return nodeLinks[nodeId] || (nodeLinks[nodeId] = {});
}
@@ -369,13 +369,13 @@ namespace ts {
function getSymbol(symbols: SymbolTable, name: string, meaning: SymbolFlags): Symbol {
if (meaning && hasProperty(symbols, name)) {
- let symbol = symbols[name];
+ const symbol = symbols[name];
Debug.assert((symbol.flags & SymbolFlags.Instantiated) === 0, "Should never get an instantiated symbol here.");
if (symbol.flags & meaning) {
return symbol;
}
if (symbol.flags & SymbolFlags.Alias) {
- let target = resolveAlias(symbol);
+ const target = resolveAlias(symbol);
// Unknown symbol means an error occurred in alias resolution, treat it as positive answer to avoid cascading errors
if (target === unknownSymbol || target.flags & meaning) {
return symbol;
@@ -421,7 +421,7 @@ namespace ts {
else if (declaration.parent.parent.kind === SyntaxKind.ForOfStatement ||
declaration.parent.parent.kind === SyntaxKind.ForInStatement) {
// ForIn/ForOf case - use site should not be used in expression part
- let expression = (declaration.parent.parent).expression;
+ const expression = (declaration.parent.parent).expression;
return isSameScopeDescendentOf(usage, expression, container);
}
}
@@ -460,7 +460,7 @@ namespace ts {
let result: Symbol;
let lastLocation: Node;
let propertyWithInvalidInitializer: Node;
- let errorLocation = location;
+ const errorLocation = location;
let grandparent: Node;
loop: while (location) {
@@ -482,7 +482,7 @@ namespace ts {
case SyntaxKind.SourceFile:
if (!isExternalModule(location)) break;
case SyntaxKind.ModuleDeclaration:
- let moduleExports = getSymbolOfNode(location).exports;
+ const moduleExports = getSymbolOfNode(location).exports;
if (location.kind === SyntaxKind.SourceFile ||
(location.kind === SyntaxKind.ModuleDeclaration && (location).name.kind === SyntaxKind.StringLiteral)) {
@@ -504,7 +504,7 @@ namespace ts {
}
result = moduleExports["default"];
- let localSymbol = getLocalSymbolForExportDefault(result);
+ const localSymbol = getLocalSymbolForExportDefault(result);
if (result && localSymbol && (result.flags & meaning) && localSymbol.name === name) {
break loop;
}
@@ -529,7 +529,7 @@ namespace ts {
// by the same name as a constructor parameter or local variable are inaccessible
// in initializer expressions for instance member variables.
if (isClassLike(location.parent) && !(location.flags & NodeFlags.Static)) {
- let ctor = findConstructorDeclaration(location.parent);
+ const ctor = findConstructorDeclaration(location.parent);
if (ctor && ctor.locals) {
if (getSymbol(ctor.locals, name, meaning & SymbolFlags.Value)) {
// Remember the property node, it will be used later to report appropriate error
@@ -552,7 +552,7 @@ namespace ts {
break loop;
}
if (location.kind === SyntaxKind.ClassExpression && meaning & SymbolFlags.Class) {
- let className = (location).name;
+ const className = (location).name;
if (className && name === className.text) {
result = location.symbol;
break loop;
@@ -597,7 +597,7 @@ namespace ts {
}
if (meaning & SymbolFlags.Function) {
- let functionName = (location).name;
+ const functionName = (location).name;
if (functionName && name === functionName.text) {
result = location.symbol;
break loop;
@@ -647,7 +647,7 @@ namespace ts {
if (propertyWithInvalidInitializer) {
// We have a match, but the reference occurred within a property initializer and the identifier also binds
// to a local variable in the constructor where the code will be emitted.
- let propertyName = (propertyWithInvalidInitializer).name;
+ const propertyName = (propertyWithInvalidInitializer).name;
error(errorLocation, Diagnostics.Initializer_of_instance_member_variable_0_cannot_reference_identifier_1_declared_in_the_constructor,
declarationNameToString(propertyName), typeof nameArg === "string" ? nameArg : declarationNameToString(nameArg));
return undefined;
@@ -659,7 +659,7 @@ namespace ts {
// declare module foo {
// interface bar {}
// }
- // let foo/*1*/: foo/*2*/.bar;
+ // const foo/*1*/: foo/*2*/.bar;
// The foo at /*1*/ and /*2*/ will share same symbol with two meaning
// block - scope variable and namespace module. However, only when we
// try to resolve name in /*1*/ which is used in variable position,
@@ -677,7 +677,7 @@ namespace ts {
function checkResolvedBlockScopedVariable(result: Symbol, errorLocation: Node): void {
Debug.assert((result.flags & SymbolFlags.BlockScopedVariable) !== 0);
// Block-scoped variables cannot be used before their definition
- let declaration = forEach(result.declarations, d => isBlockOrCatchScoped(d) ? d : undefined);
+ const declaration = forEach(result.declarations, d => isBlockOrCatchScoped(d) ? d : undefined);
Debug.assert(declaration !== undefined, "Block-scoped variable declaration is undefined");
@@ -727,9 +727,9 @@ namespace ts {
}
function getTargetOfImportClause(node: ImportClause): Symbol {
- let moduleSymbol = resolveExternalModuleName(node, (node.parent).moduleSpecifier);
+ const moduleSymbol = resolveExternalModuleName(node, (node.parent).moduleSpecifier);
if (moduleSymbol) {
- let exportDefaultSymbol = resolveSymbol(moduleSymbol.exports["default"]);
+ const exportDefaultSymbol = resolveSymbol(moduleSymbol.exports["default"]);
if (!exportDefaultSymbol) {
error(node.name, Diagnostics.Module_0_has_no_default_export, symbolToString(moduleSymbol));
}
@@ -738,13 +738,13 @@ namespace ts {
}
function getTargetOfNamespaceImport(node: NamespaceImport): Symbol {
- let moduleSpecifier = (node.parent.parent).moduleSpecifier;
+ const moduleSpecifier = (node.parent.parent).moduleSpecifier;
return resolveESModuleSymbol(resolveExternalModuleName(node, moduleSpecifier), moduleSpecifier);
}
function getMemberOfModuleVariable(moduleSymbol: Symbol, name: string): Symbol {
if (moduleSymbol.flags & SymbolFlags.Variable) {
- let typeAnnotation = (moduleSymbol.valueDeclaration).type;
+ const typeAnnotation = (moduleSymbol.valueDeclaration).type;
if (typeAnnotation) {
return getPropertyOfType(getTypeFromTypeNode(typeAnnotation), name);
}
@@ -773,7 +773,7 @@ namespace ts {
if (valueSymbol.flags & (SymbolFlags.Type | SymbolFlags.Namespace)) {
return valueSymbol;
}
- let result = createSymbol(valueSymbol.flags | typeSymbol.flags, valueSymbol.name);
+ const result = createSymbol(valueSymbol.flags | typeSymbol.flags, valueSymbol.name);
result.declarations = concatenate(valueSymbol.declarations, typeSymbol.declarations);
result.parent = valueSymbol.parent || typeSymbol.parent;
if (valueSymbol.valueDeclaration) result.valueDeclaration = valueSymbol.valueDeclaration;
@@ -784,7 +784,7 @@ namespace ts {
function getExportOfModule(symbol: Symbol, name: string): Symbol {
if (symbol.flags & SymbolFlags.Module) {
- let exports = getExportsOfSymbol(symbol);
+ const exports = getExportsOfSymbol(symbol);
if (hasProperty(exports, name)) {
return resolveSymbol(exports[name]);
}
@@ -793,7 +793,7 @@ namespace ts {
function getPropertyOfVariable(symbol: Symbol, name: string): Symbol {
if (symbol.flags & SymbolFlags.Variable) {
- let typeAnnotation = (symbol.valueDeclaration).type;
+ const typeAnnotation = (symbol.valueDeclaration).type;
if (typeAnnotation) {
return resolveSymbol(getPropertyOfType(getTypeFromTypeNode(typeAnnotation), name));
}
@@ -801,14 +801,14 @@ namespace ts {
}
function getExternalModuleMember(node: ImportDeclaration | ExportDeclaration, specifier: ImportOrExportSpecifier): Symbol {
- let moduleSymbol = resolveExternalModuleName(node, node.moduleSpecifier);
- let targetSymbol = resolveESModuleSymbol(moduleSymbol, node.moduleSpecifier);
+ const moduleSymbol = resolveExternalModuleName(node, node.moduleSpecifier);
+ const targetSymbol = resolveESModuleSymbol(moduleSymbol, node.moduleSpecifier);
if (targetSymbol) {
- let name = specifier.propertyName || specifier.name;
+ const name = specifier.propertyName || specifier.name;
if (name.text) {
- let symbolFromModule = getExportOfModule(targetSymbol, name.text);
- let symbolFromVariable = getPropertyOfVariable(targetSymbol, name.text);
- let symbol = symbolFromModule && symbolFromVariable ?
+ const symbolFromModule = getExportOfModule(targetSymbol, name.text);
+ const symbolFromVariable = getPropertyOfVariable(targetSymbol, name.text);
+ const symbol = symbolFromModule && symbolFromVariable ?
combineValueAndTypeSymbols(symbolFromVariable, symbolFromModule) :
symbolFromModule || symbolFromVariable;
if (!symbol) {
@@ -856,11 +856,11 @@ namespace ts {
function resolveAlias(symbol: Symbol): Symbol {
Debug.assert((symbol.flags & SymbolFlags.Alias) !== 0, "Should only get Alias here.");
- let links = getSymbolLinks(symbol);
+ const links = getSymbolLinks(symbol);
if (!links.target) {
links.target = resolvingSymbol;
- let node = getDeclarationOfAliasSymbol(symbol);
- let target = getTargetOfAliasDeclaration(node);
+ const node = getDeclarationOfAliasSymbol(symbol);
+ const target = getTargetOfAliasDeclaration(node);
if (links.target === resolvingSymbol) {
links.target = target || unknownSymbol;
}
@@ -875,10 +875,10 @@ namespace ts {
}
function markExportAsReferenced(node: ImportEqualsDeclaration | ExportAssignment | ExportSpecifier) {
- let symbol = getSymbolOfNode(node);
- let target = resolveAlias(symbol);
+ const symbol = getSymbolOfNode(node);
+ const target = resolveAlias(symbol);
if (target) {
- let markAlias =
+ const markAlias =
(target === unknownSymbol && compilerOptions.isolatedModules) ||
(target !== unknownSymbol && (target.flags & SymbolFlags.Value) && !isConstEnumOrConstEnumOnlyModule(target));
@@ -892,10 +892,10 @@ namespace ts {
// we reach a non-alias or an exported entity (which is always considered referenced). We do this by checking the target of
// the alias as an expression (which recursively takes us back here if the target references another alias).
function markAliasSymbolAsReferenced(symbol: Symbol) {
- let links = getSymbolLinks(symbol);
+ const links = getSymbolLinks(symbol);
if (!links.referenced) {
links.referenced = true;
- let node = getDeclarationOfAliasSymbol(symbol);
+ const node = getDeclarationOfAliasSymbol(symbol);
if (node.kind === SyntaxKind.ExportAssignment) {
// export default
checkExpressionCached((node).expression);
@@ -950,7 +950,7 @@ namespace ts {
let symbol: Symbol;
if (name.kind === SyntaxKind.Identifier) {
- let message = meaning === SymbolFlags.Namespace ? Diagnostics.Cannot_find_namespace_0 : Diagnostics.Cannot_find_name_0;
+ const message = meaning === SymbolFlags.Namespace ? Diagnostics.Cannot_find_namespace_0 : Diagnostics.Cannot_find_name_0;
symbol = resolveName(name, (name).text, meaning, ignoreErrors ? undefined : message, name);
if (!symbol) {
@@ -958,10 +958,10 @@ namespace ts {
}
}
else if (name.kind === SyntaxKind.QualifiedName || name.kind === SyntaxKind.PropertyAccessExpression) {
- let left = name.kind === SyntaxKind.QualifiedName ? (name).left : (name).expression;
- let right = name.kind === SyntaxKind.QualifiedName ? (name).right : (name).name;
+ const left = name.kind === SyntaxKind.QualifiedName ? (name).left : (name).expression;
+ const right = name.kind === SyntaxKind.QualifiedName ? (name).right : (name).name;
- let namespace = resolveEntityName(left, SymbolFlags.Namespace, ignoreErrors);
+ const namespace = resolveEntityName(left, SymbolFlags.Namespace, ignoreErrors);
if (!namespace || namespace === unknownSymbol || nodeIsMissing(right)) {
return undefined;
}
@@ -985,26 +985,26 @@ namespace ts {
return;
}
- let moduleReferenceLiteral = moduleReferenceExpression;
- let searchPath = getDirectoryPath(getSourceFile(location).fileName);
+ const moduleReferenceLiteral = moduleReferenceExpression;
+ const searchPath = getDirectoryPath(getSourceFile(location).fileName);
// Module names are escaped in our symbol table. However, string literal values aren't.
// Escape the name in the "require(...)" clause to ensure we find the right symbol.
- let moduleName = escapeIdentifier(moduleReferenceLiteral.text);
+ const moduleName = escapeIdentifier(moduleReferenceLiteral.text);
if (moduleName === undefined) {
return;
}
- let isRelative = isExternalModuleNameRelative(moduleName);
+ const isRelative = isExternalModuleNameRelative(moduleName);
if (!isRelative) {
- let symbol = getSymbol(globals, "\"" + moduleName + "\"", SymbolFlags.ValueModule);
+ const symbol = getSymbol(globals, "\"" + moduleName + "\"", SymbolFlags.ValueModule);
if (symbol) {
return symbol;
}
}
- let resolvedModule = getResolvedModule(getSourceFile(location), moduleReferenceLiteral.text);
- let sourceFile = resolvedModule && host.getSourceFile(resolvedModule.resolvedFileName);
+ const resolvedModule = getResolvedModule(getSourceFile(location), moduleReferenceLiteral.text);
+ const sourceFile = resolvedModule && host.getSourceFile(resolvedModule.resolvedFileName);
if (sourceFile) {
if (sourceFile.symbol) {
return sourceFile.symbol;
@@ -1046,12 +1046,12 @@ namespace ts {
}
function getExportsOfModule(moduleSymbol: Symbol): SymbolTable {
- let links = getSymbolLinks(moduleSymbol);
+ const links = getSymbolLinks(moduleSymbol);
return links.resolvedExports || (links.resolvedExports = getExportsForModule(moduleSymbol));
}
function extendExportSymbols(target: SymbolTable, source: SymbolTable) {
- for (let id in source) {
+ for (const id in source) {
if (id !== "default" && !hasProperty(target, id)) {
target[id] = source[id];
}
@@ -1060,7 +1060,7 @@ namespace ts {
function getExportsForModule(moduleSymbol: Symbol): SymbolTable {
let result: SymbolTable;
- let visitedSymbols: Symbol[] = [];
+ const visitedSymbols: Symbol[] = [];
visit(moduleSymbol);
return result || moduleSymbol.exports;
@@ -1076,9 +1076,9 @@ namespace ts {
extendExportSymbols(result, symbol.exports);
}
// All export * declarations are collected in an __export symbol by the binder
- let exportStars = symbol.exports["__export"];
+ const exportStars = symbol.exports["__export"];
if (exportStars) {
- for (let node of exportStars.declarations) {
+ for (const node of exportStars.declarations) {
visit(resolveExternalModuleName(node, (node).moduleSpecifier));
}
}
@@ -1126,8 +1126,8 @@ namespace ts {
}
function findConstructorDeclaration(node: ClassLikeDeclaration): ConstructorDeclaration {
- let members = node.members;
- for (let member of members) {
+ const members = node.members;
+ for (const member of members) {
if (member.kind === SyntaxKind.Constructor && nodeIsPresent((member).body)) {
return member;
}
@@ -1135,19 +1135,19 @@ namespace ts {
}
function createType(flags: TypeFlags): Type {
- let result = new Type(checker, flags);
+ const result = new Type(checker, flags);
result.id = typeCount++;
return result;
}
function createIntrinsicType(kind: TypeFlags, intrinsicName: string): IntrinsicType {
- let type = createType(kind);
+ const type = createType(kind);
type.intrinsicName = intrinsicName;
return type;
}
function createObjectType(kind: TypeFlags, symbol?: Symbol): ObjectType {
- let type = createType(kind);
+ const type = createType(kind);
type.symbol = symbol;
return type;
}
@@ -1165,11 +1165,11 @@ namespace ts {
function getNamedMembers(members: SymbolTable): Symbol[] {
let result: Symbol[];
- for (let id in members) {
+ for (const id in members) {
if (hasProperty(members, id)) {
if (!isReservedMemberName(id)) {
if (!result) result = [];
- let symbol = members[id];
+ const symbol = members[id];
if (symbolIsValue(symbol)) {
result.push(symbol);
}
@@ -1239,7 +1239,7 @@ namespace ts {
}
// If symbol needs qualification, make sure that parent is accessible, if it is then this symbol is accessible too
- let accessibleParent = getAccessibleSymbolChain(symbolFromSymbolTable.parent, enclosingDeclaration, getQualifiedLeftMeaning(meaning), useOnlyExternalAliasing);
+ const accessibleParent = getAccessibleSymbolChain(symbolFromSymbolTable.parent, enclosingDeclaration, getQualifiedLeftMeaning(meaning), useOnlyExternalAliasing);
return !!accessibleParent;
}
@@ -1267,14 +1267,14 @@ namespace ts {
// Is this external alias, then use it to name
ts.forEach(symbolFromSymbolTable.declarations, isExternalModuleImportEqualsDeclaration)) {
- let resolvedImportedSymbol = resolveAlias(symbolFromSymbolTable);
+ const resolvedImportedSymbol = resolveAlias(symbolFromSymbolTable);
if (isAccessible(symbolFromSymbolTable, resolveAlias(symbolFromSymbolTable))) {
return [symbolFromSymbolTable];
}
// Look in the exported members, if we can find accessibleSymbolChain, symbol is accessible using this chain
// but only if the symbolFromSymbolTable can be qualified
- let accessibleSymbolsFromExports = resolvedImportedSymbol.exports ? getAccessibleSymbolChainFromSymbolTable(resolvedImportedSymbol.exports) : undefined;
+ const accessibleSymbolsFromExports = resolvedImportedSymbol.exports ? getAccessibleSymbolChainFromSymbolTable(resolvedImportedSymbol.exports) : undefined;
if (accessibleSymbolsFromExports && canQualifySymbol(symbolFromSymbolTable, getQualifiedLeftMeaning(meaning))) {
return [symbolFromSymbolTable].concat(accessibleSymbolsFromExports);
}
@@ -1319,13 +1319,13 @@ namespace ts {
function isSymbolAccessible(symbol: Symbol, enclosingDeclaration: Node, meaning: SymbolFlags): SymbolAccessiblityResult {
if (symbol && enclosingDeclaration && !(symbol.flags & SymbolFlags.TypeParameter)) {
- let initialSymbol = symbol;
+ const initialSymbol = symbol;
let meaningToLook = meaning;
while (symbol) {
// Symbol is accessible if it by itself is accessible
- let accessibleSymbolChain = getAccessibleSymbolChain(symbol, enclosingDeclaration, meaningToLook, /*useOnlyExternalAliasing*/ false);
+ const accessibleSymbolChain = getAccessibleSymbolChain(symbol, enclosingDeclaration, meaningToLook, /*useOnlyExternalAliasing*/ false);
if (accessibleSymbolChain) {
- let hasAccessibleDeclarations = hasVisibleDeclarations(accessibleSymbolChain[0]);
+ const hasAccessibleDeclarations = hasVisibleDeclarations(accessibleSymbolChain[0]);
if (!hasAccessibleDeclarations) {
return {
accessibility: SymbolAccessibility.NotAccessible,
@@ -1343,7 +1343,7 @@ namespace ts {
// export class c {
// }
// }
- // let x: typeof m.c
+ // const x: typeof m.c
// In the above example when we start with checking if typeof m.c symbol is accessible,
// we are going to see if c can be accessed in scope directly.
// But it can't, hence the accessible is going to be undefined, but that doesn't mean m.c is inaccessible
@@ -1354,9 +1354,9 @@ namespace ts {
// This could be a symbol that is not exported in the external module
// or it could be a symbol from different external module that is not aliased and hence cannot be named
- let symbolExternalModule = forEach(initialSymbol.declarations, getExternalModuleContainer);
+ const symbolExternalModule = forEach(initialSymbol.declarations, getExternalModuleContainer);
if (symbolExternalModule) {
- let enclosingExternalModule = getExternalModuleContainer(enclosingDeclaration);
+ const enclosingExternalModule = getExternalModuleContainer(enclosingDeclaration);
if (symbolExternalModule !== enclosingExternalModule) {
// name from different external module that is not visible
return {
@@ -1402,7 +1402,7 @@ namespace ts {
// Mark the unexported alias as visible if its parent is visible
// because these kind of aliases can be used to name types in declaration file
- let anyImportSyntax = getAnyImportSyntax(declaration);
+ const anyImportSyntax = getAnyImportSyntax(declaration);
if (anyImportSyntax &&
!(anyImportSyntax.flags & NodeFlags.Export) && // import clause without export
isDeclarationVisible(anyImportSyntax.parent)) {
@@ -1444,8 +1444,8 @@ namespace ts {
meaning = SymbolFlags.Type;
}
- let firstIdentifier = getFirstIdentifier(entityName);
- let symbol = resolveName(enclosingDeclaration, (firstIdentifier).text, meaning, /*nodeNotFoundErrorMessage*/ undefined, /*nameArg*/ undefined);
+ const firstIdentifier = getFirstIdentifier(entityName);
+ const symbol = resolveName(enclosingDeclaration, (firstIdentifier).text, meaning, /*nodeNotFoundErrorMessage*/ undefined, /*nameArg*/ undefined);
// Verify if the symbol is accessible
return (symbol && hasVisibleDeclarations(symbol)) || {
@@ -1468,30 +1468,30 @@ namespace ts {
}
function symbolToString(symbol: Symbol, enclosingDeclaration?: Node, meaning?: SymbolFlags): string {
- let writer = getSingleLineStringWriter();
+ const writer = getSingleLineStringWriter();
getSymbolDisplayBuilder().buildSymbolDisplay(symbol, writer, enclosingDeclaration, meaning);
- let result = writer.string();
+ const result = writer.string();
releaseStringWriter(writer);
return result;
}
function signatureToString(signature: Signature, enclosingDeclaration?: Node, flags?: TypeFormatFlags): string {
- let writer = getSingleLineStringWriter();
+ const writer = getSingleLineStringWriter();
getSymbolDisplayBuilder().buildSignatureDisplay(signature, writer, enclosingDeclaration, flags);
- let result = writer.string();
+ const result = writer.string();
releaseStringWriter(writer);
return result;
}
function typeToString(type: Type, enclosingDeclaration?: Node, flags?: TypeFormatFlags): string {
- let writer = getSingleLineStringWriter();
+ const writer = getSingleLineStringWriter();
getSymbolDisplayBuilder().buildTypeDisplay(type, writer, enclosingDeclaration, flags);
let result = writer.string();
releaseStringWriter(writer);
- let maxLength = compilerOptions.noErrorTruncation || flags & TypeFormatFlags.NoTruncation ? undefined : 100;
+ const maxLength = compilerOptions.noErrorTruncation || flags & TypeFormatFlags.NoTruncation ? undefined : 100;
if (maxLength && result.length >= maxLength) {
result = result.substr(0, maxLength - "...".length) + "...";
}
@@ -1515,7 +1515,7 @@ namespace ts {
function getNameOfSymbol(symbol: Symbol): string {
if (symbol.declarations && symbol.declarations.length) {
- let declaration = symbol.declarations[0];
+ const declaration = symbol.declarations[0];
if (declaration.name) {
return declarationNameToString(declaration.name);
}
@@ -1562,7 +1562,7 @@ namespace ts {
appendSymbolNameOnly(symbol, writer);
}
- // Let the writer know we just wrote out a symbol. The declaration emitter writer uses
+ // const the writer know we just wrote out a symbol. The declaration emitter writer uses
// this to determine if an import it has previously seen (and not written out) needs
// to be written to the file once the walk of the tree is complete.
//
@@ -1572,7 +1572,7 @@ namespace ts {
writer.trackSymbol(symbol, enclosingDeclaration, meaning);
function walkSymbol(symbol: Symbol, meaning: SymbolFlags): void {
if (symbol) {
- let accessibleSymbolChain = getAccessibleSymbolChain(symbol, enclosingDeclaration, meaning, !!(flags & SymbolFormatFlags.UseOnlyExternalAliasing));
+ const accessibleSymbolChain = getAccessibleSymbolChain(symbol, enclosingDeclaration, meaning, !!(flags & SymbolFormatFlags.UseOnlyExternalAliasing));
if (!accessibleSymbolChain ||
needsQualification(accessibleSymbolChain[0], enclosingDeclaration, accessibleSymbolChain.length === 1 ? meaning : getQualifiedLeftMeaning(meaning))) {
@@ -1584,7 +1584,7 @@ namespace ts {
}
if (accessibleSymbolChain) {
- for (let accessibleSymbol of accessibleSymbolChain) {
+ for (const accessibleSymbol of accessibleSymbolChain) {
appendParentTypeArgumentsAndSymbolName(accessibleSymbol);
}
}
@@ -1607,8 +1607,8 @@ namespace ts {
// Get qualified name if the symbol is not a type parameter
// and there is an enclosing declaration or we specifically
// asked for it
- let isTypeParameter = symbol.flags & SymbolFlags.TypeParameter;
- let typeFormatFlag = TypeFormatFlags.UseFullyQualifiedType & typeFlags;
+ const isTypeParameter = symbol.flags & SymbolFlags.TypeParameter;
+ const typeFormatFlag = TypeFormatFlags.UseFullyQualifiedType & typeFlags;
if (!isTypeParameter && (enclosingDeclaration || typeFormatFlag)) {
walkSymbol(symbol, meaning);
return;
@@ -1618,7 +1618,7 @@ namespace ts {
}
function buildTypeDisplay(type: Type, writer: SymbolWriter, enclosingDeclaration?: Node, globalFlags?: TypeFormatFlags, symbolStack?: Symbol[]) {
- let globalFlagsToPass = globalFlags & TypeFormatFlags.WriteOwnNameForAnyLike;
+ const globalFlagsToPass = globalFlags & TypeFormatFlags.WriteOwnNameForAnyLike;
let inObjectTypeLiteral = false;
return writeType(type, globalFlags);
@@ -1697,7 +1697,7 @@ namespace ts {
}
function writeTypeReference(type: TypeReference, flags: TypeFormatFlags) {
- let typeArguments = type.typeArguments || emptyArray;
+ const typeArguments = type.typeArguments || emptyArray;
if (type.target === globalArrayType && !(flags & TypeFormatFlags.WriteArrayAsGenericType)) {
writeType(typeArguments[0], TypeFormatFlags.InElementType);
writePunctuation(writer, SyntaxKind.OpenBracketToken);
@@ -1707,14 +1707,14 @@ namespace ts {
// Write the type reference in the format f.g.C where A and B are type arguments
// for outer type parameters, and f and g are the respective declaring containers of those
// type parameters.
- let outerTypeParameters = type.target.outerTypeParameters;
+ const outerTypeParameters = type.target.outerTypeParameters;
let i = 0;
if (outerTypeParameters) {
- let length = outerTypeParameters.length;
+ const length = outerTypeParameters.length;
while (i < length) {
// Find group of type arguments for type parameters with the same declaring container.
- let start = i;
- let parent = getParentSymbolOfTypeParameter(outerTypeParameters[i]);
+ const start = i;
+ const parent = getParentSymbolOfTypeParameter(outerTypeParameters[i]);
do {
i++;
} while (i < length && getParentSymbolOfTypeParameter(outerTypeParameters[i]) === parent);
@@ -1726,7 +1726,7 @@ namespace ts {
}
}
}
- let typeParameterCount = (type.target.typeParameters || emptyArray).length;
+ const typeParameterCount = (type.target.typeParameters || emptyArray).length;
writeSymbolTypeReference(type.symbol, typeArguments, i, typeParameterCount, flags);
}
}
@@ -1748,7 +1748,7 @@ namespace ts {
}
function writeAnonymousType(type: ObjectType, flags: TypeFormatFlags) {
- let symbol = type.symbol;
+ const symbol = type.symbol;
if (symbol) {
// Always use 'typeof T' for type of class, enum, and module objects
if (symbol.flags & (SymbolFlags.Class | SymbolFlags.Enum | SymbolFlags.ValueModule)) {
@@ -1759,7 +1759,7 @@ namespace ts {
}
else if (contains(symbolStack, symbol)) {
// If type is an anonymous type literal in a type alias declaration, use type alias name
- let typeAlias = getTypeAliasForTypeLiteral(type);
+ const typeAlias = getTypeAliasForTypeLiteral(type);
if (typeAlias) {
// The specified symbol flags need to be reinterpreted as type flags
buildSymbolDisplay(typeAlias, writer, enclosingDeclaration, SymbolFlags.Type, SymbolFormatFlags.None, flags);
@@ -1786,9 +1786,9 @@ namespace ts {
}
function shouldWriteTypeOfFunctionSymbol() {
- let isStaticMethodSymbol = !!(symbol.flags & SymbolFlags.Method && // typeof static method
+ const isStaticMethodSymbol = !!(symbol.flags & SymbolFlags.Method && // typeof static method
forEach(symbol.declarations, declaration => declaration.flags & NodeFlags.Static));
- let isNonLocalFunctionSymbol = !!(symbol.flags & SymbolFlags.Function) &&
+ const isNonLocalFunctionSymbol = !!(symbol.flags & SymbolFlags.Function) &&
(symbol.parent || // is exported function symbol
forEach(symbol.declarations, declaration =>
declaration.parent.kind === SyntaxKind.SourceFile || declaration.parent.kind === SyntaxKind.ModuleBlock));
@@ -1807,7 +1807,7 @@ namespace ts {
}
function getIndexerParameterName(type: ObjectType, indexKind: IndexKind, fallbackName: string): string {
- let declaration = getIndexDeclarationOfSymbol(type.symbol, indexKind);
+ const declaration = getIndexDeclarationOfSymbol(type.symbol, indexKind);
if (!declaration) {
// declaration might not be found if indexer was added from the contextual type.
// in this case use fallback name
@@ -1818,7 +1818,7 @@ namespace ts {
}
function writeLiteralType(type: ObjectType, flags: TypeFormatFlags) {
- let resolved = resolveStructuredTypeMembers(type);
+ const resolved = resolveStructuredTypeMembers(type);
if (!resolved.properties.length && !resolved.stringIndexType && !resolved.numberIndexType) {
if (!resolved.callSignatures.length && !resolved.constructSignatures.length) {
writePunctuation(writer, SyntaxKind.OpenBraceToken);
@@ -1850,17 +1850,17 @@ namespace ts {
}
}
- let saveInObjectTypeLiteral = inObjectTypeLiteral;
+ const saveInObjectTypeLiteral = inObjectTypeLiteral;
inObjectTypeLiteral = true;
writePunctuation(writer, SyntaxKind.OpenBraceToken);
writer.writeLine();
writer.increaseIndent();
- for (let signature of resolved.callSignatures) {
+ for (const signature of resolved.callSignatures) {
buildSignatureDisplay(signature, writer, enclosingDeclaration, globalFlagsToPass, symbolStack);
writePunctuation(writer, SyntaxKind.SemicolonToken);
writer.writeLine();
}
- for (let signature of resolved.constructSignatures) {
+ for (const signature of resolved.constructSignatures) {
writeKeyword(writer, SyntaxKind.NewKeyword);
writeSpace(writer);
@@ -1896,11 +1896,11 @@ namespace ts {
writePunctuation(writer, SyntaxKind.SemicolonToken);
writer.writeLine();
}
- for (let p of resolved.properties) {
- let t = getTypeOfSymbol(p);
+ for (const p of resolved.properties) {
+ const t = getTypeOfSymbol(p);
if (p.flags & (SymbolFlags.Function | SymbolFlags.Method) && !getPropertiesOfObjectType(t).length) {
- let signatures = getSignaturesOfType(t, SignatureKind.Call);
- for (let signature of signatures) {
+ const signatures = getSignaturesOfType(t, SignatureKind.Call);
+ for (const signature of signatures) {
buildSymbolDisplay(p, writer);
if (p.flags & SymbolFlags.Optional) {
writePunctuation(writer, SyntaxKind.QuestionToken);
@@ -1929,7 +1929,7 @@ namespace ts {
}
function buildTypeParameterDisplayFromSymbol(symbol: Symbol, writer: SymbolWriter, enclosingDeclaraiton?: Node, flags?: TypeFormatFlags) {
- let targetSymbol = getTargetSymbol(symbol);
+ const targetSymbol = getTargetSymbol(symbol);
if (targetSymbol.flags & SymbolFlags.Class || targetSymbol.flags & SymbolFlags.Interface || targetSymbol.flags & SymbolFlags.TypeAlias) {
buildDisplayForTypeParametersAndDelimiters(getLocalTypeParametersOfClassOrInterfaceOrTypeAlias(symbol), writer, enclosingDeclaraiton, flags);
}
@@ -1937,7 +1937,7 @@ namespace ts {
function buildTypeParameterDisplay(tp: TypeParameter, writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags, symbolStack?: Symbol[]) {
appendSymbolNameOnly(tp.symbol, writer);
- let constraint = getConstraintOfTypeParameter(tp);
+ const constraint = getConstraintOfTypeParameter(tp);
if (constraint) {
writeSpace(writer);
writeKeyword(writer, SyntaxKind.ExtendsKeyword);
@@ -1947,7 +1947,7 @@ namespace ts {
}
function buildParameterDisplay(p: Symbol, writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags, symbolStack?: Symbol[]) {
- let parameterNode = p.valueDeclaration;
+ const parameterNode = p.valueDeclaration;
if (isRestParameter(parameterNode)) {
writePunctuation(writer, SyntaxKind.DotDotDotToken);
}
@@ -2069,14 +2069,14 @@ namespace ts {
function isUsedInExportAssignment(node: Node) {
// Get source File and see if it is external module and has export assigned symbol
- let externalModule = getContainingExternalModule(node);
+ const externalModule = getContainingExternalModule(node);
let exportAssignmentSymbol: Symbol;
let resolvedExportSymbol: Symbol;
if (externalModule) {
// This is export assigned symbol node
- let externalModuleSymbol = getSymbolOfNode(externalModule);
+ const externalModuleSymbol = getSymbolOfNode(externalModule);
exportAssignmentSymbol = getExportAssignmentSymbol(externalModuleSymbol);
- let symbolOfNode = getSymbolOfNode(node);
+ const symbolOfNode = getSymbolOfNode(node);
if (isSymbolUsedInExportAssignment(symbolOfNode)) {
return true;
}
@@ -2131,7 +2131,7 @@ namespace ts {
case SyntaxKind.FunctionDeclaration:
case SyntaxKind.EnumDeclaration:
case SyntaxKind.ImportEqualsDeclaration:
- let parent = getDeclarationContainer(node);
+ const parent = getDeclarationContainer(node);
// If the node is not exported or it is not ambient module element (except import declaration)
if (!(getCombinedNodeFlags(node) & NodeFlags.Export) &&
!(node.kind !== SyntaxKind.ImportEqualsDeclaration && parent.kind !== SyntaxKind.SourceFile && isInAmbientContext(parent))) {
@@ -2150,7 +2150,7 @@ namespace ts {
// Private/protected properties/methods are not visible
return false;
}
- // Public properties/methods are visible if its parents are visible, so let it fall into next case statement
+ // Public properties/methods are visible if its parents are visible, so const it fall into next case statement
case SyntaxKind.Constructor:
case SyntaxKind.ConstructSignature:
@@ -2192,7 +2192,7 @@ namespace ts {
}
if (node) {
- let links = getNodeLinks(node);
+ const links = getNodeLinks(node);
if (links.isVisible === undefined) {
links.isVisible = !!determineIfDeclarationIsVisible();
}
@@ -2206,12 +2206,12 @@ namespace ts {
exportSymbol = resolveName(node.parent, node.text, SymbolFlags.Value | SymbolFlags.Type | SymbolFlags.Namespace | SymbolFlags.Alias, Diagnostics.Cannot_find_name_0, node);
}
else if (node.parent.kind === SyntaxKind.ExportSpecifier) {
- let exportSpecifier = node.parent;
+ const exportSpecifier = node.parent;
exportSymbol = (exportSpecifier.parent.parent).moduleSpecifier ?
getExternalModuleMember(exportSpecifier.parent.parent, exportSpecifier) :
resolveEntityName(exportSpecifier.propertyName || exportSpecifier.name, SymbolFlags.Value | SymbolFlags.Type | SymbolFlags.Namespace | SymbolFlags.Alias);
}
- let result: Node[] = [];
+ const result: Node[] = [];
if (exportSymbol) {
buildVisibleNodeList(exportSymbol.declarations);
}
@@ -2220,16 +2220,16 @@ namespace ts {
function buildVisibleNodeList(declarations: Declaration[]) {
forEach(declarations, declaration => {
getNodeLinks(declaration).isVisible = true;
- let resultNode = getAnyImportSyntax(declaration) || declaration;
+ const resultNode = getAnyImportSyntax(declaration) || declaration;
if (!contains(result, resultNode)) {
result.push(resultNode);
}
if (isInternalModuleImportEqualsDeclaration(declaration)) {
// Add the referenced top container visible
- let internalModuleReference = (declaration).moduleReference;
- let firstIdentifier = getFirstIdentifier(internalModuleReference);
- let importSymbol = resolveName(declaration, firstIdentifier.text, SymbolFlags.Value | SymbolFlags.Type | SymbolFlags.Namespace,
+ const internalModuleReference = (declaration).moduleReference;
+ const firstIdentifier = getFirstIdentifier(internalModuleReference);
+ const importSymbol = resolveName(declaration, firstIdentifier.text, SymbolFlags.Value | SymbolFlags.Type | SymbolFlags.Namespace,
Diagnostics.Cannot_find_name_0, firstIdentifier);
buildVisibleNodeList(importSymbol.declarations);
}
@@ -2249,10 +2249,10 @@ namespace ts {
* @param propertyName The property name that should be used to query the target for its type
*/
function pushTypeResolution(target: TypeSystemEntity, propertyName: TypeSystemPropertyName): boolean {
- let resolutionCycleStartIndex = findResolutionCycleStartIndex(target, propertyName);
+ const resolutionCycleStartIndex = findResolutionCycleStartIndex(target, propertyName);
if (resolutionCycleStartIndex >= 0) {
// A cycle was found
- let { length } = resolutionTargets;
+ const { length } = resolutionTargets;
for (let i = resolutionCycleStartIndex; i < length; i++) {
resolutionResults[i] = false;
}
@@ -2316,13 +2316,13 @@ namespace ts {
// Every class automatically contains a static property member named 'prototype',
// the type of which is an instantiation of the class type with type Any supplied as a type argument for each type parameter.
// It is an error to explicitly declare a static property member with the name 'prototype'.
- let classType = getDeclaredTypeOfSymbol(prototype.parent);
+ const classType = getDeclaredTypeOfSymbol(prototype.parent);
return classType.typeParameters ? createTypeReference(classType, map(classType.typeParameters, _ => anyType)) : classType;
}
// Return the type of the given property in the given type, or undefined if no such property exists
function getTypeOfPropertyOfType(type: Type, name: string): Type {
- let prop = getPropertyOfType(type, name);
+ const prop = getPropertyOfType(type, name);
return prop ? getTypeOfSymbol(prop) : undefined;
}
@@ -2333,7 +2333,7 @@ namespace ts {
// Return the type of a binding element parent. We check SymbolLinks first to see if a type has been
// assigned by contextual typing.
function getTypeForBindingElementParent(node: VariableLikeDeclaration) {
- let symbol = getSymbolOfNode(node);
+ const symbol = getSymbolOfNode(node);
return symbol && getSymbolLinks(symbol).type || getTypeForVariableLikeDeclaration(node);
}
@@ -2359,8 +2359,8 @@ namespace ts {
// Return the inferred type for a binding element
function getTypeForBindingElement(declaration: BindingElement): Type {
- let pattern = declaration.parent;
- let parentType = getTypeForBindingElementParent(pattern.parent);
+ const pattern = declaration.parent;
+ const parentType = getTypeForBindingElementParent(pattern.parent);
// If parent has the unknown (error) type, then so does this binding element
if (parentType === unknownType) {
return unknownType;
@@ -2378,7 +2378,7 @@ namespace ts {
let type: Type;
if (pattern.kind === SyntaxKind.ObjectBindingPattern) {
// Use explicitly specified property name ({ p: xxx } form), or otherwise the implied name ({ p } form)
- let name = declaration.propertyName || declaration.name;
+ const name = declaration.propertyName || declaration.name;
if (isComputedNonLiteralName(name)) {
// computed properties with non-literal names are treated as 'any'
return anyType;
@@ -2386,7 +2386,7 @@ namespace ts {
// Use type of the specified property, or otherwise, for a numeric name, the type of the numeric index signature,
// or otherwise the type of the string index signature.
- let text = getTextOfPropertyName(name);
+ const text = getTextOfPropertyName(name);
type = getTypeOfPropertyOfType(parentType, text) ||
isNumericLiteralName(text) && getIndexTypeOfType(parentType, IndexKind.Number) ||
@@ -2400,10 +2400,10 @@ namespace ts {
// This elementType will be used if the specific property corresponding to this index is not
// present (aka the tuple element property). This call also checks that the parentType is in
// fact an iterable or array (depending on target language).
- let elementType = checkIteratedTypeOrElementType(parentType, pattern, /*allowStringInput*/ false);
+ const elementType = checkIteratedTypeOrElementType(parentType, pattern, /*allowStringInput*/ false);
if (!declaration.dotDotDotToken) {
// Use specific property type when parent is a tuple or numeric index type when parent is an array
- let propName = "" + indexOf(pattern.elements, declaration);
+ const propName = "" + indexOf(pattern.elements, declaration);
type = isTupleLikeType(parentType)
? getTypeOfPropertyOfType(parentType, propName)
: elementType;
@@ -2450,16 +2450,16 @@ namespace ts {
}
if (declaration.kind === SyntaxKind.Parameter) {
- let func = declaration.parent;
+ const func = declaration.parent;
// For a parameter of a set accessor, use the type of the get accessor if one is present
if (func.kind === SyntaxKind.SetAccessor && !hasDynamicName(func)) {
- let getter = getDeclarationOfKind(declaration.parent.symbol, SyntaxKind.GetAccessor);
+ const getter = getDeclarationOfKind(declaration.parent.symbol, SyntaxKind.GetAccessor);
if (getter) {
return getReturnTypeOfSignature(getSignatureFromDeclaration(getter));
}
}
// Use contextual parameter type if one is available
- let type = getContextuallyTypedParameterType(declaration);
+ const type = getContextuallyTypedParameterType(declaration);
if (type) {
return type;
}
@@ -2499,23 +2499,22 @@ namespace ts {
// Return the type implied by an object binding pattern
function getTypeFromObjectBindingPattern(pattern: BindingPattern, includePatternInType: boolean): Type {
- let members: SymbolTable = {};
+ const members: SymbolTable = {};
forEach(pattern.elements, e => {
- let name = e.propertyName || e.name;
+ const name = e.propertyName || e.name;
if (isComputedNonLiteralName(name)) {
// do not include computed properties in the implied type
return;
}
- let text = getTextOfPropertyName(name);
- let flags = SymbolFlags.Property | SymbolFlags.Transient | (e.initializer ? SymbolFlags.Optional : 0);
-
- let symbol = createSymbol(flags, text);
+ const text = getTextOfPropertyName(name);
+ const flags = SymbolFlags.Property | SymbolFlags.Transient | (e.initializer ? SymbolFlags.Optional : 0);
+ const symbol = createSymbol(flags, text);
symbol.type = getTypeFromBindingElement(e, includePatternInType);
symbol.bindingElement = e;
members[symbol.name] = symbol;
});
- let result = createAnonymousType(undefined, members, emptyArray, emptyArray, undefined, undefined);
+ const result = createAnonymousType(undefined, members, emptyArray, emptyArray, undefined, undefined);
if (includePatternInType) {
result.pattern = pattern;
}
@@ -2524,14 +2523,14 @@ namespace ts {
// Return the type implied by an array binding pattern
function getTypeFromArrayBindingPattern(pattern: BindingPattern, includePatternInType: boolean): Type {
- let elements = pattern.elements;
+ const elements = pattern.elements;
if (elements.length === 0 || elements[elements.length - 1].dotDotDotToken) {
return languageVersion >= ScriptTarget.ES6 ? createIterableType(anyType) : anyArrayType;
}
// If the pattern has at least one element, and no rest element, then it should imply a tuple type.
- let elementTypes = map(elements, e => e.kind === SyntaxKind.OmittedExpression ? anyType : getTypeFromBindingElement(e, includePatternInType));
+ const elementTypes = map(elements, e => e.kind === SyntaxKind.OmittedExpression ? anyType : getTypeFromBindingElement(e, includePatternInType));
if (includePatternInType) {
- let result = createNewTupleType(elementTypes);
+ const result = createNewTupleType(elementTypes);
result.pattern = pattern;
return result;
}
@@ -2577,7 +2576,7 @@ namespace ts {
// Report implicit any errors unless this is a private property within an ambient declaration
if (reportErrors && compilerOptions.noImplicitAny) {
- let root = getRootDeclaration(declaration);
+ const root = getRootDeclaration(declaration);
if (!isPrivateWithinAmbient(root) && !(root.kind === SyntaxKind.Parameter && isPrivateWithinAmbient(root.parent))) {
reportImplicitAnyError(declaration, type);
}
@@ -2586,14 +2585,14 @@ namespace ts {
}
function getTypeOfVariableOrParameterOrProperty(symbol: Symbol): Type {
- let links = getSymbolLinks(symbol);
+ const links = getSymbolLinks(symbol);
if (!links.type) {
// Handle prototype property
if (symbol.flags & SymbolFlags.Prototype) {
return links.type = getTypeOfPrototypeProperty(symbol);
}
// Handle catch clause variables
- let declaration = symbol.valueDeclaration;
+ const declaration = symbol.valueDeclaration;
if (declaration.parent.kind === SyntaxKind.CatchClause) {
return links.type = anyType;
}
@@ -2633,7 +2632,7 @@ namespace ts {
return accessor.type && getTypeFromTypeNode(accessor.type);
}
else {
- let setterTypeAnnotation = getSetAccessorTypeAnnotationNode(accessor);
+ const setterTypeAnnotation = getSetAccessorTypeAnnotationNode(accessor);
return setterTypeAnnotation && getTypeFromTypeNode(setterTypeAnnotation);
}
}
@@ -2641,22 +2640,22 @@ namespace ts {
}
function getTypeOfAccessors(symbol: Symbol): Type {
- let links = getSymbolLinks(symbol);
+ const links = getSymbolLinks(symbol);
if (!links.type) {
if (!pushTypeResolution(symbol, TypeSystemPropertyName.Type)) {
return unknownType;
}
- let getter = getDeclarationOfKind(symbol, SyntaxKind.GetAccessor);
- let setter = getDeclarationOfKind(symbol, SyntaxKind.SetAccessor);
+ const getter = getDeclarationOfKind(symbol, SyntaxKind.GetAccessor);
+ const setter = getDeclarationOfKind(symbol, SyntaxKind.SetAccessor);
let type: Type;
// First try to see if the user specified a return type on the get-accessor.
- let getterReturnType = getAnnotatedAccessorType(getter);
+ const getterReturnType = getAnnotatedAccessorType(getter);
if (getterReturnType) {
type = getterReturnType;
}
else {
// If the user didn't specify a return type, try to use the set-accessor's parameter type.
- let setterParameterType = getAnnotatedAccessorType(setter);
+ const setterParameterType = getAnnotatedAccessorType(setter);
if (setterParameterType) {
type = setterParameterType;
}
@@ -2677,7 +2676,7 @@ namespace ts {
if (!popTypeResolution()) {
type = anyType;
if (compilerOptions.noImplicitAny) {
- let getter = getDeclarationOfKind(symbol, SyntaxKind.GetAccessor);
+ const getter = getDeclarationOfKind(symbol, SyntaxKind.GetAccessor);
error(getter, Diagnostics._0_implicitly_has_return_type_any_because_it_does_not_have_a_return_type_annotation_and_is_referenced_directly_or_indirectly_in_one_of_its_return_expressions, symbolToString(symbol));
}
}
@@ -2687,7 +2686,7 @@ namespace ts {
}
function getTypeOfFuncClassEnumModule(symbol: Symbol): Type {
- let links = getSymbolLinks(symbol);
+ const links = getSymbolLinks(symbol);
if (!links.type) {
links.type = createObjectType(TypeFlags.Anonymous, symbol);
}
@@ -2695,7 +2694,7 @@ namespace ts {
}
function getTypeOfEnumMember(symbol: Symbol): Type {
- let links = getSymbolLinks(symbol);
+ const links = getSymbolLinks(symbol);
if (!links.type) {
links.type = getDeclaredTypeOfEnum(getParentOfSymbol(symbol));
}
@@ -2703,9 +2702,9 @@ namespace ts {
}
function getTypeOfAlias(symbol: Symbol): Type {
- let links = getSymbolLinks(symbol);
+ const links = getSymbolLinks(symbol);
if (!links.type) {
- let targetSymbol = resolveAlias(symbol);
+ const targetSymbol = resolveAlias(symbol);
// It only makes sense to get the type of a value symbol. If the result of resolving
// the alias is not a value, then it has no type. To get the type associated with a
@@ -2720,7 +2719,7 @@ namespace ts {
}
function getTypeOfInstantiatedSymbol(symbol: Symbol): Type {
- let links = getSymbolLinks(symbol);
+ const links = getSymbolLinks(symbol);
if (!links.type) {
links.type = instantiateType(getTypeOfSymbol(links.target), links.mapper);
}
@@ -2756,7 +2755,7 @@ namespace ts {
function hasBaseType(type: InterfaceType, checkBase: InterfaceType) {
return check(type);
function check(type: InterfaceType): boolean {
- let target = getTargetType(type);
+ const target = getTargetType(type);
return target === checkBase || forEach(getBaseTypes(target), check);
}
}
@@ -2765,8 +2764,8 @@ namespace ts {
// The function allocates a new array if the input type parameter set is undefined, but otherwise it modifies the set
// in-place and returns the same array.
function appendTypeParameters(typeParameters: TypeParameter[], declarations: TypeParameterDeclaration[]): TypeParameter[] {
- for (let declaration of declarations) {
- let tp = getDeclaredTypeOfTypeParameter(getSymbolOfNode(declaration));
+ for (const declaration of declarations) {
+ const tp = getDeclaredTypeOfTypeParameter(getSymbolOfNode(declaration));
if (!typeParameters) {
typeParameters = [tp];
}
@@ -2789,7 +2788,7 @@ namespace ts {
if (node.kind === SyntaxKind.ClassDeclaration || node.kind === SyntaxKind.ClassExpression ||
node.kind === SyntaxKind.FunctionDeclaration || node.kind === SyntaxKind.FunctionExpression ||
node.kind === SyntaxKind.MethodDeclaration || node.kind === SyntaxKind.ArrowFunction) {
- let declarations = (node).typeParameters;
+ const declarations = (node).typeParameters;
if (declarations) {
return appendTypeParameters(appendOuterTypeParameters(typeParameters, node), declarations);
}
@@ -2799,7 +2798,7 @@ namespace ts {
// The outer type parameters are those defined by enclosing generic classes, methods, or functions.
function getOuterTypeParametersOfClassOrInterface(symbol: Symbol): TypeParameter[] {
- let declaration = symbol.flags & SymbolFlags.Class ? symbol.valueDeclaration : getDeclarationOfKind(symbol, SyntaxKind.InterfaceDeclaration);
+ const declaration = symbol.flags & SymbolFlags.Class ? symbol.valueDeclaration : getDeclarationOfKind(symbol, SyntaxKind.InterfaceDeclaration);
return appendOuterTypeParameters(undefined, declaration);
}
@@ -2807,10 +2806,10 @@ namespace ts {
// interface, or type alias.
function getLocalTypeParametersOfClassOrInterfaceOrTypeAlias(symbol: Symbol): TypeParameter[] {
let result: TypeParameter[];
- for (let node of symbol.declarations) {
+ for (const node of symbol.declarations) {
if (node.kind === SyntaxKind.InterfaceDeclaration || node.kind === SyntaxKind.ClassDeclaration ||
node.kind === SyntaxKind.ClassExpression || node.kind === SyntaxKind.TypeAliasDeclaration) {
- let declaration = node;
+ const declaration = node;
if (declaration.typeParameters) {
result = appendTypeParameters(result, declaration.typeParameters);
}
@@ -2834,7 +2833,7 @@ namespace ts {
}
function getConstructorsForTypeArguments(type: ObjectType, typeArgumentNodes: TypeNode[]): Signature[] {
- let typeArgCount = typeArgumentNodes ? typeArgumentNodes.length : 0;
+ const typeArgCount = typeArgumentNodes ? typeArgumentNodes.length : 0;
return filter(getSignaturesOfType(type, SignatureKind.Construct),
sig => (sig.typeParameters ? sig.typeParameters.length : 0) === typeArgCount);
}
@@ -2842,7 +2841,7 @@ namespace ts {
function getInstantiatedConstructorsForTypeArguments(type: ObjectType, typeArgumentNodes: TypeNode[]): Signature[] {
let signatures = getConstructorsForTypeArguments(type, typeArgumentNodes);
if (typeArgumentNodes) {
- let typeArguments = map(typeArgumentNodes, getTypeFromTypeNode);
+ const typeArguments = map(typeArgumentNodes, getTypeFromTypeNode);
signatures = map(signatures, sig => getSignatureInstantiation(sig, typeArguments));
}
return signatures;
@@ -2855,14 +2854,14 @@ namespace ts {
// an object type with at least one construct signature.
function getBaseConstructorTypeOfClass(type: InterfaceType): ObjectType {
if (!type.resolvedBaseConstructorType) {
- let baseTypeNode = getBaseTypeNodeOfClass(type);
+ const baseTypeNode = getBaseTypeNodeOfClass(type);
if (!baseTypeNode) {
return type.resolvedBaseConstructorType = undefinedType;
}
if (!pushTypeResolution(type, TypeSystemPropertyName.ResolvedBaseConstructorType)) {
return unknownType;
}
- let baseConstructorType = checkExpression(baseTypeNode.expression);
+ const baseConstructorType = checkExpression(baseTypeNode.expression);
if (baseConstructorType.flags & TypeFlags.ObjectType) {
// Resolving the members of a class requires us to resolve the base class of that class.
// We force resolution here such that we catch circularities now.
@@ -2886,8 +2885,8 @@ namespace ts {
}
function getBaseTypes(type: InterfaceType): ObjectType[] {
- let isClass = type.symbol.flags & SymbolFlags.Class;
- let isInterface = type.symbol.flags & SymbolFlags.Interface;
+ const isClass = type.symbol.flags & SymbolFlags.Class;
+ const isInterface = type.symbol.flags & SymbolFlags.Interface;
if (!type.resolvedBaseTypes) {
if (!isClass && !isInterface) {
Debug.fail("type must be class or interface");
@@ -2904,11 +2903,11 @@ namespace ts {
function resolveBaseTypesOfClass(type: InterfaceType): void {
type.resolvedBaseTypes = type.resolvedBaseTypes || emptyArray;
- let baseContructorType = getBaseConstructorTypeOfClass(type);
+ const baseContructorType = getBaseConstructorTypeOfClass(type);
if (!(baseContructorType.flags & TypeFlags.ObjectType)) {
return;
}
- let baseTypeNode = getBaseTypeNodeOfClass(type);
+ const baseTypeNode = getBaseTypeNodeOfClass(type);
let baseType: Type;
if (baseContructorType.symbol && baseContructorType.symbol.flags & SymbolFlags.Class) {
// When base constructor type is a class we know that the constructors all have the same type parameters as the
@@ -2920,7 +2919,7 @@ namespace ts {
// The class derives from a "class-like" constructor function, check that we have at least one construct signature
// with a matching number of type parameters and use the return type of the first instantiated signature. Elsewhere
// we check that all instantiated signatures return the same type.
- let constructors = getInstantiatedConstructorsForTypeArguments(baseContructorType, baseTypeNode.typeArguments);
+ const constructors = getInstantiatedConstructorsForTypeArguments(baseContructorType, baseTypeNode.typeArguments);
if (!constructors.length) {
error(baseTypeNode.expression, Diagnostics.No_base_constructor_has_the_specified_number_of_type_arguments);
return;
@@ -2949,10 +2948,10 @@ namespace ts {
function resolveBaseTypesOfInterface(type: InterfaceType): void {
type.resolvedBaseTypes = type.resolvedBaseTypes || emptyArray;
- for (let declaration of type.symbol.declarations) {
+ for (const declaration of type.symbol.declarations) {
if (declaration.kind === SyntaxKind.InterfaceDeclaration && getInterfaceBaseTypeNodes(declaration)) {
- for (let node of getInterfaceBaseTypeNodes(declaration)) {
- let baseType = getTypeFromTypeNode(node);
+ for (const node of getInterfaceBaseTypeNodes(declaration)) {
+ const baseType = getTypeFromTypeNode(node);
if (baseType !== unknownType) {
if (getTargetType(baseType).flags & (TypeFlags.Class | TypeFlags.Interface)) {
if (type !== baseType && !hasBaseType(baseType, type)) {
@@ -2980,16 +2979,16 @@ namespace ts {
// true if the interface itself contains no references to "this" in its body, if all base types are interfaces,
// and if none of the base interfaces have a "this" type.
function isIndependentInterface(symbol: Symbol): boolean {
- for (let declaration of symbol.declarations) {
+ for (const declaration of symbol.declarations) {
if (declaration.kind === SyntaxKind.InterfaceDeclaration) {
if (declaration.flags & NodeFlags.ContainsThis) {
return false;
}
- let baseTypeNodes = getInterfaceBaseTypeNodes(declaration);
+ const baseTypeNodes = getInterfaceBaseTypeNodes(declaration);
if (baseTypeNodes) {
- for (let node of baseTypeNodes) {
+ for (const node of baseTypeNodes) {
if (isSupportedExpressionWithTypeArguments(node)) {
- let baseSymbol = resolveEntityName(node.expression, SymbolFlags.Type, /*ignoreErrors*/ true);
+ const baseSymbol = resolveEntityName(node.expression, SymbolFlags.Type, /*ignoreErrors*/ true);
if (!baseSymbol || !(baseSymbol.flags & SymbolFlags.Interface) || getDeclaredTypeOfClassOrInterface(baseSymbol).thisType) {
return false;
}
@@ -3002,12 +3001,12 @@ namespace ts {
}
function getDeclaredTypeOfClassOrInterface(symbol: Symbol): InterfaceType {
- let links = getSymbolLinks(symbol);
+ const links = getSymbolLinks(symbol);
if (!links.declaredType) {
- let kind = symbol.flags & SymbolFlags.Class ? TypeFlags.Class : TypeFlags.Interface;
- let type = links.declaredType = createObjectType(kind, symbol);
- let outerTypeParameters = getOuterTypeParametersOfClassOrInterface(symbol);
- let localTypeParameters = getLocalTypeParametersOfClassOrInterfaceOrTypeAlias(symbol);
+ const kind = symbol.flags & SymbolFlags.Class ? TypeFlags.Class : TypeFlags.Interface;
+ const type = links.declaredType = createObjectType(kind, symbol);
+ const outerTypeParameters = getOuterTypeParametersOfClassOrInterface(symbol);
+ const localTypeParameters = getLocalTypeParametersOfClassOrInterfaceOrTypeAlias(symbol);
// A class or interface is generic if it has type parameters or a "this" type. We always give classes a "this" type
// because it is not feasible to analyze all members to determine if the "this" type escapes the class (in particular,
// property types inferred from initializers and method return types inferred from return statements are very hard
@@ -3031,14 +3030,14 @@ namespace ts {
}
function getDeclaredTypeOfTypeAlias(symbol: Symbol): Type {
- let links = getSymbolLinks(symbol);
+ const links = getSymbolLinks(symbol);
if (!links.declaredType) {
// Note that we use the links object as the target here because the symbol object is used as the unique
// identity for resolution of the 'type' property in SymbolLinks.
if (!pushTypeResolution(symbol, TypeSystemPropertyName.DeclaredType)) {
return unknownType;
}
- let declaration = getDeclarationOfKind(symbol, SyntaxKind.TypeAliasDeclaration);
+ const declaration = getDeclarationOfKind(symbol, SyntaxKind.TypeAliasDeclaration);
let type = getTypeFromTypeNode(declaration.type);
if (popTypeResolution()) {
links.typeParameters = getLocalTypeParametersOfClassOrInterfaceOrTypeAlias(symbol);
@@ -3059,9 +3058,9 @@ namespace ts {
}
function getDeclaredTypeOfEnum(symbol: Symbol): Type {
- let links = getSymbolLinks(symbol);
+ const links = getSymbolLinks(symbol);
if (!links.declaredType) {
- let type = createType(TypeFlags.Enum);
+ const type = createType(TypeFlags.Enum);
type.symbol = symbol;
links.declaredType = type;
}
@@ -3069,9 +3068,9 @@ namespace ts {
}
function getDeclaredTypeOfTypeParameter(symbol: Symbol): TypeParameter {
- let links = getSymbolLinks(symbol);
+ const links = getSymbolLinks(symbol);
if (!links.declaredType) {
- let type = createType(TypeFlags.TypeParameter);
+ const type = createType(TypeFlags.TypeParameter);
type.symbol = symbol;
if (!(getDeclarationOfKind(symbol, SyntaxKind.TypeParameter)).constraint) {
type.constraint = noConstraintType;
@@ -3082,7 +3081,7 @@ namespace ts {
}
function getDeclaredTypeOfAlias(symbol: Symbol): Type {
- let links = getSymbolLinks(symbol);
+ const links = getSymbolLinks(symbol);
if (!links.declaredType) {
links.declaredType = getDeclaredTypeOfSymbol(resolveAlias(symbol));
}
@@ -3112,7 +3111,7 @@ namespace ts {
// A type reference is considered independent if each type argument is considered independent.
function isIndependentTypeReference(node: TypeReferenceNode): boolean {
if (node.typeArguments) {
- for (let typeNode of node.typeArguments) {
+ for (const typeNode of node.typeArguments) {
if (!isIndependentType(typeNode)) {
return false;
}
@@ -3154,7 +3153,7 @@ namespace ts {
if (node.kind !== SyntaxKind.Constructor && (!node.type || !isIndependentType(node.type))) {
return false;
}
- for (let parameter of node.parameters) {
+ for (const parameter of node.parameters) {
if (!isIndependentVariableLikeDeclaration(parameter)) {
return false;
}
@@ -3169,7 +3168,7 @@ namespace ts {
// assumed not to be free of "this" references.
function isIndependentMember(symbol: Symbol): boolean {
if (symbol.declarations && symbol.declarations.length === 1) {
- let declaration = symbol.declarations[0];
+ const declaration = symbol.declarations[0];
if (declaration) {
switch (declaration.kind) {
case SyntaxKind.PropertyDeclaration:
@@ -3186,8 +3185,8 @@ namespace ts {
}
function createSymbolTable(symbols: Symbol[]): SymbolTable {
- let result: SymbolTable = {};
- for (let symbol of symbols) {
+ const result: SymbolTable = {};
+ for (const symbol of symbols) {
result[symbol.name] = symbol;
}
return result;
@@ -3196,15 +3195,15 @@ namespace ts {
// The mappingThisOnly flag indicates that the only type parameter being mapped is "this". When the flag is true,
// we check symbols to see if we can quickly conclude they are free of "this" references, thus needing no instantiation.
function createInstantiatedSymbolTable(symbols: Symbol[], mapper: TypeMapper, mappingThisOnly: boolean): SymbolTable {
- let result: SymbolTable = {};
- for (let symbol of symbols) {
+ const result: SymbolTable = {};
+ for (const symbol of symbols) {
result[symbol.name] = mappingThisOnly && isIndependentMember(symbol) ? symbol : instantiateSymbol(symbol, mapper);
}
return result;
}
function addInheritedMembers(symbols: SymbolTable, baseSymbols: Symbol[]) {
- for (let s of baseSymbols) {
+ for (const s of baseSymbols) {
if (!hasProperty(symbols, s.name)) {
symbols[s.name] = s;
}
@@ -3213,7 +3212,7 @@ namespace ts {
function addInheritedSignatures(signatures: Signature[], baseSignatures: Signature[]) {
if (baseSignatures) {
- for (let signature of baseSignatures) {
+ for (const signature of baseSignatures) {
signatures.push(signature);
}
}
@@ -3221,7 +3220,7 @@ namespace ts {
function resolveDeclaredMembers(type: InterfaceType): InterfaceTypeWithDeclaredMembers {
if (!(type).declaredProperties) {
- let symbol = type.symbol;
+ const symbol = type.symbol;
(type).declaredProperties = getNamedMembers(symbol.members);
(type).declaredCallSignatures = getSignaturesOfSymbol(symbol.members["__call"]);
(type).declaredConstructSignatures = getSignaturesOfSymbol(symbol.members["__new"]);
@@ -3254,14 +3253,14 @@ namespace ts {
stringIndexType = instantiateType(source.declaredStringIndexType, mapper);
numberIndexType = instantiateType(source.declaredNumberIndexType, mapper);
}
- let baseTypes = getBaseTypes(source);
+ const baseTypes = getBaseTypes(source);
if (baseTypes.length) {
if (members === source.symbol.members) {
members = createSymbolTable(source.declaredProperties);
}
- let thisArgument = lastOrUndefined(typeArguments);
- for (let baseType of baseTypes) {
- let instantiatedBaseType = thisArgument ? getTypeWithThisArgument(instantiateType(baseType, mapper), thisArgument) : baseType;
+ const thisArgument = lastOrUndefined(typeArguments);
+ for (const baseType of baseTypes) {
+ const instantiatedBaseType = thisArgument ? getTypeWithThisArgument(instantiateType(baseType, mapper), thisArgument) : baseType;
addInheritedMembers(members, getPropertiesOfObjectType(instantiatedBaseType));
callSignatures = concatenate(callSignatures, getSignaturesOfType(instantiatedBaseType, SignatureKind.Call));
constructSignatures = concatenate(constructSignatures, getSignaturesOfType(instantiatedBaseType, SignatureKind.Construct));
@@ -3277,16 +3276,16 @@ namespace ts {
}
function resolveTypeReferenceMembers(type: TypeReference): void {
- let source = resolveDeclaredMembers(type.target);
- let typeParameters = concatenate(source.typeParameters, [source.thisType]);
- let typeArguments = type.typeArguments && type.typeArguments.length === typeParameters.length ?
+ const source = resolveDeclaredMembers(type.target);
+ const typeParameters = concatenate(source.typeParameters, [source.thisType]);
+ const typeArguments = type.typeArguments && type.typeArguments.length === typeParameters.length ?
type.typeArguments : concatenate(type.typeArguments, [type]);
resolveObjectTypeMembers(type, source, typeParameters, typeArguments);
}
function createSignature(declaration: SignatureDeclaration, typeParameters: TypeParameter[], parameters: Symbol[],
resolvedReturnType: Type, typePredicate: TypePredicate, minArgumentCount: number, hasRestParameter: boolean, hasStringLiterals: boolean): Signature {
- let sig = new Signature(checker);
+ const sig = new Signature(checker);
sig.declaration = declaration;
sig.typeParameters = typeParameters;
sig.parameters = parameters;
@@ -3307,16 +3306,16 @@ namespace ts {
if (!hasClassBaseType(classType)) {
return [createSignature(undefined, classType.localTypeParameters, emptyArray, classType, undefined, 0, false, false)];
}
- let baseConstructorType = getBaseConstructorTypeOfClass(classType);
- let baseSignatures = getSignaturesOfType(baseConstructorType, SignatureKind.Construct);
- let baseTypeNode = getBaseTypeNodeOfClass(classType);
- let typeArguments = map(baseTypeNode.typeArguments, getTypeFromTypeNode);
- let typeArgCount = typeArguments ? typeArguments.length : 0;
- let result: Signature[] = [];
- for (let baseSig of baseSignatures) {
- let typeParamCount = baseSig.typeParameters ? baseSig.typeParameters.length : 0;
+ const baseConstructorType = getBaseConstructorTypeOfClass(classType);
+ const baseSignatures = getSignaturesOfType(baseConstructorType, SignatureKind.Construct);
+ const baseTypeNode = getBaseTypeNodeOfClass(classType);
+ const typeArguments = map(baseTypeNode.typeArguments, getTypeFromTypeNode);
+ const typeArgCount = typeArguments ? typeArguments.length : 0;
+ const result: Signature[] = [];
+ for (const baseSig of baseSignatures) {
+ const typeParamCount = baseSig.typeParameters ? baseSig.typeParameters.length : 0;
if (typeParamCount === typeArgCount) {
- let sig = typeParamCount ? getSignatureInstantiation(baseSig, typeArguments) : cloneSignature(baseSig);
+ const sig = typeParamCount ? getSignatureInstantiation(baseSig, typeArguments) : cloneSignature(baseSig);
sig.typeParameters = classType.localTypeParameters;
sig.resolvedReturnType = classType;
result.push(sig);
@@ -3326,9 +3325,9 @@ namespace ts {
}
function createTupleTypeMemberSymbols(memberTypes: Type[]): SymbolTable {
- let members: SymbolTable = {};
+ const members: SymbolTable = {};
for (let i = 0; i < memberTypes.length; i++) {
- let symbol = createSymbol(SymbolFlags.Property | SymbolFlags.Transient, "" + i);
+ const symbol = createSymbol(SymbolFlags.Property | SymbolFlags.Transient, "" + i);
symbol.type = memberTypes[i];
members[i] = symbol;
}
@@ -3336,16 +3335,16 @@ namespace ts {
}
function resolveTupleTypeMembers(type: TupleType) {
- let arrayElementType = getUnionType(type.elementTypes, /*noSubtypeReduction*/ true);
+ const arrayElementType = getUnionType(type.elementTypes, /*noSubtypeReduction*/ true);
// Make the tuple type itself the 'this' type by including an extra type argument
- let arrayType = resolveStructuredTypeMembers(createTypeFromGenericGlobalType(globalArrayType, [arrayElementType, type]));
- let members = createTupleTypeMemberSymbols(type.elementTypes);
+ const arrayType = resolveStructuredTypeMembers(createTypeFromGenericGlobalType(globalArrayType, [arrayElementType, type]));
+ const members = createTupleTypeMemberSymbols(type.elementTypes);
addInheritedMembers(members, arrayType.properties);
setObjectTypeMembers(type, members, arrayType.callSignatures, arrayType.constructSignatures, arrayType.stringIndexType, arrayType.numberIndexType);
}
function findMatchingSignature(signatureList: Signature[], signature: Signature, partialMatch: boolean, ignoreReturnTypes: boolean): Signature {
- for (let s of signatureList) {
+ for (const s of signatureList) {
if (compareSignatures(s, signature, partialMatch, ignoreReturnTypes, compareTypes)) {
return s;
}
@@ -3369,7 +3368,7 @@ namespace ts {
let result: Signature[] = undefined;
for (let i = 0; i < signatureLists.length; i++) {
// Allow matching non-generic signatures to have excess parameters and different return types
- let match = i === listIndex ? signature : findMatchingSignature(signatureLists[i], signature, /*partialMatch*/ true, /*ignoreReturnTypes*/ true);
+ const match = i === listIndex ? signature : findMatchingSignature(signatureLists[i], signature, /*partialMatch*/ true, /*ignoreReturnTypes*/ true);
if (!match) {
return undefined;
}
@@ -3385,13 +3384,13 @@ namespace ts {
// parameters and may differ in return types. When signatures differ in return types, the resulting return
// type is the union of the constituent return types.
function getUnionSignatures(types: Type[], kind: SignatureKind): Signature[] {
- let signatureLists = map(types, t => getSignaturesOfType(t, kind));
+ const signatureLists = map(types, t => getSignaturesOfType(t, kind));
let result: Signature[] = undefined;
for (let i = 0; i < signatureLists.length; i++) {
- for (let signature of signatureLists[i]) {
+ for (const signature of signatureLists[i]) {
// Only process signatures with parameter lists that aren't already in the result list
if (!result || !findMatchingSignature(result, signature, /*partialMatch*/ false, /*ignoreReturnTypes*/ true)) {
- let unionSignatures = findMatchingSignatures(signatureLists, signature, i);
+ const unionSignatures = findMatchingSignatures(signatureLists, signature, i);
if (unionSignatures) {
let s = signature;
// Union the result types when more than one signature matches
@@ -3410,9 +3409,9 @@ namespace ts {
}
function getUnionIndexType(types: Type[], kind: IndexKind): Type {
- let indexTypes: Type[] = [];
- for (let type of types) {
- let indexType = getIndexTypeOfType(type, kind);
+ const indexTypes: Type[] = [];
+ for (const type of types) {
+ const indexType = getIndexTypeOfType(type, kind);
if (!indexType) {
return undefined;
}
@@ -3424,10 +3423,10 @@ namespace ts {
function resolveUnionTypeMembers(type: UnionType) {
// The members and properties collections are empty for union types. To get all properties of a union
// type use getPropertiesOfType (only the language service uses this).
- let callSignatures = getUnionSignatures(type.types, SignatureKind.Call);
- let constructSignatures = getUnionSignatures(type.types, SignatureKind.Construct);
- let stringIndexType = getUnionIndexType(type.types, IndexKind.String);
- let numberIndexType = getUnionIndexType(type.types, IndexKind.Number);
+ const callSignatures = getUnionSignatures(type.types, SignatureKind.Call);
+ const constructSignatures = getUnionSignatures(type.types, SignatureKind.Construct);
+ const stringIndexType = getUnionIndexType(type.types, IndexKind.String);
+ const numberIndexType = getUnionIndexType(type.types, IndexKind.Number);
setObjectTypeMembers(type, emptySymbols, callSignatures, constructSignatures, stringIndexType, numberIndexType);
}
@@ -3442,7 +3441,7 @@ namespace ts {
let constructSignatures: Signature[] = emptyArray;
let stringIndexType: Type = undefined;
let numberIndexType: Type = undefined;
- for (let t of type.types) {
+ for (const t of type.types) {
callSignatures = concatenate(callSignatures, getSignaturesOfType(t, SignatureKind.Call));
constructSignatures = concatenate(constructSignatures, getSignaturesOfType(t, SignatureKind.Construct));
stringIndexType = intersectTypes(stringIndexType, getIndexTypeOfType(t, IndexKind.String));
@@ -3452,7 +3451,7 @@ namespace ts {
}
function resolveAnonymousTypeMembers(type: AnonymousType) {
- let symbol = type.symbol;
+ const symbol = type.symbol;
let members: SymbolTable;
let callSignatures: Signature[];
let constructSignatures: Signature[];
@@ -3485,12 +3484,12 @@ namespace ts {
callSignatures = getSignaturesOfSymbol(symbol);
}
if (symbol.flags & SymbolFlags.Class) {
- let classType = getDeclaredTypeOfClassOrInterface(symbol);
+ const classType = getDeclaredTypeOfClassOrInterface(symbol);
constructSignatures = getSignaturesOfSymbol(symbol.members["__constructor"]);
if (!constructSignatures.length) {
constructSignatures = getDefaultConstructSignatures(classType);
}
- let baseConstructorType = getBaseConstructorTypeOfClass(classType);
+ const baseConstructorType = getBaseConstructorTypeOfClass(classType);
if (baseConstructorType.flags & TypeFlags.ObjectType) {
members = createSymbolTable(getNamedMembers(members));
addInheritedMembers(members, getPropertiesOfObjectType(baseConstructorType));
@@ -3538,9 +3537,9 @@ namespace ts {
// return the symbol for that property.Otherwise return undefined.
function getPropertyOfObjectType(type: Type, name: string): Symbol {
if (type.flags & TypeFlags.ObjectType) {
- let resolved = resolveStructuredTypeMembers(type);
+ const resolved = resolveStructuredTypeMembers(type);
if (hasProperty(resolved.members, name)) {
- let symbol = resolved.members[name];
+ const symbol = resolved.members[name];
if (symbolIsValue(symbol)) {
return symbol;
}
@@ -3549,8 +3548,8 @@ namespace ts {
}
function getPropertiesOfUnionOrIntersectionType(type: UnionOrIntersectionType): Symbol[] {
- for (let current of type.types) {
- for (let prop of getPropertiesOfType(current)) {
+ for (const current of type.types) {
+ for (const prop of getPropertiesOfType(current)) {
getPropertyOfUnionOrIntersectionType(type, prop.name);
}
// The properties of a union type are those that are present in all constituent types, so
@@ -3597,12 +3596,12 @@ namespace ts {
}
function createUnionOrIntersectionProperty(containingType: UnionOrIntersectionType, name: string): Symbol {
- let types = containingType.types;
+ const types = containingType.types;
let props: Symbol[];
- for (let current of types) {
- let type = getApparentType(current);
+ for (const current of types) {
+ const type = getApparentType(current);
if (type !== unknownType) {
- let prop = getPropertyOfType(type, name);
+ const prop = getPropertyOfType(type, name);
if (prop && !(getDeclarationFlagsFromSymbol(prop) & (NodeFlags.Private | NodeFlags.Protected))) {
if (!props) {
props = [prop];
@@ -3623,15 +3622,15 @@ namespace ts {
if (props.length === 1) {
return props[0];
}
- let propTypes: Type[] = [];
- let declarations: Declaration[] = [];
- for (let prop of props) {
+ const propTypes: Type[] = [];
+ const declarations: Declaration[] = [];
+ for (const prop of props) {
if (prop.declarations) {
addRange(declarations, prop.declarations);
}
propTypes.push(getTypeOfSymbol(prop));
}
- let result = createSymbol(SymbolFlags.Property | SymbolFlags.Transient | SymbolFlags.SyntheticProperty, name);
+ const result = createSymbol(SymbolFlags.Property | SymbolFlags.Transient | SymbolFlags.SyntheticProperty, name);
result.containingType = containingType;
result.declarations = declarations;
result.type = containingType.flags & TypeFlags.Union ? getUnionType(propTypes) : getIntersectionType(propTypes);
@@ -3639,11 +3638,11 @@ namespace ts {
}
function getPropertyOfUnionOrIntersectionType(type: UnionOrIntersectionType, name: string): Symbol {
- let properties = type.resolvedProperties || (type.resolvedProperties = {});
+ const properties = type.resolvedProperties || (type.resolvedProperties = {});
if (hasProperty(properties, name)) {
return properties[name];
}
- let property = createUnionOrIntersectionProperty(type, name);
+ const property = createUnionOrIntersectionProperty(type, name);
if (property) {
properties[name] = property;
}
@@ -3656,15 +3655,15 @@ namespace ts {
function getPropertyOfType(type: Type, name: string): Symbol {
type = getApparentType(type);
if (type.flags & TypeFlags.ObjectType) {
- let resolved = resolveStructuredTypeMembers(type);
+ const resolved = resolveStructuredTypeMembers(type);
if (hasProperty(resolved.members, name)) {
- let symbol = resolved.members[name];
+ const symbol = resolved.members[name];
if (symbolIsValue(symbol)) {
return symbol;
}
}
if (resolved === anyFunctionType || resolved.callSignatures.length || resolved.constructSignatures.length) {
- let symbol = getPropertyOfObjectType(globalFunctionType, name);
+ const symbol = getPropertyOfObjectType(globalFunctionType, name);
if (symbol) {
return symbol;
}
@@ -3679,7 +3678,7 @@ namespace ts {
function getSignaturesOfStructuredType(type: Type, kind: SignatureKind): Signature[] {
if (type.flags & TypeFlags.StructuredType) {
- let resolved = resolveStructuredTypeMembers(type);
+ const resolved = resolveStructuredTypeMembers(type);
return kind === SignatureKind.Call ? resolved.callSignatures : resolved.constructSignatures;
}
return emptyArray;
@@ -3694,18 +3693,18 @@ namespace ts {
}
function typeHasConstructSignatures(type: Type): boolean {
- let apparentType = getApparentType(type);
+ const apparentType = getApparentType(type);
if (apparentType.flags & (TypeFlags.ObjectType | TypeFlags.Union)) {
- let resolved = resolveStructuredTypeMembers(type);
+ const resolved = resolveStructuredTypeMembers(type);
return resolved.constructSignatures.length > 0;
}
return false;
}
function typeHasCallOrConstructSignatures(type: Type): boolean {
- let apparentType = getApparentType(type);
+ const apparentType = getApparentType(type);
if (apparentType.flags & TypeFlags.StructuredType) {
- let resolved = resolveStructuredTypeMembers(type);
+ const resolved = resolveStructuredTypeMembers(type);
return resolved.callSignatures.length > 0 || resolved.constructSignatures.length > 0;
}
return false;
@@ -3713,7 +3712,7 @@ namespace ts {
function getIndexTypeOfStructuredType(type: Type, kind: IndexKind): Type {
if (type.flags & TypeFlags.StructuredType) {
- let resolved = resolveStructuredTypeMembers(type);
+ const resolved = resolveStructuredTypeMembers(type);
return kind === IndexKind.String ? resolved.stringIndexType : resolved.numberIndexType;
}
}
@@ -3727,9 +3726,9 @@ namespace ts {
// Return list of type parameters with duplicates removed (duplicate identifier errors are generated in the actual
// type checking functions).
function getTypeParametersFromDeclaration(typeParameterDeclarations: TypeParameterDeclaration[]): TypeParameter[] {
- let result: TypeParameter[] = [];
+ const result: TypeParameter[] = [];
forEach(typeParameterDeclarations, node => {
- let tp = getDeclaredTypeOfTypeParameter(node.symbol);
+ const tp = getDeclaredTypeOfTypeParameter(node.symbol);
if (!contains(result, tp)) {
result.push(tp);
}
@@ -3738,8 +3737,8 @@ namespace ts {
}
function symbolsToArray(symbols: SymbolTable): Symbol[] {
- let result: Symbol[] = [];
- for (let id in symbols) {
+ const result: Symbol[] = [];
+ for (const id in symbols) {
if (!isReservedMemberName(id)) {
result.push(symbols[id]);
}
@@ -3753,9 +3752,9 @@ namespace ts {
}
if (node.initializer) {
- let signatureDeclaration = node.parent;
- let signature = getSignatureFromDeclaration(signatureDeclaration);
- let parameterIndex = signatureDeclaration.parameters.indexOf(node);
+ const signatureDeclaration = node.parent;
+ const signature = getSignatureFromDeclaration(signatureDeclaration);
+ const parameterIndex = signatureDeclaration.parameters.indexOf(node);
Debug.assert(parameterIndex >= 0);
return parameterIndex >= signature.minArgumentCount;
}
@@ -3764,18 +3763,18 @@ namespace ts {
}
function getSignatureFromDeclaration(declaration: SignatureDeclaration): Signature {
- let links = getNodeLinks(declaration);
+ const links = getNodeLinks(declaration);
if (!links.resolvedSignature) {
- let classType = declaration.kind === SyntaxKind.Constructor ?
+ const classType = declaration.kind === SyntaxKind.Constructor ?
getDeclaredTypeOfClassOrInterface(getMergedSymbol((declaration.parent).symbol))
: undefined;
- let typeParameters = classType ? classType.localTypeParameters :
+ const typeParameters = classType ? classType.localTypeParameters :
declaration.typeParameters ? getTypeParametersFromDeclaration(declaration.typeParameters) : undefined;
- let parameters: Symbol[] = [];
+ const parameters: Symbol[] = [];
let hasStringLiterals = false;
let minArgumentCount = -1;
for (let i = 0, n = declaration.parameters.length; i < n; i++) {
- let param = declaration.parameters[i];
+ const param = declaration.parameters[i];
parameters.push(param.symbol);
if (param.type && param.type.kind === SyntaxKind.StringLiteral) {
hasStringLiterals = true;
@@ -3804,7 +3803,7 @@ namespace ts {
else if (declaration.type) {
returnType = getTypeFromTypeNode(declaration.type);
if (declaration.type.kind === SyntaxKind.TypePredicate) {
- let typePredicateNode = declaration.type;
+ const typePredicateNode = declaration.type;
typePredicate = {
parameterName: typePredicateNode.parameterName ? typePredicateNode.parameterName.text : undefined,
parameterIndex: typePredicateNode.parameterName ? getTypePredicateParameterIndex(declaration.parameters, typePredicateNode.parameterName) : undefined,
@@ -3816,7 +3815,7 @@ namespace ts {
// TypeScript 1.0 spec (April 2014):
// If only one accessor includes a type annotation, the other behaves as if it had the same type annotation.
if (declaration.kind === SyntaxKind.GetAccessor && !hasDynamicName(declaration)) {
- let setter = getDeclarationOfKind(declaration.symbol, SyntaxKind.SetAccessor);
+ const setter = getDeclarationOfKind(declaration.symbol, SyntaxKind.SetAccessor);
returnType = getAnnotatedAccessorType(setter);
}
@@ -3833,9 +3832,9 @@ namespace ts {
function getSignaturesOfSymbol(symbol: Symbol): Signature[] {
if (!symbol) return emptyArray;
- let result: Signature[] = [];
+ const result: Signature[] = [];
for (let i = 0, len = symbol.declarations.length; i < len; i++) {
- let node = symbol.declarations[i];
+ const node = symbol.declarations[i];
switch (node.kind) {
case SyntaxKind.FunctionType:
case SyntaxKind.ConstructorType:
@@ -3854,7 +3853,7 @@ namespace ts {
// an implementation node if it has a body and the previous node is of the same kind and immediately
// precedes the implementation node (i.e. has the same parent and ends where the implementation starts).
if (i > 0 && (node).body) {
- let previous = symbol.declarations[i - 1];
+ const previous = symbol.declarations[i - 1];
if (node.parent === previous.parent && node.kind === previous.kind && node.pos === previous.end) {
break;
}
@@ -3883,7 +3882,7 @@ namespace ts {
if (!popTypeResolution()) {
type = anyType;
if (compilerOptions.noImplicitAny) {
- let declaration = signature.declaration;
+ const declaration = signature.declaration;
if (declaration.name) {
error(declaration.name, Diagnostics._0_implicitly_has_return_type_any_because_it_does_not_have_a_return_type_annotation_and_is_referenced_directly_or_indirectly_in_one_of_its_return_expressions, declarationNameToString(declaration.name));
}
@@ -3899,7 +3898,7 @@ namespace ts {
function getRestTypeOfSignature(signature: Signature): Type {
if (signature.hasRestParameter) {
- let type = getTypeOfSymbol(lastOrUndefined(signature.parameters));
+ const type = getTypeOfSymbol(lastOrUndefined(signature.parameters));
if (type.flags & TypeFlags.Reference && (type).target === globalArrayType) {
return (type).typeArguments[0];
}
@@ -3930,8 +3929,8 @@ namespace ts {
// object type literal or interface (using the new keyword). Each way of declaring a constructor
// will result in a different declaration kind.
if (!signature.isolatedSignatureType) {
- let isConstructor = signature.declaration.kind === SyntaxKind.Constructor || signature.declaration.kind === SyntaxKind.ConstructSignature;
- let type = createObjectType(TypeFlags.Anonymous | TypeFlags.FromSignature);
+ const isConstructor = signature.declaration.kind === SyntaxKind.Constructor || signature.declaration.kind === SyntaxKind.ConstructSignature;
+ const type = createObjectType(TypeFlags.Anonymous | TypeFlags.FromSignature);
type.members = emptySymbols;
type.properties = emptyArray;
type.callSignatures = !isConstructor ? [signature] : emptyArray;
@@ -3947,13 +3946,13 @@ namespace ts {
}
function getIndexDeclarationOfSymbol(symbol: Symbol, kind: IndexKind): SignatureDeclaration {
- let syntaxKind = kind === IndexKind.Number ? SyntaxKind.NumberKeyword : SyntaxKind.StringKeyword;
- let indexSymbol = getIndexSymbol(symbol);
+ const syntaxKind = kind === IndexKind.Number ? SyntaxKind.NumberKeyword : SyntaxKind.StringKeyword;
+ const indexSymbol = getIndexSymbol(symbol);
if (indexSymbol) {
- for (let decl of indexSymbol.declarations) {
- let node = decl;
+ for (const decl of indexSymbol.declarations) {
+ const node = decl;
if (node.parameters.length === 1) {
- let parameter = node.parameters[0];
+ const parameter = node.parameters[0];
if (parameter && parameter.type && parameter.type.kind === syntaxKind) {
return node;
}
@@ -3965,7 +3964,7 @@ namespace ts {
}
function getIndexTypeOfSymbol(symbol: Symbol, kind: IndexKind): Type {
- let declaration = getIndexDeclarationOfSymbol(symbol, kind);
+ const declaration = getIndexDeclarationOfSymbol(symbol, kind);
return declaration
? declaration.type ? getTypeFromTypeNode(declaration.type) : anyType
: undefined;
@@ -3974,7 +3973,7 @@ namespace ts {
function getConstraintOfTypeParameter(type: TypeParameter): Type {
if (!type.constraint) {
if (type.target) {
- let targetConstraint = getConstraintOfTypeParameter(type.target);
+ const targetConstraint = getConstraintOfTypeParameter(type.target);
type.constraint = targetConstraint ? instantiateType(targetConstraint, type.mapper) : noConstraintType;
}
else {
@@ -4015,17 +4014,17 @@ namespace ts {
// that care about the presence of such types at arbitrary depth in a containing type.
function getPropagatingFlagsOfTypes(types: Type[]): TypeFlags {
let result: TypeFlags = 0;
- for (let type of types) {
+ for (const type of types) {
result |= type.flags;
}
return result & TypeFlags.PropagatingFlags;
}
function createTypeReference(target: GenericType, typeArguments: Type[]): TypeReference {
- let id = getTypeListId(typeArguments);
+ const id = getTypeListId(typeArguments);
let type = target.instantiations[id];
if (!type) {
- let flags = TypeFlags.Reference | (typeArguments ? getPropagatingFlagsOfTypes(typeArguments) : 0);
+ const flags = TypeFlags.Reference | (typeArguments ? getPropagatingFlagsOfTypes(typeArguments) : 0);
type = target.instantiations[id] = createObjectType(flags, target.symbol);
type.target = target;
type.typeArguments = typeArguments;
@@ -4034,7 +4033,7 @@ namespace ts {
}
function isTypeParameterReferenceIllegalInConstraint(typeReferenceNode: TypeReferenceNode | ExpressionWithTypeArguments, typeParameterSymbol: Symbol): boolean {
- let links = getNodeLinks(typeReferenceNode);
+ const links = getNodeLinks(typeReferenceNode);
if (links.isIllegalTypeReferenceInConstraint !== undefined) {
return links.isIllegalTypeReferenceInConstraint;
}
@@ -4054,9 +4053,9 @@ namespace ts {
let typeParameterSymbol: Symbol;
function check(n: Node): void {
if (n.kind === SyntaxKind.TypeReference && (n).typeName.kind === SyntaxKind.Identifier) {
- let links = getNodeLinks(n);
+ const links = getNodeLinks(n);
if (links.isIllegalTypeReferenceInConstraint === undefined) {
- let symbol = resolveName(typeParameter, ((n).typeName).text, SymbolFlags.Type, /*nameNotFoundMessage*/ undefined, /*nameArg*/ undefined);
+ const symbol = resolveName(typeParameter, ((n).typeName).text, SymbolFlags.Type, /*nameNotFoundMessage*/ undefined, /*nameArg*/ undefined);
if (symbol && (symbol.flags & SymbolFlags.TypeParameter)) {
// TypeScript 1.0 spec (April 2014): 3.4.1
// Type parameters declared in a particular type parameter list
@@ -4084,8 +4083,8 @@ namespace ts {
// Get type from reference to class or interface
function getTypeFromClassOrInterfaceReference(node: TypeReferenceNode | ExpressionWithTypeArguments, symbol: Symbol): Type {
- let type = getDeclaredTypeOfSymbol(symbol);
- let typeParameters = type.localTypeParameters;
+ const type = getDeclaredTypeOfSymbol(symbol);
+ const typeParameters = type.localTypeParameters;
if (typeParameters) {
if (!node.typeArguments || node.typeArguments.length !== typeParameters.length) {
error(node, Diagnostics.Generic_type_0_requires_1_type_argument_s, typeToString(type, /*enclosingDeclaration*/ undefined, TypeFormatFlags.WriteArrayAsGenericType), typeParameters.length);
@@ -4107,16 +4106,16 @@ namespace ts {
// references to the type parameters of the alias. We replace those with the actual type arguments by instantiating the
// declared type. Instantiations are cached using the type identities of the type arguments as the key.
function getTypeFromTypeAliasReference(node: TypeReferenceNode | ExpressionWithTypeArguments, symbol: Symbol): Type {
- let type = getDeclaredTypeOfSymbol(symbol);
- let links = getSymbolLinks(symbol);
- let typeParameters = links.typeParameters;
+ const type = getDeclaredTypeOfSymbol(symbol);
+ const links = getSymbolLinks(symbol);
+ const typeParameters = links.typeParameters;
if (typeParameters) {
if (!node.typeArguments || node.typeArguments.length !== typeParameters.length) {
error(node, Diagnostics.Generic_type_0_requires_1_type_argument_s, symbolToString(symbol), typeParameters.length);
return unknownType;
}
- let typeArguments = map(node.typeArguments, getTypeFromTypeNode);
- let id = getTypeListId(typeArguments);
+ const typeArguments = map(node.typeArguments, getTypeFromTypeNode);
+ const id = getTypeListId(typeArguments);
return links.instantiations[id] || (links.instantiations[id] = instantiateType(type, createTypeMapper(typeParameters, typeArguments)));
}
if (node.typeArguments) {
@@ -4143,14 +4142,14 @@ namespace ts {
}
function getTypeFromTypeReference(node: TypeReferenceNode | ExpressionWithTypeArguments): Type {
- let links = getNodeLinks(node);
+ const links = getNodeLinks(node);
if (!links.resolvedType) {
// We only support expressions that are simple qualified names. For other expressions this produces undefined.
- let typeNameOrExpression = node.kind === SyntaxKind.TypeReference ? (node).typeName :
+ const typeNameOrExpression = node.kind === SyntaxKind.TypeReference ? (node).typeName :
isSupportedExpressionWithTypeArguments(node) ? (node).expression :
undefined;
- let symbol = typeNameOrExpression && resolveEntityName(typeNameOrExpression, SymbolFlags.Type) || unknownSymbol;
- let type = symbol === unknownSymbol ? unknownType :
+ const symbol = typeNameOrExpression && resolveEntityName(typeNameOrExpression, SymbolFlags.Type) || unknownSymbol;
+ const type = symbol === unknownSymbol ? unknownType :
symbol.flags & (SymbolFlags.Class | SymbolFlags.Interface) ? getTypeFromClassOrInterfaceReference(node, symbol) :
symbol.flags & SymbolFlags.TypeAlias ? getTypeFromTypeAliasReference(node, symbol) :
getTypeFromNonGenericTypeReference(node, symbol);
@@ -4163,7 +4162,7 @@ namespace ts {
}
function getTypeFromTypeQueryNode(node: TypeQueryNode): Type {
- let links = getNodeLinks(node);
+ const links = getNodeLinks(node);
if (!links.resolvedType) {
// TypeScript 1.0 spec (April 2014): 3.6.3
// The expression is processed as an identifier expression (section 4.3)
@@ -4177,8 +4176,8 @@ namespace ts {
function getTypeOfGlobalSymbol(symbol: Symbol, arity: number): ObjectType {
function getTypeDeclaration(symbol: Symbol): Declaration {
- let declarations = symbol.declarations;
- for (let declaration of declarations) {
+ const declarations = symbol.declarations;
+ for (const declaration of declarations) {
switch (declaration.kind) {
case SyntaxKind.ClassDeclaration:
case SyntaxKind.InterfaceDeclaration:
@@ -4191,7 +4190,7 @@ namespace ts {
if (!symbol) {
return arity ? emptyGenericType : emptyObjectType;
}
- let type = getDeclaredTypeOfSymbol(symbol);
+ const type = getDeclaredTypeOfSymbol(symbol);
if (!(type.flags & TypeFlags.ObjectType)) {
error(getTypeDeclaration(symbol), Diagnostics.Global_type_0_must_be_a_class_or_interface_type, symbol.name);
return arity ? emptyGenericType : emptyObjectType;
@@ -4228,8 +4227,8 @@ namespace ts {
* getExportedTypeFromNamespace('JSX', 'Element') returns the JSX.Element type
*/
function getExportedTypeFromNamespace(namespace: string, name: string): Type {
- let namespaceSymbol = getGlobalSymbol(namespace, SymbolFlags.Namespace, /*diagnosticMessage*/ undefined);
- let typeSymbol = namespaceSymbol && getSymbol(namespaceSymbol.exports, name, SymbolFlags.Type);
+ const namespaceSymbol = getGlobalSymbol(namespace, SymbolFlags.Namespace, /*diagnosticMessage*/ undefined);
+ const typeSymbol = namespaceSymbol && getSymbol(namespaceSymbol.exports, name, SymbolFlags.Type);
return typeSymbol && getDeclaredTypeOfSymbol(typeSymbol);
}
@@ -4241,7 +4240,7 @@ namespace ts {
* Creates a TypeReference for a generic `TypedPropertyDescriptor`.
*/
function createTypedPropertyDescriptorType(propertyType: Type): Type {
- let globalTypedPropertyDescriptorType = getGlobalTypedPropertyDescriptorType();
+ const globalTypedPropertyDescriptorType = getGlobalTypedPropertyDescriptorType();
return globalTypedPropertyDescriptorType !== emptyGenericType
? createTypeReference(globalTypedPropertyDescriptorType, [propertyType])
: emptyObjectType;
@@ -4267,7 +4266,7 @@ namespace ts {
}
function getTypeFromArrayTypeNode(node: ArrayTypeNode): Type {
- let links = getNodeLinks(node);
+ const links = getNodeLinks(node);
if (!links.resolvedType) {
links.resolvedType = createArrayType(getTypeFromTypeNode(node.elementType));
}
@@ -4275,18 +4274,18 @@ namespace ts {
}
function createTupleType(elementTypes: Type[]) {
- let id = getTypeListId(elementTypes);
+ const id = getTypeListId(elementTypes);
return tupleTypes[id] || (tupleTypes[id] = createNewTupleType(elementTypes));
}
function createNewTupleType(elementTypes: Type[]) {
- let type = createObjectType(TypeFlags.Tuple | getPropagatingFlagsOfTypes(elementTypes));
+ const type = createObjectType(TypeFlags.Tuple | getPropagatingFlagsOfTypes(elementTypes));
type.elementTypes = elementTypes;
return type;
}
function getTypeFromTupleTypeNode(node: TupleTypeNode): Type {
- let links = getNodeLinks(node);
+ const links = getNodeLinks(node);
if (!links.resolvedType) {
links.resolvedType = createTupleType(map(node.elementTypes, getTypeFromTypeNode));
}
@@ -4305,7 +4304,7 @@ namespace ts {
// Add the given types to the given type set. Order is preserved, duplicates are removed,
// and nested types of the given kind are flattened into the set.
function addTypesToSet(typeSet: Type[], types: Type[], typeSetKind: TypeFlags) {
- for (let type of types) {
+ for (const type of types) {
addTypeToSet(typeSet, type, typeSetKind);
}
}
@@ -4330,7 +4329,7 @@ namespace ts {
}
function containsTypeAny(types: Type[]): boolean {
- for (let type of types) {
+ for (const type of types) {
if (isTypeAny(type)) {
return true;
}
@@ -4359,7 +4358,7 @@ namespace ts {
if (types.length === 0) {
return emptyObjectType;
}
- let typeSet: Type[] = [];
+ const typeSet: Type[] = [];
addTypesToSet(typeSet, types, TypeFlags.Union);
if (containsTypeAny(typeSet)) {
return anyType;
@@ -4374,7 +4373,7 @@ namespace ts {
if (typeSet.length === 1) {
return typeSet[0];
}
- let id = getTypeListId(typeSet);
+ const id = getTypeListId(typeSet);
let type = unionTypes[id];
if (!type) {
type = unionTypes[id] = createObjectType(TypeFlags.Union | getPropagatingFlagsOfTypes(typeSet));
@@ -4384,7 +4383,7 @@ namespace ts {
}
function getTypeFromUnionTypeNode(node: UnionTypeNode): Type {
- let links = getNodeLinks(node);
+ const links = getNodeLinks(node);
if (!links.resolvedType) {
links.resolvedType = getUnionType(map(node.types, getTypeFromTypeNode), /*noSubtypeReduction*/ true);
}
@@ -4400,7 +4399,7 @@ namespace ts {
if (types.length === 0) {
return emptyObjectType;
}
- let typeSet: Type[] = [];
+ const typeSet: Type[] = [];
addTypesToSet(typeSet, types, TypeFlags.Intersection);
if (containsTypeAny(typeSet)) {
return anyType;
@@ -4408,7 +4407,7 @@ namespace ts {
if (typeSet.length === 1) {
return typeSet[0];
}
- let id = getTypeListId(typeSet);
+ const id = getTypeListId(typeSet);
let type = intersectionTypes[id];
if (!type) {
type = intersectionTypes[id] = createObjectType(TypeFlags.Intersection | getPropagatingFlagsOfTypes(typeSet));
@@ -4418,7 +4417,7 @@ namespace ts {
}
function getTypeFromIntersectionTypeNode(node: IntersectionTypeNode): Type {
- let links = getNodeLinks(node);
+ const links = getNodeLinks(node);
if (!links.resolvedType) {
links.resolvedType = getIntersectionType(map(node.types, getTypeFromTypeNode));
}
@@ -4426,7 +4425,7 @@ namespace ts {
}
function getTypeFromTypeLiteralOrFunctionOrConstructorTypeNode(node: Node): Type {
- let links = getNodeLinks(node);
+ const links = getNodeLinks(node);
if (!links.resolvedType) {
// Deferred resolution of members is handled by resolveObjectTypeMembers
links.resolvedType = createObjectType(TypeFlags.Anonymous, node.symbol);
@@ -4439,13 +4438,13 @@ namespace ts {
return stringLiteralTypes[node.text];
}
- let type = stringLiteralTypes[node.text] = createType(TypeFlags.StringLiteral);
+ const type = stringLiteralTypes[node.text] = createType(TypeFlags.StringLiteral);
type.text = getTextOfNode(node);
return type;
}
function getTypeFromStringLiteral(node: StringLiteral): Type {
- let links = getNodeLinks(node);
+ const links = getNodeLinks(node);
if (!links.resolvedType) {
links.resolvedType = getStringLiteralType(node);
}
@@ -4453,8 +4452,8 @@ namespace ts {
}
function getThisType(node: TypeNode): Type {
- let container = getThisContainer(node, /*includeArrowFunctions*/ false);
- let parent = container && container.parent;
+ const container = getThisContainer(node, /*includeArrowFunctions*/ false);
+ const parent = container && container.parent;
if (parent && (isClassLike(parent) || parent.kind === SyntaxKind.InterfaceDeclaration)) {
if (!(container.flags & NodeFlags.Static) &&
(container.kind !== SyntaxKind.Constructor || isNodeDescendentOf(node, (container).body))) {
@@ -4466,7 +4465,7 @@ namespace ts {
}
function getTypeFromThisTypeNode(node: TypeNode): Type {
- let links = getNodeLinks(node);
+ const links = getNodeLinks(node);
if (!links.resolvedType) {
links.resolvedType = getThisType(node);
}
@@ -4517,7 +4516,7 @@ namespace ts {
// Callers should first ensure this by calling isTypeNode
case SyntaxKind.Identifier:
case SyntaxKind.QualifiedName:
- let symbol = getSymbolAtLocation(node);
+ const symbol = getSymbolAtLocation(node);
return symbol && getDeclaredTypeOfSymbol(symbol);
default:
return unknownType;
@@ -4526,8 +4525,8 @@ namespace ts {
function instantiateList(items: T[], mapper: TypeMapper, instantiator: (item: T, mapper: TypeMapper) => T): T[] {
if (items && items.length) {
- let result: T[] = [];
- for (let v of items) {
+ const result: T[] = [];
+ for (const v of items) {
result.push(instantiator(v, mapper));
}
return result;
@@ -4572,7 +4571,7 @@ namespace ts {
case 2: return createBinaryTypeEraser(sources[0], sources[1]);
}
return t => {
- for (let source of sources) {
+ for (const source of sources) {
if (t === source) {
return anyType;
}
@@ -4582,7 +4581,7 @@ namespace ts {
}
function createInferenceMapper(context: InferenceContext): TypeMapper {
- let mapper: TypeMapper = t => {
+ const mapper: TypeMapper = t => {
for (let i = 0; i < context.typeParameters.length; i++) {
if (t === context.typeParameters[i]) {
context.inferences[i].isFixed = true;
@@ -4605,7 +4604,7 @@ namespace ts {
}
function instantiateTypeParameter(typeParameter: TypeParameter, mapper: TypeMapper): TypeParameter {
- let result = createType(TypeFlags.TypeParameter);
+ const result = createType(TypeFlags.TypeParameter);
result.symbol = typeParameter.symbol;
if (typeParameter.constraint) {
result.constraint = instantiateType(typeParameter.constraint, mapper);
@@ -4631,7 +4630,7 @@ namespace ts {
type: instantiateType(signature.typePredicate.type, mapper)
};
}
- let result = createSignature(signature.declaration, freshTypeParameters,
+ const result = createSignature(signature.declaration, freshTypeParameters,
instantiateList(signature.parameters, mapper, instantiateSymbol),
instantiateType(signature.resolvedReturnType, mapper),
freshTypePredicate,
@@ -4643,7 +4642,7 @@ namespace ts {
function instantiateSymbol(symbol: Symbol, mapper: TypeMapper): Symbol {
if (symbol.flags & SymbolFlags.Instantiated) {
- let links = getSymbolLinks(symbol);
+ const links = getSymbolLinks(symbol);
// If symbol being instantiated is itself a instantiation, fetch the original target and combine the
// type mappers. This ensures that original type identities are properly preserved and that aliases
// always reference a non-aliases.
@@ -4653,7 +4652,7 @@ namespace ts {
// Keep the flags from the symbol we're instantiating. Mark that is instantiated, and
// also transient so that we can just store data on it directly.
- let result = createSymbol(SymbolFlags.Instantiated | SymbolFlags.Transient | symbol.flags, symbol.name);
+ const result = createSymbol(SymbolFlags.Instantiated | SymbolFlags.Transient | symbol.flags, symbol.name);
result.declarations = symbol.declarations;
result.parent = symbol.parent;
result.target = symbol;
@@ -4667,7 +4666,7 @@ namespace ts {
function instantiateAnonymousType(type: AnonymousType, mapper: TypeMapper): ObjectType {
if (mapper.instantiations) {
- let cachedType = mapper.instantiations[type.id];
+ const cachedType = mapper.instantiations[type.id];
if (cachedType) {
return cachedType;
}
@@ -4676,7 +4675,7 @@ namespace ts {
mapper.instantiations = [];
}
// Mark the anonymous type as instantiated such that our infinite instantiation detection logic can recognize it
- let result = createObjectType(TypeFlags.Anonymous | TypeFlags.Instantiated, type.symbol);
+ const result = createObjectType(TypeFlags.Anonymous | TypeFlags.Instantiated, type.symbol);
result.target = type;
result.mapper = mapper;
mapper.instantiations[type.id] = result;
@@ -4744,9 +4743,9 @@ namespace ts {
function getTypeWithoutSignatures(type: Type): Type {
if (type.flags & TypeFlags.ObjectType) {
- let resolved = resolveStructuredTypeMembers(type);
+ const resolved = resolveStructuredTypeMembers(type);
if (resolved.constructSignatures.length) {
- let result = createObjectType(TypeFlags.Anonymous, type.symbol);
+ const result = createObjectType(TypeFlags.Anonymous, type.symbol);
result.members = resolved.members;
result.properties = resolved.properties;
result.callSignatures = emptyArray;
@@ -4784,8 +4783,8 @@ namespace ts {
}
function isSignatureAssignableTo(source: Signature, target: Signature): boolean {
- let sourceType = getOrCreateTypeFromSignature(source);
- let targetType = getOrCreateTypeFromSignature(target);
+ const sourceType = getOrCreateTypeFromSignature(source);
+ const targetType = getOrCreateTypeFromSignature(target);
return checkTypeRelatedTo(sourceType, targetType, assignableRelation, /*errorNode*/ undefined);
}
@@ -4818,7 +4817,7 @@ namespace ts {
Debug.assert(relation !== identityRelation || !errorNode, "no error reporting in identity checking");
- let result = isRelatedTo(source, target, errorNode !== undefined, headMessage);
+ const result = isRelatedTo(source, target, errorNode !== undefined, headMessage);
if (overflow) {
error(errorNode, Diagnostics.Excessive_stack_depth_comparing_types_0_and_1, typeToString(source), typeToString(target));
}
@@ -4892,7 +4891,7 @@ namespace ts {
}
}
- let saveErrorInfo = errorInfo;
+ const saveErrorInfo = errorInfo;
// Note that the "each" checks must precede the "some" checks to produce the correct results
if (source.flags & TypeFlags.Union) {
@@ -4928,7 +4927,7 @@ namespace ts {
constraint = emptyObjectType;
}
// Report constraint errors only if the constraint is not the empty object type
- let reportConstraintErrors = reportErrors && constraint !== emptyObjectType;
+ const reportConstraintErrors = reportErrors && constraint !== emptyObjectType;
if (result = isRelatedTo(constraint, target, reportConstraintErrors)) {
errorInfo = saveErrorInfo;
return result;
@@ -4943,13 +4942,13 @@ namespace ts {
}
// Even if relationship doesn't hold for unions, intersections, or generic type references,
// it may hold in a structural comparison.
- let apparentType = getApparentType(source);
+ const apparentType = getApparentType(source);
// In a check of the form X = A & B, we will have previously checked if A relates to X or B relates
// to X. Failing both of those we want to check if the aggregation of A and B's members structurally
// relates to X. Thus, we include intersection types on the source side here.
if (apparentType.flags & (TypeFlags.ObjectType | TypeFlags.Intersection) && target.flags & TypeFlags.ObjectType) {
// Report structural errors only if we haven't reported any errors yet
- let reportStructuralErrors = reportErrors && errorInfo === saveErrorInfo;
+ const reportStructuralErrors = reportErrors && errorInfo === saveErrorInfo;
if (result = objectTypeRelatedTo(apparentType, source, target, reportStructuralErrors)) {
errorInfo = saveErrorInfo;
return result;
@@ -5001,7 +5000,7 @@ namespace ts {
}
}
else if (type.flags & TypeFlags.UnionOrIntersection) {
- for (let t of (type).types) {
+ for (const t of (type).types) {
if (isKnownProperty(t, name)) {
return true;
}
@@ -5012,7 +5011,7 @@ namespace ts {
function hasExcessProperties(source: FreshObjectLiteralType, target: Type, reportErrors: boolean): boolean {
if (someConstituentTypeHasKind(target, TypeFlags.ObjectType)) {
- for (let prop of getPropertiesOfObjectType(source)) {
+ for (const prop of getPropertiesOfObjectType(source)) {
if (!isKnownProperty(target, prop.name)) {
if (reportErrors) {
// We know *exactly* where things went wrong when comparing the types.
@@ -5031,9 +5030,9 @@ namespace ts {
function eachTypeRelatedToSomeType(source: UnionOrIntersectionType, target: UnionOrIntersectionType): Ternary {
let result = Ternary.True;
- let sourceTypes = source.types;
- for (let sourceType of sourceTypes) {
- let related = typeRelatedToSomeType(sourceType, target, false);
+ const sourceTypes = source.types;
+ for (const sourceType of sourceTypes) {
+ const related = typeRelatedToSomeType(sourceType, target, false);
if (!related) {
return Ternary.False;
}
@@ -5043,9 +5042,9 @@ namespace ts {
}
function typeRelatedToSomeType(source: Type, target: UnionOrIntersectionType, reportErrors: boolean): Ternary {
- let targetTypes = target.types;
+ const targetTypes = target.types;
for (let i = 0, len = targetTypes.length; i < len; i++) {
- let related = isRelatedTo(source, targetTypes[i], reportErrors && i === len - 1);
+ const related = isRelatedTo(source, targetTypes[i], reportErrors && i === len - 1);
if (related) {
return related;
}
@@ -5055,9 +5054,9 @@ namespace ts {
function typeRelatedToEachType(source: Type, target: UnionOrIntersectionType, reportErrors: boolean): Ternary {
let result = Ternary.True;
- let targetTypes = target.types;
- for (let targetType of targetTypes) {
- let related = isRelatedTo(source, targetType, reportErrors);
+ const targetTypes = target.types;
+ for (const targetType of targetTypes) {
+ const related = isRelatedTo(source, targetType, reportErrors);
if (!related) {
return Ternary.False;
}
@@ -5067,9 +5066,9 @@ namespace ts {
}
function someTypeRelatedToType(source: UnionOrIntersectionType, target: Type, reportErrors: boolean): Ternary {
- let sourceTypes = source.types;
+ const sourceTypes = source.types;
for (let i = 0, len = sourceTypes.length; i < len; i++) {
- let related = isRelatedTo(sourceTypes[i], target, reportErrors && i === len - 1);
+ const related = isRelatedTo(sourceTypes[i], target, reportErrors && i === len - 1);
if (related) {
return related;
}
@@ -5079,9 +5078,9 @@ namespace ts {
function eachTypeRelatedToType(source: UnionOrIntersectionType, target: Type, reportErrors: boolean): Ternary {
let result = Ternary.True;
- let sourceTypes = source.types;
- for (let sourceType of sourceTypes) {
- let related = isRelatedTo(sourceType, target, reportErrors);
+ const sourceTypes = source.types;
+ for (const sourceType of sourceTypes) {
+ const related = isRelatedTo(sourceType, target, reportErrors);
if (!related) {
return Ternary.False;
}
@@ -5091,14 +5090,14 @@ namespace ts {
}
function typeArgumentsRelatedTo(source: TypeReference, target: TypeReference, reportErrors: boolean): Ternary {
- let sources = source.typeArguments || emptyArray;
- let targets = target.typeArguments || emptyArray;
+ const sources = source.typeArguments || emptyArray;
+ const targets = target.typeArguments || emptyArray;
if (sources.length !== targets.length && relation === identityRelation) {
return Ternary.False;
}
let result = Ternary.True;
for (let i = 0; i < targets.length; i++) {
- let related = isRelatedTo(sources[i], targets[i], reportErrors);
+ const related = isRelatedTo(sources[i], targets[i], reportErrors);
if (!related) {
return Ternary.False;
}
@@ -5130,8 +5129,8 @@ namespace ts {
if (overflow) {
return Ternary.False;
}
- let id = relation !== identityRelation || apparentSource.id < target.id ? apparentSource.id + "," + target.id : target.id + "," + apparentSource.id;
- let related = relation[id];
+ const id = relation !== identityRelation || apparentSource.id < target.id ? apparentSource.id + "," + target.id : target.id + "," + apparentSource.id;
+ const related = relation[id];
if (related !== undefined) {
// If we computed this relation already and it was failed and reported, or if we're not being asked to elaborate
// errors, we can use the cached value. Otherwise, recompute the relation
@@ -5162,7 +5161,7 @@ namespace ts {
maybeStack[depth] = {};
maybeStack[depth][id] = RelationComparisonResult.Succeeded;
depth++;
- let saveExpandingFlags = expandingFlags;
+ const saveExpandingFlags = expandingFlags;
if (!(expandingFlags & 1) && isDeeplyNestedGeneric(apparentSource, sourceStack, depth)) expandingFlags |= 1;
if (!(expandingFlags & 2) && isDeeplyNestedGeneric(target, targetStack, depth)) expandingFlags |= 2;
let result: Ternary;
@@ -5187,9 +5186,9 @@ namespace ts {
expandingFlags = saveExpandingFlags;
depth--;
if (result) {
- let maybeCache = maybeStack[depth];
+ const maybeCache = maybeStack[depth];
// If result is definitely true, copy assumptions to global cache, else copy to next level up
- let destinationCache = (result === Ternary.True || depth === 0) ? relation : maybeStack[depth - 1];
+ const destinationCache = (result === Ternary.True || depth === 0) ? relation : maybeStack[depth - 1];
copyMap(maybeCache, destinationCache);
}
else {
@@ -5205,10 +5204,10 @@ namespace ts {
return propertiesIdenticalTo(source, target);
}
let result = Ternary.True;
- let properties = getPropertiesOfObjectType(target);
- let requireOptionalProperties = relation === subtypeRelation && !(source.flags & TypeFlags.ObjectLiteral);
- for (let targetProp of properties) {
- let sourceProp = getPropertyOfType(source, targetProp.name);
+ const properties = getPropertiesOfObjectType(target);
+ const requireOptionalProperties = relation === subtypeRelation && !(source.flags & TypeFlags.ObjectLiteral);
+ for (const targetProp of properties) {
+ const sourceProp = getPropertyOfType(source, targetProp.name);
if (sourceProp !== targetProp) {
if (!sourceProp) {
@@ -5220,8 +5219,8 @@ namespace ts {
}
}
else if (!(targetProp.flags & SymbolFlags.Prototype)) {
- let sourcePropFlags = getDeclarationFlagsFromSymbol(sourceProp);
- let targetPropFlags = getDeclarationFlagsFromSymbol(targetProp);
+ const sourcePropFlags = getDeclarationFlagsFromSymbol(sourceProp);
+ const targetPropFlags = getDeclarationFlagsFromSymbol(targetProp);
if (sourcePropFlags & NodeFlags.Private || targetPropFlags & NodeFlags.Private) {
if (sourceProp.valueDeclaration !== targetProp.valueDeclaration) {
if (reportErrors) {
@@ -5238,9 +5237,9 @@ namespace ts {
}
}
else if (targetPropFlags & NodeFlags.Protected) {
- let sourceDeclaredInClass = sourceProp.parent && sourceProp.parent.flags & SymbolFlags.Class;
- let sourceClass = sourceDeclaredInClass ? getDeclaredTypeOfSymbol(sourceProp.parent) : undefined;
- let targetClass = getDeclaredTypeOfSymbol(targetProp.parent);
+ const sourceDeclaredInClass = sourceProp.parent && sourceProp.parent.flags & SymbolFlags.Class;
+ const sourceClass = sourceDeclaredInClass ? getDeclaredTypeOfSymbol(sourceProp.parent) : undefined;
+ const targetClass = getDeclaredTypeOfSymbol(targetProp.parent);
if (!sourceClass || !hasBaseType(sourceClass, targetClass)) {
if (reportErrors) {
reportError(Diagnostics.Property_0_is_protected_but_type_1_is_not_a_class_derived_from_2,
@@ -5256,7 +5255,7 @@ namespace ts {
}
return Ternary.False;
}
- let related = isRelatedTo(getTypeOfSymbol(sourceProp), getTypeOfSymbol(targetProp), reportErrors);
+ const related = isRelatedTo(getTypeOfSymbol(sourceProp), getTypeOfSymbol(targetProp), reportErrors);
if (!related) {
if (reportErrors) {
reportError(Diagnostics.Types_of_property_0_are_incompatible, symbolToString(targetProp));
@@ -5288,18 +5287,18 @@ namespace ts {
if (!(source.flags & TypeFlags.ObjectType && target.flags & TypeFlags.ObjectType)) {
return Ternary.False;
}
- let sourceProperties = getPropertiesOfObjectType(source);
- let targetProperties = getPropertiesOfObjectType(target);
+ const sourceProperties = getPropertiesOfObjectType(source);
+ const targetProperties = getPropertiesOfObjectType(target);
if (sourceProperties.length !== targetProperties.length) {
return Ternary.False;
}
let result = Ternary.True;
- for (let sourceProp of sourceProperties) {
- let targetProp = getPropertyOfObjectType(target, sourceProp.name);
+ for (const sourceProp of sourceProperties) {
+ const targetProp = getPropertyOfObjectType(target, sourceProp.name);
if (!targetProp) {
return Ternary.False;
}
- let related = compareProperties(sourceProp, targetProp, isRelatedTo);
+ const related = compareProperties(sourceProp, targetProp, isRelatedTo);
if (!related) {
return Ternary.False;
}
@@ -5315,10 +5314,10 @@ namespace ts {
if (target === anyFunctionType || source === anyFunctionType) {
return Ternary.True;
}
- let sourceSignatures = getSignaturesOfType(source, kind);
- let targetSignatures = getSignaturesOfType(target, kind);
+ const sourceSignatures = getSignaturesOfType(source, kind);
+ const targetSignatures = getSignaturesOfType(target, kind);
let result = Ternary.True;
- let saveErrorInfo = errorInfo;
+ const saveErrorInfo = errorInfo;
@@ -5332,8 +5331,8 @@ namespace ts {
// sourceSig and targetSig are (possibly) undefined.
//
// Note that in an extends-clause, targetSignatures is stripped, so the check never proceeds.
- let sourceSig = sourceSignatures[0];
- let targetSig = targetSignatures[0];
+ const sourceSig = sourceSignatures[0];
+ const targetSig = targetSignatures[0];
result &= abstractSignatureRelatedTo(source, sourceSig, target, targetSig);
if (result !== Ternary.True) {
@@ -5341,13 +5340,13 @@ namespace ts {
}
}
- outer: for (let t of targetSignatures) {
+ outer: for (const t of targetSignatures) {
if (!t.hasStringLiterals || target.flags & TypeFlags.FromSignature) {
let localErrors = reportErrors;
- let checkedAbstractAssignability = false;
- for (let s of sourceSignatures) {
+ const checkedAbstractAssignability = false;
+ for (const s of sourceSignatures) {
if (!s.hasStringLiterals || source.flags & TypeFlags.FromSignature) {
- let related = signatureRelatedTo(s, t, localErrors);
+ const related = signatureRelatedTo(s, t, localErrors);
if (related) {
result &= related;
errorInfo = saveErrorInfo;
@@ -5365,8 +5364,8 @@ namespace ts {
function abstractSignatureRelatedTo(source: Type, sourceSig: Signature, target: Type, targetSig: Signature) {
if (sourceSig && targetSig) {
- let sourceDecl = source.symbol && getClassLikeDeclarationOfSymbol(source.symbol);
- let targetDecl = target.symbol && getClassLikeDeclarationOfSymbol(target.symbol);
+ const sourceDecl = source.symbol && getClassLikeDeclarationOfSymbol(source.symbol);
+ const targetDecl = target.symbol && getClassLikeDeclarationOfSymbol(target.symbol);
if (!sourceDecl) {
// If the source object isn't itself a class declaration, it can be freely assigned, regardless
@@ -5374,16 +5373,16 @@ namespace ts {
return Ternary.True;
}
- let sourceErasedSignature = getErasedSignature(sourceSig);
- let targetErasedSignature = getErasedSignature(targetSig);
+ const sourceErasedSignature = getErasedSignature(sourceSig);
+ const targetErasedSignature = getErasedSignature(targetSig);
- let sourceReturnType = sourceErasedSignature && getReturnTypeOfSignature(sourceErasedSignature);
- let targetReturnType = targetErasedSignature && getReturnTypeOfSignature(targetErasedSignature);
+ const sourceReturnType = sourceErasedSignature && getReturnTypeOfSignature(sourceErasedSignature);
+ const targetReturnType = targetErasedSignature && getReturnTypeOfSignature(targetErasedSignature);
- let sourceReturnDecl = sourceReturnType && sourceReturnType.symbol && getClassLikeDeclarationOfSymbol(sourceReturnType.symbol);
- let targetReturnDecl = targetReturnType && targetReturnType.symbol && getClassLikeDeclarationOfSymbol(targetReturnType.symbol);
- let sourceIsAbstract = sourceReturnDecl && sourceReturnDecl.flags & NodeFlags.Abstract;
- let targetIsAbstract = targetReturnDecl && targetReturnDecl.flags & NodeFlags.Abstract;
+ const sourceReturnDecl = sourceReturnType && sourceReturnType.symbol && getClassLikeDeclarationOfSymbol(sourceReturnType.symbol);
+ const targetReturnDecl = targetReturnType && targetReturnType.symbol && getClassLikeDeclarationOfSymbol(targetReturnType.symbol);
+ const sourceIsAbstract = sourceReturnDecl && sourceReturnDecl.flags & NodeFlags.Abstract;
+ const targetIsAbstract = targetReturnDecl && targetReturnDecl.flags & NodeFlags.Abstract;
if (sourceIsAbstract && !(targetIsAbstract && targetDecl)) {
// if target isn't a class-declaration type, then it can be new'd, so we forbid the assignment.
@@ -5429,9 +5428,9 @@ namespace ts {
target = getErasedSignature(target);
let result = Ternary.True;
for (let i = 0; i < checkCount; i++) {
- let s = i < sourceMax ? getTypeOfSymbol(source.parameters[i]) : getRestTypeOfSignature(source);
- let t = i < targetMax ? getTypeOfSymbol(target.parameters[i]) : getRestTypeOfSignature(target);
- let saveErrorInfo = errorInfo;
+ const s = i < sourceMax ? getTypeOfSymbol(source.parameters[i]) : getRestTypeOfSignature(source);
+ const t = i < targetMax ? getTypeOfSymbol(target.parameters[i]) : getRestTypeOfSignature(target);
+ const saveErrorInfo = errorInfo;
let related = isRelatedTo(s, t, reportErrors);
if (!related) {
related = isRelatedTo(t, s, false);
@@ -5449,16 +5448,16 @@ namespace ts {
}
if (source.typePredicate && target.typePredicate) {
- let hasDifferentParameterIndex = source.typePredicate.parameterIndex !== target.typePredicate.parameterIndex;
+ const hasDifferentParameterIndex = source.typePredicate.parameterIndex !== target.typePredicate.parameterIndex;
let hasDifferentTypes: boolean;
if (hasDifferentParameterIndex ||
(hasDifferentTypes = !isTypeIdenticalTo(source.typePredicate.type, target.typePredicate.type))) {
if (reportErrors) {
- let sourceParamText = source.typePredicate.parameterName;
- let targetParamText = target.typePredicate.parameterName;
- let sourceTypeText = typeToString(source.typePredicate.type);
- let targetTypeText = typeToString(target.typePredicate.type);
+ const sourceParamText = source.typePredicate.parameterName;
+ const targetParamText = target.typePredicate.parameterName;
+ const sourceTypeText = typeToString(source.typePredicate.type);
+ const targetTypeText = typeToString(target.typePredicate.type);
if (hasDifferentParameterIndex) {
reportError(Diagnostics.Parameter_0_is_not_in_the_same_position_as_parameter_1,
@@ -5485,22 +5484,22 @@ namespace ts {
return Ternary.False;
}
- let targetReturnType = getReturnTypeOfSignature(target);
+ const targetReturnType = getReturnTypeOfSignature(target);
if (targetReturnType === voidType) return result;
- let sourceReturnType = getReturnTypeOfSignature(source);
+ const sourceReturnType = getReturnTypeOfSignature(source);
return result & isRelatedTo(sourceReturnType, targetReturnType, reportErrors);
}
function signaturesIdenticalTo(source: Type, target: Type, kind: SignatureKind): Ternary {
- let sourceSignatures = getSignaturesOfType(source, kind);
- let targetSignatures = getSignaturesOfType(target, kind);
+ const sourceSignatures = getSignaturesOfType(source, kind);
+ const targetSignatures = getSignaturesOfType(target, kind);
if (sourceSignatures.length !== targetSignatures.length) {
return Ternary.False;
}
let result = Ternary.True;
for (let i = 0, len = sourceSignatures.length; i < len; ++i) {
- let related = compareSignatures(sourceSignatures[i], targetSignatures[i], /*partialMatch*/ false, /*ignoreReturnTypes*/ false, isRelatedTo);
+ const related = compareSignatures(sourceSignatures[i], targetSignatures[i], /*partialMatch*/ false, /*ignoreReturnTypes*/ false, isRelatedTo);
if (!related) {
return Ternary.False;
}
@@ -5513,21 +5512,21 @@ namespace ts {
if (relation === identityRelation) {
return indexTypesIdenticalTo(IndexKind.String, source, target);
}
- let targetType = getIndexTypeOfType(target, IndexKind.String);
+ const targetType = getIndexTypeOfType(target, IndexKind.String);
if (targetType) {
if ((targetType.flags & TypeFlags.Any) && !(originalSource.flags & TypeFlags.Primitive)) {
// non-primitive assignment to any is always allowed, eg
// `var x: { [index: string]: any } = { property: 12 };`
return Ternary.True;
}
- let sourceType = getIndexTypeOfType(source, IndexKind.String);
+ const sourceType = getIndexTypeOfType(source, IndexKind.String);
if (!sourceType) {
if (reportErrors) {
reportError(Diagnostics.Index_signature_is_missing_in_type_0, typeToString(source));
}
return Ternary.False;
}
- let related = isRelatedTo(sourceType, targetType, reportErrors);
+ const related = isRelatedTo(sourceType, targetType, reportErrors);
if (!related) {
if (reportErrors) {
reportError(Diagnostics.Index_signatures_are_incompatible);
@@ -5543,15 +5542,15 @@ namespace ts {
if (relation === identityRelation) {
return indexTypesIdenticalTo(IndexKind.Number, source, target);
}
- let targetType = getIndexTypeOfType(target, IndexKind.Number);
+ const targetType = getIndexTypeOfType(target, IndexKind.Number);
if (targetType) {
if ((targetType.flags & TypeFlags.Any) && !(originalSource.flags & TypeFlags.Primitive)) {
// non-primitive assignment to any is always allowed, eg
// `var x: { [index: number]: any } = { property: 12 };`
return Ternary.True;
}
- let sourceStringType = getIndexTypeOfType(source, IndexKind.String);
- let sourceNumberType = getIndexTypeOfType(source, IndexKind.Number);
+ const sourceStringType = getIndexTypeOfType(source, IndexKind.String);
+ const sourceNumberType = getIndexTypeOfType(source, IndexKind.Number);
if (!(sourceStringType || sourceNumberType)) {
if (reportErrors) {
reportError(Diagnostics.Index_signature_is_missing_in_type_0, typeToString(source));
@@ -5578,8 +5577,8 @@ namespace ts {
}
function indexTypesIdenticalTo(indexKind: IndexKind, source: Type, target: Type): Ternary {
- let targetType = getIndexTypeOfType(target, indexKind);
- let sourceType = getIndexTypeOfType(source, indexKind);
+ const targetType = getIndexTypeOfType(target, indexKind);
+ const sourceType = getIndexTypeOfType(source, indexKind);
if (!sourceType && !targetType) {
return Ternary.True;
}
@@ -5598,10 +5597,10 @@ namespace ts {
function isDeeplyNestedGeneric(type: Type, stack: Type[], depth: number): boolean {
// We track type references (created by createTypeReference) and instantiated types (created by instantiateType)
if (type.flags & (TypeFlags.Reference | TypeFlags.Instantiated) && depth >= 5) {
- let symbol = type.symbol;
+ const symbol = type.symbol;
let count = 0;
for (let i = 0; i < depth; i++) {
- let t = stack[i];
+ const t = stack[i];
if (t.flags & (TypeFlags.Reference | TypeFlags.Instantiated) && t.symbol === symbol) {
count++;
if (count >= 5) return true;
@@ -5622,8 +5621,8 @@ namespace ts {
if (sourceProp === targetProp) {
return Ternary.True;
}
- let sourcePropAccessibility = getDeclarationFlagsFromSymbol(sourceProp) & (NodeFlags.Private | NodeFlags.Protected);
- let targetPropAccessibility = getDeclarationFlagsFromSymbol(targetProp) & (NodeFlags.Private | NodeFlags.Protected);
+ const sourcePropAccessibility = getDeclarationFlagsFromSymbol(sourceProp) & (NodeFlags.Private | NodeFlags.Protected);
+ const targetPropAccessibility = getDeclarationFlagsFromSymbol(targetProp) & (NodeFlags.Private | NodeFlags.Protected);
if (sourcePropAccessibility !== targetPropAccessibility) {
return Ternary.False;
}
@@ -5659,7 +5658,7 @@ namespace ts {
return Ternary.False;
}
for (let i = 0, len = source.typeParameters.length; i < len; ++i) {
- let related = compareTypes(source.typeParameters[i], target.typeParameters[i]);
+ const related = compareTypes(source.typeParameters[i], target.typeParameters[i]);
if (!related) {
return Ternary.False;
}
@@ -5673,11 +5672,11 @@ namespace ts {
// M and N (the signatures) are instantiated using type Any as the type argument for all type parameters declared by M and N
source = getErasedSignature(source);
target = getErasedSignature(target);
- let targetLen = target.parameters.length;
+ const targetLen = target.parameters.length;
for (let i = 0; i < targetLen; i++) {
- let s = isRestParameterIndex(source, i) ? getRestTypeOfSignature(source) : getTypeOfSymbol(source.parameters[i]);
- let t = isRestParameterIndex(target, i) ? getRestTypeOfSignature(target) : getTypeOfSymbol(target.parameters[i]);
- let related = compareTypes(s, t);
+ const s = isRestParameterIndex(source, i) ? getRestTypeOfSignature(source) : getTypeOfSymbol(source.parameters[i]);
+ const t = isRestParameterIndex(target, i) ? getRestTypeOfSignature(target) : getTypeOfSymbol(target.parameters[i]);
+ const related = compareTypes(s, t);
if (!related) {
return Ternary.False;
}
@@ -5694,7 +5693,7 @@ namespace ts {
}
function isSupertypeOfEach(candidate: Type, types: Type[]): boolean {
- for (let type of types) {
+ for (const type of types) {
if (candidate !== type && !isTypeSubtypeOf(type, candidate)) return false;
}
return true;
@@ -5786,13 +5785,13 @@ namespace ts {
}
function getWidenedTypeOfObjectLiteral(type: Type): Type {
- let properties = getPropertiesOfObjectType(type);
- let members: SymbolTable = {};
+ const properties = getPropertiesOfObjectType(type);
+ const members: SymbolTable = {};
forEach(properties, p => {
- let propType = getTypeOfSymbol(p);
- let widenedType = getWidenedType(propType);
+ const propType = getTypeOfSymbol(p);
+ const widenedType = getWidenedType(propType);
if (propType !== widenedType) {
- let symbol = createSymbol(p.flags | SymbolFlags.Transient, p.name);
+ const symbol = createSymbol(p.flags | SymbolFlags.Transient, p.name);
symbol.declarations = p.declarations;
symbol.parent = p.parent;
symbol.type = widenedType;
@@ -5844,7 +5843,7 @@ namespace ts {
function reportWideningErrorsInType(type: Type): boolean {
let errorReported = false;
if (type.flags & TypeFlags.Union) {
- for (let t of (type).types) {
+ for (const t of (type).types) {
if (reportWideningErrorsInType(t)) {
errorReported = true;
}
@@ -5854,15 +5853,15 @@ namespace ts {
return reportWideningErrorsInType((type).typeArguments[0]);
}
if (isTupleType(type)) {
- for (let t of type.elementTypes) {
+ for (const t of type.elementTypes) {
if (reportWideningErrorsInType(t)) {
errorReported = true;
}
}
}
if (type.flags & TypeFlags.ObjectLiteral) {
- for (let p of getPropertiesOfObjectType(type)) {
- let t = getTypeOfSymbol(p);
+ for (const p of getPropertiesOfObjectType(type)) {
+ const t = getTypeOfSymbol(p);
if (t.flags & TypeFlags.ContainsUndefinedOrNull) {
if (!reportWideningErrorsInType(t)) {
error(p.valueDeclaration, Diagnostics.Object_literal_s_property_0_implicitly_has_an_1_type, p.name, typeToString(getWidenedType(t)));
@@ -5875,7 +5874,7 @@ namespace ts {
}
function reportImplicitAnyError(declaration: Declaration, type: Type) {
- let typeAsString = typeToString(getWidenedType(type));
+ const typeAsString = typeToString(getWidenedType(type));
let diagnostic: DiagnosticMessage;
switch (declaration.kind) {
case SyntaxKind.PropertyDeclaration:
@@ -5936,15 +5935,15 @@ namespace ts {
count = sourceMax < targetMax ? sourceMax : targetMax;
}
for (let i = 0; i < count; i++) {
- let s = i < sourceMax ? getTypeOfSymbol(source.parameters[i]) : getRestTypeOfSignature(source);
- let t = i < targetMax ? getTypeOfSymbol(target.parameters[i]) : getRestTypeOfSignature(target);
+ const s = i < sourceMax ? getTypeOfSymbol(source.parameters[i]) : getRestTypeOfSignature(source);
+ const t = i < targetMax ? getTypeOfSymbol(target.parameters[i]) : getRestTypeOfSignature(target);
callback(s, t);
}
}
function createInferenceContext(typeParameters: TypeParameter[], inferUnionTypes: boolean): InferenceContext {
- let inferences: TypeInferences[] = [];
- for (let unused of typeParameters) {
+ const inferences: TypeInferences[] = [];
+ for (const unused of typeParameters) {
inferences.push({
primary: undefined, secondary: undefined, isFixed: false
});
@@ -5985,10 +5984,10 @@ namespace ts {
return;
}
- let typeParameters = context.typeParameters;
+ const typeParameters = context.typeParameters;
for (let i = 0; i < typeParameters.length; i++) {
if (target === typeParameters[i]) {
- let inferences = context.inferences[i];
+ const inferences = context.inferences[i];
if (!inferences.isFixed) {
// Any inferences that are made to a type parameter in a union type are inferior
// to inferences made to a flat (non-union) type. This is because if we infer to
@@ -5996,7 +5995,7 @@ namespace ts {
// the correct constituent on the target side could be string[]). Therefore, we put
// such inferior inferences into a secondary bucket, and only use them if the primary
// bucket is empty.
- let candidates = inferiority ?
+ const candidates = inferiority ?
inferences.secondary || (inferences.secondary = []) :
inferences.primary || (inferences.primary = []);
if (!contains(candidates, source)) {
@@ -6009,27 +6008,27 @@ namespace ts {
}
else if (source.flags & TypeFlags.Reference && target.flags & TypeFlags.Reference && (source).target === (target).target) {
// If source and target are references to the same generic type, infer from type arguments
- let sourceTypes = (source).typeArguments || emptyArray;
- let targetTypes = (target).typeArguments || emptyArray;
- let count = sourceTypes.length < targetTypes.length ? sourceTypes.length : targetTypes.length;
+ const sourceTypes = (source).typeArguments || emptyArray;
+ const targetTypes = (target).typeArguments || emptyArray;
+ const count = sourceTypes.length < targetTypes.length ? sourceTypes.length : targetTypes.length;
for (let i = 0; i < count; i++) {
inferFromTypes(sourceTypes[i], targetTypes[i]);
}
}
else if (source.flags & TypeFlags.Tuple && target.flags & TypeFlags.Tuple && (source).elementTypes.length === (target).elementTypes.length) {
// If source and target are tuples of the same size, infer from element types
- let sourceTypes = (source).elementTypes;
- let targetTypes = (target).elementTypes;
+ const sourceTypes = (source).elementTypes;
+ const targetTypes = (target).elementTypes;
for (let i = 0; i < sourceTypes.length; i++) {
inferFromTypes(sourceTypes[i], targetTypes[i]);
}
}
else if (target.flags & TypeFlags.UnionOrIntersection) {
- let targetTypes = (target).types;
+ const targetTypes = (target).types;
let typeParameterCount = 0;
let typeParameter: TypeParameter;
// First infer to each type in union or intersection that isn't a type parameter
- for (let t of targetTypes) {
+ for (const t of targetTypes) {
if (t.flags & TypeFlags.TypeParameter && contains(context.typeParameters, t)) {
typeParameter = t;
typeParameterCount++;
@@ -6050,8 +6049,8 @@ namespace ts {
}
else if (source.flags & TypeFlags.UnionOrIntersection) {
// Source is a union or intersection type, infer from each consituent type
- let sourceTypes = (source).types;
- for (let sourceType of sourceTypes) {
+ const sourceTypes = (source).types;
+ for (const sourceType of sourceTypes) {
inferFromTypes(sourceType, target);
}
}
@@ -6086,9 +6085,9 @@ namespace ts {
}
function inferFromProperties(source: Type, target: Type) {
- let properties = getPropertiesOfObjectType(target);
- for (let targetProp of properties) {
- let sourceProp = getPropertyOfObjectType(source, targetProp.name);
+ const properties = getPropertiesOfObjectType(target);
+ for (const targetProp of properties) {
+ const sourceProp = getPropertyOfObjectType(source, targetProp.name);
if (sourceProp) {
inferFromTypes(getTypeOfSymbol(sourceProp), getTypeOfSymbol(targetProp));
}
@@ -6096,11 +6095,11 @@ namespace ts {
}
function inferFromSignatures(source: Type, target: Type, kind: SignatureKind) {
- let sourceSignatures = getSignaturesOfType(source, kind);
- let targetSignatures = getSignaturesOfType(target, kind);
- let sourceLen = sourceSignatures.length;
- let targetLen = targetSignatures.length;
- let len = sourceLen < targetLen ? sourceLen : targetLen;
+ const sourceSignatures = getSignaturesOfType(source, kind);
+ const targetSignatures = getSignaturesOfType(target, kind);
+ const sourceLen = sourceSignatures.length;
+ const targetLen = targetSignatures.length;
+ const len = sourceLen < targetLen ? sourceLen : targetLen;
for (let i = 0; i < len; i++) {
inferFromSignature(getErasedSignature(sourceSignatures[sourceLen - len + i]), getErasedSignature(targetSignatures[targetLen - len + i]));
}
@@ -6122,9 +6121,9 @@ namespace ts {
}
function inferFromIndexTypes(source: Type, target: Type, sourceKind: IndexKind, targetKind: IndexKind) {
- let targetIndexType = getIndexTypeOfType(target, targetKind);
+ const targetIndexType = getIndexTypeOfType(target, targetKind);
if (targetIndexType) {
- let sourceIndexType = getIndexTypeOfType(source, sourceKind);
+ const sourceIndexType = getIndexTypeOfType(source, sourceKind);
if (sourceIndexType) {
inferFromTypes(sourceIndexType, targetIndexType);
}
@@ -6133,7 +6132,7 @@ namespace ts {
}
function getInferenceCandidates(context: InferenceContext, index: number): Type[] {
- let inferences = context.inferences[index];
+ const inferences = context.inferences[index];
return inferences.primary || inferences.secondary || emptyArray;
}
@@ -6141,10 +6140,10 @@ namespace ts {
let inferredType = context.inferredTypes[index];
let inferenceSucceeded: boolean;
if (!inferredType) {
- let inferences = getInferenceCandidates(context, index);
+ const inferences = getInferenceCandidates(context, index);
if (inferences.length) {
// Infer widened union or supertype, or the unknown type for no common supertype
- let unionOrSuperType = context.inferUnionTypes ? getUnionType(inferences) : getCommonSupertype(inferences);
+ const unionOrSuperType = context.inferUnionTypes ? getUnionType(inferences) : getCommonSupertype(inferences);
inferredType = unionOrSuperType ? getWidenedType(unionOrSuperType) : unknownType;
inferenceSucceeded = !!unionOrSuperType;
}
@@ -6159,7 +6158,7 @@ namespace ts {
// Only do the constraint check if inference succeeded (to prevent cascading errors)
if (inferenceSucceeded) {
- let constraint = getConstraintOfTypeParameter(context.typeParameters[index]);
+ const constraint = getConstraintOfTypeParameter(context.typeParameters[index]);
inferredType = constraint && !isTypeAssignableTo(inferredType, constraint) ? constraint : inferredType;
}
else if (context.failedTypeParameterIndex === undefined || context.failedTypeParameterIndex > index) {
@@ -6188,7 +6187,7 @@ namespace ts {
// EXPRESSION TYPE CHECKING
function getResolvedSymbol(node: Identifier): Symbol {
- let links = getNodeLinks(node);
+ const links = getNodeLinks(node);
if (!links.resolvedSymbol) {
links.resolvedSymbol = (!nodeIsMissing(node) && resolveName(node, node.text, SymbolFlags.Value | SymbolFlags.ExportValue, Diagnostics.Cannot_find_name_0, node)) || unknownSymbol;
}
@@ -6218,10 +6217,10 @@ namespace ts {
// or not of the given type kind (when isOfTypeKind is false)
function removeTypesFromUnionType(type: Type, typeKind: TypeFlags, isOfTypeKind: boolean, allowEmptyUnionResult: boolean): Type {
if (type.flags & TypeFlags.Union) {
- let types = (type).types;
+ const types = (type).types;
if (forEach(types, t => !!(t.flags & typeKind) === isOfTypeKind)) {
// Above we checked if we have anything to remove, now use the opposite test to do the removal
- let narrowedType = getUnionType(filter(types, t => !(t.flags & typeKind) === isOfTypeKind));
+ const narrowedType = getUnionType(filter(types, t => !(t.flags & typeKind) === isOfTypeKind));
if (allowEmptyUnionResult || narrowedType !== emptyObjectType) {
return narrowedType;
}
@@ -6241,9 +6240,9 @@ namespace ts {
// Check if a given variable is assigned within a given syntax node
function isVariableAssignedWithin(symbol: Symbol, node: Node): boolean {
- let links = getNodeLinks(node);
+ const links = getNodeLinks(node);
if (links.assignmentChecks) {
- let cachedResult = links.assignmentChecks[symbol.id];
+ const cachedResult = links.assignmentChecks[symbol.id];
if (cachedResult !== undefined) {
return cachedResult;
}
@@ -6337,7 +6336,7 @@ namespace ts {
if (node && symbol.flags & SymbolFlags.Variable) {
if (isTypeAny(type) || type.flags & (TypeFlags.ObjectType | TypeFlags.Union | TypeFlags.TypeParameter)) {
loop: while (node.parent) {
- let child = node;
+ const child = node;
node = node.parent;
let narrowedType = type;
switch (node.kind) {
@@ -6393,12 +6392,12 @@ namespace ts {
if (expr.left.kind !== SyntaxKind.TypeOfExpression || expr.right.kind !== SyntaxKind.StringLiteral) {
return type;
}
- let left = expr.left;
- let right = expr.right;
+ const left = expr.left;
+ const right = expr.right;
if (left.expression.kind !== SyntaxKind.Identifier || getResolvedSymbol(left.expression) !== symbol) {
return type;
}
- let typeInfo = primitiveTypeInfo[right.text];
+ const typeInfo = primitiveTypeInfo[right.text];
if (expr.operatorToken.kind === SyntaxKind.ExclamationEqualsEqualsToken) {
assumeTrue = !assumeTrue;
}
@@ -6462,16 +6461,16 @@ namespace ts {
return type;
}
// Check that right operand is a function type with a prototype property
- let rightType = checkExpression(expr.right);
+ const rightType = checkExpression(expr.right);
if (!isTypeSubtypeOf(rightType, globalFunctionType)) {
return type;
}
let targetType: Type;
- let prototypeProperty = getPropertyOfType(rightType, "prototype");
+ const prototypeProperty = getPropertyOfType(rightType, "prototype");
if (prototypeProperty) {
// Target type is type of the prototype property
- let prototypePropertyType = getTypeOfSymbol(prototypeProperty);
+ const prototypePropertyType = getTypeOfSymbol(prototypeProperty);
if (!isTypeAny(prototypePropertyType)) {
targetType = prototypePropertyType;
}
@@ -6502,7 +6501,7 @@ namespace ts {
// If the current type is a union type, remove all constituents that aren't assignable to target. If that produces
// 0 candidates, fall back to the assignability check
if (originalType.flags & TypeFlags.Union) {
- let assignableConstituents = filter((