Install from npm:
npm install -D error-trapper
And add babel-macros plugin to your babel config.
For wrap function:
importinitializefrom'error-trapper';importWRAPfrom'error-trapper/macros/wrap-function.macro';initialize(`${window.location.hash}../node_modules/error-trapper/lib/esprima-bundle.js`);WRAP(()=>{constfoo={firstName: 'Andy'};constbar=foo.lastName.toString;},(e,scope)=>{console.dir(scope);})();Console output:
Or print with ErrorTrap.printContext:
For parse scope:
importinitializefrom'error-trapper';importPARSE_SCOPEfrom'error-trapper/macros/parse-scope.macro';initialize(`${window.location.hash}../node_modules/error-trapper/lib/esprima-bundle.js`);try{constfoo={firstName: 'Andy'};constbar=foo.lastName.toString;}catch(e){PARSE_SCOPE((scope)=>{console.dir(scope);});}
