boperators 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +202 -0
- package/dist/cjs/core/BopConfig.js +73 -0
- package/dist/cjs/core/ErrorManager.js +126 -0
- package/dist/cjs/core/OverloadInjector.js +136 -0
- package/dist/cjs/core/OverloadStore.js +622 -0
- package/dist/cjs/core/SourceMap.js +168 -0
- package/dist/cjs/core/helpers/ensureImportedName.js +50 -0
- package/dist/cjs/core/helpers/getImportedNameForSymbol.js +64 -0
- package/dist/cjs/core/helpers/getModuleSpecifier.js +61 -0
- package/dist/cjs/core/helpers/getOperatorStringFromProperty.js +33 -0
- package/dist/cjs/core/helpers/resolveExpressionType.js +30 -0
- package/dist/cjs/core/helpers/unwrapInitializer.js +18 -0
- package/dist/cjs/core/operatorMap.js +95 -0
- package/dist/cjs/core/validateExports.js +87 -0
- package/dist/cjs/index.js +36 -0
- package/dist/cjs/lib/index.js +17 -0
- package/dist/cjs/lib/operatorSymbols.js +37 -0
- package/dist/esm/core/BopConfig.d.ts +34 -0
- package/dist/esm/core/BopConfig.js +65 -0
- package/dist/esm/core/ErrorManager.d.ts +90 -0
- package/dist/esm/core/ErrorManager.js +118 -0
- package/dist/esm/core/OverloadInjector.d.ts +33 -0
- package/dist/esm/core/OverloadInjector.js +129 -0
- package/dist/esm/core/OverloadStore.d.ts +114 -0
- package/dist/esm/core/OverloadStore.js +618 -0
- package/dist/esm/core/SourceMap.d.ts +41 -0
- package/dist/esm/core/SourceMap.js +164 -0
- package/dist/esm/core/helpers/ensureImportedName.d.ts +11 -0
- package/dist/esm/core/helpers/ensureImportedName.js +46 -0
- package/dist/esm/core/helpers/getImportedNameForSymbol.d.ts +8 -0
- package/dist/esm/core/helpers/getImportedNameForSymbol.js +60 -0
- package/dist/esm/core/helpers/getModuleSpecifier.d.ts +2 -0
- package/dist/esm/core/helpers/getModuleSpecifier.js +57 -0
- package/dist/esm/core/helpers/getOperatorStringFromProperty.d.ts +13 -0
- package/dist/esm/core/helpers/getOperatorStringFromProperty.js +30 -0
- package/dist/esm/core/helpers/resolveExpressionType.d.ts +11 -0
- package/dist/esm/core/helpers/resolveExpressionType.js +27 -0
- package/dist/esm/core/helpers/unwrapInitializer.d.ts +9 -0
- package/dist/esm/core/helpers/unwrapInitializer.js +15 -0
- package/dist/esm/core/operatorMap.d.ts +77 -0
- package/dist/esm/core/operatorMap.js +89 -0
- package/dist/esm/core/validateExports.d.ts +30 -0
- package/dist/esm/core/validateExports.js +84 -0
- package/dist/esm/index.d.ts +19 -0
- package/dist/esm/index.js +14 -0
- package/dist/esm/lib/index.d.ts +1 -0
- package/dist/esm/lib/index.js +1 -0
- package/dist/esm/lib/operatorSymbols.d.ts +33 -0
- package/dist/esm/lib/operatorSymbols.js +34 -0
- package/license.txt +8 -0
- package/package.json +54 -0
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { Node } from "ts-morph";
|
|
2
|
+
/**
|
|
3
|
+
* Validate that all classes with registered operator overloads are exported
|
|
4
|
+
* and (optionally) reachable from a package entry point.
|
|
5
|
+
*
|
|
6
|
+
* @param project The ts-morph project containing the source files.
|
|
7
|
+
* @param overloadStore Populated OverloadStore for the project.
|
|
8
|
+
* @param projectDir Absolute path to the project root — used to filter out
|
|
9
|
+
* overloads sourced from library dependencies.
|
|
10
|
+
* @param entryPoint Absolute path to the source entry point (e.g. `src/index.ts`).
|
|
11
|
+
* When provided, a second pass checks that every overload
|
|
12
|
+
* class is transitively reachable from this file via its
|
|
13
|
+
* export graph. Omit to run the file-level check only.
|
|
14
|
+
*/
|
|
15
|
+
export function validateExports({ project, overloadStore, projectDir, entryPoint, }) {
|
|
16
|
+
var _a;
|
|
17
|
+
const violations = [];
|
|
18
|
+
const normalizedDir = projectDir.replace(/\\/g, "/").replace(/\/$/, "");
|
|
19
|
+
// Deduplicate: collect unique (className, classFilePath) pairs whose
|
|
20
|
+
// source lives inside this project (skip .d.ts from dependencies).
|
|
21
|
+
const seen = new Set();
|
|
22
|
+
const classes = [];
|
|
23
|
+
for (const overload of overloadStore.getAllOverloads()) {
|
|
24
|
+
const normalized = overload.classFilePath.replace(/\\/g, "/");
|
|
25
|
+
const inProject = normalized.startsWith(`${normalizedDir}/`) ||
|
|
26
|
+
normalized === normalizedDir;
|
|
27
|
+
if (!inProject)
|
|
28
|
+
continue;
|
|
29
|
+
if (normalized.endsWith(".d.ts"))
|
|
30
|
+
continue;
|
|
31
|
+
const key = `${overload.className}::${normalized}`;
|
|
32
|
+
if (!seen.has(key)) {
|
|
33
|
+
seen.add(key);
|
|
34
|
+
classes.push({
|
|
35
|
+
className: overload.className,
|
|
36
|
+
classFilePath: overload.classFilePath,
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
// Level 2 setup: resolve the set of class declarations reachable from the
|
|
41
|
+
// entry point by walking the full export graph (follows re-exports).
|
|
42
|
+
let entryExportedClassDecls;
|
|
43
|
+
if (entryPoint) {
|
|
44
|
+
const entryFile = (_a = project.getSourceFile(entryPoint)) !== null && _a !== void 0 ? _a : project.addSourceFileAtPath(entryPoint);
|
|
45
|
+
entryExportedClassDecls = new Set();
|
|
46
|
+
for (const decls of entryFile.getExportedDeclarations().values()) {
|
|
47
|
+
for (const decl of decls) {
|
|
48
|
+
if (Node.isClassDeclaration(decl)) {
|
|
49
|
+
entryExportedClassDecls.add(decl);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
// Check each class.
|
|
55
|
+
for (const { className, classFilePath } of classes) {
|
|
56
|
+
const sourceFile = project.getSourceFile(classFilePath);
|
|
57
|
+
if (!sourceFile)
|
|
58
|
+
continue;
|
|
59
|
+
const classDecl = sourceFile.getClass(className);
|
|
60
|
+
if (!classDecl)
|
|
61
|
+
continue;
|
|
62
|
+
// Level 1: is the class exported from its own source file?
|
|
63
|
+
if (!classDecl.isExported()) {
|
|
64
|
+
violations.push({
|
|
65
|
+
className,
|
|
66
|
+
classFilePath,
|
|
67
|
+
reason: "not-exported-from-file",
|
|
68
|
+
});
|
|
69
|
+
// If not exported from file it cannot be in the entry point graph
|
|
70
|
+
// either — no need to run the deep check for this class.
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
// Level 2: is the class reachable from the entry point?
|
|
74
|
+
if (entryExportedClassDecls !== undefined &&
|
|
75
|
+
!entryExportedClassDecls.has(classDecl)) {
|
|
76
|
+
violations.push({
|
|
77
|
+
className,
|
|
78
|
+
classFilePath,
|
|
79
|
+
reason: "not-reachable-from-entry",
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return { violations };
|
|
84
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export type { BopConfFile, BopConfig, BopLogger, LoadConfigOptions, LogLevel, } from "./core/BopConfig";
|
|
2
|
+
export { ConsoleLogger, loadConfig } from "./core/BopConfig";
|
|
3
|
+
export { ErrorDescription, ErrorManager } from "./core/ErrorManager";
|
|
4
|
+
export { getOperatorStringFromProperty } from "./core/helpers/getOperatorStringFromProperty";
|
|
5
|
+
export { resolveExpressionType } from "./core/helpers/resolveExpressionType";
|
|
6
|
+
export { unwrapInitializer } from "./core/helpers/unwrapInitializer";
|
|
7
|
+
export type { TransformResult } from "./core/OverloadInjector";
|
|
8
|
+
export { OverloadInjector } from "./core/OverloadInjector";
|
|
9
|
+
export type { OverloadDescription, OverloadInfo } from "./core/OverloadStore";
|
|
10
|
+
export { OverloadStore } from "./core/OverloadStore";
|
|
11
|
+
export type { OperatorSyntaxKind, PostfixUnaryOperatorSyntaxKind, PrefixUnaryOperatorSyntaxKind, } from "./core/operatorMap";
|
|
12
|
+
export { isOperatorSyntaxKind, isPostfixUnaryOperatorSyntaxKind, isPrefixUnaryOperatorSyntaxKind, } from "./core/operatorMap";
|
|
13
|
+
export type { EditRecord } from "./core/SourceMap";
|
|
14
|
+
export { SourceMap } from "./core/SourceMap";
|
|
15
|
+
export type { ExportViolation, ExportViolationReason, ValidateExportsResult, } from "./core/validateExports";
|
|
16
|
+
export { validateExports } from "./core/validateExports";
|
|
17
|
+
export { Operator, operatorSymbols } from "./lib/operatorSymbols";
|
|
18
|
+
export type { SourceFile } from "ts-morph";
|
|
19
|
+
export { Node, Project, SyntaxKind } from "ts-morph";
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// Core transformation pipeline
|
|
2
|
+
export { ConsoleLogger, loadConfig } from "./core/BopConfig";
|
|
3
|
+
export { ErrorDescription, ErrorManager } from "./core/ErrorManager";
|
|
4
|
+
export { getOperatorStringFromProperty } from "./core/helpers/getOperatorStringFromProperty";
|
|
5
|
+
export { resolveExpressionType } from "./core/helpers/resolveExpressionType";
|
|
6
|
+
export { unwrapInitializer } from "./core/helpers/unwrapInitializer";
|
|
7
|
+
export { OverloadInjector } from "./core/OverloadInjector";
|
|
8
|
+
export { OverloadStore } from "./core/OverloadStore";
|
|
9
|
+
export { isOperatorSyntaxKind, isPostfixUnaryOperatorSyntaxKind, isPrefixUnaryOperatorSyntaxKind, } from "./core/operatorMap";
|
|
10
|
+
export { SourceMap } from "./core/SourceMap";
|
|
11
|
+
export { validateExports } from "./core/validateExports";
|
|
12
|
+
// Operator definitions
|
|
13
|
+
export { Operator, operatorSymbols } from "./lib/operatorSymbols";
|
|
14
|
+
export { Node, Project, SyntaxKind } from "ts-morph";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./operatorSymbols";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./operatorSymbols";
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Designed for internal use to ensure consistency.
|
|
3
|
+
*/
|
|
4
|
+
export declare enum Operator {
|
|
5
|
+
PLUS = "+",
|
|
6
|
+
PLUS_EQUALS = "+=",
|
|
7
|
+
MINUS = "-",
|
|
8
|
+
MINUS_EQUALS = "-=",
|
|
9
|
+
MULTIPLY = "*",
|
|
10
|
+
MULTIPLY_EQUALS = "*=",
|
|
11
|
+
DIVIDE = "/",
|
|
12
|
+
DIVIDE_EQUALS = "/=",
|
|
13
|
+
GREATER_THAN = ">",
|
|
14
|
+
GREATER_THAN_EQUAL_TO = ">=",
|
|
15
|
+
LESS_THAN = "<",
|
|
16
|
+
LESS_THAN_EQUAL_TO = "<=",
|
|
17
|
+
MODULO = "%",
|
|
18
|
+
MODULO_EQUALS = "%=",
|
|
19
|
+
EQUALS = "==",
|
|
20
|
+
STRICT_EQUALS = "===",
|
|
21
|
+
NOT_EQUALS = "!=",
|
|
22
|
+
STRICT_NOT_EQUALS = "!==",
|
|
23
|
+
AND = "&&",
|
|
24
|
+
AND_EQUALS = "&&=",
|
|
25
|
+
OR = "||",
|
|
26
|
+
OR_EQUALS = "||=",
|
|
27
|
+
NULLISH = "??",
|
|
28
|
+
NOT = "!",
|
|
29
|
+
BITWISE_NOT = "~",
|
|
30
|
+
INCREMENT = "++",
|
|
31
|
+
DECREMENT = "--"
|
|
32
|
+
}
|
|
33
|
+
export declare const operatorSymbols: string[];
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Designed for internal use to ensure consistency.
|
|
3
|
+
*/
|
|
4
|
+
export var Operator;
|
|
5
|
+
(function (Operator) {
|
|
6
|
+
Operator["PLUS"] = "+";
|
|
7
|
+
Operator["PLUS_EQUALS"] = "+=";
|
|
8
|
+
Operator["MINUS"] = "-";
|
|
9
|
+
Operator["MINUS_EQUALS"] = "-=";
|
|
10
|
+
Operator["MULTIPLY"] = "*";
|
|
11
|
+
Operator["MULTIPLY_EQUALS"] = "*=";
|
|
12
|
+
Operator["DIVIDE"] = "/";
|
|
13
|
+
Operator["DIVIDE_EQUALS"] = "/=";
|
|
14
|
+
Operator["GREATER_THAN"] = ">";
|
|
15
|
+
Operator["GREATER_THAN_EQUAL_TO"] = ">=";
|
|
16
|
+
Operator["LESS_THAN"] = "<";
|
|
17
|
+
Operator["LESS_THAN_EQUAL_TO"] = "<=";
|
|
18
|
+
Operator["MODULO"] = "%";
|
|
19
|
+
Operator["MODULO_EQUALS"] = "%=";
|
|
20
|
+
Operator["EQUALS"] = "==";
|
|
21
|
+
Operator["STRICT_EQUALS"] = "===";
|
|
22
|
+
Operator["NOT_EQUALS"] = "!=";
|
|
23
|
+
Operator["STRICT_NOT_EQUALS"] = "!==";
|
|
24
|
+
Operator["AND"] = "&&";
|
|
25
|
+
Operator["AND_EQUALS"] = "&&=";
|
|
26
|
+
Operator["OR"] = "||";
|
|
27
|
+
Operator["OR_EQUALS"] = "||=";
|
|
28
|
+
Operator["NULLISH"] = "??";
|
|
29
|
+
Operator["NOT"] = "!";
|
|
30
|
+
Operator["BITWISE_NOT"] = "~";
|
|
31
|
+
Operator["INCREMENT"] = "++";
|
|
32
|
+
Operator["DECREMENT"] = "--";
|
|
33
|
+
})(Operator || (Operator = {}));
|
|
34
|
+
export const operatorSymbols = Object.values(Operator);
|
package/license.txt
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
Copyright 2025 Dief Bell
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
4
|
+
|
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
6
|
+
|
|
7
|
+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
8
|
+
|
package/package.json
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "boperators",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"description": "Operator overloading for TypeScript.",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://github.com/DiefBell/boperators",
|
|
9
|
+
"directory": "package"
|
|
10
|
+
},
|
|
11
|
+
"homepage": "https://github.com/DiefBell/boperators/tree/main/package",
|
|
12
|
+
"main": "./dist/cjs/index.js",
|
|
13
|
+
"module": "./dist/esm/index.js",
|
|
14
|
+
"types": "./dist/esm/index.d.ts",
|
|
15
|
+
"exports": {
|
|
16
|
+
".": {
|
|
17
|
+
"types": "./dist/esm/index.d.ts",
|
|
18
|
+
"require": "./dist/cjs/index.js",
|
|
19
|
+
"import": "./dist/esm/index.js"
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
"keywords": [
|
|
23
|
+
"boperators",
|
|
24
|
+
"typescript",
|
|
25
|
+
"operator",
|
|
26
|
+
"overload",
|
|
27
|
+
"operator-overloading",
|
|
28
|
+
"ts-morph",
|
|
29
|
+
"ast",
|
|
30
|
+
"transform"
|
|
31
|
+
],
|
|
32
|
+
"scripts": {
|
|
33
|
+
"build": "tsc -p tsconfig.cjs.json && tsc -p tsconfig.esm.json",
|
|
34
|
+
"watch": "concurrently \"tsc -p tsconfig.cjs.json -w\" \"tsc -p tsconfig.esm.json -w\"",
|
|
35
|
+
"prepare": "bun run build",
|
|
36
|
+
"prepublish": "bun run build"
|
|
37
|
+
},
|
|
38
|
+
"dependencies": {
|
|
39
|
+
"ts-morph": "^27.0.0"
|
|
40
|
+
},
|
|
41
|
+
"peerDependencies": {
|
|
42
|
+
"typescript": ">=5.0.0 <5.10.0"
|
|
43
|
+
},
|
|
44
|
+
"files": [
|
|
45
|
+
"package.json",
|
|
46
|
+
"license.txt",
|
|
47
|
+
"README.md",
|
|
48
|
+
"dist"
|
|
49
|
+
],
|
|
50
|
+
"devDependencies": {
|
|
51
|
+
"@types/node": "^22.0.0",
|
|
52
|
+
"concurrently": "^9.2.1"
|
|
53
|
+
}
|
|
54
|
+
}
|