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.
See #2729, #1163, #3990
Committed 3+ years ago:
https://github.com/facebook/flow/blame/f050d4d850209027ff47500247f6e33b7ec51d4c/src/parser/flow_lexer.ml#L851-L853
(* TODO: Use [Symbol.iterator] instead of @@iterator. *)
| "@@iterator"
| "@@asyncIterator" ->
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); }" 1As documented in the ES spec well-known symbols are using
@@namenotation to refer to them in the spec, not as actual syntax usable in the language.See #2729, #1163, #3990
Committed 3+ years ago:
https://github.com/facebook/flow/blame/f050d4d850209027ff47500247f6e33b7ec51d4c/src/parser/flow_lexer.ml#L851-L853