@makano/rew 1.3.6 → 1.3.8
Sign up to get free protection for your applications and to get access to all the features.
- package/lib/rew/modules/compiler.js +68 -1
- package/lib/rew/modules/context.js +7 -0
- package/main.js +2 -1
- package/package.json +1 -1
@@ -283,6 +283,40 @@ function useImp(token, options){
|
|
283
283
|
return '';
|
284
284
|
}
|
285
285
|
|
286
|
+
function mapTokensToStrings(tokens) {
|
287
|
+
const result = [];
|
288
|
+
let current = '';
|
289
|
+
let inBrackets = false;
|
290
|
+
|
291
|
+
tokens.forEach(token => {
|
292
|
+
if (token.type === 'OTHER' && token.value === '{') {
|
293
|
+
if (current) {
|
294
|
+
result.push(current.trim());
|
295
|
+
current = '';
|
296
|
+
}
|
297
|
+
inBrackets = true;
|
298
|
+
current += token.value + ' ';
|
299
|
+
} else if (token.type === 'OTHER' && token.value === '}') {
|
300
|
+
current += token.value;
|
301
|
+
result.push(current.trim());
|
302
|
+
current = '';
|
303
|
+
inBrackets = false;
|
304
|
+
} else if(token.type === 'OTHER' && token.value === ',' && !inBrackets){
|
305
|
+
return;
|
306
|
+
} else {
|
307
|
+
current += token.value;
|
308
|
+
if (!inBrackets) {
|
309
|
+
result.push(current.trim());
|
310
|
+
current = '';
|
311
|
+
} else {
|
312
|
+
current += ' ';
|
313
|
+
}
|
314
|
+
}
|
315
|
+
});
|
316
|
+
|
317
|
+
return result;
|
318
|
+
}
|
319
|
+
|
286
320
|
function updateAliases(aliases, o = execOptions._syntaxAliases){
|
287
321
|
for(let h in o){
|
288
322
|
for(let i in o[h]){
|
@@ -293,6 +327,17 @@ function updateAliases(aliases, o = execOptions._syntaxAliases){
|
|
293
327
|
return aliases;
|
294
328
|
}
|
295
329
|
|
330
|
+
function insertAt(array, index, ...values) {
|
331
|
+
if (index > array.length) {
|
332
|
+
index = array.length;
|
333
|
+
} else if (index < 0) {
|
334
|
+
index = 0;
|
335
|
+
}
|
336
|
+
array.splice(index, 0, ...values);
|
337
|
+
|
338
|
+
return array;
|
339
|
+
}
|
340
|
+
|
296
341
|
function compileRewStuff(content, options) {
|
297
342
|
straceLog('TOKENIZE() for CURRENTFILE');
|
298
343
|
const tokens = tokenizeCoffeeScript(content);
|
@@ -318,7 +363,7 @@ function compileRewStuff(content, options) {
|
|
318
363
|
if ((token.type === "COMMENT" && multilineDeclare) || (token.type !== "COMMENT" && multilineDeclare)) {
|
319
364
|
if(token.type === "COMMENT"){
|
320
365
|
multilineDeclareBuffer.push(token.value.startsWith('###') ? token.value.slice(3) : token.value.slice(1));
|
321
|
-
if (token.value.
|
366
|
+
if (token.value.trim().endsWith(';')) {
|
322
367
|
multilineDeclare = false;
|
323
368
|
const combinedDeclaration = multilineDeclareBuffer.join('\n');
|
324
369
|
declareAlias(aliases, { ...token, value: combinedDeclaration });
|
@@ -454,6 +499,27 @@ function compileRewStuff(content, options) {
|
|
454
499
|
if(useImp(nextToken, options)) updateAliases(aliases);
|
455
500
|
result += `inc ${nextToken.value}`;
|
456
501
|
i += n;
|
502
|
+
} else if (nextToken.type === 'OTHER' && nextToken.value == "(") {
|
503
|
+
const closingBraceToken = fnextToken(ind, tokens, 'OTHER', ')');
|
504
|
+
let lastindex = ind;
|
505
|
+
if (closingBraceToken) {
|
506
|
+
const namesTokens = tokens.slice(ind, closingBraceToken.ti);
|
507
|
+
const next = gnextToken(closingBraceToken.ti, 1, tokens);
|
508
|
+
let exports = [];
|
509
|
+
if(next?.token?.value == 'as'){
|
510
|
+
const ebraceOpen = gnextToken(next.token.ti, 1, tokens);
|
511
|
+
const ebraceClose = fnextToken(ebraceOpen.ti, tokens, 'OTHER', ')');
|
512
|
+
const exportsTokens = tokens.slice(ebraceOpen.ti+1, ebraceClose.ti);
|
513
|
+
exports = mapTokensToStrings(exportsTokens.filter(token => token.type !== 'WHITESPACE'));
|
514
|
+
lastindex = ebraceClose.ti;
|
515
|
+
} else lastindex = closingBraceToken.ti;
|
516
|
+
const statements = namesTokens.filter(token => token.type !== 'WHITESPACE').map((token, index) => {
|
517
|
+
return tokenizeCoffeeScript(`\nimport `+ (exports[index] ? `${exports[index].startsWith('@') ? '* as '+ exports[index].slice(1) : exports[index]} from ${token.value};` : `${token.value}`))
|
518
|
+
});
|
519
|
+
i = lastindex+1;
|
520
|
+
insertAt(tokens, i, ...statements.flat());
|
521
|
+
continue;
|
522
|
+
}
|
457
523
|
} else if (nextToken.value === '{') {
|
458
524
|
const closingBraceToken = fnextToken(ind, tokens, 'OTHER', '}');
|
459
525
|
const nameToken = fnextToken(ind, tokens, 'STRING');
|
@@ -618,6 +684,7 @@ function compileRewStuff(content, options) {
|
|
618
684
|
}
|
619
685
|
// console.log(aliases);
|
620
686
|
// console.log(result);
|
687
|
+
// return "";
|
621
688
|
return result;
|
622
689
|
}
|
623
690
|
|
@@ -79,6 +79,13 @@ module.exports.prepareContext = function (
|
|
79
79
|
}, Main: (cb) => {
|
80
80
|
if(cb?.main){
|
81
81
|
cb.main._class = cb;
|
82
|
+
if(cb.prepare){
|
83
|
+
cb.prepare((object) => {
|
84
|
+
for(let i in object){
|
85
|
+
cb[i] = object[i];
|
86
|
+
}
|
87
|
+
});
|
88
|
+
}
|
82
89
|
}
|
83
90
|
return (['main', cb?.main ?? cb]);
|
84
91
|
}, attach: (object) => {
|
package/main.js
CHANGED