|
| 1 | +import { toTemplateLiteral as command } from './to-template-literal' |
| 2 | +import { d, run } from './_test-utils' |
| 3 | + |
| 4 | +run( |
| 5 | + command, |
| 6 | + { |
| 7 | + code: d` |
| 8 | + // @2tl |
| 9 | + const a = \`a\${a}\`, b = \`b\`, c = "c", d = 2; |
| 10 | + `, |
| 11 | + output: d` |
| 12 | + const a = \`a\${a}\`, b = \`b\`, c = \`c\`, d = 2; |
| 13 | + `, |
| 14 | + errors: ['command-removal', 'command-fix'], |
| 15 | + }, |
| 16 | + // You can specify which one to convert |
| 17 | + { |
| 18 | + code: d` |
| 19 | + // @2tl 1 4 |
| 20 | + const a = 'a', b = 'b', c = 'c', d = 'd'; |
| 21 | + `, |
| 22 | + output: d` |
| 23 | + const a = \`a\`, b = 'b', c = 'c', d = \`d\`; |
| 24 | + `, |
| 25 | + errors: ['command-removal', 'command-fix', 'command-fix'], |
| 26 | + }, |
| 27 | + // mixed |
| 28 | + { |
| 29 | + code: d` |
| 30 | + // @2tl 1 3 |
| 31 | + const a = \`a\`; const b = \`b\`; const c = 'c'; const d = \`d\`; const e = 'e'; const f = 'f'; |
| 32 | + `, |
| 33 | + output: d` |
| 34 | + const a = \`a\`; const b = \`b\`; const c = \`c\`; const d = \`d\`; const e = 'e'; const f = \`f\`; |
| 35 | + `, |
| 36 | + errors: ['command-removal', 'command-fix', 'command-fix'], |
| 37 | + }, |
| 38 | + // 'a' + b + 'c' -> `a${b}c` |
| 39 | + { |
| 40 | + code: d` |
| 41 | + // @2tl |
| 42 | + const a = 'a' + b + 'c'; |
| 43 | + `, |
| 44 | + output: d` |
| 45 | + const a = \`a\${b}c\`; |
| 46 | + `, |
| 47 | + errors: ['command-removal', 'command-fix'], |
| 48 | + }, |
| 49 | + { |
| 50 | + code: d` |
| 51 | + // @2tl |
| 52 | + const b = b + 'c' + d + 'e' + f + z + 'g' + h + 'i' + j; |
| 53 | + `, |
| 54 | + output: d` |
| 55 | + const b = \`\${b}c\${d}e\${f}\${z}g\${h}i\${j}\`; |
| 56 | + `, |
| 57 | + errors: ['command-removal', 'command-fix'], |
| 58 | + }, |
| 59 | + { |
| 60 | + code: d` |
| 61 | + // @2tl |
| 62 | + const a = a + b + c; |
| 63 | + `, |
| 64 | + output: d` |
| 65 | + const a = \`\${a}\${b}\${c}\`; |
| 66 | + `, |
| 67 | + errors: ['command-removal', 'command-fix'], |
| 68 | + }, |
| 69 | + { |
| 70 | + code: d` |
| 71 | + // @2tl 2 4 |
| 72 | + const a = a + b; const d = d + 'e'; const c = '3'; const d = '4'; |
| 73 | + `, |
| 74 | + output: d` |
| 75 | + const a = a + b; const d = \`\${d}e\`; const c = '3'; const d = \`4\`; |
| 76 | + `, |
| 77 | + errors: ['command-removal', 'command-fix', 'command-fix'], |
| 78 | + }, |
| 79 | + { |
| 80 | + code: d` |
| 81 | + // @2tl 1 2 |
| 82 | + const a = '4' + b; const d = d + 'e'; const c = '3'; const d = '4'; |
| 83 | + `, |
| 84 | + output: d` |
| 85 | + const a = \`4\${b}\`; const d = \`\${d}e\`; const c = '3'; const d = '4'; |
| 86 | + `, |
| 87 | + errors: ['command-removal', 'command-fix', 'command-fix'], |
| 88 | + }, |
| 89 | +) |
0 commit comments