mirror of https://github.com/zulip/zulip.git
typescript: Enable strictNullChecks.
Let’s do this right from the beginning instead of making a mess to clean up later. Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
parent
eb2809effe
commit
0e0baca41e
|
@ -85,10 +85,11 @@ run_test("clear", () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
run_test("undefined_keys", () => {
|
run_test("undefined_keys", () => {
|
||||||
blueslip.expect("error", "Tried to call a FoldDict method with an undefined key.", 2);
|
|
||||||
|
|
||||||
const d = new FoldDict();
|
const d = new FoldDict();
|
||||||
|
|
||||||
assert.equal(d.has(undefined), false);
|
assert.throws(
|
||||||
assert.strictEqual(d.get(undefined), undefined);
|
() => d.has(undefined),
|
||||||
|
TypeError,
|
||||||
|
"Tried to call a FoldDict method with an undefined key.",
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
|
@ -17,16 +17,19 @@ type NumberedLine = {
|
||||||
};
|
};
|
||||||
|
|
||||||
type CleanStackFrame = {
|
type CleanStackFrame = {
|
||||||
full_path: string;
|
full_path?: string;
|
||||||
show_path: string;
|
show_path?: string;
|
||||||
function_name: FunctionName;
|
function_name?: FunctionName;
|
||||||
line_number: number;
|
line_number?: number;
|
||||||
context: NumberedLine[] | undefined;
|
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.
|
// If the file is local, just show the filename.
|
||||||
// Otherwise, show the full path starting from node_modules.
|
// Otherwise, show the full path starting from node_modules.
|
||||||
|
if (full_path === undefined) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
const idx = full_path.indexOf("/node_modules/");
|
const idx = full_path.indexOf("/node_modules/");
|
||||||
if (idx !== -1) {
|
if (idx !== -1) {
|
||||||
return full_path.slice(idx + "/node_modules/".length);
|
return full_path.slice(idx + "/node_modules/".length);
|
||||||
|
@ -55,18 +58,21 @@ const sourceCache: {[source: string]: string | Promise<string>} = {};
|
||||||
const stack_trace_gps = new StackTraceGPS({sourceCache});
|
const stack_trace_gps = new StackTraceGPS({sourceCache});
|
||||||
|
|
||||||
async function get_context(location: StackFrame): Promise<NumberedLine[] | undefined> {
|
async function get_context(location: StackFrame): Promise<NumberedLine[] | undefined> {
|
||||||
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) {
|
if (sourceContent === undefined) {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
const lines = sourceContent.split("\n");
|
const lines = sourceContent.split("\n");
|
||||||
const line_number = location.getLineNumber();
|
const lo_line_num = Math.max(lineNumber - 5, 0);
|
||||||
const lo_line_num = Math.max(line_number - 5, 0);
|
const hi_line_num = Math.min(lineNumber + 4, lines.length);
|
||||||
const hi_line_num = Math.min(line_number + 4, lines.length);
|
|
||||||
return lines.slice(lo_line_num, hi_line_num).map((line: string, i: number) => ({
|
return lines.slice(lo_line_num, hi_line_num).map((line: string, i: number) => ({
|
||||||
line_number: lo_line_num + i + 1,
|
line_number: lo_line_num + i + 1,
|
||||||
line,
|
line,
|
||||||
focus: lo_line_num + i + 1 === line_number,
|
focus: lo_line_num + i + 1 === lineNumber,
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -65,10 +65,9 @@ export class FoldDict<V> {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle case-folding of keys and the empty string.
|
// Handle case-folding of keys and the empty string.
|
||||||
private _munge(key: string): string | undefined {
|
private _munge(key: string): string {
|
||||||
if (key === undefined) {
|
if (key === undefined) {
|
||||||
blueslip.error("Tried to call a FoldDict method with an undefined key.");
|
throw new TypeError("Tried to call a FoldDict method with an undefined key.");
|
||||||
return undefined;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return key.toString().toLowerCase();
|
return key.toString().toLowerCase();
|
||||||
|
|
|
@ -248,7 +248,7 @@ export default (env?: string): webpack.Configuration[] => {
|
||||||
{path: "jquery/dist/jquery.js", name: ["$", "jQuery"]},
|
{path: "jquery/dist/jquery.js", name: ["$", "jQuery"]},
|
||||||
{path: "handlebars/dist/cjs/handlebars.runtime.js", name: "Handlebars"},
|
{path: "handlebars/dist/cjs/handlebars.runtime.js", name: "Handlebars"},
|
||||||
];
|
];
|
||||||
config.module.rules.unshift(...getExposeLoaders(exposeOptions));
|
config.module!.rules.unshift(...getExposeLoaders(exposeOptions));
|
||||||
|
|
||||||
if (!production) {
|
if (!production) {
|
||||||
// Out JS debugging tools
|
// Out JS debugging tools
|
||||||
|
|
|
@ -23,7 +23,6 @@
|
||||||
|
|
||||||
/* Strict type-checking */
|
/* Strict type-checking */
|
||||||
"strict": true,
|
"strict": true,
|
||||||
"strictNullChecks": false,
|
|
||||||
"forceConsistentCasingInFileNames": true,
|
"forceConsistentCasingInFileNames": true,
|
||||||
"isolatedModules": true,
|
"isolatedModules": true,
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue