-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Open
Labels
Description
This issue has existed for quite a while and means we're asked to use an undocumented hack, and write JavaScript which wouldn't run outside of a Flow context.
$ node -e "for (const x of [1][Symbol.iterator]()) { console.log(x); }"
1
$ node -e "for (const x of [1].@@iterator()) { console.log(x); }"
[eval]:1
for (const x of [1].@@iterator()) { console.log(x); }
^
SyntaxError: Invalid or unexpected token
$ node -e "for (const x of [1]['@@iterator']()) { console.log(x); }"
[eval]:1
for (const x of [1]['@@iterator']()) { console.log(x); }
^
TypeError: [1].@@iterator is not a function or its return value is not iterable
As documented in the ES spec well-known symbols are using @@name
notation to refer to them in the spec, not as actual syntax usable in the language.
Committed 3+ years ago:
(* TODO: Use [Symbol.iterator] instead of @@iterator. *)
| "@@iterator"
| "@@asyncIterator" ->
shine1594