From 100dada8f9c8ca148e8fafa59911109071ca3d92 Mon Sep 17 00:00:00 2001 From: michal-kapala Date: Thu, 28 Mar 2024 23:34:37 +0100 Subject: [PATCH] fix empty file error + 1.0.10 version bump --- package.json | 2 +- src/frontend/parser.ts | 8 ++++++++ tests/typechecker/errors.test.ts | 5 +++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 09402ae..1341001 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "jitterbit-script", - "version": "1.0.9", + "version": "1.0.10", "description": "Static typechecker and interpreter for Jitterbit Script", "main": "build/index.js", "scripts": { diff --git a/src/frontend/parser.ts b/src/frontend/parser.ts index cba0bfc..220f1ec 100644 --- a/src/frontend/parser.ts +++ b/src/frontend/parser.ts @@ -145,6 +145,14 @@ export default class Parser { * @throws `ParserError` (runtime-only) */ private removeScopeTags(diagnostics?: Diagnostic[]): boolean { + // empty script + if(this.tokens.length === 0) { + if(diagnostics) + return true; + else + throw new ParserError("Empty script."); + } + // find the evaluation scope - ... let result = false; let openIdx: number | null = null; diff --git a/tests/typechecker/errors.test.ts b/tests/typechecker/errors.test.ts index 7b27d2d..5f5eb91 100644 --- a/tests/typechecker/errors.test.ts +++ b/tests/typechecker/errors.test.ts @@ -270,4 +270,9 @@ msg = Case( // Expected expression before the end of script. expect(result.diagnostics[0].error).toStrictEqual(true); }); + + test('Empty file.', function() { + const result = typecheck(""); + expect(result.diagnostics.length).toStrictEqual(0); + }); });