mirror of
https://github.com/vuejs/vue.git
synced 2024-11-22 04:39:46 +00:00
refactor(core): Replace "var" (#8299)
Replaces instances of "var" with "let" and "const" where applicable using the eslint 'no-var' and 'prefer-const' rules
This commit is contained in:
parent
5cfdf1a248
commit
5489339a30
@ -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)
|
||||
|
@ -244,8 +244,8 @@ describe('Options functional', () => {
|
||||
|
||||
it('should work with render fns compiled from template', done => {
|
||||
// code generated via vue-template-es2015-compiler
|
||||
var render = function (_h, _vm) {
|
||||
var _c = _vm._c
|
||||
const render = function (_h, _vm) {
|
||||
const _c = _vm._c
|
||||
return _c(
|
||||
'div',
|
||||
[
|
||||
@ -261,9 +261,9 @@ describe('Options functional', () => {
|
||||
2
|
||||
)
|
||||
}
|
||||
var staticRenderFns = [
|
||||
const staticRenderFns = [
|
||||
function (_h, _vm) {
|
||||
var _c = _vm._c
|
||||
const _c = _vm._c
|
||||
return _c('div', [_vm._v('Some '), _c('span', [_vm._v('text')])])
|
||||
}
|
||||
]
|
||||
|
@ -106,9 +106,9 @@ describe('Options watch', () => {
|
||||
})
|
||||
|
||||
it('correctly merges multiple extends', done => {
|
||||
var spy2 = jasmine.createSpy('A')
|
||||
var spy3 = jasmine.createSpy('B')
|
||||
var A = Vue.extend({
|
||||
const spy2 = jasmine.createSpy('A')
|
||||
const spy3 = jasmine.createSpy('B')
|
||||
const A = Vue.extend({
|
||||
data: function () {
|
||||
return {
|
||||
a: 0,
|
||||
@ -120,21 +120,21 @@ describe('Options watch', () => {
|
||||
}
|
||||
})
|
||||
|
||||
var B = Vue.extend({
|
||||
const B = Vue.extend({
|
||||
extends: A,
|
||||
watch: {
|
||||
a: spy2
|
||||
}
|
||||
})
|
||||
|
||||
var C = Vue.extend({
|
||||
const C = Vue.extend({
|
||||
extends: B,
|
||||
watch: {
|
||||
a: spy3
|
||||
}
|
||||
})
|
||||
|
||||
var vm = new C()
|
||||
const vm = new C()
|
||||
vm.a = 1
|
||||
|
||||
waitForUpdate(() => {
|
||||
|
@ -1,5 +1,5 @@
|
||||
function insertCSS (text) {
|
||||
var cssEl = document.createElement('style')
|
||||
const cssEl = document.createElement('style')
|
||||
cssEl.textContent = text.trim()
|
||||
document.head.appendChild(cssEl)
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
var alias = require('../../scripts/alias')
|
||||
var webpack = require('webpack')
|
||||
const alias = require('../../scripts/alias')
|
||||
const webpack = require('webpack')
|
||||
|
||||
var webpackConfig = {
|
||||
const webpackConfig = {
|
||||
mode: 'development',
|
||||
resolve: {
|
||||
alias: alias
|
||||
|
@ -1,7 +1,7 @@
|
||||
var base = require('./karma.base.config.js')
|
||||
const base = require('./karma.base.config.js')
|
||||
|
||||
module.exports = function (config) {
|
||||
var options = Object.assign(base, {
|
||||
const options = Object.assign(base, {
|
||||
browsers: ['PhantomJS'],
|
||||
reporters: ['mocha', 'coverage'],
|
||||
coverageReporter: {
|
||||
|
@ -1,4 +1,4 @@
|
||||
var base = require('./karma.base.config.js')
|
||||
const base = require('./karma.base.config.js')
|
||||
|
||||
module.exports = function (config) {
|
||||
config.set(Object.assign(base, {
|
||||
|
@ -1,5 +1,5 @@
|
||||
var webpack = require('webpack')
|
||||
var base = require('./karma.base.config.js')
|
||||
const webpack = require('webpack')
|
||||
const base = require('./karma.base.config.js')
|
||||
|
||||
base.webpack.plugins = [
|
||||
new webpack.DefinePlugin({
|
||||
@ -19,7 +19,7 @@ base.webpack.plugins = [
|
||||
* smaller batches.
|
||||
*/
|
||||
|
||||
var batches = [
|
||||
const batches = [
|
||||
// the cool kids
|
||||
{
|
||||
sl_chrome: {
|
||||
@ -79,7 +79,7 @@ var batches = [
|
||||
]
|
||||
|
||||
module.exports = function (config) {
|
||||
var batch = batches[process.argv[4] || 0]
|
||||
const batch = batches[process.argv[4] || 0]
|
||||
|
||||
config.set(Object.assign(base, {
|
||||
singleRun: true,
|
||||
|
@ -1,4 +1,4 @@
|
||||
var base = require('./karma.base.config.js')
|
||||
const base = require('./karma.base.config.js')
|
||||
|
||||
module.exports = function (config) {
|
||||
config.set(Object.assign(base, {
|
||||
|
Loading…
Reference in New Issue
Block a user