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

Does rhino supports yield statements ? #482

Closed
eugenhoro opened this issue Oct 9, 2018 · 2 comments
Closed

Does rhino supports yield statements ? #482

eugenhoro opened this issue Oct 9, 2018 · 2 comments

Comments

@eugenhoro
Copy link

I am trying to build AST of the following javascript (es6) file using the code below and I am getting an empty AST.

function * foo(x) {
while (true) {
x = x * 2;
yield x;
}
}

var g = foo(2);
console.log('start')
console.log(g.next())
console.log(g.next())
console.log(g.next())


The code for buiding the AST :

    String fileContent = String.join(System.lineSeparator(), getFileLines(file));
    AstRoot top = null;
    Reporter reporter = new Reporter();
    CompilerEnvirons compilerEnv = new CompilerEnvirons();
    compilerEnv.setErrorReporter(reporter);
    compilerEnv.setReservedKeywordAsIdentifier(true);
    compilerEnv.setIdeMode(true);
    top = new Parser(compilerEnv, compilerEnv.getErrorReporter()).parse(fileContent, file, 1);
@lfmunoz
Copy link

lfmunoz commented Oct 31, 2018

    val script= """
       function execute() {
            var c = 'a'.charCodeAt(0);
            while (c <= 'z'.charCodeAt(0)) {
                yield String.fromCharCode(c++);
            }
        }
        for (let h in execute()) out.println(h)
    """.trimIndent()

Don't use * to define the generator function.

Reference #396

@gbrail
Copy link
Collaborator

gbrail commented Nov 9, 2018

There are no ES6-style generators in Rhino yet. There has been an incomplete PR from a long time ago but it's a pretty complex set of changes and doesn't quite work.

Anyone who is looking for a project might want to check out the incomplete work that is referenced in Issue 411:

#411

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants