index.js
function decorateClasses(node) {
    // check for class nodes
    var clsNode = getCommentedClassNode(node);
    if (!clsNode || !clsNode.jsdoc || clsNode.jsdoc.props.length === 0) {
        return;
    }

    var clsSrc = clsNode.node.source();
    if (clsSrc[0] !== "{") {
        // something isn't right, bail.
        return;
    }

    // work out line endings (find first \n and see if it has \r before it)
    var nl = "\n";
    var newlineIndex = clsSrc.indexOf("\n");
    if (clsSrc[newlineIndex-1] === "\r") {
        nl = "\r\n";
    }

    // use the same indent as the next non-blank line
    var indent = "";
    var lines = clsSrc.split(nl);
    for (var i = 1; i < lines.length; i++) { //i=1 to skip the starting {
        if (lines[i].length > 0) {
            var whitespaceMatch = /^[ \t]+/.exec(lines[i]); // match spaces or tabs
            if (whitespaceMatch) {
                indent = whitespaceMatch[0];
                break;
            }
        }
    }

    // work out what to inject into the class definition
    var fieldTypeDecls = clsNode.jsdoc.props.map(function(p) {
        return indent + p.name + ": " + p.type + ";";
    }).join(nl);

    clsNode.node.update("{" + nl + fieldTypeDecls + clsSrc.substr(1));
}
function decorateClasses(node) {
    // check for class nodes
    var clsNode = getCommentedClassNode(node);
    if (!clsNode || !clsNode.jsdoc || clsNode.jsdoc.props.length === 0) {
        return;
    }

    var clsSrc = clsNode.node.source();
    if (clsSrc[0] !== "{") {
        // something isn't right, bail.
        return;
    }

    // work out line endings (find first \n and see if it has \r before it)
    var nl = "\n";
    var newlineIndex = clsSrc.indexOf("\n");
    if (clsSrc[newlineIndex-1] === "\r") {
        nl = "\r\n";
    }

    // use the same indent as the next non-blank line
    var indent = "";
    var lines = clsSrc.split(nl);
    for (var i = 1; i < lines.length; i++) { //i=1 to skip the starting {
        if (lines[i].length > 0) {
            var whitespaceMatch = /^[ \t]+/.exec(lines[i]); // match spaces or tabs
            if (whitespaceMatch) {
                indent = whitespaceMatch[0];
                break;
            }
        }
    }

    // work out what to inject into the class definition
    var fieldTypeDecls = clsNode.jsdoc.props.map(function(p) {
        return indent + p.name + ": " + p.type + ";";
    }).join(nl);

    clsNode.node.update("{" + nl + fieldTypeDecls + clsSrc.substr(1));
}
function decorateClasses ( node ) { // check for class nodes var clsNode = getCommentedClassNode ( node ) ; if ( ! clsNode || ! clsNode . jsdoc || clsNode . jsdoc . props . length === 0 ) { return ; } var clsSrc = clsNode . node . source ( ) ; if ( clsSrc [ 0 ] !== "{" ) { // something isn't right, bail. return ; } // work out line endings (find first \n and see if it has \r before it) var nl = "\n" ; var newlineIndex = clsSrc . indexOf ( "\n" ) ; if ( clsSrc [ newlineIndex - 1 ] === "\r" ) { nl = "\r\n" ; } // use the same indent as the next non-blank line var indent = "" ; var lines = clsSrc . split ( nl ) ; for ( var i = 1 ; i < lines . length ; i ++ ) { //i=1 to skip the starting { if ( lines [ i ] . length > 0 ) { var whitespaceMatch = / ^[ \t]+ / . exec ( lines [ i ] ) ; // match spaces or tabs if ( whitespaceMatch ) { indent = whitespaceMatch [ 0 ] ; break ; } } } // work out what to inject into the class definition var fieldTypeDecls = clsNode . jsdoc . props . map ( function ( p ) { return indent + p . name + ": " + p . type + ";" ; } ) . join ( nl ) ; clsNode . node . update ( "{" + nl + fieldTypeDecls + clsSrc . substr ( 1 ) ) ; }
Modify ES6 classes by adding 'field declarations' to them if the constructor has JSDoc.
Modify ES6 classes by adding field declarations to them if the constructor has JSDoc .