Don't warn about undefined properties when destructuring with default values

RESOLVED FIXED in Firefox 61

Status

()

enhancement
P3
normal
RESOLVED FIXED
Last year
Last year

People

(Reporter: kmag, Assigned: kmag)

Tracking

unspecified
mozilla61
Points:
---

Firefox Tracking Flags

(firefox61 fixed)

Details

Attachments

(1 attachment)

Assignee

Description

Last year
These warnings come up all the time in our test output. When we destructure with a default value for a missing property, e.g.:

  let obj = {};
  let {foo = 0} = obj;

We get an undefined property warning for `obj.foo`, even though we provide a default value for it. The NativeObject Detecting checks should handle this case, and treat that as a valid detection access.
Jason, do you think we should ignore the "undefined property" warnings when destructing objects?
Flags: needinfo?(jorendorff)
If this patch lands, bug 1300416 can be closed, too.
Assignee

Comment 4

Last year
(In reply to Nicolas B. Pierron [:nbp] {backlog: ~36} from comment #2)
> Jason, do you think we should ignore the "undefined property" warnings when
> destructing objects?

To be clear, this only ignores properties that have default values. I.e.,

  let {foo = 0, bar} = {};

will warn for `bar` but not `foo`.

Comment 5

Last year
mozreview-review
Comment on attachment 8969150 [details]
Bug 1455179: Support destructuring with default values in undefined property detection checks.

https://reviewboard.mozilla.org/r/237866/#review244164

Thanks for this patch, it does fix some missing corner cases implied by the original comments.
Attachment #8969150 - Flags: review?(nicolas.b.pierron) → review+
Flags: needinfo?(jorendorff)
Priority: -- → P3
Assignee

Comment 6

Last year
https://hg.mozilla.org/integration/mozilla-inbound/rev/219afe052ae3a80b1da61d60ade56d73af0b0ca2
Bug 1455179: Support destructuring with default values in undefined property detection checks. r=nbp

Comment 7

Last year
bugherder
https://hg.mozilla.org/mozilla-central/rev/219afe052ae3
Status: NEW → RESOLVED
Closed: Last year
Resolution: --- → FIXED
Target Milestone: --- → mozilla61
Duplicate of this bug: 1300416
Too late, but yes, this was the right call.
You need to log in before you can comment on or make changes to this bug.