class getter shorthand?

Has this been discussed before?

I'm imagining these two classes are behaviorally the exact same:

class Renderer extends Component {
  @cached
  get result() {
    return compileHBS(this.args.input;
  }
  
  get component () {
    return this.result.component;
  }
  
  get error() {
    return this.result.error;
  }
  
  get name() {
    return this.result.name;
  }
}

and

class Renderer extends Component {
  // syntax tbd, prior art: Svelte 
  //   though they start a line with $: to have this meaning
  @cached result := compileHBS(this.args.input);
  
  component := this.result.component;
  error := this.result.error;
  name := this.result.name;
}

The main benefit is primarily for what-would-be-one-line getters, which provides a way to define aliases for other data in way that doesn't get burned into the class instance, like a normal property would

class Renderer extends Component {
  // set once, never references this.result ever again
  component = this.result.component;
}

using getters allows us to reference component on this.result every time the getter is accessed.. it would be great to have a shorthand for this :)

thoughts?

There's this very recent discussion: Shorthand For Inline Functions.

The decorators proposal also includes an accessor modifier for fields which will automatically define getter and setter methods for the field, moving the value to a private backing field.

class Example {
  accessor myBool = false;
}

This would include both the getter and setter, though. The grouped accessors proposal would provide syntax for specifying only one.

class Example {
  accessor myBool { get; } = false;
}

So this would propose:

class Renderer extends Component {
  @cached get result() compileHBS(this.args.input);

  get component() this.result.component;
  get error() this.result.error;
  get name() this.result.name;
}

seems ok -- it's very clear that everything is still a getter and follows a similar pattern that inline ifs use.
it's only 3 more characters than := :upside_down_face:

combining decorators with accessors seems like it would be more code than today's vanilla getters. While the next iteration of the decorator proposal would change subtle things about my result getter, I don't want to have to use a getter for what-would-be-a-one-line-getter. :thinking: