@@ -89,7 +89,7 @@ function parseList(expression: string): ListArray {
89
89
. replaceAll ( "(" , "[" )
90
90
. replaceAll ( ")" , "]" )
91
91
. replaceAll ( " " , "," )
92
- . replaceAll ( / [ a - z ] ( [ a - z ] | \d ) * / g, ( a ) => '"' + a + '"' )
92
+ . replaceAll ( / [ a - z ] ( [ a - z ] | \d ) * / g, ( a ) => '"' + a + '"' ) ,
93
93
) ;
94
94
}
95
95
@@ -149,7 +149,7 @@ function calculate(expression: Expression, scope: ScopeList): number {
149
149
expression . declarations . forEach ( ( declaration ) => {
150
150
newScope . variables . set (
151
151
declaration . id . name ,
152
- calculate ( declaration . init , newScope )
152
+ calculate ( declaration . init , newScope ) ,
153
153
) ;
154
154
} ) ;
155
155
return calculate ( expression . return . argument , newScope ) ;
@@ -165,7 +165,7 @@ export type Expression =
165
165
export class ScopeList {
166
166
constructor (
167
167
public readonly variables : Map < string , number > = new Map ( ) ,
168
- public parent : ScopeList | null | undefined = null
168
+ public parent : ScopeList | null | undefined = null ,
169
169
) { }
170
170
}
171
171
export interface VariableDeclarator {
@@ -202,8 +202,7 @@ export interface Identifier {
202
202
name : string ;
203
203
}
204
204
export default evaluate ;
205
-
206
- function getVariable ( scope : ScopeList , name : string ) : number {
205
+ export function getVariable ( scope : ScopeList , name : string ) : number {
207
206
if ( ! scope . parent && ! scope . variables . has ( name ) ) {
208
207
throw Error ( "Variable not found:" + name ) ;
209
208
}
0 commit comments