beautifier / js-beautify

Beautifier for javascript
https://beautifier.io
MIT License
8.63k stars 1.38k forks source link

Problem: comma separated code gets 'Laddered' sometimes #2080

Open Owyn opened 2 years ago

Owyn commented 2 years ago

Input

The code looked like this before beautification:

[_0x20c3e9(0x89b)]()
{
    return _0x5c5206(this, void 0x0, void 0x0, function*()
    {
        const _0xba1bc7 = a0_0x1312;
        yield this[_0xba1bc7(0xf93)]('KillCount', JSON[_0xba1bc7(0x2e9)]({})),
        yield this['_set']('PickupCount', JSON[_0xba1bc7(0x2e9)]({})),
        yield this['_set']('DestroyedCount', JSON[_0xba1bc7(0x2e9)]({})),
        yield this[_0xba1bc7(0xf93)]('StageCompletionLog', JSON[_0xba1bc7(0x2e9)]({})),
        yield this['_set']('MusicSelectionPerStage', JSON['stringify']({})),
        yield this[_0xba1bc7(0xf93)]('LifetimeSurvived', JSON['stringify'](0x0)),
        yield this['_set']('LifetimeHeal', JSON[_0xba1bc7(0x2e9)](0x0)),
        yield this['_set']('CompletedHurries', JSON['stringify'](0x0)),
        yield this[_0xba1bc7(0xf93)]('OwO', JSON['stringify'](0x0)),
        yield this[_0xba1bc7(0xf93)]('HighestFever', JSON[_0xba1bc7(0x2e9)](0x0)),
        yield this['_set']('LongestFever', JSON[_0xba1bc7(0x2e9)](0x0)),
        yield this[_0xba1bc7(0xf93)]('EggData', JSON['stringify']({}));
    });
}

Expected Output

The code should have looked like this after beautification:

the same

Actual Output

The code actually looked like this after beautification:

[_0x20c3e9(0x89b)]()
{
    return _0x5c5206(this, void 0x0, void 0x0, function*()
    {
        const _0xba1bc7 = a0_0x1312;
        yield this[_0xba1bc7(0xf93)]('KillCount', JSON[_0xba1bc7(0x2e9)](
            {})),
            yield this['_set']('PickupCount', JSON[_0xba1bc7(0x2e9)](
                {})),
                yield this['_set']('DestroyedCount', JSON[_0xba1bc7(0x2e9)](
                    {})),
                    yield this[_0xba1bc7(0xf93)]('StageCompletionLog', JSON[_0xba1bc7(0x2e9)](
                        {})),
                        yield this['_set']('MusicSelectionPerStage', JSON['stringify'](
                            {})),
                            yield this[_0xba1bc7(0xf93)]('LifetimeSurvived', JSON['stringify'](0x0)),
                                yield this['_set']('LifetimeHeal', JSON[_0xba1bc7(0x2e9)](0x0)),
                                    yield this['_set']('CompletedHurries', JSON['stringify'](0x0)),
                                        yield this[_0xba1bc7(0xf93)]('OwO', JSON['stringify'](0x0)),
                                            yield this[_0xba1bc7(0xf93)]('HighestFever', JSON[_0xba1bc7(0x2e9)](0x0)),
                                                yield this['_set']('LongestFever', JSON[_0xba1bc7(0x2e9)](0x0)),
                                                    yield this[_0xba1bc7(0xf93)]('EggData', JSON['stringify'](
                                                    {}));
    });
}

Steps to Reproduce

  1. beautify code
  2. see bad result

Environment

OS: Win 10

Settings

any settings - I think

bitwiseman commented 2 years ago

PRs welcome.

SimaDovakin commented 2 years ago

When you minify this example and then beautify it you get:

[_0x20c3e9(0x89b)]() {
    return _0x5c5206(this, void 0x0, void 0x0, function*() {
        const _0xba1bc7 = a0_0x1312;
        yield this[_0xba1bc7(0xf93)]('KillCount', JSON[_0xba1bc7(0x2e9)]({})), yield this['_set']('PickupCount', JSON[_0xba1bc7(0x2e9)]({})), yield this['_set']('DestroyedCount', JSON[_0xba1bc7(0x2e9)]({})), yield this[_0xba1bc7(0xf93)]('StageCompletionLog', JSON[_0xba1bc7(0x2e9)]({})), yield this['_set']('MusicSelectionPerStage', JSON.stringify({})), yield this[_0xba1bc7(0xf93)]('LifetimeSurvived', JSON.stringify(0x0)), yield this['_set']('LifetimeHeal', JSON[_0xba1bc7(0x2e9)](0x0)), yield this['_set']('CompletedHurries', JSON.stringify(0x0)), yield this[_0xba1bc7(0xf93)]('OwO', JSON.stringify(0x0)), yield this[_0xba1bc7(0xf93)]('HighestFever', JSON[_0xba1bc7(0x2e9)](0x0)), yield this['_set']('LongestFever', JSON[_0xba1bc7(0x2e9)](0x0)), yield this[_0xba1bc7(0xf93)]('EggData', JSON.stringify({}))
    })
}

All 'yields' will be on the same line.

Owyn commented 2 years ago

All 'yields' will be on the same line.

Yea - that's also a problem which'd be nice to get fixed. But it's a separate issue https://github.com/beautify-web/js-beautify/issues/2060