From 079b5d1d58dc6397c603867eb590285a6a044376 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Fri, 21 Jun 2024 08:20:28 -0700 Subject: [PATCH] 5.5 (#80) * support 5.5 * add jsdoc-import test * use import comments * update * remove * install 5.5.2 * try this i guess? * or this? * fix * fix test * skipLibCheck * export types * make types.d.ts a module * export namespace * apply workaround from https://github.com/microsoft/TypeScript/issues/58368 --- .github/workflows/ci.yml | 2 +- package.json | 6 +- pnpm-lock.yaml | 293 ++++++++++-------- src/create-module-declaration.js | 47 ++- src/types.d.ts | 8 +- src/utils.js | 9 +- test/samples/basic/output 5.5/index.d.ts | 2 +- test/samples/basic/output 5.5/index.d.ts.map | 2 +- test/samples/jsdoc-import/input/index.js | 14 + test/samples/jsdoc-import/input/vector.d.ts | 7 + .../jsdoc-import/output 5.5/index.d.ts | 19 ++ .../jsdoc-import/output 5.5/index.d.ts.map | 17 + test/samples/jsdoc-import/output/index.d.ts | 13 + .../jsdoc-import/output/index.d.ts.map | 14 + test/test.js | 2 +- tsconfig.json | 1 + 16 files changed, 287 insertions(+), 169 deletions(-) create mode 100644 test/samples/jsdoc-import/input/index.js create mode 100644 test/samples/jsdoc-import/input/vector.d.ts create mode 100644 test/samples/jsdoc-import/output 5.5/index.d.ts create mode 100644 test/samples/jsdoc-import/output 5.5/index.d.ts.map create mode 100644 test/samples/jsdoc-import/output/index.d.ts create mode 100644 test/samples/jsdoc-import/output/index.d.ts.map diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ab94023..af930e9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -18,7 +18,7 @@ jobs: steps: - run: git config --global core.autocrlf false - uses: actions/checkout@v4 - - uses: pnpm/action-setup@v2.2.2 + - uses: pnpm/action-setup@v4 - uses: actions/setup-node@v3 with: node-version: 18 diff --git a/package.json b/package.json index ddc5275..5079559 100644 --- a/package.json +++ b/package.json @@ -20,7 +20,7 @@ "ts-api-utils": "^1.0.3" }, "peerDependencies": { - "typescript": ">=5.0.4 <5.5" + "typescript": ">=5.0.4 <5.6" }, "devDependencies": { "@types/globrex": "^0.1.2", @@ -28,7 +28,7 @@ "@types/semver": "^7.5.3", "prettier": "^3.0.3", "semver": "^7.5.4", - "typescript": "~5.4.2", + "typescript": "~5.5.2", "uvu": "^0.5.6" }, "scripts": { @@ -50,5 +50,5 @@ "types" ], "bin": "./src/cli.js", - "packageManager": "pnpm@8.8.0" + "packageManager": "pnpm@9.4.0" } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 5a446ac..fe5215d 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1,214 +1,249 @@ -lockfileVersion: '6.0' +lockfileVersion: '9.0' settings: autoInstallPeers: true excludeLinksFromLockfile: false -dependencies: - '@jridgewell/source-map': - specifier: ^0.3.5 - version: 0.3.5 - '@jridgewell/sourcemap-codec': - specifier: ^1.4.15 - version: 1.4.15 - globrex: - specifier: ^0.1.2 - version: 0.1.2 - kleur: - specifier: ^4.1.5 - version: 4.1.5 - locate-character: - specifier: ^3.0.0 - version: 3.0.0 - magic-string: - specifier: ^0.30.4 - version: 0.30.5 - sade: - specifier: ^1.8.1 - version: 1.8.1 - tiny-glob: - specifier: ^0.2.9 - version: 0.2.9 - ts-api-utils: - specifier: ^1.0.3 - version: 1.0.3(typescript@5.4.2) - -devDependencies: - '@types/globrex': - specifier: ^0.1.2 - version: 0.1.2 - '@types/node': - specifier: ^20.7.2 - version: 20.8.6 - '@types/semver': - specifier: ^7.5.3 - version: 7.5.3 - prettier: - specifier: ^3.0.3 - version: 3.0.3 - semver: - specifier: ^7.5.4 - version: 7.5.4 - typescript: - specifier: ~5.4.2 - version: 5.4.2 - uvu: - specifier: ^0.5.6 - version: 0.5.6 +importers: + + .: + dependencies: + '@jridgewell/source-map': + specifier: ^0.3.5 + version: 0.3.5 + '@jridgewell/sourcemap-codec': + specifier: ^1.4.15 + version: 1.4.15 + globrex: + specifier: ^0.1.2 + version: 0.1.2 + kleur: + specifier: ^4.1.5 + version: 4.1.5 + locate-character: + specifier: ^3.0.0 + version: 3.0.0 + magic-string: + specifier: ^0.30.4 + version: 0.30.5 + sade: + specifier: ^1.8.1 + version: 1.8.1 + tiny-glob: + specifier: ^0.2.9 + version: 0.2.9 + ts-api-utils: + specifier: ^1.0.3 + version: 1.0.3(typescript@5.5.2) + devDependencies: + '@types/globrex': + specifier: ^0.1.2 + version: 0.1.2 + '@types/node': + specifier: ^20.7.2 + version: 20.8.6 + '@types/semver': + specifier: ^7.5.3 + version: 7.5.3 + prettier: + specifier: ^3.0.3 + version: 3.0.3 + semver: + specifier: ^7.5.4 + version: 7.5.4 + typescript: + specifier: ~5.5.2 + version: 5.5.2 + uvu: + specifier: ^0.5.6 + version: 0.5.6 packages: - /@jridgewell/gen-mapping@0.3.3: + '@jridgewell/gen-mapping@0.3.3': resolution: {integrity: sha512-HLhSWOLRi875zjjMG/r+Nv0oCW8umGb0BgEhyX3dDX3egwZtB8PqLnjz3yedt8R5StBrzcg4aBpnh8UA9D1BoQ==} engines: {node: '>=6.0.0'} - dependencies: - '@jridgewell/set-array': 1.1.2 - '@jridgewell/sourcemap-codec': 1.4.15 - '@jridgewell/trace-mapping': 0.3.19 - dev: false - /@jridgewell/resolve-uri@3.1.1: + '@jridgewell/resolve-uri@3.1.1': resolution: {integrity: sha512-dSYZh7HhCDtCKm4QakX0xFpsRDqjjtZf/kjI/v3T3Nwt5r8/qz/M19F9ySyOqU94SXBmeG9ttTul+YnR4LOxFA==} engines: {node: '>=6.0.0'} - dev: false - /@jridgewell/set-array@1.1.2: + '@jridgewell/set-array@1.1.2': resolution: {integrity: sha512-xnkseuNADM0gt2bs+BvhO0p78Mk762YnZdsuzFV018NoG1Sj1SCQvpSqa7XUaTam5vAGasABV9qXASMKnFMwMw==} engines: {node: '>=6.0.0'} - dev: false - /@jridgewell/source-map@0.3.5: + '@jridgewell/source-map@0.3.5': resolution: {integrity: sha512-UTYAUj/wviwdsMfzoSJspJxbkH5o1snzwX0//0ENX1u/55kkZZkcTZP6u9bwKGkv+dkk9at4m1Cpt0uY80kcpQ==} - dependencies: - '@jridgewell/gen-mapping': 0.3.3 - '@jridgewell/trace-mapping': 0.3.19 - dev: false - /@jridgewell/sourcemap-codec@1.4.15: + '@jridgewell/sourcemap-codec@1.4.15': resolution: {integrity: sha512-eF2rxCRulEKXHTRiDrDy6erMYWqNw4LPdQ8UQA4huuxaQsVeRPFl2oM8oDGxMFhJUWZf9McpLtJasDDZb/Bpeg==} - dev: false - /@jridgewell/trace-mapping@0.3.19: + '@jridgewell/trace-mapping@0.3.19': resolution: {integrity: sha512-kf37QtfW+Hwx/buWGMPcR60iF9ziHa6r/CZJIHbmcm4+0qrXiVdxegAH0F6yddEVQ7zdkjcGCgCzUu+BcbhQxw==} - dependencies: - '@jridgewell/resolve-uri': 3.1.1 - '@jridgewell/sourcemap-codec': 1.4.15 - dev: false - /@types/globrex@0.1.2: + '@types/globrex@0.1.2': resolution: {integrity: sha512-W+8iW69LnEae5H09PxjpmI3CdJyKUTBAoDyqWx6T5ewhX5unBHYYQsGYXlXQP8l3HE/Y71vswPAvxkJC92FQhQ==} - dev: true - /@types/node@20.8.6: + '@types/node@20.8.6': resolution: {integrity: sha512-eWO4K2Ji70QzKUqRy6oyJWUeB7+g2cRagT3T/nxYibYcT4y2BDL8lqolRXjTHmkZCdJfIPaY73KbJAZmcryxTQ==} - dependencies: - undici-types: 5.25.3 - dev: true - /@types/semver@7.5.3: + '@types/semver@7.5.3': resolution: {integrity: sha512-OxepLK9EuNEIPxWNME+C6WwbRAOOI2o2BaQEGzz5Lu2e4Z5eDnEo+/aVEDMIXywoJitJ7xWd641wrGLZdtwRyw==} - dev: true - /dequal@2.0.3: + dequal@2.0.3: resolution: {integrity: sha512-0je+qPKHEMohvfRTCEo3CrPG6cAzAYgmzKyxRiYSSDkS6eGJdyVJm7WaYA5ECaAD9wLB2T4EEeymA5aFVcYXCA==} engines: {node: '>=6'} - dev: true - /diff@5.1.0: + diff@5.1.0: resolution: {integrity: sha512-D+mk+qE8VC/PAUrlAU34N+VfXev0ghe5ywmpqrawphmVZc1bEfn56uo9qpyGp1p4xpzOHkSW4ztBd6L7Xx4ACw==} engines: {node: '>=0.3.1'} - dev: true - /globalyzer@0.1.0: + globalyzer@0.1.0: resolution: {integrity: sha512-40oNTM9UfG6aBmuKxk/giHn5nQ8RVz/SS4Ir6zgzOv9/qC3kKZ9v4etGTcJbEl/NyVQH7FGU7d+X1egr57Md2Q==} - dev: false - /globrex@0.1.2: + globrex@0.1.2: resolution: {integrity: sha512-uHJgbwAMwNFf5mLst7IWLNg14x1CkeqglJb/K3doi4dw6q2IvAAmM/Y81kevy83wP+Sst+nutFTYOGg3d1lsxg==} - dev: false - /kleur@4.1.5: + kleur@4.1.5: resolution: {integrity: sha512-o+NO+8WrRiQEE4/7nwRJhN1HWpVmJm511pBHUxPLtp0BUISzlBplORYSmTclCnJvQq2tKu/sgl3xVpkc7ZWuQQ==} engines: {node: '>=6'} - /locate-character@3.0.0: + locate-character@3.0.0: resolution: {integrity: sha512-SW13ws7BjaeJ6p7Q6CO2nchbYEc3X3J6WrmTTDto7yMPqVSZTUyY5Tjbid+Ab8gLnATtygYtiDIJGQRRn2ZOiA==} - dev: false - /lru-cache@6.0.0: + lru-cache@6.0.0: resolution: {integrity: sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==} engines: {node: '>=10'} - dependencies: - yallist: 4.0.0 - dev: true - /magic-string@0.30.5: + magic-string@0.30.5: resolution: {integrity: sha512-7xlpfBaQaP/T6Vh8MO/EqXSW5En6INHEvEXQiuff7Gku0PWjU3uf6w/j9o7O+SpB5fOAkrI5HeoNgwjEO0pFsA==} engines: {node: '>=12'} - dependencies: - '@jridgewell/sourcemap-codec': 1.4.15 - dev: false - /mri@1.2.0: + mri@1.2.0: resolution: {integrity: sha512-tzzskb3bG8LvYGFF/mDTpq3jpI6Q9wc3LEmBaghu+DdCssd1FakN7Bc0hVNmEyGq1bq3RgfkCb3cmQLpNPOroA==} engines: {node: '>=4'} - /prettier@3.0.3: + prettier@3.0.3: resolution: {integrity: sha512-L/4pUDMxcNa8R/EthV08Zt42WBO4h1rarVtK0K+QJG0X187OLo7l699jWw0GKuwzkPQ//jMFA/8Xm6Fh3J/DAg==} engines: {node: '>=14'} hasBin: true - dev: true - /sade@1.8.1: + sade@1.8.1: resolution: {integrity: sha512-xal3CZX1Xlo/k4ApwCFrHVACi9fBqJ7V+mwhBsuf/1IOKbBy098Fex+Wa/5QMubw09pSZ/u8EY8PWgevJsXp1A==} engines: {node: '>=6'} - dependencies: - mri: 1.2.0 - /semver@7.5.4: + semver@7.5.4: resolution: {integrity: sha512-1bCSESV6Pv+i21Hvpxp3Dx+pSD8lIPt8uVjRrxAUt/nbswYc+tK6Y2btiULjd4+fnq15PX+nqQDC7Oft7WkwcA==} engines: {node: '>=10'} hasBin: true - dependencies: - lru-cache: 6.0.0 - dev: true - /tiny-glob@0.2.9: + tiny-glob@0.2.9: resolution: {integrity: sha512-g/55ssRPUjShh+xkfx9UPDXqhckHEsHr4Vd9zX55oSdGZc/MD0m3sferOkwWtp98bv+kcVfEHtRJgBVJzelrzg==} - dependencies: - globalyzer: 0.1.0 - globrex: 0.1.2 - dev: false - /ts-api-utils@1.0.3(typescript@5.4.2): + ts-api-utils@1.0.3: resolution: {integrity: sha512-wNMeqtMz5NtwpT/UZGY5alT+VoKdSsOOP/kqHFcUW1P/VRhH2wJ48+DN2WwUliNbQ976ETwDL0Ifd2VVvgonvg==} engines: {node: '>=16.13.0'} peerDependencies: typescript: '>=4.2.0' - dependencies: - typescript: 5.4.2 - dev: false - /typescript@5.4.2: - resolution: {integrity: sha512-+2/g0Fds1ERlP6JsakQQDXjZdZMM+rqpamFZJEKh4kwTIn3iDkgKtby0CeNd5ATNZ4Ry1ax15TMx0W2V+miizQ==} + typescript@5.5.2: + resolution: {integrity: sha512-NcRtPEOsPFFWjobJEtfihkLCZCXZt/os3zf8nTxjVH3RvTSxjrCamJpbExGvYOF+tFHc3pA65qpdwPbzjohhew==} engines: {node: '>=14.17'} hasBin: true - /undici-types@5.25.3: + undici-types@5.25.3: resolution: {integrity: sha512-Ga1jfYwRn7+cP9v8auvEXN1rX3sWqlayd4HP7OKk4mZWylEmu3KzXDUGrQUN6Ol7qo1gPvB2e5gX6udnyEPgdA==} - dev: true - /uvu@0.5.6: + uvu@0.5.6: resolution: {integrity: sha512-+g8ENReyr8YsOc6fv/NVJs2vFdHBnBNdfE49rshrTzDWOlUx4Gq7KOS2GD8eqhy2j+Ejq29+SbKH8yjkAqXqoA==} engines: {node: '>=8'} hasBin: true + + yallist@4.0.0: + resolution: {integrity: sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==} + +snapshots: + + '@jridgewell/gen-mapping@0.3.3': + dependencies: + '@jridgewell/set-array': 1.1.2 + '@jridgewell/sourcemap-codec': 1.4.15 + '@jridgewell/trace-mapping': 0.3.19 + + '@jridgewell/resolve-uri@3.1.1': {} + + '@jridgewell/set-array@1.1.2': {} + + '@jridgewell/source-map@0.3.5': + dependencies: + '@jridgewell/gen-mapping': 0.3.3 + '@jridgewell/trace-mapping': 0.3.19 + + '@jridgewell/sourcemap-codec@1.4.15': {} + + '@jridgewell/trace-mapping@0.3.19': + dependencies: + '@jridgewell/resolve-uri': 3.1.1 + '@jridgewell/sourcemap-codec': 1.4.15 + + '@types/globrex@0.1.2': {} + + '@types/node@20.8.6': + dependencies: + undici-types: 5.25.3 + + '@types/semver@7.5.3': {} + + dequal@2.0.3: {} + + diff@5.1.0: {} + + globalyzer@0.1.0: {} + + globrex@0.1.2: {} + + kleur@4.1.5: {} + + locate-character@3.0.0: {} + + lru-cache@6.0.0: + dependencies: + yallist: 4.0.0 + + magic-string@0.30.5: + dependencies: + '@jridgewell/sourcemap-codec': 1.4.15 + + mri@1.2.0: {} + + prettier@3.0.3: {} + + sade@1.8.1: + dependencies: + mri: 1.2.0 + + semver@7.5.4: + dependencies: + lru-cache: 6.0.0 + + tiny-glob@0.2.9: + dependencies: + globalyzer: 0.1.0 + globrex: 0.1.2 + + ts-api-utils@1.0.3(typescript@5.5.2): + dependencies: + typescript: 5.5.2 + + typescript@5.5.2: {} + + undici-types@5.25.3: {} + + uvu@0.5.6: dependencies: dequal: 2.0.3 diff: 5.1.0 kleur: 4.1.5 sade: 1.8.1 - dev: true - /yallist@4.0.0: - resolution: {integrity: sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==} - dev: true + yallist@4.0.0: {} diff --git a/src/create-module-declaration.js b/src/create-module-declaration.js index 4efe459..9538e4f 100644 --- a/src/create-module-declaration.js +++ b/src/create-module-declaration.js @@ -1,3 +1,4 @@ +/** @import { Binding, Declaration, Mapping, Module, ModuleReference } from './types' */ import path from 'node:path'; import ts from 'typescript'; import * as tsu from 'ts-api-utils'; @@ -11,35 +12,35 @@ import { clean_jsdoc, get_dts, is_declaration, is_reference, resolve_dts, walk } * @param {(file: string, specifier: string) => string | null} resolve * @returns {{ * content: string; - * mappings: Map; - * ambient: import('./types').ModuleReference[]; + * mappings: Map; + * ambient: ModuleReference[]; * }} */ export function create_module_declaration(id, entry, created, resolve) { let content = ''; - /** @type {Map} */ + /** @type {Map} */ const mappings = new Map(); - /** @type {import('./types').ModuleReference[]} */ + /** @type {ModuleReference[]} */ const ambient = []; - /** @type {Record>} */ + /** @type {Record>} */ const external_imports = {}; - /** @type {Record>} */ + /** @type {Record>} */ const external_import_alls = {}; - /** @type {Record>} */ + /** @type {Record>} */ const external_export_from = {}; /** @type {Set} */ const external_export_all_from = new Set(); - /** @type {Map} */ + /** @type {Map} */ const bundle = new Map(); - /** @type {Map>} */ + /** @type {Map>} */ const traced = new Map(); /** @type {Set} */ @@ -107,10 +108,8 @@ export function create_module_declaration(id, entry, created, resolve) { traced.set(file, new Map()); } - /** @type {Set} */ - const modules_to_export_all_from = new Set([ - /** @type {import('./types').Module} */ (bundle.get(entry)) - ]); + /** @type {Set} */ + const modules_to_export_all_from = new Set([/** @type {Module} */ (bundle.get(entry))]); for (const module of modules_to_export_all_from) { for (const exported of module.exports.keys()) { @@ -133,7 +132,7 @@ export function create_module_declaration(id, entry, created, resolve) { /** @type {Set} */ const names = new Set(globals); - /** @type {Set} */ + /** @type {Set} */ const declarations = new Set(); /** @param {string} name */ @@ -148,7 +147,7 @@ export function create_module_declaration(id, entry, created, resolve) { } /** - * @param {import('./types').Declaration} declaration + * @param {Declaration} declaration */ const mark = (declaration) => { if (declaration.included) return; @@ -255,9 +254,7 @@ export function create_module_declaration(id, entry, created, resolve) { throw new Error('TODO'); } - const declaration = /** @type {import('./types').Declaration} */ ( - module.declarations.get(name) - ); + const declaration = /** @type {Declaration} */ (module.declarations.get(name)); if (!declaration.included) { result.remove(node.pos, node.end); @@ -308,7 +305,7 @@ export function create_module_declaration(id, entry, created, resolve) { line: l + 1, column: match.index }; - mappings.set(name, /** @type {import('./types').Mapping} */ (mapping)); + mappings.set(name, /** @type {Mapping} */ (mapping)); } else { // TODO figure out how to repair sourcemaps in this case } @@ -321,7 +318,7 @@ export function create_module_declaration(id, entry, created, resolve) { line: loc.line, column: loc.column }; - mappings.set(name, /** @type {import('./types').Mapping} */ (mapping)); + mappings.set(name, /** @type {Mapping} */ (mapping)); } } } @@ -420,7 +417,7 @@ export function create_module_declaration(id, entry, created, resolve) { /** * @param {string} module_id * @param {string} name - * @returns {import('./types').Declaration | null} + * @returns {Declaration | null} */ function trace_export(module_id, name) { if (module_id === id) { @@ -458,7 +455,7 @@ export function create_module_declaration(id, entry, created, resolve) { /** * @param {string} id * @param {string} name - * @returns {import('./types').Declaration} + * @returns {Declaration} */ function trace(id, name) { const cache = traced.get(id); @@ -473,7 +470,7 @@ export function create_module_declaration(id, entry, created, resolve) { } if (cache.has(name)) { - return /** @type {import('./types').Declaration} */ (cache.get(name)); + return /** @type {Declaration} */ (cache.get(name)); } const module = bundle.get(id); @@ -521,9 +518,9 @@ export function create_module_declaration(id, entry, created, resolve) { } /** - * @param {import('./types').Binding} binding + * @param {Binding} binding * @param {string} alias - * @returns {import('./types').Declaration} + * @returns {Declaration} */ function create_external_declaration(binding, alias) { return { diff --git a/src/types.d.ts b/src/types.d.ts index 1ce1d7a..398d424 100644 --- a/src/types.d.ts +++ b/src/types.d.ts @@ -31,7 +31,7 @@ interface ModuleReference { external: boolean; } -export interface Module { +interface Module { file: string; dts: string; ast: SourceFile; @@ -55,14 +55,16 @@ export interface Module { exports: Map; } -export interface Namespace { +interface Namespace { declarations: Map; references: Set; exports: Map; } -export interface Mapping { +interface Mapping { source: string; line: number; column: number; } + +export { Binding, Declaration, Mapping, Module, ModuleReference, Namespace }; diff --git a/src/utils.js b/src/utils.js index f525b79..0582b9a 100644 --- a/src/utils.js +++ b/src/utils.js @@ -1,3 +1,4 @@ +/** @import { Declaration, Module, Namespace } from './types' */ import fs from 'node:fs'; import path from 'node:path'; import glob from 'tiny-glob/sync.js'; @@ -185,7 +186,7 @@ export function get_dts(file, created, resolve) { const ast = ts.createSourceFile(file, dts, ts.ScriptTarget.Latest, true, ts.ScriptKind.TS); const locator = getLocator(dts, { offsetLine: 1 }); - /** @type {import('./types').Module} */ + /** @type {Module} */ const module = { file, dts, @@ -217,7 +218,7 @@ export function get_dts(file, created, resolve) { }; } - /** @type {import('./types').Module | import('./types').Namespace} */ + /** @type {Module | Namespace} */ let current = module; /** @param {ts.Node} node */ @@ -348,9 +349,7 @@ export function get_dts(file, created, resolve) { }); } - const declaration = /** @type {import('./types').Declaration} */ ( - current.declarations.get(name) - ); + const declaration = /** @type {Declaration} */ (current.declarations.get(name)); const export_modifier = node.modifiers?.find((node) => tsu.isExportKeyword(node)); diff --git a/test/samples/basic/output 5.5/index.d.ts b/test/samples/basic/output 5.5/index.d.ts index c36aa46..68a43e3 100644 --- a/test/samples/basic/output 5.5/index.d.ts +++ b/test/samples/basic/output 5.5/index.d.ts @@ -25,4 +25,4 @@ declare module 'basic/subpackage' { export { multiply }; } -//# sourceMappingURL=index.d.ts.map \ No newline at end of file +//# sourceMappingURL=index.d.ts.map diff --git a/test/samples/basic/output 5.5/index.d.ts.map b/test/samples/basic/output 5.5/index.d.ts.map index 1cfa890..3e724d7 100644 --- a/test/samples/basic/output 5.5/index.d.ts.map +++ b/test/samples/basic/output 5.5/index.d.ts.map @@ -17,4 +17,4 @@ null ], "mappings": ";;WACiBA,OAAOA;;;;;;;;;;;UCKRC,GAAGA;;;;;;;;;UCAHC,QAAQA" -} \ No newline at end of file +} diff --git a/test/samples/jsdoc-import/input/index.js b/test/samples/jsdoc-import/input/index.js new file mode 100644 index 0000000..f6d5b30 --- /dev/null +++ b/test/samples/jsdoc-import/input/index.js @@ -0,0 +1,14 @@ +/** @import {Vector2} from './vector' */ + +/** + * Add two vectors + * @param {Vector2} a the first vector + * @param {Vector2} b the second vector + * @returns {Vector2} + */ +export function add(a, b) { + return { + x: a.x + b.x, + y: a.y + b.y + }; +} diff --git a/test/samples/jsdoc-import/input/vector.d.ts b/test/samples/jsdoc-import/input/vector.d.ts new file mode 100644 index 0000000..0ffd6f9 --- /dev/null +++ b/test/samples/jsdoc-import/input/vector.d.ts @@ -0,0 +1,7 @@ +/** A vector with two components */ +export interface Vector2 { + /** The x component */ + x: number; + /** The y component */ + y: number; +} diff --git a/test/samples/jsdoc-import/output 5.5/index.d.ts b/test/samples/jsdoc-import/output 5.5/index.d.ts new file mode 100644 index 0000000..0894aee --- /dev/null +++ b/test/samples/jsdoc-import/output 5.5/index.d.ts @@ -0,0 +1,19 @@ +declare module 'jsdoc-import' { + /** + * Add two vectors + * @param a the first vector + * @param b the second vector + * */ + function add(a: Vector2, b: Vector2): Vector2; + /** A vector with two components */ + interface Vector2 { + /** The x component */ + x: number; + /** The y component */ + y: number; + } + + export { add }; +} + +//# sourceMappingURL=index.d.ts.map diff --git a/test/samples/jsdoc-import/output 5.5/index.d.ts.map b/test/samples/jsdoc-import/output 5.5/index.d.ts.map new file mode 100644 index 0000000..f12e450 --- /dev/null +++ b/test/samples/jsdoc-import/output 5.5/index.d.ts.map @@ -0,0 +1,17 @@ +{ + "version": 3, + "file": "index.d.ts", + "names": [ + "add", + "Vector2" + ], + "sources": [ + "../input/index.js", + "../input/vector.d.ts" + ], + "sourcesContent": [ + null, + null + ], + "mappings": ";;;;;;UAQgBA,GAAGA;;WCPFC,OAAOA" +} diff --git a/test/samples/jsdoc-import/output/index.d.ts b/test/samples/jsdoc-import/output/index.d.ts new file mode 100644 index 0000000..9ff9cf7 --- /dev/null +++ b/test/samples/jsdoc-import/output/index.d.ts @@ -0,0 +1,13 @@ +declare module 'jsdoc-import' { + /** @import {Vector2} from './vector' */ + /** + * Add two vectors + * @param a the first vector + * @param b the second vector + * */ + function add(a: Vector2, b: Vector2): Vector2; + + export { add }; +} + +//# sourceMappingURL=index.d.ts.map \ No newline at end of file diff --git a/test/samples/jsdoc-import/output/index.d.ts.map b/test/samples/jsdoc-import/output/index.d.ts.map new file mode 100644 index 0000000..95b40bc --- /dev/null +++ b/test/samples/jsdoc-import/output/index.d.ts.map @@ -0,0 +1,14 @@ +{ + "version": 3, + "file": "index.d.ts", + "names": [ + "add" + ], + "sources": [ + "../input/index.js" + ], + "sourcesContent": [ + null + ], + "mappings": ";;;;;;;UAQgBA,GAAGA" +} \ No newline at end of file diff --git a/test/test.js b/test/test.js index 77bed15..aa786d2 100644 --- a/test/test.js +++ b/test/test.js @@ -51,7 +51,7 @@ for (const sample of fs.readdirSync('test/samples')) { if (!candidate.startsWith('output ')) continue; const range = candidate.slice(7); - if (semver.satisfies(ts.version, range)) { + if (semver.satisfies(ts.version.split('-')[0], range)) { output_dir = candidate; break; } diff --git a/tsconfig.json b/tsconfig.json index fc2eb64..7bb3f21 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -10,6 +10,7 @@ "module": "esnext", "target": "esnext", "moduleResolution": "bundler", + "skipLibCheck": true, "strict": true }, "include": ["src", "scripts", "test/test.js"]