oxc-project / oxc-project/backlog

Add separate variants to `ObjectPropertyKind` for methods, getters and setters

Open
#142 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
No language data
Stars
7
Forks
0
PR merge metrics
No merged PRs in 30d

Description

https://github.com/oxc-project/oxc/issues/7175 demonstrates that it's easy to confuse a function which is the property value of an object expression with an object method. i.e. to conflate these 2:

obj = {
    foo() {}
};

obj = {
    foo: function() {}
};

We could avoid this confusing by changing ObjectPropertyKind to have separate variants for methods, getters and setters.

Current:

pub enum ObjectPropertyKind<'a> {
    // This variant can be either a property or a method
    ObjectProperty(Box<'a, ObjectProperty<'a>>),
    SpreadProperty(Box<'a, SpreadElement<'a>>),
}

Proposed:

pub enum ObjectPropertyKind<'a> {
    ObjectProperty(Box<'a, ObjectProperty<'a>>),
    SpreadProperty(Box<'a, SpreadElement<'a>>),
    Method(Box<'a, ObjectMethod<'a>>),
    Getter(Box<'a, ObjectMethod<'a>>),
    Setter(Box<'a, ObjectMethod<'a>>),
}

pub struct ObjectProperty<'a> {
    pub span: Span,
    // pub kind: PropertyKind, <-- removed
    pub key: PropertyKey<'a>,
    pub value: Expression<'a>,
    pub init: Option<Expression<'a>>, // for `CoverInitializedName`
    // pub method: bool, <-- removed
    pub shorthand: bool,
    pub computed: bool,
}

pub struct ObjectMethod<'a> {
    pub span: Span,
    pub key: PropertyKey<'a>,
    pub func: Function<'a>,
    pub computed: bool,
}

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Read the ObjectPropertyKind, ObjectProperty, and ObjectMethod definitions shown in the issue, then trace how the existing variants and fields are constructed and consumed. Done means methods, getters, setters, property values, and spread properties have the distinct representations proposed, with the removed fields no longer needed.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, rust
Domain
compilers
Issue type
Refactor
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.