Adding Post-Processor
This commit is contained in:
parent
4535821e8c
commit
976f2d06e5
@ -5,6 +5,7 @@ __copyright__ = 'Copyright 2022 M.Karkowski'
|
||||
__version__ = '0.1.0'
|
||||
|
||||
from .logger import get_logger
|
||||
from .post_processor import post_process
|
||||
from .js import get_parser as get_parser_js, transform as transform_js
|
||||
from .ts import get_parser as get_parser_ts, transform as transform_ts
|
||||
from .main import main
|
27
py-helpers/prepare_code/post_processor.py
Normal file
27
py-helpers/prepare_code/post_processor.py
Normal file
@ -0,0 +1,27 @@
|
||||
|
||||
|
||||
replacers = {
|
||||
"console.log": "print",
|
||||
"console.error": "print",
|
||||
"Error(": "Exception(",
|
||||
"true": "True",
|
||||
"false": "False",
|
||||
"JSON.stringify": "json.dumps",
|
||||
"JSON.parse": "json.loads"
|
||||
}
|
||||
|
||||
def post_process(code: str) -> str:
|
||||
""" Post processes the code. This results in adapting the code by replacing default
|
||||
elements like console.log
|
||||
|
||||
Args:
|
||||
code (str): The code that have to be adapted
|
||||
|
||||
Returns:
|
||||
str: The adapted code
|
||||
"""
|
||||
|
||||
for org, new in replacers.items():
|
||||
code = code.replace(org, new)
|
||||
|
||||
return code
|
Loading…
Reference in New Issue
Block a user