mirror of
https://github.com/angular/angular.git
synced 2026-09-14 13:54:52 +08:00
refactor(compiler): ensure compiler passes closure conformance checks (#62500)
This commit adjusts some code of the compiler that currently results in conformance checks failures with JSCompiler/Closure. PR Close #62500
This commit is contained in:
committed by
Jessica Janiuk
parent
2c18043240
commit
403ba91327
@@ -133,11 +133,13 @@ export class Token {
|
||||
}
|
||||
|
||||
isTemplateLiteralPart(): this is StringToken {
|
||||
return this.isString() && this.kind === StringTokenKind.TemplateLiteralPart;
|
||||
// Note: Explicit type is needed for Closure.
|
||||
return this.isString() && (this as StringToken).kind === StringTokenKind.TemplateLiteralPart;
|
||||
}
|
||||
|
||||
isTemplateLiteralEnd(): this is StringToken {
|
||||
return this.isString() && this.kind === StringTokenKind.TemplateLiteralEnd;
|
||||
// Note: Explicit type is needed for Closure.
|
||||
return this.isString() && (this as StringToken).kind === StringTokenKind.TemplateLiteralEnd;
|
||||
}
|
||||
|
||||
isTemplateLiteralInterpolationStart(): boolean {
|
||||
|
||||
@@ -1725,9 +1725,15 @@ class EscapedCharacterCursor extends PlainCharacterCursor {
|
||||
}
|
||||
}
|
||||
|
||||
export class CursorError {
|
||||
export class CursorError extends Error {
|
||||
constructor(
|
||||
public msg: string,
|
||||
public cursor: CharacterCursor,
|
||||
) {}
|
||||
) {
|
||||
super(msg);
|
||||
|
||||
// Extending `Error` does not always work when code is transpiled. See:
|
||||
// https://stackoverflow.com/questions/41102060/typescript-extending-error-class
|
||||
Object.setPrototypeOf(this, new.target.prototype);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -148,7 +148,7 @@ export enum ParseErrorLevel {
|
||||
ERROR,
|
||||
}
|
||||
|
||||
export class ParseError {
|
||||
export class ParseError extends Error {
|
||||
constructor(
|
||||
/** Location of the error. */
|
||||
readonly span: ParseSourceSpan,
|
||||
@@ -161,7 +161,14 @@ export class ParseError {
|
||||
* couldn't be parsed. Not guaranteed to be defined, but can be used to provide more context.
|
||||
*/
|
||||
readonly relatedError?: unknown,
|
||||
) {}
|
||||
) {
|
||||
super(msg);
|
||||
|
||||
// Extending `Error` ends up breaking some internal tests. This appears to be a known issue
|
||||
// when extending errors in TS and the workaround is to explicitly set the prototype.
|
||||
// https://stackoverflow.com/questions/41102060/typescript-extending-error-class
|
||||
Object.setPrototypeOf(this, new.target.prototype);
|
||||
}
|
||||
|
||||
contextualMessage(): string {
|
||||
const ctx = this.span.start.getContext(100, 3);
|
||||
@@ -170,7 +177,7 @@ export class ParseError {
|
||||
: this.msg;
|
||||
}
|
||||
|
||||
toString(): string {
|
||||
override toString(): string {
|
||||
const details = this.span.details ? `, ${this.span.details}` : '';
|
||||
return `${this.contextualMessage()}: ${this.span.start}${details}`;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user