preact-cli icon indicating copy to clipboard operation
preact-cli copied to clipboard

Weird transpilation issues

Open teodragovic opened this issue 4 years ago • 0 comments

Do you want to request a feature or report a bug?

Bug

What is the current behaviour?

See following snippets

example 1

const getYears = (min, max) => (
    [ ...new Array(max - min + 1).keys() ].map((index) => (min + index).toString())
);
console.log(getYears(1981, 2004);

example 2

class DBWrapper {

    _db = null;

    async open() {
        if (this._db) return;

        this._db = await new Promise((resolve, reject) => {
            resolve('db')
        });

        return this;
    }

    async transaction(callback) {
        await this.open();
        return await new Promise((resolve, reject) => {
            const txn = this._db;
            callback(txn);
        });
    }

}

const db = new DBWrapper();
db.transaction((tx) => console.log(tx));

If both are pasted in src/index.js of clean preact-cli project, example 1 returns "1981[object Array Iterator]" while example 2 works. If browserlists: [">0.75%", "not ie 11", "not op_mini all"] is added to package.js, example 1 works but example 2 throws Cannot read property '_db' of undefined.

My current fix is to keep browserslist at >0.75% and add @babel/plugin-transform-arrow-functions via preact.config.js but that's unfortunate as both snippets work natively in the browser.

Please mention other relevant information.

Tested using clean [email protected] (default and typescript template) and Chrome 88 on Windows 10

BTW. example 2 is a reduced part of failing code from workbox when using custom sw and ExpirationPlugin. Jeff Posnick kindly pointed out error in transpilation to me.

teodragovic avatar Feb 12 '21 11:02 teodragovic