Skip to content

JS: Issue with destructuring defaults referencing variables previously destructured on the same object #252

@brettz9

Description

@brettz9

Per https://lgtm.com/projects/g/brettz9/webappfind/snapshot/3109d90b09b73d445f05fc17b71566bf38721aa7/files/executable-builder/executable.js?sort=name&dir=ASC&mode=heatmap&showExcluded=false#xddf739a1f6a2cb51:1 ,

..."Variable 'parentNode' always evaluates to false here."

However, this is not the case.

To illustrate with a simpler example, in the following code:

     var obj = {a: 5};
     var {a, b = a + 10} = obj;

...a from obj is destructured first to the local a, and it is then available to act as the default for b if b on obj is undefined (which in this case it is). As you can confirm in a modern JavaScript console, b will be 15 here because a is in fact available...

In my code, parentNode will not always evaluate to false because the local parentNode will be set based on the one present on target. In fact, it would, in my case, almost never be falsey...

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions