Add support for Computed / Dynamic Object Property Names
See original GitHub issueDescription
When formatting an object literal with a computed property, an undesired new line is introduced after the object’s initial curly brace.
This issue was originally filed in the vscode extension’s repo at this url: https://github.com/HookyQR/VSCodeBeautify/issues/143
Input
The code looked like this before beautification:
export default {
filesById({ files }, getters) {
return files.reduce((memo, f) => Object.assign(memo, { [f.id]: f }), {})
},
}
Expected Output
The code should not have changed after beautification:
export default {
filesById({ files }, getters) {
return files.reduce((memo, f) => Object.assign(memo, { [f.id]: f }), {})
},
}
Actual Output
The code actually looked like this after beautification:
export default {
filesById({ files }, getters) {
return files.reduce((memo, f) => Object.assign(memo, {
[f.id]: f }), {})
},
}
Steps to Reproduce
Environment
- Operating System: OS X 10.11.6
- VS Code Version: 1.12.2
- beautify Version: 1.0.2 (vscode extension)
Settings
Example:
{
"end_with_newline": true,
"indent_char": " ",
"indent_size": 4,
"indent_with_tabs": false,
"max_preserve_newlines": 2,
"wrap_line_length": 120,
"indent_body_inner_html": false,
"indent_scripts": "normal",
"wrap_attributes": "force-aligned",
"newline_between_rules": false,
"break_chained_methods": false,
"comma_first": false,
"keep_array_indentation": false,
"keep_function_indentation": false,
"operator_position": "after-newline",
"space_before_conditional": true,
"space_in_paren": false,
"space_in_empty_paren": false,
"js": {
"brace_style": "collapse,preserve-inline"
}
}
Issue Analytics
- State:
- Created 6 years ago
- Reactions:4
- Comments:13 (6 by maintainers)
Top Results From Across the Web
Is it possible to add dynamically named properties to ...
Yes. var data = { 'PropertyA': 1, 'PropertyB': 2, 'PropertyC': 3 }; data["PropertyD"] = 4; // dialog box with 4 in it alert(data....
Read more >How to Set Dynamic Object Properties using Computed ...
Here is how to set dynamic properties in JavaScript objects using the Computed Property Names feature in ES6._____Subscribe to My Channel: ...
Read more >How to use computed property names in JavaScript
A quick guide to learn how to use computed property names to dynamically create object properties in JavaScript.
Read more >Object initializer - JavaScript - MDN Web Docs - Mozilla
Computed property names ... The object initializer syntax also supports computed property names. That allows you to put an expression in brackets ...
Read more >Computed property names FTW! - codeburst
I just discovered that Javascript supports computed property names, ... being able to inject a dynamic key into an object is pretty damn...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@alexsasharegan - thanks for taking the time, that’s plenty. It is very helpful when someone goes to fix an issue like this to have links, they don’t have to be precise - close it good enough. 😄
+1 on this.
re: why it’s blocked, perhaps it makes sense to have another brace-style option all together that is more blunt / simple in approach and just preserves the brace style period.