ReviewOS

also looking at this

stacks/dtsx

fix(emit): keep a */ in a default value from closing its JSDoc

#3118
Open mkantautas wants to merge fix/defaultvalue-comment-close into main
3 files +38 -2
8 days ago

Summary

A default value holding */ closes the generated @defaultValue comment early, so the .d.ts does not parse. Globs are the usual case:

export const entry = ['src/**/*.ts']

emits

/** @defaultValue `['src/**/*.ts']` */
export declare const entry: string[];

which ends at **/, leaving *.ts'] ... as code. The same happens for export let close = '*/', a property default inside a let object ({ pattern: '**/*.ts' }), a default merged into the user's own JSDoc, and the multi-line fenced form. Running dtsx over knip's source, 52 of its plugin files come out unparsable for this reason alone.

Changes

escapeCommentEnd writes */ as *\/, the escape TypeDoc documents for comments. It is applied where the generated text enters a comment: once to the declaration-level tag in processVariableDeclaration (after all of its builders, before it is merged or written out), and to the per-property @defaultValue in inferObjectType. Text that is already escaped is left alone.

The Zig port writes the same unescaped text and is not changed here. I can send that as a follow-up.

Testing

New cases in test/declaration-emission.test.ts under "*/ inside a generated @defaultValue" run the output through Bun.Transpiler, as the file's other cases do. All 6 fail on main, for example Thrown value: 1 | /** @defaultValue `['src/**/*.ts']` */ with error: Unexpected *, and error: Unterminated string literal for the '*/' string. All pass with the fix.

bun test (Zig library built with the pinned Zig, so its tests run too), typecheck, lint, zig build test and the Zig fixture tests pass. Over 4,192 files from vue-core, vue-router, pinia and knip, unparsable outputs go from 82 to 30: the 52 knip files are fixed, none breaks, and every changed line is a */ becoming *\/.

3 changed files on the files tab, with 0 review threads.

Sign in to comment on this pull request.