andyli / jQueryExternForHaxe

Unleash the full power of jQuery in Haxe.
http://lib.haxe.org/p/jQueryExtern
65 stars 12 forks source link

Macro for jQuery Plugins doesn't work when having more than 1 plugin #20

Open mmauri opened 6 years ago

mmauri commented 6 years ago

Andy, When you have to import more than 1 Jquery plugin in the hxml file, it fails: (with only 1 plugin it works)

-lib jQueryExtern -cp src -js bin/DataTables.js -main Main --macro js.jquery.Config.addPlugin('externs.DataTable') --macro js.jquery.Config.addPlugin('externs.Semantic')

It throws this compile error: src/externs/Semantic.hx:4: lines 4-30 : JQuery class is already built before inserting plugin. Most likely due to missing compiler option: --macro js.jquery.Config.addPlugin('externs.Semantic') The terminal process terminated with exit code: 1

Sample project: https://github.com/mmauri/DataTablesSample/

Thanks for your help!

andyli commented 6 years ago

The problem is the import js.jquery.JQuery; statements in the extern modules. One extern module importing JQuery forces the compiler to build JQuery, so the other extern can no longer inject fields into JQuery.

The solution is simply to remove the import statements. You can still use JQuery (no need to use js.jquery.JQuery) in the extern body, because the extern fields are only typed after they are "pasted" into the JQuery class. Since JQuery is in js.jquery, you can reference any types in js.jquery without using fully-qualified names.

In fact, currently import statements are not supported in the plugin extern modules... I will have to think about how to support that. At the moment, please use fully-qualified names for any other types not existed in top-level or js.jquery.

Let me know if you can make the plugins work.

mmauri commented 6 years ago

Thank you very much Andy, I will remove the imports. This should be a common issue, that maybe have to be in the README file....

Thanks again for your help! Marc

mmauri commented 6 years ago

Oops! just saw you already did it.

Thanks