solid-js 1.8.1 → 1.8.2

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 (45) hide show
  1. package/dist/dev.cjs +5 -1
  2. package/dist/dev.js +301 -532
  3. package/dist/server.cjs +18 -4
  4. package/dist/server.js +89 -170
  5. package/dist/solid.cjs +5 -1
  6. package/dist/solid.js +259 -459
  7. package/h/dist/h.js +8 -34
  8. package/h/jsx-runtime/dist/jsx.js +1 -1
  9. package/h/jsx-runtime/types/index.d.ts +8 -11
  10. package/h/types/hyperscript.d.ts +11 -11
  11. package/html/dist/html.js +94 -216
  12. package/html/types/lit.d.ts +31 -45
  13. package/package.json +2 -2
  14. package/store/dist/dev.js +42 -114
  15. package/store/dist/server.js +8 -19
  16. package/store/dist/store.js +39 -105
  17. package/store/types/index.d.ts +7 -21
  18. package/store/types/modifiers.d.ts +3 -6
  19. package/store/types/mutable.d.ts +2 -5
  20. package/store/types/server.d.ts +4 -12
  21. package/store/types/store.d.ts +61 -218
  22. package/types/index.d.ts +9 -72
  23. package/types/reactive/array.d.ts +4 -12
  24. package/types/reactive/observable.d.ts +17 -25
  25. package/types/reactive/scheduler.d.ts +6 -9
  26. package/types/reactive/signal.d.ts +140 -228
  27. package/types/render/Suspense.d.ts +5 -5
  28. package/types/render/component.d.ts +31 -62
  29. package/types/render/flow.d.ts +31 -43
  30. package/types/render/hydration.d.ts +14 -14
  31. package/types/server/index.d.ts +2 -56
  32. package/types/server/reactive.d.ts +44 -68
  33. package/types/server/rendering.d.ts +95 -166
  34. package/universal/dist/dev.js +12 -28
  35. package/universal/dist/universal.js +12 -28
  36. package/universal/types/index.d.ts +1 -3
  37. package/universal/types/universal.d.ts +1 -0
  38. package/web/dist/dev.js +81 -617
  39. package/web/dist/server.cjs +1 -1
  40. package/web/dist/server.js +93 -176
  41. package/web/dist/web.js +80 -611
  42. package/web/types/client.d.ts +2 -2
  43. package/web/types/core.d.ts +1 -10
  44. package/web/types/index.d.ts +10 -27
  45. package/web/types/server-mock.d.ts +32 -47
package/html/dist/html.js CHANGED
@@ -1,29 +1,7 @@
1
- import {
2
- effect,
3
- style,
4
- insert,
5
- untrack,
6
- spread,
7
- createComponent,
8
- delegateEvents,
9
- classList,
10
- mergeProps,
11
- dynamicProperty,
12
- setAttribute,
13
- setAttributeNS,
14
- addEventListener,
15
- Aliases,
16
- getPropAlias,
17
- Properties,
18
- ChildProperties,
19
- DelegatedEvents,
20
- SVGElements,
21
- SVGNamespace
22
- } from "solid-js/web";
1
+ import { effect, style, insert, untrack, spread, createComponent, delegateEvents, classList, mergeProps, dynamicProperty, setAttribute, setAttributeNS, addEventListener, Aliases, getPropAlias, Properties, ChildProperties, DelegatedEvents, SVGElements, SVGNamespace } from 'solid-js/web';
23
2
 
24
3
  const tagRE = /(?:<!--[\S\s]*?-->|<(?:"[^"]*"['"]*|'[^']*'['"]*|[^'">])+>)/g;
25
- const attrRE =
26
- /(?:\s(?<boolean>[^/\s><=]+?)(?=[\s/>]))|(?:(?<name>\S+?)(?:\s*=\s*(?:(['"])(?<quotedValue>[\s\S]*?)\3|(?<unquotedValue>[^\s>]+))))/g;
4
+ const attrRE = /(?:\s(?<boolean>[^/\s><=]+?)(?=[\s/>]))|(?:(?<name>\S+?)(?:\s*=\s*(?:(['"])(?<quotedValue>[\s\S]*?)\3|(?<unquotedValue>[^\s>]+))))/g;
27
5
  const lookup = {
28
6
  area: true,
29
7
  base: true,
@@ -42,10 +20,10 @@ const lookup = {
42
20
  track: true,
43
21
  wbr: true
44
22
  };
45
- function parseTag(tag) {
23
+ function parseTag( tag) {
46
24
  const res = {
47
- type: "tag",
48
- name: "",
25
+ type: 'tag',
26
+ name: '',
49
27
  voidElement: false,
50
28
  attrs: [],
51
29
  children: []
@@ -53,50 +31,50 @@ function parseTag(tag) {
53
31
  const tagMatch = tag.match(/<\/?([^\s]+?)[/\s>]/);
54
32
  if (tagMatch) {
55
33
  res.name = tagMatch[1];
56
- if (lookup[tagMatch[1].toLowerCase()] || tag.charAt(tag.length - 2) === "/") {
34
+ if (lookup[tagMatch[1].toLowerCase()] || tag.charAt(tag.length - 2) === '/') {
57
35
  res.voidElement = true;
58
36
  }
59
- if (res.name.startsWith("!--")) {
60
- const endIndex = tag.indexOf("-->");
37
+ if (res.name.startsWith('!--')) {
38
+ const endIndex = tag.indexOf('-->');
61
39
  return {
62
- type: "comment",
63
- comment: endIndex !== -1 ? tag.slice(4, endIndex) : ""
40
+ type: 'comment',
41
+ comment: endIndex !== -1 ? tag.slice(4, endIndex) : ''
64
42
  };
65
43
  }
66
44
  }
67
45
  const reg = new RegExp(attrRE);
68
46
  for (const match of tag.matchAll(reg)) {
69
- if ((match[1] || match[2]).startsWith("use:")) {
47
+ if ((match[1] || match[2]).startsWith('use:')) {
70
48
  res.attrs.push({
71
- type: "directive",
49
+ type: 'directive',
72
50
  name: match[1] || match[2],
73
- value: match[4] || match[5] || ""
51
+ value: match[4] || match[5] || ''
74
52
  });
75
53
  } else {
76
54
  res.attrs.push({
77
- type: "attr",
55
+ type: 'attr',
78
56
  name: match[1] || match[2],
79
- value: match[4] || match[5] || ""
57
+ value: match[4] || match[5] || ''
80
58
  });
81
59
  }
82
60
  }
83
61
  return res;
84
62
  }
85
63
  function pushTextNode(list, html, start) {
86
- const end = html.indexOf("<", start);
64
+ const end = html.indexOf('<', start);
87
65
  const content = html.slice(start, end === -1 ? void 0 : end);
88
66
  if (!/^\s*$/.test(content)) {
89
67
  list.push({
90
- type: "text",
68
+ type: 'text',
91
69
  content: content
92
70
  });
93
71
  }
94
72
  }
95
73
  function pushCommentNode(list, tag) {
96
- const content = tag.replace("<!--", "").replace("-->", "");
74
+ const content = tag.replace('<!--', '').replace('-->', '');
97
75
  if (!/^\s*$/.test(content)) {
98
76
  list.push({
99
- type: "comment",
77
+ type: 'comment',
100
78
  content: content
101
79
  });
102
80
  }
@@ -108,15 +86,15 @@ function parse(html) {
108
86
  const arr = [];
109
87
  const byTag = {};
110
88
  html.replace(tagRE, (tag, index) => {
111
- const isOpen = tag.charAt(1) !== "/";
112
- const isComment = tag.slice(0, 4) === "<!--";
89
+ const isOpen = tag.charAt(1) !== '/';
90
+ const isComment = tag.slice(0, 4) === '<!--';
113
91
  const start = index + tag.length;
114
92
  const nextChar = html.charAt(start);
115
93
  let parent = void 0;
116
94
  if (isOpen && !isComment) {
117
95
  level++;
118
96
  current = parseTag(tag);
119
- if (!current.voidElement && nextChar && nextChar !== "<") {
97
+ if (!current.voidElement && nextChar && nextChar !== '<') {
120
98
  pushTextNode(current.children, html, start);
121
99
  }
122
100
  byTag[current.tagName] = current;
@@ -140,7 +118,7 @@ function parse(html) {
140
118
  if (!isComment) {
141
119
  level--;
142
120
  }
143
- if (nextChar !== "<" && nextChar) {
121
+ if (nextChar !== '<' && nextChar) {
144
122
  parent = level === -1 ? result : arr[level].children;
145
123
  pushTextNode(parent, html, start);
146
124
  }
@@ -151,47 +129,41 @@ function parse(html) {
151
129
  function attrString(attrs) {
152
130
  const buff = [];
153
131
  for (const attr of attrs) {
154
- buff.push(attr.name + '="' + attr.value.replace(/"/g, "&quot;") + '"');
132
+ buff.push(attr.name + '="' + attr.value.replace(/"/g, '&quot;') + '"');
155
133
  }
156
134
  if (!buff.length) {
157
- return "";
135
+ return '';
158
136
  }
159
- return " " + buff.join(" ");
137
+ return ' ' + buff.join(' ');
160
138
  }
161
139
  function stringifier(buff, doc) {
162
140
  switch (doc.type) {
163
- case "text":
141
+ case 'text':
164
142
  return buff + doc.content;
165
- case "tag":
166
- buff +=
167
- "<" + doc.name + (doc.attrs ? attrString(doc.attrs) : "") + (doc.voidElement ? "/>" : ">");
143
+ case 'tag':
144
+ buff += '<' + doc.name + (doc.attrs ? attrString(doc.attrs) : '') + (doc.voidElement ? '/>' : '>');
168
145
  if (doc.voidElement) {
169
146
  return buff;
170
147
  }
171
- return buff + doc.children.reduce(stringifier, "") + "</" + doc.name + ">";
172
- case "comment":
173
- return (buff += "<!--" + doc.content + "-->");
148
+ return buff + doc.children.reduce(stringifier, '') + '</' + doc.name + '>';
149
+ case 'comment':
150
+ return buff += '<!--' + doc.content + '-->';
174
151
  }
175
152
  }
176
153
  function stringify(doc) {
177
154
  return doc.reduce(function (token, rootEl) {
178
- return token + stringifier("", rootEl);
179
- }, "");
155
+ return token + stringifier('', rootEl);
156
+ }, '');
180
157
  }
181
158
  const cache = new Map();
182
- const VOID_ELEMENTS =
183
- /^(?:area|base|br|col|embed|hr|img|input|keygen|link|menuitem|meta|param|source|track|wbr)$/i;
159
+ const VOID_ELEMENTS = /^(?:area|base|br|col|embed|hr|img|input|keygen|link|menuitem|meta|param|source|track|wbr)$/i;
184
160
  const spaces = " \\f\\n\\r\\t";
185
161
  const almostEverything = "[^" + spaces + "\\/>\"'=]+";
186
- const attrName = "[ " + spaces + "]+(?:use:<!--#-->|" + almostEverything + ")";
162
+ const attrName = "[ " + spaces + "]+(?:use:<!--#-->|" + almostEverything + ')';
187
163
  const tagName = "<([A-Za-z$#]+[A-Za-z0-9:_-]*)((?:";
188
- const attrPartials =
189
- "(?:\\s*=\\s*(?:'[^']*?'|\"[^\"]*?\"|\\([^)]*?\\)|<[^>]*?>|" + almostEverything + "))?)";
164
+ const attrPartials = "(?:\\s*=\\s*(?:'[^']*?'|\"[^\"]*?\"|\\([^)]*?\\)|<[^>]*?>|" + almostEverything + "))?)";
190
165
  const attrSeeker = new RegExp(tagName + attrName + attrPartials + "+)([ " + spaces + "]*/?>)", "g");
191
- const findAttributes = new RegExp(
192
- "(" + attrName + "\\s*=\\s*)(<!--#-->|['\"(]([\\w\\s]*<!--#-->[\\w\\s]*)*['\")])",
193
- "gi"
194
- );
166
+ const findAttributes = new RegExp("(" + attrName + "\\s*=\\s*)(<!--#-->|['\"(]([\\w\\s]*<!--#-->[\\w\\s]*)*['\")])", "gi");
195
167
  const selfClosing = new RegExp(tagName + attrName + attrPartials + "*)([ " + spaces + "]*/>)", "g");
196
168
  const marker = "<!--#-->";
197
169
  const reservedNameSpaces = new Set(["class", "on", "oncapture", "style", "use", "prop", "attr"]);
@@ -199,10 +171,7 @@ function attrReplacer($0, $1, $2, $3) {
199
171
  return "<" + $1 + $2.replace(findAttributes, replaceAttributes) + $3;
200
172
  }
201
173
  function replaceAttributes($0, $1, $2) {
202
- return (
203
- $1.replace(/<!--#-->/g, "###") +
204
- ($2[0] === '"' || $2[0] === "'" ? $2.replace(/<!--#-->/g, "###") : '"###"')
205
- );
174
+ return $1.replace(/<!--#-->/g, "###") + ($2[0] === '"' || $2[0] === "'" ? $2.replace(/<!--#-->/g, "###") : '"###"');
206
175
  }
207
176
  function fullClosing($0, $1, $2) {
208
177
  return VOID_ELEMENTS.test($1) ? $0 : "<" + $1 + $2 + "></" + $1 + ">";
@@ -211,19 +180,17 @@ function toPropertyName(name) {
211
180
  return name.toLowerCase().replace(/-([a-z])/g, (_, w) => w.toUpperCase());
212
181
  }
213
182
  function parseDirective(name, value, tag, options) {
214
- if (name === "use:###" && value === "###") {
183
+ if (name === 'use:###' && value === '###') {
215
184
  const count = options.counter++;
216
- options.exprs.push(
217
- `typeof exprs[${count}] === "function" ? r.use(exprs[${count}], ${tag}, exprs[${options.counter++}]) : (()=>{throw new Error("use:### must be a function")})()`
218
- );
185
+ options.exprs.push(`typeof exprs[${count}] === "function" ? r.use(exprs[${count}], ${tag}, exprs[${options.counter++}]) : (()=>{throw new Error("use:### must be a function")})()`);
219
186
  } else {
220
187
  throw new Error(`Not support syntax ${name} must be use:{function}`);
221
188
  }
222
189
  }
223
- function createHTML(
224
- r,
225
- { delegateEvents = true, functionBuilder = (...args) => new Function(...args) } = {}
226
- ) {
190
+ function createHTML(r, {
191
+ delegateEvents = true,
192
+ functionBuilder = (...args) => new Function(...args)
193
+ } = {}) {
227
194
  let uuid = 1;
228
195
  r.wrapProps = props => {
229
196
  const d = Object.getOwnPropertyDescriptors(props);
@@ -239,16 +206,7 @@ function createHTML(
239
206
  markup = markup + statics[i] + "<!--#-->";
240
207
  }
241
208
  markup = markup + statics[i];
242
- const replaceList = [
243
- [selfClosing, fullClosing],
244
- [/<(<!--#-->)/g, "<###"],
245
- [/\.\.\.(<!--#-->)/g, "###"],
246
- [attrSeeker, attrReplacer],
247
- [/>\n+\s*/g, ">"],
248
- [/\n+\s*</g, "<"],
249
- [/\s+</g, " <"],
250
- [/>\s+/g, "> "]
251
- ];
209
+ const replaceList = [[selfClosing, fullClosing], [/<(<!--#-->)/g, "<###"], [/\.\.\.(<!--#-->)/g, "###"], [attrSeeker, attrReplacer], [/>\n+\s*/g, ">"], [/\n+\s*</g, "<"], [/\s+</g, " <"], [/>\s+/g, "> "]];
252
210
  markup = replaceList.reduce((acc, x) => {
253
211
  return acc.replace(x[0], x[1]);
254
212
  }, markup);
@@ -276,19 +234,7 @@ function createHTML(
276
234
  return templates;
277
235
  }
278
236
  function parseKeyValue(node, tag, name, value, isSVG, isCE, options) {
279
- let expr =
280
- value === "###"
281
- ? `!doNotWrap ? exprs[${options.counter}]() : exprs[${options.counter++}]`
282
- : value
283
- .split("###")
284
- .map((v, i) =>
285
- i
286
- ? ` + (typeof exprs[${options.counter}] === "function" ? exprs[${
287
- options.counter
288
- }]() : exprs[${options.counter++}]) + "${v}"`
289
- : `"${v}"`
290
- )
291
- .join(""),
237
+ let expr = value === "###" ? `!doNotWrap ? exprs[${options.counter}]() : exprs[${options.counter++}]` : value.split("###").map((v, i) => i ? ` + (typeof exprs[${options.counter}] === "function" ? exprs[${options.counter}]() : exprs[${options.counter++}]) + "${v}"` : `"${v}"`).join(""),
292
238
  parts,
293
239
  namespace;
294
240
  if ((parts = name.split(":")) && parts[1] && reservedNameSpaces.has(parts[0])) {
@@ -305,21 +251,12 @@ function createHTML(
305
251
  const prev = `_$v${uuid++}`;
306
252
  options.decl.push(`${prev}={}`);
307
253
  options.exprs.push(`r.classList(${tag},${expr},${prev})`);
308
- } else if (
309
- namespace !== "attr" &&
310
- (isChildProp ||
311
- (!isSVG && (r.getPropAlias(name, node.name.toUpperCase()) || isProp)) ||
312
- isCE ||
313
- namespace === "prop")
314
- ) {
254
+ } else if (namespace !== "attr" && (isChildProp || !isSVG && (r.getPropAlias(name, node.name.toUpperCase()) || isProp) || isCE || namespace === "prop")) {
315
255
  if (isCE && !isChildProp && !isProp && namespace !== "prop") name = toPropertyName(name);
316
- options.exprs.push(
317
- `${tag}.${r.getPropAlias(name, node.name.toUpperCase()) || name} = ${expr}`
318
- );
256
+ options.exprs.push(`${tag}.${r.getPropAlias(name, node.name.toUpperCase()) || name} = ${expr}`);
319
257
  } else {
320
258
  const ns = isSVG && name.indexOf(":") > -1 && r.SVGNamespace[name.split(":")[0]];
321
- if (ns) options.exprs.push(`r.setAttributeNS(${tag},"${ns}","${name}",${expr})`);
322
- else options.exprs.push(`r.setAttribute(${tag},"${r.Aliases[name] || name}",${expr})`);
259
+ if (ns) options.exprs.push(`r.setAttributeNS(${tag},"${ns}","${name}",${expr})`);else options.exprs.push(`r.setAttribute(${tag},"${r.Aliases[name] || name}",${expr})`);
323
260
  }
324
261
  }
325
262
  function parseAttribute(node, tag, name, value, isSVG, isCE, options) {
@@ -327,17 +264,11 @@ function createHTML(
327
264
  if (!name.includes(":")) {
328
265
  const lc = name.slice(2).toLowerCase();
329
266
  const delegate = delegateEvents && r.DelegatedEvents.has(lc);
330
- options.exprs.push(
331
- `r.addEventListener(${tag},"${lc}",exprs[${options.counter++}],${delegate})`
332
- );
267
+ options.exprs.push(`r.addEventListener(${tag},"${lc}",exprs[${options.counter++}],${delegate})`);
333
268
  delegate && options.delegatedEvents.add(lc);
334
269
  } else {
335
270
  let capture = name.startsWith("oncapture:");
336
- options.exprs.push(
337
- `${tag}.addEventListener("${name.slice(capture ? 10 : 3)}",exprs[${options.counter++}]${
338
- capture ? ",true" : ""
339
- })`
340
- );
271
+ options.exprs.push(`${tag}.addEventListener("${name.slice(capture ? 10 : 3)}",exprs[${options.counter++}]${capture ? ",true" : ""})`);
341
272
  }
342
273
  } else if (name === "ref") {
343
274
  options.exprs.push(`exprs[${options.counter++}](${tag})`);
@@ -347,15 +278,9 @@ function createHTML(
347
278
  }),
348
279
  count = options.counter;
349
280
  parseKeyValue(node, tag, name, value, isSVG, isCE, childOptions);
350
- options.decl.push(
351
- `_fn${count} = (${value === "###" ? "doNotWrap" : ""}) => {\n${childOptions.exprs.join(
352
- ";\n"
353
- )};\n}`
354
- );
281
+ options.decl.push(`_fn${count} = (${value === "###" ? "doNotWrap" : ""}) => {\n${childOptions.exprs.join(";\n")};\n}`);
355
282
  if (value === "###") {
356
- options.exprs.push(
357
- `typeof exprs[${count}] === "function" ? r.effect(_fn${count}) : _fn${count}(true)`
358
- );
283
+ options.exprs.push(`typeof exprs[${count}] === "function" ? r.effect(_fn${count}) : _fn${count}(true)`);
359
284
  } else {
360
285
  let check = "";
361
286
  for (let i = count; i < childOptions.counter; i++) {
@@ -377,10 +302,7 @@ function createHTML(
377
302
  if (node.children.length > 1) {
378
303
  for (let i = 0; i < node.children.length; i++) {
379
304
  const child = node.children[i];
380
- if (
381
- (child.type === "comment" && child.content === "#") ||
382
- (child.type === "tag" && child.name === "###")
383
- ) {
305
+ if (child.type === "comment" && child.content === "#" || child.type === "tag" && child.name === "###") {
384
306
  childOptions.multi = true;
385
307
  break;
386
308
  }
@@ -401,9 +323,7 @@ function createHTML(
401
323
  continue;
402
324
  }
403
325
  parseNode(child, childOptions);
404
- if (!childOptions.multi && child.type === "comment" && child.content === "#")
405
- node.children.splice(i, 1);
406
- else i++;
326
+ if (!childOptions.multi && child.type === "comment" && child.content === "#") node.children.splice(i, 1);else i++;
407
327
  }
408
328
  options.counter = childOptions.counter;
409
329
  options.templateId = childOptions.templateId;
@@ -425,28 +345,26 @@ function createHTML(
425
345
  propGroups = [props],
426
346
  componentIdentifier = options.counter++;
427
347
  for (let i = 0; i < keys.length; i++) {
428
- const { type, name, value } = node.attrs[i];
429
- if (type === "attr") {
348
+ const {
349
+ type,
350
+ name,
351
+ value
352
+ } = node.attrs[i];
353
+ if (type === 'attr') {
430
354
  if (name === "###") {
431
355
  propGroups.push(`exprs[${options.counter++}]`);
432
- propGroups.push((props = []));
356
+ propGroups.push(props = []);
433
357
  } else if (value === "###") {
434
358
  props.push(`${name}: exprs[${options.counter++}]`);
435
359
  } else props.push(`${name}: "${value}"`);
436
- } else if (type === "directive") {
360
+ } else if (type === 'directive') {
437
361
  const tag = `_$el${uuid++}`;
438
362
  const topDecl = !options.decl.length;
439
- options.decl.push(
440
- topDecl ? "" : `${tag} = ${options.path}.${options.first ? "firstChild" : "nextSibling"}`
441
- );
363
+ options.decl.push(topDecl ? "" : `${tag} = ${options.path}.${options.first ? "firstChild" : "nextSibling"}`);
442
364
  parseDirective(name, value, tag, options);
443
365
  }
444
366
  }
445
- if (
446
- node.children.length === 1 &&
447
- node.children[0].type === "comment" &&
448
- node.children[0].content === "#"
449
- ) {
367
+ if (node.children.length === 1 && node.children[0].type === "comment" && node.children[0].content === "#") {
450
368
  props.push(`children: () => exprs[${options.counter++}]`);
451
369
  } else if (node.children.length) {
452
370
  const children = {
@@ -469,20 +387,7 @@ function createHTML(
469
387
  tag = `_$el${uuid++}`;
470
388
  options.decl.push(`${tag} = ${options.path}.${options.first ? "firstChild" : "nextSibling"}`);
471
389
  }
472
- if (options.parent)
473
- options.exprs.push(
474
- `r.insert(${
475
- options.parent
476
- }, r.createComponent(exprs[${componentIdentifier}],${processComponentProps(propGroups)})${
477
- tag ? `, ${tag}` : ""
478
- })`
479
- );
480
- else
481
- options.exprs.push(
482
- `${
483
- options.fragment ? "" : "return "
484
- }r.createComponent(exprs[${componentIdentifier}],${processComponentProps(propGroups)})`
485
- );
390
+ if (options.parent) options.exprs.push(`r.insert(${options.parent}, r.createComponent(exprs[${componentIdentifier}],${processComponentProps(propGroups)})${tag ? `, ${tag}` : ""})`);else options.exprs.push(`${options.fragment ? "" : "return "}r.createComponent(exprs[${componentIdentifier}],${processComponentProps(propGroups)})`);
486
391
  options.path = tag;
487
392
  options.first = false;
488
393
  }
@@ -513,21 +418,13 @@ function createHTML(
513
418
  });
514
419
  options.templateNodes.push([child]);
515
420
  parseNode(child, childOptions);
516
- parts.push(
517
- `function() { ${
518
- childOptions.decl.join(",\n") +
519
- ";\n" +
520
- childOptions.exprs.join(";\n") +
521
- `;\nreturn _$el${id};\n`
522
- }}()`
523
- );
421
+ parts.push(`function() { ${childOptions.decl.join(",\n") + ";\n" + childOptions.exprs.join(";\n") + `;\nreturn _$el${id};\n`}}()`);
524
422
  options.counter = childOptions.counter;
525
423
  options.templateId = childOptions.templateId;
526
424
  } else if (child.type === "text") {
527
425
  parts.push(`"${child.content}"`);
528
426
  } else if (child.type === "comment") {
529
- if (child.content === "#") parts.push(`exprs[${options.counter++}]`);
530
- else if (child.content) {
427
+ if (child.content === "#") parts.push(`exprs[${options.counter++}]`);else if (child.content) {
531
428
  for (let i = 0; i < child.content.split("###").length - 1; i++) {
532
429
  parts.push(`exprs[${options.counter++}]`);
533
430
  }
@@ -539,9 +436,7 @@ function createHTML(
539
436
  const tag = `_$el${uuid++}`;
540
437
  const topDecl = !options.decl.length;
541
438
  const templateId = options.templateId;
542
- options.decl.push(
543
- topDecl ? "" : `${tag} = ${options.path}.${options.first ? "firstChild" : "nextSibling"}`
544
- );
439
+ options.decl.push(topDecl ? "" : `${tag} = ${options.path}.${options.first ? "firstChild" : "nextSibling"}`);
545
440
  const isSVG = r.SVGElements.has(node.name);
546
441
  const isCE = node.name.includes("-");
547
442
  options.hasCustomElement = isCE;
@@ -550,13 +445,15 @@ function createHTML(
550
445
  let current = "";
551
446
  const newAttrs = [];
552
447
  for (let i = 0; i < node.attrs.length; i++) {
553
- const { type, name, value } = node.attrs[i];
554
- if (type === "attr") {
448
+ const {
449
+ type,
450
+ name,
451
+ value
452
+ } = node.attrs[i];
453
+ if (type === 'attr') {
555
454
  if (value.includes("###")) {
556
455
  let count = options.counter++;
557
- current += `${name}: ${
558
- name !== "ref" ? `typeof exprs[${count}] === "function" ? exprs[${count}]() : ` : ""
559
- }exprs[${count}],`;
456
+ current += `${name}: ${name !== "ref" ? `typeof exprs[${count}] === "function" ? exprs[${count}]() : ` : ""}exprs[${count}],`;
560
457
  } else if (name === "###") {
561
458
  if (current.length) {
562
459
  spreadArgs.push(`()=>({${current}})`);
@@ -566,7 +463,7 @@ function createHTML(
566
463
  } else {
567
464
  newAttrs.push(node.attrs[i]);
568
465
  }
569
- } else if (type === "directive") {
466
+ } else if (type === 'directive') {
570
467
  parseDirective(name, value, tag, options);
571
468
  }
572
469
  }
@@ -574,17 +471,15 @@ function createHTML(
574
471
  if (current.length) {
575
472
  spreadArgs.push(`()=>({${current}})`);
576
473
  }
577
- options.exprs.push(
578
- `r.spread(${tag},${
579
- spreadArgs.length === 1
580
- ? `typeof ${spreadArgs[0]} === "function" ? r.mergeProps(${spreadArgs[0]}) : ${spreadArgs[0]}`
581
- : `r.mergeProps(${spreadArgs.join(",")})`
582
- },${isSVG},${!!node.children.length})`
583
- );
474
+ options.exprs.push(`r.spread(${tag},${spreadArgs.length === 1 ? `typeof ${spreadArgs[0]} === "function" ? r.mergeProps(${spreadArgs[0]}) : ${spreadArgs[0]}` : `r.mergeProps(${spreadArgs.join(",")})`},${isSVG},${!!node.children.length})`);
584
475
  } else {
585
476
  for (let i = 0; i < node.attrs.length; i++) {
586
- const { type, name, value } = node.attrs[i];
587
- if (type === "directive") {
477
+ const {
478
+ type,
479
+ name,
480
+ value
481
+ } = node.attrs[i];
482
+ if (type === 'directive') {
588
483
  parseDirective(name, value, tag, options);
589
484
  node.attrs.splice(i, 1);
590
485
  i--;
@@ -601,9 +496,7 @@ function createHTML(
601
496
  options.first = false;
602
497
  processChildren(node, options);
603
498
  if (topDecl) {
604
- options.decl[0] = options.hasCustomElement
605
- ? `const ${tag} = r.untrack(() => document.importNode(tmpls[${templateId}].content.firstChild, true))`
606
- : `const ${tag} = tmpls[${templateId}].content.firstChild.cloneNode(true)`;
499
+ options.decl[0] = options.hasCustomElement ? `const ${tag} = r.untrack(() => document.importNode(tmpls[${templateId}].content.firstChild, true))` : `const ${tag} = tmpls[${templateId}].content.firstChild.cloneNode(true)`;
607
500
  }
608
501
  } else if (node.type === "text") {
609
502
  const tag = `_$el${uuid++}`;
@@ -638,12 +531,10 @@ function createHTML(
638
531
  origNodes = nodes;
639
532
  let toplevel;
640
533
  if (nodes.length > 1) {
641
- nodes = [
642
- {
643
- type: "fragment",
644
- children: nodes
645
- }
646
- ];
534
+ nodes = [{
535
+ type: "fragment",
536
+ children: nodes
537
+ }];
647
538
  }
648
539
  if (nodes[0].name === "###") {
649
540
  toplevel = true;
@@ -651,25 +542,12 @@ function createHTML(
651
542
  } else parseNode(nodes[0], options);
652
543
  r.delegateEvents(Array.from(options.delegatedEvents));
653
544
  const templateNodes = [origNodes].concat(options.templateNodes);
654
- return [
655
- templateNodes.map(t => stringify(t)),
656
- funcBuilder(
657
- "tmpls",
658
- "exprs",
659
- "r",
660
- options.decl.join(",\n") +
661
- ";\n" +
662
- options.exprs.join(";\n") +
663
- (toplevel ? "" : `;\nreturn _$el${id};\n`)
664
- )
665
- ];
545
+ return [templateNodes.map(t => stringify(t)), funcBuilder("tmpls", "exprs", "r", options.decl.join(",\n") + ";\n" + options.exprs.join(";\n") + (toplevel ? "" : `;\nreturn _$el${id};\n`))];
666
546
  }
667
547
  function html(statics, ...args) {
668
- const templates =
669
- cache.get(statics) ||
670
- createTemplate(statics, {
671
- funcBuilder: functionBuilder
672
- });
548
+ const templates = cache.get(statics) || createTemplate(statics, {
549
+ funcBuilder: functionBuilder
550
+ });
673
551
  return templates[0].create(templates, args, r);
674
552
  }
675
553
  return html;
@@ -1,53 +1,39 @@
1
1
  type MountableElement = Element | Document | ShadowRoot | DocumentFragment | Node;
2
2
  interface Runtime {
3
- effect<T>(fn: (prev?: T) => T, init?: T): any;
4
- untrack<T>(fn: () => T): T;
5
- insert(parent: MountableElement, accessor: any, marker?: Node | null, init?: any): any;
6
- spread<T>(node: Element, accessor: (() => T) | T, isSVG?: Boolean, skipChildren?: Boolean): void;
7
- createComponent(Comp: (props: any) => any, props: any): any;
8
- addEventListener(node: Element, name: string, handler: () => void, delegate: boolean): void;
9
- delegateEvents(eventNames: string[]): void;
10
- classList(
11
- node: Element,
12
- value: {
13
- [k: string]: boolean;
14
- },
15
- prev?: {
16
- [k: string]: boolean;
17
- }
18
- ): void;
19
- style(
20
- node: Element,
21
- value: {
22
- [k: string]: string;
23
- },
24
- prev?: {
25
- [k: string]: string;
26
- }
27
- ): void;
28
- mergeProps(...sources: unknown[]): unknown;
29
- dynamicProperty(props: any, key: string): any;
30
- setAttribute(node: Element, name: string, value: any): void;
31
- setAttributeNS(node: Element, namespace: string, name: string, value: any): void;
32
- Aliases: Record<string, string>;
33
- getPropAlias(prop: string, tagName: string): string | undefined;
34
- Properties: Set<string>;
35
- ChildProperties: Set<string>;
36
- DelegatedEvents: Set<string>;
37
- SVGElements: Set<string>;
38
- SVGNamespace: Record<string, string>;
3
+ effect<T>(fn: (prev?: T) => T, init?: T): any;
4
+ untrack<T>(fn: () => T): T;
5
+ insert(parent: MountableElement, accessor: any, marker?: Node | null, init?: any): any;
6
+ spread<T>(node: Element, accessor: (() => T) | T, isSVG?: Boolean, skipChildren?: Boolean): void;
7
+ createComponent(Comp: (props: any) => any, props: any): any;
8
+ addEventListener(node: Element, name: string, handler: () => void, delegate: boolean): void;
9
+ delegateEvents(eventNames: string[]): void;
10
+ classList(node: Element, value: {
11
+ [k: string]: boolean;
12
+ }, prev?: {
13
+ [k: string]: boolean;
14
+ }): void;
15
+ style(node: Element, value: {
16
+ [k: string]: string;
17
+ }, prev?: {
18
+ [k: string]: string;
19
+ }): void;
20
+ mergeProps(...sources: unknown[]): unknown;
21
+ dynamicProperty(props: any, key: string): any;
22
+ setAttribute(node: Element, name: string, value: any): void;
23
+ setAttributeNS(node: Element, namespace: string, name: string, value: any): void;
24
+ Aliases: Record<string, string>;
25
+ getPropAlias(prop: string, tagName: string): string | undefined;
26
+ Properties: Set<string>;
27
+ ChildProperties: Set<string>;
28
+ DelegatedEvents: Set<string>;
29
+ SVGElements: Set<string>;
30
+ SVGNamespace: Record<string, string>;
39
31
  }
40
32
  export type HTMLTag = {
41
- (statics: TemplateStringsArray, ...args: unknown[]): Node | Node[];
33
+ (statics: TemplateStringsArray, ...args: unknown[]): Node | Node[];
42
34
  };
43
- export declare function createHTML(
44
- r: Runtime,
45
- {
46
- delegateEvents,
47
- functionBuilder
48
- }?: {
35
+ export declare function createHTML(r: Runtime, { delegateEvents, functionBuilder }?: {
49
36
  delegateEvents?: boolean;
50
37
  functionBuilder?: (...args: string[]) => Function;
51
- }
52
- ): HTMLTag;
38
+ }): HTMLTag;
53
39
  export {};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "solid-js",
3
3
  "description": "A declarative JavaScript library for building user interfaces.",
4
- "version": "1.8.1",
4
+ "version": "1.8.2",
5
5
  "author": "Ryan Carniato",
6
6
  "license": "MIT",
7
7
  "homepage": "https://solidjs.com",
@@ -206,7 +206,7 @@
206
206
  ],
207
207
  "dependencies": {
208
208
  "csstype": "^3.1.0",
209
- "seroval": "^0.10.4"
209
+ "seroval": "^0.11.6"
210
210
  },
211
211
  "scripts": {
212
212
  "build": "npm-run-all -nl build:*",