Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

LOLCODE implementation with Babel macros

License

NotificationsYou must be signed in to change notification settings

Swizec/lolcode-babel-macro

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

40 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

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.

How to use

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

Wanna know more?

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

Stars

Watchers

Forks

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp