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