2013-03-05 148 views
0

我正在使用Esprima解析器,它输出一个AST格式,它与Mozilla Spider Monkey Parser API兼容。“默认值”包含什么?

Mozilla Docs,它指定Function节点:

interface Function <: Node { 
    id: Identifier | null; 
    params: [ Pattern ]; 
    defaults: [ Expression ]; 
    rest: Identifier | null; 
    body: BlockStatement | Expression; 
    generator: boolean; 
    expression: boolean; 
} 

会是什么defaults属性包含哪些内容?它总是显示为一个空数组。

回答

0

默认的Mozilla JS AST包含ES6默认参数值。

例如,

function t(i = 20) { } 

defaults will be [{ type: 'Literal', value: 20 }]. 

因为它是基于ES6草案,Esprima主分支不承认它。