Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
var MESSAGE =
'Using the delete operator on a property will cause the shape of ' +
'the object to change. This will lead to JS engine to de-optimize ' +
'read and writes to this object.';
// For now this rule is very pessimistic to limit false positives. It only
// covers case of form: delete this.<identifier>;
module.exports = function rule(context) {
return {
UnaryExpression: function(node) {
if (node.operator !== 'delete') {
return;
}
var deleteArg = node.argument;
if (deleteArg.type !== 'MemberExpression') {
return;
}
var obj = deleteArg.object;
var property = deleteArg.property;
if (obj.type !== 'ThisExpression') {
return;
}
if (property.type !== 'Identifier') {
return;
}
context.report(node, MESSAGE);
},
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment