Skip to content

Instantly share code, notes, and snippets.

@amol- amol-/babelfilter.py
Last active Oct 29, 2015

Embed
What would you like to do?
WebAssets Filter to compile ES6 to ES5 using DukPY and BabelJS
# -*- coding: utf-8 -*-
from __future__ import absolute_import, print_function
from webassets.filter import Filter
__all__ = ('BabelJS',)
# NOTE: When using the BabelJS compiler for code
# that needs to run in the browser make sure to add
# https://cdnjs.cloudflare.com/ajax/libs/babel-core/4.6.6/browser-polyfill.js
class BabelJS(Filter):
"""WebAssets filter to compile ES6 to ES5 using DukPY.
can be registered in WebAssets using::
import webassets.filter
webassets.filter.register_filter(BabelJS)
it will be available as ``babeljs``
"""
name = 'babeljs'
max_debug_level = None
def setup(self):
try:
import dukpy
except ImportError:
raise EnvironmentError('The "dukpy" package is not installed.')
else:
self.dukpy = dukpy
super(BabelJS, self).setup()
def input(self, _in, out, **kw):
src = self.dukpy.babel_compile(_in.read())
out.write(src)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.