Last active
April 24, 2020 16:03
-
-
Save stephencookdev/5e7232f4f9eea46498e5ab896a10260f to your computer and use it in GitHub Desktop.
A look at the main visitor of grandmas-own-jsx
This file contains 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
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