Skip to content

Commit 73d575e

Browse files
Merge branch 'master' into numbersAreHard
Conflicts: src/compiler/checker.ts tests/baselines/reference/numericIndexerConstrainsPropertyDeclarations.errors.txt tests/baselines/reference/numericIndexerConstrainsPropertyDeclarations2.errors.txt
2 parents ea81831 + 49e606a commit 73d575e

File tree

320 files changed

+7097
-6296
lines changed

Some content is hidden

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

320 files changed

+7097
-6296
lines changed

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Design changes will not be accepted at this time. If you have a design change pr
99
## Legal
1010
You will need to complete a Contributor License Agreement (CLA). Briefly, this agreement testifies that you are granting us permission to use the submitted change according to the terms of the project's license, and that the work being submitted is under appropriate copyright.
1111

12-
Please submit a Contributor License Agreement (CLA) before submitting a pull request. Download the agreement ([Microsoft Contribution License Agreement.docx](https://www.codeplex.com/Download?ProjectName=typescript&DownloadId=822190)), sign, scan, and email it back to <cla@microsoft.com>. Be sure to include your github user name along with the agreement. Once we have received the signed CLA, we'll review the request. Please note that we're currently only accepting pull requests of bug fixes rather than new features.
12+
Please submit a Contributor License Agreement (CLA) before submitting a pull request. Download the agreement ([Microsoft Contribution License Agreement.docx](https://www.codeplex.com/Download?ProjectName=typescript&DownloadId=822190) or [Microsoft Contribution License Agreement.pdf](https://www.codeplex.com/Download?ProjectName=typescript&DownloadId=921298)), sign, scan, and email it back to <cla@microsoft.com>. Be sure to include your github user name along with the agreement. Once we have received the signed CLA, we'll review the request. Please note that we're currently only accepting pull requests of bug fixes rather than new features.
1313

1414
## Housekeeping
1515
Your pull request should:

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
[![Build Status](https://travis-ci.org/Microsoft/TypeScript.svg?branch=master)](https://travis-ci.org/Microsoft/TypeScript)
2+
[![Issue Stats](http://issuestats.com/github/Microsoft/TypeScript/badge/pr)](http://issuestats.com/github/microsoft/typescript)
3+
[![Issue Stats](http://issuestats.com/github/Microsoft/TypeScript/badge/issue)](http://issuestats.com/github/microsoft/typescript)
4+
15
# TypeScript
26

37
[TypeScript](http://www.typescriptlang.org/) is a language for application-scale JavaScript. TypeScript adds optional types, classes, and modules to JavaScript. TypeScript supports tools for large-scale JavaScript applications for any browser, for any host, on any OS. TypeScript compiles to readable, standards-based JavaScript. Try it out at the [playground](http://www.typescriptlang.org/Playground), and stay up to date via [our blog](http://blogs.msdn.com/typescript) and [twitter account](https://twitter.com/typescriptlang).
Binary file not shown.
Binary file not shown.
7.92 KB
Binary file not shown.
35.1 KB
Binary file not shown.

doc/spec.md

Lines changed: 302 additions & 80 deletions
Large diffs are not rendered by default.

src/compiler/checker.ts

Lines changed: 894 additions & 290 deletions
Large diffs are not rendered by default.

src/compiler/core.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ module ts {
8282
return array1.concat(array2);
8383
}
8484

85-
export function uniqueElements<T>(array: T[]): T[] {
85+
export function deduplicate<T>(array: T[]): T[] {
8686
if (array) {
8787
var result: T[] = [];
8888
for (var i = 0, len = array.length; i < len; i++) {

src/compiler/diagnosticInformationMap.generated.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ module ts {
114114
Cannot_compile_external_modules_unless_the_module_flag_is_provided: { code: 1148, category: DiagnosticCategory.Error, key: "Cannot compile external modules unless the '--module' flag is provided." },
115115
Filename_0_differs_from_already_included_filename_1_only_in_casing: { code: 1149, category: DiagnosticCategory.Error, key: "Filename '{0}' differs from already included filename '{1}' only in casing" },
116116
new_T_cannot_be_used_to_create_an_array_Use_new_Array_T_instead: { code: 1150, category: DiagnosticCategory.Error, key: "'new T[]' cannot be used to create an array. Use 'new Array<T>()' instead." },
117+
An_enum_member_cannot_have_a_numeric_name: { code: 1151, category: DiagnosticCategory.Error, key: "An enum member cannot have a numeric name." },
117118
Duplicate_identifier_0: { code: 2300, category: DiagnosticCategory.Error, key: "Duplicate identifier '{0}'." },
118119
Initializer_of_instance_member_variable_0_cannot_reference_identifier_1_declared_in_the_constructor: { code: 2301, category: DiagnosticCategory.Error, key: "Initializer of instance member variable '{0}' cannot reference identifier '{1}' declared in the constructor." },
119120
Static_members_cannot_reference_class_type_parameters: { code: 2302, category: DiagnosticCategory.Error, key: "Static members cannot reference class type parameters." },
@@ -180,8 +181,6 @@ module ts {
180181
The_right_hand_side_of_an_arithmetic_operation_must_be_of_type_any_number_or_an_enum_type: { code: 2363, category: DiagnosticCategory.Error, key: "The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type." },
181182
Invalid_left_hand_side_of_assignment_expression: { code: 2364, category: DiagnosticCategory.Error, key: "Invalid left-hand side of assignment expression." },
182183
Operator_0_cannot_be_applied_to_types_1_and_2: { code: 2365, category: DiagnosticCategory.Error, key: "Operator '{0}' cannot be applied to types '{1}' and '{2}'." },
183-
No_best_common_type_exists_between_0_1_and_2: { code: 2366, category: DiagnosticCategory.Error, key: "No best common type exists between '{0}', '{1}', and '{2}'." },
184-
No_best_common_type_exists_between_0_and_1: { code: 2367, category: DiagnosticCategory.Error, key: "No best common type exists between '{0}' and '{1}'." },
185184
Type_parameter_name_cannot_be_0: { code: 2368, category: DiagnosticCategory.Error, key: "Type parameter name cannot be '{0}'" },
186185
A_parameter_property_is_only_allowed_in_a_constructor_implementation: { code: 2369, category: DiagnosticCategory.Error, key: "A parameter property is only allowed in a constructor implementation." },
187186
A_rest_parameter_must_be_of_an_array_type: { code: 2370, category: DiagnosticCategory.Error, key: "A rest parameter must be of an array type." },

src/compiler/diagnosticMessages.json

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"category": "Error",
1212
"code": 1005
1313
},
14-
"A file cannot have a reference to itself.": {
14+
"A file cannot have a reference to itself.": {
1515
"category": "Error",
1616
"code": 1006
1717
},
@@ -187,7 +187,7 @@
187187
"category": "Error",
188188
"code": 1066
189189
},
190-
"Unexpected token. A constructor, method, accessor, or property was expected." : {
190+
"Unexpected token. A constructor, method, accessor, or property was expected.": {
191191
"category": "Error",
192192
"code": 1068
193193
},
@@ -444,9 +444,13 @@
444444
"code": 1149
445445
},
446446
"'new T[]' cannot be used to create an array. Use 'new Array<T>()' instead.": {
447-
"category": "Error",
448-
"code": 1150
449-
},
447+
"category": "Error",
448+
"code": 1150
449+
},
450+
"An enum member cannot have a numeric name.": {
451+
"category": "Error",
452+
"code": 1151
453+
},
450454

451455
"Duplicate identifier '{0}'.": {
452456
"category": "Error",
@@ -556,7 +560,7 @@
556560
"category": "Error",
557561
"code": 2326
558562
},
559-
"Property '{0}' is optional in type '{1}' but required in type '{2}'.": {
563+
"Property '{0}' is optional in type '{1}' but required in type '{2}'.": {
560564
"category": "Error",
561565
"code": 2327
562566
},
@@ -712,14 +716,6 @@
712716
"category": "Error",
713717
"code": 2365
714718
},
715-
"No best common type exists between '{0}', '{1}', and '{2}'.": {
716-
"category": "Error",
717-
"code": 2366
718-
},
719-
"No best common type exists between '{0}' and '{1}'.": {
720-
"category": "Error",
721-
"code": 2367
722-
},
723719
"Type parameter name cannot be '{0}'": {
724720
"category": "Error",
725721
"code": 2368

src/compiler/emitter.ts

Lines changed: 34 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,11 @@
44
/// <reference path="parser.ts"/>
55

66
module ts {
7-
interface EmitTextWriter extends SymbolWriter {
7+
interface EmitTextWriter {
88
write(s: string): void;
9+
writeLine(): void;
10+
increaseIndent(): void;
11+
decreaseIndent(): void;
912
getText(): string;
1013
rawWrite(s: string): void;
1114
writeLiteral(s: string): void;
@@ -15,6 +18,9 @@ module ts {
1518
getIndent(): number;
1619
}
1720

21+
interface EmitTextWriterWithSymbolWriter extends EmitTextWriter, SymbolWriter{
22+
}
23+
1824
var indentStrings: string[] = ["", " "];
1925
export function getIndentString(level: number) {
2026
if (indentStrings[level] === undefined) {
@@ -28,7 +34,7 @@ module ts {
2834
}
2935

3036
export function shouldEmitToOwnFile(sourceFile: SourceFile, compilerOptions: CompilerOptions): boolean {
31-
if (!(sourceFile.flags & NodeFlags.DeclarationFile)) {
37+
if (!isDeclarationFile(sourceFile)) {
3238
if ((isExternalModule(sourceFile) || !compilerOptions.out) && !fileExtensionIs(sourceFile.filename, ".js")) {
3339
return true;
3440
}
@@ -38,7 +44,7 @@ module ts {
3844
}
3945

4046
export function isExternalModuleOrDeclarationFile(sourceFile: SourceFile) {
41-
return isExternalModule(sourceFile) || (sourceFile.flags & NodeFlags.DeclarationFile) !== 0;
47+
return isExternalModule(sourceFile) || isDeclarationFile(sourceFile);
4248
}
4349

4450
// targetSourceFile is when users only want one file in entire project to be emitted. This is used in compilerOnSave feature
@@ -103,7 +109,7 @@ module ts {
103109
};
104110
}
105111

106-
function createTextWriter(trackSymbol: (symbol: Symbol, enclosingDeclaration?: Node, meaning?: SymbolFlags)=> void): EmitTextWriter {
112+
function createTextWriter(): EmitTextWriter {
107113
var output = "";
108114
var indent = 0;
109115
var lineStart = true;
@@ -149,17 +155,8 @@ module ts {
149155
}
150156
}
151157

152-
function writeKind(text: string, kind: SymbolDisplayPartKind) {
153-
write(text);
154-
}
155-
function writeSymbol(text: string, symbol: Symbol) {
156-
write(text);
157-
}
158158
return {
159159
write: write,
160-
trackSymbol: trackSymbol,
161-
writeKind: writeKind,
162-
writeSymbol: writeSymbol,
163160
rawWrite: rawWrite,
164161
writeLiteral: writeLiteral,
165162
writeLine: writeLine,
@@ -170,7 +167,6 @@ module ts {
170167
getLine: () => lineCount + 1,
171168
getColumn: () => lineStart ? indent * getIndentSize() + 1 : output.length - linePos + 1,
172169
getText: () => output,
173-
clear: () => { }
174170
};
175171
}
176172

@@ -318,7 +314,7 @@ module ts {
318314
}
319315

320316
function emitJavaScript(jsFilePath: string, root?: SourceFile) {
321-
var writer = createTextWriter(trackSymbol);
317+
var writer = createTextWriter();
322318
var write = writer.write;
323319
var writeLine = writer.writeLine;
324320
var increaseIndent = writer.increaseIndent;
@@ -374,8 +370,6 @@ module ts {
374370
/** Sourcemap data that will get encoded */
375371
var sourceMapData: SourceMapData;
376372

377-
function trackSymbol(symbol: Symbol, enclosingDeclaration: Node, meaning: SymbolFlags) { }
378-
379373
function initializeEmitterWithSourceMaps() {
380374
var sourceMapDir: string; // The directory in which sourcemap will be
381375

@@ -2314,7 +2308,7 @@ module ts {
23142308
}
23152309

23162310
function emitDeclarations(jsFilePath: string, root?: SourceFile) {
2317-
var writer = createTextWriter(trackSymbol);
2311+
var writer = createTextWriterWithSymbolWriter();
23182312
var write = writer.write;
23192313
var writeLine = writer.writeLine;
23202314
var increaseIndent = writer.increaseIndent;
@@ -2338,11 +2332,24 @@ module ts {
23382332
typeName?: Identifier
23392333
}
23402334

2335+
function createTextWriterWithSymbolWriter(): EmitTextWriterWithSymbolWriter {
2336+
var writer = <EmitTextWriterWithSymbolWriter>createTextWriter();
2337+
writer.trackSymbol = trackSymbol;
2338+
writer.writeKeyword = writer.write;
2339+
writer.writeOperator = writer.write;
2340+
writer.writePunctuation = writer.write;
2341+
writer.writeSpace = writer.write;
2342+
writer.writeStringLiteral = writer.writeLiteral;
2343+
writer.writeParameter = writer.write;
2344+
writer.writeSymbol = writer.write;
2345+
return writer;
2346+
}
2347+
23412348
function writeAsychronousImportDeclarations(importDeclarations: ImportDeclaration[]) {
23422349
var oldWriter = writer;
23432350
forEach(importDeclarations, aliasToWrite => {
23442351
var aliasEmitInfo = forEach(aliasDeclarationEmitInfo, declEmitInfo => declEmitInfo.declaration === aliasToWrite ? declEmitInfo : undefined);
2345-
writer = createTextWriter(trackSymbol);
2352+
writer = createTextWriterWithSymbolWriter();
23462353
for (var declarationIndent = aliasEmitInfo.indent; declarationIndent; declarationIndent--) {
23472354
writer.increaseIndent();
23482355
}
@@ -3253,14 +3260,17 @@ module ts {
32533260
if (compilerOptions.out) {
32543261
emitFile(compilerOptions.out);
32553262
}
3256-
} else {
3257-
// targetSourceFile is specified (e.g calling emitter from language service)
3263+
}
3264+
else {
3265+
// targetSourceFile is specified (e.g calling emitter from language service or calling getSemanticDiagnostic from language service)
32583266
if (shouldEmitToOwnFile(targetSourceFile, compilerOptions)) {
3259-
// If shouldEmitToOwnFile is true or targetSourceFile is an external module file, then emit targetSourceFile in its own output file
3267+
// If shouldEmitToOwnFile returns true or targetSourceFile is an external module file, then emit targetSourceFile in its own output file
32603268
var jsFilePath = getOwnEmitOutputFilePath(targetSourceFile, ".js");
32613269
emitFile(jsFilePath, targetSourceFile);
3262-
} else {
3263-
// If shouldEmitToOwnFile is false, then emit all, non-external-module file, into one single output file
3270+
}
3271+
else if (!isDeclarationFile(targetSourceFile) && compilerOptions.out) {
3272+
// Otherwise, if --out is specified and targetSourceFile is not a declaration file,
3273+
// Emit all, non-external-module file, into one single output file
32643274
emitFile(compilerOptions.out);
32653275
}
32663276
}

src/compiler/parser.ts

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,10 @@ module ts {
111111
return file.externalModuleIndicator !== undefined;
112112
}
113113

114+
export function isDeclarationFile(file: SourceFile): boolean {
115+
return (file.flags & NodeFlags.DeclarationFile) !== 0;
116+
}
117+
114118
export function isPrologueDirective(node: Node): boolean {
115119
return node.kind === SyntaxKind.ExpressionStatement && (<ExpressionStatement>node).expression.kind === SyntaxKind.StringLiteral;
116120
}
@@ -221,6 +225,8 @@ module ts {
221225
return child((<ArrayTypeNode>node).elementType);
222226
case SyntaxKind.TupleType:
223227
return children((<TupleTypeNode>node).elementTypes);
228+
case SyntaxKind.UnionType:
229+
return children((<UnionTypeNode>node).types);
224230
case SyntaxKind.ArrayLiteral:
225231
return children((<ArrayLiteral>node).elements);
226232
case SyntaxKind.ObjectLiteral:
@@ -1725,9 +1731,9 @@ module ts {
17251731
}
17261732
}
17271733

1728-
function parseType(): TypeNode {
1734+
function parseNonUnionType(): TypeNode {
17291735
var type = parseNonArrayType();
1730-
while (type && !scanner.hasPrecedingLineBreak() && parseOptional(SyntaxKind.OpenBracketToken)) {
1736+
while (!scanner.hasPrecedingLineBreak() && parseOptional(SyntaxKind.OpenBracketToken)) {
17311737
parseExpected(SyntaxKind.CloseBracketToken);
17321738
var node = <ArrayTypeNode>createNode(SyntaxKind.ArrayType, type.pos);
17331739
node.elementType = type;
@@ -1736,6 +1742,22 @@ module ts {
17361742
return type;
17371743
}
17381744

1745+
function parseType(): TypeNode {
1746+
var type = parseNonUnionType();
1747+
if (token === SyntaxKind.BarToken) {
1748+
var types = <NodeArray<TypeNode>>[type];
1749+
types.pos = type.pos;
1750+
while (parseOptional(SyntaxKind.BarToken)) {
1751+
types.push(parseNonUnionType());
1752+
}
1753+
types.end = getNodeEnd();
1754+
var node = <UnionTypeNode>createNode(SyntaxKind.UnionType, type.pos);
1755+
node.types = types;
1756+
type = finishNode(node);
1757+
}
1758+
return type;
1759+
}
1760+
17391761
function parseTypeAnnotation(): TypeNode {
17401762
return parseOptional(SyntaxKind.ColonToken) ? parseType() : undefined;
17411763
}
@@ -4031,7 +4053,7 @@ module ts {
40314053
}
40324054
}
40334055
}
4034-
else if (node.kind === SyntaxKind.ModuleDeclaration && (<ModuleDeclaration>node).name.kind === SyntaxKind.StringLiteral && (node.flags & NodeFlags.Ambient || file.flags & NodeFlags.DeclarationFile)) {
4056+
else if (node.kind === SyntaxKind.ModuleDeclaration && (<ModuleDeclaration>node).name.kind === SyntaxKind.StringLiteral && (node.flags & NodeFlags.Ambient || isDeclarationFile(file))) {
40354057
// TypeScript 1.0 spec (April 2014): 12.1.6
40364058
// An AmbientExternalModuleDeclaration declares an external module.
40374059
// This type of declaration is permitted only in the global module.

0 commit comments

Comments
 (0)