Created
February 8, 2016 17:22
-
-
Save bpugh/97e088aca3d1379addb3 to your computer and use it in GitHub Desktop.
blog post test
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
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(); | |
}; |
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
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