Skip to content

Instantly share code, notes, and snippets.

@bgirard
Created January 19, 2017 23:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bgirard/4cd7a2f02f4173a226853bb8b512d09f to your computer and use it in GitHub Desktop.
Save bgirard/4cd7a2f02f4173a226853bb8b512d09f to your computer and use it in GitHub Desktop.
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