建议
🔍 搜索词
翻转操作符,翻转操作符,重构
✅ 可实现性检查清单
我的建议满足以下准则:
- 这不会对现有的TypeScript/JavaScript代码造成破坏性的更改
- 这不会改变现有JavaScript代码的运行时行为
- 这可以在不根据表达式的类型发出不同的JS的情况下实现
- 这不是一个运行时特性(例如库功能,带有JavaScript输出的非ECMAScript语法,JS的新语法糖等)
- 这个特性将与TypeScript's Design Goals的其他部分保持一致。
⭐ 建议
为交换左右操作数和更新操作符(如果需要)实现翻转操作符重构。
这个小功能将使一些需要复制粘贴操作数和操作符的重构变得更加容易。
📃 动机示例
之前:
// harder to understand
if (5 < position) {
// ...
}
之后:
// much easier
if (position > 5) {
// ...
}
1条答案
按热度按时间yr9zkbsy1#
@RyanCavanaugh Just to clarify, the motivation here is to help developer flip pieces of code without having to copy/paste and rewriting the code. For example we used to write comparisings in the following way:
variable > literal value
, because it is easier to understand. Code example:The refactoring activation range is operator only (
>
), so it shouldn't be annoying for existing users. So this refactoring can be small, but really nice addition to TypeScript IDE possibilities.