Skip to content

Commit 3b06338

Browse files
authored
Merge pull request #14 from mkantor/prettier-plz
Omit all ordinal property keys in pretty plz notation
2 parents ab6c25b + f59c43d commit 3b06338

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

src/language/unparsing/pretty-plz.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -132,19 +132,25 @@ const sugarFreeMolecule = (value: Molecule) => {
132132
return either.makeRight(openBrace + closeBrace)
133133
} else {
134134
const keyValuePairsAsStrings: string[] = []
135+
let ordinalPropertyKeyCounter = 0n
135136
for (const [propertyKey, propertyValue] of entries) {
136137
const valueAsStringResult = atomOrMolecule(propertyValue)
137138
if (either.isLeft(valueAsStringResult)) {
138139
return valueAsStringResult
139140
}
140141

141-
keyValuePairsAsStrings.push(
142-
// TODO: Intelligently omit all ordinal property keys, not just `0`.
143-
(propertyKey === '0'
144-
? ''
145-
: kleur.cyan(quoteIfNecessary(propertyKey).concat(colon)).concat(' ')
146-
).concat(valueAsStringResult.value),
147-
)
142+
// Omit ordinal property keys:
143+
if (propertyKey === String(ordinalPropertyKeyCounter)) {
144+
keyValuePairsAsStrings.push(valueAsStringResult.value)
145+
ordinalPropertyKeyCounter += 1n
146+
} else {
147+
keyValuePairsAsStrings.push(
148+
kleur
149+
.cyan(quoteIfNecessary(propertyKey).concat(colon))
150+
.concat(' ')
151+
.concat(valueAsStringResult.value),
152+
)
153+
}
148154
}
149155

150156
return either.makeRight(

0 commit comments

Comments
 (0)