es6-shim icon indicating copy to clipboard operation
es6-shim copied to clipboard

babel-polyfill and es6-shim

Open gnh1201 opened this issue 4 years ago • 8 comments

Related items

  • babel-polyfill: https://cdnjs.com/libraries/babel-polyfill
  • Pull request https://github.com/paulmillr/es6-shim/pull/466
  • Issue https://github.com/es-shims/es5-shim/issues/476

Description

To run ES5 or higher Javascript on WSH(Windows Scripting Host), we need a babel-polyfill. for example:

function _extend(dst) {
  for (var _len = arguments.length, sources = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
    sources[_key - 1] = arguments[_key];
  }

  if (dst && sources) {
    var _loop = function _loop(src) {
      if ((typeof src === 'undefined' ? 'undefined' : _typeof(src)) === 'object') {
        Object.getOwnPropertyNames(src).forEach(function (key) {
          dst[key] = src[key];
        });
      }
    };

    var _iteratorNormalCompletion = true;
    var _didIteratorError = false;
    var _iteratorError = undefined;

    try {
      for (var _iterator = sources[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
        var src = _step.value;

        _loop(src);
      }
    } catch (err) {
      _didIteratorError = true;
      _iteratorError = err;
    } finally {
      try {
        if (!_iteratorNormalCompletion && _iterator.RETURN) {  // es5: _iterator.return, babel: _iterator.RETURN
          _iterator.RETURN();
        }
      } finally {
        if (_didIteratorError) {
          throw _iteratorError;
        }
      }
    }
  }

  return dst;
};

This code works well with only babel-polyfill and es5 shim and sham. The problem occurs when adding es6-shim here.

In this case, it should be changed as below to works.

  var defineProperty = function (object, name, value, force) {
    if (!object || (!force && name in object)) { return; }

This change has also been proposed in https://github.com/paulmillr/es6-shim/pull/466.

I think that this change should apply. Or a better idea?

gnh1201 avatar Apr 29 '21 09:04 gnh1201

This code works well with only babel-polyfill and es5 shim and sham. The problem occurs when adding es6-shim here.

gnh1201 avatar Apr 29 '21 09:04 gnh1201

Is this still an issue after #466 is merged?

ljharb avatar Apr 29 '21 23:04 ljharb

Yes. This seems to be another problem. I'll track it down.

gnh1201 avatar Apr 30 '21 00:04 gnh1201

shimtest.js: https://gist.github.com/gnh1201/2627d860e41f8bd2dba858536836c64e

gnh1201 avatar Apr 30 '21 00:04 gnh1201

@gnh1201 why do you need both - core-js and es-shims? It's a bad practice. What does es-shims fix in this case? BTW babel-polyfill is obsolete for a long time ago and the actual version of core-js should be used directly.

zloirock avatar Apr 30 '21 03:04 zloirock

@zloirock I had no choice but to choose babel-polyfill and es5-shim. It worked well and successfully executed the JS library file written in ES5. Trying es6-shim was an option for me, but I thought I'd still test it.

gnh1201 avatar Apr 30 '21 04:04 gnh1201

While most of the es-shims should work fine alongside core-js, it's definitely odd to mix them.

I would expect that es5-shim and es6-shim alone could get you mostly up to speed, except for the Symbol shams that core-js includes but es6-shim does not.

ljharb avatar Apr 30 '21 23:04 ljharb

I tested core-js and confirmed that the example code works well. But I still have to wait and see. I think I need to check the impact when es-shims is excluded from my project.

gnh1201 avatar Jul 29 '21 10:07 gnh1201