Skip to content

Problem with function hoisting #29

@lucassus

Description

@lucassus

Input code:

module.exports = function($filterProvider) {
  'ngInject';

  function ordinalSuffixFilter(ordinalSuffix) {
    'ngInject';


    return function(day) {
      if (angular.isNumber(day) && isFinite(day)) {
        return ordinalSuffix(Number(day));
      }
    };
  }

  $filterProvider.register('sqOrdinalSuffix', ordinalSuffixFilter);

};

Output code:

'use strict';

ordinalSuffixFilter.$inject = ['ordinalSuffix'];
module.exports = ['$filterProvider', function ($filterProvider) {
  'ngInject';

  function ordinalSuffixFilter(ordinalSuffix) {
    'ngInject';

    return function (day) {
      if (angular.isNumber(day) && isFinite(day)) {
        return ordinalSuffix(Number(day));
      }
    };
  }

  $filterProvider.register('sqOrdinalSuffix', ordinalSuffixFilter);
}];

In the given example ordinalSuffixFilter.$inject = ['ordinalSuffix']; is defined on the wrong scope therefore it leads to "undefined variable orfinalSuffixFilter" error. I believe that in order to avoid such errors annotations should be added directly above the annotated function.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions