refactor(transformer/class-properties): comments about shorter output (#7976)

Add TODO comments about how output could be shorter.
This commit is contained in:
overlookmotel 2024-12-17 19:21:39 +00:00
parent 4ea90d4acd
commit ff9d1b35d7

View file

@ -471,7 +471,7 @@ impl<'a, 'ctx> ClassProperties<'a, 'ctx> {
assign_expr.operator = AssignmentOperator::Assign;
assign_expr.right = ctx.ast.expression_binary(SPAN, prop_obj, operator, value);
} else if let Some(operator) = operator.to_logical_operator() {
// `Class.#prop &&= value` -> `_prop._ && (_prop._ = 1)`
// `Class.#prop &&= value` -> `_prop._ && (_prop._ = value)`
let span = assign_expr.span;
assign_expr.span = SPAN;
assign_expr.operator = AssignmentOperator::Assign;
@ -518,6 +518,9 @@ impl<'a, 'ctx> ClassProperties<'a, 'ctx> {
// `object.#prop += value`
// -> `_prop._ = _assertClassBrand(Class, object, _assertClassBrand(Class, object, _prop)._ + value)`
// TODO(improve-on-babel): Are 2 x `_assertClassBrand` calls required?
// Wouldn't `_prop._ = _assertClassBrand(Class, object, _prop)._ + value` do the same?
// `_assertClassBrand(Class, object, _prop)._`
let get_expr = self.create_assert_class_brand_underscore(
class_ident,
@ -535,6 +538,9 @@ impl<'a, 'ctx> ClassProperties<'a, 'ctx> {
// `object.#prop &&= value`
// -> `_assertClassBrand(Class, object, _prop)._ && (_prop._ = _assertClassBrand(Class, object, value))`
// TODO(improve-on-babel): Are 2 x `_assertClassBrand` calls required?
// Wouldn't `_assertClassBrand(Class, object, _prop)._ && _prop._ = value` do the same?
// `_assertClassBrand(Class, object, _prop)._`
let left = self.create_assert_class_brand_underscore(
class_ident,
@ -748,9 +754,10 @@ impl<'a, 'ctx> ClassProperties<'a, 'ctx> {
let object = ctx.ast.move_expression(&mut field_expr.object);
if is_static {
// TODO: If `object` is reference to class name, and class is declaration, use shortcuts:
// If `object` is reference to class name, and class is declaration, use shortcuts:
// `++Class.#prop` -> `_prop._ = ((_Class$prop = _prop._), ++_Class$prop)`
// `Class.#prop++` -> `_prop._ = (_Class$prop = _prop._, _Class$prop2 = _Class$prop++, _Class$prop), _Class$prop2`
// TODO(improve-on-babel): These shortcuts could be shorter - just `_prop._++` / `++_prop._`.
// Or does that behave slightly differently if `Class.#prop` is an object with `valueOf` method?
// TODO(improve-on-babel): No reason not to apply these shortcuts for class expressions too.
@ -762,6 +769,9 @@ impl<'a, 'ctx> ClassProperties<'a, 'ctx> {
// )
// ```
// TODO(improve-on-babel): Are 2 x `_assertClassBrand` calls required?
// Wouldn't `++_assertClassBrand(C, object, _prop)._` do the same?
// Check if object (`object` in `object.#prop`) is a reference to class name
// TODO: Combine this check with `duplicate_object`. Both check if `object` is an identifier,
// and look up the `SymbolId`.