function-codemorphs

codemods for in-IDE refactoring of functions

Usage no npm install needed!

<script type="module">
  import functionCodemorphs from 'https://cdn.skypack.dev/function-codemorphs';
</script>

README

function-codemorphs

CircleCI Coverage Status semantic-release Commitizen friendly npm version

codemods for in-IDE refactoring of functions

These aren't really intended to be used with the jscodeshift CLI, but rather for building IDE extensions.

convertArrowFunctionBodyToBlockStatement

Converts an arrow function with an expression body to a block statement.

Before

const foo = () => 'foo!'

After

const foo = () => {
  return 'foo!'
}

Special Options

selectionStart (number, required)

The start of the selection in the source code. This is used for determining which function to convert.

selectionEnd (number, required)

The end of the selection in the source code. This is used for determining which function to convert.

convertArrowFunctionBodyToExpression

Converts the block statement body of an arrow function to an expression, as long as the body only consists of a return statement.

Before

const foo = () => {
  return 'foo!'
}

After

const foo = () => 'foo!'

Special Options

selectionStart (number, required)

The start of the selection in the source code. This is used for determining which function to convert.

selectionEnd (number, required)

The end of the selection in the source code. This is used for determining which function to convert.