Skip to content

Commit b3e430d

Browse files
committed
fix: comment generation
1 parent 6c85c0c commit b3e430d

File tree

4 files changed

+155
-1
lines changed

4 files changed

+155
-1
lines changed

packages/dtsx/src/processor.ts

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1394,10 +1394,34 @@ function parseObjectProperties(content: string): Array<[string, string]> {
13941394
let inString = false
13951395
let stringChar = ''
13961396
let inKey = true
1397+
let inComment = false
1398+
let commentDepth = 0
13971399

13981400
for (let i = 0; i < content.length; i++) {
13991401
const char = content[i]
14001402
const prevChar = i > 0 ? content[i - 1] : ''
1403+
const nextChar = i < content.length - 1 ? content[i + 1] : ''
1404+
1405+
// Track JSDoc/block comments to avoid parsing colons inside them
1406+
if (!inString && !inComment && char === '/' && nextChar === '*') {
1407+
inComment = true
1408+
commentDepth = 1
1409+
current += char
1410+
continue
1411+
}
1412+
else if (inComment && char === '*' && nextChar === '/') {
1413+
commentDepth--
1414+
if (commentDepth === 0) {
1415+
inComment = false
1416+
}
1417+
current += char
1418+
continue
1419+
}
1420+
else if (inComment && char === '/' && nextChar === '*') {
1421+
commentDepth++
1422+
current += char
1423+
continue
1424+
}
14011425

14021426
if (!inString && (char === '"' || char === '\'' || char === '`')) {
14031427
inString = true
@@ -1408,7 +1432,7 @@ function parseObjectProperties(content: string): Array<[string, string]> {
14081432
inString = false
14091433
current += char
14101434
}
1411-
else if (!inString) {
1435+
else if (!inString && !inComment) {
14121436
if (char === '{' || char === '[' || char === '(') {
14131437
depth++
14141438
current += char

packages/dtsx/test/dts.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ describe('dts-generation', () => {
2727

2828
// List of all fixture files to test (excluding checker.ts which is too large)
2929
const fixtures = [
30+
'abseil.io',
3031
'class',
3132
'edge-cases',
3233
'enum',
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/**
2+
* **abseil.io** - Abseil Common Libraries (C++)
3+
*
4+
* @domain `abseil.io`
5+
* @version `20250512.0.0` (17 versions available)
6+
* @versions From newest version to oldest. @see https://ts-pkgx.netlify.app/packages/abseil-io.md
7+
*
8+
* @install `sh <(curl https://pkgx.sh) +abseil.io -- $SHELL -i`
9+
*
10+
* @example
11+
* ```typescript
12+
* import { pantry } from 'ts-pkgx'
13+
*
14+
* const pkg = pantry.abseilio
15+
* console.log(pkg.name) // "abseil.io"
16+
* console.log(pkg.description) // "Abseil Common Libraries (C++)"
17+
* console.log(pkg.versions[0]) // "20250512.0.0" (latest)
18+
* ```
19+
*
20+
* @see https://ts-pkgx.netlify.app/packages/abseil-io.md
21+
* @see https://ts-pkgx.netlify.app/usage
22+
*/
23+
export const abseilioPackage = {
24+
/**
25+
* The display name of this package.
26+
*/
27+
name: 'abseil.io' as const,
28+
/**
29+
* The canonical domain name for this package.
30+
*/
31+
domain: 'abseil.io' as const,
32+
/**
33+
* Brief description of what this package does.
34+
*/
35+
description: 'Abseil Common Libraries (C++)' as const,
36+
packageYmlUrl: 'https://github.com/pkgxdev/pantry/tree/main/projects/abseil.io/package.yml' as const,
37+
homepageUrl: '' as const,
38+
githubUrl: 'https://github.com/pkgxdev/pantry/' as const,
39+
/**
40+
* Command to install this package using pkgx.
41+
* @example sh <(curl https://pkgx.sh) +package-name
42+
*/
43+
installCommand: 'sh <(curl https://pkgx.sh) +abseil.io -- $SHELL -i' as const,
44+
programs: [] as const,
45+
companions: [] as const,
46+
dependencies: [] as const,
47+
/**
48+
* Available versions from newest to oldest.
49+
* @see https://ts-pkgx.netlify.app/usage for installation instructions
50+
*/
51+
versions: [
52+
'20250512.0.0',
53+
'20250127.1.0',
54+
'20250127.0.0',
55+
'20240722.1.0',
56+
'20240722.0.0',
57+
'20240116.3.0',
58+
'20240116.2.0',
59+
'20240116.1.0',
60+
'20240116.0.0',
61+
'20230802.3.0',
62+
'20230802.2.0',
63+
'20230802.1.0',
64+
'20230802.0.0',
65+
'20230125.4.0',
66+
'20230125.3.0',
67+
'20230125.2.0',
68+
'20220623.2.0',
69+
] as const,
70+
aliases: [] as const,
71+
fullPath: 'abseil.io' as const,
72+
}
73+
74+
export type AbseilioPackage = typeof abseilioPackage
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/**
2+
* **abseil.io** - Abseil Common Libraries (C++)
3+
*
4+
* @domain `abseil.io`
5+
* @version `20250512.0.0` (17 versions available)
6+
* @versions From newest version to oldest. @see https://ts-pkgx.netlify.app/packages/abseil-io.md
7+
*
8+
* @install `sh <(curl https://pkgx.sh) +abseil.io -- $SHELL -i`
9+
*
10+
* @example
11+
* ```typescript
12+
* import { pantry } from 'ts-pkgx'
13+
*
14+
* const pkg = pantry.abseilio
15+
* console.log(pkg.name) // "abseil.io"
16+
* console.log(pkg.description) // "Abseil Common Libraries (C++)"
17+
* console.log(pkg.versions[0]) // "20250512.0.0" (latest)
18+
* ```
19+
*
20+
* @see https://ts-pkgx.netlify.app/packages/abseil-io.md
21+
* @see https://ts-pkgx.netlify.app/usage
22+
*/
23+
export declare const abseilioPackage: {
24+
/**
25+
* The display name of this package.
26+
*/
27+
name: 'abseil.io';
28+
/**
29+
* The canonical domain name for this package.
30+
*/
31+
domain: 'abseil.io';
32+
/**
33+
* Brief description of what this package does.
34+
*/
35+
description: 'Abseil Common Libraries (C++)';
36+
packageYmlUrl: 'https://github.com/pkgxdev/pantry/tree/main/projects/abseil.io/package.yml';
37+
homepageUrl: '';
38+
githubUrl: 'https://github.com/pkgxdev/pantry/';
39+
/**
40+
* Command to install this package using pkgx.
41+
* @example sh <(curl https://pkgx.sh) +package-name
42+
*/
43+
installCommand: 'sh <(curl https://pkgx.sh) +abseil.io -- $SHELL -i';
44+
programs: readonly [];
45+
companions: readonly [];
46+
dependencies: readonly [];
47+
/**
48+
* Available versions from newest to oldest.
49+
* @see https://ts-pkgx.netlify.app/usage for installation instructions
50+
*/
51+
versions: readonly ['20250512.0.0', '20250127.1.0', '20250127.0.0', '20240722.1.0', '20240722.0.0', '20240116.3.0', '20240116.2.0', '20240116.1.0', '20240116.0.0', '20230802.3.0', '20230802.2.0', '20230802.1.0', '20230802.0.0', '20230125.4.0', '20230125.3.0', '20230125.2.0', '20220623.2.0'];
52+
aliases: readonly [];
53+
fullPath: 'abseil.io'
54+
};
55+
export type AbseilioPackage = typeof abseilioPackage

0 commit comments

Comments
 (0)