diff --git a/frontend_tests/node_tests/fold_dict.js b/frontend_tests/node_tests/fold_dict.js index dfcef4ab78..7be296a120 100644 --- a/frontend_tests/node_tests/fold_dict.js +++ b/frontend_tests/node_tests/fold_dict.js @@ -85,10 +85,11 @@ run_test("clear", () => { }); run_test("undefined_keys", () => { - blueslip.expect("error", "Tried to call a FoldDict method with an undefined key.", 2); - const d = new FoldDict(); - assert.equal(d.has(undefined), false); - assert.strictEqual(d.get(undefined), undefined); + assert.throws( + () => d.has(undefined), + TypeError, + "Tried to call a FoldDict method with an undefined key.", + ); }); diff --git a/static/js/blueslip_stacktrace.ts b/static/js/blueslip_stacktrace.ts index e97d353af8..f126abfe76 100644 --- a/static/js/blueslip_stacktrace.ts +++ b/static/js/blueslip_stacktrace.ts @@ -17,16 +17,19 @@ type NumberedLine = { }; type CleanStackFrame = { - full_path: string; - show_path: string; - function_name: FunctionName; - line_number: number; - context: NumberedLine[] | undefined; + full_path?: string; + show_path?: string; + function_name?: FunctionName; + line_number?: number; + context?: NumberedLine[]; }; -export function clean_path(full_path: string): string { +export function clean_path(full_path?: string): string | undefined { // If the file is local, just show the filename. // Otherwise, show the full path starting from node_modules. + if (full_path === undefined) { + return undefined; + } const idx = full_path.indexOf("/node_modules/"); if (idx !== -1) { return full_path.slice(idx + "/node_modules/".length); @@ -55,18 +58,21 @@ const sourceCache: {[source: string]: string | Promise} = {}; const stack_trace_gps = new StackTraceGPS({sourceCache}); async function get_context(location: StackFrame): Promise { - const sourceContent = await sourceCache[location.getFileName()]; + const {fileName, lineNumber} = location; + if (fileName === undefined || lineNumber === undefined) { + return undefined; + } + const sourceContent = await sourceCache[fileName]; if (sourceContent === undefined) { return undefined; } const lines = sourceContent.split("\n"); - const line_number = location.getLineNumber(); - const lo_line_num = Math.max(line_number - 5, 0); - const hi_line_num = Math.min(line_number + 4, lines.length); + const lo_line_num = Math.max(lineNumber - 5, 0); + const hi_line_num = Math.min(lineNumber + 4, lines.length); return lines.slice(lo_line_num, hi_line_num).map((line: string, i: number) => ({ line_number: lo_line_num + i + 1, line, - focus: lo_line_num + i + 1 === line_number, + focus: lo_line_num + i + 1 === lineNumber, })); } diff --git a/static/js/fold_dict.ts b/static/js/fold_dict.ts index 9fec7fdb52..d7ce31aae6 100644 --- a/static/js/fold_dict.ts +++ b/static/js/fold_dict.ts @@ -65,10 +65,9 @@ export class FoldDict { } // Handle case-folding of keys and the empty string. - private _munge(key: string): string | undefined { + private _munge(key: string): string { if (key === undefined) { - blueslip.error("Tried to call a FoldDict method with an undefined key."); - return undefined; + throw new TypeError("Tried to call a FoldDict method with an undefined key."); } return key.toString().toLowerCase(); diff --git a/tools/webpack.config.ts b/tools/webpack.config.ts index 221af40e3c..44d6f42191 100644 --- a/tools/webpack.config.ts +++ b/tools/webpack.config.ts @@ -248,7 +248,7 @@ export default (env?: string): webpack.Configuration[] => { {path: "jquery/dist/jquery.js", name: ["$", "jQuery"]}, {path: "handlebars/dist/cjs/handlebars.runtime.js", name: "Handlebars"}, ]; - config.module.rules.unshift(...getExposeLoaders(exposeOptions)); + config.module!.rules.unshift(...getExposeLoaders(exposeOptions)); if (!production) { // Out JS debugging tools diff --git a/tsconfig.json b/tsconfig.json index 4bbb0c14a0..3f8db10557 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -23,7 +23,6 @@ /* Strict type-checking */ "strict": true, - "strictNullChecks": false, "forceConsistentCasingInFileNames": true, "isolatedModules": true,