Skip to content

Commit afa7f71

Browse files
committed
clean up variables
1 parent d878d83 commit afa7f71

File tree

3 files changed

+19
-24
lines changed

3 files changed

+19
-24
lines changed

.eslintrc.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ module.exports = {
3535

3636
// TODO maybe
3737
"camelcase": "off", // TODO: turn on later
38-
// "init-declarations": ["error","always"]
38+
"init-declarations": ["error","always"]
3939
},
4040
"overrides": [
4141
{

src/highlight.js

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,12 @@ const HLJS = function(hljs) {
5656
}
5757

5858
function blockLanguage(block) {
59-
var match;
6059
var classes = block.className + ' ';
6160

6261
classes += block.parentNode ? block.parentNode.className : '';
6362

6463
// language-* takes precedence over non-prefixed class names.
65-
match = options.languageDetectRe.exec(classes);
64+
const match = options.languageDetectRe.exec(classes);
6665
if (match) {
6766
var language = getLanguage(match[1]);
6867
if (!language) {
@@ -137,22 +136,20 @@ const HLJS = function(hljs) {
137136
}
138137

139138
function processKeywords() {
140-
var keyword_match, last_index, match, buf;
141-
142139
if (!top.keywords) {
143140
emitter.addText(mode_buffer);
144141
return;
145142
}
146143

147-
last_index = 0;
144+
let last_index = 0;
148145
top.lexemesRe.lastIndex = 0;
149-
match = top.lexemesRe.exec(mode_buffer);
150-
buf = "";
146+
let match = top.lexemesRe.exec(mode_buffer);
147+
let buf = "";
151148

152149
while (match) {
153150
buf += mode_buffer.substring(last_index, match.index);
154-
keyword_match = keywordMatch(top, match);
155-
var kind = null;
151+
const keyword_match = keywordMatch(top, match);
152+
let kind = null;
156153
if (keyword_match) {
157154
emitter.addText(buf);
158155
buf = "";
@@ -305,7 +302,6 @@ const HLJS = function(hljs) {
305302

306303
var lastMatch = {};
307304
function processLexeme(text_before_match, match) {
308-
var err;
309305
var lexeme = match && match[0];
310306

311307
// add non-matched text to the current mode buffer
@@ -324,7 +320,7 @@ const HLJS = function(hljs) {
324320
// spit the "skipped" character that our regex choked on back into the output sequence
325321
mode_buffer += codeToHighlight.slice(match.index, match.index + 1);
326322
if (!SAFE_MODE) {
327-
err = new Error('0 width match regex');
323+
const err = new Error('0 width match regex');
328324
err.languageName = languageName;
329325
err.badRule = lastMatch.rule;
330326
throw err;
@@ -337,7 +333,7 @@ const HLJS = function(hljs) {
337333
return doBeginMatch(match);
338334
} else if (match.type === "illegal" && !ignore_illegals) {
339335
// illegal match, we do not continue processing
340-
err = new Error('Illegal lexeme "' + lexeme + '" for mode "' + (top.className || '<unnamed>') + '"');
336+
const err = new Error('Illegal lexeme "' + lexeme + '" for mode "' + (top.className || '<unnamed>') + '"');
341337
err.mode = top;
342338
throw err;
343339
} else if (match.type === "end") {
@@ -370,9 +366,9 @@ const HLJS = function(hljs) {
370366
}
371367

372368
compileLanguage(language);
369+
var result = '';
373370
var top = continuation || language;
374371
var continuations = {}; // keep continuations for sub-languages
375-
var result;
376372
var emitter = new options.__emitter(options);
377373
processContinuations();
378374
var mode_buffer = '';
@@ -520,8 +516,8 @@ const HLJS = function(hljs) {
520516
two optional parameters for fixMarkup.
521517
*/
522518
function highlightBlock(block) {
523-
var node, originalStream, result, resultNode, text;
524-
var language = blockLanguage(block);
519+
let node = null;
520+
const language = blockLanguage(block);
525521

526522
if (shouldNotHighlight(language)) return;
527523

@@ -534,12 +530,12 @@ const HLJS = function(hljs) {
534530
} else {
535531
node = block;
536532
}
537-
text = node.textContent;
538-
result = language ? highlight(language, text, true) : highlightAuto(text);
533+
const text = node.textContent;
534+
const result = language ? highlight(language, text, true) : highlightAuto(text);
539535

540-
originalStream = nodeStream(node);
536+
const originalStream = nodeStream(node);
541537
if (originalStream.length) {
542-
resultNode = document.createElement('div');
538+
const resultNode = document.createElement('div');
543539
resultNode.innerHTML = result.value;
544540
result.value = mergeStreams(originalStream, nodeStream(resultNode), text);
545541
}
@@ -589,7 +585,7 @@ const HLJS = function(hljs) {
589585
var PLAINTEXT_LANGUAGE = { disableAutodetect: true };
590586

591587
function registerLanguage(name, language) {
592-
var lang;
588+
var lang = null;
593589
try {
594590
lang = language(hljs);
595591
} catch (error) {

src/lib/utils.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,14 @@ export function escapeHTML(value) {
99
* @returns a single new object
1010
*/
1111
export function inherit(parent) { // inherit(parent, override_obj, override_obj, ...)
12-
var key;
1312
var result = {};
1413
var objects = Array.prototype.slice.call(arguments, 1);
1514

16-
for (key in parent) {
15+
for (const key in parent) {
1716
result[key] = parent[key];
1817
}
1918
objects.forEach(function(obj) {
20-
for (key in obj) {
19+
for (const key in obj) {
2120
result[key] = obj[key];
2221
}
2322
});

0 commit comments

Comments
 (0)