@makano/rew 1.2.93 → 1.2.95
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.
@@ -0,0 +1,16 @@
|
|
1
|
+
const { compile } = require("../modules/compiler")
|
2
|
+
|
3
|
+
const _compilePart = (code, filepath) => compile(
|
4
|
+
{
|
5
|
+
path: filepath,
|
6
|
+
content: code
|
7
|
+
},
|
8
|
+
{}
|
9
|
+
);
|
10
|
+
|
11
|
+
module.exports = (filepath) => ({
|
12
|
+
_compilePart: (code) => {
|
13
|
+
return _compilePart(code, filepath);
|
14
|
+
},
|
15
|
+
_call: (fn, ...args) => args.length ? fn.call(...args) : fn()
|
16
|
+
})
|
@@ -115,6 +115,13 @@ const ValueIfy = (val) => {
|
|
115
115
|
}
|
116
116
|
}
|
117
117
|
|
118
|
+
function insertTokenAt(array, index, value) {
|
119
|
+
if (index < 0 || index > array.length) {
|
120
|
+
throw new RangeError('Index out of bounds');
|
121
|
+
}
|
122
|
+
array.splice(index, 0, value);
|
123
|
+
}
|
124
|
+
|
118
125
|
const gnextToken = (i, n, tokens) => {
|
119
126
|
return tokens[i + n] ? (tokens[i + n].type == 'WHITESPACE' ? gnextToken(i, n + 1, tokens) : { token: tokens[i + n], n, ti: i + n }) : null;
|
120
127
|
};
|
@@ -330,6 +337,19 @@ function compileRewStuff(content, options) {
|
|
330
337
|
}
|
331
338
|
}
|
332
339
|
|
340
|
+
if (token.type === "COMMENT" && token.value.startsWith('#alias')) {
|
341
|
+
let value = '#declare';
|
342
|
+
if(token.value.match(/^#alias\*/)) value += '*';
|
343
|
+
let subs;
|
344
|
+
subs = token.value.replace(/^#alias/, '');
|
345
|
+
if(token.value.endsWith('*')) subs.split('*')[1];
|
346
|
+
|
347
|
+
value += ' key';
|
348
|
+
value += ' ' + subs.replace(/([\S]+)\s*=\s*([\S]+)/, '"$1" = $2').trim();
|
349
|
+
value += ';';
|
350
|
+
declareAlias(aliases, {...token, value});
|
351
|
+
}
|
352
|
+
|
333
353
|
if (token.type === "COMMENT" && token.value.startsWith('#declare')) {
|
334
354
|
if (token.value.includes(';')) {
|
335
355
|
declareAlias(aliases, token);
|
@@ -396,6 +416,19 @@ function compileRewStuff(content, options) {
|
|
396
416
|
} else straceLog('==> UNKNOWN');
|
397
417
|
}
|
398
418
|
|
419
|
+
if (token.type === 'IDENTIFIER' && token.value === 'as' && !options.keepImports) {
|
420
|
+
const isFrom = gnextToken(i, 3, tokens);
|
421
|
+
const isInImport = tokens[i-2];
|
422
|
+
if(isFrom?.token.value == 'from' && isInImport?.value !== '*'){
|
423
|
+
insertTokenAt(tokens, i, { type: 'WHITESPACE', value: ' ' });
|
424
|
+
insertTokenAt(tokens, i, { type: 'OTHER', value: '*' });
|
425
|
+
insertTokenAt(tokens, i, { type: 'WHITESPACE', value: ' ' });
|
426
|
+
insertTokenAt(tokens, i, { type: 'IDENTIFIER', value: 'import' });
|
427
|
+
i -= 1;
|
428
|
+
continue;
|
429
|
+
}
|
430
|
+
}
|
431
|
+
|
399
432
|
if (token.type === 'IDENTIFIER' && token.value === 'import' && !options.keepImports) {
|
400
433
|
// console.log(nextToken.type);
|
401
434
|
straceLog('IMPORT()');
|
@@ -428,8 +461,8 @@ function compileRewStuff(content, options) {
|
|
428
461
|
}
|
429
462
|
} else if (nextToken.value === '*') {
|
430
463
|
const asToken = fnextToken(ind, tokens, 'IDENTIFIER', 'as');
|
431
|
-
const nameToken = fnextToken(asToken.ri, tokens, 'STRING');
|
432
464
|
if (asToken) {
|
465
|
+
const nameToken = fnextToken(asToken.ti, tokens, 'STRING');
|
433
466
|
const nextToken = fnextToken(asToken.ti + 1, tokens, 'IDENTIFIER');
|
434
467
|
defaultName = nextToken.value;
|
435
468
|
straceLog('==>', defaultName, 'from', nameToken.value);
|
@@ -12,6 +12,7 @@ const { USING_DEFAULT, Usage, Namespace } = require("../const/usage");
|
|
12
12
|
const runtime = require("./runtime");
|
13
13
|
const { permission } = require("process");
|
14
14
|
const { straceLog } = require("../misc/strace");
|
15
|
+
const reval = require("../functions/reval");
|
15
16
|
|
16
17
|
let mainFile = "";
|
17
18
|
const isMainFile = (filepath) => filepath == mainFile;
|
@@ -37,6 +38,7 @@ module.exports.prepareContext = function (
|
|
37
38
|
},
|
38
39
|
app: findAppInfo(filepath),
|
39
40
|
...fsLib(filepath),
|
41
|
+
...reval(filepath),
|
40
42
|
__using__: {}
|
41
43
|
};
|
42
44
|
if (options.useContext) {
|
@@ -36,7 +36,8 @@ module.exports.runPath = function runPath(filepath, options = {}, custom_context
|
|
36
36
|
|
37
37
|
if(context.app){
|
38
38
|
const p = path.join(CONFIG_PATH, context.app.config.manifest.package, 'app');
|
39
|
-
|
39
|
+
const p2 = path.join(CONFIG_PATH, context.app.config.manifest.package, 'app/.allow');
|
40
|
+
if(existsSync(p) && context.app.path !== p && !existsSync(p2)){
|
40
41
|
console.log("App with the same package name has been installed. Conflicts happened. \nTo fix this, change your app's package name or remove the app making the conflict.");
|
41
42
|
return {
|
42
43
|
context: { module: { exports: null } },
|
@@ -46,11 +47,21 @@ module.exports.runPath = function runPath(filepath, options = {}, custom_context
|
|
46
47
|
}
|
47
48
|
|
48
49
|
compiled_code = preScript+'\n'+compiled_code;
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
50
|
+
|
51
|
+
let execd = exec(compiled_code, context, file.content);
|
52
|
+
|
53
|
+
if(context.module.main && (context.module.exports?.main || (typeof context.module.exports == "function" && context.module.exports.name == 'main'))){
|
54
|
+
const mainFn = context.module.exports.main ?? context.module.exports;
|
55
|
+
return {
|
56
|
+
context,
|
57
|
+
returns: mainFn(context.process.argv)
|
58
|
+
}
|
59
|
+
} else {
|
60
|
+
return {
|
61
|
+
context,
|
62
|
+
returns: execd,
|
63
|
+
};
|
64
|
+
}
|
54
65
|
}
|
55
66
|
|
56
67
|
if(options.async){
|