Skip to content

Commit

Permalink
fix: restore pieces pads in normalizeMultilinePieces (#766)
Browse files Browse the repository at this point in the history
  • Loading branch information
antongolub authored Apr 2, 2024
1 parent d79a638 commit 0844b88
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,19 @@ export function isString(obj: any) {
return typeof obj === 'string'
}

const pad = (v: string) => (v === ' ' ? ' ' : '')

export function normalizeMultilinePieces(
pieces: TemplateStringsArray
): TemplateStringsArray {
return Object.assign(
pieces.map((p, i) =>
p.trim()
? parseLine(p)
.words.map(({ w, e }) => {
if (w === '\\') return ''
return w.trim() + (p[e + 1] === ' ' ? ' ' : '')
})
.join(' ')
? pad(p[0]) +
parseLine(p)
.words.map(({ w }) => (w === '\\' ? '' : w.trim()))
.join(' ') +
pad(p[p.length - 1])
: pieces[i]
),
{ raw: pieces.raw }
Expand Down
8 changes: 8 additions & 0 deletions test/util.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
quote,
quotePowerShell,
randomId,
normalizeMultilinePieces,
getCallerLocationFromString,
} from '../build/util.js'

Expand Down Expand Up @@ -92,6 +93,13 @@ describe('util', () => {
"$ \u001b[93m$\u001b[39m\u001b[93m'\u001b[39m\u001b[93m\\\u001b[39m\u001b[93m'\u001b[39m\u001b[93m'\u001b[39m\n"
)
})

test('normalizeMultilinePieces()', () => {
assert.equal(
normalizeMultilinePieces([' a ', 'b c d', ' e']).join(','),
' a ,b c d, e'
)
})
})

test('getCallerLocation: empty', () => {
Expand Down

0 comments on commit 0844b88

Please sign in to comment.