codemodsquad / asyncify

Don't keep your promises 😉
MIT License
13 stars 6 forks source link

incorrect output for multiple else if branches that fall through #2

Closed jedwards1211 closed 4 years ago

jedwards1211 commented 4 years ago

Input

async function createUser(args) {
  const {username, groups} = args
  const user = await Users.create({username})
    .then(user => {
      if (groups) {
        return addUserToGroups(user, groups)
      } else if (foo) {
        console.log('test')
      } else if (bar) {
        console.log('test2')
      }
      console.log('blah')
      return user
    })
    .then(user => {
      if (groups) {
        console.log('test')
      } else {
        return 'noGroups'
      }
      return 'user'
    })
    .catch(err => {
      console.error(err.stack)
      return dummyUser()
    })
}

Expected

async function createUser(args) {
  const {username, groups} = args
  let user
  try {
    const user1 = await Users.create({ username })
    const user0 = await (async user => {
      if (groups) {
        return addUserToGroups(user, groups)
      } else if (foo) {
        console.log('test')
      } else if (bar) {
        console.log('test2')
      }
      console.log('blah')
      return user
    })(user1)
    if (groups) {
      console.log('test')
      user = 'user'
    } else {
      user = 'noGroups'
    }
  } catch (err) {
    console.error(err.stack)
    user = await dummyUser()
  }
}

Actual


async function createUser(args) {
  const {username, groups} = args
  let user
  try {
    let user0
    const user1 = await Users.create({ username })
    if (groups) {
      user0 = await addUserToGroups(user1, groups)
    } else if (foo) {
      console.log('test')
    } else if (bar) {
      console.log('test2')
    } else {
      console.log('blah')
      user0 = await user1
    }
    if (groups) {
      console.log('test')
      user = 'user'
    } else {
      user = 'noGroups'
    }
  } catch (err) {
    console.error(err.stack)
    user = await dummyUser()
  }
}
`
jedwards1211 commented 4 years ago

:tada: This issue has been resolved in version 1.0.3 :tada:

The release is available on:

Your semantic-release bot :package::rocket: