MCPcopy Index your code
hub / github.com/compilets/compilets

github.com/compilets/compilets @v0.1.4

Chat with this repo
repository ↗ · DeepWiki ↗ · release v0.1.4 ↗ · + Follow
941 symbols 1,832 edges 118 files 91 documented · 10%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

Compilets

TypeScript to C++ compiler.

Giving a TypeScript project, it can translate the code to C++, and produce native executables and Node.js modules.

This project does not plan to support every TypeScript feature - doing so would make it downgrade to a JavaScript interpreter - it only translates code that can be effiently represented in C++. Code relying on JavaScript's dynamic natures, for example prototype and any, will be rejected.

Currently it is still very early days, and it fails to translate most existing TypeScript projects, but it is capable of turning some performance-critical code into native Node.js modules.

Docs

There is currently no documentation on which TypeScript syntax and features are supported.

CLI

Install:

npm install -g compilets

Help:

━━━ Compilets - 0.0.1-dev ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

  $ compilets <command>

━━━ General commands ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

  compilets build [--config #0] [--target #0] ...
    Build C++ project.

  compilets gen [--root #0] [--config #0] [--target #0]
    Generate a C++ project from TypeScript project.

  compilets gn-gen [--config #0] <--target #0>
    Run "gn gen" for the C++ project.

Example:

mkdir example
cd example
echo 'console.log("Hello World!")' > main.ts
compilets gen
compilets build
./cpp-project/out/Debug/example

Compatibility with tsconfig.json and package.json

When compiling a project, the tsconfig.json file under the root directory is used for initializing the TypeScript compiler. If such file is not present, following compilerOptions will be used:

{
  noEmit: true,
  noImplicitAny: true,
  strictNullChecks: true,
  allowImportingTsExtensions: true
}

In this case the .ts files under the root directory will be used for compilation, and the files are searched non-recursively.

Also, the compilerOptions.strictNullChecks field must be true when a tsconfig.json file is provided.

When a package.json file is found in the root directory, following rules are applied:

  • The name field is used as the project's name.
  • If the compilets.main field is a .ts file, a native module will be created.
  • If the compilets.bin field is an object with values of .ts files, executables will be created for each entry of the object.

An example package.json file:

{
  "name": "download",
  "compilets": {
    "main": "lib.ts",
    "bin": {
      "download": "cli.ts"
    }
  }
}

If there is no package.json file, the root directory must contain only one .ts file and it will be compiled into executable.

Developement

The documentations of Oilpan GC (cppgc) can be found at:

You can get familiar with TypeScript's compiler APIs with following articles:

Tools below will help developement of this project:

About GN, the build system used for building C++ code:

License

This project is published under GPLv3, the C++ code (/cpp/runtime) has a an extra linking exception.

In plain words, distributing the compiled executable files does not require you to open source, only including the source code of this project requires so.

I'll change the license to a permissive one if this project gets enough funding.

Contributor license agreement

By sending a pull request, you hereby grant to owners and users of this project a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare derivative works of, publicly display, publicly perform, sublicense, and distribute your contributions and such derivative works.

The owners of the this project will also be granted the right to relicense the contributed source code and its derivative works to a more permissive license.

Extension points exported contracts — how you extend this code

CommonGnOptions (Interface)
(no doc)
src/gn-utils.ts
NamespaceBlock (Interface)
(no doc)
src/cpp-file.ts
GnGenOptions (Interface)
(no doc)
src/gn-utils.ts
IncludeDirective (Interface)
(no doc)
src/cpp-file.ts
NinjaBuildOptions (Interface)
(no doc)
src/gn-utils.ts

Core symbols most depended-on inside this repo

push
called by 92
cpp/runtime/array.h
print
called by 86
src/cpp-syntax.ts
exit
called by 54
cpp/runtime/process.cc
Equal
called by 33
cpp/runtime/type_traits.h
join
called by 33
src/print-utils.ts
StrictEqual
called by 26
cpp/runtime/type_traits.h
parseNodeType
called by 24
src/parser-typer.ts
TraceMember
called by 23
cpp/runtime/union.h

Shape

Method 408
Class 312
Function 216
Interface 5

Languages

TypeScript66%
C++34%

Modules by API surface

src/cpp-syntax.ts215 symbols
src/cpp-syntax-type.ts51 symbols
src/cpp-file.ts33 symbols
cpp/runtime/array.h33 symbols
src/parser-utils.ts32 symbols
src/parser-typer.ts27 symbols
src/parser.ts23 symbols
src/print-utils.ts21 symbols
tests/data-conversion/interface/interface.cpp20 symbols
tests/data-conversion/forward/forward.cpp18 symbols
cpp/runtime/type_traits.h18 symbols
tests/data-conversion/class-union/classunion.cpp15 symbols

For agents

$ claude mcp add compilets \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact