Skip to content

Commit cbb5daa

Browse files
committed
fix(ts-interface-generator): fix usage of quoted property etc. names
1 parent 65c4604 commit cbb5daa

File tree

1 file changed

+6
-15
lines changed

1 file changed

+6
-15
lines changed

packages/ts-interface-generator/src/interfaceGenerationHelper.ts

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -540,8 +540,9 @@ function getMemberFromPropertyAssignment<T extends MetadataSectionName>(
540540
memberKind: T
541541
): TypeForMetadataSectionName[T] {
542542
// the name
543+
const memberName = propertyAssignment.name.getText().replace(/['"]/g, "");
543544
const member: APIMember = {
544-
name: propertyAssignment.name.getText(),
545+
name: memberName,
545546
};
546547

547548
// the definition object - for the sake of parsing simplicity, let's parse the code as a JSON object
@@ -613,7 +614,9 @@ function generateInterface(
613614
if (!ts.isPropertyAssignment(propertyAssignment)) {
614615
return; // huh, not a property assignment? => does not look like something we are interested in
615616
}
616-
const memberKind = propertyAssignment.name.getText() as MetadataSectionName;
617+
const memberKind = propertyAssignment.name
618+
.getText()
619+
.replace(/['"]/g, "") as MetadataSectionName;
617620
if (
618621
!["properties", "aggregations", "associations", "events"].includes(
619622
memberKind
@@ -632,7 +635,7 @@ function generateInterface(
632635
innerObjectLiteralExpression.properties
633636
.filter((prop) => ts.isPropertyAssignment(prop))
634637
.forEach((prop) => {
635-
const name = prop.name.getText();
638+
const name = prop.name.getText().replace(/['"]/g, "");
636639
metadataObject[memberKind][name] = getMemberFromPropertyAssignment(
637640
prop as ts.PropertyAssignment,
638641
memberKind
@@ -649,18 +652,6 @@ function generateInterface(
649652
}
650653
});
651654

652-
try {
653-
// @ts-ignore Hjson.rt.* is needed for the comments, but only exists in version 3. But the types are only available for version 2.
654-
// TODO: remove! Only for debugging later stages; simple JSON parsing to be replaced with real TS parsing
655-
//metadataObject = Hjson.rt.parse(metadata[0].initializer.getFullText()) as ClassInfo; // parse with some fault tolerance: it's not a real JSON object, but JS code which may contain comments and property names which are not enclosed in double quotes
656-
} catch (e) {
657-
throw new Error(
658-
`When parsing the metadata of ${className} in ${fileName}: metadata is no valid JSON and could not be quick-fixed to be. Please make the metadata at least close to valid JSON. In particular, TypeScript type annotations cannot be used. Error: ${
659-
(e as Error).message
660-
}`
661-
);
662-
}
663-
664655
if (
665656
!metadataObject.properties &&
666657
!metadataObject.aggregations &&

0 commit comments

Comments
 (0)