Skip to content

Instantly share code, notes, and snippets.

@bpugh
Created February 8, 2016 17:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bpugh/97e088aca3d1379addb3 to your computer and use it in GitHub Desktop.
Save bpugh/97e088aca3d1379addb3 to your computer and use it in GitHub Desktop.
blog post test
export default function(file, api) {
const j = api.jscodeshift;
const {expression, statement, statements} = j.template;
const convertToTemplateString = p => {
const quasis = [
j.templateElement({ cooked: '', raw: ''}, false),
j.templateElement({ cooked: '', raw: ''}, false),
j.templateElement({ cooked: '', raw: ''}, true)
]
const expressions = [ p.node.left, p.node.right ]
return j.templateLiteral(quasis, expressions)
}
return j(file.source)
.find(j.BinaryExpression, { operator: '+' })
.replaceWith(convertToTemplateString)
.toSource();
};
const map = (list, fn, acc = []) {
if (list.length === 0) {
return acc
}
const [ a, ...as ] = list
return map(as, fn, acc.concat(fn(a)))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment