Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Problem with function hoisting #29

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
lucassus opened this issue Sep 20, 2017 · 3 comments
Closed

Problem with function hoisting #29

lucassus opened this issue Sep 20, 2017 · 3 comments
Assignees

Comments

@lucassus
Copy link

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.

@lucassus
Copy link
Author

It could be related to #22

@schmod schmod self-assigned this Sep 20, 2017
@schmod
Copy link
Owner

schmod commented Sep 20, 2017

I'll take a look at this. For now, you can work around this by declaring the function as a variable.

@schmod schmod closed this as completed in 03da4fb Sep 26, 2017
@schmod
Copy link
Owner

schmod commented Sep 26, 2017

Fixed in v0.8.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants