functionalscript 0.17.0 → 0.18.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/fs/ci/common/module.f.d.ts +4 -5
- package/fs/ci/common/module.f.js +4 -4
- package/fs/ci/config/module.f.d.ts +4 -4
- package/fs/ci/config/module.f.js +4 -4
- package/fs/ci/test.f.js +2 -4
- package/fs/dev/module.f.d.ts +3 -3
- package/fs/dev/module.f.js +12 -9
- package/fs/dev/tf/module.d.ts +1 -0
- package/fs/dev/tf/module.f.d.ts +70 -6
- package/fs/dev/tf/module.f.js +135 -87
- package/fs/dev/tf/module.js +66 -17
- package/fs/dev/tf/test.f.d.ts +21 -20
- package/fs/dev/tf/test.f.js +249 -31
- package/fs/djs/module.f.d.ts +2 -2
- package/fs/djs/module.f.js +8 -5
- package/fs/djs/test.f.js +5 -6
- package/fs/djs/tokenizer-new/test.f.js +126 -78
- package/fs/djs/transpiler/module.f.js +2 -2
- package/fs/djs/transpiler/test.f.js +11 -12
- package/fs/fjs/module.f.d.ts +2 -7
- package/fs/fjs/module.f.js +16 -22
- package/fs/fjs/module.js +2 -2
- package/fs/io/module.d.ts +3 -3
- package/fs/io/module.f.d.ts +5 -2
- package/fs/io/module.f.js +14 -3
- package/fs/io/module.js +38 -17
- package/fs/path/module.f.d.ts +6 -0
- package/fs/path/module.f.js +6 -0
- package/fs/path/test.f.d.ts +3 -5
- package/fs/path/test.f.js +67 -49
- package/fs/text/sgr/module.f.d.ts +9 -1
- package/fs/text/sgr/module.f.js +16 -5
- package/fs/types/effects/node/module.f.d.ts +17 -17
- package/fs/types/effects/node/module.f.js +20 -2
- package/fs/types/effects/node/test.f.js +8 -5
- package/fs/types/effects/node/virtual/module.f.d.ts +11 -2
- package/fs/types/effects/node/virtual/module.f.js +30 -17
- package/fs/types/function/compare/module.f.d.ts +12 -0
- package/fs/types/function/compare/module.f.js +33 -0
- package/fs/types/function/operator/test.f.d.ts +10 -0
- package/fs/types/function/operator/test.f.js +81 -0
- package/fs/types/range_map/module.f.js +3 -18
- package/fs/types/result/module.f.d.ts +4 -0
- package/fs/types/result/module.f.js +4 -0
- package/fs/types/result/test.f.d.ts +2 -4
- package/fs/types/result/test.f.js +24 -16
- package/fs/types/rtti/common/module.f.d.ts +10 -1
- package/fs/types/rtti/common/module.f.js +7 -2
- package/fs/types/rtti/parse/module.f.js +35 -46
- package/fs/types/rtti/validate/module.f.js +9 -12
- package/fs/types/sorted_list/module.f.d.ts +1 -2
- package/fs/types/sorted_list/module.f.js +8 -21
- package/fs/types/sorted_set/module.f.d.ts +1 -3
- package/fs/types/ts/test.f.d.ts +18 -0
- package/fs/types/ts/test.f.js +111 -0
- package/fs/types/uint8array/module.f.js +7 -1
- package/fs/types/uint8array/test.f.d.ts +1 -0
- package/fs/types/uint8array/test.f.js +5 -1
- package/package.json +1 -1
|
@@ -10,8 +10,15 @@ const descentParserCpOnly = (m, name, cp) => {
|
|
|
10
10
|
const tokenizeString = s => {
|
|
11
11
|
const m = descentParser(jsGrammar());
|
|
12
12
|
const cp = toArray(stringToCodePointList(s));
|
|
13
|
-
const
|
|
14
|
-
|
|
13
|
+
const [ast, ok, len] = descentParserCpOnly(m, '', cp);
|
|
14
|
+
if (cp.length === 0) {
|
|
15
|
+
return JSON.stringify([{ kind: 'eof' }]);
|
|
16
|
+
}
|
|
17
|
+
if (!ok)
|
|
18
|
+
return 'error';
|
|
19
|
+
if (cp.length > 0 && len !== cp.length)
|
|
20
|
+
return 'error';
|
|
21
|
+
const flatTokens = getTokensFromAstRule(ast);
|
|
15
22
|
const filterTokens = concat(filter(filterFunc)(flatTokens))(['']);
|
|
16
23
|
const tokens = flat(stateScan(scanFunc)(['', []])(filterTokens));
|
|
17
24
|
const jsTokens = concat(map(toJsToken)(tokens))([{ kind: 'eof' }]);
|
|
@@ -19,8 +26,16 @@ const tokenizeString = s => {
|
|
|
19
26
|
//return JSON.stringify(toArray(filterTokens))
|
|
20
27
|
return JSON.stringify(result);
|
|
21
28
|
};
|
|
29
|
+
const isNlTag = (tag) => tag === '\n' || tag === '\r';
|
|
30
|
+
const isWsTag = (tag) => tag === ' ' || tag === '\t';
|
|
22
31
|
const scanFunc = (input, state) => {
|
|
23
32
|
if (typeof input === 'string') {
|
|
33
|
+
if (isNlTag(input) && isNlTag(state[0]))
|
|
34
|
+
return [null, state];
|
|
35
|
+
if (isWsTag(input) && isWsTag(state[0]))
|
|
36
|
+
return [null, state];
|
|
37
|
+
if (isNlTag(input) && isWsTag(state[0]))
|
|
38
|
+
return [null, [input, []]];
|
|
24
39
|
const newState = [input, []];
|
|
25
40
|
if (state[0] === '') {
|
|
26
41
|
return [null, newState];
|
|
@@ -42,6 +57,10 @@ const filterFunc = tk => {
|
|
|
42
57
|
case ',':
|
|
43
58
|
case 'number':
|
|
44
59
|
case 'string':
|
|
60
|
+
case '\n':
|
|
61
|
+
case '\r':
|
|
62
|
+
case ' ':
|
|
63
|
+
case '\t':
|
|
45
64
|
return true;
|
|
46
65
|
default:
|
|
47
66
|
return false;
|
|
@@ -56,6 +75,14 @@ const toJsToken = tk => {
|
|
|
56
75
|
case ':':
|
|
57
76
|
case ',':
|
|
58
77
|
return { kind: tk[0] };
|
|
78
|
+
case '\n':
|
|
79
|
+
case '\r':
|
|
80
|
+
return { kind: 'nl' };
|
|
81
|
+
case ' ':
|
|
82
|
+
case '\t':
|
|
83
|
+
return { kind: 'ws' };
|
|
84
|
+
case 'string':
|
|
85
|
+
return { kind: 'string', value: String.fromCodePoint(...tk[1].slice(1, -1)) };
|
|
59
86
|
default:
|
|
60
87
|
return null;
|
|
61
88
|
}
|
|
@@ -81,9 +108,6 @@ const getTokensFromAstRule = ast => {
|
|
|
81
108
|
return [token];
|
|
82
109
|
return { first: token, tail: getTokensFromAstSequence(ast.sequence) };
|
|
83
110
|
};
|
|
84
|
-
const getTokensFromMatchResult = mr => {
|
|
85
|
-
return getTokensFromAstRule(mr[0]);
|
|
86
|
-
};
|
|
87
111
|
export default {
|
|
88
112
|
isValid: [() => {
|
|
89
113
|
const m = descentParser(jsGrammar());
|
|
@@ -319,34 +343,48 @@ export default {
|
|
|
319
343
|
throw result;
|
|
320
344
|
}
|
|
321
345
|
},
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
346
|
+
() => {
|
|
347
|
+
const result = tokenizeString('ᄑ');
|
|
348
|
+
if (result !== 'error') {
|
|
349
|
+
throw result;
|
|
350
|
+
}
|
|
351
|
+
},
|
|
352
|
+
() => {
|
|
353
|
+
const result = tokenizeString('{ \t\n\r}');
|
|
354
|
+
if (result !== '[{"kind":"{"},{"kind":"nl"},{"kind":"}"},{"kind":"eof"}]') {
|
|
355
|
+
throw result;
|
|
356
|
+
}
|
|
357
|
+
},
|
|
358
|
+
() => {
|
|
359
|
+
const result = tokenizeString('""');
|
|
360
|
+
if (result !== '[{"kind":"string","value":""},{"kind":"eof"}]') {
|
|
361
|
+
throw result;
|
|
362
|
+
}
|
|
363
|
+
},
|
|
364
|
+
() => {
|
|
365
|
+
const result = tokenizeString('"value"');
|
|
366
|
+
if (result !== '[{"kind":"string","value":"value"},{"kind":"eof"}]') {
|
|
367
|
+
throw result;
|
|
368
|
+
}
|
|
369
|
+
},
|
|
370
|
+
() => {
|
|
371
|
+
const result = tokenizeString('"value');
|
|
372
|
+
if (result !== 'error') {
|
|
373
|
+
throw result;
|
|
374
|
+
}
|
|
375
|
+
},
|
|
376
|
+
() => {
|
|
377
|
+
const result = tokenizeString('"value1" "value2"');
|
|
378
|
+
if (result !== '[{"kind":"string","value":"value1"},{"kind":"ws"},{"kind":"string","value":"value2"},{"kind":"eof"}]') {
|
|
379
|
+
throw result;
|
|
380
|
+
}
|
|
381
|
+
},
|
|
382
|
+
() => {
|
|
383
|
+
const result = tokenizeString('"');
|
|
384
|
+
if (result !== 'error') {
|
|
385
|
+
throw result;
|
|
386
|
+
}
|
|
387
|
+
},
|
|
350
388
|
// () => {
|
|
351
389
|
// const result = tokenizeString('"\\\\"')
|
|
352
390
|
// if (result !== '[{"kind":"string","value":"\\\\"},{"kind":"eof"}]') { throw result }
|
|
@@ -359,22 +397,30 @@ export default {
|
|
|
359
397
|
// const result = tokenizeString('"\\/"')
|
|
360
398
|
// if (result !== '[{"kind":"string","value":"/"},{"kind":"eof"}]') { throw result }
|
|
361
399
|
// },
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
400
|
+
() => {
|
|
401
|
+
const result = tokenizeString('"\\x"');
|
|
402
|
+
if (result !== 'error') {
|
|
403
|
+
throw result;
|
|
404
|
+
}
|
|
405
|
+
},
|
|
406
|
+
() => {
|
|
407
|
+
const result = tokenizeString('"\\');
|
|
408
|
+
if (result !== 'error') {
|
|
409
|
+
throw result;
|
|
410
|
+
}
|
|
411
|
+
},
|
|
412
|
+
() => {
|
|
413
|
+
const result = tokenizeString('"\r"');
|
|
414
|
+
if (result !== 'error') {
|
|
415
|
+
throw result;
|
|
416
|
+
}
|
|
417
|
+
},
|
|
418
|
+
() => {
|
|
419
|
+
const result = tokenizeString('"\n null');
|
|
420
|
+
if (result !== 'error') {
|
|
421
|
+
throw result;
|
|
422
|
+
}
|
|
423
|
+
},
|
|
378
424
|
// () => {
|
|
379
425
|
// const result = tokenizeString('"\\b\\f\\n\\r\\t"')
|
|
380
426
|
// if (result !== '[{"kind":"string","value":"\\b\\f\\n\\r\\t"},{"kind":"eof"}]') { throw result }
|
|
@@ -387,10 +433,12 @@ export default {
|
|
|
387
433
|
// const result = tokenizeString('"\\uaBcDEeFf"')
|
|
388
434
|
// if (result !== '[{"kind":"string","value":"ꯍEeFf"},{"kind":"eof"}]') { throw result }
|
|
389
435
|
// },
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
436
|
+
() => {
|
|
437
|
+
const result = tokenizeString('"\\uEeFg"');
|
|
438
|
+
if (result !== 'error') {
|
|
439
|
+
throw result;
|
|
440
|
+
}
|
|
441
|
+
},
|
|
394
442
|
// () => {
|
|
395
443
|
// const result = tokenizeString('0')
|
|
396
444
|
// if (result !== '[{"bf":[0n,0],"kind":"number","value":"0"},{"kind":"eof"}]') { throw result }
|
|
@@ -399,14 +447,14 @@ export default {
|
|
|
399
447
|
// const result = tokenizeString('[0]')
|
|
400
448
|
// if (result !== '[{"kind":"["},{"bf":[0n,0],"kind":"number","value":"0"},{"kind":"]"},{"kind":"eof"}]') { throw result }
|
|
401
449
|
// },
|
|
402
|
-
//
|
|
403
|
-
//
|
|
404
|
-
//
|
|
405
|
-
//
|
|
406
|
-
//
|
|
407
|
-
//
|
|
408
|
-
//
|
|
409
|
-
//
|
|
450
|
+
// () => {
|
|
451
|
+
// const result = tokenizeString('00')
|
|
452
|
+
// if (result !== 'error') { throw result }
|
|
453
|
+
// },
|
|
454
|
+
// () => {
|
|
455
|
+
// const result = tokenizeString('0abc,')
|
|
456
|
+
// if (result !== 'error') { throw result }
|
|
457
|
+
// },
|
|
410
458
|
// () => {
|
|
411
459
|
// const result = tokenizeString('123456789012345678901234567890')
|
|
412
460
|
// if (result !== '[{"bf":[123456789012345678901234567890n,0],"kind":"number","value":"123456789012345678901234567890"},{"kind":"eof"}]') { throw result }
|
|
@@ -421,7 +469,7 @@ export default {
|
|
|
421
469
|
// },
|
|
422
470
|
// () => {
|
|
423
471
|
// const result = tokenizeString('0. 2')
|
|
424
|
-
// if (result !== '
|
|
472
|
+
// if (result !== 'error') { throw result }
|
|
425
473
|
// },
|
|
426
474
|
// () => {
|
|
427
475
|
// const result = tokenizeString('10-0')
|
|
@@ -429,7 +477,7 @@ export default {
|
|
|
429
477
|
// },
|
|
430
478
|
// () => {
|
|
431
479
|
// const result = tokenizeString('9a:')
|
|
432
|
-
// if (result !== '
|
|
480
|
+
// if (result !== 'error') { throw result }
|
|
433
481
|
// },
|
|
434
482
|
// () => {
|
|
435
483
|
// const result = tokenizeString('-10')
|
|
@@ -441,7 +489,7 @@ export default {
|
|
|
441
489
|
// },
|
|
442
490
|
// () => {
|
|
443
491
|
// const result = tokenizeString('-00')
|
|
444
|
-
// if (result !== '
|
|
492
|
+
// if (result !== 'error') { throw result }
|
|
445
493
|
// },
|
|
446
494
|
// () => {
|
|
447
495
|
// const result = tokenizeString('-.123')
|
|
@@ -457,11 +505,11 @@ export default {
|
|
|
457
505
|
// },
|
|
458
506
|
// () => {
|
|
459
507
|
// const result = tokenizeString('-0.')
|
|
460
|
-
// if (result !== '
|
|
508
|
+
// if (result !== 'error') { throw result }
|
|
461
509
|
// },
|
|
462
510
|
// () => {
|
|
463
511
|
// const result = tokenizeString('-0.]')
|
|
464
|
-
// if (result !== '
|
|
512
|
+
// if (result !== 'error') { throw result }
|
|
465
513
|
// },
|
|
466
514
|
// () => {
|
|
467
515
|
// const result = tokenizeString('12.34')
|
|
@@ -473,11 +521,11 @@ export default {
|
|
|
473
521
|
// },
|
|
474
522
|
// () => {
|
|
475
523
|
// const result = tokenizeString('-12.')
|
|
476
|
-
// if (result !== '
|
|
524
|
+
// if (result !== 'error') { throw result }
|
|
477
525
|
// },
|
|
478
526
|
// () => {
|
|
479
527
|
// const result = tokenizeString('12.]')
|
|
480
|
-
// if (result !== '
|
|
528
|
+
// if (result !== 'error') { throw result }
|
|
481
529
|
// },
|
|
482
530
|
// () => {
|
|
483
531
|
// const result = tokenizeString('0e1')
|
|
@@ -505,11 +553,11 @@ export default {
|
|
|
505
553
|
// },
|
|
506
554
|
// () => {
|
|
507
555
|
// const result = tokenizeString('0e')
|
|
508
|
-
// if (result !== '
|
|
556
|
+
// if (result !== 'error') { throw result }
|
|
509
557
|
// },
|
|
510
558
|
// () => {
|
|
511
559
|
// const result = tokenizeString('0e-')
|
|
512
|
-
// if (result !== '
|
|
560
|
+
// if (result !== 'error') { throw result }
|
|
513
561
|
// },
|
|
514
562
|
// () => {
|
|
515
563
|
// const result = tokenizeString('ABCdef1234567890$_')
|
|
@@ -529,11 +577,11 @@ export default {
|
|
|
529
577
|
// },
|
|
530
578
|
// () => {
|
|
531
579
|
// const result = tokenizeString('123_123')
|
|
532
|
-
// if (result !== '
|
|
580
|
+
// if (result !== 'error') { throw result }
|
|
533
581
|
// },
|
|
534
582
|
// () => {
|
|
535
583
|
// const result = tokenizeString('123$123')
|
|
536
|
-
// if (result !== '
|
|
584
|
+
// if (result !== 'error') { throw result }
|
|
537
585
|
// },
|
|
538
586
|
// () => {
|
|
539
587
|
// const result = tokenizeString('1234567890n')
|
|
@@ -549,19 +597,19 @@ export default {
|
|
|
549
597
|
// },
|
|
550
598
|
// () => {
|
|
551
599
|
// const result = tokenizeString('123.456n')
|
|
552
|
-
// if (result !== '
|
|
600
|
+
// if (result !== 'error') { throw result }
|
|
553
601
|
// },
|
|
554
602
|
// () => {
|
|
555
603
|
// const result = tokenizeString('123e456n')
|
|
556
|
-
// if (result !== '
|
|
604
|
+
// if (result !== 'error') { throw result }
|
|
557
605
|
// },
|
|
558
606
|
// () => {
|
|
559
607
|
// const result = tokenizeString('1234567890na')
|
|
560
|
-
// if (result !== '
|
|
608
|
+
// if (result !== 'error') { throw result }
|
|
561
609
|
// },
|
|
562
610
|
// () => {
|
|
563
611
|
// const result = tokenizeString('1234567890nn')
|
|
564
|
-
// if (result !== '
|
|
612
|
+
// if (result !== 'error') { throw result }
|
|
565
613
|
// },
|
|
566
614
|
],
|
|
567
615
|
// operators:
|
|
@@ -876,11 +924,11 @@ export default {
|
|
|
876
924
|
// },
|
|
877
925
|
// () => {
|
|
878
926
|
// const result = tokenizeString('/* multiline comment *')
|
|
879
|
-
// if (result !== '
|
|
927
|
+
// if (result !== 'error') { throw result }
|
|
880
928
|
// },
|
|
881
929
|
// () => {
|
|
882
930
|
// const result = tokenizeString('/* multiline comment ')
|
|
883
|
-
// if (result !== '
|
|
931
|
+
// if (result !== 'error') { throw result }
|
|
884
932
|
// },
|
|
885
933
|
// () => {
|
|
886
934
|
// const result = tokenizeString('/* multiline comment \n * **/')
|
|
@@ -12,9 +12,9 @@ import { stringToList } from "../../text/utf16/module.f.js";
|
|
|
12
12
|
import { concat as pathConcat } from "../../path/module.f.js";
|
|
13
13
|
import { parseFromTokens } from "../parser/module.f.js";
|
|
14
14
|
import { run } from "../ast/module.f.js";
|
|
15
|
-
import { decodeUtf8, fromVec } from "../../types/uint8array/module.f.js";
|
|
16
15
|
import { pure } from "../../types/effects/module.f.js";
|
|
17
16
|
import { readFile } from "../../types/effects/node/module.f.js";
|
|
17
|
+
import { utf8ToString } from "../../text/module.f.js";
|
|
18
18
|
const mapDjs = context => path => {
|
|
19
19
|
const res = at(path)(context.complete);
|
|
20
20
|
if (res === null) {
|
|
@@ -26,7 +26,7 @@ const parseModule = path => readFile(path).step(result => {
|
|
|
26
26
|
if (result[0] === 'error') {
|
|
27
27
|
return pure(error({ message: 'file not found', metadata: null }));
|
|
28
28
|
}
|
|
29
|
-
const tokens = tokenize(stringToList(
|
|
29
|
+
const tokens = tokenize(stringToList(utf8ToString(result[1])))(path);
|
|
30
30
|
return pure(parseFromTokens(tokens));
|
|
31
31
|
});
|
|
32
32
|
const transpileWithImports = path => parseModuleResult => context => {
|
|
@@ -2,15 +2,14 @@ import { sort } from "../../types/object/module.f.js";
|
|
|
2
2
|
import { transpile } from "./module.f.js";
|
|
3
3
|
import { stringifyAsTree } from "../serializer/module.f.js";
|
|
4
4
|
import { virtual, emptyState } from "../../types/effects/node/virtual/module.f.js";
|
|
5
|
-
import {
|
|
6
|
-
const fileVec = (s) => toVec(encodeUtf8(s));
|
|
5
|
+
import { utf8 } from "../../text/module.f.js";
|
|
7
6
|
const run = (root) => (path) => {
|
|
8
7
|
const [_, result] = virtual({ ...emptyState, root })(transpile(path));
|
|
9
8
|
return result;
|
|
10
9
|
};
|
|
11
10
|
export default {
|
|
12
11
|
parse: () => {
|
|
13
|
-
const result = run({ a:
|
|
12
|
+
const result = run({ a: utf8('export default 1') })('a');
|
|
14
13
|
if (result[0] === 'error') {
|
|
15
14
|
throw result[1];
|
|
16
15
|
}
|
|
@@ -20,7 +19,7 @@ export default {
|
|
|
20
19
|
}
|
|
21
20
|
},
|
|
22
21
|
parseWithSubModule: () => {
|
|
23
|
-
const result = run({ a: { b:
|
|
22
|
+
const result = run({ a: { b: utf8('import c from "c"\nexport default c'), c: utf8('export default 2') } })('a/b');
|
|
24
23
|
if (result[0] === 'error') {
|
|
25
24
|
throw result[1];
|
|
26
25
|
}
|
|
@@ -31,10 +30,10 @@ export default {
|
|
|
31
30
|
},
|
|
32
31
|
parseWithSubModules: () => {
|
|
33
32
|
const result = run({
|
|
34
|
-
a:
|
|
35
|
-
b:
|
|
36
|
-
c:
|
|
37
|
-
d:
|
|
33
|
+
a: utf8('import b from "b"\nimport c from "c"\nexport default [b,c,b]'),
|
|
34
|
+
b: utf8('import d from "d"\nexport default [0,d]'),
|
|
35
|
+
c: utf8('import d from "d"\nexport default [1,d]'),
|
|
36
|
+
d: utf8('export default 2'),
|
|
38
37
|
})('a');
|
|
39
38
|
if (result[0] === 'error') {
|
|
40
39
|
throw result[1];
|
|
@@ -45,7 +44,7 @@ export default {
|
|
|
45
44
|
}
|
|
46
45
|
},
|
|
47
46
|
parseWithFileNotFoundError: () => {
|
|
48
|
-
const result = run({ a:
|
|
47
|
+
const result = run({ a: utf8('import b from "b"\nexport default b') })('a');
|
|
49
48
|
if (result[0] !== 'error') {
|
|
50
49
|
throw result;
|
|
51
50
|
}
|
|
@@ -55,9 +54,9 @@ export default {
|
|
|
55
54
|
},
|
|
56
55
|
parseWithCycleError: () => {
|
|
57
56
|
const result = run({
|
|
58
|
-
a:
|
|
59
|
-
b:
|
|
60
|
-
c:
|
|
57
|
+
a: utf8('import b from "b"\nimport c from "c"\nexport default [b,c,b]'),
|
|
58
|
+
b: utf8('import c from "c"\nexport default c'),
|
|
59
|
+
c: utf8('import b from "b"\nexport default b'),
|
|
61
60
|
})('a');
|
|
62
61
|
if (result[0] !== 'error') {
|
|
63
62
|
throw result;
|
package/fs/fjs/module.f.d.ts
CHANGED
|
@@ -1,7 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
*
|
|
4
|
-
* @module
|
|
5
|
-
*/
|
|
6
|
-
import { type Io } from '../io/module.f.ts';
|
|
7
|
-
export declare const main: (io: Io) => Promise<number>;
|
|
1
|
+
import { type NodeProgram } from '../types/effects/node/module.f.ts';
|
|
2
|
+
export declare const main: NodeProgram;
|
package/fs/fjs/module.f.js
CHANGED
|
@@ -3,42 +3,36 @@
|
|
|
3
3
|
*
|
|
4
4
|
* @module
|
|
5
5
|
*/
|
|
6
|
-
import { fromIo } from "../io/module.f.js";
|
|
7
6
|
import { compile } from "../djs/module.f.js";
|
|
8
7
|
import { main as testMain } from "../dev/tf/module.f.js";
|
|
9
8
|
import { main as casMain } from "../cas/module.f.js";
|
|
10
|
-
import { import_ } from "../types/effects/node/module.f.js";
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
const
|
|
14
|
-
const { env } = process;
|
|
15
|
-
const [command, ...rest] = process.argv.slice(2);
|
|
16
|
-
const eRun = fromIo(io);
|
|
9
|
+
import { import_, error } from "../types/effects/node/module.f.js";
|
|
10
|
+
import { pure } from "../types/effects/module.f.js";
|
|
11
|
+
export const main = options => {
|
|
12
|
+
const [command, ...rest] = options.args;
|
|
17
13
|
switch (command) {
|
|
18
14
|
case 'test':
|
|
19
15
|
case 't':
|
|
20
|
-
return testMain(
|
|
16
|
+
return testMain({ ...options, args: rest });
|
|
21
17
|
case 'compile':
|
|
22
18
|
case 'c':
|
|
23
|
-
return
|
|
19
|
+
return compile(rest);
|
|
24
20
|
case 'cas':
|
|
25
21
|
case 's':
|
|
26
|
-
return
|
|
22
|
+
return casMain(rest);
|
|
27
23
|
case 'run':
|
|
28
|
-
case 'r':
|
|
24
|
+
case 'r': {
|
|
29
25
|
const [file, ...args] = rest;
|
|
30
|
-
return
|
|
31
|
-
if (
|
|
32
|
-
throw
|
|
26
|
+
return import_(file).step(([s, v]) => {
|
|
27
|
+
if (s === 'error') {
|
|
28
|
+
throw v;
|
|
33
29
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
30
|
+
return v.default({ ...options, args });
|
|
31
|
+
});
|
|
32
|
+
}
|
|
37
33
|
case undefined:
|
|
38
|
-
error('Error: command is required');
|
|
39
|
-
return Promise.resolve(1);
|
|
34
|
+
return error('Error: command is required').step(() => pure(1));
|
|
40
35
|
default:
|
|
41
|
-
error(`Error: Unknown command "${command}"`);
|
|
42
|
-
return Promise.resolve(1);
|
|
36
|
+
return error(`Error: Unknown command "${command}"`).step(() => pure(1));
|
|
43
37
|
}
|
|
44
38
|
};
|
package/fs/fjs/module.js
CHANGED
package/fs/io/module.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { type Io
|
|
1
|
+
import { type Io } from './module.f.ts';
|
|
2
2
|
import type { Module, NodeProgram } from '../types/effects/node/module.f.ts';
|
|
3
|
+
import { type Result } from '../types/result/module.f.ts';
|
|
3
4
|
export declare const asyncImport: (v: string) => Promise<Module>;
|
|
5
|
+
export declare const tryCatch: <T>(f: () => T) => Result<T, unknown>;
|
|
4
6
|
export declare const io: Io;
|
|
5
|
-
export declare const legacyRun: Run;
|
|
6
7
|
export type NodeRun = (p: NodeProgram) => Promise<number>;
|
|
7
|
-
export declare const ioRun: (io: Io) => NodeRun;
|
|
8
8
|
declare const effectRun: NodeRun;
|
|
9
9
|
export default effectRun;
|
package/fs/io/module.f.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { type Effect } from '../types/effects/module.f.ts';
|
|
2
|
-
import type { Headers, Module, NodeOp, Env, SandboxResult } from '../types/effects/node/module.f.ts';
|
|
2
|
+
import type { Headers, Module, NodeOp, Env, SandboxResult, NodeProgram, WriteConsoles } from '../types/effects/node/module.f.ts';
|
|
3
|
+
import type { Vec } from '../types/bit_vec/module.f.ts';
|
|
3
4
|
import { type Result } from '../types/result/module.f.ts';
|
|
4
5
|
/**
|
|
5
6
|
* Represents a directory entry (file or directory) in the filesystem
|
|
@@ -114,6 +115,7 @@ export type Io = {
|
|
|
114
115
|
readonly childProcess: ChildProcess;
|
|
115
116
|
readonly now: () => number;
|
|
116
117
|
readonly sandbox: Sandbox;
|
|
118
|
+
readonly write: (stream: WriteConsoles, data: Vec) => Promise<void>;
|
|
117
119
|
};
|
|
118
120
|
export type App = (io: Io) => Promise<number>;
|
|
119
121
|
export type Run = (f: App) => Promise<never>;
|
|
@@ -123,4 +125,5 @@ export type Run = (f: App) => Promise<never>;
|
|
|
123
125
|
*/
|
|
124
126
|
export declare const run: (io: Io) => Run;
|
|
125
127
|
export type EffectToPromise = <T>(effect: Effect<NodeOp, T>) => Promise<T>;
|
|
126
|
-
export declare const fromIo: ({
|
|
128
|
+
export declare const fromIo: ({ fs: { promises: { mkdir, readFile, readdir, writeFile, rm, access } }, fetch, http: { createServer }, childProcess, asyncImport, now: ioNow, sandbox: ioSandbox, write: ioWrite, }: Io) => EffectToPromise;
|
|
129
|
+
export declare const runProgram: (io: Io) => (args: readonly string[]) => (program: NodeProgram) => Promise<number>;
|
package/fs/io/module.f.js
CHANGED
|
@@ -44,11 +44,9 @@ const collect = async (v) => {
|
|
|
44
44
|
}
|
|
45
45
|
return result;
|
|
46
46
|
};
|
|
47
|
-
export const fromIo = ({
|
|
47
|
+
export const fromIo = ({ fs: { promises: { mkdir, readFile, readdir, writeFile, rm, access } }, fetch, http: { createServer }, childProcess, asyncImport, now: ioNow, sandbox: ioSandbox, write: ioWrite, }) => {
|
|
48
48
|
const result = asyncRun({
|
|
49
49
|
all: async (...effects) => await Promise.all(effects.map(result)),
|
|
50
|
-
error: async (message) => logError(message),
|
|
51
|
-
log: async (message) => log(message),
|
|
52
50
|
fetch: async (url) => tc(async () => {
|
|
53
51
|
const response = await fetch(url);
|
|
54
52
|
if (!response.ok) {
|
|
@@ -97,6 +95,19 @@ export const fromIo = ({ console: { error: logError, log }, fs: { promises: { mk
|
|
|
97
95
|
forever: () => new Promise(() => { }),
|
|
98
96
|
now: async () => ioNow(),
|
|
99
97
|
sandbox: async (f) => ioSandbox(f),
|
|
98
|
+
write: ioWrite,
|
|
100
99
|
});
|
|
101
100
|
return result;
|
|
102
101
|
};
|
|
102
|
+
export const runProgram = (io) => {
|
|
103
|
+
const { process: { env, stdout, stderr } } = io;
|
|
104
|
+
const f = fromIo(io);
|
|
105
|
+
return (args) => (program) => f(program({
|
|
106
|
+
args,
|
|
107
|
+
env,
|
|
108
|
+
std: {
|
|
109
|
+
stdout: { isTTY: stdout.isTTY },
|
|
110
|
+
stderr: { isTTY: stderr.isTTY },
|
|
111
|
+
},
|
|
112
|
+
}));
|
|
113
|
+
};
|