question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Inline variable doesn't work with destructured variable declarations

See original GitHub issue

Describe 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

image

Additional information

  • Version of the extension impacted: v0.4.0

Thank you for this amazing project btw ❤️

Progression

  • Handle destructured object patterns #34
  • Handle destructured array patterns #38

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
nicoespeoncommented, Sep 18, 2019

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 👍

1reaction
nicoespeoncommented, Sep 27, 2019

@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 👍

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found