mirror of
https://github.com/liriliri/eruda.git
synced 2026-04-17 10:58:36 +08:00
Use let instead of var
This commit is contained in:
@@ -96,7 +96,7 @@ under html root element.
|
||||
For more information, please check the [documentation](doc/API.md).
|
||||
|
||||
```javascript
|
||||
var el = document.createElement('div');
|
||||
let el = document.createElement('div');
|
||||
document.body.appendChild(el);
|
||||
|
||||
eruda.init({
|
||||
|
||||
@@ -14,7 +14,7 @@ Initialize eruda.
|
||||
|useShadowDom=true|boolean |Use shadow dom for css encapsulation |
|
||||
|
||||
```javascript
|
||||
var el = document.createElement('div');
|
||||
let el = document.createElement('div');
|
||||
document.body.appendChild(el);
|
||||
|
||||
eruda.init({
|
||||
@@ -60,7 +60,7 @@ eruda.position(); // -> {x: 20, y: 20}
|
||||
Get tool, eg. console, elements panels.
|
||||
|
||||
```javascript
|
||||
var console = eruda.get('console');
|
||||
let console = eruda.get('console');
|
||||
console.log('eruda');
|
||||
```
|
||||
|
||||
|
||||
@@ -80,7 +80,7 @@ Js文件对于移动端来说略重(gzip后大概100kb)。建议通过url参
|
||||
* tool:指定要初始化哪些面板,默认加载所有。
|
||||
|
||||
```javascript
|
||||
var el = document.createElement('div');
|
||||
let el = document.createElement('div');
|
||||
document.body.appendChild(el);
|
||||
|
||||
eruda.init({
|
||||
|
||||
@@ -22,7 +22,7 @@ Display console logs. Implementation detail follows the [console api spec](https
|
||||
|maxLogNum |string |Max log number |
|
||||
|
||||
```javascript
|
||||
var console = eruda.get('console');
|
||||
let console = eruda.get('console');
|
||||
console.config.set('catchGlobalErr', true);
|
||||
```
|
||||
|
||||
@@ -33,7 +33,7 @@ All these methods can be used in the same way as window.console object.
|
||||
Note: When called, a corresponding event is triggered.
|
||||
|
||||
```javascript
|
||||
var console = eruda.get('console');
|
||||
let console = eruda.get('console');
|
||||
console.log('eruda is a console for %s.', 'mobile browsers');
|
||||
console.table([{test: 1}, {test: 2}, {test2: 3}], 'test');
|
||||
console.error(new Error('eruda'));
|
||||
@@ -295,7 +295,7 @@ Add color to select a color.
|
||||
Add a separator.
|
||||
|
||||
```javascript
|
||||
var cfg = eruda.util.createCfg('test');
|
||||
let cfg = eruda.util.createCfg('test');
|
||||
|
||||
cfg.set(eruda.util.defaults(cfg.get(), {
|
||||
testBool: true,
|
||||
|
||||
@@ -3,13 +3,13 @@
|
||||
|
||||
_('toStr each filter')
|
||||
|
||||
var styleList = [],
|
||||
scale = 1
|
||||
let styleList = []
|
||||
let scale = 1
|
||||
|
||||
function exports(css, container) {
|
||||
css = toStr(css)
|
||||
|
||||
for (var i = 0, len = styleList.length; i < len; i++) {
|
||||
for (let i = 0, len = styleList.length; i < len; i++) {
|
||||
if (styleList[i].css === css) return
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
_('last trim')
|
||||
|
||||
function exports(url) {
|
||||
var ret = last(url.split('/'))
|
||||
let ret = last(url.split('/'))
|
||||
|
||||
if (ret.indexOf('?') > -1) ret = trim(ret.split('?')[0])
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
_('startWith')
|
||||
|
||||
var origin = window.location.origin
|
||||
let origin = window.location.origin
|
||||
|
||||
function exports(url) {
|
||||
return !startWith(url, origin)
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
*/
|
||||
|
||||
function exports(el) {
|
||||
var parentNode = el.parentNode
|
||||
let parentNode = el.parentNode
|
||||
|
||||
if (!parentNode) return false
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ _('isUndef memStorage')
|
||||
function exports(type, memReplacement) {
|
||||
if (isUndef(memReplacement)) memReplacement = true
|
||||
|
||||
var ret
|
||||
let ret
|
||||
|
||||
switch (type) {
|
||||
case 'local':
|
||||
@@ -19,9 +19,9 @@ function exports(type, memReplacement) {
|
||||
|
||||
try {
|
||||
// Safari private browsing
|
||||
var x = 'test-localStorage-' + Date.now()
|
||||
let x = 'test-localStorage-' + Date.now()
|
||||
ret.setItem(x, x)
|
||||
var y = ret.getItem(x)
|
||||
let y = ret.getItem(x)
|
||||
ret.removeItem(x)
|
||||
if (y !== x) throw new Error()
|
||||
} catch (e) {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
var webpackCfg = require('./script/webpack.dev')
|
||||
const webpackCfg = require('./script/webpack.dev')
|
||||
webpackCfg.devtool = 'inline-source-map'
|
||||
|
||||
module.exports = function(config) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
module.exports = function(config) {
|
||||
var customLaunchers = {
|
||||
let customLaunchers = {
|
||||
sl_ios_safari_8: {
|
||||
base: 'SauceLabs',
|
||||
browserName: 'iphone',
|
||||
|
||||
@@ -1,22 +1,22 @@
|
||||
var path = require('path'),
|
||||
util = require('./util'),
|
||||
istanbul = require('istanbul')
|
||||
const path = require('path')
|
||||
const util = require('./util')
|
||||
const istanbul = require('istanbul')
|
||||
|
||||
var collector = new istanbul.Collector(),
|
||||
reporter = new istanbul.Reporter()
|
||||
let collector = new istanbul.Collector()
|
||||
let reporter = new istanbul.Reporter()
|
||||
|
||||
var remappedJson = require('../coverage/coverage-remapped.json')
|
||||
let remappedJson = require('../coverage/coverage-remapped.json')
|
||||
|
||||
var coverage = util.reduce(
|
||||
let coverage = util.reduce(
|
||||
util.keys(remappedJson),
|
||||
function(result, source) {
|
||||
if (isSrc()) {
|
||||
var correctPath = source.replace(
|
||||
let correctPath = source.replace(
|
||||
path.resolve(__dirname, '../src'),
|
||||
path.resolve(__dirname, '../')
|
||||
)
|
||||
|
||||
var val = remappedJson[source]
|
||||
let val = remappedJson[source]
|
||||
val.path = correctPath
|
||||
result[correctPath] = val
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
var copy = require('copy'),
|
||||
path = require('path'),
|
||||
util = require('./util')
|
||||
const copy = require('copy')
|
||||
const path = require('path')
|
||||
const util = require('./util')
|
||||
|
||||
util.mkdir(path.resolve(__dirname, '../test/lib'), function(err) {
|
||||
if (err) return console.log(err)
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
var autoprefixer = require('autoprefixer'),
|
||||
classPrefix = require('postcss-class-prefix'),
|
||||
webpack = require('webpack'),
|
||||
pkg = require('../package.json'),
|
||||
path = require('path')
|
||||
const autoprefixer = require('autoprefixer')
|
||||
const classPrefix = require('postcss-class-prefix')
|
||||
const webpack = require('webpack')
|
||||
const pkg = require('../package.json')
|
||||
const path = require('path')
|
||||
|
||||
process.traceDeprecation = true
|
||||
|
||||
var nodeModDir = path.resolve('./node_modules/') + '/',
|
||||
banner = pkg.name + ' v' + pkg.version + ' ' + pkg.homepage
|
||||
let nodeModDir = path.resolve('./node_modules/') + '/'
|
||||
let banner = pkg.name + ' v' + pkg.version + ' ' + pkg.homepage
|
||||
|
||||
var postcssLoader = {
|
||||
let postcssLoader = {
|
||||
loader: 'postcss-loader',
|
||||
options: {
|
||||
plugins: [classPrefix('eruda-'), autoprefixer]
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
var webpack = require('webpack')
|
||||
const webpack = require('webpack')
|
||||
|
||||
exports = require('./webpack.base')
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
var webpack = require('webpack')
|
||||
const webpack = require('webpack')
|
||||
|
||||
exports = require('./webpack.base')
|
||||
|
||||
|
||||
@@ -10,8 +10,8 @@ let callbacks = {},
|
||||
if (isWorkerSupported) {
|
||||
tryIt(function() {
|
||||
/* Some browsers like uc mobile doesn't destroy worker properly after refreshing.
|
||||
* After a few times of visiting, it reaches the maximum number of workers per site.
|
||||
*/
|
||||
* After a few times of visiting, it reaches the maximum number of workers per site.
|
||||
*/
|
||||
worker = new StringifyWorker()
|
||||
worker.onmessage = function(e) {
|
||||
let [id, result] = e.data
|
||||
|
||||
@@ -287,8 +287,8 @@ class Visitor {
|
||||
}
|
||||
visit(val) {
|
||||
/* Add 0 to distinguish stringify generated id from JsonViewer id.
|
||||
* When used in web worker, they are not calling the same uniqId method, thus result may be repeated.
|
||||
*/
|
||||
* When used in web worker, they are not calling the same uniqId method, thus result may be repeated.
|
||||
*/
|
||||
let id = uniqId('erudaJson0')
|
||||
|
||||
this._visited.push({ id, val, abstract: {} })
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
function boot(name, cb) {
|
||||
// Need a little delay to make sure width and height of webpack dev server iframe are initialized.
|
||||
setTimeout(function() {
|
||||
var options = {
|
||||
let options = {
|
||||
useShadowDom: false
|
||||
}
|
||||
if (name) {
|
||||
@@ -34,7 +34,7 @@ function boot(name, cb) {
|
||||
}
|
||||
|
||||
function loadJs(src, cb) {
|
||||
var script = document.createElement('script')
|
||||
let script = document.createElement('script')
|
||||
script.src = src + '.js'
|
||||
script.onload = cb
|
||||
document.body.appendChild(script)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
describe('console', function() {
|
||||
var tool = eruda.get('console'),
|
||||
$tool = $('.eruda-console')
|
||||
let tool = eruda.get('console')
|
||||
let $tool = $('.eruda-console')
|
||||
|
||||
beforeEach(function() {
|
||||
eruda.show('console')
|
||||
@@ -8,7 +8,7 @@ describe('console', function() {
|
||||
})
|
||||
|
||||
it('string', function() {
|
||||
var text = '<span>This is a log</span>'
|
||||
let text = '<span>This is a log</span>'
|
||||
|
||||
tool.log(text)
|
||||
expect($tool.find('.eruda-log')).toContainText(text)
|
||||
@@ -26,7 +26,7 @@ describe('console', function() {
|
||||
})
|
||||
|
||||
it('basic object', function() {
|
||||
var obj = { a: 1 }
|
||||
let obj = { a: 1 }
|
||||
|
||||
tool.log(obj)
|
||||
expect($tool.find('.eruda-log')).toContainText('Object { a: 1 }')
|
||||
@@ -97,8 +97,8 @@ describe('console', function() {
|
||||
})
|
||||
|
||||
it('Repeat log', function() {
|
||||
for (var i = 0; i < 10; i++) tool.log(1)
|
||||
var $log = $tool.find('.eruda-log-item')
|
||||
for (let i = 0; i < 10; i++) tool.log(1)
|
||||
let $log = $tool.find('.eruda-log-item')
|
||||
expect($log).toHaveLength(1)
|
||||
expect($log.find('.eruda-count')).toContainText('10')
|
||||
})
|
||||
@@ -136,7 +136,7 @@ describe('console', function() {
|
||||
return log.type !== 'error'
|
||||
})
|
||||
|
||||
var obj = {}
|
||||
let obj = {}
|
||||
Object.defineProperty(obj, 'a', {
|
||||
get: function() {
|
||||
tool.error('deprecated')
|
||||
@@ -191,11 +191,11 @@ describe('console', function() {
|
||||
})
|
||||
|
||||
describe('config', function() {
|
||||
var config = tool.config
|
||||
let config = tool.config
|
||||
|
||||
it('max number', function() {
|
||||
config.set('maxLogNum', '10')
|
||||
for (var i = 0; i < 20; i++) tool.log(i)
|
||||
for (let i = 0; i < 20; i++) tool.log(i)
|
||||
expect($tool.find('.eruda-log-item')).toHaveLength(10)
|
||||
})
|
||||
|
||||
@@ -253,7 +253,7 @@ describe('console', function() {
|
||||
|
||||
describe('events', function() {
|
||||
it('log', function() {
|
||||
var sum = 0
|
||||
let sum = 0
|
||||
function add(num) {
|
||||
sum += num
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
describe('elements', function() {
|
||||
var tool = eruda.get('elements'),
|
||||
$tool = $('.eruda-elements')
|
||||
let tool = eruda.get('elements')
|
||||
let $tool = $('.eruda-elements')
|
||||
|
||||
beforeEach(function() {
|
||||
eruda.show('elements')
|
||||
|
||||
@@ -7,7 +7,7 @@ describe('devTools', function() {
|
||||
})
|
||||
|
||||
it('init', function() {
|
||||
var container = document.createElement('div')
|
||||
let container = document.createElement('div')
|
||||
container.id = 'eruda'
|
||||
document.body.appendChild(container)
|
||||
|
||||
@@ -17,7 +17,7 @@ describe('devTools', function() {
|
||||
useShadowDom: false
|
||||
})
|
||||
|
||||
var $eruda = $('#eruda')
|
||||
let $eruda = $('#eruda')
|
||||
expect($eruda.find('.eruda-dev-tools')).toHaveLength(1)
|
||||
})
|
||||
})
|
||||
@@ -36,7 +36,7 @@ describe('devTools', function() {
|
||||
})
|
||||
|
||||
it('show', function() {
|
||||
var $tool = $('.eruda-test')
|
||||
let $tool = $('.eruda-test')
|
||||
expect($tool).toBeHidden()
|
||||
eruda.show('test')
|
||||
expect($tool).toHaveCss({ display: 'block' })
|
||||
|
||||
@@ -45,7 +45,7 @@
|
||||
</nav>
|
||||
<script>
|
||||
(function () {
|
||||
var el = document.createElement('div');
|
||||
let el = document.createElement('div');
|
||||
document.body.appendChild(el);
|
||||
setTimeout(function () {
|
||||
try
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
describe('info', function() {
|
||||
var tool = eruda.get('info'),
|
||||
$tool = $('.eruda-info')
|
||||
let tool = eruda.get('info')
|
||||
let $tool = $('.eruda-info')
|
||||
|
||||
describe('default', function() {
|
||||
it('location', function() {
|
||||
|
||||
@@ -49,13 +49,13 @@
|
||||
}
|
||||
addClickEvent('issue17', function ()
|
||||
{
|
||||
var B = function () {};
|
||||
var A = function () { this._data = 'eruda' };
|
||||
let B = function () {};
|
||||
let A = function () { this._data = 'eruda' };
|
||||
A.prototype = Object.create(B.prototype);
|
||||
Object.defineProperty(A.prototype, 'data', {
|
||||
get: function () { return this._data }
|
||||
});
|
||||
var a = new A();
|
||||
let a = new A();
|
||||
console.log(a);
|
||||
});
|
||||
addClickEvent('plugin', function ()
|
||||
@@ -72,7 +72,7 @@
|
||||
}
|
||||
};
|
||||
});
|
||||
var Tool = eruda.Tool;
|
||||
let Tool = eruda.Tool;
|
||||
eruda.add(new (Tool.extend({
|
||||
name: 'test3',
|
||||
init: function ($el)
|
||||
@@ -89,7 +89,7 @@
|
||||
resolve();
|
||||
}).then(function (res)
|
||||
{
|
||||
var a = res.a;
|
||||
let a = res.a;
|
||||
})
|
||||
});
|
||||
addClickEvent('issue31', function ()
|
||||
@@ -106,8 +106,8 @@
|
||||
});
|
||||
addClickEvent('big-array', function ()
|
||||
{
|
||||
var arr = [];
|
||||
for (var i = 0; i < 10000; i++) {
|
||||
let arr = [];
|
||||
for (let i = 0; i < 10000; i++) {
|
||||
arr.push(i);
|
||||
}
|
||||
console.log(arr);
|
||||
|
||||
@@ -1,7 +1,4 @@
|
||||
describe('network', function() {
|
||||
var tool = eruda.get('network'),
|
||||
$tool = $('.eruda-network')
|
||||
|
||||
beforeEach(function() {
|
||||
eruda.show('network')
|
||||
})
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
describe('resources', function() {
|
||||
var tool = eruda.get('resources'),
|
||||
$tool = $('.eruda-resources')
|
||||
let $tool = $('.eruda-resources')
|
||||
|
||||
beforeEach(function() {
|
||||
eruda.show('resources')
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
describe('settings', function() {
|
||||
var tool = eruda.get('settings'),
|
||||
$tool = $('.eruda-settings')
|
||||
let tool = eruda.get('settings')
|
||||
let $tool = $('.eruda-settings')
|
||||
|
||||
var cfg = eruda.config.create('eruda-test')
|
||||
let cfg = eruda.config.create('eruda-test')
|
||||
cfg.set({
|
||||
testSwitch: false,
|
||||
testSelect: '1',
|
||||
@@ -15,7 +15,7 @@ describe('settings', function() {
|
||||
})
|
||||
|
||||
it('switch', function() {
|
||||
var text = 'Test Switch'
|
||||
let text = 'Test Switch'
|
||||
|
||||
tool.switch(cfg, 'testSwitch', text)
|
||||
expect($tool.find('.eruda-switch')).toContainText(text)
|
||||
@@ -29,10 +29,10 @@ describe('settings', function() {
|
||||
})
|
||||
|
||||
it('select', function() {
|
||||
var text = 'Test Select'
|
||||
let text = 'Test Select'
|
||||
|
||||
tool.select(cfg, 'testSelect', text, ['1', '2', '3'])
|
||||
var $el = $tool.find('.eruda-select')
|
||||
let $el = $tool.find('.eruda-select')
|
||||
expect($el.find('ul li').length).toEqual(3)
|
||||
expect($el.find('.eruda-head')).toContainText(text)
|
||||
expect($el.find('.eruda-val')).toContainText('1')
|
||||
@@ -44,20 +44,20 @@ describe('settings', function() {
|
||||
expect(cfg.get('testSelect')).toBe('2')
|
||||
})
|
||||
it('range', function() {
|
||||
var text = 'Test Range'
|
||||
let text = 'Test Range'
|
||||
|
||||
tool.range(cfg, 'testRange', text, { min: 0, max: 1, step: 0.1 })
|
||||
var $el = $tool.find('.eruda-range')
|
||||
let $el = $tool.find('.eruda-range')
|
||||
expect($el.find('.eruda-head')).toContainText(text)
|
||||
expect($el.find('input').length).toEqual(1)
|
||||
$el.find('.eruda-head').click()
|
||||
})
|
||||
|
||||
it('color', function() {
|
||||
var text = 'Test Color'
|
||||
let text = 'Test Color'
|
||||
|
||||
tool.color(cfg, 'testColor', text, ['#000', '#fff'])
|
||||
var $el = $tool.find('.eruda-color')
|
||||
let $el = $tool.find('.eruda-color')
|
||||
expect($el.find('.eruda-head')).toContainText(text)
|
||||
expect($el.find('ul li').length).toEqual(2)
|
||||
$el.find('.eruda-head').click()
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
describe('snippets', function() {
|
||||
var tool = eruda.get('snippets'),
|
||||
$tool = $('.eruda-snippets')
|
||||
let tool = eruda.get('snippets')
|
||||
let $tool = $('.eruda-snippets')
|
||||
|
||||
describe('default', function() {
|
||||
it('border all', function() {
|
||||
expect($tool.find('.eruda-name').eq(0)).toContainText('Border All')
|
||||
|
||||
var $body = $('body'),
|
||||
$btn = $tool.find('.eruda-run').eq(0)
|
||||
let $body = $('body')
|
||||
let $btn = $tool.find('.eruda-run').eq(0)
|
||||
|
||||
$btn.click()
|
||||
expect($body).toHaveCss({ outlineWidth: '2px' })
|
||||
@@ -26,8 +26,8 @@ describe('snippets', function() {
|
||||
it('edit page', function() {
|
||||
expect($tool.find('.eruda-name').eq(3)).toContainText('Edit Page')
|
||||
|
||||
var $body = $('body'),
|
||||
$btn = $tool.find('.eruda-run').eq(3)
|
||||
let $body = $('body')
|
||||
let $btn = $tool.find('.eruda-run').eq(3)
|
||||
|
||||
$btn.click()
|
||||
expect($body).toHaveAttr('contenteditable', 'true')
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
describe('sources', function() {
|
||||
var tool = eruda.get('sources'),
|
||||
$tool = $('.eruda-sources')
|
||||
let tool = eruda.get('sources')
|
||||
let $tool = $('.eruda-sources')
|
||||
|
||||
beforeEach(function() {
|
||||
eruda.show('sources')
|
||||
|
||||
Reference in New Issue
Block a user