@makano/rew 1.1.7 → 1.1.9

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.
Files changed (74) hide show
  1. package/README.md +1 -1
  2. package/bin/ui +0 -0
  3. package/build.sh +3 -1
  4. package/lib/coffeescript/browser.js +144 -139
  5. package/lib/coffeescript/cake.js +132 -133
  6. package/lib/coffeescript/coffeescript.js +437 -381
  7. package/lib/coffeescript/command.js +806 -724
  8. package/lib/coffeescript/grammar.js +1908 -2474
  9. package/lib/coffeescript/helpers.js +509 -473
  10. package/lib/coffeescript/index.js +228 -215
  11. package/lib/coffeescript/lexer.js +2282 -1909
  12. package/lib/coffeescript/nodes.js +9782 -9202
  13. package/lib/coffeescript/optparse.js +255 -227
  14. package/lib/coffeescript/parser.js +20305 -1265
  15. package/lib/coffeescript/register.js +107 -87
  16. package/lib/coffeescript/repl.js +307 -284
  17. package/lib/coffeescript/rewriter.js +1389 -1079
  18. package/lib/coffeescript/scope.js +176 -172
  19. package/lib/coffeescript/sourcemap.js +242 -227
  20. package/lib/rew/cli/cli.js +245 -186
  21. package/lib/rew/cli/log.js +31 -32
  22. package/lib/rew/cli/run.js +10 -12
  23. package/lib/rew/cli/utils.js +248 -175
  24. package/lib/rew/const/config_path.js +4 -0
  25. package/lib/rew/const/default.js +38 -35
  26. package/lib/rew/const/files.js +9 -9
  27. package/lib/rew/const/opt.js +8 -8
  28. package/lib/rew/css/theme.css +2 -2
  29. package/lib/rew/functions/core.js +55 -57
  30. package/lib/rew/functions/curl.js +23 -0
  31. package/lib/rew/functions/emitter.js +52 -55
  32. package/lib/rew/functions/exec.js +25 -21
  33. package/lib/rew/functions/export.js +18 -20
  34. package/lib/rew/functions/fs.js +55 -54
  35. package/lib/rew/functions/future.js +29 -21
  36. package/lib/rew/functions/id.js +8 -9
  37. package/lib/rew/functions/import.js +104 -93
  38. package/lib/rew/functions/map.js +13 -16
  39. package/lib/rew/functions/match.js +35 -26
  40. package/lib/rew/functions/path.js +8 -8
  41. package/lib/rew/functions/require.js +32 -33
  42. package/lib/rew/functions/sleep.js +2 -2
  43. package/lib/rew/functions/stdout.js +20 -20
  44. package/lib/rew/functions/types.js +96 -95
  45. package/lib/rew/html/ui.html +12 -13
  46. package/lib/rew/html/ui.js +205 -168
  47. package/lib/rew/main.js +14 -14
  48. package/lib/rew/misc/findAppInfo.js +16 -0
  49. package/lib/rew/misc/findAppPath.js +21 -0
  50. package/lib/rew/misc/seededid.js +13 -0
  51. package/lib/rew/models/enum.js +12 -12
  52. package/lib/rew/models/struct.js +30 -32
  53. package/lib/rew/modules/compiler.js +228 -177
  54. package/lib/rew/modules/context.js +35 -22
  55. package/lib/rew/modules/fs.js +10 -10
  56. package/lib/rew/modules/runtime.js +17 -21
  57. package/lib/rew/modules/yaml.js +27 -30
  58. package/lib/rew/pkgs/conf.js +82 -75
  59. package/lib/rew/pkgs/data.js +12 -7
  60. package/lib/rew/pkgs/date.js +27 -28
  61. package/lib/rew/pkgs/env.js +6 -8
  62. package/lib/rew/pkgs/modules/data/bintree.js +52 -52
  63. package/lib/rew/pkgs/modules/data/doublylinked.js +85 -85
  64. package/lib/rew/pkgs/modules/data/linkedList.js +73 -73
  65. package/lib/rew/pkgs/modules/data/queue.js +19 -20
  66. package/lib/rew/pkgs/modules/data/stack.js +19 -19
  67. package/lib/rew/pkgs/modules/threads/worker.js +36 -26
  68. package/lib/rew/pkgs/modules/ui/classes.js +182 -178
  69. package/lib/rew/pkgs/pkgs.js +9 -10
  70. package/lib/rew/pkgs/rune.js +422 -0
  71. package/lib/rew/pkgs/threads.js +57 -53
  72. package/lib/rew/pkgs/ui.js +148 -136
  73. package/meson.build +13 -0
  74. package/package.json +9 -2
package/lib/rew/main.js CHANGED
@@ -1,17 +1,17 @@
1
- const { compileFile } = require("./modules/compiler");
2
- const { exec, runPath } = require("./modules/runtime");
3
- const fs = require("fs");
4
- const { imp } = require("./functions/import");
5
- const { FILES } = require("./const/files");
1
+ const { compileFile } = require('./modules/compiler');
2
+ const { exec, runPath } = require('./modules/runtime');
3
+ const fs = require('fs');
4
+ const { imp } = require('./functions/import');
5
+ const { FILES } = require('./const/files');
6
6
 
7
7
  module.exports.run = function (filepath, options = {}, custom_context = {}) {
8
- FILES.forEach(file => {
9
- if(fs.existsSync(file.path)) return;
10
- if(file.content){
11
- fs.writeFileSync(file.path, file.content);
12
- } else {
13
- fs.mkdirSync(file.path, { recursive: true });
14
- }
15
- });
16
- return runPath(filepath, options, custom_context);
8
+ FILES.forEach((file) => {
9
+ if (fs.existsSync(file.path)) return;
10
+ if (file.content) {
11
+ fs.writeFileSync(file.path, file.content);
12
+ } else {
13
+ fs.mkdirSync(file.path, { recursive: true });
14
+ }
15
+ });
16
+ return runPath(filepath, options, custom_context);
17
17
  };
@@ -0,0 +1,16 @@
1
+ const jsYaml = require('js-yaml');
2
+ const { findAppPath } = require('./findAppPath');
3
+ const path = require('path');
4
+ const { readFileSync } = require('fs');
5
+
6
+ module.exports.findAppInfo = function (filepath) {
7
+ const appPath = findAppPath(path.dirname(filepath));
8
+ if (appPath) {
9
+ const config = jsYaml.load(readFileSync(path.join(appPath, 'app.yaml')));
10
+ return {
11
+ path: appPath,
12
+ config,
13
+ };
14
+ }
15
+ return null;
16
+ };
@@ -0,0 +1,21 @@
1
+ const path = require('path'); // Import the 'path' module
2
+ const fs = require('fs'); // Import the 'path' module
3
+
4
+ module.exports.findAppPath = (currentDir = __dirname) => {
5
+ // Check if app.yaml exists in the current directory
6
+ const appYamlPath = path.join(currentDir, 'app.yaml');
7
+ if (fs.existsSync(appYamlPath)) {
8
+ return currentDir;
9
+ }
10
+
11
+ // If not found, move up a directory level
12
+ const parentDir = path.dirname(currentDir);
13
+
14
+ // Check if we reached the root directory
15
+ if (parentDir === currentDir) {
16
+ return null; // Not found
17
+ }
18
+
19
+ // Recursively call the function on the parent directory
20
+ return module.exports.findAppPath(parentDir);
21
+ };
@@ -0,0 +1,13 @@
1
+ module.exports.seededID = function (seed) {
2
+ const charCodes = seed.split('').map((char) => char.charCodeAt(0));
3
+
4
+ let result = '';
5
+ let sum = 0;
6
+
7
+ for (let i = 0; i < charCodes.length; i++) {
8
+ sum += charCodes[i];
9
+ result += String.fromCharCode(((charCodes[i] + sum) % 26) + 97);
10
+ }
11
+
12
+ return result.slice(0, 12);
13
+ };
@@ -1,14 +1,14 @@
1
1
  module.exports.cenum = function cenum(values) {
2
- var enumObj, i, len, value;
3
- // Create an object to hold the enum values
4
- enumObj = {};
5
- for (i = 0, len = values.length; i < len; i++) {
6
- value = values[i];
7
- enumObj[value] = value;
8
- }
9
- // Add a method to check if a value is a valid enum value
10
- enumObj.isValid = function (val) {
11
- return indexOf.call(enumObj, val) >= 0;
12
- };
13
- return enumObj;
2
+ var enumObj, i, len, value;
3
+ // Create an object to hold the enum values
4
+ enumObj = {};
5
+ for (i = 0, len = values.length; i < len; i++) {
6
+ value = values[i];
7
+ enumObj[value] = value;
8
+ }
9
+ // Add a method to check if a value is a valid enum value
10
+ enumObj.isValid = function (val) {
11
+ return indexOf.call(enumObj, val) >= 0;
12
+ };
13
+ return enumObj;
14
14
  };
@@ -1,41 +1,39 @@
1
- const { generateRandomID } = require("../functions/id");
1
+ const { generateRandomID } = require('../functions/id');
2
2
 
3
3
  module.exports.struct = function struct(template) {
4
- var key, types, value;
4
+ var key, types, value;
5
5
 
6
- types = {};
7
- for (key in template) {
8
- value = template[key];
9
- types[key] = typeof value;
10
- }
6
+ types = {};
7
+ for (key in template) {
8
+ value = template[key];
9
+ types[key] = typeof value;
10
+ }
11
11
 
12
- const fun = function (properties = {}) {
13
- var defaultValue, instance;
14
- instance = {};
15
- for (key in template) {
16
- defaultValue = template[key];
17
- if (key in properties) {
18
- value = properties[key];
19
- if (defaultValue != "!any" && typeof value !== types[key]) {
20
- throw new Error(
21
- `Type error: Expected ${types[key]} for ${key}, got ${typeof value}`,
22
- );
23
- }
24
- instance[key] = value;
25
- } else {
26
- instance[key] = defaultValue == "!any" ? null : defaultValue;
27
- }
28
- }
29
- instance.__proto__ = { '@instance': fun };
30
- return instance;
31
- };
12
+ const fun = function (properties = {}) {
13
+ var defaultValue, instance;
14
+ instance = {};
15
+ for (key in template) {
16
+ defaultValue = template[key];
17
+ if (key in properties) {
18
+ value = properties[key];
19
+ if (defaultValue != '!any' && typeof value !== types[key]) {
20
+ throw new Error(`Type error: Expected ${types[key]} for ${key}, got ${typeof value}`);
21
+ }
22
+ instance[key] = value;
23
+ } else {
24
+ instance[key] = defaultValue == '!any' ? null : defaultValue;
25
+ }
26
+ }
27
+ instance.__proto__ = { '@instance': fun };
28
+ return instance;
29
+ };
32
30
 
33
- return fun;
31
+ return fun;
34
32
  };
35
33
 
36
34
  module.exports.struct.inherits = function (struct, template) {
37
- return module.exports.struct({
38
- ...struct(),
39
- ...template,
40
- });
35
+ return module.exports.struct({
36
+ ...struct(),
37
+ ...template,
38
+ });
41
39
  };
@@ -1,206 +1,257 @@
1
- const { compile } = require("../../coffeescript/coffeescript");
2
- const { execOptions } = require("../const/opt");
3
- const { getFile } = require("./fs");
1
+ const { compile } = require('../../coffeescript/coffeescript');
2
+ const { execOptions } = require('../const/opt');
3
+ const { getFile } = require('./fs');
4
4
  const babel = require('@babel/core');
5
5
  const babelReact = require('@babel/preset-react');
6
6
 
7
7
  function tokenizeCoffeeScript(code) {
8
- const tokens = [];
9
- let currentToken = '';
10
-
11
- for (let i = 0; i < code.length; i++) {
12
- const char = code[i];
13
- const nextChar = code[i + 1];
14
-
15
- if (char === '#') {
16
- // Comment
17
- tokens.push({ type: 'COMMENT', value: char + code.substring(i + 1).split('\n')[0]+'\n' });
18
- i = code.indexOf('\n', i);
19
- } else if (char === '"' || char === "'") {
20
- // String
21
- let string = char;
22
- let escaped = false;
23
- i++;
24
- while (i < code.length && (code[i] !== char || escaped)) {
25
- string += code[i];
26
- if (code[i] === '\\' && !escaped) {
27
- escaped = true;
28
- } else {
29
- escaped = false;
30
- }
31
- i++;
32
- }
33
- string += char; // Include closing quote
34
- tokens.push({ type: 'STRING', value: string });
35
- } else if (char === '/' && (nextChar === '/' || nextChar === '*')) {
36
- // Regular expression
37
- let regex = char;
38
- i++;
39
- while (i < code.length && (code[i] !== '/' || regex.endsWith('\\'))) {
40
- regex += code[i];
41
- i++;
42
- }
43
- regex += '/';
44
- tokens.push({ type: 'REGEX', value: regex });
45
- } else if (/\s/.test(char)) {
46
- // Whitespace
47
- if(tokens[tokens.length-1]?.type == 'WHITESPACE'
48
- && tokens[tokens.length-1].value[0] == char
49
- ){
50
- tokens[tokens.length-1].value += char;
51
- } else {
52
- tokens.push({ type: 'WHITESPACE', value: char });
53
- }
54
- } else if (/[a-zA-Z_$]/.test(char)) {
55
- // Identifier
56
- let identifier = char;
57
- i++;
58
- while (i < code.length && /[a-zA-Z0-9_$]/.test(code[i])) {
59
- identifier += code[i];
60
- i++;
61
- }
62
- tokens.push({ type: 'IDENTIFIER', value: identifier });
63
- i--; // Move back one character to recheck
64
- } else {
65
- // Other characters
66
- tokens.push({ type: 'OTHER', value: char });
67
- }
68
- }
8
+ const tokens = [];
9
+ let currentToken = '';
10
+
11
+ for (let i = 0; i < code.length; i++) {
12
+ const char = code[i];
13
+ const nextChar = code[i + 1];
14
+
15
+ if (char === '#') {
16
+ // Comment
17
+ tokens.push({
18
+ type: 'COMMENT',
19
+ value: char + code.substring(i + 1).split('\n')[0] + '\n',
20
+ });
21
+ i = code.indexOf('\n', i);
22
+ } else if (char === '"' || char === "'") {
23
+ // String
24
+ let string = char;
25
+ let escaped = false;
26
+ i++;
27
+ while (i < code.length && (code[i] !== char || escaped)) {
28
+ string += code[i];
29
+ if (code[i] === '\\' && !escaped) {
30
+ escaped = true;
31
+ } else {
32
+ escaped = false;
33
+ }
34
+ i++;
35
+ }
36
+ string += char; // Include closing quote
37
+ tokens.push({ type: 'STRING', value: string });
38
+ } else if (char === '/' && (nextChar === '/' || nextChar === '*')) {
39
+ // Regular expression
40
+ let regex = char;
41
+ i++;
42
+ while (i < code.length && (code[i] !== '/' || regex.endsWith('\\'))) {
43
+ regex += code[i];
44
+ i++;
45
+ }
46
+ regex += '/';
47
+ tokens.push({ type: 'REGEX', value: regex });
48
+ } else if (/\s/.test(char)) {
49
+ // Whitespace
50
+ if (tokens[tokens.length - 1]?.type == 'WHITESPACE' && tokens[tokens.length - 1].value[0] == char) {
51
+ tokens[tokens.length - 1].value += char;
52
+ } else {
53
+ tokens.push({ type: 'WHITESPACE', value: char });
54
+ }
55
+ } else if (/[a-zA-Z_$]/.test(char)) {
56
+ // Identifier
57
+ let identifier = char;
58
+ i++;
59
+ while (i < code.length && /[a-zA-Z0-9_$]/.test(code[i])) {
60
+ identifier += code[i];
61
+ i++;
62
+ }
63
+ tokens.push({ type: 'IDENTIFIER', value: identifier });
64
+ i--; // Move back one character to recheck
65
+ } else {
66
+ // Other characters
67
+ tokens.push({ type: 'OTHER', value: char });
68
+ }
69
+ }
69
70
 
70
- return tokens;
71
+ return tokens;
71
72
  }
72
73
 
73
- const gnextToken = (i, n, tokens) => {
74
- return tokens[i + n] ? tokens[i + n].type == 'WHITESPACE' ? gnextToken(i, n + 1, tokens) : { nextToken: tokens[i + n], n } : null;
74
+ const ValueIfy = (val) => {
75
+ if(!isNaN(parseFloat(val)) || !isNaN(parseInt(val))){
76
+ return isNaN(parseInt(val)) ? parseFloat(val) : parseInt(val);
77
+ } if(val == 'true' || val == 'false') {
78
+ return val == 'true' ? true : false;
79
+ } else {
80
+ return JSON.stringify(val);
81
+ }
75
82
  }
76
83
 
84
+ const gnextToken = (i, n, tokens) => {
85
+ return tokens[i + n] ? (tokens[i + n].type == 'WHITESPACE' ? gnextToken(i, n + 1, tokens) : { token: tokens[i + n], n }) : null;
86
+ };
87
+
77
88
  const fnextToken = (i, tokens, type, value) => {
78
- return tokens.map((t, ind) => { t.ti = ind; return t }).slice(i, tokens.length - 1).map((t, ind) => { t.ri = ind; t.index = ind - i; return t }).find(t => t.type == type && (value ? t.value == value : true));
79
- }
89
+ return tokens
90
+ .map((t, ind) => {
91
+ t.ti = ind;
92
+ return t;
93
+ })
94
+ .slice(i, tokens.length - 1)
95
+ .map((t, ind) => {
96
+ t.ri = ind;
97
+ t.index = ind - i;
98
+ return t;
99
+ })
100
+ .find((t) => t.type == type && (value ? t.value == value : true));
101
+ };
80
102
 
81
103
  function compileRewStuff(content, options) {
82
- const tokens = tokenizeCoffeeScript(content);
83
- let result = '';
104
+ const tokens = tokenizeCoffeeScript(content);
105
+ let result = '';
84
106
 
85
- let hooks = [];
107
+ let hooks = [];
86
108
 
87
- for (let i = 0; i < tokens.length; i++) {
88
- const token = tokens[i];
89
- let { nextToken, n } = gnextToken(i, 1, tokens) || {};
109
+ for (let i = 0; i < tokens.length; i++) {
110
+ const token = tokens[i];
111
+ let { token: nextToken, n } = gnextToken(i, 1, tokens) || {};
90
112
 
91
- if (token.type === 'IDENTIFIER' && token.value === 'opt') {
92
- const { nextToken: nextNextToken } = gnextToken(i, 2, tokens) || {};
93
- if(nextNextToken && nextNextToken.value == 'jsxPragma'){
94
- const { nextToken: nextLastToken } = gnextToken(i, 5, tokens) || {};
95
- execOptions.jsxPragma = nextLastToken.value.slice(1).slice(0, -1);
96
- }
97
- }
98
-
99
- if (token.type === 'COMMENT' && token.value.slice(1).trim() === '@jsx') {
100
- options.jsx = true;
101
- }
102
-
103
- if (token.type === 'IDENTIFIER' && token.value === 'import') {
104
- // console.log(nextToken.type);
105
- let ind = i + n + 2;
106
-
107
- let defaultName;
108
- if (nextToken.type === 'STRING') {
109
- result += `inc ${nextToken.value}`;
110
- i += n;
111
- } else if (nextToken.value === '{') {
112
- const closingBraceToken = fnextToken(ind, tokens, 'OTHER', '}');
113
- const nameToken = fnextToken(ind, tokens, 'STRING');
114
- if (closingBraceToken) {
115
- const exportsTokens = tokens.slice(ind, closingBraceToken.ti);
116
- const exports = exportsTokens.filter(t => t.type === 'IDENTIFIER').map(t => t.value).join(', ');
117
- result += `{ ${exports} } = inc ${nameToken.value}`;
118
- i = nameToken.ti;
119
- }
120
- } else if (nextToken.value === '*') {
121
- const asToken = fnextToken(ind, tokens, 'IDENTIFIER', 'as');
122
- const nameToken = fnextToken(asToken.ri, tokens, 'STRING');
123
- if (asToken) {
124
- const nextToken = fnextToken(asToken.ti + 1, tokens, 'IDENTIFIER');
125
- defaultName = nextToken.value;
126
- result += `${defaultName} = inc ${nameToken.value}`;
127
- i = ind + 6;
128
- }
129
- } else if(nextToken) {
130
- const nameToken = fnextToken(ind, tokens, 'STRING');
131
- defaultName = nextToken.value;
132
- let { nextToken: nextNextToken, n: n2 } = gnextToken(i + 2, 1, tokens) || {};
133
- if(nextNextToken?.type == 'OTHER' && nextNextToken?.value == ','){
134
- const closingBraceToken = fnextToken(ind, tokens, 'OTHER', '}');
135
- if(closingBraceToken){
136
- const exportsTokens = tokens.slice(ind, closingBraceToken.ti);
137
- const exports = exportsTokens.filter(t => t.type === 'IDENTIFIER').map(t => t.value).join(', ');
138
- result += `{ default: ${defaultName}, ${exports} } = inc ${nameToken?.value || ""}`;
139
- i = closingBraceToken.ti + 4;
140
- }
141
- } else {
142
- result += `{ default: ${defaultName} } = inc ${nameToken?.value || ""}`;
143
- i = ind + 2;
144
- }
145
-
146
- }
113
+ if (token.type === 'IDENTIFIER' && token.value === 'opt') {
114
+ const { token: nextNextToken } = gnextToken(i, 2, tokens) || {};
115
+ if (nextNextToken && nextNextToken.value == 'jsxPragma') {
116
+ const { token: nextLastToken } = gnextToken(i, 5, tokens) || {};
117
+ execOptions.jsxPragma = nextLastToken.value.slice(1).slice(0, -1);
118
+ }
119
+ }
147
120
 
148
- const nextLastToken = fnextToken(i, tokens, 'IDENTIFIER');
121
+ if (token.type === 'COMMENT' && token.value.slice(1).trim() === '@jsx') {
122
+ options.jsx = true;
123
+ }
149
124
 
150
- if(nextLastToken?.value == 'assert'){
151
- result += ', ';
152
- i += 3;
125
+ if (token.type === 'COMMENT' && token.value.slice(1).trim() === '@cls') {
126
+ options.cls = true;
127
+ }
128
+
129
+ if (options.cls && token.type === 'OTHER' && token.value === '-' && nextToken.value == '-' && tokens[i-1]?.type == 'WHITESPACE') {
130
+ // Argument case
131
+ let offset = 0, writenext = false;
132
+ const n = gnextToken(i, 2, tokens);
133
+ let v = gnextToken(i, 3, tokens);
134
+ if(v.token.type == 'IDENTIFIER' && v.token.value == '$'){
135
+ writenext = true;
153
136
  }
137
+ result += n.token.value + ': ' + (writenext ? '' : (v.token.value == ',' ? 'true, ' : v.token.type == "STRING" ? v.token.value : ValueIfy(v.token.value)));
154
138
 
139
+ i = offset + tokens.indexOf(v.token);
155
140
  continue;
156
- }
157
-
158
-
159
- if (token.type === 'IDENTIFIER' && token.value === 'pub' &&
160
- nextToken && nextToken.type === 'IDENTIFIER' &&
161
- nextToken.value && nextToken.value !== 'undefined') {
162
-
163
- hooks.push({
164
- index: i + 1,
165
- value: `"${nextToken.value}", `
166
- });
167
- }
168
-
169
- result += token.value;
170
- if (hooks.length) {
171
- hooks.forEach((hook, ind) => {
172
- if (i == hook.index) {
173
- result += hook.value;
174
- hooks.splice(ind, 1);
175
- }
176
- });
177
- }
178
- }
141
+ }
179
142
 
180
- // console.log(result)
143
+ if (token.type === 'IDENTIFIER' && token.value === 'import') {
144
+ // console.log(nextToken.type);
145
+ let ind = i + n + 2;
181
146
 
182
- return result;
183
- }
147
+ let defaultName;
148
+ if (nextToken.type === 'STRING') {
149
+ result += `inc ${nextToken.value}`;
150
+ i += n;
151
+ } else if (nextToken.value === '{') {
152
+ const closingBraceToken = fnextToken(ind, tokens, 'OTHER', '}');
153
+ const nameToken = fnextToken(ind, tokens, 'STRING');
154
+ if (closingBraceToken) {
155
+ const exportsTokens = tokens.slice(ind, closingBraceToken.ti);
156
+ const exports = exportsTokens
157
+ .filter((t) => t.type === 'IDENTIFIER')
158
+ .map((t) => t.value)
159
+ .join(', ');
160
+ result += `{ ${exports} } = inc ${nameToken.value}`;
161
+ i = nameToken.ti;
162
+ }
163
+ } else if (nextToken.value === '*') {
164
+ const asToken = fnextToken(ind, tokens, 'IDENTIFIER', 'as');
165
+ const nameToken = fnextToken(asToken.ri, tokens, 'STRING');
166
+ if (asToken) {
167
+ const nextToken = fnextToken(asToken.ti + 1, tokens, 'IDENTIFIER');
168
+ defaultName = nextToken.value;
169
+ result += `${defaultName} = inc ${nameToken.value}`;
170
+ i = ind + 6;
171
+ }
172
+ } else if (nextToken) {
173
+ const nameToken = fnextToken(ind, tokens, 'STRING');
174
+ defaultName = nextToken.value;
175
+ let { nextToken: nextNextToken, n: n2 } = gnextToken(i + 2, 1, tokens) || {};
176
+ if (nextNextToken?.type == 'OTHER' && nextNextToken?.value == ',') {
177
+ const closingBraceToken = fnextToken(ind, tokens, 'OTHER', '}');
178
+ if (closingBraceToken) {
179
+ const exportsTokens = tokens.slice(ind, closingBraceToken.ti);
180
+ const exports = exportsTokens
181
+ .filter((t) => t.type === 'IDENTIFIER')
182
+ .map((t) => t.value)
183
+ .join(', ');
184
+ result += `{ default: ${defaultName}, ${exports} } = inc ${nameToken?.value || ''}`;
185
+ i = closingBraceToken.ti + 4;
186
+ }
187
+ } else {
188
+ result += `{ default: ${defaultName} } = inc ${nameToken?.value || ''}`;
189
+ i = ind + 2;
190
+ }
191
+ }
192
+
193
+ const nextLastToken = fnextToken(i, tokens, 'IDENTIFIER');
194
+
195
+ if (nextLastToken?.value == 'assert') {
196
+ result += ', ';
197
+ i += 3;
198
+ }
184
199
 
200
+ continue;
201
+ }
202
+
203
+ if (
204
+ token.type === 'IDENTIFIER' &&
205
+ token.value === 'pub' &&
206
+ nextToken &&
207
+ nextToken.type === 'IDENTIFIER' &&
208
+ nextToken.value &&
209
+ nextToken.value !== 'undefined'
210
+ ) {
211
+ hooks.push({
212
+ index: i + 1,
213
+ value: `"${nextToken.value}", `,
214
+ });
215
+ }
216
+
217
+ result += token.value;
218
+ if (hooks.length) {
219
+ hooks.forEach((hook, ind) => {
220
+ if (i == hook.index) {
221
+ result += hook.value;
222
+ hooks.splice(ind, 1);
223
+ }
224
+ });
225
+ }
226
+ }
227
+
228
+ // console.log(result)
229
+
230
+ return result;
231
+ }
185
232
 
186
233
  const cpl = (module.exports.compile = function (file, options = {}) {
187
- let c = compile(compileRewStuff(file.content, options), { ...options, filename: file.path, bare: false, inlineMap: false });
188
- if(execOptions.jsx || options.jsx) {
189
- c = babel.transformSync(c, {
190
- presets: [[babelReact, { pragma: execOptions.jsxPragma }]],
191
- plugins: []
192
- }).code;
193
- }
194
- return c;
234
+ let c = compile(compileRewStuff(file.content, options), {
235
+ ...options,
236
+ filename: file.path,
237
+ bare: false,
238
+ inlineMap: false,
239
+ });
240
+ if (execOptions.jsx || options.jsx) {
241
+ c = babel.transformSync(c, {
242
+ presets: [[babelReact, { pragma: execOptions.jsxPragma }]],
243
+ plugins: [],
244
+ }).code;
245
+ }
246
+ return c;
195
247
  });
196
248
 
197
249
  module.exports.compileFile = function (filepath, options = {}) {
198
- const f = getFile(filepath);
199
- const compiled_code =
200
- options.compile == false ? f.content : cpl(f, { ...options });
201
-
202
- return {
203
- compiled_code,
204
- file: f,
205
- };
250
+ const f = getFile(filepath);
251
+ const compiled_code = options.compile == false ? f.content : cpl(f, { ...options });
252
+
253
+ return {
254
+ compiled_code,
255
+ file: f,
256
+ };
206
257
  };