functionalscript 0.0.480 → 0.0.482

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.
@@ -3,13 +3,13 @@ const module_ = require('../module/module.f.cjs')
3
3
  const { idToString, dir } = module_
4
4
  const function_ = require('../module/function/module.f.cjs')
5
5
  const map = require('../../types/map/module.f.cjs')
6
- const { setReplace } = map
6
+ const { empty: mapEmpty, setReplace } = map
7
7
  const object = require('../../types/object/module.f.cjs')
8
8
  const { fromMap } = object
9
9
  const path = require('../path/module.f.cjs')
10
10
  const { parseAndFind } = path
11
11
  const stringSet = require('../../types/string_set/module.f.cjs')
12
- const { set: setSet, contains: setContains } = stringSet
12
+ const { set: setSet, contains: setContains, empty: stringSetEmpty } = stringSet
13
13
 
14
14
  /**
15
15
  * @template M
@@ -73,7 +73,7 @@ const getOrBuild = compile => packageGet => moduleMapInterface => {
73
73
  const [kind, result] = compile(source)
74
74
  if (kind === 'error') { return error(['compilation error', result])(moduleMap) }
75
75
  // build
76
- const [[state, value], [requireMap, moduleMap2]] = result(require_)([undefined, moduleMap])
76
+ const [[state, value], [requireMap, moduleMap2]] = result(require_)([mapEmpty, moduleMap])
77
77
  const x = state === 'error' ?
78
78
  error(['runtime error', value]) :
79
79
  set(['ok', { exports: value, requireMap: fromMap(requireMap) }])
@@ -90,10 +90,10 @@ const getOrBuild = compile => packageGet => moduleMapInterface => {
90
90
  }
91
91
  // check package
92
92
  const p = packageGet(moduleId.package)
93
- if (p === undefined) { return notFound(moduleMap) }
93
+ if (p === null) { return notFound(moduleMap) }
94
94
  // check file
95
95
  const source = p.file(moduleId.path.join('/'))
96
- return (source === undefined ? notFound : build(undefined)(moduleId)(source))(moduleMap)
96
+ return (source === null ? notFound : build(stringSetEmpty)(moduleId)(source))(moduleMap)
97
97
  }
98
98
  return f
99
99
  }
@@ -4,6 +4,7 @@ const module_ = require('../module/module.f.cjs')
4
4
  const function_ = require('../module/function/module.f.cjs')
5
5
  const result = require('../../types/result/module.f.cjs')
6
6
  const package_ = require('../package/module.f.cjs')
7
+ const { at } = require('../../types/object/module.f.cjs')
7
8
 
8
9
  /** @type {{ readonly [k in string]?: result.Result<function_.Function_, unknown> }} */
9
10
  const compileMap = {
@@ -32,9 +33,9 @@ const compileMap = {
32
33
  /** @type {function_.Compile} */
33
34
  const compile = source => compileMap[source] ?? ['error', 'invalid source']
34
35
 
35
- /** @typedef {{ readonly [k in string]?: string }} StringMap */
36
+ /** @typedef {{ readonly [k in string]: string }} StringMap */
36
37
 
37
- /** @type {{ readonly [k in string]?: { readonly dependencies: StringMap, files: StringMap }}} */
38
+ /** @type {{ readonly [k in string]: { readonly dependencies: StringMap, readonly files: StringMap }}} */
38
39
  const packageMap = {
39
40
  '': {
40
41
  dependencies: {
@@ -56,11 +57,11 @@ const packageMap = {
56
57
 
57
58
  /** @type {package_.Get} */
58
59
  const packageGet = packageId => {
59
- const p = packageMap[packageId]
60
- return p === undefined ? undefined :
60
+ const p = at(packageId)(packageMap)
61
+ return p === null ? null :
61
62
  {
62
- dependency: dependency => p.dependencies[dependency],
63
- file: file => p.files[file]
63
+ dependency: dependency => at(dependency)(p.dependencies),
64
+ file: file => at(file)(p.files),
64
65
  }
65
66
  }
66
67
 
@@ -70,7 +71,7 @@ const getOrBuild = _.getOrBuild
70
71
  (/** @type {module_.MapInterface<map.Map<module_.State>>} */(map))
71
72
 
72
73
  module.exports = () => {
73
- let [r, m] = getOrBuild({ package: '', path: ['index.js'] })(undefined)
74
+ let [r, m] = getOrBuild({ package: '', path: ['index.js'] })(map.empty)
74
75
  {
75
76
  const x = JSON.stringify(r)
76
77
  if (x !==
@@ -8,14 +8,14 @@ const { entries } = Object
8
8
 
9
9
  /** @typedef {{readonly[k in string]: string}} DependencyMapJson */
10
10
 
11
- /** @typedef {DependencyMapJson|undefined} DependenciesJson */
11
+ /** @typedef {DependencyMapJson|null} DependenciesJson */
12
12
 
13
13
  /** @type {(entry: json.Entry) => boolean} */
14
14
  const isDependencyJson = ([, v]) => typeof v === 'string'
15
15
 
16
- /** @type {(j: json.Unknown|undefined) => j is DependenciesJson} */
16
+ /** @type {(j: json.Unknown) => j is DependenciesJson} */
17
17
  const isDependenciesJson = j => {
18
- if (j === undefined) { return true }
18
+ if (j === null) { return true }
19
19
  if (!isObject(j)) { return false }
20
20
  return every(map(isDependencyJson)(entries(j)))
21
21
  }
@@ -1,8 +1,7 @@
1
1
  const _ = require('./module.f.cjs')
2
2
 
3
3
  module.exports = () => {
4
- if (!_.isDependenciesJson(undefined)) { throw 'error' }
5
- if (_.isDependenciesJson(null)) { throw 'error' }
4
+ if (!_.isDependenciesJson(null)) { throw 'error' }
6
5
  if (!_.isDependenciesJson({})) { throw 'error' }
7
6
  if (!_.isDependenciesJson({'a':'b'})) { throw 'error' }
8
7
  if (_.isDependenciesJson({ 'a': 12 })) { throw 'error' }
@@ -2,6 +2,7 @@ const json = require('../../json/module.f.cjs')
2
2
  const { isObject } = json
3
3
  const dependencies = require('./dependencies/module.f.cjs')
4
4
  const { isDependenciesJson } = dependencies
5
+ const { at } = require('../../types/object/module.f.cjs')
5
6
 
6
7
  /**
7
8
  * @typedef {{
@@ -16,20 +17,20 @@ const isPackageJson = j => {
16
17
  if (!isObject(j)) { return false }
17
18
  if (typeof j.name !== 'string') { return false }
18
19
  if (typeof j.version !== 'string') { return false }
19
- if (!isDependenciesJson(j.dependencies)) { return false }
20
+ if (!isDependenciesJson(at('dependencies')(j))) { return false }
20
21
  return true
21
22
  }
22
23
 
23
24
  /**
24
25
  * @typedef {{
25
- * readonly dependency: (localPackageId: string) => string | undefined
26
- * readonly file: (localFileId: string) => string | undefined
26
+ * readonly dependency: (localPackageId: string) => string | null
27
+ * readonly file: (localFileId: string) => string | null
27
28
  * }} Package
28
29
  */
29
30
 
30
31
  /**
31
32
  * @note Current package has an empty string '' as a packageId.
32
- * @typedef {(packageId: string) => Package | undefined} Get
33
+ * @typedef {(packageId: string) => Package | null} Get
33
34
  */
34
35
 
35
36
  module.exports = {
@@ -80,10 +80,10 @@ const variants = prior => () => {
80
80
  return { first: n, tail: variants(n) }
81
81
  }
82
82
 
83
- /** @type {(d: (local: string) => string|undefined) => (p: IdPath) => IdPath|undefined} */
83
+ /** @type {(d: (local: string) => string|null) => (p: IdPath) => IdPath|undefined} */
84
84
  const mapDependency = d => ([external, internal]) => {
85
85
  const id = d(external)
86
- return id === undefined ? undefined : [id, internal]
86
+ return id === null ? undefined : [id, internal]
87
87
  }
88
88
 
89
89
  /**
@@ -95,10 +95,10 @@ const mapDependency = d => ([external, internal]) => {
95
95
  */
96
96
 
97
97
  /**
98
- * @type {(d: (local: string) => string|undefined) =>
98
+ * @type {(d: (local: string) => string|null) =>
99
99
  * (dir: boolean) =>
100
100
  * (items: list.List<string>) =>
101
- * Path|undefined}
101
+ * Path|null}
102
102
  */
103
103
  const parseGlobal = dependencies =>
104
104
  {
@@ -106,23 +106,23 @@ const parseGlobal = dependencies =>
106
106
  return dir => items => {
107
107
  const v = variants([null, items])
108
108
  const r = firstNull(fMap(v))
109
- if (r === null) { return undefined }
109
+ if (r === null) { return null }
110
110
  return { package: r[0], items: toArray(r[1]), dir }
111
111
  }
112
112
  }
113
113
 
114
114
  /**
115
115
  * @type {(packageId: string) =>
116
- * (dependencies: (local: string) => string|undefined) =>
116
+ * (dependencies: (local: string) => string|null) =>
117
117
  * (local: string) =>
118
118
  * (path: string) =>
119
- * Path|undefined }
119
+ * Path|null }
120
120
  */
121
121
  const parse = packageId => dependencies => {
122
122
  const pg = parseGlobal(dependencies)
123
123
  return local => path => {
124
124
  const parsed = parseLocal(local)(path)
125
- if (parsed === null) { return undefined }
125
+ if (parsed === null) { return null }
126
126
  const {external, dir, items } = parsed
127
127
  if (!external) { return { package: packageId, items, dir } }
128
128
  return pg(dir)(items)
@@ -147,15 +147,15 @@ const parse = packageId => dependencies => {
147
147
  */
148
148
  const parseAndFind = packageGet => moduleId => path => {
149
149
  const currentPack = packageGet(moduleId.package)
150
- if (currentPack === undefined) { return null }
150
+ if (currentPack === null) { return null }
151
151
  const p = parse(moduleId.package)(currentPack.dependency)(moduleId.path.join('/'))(path)
152
- if (p === undefined) { return null }
152
+ if (p === null) { return null }
153
153
  const pack = packageGet(p.package)
154
- if (pack === undefined) { return null }
154
+ if (pack === null) { return null }
155
155
  /** @type {(file: string) => FoundResult | undefined } */
156
156
  const tryFile = file => {
157
157
  const source = pack.file(file)
158
- return source === undefined ? undefined : { id: { package: p.package, path: file.split('/') }, source }
158
+ return source === null ? undefined : { id: { package: p.package, path: file.split('/') }, source }
159
159
  }
160
160
  const file = p.items.join('/')
161
161
  const indexJs = join('/')(concat(p.items)(['index.js']))
@@ -6,17 +6,11 @@ const object = require('../../types/object/module.f.cjs')
6
6
  const { at } = require('../../types/object/module.f.cjs')
7
7
  const package_ = require('../package/module.f.cjs')
8
8
 
9
- /** @type {<T>(o: object.Map<T>) => (s: string) => T|undefined} */
10
- const i = o => s => {
11
- const r = at(s)(o)
12
- return r === null ? undefined : r
13
- }
9
+ /** @type {<T>(o: object.Map<T>) => (s: string) => T|null} */
10
+ const i = o => s => at(s)(o)
14
11
 
15
- /** @type {(g: json.Unknown|undefined) => string} */
16
- const stringify = g => {
17
- if (g === undefined) { throw g }
18
- return json.stringify(identity)(g)
19
- }
12
+ /** @type {(g: json.Unknown) => string} */
13
+ const stringify = json.stringify(identity)
20
14
 
21
15
  module.exports = {
22
16
  0: () => {
@@ -51,27 +45,27 @@ module.exports = {
51
45
  const result = _.parseLocal('')('./x/..')
52
46
  if (stringify(result) !== '{"external":false,"dir":true,"items":[]}') { throw result }
53
47
  },
54
- 8: () => {
55
- if (_.parseGlobal(() => undefined)(false)(['a', 'b']) !== undefined) { throw 'error' }
56
- if (_.parseGlobal(() => undefined)(false)(['b']) !== undefined) { throw 'error' }
57
- if (_.parseGlobal(i({ b: 'x' }))(false)(['d']) !== undefined) { throw 'error' }
58
- {
48
+ 8: {
49
+ 0: () => { if (_.parseGlobal(() => null)(false)(['a', 'b']) !== null) { throw 'error' } },
50
+ 1: () => { if (_.parseGlobal(() => null)(false)(['b']) !== null) { throw 'error' } },
51
+ 2: () => { if (_.parseGlobal(i({ b: 'x' }))(false)(['d']) !== null) { throw 'error' } },
52
+ 3: () => {
59
53
  const result = stringify(_.parseGlobal(i({ b: 'x' }))(false)(['b']))
60
54
  if (result !== '{"package":"x","items":[],"dir":false}') { throw result }
61
- }
62
- if (_.parseGlobal(i({ 'b/r': 'x' }))(false)(['b']) !== undefined) { throw 'error' }
63
- {
55
+ },
56
+ 4: () => { if (_.parseGlobal(i({ 'b/r': 'x' }))(false)(['b']) !== null) { throw 'error' } },
57
+ 5: () => {
64
58
  const result = stringify(_.parseGlobal(i({ 'b/r': 'x' }))(false)(['b', 'r']))
65
59
  if (result !== '{"package":"x","items":[],"dir":false}') { throw result }
66
- }
67
- {
60
+ },
61
+ 6: () => {
68
62
  const result = stringify(_.parseGlobal(i({ 'b/r': 'x' }))(false)(['b', 'r', 'd', 't']))
69
63
  if (result !== '{"package":"x","items":["d","t"],"dir":false}') { throw result }
70
- }
71
- {
64
+ },
65
+ 7: () => {
72
66
  const result = stringify(_.parseGlobal(i({ 'b/r': 'x' }))(true)(['b', 'r', 'd', 't']))
73
67
  if (result !== '{"package":"x","items":["d","t"],"dir":true}') { throw result }
74
- }
68
+ },
75
69
  },
76
70
  9: () => {
77
71
  /** @type {object.Map<package_.Package>} */
@@ -90,7 +84,7 @@ module.exports = {
90
84
  '': {
91
85
  dependency: x => {
92
86
  const path = `node_modules/${x}`
93
- return at(path)(packages) !== undefined ? path : undefined
87
+ return at(path)(packages) !== null ? path : null
94
88
  },
95
89
  file: i({
96
90
  'index.js': 'return "index.js"',
@@ -140,7 +134,7 @@ module.exports = {
140
134
  '': {
141
135
  dependency: x => {
142
136
  const path = `node_modules/${x}`
143
- return at(path)(packages) !== null ? path : undefined
137
+ return at(path)(packages) !== null ? path : null
144
138
  },
145
139
  file: todo
146
140
  },
@@ -167,7 +161,7 @@ module.exports = {
167
161
  '': {
168
162
  dependency: x => {
169
163
  const path = `node_modules/${x}`
170
- return at(path)(packages) !== null ? path : undefined
164
+ return at(path)(packages) !== null ? path : null
171
165
  },
172
166
  file: todo
173
167
  },
package/dev/module.mjs CHANGED
@@ -121,7 +121,7 @@ export const loadModuleMap = async () => {
121
121
  const pathStr = path.join('/')
122
122
  {
123
123
  const module = d[pathStr]
124
- if (module !== undefined) {
124
+ if (module !== void 0) {
125
125
  return [pathStr, module]
126
126
  }
127
127
  }
package/doc/LANGUAGE.md CHANGED
@@ -226,7 +226,7 @@ const iterable = list => ({
226
226
  let i = list
227
227
  while (true) {
228
228
  const r = next(i)
229
- if (r === undefined) { return }
229
+ if (r === null) { return }
230
230
  yield r.first
231
231
  i = r.tail
232
232
  }
package/fsm/module.f.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  const list = require('../types/list/module.f.cjs')
2
- const { equal, isEmpty, fold, toArray, scan, foldScan } = list
2
+ const { equal, isEmpty, fold, toArray, scan, foldScan, empty: emptyList } = list
3
3
  const byteSet = require('../types/byte_set/module.f.cjs')
4
4
  const { toRangeMap, union: byteSetUnion, one, empty } = byteSet
5
5
  const sortedSet = require('../types/sorted_set/module.f.cjs')
@@ -66,7 +66,7 @@ const scanFetch = scan(fetchOp)
66
66
  const addEntry = grammar => set => dfa => {
67
67
  const s = stringifyIdentity(set)
68
68
  if (s in dfa) { return dfa }
69
- const setMap = fold(foldOp(set))(undefined)(grammar)
69
+ const setMap = fold(foldOp(set))(emptyList)(grammar)
70
70
  const stringMap = toArray(scanStringify(setMap))
71
71
  const newDfa = { ...dfa, [s]: stringMap }
72
72
  const newStates = scanFetch(setMap)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "functionalscript",
3
- "version": "0.0.480",
3
+ "version": "0.0.482",
4
4
  "description": "FunctionalScript is a functional subset of JavaScript",
5
5
  "main": "module.f.cjs",
6
6
  "scripts": {
@@ -30,6 +30,8 @@ const nodeValues = node => () => {
30
30
  const values = map(nodeValues)
31
31
 
32
32
  module.exports = {
33
+ /** @readonly */
34
+ empty: undefined,
33
35
  /** @readonly */
34
36
  find: require('./find/module.f.cjs'),
35
37
  /** @readonly */
@@ -6,6 +6,7 @@ const {
6
6
  set: { set: btreeSet },
7
7
  /** @type {(s: StringSet) => list.List<string>} */
8
8
  values,
9
+ empty,
9
10
  } = btree
10
11
  const { cmp } = require("../string/module.f.cjs")
11
12
  const list = require('../list/module.f.cjs')
@@ -29,6 +30,8 @@ const fromValues = fold(set)(undefined)
29
30
  const remove = compose(cmp)(btreeRemove)
30
31
 
31
32
  module.exports = {
33
+ /** @readonly */
34
+ empty,
32
35
  /** @readonly */
33
36
  contains,
34
37
  /** @readonly */