changed var to const (#13061)

This commit is contained in:
Patrick O'Carroll
2018-08-29 14:26:50 +02:00
committed by Torkel Ödegaard
parent 9423e3e124
commit 5e0d0c5816
50 changed files with 298 additions and 299 deletions

View File

@@ -16,16 +16,16 @@ export function graphiteAddFunc($compile) {
return {
link: function($scope, elem) {
var ctrl = $scope.ctrl;
const ctrl = $scope.ctrl;
var $input = $(inputTemplate);
var $button = $(buttonTemplate);
const $input = $(inputTemplate);
const $button = $(buttonTemplate);
$input.appendTo(elem);
$button.appendTo(elem);
ctrl.datasource.getFuncDefs().then(function(funcDefs) {
var allFunctions = _.map(funcDefs, 'name').sort();
const allFunctions = _.map(funcDefs, 'name').sort();
$scope.functionMenu = createFunctionDropDownMenu(funcDefs);
@@ -82,7 +82,7 @@ export function graphiteAddFunc($compile) {
});
var drop;
var cleanUpDrop = function() {
const cleanUpDrop = function() {
if (drop) {
drop.destroy();
drop = null;
@@ -106,7 +106,7 @@ export function graphiteAddFunc($compile) {
shortDesc = shortDesc.substring(0, 497) + '...';
}
var contentElement = document.createElement('div');
const contentElement = document.createElement('div');
contentElement.innerHTML = '<h4>' + funcDef.name + '</h4>' + rst2html(shortDesc);
drop = new Drop({
@@ -133,7 +133,7 @@ export function graphiteAddFunc($compile) {
angular.module('grafana.directives').directive('graphiteAddFunc', graphiteAddFunc);
function createFunctionDropDownMenu(funcDefs) {
var categories = {};
const categories = {};
_.forEach(funcDefs, function(funcDef) {
if (!funcDef.category) {

View File

@@ -20,10 +20,10 @@ export function graphiteFuncEditor($compile, templateSrv, popoverSrv) {
return {
restrict: 'A',
link: function postLink($scope, elem) {
var $funcLink = $(funcSpanTemplate);
var $funcControls = $(funcControlsTemplate);
var ctrl = $scope.ctrl;
var func = $scope.func;
const $funcLink = $(funcSpanTemplate);
const $funcControls = $(funcControlsTemplate);
const ctrl = $scope.ctrl;
const func = $scope.func;
var scheduledRelink = false;
var paramCountAtLink = 0;
var cancelBlur = null;
@@ -31,9 +31,9 @@ export function graphiteFuncEditor($compile, templateSrv, popoverSrv) {
function clickFuncParam(paramIndex) {
/*jshint validthis:true */
var $link = $(this);
var $comma = $link.prev('.comma');
var $input = $link.next();
const $link = $(this);
const $comma = $link.prev('.comma');
const $input = $link.next();
$input.val(func.params[paramIndex]);
@@ -43,7 +43,7 @@ export function graphiteFuncEditor($compile, templateSrv, popoverSrv) {
$input.focus();
$input.select();
var typeahead = $input.data('typeahead');
const typeahead = $input.data('typeahead');
if (typeahead) {
$input.val('');
typeahead.lookup();
@@ -76,14 +76,14 @@ export function graphiteFuncEditor($compile, templateSrv, popoverSrv) {
function switchToLink(inputElem, paramIndex) {
/*jshint validthis:true */
var $input = $(inputElem);
const $input = $(inputElem);
clearTimeout(cancelBlur);
cancelBlur = null;
var $link = $input.prev();
var $comma = $link.prev('.comma');
var newValue = $input.val();
const $link = $input.prev();
const $comma = $link.prev('.comma');
const newValue = $input.val();
// remove optional empty params
if (newValue !== '' || paramDef(paramIndex).optional) {
@@ -110,7 +110,7 @@ export function graphiteFuncEditor($compile, templateSrv, popoverSrv) {
// this = input element
function inputBlur(paramIndex) {
/*jshint validthis:true */
var inputElem = this;
const inputElem = this;
// happens long before the click event on the typeahead options
// need to have long delay because the blur
cancelBlur = setTimeout(function() {
@@ -151,7 +151,7 @@ export function graphiteFuncEditor($compile, templateSrv, popoverSrv) {
},
});
var typeahead = $input.data('typeahead');
const typeahead = $input.data('typeahead');
typeahead.lookup = function() {
this.query = this.$element.val() || '';
return this.process(this.source);
@@ -159,7 +159,7 @@ export function graphiteFuncEditor($compile, templateSrv, popoverSrv) {
}
function toggleFuncControls() {
var targetDiv = elem.closest('.tight-form');
const targetDiv = elem.closest('.tight-form');
if (elem.hasClass('show-function-controls')) {
elem.removeClass('show-function-controls');
@@ -178,8 +178,8 @@ export function graphiteFuncEditor($compile, templateSrv, popoverSrv) {
$funcControls.appendTo(elem);
$funcLink.appendTo(elem);
var defParams = _.clone(func.def.params);
var lastParam = _.last(func.def.params);
const defParams = _.clone(func.def.params);
const lastParam = _.last(func.def.params);
while (func.params.length >= defParams.length && lastParam && lastParam.multiple) {
defParams.push(_.assign({}, lastParam, { optional: true }));
@@ -192,7 +192,7 @@ export function graphiteFuncEditor($compile, templateSrv, popoverSrv) {
var paramValue = templateSrv.highlightVariablesAsHtml(func.params[index]);
var last = index >= func.params.length - 1 && param.optional && !paramValue;
const last = index >= func.params.length - 1 && param.optional && !paramValue;
if (last && param.multiple) {
paramValue = '+';
}
@@ -201,14 +201,14 @@ export function graphiteFuncEditor($compile, templateSrv, popoverSrv) {
$('<span class="comma' + (last ? ' query-part__last' : '') + '">, </span>').appendTo(elem);
}
var $paramLink = $(
const $paramLink = $(
'<a ng-click="" class="graphite-func-param-link' +
(last ? ' query-part__last' : '') +
'">' +
(paramValue || '&nbsp;') +
'</a>'
);
var $input = $(paramTemplate);
const $input = $(paramTemplate);
$input.attr('placeholder', param.name);
paramCountAtLink++;
@@ -251,7 +251,7 @@ export function graphiteFuncEditor($compile, templateSrv, popoverSrv) {
function registerFuncControlsActions() {
$funcControls.click(function(e) {
var $target = $(e.target);
const $target = $(e.target);
if ($target.hasClass('fa-remove')) {
toggleFuncControls();
$scope.$apply(function() {
@@ -277,7 +277,7 @@ export function graphiteFuncEditor($compile, templateSrv, popoverSrv) {
}
if ($target.hasClass('fa-question-circle')) {
var funcDef = ctrl.datasource.getFuncDef(func.def.name);
const funcDef = ctrl.datasource.getFuncDef(func.def.name);
if (funcDef && funcDef.description) {
popoverSrv.show({
element: e.target,

View File

@@ -1,7 +1,7 @@
import _ from 'lodash';
import { isVersionGtOrEq } from 'app/core/utils/version';
var index = {};
const index = {};
function addFuncDef(funcDef) {
funcDef.params = funcDef.params || [];
@@ -13,7 +13,7 @@ function addFuncDef(funcDef) {
}
}
var optionalSeriesRefArgs = [{ name: 'other', type: 'value_or_series', optional: true, multiple: true }];
const optionalSeriesRefArgs = [{ name: 'other', type: 'value_or_series', optional: true, multiple: true }];
addFuncDef({
name: 'scaleToSeconds',
@@ -962,9 +962,9 @@ export class FuncInstance {
}
render(metricExp) {
var str = this.def.name + '(';
const str = this.def.name + '(';
var parameters = _.map(
const parameters = _.map(
this.params,
function(value, index) {
var paramType;
@@ -1063,7 +1063,7 @@ function getFuncDef(name, idx?) {
}
function getFuncDefs(graphiteVersion, idx?) {
var funcs = {};
const funcs = {};
_.forEach(idx || index, function(funcDef) {
if (isVersionRelatedFunction(funcDef, graphiteVersion)) {
funcs[funcDef.name] = _.assign({}, funcDef, {
@@ -1078,7 +1078,7 @@ function getFuncDefs(graphiteVersion, idx?) {
// parse response from graphite /functions endpoint into internal format
function parseFuncDefs(rawDefs) {
var funcDefs = {};
const funcDefs = {};
_.forEach(rawDefs || {}, (funcDef, funcName) => {
// skip graphite graph functions
@@ -1095,7 +1095,7 @@ function parseFuncDefs(rawDefs) {
.replace(/.. code-block *:: *none/g, '.. code-block::');
}
var func = {
const func = {
name: funcDef.name,
description: description,
category: funcDef.group,
@@ -1120,7 +1120,7 @@ function parseFuncDefs(rawDefs) {
}
_.forEach(funcDef.params, rawParam => {
var param = {
const param = {
name: rawParam.name,
type: 'string',
optional: !rawParam.required,

View File

@@ -33,8 +33,8 @@ export default class GraphiteQuery {
return;
}
var parser = new Parser(this.target.target);
var astNode = parser.getAst();
const parser = new Parser(this.target.target);
const astNode = parser.getAst();
if (astNode === null) {
this.checkOtherSegmentsIndex = 0;
return;
@@ -69,7 +69,7 @@ export default class GraphiteQuery {
}
getSegmentPathUpTo(index) {
var arr = this.segments.slice(0, index);
const arr = this.segments.slice(0, index);
return _.reduce(
arr,
@@ -87,7 +87,7 @@ export default class GraphiteQuery {
switch (astNode.type) {
case 'function':
var innerFunc = this.datasource.createFuncInstance(astNode.name, {
const innerFunc = this.datasource.createFuncInstance(astNode.name, {
withDefaultParams: false,
});
_.each(astNode.params, param => {
@@ -133,7 +133,7 @@ export default class GraphiteQuery {
}
moveAliasFuncLast() {
var aliasFunc = _.find(this.functions, function(func) {
const aliasFunc = _.find(this.functions, function(func) {
return func.def.name.startsWith('alias');
});
@@ -157,7 +157,7 @@ export default class GraphiteQuery {
updateModelTarget(targets) {
// render query
if (!this.target.textEditor) {
var metricPath = this.getSegmentPathUpTo(this.segments.length).replace(/\.select metric$/, '');
const metricPath = this.getSegmentPathUpTo(this.segments.length).replace(/\.select metric$/, '');
this.target.target = _.reduce(this.functions, wrapFunction, metricPath);
}
@@ -173,12 +173,12 @@ export default class GraphiteQuery {
updateRenderedTarget(target, targets) {
// render nested query
var targetsByRefId = _.keyBy(targets, 'refId');
const targetsByRefId = _.keyBy(targets, 'refId');
// no references to self
delete targetsByRefId[target.refId];
var nestedSeriesRefRegex = /\#([A-Z])/g;
const nestedSeriesRefRegex = /\#([A-Z])/g;
var targetWithNestedQueries = target.target;
// Use ref count to track circular references
@@ -200,8 +200,8 @@ export default class GraphiteQuery {
// Keep interpolating until there are no query references
// The reason for the loop is that the referenced query might contain another reference to another query
while (targetWithNestedQueries.match(nestedSeriesRefRegex)) {
var updated = targetWithNestedQueries.replace(nestedSeriesRefRegex, (match, g1) => {
var t = targetsByRefId[g1];
const updated = targetWithNestedQueries.replace(nestedSeriesRefRegex, (match, g1) => {
const t = targetsByRefId[g1];
if (!t) {
return match;
}

View File

@@ -9,7 +9,7 @@ import _ from 'lodash';
// http://www.fileformat.info/info/unicode/category/Lo/list.htm
// http://www.fileformat.info/info/unicode/category/Nl/list.htm
var unicodeLetterTable = [
const unicodeLetterTable = [
170,
170,
181,
@@ -898,7 +898,7 @@ var unicodeLetterTable = [
195101,
];
var identifierStartTable = [];
const identifierStartTable = [];
for (var i = 0; i < 128; i++) {
identifierStartTable[i] =
@@ -920,7 +920,7 @@ for (var i = 0; i < 128; i++) {
(i >= 97 && i <= 122); // a-z
}
var identifierPartTable = identifierStartTable;
const identifierPartTable = identifierStartTable;
export function Lexer(expression) {
this.input = expression;
@@ -940,7 +940,7 @@ Lexer.prototype = {
},
tokenize: function() {
var list = [];
const list = [];
var token;
while ((token = this.next())) {
list.push(token);
@@ -1037,7 +1037,7 @@ Lexer.prototype = {
return /^[0-9a-fA-F]$/.test(str);
}
var readUnicodeEscapeSequence = _.bind(function() {
const readUnicodeEscapeSequence = _.bind(function() {
/*jshint validthis:true */
index += 1;
@@ -1045,10 +1045,10 @@ Lexer.prototype = {
return null;
}
var ch1 = this.peek(index + 1);
var ch2 = this.peek(index + 2);
var ch3 = this.peek(index + 3);
var ch4 = this.peek(index + 4);
const ch1 = this.peek(index + 1);
const ch2 = this.peek(index + 2);
const ch3 = this.peek(index + 3);
const ch4 = this.peek(index + 4);
var code;
if (isHexDigit(ch1) && isHexDigit(ch2) && isHexDigit(ch3) && isHexDigit(ch4)) {
@@ -1065,10 +1065,10 @@ Lexer.prototype = {
return null;
}, this);
var getIdentifierStart = _.bind(function() {
const getIdentifierStart = _.bind(function() {
/*jshint validthis:true */
var chr = this.peek(index);
var code = chr.charCodeAt(0);
const chr = this.peek(index);
const code = chr.charCodeAt(0);
if (chr === '*') {
index += 1;
@@ -1096,10 +1096,10 @@ Lexer.prototype = {
return null;
}, this);
var getIdentifierPart = _.bind(function() {
const getIdentifierPart = _.bind(function() {
/*jshint validthis:true */
var chr = this.peek(index);
var code = chr.charCodeAt(0);
const chr = this.peek(index);
const code = chr.charCodeAt(0);
if (code === 92) {
return readUnicodeEscapeSequence();
@@ -1170,7 +1170,7 @@ Lexer.prototype = {
scanNumericLiteral: function(): any {
var index = 0;
var value = '';
var length = this.input.length;
const length = this.input.length;
var char = this.peek(index);
var bad;
@@ -1385,7 +1385,7 @@ Lexer.prototype = {
},
scanPunctuator: function() {
var ch1 = this.peek();
const ch1 = this.peek();
if (this.isPunctuator(ch1)) {
return {
@@ -1411,7 +1411,7 @@ Lexer.prototype = {
*/
scanStringLiteral: function() {
/*jshint loopfunc:true */
var quote = this.peek();
const quote = this.peek();
// String must start with a quote.
if (quote !== '"' && quote !== "'") {
@@ -1434,8 +1434,8 @@ Lexer.prototype = {
};
}
var char = this.peek();
var jump = 1; // A length of a jump, after we're done
const char = this.peek();
const jump = 1; // A length of a jump, after we're done
// parsing this character.
value += char;

View File

@@ -54,14 +54,14 @@ Parser.prototype = {
},
metricSegment: function() {
var curly = this.curlyBraceSegment();
const curly = this.curlyBraceSegment();
if (curly) {
return curly;
}
if (this.match('identifier') || this.match('number')) {
// hack to handle float numbers in metric segments
var parts = this.consumeToken().value.split('.');
const parts = this.consumeToken().value.split('.');
if (parts.length === 2) {
this.tokens.splice(this.index, 0, { type: '.' });
this.tokens.splice(this.index + 1, 0, {
@@ -86,7 +86,7 @@ Parser.prototype = {
this.errorMark('Expected identifier after templateStart');
}
var node = {
const node = {
type: 'template',
value: this.consumeToken().value,
};
@@ -104,7 +104,7 @@ Parser.prototype = {
return null;
}
var node = {
const node = {
type: 'metric',
segments: [],
};
@@ -114,7 +114,7 @@ Parser.prototype = {
while (this.match('.')) {
this.consumeToken();
var segment = this.metricSegment();
const segment = this.metricSegment();
if (!segment) {
this.errorMark('Expected metric identifier');
}
@@ -130,7 +130,7 @@ Parser.prototype = {
return null;
}
var node: any = {
const node: any = {
type: 'function',
name: this.consumeToken().value,
};
@@ -165,7 +165,7 @@ Parser.prototype = {
return [];
}
var param =
const param =
this.functionCall() ||
this.numericLiteral() ||
this.seriesRefExpression() ||
@@ -186,12 +186,12 @@ Parser.prototype = {
return null;
}
var value = this.tokens[this.index].value;
const value = this.tokens[this.index].value;
if (!value.match(/\#[A-Z]/)) {
return null;
}
var token = this.consumeToken();
const token = this.consumeToken();
return {
type: 'series-ref',
@@ -215,7 +215,7 @@ Parser.prototype = {
return null;
}
var token = this.consumeToken();
const token = this.consumeToken();
if (token.isUnclosed) {
throw { message: 'Unclosed string parameter', pos: token.pos };
}
@@ -227,8 +227,8 @@ Parser.prototype = {
},
errorMark: function(text) {
var currentToken = this.tokens[this.index];
var type = currentToken ? currentToken.type : 'end of string';
const currentToken = this.tokens[this.index];
const type = currentToken ? currentToken.type : 'end of string';
throw {
message: text + ' instead found ' + type,
pos: currentToken ? currentToken.pos : this.lexer.char,
@@ -242,7 +242,7 @@ Parser.prototype = {
},
matchToken: function(type, index) {
var token = this.tokens[this.index + index];
const token = this.tokens[this.index + index];
return (token === undefined && type === '') || (token && token.type === type);
},

View File

@@ -72,7 +72,7 @@ export class GraphiteQueryCtrl extends QueryCtrl {
return;
}
var path = this.queryModel.getSegmentPathUpTo(fromIndex + 1);
const path = this.queryModel.getSegmentPathUpTo(fromIndex + 1);
if (path === '') {
return Promise.resolve();
}
@@ -110,7 +110,7 @@ export class GraphiteQueryCtrl extends QueryCtrl {
if (index > 0) {
query = this.queryModel.getSegmentPathUpTo(index) + '.' + query;
}
var options = {
const options = {
range: this.panelCtrl.range,
requestId: 'get-alt-segments',
};
@@ -118,7 +118,7 @@ export class GraphiteQueryCtrl extends QueryCtrl {
return this.datasource
.metricFindQuery(query, options)
.then(segments => {
var altSegments = _.map(segments, segment => {
const altSegments = _.map(segments, segment => {
return this.uiSegmentSrv.newSegment({
value: segment.text,
expandable: segment.expandable,
@@ -238,7 +238,7 @@ export class GraphiteQueryCtrl extends QueryCtrl {
return;
}
var oldTarget = this.queryModel.target.target;
const oldTarget = this.queryModel.target.target;
this.updateModelTarget();
if (this.queryModel.target !== oldTarget && !this.paused) {
@@ -247,7 +247,7 @@ export class GraphiteQueryCtrl extends QueryCtrl {
}
addFunction(funcDef) {
var newFunc = this.datasource.createFuncInstance(funcDef, {
const newFunc = this.datasource.createFuncInstance(funcDef, {
withDefaultParams: true,
});
newFunc.added = true;