File tree Expand file tree Collapse file tree 1 file changed +4
-10
lines changed Expand file tree Collapse file tree 1 file changed +4
-10
lines changed Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ import reactSVGLoader from '../src/loader';
22import React from 'react' ;
33import testUtils from 'react-addons-test-utils' ;
44import test from 'tape' ;
5+ import vm from 'vm' ;
56
67function loader ( content ) {
78 return new Promise ( function ( resolve , reject ) {
@@ -13,17 +14,10 @@ function loader(content) {
1314 return function ( err , result ) {
1415 if ( err ) return reject ( err ) ;
1516
16- // there is a bug that
17- // vm.runInContext won't work in Node inside Promise (microtask)
1817 let exports = { } ;
19- let module = { exports } ;
20-
21- // so the ugly eval comes in
22- // since we generate the code, I assume safely that it's
23- // doing no harm
24- eval ( `(function(module, exports) { ${ result } })(module, exports)` ) ;
25-
26- resolve ( module . exports . default ) ;
18+ let sandbox = { exports, require } ;
19+ vm . runInNewContext ( result , sandbox ) ;
20+ resolve ( sandbox . exports . default ) ;
2721 }
2822 }
2923 } ;
You can’t perform that action at this time.
0 commit comments