Gathering detailed insights and metrics for babel-plugin-angularjs-annotate
Gathering detailed insights and metrics for babel-plugin-angularjs-annotate
Gathering detailed insights and metrics for babel-plugin-angularjs-annotate
Gathering detailed insights and metrics for babel-plugin-angularjs-annotate
Add Angular 1.x dependency injection annotations to ES6 code
npm install babel-plugin-angularjs-annotate
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
241 Stars
497 Commits
27 Forks
6 Watching
5 Branches
1 Contributors
Updated on 20 Nov 2024
Minified
Minified + Gzipped
JavaScript (100%)
Cumulative downloads
Total Downloads
Last day
-23.3%
16,651
Compared to previous day
Last week
-9.9%
96,309
Compared to previous week
Last month
17.9%
408,970
Compared to previous month
Last year
-27.7%
4,422,447
Compared to previous year
Fork of ng-annotate for Babel users, with a focus on speed and ES6 support.
Adds Angular 1.x DI annotations to ES5/ES6 code being processed by Babel, with support for explicit annotations (/* @ngInject */
), and automatic (implicit) annotation of typical Angular code patterns.
Fully compatible with ES5, transpiled ES6, and raw ES6 sources. Offers significantly reduced build times for projects already using Babel, compared to the standalone ng-annotate tool.
This plugin currently supports matching and transforming all of the patterns currently recognized by ng-annotate (explicit and implicit), and passes the relevant portions of ng-annotate's test suite.
Use like any other Babel plugin.
Most users will want to run
1$ npm install babel-plugin-angularjs-annotate --save-dev
and add the plugin to your .babelrc
file:
1{ 2 "presets": ["@babel/preset-env"], 3 "plugins": ["angularjs-annotate"] 4}
explicitOnly
By default, this plugin will attempt to add annotations to common AngularJS code patterns. This behavior can be disabled (requiring you to mark up functions with /* @ngInject */
or 'ngInject'
).
To pass this option to the plugin, add it to your Babel configuration:
1{ 2 "presets": ["@babel/preset-env"], 3 "plugins": [["angularjs-annotate", { "explicitOnly" : true}]] 4}
See ng-annotate's documentation and the test sources for details about the patterns that can be automatically detected by ng-annotate and this plugin, as well as information about how to explicitly mark functions and classes for annotation.
This plugin can annotate some ES6 classes and arrow functions that are not supported by ng-annotate:
Arrow functions may be annotated anywhere that a "regular" function expression may be used.
NOTE: There are places where you shouldn't use arrow functions in an Angular application. Inside of an arrow function, the value of this
is inherited from the lexical scope enclosing the function. For this reason, arrow functions should not be used to declare Angular services or providers.
If you choose to ignore this warning, we'll add the annotations to your services and providers anyway, but your application probably won't work. Future releases may treat this condition as an error.
1angular.module("MyMod").controller("MyCtrl", ($scope, $timeout) => {});
Becomes:
1angular.module("MyMod").controller("MyCtrl", ["$scope", "$timeout", ($scope, $timeout) => {}]);
Arrow functions may also be explicitly marked for annotation.
1var x = /* @ngInject */ ($scope) => {};
Becomes:
1var x = /* @ngInject */ ($scope) => {}; 2x.$inject = ["$scope"]
If a class is declared as an Angular service or factory in the same file as it is declared, it will be annotated automatically:
1class svc { 2 constructor(dep1){ 3 this.dep1 = dep1; 4 } 5} 6angular.module('MyMod').service('MySvc', svc);
Becomes:
1class svc { 2 constructor(dep1){ 3 this.dep1 = dep1; 4 } 5} 6svc.$inject = ['dep1']; 7angular.module('MyMod').service('MySvc', svc);
If a class is exported and used in another file/module, it must be explicitly marked for injection:
1/* @ngInject */ 2class svc { 3 constructor(dep1){ 4 this.dep1 = dep1; 5 } 6}
Prologue directives may also be used here:
1class svc { 2 constructor(dep1){ 3 "ngInject"; 4 this.dep1 = dep1; 5 } 6}
Object methods can be written with the new shorthand syntax:
1let foo = { 2 bar($http){ 3 'ngInject'; 4 } 5};
1$stateProvider.state('myState', { 2 controller($scope) {} 3});
Exported functions and classes may be annotated. Exported functions must have names:
1/* @ngInject */ 2export default function svc(dep1){}
This project/experiment does not seek to replace ng-annotate. However, it does seek to provide similar functionality for Angular 1.x developers who are already using Babel and/or writing code in ES6.
Because of some of the limitations presented by Babel's transformation process, this project does not aim to achieve feature parity, or provide identical output to ng-annotate. Notably, Babel does not preserve formatting and indentations like ng-annotate does, and this project does not seek to replicate the features of ng-annotate that remove or transform existing annotations.
Initially, I had hoped to make very few modifications to the upstream sources, in the hopes of eventually merging babel support directly into ng-annotate. Unfortunately, Babylon appears to have diverged too far from Acorn to make that goal realistic. (I would love to be wrong here, and would welcome contributions that close the gap between the two projects!)
npm test
MIT
, see LICENSE file.
This project is a fork of ng-annotate, which was written by Olov Lassus with the kind help by contributors. Follow @olov on Twitter for updates about ng-annotate.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
Found 4/25 approved changesets -- score normalized to 1
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
46 existing vulnerabilities detected
Details
Score
Last Scanned on 2024-11-18
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More