-
Notifications
You must be signed in to change notification settings - Fork 25
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
fix: react render config #45
Conversation
export * from "./react-studio-template-renderer"; | ||
export * from "./react-output-config"; | ||
|
||
export class ReactOutputManager extends FrameworkOutputManager<string> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code was duplicated across this file and packages/studio-ui-codegen-react/lib/react-output-manager.ts
.
1dc119d
to
66efa4c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a little bit of feedback! Looks very good overall though!
|
||
constructor(component: StudioComponent) { | ||
super(component, new ReactOutputManager()); | ||
constructor(component: StudioComponent, renderConfig: ReactRenderConfig) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you use protected renderConfig: ReactRenderConfig
, you won't need to cast this later on.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, will fix
@@ -88,11 +99,11 @@ export abstract class ReactStudioTemplateRenderer extends StudioTemplateRenderer | |||
|
|||
const result = printer.printNode(EmitHint.Unspecified, wrappedFunction, file); | |||
|
|||
const { script } = this.renderConfig as ReactRenderConfig; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See comment above about adding protected.
@@ -132,16 +143,33 @@ export abstract class ReactStudioTemplateRenderer extends StudioTemplateRenderer | |||
const result = printer.printNode(EmitHint.Unspecified, wrappedFunction, file); | |||
componentText += result; | |||
|
|||
console.log(componentText); | |||
const { script } = this.renderConfig as ReactRenderConfig; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See comment above about adding protected.
const file = createSourceFile( | ||
this.fileName, | ||
'', | ||
target as unknown as ScriptTarget, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we coerce this rather than cast to unknown?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was getting this error before. I'll look into it further to see if there is another fix.
Conversion of type 'TargetEnum | undefined' to type 'ScriptTarget' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first. Type 'TargetEnum.ES6' is not comparable to type 'ScriptTarget'.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried creating a subset of the TypeScript enum, but it seems the only way to do that is change it to a type union.
import { ScriptTarget } from 'typescript';
export type TargetEnum = Exclude<ScriptTarget, ScriptTarget.ES3>;
TargetEnum.ES6
// 'TargetEnum' only refers to a type, but is being used as a value here.
Another option would be to use the ScriptTarget
enum directly, but then a user could input any of the available option supported by TypeScript. https://github.com/microsoft/TypeScript/blob/9d443b76aac0832d7f3c890441264d39307fe31a/lib/protocol.d.ts#L2753-L2765
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We technically can support any ScriptTarget
, right? Maybe it would be best to do that. Otherwise, it might be good to create a helper function that maps the two.
'', | ||
target as unknown as ScriptTarget, | ||
false, | ||
script as unknown as ScriptKind, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we coerce this rather than cast to unknown?
b29c3d7
to
d9c7c39
Compare
d9c7c39
to
c83fa7a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
The major changes:
FrameworkRenderConfig
andReactRenderConfig
because we needed to pass these configurations into the renderer and not the output managertranspileModule
from typescript to set certain targets and modulestranspileModule
and keep typescript.transpileModule
to preserve the syntaxExample:
amplify component:
With config:
Will produce:
TODO in future change:
TS
script kind