Skip to content

Add option to prevent reversing AST_Binary nodes #1359

@iccir

Description

@iccir

Bug report or Feature request?
Feature request

Version (complete output of terser -V or specific git commit) 5.16.6

Complete CLI command or minify() options used

    let results = (await minify(inContents, {
        mangle: false,
        compress: {
            arguments     : false,
            arrows        : false,
            booleans      : false,
            booleans_as_integers : false,
            collapse_vars : false,
            comparisons   : false,
            computed_props: false,
            conditionals  : false,
            dead_code     : false,
            defaults      : false,
            directives    : false,
            drop_console  : false,
            drop_debugger : false,
            evaluate      : false,
            expression    : false,
            global_defs   : false,
            hoist_funs    : false,
            hoist_props   : false,
            hoist_vars    : false,
            ie8           : false,
            if_return     : false,
            inline        : false,
            join_vars     : false,
            keep_classnames: false,
            keep_fargs    : false,
            keep_fnames   : false,
            keep_infinity : false,
            loops         : false,
            module        : false,
            negate_iife   : false,
            passes        : 1,
            properties    : false,
            pure_getters  : false,
            pure_funcs    : null,
            reduce_funcs  : false,
            reduce_vars   : false,
            sequences     : false,
            side_effects  : false,
            switches      : false,
            top_retain    : null,
            typeofs       : false,
            unsafe        : false,
            unsafe_arrows : false,
            unsafe_comps  : false,
            unsafe_Function: false,
            unsafe_math   : false,
            unsafe_symbols: false,
            unsafe_methods: false,
            unsafe_proto  : false,
            unsafe_regexp : false,
            unsafe_undefined: false,
            unused        : false,
            warnings      : false  // legacy
        },
        output: {
            beautify: true
        }
    })).code;

terser input
if (foo == 42) { bar(); }

terser output or error
if (42 == foo) bar()

Expected result
if (foo == 42) bar()

Notes
Right now, if you turn on compress, there is no way of opting-out of AST_Binary's reversible()/reverse() logic, even when comparisons is set to false. Could there be a new option to prevent this, or could the comparisons option prevent reversing.

Specifically, in our use case, we need to run with compress for dead_code and unused, but we want to prevent as many additional transformations as possible.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions