Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support ES6 dynamic loading #1

Open
ELLIOTTCABLE opened this issue May 11, 2017 · 0 comments
Open

Support ES6 dynamic loading #1

ELLIOTTCABLE opened this issue May 11, 2017 · 0 comments

Comments

@ELLIOTTCABLE
Copy link
Owner

ELLIOTTCABLE commented May 11, 2017

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-async and a Loader to the current environment, something like:

Library('jxa-loader').shim(this)

  1. 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 … ↩︎

  2. … 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. ↩︎

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant