MatAtBread / fast-async

605 stars 21 forks source link

About a webpack warning: Duplicate declaration #37

Closed cycold closed 7 years ago

cycold commented 7 years ago

When using await within for..of Here is a warning

webpack: wait until bundle finished:
    Duplicate declaration '_iterator = _isArray ? _iterator : _iterator[Symbol.iterator]()'
    Duplicate declaration '_iterator = _isArray ? _iterator : _iterator[Symbol.iterator]()'

 DONE  Compiled successfully in 5303ms

I'm usingwebpack 2.3.3

Is there a way to remove this warning, I know this is just a Duplicate declaration

When using await within for..of, You can see this warning, like below:

async function loadCityList(Vue, store, city = "") {

  if (store.getters.getCityList.length > 0) return store.getters.getCityList()

  let cityList = await Vue.$api.supplier.getSupplierCityList({city})

  if (cityList.length == 0) return cityList

  let _cityList = []

  for (let city of cityList) {
    city = {
      cityCode: city.city,
      cityName: city.strCity,
      baiduAreaCode: city.baiduAreaCode,
      supplierList: []  
    }

    let supplierList = await Vue.$api.supplier.getSupplierList({
      "city": city.cityCode,
      "userId": 0,
      "weCharOpenId": Vue.$config.weCharOpenId
    })

    city.supplierList = supplierList.map(supplier => {
      return {
        city: city,
        strVal1: supplier.strVal1,
        supplierId: supplier.supplierId,
        supplierLogo: supplier.supplierLogo,
        supplierPic: supplier.supplierPic,
        supplierCode: supplier.supplierCode,
        supplierName: supplier.supplierName,
        supplierFullName: supplier.supplierFullName,
      }
    })
    _cityList.push(city)
  }

after build:

function loadCityList(Vue, store) {
  var $args = arguments;return new Promise(function ($return, $error) {
    var city, cityList, _cityList, _loop, _iterator, _isArray, _i, _ref, _city;

    city = $args.length > 2 && $args[2] !== undefined ? $args[2] : "";

    if (store.getters.getCityList.length > 0) return $return(store.getters.getCityList());

    return Vue.$api.supplier.getSupplierCityList({ city: city }).then(function ($await_3) {
      cityList = $await_3;

      if (cityList.length == 0) return $return(cityList);

      _cityList = [];

      _loop = function _loop(_city2) {
        return new Promise(function ($return, $error) {
          var supplierList;

          _city2 = {
            cityCode: _city2.city,
            cityName: _city2.strCity,
            baiduAreaCode: _city2.baiduAreaCode,
            supplierList: [] };

          return Vue.$api.supplier.getSupplierList({
            "city": _city2.cityCode,
            "userId": 0,
            "weCharOpenId": Vue.$config.weCharOpenId
          }).then(function ($await_4) {
            supplierList = $await_4;

            _city2.supplierList = supplierList.map(function (supplier) {
              return {
                city: _city2,
                strVal1: supplier.strVal1,
                supplierId: supplier.supplierId,
                supplierLogo: supplier.supplierLogo,
                supplierPic: supplier.supplierPic,
                supplierCode: supplier.supplierCode,
                supplierName: supplier.supplierName,
                supplierFullName: supplier.supplierFullName
              };
            });
            _cityList.push(_city2);
            _city = _city2;
            return $return();
          }.$asyncbind(this, $error), $error);
        }.$asyncbind(this));
      };
       // Here is the warning source...
       // Duplicate declaration '_iterator = _isArray ? _iterator : _iterator[Symbol.iterator]()'
      _iterator = cityList, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();
      return Function.$asyncbind.trampoline(this, $Loop_1_exit, $Loop_1, $error, true)($Loop_1);

      function $Loop_1() {
        if (true) {
          if (_isArray) {
            if (_i >= _iterator.length) return [1];
            _ref = _iterator[_i++];
          } else {
            _i = _iterator.next();
            if (_i.done) return [1];
            _ref = _i.value;
          }

          _city = _ref;
          return _loop(_city).then(function ($await_5) {
            return $Loop_1;
          }.$asyncbind(this, $error), $error);
        } else return [1];
      }

      function $Loop_1_exit() {
        store.commit("updateCityList", _cityList);

        store.commit("updateCurrentSupplierId", store.getters.getCurrentSupplierId || _cityList[0].supplierList[0].supplierId);

        store.commit("updateCurrentCityId", store.getters.getCurrentSupplier.city.cityCode);

        return $return(_cityList);
      }
    }.$asyncbind(this, $error), $error);
  }.$asyncbind(this));
}

Here is my .babelrc:

{
  "presets": [
    ["env", {
      "modules": false,
      "debug": false,
      "useBuiltIns": true,
      "loose": true,
      "exclude": [
        // for using fast-async
        "transform-regenerator",
        "transform-async-to-generator",

        "transform-es2015-unicode-regex",
        "transform-exponentiation-operator",
      ]
    }],
    // "stage-3" just use babel-plugin-transform-object-rest-spread
  ],
  "plugins": [
    "babel-plugin-transform-object-rest-spread",
    // https://github.com/MatAtBread/fast-async
    ["fast-async", {
      "env": {
        "augmentObject": false,
        "dontMapStackTraces": true,
        "dontInstallRequireHook": true
      },
      "compiler": {
        "promises": true,
        "generators": false
      },
      "runtimePattern": null,
      // using nodent-runtime like transform-runtime of babel
      "useRuntimeModule": true
    }],
    // "transform-runtime"
  ],
  "comments": false,
  "env": {
    "test": {
      "presets": ["env", "stage-2"],
      "plugins": [ "istanbul" ]
    }
  }
}
matAtWork commented 7 years ago

There's no way to suppress a specific log message, but you can turn all nodent warnings by setting "log":false in the "env" section of the config.

cycold commented 7 years ago

ok, thx.