From bd617e08f7a2524d7edc51f81cfe290f102a85d9 Mon Sep 17 00:00:00 2001
From: theniceangel <theniceangel@163.com>
Date: Wed, 11 Dec 2019 20:44:27 +0800
Subject: [PATCH] perf(all files): remove ES2015

---
 .babelrc                                      | 12 +++----
 src/common/helpers/util.js                    | 36 +++++++++++++++++--
 src/common/helpers/validator/messages.js      |  5 +--
 src/components/date-picker/date-picker.vue    |  6 ++--
 src/components/dialog/dialog.vue              | 11 +++---
 src/components/drawer/drawer.vue              |  4 +--
 src/components/form/fields/index.js           |  5 ++-
 src/components/form/form.vue                  |  4 +--
 src/components/index-list/index-list.vue      |  3 +-
 src/components/input/input.vue                |  6 ++--
 src/components/picker/picker.vue              |  2 +-
 src/components/scroll/scroll.vue              | 11 +++---
 .../segment-picker/segment-picker.vue         | 19 ++++++----
 src/components/slide/slide.vue                |  4 +--
 src/components/textarea/textarea.vue          |  3 +-
 src/components/time-picker/time-picker.vue    |  3 +-
 src/components/upload/util.js                 |  4 ++-
 17 files changed, 89 insertions(+), 49 deletions(-)

diff --git a/.babelrc b/.babelrc
index d364d7a6f..14778d1b5 100644
--- a/.babelrc
+++ b/.babelrc
@@ -5,19 +5,15 @@
       "targets": {
         "browsers": [
           "> 1%",
-          "last 2 versions",
-          "not ie <= 20",
-          "not ie_mob <= 100",
-          "not ff <= 100",
-          "not and_ff <= 100",
-          "not Edge <= 100",
-          "Android >= 4.0"
+          "not ie <= 11",
+          "Android >= 4.0",
+          "iOS >= 8"
         ]
       }
     }],
     "stage-2"
   ],
-  "plugins": ["transform-runtime", "add-module-exports", "transform-es2015-modules-umd"],
+  "plugins": ["transform-runtime"],
   "comments": false,
   "env": {
     "test": {
diff --git a/src/common/helpers/util.js b/src/common/helpers/util.js
index 1c0f8b3b6..aa1ecc6e0 100644
--- a/src/common/helpers/util.js
+++ b/src/common/helpers/util.js
@@ -18,6 +18,32 @@ function findIndex(ary, fn) {
   return index
 }
 
+function assign(target) {
+  const sources = toArray(arguments, 1)
+  sources.forEach(source => {
+    if (!source) {
+      return
+    }
+    let value
+    Object.keys(source).forEach(key => {
+      value = source[key]
+      target[key] = value
+    })
+  })
+
+  return target
+}
+
+function toArray (list, start) {
+  start = start || 0
+  let i = list.length - start
+  let ret = new Array(i)
+  while (i--) {
+    ret[i] = list[i + start]
+  }
+  return ret
+}
+
 function deepAssign(to, from) {
   for (let key in from) {
     if (!to[key] || typeof to[key] !== 'object') {
@@ -29,7 +55,8 @@ function deepAssign(to, from) {
 }
 
 function createAddAPI(baseObj) {
-  return function add(...args) {
+  return function add() {
+    const args = toArray(arguments)
     if (typeof args[0] === 'string') {
       args[0] = {
         [args[0]]: args[1]
@@ -127,7 +154,8 @@ function debounce(func, wait, immediate, initValue) {
     }
   }
 
-  const debounced = function (...args) {
+  const debounced = function () {
+    const args = toArray(arguments)
     if (timeout) {
       clearTimeout(timeout)
     }
@@ -191,6 +219,7 @@ const isNumber = judgeTypeFnCreator('Number')
 export {
   findIndex,
   deepAssign,
+  assign,
   createAddAPI,
   resetTypeValue,
   parallel,
@@ -203,5 +232,6 @@ export {
   isArray,
   isString,
   isObject,
-  isNumber
+  isNumber,
+  toArray
 }
diff --git a/src/common/helpers/validator/messages.js b/src/common/helpers/validator/messages.js
index 2b8c83a43..00743aefb 100644
--- a/src/common/helpers/validator/messages.js
+++ b/src/common/helpers/validator/messages.js
@@ -1,6 +1,7 @@
-import { deepAssign } from '../util'
+import { deepAssign, toArray } from '../util'
 
-function addMessage (...args) {
+function addMessage () {
+  const args = toArray(arguments)
   const NAMESPACE = 'validator'
   const vueProto = this._base.prototype
   const lang = vueProto.$cubeLang
diff --git a/src/components/date-picker/date-picker.vue b/src/components/date-picker/date-picker.vue
index e0e41411c..63afdb468 100644
--- a/src/components/date-picker/date-picker.vue
+++ b/src/components/date-picker/date-picker.vue
@@ -21,7 +21,7 @@
   import popupMixin from '../../common/mixins/popup'
   import pickerMixin from '../../common/mixins/picker'
   import localeMixin from '../../common/mixins/locale'
-  import { deepAssign, findIndex } from '../../common/helpers/util'
+  import { deepAssign, findIndex, assign } from '../../common/helpers/util'
   import { computeNatureMaxDay, formatType } from '../../common/lang/date'
 
   const COMPONENT_NAME = 'cube-date-picker'
@@ -109,7 +109,7 @@
     },
     computed: {
       formatConfig() {
-        const formatConfig = Object.assign({}, DEFAULT_FORMAT)
+        const formatConfig = assign({}, DEFAULT_FORMAT)
         deepAssign(formatConfig, this.format)
 
         return formatConfig
@@ -216,7 +216,7 @@
         // Month need to subtract 1.
         args[1]--
 
-        return new Date(...args)
+        return new Date(args[0], args[1], args[2], args[3], args[4], args[5])
       },
       _range(type, min, max, fatherIsMin, fatherIsMax, year = 0) {
         if (!this._rangeCache) {
diff --git a/src/components/dialog/dialog.vue b/src/components/dialog/dialog.vue
index 509b394b6..4f8e9ee4c 100644
--- a/src/components/dialog/dialog.vue
+++ b/src/components/dialog/dialog.vue
@@ -43,6 +43,7 @@
   import visibilityMixin from '../../common/mixins/visibility'
   import popupMixin from '../../common/mixins/popup'
   import localeMixin from '../../common/mixins/locale'
+  import { assign } from '../../common/helpers/util'
 
   const COMPONENT_NAME = 'cube-dialog'
   const EVENT_CONFIRM = 'confirm'
@@ -69,7 +70,7 @@
       }
     }
     const text = defBtn && this.$t(defBtn.textType)
-    return Object.assign({}, defBtn, { text }, btn)
+    return assign({}, defBtn, { text }, btn)
   }
 
   export default {
@@ -108,17 +109,13 @@
       confirmBtn: {
         type: [Object, String],
         default() {
-          return {
-            ...defConfirmBtn
-          }
+          return assign({}, defConfirmBtn)
         }
       },
       cancelBtn: {
         type: [Object, String],
         default() {
-          return {
-            ...defCancelBtn
-          }
+          return assign({}, defCancelBtn)
         }
       }
     },
diff --git a/src/components/drawer/drawer.vue b/src/components/drawer/drawer.vue
index d18e349ba..cbae201dc 100644
--- a/src/components/drawer/drawer.vue
+++ b/src/components/drawer/drawer.vue
@@ -58,7 +58,7 @@
         index: -1,
         selectedVal: [],
         selectedText: [],
-        selected: [...this.selectedIndex],
+        selected: [].concat(this.selectedIndex),
         slideStyle: {
           [transform]: 'translate3d(0, 0, 0)'
         }
@@ -66,7 +66,7 @@
     },
     watch: {
       selectedIndex(newVal) {
-        this.selected = [...newVal]
+        this.selected = [].concat(newVal)
       },
       index(newIndex, oldIndex) {
         this.showPanel()
diff --git a/src/components/form/fields/index.js b/src/components/form/fields/index.js
index f76157d46..4199589e2 100644
--- a/src/components/form/fields/index.js
+++ b/src/components/form/fields/index.js
@@ -1,9 +1,8 @@
 import processTypes from './types'
+import { assign } from '../../../common/helpers/util'
 
 function processField(field) {
-  const _field = {
-    ...field
-  }
+  const _field = assign({}, field)
   processTypes(_field)
   return _field
 }
diff --git a/src/components/form/form.vue b/src/components/form/form.vue
index 0733837af..069ce19ea 100644
--- a/src/components/form/form.vue
+++ b/src/components/form/form.vue
@@ -8,7 +8,7 @@
 
 <script>
   import { dispatchEvent } from '../../common/helpers/dom'
-  import { cb2PromiseWithResolve } from '../../common/helpers/util'
+  import { cb2PromiseWithResolve, assign } from '../../common/helpers/util'
   import CubeFormGroup from './form-group.vue'
   import LAYOUTS from './layouts'
   import mixin from './mixin'
@@ -231,7 +231,7 @@
       setValidity(key, val) {
         let validity = {}
         if (key) {
-          Object.assign(validity, this.validity)
+          assign(validity, this.validity)
           if (val === undefined) {
             delete validity[key]
           } else {
diff --git a/src/components/index-list/index-list.vue b/src/components/index-list/index-list.vue
index 9d14ad357..7cad21582 100644
--- a/src/components/index-list/index-list.vue
+++ b/src/components/index-list/index-list.vue
@@ -69,6 +69,7 @@
   import CubeIndexListGroup from './index-list-group.vue'
   import scrollMixin from '../../common/mixins/scroll'
   import deprecatedMixin from '../../common/mixins/deprecated'
+  import { assign } from '../../common/helpers/util'
 
   const COMPONENT_NAME = 'cube-index-list'
   const EVENT_SELECT = 'select'
@@ -140,7 +141,7 @@
         })
       },
       scrollOptions() {
-        return Object.assign({}, {
+        return assign({}, {
           pullDownRefresh: this.pullDownRefresh,
           pullUpLoad: this.pullUpLoad
         }, this.options)
diff --git a/src/components/input/input.vue b/src/components/input/input.vue
index 243bf7a94..11d74bba0 100644
--- a/src/components/input/input.vue
+++ b/src/components/input/input.vue
@@ -31,6 +31,8 @@
 
 <script type="text/ecmascript-6">
   import inputMixin from '../../common/mixins/input'
+  import { assign } from '../../common/helpers/util'
+
   const COMPONENT_NAME = 'cube-input'
   const EVENT_INPUT = 'input'
   const EVENT_BLUR = 'blur'
@@ -149,14 +151,14 @@
         if (typeof this.clearable === 'boolean') {
           this.formatedClearable.visible = this.clearable
         } else {
-          Object.assign(this.formatedClearable, this.clearable)
+          assign(this.formatedClearable, this.clearable)
         }
       },
       formateEye() {
         if (typeof this.eye === 'boolean') {
           this.formatedEye.open = this.eye
         } else {
-          Object.assign(this.formatedEye, this.eye)
+          assign(this.formatedEye, this.eye)
         }
       },
       handleFocus(e) {
diff --git a/src/components/picker/picker.vue b/src/components/picker/picker.vue
index 187e1cc68..89b0c5f2c 100644
--- a/src/components/picker/picker.vue
+++ b/src/components/picker/picker.vue
@@ -159,7 +159,7 @@
         }
       },
       setData(data, selectedIndex) {
-        this._indexes = selectedIndex ? [...selectedIndex] : []
+        this._indexes = selectedIndex ? [].concat(selectedIndex) : []
         this.finalData = data.slice()
         if (this.isVisible) {
           this.$nextTick(() => {
diff --git a/src/components/scroll/scroll.vue b/src/components/scroll/scroll.vue
index 28dcd4458..86c14396b 100644
--- a/src/components/scroll/scroll.vue
+++ b/src/components/scroll/scroll.vue
@@ -55,6 +55,7 @@
   import deprecatedMixin from '../../common/mixins/deprecated'
   import { getRect } from '../../common/helpers/dom'
   import { camelize } from '../../common/lang/string'
+  import { assign, toArray } from '../../common/helpers/util'
 
   const COMPONENT_NAME = 'cube-scroll'
   const DIRECTION_H = 'horizontal'
@@ -165,7 +166,7 @@
         if (pullDownRefresh === true) {
           pullDownRefresh = {}
         }
-        return Object.assign({stop: this.pullDownStop}, pullDownRefresh)
+        return assign({stop: this.pullDownStop}, pullDownRefresh)
       },
       pullUpLoad() {
         return this.options.pullUpLoad
@@ -261,7 +262,7 @@
         }
         this._calculateMinHeight()
 
-        let options = Object.assign({}, DEFAULT_OPTIONS, {
+        let options = assign({}, DEFAULT_OPTIONS, {
           scrollY: this.direction === DIRECTION_V,
           scrollX: this.direction === DIRECTION_H,
           probeType: this.needListenScroll ? 3 : 1
@@ -329,9 +330,11 @@
         this.pullUpNoMore = false
       },
       _listenScrollEvents() {
+        const vm = this
         this.finalScrollEvents.forEach((event) => {
-          this.scroll.on(camelize(event), (...args) => {
-            this.$emit(event, ...args)
+          this.scroll.on(camelize(event), function () {
+            const _args = [event].concat(toArray(arguments))
+            vm.$emit.apply(vm, _args)
           })
         })
       },
diff --git a/src/components/segment-picker/segment-picker.vue b/src/components/segment-picker/segment-picker.vue
index 3bc51aaeb..e0a0992d4 100644
--- a/src/components/segment-picker/segment-picker.vue
+++ b/src/components/segment-picker/segment-picker.vue
@@ -28,6 +28,7 @@
   import popupMixin from '../../common/mixins/popup'
   import pickerMixin from '../../common/mixins/picker'
   import localeMixin from '../../common/mixins/locale'
+  import { toArray } from '../../common/helpers/util'
 
   const COMPONENT_NAME = 'cube-segment-picker'
   const EVENT_NEXT = 'next'
@@ -103,13 +104,15 @@
         this.isVisible = false
         this.currentPicker.hide()
       },
-      _select(...args) {
+      _select() {
+        const args = toArray(arguments)
         this.selectedVal[this.current] = args[0]
         this.selectedIndex[this.current] = args[1]
         this.selectedText[this.current] = args[2]
 
         if (this.current < this.data.length - 1) {
-          this.$emit(EVENT_NEXT, this.current, ...args)
+          const _args = [EVENT_NEXT, this.current].concat(args)
+          this.$emit.apply(this, _args)
           this.current++
           this.currentPicker.show()
         } else {
@@ -118,9 +121,11 @@
           this.current = 0
         }
       },
-      _cancel(...args) {
+      _cancel() {
+        const args = toArray(arguments)
         if (this.current > 0) {
-          this.$emit(EVENT_PREV, this.current, ...args)
+          const _args = [EVENT_PREV, this.current].concat(args)
+          this.$emit.apply(this, _args)
           this.current--
           this.currentPicker.show()
         } else {
@@ -128,8 +133,10 @@
           this.$emit(EVENT_CANCEL)
         }
       },
-      _change(...args) {
-        this.$emit(EVENT_CHANGE, this.current, ...args)
+      _change() {
+        const args = toArray(arguments)
+        const _args = [EVENT_CHANGE, this.current].concat(args)
+        this.$emit.apply(this, _args)
       }
     }
   }
diff --git a/src/components/slide/slide.vue b/src/components/slide/slide.vue
index 9ba2cd75d..6f8800891 100644
--- a/src/components/slide/slide.vue
+++ b/src/components/slide/slide.vue
@@ -23,6 +23,7 @@
   import BScroll from 'better-scroll'
   import scrollMixin from '../../common/mixins/scroll'
   import deprecatedMixin from '../../common/mixins/deprecated'
+  import { assign } from '../../common/helpers/util'
 
   const COMPONENT_NAME = 'cube-slide'
   const EVENT_CHANGE = 'change'
@@ -191,8 +192,7 @@
       },
       _initSlide() {
         const eventPassthrough = this.direction === DIRECTION_H && this.allowVertical ? DIRECTION_V : ''
-
-        const options = Object.assign({}, DEFAULT_OPTIONS, {
+        const options = assign({}, DEFAULT_OPTIONS, {
           scrollX: this.direction === DIRECTION_H,
           scrollY: this.direction === DIRECTION_V,
           eventPassthrough,
diff --git a/src/components/textarea/textarea.vue b/src/components/textarea/textarea.vue
index 28ae27a75..0b77cdb1d 100644
--- a/src/components/textarea/textarea.vue
+++ b/src/components/textarea/textarea.vue
@@ -19,6 +19,7 @@
 
 <script type="text/ecmascript-6">
   import inputMixin from '../../common/mixins/input'
+  import { assign } from '../../common/helpers/util'
   const COMPONENT_NAME = 'cube-textarea'
   const EVENT_INPUT = 'input'
 
@@ -78,7 +79,7 @@
         if (typeof indicator === 'boolean') {
           indicator = {}
         }
-        return Object.assign({}, DEFAULT_INDICATOR, indicator)
+        return assign({}, DEFAULT_INDICATOR, indicator)
       },
       count() {
         return this.textareaValue.length
diff --git a/src/components/time-picker/time-picker.vue b/src/components/time-picker/time-picker.vue
index 95a3f3b4e..c95cbfd1d 100644
--- a/src/components/time-picker/time-picker.vue
+++ b/src/components/time-picker/time-picker.vue
@@ -33,6 +33,7 @@
   import localeMixin from '../../common/mixins/locale'
   import CubeCascadePicker from '../cascade-picker/cascade-picker.vue'
   import { warn } from '../../common/helpers/debug'
+  import { assign } from '../../common/helpers/util'
 
   const COMPONENT_NAME = 'cube-time-picker'
   const EVENT_SELECT = 'select'
@@ -111,7 +112,7 @@
           filter: [this.$t('today')],
           format: this.$t('formatDate')
         }
-        return Object.assign({}, defaultDay, this.day)
+        return assign({}, defaultDay, this.day)
       },
       nowText() {
         const defaultText = this.$t('now')
diff --git a/src/components/upload/util.js b/src/components/upload/util.js
index 5cf0fcce5..761e9f6dd 100644
--- a/src/components/upload/util.js
+++ b/src/components/upload/util.js
@@ -1,4 +1,5 @@
 import { inBrowser } from '../../common/helpers/env'
+import { toArray } from '../../common/helpers/util'
 
 export const URL = inBrowser ? window.URL || window.webkitURL || window.mozURL : null
 
@@ -52,7 +53,8 @@ function createURL(file) {
   return ''
 }
 
-export function evalOpts(data, ...args) {
+export function evalOpts(data) {
+  const args = toArray(arguments, 1)
   if (typeof data === 'function') {
     return data.apply(this, args)
   }
