Skip to content

Commit

Permalink
review changes
Browse files Browse the repository at this point in the history
  • Loading branch information
valya committed Aug 13, 2024
1 parent 9b6c605 commit ebdc01a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
10 changes: 8 additions & 2 deletions test/ASTHooks.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: [] });
Expand All @@ -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] });
Expand Down

0 comments on commit ebdc01a

Please sign in to comment.