@kubb/parser-ts 3.0.0-alpha.4 → 3.0.0-alpha.6

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.
@@ -255,7 +255,7 @@ function createExportDeclaration({
255
255
  name
256
256
  }) {
257
257
  if (name && !Array.isArray(name) && !asAlias) {
258
- throw new Error("When using `name` as string, `asAlias` should be true");
258
+ console.warn(`When using name as string, asAlias should be true ${name}`);
259
259
  }
260
260
  if (!Array.isArray(name)) {
261
261
  const parsedName = _optionalChain([name, 'optionalAccess', _ => _.match, 'call', _2 => _2(/^\d/)]) ? `_${_optionalChain([name, 'optionalAccess', _3 => _3.slice, 'call', _4 => _4(1)])}` : name;
@@ -287,6 +287,7 @@ function createEnumDeclaration({
287
287
  }) {
288
288
  if (type === "literal") {
289
289
  return [
290
+ void 0,
290
291
  factory.createTypeAliasDeclaration(
291
292
  [factory.createToken(_typescript2.default.SyntaxKind.ExportKeyword)],
292
293
  factory.createIdentifier(typeName),
@@ -310,6 +311,7 @@ function createEnumDeclaration({
310
311
  }
311
312
  if (type === "enum" || type === "constEnum") {
312
313
  return [
314
+ void 0,
313
315
  factory.createEnumDeclaration(
314
316
  [factory.createToken(_typescript2.default.SyntaxKind.ExportKeyword), type === "constEnum" ? factory.createToken(_typescript2.default.SyntaxKind.ConstKeyword) : void 0].filter(Boolean),
315
317
  factory.createIdentifier(typeName),
@@ -450,4 +452,4 @@ var createTupleTypeNode = factory.createTupleTypeNode;
450
452
 
451
453
 
452
454
  exports.modifiers = modifiers; exports.createQuestionToken = createQuestionToken; exports.createIntersectionDeclaration = createIntersectionDeclaration; exports.createTupleDeclaration = createTupleDeclaration; exports.createArrayDeclaration = createArrayDeclaration; exports.createUnionDeclaration = createUnionDeclaration; exports.createPropertySignature = createPropertySignature; exports.createParameterSignature = createParameterSignature; exports.createJSDoc = createJSDoc; exports.appendJSDocToNode = appendJSDocToNode; exports.createIndexSignature = createIndexSignature; exports.createTypeAliasDeclaration = createTypeAliasDeclaration; exports.createNamespaceDeclaration = createNamespaceDeclaration; exports.createImportDeclaration = createImportDeclaration; exports.createExportDeclaration = createExportDeclaration; exports.createEnumDeclaration = createEnumDeclaration; exports.createOmitDeclaration = createOmitDeclaration; exports.keywordTypeNodes = keywordTypeNodes; exports.createTypeLiteralNode = createTypeLiteralNode; exports.createTypeReferenceNode = createTypeReferenceNode; exports.createNumericLiteral = createNumericLiteral; exports.createStringLiteral = createStringLiteral; exports.createArrayTypeNode = createArrayTypeNode; exports.createLiteralTypeNode = createLiteralTypeNode; exports.createNull = createNull; exports.createIdentifier = createIdentifier; exports.createTupleTypeNode = createTupleTypeNode; exports.factory_exports = factory_exports;
453
- //# sourceMappingURL=chunk-UQLRYRTM.cjs.map
455
+ //# sourceMappingURL=chunk-KWWQXE3U.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["/home/runner/work/kubb/kubb/packages/parser-ts/dist/chunk-KWWQXE3U.cjs","../src/factory.ts"],"names":["modifiers","questionToken"],"mappings":"AAAA,irBAAI,UAAU,EAAE,MAAM,CAAC,cAAc;AACrC,IAAI,SAAS,EAAE,CAAC,MAAM,EAAE,GAAG,EAAE,GAAG;AAChC,EAAE,IAAI,CAAC,IAAI,KAAK,GAAG,GAAG;AACtB,IAAI,SAAS,CAAC,MAAM,EAAE,IAAI,EAAE,EAAE,GAAG,EAAE,GAAG,CAAC,IAAI,CAAC,EAAE,UAAU,EAAE,KAAK,CAAC,CAAC;AACjE,CAAC;AACD;AACA;ACNA,IAAA,gBAAA,EAAA,CAAA,CAAA;AAAA,QAAA,CAAA,eAAA,EAAA;AAAA,EAAA,iBAAA,EAAA,CAAA,EAAA,GAAA,iBAAA;AAAA,EAAA,sBAAA,EAAA,CAAA,EAAA,GAAA,sBAAA;AAAA,EAAA,mBAAA,EAAA,CAAA,EAAA,GAAA,mBAAA;AAAA,EAAA,qBAAA,EAAA,CAAA,EAAA,GAAA,qBAAA;AAAA,EAAA,uBAAA,EAAA,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ACqB,EAAA;AACrB,EAAA;AACqB,EAAA;AACA,EAAA;AACrB,EAAA;AACE,EAAA;AACiB,EAAA;AACtC;AAE6C;AAEE;AACH;AACD;AAEA;AAEE;AACX;AACM;AAEG;ADnIH;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","file":"/home/runner/work/kubb/kubb/packages/parser-ts/dist/chunk-KWWQXE3U.cjs","sourcesContent":[null,"import { isNumber } from 'remeda'\nimport ts from 'typescript'\n\nconst { factory } = ts\n\n// https://ts-ast-viewer.com/\n\nexport const modifiers = {\n async: factory.createModifier(ts.SyntaxKind.AsyncKeyword),\n export: factory.createModifier(ts.SyntaxKind.ExportKeyword),\n const: factory.createModifier(ts.SyntaxKind.ConstKeyword),\n static: factory.createModifier(ts.SyntaxKind.StaticKeyword),\n} as const\n\nfunction isValidIdentifier(str: string): boolean {\n if (!str.length || str.trim() !== str) {\n return false\n }\n const node = ts.parseIsolatedEntityName(str, ts.ScriptTarget.Latest)\n\n return !!node && node.kind === ts.SyntaxKind.Identifier && ts.identifierToKeywordKind(node.kind as unknown as ts.Identifier) === undefined\n}\n\nfunction propertyName(name: string | ts.PropertyName): ts.PropertyName {\n if (typeof name === 'string') {\n return isValidIdentifier(name) ? factory.createIdentifier(name) : factory.createStringLiteral(name)\n }\n return name\n}\n\nconst questionToken = factory.createToken(ts.SyntaxKind.QuestionToken)\n\nexport function createQuestionToken(token?: boolean | ts.QuestionToken) {\n if (!token) {\n return undefined\n }\n if (token === true) {\n return questionToken\n }\n return token\n}\n\nexport function createIntersectionDeclaration({\n nodes,\n withParentheses,\n}: {\n nodes: Array<ts.TypeNode>\n withParentheses?: boolean\n}): ts.TypeNode | null {\n if (!nodes.length) {\n return null\n }\n\n if (nodes.length === 1) {\n return nodes[0] || null\n }\n\n const node = factory.createIntersectionTypeNode(nodes)\n\n if (withParentheses) {\n return factory.createParenthesizedType(node)\n }\n\n return node\n}\n\n/**\n * Minimum nodes length of 2\n * @example `string & number`\n */\nexport function createTupleDeclaration({\n nodes,\n withParentheses,\n}: {\n nodes: Array<ts.TypeNode>\n withParentheses?: boolean\n}): ts.TypeNode | null {\n if (!nodes.length) {\n return null\n }\n\n if (nodes.length === 1) {\n return nodes[0] || null\n }\n\n const node = factory.createTupleTypeNode(nodes)\n\n if (withParentheses) {\n return factory.createParenthesizedType(node)\n }\n\n return node\n}\n\nexport function createArrayDeclaration({\n nodes,\n}: {\n nodes: Array<ts.TypeNode>\n}): ts.TypeNode | null {\n if (!nodes.length) {\n return factory.createTupleTypeNode([])\n }\n\n if (nodes.length === 1) {\n return factory.createArrayTypeNode(nodes.at(0)!)\n }\n\n return factory.createExpressionWithTypeArguments(factory.createIdentifier('Array'), [factory.createUnionTypeNode(nodes)])\n}\n\n/**\n * Minimum nodes length of 2\n * @example `string | number`\n */\nexport function createUnionDeclaration({\n nodes,\n withParentheses,\n}: {\n nodes: Array<ts.TypeNode>\n withParentheses?: boolean\n}): ts.TypeNode | null {\n if (!nodes.length) {\n return null\n }\n\n if (nodes.length === 1) {\n return nodes[0] || null\n }\n\n const node = factory.createUnionTypeNode(nodes)\n\n if (withParentheses) {\n return factory.createParenthesizedType(node)\n }\n\n return node\n}\n\nexport function createPropertySignature({\n readOnly,\n modifiers = [],\n name,\n questionToken,\n type,\n}: {\n readOnly?: boolean\n modifiers?: Array<ts.Modifier>\n name: ts.PropertyName | string\n questionToken?: ts.QuestionToken | boolean\n type?: ts.TypeNode\n}) {\n return factory.createPropertySignature(\n [...modifiers, readOnly ? factory.createToken(ts.SyntaxKind.ReadonlyKeyword) : undefined].filter(Boolean),\n propertyName(name),\n createQuestionToken(questionToken),\n type,\n )\n}\n\nexport function createParameterSignature(\n name: string | ts.BindingName,\n {\n modifiers,\n dotDotDotToken,\n questionToken,\n type,\n initializer,\n }: {\n decorators?: Array<ts.Decorator>\n modifiers?: Array<ts.Modifier>\n dotDotDotToken?: ts.DotDotDotToken\n questionToken?: ts.QuestionToken | boolean\n type?: ts.TypeNode\n initializer?: ts.Expression\n },\n): ts.ParameterDeclaration {\n return factory.createParameterDeclaration(modifiers, dotDotDotToken, name, createQuestionToken(questionToken), type, initializer)\n}\n\nexport function createJSDoc({ comments }: { comments: string[] }) {\n if (!comments.length) {\n return null\n }\n return factory.createJSDocComment(\n factory.createNodeArray(\n comments.map((comment, i) => {\n if (i === comments.length - 1) {\n return factory.createJSDocText(comment)\n }\n\n return factory.createJSDocText(`${comment}\\n`)\n }),\n ),\n )\n}\n\n/**\n * @link https://github.com/microsoft/TypeScript/issues/44151\n */\nexport function appendJSDocToNode<TNode extends ts.Node>({\n node,\n comments,\n}: {\n node: TNode\n comments: Array<string | undefined>\n}) {\n const filteredComments = comments.filter(Boolean)\n\n if (!filteredComments.length) {\n return node\n }\n\n const text = filteredComments.reduce((acc = '', comment = '') => {\n return `${acc}\\n * ${comment}`\n }, '*')\n\n // node: {...node}, with that ts.addSyntheticLeadingComment is appending\n return ts.addSyntheticLeadingComment({ ...node }, ts.SyntaxKind.MultiLineCommentTrivia, `${text || '*'}\\n`, true)\n}\n\nexport function createIndexSignature(\n type: ts.TypeNode,\n {\n modifiers,\n indexName = 'key',\n indexType = factory.createKeywordTypeNode(ts.SyntaxKind.StringKeyword),\n }: {\n indexName?: string\n indexType?: ts.TypeNode\n decorators?: Array<ts.Decorator>\n modifiers?: Array<ts.Modifier>\n } = {},\n) {\n return factory.createIndexSignature(modifiers, [createParameterSignature(indexName, { type: indexType })], type)\n}\n\nexport function createTypeAliasDeclaration({\n modifiers,\n name,\n typeParameters,\n type,\n}: {\n modifiers?: Array<ts.Modifier>\n name: string | ts.Identifier\n typeParameters?: Array<ts.TypeParameterDeclaration>\n type: ts.TypeNode\n}) {\n return factory.createTypeAliasDeclaration(modifiers, name, typeParameters, type)\n}\n\nexport function createNamespaceDeclaration({\n statements,\n name,\n}: {\n name: string\n statements: ts.Statement[]\n}) {\n return factory.createModuleDeclaration(\n [factory.createToken(ts.SyntaxKind.ExportKeyword)],\n factory.createIdentifier(name),\n factory.createModuleBlock(statements),\n ts.NodeFlags.Namespace,\n )\n}\n\n/**\n * In { propertyName: string; name?: string } is `name` being used to make the type more unique when multiple same names are used.\n * @example `import { Pet as Cat } from './Pet'`\n */\nexport function createImportDeclaration({\n name,\n path,\n isTypeOnly = false,\n isNameSpace = false,\n}: {\n name: string | Array<string | { propertyName: string; name?: string }>\n path: string\n isTypeOnly?: boolean\n isNameSpace?: boolean\n}) {\n if (!Array.isArray(name)) {\n let importPropertyName: ts.Identifier | undefined = factory.createIdentifier(name)\n let importName: ts.NamedImportBindings | undefined = undefined\n\n if (isNameSpace) {\n importPropertyName = undefined\n importName = factory.createNamespaceImport(factory.createIdentifier(name))\n }\n\n return factory.createImportDeclaration(\n undefined,\n factory.createImportClause(isTypeOnly, importPropertyName, importName),\n factory.createStringLiteral(path),\n undefined,\n )\n }\n\n return factory.createImportDeclaration(\n undefined,\n factory.createImportClause(\n isTypeOnly,\n undefined,\n factory.createNamedImports(\n name.map((item) => {\n if (typeof item === 'object') {\n const obj = item as { propertyName: string; name?: string }\n if (obj.name) {\n return factory.createImportSpecifier(false, factory.createIdentifier(obj.propertyName), factory.createIdentifier(obj.name))\n }\n\n return factory.createImportSpecifier(false, undefined, factory.createIdentifier(obj.propertyName))\n }\n\n return factory.createImportSpecifier(false, undefined, factory.createIdentifier(item))\n }),\n ),\n ),\n factory.createStringLiteral(path),\n undefined,\n )\n}\n\nexport function createExportDeclaration({\n path,\n asAlias,\n isTypeOnly = false,\n name,\n}: {\n path: string\n asAlias?: boolean\n isTypeOnly?: boolean\n name?: string | Array<ts.Identifier | string>\n}) {\n if (name && !Array.isArray(name) && !asAlias) {\n console.warn(`When using name as string, asAlias should be true ${name}`)\n }\n\n if (!Array.isArray(name)) {\n const parsedName = name?.match(/^\\d/) ? `_${name?.slice(1)}` : name\n\n return factory.createExportDeclaration(\n undefined,\n isTypeOnly,\n asAlias && parsedName ? factory.createNamespaceExport(factory.createIdentifier(parsedName)) : undefined,\n factory.createStringLiteral(path),\n undefined,\n )\n }\n\n return factory.createExportDeclaration(\n undefined,\n isTypeOnly,\n factory.createNamedExports(\n name.map((propertyName) => {\n return factory.createExportSpecifier(false, undefined, typeof propertyName === 'string' ? factory.createIdentifier(propertyName) : propertyName)\n }),\n ),\n factory.createStringLiteral(path),\n undefined,\n )\n}\n\nexport function createEnumDeclaration({\n type = 'enum',\n name,\n typeName,\n enums,\n}: {\n /**\n * @default `'enum'`\n */\n type?: 'enum' | 'asConst' | 'asPascalConst' | 'constEnum' | 'literal'\n /**\n * Enum name in camelCase.\n */\n name: string\n /**\n * Enum name in PascalCase.\n */\n typeName: string\n enums: [key: string | number, value: string | number | boolean][]\n}): [name: ts.Node | undefined, type: ts.Node] {\n if (type === 'literal') {\n return [\n undefined,\n factory.createTypeAliasDeclaration(\n [factory.createToken(ts.SyntaxKind.ExportKeyword)],\n factory.createIdentifier(typeName),\n undefined,\n factory.createUnionTypeNode(\n enums\n .map(([_key, value]) => {\n if (isNumber(value)) {\n return factory.createLiteralTypeNode(factory.createNumericLiteral(value?.toString()))\n }\n\n if (typeof value === 'boolean') {\n return factory.createLiteralTypeNode(value ? factory.createTrue() : factory.createFalse())\n }\n if (value) {\n return factory.createLiteralTypeNode(factory.createStringLiteral(value.toString()))\n }\n\n return undefined\n })\n .filter(Boolean),\n ),\n ),\n ]\n }\n\n if (type === 'enum' || type === 'constEnum') {\n return [\n undefined,\n factory.createEnumDeclaration(\n [factory.createToken(ts.SyntaxKind.ExportKeyword), type === 'constEnum' ? factory.createToken(ts.SyntaxKind.ConstKeyword) : undefined].filter(Boolean),\n factory.createIdentifier(typeName),\n enums\n .map(([key, value]) => {\n let initializer: ts.Expression = factory.createStringLiteral(value?.toString())\n\n if (isNumber(Number.parseInt(value.toString()))) {\n initializer = factory.createNumericLiteral(value as number)\n }\n if (typeof value === 'boolean') {\n initializer = value ? factory.createTrue() : factory.createFalse()\n }\n\n if (isNumber(Number.parseInt(key.toString()))) {\n return factory.createEnumMember(factory.createStringLiteral(`${typeName}_${key}`), initializer)\n }\n\n if (key) {\n return factory.createEnumMember(factory.createStringLiteral(`${key}`), initializer)\n }\n\n return undefined\n })\n .filter(Boolean),\n ),\n ]\n }\n\n // used when using `as const` instead of an TypeScript enum.\n const identifierName = type === 'asPascalConst' ? typeName : name\n\n return [\n factory.createVariableStatement(\n [factory.createToken(ts.SyntaxKind.ExportKeyword)],\n factory.createVariableDeclarationList(\n [\n factory.createVariableDeclaration(\n factory.createIdentifier(identifierName),\n undefined,\n undefined,\n factory.createAsExpression(\n factory.createObjectLiteralExpression(\n enums\n .map(([key, value]) => {\n let initializer: ts.Expression = factory.createStringLiteral(`${value?.toString()}`)\n\n if (isNumber(value)) {\n // Error: Negative numbers should be created in combination with createPrefixUnaryExpression factory.\n // The method createNumericLiteral only accepts positive numbers\n // or those combined with createPrefixUnaryExpression.\n // Therefore, we need to ensure that the number is not negative.\n if (value < 0) {\n initializer = factory.createPrefixUnaryExpression(ts.SyntaxKind.MinusToken, factory.createNumericLiteral(Math.abs(value)))\n } else {\n initializer = factory.createNumericLiteral(value)\n }\n }\n\n if (typeof value === 'boolean') {\n initializer = value ? factory.createTrue() : factory.createFalse()\n }\n\n if (key) {\n return factory.createPropertyAssignment(factory.createStringLiteral(`${key}`), initializer)\n }\n\n return undefined\n })\n .filter(Boolean),\n true,\n ),\n factory.createTypeReferenceNode(factory.createIdentifier('const'), undefined),\n ),\n ),\n ],\n ts.NodeFlags.Const,\n ),\n ),\n factory.createTypeAliasDeclaration(\n [factory.createToken(ts.SyntaxKind.ExportKeyword)],\n factory.createIdentifier(typeName),\n undefined,\n factory.createIndexedAccessTypeNode(\n factory.createParenthesizedType(factory.createTypeQueryNode(factory.createIdentifier(identifierName), undefined)),\n factory.createTypeOperatorNode(ts.SyntaxKind.KeyOfKeyword, factory.createTypeQueryNode(factory.createIdentifier(identifierName), undefined)),\n ),\n ),\n ]\n}\n\nexport function createOmitDeclaration({\n keys,\n type,\n nonNullable,\n}: {\n keys: Array<string> | string\n type: ts.TypeNode\n nonNullable?: boolean\n}) {\n const node = nonNullable ? factory.createTypeReferenceNode(factory.createIdentifier('NonNullable'), [type]) : type\n\n if (Array.isArray(keys)) {\n return factory.createTypeReferenceNode(factory.createIdentifier('Omit'), [\n node,\n factory.createUnionTypeNode(\n keys.map((key) => {\n return factory.createLiteralTypeNode(factory.createStringLiteral(key))\n }),\n ),\n ])\n }\n\n return factory.createTypeReferenceNode(factory.createIdentifier('Omit'), [node, factory.createLiteralTypeNode(factory.createStringLiteral(keys))])\n}\n\nexport const keywordTypeNodes = {\n any: factory.createKeywordTypeNode(ts.SyntaxKind.AnyKeyword),\n unknown: factory.createKeywordTypeNode(ts.SyntaxKind.UnknownKeyword),\n number: factory.createKeywordTypeNode(ts.SyntaxKind.NumberKeyword),\n integer: factory.createKeywordTypeNode(ts.SyntaxKind.NumberKeyword),\n object: factory.createKeywordTypeNode(ts.SyntaxKind.ObjectKeyword),\n string: factory.createKeywordTypeNode(ts.SyntaxKind.StringKeyword),\n boolean: factory.createKeywordTypeNode(ts.SyntaxKind.BooleanKeyword),\n undefined: factory.createKeywordTypeNode(ts.SyntaxKind.UndefinedKeyword),\n null: factory.createLiteralTypeNode(factory.createToken(ts.SyntaxKind.NullKeyword)),\n} as const\n\nexport const createTypeLiteralNode = factory.createTypeLiteralNode\n\nexport const createTypeReferenceNode = factory.createTypeReferenceNode\nexport const createNumericLiteral = factory.createNumericLiteral\nexport const createStringLiteral = factory.createStringLiteral\n\nexport const createArrayTypeNode = factory.createArrayTypeNode\n\nexport const createLiteralTypeNode = factory.createLiteralTypeNode\nexport const createNull = factory.createNull\nexport const createIdentifier = factory.createIdentifier\n\nexport const createTupleTypeNode = factory.createTupleTypeNode\n"]}
@@ -255,7 +255,7 @@ function createExportDeclaration({
255
255
  name
256
256
  }) {
257
257
  if (name && !Array.isArray(name) && !asAlias) {
258
- throw new Error("When using `name` as string, `asAlias` should be true");
258
+ console.warn(`When using name as string, asAlias should be true ${name}`);
259
259
  }
260
260
  if (!Array.isArray(name)) {
261
261
  const parsedName = name?.match(/^\d/) ? `_${name?.slice(1)}` : name;
@@ -287,6 +287,7 @@ function createEnumDeclaration({
287
287
  }) {
288
288
  if (type === "literal") {
289
289
  return [
290
+ void 0,
290
291
  factory.createTypeAliasDeclaration(
291
292
  [factory.createToken(ts.SyntaxKind.ExportKeyword)],
292
293
  factory.createIdentifier(typeName),
@@ -310,6 +311,7 @@ function createEnumDeclaration({
310
311
  }
311
312
  if (type === "enum" || type === "constEnum") {
312
313
  return [
314
+ void 0,
313
315
  factory.createEnumDeclaration(
314
316
  [factory.createToken(ts.SyntaxKind.ExportKeyword), type === "constEnum" ? factory.createToken(ts.SyntaxKind.ConstKeyword) : void 0].filter(Boolean),
315
317
  factory.createIdentifier(typeName),
@@ -450,4 +452,4 @@ export {
450
452
  createTupleTypeNode,
451
453
  factory_exports
452
454
  };
453
- //# sourceMappingURL=chunk-QHLKNPYD.js.map
455
+ //# sourceMappingURL=chunk-WBLAF6SH.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/factory.ts"],"sourcesContent":["import { isNumber } from 'remeda'\nimport ts from 'typescript'\n\nconst { factory } = ts\n\n// https://ts-ast-viewer.com/\n\nexport const modifiers = {\n async: factory.createModifier(ts.SyntaxKind.AsyncKeyword),\n export: factory.createModifier(ts.SyntaxKind.ExportKeyword),\n const: factory.createModifier(ts.SyntaxKind.ConstKeyword),\n static: factory.createModifier(ts.SyntaxKind.StaticKeyword),\n} as const\n\nfunction isValidIdentifier(str: string): boolean {\n if (!str.length || str.trim() !== str) {\n return false\n }\n const node = ts.parseIsolatedEntityName(str, ts.ScriptTarget.Latest)\n\n return !!node && node.kind === ts.SyntaxKind.Identifier && ts.identifierToKeywordKind(node.kind as unknown as ts.Identifier) === undefined\n}\n\nfunction propertyName(name: string | ts.PropertyName): ts.PropertyName {\n if (typeof name === 'string') {\n return isValidIdentifier(name) ? factory.createIdentifier(name) : factory.createStringLiteral(name)\n }\n return name\n}\n\nconst questionToken = factory.createToken(ts.SyntaxKind.QuestionToken)\n\nexport function createQuestionToken(token?: boolean | ts.QuestionToken) {\n if (!token) {\n return undefined\n }\n if (token === true) {\n return questionToken\n }\n return token\n}\n\nexport function createIntersectionDeclaration({\n nodes,\n withParentheses,\n}: {\n nodes: Array<ts.TypeNode>\n withParentheses?: boolean\n}): ts.TypeNode | null {\n if (!nodes.length) {\n return null\n }\n\n if (nodes.length === 1) {\n return nodes[0] || null\n }\n\n const node = factory.createIntersectionTypeNode(nodes)\n\n if (withParentheses) {\n return factory.createParenthesizedType(node)\n }\n\n return node\n}\n\n/**\n * Minimum nodes length of 2\n * @example `string & number`\n */\nexport function createTupleDeclaration({\n nodes,\n withParentheses,\n}: {\n nodes: Array<ts.TypeNode>\n withParentheses?: boolean\n}): ts.TypeNode | null {\n if (!nodes.length) {\n return null\n }\n\n if (nodes.length === 1) {\n return nodes[0] || null\n }\n\n const node = factory.createTupleTypeNode(nodes)\n\n if (withParentheses) {\n return factory.createParenthesizedType(node)\n }\n\n return node\n}\n\nexport function createArrayDeclaration({\n nodes,\n}: {\n nodes: Array<ts.TypeNode>\n}): ts.TypeNode | null {\n if (!nodes.length) {\n return factory.createTupleTypeNode([])\n }\n\n if (nodes.length === 1) {\n return factory.createArrayTypeNode(nodes.at(0)!)\n }\n\n return factory.createExpressionWithTypeArguments(factory.createIdentifier('Array'), [factory.createUnionTypeNode(nodes)])\n}\n\n/**\n * Minimum nodes length of 2\n * @example `string | number`\n */\nexport function createUnionDeclaration({\n nodes,\n withParentheses,\n}: {\n nodes: Array<ts.TypeNode>\n withParentheses?: boolean\n}): ts.TypeNode | null {\n if (!nodes.length) {\n return null\n }\n\n if (nodes.length === 1) {\n return nodes[0] || null\n }\n\n const node = factory.createUnionTypeNode(nodes)\n\n if (withParentheses) {\n return factory.createParenthesizedType(node)\n }\n\n return node\n}\n\nexport function createPropertySignature({\n readOnly,\n modifiers = [],\n name,\n questionToken,\n type,\n}: {\n readOnly?: boolean\n modifiers?: Array<ts.Modifier>\n name: ts.PropertyName | string\n questionToken?: ts.QuestionToken | boolean\n type?: ts.TypeNode\n}) {\n return factory.createPropertySignature(\n [...modifiers, readOnly ? factory.createToken(ts.SyntaxKind.ReadonlyKeyword) : undefined].filter(Boolean),\n propertyName(name),\n createQuestionToken(questionToken),\n type,\n )\n}\n\nexport function createParameterSignature(\n name: string | ts.BindingName,\n {\n modifiers,\n dotDotDotToken,\n questionToken,\n type,\n initializer,\n }: {\n decorators?: Array<ts.Decorator>\n modifiers?: Array<ts.Modifier>\n dotDotDotToken?: ts.DotDotDotToken\n questionToken?: ts.QuestionToken | boolean\n type?: ts.TypeNode\n initializer?: ts.Expression\n },\n): ts.ParameterDeclaration {\n return factory.createParameterDeclaration(modifiers, dotDotDotToken, name, createQuestionToken(questionToken), type, initializer)\n}\n\nexport function createJSDoc({ comments }: { comments: string[] }) {\n if (!comments.length) {\n return null\n }\n return factory.createJSDocComment(\n factory.createNodeArray(\n comments.map((comment, i) => {\n if (i === comments.length - 1) {\n return factory.createJSDocText(comment)\n }\n\n return factory.createJSDocText(`${comment}\\n`)\n }),\n ),\n )\n}\n\n/**\n * @link https://github.com/microsoft/TypeScript/issues/44151\n */\nexport function appendJSDocToNode<TNode extends ts.Node>({\n node,\n comments,\n}: {\n node: TNode\n comments: Array<string | undefined>\n}) {\n const filteredComments = comments.filter(Boolean)\n\n if (!filteredComments.length) {\n return node\n }\n\n const text = filteredComments.reduce((acc = '', comment = '') => {\n return `${acc}\\n * ${comment}`\n }, '*')\n\n // node: {...node}, with that ts.addSyntheticLeadingComment is appending\n return ts.addSyntheticLeadingComment({ ...node }, ts.SyntaxKind.MultiLineCommentTrivia, `${text || '*'}\\n`, true)\n}\n\nexport function createIndexSignature(\n type: ts.TypeNode,\n {\n modifiers,\n indexName = 'key',\n indexType = factory.createKeywordTypeNode(ts.SyntaxKind.StringKeyword),\n }: {\n indexName?: string\n indexType?: ts.TypeNode\n decorators?: Array<ts.Decorator>\n modifiers?: Array<ts.Modifier>\n } = {},\n) {\n return factory.createIndexSignature(modifiers, [createParameterSignature(indexName, { type: indexType })], type)\n}\n\nexport function createTypeAliasDeclaration({\n modifiers,\n name,\n typeParameters,\n type,\n}: {\n modifiers?: Array<ts.Modifier>\n name: string | ts.Identifier\n typeParameters?: Array<ts.TypeParameterDeclaration>\n type: ts.TypeNode\n}) {\n return factory.createTypeAliasDeclaration(modifiers, name, typeParameters, type)\n}\n\nexport function createNamespaceDeclaration({\n statements,\n name,\n}: {\n name: string\n statements: ts.Statement[]\n}) {\n return factory.createModuleDeclaration(\n [factory.createToken(ts.SyntaxKind.ExportKeyword)],\n factory.createIdentifier(name),\n factory.createModuleBlock(statements),\n ts.NodeFlags.Namespace,\n )\n}\n\n/**\n * In { propertyName: string; name?: string } is `name` being used to make the type more unique when multiple same names are used.\n * @example `import { Pet as Cat } from './Pet'`\n */\nexport function createImportDeclaration({\n name,\n path,\n isTypeOnly = false,\n isNameSpace = false,\n}: {\n name: string | Array<string | { propertyName: string; name?: string }>\n path: string\n isTypeOnly?: boolean\n isNameSpace?: boolean\n}) {\n if (!Array.isArray(name)) {\n let importPropertyName: ts.Identifier | undefined = factory.createIdentifier(name)\n let importName: ts.NamedImportBindings | undefined = undefined\n\n if (isNameSpace) {\n importPropertyName = undefined\n importName = factory.createNamespaceImport(factory.createIdentifier(name))\n }\n\n return factory.createImportDeclaration(\n undefined,\n factory.createImportClause(isTypeOnly, importPropertyName, importName),\n factory.createStringLiteral(path),\n undefined,\n )\n }\n\n return factory.createImportDeclaration(\n undefined,\n factory.createImportClause(\n isTypeOnly,\n undefined,\n factory.createNamedImports(\n name.map((item) => {\n if (typeof item === 'object') {\n const obj = item as { propertyName: string; name?: string }\n if (obj.name) {\n return factory.createImportSpecifier(false, factory.createIdentifier(obj.propertyName), factory.createIdentifier(obj.name))\n }\n\n return factory.createImportSpecifier(false, undefined, factory.createIdentifier(obj.propertyName))\n }\n\n return factory.createImportSpecifier(false, undefined, factory.createIdentifier(item))\n }),\n ),\n ),\n factory.createStringLiteral(path),\n undefined,\n )\n}\n\nexport function createExportDeclaration({\n path,\n asAlias,\n isTypeOnly = false,\n name,\n}: {\n path: string\n asAlias?: boolean\n isTypeOnly?: boolean\n name?: string | Array<ts.Identifier | string>\n}) {\n if (name && !Array.isArray(name) && !asAlias) {\n console.warn(`When using name as string, asAlias should be true ${name}`)\n }\n\n if (!Array.isArray(name)) {\n const parsedName = name?.match(/^\\d/) ? `_${name?.slice(1)}` : name\n\n return factory.createExportDeclaration(\n undefined,\n isTypeOnly,\n asAlias && parsedName ? factory.createNamespaceExport(factory.createIdentifier(parsedName)) : undefined,\n factory.createStringLiteral(path),\n undefined,\n )\n }\n\n return factory.createExportDeclaration(\n undefined,\n isTypeOnly,\n factory.createNamedExports(\n name.map((propertyName) => {\n return factory.createExportSpecifier(false, undefined, typeof propertyName === 'string' ? factory.createIdentifier(propertyName) : propertyName)\n }),\n ),\n factory.createStringLiteral(path),\n undefined,\n )\n}\n\nexport function createEnumDeclaration({\n type = 'enum',\n name,\n typeName,\n enums,\n}: {\n /**\n * @default `'enum'`\n */\n type?: 'enum' | 'asConst' | 'asPascalConst' | 'constEnum' | 'literal'\n /**\n * Enum name in camelCase.\n */\n name: string\n /**\n * Enum name in PascalCase.\n */\n typeName: string\n enums: [key: string | number, value: string | number | boolean][]\n}): [name: ts.Node | undefined, type: ts.Node] {\n if (type === 'literal') {\n return [\n undefined,\n factory.createTypeAliasDeclaration(\n [factory.createToken(ts.SyntaxKind.ExportKeyword)],\n factory.createIdentifier(typeName),\n undefined,\n factory.createUnionTypeNode(\n enums\n .map(([_key, value]) => {\n if (isNumber(value)) {\n return factory.createLiteralTypeNode(factory.createNumericLiteral(value?.toString()))\n }\n\n if (typeof value === 'boolean') {\n return factory.createLiteralTypeNode(value ? factory.createTrue() : factory.createFalse())\n }\n if (value) {\n return factory.createLiteralTypeNode(factory.createStringLiteral(value.toString()))\n }\n\n return undefined\n })\n .filter(Boolean),\n ),\n ),\n ]\n }\n\n if (type === 'enum' || type === 'constEnum') {\n return [\n undefined,\n factory.createEnumDeclaration(\n [factory.createToken(ts.SyntaxKind.ExportKeyword), type === 'constEnum' ? factory.createToken(ts.SyntaxKind.ConstKeyword) : undefined].filter(Boolean),\n factory.createIdentifier(typeName),\n enums\n .map(([key, value]) => {\n let initializer: ts.Expression = factory.createStringLiteral(value?.toString())\n\n if (isNumber(Number.parseInt(value.toString()))) {\n initializer = factory.createNumericLiteral(value as number)\n }\n if (typeof value === 'boolean') {\n initializer = value ? factory.createTrue() : factory.createFalse()\n }\n\n if (isNumber(Number.parseInt(key.toString()))) {\n return factory.createEnumMember(factory.createStringLiteral(`${typeName}_${key}`), initializer)\n }\n\n if (key) {\n return factory.createEnumMember(factory.createStringLiteral(`${key}`), initializer)\n }\n\n return undefined\n })\n .filter(Boolean),\n ),\n ]\n }\n\n // used when using `as const` instead of an TypeScript enum.\n const identifierName = type === 'asPascalConst' ? typeName : name\n\n return [\n factory.createVariableStatement(\n [factory.createToken(ts.SyntaxKind.ExportKeyword)],\n factory.createVariableDeclarationList(\n [\n factory.createVariableDeclaration(\n factory.createIdentifier(identifierName),\n undefined,\n undefined,\n factory.createAsExpression(\n factory.createObjectLiteralExpression(\n enums\n .map(([key, value]) => {\n let initializer: ts.Expression = factory.createStringLiteral(`${value?.toString()}`)\n\n if (isNumber(value)) {\n // Error: Negative numbers should be created in combination with createPrefixUnaryExpression factory.\n // The method createNumericLiteral only accepts positive numbers\n // or those combined with createPrefixUnaryExpression.\n // Therefore, we need to ensure that the number is not negative.\n if (value < 0) {\n initializer = factory.createPrefixUnaryExpression(ts.SyntaxKind.MinusToken, factory.createNumericLiteral(Math.abs(value)))\n } else {\n initializer = factory.createNumericLiteral(value)\n }\n }\n\n if (typeof value === 'boolean') {\n initializer = value ? factory.createTrue() : factory.createFalse()\n }\n\n if (key) {\n return factory.createPropertyAssignment(factory.createStringLiteral(`${key}`), initializer)\n }\n\n return undefined\n })\n .filter(Boolean),\n true,\n ),\n factory.createTypeReferenceNode(factory.createIdentifier('const'), undefined),\n ),\n ),\n ],\n ts.NodeFlags.Const,\n ),\n ),\n factory.createTypeAliasDeclaration(\n [factory.createToken(ts.SyntaxKind.ExportKeyword)],\n factory.createIdentifier(typeName),\n undefined,\n factory.createIndexedAccessTypeNode(\n factory.createParenthesizedType(factory.createTypeQueryNode(factory.createIdentifier(identifierName), undefined)),\n factory.createTypeOperatorNode(ts.SyntaxKind.KeyOfKeyword, factory.createTypeQueryNode(factory.createIdentifier(identifierName), undefined)),\n ),\n ),\n ]\n}\n\nexport function createOmitDeclaration({\n keys,\n type,\n nonNullable,\n}: {\n keys: Array<string> | string\n type: ts.TypeNode\n nonNullable?: boolean\n}) {\n const node = nonNullable ? factory.createTypeReferenceNode(factory.createIdentifier('NonNullable'), [type]) : type\n\n if (Array.isArray(keys)) {\n return factory.createTypeReferenceNode(factory.createIdentifier('Omit'), [\n node,\n factory.createUnionTypeNode(\n keys.map((key) => {\n return factory.createLiteralTypeNode(factory.createStringLiteral(key))\n }),\n ),\n ])\n }\n\n return factory.createTypeReferenceNode(factory.createIdentifier('Omit'), [node, factory.createLiteralTypeNode(factory.createStringLiteral(keys))])\n}\n\nexport const keywordTypeNodes = {\n any: factory.createKeywordTypeNode(ts.SyntaxKind.AnyKeyword),\n unknown: factory.createKeywordTypeNode(ts.SyntaxKind.UnknownKeyword),\n number: factory.createKeywordTypeNode(ts.SyntaxKind.NumberKeyword),\n integer: factory.createKeywordTypeNode(ts.SyntaxKind.NumberKeyword),\n object: factory.createKeywordTypeNode(ts.SyntaxKind.ObjectKeyword),\n string: factory.createKeywordTypeNode(ts.SyntaxKind.StringKeyword),\n boolean: factory.createKeywordTypeNode(ts.SyntaxKind.BooleanKeyword),\n undefined: factory.createKeywordTypeNode(ts.SyntaxKind.UndefinedKeyword),\n null: factory.createLiteralTypeNode(factory.createToken(ts.SyntaxKind.NullKeyword)),\n} as const\n\nexport const createTypeLiteralNode = factory.createTypeLiteralNode\n\nexport const createTypeReferenceNode = factory.createTypeReferenceNode\nexport const createNumericLiteral = factory.createNumericLiteral\nexport const createStringLiteral = factory.createStringLiteral\n\nexport const createArrayTypeNode = factory.createArrayTypeNode\n\nexport const createLiteralTypeNode = factory.createLiteralTypeNode\nexport const createNull = factory.createNull\nexport const createIdentifier = factory.createIdentifier\n\nexport const createTupleTypeNode = factory.createTupleTypeNode\n"],"mappings":";;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,SAAS,gBAAgB;AACzB,OAAO,QAAQ;AAEf,IAAM,EAAE,QAAQ,IAAI;AAIb,IAAM,YAAY;AAAA,EACvB,OAAO,QAAQ,eAAe,GAAG,WAAW,YAAY;AAAA,EACxD,QAAQ,QAAQ,eAAe,GAAG,WAAW,aAAa;AAAA,EAC1D,OAAO,QAAQ,eAAe,GAAG,WAAW,YAAY;AAAA,EACxD,QAAQ,QAAQ,eAAe,GAAG,WAAW,aAAa;AAC5D;AAEA,SAAS,kBAAkB,KAAsB;AAC/C,MAAI,CAAC,IAAI,UAAU,IAAI,KAAK,MAAM,KAAK;AACrC,WAAO;AAAA,EACT;AACA,QAAM,OAAO,GAAG,wBAAwB,KAAK,GAAG,aAAa,MAAM;AAEnE,SAAO,CAAC,CAAC,QAAQ,KAAK,SAAS,GAAG,WAAW,cAAc,GAAG,wBAAwB,KAAK,IAAgC,MAAM;AACnI;AAEA,SAAS,aAAa,MAAiD;AACrE,MAAI,OAAO,SAAS,UAAU;AAC5B,WAAO,kBAAkB,IAAI,IAAI,QAAQ,iBAAiB,IAAI,IAAI,QAAQ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,iBAAiB,MAAM,GAAG,CAAC,MAAM,QAAQ,sBAAsB,QAAQ,oBAAoB,IAAI,CAAC,CAAC,CAAC;AACnJ;AAEO,IAAM,mBAAmB;AAAA,EAC9B,KAAK,QAAQ,sBAAsB,GAAG,WAAW,UAAU;AAAA,EAC3D,SAAS,QAAQ,sBAAsB,GAAG,WAAW,cAAc;AAAA,EACnE,QAAQ,QAAQ,sBAAsB,GAAG,WAAW,aAAa;AAAA,EACjE,SAAS,QAAQ,sBAAsB,GAAG,WAAW,aAAa;AAAA,EAClE,QAAQ,QAAQ,sBAAsB,GAAG,WAAW,aAAa;AAAA,EACjE,QAAQ,QAAQ,sBAAsB,GAAG,WAAW,aAAa;AAAA,EACjE,SAAS,QAAQ,sBAAsB,GAAG,WAAW,cAAc;AAAA,EACnE,WAAW,QAAQ,sBAAsB,GAAG,WAAW,gBAAgB;AAAA,EACvE,MAAM,QAAQ,sBAAsB,QAAQ,YAAY,GAAG,WAAW,WAAW,CAAC;AACpF;AAEO,IAAM,wBAAwB,QAAQ;AAEtC,IAAM,0BAA0B,QAAQ;AACxC,IAAM,uBAAuB,QAAQ;AACrC,IAAM,sBAAsB,QAAQ;AAEpC,IAAM,sBAAsB,QAAQ;AAEpC,IAAM,wBAAwB,QAAQ;AACtC,IAAM,aAAa,QAAQ;AAC3B,IAAM,mBAAmB,QAAQ;AAEjC,IAAM,sBAAsB,QAAQ;","names":["modifiers","questionToken","propertyName"]}
@@ -104,7 +104,7 @@ declare function createEnumDeclaration({ type, name, typeName, enums, }: {
104
104
  */
105
105
  typeName: string;
106
106
  enums: [key: string | number, value: string | number | boolean][];
107
- }): ts.EnumDeclaration[] | (ts.TypeAliasDeclaration | ts.VariableStatement)[];
107
+ }): [name: ts.Node | undefined, type: ts.Node];
108
108
  declare function createOmitDeclaration({ keys, type, nonNullable, }: {
109
109
  keys: Array<string> | string;
110
110
  type: ts.TypeNode;
@@ -104,7 +104,7 @@ declare function createEnumDeclaration({ type, name, typeName, enums, }: {
104
104
  */
105
105
  typeName: string;
106
106
  enums: [key: string | number, value: string | number | boolean][];
107
- }): ts.EnumDeclaration[] | (ts.TypeAliasDeclaration | ts.VariableStatement)[];
107
+ }): [name: ts.Node | undefined, type: ts.Node];
108
108
  declare function createOmitDeclaration({ keys, type, nonNullable, }: {
109
109
  keys: Array<string> | string;
110
110
  type: ts.TypeNode;
package/dist/factory.cjs CHANGED
@@ -26,7 +26,7 @@
26
26
 
27
27
 
28
28
 
29
- var _chunkUQLRYRTMcjs = require('./chunk-UQLRYRTM.cjs');
29
+ var _chunkKWWQXE3Ucjs = require('./chunk-KWWQXE3U.cjs');
30
30
 
31
31
 
32
32
 
@@ -55,5 +55,5 @@ var _chunkUQLRYRTMcjs = require('./chunk-UQLRYRTM.cjs');
55
55
 
56
56
 
57
57
 
58
- exports.appendJSDocToNode = _chunkUQLRYRTMcjs.appendJSDocToNode; exports.createArrayDeclaration = _chunkUQLRYRTMcjs.createArrayDeclaration; exports.createArrayTypeNode = _chunkUQLRYRTMcjs.createArrayTypeNode; exports.createEnumDeclaration = _chunkUQLRYRTMcjs.createEnumDeclaration; exports.createExportDeclaration = _chunkUQLRYRTMcjs.createExportDeclaration; exports.createIdentifier = _chunkUQLRYRTMcjs.createIdentifier; exports.createImportDeclaration = _chunkUQLRYRTMcjs.createImportDeclaration; exports.createIndexSignature = _chunkUQLRYRTMcjs.createIndexSignature; exports.createIntersectionDeclaration = _chunkUQLRYRTMcjs.createIntersectionDeclaration; exports.createJSDoc = _chunkUQLRYRTMcjs.createJSDoc; exports.createLiteralTypeNode = _chunkUQLRYRTMcjs.createLiteralTypeNode; exports.createNamespaceDeclaration = _chunkUQLRYRTMcjs.createNamespaceDeclaration; exports.createNull = _chunkUQLRYRTMcjs.createNull; exports.createNumericLiteral = _chunkUQLRYRTMcjs.createNumericLiteral; exports.createOmitDeclaration = _chunkUQLRYRTMcjs.createOmitDeclaration; exports.createParameterSignature = _chunkUQLRYRTMcjs.createParameterSignature; exports.createPropertySignature = _chunkUQLRYRTMcjs.createPropertySignature; exports.createQuestionToken = _chunkUQLRYRTMcjs.createQuestionToken; exports.createStringLiteral = _chunkUQLRYRTMcjs.createStringLiteral; exports.createTupleDeclaration = _chunkUQLRYRTMcjs.createTupleDeclaration; exports.createTupleTypeNode = _chunkUQLRYRTMcjs.createTupleTypeNode; exports.createTypeAliasDeclaration = _chunkUQLRYRTMcjs.createTypeAliasDeclaration; exports.createTypeLiteralNode = _chunkUQLRYRTMcjs.createTypeLiteralNode; exports.createTypeReferenceNode = _chunkUQLRYRTMcjs.createTypeReferenceNode; exports.createUnionDeclaration = _chunkUQLRYRTMcjs.createUnionDeclaration; exports.keywordTypeNodes = _chunkUQLRYRTMcjs.keywordTypeNodes; exports.modifiers = _chunkUQLRYRTMcjs.modifiers;
58
+ exports.appendJSDocToNode = _chunkKWWQXE3Ucjs.appendJSDocToNode; exports.createArrayDeclaration = _chunkKWWQXE3Ucjs.createArrayDeclaration; exports.createArrayTypeNode = _chunkKWWQXE3Ucjs.createArrayTypeNode; exports.createEnumDeclaration = _chunkKWWQXE3Ucjs.createEnumDeclaration; exports.createExportDeclaration = _chunkKWWQXE3Ucjs.createExportDeclaration; exports.createIdentifier = _chunkKWWQXE3Ucjs.createIdentifier; exports.createImportDeclaration = _chunkKWWQXE3Ucjs.createImportDeclaration; exports.createIndexSignature = _chunkKWWQXE3Ucjs.createIndexSignature; exports.createIntersectionDeclaration = _chunkKWWQXE3Ucjs.createIntersectionDeclaration; exports.createJSDoc = _chunkKWWQXE3Ucjs.createJSDoc; exports.createLiteralTypeNode = _chunkKWWQXE3Ucjs.createLiteralTypeNode; exports.createNamespaceDeclaration = _chunkKWWQXE3Ucjs.createNamespaceDeclaration; exports.createNull = _chunkKWWQXE3Ucjs.createNull; exports.createNumericLiteral = _chunkKWWQXE3Ucjs.createNumericLiteral; exports.createOmitDeclaration = _chunkKWWQXE3Ucjs.createOmitDeclaration; exports.createParameterSignature = _chunkKWWQXE3Ucjs.createParameterSignature; exports.createPropertySignature = _chunkKWWQXE3Ucjs.createPropertySignature; exports.createQuestionToken = _chunkKWWQXE3Ucjs.createQuestionToken; exports.createStringLiteral = _chunkKWWQXE3Ucjs.createStringLiteral; exports.createTupleDeclaration = _chunkKWWQXE3Ucjs.createTupleDeclaration; exports.createTupleTypeNode = _chunkKWWQXE3Ucjs.createTupleTypeNode; exports.createTypeAliasDeclaration = _chunkKWWQXE3Ucjs.createTypeAliasDeclaration; exports.createTypeLiteralNode = _chunkKWWQXE3Ucjs.createTypeLiteralNode; exports.createTypeReferenceNode = _chunkKWWQXE3Ucjs.createTypeReferenceNode; exports.createUnionDeclaration = _chunkKWWQXE3Ucjs.createUnionDeclaration; exports.keywordTypeNodes = _chunkKWWQXE3Ucjs.keywordTypeNodes; exports.modifiers = _chunkKWWQXE3Ucjs.modifiers;
59
59
  //# sourceMappingURL=factory.cjs.map
@@ -1,2 +1,2 @@
1
1
  import 'typescript';
2
- export { j as appendJSDocToNode, d as createArrayDeclaration, x as createArrayTypeNode, q as createEnumDeclaration, p as createExportDeclaration, A as createIdentifier, o as createImportDeclaration, k as createIndexSignature, a as createIntersectionDeclaration, i as createJSDoc, y as createLiteralTypeNode, n as createNamespaceDeclaration, z as createNull, v as createNumericLiteral, r as createOmitDeclaration, h as createParameterSignature, g as createPropertySignature, c as createQuestionToken, w as createStringLiteral, b as createTupleDeclaration, B as createTupleTypeNode, l as createTypeAliasDeclaration, t as createTypeLiteralNode, u as createTypeReferenceNode, e as createUnionDeclaration, s as keywordTypeNodes, m as modifiers } from './factory-Cd7U4lxv.cjs';
2
+ export { j as appendJSDocToNode, d as createArrayDeclaration, x as createArrayTypeNode, q as createEnumDeclaration, p as createExportDeclaration, A as createIdentifier, o as createImportDeclaration, k as createIndexSignature, a as createIntersectionDeclaration, i as createJSDoc, y as createLiteralTypeNode, n as createNamespaceDeclaration, z as createNull, v as createNumericLiteral, r as createOmitDeclaration, h as createParameterSignature, g as createPropertySignature, c as createQuestionToken, w as createStringLiteral, b as createTupleDeclaration, B as createTupleTypeNode, l as createTypeAliasDeclaration, t as createTypeLiteralNode, u as createTypeReferenceNode, e as createUnionDeclaration, s as keywordTypeNodes, m as modifiers } from './factory-CFXA_d49.cjs';
package/dist/factory.d.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  import 'typescript';
2
- export { j as appendJSDocToNode, d as createArrayDeclaration, x as createArrayTypeNode, q as createEnumDeclaration, p as createExportDeclaration, A as createIdentifier, o as createImportDeclaration, k as createIndexSignature, a as createIntersectionDeclaration, i as createJSDoc, y as createLiteralTypeNode, n as createNamespaceDeclaration, z as createNull, v as createNumericLiteral, r as createOmitDeclaration, h as createParameterSignature, g as createPropertySignature, c as createQuestionToken, w as createStringLiteral, b as createTupleDeclaration, B as createTupleTypeNode, l as createTypeAliasDeclaration, t as createTypeLiteralNode, u as createTypeReferenceNode, e as createUnionDeclaration, s as keywordTypeNodes, m as modifiers } from './factory-Cd7U4lxv.js';
2
+ export { j as appendJSDocToNode, d as createArrayDeclaration, x as createArrayTypeNode, q as createEnumDeclaration, p as createExportDeclaration, A as createIdentifier, o as createImportDeclaration, k as createIndexSignature, a as createIntersectionDeclaration, i as createJSDoc, y as createLiteralTypeNode, n as createNamespaceDeclaration, z as createNull, v as createNumericLiteral, r as createOmitDeclaration, h as createParameterSignature, g as createPropertySignature, c as createQuestionToken, w as createStringLiteral, b as createTupleDeclaration, B as createTupleTypeNode, l as createTypeAliasDeclaration, t as createTypeLiteralNode, u as createTypeReferenceNode, e as createUnionDeclaration, s as keywordTypeNodes, m as modifiers } from './factory-CFXA_d49.js';
package/dist/factory.js CHANGED
@@ -26,7 +26,7 @@ import {
26
26
  createUnionDeclaration,
27
27
  keywordTypeNodes,
28
28
  modifiers
29
- } from "./chunk-QHLKNPYD.js";
29
+ } from "./chunk-WBLAF6SH.js";
30
30
  export {
31
31
  appendJSDocToNode,
32
32
  createArrayDeclaration,
package/dist/index.cjs CHANGED
@@ -1,11 +1,11 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
2
2
 
3
- var _chunkUQLRYRTMcjs = require('./chunk-UQLRYRTM.cjs');
3
+ var _chunkKWWQXE3Ucjs = require('./chunk-KWWQXE3U.cjs');
4
4
 
5
5
  // src/api.ts
6
6
  var _path = require('path'); var _path2 = _interopRequireDefault(_path);
7
7
  var _typescript = require('typescript'); var _typescript2 = _interopRequireDefault(_typescript);
8
- function getExports(filePath) {
8
+ function getExports(filePath, source) {
9
9
  const rootName = _path2.default.extname(filePath) ? filePath : `${filePath}.ts`;
10
10
  if (!rootName) {
11
11
  return void 0;
@@ -16,7 +16,7 @@ function getExports(filePath) {
16
16
  });
17
17
  const checker = program.getTypeChecker();
18
18
  const sources = program.getSourceFiles();
19
- const sourceFile = sources.find((sourceFile2) => sourceFile2.fileName === rootName);
19
+ const sourceFile = source ? _typescript2.default.createSourceFile(rootName, source, _typescript2.default.ScriptTarget.ES2022, false, _typescript2.default.ScriptKind.TS) : sources.find((sourceFile2) => sourceFile2.fileName === rootName);
20
20
  if (!sourceFile) {
21
21
  return void 0;
22
22
  }
@@ -73,5 +73,5 @@ function parse(ast) {
73
73
 
74
74
 
75
75
 
76
- exports.factory = _chunkUQLRYRTMcjs.factory_exports; exports.getExports = getExports; exports.parse = parse; exports.print = print;
76
+ exports.factory = _chunkKWWQXE3Ucjs.factory_exports; exports.getExports = getExports; exports.parse = parse; exports.print = print;
77
77
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["/home/runner/work/kubb/kubb/packages/parser-ts/dist/index.cjs","../src/api.ts","../src/print.ts","../src/parse.ts"],"names":["sourceFile","ts"],"mappings":"AAAA;AACE;AACF,wDAA6B;AAC7B;AACA;ACJA,wEAAiB;AAEjB,gGAAe;AAUR,SAAS,UAAA,CAAW,QAAA,EAAoD;AAC7E,EAAA,MAAM,SAAA,EAAW,cAAA,CAAK,OAAA,CAAQ,QAAQ,EAAA,EAAI,SAAA,EAAW,CAAA,EAAA;AAEtC,EAAA;AACN,IAAA;AACT,EAAA;AAEiC,EAAA;AACX,IAAA;AACV,IAAA;AACX,EAAA;AAEsC,EAAA;AACA,EAAA;AACSA,EAAAA;AAE/B,EAAA;AACR,IAAA;AACT,EAAA;AAEqD,EAAA;AAEjC,EAAA;AACX,IAAA;AACT,EAAA;AAEiD,EAAA;AACvB,EAAA;AAEc,IAAA;AAE/B,IAAA;AACwB,MAAA;AACJ,MAAA;AAC3B,IAAA;AACD,EAAA;AACH;ADbwD;AACA;AEpCzC;AAIKC;AAY2C;AAOR;AAI3B;AAEuB,EAAA;AAChB,EAAA;AACR,IAAA;AACvB,IAAA;AACA,IAAA;AACA,IAAA;AACD,EAAA;AAE4B,EAAA;AAEd,EAAA;AACN,IAAA;AACT,EAAA;AAE6B,EAAA;AACI,IAAA;AAC1B,EAAA;AAC4B,IAAA;AACnC,EAAA;AAEmD,EAAA;AACF,EAAA;AAEE,EAAA;AACrD;AFSwD;AACA;AGtDP;AACxC,EAAA;AACL,IAAA;AACe,IAAA;AACjB,EAAA;AACF;AHwDwD;AACA;AACA;AACA;AACA;AACA","file":"/home/runner/work/kubb/kubb/packages/parser-ts/dist/index.cjs","sourcesContent":[null,"import path from 'node:path'\n\nimport ts from 'typescript'\n\ntype ExportsResult = {\n name: string\n isTypeOnly: boolean\n}\n\n/**\n * @link https://github.com/microsoft/TypeScript/issues/15840\n */\nexport function getExports(filePath: string): undefined | Array<ExportsResult> {\n const rootName = path.extname(filePath) ? filePath : `${filePath}.ts`\n\n if (!rootName) {\n return undefined\n }\n\n const program = ts.createProgram({\n rootNames: [rootName],\n options: {},\n })\n\n const checker = program.getTypeChecker()\n const sources = program.getSourceFiles()\n const sourceFile = sources.find((sourceFile) => sourceFile.fileName === rootName)\n\n if (!sourceFile) {\n return undefined\n }\n\n const symbol = checker.getSymbolAtLocation(sourceFile)\n\n if (!symbol?.flags) {\n return undefined\n }\n\n const exports = checker.getExportsOfModule(symbol)\n return exports.map((e) => {\n // 5 is type and 90 is const\n const type = checker.getTypeOfSymbol(e) as unknown as { id?: 5 | 90 }\n\n return {\n name: e.escapedName.toString(),\n isTypeOnly: type?.id === 5,\n }\n })\n}\n","import ts from 'typescript'\n\nimport type { PrinterOptions } from 'typescript'\n\nconst { factory } = ts\n\ntype Options = {\n source?: string\n baseName?: string\n} & PrinterOptions\n\n/**\n * Escaped new lines in code with block comments so they can be restored by {@link restoreNewLines}\n * @param {string} code The code to escape new lines in\n * @returns The same code but with new lines escaped using block comments\n */\nconst escapeNewLines = (code: string) => code.replace(/\\n\\n/g, '\\n/* :newline: */')\n\n/**\n * Reverses {@link escapeNewLines} and restores new lines\n * @param {string} code The code with escaped new lines\n * @returns The same code with new lines restored\n */\nconst restoreNewLines = (code: string) => code.replace(/\\/\\* :newline: \\*\\//g, '\\n')\n\nexport function print(\n elements: ts.Node | Array<ts.Node | undefined> | null,\n { source = '', baseName = 'print.ts', removeComments, noEmitHelpers, newLine = ts.NewLineKind.LineFeed }: Options = {},\n): string {\n const sourceFile = ts.createSourceFile(baseName, escapeNewLines(source), ts.ScriptTarget.ES2022, false, ts.ScriptKind.TS)\n const printer = ts.createPrinter({\n omitTrailingSemicolon: true,\n newLine,\n removeComments,\n noEmitHelpers,\n })\n\n let nodes: Array<ts.Node> = []\n\n if (!elements) {\n return ''\n }\n\n if (Array.isArray(elements)) {\n nodes = elements.filter(Boolean)\n } else {\n nodes = [elements].filter(Boolean)\n }\n\n const outputFile = printer.printList(ts.ListFormat.MultiLine, factory.createNodeArray(nodes), sourceFile)\n const outputSource = printer.printFile(sourceFile)\n\n return [outputFile, restoreNewLines(outputSource)].filter(Boolean).join('\\n')\n}\n","import { print } from './print.ts'\n\nimport type ts from 'typescript'\n\ntype ParseResult = {\n ast: ts.Node\n text: string\n}\n\nexport function parse(ast: ts.Node): ParseResult {\n return {\n ast,\n text: print(ast),\n }\n}\n"]}
1
+ {"version":3,"sources":["/home/runner/work/kubb/kubb/packages/parser-ts/dist/index.cjs","../src/api.ts","../src/print.ts","../src/parse.ts"],"names":["ts"],"mappings":"AAAA;AACE;AACF,wDAA6B;AAC7B;AACA;ACJA,wEAAiB;AAEjB,gGAAe;AAUR,SAAS,UAAA,CAAW,QAAA,EAAkB,MAAA,EAAmD;AAC9F,EAAA,MAAM,SAAA,EAAW,cAAA,CAAK,OAAA,CAAQ,QAAQ,EAAA,EAAI,SAAA,EAAW,CAAA,EAAA;AAEtC,EAAA;AACN,IAAA;AACT,EAAA;AAEiC,EAAA;AACX,IAAA;AACV,IAAA;AACX,EAAA;AAEsC,EAAA;AACA,EAAA;AAEf,EAAA;AAGP,EAAA;AACR,IAAA;AACT,EAAA;AAEqD,EAAA;AAEjC,EAAA;AACX,IAAA;AACT,EAAA;AAEiD,EAAA;AACvB,EAAA;AAEc,IAAA;AAE/B,IAAA;AACwB,MAAA;AACJ,MAAA;AAC3B,IAAA;AACD,EAAA;AACH;ADfwD;AACA;AEpCzC;AAIKA;AAY2C;AAOR;AAI3B;AAEuB,EAAA;AAChB,EAAA;AACR,IAAA;AACvB,IAAA;AACA,IAAA;AACA,IAAA;AACD,EAAA;AAE4B,EAAA;AAEd,EAAA;AACN,IAAA;AACT,EAAA;AAE6B,EAAA;AACI,IAAA;AAC1B,EAAA;AAC4B,IAAA;AACnC,EAAA;AAEmD,EAAA;AACF,EAAA;AAEE,EAAA;AACrD;AFSwD;AACA;AGtDP;AACxC,EAAA;AACL,IAAA;AACe,IAAA;AACjB,EAAA;AACF;AHwDwD;AACA;AACA;AACA;AACA;AACA","file":"/home/runner/work/kubb/kubb/packages/parser-ts/dist/index.cjs","sourcesContent":[null,"import path from 'node:path'\n\nimport ts from 'typescript'\n\ntype ExportsResult = {\n name: string\n isTypeOnly: boolean\n}\n\n/**\n * @link https://github.com/microsoft/TypeScript/issues/15840\n */\nexport function getExports(filePath: string, source?: string): undefined | Array<ExportsResult> {\n const rootName = path.extname(filePath) ? filePath : `${filePath}.ts`\n\n if (!rootName) {\n return undefined\n }\n\n const program = ts.createProgram({\n rootNames: [rootName],\n options: {},\n })\n\n const checker = program.getTypeChecker()\n const sources = program.getSourceFiles()\n const sourceFile = source\n ? ts.createSourceFile(rootName, source, ts.ScriptTarget.ES2022, false, ts.ScriptKind.TS)\n : sources.find((sourceFile) => sourceFile.fileName === rootName)\n\n if (!sourceFile) {\n return undefined\n }\n\n const symbol = checker.getSymbolAtLocation(sourceFile)\n\n if (!symbol?.flags) {\n return undefined\n }\n\n const exports = checker.getExportsOfModule(symbol)\n return exports.map((e) => {\n // 5 is type and 90 is const\n const type = checker.getTypeOfSymbol(e) as unknown as { id?: 5 | 90 }\n\n return {\n name: e.escapedName.toString(),\n isTypeOnly: type?.id === 5,\n }\n })\n}\n","import ts from 'typescript'\n\nimport type { PrinterOptions } from 'typescript'\n\nconst { factory } = ts\n\ntype Options = {\n source?: string\n baseName?: string\n} & PrinterOptions\n\n/**\n * Escaped new lines in code with block comments so they can be restored by {@link restoreNewLines}\n * @param {string} code The code to escape new lines in\n * @returns The same code but with new lines escaped using block comments\n */\nconst escapeNewLines = (code: string) => code.replace(/\\n\\n/g, '\\n/* :newline: */')\n\n/**\n * Reverses {@link escapeNewLines} and restores new lines\n * @param {string} code The code with escaped new lines\n * @returns The same code with new lines restored\n */\nconst restoreNewLines = (code: string) => code.replace(/\\/\\* :newline: \\*\\//g, '\\n')\n\nexport function print(\n elements: ts.Node | Array<ts.Node | undefined> | null,\n { source = '', baseName = 'print.ts', removeComments, noEmitHelpers, newLine = ts.NewLineKind.LineFeed }: Options = {},\n): string {\n const sourceFile = ts.createSourceFile(baseName, escapeNewLines(source), ts.ScriptTarget.ES2022, false, ts.ScriptKind.TS)\n const printer = ts.createPrinter({\n omitTrailingSemicolon: true,\n newLine,\n removeComments,\n noEmitHelpers,\n })\n\n let nodes: Array<ts.Node> = []\n\n if (!elements) {\n return ''\n }\n\n if (Array.isArray(elements)) {\n nodes = elements.filter(Boolean)\n } else {\n nodes = [elements].filter(Boolean)\n }\n\n const outputFile = printer.printList(ts.ListFormat.MultiLine, factory.createNodeArray(nodes), sourceFile)\n const outputSource = printer.printFile(sourceFile)\n\n return [outputFile, restoreNewLines(outputSource)].filter(Boolean).join('\\n')\n}\n","import { print } from './print.ts'\n\nimport type ts from 'typescript'\n\ntype ParseResult = {\n ast: ts.Node\n text: string\n}\n\nexport function parse(ast: ts.Node): ParseResult {\n return {\n ast,\n text: print(ast),\n }\n}\n"]}
package/dist/index.d.cts CHANGED
@@ -1,6 +1,6 @@
1
1
  import ts, { PrinterOptions } from 'typescript';
2
2
  export { default as ts } from 'typescript';
3
- export { f as factory } from './factory-Cd7U4lxv.cjs';
3
+ export { f as factory } from './factory-CFXA_d49.cjs';
4
4
 
5
5
  type ExportsResult = {
6
6
  name: string;
@@ -9,7 +9,7 @@ type ExportsResult = {
9
9
  /**
10
10
  * @link https://github.com/microsoft/TypeScript/issues/15840
11
11
  */
12
- declare function getExports(filePath: string): undefined | Array<ExportsResult>;
12
+ declare function getExports(filePath: string, source?: string): undefined | Array<ExportsResult>;
13
13
 
14
14
  type ParseResult = {
15
15
  ast: ts.Node;
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import ts, { PrinterOptions } from 'typescript';
2
2
  export { default as ts } from 'typescript';
3
- export { f as factory } from './factory-Cd7U4lxv.js';
3
+ export { f as factory } from './factory-CFXA_d49.js';
4
4
 
5
5
  type ExportsResult = {
6
6
  name: string;
@@ -9,7 +9,7 @@ type ExportsResult = {
9
9
  /**
10
10
  * @link https://github.com/microsoft/TypeScript/issues/15840
11
11
  */
12
- declare function getExports(filePath: string): undefined | Array<ExportsResult>;
12
+ declare function getExports(filePath: string, source?: string): undefined | Array<ExportsResult>;
13
13
 
14
14
  type ParseResult = {
15
15
  ast: ts.Node;
package/dist/index.js CHANGED
@@ -1,11 +1,11 @@
1
1
  import {
2
2
  factory_exports
3
- } from "./chunk-QHLKNPYD.js";
3
+ } from "./chunk-WBLAF6SH.js";
4
4
 
5
5
  // src/api.ts
6
6
  import path from "path";
7
7
  import ts from "typescript";
8
- function getExports(filePath) {
8
+ function getExports(filePath, source) {
9
9
  const rootName = path.extname(filePath) ? filePath : `${filePath}.ts`;
10
10
  if (!rootName) {
11
11
  return void 0;
@@ -16,7 +16,7 @@ function getExports(filePath) {
16
16
  });
17
17
  const checker = program.getTypeChecker();
18
18
  const sources = program.getSourceFiles();
19
- const sourceFile = sources.find((sourceFile2) => sourceFile2.fileName === rootName);
19
+ const sourceFile = source ? ts.createSourceFile(rootName, source, ts.ScriptTarget.ES2022, false, ts.ScriptKind.TS) : sources.find((sourceFile2) => sourceFile2.fileName === rootName);
20
20
  if (!sourceFile) {
21
21
  return void 0;
22
22
  }
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/api.ts","../src/print.ts","../src/parse.ts"],"sourcesContent":["import path from 'node:path'\n\nimport ts from 'typescript'\n\ntype ExportsResult = {\n name: string\n isTypeOnly: boolean\n}\n\n/**\n * @link https://github.com/microsoft/TypeScript/issues/15840\n */\nexport function getExports(filePath: string): undefined | Array<ExportsResult> {\n const rootName = path.extname(filePath) ? filePath : `${filePath}.ts`\n\n if (!rootName) {\n return undefined\n }\n\n const program = ts.createProgram({\n rootNames: [rootName],\n options: {},\n })\n\n const checker = program.getTypeChecker()\n const sources = program.getSourceFiles()\n const sourceFile = sources.find((sourceFile) => sourceFile.fileName === rootName)\n\n if (!sourceFile) {\n return undefined\n }\n\n const symbol = checker.getSymbolAtLocation(sourceFile)\n\n if (!symbol?.flags) {\n return undefined\n }\n\n const exports = checker.getExportsOfModule(symbol)\n return exports.map((e) => {\n // 5 is type and 90 is const\n const type = checker.getTypeOfSymbol(e) as unknown as { id?: 5 | 90 }\n\n return {\n name: e.escapedName.toString(),\n isTypeOnly: type?.id === 5,\n }\n })\n}\n","import ts from 'typescript'\n\nimport type { PrinterOptions } from 'typescript'\n\nconst { factory } = ts\n\ntype Options = {\n source?: string\n baseName?: string\n} & PrinterOptions\n\n/**\n * Escaped new lines in code with block comments so they can be restored by {@link restoreNewLines}\n * @param {string} code The code to escape new lines in\n * @returns The same code but with new lines escaped using block comments\n */\nconst escapeNewLines = (code: string) => code.replace(/\\n\\n/g, '\\n/* :newline: */')\n\n/**\n * Reverses {@link escapeNewLines} and restores new lines\n * @param {string} code The code with escaped new lines\n * @returns The same code with new lines restored\n */\nconst restoreNewLines = (code: string) => code.replace(/\\/\\* :newline: \\*\\//g, '\\n')\n\nexport function print(\n elements: ts.Node | Array<ts.Node | undefined> | null,\n { source = '', baseName = 'print.ts', removeComments, noEmitHelpers, newLine = ts.NewLineKind.LineFeed }: Options = {},\n): string {\n const sourceFile = ts.createSourceFile(baseName, escapeNewLines(source), ts.ScriptTarget.ES2022, false, ts.ScriptKind.TS)\n const printer = ts.createPrinter({\n omitTrailingSemicolon: true,\n newLine,\n removeComments,\n noEmitHelpers,\n })\n\n let nodes: Array<ts.Node> = []\n\n if (!elements) {\n return ''\n }\n\n if (Array.isArray(elements)) {\n nodes = elements.filter(Boolean)\n } else {\n nodes = [elements].filter(Boolean)\n }\n\n const outputFile = printer.printList(ts.ListFormat.MultiLine, factory.createNodeArray(nodes), sourceFile)\n const outputSource = printer.printFile(sourceFile)\n\n return [outputFile, restoreNewLines(outputSource)].filter(Boolean).join('\\n')\n}\n","import { print } from './print.ts'\n\nimport type ts from 'typescript'\n\ntype ParseResult = {\n ast: ts.Node\n text: string\n}\n\nexport function parse(ast: ts.Node): ParseResult {\n return {\n ast,\n text: print(ast),\n }\n}\n"],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AAuB;AAAA,IACvB;AAAA,IACA;AAAA,IACA;AAAA,EACF,CAAC;AAED,MAAI,QAAwB,CAAC;AAE7B,MAAI,CAAC,UAAU;AACb,WAAO;AAAA,EACT;AAEA,MAAI,MAAM,QAAQ,QAAQ,GAAG;AAC3B,YAAQ,SAAS,OAAO,OAAO;AAAA,EACjC,OAAO;AACL,YAAQ,CAAC,QAAQ,EAAE,OAAO,OAAO;AAAA,EACnC;AAEA,QAAM,aAAa,QAAQ,UAAUA,IAAG,WAAW,WAAW,QAAQ,gBAAgB,KAAK,GAAG,UAAU;AACxG,QAAM,eAAe,QAAQ,UAAU,UAAU;AAEjD,SAAO,CAAC,YAAY,gBAAgB,YAAY,CAAC,EAAE,OAAO,OAAO,EAAE,KAAK,IAAI;AAC9E;;;AC5CO,SAAS,MAAM,KAA2B;AAC/C,SAAO;AAAA,IACL;AAAA,IACA,MAAM,MAAM,GAAG;AAAA,EACjB;AACF;","names":["sourceFile","ts"]}
1
+ {"version":3,"sources":["../src/api.ts","../src/print.ts","../src/parse.ts"],"sourcesContent":["import path from 'node:path'\n\nimport ts from 'typescript'\n\ntype ExportsResult = {\n name: string\n isTypeOnly: boolean\n}\n\n/**\n * @link https://github.com/microsoft/TypeScript/issues/15840\n */\nexport function getExports(filePath: string, source?: string): undefined | Array<ExportsResult> {\n const rootName = path.extname(filePath) ? filePath : `${filePath}.ts`\n\n if (!rootName) {\n return undefined\n }\n\n const program = ts.createProgram({\n rootNames: [rootName],\n options: {},\n })\n\n const checker = program.getTypeChecker()\n const sources = program.getSourceFiles()\n const sourceFile = source\n ? ts.createSourceFile(rootName, source, ts.ScriptTarget.ES2022, false, ts.ScriptKind.TS)\n : sources.find((sourceFile) => sourceFile.fileName === rootName)\n\n if (!sourceFile) {\n return undefined\n }\n\n const symbol = checker.getSymbolAtLocation(sourceFile)\n\n if (!symbol?.flags) {\n return undefined\n }\n\n const exports = checker.getExportsOfModule(symbol)\n return exports.map((e) => {\n // 5 is type and 90 is const\n const type = checker.getTypeOfSymbol(e) as unknown as { id?: 5 | 90 }\n\n return {\n name: e.escapedName.toString(),\n isTypeOnly: type?.id === 5,\n }\n })\n}\n","import ts from 'typescript'\n\nimport type { PrinterOptions } from 'typescript'\n\nconst { factory } = ts\n\ntype Options = {\n source?: string\n baseName?: string\n} & PrinterOptions\n\n/**\n * Escaped new lines in code with block comments so they can be restored by {@link restoreNewLines}\n * @param {string} code The code to escape new lines in\n * @returns The same code but with new lines escaped using block comments\n */\nconst escapeNewLines = (code: string) => code.replace(/\\n\\n/g, '\\n/* :newline: */')\n\n/**\n * Reverses {@link escapeNewLines} and restores new lines\n * @param {string} code The code with escaped new lines\n * @returns The same code with new lines restored\n */\nconst restoreNewLines = (code: string) => code.replace(/\\/\\* :newline: \\*\\//g, '\\n')\n\nexport function print(\n elements: ts.Node | Array<ts.Node | undefined> | null,\n { source = '', baseName = 'print.ts', removeComments, noEmitHelpers, newLine = ts.NewLineKind.LineFeed }: Options = {},\n): string {\n const sourceFile = ts.createSourceFile(baseName, escapeNewLines(source), ts.ScriptTarget.ES2022, false, ts.ScriptKind.TS)\n const printer = ts.createPrinter({\n omitTrailingSemicolon: true,\n newLine,\n removeComments,\n noEmitHelpers,\n })\n\n let nodes: Array<ts.Node> = []\n\n if (!elements) {\n return ''\n }\n\n if (Array.isArray(elements)) {\n nodes = elements.filter(Boolean)\n } else {\n nodes = [elements].filter(Boolean)\n }\n\n const outputFile = printer.printList(ts.ListFormat.MultiLine, factory.createNodeArray(nodes), sourceFile)\n const outputSource = printer.printFile(sourceFile)\n\n return [outputFile, restoreNewLines(outputSource)].filter(Boolean).join('\\n')\n}\n","import { print } from './print.ts'\n\nimport type ts from 'typescript'\n\ntype ParseResult = {\n ast: ts.Node\n text: string\n}\n\nexport function parse(ast: ts.Node): ParseResult {\n return {\n ast,\n text: print(ast),\n }\n}\n"],"mappings":";;;;;AAAA,OAAO,UAAU;AAEjB,OAAO,QAAQ;AAUR,SAAS,WAAW,UAAkB,QAAmD;A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B,uBAAuB;AAAA,IACvB;AAAA,IACA;AAAA,IACA;AAAA,EACF,CAAC;AAED,MAAI,QAAwB,CAAC;AAE7B,MAAI,CAAC,UAAU;AACb,WAAO;AAAA,EACT;AAEA,MAAI,MAAM,QAAQ,QAAQ,GAAG;AAC3B,YAAQ,SAAS,OAAO,OAAO;AAAA,EACjC,OAAO;AACL,YAAQ,CAAC,QAAQ,EAAE,OAAO,OAAO;AAAA,EACnC;AAEA,QAAM,aAAa,QAAQ,UAAUA,IAAG,WAAW,WAAW,QAAQ,gBAAgB,KAAK,GAAG,UAAU;AACxG,QAAM,eAAe,QAAQ,UAAU,UAAU;AAEjD,SAAO,CAAC,YAAY,gBAAgB,YAAY,CAAC,EAAE,OAAO,OAAO,EAAE,KAAK,IAAI;AAC9E;;;AC5CO,SAAS,MAAM,KAA2B;AAC/C,SAAO;AAAA,IACL;AAAA,IACA,MAAM,MAAM,GAAG;AAAA,EACjB;AACF;","names":["sourceFile","ts"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubb/parser-ts",
3
- "version": "3.0.0-alpha.4",
3
+ "version": "3.0.0-alpha.6",
4
4
  "description": "TypeScript parser",
5
5
  "keywords": [
6
6
  "typescript",
@@ -55,9 +55,9 @@
55
55
  "devDependencies": {
56
56
  "prettier": "^3.3.3",
57
57
  "tsup": "^8.2.4",
58
- "@kubb/config-biome": "3.0.0-alpha.4",
59
- "@kubb/config-ts": "3.0.0-alpha.4",
60
- "@kubb/config-tsup": "3.0.0-alpha.4"
58
+ "@kubb/config-biome": "3.0.0-alpha.6",
59
+ "@kubb/config-ts": "3.0.0-alpha.6",
60
+ "@kubb/config-tsup": "3.0.0-alpha.6"
61
61
  },
62
62
  "engines": {
63
63
  "node": ">=20"
package/src/api.ts CHANGED
@@ -10,7 +10,7 @@ type ExportsResult = {
10
10
  /**
11
11
  * @link https://github.com/microsoft/TypeScript/issues/15840
12
12
  */
13
- export function getExports(filePath: string): undefined | Array<ExportsResult> {
13
+ export function getExports(filePath: string, source?: string): undefined | Array<ExportsResult> {
14
14
  const rootName = path.extname(filePath) ? filePath : `${filePath}.ts`
15
15
 
16
16
  if (!rootName) {
@@ -24,7 +24,9 @@ export function getExports(filePath: string): undefined | Array<ExportsResult> {
24
24
 
25
25
  const checker = program.getTypeChecker()
26
26
  const sources = program.getSourceFiles()
27
- const sourceFile = sources.find((sourceFile) => sourceFile.fileName === rootName)
27
+ const sourceFile = source
28
+ ? ts.createSourceFile(rootName, source, ts.ScriptTarget.ES2022, false, ts.ScriptKind.TS)
29
+ : sources.find((sourceFile) => sourceFile.fileName === rootName)
28
30
 
29
31
  if (!sourceFile) {
30
32
  return undefined
package/src/factory.ts CHANGED
@@ -332,7 +332,7 @@ export function createExportDeclaration({
332
332
  name?: string | Array<ts.Identifier | string>
333
333
  }) {
334
334
  if (name && !Array.isArray(name) && !asAlias) {
335
- throw new Error('When using `name` as string, `asAlias` should be true')
335
+ console.warn(`When using name as string, asAlias should be true ${name}`)
336
336
  }
337
337
 
338
338
  if (!Array.isArray(name)) {
@@ -379,9 +379,10 @@ export function createEnumDeclaration({
379
379
  */
380
380
  typeName: string
381
381
  enums: [key: string | number, value: string | number | boolean][]
382
- }) {
382
+ }): [name: ts.Node | undefined, type: ts.Node] {
383
383
  if (type === 'literal') {
384
384
  return [
385
+ undefined,
385
386
  factory.createTypeAliasDeclaration(
386
387
  [factory.createToken(ts.SyntaxKind.ExportKeyword)],
387
388
  factory.createIdentifier(typeName),
@@ -410,6 +411,7 @@ export function createEnumDeclaration({
410
411
 
411
412
  if (type === 'enum' || type === 'constEnum') {
412
413
  return [
414
+ undefined,
413
415
  factory.createEnumDeclaration(
414
416
  [factory.createToken(ts.SyntaxKind.ExportKeyword), type === 'constEnum' ? factory.createToken(ts.SyntaxKind.ConstKeyword) : undefined].filter(Boolean),
415
417
  factory.createIdentifier(typeName),
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/factory.ts"],"sourcesContent":["import { isNumber } from 'remeda'\nimport ts from 'typescript'\n\nconst { factory } = ts\n\n// https://ts-ast-viewer.com/\n\nexport const modifiers = {\n async: factory.createModifier(ts.SyntaxKind.AsyncKeyword),\n export: factory.createModifier(ts.SyntaxKind.ExportKeyword),\n const: factory.createModifier(ts.SyntaxKind.ConstKeyword),\n static: factory.createModifier(ts.SyntaxKind.StaticKeyword),\n} as const\n\nfunction isValidIdentifier(str: string): boolean {\n if (!str.length || str.trim() !== str) {\n return false\n }\n const node = ts.parseIsolatedEntityName(str, ts.ScriptTarget.Latest)\n\n return !!node && node.kind === ts.SyntaxKind.Identifier && ts.identifierToKeywordKind(node.kind as unknown as ts.Identifier) === undefined\n}\n\nfunction propertyName(name: string | ts.PropertyName): ts.PropertyName {\n if (typeof name === 'string') {\n return isValidIdentifier(name) ? factory.createIdentifier(name) : factory.createStringLiteral(name)\n }\n return name\n}\n\nconst questionToken = factory.createToken(ts.SyntaxKind.QuestionToken)\n\nexport function createQuestionToken(token?: boolean | ts.QuestionToken) {\n if (!token) {\n return undefined\n }\n if (token === true) {\n return questionToken\n }\n return token\n}\n\nexport function createIntersectionDeclaration({\n nodes,\n withParentheses,\n}: {\n nodes: Array<ts.TypeNode>\n withParentheses?: boolean\n}): ts.TypeNode | null {\n if (!nodes.length) {\n return null\n }\n\n if (nodes.length === 1) {\n return nodes[0] || null\n }\n\n const node = factory.createIntersectionTypeNode(nodes)\n\n if (withParentheses) {\n return factory.createParenthesizedType(node)\n }\n\n return node\n}\n\n/**\n * Minimum nodes length of 2\n * @example `string & number`\n */\nexport function createTupleDeclaration({\n nodes,\n withParentheses,\n}: {\n nodes: Array<ts.TypeNode>\n withParentheses?: boolean\n}): ts.TypeNode | null {\n if (!nodes.length) {\n return null\n }\n\n if (nodes.length === 1) {\n return nodes[0] || null\n }\n\n const node = factory.createTupleTypeNode(nodes)\n\n if (withParentheses) {\n return factory.createParenthesizedType(node)\n }\n\n return node\n}\n\nexport function createArrayDeclaration({\n nodes,\n}: {\n nodes: Array<ts.TypeNode>\n}): ts.TypeNode | null {\n if (!nodes.length) {\n return factory.createTupleTypeNode([])\n }\n\n if (nodes.length === 1) {\n return factory.createArrayTypeNode(nodes.at(0)!)\n }\n\n return factory.createExpressionWithTypeArguments(factory.createIdentifier('Array'), [factory.createUnionTypeNode(nodes)])\n}\n\n/**\n * Minimum nodes length of 2\n * @example `string | number`\n */\nexport function createUnionDeclaration({\n nodes,\n withParentheses,\n}: {\n nodes: Array<ts.TypeNode>\n withParentheses?: boolean\n}): ts.TypeNode | null {\n if (!nodes.length) {\n return null\n }\n\n if (nodes.length === 1) {\n return nodes[0] || null\n }\n\n const node = factory.createUnionTypeNode(nodes)\n\n if (withParentheses) {\n return factory.createParenthesizedType(node)\n }\n\n return node\n}\n\nexport function createPropertySignature({\n readOnly,\n modifiers = [],\n name,\n questionToken,\n type,\n}: {\n readOnly?: boolean\n modifiers?: Array<ts.Modifier>\n name: ts.PropertyName | string\n questionToken?: ts.QuestionToken | boolean\n type?: ts.TypeNode\n}) {\n return factory.createPropertySignature(\n [...modifiers, readOnly ? factory.createToken(ts.SyntaxKind.ReadonlyKeyword) : undefined].filter(Boolean),\n propertyName(name),\n createQuestionToken(questionToken),\n type,\n )\n}\n\nexport function createParameterSignature(\n name: string | ts.BindingName,\n {\n modifiers,\n dotDotDotToken,\n questionToken,\n type,\n initializer,\n }: {\n decorators?: Array<ts.Decorator>\n modifiers?: Array<ts.Modifier>\n dotDotDotToken?: ts.DotDotDotToken\n questionToken?: ts.QuestionToken | boolean\n type?: ts.TypeNode\n initializer?: ts.Expression\n },\n): ts.ParameterDeclaration {\n return factory.createParameterDeclaration(modifiers, dotDotDotToken, name, createQuestionToken(questionToken), type, initializer)\n}\n\nexport function createJSDoc({ comments }: { comments: string[] }) {\n if (!comments.length) {\n return null\n }\n return factory.createJSDocComment(\n factory.createNodeArray(\n comments.map((comment, i) => {\n if (i === comments.length - 1) {\n return factory.createJSDocText(comment)\n }\n\n return factory.createJSDocText(`${comment}\\n`)\n }),\n ),\n )\n}\n\n/**\n * @link https://github.com/microsoft/TypeScript/issues/44151\n */\nexport function appendJSDocToNode<TNode extends ts.Node>({\n node,\n comments,\n}: {\n node: TNode\n comments: Array<string | undefined>\n}) {\n const filteredComments = comments.filter(Boolean)\n\n if (!filteredComments.length) {\n return node\n }\n\n const text = filteredComments.reduce((acc = '', comment = '') => {\n return `${acc}\\n * ${comment}`\n }, '*')\n\n // node: {...node}, with that ts.addSyntheticLeadingComment is appending\n return ts.addSyntheticLeadingComment({ ...node }, ts.SyntaxKind.MultiLineCommentTrivia, `${text || '*'}\\n`, true)\n}\n\nexport function createIndexSignature(\n type: ts.TypeNode,\n {\n modifiers,\n indexName = 'key',\n indexType = factory.createKeywordTypeNode(ts.SyntaxKind.StringKeyword),\n }: {\n indexName?: string\n indexType?: ts.TypeNode\n decorators?: Array<ts.Decorator>\n modifiers?: Array<ts.Modifier>\n } = {},\n) {\n return factory.createIndexSignature(modifiers, [createParameterSignature(indexName, { type: indexType })], type)\n}\n\nexport function createTypeAliasDeclaration({\n modifiers,\n name,\n typeParameters,\n type,\n}: {\n modifiers?: Array<ts.Modifier>\n name: string | ts.Identifier\n typeParameters?: Array<ts.TypeParameterDeclaration>\n type: ts.TypeNode\n}) {\n return factory.createTypeAliasDeclaration(modifiers, name, typeParameters, type)\n}\n\nexport function createNamespaceDeclaration({\n statements,\n name,\n}: {\n name: string\n statements: ts.Statement[]\n}) {\n return factory.createModuleDeclaration(\n [factory.createToken(ts.SyntaxKind.ExportKeyword)],\n factory.createIdentifier(name),\n factory.createModuleBlock(statements),\n ts.NodeFlags.Namespace,\n )\n}\n\n/**\n * In { propertyName: string; name?: string } is `name` being used to make the type more unique when multiple same names are used.\n * @example `import { Pet as Cat } from './Pet'`\n */\nexport function createImportDeclaration({\n name,\n path,\n isTypeOnly = false,\n isNameSpace = false,\n}: {\n name: string | Array<string | { propertyName: string; name?: string }>\n path: string\n isTypeOnly?: boolean\n isNameSpace?: boolean\n}) {\n if (!Array.isArray(name)) {\n let importPropertyName: ts.Identifier | undefined = factory.createIdentifier(name)\n let importName: ts.NamedImportBindings | undefined = undefined\n\n if (isNameSpace) {\n importPropertyName = undefined\n importName = factory.createNamespaceImport(factory.createIdentifier(name))\n }\n\n return factory.createImportDeclaration(\n undefined,\n factory.createImportClause(isTypeOnly, importPropertyName, importName),\n factory.createStringLiteral(path),\n undefined,\n )\n }\n\n return factory.createImportDeclaration(\n undefined,\n factory.createImportClause(\n isTypeOnly,\n undefined,\n factory.createNamedImports(\n name.map((item) => {\n if (typeof item === 'object') {\n const obj = item as { propertyName: string; name?: string }\n if (obj.name) {\n return factory.createImportSpecifier(false, factory.createIdentifier(obj.propertyName), factory.createIdentifier(obj.name))\n }\n\n return factory.createImportSpecifier(false, undefined, factory.createIdentifier(obj.propertyName))\n }\n\n return factory.createImportSpecifier(false, undefined, factory.createIdentifier(item))\n }),\n ),\n ),\n factory.createStringLiteral(path),\n undefined,\n )\n}\n\nexport function createExportDeclaration({\n path,\n asAlias,\n isTypeOnly = false,\n name,\n}: {\n path: string\n asAlias?: boolean\n isTypeOnly?: boolean\n name?: string | Array<ts.Identifier | string>\n}) {\n if (name && !Array.isArray(name) && !asAlias) {\n throw new Error('When using `name` as string, `asAlias` should be true')\n }\n\n if (!Array.isArray(name)) {\n const parsedName = name?.match(/^\\d/) ? `_${name?.slice(1)}` : name\n\n return factory.createExportDeclaration(\n undefined,\n isTypeOnly,\n asAlias && parsedName ? factory.createNamespaceExport(factory.createIdentifier(parsedName)) : undefined,\n factory.createStringLiteral(path),\n undefined,\n )\n }\n\n return factory.createExportDeclaration(\n undefined,\n isTypeOnly,\n factory.createNamedExports(\n name.map((propertyName) => {\n return factory.createExportSpecifier(false, undefined, typeof propertyName === 'string' ? factory.createIdentifier(propertyName) : propertyName)\n }),\n ),\n factory.createStringLiteral(path),\n undefined,\n )\n}\n\nexport function createEnumDeclaration({\n type = 'enum',\n name,\n typeName,\n enums,\n}: {\n /**\n * @default `'enum'`\n */\n type?: 'enum' | 'asConst' | 'asPascalConst' | 'constEnum' | 'literal'\n /**\n * Enum name in camelCase.\n */\n name: string\n /**\n * Enum name in PascalCase.\n */\n typeName: string\n enums: [key: string | number, value: string | number | boolean][]\n}) {\n if (type === 'literal') {\n return [\n factory.createTypeAliasDeclaration(\n [factory.createToken(ts.SyntaxKind.ExportKeyword)],\n factory.createIdentifier(typeName),\n undefined,\n factory.createUnionTypeNode(\n enums\n .map(([_key, value]) => {\n if (isNumber(value)) {\n return factory.createLiteralTypeNode(factory.createNumericLiteral(value?.toString()))\n }\n\n if (typeof value === 'boolean') {\n return factory.createLiteralTypeNode(value ? factory.createTrue() : factory.createFalse())\n }\n if (value) {\n return factory.createLiteralTypeNode(factory.createStringLiteral(value.toString()))\n }\n\n return undefined\n })\n .filter(Boolean),\n ),\n ),\n ]\n }\n\n if (type === 'enum' || type === 'constEnum') {\n return [\n factory.createEnumDeclaration(\n [factory.createToken(ts.SyntaxKind.ExportKeyword), type === 'constEnum' ? factory.createToken(ts.SyntaxKind.ConstKeyword) : undefined].filter(Boolean),\n factory.createIdentifier(typeName),\n enums\n .map(([key, value]) => {\n let initializer: ts.Expression = factory.createStringLiteral(value?.toString())\n\n if (isNumber(Number.parseInt(value.toString()))) {\n initializer = factory.createNumericLiteral(value as number)\n }\n if (typeof value === 'boolean') {\n initializer = value ? factory.createTrue() : factory.createFalse()\n }\n\n if (isNumber(Number.parseInt(key.toString()))) {\n return factory.createEnumMember(factory.createStringLiteral(`${typeName}_${key}`), initializer)\n }\n\n if (key) {\n return factory.createEnumMember(factory.createStringLiteral(`${key}`), initializer)\n }\n\n return undefined\n })\n .filter(Boolean),\n ),\n ]\n }\n\n // used when using `as const` instead of an TypeScript enum.\n const identifierName = type === 'asPascalConst' ? typeName : name\n\n return [\n factory.createVariableStatement(\n [factory.createToken(ts.SyntaxKind.ExportKeyword)],\n factory.createVariableDeclarationList(\n [\n factory.createVariableDeclaration(\n factory.createIdentifier(identifierName),\n undefined,\n undefined,\n factory.createAsExpression(\n factory.createObjectLiteralExpression(\n enums\n .map(([key, value]) => {\n let initializer: ts.Expression = factory.createStringLiteral(`${value?.toString()}`)\n\n if (isNumber(value)) {\n // Error: Negative numbers should be created in combination with createPrefixUnaryExpression factory.\n // The method createNumericLiteral only accepts positive numbers\n // or those combined with createPrefixUnaryExpression.\n // Therefore, we need to ensure that the number is not negative.\n if (value < 0) {\n initializer = factory.createPrefixUnaryExpression(ts.SyntaxKind.MinusToken, factory.createNumericLiteral(Math.abs(value)))\n } else {\n initializer = factory.createNumericLiteral(value)\n }\n }\n\n if (typeof value === 'boolean') {\n initializer = value ? factory.createTrue() : factory.createFalse()\n }\n\n if (key) {\n return factory.createPropertyAssignment(factory.createStringLiteral(`${key}`), initializer)\n }\n\n return undefined\n })\n .filter(Boolean),\n true,\n ),\n factory.createTypeReferenceNode(factory.createIdentifier('const'), undefined),\n ),\n ),\n ],\n ts.NodeFlags.Const,\n ),\n ),\n factory.createTypeAliasDeclaration(\n [factory.createToken(ts.SyntaxKind.ExportKeyword)],\n factory.createIdentifier(typeName),\n undefined,\n factory.createIndexedAccessTypeNode(\n factory.createParenthesizedType(factory.createTypeQueryNode(factory.createIdentifier(identifierName), undefined)),\n factory.createTypeOperatorNode(ts.SyntaxKind.KeyOfKeyword, factory.createTypeQueryNode(factory.createIdentifier(identifierName), undefined)),\n ),\n ),\n ]\n}\n\nexport function createOmitDeclaration({\n keys,\n type,\n nonNullable,\n}: {\n keys: Array<string> | string\n type: ts.TypeNode\n nonNullable?: boolean\n}) {\n const node = nonNullable ? factory.createTypeReferenceNode(factory.createIdentifier('NonNullable'), [type]) : type\n\n if (Array.isArray(keys)) {\n return factory.createTypeReferenceNode(factory.createIdentifier('Omit'), [\n node,\n factory.createUnionTypeNode(\n keys.map((key) => {\n return factory.createLiteralTypeNode(factory.createStringLiteral(key))\n }),\n ),\n ])\n }\n\n return factory.createTypeReferenceNode(factory.createIdentifier('Omit'), [node, factory.createLiteralTypeNode(factory.createStringLiteral(keys))])\n}\n\nexport const keywordTypeNodes = {\n any: factory.createKeywordTypeNode(ts.SyntaxKind.AnyKeyword),\n unknown: factory.createKeywordTypeNode(ts.SyntaxKind.UnknownKeyword),\n number: factory.createKeywordTypeNode(ts.SyntaxKind.NumberKeyword),\n integer: factory.createKeywordTypeNode(ts.SyntaxKind.NumberKeyword),\n object: factory.createKeywordTypeNode(ts.SyntaxKind.ObjectKeyword),\n string: factory.createKeywordTypeNode(ts.SyntaxKind.StringKeyword),\n boolean: factory.createKeywordTypeNode(ts.SyntaxKind.BooleanKeyword),\n undefined: factory.createKeywordTypeNode(ts.SyntaxKind.UndefinedKeyword),\n null: factory.createLiteralTypeNode(factory.createToken(ts.SyntaxKind.NullKeyword)),\n} as const\n\nexport const createTypeLiteralNode = factory.createTypeLiteralNode\n\nexport const createTypeReferenceNode = factory.createTypeReferenceNode\nexport const createNumericLiteral = factory.createNumericLiteral\nexport const createStringLiteral = factory.createStringLiteral\n\nexport const createArrayTypeNode = factory.createArrayTypeNode\n\nexport const createLiteralTypeNode = factory.createLiteralTypeNode\nexport const createNull = factory.createNull\nexport const createIdentifier = factory.createIdentifier\n\nexport const createTupleTypeNode = factory.createTupleTypeNode\n"],"mappings":";;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,SAAS,gBAAgB;AACzB,OAAO,QAAQ;AAEf,IAAM,EAAE,QAAQ,IAAI;AAIb,IAAM,YAAY;AAAA,EACvB,OAAO,QAAQ,eAAe,GAAG,WAAW,YAAY;AAAA,EACxD,QAAQ,QAAQ,eAAe,GAAG,WAAW,aAAa;AAAA,EAC1D,OAAO,QAAQ,eAAe,GAAG,WAAW,YAAY;AAAA,EACxD,QAAQ,QAAQ,eAAe,GAAG,WA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AAQ;","names":["modifiers","questionToken","propertyName"]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["/home/runner/work/kubb/kubb/packages/parser-ts/dist/chunk-UQLRYRTM.cjs","../src/factory.ts"],"names":["modifiers","questionToken"],"mappings":"AAAA,irBAAI,UAAU,EAAE,MAAM,CAAC,cAAc;AACrC,IAAI,SAAS,EAAE,CAAC,MAAM,EAAE,GAAG,EAAE,GAAG;AAChC,EAAE,IAAI,CAAC,IAAI,KAAK,GAAG,GAAG;AACtB,IAAI,SAAS,CAAC,MAAM,EAAE,IAAI,EAAE,EAAE,GAAG,EAAE,GAAG,CAAC,IAAI,CAAC,EAAE,UAAU,EAAE,KAAK,CAAC,CAAC;AACjE,CAAC;AACD;AACA;ACNA,IAAA,gBAAA,EAAA,CAAA,CAAA;AAAA,QAAA,CAAA,eAAA,EAAA;AAAA,EAAA,iBAAA,EAAA,CAAA,EAAA,GAAA,iBAAA;AAAA,EAAA,sBAAA,EAAA,CAAA,EAAA,GAAA,sBAAA;AAAA,EAAA,mBAAA,EAAA,CAAA,EAAA,GAAA,mBAAA;AAAA,EAAA,qBAAA,EAAA,CAAA,EAAA,GAAA,qBAAA;AAAA,EAAA,uBAAA,EAAA,CAAA,EAAA,GAAA,uBAAA;AAAA,EAAA,gBAAA,EAAA,CAAA,EAAA,GAAA,gBAAA;AAAA,EAAA,uBAAA,EAAA,CAAA,EAAA,GAAA,uBAAA;AAAA,EAAA,oBAAA,EAAA,CAAA,EAAA,GAAA,oBAAA;AAAA,EAAA,6BAAA,EAAA,CAAA,EAAA,GAAA,6BAAA;AAAA,EAAA,WAAA,EAAA,CAAA,EAAA,GAAA,WAAA;AAAA,EAAA,qBAAA,EAAA,CAAA,EAAA,GAAA,qBAAA;AAAA,EAAA,0BAAA,EAAA,CAAA,EAAA,GAAA,0BAAA;AAAA,EAAA,UAAA,EAAA,CAAA,EAAA,GAAA,UAAA;AAAA,EAAA,oBAAA,EAAA,CAAA,EAAA,GAAA,oBAAA;AAAA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AAA;AACmB,YAAA;AACzB,YAAA;AACA,YAAA;AACQ,YAAA;AACE,cAAA;AAEa,gBAAA;AACkB,kBAAA;AAEZ,kBAAA;AAKJ,oBAAA;AACC,sBAAA;AACT,oBAAA;AACS,sBAAA;AAChB,oBAAA;AACF,kBAAA;AAEqB,kBAAA;AACL,oBAAA;AAChB,kBAAA;AAES,kBAAA;AACQ,oBAAA;AACjB,kBAAA;AAEO,kBAAA;AAEM,gBAAA;AACjB,gBAAA;AACF,cAAA;AACQ,cAAA;AACV,YAAA;AACF,UAAA;AACF,QAAA;AACa,QAAA;AACf,MAAA;AACF,IAAA;AACQ,IAAA;AACkB,MAAA;AACS,MAAA;AACjC,MAAA;AACQ,MAAA;AAC0B,QAAA;AACD,QAAA;AACjC,MAAA;AACF,IAAA;AACF,EAAA;AACF;AAEsC;AACpC,EAAA;AACA,EAAA;AACA,EAAA;AAKC;AACkC,EAAA;AAEV,EAAA;AACR,IAAA;AACb,MAAA;AACQ,MAAA;AACY,QAAA;AACD,UAAA;AAChB,QAAA;AACH,MAAA;AACD,IAAA;AACH,EAAA;AAEe,EAAA;AACjB;AAEgC;AACQ,EAAA;AACrB,EAAA;AACqB,EAAA;AACrB,EAAA;AACqB,EAAA;AACA,EAAA;AACrB,EAAA;AACE,EAAA;AACiB,EAAA;AACtC;AAE6C;AAEE;AACH;AACD;AAEA;AAEE;AACX;AACM;AAEG;ADnIH;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","file":"/home/runner/work/kubb/kubb/packages/parser-ts/dist/chunk-UQLRYRTM.cjs","sourcesContent":[null,"import { isNumber } from 'remeda'\nimport ts from 'typescript'\n\nconst { factory } = ts\n\n// https://ts-ast-viewer.com/\n\nexport const modifiers = {\n async: factory.createModifier(ts.SyntaxKind.AsyncKeyword),\n export: factory.createModifier(ts.SyntaxKind.ExportKeyword),\n const: factory.createModifier(ts.SyntaxKind.ConstKeyword),\n static: factory.createModifier(ts.SyntaxKind.StaticKeyword),\n} as const\n\nfunction isValidIdentifier(str: string): boolean {\n if (!str.length || str.trim() !== str) {\n return false\n }\n const node = ts.parseIsolatedEntityName(str, ts.ScriptTarget.Latest)\n\n return !!node && node.kind === ts.SyntaxKind.Identifier && ts.identifierToKeywordKind(node.kind as unknown as ts.Identifier) === undefined\n}\n\nfunction propertyName(name: string | ts.PropertyName): ts.PropertyName {\n if (typeof name === 'string') {\n return isValidIdentifier(name) ? factory.createIdentifier(name) : factory.createStringLiteral(name)\n }\n return name\n}\n\nconst questionToken = factory.createToken(ts.SyntaxKind.QuestionToken)\n\nexport function createQuestionToken(token?: boolean | ts.QuestionToken) {\n if (!token) {\n return undefined\n }\n if (token === true) {\n return questionToken\n }\n return token\n}\n\nexport function createIntersectionDeclaration({\n nodes,\n withParentheses,\n}: {\n nodes: Array<ts.TypeNode>\n withParentheses?: boolean\n}): ts.TypeNode | null {\n if (!nodes.length) {\n return null\n }\n\n if (nodes.length === 1) {\n return nodes[0] || null\n }\n\n const node = factory.createIntersectionTypeNode(nodes)\n\n if (withParentheses) {\n return factory.createParenthesizedType(node)\n }\n\n return node\n}\n\n/**\n * Minimum nodes length of 2\n * @example `string & number`\n */\nexport function createTupleDeclaration({\n nodes,\n withParentheses,\n}: {\n nodes: Array<ts.TypeNode>\n withParentheses?: boolean\n}): ts.TypeNode | null {\n if (!nodes.length) {\n return null\n }\n\n if (nodes.length === 1) {\n return nodes[0] || null\n }\n\n const node = factory.createTupleTypeNode(nodes)\n\n if (withParentheses) {\n return factory.createParenthesizedType(node)\n }\n\n return node\n}\n\nexport function createArrayDeclaration({\n nodes,\n}: {\n nodes: Array<ts.TypeNode>\n}): ts.TypeNode | null {\n if (!nodes.length) {\n return factory.createTupleTypeNode([])\n }\n\n if (nodes.length === 1) {\n return factory.createArrayTypeNode(nodes.at(0)!)\n }\n\n return factory.createExpressionWithTypeArguments(factory.createIdentifier('Array'), [factory.createUnionTypeNode(nodes)])\n}\n\n/**\n * Minimum nodes length of 2\n * @example `string | number`\n */\nexport function createUnionDeclaration({\n nodes,\n withParentheses,\n}: {\n nodes: Array<ts.TypeNode>\n withParentheses?: boolean\n}): ts.TypeNode | null {\n if (!nodes.length) {\n return null\n }\n\n if (nodes.length === 1) {\n return nodes[0] || null\n }\n\n const node = factory.createUnionTypeNode(nodes)\n\n if (withParentheses) {\n return factory.createParenthesizedType(node)\n }\n\n return node\n}\n\nexport function createPropertySignature({\n readOnly,\n modifiers = [],\n name,\n questionToken,\n type,\n}: {\n readOnly?: boolean\n modifiers?: Array<ts.Modifier>\n name: ts.PropertyName | string\n questionToken?: ts.QuestionToken | boolean\n type?: ts.TypeNode\n}) {\n return factory.createPropertySignature(\n [...modifiers, readOnly ? factory.createToken(ts.SyntaxKind.ReadonlyKeyword) : undefined].filter(Boolean),\n propertyName(name),\n createQuestionToken(questionToken),\n type,\n )\n}\n\nexport function createParameterSignature(\n name: string | ts.BindingName,\n {\n modifiers,\n dotDotDotToken,\n questionToken,\n type,\n initializer,\n }: {\n decorators?: Array<ts.Decorator>\n modifiers?: Array<ts.Modifier>\n dotDotDotToken?: ts.DotDotDotToken\n questionToken?: ts.QuestionToken | boolean\n type?: ts.TypeNode\n initializer?: ts.Expression\n },\n): ts.ParameterDeclaration {\n return factory.createParameterDeclaration(modifiers, dotDotDotToken, name, createQuestionToken(questionToken), type, initializer)\n}\n\nexport function createJSDoc({ comments }: { comments: string[] }) {\n if (!comments.length) {\n return null\n }\n return factory.createJSDocComment(\n factory.createNodeArray(\n comments.map((comment, i) => {\n if (i === comments.length - 1) {\n return factory.createJSDocText(comment)\n }\n\n return factory.createJSDocText(`${comment}\\n`)\n }),\n ),\n )\n}\n\n/**\n * @link https://github.com/microsoft/TypeScript/issues/44151\n */\nexport function appendJSDocToNode<TNode extends ts.Node>({\n node,\n comments,\n}: {\n node: TNode\n comments: Array<string | undefined>\n}) {\n const filteredComments = comments.filter(Boolean)\n\n if (!filteredComments.length) {\n return node\n }\n\n const text = filteredComments.reduce((acc = '', comment = '') => {\n return `${acc}\\n * ${comment}`\n }, '*')\n\n // node: {...node}, with that ts.addSyntheticLeadingComment is appending\n return ts.addSyntheticLeadingComment({ ...node }, ts.SyntaxKind.MultiLineCommentTrivia, `${text || '*'}\\n`, true)\n}\n\nexport function createIndexSignature(\n type: ts.TypeNode,\n {\n modifiers,\n indexName = 'key',\n indexType = factory.createKeywordTypeNode(ts.SyntaxKind.StringKeyword),\n }: {\n indexName?: string\n indexType?: ts.TypeNode\n decorators?: Array<ts.Decorator>\n modifiers?: Array<ts.Modifier>\n } = {},\n) {\n return factory.createIndexSignature(modifiers, [createParameterSignature(indexName, { type: indexType })], type)\n}\n\nexport function createTypeAliasDeclaration({\n modifiers,\n name,\n typeParameters,\n type,\n}: {\n modifiers?: Array<ts.Modifier>\n name: string | ts.Identifier\n typeParameters?: Array<ts.TypeParameterDeclaration>\n type: ts.TypeNode\n}) {\n return factory.createTypeAliasDeclaration(modifiers, name, typeParameters, type)\n}\n\nexport function createNamespaceDeclaration({\n statements,\n name,\n}: {\n name: string\n statements: ts.Statement[]\n}) {\n return factory.createModuleDeclaration(\n [factory.createToken(ts.SyntaxKind.ExportKeyword)],\n factory.createIdentifier(name),\n factory.createModuleBlock(statements),\n ts.NodeFlags.Namespace,\n )\n}\n\n/**\n * In { propertyName: string; name?: string } is `name` being used to make the type more unique when multiple same names are used.\n * @example `import { Pet as Cat } from './Pet'`\n */\nexport function createImportDeclaration({\n name,\n path,\n isTypeOnly = false,\n isNameSpace = false,\n}: {\n name: string | Array<string | { propertyName: string; name?: string }>\n path: string\n isTypeOnly?: boolean\n isNameSpace?: boolean\n}) {\n if (!Array.isArray(name)) {\n let importPropertyName: ts.Identifier | undefined = factory.createIdentifier(name)\n let importName: ts.NamedImportBindings | undefined = undefined\n\n if (isNameSpace) {\n importPropertyName = undefined\n importName = factory.createNamespaceImport(factory.createIdentifier(name))\n }\n\n return factory.createImportDeclaration(\n undefined,\n factory.createImportClause(isTypeOnly, importPropertyName, importName),\n factory.createStringLiteral(path),\n undefined,\n )\n }\n\n return factory.createImportDeclaration(\n undefined,\n factory.createImportClause(\n isTypeOnly,\n undefined,\n factory.createNamedImports(\n name.map((item) => {\n if (typeof item === 'object') {\n const obj = item as { propertyName: string; name?: string }\n if (obj.name) {\n return factory.createImportSpecifier(false, factory.createIdentifier(obj.propertyName), factory.createIdentifier(obj.name))\n }\n\n return factory.createImportSpecifier(false, undefined, factory.createIdentifier(obj.propertyName))\n }\n\n return factory.createImportSpecifier(false, undefined, factory.createIdentifier(item))\n }),\n ),\n ),\n factory.createStringLiteral(path),\n undefined,\n )\n}\n\nexport function createExportDeclaration({\n path,\n asAlias,\n isTypeOnly = false,\n name,\n}: {\n path: string\n asAlias?: boolean\n isTypeOnly?: boolean\n name?: string | Array<ts.Identifier | string>\n}) {\n if (name && !Array.isArray(name) && !asAlias) {\n throw new Error('When using `name` as string, `asAlias` should be true')\n }\n\n if (!Array.isArray(name)) {\n const parsedName = name?.match(/^\\d/) ? `_${name?.slice(1)}` : name\n\n return factory.createExportDeclaration(\n undefined,\n isTypeOnly,\n asAlias && parsedName ? factory.createNamespaceExport(factory.createIdentifier(parsedName)) : undefined,\n factory.createStringLiteral(path),\n undefined,\n )\n }\n\n return factory.createExportDeclaration(\n undefined,\n isTypeOnly,\n factory.createNamedExports(\n name.map((propertyName) => {\n return factory.createExportSpecifier(false, undefined, typeof propertyName === 'string' ? factory.createIdentifier(propertyName) : propertyName)\n }),\n ),\n factory.createStringLiteral(path),\n undefined,\n )\n}\n\nexport function createEnumDeclaration({\n type = 'enum',\n name,\n typeName,\n enums,\n}: {\n /**\n * @default `'enum'`\n */\n type?: 'enum' | 'asConst' | 'asPascalConst' | 'constEnum' | 'literal'\n /**\n * Enum name in camelCase.\n */\n name: string\n /**\n * Enum name in PascalCase.\n */\n typeName: string\n enums: [key: string | number, value: string | number | boolean][]\n}) {\n if (type === 'literal') {\n return [\n factory.createTypeAliasDeclaration(\n [factory.createToken(ts.SyntaxKind.ExportKeyword)],\n factory.createIdentifier(typeName),\n undefined,\n factory.createUnionTypeNode(\n enums\n .map(([_key, value]) => {\n if (isNumber(value)) {\n return factory.createLiteralTypeNode(factory.createNumericLiteral(value?.toString()))\n }\n\n if (typeof value === 'boolean') {\n return factory.createLiteralTypeNode(value ? factory.createTrue() : factory.createFalse())\n }\n if (value) {\n return factory.createLiteralTypeNode(factory.createStringLiteral(value.toString()))\n }\n\n return undefined\n })\n .filter(Boolean),\n ),\n ),\n ]\n }\n\n if (type === 'enum' || type === 'constEnum') {\n return [\n factory.createEnumDeclaration(\n [factory.createToken(ts.SyntaxKind.ExportKeyword), type === 'constEnum' ? factory.createToken(ts.SyntaxKind.ConstKeyword) : undefined].filter(Boolean),\n factory.createIdentifier(typeName),\n enums\n .map(([key, value]) => {\n let initializer: ts.Expression = factory.createStringLiteral(value?.toString())\n\n if (isNumber(Number.parseInt(value.toString()))) {\n initializer = factory.createNumericLiteral(value as number)\n }\n if (typeof value === 'boolean') {\n initializer = value ? factory.createTrue() : factory.createFalse()\n }\n\n if (isNumber(Number.parseInt(key.toString()))) {\n return factory.createEnumMember(factory.createStringLiteral(`${typeName}_${key}`), initializer)\n }\n\n if (key) {\n return factory.createEnumMember(factory.createStringLiteral(`${key}`), initializer)\n }\n\n return undefined\n })\n .filter(Boolean),\n ),\n ]\n }\n\n // used when using `as const` instead of an TypeScript enum.\n const identifierName = type === 'asPascalConst' ? typeName : name\n\n return [\n factory.createVariableStatement(\n [factory.createToken(ts.SyntaxKind.ExportKeyword)],\n factory.createVariableDeclarationList(\n [\n factory.createVariableDeclaration(\n factory.createIdentifier(identifierName),\n undefined,\n undefined,\n factory.createAsExpression(\n factory.createObjectLiteralExpression(\n enums\n .map(([key, value]) => {\n let initializer: ts.Expression = factory.createStringLiteral(`${value?.toString()}`)\n\n if (isNumber(value)) {\n // Error: Negative numbers should be created in combination with createPrefixUnaryExpression factory.\n // The method createNumericLiteral only accepts positive numbers\n // or those combined with createPrefixUnaryExpression.\n // Therefore, we need to ensure that the number is not negative.\n if (value < 0) {\n initializer = factory.createPrefixUnaryExpression(ts.SyntaxKind.MinusToken, factory.createNumericLiteral(Math.abs(value)))\n } else {\n initializer = factory.createNumericLiteral(value)\n }\n }\n\n if (typeof value === 'boolean') {\n initializer = value ? factory.createTrue() : factory.createFalse()\n }\n\n if (key) {\n return factory.createPropertyAssignment(factory.createStringLiteral(`${key}`), initializer)\n }\n\n return undefined\n })\n .filter(Boolean),\n true,\n ),\n factory.createTypeReferenceNode(factory.createIdentifier('const'), undefined),\n ),\n ),\n ],\n ts.NodeFlags.Const,\n ),\n ),\n factory.createTypeAliasDeclaration(\n [factory.createToken(ts.SyntaxKind.ExportKeyword)],\n factory.createIdentifier(typeName),\n undefined,\n factory.createIndexedAccessTypeNode(\n factory.createParenthesizedType(factory.createTypeQueryNode(factory.createIdentifier(identifierName), undefined)),\n factory.createTypeOperatorNode(ts.SyntaxKind.KeyOfKeyword, factory.createTypeQueryNode(factory.createIdentifier(identifierName), undefined)),\n ),\n ),\n ]\n}\n\nexport function createOmitDeclaration({\n keys,\n type,\n nonNullable,\n}: {\n keys: Array<string> | string\n type: ts.TypeNode\n nonNullable?: boolean\n}) {\n const node = nonNullable ? factory.createTypeReferenceNode(factory.createIdentifier('NonNullable'), [type]) : type\n\n if (Array.isArray(keys)) {\n return factory.createTypeReferenceNode(factory.createIdentifier('Omit'), [\n node,\n factory.createUnionTypeNode(\n keys.map((key) => {\n return factory.createLiteralTypeNode(factory.createStringLiteral(key))\n }),\n ),\n ])\n }\n\n return factory.createTypeReferenceNode(factory.createIdentifier('Omit'), [node, factory.createLiteralTypeNode(factory.createStringLiteral(keys))])\n}\n\nexport const keywordTypeNodes = {\n any: factory.createKeywordTypeNode(ts.SyntaxKind.AnyKeyword),\n unknown: factory.createKeywordTypeNode(ts.SyntaxKind.UnknownKeyword),\n number: factory.createKeywordTypeNode(ts.SyntaxKind.NumberKeyword),\n integer: factory.createKeywordTypeNode(ts.SyntaxKind.NumberKeyword),\n object: factory.createKeywordTypeNode(ts.SyntaxKind.ObjectKeyword),\n string: factory.createKeywordTypeNode(ts.SyntaxKind.StringKeyword),\n boolean: factory.createKeywordTypeNode(ts.SyntaxKind.BooleanKeyword),\n undefined: factory.createKeywordTypeNode(ts.SyntaxKind.UndefinedKeyword),\n null: factory.createLiteralTypeNode(factory.createToken(ts.SyntaxKind.NullKeyword)),\n} as const\n\nexport const createTypeLiteralNode = factory.createTypeLiteralNode\n\nexport const createTypeReferenceNode = factory.createTypeReferenceNode\nexport const createNumericLiteral = factory.createNumericLiteral\nexport const createStringLiteral = factory.createStringLiteral\n\nexport const createArrayTypeNode = factory.createArrayTypeNode\n\nexport const createLiteralTypeNode = factory.createLiteralTypeNode\nexport const createNull = factory.createNull\nexport const createIdentifier = factory.createIdentifier\n\nexport const createTupleTypeNode = factory.createTupleTypeNode\n"]}