functionalscript 0.1.608 → 0.2.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.
Files changed (222) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/Cargo.lock +4 -0
  3. package/Cargo.toml +4 -2
  4. package/README.md +1 -1
  5. package/com/cpp/module.f.d.mts +4 -8
  6. package/com/cpp/module.f.mjs +20 -25
  7. package/com/cpp/testlib.f.mjs +3 -4
  8. package/com/cs/module.f.d.mts +4 -8
  9. package/com/cs/module.f.mjs +18 -23
  10. package/com/cs/testlib.f.mjs +3 -5
  11. package/com/rust/module.f.d.mts +3 -7
  12. package/com/rust/module.f.mjs +25 -30
  13. package/com/rust/nanocom/src/cobject.rs +1 -1
  14. package/com/rust/testlib.f.mjs +3 -5
  15. package/com/test/build.f.d.mts +2 -2
  16. package/com/test/build.f.mjs +2 -2
  17. package/com/test/build.mjs +4 -4
  18. package/com/test/rust/src/lib.rs +4 -4
  19. package/com/types/module.f.d.mts +5 -10
  20. package/com/types/module.f.mjs +5 -12
  21. package/commonjs/build/module.f.d.mts +13 -17
  22. package/commonjs/build/module.f.mjs +23 -28
  23. package/commonjs/build/test.f.mjs +4 -4
  24. package/commonjs/module/function/module.f.d.mts +0 -2
  25. package/commonjs/module/function/module.f.mjs +0 -2
  26. package/commonjs/module/module.f.d.mts +16 -21
  27. package/commonjs/module/module.f.mjs +2 -9
  28. package/commonjs/module.d.mts +1 -5
  29. package/commonjs/module.f.d.mts +0 -2
  30. package/commonjs/module.f.mjs +0 -2
  31. package/commonjs/module.mjs +2 -7
  32. package/commonjs/package/dependencies/module.f.d.mts +3 -7
  33. package/commonjs/package/dependencies/module.f.mjs +5 -10
  34. package/commonjs/package/dependencies/test.f.mjs +1 -1
  35. package/commonjs/package/module.f.d.mts +12 -18
  36. package/commonjs/package/module.f.mjs +6 -13
  37. package/commonjs/package/test.f.mjs +1 -1
  38. package/commonjs/path/module.f.d.mts +25 -32
  39. package/commonjs/path/module.f.mjs +12 -23
  40. package/commonjs/path/test.f.mjs +11 -11
  41. package/commonjs/test.mjs +1 -1
  42. package/dev/module.f.d.mts +1 -4
  43. package/dev/module.f.mjs +1 -4
  44. package/dev/module.mjs +1 -1
  45. package/dev/test/module.f.d.mts +2 -3
  46. package/dev/test/module.f.mjs +5 -7
  47. package/djs/module.f.d.mts +13 -18
  48. package/djs/module.f.mjs +12 -19
  49. package/djs/parser/module.f.d.mts +53 -37
  50. package/djs/parser/module.f.mjs +278 -131
  51. package/djs/parser/test.f.d.mts +4 -0
  52. package/djs/parser/test.f.mjs +186 -70
  53. package/djs/test.f.mjs +4 -4
  54. package/djs/tokenizer/module.f.d.mts +6 -10
  55. package/djs/tokenizer/module.f.mjs +19 -22
  56. package/djs/tokenizer/test.f.mjs +7 -7
  57. package/doc/LANGUAGE.md +17 -16
  58. package/doc/README.md +14 -50
  59. package/fsc/README.md +0 -3
  60. package/fsc/module.f.d.mts +4 -9
  61. package/fsc/module.f.mjs +17 -24
  62. package/fsc/test.f.mjs +3 -3
  63. package/fsm/README.md +1 -1
  64. package/fsm/module.f.d.mts +13 -20
  65. package/fsm/module.f.mjs +27 -38
  66. package/fsm/test.f.mjs +8 -8
  67. package/html/README.md +24 -0
  68. package/html/module.f.d.mts +7 -12
  69. package/html/module.f.mjs +14 -23
  70. package/html/test.f.mjs +4 -4
  71. package/issues/01-test-debug.md +3 -0
  72. package/issues/{publish.md → 05-publish.md} +8 -8
  73. package/issues/17-djs-extension.md +6 -0
  74. package/issues/README.md +20 -13
  75. package/issues/lang/1000-json.md +38 -0
  76. package/issues/lang/2110-default-export.md +2 -2
  77. package/issues/lang/2310-undefined.md +1 -1
  78. package/issues/lang/2330-property-accessor.md +225 -0
  79. package/issues/lang/2360-built-in.md +54 -47
  80. package/issues/lang/3240-export.md +44 -0
  81. package/issues/lang/README.md +64 -22
  82. package/issues/test.f.d.mts +16 -0
  83. package/issues/test.f.mjs +57 -0
  84. package/js/tokenizer/module.f.d.mts +18 -17
  85. package/js/tokenizer/module.f.mjs +80 -61
  86. package/js/tokenizer/test.f.mjs +15 -12
  87. package/json/module.f.d.mts +18 -26
  88. package/json/module.f.mjs +18 -31
  89. package/json/parser/module.f.d.mts +9 -13
  90. package/json/parser/module.f.mjs +9 -14
  91. package/json/parser/test.f.mjs +7 -7
  92. package/json/serializer/module.f.d.mts +11 -20
  93. package/json/serializer/module.f.mjs +14 -29
  94. package/json/serializer/test.f.mjs +2 -2
  95. package/json/test.f.mjs +3 -3
  96. package/json/tokenizer/module.f.d.mts +6 -10
  97. package/json/tokenizer/module.f.mjs +16 -20
  98. package/json/tokenizer/test.f.mjs +6 -6
  99. package/jsr.json +1 -1
  100. package/nanvm-lib/Cargo.toml +6 -0
  101. package/nanvm-lib/src/extension.rs +119 -0
  102. package/nanvm-lib/src/interface.rs +136 -0
  103. package/nanvm-lib/src/lib.rs +7 -0
  104. package/nanvm-lib/src/naive.rs +229 -0
  105. package/nanvm-lib/src/nanenum.rs +230 -0
  106. package/nanvm-lib/src/nullish.rs +7 -0
  107. package/nanvm-lib/src/sign.rs +5 -0
  108. package/nanvm-lib/src/simple.rs +32 -0
  109. package/nanvm-lib/tests/test.f.d.mts +36 -0
  110. package/nanvm-lib/tests/test.f.mjs +79 -0
  111. package/nanvm-lib/tests/test.rs +108 -0
  112. package/nodejs/version/main.mjs +1 -1
  113. package/nodejs/version/module.f.d.mts +4 -9
  114. package/nodejs/version/module.f.mjs +2 -7
  115. package/nodejs/version/test.f.mjs +3 -3
  116. package/package.json +1 -1
  117. package/prime_field/module.f.d.mts +20 -23
  118. package/prime_field/module.f.mjs +9 -12
  119. package/prime_field/test.f.mjs +1 -1
  120. package/secp/module.f.d.mts +27 -28
  121. package/secp/module.f.mjs +38 -39
  122. package/secp/test.f.mjs +4 -4
  123. package/sha2/module.f.d.mts +8 -16
  124. package/sha2/module.f.mjs +7 -20
  125. package/sha2/test.f.mjs +4 -4
  126. package/text/README.md +2 -2
  127. package/text/ascii/module.f.d.mts +69 -72
  128. package/text/ascii/module.f.mjs +5 -10
  129. package/text/ascii/test.f.mjs +3 -3
  130. package/text/module.f.d.mts +9 -14
  131. package/text/module.f.mjs +7 -14
  132. package/text/sgr/module.f.d.mts +7 -9
  133. package/text/sgr/module.f.mjs +2 -4
  134. package/text/test.f.mjs +3 -3
  135. package/text/utf16/module.f.d.mts +8 -15
  136. package/text/utf16/module.f.mjs +17 -28
  137. package/text/utf16/test.f.mjs +5 -5
  138. package/text/utf8/module.f.d.mts +4 -9
  139. package/text/utf8/module.f.mjs +9 -16
  140. package/text/utf8/test.f.mjs +4 -4
  141. package/types/array/module.f.d.mts +14 -24
  142. package/types/array/module.f.mjs +8 -25
  143. package/types/array/test.f.mjs +3 -3
  144. package/types/bigfloat/module.f.d.mts +4 -9
  145. package/types/bigfloat/module.f.mjs +3 -10
  146. package/types/bigfloat/test.f.mjs +1 -1
  147. package/types/bigint/module.f.d.mts +16 -64
  148. package/types/bigint/module.f.mjs +11 -30
  149. package/types/bigint/test.f.mjs +1 -1
  150. package/types/btree/find/module.f.d.mts +20 -26
  151. package/types/btree/find/module.f.mjs +8 -17
  152. package/types/btree/find/test.f.mjs +7 -7
  153. package/types/btree/module.f.d.mts +4 -8
  154. package/types/btree/module.f.mjs +6 -11
  155. package/types/btree/remove/module.f.d.mts +7 -12
  156. package/types/btree/remove/module.f.mjs +10 -17
  157. package/types/btree/remove/test.f.mjs +5 -5
  158. package/types/btree/set/module.f.d.mts +3 -7
  159. package/types/btree/set/module.f.mjs +4 -9
  160. package/types/btree/set/test.f.mjs +4 -4
  161. package/types/btree/test.f.mjs +9 -9
  162. package/types/btree/types/module.f.d.mts +0 -2
  163. package/types/btree/types/module.f.mjs +0 -2
  164. package/types/byte_set/module.f.d.mts +16 -29
  165. package/types/byte_set/module.f.mjs +14 -39
  166. package/types/byte_set/test.f.mjs +5 -5
  167. package/types/function/compare/module.f.d.mts +9 -15
  168. package/types/function/compare/module.f.mjs +3 -12
  169. package/types/function/compare/test.f.mjs +1 -1
  170. package/types/function/module.f.d.mts +20 -27
  171. package/types/function/module.f.mjs +4 -15
  172. package/types/function/operator/module.f.d.mts +28 -43
  173. package/types/function/operator/module.f.mjs +14 -41
  174. package/types/function/test.f.mjs +1 -1
  175. package/types/list/module.f.d.mts +56 -91
  176. package/types/list/module.f.mjs +45 -114
  177. package/types/list/test.f.mjs +10 -10
  178. package/types/map/module.f.d.mts +15 -24
  179. package/types/map/module.f.mjs +15 -30
  180. package/types/map/test.f.mjs +2 -2
  181. package/types/nibble_set/module.f.d.mts +10 -20
  182. package/types/nibble_set/module.f.mjs +7 -24
  183. package/types/nibble_set/test.f.mjs +2 -2
  184. package/types/nullable/module.f.d.mts +3 -8
  185. package/types/nullable/module.f.mjs +2 -9
  186. package/types/nullable/test.f.mjs +1 -1
  187. package/types/number/module.f.d.mts +7 -13
  188. package/types/number/module.f.mjs +8 -19
  189. package/types/number/test.f.mjs +1 -1
  190. package/types/object/module.f.d.mts +11 -18
  191. package/types/object/module.f.mjs +9 -20
  192. package/types/object/test.f.mjs +1 -1
  193. package/types/range/module.f.d.mts +3 -8
  194. package/types/range/module.f.mjs +2 -9
  195. package/types/range/test.f.mjs +1 -1
  196. package/types/range_map/module.f.d.mts +9 -15
  197. package/types/range_map/module.f.mjs +9 -18
  198. package/types/range_map/test.f.mjs +32 -32
  199. package/types/result/module.d.mts +3 -3
  200. package/types/result/module.f.d.mts +6 -12
  201. package/types/result/module.f.mjs +3 -12
  202. package/types/result/module.mjs +2 -2
  203. package/types/sorted_list/module.f.d.mts +22 -28
  204. package/types/sorted_list/module.f.mjs +10 -19
  205. package/types/sorted_list/test.f.mjs +7 -7
  206. package/types/sorted_set/module.f.d.mts +6 -12
  207. package/types/sorted_set/module.f.mjs +7 -16
  208. package/types/sorted_set/test.f.mjs +7 -7
  209. package/types/string/module.f.d.mts +8 -14
  210. package/types/string/module.f.mjs +10 -21
  211. package/types/string/test.f.mjs +2 -2
  212. package/types/string_set/module.f.d.mts +8 -16
  213. package/types/string_set/module.f.mjs +12 -27
  214. package/types/string_set/test.f.mjs +1 -1
  215. package/issues/lang/2351-property-accessor.md +0 -44
  216. package/issues/lang/2352-property-call.md +0 -43
  217. package/issues/lang/2353-property-at.md +0 -19
  218. package/issues/test-debug.md +0 -12
  219. /package/issues/{esm.md → 02-esm.md} +0 -0
  220. /package/issues/{djs.md → 03-djs.md} +0 -0
  221. /package/issues/{fs-load.md → 11-fs-load.md} +0 -0
  222. /package/issues/lang/{2330-grouping.md → 2350-grouping.md} +0 -0
@@ -1,13 +1,13 @@
1
- import parser from './module.f.mjs'
2
- import tokenizer, * as tokenizerT from '../tokenizer/module.f.mjs'
3
- import list from '../../types/list/module.f.mjs'
1
+ import * as parser from './module.f.mjs'
2
+ import * as tokenizer from '../tokenizer/module.f.mjs'
3
+ import * as list from '../../types/list/module.f.mjs'
4
4
  const { toArray } = list
5
- import djs from '../module.f.mjs'
6
- import o from '../../types/object/module.f.mjs'
5
+ import * as djs from '../module.f.mjs'
6
+ import * as o from '../../types/object/module.f.mjs'
7
7
  const { sort } = o
8
- import encoding from '../../text/utf16/module.f.mjs'
8
+ import * as encoding from '../../text/utf16/module.f.mjs'
9
9
 
10
- /** @type {(s: string) => readonly tokenizerT.DjsToken[]} */
10
+ /** @type {(s: string) => readonly tokenizer.DjsToken[]} */
11
11
  const tokenizeString = s => toArray(tokenizer.tokenize(encoding.stringToList(s)))
12
12
 
13
13
  const stringify = djs.stringify(sort)
@@ -15,243 +15,243 @@ const stringify = djs.stringify(sort)
15
15
  export default {
16
16
  valid: [
17
17
  () => {
18
- const tokenList = tokenizeString('module.exports=null')
18
+ const tokenList = tokenizeString('export default null')
19
19
  const obj = parser.parse(tokenList)
20
20
  const result = stringify(obj)
21
- if (result !== '["ok",null]') { throw result }
21
+ if (result !== '["ok",[[],[null]]]') { throw result }
22
22
  },
23
23
  () => {
24
- const tokenList = tokenizeString('module.exports=true')
24
+ const tokenList = tokenizeString('export default true')
25
25
  const obj = parser.parse(tokenList)
26
26
  const result = stringify(obj)
27
- if (result !== '["ok",true]') { throw result }
27
+ if (result !== '["ok",[[],[true]]]') { throw result }
28
28
  },
29
29
  () => {
30
- const tokenList = tokenizeString('module.exports=false')
30
+ const tokenList = tokenizeString('export default false')
31
31
  const obj = parser.parse(tokenList)
32
32
  const result = stringify(obj)
33
- if (result !== '["ok",false]') { throw result }
33
+ if (result !== '["ok",[[],[false]]]') { throw result }
34
34
  },
35
35
  () => {
36
- const tokenList = tokenizeString('module.exports=0.1')
36
+ const tokenList = tokenizeString('export default 0.1')
37
37
  const obj = parser.parse(tokenList)
38
38
  const result = stringify(obj)
39
- if (result !== '["ok",0.1]') { throw result }
39
+ if (result !== '["ok",[[],[0.1]]]') { throw result }
40
40
  },
41
41
  () => {
42
- const tokenList = tokenizeString('module.exports=1.1e+2')
42
+ const tokenList = tokenizeString('export default 1.1e+2')
43
43
  const obj = parser.parse(tokenList)
44
44
  const result = stringify(obj)
45
- if (result !== '["ok",110]') { throw result }
45
+ if (result !== '["ok",[[],[110]]]') { throw result }
46
46
  },
47
47
  () => {
48
- const tokenList = tokenizeString('module.exports="abc"')
48
+ const tokenList = tokenizeString('export default "abc"')
49
49
  const obj = parser.parse(tokenList)
50
50
  const result = stringify(obj)
51
- if (result !== '["ok","abc"]') { throw result }
51
+ if (result !== '["ok",[[],["abc"]]]') { throw result }
52
52
  },
53
53
  () => {
54
- const tokenList = tokenizeString('module.exports=[]')
54
+ const tokenList = tokenizeString('export default []')
55
55
  const obj = parser.parse(tokenList)
56
56
  const result = stringify(obj)
57
- if (result !== '["ok",[]]') { throw result }
57
+ if (result !== '["ok",[[],[["array",[]]]]]') { throw result }
58
58
  },
59
59
  () => {
60
- const tokenList = tokenizeString('module.exports=[1]')
60
+ const tokenList = tokenizeString('export default [1]')
61
61
  const obj = parser.parse(tokenList)
62
62
  const result = stringify(obj)
63
- if (result !== '["ok",[1]]') { throw result }
63
+ if (result !== '["ok",[[],[["array",[1]]]]]') { throw result }
64
64
  },
65
65
  () => {
66
- const tokenList = tokenizeString('module.exports=[[]]')
66
+ const tokenList = tokenizeString('export default [[]]')
67
67
  const obj = parser.parse(tokenList)
68
68
  const result = stringify(obj)
69
- if (result !== '["ok",[[]]]') { throw result }
69
+ if (result !== '["ok",[[],[["array",[["array",[]]]]]]]') { throw result }
70
70
  },
71
71
  () => {
72
- const tokenList = tokenizeString('module.exports=[0,[1,[2,[]]],3]')
72
+ const tokenList = tokenizeString('export default [0,[1,[2,[]]],3]')
73
73
  const obj = parser.parse(tokenList)
74
74
  const result = stringify(obj)
75
- if (result !== '["ok",[0,[1,[2,[]]],3]]') { throw result }
75
+ if (result !== '["ok",[[],[["array",[0,["array",[1,["array",[2,["array",[]]]]]],3]]]]]') { throw result }
76
76
  },
77
77
  () => {
78
- const tokenList = tokenizeString('module.exports={}')
78
+ const tokenList = tokenizeString('export default {}')
79
79
  const obj = parser.parse(tokenList)
80
80
  const result = stringify(obj)
81
- if (result !== '["ok",{}]') { throw result }
81
+ if (result !== '["ok",[[],[{}]]]') { throw result }
82
82
  },
83
83
  () => {
84
- const tokenList = tokenizeString('module.exports=[{}]')
84
+ const tokenList = tokenizeString('export default [{}]')
85
85
  const obj = parser.parse(tokenList)
86
86
  const result = stringify(obj)
87
- if (result !== '["ok",[{}]]') { throw result }
87
+ if (result !== '["ok",[[],[["array",[{}]]]]]') { throw result }
88
88
  },
89
89
  () => {
90
- const tokenList = tokenizeString('module.exports={"a":true,"b":false,"c":null}')
90
+ const tokenList = tokenizeString('export default {"a":true,"b":false,"c":null}')
91
91
  const obj = parser.parse(tokenList)
92
92
  const result = stringify(obj)
93
- if (result !== '["ok",{"a":true,"b":false,"c":null}]') { throw result }
93
+ if (result !== '["ok",[[],[{"a":true,"b":false,"c":null}]]]') { throw result }
94
94
  },
95
95
  () => {
96
- const tokenList = tokenizeString('module.exports={"a":{"b":{"c":["d"]}}}')
96
+ const tokenList = tokenizeString('export default {"a":{"b":{"c":["d"]}}}')
97
97
  const obj = parser.parse(tokenList)
98
98
  const result = stringify(obj)
99
- if (result !== '["ok",{"a":{"b":{"c":["d"]}}}]') { throw result }
99
+ if (result !== '["ok",[[],[{"a":{"b":{"c":["array",["d"]]}}}]]]') { throw result }
100
100
  },
101
101
  () => {
102
- const tokenList = tokenizeString('module.exports=1234567890n')
102
+ const tokenList = tokenizeString('export default 1234567890n')
103
103
  const obj = parser.parse(tokenList)
104
104
  const result = stringify(obj)
105
- if (result !== '["ok",1234567890n]') { throw result }
105
+ if (result !== '["ok",[[],[1234567890n]]]') { throw result }
106
106
  },
107
107
  () => {
108
- const tokenList = tokenizeString('module.exports=[1234567890n]')
108
+ const tokenList = tokenizeString('export default [1234567890n]')
109
109
  const obj = parser.parse(tokenList)
110
110
  const result = stringify(obj)
111
- if (result !== '["ok",[1234567890n]]') { throw result }
111
+ if (result !== '["ok",[[],[["array",[1234567890n]]]]]') { throw result }
112
112
  }
113
113
  ],
114
114
  invalid: [
115
115
  () => {
116
- const tokenList = tokenizeString('module.exports=')
116
+ const tokenList = tokenizeString('export default')
117
117
  const obj = parser.parse(tokenList)
118
118
  const result = stringify(obj)
119
119
  if (result !== '["error","unexpected end"]') { throw result }
120
120
  },
121
121
  () => {
122
- const tokenList = tokenizeString('module.exports="123')
122
+ const tokenList = tokenizeString('export default "123')
123
123
  const obj = parser.parse(tokenList)
124
124
  const result = stringify(obj)
125
125
  if (result !== '["error","unexpected token"]') { throw result }
126
126
  },
127
127
  () => {
128
- const tokenList = tokenizeString('module.exports=[,]')
128
+ const tokenList = tokenizeString('export default [,]')
129
129
  const obj = parser.parse(tokenList)
130
130
  const result = stringify(obj)
131
131
  if (result !== '["error","unexpected token"]') { throw result }
132
132
  },
133
133
  () => {
134
- const tokenList = tokenizeString('module.exports=[1 2]')
134
+ const tokenList = tokenizeString('export default [1 2]')
135
135
  const obj = parser.parse(tokenList)
136
136
  const result = stringify(obj)
137
137
  if (result !== '["error","unexpected token"]') { throw result }
138
138
  },
139
139
  () => {
140
- const tokenList = tokenizeString('module.exports=[1,,2]')
140
+ const tokenList = tokenizeString('export default [1,,2]')
141
141
  const obj = parser.parse(tokenList)
142
142
  const result = stringify(obj)
143
143
  if (result !== '["error","unexpected token"]') { throw result }
144
144
  },
145
145
  () => {
146
- const tokenList = tokenizeString('module.exports=[]]')
146
+ const tokenList = tokenizeString('export default []]')
147
147
  const obj = parser.parse(tokenList)
148
148
  const result = stringify(obj)
149
149
  if (result !== '["error","unexpected token"]') { throw result }
150
150
  },
151
151
  () => {
152
- const tokenList = tokenizeString('module.exports=["a"')
152
+ const tokenList = tokenizeString('export default ["a"')
153
153
  const obj = parser.parse(tokenList)
154
154
  const result = stringify(obj)
155
155
  if (result !== '["error","unexpected end"]') { throw result }
156
156
  },
157
157
  () => {
158
- const tokenList = tokenizeString('module.exports=[1,]')
158
+ const tokenList = tokenizeString('export default [1,]')
159
159
  const obj = parser.parse(tokenList)
160
160
  const result = stringify(obj)
161
161
  if (result !== '["error","unexpected token"]') { throw result }
162
162
  },
163
163
  () => {
164
- const tokenList = tokenizeString('module.exports=[,1]')
164
+ const tokenList = tokenizeString('export default [,1]')
165
165
  const obj = parser.parse(tokenList)
166
166
  const result = stringify(obj)
167
167
  if (result !== '["error","unexpected token"]') { throw result }
168
168
  },
169
169
  () => {
170
- const tokenList = tokenizeString('module.exports=[:]')
170
+ const tokenList = tokenizeString('export default [:]')
171
171
  const obj = parser.parse(tokenList)
172
172
  const result = stringify(obj)
173
173
  if (result !== '["error","unexpected token"]') { throw result }
174
174
  },
175
175
  () => {
176
- const tokenList = tokenizeString('module.exports=]')
176
+ const tokenList = tokenizeString('export default ]')
177
177
  const obj = parser.parse(tokenList)
178
178
  const result = stringify(obj)
179
179
  if (result !== '["error","unexpected token"]') { throw result }
180
180
  },
181
181
  () => {
182
- const tokenList = tokenizeString('module.exports={,}')
182
+ const tokenList = tokenizeString('export default {,}')
183
183
  const obj = parser.parse(tokenList)
184
184
  const result = stringify(obj)
185
185
  if (result !== '["error","unexpected token"]') { throw result }
186
186
  },
187
187
  () => {
188
- const tokenList = tokenizeString('module.exports={1:2}')
188
+ const tokenList = tokenizeString('export default {1:2}')
189
189
  const obj = parser.parse(tokenList)
190
190
  const result = stringify(obj)
191
191
  if (result !== '["error","unexpected token"]') { throw result }
192
192
  },
193
193
  () => {
194
- const tokenList = tokenizeString('module.exports={"1"2}')
194
+ const tokenList = tokenizeString('export default {"1"2}')
195
195
  const obj = parser.parse(tokenList)
196
196
  const result = stringify(obj)
197
197
  if (result !== '["error","unexpected token"]') { throw result }
198
198
  },
199
199
  () => {
200
- const tokenList = tokenizeString('module.exports={"1"::2}')
200
+ const tokenList = tokenizeString('export default {"1"::2}')
201
201
  const obj = parser.parse(tokenList)
202
202
  const result = stringify(obj)
203
203
  if (result !== '["error","unexpected token"]') { throw result }
204
204
  },
205
205
  () => {
206
- const tokenList = tokenizeString('module.exports={"1":2,,"3":4')
206
+ const tokenList = tokenizeString('export default {"1":2,,"3":4')
207
207
  const obj = parser.parse(tokenList)
208
208
  const result = stringify(obj)
209
209
  if (result !== '["error","unexpected token"]') { throw result }
210
210
  },
211
211
  () => {
212
- const tokenList = tokenizeString('module.exports={}}')
212
+ const tokenList = tokenizeString('export default {}}')
213
213
  const obj = parser.parse(tokenList)
214
214
  const result = stringify(obj)
215
215
  if (result !== '["error","unexpected token"]') { throw result }
216
216
  },
217
217
  () => {
218
- const tokenList = tokenizeString('module.exports={"1":2')
218
+ const tokenList = tokenizeString('export default {"1":2')
219
219
  const obj = parser.parse(tokenList)
220
220
  const result = stringify(obj)
221
221
  if (result !== '["error","unexpected end"]') { throw result }
222
222
  },
223
223
  () => {
224
- const tokenList = tokenizeString('module.exports={"1":2,}')
224
+ const tokenList = tokenizeString('export default {"1":2,}')
225
225
  const obj = parser.parse(tokenList)
226
226
  const result = stringify(obj)
227
227
  if (result !== '["error","unexpected token"]') { throw result }
228
228
  },
229
229
  () => {
230
- const tokenList = tokenizeString('module.exports={,"1":2}')
230
+ const tokenList = tokenizeString('export default {,"1":2}')
231
231
  const obj = parser.parse(tokenList)
232
232
  const result = stringify(obj)
233
233
  if (result !== '["error","unexpected token"]') { throw result }
234
234
  },
235
235
  () => {
236
- const tokenList = tokenizeString('module.exports=}')
236
+ const tokenList = tokenizeString('export default }')
237
237
  const obj = parser.parse(tokenList)
238
238
  const result = stringify(obj)
239
239
  if (result !== '["error","unexpected token"]') { throw result }
240
240
  },
241
241
  () => {
242
- const tokenList = tokenizeString('module.exports=[{]}')
242
+ const tokenList = tokenizeString('export default [{]}')
243
243
  const obj = parser.parse(tokenList)
244
244
  const result = stringify(obj)
245
245
  if (result !== '["error","unexpected token"]') { throw result }
246
246
  },
247
247
  () => {
248
- const tokenList = tokenizeString('module.exports={[}]')
248
+ const tokenList = tokenizeString('export default {[}]')
249
249
  const obj = parser.parse(tokenList)
250
250
  const result = stringify(obj)
251
251
  if (result !== '["error","unexpected token"]') { throw result }
252
252
  },
253
253
  () => {
254
- const tokenList = tokenizeString('module.exports=10-5')
254
+ const tokenList = tokenizeString('export default 10-5')
255
255
  const obj = parser.parse(tokenList)
256
256
  const result = stringify(obj)
257
257
  if (result !== '["error","unexpected token"]') { throw result }
@@ -259,24 +259,24 @@ export default {
259
259
  ],
260
260
  validWhiteSpaces:[
261
261
  () => {
262
- const tokenList = tokenizeString('module.exports=[ 0 , 1 , 2 ]')
262
+ const tokenList = tokenizeString('export default [ 0 , 1 , 2 ]')
263
263
  const obj = parser.parse(tokenList)
264
264
  const result = stringify(obj)
265
- if (result !== '["ok",[0,1,2]]') { throw result }
265
+ if (result !== '["ok",[[],[["array",[0,1,2]]]]]') { throw result }
266
266
  },
267
267
  () => {
268
- const tokenList = tokenizeString('module.exports={ "a" : 0 , "b" : 1 }')
268
+ const tokenList = tokenizeString('export default { "a" : 0 , "b" : 1 }')
269
269
  const obj = parser.parse(tokenList)
270
270
  const result = stringify(obj)
271
- if (result !== '["ok",{"a":0,"b":1}]') { throw result }
271
+ if (result !== '["ok",[[],[{"a":0,"b":1}]]]') { throw result }
272
272
  },
273
273
  ],
274
274
  validModule:[
275
275
  () => {
276
- const tokenList = tokenizeString('module.exports = null')
276
+ const tokenList = tokenizeString('export default null')
277
277
  const obj = parser.parse(tokenList)
278
278
  const result = stringify(obj)
279
- if (result !== '["ok",null]') { throw result }
279
+ if (result !== '["ok",[[],[null]]]') { throw result }
280
280
  },
281
281
  ],
282
282
  invalidModule:[
@@ -292,5 +292,121 @@ export default {
292
292
  const result = stringify(obj)
293
293
  if (result !== '["error","unexpected token"]') { throw result }
294
294
  },
295
- ]
295
+ () => {
296
+ const tokenList = tokenizeString('export null')
297
+ const obj = parser.parse(tokenList)
298
+ const result = stringify(obj)
299
+ if (result !== '["error","unexpected token"]') { throw result }
300
+ },
301
+ () => {
302
+ const tokenList = tokenizeString('export default = null')
303
+ const obj = parser.parse(tokenList)
304
+ const result = stringify(obj)
305
+ if (result !== '["error","unexpected token"]') { throw result }
306
+ },
307
+ ],
308
+ validWithConst:[
309
+ () => {
310
+ const tokenList = tokenizeString('const a = 1 \n const b = 2 \n export default 3')
311
+ const obj = parser.parse(tokenList)
312
+ const result = stringify(obj)
313
+ if (result !== '["ok",[[],[1,2,3]]]') { throw result }
314
+ },
315
+ () => {
316
+ const tokenList = tokenizeString('const a = 1 \n const b = 2 \n export default b')
317
+ const obj = parser.parse(tokenList)
318
+ const result = stringify(obj)
319
+ if (result !== '["ok",[[],[1,2,["cref",1]]]]') { throw result }
320
+ },
321
+ () => {
322
+ const tokenList = tokenizeString('const a = 1 \n const b = 2 \n export default [b,a,b]')
323
+ const obj = parser.parse(tokenList)
324
+ const result = stringify(obj)
325
+ if (result !== '["ok",[[],[1,2,["array",[["cref",1],["cref",0],["cref",1]]]]]]') { throw result }
326
+ },
327
+ () => {
328
+ const tokenList = tokenizeString('const a = 1 \n const b = 2 \n export default {"1st":b,"2nd":a,"3rd":b}')
329
+ const obj = parser.parse(tokenList)
330
+ const result = stringify(obj)
331
+ if (result !== '["ok",[[],[1,2,{"1st":["cref",1],"2nd":["cref",0],"3rd":["cref",1]}]]]') { throw result }
332
+ },
333
+ ],
334
+ invalidWithConst:[
335
+ () => {
336
+ const tokenList = tokenizeString('const a = 1 const b = 2 export default 3')
337
+ const obj = parser.parse(tokenList)
338
+ const result = stringify(obj)
339
+ if (result !== '["error","unexpected token"]') { throw result }
340
+ },
341
+ () => {
342
+ const tokenList = tokenizeString('const = 1 \n const b = 2 \n export default 3')
343
+ const obj = parser.parse(tokenList)
344
+ const result = stringify(obj)
345
+ if (result !== '["error","unexpected token"]') { throw result }
346
+ },
347
+ () => {
348
+ const tokenList = tokenizeString('const a = 1 \n const a = 2 \n export default 3')
349
+ const obj = parser.parse(tokenList)
350
+ const result = stringify(obj)
351
+ if (result !== '["error","duplicate id"]') { throw result }
352
+ },
353
+ ],
354
+ validWithArgs:[
355
+ () => {
356
+ const tokenList = tokenizeString('import a from "test/test.f.mjs" \n export default a')
357
+ const obj = parser.parse(tokenList)
358
+ const result = stringify(obj)
359
+ if (result !== '["ok",[["test/test.f.mjs"],[["aref",0]]]]') { throw result }
360
+ },
361
+ () => {
362
+ const tokenList = tokenizeString('import a from "first/test.f.mjs" \n import b from "second/test.f.mjs" \n export default [b, a, b]')
363
+ const obj = parser.parse(tokenList)
364
+ const result = stringify(obj)
365
+ if (result !== '["ok",[["first/test.f.mjs","second/test.f.mjs"],[["array",[["aref",1],["aref",0],["aref",1]]]]]]') { throw result }
366
+ },
367
+ () => {
368
+ const tokenList = tokenizeString('import a from "test/test.f.mjs" \n const b = null \n export default [b, a, b]')
369
+ const obj = parser.parse(tokenList)
370
+ const result = stringify(obj)
371
+ if (result !== '["ok",[["test/test.f.mjs"],[null,["array",[["cref",0],["aref",0],["cref",0]]]]]]') { throw result }
372
+ },
373
+ ],
374
+ invalidWithArgs:[
375
+ () => {
376
+ const tokenList = tokenizeString('import a from "test/test.f.mjs" export default a')
377
+ const obj = parser.parse(tokenList)
378
+ const result = stringify(obj)
379
+ if (result !== '["error","unexpected token"]') { throw result }
380
+ },
381
+ () => {
382
+ const tokenList = tokenizeString('import a from \n export default a')
383
+ const obj = parser.parse(tokenList)
384
+ const result = stringify(obj)
385
+ if (result !== '["error","unexpected token"]') { throw result }
386
+ },
387
+ () => {
388
+ const tokenList = tokenizeString('import a "test/test.f.mjs" \n export default a')
389
+ const obj = parser.parse(tokenList)
390
+ const result = stringify(obj)
391
+ if (result !== '["error","unexpected token"]') { throw result }
392
+ },
393
+ () => {
394
+ const tokenList = tokenizeString('import from "test/test.f.mjs" \n export default a')
395
+ const obj = parser.parse(tokenList)
396
+ const result = stringify(obj)
397
+ if (result !== '["error","unexpected token"]') { throw result }
398
+ },
399
+ () => {
400
+ const tokenList = tokenizeString('import a from "first/test.f.mjs" \n import a from "second/test.f.mjs" \n export default [b, a, b]')
401
+ const obj = parser.parse(tokenList)
402
+ const result = stringify(obj)
403
+ if (result !== '["error","duplicate id"]') { throw result }
404
+ },
405
+ () => {
406
+ const tokenList = tokenizeString('import a from "test/test.f.mjs" \n const a = null \n export default null')
407
+ const obj = parser.parse(tokenList)
408
+ const result = stringify(obj)
409
+ if (result !== '["error","duplicate id"]') { throw result }
410
+ },
411
+ ],
296
412
  }
package/djs/test.f.mjs CHANGED
@@ -1,9 +1,9 @@
1
- import json from '../json/module.f.mjs'
2
- import list from '../types/object/module.f.mjs'
1
+ import * as json from '../json/module.f.mjs'
2
+ import * as list from '../types/object/module.f.mjs'
3
3
  const { sort } = list
4
- import f from '../types/function/module.f.mjs'
4
+ import * as f from '../types/function/module.f.mjs'
5
5
  const { identity } = f
6
- import djs from './module.f.mjs'
6
+ import * as djs from './module.f.mjs'
7
7
 
8
8
  export default {
9
9
  stringify: [
@@ -1,17 +1,13 @@
1
- declare namespace _default {
2
- export { tokenize };
3
- }
4
- export default _default;
1
+ /** @type {(input: list.List<number>) => list.List<DjsToken>} */
2
+ export const tokenize: (input: list.List<number>) => list.List<DjsToken>;
5
3
  export type DjsToken = {
6
4
  readonly kind: "true" | "false" | "null";
7
5
  } | {
8
6
  readonly kind: "{" | "}" | ":" | "," | "[" | "]" | "." | "=";
9
- } | jsTokenizerT.StringToken | jsTokenizerT.NumberToken | jsTokenizerT.ErrorToken | jsTokenizerT.IdToken | jsTokenizerT.BigIntToken | jsTokenizerT.WhitespaceToken;
7
+ } | jsTokenizer.StringToken | jsTokenizer.NumberToken | jsTokenizer.ErrorToken | jsTokenizer.IdToken | jsTokenizer.BigIntToken | jsTokenizer.WhitespaceToken | jsTokenizer.NewLineToken;
10
8
  export type ScanState = {
11
9
  readonly kind: "def" | "-";
12
10
  };
13
- export type ScanInput = jsTokenizerT.JsToken | null;
14
- /** @type {(input: List.List<number>) => List.List<DjsToken>} */
15
- declare const tokenize: (input: List.List<number>) => List.List<DjsToken>;
16
- import * as jsTokenizerT from '../../js/tokenizer/module.f.mjs';
17
- import * as List from '../../types/list/module.f.mjs';
11
+ export type ScanInput = jsTokenizer.JsToken | null;
12
+ import * as list from '../../types/list/module.f.mjs';
13
+ import * as jsTokenizer from '../../js/tokenizer/module.f.mjs';
@@ -1,22 +1,23 @@
1
1
  // @ts-self-types="./module.f.d.mts"
2
2
 
3
3
  import * as Operator from '../../types/function/operator/module.f.mjs'
4
- import list, * as List from '../../types/list/module.f.mjs'
4
+ import * as list from '../../types/list/module.f.mjs'
5
5
  const { empty, flat, stateScan } = list
6
- import bf from '../../types/bigfloat/module.f.mjs'
6
+ import * as bf from '../../types/bigfloat/module.f.mjs'
7
7
  const { multiply } = bf
8
- import jsTokenizer, * as jsTokenizerT from '../../js/tokenizer/module.f.mjs'
8
+ import * as jsTokenizer from '../../js/tokenizer/module.f.mjs'
9
9
 
10
10
  /**
11
11
  * @typedef {|
12
12
  * {readonly kind: 'true' | 'false' | 'null'} |
13
13
  * {readonly kind: '{' | '}' | ':' | ',' | '[' | ']' | '.' | '=' } |
14
- * jsTokenizerT.StringToken |
15
- * jsTokenizerT.NumberToken |
16
- * jsTokenizerT.ErrorToken |
17
- * jsTokenizerT.IdToken |
18
- * jsTokenizerT.BigIntToken |
19
- * jsTokenizerT.WhitespaceToken
14
+ * jsTokenizer.StringToken |
15
+ * jsTokenizer.NumberToken |
16
+ * jsTokenizer.ErrorToken |
17
+ * jsTokenizer.IdToken |
18
+ * jsTokenizer.BigIntToken |
19
+ * jsTokenizer.WhitespaceToken |
20
+ * jsTokenizer.NewLineToken
20
21
  * } DjsToken
21
22
  */
22
23
 
@@ -28,11 +29,11 @@ import jsTokenizer, * as jsTokenizerT from '../../js/tokenizer/module.f.mjs'
28
29
 
29
30
  /**
30
31
  * @typedef {|
31
- * jsTokenizerT.JsToken | null
32
+ * jsTokenizer.JsToken | null
32
33
  * } ScanInput
33
34
  */
34
35
 
35
- /** @type {(input: jsTokenizerT.JsToken) => List.List<DjsToken>} */
36
+ /** @type {(input: jsTokenizer.JsToken) => list.List<DjsToken>} */
36
37
  const mapToken = input =>
37
38
  {
38
39
  switch(input.kind)
@@ -53,12 +54,13 @@ const mapToken = input =>
53
54
  case 'string':
54
55
  case 'number':
55
56
  case 'ws':
57
+ case 'nl':
56
58
  case 'error': return [input]
57
59
  default: return jsTokenizer.isKeywordToken(input) ? [{ kind: 'id', value: input.kind }] : [{ kind: 'error', message: 'invalid token' }]
58
60
  }
59
61
  }
60
62
 
61
- /** @type {(input: ScanInput) => readonly [List.List<DjsToken>, ScanState]} */
63
+ /** @type {(input: ScanInput) => readonly [list.List<DjsToken>, ScanState]} */
62
64
  const parseDefaultState = input =>
63
65
  {
64
66
  if (input === null) return [empty, { kind: 'def'}]
@@ -69,7 +71,7 @@ const parseDefaultState = input =>
69
71
  }
70
72
  }
71
73
 
72
- /** @type {(input: ScanInput) => readonly [List.List<DjsToken>, ScanState]} */
74
+ /** @type {(input: ScanInput) => readonly [list.List<DjsToken>, ScanState]} */
73
75
  const parseMinusState = input =>
74
76
  {
75
77
  if (input === null) return [[{ kind: 'error', message: 'invalid token' }], { kind: 'def'}]
@@ -82,7 +84,7 @@ const parseMinusState = input =>
82
84
  }
83
85
  }
84
86
 
85
- /** @type {Operator.StateScan<ScanInput, ScanState, List.List<DjsToken>>} */
87
+ /** @type {Operator.StateScan<ScanInput, ScanState, list.List<DjsToken>>} */
86
88
  const scanToken = state => input => {
87
89
  switch(state.kind)
88
90
  {
@@ -91,15 +93,10 @@ const scanToken = state => input => {
91
93
  }
92
94
  }
93
95
 
94
- /** @type {(input: List.List<number>) => List.List<DjsToken>} */
95
- const tokenize = input =>
96
+ /** @type {(input: list.List<number>) => list.List<DjsToken>} */
97
+ export const tokenize = input =>
96
98
  {
97
- /** @type {List.List<ScanInput>} */
99
+ /** @type {list.List<ScanInput>} */
98
100
  const jsTokens = jsTokenizer.tokenize(input)
99
101
  return flat(stateScan(scanToken)({ kind: 'def' })(list.concat(jsTokens)([null])))
100
102
  }
101
-
102
- export default {
103
- /** @readonly */
104
- tokenize
105
- }
@@ -1,12 +1,12 @@
1
- import tokenizer, * as tokenizerT from './module.f.mjs'
2
- import list from '../../types/list/module.f.mjs'
1
+ import * as tokenizer from './module.f.mjs'
2
+ import * as list from '../../types/list/module.f.mjs'
3
3
  const { toArray } = list
4
- import djs from '../module.f.mjs'
5
- import o from '../../types/object/module.f.mjs'
4
+ import * as djs from '../module.f.mjs'
5
+ import * as o from '../../types/object/module.f.mjs'
6
6
  const { sort } = o
7
- import encoding from '../../text/utf16/module.f.mjs'
7
+ import * as encoding from '../../text/utf16/module.f.mjs'
8
8
 
9
- /** @type {(s: string) => readonly tokenizerT.DjsToken[]} */
9
+ /** @type {(s: string) => readonly tokenizer.DjsToken[]} */
10
10
  const tokenizeString = s => toArray(tokenizer.tokenize(encoding.stringToList(s)))
11
11
 
12
12
  const stringify = djs.stringify(sort)
@@ -47,7 +47,7 @@ export default {
47
47
  },
48
48
  () => {
49
49
  const result = stringify(tokenizeString('{ \t\n\r}'))
50
- if (result !== '[{"kind":"{"},{"kind":"ws"},{"kind":"}"}]') { throw result }
50
+ if (result !== '[{"kind":"{"},{"kind":"nl"},{"kind":"}"}]') { throw result }
51
51
  },
52
52
  () => {
53
53
  const result = stringify(tokenizeString('""'))