-
-
Notifications
You must be signed in to change notification settings - Fork 669
Implement transform classes #892
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
Conversation
This now supports transforms written in TS without the need to build them. Haven't tested in detail, but the example works. |
The reason for building the typescript file was to bundle the transformer. This way you only need to provide one file. Also in situations like the browser it means a required ts-node/typescript dependency. |
For browser you should write on pure JS or transpile to JS from TS offline as usual. Current solution support ts-node optionally. |
typescript allow output to single bundle since 1.8. You don't need webpack for this. |
Ah cool! But still my point is that you if want to develop offline you need the proper types and that's been the headache for me. |
Last time I checked Not sure about the types issue you are describing, but if you for example need |
Okay thanks for the info. I was able to get everything to work with webpack, but tsc is still mad that there are two definitions for primitives, one in |
I think the portable definitions shouldn't be included there since transforms are TS, not portable AS. Does this come from your tsconfig? If so, try to make it a normal TS project. |
I did, but |
So I guess ideally we'd inline these in the .d.ts, essentially replacing their occurrences with |
If we can always expect that there will be global definitions for the primitives, why can't we just remove it? Wouldn't you always want to have portable or assembly types in your types path? |
Not necessarily. There are the following cases to consider:
with 3. and 4. being problematic apparently. However, 2. is a valid case as well in which case the |
Last commit does that now, that is replace all occurrences of |
Cool that works on my end. Thanks! |
Great, let me know if there's something else necessary here, or if it's good to merge. |
My one last suggestion is to add a |
Alright, added an It's important to use the exact Binaryen dependency used by asc for this because wrapping like this requires that all the data is in Binaryen's memory already. |
Thanks! Why must the module be rewrapped? I thought that the one passed was already wrapped by the compiler's module class. |
It is not ultimately necessary to do that, but I'd imagine that the binaryen.js API is more friendly to consume than the internal C-API wrapper. If the internal API is good enough, one can ofc use that instead. Just note that extending the internal |
Ah cool well then it LGTM! |
Oh one last thing, can there be a try catch surrounding the each call to the transform class? |
I guess better if try/catch will be inside |
Yeah but since the current style is to call the callback with the error, it would be good if the transforms can use the callback to check if their error occurred. |
May be better have a possibility interrupt next process and gracefully shutdown compiler like: class MyTransform extends Transform {
afterParse(parser: Parser): boolean {
try {
....
return true // ok
} catch (e) {
// handle error
return false // interrupt and skip next transforms
}
} ...
function applyTransform(name, ...args) {
var result = transforms.every(transform => {
if (typeof transform[name] === "function") {
return transform[name](...args));
}
return true;
});
if (!result) throw new Error(...); // or pass this to return or better shutdown compiler
}
... |
What this now does it to abort compilation on the first transform throwing, and propagates the error to the callback function. In case of the default callback, the exit code will be 1. That sufficient? |
Merging so we can generate an updated assemblyscript.d.ts along with the recent Binaryen update. If there's anything else, you know what to do :) |
Thanks! |
This PR explores an alternative to #866. This is backwards-compatible to transform modules but now also supports classes that are populated with additional utility. On top of that this utilizes ts-node to run transforms written in TS without the need to build them.