diff --git a/lib/ast.js b/lib/ast.js index 2e539cff..1892a30a 100644 --- a/lib/ast.js +++ b/lib/ast.js @@ -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" diff --git a/lib/output.js b/lib/output.js index 135636b9..2a8cc201 100644 --- a/lib/output.js +++ b/lib/output.js @@ -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(); diff --git a/lib/parse.js b/lib/parse.js index 95a9f776..f6ea9b40 100644 --- a/lib/parse.js +++ b/lib/parse.js @@ -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(",");