Xmader / retidy

Extract, unminify, and beautify ("retidy") each file from a webpack/parcel bundle (JavaScript reverse engineering)
MIT License
44 stars 10 forks source link

unminifyIfStatements causes bug #6

Open Reson-a opened 3 years ago

Reson-a commented 3 years ago

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 commented 3 years ago

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

after the transformation

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

jiicoding commented 2 years ago

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