@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,4 +1,4 @@
1
- import { getSymbolCreatorSymbol, OutputSymbolFlags, refkey } from "@alloy-js/core";
1
+ import { getSymbolCreatorSymbol, refkey } from "@alloy-js/core";
2
2
  import { TSModuleScope, TSOutputSymbol, TSPackageScope } from "./symbols/index.js";
3
3
 
4
4
  /**
@@ -43,13 +43,11 @@ import { TSModuleScope, TSOutputSymbol, TSPackageScope } from "./symbols/index.j
43
43
  // ────────────────────────────────────────────────────────────────
44
44
 
45
45
  function assignMembers(binder, ownerSym, members, keys, isStatic) {
46
- let scope;
46
+ let space;
47
47
  if (isStatic) {
48
- ownerSym.flags |= OutputSymbolFlags.StaticMemberContainer;
49
- scope = ownerSym.staticMemberScope;
48
+ space = ownerSym.staticMembers;
50
49
  } else {
51
- ownerSym.flags |= OutputSymbolFlags.InstanceMemberContainer;
52
- scope = ownerSym.instanceMemberScope;
50
+ space = ownerSym.instanceMembers;
53
51
  }
54
52
  const namespace = isStatic ? "static" : "instance";
55
53
  for (const member of members) {
@@ -61,22 +59,12 @@ function assignMembers(binder, ownerSym, members, keys, isStatic) {
61
59
  const memberKey = keys[namespace][memberObj.name];
62
60
  if (!memberKey) continue; // Skip if key doesn't exist
63
61
 
64
- let memberFlags = isStatic ? OutputSymbolFlags.StaticMember : OutputSymbolFlags.InstanceMember;
65
- if (memberObj.staticMembers?.length) {
66
- memberFlags |= OutputSymbolFlags.StaticMemberContainer;
67
- }
68
- if (memberObj.instanceMembers?.length) {
69
- memberFlags |= OutputSymbolFlags.InstanceMemberContainer;
70
- }
71
- const memberSym = new TSOutputSymbol(memberObj.name, {
72
- scope,
62
+ const memberSym = new TSOutputSymbol(memberObj.name, space, {
73
63
  binder,
74
64
  refkeys: memberKey,
75
65
  export: false,
76
- default: false,
77
- flags: memberFlags
66
+ default: false
78
67
  });
79
- scope.symbols.add(memberSym);
80
68
 
81
69
  // Recursively handle nested static and instance members
82
70
  if (memberObj.staticMembers && isStatic) {
@@ -94,15 +82,13 @@ function createSymbols(binder, props, refkeys) {
94
82
  });
95
83
  for (const [path, symbols] of Object.entries(props.descriptor)) {
96
84
  const keys = path === "." ? refkeys : refkeys[path];
97
- const moduleScope = new TSModuleScope(path, {
98
- binder,
99
- parent: pkgScope
85
+ const moduleScope = new TSModuleScope(path, pkgScope, {
86
+ binder
100
87
  });
101
88
  pkgScope.exportedSymbols.set(path, moduleScope);
102
89
  if (symbols.default) {
103
90
  const key = keys.default;
104
- const sym = new TSOutputSymbol(symbols.default, {
105
- scope: moduleScope,
91
+ const sym = new TSOutputSymbol(symbols.default, moduleScope.values, {
106
92
  refkeys: key,
107
93
  export: true,
108
94
  default: true
@@ -114,20 +100,12 @@ function createSymbols(binder, props, refkeys) {
114
100
  name: exportedName
115
101
  } : exportedName;
116
102
  const key = keys[namedRef.name];
117
- let flags = OutputSymbolFlags.None;
118
- if (namedRef.staticMembers?.length) {
119
- flags |= OutputSymbolFlags.StaticMemberContainer;
120
- }
121
- if (namedRef.instanceMembers?.length) {
122
- flags |= OutputSymbolFlags.InstanceMemberContainer;
123
- }
124
- const ownerSym = new TSOutputSymbol(namedRef.name, {
103
+ const ownerSym = new TSOutputSymbol(namedRef.name, moduleScope.values, {
125
104
  binder,
126
- scope: moduleScope,
127
105
  refkeys: key,
128
106
  export: true,
129
107
  default: false,
130
- flags
108
+ hasInstanceMembers: !!namedRef.instanceMembers?.length
131
109
  });
132
110
  moduleScope.exportedSymbols.set(key, ownerSym);
133
111
  assignMembers(binder, ownerSym, namedRef.staticMembers ?? [], keys[namedRef.name], /* isStatic */true);
@@ -1,7 +1,26 @@
1
+ import { OutputScopeOptions } from "@alloy-js/core";
2
+ import { TSLexicalScope } from "./ts-lexical-scope.js";
3
+ import { TSMemberScope } from "./ts-member-scope.js";
4
+ import { CreateTsSymbolOptions, TSOutputSymbol } from "./ts-output-symbol.js";
1
5
  export * from "./reference.js";
2
6
  export * from "./scopes.js";
7
+ export * from "./ts-lexical-scope.js";
3
8
  export * from "./ts-member-scope.js";
4
9
  export * from "./ts-module-scope.js";
5
10
  export * from "./ts-output-symbol.js";
6
11
  export * from "./ts-package-scope.js";
12
+ export declare function createTypeAndValueSymbol(name: string, options?: CreateTsSymbolOptions): TSOutputSymbol;
13
+ export declare function createTypeSymbol(name: string, options: CreateTsSymbolOptions): TSOutputSymbol;
14
+ export declare function createValueSymbol(name: string, options?: CreateTsSymbolOptions): TSOutputSymbol;
15
+ export declare function createTransientValueSymbol(): TSOutputSymbol;
16
+ export declare function createStaticMemberSymbol(name: string, options?: CreateTsSymbolOptions): TSOutputSymbol;
17
+ export declare function createInstanceMemberSymbol(name: string, options?: CreateTsSymbolOptions): TSOutputSymbol;
18
+ export declare function createPrivateStaticMemberSymbol(name: string, options?: CreateTsSymbolOptions): TSOutputSymbol;
19
+ export declare function createPrivateInstanceMemberSymbol(name: string, options?: CreateTsSymbolOptions): TSOutputSymbol;
20
+ export declare function createMemberSymbol(name: string, locationOptions: {
21
+ jsPrivate?: boolean;
22
+ static?: boolean;
23
+ }, options?: CreateTsSymbolOptions): TSOutputSymbol;
24
+ export declare function createLexicalScope(name: string, options?: OutputScopeOptions): TSLexicalScope;
25
+ export declare function createMemberScope(name: string, ownerSymbol: TSOutputSymbol, options?: OutputScopeOptions): TSMemberScope;
7
26
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/symbols/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC;AAC5B,cAAc,sBAAsB,CAAC;AACrC,cAAc,sBAAsB,CAAC;AACrC,cAAc,uBAAuB,CAAC;AACtC,cAAc,uBAAuB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/symbols/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAGpD,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,qBAAqB,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAE9E,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC;AAC5B,cAAc,uBAAuB,CAAC;AACtC,cAAc,sBAAsB,CAAC;AACrC,cAAc,sBAAsB,CAAC;AACrC,cAAc,uBAAuB,CAAC;AACtC,cAAc,uBAAuB,CAAC;AAEtC,wBAAgB,wBAAwB,CACtC,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE,qBAA0B,kBAKpC;AAED,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,qBAAqB,kBAS5E;AAED,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE,qBAA0B,kBAUpC;AAED,wBAAgB,0BAA0B,mBAIzC;AAED,wBAAgB,wBAAwB,CACtC,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE,qBAA0B,kBAIpC;AAED,wBAAgB,0BAA0B,CACxC,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE,qBAA0B,kBAIpC;AAED,wBAAgB,+BAA+B,CAC7C,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE,qBAA0B,kBAIpC;AAED,wBAAgB,iCAAiC,CAC/C,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE,qBAA0B,kBAIpC;AAED,wBAAgB,kBAAkB,CAChC,IAAI,EAAE,MAAM,EACZ,eAAe,EAAE;IAAE,SAAS,CAAC,EAAE,OAAO,CAAC;IAAC,MAAM,CAAC,EAAE,OAAO,CAAA;CAAE,EAC1D,OAAO,GAAE,qBAA0B,kBAepC;AAED,wBAAgB,kBAAkB,CAChC,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE,kBAAuB,kBAKjC;AAED,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,MAAM,EACZ,WAAW,EAAE,cAAc,EAC3B,OAAO,GAAE,kBAAuB,iBAIjC"}
@@ -1,6 +1,77 @@
1
+ import { useLexicalScope, useMemberOwner } from "../utils.js";
2
+ import { useTSScope } from "./scopes.js";
3
+ import { TSLexicalScope } from "./ts-lexical-scope.js";
4
+ import { TSMemberScope } from "./ts-member-scope.js";
5
+ import { TSOutputSymbol } from "./ts-output-symbol.js";
1
6
  export * from "./reference.js";
2
7
  export * from "./scopes.js";
8
+ export * from "./ts-lexical-scope.js";
3
9
  export * from "./ts-member-scope.js";
4
10
  export * from "./ts-module-scope.js";
5
11
  export * from "./ts-output-symbol.js";
6
- export * from "./ts-package-scope.js";
12
+ export * from "./ts-package-scope.js";
13
+ export function createTypeAndValueSymbol(name, options = {}) {
14
+ const scope = useLexicalScope();
15
+ const spaces = scope ? [scope.types, scope.values] : [];
16
+ return new TSOutputSymbol(name, spaces, options);
17
+ }
18
+ export function createTypeSymbol(name, options) {
19
+ const scope = useLexicalScope();
20
+ if (scope && !scope.types) {
21
+ throw new Error("Attempting to create a type symbol in a scope that does not have a type declaration space.");
22
+ }
23
+ const spaces = scope ? [scope.types] : [];
24
+ return new TSOutputSymbol(name, spaces, options);
25
+ }
26
+ export function createValueSymbol(name, options = {}) {
27
+ const scope = useLexicalScope();
28
+ if (scope && !scope.values) {
29
+ throw new Error("Attempting to create a value symbol in a scope that does not have a value declaration space.");
30
+ }
31
+ const spaces = scope ? [scope.values] : [];
32
+ return new TSOutputSymbol(name, spaces, options);
33
+ }
34
+ export function createTransientValueSymbol() {
35
+ return new TSOutputSymbol("transient-value", undefined, {
36
+ transient: true
37
+ });
38
+ }
39
+ export function createStaticMemberSymbol(name, options = {}) {
40
+ const owner = useMemberOwner();
41
+ return new TSOutputSymbol(name, owner.staticMembers, options);
42
+ }
43
+ export function createInstanceMemberSymbol(name, options = {}) {
44
+ const owner = useMemberOwner();
45
+ return new TSOutputSymbol(name, owner.instanceMembers, options);
46
+ }
47
+ export function createPrivateStaticMemberSymbol(name, options = {}) {
48
+ const owner = useMemberOwner();
49
+ return new TSOutputSymbol(name, owner.privateStaticMembers, options);
50
+ }
51
+ export function createPrivateInstanceMemberSymbol(name, options = {}) {
52
+ const owner = useMemberOwner();
53
+ return new TSOutputSymbol(name, owner.privateInstanceMembers, options);
54
+ }
55
+ export function createMemberSymbol(name, locationOptions, options = {}) {
56
+ if (locationOptions.jsPrivate) {
57
+ if (locationOptions.static) {
58
+ return createPrivateStaticMemberSymbol(name, options);
59
+ } else {
60
+ return createPrivateInstanceMemberSymbol(name, options);
61
+ }
62
+ } else {
63
+ if (locationOptions.static) {
64
+ return createStaticMemberSymbol(name, options);
65
+ } else {
66
+ return createInstanceMemberSymbol(name, options);
67
+ }
68
+ }
69
+ }
70
+ export function createLexicalScope(name, options = {}) {
71
+ const parent = useTSScope();
72
+ return new TSLexicalScope(name, parent, options);
73
+ }
74
+ export function createMemberScope(name, ownerSymbol, options = {}) {
75
+ const parent = useTSScope();
76
+ return new TSMemberScope(name, parent, ownerSymbol, options);
77
+ }
@@ -1,7 +1,7 @@
1
- import { Refkey } from "@alloy-js/core";
1
+ import { Children, Refkey } from "@alloy-js/core";
2
2
  import { TSOutputSymbol } from "./ts-output-symbol.js";
3
3
  export interface RefOptions {
4
4
  type?: boolean;
5
5
  }
6
- export declare function ref(refkey: Refkey, options?: RefOptions): () => [string, TSOutputSymbol | undefined];
6
+ export declare function ref(refkey: Refkey, options?: RefOptions): () => [Children, TSOutputSymbol | undefined];
7
7
  //# sourceMappingURL=reference.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"reference.d.ts","sourceRoot":"","sources":["../../../src/symbols/reference.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,MAAM,EAKP,MAAM,gBAAgB,CAAC;AAWxB,OAAO,EAAE,cAAc,EAAiB,MAAM,uBAAuB,CAAC;AAGtE,MAAM,WAAW,UAAU;IACzB,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB;AACD,wBAAgB,GAAG,CACjB,MAAM,EAAE,MAAM,EACd,OAAO,CAAC,EAAE,UAAU,GACnB,MAAM,CAAC,MAAM,EAAE,cAAc,GAAG,SAAS,CAAC,CA2G5C"}
1
+ {"version":3,"file":"reference.d.ts","sourceRoot":"","sources":["../../../src/symbols/reference.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAIR,MAAM,EAIP,MAAM,gBAAgB,CAAC;AAOxB,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAGvD,MAAM,WAAW,UAAU;IACzB,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB;AACD,wBAAgB,GAAG,CACjB,MAAM,EAAE,MAAM,EACd,OAAO,CAAC,EAAE,UAAU,GACnB,MAAM,CAAC,QAAQ,EAAE,cAAc,GAAG,SAAS,CAAC,CAsF9C"}
@@ -1,43 +1,34 @@
1
- import { memo, OutputSymbolFlags, resolve, untrack, useContext, useMemberScope } from "@alloy-js/core";
1
+ import { createComponent as _$createComponent } from "@alloy-js/core/jsx-runtime";
2
+ import { memo, resolve, untrack, useContext } from "@alloy-js/core";
3
+ import { MemberExpression } from "../components/MemberExpression.js";
2
4
  import { usePackage } from "../components/PackageDirectory.js";
3
5
  import { SourceFileContext } from "../components/SourceFile.js";
4
- import { usePrivateScope } from "../context/private-scope.js";
5
- import { isValidJSIdentifier } from "../utils.js";
6
- import { TSSymbolFlags } from "./ts-output-symbol.js";
6
+ import { TSLexicalScope } from "./ts-lexical-scope.js";
7
+ import { TSModuleScope } from "./ts-module-scope.js";
8
+ import { TSPackageScope } from "./ts-package-scope.js";
7
9
  export function ref(refkey, options) {
8
10
  const sourceFile = useContext(SourceFileContext);
9
- const resolveResult = resolve(refkey);
10
- const currentScope = useMemberScope();
11
- const currentPrivateScope = usePrivateScope();
11
+ const resolveResult = resolve(refkey, {
12
+ memberResolver
13
+ });
12
14
  return memo(() => {
13
15
  if (resolveResult.value === undefined) {
14
16
  return ["<Unresolved Symbol>", undefined];
15
17
  }
16
18
  const {
17
- targetDeclaration,
19
+ symbol,
18
20
  pathDown,
19
- memberPath
21
+ memberPath,
22
+ lexicalDeclaration,
23
+ commonScope
20
24
  } = resolveResult.value;
21
- // if we resolved a instance member, check if we should be able to access
22
- // it.
23
- if (targetDeclaration.flags & OutputSymbolFlags.InstanceMember) {
24
- if (targetDeclaration.tsFlags & TSSymbolFlags.PrivateMember) {
25
- if (currentPrivateScope?.instanceMembers !== targetDeclaration.scope) {
26
- throw new Error("Cannot resolve private member symbols from a different scope");
27
- }
28
- } else {
29
- if (currentScope?.instanceMembers !== targetDeclaration.scope) {
30
- throw new Error("Cannot resolve member symbols from a different member scope");
31
- }
32
- }
33
- }
34
- validateSymbolReachable(pathDown, memberPath, currentPrivateScope);
25
+ validateSymbolReachable(pathDown);
35
26
 
36
27
  // Where the target declaration is relative to the referencing scope.
37
28
  // * package: target symbol is in a different package
38
29
  // * module: target symbol is in a different module
39
30
  // * local: target symbol is within the current module
40
- const targetLocation = pathDown[0]?.kind ?? "local";
31
+ const targetLocation = pathDown[0] instanceof TSPackageScope ? "package" : pathDown[0] instanceof TSModuleScope ? "module" : "local";
41
32
  let localSymbol;
42
33
  if (targetLocation === "package") {
43
34
  // need package import
@@ -46,14 +37,12 @@ export function ref(refkey, options) {
46
37
  if (pkg && !sourcePackage.builtin) {
47
38
  pkg.scope.addDependency(sourcePackage);
48
39
  }
49
- const symbolPath = [...pathDown.slice(2).map(s => s.owner), targetDeclaration];
50
- const importSymbol = symbolPath[0];
51
40
 
52
41
  // find public dependency
53
42
  for (const module of sourcePackage.exportedSymbols.values()) {
54
- for (const refkey of importSymbol.refkeys) {
43
+ for (const refkey of lexicalDeclaration.refkeys) {
55
44
  if (module.exportedSymbols.has(refkey)) {
56
- localSymbol = untrack(() => sourceFile.scope.addImport(importSymbol, module, {
45
+ localSymbol = untrack(() => sourceFile.scope.addImport(lexicalDeclaration, module, {
57
46
  type: options?.type
58
47
  }));
59
48
  break;
@@ -61,62 +50,71 @@ export function ref(refkey, options) {
61
50
  }
62
51
  }
63
52
  if (!localSymbol) {
64
- throw new Error("The symbol " + targetDeclaration.name + " is not exported from package");
53
+ throw new Error("The symbol " + symbol.name + " is not exported from package");
65
54
  }
66
55
  } else if (targetLocation === "module") {
67
- const symbolPath = [...pathDown.slice(1).map(s => s.owner), targetDeclaration];
68
- const importSymbol = symbolPath[0];
69
- localSymbol = untrack(() => sourceFile.scope.addImport(importSymbol, pathDown[0], {
56
+ localSymbol = untrack(() => sourceFile.scope.addImport(lexicalDeclaration, pathDown[0], {
70
57
  type: options?.type
71
58
  }));
72
59
  }
73
- if (memberPath && memberPath.length > 0) {
74
- if (localSymbol) {
75
- memberPath[0] = localSymbol;
60
+ const parts = [];
61
+ if (commonScope && commonScope.isMemberScope) {
62
+ // we are referencing a member of a type we are inside
63
+ if (lexicalDeclaration.isInstanceMemberSymbol) {
64
+ parts.push(_$createComponent(MemberExpression.Part, {
65
+ id: "this"
66
+ }));
67
+ } else {
68
+ parts.push(_$createComponent(MemberExpression.Part, {
69
+ get symbol() {
70
+ return commonScope.ownerSymbol;
71
+ }
72
+ }));
76
73
  }
77
- return [buildMemberExpression(memberPath), memberPath.at(-1)];
74
+ parts.push(_$createComponent(MemberExpression.Part, {
75
+ symbol: lexicalDeclaration
76
+ }));
78
77
  } else {
79
- return [buildMemberExpression([localSymbol ?? targetDeclaration]), localSymbol ?? targetDeclaration];
78
+ parts.push(_$createComponent(MemberExpression.Part, {
79
+ symbol: localSymbol ?? lexicalDeclaration
80
+ }));
80
81
  }
81
- });
82
- }
83
- function buildMemberExpression(path) {
84
- let memberExpr = "";
85
- const base = path[0];
86
- if (base.flags & OutputSymbolFlags.InstanceMember) {
87
- memberExpr += "this";
88
- } else {
89
- memberExpr += base.name;
90
- path = path.slice(1);
91
- }
92
- let prevNullish = base.tsFlags & TSSymbolFlags.Nullish;
93
- for (const sym of path) {
94
- const optional = prevNullish ? "?" : "";
95
- if (sym.tsFlags & TSSymbolFlags.PrivateMember) {
96
- memberExpr += `${optional}.#${sym.name}`;
97
- } else if (isValidJSIdentifier(sym.name) && !(sym.tsFlags & TSSymbolFlags.TypeSymbol)) {
98
- memberExpr += `${optional}.${sym.name}`;
99
- } else {
100
- const joiner = sym.tsFlags & TSSymbolFlags.Nullish ? "?." : "";
101
- memberExpr += `${joiner}[${JSON.stringify(sym.name)}]`;
82
+ for (const part of memberPath) {
83
+ parts.push(_$createComponent(MemberExpression.Part, {
84
+ symbol: part
85
+ }));
102
86
  }
103
- prevNullish = sym.tsFlags & TSSymbolFlags.Nullish;
104
- }
105
- return memberExpr;
87
+ return [_$createComponent(MemberExpression, {
88
+ children: parts
89
+ }), localSymbol ?? symbol];
90
+ });
106
91
  }
107
- function validateSymbolReachable(path, memberPath, currentPrivateScope) {
92
+ function validateSymbolReachable(path) {
108
93
  for (const scope of path) {
109
- if (scope.kind === "function") {
94
+ if (!(scope instanceof TSModuleScope) && scope instanceof TSLexicalScope) {
110
95
  throw new Error("Cannot reference a symbol inside a function from outside a function");
111
96
  }
112
97
  }
113
- if (memberPath) {
114
- for (const sym of memberPath) {
115
- // make sure we're not trying to access a static private from outside
116
- // the static member scope.
117
- if (sym.flags & OutputSymbolFlags.StaticMember && sym.tsFlags & TSSymbolFlags.PrivateMember && currentPrivateScope?.staticMembers !== sym.scope) {
118
- throw new Error("Cannot resolve private static member symbols from a different scope");
98
+ }
99
+ const memberResolver = function (owner, member, context) {
100
+ if (context.isMemberAccess) {
101
+ if (!member.isMemberSymbol) {
102
+ throw new Error(`${member.name} is not a member symbol.`);
103
+ }
104
+ const memberOwner = owner.hasTypeSymbol ? owner.type : owner.dealias();
105
+ if (member.ownerSymbol !== memberOwner) {
106
+ throw new Error(`${member.name} is not a member of ${owner.name}.`);
107
+ }
108
+ } else {
109
+ if (member.isInstanceMemberSymbol) {
110
+ if (!context.referencePath.some(s => s.isMemberScope && s.ownerSymbol === owner)) {
111
+ throw new Error(`Cannot reference instance member '${member.name}' without an instance of '${owner.name}' in scope`);
112
+ }
113
+ }
114
+ if (member.isPrivateMemberSymbol) {
115
+ if (!context.referencePath.some(s => s.isMemberScope && s.ownerSymbol === owner)) {
116
+ throw new Error(`Cannot reference private member '${member.name}' outside an instance of '${owner.name} in scope'`);
119
117
  }
120
118
  }
121
119
  }
122
- }
120
+ };
@@ -1,13 +1,10 @@
1
- import { OutputScope } from "@alloy-js/core";
1
+ import { TSLexicalScope } from "./ts-lexical-scope.js";
2
2
  import { TSMemberScope } from "./ts-member-scope.js";
3
3
  import { TSModuleScope } from "./ts-module-scope.js";
4
4
  import { TSPackageScope } from "./ts-package-scope.js";
5
- export type TSOutputScope = TSGlobalScope | TSPackageScope | TSModuleScope | TSFunctionScope | TSMemberScope;
6
- export interface TSGlobalScope extends OutputScope {
7
- kind: "global";
8
- }
9
- export interface TSFunctionScope extends OutputScope {
10
- kind: "function";
11
- }
5
+ export type TSOutputScope = TSPackageScope | TSModuleScope | TSLexicalScope;
12
6
  export declare function useTSScope(): TSOutputScope;
7
+ export declare function useTSLexicalScope(): TSLexicalScope;
8
+ export declare function useTSLexicalScopeIfPresent(): TSLexicalScope | undefined;
9
+ export declare function useTSMemberScope(): TSMemberScope;
13
10
  //# sourceMappingURL=scopes.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"scopes.d.ts","sourceRoot":"","sources":["../../../src/symbols/scopes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAY,MAAM,gBAAgB,CAAC;AACvD,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAEvD,MAAM,MAAM,aAAa,GACrB,aAAa,GACb,cAAc,GACd,aAAa,GACb,eAAe,GACf,aAAa,CAAC;AAElB,MAAM,WAAW,aAAc,SAAQ,WAAW;IAChD,IAAI,EAAE,QAAQ,CAAC;CAChB;AAED,MAAM,WAAW,eAAgB,SAAQ,WAAW;IAClD,IAAI,EAAE,UAAU,CAAC;CAClB;AAED,wBAAgB,UAAU,IACH,aAAa,CACnC"}
1
+ {"version":3,"file":"scopes.d.ts","sourceRoot":"","sources":["../../../src/symbols/scopes.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAEvD,MAAM,MAAM,aAAa,GAAG,cAAc,GAAG,aAAa,GAAG,cAAc,CAAC;AAE5E,wBAAgB,UAAU,IACH,aAAa,CACnC;AAED,wBAAgB,iBAAiB,IAAI,cAAc,CAUlD;AAED,wBAAgB,0BAA0B,+BAWzC;AAED,wBAAgB,gBAAgB,IAAI,aAAa,CAUhD"}
@@ -1,4 +1,30 @@
1
1
  import { useScope } from "@alloy-js/core";
2
+ import { TSLexicalScope } from "./ts-lexical-scope.js";
3
+ import { TSMemberScope } from "./ts-member-scope.js";
2
4
  export function useTSScope() {
3
5
  return useScope();
6
+ }
7
+ export function useTSLexicalScope() {
8
+ const scope = useTSScope();
9
+ if (!(scope instanceof TSLexicalScope)) {
10
+ throw new Error("Expected a TSLexicalScope, but got " + scope.constructor.name);
11
+ }
12
+ return scope;
13
+ }
14
+ export function useTSLexicalScopeIfPresent() {
15
+ const scope = useTSScope();
16
+ if (!scope) {
17
+ return undefined;
18
+ }
19
+ if (!(scope instanceof TSLexicalScope)) {
20
+ throw new Error("Expected a TSLexicalScope, but got " + scope.constructor.name);
21
+ }
22
+ return scope;
23
+ }
24
+ export function useTSMemberScope() {
25
+ const scope = useTSScope();
26
+ if (!(scope instanceof TSMemberScope)) {
27
+ throw new Error("Expected a TSMemberScope, but got " + scope.constructor.name);
28
+ }
29
+ return scope;
4
30
  }
@@ -0,0 +1,12 @@
1
+ import { OutputScope } from "@alloy-js/core";
2
+ /**
3
+ * A lexical scope for TypeScript, which contains declaration spaces for types
4
+ * and values. This scope is used to hold symbols for things like variable or
5
+ * interface declarations.
6
+ */
7
+ export declare class TSLexicalScope extends OutputScope {
8
+ static readonly declarationSpaces: string[];
9
+ get values(): import("@alloy-js/core").OutputSpace;
10
+ get types(): import("@alloy-js/core").OutputSpace;
11
+ }
12
+ //# sourceMappingURL=ts-lexical-scope.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ts-lexical-scope.d.ts","sourceRoot":"","sources":["../../../src/symbols/ts-lexical-scope.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C;;;;GAIG;AACH,qBAAa,cAAe,SAAQ,WAAW;IAC7C,gBAAuB,iBAAiB,WAAuB;IAE/D,IAAI,MAAM,yCAET;IAED,IAAI,KAAK,yCAER;CACF"}
@@ -0,0 +1,16 @@
1
+ import { OutputScope } from "@alloy-js/core";
2
+
3
+ /**
4
+ * A lexical scope for TypeScript, which contains declaration spaces for types
5
+ * and values. This scope is used to hold symbols for things like variable or
6
+ * interface declarations.
7
+ */
8
+ export class TSLexicalScope extends OutputScope {
9
+ static declarationSpaces = ["values", "types"];
10
+ get values() {
11
+ return this.spaceFor("values");
12
+ }
13
+ get types() {
14
+ return this.spaceFor("types");
15
+ }
16
+ }
@@ -1,7 +1,15 @@
1
- import { OutputScope } from "@alloy-js/core";
1
+ import { OutputScopeOptions } from "@alloy-js/core";
2
+ import { TSOutputScope } from "./scopes.js";
3
+ import { TSLexicalScope } from "./ts-lexical-scope.js";
2
4
  import { TSOutputSymbol } from "./ts-output-symbol.js";
3
- export declare class TSMemberScope extends OutputScope {
4
- get kind(): "member";
5
- get owner(): TSOutputSymbol;
5
+ /**
6
+ * A member scope for TypeScript. Member declarations create symbols in this
7
+ * scope, which will be added to the owner symbol's members.
8
+ */
9
+ export declare class TSMemberScope extends TSLexicalScope {
10
+ static readonly declarationSpaces: never[];
11
+ constructor(name: string, parentScope: TSOutputScope | undefined, ownerSymbol: TSOutputSymbol, options?: OutputScopeOptions);
12
+ get ownerSymbol(): TSOutputSymbol;
13
+ get isMemberScope(): boolean;
6
14
  }
7
15
  //# sourceMappingURL=ts-member-scope.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ts-member-scope.d.ts","sourceRoot":"","sources":["../../../src/symbols/ts-member-scope.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAEvD,qBAAa,aAAc,SAAQ,WAAW;IAC5C,IAAI,IAAI,IACC,QAAQ,CAChB;IAED,IAAI,KAAK,IACe,cAAc,CACrC;CACF"}
1
+ {"version":3,"file":"ts-member-scope.d.ts","sourceRoot":"","sources":["../../../src/symbols/ts-member-scope.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AACpD,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAEvD;;;GAGG;AACH,qBAAa,aAAc,SAAQ,cAAc;IAC/C,gBAAuB,iBAAiB,UAAM;gBAG5C,IAAI,EAAE,MAAM,EACZ,WAAW,EAAE,aAAa,GAAG,SAAS,EACtC,WAAW,EAAE,cAAc,EAC3B,OAAO,GAAE,kBAAuB;IAKlC,IAAI,WAAW,IACe,cAAc,CAC3C;IAED,IAAI,aAAa,YAEhB;CACF"}
@@ -1,9 +1,18 @@
1
- import { OutputScope } from "@alloy-js/core";
2
- export class TSMemberScope extends OutputScope {
3
- get kind() {
4
- return "member";
1
+ import { TSLexicalScope } from "./ts-lexical-scope.js";
2
+ /**
3
+ * A member scope for TypeScript. Member declarations create symbols in this
4
+ * scope, which will be added to the owner symbol's members.
5
+ */
6
+ export class TSMemberScope extends TSLexicalScope {
7
+ static declarationSpaces = [];
8
+ constructor(name, parentScope, ownerSymbol, options = {}) {
9
+ options.ownerSymbol = ownerSymbol;
10
+ super(name, parentScope, options);
5
11
  }
6
- get owner() {
7
- return super.owner;
12
+ get ownerSymbol() {
13
+ return super.ownerSymbol;
14
+ }
15
+ get isMemberScope() {
16
+ return true;
8
17
  }
9
18
  }
@@ -1,4 +1,5 @@
1
- import { OutputScope, Refkey } from "@alloy-js/core";
1
+ import { Refkey } from "@alloy-js/core";
2
+ import { TSLexicalScope } from "./ts-lexical-scope.js";
2
3
  import { TSOutputSymbol } from "./ts-output-symbol.js";
3
4
  export interface ImportedSymbol {
4
5
  local: TSOutputSymbol;
@@ -8,12 +9,16 @@ export type ImportRecords = Map<TSModuleScope, Set<ImportedSymbol>>;
8
9
  export interface AddImportOptions {
9
10
  type?: boolean;
10
11
  }
11
- export declare class TSModuleScope extends OutputScope {
12
+ /**
13
+ * A lexical scope for TypeScript which represents the top-level scope of a
14
+ * module. Manages the module's imported and exported symbols.
15
+ */
16
+ export declare class TSModuleScope extends TSLexicalScope {
12
17
  #private;
13
- get kind(): "module";
14
18
  get exportedSymbols(): Map<Refkey, TSOutputSymbol>;
15
19
  get importedSymbols(): Map<TSOutputSymbol, TSOutputSymbol>;
16
20
  get importedModules(): ImportRecords;
17
21
  addImport(targetSymbol: TSOutputSymbol, targetModule: TSModuleScope, options?: AddImportOptions): TSOutputSymbol;
22
+ getAllSymbols(): Set<TSOutputSymbol>;
18
23
  }
19
24
  //# sourceMappingURL=ts-module-scope.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ts-module-scope.d.ts","sourceRoot":"","sources":["../../../src/symbols/ts-module-scope.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAY,MAAM,EAAmB,MAAM,gBAAgB,CAAC;AAChF,OAAO,EAAE,cAAc,EAAiB,MAAM,uBAAuB,CAAC;AAEtE,MAAM,WAAW,cAAc;IAC7B,KAAK,EAAE,cAAc,CAAC;IACtB,MAAM,EAAE,cAAc,CAAC;CACxB;AACD,MAAM,MAAM,aAAa,GAAG,GAAG,CAAC,aAAa,EAAE,GAAG,CAAC,cAAc,CAAC,CAAC,CAAC;AAEpE,MAAM,WAAW,gBAAgB;IAC/B,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB;AAED,qBAAa,aAAc,SAAQ,WAAW;;IAC5C,IAAI,IAAI,IACC,QAAQ,CAChB;IAGD,IAAI,eAAe,gCAElB;IAKD,IAAI,eAAe,wCAElB;IAGD,IAAI,eAAe,kBAElB;IAED,SAAS,CACP,YAAY,EAAE,cAAc,EAC5B,YAAY,EAAE,aAAa,EAC3B,OAAO,CAAC,EAAE,gBAAgB;CAuC7B"}
1
+ {"version":3,"file":"ts-module-scope.d.ts","sourceRoot":"","sources":["../../../src/symbols/ts-module-scope.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,MAAM,EAAmB,MAAM,gBAAgB,CAAC;AACnE,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,cAAc,EAAiB,MAAM,uBAAuB,CAAC;AAEtE,MAAM,WAAW,cAAc;IAC7B,KAAK,EAAE,cAAc,CAAC;IACtB,MAAM,EAAE,cAAc,CAAC;CACxB;AACD,MAAM,MAAM,aAAa,GAAG,GAAG,CAAC,aAAa,EAAE,GAAG,CAAC,cAAc,CAAC,CAAC,CAAC;AAEpE,MAAM,WAAW,gBAAgB;IAC/B,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB;AAED;;;GAGG;AACH,qBAAa,aAAc,SAAQ,cAAc;;IAE/C,IAAI,eAAe,gCAElB;IAMD,IAAI,eAAe,wCAElB;IAGD,IAAI,eAAe,kBAElB;IAED,SAAS,CACP,YAAY,EAAE,cAAc,EAC5B,YAAY,EAAE,aAAa,EAC3B,OAAO,CAAC,EAAE,gBAAgB;IAqC5B,aAAa;CAUd"}