Open jimmywarting opened 11 months ago
Bun's transpiler is what enables JSX, TypeScript, CommonJS and more to "just work". We are not going to disable the transpiler by default.
If you want to disable the transpiler for your code, you can stick // @bun
as a comment at the top of the file.
That's just weird... are there any other option to opt into disable it then? like using bunfig.toml
?
I don't want to have to add this comment to every file.
Perhaps you can disable it for just plain vanilla .js
files?
We could add a CLI flag for this, which would be the same behaviour as if every file had // @bun
at the top.
both a CLI flag and a bunfig.toml config would be 👍
@Jarred-Sumner After added // @bun
to the top of the file, I got this error
SyntaxError: Unexpected token '{'. Expected 'from' before imported module name.
at /Users/ayon/Workspace/jsext/example.ts:4
Any ideas?
This is my code:
// @bun
import util, { InspectOptions } from "node:util";
import type { Ensured } from "./index.ts";
Is there any way not to remove the comments? I tried ts-node and deno, they both keep the comment as is, it's so odd that Bun removed them. I'd like to do some analysis based on the comment in the source code returned from the toString()
function.
@ayonli
you are using TypeScript specific syntax. like import type ...
I have just learned that // @bun
disables the transpiler. So it would expect your code to be pure vanilla javascript.
hence why you get the Syntax Error "Unexpected token '{'. Expected 'from' before imported module name"
@jimmywarting And this directive seems odd too, it is more like @no-bun
instead of @bun
.
just the name "bun" isn't such a good word in itself. it dose not describe what the comment dose or what the meaning of it is
following typescript convention (@ts-check @ts-expect-error @ts-ignore @ts-nocheck
)
then i think a better name for it would be @bun-notransform
or @bun-ignore
What version of Bun is running?
1.0.2+37edd5a6e389265738e89265bcbdf2999cb81a49
What platform is your computer?
Darwin 22.4.0 arm64 arm
What steps can reproduce the bug?
bun run script.js
What is the expected behavior?
To see that the source code is exactly the same, but it's not.
What do you see instead?
transformed code.
Additional information
This is bad... the code are not exactly the same. i expected them to be the same, and i must rely on them being exactly the same.
code transformation should be disabled by default.
!1
and!0