Skip to content

refactor(core): Replace "var" #8299

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 24, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion scripts/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
},
Expand Down
8 changes: 4 additions & 4 deletions scripts/get-weex-version.js
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/platforms/web/runtime/components/transition-group.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion src/platforms/web/util/style.js
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
})
Expand Down
2 changes: 1 addition & 1 deletion src/platforms/weex/runtime/modules/style.js
Original file line number Diff line number Diff line change
Expand Up @@ -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])
}
Expand Down
14 changes: 7 additions & 7 deletions test/e2e/runner.js
Original file line number Diff line number Diff line change
@@ -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'
})

Expand Down
6 changes: 3 additions & 3 deletions test/e2e/specs/grid.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module.exports = {
'grid': function (browser) {
var columns = ['name', 'power']
const columns = ['name', 'power']

browser
.url('http://localhost:8080/examples/grid/')
Expand Down Expand Up @@ -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]]
Expand Down
12 changes: 6 additions & 6 deletions test/e2e/specs/svg.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions test/e2e/specs/tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
6 changes: 3 additions & 3 deletions test/helpers/to-have-been-warned.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand All @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion test/helpers/trigger-event.js
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
6 changes: 3 additions & 3 deletions test/ssr/ssr-stream.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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, '')
})
Expand Down
4 changes: 2 additions & 2 deletions test/unit/features/component/component-async.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion test/unit/features/component/component-keep-alive.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down
2 changes: 1 addition & 1 deletion test/unit/features/directives/class.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand Down
4 changes: 2 additions & 2 deletions test/unit/features/directives/for.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions test/unit/features/directives/model-radio.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'])
Expand Down Expand Up @@ -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)
Expand Down
20 changes: 10 additions & 10 deletions test/unit/features/directives/model-select.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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(() => {
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion test/unit/features/directives/model-text.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand Down
8 changes: 4 additions & 4 deletions test/unit/features/directives/style.spec.js
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 2 additions & 2 deletions test/unit/features/instance/methods-data.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/unit/features/instance/methods-events.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading