Repository: TypeScript
Issue: Feature Request: Ability to opt out of liveBinding with exports of const values
Labels: Suggestion,Awaiting More Feedback

# Suggestion

<!--
  Please fill in each section completely. Thank you!
-->

## 🔍 Search Terms

<!--
  💡 Did you know? TypeScript has over 2,000 open suggestions!
  🔎 Please search thoroughly before logging new feature requests as most common ideas already have a proposal in progress.
  The "Common Feature Requests" section of the FAQ lists many popular requests: https://github.com/Microsoft/TypeScript/wiki/FAQ#common-feature-requests

  Replace the text below:
-->

liveBinding Object defineProperty allocation export live view

## ✅ Viability Checklist

<!--
   Suggestions that don't meet all these criteria are very, very unlikely to be accepted.
   We always recommend reviewing the TypeScript design goals before investing time writing
   a proposal for ideas outside the scope of the project.
-->
My suggestion meets these guidelines:

* [ x] This wouldn't be a breaking change in existing TypeScript/JavaScript code
* [ x] This wouldn't change the runtime behavior of existing JavaScript code
* [ x] This could be implemented without emitting different JS based on the types of the expressions
* [ x] This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, new syntax sugar for JS, etc.)
* [x ] This feature would agree with the rest of [TypeScript's Design Goals](https://github.com/Microsoft/TypeScript/wiki/TypeScript-Design-Goals).


## ⭐ Suggestion

<!-- A summary of what you'd like to see added or changed -->

opt out of liveBinding added in https://github.com/microsoft/TypeScript/pull/35967 for const values

## 📃 Motivating Example

<!--
  If you were announcing this feature in a blog post, what's a short explanation that shows
  a developer why this feature improves the language?
-->

Doing some profiling of an app I'm creating and seeing a lot of calls to the get function of Object defineProperty  that was added as part of https://github.com/microsoft/TypeScript/pull/35967. These might be optimized away when not using `--trace-allocation-stack-interval` but it would be great to not have to rely on the optimizer to do the right thing here.

I originally wanted to add a flag that would make sure that  https://github.com/microsoft/TypeScript/blob/1e65b330a71cc09065b31f1724d78e931aafed51/src/compiler/transformers/module/module.ts#L1147 doesn't unconditionally pass true here, but that would be a breaking change to existing Typescript code if the flag was used with a modifiable export (does the breaking change guideline count if someone needs to explicitly flag themselves into a behavior?)

If the exported value is const then you don't need a "live view" of it. But it's not clear if there is a good way to communicate const-ness at the time the export expression is created.

## 💻 Use Cases

<!--
  What do you want to use this for?
  What shortcomings exist with current approaches?
  What workarounds are you using in the meantime?
-->

I think I can work around this by saving the value of the re-export to a variable local to the the current script/module and using that. But that seems cumbersome.