I’m trying to use H5 to convert C# code into JS and then use the result in an Angular project, but I’m having trouble importing the generated JS module.
I wrote a simple C# class like this:
namespace TW3.Shared {
public class Class1 {
public int Sum(int x, int y) {
return x + y;
}
}
}
…and using the following h5.json
configuration file:
{
"module": {
"type": "ES6",
"name": "XXX"
},
"generateTypeScript": true
}
…I got these 2 files:
// SharedJS.js
/**
* @compiler H5 24.2.45744+d8342060ba1fec4b36b7d0c2865c74ad945e2889
*/
H5.assemblyVersion("SharedJS","1.0.0.0");
H5.assembly("SharedJS", function ($asm, globals) {
"use strict";
(function () {
var XXX = { };
H5.define("TW3.Shared.Class1", {
$metadata : function () { return {"att":1048577,"a":2,"m":[{"a":2,"isSynthetic":true,"n":".ctor","t":1,"sn":"ctor"},{"a":2,"n":"Sum","t":8,"pi":[{"n":"x","pt":System.Int32,"ps":0},{"n":"y","pt":System.Int32,"ps":1}],"sn":"Sum","rt":System.Int32,"p":[System.Int32,System.Int32],"box":function ($v) { return H5.box($v, System.Int32);}}]}; },
$scope: XXX,
$module: "XXX",
methods: {
Sum: function (x, y) {
return ((x + y) | 0);
}
}
});
export {XXX};
}) ();
});
// SharedJS.d.ts
namespace TW3.Shared {
interface Class1 {
Sum(x: number, y: number): number;
}
interface Class1Func extends Function {
prototype: Class1;
new (): Class1;
}
var Class1: Class1Func;
}
So, what do I need to do in order to call Class1.Sum()
inside Angular?
I tried adding the generated .js and .ts files to angular.json
:
"scripts": [
"src/assets/js/SharedJS/h5.js",
"src/assets/js/SharedJS/h5.meta.js",
"src/assets/js/SharedJS/SharedJS.js",
"src/assets/js/SharedJS/SharedJS.meta.js",
"src/assets/js/SharedJS/SharedJS.d.ts"
]
but if I do that, then I get an error when I try to build the angular project:
X [ERROR] Unexpected "export"
angular:script/global:scripts.js:51675:8:
51675 │ export {XXX};
╵ ~~~~~~