Skip to content

define for optional chaining is different from esbuild #7383

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

Closed
hi-ogawa opened this issue Nov 21, 2024 · 3 comments
Closed

define for optional chaining is different from esbuild #7383

hi-ogawa opened this issue Nov 21, 2024 · 3 comments
Assignees
Labels
C-bug Category - Bug

Comments

@hi-ogawa
Copy link
Contributor

I don't have a specific use case in mind, but I was testing a similar example from evanw/esbuild#3551 which I reported on esbuild in the past and found a minor difference/inconsistency.

reproduction: https://github.com/hi-ogawa/reproductions/tree/main/rolldown-define-optional-chain

  • input
{
  define: {
    'globalThis.process.env': '{}'
  }
}
console.log(globalThis.process.env)
console.log(globalThis.process?.env)
console.log(globalThis.process?.env.ok)
console.log((globalThis.process?.env).ok)
  • output (oxc, rolldown)
console.log({});
console.log(globalThis.process?.env);
console.log({}.ok);
console.log((globalThis.process?.env).ok);
  • output (esbuild)
var define_globalThis_process_env_default = {};
console.log(define_globalThis_process_env_default);
console.log(define_globalThis_process_env_default);
console.log(define_globalThis_process_env_default.ok);
console.log(define_globalThis_process_env_default.ok);
@hi-ogawa hi-ogawa added the C-bug Category - Bug label Nov 21, 2024
@Boshen Boshen self-assigned this Nov 21, 2024
@IWANABETHATGUY
Copy link
Contributor

Most of the part should be done with #7433 ?

@IWANABETHATGUY
Copy link
Contributor

IWANABETHATGUY commented Nov 24, 2024

The only difference should not relevant to optional chain? Because for a normal StaticMemberExpr we still will not generate a shared object, we will replace each DotDefineMemberExpr with a ObjectExpr

@hi-ogawa
Copy link
Contributor Author

Thanks for the fix!
I think we can close. I've never wondered why esbuild uses shared object, but I think that's for later when that alignment turns out to be important.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category - Bug
Projects
None yet
Development

No branches or pull requests

3 participants