@makano/rew 1.2.82 → 1.2.84

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,4 @@
1
1
  Function.prototype.wait = function(...args) {
2
2
  return wait(this, ...args);
3
- };
3
+ };
4
+ Function.prototype.globe = () => global
@@ -34,6 +34,19 @@ module.exports.Usage = class Usage {
34
34
  return new Usage.Group(group, {});
35
35
  }
36
36
 
37
+ /**
38
+ *
39
+ * @param {...Usage} usages
40
+ * @returns {any[]}
41
+ */
42
+ merge(...usages){
43
+ return new Usage(usages.map(u => u.name).join('-'), (...args) => {
44
+ return usages.map(u => {
45
+ return u.trigger(...args)
46
+ });
47
+ })
48
+ }
49
+
37
50
  static Group = class UsageGroup {
38
51
  g = []
39
52
  constructor(g, props = {}){
@@ -51,24 +64,26 @@ module.exports.Usage = class Usage {
51
64
 
52
65
  class Namespace extends module.exports.Usage {
53
66
  namespace = {};
54
- constructor(ns, cb){
67
+ constructor(ns, cb, parent){
55
68
  super('namespace');
56
69
  if(ns instanceof Namespace.Group){
57
70
  if(ns.onUse) this.onUse = ns.onUse;
71
+ if(ns.parent) parent = ns.parent;
58
72
  cb = ns.g[1]
59
73
  ns = ns.g[0]
60
74
  }
61
75
  this.save = false;
62
76
  this.trigger = cb;
63
77
  this.namespace = ns;
78
+ this.parent = parent;
64
79
  }
65
80
 
66
81
  static Group = class NamespaceGroup extends module.exports.Usage.Group {}
67
82
  }
68
83
  module.exports.Namespace = Namespace;
69
84
 
70
- module.exports.namespace = (namespace, cb) => {
71
- return new Namespace(namespace, cb);
85
+ module.exports.namespace = (namespace, cb, parent) => {
86
+ return new Namespace(namespace, cb, parent);
72
87
  }
73
88
 
74
89
  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
 
@@ -419,7 +420,7 @@ const cpl = (module.exports.compile = function (file, options = {}) {
419
420
 
420
421
  const babelify = (code, options) => babel.transformSync(code, {
421
422
  presets: [
422
- ...(doJSX ? [[babelReact, { pragmaFrag: options.jsxPragmaFrag || execOptions.jsxPragmaFrag, pragma: options.jsxPragma || execOptions.jsxPragma }]] : [])
423
+ ...(doJSX ? [[babelReact, { throwIfNamespace: false, pragmaFrag: options.jsxPragmaFrag || execOptions.jsxPragmaFrag, pragma: options.jsxPragma || execOptions.jsxPragma }]] : [])
423
424
  ],
424
425
  plugins: [
425
426
  ...(doDecorators ? [[require('@babel/plugin-proposal-decorators'), { version: '2023-05' }], [require('@babel/plugin-proposal-class-properties'), { loose: true }], [require('@babel/plugin-transform-class-static-block'), {}]] : [])
@@ -123,15 +123,17 @@ 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
131
  if(name.onUse) name.onUse();
131
- runtime.exec(code, childContext, code, context.module.filepath);
132
+ return runtime.exec(code, childContext, code, context.module.filepath);
132
133
  } else if(name instanceof Usage) {
133
134
  const v = name.trigger(...params) || true;
134
135
  if(name.save !== false) context.__using__[name.name] = v;
136
+ return v;
135
137
  } else {
136
138
  context.__using__[name] = params.length ? params.length > 1 ? [...params] : params : true;
137
139
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@makano/rew",
3
- "version": "1.2.82",
3
+ "version": "1.2.84",
4
4
  "description": "A simple coffescript runtime and app manager",
5
5
  "main": "main.js",
6
6
  "directories": {