andrey-skl / ng-annotate-loader

Webpack loader to annotate angular applications
MIT License
120 stars 28 forks source link

Named Function Annotation #9

Closed patrickhousley closed 9 years ago

patrickhousley commented 9 years ago

I do not seem to be able to use a named function without including the annotation above it.

import '../common/responsive.service'
import '../common/cookie.service'

module.service('menuConfigService', MenuConfigService);

function MenuConfigService(responsiveUtils, cookieService) {
  var cfg = {};

  var keys = Object.keys(bladeData);
  keys.forEach(function (key) {
    var keyData = _.cloneDeep(bladeData[key]);
    if (typeof keyData === 'object' && keyData.data) {
      keyData.data = convertMobileData(keyData['data'], responsiveUtils, cookieService);
    }
    cfg[key] = keyData;
  });

  return cfg;
}

The above code will result in an error stating MenuConfigService is not using explicit annotation. This does appear to be supported by ng-annotate https://github.com/olov/ng-annotate/issues/57. Is this an issue with the loader?

  module: {
    loaders: [
      {
        test: /\.jsx?$/,
        loader: 'ng-annotate-loader!babel-loader?stage=0',
        exclude: /web_modules|node_modules|bower_components/
      },
      {test: /\.(png|jpg|jpeg|gif|svg)$/, loader: 'url-loader?limit=10000'},
      {test: /\.json$/, loader: 'json-loader'},
      {test: /\.jade$/, loader: 'raw!sprint-jade-loader'}
    ]
  }
andrey-skl commented 9 years ago

@patrickhousley according to referenced issue it should work, but it doesn't if you're right. I'm going to investigate that, thanks.

patrickhousley commented 9 years ago

Below is the code that is returned from the babel loader and sent into the annotate loader. It is the exact same when it comes out of the annotate loader.

'use strict';

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }

var _angular = require('angular');

var _angular2 = _interopRequireDefault(_angular);

var _jquery = require('jquery');

var _jquery2 = _interopRequireDefault(_jquery);

var _module2 = require('../module');

var _module3 = _interopRequireDefault(_module2);

// Import any modules external to the menu component

require('../common/responsive.service');

require('../common/cookie.service');

_module3['default'].service('menuConfigService', MenuConfigService);

function MenuConfigService(responsiveUtils, cookieService) {
  .....
}

I don't think this is an issue with ng-annotate-loader. I updated the ng-annotate dependency for the loader locally and still had the issue.

andrey-skl commented 9 years ago

Okay, now it is enough to update ng-annotate go get that feature

andrey-skl commented 9 years ago

Have fixed that in 0.0.7 verision, npm package is updated. Please check.

RickEyre commented 9 years ago

This seems to still be an issue with version 0.0.10

andrey-skl commented 9 years ago

@RickEyre not sure. We have a passing test https://github.com/huston007/ng-annotate-loader/blob/master/examples/simple/file-to-annotate.js#L23 https://github.com/huston007/ng-annotate-loader/blob/master/examples/simple/annotated-reference.js#L72