Skip to content

Commit 530f496

Browse files
committed
Replace JS-implemented esprima-serializer with escodegen python package, which is claimed to be a rewrite of jscodegen into Python.
1 parent 8d2876b commit 530f496

File tree

3 files changed

+9
-43
lines changed

3 files changed

+9
-43
lines changed

README.md

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ Installation
7878
Opener requires:
7979

8080
* Python ≥ 3.9
81-
* Node.js ≥ 12
8281

8382
Clone the repository and enter the directory:
8483

@@ -95,12 +94,6 @@ verified to work):
9594
pip3 install -r requirements.txt
9695
```
9796

98-
And install the required NPM packages:
99-
100-
```bash
101-
npm install
102-
```
103-
10497
Then, you can run `./opener.py`.
10598

10699
Usage

opener/__main__.py

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -63,18 +63,6 @@ def usage(*, exit: bool, error: bool):
6363
sys.exit(int(error))
6464

6565

66-
def run_codegen_js(ast_dict: dict):
67-
path = pkg_resources.resource_filename(__name__, "codegen.js")
68-
proc = subprocess.Popen(
69-
["node", path],
70-
stdin=subprocess.PIPE,
71-
encoding="utf8",
72-
)
73-
json.dump(ast_dict, proc.stdin, cls=JsonEncoder)
74-
proc.stdin.close()
75-
proc.wait()
76-
77-
7866
def main():
7967
positional_args = []
8068
temp_prefix = DEFAULT_TEMP_PREFIX
@@ -147,7 +135,15 @@ def main():
147135
else:
148136
if verbose:
149137
print("Formatting code...", file=sys.stderr)
150-
run_codegen_js(ast_dict)
138+
139+
try:
140+
import escodegen
141+
except ImportError:
142+
from warnings import warn
143+
warn("jscodegen has some issues and produces incorrect results (at least the version in the upstream repo when this remark was added here), better use https://github.com/0o120/escodegen-python")
144+
import jscodegen as escodegen
145+
146+
print(escodegen.generate(ast_dict))
151147

152148

153149
if __name__ == "__main__":

opener/codegen.js

Lines changed: 0 additions & 23 deletions
This file was deleted.

0 commit comments

Comments
 (0)