Bug
I was trying to run the production build of my Ionic project and it kept throwing this error after compiling all files:
ERROR in main-es2015.666cd125f034b56ee8a6.js from Terser
Yield cannot be used as identifier inside generators [main-es2015.666cd125f034b56ee8a6.js:16146,59]
Simply renaming this object's _yield_ attribute to _yield_value_ made the build pass.
const body = {
...this.harvest,
yield: ...
}
Version (I gathered it from package-lock.json file as I didn't install it myself but is a dependency of other project dependencies)
4.3.1
Complete CLI command or minify() options used
Using Ionic CLI so I'm not sure which options it's using.
terser output or error
ERROR in main-es2015.666cd125f034b56ee8a6.js from Terser
Yield cannot be used as identifier inside generators [main-es2015.666cd125f034b56ee8a6.js:16146,59]
Expected result
I'm aware _yield_ is a reserved Javascript world but I wasn't expecting an error to be thrown by using it as an object attribute.
Is it the expected behavior? Should I be aware with using this keyword by any means?
Hey there!
This is a legit bug in the parser.
Here's some places where you can't use yield in a generator (from my tests)
function * x (){
function yield () { }
const yield = 4
console.log({ yield })
}
Your usage should have been fine. This is just the parser being too strict.
That's nice! But just to be clear, the yield attribute wasn't inside a generator despite the message being thrown. It was inside a simple object that was being sent to my API.
Something like:
const body = {
yield: 1
}
Cool.
I've dropped all the checks anyway. Terser isn't a linter so no point on worrying about input correctness :)