Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions compiler/layouter.nim
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,9 @@ proc optionalIsGood(em: var Emitter; pos, currentLen: int): bool =
if isLongEnough(lineLenTotal, nlPos, p):
em.kinds[nlPos] = ltOptionalNewline
if em.kinds[nlPos+1] == ltSpaces:
# inhibit extra spaces when concatenating two lines
em.tokens[nlPos+1] = if em.tokens[nlPos-2] == ",": " " else: ""
# inhibit extra spaces when concatenating two lines; only an
# opening bracket is written without a space after it (#26691, #26692)
em.tokens[nlPos+1] = if em.kinds[nlPos-2] == ltSomeParLe: "" else: " "
result = true
elif em.tokens[p+1].len < ourIndent:
result = isLongEnough(lineLen, pos, p)
Expand Down
21 changes: 21 additions & 0 deletions nimpretty/tests/expected/tjoinlines.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# bug #26691: `and` at the end of a joined line keeps its space
import std/json

let after = %*[{"rule": {"chain": "nginwho", "expr": [1, 2, 3]}}]
block:
block:
var rules: seq[string]
for node in after:
if node.contains("rule") and node["rule"]["chain"].getStr() ==
"nginwho" and node["rule"]["expr"].len > 2:
rules.add("match")
echo rules

# bug #26692: a binary `&` at the end of a joined line keeps its space
proc makeCommand(name, key, cert: string): string =
result = "openssl req -x509 -newkey rsa:2048 -nodes -days 1 -subj /CN=" &
name & " -addext subjectAltName=IP:127.0.0.1 -keyout " & key & " -out " &
cert &
" 2>/dev/null"

echo makeCommand("example", "key.pem", "cert.pem")
20 changes: 20 additions & 0 deletions nimpretty/tests/tjoinlines.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# bug #26691: `and` at the end of a joined line keeps its space
import std/json

let after = %*[{"rule": {"chain": "nginwho", "expr": [1, 2, 3]}}]
block:
block:
var rules: seq[string]
for node in after:
if node.contains("rule") and node["rule"]["chain"].getStr() == "nginwho" and
node["rule"]["expr"].len > 2:
rules.add("match")
echo rules

# bug #26692: a binary `&` at the end of a joined line keeps its space
proc makeCommand(name, key, cert: string): string =
result = "openssl req -x509 -newkey rsa:2048 -nodes -days 1 -subj /CN=" & name &
" -addext subjectAltName=IP:127.0.0.1 -keyout " & key & " -out " & cert &
" 2>/dev/null"

echo makeCommand("example", "key.pem", "cert.pem")
Loading