dylan-conway / bun-bug

Incredibly fast JavaScript runtime, bundler, test runner, and package manager – all in one

Home Page:https://bun.sh

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Bun includes a TypeScript -> JavaScript transpiler, which is used to power the runtime (run .ts files directly). It can be run in isolation with the CLI command bun build ./input.ts (default output to stdout).

The bug comes from transpiling TypeScript enums inside of namespaces. JavaScript has neither enum nor namespace, so it's the transpiler's job to lower this syntax into valid JavaScript.

Given the input:

namespace Test {
  export enum Foo {}
}

Bun currently outputs the following, which when run throws a syntax error:

// test.ts
var Test;
(function (Test) {
  export let Foo; // <-- SyntaxError: unexpected`export`
  (function (Foo2) {})((Foo = Test.Foo || (Test.Foo = {})));
})(Test || (Test = {}));

It is worth noting that parser/transpiler in Bun was originally written by porting esbuild to Zig, with many functions names being identical, down to copying some of their comments. Esbuild does not have this bug.

Bun can be rebuild with ninja -Cbuild, where it is available as bun-debug. VSCode's debugger has been configured to run bun-debug build on the sample file for you.

About

Incredibly fast JavaScript runtime, bundler, test runner, and package manager – all in one

https://bun.sh

License:Other


Languages

Language:Zig 60.0%Language:C++ 24.1%Language:JavaScript 5.9%Language:TypeScript 5.2%Language:C 3.3%Language:Shell 0.4%Language:Makefile 0.3%Language:CMake 0.2%Language:Objective-C 0.1%Language:PowerShell 0.1%Language:Perl 0.1%Language:Dockerfile 0.1%Language:CSS 0.1%Language:Ruby 0.1%Language:Rust 0.0%Language:HTML 0.0%Language:AMPL 0.0%