Skip to content

Conversation

@aapoalas
Copy link
Member

@aapoalas aapoalas commented Oct 3, 2024

With this silly lump of code, Nova now supports field initializers with default constructors.

Field initializers with derived class ECMAScript constructors do not yet work because the initializers are incorrectly run at the very beginning of the ECMAScript constructor instead of as the last step of the super() call. Fixing this wouldn't be too big of a deal but the simple fix won't fix cases like:

let counter = 0;
class Foo extends Bar {
  field = counter++;
  constructor(counter) {
    super();
    console.log(counter);
  }
}

console.log(new Foo(100).field);

Instead of logging 100 and then 0, this would instead log 100 twice because the field initializer code would incorrectly use the counter parameter. It seems likely that I will need to add proper ECMAScriptConstructorFunction variants after all. Luckily now the variants are at least a little less painful to add.

@aapoalas aapoalas force-pushed the feat/ecmascript-class-constructor-functions branch from a37ef64 to 457e8b3 Compare October 5, 2024 14:21
@aapoalas aapoalas merged commit 50414fa into main Oct 8, 2024
@aapoalas aapoalas deleted the feat/ecmascript-class-constructor-functions branch October 8, 2024 13:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants