@@ -16,13 +16,23 @@ function negate(f) {
16
16
return negate0 . bind ( f )
17
17
}
18
18
19
+ /**
20
+ * Checks if the given token is a PunctuatorToken with the given value
21
+ * @param {Token } token - The token to check.
22
+ * @param {string } value - The value to check.
23
+ * @returns {boolean } `true` if the token is a PunctuatorToken with the given value.
24
+ */
25
+ function isPunctuatorTokenWithValue ( token , value ) {
26
+ return token . type === "Punctuator" && token . value === value
27
+ }
28
+
19
29
/**
20
30
* Checks if the given token is an arrow token or not.
21
31
* @param {Token } token - The token to check.
22
32
* @returns {boolean } `true` if the token is an arrow token.
23
33
*/
24
34
export function isArrowToken ( token ) {
25
- return token . value === "=>" && token . type === "Punctuator"
35
+ return isPunctuatorTokenWithValue ( token , "=>" )
26
36
}
27
37
28
38
/**
@@ -31,7 +41,7 @@ export function isArrowToken(token) {
31
41
* @returns {boolean } `true` if the token is a comma token.
32
42
*/
33
43
export function isCommaToken ( token ) {
34
- return token . value === "," && token . type === "Punctuator"
44
+ return isPunctuatorTokenWithValue ( token , "," )
35
45
}
36
46
37
47
/**
@@ -40,7 +50,7 @@ export function isCommaToken(token) {
40
50
* @returns {boolean } `true` if the token is a semicolon token.
41
51
*/
42
52
export function isSemicolonToken ( token ) {
43
- return token . value === ";" && token . type === "Punctuator"
53
+ return isPunctuatorTokenWithValue ( token , ";" )
44
54
}
45
55
46
56
/**
@@ -49,7 +59,7 @@ export function isSemicolonToken(token) {
49
59
* @returns {boolean } `true` if the token is a colon token.
50
60
*/
51
61
export function isColonToken ( token ) {
52
- return token . value === ":" && token . type === "Punctuator"
62
+ return isPunctuatorTokenWithValue ( token , ":" )
53
63
}
54
64
55
65
/**
@@ -58,7 +68,7 @@ export function isColonToken(token) {
58
68
* @returns {boolean } `true` if the token is an opening parenthesis token.
59
69
*/
60
70
export function isOpeningParenToken ( token ) {
61
- return token . value === "(" && token . type === "Punctuator"
71
+ return isPunctuatorTokenWithValue ( token , "(" )
62
72
}
63
73
64
74
/**
@@ -67,7 +77,7 @@ export function isOpeningParenToken(token) {
67
77
* @returns {boolean } `true` if the token is a closing parenthesis token.
68
78
*/
69
79
export function isClosingParenToken ( token ) {
70
- return token . value === ")" && token . type === "Punctuator"
80
+ return isPunctuatorTokenWithValue ( token , ")" )
71
81
}
72
82
73
83
/**
@@ -76,7 +86,7 @@ export function isClosingParenToken(token) {
76
86
* @returns {boolean } `true` if the token is an opening square bracket token.
77
87
*/
78
88
export function isOpeningBracketToken ( token ) {
79
- return token . value === "[" && token . type === "Punctuator"
89
+ return isPunctuatorTokenWithValue ( token , "[" )
80
90
}
81
91
82
92
/**
@@ -85,7 +95,7 @@ export function isOpeningBracketToken(token) {
85
95
* @returns {boolean } `true` if the token is a closing square bracket token.
86
96
*/
87
97
export function isClosingBracketToken ( token ) {
88
- return token . value === "]" && token . type === "Punctuator"
98
+ return isPunctuatorTokenWithValue ( token , "]" )
89
99
}
90
100
91
101
/**
@@ -94,7 +104,7 @@ export function isClosingBracketToken(token) {
94
104
* @returns {boolean } `true` if the token is an opening brace token.
95
105
*/
96
106
export function isOpeningBraceToken ( token ) {
97
- return token . value === "{" && token . type === "Punctuator"
107
+ return isPunctuatorTokenWithValue ( token , "{" )
98
108
}
99
109
100
110
/**
@@ -103,7 +113,7 @@ export function isOpeningBraceToken(token) {
103
113
* @returns {boolean } `true` if the token is a closing brace token.
104
114
*/
105
115
export function isClosingBraceToken ( token ) {
106
- return token . value === "}" && token . type === "Punctuator"
116
+ return isPunctuatorTokenWithValue ( token , "}" )
107
117
}
108
118
109
119
/**
@@ -112,11 +122,7 @@ export function isClosingBraceToken(token) {
112
122
* @returns {boolean } `true` if the token is a comment token.
113
123
*/
114
124
export function isCommentToken ( token ) {
115
- return (
116
- token . type === "Line" ||
117
- token . type === "Block" ||
118
- token . type === "Shebang"
119
- )
125
+ return [ "Block" , "Line" , "Shebang" ] . includes ( token . type )
120
126
}
121
127
122
128
export const isNotArrowToken = negate ( isArrowToken )
0 commit comments