@jetshop/format-message-estree-util 6.1.4 → 6.2.13
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/index.js +84 -3
- package/package.json +2 -2
package/index.js
CHANGED
|
@@ -44,12 +44,13 @@ exports = module.exports = {
|
|
|
44
44
|
if (context && context.type === 'eslint') {
|
|
45
45
|
var scope = context.context.getScope();
|
|
46
46
|
while (!binding && scope) {
|
|
47
|
-
var ref = scope.variables.
|
|
47
|
+
var ref = scope.variables.find(function(variable) {
|
|
48
48
|
return variable.name === node.name;
|
|
49
|
-
})
|
|
49
|
+
});
|
|
50
50
|
binding = ref && ref.defs && ref.defs[0];
|
|
51
51
|
scope = scope.upper;
|
|
52
52
|
}
|
|
53
|
+
|
|
53
54
|
return binding;
|
|
54
55
|
}
|
|
55
56
|
},
|
|
@@ -68,7 +69,43 @@ exports = module.exports = {
|
|
|
68
69
|
);
|
|
69
70
|
},
|
|
70
71
|
|
|
72
|
+
isImportIntlContext: function(binding) {
|
|
73
|
+
if (!binding || !binding.node) return false;
|
|
74
|
+
|
|
75
|
+
var node = binding.node;
|
|
76
|
+
var parent = binding.path ? binding.path.parentPath.node : node.parent;
|
|
77
|
+
|
|
78
|
+
return (
|
|
79
|
+
parent &&
|
|
80
|
+
parent.source &&
|
|
81
|
+
this.isStringLiteral(parent.source) &&
|
|
82
|
+
MODULE_NAME_PATTERN.test(parent.source.value) &&
|
|
83
|
+
node.type === 'ImportSpecifier' &&
|
|
84
|
+
node.imported &&
|
|
85
|
+
node.imported.name === 'Intl'
|
|
86
|
+
);
|
|
87
|
+
},
|
|
88
|
+
|
|
89
|
+
isImportUseIntl: function(binding) {
|
|
90
|
+
if (!binding || !binding.node) return false;
|
|
91
|
+
|
|
92
|
+
var node = binding.node;
|
|
93
|
+
var parent = binding.path ? binding.path.parentPath.node : node.parent;
|
|
94
|
+
|
|
95
|
+
return (
|
|
96
|
+
parent &&
|
|
97
|
+
parent.source &&
|
|
98
|
+
this.isStringLiteral(parent.source) &&
|
|
99
|
+
MODULE_NAME_PATTERN.test(parent.source.value) &&
|
|
100
|
+
node.type === 'ImportSpecifier' &&
|
|
101
|
+
node.imported &&
|
|
102
|
+
node.imported.name === 'useIntl'
|
|
103
|
+
);
|
|
104
|
+
},
|
|
105
|
+
|
|
71
106
|
isImportFormatMessage: function(binding) {
|
|
107
|
+
if (!binding || !binding.node) return false;
|
|
108
|
+
|
|
72
109
|
var node = binding.node;
|
|
73
110
|
var parent = binding.path ? binding.path.parentPath.node : node.parent;
|
|
74
111
|
return (
|
|
@@ -97,6 +134,48 @@ exports = module.exports = {
|
|
|
97
134
|
);
|
|
98
135
|
},
|
|
99
136
|
|
|
137
|
+
isIntlContextCall: function(binding) {
|
|
138
|
+
if (!binding || !binding.node) return false;
|
|
139
|
+
|
|
140
|
+
var parent = binding.path ? binding.path.parentPath : binding.node.parent;
|
|
141
|
+
if (!parent) return false;
|
|
142
|
+
|
|
143
|
+
var element = parent.parentPath
|
|
144
|
+
? parent.parentPath &&
|
|
145
|
+
parent.parentPath.parentPath &&
|
|
146
|
+
parent.parentPath.parentPath.node
|
|
147
|
+
: parent.parent;
|
|
148
|
+
|
|
149
|
+
if (!element || !element.openingElement) {
|
|
150
|
+
return false;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
var openingElement = element.openingElement;
|
|
154
|
+
|
|
155
|
+
if (openingElement.name && openingElement.name.type === 'JSXIdentifier') {
|
|
156
|
+
return this.isImportIntlContext(this.getBinding(openingElement.name));
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
return false;
|
|
160
|
+
},
|
|
161
|
+
|
|
162
|
+
isUseIntlCall: function(binding) {
|
|
163
|
+
if (!binding || !binding.node) return false;
|
|
164
|
+
|
|
165
|
+
if (
|
|
166
|
+
binding.node.type === 'VariableDeclarator' &&
|
|
167
|
+
binding.node.init &&
|
|
168
|
+
binding.node.init.type === 'CallExpression'
|
|
169
|
+
) {
|
|
170
|
+
const callee = this.getBinding(binding.node.init.callee);
|
|
171
|
+
if (!callee || !callee.node) return false;
|
|
172
|
+
|
|
173
|
+
return this.isImportUseIntl(callee);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
return false;
|
|
177
|
+
},
|
|
178
|
+
|
|
100
179
|
isFormatMessage: function(node) {
|
|
101
180
|
if (node.type !== 'Identifier') return false;
|
|
102
181
|
var binding = this.getBinding(node);
|
|
@@ -107,7 +186,9 @@ exports = module.exports = {
|
|
|
107
186
|
(binding.node.type === 'VariableDeclarator' &&
|
|
108
187
|
binding.node.id.type === 'Identifier' &&
|
|
109
188
|
binding.node.init &&
|
|
110
|
-
this.isRequireFormatMessage(binding.node.init))
|
|
189
|
+
this.isRequireFormatMessage(binding.node.init)) ||
|
|
190
|
+
this.isIntlContextCall(binding) ||
|
|
191
|
+
this.isUseIntlCall(binding)
|
|
111
192
|
);
|
|
112
193
|
},
|
|
113
194
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jetshop/format-message-estree-util",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.2.13",
|
|
4
4
|
"description": "Utility functions for format-message use in ECMAScript ASTs",
|
|
5
5
|
"author": "Andy VanWagoner <andy@vanwago.net>",
|
|
6
6
|
"homepage": "https://github.com/format-message/format-message/tree/master/packages/format-message-estree-util",
|
|
@@ -11,5 +11,5 @@
|
|
|
11
11
|
"format-message",
|
|
12
12
|
"estree"
|
|
13
13
|
],
|
|
14
|
-
"gitHead": "
|
|
14
|
+
"gitHead": "eabf53eca2e7d617a9de16fed4c640769c1f994c"
|
|
15
15
|
}
|