- Notifications
You must be signed in to change notification settings - Fork0
LOLCODE implementation with Babel macros
License
Swizec/lolcode-babel-macro
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
A fully functioning LOLCODE-to-JavaScript compiler implemented as a Babel macro. You never thought you wanted this and now here it is. You’re welcome. 🐱
Let me start by proving that this crazy contraption works 👇
https://codesandbox.io/s/github/Swizec/lolcode.macro-example
Here you have a CodeSandbox with the legendary FizzBuzz implemented in LOLCODE. A Babel macro compiles it to a JavaScript function at build-time and you use it as any ole JavaScript at runtime.
LOLCODE goes in 🐱
HAII HAS AcountITS1IM IN YRfizzbuzzUPPIN YRcountTILBOTH SAEMcountAN30I HAS AdivITSMODOFcountAN3ITRBOTH SAEM0ANdivO RLY?YA RLYVISIBLE"Fizz"MEBBEBOTH SAEM0ANMODOFcountAN5VISIBLE"Buzz"NO WAIVISIBLEcountOICIM OUTTA YRfizzbuzzKTHXBYE
JavaScript comes out ✌️
varfizzbuzz=function(stdlib){returnfunction(){varIT;varcount=1;for(;!stdlib["BOTH SAEM"](count,30);count++){var_IT=void0;vardiv=stdlib["MOD OF"](count,3);_IT=stdlib["BOTH SAEM"](0,div);if(_IT){var_IT2=void0;console.log("Fizz");}elseif(stdlib["BOTH SAEM"](0,stdlib["MOD OF"](count,5))){var_IT3=void0;console.log("Buzz");}else{var_IT4=void0;console.log(count);};};};}(lolcode_macro_dist_lolstdlib__WEBPACK_IMPORTED_MODULE_2__["default"]);
Taken from Chrome DevTools source maps. That's after Webpack and Babel do their thing. Intermediate output fromlolcode.macro
is modern JavaScript with lets and consts.
Install from NPM
$ npm install lolcode.macro
Then import and use similarly to CSS-in-JS or GraphQL
import{lolcode}from"lolcode.macro";importlolstdlibfrom"lolcode.macro/dist/lolstdlib";constfizzbuzz=lolcode`HAI I HAS A count ITS 1 IM IN YR fizzbuzz UPPIN YR count TIL BOTH SAEM count AN 30 I HAS A div ITS MOD OF count AN 3 IT R BOTH SAEM 0 AN div O RLY? YA RLY VISIBLE "Fizz" MEBBE BOTH SAEM 0 AN MOD OF count AN 5 VISIBLE "Buzz" NO WAI VISIBLE count OIC IM OUTTA YR fizzbuzzKTHXBYE`;fizzbuzz();
Details best grokked fromthis CodeSandbox
Here is a full blog post about how it works 👉LOLCODE-to-JavaScript compiler babel macro
About
LOLCODE implementation with Babel macros
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.