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

unminifyIfStatements causes bug #6

Open
Reson-a opened this issue Feb 24, 2021 · 2 comments
Open

unminifyIfStatements causes bug #6

Reson-a opened this issue Feb 24, 2021 · 2 comments

Comments

@Reson-a
Copy link

Reson-a commented Feb 24, 2021

unminify-if-statements.ts

return x || a() -> if (!x) { return a() }

when x is true, it returns undefined

I disabled this transformer to make it work

@Reson-a
Copy link
Author

Reson-a commented Feb 24, 2021

function isNullOrUndefined(value) { return value === null || value === undefined }

after the transformation

function isNullOrUndefined(value) { if (!(value === null)) { return undefined === value } }

@jiicoding
Copy link

I fixed the

return x || a()

bug by adding an else statement, so after the transform

`if (!x) { return a() } else { return(x)}

the fix for the lower half for unminifyIfStatements()

I am skipping return( a || b || c) for now

            if (returnE.operator === "||") {
                // don't handle return( a || b || c)

                if (returnE.left.type!=="LogicalExpression")  { // custom replace `return x || a()` -> `if (!x) { return a() } else return(x)`
                    path.replaceWith(
                        ifStatement(
                            test,
                            returnStatement(returnE.right),
                            returnStatement(returnE.left)
                        )
                    )
                }
            }
            else
                path.replaceWith(
                    ifStatement(
                        test,
                        returnStatement(returnE.right),
                    )
                )
            return

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