@makano/rew 1.1.8 → 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.
- 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 +243 -202
- package/lib/rew/cli/log.js +31 -32
- package/lib/rew/cli/run.js +10 -12
- package/lib/rew/cli/utils.js +248 -176
- package/lib/rew/const/config_path.js +2 -3
- 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 +116 -110
- 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/findAppInfo.js +14 -14
- package/lib/rew/misc/findAppPath.js +16 -16
- package/lib/rew/misc/seededid.js +9 -11
- package/lib/rew/models/enum.js +12 -12
- package/lib/rew/models/struct.js +30 -32
- package/lib/rew/modules/compiler.js +228 -177
- package/lib/rew/modules/context.js +33 -21
- 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 +80 -80
- 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 +391 -345
- package/lib/rew/pkgs/threads.js +57 -53
- package/lib/rew/pkgs/ui.js +148 -136
- package/package.json +1 -1
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
|
};
|
@@ -1,16 +1,16 @@
|
|
1
|
-
const jsYaml = require(
|
2
|
-
const { findAppPath } = require(
|
1
|
+
const jsYaml = require('js-yaml');
|
2
|
+
const { findAppPath } = require('./findAppPath');
|
3
3
|
const path = require('path');
|
4
|
-
const { readFileSync } = require(
|
4
|
+
const { readFileSync } = require('fs');
|
5
5
|
|
6
|
-
module.exports.findAppInfo = function(filepath){
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
}
|
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
|
+
};
|
@@ -1,21 +1,21 @@
|
|
1
|
-
const path = require('path');
|
2
|
-
const fs = require('fs');
|
1
|
+
const path = require('path'); // Import the 'path' module
|
2
|
+
const fs = require('fs'); // Import the 'path' module
|
3
3
|
|
4
4
|
module.exports.findAppPath = (currentDir = __dirname) => {
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
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
10
|
|
11
|
-
|
12
|
-
|
11
|
+
// If not found, move up a directory level
|
12
|
+
const parentDir = path.dirname(currentDir);
|
13
13
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
14
|
+
// Check if we reached the root directory
|
15
|
+
if (parentDir === currentDir) {
|
16
|
+
return null; // Not found
|
17
|
+
}
|
18
18
|
|
19
|
-
|
20
|
-
|
21
|
-
};
|
19
|
+
// Recursively call the function on the parent directory
|
20
|
+
return module.exports.findAppPath(parentDir);
|
21
|
+
};
|
package/lib/rew/misc/seededid.js
CHANGED
@@ -1,15 +1,13 @@
|
|
1
|
-
|
2
|
-
|
3
1
|
module.exports.seededID = function (seed) {
|
4
|
-
|
2
|
+
const charCodes = seed.split('').map((char) => char.charCodeAt(0));
|
5
3
|
|
6
|
-
|
7
|
-
|
4
|
+
let result = '';
|
5
|
+
let sum = 0;
|
8
6
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
7
|
+
for (let i = 0; i < charCodes.length; i++) {
|
8
|
+
sum += charCodes[i];
|
9
|
+
result += String.fromCharCode(((charCodes[i] + sum) % 26) + 97);
|
10
|
+
}
|
13
11
|
|
14
|
-
|
15
|
-
}
|
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,257 @@
|
|
1
|
-
const { compile } = require(
|
2
|
-
const { execOptions } = require(
|
3
|
-
const { getFile } = require(
|
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
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
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
|
-
|
71
|
+
return tokens;
|
71
72
|
}
|
72
73
|
|
73
|
-
const
|
74
|
-
|
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
|
-
|
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
|
-
|
83
|
-
|
104
|
+
const tokens = tokenizeCoffeeScript(content);
|
105
|
+
let result = '';
|
84
106
|
|
85
|
-
|
107
|
+
let hooks = [];
|
86
108
|
|
87
|
-
|
88
|
-
|
89
|
-
|
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
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
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
|
-
|
121
|
+
if (token.type === 'COMMENT' && token.value.slice(1).trim() === '@jsx') {
|
122
|
+
options.jsx = true;
|
123
|
+
}
|
149
124
|
|
150
|
-
|
151
|
-
|
152
|
-
|
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
|
-
|
143
|
+
if (token.type === 'IDENTIFIER' && token.value === 'import') {
|
144
|
+
// console.log(nextToken.type);
|
145
|
+
let ind = i + n + 2;
|
181
146
|
|
182
|
-
|
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
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
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
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
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
|
};
|