brackets-FuncDocr icon indicating copy to clipboard operation
brackets-FuncDocr copied to clipboard

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

Open Anima-t3d opened this issue 9 years ago • 7 comments

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';
    }
}

Anima-t3d avatar May 23 '16 09:05 Anima-t3d

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

Wikunia avatar May 24 '16 13:05 Wikunia

You would need it when the key contains . or -

Anima-t3d avatar May 25 '16 06:05 Anima-t3d

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

Wikunia avatar May 25 '16 11:05 Wikunia

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 avatar May 26 '16 02:05 Anima-t3d

@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.

Anima-t3d avatar Jun 10 '16 07:06 Anima-t3d

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.

Wikunia avatar Jun 10 '16 09:06 Wikunia

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!

Anima-t3d avatar Jun 10 '16 12:06 Anima-t3d