Skip to content

Instantly share code, notes, and snippets.

@yorkxin
Last active March 1, 2016 09:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yorkxin/b554955d1632f41815e8 to your computer and use it in GitHub Desktop.
Save yorkxin/b554955d1632f41815e8 to your computer and use it in GitHub Desktop.
CJSX (CoffeeScript + JSX) to ES6

(Not) CJSX to ES6 converter

It does noly convert a small set of codes into ES6. You sill need to edit the file.

Usage

find ./components -name "*.cjsx" -exec ./converter.sh {} \;
s/(.+) = require[(]? ?(.+)[)]?/import \1 from \2;/
s/module.exports = /export default /
s/React.createClass//
s/ displayName: "([A-Za-z0-9]+)"/class \1 extends React.Component {/
s/@/this./g
s/ (.+): ?->/ \1 () {/
s/ (.+): \((.+)\) ?->/ \1 (\2) {/
s/\((.+)\) ->/function (\1) {/
#!/bin/sh
cjsx=$1
jsx=`echo $cjsx | sed 's/.cjsx/.jsx/'`
sed -E -f coffee2es6.sed $cjsx > $jsx
rm $cjsx
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment