Skip to content
This repository was archived by the owner on Jan 14, 2019. It is now read-only.

Commit 4ecdb8b

Browse files
armano2JamesHenry
authored andcommitted
refactor: remove internal typescript method call with hasModifier (#48)
1 parent fb10ef2 commit 4ecdb8b

File tree

2 files changed

+11
-19
lines changed

2 files changed

+11
-19
lines changed

src/convert.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -952,7 +952,7 @@ export default function convert(config: ConvertConfig): ESTreeNode | null {
952952
key: convertChild(node.name),
953953
value: convertChild(node.initializer),
954954
computed: nodeUtils.isComputedProperty(node.name),
955-
static: nodeUtils.hasStaticModifierFlag(node),
955+
static: nodeUtils.hasModifier(SyntaxKind.StaticKeyword, node),
956956
readonly:
957957
nodeUtils.hasModifier(SyntaxKind.ReadonlyKeyword, node) || undefined
958958
});
@@ -1062,7 +1062,7 @@ export default function convert(config: ConvertConfig): ESTreeNode | null {
10621062
key: convertChild(node.name),
10631063
value: method,
10641064
computed: nodeUtils.isComputedProperty(node.name),
1065-
static: nodeUtils.hasStaticModifierFlag(node),
1065+
static: nodeUtils.hasModifier(SyntaxKind.StaticKeyword, node),
10661066
kind: 'method'
10671067
});
10681068

@@ -1107,7 +1107,10 @@ export default function convert(config: ConvertConfig): ESTreeNode | null {
11071107

11081108
// TypeScript uses this even for static methods named "constructor"
11091109
case SyntaxKind.Constructor: {
1110-
const constructorIsStatic = nodeUtils.hasStaticModifierFlag(node),
1110+
const constructorIsStatic = nodeUtils.hasModifier(
1111+
SyntaxKind.StaticKeyword,
1112+
node
1113+
),
11111114
constructorIsAbstract = nodeUtils.hasModifier(
11121115
SyntaxKind.AbstractKeyword,
11131116
node

src/node-utils.ts

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,6 @@ export default {
145145
isJSXToken,
146146
getDeclarationKind,
147147
getTSNodeAccessibility,
148-
hasStaticModifierFlag,
149148
findNextToken,
150149
findFirstMatchingToken,
151150
findChildOfKind,
@@ -206,11 +205,14 @@ function isESTreeClassMember(node: ts.Node): boolean {
206205

207206
/**
208207
* Checks if a ts.Node has a modifier
209-
* @param {number} modifierKind TypeScript SyntaxKind modifier
208+
* @param {ts.KeywordSyntaxKind} modifierKind TypeScript SyntaxKind modifier
210209
* @param {ts.Node} node TypeScript AST node
211210
* @returns {boolean} has the modifier specified
212211
*/
213-
function hasModifier(modifierKind: number, node: ts.Node): boolean {
212+
function hasModifier(
213+
modifierKind: ts.KeywordSyntaxKind,
214+
node: ts.Node
215+
): boolean {
214216
return (
215217
!!node.modifiers &&
216218
!!node.modifiers.length &&
@@ -394,19 +396,6 @@ function getTSNodeAccessibility(node: ts.Node): string | null {
394396
return null;
395397
}
396398

397-
/**
398-
* Returns true if the given ts.Node has the modifier flag set which corresponds
399-
* to the static keyword.
400-
* @param {ts.Node} node The ts.Node
401-
* @returns {boolean} whether or not the static modifier flag is set
402-
*/
403-
function hasStaticModifierFlag(node: ts.Node): boolean {
404-
/**
405-
* TODO: Remove dependency on private TypeScript method
406-
*/
407-
return Boolean((ts as any).getModifierFlags(node) & ts.ModifierFlags.Static);
408-
}
409-
410399
/**
411400
* Finds the next token based on the previous one and its parent
412401
* Had to copy this from TS instead of using TS's version because theirs doesn't pass the ast to getChildren

0 commit comments

Comments
 (0)