Skip to content

Commit

Permalink
Replace JS-implemented esprima-serializer with escodegen python pac…
Browse files Browse the repository at this point in the history
…kage, which is claimed to be a rewrite of `jscodegen` into Python.
  • Loading branch information
KOLANICH committed Mar 1, 2023
1 parent 8d2876b commit b8e6d5f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 36 deletions.
22 changes: 9 additions & 13 deletions opener/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,18 +63,6 @@ def usage(*, exit: bool, error: bool):
sys.exit(int(error))


def run_codegen_js(ast_dict: dict):
path = pkg_resources.resource_filename(__name__, "codegen.js")
proc = subprocess.Popen(
["node", path],
stdin=subprocess.PIPE,
encoding="utf8",
)
json.dump(ast_dict, proc.stdin, cls=JsonEncoder)
proc.stdin.close()
proc.wait()


def main():
positional_args = []
temp_prefix = DEFAULT_TEMP_PREFIX
Expand Down Expand Up @@ -147,7 +135,15 @@ def main():
else:
if verbose:
print("Formatting code...", file=sys.stderr)
run_codegen_js(ast_dict)

try:
import escodegen
except ImportError:
from warnings import warn
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")
import jscodegen as escodegen

print(escodegen.generate(ast_dict))


if __name__ == "__main__":
Expand Down
23 changes: 0 additions & 23 deletions opener/codegen.js

This file was deleted.

0 comments on commit b8e6d5f

Please sign in to comment.