comment-parser 1.1.5 → 1.1.6-beta.0
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 +4 -0
- package/browser/index.js +44 -1
- package/es6/index.d.ts +2 -0
- package/es6/index.js +2 -0
- package/es6/transforms/crlf.d.ts +3 -0
- package/es6/transforms/crlf.js +42 -0
- package/es6/util.js +1 -1
- package/lib/index.d.ts +2 -0
- package/lib/index.js +2 -0
- package/lib/transforms/crlf.d.ts +3 -0
- package/lib/transforms/crlf.js +45 -0
- package/lib/util.js +1 -1
- package/package.json +2 -2
- package/src/index.ts +2 -0
- package/src/transforms/crlf.ts +38 -0
- package/src/util.ts +1 -1
- package/tests/unit/source-parser.spec.ts +49 -1
- package/tests/unit/transforms-crlf.spec.ts +70 -0
- package/tests/unit/util.spec.ts +2 -2
package/CHANGELOG.md
CHANGED
package/browser/index.js
CHANGED
|
@@ -11,7 +11,7 @@ var CommentParser = (function (exports) {
|
|
|
11
11
|
: [source.slice(0, matches[0].length), source.slice(matches[0].length)];
|
|
12
12
|
}
|
|
13
13
|
function splitLines(source) {
|
|
14
|
-
return source.split(/\
|
|
14
|
+
return source.split(/\n/);
|
|
15
15
|
}
|
|
16
16
|
function seedSpec(spec = {}) {
|
|
17
17
|
return Object.assign({ tag: '', name: '', type: '', optional: false, description: '', problems: [], source: [] }, spec);
|
|
@@ -530,6 +530,48 @@ var CommentParser = (function (exports) {
|
|
|
530
530
|
};
|
|
531
531
|
}
|
|
532
532
|
|
|
533
|
+
var __rest$2 = (window && window.__rest) || function (s, e) {
|
|
534
|
+
var t = {};
|
|
535
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
536
|
+
t[p] = s[p];
|
|
537
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
538
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
539
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
540
|
+
t[p[i]] = s[p[i]];
|
|
541
|
+
}
|
|
542
|
+
return t;
|
|
543
|
+
};
|
|
544
|
+
const order = [
|
|
545
|
+
'end',
|
|
546
|
+
'description',
|
|
547
|
+
'postType',
|
|
548
|
+
'type',
|
|
549
|
+
'postName',
|
|
550
|
+
'name',
|
|
551
|
+
'postTag',
|
|
552
|
+
'tag',
|
|
553
|
+
'postDelimiter',
|
|
554
|
+
'delimiter',
|
|
555
|
+
'start',
|
|
556
|
+
];
|
|
557
|
+
function crlf(ending) {
|
|
558
|
+
const normalize = (source) => source.replace(/\r*$/, ending === 'LF' ? '' : '\r');
|
|
559
|
+
function update(line) {
|
|
560
|
+
const { tokens } = line;
|
|
561
|
+
for (const f of order) {
|
|
562
|
+
if (tokens[f] !== '') {
|
|
563
|
+
tokens[f] = normalize(tokens[f]);
|
|
564
|
+
break;
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
return Object.assign(Object.assign({}, line), { tokens });
|
|
568
|
+
}
|
|
569
|
+
return (_a) => {
|
|
570
|
+
var { source } = _a, fields = __rest$2(_a, ["source"]);
|
|
571
|
+
return rewireSource(Object.assign(Object.assign({}, fields), { source: source.map(update) }));
|
|
572
|
+
};
|
|
573
|
+
}
|
|
574
|
+
|
|
533
575
|
function flow(...transforms) {
|
|
534
576
|
return (block) => transforms.reduce((block, t) => t(block), block);
|
|
535
577
|
}
|
|
@@ -583,6 +625,7 @@ var CommentParser = (function (exports) {
|
|
|
583
625
|
flow: flow,
|
|
584
626
|
align: align,
|
|
585
627
|
indent: indent,
|
|
628
|
+
crlf: crlf,
|
|
586
629
|
};
|
|
587
630
|
const tokenizers = {
|
|
588
631
|
tag: tagTokenizer,
|
package/es6/index.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ import tagTokenizer from './parser/tokenizers/tag';
|
|
|
5
5
|
import typeTokenizer from './parser/tokenizers/type';
|
|
6
6
|
import alignTransform from './transforms/align';
|
|
7
7
|
import indentTransform from './transforms/indent';
|
|
8
|
+
import crlfTransform from './transforms/crlf';
|
|
8
9
|
import { flow as flowTransform } from './transforms/index';
|
|
9
10
|
export * from './primitives';
|
|
10
11
|
export declare function parse(source: string, options?: Partial<ParserOptions>): import("./primitives").Block[];
|
|
@@ -14,6 +15,7 @@ export declare const transforms: {
|
|
|
14
15
|
flow: typeof flowTransform;
|
|
15
16
|
align: typeof alignTransform;
|
|
16
17
|
indent: typeof indentTransform;
|
|
18
|
+
crlf: typeof crlfTransform;
|
|
17
19
|
};
|
|
18
20
|
export declare const tokenizers: {
|
|
19
21
|
tag: typeof tagTokenizer;
|
package/es6/index.js
CHANGED
|
@@ -6,6 +6,7 @@ import typeTokenizer from './parser/tokenizers/type';
|
|
|
6
6
|
import getStringifier from './stringifier/index';
|
|
7
7
|
import alignTransform from './transforms/align';
|
|
8
8
|
import indentTransform from './transforms/indent';
|
|
9
|
+
import crlfTransform from './transforms/crlf';
|
|
9
10
|
import { flow as flowTransform } from './transforms/index';
|
|
10
11
|
export * from './primitives';
|
|
11
12
|
export function parse(source, options = {}) {
|
|
@@ -17,6 +18,7 @@ export const transforms = {
|
|
|
17
18
|
flow: flowTransform,
|
|
18
19
|
align: alignTransform,
|
|
19
20
|
indent: indentTransform,
|
|
21
|
+
crlf: crlfTransform,
|
|
20
22
|
};
|
|
21
23
|
export const tokenizers = {
|
|
22
24
|
tag: tagTokenizer,
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
2
|
+
var t = {};
|
|
3
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
4
|
+
t[p] = s[p];
|
|
5
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
6
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
7
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
8
|
+
t[p[i]] = s[p[i]];
|
|
9
|
+
}
|
|
10
|
+
return t;
|
|
11
|
+
};
|
|
12
|
+
import { rewireSource } from '../util';
|
|
13
|
+
const order = [
|
|
14
|
+
'end',
|
|
15
|
+
'description',
|
|
16
|
+
'postType',
|
|
17
|
+
'type',
|
|
18
|
+
'postName',
|
|
19
|
+
'name',
|
|
20
|
+
'postTag',
|
|
21
|
+
'tag',
|
|
22
|
+
'postDelimiter',
|
|
23
|
+
'delimiter',
|
|
24
|
+
'start',
|
|
25
|
+
];
|
|
26
|
+
export default function crlf(ending) {
|
|
27
|
+
const normalize = (source) => source.replace(/\r*$/, ending === 'LF' ? '' : '\r');
|
|
28
|
+
function update(line) {
|
|
29
|
+
const { tokens } = line;
|
|
30
|
+
for (const f of order) {
|
|
31
|
+
if (tokens[f] !== '') {
|
|
32
|
+
tokens[f] = normalize(tokens[f]);
|
|
33
|
+
break;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return Object.assign(Object.assign({}, line), { tokens });
|
|
37
|
+
}
|
|
38
|
+
return (_a) => {
|
|
39
|
+
var { source } = _a, fields = __rest(_a, ["source"]);
|
|
40
|
+
return rewireSource(Object.assign(Object.assign({}, fields), { source: source.map(update) }));
|
|
41
|
+
};
|
|
42
|
+
}
|
package/es6/util.js
CHANGED
|
@@ -8,7 +8,7 @@ export function splitSpace(source) {
|
|
|
8
8
|
: [source.slice(0, matches[0].length), source.slice(matches[0].length)];
|
|
9
9
|
}
|
|
10
10
|
export function splitLines(source) {
|
|
11
|
-
return source.split(/\
|
|
11
|
+
return source.split(/\n/);
|
|
12
12
|
}
|
|
13
13
|
export function seedBlock(block = {}) {
|
|
14
14
|
return Object.assign({ description: '', tags: [], source: [], problems: [] }, block);
|
package/lib/index.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ import tagTokenizer from './parser/tokenizers/tag';
|
|
|
5
5
|
import typeTokenizer from './parser/tokenizers/type';
|
|
6
6
|
import alignTransform from './transforms/align';
|
|
7
7
|
import indentTransform from './transforms/indent';
|
|
8
|
+
import crlfTransform from './transforms/crlf';
|
|
8
9
|
import { flow as flowTransform } from './transforms/index';
|
|
9
10
|
export * from './primitives';
|
|
10
11
|
export declare function parse(source: string, options?: Partial<ParserOptions>): import("./primitives").Block[];
|
|
@@ -14,6 +15,7 @@ export declare const transforms: {
|
|
|
14
15
|
flow: typeof flowTransform;
|
|
15
16
|
align: typeof alignTransform;
|
|
16
17
|
indent: typeof indentTransform;
|
|
18
|
+
crlf: typeof crlfTransform;
|
|
17
19
|
};
|
|
18
20
|
export declare const tokenizers: {
|
|
19
21
|
tag: typeof tagTokenizer;
|
package/lib/index.js
CHANGED
|
@@ -19,6 +19,7 @@ const type_1 = require("./parser/tokenizers/type");
|
|
|
19
19
|
const index_2 = require("./stringifier/index");
|
|
20
20
|
const align_1 = require("./transforms/align");
|
|
21
21
|
const indent_1 = require("./transforms/indent");
|
|
22
|
+
const crlf_1 = require("./transforms/crlf");
|
|
22
23
|
const index_3 = require("./transforms/index");
|
|
23
24
|
__exportStar(require("./primitives"), exports);
|
|
24
25
|
function parse(source, options = {}) {
|
|
@@ -32,6 +33,7 @@ exports.transforms = {
|
|
|
32
33
|
flow: index_3.flow,
|
|
33
34
|
align: align_1.default,
|
|
34
35
|
indent: indent_1.default,
|
|
36
|
+
crlf: crlf_1.default,
|
|
35
37
|
};
|
|
36
38
|
exports.tokenizers = {
|
|
37
39
|
tag: tag_1.default,
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
3
|
+
var t = {};
|
|
4
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
5
|
+
t[p] = s[p];
|
|
6
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
7
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
8
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
9
|
+
t[p[i]] = s[p[i]];
|
|
10
|
+
}
|
|
11
|
+
return t;
|
|
12
|
+
};
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
const util_1 = require("../util");
|
|
15
|
+
const order = [
|
|
16
|
+
'end',
|
|
17
|
+
'description',
|
|
18
|
+
'postType',
|
|
19
|
+
'type',
|
|
20
|
+
'postName',
|
|
21
|
+
'name',
|
|
22
|
+
'postTag',
|
|
23
|
+
'tag',
|
|
24
|
+
'postDelimiter',
|
|
25
|
+
'delimiter',
|
|
26
|
+
'start',
|
|
27
|
+
];
|
|
28
|
+
function crlf(ending) {
|
|
29
|
+
const normalize = (source) => source.replace(/\r*$/, ending === 'LF' ? '' : '\r');
|
|
30
|
+
function update(line) {
|
|
31
|
+
const { tokens } = line;
|
|
32
|
+
for (const f of order) {
|
|
33
|
+
if (tokens[f] !== '') {
|
|
34
|
+
tokens[f] = normalize(tokens[f]);
|
|
35
|
+
break;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return Object.assign(Object.assign({}, line), { tokens });
|
|
39
|
+
}
|
|
40
|
+
return (_a) => {
|
|
41
|
+
var { source } = _a, fields = __rest(_a, ["source"]);
|
|
42
|
+
return util_1.rewireSource(Object.assign(Object.assign({}, fields), { source: source.map(update) }));
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
exports.default = crlf;
|
package/lib/util.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "comment-parser",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.6-beta.0",
|
|
4
4
|
"description": "Generic JSDoc-like comment parser",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -53,4 +53,4 @@
|
|
|
53
53
|
},
|
|
54
54
|
"homepage": "https://github.com/syavorsky/comment-parser",
|
|
55
55
|
"dependencies": {}
|
|
56
|
-
}
|
|
56
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -6,6 +6,7 @@ import typeTokenizer from './parser/tokenizers/type';
|
|
|
6
6
|
import getStringifier from './stringifier/index';
|
|
7
7
|
import alignTransform from './transforms/align';
|
|
8
8
|
import indentTransform from './transforms/indent';
|
|
9
|
+
import crlfTransform from './transforms/crlf';
|
|
9
10
|
import { flow as flowTransform } from './transforms/index';
|
|
10
11
|
|
|
11
12
|
export * from './primitives';
|
|
@@ -21,6 +22,7 @@ export const transforms = {
|
|
|
21
22
|
flow: flowTransform,
|
|
22
23
|
align: alignTransform,
|
|
23
24
|
indent: indentTransform,
|
|
25
|
+
crlf: crlfTransform,
|
|
24
26
|
};
|
|
25
27
|
|
|
26
28
|
export const tokenizers = {
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { Transform } from './index';
|
|
2
|
+
import { Block, Line } from '../primitives';
|
|
3
|
+
import { rewireSource } from '../util';
|
|
4
|
+
|
|
5
|
+
const order = [
|
|
6
|
+
'end',
|
|
7
|
+
'description',
|
|
8
|
+
'postType',
|
|
9
|
+
'type',
|
|
10
|
+
'postName',
|
|
11
|
+
'name',
|
|
12
|
+
'postTag',
|
|
13
|
+
'tag',
|
|
14
|
+
'postDelimiter',
|
|
15
|
+
'delimiter',
|
|
16
|
+
'start',
|
|
17
|
+
];
|
|
18
|
+
|
|
19
|
+
export type Ending = 'LF' | 'CRLF';
|
|
20
|
+
|
|
21
|
+
export default function crlf(ending: Ending): Transform {
|
|
22
|
+
const normalize = (source: string): string =>
|
|
23
|
+
source.replace(/\r*$/, ending === 'LF' ? '' : '\r');
|
|
24
|
+
|
|
25
|
+
function update(line: Line): Line {
|
|
26
|
+
const { tokens } = line;
|
|
27
|
+
for (const f of order) {
|
|
28
|
+
if (tokens[f] !== '') {
|
|
29
|
+
tokens[f] = normalize(tokens[f]);
|
|
30
|
+
break;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return { ...line, tokens };
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return ({ source, ...fields }: Block): Block =>
|
|
37
|
+
rewireSource({ ...fields, source: source.map(update) });
|
|
38
|
+
}
|
package/src/util.ts
CHANGED
|
@@ -12,7 +12,7 @@ export function splitSpace(source: string): [string, string] {
|
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
export function splitLines(source: string): string[] {
|
|
15
|
-
return source.split(/\
|
|
15
|
+
return source.split(/\n/);
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
export function seedBlock(block: Partial<Block> = {}): Block {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import getParser, { Parser } from '../../src/parser/source-parser';
|
|
2
|
-
import {
|
|
2
|
+
import { Line } from '../../src/primitives';
|
|
3
3
|
import { splitLines, seedBlock, seedTokens } from '../../src/util';
|
|
4
4
|
|
|
5
5
|
let _parse: Parser;
|
|
@@ -235,3 +235,51 @@ test('start line number', () => {
|
|
|
235
235
|
|
|
236
236
|
expect(parsed).toEqual([null, block]);
|
|
237
237
|
});
|
|
238
|
+
|
|
239
|
+
test('carriage returns', () => {
|
|
240
|
+
const source = splitLines(
|
|
241
|
+
['/**', ' * description', ' *', ' */', ''].join('\r\n')
|
|
242
|
+
);
|
|
243
|
+
|
|
244
|
+
const parsed = source.map(getParser());
|
|
245
|
+
|
|
246
|
+
const block = [
|
|
247
|
+
{
|
|
248
|
+
number: 0,
|
|
249
|
+
source: '/**\r',
|
|
250
|
+
tokens: seedTokens({
|
|
251
|
+
delimiter: '/**',
|
|
252
|
+
postDelimiter: '\r',
|
|
253
|
+
}),
|
|
254
|
+
},
|
|
255
|
+
{
|
|
256
|
+
number: 1,
|
|
257
|
+
source: ' * description\r',
|
|
258
|
+
tokens: seedTokens({
|
|
259
|
+
start: ' ',
|
|
260
|
+
delimiter: '*',
|
|
261
|
+
postDelimiter: ' ',
|
|
262
|
+
description: 'description\r',
|
|
263
|
+
}),
|
|
264
|
+
},
|
|
265
|
+
{
|
|
266
|
+
number: 2,
|
|
267
|
+
source: ' *\r',
|
|
268
|
+
tokens: seedTokens({
|
|
269
|
+
start: ' ',
|
|
270
|
+
delimiter: '*',
|
|
271
|
+
postDelimiter: '\r',
|
|
272
|
+
}),
|
|
273
|
+
},
|
|
274
|
+
{
|
|
275
|
+
number: 3,
|
|
276
|
+
source: ' */\r',
|
|
277
|
+
tokens: seedTokens({
|
|
278
|
+
start: ' ',
|
|
279
|
+
end: '*/\r',
|
|
280
|
+
}),
|
|
281
|
+
},
|
|
282
|
+
];
|
|
283
|
+
|
|
284
|
+
expect(parsed).toEqual([...nulls(3), block, null]);
|
|
285
|
+
});
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import crlf, { Ending } from '../../src/transforms/crlf';
|
|
2
|
+
import getParser, { Parser } from '../../src/parser/index';
|
|
3
|
+
import getStringifier, { Stringifier } from '../../src/stringifier/index';
|
|
4
|
+
|
|
5
|
+
const tests = [
|
|
6
|
+
[
|
|
7
|
+
'no CR',
|
|
8
|
+
'CRLF',
|
|
9
|
+
`
|
|
10
|
+
/**
|
|
11
|
+
* description
|
|
12
|
+
*
|
|
13
|
+
*/`,
|
|
14
|
+
`
|
|
15
|
+
/**\r
|
|
16
|
+
* description\r
|
|
17
|
+
*\r
|
|
18
|
+
*/\r`,
|
|
19
|
+
],
|
|
20
|
+
[
|
|
21
|
+
'mixed',
|
|
22
|
+
'CRLF',
|
|
23
|
+
`
|
|
24
|
+
/**
|
|
25
|
+
* description
|
|
26
|
+
*\r
|
|
27
|
+
*/`,
|
|
28
|
+
`
|
|
29
|
+
/**\r
|
|
30
|
+
* description\r
|
|
31
|
+
*\r
|
|
32
|
+
*/\r`,
|
|
33
|
+
],
|
|
34
|
+
[
|
|
35
|
+
'no CR',
|
|
36
|
+
'LF',
|
|
37
|
+
`
|
|
38
|
+
/**
|
|
39
|
+
* description
|
|
40
|
+
*
|
|
41
|
+
*/`,
|
|
42
|
+
`
|
|
43
|
+
/**
|
|
44
|
+
* description
|
|
45
|
+
*
|
|
46
|
+
*/`,
|
|
47
|
+
],
|
|
48
|
+
[
|
|
49
|
+
'mixed',
|
|
50
|
+
'LF',
|
|
51
|
+
`
|
|
52
|
+
/**
|
|
53
|
+
* description
|
|
54
|
+
*\r
|
|
55
|
+
*/`,
|
|
56
|
+
`
|
|
57
|
+
/**
|
|
58
|
+
* description
|
|
59
|
+
*
|
|
60
|
+
*/`,
|
|
61
|
+
],
|
|
62
|
+
];
|
|
63
|
+
|
|
64
|
+
test.each(tests)('CRLF - %s to %s', (name, mode, source, expected) => {
|
|
65
|
+
expected = expected.slice(1);
|
|
66
|
+
const parsed = getParser()(source);
|
|
67
|
+
const normalized = crlf(mode as Ending)(parsed[0]);
|
|
68
|
+
const out = getStringifier()(normalized);
|
|
69
|
+
expect(out).toBe(expected);
|
|
70
|
+
});
|
package/tests/unit/util.spec.ts
CHANGED
|
@@ -8,9 +8,9 @@ import {
|
|
|
8
8
|
} from '../../src/util';
|
|
9
9
|
|
|
10
10
|
test.each([
|
|
11
|
-
['win', 'a\r\nb\r\nc', ['a', 'b', 'c']],
|
|
11
|
+
['win', 'a\r\nb\r\nc', ['a\r', 'b\r', 'c']],
|
|
12
12
|
['unix', 'a\nb\nc', ['a', 'b', 'c']],
|
|
13
|
-
['mixed', 'a\nb\r\nc', ['a', 'b', 'c']],
|
|
13
|
+
['mixed', 'a\nb\r\nc', ['a', 'b\r', 'c']],
|
|
14
14
|
['none', 'abc', ['abc']],
|
|
15
15
|
])('spliLines - %s', (name, source, parsed) =>
|
|
16
16
|
expect(splitLines(source)).toEqual(parsed)
|