-
Notifications
You must be signed in to change notification settings - Fork 9
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
constructor parameters with @ sometime not recognized #5
Comments
The example code you gave me gives no error. But I think I found your specific problem anyway: You most likely have another variable in the same scope, also called export class ClassTest
constructor: (@option)->
option = 123 The official CoffeeScript compiler translates this into var option;
export var ClassTest = class ClassTest {
constructor(option1) {
this.option = option1;
}
};
option = 123; Notice the export class ClassTest
constructor: (@option)->
option = 123 export var ClassTest = (function() {
var option;
class ClassTest {
constructor(option1) {
this.option = option1;
}
};
option = 123;
return ClassTest;
}).call(this); In this case, if it weren't So, to solve this issue, the CS compiler needs to look for usage the variable in the constructor itself, not the surrounding code. Until now, this was not a problem because who cares what the invisible variable is called. But with JSDoc, it is... I'll create a issue in a sec It's a bit of an edge case, really. Besides removing the conflicting var from the same scope, there's at least two ways to workaround it: class ClassTest
###*
* @param {object} option
###
constructor: (option)->
@option = option class ClassTest
constructor: (###* @type {object} option ###)-> In future, with Coffee-Type-Script (there's no name yet), the best way will be class ClassTest
constructor: (@option ~ object) -> but only if you will want to use TS anyway, so a solution to the JSDoc problem is desirable. |
You could also change your Also, this |
You are right, there is an option outside the scope of the class, but not as you assumed : the complete sample.coffee to reconstruct the problem: outSideMethod = (s) ->
option = s
export class ClassTest
###*
* @constructor
* @param {object} option
* @param {Function} callMe
* @param {string} name
###
constructor: (@option,@callMe, name)->
a = 2
and here the output of the compiler: var outSideMethod;
outSideMethod = function(s) {
var option;
return option = s;
};
export var ClassTest = class ClassTest {
/**
* @constructor
* @param {object} option
* @param {Function} callMe
* @param {string} name
*/
constructor(option1, callMe, name) {
var a;
this.option = option1;
this.callMe = callMe;
a = 2;
}
}; and here the output of coffeesense
|
yeah that's even worse. there is an issue about this already: jashkenas/coffeescript#4865
|
Maybe it would be a good idea to collect all those things and add it to the documentation of coffeesense ? |
until now, these were shown at the *start* of the file with the note `The position of this error could not be mapped back to CoffeeScript, sorry. Here's the failing JavaScript context: ...` I now moved the location to the next available follow up code line where there is any source map info available which is much more helpful ref #5
I had added it to the readme last year. other than that, as there's nothing to do from an extension standpoint, I'll close this |
When prefixing constructor arguments with @
like
Coffeesense complains:
However changing the param name from option to options (in code and jsdoc) let the message disappear for the moment, but it pops up later again complaining about the new names
The text was updated successfully, but these errors were encountered: