Can't process multiple comments that start and end on the same line
Opened this issue · 0 comments
dglsparsons commented
Example in the playground:
// Invoking parser with default config covers the most genearic cases.
// Note how /*** and /* blocks are ignored
/** foo One-liner *//** @some-tag {someType} someName */undefined/**
* Description may go
* over multiple lines followed by @tags
* @param {string} name the name parameter
* @param {any} value the value parameter
*//* comment here */
const parsed = parse(source);
const stringified = parsed.map((block) => stringify(block));
showParsed(parsed)
showStringified(stringified)
produces
[
{
"description": "foo One-liner *//** @some-tag {someType} someName */undefined/** Description may go over multiple lines followed by @tags",
"tags": [
{
"tag": "param",
"name": "name",
"type": "string",
"optional": false,
"description": "the name parameter",
"problems": [],
"source": [
{
"number": 6,
"source": " * @param {string} name the name parameter",
"tokens": {
"start": " ",
"delimiter": "*",
"postDelimiter": " ",
"tag": "@param",
"postTag": " ",
"name": "name",
"postName": " ",
"type": "{string}",
"postType": " ",
"description": "the name parameter",
"end": "",
"lineEnd": ""
}
}
]
},
{
"tag": "param",
"name": "value",
"type": "any",
"optional": false,
"description": "the value parameter *//* comment here",
"problems": [],
"source": [
{
"number": 7,
"source": " * @param {any} value the value parameter",
"tokens": {
"start": " ",
"delimiter": "*",
"postDelimiter": " ",
"tag": "@param",
"postTag": " ",
"name": "value",
"postName": " ",
"type": "{any}",
"postType": " ",
"description": "the value parameter",
"end": "",
"lineEnd": ""
}
},
{
"number": 8,
"source": " *//* comment here */",
"tokens": {
"start": " ",
"delimiter": "",
"postDelimiter": "",
"tag": "",
"postTag": "",
"name": "",
"postName": "",
"type": "",
"postType": "",
"description": "*//* comment here ",
"end": "*/",
"lineEnd": ""
}
}
]
}
],
"source": [
{
"number": 3,
"source": "/** foo One-liner *//** @some-tag {someType} someName */undefined/**",
"tokens": {
"start": "",
"delimiter": "/**",
"postDelimiter": " ",
"tag": "",
"postTag": "",
"name": "",
"postName": "",
"type": "",
"postType": "",
"description": "foo One-liner *//** @some-tag {someType} someName */undefined/**",
"end": "",
"lineEnd": ""
}
},
{
"number": 4,
"source": " * Description may go",
"tokens": {
"start": " ",
"delimiter": "*",
"postDelimiter": " ",
"tag": "",
"postTag": "",
"name": "",
"postName": "",
"type": "",
"postType": "",
"description": "Description may go",
"end": "",
"lineEnd": ""
}
},
{
"number": 5,
"source": " * over multiple lines followed by @tags",
"tokens": {
"start": " ",
"delimiter": "*",
"postDelimiter": " ",
"tag": "",
"postTag": "",
"name": "",
"postName": "",
"type": "",
"postType": "",
"description": "over multiple lines followed by @tags",
"end": "",
"lineEnd": ""
}
},
{
"number": 6,
"source": " * @param {string} name the name parameter",
"tokens": {
"start": " ",
"delimiter": "*",
"postDelimiter": " ",
"tag": "@param",
"postTag": " ",
"name": "name",
"postName": " ",
"type": "{string}",
"postType": " ",
"description": "the name parameter",
"end": "",
"lineEnd": ""
}
},
{
"number": 7,
"source": " * @param {any} value the value parameter",
"tokens": {
"start": " ",
"delimiter": "*",
"postDelimiter": " ",
"tag": "@param",
"postTag": " ",
"name": "value",
"postName": " ",
"type": "{any}",
"postType": " ",
"description": "the value parameter",
"end": "",
"lineEnd": ""
}
},
{
"number": 8,
"source": " *//* comment here */",
"tokens": {
"start": " ",
"delimiter": "",
"postDelimiter": "",
"tag": "",
"postTag": "",
"name": "",
"postName": "",
"type": "",
"postType": "",
"description": "*//* comment here ",
"end": "*/",
"lineEnd": ""
}
}
],
"problems": []
}
]
When instead it should produce:
[
{
"description": "foo One-liner",
"tags": [],
"source": [
{
"number": 3,
"source": "/** foo One-liner */",
"tokens": {
"start": "",
"delimiter": "/**",
"postDelimiter": " ",
"tag": "",
"postTag": "",
"name": "",
"postName": "",
"type": "",
"postType": "",
"description": "foo One-liner ",
"end": "*/",
"lineEnd": ""
}
}
],
"problems": []
},
{
"description": "",
"tags": [
{
"tag": "some-tag",
"name": "someName",
"type": "someType",
"optional": false,
"description": "",
"problems": [],
"source": [
{
"number": 4,
"source": "/** @some-tag {someType} someName */",
"tokens": {
"start": "",
"delimiter": "/**",
"postDelimiter": " ",
"tag": "@some-tag",
"postTag": " ",
"name": "someName",
"postName": " ",
"type": "{someType}",
"postType": " ",
"description": "",
"end": "*/",
"lineEnd": ""
}
}
]
}
],
"source": [
{
"number": 4,
"source": "/** @some-tag {someType} someName */",
"tokens": {
"start": "",
"delimiter": "/**",
"postDelimiter": " ",
"tag": "@some-tag",
"postTag": " ",
"name": "someName",
"postName": " ",
"type": "{someType}",
"postType": " ",
"description": "",
"end": "*/",
"lineEnd": ""
}
}
],
"problems": []
},
{
"description": "Description may go over multiple lines followed by @tags",
"tags": [
{
"tag": "param",
"name": "name",
"type": "string",
"optional": false,
"description": "the name parameter",
"problems": [],
"source": [
{
"number": 8,
"source": " * @param {string} name the name parameter",
"tokens": {
"start": " ",
"delimiter": "*",
"postDelimiter": " ",
"tag": "@param",
"postTag": " ",
"name": "name",
"postName": " ",
"type": "{string}",
"postType": " ",
"description": "the name parameter",
"end": "",
"lineEnd": ""
}
}
]
},
{
"tag": "param",
"name": "value",
"type": "any",
"optional": false,
"description": "the value parameter",
"problems": [],
"source": [
{
"number": 9,
"source": " * @param {any} value the value parameter",
"tokens": {
"start": " ",
"delimiter": "*",
"postDelimiter": " ",
"tag": "@param",
"postTag": " ",
"name": "value",
"postName": " ",
"type": "{any}",
"postType": " ",
"description": "the value parameter",
"end": "",
"lineEnd": ""
}
},
{
"number": 10,
"source": " */",
"tokens": {
"start": " ",
"delimiter": "",
"postDelimiter": "",
"tag": "",
"postTag": "",
"name": "",
"postName": "",
"type": "",
"postType": "",
"description": "",
"end": "*/",
"lineEnd": ""
}
}
]
}
],
"source": [
{
"number": 5,
"source": "/**",
"tokens": {
"start": "",
"delimiter": "/**",
"postDelimiter": "",
"tag": "",
"postTag": "",
"name": "",
"postName": "",
"type": "",
"postType": "",
"description": "",
"end": "",
"lineEnd": ""
}
},
{
"number": 6,
"source": " * Description may go",
"tokens": {
"start": " ",
"delimiter": "*",
"postDelimiter": " ",
"tag": "",
"postTag": "",
"name": "",
"postName": "",
"type": "",
"postType": "",
"description": "Description may go",
"end": "",
"lineEnd": ""
}
},
{
"number": 7,
"source": " * over multiple lines followed by @tags",
"tokens": {
"start": " ",
"delimiter": "*",
"postDelimiter": " ",
"tag": "",
"postTag": "",
"name": "",
"postName": "",
"type": "",
"postType": "",
"description": "over multiple lines followed by @tags",
"end": "",
"lineEnd": ""
}
},
{
"number": 8,
"source": " * @param {string} name the name parameter",
"tokens": {
"start": " ",
"delimiter": "*",
"postDelimiter": " ",
"tag": "@param",
"postTag": " ",
"name": "name",
"postName": " ",
"type": "{string}",
"postType": " ",
"description": "the name parameter",
"end": "",
"lineEnd": ""
}
},
{
"number": 9,
"source": " * @param {any} value the value parameter",
"tokens": {
"start": " ",
"delimiter": "*",
"postDelimiter": " ",
"tag": "@param",
"postTag": " ",
"name": "value",
"postName": " ",
"type": "{any}",
"postType": " ",
"description": "the value parameter",
"end": "",
"lineEnd": ""
}
},
{
"number": 10,
"source": " */",
"tokens": {
"start": " ",
"delimiter": "",
"postDelimiter": "",
"tag": "",
"postTag": "",
"name": "",
"postName": "",
"type": "",
"postType": "",
"description": "",
"end": "*/",
"lineEnd": ""
}
}
],
"problems": []
}
]