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

Weird transpilation issues #1536

Open
teodragovic opened this issue Feb 12, 2021 · 0 comments
Open

Weird transpilation issues #1536

teodragovic opened this issue Feb 12, 2021 · 0 comments

Comments

@teodragovic
Copy link
Contributor

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.

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

1 participant