packages/pegjs/lib/util/vm.js
function evalModule( source, context ) {

    const argumentKeys = Object.keys( context );
    const argumentValues = argumentKeys.map( argument => context[ argument ] );

    const sandbox = { exports: {} };
    argumentKeys.push( "module", "exports", source );
    argumentValues.push( sandbox, sandbox.exports );

    Function( ...argumentKeys )( ...argumentValues );

    return sandbox.exports;

}
function evalModule( source, context ) {

    const argumentKeys = Object.keys( context );
    const argumentValues = argumentKeys.map( argument => context[ argument ] );

    const sandbox = { exports: {} };
    argumentKeys.push( "module", "exports", source );
    argumentValues.push( sandbox, sandbox.exports );

    Function( ...argumentKeys )( ...argumentValues );

    return sandbox.exports;

}
function evalModule ( source , context ) { const argumentKeys = Object . keys ( context ) ; const argumentValues = argumentKeys . map ( argument => context [ argument ] ) ; const sandbox = { exports : { } } ; argumentKeys . push ( "module" , "exports" , source ) ; argumentValues . push ( sandbox , sandbox . exports ) ; Function ( ... argumentKeys ) ( ... argumentValues ) ; return sandbox . exports ; }
`eval` the given source as a CommonJS module, using properties found in `context` as top-level variables.

Based on `vm.runInContext` found in Node.js, this is a cross-env solution.
eval the given source as a CommonJS module using properties found in context as top - level variables .