Merge branch 'master' of https://github.com/Microsoft/TypeScript into updateDomDTs

This commit is contained in:
Zhengbo Li
2015-06-03 15:25:36 -07:00
26 changed files with 1991 additions and 1285 deletions
+265 -270
View File
@@ -2783,34 +2783,30 @@ var ts;
var symbolCount = 0;
var Symbol = ts.objectAllocator.getSymbolConstructor();
if (!file.locals) {
file.locals = {};
container = file;
setBlockScopeContainer(file, false);
bind(file);
file.symbolCount = symbolCount;
}
return;
function createSymbol(flags, name) {
symbolCount++;
return new Symbol(flags, name);
}
function setBlockScopeContainer(node, cleanLocals) {
blockScopeContainer = node;
if (cleanLocals) {
blockScopeContainer.locals = undefined;
}
}
function addDeclarationToSymbol(symbol, node, symbolKind) {
symbol.flags |= symbolKind;
if (!symbol.declarations)
symbol.declarations = [];
symbol.declarations.push(node);
if (symbolKind & 1952 && !symbol.exports)
symbol.exports = {};
if (symbolKind & 6240 && !symbol.members)
symbol.members = {};
function addDeclarationToSymbol(symbol, node, symbolFlags) {
symbol.flags |= symbolFlags;
node.symbol = symbol;
if (symbolKind & 107455 && !symbol.valueDeclaration)
if (!symbol.declarations) {
symbol.declarations = [];
}
symbol.declarations.push(node);
if (symbolFlags & 1952 && !symbol.exports) {
symbol.exports = {};
}
if (symbolFlags & 6240 && !symbol.members) {
symbol.members = {};
}
if (symbolFlags & 107455 && !symbol.valueDeclaration) {
symbol.valueDeclaration = node;
}
}
function getDeclarationName(node) {
if (node.name) {
@@ -2825,12 +2821,12 @@ var ts;
return node.name.text;
}
switch (node.kind) {
case 144:
case 136:
return "__constructor";
case 143:
case 139:
return "__call";
case 144:
case 140:
return "__new";
case 141:
@@ -2847,12 +2843,14 @@ var ts;
function getDisplayName(node) {
return node.name ? ts.declarationNameToString(node.name) : getDeclarationName(node);
}
function declareSymbol(symbols, parent, node, includes, excludes) {
function declareSymbol(symbolTable, parent, node, includes, excludes) {
ts.Debug.assert(!ts.hasDynamicName(node));
var name = node.flags & 256 && parent ? "default" : getDeclarationName(node);
var symbol;
if (name !== undefined) {
symbol = ts.hasProperty(symbols, name) ? symbols[name] : (symbols[name] = createSymbol(0, name));
symbol = ts.hasProperty(symbolTable, name)
? symbolTable[name]
: (symbolTable[name] = createSymbol(0, name));
if (symbol.flags & excludes) {
if (node.name) {
node.name.parent = node;
@@ -2872,79 +2870,115 @@ var ts;
}
addDeclarationToSymbol(symbol, node, includes);
symbol.parent = parent;
if ((node.kind === 202 || node.kind === 175) && symbol.exports) {
var prototypeSymbol = createSymbol(4 | 134217728, "prototype");
if (ts.hasProperty(symbol.exports, prototypeSymbol.name)) {
if (node.name) {
node.name.parent = node;
}
file.bindDiagnostics.push(ts.createDiagnosticForNode(symbol.exports[prototypeSymbol.name].declarations[0], ts.Diagnostics.Duplicate_identifier_0, prototypeSymbol.name));
}
symbol.exports[prototypeSymbol.name] = prototypeSymbol;
prototypeSymbol.parent = symbol;
}
return symbol;
}
function declareModuleMember(node, symbolKind, symbolExcludes) {
function declareModuleMember(node, symbolFlags, symbolExcludes) {
var hasExportModifier = ts.getCombinedNodeFlags(node) & 1;
if (symbolKind & 8388608) {
if (symbolFlags & 8388608) {
if (node.kind === 218 || (node.kind === 209 && hasExportModifier)) {
declareSymbol(container.symbol.exports, container.symbol, node, symbolKind, symbolExcludes);
return declareSymbol(container.symbol.exports, container.symbol, node, symbolFlags, symbolExcludes);
}
else {
declareSymbol(container.locals, undefined, node, symbolKind, symbolExcludes);
return declareSymbol(container.locals, undefined, node, symbolFlags, symbolExcludes);
}
}
else {
if (hasExportModifier || container.flags & 65536) {
var exportKind = (symbolKind & 107455 ? 1048576 : 0) |
(symbolKind & 793056 ? 2097152 : 0) |
(symbolKind & 1536 ? 4194304 : 0);
var exportKind = (symbolFlags & 107455 ? 1048576 : 0) |
(symbolFlags & 793056 ? 2097152 : 0) |
(symbolFlags & 1536 ? 4194304 : 0);
var local = declareSymbol(container.locals, undefined, node, exportKind, symbolExcludes);
local.exportSymbol = declareSymbol(container.symbol.exports, container.symbol, node, symbolKind, symbolExcludes);
local.exportSymbol = declareSymbol(container.symbol.exports, container.symbol, node, symbolFlags, symbolExcludes);
node.localSymbol = local;
return local;
}
else {
declareSymbol(container.locals, undefined, node, symbolKind, symbolExcludes);
return declareSymbol(container.locals, undefined, node, symbolFlags, symbolExcludes);
}
}
}
function bindChildren(node, symbolKind, isBlockScopeContainer) {
if (symbolKind & 255504) {
node.locals = {};
}
function bindChildren(node) {
var saveParent = parent;
var saveContainer = container;
var savedBlockScopeContainer = blockScopeContainer;
parent = node;
if (symbolKind & 262128) {
container = node;
var containerFlags = getContainerFlags(node);
if (containerFlags & 1) {
container = blockScopeContainer = node;
if (containerFlags & 4) {
container.locals = {};
}
addToContainerChain(container);
}
if (isBlockScopeContainer) {
setBlockScopeContainer(node, (symbolKind & 255504) === 0 && node.kind !== 228);
else if (containerFlags & 2) {
blockScopeContainer = node;
blockScopeContainer.locals = undefined;
}
ts.forEachChild(node, bind);
container = saveContainer;
parent = saveParent;
blockScopeContainer = savedBlockScopeContainer;
}
function addToContainerChain(node) {
if (lastContainer) {
lastContainer.nextContainer = node;
function getContainerFlags(node) {
switch (node.kind) {
case 175:
case 202:
case 203:
case 205:
case 146:
case 155:
return 1;
case 139:
case 140:
case 141:
case 135:
case 134:
case 201:
case 136:
case 137:
case 138:
case 143:
case 144:
case 163:
case 164:
case 206:
case 228:
return 5;
case 224:
case 187:
case 188:
case 189:
case 208:
return 2;
case 180:
return ts.isFunctionLike(node.parent) ? 0 : 2;
}
lastContainer = node;
return 0;
}
function bindDeclaration(node, symbolKind, symbolExcludes, isBlockScopeContainer) {
function addToContainerChain(next) {
if (lastContainer) {
lastContainer.nextContainer = next;
}
lastContainer = next;
}
function declareSymbolAndAddToSymbolTable(node, symbolFlags, symbolExcludes) {
declareSymbolAndAddToSymbolTableWorker(node, symbolFlags, symbolExcludes);
}
function declareSymbolAndAddToSymbolTableWorker(node, symbolFlags, symbolExcludes) {
switch (container.kind) {
case 206:
declareModuleMember(node, symbolKind, symbolExcludes);
break;
return declareModuleMember(node, symbolFlags, symbolExcludes);
case 228:
if (ts.isExternalModule(container)) {
declareModuleMember(node, symbolKind, symbolExcludes);
break;
}
return declareSourceFileMember(node, symbolFlags, symbolExcludes);
case 175:
case 202:
return declareClassMember(node, symbolFlags, symbolExcludes);
case 205:
return declareSymbol(container.symbol.exports, container.symbol, node, symbolFlags, symbolExcludes);
case 146:
case 155:
case 203:
return declareSymbol(container.symbol.members, container.symbol, node, symbolFlags, symbolExcludes);
case 143:
case 144:
case 139:
@@ -2958,29 +2992,24 @@ var ts;
case 201:
case 163:
case 164:
declareSymbol(container.locals, undefined, node, symbolKind, symbolExcludes);
break;
case 175:
case 202:
if (node.flags & 128) {
declareSymbol(container.symbol.exports, container.symbol, node, symbolKind, symbolExcludes);
break;
}
case 146:
case 155:
case 203:
declareSymbol(container.symbol.members, container.symbol, node, symbolKind, symbolExcludes);
break;
case 205:
declareSymbol(container.symbol.exports, container.symbol, node, symbolKind, symbolExcludes);
break;
return declareSymbol(container.locals, undefined, node, symbolFlags, symbolExcludes);
}
bindChildren(node, symbolKind, isBlockScopeContainer);
}
function declareClassMember(node, symbolFlags, symbolExcludes) {
return node.flags & 128
? declareSymbol(container.symbol.exports, container.symbol, node, symbolFlags, symbolExcludes)
: declareSymbol(container.symbol.members, container.symbol, node, symbolFlags, symbolExcludes);
}
function declareSourceFileMember(node, symbolFlags, symbolExcludes) {
return ts.isExternalModule(file)
? declareModuleMember(node, symbolFlags, symbolExcludes)
: declareSymbol(file.locals, undefined, node, symbolFlags, symbolExcludes);
}
function isAmbientContext(node) {
while (node) {
if (node.flags & 2)
if (node.flags & 2) {
return true;
}
node = node.parent;
}
return false;
@@ -3008,15 +3037,15 @@ var ts;
function bindModuleDeclaration(node) {
setExportContextFlag(node);
if (node.name.kind === 8) {
bindDeclaration(node, 512, 106639, true);
declareSymbolAndAddToSymbolTable(node, 512, 106639);
}
else {
var state = getModuleInstanceState(node);
if (state === 0) {
bindDeclaration(node, 1024, 0, true);
declareSymbolAndAddToSymbolTable(node, 1024, 0);
}
else {
bindDeclaration(node, 512, 106639, true);
declareSymbolAndAddToSymbolTable(node, 512, 106639);
var currentModuleIsConstEnumOnly = state === 2;
if (node.symbol.constEnumOnlyModule === undefined) {
node.symbol.constEnumOnlyModule = currentModuleIsConstEnumOnly;
@@ -3028,36 +3057,25 @@ var ts;
}
}
function bindFunctionOrConstructorType(node) {
// For a given function symbol "<...>(...) => T" we want to generate a symbol identical
// to the one we would get for: { <...>(...): T }
//
// 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.
var symbol = createSymbol(131072, getDeclarationName(node));
addDeclarationToSymbol(symbol, node, 131072);
bindChildren(node, 131072, false);
var typeLiteralSymbol = createSymbol(2048, "__type");
addDeclarationToSymbol(typeLiteralSymbol, node, 2048);
typeLiteralSymbol.members = {};
typeLiteralSymbol.members[node.kind === 143 ? "__call" : "__new"] = symbol;
typeLiteralSymbol.members = (_a = {}, _a[symbol.name] = symbol, _a);
var _a;
}
function bindAnonymousDeclaration(node, symbolKind, name, isBlockScopeContainer) {
var symbol = createSymbol(symbolKind, name);
addDeclarationToSymbol(symbol, node, symbolKind);
bindChildren(node, symbolKind, isBlockScopeContainer);
function bindAnonymousDeclaration(node, symbolFlags, name) {
var symbol = createSymbol(symbolFlags, name);
addDeclarationToSymbol(symbol, node, symbolFlags);
}
function bindCatchVariableDeclaration(node) {
bindChildren(node, 0, true);
}
function bindBlockScopedDeclaration(node, symbolKind, symbolExcludes) {
function bindBlockScopedDeclaration(node, symbolFlags, symbolExcludes) {
switch (blockScopeContainer.kind) {
case 206:
declareModuleMember(node, symbolKind, symbolExcludes);
declareModuleMember(node, symbolFlags, symbolExcludes);
break;
case 228:
if (ts.isExternalModule(container)) {
declareModuleMember(node, symbolKind, symbolExcludes);
declareModuleMember(node, symbolFlags, symbolExcludes);
break;
}
default:
@@ -3065,9 +3083,8 @@ var ts;
blockScopeContainer.locals = {};
addToContainerChain(blockScopeContainer);
}
declareSymbol(blockScopeContainer.locals, undefined, node, symbolKind, symbolExcludes);
declareSymbol(blockScopeContainer.locals, undefined, node, symbolFlags, symbolExcludes);
}
bindChildren(node, symbolKind, false);
}
function bindBlockScopedVariableDeclaration(node) {
bindBlockScopedDeclaration(node, 2, 107455);
@@ -3077,158 +3094,143 @@ var ts;
}
function bind(node) {
node.parent = parent;
bindWorker(node);
bindChildren(node);
}
function bindWorker(node) {
switch (node.kind) {
case 129:
bindDeclaration(node, 262144, 530912, false);
break;
return declareSymbolAndAddToSymbolTable(node, 262144, 530912);
case 130:
bindParameter(node);
break;
return bindParameter(node);
case 199:
case 153:
if (ts.isBindingPattern(node.name)) {
bindChildren(node, 0, false);
}
else if (ts.isBlockOrCatchScoped(node)) {
bindBlockScopedVariableDeclaration(node);
}
else if (ts.isParameterDeclaration(node)) {
bindDeclaration(node, 1, 107455, false);
}
else {
bindDeclaration(node, 1, 107454, false);
}
break;
return bindVariableDeclarationOrBindingElement(node);
case 133:
case 132:
bindPropertyOrMethodOrAccessor(node, 4 | (node.questionToken ? 536870912 : 0), 107455, false);
break;
return bindPropertyOrMethodOrAccessor(node, 4 | (node.questionToken ? 536870912 : 0), 107455);
case 225:
case 226:
bindPropertyOrMethodOrAccessor(node, 4, 107455, false);
break;
return bindPropertyOrMethodOrAccessor(node, 4, 107455);
case 227:
bindPropertyOrMethodOrAccessor(node, 8, 107455, false);
break;
return bindPropertyOrMethodOrAccessor(node, 8, 107455);
case 139:
case 140:
case 141:
bindDeclaration(node, 131072, 0, false);
break;
return declareSymbolAndAddToSymbolTable(node, 131072, 0);
case 135:
case 134:
bindPropertyOrMethodOrAccessor(node, 8192 | (node.questionToken ? 536870912 : 0), ts.isObjectLiteralMethod(node) ? 107455 : 99263, true);
break;
return bindPropertyOrMethodOrAccessor(node, 8192 | (node.questionToken ? 536870912 : 0), ts.isObjectLiteralMethod(node) ? 107455 : 99263);
case 201:
bindDeclaration(node, 16, 106927, true);
break;
return declareSymbolAndAddToSymbolTable(node, 16, 106927);
case 136:
bindDeclaration(node, 16384, 0, true);
break;
return declareSymbolAndAddToSymbolTable(node, 16384, 0);
case 137:
bindPropertyOrMethodOrAccessor(node, 32768, 41919, true);
break;
return bindPropertyOrMethodOrAccessor(node, 32768, 41919);
case 138:
bindPropertyOrMethodOrAccessor(node, 65536, 74687, true);
break;
return bindPropertyOrMethodOrAccessor(node, 65536, 74687);
case 143:
case 144:
bindFunctionOrConstructorType(node);
break;
return bindFunctionOrConstructorType(node);
case 146:
bindAnonymousDeclaration(node, 2048, "__type", false);
break;
return bindAnonymousDeclaration(node, 2048, "__type");
case 155:
bindAnonymousDeclaration(node, 4096, "__object", false);
break;
return bindAnonymousDeclaration(node, 4096, "__object");
case 163:
case 164:
bindAnonymousDeclaration(node, 16, "__function", true);
break;
return bindAnonymousDeclaration(node, 16, "__function");
case 175:
bindAnonymousDeclaration(node, 32, "__class", false);
break;
case 224:
bindCatchVariableDeclaration(node);
break;
case 202:
bindBlockScopedDeclaration(node, 32, 899583);
break;
return bindClassLikeDeclaration(node);
case 203:
bindBlockScopedDeclaration(node, 64, 792992);
break;
return bindBlockScopedDeclaration(node, 64, 792992);
case 204:
bindBlockScopedDeclaration(node, 524288, 793056);
break;
return bindBlockScopedDeclaration(node, 524288, 793056);
case 205:
if (ts.isConst(node)) {
bindBlockScopedDeclaration(node, 128, 899967);
}
else {
bindBlockScopedDeclaration(node, 256, 899327);
}
break;
return bindEnumDeclaration(node);
case 206:
bindModuleDeclaration(node);
break;
return bindModuleDeclaration(node);
case 209:
case 212:
case 214:
case 218:
bindDeclaration(node, 8388608, 8388608, false);
break;
return declareSymbolAndAddToSymbolTable(node, 8388608, 8388608);
case 211:
if (node.name) {
bindDeclaration(node, 8388608, 8388608, false);
}
else {
bindChildren(node, 0, false);
}
break;
return bindImportClause(node);
case 216:
if (!node.exportClause) {
declareSymbol(container.symbol.exports, container.symbol, node, 1073741824, 0);
}
bindChildren(node, 0, false);
break;
return bindExportDeclaration(node);
case 215:
if (node.expression.kind === 65) {
declareSymbol(container.symbol.exports, container.symbol, node, 8388608, 107455 | 8388608);
}
else {
declareSymbol(container.symbol.exports, container.symbol, node, 4, 107455 | 8388608);
}
bindChildren(node, 0, false);
break;
return bindExportAssignment(node);
case 228:
setExportContextFlag(node);
if (ts.isExternalModule(node)) {
bindAnonymousDeclaration(node, 512, '"' + ts.removeFileExtension(node.fileName) + '"', true);
break;
}
case 180:
bindChildren(node, 0, !ts.isFunctionLike(node.parent));
break;
case 224:
case 187:
case 188:
case 189:
case 208:
bindChildren(node, 0, true);
break;
default:
var saveParent = parent;
parent = node;
ts.forEachChild(node, bind);
parent = saveParent;
return bindSourceFileIfExternalModule();
}
}
function bindSourceFileIfExternalModule() {
setExportContextFlag(file);
if (ts.isExternalModule(file)) {
bindAnonymousDeclaration(file, 512, '"' + ts.removeFileExtension(file.fileName) + '"');
}
}
function bindExportAssignment(node) {
if (node.expression.kind === 65) {
declareSymbol(container.symbol.exports, container.symbol, node, 8388608, 107455 | 8388608);
}
else {
declareSymbol(container.symbol.exports, container.symbol, node, 4, 107455 | 8388608);
}
}
function bindExportDeclaration(node) {
if (!node.exportClause) {
declareSymbol(container.symbol.exports, container.symbol, node, 1073741824, 0);
}
}
function bindImportClause(node) {
if (node.name) {
declareSymbolAndAddToSymbolTable(node, 8388608, 8388608);
}
}
function bindClassLikeDeclaration(node) {
if (node.kind === 202) {
bindBlockScopedDeclaration(node, 32, 899583);
}
else {
bindAnonymousDeclaration(node, 32, "__class");
}
var symbol = node.symbol;
var prototypeSymbol = createSymbol(4 | 134217728, "prototype");
if (ts.hasProperty(symbol.exports, prototypeSymbol.name)) {
if (node.name) {
node.name.parent = node;
}
file.bindDiagnostics.push(ts.createDiagnosticForNode(symbol.exports[prototypeSymbol.name].declarations[0], ts.Diagnostics.Duplicate_identifier_0, prototypeSymbol.name));
}
symbol.exports[prototypeSymbol.name] = prototypeSymbol;
prototypeSymbol.parent = symbol;
}
function bindEnumDeclaration(node) {
return ts.isConst(node)
? bindBlockScopedDeclaration(node, 128, 899967)
: bindBlockScopedDeclaration(node, 256, 899327);
}
function bindVariableDeclarationOrBindingElement(node) {
if (!ts.isBindingPattern(node.name)) {
if (ts.isBlockOrCatchScoped(node)) {
bindBlockScopedVariableDeclaration(node);
}
else if (ts.isParameterDeclaration(node)) {
declareSymbolAndAddToSymbolTable(node, 1, 107455);
}
else {
declareSymbolAndAddToSymbolTable(node, 1, 107454);
}
}
}
function bindParameter(node) {
if (ts.isBindingPattern(node.name)) {
bindAnonymousDeclaration(node, 1, getDestructuringParameterName(node), false);
bindAnonymousDeclaration(node, 1, getDestructuringParameterName(node));
}
else {
bindDeclaration(node, 1, 107455, false);
declareSymbolAndAddToSymbolTable(node, 1, 107455);
}
if (node.flags & 112 &&
node.parent.kind === 136 &&
@@ -3237,13 +3239,10 @@ var ts;
declareSymbol(classDeclaration.symbol.members, classDeclaration.symbol, node, 4, 107455);
}
}
function bindPropertyOrMethodOrAccessor(node, symbolKind, symbolExcludes, isBlockScopeContainer) {
if (ts.hasDynamicName(node)) {
bindAnonymousDeclaration(node, symbolKind, "__computed", isBlockScopeContainer);
}
else {
bindDeclaration(node, symbolKind, symbolExcludes, isBlockScopeContainer);
}
function bindPropertyOrMethodOrAccessor(node, symbolFlags, symbolExcludes) {
return ts.hasDynamicName(node)
? bindAnonymousDeclaration(node, symbolFlags, "__computed")
: declareSymbolAndAddToSymbolTable(node, symbolFlags, symbolExcludes);
}
}
})(ts || (ts = {}));
@@ -4020,10 +4019,6 @@ var ts;
}
}
ts.getExternalModuleName = getExternalModuleName;
function hasDotDotDotToken(node) {
return node && node.kind === 130 && node.dotDotDotToken !== undefined;
}
ts.hasDotDotDotToken = hasDotDotDotToken;
function hasQuestionToken(node) {
if (node) {
switch (node.kind) {
@@ -4042,10 +4037,6 @@ var ts;
return false;
}
ts.hasQuestionToken = hasQuestionToken;
function hasRestParameters(s) {
return s.parameters.length > 0 && ts.lastOrUndefined(s.parameters).dotDotDotToken !== undefined;
}
ts.hasRestParameters = hasRestParameters;
function isJSDocConstructSignature(node) {
return node.kind === 241 &&
node.parameters.length > 0 &&
@@ -5024,7 +5015,6 @@ var ts;
/// <reference path="utilities.ts"/>
var ts;
(function (ts) {
ts.throwOnJSDocErrors = false;
var nodeConstructors = new Array(252);
ts.parseTime = 0;
function getNodeConstructor(kind) {
@@ -8570,12 +8560,6 @@ var ts;
return finishNode(result);
}
JSDocParser.parseJSDocTypeExpression = parseJSDocTypeExpression;
function setError(message) {
parseErrorAtCurrentToken(message);
if (ts.throwOnJSDocErrors) {
throw new Error(message.key);
}
}
function parseJSDocTopLevelType() {
var type = parseJSDocType();
if (token === 44) {
@@ -9717,27 +9701,31 @@ var ts;
case 138:
case 201:
case 164:
if (name === "arguments") {
if (meaning & 3 && name === "arguments") {
result = argumentsSymbol;
break loop;
}
break;
case 163:
if (name === "arguments") {
if (meaning & 3 && name === "arguments") {
result = argumentsSymbol;
break loop;
}
var functionName = location.name;
if (functionName && name === functionName.text) {
result = location.symbol;
break loop;
if (meaning & 16) {
var functionName = location.name;
if (functionName && name === functionName.text) {
result = location.symbol;
break loop;
}
}
break;
case 175:
var className = location.name;
if (className && name === className.text) {
result = location.symbol;
break loop;
if (meaning & 32) {
var className = location.name;
if (className && name === className.text) {
result = location.symbol;
break loop;
}
}
break;
case 131:
@@ -10771,11 +10759,12 @@ var ts;
}
}
function buildParameterDisplay(p, writer, enclosingDeclaration, flags, typeStack) {
if (ts.hasDotDotDotToken(p.valueDeclaration)) {
var parameterNode = p.valueDeclaration;
if (ts.isRestParameter(parameterNode)) {
writePunctuation(writer, 21);
}
appendSymbolNameOnly(p, writer);
if (ts.hasQuestionToken(p.valueDeclaration) || p.valueDeclaration.initializer) {
if (isOptionalParameter(parameterNode)) {
writePunctuation(writer, 50);
}
writePunctuation(writer, 51);
@@ -11933,6 +11922,9 @@ var ts;
}
return result;
}
function isOptionalParameter(node) {
return ts.hasQuestionToken(node) || !!node.initializer;
}
function getSignatureFromDeclaration(declaration) {
var links = getNodeLinks(declaration);
if (!links.resolvedSignature) {
@@ -11973,7 +11965,7 @@ var ts;
returnType = anyType;
}
}
links.resolvedSignature = createSignature(declaration, typeParameters, parameters, returnType, minArgumentCount, ts.hasRestParameters(declaration), hasStringLiterals);
links.resolvedSignature = createSignature(declaration, typeParameters, parameters, returnType, minArgumentCount, ts.hasRestParameter(declaration), hasStringLiterals);
}
return links.resolvedSignature;
}
@@ -12202,27 +12194,7 @@ var ts;
type = unknownType;
}
else {
type = getDeclaredTypeOfSymbol(symbol);
if (type.flags & (1024 | 2048) && type.flags & 4096) {
var localTypeParameters = type.localTypeParameters;
var expectedTypeArgCount = localTypeParameters ? localTypeParameters.length : 0;
var typeArgCount = node.typeArguments ? node.typeArguments.length : 0;
if (typeArgCount === expectedTypeArgCount) {
if (typeArgCount) {
type = createTypeReference(type, ts.concatenate(type.outerTypeParameters, ts.map(node.typeArguments, getTypeFromTypeNode)));
}
}
else {
error(node, ts.Diagnostics.Generic_type_0_requires_1_type_argument_s, typeToString(type, undefined, 1), expectedTypeArgCount);
type = undefined;
}
}
else {
if (node.typeArguments) {
error(node, ts.Diagnostics.Type_0_is_not_generic, typeToString(type));
type = undefined;
}
}
type = createTypeReferenceIfGeneric(getDeclaredTypeOfSymbol(symbol), node, node.typeArguments);
}
}
}
@@ -12230,6 +12202,29 @@ var ts;
}
return links.resolvedType;
}
function createTypeReferenceIfGeneric(type, node, typeArguments) {
if (type.flags & (1024 | 2048) && type.flags & 4096) {
var localTypeParameters = type.localTypeParameters;
var expectedTypeArgCount = localTypeParameters ? localTypeParameters.length : 0;
var typeArgCount = typeArguments ? typeArguments.length : 0;
if (typeArgCount === expectedTypeArgCount) {
if (typeArgCount) {
return createTypeReference(type, ts.concatenate(type.outerTypeParameters, ts.map(typeArguments, getTypeFromTypeNode)));
}
}
else {
error(node, ts.Diagnostics.Generic_type_0_requires_1_type_argument_s, typeToString(type, undefined, 1), expectedTypeArgCount);
return undefined;
}
}
else {
if (typeArguments) {
error(node, ts.Diagnostics.Type_0_is_not_generic, typeToString(type));
return undefined;
}
}
return type;
}
function getTypeFromTypeQueryNode(node) {
var links = getNodeLinks(node);
if (!links.resolvedType) {
@@ -14173,7 +14168,7 @@ var ts;
if (isContextSensitive(func)) {
var contextualSignature = getContextualSignature(func);
if (contextualSignature) {
var funcHasRestParameters = ts.hasRestParameters(func);
var funcHasRestParameters = ts.hasRestParameter(func);
var len = func.parameters.length - (funcHasRestParameters ? 1 : 0);
var indexOfParameter = ts.indexOf(func.parameters, parameter);
if (indexOfParameter < len) {
@@ -16687,7 +16682,7 @@ var ts;
}
}
function checkCollisionWithArgumentsInGeneratedCode(node) {
if (!ts.hasRestParameters(node) || ts.isInAmbientContext(node) || ts.nodeIsMissing(node.body)) {
if (!ts.hasRestParameter(node) || ts.isInAmbientContext(node) || ts.nodeIsMissing(node.body)) {
return;
}
ts.forEach(node.parameters, function (p) {
@@ -23709,7 +23704,7 @@ var ts;
}
}
function emitRestParameter(node) {
if (languageVersion < 2 && ts.hasRestParameters(node)) {
if (languageVersion < 2 && ts.hasRestParameter(node)) {
var restIndex = node.parameters.length - 1;
var restParam = node.parameters[restIndex];
if (ts.isBindingPattern(restParam.name)) {
@@ -23817,7 +23812,7 @@ var ts;
write("(");
if (node) {
var parameters = node.parameters;
var omitCount = languageVersion < 2 && ts.hasRestParameters(node) ? 1 : 0;
var omitCount = languageVersion < 2 && ts.hasRestParameter(node) ? 1 : 0;
emitList(parameters, 0, parameters.length - omitCount, false, false);
}
write(")");
+382 -277
View File
File diff suppressed because it is too large Load Diff
+4 -4
View File
@@ -999,6 +999,7 @@ declare module "typescript" {
UseOnlyExternalAliasing = 2,
}
const enum SymbolFlags {
None = 0,
FunctionScopedVariable = 1,
BlockScopedVariable = 2,
Property = 4,
@@ -1057,10 +1058,8 @@ declare module "typescript" {
AliasExcludes = 8388608,
ModuleMember = 8914931,
ExportHasLocal = 944,
HasLocals = 255504,
HasExports = 1952,
HasMembers = 6240,
IsContainer = 262128,
PropertyOrAccessor = 98308,
Export = 7340032,
}
@@ -1068,9 +1067,9 @@ declare module "typescript" {
flags: SymbolFlags;
name: string;
declarations?: Declaration[];
valueDeclaration?: Declaration;
members?: SymbolTable;
exports?: SymbolTable;
valueDeclaration?: Declaration;
}
interface SymbolTable {
[index: string]: Symbol;
@@ -1358,7 +1357,6 @@ declare module "typescript" {
function getTypeParameterOwner(d: Declaration): Declaration;
}
declare module "typescript" {
var throwOnJSDocErrors: boolean;
function getNodeConstructor(kind: SyntaxKind): new () => Node;
function createNode(kind: SyntaxKind): Node;
function forEachChild<T>(node: Node, cbNode: (node: Node) => T, cbNodeArray?: (nodes: Node[]) => T): T;
@@ -1913,6 +1911,7 @@ declare module "typescript" {
static typeParameterName: string;
static typeAliasName: string;
static parameterName: string;
static docCommentTagName: string;
}
const enum ClassificationType {
comment = 1,
@@ -1932,6 +1931,7 @@ declare module "typescript" {
typeParameterName = 15,
typeAliasName = 16,
parameterName = 17,
docCommentTagName = 18,
}
interface DisplayPartsSymbolWriter extends SymbolWriter {
displayParts(): SymbolDisplayPart[];
+518 -318
View File
File diff suppressed because it is too large Load Diff
+4 -4
View File
@@ -999,6 +999,7 @@ declare module ts {
UseOnlyExternalAliasing = 2,
}
const enum SymbolFlags {
None = 0,
FunctionScopedVariable = 1,
BlockScopedVariable = 2,
Property = 4,
@@ -1057,10 +1058,8 @@ declare module ts {
AliasExcludes = 8388608,
ModuleMember = 8914931,
ExportHasLocal = 944,
HasLocals = 255504,
HasExports = 1952,
HasMembers = 6240,
IsContainer = 262128,
PropertyOrAccessor = 98308,
Export = 7340032,
}
@@ -1068,9 +1067,9 @@ declare module ts {
flags: SymbolFlags;
name: string;
declarations?: Declaration[];
valueDeclaration?: Declaration;
members?: SymbolTable;
exports?: SymbolTable;
valueDeclaration?: Declaration;
}
interface SymbolTable {
[index: string]: Symbol;
@@ -1358,7 +1357,6 @@ declare module ts {
function getTypeParameterOwner(d: Declaration): Declaration;
}
declare module ts {
var throwOnJSDocErrors: boolean;
function getNodeConstructor(kind: SyntaxKind): new () => Node;
function createNode(kind: SyntaxKind): Node;
function forEachChild<T>(node: Node, cbNode: (node: Node) => T, cbNodeArray?: (nodes: Node[]) => T): T;
@@ -1913,6 +1911,7 @@ declare module ts {
static typeParameterName: string;
static typeAliasName: string;
static parameterName: string;
static docCommentTagName: string;
}
const enum ClassificationType {
comment = 1,
@@ -1932,6 +1931,7 @@ declare module ts {
typeParameterName = 15,
typeAliasName = 16,
parameterName = 17,
docCommentTagName = 18,
}
interface DisplayPartsSymbolWriter extends SymbolWriter {
displayParts(): SymbolDisplayPart[];
+518 -318
View File
File diff suppressed because it is too large Load Diff
+76 -73
View File
@@ -1485,7 +1485,7 @@ module ts {
return appendParentTypeArgumentsAndSymbolName(symbol);
}
function buildTypeDisplay(type: Type, writer: SymbolWriter, enclosingDeclaration?: Node, globalFlags?: TypeFormatFlags, typeStack?: Type[]) {
function buildTypeDisplay(type: Type, writer: SymbolWriter, enclosingDeclaration?: Node, globalFlags?: TypeFormatFlags, symbolStack?: Symbol[]) {
let globalFlagsToPass = globalFlags & TypeFormatFlags.WriteOwnNameForAnyLike;
return writeType(type, globalFlags);
@@ -1608,49 +1608,54 @@ module ts {
}
function writeAnonymousType(type: ObjectType, flags: TypeFormatFlags) {
// Always use 'typeof T' for type of class, enum, and module objects
if (type.symbol && type.symbol.flags & (SymbolFlags.Class | SymbolFlags.Enum | SymbolFlags.ValueModule)) {
writeTypeofSymbol(type, flags);
}
// Use 'typeof T' for types of functions and methods that circularly reference themselves
else if (shouldWriteTypeOfFunctionSymbol()) {
writeTypeofSymbol(type, flags);
}
else if (typeStack && contains(typeStack, type)) {
// If type is an anonymous type literal in a type alias declaration, use type alias name
let 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);
let 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)) {
writeTypeofSymbol(type, flags);
}
else if (shouldWriteTypeOfFunctionSymbol()) {
writeTypeofSymbol(type, flags);
}
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);
if (typeAlias) {
// The specified symbol flags need to be reinterpreted as type flags
buildSymbolDisplay(typeAlias, writer, enclosingDeclaration, SymbolFlags.Type, SymbolFormatFlags.None, flags);
}
else {
// Recursive usage, use any
writeKeyword(writer, SyntaxKind.AnyKeyword);
}
}
else {
// Recursive usage, use any
writeKeyword(writer, SyntaxKind.AnyKeyword);
// Since instantiations of the same anonymous type have the same symbol, tracking symbols instead
// of types allows us to catch circular references to instantiations of the same anonymous type
if (!symbolStack) {
symbolStack = [];
}
symbolStack.push(symbol);
writeLiteralType(type, flags);
symbolStack.pop();
}
}
else {
if (!typeStack) {
typeStack = [];
}
typeStack.push(type);
// Anonymous types with no symbol are never circular
writeLiteralType(type, flags);
typeStack.pop();
}
function shouldWriteTypeOfFunctionSymbol() {
if (type.symbol) {
let isStaticMethodSymbol = !!(type.symbol.flags & SymbolFlags.Method && // typeof static method
ts.forEach(type.symbol.declarations, declaration => declaration.flags & NodeFlags.Static));
let isNonLocalFunctionSymbol = !!(type.symbol.flags & SymbolFlags.Function) &&
(type.symbol.parent || // is exported function symbol
ts.forEach(type.symbol.declarations, declaration =>
declaration.parent.kind === SyntaxKind.SourceFile || declaration.parent.kind === SyntaxKind.ModuleBlock));
if (isStaticMethodSymbol || isNonLocalFunctionSymbol) {
// typeof is allowed only for static/non local functions
return !!(flags & TypeFormatFlags.UseTypeOfFunction) || // use typeof if format flags specify it
(typeStack && contains(typeStack, type)); // it is type of the symbol uses itself recursively
}
let isStaticMethodSymbol = !!(symbol.flags & SymbolFlags.Method && // typeof static method
forEach(symbol.declarations, declaration => declaration.flags & NodeFlags.Static));
let 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));
if (isStaticMethodSymbol || isNonLocalFunctionSymbol) {
// typeof is allowed only for static/non local functions
return !!(flags & TypeFormatFlags.UseTypeOfFunction) || // use typeof if format flags specify it
(contains(symbolStack, symbol)); // it is type of the symbol uses itself recursively
}
}
}
@@ -1685,7 +1690,7 @@ module ts {
if (flags & TypeFormatFlags.InElementType) {
writePunctuation(writer, SyntaxKind.OpenParenToken);
}
buildSignatureDisplay(resolved.callSignatures[0], writer, enclosingDeclaration, globalFlagsToPass | TypeFormatFlags.WriteArrowStyleSignature, typeStack);
buildSignatureDisplay(resolved.callSignatures[0], writer, enclosingDeclaration, globalFlagsToPass | TypeFormatFlags.WriteArrowStyleSignature, symbolStack);
if (flags & TypeFormatFlags.InElementType) {
writePunctuation(writer, SyntaxKind.CloseParenToken);
}
@@ -1697,7 +1702,7 @@ module ts {
}
writeKeyword(writer, SyntaxKind.NewKeyword);
writeSpace(writer);
buildSignatureDisplay(resolved.constructSignatures[0], writer, enclosingDeclaration, globalFlagsToPass | TypeFormatFlags.WriteArrowStyleSignature, typeStack);
buildSignatureDisplay(resolved.constructSignatures[0], writer, enclosingDeclaration, globalFlagsToPass | TypeFormatFlags.WriteArrowStyleSignature, symbolStack);
if (flags & TypeFormatFlags.InElementType) {
writePunctuation(writer, SyntaxKind.CloseParenToken);
}
@@ -1709,7 +1714,7 @@ module ts {
writer.writeLine();
writer.increaseIndent();
for (let signature of resolved.callSignatures) {
buildSignatureDisplay(signature, writer, enclosingDeclaration, globalFlagsToPass, typeStack);
buildSignatureDisplay(signature, writer, enclosingDeclaration, globalFlagsToPass, symbolStack);
writePunctuation(writer, SyntaxKind.SemicolonToken);
writer.writeLine();
}
@@ -1717,7 +1722,7 @@ module ts {
writeKeyword(writer, SyntaxKind.NewKeyword);
writeSpace(writer);
buildSignatureDisplay(signature, writer, enclosingDeclaration, globalFlagsToPass, typeStack);
buildSignatureDisplay(signature, writer, enclosingDeclaration, globalFlagsToPass, symbolStack);
writePunctuation(writer, SyntaxKind.SemicolonToken);
writer.writeLine();
}
@@ -1758,7 +1763,7 @@ module ts {
if (p.flags & SymbolFlags.Optional) {
writePunctuation(writer, SyntaxKind.QuestionToken);
}
buildSignatureDisplay(signature, writer, enclosingDeclaration, globalFlagsToPass, typeStack);
buildSignatureDisplay(signature, writer, enclosingDeclaration, globalFlagsToPass, symbolStack);
writePunctuation(writer, SyntaxKind.SemicolonToken);
writer.writeLine();
}
@@ -1787,18 +1792,18 @@ module ts {
}
}
function buildTypeParameterDisplay(tp: TypeParameter, writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags, typeStack?: Type[]) {
function buildTypeParameterDisplay(tp: TypeParameter, writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags, symbolStack?: Symbol[]) {
appendSymbolNameOnly(tp.symbol, writer);
let constraint = getConstraintOfTypeParameter(tp);
if (constraint) {
writeSpace(writer);
writeKeyword(writer, SyntaxKind.ExtendsKeyword);
writeSpace(writer);
buildTypeDisplay(constraint, writer, enclosingDeclaration, flags, typeStack);
buildTypeDisplay(constraint, writer, enclosingDeclaration, flags, symbolStack);
}
}
function buildParameterDisplay(p: Symbol, writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags, typeStack?: Type[]) {
function buildParameterDisplay(p: Symbol, writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags, symbolStack?: Symbol[]) {
let parameterNode = <ParameterDeclaration>p.valueDeclaration;
if (isRestParameter(parameterNode)) {
writePunctuation(writer, SyntaxKind.DotDotDotToken);
@@ -1810,10 +1815,10 @@ module ts {
writePunctuation(writer, SyntaxKind.ColonToken);
writeSpace(writer);
buildTypeDisplay(getTypeOfSymbol(p), writer, enclosingDeclaration, flags, typeStack);
buildTypeDisplay(getTypeOfSymbol(p), writer, enclosingDeclaration, flags, symbolStack);
}
function buildDisplayForTypeParametersAndDelimiters(typeParameters: TypeParameter[], writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags, typeStack?: Type[]) {
function buildDisplayForTypeParametersAndDelimiters(typeParameters: TypeParameter[], writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags, symbolStack?: Symbol[]) {
if (typeParameters && typeParameters.length) {
writePunctuation(writer, SyntaxKind.LessThanToken);
for (let i = 0; i < typeParameters.length; i++) {
@@ -1821,13 +1826,13 @@ module ts {
writePunctuation(writer, SyntaxKind.CommaToken);
writeSpace(writer);
}
buildTypeParameterDisplay(typeParameters[i], writer, enclosingDeclaration, flags, typeStack);
buildTypeParameterDisplay(typeParameters[i], writer, enclosingDeclaration, flags, symbolStack);
}
writePunctuation(writer, SyntaxKind.GreaterThanToken);
}
}
function buildDisplayForTypeArgumentsAndDelimiters(typeParameters: TypeParameter[], mapper: TypeMapper, writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags, typeStack?: Type[]) {
function buildDisplayForTypeArgumentsAndDelimiters(typeParameters: TypeParameter[], mapper: TypeMapper, writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags, symbolStack?: Symbol[]) {
if (typeParameters && typeParameters.length) {
writePunctuation(writer, SyntaxKind.LessThanToken);
for (let i = 0; i < typeParameters.length; i++) {
@@ -1841,19 +1846,19 @@ module ts {
}
}
function buildDisplayForParametersAndDelimiters(parameters: Symbol[], writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags, typeStack?: Type[]) {
function buildDisplayForParametersAndDelimiters(parameters: Symbol[], writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags, symbolStack?: Symbol[]) {
writePunctuation(writer, SyntaxKind.OpenParenToken);
for (let i = 0; i < parameters.length; i++) {
if (i > 0) {
writePunctuation(writer, SyntaxKind.CommaToken);
writeSpace(writer);
}
buildParameterDisplay(parameters[i], writer, enclosingDeclaration, flags, typeStack);
buildParameterDisplay(parameters[i], writer, enclosingDeclaration, flags, symbolStack);
}
writePunctuation(writer, SyntaxKind.CloseParenToken);
}
function buildReturnTypeDisplay(signature: Signature, writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags, typeStack?: Type[]) {
function buildReturnTypeDisplay(signature: Signature, writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags, symbolStack?: Symbol[]) {
if (flags & TypeFormatFlags.WriteArrowStyleSignature) {
writeSpace(writer);
writePunctuation(writer, SyntaxKind.EqualsGreaterThanToken);
@@ -1862,21 +1867,21 @@ module ts {
writePunctuation(writer, SyntaxKind.ColonToken);
}
writeSpace(writer);
buildTypeDisplay(getReturnTypeOfSignature(signature), writer, enclosingDeclaration, flags, typeStack);
buildTypeDisplay(getReturnTypeOfSignature(signature), writer, enclosingDeclaration, flags, symbolStack);
}
function buildSignatureDisplay(signature: Signature, writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags, typeStack?: Type[]) {
function buildSignatureDisplay(signature: Signature, writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags, symbolStack?: Symbol[]) {
if (signature.target && (flags & TypeFormatFlags.WriteTypeArgumentsOfSignature)) {
// Instantiated signature, write type arguments instead
// This is achieved by passing in the mapper separately
buildDisplayForTypeArgumentsAndDelimiters(signature.target.typeParameters, signature.mapper, writer, enclosingDeclaration);
}
else {
buildDisplayForTypeParametersAndDelimiters(signature.typeParameters, writer, enclosingDeclaration, flags, typeStack);
buildDisplayForTypeParametersAndDelimiters(signature.typeParameters, writer, enclosingDeclaration, flags, symbolStack);
}
buildDisplayForParametersAndDelimiters(signature.parameters, writer, enclosingDeclaration, flags, typeStack);
buildReturnTypeDisplay(signature, writer, enclosingDeclaration, flags, typeStack);
buildDisplayForParametersAndDelimiters(signature.parameters, writer, enclosingDeclaration, flags, symbolStack);
buildReturnTypeDisplay(signature, writer, enclosingDeclaration, flags, symbolStack);
}
return _displayBuilder || (_displayBuilder = {
@@ -2373,7 +2378,7 @@ module ts {
// Variable has initializer that circularly references the variable itself
type = anyType;
if (compilerOptions.noImplicitAny) {
error(symbol.valueDeclaration, Diagnostics._0_implicitly_has_type_any_because_it_is_does_not_have_a_type_annotation_and_is_referenced_directly_or_indirectly_in_its_own_initializer,
error(symbol.valueDeclaration, Diagnostics._0_implicitly_has_type_any_because_it_does_not_have_a_type_annotation_and_is_referenced_directly_or_indirectly_in_its_own_initializer,
symbolToString(symbol));
}
}
@@ -3996,19 +4001,8 @@ module ts {
}
function instantiateAnonymousType(type: ObjectType, mapper: TypeMapper): ObjectType {
// If this type has already been instantiated using this mapper, returned the cached result. This guards against
// infinite instantiations of cyclic types, e.g. "var x: { a: T, b: typeof x };"
if (mapper.mappings) {
let cached = <ObjectType>mapper.mappings[type.id];
if (cached) {
return cached;
}
}
else {
mapper.mappings = {};
}
// Instantiate the given type using the given mapper and cache the result
let result = <ResolvedType>createObjectType(TypeFlags.Anonymous, type.symbol);
// Mark the anonymous type as instantiated such that our infinite instantiation detection logic can recognize it
let result = <ResolvedType>createObjectType(TypeFlags.Anonymous | TypeFlags.Instantiated, type.symbol);
result.properties = instantiateList(getPropertiesOfObjectType(type), mapper, instantiateSymbol);
result.members = createSymbolTable(result.properties);
result.callSignatures = instantiateList(getSignaturesOfType(type, SignatureKind.Call), mapper, instantiateSignature);
@@ -4017,7 +4011,6 @@ module ts {
let numberIndexType = getIndexTypeOfType(type, IndexKind.Number);
if (stringIndexType) result.stringIndexType = instantiateType(stringIndexType, mapper);
if (numberIndexType) result.numberIndexType = instantiateType(numberIndexType, mapper);
mapper.mappings[type.id] = result;
return result;
}
@@ -4432,12 +4425,13 @@ module ts {
// Effectively, we will generate a false positive when two types are structurally equal to at least 10 levels, but unequal at
// some level beyond that.
function isDeeplyNestedGeneric(type: ObjectType, stack: ObjectType[]): boolean {
if (type.flags & TypeFlags.Reference && depth >= 10) {
let target = (<TypeReference>type).target;
// We track type references (created by createTypeReference) and instantiated types (created by instantiateType)
if (type.flags & (TypeFlags.Reference | TypeFlags.Instantiated) && depth >= 10) {
let symbol = type.symbol;
let count = 0;
for (let i = 0; i < depth; i++) {
let t = stack[i];
if (t.flags & TypeFlags.Reference && (<TypeReference>t).target === target) {
if (t.flags & (TypeFlags.Reference | TypeFlags.Instantiated) && t.symbol === symbol) {
count++;
if (count >= 10) return true;
}
@@ -7657,6 +7651,15 @@ module ts {
}
if (node.body) {
if (!node.type) {
// There are some checks that are only performed in getReturnTypeFromBody, that may produce errors
// we need. An example is the noImplicitAny errors resulting from widening the return expression
// of a function. Because checking of function expression bodies is deferred, there was never an
// appropriate time to do this during the main walk of the file (see the comment at the top of
// checkFunctionExpressionBodies). So it must be done now.
getReturnTypeOfSignature(getSignatureFromDeclaration(node));
}
if (node.body.kind === SyntaxKind.Block) {
checkSourceElement(node.body);
}
@@ -529,7 +529,7 @@ module ts {
Object_literal_s_property_0_implicitly_has_an_1_type: { code: 7018, category: DiagnosticCategory.Error, key: "Object literal's property '{0}' implicitly has an '{1}' type." },
Rest_parameter_0_implicitly_has_an_any_type: { code: 7019, category: DiagnosticCategory.Error, key: "Rest parameter '{0}' implicitly has an 'any[]' type." },
Call_signature_which_lacks_return_type_annotation_implicitly_has_an_any_return_type: { code: 7020, category: DiagnosticCategory.Error, key: "Call signature, which lacks return-type annotation, implicitly has an 'any' return type." },
_0_implicitly_has_type_any_because_it_is_does_not_have_a_type_annotation_and_is_referenced_directly_or_indirectly_in_its_own_initializer: { code: 7022, category: DiagnosticCategory.Error, key: "'{0}' implicitly has type 'any' because it is does not have a type annotation and is referenced directly or indirectly in its own initializer." },
_0_implicitly_has_type_any_because_it_does_not_have_a_type_annotation_and_is_referenced_directly_or_indirectly_in_its_own_initializer: { code: 7022, category: DiagnosticCategory.Error, key: "'{0}' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer." },
_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: { code: 7023, category: DiagnosticCategory.Error, key: "'{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." },
Function_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: { code: 7024, category: DiagnosticCategory.Error, key: "Function 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." },
Generator_implicitly_has_type_0_because_it_does_not_yield_any_values_Consider_supplying_a_return_type: { code: 7025, category: DiagnosticCategory.Error, key: "Generator implicitly has type '{0}' because it does not yield any values. Consider supplying a return type." },
+1 -1
View File
@@ -2107,7 +2107,7 @@
"category": "Error",
"code": 7020
},
"'{0}' implicitly has type 'any' because it is does not have a type annotation and is referenced directly or indirectly in its own initializer.": {
"'{0}' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.": {
"category": "Error",
"code": 7022
},
+8 -8
View File
@@ -1582,14 +1582,15 @@ module ts {
Tuple = 0x00002000, // Tuple
Union = 0x00004000, // Union
Anonymous = 0x00008000, // Anonymous
Instantiated = 0x00010000, // Instantiated anonymous type
/* @internal */
FromSignature = 0x00010000, // Created for signature assignment check
ObjectLiteral = 0x00020000, // Originates in an object literal
FromSignature = 0x00020000, // Created for signature assignment check
ObjectLiteral = 0x00040000, // Originates in an object literal
/* @internal */
ContainsUndefinedOrNull = 0x00040000, // Type is or contains Undefined or Null type
ContainsUndefinedOrNull = 0x00080000, // Type is or contains Undefined or Null type
/* @internal */
ContainsObjectLiteral = 0x00080000, // Type is or contains object literal type
ESSymbol = 0x00100000, // Type of symbol primitive introduced in ES6
ContainsObjectLiteral = 0x00100000, // Type is or contains object literal type
ESSymbol = 0x00200000, // Type of symbol primitive introduced in ES6
/* @internal */
Intrinsic = Any | String | Number | Boolean | ESSymbol | Void | Undefined | Null,
@@ -1674,8 +1675,8 @@ module ts {
properties: Symbol[]; // Properties
callSignatures: Signature[]; // Call signatures of type
constructSignatures: Signature[]; // Construct signatures of type
stringIndexType: Type; // String index type
numberIndexType: Type; // Numeric index type
stringIndexType?: Type; // String index type
numberIndexType?: Type; // Numeric index type
}
// Just a place to cache element types of iterables and iterators
@@ -1731,7 +1732,6 @@ module ts {
/* @internal */
export interface TypeMapper {
(t: TypeParameter): Type;
mappings?: Map<Type>; // Type mapping cache
}
/* @internal */
@@ -0,0 +1,37 @@
//// [cyclicGenericTypeInstantiation.ts]
function foo<T>() {
var z = foo<typeof y>();
var y: {
y2: typeof z
};
return y;
}
function bar<T>() {
var z = bar<typeof y>();
var y: {
y2: typeof z;
}
return y;
}
var a = foo<number>();
var b = bar<number>();
a = b;
//// [cyclicGenericTypeInstantiation.js]
function foo() {
var z = foo();
var y;
return y;
}
function bar() {
var z = bar();
var y;
return y;
}
var a = foo();
var b = bar();
a = b;
@@ -0,0 +1,55 @@
=== tests/cases/compiler/cyclicGenericTypeInstantiation.ts ===
function foo<T>() {
>foo : Symbol(foo, Decl(cyclicGenericTypeInstantiation.ts, 0, 0))
>T : Symbol(T, Decl(cyclicGenericTypeInstantiation.ts, 0, 13))
var z = foo<typeof y>();
>z : Symbol(z, Decl(cyclicGenericTypeInstantiation.ts, 1, 7))
>foo : Symbol(foo, Decl(cyclicGenericTypeInstantiation.ts, 0, 0))
>y : Symbol(y, Decl(cyclicGenericTypeInstantiation.ts, 2, 7))
var y: {
>y : Symbol(y, Decl(cyclicGenericTypeInstantiation.ts, 2, 7))
y2: typeof z
>y2 : Symbol(y2, Decl(cyclicGenericTypeInstantiation.ts, 2, 12))
>z : Symbol(z, Decl(cyclicGenericTypeInstantiation.ts, 1, 7))
};
return y;
>y : Symbol(y, Decl(cyclicGenericTypeInstantiation.ts, 2, 7))
}
function bar<T>() {
>bar : Symbol(bar, Decl(cyclicGenericTypeInstantiation.ts, 6, 1))
>T : Symbol(T, Decl(cyclicGenericTypeInstantiation.ts, 9, 13))
var z = bar<typeof y>();
>z : Symbol(z, Decl(cyclicGenericTypeInstantiation.ts, 10, 7))
>bar : Symbol(bar, Decl(cyclicGenericTypeInstantiation.ts, 6, 1))
>y : Symbol(y, Decl(cyclicGenericTypeInstantiation.ts, 11, 7))
var y: {
>y : Symbol(y, Decl(cyclicGenericTypeInstantiation.ts, 11, 7))
y2: typeof z;
>y2 : Symbol(y2, Decl(cyclicGenericTypeInstantiation.ts, 11, 12))
>z : Symbol(z, Decl(cyclicGenericTypeInstantiation.ts, 10, 7))
}
return y;
>y : Symbol(y, Decl(cyclicGenericTypeInstantiation.ts, 11, 7))
}
var a = foo<number>();
>a : Symbol(a, Decl(cyclicGenericTypeInstantiation.ts, 17, 3))
>foo : Symbol(foo, Decl(cyclicGenericTypeInstantiation.ts, 0, 0))
var b = bar<number>();
>b : Symbol(b, Decl(cyclicGenericTypeInstantiation.ts, 18, 3))
>bar : Symbol(bar, Decl(cyclicGenericTypeInstantiation.ts, 6, 1))
a = b;
>a : Symbol(a, Decl(cyclicGenericTypeInstantiation.ts, 17, 3))
>b : Symbol(b, Decl(cyclicGenericTypeInstantiation.ts, 18, 3))
@@ -0,0 +1,60 @@
=== tests/cases/compiler/cyclicGenericTypeInstantiation.ts ===
function foo<T>() {
>foo : <T>() => { y2: any; }
>T : T
var z = foo<typeof y>();
>z : { y2: any; }
>foo<typeof y>() : { y2: any; }
>foo : <T>() => { y2: any; }
>y : { y2: any; }
var y: {
>y : { y2: any; }
y2: typeof z
>y2 : { y2: any; }
>z : { y2: any; }
};
return y;
>y : { y2: any; }
}
function bar<T>() {
>bar : <T>() => { y2: any; }
>T : T
var z = bar<typeof y>();
>z : { y2: any; }
>bar<typeof y>() : { y2: any; }
>bar : <T>() => { y2: any; }
>y : { y2: any; }
var y: {
>y : { y2: any; }
y2: typeof z;
>y2 : { y2: any; }
>z : { y2: any; }
}
return y;
>y : { y2: any; }
}
var a = foo<number>();
>a : { y2: any; }
>foo<number>() : { y2: any; }
>foo : <T>() => { y2: any; }
var b = bar<number>();
>b : { y2: any; }
>bar<number>() : { y2: any; }
>bar : <T>() => { y2: any; }
a = b;
>a = b : { y2: any; }
>a : { y2: any; }
>b : { y2: any; }
@@ -1,7 +1,7 @@
tests/cases/conformance/es6/for-ofStatements/for-of32.ts(1,10): error TS7022: 'v' implicitly has type 'any' because it is does not have a type annotation and is referenced directly or indirectly in its own initializer.
tests/cases/conformance/es6/for-ofStatements/for-of32.ts(1,10): error TS7022: 'v' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.
==== tests/cases/conformance/es6/for-ofStatements/for-of32.ts (1 errors) ====
for (var v of v) { }
~
!!! error TS7022: 'v' implicitly has type 'any' because it is does not have a type annotation and is referenced directly or indirectly in its own initializer.
!!! error TS7022: 'v' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.
@@ -1,11 +1,11 @@
tests/cases/conformance/es6/for-ofStatements/for-of33.ts(1,10): error TS7022: 'v' implicitly has type 'any' because it is does not have a type annotation and is referenced directly or indirectly in its own initializer.
tests/cases/conformance/es6/for-ofStatements/for-of33.ts(1,10): error TS7022: 'v' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.
tests/cases/conformance/es6/for-ofStatements/for-of33.ts(4,5): error TS7023: '[Symbol.iterator]' 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.
==== tests/cases/conformance/es6/for-ofStatements/for-of33.ts (2 errors) ====
for (var v of new StringIterator) { }
~
!!! error TS7022: 'v' implicitly has type 'any' because it is does not have a type annotation and is referenced directly or indirectly in its own initializer.
!!! error TS7022: 'v' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.
class StringIterator {
[Symbol.iterator]() {
@@ -1,11 +1,11 @@
tests/cases/conformance/es6/for-ofStatements/for-of34.ts(1,10): error TS7022: 'v' implicitly has type 'any' because it is does not have a type annotation and is referenced directly or indirectly in its own initializer.
tests/cases/conformance/es6/for-ofStatements/for-of34.ts(1,10): error TS7022: 'v' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.
tests/cases/conformance/es6/for-ofStatements/for-of34.ts(4,5): error TS7023: 'next' 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.
==== tests/cases/conformance/es6/for-ofStatements/for-of34.ts (2 errors) ====
for (var v of new StringIterator) { }
~
!!! error TS7022: 'v' implicitly has type 'any' because it is does not have a type annotation and is referenced directly or indirectly in its own initializer.
!!! error TS7022: 'v' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.
class StringIterator {
next() {
@@ -1,11 +1,11 @@
tests/cases/conformance/es6/for-ofStatements/for-of35.ts(1,10): error TS7022: 'v' implicitly has type 'any' because it is does not have a type annotation and is referenced directly or indirectly in its own initializer.
tests/cases/conformance/es6/for-ofStatements/for-of35.ts(1,10): error TS7022: 'v' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.
tests/cases/conformance/es6/for-ofStatements/for-of35.ts(4,5): error TS7023: 'next' 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.
==== tests/cases/conformance/es6/for-ofStatements/for-of35.ts (2 errors) ====
for (var v of new StringIterator) { }
~
!!! error TS7022: 'v' implicitly has type 'any' because it is does not have a type annotation and is referenced directly or indirectly in its own initializer.
!!! error TS7022: 'v' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.
class StringIterator {
next() {
@@ -7,7 +7,7 @@ tests/cases/compiler/implicitAnyFromCircularInference.ts(18,10): error TS7024: F
tests/cases/compiler/implicitAnyFromCircularInference.ts(23,10): error TS7024: Function 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.
tests/cases/compiler/implicitAnyFromCircularInference.ts(26,10): error TS7023: 'h' 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.
tests/cases/compiler/implicitAnyFromCircularInference.ts(28,14): error TS7023: 'foo' 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.
tests/cases/compiler/implicitAnyFromCircularInference.ts(41,5): error TS7022: 's' implicitly has type 'any' because it is does not have a type annotation and is referenced directly or indirectly in its own initializer.
tests/cases/compiler/implicitAnyFromCircularInference.ts(41,5): error TS7022: 's' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.
tests/cases/compiler/implicitAnyFromCircularInference.ts(46,5): error TS7023: 'x' 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.
@@ -72,7 +72,7 @@ tests/cases/compiler/implicitAnyFromCircularInference.ts(46,5): error TS7023: 'x
// Error expected
s = foo(this);
~~~~~~~~~~~~~~
!!! error TS7022: 's' implicitly has type 'any' because it is does not have a type annotation and is referenced directly or indirectly in its own initializer.
!!! error TS7022: 's' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.
}
class D {
@@ -1,12 +1,15 @@
tests/cases/compiler/multiLinePropertyAccessAndArrowFunctionIndent1.ts(1,1): error TS1108: A 'return' statement can only be used within a function body.
tests/cases/compiler/multiLinePropertyAccessAndArrowFunctionIndent1.ts(1,18): error TS2304: Cannot find name 'role'.
tests/cases/compiler/multiLinePropertyAccessAndArrowFunctionIndent1.ts(2,18): error TS2304: Cannot find name 'Role'.
tests/cases/compiler/multiLinePropertyAccessAndArrowFunctionIndent1.ts(4,26): error TS2503: Cannot find namespace 'ng'.
==== tests/cases/compiler/multiLinePropertyAccessAndArrowFunctionIndent1.ts (3 errors) ====
==== tests/cases/compiler/multiLinePropertyAccessAndArrowFunctionIndent1.ts (4 errors) ====
return this.edit(role)
~~~~~~
!!! error TS1108: A 'return' statement can only be used within a function body.
~~~~
!!! error TS2304: Cannot find name 'role'.
.then((role: Role) =>
~~~~
!!! error TS2304: Cannot find name 'Role'.
@@ -0,0 +1,7 @@
tests/cases/compiler/typeCheckObjectLiteralMethodBody.ts(1,13): error TS7010: 'bar', which lacks return-type annotation, implicitly has an 'any' return type.
==== tests/cases/compiler/typeCheckObjectLiteralMethodBody.ts (1 errors) ====
var foo = { bar() { return undefined } };
~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS7010: 'bar', which lacks return-type annotation, implicitly has an 'any' return type.
@@ -0,0 +1,5 @@
//// [typeCheckObjectLiteralMethodBody.ts]
var foo = { bar() { return undefined } };
//// [typeCheckObjectLiteralMethodBody.js]
var foo = { bar: function () { return undefined; } };
@@ -0,0 +1,7 @@
tests/cases/compiler/typeCheckReturnExpression.ts(1,11): error TS7011: Function expression, which lacks return-type annotation, implicitly has an 'any' return type.
==== tests/cases/compiler/typeCheckReturnExpression.ts (1 errors) ====
var foo = () => undefined;
~~~~~~~~~~~~~~~
!!! error TS7011: Function expression, which lacks return-type annotation, implicitly has an 'any' return type.
@@ -0,0 +1,5 @@
//// [typeCheckReturnExpression.ts]
var foo = () => undefined;
//// [typeCheckReturnExpression.js]
var foo = function () { return undefined; };
@@ -0,0 +1,20 @@
function foo<T>() {
var z = foo<typeof y>();
var y: {
y2: typeof z
};
return y;
}
function bar<T>() {
var z = bar<typeof y>();
var y: {
y2: typeof z;
}
return y;
}
var a = foo<number>();
var b = bar<number>();
a = b;
@@ -0,0 +1,2 @@
//@noImplicitAny: true
var foo = { bar() { return undefined } };
@@ -0,0 +1,2 @@
//@noImplicitAny: true
var foo = () => undefined;