first attempt at including 'yield*'

This commit is contained in:
Andreas Lubbe
2013-12-23 19:32:25 -08:00
parent dab4ae9416
commit 25b1eee293
5 changed files with 9 additions and 8 deletions

View File

@@ -803,7 +803,7 @@
})();
JS_KEYWORDS = ['true', 'false', 'null', 'this', 'new', 'delete', 'typeof', 'in', 'instanceof', 'return', 'throw', 'break', 'continue', 'debugger', 'yield', 'if', 'else', 'switch', 'for', 'while', 'do', 'try', 'catch', 'finally', 'class', 'extends', 'super'];
JS_KEYWORDS = ['true', 'false', 'null', 'this', 'new', 'delete', 'typeof', 'in', 'instanceof', 'return', 'throw', 'break', 'continue', 'debugger', 'yield', 'yield*', 'if', 'else', 'switch', 'for', 'while', 'do', 'try', 'catch', 'finally', 'class', 'extends', 'super'];
COFFEE_KEYWORDS = ['undefined', 'then', 'unless', 'until', 'loop', 'of', 'by', 'when'];
@@ -880,7 +880,7 @@
COMPOUND_ASSIGN = ['-=', '+=', '/=', '*=', '%=', '||=', '&&=', '?=', '<<=', '>>=', '>>>=', '&=', '^=', '|='];
UNARY = ['!', '~', 'NEW', 'TYPEOF', 'DELETE', 'DO', 'YIELD'];
UNARY = ['!', '~', 'NEW', 'TYPEOF', 'DELETE', 'DO', 'YIELD', 'YIELD*'];
LOGIC = ['&&', '||', '&', '|', '^'];

View File

@@ -2378,7 +2378,7 @@
return (new Parens(this)).compileToFragments(o);
}
plusMinus = op === '+' || op === '-';
if ((op === 'new' || op === 'typeof' || op === 'delete' || op === 'yield') || plusMinus && this.first instanceof Op && this.first.operator === op) {
if ((op === 'new' || op === 'typeof' || op === 'delete' || op === 'yield' || op === 'yield*') || plusMinus && this.first instanceof Op && this.first.operator === op) {
parts.push([this.makeCode(' ')]);
}
if ((plusMinus && this.first instanceof Op) || (op === 'new' && this.first.isStatement(o))) {

View File

@@ -713,7 +713,7 @@ exports.Lexer = class Lexer
JS_KEYWORDS = [
'true', 'false', 'null', 'this'
'new', 'delete', 'typeof', 'in', 'instanceof'
'return', 'throw', 'break', 'continue', 'debugger', 'yield'
'return', 'throw', 'break', 'continue', 'debugger', 'yield', 'yield*'
'if', 'else', 'switch', 'for', 'while', 'do', 'try', 'catch', 'finally'
'class', 'extends', 'super'
]
@@ -834,7 +834,7 @@ COMPOUND_ASSIGN = [
]
# Unary tokens.
UNARY = ['!', '~', 'NEW', 'TYPEOF', 'DELETE', 'DO', 'YIELD']
UNARY = ['!', '~', 'NEW', 'TYPEOF', 'DELETE', 'DO', 'YIELD', 'YIELD*']
# Logical tokens.
LOGIC = ['&&', '||', '&', '|', '^']

View File

@@ -1700,8 +1700,8 @@ exports.Op = class Op extends Base
if o.level >= LEVEL_ACCESS
return (new Parens this).compileToFragments o
plusMinus = op in ['+', '-']
parts.push [@makeCode(' ')] if op in ['new', 'typeof', 'delete', 'yield'] or
plusMinus and @first instanceof Op and @first.operator is op
parts.push [@makeCode(' ')] if op in ['new', 'typeof', 'delete', 'yield'
'yield*'] or plusMinus and @first instanceof Op and @first.operator is op
if (plusMinus and @first instanceof Op) or (op is 'new' and @first.isStatement o)
@first = new Parens @first
parts.push @first.compileToFragments o, LEVEL_OP

View File

@@ -11,7 +11,8 @@ test "generator definition", ->
yield 0
yield 1
yield 2
y = x()
y = do ->*
yield* x()
z = y.next()
eq z.value, 0
eq z.done, false