Fix various javascript warnings and typos

This commit is contained in:
Eric Vergnaud 2021-01-23 20:39:53 +08:00
parent 107f40c63c
commit 954649d5aa
10 changed files with 58 additions and 54 deletions

View File

@ -73,4 +73,4 @@ const CharStreams = {
} }
}; };
module.exports = CharStreams module.exports = CharStreams;

View File

@ -99,11 +99,11 @@ class IntervalSet {
const r = this.intervals[k + 1]; const r = this.intervals[k + 1];
// if r contained in l // if r contained in l
if (l.stop >= r.stop) { if (l.stop >= r.stop) {
this.intervals.pop(k + 1); this.intervals = this.intervals.splice(k + 1, 1);
this.reduce(k); this.reduce(k);
} else if (l.stop >= r.start) { } else if (l.stop >= r.start) {
this.intervals[k] = new Interval(l.start, r.stop); this.intervals[k] = new Interval(l.start, r.stop);
this.intervals.pop(k + 1); this.intervals = this.intervals.splice(k + 1, 1);
} }
} }
} }

View File

@ -423,12 +423,12 @@ function titleCase(str) {
function equalArrays(a, b) { function equalArrays(a, b) {
if (!Array.isArray(a) || !Array.isArray(b)) if (!Array.isArray(a) || !Array.isArray(b))
return false; return false;
if (a == b) if (a === b)
return true; return true;
if (a.length != b.length) if (a.length !== b.length)
return false; return false;
for (let i = 0; i < a.length; i++) { for (let i = 0; i < a.length; i++) {
if (a[i] == b[i]) if (a[i] === b[i])
continue; continue;
if (!a[i].equals || !a[i].equals(b[i])) if (!a[i].equals || !a[i].equals(b[i]))
return false; return false;

View File

@ -156,7 +156,7 @@ class LexerATNConfig extends ATNConfig {
equals(other) { equals(other) {
return this === other || return this === other ||
(other instanceof LexerATNConfig && (other instanceof LexerATNConfig &&
this.passedThroughNonGreedyDecision == other.passedThroughNonGreedyDecision && this.passedThroughNonGreedyDecision === other.passedThroughNonGreedyDecision &&
(this.lexerActionExecutor ? this.lexerActionExecutor.equals(other.lexerActionExecutor) : !other.lexerActionExecutor) && (this.lexerActionExecutor ? this.lexerActionExecutor.equals(other.lexerActionExecutor) : !other.lexerActionExecutor) &&
super.equals(other)); super.equals(other));
} }

View File

@ -589,7 +589,7 @@ class ParserATNSimulator extends ATNSimulator {
} }
const fullCtx = true; const fullCtx = true;
let foundExactAmbig = false; let foundExactAmbig = false;
let reach = null; let reach;
let previous = s0; let previous = s0;
input.seek(startIndex); input.seek(startIndex);
let t = input.LA(1); let t = input.LA(1);
@ -1253,7 +1253,7 @@ class ParserATNSimulator extends ATNSimulator {
// both epsilon transitions and non-epsilon transitions. // both epsilon transitions and non-epsilon transitions.
} }
for(let i = 0;i<p.transitions.length; i++) { for(let i = 0;i<p.transitions.length; i++) {
if(i==0 && this.canDropLoopEntryEdgeInLeftRecursiveRule(config)) if(i === 0 && this.canDropLoopEntryEdgeInLeftRecursiveRule(config))
continue; continue;
const t = p.transitions[i]; const t = p.transitions[i];
@ -1308,9 +1308,9 @@ class ParserATNSimulator extends ATNSimulator {
// the context has an empty stack case. If so, it would mean // the context has an empty stack case. If so, it would mean
// global FOLLOW so we can't perform optimization // global FOLLOW so we can't perform optimization
// Are we the special loop entry/exit state? or SLL wildcard // Are we the special loop entry/exit state? or SLL wildcard
if(p.stateType != ATNState.STAR_LOOP_ENTRY) if(p.stateType !== ATNState.STAR_LOOP_ENTRY)
return false; return false;
if(p.stateType != ATNState.STAR_LOOP_ENTRY || !p.isPrecedenceDecision || if(p.stateType !== ATNState.STAR_LOOP_ENTRY || !p.isPrecedenceDecision ||
config.context.isEmpty() || config.context.hasEmptyPath()) config.context.isEmpty() || config.context.hasEmptyPath())
return false; return false;
@ -1318,7 +1318,7 @@ class ParserATNSimulator extends ATNSimulator {
const numCtxs = config.context.length; const numCtxs = config.context.length;
for(let i=0; i<numCtxs; i++) { // for each stack context for(let i=0; i<numCtxs; i++) { // for each stack context
const returnState = this.atn.states[config.context.getReturnState(i)]; const returnState = this.atn.states[config.context.getReturnState(i)];
if (returnState.ruleIndex != p.ruleIndex) if (returnState.ruleIndex !== p.ruleIndex)
return false; return false;
} }
@ -1332,29 +1332,29 @@ class ParserATNSimulator extends ATNSimulator {
const returnStateNumber = config.context.getReturnState(i); const returnStateNumber = config.context.getReturnState(i);
const returnState = this.atn.states[returnStateNumber]; const returnState = this.atn.states[returnStateNumber];
// all states must have single outgoing epsilon edge // all states must have single outgoing epsilon edge
if (returnState.transitions.length != 1 || !returnState.transitions[0].isEpsilon) if (returnState.transitions.length !== 1 || !returnState.transitions[0].isEpsilon)
return false; return false;
// Look for prefix op case like 'not expr', (' type ')' expr // Look for prefix op case like 'not expr', (' type ')' expr
const returnStateTarget = returnState.transitions[0].target; const returnStateTarget = returnState.transitions[0].target;
if ( returnState.stateType == ATNState.BLOCK_END && returnStateTarget == p ) if ( returnState.stateType === ATNState.BLOCK_END && returnStateTarget === p )
continue; continue;
// Look for 'expr op expr' or case where expr's return state is block end // Look for 'expr op expr' or case where expr's return state is block end
// of (...)* internal block; the block end points to loop back // of (...)* internal block; the block end points to loop back
// which points to p but we don't need to check that // which points to p but we don't need to check that
if ( returnState == blockEndState ) if ( returnState === blockEndState )
continue; continue;
// Look for ternary expr ? expr : expr. The return state points at block end, // Look for ternary expr ? expr : expr. The return state points at block end,
// which points at loop entry state // which points at loop entry state
if ( returnStateTarget == blockEndState ) if ( returnStateTarget === blockEndState )
continue; continue;
// Look for complex prefix 'between expr and expr' case where 2nd expr's // Look for complex prefix 'between expr and expr' case where 2nd expr's
// return state points at block end state of (...)* internal block // return state points at block end state of (...)* internal block
if (returnStateTarget.stateType == ATNState.BLOCK_END && returnStateTarget.transitions.length == 1 if (returnStateTarget.stateType === ATNState.BLOCK_END && returnStateTarget.transitions.length === 1
&& returnStateTarget.transitions[0].isEpsilon && returnStateTarget.transitions[0].target == p) && returnStateTarget.transitions[0].isEpsilon && returnStateTarget.transitions[0].target === p)
continue; continue;
// anything else ain't conforming // anything else ain't conforming
@ -1401,7 +1401,7 @@ class ParserATNSimulator extends ATNSimulator {
actionTransition(config, t) { actionTransition(config, t) {
if (this.debug) { if (this.debug) {
const index = t.actionIndex==-1 ? 65535 : t.actionIndex; const index = t.actionIndex === -1 ? 65535 : t.actionIndex;
console.log("ACTION edge " + t.ruleIndex + ":" + index); console.log("ACTION edge " + t.ruleIndex + ":" + index);
} }
return new ATNConfig({state:t.target}, config); return new ATNConfig({state:t.target}, config);
@ -1659,7 +1659,7 @@ class ParserATNSimulator extends ATNSimulator {
* state was not already present * state was not already present
*/ */
addDFAState(dfa, D) { addDFAState(dfa, D) {
if (D == ATNSimulator.ERROR) { if (D === ATNSimulator.ERROR) {
return D; return D;
} }
const existing = dfa.states.get(D); const existing = dfa.states.get(D);

View File

@ -501,7 +501,7 @@ const PredictionMode = {
getConflictingAltSubsets: function(configs) { getConflictingAltSubsets: function(configs) {
const configToAlts = new Map(); const configToAlts = new Map();
configToAlts.hashFunction = function(cfg) { hashStuff(cfg.state.stateNumber, cfg.context); }; configToAlts.hashFunction = function(cfg) { hashStuff(cfg.state.stateNumber, cfg.context); };
configToAlts.equalsFunction = function(c1, c2) { return c1.state.stateNumber==c2.state.stateNumber && c1.context.equals(c2.context);} configToAlts.equalsFunction = function(c1, c2) { return c1.state.stateNumber === c2.state.stateNumber && c1.context.equals(c2.context);};
configs.items.map(function(cfg) { configs.items.map(function(cfg) {
let alts = configToAlts.get(cfg); let alts = configToAlts.get(cfg);
if (alts === null) { if (alts === null) {
@ -557,6 +557,6 @@ const PredictionMode = {
} }
return result; return result;
} }
} };
module.exports = PredictionMode; module.exports = PredictionMode;

View File

@ -111,7 +111,7 @@ class DFA {
*/ */
setPrecedenceDfa(precedenceDfa) { setPrecedenceDfa(precedenceDfa) {
if (this.precedenceDfa!==precedenceDfa) { if (this.precedenceDfa!==precedenceDfa) {
this._states = new DFAStatesSet(); this._states = new Set();
if (precedenceDfa) { if (precedenceDfa) {
const precedenceState = new DFAState(null, new ATNConfigSet()); const precedenceState = new DFAState(null, new ATNConfigSet());
precedenceState.edges = []; precedenceState.edges = [];

View File

@ -11,7 +11,8 @@
* and what kind of problem occurred. * and what kind of problem occurred.
*/ */
const {PredicateTransition} = require('./../atn/Transition') const {PredicateTransition} = require('./../atn/Transition');
const {Interval} = require('../IntervalSet').Interval;
class RecognitionException extends Error { class RecognitionException extends Error {
constructor(params) { constructor(params) {
@ -76,9 +77,9 @@ class LexerNoViableAltException extends RecognitionException {
} }
toString() { toString() {
let symbol = "" let symbol = "";
if (this.startIndex >= 0 && this.startIndex < this.input.size) { if (this.startIndex >= 0 && this.startIndex < this.input.size) {
symbol = this.input.getText((this.startIndex,this.startIndex)); symbol = this.input.getText(new Interval(this.startIndex,this.startIndex));
} }
return "LexerNoViableAltException" + symbol; return "LexerNoViableAltException" + symbol;
} }

View File

@ -4,22 +4,24 @@ if (!String.prototype.codePointAt) {
'use strict'; // needed to support `apply`/`call` with `undefined`/`null` 'use strict'; // needed to support `apply`/`call` with `undefined`/`null`
var defineProperty = (function() { var defineProperty = (function() {
// IE 8 only supports `Object.defineProperty` on DOM elements // IE 8 only supports `Object.defineProperty` on DOM elements
let result;
try { try {
var object = {}; const object = {};
var $defineProperty = Object.defineProperty; const $defineProperty = Object.defineProperty;
var result = $defineProperty(object, object, object) && $defineProperty; result = $defineProperty(object, object, object) && $defineProperty;
} catch(error) {} } catch(error) {
}
return result; return result;
}()); }());
var codePointAt = function(position) { const codePointAt = function(position) {
if (this == null) { if (this == null) {
throw TypeError(); throw TypeError();
} }
var string = String(this); const string = String(this);
var size = string.length; const size = string.length;
// `ToInteger` // `ToInteger`
var index = position ? Number(position) : 0; let index = position ? Number(position) : 0;
if (index != index) { // better `isNaN` if (index !== index) { // better `isNaN`
index = 0; index = 0;
} }
// Account for out-of-bounds indices: // Account for out-of-bounds indices:
@ -27,8 +29,8 @@ if (!String.prototype.codePointAt) {
return undefined; return undefined;
} }
// Get the first code unit // Get the first code unit
var first = string.charCodeAt(index); const first = string.charCodeAt(index);
var second; let second;
if ( // check if its the start of a surrogate pair if ( // check if its the start of a surrogate pair
first >= 0xD800 && first <= 0xDBFF && // high surrogate first >= 0xD800 && first <= 0xDBFF && // high surrogate
size > index + 1 // there is a next code unit size > index + 1 // there is a next code unit

View File

@ -1,35 +1,36 @@
/*! https://mths.be/fromcodepoint v0.2.1 by @mathias */ /*! https://mths.be/fromcodepoint v0.2.1 by @mathias */
if (!String.fromCodePoint) { if (!String.fromCodePoint) {
(function() { (function() {
var defineProperty = (function() { const defineProperty = (function() {
// IE 8 only supports `Object.defineProperty` on DOM elements // IE 8 only supports `Object.defineProperty` on DOM elements
let result;
try { try {
var object = {}; const object = {};
var $defineProperty = Object.defineProperty; const $defineProperty = Object.defineProperty;
var result = $defineProperty(object, object, object) && $defineProperty; result = $defineProperty(object, object, object) && $defineProperty;
} catch(error) {} } catch(error) {}
return result; return result;
}()); }());
var stringFromCharCode = String.fromCharCode; const stringFromCharCode = String.fromCharCode;
var floor = Math.floor; const floor = Math.floor;
var fromCodePoint = function(_) { const fromCodePoint = function(_) {
var MAX_SIZE = 0x4000; const MAX_SIZE = 0x4000;
var codeUnits = []; const codeUnits = [];
var highSurrogate; let highSurrogate;
var lowSurrogate; let lowSurrogate;
var index = -1; let index = -1;
var length = arguments.length; const length = arguments.length;
if (!length) { if (!length) {
return ''; return '';
} }
var result = ''; let result = '';
while (++index < length) { while (++index < length) {
var codePoint = Number(arguments[index]); let codePoint = Number(arguments[index]);
if ( if (
!isFinite(codePoint) || // `NaN`, `+Infinity`, or `-Infinity` !isFinite(codePoint) || // `NaN`, `+Infinity`, or `-Infinity`
codePoint < 0 || // not a valid Unicode code point codePoint < 0 || // not a valid Unicode code point
codePoint > 0x10FFFF || // not a valid Unicode code point codePoint > 0x10FFFF || // not a valid Unicode code point
floor(codePoint) != codePoint // not an integer floor(codePoint) !== codePoint // not an integer
) { ) {
throw RangeError('Invalid code point: ' + codePoint); throw RangeError('Invalid code point: ' + codePoint);
} }
@ -42,7 +43,7 @@ if (!String.fromCodePoint) {
lowSurrogate = (codePoint % 0x400) + 0xDC00; lowSurrogate = (codePoint % 0x400) + 0xDC00;
codeUnits.push(highSurrogate, lowSurrogate); codeUnits.push(highSurrogate, lowSurrogate);
} }
if (index + 1 == length || codeUnits.length > MAX_SIZE) { if (index + 1 === length || codeUnits.length > MAX_SIZE) {
result += stringFromCharCode.apply(null, codeUnits); result += stringFromCharCode.apply(null, codeUnits);
codeUnits.length = 0; codeUnits.length = 0;
} }