-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Typescript support #162
Typescript support #162
Conversation
arguments and return type.
I am glancing at the PR, and I wonder about a possible improvement in the output:
Here there are placeholder names for the arguments, but in theory we could get the llvm argument names if present, and use those. Here there is an extra 'L' in front that stands for "local", but for typescript we could just sanitize keywords and invalid characters. |
another thing, to help with the review: Try to refactor the commits so that commits that fix something you wrote earlier in the PR disappear (Example: 9f245fc). And put at the beginning commits that don't add functional changes. Example: the last commit 787fceb could be at the beginning, so all the other commits can just use those types from the start. |
Actually about my first comment: it might be that those nice names are only available in debug builds of llvm. In that case, it woudl be useless. |
Thanks for the tips, I will definitely keep this in mind going forward.
Yes, you're right, I didn't notice them in the output before because I was compiling to wasm. The reason we don't have true argument names for the constructor is because that declaration is not for the actual constructor, it's for the "new helper", which looks like this: function __ZN4Rect3newEii(Larg0,Larg1){
var tmp0=null;
tmp0={i0:0,i1:0};
__ZN4RectC1Eii(tmp0,Larg0,Larg1);
return tmp0;
} I do believe the true names are available for the actual constructor even in release builds, and special logic could be implemented to use those names instead when generating the declaration for the new helper. |
Also, good note on sanitizing variable names, it had not occurred to me that those might conflict with typescript keywords. |
While looking into how to obtain the constructor from a The new helper in javascript now looks like this: function __ZN4Rect3newEii(Lwidth,Lheight){
var tmp0=null;
tmp0={i0:0,i1:0};
__ZN4RectC1Eii(tmp0,Lwidth,Lheight);
return tmp0;
} And its typescript declaration looks like this: Rect: {
new(width: number, height: number): Rect;
}; |
Unsure, there is certainly no guarantee that they have any specific value |
Merged |
This PR implements the automatic generation of typescript declaration files for jsexported code.
Also moved the
MODULE_TYPE
enum from a private inner type ofCheerpWriter
into Utility.h because it is also required byCheerpDTSWriter
.New flags:
-cheerp-make-dts
-cheerp-dts-output-file=<file>
Example: