Terser: Can't use 'yield' as a simple object attribute as it throws an error while building a Ionic project

Created on 12 Jun 2020  路  3Comments  路  Source: terser/terser

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?

bug

All 3 comments

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 :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Shmasya picture Shmasya  路  6Comments

KyleMit picture KyleMit  路  6Comments

zbream picture zbream  路  6Comments

timocov picture timocov  路  3Comments

maksimr picture maksimr  路  7Comments