Skip to content

Commit

Permalink
refactor: Disallow variable redeclarations
Browse files Browse the repository at this point in the history
Co-Authored-By: Michael Schmidt <[email protected]>
  • Loading branch information
ExE-Boss and RunDevelopment committed Mar 31, 2019
1 parent 08f1930 commit 1ad9c03
Show file tree
Hide file tree
Showing 10 changed files with 61 additions and 31 deletions.
2 changes: 1 addition & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
],
"no-inner-declarations": "off",
"no-mixed-spaces-and-tabs": "error",
"no-redeclare": "off",
"no-redeclare": "error",
"no-sparse-arrays": "off",
"no-unused-vars": [
"warn",
Expand Down
31 changes: 22 additions & 9 deletions components/prism-core.js
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,15 @@ var _ = {
return Token.stringify(_.util.encode(env.tokens), env.language);
},

/**
* @param {string} text
* @param {string | string[] | Array<string|Token>} strarr
* @param {Prism.Grammar} grammar
* @param {number} index
* @param {number} startPos
* @param {boolean} oneshot
* @param {string} [target]
*/
matchGrammar: function (text, strarr, grammar, index, startPos, oneshot, target) {
for (var token in grammar) {
if(!grammar.hasOwnProperty(token) || !grammar[token]) {
Expand Down Expand Up @@ -308,7 +317,9 @@ var _ = {
// Don’t cache length as it changes during the loop
for (var i = index, pos = startPos; i < strarr.length; pos += strarr[i].length, ++i) {

var str = strarr[i];
var str = strarr[i],
match,
delNum;

if (strarr.length > text.length) {
// Something went terribly wrong, ABORT, ABORT!
Expand All @@ -321,7 +332,7 @@ var _ = {

if (greedy && i != strarr.length - 1) {
pattern.lastIndex = pos;
var match = pattern.exec(text);
match = pattern.exec(text);
if (!match) {
break;
}
Expand Down Expand Up @@ -352,8 +363,8 @@ var _ = {
} else {
pattern.lastIndex = 0;

var match = pattern.exec(str),
delNum = 1;
match = pattern.exec(str);
delNum = 1;
}

if (!match) {
Expand All @@ -368,12 +379,14 @@ var _ = {
lookbehindLength = match[1] ? match[1].length : 0;
}

var from = match.index + lookbehindLength,
match = match[0].slice(lookbehindLength),
to = from + match.length,
before = str.slice(0, from),
from = match.index + lookbehindLength;
match = match[0].slice(lookbehindLength);
to = from + match.length;

var before = str.slice(0, from),
after = str.slice(to);

/** @type {[number, number, ...any[]]} */
var args = [i, delNum];

if (before) {
Expand Down Expand Up @@ -546,5 +559,5 @@ if (typeof module !== 'undefined' && module.exports) {

// hack for components to work correctly in node.js
if (typeof global !== 'undefined') {
global['Prism'] = Prism;
global.Prism = Prism;
}
2 changes: 1 addition & 1 deletion components/prism-core.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions plugins/command-line/prism-command-line.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,11 @@ Prism.hooks.add('before-highlight', function (env) {

var outputSections = pre.getAttribute('data-output');
var outputFilter = pre.getAttribute('data-filter-output');

var i = 0;
if (outputSections || outputSections === '') { // The user specified the output lines. -- cwells
outputSections = outputSections.split(',');
for (var i = 0; i < outputSections.length; i++) { // Parse the output sections into start/end ranges. -- cwells
for (i = 0; i < outputSections.length; i++) { // Parse the output sections into start/end ranges. -- cwells
var range = outputSections[i].split('-');
var outputStart = parseInt(range[0], 10);
var outputEnd = (range.length === 2 ? parseInt(range[1], 10) : outputStart);
Expand All @@ -59,7 +61,7 @@ Prism.hooks.add('before-highlight', function (env) {
}
}
} else if (outputFilter) { // Treat lines beginning with this string as output. -- cwells
for (var i = 0; i < codeLines.length; i++) {
for (i = 0; i < codeLines.length; i++) {
if (codeLines[i].indexOf(outputFilter) === 0) { // This line is output. -- cwells
outputLines[i] = codeLines[i].slice(outputFilter.length);
codeLines[i] = '';
Expand Down
2 changes: 1 addition & 1 deletion plugins/command-line/prism-command-line.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 1ad9c03

Please sign in to comment.