Skip to content

Latest commit

 

History

History
49 lines (39 loc) · 952 Bytes

no-do-expression.md

File metadata and controls

49 lines (39 loc) · 952 Bytes

no-do-expression

This prevents the use of Do Expressions

let a = do {
  if(x > 10) {
    'big'
  } else {
    'small'
  }
}

These will not be allowed because they are not supported in the following browsers:

  • Edge (any version at the time of writing)
  • Safari (any version at the time of writing)
  • Firefox (any version at the time of writing)
  • Chrome (any version at the time of writing)

What is the Fix?

If the expression is short, you can consider using a ternary operator:

// these are equivalent:
let a = do {
  if(x > 10) {
    'big'
  } else {
    'small'
  }
}
let a = x > 10 ? 'big' : 'small'

You can also avoid the use of the do expression, and declare a variable upfront without assigning it immediately:

let a
if(x > 10) {
  let a = 'big'
} else {
  let a = 'small'
}

This can be safely disabled if you intend to compile code with the @babel/plugin-proposal-do-expressions Babel plugin.