@@ -3,6 +3,7 @@ import type es from 'estree'
33
44import type { IOptions } from '..'
55import * as errors from '../errors/errors'
6+ import { RuntimeSourceError } from '../errors/runtimeSourceError'
67import { parse } from '../parser/parser'
78import type {
89 BlockExpression ,
@@ -25,7 +26,6 @@ import { filterImportDeclarations } from '../utils/ast/helpers'
2526import { evaluateBinaryExpression , evaluateUnaryExpression } from '../utils/operators'
2627import * as rttc from '../utils/rttc'
2728import { checkProgramForUndefinedVariables } from '../validator/validator'
28- import { RuntimeSourceError } from '../errors/runtimeSourceError'
2929import { nodeToValue , objectToString , valueToExpression } from './converter'
3030import * as builtin from './lib'
3131import {
@@ -210,7 +210,7 @@ function findMain(
210210
211211 const freeNames : any [ ] = [ ]
212212
213- const finders = {
213+ const finders : Partial < Record < any , ( target : any ) => void > > = {
214214 Identifier ( target : es . Identifier ) : void {
215215 seenBefore . set ( target , target )
216216 let bound = false
@@ -418,7 +418,7 @@ function substituteMain(
418418 * and push the appropriate access string into the path
419419 * 3. Return the dummyReplacement
420420 */
421- const substituters = {
421+ const substituters : Partial < Record < substituterNodes [ 'type' ] , any > > = {
422422 // if name to be replaced is found,
423423 // push endMarker into path
424424 Identifier (
@@ -1325,7 +1325,7 @@ function reduceMain(
13251325
13261326 // converts body of code to string
13271327 function bodify ( target : substituterNodes ) : string {
1328- const bodifiers = {
1328+ const bodifiers : Partial < Record < substituterNodes [ 'type' ] , ( target : any ) => string > > = {
13291329 Literal : ( target : es . Literal ) : string =>
13301330 target . raw !== undefined ? target . raw : String ( target . value ) ,
13311331
@@ -1409,7 +1409,7 @@ function reduceMain(
14091409
14101410 // generates string to explain current step
14111411 function explain ( target : substituterNodes ) : string {
1412- const explainers = {
1412+ const explainers : Partial < Record < substituterNodes [ 'type' ] , ( target : any ) => string > > = {
14131413 BinaryExpression : ( target : es . BinaryExpression ) : string =>
14141414 'Binary expression ' + bodify ( target ) + ' evaluated' ,
14151415
@@ -1496,7 +1496,7 @@ function reduceMain(
14961496 return explainer === undefined ? '...' : explainer ( target )
14971497 }
14981498
1499- const reducers = {
1499+ const reducers : Partial < Record < substituterNodes [ 'type' ] , any > > = {
15001500 // source 0
15011501 Identifier (
15021502 node : es . Identifier ,
@@ -1738,8 +1738,10 @@ function reduceMain(
17381738 paths ,
17391739 explain ( node )
17401740 ]
1741+ // @ts -expect-error implicitAnyIndexError
17411742 } else if ( typeof builtin [ ( callee as es . Identifier ) . name ] === 'function' ) {
17421743 // Source specific built-in function
1744+ // @ts -expect-error implicitAnyIndexError
17431745 return [ builtin [ ( callee as es . Identifier ) . name ] ( ...args ) , context , paths , explain ( node ) ]
17441746 } else {
17451747 // Common built-in function
@@ -1827,10 +1829,12 @@ function reduceMain(
18271829 )
18281830
18291831 // Fix path highlighting after preserving first statement
1830- path . forEach ( pathStep => {
1832+ path . forEach ( ( pathStep : any [ ] ) => {
18311833 pathStep . forEach ( ( _ , i ) => {
18321834 if ( i == 0 ) {
1833- pathStep [ i ] = pathStep [ i ] . replace ( / \d + / g, match => String ( Number ( match ) + 1 ) )
1835+ pathStep [ i ] = pathStep [ i ] . replace ( / \d + / g, ( match : any ) =>
1836+ String ( Number ( match ) + 1 )
1837+ )
18341838 }
18351839 } )
18361840 } )
@@ -2055,10 +2059,12 @@ function reduceMain(
20552059 )
20562060
20572061 // Fix path highlighting after preserving first statement
2058- path . forEach ( pathStep => {
2062+ path . forEach ( ( pathStep : any [ ] ) => {
20592063 pathStep . forEach ( ( _ , i ) => {
20602064 if ( i == 0 ) {
2061- pathStep [ i ] = pathStep [ i ] . replace ( / \d + / g, match => String ( Number ( match ) + 1 ) )
2065+ pathStep [ i ] = pathStep [ i ] . replace ( / \d + / g, ( match : any ) =>
2066+ String ( Number ( match ) + 1 )
2067+ )
20622068 }
20632069 } )
20642070 } )
@@ -2277,10 +2283,12 @@ function reduceMain(
22772283 )
22782284
22792285 // Fix path highlighting after preserving first statement
2280- path . forEach ( pathStep => {
2286+ path . forEach ( ( pathStep : any [ ] ) => {
22812287 pathStep . forEach ( ( _ , i ) => {
22822288 if ( i == 0 ) {
2283- pathStep [ i ] = pathStep [ i ] . replace ( / \d + / g, match => String ( Number ( match ) + 1 ) )
2289+ pathStep [ i ] = pathStep [ i ] . replace ( / \d + / g, ( match : any ) =>
2290+ String ( Number ( match ) + 1 )
2291+ )
22842292 }
22852293 } )
22862294 } )
@@ -2491,7 +2499,7 @@ function treeifyMain(target: substituterNodes): substituterNodes {
24912499 // has an identifier: replace with the name
24922500 // else: replace with an identifer "=>"
24932501 let verboseCount = 0
2494- const treeifiers = {
2502+ const treeifiers : Partial < Record < substituterNodes [ 'type' ] , ( target : any ) => any > > = {
24952503 // Identifier: return
24962504 ExpressionStatement : ( target : es . ExpressionStatement ) : es . ExpressionStatement => {
24972505 return ast . expressionStatement ( treeify ( target . expression ) as es . Expression )
@@ -2643,7 +2651,7 @@ function jsTreeifyMain(
26432651 // visited before recursing to this target: replace with the name
26442652 // else: replace with a FunctionExpression
26452653 let verboseCount = 0
2646- const treeifiers = {
2654+ const treeifiers : Partial < Record < substituterNodes [ 'type' ] , ( target : any ) => substituterNodes > > = {
26472655 Identifier : ( target : es . Identifier ) : es . Identifier => {
26482656 if ( readOnly && target . name . startsWith ( 'anonymous_' ) ) {
26492657 return ast . identifier ( '[Function]' )
@@ -2825,7 +2833,7 @@ function pathifyMain(
28252833 let endIndex = path === undefined ? 0 : path . length - 1
28262834 const redexMarker = ast . identifier ( '@redex' ) as substituterNodes
28272835 const withBrackets = ast . identifier ( '(@redex)' ) as substituterNodes
2828- const pathifiers = {
2836+ const pathifiers : Partial < Record < substituterNodes [ 'type' ] , any > > = {
28292837 ExpressionStatement : ( target : es . ExpressionStatement ) : es . ExpressionStatement => {
28302838 let exp = jsTreeifyMain ( target . expression , visited , true ) as es . Expression
28312839 if ( path [ pathIndex ] === 'expression' ) {
@@ -3269,10 +3277,10 @@ function substPredefinedFns(program: es.Program, context: Context): [es.Program,
32693277}
32703278
32713279function substPredefinedConstants ( program : es . Program ) : es . Program {
3272- const constants = [ [ 'undefined' , undefined ] ]
3280+ const constants : any [ ] = [ [ 'undefined' , undefined ] ]
32733281 const mathConstants = Object . getOwnPropertyNames ( Math )
3274- . filter ( name => typeof Math [ name ] !== 'function' )
3275- . map ( name => [ 'math_' + name , Math [ name ] ] )
3282+ . filter ( name => typeof Math [ name as keyof typeof Math ] !== 'function' )
3283+ . map ( name => [ 'math_' + name , Math [ name as keyof typeof Math ] ] )
32763284 let substed = program
32773285 for ( const nameValuePair of constants . concat ( mathConstants ) ) {
32783286 substed = substituteMain (
0 commit comments