cognitive-complexity-ts 0.6.5 → 0.8.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/build/shared/types.d.ts +6 -1
- package/build/src/cognitive-complexity/Scope.d.ts +4 -0
- package/build/src/cognitive-complexity/Scope.js +4 -0
- package/build/src/cognitive-complexity/cognitive-complexity.js +109 -59
- package/build/src/cognitive-complexity/debug.d.ts +1 -1
- package/build/src/cognitive-complexity/debug.js +2 -2
- package/build/src/cognitive-complexity/depth.d.ts +2 -2
- package/build/src/cognitive-complexity/depth.js +58 -36
- package/build/src/cognitive-complexity/node-inspection.d.ts +28 -2
- package/build/src/cognitive-complexity/node-inspection.js +110 -43
- package/build/src/cognitive-complexity/node-naming.js +25 -16
- package/build/src/cognitive-complexity/output.js +23 -14
- package/build/src/json.js +17 -7
- package/build/src/ui-server/ui-server.d.ts +0 -1
- package/build/src/ui-server/ui-server.js +18 -9
- package/build/src/util/util.d.ts +0 -2
- package/build/src/util/util.js +6 -32
- package/build/ui/ts/complexity-tree/ComplexityController.js +53 -11
- package/build/ui/ts/component/Filterers.js +10 -13
- package/build/ui/ts/domain/sortedOutput.js +5 -3
- package/package.json +13 -15
- package/ui/README.md +0 -26
|
@@ -15,15 +15,43 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
15
15
|
}) : function(o, v) {
|
|
16
16
|
o["default"] = v;
|
|
17
17
|
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
};
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
25
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.
|
|
36
|
+
exports.getColumnAndLine = getColumnAndLine;
|
|
37
|
+
exports.getIdentifier = getIdentifier;
|
|
38
|
+
exports.getFirstNonParenthesizedAncestor = getFirstNonParenthesizedAncestor;
|
|
39
|
+
exports.getNodeKind = getNodeKind;
|
|
40
|
+
exports.getTextWithoutBrackets = getTextWithoutBrackets;
|
|
41
|
+
exports.isBreakOrContinueToLabel = isBreakOrContinueToLabel;
|
|
42
|
+
exports.isContainer = isContainer;
|
|
43
|
+
exports.isForLikeStatement = isForLikeStatement;
|
|
44
|
+
exports.isFunctionNode = isFunctionNode;
|
|
45
|
+
exports.isSyntaxList = isSyntaxList;
|
|
46
|
+
exports.isNewSequenceOfBinaryOperators = isNewSequenceOfBinaryOperators;
|
|
47
|
+
exports.isNewSequenceOfBinaryTypeOperators = isNewSequenceOfBinaryTypeOperators;
|
|
48
|
+
exports.isChainableBinaryOperator = isChainableBinaryOperator;
|
|
49
|
+
exports.isChainableBinaryTypeOperator = isChainableBinaryTypeOperator;
|
|
50
|
+
exports.breaksASequenceOfBinaryOperators = breaksASequenceOfBinaryOperators;
|
|
51
|
+
exports.pausesASequenceOfBinaryOperators = pausesASequenceOfBinaryOperators;
|
|
52
|
+
exports.pausesASequenceOfBinaryTypeOperators = pausesASequenceOfBinaryTypeOperators;
|
|
53
|
+
exports.passThroughNameBeingAssigned = passThroughNameBeingAssigned;
|
|
54
|
+
exports.report = report;
|
|
27
55
|
const ts = __importStar(require("typescript"));
|
|
28
56
|
const util_1 = require("../util/util");
|
|
29
57
|
function getColumnAndLine(node) {
|
|
@@ -34,7 +62,6 @@ function getColumnAndLine(node) {
|
|
|
34
62
|
line: lineAndCol.line + 1,
|
|
35
63
|
};
|
|
36
64
|
}
|
|
37
|
-
exports.getColumnAndLine = getColumnAndLine;
|
|
38
65
|
function getIdentifier(node) {
|
|
39
66
|
for (const child of node.getChildren()) {
|
|
40
67
|
if (ts.isMemberName(child) || ts.isComputedPropertyName(child)) {
|
|
@@ -43,7 +70,6 @@ function getIdentifier(node) {
|
|
|
43
70
|
}
|
|
44
71
|
return undefined;
|
|
45
72
|
}
|
|
46
|
-
exports.getIdentifier = getIdentifier;
|
|
47
73
|
function getFirstNonParenthesizedAncestor(node) {
|
|
48
74
|
let firstNonParenthesisAncestor = node.parent;
|
|
49
75
|
while (ts.isParenthesizedExpression(firstNonParenthesisAncestor)) {
|
|
@@ -51,7 +77,21 @@ function getFirstNonParenthesizedAncestor(node) {
|
|
|
51
77
|
}
|
|
52
78
|
return firstNonParenthesisAncestor;
|
|
53
79
|
}
|
|
54
|
-
|
|
80
|
+
function getNodeKind(node) {
|
|
81
|
+
if (isFunctionNode(node)) {
|
|
82
|
+
return "function";
|
|
83
|
+
}
|
|
84
|
+
if (ts.isClassDeclaration(node) || ts.isClassExpression(node)) {
|
|
85
|
+
return "class";
|
|
86
|
+
}
|
|
87
|
+
if (ts.isTypeAliasDeclaration(node) || ts.isInterfaceDeclaration(node)) {
|
|
88
|
+
return "type";
|
|
89
|
+
}
|
|
90
|
+
if (ts.isModuleDeclaration(node)) {
|
|
91
|
+
return "module";
|
|
92
|
+
}
|
|
93
|
+
return undefined;
|
|
94
|
+
}
|
|
55
95
|
function getTextWithoutBrackets(node) {
|
|
56
96
|
if (ts.isParenthesizedExpression(node)) {
|
|
57
97
|
return node.getChildren()
|
|
@@ -61,11 +101,6 @@ function getTextWithoutBrackets(node) {
|
|
|
61
101
|
}
|
|
62
102
|
return node.getText();
|
|
63
103
|
}
|
|
64
|
-
exports.getTextWithoutBrackets = getTextWithoutBrackets;
|
|
65
|
-
function isBinaryTypeOperator(node) {
|
|
66
|
-
return ts.isUnionTypeNode(node) || ts.isIntersectionTypeNode(node);
|
|
67
|
-
}
|
|
68
|
-
exports.isBinaryTypeOperator = isBinaryTypeOperator;
|
|
69
104
|
function isBreakOrContinueToLabel(node) {
|
|
70
105
|
if (ts.isBreakOrContinueStatement(node)) {
|
|
71
106
|
for (const child of node.getChildren()) {
|
|
@@ -76,64 +111,97 @@ function isBreakOrContinueToLabel(node) {
|
|
|
76
111
|
}
|
|
77
112
|
return false;
|
|
78
113
|
}
|
|
79
|
-
exports.isBreakOrContinueToLabel = isBreakOrContinueToLabel;
|
|
80
114
|
function isContainer(node) {
|
|
81
115
|
return isFunctionNode(node)
|
|
82
116
|
|| ts.isClassDeclaration(node)
|
|
83
|
-
|| ts.isConstructorDeclaration(node)
|
|
84
117
|
|| ts.isInterfaceDeclaration(node)
|
|
85
118
|
|| ts.isModuleDeclaration(node)
|
|
86
119
|
|| ts.isTypeAliasDeclaration(node)
|
|
87
120
|
|| ts.isSourceFile(node)
|
|
88
121
|
|| ts.isSourceFile(node.parent);
|
|
89
122
|
}
|
|
90
|
-
exports.isContainer = isContainer;
|
|
91
123
|
function isForLikeStatement(node) {
|
|
92
124
|
return ts.isForInStatement(node)
|
|
93
125
|
|| ts.isForOfStatement(node)
|
|
94
126
|
|| ts.isForStatement(node);
|
|
95
127
|
}
|
|
96
|
-
exports.isForLikeStatement = isForLikeStatement;
|
|
97
128
|
function isFunctionNode(node) {
|
|
98
129
|
return ts.isArrowFunction(node)
|
|
99
130
|
|| ts.isFunctionDeclaration(node)
|
|
100
131
|
|| ts.isFunctionExpression(node)
|
|
101
132
|
|| ts.isMethodDeclaration(node)
|
|
133
|
+
|| ts.isConstructorDeclaration(node)
|
|
102
134
|
|| ts.isAccessor(node);
|
|
103
135
|
}
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
136
|
+
function isSyntaxList(node) {
|
|
137
|
+
return node.kind === ts.SyntaxKind.SyntaxList;
|
|
138
|
+
}
|
|
139
|
+
function isNewSequenceOfBinaryOperators(node, precedingOperator) {
|
|
140
|
+
if (!isChainableBinaryOperator(node)
|
|
141
|
+
&& node.kind !== ts.SyntaxKind.AmpersandAmpersandEqualsToken
|
|
142
|
+
&& node.kind !== ts.SyntaxKind.BarBarEqualsToken
|
|
143
|
+
&& node.kind !== ts.SyntaxKind.QuestionQuestionEqualsToken) {
|
|
108
144
|
return false;
|
|
109
145
|
}
|
|
110
|
-
|
|
111
|
-
|
|
146
|
+
// is now an operator, or is different to previous operator
|
|
147
|
+
return precedingOperator === undefined || node.kind !== precedingOperator;
|
|
148
|
+
}
|
|
149
|
+
function isNewSequenceOfBinaryTypeOperators(node, precedingTypeOperator) {
|
|
150
|
+
if (!isChainableBinaryTypeOperator(node)) {
|
|
112
151
|
return false;
|
|
113
152
|
}
|
|
114
|
-
|
|
115
|
-
|| operatorToken.kind === ts.SyntaxKind.BarBarToken
|
|
116
|
-
|| operatorToken.kind === ts.SyntaxKind.QuestionQuestionToken;
|
|
117
|
-
const firstNonParenthesisAncestor = getFirstNonParenthesizedAncestor(node);
|
|
118
|
-
if (operatorIsBoolean) {
|
|
119
|
-
// True if the parent does not use the same operator as this node.
|
|
120
|
-
// Presumably true if the parent is not a binary expression.
|
|
121
|
-
// Child number 1 is the operator token.
|
|
122
|
-
return ((_a = firstNonParenthesisAncestor.getChildAt(1)) === null || _a === void 0 ? void 0 : _a.kind) != operatorToken.kind;
|
|
123
|
-
}
|
|
124
|
-
return false;
|
|
153
|
+
return precedingTypeOperator !== node.kind;
|
|
125
154
|
}
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
155
|
+
function isChainableBinaryOperator(node) {
|
|
156
|
+
return node.kind === ts.SyntaxKind.AmpersandAmpersandToken
|
|
157
|
+
|| node.kind === ts.SyntaxKind.BarBarToken
|
|
158
|
+
|| node.kind === ts.SyntaxKind.QuestionQuestionToken;
|
|
159
|
+
}
|
|
160
|
+
function isChainableBinaryTypeOperator(node) {
|
|
161
|
+
const isPartOfTypeExpression = (node === null || node === void 0 ? void 0 : node.parent) !== undefined // this is actually undefined-able
|
|
162
|
+
&& (ts.isUnionTypeNode(node.parent) || ts.isIntersectionTypeNode(node.parent)); // doing .parent skips the syntax list for some reason
|
|
163
|
+
return isPartOfTypeExpression
|
|
164
|
+
&& (node.kind === ts.SyntaxKind.AmpersandToken || node.kind === ts.SyntaxKind.BarToken);
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* A node that causes an end to a sequence of binary operators
|
|
168
|
+
* (i.e. A && B { C && D }, the curly braces end the prior sequence;
|
|
169
|
+
* C will not be interpreted as part of the last sequence.
|
|
170
|
+
*/
|
|
171
|
+
function breaksASequenceOfBinaryOperators(node) {
|
|
172
|
+
return ts.isStatement(node)
|
|
173
|
+
|| ts.isBlock(node)
|
|
174
|
+
|| isFunctionNode(node)
|
|
175
|
+
|| ts.isParameter(node)
|
|
176
|
+
|| ts.isTypeParameterDeclaration(node)
|
|
177
|
+
|| ts.isPropertyDeclaration(node)
|
|
178
|
+
|| (node.kind === ts.SyntaxKind.ColonToken && isFunctionNode(node.parent))
|
|
179
|
+
|| node.kind === ts.SyntaxKind.FirstAssignment; // separates extends expression from parameter default
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* A node that doesn't cause an end to a sequence of binary operators
|
|
183
|
+
* (i.e. A && Node && B, the 2 && are in the same sequence)
|
|
184
|
+
* but the node's children don't form part of that sequence
|
|
185
|
+
* (i.e. A && Node(B && C) && D, this is two sequences, one inside Node(), the other outside)
|
|
186
|
+
*/
|
|
187
|
+
function pausesASequenceOfBinaryOperators(node) {
|
|
188
|
+
return ts.isCallLikeExpression(node)
|
|
189
|
+
|| ts.isPrefixUnaryExpression(node)
|
|
190
|
+
|| ts.isElementAccessExpression(node);
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* @see {pausesASequenceOfBinaryOperators} but for type operators
|
|
194
|
+
*/
|
|
195
|
+
function pausesASequenceOfBinaryTypeOperators(node) {
|
|
196
|
+
return ts.isParenthesizedExpression(node)
|
|
197
|
+
|| ts.isTypeReferenceNode(node)
|
|
198
|
+
|| ts.isAsExpression(node);
|
|
129
199
|
}
|
|
130
|
-
exports.isSyntaxList = isSyntaxList;
|
|
131
200
|
function passThroughNameBeingAssigned(node) {
|
|
132
201
|
return isSyntaxList(node)
|
|
133
202
|
|| ts.isObjectLiteralExpression(node)
|
|
134
203
|
|| ts.isParenthesizedExpression(node);
|
|
135
204
|
}
|
|
136
|
-
exports.passThroughNameBeingAssigned = passThroughNameBeingAssigned;
|
|
137
205
|
function report(node, depth = 0) {
|
|
138
206
|
const toLog = [(0, util_1.repeat)("\t", depth), ts.SyntaxKind[node.kind], node.kind];
|
|
139
207
|
console.error(...toLog);
|
|
@@ -141,5 +209,4 @@ function report(node, depth = 0) {
|
|
|
141
209
|
report(child, depth + 1);
|
|
142
210
|
}
|
|
143
211
|
}
|
|
144
|
-
exports.report = report;
|
|
145
212
|
//# sourceMappingURL=node-inspection.js.map
|
|
@@ -15,15 +15,29 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
15
15
|
}) : function(o, v) {
|
|
16
16
|
o["default"] = v;
|
|
17
17
|
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
};
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
25
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.
|
|
36
|
+
exports.chooseContainerName = chooseContainerName;
|
|
37
|
+
exports.getIntroducedLocalName = getIntroducedLocalName;
|
|
38
|
+
exports.getNameIfCalledNode = getNameIfCalledNode;
|
|
39
|
+
exports.getNameOfAssignment = getNameOfAssignment;
|
|
40
|
+
exports.getExpressionToAccessObjectMember = getExpressionToAccessObjectMember;
|
|
27
41
|
const ts = __importStar(require("typescript"));
|
|
28
42
|
const node_util_1 = require("../util/node-util");
|
|
29
43
|
const node_inspection_1 = require("./node-inspection");
|
|
@@ -38,9 +52,6 @@ function chooseContainerName(node, variableBeingDefined) {
|
|
|
38
52
|
if (ts.isClassExpression(node)) {
|
|
39
53
|
return getClassExpressionName(node, variableBeingDefined);
|
|
40
54
|
}
|
|
41
|
-
if (ts.isConstructorDeclaration(node)) {
|
|
42
|
-
return "constructor";
|
|
43
|
-
}
|
|
44
55
|
if (ts.isInterfaceDeclaration(node)) {
|
|
45
56
|
return getInterfaceDeclarationName(node);
|
|
46
57
|
}
|
|
@@ -52,7 +63,6 @@ function chooseContainerName(node, variableBeingDefined) {
|
|
|
52
63
|
}
|
|
53
64
|
return undefined;
|
|
54
65
|
}
|
|
55
|
-
exports.chooseContainerName = chooseContainerName;
|
|
56
66
|
function getIntroducedLocalName(node) {
|
|
57
67
|
if (ts.isVariableDeclaration(node)) {
|
|
58
68
|
return (0, node_inspection_1.getIdentifier)(node);
|
|
@@ -77,7 +87,6 @@ function getIntroducedLocalName(node) {
|
|
|
77
87
|
}
|
|
78
88
|
return undefined;
|
|
79
89
|
}
|
|
80
|
-
exports.getIntroducedLocalName = getIntroducedLocalName;
|
|
81
90
|
function getNameIfCalledNode(node) {
|
|
82
91
|
if (ts.isCallExpression(node)) {
|
|
83
92
|
return getCalledFunctionName(node);
|
|
@@ -99,7 +108,6 @@ function getNameIfCalledNode(node) {
|
|
|
99
108
|
}
|
|
100
109
|
return undefined;
|
|
101
110
|
}
|
|
102
|
-
exports.getNameIfCalledNode = getNameIfCalledNode;
|
|
103
111
|
function getNameOfAssignment(node) {
|
|
104
112
|
if (ts.isVariableDeclaration(node)
|
|
105
113
|
|| ts.isPropertyDeclaration(node)
|
|
@@ -116,7 +124,6 @@ function getNameOfAssignment(node) {
|
|
|
116
124
|
}
|
|
117
125
|
return undefined;
|
|
118
126
|
}
|
|
119
|
-
exports.getNameOfAssignment = getNameOfAssignment;
|
|
120
127
|
function getExpressionToAccessObjectMember(node) {
|
|
121
128
|
if (ts.isMethodDeclaration(node)) {
|
|
122
129
|
const [name, requiresDot] = getMethodDeclarationName(node);
|
|
@@ -138,7 +145,6 @@ function getExpressionToAccessObjectMember(node) {
|
|
|
138
145
|
}
|
|
139
146
|
return undefined;
|
|
140
147
|
}
|
|
141
|
-
exports.getExpressionToAccessObjectMember = getExpressionToAccessObjectMember;
|
|
142
148
|
/**
|
|
143
149
|
* @return [name, requires dot syntax]
|
|
144
150
|
*/
|
|
@@ -184,6 +190,9 @@ function getFunctionNodeName(func) {
|
|
|
184
190
|
if (ts.isArrowFunction(func)) {
|
|
185
191
|
return undefined;
|
|
186
192
|
}
|
|
193
|
+
if (ts.isConstructorDeclaration(func)) {
|
|
194
|
+
return "constructor";
|
|
195
|
+
}
|
|
187
196
|
if (ts.isFunctionDeclaration(func)) {
|
|
188
197
|
const functionKeywordIndex = func.getChildren()
|
|
189
198
|
.findIndex(node => node.kind === ts.SyntaxKind.FunctionKeyword);
|
|
@@ -18,15 +18,29 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
18
18
|
}) : function(o, v) {
|
|
19
19
|
o["default"] = v;
|
|
20
20
|
});
|
|
21
|
-
var __importStar = (this && this.__importStar) || function (
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
};
|
|
21
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
22
|
+
var ownKeys = function(o) {
|
|
23
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
24
|
+
var ar = [];
|
|
25
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
26
|
+
return ar;
|
|
27
|
+
};
|
|
28
|
+
return ownKeys(o);
|
|
29
|
+
};
|
|
30
|
+
return function (mod) {
|
|
31
|
+
if (mod && mod.__esModule) return mod;
|
|
32
|
+
var result = {};
|
|
33
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
34
|
+
__setModuleDefault(result, mod);
|
|
35
|
+
return result;
|
|
36
|
+
};
|
|
37
|
+
})();
|
|
28
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.
|
|
39
|
+
exports.getFileOrFolderOutput = getFileOrFolderOutput;
|
|
40
|
+
exports.getFileOutput = getFileOutput;
|
|
41
|
+
exports.getSourceOutput = getSourceOutput;
|
|
42
|
+
exports.getFolderOutput = getFolderOutput;
|
|
43
|
+
exports.programOutput = programOutput;
|
|
30
44
|
const fs_1 = require("fs");
|
|
31
45
|
const path = __importStar(require("path"));
|
|
32
46
|
const ts = __importStar(require("typescript"));
|
|
@@ -45,19 +59,16 @@ async function getFileOrFolderOutput(entryPath) {
|
|
|
45
59
|
return getFileOutput(entryPath);
|
|
46
60
|
}
|
|
47
61
|
}
|
|
48
|
-
exports.getFileOrFolderOutput = getFileOrFolderOutput;
|
|
49
62
|
// API
|
|
50
63
|
async function getFileOutput(filePath) {
|
|
51
64
|
const fileContent = (await fs_1.promises.readFile(filePath)).toString();
|
|
52
65
|
return getSourceOutput(fileContent, path.basename(filePath));
|
|
53
66
|
}
|
|
54
|
-
exports.getFileOutput = getFileOutput;
|
|
55
67
|
// API
|
|
56
68
|
function getSourceOutput(sourceCode, fileName = "") {
|
|
57
69
|
const parsedFile = ts.createSourceFile(fileName, sourceCode, ts.ScriptTarget.Latest, true);
|
|
58
70
|
return (0, cognitive_complexity_1.fileCost)(parsedFile);
|
|
59
71
|
}
|
|
60
|
-
exports.getSourceOutput = getSourceOutput;
|
|
61
72
|
// API
|
|
62
73
|
async function getFolderOutput(folderPath) {
|
|
63
74
|
const folderContents = await fs_1.promises.readdir(folderPath, { withFileTypes: true });
|
|
@@ -66,13 +77,12 @@ async function getFolderOutput(folderPath) {
|
|
|
66
77
|
return getFolderOutput(folderPath + "/" + entry.name);
|
|
67
78
|
}
|
|
68
79
|
// correct extension
|
|
69
|
-
if (entry.name.match(/.*\.[tj]sx?$/) !== null) {
|
|
80
|
+
if (entry.name.match(/.*\.[cm]?[tj]sx?$/) !== null) {
|
|
70
81
|
return getFileOutput(folderPath + "/" + entry.name);
|
|
71
82
|
}
|
|
72
83
|
return undefined;
|
|
73
84
|
});
|
|
74
85
|
}
|
|
75
|
-
exports.getFolderOutput = getFolderOutput;
|
|
76
86
|
// API
|
|
77
87
|
/**
|
|
78
88
|
* @param entryPath Relative to cwd
|
|
@@ -90,5 +100,4 @@ async function programOutput(entryPath) {
|
|
|
90
100
|
return value;
|
|
91
101
|
});
|
|
92
102
|
}
|
|
93
|
-
exports.programOutput = programOutput;
|
|
94
103
|
//# sourceMappingURL=output.js.map
|
package/build/src/json.js
CHANGED
|
@@ -15,13 +15,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
15
15
|
}) : function(o, v) {
|
|
16
16
|
o["default"] = v;
|
|
17
17
|
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
};
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
25
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
36
|
const path = __importStar(require("path"));
|
|
27
37
|
const process = __importStar(require("process"));
|
|
@@ -15,15 +15,25 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
15
15
|
}) : function(o, v) {
|
|
16
16
|
o["default"] = v;
|
|
17
17
|
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
};
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
25
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.createUiServer =
|
|
36
|
+
exports.createUiServer = createUiServer;
|
|
27
37
|
const fs_1 = require("fs");
|
|
28
38
|
const http = __importStar(require("http"));
|
|
29
39
|
const path = __importStar(require("path"));
|
|
@@ -47,7 +57,6 @@ function createUiServer(combinedOutputsJson) {
|
|
|
47
57
|
res.end();
|
|
48
58
|
});
|
|
49
59
|
}
|
|
50
|
-
exports.createUiServer = createUiServer;
|
|
51
60
|
function cached(res) {
|
|
52
61
|
res.setHeader("Cache-Control", "max-age=365000000; immutable");
|
|
53
62
|
}
|
package/build/src/util/util.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
export declare function countNotAtTheEnds<T>(arr: T[], count: (elem: T) => boolean): number;
|
|
2
1
|
export declare function doesNotThrow<T>(promise: Promise<T>): Promise<boolean>;
|
|
3
2
|
/**
|
|
4
3
|
* Builds an object from a list of keys whose values are based on the key itself,
|
|
@@ -17,7 +16,6 @@ export declare function keysToAsyncValues<K extends keyof any, V>(keys: K[], toV
|
|
|
17
16
|
export declare function createObjectOfPromisedValues<I, K extends keyof any, V>(inputs: I[], toKey: (input: I) => K, toMaybePromise: (input: I) => Promise<V> | undefined): Promise<Record<K, V>>;
|
|
18
17
|
export declare function nonNaN(num: number, fallback: number): number;
|
|
19
18
|
export declare function repeat(str: string, times: number): string;
|
|
20
|
-
export declare function toPromise<T, E>(action: (callback: (err: E, successData: T) => void) => void, errorTransformer?: (err: E) => Error): Promise<T>;
|
|
21
19
|
export declare class Unreachable extends Error {
|
|
22
20
|
constructor(reason: string);
|
|
23
21
|
}
|
package/build/src/util/util.js
CHANGED
|
@@ -1,19 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Unreachable =
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
for (let i = 1; i < arr.length - 2; i++) {
|
|
10
|
-
if (count(arr[i])) {
|
|
11
|
-
tot += 1;
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
return tot;
|
|
15
|
-
}
|
|
16
|
-
exports.countNotAtTheEnds = countNotAtTheEnds;
|
|
3
|
+
exports.Unreachable = void 0;
|
|
4
|
+
exports.doesNotThrow = doesNotThrow;
|
|
5
|
+
exports.keysToAsyncValues = keysToAsyncValues;
|
|
6
|
+
exports.createObjectOfPromisedValues = createObjectOfPromisedValues;
|
|
7
|
+
exports.nonNaN = nonNaN;
|
|
8
|
+
exports.repeat = repeat;
|
|
17
9
|
async function doesNotThrow(promise) {
|
|
18
10
|
try {
|
|
19
11
|
await promise;
|
|
@@ -23,7 +15,6 @@ async function doesNotThrow(promise) {
|
|
|
23
15
|
return false;
|
|
24
16
|
}
|
|
25
17
|
}
|
|
26
|
-
exports.doesNotThrow = doesNotThrow;
|
|
27
18
|
/**
|
|
28
19
|
* Builds an object from a list of keys whose values are based on the key itself,
|
|
29
20
|
* but where that value is produced asynchronously.
|
|
@@ -43,7 +34,6 @@ async function keysToAsyncValues(keys, toValue) {
|
|
|
43
34
|
await Promise.all(promises);
|
|
44
35
|
return output;
|
|
45
36
|
}
|
|
46
|
-
exports.keysToAsyncValues = keysToAsyncValues;
|
|
47
37
|
/**
|
|
48
38
|
* Builds an object from a list of input items.
|
|
49
39
|
* The keys and values are derived from the input item,
|
|
@@ -70,14 +60,12 @@ async function createObjectOfPromisedValues(inputs, toKey, toMaybePromise) {
|
|
|
70
60
|
await Promise.all(promises);
|
|
71
61
|
return output;
|
|
72
62
|
}
|
|
73
|
-
exports.createObjectOfPromisedValues = createObjectOfPromisedValues;
|
|
74
63
|
function nonNaN(num, fallback) {
|
|
75
64
|
if (Number.isNaN(num)) {
|
|
76
65
|
return fallback;
|
|
77
66
|
}
|
|
78
67
|
return num;
|
|
79
68
|
}
|
|
80
|
-
exports.nonNaN = nonNaN;
|
|
81
69
|
function repeat(str, times) {
|
|
82
70
|
let res = "";
|
|
83
71
|
for (let i = 0; i < times; i++) {
|
|
@@ -85,20 +73,6 @@ function repeat(str, times) {
|
|
|
85
73
|
}
|
|
86
74
|
return res;
|
|
87
75
|
}
|
|
88
|
-
exports.repeat = repeat;
|
|
89
|
-
function toPromise(action, errorTransformer) {
|
|
90
|
-
return new Promise((resolve, reject) => {
|
|
91
|
-
action((err, successData) => {
|
|
92
|
-
if (err) {
|
|
93
|
-
reject(errorTransformer ? errorTransformer(err) : err);
|
|
94
|
-
}
|
|
95
|
-
else {
|
|
96
|
-
resolve(successData);
|
|
97
|
-
}
|
|
98
|
-
});
|
|
99
|
-
});
|
|
100
|
-
}
|
|
101
|
-
exports.toPromise = toPromise;
|
|
102
76
|
class Unreachable extends Error {
|
|
103
77
|
constructor(reason) {
|
|
104
78
|
super("Unreachable branch.\n" + reason);
|