babel-plugin-transform-ng-autoinject

Transform __autoinject($rootScope) to angularjs' inject((_$rootScope_) => $rootScope = _$rootScope_)

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
babel-plugin-transform-ng-autoinject
2.0.25 years ago5 years agoMinified + gzip package size for babel-plugin-transform-ng-autoinject in KB

Readme

FOR BABEL 7.X INSTALL V2.X - FOR OLDER V1.X
babel-plugin-transform-ng-autoinject
When writing tests for AngularJS 1.x ease the pain of writing enormous boilerplate like this:
let $rootScope, $httpBackend
beforeEach(inject((_$rootScope_, _$httpBackend_) => {
  $rootScope = _$rootScope_;
  $httpBackend = _$httpBackend_;
}));

With the following syntax:
let $rootScope, $httpBackend
beforeEach(__autoinject($rootScope, $httpBackend));

The plugin simply transforms the __autoinject expression into the former inject(...)
The exact form the plugin outputs the autoinject expression is:
let $rootScope, $httpBackend
beforeEach(inject((_$rootScope_, _$httpBackend_) => {
  ({
    $rootScope,
    $httpBackend
  } = {
    $rootScope: _$rootScope_;
    $httpBackend: _$httpBackend_;
  });
}));
Installation
npm install --save-dev babel-plugin-transform-ng-autoinject

.babelrc --
{
  "presets": ["es2016"],
  "plugins": ["transform-ng-autoinject"]
}