fix(cli): extra line break in the tail of dts file (#2255)

This commit is contained in:
LongYinan 2024-09-15 11:44:29 +08:00 committed by GitHub
parent 1427ddce64
commit 20b9de3ec7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
10 changed files with 33 additions and 33 deletions

View File

@ -614,7 +614,6 @@ Generated by [AVA](https://avajs.dev).
export function xxh128(input: Buffer): bigint␊
export function xxh3_64(input: Buffer): bigint␊
}␊
`
## should process type def with noConstEnum correctly
@ -1169,5 +1168,4 @@ Generated by [AVA](https://avajs.dev).
export function xxh128(input: Buffer): bigint␊
export function xxh3_64(input: Buffer): bigint␊
}␊
`

View File

@ -92,39 +92,43 @@ export async function processTypeDef(
const groupedDefs = preprocessTypeDef(defs)
header = header ?? ''
let dts = ''
sortBy(Array.from(groupedDefs), ([namespace]) => namespace).forEach(
([namespace, defs]) => {
if (namespace === TOP_LEVEL_NAMESPACE) {
for (const def of defs) {
dts += prettyPrint(def, constEnum, 0) + '\n\n'
switch (def.kind) {
case TypeDefKind.Const:
case TypeDefKind.Enum:
case TypeDefKind.StringEnum:
case TypeDefKind.Fn:
case TypeDefKind.Struct: {
exports.push(def.name)
if (def.original_name && def.original_name !== def.name) {
exports.push(def.original_name)
const dts =
sortBy(Array.from(groupedDefs), ([namespace]) => namespace)
.map(([namespace, defs]) => {
if (namespace === TOP_LEVEL_NAMESPACE) {
return defs
.map((def) => {
switch (def.kind) {
case TypeDefKind.Const:
case TypeDefKind.Enum:
case TypeDefKind.StringEnum:
case TypeDefKind.Fn:
case TypeDefKind.Struct: {
exports.push(def.name)
if (def.original_name && def.original_name !== def.name) {
exports.push(def.original_name)
}
break
}
default:
break
}
break
}
default:
break
return prettyPrint(def, constEnum, 0)
})
.join('\n\n')
} else {
exports.push(namespace)
let declaration = ''
declaration += `export declare namespace ${namespace} {\n`
for (const def of defs) {
declaration += prettyPrint(def, constEnum, 2, true) + '\n'
}
declaration += '}'
return declaration
}
} else {
exports.push(namespace)
dts += `export declare namespace ${namespace} {\n`
for (const def of defs) {
dts += prettyPrint(def, constEnum, 2, true) + '\n'
}
dts += '}\n\n'
}
},
)
})
.join('\n\n') + '\n'
if (dts.indexOf('ExternalObject<') > -1) {
header += `

View File

@ -854,5 +854,4 @@ Generated by [AVA](https://avajs.dev).
export function xxh128(input: Buffer): bigint␊
export function xxh3_64(input: Buffer): bigint␊
}␊
`

View File

@ -844,4 +844,3 @@ export declare namespace xxh3 {
export function xxh128(input: Buffer): bigint
export function xxh3_64(input: Buffer): bigint
}