Skip to content

Commit 220481d

Browse files
committed
Remove some unused helpers
1 parent 4bc488d commit 220481d

File tree

3 files changed

+1
-78
lines changed

3 files changed

+1
-78
lines changed

src/TSHelper.ts

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -29,32 +29,7 @@ const defaultArrayCallMethodNames = new Set<string>([
2929
"flatMap",
3030
]);
3131

32-
const defaultArrayPropertyNames = new Set<string>([
33-
"length",
34-
]);
35-
3632
export class TSHelper {
37-
// Reverse lookup of enum key by value
38-
public static enumName<T>(needle: T, haystack: any): string {
39-
for (const name in haystack) {
40-
if (haystack[name] === needle) {
41-
return name;
42-
}
43-
}
44-
return "unknown";
45-
}
46-
47-
// Breaks down a mask into all flag names.
48-
public static enumNames<T>(mask: number, haystack: any): string[] {
49-
const result = [];
50-
for (const name in haystack) {
51-
if ((mask & haystack[name]) !== 0 && mask >= haystack[name]) {
52-
result.push(name);
53-
}
54-
}
55-
return result;
56-
}
57-
5833
public static getExtendedTypeNode(node: ts.ClassLikeDeclarationBase, checker: ts.TypeChecker):
5934
ts.ExpressionWithTypeArguments | undefined {
6035
if (node && node.heritageClauses) {
@@ -353,21 +328,6 @@ export class TSHelper {
353328
return [false, undefined];
354329
}
355330

356-
public static isExpressionStatement(node: ts.Expression): boolean {
357-
return node.parent === undefined || ts.isExpressionStatement(node.parent) || ts.isForStatement(node.parent);
358-
}
359-
360-
public static isInGlobalScope(node: ts.Node): boolean {
361-
let parent = node.parent;
362-
while (parent !== undefined) {
363-
if (ts.isBlock(parent)) {
364-
return false;
365-
}
366-
parent = parent.parent;
367-
}
368-
return true;
369-
}
370-
371331
// Returns true for expressions that may have effects when evaluated
372332
public static isExpressionWithEvaluationEffect(node: ts.Expression): boolean {
373333
return !(ts.isLiteralExpression(node) || ts.isIdentifier(node) || node.kind === ts.SyntaxKind.ThisKeyword);
@@ -644,10 +604,6 @@ export class TSHelper {
644604
signatureDeclarations.map(s => TSHelper.getDeclarationContextType(s, checker)));
645605
}
646606

647-
public static isDefaultArrayPropertyName(methodName: string): boolean {
648-
return defaultArrayPropertyNames.has(methodName);
649-
}
650-
651607
public static escapeString(text: string): string {
652608
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String
653609
const escapeSequences: Array<[RegExp, string]> = [

src/TSTLErrors.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,7 @@ export class TSTLErrors {
115115
new TranspileError(`Unsupported import type.`, node);
116116

117117
public static UnsupportedKind = (description: string, kind: ts.SyntaxKind, node: ts.Node) =>
118-
{
119-
const kindName = tsHelper.enumName(kind, ts.SyntaxKind);
120-
return new TranspileError(`Unsupported ${description} kind: ${kindName}`, node);
121-
};
118+
new TranspileError(`Unsupported ${description} kind: ${ts.SyntaxKind[kind]}`, node);
122119

123120
public static UnsupportedProperty = (parentName: string, property: string, node: ts.Node) =>
124121
new TranspileError(`Unsupported property on ${parentName}: ${property}`, node);

test/unit/tshelper.spec.ts

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3,36 +3,6 @@ import { DecoratorKind } from "../../src/Decorator";
33
import { TSHelper as tsHelper } from "../../src/TSHelper";
44
import * as util from "../util";
55

6-
enum TestEnum {
7-
testA = 1,
8-
testB = 2,
9-
testC = 4,
10-
}
11-
12-
test.each([
13-
{ inp: TestEnum.testA, expected: "testA" },
14-
{ inp: -1, expected: "unknown" },
15-
{ inp: TestEnum.testA | TestEnum.testB, expected: "unknown" },
16-
])("EnumName (%p)", ({ inp, expected }) => {
17-
const result = tsHelper.enumName(inp, TestEnum);
18-
19-
expect(result).toEqual(expected);
20-
});
21-
22-
test.each([
23-
{ inp: TestEnum.testA, expected: ["testA"] },
24-
{ inp: -1, expected: [] },
25-
{ inp: TestEnum.testA | TestEnum.testC, expected: ["testA", "testC"] },
26-
{
27-
inp: TestEnum.testA | TestEnum.testB | TestEnum.testC,
28-
expected: ["testA", "testB", "testC"],
29-
},
30-
])("EnumNames (%p)", ({ inp, expected }) => {
31-
const result = tsHelper.enumNames(inp, TestEnum);
32-
33-
expect(result).toEqual(expected);
34-
});
35-
366
test("GetCustomDecorators single", () => {
377
const source = `
388
/** @compileMembersOnly */

0 commit comments

Comments
 (0)