@openrewrite/rewrite 8.62.0 → 8.62.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 (90) hide show
  1. package/dist/java/rpc.d.ts +3 -3
  2. package/dist/java/rpc.d.ts.map +1 -1
  3. package/dist/java/rpc.js +6 -6
  4. package/dist/java/rpc.js.map +1 -1
  5. package/dist/java/tree.d.ts +31 -33
  6. package/dist/java/tree.d.ts.map +1 -1
  7. package/dist/java/tree.js +125 -7
  8. package/dist/java/tree.js.map +1 -1
  9. package/dist/java/type.d.ts +70 -57
  10. package/dist/java/type.d.ts.map +1 -1
  11. package/dist/java/type.js +454 -25
  12. package/dist/java/type.js.map +1 -1
  13. package/dist/java/visitor.d.ts +4 -4
  14. package/dist/java/visitor.d.ts.map +1 -1
  15. package/dist/java/visitor.js +34 -28
  16. package/dist/java/visitor.js.map +1 -1
  17. package/dist/javascript/assertions.d.ts +3 -0
  18. package/dist/javascript/assertions.d.ts.map +1 -1
  19. package/dist/javascript/assertions.js +78 -1
  20. package/dist/javascript/assertions.js.map +1 -1
  21. package/dist/javascript/format.js +4 -4
  22. package/dist/javascript/format.js.map +1 -1
  23. package/dist/javascript/parser.d.ts +1 -1
  24. package/dist/javascript/parser.d.ts.map +1 -1
  25. package/dist/javascript/parser.js +38 -11
  26. package/dist/javascript/parser.js.map +1 -1
  27. package/dist/javascript/rpc.js +1 -4
  28. package/dist/javascript/rpc.js.map +1 -1
  29. package/dist/javascript/tree.d.ts +33 -35
  30. package/dist/javascript/tree.d.ts.map +1 -1
  31. package/dist/javascript/tree.js +70 -17
  32. package/dist/javascript/tree.js.map +1 -1
  33. package/dist/javascript/type-mapping.d.ts +44 -8
  34. package/dist/javascript/type-mapping.d.ts.map +1 -1
  35. package/dist/javascript/type-mapping.js +506 -101
  36. package/dist/javascript/type-mapping.js.map +1 -1
  37. package/dist/javascript/visitor.d.ts +2 -2
  38. package/dist/javascript/visitor.d.ts.map +1 -1
  39. package/dist/javascript/visitor.js.map +1 -1
  40. package/dist/json/tree.d.ts +0 -2
  41. package/dist/json/tree.d.ts.map +1 -1
  42. package/dist/json/tree.js +12 -2
  43. package/dist/json/tree.js.map +1 -1
  44. package/dist/reference.js +1 -1
  45. package/dist/reference.js.map +1 -1
  46. package/dist/rpc/queue.d.ts +0 -3
  47. package/dist/rpc/queue.d.ts.map +1 -1
  48. package/dist/rpc/queue.js +6 -6
  49. package/dist/rpc/queue.js.map +1 -1
  50. package/dist/rpc/request/parse.d.ts.map +1 -1
  51. package/dist/rpc/request/parse.js.map +1 -1
  52. package/dist/rpc/rewrite-rpc.d.ts +1 -0
  53. package/dist/rpc/rewrite-rpc.d.ts.map +1 -1
  54. package/dist/rpc/rewrite-rpc.js +1 -1
  55. package/dist/rpc/rewrite-rpc.js.map +1 -1
  56. package/dist/rpc/server.js +1 -1
  57. package/dist/test/rewrite-test.d.ts +1 -1
  58. package/dist/test/rewrite-test.d.ts.map +1 -1
  59. package/dist/test/rewrite-test.js +18 -2
  60. package/dist/test/rewrite-test.js.map +1 -1
  61. package/dist/text/tree.d.ts +0 -2
  62. package/dist/text/tree.d.ts.map +1 -1
  63. package/dist/text/tree.js +4 -17
  64. package/dist/text/tree.js.map +1 -1
  65. package/dist/tree.d.ts +1 -0
  66. package/dist/tree.d.ts.map +1 -1
  67. package/dist/tree.js +14 -0
  68. package/dist/tree.js.map +1 -1
  69. package/dist/version.txt +1 -1
  70. package/package.json +3 -3
  71. package/src/java/rpc.ts +18 -15
  72. package/src/java/tree.ts +68 -38
  73. package/src/java/type.ts +475 -74
  74. package/src/java/visitor.ts +45 -39
  75. package/src/javascript/assertions.ts +52 -1
  76. package/src/javascript/format.ts +4 -4
  77. package/src/javascript/parser.ts +51 -18
  78. package/src/javascript/rpc.ts +8 -10
  79. package/src/javascript/tree.ts +34 -35
  80. package/src/javascript/type-mapping.ts +519 -47
  81. package/src/javascript/visitor.ts +5 -5
  82. package/src/json/tree.ts +1 -2
  83. package/src/reference.ts +1 -1
  84. package/src/rpc/queue.ts +8 -12
  85. package/src/rpc/request/parse.ts +1 -1
  86. package/src/rpc/rewrite-rpc.ts +3 -2
  87. package/src/rpc/server.ts +1 -1
  88. package/src/test/rewrite-test.ts +19 -3
  89. package/src/text/tree.ts +0 -1
  90. package/src/tree.ts +15 -0
@@ -1,46 +1,8 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
36
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
37
- return new (P || (P = Promise))(function (resolve, reject) {
38
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
39
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
40
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
41
- step((generator = generator.apply(thisArg, _arguments || [])).next());
42
- });
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
43
4
  };
5
+ var _a;
44
6
  Object.defineProperty(exports, "__esModule", { value: true });
45
7
  exports.JavaScriptTypeMapping = void 0;
46
8
  /*
@@ -58,125 +20,568 @@ exports.JavaScriptTypeMapping = void 0;
58
20
  * See the License for the specific language governing permissions and
59
21
  * limitations under the License.
60
22
  */
61
- const ts = __importStar(require("typescript"));
23
+ const typescript_1 = __importDefault(require("typescript"));
62
24
  const java_1 = require("../java");
63
- const rpc_1 = require("../rpc");
25
+ const immer_1 = require("immer");
26
+ // Helper class to create Type objects that immer won't traverse
27
+ class NonDraftableType {
28
+ constructor() {
29
+ this[_a] = false;
30
+ }
31
+ }
32
+ _a = immer_1.immerable;
33
+ const builtInTypes = new Set([
34
+ 'Array', 'Object', 'Function', 'String', 'Number', 'Boolean',
35
+ 'Date', 'RegExp', 'Error', 'Promise', 'Map', 'Set', 'WeakMap',
36
+ 'WeakSet', 'Symbol', 'BigInt', 'HTMLElement', 'Document',
37
+ 'Window', 'Console', 'JSON', 'Math', 'Reflect', 'Proxy'
38
+ ]);
64
39
  class JavaScriptTypeMapping {
65
- constructor(checker) {
40
+ constructor(checker, projectRoot = process.cwd()) {
66
41
  this.checker = checker;
42
+ this.projectRoot = projectRoot;
67
43
  this.typeCache = new Map();
68
- this.regExpSymbol = checker.resolveName("RegExp", undefined, ts.SymbolFlags.Type, false);
44
+ this.regExpSymbol = checker.resolveName("RegExp", undefined, typescript_1.default.SymbolFlags.Type, false);
69
45
  }
70
46
  type(node) {
71
47
  let type;
72
- if (ts.isExpression(node)) {
48
+ if (typescript_1.default.isExpression(node)) {
73
49
  type = this.checker.getTypeAtLocation(node);
74
50
  }
75
- else if (ts.isTypeNode(node)) {
51
+ else if (typescript_1.default.isTypeNode(node)) {
76
52
  type = this.checker.getTypeFromTypeNode(node);
77
53
  }
78
54
  return type && this.getType(type);
79
55
  }
80
56
  getType(type) {
57
+ var _b;
81
58
  const signature = this.getSignature(type);
82
59
  const existing = this.typeCache.get(signature);
83
60
  if (existing) {
84
61
  return existing;
85
62
  }
86
- const result = this.createType(type, signature);
63
+ // Check if this is an array type BEFORE checking for classes
64
+ // TypeScript represents Array<T> as a reference to the Array interface
65
+ if (this.checker.isArrayType(type)) {
66
+ const arrayType = this.createArrayType(type);
67
+ this.typeCache.set(signature, arrayType);
68
+ return arrayType;
69
+ }
70
+ // Check for class/interface/enum types (but not arrays)
71
+ const symbol = (_b = type.getSymbol) === null || _b === void 0 ? void 0 : _b.call(type);
72
+ if (symbol) {
73
+ if (symbol.flags & (typescript_1.default.SymbolFlags.Class | typescript_1.default.SymbolFlags.Interface | typescript_1.default.SymbolFlags.Enum | typescript_1.default.SymbolFlags.TypeAlias)) {
74
+ // Create and cache shell first to handle circular references
75
+ const classType = this.createEmptyClassType(type);
76
+ this.typeCache.set(signature, classType);
77
+ this.populateClassType(classType, type);
78
+ return classType;
79
+ }
80
+ }
81
+ // For anonymous object types that could have circular references
82
+ if (type.flags & typescript_1.default.TypeFlags.Object) {
83
+ const objectFlags = type.objectFlags;
84
+ if (objectFlags & typescript_1.default.ObjectFlags.Anonymous) {
85
+ // Anonymous object type - create and cache shell, then populate
86
+ const classType = this.createEmptyClassType(type);
87
+ this.typeCache.set(signature, classType);
88
+ this.populateClassType(classType, type);
89
+ return classType;
90
+ }
91
+ }
92
+ // For non-object types, we can create them directly without recursion concerns
93
+ const result = this.createPrimitiveOrUnknownType(type);
87
94
  this.typeCache.set(signature, result);
88
95
  return result;
89
96
  }
90
97
  getSignature(type) {
91
- // FIXME for classes we need to include the containing module / package in the signature and probably include in the qualified name
92
- if ("id" in type) { // a private field returned by the type checker
98
+ var _b, _c;
99
+ // Try to use TypeScript's internal id if available
100
+ if ("id" in type && type.id !== undefined) {
93
101
  return type.id;
94
102
  }
95
- else {
96
- throw new Error("no id property in type: " + JSON.stringify(type));
103
+ // Fallback: Generate a string signature based on type characteristics
104
+ const typeString = this.checker.typeToString(type);
105
+ const symbol = (_b = type.getSymbol) === null || _b === void 0 ? void 0 : _b.call(type);
106
+ if (symbol) {
107
+ const declaration = symbol.valueDeclaration || ((_c = symbol.declarations) === null || _c === void 0 ? void 0 : _c[0]);
108
+ if (declaration) {
109
+ const sourceFile = declaration.getSourceFile();
110
+ const fileName = sourceFile.fileName;
111
+ const pos = declaration.pos;
112
+ // Create unique signature from file + position + type string
113
+ // This ensures types from different modules are distinguished
114
+ return `${fileName}:${pos}:${typeString}`;
115
+ }
97
116
  }
117
+ // Last resort: use type string with a prefix to distinguish from numeric IDs
118
+ // This might happen for synthetic types or types without declarations
119
+ return `synthetic:${typeString}`;
98
120
  }
99
121
  primitiveType(node) {
100
122
  const type = this.type(node);
101
- return java_1.JavaType.isPrimitive(type) ? type : java_1.JavaType.Primitive.None;
123
+ if (java_1.Type.isClass(type) && type.fullyQualifiedName === 'lib.RegExp') {
124
+ return java_1.Type.Primitive.String;
125
+ }
126
+ return java_1.Type.isPrimitive(type) ? type : java_1.Type.Primitive.None;
102
127
  }
103
128
  variableType(node) {
104
- if (ts.isVariableDeclaration(node)) {
129
+ if (typescript_1.default.isVariableDeclaration(node)) {
105
130
  const symbol = this.checker.getSymbolAtLocation(node.name);
106
131
  if (symbol) {
107
- const type = this.checker.getTypeOfSymbolAtLocation(symbol, node);
132
+ // TODO: Implement in Phase 6
133
+ // const type = this.checker.getTypeOfSymbolAtLocation(symbol, node);
134
+ // return JavaType.Variable with proper mapping
108
135
  }
109
136
  }
110
137
  return undefined;
111
138
  }
112
139
  methodType(node) {
113
- return undefined;
140
+ let signature;
141
+ let methodName;
142
+ let declaringType;
143
+ let declaredFormalTypeNames = [];
144
+ // Handle different kinds of nodes that represent methods or method invocations
145
+ if (typescript_1.default.isCallExpression(node)) {
146
+ // For method invocations (e.g., _.map(...))
147
+ signature = this.checker.getResolvedSignature(node);
148
+ if (!signature) {
149
+ return undefined;
150
+ }
151
+ const symbol = this.checker.getSymbolAtLocation(node.expression);
152
+ if (!symbol) {
153
+ return undefined;
154
+ }
155
+ // Get the method name
156
+ if (typescript_1.default.isPropertyAccessExpression(node.expression)) {
157
+ methodName = node.expression.name.getText();
158
+ const exprType = this.checker.getTypeAtLocation(node.expression.expression);
159
+ declaringType = this.getType(exprType);
160
+ }
161
+ else if (typescript_1.default.isIdentifier(node.expression)) {
162
+ methodName = node.expression.getText();
163
+ // For standalone functions, use the symbol's parent or module
164
+ const parent = symbol.parent;
165
+ if (parent) {
166
+ const parentType = this.checker.getDeclaredTypeOfSymbol(parent);
167
+ declaringType = this.getType(parentType);
168
+ }
169
+ else {
170
+ declaringType = java_1.Type.unknownType;
171
+ }
172
+ }
173
+ else {
174
+ methodName = symbol.getName();
175
+ declaringType = java_1.Type.unknownType;
176
+ }
177
+ // Get type parameters from signature
178
+ const typeParameters = signature.getTypeParameters();
179
+ if (typeParameters) {
180
+ for (const tp of typeParameters) {
181
+ declaredFormalTypeNames.push(tp.symbol.getName());
182
+ }
183
+ }
184
+ }
185
+ else if (typescript_1.default.isMethodDeclaration(node) || typescript_1.default.isMethodSignature(node)) {
186
+ // For method declarations
187
+ const symbol = this.checker.getSymbolAtLocation(node.name);
188
+ if (!symbol) {
189
+ return undefined;
190
+ }
191
+ signature = this.checker.getSignatureFromDeclaration(node);
192
+ if (!signature) {
193
+ return undefined;
194
+ }
195
+ methodName = symbol.getName();
196
+ // Get the declaring type (the class/interface that contains this method)
197
+ const parent = node.parent;
198
+ if (typescript_1.default.isClassDeclaration(parent) || typescript_1.default.isInterfaceDeclaration(parent) || typescript_1.default.isObjectLiteralExpression(parent)) {
199
+ const parentType = this.checker.getTypeAtLocation(parent);
200
+ declaringType = this.getType(parentType);
201
+ }
202
+ else {
203
+ declaringType = java_1.Type.unknownType;
204
+ }
205
+ // Get type parameters from node
206
+ if (node.typeParameters) {
207
+ for (const tp of node.typeParameters) {
208
+ declaredFormalTypeNames.push(tp.name.getText());
209
+ }
210
+ }
211
+ }
212
+ else if (typescript_1.default.isFunctionDeclaration(node) || typescript_1.default.isFunctionExpression(node)) {
213
+ // For function declarations/expressions
214
+ signature = this.checker.getSignatureFromDeclaration(node);
215
+ if (!signature) {
216
+ return undefined;
217
+ }
218
+ methodName = node.name ? node.name.getText() : "<anonymous>";
219
+ declaringType = java_1.Type.unknownType;
220
+ // Get type parameters from node
221
+ if (node.typeParameters) {
222
+ for (const tp of node.typeParameters) {
223
+ declaredFormalTypeNames.push(tp.name.getText());
224
+ }
225
+ }
226
+ }
227
+ else {
228
+ // For other node types, return undefined
229
+ return undefined;
230
+ }
231
+ // Common logic for all method types
232
+ const returnType = signature.getReturnType();
233
+ const parameters = signature.getParameters();
234
+ const parameterTypes = [];
235
+ const parameterNames = [];
236
+ for (const param of parameters) {
237
+ parameterNames.push(param.getName());
238
+ const paramType = this.checker.getTypeOfSymbolAtLocation(param, node);
239
+ parameterTypes.push(this.getType(paramType));
240
+ }
241
+ // Create the Type.Method object
242
+ return Object.assign(new NonDraftableType(), {
243
+ kind: java_1.Type.Kind.Method,
244
+ declaringType: declaringType,
245
+ name: methodName,
246
+ returnType: this.getType(returnType),
247
+ parameterNames: parameterNames,
248
+ parameterTypes: parameterTypes,
249
+ thrownExceptions: [], // JavaScript doesn't have checked exceptions
250
+ annotations: [],
251
+ defaultValue: undefined,
252
+ declaredFormalTypeNames: declaredFormalTypeNames,
253
+ toJSON: function () {
254
+ return java_1.Type.signature(this);
255
+ }
256
+ });
257
+ }
258
+ /**
259
+ * Create a JavaType.Array from a TypeScript array type
260
+ */
261
+ createArrayType(type) {
262
+ // Get the element type (type argument of Array<T>)
263
+ const typeArgs = this.checker.getTypeArguments(type);
264
+ const elemType = typeArgs.length > 0 ? this.getType(typeArgs[0]) : java_1.Type.unknownType;
265
+ return Object.assign(new NonDraftableType(), {
266
+ kind: java_1.Type.Kind.Array,
267
+ elemType: elemType,
268
+ annotations: [],
269
+ toJSON: function () {
270
+ return java_1.Type.signature(this);
271
+ }
272
+ });
114
273
  }
115
- createType(type, cacheKey) {
116
- const signature = this.checker.typeToString(type);
274
+ /**
275
+ * Get the fully qualified name for a TypeScript type.
276
+ * Format: "module-specifier.TypeName" (e.g., "@mui/material.Button", "src/components/Button.Button")
277
+ */
278
+ getFullyQualifiedName(type) {
279
+ var _b, _c;
280
+ const symbol = (_b = type.getSymbol) === null || _b === void 0 ? void 0 : _b.call(type);
281
+ if (!symbol) {
282
+ return "unknown";
283
+ }
284
+ const typeName = symbol.getName();
285
+ const declaration = symbol.valueDeclaration || ((_c = symbol.declarations) === null || _c === void 0 ? void 0 : _c[0]);
286
+ if (!declaration) {
287
+ // No declaration - might be a built-in or synthetic type
288
+ if (builtInTypes.has(typeName)) {
289
+ return `lib.${typeName}`;
290
+ }
291
+ return typeName;
292
+ }
293
+ const sourceFile = declaration.getSourceFile();
294
+ const fileName = sourceFile.fileName;
295
+ // Check if this is a test file (snowflake ID as filename)
296
+ // Test files are generated with numeric IDs like "672087069480189952.ts"
297
+ if (/^\d+\.(ts|tsx|js|jsx)$/.test(fileName)) {
298
+ // For test files, just return the type name without module prefix
299
+ return typeName;
300
+ }
301
+ // Check if this is from TypeScript's lib files (lib.d.ts, lib.dom.d.ts, etc.)
302
+ if (fileName.includes("/typescript/lib/lib.") || fileName.includes("\\typescript\\lib\\lib.")) {
303
+ return `lib.${typeName}`;
304
+ }
305
+ // Check if this is from an external module (node_modules or .d.ts)
306
+ if (sourceFile.isDeclarationFile || fileName.includes("node_modules")) {
307
+ const packageName = this.extractPackageName(fileName);
308
+ if (packageName) {
309
+ return `${packageName}.${typeName}`;
310
+ }
311
+ }
312
+ // For local files, use relative path from project root
313
+ const relativePath = this.getRelativeModulePath(fileName);
314
+ return `${relativePath}.${typeName}`;
315
+ }
316
+ /**
317
+ * Extract package name from a node_modules path.
318
+ * Examples:
319
+ * - /path/to/project/node_modules/react/index.d.ts -> "react"
320
+ * - /path/to/project/node_modules/@mui/material/Button/index.d.ts -> "@mui/material"
321
+ */
322
+ extractPackageName(fileName) {
323
+ const match = fileName.match(/node_modules\/(@[^\/]+\/[^\/]+|[^\/]+)/);
324
+ return match ? match[1] : null;
325
+ }
326
+ /**
327
+ * Get relative module path from project root.
328
+ * Removes file extension and uses forward slashes.
329
+ */
330
+ getRelativeModulePath(fileName) {
331
+ // Remove project root and normalize path
332
+ let relativePath = fileName;
333
+ if (fileName.startsWith(this.projectRoot)) {
334
+ relativePath = fileName.slice(this.projectRoot.length);
335
+ }
336
+ // Remove leading slash and file extension
337
+ relativePath = relativePath.replace(/^\//, '').replace(/\.[^/.]+$/, '');
338
+ // Convert backslashes to forward slashes (for Windows)
339
+ relativePath = relativePath.replace(/\\/g, '/');
340
+ return relativePath;
341
+ }
342
+ /**
343
+ * Create an empty JavaType.Class shell from a TypeScript type.
344
+ * The shell will be populated later to handle circular references.
345
+ */
346
+ createEmptyClassType(type) {
347
+ var _b;
348
+ // Use our custom getFullyQualifiedName method for consistent naming
349
+ let fullyQualifiedName = this.getFullyQualifiedName(type);
350
+ // If getFullyQualifiedName returned unknown, fall back to TypeScript's method
351
+ if (fullyQualifiedName === "unknown") {
352
+ const symbol = type.symbol;
353
+ fullyQualifiedName = symbol ? this.checker.getFullyQualifiedName(symbol) : `<anonymous>${this.checker.typeToString(type)}`;
354
+ // Fix FQN for types from @types packages
355
+ // TypeScript returns "_.LoDashStatic" but we want "@types/lodash.LoDashStatic"
356
+ if (symbol && symbol.declarations && symbol.declarations.length > 0) {
357
+ const sourceFile = symbol.declarations[0].getSourceFile();
358
+ const fileName = sourceFile.fileName;
359
+ // Check if this is from @types package
360
+ const typesMatch = fileName.match(/node_modules\/@types\/([^/]+)/);
361
+ if (typesMatch) {
362
+ const packageName = typesMatch[1];
363
+ // Replace the module specifier part with @types/package
364
+ fullyQualifiedName = fullyQualifiedName.replace(/^[^.]+\./, `@types/${packageName}.`);
365
+ }
366
+ }
367
+ }
368
+ // Determine the class kind based on symbol flags
369
+ let classKind = java_1.Type.Class.Kind.Interface; // Default to interface
370
+ const symbol = (_b = type.getSymbol) === null || _b === void 0 ? void 0 : _b.call(type);
371
+ if (symbol) {
372
+ if (symbol.flags & typescript_1.default.SymbolFlags.Class) {
373
+ classKind = java_1.Type.Class.Kind.Class;
374
+ }
375
+ else if (symbol.flags & typescript_1.default.SymbolFlags.Enum) {
376
+ classKind = java_1.Type.Class.Kind.Enum;
377
+ }
378
+ else if (symbol.flags & typescript_1.default.SymbolFlags.Interface) {
379
+ classKind = java_1.Type.Class.Kind.Interface;
380
+ }
381
+ }
382
+ // Create empty class type shell (no members yet to avoid recursion)
383
+ return Object.assign(new NonDraftableType(), {
384
+ kind: java_1.Type.Kind.Class,
385
+ classKind: classKind,
386
+ fullyQualifiedName: fullyQualifiedName,
387
+ typeParameters: [],
388
+ annotations: [],
389
+ interfaces: [],
390
+ members: [],
391
+ methods: [],
392
+ toJSON: function () {
393
+ return java_1.Type.signature(this);
394
+ }
395
+ });
396
+ }
397
+ /**
398
+ * Populates the class type with members, methods, heritage, and type parameters
399
+ * Since the shell is already in the cache, any recursive references will find it
400
+ */
401
+ populateClassType(classType, type) {
402
+ var _b, _c, _d, _e, _f, _g, _h, _j;
403
+ const symbol = (_b = type.getSymbol) === null || _b === void 0 ? void 0 : _b.call(type);
404
+ // Try to get base types using TypeScript's getBaseTypes API
405
+ // This works for both local and external types (from node_modules)
406
+ if (type.flags & typescript_1.default.TypeFlags.Object) {
407
+ let baseTypes;
408
+ // Check if this is a class or interface type that supports getBaseTypes
409
+ const objectType = type;
410
+ if (objectType.objectFlags & (typescript_1.default.ObjectFlags.Class | typescript_1.default.ObjectFlags.Interface)) {
411
+ try {
412
+ baseTypes = (_d = (_c = this.checker).getBaseTypes) === null || _d === void 0 ? void 0 : _d.call(_c, type);
413
+ }
414
+ catch (e) {
415
+ // getBaseTypes might fail for some types, fall back to declaration-based extraction
416
+ }
417
+ }
418
+ else if (symbol) {
419
+ // For constructor functions or type references, we need to get the actual class type
420
+ // Try to get the type of the class itself (not the constructor or instance)
421
+ const classSymbol = symbol.flags & typescript_1.default.SymbolFlags.Alias ?
422
+ this.checker.getAliasedSymbol(symbol) : symbol;
423
+ if (classSymbol && classSymbol.flags & (typescript_1.default.SymbolFlags.Class | typescript_1.default.SymbolFlags.Interface)) {
424
+ // Get the type of the class declaration itself
425
+ const declaredType = this.checker.getDeclaredTypeOfSymbol(classSymbol);
426
+ if (declaredType && declaredType !== type) {
427
+ try {
428
+ baseTypes = (_f = (_e = this.checker).getBaseTypes) === null || _f === void 0 ? void 0 : _f.call(_e, declaredType);
429
+ }
430
+ catch (e) {
431
+ // getBaseTypes might fail, fall back to declaration-based extraction
432
+ }
433
+ }
434
+ }
435
+ else if (classSymbol && classSymbol.valueDeclaration && typescript_1.default.isClassDeclaration(classSymbol.valueDeclaration)) {
436
+ // Handle the case where the symbol is for a class value (constructor function)
437
+ // Get the instance type of the class
438
+ const instanceType = this.checker.getDeclaredTypeOfSymbol(classSymbol);
439
+ if (instanceType && instanceType !== type) {
440
+ try {
441
+ baseTypes = (_h = (_g = this.checker).getBaseTypes) === null || _h === void 0 ? void 0 : _h.call(_g, instanceType);
442
+ }
443
+ catch (e) {
444
+ // getBaseTypes might fail, fall back to declaration-based extraction
445
+ }
446
+ }
447
+ }
448
+ }
449
+ if (baseTypes && baseTypes.length > 0) {
450
+ // For classes, the first base type is usually the superclass
451
+ // Additional base types are interfaces
452
+ if (classType.classKind === java_1.Type.Class.Kind.Class) {
453
+ const firstBase = this.getType(baseTypes[0]);
454
+ if (java_1.Type.isClass(firstBase)) {
455
+ classType.supertype = firstBase;
456
+ }
457
+ // Rest are interfaces
458
+ for (let i = 1; i < baseTypes.length; i++) {
459
+ const interfaceType = this.getType(baseTypes[i]);
460
+ if (java_1.Type.isClass(interfaceType)) {
461
+ classType.interfaces.push(interfaceType);
462
+ }
463
+ }
464
+ }
465
+ else {
466
+ // For interfaces, all base types are extended interfaces
467
+ for (const baseType of baseTypes) {
468
+ const interfaceType = this.getType(baseType);
469
+ if (java_1.Type.isClass(interfaceType)) {
470
+ classType.interfaces.push(interfaceType);
471
+ }
472
+ }
473
+ }
474
+ }
475
+ }
476
+ // Extract type parameters from declarations (not provided by getBaseTypes)
477
+ if (symbol === null || symbol === void 0 ? void 0 : symbol.declarations) {
478
+ for (const declaration of symbol.declarations) {
479
+ if (typescript_1.default.isClassDeclaration(declaration) || typescript_1.default.isInterfaceDeclaration(declaration)) {
480
+ // Extract type parameters
481
+ if (declaration.typeParameters) {
482
+ for (const tp of declaration.typeParameters) {
483
+ const tpType = this.checker.getTypeAtLocation(tp);
484
+ classType.typeParameters.push(this.getType(tpType));
485
+ }
486
+ }
487
+ break; // Only process the first declaration
488
+ }
489
+ }
490
+ }
491
+ // Get properties and methods
492
+ const properties = this.checker.getPropertiesOfType(type);
493
+ for (const prop of properties) {
494
+ const declaration = prop.valueDeclaration || ((_j = prop.declarations) === null || _j === void 0 ? void 0 : _j[0]);
495
+ if (!declaration) {
496
+ // Skip properties without declarations (synthetic/built-in properties)
497
+ continue;
498
+ }
499
+ if (prop.flags & typescript_1.default.SymbolFlags.Method) {
500
+ // TODO: Create Type.Method when method support is added
501
+ // For now, skip methods
502
+ continue;
503
+ }
504
+ else {
505
+ // Create Type.Variable for fields/properties
506
+ const propType = this.checker.getTypeOfSymbolAtLocation(prop, declaration);
507
+ const variable = Object.assign(new NonDraftableType(), {
508
+ kind: java_1.Type.Kind.Variable,
509
+ name: prop.getName(),
510
+ owner: classType, // Cyclic reference to the containing class (already in cache)
511
+ type: this.getType(propType), // This will find classType in cache if it's recursive
512
+ annotations: [],
513
+ toJSON: function () {
514
+ return java_1.Type.signature(this);
515
+ }
516
+ });
517
+ classType.members.push(variable);
518
+ }
519
+ }
520
+ }
521
+ /**
522
+ * Note: Object/Class/Interface types are handled in getType() to properly manage circular references
523
+ * This method should only be called for primitive and unknown types
524
+ */
525
+ createPrimitiveOrUnknownType(type) {
526
+ var _b;
527
+ // Check for literals first
117
528
  if (type.isLiteral()) {
118
529
  if (type.isNumberLiteral()) {
119
- return java_1.JavaType.Primitive.Double;
530
+ return java_1.Type.Primitive.Double;
120
531
  }
121
532
  else if (type.isStringLiteral()) {
122
- return java_1.JavaType.Primitive.String;
533
+ return java_1.Type.Primitive.String;
123
534
  }
124
535
  }
125
- if (type.flags === ts.TypeFlags.Null) {
126
- return java_1.JavaType.Primitive.Null;
536
+ // Check for primitive types
537
+ if (type.flags === typescript_1.default.TypeFlags.Null) {
538
+ return java_1.Type.Primitive.Null;
127
539
  }
128
- else if (type.flags === ts.TypeFlags.Undefined) {
129
- return java_1.JavaType.Primitive.None;
540
+ else if (type.flags === typescript_1.default.TypeFlags.Undefined) {
541
+ return java_1.Type.Primitive.None;
130
542
  }
131
- else if (type.flags === ts.TypeFlags.Number ||
132
- type.flags === ts.TypeFlags.NumberLiteral ||
133
- type.flags === ts.TypeFlags.NumberLike) {
134
- return java_1.JavaType.Primitive.Double;
543
+ else if (type.flags === typescript_1.default.TypeFlags.Number ||
544
+ type.flags === typescript_1.default.TypeFlags.NumberLiteral ||
545
+ type.flags === typescript_1.default.TypeFlags.NumberLike) {
546
+ return java_1.Type.Primitive.Double;
135
547
  }
136
- else if (type.flags === ts.TypeFlags.String ||
137
- type.flags === ts.TypeFlags.StringLiteral ||
138
- type.flags === ts.TypeFlags.StringLike) {
139
- return java_1.JavaType.Primitive.String;
548
+ else if (type.flags === typescript_1.default.TypeFlags.String ||
549
+ type.flags === typescript_1.default.TypeFlags.StringLiteral ||
550
+ type.flags === typescript_1.default.TypeFlags.StringLike) {
551
+ return java_1.Type.Primitive.String;
140
552
  }
141
- else if (type.flags === ts.TypeFlags.Void) {
142
- return java_1.JavaType.Primitive.Void;
553
+ else if (type.flags === typescript_1.default.TypeFlags.Void) {
554
+ return java_1.Type.Primitive.Void;
143
555
  }
144
- else if (type.flags === ts.TypeFlags.BigInt ||
145
- type.flags === ts.TypeFlags.BigIntLiteral ||
146
- type.flags === ts.TypeFlags.BigIntLike) {
147
- return java_1.JavaType.Primitive.Long;
556
+ else if (type.flags === typescript_1.default.TypeFlags.BigInt ||
557
+ type.flags === typescript_1.default.TypeFlags.BigIntLiteral ||
558
+ type.flags === typescript_1.default.TypeFlags.BigIntLike) {
559
+ return java_1.Type.Primitive.Long;
148
560
  }
149
561
  else if ((type.symbol !== undefined && type.symbol === this.regExpSymbol) ||
150
562
  this.checker.typeToString(type) === "RegExp") {
151
- return java_1.JavaType.Primitive.String;
563
+ return java_1.Type.Primitive.String;
152
564
  }
153
565
  /**
154
566
  * TypeScript may assign multiple flags to a single type (e.g., Boolean + Union).
155
567
  * Using a bitwise check ensures we detect Boolean even if other flags are set.
156
568
  */
157
- if (type.flags & ts.TypeFlags.Boolean ||
158
- type.flags & ts.TypeFlags.BooleanLiteral ||
159
- type.flags & ts.TypeFlags.BooleanLike) {
160
- return java_1.JavaType.Primitive.Boolean;
161
- }
162
- // if (ts.isRegularExpressionLiteral(node)) {
163
- // return JavaType.Primitive.String;
164
- // }
165
- return java_1.JavaType.unknownType;
569
+ if (type.flags & typescript_1.default.TypeFlags.Boolean ||
570
+ type.flags & typescript_1.default.TypeFlags.BooleanLiteral ||
571
+ type.flags & typescript_1.default.TypeFlags.BooleanLike) {
572
+ return java_1.Type.Primitive.Boolean;
573
+ }
574
+ // Check for type aliases that may resolve to primitives
575
+ const symbol = (_b = type.getSymbol) === null || _b === void 0 ? void 0 : _b.call(type);
576
+ if (symbol && symbol.flags & typescript_1.default.SymbolFlags.TypeAlias) {
577
+ // Type aliases may resolve to primitive types
578
+ const aliasedType = this.checker.getDeclaredTypeOfSymbol(symbol);
579
+ if (aliasedType !== type) {
580
+ return this.getType(aliasedType);
581
+ }
582
+ }
583
+ return java_1.Type.unknownType;
166
584
  }
167
585
  }
168
586
  exports.JavaScriptTypeMapping = JavaScriptTypeMapping;
169
- rpc_1.RpcCodecs.registerCodec(java_1.JavaType.Kind.Primitive, {
170
- rpcSend(after, q) {
171
- return __awaiter(this, void 0, void 0, function* () {
172
- yield q.getAndSend(after, p => p.keyword);
173
- });
174
- },
175
- rpcReceive(before, q) {
176
- return __awaiter(this, void 0, void 0, function* () {
177
- const keyword = yield q.receive(before.keyword);
178
- return java_1.JavaType.Primitive.fromKeyword(keyword);
179
- });
180
- }
181
- });
182
587
  //# sourceMappingURL=type-mapping.js.map