Skip to content

Commit d9660b3

Browse files
authored
Refactor property name handling in emitWebIdl function to support hyphenated names (#2049)
* Refactor property name handling in emitWebIdl function to support hyphenated names * Update emitter.ts
1 parent 99c5952 commit d9660b3

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/build/emitter.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -880,11 +880,14 @@ export function emitWebIdl(
880880
if (p.optional) {
881881
pType += " | undefined";
882882
}
883+
const propertyName = p.name.includes("-") ? `"${p.name}"` : p.name;
883884
const optionalModifier = !p.optional || prefix ? "" : "?";
884885
const canPutForward =
885886
compilerBehavior.allowUnrelatedSetterType || !p.readonly;
886887
if (!prefix && canPutForward && p.putForwards) {
887-
printer.printLine(`get ${p.name}${optionalModifier}(): ${pType};`);
888+
printer.printLine(
889+
`get ${propertyName}${optionalModifier}(): ${pType};`,
890+
);
888891

889892
const forwardingProperty = getPropertyFromInterface(
890893
allInterfacesMap[pType],
@@ -898,12 +901,12 @@ export function emitWebIdl(
898901
setterType += ` | ${pType}`;
899902
}
900903
printer.printLine(
901-
`set ${p.name}${optionalModifier}(${p.putForwards}: ${setterType});`,
904+
`set ${propertyName}${optionalModifier}(${p.putForwards}: ${setterType});`,
902905
);
903906
} else {
904907
const readOnlyModifier = p.readonly && prefix === "" ? "readonly " : "";
905908
printer.printLine(
906-
`${prefix}${readOnlyModifier}${p.name}${optionalModifier}: ${pType};`,
909+
`${prefix}${readOnlyModifier}${propertyName}${optionalModifier}: ${pType};`,
907910
);
908911
}
909912
}

0 commit comments

Comments
 (0)