Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make the ES6 effort available even though it is not complete #39

Open
mrdeveloperdude opened this issue Sep 3, 2021 · 1 comment
Open

Comments

@mrdeveloperdude
Copy link

mrdeveloperdude commented Sep 3, 2021

I have been scavanging the net looking for a pure python implementation of a js parser that supports ES6 for a good week now, and it is just a fluke that I found this project and this pull request: #15

I think this is the ONLY effort of it's kind, and a very important one at that. Every other package out there has a dependency on nodejs which is unacceptable for many common scenarios.

My usage of ES6 is minimal. I use a few keywords like let and const, mostly sugar really. I suspect this is the case for many users. Even if the ES6 parser effort is still incomplete it would probably do much better than the ES5 implementation for many js code collections out there.

That is why I suggest that this excellent effort is merged into main branch with a caveat that it is "beta" and "incomplete" into the main calmjs.parse and crimp pypi packages. Since it resides in it's own es6 module anyway that would be feasible.

Also, if you could guide me I would be glad to contribute to this project!

@metatoaster
Copy link
Member

Hi, while I understand your enthusiasm, there is a major risk to releasing something half-baked as users of packages typically will not read the warnings about incomplete implementation in detail, and if things were to change in the future it may result in unintended breakage in any applications that were to depend on the faulty version of the library that have been made available on PyPI. Not to mention, there are other projects out there that have a dependency on the latest version of calmjs.parse so I will not make a release that may have any impact on those projects.

That said, if you must use the version available now, you may install the code made available under that pull request using the following:

$ pip install git+https://github.com/calmjs/calmjs.parse.git@refs/pull/15/merge#egg=calmjs.parse
Collecting calmjs.parse
  Cloning https://github.com/calmjs/calmjs.parse.git (to revision refs/pull/15/merge) to ...
...
Successfully installed calmjs.parse-1.3.0.dev0 ply-3.11

Then this may be done:

>>> from calmjs.parse.parsers import es2015
>>> es2015.parse('var hello = `world`;')
<ES2015Program @1:1 ?children=[
  <VarStatement @1:1 ?children=[
    <VarDecl @1:5 identifier=<Identifier ...>, initializer=<TemplateLiteral ...>>
  ]>
]>

None of the newest modules are documented and the features as implemented may shift over time, not to mention I have not rebase the pull request in quite some time so the version available and number may change once I get the real version 1.3.0 out (probably some time before end of November when I get the code to dict conversion done - I really don't have much time to work on this project now).

Also note that const and let keywords have not actually been incorporated into the parser yet, as the whole template literal and generator expressions are the more annoying part of the specification that I was dealing with.

>>> es2015.parse('const hello = "world";')
Traceback (most recent call last):
...
calmjs.parse.exceptions.ECMASyntaxError: Unexpected 'hello' at 1:7 after 'const' at 1:1
>>> 

While at first glance there may not seem to be any connection of those let and const keywords with the more problematic parts of the ECMAScript specification, this is a very naive stance to take - I don't quite fully grasp what kind of "safe" shortcuts may be taken in the generator expressions, that's one of the reason why I haven't touched this construct yet (not to mention I may need to rebuild the lexer rather than reusing the existing ES5 one taken mostly verbatim from slimit).

For a pure Python implementation of ES2015 and higher parser, please consider trying out the Python port of esprima, which does already support the parsing into a structure that may then be interrogated, and has no dependency for nodejs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants