Created
August 6, 2011 22:02
-
-
Save scribu/1129798 to your computer and use it in GitHub Desktop.
Javascript To Coco
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# remove useless punctuation | |
s/;$//g | |
s/,$//g | |
# comments start with # | |
s:// :# :g | |
# var is out | |
s/var //g | |
/var$/d | |
# function definitions | |
s/function *(\(.*\)) {/(\1) ->/g | |
s/() ->/->/g | |
# if statements | |
s/if ( \(.*\) ) {/if \1/g | |
s/if ( \(.*\) )/if \1/g | |
/}$/d | |
# object literals don't even need brackets | |
s/, {$/,/g | |
s/({$/(/g | |
s/})$/)/g | |
# instance properties | |
s/this\./@/g | |
s/self\./@/g |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This script can be used to convert regular Javascript into Coco.
Usage example:
sed --file=coco.sed script.js > script.co