Reputation: 2075
Using JavaScriptCore, I would like to integrate part of a modern Javascript codebase into a Swift 5.x program for ios/ipados 13. The JS code uses ES6+ features extensively. For example: async/await
, static imports (import * as something from “something.js”
), and dynamic imports (`await loadedModule = import(“something.js”);
Based on this post from 2018, it seems as though import statements weren’t implemented properly at that point: How to import modules in Swift's JavaScriptCore?
(I don’t think that it’s appropriate to resurrect that post since at this point a lot has changed.)
Since that time, has JavaScriptCore integrated these features? From my understanding, if they work in the Safari browser, then they should also work in standalone JavaScriptCore (or is that wrong to assume)? I don’t think it would be practical to use babel or webpack to convert my code.
If it’s possible, how do I load this sort of JavaScript from Swift?
EDIT:
I still get
JS Exception: SyntaxError: Unexpected token '*'. import call expects exactly one argument.
when I try the following:
import * as mod from "./mod.js";
Upvotes: 2
Views: 1316
Reputation: 2075
The answer is "no," but I can use Babel to transpile files with static imports / exports into code containing require
s, and also implement my own version of require
in Swift to simulate what I want.
Upvotes: 1