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

feat: support useless literal object expansion #1411

Open
ahaoboy opened this issue Jan 30, 2025 · 2 comments
Open

feat: support useless literal object expansion #1411

ahaoboy opened this issue Jan 30, 2025 · 2 comments

Comments

@ahaoboy
Copy link

ahaoboy commented Jan 30, 2025

const b = {};

const a = {
  ...{
    x: false,
  },
  ...b,
};

oxlint

const b = {};

const a = {
  x: false,
  ...b,
};
@0f-0b
Copy link
Contributor

0f-0b commented Jan 30, 2025

There are some edge cases related to __proto__ and super. For example, the expression { ...{ __proto__: null } } is not equivalent to { __proto__: null }. Neither is { ...{ method() { return super.constructor } } } interchangeable with { method() { return super.constructor } }.

@ahaoboy
Copy link
Author

ahaoboy commented Jan 31, 2025

There are some edge cases related to __proto__ and super. For example, the expression { ...{ __proto__: null } } is not equivalent to { __proto__: null }. Neither is { ...{ method() { return super.constructor } } } interchangeable with { method() { return super.constructor } }.

It seems that oxlint has not considered this much, and this seems more suitable as a warning to remind users that there may be unnecessary overhead

const b = {};

const a = {
  ...{
    x: false,
  },
  ...b,
};

const a2 = {
  ...{
    __proto__: null
  },
  ...b,
}

const a3 = {
  ...{
    method() { return super.constructor }
  },
  ...b,
}
const b = {};

const a = {
  
    x: false,
  ...b,
};

const a2 = {
  
    __proto__: null,
  ...b,
}

const a3 = {
  
    method() { return super.constructor },
  ...b,
}

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

No branches or pull requests

2 participants