Skip to content

Commit ea4e3de

Browse files
Remove unnecessary diagnostics split on SourceFile.
1 parent f20fbb9 commit ea4e3de

14 files changed

Lines changed: 13 additions & 78 deletions

src/compiler/parser.ts

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -357,14 +357,6 @@ module ts {
357357
forEachChild(sourceFile, walk);
358358
}
359359

360-
export function getSyntacticDiagnostics(sourceFile: SourceFile): Diagnostic[] {
361-
if (!sourceFile.syntacticDiagnostics) {
362-
sourceFile.syntacticDiagnostics = sourceFile.referenceDiagnostics.concat(sourceFile.parseDiagnostics);
363-
}
364-
365-
return sourceFile.syntacticDiagnostics;
366-
}
367-
368360
function moveElementEntirelyPastChangeRange(element: IncrementalElement, delta: number) {
369361
if (element.length) {
370362
visitArray(<IncrementalNodeArray>element);
@@ -880,7 +872,6 @@ module ts {
880872
sourceFile.end = sourceText.length;
881873
sourceFile.text = sourceText;
882874

883-
sourceFile.referenceDiagnostics = [];
884875
sourceFile.parseDiagnostics = [];
885876
sourceFile.bindDiagnostics = [];
886877
sourceFile.languageVersion = languageVersion;
@@ -4698,15 +4689,15 @@ module ts {
46984689
referencedFiles.push(fileReference);
46994690
}
47004691
if (diagnosticMessage) {
4701-
sourceFile.referenceDiagnostics.push(createFileDiagnostic(sourceFile, range.pos, range.end - range.pos, diagnosticMessage));
4692+
sourceFile.parseDiagnostics.push(createFileDiagnostic(sourceFile, range.pos, range.end - range.pos, diagnosticMessage));
47024693
}
47034694
}
47044695
else {
47054696
var amdModuleNameRegEx = /^\/\/\/\s*<amd-module\s+name\s*=\s*('|")(.+?)\1/gim;
47064697
var amdModuleNameMatchResult = amdModuleNameRegEx.exec(comment);
47074698
if (amdModuleNameMatchResult) {
47084699
if (amdModuleName) {
4709-
sourceFile.referenceDiagnostics.push(createFileDiagnostic(sourceFile, range.pos, range.end - range.pos, Diagnostics.An_AMD_module_cannot_have_multiple_name_assignments));
4700+
sourceFile.parseDiagnostics.push(createFileDiagnostic(sourceFile, range.pos, range.end - range.pos, Diagnostics.An_AMD_module_cannot_have_multiple_name_assignments));
47104701
}
47114702
amdModuleName = amdModuleNameMatchResult[2];
47124703
}

src/compiler/program.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,13 +225,17 @@ module ts {
225225
}
226226

227227
function getSyntacticDiagnostics(sourceFile?: SourceFile): Diagnostic[]{
228-
return getDiagnosticsHelper(sourceFile, ts.getSyntacticDiagnostics);
228+
return getDiagnosticsHelper(sourceFile, getSyntacticDiagnosticsForFile);
229229
}
230230

231231
function getSemanticDiagnostics(sourceFile?: SourceFile): Diagnostic[]{
232232
return getDiagnosticsHelper(sourceFile, getSemanticDiagnosticsForFile);
233233
}
234234

235+
function getSyntacticDiagnosticsForFile(sourceFile: SourceFile): Diagnostic[] {
236+
return sourceFile.parseDiagnostics;
237+
}
238+
235239
function getSemanticDiagnosticsForFile(sourceFile: SourceFile): Diagnostic[] {
236240
var typeChecker = getDiagnosticsProducingTypeChecker();
237241

src/compiler/types.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -902,20 +902,13 @@ module ts {
902902
/* @internal */ identifierCount: number;
903903
/* @internal */ symbolCount: number;
904904

905-
// Diagnostics reported about the "///<reference" comments in the file.
906-
/* @internal */ referenceDiagnostics: Diagnostic[];
907-
908-
// Parse errors refer specifically to things the parser could not understand at all (like
909-
// missing tokens, or tokens it didn't know how to deal with).
905+
// File level diagnostics reported by the parser (includes diagnostics about /// references
906+
// as well as code diagnostics).
910907
/* @internal */ parseDiagnostics: Diagnostic[];
911908

912909
// File level diagnostics reported by the binder.
913910
/* @internal */ bindDiagnostics: Diagnostic[];
914911

915-
// Returns all syntactic diagnostics (i.e. the reference, parser and grammar diagnostics).
916-
// This field should never be used directly, use getSyntacticDiagnostics function instead.
917-
/* @internal */ syntacticDiagnostics: Diagnostic[];
918-
919912
// Stores a line map for the file.
920913
// This field should never be used directly to obtain line map, use getLineMap function instead.
921914
/* @internal */ lineMap: number[];

src/harness/fourslash.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1407,15 +1407,15 @@ module FourSlash {
14071407
var incrementalSourceFile = this.languageService.getSourceFile(this.activeFile.fileName);
14081408
Utils.assertInvariants(incrementalSourceFile, /*parent:*/ undefined);
14091409

1410-
var incrementalSyntaxDiagnostics = ts.getSyntacticDiagnostics(incrementalSourceFile);
1410+
var incrementalSyntaxDiagnostics = incrementalSourceFile.parseDiagnostics;
14111411

14121412
// Check syntactic structure
14131413
var snapshot = this.languageServiceShimHost.getScriptSnapshot(this.activeFile.fileName);
14141414
var content = snapshot.getText(0, snapshot.getLength());
14151415

14161416
var referenceSourceFile = ts.createLanguageServiceSourceFile(
14171417
this.activeFile.fileName, createScriptSnapShot(content), ts.ScriptTarget.Latest, /*version:*/ "0", /*setNodeParents:*/ false);
1418-
var referenceSyntaxDiagnostics = ts.getSyntacticDiagnostics(referenceSourceFile);
1418+
var referenceSyntaxDiagnostics = referenceSourceFile.parseDiagnostics;
14191419

14201420
Utils.assertDiagnosticsEquals(incrementalSyntaxDiagnostics, referenceSyntaxDiagnostics);
14211421
Utils.assertStructuralEquals(incrementalSourceFile, referenceSourceFile);

src/services/services.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ module ts {
6464
getLineAndCharacterFromPosition(pos: number): LineAndCharacter;
6565
getLineStarts(): number[];
6666
getPositionFromLineAndCharacter(line: number, character: number): number;
67-
getSyntacticDiagnostics(): Diagnostic[];
6867
update(newText: string, textChangeRange: TextChangeRange): SourceFile;
6968
}
7069

@@ -747,10 +746,6 @@ module ts {
747746

748747
private namedDeclarations: Declaration[];
749748

750-
public getSyntacticDiagnostics(): Diagnostic[]{
751-
return getSyntacticDiagnostics(this);
752-
}
753-
754749
public update(newText: string, textChangeRange: TextChangeRange): SourceFile {
755750
return updateSourceFile(this, newText, textChangeRange);
756751
}

tests/baselines/reference/APISample_compile.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1407,7 +1407,6 @@ declare module "typescript" {
14071407
function createNode(kind: SyntaxKind): Node;
14081408
function forEachChild<T>(node: Node, cbNode: (node: Node) => T, cbNodeArray?: (nodes: Node[]) => T): T;
14091409
function modifierToFlag(token: SyntaxKind): NodeFlags;
1410-
function getSyntacticDiagnostics(sourceFile: SourceFile): Diagnostic[];
14111410
function updateSourceFile(sourceFile: SourceFile, newText: string, textChangeRange: TextChangeRange): SourceFile;
14121411
function isEvalOrArgumentsIdentifier(node: Node): boolean;
14131412
function createSourceFile(fileName: string, sourceText: string, languageVersion: ScriptTarget, setParentNodes?: boolean): SourceFile;
@@ -1473,7 +1472,6 @@ declare module "typescript" {
14731472
getLineAndCharacterFromPosition(pos: number): LineAndCharacter;
14741473
getLineStarts(): number[];
14751474
getPositionFromLineAndCharacter(line: number, character: number): number;
1476-
getSyntacticDiagnostics(): Diagnostic[];
14771475
update(newText: string, textChangeRange: TextChangeRange): SourceFile;
14781476
}
14791477
/**

tests/baselines/reference/APISample_compile.types

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4493,12 +4493,6 @@ declare module "typescript" {
44934493
>SyntaxKind : SyntaxKind
44944494
>NodeFlags : NodeFlags
44954495

4496-
function getSyntacticDiagnostics(sourceFile: SourceFile): Diagnostic[];
4497-
>getSyntacticDiagnostics : (sourceFile: SourceFile) => Diagnostic[]
4498-
>sourceFile : SourceFile
4499-
>SourceFile : SourceFile
4500-
>Diagnostic : Diagnostic
4501-
45024496
function updateSourceFile(sourceFile: SourceFile, newText: string, textChangeRange: TextChangeRange): SourceFile;
45034497
>updateSourceFile : (sourceFile: SourceFile, newText: string, textChangeRange: TextChangeRange) => SourceFile
45044498
>sourceFile : SourceFile
@@ -4755,10 +4749,6 @@ declare module "typescript" {
47554749
>line : number
47564750
>character : number
47574751

4758-
getSyntacticDiagnostics(): Diagnostic[];
4759-
>getSyntacticDiagnostics : () => Diagnostic[]
4760-
>Diagnostic : Diagnostic
4761-
47624752
update(newText: string, textChangeRange: TextChangeRange): SourceFile;
47634753
>update : (newText: string, textChangeRange: TextChangeRange) => SourceFile
47644754
>newText : string

tests/baselines/reference/APISample_linter.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1439,7 +1439,6 @@ declare module "typescript" {
14391439
function createNode(kind: SyntaxKind): Node;
14401440
function forEachChild<T>(node: Node, cbNode: (node: Node) => T, cbNodeArray?: (nodes: Node[]) => T): T;
14411441
function modifierToFlag(token: SyntaxKind): NodeFlags;
1442-
function getSyntacticDiagnostics(sourceFile: SourceFile): Diagnostic[];
14431442
function updateSourceFile(sourceFile: SourceFile, newText: string, textChangeRange: TextChangeRange): SourceFile;
14441443
function isEvalOrArgumentsIdentifier(node: Node): boolean;
14451444
function createSourceFile(fileName: string, sourceText: string, languageVersion: ScriptTarget, setParentNodes?: boolean): SourceFile;
@@ -1505,7 +1504,6 @@ declare module "typescript" {
15051504
getLineAndCharacterFromPosition(pos: number): LineAndCharacter;
15061505
getLineStarts(): number[];
15071506
getPositionFromLineAndCharacter(line: number, character: number): number;
1508-
getSyntacticDiagnostics(): Diagnostic[];
15091507
update(newText: string, textChangeRange: TextChangeRange): SourceFile;
15101508
}
15111509
/**

tests/baselines/reference/APISample_linter.types

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4640,12 +4640,6 @@ declare module "typescript" {
46404640
>SyntaxKind : SyntaxKind
46414641
>NodeFlags : NodeFlags
46424642

4643-
function getSyntacticDiagnostics(sourceFile: SourceFile): Diagnostic[];
4644-
>getSyntacticDiagnostics : (sourceFile: SourceFile) => Diagnostic[]
4645-
>sourceFile : SourceFile
4646-
>SourceFile : SourceFile
4647-
>Diagnostic : Diagnostic
4648-
46494643
function updateSourceFile(sourceFile: SourceFile, newText: string, textChangeRange: TextChangeRange): SourceFile;
46504644
>updateSourceFile : (sourceFile: SourceFile, newText: string, textChangeRange: TextChangeRange) => SourceFile
46514645
>sourceFile : SourceFile
@@ -4902,10 +4896,6 @@ declare module "typescript" {
49024896
>line : number
49034897
>character : number
49044898

4905-
getSyntacticDiagnostics(): Diagnostic[];
4906-
>getSyntacticDiagnostics : () => Diagnostic[]
4907-
>Diagnostic : Diagnostic
4908-
49094899
update(newText: string, textChangeRange: TextChangeRange): SourceFile;
49104900
>update : (newText: string, textChangeRange: TextChangeRange) => SourceFile
49114901
>newText : string

tests/baselines/reference/APISample_transform.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1440,7 +1440,6 @@ declare module "typescript" {
14401440
function createNode(kind: SyntaxKind): Node;
14411441
function forEachChild<T>(node: Node, cbNode: (node: Node) => T, cbNodeArray?: (nodes: Node[]) => T): T;
14421442
function modifierToFlag(token: SyntaxKind): NodeFlags;
1443-
function getSyntacticDiagnostics(sourceFile: SourceFile): Diagnostic[];
14441443
function updateSourceFile(sourceFile: SourceFile, newText: string, textChangeRange: TextChangeRange): SourceFile;
14451444
function isEvalOrArgumentsIdentifier(node: Node): boolean;
14461445
function createSourceFile(fileName: string, sourceText: string, languageVersion: ScriptTarget, setParentNodes?: boolean): SourceFile;
@@ -1506,7 +1505,6 @@ declare module "typescript" {
15061505
getLineAndCharacterFromPosition(pos: number): LineAndCharacter;
15071506
getLineStarts(): number[];
15081507
getPositionFromLineAndCharacter(line: number, character: number): number;
1509-
getSyntacticDiagnostics(): Diagnostic[];
15101508
update(newText: string, textChangeRange: TextChangeRange): SourceFile;
15111509
}
15121510
/**

0 commit comments

Comments
 (0)