Skip to content

Commit f32502c

Browse files
Merge pull request #1692 from AxiomCodeAI/loop/ty-is1626
typescript: a published module's classes, method-reference consts, namespaces, object literals and default arrows are entry points
2 parents c15b8d3 + fb45273 commit f32502c

24 files changed

Lines changed: 199 additions & 8 deletions

‎graph/test/typescript/cases/77-package-published-entries/src/plugins/deep/tracer.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// CONTROL: two segments below plugins/, which the one-segment `*` does not match, and
2-
// imported (not called) by logger.ts, so it is not an unimported module either.
2+
// imported (neither called nor published) by logger.ts, so it is not an unimported module either.
33
// tracer must stay unreachable.
44
export function tracer() {
55
return 'trace';

‎graph/test/typescript/cases/77-package-published-entries/src/plugins/logger.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
// Published by the "./plugins/*" subpath pattern: `*` = logger.
22
import { tracer } from './deep/tracer';
33

4-
export const traced = tracer;
4+
// Reads tracer without publishing it: a published const bound to `tracer` itself would
5+
// hand the function to a consumer, which is a root (79-package-published-members).
6+
export const tracerName = tracer.name;
57

68
export function logger(message: string) {
79
return format(message);
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"name": "published-members",
3+
"private": false,
4+
"exports": {
5+
"./cls": "./dist/cls.js",
6+
"./anon": "./dist/anon.js",
7+
"./bound": "./dist/bound.js",
8+
"./ns": "./dist/ns.js",
9+
"./api": "./dist/api.js"
10+
}
11+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// An anonymous default arrow of a published module.
2+
export default (x: number) => x;
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// A published object literal of callables.
2+
export const api = {
3+
method() { return 1; },
4+
arrow: () => 2,
5+
};
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// A published const bound to a method reference: the headline API of many libraries.
2+
class Engine {
3+
produce(x: number) { return x + 1; }
4+
finish(x: number) { return x - 1; }
5+
static make() { return new Engine(); }
6+
// CONTROL: a method no published const names stays unrooted.
7+
unused() { return 0; }
8+
}
9+
const engine = new Engine();
10+
export const produce = engine.produce;
11+
export const finish = engine.finish.bind(engine);
12+
export const make = Engine.make;
13+
// CONTROL: a published const holding a plain value roots nothing.
14+
export const version = 1;
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// An exported class of a published module: its public members are the API.
2+
export class Store {
3+
get() { return 1; }
4+
static create() { return new Store(); }
5+
// CONTROL: private and #private members are not reachable from a consumer.
6+
private secret() { return 2; }
7+
#hidden() { return 3; }
8+
}
9+
10+
// CONTROL: a class that is declared but not exported publishes nothing.
11+
class Internal {
12+
run() { return 4; }
13+
}
14+
export const internalCount = 1;
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// The project's own test imports each published module, so none is an unimported module.
2+
import { Store } from './cls';
3+
import anon from './anon';
4+
import { produce } from './bound';
5+
import { Result } from './ns';
6+
import { api } from './api';
7+
8+
export const all = [Store, anon, produce, Result, api];
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// The exported functions of an exported namespace.
2+
export namespace Result {
3+
export function ok(x: number) { return { ok: true, x }; }
4+
// CONTROL: a namespace function that is not exported is not published.
5+
function hidden() { return 0; }
6+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"compilerOptions": { "strict": true, "target": "es2020", "module": "esnext", "outDir": "dist" },
3+
"include": ["src"]
4+
}

0 commit comments

Comments
 (0)