@makano/rew 1.2.61 → 1.2.63

Sign up to get free protection for your applications and to get access to all the features.
@@ -11,72 +11,86 @@ const { wait } = require('../functions/wait');
11
11
  const { REW_FILE_TYPE } = require('../const/ext');
12
12
  const { USING_DEFAULT } = require('../const/usage');
13
13
 
14
+
15
+
14
16
  function tokenizeCoffeeScript(code) {
15
- const tokens = [];
16
- let currentToken = '';
17
-
18
- for (let i = 0; i < code.length; i++) {
19
- const char = code[i];
20
- const nextChar = code[i + 1];
21
-
22
- if (char === '#') {
23
- // Comment
24
- tokens.push({
25
- type: 'COMMENT',
26
- value: char + code.substring(i + 1).split('\n')[0] + '\n',
27
- });
28
- const ind = code.indexOf('\n', i);
29
- i = ind < 0 ? code.length-1 : ind;
30
- } else if (char === '"' || char === "'") {
31
- // String
32
- let string = char;
33
- let escaped = false;
34
- i++;
35
- while (i < code.length && (code[i] !== char || escaped)) {
36
- string += code[i];
37
- if (code[i] === '\\' && !escaped) {
38
- escaped = true;
39
- } else {
40
- escaped = false;
41
- }
42
- i++;
43
- }
44
- string += char; // Include closing quote
45
- tokens.push({ type: 'STRING', value: string });
46
- } else if (char === '/' && (nextChar === '/' || nextChar === '*')) {
47
- // Regular expression
48
- let regex = char;
49
- i++;
50
- while (i < code.length && (code[i] !== '/' || regex.endsWith('\\'))) {
51
- regex += code[i];
52
- i++;
53
- }
54
- regex += '/';
55
- tokens.push({ type: 'REGEX', value: regex });
56
- } else if (/\s/.test(char)) {
57
- // Whitespace
58
- if (tokens[tokens.length - 1]?.type == 'WHITESPACE' && tokens[tokens.length - 1].value[0] == char) {
59
- tokens[tokens.length - 1].value += char;
60
- } else {
61
- tokens.push({ type: 'WHITESPACE', value: char });
62
- }
63
- } else if (/[a-zA-Z\._$]/.test(char)) {
64
- // Identifier
65
- let identifier = char;
66
- i++;
67
- while (i < code.length && /[a-zA-Z0-9\._$]/.test(code[i])) {
68
- identifier += code[i];
69
- i++;
70
- }
71
- tokens.push({ type: 'IDENTIFIER', value: identifier });
72
- i--; // Move back one character to recheck
73
- } else {
74
- // Other characters
75
- tokens.push({ type: 'OTHER', value: char });
76
- }
77
- }
17
+ const tokens = [];
18
+ let currentToken = '';
19
+ let i = 0;
20
+
21
+ while (i < code.length) {
22
+ const char = code[i];
23
+ const nextChar = code[i + 1];
24
+ const nextNextChar = code[i + 2];
25
+
26
+ if (char === '#') {
27
+ // Comment
28
+ const commentEnd = code.indexOf('\n', i);
29
+ const comment = code.substring(i, commentEnd < 0 ? code.length : commentEnd + 1);
30
+ tokens.push({ type: 'COMMENT', value: comment });
31
+ i += comment.length - 1;
32
+ } else if (char === '"' && nextChar === '"' && nextNextChar === '"') {
33
+ // Triple-quoted string
34
+ let string = '"""';
35
+ i += 3;
36
+ while (i < code.length && !(code[i] === '"' && code[i + 1] === '"' && code[i + 2] === '"')) {
37
+ string += code[i];
38
+ i++;
39
+ }
40
+ string += '"""'; // Include closing triple quotes
41
+ tokens.push({ type: 'TRIPLE_STRING', value: string });
42
+ i += 2; // Skip past the closing triple quotes
43
+ } else if (char === '"' || char === "'") {
44
+ // Single or double-quoted string
45
+ let string = char;
46
+ let escaped = false;
47
+ i++;
48
+ while (i < code.length && (code[i] !== char || escaped)) {
49
+ string += code[i];
50
+ if (code[i] === '\\' && !escaped) {
51
+ escaped = true;
52
+ } else {
53
+ escaped = false;
54
+ }
55
+ i++;
56
+ }
57
+ string += char; // Include closing quote
58
+ tokens.push({ type: 'STRING', value: string });
59
+ } else if (char === '/' && nextChar !== ' ' && nextChar !== '/' && nextChar !== '*') {
60
+ // Regular expression
61
+ let regex = char;
62
+ i++;
63
+ while (i < code.length && (code[i] !== '/' || regex.endsWith('\\'))) {
64
+ regex += code[i];
65
+ i++;
66
+ }
67
+ regex += '/';
68
+ tokens.push({ type: 'REGEX', value: regex });
69
+ } else if (/\s/.test(char)) {
70
+ // Whitespace
71
+ if (tokens[tokens.length - 1]?.type === 'WHITESPACE') {
72
+ tokens[tokens.length - 1].value += char;
73
+ } else {
74
+ tokens.push({ type: 'WHITESPACE', value: char });
75
+ }
76
+ } else if (/[a-zA-Z_$]/.test(char)) {
77
+ // Identifier
78
+ let identifier = char;
79
+ i++;
80
+ while (i < code.length && /[a-zA-Z0-9_$]/.test(code[i])) {
81
+ identifier += code[i];
82
+ i++;
83
+ }
84
+ tokens.push({ type: 'IDENTIFIER', value: identifier });
85
+ i--; // Move back one character to recheck
86
+ } else {
87
+ // Other characters
88
+ tokens.push({ type: 'OTHER', value: char });
89
+ }
90
+ i++;
91
+ }
78
92
 
79
- return tokens;
93
+ return tokens;
80
94
  }
81
95
 
82
96
  const ValueIfy = (val) => {
@@ -255,6 +269,10 @@ function compileRewStuff(content, options) {
255
269
  });
256
270
  }
257
271
 
272
+ // if(token.type === 'TRIPLE_STRING'){
273
+ // token.value = '```'+token.value.slice(3).slice(0, -3).replace(/\#\{/g, '${')+'```';
274
+ // }
275
+
258
276
  result += token.value;
259
277
  if (hooks.length) {
260
278
  hooks.forEach((hook, ind) => {
@@ -452,7 +452,7 @@ module.exports = (context, importOptions) => {
452
452
  return new State(value);
453
453
  }
454
454
  invokeState(states, callback){
455
- const statesMapped = states.map(i => i instanceof State ? `getState('${i.id}')` : JSON.stringify(i));
455
+ const statesMapped = states.map(i => i instanceof State ? `getState('${i.id}')` : (typeof i == "function" ? i.toString() : JSON.stringify(i)));
456
456
  return `((${callback})(event, ...[${statesMapped}]))`;
457
457
  }
458
458
  async bundle(filepath, options = {}) {
@@ -487,7 +487,7 @@ module.exports = (context, importOptions) => {
487
487
  },
488
488
  async transform(code, id) {
489
489
  if (id.endsWith(REW_FILE_TYPE.EXTENSION) || id.endsWith('.coffee')) {
490
- const result = compile({ content: code, path: filepath }, { jsx: true, async: true, keepImports: true });
490
+ const result = compile({ content: code, path: filepath }, { type: id.endsWith('.coffee') ? "coffee" : undefined, jsx: true, async: true, keepImports: true });
491
491
  return {
492
492
  code: await result,
493
493
  map: null,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@makano/rew",
3
- "version": "1.2.61",
3
+ "version": "1.2.63",
4
4
  "description": "A simple coffescript runtime and app manager",
5
5
  "main": "main.js",
6
6
  "directories": {