functionalscript 0.0.478 → 0.0.479

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,8 +55,8 @@ 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
61
  if (r === undefined) { return error('file not found') }
62
62
  const rIdStr = idToString(r.id)
@@ -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)
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.479",
4
4
  "description": "FunctionalScript is a functional subset of JavaScript",
5
5
  "main": "module.f.cjs",
6
6
  "scripts": {