mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-22 22:55:36 -05:00
Add a dedicated 'EndOfFile' token to a SourceFile.
This is important for incremental parsing, as it is where we can attach parse errors at the end of the file to. Also, it helps with things like emitting comments at the end of the file.
This commit is contained in:
@@ -3443,6 +3443,7 @@ module ts {
|
||||
// Start new file on new line
|
||||
writeLine();
|
||||
emitDetachedComments(node);
|
||||
|
||||
// emit prologue directives prior to __extends
|
||||
var startIndex = emitDirectivePrologues(node.statements, /*startWithNewLine*/ false);
|
||||
if (!extendsEmitted && resolver.getNodeCheckFlags(node) & NodeCheckFlags.EmitExtends) {
|
||||
@@ -3474,6 +3475,8 @@ module ts {
|
||||
emitCaptureThisForNodeIfNecessary(node);
|
||||
emitLinesStartingAt(node.statements, startIndex);
|
||||
}
|
||||
|
||||
emitLeadingComments(node.endOfFileToken);
|
||||
}
|
||||
|
||||
function emitNode(node: Node): void {
|
||||
|
||||
@@ -313,8 +313,10 @@ module ts {
|
||||
case SyntaxKind.FinallyBlock:
|
||||
case SyntaxKind.FunctionBlock:
|
||||
case SyntaxKind.ModuleBlock:
|
||||
case SyntaxKind.SourceFile:
|
||||
return children((<Block>node).statements);
|
||||
case SyntaxKind.SourceFile:
|
||||
return children((<SourceFile>node).statements) ||
|
||||
child((<SourceFile>node).endOfFileToken);
|
||||
case SyntaxKind.VariableStatement:
|
||||
return children(node.modifiers) ||
|
||||
children((<VariableStatement>node).declarations);
|
||||
@@ -4294,6 +4296,9 @@ module ts {
|
||||
sourceFile.amdModuleName = referenceComments.amdModuleName;
|
||||
|
||||
sourceFile.statements = parseList(ParsingContext.SourceElements, /*checkForStrictMode*/ true, parseSourceElement);
|
||||
Debug.assert(token === SyntaxKind.EndOfFileToken);
|
||||
sourceFile.endOfFileToken = parseTokenNode();
|
||||
|
||||
sourceFile.externalModuleIndicator = getExternalModuleIndicator();
|
||||
|
||||
sourceFile.nodeCount = nodeCount;
|
||||
|
||||
@@ -786,6 +786,7 @@ module ts {
|
||||
// Source files are declarations when they are external modules.
|
||||
export interface SourceFile extends Declaration {
|
||||
statements: NodeArray<ModuleElement>;
|
||||
endOfFileToken: Node;
|
||||
|
||||
filename: string;
|
||||
text: string;
|
||||
|
||||
@@ -722,6 +722,9 @@ module ts {
|
||||
public filename: string;
|
||||
public text: string;
|
||||
|
||||
public statements: NodeArray<Statement>;
|
||||
public endOfFileToken: Node;
|
||||
|
||||
// These methods will have their implementation provided by the implementation the
|
||||
// compiler actually exports off of SourceFile.
|
||||
public getLineAndCharacterFromPosition: (position: number) => LineAndCharacter;
|
||||
@@ -743,7 +746,6 @@ module ts {
|
||||
public nodeCount: number;
|
||||
public identifierCount: number;
|
||||
public symbolCount: number;
|
||||
public statements: NodeArray<Statement>;
|
||||
public version: string;
|
||||
public isOpen: boolean;
|
||||
public languageVersion: ScriptTarget;
|
||||
|
||||
Reference in New Issue
Block a user