functionalscript 0.1.608 → 0.1.609

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 (60) 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/rust/nanocom/src/cobject.rs +1 -1
  6. package/com/test/rust/src/lib.rs +4 -4
  7. package/dev/module.mjs +1 -1
  8. package/dev/test/module.f.mjs +1 -1
  9. package/djs/parser/module.f.d.mts +51 -31
  10. package/djs/parser/module.f.mjs +275 -122
  11. package/djs/parser/test.f.d.mts +4 -0
  12. package/djs/parser/test.f.mjs +179 -63
  13. package/djs/tokenizer/module.f.d.mts +1 -1
  14. package/djs/tokenizer/module.f.mjs +3 -1
  15. package/djs/tokenizer/test.f.mjs +1 -1
  16. package/doc/LANGUAGE.md +17 -16
  17. package/doc/README.md +14 -50
  18. package/fsc/README.md +0 -3
  19. package/fsm/README.md +1 -1
  20. package/html/README.md +24 -0
  21. package/issues/01-test-debug.md +3 -0
  22. package/issues/{publish.md → 05-publish.md} +8 -8
  23. package/issues/17-djs-extension.md +6 -0
  24. package/issues/README.md +20 -13
  25. package/issues/lang/1000-json.md +38 -0
  26. package/issues/lang/2110-default-export.md +2 -2
  27. package/issues/lang/2310-undefined.md +1 -1
  28. package/issues/lang/2330-property-accessor.md +225 -0
  29. package/issues/lang/2360-built-in.md +54 -47
  30. package/issues/lang/3240-export.md +44 -0
  31. package/issues/lang/README.md +64 -22
  32. package/issues/test.f.d.mts +16 -0
  33. package/issues/test.f.mjs +57 -0
  34. package/js/tokenizer/module.f.d.mts +8 -2
  35. package/js/tokenizer/module.f.mjs +29 -3
  36. package/js/tokenizer/test.f.mjs +9 -6
  37. package/json/tokenizer/module.f.mjs +2 -1
  38. package/jsr.json +1 -1
  39. package/nanvm-lib/Cargo.toml +6 -0
  40. package/nanvm-lib/src/extension.rs +119 -0
  41. package/nanvm-lib/src/interface.rs +136 -0
  42. package/nanvm-lib/src/lib.rs +7 -0
  43. package/nanvm-lib/src/naive.rs +229 -0
  44. package/nanvm-lib/src/nanenum.rs +230 -0
  45. package/nanvm-lib/src/nullish.rs +7 -0
  46. package/nanvm-lib/src/sign.rs +5 -0
  47. package/nanvm-lib/src/simple.rs +32 -0
  48. package/nanvm-lib/tests/test.f.d.mts +36 -0
  49. package/nanvm-lib/tests/test.f.mjs +79 -0
  50. package/nanvm-lib/tests/test.rs +108 -0
  51. package/package.json +1 -1
  52. package/text/README.md +2 -2
  53. package/issues/lang/2351-property-accessor.md +0 -44
  54. package/issues/lang/2352-property-call.md +0 -43
  55. package/issues/lang/2353-property-at.md +0 -19
  56. package/issues/test-debug.md +0 -12
  57. /package/issues/{esm.md → 02-esm.md} +0 -0
  58. /package/issues/{djs.md → 03-djs.md} +0 -0
  59. /package/issues/{fs-load.md → 11-fs-load.md} +0 -0
  60. /package/issues/lang/{2330-grouping.md → 2350-grouping.md} +0 -0
@@ -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
  }
@@ -6,7 +6,7 @@ export type DjsToken = {
6
6
  readonly kind: "true" | "false" | "null";
7
7
  } | {
8
8
  readonly kind: "{" | "}" | ":" | "," | "[" | "]" | "." | "=";
9
- } | jsTokenizerT.StringToken | jsTokenizerT.NumberToken | jsTokenizerT.ErrorToken | jsTokenizerT.IdToken | jsTokenizerT.BigIntToken | jsTokenizerT.WhitespaceToken;
9
+ } | jsTokenizerT.StringToken | jsTokenizerT.NumberToken | jsTokenizerT.ErrorToken | jsTokenizerT.IdToken | jsTokenizerT.BigIntToken | jsTokenizerT.WhitespaceToken | jsTokenizerT.NewLineToken;
10
10
  export type ScanState = {
11
11
  readonly kind: "def" | "-";
12
12
  };
@@ -16,7 +16,8 @@ import jsTokenizer, * as jsTokenizerT from '../../js/tokenizer/module.f.mjs'
16
16
  * jsTokenizerT.ErrorToken |
17
17
  * jsTokenizerT.IdToken |
18
18
  * jsTokenizerT.BigIntToken |
19
- * jsTokenizerT.WhitespaceToken
19
+ * jsTokenizerT.WhitespaceToken |
20
+ * jsTokenizerT.NewLineToken
20
21
  * } DjsToken
21
22
  */
22
23
 
@@ -53,6 +54,7 @@ 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
  }
@@ -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('""'))
package/doc/LANGUAGE.md CHANGED
@@ -1,15 +1,16 @@
1
1
  # FunctionalScript Programming Language
2
2
 
3
- Principals:
4
- - FunctionalScript VM should behaves the same way as a JavaScript VM
3
+ Principles:
4
+
5
+ - FunctionalScript VM should behaves the same way as a JavaScript VM,
5
6
  - Any unsupported feature should be reported at compile-time.
6
7
 
7
8
  ## 1. Module Ecosystem
8
9
 
9
- FunctionalScript uses [CommonJS](https://en.wikipedia.org/wiki/CommonJS) conventions as a module ecosystem. For example,
10
+ FunctionalScript uses ESM conventions as a module ecosystem. For example,
10
11
 
11
12
  ```js
12
- const thirdPartyModule = require('third-party-package/module')
13
+ import thirdPartyModule from 'third-party-package/module'
13
14
 
14
15
  const result = thirdPartyModule.someFunction('hello')
15
16
  ```
@@ -39,10 +40,10 @@ npm install -S github:functionalscript/functionalscript
39
40
 
40
41
  A module is a file with the `.js` extension. It contains three parts: references to other modules, definitions, and exports. For example
41
42
 
42
- `./first.js`
43
+ `./first.f.mjs`
43
44
  ```js
44
45
  // 1. references
45
- const math = require('math')
46
+ import math from 'math'
46
47
 
47
48
  // 2. definitions
48
49
  const myConst = 42
@@ -52,35 +53,35 @@ const add42 = addition(42)
52
53
  const _10digitsOfPi = math.calculatePi(10)
53
54
 
54
55
  // 3. exports
55
- module.exports = {
56
+ export default {
56
57
  addition,
57
58
  add42,
58
59
  _10digitsOfPi,
59
60
  }
60
61
  ```
61
62
 
62
- `./second.js`
63
+ `./second.f.mjs`
63
64
  ```js
64
65
  // 1. references
65
- const first = require('./first.js')
66
+ import first from './first.f.mjs'
66
67
 
67
68
  // 2. definitions
68
69
  const _42plus7 = first.add42(7)
69
70
 
70
71
  // 3. exports
71
- module.exports = {
72
+ export default {
72
73
  _42plus7,
73
74
  }
74
75
  ```
75
76
 
76
77
  ## 4. References To Other Modules
77
78
 
78
- The format of references is `const ANYNAME = require('PATH_TO_A_MODULE')`. For example,
79
+ The format of references is `import ANYNAME from 'PATH_TO_A_MODULE'`. For example,
79
80
 
80
81
  ```js
81
- const math = require('math')
82
- const algebra = require('math/algebra')
83
- const localFile = require('../some-directory/some-file.js')
82
+ import math from 'math'
83
+ import algebra from 'math/algebra'
84
+ import localFile from '../some-directory/some-file.f.mjs'
84
85
  ```
85
86
 
86
87
  ## 5. Definitions
@@ -107,11 +108,11 @@ See [Expressions](#7-Expressions).
107
108
 
108
109
  ### 6. Exports
109
110
 
110
- The format of exports is `module.exports = { A_LIST_OF_EXPORTED_DEFINITIONS }`. There should be only one `module.exports` at
111
+ The format of exports is `export default { A_LIST_OF_EXPORTED_DEFINITIONS }`. There should be only one `export default` at
111
112
  the end of a FunctionalScript file. For example,
112
113
 
113
114
  ```js
114
- module.exports = {
115
+ export default {
115
116
  nestedStructure,
116
117
  array,
117
118
  structure,