Skip to content

Commit 4389a52

Browse files
committed
fix(complex-types): escape quotes in keys
1 parent c5b7629 commit 4389a52

File tree

4 files changed

+9
-1
lines changed

4 files changed

+9
-1
lines changed

packages/complex-types/src/core/printer.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,9 @@ export class Printer {
8989
const parts: string[] = [];
9090
for (const [propName, propData] of Object.entries(props)) {
9191
const questionMark = propData.isOptional ? "?" : "";
92-
parts.push(`"${propName}"${questionMark}: ${propData.value},`);
92+
parts.push(
93+
`"${escapeQuotes(propName)}"${questionMark}: ${propData.value},`,
94+
);
9395
}
9496

9597
return Object.keys(props).length > 0 ? `{\n${parts.join("\n")}\n}` : "";

packages/complex-types/test/__fixtures__/defineProps/basic.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ defineProps<
1919
// keepOrder2: number | string;
2020
error: Error;
2121
null: string | null;
22+
'quotes"': string;
2223
} & SomeInterface & {
2324
[MappedString in "1-1" | "1-2"]: `${MappedString}MappedType`;
2425
} & {

packages/complex-types/test/__snapshots__/fixtures-compiled.test.ts.snap

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,10 @@ var _sfc_main = /* @__PURE__ */ defineComponent({
131131
required: true
132132
},
133133
null: { required: true },
134+
"quotes\\"": {
135+
type: String,
136+
required: true
137+
},
134138
emptyInterface: {
135139
type: Object,
136140
required: true

packages/complex-types/test/__snapshots__/fixtures.test.ts.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ defineProps<
5353
"function": Function,
5454
"error": object,
5555
"null": null | string,
56+
"quotes\\"": string,
5657
} & {
5758
"emptyInterface": object,
5859
"conditionalNumber": number,

0 commit comments

Comments
 (0)