termi / es6-transpiler

Tomorrow's JavaScript syntax today
Other
216 stars 18 forks source link

TypeError: Object ; has no method 'contains' #66

Closed chemerisuk closed 9 years ago

chemerisuk commented 10 years ago

Noticed that the latest version fails to process immediately invoked function with "use strict" on the top:

(function() {
  "use strict";
  ...
}());

with error:

TypeError: Object ; has no method 'contains'.

Just FYI I'm using the project in scope of gulp-es6-transpiler.

chemerisuk commented 10 years ago

I believe the problem here is that you use String#contains that does not exist in ES5.

chemerisuk commented 10 years ago

Submitted PR https://github.com/termi/es6-transpiler/pull/67 with the fix. Please merge it asap

nicoolas25 commented 10 years ago

+1

kobezzza commented 10 years ago

+1

nicoolas25 commented 10 years ago

What about the node version you're using?

I have this error with version 0.10.33. I'm thinking about using version 0.11.14 since it seems to support things like --harmony_strings.

chemerisuk commented 10 years ago

@nicoolas25 well, it will work on 0.11 I guess, but there are some environments where this version can't be used (yet), because it's not stable.

chemerisuk commented 10 years ago

BTW recently String#contains was renamed to String#includes, so the first one is non-standard now. Details here: https://github.com/tc39/Array.prototype.includes#status

maranomynet commented 10 years ago

+1

maranomynet commented 10 years ago

.contains() has been part of transpiler/RegExp.js since March 2014, but only got added to transpiler/core.js last August.

chemerisuk commented 10 years ago

Alright, the real cause of the problem is https://github.com/paulmillr/es6-shim/commit/226517d3742fe382f8a5d07a9b3deb2e54c174c4 that the transpiler uses as a dependency. It explains why we started to have this error only recently.

Not sure if the project is maintained at present, but I found a workaround. You can fix es6-shim to the robust version in your package.json and add install script that removes the dependency from es6-transpiler. In such case the project will use parent version of es6-shim that we specified above. Check example here https://github.com/chemerisuk/better-dom-boilerplate/commit/3f2412315ad2784525ddd77682cbdd6ad43e91a0

maranomynet commented 10 years ago

Err, shouldn't es6-transpiler simply upgrade to use .includes() instead of .contains() ? That sounds like the simplest fix.

nicoolas25 commented 10 years ago

Yep, it should and the author will probably update this soon. In the meantime, we have the @chemerisuk workarround.

monolithed commented 9 years ago

[Fixed] https://github.com/termi/es6-transpiler/commit/4e229240a34570268b75d1ef087d537bc490c86e

chemerisuk commented 9 years ago

I can confirm, it works in 0.7.18. Therefore my workaround can be removed.