Skip to content

Commit d43c185

Browse files
committed
Fix flowSkipColonSpace by forcing quoteFlowKeys
1 parent a5fdb31 commit d43c185

2 files changed

Lines changed: 13 additions & 2 deletions

File tree

src/ast/presenter.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,10 @@ interface PresenterOptions {
6767
flowSkipCommaSpace?: boolean
6868

6969
/**
70-
* Omits the space after `:` in flow mappings: `{a: 1}` becomes `{a:1}`.
70+
* Omits the space after `:` in flow mappings: `{"a": 1}` becomes `{"a":1}`.
71+
*
72+
* This forces `quoteFlowKeys`; otherwise `a:1` would be parsed as a single
73+
* plain scalar instead of a mapping entry.
7174
*
7275
* @defaultValue `false`
7376
*/
@@ -132,6 +135,10 @@ function createPresenterState (options: PresenterOptions): PresenterState {
132135
...options
133136
}
134137

138+
if (opts.flowSkipColonSpace) {
139+
opts.quoteFlowKeys = true
140+
}
141+
135142
return {
136143
...opts,
137144
defaultScalarTagName: opts.schema.defaultScalarTag.tagName,

test/core/units/dump-options.test.mjs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,11 @@ describe('dump options', () => {
151151

152152
it('flowSkipColonSpace — drops the space after flow colons', () => {
153153
assert.equal(dump({ a: 1 }, { flowLevel: 0 }), '{a: 1}\n')
154-
assert.equal(dump({ a: 1 }, { flowLevel: 0, flowSkipColonSpace: true }), '{a:1}\n')
154+
155+
const output = dump({ a: 1 }, { flowLevel: 0, flowSkipColonSpace: true })
156+
157+
assert.equal(output, '{"a":1}\n')
158+
assert.deepEqual(load(output), { a: 1 })
155159
})
156160

157161
it('quoteFlowKeys — quotes keys in flow mappings', () => {

0 commit comments

Comments
 (0)