olov / ng-annotate

Add, remove and rebuild AngularJS dependency injection annotations
MIT License
2.03k stars 152 forks source link

Rest parameters error #251

Closed thany closed 7 years ago

thany commented 7 years ago

TL;DR: ng-annotate appears to choke on any code, even bits that don't need annotation, with rest params.

Consider this function then:

function foo(bar, ...more) {
  //Do whatever
}

As far as I can tell, stuff this somewhere in your code (make sure it doesn't get optimized away in some manner) and pull ng-annotate over it. It doesn't matter that this function has nothing to do with Angular, ng-annotate will error either way.

Error: StringMap expected string key
    at stringmap.set (D:\Klanten\qsdashboard\node_modules\stringmap\stringmap.js:100:19)
    at Scope.add (D:\Klanten\qsdashboard\node_modules\ng-annotate\build\es5\scope.js:102:17)
    at D:\Klanten\qsdashboard\node_modules\ng-annotate\build\es5\scopetools.js:65:25
    at Array.forEach (native)
    at createScopes (D:\Klanten\qsdashboard\node_modules\ng-annotate\build\es5\scopetools.js:64:21)
    at visit (D:\Klanten\qsdashboard\node_modules\ordered-ast-traverse\ordered-ast-traverse.js:25:19)
    at visit (D:\Klanten\qsdashboard\node_modules\ordered-ast-traverse\ordered-ast-traverse.js:46:21)
    at visit (D:\Klanten\qsdashboard\node_modules\ordered-ast-traverse\ordered-ast-traverse.js:43:25)
    at visit (D:\Klanten\qsdashboard\node_modules\ordered-ast-traverse\ordered-ast-traverse.js:43:25)
    at visit (D:\Klanten\qsdashboard\node_modules\ordered-ast-traverse\ordered-ast-traverse.js:46:21)

StringMap is not to blame, it seems. It's just trying to insert an key/value pair into a stringmap, for which key=undefined, and value is this object:

{ kind: 'param',
  node:
   Node {
     type: 'RestElement',
     start: 589009,
     end: 589019,
     loc: SourceLocation { start: [Object], end: [Object] },
     range: [ 589009, 589019 ],
     argument:
      Node {
        type: 'Identifier',
        start: 589012,
        end: 589019,
        loc: [Object],
        range: [Object],
        name: 'sources' } } }

This tells me, it is at least aware of rest params. It's just not supporting them correctly.

Please note: I'm not using any type of transpiler/cispiler of any kind. I'm using ES6 straight in the browser.

olov commented 7 years ago

245

thany commented 7 years ago

So this project is abandoned?

olov commented 7 years ago

It's just about to be deprecated in favor of https://github.com/schmod/babel-plugin-angularjs-annotate/tree/next so there will be no new feature-releases. Thanks for using it and I hope you'll like its successor.

thany commented 7 years ago

That's a sad thing to happen. Why would you let yourself be defeated? All you need is ES6 support, and node.js provides it beautifully.

There no reason to deprecate one package just because another similar one happens to exist. Besides, the one you referred is a Babel plugin, and I imagine setting up Babel (which I have absolutely no need for by itself) is a lot more pain than including ngAnnotate.