functionalscript 0.0.561 → 0.0.563

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.
@@ -49,11 +49,15 @@ jobs:
49
49
 
50
50
  runs-on: ubuntu-latest
51
51
 
52
+ strategy:
53
+ matrix:
54
+ deno-version: [1.x, 2.x]
55
+
52
56
  steps:
53
57
  - uses: actions/checkout@v2
54
58
  - uses: denoland/setup-deno@v1
55
59
  with:
56
- deno-version: v1.x
60
+ deno-version: ${{ matrix.deno-version }}
57
61
  - run: deno run --quiet --allow-read --allow-env --allow-net --allow-hrtime ./dev/test.mjs
58
62
 
59
63
  bun:
package/html/module.f.cjs CHANGED
@@ -7,63 +7,38 @@ const { stringToList } = require('../text/utf16/module.f.cjs')
7
7
  const { fromCharCode } = String
8
8
  const { entries } = Object
9
9
 
10
- /**
11
- * @typedef {|
12
- * 'a' |
13
- * 'b' |
14
- * 'body' |
15
- * 'canvas' |
16
- * 'div' |
17
- * 'h1' |
18
- * 'h2' |
19
- * 'h3' |
20
- * 'h4' |
21
- * 'h5' |
22
- * 'h6' |
23
- * 'head' |
24
- * 'html' |
25
- * 'label' |
26
- * 'p' |
27
- * 'pre' |
28
- * 'script' |
29
- * 'table' |
30
- * 'td' |
31
- * 'th' |
32
- * 'title' |
33
- * 'tr'
34
- * } Tag
35
- */
36
-
37
- /**
38
- * https://developer.mozilla.org/en-US/docs/Glossary/Void_element
39
- *
40
- * @typedef {
41
- * | 'area'
42
- * | 'base'
43
- * | 'br'
44
- * | 'col'
45
- * | 'embed'
46
- * | 'hr'
47
- * | 'img'
48
- * | 'input'
49
- * | 'link'
50
- * | 'meta'
51
- * | 'param'
52
- * | 'source'
53
- * | 'track'
54
- * | 'wbr'
55
- * } VoidTag
56
- */
57
-
58
- /** @typedef {readonly[VoidTag]} VoidElement1*/
59
-
60
- /** @typedef {readonly[VoidTag, Attributes]} VoidElement2 */
61
-
62
- /** @typedef {readonly[Tag, readonly Node[]]} Element2 */
10
+ /** @typedef {string} Tag */
11
+
12
+ // https://developer.mozilla.org/en-US/docs/Glossary/Void_element
13
+ const voidTagList = [
14
+ 'area',
15
+ 'base',
16
+ 'br',
17
+ 'col',
18
+ 'embed',
19
+ 'hr',
20
+ 'img',
21
+ 'input',
22
+ 'link',
23
+ 'meta',
24
+ 'param',
25
+ 'source',
26
+ 'track',
27
+ 'wbr',
28
+ ]
29
+
30
+ /** @type {(tag: string) => boolean} */
31
+ const isVoid = tag => voidTagList.includes(tag)
32
+
33
+ /** @typedef {readonly[Tag]} Element1*/
34
+
35
+ /** @typedef {readonly[Tag, Attributes]} Element2A */
36
+
37
+ /** @typedef {readonly[Tag, readonly Node[]]} Element2N */
63
38
 
64
39
  /** @typedef {readonly[Tag, Attributes, Nodes]} Element3*/
65
40
 
66
- /** @typedef {VoidElement1 | VoidElement2 | Element2 | Element3} Element */
41
+ /** @typedef {Element1 | Element2A | Element2N | Element3} Element */
67
42
 
68
43
  /**
69
44
  * @typedef {{
@@ -103,29 +78,39 @@ const attribute = ([name, value]) => flat([[' ', name, '="'], escape(value), ['"
103
78
  /** @type {(a: Attributes) => list.List<string>} */
104
79
  const attributes = compose(entries)(flatMap(attribute))
105
80
 
81
+ const open = (/** @type {Element2A} */[tag, a]) => flat([[`<`, tag], attributes(a), [`>`]])
82
+
83
+ const close = (/** @type {string}*/tag) => ['</', tag, '>']
84
+
85
+ /** @type {(_: Element3) => list.List<string>} */
86
+ const element3 = ([tag, a, ns]) =>
87
+ flat([open([tag, a]), nodes(ns), close(tag)])
88
+
89
+ /** @type {(_: Element2A) => list.List<string>} */
90
+ const element2a = e => {
91
+ const [tag] = e
92
+ return flat([open(e), isVoid(tag) ? [] : close(tag)])
93
+ }
94
+
106
95
  /** @type {(element: Element) => list.List<string>} */
107
96
  const element = e => {
108
- const f = () => {
109
- switch (e.length) {
110
- case 1: { return [[`<`, e[0], '/>']] }
111
- case 2: {
112
- const [tag, a] = e
113
- return a instanceof Array ?
114
- [['<', tag, '>'], nodes(a), ['</', tag, '>']] :
115
- [[`<`, tag], attributes(a), [`/>`]]
116
- }
117
- default: {
118
- const [tag, a, ns] = e
119
- return [['<', tag], attributes(a), ['>'], nodes(ns), ['</', tag, '>']]
120
- }
97
+ switch (e.length) {
98
+ case 1: { return element2a([e[0], {}]) }
99
+ case 2: {
100
+ const [tag, a] = e
101
+ return a instanceof Array ?
102
+ element3([tag, {}, a]) :
103
+ element2a([tag, a])
104
+ }
105
+ default: {
106
+ return element3(e)
121
107
  }
122
108
  }
123
- return flat(f())
124
109
  }
125
110
 
126
111
  const html = compose(element)(listConcat(['<!DOCTYPE html>']))
127
112
 
128
- const htmlToString = compose(html)(stringConcat)
113
+ const htmlToString = compose(html)(stringConcat)
129
114
 
130
115
  module.exports = {
131
116
  /** @readonly */
package/html/test.f.cjs CHANGED
@@ -5,10 +5,30 @@ module.exports = {
5
5
  const r = _.htmlToString(['html', []])
6
6
  if (r !== '<!DOCTYPE html><html></html>') { throw r }
7
7
  },
8
+ empty2: () => {
9
+ const r = _.htmlToString(['html'])
10
+ if (r !== '<!DOCTYPE html><html></html>') { throw r }
11
+ },
12
+ void: () => {
13
+ const r = _.htmlToString(['area'])
14
+ if (r !== '<!DOCTYPE html><area>') { throw r }
15
+ },
8
16
  some: () => {
9
17
  /** @type {_.Element} */
10
18
  const x = ['div', {}, ['<div>&amp;</div>', ['a', { href: 'hello"' }, []]]]
11
19
  const s = _.htmlToString(x)
12
20
  if (s !== '<!DOCTYPE html><div>&lt;div&gt;&amp;amp;&lt;/div&gt;<a href="hello&quot;"></a></div>') { throw s }
21
+ },
22
+ some2: () => {
23
+ /** @type {_.Element} */
24
+ const x = ['div', ['<div>&amp;</div>', ['a', { href: 'hello"' }, []]]]
25
+ const s = _.htmlToString(x)
26
+ if (s !== '<!DOCTYPE html><div>&lt;div&gt;&amp;amp;&lt;/div&gt;<a href="hello&quot;"></a></div>') { throw s }
27
+ },
28
+ someVoid: () => {
29
+ /** @type {_.Element} */
30
+ const x = ['div', [['br', {id: '5'}], '<div>&amp;</div>', ['a', { href: 'hello"' }, []]]]
31
+ const s = _.htmlToString(x)
32
+ if (s !== '<!DOCTYPE html><div><br id="5">&lt;div&gt;&amp;amp;&lt;/div&gt;<a href="hello&quot;"></a></div>') { throw s }
13
33
  }
14
34
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "functionalscript",
3
- "version": "0.0.561",
3
+ "version": "0.0.563",
4
4
  "description": "FunctionalScript is a functional subset of JavaScript",
5
5
  "main": "module.f.cjs",
6
6
  "scripts": {
@@ -30,7 +30,7 @@
30
30
  },
31
31
  "homepage": "https://github.com/functionalscript/functionalscript#readme",
32
32
  "devDependencies": {
33
- "@types/node": "^22.0.0",
34
- "typescript": "^5.5.4"
33
+ "@types/node": "^22.9.0",
34
+ "typescript": "^5.6.3"
35
35
  }
36
36
  }