Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generator: correctly distinguish yield as identifier vs keyword #1186

Closed
ariya opened this issue Jun 3, 2015 · 2 comments
Closed

Generator: correctly distinguish yield as identifier vs keyword #1186

ariya opened this issue Jun 3, 2015 · 2 comments
Assignees
Labels
Milestone

Comments

@ariya
Copy link
Contributor

ariya commented Jun 3, 2015

Valid Syntax

Nested yield expression:

function *g() { yield yield }
function *g() { yield *yield }

yield as the name of a generator, declaration and method:

function *yield() {}
({ *yield() {} })

yield as the default value:

function *g(x = yield){}
function *g() { (x = yield) => {} }

Function expression:

function *g(){ var y = function yield(){}; }
function *g(){ var z = function(yield){}; }

Property name:

"use strict"; var { yield: x } = foo;
"use strict"; ({ yield() {} })
function *g() { obj.yield(); }
function *g() { yield obj.yield; }
class A extends B { X(){ super.yield } }

Object pattern:

function f({yield: y}){}
function *g({yield: y}){}

Arrow expression:

(x) => x + yield;
(z) => { yield + z };
function *g() { (x) => x + yield; }
function *g() { (z) => { yield + z }; }

Non-strict mode use of yield as an identifier:

([yield] = x)
(x = yield) => {}
(yield) => 42
var { x: yield } = foo
var { yield: x } = foo
try {} catch (yield) {}
function f(yield) {}
function yield(){}
(function(yield) {})
(function yield(){})
({ yield() {} })
let yield = 42
function f(...yield) {}
var yield

Parse Failures

yield is not allowed as a binding identifier:

function *g() { try {} catch (yield) {} }
function *g() { let yield }
function *g() { var yield }
function *g() { function *yield(){} }
function *g() { return yield.x; }
function *g(yield){}
function *g(a, b, c, ...yield){}
function *g() { (yield) => 42 }
function *g() { (a, b, c, yield) => 42 }
((function*yield(){})
(function *(yield){})
(function *(x, ...yield){})
export default function *yield() {}

Strict mode violation (each line is its own example):

"use strict"; ([yield] = x)
"use strict"; (x = yield) => {}
"use strict"; (yield) => 42
"use strict"; var { x: yield } = foo;
"use strict"; try {} catch (yield) {}
"use strict"; function f(yield) {}
function yield(){ "use strict" }
(function yield(){ "use strict" })
"use strict"; function f() { yield }
"use strict"; let yield = 42
"use strict"; function f(...yield) {}
"use strict"; var yield
"use strict"; function *g() { var y = function yield(){}; }
"use strict"; function *g() { var z = function(yield) {} }

Yield expression in a wrong place:

var {x: y = yield 3} = z;
(function() { yield 3; })
function* g() { (x = yield 42) => {} }
@ariya ariya added the es6 label Jun 3, 2015
@ariya ariya mentioned this issue Jun 3, 2015
@ariya
Copy link
Contributor Author

ariya commented Jun 3, 2015

For a previous ref, see #1178 (comment).

@ariya ariya self-assigned this Jul 7, 2015
@ariya ariya added this to the 2.5 milestone Jul 7, 2015
@mikesherov mikesherov mentioned this issue Jul 7, 2015
25 tasks
ariya added a commit to ariya/esprima that referenced this issue Jul 7, 2015
`yield` is a keyword in strict mode, inside a generator, or as part of a
yield expression. `yield` may be used as an identifier for the name of
generators, methods, object properties, and function expressions.

Fixes jquery#1186
@ariya
Copy link
Contributor Author

ariya commented Jul 7, 2015

Please note that there is also another issue with yield, this is covered by the sibling issue #1185.

@ariya ariya closed this as completed in 1a43ccf Jul 8, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

1 participant