From ebdc01af155ce1cd831df1233797085d7bb953e1 Mon Sep 17 00:00:00 2001 From: Valya Bullions Date: Tue, 13 Aug 2024 15:31:32 +0100 Subject: [PATCH] review changes --- src/index.ts | 2 +- test/ASTHooks.test.ts | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/index.ts b/src/index.ts index ec19468..705b470 100644 --- a/src/index.ts +++ b/src/index.ts @@ -24,7 +24,7 @@ export class Tournament { public errorHandler: (error: Error) => void = () => {}, private _dataNodeName: string = DATA_NODE_NAME, Evaluator: ExpressionEvaluatorClass = FunctionEvaluator, - private astHooks: TournamentHooks = { before: [], after: [] }, + private readonly astHooks: TournamentHooks = { before: [], after: [] }, ) { this.setEvaluator(Evaluator); } diff --git a/test/ASTHooks.test.ts b/test/ASTHooks.test.ts index e1e7857..b934946 100644 --- a/test/ASTHooks.test.ts +++ b/test/ASTHooks.test.ts @@ -6,7 +6,10 @@ describe('AST Hooks', () => { const hook: ASTBeforeHook = (ast) => { expect(ast.program.body).toHaveLength(1); expect(ast.program.body[0].type).toBe('ExpressionStatement'); - expect((ast.program.body[0] as ExpressionStatement).expression.type).toBe('Identifier'); + if (ast.program.body[0].type !== 'ExpressionStatement') { + fail('Expected ExpressionStatement'); + } + expect(ast.program.body[0].expression.type).toBe('Identifier'); }; const t = new Tournament(() => {}, undefined, undefined, { before: [hook], after: [] }); @@ -16,7 +19,10 @@ describe('AST Hooks', () => { test('After hooks are called after variable expansion', () => { const hook: ASTAfterHook = (ast) => { expect(ast.type).toBe('ExpressionStatement'); - expect((ast as ExpressionStatement).expression.type).toBe('MemberExpression'); + if (ast.type !== 'ExpressionStatement') { + fail('Expected ExpressionStatement'); + } + expect(ast.expression.type).toBe('MemberExpression'); }; const t = new Tournament(() => {}, undefined, undefined, { before: [], after: [hook] });