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

break transform to return #73

Open
chinayu9 opened this issue Nov 25, 2021 · 2 comments
Open

break transform to return #73

chinayu9 opened this issue Nov 25, 2021 · 2 comments

Comments

@chinayu9
Copy link

source code:

const test1 = async () => {
    return Promise.resolve("1");
}

export const test2 = async () => {
    const r = await test1();
    switch (r) {
        case "1":
            console.log("1111");
            break;
        case "2":
            console.log("2222");
            break;
    }
    console.log("33333333333");
}

transformed code:

_$pi.define("client/app_a/a1", ["require", "exports", "module"], function (require, exports, module) {
    "use strict";

    exports.test2 = void 0;
    const test1 = function () {
        try {
            return Promise.resolve("1");
        } catch (e) {
            return Promise.reject(e);
        }
    };
    exports.test2 = function () {
        try {
            return Promise.resolve(test1()).then(function (r) {
                switch (r) {
                    case "1":
                        console.log("1111");
                        return;

                    case "2":
                        console.log("2222");
                        return;

                }
                console.log("333");
            });
        } catch (e) {
            return Promise.reject(e);
        }
    };
});

break transformed to return,the last print 333 can not be printed

@rpetrich
Copy link
Owner

Which version are you using? I've imported the following test case:

async () => {
	const r = await test1();
	switch (r) {
		case "1":
			console.log("1111");
			break;
		case "2":
			console.log("2222");
			break;
	}
	console.log("33333333333");
}

And get the following output on version 0.8.16:

function(){try{return Promise.resolve(test1()).then(function(r){switch(r){case"1":console.log("1111");break;case"2":console.log("2222");break;}console.log("33333333333");});}catch(e){return Promise.reject(e);}}

Which unminifies to:

function() {
    try {
        return Promise.resolve(test1()).then(function(r) {
            switch (r) {
                case "1":
                    console.log("1111");
                    break;
                case "2":
                    console.log("2222");
                    break;
            }
            console.log("33333333333");
        });
    } catch (e) {
        return Promise.reject(e);
    }
}

@rpetrich
Copy link
Owner

@chinayu9 checking in. do you have any thoughts on the test case?

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

2 participants