Skip to content

Commit

Permalink
feat(data-point-codemods): error in existing input variable
Browse files Browse the repository at this point in the history
  • Loading branch information
Acatl Pacheco committed Jan 24, 2018
1 parent 8117cf7 commit 7b9aa50
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ it('throws variable value is already in scope', () => {
const jscodeshift = require('jscodeshift')
const transform = require('../../transforms/reducer-args-acc-to-val-acc')
const source = `
const f = value = acc => {
return value + acc.value
const f = input = acc => {
return input + acc.value
}
`

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,30 +73,30 @@ module.exports = (file, api, options) => {
return node.value
}

function checkValueVariable (node) {
function checkInputVariable (node) {
j(node)
.find(j.Identifier, {
name: 'value'
name: 'input'
})
.forEach(nodePath => {
const parentNode = nodePath.parentPath.value
if (parentNode.type !== 'MemberExpression') {
const nodeStart = parentNode.loc.start
throw Error(
util.format(
'Refactor Reducer arguments (acc) -> (acc, value) Failed.',
'\nA variable with name `value` already exists in the scope of a reducer function.',
'Refactor Reducer arguments (acc) -> (input, acc) Failed.',
'\nA variable with name `input` already exists in the scope of a reducer function.',
`\n\n${j(node).toSource()}`,
`\n^------- ${file.path}:${nodeStart.line}:${nodeStart.column}`,
"\n\nTry refactoring this block of code to remove any variable of name 'value' before running the codemod.\n\n"
"\n\nTry refactoring this block of code to remove any variable of name 'input' before running the codemod.\n\n"
)
)
}
})
}

function refactorReducer (node) {
checkValueVariable(node)
checkInputVariable(node)
replaceAccValueReferences(node)
addValueParam(node)
}
Expand Down

0 comments on commit 7b9aa50

Please sign in to comment.