@alloy-js/core 0.21.0-dev.1 → 0.21.0-dev.13

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 (99) hide show
  1. package/dist/src/binder.d.ts +3 -3
  2. package/dist/src/binder.d.ts.map +1 -1
  3. package/dist/src/binder.js +18 -4
  4. package/dist/src/binder.js.map +1 -1
  5. package/dist/src/components/ReferenceOrContent.d.ts +1 -1
  6. package/dist/src/components/ReferenceOrContent.d.ts.map +1 -1
  7. package/dist/src/index.d.ts +1 -0
  8. package/dist/src/index.d.ts.map +1 -1
  9. package/dist/src/index.js +1 -0
  10. package/dist/src/index.js.map +1 -1
  11. package/dist/src/library-symbol-reference.d.ts +8 -0
  12. package/dist/src/library-symbol-reference.d.ts.map +1 -0
  13. package/dist/src/library-symbol-reference.js +5 -0
  14. package/dist/src/library-symbol-reference.js.map +1 -0
  15. package/dist/src/pretty-string/pretty-string.d.ts +47 -0
  16. package/dist/src/pretty-string/pretty-string.d.ts.map +1 -0
  17. package/dist/src/pretty-string/pretty-string.js +100 -0
  18. package/dist/src/pretty-string/pretty-string.js.map +1 -0
  19. package/dist/src/pretty-string/pretty-string.test.d.ts +2 -0
  20. package/dist/src/pretty-string/pretty-string.test.d.ts.map +1 -0
  21. package/dist/src/pretty-string/pretty-string.test.js +38 -0
  22. package/dist/src/pretty-string/pretty-string.test.js.map +1 -0
  23. package/dist/src/reactivity.d.ts.map +1 -1
  24. package/dist/src/reactivity.js +4 -1
  25. package/dist/src/reactivity.js.map +1 -1
  26. package/dist/src/refkey.d.ts +12 -8
  27. package/dist/src/refkey.d.ts.map +1 -1
  28. package/dist/src/refkey.js +41 -12
  29. package/dist/src/refkey.js.map +1 -1
  30. package/dist/src/render.d.ts.map +1 -1
  31. package/dist/src/render.js +13 -4
  32. package/dist/src/render.js.map +1 -1
  33. package/dist/src/runtime/component.d.ts +22 -2
  34. package/dist/src/runtime/component.d.ts.map +1 -1
  35. package/dist/src/runtime/component.js +18 -0
  36. package/dist/src/runtime/component.js.map +1 -1
  37. package/dist/src/scheduler.d.ts +4 -4
  38. package/dist/src/scheduler.d.ts.map +1 -1
  39. package/dist/src/scheduler.js +10 -5
  40. package/dist/src/scheduler.js.map +1 -1
  41. package/dist/src/symbols/output-scope.js +4 -2
  42. package/dist/src/symbols/output-scope.js.map +1 -1
  43. package/dist/src/symbols/output-symbol.d.ts +9 -0
  44. package/dist/src/symbols/output-symbol.d.ts.map +1 -1
  45. package/dist/src/symbols/output-symbol.js +30 -0
  46. package/dist/src/symbols/output-symbol.js.map +1 -1
  47. package/dist/src/tracer.d.ts.map +1 -1
  48. package/dist/src/tracer.js +4 -4
  49. package/dist/src/tracer.js.map +1 -1
  50. package/dist/src/utils.d.ts +12 -0
  51. package/dist/src/utils.d.ts.map +1 -1
  52. package/dist/src/utils.js +15 -3
  53. package/dist/src/utils.js.map +1 -1
  54. package/dist/test/reactivity/circular-reactives.test.js +18 -0
  55. package/dist/test/reactivity/circular-reactives.test.js.map +1 -1
  56. package/dist/test/refkey.test.js +11 -1
  57. package/dist/test/refkey.test.js.map +1 -1
  58. package/dist/test/rendering/basic.test.js +22 -0
  59. package/dist/test/rendering/basic.test.js.map +1 -1
  60. package/dist/test/symbols/output-scope.test.js +4 -3
  61. package/dist/test/symbols/output-scope.test.js.map +1 -1
  62. package/dist/test/symbols/resolution.test.js +29 -1
  63. package/dist/test/symbols/resolution.test.js.map +1 -1
  64. package/dist/test/utils.test.js +13 -0
  65. package/dist/test/utils.test.js.map +1 -1
  66. package/dist/testing/create-test-wrapper.d.ts +22 -0
  67. package/dist/testing/create-test-wrapper.d.ts.map +1 -0
  68. package/dist/testing/create-test-wrapper.js +60 -0
  69. package/dist/testing/create-test-wrapper.js.map +1 -0
  70. package/dist/testing/index.d.ts +1 -0
  71. package/dist/testing/index.d.ts.map +1 -1
  72. package/dist/testing/index.js +1 -0
  73. package/dist/testing/index.js.map +1 -1
  74. package/dist/tsconfig.tsbuildinfo +1 -1
  75. package/package.json +1 -1
  76. package/src/binder.ts +34 -6
  77. package/src/index.ts +1 -0
  78. package/src/library-symbol-reference.ts +20 -0
  79. package/src/pretty-string/pretty-string.test.ts +47 -0
  80. package/src/pretty-string/pretty-string.ts +130 -0
  81. package/src/reactivity.ts +4 -1
  82. package/src/refkey.ts +68 -26
  83. package/src/render.ts +14 -3
  84. package/src/runtime/component.ts +33 -1
  85. package/src/scheduler.ts +12 -11
  86. package/src/symbols/output-scope.ts +4 -4
  87. package/src/symbols/output-symbol.ts +40 -0
  88. package/src/tracer.ts +5 -8
  89. package/src/utils.tsx +25 -4
  90. package/temp/api.json +854 -92
  91. package/test/reactivity/circular-reactives.test.tsx +20 -0
  92. package/test/refkey.test.ts +12 -1
  93. package/test/rendering/basic.test.tsx +35 -1
  94. package/test/symbols/output-scope.test.ts +4 -4
  95. package/test/symbols/resolution.test.ts +42 -1
  96. package/test/utils.test.tsx +18 -0
  97. package/testing/create-test-wrapper.tsx +70 -0
  98. package/testing/index.ts +1 -0
  99. package/tsconfig.json +1 -0
@@ -94,6 +94,11 @@ export interface OutputSymbolOptions {
94
94
  * also ignoring name conflict resolution.
95
95
  */
96
96
  ignoreNameConflict?: boolean;
97
+
98
+ /**
99
+ * Provide a function which lazy-initializes members when an enumeration of members are needed.
100
+ */
101
+ lazyMemberInitializer?: () => void;
97
102
  }
98
103
 
99
104
  let symbolCount = 0;
@@ -459,6 +464,40 @@ export abstract class OutputSymbol {
459
464
  return this.#namePolicy;
460
465
  }
461
466
 
467
+ #lazyMemberInitializer: (() => void) | undefined;
468
+ #lazyMembersInitialized: boolean = false;
469
+
470
+ #initializeMembers() {
471
+ if (this.#lazyMemberInitializer && !this.#lazyMembersInitialized) {
472
+ this.#lazyMemberInitializer();
473
+ }
474
+ this.#lazyMembersInitialized = true;
475
+ }
476
+
477
+ /**
478
+ * Get a member symbol by name from this symbol's member spaces. Checks member
479
+ * spaces in order until it finds a member with that name.
480
+ */
481
+ resolveMemberByName(name: string): OutputSymbol | undefined {
482
+ this.#initializeMembers();
483
+
484
+ if (this.isTyped) {
485
+ if (!this.hasTypeSymbol) {
486
+ return undefined;
487
+ }
488
+
489
+ return this.type!.resolveMemberByName(name);
490
+ }
491
+ for (const space of this.memberSpaces) {
492
+ const member = space.symbolNames.get(name);
493
+ if (member) {
494
+ return member;
495
+ }
496
+ }
497
+
498
+ return undefined;
499
+ }
500
+
462
501
  // Tell \@vue/reactivity that this symbol should never be wrapped in a reactive
463
502
  // proxy.
464
503
  [ReactiveFlags.SKIP] = true;
@@ -502,6 +541,7 @@ export abstract class OutputSymbol {
502
541
  this.#isTransient = !!options.transient;
503
542
  this.#isTyped = !!options.type;
504
543
  this.type = options.type;
544
+ this.#lazyMemberInitializer = options.lazyMemberInitializer;
505
545
 
506
546
  this.#handleNewSpaces(this.#spaces);
507
547
  const constructor = this.constructor as typeof OutputSymbol;
package/src/tracer.ts CHANGED
@@ -1,6 +1,6 @@
1
- import { effect, ReactiveEffectRunner } from "@vue/reactivity";
1
+ import { effect } from "@vue/reactivity";
2
2
  import { untrack } from "./reactivity.js";
3
- import { isMemberRefkey, type Refkey } from "./refkey.js";
3
+ import { inspectRefkey, type Refkey } from "./refkey.js";
4
4
  import { scheduler } from "./scheduler.js";
5
5
  import { type OutputScope } from "./symbols/output-scope.js";
6
6
  import type {
@@ -210,7 +210,7 @@ export function traceEffect(phase: TracePhase, cb: () => string) {
210
210
  let first = true;
211
211
  const triggerIds = new Set<number>();
212
212
 
213
- const runner: ReactiveEffectRunner<void> = effect(
213
+ effect(
214
214
  () => {
215
215
  if (first) {
216
216
  // just track what we need, don't log.
@@ -222,7 +222,7 @@ export function traceEffect(phase: TracePhase, cb: () => string) {
222
222
  triggerIds.clear();
223
223
  },
224
224
  {
225
- scheduler: scheduler(() => runner, true),
225
+ scheduler: scheduler(true),
226
226
  onTrigger(event) {
227
227
  const id = triggerCount++;
228
228
  if (dids.has(id)) {
@@ -429,10 +429,7 @@ export function formatRefkeys(refkeys: Refkey[] | Refkey | undefined) {
429
429
  }
430
430
 
431
431
  function formatRefkey(refkey: Refkey): string {
432
- const text =
433
- isMemberRefkey(refkey) ?
434
- `memberRefkey[${formatRefkey(refkey.base)} -> ${formatRefkey(refkey.member)}]`
435
- : `refkey[${refkey.key}]`;
432
+ const text = inspectRefkey(refkey);
436
433
 
437
434
  return colorText(text, {
438
435
  fg: {
package/src/utils.tsx CHANGED
@@ -56,6 +56,22 @@ export function mapJoin<T, U, V>(
56
56
  cb: (key: T, value: U, index: number) => V,
57
57
  options?: JoinOptions,
58
58
  ): () => (V | string | undefined | CustomContext)[];
59
+ /**
60
+ * Map a Map to an array using a mapper and place a joiner between each element.
61
+ * Defaults to joining with a newline.
62
+ *
63
+ * @see {@link join} for joining without mapping.
64
+ * @param src - Source map.
65
+ * @param cb - Mapper function.
66
+ * @param options - Join options.
67
+ * @returns The mapped and joined array.
68
+ *
69
+ */
70
+ export function mapJoin<U, V>(
71
+ src: () => Set<U>,
72
+ cb: (value: U, index: number) => V,
73
+ options?: JoinOptions,
74
+ ): () => (V | string | undefined | CustomContext)[];
59
75
  /**
60
76
  * Map a array or iterator to another array using a mapper and place a joiner
61
77
  * between each element. Defaults to joining with a newline.
@@ -72,7 +88,7 @@ export function mapJoin<T, V>(
72
88
  options?: JoinOptions,
73
89
  ): () => (V | string | undefined | CustomContext)[];
74
90
  export function mapJoin<T, U, V>(
75
- src: () => Map<T, U> | T[] | Iterable<T>,
91
+ src: () => Map<T, U> | Set<T> | T[] | Iterable<T>,
76
92
  cb: (key: T, valueOrIndex: U | number, index: number) => V,
77
93
  rawOptions: JoinOptions = {},
78
94
  ): () => Children {
@@ -94,6 +110,7 @@ export function mapJoin<T, U, V>(
94
110
  const itemsSourceRaw = toRaw(itemsSource);
95
111
  let items =
96
112
  Array.isArray(itemsSourceRaw) ? (itemsSource as T[]) : [...itemsSource];
113
+
97
114
  if (options.skipFalsy) {
98
115
  items = items.filter(
99
116
  (item) =>
@@ -103,8 +120,8 @@ export function mapJoin<T, U, V>(
103
120
  // this is important to access here in reactive context so we are
104
121
  // notified of new items from reactives.
105
122
  const itemsLen = items.length;
106
- const compare: any = getCompareFunction(itemsSource);
107
- const mapper: any = getMapperFunction(itemsSource);
123
+ const compare: any = getCompareFunction(itemsSourceRaw);
124
+ const mapper: any = getMapperFunction(itemsSourceRaw);
108
125
 
109
126
  return untrack(() => {
110
127
  let startIndex = 0;
@@ -160,7 +177,11 @@ export function mapJoin<T, U, V>(
160
177
  }
161
178
 
162
179
  function getMapperFunction(itemsSource: Map<T, U> | T[] | Iterable<T>) {
163
- return Array.isArray(itemsSource) || isIterable(itemsSource) ?
180
+ return (
181
+ Array.isArray(itemsSource) ||
182
+ itemsSource instanceof Set ||
183
+ isIterable(itemsSource)
184
+ ) ?
164
185
  mapArray
165
186
  : mapMap;
166
187
  }