Skip to content

Commit

Permalink
Enable 'strict' compilation
Browse files Browse the repository at this point in the history
Remaining problems are suppressed using definite assignment assertions.

See tunnelvisionlabs#495
  • Loading branch information
sharwell committed Jan 1, 2021
1 parent fc351cb commit dace7c3
Show file tree
Hide file tree
Showing 15 changed files with 26 additions and 27 deletions.
8 changes: 4 additions & 4 deletions benchmark/TestPerformance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1516,8 +1516,8 @@ export class FileParseResult {
}

class StatisticsLexerATNSimulator extends LexerATNSimulator {
public totalTransitions: number;
public computedTransitions: number;
public totalTransitions!: number;
public computedTransitions!: number;

constructor(atn: ATN);
constructor(atn: ATN, recog: Lexer);
Expand Down Expand Up @@ -1551,7 +1551,7 @@ class StatisticsParserATNSimulator extends ParserATNSimulator {
public computedTransitions: Uint32Array;
public fullContextTransitions: Uint32Array;

private decision: number;
private decision!: number;

constructor(atn: ATN, parser: Parser) {
super(atn, parser);
Expand Down Expand Up @@ -1651,7 +1651,7 @@ class DescriptiveLexerErrorListener implements ANTLRErrorListener<number> {

class SummarizingDiagnosticErrorListener extends DiagnosticErrorListener {
private _sllConflict: BitSet | undefined;
private _sllConfigs: ATNConfigSet;
private _sllConfigs!: ATNConfigSet;

@Override
public reportAmbiguity(recognizer: Parser, dfa: DFA, startIndex: number, stopIndex: number, exact: boolean, ambigAlts: BitSet | undefined, configs: ATNConfigSet): void {
Expand Down
4 changes: 2 additions & 2 deletions src/Parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export abstract class Parser extends Recognizer<Token, ParserATNSimulator> {
* @see #getInputStream
* @see #setInputStream
*/
protected _input: TokenStream;
protected _input!: TokenStream;

protected readonly _precedenceStack: IntegerStack = new IntegerStack();

Expand All @@ -104,7 +104,7 @@ export abstract class Parser extends Recognizer<Token, ParserATNSimulator> {
*
* This is always non-undefined during the parsing process.
*/
protected _ctx: ParserRuleContext;
protected _ctx!: ParserRuleContext;

/**
* Specifies whether or not the parser should construct a parse tree during
Expand Down
2 changes: 1 addition & 1 deletion src/ParserInterpreter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export class ParserInterpreter extends Parser {
*/
protected _overrideDecisionRoot?: InterpreterRuleContext = undefined;

protected _rootContext: InterpreterRuleContext;
protected _rootContext!: InterpreterRuleContext;

/** A copy constructor that creates a new parser interpreter by reusing
* the fields of a previous interpreter.
Expand Down
2 changes: 1 addition & 1 deletion src/ParserRuleContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export class ParserRuleContext extends RuleContext {
*/
// public Array<number> states;

public _start: Token;
public _start!: Token;
public _stop: Token | undefined;

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Recognizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export abstract class Recognizer<TSymbol, ATNInterpreter extends ATNSimulator> {
@NotNull
private readonly _listeners: Array<ANTLRErrorListener<TSymbol>> = [ConsoleErrorListener.INSTANCE];

protected _interp: ATNInterpreter;
protected _interp!: ATNInterpreter;

private _stateNumber = -1;

Expand Down
2 changes: 1 addition & 1 deletion src/TokenStreamRewriter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,7 @@ export class TokenStreamRewriter {
export class RewriteOperation {
protected tokens: TokenStream;
/** What index into rewrites List are we? */
public instructionIndex: number;
public instructionIndex!: number;
/** Token buffer index. */
public index: number;
public text: {};
Expand Down
8 changes: 4 additions & 4 deletions src/atn/ATN.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ export class ATN {
/**
* Maps from rule index to starting state number.
*/
public ruleToStartState: RuleStartState[];
public ruleToStartState!: RuleStartState[];

/**
* Maps from rule index to stop state number.
*/
public ruleToStopState: RuleStopState[];
public ruleToStopState!: RuleStopState[];

@NotNull
public modeNameToStartState: Map<string, TokensStartState> =
Expand All @@ -69,13 +69,13 @@ export class ATN {
* {@link ATNDeserializationOptions#isGenerateRuleBypassTransitions}
* deserialization option was specified; otherwise, this is `undefined`.
*/
public ruleToTokenType: Int32Array;
public ruleToTokenType!: Int32Array;

/**
* For lexer ATNs, this is an array of {@link LexerAction} objects which may
* be referenced by action transitions in the ATN.
*/
public lexerActions: LexerAction[];
public lexerActions!: LexerAction[];

@NotNull
public modeToStartState: TokensStartState[] = [];
Expand Down
2 changes: 1 addition & 1 deletion src/atn/BlockEndState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { Override } from "../Decorators";

/** Terminal node of a simple `(a|b|c)` block. */
export class BlockEndState extends ATNState {
public startState: BlockStartState;
public startState!: BlockStartState;

@Override
get stateType(): ATNStateType {
Expand Down
2 changes: 1 addition & 1 deletion src/atn/BlockStartState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ import { Override } from "../Decorators";

/** The start of a regular `(...)` block. */
export abstract class BlockStartState extends DecisionState {
public endState: BlockEndState;
public endState!: BlockEndState;
}
2 changes: 1 addition & 1 deletion src/atn/LoopEndState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { Override } from "../Decorators";

/** Mark the end of a * or + loop. */
export class LoopEndState extends ATNState {
public loopBackState: ATNState;
public loopBackState!: ATNState;

@Override
get stateType(): ATNStateType {
Expand Down
2 changes: 1 addition & 1 deletion src/atn/PlusBlockStartState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { PlusLoopbackState } from "./PlusLoopbackState";
* real decision-making note for `A+`.
*/
export class PlusBlockStartState extends BlockStartState {
public loopBackState: PlusLoopbackState;
public loopBackState!: PlusLoopbackState;

@Override
get stateType(): ATNStateType {
Expand Down
2 changes: 1 addition & 1 deletion src/atn/RuleStartState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { Override } from "../Decorators";
import { RuleStopState } from "./RuleStopState";

export class RuleStartState extends ATNState {
public stopState: RuleStopState;
public stopState!: RuleStopState;
public isPrecedenceRule: boolean = false;
public leftFactored: boolean = false;

Expand Down
2 changes: 1 addition & 1 deletion src/atn/StarLoopEntryState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { Override } from "../Decorators";
import { StarLoopbackState } from "./StarLoopbackState";

export class StarLoopEntryState extends DecisionState {
public loopBackState: StarLoopbackState;
public loopBackState!: StarLoopbackState;

/**
* Indicates whether this state can benefit from a precedence DFA during SLL
Expand Down
10 changes: 5 additions & 5 deletions src/misc/InterpreterDataReader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,10 +181,10 @@ export namespace InterpreterDataReader {
}

export class InterpreterData {
public atn: ATN;
public vocabulary: Vocabulary;
public ruleNames: string[];
public channels: string[]; // Only valid for lexer grammars.
public modes: string[]; // ditto
public atn!: ATN;
public vocabulary!: Vocabulary;
public ruleNames!: string[];
public channels!: string[]; // Only valid for lexer grammars.
public modes!: string[]; // ditto
}
}
3 changes: 1 addition & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
"es6"
],
"noImplicitAny": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"strict": true,
"experimentalDecorators": true,
"declaration": true,
"preserveConstEnums": true,
Expand Down

0 comments on commit dace7c3

Please sign in to comment.