Closure Compiler EXTERNS for PIXI.js - annotations of user object parameters

I am preparing an externs file for the pixijs library to work with the closure compiler. The only problem I encountered is the parameters of user objects. Here is a quick example:

pixi.js source:

/** * Set the style of the text * * @param [style] {object} The style parameters * @param [style.font='bold 20pt Arial'] {string} The style and size of the font * @param [style.fill='black'] {string|number} A canvas fillstyle that will be used on the text eg 'red', '#00FF00' * @param [style.align='left'] {string} Alignment for multiline text ('left', 'center' or 'right'), does not affect single line text 

closing compiler output:

 lib/pixi-externs.js:3266: WARNING - Parse error. invalid param name "style.font" * @param [style.font='bold 20pt Arial'] {string} The style and size of the font ^ lib/pixi-externs.js:3266: WARNING - Bad type annotation. missing closing ] * @param [style.font='bold 20pt Arial'] {string} The style and size of the font ^ lib/pixi-externs.js:3267: WARNING - Parse error. invalid param name "style.fill" * @param [style.fill='black'] {string|number} A canvas fillstyle that will be used on the text eg 'red', '#00FF00' ^ lib/pixi-externs.js:3268: WARNING - Parse error. invalid param name "style.align" * @param [style.align='left'] {string} Alignment for multiline text ('left', 'center' or 'right'), does not affect single line text ^ 

How can these pixijs annotations adapt to closing compiler annotations?

If this cannot be done with annotations, can I overcome this by defining a new object?

 * @param {PIXI.TextStyleObject} style The style parameters 

and creating a separate definition for the TextStyleObject, for example:

 PIXI.TextStyleObject = {}; PIXI.TextStyleObject.font; PIXI.TextStyleObject.fill; PIXI.TextStyleObject.align; 

What is the correct way to solve this problem?

+5
source share
1 answer

For this you want to use a recording object:

 /** @param {{ * font: string, * fill: string, * align: string * }} object */ 

If you reuse the same recording object more than once, you can use typedef for the alias:

 /** @typedef {{ * font: string, * fill: string, * align: string * }} */ var PixiStyleOptions; /** @param {PixiStyleOptions} object */ 
+1
source

Source: https://habr.com/ru/post/1237571/


All Articles