From dc925959887990de3b1d014f76a7950912196726 Mon Sep 17 00:00:00 2001 From: Ankit Date: Mon, 5 Feb 2024 09:27:10 +0000 Subject: [PATCH] fix: types made optional fix #84 --- src/index.ts | 3 +-- src/lexer.ts | 2 +- src/postfix_evaluator.ts | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/index.ts b/src/index.ts index e166bbd..c3ecf32 100644 --- a/src/index.ts +++ b/src/index.ts @@ -7,7 +7,6 @@ import { createMathFunctions } from './functions' // var Mexp = function (parsed) { // this.value = parsed // } - class Mexp { static TOKEN_TYPES = tokenTypes static tokenTypes = tokenTypes @@ -16,7 +15,7 @@ class Mexp { addToken = addToken lex = lex postfixEval = postfixEval - eval(string: string, tokens: Token[], Constants: Constants) { + eval(string: string, tokens?: Token[], Constants?: Constants) { return this.postfixEval(this.toPostfix(this.lex(string, tokens)), Constants) } math!: ReturnType diff --git a/src/lexer.ts b/src/lexer.ts index cd76ebe..521759e 100644 --- a/src/lexer.ts +++ b/src/lexer.ts @@ -195,7 +195,7 @@ function tokenize(mexp: Mexp, string: string) { } return nodes; } -export const lex = function (this: Mexp, inp: string, tokens: Token[]) { +export const lex = function (this: Mexp, inp: string, tokens?: Token[]) { "use strict"; var changeSignObj: ParsedToken = { value: this.math.changeSign, diff --git a/src/postfix_evaluator.ts b/src/postfix_evaluator.ts index 65f06b1..11bcf55 100644 --- a/src/postfix_evaluator.ts +++ b/src/postfix_evaluator.ts @@ -1,7 +1,7 @@ import { toPostfix } from './postfix' import { tokenTypes, ParsedToken } from './token' export type Constants = Record -export function postfixEval(arr: ReturnType, Constants: Constants) { +export function postfixEval(arr: ReturnType, Constants?: Constants) { Constants = Constants || {} Constants.PI = Math.PI Constants.E = Math.E