switch-call-expression-to-new-expression.js 597 B

123456789101112131415161718
  1. 'use strict';
  2. const {isParenthesized} = require('../utils/parentheses.js');
  3. const shouldAddParenthesesToNewExpressionCallee = require('../utils/should-add-parentheses-to-new-expression-callee.js');
  4. function * switchCallExpressionToNewExpression(node, sourceCode, fixer) {
  5. yield fixer.insertTextBefore(node, 'new ');
  6. const {callee} = node;
  7. if (
  8. !isParenthesized(callee, sourceCode)
  9. && shouldAddParenthesesToNewExpressionCallee(callee)
  10. ) {
  11. yield fixer.insertTextBefore(callee, '(');
  12. yield fixer.insertTextAfter(callee, ')');
  13. }
  14. }
  15. module.exports = switchCallExpressionToNewExpression;