Skip to content

Commit 5489339

Browse files
slichlyter12yyx990803
authored andcommitted
refactor(core): Replace "var" (#8299)
Replaces instances of "var" with "let" and "const" where applicable using the eslint 'no-var' and 'prefer-const' rules
1 parent 5cfdf1a commit 5489339

30 files changed

+82
-82
lines changed

Diff for: scripts/build.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ function buildEntry (config) {
4848
.then(bundle => bundle.generate(output))
4949
.then(({ code }) => {
5050
if (isProd) {
51-
var minified = (banner ? banner + '\n' : '') + terser.minify(code, {
51+
const minified = (banner ? banner + '\n' : '') + terser.minify(code, {
5252
output: {
5353
ascii_only: true
5454
},

Diff for: scripts/get-weex-version.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
var coreVersion = require('../package.json').version
2-
var weexVersion = require('../packages/weex-vue-framework/package.json').version
3-
var weexBaseVersion = weexVersion.match(/^[\d.]+/)[0]
4-
var weexSubVersion = Number(weexVersion.match(/-weex\.(\d+)$/)[1])
1+
const coreVersion = require('../package.json').version
2+
const weexVersion = require('../packages/weex-vue-framework/package.json').version
3+
let weexBaseVersion = weexVersion.match(/^[\d.]+/)[0]
4+
let weexSubVersion = Number(weexVersion.match(/-weex\.(\d+)$/)[1])
55

66
if (weexBaseVersion === coreVersion) {
77
// same core version, increment sub version

Diff for: src/platforms/web/runtime/components/transition-group.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,8 @@ export default {
111111

112112
children.forEach((c: VNode) => {
113113
if (c.data.moved) {
114-
var el: any = c.elm
115-
var s: any = el.style
114+
const el: any = c.elm
115+
const s: any = el.style
116116
addTransitionClass(el, moveClass)
117117
s.transform = s.WebkitTransform = s.transitionDuration = ''
118118
el.addEventListener(transitionEndEvent, el._moveCb = function cb (e) {

Diff for: src/platforms/web/util/style.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export const parseStyleText = cached(function (cssText) {
88
const propertyDelimiter = /:(.+)/
99
cssText.split(listDelimiter).forEach(function (item) {
1010
if (item) {
11-
var tmp = item.split(propertyDelimiter)
11+
const tmp = item.split(propertyDelimiter)
1212
tmp.length > 1 && (res[tmp[0].trim()] = tmp[1].trim())
1313
}
1414
})

Diff for: src/platforms/weex/runtime/modules/style.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ function updateStyle (oldVnode: VNodeWithData, vnode: VNodeWithData) {
7070

7171
function toObject (arr) {
7272
const res = {}
73-
for (var i = 0; i < arr.length; i++) {
73+
for (let i = 0; i < arr.length; i++) {
7474
if (arr[i]) {
7575
extend(res, arr[i])
7676
}

Diff for: test/e2e/runner.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
1-
var path = require('path')
2-
var spawn = require('cross-spawn')
3-
var httpServer = require('http-server')
4-
var server = httpServer.createServer({
1+
const path = require('path')
2+
const spawn = require('cross-spawn')
3+
const httpServer = require('http-server')
4+
const server = httpServer.createServer({
55
root: path.resolve(__dirname, '../../')
66
})
77

88
server.listen(8080)
99

10-
var args = process.argv.slice(2)
10+
let args = process.argv.slice(2)
1111
if (args.indexOf('--config') === -1) {
1212
args = args.concat(['--config', 'test/e2e/nightwatch.config.js'])
1313
}
1414
if (args.indexOf('--env') === -1) {
1515
args = args.concat(['--env', 'chrome,phantomjs'])
1616
}
17-
var i = args.indexOf('--test')
17+
const i = args.indexOf('--test')
1818
if (i > -1) {
1919
args[i + 1] = 'test/e2e/specs/' + args[i + 1] + '.js'
2020
}
2121

22-
var runner = spawn('./node_modules/.bin/nightwatch', args, {
22+
const runner = spawn('./node_modules/.bin/nightwatch', args, {
2323
stdio: 'inherit'
2424
})
2525

Diff for: test/e2e/specs/grid.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module.exports = {
22
'grid': function (browser) {
3-
var columns = ['name', 'power']
3+
const columns = ['name', 'power']
44

55
browser
66
.url('http://localhost:8080/examples/grid/')
@@ -92,8 +92,8 @@ module.exports = {
9292

9393
function assertTable (data) {
9494
browser.assert.count('td', data.length * columns.length)
95-
for (var i = 0; i < data.length; i++) {
96-
for (var j = 0; j < columns.length; j++) {
95+
for (let i = 0; i < data.length; i++) {
96+
for (let j = 0; j < columns.length; j++) {
9797
browser.assert.containsText(
9898
'tr:nth-child(' + (i + 1) + ') td:nth-child(' + (j + 1) + ')',
9999
data[i][columns[j]]

Diff for: test/e2e/specs/svg.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ module.exports = {
1212
.assert.count('button', 7)
1313
.assert.count('input[type="range"]', 6)
1414
.assert.evaluate(function () {
15-
var points = stats.map(function (stat, i) {
16-
var point = valueToPoint(stat.value, i, 6)
15+
const points = stats.map(function (stat, i) {
16+
const point = valueToPoint(stat.value, i, 6)
1717
return point.x + ',' + point.y
1818
}).join(' ')
1919
return document.querySelector('polygon').attributes[0].value === points
@@ -24,8 +24,8 @@ module.exports = {
2424
.assert.count('button', 6)
2525
.assert.count('input[type="range"]', 5)
2626
.assert.evaluate(function () {
27-
var points = stats.map(function (stat, i) {
28-
var point = valueToPoint(stat.value, i, 5)
27+
const points = stats.map(function (stat, i) {
28+
const point = valueToPoint(stat.value, i, 5)
2929
return point.x + ',' + point.y
3030
}).join(' ')
3131
return document.querySelector('polygon').attributes[0].value === points
@@ -37,8 +37,8 @@ module.exports = {
3737
.assert.count('button', 7)
3838
.assert.count('input[type="range"]', 6)
3939
.assert.evaluate(function () {
40-
var points = stats.map(function (stat, i) {
41-
var point = valueToPoint(stat.value, i, 6)
40+
const points = stats.map(function (stat, i) {
41+
const point = valueToPoint(stat.value, i, 6)
4242
return point.x + ',' + point.y
4343
}).join(' ')
4444
return document.querySelector('polygon').attributes[0].value === points

Diff for: test/e2e/specs/tree.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ module.exports = {
6363
.assert.count('.item > ul', 5)
6464
.assert.containsText('#demo ul > .item:nth-child(1)', '[-]')
6565
.assert.evaluate(function () {
66-
var firstItem = document.querySelector('#demo ul > .item:nth-child(1)')
67-
var ul = firstItem.querySelector('ul')
66+
const firstItem = document.querySelector('#demo ul > .item:nth-child(1)')
67+
const ul = firstItem.querySelector('ul')
6868
return ul.children.length === 2
6969
})
7070
.end()

Diff for: test/helpers/to-have-been-warned.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ let asserted
1414

1515
function createCompareFn (spy) {
1616
const hasWarned = msg => {
17-
var count = spy.calls.count()
18-
var args
17+
let count = spy.calls.count()
18+
let args
1919
while (count--) {
2020
args = spy.calls.argsFor(count)
2121
if (args.some(containsMsg)) {
@@ -31,7 +31,7 @@ function createCompareFn (spy) {
3131
return {
3232
compare: msg => {
3333
asserted = asserted.concat(msg)
34-
var warned = Array.isArray(msg)
34+
const warned = Array.isArray(msg)
3535
? msg.some(hasWarned)
3636
: hasWarned(msg)
3737
return {

Diff for: test/helpers/trigger-event.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
window.triggerEvent = function triggerEvent (target, event, process) {
2-
var e = document.createEvent('HTMLEvents')
2+
const e = document.createEvent('HTMLEvents')
33
e.initEvent(event, true, true)
44
if (process) process(e)
55
target.dispatchEvent(e)

Diff for: test/ssr/ssr-stream.spec.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,9 @@ describe('SSR: renderToStream', () => {
8989
template: `<div></div>`,
9090
_scopeId: '_component2'
9191
})
92-
var stream1 = renderToStream(component1)
93-
var stream2 = renderToStream(component2)
94-
var res = ''
92+
const stream1 = renderToStream(component1)
93+
const stream2 = renderToStream(component2)
94+
let res = ''
9595
stream1.on('data', (text) => {
9696
res += text.toString('utf-8').replace(/x/g, '')
9797
})

Diff for: test/unit/features/component/component-async.spec.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ describe('Component async', () => {
7979
})
8080

8181
it('dynamic', done => {
82-
var vm = new Vue({
82+
const vm = new Vue({
8383
template: '<component :is="view"></component>',
8484
data: {
8585
view: 'view-a'
@@ -103,7 +103,7 @@ describe('Component async', () => {
103103
}
104104
}
105105
}).$mount()
106-
var aCalled = false
106+
let aCalled = false
107107
function step1 () {
108108
// ensure A is resolved only once
109109
expect(aCalled).toBe(false)

Diff for: test/unit/features/component/component-keep-alive.spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ describe('Component keep-alive', () => {
140140
components
141141
}).$mount()
142142

143-
var oneInstance = vm.$refs.one
143+
const oneInstance = vm.$refs.one
144144
expect(vm.$el.textContent).toBe('two')
145145
assertHookCalls(one, [1, 1, 1, 0, 0])
146146
assertHookCalls(two, [1, 1, 1, 0, 0])

Diff for: test/unit/features/directives/class.spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ function assertClass (assertions, done) {
55
template: '<div class="foo" :class="value"></div>',
66
data: { value: '' }
77
}).$mount()
8-
var chain = waitForUpdate()
8+
const chain = waitForUpdate()
99
assertions.forEach(([value, expected], i) => {
1010
chain.then(() => {
1111
if (typeof value === 'function') {

Diff for: test/unit/features/directives/for.spec.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ describe('Directive v-for', () => {
330330
}).then(done)
331331

332332
function assertMarkup () {
333-
var markup = vm.list.map(function (item) {
333+
const markup = vm.list.map(function (item) {
334334
return '<p>' + item.a + '</p><p>' + (item.a + 1) + '</p>'
335335
}).join('')
336336
expect(vm.$el.innerHTML).toBe(markup)
@@ -370,7 +370,7 @@ describe('Directive v-for', () => {
370370
}).then(done)
371371

372372
function assertMarkup () {
373-
var markup = vm.list.map(function (item) {
373+
const markup = vm.list.map(function (item) {
374374
return `<p>${item.a}<span>${item.a}</span></p>`
375375
}).join('')
376376
expect(vm.$el.innerHTML).toBe(markup)

Diff for: test/unit/features/directives/model-radio.spec.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ describe('Directive v-model radio', () => {
117117
'</div>'
118118
}).$mount()
119119
document.body.appendChild(vm.$el)
120-
var inputs = vm.$el.getElementsByTagName('input')
120+
const inputs = vm.$el.getElementsByTagName('input')
121121
inputs[1].click()
122122
waitForUpdate(() => {
123123
expect(vm.selections).toEqual(['b', '1'])
@@ -160,7 +160,7 @@ describe('Directive v-model radio', () => {
160160
'<input type="radio" value="true" v-model="test" name="test">' +
161161
'</div>'
162162
}).$mount()
163-
var radioboxInput = vm.$el.children
163+
const radioboxInput = vm.$el.children
164164
expect(radioboxInput[0].checked).toBe(false)
165165
expect(radioboxInput[1].checked).toBe(false)
166166
expect(radioboxInput[2].checked).toBe(true)

Diff for: test/unit/features/directives/model-select.spec.js

+10-10
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import { looseEqual } from 'shared/util'
44
// Android 4.4 Chrome 30 has the bug that a multi-select option cannot be
55
// deselected by setting its "selected" prop via JavaScript.
66
function hasMultiSelectBug () {
7-
var s = document.createElement('select')
7+
const s = document.createElement('select')
88
s.setAttribute('multiple', '')
9-
var o = document.createElement('option')
9+
const o = document.createElement('option')
1010
s.appendChild(o)
1111
o.selected = true
1212
o.selected = false
@@ -18,8 +18,8 @@ function hasMultiSelectBug () {
1818
* we have to manually loop through the options
1919
*/
2020
function updateSelect (el, value) {
21-
var options = el.options
22-
var i = options.length
21+
const options = el.options
22+
let i = options.length
2323
while (i--) {
2424
if (looseEqual(getValue(options[i]), value)) {
2525
options[i].selected = true
@@ -245,7 +245,7 @@ describe('Directive v-model select', () => {
245245
'<option>c</option>' +
246246
'</select>'
247247
}).$mount()
248-
var opts = vm.$el.options
248+
const opts = vm.$el.options
249249
expect(opts[0].selected).toBe(false)
250250
expect(opts[1].selected).toBe(true)
251251
expect(opts[2].selected).toBe(false)
@@ -272,7 +272,7 @@ describe('Directive v-model select', () => {
272272
'<option v-for="o in opts">{{ o }}</option>' +
273273
'</select>'
274274
}).$mount()
275-
var opts = vm.$el.options
275+
const opts = vm.$el.options
276276
expect(opts[0].selected).toBe(false)
277277
expect(opts[1].selected).toBe(true)
278278
expect(opts[2].selected).toBe(false)
@@ -345,7 +345,7 @@ describe('Directive v-model select', () => {
345345
'<option selected>c</option>' +
346346
'</select>'
347347
}).$mount()
348-
var opts = vm.$el.options
348+
const opts = vm.$el.options
349349
expect(opts[0].selected).toBe(true)
350350
expect(opts[1].selected).toBe(true)
351351
expect(opts[2].selected).toBe(true)
@@ -379,8 +379,8 @@ describe('Directive v-model select', () => {
379379
'</div>'
380380
}).$mount()
381381
document.body.appendChild(vm.$el)
382-
var selects = vm.$el.getElementsByTagName('select')
383-
var select0 = selects[0]
382+
const selects = vm.$el.getElementsByTagName('select')
383+
const select0 = selects[0]
384384
select0.options[0].selected = true
385385
triggerEvent(select0, 'change')
386386
waitForUpdate(() => {
@@ -421,7 +421,7 @@ describe('Directive v-model select', () => {
421421
'<option value="true">c</option>' +
422422
'</select>'
423423
}).$mount()
424-
var opts = vm.$el.options
424+
const opts = vm.$el.options
425425
expect(opts[0].selected).toBe(false)
426426
expect(opts[1].selected).toBe(true)
427427
expect(opts[2].selected).toBe(false)

Diff for: test/unit/features/directives/model-text.spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ describe('Directive v-model text', () => {
167167
'<span ref="rs">{{selections}}</span>' +
168168
'</div>'
169169
}).$mount()
170-
var inputs = vm.$el.getElementsByTagName('input')
170+
const inputs = vm.$el.getElementsByTagName('input')
171171
inputs[1].value = 'test'
172172
triggerEvent(inputs[1], 'input')
173173
waitForUpdate(() => {

Diff for: test/unit/features/directives/style.spec.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import Vue from 'vue'
22

33
function checkPrefixedProp (prop) {
4-
var el = document.createElement('div')
5-
var upper = prop.charAt(0).toUpperCase() + prop.slice(1)
4+
const el = document.createElement('div')
5+
const upper = prop.charAt(0).toUpperCase() + prop.slice(1)
66
if (!(prop in el.style)) {
7-
var prefixes = ['Webkit', 'Moz', 'ms']
8-
var i = prefixes.length
7+
const prefixes = ['Webkit', 'Moz', 'ms']
8+
let i = prefixes.length
99
while (i--) {
1010
if ((prefixes[i] + upper) in el.style) {
1111
prop = prefixes[i] + upper

Diff for: test/unit/features/instance/methods-data.spec.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ describe('Instance methods data', () => {
7373
})
7474

7575
it('deep watch', done => {
76-
var oldA = vm.a
76+
const oldA = vm.a
7777
vm.$watch('a', spy, { deep: true })
7878
vm.a.b = 2
7979
waitForUpdate(() => {
@@ -85,7 +85,7 @@ describe('Instance methods data', () => {
8585
})
8686

8787
it('handler option', done => {
88-
var oldA = vm.a
88+
const oldA = vm.a
8989
vm.$watch('a', {
9090
handler: spy,
9191
deep: true

Diff for: test/unit/features/instance/methods-events.spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ describe('Instance methods events', () => {
7777
})
7878

7979
it('$off event + fn', () => {
80-
var spy2 = jasmine.createSpy('emitter')
80+
const spy2 = jasmine.createSpy('emitter')
8181
vm.$on('test', spy)
8282
vm.$on('test', spy2)
8383
vm.$off('test', spy)

0 commit comments

Comments
 (0)