Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fn.toString() should return author time code instead of optimized code and bun run, bun build, bun build --minify should log the same. #10488

Closed
liquancss opened this issue Apr 24, 2024 · 7 comments
Labels
bug Something isn't working transpiler parser || printer

Comments

@liquancss
Copy link

What version of Bun is running?

1.1.4+fbe2fe0c3

What platform is your computer?

Microsoft Windows NT 10.0.19044.0 x64

What steps can reproduce the bug?

// main.js
function foo(){
    const a = 1;
    return a+v;
}
console.log("foo.toString", foo.toString())
bun run main.js

What is the expected behavior?

it should like this

foo.toString function foo(){
    const a = 1;
    return a+v;
}

What do you see instead?

I get optimized code.

foo.toString function() {
  return 1 + v;
}

As you can see, bun build without --minify flag works fine as node and browser. But bun run and bun build --minify just behave very differently.

image

Additional information

No response

@liquancss liquancss added the bug Something isn't working label Apr 24, 2024
@anru
Copy link

anru commented Jun 18, 2024

Still actual for bun v1.1.13

@anru
Copy link

anru commented Jun 18, 2024

@Jarred-Sumner this bug causes runtime inconsistency with node.js runtime. So, in some cases it's blocker for replace node to bun where you have to use fn.toString() functionality. For example dynamically generate js code for submitting it via api

@anru
Copy link

anru commented Jul 9, 2024

Can confirm this issue has been fixed in version 1.1.18

@liquancss
Copy link
Author

Can confirm this issue has been fixed in version 1.1.18 🎉

I tried it on my mac and windows with bun v1.1.18, it's still unchanged.

Please tell me which platform do you use and share me related test code as well.

1.1 mac snopshot

截屏2024-07-10 08 43 17

1.2 windows snopshot

image

@anru
Copy link

anru commented Jul 10, 2024

That's right, I jumped to conslusions too soon.

I have tested only in bun repl.
image

But bug is still actual for bun run/bun build

@liquancss
Copy link
Author

That's right, I jumped to conslusions too soon.

I have tested only in bun repl. image

But bug is still actual for bun run/bun build

Yep, it’ true.

I’m just curious that bun is a JavaScript runtime thus they should implement the language runtime as ecma spec says.

From my view, bun seems to make JavaScript dialect themselves, and plus four kind dialects. One snippet code generate four very different results.

@paperdave paperdave added bundler Something to do with the bundler transpiler parser || printer and removed bundler Something to do with the bundler labels Sep 1, 2024
@paperdave
Copy link
Member

Duplicate of #3248 (you should 👍 that issue).

This might be fixed for bun run, but it will not be changed for bun build --minify, as minification intentionally alters the source code to be smaller.

@paperdave paperdave closed this as not planned Won't fix, can't repro, duplicate, stale Sep 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working transpiler parser || printer
Projects
None yet
Development

No branches or pull requests

3 participants