TypeScript icon indicating copy to clipboard operation
TypeScript copied to clipboard

Fix to aggressive indentation for ternary operator #3676

Open wukongO-O opened this issue 10 months ago • 3 comments

Fixes #3676

  • This PR provides a solution to the aggressive indentation for nested conditional expressions using a specific style (issue #3676). Instead of using a one-liner, the style keeps the true branch in the same line as its associated condition but the false branch in the next line. Without the changes in this PR, the false branch gets mistakenly indented. This PR corrects the behavior by specifying this category of style in the function nodeWillIndentChild in smartindenter.ts.
  • The added unit test includes examples mentioned in the original issue and discussion.
  • The solution does not address the "different, but similar" example in the last comment on May 31, 2019. I'm not sure if it's opened as a separate issue already? Also, when I stepped through that example, it appears that the issue might be more related to how context node is assigned to child node, and how indentation, delta, node start position get inherited/recalculated with nested, mixed types.
  • As of now, the code is up to date and all tests, including the new test, passed locally.

wukongO-O avatar Mar 15 '25 23:03 wukongO-O

This PR doesn't have any linked issues. Please open an issue that references this PR. From there we can discuss and prioritise.

typescript-bot avatar Mar 15 '25 23:03 typescript-bot

@microsoft-github-policy-service agree

wukongO-O avatar Mar 15 '25 23:03 wukongO-O

This PR doesn't have any linked issues. Please open an issue that references this PR. From there we can discuss and prioritise.

https://github.com/microsoft/TypeScript/issues/3676

wukongO-O avatar Mar 16 '25 00:03 wukongO-O