Emit does not preserve empty lines
Hi,
TS Version: 1.1
Given
function foo() {
var x = 10;
var y = 11;
}
We used to get
function foo() {
var x = 10;
var y = 11;
}
In the new compiler the line break is missing
function foo() {
var x = 10;
var y = 11;
}
(Both compilers removed the first empty line, but the new compiler has gone a step further.)
This can affect the experience when debugging JavaScript in the browser.
I would also like to see this implemented, with a few specific reasons in mind:
- Consistency with general design philosophy per NoelAbrahams' comment above
- Ciantic's comment about needing to deliver JS elsewhere
- Being able to cleanly compare JS generated through TS and JS that existed before, where demonstrating a close match is important to adoption
- Not having long lines requiring horizontal scrolling in the emitted code, where the source included line breaks to make things neat and beautiful and meeting linter/style specs (also commented on above)
- Being able to continue working with transpiled JS if all these overhead costs of TypeScript become too much; anticipating difficulty here creates lock-in costs that raise barriers to adoption in the first place.
This PR, discussed in the 3.9 release notes, show code actions preserving newlines; why can't the emitted code do something similar?
Are there any updates for almost 10 years? I would like to be able to configure preserving new lines
I'm changing this to Won't Fix. Reasons:
- This has obviously not been a key blocker for anyone
- Of all the "keep trivia" problems we have, this is surely the lowest-priority among them
- At this point, many alternative transpilers with different configurable behaviors around comments/whitespace exist; if you need truly need newline preservation, you can use one of those
- Performance remains top-of-mind for us and anything that makes emit slower needs to be carrying a lot more value than newline preservation.
At this point, many alternative transpilers with different configurable behaviors around comments/whitespace exist
Does anyone know of a good option for this?
At this point, many alternative transpilers with different configurable behaviors around comments/whitespace exist
Does anyone know of a good option for this?
It depends on your exact needs. There are several suggestions in this issue and a list of other transpilers is as follows. Note that this list hasn't been sanitized for the specific requirement:
- tsup (uses esbuild or swc depending on config)
- esbuild
- swc
- babel (with @babel/plugin-typescript)
- rollup (with @rollup/plugin-typescript or rollup-plugin-typescript2)
- turbopack