functionalscript 0.0.271 → 0.0.272

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.
@@ -18,24 +18,31 @@ const module_ = require("../module")
18
18
  /** @type {(path: string) => readonly string[]} */
19
19
  const split = path => path.split('/')
20
20
 
21
- /** @type {(s: undefined|list.List<string>) => (items: string) => undefined|list.List<string>} */
21
+ /** @typedef {readonly[list.List<string>] | undefined} OptionList */
22
+
23
+ /** @type {(s: OptionList) => (items: string) => OptionList} */
22
24
  const normItemsOp = prior => item => {
23
25
  if (prior === undefined) { return undefined }
26
+ const priorList = prior[0]
24
27
  switch (item) {
25
28
  case '': case '.': { return prior }
26
29
  case '..': {
27
- const result = list.next(prior)
30
+ const result = list.next(priorList)
28
31
  if (result === undefined) { return undefined }
29
- return result.tail
32
+ return [result.tail]
30
33
  }
31
34
  default: {
32
- return list.nonEmpty(item)(prior)
35
+ return [list.nonEmpty(item)(priorList)]
33
36
  }
34
37
  }
35
38
  }
36
39
 
37
- /** @type {(items: list.List<string>) => list.List<string>|undefined} */
38
- const normItems = compose(list.reduce(normItemsOp)([]))(option.map(list.reverse))
40
+ /** @type {(items: list.List<string>) => OptionList} */
41
+ const normItems = items => {
42
+ const result = list.reduce(normItemsOp)([undefined])(items)
43
+ if (result === undefined) { return result }
44
+ return [list.reverse(result[0])]
45
+ }
39
46
 
40
47
  /** @type {(local: string) => (path: string) => LocalPath|undefined} */
41
48
  const parseLocal = local => {
@@ -55,7 +62,7 @@ const parseLocal = local => {
55
62
  return {
56
63
  external,
57
64
  dir: path[path.length - 1] === '/',
58
- items: list.toArray(n)
65
+ items: list.toArray(n[0])
59
66
  }
60
67
  }
61
68
  return f
@@ -116,7 +123,13 @@ const parse = packageId => dependencies => local => path => {
116
123
  return parseGlobal(dependencies)(dir)(items)
117
124
  }
118
125
 
119
- /** @typedef {readonly[string, string] | undefined} Result */
126
+ /**
127
+ * @typedef {{
128
+ * readonly package: string
129
+ * readonly file: string
130
+ * readonly source: string
131
+ * }| undefined} Result
132
+ */
120
133
 
121
134
  /**
122
135
  * @type {(packageGet: package_.Get) =>
@@ -133,10 +146,10 @@ const parseAndFind = packageGet => packageId => local => path => {
133
146
  if (p === undefined) { return undefined }
134
147
  const pack = packageGet(p.packageId)
135
148
  if (pack === undefined) { return undefined }
136
- /** @type {(fileId: string) => Result } */
137
- const tryFile = fileId => {
138
- const source = pack.file(fileId)
139
- return source === undefined ? undefined : [fileId, source]
149
+ /** @type {(file: string) => Result } */
150
+ const tryFile = file => {
151
+ const source = pack.file(file)
152
+ return source === undefined ? undefined : { package: p.packageId, file, source }
140
153
  }
141
154
  const file = p.items.join('/')
142
155
  const indexJs = list.join('/')(list.concat(p.items)(['index.js']))
@@ -1,7 +1,10 @@
1
1
  const _ = require('.')
2
+ const { todo } = require('../../dev')
2
3
  const json = require('../../json')
3
4
  const { identity } = require('../../types/function')
5
+ const object = require('../../types/object')
4
6
  const { at } = require('../../types/object')
7
+ const package_ = require('../package')
5
8
 
6
9
  /** @type {(g: json.Unknown|undefined) => string} */
7
10
  const stringify = g => {
@@ -51,15 +54,101 @@ const stringify = g => {
51
54
  if (_.parseGlobal(d => at(d)({ b: 'x' }))(false)(['d']) !== undefined) { throw 'error' }
52
55
  {
53
56
  const result = stringify(_.parseGlobal(d => at(d)({ b: 'x' }))(false)(['b']))
54
- if (result !== '["x",""]') { throw result }
57
+ if (result !== '{"packageId":"x","items":[],"dir":false}') { throw result }
55
58
  }
56
59
  if (_.parseGlobal(d => at(d)({ 'b/r': 'x' }))(false)(['b']) !== undefined) { throw 'error' }
57
60
  {
58
61
  const result = stringify(_.parseGlobal(d => at(d)({ 'b/r': 'x' }))(false)(['b', 'r']))
59
- if (result !== '["x",""]') { throw result }
62
+ if (result !== '{"packageId":"x","items":[],"dir":false}') { throw result }
60
63
  }
61
64
  {
62
65
  const result = stringify(_.parseGlobal(d => at(d)({ 'b/r': 'x' }))(false)(['b', 'r', 'd', 't']))
63
- if (result !== '["x","d/t"]') { throw result }
66
+ if (result !== '{"packageId":"x","items":["d","t"],"dir":false}') { throw result }
64
67
  }
68
+ {
69
+ const result = stringify(_.parseGlobal(d => at(d)({ 'b/r': 'x' }))(true)(['b', 'r', 'd', 't']))
70
+ if (result !== '{"packageId":"x","items":["d","t"],"dir":true}') { throw result }
71
+ }
72
+ }
73
+
74
+ {
75
+ /** @type {object.Map<package_.Package>} */
76
+ const packages = {
77
+ '': {
78
+ dependency: () => todo(),
79
+ file: path => at(path)({ 'a/c': 'return "a/c"' }),
80
+ }
81
+ }
82
+ const result = stringify(_.parseAndFind(p => at(p)(packages))('')('a/b')('../c'))
83
+ if (result !== '{"package":"","file":"a/c","source":"return \\"a/c\\""}') { throw result }
65
84
  }
85
+
86
+ {
87
+ /** @type {object.Map<package_.Package>} */
88
+ const packages = {
89
+ '': {
90
+ dependency: x => {
91
+ const path = `node_modules/${x}`
92
+ return at(path)(packages) !== undefined ? path : undefined
93
+ },
94
+ file: todo
95
+ },
96
+ 'node_modules/z': {
97
+ dependency: () => todo(),
98
+ file: path => at(path)({ 'a/c/index.js': 'return "a/c"' }),
99
+ }
100
+ }
101
+ const result = stringify(_.parseAndFind(p => at(p)(packages))('')('a/b')('z/a/c'))
102
+ if (result !== '{"package":"node_modules/z","file":"a/c/index.js","source":"return \\"a/c\\""}') { throw result }
103
+ }
104
+
105
+ {
106
+ /** @type {object.Map<package_.Package>} */
107
+ const packages = {
108
+ '': {
109
+ dependency: x => {
110
+ const path = `node_modules/${x}`
111
+ return at(path)(packages) !== undefined ? path : undefined
112
+ },
113
+ file: todo
114
+ },
115
+ 'node_modules/z/a': {
116
+ dependency: () => todo(),
117
+ file: path => at(path)({
118
+ 'c/index.js': 'return "c/index.js"',
119
+ 'c.js': 'return "c.js"'
120
+ }),
121
+ }
122
+ }
123
+ {
124
+ const result = stringify(_.parseAndFind(p => at(p)(packages))('')('a/b')('z/a/c'))
125
+ if (result !== '{"package":"node_modules/z/a","file":"c.js","source":"return \\"c.js\\""}') { throw result }
126
+ }
127
+ {
128
+ const result = stringify(_.parseAndFind(p => at(p)(packages))('')('a/b')('z/a/c/'))
129
+ if (result !== '{"package":"node_modules/z/a","file":"c/index.js","source":"return \\"c/index.js\\""}') { throw result }
130
+ }
131
+ }
132
+
133
+ {
134
+ /** @type {object.Map<package_.Package>} */
135
+ const packages = {
136
+ '': {
137
+ dependency: x => {
138
+ const path = `node_modules/${x}`
139
+ return at(path)(packages) !== undefined ? path : undefined
140
+ },
141
+ file: todo
142
+ },
143
+ 'node_modules/z/a/c': {
144
+ dependency: () => todo(),
145
+ file: path => at(path)({
146
+ '': 'throw',
147
+ '.js': 'throw',
148
+ 'index.js': 'return "a/c"'
149
+ }),
150
+ }
151
+ }
152
+ const result = stringify(_.parseAndFind(p => at(p)(packages))('')('a/b')('z/a/c'))
153
+ if (result !== '{"package":"node_modules/z/a/c","file":"index.js","source":"return \\"a/c\\""}') { throw result }
154
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "functionalscript",
3
- "version": "0.0.271",
3
+ "version": "0.0.272",
4
4
  "description": "FunctionalScript is a functional subset of JavaScript",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/test.js CHANGED
@@ -7,6 +7,7 @@ require('./types/object/test')
7
7
  require('./io/commonjs/test')
8
8
  require('./commonjs/package/dependencies/test')
9
9
  require('./commonjs/package/test')
10
+ require('./commonjs/path/test')
10
11
 
11
12
  /** @type {() => never} */
12
13
  const assert = () => { throw 'assert' }
@@ -100,12 +101,12 @@ const assert_if = c => { if (c) { throw 'assert_if' } }
100
101
  //const c = o['__defineGetter__']
101
102
  //const c = o['__defineSetter__']
102
103
  //const c = o['__lookupGetter__']
103
- //const c = o['__lookupSetter__']
104
- //const c = o['hasOwnProperty']
104
+ //const c = o['__lookupSetter__']
105
+ //const c = o['hasOwnProperty']
105
106
  //const c = o['isPrototypeOf']
106
107
  //const c = o['propertyIsEnumerable']
107
108
  //const c = o['toString']
108
- const c = o['valueOf']
109
+ const c = o['valueOf']
109
110
  //console.log(c)
110
111
  }
111
112
 
@@ -329,7 +329,7 @@ const stress = () => {
329
329
  }
330
330
  }
331
331
 
332
- stress()
332
+ // stress()
333
333
 
334
334
  module.exports = {
335
335