{"id":14973180,"url":"https://github.com/schmod/babel-plugin-angularjs-annotate","last_synced_at":"2025-10-01T23:30:37.609Z","repository":{"id":48834692,"uuid":"51088360","full_name":"schmod/babel-plugin-angularjs-annotate","owner":"schmod","description":"Add Angular 1.x dependency injection annotations to ES6 code","archived":false,"fork":true,"pushed_at":"2023-02-09T17:00:38.000Z","size":2052,"stargazers_count":240,"open_issues_count":28,"forks_count":27,"subscribers_count":6,"default_branch":"master","last_synced_at":"2024-10-30T02:30:48.889Z","etag":null,"topics":["angularjs","babel","babel-plugin","dependency-injection","javascript"],"latest_commit_sha":null,"homepage":"http://schmod.github.io/babel-plugin-angularjs-annotate","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"olov/ng-annotate","license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/schmod.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGES.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-02-04T16:21:17.000Z","updated_at":"2024-08-16T10:18:51.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/schmod/babel-plugin-angularjs-annotate","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/schmod%2Fbabel-plugin-angularjs-annotate","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/schmod%2Fbabel-plugin-angularjs-annotate/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/schmod%2Fbabel-plugin-angularjs-annotate/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/schmod%2Fbabel-plugin-angularjs-annotate/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/schmod","download_url":"https://codeload.github.com/schmod/babel-plugin-angularjs-annotate/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":234571679,"owners_count":18854352,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["angularjs","babel","babel-plugin","dependency-injection","javascript"],"created_at":"2024-09-24T13:48:16.951Z","updated_at":"2025-10-01T23:30:37.246Z","avatar_url":"https://github.com/schmod.png","language":"JavaScript","readme":"# babel-plugin-angularjs-annotate\n\n[![Circle CI](https://circleci.com/gh/schmod/babel-plugin-angularjs-annotate.svg?style=svg)](https://circleci.com/gh/schmod/babel-plugin-angularjs-annotate) [![npm version](https://badge.fury.io/js/babel-plugin-angularjs-annotate.svg)](https://badge.fury.io/js/babel-plugin-angularjs-annotate)\n\nFork of [ng-annotate](https://github.com/olov/ng-annotate) for Babel users, with a focus on speed and ES6 support.\n\nAdds 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.\n\nFully 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.\n\nThis 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.\n\n## Installation\n\nUse like any other [Babel plugin](https://babeljs.io/docs/plugins/).\n\nMost users will want to run\n\n```sh\n$ npm install babel-plugin-angularjs-annotate --save-dev\n```\n\nand add the plugin to your `.babelrc` file:\n\n```json\n{\n  \"presets\": [\"@babel/preset-env\"],\n  \"plugins\": [\"angularjs-annotate\"]\n}\n```\n\n## Options\n\n### `explicitOnly`\n\nBy 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'`).\n\nTo pass this option to the plugin, [add it to your Babel configuration](https://babeljs.io/docs/plugins/#plugin-options):\n\n```json\n{\n  \"presets\": [\"@babel/preset-env\"],\n  \"plugins\": [[\"angularjs-annotate\", { \"explicitOnly\" : true}]]\n}\n```\n\n## Usage\n\nSee [ng-annotate](https://github.com/olov/ng-annotate)'s documentation and the [test sources](tests/) 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.\n\n[Try it out in your browser](http://schmod.github.io/babel-plugin-angularjs-annotate/).\n\n### ES6 Annotations\n\nThis plugin can annotate some ES6 classes and arrow functions that are not supported by ng-annotate:\n\n#### Implicit arrow function annotation\n\nArrow functions may be annotated anywhere that a \"regular\" function expression may be used.\n\n**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.\n\n_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._\n\n```js\nangular.module(\"MyMod\").controller(\"MyCtrl\", ($scope, $timeout) =\u003e {});\n```\n\nBecomes:\n\n```js\nangular.module(\"MyMod\").controller(\"MyCtrl\", [\"$scope\", \"$timeout\", ($scope, $timeout) =\u003e {}]);\n```\n\n#### Explicit arrow function annotation\n\nArrow functions may also be explicitly marked for annotation.\n\n```js\nvar x = /* @ngInject */ ($scope) =\u003e {};\n```\n\nBecomes:\n\n```js\nvar x = /* @ngInject */ ($scope) =\u003e {};\nx.$inject = [\"$scope\"]\n```\n\n#### Implicit Class Annotation\n\nIf a class is declared as an Angular service or factory in the same file as it is declared, it will be annotated automatically:\n\n```js\nclass svc {\n    constructor(dep1){\n        this.dep1 = dep1;\n    }\n}\nangular.module('MyMod').service('MySvc', svc);\n```\n\nBecomes:\n\n```js\nclass svc {\n    constructor(dep1){\n        this.dep1 = dep1;\n    }\n}\nsvc.$inject = ['dep1'];\nangular.module('MyMod').service('MySvc', svc);\n```\n\n#### Explicit Class Annotation\n\nIf a class is exported and used in another file/module, it must be explicitly marked for injection:\n\n```js\n/* @ngInject */\nclass svc {\n  constructor(dep1){\n      this.dep1 = dep1;\n  }\n}\n```\n\nPrologue directives may also be used here:\n\n```js\nclass svc {\n  constructor(dep1){\n      \"ngInject\";\n      this.dep1 = dep1;\n  }\n}\n```\n\n\n#### Object Method Shorthand\n\nObject methods can be written with the new [shorthand](http://exploringjs.com/es6/ch_oop-besides-classes.html#object-literal-method-definitions) syntax:\n\n```js\nlet foo = {\n  bar($http){\n    'ngInject';\n  }\n};\n```\n\n```js\n$stateProvider.state('myState', {\n  controller($scope) {}\n});\n```\n\n#### Exports\n\nExported functions and classes may be annotated.  Exported functions must have names:\n\n```js\n/* @ngInject */\nexport default function svc(dep1){}\n```\n\n## Notes \u0026 Philosophy\n\nThis project/experiment does _not_ seek to replace ng-annotate.  However, it does seek to provide similar\nfunctionality for Angular 1.x developers who are already using Babel and/or writing code in ES6.\n\nBecause of some of the limitations presented by Babel's transformation process, this project does not aim to\nachieve feature parity, or provide identical output to ng-annotate. Notably, Babel does not preserve formatting\nand indentations like ng-annotate does, and this project does not seek to replicate the features of ng-annotate that remove or transform existing annotations.\n\nInitially, I had hoped to make very few modifications to the upstream sources, in the hopes of eventually\nmerging babel support directly into ng-annotate.  Unfortunately, Babylon appears to have diverged too\nfar 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!)\n\n### To run tests:\n\n```\nnpm test\n```\n\n\n## License\n`MIT`, see [LICENSE](LICENSE) file.\n\nThis project is a fork of [ng-annotate](https://github.com/olov/ng-annotate), which  was written by [Olov Lassus](https://github.com/olov) with the kind help by\n[contributors](https://github.com/olov/ng-annotate/graphs/contributors).\n[Follow @olov](https://twitter.com/olov) on Twitter for updates about ng-annotate.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fschmod%2Fbabel-plugin-angularjs-annotate","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fschmod%2Fbabel-plugin-angularjs-annotate","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fschmod%2Fbabel-plugin-angularjs-annotate/lists"}