leaningtech/cheerp-meta

[Feature request] -cheerp-make-module=typescript or ES6

sdykae opened this issue · 1 comments

ES6 modules?
import { add } from "./file.js";
import { add } from "./file.ts"; (with tipes :(?)

Hi @sdykae, ES6 support was on our wish-list and it was recently merged into Cheerp.

An explanation of the feature is here: https://leaningtech.github.io/cheerp-meta/pages/ES6-Modules.

ES6 modules generated by Cheerp will have as default export an initializing function: example.

Basic syntax:

import instantiate from './add.js'

var module = await instantiate();
var add = module.add;
console.log(add(23, 23));

The syntax you suggest is available by composing the original module with a wrapper module: complete example on GitHub's Gist

Composed syntax:

import instantiate from './add.js'

var module = await instantiate();
var add = module.add;

export {add};

then

import {add} from "./wrap_add.js"

console.log(add(23, 19));