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,51 +1,36 @@
1
1
  // @ts-self-types="./module.f.d.mts"
2
2
  import * as BtreeTypes from '../btree/types/module.f.mjs'
3
- import btree from '../btree/module.f.mjs'
4
- import btf from '../btree/find/module.f.mjs'
3
+ import * as btree from '../btree/module.f.mjs'
4
+ import * as btf from '../btree/find/module.f.mjs'
5
5
  const { find, isFound } = btf
6
- import btr from '../btree/remove/module.f.mjs'
6
+ import * as btr from '../btree/remove/module.f.mjs'
7
7
  const { remove: btreeRemove } = btr
8
- import bts from '../btree/set/module.f.mjs'
8
+ import * as bts from '../btree/set/module.f.mjs'
9
9
  const { set: btreeSet } = bts
10
- const {
10
+ export const {
11
11
  /** @type {(s: StringSet) => list.List<string>} */
12
12
  values,
13
13
  empty,
14
14
  } = btree
15
- import string from "../string/module.f.mjs"
15
+ import * as string from "../string/module.f.mjs"
16
16
  const { cmp } = string
17
- import list from '../list/module.f.mjs'
17
+ import * as list from '../list/module.f.mjs'
18
18
  const { fold } = list
19
- import f from '../function/module.f.mjs'
19
+ import * as f from '../function/module.f.mjs'
20
20
  const { compose } = f
21
21
 
22
22
  /** @typedef {BtreeTypes.Tree<string>} StringSet */
23
23
 
24
24
  /** @type {(value: string) => (set: StringSet) => boolean} */
25
- const contains = value => {
25
+ export const contains = value => {
26
26
  const f = find(cmp(value))
27
27
  return s => s !== null && isFound(f(s).first)
28
28
  }
29
29
 
30
30
  /** @type {(value: string) => (s: StringSet) => StringSet} */
31
- const set = value => btreeSet(cmp(value))(() => value)
31
+ export const set = value => btreeSet(cmp(value))(() => value)
32
32
 
33
- const fromValues = fold(set)(null)
33
+ export const fromValues = fold(set)(null)
34
34
 
35
35
  /** @type {(value: string) => (s: StringSet) => StringSet} */
36
- const remove = compose(cmp)(btreeRemove)
37
-
38
- export default {
39
- /** @readonly */
40
- empty,
41
- /** @readonly */
42
- contains,
43
- /** @readonly */
44
- set,
45
- /** @readonly */
46
- values,
47
- /** @readonly */
48
- fromValues,
49
- /** @readonly */
50
- remove,
51
- }
36
+ export const remove = compose(cmp)(btreeRemove)
@@ -1,4 +1,4 @@
1
- import _ from './module.f.mjs'
1
+ import * as _ from './module.f.mjs'
2
2
 
3
3
  export default {
4
4
  contains: () => {
@@ -1,44 +0,0 @@
1
- # Property Accessor
2
-
3
- - `.`
4
- - `?.`
5
-
6
- FunctionalScript is a strict subset of JavaScript and should behave the same way as JavaScript or reject JS code during compilation as non-valid FS code. However, every object in JavaScript has inherited properties, such as [`constructor`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/constructor) and [`__proto__`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/proto). These properties can cause side effects. For example:
7
-
8
- ```js
9
- const f = (() => {}).constructor
10
- const g = f(`console.log('hello')`)
11
- g() // we received direct access to I/O
12
- ```
13
-
14
- According to FunctionScript principles, an FS compiler should reject such code during compilation. So, the compiler will prohibit the use of `construct` and `__proto__` after `.` and `?.`.
15
-
16
- If an object has its own properties with such names (e.g. `constructor`) then we can access it using the [Object.getOwnPropertyDescriptor](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertyDescriptor) function instead. The function doesn't return inherited properties.
17
-
18
- ```js
19
- const f = (() => {}).constructor
20
- const g = Object.getOwnPropertyDescriptor(f, 'constructor') // g === undefined
21
-
22
- const myObject = { constructor: 42 }
23
- const c = Object.getOwnPropertyDescriptor(myObject, 'constructor').value // c === 42
24
- ```
25
-
26
- Here's the reason why we prohibit `__proto__`:
27
-
28
- ```js
29
- const p = (() => {}).__proto__
30
- const f = Object.getOwnPropertyDescriptor(p, 'constructor').value
31
- const g = f(`console.log('hello')`)
32
- g() // side-effect
33
- ```
34
-
35
- ## Example
36
-
37
- ```js
38
- const a = { x: 3}
39
- export default a.x
40
- ```
41
-
42
- Depends on [const](./2120-const.md), [default-import](./2130-default-import.md) and [undefined](./2310-undefined.md).
43
-
44
- See <https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Property_accessors>.
@@ -1,43 +0,0 @@
1
- # Function Call With Property Accessor
2
-
3
- Operators `a.b()`, `a?.b()`.
4
-
5
- ```js
6
- const x = a.b(5)
7
- ```
8
-
9
- For `null?.b(x())`. We follow the same behavior as JS, so the `x` function will not be called.
10
-
11
- Not allowed (additional to `constructor` and `__proto__`, see [property-accessor](./2351-property-accessor.md)):
12
-
13
- - `__defineGetter__`
14
- - `__defineSetter__`
15
- - `__lookupGetter__`
16
- - `__lookupSetter__`
17
- - `isPrototypeOf` FS has no prototype concept because it has no inheritance.
18
- - `toLocaleString` because it depends on the locale, which is a side-effect.
19
-
20
- Also, from a function:
21
-
22
- - `apply`
23
- - `bind`
24
- - `call`
25
-
26
- Also, from an array:
27
-
28
- - `copyWithin`
29
- - `entries` - returns an iterator.
30
- - `values` - returns an iterator.
31
- - `keys` - returns an iterator.
32
- - `pop`
33
- - `push`
34
- - `shift`
35
- - `unshift`
36
- - `sort`
37
- - `reverse`
38
-
39
- FunctionalScript doesn't allow direct access to iterators. An iterator can be mutated by `.next()` or `for()`. Indirect access to iterators is allowed through the `Iterable` interface. For example
40
- ```js
41
- for (const i of [1, 2]) { }
42
- ```
43
- In this example, the loop gets a temporary iterator from the iterable interface of `[1, 2]` then use it and discard it. A user can't have direct access to the iterator and can't make a copy of it.
@@ -1,19 +0,0 @@
1
- # At
2
-
3
- `a[42]`, `a['str']`, `a[+i]`.
4
-
5
- ```js
6
- import m from './m.f.mjs'
7
- const a = [2, 3]
8
- export default {
9
- "a": a[0],
10
- // we don't know what is the type of `m` so we force it to be a `number` or `bigint`.
11
- "b": a[+m]
12
- }
13
- ```
14
-
15
- In `a[i]`, `i` has to be a `number` or known `string`, which is not equal to prohibited words, see [property-accessor](./2351-property-accessor.md). If we don't know what is `i`, `+` requires before `i`.
16
-
17
- It means that the byte code for the expression inside the `[]` should be either the unary `+`, a number literal, or a string literal (excluding some strings). If it references an object, FS gives up. In the future, FS may try deeper analyses and type inference can help a lot.
18
-
19
- Depends on [property-accessor](./2351-property-accessor.md).
@@ -1,12 +0,0 @@
1
- # Allow Debugging During Test Run
2
-
3
- Currently, we read files as strings and then parse them as functions. See [dev/test.mjs](../dev/test.mjs). In this case, the
4
- debugger doesn't know about the source code and can't debug the functions. The main reason for loading modules as functions was
5
- that Deno v1 didn't support `.cjs` files. However, Deno v2 supports them.
6
-
7
- We can fix the issue by changing our test runner. The test runner will scan all directories, find all `test.f.cjs` files, and
8
- then load them using `require`.
9
-
10
- Limitations: we will not able to check test module dependencies to have module coverage but, anyway, without a parser, we are not able to get full coverage. So, we can drop support for it right now.
11
-
12
- **Note:** In this case, we may drop support for Deno v1. At least until we switch to [ESM](./esm.md).
File without changes
File without changes
File without changes