Pyjsparser

2.7.1 · maintenance · verified Mon Apr 13

Pyjsparser is a fast JavaScript parser for Python, based on a manual translation of esprima.js. It aims to be a comprehensible JavaScript parser for Python, supporting ECMAScript 5.1 and parts of ECMAScript 6. The library is currently at version 2.7.1, with its last release dating back to April 2019, suggesting a maintenance-level release cadence rather than active development.

Warnings

Install

Imports

Quickstart

Parses a given JavaScript string into an Abstract Syntax Tree (AST).

from pyjsparser import parse

js_code = 'var message = "Hello, Pyjsparser!"; console.log(message);'
ast = parse(js_code)
print(ast)

# Example of accessing a property (structure depends on AST)
# For illustration, this may need adjustment based on the exact AST output
# if ast and ast['type'] == 'Program' and ast['body']:
#     first_statement = ast['body'][0]
#     if first_statement['type'] == 'VariableDeclaration':
#         print(f"Variable declared: {first_statement['declarations'][0]['id']['name']}")

view raw JSON →