ts-fn-source-code-range-recorder

This transformer records all code range of function declarations and arrow functions into a json file named .file-fn-range.json in the project root.

Usage no npm install needed!

<script type="module">
  import tsFnSourceCodeRangeRecorder from 'https://cdn.skypack.dev/ts-fn-source-code-range-recorder';
</script>

README

ts-fn-source-code-range-recorder

Introduction

This transformer records all code range of function declarations and arrow functions into a json file named .file-fn-range.json in the project root.

Sample:

|---my-app
|   |---src
|   |   |---inner
|   |   |   |---b.ts
|   |   |---a.ts

src/a.ts:

export function add(a: number, b: number): number {
  return a + b;
}

src/inner/b.ts:

export const add = (a: number, b: number): number => {
  return a + b;
}

export class Calc {
  add(a: number, b: number): number {
    return a + b;
  }
}

_fileFnRange.json:

{
  "src/a.ts": [
    {
      "start": 0,
      "end": 69
    }
  ],
  "src/inner/b.ts": [
    {
      "start": 6,
      "end": 72
    },
    {
      "start": 18,
      "end": 72
    },
    {
      "start": 93,
      "end": 153
    }
  ]
}

Installation

$ npm i -D ts-fn-source-code-range-recorder

Usage

Assumes that your source code directory is src and tsconfig.json is in the project root.

Creates a new file named "compile.ts" in the project root with following content:s

import { compile } from "ts-fn-source-code-range-recorder";

compile("src", "tsconfig.json");

Then run

$ ts-node compile.ts

to compile your code into JS.