-
Notifications
You must be signed in to change notification settings - Fork 150
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add --rename option to rename declarations and references #47
Conversation
The `--rename` option takes a string as input, treating every couple, separated by a space, as a find-replace option. For example, `--rename "$theService $myService "theFactory myFactory"`will replace `$theService` with `$myService` and `theFactory` with `myFactory` in both the declaration and in any annotation that will be added by ng-annotate. The actual use of the provider won't be changed. Closes olov#44
@@ -218,7 +218,7 @@ function matchRegular(node, ctx) { | |||
const args = node.arguments; | |||
const target = (is.someof(method.name, ["config", "run"]) ? | |||
args.length === 1 && args[0] : | |||
args.length === 2 && args[0].type === "Literal" && is.string(args[0].value) && args[1]); | |||
args.length === 2 && args[0].type === "Literal" && is.string(args[0].value) && [args[0], args[1]]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The main difference is here, where I return another target, besides the defined function, that is the given provider name.
Thanks for the PR! I'll review it and provide feedback as soon as I can (may take a day or two). |
Thanks! This was mainly needed to solve incompatibilities between |
While trying to build I realized that |
@@ -126,6 +131,15 @@ function runAnnotate(err, src) { | |||
}); | |||
} | |||
|
|||
if (config.rename) { | |||
let flattenRename = config.rename.split(" "); | |||
let renameMap = {}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Most of added let
s should be replaced with const
s. Even this one (const
is shallow constant, you can still mess with keys).
👍 |
Overall I think this is fine and I'm willing to merge it as an experimental feature. Because renaming is not really a core feature of ng-annotate, it may be removed in the future, in which case I'll try to make it possible to implement the same thing with a plugin. Also see #42. Make sure that you're confident with this. Before merging, it needs tests. Create a tests/rename_original.js and tests/rename_renamed.js and the necessary code in the runner. Also please change all your let to const, then only make things let when the variable binding changes (v8 will tell you if you're unsure, so will defs in build.sh). |
Achieving the same thing with a plugin would be awesome. |
Waiting for the merge! |
Ok, can you fix the following:
Thanks! |
Sure, I'm on vacation right now, I will be able to get back to it after
|
Conflicts: ng-annotate-main.js ng-annotate.js nginject-comments.js run-tests.js
About the rename API, could you please confirm that CLI example: $ node --harmony ng-annotate.js -a --rename "[{\"from\":\"$a\", \"to\":\"$aRenamed\"}]" tests/rename.js |
No, the CLI can function as you already made it, the API however: |
So every from-to association should be transformed into a |
|
The rename CLI option remains the same, but it is passed to `ng-annotate-main.js` as a from-to object collection; it is then transformed and used as a stringmap. Rename tests have been separated from the original full test and simplified to test against the main cases.
Changes have been pushed, thank you for your support in this :) |
@olov Would be great if you could merge this, it's blocking our release of a compat build for angular-strap. Thanks! |
The
--rename
option takes a string as input, treating every couple, separated by a space,as a find-replace option.
For example,
--rename "$theService $myService theFactory myFactory"
will replace$theService
with$myService
andtheFactory
withmyFactory
in both the declaration and in any annotation that will be added by ng-annotate. The actual use of the provider won't be changed.Closes #44