@makano/rew 1.3.6 → 1.3.7

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.
@@ -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.includes(';')) {
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');
@@ -617,7 +683,8 @@ function compileRewStuff(content, options) {
617
683
  options.aliases = aliases;
618
684
  }
619
685
  // console.log(aliases);
620
- // console.log(result);
686
+ console.log(result);
687
+ return "";
621
688
  return result;
622
689
  }
623
690
 
package/main.js CHANGED
@@ -9,5 +9,6 @@ module.exports = {
9
9
  compileFile,
10
10
  run,
11
11
  pkgs,
12
- utils
12
+ utils,
13
+ LineMap: require('./lib/civet/main').SourceMap
13
14
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@makano/rew",
3
- "version": "1.3.6",
3
+ "version": "1.3.7",
4
4
  "description": "A simple coffescript runtime and app manager",
5
5
  "main": "main.js",
6
6
  "directories": {