File tree Expand file tree Collapse file tree 5 files changed +36
-128
lines changed Expand file tree Collapse file tree 5 files changed +36
-128
lines changed Original file line number Diff line number Diff line change 99 * @throws {TypeError }
1010 * @return {* }
1111 */
12- function __get__ ( ) {
13- arguments . varName = arguments [ 0 ] ;
12+ function __get__ ( varName ) {
1413 try {
15- if ( arguments . varName && typeof arguments . varName === "string" ) {
16- return eval ( arguments . varName ) ;
14+ if ( varName && typeof varName === "string" ) {
15+ return eval ( varName ) ;
1716 } else {
1817 throw new TypeError ( "__get__ expects a non-empty string" ) ;
1918 }
2019 } catch ( e ) {
21- return ;
20+ return {
21+ __get__ : ( ) => { }
22+ }
2223 }
2324}
2425
Load Diff This file was deleted.
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 11"use strict" ;
22
33var __get__ = require ( "./__get__.js" ) ;
4- var __set__ = require ( "./__set__.js" ) ;
5- var __with__ = require ( "./__with__.js" ) ;
64
75var srcs = {
86 "__get__" : __get__ . toString ( ) ,
9- "__set__" : __set__ . toString ( ) ,
10- "__with__" : __with__ . toString ( )
117} ;
128
139function getDefinePropertySrc ( ) {
Original file line number Diff line number Diff line change 11var rewireModule = require ( "./rewire.js" ) ;
2+ var fs = require ( 'fs' ) ;
3+
4+ function fileExists ( path , silent ) {
5+ if ( silent === void 0 ) { silent = true ; }
6+ try {
7+ fs . accessSync ( path , fs . F_OK ) ;
8+ }
9+ catch ( e ) {
10+ if ( e ) {
11+ if ( ! silent ) {
12+ console . log ( e ) ;
13+ }
14+ return false ;
15+ }
16+ }
17+ return true ;
18+ }
219
320/**
421 * Adds a special setter and getter to the module located at filename. After the module has been rewired, you can
@@ -8,9 +25,20 @@ var rewireModule = require("./rewire.js");
825 * @return {* } the rewired module
926 */
1027function rewire ( filename ) {
11- return rewireModule ( module . parent , filename ) ;
28+ // is not a package path
29+ if ( ! filename . match ( / ^ [ a - z A - Z ] / ) ) {
30+ // if the file doesn't exist yet,
31+ // set to get undefined
32+ if ( ! fileExists ( filename ) ) {
33+ return {
34+ __get__ : ( ) => { }
35+ } ;
36+ }
37+ }
38+ // proceed with rewiring
39+ return rewireModule ( module . parent , filename ) ;
1240}
1341
1442module . exports = rewire ;
1543
16- delete require . cache [ __filename ] ; // deleting self from module cache so the parent module is always up to date
44+ delete require . cache [ __filename ] ; // deleting self from module cache so the parent module is always up to date
You can’t perform that action at this time.
0 commit comments