Open Mrxyy opened 1 year ago
What bundler are you using?
What bundler are you using?
webpack5
I suppose the solution is to use Object.defineProperties()
instead of Object.assign()
I suppose the solution is to use
Object.defineProperties()
instead ofObject.assign()
Yes, the above code is just to ensure that the current compiled results work.
Same problem. Generated binding to esm:
const __module0 = imports["./main.js"];
const adaptedImports = {
"./main.js": Object.assign(Object.create(__module0), {
myFunc(x) {
// assembly/index/my_func(i32) => bool
return __module0.myFunc(x) ? 1 : 0;
},
}),
};
In Chrome and Vivaldi works fine. if Firefox throw:
Uncaught TypeError: "myFunc" is read-only
If I edit manually to
const __module0 = imports["./main.js"];
const adaptedImports = {
"./main.js": Object.assign({
myFunc(x) {
// assembly/index/my_func(i32) => bool
return __module0.myFunc(x) ? 1 : 0;
},
}),
};
or to
const __module0 = imports["./main.js"];
const adaptedImports = {
"./main.js": Object.create(__module0),
};
it works. Also works when calling func via globalThis in env.ts:
// env
@external("env", "myFunc")
export declare function my_func(x: f32): boolean
main.ts:
// ./main.js
globalThis.myFunc = (x: number): boolean => {
console.info('main.js myFunc()');
return true;
}
But manual edits or calls through a global object are unnecessary work.
Bug description
Compiling esm code cannot be used directly in the bundler module,.e.g:
The Object.assign cant work. Because bundle module is not the same as browser esm.module export variable just only have getter.
Steps to reproduce
@external("../test","test")
AssemblyScript version
^0.27.0