import ts from "typescript"; import { Type } from "../java"; export declare class JavaScriptTypeMapping { private readonly checker; private readonly sourceRoot?; private readonly typeCache; private readonly methodCache; private readonly regExpSymbol; private readonly stringWrapperType; private readonly numberWrapperType; private readonly booleanWrapperType; constructor(checker: ts.TypeChecker, sourceRoot?: string | undefined); type(node: ts.Node): Type | undefined; /** * Resolve the type of a decorator from the symbol it references, naming it by the decorator's * fully qualified name (e.g. `typeorm.Entity`) rather than the generic function type of the * decorator factory. Decorators are the JavaScript/TypeScript analogue of Java annotations, so * — like {@code J.Annotation} in the Java LST — they are typed as a {@link Type.FullyQualified} * with {@code classKind = Annotation}, which lets recipes match them by fully qualified name. * * @param node the identifier or qualified name naming the decorator (e.g. `Entity` in `@Entity()`) */ annotationType(node: ts.Node): Type.FullyQualified | undefined; /** * Resolve the declared type of a class / interface / enum / class-expression. * * Using {@code getTypeAtLocation} on these declaration nodes is unsafe: TypeScript returns * the type of the declared *value*, not the type itself. For string or numeric enums that * ends up being the union of enum literals, which on the JS side resolves to * {@link Type.Primitive} (e.g. String for string enums). The Java-side RPC receiver then * rejects it with "A class can only be type attributed with a fully qualified type name", * because {@code J.ClassDeclaration.type} must be {@link Type.FullyQualified}. * * Instead, we resolve through the declaration's own symbol. For classes and interfaces we * reuse the full type mapping pipeline (so members, methods, supertypes and type parameters * are populated). For enums — which have no class-shaped representation in TypeScript — and * any residual non-FQ result, we build a minimal class shell whose FQN and {@code classKind} * are derived from the declaration itself. */ declarationType(node: ts.ClassDeclaration | ts.ClassExpression | ts.InterfaceDeclaration | ts.EnumDeclaration): Type.FullyQualified | undefined; /** * Map an exported symbol (type alias, namespace, function, ...) to its {@link Type} via the * symbol's declared or value type. Enumerator-only entry point ({@code exportedTypes}) for * exports that are not class/interface/enum declarations; those go through {@link declarationType}. */ exportedType(symbol: ts.Symbol): Type | undefined; private getType; private getSignature; primitiveType(node: ts.Node): Type.Primitive; variableType(node: ts.Node): Type.Variable | undefined; /** * Extract the npm module name from a file path. * Handles various package manager layouts: * - Standard: /path/node_modules/react/index.d.ts -> react * - Scoped: /path/node_modules/@types/react/index.d.ts -> react * - Scoped with __ encoding: /path/node_modules/@types/testing-library__react/index.d.ts -> @testing-library/react * - Nested node_modules: /path/node_modules/pkg/node_modules/dep/index.d.ts -> dep * - pnpm: /path/node_modules/.pnpm/react@18.2.0/node_modules/react/index.d.ts -> react * * @returns The module name, or undefined if not from node_modules */ private extractModuleNameFromPath; /** * Normalize a node_modules package name to the specifier consumers actually import. * * DefinitelyTyped packages (`@types/`) are never importable under that name — the * importable specifier is ``, with DefinitelyTyped's `__` scoped-package encoding * decoded back to a `@scope/name` form. Using the importable specifier keeps attributed * fully qualified names consistent regardless of whether a type is reached through a direct * import (which already resolves via the module specifier) or transitively (e.g. a call's * return type), which falls back to the declaration file's `node_modules` path. * * Examples: * - `@types/express-serve-static-core` -> `express-serve-static-core` * - `@types/node` -> `node` * - `@types/testing-library__react` -> `@testing-library/react` */ private normalizePackageName; /** * Helper to create a Type.Method object from common parameters */ private createMethodType; private wrapperType; methodType(node: ts.Node): Type.Method | undefined; /** * Get the fully qualified name for a TypeScript type. * Uses TypeScript's built-in resolution which properly handles things like: * - React.Component (not @types/react.Component) * - _.LoDashStatic (not @types/lodash.LoDashStatic) */ private getFullyQualifiedName; private getFullyQualifiedNameFromSymbol; /** * Whether {@code namespaceName} is exposed as a UMD global from the given declaration file * (e.g. `export as namespace React`). The namespace name of a UMD global is the conventional * public identifier (React, lodash `_`, jQuery `$`) and must be preserved rather than replaced * with the package name. */ private isUmdGlobalNamespace; /** * Create an empty JavaType.Class shell from a TypeScript type. * The shell will be populated later to handle circular references. */ private createEmptyClassType; /** * Populates the class type with members, methods, heritage, and type parameters * Since the shell is already in the cache, any recursive references will find it */ private populateClassType; /** * Note: Object/Class/Interface types are handled in getType() to properly manage circular references * This method should only be called for primitive and unknown types */ private createPrimitiveOrUnknownType; /** * Create a union type from TypeScript union type (e.g., string | number) * Note: Cache check is done in getType() before calling this method */ private createUnionType; /** * Create an intersection type from TypeScript intersection type (e.g., A & B) * Note: Cache check is done in getType() before calling this method */ private createIntersectionType; /** * Create a generic type variable from a TypeScript type parameter. * Examples: T, K extends string, V extends keyof T * Note: Cache check is done in getType() before calling this method */ private createGenericTypeVariable; /** * Create an empty function type shell with FQN 𝑓. * The shell will be populated later to handle circular references. */ private createEmptyFunctionType; /** * Populate a function type with signature information. * The function type has generic type parameters for return type (first) and parameter types (subsequent), * and contains an apply() method with the matching signature. * Since the shell is already in the cache, any recursive references will find it. */ private populateFunctionType; } //# sourceMappingURL=type-mapping.d.ts.map