Provide context to parser (#517)
parent
04dfef3b63
commit
30cfa29553
@ -0,0 +1,25 @@
|
|||||||
|
"use strict";
|
||||||
|
|
||||||
|
const vm = {
|
||||||
|
|
||||||
|
runInContext( code, context ) {
|
||||||
|
|
||||||
|
const peg$context = typeof context !== "undefined" ? context : {};
|
||||||
|
|
||||||
|
/* eslint indent: 0 */
|
||||||
|
return eval( `
|
||||||
|
${
|
||||||
|
Object.keys( peg$context )
|
||||||
|
.map( key => `var ${ key } = peg$context.${ key };` )
|
||||||
|
.join( "" )
|
||||||
|
}
|
||||||
|
var vm = null, code = null, context = null;
|
||||||
|
|
||||||
|
${ code }
|
||||||
|
` );
|
||||||
|
|
||||||
|
},
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = vm;
|
Loading…
Reference in New Issue