Skip to content

Instantly share code, notes, and snippets.

@stephencookdev
Last active April 24, 2020 16:03
Show Gist options
  • Save stephencookdev/5e7232f4f9eea46498e5ab896a10260f to your computer and use it in GitHub Desktop.
Save stephencookdev/5e7232f4f9eea46498e5ab896a10260f to your computer and use it in GitHub Desktop.
A look at the main visitor of grandmas-own-jsx
module.exports = function ({ types: t }) {
const GrandmaVisitor = {
StringLiteral(path, state) {
if (path.node.value === "👵") {
const recipeRef = state.grandmasRecipes[path.node.loc.start.line];
const recipeMatches = recipeRef && recipeRef.start > path.node.start;
if (recipeMatches) {
const recipe = recipeRef.value;
const domStruc = cookRecipe(recipe, state.grandmasReference);
const typeExpression = genTypeExpression(domStruc);
path.replaceWith(typeExpression);
}
}
},
};
const GrandmaVisitorInitiator = { /* ... */ };
return { visitor: GrandmaVisitorInitiator };
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment