@alloy-js/typescript 0.20.0-dev.0 → 0.20.0-dev.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 (134) hide show
  1. package/dist/src/builtins/node.d.ts +1 -1
  2. package/dist/src/components/ArrowFunction.d.ts.map +1 -1
  3. package/dist/src/components/ArrowFunction.js +7 -13
  4. package/dist/src/components/BlockScope.d.ts.map +1 -1
  5. package/dist/src/components/BlockScope.js +3 -2
  6. package/dist/src/components/ClassDeclaration.d.ts.map +1 -1
  7. package/dist/src/components/ClassDeclaration.js +20 -30
  8. package/dist/src/components/Declaration.d.ts +2 -9
  9. package/dist/src/components/Declaration.d.ts.map +1 -1
  10. package/dist/src/components/Declaration.js +20 -43
  11. package/dist/src/components/EnumDeclaration.d.ts.map +1 -1
  12. package/dist/src/components/EnumDeclaration.js +5 -9
  13. package/dist/src/components/EnumMember.d.ts.map +1 -1
  14. package/dist/src/components/EnumMember.js +3 -4
  15. package/dist/src/components/ExportStatement.d.ts.map +1 -1
  16. package/dist/src/components/ExportStatement.js +2 -1
  17. package/dist/src/components/FunctionBase.d.ts.map +1 -1
  18. package/dist/src/components/FunctionBase.js +15 -12
  19. package/dist/src/components/FunctionDeclaration.d.ts.map +1 -1
  20. package/dist/src/components/FunctionDeclaration.js +3 -3
  21. package/dist/src/components/FunctionExpression.d.ts.map +1 -1
  22. package/dist/src/components/FunctionExpression.js +7 -13
  23. package/dist/src/components/FunctionType.d.ts.map +1 -1
  24. package/dist/src/components/FunctionType.js +3 -3
  25. package/dist/src/components/IfStatement.d.ts.map +1 -1
  26. package/dist/src/components/IfStatement.js +2 -1
  27. package/dist/src/components/ImportStatement.d.ts.map +1 -1
  28. package/dist/src/components/ImportStatement.js +3 -4
  29. package/dist/src/components/Interface.d.ts.map +1 -1
  30. package/dist/src/components/Interface.js +14 -13
  31. package/dist/src/components/InterfaceMethod.d.ts.map +1 -1
  32. package/dist/src/components/InterfaceMethod.js +4 -3
  33. package/dist/src/components/LexicalScope.d.ts +12 -0
  34. package/dist/src/components/LexicalScope.d.ts.map +1 -0
  35. package/dist/src/components/LexicalScope.js +24 -0
  36. package/dist/src/components/MemberDeclaration.d.ts +1 -10
  37. package/dist/src/components/MemberDeclaration.d.ts.map +1 -1
  38. package/dist/src/components/MemberDeclaration.js +3 -7
  39. package/dist/src/components/MemberExpression.d.ts.map +1 -1
  40. package/dist/src/components/MemberExpression.js +13 -5
  41. package/dist/src/components/MemberScope.d.ts +15 -0
  42. package/dist/src/components/MemberScope.d.ts.map +1 -0
  43. package/dist/src/components/MemberScope.js +17 -0
  44. package/dist/src/components/NewExpression.d.ts.map +1 -1
  45. package/dist/src/components/NewExpression.js +5 -5
  46. package/dist/src/components/ObjectExpression.d.ts.map +1 -1
  47. package/dist/src/components/ObjectExpression.js +10 -14
  48. package/dist/src/components/PropertyName.js +1 -2
  49. package/dist/src/components/SourceFile.d.ts.map +1 -1
  50. package/dist/src/components/SourceFile.js +3 -2
  51. package/dist/src/components/VarDeclaration.d.ts.map +1 -1
  52. package/dist/src/components/VarDeclaration.js +14 -26
  53. package/dist/src/context/index.d.ts +1 -1
  54. package/dist/src/context/index.d.ts.map +1 -1
  55. package/dist/src/context/index.js +1 -1
  56. package/dist/src/create-package.d.ts.map +1 -1
  57. package/dist/src/create-package.js +11 -33
  58. package/dist/src/symbols/index.d.ts +19 -0
  59. package/dist/src/symbols/index.d.ts.map +1 -1
  60. package/dist/src/symbols/index.js +72 -1
  61. package/dist/src/symbols/reference.d.ts +2 -2
  62. package/dist/src/symbols/reference.d.ts.map +1 -1
  63. package/dist/src/symbols/reference.js +68 -70
  64. package/dist/src/symbols/scopes.d.ts +5 -8
  65. package/dist/src/symbols/scopes.d.ts.map +1 -1
  66. package/dist/src/symbols/scopes.js +26 -0
  67. package/dist/src/symbols/ts-lexical-scope.d.ts +12 -0
  68. package/dist/src/symbols/ts-lexical-scope.d.ts.map +1 -0
  69. package/dist/src/symbols/ts-lexical-scope.js +16 -0
  70. package/dist/src/symbols/ts-member-scope.d.ts +12 -4
  71. package/dist/src/symbols/ts-member-scope.d.ts.map +1 -1
  72. package/dist/src/symbols/ts-member-scope.js +15 -6
  73. package/dist/src/symbols/ts-module-scope.d.ts +8 -3
  74. package/dist/src/symbols/ts-module-scope.d.ts.map +1 -1
  75. package/dist/src/symbols/ts-module-scope.js +29 -18
  76. package/dist/src/symbols/ts-output-symbol.d.ts +19 -18
  77. package/dist/src/symbols/ts-output-symbol.d.ts.map +1 -1
  78. package/dist/src/symbols/ts-output-symbol.js +60 -37
  79. package/dist/src/symbols/ts-package-scope.d.ts +1 -1
  80. package/dist/src/symbols/ts-package-scope.d.ts.map +1 -1
  81. package/dist/src/symbols/ts-package-scope.js +4 -5
  82. package/dist/src/utils.d.ts +4 -0
  83. package/dist/src/utils.d.ts.map +1 -1
  84. package/dist/src/utils.js +23 -1
  85. package/dist/test/class.test.js +4 -4
  86. package/dist/test/externals.test.js +2 -38
  87. package/dist/test/reference.test.js +3 -3
  88. package/dist/tsconfig.tsbuildinfo +1 -1
  89. package/package.json +3 -3
  90. package/src/components/ArrowFunction.tsx +7 -10
  91. package/src/components/BlockScope.tsx +3 -3
  92. package/src/components/ClassDeclaration.tsx +19 -44
  93. package/src/components/Declaration.tsx +22 -53
  94. package/src/components/EnumDeclaration.tsx +4 -11
  95. package/src/components/EnumMember.tsx +3 -3
  96. package/src/components/ExportStatement.tsx +2 -1
  97. package/src/components/FunctionBase.tsx +33 -28
  98. package/src/components/FunctionDeclaration.tsx +3 -3
  99. package/src/components/FunctionExpression.tsx +7 -10
  100. package/src/components/FunctionType.tsx +3 -3
  101. package/src/components/IfStatement.tsx +2 -1
  102. package/src/components/ImportStatement.tsx +4 -8
  103. package/src/components/Interface.tsx +15 -22
  104. package/src/components/InterfaceMethod.tsx +4 -4
  105. package/src/components/LexicalScope.tsx +27 -0
  106. package/src/components/MemberDeclaration.tsx +8 -20
  107. package/src/components/MemberExpression.tsx +25 -5
  108. package/src/components/MemberScope.tsx +29 -0
  109. package/src/components/NewExpression.tsx +4 -5
  110. package/src/components/ObjectExpression.tsx +11 -18
  111. package/src/components/PropertyName.tsx +2 -2
  112. package/src/components/SourceFile.tsx +3 -1
  113. package/src/components/VarDeclaration.tsx +14 -28
  114. package/src/context/index.ts +1 -1
  115. package/src/create-package.ts +10 -39
  116. package/src/symbols/index.ts +118 -0
  117. package/src/symbols/reference.tsx +163 -0
  118. package/src/symbols/scopes.ts +38 -13
  119. package/src/symbols/ts-lexical-scope.ts +18 -0
  120. package/src/symbols/ts-member-scope.ts +23 -6
  121. package/src/symbols/ts-module-scope.ts +31 -21
  122. package/src/symbols/ts-output-symbol.ts +111 -49
  123. package/src/symbols/ts-package-scope.ts +5 -5
  124. package/src/utils.ts +38 -1
  125. package/temp/api.json +1641 -713
  126. package/test/class.test.tsx +10 -4
  127. package/test/externals.test.tsx +1 -40
  128. package/test/reference.test.tsx +5 -5
  129. package/tsdoc-metadata.json +1 -1
  130. package/dist/src/context/private-scope.d.ts +0 -18
  131. package/dist/src/context/private-scope.d.ts.map +0 -1
  132. package/dist/src/context/private-scope.js +0 -8
  133. package/src/context/private-scope.ts +0 -23
  134. package/src/symbols/reference.ts +0 -197
@@ -1,9 +1,11 @@
1
- import { OutputScope, reactive, shallowReactive } from "@alloy-js/core";
1
+ import { reactive, shallowReactive } from "@alloy-js/core";
2
+ import { TSLexicalScope } from "./ts-lexical-scope.js";
2
3
  import { TSOutputSymbol, TSSymbolFlags } from "./ts-output-symbol.js";
3
- export class TSModuleScope extends OutputScope {
4
- get kind() {
5
- return "module";
6
- }
4
+ /**
5
+ * A lexical scope for TypeScript which represents the top-level scope of a
6
+ * module. Manages the module's imported and exported symbols.
7
+ */
8
+ export class TSModuleScope extends TSLexicalScope {
7
9
  #exportedSymbols = shallowReactive(new Map());
8
10
  get exportedSymbols() {
9
11
  return this.#exportedSymbols;
@@ -19,26 +21,25 @@ export class TSModuleScope extends OutputScope {
19
21
  addImport(targetSymbol, targetModule, options) {
20
22
  const existing = this.importedSymbols.get(targetSymbol);
21
23
  if (existing) {
22
- if (!options?.type && existing.tsFlags & TSSymbolFlags.TypeSymbol) {
23
- existing.tsFlags &= ~TSSymbolFlags.TypeSymbol;
24
+ if (!options?.type && existing.isTypeSymbol) {
25
+ existing.spaces.push(this.values);
24
26
  }
25
27
  return existing;
26
28
  }
27
- if (targetModule.kind !== "module") {
28
- throw new Error("Cannot import symbol that isn't in module scope");
29
- }
30
29
  if (!this.importedModules.has(targetModule)) {
31
30
  this.importedModules.set(targetModule, new Set());
32
31
  }
33
- const localSymbol = new TSOutputSymbol(targetSymbol.name, {
34
- binder: this.binder,
35
- scope: this,
36
- aliasTarget: targetSymbol,
37
- tsFlags: TSSymbolFlags.LocalImportSymbol
38
- });
39
- targetSymbol.copyTo(localSymbol);
32
+ let localSymbol;
40
33
  if (options?.type) {
41
- localSymbol.tsFlags |= TSSymbolFlags.TypeSymbol;
34
+ localSymbol = new TSOutputSymbol(targetSymbol.name, this.types, {
35
+ aliasTarget: targetSymbol,
36
+ tsFlags: TSSymbolFlags.LocalImportSymbol
37
+ });
38
+ } else {
39
+ localSymbol = new TSOutputSymbol(targetSymbol.name, this.values, {
40
+ aliasTarget: targetSymbol,
41
+ tsFlags: TSSymbolFlags.LocalImportSymbol
42
+ });
42
43
  }
43
44
  this.importedSymbols.set(targetSymbol, localSymbol);
44
45
  this.importedModules.get(targetModule).add({
@@ -47,4 +48,14 @@ export class TSModuleScope extends OutputScope {
47
48
  });
48
49
  return localSymbol;
49
50
  }
51
+ getAllSymbols() {
52
+ const allSymbols = new Set();
53
+ for (const symbol of this.values) {
54
+ allSymbols.add(symbol);
55
+ }
56
+ for (const symbol of this.types) {
57
+ allSymbols.add(symbol);
58
+ }
59
+ return allSymbols;
60
+ }
50
61
  }
@@ -1,40 +1,41 @@
1
- import { OutputScopeFlags, OutputSymbol, OutputSymbolOptions } from "@alloy-js/core";
1
+ import { OutputSpace, OutputSymbol, OutputSymbolOptions } from "@alloy-js/core";
2
2
  import { TSOutputScope } from "./scopes.js";
3
- import { TSMemberScope } from "./ts-member-scope.js";
4
3
  export declare enum TSSymbolFlags {
5
4
  None = 0,
6
5
  LocalImportSymbol = 1,
7
6
  TypeSymbol = 2,
8
7
  ParameterSymbol = 4,
9
- PrivateMember = 8,
10
- PrivateMemberContainer = 16,
11
- Nullish = 32
8
+ Nullish = 8
12
9
  }
13
10
  export interface CreateTsSymbolOptions extends OutputSymbolOptions {
14
- scope?: TSOutputScope;
15
- owner?: TSOutputSymbol;
16
11
  export?: boolean;
17
12
  default?: boolean;
18
13
  tsFlags?: TSSymbolFlags;
14
+ hasInstanceMembers?: boolean;
19
15
  }
20
16
  export declare class TSOutputSymbol extends OutputSymbol {
21
17
  #private;
22
- constructor(name: string, options?: CreateTsSymbolOptions);
18
+ static readonly memberSpaces: readonly ["static", "instance", "private-static", "private-instance"];
19
+ constructor(name: string, spaces: OutputSpace[] | OutputSpace | undefined, options?: CreateTsSymbolOptions);
20
+ get ownerSymbol(): TSOutputSymbol | undefined;
21
+ copy(): TSOutputSymbol;
23
22
  get export(): boolean;
24
23
  set export(value: boolean);
25
24
  get default(): boolean;
26
25
  set default(value: boolean);
27
26
  get tsFlags(): TSSymbolFlags;
27
+ get hasInstanceMembers(): boolean;
28
28
  set tsFlags(value: TSSymbolFlags);
29
- get scope(): TSOutputScope;
30
- set scope(value: TSOutputScope);
31
- get staticMemberScope(): TSMemberScope | undefined;
32
- get instanceMemberScope(): TSMemberScope | undefined;
33
- get privateMemberScope(): TSMemberScope | undefined;
34
- get privateStaticMemberScope(): TSMemberScope | undefined;
35
- protected createMemberScope(name: string, options: {
36
- owner?: OutputSymbol;
37
- flags?: OutputScopeFlags;
38
- }): TSMemberScope;
29
+ get scope(): TSOutputScope | undefined;
30
+ get staticMembers(): import("@alloy-js/core").OutputMemberSpace;
31
+ get instanceMembers(): import("@alloy-js/core").OutputMemberSpace;
32
+ get privateInstanceMembers(): import("@alloy-js/core").OutputMemberSpace;
33
+ get privateStaticMembers(): import("@alloy-js/core").OutputMemberSpace;
34
+ get isPrivateMemberSymbol(): boolean;
35
+ get isPublicMemberSymbol(): boolean;
36
+ get isStaticMemberSymbol(): boolean;
37
+ get isInstanceMemberSymbol(): boolean;
38
+ get isTypeSymbol(): boolean;
39
+ get isValueSymbol(): boolean;
39
40
  }
40
41
  //# sourceMappingURL=ts-output-symbol.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ts-output-symbol.d.ts","sourceRoot":"","sources":["../../../src/symbols/ts-output-symbol.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAChB,YAAY,EACZ,mBAAmB,EAKpB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAGrD,oBAAY,aAAa;IACvB,IAAI,IAAsB;IAC1B,iBAAiB,IAAc;IAC/B,UAAU,IAAqB;IAC/B,eAAe,IAAgB;IAC/B,aAAa,IAAkB;IAC/B,sBAAsB,KAAS;IAC/B,OAAO,KAAS;CACjB;AAED,MAAM,WAAW,qBAAsB,SAAQ,mBAAmB;IAChE,KAAK,CAAC,EAAE,aAAa,CAAC;IACtB,KAAK,CAAC,EAAE,cAAc,CAAC;IACvB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,OAAO,CAAC,EAAE,aAAa,CAAC;CACzB;AAED,qBAAa,cAAe,SAAQ,YAAY;;gBAClC,IAAI,EAAE,MAAM,EAAE,OAAO,GAAE,qBAA0B;IAgC7D,IAAI,MAAM,IAKQ,OAAO,CAFxB;IAED,IAAI,MAAM,CAAC,KAAK,EAAE,OAAO,EAMxB;IAGD,IAAI,OAAO,IAKQ,OAAO,CAFzB;IAED,IAAI,OAAO,CAAC,KAAK,EAAE,OAAO,EAMzB;IAGD,IAAI,OAAO,IAIQ,aAAa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,CACvD;IAED,IAAI;IA+BJ,IAAI,MAAM,IAKQ,OAAO,CAFxB;IAED,IAAI,MAAM,CAAC,KAAK,EAAE,OAAO,EAMxB;IAGD,IAAI,OAAO,IAKQ,OAAO,CAFzB;IAED,IAAI,OAAO,CAAC,KAAK,EAAE,OAAO,EAMzB;IAGD,IAAI,OAAO,IAWQ,aAAa,CAR/B;IAGD,IAAI,kBAAkB,YAGrB;IAED,IAAI,OAAO,CAAC,KAAK,EAAE,aAAa,EAO/B;IAED,IAAI,KAAK,IAAI,aAAa,GAAG,SAAS,CAErC;IAED,IAAI,aAAa,+CAEhB;IAED,IAAI,eAAe,+CAElB;IAED,IAAI,sBAAsB,+CAEzB;IAED,IAAI,oBAAoB,+CAEvB;IAED,IAAI,qBAAqB,YAOxB;IAED,IAAI,oBAAoB,YAEvB;IAED,IAAI,oBAAoB,YAEvB;IAED,IAAI,sBAAsB,YAOzB;IAED,IAAI,YAAY,YAEf;IAED,IAAI,aAAa,YAEhB;CACF"}
@@ -1,5 +1,5 @@
1
- import { OutputScopeFlags, OutputSymbol, track, TrackOpTypes, trigger, TriggerOpTypes } from "@alloy-js/core";
2
- import { TSMemberScope } from "./ts-member-scope.js";
1
+ import { OutputSymbol, track, TrackOpTypes, trigger, TriggerOpTypes, watch } from "@alloy-js/core";
2
+ import { TSModuleScope } from "./ts-module-scope.js";
3
3
 
4
4
  // prettier-ignore
5
5
  export let TSSymbolFlags = /*#__PURE__*/function (TSSymbolFlags) {
@@ -7,37 +7,47 @@ export let TSSymbolFlags = /*#__PURE__*/function (TSSymbolFlags) {
7
7
  TSSymbolFlags[TSSymbolFlags["LocalImportSymbol"] = 1] = "LocalImportSymbol";
8
8
  TSSymbolFlags[TSSymbolFlags["TypeSymbol"] = 2] = "TypeSymbol";
9
9
  TSSymbolFlags[TSSymbolFlags["ParameterSymbol"] = 4] = "ParameterSymbol";
10
- TSSymbolFlags[TSSymbolFlags["PrivateMember"] = 8] = "PrivateMember";
11
- TSSymbolFlags[TSSymbolFlags["PrivateMemberContainer"] = 16] = "PrivateMemberContainer";
12
- TSSymbolFlags[TSSymbolFlags["Nullish"] = 32] = "Nullish";
10
+ TSSymbolFlags[TSSymbolFlags["Nullish"] = 8] = "Nullish";
13
11
  return TSSymbolFlags;
14
12
  }({});
15
13
  export class TSOutputSymbol extends OutputSymbol {
16
- constructor(name, options = {}) {
17
- super(name, options);
14
+ static memberSpaces = ["static", "instance", "private-static", "private-instance"];
15
+ constructor(name, spaces, options = {}) {
16
+ super(name, spaces, options);
18
17
  this.#export = !!options.export;
19
18
  this.#default = !!options.default;
20
19
  this.#tsFlags = options.tsFlags ?? TSSymbolFlags.None;
21
- this.#privateMemberScope = undefined;
22
- this.#privateStaticMemberScope = undefined;
23
- if (this.#tsFlags & TSSymbolFlags.PrivateMemberContainer) {
24
- this.#privateMemberScope = new TSMemberScope("private members", {
25
- binder: this.binder,
26
- owner: this,
27
- flags: OutputScopeFlags.InstanceMemberScope
28
- });
29
- this.#privateStaticMemberScope = new TSMemberScope("private static members", {
30
- flags: OutputScopeFlags.StaticMemberScope,
31
- binder: this.binder,
32
- owner: this
33
- });
20
+ this.#hasInstanceMembers = !!options.hasInstanceMembers;
21
+ if (this.ownerSymbol?.isTypeSymbol || this.spaces.some(s => s.key === "types") && !this.spaces.some(s => s.key === "values")) {
22
+ // Classes and enums are both types and values. The check above will treat them as values
23
+ // exclusively so that referencing occurs properly. This should instead use type or value
24
+ // referencing based on type context.
25
+ this.#tsFlags |= TSSymbolFlags.TypeSymbol;
34
26
  }
35
- if (options.export && this.scope.kind === "module") {
27
+ if (options.export && this.scope && this.scope instanceof TSModuleScope) {
36
28
  for (const refkey of this.refkeys) {
37
29
  this.scope.exportedSymbols.set(refkey, this);
38
30
  }
39
31
  }
40
32
  }
33
+ get ownerSymbol() {
34
+ return super.ownerSymbol;
35
+ }
36
+ copy() {
37
+ const copy = new TSOutputSymbol(this.name, undefined, {
38
+ binder: this.binder,
39
+ aliasTarget: this.aliasTarget,
40
+ default: this.default,
41
+ export: this.export,
42
+ tsFlags: this.tsFlags,
43
+ metadata: this.metadata
44
+ });
45
+ this.initializeCopy(copy);
46
+ watch(() => this.default, def => copy.default = def);
47
+ watch(() => this.export, exp => copy.export = exp);
48
+ watch(() => this.tsFlags, flags => copy.tsFlags = flags);
49
+ return copy;
50
+ }
41
51
  #export;
42
52
  get export() {
43
53
  track(this, TrackOpTypes.GET, "export");
@@ -67,6 +77,11 @@ export class TSOutputSymbol extends OutputSymbol {
67
77
  track(this, TrackOpTypes.GET, "tsFlags");
68
78
  return this.#tsFlags;
69
79
  }
80
+ #hasInstanceMembers = false;
81
+ get hasInstanceMembers() {
82
+ track(this, TrackOpTypes.GET, "hasInstanceMembers");
83
+ return this.#hasInstanceMembers;
84
+ }
70
85
  set tsFlags(value) {
71
86
  const oldValue = this.#tsFlags;
72
87
  if (oldValue === value) {
@@ -78,26 +93,34 @@ export class TSOutputSymbol extends OutputSymbol {
78
93
  get scope() {
79
94
  return super.scope;
80
95
  }
81
- set scope(value) {
82
- super.scope = value;
96
+ get staticMembers() {
97
+ return this.memberSpaceFor("static");
83
98
  }
84
- get staticMemberScope() {
85
- return super.staticMemberScope;
99
+ get instanceMembers() {
100
+ return this.memberSpaceFor("instance");
86
101
  }
87
- get instanceMemberScope() {
88
- return super.instanceMemberScope;
102
+ get privateInstanceMembers() {
103
+ return this.memberSpaceFor("private-instance");
89
104
  }
90
- #privateMemberScope;
91
- get privateMemberScope() {
92
- return this.#privateMemberScope;
105
+ get privateStaticMembers() {
106
+ return this.memberSpaceFor("private-static");
93
107
  }
94
- #privateStaticMemberScope;
95
- get privateStaticMemberScope() {
96
- return this.#privateStaticMemberScope;
108
+ get isPrivateMemberSymbol() {
109
+ return this.spaces.length > 0 && this.spaces.filter(s => s.key === "private-static" || s.key === "private-instance").length > 0;
97
110
  }
98
- createMemberScope(name, options) {
99
- return new TSMemberScope(name, {
100
- ...options
101
- });
111
+ get isPublicMemberSymbol() {
112
+ return !this.isPrivateMemberSymbol;
113
+ }
114
+ get isStaticMemberSymbol() {
115
+ return !this.isInstanceMemberSymbol;
116
+ }
117
+ get isInstanceMemberSymbol() {
118
+ return this.spaces.length > 0 && this.spaces.filter(s => s.key === "instance" || s.key === "private-instance").length > 0;
119
+ }
120
+ get isTypeSymbol() {
121
+ return !!(this.tsFlags & TSSymbolFlags.TypeSymbol);
122
+ }
123
+ get isValueSymbol() {
124
+ return this.spaces.some(s => s.key === "values");
102
125
  }
103
126
  }
@@ -5,7 +5,6 @@ export interface TSPackageScopeOptions extends OutputScopeOptions {
5
5
  }
6
6
  export declare class TSPackageScope extends OutputScope {
7
7
  #private;
8
- get kind(): "package";
9
8
  /**
10
9
  * The version of the this package.
11
10
  */
@@ -39,5 +38,6 @@ export declare class TSPackageScope extends OutputScope {
39
38
  addExport(publicPath: string, module: TSModuleScope): void;
40
39
  addModule(module: TSModuleScope): void;
41
40
  findExportedSymbol(refkey: Refkey): [string, TSModuleScope] | null;
41
+ copyTo(): TSPackageScope;
42
42
  }
43
43
  //# sourceMappingURL=ts-package-scope.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ts-package-scope.d.ts","sourceRoot":"","sources":["../../../src/symbols/ts-package-scope.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EACX,kBAAkB,EAClB,MAAM,EAEP,MAAM,gBAAgB,CAAC;AAExB,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAErD,MAAM,WAAW,qBAAsB,SAAQ,kBAAkB;IAC/D,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED,qBAAa,cAAe,SAAQ,WAAW;;IAC7C,IAAI,IAAI,IACC,SAAS,CACjB;IAED;;OAEG;IACH,IAAI,OAAO,WAEV;IAGD;;;;;OAKG;IACH,IAAI,eAAe,+BAElB;IAGD;;OAEG;IACH,IAAI,YAAY,wBAEf;IAGD;;;OAGG;IACH,IAAI,OAAO,uBAEV;IAGD;;OAEG;IACH,IAAI,IAAI,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,CAAC,GAAG,IAAI;IAUlE,MAAM,IAAI,cAAc;CAGzB"}
@@ -1,10 +1,6 @@
1
1
  import { OutputScope, shallowReactive } from "@alloy-js/core";
2
2
  import { modulePath } from "../utils.js";
3
3
  export class TSPackageScope extends OutputScope {
4
- get kind() {
5
- return "package";
6
- }
7
-
8
4
  /**
9
5
  * The version of the this package.
10
6
  */
@@ -57,7 +53,7 @@ export class TSPackageScope extends OutputScope {
57
53
  }
58
54
  #builtin;
59
55
  constructor(name, version, path, options = {}) {
60
- super(name, options);
56
+ super(name, undefined, options);
61
57
  this.#version = version;
62
58
  this.#path = path;
63
59
  this.#builtin = !!options.builtin;
@@ -79,4 +75,7 @@ export class TSPackageScope extends OutputScope {
79
75
  }
80
76
  return null;
81
77
  }
78
+ copyTo() {
79
+ throw new Error("Not supported");
80
+ }
82
81
  }
@@ -1,4 +1,6 @@
1
1
  import { CallSignatureProps } from "./components/CallSignature.jsx";
2
+ import { TSLexicalScope } from "./symbols/ts-lexical-scope.js";
3
+ import { TSOutputSymbol } from "./symbols/ts-output-symbol.js";
2
4
  export declare function modulePath(path: string): string;
3
5
  /**
4
6
  * Extract only the call signature props from a props object which extends
@@ -6,4 +8,6 @@ export declare function modulePath(path: string): string;
6
8
  */
7
9
  export declare function getCallSignatureProps(props: CallSignatureProps, defaults?: Partial<CallSignatureProps>): CallSignatureProps;
8
10
  export declare function isValidJSIdentifier(str: string): boolean;
11
+ export declare function useLexicalScope(): TSLexicalScope | undefined;
12
+ export declare function useMemberOwner(): TSOutputSymbol;
9
13
  //# sourceMappingURL=utils.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAC;AAEpE,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,UAMtC;AAED;;;GAGG;AACH,wBAAgB,qBAAqB,CACnC,KAAK,EAAE,kBAAkB,EACzB,QAAQ,CAAC,EAAE,OAAO,CAAC,kBAAkB,CAAC,sBAevC;AAKD,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,MAAM,WAE9C"}
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAC;AACpE,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAC/D,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAE/D,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,UAMtC;AAED;;;GAGG;AACH,wBAAgB,qBAAqB,CACnC,KAAK,EAAE,kBAAkB,EACzB,QAAQ,CAAC,EAAE,OAAO,CAAC,kBAAkB,CAAC,sBAevC;AAKD,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,MAAM,WAE9C;AAED,wBAAgB,eAAe,IAAI,cAAc,GAAG,SAAS,CAa5D;AAED,wBAAgB,cAAc,IAAI,cAAc,CAa/C"}
package/dist/src/utils.js CHANGED
@@ -1,4 +1,6 @@
1
- import { defaultProps, splitProps } from "@alloy-js/core";
1
+ import { defaultProps, splitProps, useMemberContext, useScope } from "@alloy-js/core";
2
+ import { TSLexicalScope } from "./symbols/ts-lexical-scope.js";
3
+ import { TSOutputSymbol } from "./symbols/ts-output-symbol.js";
2
4
  export function modulePath(path) {
3
5
  if (path[0] !== ".") {
4
6
  path = "./" + path;
@@ -20,4 +22,24 @@ export function getCallSignatureProps(props, defaults) {
20
22
  const identifierRegex = /^(?:[\p{ID_Start}$_])(?:[\p{ID_Continue}$\u200C\u200D])*$/u;
21
23
  export function isValidJSIdentifier(str) {
22
24
  return identifierRegex.test(str);
25
+ }
26
+ export function useLexicalScope() {
27
+ const scope = useScope();
28
+ if (!scope) {
29
+ return undefined;
30
+ }
31
+ if (!(scope instanceof TSLexicalScope)) {
32
+ throw new Error("A lexical scope is required but the current scope is not a lexical scope");
33
+ }
34
+ return scope;
35
+ }
36
+ export function useMemberOwner() {
37
+ const memberScope = useMemberContext();
38
+ if (!memberScope) {
39
+ throw new Error("A member owner is required but no member scope was found");
40
+ }
41
+ if (!(memberScope.ownerSymbol instanceof TSOutputSymbol)) {
42
+ throw new Error("A member owner is required but the current owner is not a TSOutputSymbol");
43
+ }
44
+ return memberScope.ownerSymbol;
23
45
  }
@@ -135,7 +135,7 @@ describe("instance members", () => {
135
135
  });
136
136
  }
137
137
  }), one]);
138
- }).toThrow(/Cannot resolve member symbols/);
138
+ }).toThrow(/Cannot reference instance member 'one' without an instance of 'Foo'/);
139
139
  });
140
140
  it("cannot be referenced outside the class when protected", () => {
141
141
  const one = refkey();
@@ -155,7 +155,7 @@ describe("instance members", () => {
155
155
  });
156
156
  }
157
157
  }), one]);
158
- }).toThrow(/Cannot resolve member symbols/);
158
+ }).toThrow(/Cannot reference instance member 'one' without an instance of 'Foo'/);
159
159
  });
160
160
  it("cannot be referenced outside the class when private", () => {
161
161
  const one = refkey();
@@ -175,7 +175,7 @@ describe("instance members", () => {
175
175
  });
176
176
  }
177
177
  }), one]);
178
- }).toThrow(/Cannot resolve private member symbols/);
178
+ }).toThrow(/Cannot reference instance member 'one' without an instance of 'Foo'/);
179
179
  });
180
180
  it("works with invalid identifier names", () => {
181
181
  const one = refkey();
@@ -397,7 +397,7 @@ describe("static members", () => {
397
397
  }
398
398
  });
399
399
  }
400
- }), _$createIntrinsic("hbr", {}), two, ";"])).toThrow(/Cannot resolve/);
400
+ }), _$createIntrinsic("hbr", {}), two, ";"])).toThrow(/Cannot reference/);
401
401
  });
402
402
  });
403
403
  describe("instance methods", () => {
@@ -1,8 +1,8 @@
1
1
  import { memo as _$memo, createIntrinsic as _$createIntrinsic, createComponent as _$createComponent } from "@alloy-js/core/jsx-runtime";
2
2
  import { Output, render } from "@alloy-js/core";
3
- import { expect, it } from "vitest";
3
+ import { it } from "vitest";
4
4
  import { fs } from "../src/builtins/node.js";
5
- import { createPackage, FunctionDeclaration, PackageDirectory, SourceFile, TSOutputSymbol } from "../src/index.js";
5
+ import { createPackage, FunctionDeclaration, PackageDirectory, SourceFile } from "../src/index.js";
6
6
  import { assertFileContents } from "./utils.js";
7
7
  it("can import builtins", () => {
8
8
  const testLib = createPackage({
@@ -191,40 +191,4 @@ it("can import static members", () => {
191
191
  }
192
192
  `
193
193
  });
194
- });
195
- it("can import instance members", () => {
196
- const mcpSdk = createPackage({
197
- name: "@modelcontextprotocol/sdk",
198
- version: "^3.23.0",
199
- descriptor: {
200
- "./server/index.js": {
201
- named: [{
202
- name: "Server",
203
- instanceMembers: ["instanceHandler"]
204
- }]
205
- }
206
- }
207
- });
208
- function RunTest() {
209
- const sym = new TSOutputSymbol("foo");
210
- const binder = sym.binder;
211
- expect(binder).toBeDefined();
212
- const source = binder.getSymbolForRefkey(mcpSdk["./server/index.js"].Server).value;
213
- expect(source).toBeDefined();
214
- expect(source.instanceMemberScope?.symbols.size).toBe(1);
215
- source.instantiateTo(sym);
216
- expect(sym.staticMemberScope?.symbols.size).toBe(1);
217
- expect([...sym.staticMemberScope.symbols][0].name).toBe("instanceHandler");
218
- }
219
- render(_$createComponent(Output, {
220
- externals: [mcpSdk],
221
- get children() {
222
- return _$createComponent(SourceFile, {
223
- path: "index.ts",
224
- get children() {
225
- return _$createComponent(RunTest, {});
226
- }
227
- });
228
- }
229
- }));
230
194
  });
@@ -1,5 +1,5 @@
1
1
  import { createComponent as _$createComponent } from "@alloy-js/core/jsx-runtime";
2
- import { Declaration, Output, refkey, render } from "@alloy-js/core";
2
+ import { Output, refkey, render } from "@alloy-js/core";
3
3
  import "@alloy-js/core/testing";
4
4
  import { it } from "vitest";
5
5
  import * as ts from "../src/components/index.js";
@@ -11,7 +11,7 @@ it("works with back references", () => {
11
11
  return [_$createComponent(ts.SourceFile, {
12
12
  path: "test1.ts",
13
13
  get children() {
14
- return _$createComponent(Declaration, {
14
+ return _$createComponent(ts.Declaration, {
15
15
  name: "foo",
16
16
  get refkey() {
17
17
  return refkey("foo");
@@ -57,7 +57,7 @@ it("works with forward references", () => {
57
57
  }), _$createComponent(ts.SourceFile, {
58
58
  path: "test1.ts",
59
59
  get children() {
60
- return _$createComponent(Declaration, {
60
+ return _$createComponent(ts.Declaration, {
61
61
  name: "foo",
62
62
  get refkey() {
63
63
  return refkey("foo");