@kubb/plugin-ts 5.0.1 → 5.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +9 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +17 -17
- package/dist/index.js +9 -5
- package/dist/index.js.map +1 -1
- package/package.json +8 -4
package/dist/index.cjs
CHANGED
|
@@ -665,8 +665,10 @@ function createEnumDeclaration({ type = "enum", name, typeName, enums, enumKeyCa
|
|
|
665
665
|
}).filter((node) => node !== void 0)))];
|
|
666
666
|
if (type === "enum" || type === "constEnum") return [void 0, factory.createEnumDeclaration([factory.createToken(typescript.default.SyntaxKind.ExportKeyword), type === "constEnum" ? factory.createToken(typescript.default.SyntaxKind.ConstKeyword) : void 0].filter((modifier) => modifier !== void 0), factory.createIdentifier(typeName), enums.map(([key, value, description]) => {
|
|
667
667
|
let initializer = factory.createStringLiteral(value?.toString());
|
|
668
|
-
if (Number.parseInt(value.toString(), 10) === value && isNumber(value))
|
|
669
|
-
|
|
668
|
+
if (Number.parseInt(value.toString(), 10) === value && isNumber(value)) {
|
|
669
|
+
if (value < 0) initializer = factory.createPrefixUnaryExpression(typescript.default.SyntaxKind.MinusToken, factory.createNumericLiteral(Math.abs(value)));
|
|
670
|
+
else initializer = factory.createNumericLiteral(value);
|
|
671
|
+
}
|
|
670
672
|
if (typeof value === "boolean") initializer = value ? factory.createTrue() : factory.createFalse();
|
|
671
673
|
if (isNumber(Number.parseInt(key.toString(), 10))) {
|
|
672
674
|
const casingKey = applyEnumKeyCasing(`${typeName}_${key}`, enumKeyCasing);
|
|
@@ -687,8 +689,10 @@ function createEnumDeclaration({ type = "enum", name, typeName, enums, enumKeyCa
|
|
|
687
689
|
if (enums.length === 0) return [void 0, factory.createTypeAliasDeclaration([factory.createToken(typescript.default.SyntaxKind.ExportKeyword)], factory.createIdentifier(typeName), void 0, factory.createKeywordTypeNode(typescript.default.SyntaxKind.NeverKeyword))];
|
|
688
690
|
return [factory.createVariableStatement([factory.createToken(typescript.default.SyntaxKind.ExportKeyword)], factory.createVariableDeclarationList([factory.createVariableDeclaration(factory.createIdentifier(identifierName), void 0, void 0, factory.createAsExpression(factory.createObjectLiteralExpression(enums.map(([key, value, description]) => {
|
|
689
691
|
let initializer = factory.createStringLiteral(value?.toString());
|
|
690
|
-
if (isNumber(value))
|
|
691
|
-
|
|
692
|
+
if (isNumber(value)) {
|
|
693
|
+
if (value < 0) initializer = factory.createPrefixUnaryExpression(typescript.default.SyntaxKind.MinusToken, factory.createNumericLiteral(Math.abs(value)));
|
|
694
|
+
else initializer = factory.createNumericLiteral(value);
|
|
695
|
+
}
|
|
692
696
|
if (typeof value === "boolean") initializer = value ? factory.createTrue() : factory.createFalse();
|
|
693
697
|
if (key !== null && key !== void 0) {
|
|
694
698
|
const casingKey = applyEnumKeyCasing(key.toString(), enumKeyCasing);
|
|
@@ -1469,7 +1473,7 @@ const printerTs = kubb_kit.ast.createPrinter((options) => {
|
|
|
1469
1473
|
return createTypeReferenceNode(name, void 0);
|
|
1470
1474
|
},
|
|
1471
1475
|
enum(node) {
|
|
1472
|
-
const values =
|
|
1476
|
+
const values = kubb_kit.ast.getSchemaLiteralValues(node);
|
|
1473
1477
|
if (this.options.enum.type === "inlineLiteral" || !node.name || isInlineConstEnum(node, this.options.enumSchemaNames)) return createUnionDeclaration({
|
|
1474
1478
|
withParentheses: true,
|
|
1475
1479
|
nodes: values.filter((v) => v !== null && v !== void 0).map((value) => constToTypeNode(value, typeof value)).filter(isNonNullable)
|