Skip to content

Commit a90c62b

Browse files
committed
Merge branch 'master' into tsc
2 parents 9d8cee1 + 39046fa commit a90c62b

Some content is hidden

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

48 files changed

+245
-127
lines changed

src/compiler/checker.ts

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3844,21 +3844,40 @@ module ts {
38443844
}
38453845

38463846
// The candidate list orders groups in reverse, but within a group signatures are kept in declaration order
3847+
// A nit here is that we reorder only signatures that belong to the same symbol,
3848+
// so order how inherited signatures are processed is still preserved.
3849+
// interface A { (x: string): void }
3850+
// interface B extends A { (x: 'foo'): string }
3851+
// var b: B;
3852+
// b('foo') // <- here overloads should be processed as [(x:'foo'): string, (x: string): void]
38473853
function collectCandidates(node: CallExpression, signatures: Signature[]): Signature[]{
38483854
var result: Signature[] = [];
38493855
var lastParent: Node;
3856+
var lastSymbol: Symbol;
3857+
var cutoffPos: number = 0;
38503858
var pos: number;
38513859
for (var i = 0; i < signatures.length; i++) {
38523860
var signature = signatures[i];
38533861
if (isCandidateSignature(node, signature)) {
3854-
var parent = signature.declaration ? signature.declaration.parent : undefined;
3855-
if (lastParent && parent === lastParent) {
3856-
pos++;
3862+
var symbol = signature.declaration && getSymbolOfNode(signature.declaration);
3863+
var parent = signature.declaration && signature.declaration.parent;
3864+
if (!lastSymbol || symbol === lastSymbol) {
3865+
if (lastParent && parent === lastParent) {
3866+
pos++;
3867+
}
3868+
else {
3869+
lastParent = parent;
3870+
pos = cutoffPos;
3871+
}
38573872
}
38583873
else {
3874+
// current declaration belongs to a different symbol
3875+
// set cutoffPos so reorderings in the future won't change result set from 0 to cutoffPos
3876+
pos = cutoffPos = result.length;
38593877
lastParent = parent;
3860-
pos = 0;
38613878
}
3879+
lastSymbol = symbol;
3880+
38623881
for (var j = result.length; j > pos; j--) {
38633882
result[j] = result[j - 1];
38643883
}

src/compiler/core.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ module ts {
174174
var result: Map<T> = {};
175175

176176
forEach(array, value => {
177-
result[makeKey(value)] = value
177+
result[makeKey(value)] = value;
178178
});
179179

180180
return result;

src/compiler/diagnosticInformationMap.generated.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ module ts {
105105
An_object_literal_cannot_have_multiple_get_Slashset_accessors_with_the_same_name: { code: 1118, category: DiagnosticCategory.Error, key: "An object literal cannot have multiple get/set accessors with the same name." },
106106
An_object_literal_cannot_have_property_and_accessor_with_the_same_name: { code: 1119, category: DiagnosticCategory.Error, key: "An object literal cannot have property and accessor with the same name." },
107107
An_export_assignment_cannot_have_modifiers: { code: 1120, category: DiagnosticCategory.Error, key: "An export assignment cannot have modifiers." },
108+
Octal_literals_are_not_allowed_in_strict_mode: { code: 1121, category: DiagnosticCategory.Error, key: "Octal literals are not allowed in strict mode." },
108109
Duplicate_identifier_0: { code: 2000, category: DiagnosticCategory.Error, key: "Duplicate identifier '{0}'." },
109110
Extends_clause_of_exported_class_0_has_or_is_using_private_name_1: { code: 2018, category: DiagnosticCategory.Error, key: "Extends clause of exported class '{0}' has or is using private name '{1}'." },
110111
Implements_clause_of_exported_class_0_has_or_is_using_private_name_1: { code: 2019, category: DiagnosticCategory.Error, key: "Implements clause of exported class '{0}' 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
@@ -412,6 +412,10 @@
412412
"category": "Error",
413413
"code": 1120
414414
},
415+
"Octal literals are not allowed in strict mode.": {
416+
"category": "Error",
417+
"code": 1121
418+
},
415419
"Duplicate identifier '{0}'.": {
416420
"category": "Error",
417421
"code": 2000

src/compiler/parser.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1055,8 +1055,29 @@ module ts {
10551055
function parseLiteralNode(): LiteralExpression {
10561056
var node = <LiteralExpression>createNode(token);
10571057
node.text = scanner.getTokenValue();
1058+
var tokenPos = scanner.getTokenPos();
10581059
nextToken();
1059-
return finishNode(node);
1060+
finishNode(node);
1061+
1062+
// Octal literals are not allowed in strict mode or ES5
1063+
// Note that theoretically the following condition would hold true literals like 009,
1064+
// which is not octal.But because of how the scanner separates the tokens, we would
1065+
// never get a token like this.Instead, we would get 00 and 9 as two separate tokens.
1066+
// We also do not need to check for negatives because any prefix operator would be part of a
1067+
// parent unary expression.
1068+
if (node.kind === SyntaxKind.NumericLiteral
1069+
&& sourceText.charCodeAt(tokenPos) === CharacterCodes._0
1070+
&& isOctalDigit(sourceText.charCodeAt(tokenPos + 1))) {
1071+
1072+
if (isInStrictMode) {
1073+
grammarErrorOnNode(node, Diagnostics.Octal_literals_are_not_allowed_in_strict_mode);
1074+
}
1075+
else if (languageVersion >= ScriptTarget.ES5) {
1076+
grammarErrorOnNode(node, Diagnostics.Octal_literals_are_not_available_when_targeting_ECMAScript_5_and_higher);
1077+
}
1078+
}
1079+
1080+
return node;
10601081
}
10611082

10621083
function parseStringLiteral(): LiteralExpression {

src/compiler/scanner.ts

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,10 @@ module ts {
300300
return ch >= CharacterCodes._0 && ch <= CharacterCodes._9;
301301
}
302302

303+
export function isOctalDigit(ch: number): boolean {
304+
return ch >= CharacterCodes._0 && ch <= CharacterCodes._7;
305+
}
306+
303307
export function skipTrivia(text: string, pos: number, stopAfterLineBreak?: boolean): number {
304308
while (true) {
305309
var ch = text.charCodeAt(pos);
@@ -360,7 +364,9 @@ module ts {
360364
var precedingLineBreak: boolean;
361365

362366
function error(message: DiagnosticMessage): void {
363-
if (onError) onError(message);
367+
if (onError) {
368+
onError(message);
369+
}
364370
}
365371

366372
function isIdentifierStart(ch: number): boolean {
@@ -398,6 +404,14 @@ module ts {
398404
return +(text.substring(start, end));
399405
}
400406

407+
function scanOctalDigits(): number {
408+
var start = pos;
409+
while (isOctalDigit(text.charCodeAt(pos))) {
410+
pos++;
411+
}
412+
return +(text.substring(start, pos));
413+
}
414+
401415
function scanHexDigits(count: number, exact?: boolean): number {
402416
var digits = 0;
403417
var value = 0;
@@ -681,7 +695,7 @@ module ts {
681695

682696
if (!commentClosed) {
683697
pos++;
684-
onError(Diagnostics.Asterisk_Slash_expected);
698+
error(Diagnostics.Asterisk_Slash_expected);
685699
}
686700

687701
if (onComment) {
@@ -708,6 +722,14 @@ module ts {
708722
tokenValue = "" + value;
709723
return SyntaxKind.NumericLiteral;
710724
}
725+
// Try to parse as an octal
726+
if (pos + 1 < len && isOctalDigit(text.charCodeAt(pos + 1))) {
727+
tokenValue = "" + scanOctalDigits();
728+
return SyntaxKind.NumericLiteral;
729+
}
730+
// This fall-through is a deviation from the EcmaScript grammar. The grammar says that a leading zero
731+
// can only be followed by an octal digit, a dot, or the end of the number literal. However, we are being
732+
// permissive and allowing decimal digits of the form 08* and 09* (which many browsers also do).
711733
case CharacterCodes._1:
712734
case CharacterCodes._2:
713735
case CharacterCodes._3:

src/compiler/tsc.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -362,8 +362,8 @@ module ts {
362362
var output = "";
363363

364364
// We want to align our "syntax" and "examples" commands to a certain margin.
365-
var syntaxLength = getDiagnosticText(Diagnostics.Syntax_Colon_0, "").length
366-
var examplesLength = getDiagnosticText(Diagnostics.Examples_Colon_0, "").length
365+
var syntaxLength = getDiagnosticText(Diagnostics.Syntax_Colon_0, "").length;
366+
var examplesLength = getDiagnosticText(Diagnostics.Examples_Colon_0, "").length;
367367
var marginLength = Math.max(syntaxLength, examplesLength);
368368

369369
// Build up the syntactic skeleton.

src/compiler/types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -635,8 +635,8 @@ module ts {
635635

636636
export interface SymbolAccessiblityResult {
637637
accessibility: SymbolAccessibility;
638-
errorSymbolName?: string // Optional symbol name that results in error
639-
errorModuleName?: string // If the symbol is not visibile from module, module's name
638+
errorSymbolName?: string; // Optional symbol name that results in error
639+
errorModuleName?: string; // If the symbol is not visibile from module, module's name
640640
}
641641

642642
export interface EmitResolver {

src/harness/compilerRunner.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ class CompilerBaselineRunner extends RunnerBase {
365365
walker.results.forEach(result => {
366366
var formattedLine = result.identifierName + " : " + result.type;
367367
if (!typeMap[file.unitName]) {
368-
typeMap[file.unitName] = {}
368+
typeMap[file.unitName] = {};
369369
}
370370

371371
var typeInfo = [formattedLine];
@@ -386,7 +386,7 @@ class CompilerBaselineRunner extends RunnerBase {
386386
walker.results.forEach(result => {
387387
var formattedLine = result.identifierName + " : " + result.type;
388388
if (!typeMap[file.unitName]) {
389-
typeMap[file.unitName] = {}
389+
typeMap[file.unitName] = {};
390390
} else {
391391
typeLines.push('No type information for this code.');
392392
}

src/harness/exec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class WindowsScriptHostExec implements IExec {
3232
var process = shell.Exec(fileName + ' ' + cmdLineArgs.join(' '));
3333
} catch(e) {
3434
result.stderr = e.message;
35-
result.exitCode = 1
35+
result.exitCode = 1;
3636
handleResult(result);
3737
return;
3838
}

0 commit comments

Comments
 (0)