@lvce-editor/eslint-plugin-virtual-dom 17.0.2 → 17.1.0
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/dist/index.js +32 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -150,6 +150,35 @@ const isStaticIdentifier = (sourceCode, node) => {
|
|
|
150
150
|
const variable = findVariable(sourceCode, node);
|
|
151
151
|
return Boolean(variable && isStaticModuleVariable(variable));
|
|
152
152
|
};
|
|
153
|
+
const isPropertyMutation = (sourceCode, identifier) => {
|
|
154
|
+
const ancestors = sourceCode.getAncestors(identifier);
|
|
155
|
+
let current = identifier;
|
|
156
|
+
for (let i = ancestors.length - 1; i >= 0; i--) {
|
|
157
|
+
const parent = ancestors[i];
|
|
158
|
+
if (parent.type === 'MemberExpression' && parent.object === current) {
|
|
159
|
+
current = parent;
|
|
160
|
+
continue;
|
|
161
|
+
}
|
|
162
|
+
return parent.type === 'AssignmentExpression' && parent.left === current || parent.type === 'UpdateExpression' && parent.argument === current || parent.type === 'UnaryExpression' && parent.operator === 'delete' && parent.argument === current;
|
|
163
|
+
}
|
|
164
|
+
return false;
|
|
165
|
+
};
|
|
166
|
+
const isMutatedVariable = (sourceCode, variable) => {
|
|
167
|
+
return variable.references.some(reference => {
|
|
168
|
+
if (!reference.init && reference.isWrite()) {
|
|
169
|
+
return true;
|
|
170
|
+
}
|
|
171
|
+
return reference.identifier.type === 'Identifier' && isPropertyMutation(sourceCode, reference.identifier);
|
|
172
|
+
});
|
|
173
|
+
};
|
|
174
|
+
const isMutatedObject = (sourceCode, node) => {
|
|
175
|
+
const parent = sourceCode.getAncestors(node).at(-1);
|
|
176
|
+
if (parent?.type !== 'VariableDeclarator' || parent.init !== node || parent.id.type !== 'Identifier') {
|
|
177
|
+
return false;
|
|
178
|
+
}
|
|
179
|
+
const variable = findVariable(sourceCode, parent.id);
|
|
180
|
+
return Boolean(variable && isMutatedVariable(sourceCode, variable));
|
|
181
|
+
};
|
|
153
182
|
const isVirtualDomElement = node => {
|
|
154
183
|
if (!isVirtualDomNode(node) || !hasProperty(node, 'childCount')) {
|
|
155
184
|
return false;
|
|
@@ -206,6 +235,9 @@ const create$b = context => {
|
|
|
206
235
|
if (!isStaticExpression(context.sourceCode, node)) {
|
|
207
236
|
return;
|
|
208
237
|
}
|
|
238
|
+
if (isMutatedObject(context.sourceCode, node)) {
|
|
239
|
+
return;
|
|
240
|
+
}
|
|
209
241
|
context.report({
|
|
210
242
|
messageId: 'hoistStaticNode',
|
|
211
243
|
node
|