functionalscript 0.0.425 → 0.0.426

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 (2) hide show
  1. package/package.json +1 -1
  2. package/test.mjs +47 -17
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "functionalscript",
3
- "version": "0.0.425",
3
+ "version": "0.0.426",
4
4
  "description": "FunctionalScript is a functional subset of JavaScript",
5
5
  "main": "module.f.cjs",
6
6
  "scripts": {
package/test.mjs CHANGED
@@ -21,7 +21,18 @@
21
21
  /** @type {FsPromises} */
22
22
  const { readdir, readFile } = await import(globalThis.Deno ? 'https://deno.land/std/node/fs/promises.ts' : 'node:fs/promises')
23
23
 
24
- /** @typedef {{ exports?: unknown }} Module */
24
+ /**
25
+ * @typedef {{
26
+ * [k: in string]?: Module
27
+ * }} Dependencies
28
+ */
29
+
30
+ /**
31
+ * @typedef {{
32
+ * dependencies: Dependencies
33
+ * exports?: unknown
34
+ * }} Module
35
+ */
25
36
 
26
37
  /** @typedef {(name: string) => unknown} Require */
27
38
 
@@ -70,32 +81,42 @@ const map = await load()
70
81
 
71
82
  /**
72
83
  * @typedef {{
73
- * [k in string]: unknown
84
+ * [k in string]: Module
74
85
  * }} ModuleMap
75
86
  */
76
87
 
77
88
  const build = async () => {
78
89
  /** @type {ModuleMap} */
79
90
  const d = {}
80
- /** @type {(base: readonly string[]) => (i: string) => (k: string) => unknown} */
81
- const req = p => i => k => {
91
+ /** @type {(base: readonly string[]) => (i: string) => (k: string) => readonly[string, Module]} */
92
+ const req = base => i => k => {
82
93
  const relativePath = k.split('/')
83
94
  const dif = relativePath.filter(v => v === '..').length
84
- const path = [p.slice(0, p.length - dif), relativePath.filter(v => !['..', '.'].includes(v))]
95
+ const path = [base.slice(0, base.length - dif), relativePath.filter(v => !['..', '.'].includes(v))]
85
96
  .flat()
86
97
  const pathStr = path.join('/')
87
98
  const newBase = path.slice(0, path.length - 1)
88
- const result = d[pathStr]
89
- if (result === undefined) {
99
+ {
100
+ const module = d[pathStr]
101
+ if (module !== undefined) {
102
+ return [pathStr, module]
103
+ }
104
+ }
105
+ {
90
106
  /** @type {Module} */
91
- const me = {}
107
+ const module = {
108
+ dependencies: {}
109
+ }
92
110
  console.log(`${i}building ${pathStr}`)
93
- map[pathStr](me, req(newBase)(`${i}| `))
94
- const newResult = me.exports
95
- d[pathStr] = newResult
96
- return newResult
97
- } else {
98
- return result
111
+ const getModule = req(newBase)(`${i}| `)
112
+ const newReq = s => {
113
+ const [p, result] = getModule(s)
114
+ module.dependencies[p] = result
115
+ return result.exports
116
+ }
117
+ map[pathStr](module, newReq)
118
+ d[pathStr] = module
119
+ return [pathStr, module]
99
120
  }
100
121
  }
101
122
  const r = req(['.'])('')
@@ -107,6 +128,16 @@ const build = async () => {
107
128
 
108
129
  const modules = await build()
109
130
 
131
+ // graph
132
+
133
+ for (const [k, v] of Object.entries(modules)) {
134
+ console.log(`: ${k}`)
135
+ console.log(Object.keys(v.dependencies))
136
+ }
137
+
138
+ // test runner.
139
+
140
+ /** @type {(i: string) => (v: unknown) => void} */
110
141
  const test = i => v => {
111
142
  switch (typeof v) {
112
143
  case 'function': {
@@ -124,9 +155,8 @@ const test = i => v => {
124
155
  }
125
156
  } else {
126
157
  for (const [k, v2] of Object.entries(v)) {
127
- const i2 = `${i}| `
128
158
  console.log(`${i}${k}:`)
129
- test(i2)(v2)
159
+ test(`${i}| `)(v2)
130
160
  }
131
161
  }
132
162
  return;
@@ -137,6 +167,6 @@ const test = i => v => {
137
167
  for (const [k, v] of Object.entries(modules)) {
138
168
  if (k.endsWith('test.f.cjs')) {
139
169
  console.log(`testing ${k}`)
140
- test('| ')(v)
170
+ test('| ')(v.exports)
141
171
  }
142
172
  }