Inline variable doesn't work with destructured variable declarations
See original GitHub issueDescribe the scenario
“Inline variable” refactoring doesn’t work if the variable is declared via destructuring
How to reproduce
// Case 1.
// Command+Option+N ->
// Throws "I didn't found a valid code to inline from current selection 🤔" error
const { userId } = session
return messages.map(message => ({ userId }))
// Case 2.
// Command+Option+N ->
// Inlines just fine
const playerId = session.playerId
return messages.map(message => ({ playerId }))
Expected behavior
Expecting Case 1. to work
Screenshots
Additional information
- Version of the extension impacted: v0.4.0
Thank you for this amazing project btw ❤️
Progression
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (4 by maintainers)
Top Results From Across the Web
Can I pre-declare variables for destructuring assignment of ...
I understand that replacing var with let means I'm not required to pre-declare my variables and that having the let inline is valid...
Read more >Destructuring assignment - JavaScript - MDN Web Docs
The destructuring assignment syntax is a JavaScript expression that makes it possible to unpack values from arrays, or properties from objects, ...
Read more >Documentation - Variable Declaration - TypeScript
When a variable is declared using let , it uses what some call lexical-scoping or block-scoping. Unlike variables declared with var whose scopes...
Read more >Destructuring assignment - The Modern JavaScript Tutorial
It's called “destructuring assignment,” because it “destructurizes” by copying items into variables. But the array itself is not modified.
Read more >Destructuring and parameter handling in ECMAScript 6 - 2ality
If you declare variables via destructuring then you must use simple identifiers, you can't refer to object properties and array elements.
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 Free
Top 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
Hello @noway 👋
I’ve got good news: the pattern you reported is now supported 🎉 I completed the implementation to handle destructured object patterns. It should work with complex objects too (nested cases, rest element, etc.).
I’m not closing the issue yet as it still doesn’t handle destructured array patterns (e.g.
const [userId] = session
). But that should be faster to implement now that we take care of object patterns.It will be shipped in the next release (v0.8.0), on Sunday 👍
@noway as I said, implementing the array pattern was easier now that the object pattern was implemented.
It’s now fully supported. The full support with array patterns will be shipped in the next release (probably on Sunday, I tend to release a new version every Sunday 😄).
I hope that will be as helpful to you as it is to me. Thanks again for pushing it 👍