@kubb/parser-ts
Advanced tools
Comparing version 0.0.0-canary-20240806053140 to 0.0.0-canary-20241104172400
import 'typescript'; | ||
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'; | ||
export { j as appendJSDocToNode, d as createArrayDeclaration, x as createArrayTypeNode, q as createEnumDeclaration, p as createExportDeclaration, D as createFalse, 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, C as createTrue, 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-1NIBrzkm.js'; |
@@ -1,59 +0,3 @@ | ||
import { | ||
appendJSDocToNode, | ||
createArrayDeclaration, | ||
createArrayTypeNode, | ||
createEnumDeclaration, | ||
createExportDeclaration, | ||
createIdentifier, | ||
createImportDeclaration, | ||
createIndexSignature, | ||
createIntersectionDeclaration, | ||
createJSDoc, | ||
createLiteralTypeNode, | ||
createNamespaceDeclaration, | ||
createNull, | ||
createNumericLiteral, | ||
createOmitDeclaration, | ||
createParameterSignature, | ||
createPropertySignature, | ||
createQuestionToken, | ||
createStringLiteral, | ||
createTupleDeclaration, | ||
createTupleTypeNode, | ||
createTypeAliasDeclaration, | ||
createTypeLiteralNode, | ||
createTypeReferenceNode, | ||
createUnionDeclaration, | ||
keywordTypeNodes, | ||
modifiers | ||
} from "./chunk-QHLKNPYD.js"; | ||
export { | ||
appendJSDocToNode, | ||
createArrayDeclaration, | ||
createArrayTypeNode, | ||
createEnumDeclaration, | ||
createExportDeclaration, | ||
createIdentifier, | ||
createImportDeclaration, | ||
createIndexSignature, | ||
createIntersectionDeclaration, | ||
createJSDoc, | ||
createLiteralTypeNode, | ||
createNamespaceDeclaration, | ||
createNull, | ||
createNumericLiteral, | ||
createOmitDeclaration, | ||
createParameterSignature, | ||
createPropertySignature, | ||
createQuestionToken, | ||
createStringLiteral, | ||
createTupleDeclaration, | ||
createTupleTypeNode, | ||
createTypeAliasDeclaration, | ||
createTypeLiteralNode, | ||
createTypeReferenceNode, | ||
createUnionDeclaration, | ||
keywordTypeNodes, | ||
modifiers | ||
}; | ||
export { appendJSDocToNode, createArrayDeclaration, createArrayTypeNode, createEnumDeclaration, createExportDeclaration, createFalse, createIdentifier, createImportDeclaration, createIndexSignature, createIntersectionDeclaration, createJSDoc, createLiteralTypeNode, createNamespaceDeclaration, createNull, createNumericLiteral, createOmitDeclaration, createParameterSignature, createPropertySignature, createQuestionToken, createStringLiteral, createTrue, createTupleDeclaration, createTupleTypeNode, createTypeAliasDeclaration, createTypeLiteralNode, createTypeReferenceNode, createUnionDeclaration, keywordTypeNodes, modifiers } from './chunk-RWXGFVS2.js'; | ||
//# sourceMappingURL=factory.js.map | ||
//# sourceMappingURL=factory.js.map |
import ts, { PrinterOptions } from 'typescript'; | ||
export { default as ts } from 'typescript'; | ||
export { f as factory } from './factory-Cd7U4lxv.js'; | ||
export { f as factory } from './factory-1NIBrzkm.js'; | ||
type ExportsResult = { | ||
name: string; | ||
isTypeOnly: boolean; | ||
}; | ||
/** | ||
* @link https://github.com/microsoft/TypeScript/issues/15840 | ||
*/ | ||
declare function getExports(filePath: string): undefined | Array<ExportsResult>; | ||
type ParseResult = { | ||
ast: ts.Node; | ||
text: string; | ||
}; | ||
declare function parse(ast: ts.Node): ParseResult; | ||
type Options = { | ||
@@ -24,4 +8,12 @@ source?: string; | ||
} & PrinterOptions; | ||
declare function print(elements: ts.Node | Array<ts.Node | undefined> | null, { source, baseName, removeComments, noEmitHelpers, newLine }?: Options): string; | ||
/** | ||
* Convert AST TypeScript nodes to a string based on the TypeScript printer. | ||
*/ | ||
declare function print(elements: Array<ts.Node>, { source, baseName, removeComments, noEmitHelpers, newLine }?: Options): string; | ||
export { getExports, parse, print }; | ||
/** | ||
* Format the generated code based on the TypeScript printer. | ||
*/ | ||
declare function format(source: string): string; | ||
export { format, print }; |
@@ -1,45 +0,10 @@ | ||
import { | ||
factory_exports | ||
} from "./chunk-QHLKNPYD.js"; | ||
export { factory_exports as factory } from './chunk-RWXGFVS2.js'; | ||
import ts from 'typescript'; | ||
// src/api.ts | ||
import path from "path"; | ||
import ts from "typescript"; | ||
function getExports(filePath) { | ||
const rootName = path.extname(filePath) ? filePath : `${filePath}.ts`; | ||
if (!rootName) { | ||
return void 0; | ||
} | ||
const program = ts.createProgram({ | ||
rootNames: [rootName], | ||
options: {} | ||
}); | ||
const checker = program.getTypeChecker(); | ||
const sources = program.getSourceFiles(); | ||
const sourceFile = sources.find((sourceFile2) => sourceFile2.fileName === rootName); | ||
if (!sourceFile) { | ||
return void 0; | ||
} | ||
const symbol = checker.getSymbolAtLocation(sourceFile); | ||
if (!symbol?.flags) { | ||
return void 0; | ||
} | ||
const exports = checker.getExportsOfModule(symbol); | ||
return exports.map((e) => { | ||
const type = checker.getTypeOfSymbol(e); | ||
return { | ||
name: e.escapedName.toString(), | ||
isTypeOnly: type?.id === 5 | ||
}; | ||
}); | ||
} | ||
// src/print.ts | ||
import ts2 from "typescript"; | ||
var { factory } = ts2; | ||
var { factory } = ts; | ||
var escapeNewLines = (code) => code.replace(/\n\n/g, "\n/* :newline: */"); | ||
var restoreNewLines = (code) => code.replace(/\/\* :newline: \*\//g, "\n"); | ||
function print(elements, { source = "", baseName = "print.ts", removeComments, noEmitHelpers, newLine = ts2.NewLineKind.LineFeed } = {}) { | ||
const sourceFile = ts2.createSourceFile(baseName, escapeNewLines(source), ts2.ScriptTarget.ES2022, false, ts2.ScriptKind.TS); | ||
const printer = ts2.createPrinter({ | ||
function print(elements, { source = "", baseName = "print.ts", removeComments, noEmitHelpers, newLine = ts.NewLineKind.LineFeed } = {}) { | ||
const sourceFile = ts.createSourceFile(baseName, escapeNewLines(source), ts.ScriptTarget.ES2022, false, ts.ScriptKind.TS); | ||
const printer = ts.createPrinter({ | ||
omitTrailingSemicolon: true, | ||
@@ -59,3 +24,3 @@ newLine, | ||
} | ||
const outputFile = printer.printList(ts2.ListFormat.MultiLine, factory.createNodeArray(nodes), sourceFile); | ||
const outputFile = printer.printList(ts.ListFormat.MultiLine, factory.createNodeArray(nodes), sourceFile); | ||
const outputSource = printer.printFile(sourceFile); | ||
@@ -65,15 +30,9 @@ return [outputFile, restoreNewLines(outputSource)].filter(Boolean).join("\n"); | ||
// src/parse.ts | ||
function parse(ast) { | ||
return { | ||
ast, | ||
text: print(ast) | ||
}; | ||
// src/format.ts | ||
function format(source) { | ||
return print([], { source, noEmitHelpers: false }); | ||
} | ||
export { | ||
factory_exports as factory, | ||
getExports, | ||
parse, | ||
}; | ||
export { format, print }; | ||
//# sourceMappingURL=index.js.map | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@kubb/parser-ts", | ||
"version": "0.0.0-canary-20240806053140", | ||
"version": "0.0.0-canary-20241104172400", | ||
"description": "TypeScript parser", | ||
@@ -51,15 +51,12 @@ "keywords": [ | ||
"dependencies": { | ||
"remeda": "^2.7.1", | ||
"ts-morph": "^23.0.0", | ||
"typescript": "^5.5.4" | ||
"remeda": "^2.16.0", | ||
"typescript": "^5.6.3" | ||
}, | ||
"devDependencies": { | ||
"prettier": "^3.3.3", | ||
"tsup": "^8.2.4", | ||
"@kubb/config-biome": "0.0.0-canary-20240806053140", | ||
"@kubb/config-ts": "0.0.0-canary-20240806053140", | ||
"@kubb/config-tsup": "0.0.0-canary-20240806053140" | ||
"tsup": "^8.3.5", | ||
"@kubb/config-ts": "0.0.0-canary-20241104172400", | ||
"@kubb/config-tsup": "0.0.0-canary-20241104172400" | ||
}, | ||
"engines": { | ||
"node": ">=18" | ||
"node": ">=20" | ||
}, | ||
@@ -66,0 +63,0 @@ "publishConfig": { |
@@ -16,8 +16,4 @@ <div align="center"> | ||
<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section --> | ||
<!-- ALL-CONTRIBUTORS-BADGE:END --> | ||
</p> | ||
<h4> | ||
<a href="https://codesandbox.io/s/github/kubb-labs/kubb/tree/alpha/examples/typescript" target="_blank">View Demo</a> | ||
<a href="https://codesandbox.io/s/github/kubb-labs/kubb/tree/main//examples/typescript" target="_blank">View Demo</a> | ||
<span> · </span> | ||
@@ -31,2 +27,15 @@ <a href="https://kubb.dev/" target="_blank">Documentation</a> | ||
</div> | ||
## Supporting Kubb | ||
Kubb uses an MIT-licensed open source project with its ongoing development made possible entirely by the support of Sponsors. If you would like to become a sponsor, please consider: | ||
- [Become a Sponsor on GitHub](https://github.com/sponsors/stijnvanhulle) | ||
<p align="center"> | ||
<a href="https://github.com/sponsors/stijnvanhulle"> | ||
<img src="https://raw.githubusercontent.com/stijnvanhulle/sponsors/main/sponsors.svg" alt="My sponsors" /> | ||
</a> | ||
</p> | ||
<!-- Badges --> | ||
@@ -33,0 +42,0 @@ |
@@ -121,9 +121,9 @@ import { isNumber } from 'remeda' | ||
withParentheses?: boolean | ||
}): ts.TypeNode | null { | ||
}): ts.TypeNode { | ||
if (!nodes.length) { | ||
return null | ||
return keywordTypeNodes.any | ||
} | ||
if (nodes.length === 1) { | ||
return nodes[0] || null | ||
return nodes[0] as ts.TypeNode | ||
} | ||
@@ -215,3 +215,3 @@ | ||
const text = filteredComments.reduce((acc = '', comment = '') => { | ||
return `${acc}\n * ${comment}` | ||
return `${acc}\n * ${comment.replaceAll('*/', '*\\/')}` | ||
}, '*') | ||
@@ -337,3 +337,3 @@ | ||
if (name && !Array.isArray(name) && !asAlias) { | ||
throw new Error('When using `name` as string, `asAlias` should be true') | ||
console.warn(`When using name as string, asAlias should be true ${name}`) | ||
} | ||
@@ -385,5 +385,6 @@ | ||
enums: [key: string | number, value: string | number | boolean][] | ||
}) { | ||
}): [name: ts.Node | undefined, type: ts.Node] { | ||
if (type === 'literal') { | ||
return [ | ||
undefined, | ||
factory.createTypeAliasDeclaration( | ||
@@ -417,2 +418,3 @@ [factory.createToken(ts.SyntaxKind.ExportKeyword)], | ||
return [ | ||
undefined, | ||
factory.createEnumDeclaration( | ||
@@ -498,3 +500,3 @@ [factory.createToken(ts.SyntaxKind.ExportKeyword), type === 'constEnum' ? factory.createToken(ts.SyntaxKind.ConstKeyword) : undefined].filter(Boolean), | ||
factory.createTypeAliasDeclaration( | ||
[factory.createToken(ts.SyntaxKind.ExportKeyword)], | ||
type === 'asPascalConst' ? [] : [factory.createToken(ts.SyntaxKind.ExportKeyword)], | ||
factory.createIdentifier(typeName), | ||
@@ -560,1 +562,3 @@ undefined, | ||
export const createTupleTypeNode = factory.createTupleTypeNode | ||
export const createTrue = factory.createTrue | ||
export const createFalse = factory.createFalse |
@@ -1,5 +0,3 @@ | ||
export { getExports } from './api.ts' | ||
export { parse } from './parse.ts' | ||
export { print } from './print.ts' | ||
export type { default as ts } from 'typescript' | ||
export { format } from './format.ts' | ||
export * as factory from './factory.ts' |
@@ -26,4 +26,7 @@ import ts from 'typescript' | ||
/** | ||
* Convert AST TypeScript nodes to a string based on the TypeScript printer. | ||
*/ | ||
export function print( | ||
elements: ts.Node | Array<ts.Node | undefined> | null, | ||
elements: Array<ts.Node>, | ||
{ source = '', baseName = 'print.ts', removeComments, noEmitHelpers, newLine = ts.NewLineKind.LineFeed }: Options = {}, | ||
@@ -30,0 +33,0 @@ ): string { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
155296
2
3
53
25
1821
1
- Removedts-morph@^23.0.0
- Removed@nodelib/fs.scandir@2.1.5(transitive)
- Removed@nodelib/fs.stat@2.0.5(transitive)
- Removed@nodelib/fs.walk@1.2.8(transitive)
- Removed@ts-morph/common@0.24.0(transitive)
- Removedbalanced-match@1.0.2(transitive)
- Removedbrace-expansion@2.0.1(transitive)
- Removedbraces@3.0.3(transitive)
- Removedcode-block-writer@13.0.3(transitive)
- Removedfast-glob@3.3.3(transitive)
- Removedfastq@1.18.0(transitive)
- Removedfill-range@7.1.1(transitive)
- Removedglob-parent@5.1.2(transitive)
- Removedis-extglob@2.1.1(transitive)
- Removedis-glob@4.0.3(transitive)
- Removedis-number@7.0.0(transitive)
- Removedmerge2@1.4.1(transitive)
- Removedmicromatch@4.0.8(transitive)
- Removedminimatch@9.0.5(transitive)
- Removedmkdirp@3.0.1(transitive)
- Removedpath-browserify@1.0.1(transitive)
- Removedpicomatch@2.3.1(transitive)
- Removedqueue-microtask@1.2.3(transitive)
- Removedreusify@1.0.4(transitive)
- Removedrun-parallel@1.2.0(transitive)
- Removedto-regex-range@5.0.1(transitive)
- Removedts-morph@23.0.0(transitive)
Updatedremeda@^2.16.0
Updatedtypescript@^5.6.3