functionalscript 0.7.0 → 0.8.1

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.
Files changed (125) hide show
  1. package/LICENSE +21 -661
  2. package/README.md +3 -2
  3. package/bnf/data/module.f.d.ts +16 -6
  4. package/bnf/data/module.f.js +115 -23
  5. package/bnf/data/test.f.d.ts +4 -0
  6. package/bnf/data/test.f.js +389 -14
  7. package/bnf/module.f.d.ts +5 -4
  8. package/bnf/module.f.js +1 -1
  9. package/bnf/testlib.f.js +1 -1
  10. package/ci/module.f.d.ts +3 -0
  11. package/ci/module.f.js +169 -0
  12. package/ci/module.js +3 -0
  13. package/crypto/hmac/module.f.d.ts +5 -4
  14. package/crypto/hmac/module.f.js +9 -18
  15. package/crypto/hmac/test.f.d.ts +1 -0
  16. package/crypto/hmac/test.f.js +16 -8
  17. package/crypto/prime_field/module.f.d.ts +1 -1
  18. package/crypto/prime_field/module.f.js +4 -3
  19. package/crypto/prime_field/test.f.js +13 -13
  20. package/crypto/rfc6979/module.f.d.ts +15 -0
  21. package/crypto/rfc6979/module.f.js +98 -0
  22. package/crypto/rfc6979/test.f.d.ts +10 -0
  23. package/crypto/rfc6979/test.f.js +490 -0
  24. package/crypto/secp/module.f.d.ts +4 -4
  25. package/crypto/secp/module.f.js +1 -1
  26. package/crypto/secp/test.f.js +8 -8
  27. package/crypto/sha2/module.f.d.ts +11 -5
  28. package/crypto/sha2/module.f.js +4 -3
  29. package/crypto/sha2/test.f.d.ts +4 -1
  30. package/crypto/sha2/test.f.js +41 -31
  31. package/crypto/sign/module.f.d.ts +1 -1
  32. package/crypto/sign/module.f.js +3 -2
  33. package/dev/tf/all.test.js +9 -1
  34. package/djs/ast/module.f.d.ts +3 -3
  35. package/djs/ast/test.f.js +7 -8
  36. package/djs/parser/module.f.d.ts +3 -3
  37. package/djs/parser/module.f.js +4 -4
  38. package/djs/parser/test.f.js +76 -77
  39. package/djs/serializer/module.f.d.ts +8 -8
  40. package/djs/serializer/module.f.js +4 -7
  41. package/djs/serializer/test.f.js +8 -9
  42. package/djs/tokenizer/module.f.d.ts +2 -2
  43. package/djs/tokenizer/module.f.js +3 -5
  44. package/djs/tokenizer/test.f.js +8 -10
  45. package/djs/transpiler/module.f.d.ts +3 -3
  46. package/djs/transpiler/module.f.js +2 -0
  47. package/fsc/bnf.f.d.ts +1 -1
  48. package/fsc/bnf.f.js +39 -51
  49. package/fsc/json.f.d.ts +1 -1
  50. package/fsc/json.f.js +56 -81
  51. package/fsc/test.f.d.ts +5 -0
  52. package/fsc/test.f.js +69 -7
  53. package/fsm/module.f.js +3 -3
  54. package/fsm/test.f.js +21 -25
  55. package/html/module.f.js +17 -4
  56. package/html/test.f.d.ts +7 -0
  57. package/html/test.f.js +37 -0
  58. package/issues/031-json.f.d.ts +1 -0
  59. package/js/tokenizer/module.f.d.ts +4 -4
  60. package/js/tokenizer/module.f.js +12 -17
  61. package/js/tokenizer/test.f.js +9 -11
  62. package/json/module.f.d.ts +6 -6
  63. package/json/module.f.js +5 -10
  64. package/json/parser/module.f.d.ts +4 -4
  65. package/json/parser/module.f.js +7 -4
  66. package/json/parser/test.f.js +47 -49
  67. package/json/serializer/module.f.d.ts +6 -6
  68. package/json/serializer/module.f.js +3 -2
  69. package/json/serializer/test.f.js +13 -13
  70. package/json/test.f.js +13 -15
  71. package/json/tokenizer/module.f.d.ts +4 -4
  72. package/json/tokenizer/module.f.js +6 -7
  73. package/json/tokenizer/test.f.js +7 -9
  74. package/nanvm-lib/tests/vm/test.f.d.ts +25 -0
  75. package/nanvm-lib/tests/vm/test.f.js +105 -0
  76. package/package.json +8 -8
  77. package/text/ascii/test.f.js +2 -2
  78. package/text/module.f.d.ts +3 -2
  79. package/text/module.f.js +2 -2
  80. package/text/test.f.js +3 -3
  81. package/text/utf16/test.f.js +2 -2
  82. package/text/utf8/test.f.js +2 -2
  83. package/types/array/test.f.js +2 -2
  84. package/types/bigint/module.f.d.ts +6 -3
  85. package/types/bigint/module.f.js +12 -11
  86. package/types/bigint/test.f.d.ts +2 -0
  87. package/types/bigint/test.f.js +21 -2
  88. package/types/bit_vec/module.f.d.ts +66 -34
  89. package/types/bit_vec/module.f.js +97 -32
  90. package/types/bit_vec/test.f.d.ts +7 -0
  91. package/types/bit_vec/test.f.js +283 -62
  92. package/types/btree/find/test.f.js +9 -8
  93. package/types/btree/remove/test.f.js +4 -4
  94. package/types/btree/set/test.f.js +4 -4
  95. package/types/btree/test.f.js +7 -7
  96. package/types/byte_set/test.f.js +2 -2
  97. package/types/function/compare/module.f.d.ts +15 -1
  98. package/types/function/compare/module.f.js +1 -1
  99. package/types/function/compare/test.f.js +37 -4
  100. package/types/list/test.f.js +93 -93
  101. package/types/monoid/module.f.d.ts +4 -4
  102. package/types/monoid/module.f.js +3 -3
  103. package/types/monoid/test.f.js +3 -3
  104. package/types/nominal/module.f.d.ts +5 -0
  105. package/types/nominal/module.f.js +4 -0
  106. package/types/nominal/test.f.d.ts +5 -0
  107. package/types/nominal/test.f.js +53 -0
  108. package/types/number/module.f.js +2 -2
  109. package/types/range_map/test.f.js +21 -21
  110. package/types/sorted_list/test.f.js +10 -10
  111. package/types/sorted_set/test.f.js +14 -14
  112. package/types/string/module.f.js +2 -2
  113. package/types/string_set/module.f.js +3 -3
  114. package/bnf/djs/module.f.d.ts +0 -77
  115. package/bnf/djs/module.f.js +0 -207
  116. package/bnf/djs/test.f.d.ts +0 -8
  117. package/bnf/djs/test.f.js +0 -277
  118. package/bnf/func/module.f.d.ts +0 -148
  119. package/bnf/func/module.f.js +0 -132
  120. package/bnf/func/test.f.d.ts +0 -12
  121. package/bnf/func/test.f.js +0 -171
  122. package/bnf/func/testlib.f.d.ts +0 -25
  123. package/bnf/func/testlib.f.js +0 -150
  124. /package/{issues/31-json.f.d.ts → ci/module.d.ts} +0 -0
  125. /package/issues/{31-json.f.js → 031-json.f.js} +0 -0
@@ -1,8 +1,7 @@
1
1
  import { countRefs, stringify, stringifyAsTree } from "./module.f.js";
2
- import * as list from "../../types/object/module.f.js";
3
- const { sort } = list;
2
+ import { sort } from "../../types/object/module.f.js";
4
3
  import { identity } from "../../types/function/module.f.js";
5
- import * as json from "../../json/module.f.js";
4
+ import { setProperty } from "../../json/module.f.js";
6
5
  export default {
7
6
  stringify: [
8
7
  {
@@ -83,14 +82,14 @@ export default {
83
82
  stringifyAsTree: [
84
83
  {
85
84
  sort: () => {
86
- const r = json.setProperty("Hello")(['a'])({});
85
+ const r = setProperty("Hello")(['a'])({});
87
86
  const x = stringifyAsTree(sort)(r);
88
87
  if (x !== '{"a":"Hello"}') {
89
88
  throw x;
90
89
  }
91
90
  },
92
91
  identity: () => {
93
- const x = stringifyAsTree(identity)(json.setProperty("Hello")(['a'])({}));
92
+ const x = stringifyAsTree(identity)(setProperty("Hello")(['a'])({}));
94
93
  if (x !== '{"a":"Hello"}') {
95
94
  throw x;
96
95
  }
@@ -98,13 +97,13 @@ export default {
98
97
  },
99
98
  {
100
99
  sort: () => {
101
- const x = stringifyAsTree(sort)(json.setProperty("Hello")(['a'])({ c: [], b: 12 }));
100
+ const x = stringifyAsTree(sort)(setProperty("Hello")(['a'])({ c: [], b: 12 }));
102
101
  if (x !== '{"a":"Hello","b":12,"c":[]}') {
103
102
  throw x;
104
103
  }
105
104
  },
106
105
  identity: () => {
107
- const x = stringifyAsTree(identity)(json.setProperty("Hello")(['a'])({ c: [], b: 12 }));
106
+ const x = stringifyAsTree(identity)(setProperty("Hello")(['a'])({ c: [], b: 12 }));
108
107
  if (x !== '{"c":[],"b":12,"a":"Hello"}') {
109
108
  throw x;
110
109
  }
@@ -113,7 +112,7 @@ export default {
113
112
  {
114
113
  sort: () => {
115
114
  const _0 = { a: { y: [24] }, c: [], b: 12 };
116
- const _1 = json.setProperty("Hello")(['a', 'x'])(_0);
115
+ const _1 = setProperty("Hello")(['a', 'x'])(_0);
117
116
  const _2 = stringifyAsTree(sort)(_1);
118
117
  if (_2 !== '{"a":{"x":"Hello","y":[24]},"b":12,"c":[]}') {
119
118
  throw _2;
@@ -121,7 +120,7 @@ export default {
121
120
  },
122
121
  identity: () => {
123
122
  const _0 = { a: { y: [24] }, c: [], b: 12 };
124
- const _1 = json.setProperty("Hello")(['a', 'x'])(_0);
123
+ const _1 = setProperty("Hello")(['a', 'x'])(_0);
125
124
  const _2 = stringifyAsTree(identity)(_1);
126
125
  if (_2 !== '{"a":{"y":[24],"x":"Hello"},"c":[],"b":12}') {
127
126
  throw _2;
@@ -1,4 +1,4 @@
1
- import * as list from '../../types/list/module.f.ts';
1
+ import { type List } from '../../types/list/module.f.ts';
2
2
  import * as jsTokenizer from '../../js/tokenizer/module.f.ts';
3
3
  export type DjsToken = {
4
4
  readonly kind: 'true' | 'false' | 'null' | 'undefined';
@@ -9,4 +9,4 @@ export type DjsTokenWithMetadata = {
9
9
  readonly token: DjsToken;
10
10
  readonly metadata: jsTokenizer.TokenMetadata;
11
11
  };
12
- export declare const tokenize: (input: list.List<number>) => (path: string) => list.List<DjsTokenWithMetadata>;
12
+ export declare const tokenize: (input: List<number>) => (path: string) => List<DjsTokenWithMetadata>;
@@ -1,7 +1,5 @@
1
- import * as list from "../../types/list/module.f.js";
2
- const { empty, flat, stateScan } = list;
3
- import * as bf from "../../types/bigfloat/module.f.js";
4
- const { multiply } = bf;
1
+ import { empty, flat, map, stateScan } from "../../types/list/module.f.js";
2
+ import { multiply } from "../../types/bigfloat/module.f.js";
5
3
  import * as jsTokenizer from "../../js/tokenizer/module.f.js";
6
4
  const mapToken = input => {
7
5
  switch (input.kind) {
@@ -55,7 +53,7 @@ const scanToken = state => input => {
55
53
  const mapTokenWithMetadata = metadata => token => { return { token, metadata }; };
56
54
  const scanTokenWithMetadata = state => (input) => {
57
55
  const [djsTokens, newState] = scanToken(state)(input.token);
58
- const djsTokensWithMetadata = list.map(mapTokenWithMetadata(input.metadata))(djsTokens);
56
+ const djsTokensWithMetadata = map(mapTokenWithMetadata(input.metadata))(djsTokens);
59
57
  return [djsTokensWithMetadata, newState];
60
58
  };
61
59
  export const tokenize = input => path => {
@@ -1,13 +1,11 @@
1
- import * as tokenizer from "./module.f.js";
2
- import * as list from "../../types/list/module.f.js";
3
- const { toArray } = list;
4
- import * as serializer from "../serializer/module.f.js";
5
- import * as o from "../../types/object/module.f.js";
6
- const { sort } = o;
7
- import * as encoding from "../../text/utf16/module.f.js";
8
- const tokenizeString = s => toArray(list.map(withoutMetada)(tokenizer.tokenize(encoding.stringToList(s))('')));
9
- const tokenizeStringWithMetadata = s => toArray(tokenizer.tokenize(encoding.stringToList(s))(''));
10
- const stringify = serializer.stringifyAsTree(sort);
1
+ import { tokenize } from "./module.f.js";
2
+ import { map, toArray } from "../../types/list/module.f.js";
3
+ import { stringifyAsTree } from "../serializer/module.f.js";
4
+ import { sort } from "../../types/object/module.f.js";
5
+ import { stringToList } from "../../text/utf16/module.f.js";
6
+ const tokenizeString = s => toArray(map(withoutMetada)(tokenize(stringToList(s))('')));
7
+ const tokenizeStringWithMetadata = s => toArray(tokenize(stringToList(s))(''));
8
+ const stringify = stringifyAsTree(sort);
11
9
  const withoutMetada = tokenWithMetada => { return tokenWithMetada.token; };
12
10
  export default {
13
11
  djs: [
@@ -1,4 +1,4 @@
1
- import type * as djs from '../module.f.ts';
1
+ import { type Unknown } from '../module.f.ts';
2
2
  import { type Result } from '../../types/result/module.f.ts';
3
3
  import { type List } from '../../types/list/module.f.ts';
4
4
  import { type OrderedMap } from '../../types/ordered_map/module.f.ts';
@@ -11,6 +11,6 @@ export type ParseContext = {
11
11
  readonly error: ParseError | null;
12
12
  };
13
13
  export type djsResult = {
14
- djs: djs.Unknown;
14
+ djs: Unknown;
15
15
  };
16
- export declare const transpile: (fs: Fs) => (path: string) => Result<djs.Unknown, ParseError>;
16
+ export declare const transpile: (fs: Fs) => (path: string) => Result<Unknown, ParseError>;
@@ -1,5 +1,7 @@
1
+ import {} from "../module.f.js";
1
2
  import { error, ok } from "../../types/result/module.f.js";
2
3
  import { fold, drop, map as listMap, toArray, includes } from "../../types/list/module.f.js";
4
+ import {} from "../../types/function/operator/module.f.js";
3
5
  import { tokenize } from "../tokenizer/module.f.js";
4
6
  import { setReplace, at } from "../../types/ordered_map/module.f.js";
5
7
  import { stringToList } from "../../text/utf16/module.f.js";
package/fsc/bnf.f.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- import { type Rule } from '../bnf/func/module.f.ts';
1
+ import { type Rule } from '../bnf/module.f.ts';
2
2
  export declare const wsModule: Rule;
package/fsc/bnf.f.js CHANGED
@@ -1,54 +1,42 @@
1
- import { cp, range, remove, set, str } from "../bnf/func/module.f.js";
1
+ import { range, remove, set, option } from "../bnf/module.f.js";
2
2
  import { digit, json, unicode, ws0, ws1, wsNoNewLine0 } from "./json.f.js";
3
- export const wsModule = () => [[ws0, module]];
4
- const module = () => [
5
- [json, ws0],
6
- [fjs],
7
- ];
8
- const fjs = () => [
9
- [],
10
- [...str('const'), ws1, id, ws0, cp('='), ws0, json, wsNoNewLine0, fjsTail],
11
- [...str('export'), ws1, ...str('default'), ws1, json],
12
- ];
13
- const fjsTail = () => [
14
- [],
15
- [cp('\n'), ws0, fjs],
16
- ];
3
+ export const wsModule = () => [ws0, module];
4
+ const module = () => ({
5
+ json: [json, ws0],
6
+ fjs,
7
+ });
8
+ const fjs = () => option({
9
+ const: ['const', ws1, id, ws0, '=', ws0, json, wsNoNewLine0, fjsTail],
10
+ export: ['export', ws1, 'default', ws1, json],
11
+ });
12
+ const fjsTail = option(['\n', ws0, fjs]);
17
13
  // line comment
18
- const lineItem = () => remove(unicode, [cp('\n')]);
19
- const line = () => [
20
- [],
21
- [lineItem, line]
22
- ];
23
- const lineComment = () => [
24
- [cp('/'), commentTail, cp('\n')]
25
- ];
26
- const multiLineSkip = () => remove(unicode, [cp('/')]);
27
- const multiLineItem = () => remove(unicode, [cp('*')]);
28
- const multiLine = () => [
29
- [cp('*'), multiLineTail],
30
- [multiLineItem, multiLine]
31
- ];
32
- const multiLineTail = () => [
33
- [cp('/')],
34
- [multiLineSkip, multiLine]
35
- ];
36
- const commentTail = () => [
37
- [cp('/'), lineComment],
38
- [cp('*'), multiLine],
39
- ];
14
+ const lineItem = remove(unicode, set('\n'));
15
+ const line = () => option([lineItem, line]);
16
+ const lineComment = () => ['/', commentTail, '\n'];
17
+ const multiLineSkip = remove(unicode, set('/'));
18
+ const multiLineItem = remove(unicode, set('*'));
19
+ const multiLine = () => ({
20
+ '*': ['*', multiLineTail],
21
+ '_': [multiLineItem, multiLine]
22
+ });
23
+ const multiLineTail = {
24
+ '/': '/',
25
+ '_': [multiLineSkip, multiLine]
26
+ };
27
+ const commentTail = {
28
+ '/': ['/', lineComment],
29
+ '*': ['*', multiLine],
30
+ };
40
31
  // id
41
- const id = () => [[alpha, idTail0]];
42
- const alpha = () => [
43
- [range('AZ')],
44
- [range('az')],
45
- ...set('_$'),
46
- ];
47
- const idTail0 = () => [
48
- [],
49
- [alphaDigit, idTail0],
50
- ];
51
- const alphaDigit = () => [
52
- [alpha],
53
- [digit],
54
- ];
32
+ const id = () => [alpha, idTail0];
33
+ const alpha = {
34
+ upper: range('AZ'),
35
+ lower: range('az'),
36
+ _: set('_$'),
37
+ };
38
+ const idTail0 = () => option([alphaDigit, idTail0]);
39
+ const alphaDigit = {
40
+ alpha,
41
+ digit,
42
+ };
package/fsc/json.f.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { type Rule, type TerminalRange } from '../bnf/func/module.f.ts';
1
+ import { type Rule, type TerminalRange } from '../bnf/module.f.ts';
2
2
  export declare const wsNoNewLine0: Rule;
3
3
  export declare const ws0: Rule;
4
4
  export declare const ws1: Rule;
package/fsc/json.f.js CHANGED
@@ -1,89 +1,64 @@
1
- import { cp, join0, range, remove, repeat0, set, str } from "../bnf/func/module.f.js";
1
+ import { join0Plus, rangeEncode, range, remove, repeat0Plus, set, option } from "../bnf/module.f.js";
2
2
  // space
3
- const wsNoNewLineItem = () => set(' \t\r');
4
- export const wsNoNewLine0 = () => [
5
- [],
6
- [wsNoNewLineItem, wsNoNewLine0],
7
- ];
8
- const wsItem = () => [
9
- [wsNoNewLineItem],
10
- str('\n'),
11
- ];
12
- export const ws0 = () => [
13
- [],
14
- [ws1],
15
- ];
16
- export const ws1 = () => [
17
- [wsItem, ws0]
18
- ];
3
+ const wsNoNewLineItem = set(' \t\r');
4
+ export const wsNoNewLine0 = repeat0Plus(wsNoNewLineItem);
5
+ const wsItem = {
6
+ wsNoNewLineItem,
7
+ n: '\n',
8
+ };
9
+ export const ws0 = () => option(ws1);
10
+ export const ws1 = [wsItem, ws0];
19
11
  //
20
- export const json = () => [
21
- [object],
22
- [array],
23
- [number],
24
- [string],
25
- str('true'),
26
- str('false'),
27
- str('null'),
28
- ];
12
+ export const json = () => ({
13
+ object,
14
+ array,
15
+ number,
16
+ string,
17
+ true: 'true',
18
+ false: 'false',
19
+ null: 'null',
20
+ });
29
21
  //
30
- const separator = () => [[cp(','), ws0]];
22
+ const separator = [',', ws0];
31
23
  // object
32
- const member = () => [[string, ws0, cp(':'), ws0, json, ws0]];
33
- const object = () => [
34
- [cp('{'), ws0, join0(member, separator), cp('}')]
35
- ];
24
+ const member = () => [string, ws0, ':', ws0, json, ws0];
25
+ const object = ['{', ws0, join0Plus(member, separator), '}'];
36
26
  // array
37
- const element = () => [
38
- [json, ws0]
39
- ];
40
- const array = () => [
41
- [cp('['), ws0, join0(element, separator), cp(']')]
42
- ];
27
+ const element = [json, ws0];
28
+ const array = ['[', ws0, join0Plus(element, separator), ']'];
43
29
  // string
44
- const character = () => [
45
- ...remove(unicode, [cp('"'), cp('\\')]),
46
- [cp('\\'), escape],
47
- ];
48
- const string = () => [[cp('"'), repeat0(character), cp('"')]];
49
- export const unicode = [0x20, 0x10FFFF];
50
- const escape = () => [
30
+ const character = () => ({
31
+ ...remove(unicode, set('"\\')),
32
+ '\\': ['\\', escape],
33
+ });
34
+ const string = ['"', repeat0Plus(character), '"'];
35
+ export const unicode = rangeEncode(0x20, 0x10FFFF);
36
+ const escape = () => ({
51
37
  ...set('"\\/bfnrt'),
52
- [cp('u'), hex, hex, hex, hex] // 117
53
- ];
54
- const hex = () => [
55
- [digit],
56
- [range('AF')],
57
- [range('af')],
58
- ];
38
+ 'u': ['u', hex, hex, hex, hex] // 117
39
+ });
40
+ const hex = () => ({
41
+ digit,
42
+ upper: range('AF'),
43
+ lower: range('af'),
44
+ });
59
45
  // number
60
- const number = () => [
61
- [uNumber],
62
- [cp('-'), uNumber],
63
- ];
64
- const uNumber = () => [
65
- [uint, fraction0, exponent0],
66
- ];
67
- const uint = () => [
68
- str('0'),
69
- [range('19'), digits0]
70
- ];
71
- export const digit = () => [[range('09')]];
72
- const digits0 = repeat0(digit);
73
- const digits1 = () => [
74
- [digit, digits0]
75
- ];
76
- const fraction0 = () => [
77
- [],
78
- [cp('.'), digits1]
79
- ];
80
- const exponent0 = () => [
81
- [],
82
- [e, sign, digits1],
83
- ];
84
- const e = () => set('eE');
85
- const sign = () => [
86
- [],
87
- [cp('+')],
88
- [cp('-')],
89
- ];
46
+ const number = () => ({
47
+ uNumber,
48
+ minus: ['-', uNumber],
49
+ });
50
+ const uNumber = () => [uint, fraction0, exponent0];
51
+ const uint = () => ({
52
+ '0': '0',
53
+ '19': [range('19'), digits0]
54
+ });
55
+ export const digit = range('09');
56
+ const digits0 = repeat0Plus(digit);
57
+ const digits1 = [digit, digits0];
58
+ const fraction0 = option(['.', digits1]);
59
+ const exponent0 = () => option([e, sign, digits1]);
60
+ const e = set('eE');
61
+ const sign = option({
62
+ '+': '+',
63
+ '-': '-',
64
+ });
package/fsc/test.f.d.ts CHANGED
@@ -1,4 +1,9 @@
1
1
  declare const _default: {
2
2
  a: () => void;
3
+ fn: () => void;
4
+ f1: () => void;
5
+ f2: () => void;
6
+ f3: () => void;
7
+ f4: () => void;
3
8
  };
4
9
  export default _default;
package/fsc/test.f.js CHANGED
@@ -1,18 +1,80 @@
1
- import * as _ from "./module.f.js";
2
- import * as ascii from "../text/ascii/module.f.js";
3
- const { one } = ascii;
4
- import * as j from "../json/module.f.js";
5
- const { stringify } = j;
1
+ import { init } from "./module.f.js";
2
+ import { one } from "../text/ascii/module.f.js";
3
+ import { stringify } from "../json/module.f.js";
6
4
  const s = stringify(i => i);
7
5
  const f = v => {
8
6
  const n = one(v);
9
- return s(_.init(n)[0]);
7
+ return s(init(n)[0]);
10
8
  };
9
+ // this doesn't change a name of the function
10
+ const fn = (f, name) => ({ [name]: f }[name]);
11
+ const withName = (name) =>
12
+ // translated into one command: define a `function [name]() { return undefined }`
13
+ Object.getOwnPropertyDescriptor({ [name]: () => undefined }, name).value;
11
14
  export default {
12
15
  a: () => {
13
16
  const x = f('1');
14
- if (x != '["1"]') {
17
+ if (x !== '["1"]') {
15
18
  throw x;
16
19
  }
20
+ },
21
+ fn: () => {
22
+ const o = {
23
+ ["hello world!"]: () => undefined
24
+ };
25
+ const f = o["hello world!"];
26
+ const { name } = f;
27
+ if (name !== "hello world!") {
28
+ throw name;
29
+ }
30
+ //
31
+ const f1 = { ["boring"]: () => undefined }["boring"];
32
+ if (f1.name !== "boring") {
33
+ throw f1.name;
34
+ }
35
+ //
36
+ const x = fn(() => undefined, "hello").name;
37
+ if (x !== "") {
38
+ throw x;
39
+ }
40
+ //
41
+ const m = withName("boring2").name;
42
+ if (m !== "boring2") {
43
+ throw m;
44
+ }
45
+ //
46
+ const a = function x() { return undefined; };
47
+ if (a.name !== "x") {
48
+ throw a.name;
49
+ }
50
+ },
51
+ //
52
+ f1: () => {
53
+ const m1 = () => undefined;
54
+ if (m1.name !== "m1") {
55
+ throw m1.name;
56
+ }
57
+ },
58
+ //
59
+ f2: () => {
60
+ const m11 = (() => undefined);
61
+ if (m11.name !== "m11") {
62
+ throw m11.name;
63
+ }
64
+ },
65
+ //
66
+ f3: () => {
67
+ const m2 = true ? () => undefined : () => undefined;
68
+ // for `bun` it is `m2`:
69
+ // if (m2.name !== "") { throw m2.name }
70
+ // see also https://github.com/oven-sh/bun/issues/20398
71
+ },
72
+ f4: () => {
73
+ const id = (i) => i;
74
+ const f = id(() => undefined);
75
+ // for `bun` it is `m2`:
76
+ if (f.name !== "") {
77
+ throw f.name;
78
+ }
17
79
  }
18
80
  };
package/fsm/module.f.js CHANGED
@@ -2,11 +2,11 @@ import { equal, isEmpty, fold, toArray, scan, foldScan, empty as emptyList } fro
2
2
  import { toRangeMap, union as byteSetUnion, one, empty, range } from "../types/byte_set/module.f.js";
3
3
  import { intersect, union as sortedSetUnion } from "../types/sorted_set/module.f.js";
4
4
  import { merge, get as rangeMapGet } from "../types/range_map/module.f.js";
5
- import { unsafeCmp } from "../types/function/compare/module.f.js";
6
5
  import { strictEqual } from "../types/function/operator/module.f.js";
7
6
  import { stringify } from "../json/module.f.js";
8
7
  import { identity } from "../types/function/module.f.js";
9
8
  import { stringToList } from "../text/utf16/module.f.js";
9
+ import { cmp } from "../types/string/module.f.js";
10
10
  const stringifyIdentity = stringify(identity);
11
11
  export const toRange = s => {
12
12
  const [b, e] = toArray(stringToList(s));
@@ -17,8 +17,8 @@ export const toUnion = s => {
17
17
  const codePoints = stringToList(s);
18
18
  return fold(toUnionOp)(empty)(codePoints);
19
19
  };
20
- const mergeOp = { union: sortedSetUnion(unsafeCmp), equal: equal(strictEqual), def: [] };
21
- const hasState = s => set => !isEmpty(intersect(unsafeCmp)([s])(set));
20
+ const mergeOp = { union: sortedSetUnion(cmp), equal: equal(strictEqual), def: [] };
21
+ const hasState = s => set => !isEmpty(intersect(cmp)([s])(set));
22
22
  const foldOp = set => ([ruleIn, bs, ruleOut]) => rm => {
23
23
  if (hasState(ruleIn)(set)) {
24
24
  return merge(mergeOp)(rm)(toRangeMap(bs)(ruleOut));
package/fsm/test.f.js CHANGED
@@ -1,24 +1,20 @@
1
- import * as _ from "./module.f.js";
2
- import * as byteSet from "../types/byte_set/module.f.js";
3
- import * as o from "../types/object/module.f.js";
4
- const { sort, fromEntries } = o;
5
- import * as json from "../json/module.f.js";
6
- import * as f from "../types/function/module.f.js";
7
- const { identity } = f;
8
- import * as list from "../types/list/module.f.js";
9
- const { toArray } = list;
10
- import * as utf16 from "../text/utf16/module.f.js";
11
- const { stringToList } = utf16;
12
- const stringifyIdentity = json.stringify(identity);
1
+ import { dfa, run, toRange, toUnion } from "./module.f.js";
2
+ import { union } from "../types/byte_set/module.f.js";
3
+ import { sort, fromEntries } from "../types/object/module.f.js";
4
+ import { stringify } from "../json/module.f.js";
5
+ import { identity } from "../types/function/module.f.js";
6
+ import { toArray } from "../types/list/module.f.js";
7
+ import { stringToList } from "../text/utf16/module.f.js";
8
+ const stringifyIdentity = stringify(identity);
13
9
  const buildDfa = () => {
14
- const lowercaseAlpha = _.toRange('az');
15
- const uppercaseAlpha = _.toRange('AZ');
16
- const alpha = byteSet.union(lowercaseAlpha)(uppercaseAlpha);
17
- const idSymbol = _.toUnion('_$');
18
- const idBegin = byteSet.union(alpha)(idSymbol);
19
- const digit = _.toRange('09');
20
- const idNext = byteSet.union(idBegin)(digit);
21
- const dot = _.toUnion('.');
10
+ const lowercaseAlpha = toRange('az');
11
+ const uppercaseAlpha = toRange('AZ');
12
+ const alpha = union(lowercaseAlpha)(uppercaseAlpha);
13
+ const idSymbol = toUnion('_$');
14
+ const idBegin = union(alpha)(idSymbol);
15
+ const digit = toRange('09');
16
+ const idNext = union(idBegin)(digit);
17
+ const dot = toUnion('.');
22
18
  const grammar = [
23
19
  ['', digit, 'int'],
24
20
  ['int', digit, 'int'],
@@ -30,7 +26,7 @@ const buildDfa = () => {
30
26
  ['', idBegin, 'id'],
31
27
  ['id', idNext, 'id']
32
28
  ];
33
- return _.dfa(grammar);
29
+ return dfa(grammar);
34
30
  };
35
31
  export default {
36
32
  dfa: () => {
@@ -83,7 +79,7 @@ export default {
83
79
  () => {
84
80
  const dfa = buildDfa();
85
81
  const input = stringToList('a1');
86
- const result = stringifyIdentity(toArray(_.run(dfa)(input)));
82
+ const result = stringifyIdentity(toArray(run(dfa)(input)));
87
83
  const expectedOutput = [
88
84
  '["id"]',
89
85
  '["id"]'
@@ -96,7 +92,7 @@ export default {
96
92
  () => {
97
93
  const dfa = buildDfa();
98
94
  const input = stringToList('0.1');
99
- const result = stringifyIdentity(toArray(_.run(dfa)(input)));
95
+ const result = stringifyIdentity(toArray(run(dfa)(input)));
100
96
  const expectedOutput = [
101
97
  '["floatBegin","int"]',
102
98
  '["floatDot"]',
@@ -110,7 +106,7 @@ export default {
110
106
  () => {
111
107
  const dfa = buildDfa();
112
108
  const input = stringToList('//');
113
- const result = stringifyIdentity(toArray(_.run(dfa)(input)));
109
+ const result = stringifyIdentity(toArray(run(dfa)(input)));
114
110
  const expectedOutput = [
115
111
  '[]',
116
112
  '[]'
@@ -123,7 +119,7 @@ export default {
123
119
  () => {
124
120
  const dfa = buildDfa();
125
121
  const input = stringToList('::');
126
- const result = stringifyIdentity(toArray(_.run(dfa)(input)));
122
+ const result = stringifyIdentity(toArray(run(dfa)(input)));
127
123
  const expectedOutput = [
128
124
  '[]',
129
125
  '[]'
package/html/module.f.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { map, flatMap, flat, concat as listConcat } from "../types/list/module.f.js";
2
- import { concat as stringConcat } from "../types/string/module.f.js";
2
+ import { concat, concat as stringConcat } from "../types/string/module.f.js";
3
3
  import { compose } from "../types/function/module.f.js";
4
4
  import { stringToList } from "../text/utf16/module.f.js";
5
5
  const { fromCharCode } = String;
@@ -25,6 +25,14 @@ const voidTagList = [
25
25
  'track',
26
26
  'wbr',
27
27
  ];
28
+ /**
29
+ * https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/script
30
+ * https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/style
31
+ */
32
+ const rawText = [
33
+ 'script',
34
+ 'style'
35
+ ];
28
36
  /**
29
37
  * https://stackoverflow.com/questions/7381974/which-characters-need-to-be-escaped-in-html
30
38
  */
@@ -40,6 +48,10 @@ const escapeCharCode = (code) => {
40
48
  const escape = compose(stringToList)(map(escapeCharCode));
41
49
  const node = (n) => typeof n === 'string' ? escape(n) : element(n);
42
50
  const nodes = flatMap(node);
51
+ const raw = (n) => typeof n === 'string' ? n : '';
52
+ const mr = map(raw);
53
+ // Escape closing tags in raw text elements
54
+ const rawMap = (n) => concat(mr(n)).replaceAll('</', '<\\/');
43
55
  const attribute = ([name, value]) => flat([[' ', name, '="'], escape(value), ['"']]);
44
56
  const attributes = compose(entries)(flatMap(attribute));
45
57
  const parseElement = (e) => {
@@ -53,9 +65,10 @@ const parseElement = (e) => {
53
65
  export const element = (e) => {
54
66
  const [tag, a, n] = parseElement(e);
55
67
  const open = flat([[`<`, tag], attributes(a), [`>`]]);
56
- return voidTagList.includes(tag) ?
57
- open :
58
- flat([open, nodes(n), ['</', tag, '>']]);
68
+ if (voidTagList.includes(tag)) {
69
+ return open;
70
+ }
71
+ return flat([open, rawText.includes(tag) ? [rawMap(n)] : nodes(n), ['</', tag, '>']]);
59
72
  };
60
73
  export const html = compose(element)(listConcat(['<!DOCTYPE html>']));
61
74
  export const htmlToString = compose(html)(stringConcat);