@@ -5,6 +5,8 @@ module ts {
5
5
var nextNodeId = 1;
6
6
var nextMergeId = 1;
7
7
8
+ /* @internal */ export var checkTime = 0;
9
+
8
10
export function createTypeChecker(host: TypeCheckerHost, produceDiagnostics: boolean): TypeChecker {
9
11
var Symbol = objectAllocator.getSymbolConstructor();
10
12
var Type = objectAllocator.getTypeConstructor();
@@ -48,12 +50,12 @@ module ts {
48
50
getContextualType,
49
51
getFullyQualifiedName,
50
52
getResolvedSignature,
51
- getEnumMemberValue ,
53
+ getConstantValue ,
52
54
isValidPropertyAccess,
53
55
getSignatureFromDeclaration,
54
56
isImplementationOfOverload,
55
57
getAliasedSymbol: resolveImport,
56
- getEmitResolver: () => emitResolver ,
58
+ getEmitResolver,
57
59
};
58
60
59
61
var undefinedSymbol = createSymbol(SymbolFlags.Property | SymbolFlags.Transient, "undefined");
@@ -104,8 +106,7 @@ module ts {
104
106
var nodeLinks: NodeLinks[] = [];
105
107
var potentialThisCollisions: Node[] = [];
106
108
107
- var diagnostics: Diagnostic[] = [];
108
- var diagnosticsModified: boolean = false;
109
+ var diagnostics = createDiagnosticCollection();
109
110
110
111
var primitiveTypeInfo: Map<{ type: Type; flags: TypeFlags }> = {
111
112
"string": {
@@ -122,16 +123,18 @@ module ts {
122
123
}
123
124
};
124
125
125
- function addDiagnostic(diagnostic: Diagnostic) {
126
- diagnostics.push(diagnostic);
127
- diagnosticsModified = true;
126
+ function getEmitResolver(sourceFile?: SourceFile) {
127
+ // Ensure we have all the type information in place for this file so that all the
128
+ // emitter questions of this resolver will return the right information.
129
+ getDiagnostics(sourceFile);
130
+ return emitResolver;
128
131
}
129
132
130
133
function error(location: Node, message: DiagnosticMessage, arg0?: any, arg1?: any, arg2?: any): void {
131
134
var diagnostic = location
132
135
? createDiagnosticForNode(location, message, arg0, arg1, arg2)
133
136
: createCompilerDiagnostic(message, arg0, arg1, arg2);
134
- addDiagnostic (diagnostic);
137
+ diagnostics.add (diagnostic);
135
138
}
136
139
137
140
function createSymbol(flags: SymbolFlags, name: string): Symbol {
@@ -3479,7 +3482,8 @@ module ts {
3479
3482
if (containingMessageChain) {
3480
3483
errorInfo = concatenateDiagnosticMessageChains(containingMessageChain, errorInfo);
3481
3484
}
3482
- addDiagnostic(createDiagnosticForNodeFromMessageChain(errorNode, errorInfo, host.getCompilerHost().getNewLine()));
3485
+
3486
+ diagnostics.add(createDiagnosticForNodeFromMessageChain(errorNode, errorInfo));
3483
3487
}
3484
3488
return result !== Ternary.False;
3485
3489
@@ -5705,9 +5709,9 @@ module ts {
5705
5709
return false;
5706
5710
}
5707
5711
else {
5708
- var diagnosticsCount = diagnostics.length ;
5712
+ var modificationCount = diagnostics.getModificationCount() ;
5709
5713
checkClassPropertyAccess(node, left, type, prop);
5710
- return diagnostics.length === diagnosticsCount
5714
+ return diagnostics.getModificationCount() === modificationCount;
5711
5715
}
5712
5716
}
5713
5717
}
@@ -8927,7 +8931,7 @@ module ts {
8927
8931
8928
8932
var errorInfo = chainDiagnosticMessages(undefined, Diagnostics.Named_properties_0_of_types_1_and_2_are_not_identical, prop.name, typeName1, typeName2);
8929
8933
errorInfo = chainDiagnosticMessages(errorInfo, Diagnostics.Interface_0_cannot_simultaneously_extend_types_1_and_2, typeToString(type), typeName1, typeName2);
8930
- addDiagnostic (createDiagnosticForNodeFromMessageChain(typeNode, errorInfo, host.getCompilerHost().getNewLine() ));
8934
+ diagnostics.add (createDiagnosticForNodeFromMessageChain(typeNode, errorInfo));
8931
8935
}
8932
8936
}
8933
8937
}
@@ -9542,8 +9546,14 @@ module ts {
9542
9546
}
9543
9547
}
9544
9548
9545
- // Fully type check a source file and collect the relevant diagnostics.
9546
9549
function checkSourceFile(node: SourceFile) {
9550
+ var start = new Date().getTime();
9551
+ checkSourceFileWorker(node);
9552
+ checkTime += new Date().getTime() - start;
9553
+ }
9554
+
9555
+ // Fully type check a source file and collect the relevant diagnostics.
9556
+ function checkSourceFileWorker(node: SourceFile) {
9547
9557
var links = getNodeLinks(node);
9548
9558
if (!(links.flags & NodeCheckFlags.TypeChecked)) {
9549
9559
// Grammar checking
@@ -9578,30 +9588,19 @@ module ts {
9578
9588
}
9579
9589
}
9580
9590
9581
- function getSortedDiagnostics(): Diagnostic[]{
9582
- Debug.assert(produceDiagnostics, "diagnostics are available only in the full typecheck mode");
9583
-
9584
- if (diagnosticsModified) {
9585
- diagnostics.sort(compareDiagnostics);
9586
- diagnostics = deduplicateSortedDiagnostics(diagnostics);
9587
- diagnosticsModified = false;
9588
- }
9589
- return diagnostics;
9590
- }
9591
-
9592
9591
function getDiagnostics(sourceFile?: SourceFile): Diagnostic[] {
9593
9592
throwIfNonDiagnosticsProducing();
9594
9593
if (sourceFile) {
9595
9594
checkSourceFile(sourceFile);
9596
- return filter(getSortedDiagnostics(), d => d.file === sourceFile);
9595
+ return diagnostics.getDiagnostics( sourceFile.fileName );
9597
9596
}
9598
9597
forEach(host.getSourceFiles(), checkSourceFile);
9599
- return getSortedDiagnostics ();
9598
+ return diagnostics.getDiagnostics ();
9600
9599
}
9601
9600
9602
- function getGlobalDiagnostics(): Diagnostic[]{
9601
+ function getGlobalDiagnostics(): Diagnostic[] {
9603
9602
throwIfNonDiagnosticsProducing();
9604
- return filter(getSortedDiagnostics(), d => !d.file );
9603
+ return diagnostics.getGlobalDiagnostics( );
9605
9604
}
9606
9605
9607
9606
function throwIfNonDiagnosticsProducing() {
@@ -9625,7 +9624,7 @@ module ts {
9625
9624
return false;
9626
9625
}
9627
9626
9628
- function getSymbolsInScope(location: Node, meaning: SymbolFlags): Symbol[]{
9627
+ function getSymbolsInScope(location: Node, meaning: SymbolFlags): Symbol[] {
9629
9628
var symbols: SymbolTable = {};
9630
9629
var memberFlags: NodeFlags = 0;
9631
9630
function copySymbol(symbol: Symbol, meaning: SymbolFlags) {
@@ -10011,7 +10010,7 @@ module ts {
10011
10010
return getNamedMembers(propsByName);
10012
10011
}
10013
10012
10014
- function getRootSymbols(symbol: Symbol): Symbol[]{
10013
+ function getRootSymbols(symbol: Symbol): Symbol[] {
10015
10014
if (symbol.flags & SymbolFlags.UnionProperty) {
10016
10015
var symbols: Symbol[] = [];
10017
10016
var name = symbol.name;
@@ -10119,11 +10118,6 @@ module ts {
10119
10118
return isImportResolvedToValue(getSymbolOfNode(node));
10120
10119
}
10121
10120
10122
- function hasSemanticDiagnostics(sourceFile?: SourceFile) {
10123
- // Return true if there is any semantic error in a file or globally
10124
- return getDiagnostics(sourceFile).length > 0 || getGlobalDiagnostics().length > 0;
10125
- }
10126
-
10127
10121
function isImportResolvedToValue(symbol: Symbol): boolean {
10128
10122
var target = resolveImport(symbol);
10129
10123
// const enums and modules that contain only const enums are not considered values from the emit perespective
@@ -10177,7 +10171,11 @@ module ts {
10177
10171
return getNodeLinks(node).enumMemberValue;
10178
10172
}
10179
10173
10180
- function getConstantValue(node: PropertyAccessExpression | ElementAccessExpression): number {
10174
+ function getConstantValue(node: EnumMember | PropertyAccessExpression | ElementAccessExpression): number {
10175
+ if (node.kind === SyntaxKind.EnumMember) {
10176
+ return getEnumMemberValue(<EnumMember>node);
10177
+ }
10178
+
10181
10179
var symbol = getNodeLinks(node).resolvedSymbol;
10182
10180
if (symbol && (symbol.flags & SymbolFlags.EnumMember)) {
10183
10181
var declaration = symbol.valueDeclaration;
@@ -10216,9 +10214,7 @@ module ts {
10216
10214
getExportAssignmentName,
10217
10215
isReferencedImportDeclaration,
10218
10216
getNodeCheckFlags,
10219
- getEnumMemberValue,
10220
10217
isTopLevelValueImportWithEntityName,
10221
- hasSemanticDiagnostics,
10222
10218
isDeclarationVisible,
10223
10219
isImplementationOfOverload,
10224
10220
writeTypeOfDeclaration,
@@ -10234,14 +10230,15 @@ module ts {
10234
10230
// Bind all source files and propagate errors
10235
10231
forEach(host.getSourceFiles(), file => {
10236
10232
bindSourceFile(file);
10237
- forEach(file.semanticDiagnostics, addDiagnostic);
10238
10233
});
10234
+
10239
10235
// Initialize global symbol table
10240
10236
forEach(host.getSourceFiles(), file => {
10241
10237
if (!isExternalModule(file)) {
10242
10238
extendSymbolTable(globals, file.locals);
10243
10239
}
10244
10240
});
10241
+
10245
10242
// Initialize special symbols
10246
10243
getSymbolLinks(undefinedSymbol).type = undefinedType;
10247
10244
getSymbolLinks(argumentsSymbol).type = getGlobalType("IArguments");
@@ -11035,14 +11032,14 @@ module ts {
11035
11032
if (!hasParseDiagnostics(sourceFile)) {
11036
11033
var scanner = createScanner(languageVersion, /*skipTrivia*/ true, sourceFile.text);
11037
11034
var start = scanToken(scanner, node.pos);
11038
- diagnostics.push (createFileDiagnostic(sourceFile, start, scanner.getTextPos() - start, message, arg0, arg1, arg2));
11035
+ diagnostics.add (createFileDiagnostic(sourceFile, start, scanner.getTextPos() - start, message, arg0, arg1, arg2));
11039
11036
return true;
11040
11037
}
11041
11038
}
11042
11039
11043
11040
function grammarErrorAtPos(sourceFile: SourceFile, start: number, length: number, message: DiagnosticMessage, arg0?: any, arg1?: any, arg2?: any): boolean {
11044
11041
if (!hasParseDiagnostics(sourceFile)) {
11045
- diagnostics.push (createFileDiagnostic(sourceFile, start, length, message, arg0, arg1, arg2));
11042
+ diagnostics.add (createFileDiagnostic(sourceFile, start, length, message, arg0, arg1, arg2));
11046
11043
return true;
11047
11044
}
11048
11045
}
@@ -11052,7 +11049,7 @@ module ts {
11052
11049
if (!hasParseDiagnostics(sourceFile)) {
11053
11050
var span = getErrorSpanForNode(node);
11054
11051
var start = span.end > span.pos ? skipTrivia(sourceFile.text, span.pos) : span.pos;
11055
- diagnostics.push (createFileDiagnostic(sourceFile, start, span.end - start, message, arg0, arg1, arg2));
11052
+ diagnostics.add (createFileDiagnostic(sourceFile, start, span.end - start, message, arg0, arg1, arg2));
11056
11053
return true;
11057
11054
}
11058
11055
}
@@ -11186,7 +11183,7 @@ module ts {
11186
11183
if (!hasParseDiagnostics(sourceFile)) {
11187
11184
var scanner = createScanner(languageVersion, /*skipTrivia*/ true, sourceFile.text);
11188
11185
scanToken(scanner, node.pos);
11189
- diagnostics.push (createFileDiagnostic(sourceFile, scanner.getTextPos(), 0, message, arg0, arg1, arg2));
11186
+ diagnostics.add (createFileDiagnostic(sourceFile, scanner.getTextPos(), 0, message, arg0, arg1, arg2));
11190
11187
return true;
11191
11188
}
11192
11189
}
0 commit comments