functionalscript 0.0.479 → 0.0.480

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.
@@ -58,7 +58,7 @@ const getOrBuild = compile => packageGet => moduleMapInterface => {
58
58
  const error = e => [['error', e], [requireMap, m]]
59
59
  if (moduleDir === null) { return error('file not found') }
60
60
  const r = parseAndFind(packageGet)(moduleDir)(p)
61
- if (r === undefined) { return error('file not found') }
61
+ if (r === null) { return error('file not found') }
62
62
  const rIdStr = idToString(r.id)
63
63
  if (setContains(rIdStr)(buildSet1)) { return error('circular reference') }
64
64
  const [state, m1] = build(buildSet1)(r.id)(r.source)(m)
@@ -11,11 +11,11 @@ const compileMap = {
11
11
  'ok',
12
12
  require_ => m0 => {
13
13
  let [r, m] = require_('./b')(m0);
14
- if (r[0] === 'error') { throw r }
14
+ if (r[0] === 'error') { throw JSON.stringify(r) }
15
15
  [r, m] = require_('./a/')(m);
16
- if (r[0] === 'error') { throw r }
16
+ if (r[0] === 'error') { throw JSON.stringify(r) }
17
17
  [r, m] = require_('x/r')(m);
18
- if (r[0] === 'error') { throw r }
18
+ if (r[0] === 'error') { throw JSON.stringify(r) }
19
19
  return [['ok', ':index.js'], m]
20
20
  }],
21
21
  ':b.js': [
@@ -71,21 +71,30 @@ const getOrBuild = _.getOrBuild
71
71
 
72
72
  module.exports = () => {
73
73
  let [r, m] = getOrBuild({ package: '', path: ['index.js'] })(undefined)
74
- if (JSON.stringify(r) !==
75
- '["ok",{"exports":":index.js","requireMap":{"./a/":"/a/index.js","./b":"/b.js","x/r":"/node_modules/x/r.js"}}]'
76
- ) {
77
- throw r
74
+ {
75
+ const x = JSON.stringify(r)
76
+ if (x !==
77
+ '["ok",{"exports":":index.js","requireMap":{"./a/":"/a/index.js","./b":"/b.js","x/r":"/node_modules/x/r.js"}}]'
78
+ ) {
79
+ throw x
80
+ }
78
81
  }
79
- [r, m] = getOrBuild({ package: '', path: ['b.js'] })(m)
80
- if (JSON.stringify(r) !==
81
- '["ok",{"exports":":b.js","requireMap":{}}]'
82
- ) {
83
- throw r
82
+ {
83
+ [r, m] = getOrBuild({ package: '', path: ['b.js'] })(m)
84
+ const x = JSON.stringify(r)
85
+ if (x !==
86
+ '["ok",{"exports":":b.js","requireMap":{}}]'
87
+ ) {
88
+ throw x
89
+ }
84
90
  }
85
- [r, m] = getOrBuild({ package: '', path: ['c.js'] })(m)
86
- if (JSON.stringify(r) !==
87
- '["error",["file not found"]]'
88
- ) {
89
- throw r
91
+ {
92
+ [r, m] = getOrBuild({ package: '', path: ['c.js'] })(m)
93
+ const x = JSON.stringify(r)
94
+ if (x !==
95
+ '["error",["file not found"]]'
96
+ ) {
97
+ throw x
98
+ }
90
99
  }
91
100
  }
@@ -17,17 +17,17 @@ const module_ = require("../module/module.f.cjs")
17
17
  /** @type {(path: string) => readonly string[]} */
18
18
  const split = path => path.split('/')
19
19
 
20
- /** @typedef {readonly[list.List<string>] | undefined} OptionList */
20
+ /** @typedef {readonly[list.List<string>] | null} OptionList */
21
21
 
22
22
  /** @type {(items: string) => (prior: OptionList) => OptionList} */
23
23
  const normItemsOp = first => prior => {
24
- if (prior === undefined) { return undefined }
24
+ if (prior === null) { return null }
25
25
  const tail = prior[0]
26
26
  switch (first) {
27
27
  case '': case '.': { return prior }
28
28
  case '..': {
29
29
  const result = next(tail)
30
- if (result === undefined) { return undefined }
30
+ if (result === list.empty) { return null }
31
31
  return [result.tail]
32
32
  }
33
33
  default: {
@@ -38,46 +38,45 @@ const normItemsOp = first => prior => {
38
38
 
39
39
  /** @type {(items: list.List<string>) => OptionList} */
40
40
  const normItems = items => {
41
- const result = fold(normItemsOp)([undefined])(items)
42
- return result === undefined ? result : [reverse(result[0])]
41
+ const result = fold(normItemsOp)([list.empty])(items)
42
+ return result === null ? result : [reverse(result[0])]
43
43
  }
44
44
 
45
- const firstUndefined = first(undefined)
45
+ const firstNull = first(null)
46
46
 
47
- /** @type {(local: string) => (path: string) => LocalPath|undefined} */
47
+ /** @type {(local: string) => (path: string) => LocalPath|null} */
48
48
  const parseLocal = local => {
49
49
  /** @type {(path: string) => readonly[boolean, boolean, list.List<string>]} */
50
50
  const fSeq = path => {
51
51
  const pathSeq = split(path)
52
- const dir = [undefined, '', '.', '..'].includes(pathSeq[pathSeq.length - 1])
53
- return /** @type {readonly (string|undefined)[]} */(['.', '..']).includes(firstUndefined(pathSeq)) ?
52
+ const dir = [null, '', '.', '..'].includes(pathSeq[pathSeq.length - 1])
53
+ return /** @type {readonly (string|null)[]} */(['.', '..']).includes(firstNull(pathSeq)) ?
54
54
  [false, dir, flat([split(local), pathSeq])] :
55
55
  [true, dir, pathSeq]
56
56
  }
57
- /** @type {(path: string) => LocalPath|undefined} */
58
- const f = path => {
57
+ // /** @type {(path: string) => LocalPath|null} */
58
+ return path => {
59
59
  const [external, dir, items] = fSeq(path)
60
60
  const n = normItems(items)
61
- if (n === undefined) { return undefined }
61
+ if (n === null) { return null }
62
62
  return {
63
63
  external,
64
64
  dir,
65
65
  items: toArray(n[0])
66
66
  }
67
67
  }
68
- return f
69
68
  }
70
69
 
71
70
  /** @typedef {readonly[string, list.List<string>]} IdPath */
72
71
 
73
- /** @type {(prior: readonly[string|undefined, list.List<string>]) => list.Thunk<IdPath>} */
72
+ /** @type {(prior: readonly[string|null, list.List<string>]) => list.Thunk<IdPath>} */
74
73
  const variants = prior => () => {
75
74
  const [a, b] = prior
76
75
  const r = next(b)
77
- if (r === undefined) { return undefined }
76
+ if (r === list.empty) { return list.empty }
78
77
  const { first, tail } = r
79
78
  /** @type {IdPath} */
80
- const n = [a === undefined ? first : `${a}/${first}`, tail]
79
+ const n = [a === null ? first : `${a}/${first}`, tail]
81
80
  return { first: n, tail: variants(n) }
82
81
  }
83
82
 
@@ -105,9 +104,9 @@ const parseGlobal = dependencies =>
105
104
  {
106
105
  const fMap = filterMap(mapDependency(dependencies))
107
106
  return dir => items => {
108
- const v = variants([undefined, items])
109
- const r = firstUndefined(fMap(v))
110
- if (r === undefined) { return undefined }
107
+ const v = variants([null, items])
108
+ const r = firstNull(fMap(v))
109
+ if (r === null) { return undefined }
111
110
  return { package: r[0], items: toArray(r[1]), dir }
112
111
  }
113
112
  }
@@ -123,7 +122,7 @@ const parse = packageId => dependencies => {
123
122
  const pg = parseGlobal(dependencies)
124
123
  return local => path => {
125
124
  const parsed = parseLocal(local)(path)
126
- if (parsed === undefined) { return undefined }
125
+ if (parsed === null) { return undefined }
127
126
  const {external, dir, items } = parsed
128
127
  if (!external) { return { package: packageId, items, dir } }
129
128
  return pg(dir)(items)
@@ -134,9 +133,11 @@ const parse = packageId => dependencies => {
134
133
  * @typedef {{
135
134
  * readonly id: module_.Id
136
135
  * readonly source: string
137
- * }| undefined} Result
136
+ * }} FoundResult
138
137
  */
139
138
 
139
+ /** @typedef {FoundResult| null} Result */
140
+
140
141
  /**
141
142
  * @type {(packageGet: package_.Get) =>
142
143
  * (moduleId: module_.Id) =>
@@ -146,12 +147,12 @@ const parse = packageId => dependencies => {
146
147
  */
147
148
  const parseAndFind = packageGet => moduleId => path => {
148
149
  const currentPack = packageGet(moduleId.package)
149
- if (currentPack === undefined) { return undefined }
150
+ if (currentPack === undefined) { return null }
150
151
  const p = parse(moduleId.package)(currentPack.dependency)(moduleId.path.join('/'))(path)
151
- if (p === undefined) { return undefined }
152
+ if (p === undefined) { return null }
152
153
  const pack = packageGet(p.package)
153
- if (pack === undefined) { return undefined }
154
- /** @type {(file: string) => Result } */
154
+ if (pack === undefined) { return null }
155
+ /** @type {(file: string) => FoundResult | undefined } */
155
156
  const tryFile = file => {
156
157
  const source = pack.file(file)
157
158
  return source === undefined ? undefined : { id: { package: p.package, path: file.split('/') }, source }
@@ -159,7 +160,7 @@ const parseAndFind = packageGet => moduleId => path => {
159
160
  const file = p.items.join('/')
160
161
  const indexJs = join('/')(concat(p.items)(['index.js']))
161
162
  const fileList = p.dir || isEmpty(p.items) ? [indexJs] : [file, `${file}.js`, indexJs]
162
- return firstUndefined(filterMap(tryFile)(fileList))
163
+ return firstNull(filterMap(tryFile)(fileList))
163
164
  }
164
165
 
165
166
  module.exports = {
@@ -6,80 +6,85 @@ 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
+ }
14
+
9
15
  /** @type {(g: json.Unknown|undefined) => string} */
10
16
  const stringify = g => {
11
17
  if (g === undefined) { throw g }
12
18
  return json.stringify(identity)(g)
13
19
  }
14
20
 
15
- module.exports = [
16
- () => {
17
- const p = { name: '', version: '' }
21
+ module.exports = {
22
+ 0: () => {
18
23
  const result = _.parseLocal('')('./a')
19
24
  if (stringify(result) !== '{"external":false,"dir":false,"items":["a"]}') { throw result }
20
25
  },
21
- () => {
26
+ 1: () => {
22
27
  const result = _.parseLocal('')('./a/')
23
28
  if (stringify(result) !== '{"external":false,"dir":true,"items":["a"]}') { throw result }
24
29
  },
25
- () => {
30
+ 2: () => {
26
31
  const result = _.parseLocal('')('..')
27
- if (result !== undefined) { throw result }
32
+ if (result !== null) { throw result }
28
33
  },
29
- () => {
34
+ 3: () => {
30
35
  const result = _.parseLocal('a')('')
31
36
  if (stringify(result) !== '{"external":true,"dir":true,"items":[]}') { throw result }
32
37
  },
33
- () => {
38
+ 4: () => {
34
39
  const result = _.parseLocal('')('./a/b/.././c')
35
40
  if (stringify(result) !== '{"external":false,"dir":false,"items":["a","c"]}') { throw result }
36
41
  },
37
- () => {
42
+ 5: () => {
38
43
  const result = _.parseLocal('x/r')('./a/b/.././c')
39
44
  if (stringify(result) !== '{"external":false,"dir":false,"items":["x","r","a","c"]}') { throw result }
40
45
  },
41
- () => {
46
+ 6: () => {
42
47
  const result = _.parseLocal('a')('a/b/.././c')
43
48
  if (stringify(result) !== '{"external":true,"dir":false,"items":["a","c"]}') { throw result }
44
49
  },
45
- () => {
50
+ 7: () => {
46
51
  const result = _.parseLocal('')('./x/..')
47
52
  if (stringify(result) !== '{"external":false,"dir":true,"items":[]}') { throw result }
48
53
  },
49
- () => {
54
+ 8: () => {
50
55
  if (_.parseGlobal(() => undefined)(false)(['a', 'b']) !== undefined) { throw 'error' }
51
56
  if (_.parseGlobal(() => undefined)(false)(['b']) !== undefined) { throw 'error' }
52
- if (_.parseGlobal(d => at(d)({ b: 'x' }))(false)(['d']) !== undefined) { throw 'error' }
57
+ if (_.parseGlobal(i({ b: 'x' }))(false)(['d']) !== undefined) { throw 'error' }
53
58
  {
54
- const result = stringify(_.parseGlobal(d => at(d)({ b: 'x' }))(false)(['b']))
59
+ const result = stringify(_.parseGlobal(i({ b: 'x' }))(false)(['b']))
55
60
  if (result !== '{"package":"x","items":[],"dir":false}') { throw result }
56
61
  }
57
- if (_.parseGlobal(d => at(d)({ 'b/r': 'x' }))(false)(['b']) !== undefined) { throw 'error' }
62
+ if (_.parseGlobal(i({ 'b/r': 'x' }))(false)(['b']) !== undefined) { throw 'error' }
58
63
  {
59
- const result = stringify(_.parseGlobal(d => at(d)({ 'b/r': 'x' }))(false)(['b', 'r']))
64
+ const result = stringify(_.parseGlobal(i({ 'b/r': 'x' }))(false)(['b', 'r']))
60
65
  if (result !== '{"package":"x","items":[],"dir":false}') { throw result }
61
66
  }
62
67
  {
63
- const result = stringify(_.parseGlobal(d => at(d)({ 'b/r': 'x' }))(false)(['b', 'r', 'd', 't']))
68
+ const result = stringify(_.parseGlobal(i({ 'b/r': 'x' }))(false)(['b', 'r', 'd', 't']))
64
69
  if (result !== '{"package":"x","items":["d","t"],"dir":false}') { throw result }
65
70
  }
66
71
  {
67
- const result = stringify(_.parseGlobal(d => at(d)({ 'b/r': 'x' }))(true)(['b', 'r', 'd', 't']))
72
+ const result = stringify(_.parseGlobal(i({ 'b/r': 'x' }))(true)(['b', 'r', 'd', 't']))
68
73
  if (result !== '{"package":"x","items":["d","t"],"dir":true}') { throw result }
69
74
  }
70
75
  },
71
- () => {
76
+ 9: () => {
72
77
  /** @type {object.Map<package_.Package>} */
73
78
  const packages = {
74
79
  '': {
75
80
  dependency: () => todo(),
76
- file: path => at(path)({ 'a/c': 'return "a/c"' }),
81
+ file: i({ 'a/c': 'return "a/c"' }),
77
82
  }
78
83
  }
79
- const result = stringify(_.parseAndFind(p => at(p)(packages))({ package: '', path: ['a', 'b'] })('../c'))
84
+ const result = stringify(_.parseAndFind(i(packages))({ package: '', path: ['a', 'b'] })('../c'))
80
85
  if (result !== '{"id":{"package":"","path":["a","c"]},"source":"return \\"a/c\\""}') { throw result }
81
86
  },
82
- () => {
87
+ 10: () => {
83
88
  /** @type {object.Map<package_.Package>} */
84
89
  const packages = {
85
90
  '': {
@@ -87,7 +92,7 @@ module.exports = [
87
92
  const path = `node_modules/${x}`
88
93
  return at(path)(packages) !== undefined ? path : undefined
89
94
  },
90
- file: path => at(path)({
95
+ file: i({
91
96
  'index.js': 'return "index.js"',
92
97
  'x/index.js': 'return "x/index.js"',
93
98
  'x.js': 'return "x.js"',
@@ -95,87 +100,87 @@ module.exports = [
95
100
  },
96
101
  'node_modules/z': {
97
102
  dependency: () => todo(),
98
- file: path => at(path)({ 'a/c/index.js': 'return "a/c"' }),
103
+ file: i({ 'a/c/index.js': 'return "a/c"' }),
99
104
  }
100
105
  }
101
106
  {
102
- const result = stringify(_.parseAndFind(p => at(p)(packages))({ package: '', path: ['a', 'b'] })('z/a/c'))
107
+ const result = stringify(_.parseAndFind(i(packages))({ package: '', path: ['a', 'b'] })('z/a/c'))
103
108
  if (result !== '{"id":{"package":"node_modules/z","path":["a","c","index.js"]},"source":"return \\"a/c\\""}') {
104
109
  throw result
105
110
  }
106
111
  }
107
112
  {
108
- const result = stringify(_.parseAndFind(p => at(p)(packages))({ package: '', path: ['a', 'b'] })('../..'))
113
+ const result = stringify(_.parseAndFind(i(packages))({ package: '', path: ['a', 'b'] })('../..'))
109
114
  if (result !== '{"id":{"package":"","path":["index.js"]},"source":"return \\"index.js\\""}') { throw result }
110
115
  }
111
116
  {
112
- const result = stringify(_.parseAndFind(p => at(p)(packages))({ package: '', path: [] })('./x'))
117
+ const result = stringify(_.parseAndFind(i(packages))({ package: '', path: [] })('./x'))
113
118
  if (result !== '{"id":{"package":"","path":["x.js"]},"source":"return \\"x.js\\""}') { throw result }
114
119
  }
115
120
  {
116
- const result = stringify(_.parseAndFind(p => at(p)(packages))({ package: '', path: [] })('./x.js'))
121
+ const result = stringify(_.parseAndFind(i(packages))({ package: '', path: [] })('./x.js'))
117
122
  if (result !== '{"id":{"package":"","path":["x.js"]},"source":"return \\"x.js\\""}') { throw result }
118
123
  }
119
124
  {
120
- const result = stringify(_.parseAndFind(p => at(p)(packages))({ package: '', path: [] })('./x/'))
125
+ const result = stringify(_.parseAndFind(i(packages))({ package: '', path: [] })('./x/'))
121
126
  if (result !== '{"id":{"package":"","path":["x","index.js"]},"source":"return \\"x/index.js\\""}') { throw result }
122
127
  }
123
128
  {
124
- const result = stringify(_.parseAndFind(p => at(p)(packages))({ package: '', path: ['x', 'a'] })('../'))
129
+ const result = stringify(_.parseAndFind(i(packages))({ package: '', path: ['x', 'a'] })('../'))
125
130
  if (result !== '{"id":{"package":"","path":["x","index.js"]},"source":"return \\"x/index.js\\""}') { throw result }
126
131
  }
127
132
  {
128
- const result = stringify(_.parseAndFind(p => at(p)(packages))({ package: '', path: ['x', 'a'] })('..'))
133
+ const result = stringify(_.parseAndFind(i(packages))({ package: '', path: ['x', 'a'] })('..'))
129
134
  if (result !== '{"id":{"package":"","path":["x","index.js"]},"source":"return \\"x/index.js\\""}') { throw result }
130
135
  }
131
136
  },
132
- () => {
137
+ 11: () => {
133
138
  /** @type {object.Map<package_.Package>} */
134
139
  const packages = {
135
140
  '': {
136
141
  dependency: x => {
137
142
  const path = `node_modules/${x}`
138
- return at(path)(packages) !== undefined ? path : undefined
143
+ return at(path)(packages) !== null ? path : undefined
139
144
  },
140
145
  file: todo
141
146
  },
142
147
  'node_modules/z/a': {
143
148
  dependency: () => todo(),
144
- file: path => at(path)({
149
+ file: i({
145
150
  'c/index.js': 'return "c/index.js"',
146
151
  'c.js': 'return "c.js"'
147
152
  }),
148
153
  }
149
154
  }
150
155
  {
151
- const result = stringify(_.parseAndFind(p => at(p)(packages))({ package: '', path: ['a', 'b'] })('z/a/c'))
156
+ const result = stringify(_.parseAndFind(i(packages))({ package: '', path: ['a', 'b'] })('z/a/c'))
152
157
  if (result !== '{"id":{"package":"node_modules/z/a","path":["c.js"]},"source":"return \\"c.js\\""}') { throw result }
153
158
  }
154
159
  {
155
- const result = stringify(_.parseAndFind(p => at(p)(packages))({ package: '', path: ['a', 'b'] })('z/a/c/'))
160
+ const result = stringify(_.parseAndFind(i(packages))({ package: '', path: ['a', 'b'] })('z/a/c/'))
156
161
  if (result !== '{"id":{"package":"node_modules/z/a","path":["c","index.js"]},"source":"return \\"c/index.js\\""}') { throw result }
157
162
  }
158
163
  },
159
- () => {
164
+ 12: () => {
160
165
  /** @type {object.Map<package_.Package>} */
161
166
  const packages = {
162
167
  '': {
163
168
  dependency: x => {
164
169
  const path = `node_modules/${x}`
165
- return at(path)(packages) !== undefined ? path : undefined
170
+ return at(path)(packages) !== null ? path : undefined
166
171
  },
167
172
  file: todo
168
173
  },
169
174
  'node_modules/z/a/c': {
170
175
  dependency: () => todo(),
171
- file: path => at(path)({
176
+ file: i({
172
177
  '': 'throw',
173
178
  '.js': 'throw',
174
179
  'index.js': 'return "a/c"'
175
180
  }),
176
181
  }
177
182
  }
178
- const result = stringify(_.parseAndFind(p => at(p)(packages))({ package: '', path: ['a', 'b'] })('z/a/c'))
183
+ const result = stringify(_.parseAndFind(i(packages))({ package: '', path: ['a', 'b'] })('z/a/c'))
179
184
  if (result !== '{"id":{"package":"node_modules/z/a/c","path":["index.js"]},"source":"return \\"a/c\\""}') { throw result }
180
185
  }
181
- ]
186
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "functionalscript",
3
- "version": "0.0.479",
3
+ "version": "0.0.480",
4
4
  "description": "FunctionalScript is a functional subset of JavaScript",
5
5
  "main": "module.f.cjs",
6
6
  "scripts": {
@@ -16,8 +16,11 @@ const { getOwnPropertyDescriptor, fromEntries: objectFromEntries } = Object
16
16
  * @typedef {readonly[string, T]} Entry
17
17
  */
18
18
 
19
- /** @type {(name: string) => <T>(object: Map<T>) => T|undefined} */
20
- const at = name => object => getOwnPropertyDescriptor(object, name)?.value
19
+ /** @type {(name: string) => <T>(object: Map<T>) => T|null} */
20
+ const at = name => object => {
21
+ const r = getOwnPropertyDescriptor(object, name)
22
+ return r === void 0 ? null : r.value
23
+ }
21
24
 
22
25
  /** @type {<T>(e: list.List<Entry<T>>) => list.List<Entry<T>>} */
23
26
  const sort = e => mapEntries(mapFromEntries(e))
@@ -26,7 +29,7 @@ const sort = e => mapEntries(mapFromEntries(e))
26
29
  const fromEntries = e => objectFromEntries(iterable(e))
27
30
 
28
31
  /** @type {<T>(m: map.Map<T>) => Map<T>} */
29
- const fromMap = m => fromEntries(mapEntries(m))
32
+ const fromMap = m => fromEntries(mapEntries(m))
30
33
 
31
34
  module.exports = {
32
35
  /** @readonly */
@@ -4,7 +4,7 @@ module.exports = {
4
4
  ctor: () => {
5
5
  const a = {}
6
6
  const value = _.at('constructor')(a)
7
- if (value !== undefined) { throw value }
7
+ if (value !== null) { throw value }
8
8
  },
9
9
  property: () => {
10
10
  const a = { constructor: 42 }