Skip to content

Parsing Options

Learn to configure how Parsee analyzes source code.

Basic Parsing

Parse TypeScript/JavaScript code:

typescript
import { parseWithTsMorph } from "@briklab/lib/parsee";

const code = `
  export class MyClass {
    name: string;
    constructor(name: string) {
      this.name = name;
    }
    greet() {
      return \`Hello, \${this.name}\`;
    }
  }
`;

const result = parseWithTsMorph(code);
console.log(result.classes.length); // 1
console.log(result.classes[0].name); // "MyClass"

Live demo of parsing options:

Console
No logs yet.

Parse Mode Options

Different parsing modes:

typescript
import { parseWithTsMorph } from "@briklab/lib/parsee";

const code = `
  export function hello() {
    return "world";
  }
`;

// Default parsing
const defaultResult = parseWithTsMorph(code);

// With specific options
const result = parseWithTsMorph(code, {
  mode: "full" // 'full' or 'quick'
});

console.log(result.functions.length); // 1

Filtering Results

Control what gets parsed:

typescript
import { parseWithTsMorph } from "@briklab/lib/parsee";

const code = `
  export class User {
    name: string;
  }
  
  private class Internal {
    data: any;
  }
`;

const result = parseWithTsMorph(code, {
  includePrivate: false // Skip private members
});

console.log(result.classes.length); // Depending on settings

Module Resolution

Handle imports and exports:

typescript
import { parseWithTsMorph } from "@briklab/lib/parsee";

const code = `
  import { Component } from '@angular/core';
  import * as utils from './utils';
  
  export class AppComponent {
    title = 'app';
  }
`;

const result = parseWithTsMorph(code, {
  resolveImports: true
});

// Access import information
console.log(result);

Generic Type Extraction

Handle generic types:

typescript
import { parseWithTsMorph } from "@briklab/lib/parsee";

const code = `
  export class Repository<T> {
    data: T[];
    find(id: number): T | null {
      return this.data[0];
    }
  }
`;

const result = parseWithTsMorph(code);
console.log(result.classes[0].name); // "Repository"

Next Steps