tern icon indicating copy to clipboard operation
tern copied to clipboard

Undefined "$(fn)" method in JQuery module.

Open krkhnh opened this issue 7 years ago • 15 comments

Since "$(fn)" is undefined by JQuery module, validation modules like Lint keep showing error like this.

[Lint]: Invalid argument at 1: cannot convert from Function.prototype to string|Node|Array

"$(function() {})" is marked as an error. While equivelent "$(document).ready(function() {})" is fine.

krkhnh avatar Dec 07 '17 08:12 krkhnh

What tool are you used for lint?

othree avatar Jul 05 '18 07:07 othree

I'm using Spring Tool Suite(3.9.4.RELEASE) with Tern Eclipse IDE(1.2.0.2016061608) from Eclipse Marketplace. I tried "Lint" Validator. Results look like this:

image

krkhnh avatar Jul 06 '18 05:07 krkhnh

Do you use this def: https://github.com/ternjs/tern/blob/master/defs/jquery.json The message seems not match the def.

othree avatar Jul 09 '18 15:07 othree

Can you try https://gist.github.com/othree/27cf283cf8b66f0f9cf9ca69fc0aeb46

othree avatar Jul 09 '18 15:07 othree

I added tern-def-jquery.json in "\plugins\ternjs_1.2.0.201606160856\node_modules\tern\defs" from IDE folder and used it without other original JQuery modules. But same results. This is the original jquery.json from the plugin: jquery.zip

I just found out that if I uncheck all jQuery related modules, the errors changed like this. image

krkhnh avatar Jul 10 '18 01:07 krkhnh

The def is a little bit out of date. Ok, I can confirm error at line 74 and 80 matches the def. Still not sure error at line 79.

Did you try the one I provided above. Line 14 is different.

othree avatar Jul 10 '18 02:07 othree

Yes. I replaced everything in jquery.json.

krkhnh avatar Jul 10 '18 02:07 krkhnh

How about change line 14 to

    "!type": "fn(selector: ?, context?: frameElement) -> jQuery.fn",

And restart IDE to make sure the Tern server restarted

othree avatar Jul 10 '18 02:07 othree

It partially worked.

image

Sorry for changing lines. I'll try to keep it from now on.

krkhnh avatar Jul 10 '18 02:07 krkhnh

Can you try this one: https://github.com/othree/tern/blob/jquery-def/defs/jquery.json

If everything works fine. I will merge back to here. But you will need to wait releases for both Tern and Tern Eclipse IDE(for upgrade Tern version).

othree avatar Jul 10 '18 03:07 othree

It worked! No error.

krkhnh avatar Jul 10 '18 04:07 krkhnh

Can you help me test one more sample code? (Sorry I didn't get the environment ready)


$('div').click({data: 1}, function (event) {
  event;
});

I hope this code sample could have no errors and event have correct auto complete candidate.

Thanks

othree avatar Jul 10 '18 06:07 othree

I pasted your code below the original code. No error. But... I just noticed that after I changed JSON, there was no auto-completes too. In fact, there is no error whatsoever; even with wrong syntax.

krkhnh avatar Jul 10 '18 07:07 krkhnh

I have updated it and it should work now. https://github.com/othree/tern/blob/jquery-def/defs/jquery.json But there is still some issue I need to fix before I can merge back.

The problem is that jQuery.click (and similar methods) use something like polymorphism. The first parameter can be an event handler or data. Which is not good for TernJS.

othree avatar Jul 10 '18 08:07 othree

It works. Auto-completes works too. Thank you.

image

krkhnh avatar Jul 11 '18 00:07 krkhnh