Search code examples
javascriptgoogle-closure-compilergoogle-closurevjet

Translating VJET type annotations into Closure type annotations


EBay's VJET and Google's Closure Compiler both use type annotations in Javascript comments.

Why have they chosen incompatible syntaxes?

VJET

function add(a, b) {  //< Number add(Number, Number)
    return a + b ;
}

Google Closure

/**
 * Queries a Baz for items.
 * @param {number} groupNum Subgroup id to query.
 * @param {string|number|null} term An itemName,
 *     or itemId, or null to search everything.
 */
goog.Baz.prototype.query = function(groupNum, term) {
  ...
};

Is there a way of automatically turning VJET type annotations into Google Closure type annotations?


Solution

  • There is not an automated way to tranlate vjetdocs into jsdocs but here is a manual translation for query api. First I will translate from closure's jsdoc to vjetdoc and then back to show you differences.

    /**
     * Queries a Baz for items.
     * @param {number} groupNum Subgroup id to query.
     * @param {string|number|null} term An itemName,
     *     or itemId, or null to search everything.
     */
    

    groupNum in VJET doc is first first position and type would be Number (not number) vjet uses the case sensitive EcmaScript standard type name.

    itemName is VJET doc would be a mixed type which could be Number or String. With VJETDoc currently there is no default type named Null. If there was a Null data type it would be upper case. I believe this should be added to VJET, but null can be passed in and VJET will not complain with the declarations below.

    You can write it in vjetdoc with or without names of function and params (if you don't want to repeat yourself... position takes over.

    // shortest form
    function query(groupNum, itemName) {  //< void (Number, {String|Number}?)
    
    }
    //
    // longer form - on same line as declaration
    function query(groupNum, itemName) {  //< void query(Number groupNum, {String|Number}? itemName)
    
    }
    
    // longer form mixed with jsdocs
    
    /**> void query(Number groupNum, {String|Number}? itemName);
     * 
     * Queries a Baz for items.
     * @param {number} groupNum Subgroup id to query.
     * @param {string|number|null} term An itemName,
     *     or itemId, or null to search everything.
    */
    function query(groupNum, itemName) {  
    
    }
    
    
    query(10,"test");
    query(30,20);
    query(20,null);