Skip to content

Instantly share code, notes, and snippets.

@stephencookdev
Created April 24, 2020 15:15
Show Gist options
  • Save stephencookdev/98e96b711aae69864fbe1f7ceb5df6bf to your computer and use it in GitHub Desktop.
Save stephencookdev/98e96b711aae69864fbe1f7ceb5df6bf to your computer and use it in GitHub Desktop.
A look at the initiator visitor of grandmas-own-jsx
module.exports = function ({ types: t }) {
const GrandmaVisitorInitiator = {
Program(path) {
const commentLineTokens = path.parent.comments.filter(
(token) => token.type === "CommentLine"
);
const commentBlockTokens = path.parent.comments.filter(
(token) => token.type === "CommentBlock"
);
if (!commentLineTokens.length || !commentBlockTokens.length) return;
const grandmasReference = buildGrandmasReference(commentLineTokens);
const grandmasRecipes = buildGrandmasRecipe(commentBlockTokens);
path.traverse(GrandmaVisitor, {
grandmasReference: grandmasReference,
grandmasRecipes: grandmasRecipes,
});
},
};
return { visitor: GrandmaVisitorInitiator };
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment