Skip to content

MAJOR 4.0.0, 2020-09-01

Compare
Choose a tag to compare
@kaelzhang kaelzhang released this 01 Sep 06:26
· 37 commits to master since this release
  • MAJOR: fixes #21, removes after-comma:${prop} and after symbol properties, and introduce after:${prop}
  • MAJOR: #20 symbol properties of comments are now not enumerable, so that you could use Object.keys to get the keys of the parsed object as the normal ones

4.0.0 brings breaking changes, but however, logically but not programmatically.

So for most scenarios, you need NOT to change your code, and an upgrade is recommended.

Upgrade Guide

Use assign instead of object spreading

const parsed = parse(`{
  // comment
  "foo": "bar"
}`)

In 3.x, it is ok to do as following

stringify({...parsed}, null, 2)
// {
//   // comment
//   "foo": "bar"
// }

But with comment-json@4.0.0, the code above will print

{
  "foo": "bar"
}

Because since 4.0.0, symbol properties of comments are non-enumerable, so object spreading will not work for this case, and you should use assign function to copy those properties.

const {assign} = require('comment-json')

stringify(assign({}, parsed), null, 2)

Changes of symbol properties

TL;NR

{
  "foo": "bar" /* after value */, // after foo
  "bar": "baz" // after bar
}

In 3.x

  • The comment after foo is marked as Symbol.for('after-comma:foo')
  • The comment after bar is marked as Symbol.for('after-value:bar')

But in 4.x

  • The comment after foo is marked as Symbol.for('after:foo')
  • The comment after bar is marked as Symbol.for('after:bar')

And in both 3.x and 4.x after value is marked as Symbol.for('after-value:foo')