Everywhere: Remove source location prefix from assertions

When an assertion gets called the stacktrace provides enough
source information anyways
This commit is contained in:
networkException 2021-10-24 23:11:34 +02:00
parent 5afae11193
commit be84284020
2 changed files with 13 additions and 17 deletions

View file

@ -29,7 +29,7 @@ export class Highlighter {
case Type.DOCTYPE: this.reconsumeIn(State.DOCTYPE); break; case Type.DOCTYPE: this.reconsumeIn(State.DOCTYPE); break;
case Type.Comment: this.reconsumeIn(State.Comment); break; case Type.Comment: this.reconsumeIn(State.Comment); break;
case Type.EndOfFile: this.finished = true; break; case Type.EndOfFile: this.finished = true; break;
default: TODO(`Highlighter#spin, Unimplemented token type '${this.currentToken.type}'`); default: TODO(`Unimplemented token type '${this.currentToken.type}'`);
} }
break; break;
@ -160,7 +160,7 @@ export class Highlighter {
this.state = State.Undefined; this.state = State.Undefined;
break; break;
default: TODO(`Highlighter#iterate, Unimplemented state '${this.state}'`); default: TODO(`Unimplemented state '${this.state}'`);
} }
} }
@ -179,7 +179,7 @@ export class Highlighter {
private consumeNextTokenOfType<T extends Type>(type: T): Token & { type: T } { private consumeNextTokenOfType<T extends Type>(type: T): Token & { type: T } {
this.currentToken = this.tokens[this.pointer]; this.currentToken = this.tokens[this.pointer];
VERIFY(this.currentToken.type === type, `Highlighter#consumeNextOfType: Expected '${type}', got '${this.currentToken.type}' instead`); VERIFY(this.currentToken.type === type, `Expected '${type}', got '${this.currentToken.type}' instead`);
this.pointer++; this.pointer++;
@ -189,8 +189,7 @@ export class Highlighter {
private consumeNextTokenOfEitherType<T extends Type, U extends Type>(a: T, b: U): Token & { type: T | U } { private consumeNextTokenOfEitherType<T extends Type, U extends Type>(a: T, b: U): Token & { type: T | U } {
this.currentToken = this.tokens[this.pointer]; this.currentToken = this.tokens[this.pointer];
VERIFY(this.currentToken.type === a || this.currentToken.type === b, VERIFY(this.currentToken.type === a || this.currentToken.type === b, `Expected '${a}' or '${b}', got '${this.currentToken.type}' instead`);
`Highlighter#consumeNextTokenOfEitherType: Expected '${a}' or '${b}', got '${this.currentToken.type}' instead`);
this.pointer++; this.pointer++;
@ -212,14 +211,13 @@ export class Highlighter {
} }
private currentTokenOfType<T extends Type>(type: T): Token & { type: T } { private currentTokenOfType<T extends Type>(type: T): Token & { type: T } {
VERIFY(this.currentToken.type === type, `Highlighter#currentTokenOfType: Expected '${type}', got '${this.currentToken.type}' instead`); VERIFY(this.currentToken.type === type, `Expected '${type}', got '${this.currentToken.type}' instead`);
return this.currentToken as Token & { type: T }; return this.currentToken as Token & { type: T };
} }
private currentTokenOfEitherType<T extends Type, U extends Type>(a: T, b: U): Token & { type: T | U } { private currentTokenOfEitherType<T extends Type, U extends Type>(a: T, b: U): Token & { type: T | U } {
VERIFY(this.currentToken.type === a || this.currentToken.type === b, VERIFY(this.currentToken.type === a || this.currentToken.type === b, `Expected '${a}' or '${b}', got '${this.currentToken.type}' instead`);
`Highlighter#currentTokenOfEitherType: Expected '${a}' or '${b}', got '${this.currentToken.type}' instead`);
return this.currentToken as Token & { type: T }; return this.currentToken as Token & { type: T };
} }

View file

@ -510,7 +510,7 @@ export class Tokenizer {
break; break;
} }
default: TODO(`Tokenizer#iterate, Unimplemented state '${this.state}'`); default: TODO(`Unimplemented state '${this.state}'`);
} }
} }
@ -581,7 +581,7 @@ export class Tokenizer {
for (let i = 0; i < input.length; i++) { for (let i = 0; i < input.length; i++) {
const consumed = this.consumeNext(); const consumed = this.consumeNext();
VERIFY(consumed === input[i], `Tokenizer#consumeNextFew: Expected '${input[i]}' (${input} at ${i}), got ${consumed} instead`); VERIFY(consumed === input[i], `Expected '${input[i]}' (${input} at ${i}), got ${consumed} instead`);
} }
} }
@ -589,8 +589,7 @@ export class Tokenizer {
for (let i = 0; i < input.length; i++) { for (let i = 0; i < input.length; i++) {
const consumed = this.consumeNext()?.toLowerCase(); const consumed = this.consumeNext()?.toLowerCase();
VERIFY(consumed === input[i].toLowerCase(), VERIFY(consumed === input[i].toLowerCase(), `Expected '${input[i].toLowerCase()}' (${input.toLowerCase()} at ${i}), got ${consumed} instead`);
`Tokenizer#consumeNextFewCaseInsensitive: Expected '${input[i].toLowerCase()}' (${input.toLowerCase()} at ${i}), got ${consumed} instead`);
} }
} }
@ -599,26 +598,25 @@ export class Tokenizer {
} }
private emitCurrentOfType(type: Type): void { private emitCurrentOfType(type: Type): void {
VERIFY(this.currentToken.type === type, `Tokenizer#emitCurrentOfType: Expected '${type}', got '${this.currentToken.type}' instead`); VERIFY(this.currentToken.type === type, `Expected '${type}', got '${this.currentToken.type}' instead`);
this.tokens.push(this.currentToken); this.tokens.push(this.currentToken);
} }
private emitCurrentOfEitherType(a: Type, b: Type): void { private emitCurrentOfEitherType(a: Type, b: Type): void {
VERIFY(this.currentToken.type === a || this.currentToken.type === b, `Tokenizer#emitCurrentOfEitherType: Expected '${a}' or '${b}', got '${this.currentToken.type}' instead`); VERIFY(this.currentToken.type === a || this.currentToken.type === b, `Expected '${a}' or '${b}', got '${this.currentToken.type}' instead`);
this.tokens.push(this.currentToken); this.tokens.push(this.currentToken);
} }
private currentOfType<T extends Type>(type: T): Token & { type: T } { private currentOfType<T extends Type>(type: T): Token & { type: T } {
VERIFY(this.currentToken.type === type, `Tokenizer#currentOfType: Expected '${type}', got '${this.currentToken.type}' instead`); VERIFY(this.currentToken.type === type, `Expected '${type}', got '${this.currentToken.type}' instead`);
return this.currentToken as Token & { type: T }; return this.currentToken as Token & { type: T };
} }
private currentOfEitherType<T extends Type, U extends Type>(a: T, b: U): Token & { type: T | U } { private currentOfEitherType<T extends Type, U extends Type>(a: T, b: U): Token & { type: T | U } {
VERIFY(this.currentToken.type === a || this.currentToken.type === b, VERIFY(this.currentToken.type === a || this.currentToken.type === b, `Expected '${a}' or '${b}', got '${this.currentToken.type}' instead`);
`Tokenizer#currentOfEitherType: Expected '${a}' or '${b}', got '${this.currentToken.type}' instead`);
return this.currentToken as Token & { type: T }; return this.currentToken as Token & { type: T };
} }