keithamus / proposal-object-freeze-seal-syntax

A JavaScript TC39 proposal for Object.freeze & Object.seal syntax
https://www.keithcirkel.co.uk/object-freeze-seal-syntax
59 stars 8 forks source link

"Freezing an functions destructured options bag" example seems incorrect #7

Closed msegado closed 6 years ago

msegado commented 6 years ago

As written, the new syntax example contains what look like implementation details (including the _ref1 variable), and the desugared version uses let instead of const... I'm guessing these were just copy/paste/editing errors and that it was intended to be more like the following?

function ajax({# url, headers, onSuccess #}) {
  url = new URL(url) // throws TypeError('cannot assign to const `url`')
  fetch(url, { headers }).then(onSuccess)
}
ajax({ url: 'http://example.com', onSuccess: console.log })

...desugars to...

function ajax(_ref1) {
  const _ref2 = Object.seal({ url: undefined, headers: undefined, onSuccess: undefined }) // seal now, const later
  Object.assign(_ref2, _ref1)
  const url = _ref2.url
  const headers = _ref2.headers
  const onSuccess = _ref2.onSuccess

  url = new URL(url) // throws TypeError('cannot assign to const `url`')
  fetch(url, { headers }).then(onSuccess)
}
ajax({ url: 'http://example.com', onSuccess: console.log })
keithamus commented 6 years ago

Hey @msegado thanks for the issue.

You're absolutely right! This looks like a copy paste error. How would you like to submit a PR correcting this?

msegado commented 6 years ago

Sure, thanks for the chance to contribute... just opened a PR.