Permalink
Browse files

refactor(core): Replace "var" (#8299)

Replaces instances of "var" with "let" and "const" where applicable using the eslint 'no-var' and
'prefer-const' rules
  • Loading branch information...
slichlyter12 authored and yyx990803 committed Oct 24, 2018
1 parent 5cfdf1a commit 5489339a30e25d1bdea4492ea253144ede0d31f1
Showing with 82 additions and 82 deletions.
  1. +1 βˆ’1 scripts/build.js
  2. +4 βˆ’4 scripts/get-weex-version.js
  3. +2 βˆ’2 src/platforms/web/runtime/components/transition-group.js
  4. +1 βˆ’1 src/platforms/web/util/style.js
  5. +1 βˆ’1 src/platforms/weex/runtime/modules/style.js
  6. +7 βˆ’7 test/e2e/runner.js
  7. +3 βˆ’3 test/e2e/specs/grid.js
  8. +6 βˆ’6 test/e2e/specs/svg.js
  9. +2 βˆ’2 test/e2e/specs/tree.js
  10. +3 βˆ’3 test/helpers/to-have-been-warned.js
  11. +1 βˆ’1 test/helpers/trigger-event.js
  12. +3 βˆ’3 test/ssr/ssr-stream.spec.js
  13. +2 βˆ’2 test/unit/features/component/component-async.spec.js
  14. +1 βˆ’1 test/unit/features/component/component-keep-alive.spec.js
  15. +1 βˆ’1 test/unit/features/directives/class.spec.js
  16. +2 βˆ’2 test/unit/features/directives/for.spec.js
  17. +2 βˆ’2 test/unit/features/directives/model-radio.spec.js
  18. +10 βˆ’10 test/unit/features/directives/model-select.spec.js
  19. +1 βˆ’1 test/unit/features/directives/model-text.spec.js
  20. +4 βˆ’4 test/unit/features/directives/style.spec.js
  21. +2 βˆ’2 test/unit/features/instance/methods-data.spec.js
  22. +1 βˆ’1 test/unit/features/instance/methods-events.spec.js
  23. +4 βˆ’4 test/unit/features/options/functional.spec.js
  24. +6 βˆ’6 test/unit/features/options/watch.spec.js
  25. +1 βˆ’1 test/unit/features/transition/inject-styles.js
  26. +3 βˆ’3 test/unit/karma.base.config.js
  27. +2 βˆ’2 test/unit/karma.cover.config.js
  28. +1 βˆ’1 test/unit/karma.dev.config.js
  29. +4 βˆ’4 test/unit/karma.sauce.config.js
  30. +1 βˆ’1 test/unit/karma.unit.config.js
@@ -48,7 +48,7 @@ function buildEntry (config) {
.then(bundle => bundle.generate(output))
.then(({ code }) => {
if (isProd) {
var minified = (banner ? banner + '\n' : '') + terser.minify(code, {
const minified = (banner ? banner + '\n' : '') + terser.minify(code, {
output: {
ascii_only: true
},
@@ -1,7 +1,7 @@
var coreVersion = require('../package.json').version
var weexVersion = require('../packages/weex-vue-framework/package.json').version
var weexBaseVersion = weexVersion.match(/^[\d.]+/)[0]
var weexSubVersion = Number(weexVersion.match(/-weex\.(\d+)$/)[1])
const coreVersion = require('../package.json').version
const weexVersion = require('../packages/weex-vue-framework/package.json').version
let weexBaseVersion = weexVersion.match(/^[\d.]+/)[0]
let weexSubVersion = Number(weexVersion.match(/-weex\.(\d+)$/)[1])
if (weexBaseVersion === coreVersion) {
// same core version, increment sub version
@@ -111,8 +111,8 @@ export default {
children.forEach((c: VNode) => {
if (c.data.moved) {
var el: any = c.elm
var s: any = el.style
const el: any = c.elm
const s: any = el.style
addTransitionClass(el, moveClass)
s.transform = s.WebkitTransform = s.transitionDuration = ''
el.addEventListener(transitionEndEvent, el._moveCb = function cb (e) {
@@ -8,7 +8,7 @@ export const parseStyleText = cached(function (cssText) {
const propertyDelimiter = /:(.+)/
cssText.split(listDelimiter).forEach(function (item) {
if (item) {
var tmp = item.split(propertyDelimiter)
const tmp = item.split(propertyDelimiter)
tmp.length > 1 && (res[tmp[0].trim()] = tmp[1].trim())
}
})
@@ -70,7 +70,7 @@ function updateStyle (oldVnode: VNodeWithData, vnode: VNodeWithData) {
function toObject (arr) {
const res = {}
for (var i = 0; i < arr.length; i++) {
for (let i = 0; i < arr.length; i++) {
if (arr[i]) {
extend(res, arr[i])
}
@@ -1,25 +1,25 @@
var path = require('path')
var spawn = require('cross-spawn')
var httpServer = require('http-server')
var server = httpServer.createServer({
const path = require('path')
const spawn = require('cross-spawn')
const httpServer = require('http-server')
const server = httpServer.createServer({
root: path.resolve(__dirname, '../../')
})
server.listen(8080)
var args = process.argv.slice(2)
let args = process.argv.slice(2)
if (args.indexOf('--config') === -1) {
args = args.concat(['--config', 'test/e2e/nightwatch.config.js'])
}
if (args.indexOf('--env') === -1) {
args = args.concat(['--env', 'chrome,phantomjs'])
}
var i = args.indexOf('--test')
const i = args.indexOf('--test')
if (i > -1) {
args[i + 1] = 'test/e2e/specs/' + args[i + 1] + '.js'
}
var runner = spawn('./node_modules/.bin/nightwatch', args, {
const runner = spawn('./node_modules/.bin/nightwatch', args, {
stdio: 'inherit'
})
@@ -1,6 +1,6 @@
module.exports = {
'grid': function (browser) {
var columns = ['name', 'power']
const columns = ['name', 'power']
browser
.url('http://localhost:8080/examples/grid/')
@@ -92,8 +92,8 @@ module.exports = {
function assertTable (data) {
browser.assert.count('td', data.length * columns.length)
for (var i = 0; i < data.length; i++) {
for (var j = 0; j < columns.length; j++) {
for (let i = 0; i < data.length; i++) {
for (let j = 0; j < columns.length; j++) {
browser.assert.containsText(
'tr:nth-child(' + (i + 1) + ') td:nth-child(' + (j + 1) + ')',
data[i][columns[j]]
@@ -12,8 +12,8 @@ module.exports = {
.assert.count('button', 7)
.assert.count('input[type="range"]', 6)
.assert.evaluate(function () {
var points = stats.map(function (stat, i) {
var point = valueToPoint(stat.value, i, 6)
const points = stats.map(function (stat, i) {
const point = valueToPoint(stat.value, i, 6)
return point.x + ',' + point.y
}).join(' ')
return document.querySelector('polygon').attributes[0].value === points
@@ -24,8 +24,8 @@ module.exports = {
.assert.count('button', 6)
.assert.count('input[type="range"]', 5)
.assert.evaluate(function () {
var points = stats.map(function (stat, i) {
var point = valueToPoint(stat.value, i, 5)
const points = stats.map(function (stat, i) {
const point = valueToPoint(stat.value, i, 5)
return point.x + ',' + point.y
}).join(' ')
return document.querySelector('polygon').attributes[0].value === points
@@ -37,8 +37,8 @@ module.exports = {
.assert.count('button', 7)
.assert.count('input[type="range"]', 6)
.assert.evaluate(function () {
var points = stats.map(function (stat, i) {
var point = valueToPoint(stat.value, i, 6)
const points = stats.map(function (stat, i) {
const point = valueToPoint(stat.value, i, 6)
return point.x + ',' + point.y
}).join(' ')
return document.querySelector('polygon').attributes[0].value === points
@@ -63,8 +63,8 @@ module.exports = {
.assert.count('.item > ul', 5)
.assert.containsText('#demo ul > .item:nth-child(1)', '[-]')
.assert.evaluate(function () {
var firstItem = document.querySelector('#demo ul > .item:nth-child(1)')
var ul = firstItem.querySelector('ul')
const firstItem = document.querySelector('#demo ul > .item:nth-child(1)')
const ul = firstItem.querySelector('ul')
return ul.children.length === 2
})
.end()
@@ -14,8 +14,8 @@ let asserted
function createCompareFn (spy) {
const hasWarned = msg => {
var count = spy.calls.count()
var args
let count = spy.calls.count()
let args
while (count--) {
args = spy.calls.argsFor(count)
if (args.some(containsMsg)) {
@@ -31,7 +31,7 @@ function createCompareFn (spy) {
return {
compare: msg => {
asserted = asserted.concat(msg)
var warned = Array.isArray(msg)
const warned = Array.isArray(msg)
? msg.some(hasWarned)
: hasWarned(msg)
return {
@@ -1,5 +1,5 @@
window.triggerEvent = function triggerEvent (target, event, process) {
var e = document.createEvent('HTMLEvents')
const e = document.createEvent('HTMLEvents')
e.initEvent(event, true, true)
if (process) process(e)
target.dispatchEvent(e)
@@ -89,9 +89,9 @@ describe('SSR: renderToStream', () => {
template: `<div></div>`,
_scopeId: '_component2'
})
var stream1 = renderToStream(component1)
var stream2 = renderToStream(component2)
var res = ''
const stream1 = renderToStream(component1)
const stream2 = renderToStream(component2)
let res = ''
stream1.on('data', (text) => {
res += text.toString('utf-8').replace(/x/g, '')
})
@@ -79,7 +79,7 @@ describe('Component async', () => {
})
it('dynamic', done => {
var vm = new Vue({
const vm = new Vue({
template: '<component :is="view"></component>',
data: {
view: 'view-a'
@@ -103,7 +103,7 @@ describe('Component async', () => {
}
}
}).$mount()
var aCalled = false
let aCalled = false
function step1 () {
// ensure A is resolved only once
expect(aCalled).toBe(false)
@@ -140,7 +140,7 @@ describe('Component keep-alive', () => {
components
}).$mount()
var oneInstance = vm.$refs.one
const oneInstance = vm.$refs.one
expect(vm.$el.textContent).toBe('two')
assertHookCalls(one, [1, 1, 1, 0, 0])
assertHookCalls(two, [1, 1, 1, 0, 0])
@@ -5,7 +5,7 @@ function assertClass (assertions, done) {
template: '<div class="foo" :class="value"></div>',
data: { value: '' }
}).$mount()
var chain = waitForUpdate()
const chain = waitForUpdate()
assertions.forEach(([value, expected], i) => {
chain.then(() => {
if (typeof value === 'function') {
@@ -330,7 +330,7 @@ describe('Directive v-for', () => {
}).then(done)
function assertMarkup () {
var markup = vm.list.map(function (item) {
const markup = vm.list.map(function (item) {
return '<p>' + item.a + '</p><p>' + (item.a + 1) + '</p>'
}).join('')
expect(vm.$el.innerHTML).toBe(markup)
@@ -370,7 +370,7 @@ describe('Directive v-for', () => {
}).then(done)
function assertMarkup () {
var markup = vm.list.map(function (item) {
const markup = vm.list.map(function (item) {
return `<p>${item.a}<span>${item.a}</span></p>`
}).join('')
expect(vm.$el.innerHTML).toBe(markup)
@@ -117,7 +117,7 @@ describe('Directive v-model radio', () => {
'</div>'
}).$mount()
document.body.appendChild(vm.$el)
var inputs = vm.$el.getElementsByTagName('input')
const inputs = vm.$el.getElementsByTagName('input')
inputs[1].click()
waitForUpdate(() => {
expect(vm.selections).toEqual(['b', '1'])
@@ -160,7 +160,7 @@ describe('Directive v-model radio', () => {
'<input type="radio" value="true" v-model="test" name="test">' +
'</div>'
}).$mount()
var radioboxInput = vm.$el.children
const radioboxInput = vm.$el.children
expect(radioboxInput[0].checked).toBe(false)
expect(radioboxInput[1].checked).toBe(false)
expect(radioboxInput[2].checked).toBe(true)
@@ -4,9 +4,9 @@ import { looseEqual } from 'shared/util'
// Android 4.4 Chrome 30 has the bug that a multi-select option cannot be
// deselected by setting its "selected" prop via JavaScript.
function hasMultiSelectBug () {
var s = document.createElement('select')
const s = document.createElement('select')
s.setAttribute('multiple', '')
var o = document.createElement('option')
const o = document.createElement('option')
s.appendChild(o)
o.selected = true
o.selected = false
@@ -18,8 +18,8 @@ function hasMultiSelectBug () {
* we have to manually loop through the options
*/
function updateSelect (el, value) {
var options = el.options
var i = options.length
const options = el.options
let i = options.length
while (i--) {
if (looseEqual(getValue(options[i]), value)) {
options[i].selected = true
@@ -245,7 +245,7 @@ describe('Directive v-model select', () => {
'<option>c</option>' +
'</select>'
}).$mount()
var opts = vm.$el.options
const opts = vm.$el.options
expect(opts[0].selected).toBe(false)
expect(opts[1].selected).toBe(true)
expect(opts[2].selected).toBe(false)
@@ -272,7 +272,7 @@ describe('Directive v-model select', () => {
'<option v-for="o in opts">{{ o }}</option>' +
'</select>'
}).$mount()
var opts = vm.$el.options
const opts = vm.$el.options
expect(opts[0].selected).toBe(false)
expect(opts[1].selected).toBe(true)
expect(opts[2].selected).toBe(false)
@@ -345,7 +345,7 @@ describe('Directive v-model select', () => {
'<option selected>c</option>' +
'</select>'
}).$mount()
var opts = vm.$el.options
const opts = vm.$el.options
expect(opts[0].selected).toBe(true)
expect(opts[1].selected).toBe(true)
expect(opts[2].selected).toBe(true)
@@ -379,8 +379,8 @@ describe('Directive v-model select', () => {
'</div>'
}).$mount()
document.body.appendChild(vm.$el)
var selects = vm.$el.getElementsByTagName('select')
var select0 = selects[0]
const selects = vm.$el.getElementsByTagName('select')
const select0 = selects[0]
select0.options[0].selected = true
triggerEvent(select0, 'change')
waitForUpdate(() => {
@@ -421,7 +421,7 @@ describe('Directive v-model select', () => {
'<option value="true">c</option>' +
'</select>'
}).$mount()
var opts = vm.$el.options
const opts = vm.$el.options
expect(opts[0].selected).toBe(false)
expect(opts[1].selected).toBe(true)
expect(opts[2].selected).toBe(false)
@@ -167,7 +167,7 @@ describe('Directive v-model text', () => {
'<span ref="rs">{{selections}}</span>' +
'</div>'
}).$mount()
var inputs = vm.$el.getElementsByTagName('input')
const inputs = vm.$el.getElementsByTagName('input')
inputs[1].value = 'test'
triggerEvent(inputs[1], 'input')
waitForUpdate(() => {
@@ -1,11 +1,11 @@
import Vue from 'vue'
function checkPrefixedProp (prop) {
var el = document.createElement('div')
var upper = prop.charAt(0).toUpperCase() + prop.slice(1)
const el = document.createElement('div')
const upper = prop.charAt(0).toUpperCase() + prop.slice(1)
if (!(prop in el.style)) {
var prefixes = ['Webkit', 'Moz', 'ms']
var i = prefixes.length
const prefixes = ['Webkit', 'Moz', 'ms']
let i = prefixes.length
while (i--) {
if ((prefixes[i] + upper) in el.style) {
prop = prefixes[i] + upper
@@ -73,7 +73,7 @@ describe('Instance methods data', () => {
})
it('deep watch', done => {
var oldA = vm.a
const oldA = vm.a
vm.$watch('a', spy, { deep: true })
vm.a.b = 2
waitForUpdate(() => {
@@ -85,7 +85,7 @@ describe('Instance methods data', () => {
})
it('handler option', done => {
var oldA = vm.a
const oldA = vm.a
vm.$watch('a', {
handler: spy,
deep: true
@@ -77,7 +77,7 @@ describe('Instance methods events', () => {
})
it('$off event + fn', () => {
var spy2 = jasmine.createSpy('emitter')
const spy2 = jasmine.createSpy('emitter')
vm.$on('test', spy)
vm.$on('test', spy2)
vm.$off('test', spy)
Oops, something went wrong.

0 comments on commit 5489339

Please sign in to comment.