Skip to content

Commit 4a24f25

Browse files
authored
fix(dts-generator): handle enum values properly which are quoted strings (#504)
Happens when name===value and name contains special characters
1 parent c270bf5 commit 4a24f25

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

packages/dts-generator/src/phases/dts-code-gen.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -742,7 +742,11 @@ function genEnumValue(ast: Variable, withValue = false) {
742742
let text = "";
743743
text += JSDOC(ast) + NL;
744744
if (withValue) {
745-
text += `${ast.name} = "${(ast as VariableWithValue).value}",`; // TODO string escaping
745+
let astVal = (ast as VariableWithValue).value;
746+
if (typeof astVal !== "string" || !astVal.match(/^".*"$/)) {
747+
astVal = `"${astVal}"`; // TODO string escaping
748+
}
749+
text += `${ast.name} = ${astVal},`;
746750
} else {
747751
text += `${ast.name},`;
748752
}

0 commit comments

Comments
 (0)