@@ -9,7 +9,7 @@ var Module = require("module"),
9
9
10
10
var __get__Src = __get__ . toString ( ) ,
11
11
__set__Src = __set__ . toString ( ) ,
12
- __with_Src = __with__ . toString ( ) ;
12
+ __with__Src = __with__ . toString ( ) ;
13
13
14
14
/**
15
15
* Does actual rewiring the module. For further documentation @see index.js
@@ -18,7 +18,13 @@ function internalRewire(parentModulePath, targetPath) {
18
18
var targetModule ,
19
19
prelude ,
20
20
appendix ,
21
- src ;
21
+ srcs ;
22
+
23
+ srcs = {
24
+ "__get__" : __get__Src ,
25
+ "__set__" : __set__Src ,
26
+ "__with__" : __with__Src
27
+ } ;
22
28
23
29
// Checking params
24
30
if ( typeof targetPath !== "string" ) {
@@ -42,11 +48,20 @@ function internalRewire(parentModulePath, targetPath) {
42
48
// We prepend a list of all globals declared with var so they can be overridden (without changing original globals)
43
49
prelude = getImportGlobalsSrc ( ) ;
44
50
51
+
45
52
// We append our special setter and getter.
46
53
appendix = "\n" ;
47
- appendix += "module.exports.__set__ = " + __set__Src + "; " ;
48
- appendix += "module.exports.__get__ = " + __get__Src + "; " ;
49
- appendix += "module.exports.__with__ = " + __with_Src + "; " ;
54
+
55
+ Object . keys ( srcs ) . forEach ( function ( key ) {
56
+ var str = [
57
+ "Object.defineProperty(module.exports, '" ,
58
+ key ,
59
+ "', {enumerable: false, value: " ,
60
+ srcs [ key ] ,
61
+ "}); "
62
+ ] . join ( "" ) ;
63
+ appendix += str ;
64
+ } ) ;
50
65
51
66
// Check if the module uses the strict mode.
52
67
// If so we must ensure that "use strict"; stays at the beginning of the module.
0 commit comments