Wikunia / brackets-FuncDocr

FuncDocr generates JS/PHPDoc annotations for your functions
101 stars 14 forks source link

Named function expression with the key being a string is not recognized #85

Open Anima-t3d opened 8 years ago

Anima-t3d commented 8 years ago

A named expression with the key being a string is not recognised. See 'hello2'

var test = {
    /**
     * [[Description]]
     * @param   {[[Type]]} one       [[Description]]
     * @returns {string}   [[Description]]
     */
    hello: function (one) {
        return 'test';
    },
    /**
    */
    'hello2': function (two) {
        return 'test2';
    }
}
Wikunia commented 8 years ago

I never saw that before. Why do you ever need this? :D

Anima-t3d commented 8 years ago

You would need it when the key contains . or -

Wikunia commented 8 years ago

They aren't allowed as variable names! You can check whether it's allowed or not here: https://mothereff.in/js-variables

Anima-t3d commented 8 years ago

They aren't allowed as variable names!

I wasn't referring to variable name. I was referring to JavaScript property names and they are allowed see https://mothereff.in/js-properties but: You need to quote this property name

I hope that is more clear?

Anima-t3d commented 8 years ago

@Wikunia can you please include this? It is often used in js when writing Meteor.methods in Meteor.

Example in ES6:

Meteor.methods({
  'todos.updateText'({ todoId, newText }) {
    new SimpleSchema({
      todoId: { type: String },
      newText: { type: String }
    }).validate({ todoId, newText });

    const todo = Todos.findOne(todoId);

    if (!todo.editableBy(this.userId)) {
      throw new Meteor.Error('todos.updateText.unauthorized',
        'Cannot edit todos in a private list that is not yours');
    }

    Todos.update(todoId, {
      $set: { text: newText }
    });
  }
});

Thanks.

Wikunia commented 8 years ago

Unfortunately that ' stuff isn't the only problem here :/ Don't have much time to work on that one. At the moment the extension works using regular expressions (see readme) and it would be best to have a real parser for that. But at the moment my time is limited as well as the financial support. I'm sorry for that one :( The problem at your example is that ES6 isn't really supported in my extension so destructuring doesn't work at the moment.

Anima-t3d commented 8 years ago

I noticed the usage of regular expressions. I am mainly interested in the support for ' and can completely understand you not being able to support the quirky stuff ES6 brings. I just showed the example on the official guide, which happens to use ES6.

Your efforts are very much appreciated! Thanks!