Closed Bug 1793963 Opened 2 years ago Closed 2 years ago

Code generation for class decorators

Categories

(Core :: JavaScript Engine, enhancement, P2)

enhancement

Tracking

()

RESOLVED FIXED
117 Branch
Tracking Status
firefox117 --- fixed

People

(Reporter: dminor, Assigned: dminor)

References

(Blocks 1 open bug)

Details

Attachments

(2 files)

Code generation for decorators is likely to be complicated, so we'll split it into multiple bugs. This bug covers code generation for class decorators.

Please note: in the shims and TypeScript experimental support I've seen, the order of class decorators may be backwards, compared to other types of decorators.

:-) TypeScript 5 nightlies seem to get the ordering of class decorators from top to bottom, rather than from bottom to top as comment 1 shows. I think TS5 has it right.

OK, I really need to apologize, because after a year, I finally understand that decorators running from bottom to top is desirable. The reasoning has to do with the classes they return.

For class decorators which can return a new class, top-to-bottom implies the earliest decorator returns the outermost class:

class C extends B {
}

class B extends A {
}

class A {
}

This would be like:

@C
@B
class A {
}

That's why class decorators run backwards, from bottom to top.

I think the appropriate punishment for so much bug spam is to make me write the class decorators documentation on developer.mozilla.org.

Assignee: nobody → dminor
Status: NEW → ASSIGNED

We currently synthesize a while loop to process initializers added by decorators, but this
while loop doesn't really have a location in the input source, so we fake it. This adds
a version of WhiteEmitter::Cond that does not take source coordinates to avoid
triggering assertions about the coordinate validity.

Attachment #9344915 - Attachment description: Bug 1793963 - Add version of WhileEmitter::Cond without source coordinates; r=arai → Bug 1793963 - Add InternalWhileEmitter; r=arai
Pushed by dminor@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/d40ced9b1d57 Add InternalWhileEmitter; r=arai https://hg.mozilla.org/integration/autoland/rev/b91fdb9d2883 Add bytecode generation for class decorators; r=arai
Status: ASSIGNED → RESOLVED
Closed: 2 years ago
Resolution: --- → FIXED
Target Milestone: --- → 117 Branch
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: