node-swift
node-swift copied to clipboard
Support implementing Symbol-based EcmaScript protocols like Iterable
This adds a set of features that allow Swift developers to implement protocols using Symbols, like Iterable:
- Add helpers to
NodeSymbolto access well-know symbols likeSymbol.iterator, or the global symbol registry likeSymbol.for("user.land.protocol"). @NodeName(replacementName)renames members exposed with@NodeClass+@NodePropertyor@NodeMethod. To implement a symbol-based protocol, pass the symbol as the replacementName.- Implement
NodeIteratorclass to support the Iterable protocol. An example iterable is included in an integration test.
Individual commits have some more details.
Discussion points:
- Should the renaming functionality
@NodeNamebe better as a parameter for the existing@NodeMethod/@NodePropertymacros? It was easier to implement as a new macro for me because I'm new to Swift. - I avoided using macros to implement
NodeIteratorsince I didn't see other uses within the library. Should I convert that class to a@NodeClassmacro? Since there's only one method exposed, it's not much difference in code size in this instance. - The
NodeIteratorclass is used for supporting Swift developers writing Iterable classes to Node, not for consuming Node iterators in Swift, although that could also be useful as well. Should this implementation do both? Or is this kind of thing out of scope for the node-swift library? - Code style: I tried to follow four-space indents as best I could. Is there an auto-formatting setup you use? My editor tried its best to really mess things up, and it would be easier to contribute if there was some
swift-formatorswiftformattool set up.