Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
overlookmotel opened this issue Nov 6, 2024 · 1 comment · Fixed by #7200
Closed

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

overlookmotel opened this issue Nov 6, 2024 · 1 comment · Fixed by #7200
Assignees
Labels
C-bug Category - Bug

Comments

@overlookmotel
Copy link
Collaborator

overlookmotel commented Nov 6, 2024

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

@Dunqing
Copy link
Member

Dunqing commented Nov 7, 2024

Yes, we should skip non-method ObjectPropertyValue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category - Bug
Projects
None yet
2 participants