1
- import { TSESTree , AST_NODE_TYPES } from '@typescript-eslint/typescript-estree' ;
1
+ import { TSESTree } from '@typescript-eslint/typescript-estree' ;
2
2
import { Scope } from 'eslint' ;
3
3
4
4
export interface MessageDescriptor {
@@ -14,7 +14,7 @@ export interface MessageDescriptorNodeInfo {
14
14
}
15
15
16
16
function isStringLiteral ( node : TSESTree . Node ) : node is TSESTree . StringLiteral {
17
- return node . type === AST_NODE_TYPES . Literal && typeof node . value === 'string' ;
17
+ return node . type === " Literal" && typeof node . value === 'string' ;
18
18
}
19
19
20
20
function findReferenceImport (
@@ -28,22 +28,22 @@ function findReferenceImport(
28
28
29
29
function isIntlFormatMessageCall ( node : TSESTree . Node ) {
30
30
return (
31
- node . type === AST_NODE_TYPES . CallExpression &&
32
- node . callee . type === AST_NODE_TYPES . MemberExpression &&
33
- node . callee . object . type === AST_NODE_TYPES . Identifier &&
31
+ node . type === " CallExpression" &&
32
+ node . callee . type === " MemberExpression" &&
33
+ node . callee . object . type === " Identifier" &&
34
34
node . callee . object . name === 'intl' &&
35
- node . callee . property . type === AST_NODE_TYPES . Identifier &&
35
+ node . callee . property . type === " Identifier" &&
36
36
node . callee . property . name === 'formatMessage' &&
37
37
node . arguments . length >= 1 &&
38
- node . arguments [ 0 ] . type === AST_NODE_TYPES . ObjectExpression
38
+ node . arguments [ 0 ] . type === " ObjectExpression"
39
39
) ;
40
40
}
41
41
42
42
function isSingleMessageDescriptorDeclaration (
43
43
id : TSESTree . LeftHandSideExpression ,
44
44
importedVars : Scope . Variable [ ]
45
45
) {
46
- if ( id . type !== AST_NODE_TYPES . Identifier ) {
46
+ if ( id . type !== " Identifier" ) {
47
47
return false ;
48
48
}
49
49
const importedVar = findReferenceImport ( id , importedVars ) ;
@@ -56,7 +56,7 @@ function isMultipleMessageDescriptorDeclaration(
56
56
id : TSESTree . LeftHandSideExpression ,
57
57
importedVars : Scope . Variable [ ]
58
58
) {
59
- if ( id . type !== AST_NODE_TYPES . Identifier ) {
59
+ if ( id . type !== " Identifier" ) {
60
60
return false ;
61
61
}
62
62
const importedVar = findReferenceImport ( id , importedVars ) ;
@@ -69,7 +69,7 @@ function isMultipleMessageDescriptorDeclaration(
69
69
function extractMessageDescriptor (
70
70
node ?: TSESTree . Expression
71
71
) : MessageDescriptorNodeInfo | undefined {
72
- if ( ! node || node . type !== AST_NODE_TYPES . ObjectExpression ) {
72
+ if ( ! node || node . type !== " ObjectExpression" ) {
73
73
return ;
74
74
}
75
75
const result : MessageDescriptorNodeInfo = {
@@ -79,8 +79,8 @@ function extractMessageDescriptor(
79
79
} ;
80
80
for ( const prop of node . properties ) {
81
81
if (
82
- prop . type !== AST_NODE_TYPES . Property ||
83
- prop . key . type !== AST_NODE_TYPES . Identifier
82
+ prop . type !== " Property" ||
83
+ prop . key . type !== " Identifier"
84
84
) {
85
85
continue ;
86
86
}
@@ -118,8 +118,8 @@ function extractMessageDescriptorFromJSXElement(
118
118
} ;
119
119
for ( const prop of node . attributes ) {
120
120
if (
121
- prop . type !== AST_NODE_TYPES . JSXAttribute ||
122
- prop . name . type !== AST_NODE_TYPES . JSXIdentifier
121
+ prop . type !== " JSXAttribute" ||
122
+ prop . name . type !== " JSXIdentifier"
123
123
) {
124
124
continue ;
125
125
}
@@ -128,7 +128,7 @@ function extractMessageDescriptorFromJSXElement(
128
128
case 'defaultMessage' :
129
129
result . messageNode = prop . value ;
130
130
if (
131
- prop . value ?. type === AST_NODE_TYPES . Literal &&
131
+ prop . value ?. type === " Literal" &&
132
132
typeof prop . value . value === 'string'
133
133
) {
134
134
result . message . defaultMessage = prop . value . value ;
@@ -137,24 +137,24 @@ function extractMessageDescriptorFromJSXElement(
137
137
case 'description' :
138
138
result . descriptionNode = prop . value ;
139
139
if (
140
- prop . value ?. type === AST_NODE_TYPES . Literal &&
140
+ prop . value ?. type === " Literal" &&
141
141
typeof prop . value . value === 'string'
142
142
) {
143
143
result . message . description = prop . value . value ;
144
144
}
145
145
break ;
146
146
case 'id' :
147
147
if (
148
- prop . value ?. type === AST_NODE_TYPES . Literal &&
148
+ prop . value ?. type === " Literal" &&
149
149
typeof prop . value . value === 'string'
150
150
) {
151
151
result . message . id = prop . value . value ;
152
152
}
153
153
break ;
154
154
case 'values' :
155
155
if (
156
- prop . value ?. type === AST_NODE_TYPES . JSXExpressionContainer &&
157
- prop . value . expression . type === AST_NODE_TYPES . ObjectExpression
156
+ prop . value ?. type === " JSXExpressionContainer" &&
157
+ prop . value . expression . type === " ObjectExpression"
158
158
) {
159
159
values = prop . value . expression ;
160
160
}
@@ -170,18 +170,18 @@ function extractMessageDescriptorFromJSXElement(
170
170
function extractMessageDescriptors ( node ?: TSESTree . Expression ) {
171
171
if (
172
172
! node ||
173
- node . type !== AST_NODE_TYPES . ObjectExpression ||
173
+ node . type !== " ObjectExpression" ||
174
174
! node . properties . length
175
175
) {
176
176
return [ ] ;
177
177
}
178
178
const msgs = [ ] ;
179
179
for ( const prop of node . properties ) {
180
- if ( prop . type !== AST_NODE_TYPES . Property ) {
180
+ if ( prop . type !== " Property" ) {
181
181
continue ;
182
182
}
183
183
const msg = prop . value ;
184
- if ( msg . type !== AST_NODE_TYPES . ObjectExpression ) {
184
+ if ( msg . type !== " ObjectExpression" ) {
185
185
continue ;
186
186
}
187
187
const nodeInfo = extractMessageDescriptor ( msg ) ;
@@ -197,7 +197,7 @@ export function extractMessages(
197
197
importedMacroVars : Scope . Variable [ ] ,
198
198
excludeMessageDeclCalls = false
199
199
) : Array < [ MessageDescriptorNodeInfo , TSESTree . Expression | undefined ] > {
200
- if ( node . type === AST_NODE_TYPES . CallExpression ) {
200
+ if ( node . type === " CallExpression" ) {
201
201
const expr = node ;
202
202
const fnId = expr . callee ;
203
203
if (
@@ -219,9 +219,9 @@ export function extractMessages(
219
219
] ) ;
220
220
}
221
221
} else if (
222
- node . type === AST_NODE_TYPES . JSXOpeningElement &&
222
+ node . type === " JSXOpeningElement" &&
223
223
node . name &&
224
- node . name . type === AST_NODE_TYPES . JSXIdentifier &&
224
+ node . name . type === " JSXIdentifier" &&
225
225
node . name . name === 'FormattedMessage'
226
226
) {
227
227
const msgDescriptorNodeInfo = extractMessageDescriptorFromJSXElement ( node ) ;
0 commit comments