Skip to content

Commit

Permalink
fix: function-paren-newline: crash on "new new Foo();"
Browse files Browse the repository at this point in the history
  • Loading branch information
coderaiser committed May 9, 2022
1 parent 9b17d6f commit d42e865
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
7 changes: 4 additions & 3 deletions lib/rules/function-paren-newline.js
Expand Up @@ -191,10 +191,11 @@ module.exports = {
function getParenTokens(node) {
switch (node.type) {
case "NewExpression":
if (!node.arguments.length && !(
astUtils.isOpeningParenToken(sourceCode.getLastToken(node, { skip: 1 })) &&
if (node.callee.type === "NewExpression" ||
!node.arguments.length && !(
astUtils.isOpeningParenToken(sourceCode.getLastToken(node, { skip: 1 })) &&
astUtils.isClosingParenToken(sourceCode.getLastToken(node))
)) {
)) {

// If the NewExpression does not have parens (e.g. `new Foo`), return null.
return null;
Expand Down
1 change: 1 addition & 0 deletions tests/lib/rules/function-paren-newline.js
Expand Up @@ -30,6 +30,7 @@ const ruleTester = new RuleTester({ parserOptions: { ecmaVersion: 6 } });
ruleTester.run("function-paren-newline", rule, {

valid: [
"new new Foo();",

// multiline option (default)
"function baz(foo, bar) {}",
Expand Down

0 comments on commit d42e865

Please sign in to comment.