Skip to content

Commit 23b53fa

Browse files
committed
docs
1 parent 81b1f58 commit 23b53fa

File tree

3 files changed

+198
-255
lines changed

3 files changed

+198
-255
lines changed

IMPLICIT.md

+98
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
# Implicit matching
2+
ng-annotate uses static analysis to detect common AngularJS code patterns.
3+
There are patterns it does not and never will understand and for those you
4+
should use `"ngInject"` instead, see [README.md](README.md).
5+
6+
7+
## Declaration forms
8+
ng-annotate understands the two common declaration forms:
9+
10+
Long form:
11+
12+
```js
13+
angular.module("MyMod").controller("MyCtrl", function($scope, $timeout) {
14+
});
15+
```
16+
17+
Short form:
18+
19+
```js
20+
myMod.controller("MyCtrl", function($scope, $timeout) {
21+
});
22+
```
23+
24+
It's not limited to `.controller` of course. It understands `.config`, `.factory`,
25+
`.directive`, `.filter`, `.run`, `.controller`, `.provider`, `.service`, `.decorator`,
26+
`.component`, `.animation` and `.invoke`.
27+
28+
For short forms it does not need to see the declaration of `myMod` so you can run it
29+
on your individual source files without concatenating. If ng-annotate detects a short form
30+
false positive then you can use the `--regexp` option to limit the module identifier.
31+
Examples: `--regexp "^myMod$"` (match only `myMod`) or `--regexp "^$"` (ignore short forms).
32+
You can also use `--regexp` to opt-in for more advanced method callee matching, for
33+
example `--regexp "^require(.*)$"` to detect and transform
34+
`require('app-module').controller(..)`. Not using the option is the same as passing
35+
`--regexp "^[a-zA-Z0-9_\$\.\s]+$"`, which means that the callee can be a (non-unicode)
36+
identifier (`foo`), possibly with dot notation (`foo.bar`).
37+
38+
ng-annotate understands `angular.module("MyMod", function(dep) ..)` as an alternative to
39+
`angular.module("MyMod").config(function(dep) ..)`.
40+
41+
ng-annotate understands `this.$get = function($scope) ..` and
42+
`{.., $get: function($scope) ..}` inside a `provider`. `self` and `that` can be used as
43+
aliases for `this`.
44+
45+
ng-annotate understands `return {.., controller: function($scope) ..}` inside a
46+
`directive`.
47+
48+
ng-annotate understands `$provide.decorator("bar", function($scope) ..)`, `$provide.service`,
49+
`$provide.factory` and `$provide.provider`.
50+
51+
ng-annotate understands `$routeProvider.when("path", { .. })`.
52+
53+
ng-annotate understands `$controllerProvider.register("foo", function($scope) ..)`.
54+
55+
ng-annotate understands `$httpProvider.interceptors.push(function($scope) ..)` and
56+
`$httpProvider.responseInterceptors.push(function($scope) ..)`.
57+
58+
ng-annotate understands `$injector.invoke(function ..)`.
59+
60+
ng-annotate understands [ui-router](https://github.com/angular-ui/ui-router) (`$stateProvider` and
61+
`$urlRouterProvider`).
62+
63+
ng-annotate understands `$uibModal.open` (and `$modal.open`) ([angular-ui/bootstrap](http://angular-ui.github.io/bootstrap/)).
64+
65+
ng-annotate understands `$mdDialog.show`, `$mdToast.show` and `$mdBottomSheet.show`
66+
([angular material design](https://material.angularjs.org/#/api/material.components.dialog/service/$mdDialog)).
67+
68+
ng-annotate understands `myMod.store("MyCtrl", function ..)`
69+
([flux-angular](https://github.com/christianalfoni/flux-angular)).
70+
71+
ng-annotate understands chaining.
72+
73+
ng-annotate understands IIFE's and attempts to match through them, so
74+
`(function() { return function($scope) .. })()` works anywhere
75+
`function($scope) ..` does (for any IIFE args and params).
76+
77+
ng-annotate understands [angular-dashboard-framework](https://github.com/sdorra/angular-dashboard-framework)
78+
via optional `--enable angular-dashboard-framework`.
79+
80+
81+
## Reference-following
82+
ng-annotate follows references. This works if and only if the referenced declaration is
83+
a) a function declaration or
84+
b) a variable declaration with an initializer.
85+
Modifications to a reference outside of its declaration site are ignored by ng-annotate.
86+
87+
These examples will get annotated:
88+
89+
```js
90+
function MyCtrl($scope, $timeout) {
91+
}
92+
var MyCtrl2 = function($scope) {};
93+
94+
angular.module("MyMod").controller("MyCtrl", MyCtrl);
95+
angular.module("MyMod").controller("MyCtrl", MyCtrl2);
96+
```
97+
98+

OPTIONS.md

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
## ng-annotate command-line options
2+
3+
`ng-annotate OPTIONS <file>`. The errors (if any) will go to stderr,
4+
the transpiled output to stdout.
5+
6+
Use the `--add` (`-a`) option to add annotations where non-existing,
7+
use `--remove` (`-r`) to remove all existing annotations,
8+
use `--add --remove` (`-ar`) to rebuild all annotations.
9+
10+
Use the `-o` option to write output to file.
11+
12+
Provide `-` instead of an input `<file>` to read input from stdin.
13+
14+
Use the `--sourcemap` option to generate an inline sourcemap.
15+
16+
Use the `--sourceroot` option to set the sourceRoot property of the generated sourcemap.
17+
18+
Use the `--single_quotes` option to output `'$scope'` instead of `"$scope"`.
19+
20+
Use the `--regexp` option to restrict matching further or to expand matching.
21+
See description further down.
22+
23+
Use the `--list` option to list optional matchers.
24+
25+
Use the `--enable` option to enable optional matcher.
26+
27+
*experimental* Use the `--rename` option to rename providers (services, factories,
28+
controllers, etc.) with a new name when declared and referenced through annotation.
29+
Use it like this: `--rename oldname1 newname1 oldname2 newname2`
30+
31+
*experimental* Use the `--plugin` option to load a user plugin with the provided path,
32+
1.x may change API). See [plugin-example.js](plugin-example.js) for more info.
33+
34+
*experimental* Use the `--stats` option to print statistics on stderr.
35+
36+
37+
## Library (API)
38+
ng-annotate can be used as a library. See [ng-annotate.js](ng-annotate.js) for further info about
39+
options and return value.
40+
41+
```js
42+
var ngAnnotate = require("ng-annotate");
43+
var somePlugin = require("./some/path/some-plugin");
44+
var res = ngAnnotate(src, {
45+
add: true,
46+
plugin: [somePlugin],
47+
rename: [{from: "generalname", to: "uniquename"}, {from: "alpha", to: "beta"}],
48+
map: { inline: false, inFile: "source.js", sourceRoot: "/path/to/source/root" },
49+
enable: ["angular-dashboard-framework"],
50+
});
51+
var errorstringArray = res.errors;
52+
var transformedSource = res.src;
53+
var transformedSourceMap = res.map;
54+
```

0 commit comments

Comments
 (0)