@alloy-js/typescript 0.16.0 → 0.17.0

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 (128) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/dist/src/builtins/node.d.ts +9 -41
  3. package/dist/src/builtins/node.d.ts.map +1 -1
  4. package/dist/src/components/ArrowFunction.d.ts +3 -3
  5. package/dist/src/components/BarrelFile.d.ts +1 -1
  6. package/dist/src/components/BarrelFile.d.ts.map +1 -1
  7. package/dist/src/components/BlockScope.d.ts +1 -1
  8. package/dist/src/components/BlockScope.d.ts.map +1 -1
  9. package/dist/src/components/ClassDeclaration.d.ts.map +1 -1
  10. package/dist/src/components/ClassDeclaration.js +5 -7
  11. package/dist/src/components/Declaration.d.ts.map +1 -1
  12. package/dist/src/components/Declaration.js +3 -4
  13. package/dist/src/components/EnumDeclaration.d.ts +1 -1
  14. package/dist/src/components/EnumDeclaration.d.ts.map +1 -1
  15. package/dist/src/components/EnumDeclaration.js +3 -4
  16. package/dist/src/components/EnumMember.d.ts.map +1 -1
  17. package/dist/src/components/EnumMember.js +3 -4
  18. package/dist/src/components/FunctionBase.d.ts +4 -4
  19. package/dist/src/components/FunctionBase.d.ts.map +1 -1
  20. package/dist/src/components/FunctionBase.js +15 -10
  21. package/dist/src/components/FunctionDeclaration.d.ts +3 -3
  22. package/dist/src/components/FunctionExpression.d.ts +3 -3
  23. package/dist/src/components/FunctionType.d.ts +2 -2
  24. package/dist/src/components/ImportStatement.d.ts +1 -1
  25. package/dist/src/components/ImportStatement.d.ts.map +1 -1
  26. package/dist/src/components/Interface.js +1 -1
  27. package/dist/src/components/InterfaceMethod.d.ts +2 -2
  28. package/dist/src/components/MemberDeclaration.d.ts +1 -1
  29. package/dist/src/components/MemberDeclaration.d.ts.map +1 -1
  30. package/dist/src/components/MemberDeclaration.js +4 -4
  31. package/dist/src/components/MemberExpression.d.ts +6 -1
  32. package/dist/src/components/MemberExpression.d.ts.map +1 -1
  33. package/dist/src/components/MemberExpression.js +38 -14
  34. package/dist/src/components/NewExpression.d.ts +5 -0
  35. package/dist/src/components/NewExpression.d.ts.map +1 -0
  36. package/dist/src/components/NewExpression.js +12 -0
  37. package/dist/src/components/ObjectExpression.d.ts.map +1 -1
  38. package/dist/src/components/ObjectExpression.js +14 -15
  39. package/dist/src/components/PackageDirectory.d.ts.map +1 -1
  40. package/dist/src/components/PackageDirectory.js +3 -3
  41. package/dist/src/components/PackageJson.d.ts +1 -1
  42. package/dist/src/components/PackageJson.d.ts.map +1 -1
  43. package/dist/src/components/PropertyName.d.ts +1 -1
  44. package/dist/src/components/PropertyName.d.ts.map +1 -1
  45. package/dist/src/components/Reference.d.ts +1 -1
  46. package/dist/src/components/Reference.d.ts.map +1 -1
  47. package/dist/src/components/Reference.js +5 -1
  48. package/dist/src/components/SourceFile.d.ts.map +1 -1
  49. package/dist/src/components/SourceFile.js +3 -3
  50. package/dist/src/components/TsConfigJson.d.ts +1 -1
  51. package/dist/src/components/TsConfigJson.d.ts.map +1 -1
  52. package/dist/src/components/TypeDeclaration.d.ts +1 -1
  53. package/dist/src/components/TypeDeclaration.d.ts.map +1 -1
  54. package/dist/src/components/VarDeclaration.d.ts.map +1 -1
  55. package/dist/src/components/VarDeclaration.js +30 -10
  56. package/dist/src/components/index.d.ts +1 -0
  57. package/dist/src/components/index.d.ts.map +1 -1
  58. package/dist/src/components/index.js +1 -0
  59. package/dist/src/components/stc/index.d.ts +45 -43
  60. package/dist/src/components/stc/index.d.ts.map +1 -1
  61. package/dist/src/components/stc/index.js +46 -44
  62. package/dist/src/create-package.d.ts +62 -18
  63. package/dist/src/create-package.d.ts.map +1 -1
  64. package/dist/src/create-package.js +153 -15
  65. package/dist/src/source-directory-data.d.ts.map +1 -1
  66. package/dist/src/source-directory-data.js +2 -2
  67. package/dist/src/symbols/reference.d.ts +2 -1
  68. package/dist/src/symbols/reference.d.ts.map +1 -1
  69. package/dist/src/symbols/reference.js +3 -4
  70. package/dist/src/symbols/scopes.d.ts +1 -4
  71. package/dist/src/symbols/scopes.d.ts.map +1 -1
  72. package/dist/src/symbols/ts-member-scope.d.ts +4 -6
  73. package/dist/src/symbols/ts-member-scope.d.ts.map +1 -1
  74. package/dist/src/symbols/ts-member-scope.js +8 -10
  75. package/dist/src/symbols/ts-module-scope.d.ts +8 -11
  76. package/dist/src/symbols/ts-module-scope.d.ts.map +1 -1
  77. package/dist/src/symbols/ts-module-scope.js +47 -40
  78. package/dist/src/symbols/ts-output-symbol.d.ts +23 -16
  79. package/dist/src/symbols/ts-output-symbol.d.ts.map +1 -1
  80. package/dist/src/symbols/ts-output-symbol.js +88 -27
  81. package/dist/src/symbols/ts-package-scope.d.ts +18 -14
  82. package/dist/src/symbols/ts-package-scope.d.ts.map +1 -1
  83. package/dist/src/symbols/ts-package-scope.js +78 -27
  84. package/dist/test/class.test.js +2 -1
  85. package/dist/test/externals.test.js +87 -2
  86. package/dist/test/function-declaration.test.js +74 -3
  87. package/dist/test/member-expression.test.js +108 -2
  88. package/dist/test/new-expression.test.d.ts +2 -0
  89. package/dist/test/new-expression.test.d.ts.map +1 -0
  90. package/dist/test/new-expression.test.js +62 -0
  91. package/dist/test/var-declaration.test.d.ts.map +1 -1
  92. package/dist/test/var-declaration.test.js +145 -2
  93. package/dist/tsconfig.tsbuildinfo +1 -1
  94. package/package.json +4 -4
  95. package/src/components/ClassDeclaration.tsx +5 -7
  96. package/src/components/Declaration.tsx +3 -8
  97. package/src/components/EnumDeclaration.tsx +3 -4
  98. package/src/components/EnumMember.tsx +3 -4
  99. package/src/components/FunctionBase.tsx +25 -18
  100. package/src/components/ImportStatement.tsx +0 -1
  101. package/src/components/Interface.tsx +1 -1
  102. package/src/components/MemberDeclaration.tsx +5 -8
  103. package/src/components/MemberExpression.tsx +67 -15
  104. package/src/components/NewExpression.tsx +25 -0
  105. package/src/components/ObjectExpression.tsx +18 -16
  106. package/src/components/PackageDirectory.tsx +2 -10
  107. package/src/components/Reference.tsx +4 -2
  108. package/src/components/SourceFile.tsx +2 -5
  109. package/src/components/VarDeclaration.tsx +34 -11
  110. package/src/components/index.ts +1 -0
  111. package/src/components/stc/index.ts +46 -44
  112. package/src/create-package.ts +274 -35
  113. package/src/source-directory-data.ts +2 -2
  114. package/src/symbols/reference.ts +10 -5
  115. package/src/symbols/scopes.ts +1 -6
  116. package/src/symbols/ts-member-scope.ts +8 -23
  117. package/src/symbols/ts-module-scope.ts +58 -62
  118. package/src/symbols/ts-output-symbol.ts +108 -50
  119. package/src/symbols/ts-package-scope.ts +71 -53
  120. package/temp/api.json +1589 -1619
  121. package/test/class.test.tsx +2 -1
  122. package/test/externals.test.tsx +99 -1
  123. package/test/function-declaration.test.tsx +75 -2
  124. package/test/member-expression.test.tsx +93 -2
  125. package/test/new-expression.test.tsx +42 -0
  126. package/test/values.test.tsx +1 -0
  127. package/test/var-declaration.test.tsx +101 -1
  128. package/tsdoc-metadata.json +1 -1
@@ -1,43 +1,50 @@
1
- import { refkey } from "@alloy-js/core";
2
- import { createTSSymbol, TSSymbolFlags } from "./ts-output-symbol.js";
3
- export function createTSModuleScope(binder, parent, path) {
4
- return binder.createScope({
5
- kind: "module",
6
- name: path,
7
- parent,
8
- exportedSymbols: new Map(),
9
- importedSymbols: new Map(),
10
- importedModules: new Map(),
11
- addImport(targetSymbol, targetModule, options) {
12
- const existing = this.importedSymbols.get(targetSymbol);
13
- if (existing) {
14
- if (!options?.type && existing.tsFlags & TSSymbolFlags.TypeSymbol) {
15
- existing.tsFlags &= ~TSSymbolFlags.TypeSymbol;
16
- }
17
- return existing;
1
+ import { OutputScope, reactive, shallowReactive } from "@alloy-js/core";
2
+ import { TSOutputSymbol, TSSymbolFlags } from "./ts-output-symbol.js";
3
+ export class TSModuleScope extends OutputScope {
4
+ get kind() {
5
+ return "module";
6
+ }
7
+ #exportedSymbols = shallowReactive(new Map());
8
+ get exportedSymbols() {
9
+ return this.#exportedSymbols;
10
+ }
11
+ #importedSymbols = shallowReactive(new Map());
12
+ get importedSymbols() {
13
+ return this.#importedSymbols;
14
+ }
15
+ #importedModules = reactive(new Map());
16
+ get importedModules() {
17
+ return this.#importedModules;
18
+ }
19
+ addImport(targetSymbol, targetModule, options) {
20
+ const existing = this.importedSymbols.get(targetSymbol);
21
+ if (existing) {
22
+ if (!options?.type && existing.tsFlags & TSSymbolFlags.TypeSymbol) {
23
+ existing.tsFlags &= ~TSSymbolFlags.TypeSymbol;
18
24
  }
19
- if (targetModule.kind !== "module") {
20
- throw new Error("Cannot import symbol that isn't in module scope");
21
- }
22
- if (!this.importedModules.has(targetModule)) {
23
- this.importedModules.set(targetModule, new Set());
24
- }
25
- const localSymbol = createTSSymbol({
26
- binder,
27
- scope: this,
28
- name: targetSymbol.name,
29
- refkey: refkey({}),
30
- tsFlags: TSSymbolFlags.LocalImportSymbol
31
- });
32
- if (options?.type) {
33
- localSymbol.tsFlags |= TSSymbolFlags.TypeSymbol;
34
- }
35
- this.importedSymbols.set(targetSymbol, localSymbol);
36
- this.importedModules.get(targetModule).add({
37
- local: localSymbol,
38
- target: targetSymbol
39
- });
40
- return localSymbol;
25
+ return existing;
26
+ }
27
+ if (targetModule.kind !== "module") {
28
+ throw new Error("Cannot import symbol that isn't in module scope");
29
+ }
30
+ if (!this.importedModules.has(targetModule)) {
31
+ this.importedModules.set(targetModule, new Set());
32
+ }
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);
40
+ if (options?.type) {
41
+ localSymbol.tsFlags |= TSSymbolFlags.TypeSymbol;
41
42
  }
42
- });
43
+ this.importedSymbols.set(targetSymbol, localSymbol);
44
+ this.importedModules.get(targetModule).add({
45
+ local: localSymbol,
46
+ target: targetSymbol
47
+ });
48
+ return localSymbol;
49
+ }
43
50
  }
@@ -1,4 +1,4 @@
1
- import { Binder, OutputSymbol, OutputSymbolFlags, Refkey } from "@alloy-js/core";
1
+ import { OutputScopeFlags, OutputSymbol, OutputSymbolOptions } from "@alloy-js/core";
2
2
  import { TSOutputScope } from "./scopes.js";
3
3
  import { TSMemberScope } from "./ts-member-scope.js";
4
4
  export declare enum TSSymbolFlags {
@@ -10,24 +10,31 @@ export declare enum TSSymbolFlags {
10
10
  PrivateMemberContainer = 16,
11
11
  Nullish = 32
12
12
  }
13
- export interface TSOutputSymbol extends OutputSymbol {
14
- scope: TSOutputScope;
15
- export: boolean;
16
- default: boolean;
17
- tsFlags: TSSymbolFlags;
18
- privateMemberScope?: TSMemberScope;
19
- privateStaticMemberScope?: TSMemberScope;
20
- }
21
- export interface createTsSymbolOptions {
22
- name: string;
23
- refkey?: Refkey | Refkey[];
24
- binder?: Binder;
13
+ export interface CreateTsSymbolOptions extends OutputSymbolOptions {
25
14
  scope?: TSOutputScope;
15
+ owner?: TSOutputSymbol;
26
16
  export?: boolean;
27
17
  default?: boolean;
28
- flags?: OutputSymbolFlags;
29
18
  tsFlags?: TSSymbolFlags;
30
- metadata?: Record<string, unknown>;
31
19
  }
32
- export declare function createTSSymbol(options: createTsSymbolOptions): TSOutputSymbol;
20
+ export declare class TSOutputSymbol extends OutputSymbol {
21
+ #private;
22
+ constructor(name: string, options?: CreateTsSymbolOptions);
23
+ get export(): boolean;
24
+ set export(value: boolean);
25
+ get default(): boolean;
26
+ set default(value: boolean);
27
+ get tsFlags(): TSSymbolFlags;
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;
39
+ }
33
40
  //# 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,MAAM,EACN,YAAY,EACZ,iBAAiB,EACjB,MAAM,EAEP,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAuB,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAG1E,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,cAAe,SAAQ,YAAY;IAClD,KAAK,EAAE,aAAa,CAAC;IACrB,MAAM,EAAE,OAAO,CAAC;IAChB,OAAO,EAAE,OAAO,CAAC;IACjB,OAAO,EAAE,aAAa,CAAC;IACvB,kBAAkB,CAAC,EAAE,aAAa,CAAC;IACnC,wBAAwB,CAAC,EAAE,aAAa,CAAC;CAC1C;AAED,MAAM,WAAW,qBAAqB;IACpC,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IAC3B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,aAAa,CAAC;IACtB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,KAAK,CAAC,EAAE,iBAAiB,CAAC;IAC1B,OAAO,CAAC,EAAE,aAAa,CAAC;IACxB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACpC;AAED,wBAAgB,cAAc,CAAC,OAAO,EAAE,qBAAqB,GAAG,cAAc,CAsC7E"}
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,CAD/B;IACD,IAAI,OAAO,CAAC,KAAK,EAAE,aAAa,EAO/B;IAED,IAAI,KAAK,IAGQ,aAAa,CAD7B;IACD,IAAI,KAAK,CAAC,KAAK,EAAE,aAAa,EAE7B;IAED,IAAI,iBAAiB,IACe,aAAa,GAAG,SAAS,CAC5D;IAED,IAAI,mBAAmB,IACe,aAAa,GAAG,SAAS,CAC9D;IAGD,IAAI,kBAAkB,8BAErB;IAGD,IAAI,wBAAwB,8BAE3B;IAED,SAAS,CAAC,iBAAiB,CACzB,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE;QAAE,KAAK,CAAC,EAAE,YAAY,CAAC;QAAC,KAAK,CAAC,EAAE,gBAAgB,CAAA;KAAE,GAC1D,aAAa;CAKjB"}
@@ -1,5 +1,5 @@
1
- import { OutputSymbolFlags, useDefaultScope } from "@alloy-js/core";
2
- import { createTSMemberScope } from "./ts-member-scope.js";
1
+ import { OutputScopeFlags, OutputSymbol, track, TrackOpTypes, trigger, TriggerOpTypes } from "@alloy-js/core";
2
+ import { TSMemberScope } from "./ts-member-scope.js";
3
3
 
4
4
  // prettier-ignore
5
5
  export let TSSymbolFlags = /*#__PURE__*/function (TSSymbolFlags) {
@@ -12,31 +12,92 @@ export let TSSymbolFlags = /*#__PURE__*/function (TSSymbolFlags) {
12
12
  TSSymbolFlags[TSSymbolFlags["Nullish"] = 32] = "Nullish";
13
13
  return TSSymbolFlags;
14
14
  }({});
15
- export function createTSSymbol(options) {
16
- const scope = options.scope ?? useDefaultScope(options.flags);
17
- if (scope.kind !== "module" && (options.export || options.default)) {
18
- throw new Error("Can't export symbol from non-module scope");
19
- }
20
- const binder = scope.binder;
21
- const tsFlags = options.tsFlags ?? TSSymbolFlags.None;
22
- const sym = binder.createSymbol({
23
- name: options.name,
24
- scope,
25
- refkey: options.refkey,
26
- export: !!options.export,
27
- default: !!options.default,
28
- flags: options.flags ?? OutputSymbolFlags.None,
29
- tsFlags,
30
- metadata: options.metadata
31
- });
32
- if (tsFlags & TSSymbolFlags.PrivateMemberContainer) {
33
- sym.privateMemberScope = createTSMemberScope(binder, undefined, sym);
34
- sym.privateStaticMemberScope = createTSMemberScope(binder, undefined, sym, true);
35
- }
36
- if (options.export && scope.kind === "module") {
37
- for (const refkey of sym.refkeys) {
38
- scope.exportedSymbols.set(refkey, sym);
15
+ export class TSOutputSymbol extends OutputSymbol {
16
+ constructor(name, options = {}) {
17
+ super(name, options);
18
+ this.#export = !!options.export;
19
+ this.#default = !!options.default;
20
+ 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
+ });
39
34
  }
35
+ if (options.export && this.scope.kind === "module") {
36
+ for (const refkey of this.refkeys) {
37
+ this.scope.exportedSymbols.set(refkey, this);
38
+ }
39
+ }
40
+ }
41
+ #export;
42
+ get export() {
43
+ track(this, TrackOpTypes.GET, "export");
44
+ return this.#export;
45
+ }
46
+ set export(value) {
47
+ if (this.#export === value) {
48
+ return;
49
+ }
50
+ this.#export = value;
51
+ trigger(this, TriggerOpTypes.SET, "export", value, !value);
52
+ }
53
+ #default;
54
+ get default() {
55
+ track(this, TrackOpTypes.GET, "default");
56
+ return this.#default;
57
+ }
58
+ set default(value) {
59
+ if (this.#default === value) {
60
+ return;
61
+ }
62
+ this.#default = value;
63
+ trigger(this, TriggerOpTypes.SET, "default", value, !value);
64
+ }
65
+ #tsFlags;
66
+ get tsFlags() {
67
+ track(this, TrackOpTypes.GET, "tsFlags");
68
+ return this.#tsFlags;
69
+ }
70
+ set tsFlags(value) {
71
+ const oldValue = this.#tsFlags;
72
+ if (oldValue === value) {
73
+ return;
74
+ }
75
+ this.#tsFlags = value;
76
+ trigger(this, TriggerOpTypes.SET, "tsFlags", value, oldValue);
77
+ }
78
+ get scope() {
79
+ return super.scope;
80
+ }
81
+ set scope(value) {
82
+ super.scope = value;
83
+ }
84
+ get staticMemberScope() {
85
+ return super.staticMemberScope;
86
+ }
87
+ get instanceMemberScope() {
88
+ return super.instanceMemberScope;
89
+ }
90
+ #privateMemberScope;
91
+ get privateMemberScope() {
92
+ return this.#privateMemberScope;
93
+ }
94
+ #privateStaticMemberScope;
95
+ get privateStaticMemberScope() {
96
+ return this.#privateStaticMemberScope;
97
+ }
98
+ createMemberScope(name, options) {
99
+ return new TSMemberScope(name, {
100
+ ...options
101
+ });
40
102
  }
41
- return sym;
42
103
  }
@@ -1,39 +1,43 @@
1
- import { Binder, OutputScope, Refkey } from "@alloy-js/core";
1
+ import { OutputScope, OutputScopeOptions, Refkey } from "@alloy-js/core";
2
2
  import { TSModuleScope } from "./ts-module-scope.js";
3
- export interface TSPackageScope extends OutputScope {
4
- kind: "package";
3
+ export interface TSPackageScopeOptions extends OutputScopeOptions {
4
+ builtin?: boolean;
5
+ }
6
+ export declare class TSPackageScope extends OutputScope {
7
+ #private;
8
+ get kind(): "package";
5
9
  /**
6
10
  * The version of the this package.
7
11
  */
8
- version: string;
12
+ get version(): string;
9
13
  /**
10
14
  * The symbols exported by this package. They are broken down by which paths
11
15
  * they are exported from. It is possible a symbol may be present at multiple
12
16
  * paths, in which case emitters can decide which symbol to use based on their
13
17
  * own heuristics.
14
18
  */
15
- exportedSymbols: Map<string, TSModuleScope>;
16
- /**
17
- * The path of the root directory of the package.
18
- */
19
- path: string;
19
+ get exportedSymbols(): Map<string, TSModuleScope>;
20
20
  /**
21
21
  * The scopes for the packages this package depends on.
22
22
  */
23
- dependencies: Set<TSPackageScope>;
23
+ get dependencies(): Set<TSPackageScope>;
24
24
  /**
25
25
  * All of the modules contained within the package. These modules may or may not
26
26
  * be exported.
27
27
  */
28
- modules: Set<TSModuleScope>;
28
+ get modules(): Set<TSModuleScope>;
29
+ /**
30
+ * The path of the root directory of the package.
31
+ */
32
+ get path(): string;
29
33
  /**
30
34
  * Whether this is a built-in package provided by the platform.
31
35
  */
32
- builtin?: boolean;
33
- addExport(publicPath: string, localModule: TSModuleScope): void;
36
+ get builtin(): boolean;
37
+ constructor(name: string, version: string, path: string, options?: TSPackageScopeOptions);
34
38
  addDependency(pkg: TSPackageScope): void;
39
+ addExport(publicPath: string, module: TSModuleScope): void;
35
40
  addModule(module: TSModuleScope): void;
36
41
  findExportedSymbol(refkey: Refkey): [string, TSModuleScope] | null;
37
42
  }
38
- export declare function createTSPackageScope(binder: Binder, parent: OutputScope | undefined, name: string, version: string, path: string, builtin?: boolean): TSPackageScope;
39
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,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAE7D,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAErD,MAAM,WAAW,cAAe,SAAQ,WAAW;IACjD,IAAI,EAAE,SAAS,CAAC;IAChB;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC;IAEhB;;;;;OAKG;IACH,eAAe,EAAE,GAAG,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;IAE5C;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IAEb;;OAEG;IACH,YAAY,EAAE,GAAG,CAAC,cAAc,CAAC,CAAC;IAElC;;;OAGG;IACH,OAAO,EAAE,GAAG,CAAC,aAAa,CAAC,CAAC;IAE5B;;OAEG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAElB,SAAS,CAAC,UAAU,EAAE,MAAM,EAAE,WAAW,EAAE,aAAa,GAAG,IAAI,CAAC;IAChE,aAAa,CAAC,GAAG,EAAE,cAAc,GAAG,IAAI,CAAC;IACzC,SAAS,CAAC,MAAM,EAAE,aAAa,GAAG,IAAI,CAAC;IACvC,kBAAkB,CAAC,MAAM,EAAE,MAAM,GAAG,CAAC,MAAM,EAAE,aAAa,CAAC,GAAG,IAAI,CAAC;CACpE;AAED,wBAAgB,oBAAoB,CAClC,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,WAAW,GAAG,SAAS,EAC/B,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE,OAAe,kBA+BzB"}
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,WAEP;IAGD;;OAEG;IACH,IAAI,OAAO,YAEV;gBAIC,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE,qBAA0B;IAQrC,aAAa,CAAC,GAAG,EAAE,cAAc;IAGjC,SAAS,CAAC,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,aAAa;IAGnD,SAAS,CAAC,MAAM,EAAE,aAAa;IAI/B,kBAAkB,CAAC,MAAM,EAAE,MAAM,GAAG,CAAC,MAAM,EAAE,aAAa,CAAC,GAAG,IAAI;CASnE"}
@@ -1,31 +1,82 @@
1
+ import { OutputScope, shallowReactive } from "@alloy-js/core";
1
2
  import { modulePath } from "../utils.js";
2
- export function createTSPackageScope(binder, parent, name, version, path, builtin = false) {
3
- return binder.createScope({
4
- kind: "package",
5
- name,
6
- parent,
7
- exportedSymbols: new Map(),
8
- dependencies: new Set(),
9
- modules: new Set(),
10
- version,
11
- path: path,
12
- builtin,
13
- addDependency(pkg) {
14
- this.dependencies.add(pkg);
15
- },
16
- addExport(publicPath, module) {
17
- this.exportedSymbols.set(modulePath(publicPath), module);
18
- },
19
- addModule(module) {
20
- this.modules.add(module);
21
- },
22
- findExportedSymbol(refkey) {
23
- for (const [publicPath, module] of this.exportedSymbols) {
24
- if (module.exportedSymbols.has(refkey)) {
25
- return [publicPath, module];
26
- }
3
+ export class TSPackageScope extends OutputScope {
4
+ get kind() {
5
+ return "package";
6
+ }
7
+
8
+ /**
9
+ * The version of the this package.
10
+ */
11
+ get version() {
12
+ return this.#version;
13
+ }
14
+ #version;
15
+
16
+ /**
17
+ * The symbols exported by this package. They are broken down by which paths
18
+ * they are exported from. It is possible a symbol may be present at multiple
19
+ * paths, in which case emitters can decide which symbol to use based on their
20
+ * own heuristics.
21
+ */
22
+ get exportedSymbols() {
23
+ return this.#exportedSymbols;
24
+ }
25
+ #exportedSymbols = shallowReactive(new Map());
26
+
27
+ /**
28
+ * The scopes for the packages this package depends on.
29
+ */
30
+ get dependencies() {
31
+ return this.#dependencies;
32
+ }
33
+ #dependencies = shallowReactive(new Set());
34
+
35
+ /**
36
+ * All of the modules contained within the package. These modules may or may not
37
+ * be exported.
38
+ */
39
+ get modules() {
40
+ return this.#modules;
41
+ }
42
+ #modules = shallowReactive(new Set());
43
+
44
+ /**
45
+ * The path of the root directory of the package.
46
+ */
47
+ get path() {
48
+ return this.#path;
49
+ }
50
+ #path;
51
+
52
+ /**
53
+ * Whether this is a built-in package provided by the platform.
54
+ */
55
+ get builtin() {
56
+ return this.#builtin;
57
+ }
58
+ #builtin;
59
+ constructor(name, version, path, options = {}) {
60
+ super(name, options);
61
+ this.#version = version;
62
+ this.#path = path;
63
+ this.#builtin = !!options.builtin;
64
+ }
65
+ addDependency(pkg) {
66
+ this.dependencies.add(pkg);
67
+ }
68
+ addExport(publicPath, module) {
69
+ this.exportedSymbols.set(modulePath(publicPath), module);
70
+ }
71
+ addModule(module) {
72
+ this.modules.add(module);
73
+ }
74
+ findExportedSymbol(refkey) {
75
+ for (const [publicPath, module] of this.exportedSymbols) {
76
+ if (module.exportedSymbols.has(refkey)) {
77
+ return [publicPath, module];
27
78
  }
28
- return null;
29
79
  }
30
- });
80
+ return null;
81
+ }
31
82
  }
@@ -252,7 +252,8 @@ describe("instance members", () => {
252
252
  const rk2 = refkey();
253
253
  const tree = render(_$createComponent(Output, {
254
254
  nameConflictResolver: () => {
255
- console.log("CONFLIT");
255
+ // do nothing
256
+ return undefined;
256
257
  },
257
258
  get children() {
258
259
  return [_$createComponent(ts.SourceFile, {
@@ -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 { it } from "vitest";
3
+ import { expect, it } from "vitest";
4
4
  import { fs } from "../src/builtins/node.js";
5
- import { createPackage, FunctionDeclaration, PackageDirectory, SourceFile } from "../src/index.js";
5
+ import { createPackage, FunctionDeclaration, PackageDirectory, SourceFile, TSOutputSymbol } from "../src/index.js";
6
6
  import { assertFileContents } from "./utils.js";
7
7
  it("can import builtins", () => {
8
8
  const testLib = createPackage({
@@ -142,4 +142,89 @@ it("can import builtins without a package", () => {
142
142
  }
143
143
  `
144
144
  });
145
+ });
146
+ it("can import static members", () => {
147
+ const mcpSdk = createPackage({
148
+ name: "@modelcontextprotocol/sdk",
149
+ version: "^3.23.0",
150
+ descriptor: {
151
+ "./server/index.js": {
152
+ named: [{
153
+ name: "server",
154
+ staticMembers: ["setRequestHandler", {
155
+ name: "nested",
156
+ staticMembers: ["nestedHandler"]
157
+ }],
158
+ instanceMembers: ["instanceHandler"]
159
+ }, {
160
+ name: "noMembers"
161
+ }, "simpleName"]
162
+ }
163
+ }
164
+ });
165
+ const res = render(_$createComponent(Output, {
166
+ externals: [mcpSdk],
167
+ get children() {
168
+ return _$createComponent(SourceFile, {
169
+ path: "index.ts",
170
+ get children() {
171
+ return _$createComponent(FunctionDeclaration, {
172
+ name: "foo",
173
+ get children() {
174
+ return [_$memo(() => mcpSdk["./server/index.js"].server), "();", _$createIntrinsic("hbr", {}), _$memo(() => mcpSdk["./server/index.js"].server.static.setRequestHandler), "();", _$createIntrinsic("hbr", {}), _$memo(() => mcpSdk["./server/index.js"].server.static.nested.static.nestedHandler), "();", _$createIntrinsic("hbr", {}), _$memo(() => mcpSdk["./server/index.js"].noMembers), "();", _$createIntrinsic("hbr", {}), _$memo(() => mcpSdk["./server/index.js"].simpleName), "();"];
175
+ }
176
+ });
177
+ }
178
+ });
179
+ }
180
+ }));
181
+ assertFileContents(res, {
182
+ "index.ts": `
183
+ import { noMembers, server, simpleName } from "@modelcontextprotocol/sdk/server/index.js";
184
+
185
+ function foo() {
186
+ server();
187
+ server.setRequestHandler();
188
+ server.nested.nestedHandler();
189
+ noMembers();
190
+ simpleName();
191
+ }
192
+ `
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
+ }));
145
230
  });
@@ -1,8 +1,9 @@
1
- import { createComponent as _$createComponent } from "@alloy-js/core/jsx-runtime";
2
- import { refkey, StatementList } from "@alloy-js/core";
1
+ import { createComponent as _$createComponent, memo as _$memo } from "@alloy-js/core/jsx-runtime";
2
+ import { List, memberRefkey, refkey, StatementList } from "@alloy-js/core";
3
3
  import { d } from "@alloy-js/core/testing";
4
4
  import { describe, expect, it } from "vitest";
5
- import { FunctionDeclaration, VarDeclaration } from "../src/index.js";
5
+ import { ClassField } from "../src/components/stc/index.js";
6
+ import { ClassDeclaration, FunctionDeclaration, InterfaceDeclaration, InterfaceMember, VarDeclaration } from "../src/index.js";
6
7
  import { toSourceText } from "./utils.js";
7
8
  it("works", () => {
8
9
  expect(toSourceText(_$createComponent(FunctionDeclaration, {
@@ -243,4 +244,74 @@ describe("symbols", () => {
243
244
  }
244
245
  `);
245
246
  });
247
+ it("adds symbols for members of parameters when a type is provided", () => {
248
+ const ifaceRk = refkey();
249
+ const ifaceMemberRk = refkey();
250
+ const clsRk = refkey();
251
+ const clsMemberRk = refkey();
252
+ const ifaceParamRk = refkey();
253
+ const clsParamRk = refkey();
254
+ const ifaceParam = {
255
+ name: "ifaceParam",
256
+ refkey: ifaceParamRk,
257
+ type: ifaceRk,
258
+ optional: true
259
+ };
260
+ const clsParam = {
261
+ name: "classParam",
262
+ refkey: clsParamRk,
263
+ type: clsRk,
264
+ optional: true
265
+ };
266
+ const decl = _$createComponent(List, {
267
+ doubleHardline: true,
268
+ get children() {
269
+ return [_$createComponent(InterfaceDeclaration, {
270
+ name: "IFace",
271
+ refkey: ifaceRk,
272
+ get children() {
273
+ return _$createComponent(InterfaceMember, {
274
+ name: "ifaceProp",
275
+ refkey: ifaceMemberRk,
276
+ children: "string"
277
+ });
278
+ }
279
+ }), _$createComponent(ClassDeclaration, {
280
+ name: "Class",
281
+ refkey: clsRk,
282
+ get children() {
283
+ return _$createComponent(ClassField, {
284
+ name: "classProp",
285
+ refkey: clsMemberRk,
286
+ children: "42"
287
+ });
288
+ }
289
+ }), _$createComponent(FunctionDeclaration, {
290
+ name: "fn",
291
+ parameters: [ifaceParam, clsParam],
292
+ get children() {
293
+ return _$createComponent(StatementList, {
294
+ get children() {
295
+ return [["console.log(", _$memo(() => memberRefkey(ifaceParamRk, ifaceMemberRk)), ")"], ["console.log(", _$memo(() => memberRefkey(clsParamRk, clsMemberRk)), ");"]];
296
+ }
297
+ });
298
+ }
299
+ })];
300
+ }
301
+ });
302
+ expect(toSourceText(decl)).toBe(d`
303
+ interface IFace {
304
+ ifaceProp: string
305
+ }
306
+
307
+ class Class {
308
+ classProp = 42
309
+ }
310
+
311
+ function fn(ifaceParam?: IFace, classParam?: Class) {
312
+ console.log(ifaceParam?.ifaceProp);
313
+ console.log(classParam?.classProp);;
314
+ }
315
+ `);
316
+ });
246
317
  });