Skip to content

Commit

Permalink
Command Line: Remove endsWith polyfill
Browse files Browse the repository at this point in the history
  • Loading branch information
at055612 committed Feb 10, 2022
1 parent 702d560 commit 88cd35d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
23 changes: 12 additions & 11 deletions plugins/command-line/prism-command-line.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,6 @@
return;
}

// Polyfill for pre-ES6 Support, i.e. Internet Explorer
if (!String.prototype.endsWith) {
String.prototype.endsWith = function (search, this_len) {
if (this_len === undefined || this_len > this.length) {
this_len = this.length;
}
return this.substring(this_len - search.length, this_len) === search;
};
}

var CLASS_PATTERN = /(?:^|\s)command-line(?:\s|$)/;
var PROMPT_CLASS = 'command-line-prompt';

Expand All @@ -22,6 +12,17 @@
? function (s, p) { return s.startsWith(p); }
: function (s, p) { return s.indexOf(p) === 0; };

// Support for IE11 that has no endsWith()
/** @type {(str: string, suffix: string) => boolean} */
var endsWith = ''.endsWith
? function (str, suffix) {
return str.endsWith(suffix);
}
: function (str, suffix) {
var len = str.length;
return str.substring(len - suffix.length, len) === suffix;
};

/**
* Returns whether the given hook environment has a command line info object.
*
Expand Down Expand Up @@ -81,7 +82,7 @@
if (lineContinuationStr && codeLines.length > 1) {
for (var j = 1; j < codeLines.length; j++) {
if (codeLines.hasOwnProperty(j - 1)
&& codeLines[j - 1].endsWith(lineContinuationStr)) {
&& endsWith(codeLines[j - 1], lineContinuationStr)) {
// Mark this line as being a continuation line
continuationLineIndicies.add(j);
}
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.

0 comments on commit 88cd35d

Please sign in to comment.