Skip to content

Commit cca29a5

Browse files
author
steveluc
committed
Merge branch 'master' of https://github.com/Microsoft/TypeScript
2 parents b35fea8 + 6637f49 commit cca29a5

File tree

2,501 files changed

+95016
-86185
lines changed

Some content is hidden

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

2,501 files changed

+95016
-86185
lines changed

scripts/processDiagnosticMessages.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ function buildInfoFileOutput(messageTable: InputDiagnosticMessageTable, nameMap:
5454
var result =
5555
'// <auto-generated />\r\n' +
5656
'/// <reference path="types.ts" />\r\n' +
57+
'/* @internal */\r\n' +
5758
'module ts {\r\n' +
5859
' export var Diagnostics = {\r\n';
5960
var names = Utilities.getObjectKeys(messageTable);

src/compiler/diagnosticMessages.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2043,19 +2043,19 @@
20432043
},
20442044
"'import ... =' can only be used in a .ts file.": {
20452045
"category": "Error",
2046-
"code": 8002
2046+
"code": 8002
20472047
},
20482048
"'export=' can only be used in a .ts file.": {
20492049
"category": "Error",
2050-
"code": 8003
2050+
"code": 8003
20512051
},
20522052
"'type parameter declarations' can only be used in a .ts file.": {
20532053
"category": "Error",
2054-
"code": 8004
2054+
"code": 8004
20552055
},
20562056
"'implements clauses' can only be used in a .ts file.": {
20572057
"category": "Error",
2058-
"code": 8005
2058+
"code": 8005
20592059
},
20602060
"'interface declarations' can only be used in a .ts file.": {
20612061
"category": "Error",

src/harness/typeWriter.ts

Lines changed: 25 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
interface TypeWriterResult {
22
line: number;
3-
column: number;
43
syntaxKind: number;
54
sourceText: string;
65
type: string;
@@ -29,90 +28,43 @@ class TypeWriterWalker {
2928
}
3029

3130
private visitNode(node: ts.Node): void {
32-
switch (node.kind) {
33-
// Should always log expressions that are not tokens
34-
// Also, always log the "this" keyword
35-
// TODO: Ideally we should log all expressions, but to compare to the
36-
// old typeWriter baselines, suppress tokens
37-
case ts.SyntaxKind.ThisKeyword:
38-
case ts.SyntaxKind.SuperKeyword:
39-
case ts.SyntaxKind.ArrayLiteralExpression:
40-
case ts.SyntaxKind.ObjectLiteralExpression:
41-
case ts.SyntaxKind.ElementAccessExpression:
42-
case ts.SyntaxKind.CallExpression:
43-
case ts.SyntaxKind.NewExpression:
44-
case ts.SyntaxKind.TypeAssertionExpression:
45-
case ts.SyntaxKind.ParenthesizedExpression:
46-
case ts.SyntaxKind.FunctionExpression:
47-
case ts.SyntaxKind.ArrowFunction:
48-
case ts.SyntaxKind.TypeOfExpression:
49-
case ts.SyntaxKind.VoidExpression:
50-
case ts.SyntaxKind.DeleteExpression:
51-
case ts.SyntaxKind.PrefixUnaryExpression:
52-
case ts.SyntaxKind.PostfixUnaryExpression:
53-
case ts.SyntaxKind.BinaryExpression:
54-
case ts.SyntaxKind.ConditionalExpression:
55-
case ts.SyntaxKind.SpreadElementExpression:
56-
this.log(node, this.getTypeOfNode(node));
57-
break;
58-
59-
case ts.SyntaxKind.PropertyAccessExpression:
60-
for (var current = node; current.kind === ts.SyntaxKind.PropertyAccessExpression; current = current.parent) {
61-
}
62-
if (current.kind !== ts.SyntaxKind.HeritageClauseElement) {
63-
this.log(node, this.getTypeOfNode(node));
64-
}
65-
break;
66-
67-
// Should not change expression status (maybe expressions)
68-
// TODO: Again, ideally should log number and string literals too,
69-
// but to be consistent with the old typeWriter, just log identifiers
70-
case ts.SyntaxKind.Identifier:
71-
var identifier = <ts.Identifier>node;
72-
if (!this.isLabel(identifier)) {
73-
var type = this.getTypeOfNode(identifier);
74-
this.log(node, type);
75-
}
76-
break;
31+
if (ts.isExpression(node) || node.kind === ts.SyntaxKind.Identifier) {
32+
this.logTypeAndSymbol(node);
7733
}
7834

7935
ts.forEachChild(node, child => this.visitNode(child));
8036
}
8137

82-
private isLabel(identifier: ts.Identifier): boolean {
83-
var parent = identifier.parent;
84-
switch (parent.kind) {
85-
case ts.SyntaxKind.ContinueStatement:
86-
case ts.SyntaxKind.BreakStatement:
87-
return (<ts.BreakOrContinueStatement>parent).label === identifier;
88-
case ts.SyntaxKind.LabeledStatement:
89-
return (<ts.LabeledStatement>parent).label === identifier;
90-
}
91-
return false;
92-
}
93-
94-
private log(node: ts.Node, type: ts.Type): void {
38+
private logTypeAndSymbol(node: ts.Node): void {
9539
var actualPos = ts.skipTrivia(this.currentSourceFile.text, node.pos);
9640
var lineAndCharacter = this.currentSourceFile.getLineAndCharacterOfPosition(actualPos);
9741
var sourceText = ts.getTextOfNodeFromSourceText(this.currentSourceFile.text, node);
98-
99-
// If we got an unknown type, we temporarily want to fall back to just pretending the name
100-
// (source text) of the node is the type. This is to align with the old typeWriter to make
101-
// baseline comparisons easier. In the long term, we will want to just call typeToString
42+
43+
var type = this.checker.getTypeAtLocation(node);
44+
ts.Debug.assert(type !== undefined, "type doesn't exist");
45+
var symbol = this.checker.getSymbolAtLocation(node);
46+
47+
var typeString = this.checker.typeToString(type, node.parent, ts.TypeFormatFlags.NoTruncation);
48+
if (symbol) {
49+
var symbolString = "Symbol(" + this.checker.symbolToString(symbol, node.parent);
50+
if (symbol.declarations) {
51+
for (let declaration of symbol.declarations) {
52+
symbolString += ", ";
53+
let declSourceFile = declaration.getSourceFile();
54+
let declLineAndCharacter = declSourceFile.getLineAndCharacterOfPosition(declaration.pos);
55+
symbolString += `Decl(${ ts.getBaseFileName(declSourceFile.fileName) }, ${ declLineAndCharacter.line }, ${ declLineAndCharacter.character })`
56+
}
57+
}
58+
symbolString += ")";
59+
60+
typeString += ", " + symbolString;
61+
}
62+
10263
this.results.push({
10364
line: lineAndCharacter.line,
104-
// todo(cyrusn): Not sure why column is one-based for type-writer. But I'm preserving
105-
// that behavior to prevent having a lot of baselines to fix up.
106-
column: lineAndCharacter.character + 1,
10765
syntaxKind: node.kind,
10866
sourceText: sourceText,
109-
type: this.checker.typeToString(type, node.parent, ts.TypeFormatFlags.NoTruncation | ts.TypeFormatFlags.WriteOwnNameForAnyLike)
67+
type: typeString
11068
});
11169
}
112-
113-
private getTypeOfNode(node: ts.Node): ts.Type {
114-
var type = this.checker.getTypeAtLocation(node);
115-
ts.Debug.assert(type !== undefined, "type doesn't exist");
116-
return type;
117-
}
11870
}
Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,40 @@
11
=== tests/cases/compiler/2dArrays.ts ===
22
class Cell {
3-
>Cell : Cell
3+
>Cell : Cell, Symbol(Cell, Decl(2dArrays.ts, 0, 0))
44
}
55

66
class Ship {
7-
>Ship : Ship
7+
>Ship : Ship, Symbol(Ship, Decl(2dArrays.ts, 1, 1))
88

99
isSunk: boolean;
10-
>isSunk : boolean
10+
>isSunk : boolean, Symbol(isSunk, Decl(2dArrays.ts, 3, 12))
1111
}
1212

1313
class Board {
14-
>Board : Board
14+
>Board : Board, Symbol(Board, Decl(2dArrays.ts, 5, 1))
1515

1616
ships: Ship[];
17-
>ships : Ship[]
18-
>Ship : Ship
17+
>ships : Ship[], Symbol(ships, Decl(2dArrays.ts, 7, 13))
18+
>Ship : Ship, Symbol(Ship, Decl(2dArrays.ts, 1, 1))
1919

2020
cells: Cell[];
21-
>cells : Cell[]
22-
>Cell : Cell
21+
>cells : Cell[], Symbol(cells, Decl(2dArrays.ts, 8, 18))
22+
>Cell : Cell, Symbol(Cell, Decl(2dArrays.ts, 0, 0))
2323

2424
private allShipsSunk() {
25-
>allShipsSunk : () => boolean
25+
>allShipsSunk : () => boolean, Symbol(allShipsSunk, Decl(2dArrays.ts, 9, 18))
2626

2727
return this.ships.every(function (val) { return val.isSunk; });
2828
>this.ships.every(function (val) { return val.isSunk; }) : boolean
29-
>this.ships.every : (callbackfn: (value: Ship, index: number, array: Ship[]) => boolean, thisArg?: any) => boolean
30-
>this.ships : Ship[]
31-
>this : Board
32-
>ships : Ship[]
33-
>every : (callbackfn: (value: Ship, index: number, array: Ship[]) => boolean, thisArg?: any) => boolean
29+
>this.ships.every : (callbackfn: (value: Ship, index: number, array: Ship[]) => boolean, thisArg?: any) => boolean, Symbol(Array.every, Decl(lib.d.ts, 1094, 62))
30+
>this.ships : Ship[], Symbol(ships, Decl(2dArrays.ts, 7, 13))
31+
>this : Board, Symbol(Board, Decl(2dArrays.ts, 5, 1))
32+
>ships : Ship[], Symbol(ships, Decl(2dArrays.ts, 7, 13))
33+
>every : (callbackfn: (value: Ship, index: number, array: Ship[]) => boolean, thisArg?: any) => boolean, Symbol(Array.every, Decl(lib.d.ts, 1094, 62))
3434
>function (val) { return val.isSunk; } : (val: Ship) => boolean
35-
>val : Ship
36-
>val.isSunk : boolean
37-
>val : Ship
38-
>isSunk : boolean
35+
>val : Ship, Symbol(val, Decl(2dArrays.ts, 12, 42))
36+
>val.isSunk : boolean, Symbol(Ship.isSunk, Decl(2dArrays.ts, 3, 12))
37+
>val : Ship, Symbol(val, Decl(2dArrays.ts, 12, 42))
38+
>isSunk : boolean, Symbol(Ship.isSunk, Decl(2dArrays.ts, 3, 12))
3939
}
4040
}

0 commit comments

Comments
 (0)