Skip to content

Commit b702765

Browse files
author
Yui T
committed
Merge branch 'master' into duplicateIdentifierBindingElement
2 parents 38b1bb0 + e0931d8 commit b702765

File tree

95 files changed

+1970
-2059
lines changed

Some content is hidden

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

95 files changed

+1970
-2059
lines changed

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
}
@@ -5375,20 +5378,43 @@ module ts {
53755378
if (!isTypeSubtypeOf(rightType, globalFunctionType)) {
53765379
return type;
53775380
}
5378-
// Target type is type of prototype property
5381+
5382+
let targetType: Type;
53795383
let prototypeProperty = getPropertyOfType(rightType, "prototype");
5380-
if (!prototypeProperty) {
5381-
return type;
5384+
if (prototypeProperty) {
5385+
// Target type is type of the protoype property
5386+
let prototypePropertyType = getTypeOfSymbol(prototypeProperty);
5387+
if (prototypePropertyType !== anyType) {
5388+
targetType = prototypePropertyType;
5389+
}
53825390
}
5383-
let targetType = getTypeOfSymbol(prototypeProperty);
5384-
// Narrow to target type if it is a subtype of current type
5385-
if (isTypeSubtypeOf(targetType, type)) {
5386-
return targetType;
5391+
5392+
if (!targetType) {
5393+
// Target type is type of construct signature
5394+
let constructSignatures: Signature[];
5395+
if (rightType.flags & TypeFlags.Interface) {
5396+
constructSignatures = resolveDeclaredMembers(<InterfaceType>rightType).declaredConstructSignatures;
5397+
}
5398+
else if (rightType.flags & TypeFlags.Anonymous) {
5399+
constructSignatures = getSignaturesOfType(rightType, SignatureKind.Construct);
5400+
}
5401+
5402+
if (constructSignatures && constructSignatures.length) {
5403+
targetType = getUnionType(map(constructSignatures, signature => getReturnTypeOfSignature(getErasedSignature(signature))));
5404+
}
53875405
}
5388-
// If current type is a union type, remove all constituents that aren't subtypes of target type
5389-
if (type.flags & TypeFlags.Union) {
5390-
return getUnionType(filter((<UnionType>type).types, t => isTypeSubtypeOf(t, targetType)));
5406+
5407+
if (targetType) {
5408+
// Narrow to the target type if it's a subtype of the current type
5409+
if (isTypeSubtypeOf(targetType, type)) {
5410+
return targetType;
5411+
}
5412+
// If the current type is a union type, remove all constituents that aren't subtypes of the target.
5413+
if (type.flags & TypeFlags.Union) {
5414+
return getUnionType(filter((<UnionType>type).types, t => isTypeSubtypeOf(t, targetType)));
5415+
}
53915416
}
5417+
53925418
return type;
53935419
}
53945420

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: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,12 @@ module ts {
219219
// Create the emit resolver outside of the "emitTime" tracking code below. That way
220220
// any cost associated with it (like type checking) are appropriate associated with
221221
// the type-checking counter.
222-
let emitResolver = getDiagnosticsProducingTypeChecker().getEmitResolver(sourceFile);
222+
//
223+
// If the -out option is specified, we should not pass the source file to getEmitResolver.
224+
// This is because in the -out scenario all files need to be emitted, and therefore all
225+
// files need to be type checked. And the way to specify that all files need to be type
226+
// checked is to not pass the file to getEmitResolver.
227+
let emitResolver = getDiagnosticsProducingTypeChecker().getEmitResolver(options.out ? undefined : sourceFile);
223228

224229
let start = new Date().getTime();
225230

@@ -307,38 +312,45 @@ module ts {
307312
function processSourceFile(fileName: string, isDefaultLib: boolean, refFile?: SourceFile, refPos?: number, refEnd?: number) {
308313
let start: number;
309314
let length: number;
315+
let extensions: string;
316+
let diagnosticArgument: string[];
310317
if (refEnd !== undefined && refPos !== undefined) {
311318
start = refPos;
312319
length = refEnd - refPos;
313320
}
314321
let diagnostic: DiagnosticMessage;
315322
if (hasExtension(fileName)) {
316-
if (!options.allowNonTsExtensions && !fileExtensionIs(host.getCanonicalFileName(fileName), ".ts")) {
317-
diagnostic = Diagnostics.File_0_must_have_extension_ts_or_d_ts;
323+
if (!options.allowNonTsExtensions && !forEach(supportedExtensions, extension => fileExtensionIs(host.getCanonicalFileName(fileName), extension))) {
324+
diagnostic = Diagnostics.File_0_has_unsupported_extension_The_only_supported_extensions_are_1;
325+
diagnosticArgument = [fileName, "'" + supportedExtensions.join("', '") + "'"];
318326
}
319327
else if (!findSourceFile(fileName, isDefaultLib, refFile, refPos, refEnd)) {
320328
diagnostic = Diagnostics.File_0_not_found;
329+
diagnosticArgument = [fileName];
321330
}
322331
else if (refFile && host.getCanonicalFileName(fileName) === host.getCanonicalFileName(refFile.fileName)) {
323332
diagnostic = Diagnostics.A_file_cannot_have_a_reference_to_itself;
333+
diagnosticArgument = [fileName];
324334
}
325335
}
326336
else {
327337
if (options.allowNonTsExtensions && !findSourceFile(fileName, isDefaultLib, refFile, refPos, refEnd)) {
328338
diagnostic = Diagnostics.File_0_not_found;
339+
diagnosticArgument = [fileName];
329340
}
330-
else if (!findSourceFile(fileName + ".ts", isDefaultLib, refFile, refPos, refEnd) && !findSourceFile(fileName + ".d.ts", isDefaultLib, refFile, refPos, refEnd)) {
341+
else if (!forEach(supportedExtensions, extension => findSourceFile(fileName + extension, isDefaultLib, refFile, refPos, refEnd))) {
331342
diagnostic = Diagnostics.File_0_not_found;
332343
fileName += ".ts";
344+
diagnosticArgument = [fileName];
333345
}
334346
}
335347

336348
if (diagnostic) {
337349
if (refFile) {
338-
diagnostics.add(createFileDiagnostic(refFile, start, length, diagnostic, fileName));
350+
diagnostics.add(createFileDiagnostic(refFile, start, length, diagnostic, ...diagnosticArgument));
339351
}
340352
else {
341-
diagnostics.add(createCompilerDiagnostic(diagnostic, fileName));
353+
diagnostics.add(createCompilerDiagnostic(diagnostic, ...diagnosticArgument));
342354
}
343355
}
344356
}
@@ -417,9 +429,10 @@ module ts {
417429
let moduleNameText = (<LiteralExpression>moduleNameExpr).text;
418430
if (moduleNameText) {
419431
let searchPath = basePath;
432+
let searchName: string;
420433
while (true) {
421-
let searchName = normalizePath(combinePaths(searchPath, moduleNameText));
422-
if (findModuleSourceFile(searchName + ".ts", moduleNameExpr) || findModuleSourceFile(searchName + ".d.ts", moduleNameExpr)) {
434+
searchName = normalizePath(combinePaths(searchPath, moduleNameText));
435+
if (forEach(supportedExtensions, extension => findModuleSourceFile(searchName + extension, moduleNameExpr))) {
423436
break;
424437
}
425438
let parentPath = getDirectoryPath(searchPath);
@@ -448,10 +461,7 @@ module ts {
448461
// An ExternalImportDeclaration in anAmbientExternalModuleDeclaration may reference other external modules
449462
// only through top - level external module names. Relative external module names are not permitted.
450463
let searchName = normalizePath(combinePaths(basePath, moduleName));
451-
let tsFile = findModuleSourceFile(searchName + ".ts", nameLiteral);
452-
if (!tsFile) {
453-
findModuleSourceFile(searchName + ".d.ts", nameLiteral);
454-
}
464+
forEach(supportedExtensions, extension => findModuleSourceFile(searchName + extension, nameLiteral));
455465
}
456466
}
457467
});

src/compiler/utilities.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -484,9 +484,6 @@ module ts {
484484
case SyntaxKind.IndexSignature:
485485
case SyntaxKind.FunctionType:
486486
case SyntaxKind.ConstructorType:
487-
case SyntaxKind.FunctionExpression:
488-
case SyntaxKind.ArrowFunction:
489-
case SyntaxKind.FunctionDeclaration:
490487
return true;
491488
}
492489
}

src/harness/fourslash.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -144,10 +144,10 @@ module FourSlash {
144144
if (globalOptions.hasOwnProperty(prop)) {
145145
switch (prop) {
146146
case metadataOptionNames.allowNonTsExtensions:
147-
settings.allowNonTsExtensions = true;
147+
settings.allowNonTsExtensions = globalOptions[prop] === "true";
148148
break;
149149
case metadataOptionNames.declaration:
150-
settings.declaration = true;
150+
settings.declaration = globalOptions[prop] === "true";
151151
break;
152152
case metadataOptionNames.mapRoot:
153153
settings.mapRoot = globalOptions[prop];
@@ -174,7 +174,7 @@ module FourSlash {
174174
settings.outDir = globalOptions[prop];
175175
break;
176176
case metadataOptionNames.sourceMap:
177-
settings.sourceMap = true;
177+
settings.sourceMap = globalOptions[prop] === "true";
178178
break;
179179
case metadataOptionNames.sourceRoot:
180180
settings.sourceRoot = globalOptions[prop];
@@ -308,7 +308,7 @@ module FourSlash {
308308
ts.forEach(testData.files, file => {
309309
// Create map between fileName and its content for easily looking up when resolveReference flag is specified
310310
this.inputFiles[file.fileName] = file.content;
311-
if (!startResolveFileRef && file.fileOptions[metadataOptionNames.resolveReference]) {
311+
if (!startResolveFileRef && file.fileOptions[metadataOptionNames.resolveReference] === "true") {
312312
startResolveFileRef = file;
313313
} else if (startResolveFileRef) {
314314
// If entry point for resolving file references is already specified, report duplication error
@@ -1158,7 +1158,7 @@ module FourSlash {
11581158
var allFourSlashFiles = this.testData.files;
11591159
for (var idx = 0; idx < allFourSlashFiles.length; ++idx) {
11601160
var file = allFourSlashFiles[idx];
1161-
if (file.fileOptions[metadataOptionNames.emitThisFile]) {
1161+
if (file.fileOptions[metadataOptionNames.emitThisFile] === "true") {
11621162
// Find a file with the flag emitThisFile turned on
11631163
emitFiles.push(file);
11641164
}

0 commit comments

Comments
 (0)