@alloy-js/core 0.20.0-dev.3 → 0.20.0-dev.6

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 (137) hide show
  1. package/dist/src/binder.d.ts +62 -38
  2. package/dist/src/binder.d.ts.map +1 -1
  3. package/dist/src/binder.js +214 -173
  4. package/dist/src/components/Declaration.d.ts +2 -2
  5. package/dist/src/components/Declaration.d.ts.map +1 -1
  6. package/dist/src/components/Declaration.js +8 -2
  7. package/dist/src/components/MemberDeclaration.d.ts +2 -2
  8. package/dist/src/components/MemberDeclaration.d.ts.map +1 -1
  9. package/dist/src/components/MemberDeclaration.js +9 -5
  10. package/dist/src/components/MemberScope.d.ts +30 -13
  11. package/dist/src/components/MemberScope.d.ts.map +1 -1
  12. package/dist/src/components/MemberScope.js +37 -15
  13. package/dist/src/components/Output.d.ts.map +1 -1
  14. package/dist/src/components/Output.js +2 -5
  15. package/dist/src/components/ReferenceOrContent.d.ts +1 -1
  16. package/dist/src/components/ReferenceOrContent.d.ts.map +1 -1
  17. package/dist/src/components/Scope.d.ts +5 -5
  18. package/dist/src/components/Scope.d.ts.map +1 -1
  19. package/dist/src/components/Scope.js +9 -5
  20. package/dist/src/context/member-scope.d.ts +7 -8
  21. package/dist/src/context/member-scope.d.ts.map +1 -1
  22. package/dist/src/context/member-scope.js +5 -5
  23. package/dist/src/context/name-policy.d.ts.map +1 -1
  24. package/dist/src/context/name-policy.js +3 -0
  25. package/dist/src/context/scope.d.ts +1 -0
  26. package/dist/src/context/scope.d.ts.map +1 -1
  27. package/dist/src/context/scope.js +7 -0
  28. package/dist/src/inspect.browser.d.ts +5 -0
  29. package/dist/src/inspect.browser.d.ts.map +1 -0
  30. package/dist/src/inspect.browser.js +5 -0
  31. package/dist/src/inspect.d.ts +2 -0
  32. package/dist/src/inspect.d.ts.map +1 -0
  33. package/dist/src/inspect.js +1 -0
  34. package/dist/src/name-policy.d.ts +11 -0
  35. package/dist/src/name-policy.d.ts.map +1 -1
  36. package/dist/src/name-policy.js +3 -0
  37. package/dist/src/reactive-union-set.d.ts.map +1 -1
  38. package/dist/src/reactive-union-set.js +12 -8
  39. package/dist/src/refkey.d.ts +39 -3
  40. package/dist/src/refkey.d.ts.map +1 -1
  41. package/dist/src/refkey.js +52 -8
  42. package/dist/src/symbols/basic-scope.d.ts +14 -0
  43. package/dist/src/symbols/basic-scope.d.ts.map +1 -0
  44. package/dist/src/symbols/basic-scope.js +20 -0
  45. package/dist/src/symbols/basic-symbol.d.ts +19 -0
  46. package/dist/src/symbols/basic-symbol.d.ts.map +1 -0
  47. package/dist/src/symbols/basic-symbol.js +28 -0
  48. package/dist/src/symbols/index.d.ts +3 -1
  49. package/dist/src/symbols/index.d.ts.map +1 -1
  50. package/dist/src/symbols/index.js +3 -1
  51. package/dist/src/symbols/output-scope.d.ts +70 -41
  52. package/dist/src/symbols/output-scope.d.ts.map +1 -1
  53. package/dist/src/symbols/output-scope.js +98 -130
  54. package/dist/src/symbols/output-space.d.ts +25 -0
  55. package/dist/src/symbols/output-space.d.ts.map +1 -0
  56. package/dist/src/symbols/output-space.js +35 -0
  57. package/dist/src/symbols/output-symbol.d.ts +213 -37
  58. package/dist/src/symbols/output-symbol.d.ts.map +1 -1
  59. package/dist/src/symbols/output-symbol.js +323 -203
  60. package/dist/src/symbols/symbol-flow.d.ts +1 -1
  61. package/dist/src/symbols/symbol-flow.d.ts.map +1 -1
  62. package/dist/src/symbols/symbol-flow.js +22 -7
  63. package/dist/src/symbols/symbol-slot.d.ts +27 -9
  64. package/dist/src/symbols/symbol-slot.d.ts.map +1 -1
  65. package/dist/src/symbols/symbol-slot.js +20 -4
  66. package/dist/src/symbols/symbol-table.d.ts +19 -8
  67. package/dist/src/symbols/symbol-table.d.ts.map +1 -1
  68. package/dist/src/symbols/symbol-table.js +65 -16
  69. package/dist/src/tracer.d.ts +15 -3
  70. package/dist/src/tracer.d.ts.map +1 -1
  71. package/dist/src/tracer.js +39 -63
  72. package/dist/src/utils.d.ts +1 -1
  73. package/dist/src/utils.d.ts.map +1 -1
  74. package/dist/src/utils.js +4 -4
  75. package/dist/src/write-output.d.ts +1 -1
  76. package/dist/src/write-output.d.ts.map +1 -1
  77. package/dist/src/write-output.js +31 -37
  78. package/dist/test/components/declaration.test.js +9 -14
  79. package/dist/test/components/reference-or-content.test.js +2 -2
  80. package/dist/test/symbols/output-scope.test.js +33 -198
  81. package/dist/test/symbols/output-symbol.test.js +139 -385
  82. package/dist/test/symbols/resolution.test.js +431 -114
  83. package/dist/test/symbols/symbol-table.test.d.ts +2 -0
  84. package/dist/test/symbols/symbol-table.test.d.ts.map +1 -0
  85. package/dist/test/symbols/symbol-table.test.js +14 -0
  86. package/dist/test/symbols/utils.d.ts +10 -24
  87. package/dist/test/symbols/utils.d.ts.map +1 -1
  88. package/dist/test/symbols/utils.js +23 -45
  89. package/dist/tsconfig.tsbuildinfo +1 -1
  90. package/package.json +4 -2
  91. package/src/binder.ts +348 -273
  92. package/src/components/Declaration.tsx +13 -3
  93. package/src/components/MemberDeclaration.tsx +15 -8
  94. package/src/components/MemberScope.tsx +61 -20
  95. package/src/components/Output.tsx +0 -4
  96. package/src/components/Scope.tsx +16 -9
  97. package/src/context/member-scope.ts +10 -10
  98. package/src/context/name-policy.ts +3 -0
  99. package/src/context/scope.ts +9 -0
  100. package/src/inspect.browser.ts +6 -0
  101. package/src/inspect.ts +1 -0
  102. package/src/name-policy.ts +14 -0
  103. package/src/reactive-union-set.ts +14 -8
  104. package/src/refkey.ts +88 -14
  105. package/src/symbols/basic-scope.ts +23 -0
  106. package/src/symbols/basic-symbol.ts +32 -0
  107. package/src/symbols/index.ts +3 -1
  108. package/src/symbols/output-scope.ts +131 -170
  109. package/src/symbols/output-space.ts +49 -0
  110. package/src/symbols/output-symbol.ts +434 -258
  111. package/src/symbols/symbol-flow.ts +38 -9
  112. package/src/symbols/symbol-slot.tsx +46 -8
  113. package/src/symbols/symbol-table.ts +95 -21
  114. package/src/tracer.ts +53 -83
  115. package/src/utils.tsx +4 -4
  116. package/src/write-output.ts +33 -45
  117. package/temp/api.json +5551 -3066
  118. package/test/components/declaration.test.tsx +6 -19
  119. package/test/components/reference-or-content.test.tsx +2 -2
  120. package/test/symbols/output-scope.test.ts +33 -125
  121. package/test/symbols/output-symbol.test.ts +128 -348
  122. package/test/symbols/resolution.test.ts +530 -117
  123. package/test/symbols/symbol-table.test.ts +15 -0
  124. package/test/symbols/utils.ts +38 -74
  125. package/tsdoc.json +4 -0
  126. package/dist/src/slot.d.ts +0 -15
  127. package/dist/src/slot.d.ts.map +0 -1
  128. package/dist/src/slot.js +0 -50
  129. package/dist/src/symbols/flags.d.ts +0 -70
  130. package/dist/src/symbols/flags.d.ts.map +0 -1
  131. package/dist/src/symbols/flags.js +0 -72
  132. package/dist/test/components/slot.test.d.ts +0 -2
  133. package/dist/test/components/slot.test.d.ts.map +0 -1
  134. package/dist/test/components/slot.test.js +0 -134
  135. package/src/slot.ts +0 -89
  136. package/src/symbols/flags.ts +0 -82
  137. package/test/components/slot.test.tsx +0 -174
@@ -0,0 +1,15 @@
1
+ import { describe, expect, it } from "vitest";
2
+ import { createScope, createSymbol } from "./utils.js";
3
+
4
+ describe("OutputSymbol#moveTo", () => {
5
+ it("moves the symbol to a new symbol table", () => {
6
+ const scope = createScope("scope");
7
+ const [symbol] = createSymbol("sym", scope);
8
+ expect(symbol.spaces).toEqual([scope.symbols]);
9
+ const newScope = createScope("new-scope");
10
+ scope.symbols.moveTo(newScope.symbols);
11
+ expect(scope.symbols.has(symbol)).toBe(false);
12
+ expect(newScope.symbols.has(symbol)).toBe(true);
13
+ expect(symbol.spaces).toEqual([newScope.symbols]);
14
+ });
15
+ });
@@ -1,93 +1,57 @@
1
- import { Binder } from "../../src/index.browser.js";
2
- import { Refkey, refkey } from "../../src/refkey.js";
3
- import {
4
- OutputScopeFlags,
5
- OutputSymbolFlags,
6
- } from "../../src/symbols/flags.js";
7
- import { OutputScope } from "../../src/symbols/output-scope.js";
8
- import { OutputSymbol } from "../../src/symbols/output-symbol.js";
1
+ import { beforeEach } from "vitest";
2
+ import { Binder, createOutputBinder } from "../../src/binder.js";
3
+ import { OutputSpace } from "../../src/index.js";
4
+ import { Namekey, refkey, Refkey } from "../../src/refkey.js";
5
+ import { BasicScope } from "../../src/symbols/basic-scope.js";
6
+ import { BasicSymbol } from "../../src/symbols/basic-symbol.js";
7
+ import { OutputScopeOptions } from "../../src/symbols/output-scope.js";
8
+ import { OutputSymbolOptions } from "../../src/symbols/output-symbol.js";
9
9
 
10
10
  type ScopeRecords = Record<string, ScopeDescriptor>;
11
11
  type SymbolRecords = Record<string, SymbolDescriptor>;
12
12
 
13
13
  interface ScopeDescriptor {
14
- flags?: OutputScopeFlags;
15
14
  scopes?: ScopeRecords;
16
15
  symbols: SymbolRecords;
17
16
  }
18
17
 
19
18
  interface SymbolDescriptor {
20
19
  refkey?: Refkey;
21
- flags?: OutputSymbolFlags;
22
20
  instanceMembers?: SymbolRecords;
23
21
  staticMembers?: SymbolRecords;
24
22
  }
25
23
 
26
- interface ScopeTreeResult {
27
- symbols: Record<string, OutputSymbol>;
28
- scopes: Record<string, OutputScope>;
24
+ export let binder: Binder;
25
+ beforeEach(() => {
26
+ binder = createOutputBinder();
27
+ });
28
+
29
+ export function createScope(
30
+ name: string,
31
+ parent?: BasicScope,
32
+ options?: OutputScopeOptions,
33
+ ) {
34
+ return new BasicScope(name, parent, {
35
+ binder,
36
+ ...options,
37
+ });
29
38
  }
30
- export function createScopeTree(
31
- binder: Binder,
32
- tree: ScopeRecords,
33
- ): ScopeTreeResult {
34
- const createdItems: ScopeTreeResult = {
35
- symbols: {},
36
- scopes: {},
37
- };
38
39
 
39
- for (const [name, desc] of Object.entries(tree)) {
40
- createScope(name, desc);
41
- }
42
-
43
- return createdItems;
44
-
45
- function createScope(
46
- name: string,
47
- descriptor: ScopeDescriptor,
48
- parent = binder.globalScope,
49
- ) {
50
- const scope = new OutputScope(name, {
51
- binder,
52
- parent,
53
- flags: descriptor.flags,
54
- });
55
-
56
- createdItems.scopes[name] = scope;
57
-
58
- for (const [name, desc] of Object.entries(descriptor.symbols)) {
59
- createSymbol(name, desc, scope);
60
- }
61
-
62
- for (const [name, desc] of Object.entries(descriptor.scopes ?? {})) {
63
- createScope(name, desc, scope);
64
- }
65
- }
66
-
67
- function createSymbol(
68
- name: string,
69
- descriptor: SymbolDescriptor,
70
- parent: OutputScope,
71
- ) {
72
- const symbol = new OutputSymbol(name, {
40
+ export function createSymbol(
41
+ name: string | Namekey,
42
+ scope: BasicScope | OutputSpace,
43
+ options?: OutputSymbolOptions,
44
+ ): [BasicSymbol, Refkey] {
45
+ const space = scope instanceof BasicScope ? scope.symbols : scope;
46
+ const key = refkey();
47
+ const refkeys = options?.refkeys ? [...[options.refkeys].flat(), key] : [key];
48
+
49
+ return [
50
+ new BasicSymbol(name, space, {
73
51
  binder,
74
- scope: parent,
75
- refkeys: [descriptor.refkey ?? refkey()],
76
- flags: descriptor.flags ?? OutputSymbolFlags.None,
77
- });
78
-
79
- createdItems.symbols[name] = symbol;
80
-
81
- if (descriptor.instanceMembers) {
82
- for (const [name, desc] of Object.entries(descriptor.instanceMembers)) {
83
- createSymbol(name, desc, symbol.instanceMemberScope!);
84
- }
85
- }
86
-
87
- if (descriptor.staticMembers) {
88
- for (const [name, desc] of Object.entries(descriptor.staticMembers)) {
89
- createSymbol(name, desc, symbol.staticMemberScope!);
90
- }
91
- }
92
- }
52
+ ...options,
53
+ refkeys,
54
+ }),
55
+ key,
56
+ ];
93
57
  }
package/tsdoc.json ADDED
@@ -0,0 +1,4 @@
1
+ {
2
+ "$schema": "https://developer.microsoft.com/json-schemas/tsdoc/v0/tsdoc.schema.json",
3
+ "extends": ["../../tsdoc.base.json"]
4
+ }
@@ -1,15 +0,0 @@
1
- import { Ref } from "@vue/reactivity";
2
- import { Children, Component, ComponentDefinition } from "./runtime/component.js";
3
- import type { OutputSymbol } from "./symbols/output-symbol.js";
4
- export interface SlotInstance extends ComponentDefinition {
5
- }
6
- export interface SlotDefinition<TSlotProps> {
7
- find: (...args: any[]) => () => Ref<unknown>;
8
- create(key: unknown, props: TSlotProps, defaultContent?: Children): ComponentDefinition;
9
- }
10
- export type SlotKey = Ref<unknown>;
11
- export declare function defineSlot<TSlotProps, TFinder extends (...args: any[]) => Ref<unknown> | unknown = (...args: any[]) => Ref<unknown> | unknown>(finder: TFinder): SlotDefinition<TSlotProps>;
12
- export declare const extensionEffects: (() => void)[];
13
- export declare function replace<T>(slotKeyFn: () => SlotKey, replacement: Component<T>): void;
14
- export declare function rename(slotKeyFn: () => Ref<OutputSymbol | undefined>, newName: string): void;
15
- //# sourceMappingURL=slot.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"slot.d.ts","sourceRoot":"","sources":["../../src/slot.ts"],"names":[],"mappings":"AAAA,OAAO,EAAO,GAAG,EAAE,MAAM,iBAAiB,CAAC;AAE3C,OAAO,EACL,QAAQ,EACR,SAAS,EACT,mBAAmB,EACpB,MAAM,wBAAwB,CAAC;AAChC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAE/D,MAAM,WAAW,YAAa,SAAQ,mBAAmB;CAAG;AAE5D,MAAM,WAAW,cAAc,CAAC,UAAU;IACxC,IAAI,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,MAAM,GAAG,CAAC,OAAO,CAAC,CAAC;IAC7C,MAAM,CACJ,GAAG,EAAE,OAAO,EACZ,KAAK,EAAE,UAAU,EACjB,cAAc,CAAC,EAAE,QAAQ,GACxB,mBAAmB,CAAC;CACxB;AAED,MAAM,MAAM,OAAO,GAAG,GAAG,CAAC,OAAO,CAAC,CAAC;AAInC,wBAAgB,UAAU,CACxB,UAAU,EACV,OAAO,SAAS,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,CAAC,OAAO,CAAC,GAAG,OAAO,GAAG,CAC3D,GAAG,IAAI,EAAE,GAAG,EAAE,KACX,GAAG,CAAC,OAAO,CAAC,GAAG,OAAO,EAC3B,MAAM,EAAE,OAAO,GAAG,cAAc,CAAC,UAAU,CAAC,CAsB7C;AAED,eAAO,MAAM,gBAAgB,EAAE,CAAC,MAAM,IAAI,CAAC,EAAO,CAAC;AAEnD,wBAAgB,OAAO,CAAC,CAAC,EACvB,SAAS,EAAE,MAAM,OAAO,EACxB,WAAW,EAAE,SAAS,CAAC,CAAC,CAAC,QAkB1B;AAED,wBAAgB,MAAM,CACpB,SAAS,EAAE,MAAM,GAAG,CAAC,YAAY,GAAG,SAAS,CAAC,EAC9C,OAAO,EAAE,MAAM,QAShB"}
package/dist/src/slot.js DELETED
@@ -1,50 +0,0 @@
1
- import { ref } from "@vue/reactivity";
2
- import { effect, memo } from "./reactivity.js";
3
- const slotMappers = new Map();
4
- export function defineSlot(finder) {
5
- return {
6
- find: (...args) => () => ref(finder(...args)),
7
- create(key, props, defaultContent) {
8
- return function () {
9
- return memo(() => {
10
- if (key === undefined) {
11
- return defaultContent;
12
- }
13
- const component = slotMappers.get(key);
14
- if (!component) {
15
- return defaultContent;
16
- }
17
- return component({
18
- ...props,
19
- original: defaultContent
20
- });
21
- });
22
- };
23
- }
24
- };
25
- }
26
- export const extensionEffects = [];
27
- export function replace(slotKeyFn, replacement) {
28
- extensionEffects.push(() => {
29
- effect(prev => {
30
- if (prev) {
31
- slotMappers.delete(prev.value);
32
- }
33
- const slotKey = slotKeyFn();
34
- if (slotKey.value === undefined) {
35
- return slotKey;
36
- }
37
- slotMappers.set(slotKey.value, replacement);
38
- return slotKey;
39
- });
40
- });
41
- }
42
- export function rename(slotKeyFn, newName) {
43
- extensionEffects.push(() => {
44
- effect(() => {
45
- const sym = slotKeyFn().value;
46
- if (!sym) return;
47
- sym.name = newName;
48
- });
49
- });
50
- }
@@ -1,70 +0,0 @@
1
- /**
2
- * Flags that describe an output scope.
3
- */
4
- export declare enum OutputScopeFlags {
5
- None = 0,
6
- /**
7
- * This scope is a static member scope.
8
- */
9
- StaticMemberScope = 1,
10
- /**
11
- * This scope is an instance member scope.
12
- */
13
- InstanceMemberScope = 2,
14
- /**
15
- * This scope is transient, and only exists to be merged with other scopes.
16
- */
17
- Transient = 4,
18
- /**
19
- * This scope is a member scope. Scopes with this flag will have an `owner`
20
- * property that points to the symbol whose member this scope holds.
21
- */
22
- MemberScope = 3
23
- }
24
- /**
25
- * Flags that describe an output symbol.
26
- */
27
- export declare enum OutputSymbolFlags {
28
- None = 0,
29
- /**
30
- * The symbol is an instance member container. Symbols with this flag will have a
31
- * instanceMemberScope property that contains symbols for instance members.
32
- */
33
- InstanceMemberContainer = 1,
34
- /**
35
- * The symbol is a static member container. Symbols with this flag will have a
36
- * staticMemberScope property that contains symbols for static members.
37
- */
38
- StaticMemberContainer = 2,
39
- /**
40
- * Whether this symbol contains members of any kind.
41
- */
42
- MemberContainer = 3,
43
- /**
44
- * Whether this symbol is an instance member of another symbol (i.e that it is
45
- * stored in an instance member scope).
46
- */
47
- InstanceMember = 4,
48
- /**
49
- * Whether this symbol is a static member of another symbol (i.e that it is
50
- * stored in a static member scope).
51
- */
52
- StaticMember = 8,
53
- /**
54
- * Transient symbols are not added to symbol tables and do not create
55
- * referencable refkeys. They are used for temporary symbols that are intended
56
- * to be used to calculate other symbols.
57
- */
58
- Transient = 16,
59
- /**
60
- * This symbol aliases another symbol. Only its name, flags, and scope are
61
- * stored in this symbol. Otherwise, everything else is located on the alias
62
- * target.
63
- */
64
- Alias = 32,
65
- /**
66
- * Whether this is an instance member or static member of another symbol.
67
- */
68
- Member = 12
69
- }
70
- //# sourceMappingURL=flags.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"flags.d.ts","sourceRoot":"","sources":["../../../src/symbols/flags.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,oBAAY,gBAAgB;IAC1B,IAAI,IAAI;IAER;;OAEG;IACH,iBAAiB,IAAS;IAE1B;;OAEG;IACH,mBAAmB,IAAS;IAE5B;;OAEG;IACH,SAAS,IAAS;IAElB;;;OAGG;IACH,WAAW,IAA0C;CACtD;AAED;;GAEG;AACH,oBAAY,iBAAiB;IAC3B,IAAI,IAAI;IAER;;;OAGG;IACH,uBAAuB,IAAS;IAEhC;;;OAGG;IACH,qBAAqB,IAAS;IAE9B;;OAEG;IACH,eAAe,IAAkD;IAEjE;;;OAGG;IACH,cAAc,IAAS;IAEvB;;;OAGG;IACH,YAAY,IAAS;IAErB;;;;OAIG;IACH,SAAS,KAAS;IAElB;;;;OAIG;IACH,KAAK,KAAS;IAEd;;OAEG;IACH,MAAM,KAAgC;CACvC"}
@@ -1,72 +0,0 @@
1
- /**
2
- * Flags that describe an output scope.
3
- */
4
- export let OutputScopeFlags = /*#__PURE__*/function (OutputScopeFlags) {
5
- OutputScopeFlags[OutputScopeFlags["None"] = 0] = "None";
6
- /**
7
- * This scope is a static member scope.
8
- */
9
- OutputScopeFlags[OutputScopeFlags["StaticMemberScope"] = 1] = "StaticMemberScope";
10
- /**
11
- * This scope is an instance member scope.
12
- */
13
- OutputScopeFlags[OutputScopeFlags["InstanceMemberScope"] = 2] = "InstanceMemberScope";
14
- /**
15
- * This scope is transient, and only exists to be merged with other scopes.
16
- */
17
- OutputScopeFlags[OutputScopeFlags["Transient"] = 4] = "Transient";
18
- /**
19
- * This scope is a member scope. Scopes with this flag will have an `owner`
20
- * property that points to the symbol whose member this scope holds.
21
- */
22
- OutputScopeFlags[OutputScopeFlags["MemberScope"] = 3] = "MemberScope";
23
- return OutputScopeFlags;
24
- }({});
25
-
26
- /**
27
- * Flags that describe an output symbol.
28
- */
29
- export let OutputSymbolFlags = /*#__PURE__*/function (OutputSymbolFlags) {
30
- OutputSymbolFlags[OutputSymbolFlags["None"] = 0] = "None";
31
- /**
32
- * The symbol is an instance member container. Symbols with this flag will have a
33
- * instanceMemberScope property that contains symbols for instance members.
34
- */
35
- OutputSymbolFlags[OutputSymbolFlags["InstanceMemberContainer"] = 1] = "InstanceMemberContainer";
36
- /**
37
- * The symbol is a static member container. Symbols with this flag will have a
38
- * staticMemberScope property that contains symbols for static members.
39
- */
40
- OutputSymbolFlags[OutputSymbolFlags["StaticMemberContainer"] = 2] = "StaticMemberContainer";
41
- /**
42
- * Whether this symbol contains members of any kind.
43
- */
44
- OutputSymbolFlags[OutputSymbolFlags["MemberContainer"] = 3] = "MemberContainer";
45
- /**
46
- * Whether this symbol is an instance member of another symbol (i.e that it is
47
- * stored in an instance member scope).
48
- */
49
- OutputSymbolFlags[OutputSymbolFlags["InstanceMember"] = 4] = "InstanceMember";
50
- /**
51
- * Whether this symbol is a static member of another symbol (i.e that it is
52
- * stored in a static member scope).
53
- */
54
- OutputSymbolFlags[OutputSymbolFlags["StaticMember"] = 8] = "StaticMember";
55
- /**
56
- * Transient symbols are not added to symbol tables and do not create
57
- * referencable refkeys. They are used for temporary symbols that are intended
58
- * to be used to calculate other symbols.
59
- */
60
- OutputSymbolFlags[OutputSymbolFlags["Transient"] = 16] = "Transient";
61
- /**
62
- * This symbol aliases another symbol. Only its name, flags, and scope are
63
- * stored in this symbol. Otherwise, everything else is located on the alias
64
- * target.
65
- */
66
- OutputSymbolFlags[OutputSymbolFlags["Alias"] = 32] = "Alias";
67
- /**
68
- * Whether this is an instance member or static member of another symbol.
69
- */
70
- OutputSymbolFlags[OutputSymbolFlags["Member"] = 12] = "Member";
71
- return OutputSymbolFlags;
72
- }({});
@@ -1,2 +0,0 @@
1
- import "../../testing/extend-expect.js";
2
- //# sourceMappingURL=slot.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"slot.test.d.ts","sourceRoot":"","sources":["../../../test/components/slot.test.tsx"],"names":[],"mappings":"AAcA,OAAO,gCAAgC,CAAC"}
@@ -1,134 +0,0 @@
1
- import { memo as _$memo, createComponent as _$createComponent } from "@alloy-js/core/jsx-runtime";
2
- import { it } from "vitest";
3
- import { Output } from "../../src/components/Output.js";
4
- import { SourceFile } from "../../src/components/SourceFile.js";
5
- import { Declaration, Name, refkey, Scope, useBinder } from "../../src/index.js";
6
- import { render } from "../../src/render.js";
7
- import { defineSlot, rename, replace } from "../../src/slot.js";
8
- import { OutputSymbol } from "../../src/symbols/output-symbol.js";
9
- import "../../testing/extend-expect.js";
10
- it("works with string keys", () => {
11
- const FunctionSlot = defineSlot(query => query.name);
12
- function MyFunctionComponent(props) {
13
- const FunctionSlotInstance = FunctionSlot.create(props.name, {
14
- ...props,
15
- additionalProp: "hi"
16
- }, ["function ", _$memo(() => props.name), "() ", "{", "console.log(\"hello world\");", "}"]);
17
- return _$createComponent(FunctionSlotInstance, {});
18
- }
19
-
20
- // extension.tsx
21
- replace(FunctionSlot.find({
22
- name: "foo"
23
- }), props => {
24
- return ["// original", _$memo(() => props.original)];
25
- });
26
- const _tree = render(_$createComponent(Output, {
27
- get children() {
28
- return _$createComponent(SourceFile, {
29
- path: "test.ts",
30
- filetype: "ts",
31
- get children() {
32
- return _$createComponent(MyFunctionComponent, {
33
- name: "foo"
34
- });
35
- }
36
- });
37
- }
38
- }));
39
-
40
- // console.log(tree.contents[0].contents);
41
- });
42
- it("works with symbols", () => {
43
- const FunctionSlot = defineSlot(query => {
44
- const binder = useBinder();
45
- return binder.resolveFQN(query.fqn);
46
- });
47
- function MyFunctionComponent(props) {
48
- const sym = new OutputSymbol(props.name, {
49
- refkeys: refkey()
50
- });
51
- const FunctionSlotInstance = FunctionSlot.create(sym, {
52
- ...props,
53
- additionalProp: "hi"
54
- }, _$createComponent(Declaration, {
55
- symbol: sym,
56
- get children() {
57
- return ["function ", _$createComponent(Name, {}), "() ", "{", "console.log(\"hello world\");", "}"];
58
- }
59
- }));
60
- return _$createComponent(FunctionSlotInstance, {});
61
- }
62
-
63
- // extension.tsx
64
- replace(FunctionSlot.find({
65
- fqn: "foo.bar"
66
- }), props => {
67
- return ["// original", _$memo(() => props.original)];
68
- });
69
- const _tree = render(_$createComponent(Output, {
70
- get children() {
71
- return _$createComponent(SourceFile, {
72
- path: "test.ts",
73
- filetype: "ts",
74
- get children() {
75
- return _$createComponent(Scope, {
76
- name: "foo",
77
- get children() {
78
- return _$createComponent(MyFunctionComponent, {
79
- name: "bar"
80
- });
81
- }
82
- });
83
- }
84
- });
85
- }
86
- }));
87
-
88
- // console.log(tree.contents[0].contents);
89
- });
90
- it("can rename", () => {
91
- const FunctionSlot = defineSlot(query => {
92
- const binder = useBinder();
93
- return binder.resolveFQN(query.fqn);
94
- });
95
- function MyFunctionComponent(props) {
96
- const sym = new OutputSymbol(props.name, {
97
- refkeys: refkey()
98
- });
99
- const FunctionSlotInstance = FunctionSlot.create(sym, {
100
- ...props,
101
- additionalProp: "hi"
102
- }, _$createComponent(Declaration, {
103
- symbol: sym,
104
- get children() {
105
- return ["function ", _$createComponent(Name, {}), "() ", "{", "console.log(\"hello world\");", "}"];
106
- }
107
- }));
108
- return _$createComponent(FunctionSlotInstance, {});
109
- }
110
- rename(() => {
111
- const binder = useBinder();
112
- return binder.resolveFQN("foo.bar");
113
- }, "bazxxx");
114
- const _tree = render(_$createComponent(Output, {
115
- get children() {
116
- return _$createComponent(SourceFile, {
117
- path: "test.ts",
118
- filetype: "ts",
119
- get children() {
120
- return _$createComponent(Scope, {
121
- name: "foo",
122
- get children() {
123
- return _$createComponent(MyFunctionComponent, {
124
- name: "bar"
125
- });
126
- }
127
- });
128
- }
129
- });
130
- }
131
- }));
132
-
133
- // console.log(tree.contents[0].contents);
134
- });
package/src/slot.ts DELETED
@@ -1,89 +0,0 @@
1
- import { ref, Ref } from "@vue/reactivity";
2
- import { effect, memo } from "./reactivity.js";
3
- import {
4
- Children,
5
- Component,
6
- ComponentDefinition,
7
- } from "./runtime/component.js";
8
- import type { OutputSymbol } from "./symbols/output-symbol.js";
9
-
10
- export interface SlotInstance extends ComponentDefinition {}
11
-
12
- export interface SlotDefinition<TSlotProps> {
13
- find: (...args: any[]) => () => Ref<unknown>;
14
- create(
15
- key: unknown,
16
- props: TSlotProps,
17
- defaultContent?: Children,
18
- ): ComponentDefinition;
19
- }
20
-
21
- export type SlotKey = Ref<unknown>;
22
-
23
- const slotMappers = new Map<unknown, ComponentDefinition<any>>();
24
-
25
- export function defineSlot<
26
- TSlotProps,
27
- TFinder extends (...args: any[]) => Ref<unknown> | unknown = (
28
- ...args: any[]
29
- ) => Ref<unknown> | unknown,
30
- >(finder: TFinder): SlotDefinition<TSlotProps> {
31
- return {
32
- find: ((...args: any[]) =>
33
- () =>
34
- ref(finder(...args))) as any,
35
- create(key, props, defaultContent) {
36
- return function () {
37
- return memo(() => {
38
- if (key === undefined) {
39
- return defaultContent;
40
- }
41
-
42
- const component = slotMappers.get(key);
43
- if (!component) {
44
- return defaultContent;
45
- }
46
-
47
- return component({ ...props, original: defaultContent });
48
- });
49
- };
50
- },
51
- };
52
- }
53
-
54
- export const extensionEffects: (() => void)[] = [];
55
-
56
- export function replace<T>(
57
- slotKeyFn: () => SlotKey,
58
- replacement: Component<T>,
59
- ) {
60
- extensionEffects.push(() => {
61
- effect((prev: SlotKey | undefined) => {
62
- if (prev) {
63
- slotMappers.delete(prev.value);
64
- }
65
-
66
- const slotKey = slotKeyFn();
67
- if (slotKey.value === undefined) {
68
- return slotKey;
69
- }
70
-
71
- slotMappers.set(slotKey.value, replacement);
72
-
73
- return slotKey;
74
- });
75
- });
76
- }
77
-
78
- export function rename(
79
- slotKeyFn: () => Ref<OutputSymbol | undefined>,
80
- newName: string,
81
- ) {
82
- extensionEffects.push(() => {
83
- effect(() => {
84
- const sym = slotKeyFn().value;
85
- if (!sym) return;
86
- sym.name = newName;
87
- });
88
- });
89
- }
@@ -1,82 +0,0 @@
1
- /**
2
- * Flags that describe an output scope.
3
- */
4
- export enum OutputScopeFlags {
5
- None = 0,
6
-
7
- /**
8
- * This scope is a static member scope.
9
- */
10
- StaticMemberScope = 1 << 0,
11
-
12
- /**
13
- * This scope is an instance member scope.
14
- */
15
- InstanceMemberScope = 1 << 1,
16
-
17
- /**
18
- * This scope is transient, and only exists to be merged with other scopes.
19
- */
20
- Transient = 1 << 2,
21
-
22
- /**
23
- * This scope is a member scope. Scopes with this flag will have an `owner`
24
- * property that points to the symbol whose member this scope holds.
25
- */
26
- MemberScope = StaticMemberScope | InstanceMemberScope,
27
- }
28
-
29
- /**
30
- * Flags that describe an output symbol.
31
- */
32
- export enum OutputSymbolFlags {
33
- None = 0,
34
-
35
- /**
36
- * The symbol is an instance member container. Symbols with this flag will have a
37
- * instanceMemberScope property that contains symbols for instance members.
38
- */
39
- InstanceMemberContainer = 1 << 0,
40
-
41
- /**
42
- * The symbol is a static member container. Symbols with this flag will have a
43
- * staticMemberScope property that contains symbols for static members.
44
- */
45
- StaticMemberContainer = 1 << 1,
46
-
47
- /**
48
- * Whether this symbol contains members of any kind.
49
- */
50
- MemberContainer = InstanceMemberContainer | StaticMemberContainer,
51
-
52
- /**
53
- * Whether this symbol is an instance member of another symbol (i.e that it is
54
- * stored in an instance member scope).
55
- */
56
- InstanceMember = 1 << 2,
57
-
58
- /**
59
- * Whether this symbol is a static member of another symbol (i.e that it is
60
- * stored in a static member scope).
61
- */
62
- StaticMember = 1 << 3,
63
-
64
- /**
65
- * Transient symbols are not added to symbol tables and do not create
66
- * referencable refkeys. They are used for temporary symbols that are intended
67
- * to be used to calculate other symbols.
68
- */
69
- Transient = 1 << 4,
70
-
71
- /**
72
- * This symbol aliases another symbol. Only its name, flags, and scope are
73
- * stored in this symbol. Otherwise, everything else is located on the alias
74
- * target.
75
- */
76
- Alias = 1 << 5,
77
-
78
- /**
79
- * Whether this is an instance member or static member of another symbol.
80
- */
81
- Member = InstanceMember | StaticMember,
82
- }