@makano/rew 1.2.83 → 1.2.85

Sign up to get free protection for your applications and to get access to all the features.
@@ -64,24 +64,27 @@ module.exports.Usage = class Usage {
64
64
 
65
65
  class Namespace extends module.exports.Usage {
66
66
  namespace = {};
67
- constructor(ns, cb){
67
+ constructor(ns, cb, parent){
68
68
  super('namespace');
69
69
  if(ns instanceof Namespace.Group){
70
70
  if(ns.onUse) this.onUse = ns.onUse;
71
+ if(ns.parent) parent = ns.parent;
72
+ if(ns.onAfterUse) this.onAfterUse = ns.onAfterUse;
71
73
  cb = ns.g[1]
72
74
  ns = ns.g[0]
73
75
  }
74
76
  this.save = false;
75
77
  this.trigger = cb;
76
78
  this.namespace = ns;
79
+ this.parent = parent;
77
80
  }
78
81
 
79
82
  static Group = class NamespaceGroup extends module.exports.Usage.Group {}
80
83
  }
81
84
  module.exports.Namespace = Namespace;
82
85
 
83
- module.exports.namespace = (namespace, cb) => {
84
- return new Namespace(namespace, cb);
86
+ module.exports.namespace = (namespace, cb, parent) => {
87
+ return new Namespace(namespace, cb, parent);
85
88
  }
86
89
 
87
90
  module.exports.namespace.group = (group, props) => new Namespace.Group(group, props);
@@ -326,16 +326,17 @@ function compileRewStuff(content, options) {
326
326
  nextToken.value &&
327
327
  nextToken.value !== 'undefined' && !options.keepImports
328
328
  ) {
329
- let next = {...nextToken};
329
+ let next = {...nextToken}, isClass = false;
330
330
  if(next.value == 'default'){
331
331
  i += 2;
332
332
  }
333
333
  if(next.value == 'class'){
334
334
  next.value = gnextToken(i, n + 1, tokens)?.token.value || "default";
335
+ isClass = true;
335
336
  }
336
337
  hooks.push({
337
338
  index: i + 1,
338
- value: `"${next.value}", `,
339
+ value: `"${next.value}", ${isClass ? `${next.value} = ` : ''}`,
339
340
  });
340
341
  }
341
342
 
@@ -123,12 +123,15 @@ module.exports.prepareContext = function (
123
123
  }
124
124
  } else if(name instanceof Namespace) {
125
125
  const trigger = name.trigger;
126
- const childContext = {...context, ...name.namespace, trigger};
126
+ const parentContext = name.parent || context;
127
+ const childContext = {...parentContext, ...name.namespace, trigger};
127
128
  childContext.currentNamespace = name.namespace;
128
- childContext.parentNamespace = context;
129
+ childContext.parentNamespace = parentContext;
129
130
  const code = `(${trigger.toString()})()`;
130
- if(name.onUse) name.onUse();
131
- return runtime.exec(code, childContext, code, context.module.filepath);
131
+ if(name.onUse) name.onUse();
132
+ const r = runtime.exec(code, childContext, code, context.module.filepath);
133
+ if(name.onAfterUse) name.onAfterUse();
134
+ return r;
132
135
  } else if(name instanceof Usage) {
133
136
  const v = name.trigger(...params) || true;
134
137
  if(name.save !== false) context.__using__[name.name] = v;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@makano/rew",
3
- "version": "1.2.83",
3
+ "version": "1.2.85",
4
4
  "description": "A simple coffescript runtime and app manager",
5
5
  "main": "main.js",
6
6
  "directories": {