-
-
Save frontEnd-fucker/8d23629f0d3f4516c83dc6537f07458a to your computer and use it in GitHub Desktop.
jscodeshift transform for converting double quotes to single quotes – *except* in JSX (HTML) attributes
This file contains hidden or 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(fileInfo, api) { | |
| var j = api.jscodeshift; | |
| var out = j(fileInfo.source) | |
| .find(j.Literal) | |
| .forEach(function (path) { | |
| // Only consider literals that start/end w/ double quotes | |
| if (!/^".*"$/.test(path.value.raw)) { | |
| return; | |
| } | |
| // Skip JSX element attributes | |
| if (path.parent.value.type === 'JSXAttribute') { | |
| return; | |
| } | |
| j(path).replaceWith(j.literal(path.value.value)); | |
| }) | |
| .toSource({quote: 'single'}); | |
| return out; | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment