functionalscript 0.0.478 → 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.
@@ -52,13 +52,13 @@ const joinComma = join(', ')
52
52
  /** @type {(name: string) => (lib: types.Library) => text.Block} */
53
53
  const cpp = name => lib => {
54
54
 
55
- /** @type {(t: types.Type) => string|undefined} */
55
+ /** @type {(t: types.Type) => string|null} */
56
56
  const interface_ = t => {
57
57
  if (!(t instanceof Array) || t.length !== 1) {
58
- return undefined
58
+ return null
59
59
  }
60
60
  const [name] = t
61
- return lib[name].interface !== undefined ? name : undefined
61
+ return 'interface' in lib[name] ? name : null
62
62
  }
63
63
 
64
64
  /** @type {(i: (t: string) => string) => (t: types.Type) => string} */
@@ -66,8 +66,8 @@ const cpp = name => lib => {
66
66
  if (typeof (t) === 'string') { return baseType(t) }
67
67
  if (t.length === 2) { return `${type(t[1])} const*` }
68
68
  const [id] = t
69
- if (lib[id].interface === undefined) { return id }
70
- return i(id)
69
+ if ('interface' in lib[id]) { return i(id) }
70
+ return id
71
71
  }
72
72
 
73
73
  const type = objectType(comRef)
@@ -101,7 +101,7 @@ const cpp = name => lib => {
101
101
  const paramArrayStr = `(${joinComma(mapParam(paramL))})`
102
102
  const m = methodHeader(result)(paramArrayStr)
103
103
  const resultName = interface_(paramArray._)
104
- if (resultName === undefined) {
104
+ if (resultName === null) {
105
105
  return [m(name)]
106
106
  }
107
107
  return [
@@ -127,15 +127,15 @@ const cpp = name => lib => {
127
127
  }
128
128
 
129
129
  /** @type {(kv: obj.Entry<types.Definition>) => text.Block} */
130
- const def = ([name, d]) => d.interface === undefined
131
- ? struct(name)(defStruct(d))
132
- : [
130
+ const def = ([name, d]) => 'interface' in d
131
+ ? [
133
132
  `class ${name} : public ::nanocom::IUnknown`,
134
133
  '{',
135
134
  'public:',
136
135
  defInterface(d),
137
136
  '};'
138
137
  ]
138
+ : struct(name)(defStruct(d))
139
139
 
140
140
  /** @type {(kv: obj.Entry<types.Definition>) => text.Block} */
141
141
  const forward = ([name]) => [`struct ${name};`]
@@ -96,14 +96,13 @@ const flatMapMethod = flatMap(method)
96
96
 
97
97
  /** @type {(e: obj.Entry<types.Definition>) => list.List<text.Item>} */
98
98
  const def = ([n, d]) => {
99
- const i = d.interface
100
- return i === undefined ?
99
+ return !('interface' in d) ?
101
100
  struct(n)(mapField(entries(d.struct))) :
102
101
  typeDef
103
102
  ([`Guid("${d.guid}")`, 'InterfaceType(ComInterfaceType.InterfaceIsIUnknown)'])
104
103
  ('interface')
105
104
  (n)
106
- (flatMapMethod(entries(i)))
105
+ (flatMapMethod(entries(d.interface)))
107
106
  }
108
107
 
109
108
  const flatMapDef = flatMap(def)
@@ -84,7 +84,7 @@ const whereContent = h => ({ where, content }) => {
84
84
 
85
85
  /** @type {(impl: Impl) => text.Block} */
86
86
  const rustImpl = i => {
87
- const p = i.param === undefined ? '' : `<${i.param}>`
87
+ const p = 'param' in i ? `<${i.param}>` : ''
88
88
  const header = `impl${p} ${i.trait} for ${i.type}`
89
89
  return whereContent(header)(i)
90
90
  }
@@ -135,7 +135,7 @@ const rust = library => {
135
135
  if (t.length === 2) { return `*const ${f(ref)(t[1])}` }
136
136
  const [id] = t
137
137
  const fullId = `${p}${id}`
138
- return library[id].interface === undefined ? fullId : o(fullId)
138
+ return 'interface' in library[id] ? o(fullId) : fullId
139
139
  }
140
140
  return f
141
141
  }
@@ -157,8 +157,7 @@ const rust = library => {
157
157
 
158
158
  /** @type {(first: readonly string[]) => (p: types.FieldArray) => string} */
159
159
  const func = first => p => {
160
- const result = p._
161
- const resultStr = result === undefined ? '' : ` -> ${type(super_)(ref)(result)}`
160
+ const resultStr = '_' in p ? ` -> ${type(super_)(ref)(p._)}` : ''
162
161
  const params = commaJoin(flat([first, mapParam(paramList(p))]))
163
162
  return `(${params})${resultStr}`
164
163
  }
@@ -248,7 +247,7 @@ const rust = library => {
248
247
  }
249
248
 
250
249
  /** @type {(type: object.Entry<types.Definition>) => text.Block} */
251
- const def = ([name, type]) => (type.interface === undefined ? struct(type.struct) : interface_(type))(name)
250
+ const def = ([name, type]) => ('interface' in type ? interface_(type) : struct(type.struct))(name)
252
251
 
253
252
  return flat([['#![allow(non_snake_case)]'], flatMap(def)(entries(library))])
254
253
  }
@@ -10,7 +10,6 @@ const { entries } = Object
10
10
 
11
11
  /**
12
12
  * @typedef {{
13
- * readonly interface?: undefined
14
13
  * readonly struct: FieldArray
15
14
  * }} Struct
16
15
  */
@@ -17,15 +17,15 @@
17
17
  // - `localPackageId` examples:
18
18
  // - `functionalscript`
19
19
 
20
- type PackageGet = (packageId: string) => Package | undefined
20
+ type PackageGet = (packageId: string) => Package | null
21
21
 
22
22
  // A local file id is
23
23
 
24
24
  type Package = {
25
25
  // returns a global package id.
26
- readonly dependency: (localPackageId: string) => string | undefined
26
+ readonly dependency: (localPackageId: string) => string | null
27
27
  // returns source of the file.
28
- readonly file: (localFileId: string) => string | undefined
28
+ readonly file: (localFileId: string) => string | null
29
29
  }
30
30
  ```
31
31
 
@@ -38,7 +38,7 @@ type Package = {
38
38
  //
39
39
  // A module is a compiled and initialized source file.
40
40
 
41
- type ModuleGet = (moduleId: string) => ModuleState | undefined
41
+ type ModuleGet = (moduleId: string) => ModuleState | null
42
42
 
43
43
  type ModuleMapInterface<M> = {
44
44
  readonly get: (moduleMap: M) => ModuleGet
@@ -55,10 +55,10 @@ const getOrBuild = compile => packageGet => moduleMapInterface => {
55
55
  /** @type {function_.Require<readonly[map.Map<string>, M]>} */
56
56
  const require_ = p => ([requireMap, m]) => {
57
57
  /** @type {(e: unknown) => function_.Result<readonly[map.Map<string>, M]>} */
58
- const error = e => [['error', 'file not found'], [requireMap, m]]
59
- if (moduleDir === undefined) { return error('file not found') }
58
+ const error = e => [['error', e], [requireMap, m]]
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
  }
@@ -38,10 +38,10 @@ const object = require('../../types/object/module.f.cjs')
38
38
  * }} Id
39
39
  */
40
40
 
41
- /** @type {(id: Id) => Id | undefined} */
41
+ /** @type {(id: Id) => Id | null} */
42
42
  const dir = id => {
43
43
  const len = id.path.length
44
- if (len < 1) { return undefined }
44
+ if (len < 1) { return null }
45
45
  return {
46
46
  package: id.package,
47
47
  path: id.path.slice(0, len - 1)
@@ -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/commonjs/test.cjs CHANGED
@@ -6,7 +6,7 @@ module.exports = {
6
6
  const source = 'module.exports = "Hello world!"'
7
7
  const m = _.compile(source)
8
8
  if (m[0] !== 'ok') { throw m }
9
- const [result] = m[1](() => { throw 0 })(undefined)
9
+ const [result] = m[1](() => { throw 0 })(null)
10
10
  if (result[0] !== 'ok') { throw result }
11
11
  if (result[1] !== 'Hello world!') { throw result }
12
12
  },
@@ -24,7 +24,7 @@ module.exports = {
24
24
  const source = 'a = 5'
25
25
  const m = _.compile(source)
26
26
  if (m[0] !== 'ok') { throw m }
27
- const [result] = m[1](() => { throw 0 })(undefined)
27
+ const [result] = m[1](() => { throw 0 })(null)
28
28
  if (result[0] !== 'error') { throw result }
29
29
  },
30
30
  test: () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "functionalscript",
3
- "version": "0.0.478",
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 }