flexxui / pscript

Python to JavaScript compiler
http://pscript.readthedocs.io
BSD 2-Clause "Simplified" License
256 stars 25 forks source link

Add JS Set #60

Open jayvdb opened 3 years ago

jayvdb commented 3 years ago

Fixes https://github.com/flexxui/pscript/issues/24

jayvdb commented 3 years ago

I expect that I have missed some obvious things, and that the implementation is not efficient esp using Array.from unnecessarily. I'm happy to amend this based on guidance from people who know the codebase better, for feel free to merge and fix it if that is less effort for the maintainers. I know that there are still some fairly basic scenarios not covered, e.g. the older syntax set([1]) | set([1]) doesn't trigger op_set_*, and len(set()) doesnt work just like len({}) doesnt work for dict. Operators -, + and various >/</>=/<= probably are not working. I'm hoping to get feedback on this objective, structure and style before fleshing this out further.

jayvdb commented 3 years ago

@almarklein , could you approve the workflow for this please.

almarklein commented 3 years ago

We can add difference, intersection et al. in parser3.py to trigger the functions you added to the stdlib.

almarklein commented 3 years ago

Thanks for this! You seem to have found your way around the codebase well, and also added tests. Nice!

This looks good. I added few comments. I think we should drop the operators for literals to avoid confusion, but we could add support for e.g. some_set.difference(). Fine if you want to leave that for another PR/day/person :) We should probably document the limitations for set in the docs too.