import * as tr from "text-runner-core" ; import { appendAsyncCallback } from "../helpers/append-async-callback" ; import { hasCallbackPlaceholder } from "../helpers/has-callback-placeholder" ; import { replaceAsyncCallback } from "../helpers/replace-async-callback" ; import { replaceRequireLocalModule } from "../helpers/replace-require-local-module" ; import { replaceVariableDeclarations } from "../helpers/replace-variable-declarations" ; type DoneFunction = ( err ? : Error ) => void ; /** The "runJavascript" action runs the JavaScript code given in the code block. */ export function runnable ( action , done ) { action . name ( "run JavaScript" ) ; let code = action . region . text ( ) ; if ( code === "" ) { done ( new Error ( "no JavaScript code found" ) ) ; return ; } code = replaceRequireLocalModule ( code ) ; code = replaceVariableDeclarations ( code ) ; const __finished = done ; code = hasCallbackPlaceholder ( code ) ? replaceAsyncCallback ( code ) : appendAsyncCallback ( code ) ; action . log ( code ) ; eval ( code ) ; }