-
-
Notifications
You must be signed in to change notification settings - Fork 1k
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
updates typescript renderer to have babel 7 compliant output #1192
Conversation
Will this change break existing code if its types are generated with @colinking Any opinions about this wrt Typewriter? |
@schani we don't emit any JSON conversion logic in our JS clients, so this shouldn't affect us! Thanks for the heads up |
@schani looks like the build fails because (my guess) is that there's an output miss match. Is there a place I need to go to update the output to get the tests to pass? Although I can't explain why the |
No, you're emitting incorrect code for Flow:
|
@schani got the languages to build correctly. Any guidance on how to update the diff? I tried searching around the test suite and couldn't find any information. |
There's nothing that can be done about the diff signaling a build failure - Buildkite doesn't support an intermediate "Warning" level for builds. It just means there's a diff we have to look at before we merge. In this case it looks like the change introduces weird changes in the output. Boilerplate code is added to all files, it seems. Here's the diff: |
Ah. I see. That's actually expected. If you look at a subset of the output currently: export namespace Convert {
export function toCoordinate(json: string): Coordinate {
return cast(JSON.parse(json), r("Coordinate"));
}
export function coordinateToJson(value: Coordinate): string {
return JSON.stringify(uncast(value, r("Coordinate")), null, 2);
}
function invalidValue(typ: any, val: any): never {
throw Error(`Invalid value ${JSON.stringify(val)} for type ${JSON.stringify(typ)}`);
}
function jsonToJSProps(typ: any): any {
if (typ.jsonToJS === undefined) {
var map: any = {};
typ.props.forEach((p: any) => map[p.json] = { key: p.js, typ: p.typ });
typ.jsonToJS = map;
}
return typ.jsonToJS;
}
//additional fields...
}
I wanted to make sure those addition functions didn't get exported with the class so I moved them outside of the classes' definition. Only the class and public methods are exported and the rest remain in the module. This means we have to dedent all of that output so that's why the diff is so huge. export class Convert {
public static toCoordinate(json: string): Coordinate {
return cast(JSON.parse(json), r("Coordinate"));
}
public static coordinateToJson(value: Coordinate): string {
return JSON.stringify(uncast(value, r("Coordinate")), null, 2);
}
}
// none of these functions are exported. They remain private to the module
// however, they get dedented so that's why the diff is so large
function invalidValue(typ: any, val: any): never {
throw Error(`Invalid value ${JSON.stringify(val)} for type ${JSON.stringify(typ)}`);
}
function jsonToJSProps(typ: any): any {
if (typ.jsonToJS === undefined) {
var map: any = {};
typ.props.forEach((p: any) => map[p.json] = { key: p.js, typ: p.typ });
typ.jsonToJS = map;
}
return typ.jsonToJS;
}
//additional fields... |
Yes, but that's not the issue. The issue is that that boilerplate code is added where it wasn't present before. Just look at the first file in that diff. There are no deletions, only additions. |
Yeah. There definitely shouldn't be additions without the deletions. I'm trying to repro this locally. I'm running the cli in my fork of the repo and comparing the outputs.
running |
This is extremely odd. I don't understand what's going on there. It seems like the output we have from |
updates typescript renderer to have babel 7 compliant output
Background
The current output is not Babel 7 compliant.
#1189
Changes
Pull the
_jsOptions.runtimeCheck
output into a helper method. This is needed to decouple the output from the actual convert functions.Converts the
namespace
block in the TS renderer to a class and updates the convert methods to be static methods. I think I like this better thanconst
actually. It's also slightly simpler because of the commas needed when defining methods on an object literal.Below is a screen shot of a sample output: