Skip to content

Commit 0cc039d

Browse files
committed
Merge branch 'master' of github.com:Microsoft/TypeScript
2 parents eef2c12 + 5129d7c commit 0cc039d

50 files changed

Lines changed: 1902 additions & 557 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

bin/tsc.js

Lines changed: 100 additions & 74 deletions
Large diffs are not rendered by default.

bin/tsserver.js

Lines changed: 103 additions & 77 deletions
Large diffs are not rendered by default.

bin/typescript.js

Lines changed: 120 additions & 78 deletions
Large diffs are not rendered by default.

bin/typescriptServices.js

Lines changed: 120 additions & 78 deletions
Large diffs are not rendered by default.

src/compiler/checker.ts

Lines changed: 39 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -803,7 +803,9 @@ module ts {
803803

804804
let symbol: Symbol;
805805
if (name.kind === SyntaxKind.Identifier) {
806-
symbol = resolveName(name, (<Identifier>name).text, meaning, Diagnostics.Cannot_find_name_0, <Identifier>name);
806+
let message = meaning === SymbolFlags.Namespace ? Diagnostics.Cannot_find_namespace_0 : Diagnostics.Cannot_find_name_0;
807+
808+
symbol = resolveName(name, (<Identifier>name).text, meaning, message, <Identifier>name);
807809
if (!symbol) {
808810
return undefined;
809811
}
@@ -855,10 +857,11 @@ module ts {
855857
return symbol;
856858
}
857859
}
860+
let fileName: string;
858861
let sourceFile: SourceFile;
859862
while (true) {
860-
let fileName = normalizePath(combinePaths(searchPath, moduleName));
861-
sourceFile = host.getSourceFile(fileName + ".ts") || host.getSourceFile(fileName + ".d.ts");
863+
fileName = normalizePath(combinePaths(searchPath, moduleName));
864+
sourceFile = forEach(supportedExtensions, extension => host.getSourceFile(fileName + extension));
862865
if (sourceFile || isRelative) {
863866
break;
864867
}
@@ -5382,20 +5385,43 @@ module ts {
53825385
if (!isTypeSubtypeOf(rightType, globalFunctionType)) {
53835386
return type;
53845387
}
5385-
// Target type is type of prototype property
5388+
5389+
let targetType: Type;
53865390
let prototypeProperty = getPropertyOfType(rightType, "prototype");
5387-
if (!prototypeProperty) {
5388-
return type;
5391+
if (prototypeProperty) {
5392+
// Target type is type of the protoype property
5393+
let prototypePropertyType = getTypeOfSymbol(prototypeProperty);
5394+
if (prototypePropertyType !== anyType) {
5395+
targetType = prototypePropertyType;
5396+
}
53895397
}
5390-
let targetType = getTypeOfSymbol(prototypeProperty);
5391-
// Narrow to target type if it is a subtype of current type
5392-
if (isTypeSubtypeOf(targetType, type)) {
5393-
return targetType;
5398+
5399+
if (!targetType) {
5400+
// Target type is type of construct signature
5401+
let constructSignatures: Signature[];
5402+
if (rightType.flags & TypeFlags.Interface) {
5403+
constructSignatures = resolveDeclaredMembers(<InterfaceType>rightType).declaredConstructSignatures;
5404+
}
5405+
else if (rightType.flags & TypeFlags.Anonymous) {
5406+
constructSignatures = getSignaturesOfType(rightType, SignatureKind.Construct);
5407+
}
5408+
5409+
if (constructSignatures && constructSignatures.length) {
5410+
targetType = getUnionType(map(constructSignatures, signature => getReturnTypeOfSignature(getErasedSignature(signature))));
5411+
}
53945412
}
5395-
// If current type is a union type, remove all constituents that aren't subtypes of target type
5396-
if (type.flags & TypeFlags.Union) {
5397-
return getUnionType(filter((<UnionType>type).types, t => isTypeSubtypeOf(t, targetType)));
5413+
5414+
if (targetType) {
5415+
// Narrow to the target type if it's a subtype of the current type
5416+
if (isTypeSubtypeOf(targetType, type)) {
5417+
return targetType;
5418+
}
5419+
// If the current type is a union type, remove all constituents that aren't subtypes of the target.
5420+
if (type.flags & TypeFlags.Union) {
5421+
return getUnionType(filter((<UnionType>type).types, t => isTypeSubtypeOf(t, targetType)));
5422+
}
53985423
}
5424+
53995425
return type;
54005426
}
54015427

src/compiler/core.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -640,16 +640,18 @@ module ts {
640640
return pathLen > extLen && path.substr(pathLen - extLen, extLen) === extension;
641641
}
642642

643-
let supportedExtensions = [".d.ts", ".ts", ".js"];
643+
/**
644+
* List of supported extensions in order of file resolution precedence.
645+
*/
646+
export const supportedExtensions = [".ts", ".d.ts"];
644647

648+
const extensionsToRemove = [".d.ts", ".ts", ".js"];
645649
export function removeFileExtension(path: string): string {
646-
for (let ext of supportedExtensions) {
647-
650+
for (let ext of extensionsToRemove) {
648651
if (fileExtensionIs(path, ext)) {
649652
return path.substr(0, path.length - ext.length);
650653
}
651654
}
652-
653655
return path;
654656
}
655657

src/compiler/diagnosticInformationMap.generated.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,7 @@ module ts {
364364
A_class_can_only_implement_an_identifier_Slashqualified_name_with_optional_type_arguments: { code: 2500, category: DiagnosticCategory.Error, key: "A class can only implement an identifier/qualified-name with optional type arguments." },
365365
A_rest_element_cannot_contain_a_binding_pattern: { code: 2501, category: DiagnosticCategory.Error, key: "A rest element cannot contain a binding pattern." },
366366
_0_is_referenced_directly_or_indirectly_in_its_own_type_annotation: { code: 2502, category: DiagnosticCategory.Error, key: "'{0}' is referenced directly or indirectly in its own type annotation." },
367+
Cannot_find_namespace_0: { code: 2503, category: DiagnosticCategory.Error, key: "Cannot find namespace '{0}'." },
367368
Import_declaration_0_is_using_private_name_1: { code: 4000, category: DiagnosticCategory.Error, key: "Import declaration '{0}' is using private name '{1}'." },
368369
Type_parameter_0_of_exported_class_has_or_is_using_private_name_1: { code: 4002, category: DiagnosticCategory.Error, key: "Type parameter '{0}' of exported class has or is using private name '{1}'." },
369370
Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1: { code: 4004, category: DiagnosticCategory.Error, key: "Type parameter '{0}' of exported interface has or is using private name '{1}'." },
@@ -497,7 +498,7 @@ module ts {
497498
Corrupted_locale_file_0: { code: 6051, category: DiagnosticCategory.Error, key: "Corrupted locale file {0}." },
498499
Raise_error_on_expressions_and_declarations_with_an_implied_any_type: { code: 6052, category: DiagnosticCategory.Message, key: "Raise error on expressions and declarations with an implied 'any' type." },
499500
File_0_not_found: { code: 6053, category: DiagnosticCategory.Error, key: "File '{0}' not found." },
500-
File_0_must_have_extension_ts_or_d_ts: { code: 6054, category: DiagnosticCategory.Error, key: "File '{0}' must have extension '.ts' or '.d.ts'." },
501+
File_0_has_unsupported_extension_The_only_supported_extensions_are_1: { code: 6054, category: DiagnosticCategory.Error, key: "File '{0}' has unsupported extension. The only supported extensions are {1}." },
501502
Suppress_noImplicitAny_errors_for_indexing_objects_lacking_index_signatures: { code: 6055, category: DiagnosticCategory.Message, key: "Suppress noImplicitAny errors for indexing objects lacking index signatures." },
502503
Do_not_emit_declarations_for_code_that_has_an_internal_annotation: { code: 6056, category: DiagnosticCategory.Message, key: "Do not emit declarations for code that has an '@internal' annotation." },
503504
Preserve_new_lines_when_emitting_code: { code: 6057, category: DiagnosticCategory.Message, key: "Preserve new-lines when emitting code." },

src/compiler/diagnosticMessages.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1444,6 +1444,10 @@
14441444
"category": "Error",
14451445
"code": 2502
14461446
},
1447+
"Cannot find namespace '{0}'.": {
1448+
"category": "Error",
1449+
"code": 2503
1450+
},
14471451

14481452
"Import declaration '{0}' is using private name '{1}'.": {
14491453
"category": "Error",
@@ -1978,7 +1982,7 @@
19781982
"category": "Error",
19791983
"code": 6053
19801984
},
1981-
"File '{0}' must have extension '.ts' or '.d.ts'.": {
1985+
"File '{0}' has unsupported extension. The only supported extensions are {1}.": {
19821986
"category": "Error",
19831987
"code": 6054
19841988
},

src/compiler/emitter.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3898,6 +3898,8 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
38983898
emitToken(SyntaxKind.CloseBraceToken, node.members.end);
38993899
scopeEmitEnd();
39003900

3901+
// TODO(rbuckton): Need to go back to `let _a = class C {}` approach, removing the defineProperty call for now.
3902+
39013903
// For a decorated class, we need to assign its name (if it has one). This is because we emit
39023904
// the class as a class expression to avoid the double-binding of the identifier:
39033905
//
@@ -3907,15 +3909,6 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
39073909
//
39083910
if (thisNodeIsDecorated) {
39093911
write(";");
3910-
if (node.name) {
3911-
writeLine();
3912-
write("Object.defineProperty(");
3913-
emitDeclarationName(node);
3914-
write(", \"name\", { value: \"");
3915-
emitDeclarationName(node);
3916-
write("\", configurable: true });");
3917-
writeLine();
3918-
}
39193912
}
39203913

39213914
// Emit static property assignment. Because classDeclaration is lexically evaluated,

src/compiler/program.ts

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -307,38 +307,45 @@ module ts {
307307
function processSourceFile(fileName: string, isDefaultLib: boolean, refFile?: SourceFile, refPos?: number, refEnd?: number) {
308308
let start: number;
309309
let length: number;
310+
let extensions: string;
311+
let diagnosticArgument: string[];
310312
if (refEnd !== undefined && refPos !== undefined) {
311313
start = refPos;
312314
length = refEnd - refPos;
313315
}
314316
let diagnostic: DiagnosticMessage;
315317
if (hasExtension(fileName)) {
316-
if (!options.allowNonTsExtensions && !fileExtensionIs(host.getCanonicalFileName(fileName), ".ts")) {
317-
diagnostic = Diagnostics.File_0_must_have_extension_ts_or_d_ts;
318+
if (!options.allowNonTsExtensions && !forEach(supportedExtensions, extension => fileExtensionIs(host.getCanonicalFileName(fileName), extension))) {
319+
diagnostic = Diagnostics.File_0_has_unsupported_extension_The_only_supported_extensions_are_1;
320+
diagnosticArgument = [fileName, "'" + supportedExtensions.join("', '") + "'"];
318321
}
319322
else if (!findSourceFile(fileName, isDefaultLib, refFile, refPos, refEnd)) {
320323
diagnostic = Diagnostics.File_0_not_found;
324+
diagnosticArgument = [fileName];
321325
}
322326
else if (refFile && host.getCanonicalFileName(fileName) === host.getCanonicalFileName(refFile.fileName)) {
323327
diagnostic = Diagnostics.A_file_cannot_have_a_reference_to_itself;
328+
diagnosticArgument = [fileName];
324329
}
325330
}
326331
else {
327332
if (options.allowNonTsExtensions && !findSourceFile(fileName, isDefaultLib, refFile, refPos, refEnd)) {
328333
diagnostic = Diagnostics.File_0_not_found;
334+
diagnosticArgument = [fileName];
329335
}
330-
else if (!findSourceFile(fileName + ".ts", isDefaultLib, refFile, refPos, refEnd) && !findSourceFile(fileName + ".d.ts", isDefaultLib, refFile, refPos, refEnd)) {
336+
else if (!forEach(supportedExtensions, extension => findSourceFile(fileName + extension, isDefaultLib, refFile, refPos, refEnd))) {
331337
diagnostic = Diagnostics.File_0_not_found;
332338
fileName += ".ts";
339+
diagnosticArgument = [fileName];
333340
}
334341
}
335342

336343
if (diagnostic) {
337344
if (refFile) {
338-
diagnostics.add(createFileDiagnostic(refFile, start, length, diagnostic, fileName));
345+
diagnostics.add(createFileDiagnostic(refFile, start, length, diagnostic, ...diagnosticArgument));
339346
}
340347
else {
341-
diagnostics.add(createCompilerDiagnostic(diagnostic, fileName));
348+
diagnostics.add(createCompilerDiagnostic(diagnostic, ...diagnosticArgument));
342349
}
343350
}
344351
}
@@ -417,9 +424,10 @@ module ts {
417424
let moduleNameText = (<LiteralExpression>moduleNameExpr).text;
418425
if (moduleNameText) {
419426
let searchPath = basePath;
427+
let searchName: string;
420428
while (true) {
421-
let searchName = normalizePath(combinePaths(searchPath, moduleNameText));
422-
if (findModuleSourceFile(searchName + ".ts", moduleNameExpr) || findModuleSourceFile(searchName + ".d.ts", moduleNameExpr)) {
429+
searchName = normalizePath(combinePaths(searchPath, moduleNameText));
430+
if (forEach(supportedExtensions, extension => findModuleSourceFile(searchName + extension, moduleNameExpr))) {
423431
break;
424432
}
425433
let parentPath = getDirectoryPath(searchPath);
@@ -448,10 +456,7 @@ module ts {
448456
// An ExternalImportDeclaration in anAmbientExternalModuleDeclaration may reference other external modules
449457
// only through top - level external module names. Relative external module names are not permitted.
450458
let searchName = normalizePath(combinePaths(basePath, moduleName));
451-
let tsFile = findModuleSourceFile(searchName + ".ts", nameLiteral);
452-
if (!tsFile) {
453-
findModuleSourceFile(searchName + ".d.ts", nameLiteral);
454-
}
459+
forEach(supportedExtensions, extension => findModuleSourceFile(searchName + extension, nameLiteral));
455460
}
456461
}
457462
});

0 commit comments

Comments
 (0)