Manually decode JS source code

This commit is contained in:
Alessandro Molina 2018-04-09 23:44:23 +02:00
parent d769651e24
commit 58b2eb5de7
2 changed files with 4 additions and 4 deletions

View File

@ -9,9 +9,9 @@ def babel_compile(source, **kwargs):
presets = kwargs.get('presets')
if not presets:
kwargs['presets'] = ["es2015"]
with open(BABEL_COMPILER, 'r') as babel_js:
with open(BABEL_COMPILER, 'rb') as babel_js:
return evaljs(
(babel_js.read(),
(babel_js.read().decode('utf-8'),
'var bres, res;'
'bres = Babel.transform(dukpy.es6code, dukpy.babel_options);',
'res = {map: bres.map, code: bres.code};'),

View File

@ -6,9 +6,9 @@ COFFEE_COMPILER = os.path.join(os.path.dirname(__file__), 'jsmodules', 'coffeesc
def coffee_compile(source):
"""Compiles the given ``source`` from CoffeeScript to JavaScript"""
with open(COFFEE_COMPILER, 'r') as coffeescript_js:
with open(COFFEE_COMPILER, 'rb') as coffeescript_js:
return evaljs(
(coffeescript_js.read(),
(coffeescript_js.read().decode('utf-8'),
'CoffeeScript.compile(dukpy.coffeecode)'),
coffeecode=source
)