-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #70 from bantic/clean-up-helpers-code
Clean up helpers code
- Loading branch information
Showing
12 changed files
with
176 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
function transformer(file, api) { | ||
var j = api.jscodeshift; | ||
|
||
var foundHelper = false; | ||
|
||
var root = j(file.source); | ||
|
||
// Replaces: | ||
// import { helper } from '@ember/component/helper'; | ||
// With: | ||
// import { helper as buildHelper } from '@ember/component/helper'; | ||
root.find(j.ImportDeclaration, { | ||
source: { value: '@ember/component/helper' }, | ||
}).filter(path => { | ||
return path.value.specifiers[0].local.name === 'helper'; | ||
}) | ||
.forEach(function(path) { | ||
foundHelper = true; | ||
var specifier = j.importSpecifier( | ||
j.identifier('helper'), | ||
j.identifier('buildHelper') | ||
); | ||
|
||
path.value.specifiers[0] = specifier; | ||
}); | ||
|
||
// Replace helper(...) with buildHelper(...) | ||
if (foundHelper) { | ||
root.find(j.CallExpression, { | ||
callee: { name: 'helper' } | ||
}).forEach(path => { | ||
path.value.callee.name = 'buildHelper'; | ||
}); | ||
} | ||
|
||
return root.toSource(); | ||
} | ||
|
||
module.exports = transformer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters