Skip to content

Commit e620e30

Browse files
author
luomingtao
committed
fix: custom Exception extends Error
1 parent 1d9c5cc commit e620e30

File tree

7 files changed

+377
-368
lines changed

7 files changed

+377
-368
lines changed

src/FailedPredicateException.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ export class FailedPredicateException extends RecognitionException {
3232
recognizer.inputStream,
3333
recognizer.context,
3434
FailedPredicateException.formatMessage(predicate, message));
35+
Object.setPrototypeOf(this, FailedPredicateException.prototype);
36+
3537
let s: ATNState = recognizer.interpreter.atn.states[recognizer.state];
3638

3739
let trans = s.transition(0) as AbstractPredicateTransition;

src/InputMismatchException.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export class InputMismatchException extends RecognitionException {
2424
}
2525

2626
super(recognizer, recognizer.inputStream, context);
27+
Object.setPrototypeOf(this, InputMismatchException.prototype);
2728

2829
if (state !== undefined) {
2930
this.setOffendingState(state);

src/LexerNoViableAltException.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ export class LexerNoViableAltException extends RecognitionException {
2828
startIndex: number,
2929
deadEndConfigs: ATNConfigSet | undefined) {
3030
super(lexer, input);
31+
Object.setPrototypeOf(this, LexerNoViableAltException.prototype);
32+
3133
this._startIndex = startIndex;
3234
this._deadEndConfigs = deadEndConfigs;
3335
}

src/NoViableAltException.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ export class NoViableAltException extends RecognitionException {
7474
}
7575

7676
super(recognizer, input, ctx);
77+
Object.setPrototypeOf(this, NoViableAltException.prototype);
78+
7779
this._deadEndConfigs = deadEndConfigs;
7880
this._startToken = startToken as Token;
7981
this.setOffendingToken(recognizer, offendingToken);

src/RecognitionException.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ export class RecognitionException extends Error {
6868
if (recognizer) {
6969
this._offendingState = recognizer.state;
7070
}
71+
// see https://github.com/Microsoft/TypeScript-wiki/blob/master/Breaking-Changes.md#extending-built-ins-like-error-array-and-map-may-no-longer-work
72+
Object.setPrototypeOf(this, RecognitionException.prototype);
7173
}
7274

7375
/**

src/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@
22
* Copyright 2016 The ANTLR Project. All rights reserved.
33
* Licensed under the BSD-3-Clause license. See LICENSE file in the project root for license information.
44
*/
5+
56
export * from "./ParserInterpreter";
67
export * from "./Parser";
8+
79
export * from "./ANTLRErrorListener";
810
export * from "./ANTLRErrorStrategy";
9-
// export * from "./ANTLRFileStream";
1011
export * from "./ANTLRInputStream";
12+
export * from "./BailErrorStrategy";
1113
export * from "./BufferedTokenStream";
1214
export * from "./CharStream";
1315
export * from "./CharStreams";
@@ -17,6 +19,7 @@ export * from "./CommonToken";
1719
export * from "./CommonTokenFactory";
1820
export * from "./CommonTokenStream";
1921
export * from "./ConsoleErrorListener";
22+
export * from "./Decorators";
2023
export * from "./DefaultErrorStrategy";
2124
export * from "./Dependents";
2225
export * from "./DiagnosticErrorListener";
@@ -44,12 +47,9 @@ export * from "./TokenFactory";
4447
export * from "./TokenSource";
4548
export * from "./TokenStream";
4649
export * from "./TokenStreamRewriter";
47-
// export * from "./UnbufferedCharStream";
48-
// export * from "./UnbufferedTokenStream";
4950
export * from "./Vocabulary";
5051
export * from "./VocabularyImpl";
5152
export * from "./WritableToken";
52-
export * from "./BailErrorStrategy";
5353

5454
export * from "./atn";
5555
export * from "./dfa";

0 commit comments

Comments
 (0)