Prettier: Removing necessary member expression parenthesis for new

Created on 7 Jun 2017  路  3Comments  路  Source: prettier/prettier

Prettier 1.4.2 is doing this:

  function createObj() {
    return { prop: class {} };
  }

- new (createObj()).prop();
+ new createObj().prop();

This changes the behavior of the code from:

let obj = createObj();
new obj.prop();

To:

let obj = new createObj();
obj.prop();

[[Demo](https://prettier.github.io/prettier/#%7B%22content%22%3A%22function%20createObj()%20%7B%5Cn%20%20return%20%7B%20prop%3A%20class%20%7B%7D%20%7D%3B%5Cn%7D%5Cn%5Cnnew%20(createObj()).prop()%3B%5Cn%22%2C%22options%22%3A%7B%22printWidth%22%3A80%2C%22tabWidth%22%3A2%2C%22singleQuote%22%3Afalse%2C%22trailingComma%22%3A%22none%22%2C%22bracketSpacing%22%3Atrue%2C%22jsxBracketSameLine%22%3Afalse%2C%22parser%22%3A%22babylon%22%2C%22semi%22%3Atrue%2C%22useTabs%22%3Afalse%2C%22doc%22%3Afalse%7D%7D)]

locked-due-to-inactivity high bug

Most helpful comment

I just published 1.4.3 which fixes it. Thanks for reporting it!

All 3 comments

Thanks for the repro, I'll send a fix.

I just published 1.4.3 which fixes it. Thanks for reporting it!

Thanks for the quick fix!

Was this page helpful?
0 / 5 - 0 ratings