comment-parser 1.4.3 → 1.4.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/browser/index.js +1 -1
- package/es6/parser/block-parser.d.ts +1 -1
- package/es6/parser/block-parser.js +1 -1
- package/lib/parser/block-parser.cjs +1 -1
- package/lib/parser/block-parser.cjs.map +1 -1
- package/lib/parser/block-parser.d.ts +1 -1
- package/package.json +6 -2
- package/src/parser/block-parser.ts +2 -2
- package/tests/unit/block-parser.spec.ts +80 -0
package/CHANGELOG.md
CHANGED
package/browser/index.js
CHANGED
|
@@ -3,7 +3,7 @@ import { Line } from '../primitives.js';
|
|
|
3
3
|
* Groups source lines in sections representing tags.
|
|
4
4
|
* First section is a block description if present. Last section captures lines starting with
|
|
5
5
|
* the last tag to the end of the block, including dangling closing marker.
|
|
6
|
-
* @param {Line[]} block
|
|
6
|
+
* @param {Line[]} block source lines making a single comment block
|
|
7
7
|
*/
|
|
8
8
|
export type Parser = (block: Line[]) => Line[][];
|
|
9
9
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"block-parser.cjs","names":["Object","defineProperty","exports","value","default","getParser","reTag","fence","fencer","getFencer","toggleFence","source","isFenced","parseBlock","sections","line","test","tokens","description","push","length","split"],"sources":["block-parser.js"],"sourcesContent":["\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.default = getParser;\nconst reTag =
|
|
1
|
+
{"version":3,"file":"block-parser.cjs","names":["Object","defineProperty","exports","value","default","getParser","reTag","fence","fencer","getFencer","toggleFence","source","isFenced","parseBlock","sections","line","test","tokens","description","push","length","split"],"sources":["block-parser.js"],"sourcesContent":["\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.default = getParser;\nconst reTag = /^@[^\\s/]+(?=\\s|$)/;\n/**\n * Creates configured `Parser`\n * @param {Partial<Options>} options\n */\nfunction getParser({ fence = '```', } = {}) {\n const fencer = getFencer(fence);\n const toggleFence = (source, isFenced) => fencer(source) ? !isFenced : isFenced;\n return function parseBlock(source) {\n // start with description section\n const sections = [[]];\n let isFenced = false;\n for (const line of source) {\n if (reTag.test(line.tokens.description) && !isFenced) {\n sections.push([line]);\n }\n else {\n sections[sections.length - 1].push(line);\n }\n isFenced = toggleFence(line.tokens.description, isFenced);\n }\n return sections;\n };\n}\nfunction getFencer(fence) {\n if (typeof fence === 'string')\n return (source) => source.split(fence).length % 2 === 0;\n return fence;\n}\n"],"mappings":"AAAA,YAAY;;AACZA,MAAM,CAACC,cAAc,CAACC,OAAO,EAAE,YAAY,EAAE;EAAEC,KAAK,EAAE;AAAK,CAAC,CAAC;AAC7DD,OAAO,CAACE,OAAO,GAAGC,SAAS;AAC3B,MAAMC,KAAK,GAAG,mBAAmB;AACjC;AACA;AACA;AACA;AACA,SAASD,SAASA,CAAC;EAAEE,KAAK,GAAG;AAAO,CAAC,GAAG,CAAC,CAAC,EAAE;EACxC,MAAMC,MAAM,GAAGC,SAAS,CAACF,KAAK,CAAC;EAC/B,MAAMG,WAAW,GAAGA,CAACC,MAAM,EAAEC,QAAQ,KAAKJ,MAAM,CAACG,MAAM,CAAC,GAAG,CAACC,QAAQ,GAAGA,QAAQ;EAC/E,OAAO,SAASC,UAAUA,CAACF,MAAM,EAAE;IAC/B;IACA,MAAMG,QAAQ,GAAG,CAAC,EAAE,CAAC;IACrB,IAAIF,QAAQ,GAAG,KAAK;IACpB,KAAK,MAAMG,IAAI,IAAIJ,MAAM,EAAE;MACvB,IAAIL,KAAK,CAACU,IAAI,CAACD,IAAI,CAACE,MAAM,CAACC,WAAW,CAAC,IAAI,CAACN,QAAQ,EAAE;QAClDE,QAAQ,CAACK,IAAI,CAAC,CAACJ,IAAI,CAAC,CAAC;MACzB,CAAC,MACI;QACDD,QAAQ,CAACA,QAAQ,CAACM,MAAM,GAAG,CAAC,CAAC,CAACD,IAAI,CAACJ,IAAI,CAAC;MAC5C;MACAH,QAAQ,GAAGF,WAAW,CAACK,IAAI,CAACE,MAAM,CAACC,WAAW,EAAEN,QAAQ,CAAC;IAC7D;IACA,OAAOE,QAAQ;EACnB,CAAC;AACL;AACA,SAASL,SAASA,CAACF,KAAK,EAAE;EACtB,IAAI,OAAOA,KAAK,KAAK,QAAQ,EACzB,OAAQI,MAAM,IAAKA,MAAM,CAACU,KAAK,CAACd,KAAK,CAAC,CAACa,MAAM,GAAG,CAAC,KAAK,CAAC;EAC3D,OAAOb,KAAK;AAChB","ignoreList":[]}
|
|
@@ -3,7 +3,7 @@ import { Line } from '../primitives.js';
|
|
|
3
3
|
* Groups source lines in sections representing tags.
|
|
4
4
|
* First section is a block description if present. Last section captures lines starting with
|
|
5
5
|
* the last tag to the end of the block, including dangling closing marker.
|
|
6
|
-
* @param {Line[]} block
|
|
6
|
+
* @param {Line[]} block source lines making a single comment block
|
|
7
7
|
*/
|
|
8
8
|
export type Parser = (block: Line[]) => Line[][];
|
|
9
9
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "comment-parser",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.4",
|
|
4
4
|
"description": "Generic JSDoc-like comment parser",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/index.cjs",
|
|
@@ -57,8 +57,12 @@
|
|
|
57
57
|
"pretest": "rimraf coverage; npm run build",
|
|
58
58
|
"test": "prettier --check src tests && jest --verbose",
|
|
59
59
|
"preversion": "npm run build",
|
|
60
|
+
"postversion": "git add . && git commit -m \"chore: release v$(node -p \"require('./package.json').version\")\"",
|
|
60
61
|
"prepare": "npm run build",
|
|
61
|
-
"prepublishOnly": "npm run build"
|
|
62
|
+
"prepublishOnly": "npm run build",
|
|
63
|
+
"release:add": "git pull origin master && changeset",
|
|
64
|
+
"release:version": "git pull origin master && changeset version && npm install",
|
|
65
|
+
"release:publish": "git pull origin master && npm run build && changeset publish && git push --follow-tags"
|
|
62
66
|
},
|
|
63
67
|
"repository": {
|
|
64
68
|
"type": "git",
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { Line } from '../primitives.js';
|
|
2
2
|
|
|
3
|
-
const reTag =
|
|
3
|
+
const reTag = /^@[^\s/]+(?=\s|$)/;
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Groups source lines in sections representing tags.
|
|
7
7
|
* First section is a block description if present. Last section captures lines starting with
|
|
8
8
|
* the last tag to the end of the block, including dangling closing marker.
|
|
9
|
-
* @param {Line[]} block
|
|
9
|
+
* @param {Line[]} block source lines making a single comment block
|
|
10
10
|
*/
|
|
11
11
|
export type Parser = (block: Line[]) => Line[][];
|
|
12
12
|
|
|
@@ -167,3 +167,83 @@ test('fence function', () => {
|
|
|
167
167
|
expect(groups.length).toBe(2);
|
|
168
168
|
expect(groups).toEqual([source.slice(0, 5), source.slice(5)]);
|
|
169
169
|
});
|
|
170
|
+
|
|
171
|
+
test('should not treat @npm/package or @ember/debug as tags', () => {
|
|
172
|
+
const parser = getParser();
|
|
173
|
+
const lines: Line[] = [
|
|
174
|
+
{
|
|
175
|
+
number: 1,
|
|
176
|
+
source: '/**',
|
|
177
|
+
tokens: seedTokens({
|
|
178
|
+
start: '',
|
|
179
|
+
delimiter: '/**',
|
|
180
|
+
postDelimiter: '',
|
|
181
|
+
description: '',
|
|
182
|
+
end: '',
|
|
183
|
+
}),
|
|
184
|
+
},
|
|
185
|
+
{
|
|
186
|
+
number: 2,
|
|
187
|
+
source: ' * Description line',
|
|
188
|
+
tokens: seedTokens({
|
|
189
|
+
start: ' ',
|
|
190
|
+
delimiter: '*',
|
|
191
|
+
postDelimiter: ' ',
|
|
192
|
+
description: 'Description line',
|
|
193
|
+
end: '',
|
|
194
|
+
}),
|
|
195
|
+
},
|
|
196
|
+
{
|
|
197
|
+
number: 3,
|
|
198
|
+
source: ' * @ember/debug should not be treated as tag',
|
|
199
|
+
tokens: seedTokens({
|
|
200
|
+
start: ' ',
|
|
201
|
+
delimiter: '*',
|
|
202
|
+
postDelimiter: ' ',
|
|
203
|
+
description: '@ember/debug should not be treated as tag',
|
|
204
|
+
end: '',
|
|
205
|
+
}),
|
|
206
|
+
},
|
|
207
|
+
{
|
|
208
|
+
number: 4,
|
|
209
|
+
source: ' * @npm/package should not be treated as tag either',
|
|
210
|
+
tokens: seedTokens({
|
|
211
|
+
start: ' ',
|
|
212
|
+
delimiter: '*',
|
|
213
|
+
postDelimiter: ' ',
|
|
214
|
+
description: '@npm/package should not be treated as tag either',
|
|
215
|
+
end: '',
|
|
216
|
+
}),
|
|
217
|
+
},
|
|
218
|
+
{
|
|
219
|
+
number: 5,
|
|
220
|
+
source: ' * @param {string} value',
|
|
221
|
+
tokens: seedTokens({
|
|
222
|
+
start: ' ',
|
|
223
|
+
delimiter: '*',
|
|
224
|
+
postDelimiter: ' ',
|
|
225
|
+
description: '@param {string} value',
|
|
226
|
+
end: '',
|
|
227
|
+
}),
|
|
228
|
+
},
|
|
229
|
+
{
|
|
230
|
+
number: 6,
|
|
231
|
+
source: ' */',
|
|
232
|
+
tokens: seedTokens({
|
|
233
|
+
start: ' ',
|
|
234
|
+
delimiter: '',
|
|
235
|
+
postDelimiter: '',
|
|
236
|
+
description: '',
|
|
237
|
+
end: '*/',
|
|
238
|
+
}),
|
|
239
|
+
},
|
|
240
|
+
];
|
|
241
|
+
|
|
242
|
+
const groups: Line[][] = parser(lines);
|
|
243
|
+
|
|
244
|
+
// Should have 2 sections: description (lines 0-3) and @param tag (lines 4-5)
|
|
245
|
+
// @ember/debug and @npm/package should stay in description, not create new sections
|
|
246
|
+
expect(groups.length).toBe(2);
|
|
247
|
+
expect(groups[0]).toEqual([lines[0], lines[1], lines[2], lines[3]]);
|
|
248
|
+
expect(groups[1]).toEqual([lines[4], lines[5]]);
|
|
249
|
+
});
|