Skip to content

Commit 30426fd

Browse files
committed
fix: restore pieces pads in normalizeMultilinePieces
1 parent d79a638 commit 30426fd

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

src/util.ts

+7-6
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,19 @@ export function isString(obj: any) {
2424
return typeof obj === 'string'
2525
}
2626

27+
const pad = (v: string) => (v === ' ' ? ' ' : '')
28+
2729
export function normalizeMultilinePieces(
2830
pieces: TemplateStringsArray
2931
): TemplateStringsArray {
3032
return Object.assign(
3133
pieces.map((p, i) =>
3234
p.trim()
33-
? parseLine(p)
34-
.words.map(({ w, e }) => {
35-
if (w === '\\') return ''
36-
return w.trim() + (p[e + 1] === ' ' ? ' ' : '')
37-
})
38-
.join(' ')
35+
? pad(p[0]) +
36+
parseLine(p)
37+
.words.map(({ w }) => (w === '\\' ? '' : w.trim()))
38+
.join(' ') +
39+
pad(p[p.length - 1])
3940
: pieces[i]
4041
),
4142
{ raw: pieces.raw }

test/util.test.js

+8
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import {
2424
quote,
2525
quotePowerShell,
2626
randomId,
27+
normalizeMultilinePieces,
2728
getCallerLocationFromString,
2829
} from '../build/util.js'
2930

@@ -92,6 +93,13 @@ describe('util', () => {
9293
"$ \u001b[93m$\u001b[39m\u001b[93m'\u001b[39m\u001b[93m\\\u001b[39m\u001b[93m'\u001b[39m\u001b[93m'\u001b[39m\n"
9394
)
9495
})
96+
97+
test('normalizeMultilinePieces()', () => {
98+
assert.equal(
99+
normalizeMultilinePieces([' a ', 'b c d', ' e']).join(','),
100+
' a ,b c d, e'
101+
)
102+
})
95103
})
96104

97105
test('getCallerLocation: empty', () => {

0 commit comments

Comments
 (0)