Skip to content

Commit

Permalink
fix: ensuring we properly escape object keys with non-alpha characters
Browse files Browse the repository at this point in the history
  • Loading branch information
alharris-at committed Oct 29, 2021
1 parent 19f3182 commit 5216eca
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -714,7 +714,7 @@ import {
} from \\"@aws-amplify/ui-react\\";
export type CustomButtonProps = Partial<ButtonProps> & {
variant: \\"primary\\" | \\"secondary\\";
variant?: \\"primary\\" | \\"secondary\\";
size?: \\"large\\";
} & {
overrides?: EscapeHatchProps | undefined | null;
Expand All @@ -730,7 +730,10 @@ export default function CustomButton(
},
{
variantValues: { variant: \\"secondary\\" },
overrides: { Button: { fontSize: \\"40px\\" } },
overrides: {
Button: { fontSize: \\"40px\\" },
\\"Button.Text\\": { fontSize: \\"40px\\" },
},
},
{
variantValues: { variant: \\"primary\\", size: \\"large\\" },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
"overrides": {
"Button": {
"fontSize": "40px"
},
"Button.Text": {
"fontSize": "40px"
}
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ export function jsonToLiteral(
// else object
return factory.createObjectLiteralExpression(
Object.entries(jsonObject).map(([key, value]) =>
factory.createPropertyAssignment(factory.createIdentifier(key), jsonToLiteral(value)),
factory.createPropertyAssignment(factory.createStringLiteral(key), jsonToLiteral(value)),
),
false,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ export abstract class ReactStudioTemplateRenderer extends StudioTemplateRenderer
* required and optional parameters, then building the appropriate property signature based on that.
* e.g.
{
variant: "primary" | "secondary",
variant?: "primary" | "secondary",
size?: "large",
}
*/
Expand Down Expand Up @@ -356,7 +356,7 @@ export abstract class ReactStudioTemplateRenderer extends StudioTemplateRenderer
return factory.createPropertySignature(
undefined,
factory.createIdentifier(key),
undefined,
factory.createToken(ts.SyntaxKind.QuestionToken),
factory.createUnionTypeNode(valueTypeNodes),
);
});
Expand Down
20 changes: 8 additions & 12 deletions packages/test-generator/lib/components/componentWithVariant.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
"id": "1234-5678-9010",
"componentType": "Button",
"name": "ComponentWithVariant",
"properties": {},
"properties": {
"children": {
"value": "ComponentWithVariant"
}
},
"variants": [
{
"variantValues": {
Expand All @@ -11,6 +15,9 @@
"overrides": {
"Button": {
"fontSize": "12px"
},
"Button.Text": {
"fontSize": "12px"
}
}
},
Expand All @@ -35,16 +42,5 @@
}
}
}
],
"children": [
{
"componentType": "String",
"name": "String",
"properties": {
"value": {
"value": "ComponentWithVariant"
}
}
}
]
}

0 comments on commit 5216eca

Please sign in to comment.