rooklang 0.3.4 → 0.4.1

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 (135) hide show
  1. package/README.md +33 -2
  2. package/README.ru.md +33 -2
  3. package/dist/ast/declarations.d.ts +19 -3
  4. package/dist/ast/expressions.d.ts +4 -8
  5. package/dist/ast/statements.d.ts +3 -1
  6. package/dist/bun-register.d.ts +1 -0
  7. package/dist/bun-register.js +9 -0
  8. package/dist/bun.d.ts +34 -0
  9. package/dist/bun.js +99 -0
  10. package/dist/checker/assignments.d.ts +2 -0
  11. package/dist/checker/assignments.js +9 -3
  12. package/dist/checker/base.d.ts +8 -2
  13. package/dist/checker/base.js +3 -3
  14. package/dist/checker/builtins.js +7 -3
  15. package/dist/checker/channels.js +1 -2
  16. package/dist/checker/classes.js +7 -1
  17. package/dist/checker/closing.js +1 -1
  18. package/dist/checker/completion.d.ts +1 -1
  19. package/dist/checker/completion.js +2 -1
  20. package/dist/checker/component-bindings.d.ts +7 -0
  21. package/dist/checker/component-bindings.js +45 -0
  22. package/dist/checker/component-values.js +10 -7
  23. package/dist/checker/components.d.ts +2 -2
  24. package/dist/checker/components.js +8 -3
  25. package/dist/checker/context.d.ts +28 -5
  26. package/dist/checker/context.js +23 -0
  27. package/dist/checker/control-flow.d.ts +6 -5
  28. package/dist/checker/control-flow.js +48 -40
  29. package/dist/checker/declarations.d.ts +2 -2
  30. package/dist/checker/declarations.js +3 -2
  31. package/dist/checker/decorator-exports.js +4 -0
  32. package/dist/checker/decorator-includes.d.ts +9 -0
  33. package/dist/checker/decorator-includes.js +71 -0
  34. package/dist/checker/decorator-members.d.ts +8 -10
  35. package/dist/checker/decorator-members.js +28 -31
  36. package/dist/checker/decorator-wrappers.d.ts +1 -1
  37. package/dist/checker/decorator-wrappers.js +3 -2
  38. package/dist/checker/decorators.d.ts +14 -5
  39. package/dist/checker/decorators.js +52 -25
  40. package/dist/checker/expressions.d.ts +1 -1
  41. package/dist/checker/expressions.js +7 -6
  42. package/dist/checker/flow.d.ts +25 -3
  43. package/dist/checker/flow.js +48 -8
  44. package/dist/checker/functions.d.ts +2 -2
  45. package/dist/checker/functions.js +9 -5
  46. package/dist/checker/helpers.d.ts +4 -1
  47. package/dist/checker/helpers.js +7 -2
  48. package/dist/checker/imports.js +5 -2
  49. package/dist/checker/loops.d.ts +2 -0
  50. package/dist/checker/loops.js +27 -2
  51. package/dist/checker/markup.js +14 -2
  52. package/dist/checker/members.js +3 -1
  53. package/dist/checker/shared-state.d.ts +11 -0
  54. package/dist/checker/shared-state.js +37 -0
  55. package/dist/checker/statements.d.ts +5 -2
  56. package/dist/checker/statements.js +51 -22
  57. package/dist/checker/tagged-unions.d.ts +37 -0
  58. package/dist/checker/tagged-unions.js +132 -0
  59. package/dist/checker/untyped-globals.d.ts +1 -0
  60. package/dist/checker/untyped-globals.js +3 -1
  61. package/dist/codegen/attributes.d.ts +4 -0
  62. package/dist/codegen/attributes.js +24 -2
  63. package/dist/codegen/component-helpers.d.ts +6 -1
  64. package/dist/codegen/component-helpers.js +6 -1
  65. package/dist/codegen/component-props.d.ts +11 -2
  66. package/dist/codegen/component-props.js +50 -5
  67. package/dist/codegen/components.d.ts +6 -5
  68. package/dist/codegen/components.js +44 -21
  69. package/dist/codegen/control-flow.d.ts +2 -0
  70. package/dist/codegen/control-flow.js +23 -9
  71. package/dist/codegen/creation.js +5 -2
  72. package/dist/codegen/early-returns.d.ts +4 -3
  73. package/dist/codegen/early-returns.js +17 -5
  74. package/dist/codegen/emitter.d.ts +3 -0
  75. package/dist/codegen/emitter.js +18 -4
  76. package/dist/codegen/expressions.js +0 -2
  77. package/dist/codegen/functions.d.ts +11 -1
  78. package/dist/codegen/functions.js +31 -3
  79. package/dist/codegen/live.d.ts +60 -0
  80. package/dist/codegen/live.js +29 -0
  81. package/dist/codegen/mutations.d.ts +7 -0
  82. package/dist/codegen/mutations.js +43 -2
  83. package/dist/codegen/options.d.ts +2 -0
  84. package/dist/codegen/reactive.d.ts +4 -59
  85. package/dist/codegen/reactive.js +34 -72
  86. package/dist/codegen/runtime.js +24 -7
  87. package/dist/codegen/shared.d.ts +22 -0
  88. package/dist/codegen/shared.js +93 -0
  89. package/dist/codegen/simple-statements.d.ts +1 -1
  90. package/dist/codegen/statements.d.ts +5 -0
  91. package/dist/codegen/statements.js +35 -0
  92. package/dist/codegen/updates.d.ts +11 -3
  93. package/dist/codegen/updates.js +52 -4
  94. package/dist/codegen/web-components.d.ts +2 -2
  95. package/dist/codegen/web-components.js +2 -2
  96. package/dist/compile-file.d.ts +4 -1
  97. package/dist/compile.d.ts +1 -1
  98. package/dist/compile.js +6 -2
  99. package/dist/decorator-copy.d.ts +1 -1
  100. package/dist/decorator-copy.js +1 -0
  101. package/dist/decorator-names.d.ts +14 -0
  102. package/dist/decorator-names.js +56 -0
  103. package/dist/decorators.d.ts +2 -3
  104. package/dist/decorators.js +36 -14
  105. package/dist/index.d.ts +1 -1
  106. package/dist/inline-packages.d.ts +2 -1
  107. package/dist/inline-packages.js +9 -4
  108. package/dist/loader.js +6 -19
  109. package/dist/names.d.ts +4 -0
  110. package/dist/names.js +29 -0
  111. package/dist/parser/base.d.ts +1 -0
  112. package/dist/parser/base.js +1 -1
  113. package/dist/parser/control-flow.d.ts +5 -0
  114. package/dist/parser/control-flow.js +28 -2
  115. package/dist/parser/declarations.d.ts +5 -15
  116. package/dist/parser/declarations.js +15 -119
  117. package/dist/parser/decorators.d.ts +6 -2
  118. package/dist/parser/decorators.js +43 -19
  119. package/dist/parser/params.d.ts +21 -0
  120. package/dist/parser/params.js +143 -0
  121. package/dist/parser/simple-statements.d.ts +1 -0
  122. package/dist/parser/simple-statements.js +22 -6
  123. package/dist/parser/statements.d.ts +5 -2
  124. package/dist/parser/statements.js +18 -11
  125. package/dist/run-cache.d.ts +7 -0
  126. package/dist/run-cache.js +24 -0
  127. package/dist/run-file.js +6 -1
  128. package/dist/runtime/sources.js +4 -3
  129. package/dist/walk.js +3 -3
  130. package/package.json +10 -2
  131. package/src/runtime/decode.js +41 -10
  132. package/src/runtime/go.js +10 -4
  133. package/src/runtime/index.js +1 -0
  134. package/src/runtime/markup.js +27 -17
  135. package/src/runtime/shared.js +17 -0
@@ -1,10 +1,10 @@
1
1
  // Markup: the owners of the blocks that `{if}`, `{switch}` and `{for}` remove, the
2
- // `mount()` of components, the blocks themselves, elements and the CSS of components.
2
+ // `mount` of components, the blocks themselves, elements and the CSS of components.
3
3
 
4
4
  import { $$runDeferred } from './core.js';
5
5
 
6
- // Owners of markup that `{if}`, `{switch}` and `{for}` may remove: the functions returned by the
7
- // `mount()` of its components, and the removal of the blocks inside it, run when it is removed.
6
+ // Owners of markup that `{if}`, `{switch}` and `{for}` may remove: what the `mount` and `effect`
7
+ // of its components deferred, and the removal of the blocks inside it, run when it is removed.
8
8
  // The current owner is shared by the modules of a page, since the blocks of one module may hold
9
9
  // the components of another.
10
10
  export const $$owner = Symbol.for('rook.owner');
@@ -36,15 +36,17 @@ export function $$onRemove(cleanup) {
36
36
  globalThis[$$owner]?.cleanups.push(cleanup);
37
37
  }
38
38
 
39
- // `mount() { ... }` of a component: runs when its markup is in the document. That is checked after
39
+ // `mount { ... }` of a component: runs when its markup is in the document. That is checked after
40
40
  // the code that creates the component; markup that is not in the document yet is waited for with a
41
41
  // MutationObserver, which watches only while some markup waits. Markup that its owner removes
42
- // before that never mounts. The function `mount` returns runs when the owner is removed.
42
+ // before that never mounts. What its `defer`s put into `cleanups` runs when the owner is removed;
43
+ // they are added to the owner once it mounts, so the cleanups of the decorators, which mount after
44
+ // the component, run before those of the component.
43
45
  export const $$waiting = new Set();
44
46
  export let $$observer = null;
45
47
 
46
- export function $$mount(node, mount) {
47
- const entry = { node, mount, owner: globalThis[$$owner] };
48
+ export function $$mount(node, mount, cleanups) {
49
+ const entry = { node, mount, cleanups, owner: globalThis[$$owner] };
48
50
 
49
51
  entry.owner?.cleanups.push(() => $$waiting.delete(entry));
50
52
  queueMicrotask(() => $$tryMount(entry));
@@ -65,9 +67,8 @@ export function $$tryMount(entry) {
65
67
  return;
66
68
  }
67
69
 
68
- const cleanup = entry.mount();
69
-
70
- if (typeof cleanup === 'function') entry.owner?.cleanups.push(cleanup);
70
+ entry.mount();
71
+ if (entry.cleanups) entry.owner?.cleanups.push(() => $$runDeferred(entry.cleanups.splice(0)));
71
72
  }
72
73
 
73
74
  export function $$mountWaiting() {
@@ -216,8 +217,10 @@ export function $$dynamic(component, create) {
216
217
 
217
218
  // `{for item in items { ... }}` in markup: a block for each item, between its own markers. On
218
219
  // updates the blocks are found again by the item itself: blocks of items that stay are updated and
219
- // moved into place, others are created or removed.
220
- export function $$list(items, create) {
220
+ // moved into place, others are created or removed. With `key`, of `with key item.id`, they are
221
+ // found by the key instead, so an item replaced by another with the same key keeps its block,
222
+ // which gets the new item.
223
+ export function $$list(items, create, key = (item) => item) {
221
224
  const end = document.createTextNode('');
222
225
  const fragment = document.createDocumentFragment();
223
226
 
@@ -236,24 +239,25 @@ export function $$list(items, create) {
236
239
  const old = new Map();
237
240
 
238
241
  for (const block of blocks) {
239
- const same = old.get(block.item);
242
+ const same = old.get(block.key);
240
243
 
241
244
  if (same) same.push(block);
242
- else old.set(block.item, [block]);
245
+ else old.set(block.key, [block]);
243
246
  }
244
247
 
245
248
  const next = [];
246
249
  let index = 0;
247
250
 
248
251
  for (const item of items()) {
249
- let block = old.get(item)?.shift();
252
+ const id = key(item, index);
253
+ let block = old.get(id)?.shift();
250
254
 
251
255
  if (block) {
252
- block.update?.(index);
256
+ block.update?.(index, item);
253
257
  } else {
254
258
  const [[content, blockUpdate], remove] = $$owned(() => create(item, index));
255
259
 
256
- block = { item, start: document.createTextNode(''), end: document.createTextNode('') };
260
+ block = { key: id, start: document.createTextNode(''), end: document.createTextNode('') };
257
261
  block.update = blockUpdate;
258
262
  block.remove = remove;
259
263
  block.content = document.createDocumentFragment();
@@ -315,6 +319,12 @@ export function $$svgElement(tag, attributes) {
315
319
  return element;
316
320
  }
317
321
 
322
+ // The class of `class={[styles.tab, active ? styles.active : null]}`: the classes that are not
323
+ // null or empty, separated by spaces.
324
+ export function $$classes(list) {
325
+ return list.filter((each) => each).join(' ');
326
+ }
327
+
318
328
  // Sets an attribute whose value may be null: then the attribute is removed.
319
329
  export function $$attribute(element, name, value) {
320
330
  if (value == null) element.removeAttribute(name);
@@ -0,0 +1,17 @@
1
+ // State of a module, `state items []Item = []` at its top level: the set of the updates of the
2
+ // components that read it, which every change of it runs.
3
+
4
+ import { $$onRemove } from './markup.js';
5
+
6
+ // A component adds its update while it is on the page: `{if}`, `{switch}` or `{for}` that removes
7
+ // it takes the update away.
8
+ export function $$watch(listeners, update) {
9
+ listeners.add(update);
10
+ $$onRemove(() => listeners.delete(update));
11
+ }
12
+
13
+ // After a change of the state: the updates run on a copy, since one may remove a component, or
14
+ // add one, that listens too.
15
+ export function $$changed(listeners) {
16
+ for (const update of [...listeners]) update();
17
+ }