question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

java.lang.IllegalStateException: 'yield' expression is not within a generator function.

See original GitHub issue

I tried to transpile down the vscode frontend from es2020 to es2015 in order to use it on a machine that does not support newer browsers. Rare use case but should work in a bug free world. 😃 For that, I grabbed closure-compiler-v20211107.jar and used it like this:

/usr/lib/code-server/vendor/modules/code-oss-dev/out/vs/workbench# closure-compiler --js workbench.web.api.js --js_output_file workbench.web.api.js --language_in ECMASCRIPT_2020 --language_out ECMASCRIPT_2015
java.lang.IllegalStateException: 'yield' expression is not within a generator function. Reference node:
YIELD 1461:4095  [length: 32] [source_file: workbench.web.api.js]
    CALL 1461:4095  [length: 26] [source_file: workbench.web.api.js]
        GETPROP createTerminal 1461:4095  [length: 14] [source_file: workbench.web.api.js]
            NAME L 1461:4095  [length: 4] [source_file: workbench.web.api.js]
        NAME E 1461:4095  [length: 1] [source_file: workbench.web.api.js]
        NAME M 1461:4095  [length: 1] [source_file: workbench.web.api.js]
        NAME J 1461:4095  [length: 1] [source_file: workbench.web.api.js]

 Parent node:
NAME la 1461:4095  [length: 40] [source_file: workbench.web.api.js] [constant_var_flags: 2]
    YIELD 1461:4095  [length: 32] [source_file: workbench.web.api.js]
        CALL 1461:4095  [length: 26] [source_file: workbench.web.api.js]
            GETPROP createTerminal 1461:4095  [length: 14] [source_file: workbench.web.api.js]
                NAME L 1461:4095  [length: 4] [source_file: workbench.web.api.js]
            NAME E 1461:4095  [length: 1] [source_file: workbench.web.api.js]
            NAME M 1461:4095  [length: 1] [source_file: workbench.web.api.js]
            NAME J 1461:4095  [length: 1] [source_file: workbench.web.api.js]

        at com.google.javascript.jscomp.AstValidator$1.handleViolation(AstValidator.java:86)
        at com.google.javascript.jscomp.AstValidator.violation(AstValidator.java:1995)
        at com.google.javascript.jscomp.AstValidator.validateYieldWithinGeneratorFunction(AstValidator.java:613)
        at com.google.javascript.jscomp.AstValidator.validateYield(AstValidator.java:607)
        at com.google.javascript.jscomp.AstValidator.validateExpression(AstValidator.java:440)
        at com.google.javascript.jscomp.AstValidator.validateNameDeclarationChild(AstValidator.java:1262)
        at com.google.javascript.jscomp.AstValidator.validateNameDeclarationHelper(AstValidator.java:1227)
        at com.google.javascript.jscomp.AstValidator.validateStatement(AstValidator.java:206)
        at com.google.javascript.jscomp.AstValidator.validateStatement(AstValidator.java:153)
        at com.google.javascript.jscomp.AstValidator.validateBlock(AstValidator.java:941)
        at com.google.javascript.jscomp.AstValidator.validateFunctionExpressionHelper(AstValidator.java:1052)
        at com.google.javascript.jscomp.AstValidator.validateFunctionExpression(AstValidator.java:1034)
        at com.google.javascript.jscomp.AstValidator.validateExpression(AstValidator.java:424)
        at com.google.javascript.jscomp.AstValidator.validateCall(AstValidator.java:1119)
        at com.google.javascript.jscomp.AstValidator.validateExpression(AstValidator.java:412)
        at com.google.javascript.jscomp.AstValidator.validateBinaryOp(AstValidator.java:1905)
        at com.google.javascript.jscomp.AstValidator.validateExpression(AstValidator.java:380)
        at com.google.javascript.jscomp.AstValidator.validateIf(AstValidator.java:1450)
        at com.google.javascript.jscomp.AstValidator.validateStatement(AstValidator.java:201)
        at com.google.javascript.jscomp.AstValidator.validateStatement(AstValidator.java:153)
        at com.google.javascript.jscomp.AstValidator.validateBlock(AstValidator.java:941)
        at com.google.javascript.jscomp.AstValidator.validateIf(AstValidator.java:1451)
        at com.google.javascript.jscomp.AstValidator.validateStatement(AstValidator.java:201)
        at com.google.javascript.jscomp.AstValidator.validateStatement(AstValidator.java:153)
        at com.google.javascript.jscomp.AstValidator.validateBlock(AstValidator.java:941)
        at com.google.javascript.jscomp.AstValidator.validateFunctionBody(AstValidator.java:1082)
        at com.google.javascript.jscomp.AstValidator.validateFunctionExpressionHelper(AstValidator.java:1058)
        at com.google.javascript.jscomp.AstValidator.validateFunctionExpression(AstValidator.java:1034)
        at com.google.javascript.jscomp.AstValidator.validateExpression(AstValidator.java:424)
        at com.google.javascript.jscomp.AstValidator.validatePseudoExpression(AstValidator.java:480)
        at com.google.javascript.jscomp.AstValidator.validateCall(AstValidator.java:1122)
        at com.google.javascript.jscomp.AstValidator.validateExpression(AstValidator.java:412)
        at com.google.javascript.jscomp.AstValidator.validateReturn(AstValidator.java:1467)
        at com.google.javascript.jscomp.AstValidator.validateStatement(AstValidator.java:212)
        at com.google.javascript.jscomp.AstValidator.validateStatement(AstValidator.java:153)
        at com.google.javascript.jscomp.AstValidator.validateBlock(AstValidator.java:941)
        at com.google.javascript.jscomp.AstValidator.validateFunctionBody(AstValidator.java:1082)
        at com.google.javascript.jscomp.AstValidator.validateFunctionExpressionHelper(AstValidator.java:1058)
        at com.google.javascript.jscomp.AstValidator.validateFunctionExpression(AstValidator.java:1034)
        at com.google.javascript.jscomp.AstValidator.validateMemberFunction(AstValidator.java:918)
        at com.google.javascript.jscomp.AstValidator.validateClassMember(AstValidator.java:877)
        at com.google.javascript.jscomp.AstValidator.validateClassMembers(AstValidator.java:867)
        at com.google.javascript.jscomp.AstValidator.validateClassHelper(AstValidator.java:861)
        at com.google.javascript.jscomp.AstValidator.validateClassDeclaration(AstValidator.java:833)
        at com.google.javascript.jscomp.AstValidator.validateStatement(AstValidator.java:231)
        at com.google.javascript.jscomp.AstValidator.validateStatement(AstValidator.java:153)
        at com.google.javascript.jscomp.AstValidator.validateBlock(AstValidator.java:941)
        at com.google.javascript.jscomp.AstValidator.validateFunctionBody(AstValidator.java:1082)
        at com.google.javascript.jscomp.AstValidator.validateFunctionExpressionHelper(AstValidator.java:1058)
        at com.google.javascript.jscomp.AstValidator.validateFunctionExpression(AstValidator.java:1034)
        at com.google.javascript.jscomp.AstValidator.validateExpression(AstValidator.java:424)
        at com.google.javascript.jscomp.AstValidator.validatePseudoExpression(AstValidator.java:480)
        at com.google.javascript.jscomp.AstValidator.validateCall(AstValidator.java:1122)
        at com.google.javascript.jscomp.AstValidator.validateExpression(AstValidator.java:412)
        at com.google.javascript.jscomp.AstValidator.validateExprStmt(AstValidator.java:1460)
        at com.google.javascript.jscomp.AstValidator.validateStatement(AstValidator.java:209)
        at com.google.javascript.jscomp.AstValidator.validateStatement(AstValidator.java:153)
        at com.google.javascript.jscomp.AstValidator.validateBlock(AstValidator.java:941)
        at com.google.javascript.jscomp.AstValidator.validateFunctionBody(AstValidator.java:1082)
        at com.google.javascript.jscomp.AstValidator.validateFunctionExpressionHelper(AstValidator.java:1058)
        at com.google.javascript.jscomp.AstValidator.validateFunctionExpression(AstValidator.java:1034)
        at com.google.javascript.jscomp.AstValidator.validateExpression(AstValidator.java:424)
        at com.google.javascript.jscomp.AstValidator.validatePropertyReferenceTarget(AstValidator.java:1662)
        at com.google.javascript.jscomp.AstValidator.validateGetProp(AstValidator.java:1644)
        at com.google.javascript.jscomp.AstValidator.validateExpression(AstValidator.java:392)
        at com.google.javascript.jscomp.AstValidator.validateCall(AstValidator.java:1119)
        at com.google.javascript.jscomp.AstValidator.validateExpression(AstValidator.java:412)
        at com.google.javascript.jscomp.AstValidator.validateExprStmt(AstValidator.java:1460)
        at com.google.javascript.jscomp.AstValidator.validateStatement(AstValidator.java:209)
        at com.google.javascript.jscomp.AstValidator.validateStatement(AstValidator.java:153)
        at com.google.javascript.jscomp.AstValidator.validateStatements(AstValidator.java:147)
        at com.google.javascript.jscomp.AstValidator.validateScript(AstValidator.java:136)
        at com.google.javascript.jscomp.AstValidator.validateCodeRoot(AstValidator.java:123)
        at com.google.javascript.jscomp.AstValidator.process(AstValidator.java:109)
        at com.google.javascript.jscomp.PhaseOptimizer$NamedPass.process(PhaseOptimizer.java:317)
        at com.google.javascript.jscomp.PhaseOptimizer.process(PhaseOptimizer.java:232)
        at com.google.javascript.jscomp.Compiler.performTranspilationAndOptimizations(Compiler.java:2573)
        at com.google.javascript.jscomp.Compiler.lambda$stage2Passes$5(Compiler.java:939)
        at com.google.javascript.jscomp.CompilerExecutor.lambda$runInCompilerThread$0(CompilerExecutor.java:101)
        at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
        at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
        at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
        at java.base/java.lang.Thread.run(Thread.java:833)

From this output, I cannot tell which part of the file causes this, I am sorry. But you can reproduce it if you install code-server. This may help: https://github.com/cdr/code-server/tree/v3.12.0/vendor

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:12 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
brad4dcommented, Dec 29, 2021

Since blocks cannot be placed inside an expression, it’s necessary to decompose expressions into multiple statements and create temporary variables, etc. in order to preserve the order of operations from the original code. The ExpressionDecomposer can do this except for a few edge cases, but apparently we previously opted to use the arrow-function approach instead. Likely this was partly because it seemed a more elegant solution at the time and partly because handling destructuring of for-loops that contain multiple variable declarations (e.g. for (let x = 3, [y, z] = obj; ... gets tricky.

Now it doesn’t seem so elegant. I’m thinking the right approach is to first wrap such for-loops in a block and extract the declaration part into the block. Then the compiler can successfully break it into multiple declaration statements, which is a prerequisite for Es6RewriteDestructuring to use ExpressionDecomposer the way we want. Once that’s done, I think we can use ExpressionDecomposer in Es6RewriteDestructuring instead of creating IIFEs to transpile the destructuring.

1reaction
brad4dcommented, Dec 22, 2021

I have a fix for this in internal review.

Read more comments on GitHub >

github_iconTop Results From Across the Web

A 'yield' expression is only allowed in a generator body
Because your generator fetch01 is sync but you're waiting an Promise to be resovled. yield can not be wrapped in other functions other...
Read more >
Generator.prototype.throw() - JavaScript - MDN Web Docs
The value yielded from the next yield expression. ... the exception passed to throw() will be thrown out from the generator function.
Read more >
Asynchronous testing - ScalaTest
ScalaTest supports asynchronous non-blocking testing. Given a Future returned by the ... Running the above AddSpec in the Scala interpreter would yield:
Read more >
SQL error messages and exceptions - Oracle Help Center
The LTRIM() and RTRIM() built-in functions support multiple trim characters. ... not match the number of columns in the underlying query expression in...
Read more >
jigsaw/jake/nashorn: 875506d0f097 - Java.net
FUNCTION ) { - StringBuilder buf = new StringBuilder(objName); + final ... must not contain yield expression if yield=true (i.e. this is generator...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found