From 53e78056e62d4d3550b887ca5591044c659f3d30 Mon Sep 17 00:00:00 2001 From: Duncan Uszkay Date: Tue, 31 Mar 2020 14:52:03 -0400 Subject: [PATCH] Fail early when a top level statement fails to resolve --- src/compiler.ts | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/compiler.ts b/src/compiler.ts index 495f670822..61196e611c 100644 --- a/src/compiler.ts +++ b/src/compiler.ts @@ -908,7 +908,7 @@ export class Compiler extends DiagnosticEmitter { var flow = startFunction.flow; this.currentFlow = flow; for (let statements = file.source.statements, i = 0, k = statements.length; i < k; ++i) { - this.compileTopLevelStatement(statements[i], startFunctionBody); + if(!this.compileTopLevelStatement(statements[i], startFunctionBody)) return; } this.finishAutoreleases(flow, startFunctionBody); // no need to insert unreachable since last statement should have done that @@ -1835,7 +1835,7 @@ export class Compiler extends DiagnosticEmitter { // === Statements =============================================================================== /** Compiles a top level statement (incl. function declarations etc.) to the specified body. */ - compileTopLevelStatement(statement: Statement, body: ExpressionRef[]): void { + compileTopLevelStatement(statement: Statement, body: ExpressionRef[]): bool { switch (statement.kind) { case NodeKind.CLASSDECLARATION: { let memberStatements = (statement).members; @@ -1861,7 +1861,7 @@ export class Compiler extends DiagnosticEmitter { this.currentParent = element; let memberStatements = declaration.members; for (let i = 0, k = memberStatements.length; i < k; ++i) { - this.compileTopLevelStatement(memberStatements[i], body); + if(!this.compileTopLevelStatement(memberStatements[i], body)) return false; } this.currentParent = previousParent; } @@ -1876,7 +1876,9 @@ export class Compiler extends DiagnosticEmitter { if ( !element.is(CommonFlags.AMBIENT) && // delay imports !element.hasDecorator(DecoratorFlags.LAZY) - ) this.compileGlobal(element); + ) { + if(!this.compileGlobal(element)) return false; + } } } break; @@ -1884,7 +1886,7 @@ export class Compiler extends DiagnosticEmitter { case NodeKind.FIELDDECLARATION: { let element = this.program.getElementByDeclaration(statement); if (element !== null && element.kind == ElementKind.GLOBAL) { // static - if (!element.hasDecorator(DecoratorFlags.LAZY)) this.compileGlobal(element); + if (!element.hasDecorator(DecoratorFlags.LAZY)) return this.compileGlobal(element); } break; } @@ -1897,7 +1899,7 @@ export class Compiler extends DiagnosticEmitter { break; } case NodeKind.EXPORTDEFAULT: { - this.compileTopLevelStatement((statement).declaration, body); + return this.compileTopLevelStatement((statement).declaration, body); break; } case NodeKind.IMPORT: { @@ -1916,6 +1918,8 @@ export class Compiler extends DiagnosticEmitter { break; } } + + return true; } /** Compiles a statement. */