feat(comments): add support for JavaDoc blocks parsing

This commit is contained in:
PreslavKozovski 2021-02-08 17:25:47 +02:00
Родитель 36203e3fef
Коммит 3d13d87d61
14 изменённых файлов: 241 добавлений и 126 удалений

12
dss.js
Просмотреть файл

@ -293,12 +293,13 @@ let dss = ( function() {
* @returns {boolean} - Result of check.
*/
let parseMultiLine = function( line ) {
let cleaned = line.replace( /\s*\/\*/, '' );
return cleaned.replace( /\*\//, '' );
let cleaned = line.replace( /\s*\/\*/, '' ).trim();
cleaned = cleaned.replace( /\*\//, '' );
return cleaned.replace( /^\*/, '' );
};
/* eslint-disable no-param-reassign */
lines = String(lines);
lines.split( /\n/ ).forEach( function( line ) {
lines.split( /\n/ ).forEach(( line, index, linesArr ) => {
lineNum = lineNum + 1;
line = String(line);
@ -333,8 +334,9 @@ let dss = ( function() {
// Store current block if done
if ( !singleLineComment( line ) && !insideMultiLineBlock ) {
if ( currentBlock ) {
let type = _dss.getKeyType(_dss.trim(line));
let key = _dss.getKey(_dss.trim(line), type);
const lineToParse = endMultiLineComment(line) ? String(linesArr[index + 1]) : line;
const type = _dss.getKeyType(_dss.trim(lineToParse));
const key = _dss.getKey(_dss.trim(lineToParse), type);
_blocks.push( _dss.normalize( currentBlock ) );
_blockValues.push({

Просмотреть файл

@ -0,0 +1,20 @@
/**
* @name Button
* @description Your standard form button.
* @state :hover - Highlights when hovering.
* @state :disabled - Dims the button when disabled.
* @state .primary - Indicates button is the primary action.
* @state .smaller - A smaller button
* @markup <button>This is a button</button>
* @deprecated 123.321
* @deprecatedDescription This is deprecated.
* @group Buttons
* @type Color
* @subtype Text-Color
* @param {string} par1 - parmOne description
* @param {function} par2 - paramTwo description
* @param par3 - paramThree description
* @param par4
* @returns {number} - return description
* @returns - no type - return description
*/

Просмотреть файл

@ -0,0 +1,57 @@
/**
* @name Button
* @description Button description
* @type myType
* @key myKey
*/
$button-bg: white;
/**
* @name Grid
*/
$grid-bg: black;
/**
* @name Spacing
*/
$spacing: (
0: 0,
1: 4px,
xl: 24px,
thin: 2px,
hair: 1px
) !default;
/**
* @name Decimal Round
*/
@function decimal-round($float, $digits: 2) {
$pow: pow(10, $digits);
@return round($float * $pow) / $pow;
}
/**
* @name k-d-flex
*/
.k-d-flex { display: flex; }
/**
* @name k-resize-none
*/
/**
* @name Resize Both
* @type selector
* @key .k-resize-both
*/
$utils-resize: (
none,
both
) !default;
@each $resize in $utils-resize {
// sass-lint:disable-block no-important
.k-resize-#{$resize} { resize: $resize !important; }
}

14
test/data/css/button.scss Normal file
Просмотреть файл

@ -0,0 +1,14 @@
/**
* @name Button
* @description Your standard form button.
*
* @state :hover - Highlights when hovering.
* @state :disabled - Dims the button when disabled.
* @state .primary - Indicates button is the primary action.
* @state .smaller - A smaller button
*
* @markup
* <span>
* <button>This is a button</button>
* </span>
*/

Просмотреть файл

@ -0,0 +1,5 @@
/**
* @description Your standard description with an @ in it
* second row test
* @name Special character "@" description test.
*/

Просмотреть файл

@ -0,0 +1,8 @@
/**
* @name Button
* @markup
* <span>
* <button>This is a button</button>
* </span>
* @description Your standard form button.
*/

Просмотреть файл

@ -0,0 +1,5 @@
/**
* @description Your standard form button.
* second row test
* @name Multi Line description
*/

Просмотреть файл

Просмотреть файл

Просмотреть файл

Просмотреть файл

Просмотреть файл

@ -3,10 +3,12 @@ const dss = require('../dss');
const fs = require('fs');
const path = require('path');
describe('Core tests', function() {
[ 'css', 'scss' ].forEach((ext) => {
describe(`Core tests - ${ext}`, function() {
it('should should parse the data', function() {
const file = fs.readFileSync(path.join(__dirname, 'data/button.scss'), 'utf8');
const file = fs.readFileSync(path.join(__dirname, `data/${ext}/button.scss`), 'utf8');
dss.parse(file, {}, function(parsed) {
const data = parsed.blocks[0];
@ -34,7 +36,7 @@ describe('Core tests', function() {
});
it('multiline markup is correctly parsed when not as last parser', function() {
const file = fs.readFileSync(path.join(__dirname, 'data/markup-not-last.scss'), 'utf8');
const file = fs.readFileSync(path.join(__dirname, `data/${ext}/markup-not-last.scss`), 'utf8');
dss.parse(file, {}, function(parsed) {
const data = parsed.blocks[0];
@ -55,7 +57,7 @@ describe('Core tests', function() {
});
it('multiline description is correctly parsed', function() {
const file = fs.readFileSync(path.join(__dirname, 'data/multi-line-description.scss'), 'utf8');
const file = fs.readFileSync(path.join(__dirname, `data/${ext}/multi-line-description.scss`), 'utf8');
dss.parse(file, {}, function(parsed) {
const data = parsed.blocks[0];
@ -66,7 +68,7 @@ describe('Core tests', function() {
});
it('description with the @ symbol is correctly parsed', function() {
const file = fs.readFileSync(path.join(__dirname, 'data/description-with-special-symbol.scss'), 'utf8');
const file = fs.readFileSync(path.join(__dirname, `data/${ext}/description-with-special-symbol.scss`), 'utf8');
dss.parse(file, {}, function(parsed) {
const data = parsed.blocks[0];
@ -77,7 +79,7 @@ describe('Core tests', function() {
});
it('should should parse all annotations', function() {
const file = fs.readFileSync(path.join(__dirname, 'data/all-annotations.scss'), 'utf8');
const file = fs.readFileSync(path.join(__dirname, `data/${ext}/all-annotations.scss`), 'utf8');
dss.parse(file, {}, function(parsed) {
const data = parsed.blocks[0];
@ -120,7 +122,7 @@ describe('Core tests', function() {
});
it('should should parse and include key values', function() {
const file = fs.readFileSync(path.join(__dirname, 'data/all-key-types.scss'), 'utf8');
const file = fs.readFileSync(path.join(__dirname, `data/${ext}/all-key-types.scss`), 'utf8');
dss.parse(file, {}, function(parsed) {
const blocks = parsed.blocks;
@ -156,4 +158,6 @@ describe('Core tests', function() {
});
});
});
});