Skip to content

Commit 0ef3cd1

Browse files
author
Yui T
committed
Merge branch 'master' into tupleConformance
2 parents 7fe643b + 432fff1 commit 0ef3cd1

File tree

46 files changed

+1319
-754
lines changed

Some content is hidden

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

46 files changed

+1319
-754
lines changed

Jakefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ var servicesSources = [
5757
"services.ts",
5858
"shims.ts",
5959
"signatureHelp.ts",
60-
"utilities.ts"
60+
"utilities.ts",
61+
"navigationBar.ts"
6162
].map(function (f) {
6263
return path.join(servicesDirectory, f);
6364
}));

src/compiler/binder.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ module ts {
337337
break;
338338
case SyntaxKind.SourceFile:
339339
if (isExternalModule(<SourceFile>node)) {
340-
bindAnonymousDeclaration(node, SymbolFlags.ValueModule, '"' + getModuleNameFromFilename((<SourceFile>node).filename) + '"');
340+
bindAnonymousDeclaration(node, SymbolFlags.ValueModule, '"' + removeFileExtension((<SourceFile>node).filename) + '"');
341341
break;
342342
}
343343
default:

src/compiler/checker.ts

Lines changed: 37 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -2575,7 +2575,7 @@ module ts {
25752575
function getStringLiteralType(node: StringLiteralTypeNode): StringLiteralType {
25762576
if (hasProperty(stringLiteralTypes, node.text)) return stringLiteralTypes[node.text];
25772577
var type = stringLiteralTypes[node.text] = <StringLiteralType>createType(TypeFlags.StringLiteral);
2578-
type.text = getSourceTextOfNode(node);
2578+
type.text = getTextOfNode(node);
25792579
return type;
25802580
}
25812581

@@ -5050,10 +5050,21 @@ module ts {
50505050
if (leftType.flags & (TypeFlags.Undefined | TypeFlags.Null)) leftType = rightType;
50515051
if (rightType.flags & (TypeFlags.Undefined | TypeFlags.Null)) rightType = leftType;
50525052

5053-
var leftOk = checkArithmeticOperandType(node.left, leftType, Diagnostics.The_left_hand_side_of_an_arithmetic_operation_must_be_of_type_any_number_or_an_enum_type);
5054-
var rightOk = checkArithmeticOperandType(node.right, rightType, Diagnostics.The_right_hand_side_of_an_arithmetic_operation_must_be_of_type_any_number_or_an_enum_type);
5055-
if (leftOk && rightOk) {
5056-
checkAssignmentOperator(numberType);
5053+
var suggestedOperator: SyntaxKind;
5054+
// if a user tries to apply a bitwise operator to 2 boolean operands
5055+
// try and return them a helpful suggestion
5056+
if ((leftType.flags & TypeFlags.Boolean) &&
5057+
(rightType.flags & TypeFlags.Boolean) &&
5058+
(suggestedOperator = getSuggestedBooleanOperator(node.operator)) !== undefined) {
5059+
error(node, Diagnostics.The_0_operator_is_not_allowed_for_boolean_types_Consider_using_1_instead, tokenToString(node.operator), tokenToString(suggestedOperator));
5060+
}
5061+
else {
5062+
// otherwise just check each operand separately and report errors as normal
5063+
var leftOk = checkArithmeticOperandType(node.left, leftType, Diagnostics.The_left_hand_side_of_an_arithmetic_operation_must_be_of_type_any_number_or_an_enum_type);
5064+
var rightOk = checkArithmeticOperandType(node.right, rightType, Diagnostics.The_right_hand_side_of_an_arithmetic_operation_must_be_of_type_any_number_or_an_enum_type);
5065+
if (leftOk && rightOk) {
5066+
checkAssignmentOperator(numberType);
5067+
}
50575068
}
50585069

50595070
return numberType;
@@ -5118,6 +5129,22 @@ module ts {
51185129
case SyntaxKind.CommaToken:
51195130
return rightType;
51205131
}
5132+
5133+
function getSuggestedBooleanOperator(operator: SyntaxKind): SyntaxKind {
5134+
switch (operator) {
5135+
case SyntaxKind.BarToken:
5136+
case SyntaxKind.BarEqualsToken:
5137+
return SyntaxKind.BarBarToken;
5138+
case SyntaxKind.CaretToken:
5139+
case SyntaxKind.CaretEqualsToken:
5140+
return SyntaxKind.ExclamationEqualsEqualsToken;
5141+
case SyntaxKind.AmpersandToken:
5142+
case SyntaxKind.AmpersandEqualsToken:
5143+
return SyntaxKind.AmpersandAmpersandToken;
5144+
default:
5145+
return undefined;
5146+
}
5147+
}
51215148

51225149
function checkAssignmentOperator(valueType: Type): void {
51235150
if (fullTypeCheck && operator >= SyntaxKind.FirstAssignment && operator <= SyntaxKind.LastAssignment) {
@@ -5658,6 +5685,10 @@ module ts {
56585685
var isConstructor = (symbol.flags & SymbolFlags.Constructor) !== 0;
56595686

56605687
function reportImplementationExpectedError(node: FunctionDeclaration): void {
5688+
if (node.name && node.name.kind === SyntaxKind.Missing) {
5689+
return;
5690+
}
5691+
56615692
var seen = false;
56625693
var subsequentNode = forEachChild(node.parent, c => {
56635694
if (seen) {
@@ -7099,23 +7130,6 @@ module ts {
70997130
return mapToArray(symbols);
71007131
}
71017132

7102-
// True if the given identifier is the name of a type declaration node (class, interface, enum, type parameter, etc)
7103-
function isTypeDeclarationName(name: Node): boolean {
7104-
return name.kind == SyntaxKind.Identifier &&
7105-
isTypeDeclaration(name.parent) &&
7106-
(<Declaration>name.parent).name === name;
7107-
}
7108-
7109-
function isTypeDeclaration(node: Node): boolean {
7110-
switch (node.kind) {
7111-
case SyntaxKind.TypeParameter:
7112-
case SyntaxKind.ClassDeclaration:
7113-
case SyntaxKind.InterfaceDeclaration:
7114-
case SyntaxKind.EnumDeclaration:
7115-
return true;
7116-
}
7117-
}
7118-
71197133
// True if the given identifier is part of a type reference
71207134
function isTypeReferenceIdentifier(entityName: EntityName): boolean {
71217135
var node: Node = entityName;
@@ -7194,75 +7208,6 @@ module ts {
71947208
return false;
71957209
}
71967210

7197-
function isTypeNode(node: Node): boolean {
7198-
if (node.kind >= SyntaxKind.FirstTypeNode && node.kind <= SyntaxKind.LastTypeNode) {
7199-
return true;
7200-
}
7201-
7202-
switch (node.kind) {
7203-
case SyntaxKind.AnyKeyword:
7204-
case SyntaxKind.NumberKeyword:
7205-
case SyntaxKind.StringKeyword:
7206-
case SyntaxKind.BooleanKeyword:
7207-
return true;
7208-
case SyntaxKind.VoidKeyword:
7209-
return node.parent.kind !== SyntaxKind.PrefixOperator;
7210-
case SyntaxKind.StringLiteral:
7211-
// Specialized signatures can have string literals as their parameters' type names
7212-
return node.parent.kind === SyntaxKind.Parameter;
7213-
// Identifiers and qualified names may be type nodes, depending on their context. Climb
7214-
// above them to find the lowest container
7215-
case SyntaxKind.Identifier:
7216-
// If the identifier is the RHS of a qualified name, then it's a type iff its parent is.
7217-
if (node.parent.kind === SyntaxKind.QualifiedName) {
7218-
node = node.parent;
7219-
}
7220-
// Fall through
7221-
case SyntaxKind.QualifiedName:
7222-
// At this point, node is either a qualified name or an identifier
7223-
var parent = node.parent;
7224-
if (parent.kind === SyntaxKind.TypeQuery) {
7225-
return false;
7226-
}
7227-
// Do not recursively call isTypeNode on the parent. In the example:
7228-
//
7229-
// var a: A.B.C;
7230-
//
7231-
// Calling isTypeNode would consider the qualified name A.B a type node. Only C or
7232-
// A.B.C is a type node.
7233-
if (parent.kind >= SyntaxKind.FirstTypeNode && parent.kind <= SyntaxKind.LastTypeNode) {
7234-
return true;
7235-
}
7236-
switch (parent.kind) {
7237-
case SyntaxKind.TypeParameter:
7238-
return node === (<TypeParameterDeclaration>parent).constraint;
7239-
case SyntaxKind.Property:
7240-
case SyntaxKind.Parameter:
7241-
case SyntaxKind.VariableDeclaration:
7242-
return node === (<VariableDeclaration>parent).type;
7243-
case SyntaxKind.FunctionDeclaration:
7244-
case SyntaxKind.FunctionExpression:
7245-
case SyntaxKind.ArrowFunction:
7246-
case SyntaxKind.Constructor:
7247-
case SyntaxKind.Method:
7248-
case SyntaxKind.GetAccessor:
7249-
case SyntaxKind.SetAccessor:
7250-
return node === (<FunctionDeclaration>parent).type;
7251-
case SyntaxKind.CallSignature:
7252-
case SyntaxKind.ConstructSignature:
7253-
case SyntaxKind.IndexSignature:
7254-
return node === (<SignatureDeclaration>parent).type;
7255-
case SyntaxKind.TypeAssertion:
7256-
return node === (<TypeAssertion>parent).type;
7257-
case SyntaxKind.CallExpression:
7258-
case SyntaxKind.NewExpression:
7259-
return (<CallExpression>parent).typeArguments.indexOf(node) >= 0;
7260-
}
7261-
}
7262-
7263-
return false;
7264-
}
7265-
72667211
function isInRightSideOfImportOrExportAssignment(node: EntityName) {
72677212
while (node.parent.kind === SyntaxKind.QualifiedName) {
72687213
node = node.parent;
@@ -7516,7 +7461,7 @@ module ts {
75167461
while (!isUniqueLocalName(escapeIdentifier(prefix + name), container)) {
75177462
prefix += "_";
75187463
}
7519-
links.localModuleName = prefix + getSourceTextOfNode(container.name);
7464+
links.localModuleName = prefix + getTextOfNode(container.name);
75207465
}
75217466
return links.localModuleName;
75227467
}

src/compiler/core.ts

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -209,11 +209,9 @@ module ts {
209209
export var localizedDiagnosticMessages: Map<string> = undefined;
210210

211211
export function getLocaleSpecificMessage(message: string) {
212-
if (ts.localizedDiagnosticMessages) {
213-
message = localizedDiagnosticMessages[message];
214-
}
215-
216-
return message;
212+
return localizedDiagnosticMessages && localizedDiagnosticMessages[message]
213+
? localizedDiagnosticMessages[message]
214+
: message;
217215
}
218216

219217
export function createFileDiagnostic(file: SourceFile, start: number, length: number, message: DiagnosticMessage, ...args: any[]): Diagnostic;
@@ -535,6 +533,43 @@ module ts {
535533
return pathLen > extLen && path.substr(pathLen - extLen, extLen) === extension;
536534
}
537535

536+
var supportedExtensions = [".d.ts", ".ts", ".js"];
537+
538+
export function removeFileExtension(path: string): string {
539+
for (var i = 0; i < supportedExtensions.length; i++) {
540+
var ext = supportedExtensions[i];
541+
542+
if (fileExtensionIs(path, ext)) {
543+
return path.substr(0, path.length - ext.length);
544+
}
545+
}
546+
547+
return path;
548+
}
549+
550+
var escapedCharsRegExp = /[\t\v\f\b\0\r\n\"\\\u2028\u2029\u0085]/g;
551+
var escapedCharsMap: Map<string> = {
552+
"\t": "\\t",
553+
"\v": "\\v",
554+
"\f": "\\f",
555+
"\b": "\\b",
556+
"\0": "\\0",
557+
"\r": "\\r",
558+
"\n": "\\n",
559+
"\"": "\\\"",
560+
"\u2028": "\\u2028", // lineSeparator
561+
"\u2029": "\\u2029", // paragraphSeparator
562+
"\u0085": "\\u0085" // nextLine
563+
};
564+
565+
/** NOTE: This *does not* support the full escape characters, it only supports the subset that can be used in file names
566+
* or string literals. If the information encoded in the map changes, this needs to be revisited. */
567+
export function escapeString(s: string): string {
568+
return escapedCharsRegExp.test(s) ? s.replace(escapedCharsRegExp, c => {
569+
return escapedCharsMap[c] || c;
570+
}) : s;
571+
}
572+
538573
export interface ObjectAllocator {
539574
getNodeConstructor(kind: SyntaxKind): new () => Node;
540575
getSymbolConstructor(): new (flags: SymbolFlags, name: string) => Symbol;

src/compiler/diagnosticInformationMap.generated.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,7 @@ module ts {
261261
Property_0_is_protected_in_type_1_but_public_in_type_2: { code: 2444, category: DiagnosticCategory.Error, key: "Property '{0}' is protected in type '{1}' but public in type '{2}'." },
262262
Property_0_is_protected_and_only_accessible_within_class_1_and_its_subclasses: { code: 2445, category: DiagnosticCategory.Error, key: "Property '{0}' is protected and only accessible within class '{1}' and its subclasses." },
263263
Property_0_is_protected_and_only_accessible_through_an_instance_of_class_1: { code: 2446, category: DiagnosticCategory.Error, key: "Property '{0}' is protected and only accessible through an instance of class '{1}'." },
264+
The_0_operator_is_not_allowed_for_boolean_types_Consider_using_1_instead: { code: 2447, category: DiagnosticCategory.Error, key: "The '{0}' operator is not allowed for boolean types. Consider using '{1}' instead." },
264265
Import_declaration_0_is_using_private_name_1: { code: 4000, category: DiagnosticCategory.Error, key: "Import declaration '{0}' is using private name '{1}'." },
265266
Type_parameter_0_of_exported_class_has_or_is_using_name_1_from_private_module_2: { code: 4001, category: DiagnosticCategory.Error, key: "Type parameter '{0}' of exported class has or is using name '{1}' from private module '{2}'." },
266267
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}'." },

src/compiler/diagnosticMessages.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1036,6 +1036,10 @@
10361036
"category": "Error",
10371037
"code": 2446
10381038
},
1039+
"The '{0}' operator is not allowed for boolean types. Consider using '{1}' instead.": {
1040+
"category": "Error",
1041+
"code": 2447
1042+
},
10391043

10401044
"Import declaration '{0}' is using private name '{1}'.": {
10411045
"category": "Error",

src/compiler/emitter.ts

Lines changed: 4 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,10 @@ module ts {
5656

5757
function getOwnEmitOutputFilePath(sourceFile: SourceFile, extension: string) {
5858
if (compilerOptions.outDir) {
59-
var emitOutputFilePathWithoutExtension = getModuleNameFromFilename(getSourceFilePathInNewDir(compilerOptions.outDir, sourceFile));
59+
var emitOutputFilePathWithoutExtension = removeFileExtension(getSourceFilePathInNewDir(compilerOptions.outDir, sourceFile));
6060
}
6161
else {
62-
var emitOutputFilePathWithoutExtension = getModuleNameFromFilename(sourceFile.filename);
62+
var emitOutputFilePathWithoutExtension = removeFileExtension(sourceFile.filename);
6363
}
6464

6565
return emitOutputFilePathWithoutExtension + extension;
@@ -591,21 +591,6 @@ module ts {
591591
recordSourceMapSpan(comment.end);
592592
}
593593

594-
var escapedCharsRegExp = /[\t\v\f\b\0\r\n\"\u2028\u2029\u0085]/g;
595-
var escapedCharsMap: Map<string> = {
596-
"\t": "\\t",
597-
"\v": "\\v",
598-
"\f": "\\f",
599-
"\b": "\\b",
600-
"\0": "\\0",
601-
"\r": "\\r",
602-
"\n": "\\n",
603-
"\"": "\\\"",
604-
"\u2028": "\\u2028", // lineSeparator
605-
"\u2029": "\\u2029", // paragraphSeparator
606-
"\u0085": "\\u0085" // nextLine
607-
};
608-
609594
function serializeSourceMapContents(version: number, file: string, sourceRoot: string, sources: string[], names: string[], mappings: string) {
610595
if (typeof JSON !== "undefined") {
611596
return JSON.stringify({
@@ -620,14 +605,6 @@ module ts {
620605

621606
return "{\"version\":" + version + ",\"file\":\"" + escapeString(file) + "\",\"sourceRoot\":\"" + escapeString(sourceRoot) + "\",\"sources\":[" + serializeStringArray(sources) + "],\"names\":[" + serializeStringArray(names) + "],\"mappings\":\"" + escapeString(mappings) + "\"}";
622607

623-
/** This does not support the full escape characters, it only supports the subset that can be used in file names
624-
* or string literals. If the information encoded in the map changes, this needs to be revisited. */
625-
function escapeString(s: string): string {
626-
return escapedCharsRegExp.test(s) ? s.replace(escapedCharsRegExp, c => {
627-
return escapedCharsMap[c] || c;
628-
}) : s;
629-
}
630-
631608
function serializeStringArray(list: string[]): string {
632609
var output = "";
633610
for (var i = 0, n = list.length; i < n; i++) {
@@ -3164,7 +3141,7 @@ module ts {
31643141
? referencedFile.filename // Declaration file, use declaration file name
31653142
: shouldEmitToOwnFile(referencedFile, compilerOptions)
31663143
? getOwnEmitOutputFilePath(referencedFile, ".d.ts") // Own output file so get the .d.ts file
3167-
: getModuleNameFromFilename(compilerOptions.out) + ".d.ts";// Global out file
3144+
: removeFileExtension(compilerOptions.out) + ".d.ts";// Global out file
31683145

31693146
declFileName = getRelativePathToDirectoryOrUrl(
31703147
getDirectoryPath(normalizeSlashes(jsFilePath)),
@@ -3237,7 +3214,7 @@ module ts {
32373214
}
32383215
});
32393216
declarationOutput += synchronousDeclarationOutput.substring(appliedSyncOutputPos);
3240-
writeFile(getModuleNameFromFilename(jsFilePath) + ".d.ts", declarationOutput, compilerOptions.emitBOM);
3217+
writeFile(removeFileExtension(jsFilePath) + ".d.ts", declarationOutput, compilerOptions.emitBOM);
32413218
}
32423219
}
32433220

0 commit comments

Comments
 (0)