Skip to content

Commit 06bb947

Browse files
Merge pull request microsoft#1345 from Microsoft/eofComments
Add a dedicated 'EndOfFile' token to a SourceFile.
2 parents 6e945af + 5a7500c commit 06bb947

46 files changed

Lines changed: 636 additions & 3 deletions

Some content is hidden

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

src/compiler/emitter.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3443,6 +3443,7 @@ module ts {
34433443
// Start new file on new line
34443444
writeLine();
34453445
emitDetachedComments(node);
3446+
34463447
// emit prologue directives prior to __extends
34473448
var startIndex = emitDirectivePrologues(node.statements, /*startWithNewLine*/ false);
34483449
if (!extendsEmitted && resolver.getNodeCheckFlags(node) & NodeCheckFlags.EmitExtends) {
@@ -3474,6 +3475,8 @@ module ts {
34743475
emitCaptureThisForNodeIfNecessary(node);
34753476
emitLinesStartingAt(node.statements, startIndex);
34763477
}
3478+
3479+
emitLeadingComments(node.endOfFileToken);
34773480
}
34783481

34793482
function emitNode(node: Node): void {

src/compiler/parser.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,8 +313,10 @@ module ts {
313313
case SyntaxKind.FinallyBlock:
314314
case SyntaxKind.FunctionBlock:
315315
case SyntaxKind.ModuleBlock:
316-
case SyntaxKind.SourceFile:
317316
return children((<Block>node).statements);
317+
case SyntaxKind.SourceFile:
318+
return children((<SourceFile>node).statements) ||
319+
child((<SourceFile>node).endOfFileToken);
318320
case SyntaxKind.VariableStatement:
319321
return children(node.modifiers) ||
320322
children((<VariableStatement>node).declarations);
@@ -4294,6 +4296,9 @@ module ts {
42944296
sourceFile.amdModuleName = referenceComments.amdModuleName;
42954297

42964298
sourceFile.statements = parseList(ParsingContext.SourceElements, /*checkForStrictMode*/ true, parseSourceElement);
4299+
Debug.assert(token === SyntaxKind.EndOfFileToken);
4300+
sourceFile.endOfFileToken = parseTokenNode();
4301+
42974302
sourceFile.externalModuleIndicator = getExternalModuleIndicator();
42984303

42994304
sourceFile.nodeCount = nodeCount;

src/compiler/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -786,6 +786,7 @@ module ts {
786786
// Source files are declarations when they are external modules.
787787
export interface SourceFile extends Declaration {
788788
statements: NodeArray<ModuleElement>;
789+
endOfFileToken: Node;
789790

790791
filename: string;
791792
text: string;

src/services/services.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -722,6 +722,9 @@ module ts {
722722
public filename: string;
723723
public text: string;
724724

725+
public statements: NodeArray<Statement>;
726+
public endOfFileToken: Node;
727+
725728
// These methods will have their implementation provided by the implementation the
726729
// compiler actually exports off of SourceFile.
727730
public getLineAndCharacterFromPosition: (position: number) => LineAndCharacter;
@@ -743,7 +746,6 @@ module ts {
743746
public nodeCount: number;
744747
public identifierCount: number;
745748
public symbolCount: number;
746-
public statements: NodeArray<Statement>;
747749
public version: string;
748750
public isOpen: boolean;
749751
public languageVersion: ScriptTarget;

tests/baselines/reference/anyAssignableToEveryType.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,3 +83,8 @@ function foo(x, y, z) {
8383
y = a;
8484
z = a;
8585
}
86+
//function foo<T, U extends T, V extends Date>(x: T, y: U, z: V) {
87+
// x = a;
88+
// y = a;
89+
// z = a;
90+
//}

tests/baselines/reference/augmentedTypesClass3.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,4 @@ var c5c = (function () {
5252
};
5353
return c5c;
5454
})();
55+
//import c5c = require('');

tests/baselines/reference/augmentedTypesEnum.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,3 +105,6 @@ var e6b;
105105
(function (e6b) {
106106
e6b.y = 2;
107107
})(e6b || (e6b = {})); // should be error
108+
// enum then import, messes with error reporting
109+
//enum e7 { One }
110+
//import e7 = require(''); // should be error

tests/baselines/reference/augmentedTypesEnum2.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,5 @@ var e2 = (function () {
4040
};
4141
return e2;
4242
})();
43+
//enum then enum - covered
44+
//enum then import - covered

tests/baselines/reference/augmentedTypesFunction.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,3 +93,6 @@ var y5b;
9393
})(y5b || (y5b = {})); // should be an error
9494
function y5c() {
9595
}
96+
// function then import, messes with other errors
97+
//function y6() { }
98+
//import y6 = require('');

tests/baselines/reference/augmentedTypesInterface.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,4 @@ var i3;
4848
i3[i3["One"] = 0] = "One";
4949
})(i3 || (i3 = {}));
5050
;
51+
//import i4 = require(''); // error

0 commit comments

Comments
 (0)