You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Both JXA scripts and “Script Libraries” are evaluated as ES6 Scripts; this means, despite the JavaScriptCore in macOS 10.12 “Sierra” being modern enough to support¹ES6 Modules, that there's no direct exposure of any method² to use them.
I'd like to write my JXA code as ES6 modules. There's obviously transpilers that will reduce ‘Module’ files (with export/import statements) to ‘script’ files (with require() calls) but I'd like to avoid this; what's needed, therefore, is a System.loader implementation that relies on the native tooling in JXA. I'm considering this as my next project.
Meanwhile, as jxa-async is presumably required for any such (obviously-asynchronous) Loader implementation, the jxa-async shim is presumably one of the very first modules I'd want to include in new JXA scripts. That, however, leaves a chicken-and-the-egg problem (can't have a Loader without asynchronicity; can't get asynchronicity using that Loader.)
There would have to be a combined shim that adds both jxa-asyncand a Loader to the current environment, something like:
… but the corresponding programmatic API (await import(), as a function), accessible from within JavaScript — specifically within JavaScript Scripts — to consume ES6 Modules, has not yet landed. ↩︎
The text was updated successfully, but these errors were encountered:
Both JXA scripts and “Script Libraries” are evaluated as ES6
Script
s; this means, despite the JavaScriptCore in macOS 10.12 “Sierra” being modern enough to support¹ ES6Module
s, that there's no direct exposure of any method² to use them.I'd like to write my JXA code as ES6 modules. There's obviously transpilers that will reduce ‘Module’ files (with export/import statements) to ‘script’ files (with
require()
calls) but I'd like to avoid this; what's needed, therefore, is aSystem.loader
implementation that relies on the native tooling in JXA. I'm considering this as my next project.Meanwhile, as
jxa-async
is presumably required for any such (obviously-asynchronous)Loader
implementation, thejxa-async
shim is presumably one of the very first modules I'd want to include in new JXA scripts. That, however, leaves a chicken-and-the-egg problem (can't have a Loader without asynchronicity; can't get asynchronicity using that Loader.)There would have to be a combined shim that adds both
jxa-async
and a Loader to the current environment, something like:Specifically, ES6 modules can be written and loaded in HTML with the declarative
<script type="module">
extension (see: Add <script type="module"> and module resolution/fetching/evaluation whatwg/html#443) as of Safari 10.1 … ↩︎… but the corresponding programmatic API (
await import()
, as a function), accessible from within JavaScript — specifically within JavaScriptScript
s — to consume ES6 Modules, has not yet landed. ↩︎The text was updated successfully, but these errors were encountered: