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

docs: Add example with object pattern to computed-property-spacing #14004

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions docs/rules/computed-property-spacing.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ var a = "prop";
var obj = {
[a]: "value" // computed property key in object literal (ECMAScript 6)
};

// applies to the spacing for dynamic keys (computed property key) when destructuring objects.
const ({ [a]: someProp } = obj); // someProp now maps to the value of prop.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Parentheses are invalid syntax here:

Suggested change
const ({ [a]: someProp } = obj); // someProp now maps to the value of prop.
const { [a]: someProp } = obj; // someProp now maps to the value of prop.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait, I think I did not read this right, that syntax looks wrong, that works, when assigning to a delcared variable:

let someProp;
({ [a]: someProp } = obj);

but if we are declaring a new variable:

const { [a]: someProp } = obj;

this is mentioned in this section: Assignment without declaration

Comment on lines +17 to +19
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// applies to the spacing for dynamic keys (computed property key) when destructuring objects.
const ({ [a]: someProp } = obj); // someProp now maps to the value of prop.
var { [a]: x } = obj; // computed property key in object destructuring pattern (ECMAScript 6)

```

## Rule Details
Expand Down