support generator function declare

This commit is contained in:
jchbh 2015-05-20 09:59:12 -07:00
parent 0552dbd93c
commit b7abd50b05
3 changed files with 13 additions and 1 deletions

View File

@ -359,9 +359,10 @@ var AST_Toplevel = DEFNODE("Toplevel", "globals", {
}
}, AST_Scope);
var AST_Lambda = DEFNODE("Lambda", "name argnames uses_arguments", {
var AST_Lambda = DEFNODE("Lambda", "name argnames uses_arguments isgenerator", {
$documentation: "Base class for functions",
$propdoc: {
isgenerator: "is generatorFn or not",
name: "[AST_SymbolDeclaration?] the name of this function",
argnames: "[AST_SymbolFunarg*] array of function arguments",
uses_arguments: "[boolean/S] tells whether this function accesses the arguments array"

View File

@ -220,6 +220,10 @@ function OutputStream(options) {
might_need_space = true;
};
var star = function(){
print("*");
}
var indent = options.beautify ? function(half) {
if (options.beautify) {
print(make_indent(half ? 0.5 : 0));
@ -332,6 +336,7 @@ function OutputStream(options) {
newline : newline,
print : print,
space : space,
star : star,
comma : comma,
colon : colon,
last : function() { return last },
@ -731,6 +736,8 @@ function OutputStream(options) {
var self = this;
if (!nokeyword) {
output.print("function");
if(this.isgenerator)
output.star();
}
if (self.name) {
output.space();

View File

@ -953,12 +953,16 @@ function parse($TEXT, options) {
var function_ = function(ctor) {
var in_statement = ctor === AST_Defun;
var isgenerator = is("operator", "*");
if (isgenerator)
next();
var name = is("name") ? as_symbol(in_statement ? AST_SymbolDefun : AST_SymbolLambda) : null;
if (in_statement && !name)
unexpected();
expect("(");
return new ctor({
name: name,
isgenerator: isgenerator,
argnames: (function(first, a){
while (!is("punc", ")")) {
if (first) first = false; else expect(",");