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

Object property indented after await #1517

Closed
Verdier opened this issue Aug 28, 2018 · 5 comments
Closed

Object property indented after await #1517

Verdier opened this issue Aug 28, 2018 · 5 comments

Comments

@Verdier
Copy link

Verdier commented Aug 28, 2018

Description

Since version 1.8.1, When formatting an object, a property is indented if the previous property is initialized using the await keyword.

Input

The code looked like this before beautification:

async function() {
  const obj = {
    a: 1,
    b: await fn(),
    c: 2
  };
}

Expected Output

The code should have looked like this after beautification:

async function() {
  const obj = {
    a: 1,
    b: await fn(),
    c: 2
  };
}

Actual Output

The code actually looked like this after beautification:

async function() {
  const obj = {
    a: 1,
    b: await fn(),
      c: 2
  };
}

Settings

Default

@qguv
Copy link

qguv commented Aug 30, 2018

This is also a problem in multi-variable assignment statements. E.g.:

const os = require('os');

const foo = async =>{};

const a = 1,
    b = 2,
    c = await foo(),
    d = 3,
    e = await foo(),
    f = 4,
    g = 5,
    h = await foo(),
    i = await foo(),
    j = (await foo()),
    k = (await foo()),
    l = 6,
    m = 7,
    n = await foo(),
    o = 8;

Becomes:

const os = require('os');

const foo = async =>{};

const a = 1,
    b = 2,
    c = await foo(),
        d = 3,
        e = await foo(),
            f = 4,
            g = 5,
            h = await foo(),
                i = await foo(),
                    j = (await foo()),
                    k = (await foo()),
                    l = 6,
                    m = 7,
                    n = await foo(),
                        o = 8;

Note that it's not an issue if the whole await-call expression is enclosed with parentheses.

animation demonstrating the issue

@bitwiseman
Copy link
Member

Thanks for the detailed issue report. This will help craft a fix.

Docs for await
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/await

@qguv
Copy link

qguv commented Aug 30, 2018

Just confirmed that the Issue wasn't present in v1.7.5.

@bitwiseman
Copy link
Member

@qguv

Please try some inputs on https://beautifier.io/ and see if they look right.

@qguv
Copy link

qguv commented Sep 19, 2018

@bitwiseman Looks great! Thanks again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants