Skip to content

Support well-known symbols, deprecating @@property hack #8321

@Beanow

Description

@Beanow

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" ->

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions