| 24 | let doubleSingleQuotes = false; |
| 25 | |
| 26 | const fixEscapes = node => { |
| 27 | if (node.type !== 'Literal' || typeof node.value !== 'string') return; |
| 28 | if (doubleSingleQuotes) node.value = node.value.replace(/''+/g, '$&$&'); |
| 29 | node.value = node.value.replace( |
| 30 | /('*)\\([#{}\\]|u[0-9a-f]{4})('*)/g, |
| 31 | (_, start, char, end) => { |
| 32 | switch (char[0]) { |
| 33 | case 'u': { |
| 34 | const code = parseInt(char.slice(1), 16); |
| 35 | return start + String.fromCharCode(code) + end; |
| 36 | } |
| 37 | case '\\': |
| 38 | return `${start}\\${end}`; |
| 39 | default: |
| 40 | // Assume multiple ' are already escaped |
| 41 | if (start === "'") start = "''"; |
| 42 | if (end === "'") end = "''"; |
| 43 | return `'${start}${char}${end}'`; |
| 44 | } |
| 45 | } |
| 46 | ); |
| 47 | }; |
| 48 | |
| 49 | module.exports = ({ source }, { jscodeshift: j }, options) => { |
| 50 | if (options.doubleSingleQuotes) doubleSingleQuotes = true; |
no outgoing calls
no test coverage detected