@kubb/parser
Advanced tools
Comparing version 2.8.1 to 2.8.2
@@ -18,3 +18,3 @@ import ts from 'typescript'; | ||
*/ | ||
declare function createTupleDeclaration({ nodes, withParentheses }: { | ||
declare function createTupleDeclaration({ nodes, withParentheses, }: { | ||
nodes: Array<ts.TypeNode>; | ||
@@ -27,3 +27,3 @@ withParentheses?: boolean; | ||
*/ | ||
declare function createUnionDeclaration({ nodes, withParentheses }: { | ||
declare function createUnionDeclaration({ nodes, withParentheses, }: { | ||
nodes: Array<ts.TypeNode>; | ||
@@ -53,3 +53,3 @@ withParentheses?: boolean; | ||
*/ | ||
declare function appendJSDocToNode<TNode extends ts.Node>({ node, comments }: { | ||
declare function appendJSDocToNode<TNode extends ts.Node>({ node, comments, }: { | ||
node: TNode; | ||
@@ -108,3 +108,3 @@ comments: Array<string | undefined>; | ||
}): ts.EnumDeclaration[] | (ts.TypeAliasDeclaration | ts.VariableStatement)[]; | ||
declare function createOmitDeclaration({ keys, type, nonNullable }: { | ||
declare function createOmitDeclaration({ keys, type, nonNullable, }: { | ||
keys: Array<string> | string; | ||
@@ -111,0 +111,0 @@ type: ts.TypeNode; |
@@ -0,2 +1,56 @@ | ||
import { | ||
__commonJS, | ||
__toESM, | ||
init_esm_shims | ||
} from "./chunk-47Z32ZKI.js"; | ||
// ../../node_modules/.pnpm/lodash.tonumber@4.0.3/node_modules/lodash.tonumber/index.js | ||
var require_lodash = __commonJS({ | ||
"../../node_modules/.pnpm/lodash.tonumber@4.0.3/node_modules/lodash.tonumber/index.js"(exports, module) { | ||
"use strict"; | ||
init_esm_shims(); | ||
var NAN = 0 / 0; | ||
var symbolTag = "[object Symbol]"; | ||
var reTrim = /^\s+|\s+$/g; | ||
var reIsBadHex = /^[-+]0x[0-9a-f]+$/i; | ||
var reIsBinary = /^0b[01]+$/i; | ||
var reIsOctal = /^0o[0-7]+$/i; | ||
var freeParseInt = parseInt; | ||
var objectProto = Object.prototype; | ||
var objectToString = objectProto.toString; | ||
function isObject(value) { | ||
var type = typeof value; | ||
return !!value && (type == "object" || type == "function"); | ||
} | ||
function isObjectLike(value) { | ||
return !!value && typeof value == "object"; | ||
} | ||
function isSymbol(value) { | ||
return typeof value == "symbol" || isObjectLike(value) && objectToString.call(value) == symbolTag; | ||
} | ||
function toNumber2(value) { | ||
if (typeof value == "number") { | ||
return value; | ||
} | ||
if (isSymbol(value)) { | ||
return NAN; | ||
} | ||
if (isObject(value)) { | ||
var other = typeof value.valueOf == "function" ? value.valueOf() : value; | ||
value = isObject(other) ? other + "" : other; | ||
} | ||
if (typeof value != "string") { | ||
return value === 0 ? value : +value; | ||
} | ||
value = value.replace(reTrim, ""); | ||
var isBinary = reIsBinary.test(value); | ||
return isBinary || reIsOctal.test(value) ? freeParseInt(value.slice(2), isBinary ? 2 : 8) : reIsBadHex.test(value) ? NAN : +value; | ||
} | ||
module.exports = toNumber2; | ||
} | ||
}); | ||
// src/factory.ts | ||
init_esm_shims(); | ||
var import_lodash = __toESM(require_lodash(), 1); | ||
import ts from "typescript"; | ||
@@ -23,2 +77,8 @@ var { factory } = ts; | ||
} | ||
function isNumber(value) { | ||
if (typeof value === "string") { | ||
return !isNaN((0, import_lodash.default)(value)); | ||
} | ||
return typeof value === "number"; | ||
} | ||
var questionToken = factory.createToken(ts.SyntaxKind.QuestionToken); | ||
@@ -50,3 +110,6 @@ function createQuestionToken(token) { | ||
} | ||
function createTupleDeclaration({ nodes, withParentheses }) { | ||
function createTupleDeclaration({ | ||
nodes, | ||
withParentheses | ||
}) { | ||
if (!nodes.length) { | ||
@@ -64,3 +127,6 @@ return null; | ||
} | ||
function createUnionDeclaration({ nodes, withParentheses }) { | ||
function createUnionDeclaration({ | ||
nodes, | ||
withParentheses | ||
}) { | ||
if (!nodes.length) { | ||
@@ -86,3 +152,6 @@ return null; | ||
return factory.createPropertySignature( | ||
[...modifiers2, readOnly ? factory.createToken(ts.SyntaxKind.ReadonlyKeyword) : void 0].filter(Boolean), | ||
[ | ||
...modifiers2, | ||
readOnly ? factory.createToken(ts.SyntaxKind.ReadonlyKeyword) : void 0 | ||
].filter(Boolean), | ||
propertyName(name), | ||
@@ -100,3 +169,10 @@ createQuestionToken(questionToken2), | ||
}) { | ||
return factory.createParameterDeclaration(modifiers2, dotDotDotToken, name, createQuestionToken(questionToken2), type, initializer); | ||
return factory.createParameterDeclaration( | ||
modifiers2, | ||
dotDotDotToken, | ||
name, | ||
createQuestionToken(questionToken2), | ||
type, | ||
initializer | ||
); | ||
} | ||
@@ -116,3 +192,6 @@ function createJSDoc({ comments }) { | ||
} | ||
function appendJSDocToNode({ node, comments }) { | ||
function appendJSDocToNode({ | ||
node, | ||
comments | ||
}) { | ||
const filteredComments = comments.filter(Boolean); | ||
@@ -126,4 +205,9 @@ if (!filteredComments.length) { | ||
}, "*"); | ||
return ts.addSyntheticLeadingComment({ ...node }, ts.SyntaxKind.MultiLineCommentTrivia, `${text || "*"} | ||
`, true); | ||
return ts.addSyntheticLeadingComment( | ||
{ ...node }, | ||
ts.SyntaxKind.MultiLineCommentTrivia, | ||
`${text || "*"} | ||
`, | ||
true | ||
); | ||
} | ||
@@ -135,3 +219,7 @@ function createIndexSignature(type, { | ||
} = {}) { | ||
return factory.createIndexSignature(modifiers2, [createParameterSignature(indexName, { type: indexType })], type); | ||
return factory.createIndexSignature( | ||
modifiers2, | ||
[createParameterSignature(indexName, { type: indexType })], | ||
type | ||
); | ||
} | ||
@@ -144,3 +232,8 @@ function createTypeAliasDeclaration({ | ||
}) { | ||
return factory.createTypeAliasDeclaration(modifiers2, name, typeParameters, type); | ||
return factory.createTypeAliasDeclaration( | ||
modifiers2, | ||
name, | ||
typeParameters, | ||
type | ||
); | ||
} | ||
@@ -169,3 +262,5 @@ function createNamespaceDeclaration({ | ||
importPropertyName = void 0; | ||
importName = factory.createNamespaceImport(factory.createIdentifier(name)); | ||
importName = factory.createNamespaceImport( | ||
factory.createIdentifier(name) | ||
); | ||
} | ||
@@ -189,7 +284,19 @@ return factory.createImportDeclaration( | ||
if (obj.name) { | ||
return factory.createImportSpecifier(false, factory.createIdentifier(obj.propertyName), factory.createIdentifier(obj.name)); | ||
return factory.createImportSpecifier( | ||
false, | ||
factory.createIdentifier(obj.propertyName), | ||
factory.createIdentifier(obj.name) | ||
); | ||
} | ||
return factory.createImportSpecifier(false, void 0, factory.createIdentifier(obj.propertyName)); | ||
return factory.createImportSpecifier( | ||
false, | ||
void 0, | ||
factory.createIdentifier(obj.propertyName) | ||
); | ||
} | ||
return factory.createImportSpecifier(false, void 0, factory.createIdentifier(item)); | ||
return factory.createImportSpecifier( | ||
false, | ||
void 0, | ||
factory.createIdentifier(item) | ||
); | ||
}) | ||
@@ -226,3 +333,7 @@ ) | ||
name.map((propertyName2) => { | ||
return factory.createExportSpecifier(false, void 0, typeof propertyName2 === "string" ? factory.createIdentifier(propertyName2) : propertyName2); | ||
return factory.createExportSpecifier( | ||
false, | ||
void 0, | ||
typeof propertyName2 === "string" ? factory.createIdentifier(propertyName2) : propertyName2 | ||
); | ||
}) | ||
@@ -246,11 +357,19 @@ ), | ||
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())); | ||
})) | ||
factory.createUnionTypeNode( | ||
enums.map(([_key, value]) => { | ||
if (isNumber(value)) { | ||
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()) | ||
); | ||
}) | ||
) | ||
) | ||
@@ -262,8 +381,13 @@ ]; | ||
factory.createEnumDeclaration( | ||
[factory.createToken(ts.SyntaxKind.ExportKeyword), type === "constEnum" ? factory.createToken(ts.SyntaxKind.ConstKeyword) : void 0].filter(Boolean), | ||
[ | ||
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()); | ||
if (typeof value === "number") { | ||
initializer = factory.createNumericLiteral(value); | ||
let initializer = factory.createStringLiteral( | ||
value?.toString() | ||
); | ||
if (isNumber(value)) { | ||
initializer = factory.createNumericLiteral((0, import_lodash.default)(value)); | ||
} | ||
@@ -273,6 +397,12 @@ if (typeof value === "boolean") { | ||
} | ||
if (typeof key === "number") { | ||
return factory.createEnumMember(factory.createStringLiteral(`${typeName}_${key}`), initializer); | ||
if (isNumber(key)) { | ||
return factory.createEnumMember( | ||
factory.createStringLiteral(`${typeName}_${key}`), | ||
initializer | ||
); | ||
} | ||
return factory.createEnumMember(factory.createStringLiteral(`${key}`), initializer); | ||
return factory.createEnumMember( | ||
factory.createStringLiteral(`${key}`), | ||
initializer | ||
); | ||
}) | ||
@@ -295,4 +425,6 @@ ) | ||
enums.map(([key, value]) => { | ||
let initializer = factory.createStringLiteral(`${value?.toString()}`); | ||
if (typeof value === "number") { | ||
let initializer = factory.createStringLiteral( | ||
`${value?.toString()}` | ||
); | ||
if (isNumber(value)) { | ||
initializer = factory.createNumericLiteral(value); | ||
@@ -303,7 +435,13 @@ } | ||
} | ||
return factory.createPropertyAssignment(factory.createStringLiteral(`${key}`), initializer); | ||
return factory.createPropertyAssignment( | ||
factory.createStringLiteral(`${key}`), | ||
initializer | ||
); | ||
}), | ||
true | ||
), | ||
factory.createTypeReferenceNode(factory.createIdentifier("const"), void 0) | ||
factory.createTypeReferenceNode( | ||
factory.createIdentifier("const"), | ||
void 0 | ||
) | ||
) | ||
@@ -320,4 +458,15 @@ ) | ||
factory.createIndexedAccessTypeNode( | ||
factory.createParenthesizedType(factory.createTypeQueryNode(factory.createIdentifier(identifierName), void 0)), | ||
factory.createTypeOperatorNode(ts.SyntaxKind.KeyOfKeyword, factory.createTypeQueryNode(factory.createIdentifier(identifierName), void 0)) | ||
factory.createParenthesizedType( | ||
factory.createTypeQueryNode( | ||
factory.createIdentifier(identifierName), | ||
void 0 | ||
) | ||
), | ||
factory.createTypeOperatorNode( | ||
ts.SyntaxKind.KeyOfKeyword, | ||
factory.createTypeQueryNode( | ||
factory.createIdentifier(identifierName), | ||
void 0 | ||
) | ||
) | ||
) | ||
@@ -327,4 +476,10 @@ ) | ||
} | ||
function createOmitDeclaration({ keys, type, nonNullable }) { | ||
const node = nonNullable ? factory.createTypeReferenceNode(factory.createIdentifier("NonNullable"), [type]) : type; | ||
function createOmitDeclaration({ | ||
keys, | ||
type, | ||
nonNullable | ||
}) { | ||
const node = nonNullable ? factory.createTypeReferenceNode(factory.createIdentifier("NonNullable"), [ | ||
type | ||
]) : type; | ||
if (Array.isArray(keys)) { | ||
@@ -335,3 +490,5 @@ return factory.createTypeReferenceNode(factory.createIdentifier("Omit"), [ | ||
keys.map((key) => { | ||
return factory.createLiteralTypeNode(factory.createStringLiteral(key)); | ||
return factory.createLiteralTypeNode( | ||
factory.createStringLiteral(key) | ||
); | ||
}) | ||
@@ -341,3 +498,6 @@ ) | ||
} | ||
return factory.createTypeReferenceNode(factory.createIdentifier("Omit"), [node, factory.createLiteralTypeNode(factory.createStringLiteral(keys))]); | ||
return factory.createTypeReferenceNode(factory.createIdentifier("Omit"), [ | ||
node, | ||
factory.createLiteralTypeNode(factory.createStringLiteral(keys)) | ||
]); | ||
} | ||
@@ -353,3 +513,5 @@ var keywordTypeNodes = { | ||
undefined: factory.createKeywordTypeNode(ts.SyntaxKind.UndefinedKeyword), | ||
null: factory.createLiteralTypeNode(factory.createToken(ts.SyntaxKind.NullKeyword)) | ||
null: factory.createLiteralTypeNode( | ||
factory.createToken(ts.SyntaxKind.NullKeyword) | ||
) | ||
}; | ||
@@ -356,0 +518,0 @@ var createTypeLiteralNode = factory.createTypeLiteralNode; |
@@ -0,2 +1,10 @@ | ||
import { | ||
init_esm_shims | ||
} from "./chunk-47Z32ZKI.js"; | ||
// src/index.ts | ||
init_esm_shims(); | ||
// src/api.ts | ||
init_esm_shims(); | ||
import path from "path"; | ||
@@ -33,3 +41,7 @@ import ts from "typescript"; | ||
// src/parse.ts | ||
init_esm_shims(); | ||
// src/print.ts | ||
init_esm_shims(); | ||
import ts2 from "typescript"; | ||
@@ -36,0 +48,0 @@ var { factory } = ts2; |
{ | ||
"name": "@kubb/parser", | ||
"version": "2.8.1", | ||
"version": "2.8.2", | ||
"description": "Generator parser", | ||
@@ -55,2 +55,4 @@ "keywords": [ | ||
"eslint": "^8.57.0", | ||
"lodash.tonumber": "^4.0.3", | ||
"@types/lodash.tonumber": "^4.0.3", | ||
"tsup": "^8.0.2", | ||
@@ -57,0 +59,0 @@ "@kubb/eslint-config": "1.1.8", |
/* eslint-disable @typescript-eslint/unbound-method */ | ||
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */ | ||
import toNumber from 'lodash.tonumber' | ||
import ts from 'typescript' | ||
@@ -22,3 +23,8 @@ | ||
return !!node && node.kind === ts.SyntaxKind.Identifier && ts.identifierToKeywordKind(node.kind as unknown as ts.Identifier) === undefined | ||
return ( | ||
!!node | ||
&& node.kind === ts.SyntaxKind.Identifier | ||
&& ts.identifierToKeywordKind(node.kind as unknown as ts.Identifier) | ||
=== undefined | ||
) | ||
} | ||
@@ -28,3 +34,5 @@ | ||
if (typeof name === 'string') { | ||
return isValidIdentifier(name) ? factory.createIdentifier(name) : factory.createStringLiteral(name) | ||
return isValidIdentifier(name) | ||
? factory.createIdentifier(name) | ||
: factory.createStringLiteral(name) | ||
} | ||
@@ -34,2 +42,9 @@ return name | ||
function isNumber(value: unknown): value is number { | ||
if (typeof value === 'string') { | ||
return !isNaN(toNumber(value)) | ||
} | ||
return typeof value === 'number' | ||
} | ||
const questionToken = factory.createToken(ts.SyntaxKind.QuestionToken) | ||
@@ -75,3 +90,9 @@ | ||
*/ | ||
export function createTupleDeclaration({ nodes, withParentheses }: { nodes: Array<ts.TypeNode>; withParentheses?: boolean }): ts.TypeNode | null { | ||
export function createTupleDeclaration({ | ||
nodes, | ||
withParentheses, | ||
}: { | ||
nodes: Array<ts.TypeNode> | ||
withParentheses?: boolean | ||
}): ts.TypeNode | null { | ||
if (!nodes.length) { | ||
@@ -97,3 +118,9 @@ return null | ||
*/ | ||
export function createUnionDeclaration({ nodes, withParentheses }: { nodes: Array<ts.TypeNode>; withParentheses?: boolean }): ts.TypeNode | null { | ||
export function createUnionDeclaration({ | ||
nodes, | ||
withParentheses, | ||
}: { | ||
nodes: Array<ts.TypeNode> | ||
withParentheses?: boolean | ||
}): ts.TypeNode | null { | ||
if (!nodes.length) { | ||
@@ -130,3 +157,6 @@ return null | ||
return factory.createPropertySignature( | ||
[...modifiers, readOnly ? factory.createToken(ts.SyntaxKind.ReadonlyKeyword) : undefined].filter(Boolean), | ||
[ | ||
...modifiers, | ||
readOnly ? factory.createToken(ts.SyntaxKind.ReadonlyKeyword) : undefined, | ||
].filter(Boolean), | ||
propertyName(name), | ||
@@ -155,3 +185,10 @@ createQuestionToken(questionToken), | ||
): ts.ParameterDeclaration { | ||
return factory.createParameterDeclaration(modifiers, dotDotDotToken, name, createQuestionToken(questionToken), type, initializer) | ||
return factory.createParameterDeclaration( | ||
modifiers, | ||
dotDotDotToken, | ||
name, | ||
createQuestionToken(questionToken), | ||
type, | ||
initializer, | ||
) | ||
} | ||
@@ -176,3 +213,9 @@ | ||
*/ | ||
export function appendJSDocToNode<TNode extends ts.Node>({ node, comments }: { node: TNode; comments: Array<string | undefined> }) { | ||
export function appendJSDocToNode<TNode extends ts.Node>({ | ||
node, | ||
comments, | ||
}: { | ||
node: TNode | ||
comments: Array<string | undefined> | ||
}) { | ||
const filteredComments = comments.filter(Boolean) | ||
@@ -189,3 +232,8 @@ | ||
// node: {...node}, with that ts.addSyntheticLeadingComment is appending | ||
return ts.addSyntheticLeadingComment({ ...node }, ts.SyntaxKind.MultiLineCommentTrivia, `${text || '*'}\n`, true) | ||
return ts.addSyntheticLeadingComment( | ||
{ ...node }, | ||
ts.SyntaxKind.MultiLineCommentTrivia, | ||
`${text || '*'}\n`, | ||
true, | ||
) | ||
} | ||
@@ -206,3 +254,7 @@ | ||
) { | ||
return factory.createIndexSignature(modifiers, [createParameterSignature(indexName, { type: indexType })], type) | ||
return factory.createIndexSignature( | ||
modifiers, | ||
[createParameterSignature(indexName, { type: indexType })], | ||
type, | ||
) | ||
} | ||
@@ -221,3 +273,8 @@ | ||
}) { | ||
return factory.createTypeAliasDeclaration(modifiers, name, typeParameters, type) | ||
return factory.createTypeAliasDeclaration( | ||
modifiers, | ||
name, | ||
typeParameters, | ||
type, | ||
) | ||
} | ||
@@ -261,3 +318,5 @@ | ||
importPropertyName = undefined | ||
importName = factory.createNamespaceImport(factory.createIdentifier(name)) | ||
importName = factory.createNamespaceImport( | ||
factory.createIdentifier(name), | ||
) | ||
} | ||
@@ -283,9 +342,21 @@ | ||
if (obj.name) { | ||
return factory.createImportSpecifier(false, factory.createIdentifier(obj.propertyName), factory.createIdentifier(obj.name)) | ||
return factory.createImportSpecifier( | ||
false, | ||
factory.createIdentifier(obj.propertyName), | ||
factory.createIdentifier(obj.name), | ||
) | ||
} | ||
return factory.createImportSpecifier(false, undefined, factory.createIdentifier(obj.propertyName)) | ||
return factory.createImportSpecifier( | ||
false, | ||
undefined, | ||
factory.createIdentifier(obj.propertyName), | ||
) | ||
} | ||
return factory.createImportSpecifier(false, undefined, factory.createIdentifier(item)) | ||
return factory.createImportSpecifier( | ||
false, | ||
undefined, | ||
factory.createIdentifier(item), | ||
) | ||
}), | ||
@@ -320,3 +391,5 @@ ), | ||
isTypeOnly, | ||
asAlias && parsedName ? factory.createNamespaceExport(factory.createIdentifier(parsedName)) : undefined, | ||
asAlias && parsedName | ||
? factory.createNamespaceExport(factory.createIdentifier(parsedName)) | ||
: undefined, | ||
factory.createStringLiteral(path), | ||
@@ -332,3 +405,9 @@ undefined, | ||
name.map((propertyName) => { | ||
return factory.createExportSpecifier(false, undefined, typeof propertyName === 'string' ? factory.createIdentifier(propertyName) : propertyName) | ||
return factory.createExportSpecifier( | ||
false, | ||
undefined, | ||
typeof propertyName === 'string' | ||
? factory.createIdentifier(propertyName) | ||
: propertyName, | ||
) | ||
}), | ||
@@ -367,13 +446,21 @@ ), | ||
undefined, | ||
factory.createUnionTypeNode(enums.map(([_key, value]) => { | ||
if (typeof value === 'number') { | ||
return factory.createLiteralTypeNode(factory.createNumericLiteral(value?.toString())) | ||
} | ||
factory.createUnionTypeNode( | ||
enums.map(([_key, value]) => { | ||
if (isNumber(value)) { | ||
return factory.createLiteralTypeNode( | ||
factory.createNumericLiteral(value?.toString()), | ||
) | ||
} | ||
if (typeof value === 'boolean') { | ||
return factory.createLiteralTypeNode(value ? factory.createTrue() : factory.createFalse()) | ||
} | ||
if (typeof value === 'boolean') { | ||
return factory.createLiteralTypeNode( | ||
value ? factory.createTrue() : factory.createFalse(), | ||
) | ||
} | ||
return factory.createLiteralTypeNode(factory.createStringLiteral(value?.toString())) | ||
})), | ||
return factory.createLiteralTypeNode( | ||
factory.createStringLiteral(value?.toString()), | ||
) | ||
}), | ||
), | ||
), | ||
@@ -386,9 +473,16 @@ ] | ||
factory.createEnumDeclaration( | ||
[factory.createToken(ts.SyntaxKind.ExportKeyword), type === 'constEnum' ? factory.createToken(ts.SyntaxKind.ConstKeyword) : undefined].filter(Boolean), | ||
[ | ||
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(), | ||
) | ||
if (typeof value === 'number') { | ||
initializer = factory.createNumericLiteral(value) | ||
if (isNumber(value)) { | ||
initializer = factory.createNumericLiteral(toNumber(value)) | ||
} | ||
@@ -399,7 +493,13 @@ if (typeof value === 'boolean') { | ||
if (typeof key === 'number') { | ||
return factory.createEnumMember(factory.createStringLiteral(`${typeName}_${key}`), initializer) | ||
if (isNumber(key)) { | ||
return factory.createEnumMember( | ||
factory.createStringLiteral(`${typeName}_${key}`), | ||
initializer, | ||
) | ||
} | ||
return factory.createEnumMember(factory.createStringLiteral(`${key}`), initializer) | ||
return factory.createEnumMember( | ||
factory.createStringLiteral(`${key}`), | ||
initializer, | ||
) | ||
}), | ||
@@ -425,16 +525,26 @@ ), | ||
enums.map(([key, value]) => { | ||
let initializer: ts.Expression = factory.createStringLiteral(`${value?.toString()}`) | ||
let initializer: ts.Expression = factory.createStringLiteral( | ||
`${value?.toString()}`, | ||
) | ||
if (typeof value === 'number') { | ||
if (isNumber(value)) { | ||
initializer = factory.createNumericLiteral(value) | ||
} | ||
if (typeof value === 'boolean') { | ||
initializer = value ? factory.createTrue() : factory.createFalse() | ||
initializer = value | ||
? factory.createTrue() | ||
: factory.createFalse() | ||
} | ||
return factory.createPropertyAssignment(factory.createStringLiteral(`${key}`), initializer) | ||
return factory.createPropertyAssignment( | ||
factory.createStringLiteral(`${key}`), | ||
initializer, | ||
) | ||
}), | ||
true, | ||
), | ||
factory.createTypeReferenceNode(factory.createIdentifier('const'), undefined), | ||
factory.createTypeReferenceNode( | ||
factory.createIdentifier('const'), | ||
undefined, | ||
), | ||
), | ||
@@ -451,4 +561,15 @@ ), | ||
factory.createIndexedAccessTypeNode( | ||
factory.createParenthesizedType(factory.createTypeQueryNode(factory.createIdentifier(identifierName), undefined)), | ||
factory.createTypeOperatorNode(ts.SyntaxKind.KeyOfKeyword, factory.createTypeQueryNode(factory.createIdentifier(identifierName), undefined)), | ||
factory.createParenthesizedType( | ||
factory.createTypeQueryNode( | ||
factory.createIdentifier(identifierName), | ||
undefined, | ||
), | ||
), | ||
factory.createTypeOperatorNode( | ||
ts.SyntaxKind.KeyOfKeyword, | ||
factory.createTypeQueryNode( | ||
factory.createIdentifier(identifierName), | ||
undefined, | ||
), | ||
), | ||
), | ||
@@ -459,4 +580,16 @@ ), | ||
export function createOmitDeclaration({ keys, type, nonNullable }: { keys: Array<string> | string; type: ts.TypeNode; nonNullable?: boolean }) { | ||
const node = nonNullable ? factory.createTypeReferenceNode(factory.createIdentifier('NonNullable'), [type]) : type | ||
export function createOmitDeclaration({ | ||
keys, | ||
type, | ||
nonNullable, | ||
}: { | ||
keys: Array<string> | string | ||
type: ts.TypeNode | ||
nonNullable?: boolean | ||
}) { | ||
const node = nonNullable | ||
? factory.createTypeReferenceNode(factory.createIdentifier('NonNullable'), [ | ||
type, | ||
]) | ||
: type | ||
@@ -468,3 +601,5 @@ if (Array.isArray(keys)) { | ||
keys.map((key) => { | ||
return factory.createLiteralTypeNode(factory.createStringLiteral(key)) | ||
return factory.createLiteralTypeNode( | ||
factory.createStringLiteral(key), | ||
) | ||
}), | ||
@@ -475,3 +610,6 @@ ), | ||
return factory.createTypeReferenceNode(factory.createIdentifier('Omit'), [node, factory.createLiteralTypeNode(factory.createStringLiteral(keys))]) | ||
return factory.createTypeReferenceNode(factory.createIdentifier('Omit'), [ | ||
node, | ||
factory.createLiteralTypeNode(factory.createStringLiteral(keys)), | ||
]) | ||
} | ||
@@ -488,3 +626,5 @@ | ||
undefined: factory.createKeywordTypeNode(ts.SyntaxKind.UndefinedKeyword), | ||
null: factory.createLiteralTypeNode(factory.createToken(ts.SyntaxKind.NullKeyword)), | ||
null: factory.createLiteralTypeNode( | ||
factory.createToken(ts.SyntaxKind.NullKeyword), | ||
), | ||
} as const | ||
@@ -491,0 +631,0 @@ |
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
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
151513
24
2049
7