@makano/rew 1.2.78 → 1.2.80

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,6 +2,7 @@ const { CONFIG_PATH } = require("../const/config_path");
2
2
  const path = require('path');
3
3
  const fs = require('fs');
4
4
  const conf = require("../pkgs/conf");
5
+ const { log } = require("./log");
5
6
 
6
7
  const binpath = path.join(conf({}).create('').root, '.bin');
7
8
  const logspath = path.join(conf({}).create('').root, '.logs');
@@ -7,6 +7,7 @@ const execOptions = {
7
7
  useImport: false,
8
8
  cwdAlias: '$',
9
9
  jsxPragma: '__using__.JSX.createElement',
10
+ jsxPragmaFrag: '__using__.JSX.Fragment',
10
11
  jsx: false,
11
12
  typescript: false,
12
13
  decorators: false,
@@ -1,9 +1,10 @@
1
1
 
2
2
 
3
3
 
4
+ const JSX_FRAGMENT_SYMBOL = Symbol('fragment');
4
5
  module.exports.USING_DEFAULT = {
5
6
  JSX: {
6
- param: (param) => ({ createElement: param }),
7
+ param: (param, fragment) => ({ createElement: param, Fragment: fragment || param(JSX_FRAGMENT_SYMBOL, { isFragment: true }), fragmentSymbol: JSX_FRAGMENT_SYMBOL }),
7
8
  use: (options) => options.jsx = true
8
9
  },
9
10
  TYPES: {
@@ -53,6 +54,7 @@ class Namespace extends module.exports.Usage {
53
54
  constructor(ns, cb){
54
55
  super('namespace');
55
56
  if(ns instanceof Namespace.Group){
57
+ if(ns.onUse) this.onUse = ns.onUse;
56
58
  cb = ns.g[1]
57
59
  ns = ns.g[0]
58
60
  }
@@ -20,6 +20,7 @@ function tokenizeCoffeeScript(code) {
20
20
 
21
21
  while (i < code.length) {
22
22
  const char = code[i];
23
+ const prevChar = code[i - 1];
23
24
  const nextChar = code[i + 1];
24
25
  const nextNextChar = code[i + 2];
25
26
 
@@ -56,7 +57,7 @@ function tokenizeCoffeeScript(code) {
56
57
  }
57
58
  string += char; // Include closing quote
58
59
  tokens.push({ type: 'STRING', value: string });
59
- } else if (char === '/' && nextChar !== ' ' && nextChar !== '/' && nextChar !== '*') {
60
+ } else if (char === '/' && nextChar !== ' ' && nextChar !== '/' && nextChar !== '*' && prevChar !== '<') {
60
61
  // Regular expression
61
62
  let regex = char;
62
63
  i++;
@@ -235,6 +236,9 @@ function compileRewStuff(content, options) {
235
236
  const { use } = USING_DEFAULT[next];
236
237
  use?.(options);
237
238
  nextToken.value = `"${nextToken.value}"`
239
+
240
+ const { token: nextNextToken } = gnextToken(i, 3, tokens) || {};
241
+ if(nextNextToken.value == "as") nextNextToken.value = ",";
238
242
  }
239
243
  }
240
244
 
@@ -350,6 +354,7 @@ function compileRewStuff(content, options) {
350
354
  // token.value = '```'+token.value.slice(3).slice(0, -3).replace(/\#\{/g, '${')+'```';
351
355
  // }
352
356
 
357
+ // process.stdout.write(token.value);
353
358
  result += token.value;
354
359
  if (hooks.length) {
355
360
  hooks.forEach((hook, ind) => {
@@ -372,27 +377,31 @@ function compileRewStuff(content, options) {
372
377
  }
373
378
  }
374
379
 
380
+ // console.log(result);
381
+
375
382
  return result;
376
383
  }
377
384
 
378
385
  const compileCivetStuff = (file, options) => {
386
+ const preCompileOptions = {
387
+ filename: file.path,
388
+ ...options
389
+ };
390
+ const prepared = compileRewStuff(file.content, preCompileOptions);
391
+
379
392
  const compileOptions = {
380
- ...options,
393
+ ...preCompileOptions,
381
394
  bare: true,
382
395
  filename: file.path,
383
396
  inlineMap: false,
384
397
  js: true
385
398
  };
386
399
 
387
- const prepared = compileRewStuff(file.content, {
388
- filename: file.path,
389
- ...options
390
- });
391
400
  let compiled = options.async ? compileCivet(prepared, compileOptions) : wait(compileCivet, prepared, compileOptions);
392
401
 
393
402
  return {
394
403
  compiled,
395
- options
404
+ options: preCompileOptions
396
405
  };
397
406
  }
398
407
 
@@ -410,7 +419,7 @@ const cpl = (module.exports.compile = function (file, options = {}) {
410
419
 
411
420
  const babelify = (code, options) => babel.transformSync(code, {
412
421
  presets: [
413
- ...(doJSX ? [[babelReact, { pragma: options.jsxPragma || execOptions.jsxPragma }]] : [])
422
+ ...(doJSX ? [[babelReact, { pragmaFrag: options.jsxPragmaFrag || execOptions.jsxPragmaFrag, pragma: options.jsxPragma || execOptions.jsxPragma }]] : [])
414
423
  ],
415
424
  plugins: [
416
425
  ...(doDecorators ? [[require('@babel/plugin-proposal-decorators'), { version: '2023-05' }], [require('@babel/plugin-proposal-class-properties'), { loose: true }], [require('@babel/plugin-transform-class-static-block'), {}]] : [])
@@ -21,6 +21,7 @@ module.exports.prepareContext = function (
21
21
  runPath = () => {},
22
22
  ) {
23
23
  if (mainFile == "") mainFile = filepath;
24
+ /** @type {Record<string, any>} */
24
25
  let context = {
25
26
  module: {
26
27
  exports: null,
@@ -126,6 +127,7 @@ module.exports.prepareContext = function (
126
127
  childContext.currentNamespace = name.namespace;
127
128
  childContext.parentNamespace = context;
128
129
  const code = `(${trigger.toString()})()`;
130
+ if(name.onUse) name.onUse();
129
131
  runtime.exec(code, childContext, code, context.module.filepath);
130
132
  } else if(name instanceof Usage) {
131
133
  const v = name.trigger(...params) || true;
@@ -102,6 +102,11 @@ function createTextNode(text) {
102
102
  class ElementTypeNode extends nodeType('element') { };
103
103
  class ElementNode extends node(ElementTypeNode) { };
104
104
  function createElement(type, props, ...children) {
105
+
106
+ if(typeof type == "symbol" && props.isFragment){
107
+ return 'div';
108
+ }
109
+
105
110
  const flattenChildren = (childrenArray) =>
106
111
  childrenArray.flatMap(child => Array.isArray(child) ? flattenChildren(child) : child).map(child => {
107
112
  if (typeof child !== 'object') return createTextNode(child.toString());
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@makano/rew",
3
- "version": "1.2.78",
3
+ "version": "1.2.80",
4
4
  "description": "A simple coffescript runtime and app manager",
5
5
  "main": "main.js",
6
6
  "directories": {