yukigo 0.2.3 → 0.3.2
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/.mocharc.json +3 -3
- package/CHANGELOG.md +105 -40
- package/README.md +193 -193
- package/dist/analyzer/GraphBuilder.d.ts +1 -0
- package/dist/analyzer/GraphBuilder.js +2 -1
- package/dist/analyzer/index.d.ts +0 -7
- package/dist/analyzer/index.js +3 -3
- package/dist/analyzer/inspections/functional/functional.d.ts +1 -1
- package/dist/analyzer/inspections/functional/functional.js +1 -1
- package/dist/analyzer/inspections/functional/smells.d.ts +3 -3
- package/dist/analyzer/inspections/functional/smells.js +27 -35
- package/dist/analyzer/inspections/generic/generic.d.ts +22 -14
- package/dist/analyzer/inspections/generic/generic.js +82 -60
- package/dist/analyzer/inspections/generic/smells.d.ts +2 -0
- package/dist/analyzer/inspections/generic/smells.js +55 -64
- package/dist/analyzer/inspections/imperative/imperative.d.ts +3 -3
- package/dist/analyzer/inspections/imperative/imperative.js +3 -3
- package/dist/analyzer/inspections/imperative/smells.d.ts +1 -0
- package/dist/analyzer/inspections/imperative/smells.js +8 -5
- package/dist/analyzer/inspections/logic/logic.d.ts +8 -8
- package/dist/analyzer/inspections/logic/logic.js +5 -5
- package/dist/analyzer/inspections/logic/smells.js +2 -2
- package/dist/analyzer/inspections/object/object.d.ts +5 -5
- package/dist/analyzer/inspections/object/object.js +22 -21
- package/dist/analyzer/inspections/object/smells.js +11 -23
- package/dist/analyzer/utils.d.ts +6 -2
- package/dist/analyzer/utils.js +6 -2
- package/dist/interpreter/components/EnvBuilder.d.ts +20 -1
- package/dist/interpreter/components/EnvBuilder.js +211 -66
- package/dist/interpreter/components/EqualityComparer.d.ts +15 -0
- package/dist/interpreter/components/EqualityComparer.js +69 -0
- package/dist/interpreter/components/Operations.d.ts +17 -14
- package/dist/interpreter/components/Operations.js +61 -62
- package/dist/interpreter/components/PatternMatcher.d.ts +19 -58
- package/dist/interpreter/components/PatternMatcher.js +185 -286
- package/dist/interpreter/components/RuntimeContext.d.ts +24 -15
- package/dist/interpreter/components/RuntimeContext.js +43 -4
- package/dist/interpreter/components/TestRunner.d.ts +15 -13
- package/dist/interpreter/components/TestRunner.js +86 -53
- package/dist/interpreter/components/evaluators/BaseEvaluator.d.ts +19 -0
- package/dist/interpreter/components/evaluators/BaseEvaluator.js +20 -0
- package/dist/interpreter/components/evaluators/ExpressionEvaluator.d.ts +34 -0
- package/dist/interpreter/components/evaluators/ExpressionEvaluator.js +298 -0
- package/dist/interpreter/components/evaluators/OperationEvaluator.d.ts +25 -0
- package/dist/interpreter/components/evaluators/OperationEvaluator.js +226 -0
- package/dist/interpreter/components/evaluators/PrimitiveEvaluator.d.ts +19 -0
- package/dist/interpreter/components/evaluators/PrimitiveEvaluator.js +50 -0
- package/dist/interpreter/components/evaluators/StatementEvaluator.d.ts +28 -0
- package/dist/interpreter/components/evaluators/StatementEvaluator.js +240 -0
- package/dist/interpreter/components/evaluators/TestingEvaluator.d.ts +15 -0
- package/dist/interpreter/components/evaluators/TestingEvaluator.js +14 -0
- package/dist/interpreter/components/evaluators/index.d.ts +110 -0
- package/dist/interpreter/components/evaluators/index.js +21 -0
- package/dist/interpreter/components/evaluators/utils.d.ts +7 -0
- package/dist/interpreter/components/evaluators/utils.js +50 -0
- package/dist/interpreter/components/hooks/YukigoHook.d.ts +27 -0
- package/dist/interpreter/components/hooks/YukigoHook.js +1 -0
- package/dist/interpreter/components/kernel/commands.d.ts +122 -0
- package/dist/interpreter/components/kernel/commands.js +203 -0
- package/dist/interpreter/components/kernel/index.d.ts +51 -0
- package/dist/interpreter/components/kernel/index.js +176 -0
- package/dist/interpreter/components/logic/LogicEngine.d.ts +26 -23
- package/dist/interpreter/components/logic/LogicEngine.js +234 -221
- package/dist/interpreter/components/logic/LogicResolver.d.ts +22 -51
- package/dist/interpreter/components/logic/LogicResolver.js +73 -440
- package/dist/interpreter/components/logic/LogicTerm.d.ts +104 -0
- package/dist/interpreter/components/logic/LogicTerm.js +423 -0
- package/dist/interpreter/components/logic/LogicTranslator.d.ts +25 -9
- package/dist/interpreter/components/logic/LogicTranslator.js +211 -74
- package/dist/interpreter/components/runtimes/FunctionRuntime.d.ts +6 -4
- package/dist/interpreter/components/runtimes/FunctionRuntime.js +82 -84
- package/dist/interpreter/components/runtimes/LazyRuntime.d.ts +13 -14
- package/dist/interpreter/components/runtimes/LazyRuntime.js +112 -239
- package/dist/interpreter/components/runtimes/ObjectRuntime.d.ts +17 -14
- package/dist/interpreter/components/runtimes/ObjectRuntime.js +105 -74
- package/dist/interpreter/errors.d.ts +10 -0
- package/dist/interpreter/errors.js +17 -0
- package/dist/interpreter/index.d.ts +9 -5
- package/dist/interpreter/index.js +11 -13
- package/dist/interpreter/primitives/YuValue.d.ts +21 -0
- package/dist/interpreter/primitives/YuValue.js +40 -0
- package/dist/interpreter/primitives/capabilities.d.ts +90 -0
- package/dist/interpreter/primitives/capabilities.js +1 -0
- package/dist/interpreter/primitives/entities/LazyList.d.ts +48 -0
- package/dist/interpreter/primitives/entities/LazyList.js +164 -0
- package/dist/interpreter/primitives/entities/LogicResult.d.ts +51 -0
- package/dist/interpreter/primitives/entities/LogicResult.js +101 -0
- package/dist/interpreter/primitives/entities/RuntimeClass.d.ts +24 -0
- package/dist/interpreter/primitives/entities/RuntimeClass.js +57 -0
- package/dist/interpreter/primitives/entities/RuntimeFunction.d.ts +40 -0
- package/dist/interpreter/primitives/entities/RuntimeFunction.js +73 -0
- package/dist/interpreter/primitives/entities/RuntimeObject.d.ts +27 -0
- package/dist/interpreter/primitives/entities/RuntimeObject.js +82 -0
- package/dist/interpreter/primitives/entities/RuntimePredicate.d.ts +19 -0
- package/dist/interpreter/primitives/entities/RuntimePredicate.js +59 -0
- package/dist/interpreter/primitives/index.d.ts +14 -0
- package/dist/interpreter/primitives/index.js +14 -0
- package/dist/interpreter/primitives/scalars/YuBoolean.d.ts +24 -0
- package/dist/interpreter/primitives/scalars/YuBoolean.js +69 -0
- package/dist/interpreter/primitives/scalars/YuChar.d.ts +28 -0
- package/dist/interpreter/primitives/scalars/YuChar.js +78 -0
- package/dist/interpreter/primitives/scalars/YuNil.d.ts +25 -0
- package/dist/interpreter/primitives/scalars/YuNil.js +73 -0
- package/dist/interpreter/primitives/scalars/YuNumber.d.ts +49 -0
- package/dist/interpreter/primitives/scalars/YuNumber.js +165 -0
- package/dist/interpreter/primitives/sequences/YuArray.d.ts +33 -0
- package/dist/interpreter/primitives/sequences/YuArray.js +150 -0
- package/dist/interpreter/primitives/sequences/YuString.d.ts +40 -0
- package/dist/interpreter/primitives/sequences/YuString.js +130 -0
- package/dist/interpreter/utils.d.ts +23 -10
- package/dist/interpreter/utils.js +25 -30
- package/dist/tester/index.d.ts +3 -3
- package/dist/tester/index.js +39 -28
- package/dist/utils/helpers.d.ts +13 -5
- package/dist/utils/helpers.js +38 -85
- package/package.json +3 -16
- package/src/analyzer/GraphBuilder.ts +143 -142
- package/src/analyzer/index.ts +185 -194
- package/src/analyzer/inspections/functional/functional.ts +121 -121
- package/src/analyzer/inspections/functional/smells.ts +88 -102
- package/src/analyzer/inspections/generic/generic.ts +610 -577
- package/src/analyzer/inspections/generic/smells.ts +355 -365
- package/src/analyzer/inspections/imperative/imperative.ts +104 -101
- package/src/analyzer/inspections/imperative/smells.ts +58 -54
- package/src/analyzer/inspections/logic/logic.ts +84 -90
- package/src/analyzer/inspections/logic/smells.ts +54 -54
- package/src/analyzer/inspections/object/object.ts +295 -264
- package/src/analyzer/inspections/object/smells.ts +130 -144
- package/src/analyzer/utils.ts +115 -109
- package/src/index.ts +3 -3
- package/src/interpreter/components/EnvBuilder.ts +405 -202
- package/src/interpreter/components/EqualityComparer.ts +107 -0
- package/src/interpreter/components/Operations.ts +126 -99
- package/src/interpreter/components/PatternMatcher.ts +375 -475
- package/src/interpreter/components/RuntimeContext.ts +181 -119
- package/src/interpreter/components/TestRunner.ts +223 -151
- package/src/interpreter/components/evaluators/BaseEvaluator.ts +36 -0
- package/src/interpreter/components/evaluators/ExpressionEvaluator.ts +475 -0
- package/src/interpreter/components/evaluators/OperationEvaluator.ts +477 -0
- package/src/interpreter/components/evaluators/PrimitiveEvaluator.ts +80 -0
- package/src/interpreter/components/evaluators/StatementEvaluator.ts +372 -0
- package/src/interpreter/components/evaluators/TestingEvaluator.ts +26 -0
- package/src/interpreter/components/evaluators/index.ts +34 -0
- package/src/interpreter/components/evaluators/utils.ts +64 -0
- package/src/interpreter/components/hooks/YukigoHook.ts +45 -0
- package/src/interpreter/components/kernel/commands.ts +255 -0
- package/src/interpreter/components/kernel/index.ts +222 -0
- package/src/interpreter/components/logic/LogicEngine.ts +509 -519
- package/src/interpreter/components/logic/LogicResolver.ts +209 -858
- package/src/interpreter/components/logic/LogicTerm.ts +477 -0
- package/src/interpreter/components/logic/LogicTranslator.ts +362 -149
- package/src/interpreter/components/runtimes/FunctionRuntime.ts +249 -227
- package/src/interpreter/components/runtimes/LazyRuntime.ts +226 -334
- package/src/interpreter/components/runtimes/ObjectRuntime.ts +262 -224
- package/src/interpreter/errors.ts +68 -47
- package/src/interpreter/index.ts +50 -52
- package/src/interpreter/primitives/YuValue.ts +64 -0
- package/src/interpreter/primitives/capabilities.ts +111 -0
- package/src/interpreter/primitives/entities/LazyList.ts +225 -0
- package/src/interpreter/primitives/entities/LogicResult.ts +133 -0
- package/src/interpreter/primitives/entities/RuntimeClass.ts +70 -0
- package/src/interpreter/primitives/entities/RuntimeFunction.ts +108 -0
- package/src/interpreter/primitives/entities/RuntimeObject.ts +110 -0
- package/src/interpreter/primitives/entities/RuntimePredicate.ts +77 -0
- package/src/interpreter/primitives/index.ts +17 -0
- package/src/interpreter/primitives/scalars/YuBoolean.ts +79 -0
- package/src/interpreter/primitives/scalars/YuChar.ts +94 -0
- package/src/interpreter/primitives/scalars/YuNil.ts +84 -0
- package/src/interpreter/primitives/scalars/YuNumber.ts +187 -0
- package/src/interpreter/primitives/sequences/YuArray.ts +178 -0
- package/src/interpreter/primitives/sequences/YuString.ts +165 -0
- package/src/interpreter/utils.ts +105 -84
- package/src/tester/index.ts +157 -128
- package/src/utils/helpers.ts +113 -169
- package/tests/analyzer/functional.spec.ts +221 -207
- package/tests/analyzer/generic.spec.ts +178 -178
- package/tests/analyzer/helpers.spec.ts +83 -89
- package/tests/analyzer/logic.spec.ts +237 -237
- package/tests/analyzer/oop.spec.ts +320 -323
- package/tests/analyzer/transitive.spec.ts +166 -166
- package/tests/interpreter/EnvBuilder.spec.ts +181 -183
- package/tests/interpreter/FunctionRuntime.spec.ts +224 -223
- package/tests/interpreter/LazyRuntime.spec.ts +227 -225
- package/tests/interpreter/LogicEngine.spec.ts +371 -327
- package/tests/interpreter/LogicSubstitution.spec.ts +90 -80
- package/tests/interpreter/ObjectRuntime.spec.ts +431 -606
- package/tests/interpreter/Operations.spec.ts +312 -220
- package/tests/interpreter/PatternSystem.spec.ts +254 -213
- package/tests/interpreter/Tests.spec.ts +122 -122
- package/tests/interpreter/interpreter.spec.ts +1143 -991
- package/tests/kernel/YukigoKernel.spec.ts +112 -0
- package/tests/tester/Tester.spec.ts +156 -152
- package/tsconfig.build.json +16 -15
- package/tsconfig.json +27 -25
- package/dist/interpreter/components/Visitor.d.ts +0 -70
- package/dist/interpreter/components/Visitor.js +0 -634
- package/dist/interpreter/entities.d.ts +0 -105
- package/dist/interpreter/entities.js +0 -96
- package/dist/interpreter/trampoline.d.ts +0 -17
- package/dist/interpreter/trampoline.js +0 -38
- package/dist/src/analyzer/GraphBuilder.d.ts +0 -30
- package/dist/src/analyzer/GraphBuilder.js +0 -100
- package/dist/src/analyzer/index.d.ts +0 -59
- package/dist/src/analyzer/index.js +0 -152
- package/dist/src/analyzer/inspections/functional/functional.d.ts +0 -44
- package/dist/src/analyzer/inspections/functional/functional.js +0 -149
- package/dist/src/analyzer/inspections/functional/smells.d.ts +0 -16
- package/dist/src/analyzer/inspections/functional/smells.js +0 -98
- package/dist/src/analyzer/inspections/generic/generic.d.ts +0 -178
- package/dist/src/analyzer/inspections/generic/generic.js +0 -604
- package/dist/src/analyzer/inspections/generic/smells.d.ts +0 -61
- package/dist/src/analyzer/inspections/generic/smells.js +0 -349
- package/dist/src/analyzer/inspections/imperative/imperative.d.ts +0 -35
- package/dist/src/analyzer/inspections/imperative/imperative.js +0 -109
- package/dist/src/analyzer/inspections/imperative/smells.d.ts +0 -16
- package/dist/src/analyzer/inspections/imperative/smells.js +0 -58
- package/dist/src/analyzer/inspections/logic/logic.d.ts +0 -32
- package/dist/src/analyzer/inspections/logic/logic.js +0 -96
- package/dist/src/analyzer/inspections/logic/smells.d.ts +0 -15
- package/dist/src/analyzer/inspections/logic/smells.js +0 -60
- package/dist/src/analyzer/inspections/object/object.d.ts +0 -90
- package/dist/src/analyzer/inspections/object/object.js +0 -321
- package/dist/src/analyzer/inspections/object/smells.d.ts +0 -30
- package/dist/src/analyzer/inspections/object/smells.js +0 -135
- package/dist/src/analyzer/utils.d.ts +0 -30
- package/dist/src/analyzer/utils.js +0 -78
- package/dist/src/index.d.ts +0 -4
- package/dist/src/index.js +0 -4
- package/dist/src/interpreter/components/EnvBuilder.d.ts +0 -21
- package/dist/src/interpreter/components/EnvBuilder.js +0 -155
- package/dist/src/interpreter/components/Operations.d.ts +0 -14
- package/dist/src/interpreter/components/Operations.js +0 -84
- package/dist/src/interpreter/components/PatternMatcher.d.ts +0 -73
- package/dist/src/interpreter/components/PatternMatcher.js +0 -358
- package/dist/src/interpreter/components/RuntimeContext.d.ts +0 -35
- package/dist/src/interpreter/components/RuntimeContext.js +0 -93
- package/dist/src/interpreter/components/TestRunner.d.ts +0 -19
- package/dist/src/interpreter/components/TestRunner.js +0 -110
- package/dist/src/interpreter/components/Visitor.d.ts +0 -71
- package/dist/src/interpreter/components/Visitor.js +0 -638
- package/dist/src/interpreter/components/logic/LogicEngine.d.ts +0 -29
- package/dist/src/interpreter/components/logic/LogicEngine.js +0 -259
- package/dist/src/interpreter/components/logic/LogicResolver.d.ts +0 -53
- package/dist/src/interpreter/components/logic/LogicResolver.js +0 -484
- package/dist/src/interpreter/components/logic/LogicTranslator.d.ts +0 -14
- package/dist/src/interpreter/components/logic/LogicTranslator.js +0 -99
- package/dist/src/interpreter/components/runtimes/FunctionRuntime.d.ts +0 -12
- package/dist/src/interpreter/components/runtimes/FunctionRuntime.js +0 -149
- package/dist/src/interpreter/components/runtimes/LazyRuntime.d.ts +0 -19
- package/dist/src/interpreter/components/runtimes/LazyRuntime.js +0 -269
- package/dist/src/interpreter/components/runtimes/ObjectRuntime.d.ts +0 -35
- package/dist/src/interpreter/components/runtimes/ObjectRuntime.js +0 -126
- package/dist/src/interpreter/errors.d.ts +0 -19
- package/dist/src/interpreter/errors.js +0 -36
- package/dist/src/interpreter/index.d.ts +0 -24
- package/dist/src/interpreter/index.js +0 -41
- package/dist/src/interpreter/trampoline.d.ts +0 -17
- package/dist/src/interpreter/trampoline.js +0 -38
- package/dist/src/interpreter/utils.d.ts +0 -11
- package/dist/src/interpreter/utils.js +0 -65
- package/dist/src/tester/index.d.ts +0 -25
- package/dist/src/tester/index.js +0 -113
- package/dist/src/utils/helpers.d.ts +0 -13
- package/dist/src/utils/helpers.js +0 -52
- package/src/interpreter/components/Visitor.ts +0 -1065
- package/src/interpreter/trampoline.ts +0 -71
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { Lambda, Equation,
|
|
1
|
+
import { Lambda, Equation, Guard } from "yukigo-ast";
|
|
2
2
|
import { ScopedVisitor, VisitorConstructor } from "../../utils.js";
|
|
3
3
|
export declare class HasRedundantLambda extends ScopedVisitor {
|
|
4
4
|
visitLambda(node: Lambda): void;
|
|
5
5
|
}
|
|
6
6
|
export declare class HasRedundantGuards extends ScopedVisitor {
|
|
7
|
-
|
|
7
|
+
visitGuard(node: Guard): void;
|
|
8
8
|
private isAlwaysTrue;
|
|
9
9
|
}
|
|
10
10
|
export declare class ShouldUseOtherwise extends ScopedVisitor {
|
|
11
|
-
|
|
11
|
+
visitGuard(node: Guard): void;
|
|
12
12
|
}
|
|
13
13
|
export declare class HasRedundantParameter extends ScopedVisitor {
|
|
14
14
|
visitEquation(node: Equation): void;
|
|
@@ -4,24 +4,24 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
4
4
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
5
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
6
|
};
|
|
7
|
-
import { Call, VariablePattern, Variable, StopTraversalException, BooleanPrimitive, Application,
|
|
7
|
+
import { Call, VariablePattern, Variable, StopTraversalException, BooleanPrimitive, Application, Otherwise, } from "yukigo-ast";
|
|
8
8
|
import { AutoScoped, ScopedVisitor } from "../../utils.js";
|
|
9
9
|
import { Uses } from "../generic/generic.js";
|
|
10
10
|
let HasRedundantLambda = class HasRedundantLambda extends ScopedVisitor {
|
|
11
11
|
visitLambda(node) {
|
|
12
12
|
if (node.parameters.length !== 1)
|
|
13
13
|
return;
|
|
14
|
-
if (!
|
|
14
|
+
if (!node.body.is(Application))
|
|
15
15
|
return;
|
|
16
16
|
const param = node.parameters[0];
|
|
17
17
|
const call = node.body;
|
|
18
|
-
if (call.functionExpr
|
|
19
|
-
call.functionExpr instanceof Call)
|
|
18
|
+
if (call.functionExpr.is(Application) || call.functionExpr.is(Call))
|
|
20
19
|
return;
|
|
21
20
|
const arg = call.parameter;
|
|
22
|
-
|
|
23
|
-
arg
|
|
24
|
-
param.name.value === arg.identifier.value
|
|
21
|
+
const hasRedudantParam = param.is(VariablePattern) &&
|
|
22
|
+
arg.is(Variable) &&
|
|
23
|
+
param.name.value === arg.identifier.value;
|
|
24
|
+
if (hasRedudantParam)
|
|
25
25
|
throw new StopTraversalException();
|
|
26
26
|
}
|
|
27
27
|
};
|
|
@@ -30,23 +30,16 @@ HasRedundantLambda = __decorate([
|
|
|
30
30
|
], HasRedundantLambda);
|
|
31
31
|
export { HasRedundantLambda };
|
|
32
32
|
let HasRedundantGuards = class HasRedundantGuards extends ScopedVisitor {
|
|
33
|
-
|
|
34
|
-
if (
|
|
35
|
-
|
|
36
|
-
// If there is only 1 guard...
|
|
37
|
-
if (node.body.length === 1) {
|
|
38
|
-
const guard = node.body[0];
|
|
39
|
-
// ...and that guard is "True" or "otherwise"
|
|
40
|
-
if (this.isAlwaysTrue(guard.condition))
|
|
41
|
-
throw new StopTraversalException();
|
|
42
|
-
}
|
|
33
|
+
visitGuard(node) {
|
|
34
|
+
if (this.isAlwaysTrue(node.condition))
|
|
35
|
+
throw new StopTraversalException();
|
|
43
36
|
}
|
|
44
37
|
isAlwaysTrue(node) {
|
|
45
38
|
// check for boolean literal 'True'
|
|
46
|
-
if (node
|
|
39
|
+
if (node.is(BooleanPrimitive) && node.value === true)
|
|
47
40
|
return true;
|
|
48
41
|
// check for default case
|
|
49
|
-
if (node
|
|
42
|
+
if (node.is(Otherwise))
|
|
50
43
|
return true;
|
|
51
44
|
return false;
|
|
52
45
|
}
|
|
@@ -56,9 +49,8 @@ HasRedundantGuards = __decorate([
|
|
|
56
49
|
], HasRedundantGuards);
|
|
57
50
|
export { HasRedundantGuards };
|
|
58
51
|
let ShouldUseOtherwise = class ShouldUseOtherwise extends ScopedVisitor {
|
|
59
|
-
|
|
60
|
-
if (node.condition
|
|
61
|
-
node.condition.value === true)
|
|
52
|
+
visitGuard(node) {
|
|
53
|
+
if (node.condition.is(BooleanPrimitive) && node.condition.value === true)
|
|
62
54
|
throw new StopTraversalException();
|
|
63
55
|
}
|
|
64
56
|
};
|
|
@@ -69,19 +61,19 @@ export { ShouldUseOtherwise };
|
|
|
69
61
|
let HasRedundantParameter = class HasRedundantParameter extends ScopedVisitor {
|
|
70
62
|
visitEquation(node) {
|
|
71
63
|
for (const pattern of node.patterns) {
|
|
72
|
-
if (pattern
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
64
|
+
if (!pattern.is(VariablePattern))
|
|
65
|
+
continue;
|
|
66
|
+
const paramName = pattern.name.value;
|
|
67
|
+
const usageChecker = new Uses(paramName, this.binding);
|
|
68
|
+
try {
|
|
69
|
+
node.accept(usageChecker);
|
|
70
|
+
// uses didnt throw so the param is not being used
|
|
71
|
+
throw new StopTraversalException();
|
|
72
|
+
}
|
|
73
|
+
catch (e) {
|
|
74
|
+
if (e instanceof StopTraversalException)
|
|
75
|
+
continue;
|
|
76
|
+
throw e;
|
|
85
77
|
}
|
|
86
78
|
}
|
|
87
79
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ArithmeticBinaryOperation, ArithmeticUnaryOperation, Assignment,
|
|
2
|
-
import { VisitorConstructor, ScopedVisitor } from "../../utils.js";
|
|
1
|
+
import { ArithmeticBinaryOperation, ArithmeticUnaryOperation, Assignment, Attribute, Call, Catch, Class, EntryPoint, Equation, Fact, Function, If, LogicalBinaryOperation, LogicalUnaryOperation, Method, Object, Print, Procedure, Raise, Record as RecordNode, Rule, SimpleType, SymbolPrimitive, Try, TypeAlias, TypeSignature, TypeVar, Variable } from "yukigo-ast";
|
|
2
|
+
import { VisitorConstructor, ScopedVisitor, InspectionVisitor } from "../../utils.js";
|
|
3
3
|
export declare class Assigns extends ScopedVisitor {
|
|
4
4
|
private readonly targetIdentifier;
|
|
5
5
|
constructor(targetIdentifier: string, scope?: string);
|
|
@@ -24,6 +24,7 @@ export declare class Declares extends ScopedVisitor {
|
|
|
24
24
|
visitVariable(node: Variable): void;
|
|
25
25
|
visitAttribute(node: Attribute): void;
|
|
26
26
|
visitTypeAlias(node: TypeAlias): void;
|
|
27
|
+
visitTypeSignature(node: TypeSignature): void;
|
|
27
28
|
}
|
|
28
29
|
export declare class DeclaresComputation extends ScopedVisitor {
|
|
29
30
|
private readonly callName;
|
|
@@ -43,7 +44,7 @@ export declare class DeclaresComputationWithArity extends ScopedVisitor {
|
|
|
43
44
|
visitFact(node: Fact): void;
|
|
44
45
|
visitRule(node: Rule): void;
|
|
45
46
|
}
|
|
46
|
-
export declare class DeclaresEntryPoint extends
|
|
47
|
+
export declare class DeclaresEntryPoint extends InspectionVisitor {
|
|
47
48
|
visitEntryPoint(node: EntryPoint): void;
|
|
48
49
|
}
|
|
49
50
|
export declare class DeclaresFunction extends ScopedVisitor {
|
|
@@ -51,6 +52,7 @@ export declare class DeclaresFunction extends ScopedVisitor {
|
|
|
51
52
|
constructor(targetBinding: string, scope?: string);
|
|
52
53
|
visitFunction(node: Function): void;
|
|
53
54
|
}
|
|
55
|
+
type CallableDeclaration = Function | Method | Procedure | Fact | Rule;
|
|
54
56
|
export declare class DeclaresRecursively extends ScopedVisitor {
|
|
55
57
|
private readonly targetBinding;
|
|
56
58
|
constructor(targetBinding: string, scope?: string);
|
|
@@ -59,9 +61,9 @@ export declare class DeclaresRecursively extends ScopedVisitor {
|
|
|
59
61
|
visitProcedure(node: Procedure): void;
|
|
60
62
|
visitFact(node: Fact): void;
|
|
61
63
|
visitRule(node: Rule): void;
|
|
62
|
-
visitNested(node:
|
|
64
|
+
visitNested(node: CallableDeclaration): void;
|
|
63
65
|
}
|
|
64
|
-
export declare class
|
|
66
|
+
export declare class HasDirectRecursion extends InspectionVisitor {
|
|
65
67
|
private readonly binding;
|
|
66
68
|
private isInsideBody;
|
|
67
69
|
constructor(binding: string);
|
|
@@ -72,12 +74,12 @@ export declare class UsesDirectRecursion extends TraverseVisitor {
|
|
|
72
74
|
visitEquation(node: Equation): void;
|
|
73
75
|
visitSymbolPrimitive(node: SymbolPrimitive): void;
|
|
74
76
|
}
|
|
75
|
-
export declare class DeclaresTypeAlias extends
|
|
77
|
+
export declare class DeclaresTypeAlias extends InspectionVisitor {
|
|
76
78
|
private readonly typeAliasName;
|
|
77
79
|
constructor(typeAliasName: string);
|
|
78
80
|
visitTypeAlias(node: TypeAlias): void;
|
|
79
81
|
}
|
|
80
|
-
export declare class DeclaresTypeSignature extends
|
|
82
|
+
export declare class DeclaresTypeSignature extends InspectionVisitor {
|
|
81
83
|
private readonly targetBinding;
|
|
82
84
|
constructor(targetBinding: string);
|
|
83
85
|
visitTypeSignature(node: TypeSignature): void;
|
|
@@ -120,41 +122,46 @@ export declare class UsesType extends ScopedVisitor {
|
|
|
120
122
|
visitSimpleType(node: SimpleType): void;
|
|
121
123
|
visitTypeVar(node: TypeVar): void;
|
|
122
124
|
}
|
|
123
|
-
export declare class HasBinding extends
|
|
125
|
+
export declare class HasBinding extends InspectionVisitor {
|
|
126
|
+
private readonly targetBinding;
|
|
127
|
+
constructor(targetBinding: string);
|
|
128
|
+
private check;
|
|
124
129
|
visitFunction(node: Function): void;
|
|
125
130
|
visitObject(node: Object): void;
|
|
126
131
|
visitClass(node: Class): void;
|
|
127
132
|
visitRule(node: Rule): void;
|
|
128
133
|
visitFact(node: Fact): void;
|
|
129
134
|
visitTypeAlias(node: TypeAlias): void;
|
|
130
|
-
visitTypeSignature(node: TypeSignature): void;
|
|
131
135
|
visitRecord(node: RecordNode): void;
|
|
136
|
+
visitVariable(node: Variable): void;
|
|
137
|
+
visitMethod(node: Method): void;
|
|
138
|
+
visitProcedure(node: Procedure): void;
|
|
132
139
|
}
|
|
133
|
-
export declare class SubordinatesDeclarationsTo extends
|
|
140
|
+
export declare class SubordinatesDeclarationsTo extends InspectionVisitor {
|
|
134
141
|
private childName;
|
|
135
142
|
private parentName;
|
|
136
143
|
constructor(childName: string, parentName: string);
|
|
137
144
|
visitFunction(node: Function): void;
|
|
138
145
|
}
|
|
139
|
-
export declare class SubordinatesDeclarationsToEntryPoint extends
|
|
146
|
+
export declare class SubordinatesDeclarationsToEntryPoint extends InspectionVisitor {
|
|
140
147
|
private childName;
|
|
141
148
|
constructor(childName: string);
|
|
142
149
|
visitEntryPoint(node: EntryPoint): void;
|
|
143
150
|
}
|
|
144
|
-
export declare class TypesAs extends
|
|
151
|
+
export declare class TypesAs extends InspectionVisitor {
|
|
145
152
|
private typeName;
|
|
146
153
|
private bindingName;
|
|
147
154
|
constructor(typeName: string, bindingName: string);
|
|
148
155
|
visitTypeSignature(node: TypeSignature): void;
|
|
149
156
|
}
|
|
150
|
-
export declare class TypesParameterAs extends
|
|
157
|
+
export declare class TypesParameterAs extends InspectionVisitor {
|
|
151
158
|
private paramIndex;
|
|
152
159
|
private typeName;
|
|
153
160
|
private bindingName;
|
|
154
161
|
constructor(paramIndex: number, typeName: string, bindingName: string);
|
|
155
162
|
visitTypeSignature(node: TypeSignature): void;
|
|
156
163
|
}
|
|
157
|
-
export declare class TypesReturnAs extends
|
|
164
|
+
export declare class TypesReturnAs extends InspectionVisitor {
|
|
158
165
|
private typeName;
|
|
159
166
|
private bindingName;
|
|
160
167
|
constructor(typeName: string, bindingName: string);
|
|
@@ -175,3 +182,4 @@ export declare class UsesExceptions extends ScopedVisitor {
|
|
|
175
182
|
visitRaise(node: Raise): void;
|
|
176
183
|
}
|
|
177
184
|
export declare const genericInspections: Record<string, VisitorConstructor>;
|
|
185
|
+
export {};
|
|
@@ -4,8 +4,8 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
4
4
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
5
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
6
|
};
|
|
7
|
-
import {
|
|
8
|
-
import { ScopedVisitor, AutoScoped } from "../../utils.js";
|
|
7
|
+
import { NativeBody, ParameterizedType, StopTraversalException, SymbolPrimitive, VariablePattern, } from "yukigo-ast";
|
|
8
|
+
import { ScopedVisitor, InspectionVisitor, AutoScoped, } from "../../utils.js";
|
|
9
9
|
let Assigns = class Assigns extends ScopedVisitor {
|
|
10
10
|
targetIdentifier;
|
|
11
11
|
constructor(targetIdentifier, scope) {
|
|
@@ -88,6 +88,9 @@ let Declares = class Declares extends ScopedVisitor {
|
|
|
88
88
|
visitTypeAlias(node) {
|
|
89
89
|
this.check(node);
|
|
90
90
|
}
|
|
91
|
+
visitTypeSignature(node) {
|
|
92
|
+
this.check(node);
|
|
93
|
+
}
|
|
91
94
|
};
|
|
92
95
|
Declares = __decorate([
|
|
93
96
|
AutoScoped
|
|
@@ -155,7 +158,7 @@ DeclaresComputationWithArity = __decorate([
|
|
|
155
158
|
AutoScoped
|
|
156
159
|
], DeclaresComputationWithArity);
|
|
157
160
|
export { DeclaresComputationWithArity };
|
|
158
|
-
export class DeclaresEntryPoint extends
|
|
161
|
+
export class DeclaresEntryPoint extends InspectionVisitor {
|
|
159
162
|
visitEntryPoint(node) {
|
|
160
163
|
throw new StopTraversalException();
|
|
161
164
|
}
|
|
@@ -179,7 +182,7 @@ let DeclaresRecursively = class DeclaresRecursively extends ScopedVisitor {
|
|
|
179
182
|
targetBinding;
|
|
180
183
|
constructor(targetBinding, scope) {
|
|
181
184
|
super(scope);
|
|
182
|
-
this.targetBinding = targetBinding;
|
|
185
|
+
this.targetBinding = new SymbolPrimitive(targetBinding);
|
|
183
186
|
}
|
|
184
187
|
visitFunction(node) {
|
|
185
188
|
super.visitFunction(node);
|
|
@@ -202,9 +205,8 @@ let DeclaresRecursively = class DeclaresRecursively extends ScopedVisitor {
|
|
|
202
205
|
this.visitNested(node);
|
|
203
206
|
}
|
|
204
207
|
visitNested(node) {
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
node.identifier.value === this.targetBinding)
|
|
208
|
+
const hasOwnIdentifier = node.identifier.equals(this.targetBinding);
|
|
209
|
+
if (hasOwnIdentifier)
|
|
208
210
|
throw new StopTraversalException();
|
|
209
211
|
}
|
|
210
212
|
};
|
|
@@ -212,7 +214,7 @@ DeclaresRecursively = __decorate([
|
|
|
212
214
|
AutoScoped
|
|
213
215
|
], DeclaresRecursively);
|
|
214
216
|
export { DeclaresRecursively };
|
|
215
|
-
export class
|
|
217
|
+
export class HasDirectRecursion extends InspectionVisitor {
|
|
216
218
|
binding;
|
|
217
219
|
isInsideBody = false;
|
|
218
220
|
constructor(binding) {
|
|
@@ -242,12 +244,9 @@ export class UsesDirectRecursion extends TraverseVisitor {
|
|
|
242
244
|
visitEquation(node) {
|
|
243
245
|
this.isInsideBody = true;
|
|
244
246
|
try {
|
|
245
|
-
if (
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
else {
|
|
249
|
-
this.traverseCollection(node.body);
|
|
250
|
-
}
|
|
247
|
+
if (node.body instanceof NativeBody)
|
|
248
|
+
return;
|
|
249
|
+
node.body.accept(this);
|
|
251
250
|
}
|
|
252
251
|
finally {
|
|
253
252
|
this.isInsideBody = false;
|
|
@@ -258,7 +257,7 @@ export class UsesDirectRecursion extends TraverseVisitor {
|
|
|
258
257
|
throw new StopTraversalException();
|
|
259
258
|
}
|
|
260
259
|
}
|
|
261
|
-
export class DeclaresTypeAlias extends
|
|
260
|
+
export class DeclaresTypeAlias extends InspectionVisitor {
|
|
262
261
|
typeAliasName;
|
|
263
262
|
constructor(typeAliasName) {
|
|
264
263
|
super();
|
|
@@ -269,7 +268,7 @@ export class DeclaresTypeAlias extends TraverseVisitor {
|
|
|
269
268
|
throw new StopTraversalException();
|
|
270
269
|
}
|
|
271
270
|
}
|
|
272
|
-
export class DeclaresTypeSignature extends
|
|
271
|
+
export class DeclaresTypeSignature extends InspectionVisitor {
|
|
273
272
|
targetBinding;
|
|
274
273
|
constructor(targetBinding) {
|
|
275
274
|
super();
|
|
@@ -395,37 +394,59 @@ UsesType = __decorate([
|
|
|
395
394
|
AutoScoped
|
|
396
395
|
], UsesType);
|
|
397
396
|
export { UsesType };
|
|
398
|
-
|
|
397
|
+
export class HasBinding extends InspectionVisitor {
|
|
398
|
+
targetBinding;
|
|
399
|
+
constructor(targetBinding) {
|
|
400
|
+
super();
|
|
401
|
+
this.targetBinding = targetBinding;
|
|
402
|
+
}
|
|
403
|
+
check(identifier) {
|
|
404
|
+
if (identifier && identifier.value === this.targetBinding) {
|
|
405
|
+
throw new StopTraversalException();
|
|
406
|
+
}
|
|
407
|
+
}
|
|
399
408
|
visitFunction(node) {
|
|
400
|
-
|
|
409
|
+
this.check(node.identifier);
|
|
410
|
+
super.visitFunction(node);
|
|
401
411
|
}
|
|
402
412
|
visitObject(node) {
|
|
403
|
-
|
|
413
|
+
this.check(node.identifier);
|
|
414
|
+
super.visitObject(node);
|
|
404
415
|
}
|
|
405
416
|
visitClass(node) {
|
|
406
|
-
|
|
417
|
+
this.check(node.identifier);
|
|
418
|
+
super.visitClass(node);
|
|
407
419
|
}
|
|
408
420
|
visitRule(node) {
|
|
409
|
-
|
|
421
|
+
this.check(node.identifier);
|
|
422
|
+
super.visitRule(node);
|
|
410
423
|
}
|
|
411
424
|
visitFact(node) {
|
|
412
|
-
|
|
425
|
+
this.check(node.identifier);
|
|
426
|
+
super.visitFact(node);
|
|
413
427
|
}
|
|
414
428
|
visitTypeAlias(node) {
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
visitTypeSignature(node) {
|
|
418
|
-
throw new StopTraversalException();
|
|
429
|
+
this.check(node.identifier);
|
|
430
|
+
super.visitTypeAlias(node);
|
|
419
431
|
}
|
|
420
432
|
visitRecord(node) {
|
|
421
|
-
|
|
433
|
+
this.check(node.name);
|
|
434
|
+
super.visitRecord(node);
|
|
422
435
|
}
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
436
|
+
visitVariable(node) {
|
|
437
|
+
this.check(node.identifier);
|
|
438
|
+
super.visitVariable(node);
|
|
439
|
+
}
|
|
440
|
+
visitMethod(node) {
|
|
441
|
+
this.check(node.identifier);
|
|
442
|
+
super.visitMethod(node);
|
|
443
|
+
}
|
|
444
|
+
visitProcedure(node) {
|
|
445
|
+
this.check(node.identifier);
|
|
446
|
+
super.visitProcedure(node);
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
export class SubordinatesDeclarationsTo extends InspectionVisitor {
|
|
429
450
|
childName;
|
|
430
451
|
parentName;
|
|
431
452
|
constructor(childName, parentName) {
|
|
@@ -443,7 +464,7 @@ export class SubordinatesDeclarationsTo extends TraverseVisitor {
|
|
|
443
464
|
}
|
|
444
465
|
}
|
|
445
466
|
}
|
|
446
|
-
export class SubordinatesDeclarationsToEntryPoint extends
|
|
467
|
+
export class SubordinatesDeclarationsToEntryPoint extends InspectionVisitor {
|
|
447
468
|
childName;
|
|
448
469
|
constructor(childName) {
|
|
449
470
|
super();
|
|
@@ -454,7 +475,7 @@ export class SubordinatesDeclarationsToEntryPoint extends TraverseVisitor {
|
|
|
454
475
|
node.expression.statements.forEach((stmt) => stmt.accept(childFinder));
|
|
455
476
|
}
|
|
456
477
|
}
|
|
457
|
-
export class TypesAs extends
|
|
478
|
+
export class TypesAs extends InspectionVisitor {
|
|
458
479
|
typeName;
|
|
459
480
|
bindingName;
|
|
460
481
|
constructor(typeName, bindingName) {
|
|
@@ -472,7 +493,11 @@ export class TypesAs extends TraverseVisitor {
|
|
|
472
493
|
}
|
|
473
494
|
}
|
|
474
495
|
}
|
|
475
|
-
|
|
496
|
+
function isFormatAgnosticMatch(actual, expected) {
|
|
497
|
+
const normalize = (str) => str.replace(/\s+/g, " ").trim();
|
|
498
|
+
return normalize(actual) === normalize(expected);
|
|
499
|
+
}
|
|
500
|
+
export class TypesParameterAs extends InspectionVisitor {
|
|
476
501
|
paramIndex;
|
|
477
502
|
typeName;
|
|
478
503
|
bindingName;
|
|
@@ -483,21 +508,19 @@ export class TypesParameterAs extends TraverseVisitor {
|
|
|
483
508
|
this.bindingName = bindingName;
|
|
484
509
|
}
|
|
485
510
|
visitTypeSignature(node) {
|
|
486
|
-
if (node.identifier.value
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
}
|
|
497
|
-
}
|
|
511
|
+
if (node.identifier.value !== this.bindingName)
|
|
512
|
+
return;
|
|
513
|
+
if (!node.body.is(ParameterizedType))
|
|
514
|
+
return;
|
|
515
|
+
const paramType = node.body.inputs[this.paramIndex];
|
|
516
|
+
if (!paramType)
|
|
517
|
+
return;
|
|
518
|
+
const actualType = paramType.toString();
|
|
519
|
+
if (isFormatAgnosticMatch(actualType, this.typeName))
|
|
520
|
+
throw new StopTraversalException();
|
|
498
521
|
}
|
|
499
522
|
}
|
|
500
|
-
export class TypesReturnAs extends
|
|
523
|
+
export class TypesReturnAs extends InspectionVisitor {
|
|
501
524
|
typeName;
|
|
502
525
|
bindingName;
|
|
503
526
|
constructor(typeName, bindingName) {
|
|
@@ -506,14 +529,12 @@ export class TypesReturnAs extends TraverseVisitor {
|
|
|
506
529
|
this.bindingName = bindingName;
|
|
507
530
|
}
|
|
508
531
|
visitTypeSignature(node) {
|
|
509
|
-
if (node.identifier.value
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
}
|
|
516
|
-
}
|
|
532
|
+
if (node.identifier.value !== this.bindingName)
|
|
533
|
+
return;
|
|
534
|
+
if (node.body.is(ParameterizedType)) {
|
|
535
|
+
const actualType = node.body.returnType.toString();
|
|
536
|
+
if (isFormatAgnosticMatch(actualType, this.typeName))
|
|
537
|
+
throw new StopTraversalException();
|
|
517
538
|
}
|
|
518
539
|
}
|
|
519
540
|
}
|
|
@@ -525,8 +546,9 @@ let Rescues = class Rescues extends ScopedVisitor {
|
|
|
525
546
|
}
|
|
526
547
|
visitCatch(node) {
|
|
527
548
|
for (const pattern of node.patterns) {
|
|
528
|
-
|
|
529
|
-
pattern.name.value === this.exceptionName
|
|
549
|
+
const capturesExceptionAs = pattern.is(VariablePattern) &&
|
|
550
|
+
pattern.name.value === this.exceptionName;
|
|
551
|
+
if (capturesExceptionAs) {
|
|
530
552
|
throw new StopTraversalException();
|
|
531
553
|
}
|
|
532
554
|
}
|
|
@@ -573,7 +595,7 @@ export const genericInspections = {
|
|
|
573
595
|
DeclaresEntryPoint: DeclaresEntryPoint,
|
|
574
596
|
DeclaresFunction: DeclaresFunction,
|
|
575
597
|
DeclaresRecursively: DeclaresRecursively,
|
|
576
|
-
|
|
598
|
+
HasDirectRecursion: HasDirectRecursion,
|
|
577
599
|
DeclaresTypeAlias: DeclaresTypeAlias,
|
|
578
600
|
DeclaresTypeSignature: DeclaresTypeSignature,
|
|
579
601
|
HasTypeSignature: DeclaresTypeSignature,
|
|
@@ -32,9 +32,11 @@ export declare class HasRedundantBooleanComparison extends ScopedVisitor {
|
|
|
32
32
|
}
|
|
33
33
|
export declare class HasRedundantIf extends ScopedVisitor {
|
|
34
34
|
visitIf(node: If): void;
|
|
35
|
+
private isBooleanBlock;
|
|
35
36
|
}
|
|
36
37
|
export declare class HasRedundantLocalVariableReturn extends ScopedVisitor {
|
|
37
38
|
visitSequence(node: Sequence): void;
|
|
39
|
+
private isPointlessAssignment;
|
|
38
40
|
}
|
|
39
41
|
export declare class HasTooShortIdentifiers extends ScopedVisitor {
|
|
40
42
|
private readonly minLength;
|