Use ! instead of throws
MODIFY
packages/@romejs/cli-flags/Parser.ts
packages/@romejs/cli-flags/Parser.ts
@@ -640,10 +640,7 @@ export default class Parser<T> {
}
for (const category of sortedCategoryNames) {
- const commands = commandsByCategory.get(category);
- if (commands === undefined) {
- throw new Error('Impossible. Should always be populated.');
- }
+ const commands = commandsByCategory.get(category)!;
if (category !== undefined) {
reporter.logAll(`<emphasis>${category} Commands</emphasis>`);

MODIFY
packages/@romejs/codec-js-regexp/index.ts
packages/@romejs/codec-js-regexp/index.ts
@@ -1126,10 +1126,7 @@ export const createRegExpParser = createParser((ParserCore) =>
let expression: undefined | RegExpSubExpression | RegExpAlternation;
while (alternations.length > 0) {
- const alternation = alternations.shift();
- if (alternation === undefined) {
- throw new Error('Impossible. We check it above.');
- }
+ const alternation = alternations.shift()!;
const sub: RegExpSubExpression = {
type: 'RegExpSubExpression',

MODIFY
packages/@romejs/core/master/bundler/Bundler.ts
packages/@romejs/core/master/bundler/Bundler.ts
@@ -170,10 +170,7 @@ export default class Bundler {
// Could maybe do some of this in parallel?
while (entries.length > 0) {
- const entry = entries.shift();
- if (entry === undefined) {
- throw new Error('Impossible. We just checked.');
- }
+ const entry = entries.shift()!;
const promise = (async () => {
const text = markup`<filelink target="${entry.join()}" />`;

MODIFY
packages/@romejs/core/master/fs/MemoryFileSystem.ts
packages/@romejs/core/master/fs/MemoryFileSystem.ts
@@ -976,10 +976,7 @@ export default class MemoryFileSystem {
const ignoresByProject: Map<ProjectDefinition, PathPatterns> = new Map();
while (crawl.length > 0) {
- const path = crawl.pop();
- if (path === undefined) {
- throw new Error('crawl.length already validated');
- }
+ const path = crawl.pop()!;
const project = this.master.projectManager.assertProjectExisting(path);

MODIFY
packages/@romejs/core/master/testing/utils.ts
packages/@romejs/core/master/testing/utils.ts
@@ -46,10 +46,7 @@ export function percentInsideCoverageFolder(
const folders = [folder];
while (folders.length > 0) {
- const folder = folders.shift();
- if (folder === undefined) {
- throw new Error('folders.length has already been validated');
- }
+ const folder = folders.shift()!;
for (const file of folder.files.values()) {
totalFiles++;

MODIFY
packages/@romejs/core/test-worker/SnapshotManager.ts
packages/@romejs/core/test-worker/SnapshotManager.ts
@@ -110,10 +110,7 @@ export default class SnapshotManager {
this.snapshots.set(path, snapshot);
while (nodes.length > 0) {
- const node = nodes.shift();
- if (node === undefined) {
- throw new Error('Impossible');
- }
+ const node = nodes.shift()!;
if (node.type === 'Heading' && node.level === 1) {
// Title
@@ -208,10 +205,7 @@ export default class SnapshotManager {
const testNames = Array.from(testNameToEntries.keys()).sort();
for (const testName of testNames) {
- const entries = testNameToEntries.get(testName);
- if (entries === undefined) {
- throw new Error('Impossible');
- }
+ const entries = testNameToEntries.get(testName)!;
lines.push(`## \`${testName}\``);
pushNewline();
@@ -219,10 +213,7 @@ export default class SnapshotManager {
const entryNames = Array.from(entries.keys()).sort();
for (const snapshotName of entryNames) {
- const entry = entries.get(snapshotName);
- if (entry === undefined) {
- throw new Error('Impossible');
- }
+ const entry = entries.get(snapshotName)!;
const {value} = entry;
const language = entry.language === undefined ? '' : entry.language;

MODIFY
packages/@romejs/js-compiler/transforms/compile/jsx.ts
packages/@romejs/js-compiler/transforms/compile/jsx.ts
@@ -158,10 +158,7 @@ function buildOpeningElementAttributes(attribs: JSXElement['attributes']) {
const objs: Array<AnyExpression> = [];
while (attribs.length > 0) {
- const prop = attribs.shift();
- if (prop === undefined) {
- throw new Error('Already validated length');
- }
+ const prop = attribs.shift()!;
if (prop.type === 'JSXSpreadAttribute') {
_props = pushProps(_props, objs);

MODIFY
packages/@romejs/js-parser/tokenizer/index.ts
packages/@romejs/js-parser/tokenizer/index.ts
@@ -1564,11 +1564,7 @@ function readEscapedChar(
const codePos = ob1Dec(parser.state.index);
const octalMatches = parser.input.substr(getIndex(parser) - 1, 3).match(
/^[0-7]+/,
- );
-
- if (octalMatches == null) {
- throw new Error('No octals found, impossible since we checked it');
- }
+ )!;
let octalStr = octalMatches[0];
let octal = parseInt(octalStr, 8);

MODIFY
packages/@romejs/path/collections.ts
packages/@romejs/path/collections.ts
@@ -35,11 +35,7 @@ class FilePathMap<FilePath extends UnknownFilePath, Value> {
*[Symbol.iterator](): Iterator<[FilePath, Value]> {
for (const [joined, value] of this.joinedToValue) {
- const path = this.joinedToPath.get(joined);
- if (path === undefined) {
- throw new Error('Impossible');
- }
-
+ const path = this.joinedToPath.get(joined)!;
yield [path, value];
}
}

Use ! instead of throws