44*/
55var path = require ( "path" ) ;
66var ModuleAliasPlugin = require ( "enhanced-resolve/lib/ModuleAliasPlugin" ) ;
7+ var ModuleParserHelpers = require ( "./ModuleParserHelpers" ) ;
78
89function NodeSourcePlugin ( ) {
910}
1011module . exports = NodeSourcePlugin ;
1112NodeSourcePlugin . prototype . apply = function ( compiler ) {
12- function addParsedVariable ( name , expression ) {
13- if ( ! this . state . current . addVariable ) return false ;
14- var deps = [ ] ;
15- this . parse ( expression , { current : {
16- addDependency : function ( dep ) {
17- dep . userRequest = name ;
18- deps . push ( dep ) ;
19- }
20- } } ) ;
21- this . state . current . addVariable ( name , expression , deps ) ;
22- return true ;
23- }
2413 function ignore ( ) { return true ; }
2514 compiler . parser . plugin ( "expression process" , function ( expr ) {
26- return addParsedVariable . call ( this , "process" , "require(" + JSON . stringify ( path . join ( __dirname , ".." , ".." , "buildin" , "process.js" ) ) + ")" ) ;
15+ return ModuleParserHelpers . addParsedVariable ( this , "process" , "require(" + JSON . stringify ( path . join ( __dirname , ".." , ".." , "buildin" , "process.js" ) ) + ")" ) ;
2716 } ) ;
2817 compiler . parser . plugin ( "expression global" , function ( expr ) {
29- return this . state . current . addVariable ( "global" , "this" ) ;
18+ this . state . current . addVariable ( "global" , "this" ) ;
19+ return true ;
3020 } ) ;
3121 compiler . parser . plugin ( "expression __filename" , function ( expr ) {
3222 return this . state . current . addVariable ( "__filename" , "window.location.pathname" ) ;
@@ -38,7 +28,7 @@ NodeSourcePlugin.prototype.apply = function(compiler) {
3828 compiler . parser . plugin ( "expression module.loaded" , ignore ) ;
3929 compiler . parser . plugin ( "expression module.id" , ignore ) ;
4030 compiler . parser . plugin ( "expression module" , function ( expr ) {
41- return addParsedVariable . call ( this , "module" , "require(" + JSON . stringify ( path . join ( __dirname , ".." , ".." , "buildin" , "module.js" ) ) + ")(module)" ) ;
31+ return ModuleParserHelpers . addParsedVariable ( this , "module" , "require(" + JSON . stringify ( path . join ( __dirname , ".." , ".." , "buildin" , "module.js" ) ) + ")(module)" ) ;
4232 } ) ;
4333 compiler . resolvers . normal . apply (
4434 new ModuleAliasPlugin ( ( function ( ) {
0 commit comments