Skip to content

Commit

Permalink
feat(aliases): add return alias for returns parser
Browse files Browse the repository at this point in the history
  • Loading branch information
PreslavKozovski committed Feb 10, 2021
1 parent 9e94233 commit 2f9b1dc
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
18 changes: 14 additions & 4 deletions dss.js
Expand Up @@ -33,14 +33,18 @@ let dss = ( function() {
_dss.parsers[ name ] = callback;
};

// Store parsers
_dss.aliases = {};

/**
* Add an alias for a parser.
*
* @param {String} newName - The name of the new variable.
* @param {String} oldName - The name of the existing parser to use.
* @param {String} aliasParserName - The name of the new parser.
* @param {String} existingParserName - The name of the existing parser.
*/
_dss.alias = function( newName, oldName ) {
_dss.parsers[ newName ] = _dss.parsers[ oldName ];
_dss.alias = function( aliasParserName, existingParserName ) {
_dss.aliases[ aliasParserName ] = existingParserName;
_dss.parsers[ aliasParserName ] = _dss.parsers[ existingParserName ];
};

/**
Expand Down Expand Up @@ -224,6 +228,10 @@ let dss = ( function() {
let variable = _dss.parsers[ name ];
let index = block.indexOf( line );

if ( _dss.aliases[name] ) {
name = _dss.aliases[name];
}

line = {};
line[ name ] = ( variable ) ? variable.apply( null, [ index, description, block, file, name ] ) : ''; // eslint-disable-line no-useless-call

Expand Down Expand Up @@ -633,4 +641,6 @@ dss.parser('returns', (i, line, block, file) => { // eslint-disable-line no-unus
};
});

dss.alias('return', 'returns');

module.exports = dss;
2 changes: 1 addition & 1 deletion test/data/css/all-annotations.scss
Expand Up @@ -17,5 +17,5 @@
* @param par3 - paramThree description
* @param par4
* @returns {number} - return description
* @returns - no type - return description
* @return - no type - return description
*/
2 changes: 1 addition & 1 deletion test/data/scss/all-annotations.scss
Expand Up @@ -16,4 +16,4 @@
/// @param par3 - paramThree description
/// @param par4
/// @returns {number} - return description
/// @returns - no type - return description
/// @return - no type - return description

0 comments on commit 2f9b1dc

Please sign in to comment.