CtrlK
CommunityDocumentationLog inGet started
Tessl Logo

tessl/npm-ts-api-utils

tessl install tessl/npm-ts-api-utils@2.0.0

Utility functions for working with TypeScript's API, providing comprehensive tools for analyzing and manipulating TypeScript AST nodes, types, and compiler APIs.

Agent Success

Agent success rate when using this tile

79%

Improvement

Agent success rate improvement when using this tile compared to baseline

1.98x

Baseline

Agent success rate without this tile

40%

task.mdevals/scenario-10/

TypeScript Code Analyzer

A utility that analyzes TypeScript source code to identify specific patterns related to property definitions and const contexts.

Capabilities

Identify Static Object.defineProperty Calls

Analyzes TypeScript code and finds all Object.defineProperty() calls that can be statically analyzed (bindable calls).

  • Given TypeScript code containing Object.defineProperty(obj, 'prop', { value: 42 }), the analyzer returns information indicating this is a bindable property definition call @test
  • Given TypeScript code with a dynamic property name like Object.defineProperty(obj, computedName, descriptor), the analyzer correctly identifies this is not a bindable call @test
  • Given TypeScript code with no Object.defineProperty() calls, the analyzer returns an empty result @test

Detect Const Assertion Contexts

Analyzes TypeScript code to detect expressions that are in const contexts (e.g., as const assertions, const type parameters).

  • Given TypeScript code containing const obj = { x: 10 } as const, the analyzer identifies the object literal as being in a const context @test
  • Given TypeScript code with const arr = [1, 2, 3] (without as const), the analyzer correctly identifies the array literal is not in a const context @test
  • Given TypeScript code with a const type parameter like function f<T extends readonly string[]>(x: T), the analyzer identifies expressions bound to T as being in a const context @test

Implementation

@generates

API

/**
 * Result of analyzing a bindable Object.defineProperty call
 */
export interface BindablePropertyInfo {
  /** The line number where the call occurs */
  line: number;
  /** The property name being defined (if statically determinable) */
  propertyName?: string;
  /** Whether this is a bindable (statically analyzable) call */
  isBindable: boolean;
}

/**
 * Result of analyzing a const context
 */
export interface ConstContextInfo {
  /** The line number where the expression occurs */
  line: number;
  /** The type of expression (e.g., 'ObjectLiteral', 'ArrayLiteral') */
  expressionType: string;
  /** Whether the expression is in a const context */
  isConst: boolean;
}

/**
 * Overall analysis result
 */
export interface AnalysisResult {
  /** Information about Object.defineProperty calls found */
  propertyDefinitions: BindablePropertyInfo[];
  /** Information about const contexts found */
  constContexts: ConstContextInfo[];
}

/**
 * Analyzes TypeScript source code to identify bindable property definitions
 * and const assertion contexts.
 *
 * @param sourceCode - The TypeScript source code to analyze as a string
 * @returns An AnalysisResult containing information about property definitions and const contexts
 */
export function analyzeCode(sourceCode: string): AnalysisResult;

Dependencies { .dependencies }

ts-api-utils { .dependency }

Provides TypeScript API utilities for AST analysis, specifically for detecting bindable Object.defineProperty calls and const contexts.

typescript { .dependency }

Provides the TypeScript compiler API for parsing and analyzing TypeScript source code.

Version

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/ts-api-utils@2.0.x
tile.json