Skip to content

add JS-snippet support using from: .module("/path/to/js-module.js") syntax#792

Open
sliemeobn wants to merge 5 commits into
swiftwasm:mainfrom
sliemeobn:feature/js-snippets
Open

add JS-snippet support using from: .module("/path/to/js-module.js") syntax#792
sliemeobn wants to merge 5 commits into
swiftwasm:mainfrom
sliemeobn:feature/js-snippets

Conversation

@sliemeobn

@sliemeobn sliemeobn commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

allow to ship JS code as the source for imports (in addition to ".global" and explicitly provided imports)

@JSFunction(from: .module("/Modules/JSImportModule.mjs"))
func moduleAdd(_ lhs: Int, _ rhs: Int) throws(JSException) -> Int

@JSFunction(jsName: "renamedFunction", from: .module("/Modules/JSImportModule.mjs"))
func moduleRenamed() throws(JSException) -> String

@JSGetter(jsName: "version", from: .module("/Modules/JSImportModule.mjs"))
var moduleVersion: String
// Modules/JSImportModule.mjs
export function moduleAdd(lhs, rhs) {
    return lhs + rhs;
}

export function renamedFunction() {
    return "renamed";
}

export const version = "1.0";

I noticed that currently there is no diagnostic when from: is used in places that do not support it, I did not add these checks (eg: class members, setters) to this PR more focussed. (#793)

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

Successfully merging this pull request may close these issues.

1 participant