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

bugfix: consider TS' target in call to parseRuntime() #2687

Closed
wants to merge 1 commit into from

Conversation

nettybun
Copy link

Closes #2628

Currently esbuild emits ||= even when TS target is set to ES6:

$ echo 'var a = { a:1 }; window.xyz ||= a; export default { b:2, ...a }' | ./esbuild --loader=ts --tsconfig-raw='{"compilerOptions": { "target": "es6" }}'
[...]
var __spreadValues = (a2, b) => {
  for (var prop in b ||= {})
    [...]
  return a2;
};
var a = { a: 1 };
window.xyz || (window.xyz = a);
export default __spreadValues({ b: 2 }, a);

This PR fixes the output to lower ||= into b || (b = {}):

$ echo 'var a = { a:1 }; window.xyz ||= a; export default { b:2, ...a }' | ./esbuild --loader=ts --tsconfig-raw='{"compilerOptions": { "target": "es6" }}'
[...]
var __spreadValues = (a2, b) => {
  for (var prop in b || (b = {}))
   [...]
  return a2;
};
var a = { a: 1 };
window.xyz || (window.xyz = a);
export default __spreadValues({ b: 2 }, a);

Disclaimer: I've never written Go and I debugged this with a dozen fmt.Println() calls. Sorry I'm not up for writing tests. Also see PR comment about the cache key.

Comment on lines +2490 to +2492
// TODO: Safe to use a pointer here? Is the target itself easier/safer?
// tsTargetValue *config.TSTarget.value?
tsTarget *config.TSTarget
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please review/edit this line - I'll defer to you on whether an ES version number like 2015 is more appropriate than a pointer.

@nettybun
Copy link
Author

@evanw Is this ok to be merged? My company is patching esbuild to workaround it but would prefer official upstream release. Thank you! 👏

@nettybun nettybun changed the title Consider TypeScript's target in parseRuntime() bugfix: consider TS' target in call to parseRuntime() Nov 27, 2022
@evanw
Copy link
Owner

evanw commented Jul 14, 2023

I’m closing this PR as #2628 has been closed. The target field of tsconfig.json no longer affects esbuild’s syntax transforms.

@evanw evanw closed this Jul 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

target in tsconfig doesn't affect esbuild's runtime library
2 participants