@kubb/parser
Advanced tools
Comparing version 0.0.0-canary-20240114112243 to 0.0.0-canary-20240114133034
@@ -94,3 +94,3 @@ import ts from 'typescript'; | ||
*/ | ||
type?: 'enum' | 'asConst' | 'asPascalConst'; | ||
type?: 'enum' | 'asConst' | 'asPascalConst' | 'constEnum' | 'literal'; | ||
/** | ||
@@ -97,0 +97,0 @@ * Enum name in camelCase. |
@@ -229,9 +229,27 @@ import ts from 'typescript'; | ||
}) { | ||
if (type === "enum") { | ||
if (type === "literal") { | ||
return [ | ||
factory.createEnumDeclaration( | ||
factory.createTypeAliasDeclaration( | ||
[factory.createToken(ts.SyntaxKind.ExportKeyword)], | ||
factory.createIdentifier(typeName), | ||
void 0, | ||
factory.createUnionTypeNode(enums.map(([_key, value]) => { | ||
if (typeof value === "number") { | ||
return factory.createLiteralTypeNode(factory.createNumericLiteral(value?.toString())); | ||
} | ||
if (typeof value === "boolean") { | ||
return factory.createLiteralTypeNode(value ? factory.createTrue() : factory.createFalse()); | ||
} | ||
return factory.createLiteralTypeNode(factory.createStringLiteral(value?.toString())); | ||
})) | ||
) | ||
]; | ||
} | ||
if (type === "enum" || type === "constEnum") { | ||
return [ | ||
factory.createEnumDeclaration( | ||
[factory.createToken(ts.SyntaxKind.ExportKeyword), type === "constEnum" ? factory.createToken(ts.SyntaxKind.ConstKeyword) : void 0].filter(Boolean), | ||
factory.createIdentifier(typeName), | ||
enums.map(([key, value]) => { | ||
let initializer = factory.createStringLiteral(`${value?.toString()}`); | ||
let initializer = factory.createStringLiteral(value?.toString()); | ||
if (typeof value === "number") { | ||
@@ -238,0 +256,0 @@ initializer = factory.createNumericLiteral(value); |
{ | ||
"name": "@kubb/parser", | ||
"version": "0.0.0-canary-20240114112243", | ||
"version": "0.0.0-canary-20240114133034", | ||
"description": "Generator parser", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -335,3 +335,3 @@ /* eslint-disable @typescript-eslint/unbound-method */ | ||
*/ | ||
type?: 'enum' | 'asConst' | 'asPascalConst' | ||
type?: 'enum' | 'asConst' | 'asPascalConst' | 'constEnum' | 'literal' | ||
/** | ||
@@ -347,9 +347,30 @@ * Enum name in camelCase. | ||
}) { | ||
if (type === 'enum') { | ||
if (type === 'literal') { | ||
return [ | ||
factory.createEnumDeclaration( | ||
factory.createTypeAliasDeclaration( | ||
[factory.createToken(ts.SyntaxKind.ExportKeyword)], | ||
factory.createIdentifier(typeName), | ||
undefined, | ||
factory.createUnionTypeNode(enums.map(([_key, value]) => { | ||
if (typeof value === 'number') { | ||
return factory.createLiteralTypeNode(factory.createNumericLiteral(value?.toString())) | ||
} | ||
if (typeof value === 'boolean') { | ||
return factory.createLiteralTypeNode(value ? factory.createTrue() : factory.createFalse()) | ||
} | ||
return factory.createLiteralTypeNode(factory.createStringLiteral(value?.toString())) | ||
})), | ||
), | ||
] | ||
} | ||
if (type === 'enum' || type === 'constEnum') { | ||
return [ | ||
factory.createEnumDeclaration( | ||
[factory.createToken(ts.SyntaxKind.ExportKeyword), type === 'constEnum' ? factory.createToken(ts.SyntaxKind.ConstKeyword) : undefined].filter(Boolean), | ||
factory.createIdentifier(typeName), | ||
enums.map(([key, value]) => { | ||
let initializer: ts.Expression = factory.createStringLiteral(`${value?.toString()}`) | ||
let initializer: ts.Expression = factory.createStringLiteral(value?.toString()) | ||
@@ -356,0 +377,0 @@ if (typeof value === 'number') { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
121105
1496