Upgrade the source to use ES6 syntax including classes, import and static properties (#679)

* Add babel transform-class-properties to have static class properties

* Upgrade Lexer and Parser files to use ES6 classes

* Update eslint max line length to 90 character (more indent because of using ES6 classes)

* Upgrade eslint and jasmin to support ES stage-2 features

* Use static properties to place constants near their functions

* Migrate all remaining sources to ES6 syntax

* Increase eslint max line length to 84

* Remove non-babelified endpoint in dev server.js

* Clean up server.js functions after removing browserified

* Make screenshotter not to use babel endpoint as we babelify everything now
This commit is contained in:
Hossein Saniei
2017-07-03 16:39:21 +04:30
committed by Kevin Barabash
parent 0edd3d1bbb
commit a019f36f8a
28 changed files with 1766 additions and 1759 deletions

View File

@@ -9,53 +9,55 @@
* @param {string} message The error message
* @param {(Token|ParseNode)=} token An object providing position information
*/
function ParseError(message, token) {
let error = "KaTeX parse error: " + message;
let start;
let end;
class ParseError {
constructor(message, token) {
let error = "KaTeX parse error: " + message;
let start;
let end;
if (token && token.lexer && token.start <= token.end) {
// If we have the input and a position, make the error a bit fancier
if (token && token.lexer && token.start <= token.end) {
// If we have the input and a position, make the error a bit fancier
// Get the input
const input = token.lexer.input;
// Get the input
const input = token.lexer.input;
// Prepend some information
start = token.start;
end = token.end;
if (start === input.length) {
error += " at end of input: ";
} else {
error += " at position " + (start + 1) + ": ";
// Prepend some information
start = token.start;
end = token.end;
if (start === input.length) {
error += " at end of input: ";
} else {
error += " at position " + (start + 1) + ": ";
}
// Underline token in question using combining underscores
const underlined = input.slice(start, end).replace(/[^]/g, "$&\u0332");
// Extract some context from the input and add it to the error
let left;
if (start > 15) {
left = "…" + input.slice(start - 15, start);
} else {
left = input.slice(0, start);
}
let right;
if (end + 15 < input.length) {
right = input.slice(end, end + 15) + "…";
} else {
right = input.slice(end);
}
error += left + underlined + right;
}
// Underline token in question using combining underscores
const underlined = input.slice(start, end).replace(/[^]/g, "$&\u0332");
// Some hackery to make ParseError a prototype of Error
// See http://stackoverflow.com/a/8460753
const self = new Error(error);
self.name = "ParseError";
self.__proto__ = ParseError.prototype;
// Extract some context from the input and add it to the error
let left;
if (start > 15) {
left = "…" + input.slice(start - 15, start);
} else {
left = input.slice(0, start);
}
let right;
if (end + 15 < input.length) {
right = input.slice(end, end + 15) + "…";
} else {
right = input.slice(end);
}
error += left + underlined + right;
self.position = start;
return self;
}
// Some hackery to make ParseError a prototype of Error
// See http://stackoverflow.com/a/8460753
const self = new Error(error);
self.name = "ParseError";
self.__proto__ = ParseError.prototype;
self.position = start;
return self;
}
// More hackery