Skip to content

Commit 0a6f027

Browse files
committed
Merge pull request #554 from Microsoft/typeBaselines
Changes to typeWriter and type baselines
2 parents f55b5ef + ae59368 commit 0a6f027

File tree

526 files changed

+13704
-13580
lines changed

Some content is hidden

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

526 files changed

+13704
-13580
lines changed

src/compiler/checker.ts

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -906,7 +906,7 @@ module ts {
906906
// Get qualified name
907907
if (enclosingDeclaration &&
908908
// Properties/methods/Signatures/Constructors/TypeParameters do not need qualification
909-
!(symbol.flags & SymbolFlags.PropertyOrAccessor & SymbolFlags.Signature & SymbolFlags.Constructor & SymbolFlags.Method & SymbolFlags.TypeParameter)) {
909+
!(symbol.flags & (SymbolFlags.PropertyOrAccessor | SymbolFlags.Signature | SymbolFlags.Constructor | SymbolFlags.Method | SymbolFlags.TypeParameter))) {
910910
var symbolName: string;
911911
while (symbol) {
912912
var isFirstName = !symbolName;
@@ -2236,13 +2236,12 @@ module ts {
22362236
return emptyObjectType;
22372237
}
22382238
var type = getDeclaredTypeOfSymbol(symbol);
2239-
var name = symbol.name;
22402239
if (!(type.flags & TypeFlags.ObjectType)) {
2241-
error(getTypeDeclaration(symbol), Diagnostics.Global_type_0_must_be_a_class_or_interface_type, name);
2240+
error(getTypeDeclaration(symbol), Diagnostics.Global_type_0_must_be_a_class_or_interface_type, symbol.name);
22422241
return emptyObjectType;
22432242
}
22442243
if (((<InterfaceType>type).typeParameters ? (<InterfaceType>type).typeParameters.length : 0) !== arity) {
2245-
error(getTypeDeclaration(symbol), Diagnostics.Global_type_0_must_have_1_type_parameter_s, name, arity);
2244+
error(getTypeDeclaration(symbol), Diagnostics.Global_type_0_must_have_1_type_parameter_s, symbol.name, arity);
22462245
return emptyObjectType;
22472246
}
22482247
return <ObjectType>type;
@@ -3545,7 +3544,8 @@ module ts {
35453544
return false;
35463545
}
35473546

3548-
function checkSuperExpression(node: Node, isCallExpression: boolean): Type {
3547+
function checkSuperExpression(node: Node): Type {
3548+
var isCallExpression = node.parent.kind === SyntaxKind.CallExpression && (<CallExpression>node.parent).func === node;
35493549
var enclosingClass = <ClassDeclaration>getAncestor(node, SyntaxKind.ClassDeclaration);
35503550
var baseClass: Type;
35513551
if (enclosingClass && enclosingClass.baseType) {
@@ -4179,7 +4179,7 @@ module ts {
41794179

41804180
function resolveCallExpression(node: CallExpression): Signature {
41814181
if (node.func.kind === SyntaxKind.SuperKeyword) {
4182-
var superType = checkSuperExpression(node.func, true);
4182+
var superType = checkSuperExpression(node.func);
41834183
if (superType !== unknownType) {
41844184
return resolveCall(node, getSignaturesOfType(superType, SignatureKind.Construct));
41854185
}
@@ -4827,7 +4827,7 @@ module ts {
48274827
case SyntaxKind.ThisKeyword:
48284828
return checkThisExpression(node);
48294829
case SyntaxKind.SuperKeyword:
4830-
return checkSuperExpression(node, false);
4830+
return checkSuperExpression(node);
48314831
case SyntaxKind.NullKeyword:
48324832
return nullType;
48334833
case SyntaxKind.TrueKeyword:
@@ -6681,6 +6681,7 @@ module ts {
66816681
case SyntaxKind.Parameter:
66826682
case SyntaxKind.Property:
66836683
case SyntaxKind.EnumMember:
6684+
case SyntaxKind.PropertyAssignment:
66846685
return (<VariableDeclaration>parent).initializer === node;
66856686
case SyntaxKind.ExpressionStatement:
66866687
case SyntaxKind.IfStatement:
@@ -6810,6 +6811,11 @@ module ts {
68106811
/*all meanings*/ SymbolFlags.Value | SymbolFlags.Type | SymbolFlags.Namespace | SymbolFlags.Import);
68116812
}
68126813

6814+
if (isInRightSideOfImportOrExportAssignment(entityName)) {
6815+
// Since we already checked for ExportAssignment, this really could only be an Import
6816+
return getSymbolOfPartOfRightHandSideOfImport(entityName);
6817+
}
6818+
68136819
if (isRightSideOfQualifiedNameOrPropertyAccess(entityName)) {
68146820
entityName = entityName.parent;
68156821
}
@@ -6920,11 +6926,7 @@ module ts {
69206926
}
69216927

69226928
if (isInRightSideOfImportOrExportAssignment(node)) {
6923-
var symbol: Symbol;
6924-
symbol = node.parent.kind === SyntaxKind.ExportAssignment
6925-
? getSymbolInfo(node)
6926-
: getSymbolOfPartOfRightHandSideOfImport(node);
6927-
6929+
var symbol = getSymbolInfo(node);
69286930
var declaredType = getDeclaredTypeOfSymbol(symbol);
69296931
return declaredType !== unknownType ? declaredType : getTypeOfSymbol(symbol);
69306932
}

src/harness/compilerRunner.ts

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,16 @@ class CompilerBaselineRunner extends RunnerBase {
4141
describe('compiler tests for ' + fileName, () => {
4242
// Mocha holds onto the closure environment of the describe callback even after the test is done.
4343
// Everything declared here should be cleared out in the "after" callback.
44-
var justName = fileName.replace(/^.*[\\\/]/, ''); // strips the fileName from the path.
45-
var content = Harness.IO.readFile(fileName);
46-
var testCaseContent = Harness.TestCaseParser.makeUnitsFromTest(content, fileName);
44+
var justName: string;
45+
var content: string;
46+
var testCaseContent: { settings: Harness.TestCaseParser.CompilerSetting[]; testUnitData: Harness.TestCaseParser.TestUnitData[]; }
4747

48-
var units = testCaseContent.testUnitData;
49-
var tcSettings = testCaseContent.settings;
50-
var createNewInstance = false;
48+
var units: Harness.TestCaseParser.TestUnitData[];
49+
var tcSettings: Harness.TestCaseParser.CompilerSetting[];
50+
var createNewInstance: boolean;
5151

52-
var lastUnit = units[units.length - 1];
53-
var rootDir = lastUnit.originalFilePath.indexOf('conformance') === -1 ? 'tests/cases/compiler/' : lastUnit.originalFilePath.substring(0, lastUnit.originalFilePath.lastIndexOf('/')) + '/';
52+
var lastUnit: Harness.TestCaseParser.TestUnitData;
53+
var rootDir: string;
5454

5555
var result: Harness.Compiler.CompilerResult;
5656
var checker: ts.TypeChecker;
@@ -68,6 +68,14 @@ class CompilerBaselineRunner extends RunnerBase {
6868
var createNewInstance = false;
6969

7070
before(() => {
71+
justName = fileName.replace(/^.*[\\\/]/, ''); // strips the fileName from the path.
72+
content = Harness.IO.readFile(fileName);
73+
testCaseContent = Harness.TestCaseParser.makeUnitsFromTest(content, fileName);
74+
units = testCaseContent.testUnitData;
75+
tcSettings = testCaseContent.settings;
76+
createNewInstance = false;
77+
lastUnit = units[units.length - 1];
78+
rootDir = lastUnit.originalFilePath.indexOf('conformance') === -1 ? 'tests/cases/compiler/' : lastUnit.originalFilePath.substring(0, lastUnit.originalFilePath.lastIndexOf('/')) + '/';
7179
harnessCompiler = Harness.Compiler.getCompiler();
7280
// We need to assemble the list of input files for the compiler and other related files on the 'filesystem' (ie in a multi-file test)
7381
// If the last file in a test uses require or a triple slash reference we'll assume all other files will be brought in via references,
@@ -307,7 +315,7 @@ class CompilerBaselineRunner extends RunnerBase {
307315
allFiles.forEach(file => {
308316
var codeLines = file.content.split('\n');
309317
walker.getTypes(file.unitName).forEach(result => {
310-
var formattedLine = result.identifierName + " : " + result.type;
318+
var formattedLine = result.sourceText.replace(/\r?\n/g, "") + " : " + result.type;
311319
if (!typeMap[file.unitName]) {
312320
typeMap[file.unitName] = {};
313321
}

src/harness/typeWriter.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ interface TypeWriterResult {
22
line: number;
33
column: number;
44
syntaxKind: string;
5-
identifierName: string;
5+
sourceText: string;
66
type: string;
77
}
88

@@ -28,7 +28,7 @@ class TypeWriterWalker {
2828
// TODO: Ideally we should log all expressions, but to compare to the
2929
// old typeWriter baselines, suppress tokens
3030
case ts.SyntaxKind.ThisKeyword:
31-
case ts.SyntaxKind.RegularExpressionLiteral:
31+
case ts.SyntaxKind.SuperKeyword:
3232
case ts.SyntaxKind.ArrayLiteral:
3333
case ts.SyntaxKind.ObjectLiteral:
3434
case ts.SyntaxKind.PropertyAccess:
@@ -77,7 +77,6 @@ class TypeWriterWalker {
7777
var actualPos = ts.skipTrivia(this.currentSourceFile.text, node.pos);
7878
var lineAndCharacter = this.currentSourceFile.getLineAndCharacterFromPosition(actualPos);
7979
var sourceText = ts.getSourceTextOfNodeFromSourceText(this.currentSourceFile.text, node);
80-
var isUnknownType = (<ts.IntrinsicType>type).intrinsicName === "unknown";
8180

8281
// If we got an unknown type, we temporarily want to fall back to just pretending the name
8382
// (source text) of the node is the type. This is to align with the old typeWriter to make
@@ -86,8 +85,8 @@ class TypeWriterWalker {
8685
line: lineAndCharacter.line - 1,
8786
column: lineAndCharacter.character,
8887
syntaxKind: ts.SyntaxKind[node.kind],
89-
identifierName: sourceText,
90-
type: isUnknownType ? sourceText : this.checker.typeToString(type)
88+
sourceText: sourceText,
89+
type: this.checker.typeToString(type, node.parent, ts.TypeFormatFlags.None)
9190
});
9291
}
9392

tests/baselines/reference/AmbientModuleAndAmbientWithSameNameAndCommonRoot.types

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,15 @@ var p: { x: number; y: number; }
4545
var p = A.Point.Origin;
4646
>p : { x: number; y: number; }
4747
>A.Point.Origin : { x: number; y: number; }
48-
>A.Point : typeof Point
48+
>A.Point : typeof A.Point
4949
>A : typeof A
50-
>Point : typeof Point
50+
>Point : typeof A.Point
5151
>Origin : { x: number; y: number; }
5252

5353
var p = new A.Point(0, 0); // unexpected error here, bug 840000
5454
>p : { x: number; y: number; }
55-
>new A.Point(0, 0) : Point
56-
>A.Point : typeof Point
55+
>new A.Point(0, 0) : A.Point
56+
>A.Point : typeof A.Point
5757
>A : typeof A
58-
>Point : typeof Point
58+
>Point : typeof A.Point
5959

tests/baselines/reference/AmbientModuleAndNonAmbientClassWithSameNameAndCommonRoot.types

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,15 @@ var p: { x: number; y: number; }
3939
var p = A.Point.Origin;
4040
>p : { x: number; y: number; }
4141
>A.Point.Origin : { x: number; y: number; }
42-
>A.Point : typeof Point
42+
>A.Point : typeof A.Point
4343
>A : typeof A
44-
>Point : typeof Point
44+
>Point : typeof A.Point
4545
>Origin : { x: number; y: number; }
4646

4747
var p = new A.Point(0, 0); // unexpected error here, bug 840000
4848
>p : { x: number; y: number; }
49-
>new A.Point(0, 0) : Point
50-
>A.Point : typeof Point
49+
>new A.Point(0, 0) : A.Point
50+
>A.Point : typeof A.Point
5151
>A : typeof A
52-
>Point : typeof Point
52+
>Point : typeof A.Point
5353

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
==== tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ArrowFunctions/ArrowFunction1.ts (1 errors) ====
2+
var v = (a: ) => {
3+
~
4+
!!! Type expected.
5+
6+
};
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
==== tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ArrowFunctions/ArrowFunction2.ts (2 errors) ====
2+
var v = (a: b,) => {
3+
~
4+
!!! Trailing comma not allowed.
5+
~
6+
!!! Cannot find name 'b'.
7+
8+
};
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
==== tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ArrowFunctions/ArrowFunction3.ts (3 errors) ====
2+
var v = (a): => {
3+
~
4+
!!! ',' expected.
5+
~~
6+
!!! ';' expected.
7+
~
8+
!!! Cannot find name 'a'.
9+
10+
};
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
//// [ArrowFunction4.ts]
2+
var v = (a, b) => {
3+
4+
};
5+
6+
//// [ArrowFunction4.js]
7+
var v = function (a, b) {
8+
};
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
=== tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ArrowFunctions/ArrowFunction4.ts ===
2+
var v = (a, b) => {
3+
>v : (a: any, b: any) => void
4+
>(a, b) => { } : (a: any, b: any) => void
5+
>a : any
6+
>b : any
7+
8+
};

0 commit comments

Comments
 (0)