Re: es-discuss Digest, Vol 94, Issue 84

2014-12-25 Thread Isiah Meadows
That search (`/([']?)enumerable\1\s:\strue/`) would miss quite a few
intentional cases as well, because IIRC Object.create and friends default
to false for each of the descriptors, enumerable, configurable, and
writable. Maybe, that could be better run with this ast-types visitor or
similar? Note that I typed this on a phone, and thus is untested and
possibly with a lot of typos in it as well, given it's easy to miss a key.

```js
// count = 0;
visitCallExpression: function (path) {
  var node = path.node;
  function eqish(a, b) {
return Object.keys(b)
.every(function (key) {
  if (!(key in a)) return false;
  var propA = a[key], propB = b[key];
  if (typeof propB !== 'object' ||
  propA === null)
return propA !== propB ||
  propA !== propA;  // NaN
  return eqish(propA, propB);
});
  }
  function ident(str) {
return {type: 'Identifier', name: str};
  }
  function literal(val) {
return {type: 'Literal', value: val};
  }
  function c(str) {
return {
  type: 'MemberExpression',
  object: ident('Object'),
  property: ident(str),
  computed: false
};
  }
  function helper(args) {
var cond = (args.length = 1 ||
  args[1].type !== 'ObjectExpression' ||
  !args.some(function (node) {
return eqish(node, stringEnum) ||
  eqish(node, identEnum);
  }) ||
  !args.every(function (node) {
return eqish(stringEnumish, node) ||
  eqish(identEnumish, node);
  }));
  if (cond) count++
  return cond;
  }
  var stringEnum = {
type: 'Property',
key: literal('enumerable'),
value: literal(false),
kind: 'init',
  };
  var identEnum = {
type: 'Property',
key: ident('enumerable'),
value: literal(false),
kind: 'init',
  };
  var stringEnumish = {
type: 'Property',
key: literal('enumerable'),
value: literal(false),
kind: 'init',
  };
  var identEnumish = {
type: 'Property',
key: ident('enumerable'),
value: literal(false),
kind: 'init',
  };
  var O_dPs = c('defineProperties');
  var O_c = c('create')
  var O_dP = c('defineProperty');
  var callee = node.callee;
  var args = node.arguments;
  if (eqish(callee, O_dP))
return helper(args);
  if (eqish(callee, O_dPs) ||
  eqish(callee, O_c))
return args.every(function (spec) {
  return helper(Object.keys(spec));
});
  return false;
},
```
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: classes and enumerability

2014-12-25 Thread Andrea Giammarchi
Considered how this thread started and the exact day of the year a common
agreement happened, I believe the following ending would be more than
appropriate:


Ho Ho Ho
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss