README
hacklang-sucrose
An actual working implementation of hacklang. This repository is a minimal-change adaptation of Sucrase
Usage
See ./examples/
to use it with webpack, with a node project (coming soon) or with CRA
Contributing
Setup
git clone https://github.com/eankeen/hacklang-sucrose
cd hacklang-sucrase
yarn i
yarn i -D tslib
yarn generate
yarn build
Adding Your Keyword
Note: For reference, see the var
-> rice
, const
-> yuto
, class
-> aditya
(partially), and throw
-> carrot
Edit keyword entry in
KEYWORDS
variable ingenerator/generateReadWordTree.ts
. Make sure to prepend a comment!Add if statement for your new keyword in the second loop over
ALL_KEYWORDS
(starts around line 130) ingenerator/generateReadWordTree.ts
- This is done because the property (ex.
_var
) used to access the real name of the token (ex.rice
). Is autogenerated from the changed token we specify. We want to make the accessor stay as_var
(instead of changing to_rice
) so we don't have to refactor the rest of the codebase
Edit
KeywordTokenType
instantiation for your keyword ingenerator/generateTokenTypes.ts
Generate the proper tokens from your changes
yarn generate
Add your token to the Hacklang transformer in
src/parser/transformers/HacklangTransformer.ts
Build project
- The build pipeline is different compared to Sucrose because the multi-step self-build check to ensure compiler output integrity has been removed
yarn build
- Test your keyword :)
node examples/sucrase-cli/input.js
( cd examples/webpack && yarn webpack )
( cd examples/create-react-app && yarn start )
- Commit changes and make a PR 😝
Note that although the setup for above should work for most of the keywords, entities such as =
, super()
, constructor()
and possibly this
may require a custom transformation under src/parser/transformers/HacklangTransformer.ts
Roadmap
- create webpack plugin to auto modify CRA config
- create example for node using our @sucrase/register
- add more keywords