[Pas2js] Javascript import and export

Michael Van Canneyt michael at freepascal.org
Mon Jul 5 09:19:59 CEST 2021



On Mon, 5 Jul 2021, Ng Pheng Siong wrote:

> On Mon, Jul 05, 2021 at 05:44:22AM +0200, Michael Van Canneyt wrote:
>> The plan is to translate the existing $linklib directive, like this one:
>> 
>> {$linklib atom}
>> 
>> to an import/require statement that will be prepended to the javascript file.
>> There will be statements in the JS or system unit which will allow you
>> retrieve the imported objects.
>> 
>> I will try to document in the WIKI what has been discussed, there is more
>> than what I wrote here.
>
> Sounds good!
>
>> But if you want to use import statements already today, this is easily done.
>> simply look at the demos for VSCode and Atom plugins. They just require a
>> small js file which is prepended/appended to the compiler
>> output, look for the packageglue.js file, which is appended with -Ja or
>> prepended with -Ji.
>
> And using -Ji for the import statements work!

Yes, it does :-)

>
>> I have published the article I wrote about this technique for Blaise Pascal
>> magazine. See here:
>> https://www.freepascal.org/~michael/articles/index.html#atomvscode
>
> The approach is well explained. Thanks for the hint. I look forward to
> sharing how far I can go with pas2js and NativeScript.

I worked on a (Java) project using react native. It was a pain....

So I look forward to hearing from you how you did it, and will be glad to 
share it with the world with a new article :-)

Michael.


More information about the Pas2js mailing list