Could the TypeScript compiler be adapted to allow safe use of Allman-style braces in places where it classically breaks JavaScript code? TypeScript is designed to generate idiomatic JavaScript, so the resulting braces would be generated in K&R style anyhow.
As an example:
// currently breaks in JS (and won't compile in TypeScript)
function getPerson() {
// compiler inserts semicolon after return, return executes prematurely
return
{
firstname: "Eric",
lastname: "Allman"
};
}
P.S. I'm just curious; not really interested in debating whether or not it's a "good idea" to go against generally-accepted JS practices.
What the TypeScript compiler does do is add the semi-colon, so you can see the problem - rather than waiting for the browser to implicitly add it and cause odd behaviour.
Whether this is something the community wants to add isn't something that can be answered on Stack Overflow - you would have to start a discussion on Codeplex.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With