File tree Expand file tree Collapse file tree 3 files changed +83
-4
lines changed Expand file tree Collapse file tree 3 files changed +83
-4
lines changed Original file line number Diff line number Diff line change 1+ exports[`test ignores annotations inside a code fence 1`] = `
2+ Array [
3+ Object {
4+ "annotations": Object {
5+ "a": true,
6+ "b": true,
7+ },
8+ "description": "This comment contains a code fence
9+ \`\`\`scss
10+ @media () {}
11+ \`\`\`",
12+ },
13+ ]
14+ `;
15+
16+ exports[`test parses description and annotations (multi) 1`] = `
17+ Array [
18+ Object {
19+ "annotations": Object {
20+ "a": "hello",
21+ "b": "world",
22+ },
23+ "description": "This is a multi-line
24+ description",
25+ },
26+ ]
27+ `;
28+
29+ exports[`test parses description and annotations 1`] = `
30+ Array [
31+ Object {
32+ "annotations": Object {
33+ "world": true,
34+ },
35+ "description": "Hello",
36+ },
37+ ]
38+ `;
Original file line number Diff line number Diff line change 1+ const comments = require('../comments')
2+
3+ it('parses description and annotations', () => {
4+ expect(comments(`
5+ /**
6+ * Hello
7+ * @world
8+ */
9+ `)).toMatchSnapshot()
10+ })
11+
12+ it('parses description and annotations (multi)', () => {
13+ expect(comments(`
14+ /**
15+ * This is a multi-line
16+ * description
17+ * @a hello
18+ * @b world
19+ */
20+ `)).toMatchSnapshot()
21+ })
22+
23+ it('ignores annotations inside a code fence', () => {
24+ expect(comments(`
25+ /**
26+ * This comment contains a code fence
27+ * \`\`\`scss
28+ * @media () {}
29+ * \`\`\`
30+ * @a
31+ * @b
32+ */
33+ `)).toMatchSnapshot()
34+ })
Original file line number Diff line number Diff line change @@ -25,14 +25,19 @@ const remove = pattern => s => s.replace(pattern, '')
2525 *
2626 */
2727const reduceComment = (comment, line) => {
28- let match = line.match(/^@([^\s]+)(?:\s(.+))?/)
29- if (!match) {
28+ let annotation = comment.get('__codeFence')
29+ ? false
30+ : line.match(/^@([^\s]+)(?:\s(.+))?/)
31+ if (/```/.test(line)) {
32+ comment = comment.set('__codeFence', !comment.get('__codeFence', false))
33+ }
34+ if (!annotation) {
3035 return comment.update('description', description =>
3136 description.push(line)
3237 )
3338 } else {
34- return comment.setIn(['annotations', match [1]],
35- _.isUndefined(match [2]) ? true : match [2]
39+ return comment.setIn(['annotations', annotation [1]],
40+ _.isUndefined(annotation [2]) ? true : annotation [2]
3641 )
3742 }
3843}
@@ -51,6 +56,8 @@ module.exports = styles => {
5156 )
5257 .map(comment => comment
5358 .reduce(reduceComment, baseComment)
59+ .update(comment =>
60+ comment.keySeq().reduce((a, b) => /^__/.test(b) ? a.delete(b) : a, comment))
5461 .update(comment => comment
5562 .update('description', description =>
5663 description.join('\n').trim()
You can’t perform that action at this time.
0 commit comments