Skip to content

[Bug]: Compilation errors when tracked values are assigned to class members #476

@sreekar339339

Description

@sreekar339339

Issue Category

Compilation Bug

Bug Description

Error: [Ripple] Cannot set properties of undefined (setting 'tracking')

export class UndoRedoState {
  constructor(val) {
    this.history = #[];
    this.currentIdx = track(-1);
    this.currentState = track(() => this.history[this.@currentIdx]);
    this.canUndo = track(() => this.@currentIdx > 0);
    this.canRedo = track(() => this.@currentIdx < this.history.length - 1);
    this.canReset = track(() => this.@canUndo || this.@canRedo);
    this.length = track(() => this.history.length);
    this.isAtLatestState = track(() => this.@currentIdx === this.history.length - 1);
    this.state = val;
  }

  get state() {
    return this.@currentState;
  }

  set state(val) {
    if (!this.@isAtLatestState) this.history.splice(this.@currentIdx + 1);
    this.history[++this.@currentIdx] = val;
  }

  undo() {
    if (!this.@canUndo) return;
    this.@currentIdx--;
  }

  redo() {
    if (!this.@canRedo) return;
    this.@currentIdx++;
  }

  goto(idx) {
    this.@currentIdx = idx;
  }

  reset() {
    if (!this.@canReset) return;
    this.@currentIdx = 0;
    this.history.splice(1);
  }

  toString() {
    return JSON.stringify({
      history: this.history,
      currentIdx: this.@currentIdx,
      currentState: this.@currentState,
    }, null, 2);
  }
}

Error is seen because Ripple is bugging out when compiling this class

Reproduction Steps

Playground repo link

Environment

Additional Context

No response

Checklist

  • I've searched for existing issues
  • I'm willing to help implement a fix

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions