diff --git a/src/parser.ts b/src/parser.ts index 0c0ac7d9c0..bfbc857053 100644 --- a/src/parser.ts +++ b/src/parser.ts @@ -13,10 +13,6 @@ import { PATH_DELIMITER } from "./common"; -import { - Program -} from "./program"; - import { Tokenizer, Token, @@ -28,7 +24,8 @@ import { import { DiagnosticCode, - DiagnosticEmitter + DiagnosticEmitter, + DiagnosticMessage } from "./diagnostics"; import { @@ -95,8 +92,6 @@ import { /** Parser interface. */ export class Parser extends DiagnosticEmitter { - /** Program being created. */ - program: Program; /** Source file names to be requested next. */ backlog: string[] = new Array(); /** Source file names already seen, that is processed or backlogged. */ @@ -109,11 +104,16 @@ export class Parser extends DiagnosticEmitter { currentSource: Source; /** Dependency map **/ dependees: Map = new Map(); + /** An array of parsed sources. */ + sources: Source[]; /** Constructs a new parser. */ - constructor(program: Program) { - super(program.diagnostics); - this.program = program; + constructor( + diagnostics: DiagnosticMessage[] | null = null, + sources: Source[] | null = null + ) { + super(diagnostics); + this.sources = sources ? sources : new Array(); } /** Parses a file and adds its definitions to the program. */ @@ -145,12 +145,12 @@ export class Parser extends DiagnosticEmitter { : SourceKind.LIBRARY : SourceKind.USER ); - var program = this.program; - program.sources.push(source); + + this.sources.push(source); this.currentSource = source; // tokenize and parse - var tn = new Tokenizer(source, program.diagnostics); + var tn = new Tokenizer(source, this.diagnostics); tn.onComment = this.onComment; var statements = source.statements; while (!tn.skip(Token.ENDOFFILE)) { diff --git a/src/program.ts b/src/program.ts index c44578fbfe..79b30307d3 100644 --- a/src/program.ts +++ b/src/program.ts @@ -537,7 +537,7 @@ export class Program extends DiagnosticEmitter { var nativeFile = new File(this, nativeSource); this.nativeFile = nativeFile; this.filesByName.set(nativeFile.internalName, nativeFile); - this.parser = new Parser(this); + this.parser = new Parser(this.diagnostics, this.sources); this.resolver = new Resolver(this); }