schmod / babel-plugin-angularjs-annotate

Add Angular 1.x dependency injection annotations to ES6 code
http://schmod.github.io/babel-plugin-angularjs-annotate
MIT License
241 stars 26 forks source link

Crashes on object shorthand #16

Closed willsoto closed 7 years ago

willsoto commented 7 years ago

Currently fails with the following error:

TypeError: test.js: Cannot read property '$chained' of undefined

You should be able to reproduce this with the following code (test.js):

import angular from 'angular';
import ngRoute from 'angular-route';

export default angular.module('app', [
  ngRoute
])

.config(function($routeProvider) {
  'ngInject';

  $routeProvider
    .when('/some/url', {
      templateUrl: './template.html',
      controller: 'ViewController',
      controllerAs: 'view',
      resolve: {
        payload($route, $location) {
          'ngInject';

          return true;
        }
      }
    });
});

Create the following babelrc:

{
  "presets": [
    [
      "env",
      {
        "targets": {
          "chrome": 52
        }
      }
    ]
  ],
  "plugins": [
    "angularjs-annotate"
  ]
}

and the following command:

./node_modules/.bin/babel test.js

Versions:

Node: 7.0.0 NPM: 4.0.1 Babel: 6.18.0 (babel-core 6.18.2)


When you remove payload() {} from the resolve object, the code successfully transpiles.

schmod commented 7 years ago

Fixed this in 0.7.0. Let me know if it works for you!