Skip to content

Async function transforms mis-identifying object properties as methods #7175

@overlookmotel

Description

@overlookmotel

Stack up to #7148 contains a few places where it checks if a Function is an object method with matches!(parent, Ancestor::ObjectPropertyValue(_)). I think the code it's trying to match is:

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

But it will also match where the function is a property value, not a method:

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

I think also need a check if object_prop.method to be able to tell the difference between the two.

&& matches!(
ancestors.next().unwrap(),
Ancestor::MethodDefinitionValue(_) | Ancestor::ObjectPropertyValue(_)
) {

&& matches!(
ctx.parent(),
// `class A { async foo() {} }` | `({ async foo() {} })`
Ancestor::MethodDefinitionValue(_) | Ancestor::PropertyDefinitionValue(_)
)

&& matches!(
ctx.parent(),
// `class A { async foo() {} }` | `({ async foo() {} })`
Ancestor::MethodDefinitionValue(_) | Ancestor::ObjectPropertyValue(_)
)

Personally, I think it'd be ideal if AST didn't use ObjectProperty for both properties and methods, to avoid this confusing ambiguity. oxc-project/backlog#142

Metadata

Metadata

Assignees

Labels

C-bugCategory - Bug

Type

No type

Priority

None yet

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions