Path: csiph.com!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail From: Anton Shepelev Newsgroups: comp.lang.javascript Subject: Re: Exposing a module in the current scope Date: Sat, 20 Mar 2021 13:51:50 +0300 Organization: A noiseless patient Spider Lines: 87 Message-ID: <20210320135150.9172df52c3ad3891bcb2299b@gmail.com> References: <20210318192107.08e2fac2d6aeada5596c4dd0@freeshell.de> <7921cdf5-084a-4011-9a0e-680e0b45c442n@googlegroups.com> <20210318235703.ea4798e2fc9d01b5194a34ca@gmail.com> <5a31706e-e012-47ea-b047-867d6da83212n@googlegroups.com> <20210319181117.c09ff1a07699679434f6310e@g{oogle}mail.com> <9dd35db1-fee3-4142-bf30-24e8da7bdc98n@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Injection-Info: reader02.eternal-september.org; posting-host="0b6de666454792515201e0a3034742c6"; logging-data="26877"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+HNODZi3ggg8FKbeqTtwUGIWIO3cIohBU=" Cancel-Lock: sha1:XmQSxVbmzzZuYo7cY3ebge1jkb4= X-Newsreader: Sylpheed 3.7.0 (GTK+ 2.24.30; i686-pc-mingw32) Xref: csiph.com comp.lang.javascript:39715 Michael Haufe to Anton Shepelev: > > Why are you writing in Markdown? > > To make clear what is code and what is a comment about the > code I see. Most of the time it seems sufficient simply to write the code down after a vertical space. When doubt is possible, I will also indent the code block on the left. > More than JavaScript is used in this group in discussions. > There is also TypeScript, ActionScript, and others. One can also indicate the language in the prose. > The above I find more straightforward than what used to be > common: The above I find more straightforward than what > used to be common: > > > > > Did anybody in this newsgroup use to post pieces of JavaScript code inside HTML tags? That was terrible, indeed. They must have been confusing Usenet articles that discuss the code and actual web pages that use it. > > As I wrote, it does recognise the `import' statement, > > but fails with: > > > > import declarations may only appear at top level of a module > > > > presumably because it cannot treat .xsjs files as > > modules. > > Which makes sense as they mention the *.xjslib extension. That extenstion is reserved for libraries, whereas the actual server-side applications must be .xsjs, and I can't seem to use the `import' statement in .xsjs because of the error quoted above. If I rename the main file to .mjs, the error goes away, but HANA XS no longer "serves" them, considering them as data files rather than JavaScript sources to be executed. That is very strage and illogical. > Since you verified that it's newer than ES5 you can't > ignore my suggestion. The modern module approach is more > appropriate. I do not ignore them. I just can't follow them :-) > Since you confirmed that at least some ES6 features are > available, you can ignore my example and try something > more modern: > > ``` > function log(msg) { $.trace.debug(msg); }; > > export default log > ``` > > or for multiple exports: > > ``` > function log(msg) { ... }; > function hello(msg){ ... }; > > export {hello, log} > ``` I will try it on Monday, but I think it will complain again that `export' can only occur at the top level of a module, because in its self-contradictory opinion a file is not a module unless has one of the unsupported extensions .js or .mjs. I will let you know. -- () ascii ribbon campaign -- against html e-mail /\ http://preview.tinyurl.com/qcy6mjc [archived]