@makano/rew 1.4.2 → 1.4.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/rew/modules/context.js +36 -4
 - package/package.json +1 -1
 - package/runtime.d.ts +3 -1
 
| 
         @@ -16,6 +16,7 @@ const STDNS = require("../const/stdns"); 
     | 
|
| 
       16 
16 
     | 
    
         | 
| 
       17 
17 
     | 
    
         
             
            let mainFile = "";
         
     | 
| 
       18 
18 
     | 
    
         
             
            const isMainFile = (filepath) => filepath == mainFile;
         
     | 
| 
      
 19 
     | 
    
         
            +
            const globalContext = {};
         
     | 
| 
       19 
20 
     | 
    
         
             
            module.exports.prepareContext = function (
         
     | 
| 
       20 
21 
     | 
    
         
             
              custom_context,
         
     | 
| 
       21 
22 
     | 
    
         
             
              options,
         
     | 
| 
         @@ -42,7 +43,8 @@ module.exports.prepareContext = function ( 
     | 
|
| 
       42 
43 
     | 
    
         
             
                __using__: {},
         
     | 
| 
       43 
44 
     | 
    
         
             
                get _(){
         
     | 
| 
       44 
45 
     | 
    
         
             
                  return void 0;
         
     | 
| 
       45 
     | 
    
         
            -
                }
         
     | 
| 
      
 46 
     | 
    
         
            +
                },
         
     | 
| 
      
 47 
     | 
    
         
            +
                ...globalContext
         
     | 
| 
       46 
48 
     | 
    
         
             
              };
         
     | 
| 
       47 
49 
     | 
    
         
             
              if (options.useContext) {
         
     | 
| 
       48 
50 
     | 
    
         
             
                context = {
         
     | 
| 
         @@ -69,6 +71,8 @@ module.exports.prepareContext = function ( 
     | 
|
| 
       69 
71 
     | 
    
         
             
                      this.define = std.prototype.define;
         
     | 
| 
       70 
72 
     | 
    
         
             
                      this.Main = std.prototype.Main;
         
     | 
| 
       71 
73 
     | 
    
         
             
                      this.attach = std.prototype.attach;
         
     | 
| 
      
 74 
     | 
    
         
            +
                      this.named = std.prototype.named;
         
     | 
| 
      
 75 
     | 
    
         
            +
                      this.detach = std.prototype.detach;
         
     | 
| 
       72 
76 
     | 
    
         
             
                      this.out = std.prototype.out;
         
     | 
| 
       73 
77 
     | 
    
         
             
                      this.inp = std.prototype.in;
         
     | 
| 
       74 
78 
     | 
    
         
             
                      this['@cb'] = cb;
         
     | 
| 
         @@ -94,10 +98,38 @@ module.exports.prepareContext = function ( 
     | 
|
| 
       94 
98 
     | 
    
         
             
                    }
         
     | 
| 
       95 
99 
     | 
    
         
             
                  }
         
     | 
| 
       96 
100 
     | 
    
         
             
                  return (['main', cb?.main ?? cb]);
         
     | 
| 
       97 
     | 
    
         
            -
                },  
     | 
| 
       98 
     | 
    
         
            -
                   
     | 
| 
       99 
     | 
    
         
            -
             
     | 
| 
      
 101 
     | 
    
         
            +
                }, named: (name) => {
         
     | 
| 
      
 102 
     | 
    
         
            +
                  return (item) => [name, item];
         
     | 
| 
      
 103 
     | 
    
         
            +
                }, attach: (name, object) => {
         
     | 
| 
      
 104 
     | 
    
         
            +
                  if(Array.isArray(name) && name.length == 2 && typeof name[0] == 'string'){
         
     | 
| 
      
 105 
     | 
    
         
            +
                    object = name[1];
         
     | 
| 
      
 106 
     | 
    
         
            +
                    name = name[0];
         
     | 
| 
      
 107 
     | 
    
         
            +
                  }
         
     | 
| 
      
 108 
     | 
    
         
            +
                  if(typeof name == "object" && typeof object == "string"){
         
     | 
| 
      
 109 
     | 
    
         
            +
                    const tname = object;
         
     | 
| 
      
 110 
     | 
    
         
            +
                    object = name;
         
     | 
| 
      
 111 
     | 
    
         
            +
                    name = tname;
         
     | 
| 
      
 112 
     | 
    
         
            +
                  }
         
     | 
| 
      
 113 
     | 
    
         
            +
                  if(typeof name == "object" && !object){
         
     | 
| 
      
 114 
     | 
    
         
            +
                    object = name;
         
     | 
| 
      
 115 
     | 
    
         
            +
                    name = object.name;
         
     | 
| 
      
 116 
     | 
    
         
            +
                  }
         
     | 
| 
      
 117 
     | 
    
         
            +
                  if(typeof name == "function"){
         
     | 
| 
      
 118 
     | 
    
         
            +
                    object = name;
         
     | 
| 
      
 119 
     | 
    
         
            +
                    name = object.name;
         
     | 
| 
      
 120 
     | 
    
         
            +
                  }
         
     | 
| 
      
 121 
     | 
    
         
            +
                  if(!name) return false;
         
     | 
| 
      
 122 
     | 
    
         
            +
                  globalContext[name] = object;
         
     | 
| 
      
 123 
     | 
    
         
            +
                  context[name] = object;
         
     | 
| 
      
 124 
     | 
    
         
            +
                  return true;
         
     | 
| 
      
 125 
     | 
    
         
            +
                }, detach: (nameOrObject) => {
         
     | 
| 
      
 126 
     | 
    
         
            +
                  const name = Object.keys(globalContext).find((key) => key == nameOrObject || globalContext[key] == nameOrObject);
         
     | 
| 
      
 127 
     | 
    
         
            +
                  if(name) {
         
     | 
| 
      
 128 
     | 
    
         
            +
                    delete globalContext[name];
         
     | 
| 
      
 129 
     | 
    
         
            +
                    delete context[name];
         
     | 
| 
      
 130 
     | 
    
         
            +
                    return true;
         
     | 
| 
       100 
131 
     | 
    
         
             
                  }
         
     | 
| 
      
 132 
     | 
    
         
            +
                  return false;
         
     | 
| 
       101 
133 
     | 
    
         
             
                } }
         
     | 
| 
       102 
134 
     | 
    
         
             
                Object.defineProperty(std.prototype, 'void', {
         
     | 
| 
       103 
135 
     | 
    
         
             
                  get: () => void 0
         
     | 
    
        package/package.json
    CHANGED
    
    
    
        package/runtime.d.ts
    CHANGED
    
    | 
         @@ -1029,8 +1029,10 @@ declare namespace Rew { 
     | 
|
| 
       1029 
1029 
     | 
    
         
             
                prototype: {
         
     | 
| 
       1030 
1030 
     | 
    
         
             
                  void: void,
         
     | 
| 
       1031 
1031 
     | 
    
         
             
                  Main: () => [string, () => any],
         
     | 
| 
      
 1032 
     | 
    
         
            +
                  named: (name: string) => (item: any) => [string, any],
         
     | 
| 
       1032 
1033 
     | 
    
         
             
                  define: (name: string, object: any) => any,
         
     | 
| 
       1033 
     | 
    
         
            -
                  attach: (object: any) => any,
         
     | 
| 
      
 1034 
     | 
    
         
            +
                  attach: (name: string | any, object: any) => any,
         
     | 
| 
      
 1035 
     | 
    
         
            +
                  detach: (nameOrObject: any) => any,
         
     | 
| 
       1034 
1036 
     | 
    
         | 
| 
       1035 
1037 
     | 
    
         
             
                  out: stdout;
         
     | 
| 
       1036 
1038 
     | 
    
         
             
                  in: stdin;
         
     |