From e6c54052f13c7a000df2bbd0b9ea28024ac544aa Mon Sep 17 00:00:00 2001 From: Sam Vervaeck Date: Sat, 23 May 2020 22:37:41 +0200 Subject: [PATCH] Integrate type checker in frontend --- src/bin/bolt.ts | 7 +++++++ src/frontend.ts | 8 +++----- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/bin/bolt.ts b/src/bin/bolt.ts index 6fa1fa53d..2c767086f 100644 --- a/src/bin/bolt.ts +++ b/src/bin/bolt.ts @@ -69,12 +69,19 @@ yargs .string('target') .describe('target', 'The target language to compile to.') .default('target', 'JS') + .boolean('force') + .describe('force', 'Ignore as much errors as possible.') + .default('force', false) , args => { const sourceFiles = toArray(args.files as string[] | string).map(parseSourceFile); const program = new Program(sourceFiles); const frontend = new Frontend(); + frontend.typeCheck(program); + if (frontend.diagnostics.hasErrors && !args.force) { + process.exit(1); + } frontend.compile(program, args.target); }) diff --git a/src/frontend.ts b/src/frontend.ts index b376e4ac9..659b043f4 100644 --- a/src/frontend.ts +++ b/src/frontend.ts @@ -88,18 +88,16 @@ export class Frontend { return new Package(projectDir); } - public compile(program: Program, target: string) { - + public typeCheck(program: Program) { for (const sourceFile of program.getAllSourceFiles()) { this.checker.registerSourceFile(sourceFile as BoltSourceFile); } for (const sourceFile of program.getAllSourceFiles()) { this.checker.checkSourceFile(sourceFile as BoltSourceFile); } + } - if (this.diagnostics.hasErrors) { - throw new Error(`Compilation failed because of type-checking errors.`); - } + public compile(program: Program, target: string) { switch (target) {