Implement harmony generators and yield
Uses #716's implementation and adds tests. Fixes #716.
This commit is contained in:
committed by
Richard van Velzen
parent
634f231b78
commit
91cdb93e57
@@ -226,6 +226,10 @@ function OutputStream(options) {
|
||||
OUTPUT += str;
|
||||
};
|
||||
|
||||
var star = function(){
|
||||
print("*");
|
||||
}
|
||||
|
||||
var space = options.beautify ? function() {
|
||||
print(" ");
|
||||
} : function() {
|
||||
@@ -343,6 +347,7 @@ function OutputStream(options) {
|
||||
should_break : function() { return options.width && this.current_width() >= options.width },
|
||||
newline : newline,
|
||||
print : print,
|
||||
star : star,
|
||||
space : space,
|
||||
comma : comma,
|
||||
colon : colon,
|
||||
@@ -783,6 +788,9 @@ function OutputStream(options) {
|
||||
var self = this;
|
||||
if (!nokeyword) {
|
||||
output.print("function");
|
||||
if (this.is_generator) {
|
||||
output.star();
|
||||
}
|
||||
if (self.name) {
|
||||
output.space();
|
||||
}
|
||||
@@ -1203,8 +1211,13 @@ function OutputStream(options) {
|
||||
output.print(self.operator);
|
||||
});
|
||||
DEFPRINT(AST_Binary, function(self, output){
|
||||
var isYield = (self.left.operator == "yield" || self.left.operator === "yield*");
|
||||
var op = self.operator;
|
||||
|
||||
isYield && output.print("(");
|
||||
self.left.print(output);
|
||||
isYield && output.print(")");
|
||||
|
||||
if (op[0] == ">" /* ">>" ">>>" ">" ">=" */
|
||||
&& self.left instanceof AST_UnaryPostfix
|
||||
&& self.left.operator == "--") {
|
||||
@@ -1214,7 +1227,12 @@ function OutputStream(options) {
|
||||
// the space is optional depending on "beautify"
|
||||
output.space();
|
||||
}
|
||||
|
||||
isYield = (self.right.operator == "yield" || self.right.operator === "yield*");
|
||||
isYield && output.print("(");
|
||||
output.print(op);
|
||||
isYield && output.print(")");
|
||||
|
||||
if ((op == "<" || op == "<<")
|
||||
&& self.right instanceof AST_UnaryPrefix
|
||||
&& self.right.operator == "!"
|
||||
|
||||
Reference in New Issue
Block a user