简体   繁体   English

用于PIXI.js的Closure Compiler EXTERNS-自定义对象参数注释

[英]Closure Compiler EXTERNS for PIXI.js - custom object parameter annotations

I am preparing externs file for pixijs library to work with closure compiler. 我正在为pixijs库准备externs文件,以便与闭包编译器一起使用。 The only problem I am having so far is with custom object parameters. 到目前为止,我唯一的问题是自定义对象参数。 Here is a short example: 这是一个简短的示例:

pixi.js source: pixi.js来源:

/**
 * 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

closure 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 be adapted to closure compiler annotations? 这些pixijs注释如何适应闭包编译器注释?

If there is no way to achieve this through annotations, could I overcome this by defining a new object ? 如果没有办法通过注释实现此目的,我可以通过定义一个新对象来克服它吗?

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

and creating a separate TextStyleObject object definition like so ? 并像这样创建一个单独的TextStyleObject对象定义?

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

What is the correct way to solve this issue? 解决此问题的正确方法是什么?

You'll want to use a record object to do this: 您将要使用一个记录对象来执行此操作:

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

If you find yourself re-using the same record object more than once, you can use a typedef to alias it: 如果发现自己多次重复使用同一记录对象,则可以使用typedef对其进行别名:

/** @typedef {{
 *        font: string,
 *        fill: string,
 *        align: string
 *      }}
 */
 var PixiStyleOptions;

/** @param {PixiStyleOptions} object */

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM