comment-parser 1.4.3 → 1.4.5
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 +12 -0
- package/browser/index.js +12 -7
- package/es6/parser/block-parser.d.ts +1 -1
- package/es6/parser/block-parser.js +1 -1
- package/es6/parser/tokenizers/name.js +11 -6
- 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/lib/parser/tokenizers/name.cjs +12 -6
- package/lib/parser/tokenizers/name.cjs.map +1 -1
- package/package.json +5 -2
- package/src/parser/block-parser.ts +2 -2
- package/src/parser/tokenizers/name.ts +12 -8
- package/tests/unit/block-parser.spec.ts +80 -0
- package/tests/unit/spec-name-tokenizer.spec.ts +94 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# v1.4.1
|
|
2
2
|
|
|
3
|
+
## 1.4.5
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- fix: skip empty lines in name tokenizer only when type is present
|
|
8
|
+
|
|
9
|
+
## 1.4.4
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- fully exclude slash-containing strings like @npm/package from tag detection @brettz9
|
|
14
|
+
|
|
3
15
|
## 1.4.3
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
package/browser/index.js
CHANGED
|
@@ -60,7 +60,7 @@ var CommentParser = (function (exports) {
|
|
|
60
60
|
return block;
|
|
61
61
|
}
|
|
62
62
|
|
|
63
|
-
const reTag =
|
|
63
|
+
const reTag = /^@[^\s/]+(?=\s|$)/;
|
|
64
64
|
/**
|
|
65
65
|
* Creates configured `Parser`
|
|
66
66
|
* @param {Partial<Options>} options
|
|
@@ -264,13 +264,18 @@ var CommentParser = (function (exports) {
|
|
|
264
264
|
// look for the name starting in the line where {type} ends
|
|
265
265
|
let finalTypeLine = spec.source.reduce(typeEnd, 0);
|
|
266
266
|
let tokens;
|
|
267
|
-
|
|
267
|
+
if (spec.type) {
|
|
268
|
+
do {
|
|
269
|
+
({ tokens } = spec.source[finalTypeLine]);
|
|
270
|
+
if (tokens.description.trim()) {
|
|
271
|
+
break;
|
|
272
|
+
}
|
|
273
|
+
finalTypeLine++;
|
|
274
|
+
} while (spec.source[finalTypeLine]);
|
|
275
|
+
}
|
|
276
|
+
else {
|
|
268
277
|
({ tokens } = spec.source[finalTypeLine]);
|
|
269
|
-
|
|
270
|
-
break;
|
|
271
|
-
}
|
|
272
|
-
finalTypeLine++;
|
|
273
|
-
} while (spec.source[finalTypeLine]);
|
|
278
|
+
}
|
|
274
279
|
const source = tokens.description.trimStart();
|
|
275
280
|
const quotedGroups = source.split('"');
|
|
276
281
|
// if it starts with quoted group, assume it is a literal
|
|
@@ -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
|
/**
|
|
@@ -10,13 +10,18 @@ export default function nameTokenizer() {
|
|
|
10
10
|
// look for the name starting in the line where {type} ends
|
|
11
11
|
let finalTypeLine = spec.source.reduce(typeEnd, 0);
|
|
12
12
|
let tokens;
|
|
13
|
-
|
|
13
|
+
if (spec.type) {
|
|
14
|
+
do {
|
|
15
|
+
({ tokens } = spec.source[finalTypeLine]);
|
|
16
|
+
if (tokens.description.trim()) {
|
|
17
|
+
break;
|
|
18
|
+
}
|
|
19
|
+
finalTypeLine++;
|
|
20
|
+
} while (spec.source[finalTypeLine]);
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
14
23
|
({ tokens } = spec.source[finalTypeLine]);
|
|
15
|
-
|
|
16
|
-
break;
|
|
17
|
-
}
|
|
18
|
-
finalTypeLine++;
|
|
19
|
-
} while (spec.source[finalTypeLine]);
|
|
24
|
+
}
|
|
20
25
|
const source = tokens.description.trimStart();
|
|
21
26
|
const quotedGroups = source.split('"');
|
|
22
27
|
// if it starts with quoted group, assume it is a literal
|
|
@@ -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
|
/**
|
|
@@ -18,15 +18,21 @@ function nameTokenizer() {
|
|
|
18
18
|
// look for the name starting in the line where {type} ends
|
|
19
19
|
let finalTypeLine = spec.source.reduce(typeEnd, 0);
|
|
20
20
|
let tokens;
|
|
21
|
-
|
|
21
|
+
if (spec.type) {
|
|
22
|
+
do {
|
|
23
|
+
({
|
|
24
|
+
tokens
|
|
25
|
+
} = spec.source[finalTypeLine]);
|
|
26
|
+
if (tokens.description.trim()) {
|
|
27
|
+
break;
|
|
28
|
+
}
|
|
29
|
+
finalTypeLine++;
|
|
30
|
+
} while (spec.source[finalTypeLine]);
|
|
31
|
+
} else {
|
|
22
32
|
({
|
|
23
33
|
tokens
|
|
24
34
|
} = spec.source[finalTypeLine]);
|
|
25
|
-
|
|
26
|
-
break;
|
|
27
|
-
}
|
|
28
|
-
finalTypeLine++;
|
|
29
|
-
} while (spec.source[finalTypeLine]);
|
|
35
|
+
}
|
|
30
36
|
const source = tokens.description.trimStart();
|
|
31
37
|
const quotedGroups = source.split('"');
|
|
32
38
|
// if it starts with quoted group, assume it is a literal
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"name.cjs","names":["Object","defineProperty","exports","value","default","nameTokenizer","util_js_1","require","isQuoted","s","startsWith","endsWith","typeEnd","num","tokens","i","type","spec","finalTypeLine","source","reduce","description","trim","trimStart","quotedGroups","split","length","name","postName","splitSpace","slice","brackets","optional","defaultValue","ch","isSpace","problems","push","code","message","line","number","critical","nameToken","parts","undefined","join","test"],"sources":["name.js"],"sourcesContent":["\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.default = nameTokenizer;\nconst util_js_1 = require(\"../../util.js\");\nconst isQuoted = (s) => s && s.startsWith('\"') && s.endsWith('\"');\n/**\n * Splits remaining `spec.lines[].tokens.description` into `name` and `descriptions` tokens,\n * and populates the `spec.name`\n */\nfunction nameTokenizer() {\n const typeEnd = (num, { tokens }, i) => tokens.type === '' ? num : i;\n return (spec) => {\n // look for the name starting in the line where {type} ends\n let finalTypeLine = spec.source.reduce(typeEnd, 0);\n let tokens;\n do {\n
|
|
1
|
+
{"version":3,"file":"name.cjs","names":["Object","defineProperty","exports","value","default","nameTokenizer","util_js_1","require","isQuoted","s","startsWith","endsWith","typeEnd","num","tokens","i","type","spec","finalTypeLine","source","reduce","description","trim","trimStart","quotedGroups","split","length","name","postName","splitSpace","slice","brackets","optional","defaultValue","ch","isSpace","problems","push","code","message","line","number","critical","nameToken","parts","undefined","join","test"],"sources":["name.js"],"sourcesContent":["\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.default = nameTokenizer;\nconst util_js_1 = require(\"../../util.js\");\nconst isQuoted = (s) => s && s.startsWith('\"') && s.endsWith('\"');\n/**\n * Splits remaining `spec.lines[].tokens.description` into `name` and `descriptions` tokens,\n * and populates the `spec.name`\n */\nfunction nameTokenizer() {\n const typeEnd = (num, { tokens }, i) => tokens.type === '' ? num : i;\n return (spec) => {\n // look for the name starting in the line where {type} ends\n let finalTypeLine = spec.source.reduce(typeEnd, 0);\n let tokens;\n if (spec.type) {\n do {\n ({ tokens } = spec.source[finalTypeLine]);\n if (tokens.description.trim()) {\n break;\n }\n finalTypeLine++;\n } while (spec.source[finalTypeLine]);\n }\n else {\n ({ tokens } = spec.source[finalTypeLine]);\n }\n const source = tokens.description.trimStart();\n const quotedGroups = source.split('\"');\n // if it starts with quoted group, assume it is a literal\n if (quotedGroups.length > 1 &&\n quotedGroups[0] === '' &&\n quotedGroups.length % 2 === 1) {\n spec.name = quotedGroups[1];\n tokens.name = `\"${quotedGroups[1]}\"`;\n [tokens.postName, tokens.description] = (0, util_js_1.splitSpace)(source.slice(tokens.name.length));\n return spec;\n }\n let brackets = 0;\n let name = '';\n let optional = false;\n let defaultValue;\n // assume name is non-space string or anything wrapped into brackets\n for (const ch of source) {\n if (brackets === 0 && (0, util_js_1.isSpace)(ch))\n break;\n if (ch === '[')\n brackets++;\n if (ch === ']')\n brackets--;\n name += ch;\n }\n if (brackets !== 0) {\n spec.problems.push({\n code: 'spec:name:unpaired-brackets',\n message: 'unpaired brackets',\n line: spec.source[0].number,\n critical: true,\n });\n return spec;\n }\n const nameToken = name;\n if (name[0] === '[' && name[name.length - 1] === ']') {\n optional = true;\n name = name.slice(1, -1);\n const parts = name.split('=');\n name = parts[0].trim();\n if (parts[1] !== undefined)\n defaultValue = parts.slice(1).join('=').trim();\n if (name === '') {\n spec.problems.push({\n code: 'spec:name:empty-name',\n message: 'empty name',\n line: spec.source[0].number,\n critical: true,\n });\n return spec;\n }\n if (defaultValue === '') {\n spec.problems.push({\n code: 'spec:name:empty-default',\n message: 'empty default value',\n line: spec.source[0].number,\n critical: true,\n });\n return spec;\n }\n // has \"=\" and is not a string, except for \"=>\"\n if (!isQuoted(defaultValue) && /=(?!>)/.test(defaultValue)) {\n spec.problems.push({\n code: 'spec:name:invalid-default',\n message: 'invalid default value syntax',\n line: spec.source[0].number,\n critical: true,\n });\n return spec;\n }\n }\n spec.optional = optional;\n spec.name = name;\n tokens.name = nameToken;\n if (defaultValue !== undefined)\n spec.default = defaultValue;\n [tokens.postName, tokens.description] = (0, util_js_1.splitSpace)(source.slice(tokens.name.length));\n return spec;\n };\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,aAAa;AAC/B,MAAMC,SAAS,GAAGC,OAAO,kBAAiB;AAC1C,MAAMC,QAAQ,GAAIC,CAAC,IAAKA,CAAC,IAAIA,CAAC,CAACC,UAAU,CAAC,GAAG,CAAC,IAAID,CAAC,CAACE,QAAQ,CAAC,GAAG,CAAC;AACjE;AACA;AACA;AACA;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,EAAEV,MAAM,CAACW,KAAK,CAAChB,MAAM,CAACa,IAAI,CAACD,MAAM,CAAC,CAAC;IACnG,OAAOT,IAAI;EACf,CAAC;AACL","ignoreList":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "comment-parser",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.5",
|
|
4
4
|
"description": "Generic JSDoc-like comment parser",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/index.cjs",
|
|
@@ -58,7 +58,10 @@
|
|
|
58
58
|
"test": "prettier --check src tests && jest --verbose",
|
|
59
59
|
"preversion": "npm run build",
|
|
60
60
|
"prepare": "npm run build",
|
|
61
|
-
"prepublishOnly": "npm run build"
|
|
61
|
+
"prepublishOnly": "npm run build",
|
|
62
|
+
"release:add": "changeset",
|
|
63
|
+
"release:version": "git pull origin main && changeset version && npm install && git add . && git commit -m \"release v$(node -p \"require('./package.json').version\")\"",
|
|
64
|
+
"release:publish": "git pull origin main && changeset publish && git push --follow-tags"
|
|
62
65
|
},
|
|
63
66
|
"repository": {
|
|
64
67
|
"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
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Spec, Line } from '../../primitives.js';
|
|
1
|
+
import { Spec, Line, Tokens } from '../../primitives.js';
|
|
2
2
|
import { splitSpace, isSpace } from '../../util.js';
|
|
3
3
|
import { Tokenizer } from './index.js';
|
|
4
4
|
|
|
@@ -16,14 +16,18 @@ export default function nameTokenizer(): Tokenizer {
|
|
|
16
16
|
// look for the name starting in the line where {type} ends
|
|
17
17
|
let finalTypeLine = spec.source.reduce(typeEnd, 0);
|
|
18
18
|
|
|
19
|
-
let tokens;
|
|
20
|
-
|
|
19
|
+
let tokens: Tokens;
|
|
20
|
+
if (spec.type) {
|
|
21
|
+
do {
|
|
22
|
+
({ tokens } = spec.source[finalTypeLine]);
|
|
23
|
+
if (tokens.description.trim()) {
|
|
24
|
+
break;
|
|
25
|
+
}
|
|
26
|
+
finalTypeLine++;
|
|
27
|
+
} while (spec.source[finalTypeLine]);
|
|
28
|
+
} else {
|
|
21
29
|
({ tokens } = spec.source[finalTypeLine]);
|
|
22
|
-
|
|
23
|
-
break;
|
|
24
|
-
}
|
|
25
|
-
finalTypeLine++;
|
|
26
|
-
} while (spec.source[finalTypeLine]);
|
|
30
|
+
}
|
|
27
31
|
|
|
28
32
|
const source = tokens.description.trimStart();
|
|
29
33
|
|
|
@@ -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
|
+
});
|
|
@@ -734,3 +734,97 @@ test('after multiline {type}', () => {
|
|
|
734
734
|
})
|
|
735
735
|
);
|
|
736
736
|
});
|
|
737
|
+
|
|
738
|
+
test('name on second line after type', () => {
|
|
739
|
+
const sourceIn = [
|
|
740
|
+
{
|
|
741
|
+
number: 0,
|
|
742
|
+
source: '...',
|
|
743
|
+
tokens: seedTokens({
|
|
744
|
+
tag: '@param',
|
|
745
|
+
postTag: ' ',
|
|
746
|
+
type: '{string}',
|
|
747
|
+
postType: '',
|
|
748
|
+
description: '',
|
|
749
|
+
}),
|
|
750
|
+
},
|
|
751
|
+
{
|
|
752
|
+
number: 1,
|
|
753
|
+
source: '...',
|
|
754
|
+
tokens: seedTokens({
|
|
755
|
+
description: 'foo The foo description.',
|
|
756
|
+
}),
|
|
757
|
+
},
|
|
758
|
+
];
|
|
759
|
+
|
|
760
|
+
const sourceOut = JSON.parse(JSON.stringify(sourceIn));
|
|
761
|
+
Object.assign(sourceOut[1].tokens, {
|
|
762
|
+
name: 'foo',
|
|
763
|
+
postName: ' ',
|
|
764
|
+
description: 'The foo description.',
|
|
765
|
+
});
|
|
766
|
+
|
|
767
|
+
expect(tokenize(seedSpec({ type: 'string', source: sourceIn }))).toEqual(
|
|
768
|
+
seedSpec({
|
|
769
|
+
type: 'string',
|
|
770
|
+
name: 'foo',
|
|
771
|
+
source: sourceOut,
|
|
772
|
+
})
|
|
773
|
+
);
|
|
774
|
+
});
|
|
775
|
+
|
|
776
|
+
test('no type - should not look for name on subsequent lines', () => {
|
|
777
|
+
const sourceIn = [
|
|
778
|
+
{
|
|
779
|
+
number: 0,
|
|
780
|
+
source: '...',
|
|
781
|
+
tokens: seedTokens({
|
|
782
|
+
tag: '@example',
|
|
783
|
+
postTag: '',
|
|
784
|
+
description: '',
|
|
785
|
+
}),
|
|
786
|
+
},
|
|
787
|
+
{
|
|
788
|
+
number: 1,
|
|
789
|
+
source: '...',
|
|
790
|
+
tokens: seedTokens({
|
|
791
|
+
description: 'const foo = bar()',
|
|
792
|
+
}),
|
|
793
|
+
},
|
|
794
|
+
];
|
|
795
|
+
|
|
796
|
+
expect(tokenize(seedSpec({ source: sourceIn }))).toEqual(
|
|
797
|
+
seedSpec({
|
|
798
|
+
name: '',
|
|
799
|
+
source: sourceIn,
|
|
800
|
+
})
|
|
801
|
+
);
|
|
802
|
+
});
|
|
803
|
+
|
|
804
|
+
test('no type with comment syntax - should not parse as name', () => {
|
|
805
|
+
const sourceIn = [
|
|
806
|
+
{
|
|
807
|
+
number: 0,
|
|
808
|
+
source: '...',
|
|
809
|
+
tokens: seedTokens({
|
|
810
|
+
tag: '@example',
|
|
811
|
+
postTag: '',
|
|
812
|
+
description: '',
|
|
813
|
+
}),
|
|
814
|
+
},
|
|
815
|
+
{
|
|
816
|
+
number: 1,
|
|
817
|
+
source: '...',
|
|
818
|
+
tokens: seedTokens({
|
|
819
|
+
description: '// Create something',
|
|
820
|
+
}),
|
|
821
|
+
},
|
|
822
|
+
];
|
|
823
|
+
|
|
824
|
+
expect(tokenize(seedSpec({ source: sourceIn }))).toEqual(
|
|
825
|
+
seedSpec({
|
|
826
|
+
name: '',
|
|
827
|
+
source: sourceIn,
|
|
828
|
+
})
|
|
829
|
+
);
|
|
830
|
+
});
|