Skip to content

Commit 3757140

Browse files
committedNov 11, 2023
Consider JSDoc tags of individual export specifiers + their parent declaration
1 parent c9b3770 commit 3757140

File tree

9 files changed

+90
-3
lines changed

9 files changed

+90
-3
lines changed
 

‎fixtures/re-exports-public/index.ts

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { something } from './module.js';
2+
something;
3+
4+
/** @public */
5+
export {
6+
/** @public */
7+
somethingToIgnore,
8+
somethingIgnoredAnyway,
9+
} from './module.js';

‎fixtures/re-exports-public/module.ts

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export const something = 1;
2+
export const somethingToIgnore = 1;
3+
export const somethingIgnoredAnyway = 1;
+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"name": "@fixtures/re-exports-public"
3+
}

‎fixtures/re-exports/1-entry.ts

+6
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,8 @@
11
import { something } from './2-re-export-star.js';
22
something;
3+
4+
export {
5+
/** @public */
6+
somethingToIgnore,
7+
somethingNotToIgnore,
8+
} from './2-re-export-star.js';
+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export { something } from './4-my-module';
1+
export { something, somethingToIgnore, somethingNotToIgnore } from './4-my-module';

‎fixtures/re-exports/4-my-module.ts

+3
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
11
export const something = {};
2+
3+
export const somethingToIgnore = {};
4+
export const somethingNotToIgnore = {};

‎src/typescript/ast-helpers.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,11 @@ export const isInModuleBlock = (node: ts.Node) => {
133133

134134
export const getJSDocTags = (node: ts.Node) => {
135135
const tags = new Set<string>();
136-
const declaration = ts.isExportSpecifier(node) || ts.isBindingElement(node) ? node.parent.parent : node;
137-
for (const tagNode of ts.getJSDocTags(declaration)) {
136+
let tagNodes = ts.getJSDocTags(node);
137+
if (ts.isExportSpecifier(node) || ts.isBindingElement(node)) {
138+
tagNodes = [...tagNodes, ...ts.getJSDocTags(node.parent.parent)];
139+
}
140+
for (const tagNode of tagNodes) {
138141
const match = tagNode.getText()?.match(/@\S+/);
139142
if (match) tags.add(match[0]);
140143
}

‎test/re-exports-public.test.ts

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import assert from 'node:assert/strict';
2+
import test from 'node:test';
3+
import { main } from '../src/index.js';
4+
import { resolve } from '../src/util/path.js';
5+
import baseArguments from './helpers/baseArguments.js';
6+
import baseCounters from './helpers/baseCounters.js';
7+
8+
const cwd = resolve('fixtures/re-exports-public');
9+
10+
test('Ignore re-exports from included entry files', async () => {
11+
const { counters } = await main({
12+
...baseArguments,
13+
cwd,
14+
isIncludeEntryExports: true,
15+
});
16+
17+
assert.deepEqual(counters, {
18+
...baseCounters,
19+
processed: 2,
20+
total: 2,
21+
});
22+
});

‎test/re-exports.test.ts

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import assert from 'node:assert/strict';
2+
import test from 'node:test';
3+
import { main } from '../src/index.js';
4+
import { resolve } from '../src/util/path.js';
5+
import baseArguments from './helpers/baseArguments.js';
6+
import baseCounters from './helpers/baseCounters.js';
7+
8+
const cwd = resolve('fixtures/re-exports');
9+
10+
test('Ignore re-exports from entry files', async () => {
11+
const { counters } = await main({
12+
...baseArguments,
13+
cwd,
14+
});
15+
16+
assert.deepEqual(counters, {
17+
...baseCounters,
18+
processed: 4,
19+
total: 4,
20+
});
21+
});
22+
23+
test('Ignore re-exports from entry files (include entry + ignore @public)', async () => {
24+
const { issues, counters } = await main({
25+
...baseArguments,
26+
cwd,
27+
isIncludeEntryExports: true,
28+
});
29+
30+
assert(issues.exports['1-entry.ts']['somethingNotToIgnore']);
31+
32+
assert.deepEqual(counters, {
33+
...baseCounters,
34+
exports: 1,
35+
processed: 4,
36+
total: 4,
37+
});
38+
});

0 commit comments

Comments
 (0)
Please sign in to comment.