Merge branch 'master' into truncateTypesInErrors

Conflicts:
	src/compiler/checker.ts
This commit is contained in:
Anders Hejlsberg
2014-09-09 13:51:08 -07:00
52 changed files with 2480 additions and 1117 deletions
+57 -52
View File
@@ -3807,30 +3807,42 @@ declare var Window: {
new(): Window;
}
interface FormData {
append(name: any, value: any, blobName?: string): void;
interface HTMLCollection extends MSHTMLCollectionExtensions {
/**
* Sets or retrieves the number of objects in a collection.
*/
length: number;
/**
* Retrieves an object from various collections.
*/
item(nameOrIndex?: any, optionalIndex?: any): Element;
/**
* Retrieves a select object or an object from an options collection.
*/
namedItem(name: string): Element;
// [name: string]: Element;
[index: number]: Element;
}
declare var FormData: {
prototype: FormData;
new (form?: HTMLFormElement): FormData;
declare var HTMLCollection: {
prototype: HTMLCollection;
new(): HTMLCollection;
}
interface SourceBuffer extends EventTarget {
updating: boolean;
appendWindowStart: number;
appendWindowEnd: number;
buffered: TimeRanges;
timestampOffset: number;
audioTracks: AudioTrackList;
appendBuffer(data: ArrayBufferView): void;
appendBuffer(data: ArrayBuffer): void;
remove(start: number, end: number): void;
abort(): void;
appendStream(stream: MSStream, maxSize?: number): void;
interface BlobPropertyBag {
type?: string;
endings?: string;
}
declare var SourceBuffer: {
prototype: SourceBuffer;
new(): SourceBuffer;
interface Blob {
type: string;
size: number;
msDetachStream(): any;
slice(start?: number, end?: number, contentType?: string): Blob;
msClose(): void;
}
declare var Blob: {
prototype: Blob;
new (blobParts?: any[], options?: BlobPropertyBag): Blob;
}
interface NavigatorID {
@@ -5739,26 +5751,6 @@ declare var MSCSSProperties: {
new(): MSCSSProperties;
}
interface HTMLCollection extends MSHTMLCollectionExtensions {
/**
* Sets or retrieves the number of objects in a collection.
*/
length: number;
/**
* Retrieves an object from various collections.
*/
item(nameOrIndex?: any, optionalIndex?: any): Element;
/**
* Retrieves a select object or an object from an options collection.
*/
namedItem(name: string): Element;
// [name: string]: Element;
}
declare var HTMLCollection: {
prototype: HTMLCollection;
new(): HTMLCollection;
}
interface SVGExternalResourcesRequired {
externalResourcesRequired: SVGAnimatedBoolean;
}
@@ -11994,18 +11986,6 @@ declare var FileReader: {
new(): FileReader;
}
interface Blob {
type: string;
size: number;
msDetachStream(): any;
slice(start?: number, end?: number, contentType?: string): Blob;
msClose(): void;
}
declare var Blob: {
prototype: Blob;
new(): Blob;
}
interface ApplicationCache extends EventTarget {
status: number;
ondownloading: (ev: Event) => any;
@@ -12164,6 +12144,14 @@ declare var MSManipulationEvent: {
MS_MANIPULATION_STATE_CANCELLED: number;
}
interface FormData {
append(name: any, value: any, blobName?: string): void;
}
declare var FormData: {
prototype: FormData;
new(): FormData;
}
interface HTMLDataListElement extends HTMLElement {
options: HTMLCollection;
}
@@ -12582,6 +12570,23 @@ interface RandomSource {
getRandomValues(array: ArrayBufferView): ArrayBufferView;
}
interface SourceBuffer extends EventTarget {
updating: boolean;
appendWindowStart: number;
appendWindowEnd: number;
buffered: TimeRanges;
timestampOffset: number;
audioTracks: AudioTrackList;
appendBuffer(data: ArrayBuffer): void;
remove(start: number, end: number): void;
abort(): void;
appendStream(stream: MSStream, maxSize?: number): void;
}
declare var SourceBuffer: {
prototype: SourceBuffer;
new(): SourceBuffer;
}
interface MSInputMethodContext extends EventTarget {
oncandidatewindowshow: (ev: any) => any;
target: HTMLElement;
+57 -52
View File
@@ -2704,30 +2704,42 @@ declare var Window: {
new(): Window;
}
interface FormData {
append(name: any, value: any, blobName?: string): void;
interface HTMLCollection extends MSHTMLCollectionExtensions {
/**
* Sets or retrieves the number of objects in a collection.
*/
length: number;
/**
* Retrieves an object from various collections.
*/
item(nameOrIndex?: any, optionalIndex?: any): Element;
/**
* Retrieves a select object or an object from an options collection.
*/
namedItem(name: string): Element;
// [name: string]: Element;
[index: number]: Element;
}
declare var FormData: {
prototype: FormData;
new (form?: HTMLFormElement): FormData;
declare var HTMLCollection: {
prototype: HTMLCollection;
new(): HTMLCollection;
}
interface SourceBuffer extends EventTarget {
updating: boolean;
appendWindowStart: number;
appendWindowEnd: number;
buffered: TimeRanges;
timestampOffset: number;
audioTracks: AudioTrackList;
appendBuffer(data: ArrayBufferView): void;
appendBuffer(data: ArrayBuffer): void;
remove(start: number, end: number): void;
abort(): void;
appendStream(stream: MSStream, maxSize?: number): void;
interface BlobPropertyBag {
type?: string;
endings?: string;
}
declare var SourceBuffer: {
prototype: SourceBuffer;
new(): SourceBuffer;
interface Blob {
type: string;
size: number;
msDetachStream(): any;
slice(start?: number, end?: number, contentType?: string): Blob;
msClose(): void;
}
declare var Blob: {
prototype: Blob;
new (blobParts?: any[], options?: BlobPropertyBag): Blob;
}
interface NavigatorID {
@@ -4636,26 +4648,6 @@ declare var MSCSSProperties: {
new(): MSCSSProperties;
}
interface HTMLCollection extends MSHTMLCollectionExtensions {
/**
* Sets or retrieves the number of objects in a collection.
*/
length: number;
/**
* Retrieves an object from various collections.
*/
item(nameOrIndex?: any, optionalIndex?: any): Element;
/**
* Retrieves a select object or an object from an options collection.
*/
namedItem(name: string): Element;
// [name: string]: Element;
}
declare var HTMLCollection: {
prototype: HTMLCollection;
new(): HTMLCollection;
}
interface SVGExternalResourcesRequired {
externalResourcesRequired: SVGAnimatedBoolean;
}
@@ -10891,18 +10883,6 @@ declare var FileReader: {
new(): FileReader;
}
interface Blob {
type: string;
size: number;
msDetachStream(): any;
slice(start?: number, end?: number, contentType?: string): Blob;
msClose(): void;
}
declare var Blob: {
prototype: Blob;
new(): Blob;
}
interface ApplicationCache extends EventTarget {
status: number;
ondownloading: (ev: Event) => any;
@@ -11061,6 +11041,14 @@ declare var MSManipulationEvent: {
MS_MANIPULATION_STATE_CANCELLED: number;
}
interface FormData {
append(name: any, value: any, blobName?: string): void;
}
declare var FormData: {
prototype: FormData;
new(): FormData;
}
interface HTMLDataListElement extends HTMLElement {
options: HTMLCollection;
}
@@ -11479,6 +11467,23 @@ interface RandomSource {
getRandomValues(array: ArrayBufferView): ArrayBufferView;
}
interface SourceBuffer extends EventTarget {
updating: boolean;
appendWindowStart: number;
appendWindowEnd: number;
buffered: TimeRanges;
timestampOffset: number;
audioTracks: AudioTrackList;
appendBuffer(data: ArrayBuffer): void;
remove(start: number, end: number): void;
abort(): void;
appendStream(stream: MSStream, maxSize?: number): void;
}
declare var SourceBuffer: {
prototype: SourceBuffer;
new(): SourceBuffer;
}
interface MSInputMethodContext extends EventTarget {
oncandidatewindowshow: (ev: any) => any;
target: HTMLElement;
+6 -1
View File
@@ -1453,6 +1453,11 @@ declare var FileReader: {
new(): FileReader;
}
interface BlobPropertyBag {
type?: string;
endings?: string;
}
interface Blob {
type: string;
size: number;
@@ -1462,7 +1467,7 @@ interface Blob {
}
declare var Blob: {
prototype: Blob;
new(): Blob;
new (blobParts?: any[], options?: BlobPropertyBag): Blob;
}
interface MSStream {
+344 -226
View File
@@ -267,6 +267,7 @@ var ts;
Import_name_cannot_be_0: { code: 2438, category: 1 /* Error */, key: "Import name cannot be '{0}'" },
Import_declaration_in_an_ambient_external_module_declaration_cannot_reference_external_module_through_relative_external_module_name: { code: 2439, category: 1 /* Error */, key: "Import declaration in an ambient external module declaration cannot reference external module through relative external module name." },
Import_declaration_conflicts_with_local_declaration_of_0: { code: 2440, category: 1 /* Error */, key: "Import declaration conflicts with local declaration of '{0}'" },
Duplicate_identifier_0_Compiler_reserves_name_1_in_top_level_scope_of_an_external_module: { code: 2441, category: 1 /* Error */, key: "Duplicate identifier '{0}'. Compiler reserves name '{1}' in top level scope of an external module." },
Import_declaration_0_is_using_private_name_1: { code: 4000, category: 1 /* Error */, key: "Import declaration '{0}' is using private name '{1}'." },
Type_parameter_0_of_exported_class_has_or_is_using_name_1_from_private_module_2: { code: 4001, category: 1 /* Error */, key: "Type parameter '{0}' of exported class has or is using name '{1}' from private module '{2}'." },
Type_parameter_0_of_exported_class_has_or_is_using_private_name_1: { code: 4002, category: 1 /* Error */, key: "Type parameter '{0}' of exported class has or is using private name '{1}'." },
@@ -566,7 +567,8 @@ var ts;
var pos = 0;
var lineStart = 0;
while (pos < text.length) {
switch (text.charCodeAt(pos++)) {
var ch = text.charCodeAt(pos++);
switch (ch) {
case 13 /* carriageReturn */:
if (text.charCodeAt(pos) === 10 /* lineFeed */) {
pos++;
@@ -575,6 +577,12 @@ var ts;
result.push(lineStart);
lineStart = pos;
break;
default:
if (ch > 127 /* maxAsciiCharacter */ && isLineBreak(ch)) {
result.push(lineStart);
lineStart = pos;
}
break;
}
}
result.push(lineStart);
@@ -608,7 +616,7 @@ var ts;
}
ts.isWhiteSpace = isWhiteSpace;
function isLineBreak(ch) {
return ch === 10 /* lineFeed */ || ch === 13 /* carriageReturn */ || ch === 8232 /* lineSeparator */ || ch === 8233 /* paragraphSeparator */;
return ch === 10 /* lineFeed */ || ch === 13 /* carriageReturn */ || ch === 8232 /* lineSeparator */ || ch === 8233 /* paragraphSeparator */ || ch === 133 /* nextLine */;
}
ts.isLineBreak = isLineBreak;
function isDigit(ch) {
@@ -748,6 +756,14 @@ var ts;
return getCommentRanges(text, pos, true);
}
ts.getTrailingComments = getTrailingComments;
function isIdentifierStart(ch, languageVersion) {
return ch >= 65 /* A */ && ch <= 90 /* Z */ || ch >= 97 /* a */ && ch <= 122 /* z */ || ch === 36 /* $ */ || ch === 95 /* _ */ || ch > 127 /* maxAsciiCharacter */ && isUnicodeIdentifierStart(ch, languageVersion);
}
ts.isIdentifierStart = isIdentifierStart;
function isIdentifierPart(ch, languageVersion) {
return ch >= 65 /* A */ && ch <= 90 /* Z */ || ch >= 97 /* a */ && ch <= 122 /* z */ || ch >= 48 /* _0 */ && ch <= 57 /* _9 */ || ch === 36 /* $ */ || ch === 95 /* _ */ || ch > 127 /* maxAsciiCharacter */ && isUnicodeIdentifierPart(ch, languageVersion);
}
ts.isIdentifierPart = isIdentifierPart;
function createScanner(languageVersion, text, onError, onComment) {
var pos;
var len;
@@ -2732,6 +2748,42 @@ var ts;
return false;
}
ts.isInAmbientContext = isInAmbientContext;
function isDeclaration(node) {
switch (node.kind) {
case 113 /* TypeParameter */:
case 114 /* Parameter */:
case 166 /* VariableDeclaration */:
case 115 /* Property */:
case 129 /* PropertyAssignment */:
case 176 /* EnumMember */:
case 116 /* Method */:
case 167 /* FunctionDeclaration */:
case 118 /* GetAccessor */:
case 119 /* SetAccessor */:
case 169 /* ClassDeclaration */:
case 170 /* InterfaceDeclaration */:
case 171 /* EnumDeclaration */:
case 172 /* ModuleDeclaration */:
case 174 /* ImportDeclaration */:
return true;
}
return false;
}
ts.isDeclaration = isDeclaration;
function isDeclarationOrFunctionExpressionOrCatchVariableName(name) {
if (name.kind !== 55 /* Identifier */ && name.kind !== 3 /* StringLiteral */ && name.kind !== 2 /* NumericLiteral */) {
return false;
}
var parent = name.parent;
if (isDeclaration(parent) || parent.kind === 136 /* FunctionExpression */) {
return parent.name === name;
}
if (parent.kind === 163 /* CatchBlock */) {
return parent.variable === name;
}
return false;
}
ts.isDeclarationOrFunctionExpressionOrCatchVariableName = isDeclarationOrFunctionExpressionOrCatchVariableName;
var ParsingContext;
(function (ParsingContext) {
ParsingContext[ParsingContext["SourceElements"] = 0] = "SourceElements";
@@ -2820,6 +2872,22 @@ var ts;
ControlBlockContext[ControlBlockContext["Nested"] = 1] = "Nested";
ControlBlockContext[ControlBlockContext["CrossingFunctionBoundary"] = 2] = "CrossingFunctionBoundary";
})(ControlBlockContext || (ControlBlockContext = {}));
function isKeyword(token) {
return ts.SyntaxKind.FirstKeyword <= token && token <= ts.SyntaxKind.LastKeyword;
}
ts.isKeyword = isKeyword;
function isModifier(token) {
switch (token) {
case 98 /* PublicKeyword */:
case 96 /* PrivateKeyword */:
case 99 /* StaticKeyword */:
case 68 /* ExportKeyword */:
case 104 /* DeclareKeyword */:
return true;
}
return false;
}
ts.isModifier = isModifier;
function createSourceFile(filename, sourceText, languageVersion, version, isOpen) {
if (isOpen === void 0) { isOpen = false; }
var file;
@@ -3054,12 +3122,15 @@ var ts;
function createMissingNode() {
return createNode(111 /* Missing */);
}
function internIdentifier(text) {
return ts.hasProperty(identifiers, text) ? identifiers[text] : (identifiers[text] = text);
}
function createIdentifier(isIdentifier) {
identifierCount++;
if (isIdentifier) {
var node = createNode(55 /* Identifier */);
var text = escapeIdentifier(scanner.getTokenValue());
node.text = ts.hasProperty(identifiers, text) ? identifiers[text] : (identifiers[text] = text);
node.text = internIdentifier(text);
nextToken();
return finishNode(node);
}
@@ -3077,24 +3148,10 @@ var ts;
}
function parsePropertyName() {
if (token === 3 /* StringLiteral */ || token === 2 /* NumericLiteral */) {
return parsePrimaryExpression();
return parseLiteralNode(true);
}
return parseIdentifierName();
}
function isKeyword(token) {
return ts.SyntaxKind.FirstKeyword <= token && token <= ts.SyntaxKind.LastKeyword;
}
function isModifier(token) {
switch (token) {
case 98 /* PublicKeyword */:
case 96 /* PrivateKeyword */:
case 99 /* StaticKeyword */:
case 68 /* ExportKeyword */:
case 104 /* DeclareKeyword */:
return true;
}
return false;
}
function parseContextualModifier(t) {
return token === t && tryParse(function () {
nextToken();
@@ -3309,9 +3366,10 @@ var ts;
nextToken();
return finishNode(node);
}
function parseLiteralNode() {
function parseLiteralNode(internName) {
var node = createNode(token);
node.text = scanner.getTokenValue();
var text = scanner.getTokenValue();
node.text = internName ? internIdentifier(text) : text;
var tokenPos = scanner.getTokenPos();
nextToken();
finishNode(node);
@@ -3327,7 +3385,7 @@ var ts;
}
function parseStringLiteral() {
if (token === 3 /* StringLiteral */)
return parseLiteralNode();
return parseLiteralNode(true);
error(ts.Diagnostics.String_literal_expected);
return createMissingNode();
}
@@ -3999,6 +4057,10 @@ var ts;
}
else {
indexedAccess.index = parseExpression();
if (indexedAccess.index.kind === 3 /* StringLiteral */ || indexedAccess.index.kind === 2 /* NumericLiteral */) {
var literal = indexedAccess.index;
literal.text = internIdentifier(literal.text);
}
parseExpected(10 /* CloseBracketToken */);
}
expr = finishNode(indexedAccess);
@@ -5304,6 +5366,7 @@ var ts;
file.version = version;
file.isOpen = isOpen;
file.languageVersion = languageVersion;
file.identifiers = identifiers;
return file;
}
ts.createSourceFile = createSourceFile;
@@ -5368,18 +5431,17 @@ var ts;
}
function findSourceFile(filename, isDefaultLib, refFile, refStart, refLength) {
var canonicalName = host.getCanonicalFileName(filename);
var file = getSourceFile(filename);
if (file) {
if (host.useCaseSensitiveFileNames() && canonicalName !== file.filename) {
if (ts.hasProperty(filesByName, canonicalName)) {
var file = filesByName[canonicalName];
if (file && host.useCaseSensitiveFileNames() && canonicalName !== file.filename) {
errors.push(ts.createFileDiagnostic(refFile, refStart, refLength, ts.Diagnostics.Filename_0_differs_from_already_included_filename_1_only_in_casing, filename, file.filename));
}
}
else {
file = host.getSourceFile(filename, options.target, function (hostErrorMessage) {
var file = filesByName[canonicalName] = host.getSourceFile(filename, options.target, function (hostErrorMessage) {
errors.push(ts.createFileDiagnostic(refFile, refStart, refLength, ts.Diagnostics.Cannot_read_file_0_Colon_1, filename, hostErrorMessage));
});
if (file) {
filesByName[host.getCanonicalFileName(filename)] = file;
seenNoDefaultLib = seenNoDefaultLib || file.hasNoDefaultLib;
if (!options.noResolve) {
var basePath = ts.getDirectoryPath(filename);
@@ -5904,18 +5966,10 @@ var ts;
function writeLiteral(s) {
if (s && s.length) {
write(s);
var pos = 0;
while (pos < s.length) {
switch (s.charCodeAt(pos++)) {
case 13 /* carriageReturn */:
if (pos < s.length && s.charCodeAt(pos) === 10 /* lineFeed */) {
pos++;
}
case 10 /* lineFeed */:
lineCount++;
linePos = output.length - s.length + pos;
break;
}
var lineStartsOfS = ts.getLineStarts(s);
if (lineStartsOfS.length > 1) {
lineCount = lineCount + lineStartsOfS.length - 1;
linePos = output.length - s.length + lineStartsOfS[lineStartsOfS.length - 1];
}
}
}
@@ -6026,10 +6080,9 @@ var ts;
}
function calculateIndent(pos, end) {
var currentLineIndent = 0;
while (pos < end && ts.isWhiteSpace(currentSourceFile.text.charCodeAt(pos))) {
pos++;
for (; pos < end && ts.isWhiteSpace(currentSourceFile.text.charCodeAt(pos)); pos++) {
if (currentSourceFile.text.charCodeAt(pos) === 9 /* tab */) {
currentLineIndent += getIndentSize();
currentLineIndent += getIndentSize() - (currentLineIndent % getIndentSize());
}
else {
currentLineIndent++;
@@ -7275,14 +7328,12 @@ var ts;
return emitPinnedOrTripleSlashComments(node);
}
emitLeadingComments(node);
if (!(node.flags & 1 /* Export */)) {
emitStart(node);
write("var ");
emit(node.name);
write(";");
emitEnd(node);
writeLine();
}
emitStart(node);
write("var ");
emit(node.name);
write(";");
emitEnd(node);
writeLine();
emitStart(node);
write("(function (");
emitStart(node.name);
@@ -7306,21 +7357,15 @@ var ts;
scopeEmitEnd();
}
write(")(");
if (node.flags & 1 /* Export */) {
emit(node.name);
write(" = ");
}
emitModuleMemberName(node);
write(" || (");
emitModuleMemberName(node);
write(" = {}));");
emitEnd(node);
if (node.flags & 1 /* Export */) {
writeLine();
emitStart(node);
write("var ");
emit(node.name);
write(" = ");
emitModuleMemberName(node);
emitEnd(node);
write(";");
}
emitTrailingComments(node);
}
function emitImportDeclaration(node) {
@@ -8327,39 +8372,43 @@ var ts;
}
}
function resolveScriptReference(sourceFile, reference) {
var referenceFileName = compilerOptions.noResolve ? reference.filename : ts.normalizePath(ts.combinePaths(ts.getDirectoryPath(sourceFile.filename), reference.filename));
var referenceFileName = ts.normalizePath(ts.combinePaths(ts.getDirectoryPath(sourceFile.filename), reference.filename));
return program.getSourceFile(referenceFileName);
}
var referencePathsOutput = "";
function writeReferencePath(referencedFile) {
var declFileName = referencedFile.flags & 512 /* DeclarationFile */ ? referencedFile.filename : shouldEmitToOwnFile(referencedFile) ? getOwnEmitOutputFilePath(referencedFile, ".d.ts") : ts.getModuleNameFromFilename(compilerOptions.out) + ".d.ts";
declFileName = ts.getRelativePathToDirectoryOrUrl(ts.getDirectoryPath(ts.normalizeSlashes(jsFilePath)), declFileName, compilerHost.getCurrentDirectory(), false);
referencePathsOutput += "/// <reference path='" + declFileName + "' />" + newLine;
referencePathsOutput += "/// <reference path=\"" + declFileName + "\" />" + newLine;
}
if (root) {
var addedGlobalFileReference = false;
ts.forEach(root.referencedFiles, function (fileReference) {
var referencedFile = resolveScriptReference(root, fileReference);
if ((referencedFile.flags & 512 /* DeclarationFile */) || shouldEmitToOwnFile(referencedFile) || !addedGlobalFileReference) {
writeReferencePath(referencedFile);
if (!isExternalModuleOrDeclarationFile(referencedFile)) {
addedGlobalFileReference = true;
if (!compilerOptions.noResolve) {
var addedGlobalFileReference = false;
ts.forEach(root.referencedFiles, function (fileReference) {
var referencedFile = resolveScriptReference(root, fileReference);
if ((referencedFile.flags & 512 /* DeclarationFile */) || shouldEmitToOwnFile(referencedFile) || !addedGlobalFileReference) {
writeReferencePath(referencedFile);
if (!isExternalModuleOrDeclarationFile(referencedFile)) {
addedGlobalFileReference = true;
}
}
}
});
});
}
emitNode(root);
}
else {
var emittedReferencedFiles = [];
ts.forEach(program.getSourceFiles(), function (sourceFile) {
if (!isExternalModuleOrDeclarationFile(sourceFile)) {
ts.forEach(sourceFile.referencedFiles, function (fileReference) {
var referencedFile = resolveScriptReference(sourceFile, fileReference);
if (isExternalModuleOrDeclarationFile(referencedFile) && !ts.contains(emittedReferencedFiles, referencedFile)) {
writeReferencePath(referencedFile);
emittedReferencedFiles.push(referencedFile);
}
});
if (!compilerOptions.noResolve) {
ts.forEach(sourceFile.referencedFiles, function (fileReference) {
var referencedFile = resolveScriptReference(sourceFile, fileReference);
if (isExternalModuleOrDeclarationFile(referencedFile) && !ts.contains(emittedReferencedFiles, referencedFile)) {
writeReferencePath(referencedFile);
emittedReferencedFiles.push(referencedFile);
}
});
}
emitNode(sourceFile);
}
});
@@ -8409,6 +8458,17 @@ var ts;
var nextSymbolId = 1;
var nextNodeId = 1;
var nextMergeId = 1;
function getDeclarationOfKind(symbol, kind) {
var declarations = symbol.declarations;
for (var i = 0; i < declarations.length; i++) {
var declaration = declarations[i];
if (declaration.kind === kind) {
return declaration;
}
}
return undefined;
}
ts.getDeclarationOfKind = getDeclarationOfKind;
function createTypeChecker(program, fullTypeCheck) {
var Symbol = ts.objectAllocator.getSymbolConstructor();
var Type = ts.objectAllocator.getTypeConstructor();
@@ -8439,7 +8499,9 @@ var ts;
getApparentType: getApparentType,
typeToString: typeToString,
symbolToString: symbolToString,
getAugmentedPropertiesOfApparentType: getAugmentedPropertiesOfApparentType
getAugmentedPropertiesOfApparentType: getAugmentedPropertiesOfApparentType,
getRootSymbol: getRootSymbol,
getContextualType: getContextualType
};
var undefinedSymbol = createSymbol(2 /* Property */ | 33554432 /* Transient */, "undefined");
var argumentsSymbol = createSymbol(2 /* Property */ | 33554432 /* Transient */, "arguments");
@@ -8887,16 +8949,6 @@ var ts;
}
return false;
}
function getDeclarationOfKind(symbol, kind) {
var declarations = symbol.declarations;
for (var i = 0; i < declarations.length; i++) {
var declaration = declarations[i];
if (declaration.kind === kind) {
return declaration;
}
}
return undefined;
}
function findConstructorDeclaration(node) {
var members = node.members;
for (var i = 0; i < members.length; i++) {
@@ -9917,27 +9969,38 @@ var ts;
}
function resolveAnonymousTypeMembers(type) {
var symbol = type.symbol;
var members = emptySymbols;
var callSignatures = emptyArray;
var constructSignatures = emptyArray;
if (symbol.flags & ts.SymbolFlags.HasExports) {
members = symbol.exports;
if (symbol.flags & 512 /* TypeLiteral */) {
var members = symbol.members;
var callSignatures = getSignaturesOfSymbol(members["__call"]);
var constructSignatures = getSignaturesOfSymbol(members["__new"]);
var stringIndexType = getIndexTypeOfSymbol(symbol, 0 /* String */);
var numberIndexType = getIndexTypeOfSymbol(symbol, 1 /* Number */);
}
if (symbol.flags & (8 /* Function */ | 2048 /* Method */)) {
callSignatures = getSignaturesOfSymbol(symbol);
}
if (symbol.flags & 16 /* Class */) {
var classType = getDeclaredTypeOfClass(symbol);
constructSignatures = getSignaturesOfSymbol(symbol.members["__constructor"]);
if (!constructSignatures.length)
constructSignatures = getDefaultConstructSignatures(classType);
if (classType.baseTypes.length) {
var members = createSymbolTable(getNamedMembers(members));
addInheritedMembers(members, getPropertiesOfType(getTypeOfSymbol(classType.baseTypes[0].symbol)));
else {
var members = emptySymbols;
var callSignatures = emptyArray;
var constructSignatures = emptyArray;
if (symbol.flags & ts.SymbolFlags.HasExports) {
members = symbol.exports;
}
if (symbol.flags & (8 /* Function */ | 2048 /* Method */)) {
callSignatures = getSignaturesOfSymbol(symbol);
}
if (symbol.flags & 16 /* Class */) {
var classType = getDeclaredTypeOfClass(symbol);
constructSignatures = getSignaturesOfSymbol(symbol.members["__constructor"]);
if (!constructSignatures.length) {
constructSignatures = getDefaultConstructSignatures(classType);
}
if (classType.baseTypes.length) {
members = createSymbolTable(getNamedMembers(members));
addInheritedMembers(members, getPropertiesOfType(getTypeOfSymbol(classType.baseTypes[0].symbol)));
}
}
var stringIndexType = undefined;
var numberIndexType = (symbol.flags & 64 /* Enum */) ? stringType : undefined;
}
var numberIndexType = (symbol.flags & 64 /* Enum */) ? stringType : undefined;
setObjectTypeMembers(type, members, callSignatures, constructSignatures, undefined, numberIndexType);
setObjectTypeMembers(type, members, callSignatures, constructSignatures, stringIndexType, numberIndexType);
}
function resolveObjectTypeMembers(type) {
if (!type.members) {
@@ -10319,13 +10382,7 @@ var ts;
function getTypeFromTypeLiteralNode(node) {
var links = getNodeLinks(node);
if (!links.resolvedType) {
var symbol = node.symbol;
var members = symbol.members;
var callSignatures = getSignaturesOfSymbol(members["__call"]);
var constructSignatures = getSignaturesOfSymbol(members["__new"]);
var stringIndexType = getIndexTypeOfSymbol(symbol, 0 /* String */);
var numberIndexType = getIndexTypeOfSymbol(symbol, 1 /* Number */);
links.resolvedType = createAnonymousType(symbol, members, callSignatures, constructSignatures, stringIndexType, numberIndexType);
links.resolvedType = createObjectType(8192 /* Anonymous */, node.symbol);
}
return links.resolvedType;
}
@@ -11054,45 +11111,6 @@ var ts;
function isTypeOfObjectLiteral(type) {
return (type.flags & 8192 /* Anonymous */) && type.symbol && (type.symbol.flags & 1024 /* ObjectLiteral */) ? true : false;
}
function getWidenedTypeOfObjectLiteral(type) {
var properties = getPropertiesOfType(type);
if (properties.length) {
var widenedTypes = [];
var propTypeWasWidened = false;
ts.forEach(properties, function (p) {
var propType = getTypeOfSymbol(p);
var widenedType = getWidenedType(propType);
if (propType !== widenedType) {
propTypeWasWidened = true;
if (program.getCompilerOptions().noImplicitAny && getInnermostTypeOfNestedArrayTypes(widenedType) === anyType) {
error(p.valueDeclaration, ts.Diagnostics.Object_literal_s_property_0_implicitly_has_an_1_type, p.name, typeToString(widenedType));
}
}
widenedTypes.push(widenedType);
});
if (propTypeWasWidened) {
var members = {};
var index = 0;
ts.forEach(properties, function (p) {
var symbol = createSymbol(2 /* Property */ | 33554432 /* Transient */, p.name);
symbol.declarations = p.declarations;
symbol.parent = p.parent;
symbol.type = widenedTypes[index++];
if (p.valueDeclaration)
symbol.valueDeclaration = p.valueDeclaration;
members[symbol.name] = symbol;
});
var stringIndexType = getIndexTypeOfType(type, 0 /* String */);
var numberIndexType = getIndexTypeOfType(type, 1 /* Number */);
if (stringIndexType)
stringIndexType = getWidenedType(stringIndexType);
if (numberIndexType)
numberIndexType = getWidenedType(numberIndexType);
type = createAnonymousType(type.symbol, members, emptyArray, emptyArray, stringIndexType, numberIndexType);
}
}
return type;
}
function isArrayType(type) {
return type.flags & 4096 /* Reference */ && type.target === globalArrayType;
}
@@ -11102,13 +11120,7 @@ var ts;
}
return type;
}
function getWidenedTypeOfArrayLiteral(type) {
var elementType = type.typeArguments[0];
var widenedType = getWidenedType(elementType);
type = elementType !== widenedType ? createArrayType(widenedType) : type;
return type;
}
function getWidenedType(type) {
function getWidenedType(type, supressNoImplicitAnyErrors) {
if (type.flags & (32 /* Undefined */ | 64 /* Null */)) {
return anyType;
}
@@ -11119,6 +11131,52 @@ var ts;
return getWidenedTypeOfArrayLiteral(type);
}
return type;
function getWidenedTypeOfObjectLiteral(type) {
var properties = getPropertiesOfType(type);
if (properties.length) {
var widenedTypes = [];
var propTypeWasWidened = false;
ts.forEach(properties, function (p) {
var propType = getTypeOfSymbol(p);
var widenedType = getWidenedType(propType);
if (propType !== widenedType) {
propTypeWasWidened = true;
if (!supressNoImplicitAnyErrors && program.getCompilerOptions().noImplicitAny && getInnermostTypeOfNestedArrayTypes(widenedType) === anyType) {
error(p.valueDeclaration, ts.Diagnostics.Object_literal_s_property_0_implicitly_has_an_1_type, p.name, typeToString(widenedType));
}
}
widenedTypes.push(widenedType);
});
if (propTypeWasWidened) {
var members = {};
var index = 0;
ts.forEach(properties, function (p) {
var symbol = createSymbol(2 /* Property */ | 33554432 /* Transient */, p.name);
symbol.declarations = p.declarations;
symbol.parent = p.parent;
symbol.type = widenedTypes[index++];
symbol.target = p;
if (p.valueDeclaration)
symbol.valueDeclaration = p.valueDeclaration;
members[symbol.name] = symbol;
});
var stringIndexType = getIndexTypeOfType(type, 0 /* String */);
var numberIndexType = getIndexTypeOfType(type, 1 /* Number */);
if (stringIndexType)
stringIndexType = getWidenedType(stringIndexType);
if (numberIndexType)
numberIndexType = getWidenedType(numberIndexType);
type = createAnonymousType(type.symbol, members, emptyArray, emptyArray, stringIndexType, numberIndexType);
}
}
return type;
}
function getWidenedTypeOfArrayLiteral(type) {
var elementType = type.typeArguments[0];
var widenedType = getWidenedType(elementType, supressNoImplicitAnyErrors);
type = elementType !== widenedType ? createArrayType(widenedType) : type;
return type;
}
}
function forEachMatchingParameterType(source, target, callback) {
var sourceMax = source.parameters.length;
@@ -11652,6 +11710,7 @@ var ts;
if (member.valueDeclaration)
prop.valueDeclaration = member.valueDeclaration;
prop.type = type;
prop.target = member;
member = prop;
}
else {
@@ -12020,9 +12079,9 @@ var ts;
var exprType = checkExpression(node.operand);
var targetType = getTypeFromTypeNode(node.type);
if (fullTypeCheck && targetType !== unknownType) {
var widenedType = getWidenedType(exprType);
if (!(isTypeAssignableTo(exprType, targetType) || isTypeAssignableTo(targetType, widenedType))) {
checkTypeAssignableTo(targetType, widenedType, node, ts.Diagnostics.Neither_type_0_nor_type_1_is_assignable_to_the_other_Colon, ts.Diagnostics.Neither_type_0_nor_type_1_is_assignable_to_the_other);
var widenedType = getWidenedType(exprType, true);
if (!(isTypeAssignableTo(targetType, widenedType))) {
checkTypeAssignableTo(exprType, targetType, node, ts.Diagnostics.Neither_type_0_nor_type_1_is_assignable_to_the_other_Colon, ts.Diagnostics.Neither_type_0_nor_type_1_is_assignable_to_the_other);
}
}
return targetType;
@@ -12162,26 +12221,26 @@ var ts;
}
}
}
checkSignatureDeclaration(node);
}
}
if (fullTypeCheck && !(links.flags & 1 /* TypeChecked */)) {
checkSignatureDeclaration(node);
if (node.type) {
checkIfNonVoidFunctionHasReturnExpressionsOrSingleThrowStatment(node, getTypeFromTypeNode(node.type));
}
if (node.body.kind === 168 /* FunctionBlock */) {
checkSourceElement(node.body);
}
else {
var exprType = checkExpression(node.body);
if (node.type) {
checkTypeAssignableTo(exprType, getTypeFromTypeNode(node.type), node.body, undefined, undefined);
}
}
links.flags |= 1 /* TypeChecked */;
}
return type;
}
function checkFunctionExpressionBody(node) {
if (node.type) {
checkIfNonVoidFunctionHasReturnExpressionsOrSingleThrowStatment(node, getTypeFromTypeNode(node.type));
}
if (node.body.kind === 168 /* FunctionBlock */) {
checkSourceElement(node.body);
}
else {
var exprType = checkExpression(node.body);
if (node.type) {
checkTypeAssignableTo(exprType, getTypeFromTypeNode(node.type), node.body, undefined, undefined);
}
checkFunctionExpressionBodies(node.body);
}
}
function checkArithmeticOperandType(operand, type, diagnostic) {
if (!(type.flags & (1 /* Any */ | ts.TypeFlags.NumberLike))) {
error(operand, diagnostic);
@@ -12504,6 +12563,7 @@ var ts;
if (fullTypeCheck) {
checkCollisionWithCapturedSuperVariable(node, node.name);
checkCollisionWithCapturedThisVariable(node, node.name);
checkCollistionWithRequireExportsInGeneratedCode(node, node.name);
checkCollisionWithArgumentsInGeneratedCode(node);
if (program.getCompilerOptions().noImplicitAny && !node.type) {
switch (node.kind) {
@@ -13031,6 +13091,18 @@ var ts;
}
}
}
function checkCollistionWithRequireExportsInGeneratedCode(node, name) {
if (!needCollisionCheckForIdentifier(node, name, "require") && !needCollisionCheckForIdentifier(node, name, "exports")) {
return;
}
if (node.kind === 172 /* ModuleDeclaration */ && !ts.isInstantiated(node)) {
return;
}
var parent = node.kind === 166 /* VariableDeclaration */ ? node.parent.parent : node.parent;
if (parent.kind === 177 /* SourceFile */ && ts.isExternalModule(parent)) {
error(name, ts.Diagnostics.Duplicate_identifier_0_Compiler_reserves_name_1_in_top_level_scope_of_an_external_module, name.text, name.text);
}
}
function checkVariableDeclaration(node) {
checkSourceElement(node.type);
checkExportsOnMergedDeclarations(node);
@@ -13052,6 +13124,7 @@ var ts;
}
checkCollisionWithCapturedSuperVariable(node, node.name);
checkCollisionWithCapturedThisVariable(node, node.name);
checkCollistionWithRequireExportsInGeneratedCode(node, node.name);
if (!useTypeFromValueDeclaration) {
if (typeOfValueDeclaration !== unknownType && type !== unknownType && !isTypeIdenticalTo(typeOfValueDeclaration, type)) {
error(node.name, ts.Diagnostics.Subsequent_variable_declarations_must_have_the_same_type_Variable_0_must_be_of_type_1_but_here_has_type_2, ts.identifierToString(node.name), typeToString(typeOfValueDeclaration), typeToString(type));
@@ -13250,6 +13323,7 @@ var ts;
checkTypeNameIsReserved(node.name, ts.Diagnostics.Class_name_cannot_be_0);
checkTypeParameters(node.typeParameters);
checkCollisionWithCapturedThisVariable(node, node.name);
checkCollistionWithRequireExportsInGeneratedCode(node, node.name);
checkExportsOnMergedDeclarations(node);
var symbol = getSymbolOfNode(node);
var type = getDeclaredTypeOfSymbol(symbol);
@@ -13417,6 +13491,7 @@ var ts;
}
checkTypeNameIsReserved(node.name, ts.Diagnostics.Enum_name_cannot_be_0);
checkCollisionWithCapturedThisVariable(node, node.name);
checkCollistionWithRequireExportsInGeneratedCode(node, node.name);
checkExportsOnMergedDeclarations(node);
var enumSymbol = getSymbolOfNode(node);
var enumType = getDeclaredTypeOfSymbol(enumSymbol);
@@ -13473,6 +13548,7 @@ var ts;
function checkModuleDeclaration(node) {
if (fullTypeCheck) {
checkCollisionWithCapturedThisVariable(node, node.name);
checkCollistionWithRequireExportsInGeneratedCode(node, node.name);
checkExportsOnMergedDeclarations(node);
var symbol = getSymbolOfNode(node);
if (symbol.flags & 128 /* ValueModule */ && symbol.declarations.length > 1 && !ts.isInAmbientContext(node)) {
@@ -13505,6 +13581,7 @@ var ts;
}
function checkImportDeclaration(node) {
checkCollisionWithCapturedThisVariable(node, node.name);
checkCollistionWithRequireExportsInGeneratedCode(node, node.name);
var symbol = getSymbolOfNode(node);
var target;
if (node.entityName) {
@@ -13587,9 +13664,10 @@ var ts;
case 167 /* FunctionDeclaration */:
return checkFunctionDeclaration(node);
case 143 /* Block */:
return checkBlock(node);
case 168 /* FunctionBlock */:
case 173 /* ModuleBlock */:
return checkBlock(node);
return checkBody(node);
case 144 /* VariableStatement */:
return checkVariableStatement(node);
case 146 /* ExpressionStatement */:
@@ -13635,12 +13713,79 @@ var ts;
return checkExportAssignment(node);
}
}
function checkFunctionExpressionBodies(node) {
switch (node.kind) {
case 136 /* FunctionExpression */:
case 137 /* ArrowFunction */:
ts.forEach(node.parameters, checkFunctionExpressionBodies);
checkFunctionExpressionBody(node);
break;
case 116 /* Method */:
case 117 /* Constructor */:
case 118 /* GetAccessor */:
case 119 /* SetAccessor */:
case 167 /* FunctionDeclaration */:
ts.forEach(node.parameters, checkFunctionExpressionBodies);
break;
case 155 /* WithStatement */:
checkFunctionExpressionBodies(node.expression);
break;
case 114 /* Parameter */:
case 115 /* Property */:
case 127 /* ArrayLiteral */:
case 128 /* ObjectLiteral */:
case 129 /* PropertyAssignment */:
case 130 /* PropertyAccess */:
case 131 /* IndexedAccess */:
case 132 /* CallExpression */:
case 133 /* NewExpression */:
case 134 /* TypeAssertion */:
case 135 /* ParenExpression */:
case 138 /* PrefixOperator */:
case 139 /* PostfixOperator */:
case 140 /* BinaryExpression */:
case 141 /* ConditionalExpression */:
case 143 /* Block */:
case 168 /* FunctionBlock */:
case 173 /* ModuleBlock */:
case 144 /* VariableStatement */:
case 146 /* ExpressionStatement */:
case 147 /* IfStatement */:
case 148 /* DoStatement */:
case 149 /* WhileStatement */:
case 150 /* ForStatement */:
case 151 /* ForInStatement */:
case 152 /* ContinueStatement */:
case 153 /* BreakStatement */:
case 154 /* ReturnStatement */:
case 156 /* SwitchStatement */:
case 157 /* CaseClause */:
case 158 /* DefaultClause */:
case 159 /* LabelledStatement */:
case 160 /* ThrowStatement */:
case 161 /* TryStatement */:
case 162 /* TryBlock */:
case 163 /* CatchBlock */:
case 164 /* FinallyBlock */:
case 166 /* VariableDeclaration */:
case 169 /* ClassDeclaration */:
case 171 /* EnumDeclaration */:
case 176 /* EnumMember */:
case 177 /* SourceFile */:
ts.forEachChild(node, checkFunctionExpressionBodies);
break;
}
}
function checkBody(node) {
checkBlock(node);
checkFunctionExpressionBodies(node);
}
function checkSourceFile(node) {
var links = getNodeLinks(node);
if (!(links.flags & 1 /* TypeChecked */)) {
emitExtends = false;
potentialThisCollisions.length = 0;
ts.forEach(node.statements, checkSourceElement);
checkBody(node);
if (ts.isExternalModule(node)) {
var symbol = getExportAssignmentSymbol(node.symbol);
if (symbol && symbol.flags & 4194304 /* Import */) {
@@ -13754,19 +13899,6 @@ var ts;
function isTypeDeclarationName(name) {
return name.kind == 55 /* Identifier */ && isTypeDeclaration(name.parent) && name.parent.name === name;
}
function isDeclarationOrFunctionExpressionOrCatchVariableName(name) {
if (name.kind !== 55 /* Identifier */ && name.kind !== 3 /* StringLiteral */ && name.kind !== 2 /* NumericLiteral */) {
return false;
}
var parent = name.parent;
if (isDeclaration(parent) || parent.kind === 136 /* FunctionExpression */) {
return parent.name === name;
}
if (parent.kind === 163 /* CatchBlock */) {
return parent.variable === name;
}
return false;
}
function isTypeDeclaration(node) {
switch (node.kind) {
case 113 /* TypeParameter */:
@@ -13776,27 +13908,6 @@ var ts;
return true;
}
}
function isDeclaration(node) {
switch (node.kind) {
case 113 /* TypeParameter */:
case 114 /* Parameter */:
case 166 /* VariableDeclaration */:
case 115 /* Property */:
case 129 /* PropertyAssignment */:
case 176 /* EnumMember */:
case 116 /* Method */:
case 167 /* FunctionDeclaration */:
case 118 /* GetAccessor */:
case 119 /* SetAccessor */:
case 169 /* ClassDeclaration */:
case 170 /* InterfaceDeclaration */:
case 171 /* EnumDeclaration */:
case 172 /* ModuleDeclaration */:
case 174 /* ImportDeclaration */:
return true;
}
return false;
}
function isTypeReferenceIdentifier(entityName) {
var node = entityName;
while (node.parent && node.parent.kind === 112 /* QualifiedName */)
@@ -13940,7 +14051,7 @@ var ts;
return (node.parent.kind === 112 /* QualifiedName */ || node.parent.kind === 130 /* PropertyAccess */) && node.parent.right === node;
}
function getSymbolOfEntityName(entityName) {
if (isDeclarationOrFunctionExpressionOrCatchVariableName(entityName)) {
if (ts.isDeclarationOrFunctionExpressionOrCatchVariableName(entityName)) {
return getSymbolOfNode(entityName.parent);
}
if (entityName.parent.kind === 175 /* ExportAssignment */) {
@@ -13976,6 +14087,12 @@ var ts;
return undefined;
}
function getSymbolInfo(node) {
if (ts.isDeclarationOrFunctionExpressionOrCatchVariableName(node)) {
return getSymbolOfNode(node.parent);
}
if (node.kind === 55 /* Identifier */ && isInRightSideOfImportOrExportAssignment(node)) {
return node.parent.kind === 175 /* ExportAssignment */ ? getSymbolOfEntityName(node) : getSymbolOfPartOfRightHandSideOfImport(node);
}
switch (node.kind) {
case 55 /* Identifier */:
case 130 /* PropertyAccess */:
@@ -13992,7 +14109,13 @@ var ts;
}
return undefined;
case 3 /* StringLiteral */:
if (node.parent.kind === 131 /* IndexedAccess */ && node.parent.index === node) {
if (node.parent.kind === 174 /* ImportDeclaration */ && node.parent.externalModuleName === node) {
var importSymbol = getSymbolOfNode(node.parent);
var moduleType = getTypeOfSymbol(importSymbol);
return moduleType ? moduleType.symbol : undefined;
}
case 2 /* NumericLiteral */:
if (node.parent.kind == 131 /* IndexedAccess */ && node.parent.index === node) {
var objectType = checkExpression(node.parent.object);
if (objectType === unknownType)
return undefined;
@@ -14001,14 +14124,6 @@ var ts;
return undefined;
return getPropertyOfApparentType(apparentType, node.text);
}
else if (node.parent.kind === 174 /* ImportDeclaration */ && node.parent.externalModuleName === node) {
var importSymbol = getSymbolOfNode(node.parent);
var moduleType = getTypeOfSymbol(importSymbol);
return moduleType ? moduleType.symbol : undefined;
}
else if (node.parent.kind === 172 /* ModuleDeclaration */) {
return getSymbolOfNode(node.parent);
}
break;
}
return undefined;
@@ -14028,11 +14143,11 @@ var ts;
var symbol = getSymbolInfo(node);
return getDeclaredTypeOfSymbol(symbol);
}
if (isDeclaration(node)) {
if (ts.isDeclaration(node)) {
var symbol = getSymbolOfNode(node);
return getTypeOfSymbol(symbol);
}
if (isDeclarationOrFunctionExpressionOrCatchVariableName(node)) {
if (ts.isDeclarationOrFunctionExpressionOrCatchVariableName(node)) {
var symbol = getSymbolInfo(node);
return getTypeOfSymbol(symbol);
}
@@ -14079,6 +14194,9 @@ var ts;
return getPropertiesOfType(apparentType);
}
}
function getRootSymbol(symbol) {
return (symbol.flags & 33554432 /* Transient */) ? getSymbolLinks(symbol).target : symbol;
}
function isExternalModuleSymbol(symbol) {
return symbol.flags & 128 /* ValueModule */ && symbol.declarations.length === 1 && symbol.declarations[0].kind === 177 /* SourceFile */;
}
+1088 -595
View File
File diff suppressed because one or more lines are too long
-124
View File
@@ -1,124 +0,0 @@
declare var require: any, process: any;
declare var __dirname: any;
var fs = require("fs");
var path = require("path");
var child_process = require('child_process');
var tscRoot = path.join(__dirname, "..\\");
var tscPath = path.join(tscRoot, "built", "instrumented", "tsc.js");
var rwcTestPath = path.join(tscRoot, "tests", "cases", "rwc", "dt");
var definitelyTypedRoot = process.argv[2];
function fileExtensionIs(path: string, extension: string): boolean {
var pathLen = path.length;
var extLen = extension.length;
return pathLen > extLen && path.substr(pathLen - extLen, extLen).toLocaleLowerCase() === extension.toLocaleLowerCase();
}
function copyFileSync(source, destination) {
var text = fs.readFileSync(source);
fs.writeFileSync(destination, text);
}
function importDefinitelyTypedTest(testCaseName: string, testFiles: string[], responseFile: string ) {
var cmd = "node " + tscPath + " --module commonjs " + testFiles.join(" ");
if (responseFile) cmd += " @" + responseFile;
var testDirectoryName = testCaseName + "_" + Math.floor((Math.random() * 10000) + 1);
var testDirectoryPath = path.join(process.env["temp"], testDirectoryName);
if (fs.existsSync(testDirectoryPath)) {
throw new Error("Could not create test directory");
}
fs.mkdirSync(testDirectoryPath);
child_process.exec(cmd, {
maxBuffer: 1 * 1024 * 1024,
cwd: testDirectoryPath
}, (error, stdout, stderr) => {
//console.log("importing " + testCaseName + " ...");
//console.log(cmd);
if (error) {
console.log("importing " + testCaseName + " ...");
console.log(cmd);
console.log("==> error " + JSON.stringify(error));
console.log("==> stdout " + String(stdout));
console.log("==> stderr " + String(stderr));
console.log("\r\n");
return;
}
// copy generated file to output location
var outputFilePath = path.join(testDirectoryPath, "iocapture0.json");
var testCasePath = path.join(rwcTestPath, "DefinitelyTyped_" + testCaseName + ".json");
copyFileSync(outputFilePath, testCasePath);
//console.log("output generated at: " + outputFilePath);
if (!fs.existsSync(testCasePath)) {
throw new Error("could not find test case at: " + testCasePath);
}
else {
fs.unlinkSync(outputFilePath);
fs.rmdirSync(testDirectoryPath);
//console.log("testcase generated at: " + testCasePath);
//console.log("Done.");
}
//console.log("\r\n");
})
.on('error', function (error) {
console.log("==> error " + JSON.stringify(error));
console.log("\r\n");
});
}
function importDefinitelyTypedTests(definitelyTypedRoot: string): void {
fs.readdir(definitelyTypedRoot, (err, subDirectorys) => {
if (err) throw err;
subDirectorys
.filter(d => ["_infrastructure", "node_modules", ".git"].indexOf(d) >= 0)
.filter(i => fs.statSync(path.join(definitelyTypedRoot, i)).isDirectory())
.forEach(d => {
var directoryPath = path.join(definitelyTypedRoot, d);
fs.readdir(directoryPath, function (err, files) {
if (err) throw err;
var tsFiles = [];
var testFiles = [];
var paramFile;
files
.map(f => path.join(directoryPath, f))
.forEach(f => {
if (fileExtensionIs(f, ".ts")) tsFiles.push(f);
else if (fileExtensionIs(f, ".tscparams")) paramFile = f;
if (fileExtensionIs(f, "-tests.ts")) testFiles.push(f);
});
if (testFiles.length === 0) {
// no test files but multiple d.ts's, e.g. winjs
var regexp = new RegExp(d + "(([-][0-9])|([\.]d[\.]ts))");
if (tsFiles.length > 1 && tsFiles.every(t => fileExtensionIs(t, ".d.ts") && regexp.test(t))) {
tsFiles.forEach(filename => {
importDefinitelyTypedTest(path.basename(filename, ".d.ts"), [filename], paramFile);
});
}
else {
importDefinitelyTypedTest(d, tsFiles, paramFile);
}
}
else {
testFiles.forEach(filename => {
importDefinitelyTypedTest(path.basename(filename, "-tests.ts"), [filename], paramFile);
});
}
});
})
});
}
importDefinitelyTypedTests(definitelyTypedRoot);
+50 -50
View File
@@ -3151,45 +3151,6 @@ module ts {
return (type.flags & TypeFlags.Anonymous) && type.symbol && (type.symbol.flags & SymbolFlags.ObjectLiteral) ? true : false;
}
function getWidenedTypeOfObjectLiteral(type: Type): Type {
var properties = getPropertiesOfType(type);
if (properties.length) {
var widenedTypes: Type[] = [];
var propTypeWasWidened: boolean = false;
forEach(properties, p => {
var propType = getTypeOfSymbol(p);
var widenedType = getWidenedType(propType);
if (propType !== widenedType) {
propTypeWasWidened = true;
if (compilerOptions.noImplicitAny && getInnermostTypeOfNestedArrayTypes(widenedType) === anyType) {
error(p.valueDeclaration, Diagnostics.Object_literal_s_property_0_implicitly_has_an_1_type, p.name, typeToString(widenedType));
}
}
widenedTypes.push(widenedType);
});
if (propTypeWasWidened) {
var members: SymbolTable = {};
var index = 0;
forEach(properties, p => {
var symbol = <TransientSymbol>createSymbol(SymbolFlags.Property | SymbolFlags.Transient, p.name);
symbol.declarations = p.declarations;
symbol.parent = p.parent;
symbol.type = widenedTypes[index++];
symbol.target = p;
if (p.valueDeclaration) symbol.valueDeclaration = p.valueDeclaration;
members[symbol.name] = symbol;
});
var stringIndexType = getIndexTypeOfType(type, IndexKind.String);
var numberIndexType = getIndexTypeOfType(type, IndexKind.Number);
if (stringIndexType) stringIndexType = getWidenedType(stringIndexType);
if (numberIndexType) numberIndexType = getWidenedType(numberIndexType);
type = createAnonymousType(type.symbol, members, emptyArray, emptyArray, stringIndexType, numberIndexType);
}
}
return type;
}
function isArrayType(type: Type): boolean {
return type.flags & TypeFlags.Reference && (<TypeReference>type).target === globalArrayType;
}
@@ -3202,17 +3163,8 @@ module ts {
return type;
}
function getWidenedTypeOfArrayLiteral(type: Type): Type {
var elementType = (<TypeReference>type).typeArguments[0];
var widenedType = getWidenedType(elementType);
type = elementType !== widenedType ? createArrayType(widenedType) : type;
return type;
}
/* If we are widening on a literal, then we may need to the 'node' parameter for reporting purposes */
function getWidenedType(type: Type): Type {
function getWidenedType(type: Type, supressNoImplicitAnyErrors?: boolean): Type {
if (type.flags & (TypeFlags.Undefined | TypeFlags.Null)) {
return anyType;
}
@@ -3223,6 +3175,54 @@ module ts {
return getWidenedTypeOfArrayLiteral(type);
}
return type;
function getWidenedTypeOfObjectLiteral(type: Type): Type {
var properties = getPropertiesOfType(type);
if (properties.length) {
var widenedTypes: Type[] = [];
var propTypeWasWidened: boolean = false;
forEach(properties, p => {
var propType = getTypeOfSymbol(p);
var widenedType = getWidenedType(propType);
if (propType !== widenedType) {
propTypeWasWidened = true;
if (!supressNoImplicitAnyErrors && program.getCompilerOptions().noImplicitAny && getInnermostTypeOfNestedArrayTypes(widenedType) === anyType) {
error(p.valueDeclaration, Diagnostics.Object_literal_s_property_0_implicitly_has_an_1_type, p.name, typeToString(widenedType));
}
}
widenedTypes.push(widenedType);
});
if (propTypeWasWidened) {
var members: SymbolTable = {};
var index = 0;
forEach(properties, p => {
var symbol = <TransientSymbol>createSymbol(SymbolFlags.Property | SymbolFlags.Transient, p.name);
symbol.declarations = p.declarations;
symbol.parent = p.parent;
symbol.type = widenedTypes[index++];
symbol.target = p;
if (p.valueDeclaration) symbol.valueDeclaration = p.valueDeclaration;
members[symbol.name] = symbol;
});
var stringIndexType = getIndexTypeOfType(type, IndexKind.String);
var numberIndexType = getIndexTypeOfType(type, IndexKind.Number);
if (stringIndexType) stringIndexType = getWidenedType(stringIndexType);
if (numberIndexType) numberIndexType = getWidenedType(numberIndexType);
type = createAnonymousType(type.symbol, members, emptyArray, emptyArray, stringIndexType, numberIndexType);
}
}
return type;
}
function getWidenedTypeOfArrayLiteral(type: Type): Type {
var elementType = (<TypeReference>type).typeArguments[0];
var widenedType = getWidenedType(elementType, supressNoImplicitAnyErrors);
type = elementType !== widenedType ? createArrayType(widenedType) : type;
return type;
}
}
function forEachMatchingParameterType(source: Signature, target: Signature, callback: (s: Type, t: Type) => void) {
@@ -4348,7 +4348,7 @@ module ts {
var exprType = checkExpression(node.operand);
var targetType = getTypeFromTypeNode(node.type);
if (fullTypeCheck && targetType !== unknownType) {
var widenedType = getWidenedType(exprType);
var widenedType = getWidenedType(exprType, /*supressNoImplicitAnyErrors*/ true);
if (!(isTypeAssignableTo(targetType, widenedType))) {
checkTypeAssignableTo(exprType, targetType, node, Diagnostics.Neither_type_0_nor_type_1_is_assignable_to_the_other_Colon, Diagnostics.Neither_type_0_nor_type_1_is_assignable_to_the_other);
}
+17 -12
View File
@@ -1886,6 +1886,23 @@ declare var HTMLCollection: {
new(): HTMLCollection;
}
interface BlobPropertyBag {
type?: string;
endings?: string;
}
interface Blob {
type: string;
size: number;
msDetachStream(): any;
slice(start?: number, end?: number, contentType?: string): Blob;
msClose(): void;
}
declare var Blob: {
prototype: Blob;
new (blobParts?: any[], options?: BlobPropertyBag): Blob;
}
interface NavigatorID {
appVersion: string;
appName: string;
@@ -10027,18 +10044,6 @@ declare var FileReader: {
new(): FileReader;
}
interface Blob {
type: string;
size: number;
msDetachStream(): any;
slice(start?: number, end?: number, contentType?: string): Blob;
msClose(): void;
}
declare var Blob: {
prototype: Blob;
new(): Blob;
}
interface ApplicationCache extends EventTarget {
status: number;
ondownloading: (ev: Event) => any;
+6 -1
View File
@@ -614,6 +614,11 @@ declare var FileReader: {
new(): FileReader;
}
interface BlobPropertyBag {
type?: string;
endings?: string;
}
interface Blob {
type: string;
size: number;
@@ -623,7 +628,7 @@ interface Blob {
}
declare var Blob: {
prototype: Blob;
new(): Blob;
new (blobParts?: any[], options?: BlobPropertyBag): Blob;
}
interface MSStream {
@@ -0,0 +1,6 @@
==== tests/cases/conformance/ambient/ambientExternalModuleInsideNonAmbient.ts (1 errors) ====
module M {
export declare module "M" { }
~~~
!!! Ambient external modules cannot be nested in other modules.
}
@@ -0,0 +1,6 @@
//// [ambientExternalModuleInsideNonAmbient.ts]
module M {
export declare module "M" { }
}
//// [ambientExternalModuleInsideNonAmbient.js]
@@ -0,0 +1,4 @@
==== tests/cases/conformance/ambient/ambientExternalModuleInsideNonAmbientExternalModule.ts (1 errors) ====
export declare module "M" { }
~~~
!!! Ambient external modules cannot be nested in other modules.
@@ -0,0 +1,6 @@
//// [ambientExternalModuleInsideNonAmbientExternalModule.ts]
export declare module "M" { }
//// [ambientExternalModuleInsideNonAmbientExternalModule.js]
define(["require", "exports"], function (require, exports) {
});
@@ -0,0 +1,25 @@
//// [tests/cases/conformance/ambient/ambientExternalModuleMerging.ts] ////
//// [ambientExternalModuleMerging_use.ts]
import M = require("M");
// Should be strings
var x = M.x;
var y = M.y;
//// [ambientExternalModuleMerging_declare.ts]
declare module "M" {
export var x: string;
}
// Merge
declare module "M" {
export var y: string;
}
//// [ambientExternalModuleMerging_use.js]
define(["require", "exports", "M"], function (require, exports, M) {
// Should be strings
var x = M.x;
var y = M.y;
});
//// [ambientExternalModuleMerging_declare.js]
@@ -0,0 +1,28 @@
=== tests/cases/conformance/ambient/ambientExternalModuleMerging_use.ts ===
import M = require("M");
>M : typeof M
// Should be strings
var x = M.x;
>x : string
>M.x : string
>M : typeof M
>x : string
var y = M.y;
>y : string
>M.y : string
>M : typeof M
>y : string
=== tests/cases/conformance/ambient/ambientExternalModuleMerging_declare.ts ===
declare module "M" {
export var x: string;
>x : string
}
// Merge
declare module "M" {
export var y: string;
>y : string
}
@@ -0,0 +1,24 @@
//// [ambientInsideNonAmbient.ts]
module M {
export declare var x;
export declare function f();
export declare class C { }
export declare enum E { }
export declare module M { }
}
module M2 {
declare var x;
declare function f();
declare class C { }
declare enum E { }
declare module M { }
}
//// [ambientInsideNonAmbient.js]
var M;
(function (M) {
})(M || (M = {}));
var M2;
(function (M2) {
})(M2 || (M2 = {}));
@@ -0,0 +1,38 @@
=== tests/cases/conformance/ambient/ambientInsideNonAmbient.ts ===
module M {
>M : typeof M
export declare var x;
>x : any
export declare function f();
>f : () => any
export declare class C { }
>C : C
export declare enum E { }
>E : E
export declare module M { }
>M : unknown
}
module M2 {
>M2 : typeof M2
declare var x;
>x : any
declare function f();
>f : () => any
declare class C { }
>C : C
declare enum E { }
>E : E
declare module M { }
>M : unknown
}
@@ -0,0 +1,10 @@
//// [ambientInsideNonAmbientExternalModule.ts]
export declare var x;
export declare function f();
export declare class C { }
export declare enum E { }
export declare module M { }
//// [ambientInsideNonAmbientExternalModule.js]
define(["require", "exports"], function (require, exports) {
});
@@ -0,0 +1,16 @@
=== tests/cases/conformance/ambient/ambientInsideNonAmbientExternalModule.ts ===
export declare var x;
>x : any
export declare function f();
>f : () => any
export declare class C { }
>C : C
export declare enum E { }
>E : E
export declare module M { }
>M : unknown
@@ -1,4 +1,4 @@
==== tests/cases/compiler/augmentedTypeAssignmentCompatIndexSignature.ts (2 errors) ====
==== tests/cases/conformance/types/members/augmentedTypeAssignmentCompatIndexSignature.ts (2 errors) ====
interface Foo { a }
interface Bar { b }
@@ -1,4 +1,4 @@
=== tests/cases/compiler/augmentedTypeBracketAccessIndexSignature.ts ===
=== tests/cases/conformance/types/members/augmentedTypeBracketAccessIndexSignature.ts ===
interface Foo { a }
>Foo : Foo
>a : any
@@ -0,0 +1,26 @@
//// [classDoesNotDependOnPrivateMember.ts]
module M {
interface I { }
export class C {
private x: I;
}
}
//// [classDoesNotDependOnPrivateMember.js]
var M;
(function (M) {
var C = (function () {
function C() {
}
return C;
})();
M.C = C;
})(M || (M = {}));
//// [classDoesNotDependOnPrivateMember.d.ts]
declare module M {
class C {
private x;
}
}
@@ -0,0 +1,15 @@
=== tests/cases/conformance/declarationEmit/classDoesNotDependOnPrivateMember.ts ===
module M {
>M : typeof M
interface I { }
>I : I
export class C {
>C : C
private x: I;
>x : I
>I : I
}
}
@@ -0,0 +1,28 @@
//// [contextuallyTypedFunctionExpressionsAndReturnAnnotations.ts]
declare function foo(x: (y: string) => (y2: number) => void);
// Contextually type the parameter even if there is a return annotation
foo((y): (y2: number) => void => {
var z = y.charAt(0); // Should be string
return null;
});
foo((y: string) => {
return y2 => {
var z = y2.toFixed(); // Should be string
return 0;
};
});
//// [contextuallyTypedFunctionExpressionsAndReturnAnnotations.js]
// Contextually type the parameter even if there is a return annotation
foo(function (y) {
var z = y.charAt(0); // Should be string
return null;
});
foo(function (y) {
return function (y2) {
var z = y2.toFixed(); // Should be string
return 0;
};
});
@@ -0,0 +1,45 @@
=== tests/cases/conformance/expressions/functions/contextuallyTypedFunctionExpressionsAndReturnAnnotations.ts ===
declare function foo(x: (y: string) => (y2: number) => void);
>foo : (x: (y: string) => (y2: number) => void) => any
>x : (y: string) => (y2: number) => void
>y : string
>y2 : number
// Contextually type the parameter even if there is a return annotation
foo((y): (y2: number) => void => {
>foo((y): (y2: number) => void => { var z = y.charAt(0); // Should be string return null;}) : any
>foo : (x: (y: string) => (y2: number) => void) => any
>(y): (y2: number) => void => { var z = y.charAt(0); // Should be string return null;} : (y: string) => (y2: number) => void
>y : string
>y2 : number
var z = y.charAt(0); // Should be string
>z : string
>y.charAt(0) : string
>y.charAt : (pos: number) => string
>y : string
>charAt : (pos: number) => string
return null;
});
foo((y: string) => {
>foo((y: string) => { return y2 => { var z = y2.toFixed(); // Should be string return 0; };}) : any
>foo : (x: (y: string) => (y2: number) => void) => any
>(y: string) => { return y2 => { var z = y2.toFixed(); // Should be string return 0; };} : (y: string) => (y2: number) => number
>y : string
return y2 => {
>y2 => { var z = y2.toFixed(); // Should be string return 0; } : (y2: number) => number
>y2 : number
var z = y2.toFixed(); // Should be string
>z : string
>y2.toFixed() : string
>y2.toFixed : (fractionDigits?: number) => string
>y2 : number
>toFixed : (fractionDigits?: number) => string
return 0;
};
});
@@ -0,0 +1,13 @@
//// [derivedInterfaceDoesNotHideBaseSignatures.ts]
// Derived interfaces no longer hide signatures from base types, so these signatures are always compatible.
interface Base {
(): string;
new (x: string): number;
}
interface Derived extends Base {
(): number;
new (x: string): string;
}
//// [derivedInterfaceDoesNotHideBaseSignatures.js]
@@ -0,0 +1,18 @@
=== tests/cases/conformance/interfaces/interfaceDeclarations/derivedInterfaceDoesNotHideBaseSignatures.ts ===
// Derived interfaces no longer hide signatures from base types, so these signatures are always compatible.
interface Base {
>Base : Base
(): string;
new (x: string): number;
>x : string
}
interface Derived extends Base {
>Derived : Derived
>Base : Base
(): number;
new (x: string): string;
>x : string
}
@@ -0,0 +1,24 @@
==== tests/cases/conformance/enums/enumConstantMembers.ts (2 errors) ====
// Constant members allow negatives, but not decimals. Also hex literals are allowed
enum E1 {
a = 1,
b
}
enum E2 {
a = - 1,
b
}
enum E3 {
a = 0.1,
b // Error because 0.1 is not a constant
~
!!! Enum member must have initializer.
}
declare enum E4 {
a = 1,
b = -1,
c = 0.1 // Not a constant
~
!!! Ambient enum elements can only have integer literal initializers.
}
@@ -1,4 +1,4 @@
==== tests/cases/compiler/forgottenNew.ts (1 errors) ====
==== tests/cases/conformance/expressions/functionCalls/forgottenNew.ts (1 errors) ====
module Tools {
export class NullLogger { }
}
@@ -1,4 +1,4 @@
==== tests/cases/compiler/indexSignatureTypeInference.ts (1 errors) ====
==== tests/cases/conformance/types/typeRelationships/typeInference/indexSignatureTypeInference.ts (1 errors) ====
interface NumberMap<T> {
[index: number]: T;
}
@@ -0,0 +1,20 @@
==== tests/cases/compiler/noImplicitAnyInCastExpression.ts (1 errors) ====
// verify no noImplictAny errors reported with cast expression
interface IFoo {
a: number;
b: string;
}
// Expr type not assignable to target type
(<IFoo>{ a: null });
// Expr type assignable to target type
(<IFoo>{ a: 2, b: undefined });
// Neither types is assignable to each other
(<IFoo>{ c: null });
~~~~~~~~~~~~~~~~~
!!! Neither type '{ c: null; }' nor type 'IFoo' is assignable to the other:
!!! Property 'a' is missing in type '{ c: null; }'.
@@ -0,0 +1,26 @@
//// [noImplicitAnyInCastExpression.ts]
// verify no noImplictAny errors reported with cast expression
interface IFoo {
a: number;
b: string;
}
// Expr type not assignable to target type
(<IFoo>{ a: null });
// Expr type assignable to target type
(<IFoo>{ a: 2, b: undefined });
// Neither types is assignable to each other
(<IFoo>{ c: null });
//// [noImplicitAnyInCastExpression.js]
// verify no noImplictAny errors reported with cast expression
// Expr type not assignable to target type
{ a: null };
// Expr type assignable to target type
{ a: 2, b: undefined };
// Neither types is assignable to each other
{ c: null };
@@ -0,0 +1,99 @@
//// [recursiveTypesWithTypeof.ts]
// None of these declarations should have any errors!
// Using typeof directly, these should be any
var c: typeof c;
var c: any;
var d: typeof e;
var d: any;
var e: typeof d;
var e: any;
// In type arguments, these should be any
interface Foo<T> { }
var f: Array<typeof f>;
var f: any;
var f2: Foo<typeof f2>;
var f2: any;
var f3: Foo<typeof f3>[];
var f3: any;
// Truly recursive types
var g: { x: typeof g; };
var g: typeof g.x;
var h: () => typeof h;
var h = h();
var i: (x: typeof i) => typeof x;
var i = i(i);
var j: <T extends typeof j>(x: T) => T;
var j = j(j);
// Same as h, i, j with construct signatures
var h2: new () => typeof h2;
var h2 = new h2();
var i2: new (x: typeof i2) => typeof x;
var i2 = new i2(i2);
var j2: new <T extends typeof j2>(x: T) => T;
var j2 = new j2(j2);
// Indexers
var k: { [n: number]: typeof k;[s: string]: typeof k };
var k = k[0];
var k = k[''];
// Hybrid - contains type literals as well as type arguments
// These two are recursive
var hy1: { x: typeof hy1 }[];
var hy1 = hy1[0].x;
var hy2: { x: Array<typeof hy2> };
var hy2 = hy2.x[0];
interface Foo2<T, U> { }
// This one should be any because the first type argument is not contained inside a type literal
var hy3: Foo2<typeof hy3, { x: typeof hy3 }>;
var hy3: any;
//// [recursiveTypesWithTypeof.js]
// None of these declarations should have any errors!
// Using typeof directly, these should be any
var c;
var c;
var d;
var d;
var e;
var e;
var f;
var f;
var f2;
var f2;
var f3;
var f3;
// Truly recursive types
var g;
var g;
var h;
var h = h();
var i;
var i = i(i);
var j;
var j = j(j);
// Same as h, i, j with construct signatures
var h2;
var h2 = new h2();
var i2;
var i2 = new i2(i2);
var j2;
var j2 = new j2(j2);
// Indexers
var k;
var k = k[0];
var k = k[''];
// Hybrid - contains type literals as well as type arguments
// These two are recursive
var hy1;
var hy1 = hy1[0].x;
var hy2;
var hy2 = hy2.x[0];
// This one should be any because the first type argument is not contained inside a type literal
var hy3;
var hy3;
@@ -0,0 +1,196 @@
=== tests/cases/conformance/types/specifyingTypes/typeQueries/recursiveTypesWithTypeof.ts ===
// None of these declarations should have any errors!
// Using typeof directly, these should be any
var c: typeof c;
>c : any
>c : any
var c: any;
>c : any
var d: typeof e;
>d : any
>e : any
var d: any;
>d : any
var e: typeof d;
>e : any
>d : any
var e: any;
>e : any
// In type arguments, these should be any
interface Foo<T> { }
>Foo : Foo<T>
>T : T
var f: Array<typeof f>;
>f : any
>Array : T[]
>f : any
var f: any;
>f : any
var f2: Foo<typeof f2>;
>f2 : any
>Foo : Foo<T>
>f2 : any
var f2: any;
>f2 : any
var f3: Foo<typeof f3>[];
>f3 : any
>Foo : Foo<T>
>f3 : any
var f3: any;
>f3 : any
// Truly recursive types
var g: { x: typeof g; };
>g : { x: any; }
>x : { x: any; }
>g : { x: any; }
var g: typeof g.x;
>g : { x: any; }
>g : { x: any; }
>x : { x: any; }
var h: () => typeof h;
>h : () => any
>h : () => any
var h = h();
>h : () => any
>h() : () => any
>h : () => any
var i: (x: typeof i) => typeof x;
>i : (x: any) => any
>x : (x: any) => any
>i : (x: any) => any
>x : (x: any) => any
var i = i(i);
>i : (x: any) => any
>i(i) : (x: any) => any
>i : (x: any) => any
>i : (x: any) => any
var j: <T extends typeof j>(x: T) => T;
>j : <T extends any>(x: T) => T
>T : T
>j : <T extends any>(x: T) => T
>x : T
>T : T
>T : T
var j = j(j);
>j : <T extends any>(x: T) => T
>j(j) : <T extends any>(x: T) => T
>j : <T extends any>(x: T) => T
>j : <T extends any>(x: T) => T
// Same as h, i, j with construct signatures
var h2: new () => typeof h2;
>h2 : new () => any
>h2 : new () => any
var h2 = new h2();
>h2 : new () => any
>new h2() : new () => any
>h2 : new () => any
var i2: new (x: typeof i2) => typeof x;
>i2 : new (x: any) => any
>x : new (x: any) => any
>i2 : new (x: any) => any
>x : new (x: any) => any
var i2 = new i2(i2);
>i2 : new (x: any) => any
>new i2(i2) : new (x: any) => any
>i2 : new (x: any) => any
>i2 : new (x: any) => any
var j2: new <T extends typeof j2>(x: T) => T;
>j2 : new <T extends any>(x: T) => T
>T : T
>j2 : new <T extends any>(x: T) => T
>x : T
>T : T
>T : T
var j2 = new j2(j2);
>j2 : new <T extends any>(x: T) => T
>new j2(j2) : new <T extends any>(x: T) => T
>j2 : new <T extends any>(x: T) => T
>j2 : new <T extends any>(x: T) => T
// Indexers
var k: { [n: number]: typeof k;[s: string]: typeof k };
>k : { [x: string]: any; [x: number]: any; }
>n : number
>k : { [x: string]: any; [x: number]: any; }
>s : string
>k : { [x: string]: any; [x: number]: any; }
var k = k[0];
>k : { [x: string]: any; [x: number]: any; }
>k[0] : { [x: string]: any; [x: number]: any; }
>k : { [x: string]: any; [x: number]: any; }
var k = k[''];
>k : { [x: string]: any; [x: number]: any; }
>k[''] : { [x: string]: any; [x: number]: any; }
>k : { [x: string]: any; [x: number]: any; }
// Hybrid - contains type literals as well as type arguments
// These two are recursive
var hy1: { x: typeof hy1 }[];
>hy1 : { x: any[]; }[]
>x : { x: any[]; }[]
>hy1 : { x: any[]; }[]
var hy1 = hy1[0].x;
>hy1 : { x: any[]; }[]
>hy1[0].x : { x: any[]; }[]
>hy1[0] : { x: any[]; }
>hy1 : { x: any[]; }[]
>x : { x: any[]; }[]
var hy2: { x: Array<typeof hy2> };
>hy2 : { x: any[]; }
>x : { x: any[]; }[]
>Array : T[]
>hy2 : { x: any[]; }
var hy2 = hy2.x[0];
>hy2 : { x: any[]; }
>hy2.x[0] : { x: any[]; }
>hy2.x : { x: any[]; }[]
>hy2 : { x: any[]; }
>x : { x: any[]; }[]
interface Foo2<T, U> { }
>Foo2 : Foo2<T, U>
>T : T
>U : U
// This one should be any because the first type argument is not contained inside a type literal
var hy3: Foo2<typeof hy3, { x: typeof hy3 }>;
>hy3 : any
>Foo2 : Foo2<T, U>
>hy3 : any
>x : any
>hy3 : any
var hy3: any;
>hy3 : any
@@ -0,0 +1,5 @@
//// [specializedSignatureWithOptional.ts]
declare function f(x?: "hi"): void;
declare function f(x?: string): void;
//// [specializedSignatureWithOptional.js]
@@ -0,0 +1,9 @@
=== tests/cases/conformance/types/objectTypeLiteral/callSignatures/specializedSignatureWithOptional.ts ===
declare function f(x?: "hi"): void;
>f : { (x?: "hi"): void; (x?: string): void; }
>x : "hi"
declare function f(x?: string): void;
>f : { (x?: "hi"): void; (x?: string): void; }
>x : string
@@ -0,0 +1,17 @@
//@noImplicitAny: true
// verify no noImplictAny errors reported with cast expression
interface IFoo {
a: number;
b: string;
}
// Expr type not assignable to target type
(<IFoo>{ a: null });
// Expr type assignable to target type
(<IFoo>{ a: 2, b: undefined });
// Neither types is assignable to each other
(<IFoo>{ c: null });
@@ -0,0 +1,3 @@
module M {
export declare module "M" { }
}
@@ -0,0 +1,2 @@
//@module: amd
export declare module "M" { }
@@ -0,0 +1,16 @@
//@filename: ambientExternalModuleMerging_use.ts
//@module: amd
import M = require("M");
// Should be strings
var x = M.x;
var y = M.y;
//@filename: ambientExternalModuleMerging_declare.ts
declare module "M" {
export var x: string;
}
// Merge
declare module "M" {
export var y: string;
}
@@ -0,0 +1,15 @@
module M {
export declare var x;
export declare function f();
export declare class C { }
export declare enum E { }
export declare module M { }
}
module M2 {
declare var x;
declare function f();
declare class C { }
declare enum E { }
declare module M { }
}
@@ -0,0 +1,6 @@
// @module: amd
export declare var x;
export declare function f();
export declare class C { }
export declare enum E { }
export declare module M { }
@@ -0,0 +1,7 @@
//@declaration: true
module M {
interface I { }
export class C {
private x: I;
}
}
@@ -0,0 +1,19 @@
// Constant members allow negatives, but not decimals. Also hex literals are allowed
enum E1 {
a = 1,
b
}
enum E2 {
a = - 1,
b
}
enum E3 {
a = 0.1,
b // Error because 0.1 is not a constant
}
declare enum E4 {
a = 1,
b = -1,
c = 0.1 // Not a constant
}
@@ -0,0 +1,14 @@
declare function foo(x: (y: string) => (y2: number) => void);
// Contextually type the parameter even if there is a return annotation
foo((y): (y2: number) => void => {
var z = y.charAt(0); // Should be string
return null;
});
foo((y: string) => {
return y2 => {
var z = y2.toFixed(); // Should be string
return 0;
};
});
@@ -0,0 +1,10 @@
// Derived interfaces no longer hide signatures from base types, so these signatures are always compatible.
interface Base {
(): string;
new (x: string): number;
}
interface Derived extends Base {
(): number;
new (x: string): string;
}
@@ -0,0 +1,2 @@
declare function f(x?: "hi"): void;
declare function f(x?: string): void;
@@ -0,0 +1,53 @@
// None of these declarations should have any errors!
// Using typeof directly, these should be any
var c: typeof c;
var c: any;
var d: typeof e;
var d: any;
var e: typeof d;
var e: any;
// In type arguments, these should be any
interface Foo<T> { }
var f: Array<typeof f>;
var f: any;
var f2: Foo<typeof f2>;
var f2: any;
var f3: Foo<typeof f3>[];
var f3: any;
// Truly recursive types
var g: { x: typeof g; };
var g: typeof g.x;
var h: () => typeof h;
var h = h();
var i: (x: typeof i) => typeof x;
var i = i(i);
var j: <T extends typeof j>(x: T) => T;
var j = j(j);
// Same as h, i, j with construct signatures
var h2: new () => typeof h2;
var h2 = new h2();
var i2: new (x: typeof i2) => typeof x;
var i2 = new i2(i2);
var j2: new <T extends typeof j2>(x: T) => T;
var j2 = new j2(j2);
// Indexers
var k: { [n: number]: typeof k;[s: string]: typeof k };
var k = k[0];
var k = k[''];
// Hybrid - contains type literals as well as type arguments
// These two are recursive
var hy1: { x: typeof hy1 }[];
var hy1 = hy1[0].x;
var hy2: { x: Array<typeof hy2> };
var hy2 = hy2.x[0];
interface Foo2<T, U> { }
// This one should be any because the first type argument is not contained inside a type literal
var hy3: Foo2<typeof hy3, { x: typeof hy3 }>;
var hy3: any;