summaryrefslogtreecommitdiff
path: root/std
diff options
context:
space:
mode:
Diffstat (limited to 'std')
-rw-r--r--std/encoding/base32_test.ts2
-rw-r--r--std/encoding/csv.ts10
-rw-r--r--std/encoding/csv_test.ts34
-rw-r--r--std/encoding/yaml/loader/loader.ts6
-rwxr-xr-xstd/examples/gist.ts2
-rw-r--r--std/fs/copy.ts2
-rw-r--r--std/fs/empty_dir_test.ts3
-rw-r--r--std/fs/exists_test.ts2
-rw-r--r--std/fs/walk.ts16
-rw-r--r--std/http/cookie.ts2
-rwxr-xr-xstd/http/file_server.ts20
-rw-r--r--std/http/file_server_test.ts2
-rw-r--r--std/http/server.ts2
-rw-r--r--std/http/server_test.ts5
-rw-r--r--std/io/bufio.ts2
-rw-r--r--std/manual.md2
-rw-r--r--std/node/events.ts33
-rw-r--r--std/node/events_test.ts19
-rw-r--r--std/node/global.ts3
-rw-r--r--std/node/module.ts43
-rw-r--r--std/node/os.ts4
-rw-r--r--std/path/utils.ts6
-rw-r--r--std/path/win32.ts2
-rw-r--r--std/textproto/mod.ts4
-rw-r--r--std/util/deep_assign.ts3
25 files changed, 135 insertions, 94 deletions
diff --git a/std/encoding/base32_test.ts b/std/encoding/base32_test.ts
index eb51e44ab..28550d57a 100644
--- a/std/encoding/base32_test.ts
+++ b/std/encoding/base32_test.ts
@@ -6,7 +6,7 @@ import { encode, decode } from "./base32.ts";
// Lifted from https://stackoverflow.com/questions/38987784
const fromHexString = (hexString: string): Uint8Array =>
- new Uint8Array(hexString.match(/.{1,2}/g).map(byte => parseInt(byte, 16)));
+ new Uint8Array(hexString.match(/.{1,2}/g)!.map(byte => parseInt(byte, 16)));
const toHexString = (bytes: Uint8Array): string =>
bytes.reduce((str, byte) => str + byte.toString(16).padStart(2, "0"), "");
diff --git a/std/encoding/csv.ts b/std/encoding/csv.ts
index 1314afcaa..12336b10d 100644
--- a/std/encoding/csv.ts
+++ b/std/encoding/csv.ts
@@ -46,7 +46,7 @@ function chkOptions(opt: ReadOptions): void {
}
if (
INVALID_RUNE.includes(opt.comma) ||
- INVALID_RUNE.includes(opt.comment) ||
+ (typeof opt.comment === "string" && INVALID_RUNE.includes(opt.comment)) ||
opt.comma === opt.comment
) {
throw new Error("Invalid Delimiter");
@@ -122,7 +122,7 @@ export async function readMatrix(
}
): Promise<string[][]> {
const result: string[][] = [];
- let _nbFields: number;
+ let _nbFields: number | undefined;
let lineResult: string[];
let first = true;
let lineIndex = 0;
@@ -253,8 +253,10 @@ export async function parse(
});
}
if (opt.parse) {
- assert(opt.parse != null, "opt.parse must be set");
- return r.map((e: string[]): unknown => opt.parse(e));
+ return r.map((e: string[]): unknown => {
+ assert(opt.parse, "opt.parse must be set");
+ return opt.parse(e);
+ });
}
return r;
}
diff --git a/std/encoding/csv_test.ts b/std/encoding/csv_test.ts
index 74ba8face..efea353e1 100644
--- a/std/encoding/csv_test.ts
+++ b/std/encoding/csv_test.ts
@@ -476,26 +476,32 @@ for (const t of testCases) {
if (t.Error) {
let err;
try {
- actual = await readMatrix(new BufReader(new StringReader(t.Input)), {
- comma: comma,
- comment: comment,
- trimLeadingSpace: trim,
- fieldsPerRecord: fieldsPerRec,
- lazyQuotes: lazyquote
- });
+ actual = await readMatrix(
+ new BufReader(new StringReader(t.Input ?? "")),
+ {
+ comma: comma,
+ comment: comment,
+ trimLeadingSpace: trim,
+ fieldsPerRecord: fieldsPerRec,
+ lazyQuotes: lazyquote
+ }
+ );
} catch (e) {
err = e;
}
assert(err);
assertEquals(err.message, t.Error);
} else {
- actual = await readMatrix(new BufReader(new StringReader(t.Input)), {
- comma: comma,
- comment: comment,
- trimLeadingSpace: trim,
- fieldsPerRecord: fieldsPerRec,
- lazyQuotes: lazyquote
- });
+ actual = await readMatrix(
+ new BufReader(new StringReader(t.Input ?? "")),
+ {
+ comma: comma,
+ comment: comment,
+ trimLeadingSpace: trim,
+ fieldsPerRecord: fieldsPerRec,
+ lazyQuotes: lazyquote
+ }
+ );
const expected = t.Output;
assertEquals(actual, expected);
}
diff --git a/std/encoding/yaml/loader/loader.ts b/std/encoding/yaml/loader/loader.ts
index 556bd5b47..7db72a01d 100644
--- a/std/encoding/yaml/loader/loader.ts
+++ b/std/encoding/yaml/loader/loader.ts
@@ -187,7 +187,7 @@ interface DirectiveHandlers {
[directive: string]: (
state: LoaderState,
name: string,
- ...args: unknown[]
+ ...args: string[]
) => void;
}
@@ -362,7 +362,7 @@ function storeMappingPair(
mergeMappings(state, result, valueNode[index], overridableKeys);
}
} else {
- mergeMappings(state, result, valueNode, overridableKeys);
+ mergeMappings(state, result, valueNode as ArrayObject, overridableKeys);
}
} else {
if (
@@ -1610,7 +1610,7 @@ function readDocument(state: LoaderState): void {
const documentStart = state.position;
let position: number,
directiveName: string,
- directiveArgs: unknown[],
+ directiveArgs: string[],
hasDirectives = false,
ch: number;
diff --git a/std/examples/gist.ts b/std/examples/gist.ts
index ead97c7e2..8fc97e0f8 100755
--- a/std/examples/gist.ts
+++ b/std/examples/gist.ts
@@ -24,7 +24,7 @@ if (parsedArgs._.length === 0) {
Deno.exit(1);
}
-const files = {};
+const files: Record<string, { content: string }> = {};
for (const filename of parsedArgs._) {
const base = pathBase(filename);
const content = await Deno.readFile(filename);
diff --git a/std/fs/copy.ts b/std/fs/copy.ts
index 62e6f59e5..86fac78df 100644
--- a/std/fs/copy.ts
+++ b/std/fs/copy.ts
@@ -85,6 +85,8 @@ async function copyFile(
await Deno.copyFile(src, dest);
if (options.preserveTimestamps) {
const statInfo = await Deno.stat(src);
+ assert(statInfo.accessed != null, `statInfo.accessed is unavailable`);
+ assert(statInfo.modified != null, `statInfo.modified is unavailable`);
await Deno.utime(dest, statInfo.accessed, statInfo.modified);
}
}
diff --git a/std/fs/empty_dir_test.ts b/std/fs/empty_dir_test.ts
index b27ebd033..928ba80e6 100644
--- a/std/fs/empty_dir_test.ts
+++ b/std/fs/empty_dir_test.ts
@@ -1,5 +1,6 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
import {
+ assert,
assertEquals,
assertStrContains,
assertThrows,
@@ -225,6 +226,8 @@ Deno.test(async function emptyDirPermission(): Promise<void> {
args: args
});
+ assert(stdout);
+
const output = await Deno.readAll(stdout);
assertStrContains(new TextDecoder().decode(output), s.output);
diff --git a/std/fs/exists_test.ts b/std/fs/exists_test.ts
index 06b908b9d..204799447 100644
--- a/std/fs/exists_test.ts
+++ b/std/fs/exists_test.ts
@@ -131,7 +131,7 @@ Deno.test(async function existsPermission(): Promise<void> {
args: args
});
- const output = await Deno.readAll(stdout);
+ const output = await Deno.readAll(stdout!);
assertStrContains(new TextDecoder().decode(output), s.output);
}
diff --git a/std/fs/walk.ts b/std/fs/walk.ts
index 108eebc46..890114525 100644
--- a/std/fs/walk.ts
+++ b/std/fs/walk.ts
@@ -65,9 +65,9 @@ export async function* walk(
includeFiles = true,
includeDirs = true,
followSymlinks = false,
- exts = null,
- match = null,
- skip = null
+ exts = undefined,
+ match = undefined,
+ skip = undefined
}: WalkOptions = {}
): AsyncIterableIterator<WalkInfo> {
if (maxDepth < 0) {
@@ -76,7 +76,7 @@ export async function* walk(
if (includeDirs && include(root, exts, match, skip)) {
yield { filename: root, info: await stat(root) };
}
- if (maxDepth < 1 || !include(root, null, null, skip)) {
+ if (maxDepth < 1 || !include(root, undefined, undefined, skip)) {
return;
}
const ls: FileInfo[] = await readDir(root);
@@ -119,9 +119,9 @@ export function* walkSync(
includeFiles = true,
includeDirs = true,
followSymlinks = false,
- exts = null,
- match = null,
- skip = null
+ exts = undefined,
+ match = undefined,
+ skip = undefined
}: WalkOptions = {}
): IterableIterator<WalkInfo> {
if (maxDepth < 0) {
@@ -130,7 +130,7 @@ export function* walkSync(
if (includeDirs && include(root, exts, match, skip)) {
yield { filename: root, info: statSync(root) };
}
- if (maxDepth < 1 || !include(root, null, null, skip)) {
+ if (maxDepth < 1 || !include(root, undefined, undefined, skip)) {
return;
}
const ls: FileInfo[] = readDirSync(root);
diff --git a/std/http/cookie.ts b/std/http/cookie.ts
index 5e4f38a29..10c9bd689 100644
--- a/std/http/cookie.ts
+++ b/std/http/cookie.ts
@@ -45,7 +45,7 @@ function toString(cookie: Cookie): string {
if (cookie.httpOnly) {
out.push("HttpOnly");
}
- if (Number.isInteger(cookie.maxAge)) {
+ if (typeof cookie.maxAge === "number" && Number.isInteger(cookie.maxAge)) {
assert(cookie.maxAge > 0, "Max-Age must be an integer superior to 0");
out.push(`Max-Age=${cookie.maxAge}`);
}
diff --git a/std/http/file_server.ts b/std/http/file_server.ts
index d71b9ad53..aa0ff49da 100755
--- a/std/http/file_server.ts
+++ b/std/http/file_server.ts
@@ -15,6 +15,7 @@ import {
Response
} from "./server.ts";
import { parse } from "../flags/mod.ts";
+import { assert } from "../testing/asserts.ts";
interface EntryInfo {
mode: string;
@@ -40,10 +41,10 @@ const encoder = new TextEncoder();
const serverArgs = parse(args) as FileServerArgs;
const CORSEnabled = serverArgs.cors ? true : false;
-const target = posix.resolve(serverArgs._[1] || "");
-const addr = `0.0.0.0:${serverArgs.port || serverArgs.p || 4500}`;
+const target = posix.resolve(serverArgs._[1] ?? "");
+const addr = `0.0.0.0:${serverArgs.port ?? serverArgs.p ?? 4500}`;
-if (serverArgs.h || serverArgs.help) {
+if (serverArgs.h ?? serverArgs.help) {
console.log(`Deno File Server
Serves a local directory in HTTP.
@@ -125,8 +126,8 @@ async function serveDir(
const listEntry: EntryInfo[] = [];
const fileInfos = await readDir(dirPath);
for (const fileInfo of fileInfos) {
- const filePath = posix.join(dirPath, fileInfo.name);
- const fileUrl = posix.join(dirUrl, fileInfo.name);
+ const filePath = posix.join(dirPath, fileInfo.name ?? "");
+ const fileUrl = posix.join(dirUrl, fileInfo.name ?? "");
if (fileInfo.name === "index.html" && fileInfo.isFile()) {
// in case index.html as dir...
return await serveFile(req, filePath);
@@ -139,7 +140,7 @@ async function serveDir(
listEntry.push({
mode: modeToString(fileInfo.isDirectory(), mode),
size: fileInfo.isFile() ? fileLenToString(fileInfo.len) : "",
- name: fileInfo.name,
+ name: fileInfo.name ?? "",
url: fileUrl
});
}
@@ -311,7 +312,7 @@ listenAndServe(
}
const fsPath = posix.join(target, normalizedUrl);
- let response: Response;
+ let response: Response | undefined;
try {
const info = await stat(fsPath);
if (info.isDirectory()) {
@@ -324,10 +325,11 @@ listenAndServe(
response = await serveFallback(req, e);
} finally {
if (CORSEnabled) {
+ assert(response);
setCORS(response);
}
- serverLog(req, response);
- req.respond(response);
+ serverLog(req, response!);
+ req.respond(response!);
}
}
);
diff --git a/std/http/file_server_test.ts b/std/http/file_server_test.ts
index 0329168e7..7c60d5f56 100644
--- a/std/http/file_server_test.ts
+++ b/std/http/file_server_test.ts
@@ -38,7 +38,7 @@ test(async function serveFile(): Promise<void> {
assert(res.headers.has("access-control-allow-origin"));
assert(res.headers.has("access-control-allow-headers"));
assert(res.headers.has("content-type"));
- assert(res.headers.get("content-type").includes("charset=utf-8"));
+ assert(res.headers.get("content-type")!.includes("charset=utf-8"));
const downloadedFile = await res.text();
const localFile = new TextDecoder().decode(
await Deno.readFile("README.md")
diff --git a/std/http/server.ts b/std/http/server.ts
index c6a895a1f..9e9cde016 100644
--- a/std/http/server.ts
+++ b/std/http/server.ts
@@ -436,7 +436,7 @@ export class Server implements AsyncIterable<ServerRequest> {
): AsyncIterableIterator<ServerRequest> {
const bufr = new BufReader(conn);
const w = new BufWriter(conn);
- let req: ServerRequest | Deno.EOF;
+ let req: ServerRequest | Deno.EOF | undefined;
let err: Error | undefined;
while (!this.closing) {
diff --git a/std/http/server_test.ts b/std/http/server_test.ts
index 123bc7155..89aaca4ea 100644
--- a/std/http/server_test.ts
+++ b/std/http/server_test.ts
@@ -545,7 +545,7 @@ test(async function testReadRequestError(): Promise<void> {
for (const test of testCases) {
const reader = new BufReader(new StringReader(test.in));
let err;
- let req: ServerRequest | Deno.EOF;
+ let req: ServerRequest | Deno.EOF | undefined;
try {
req = await readRequest(mockConn as Deno.Conn, reader);
} catch (e) {
@@ -559,7 +559,7 @@ test(async function testReadRequestError(): Promise<void> {
assert(err instanceof (test.err as typeof UnexpectedEOFError));
} else {
assert(req instanceof ServerRequest);
- assert(test.headers != null);
+ assert(test.headers);
assertEquals(err, undefined);
assertNotEquals(req, Deno.EOF);
for (const h of test.headers) {
@@ -719,6 +719,7 @@ if (Deno.build.os !== "win") {
const serverRoutine = async (): Promise<void> => {
let reqCount = 0;
const server = serve(":8124");
+ // @ts-ignore
const serverRid = server.listener["rid"];
let connRid = -1;
for await (const req of server) {
diff --git a/std/io/bufio.ts b/std/io/bufio.ts
index c0a52ac6a..fa0ba7e73 100644
--- a/std/io/bufio.ts
+++ b/std/io/bufio.ts
@@ -311,7 +311,7 @@ export class BufReader implements Reader {
*/
async readSlice(delim: number): Promise<Uint8Array | Deno.EOF> {
let s = 0; // search start index
- let slice: Uint8Array;
+ let slice: Uint8Array | undefined;
while (true) {
// Search buffer.
diff --git a/std/manual.md b/std/manual.md
index 78037ad1e..99feef15b 100644
--- a/std/manual.md
+++ b/std/manual.md
@@ -1538,7 +1538,7 @@ Build with Cargo:
cargo build -vv
# Run:
-./target/debug/deno tests/002_hello.ts
+./target/debug/deno cli/tests/002_hello.ts
```
#### Testing and Tools
diff --git a/std/node/events.ts b/std/node/events.ts
index f4b3e0bc5..b2f1d6026 100644
--- a/std/node/events.ts
+++ b/std/node/events.ts
@@ -22,6 +22,7 @@
// USE OR OTHER DEALINGS IN THE SOFTWARE.
import { validateIntegerRange } from "./util.ts";
+import { assert } from "../testing/asserts.ts";
export interface WrappedFunction extends Function {
listener: Function;
@@ -163,7 +164,8 @@ export default class EventEmitter {
private unwrapListeners(arr: Function[]): Function[] {
const unwrappedListeners: Function[] = new Array(arr.length) as Function[];
for (let i = 0; i < arr.length; i++) {
- unwrappedListeners[i] = arr[i]["listener"] || arr[i];
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
+ unwrappedListeners[i] = (arr[i] as any)["listener"] || arr[i];
}
return unwrappedListeners;
}
@@ -232,10 +234,12 @@ export default class EventEmitter {
const wrapperContext = {
eventName: eventName,
listener: listener,
- rawListener: wrapper,
+ rawListener: (wrapper as unknown) as WrappedFunction,
context: this
};
- const wrapped = wrapper.bind(wrapperContext);
+ const wrapped = (wrapper.bind(
+ wrapperContext
+ ) as unknown) as WrappedFunction;
wrapperContext.rawListener = wrapped;
wrapped.listener = listener;
return wrapped as WrappedFunction;
@@ -275,7 +279,7 @@ export default class EventEmitter {
return this;
}
- if (this._events.has(eventName)) {
+ if (eventName && this._events.has(eventName)) {
const listeners = (this._events.get(eventName) as Array<
Function | WrappedFunction
>).slice(); // Create a copy; We use it AFTER it's deleted.
@@ -299,14 +303,19 @@ export default class EventEmitter {
*/
public removeListener(eventName: string | symbol, listener: Function): this {
if (this._events.has(eventName)) {
- const arr: Array<Function | WrappedFunction> = this._events.get(
- eventName
- );
+ const arr:
+ | Array<Function | WrappedFunction>
+ | undefined = this._events.get(eventName);
+
+ assert(arr);
let listenerIndex = -1;
for (let i = arr.length - 1; i >= 0; i--) {
// arr[i]["listener"] is the reference to the listener inside a bound 'once' wrapper
- if (arr[i] == listener || arr[i]["listener"] == listener) {
+ if (
+ arr[i] == listener ||
+ (arr[i] && (arr[i] as WrappedFunction)["listener"] == listener)
+ ) {
listenerIndex = i;
break;
}
@@ -421,8 +430,10 @@ export function on(
): AsyncInterable {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const unconsumedEventValues: any[] = [];
- const unconsumedPromises = [];
- let error = null;
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
+ const unconsumedPromises: any[] = [];
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
+ let error: Error | null = null;
let finished = false;
const iterator = {
@@ -476,7 +487,7 @@ export function on(
},
// eslint-disable-next-line @typescript-eslint/no-explicit-any
- [Symbol.asyncIterator](): AsyncIterable<any> {
+ [Symbol.asyncIterator](): any {
return this;
}
};
diff --git a/std/node/events_test.ts b/std/node/events_test.ts
index c89df298a..b0b74e499 100644
--- a/std/node/events_test.ts
+++ b/std/node/events_test.ts
@@ -17,7 +17,7 @@ test({
fn() {
let eventsFired: string[] = [];
const testEmitter = new EventEmitter();
- testEmitter.on("newListener", event => {
+ testEmitter.on("newListener", (event: string) => {
if (event !== "newListener") {
eventsFired.push("newListener");
}
@@ -81,20 +81,23 @@ test({
fn() {
const testEmitter = new EventEmitter();
const eventsFired: string[] = [];
- testEmitter.on("event", oneArg => {
+ testEmitter.on("event", (oneArg: string) => {
eventsFired.push("event(" + oneArg + ")");
});
- testEmitter.on("event", (oneArg, twoArg) => {
+ testEmitter.on("event", (oneArg: string, twoArg: string) => {
eventsFired.push("event(" + oneArg + ", " + twoArg + ")");
});
testEmitter.on("non-event", shouldNeverBeEmitted);
- testEmitter.on("event", (oneArg, twoArg, threeArg) => {
- eventsFired.push(
- "event(" + oneArg + ", " + twoArg + ", " + threeArg + ")"
- );
- });
+ testEmitter.on(
+ "event",
+ (oneArg: string, twoArg: string, threeArg: string) => {
+ eventsFired.push(
+ "event(" + oneArg + ", " + twoArg + ", " + threeArg + ")"
+ );
+ }
+ );
testEmitter.emit("event", 1, 2, 3);
assertEquals(eventsFired, ["event(1)", "event(1, 2)", "event(1, 2, 3)"]);
}
diff --git a/std/node/global.ts b/std/node/global.ts
index c21b0b659..c889e9c8d 100644
--- a/std/node/global.ts
+++ b/std/node/global.ts
@@ -1 +1,2 @@
-window["global"] = window;
+// @ts-ignore
+globalThis["global"] = globalThis;
diff --git a/std/node/module.ts b/std/node/module.ts
index ac436c555..547c76bab 100644
--- a/std/node/module.ts
+++ b/std/node/module.ts
@@ -40,7 +40,7 @@ const isWindows = path.isWindows;
const relativeResolveCache = Object.create(null);
let requireDepth = 0;
-let statCache = null;
+let statCache: Map<string, StatResult> | null = null;
type StatResult = -1 | 0 | 1;
// Returns 0 if the path refers to
@@ -64,7 +64,11 @@ function stat(filename: string): StatResult {
}
}
-function updateChildren(parent: Module, child: Module, scan: boolean): void {
+function updateChildren(
+ parent: Module | null,
+ child: Module,
+ scan: boolean
+): void {
const children = parent && parent.children;
if (children && !(scan && children.includes(child))) {
children.push(child);
@@ -75,17 +79,17 @@ class Module {
id: string;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
exports: any;
- parent?: Module;
- filename: string;
+ parent: Module | null;
+ filename: string | null;
loaded: boolean;
children: Module[];
paths: string[];
path: string;
- constructor(id = "", parent?: Module) {
+ constructor(id = "", parent?: Module | null) {
this.id = id;
this.exports = {};
- this.parent = parent;
- updateChildren(parent, this, false);
+ this.parent = parent || null;
+ updateChildren(parent || null, this, false);
this.filename = null;
this.loaded = false;
this.children = [];
@@ -229,25 +233,25 @@ class Module {
fakeParent.paths = Module._nodeModulePaths(path);
const lookupPaths = Module._resolveLookupPaths(request, fakeParent);
- for (let j = 0; j < lookupPaths.length; j++) {
- if (!paths.includes(lookupPaths[j])) paths.push(lookupPaths[j]);
+ for (let j = 0; j < lookupPaths!.length; j++) {
+ if (!paths.includes(lookupPaths![j])) paths.push(lookupPaths![j]);
}
}
}
} else if (options.paths === undefined) {
- paths = Module._resolveLookupPaths(request, parent);
+ paths = Module._resolveLookupPaths(request, parent)!;
} else {
throw new Error("options.paths is invalid");
}
} else {
- paths = Module._resolveLookupPaths(request, parent);
+ paths = Module._resolveLookupPaths(request, parent)!;
}
// Look up the filename first, since that's the cache key.
const filename = Module._findPath(request, paths, isMain);
if (!filename) {
const requireStack = [];
- for (let cursor = parent; cursor; cursor = cursor.parent) {
+ for (let cursor: Module | null = parent; cursor; cursor = cursor.parent) {
requireStack.push(cursor.filename || cursor.id);
}
let message = `Cannot find module '${request}'`;
@@ -341,7 +345,7 @@ class Module {
// object.
// eslint-disable-next-line @typescript-eslint/no-explicit-any
static _load(request: string, parent: Module, isMain: boolean): any {
- let relResolveCacheIdentifier;
+ let relResolveCacheIdentifier: string | undefined;
if (parent) {
// Fast path for (lazy loaded) modules in the same directory. The indirect
// caching is required to allow cache invalidation without changing the old
@@ -385,6 +389,7 @@ class Module {
Module._cache[filename] = module;
if (parent !== undefined) {
+ assert(relResolveCacheIdentifier);
relativeResolveCache[relResolveCacheIdentifier] = filename;
}
@@ -397,6 +402,7 @@ class Module {
if (threw) {
delete Module._cache[filename];
if (parent !== undefined) {
+ assert(relResolveCacheIdentifier);
delete relativeResolveCache[relResolveCacheIdentifier];
}
} else if (
@@ -602,7 +608,7 @@ for (const id of nativeModulePolyfill.keys()) {
Module.builtinModules.push(id);
}
-let modulePaths = [];
+let modulePaths: string[] = [];
// Given a module name, and a list of paths to test, returns the first
// matching file in the following precedence.
@@ -664,7 +670,7 @@ function readPackage(requestPath: string): PackageInfo | null {
}
function readPackageScope(
- checkPath
+ checkPath: string
): { path: string; data: PackageInfo } | false {
const rootSeparatorIndex = checkPath.indexOf(path.sep);
let separatorIndex;
@@ -987,6 +993,7 @@ const CircularRequirePrototypeWarningProxy = new Proxy(
{
// eslint-disable-next-line @typescript-eslint/no-explicit-any
get(target, prop): any {
+ // @ts-ignore
if (prop in target) return target[prop];
emitCircularRequireWarning(prop);
return undefined;
@@ -1150,7 +1157,7 @@ function getPathFromURLWin32(url: URL): string {
let pathname = url.pathname;
for (let n = 0; n < pathname.length; n++) {
if (pathname[n] === "%") {
- const third = pathname.codePointAt(n + 2) | 0x20;
+ const third = pathname.codePointAt(n + 2)! | 0x20;
if (
(pathname[n + 1] === "2" && third === 102) || // 2f 2F /
(pathname[n + 1] === "5" && third === 99)
@@ -1165,7 +1172,7 @@ function getPathFromURLWin32(url: URL): string {
pathname = pathname.replace(forwardSlashRegEx, "\\");
pathname = decodeURIComponent(pathname);
// TODO: handle windows hostname case (needs bindings)
- const letter = pathname.codePointAt(1) | 0x20;
+ const letter = pathname.codePointAt(1)! | 0x20;
const sep = pathname[2];
if (
letter < CHAR_LOWERCASE_A ||
@@ -1184,7 +1191,7 @@ function getPathFromURLPosix(url: URL): string {
const pathname = url.pathname;
for (let n = 0; n < pathname.length; n++) {
if (pathname[n] === "%") {
- const third = pathname.codePointAt(n + 2) | 0x20;
+ const third = pathname.codePointAt(n + 2)! | 0x20;
if (pathname[n + 1] === "2" && third === 102) {
throw new Error(
"Invalid file URL path: must not include encoded / characters"
diff --git a/std/node/os.ts b/std/node/os.ts
index e4a00c450..3bff03a69 100644
--- a/std/node/os.ts
+++ b/std/node/os.ts
@@ -123,7 +123,7 @@ export function getPriority(pid = 0): number {
}
/** Returns the string path of the current user's home directory. */
-export function homedir(): string {
+export function homedir(): string | null {
return Deno.dir("home");
}
@@ -157,7 +157,7 @@ export function release(): string {
/** Not yet implemented */
export function setPriority(pid: number, priority?: number): void {
- /* The node API has the 'pid' as the first parameter and as optional.
+ /* The node API has the 'pid' as the first parameter and as optional.
This makes for a problematic implementation in Typescript. */
if (priority === undefined) {
priority = pid;
diff --git a/std/path/utils.ts b/std/path/utils.ts
index 9911f5347..cb1c14c16 100644
--- a/std/path/utils.ts
+++ b/std/path/utils.ts
@@ -46,13 +46,13 @@ export function normalizeString(
let lastSegmentLength = 0;
let lastSlash = -1;
let dots = 0;
- let code: number;
+ let code: number | undefined;
for (let i = 0, len = path.length; i <= len; ++i) {
if (i < len) code = path.charCodeAt(i);
- else if (isPathSeparator(code)) break;
+ else if (isPathSeparator(code!)) break;
else code = CHAR_FORWARD_SLASH;
- if (isPathSeparator(code)) {
+ if (isPathSeparator(code!)) {
if (lastSlash === i - 1 || dots === 1) {
// NOOP
} else if (lastSlash !== i - 1 && dots === 2) {
diff --git a/std/path/win32.ts b/std/path/win32.ts
index 11518ee7c..2f28d22c1 100644
--- a/std/path/win32.ts
+++ b/std/path/win32.ts
@@ -303,7 +303,7 @@ export function join(...paths: string[]): string {
if (pathsCount === 0) return ".";
let joined: string | undefined;
- let firstPart: string;
+ let firstPart: string | null = null;
for (let i = 0; i < pathsCount; ++i) {
const path = paths[i];
assertPath(path);
diff --git a/std/textproto/mod.ts b/std/textproto/mod.ts
index 465753823..dd7d3ede9 100644
--- a/std/textproto/mod.ts
+++ b/std/textproto/mod.ts
@@ -67,7 +67,7 @@ export class TextProtoReader {
*/
async readMIMEHeader(): Promise<Headers | Deno.EOF> {
const m = new Headers();
- let line: Uint8Array;
+ let line: Uint8Array | undefined;
// The first line cannot start with a leading space.
let buf = await this.r.peek(1);
@@ -135,7 +135,7 @@ export class TextProtoReader {
async readLineSlice(): Promise<Uint8Array | Deno.EOF> {
// this.closeDot();
- let line: Uint8Array;
+ let line: Uint8Array | undefined;
while (true) {
const r = await this.r.readLine();
if (r === Deno.EOF) return Deno.EOF;
diff --git a/std/util/deep_assign.ts b/std/util/deep_assign.ts
index 9b57e45dc..9034d89bd 100644
--- a/std/util/deep_assign.ts
+++ b/std/util/deep_assign.ts
@@ -1,4 +1,6 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
+import { assert } from "../testing/asserts.ts";
+
export function deepAssign(
target: Record<string, unknown>,
...sources: object[]
@@ -24,6 +26,7 @@ export function deepAssign(
if (typeof target[key] !== `object` || !target[key]) {
target[key] = {};
}
+ assert(value);
deepAssign(target[key] as Record<string, unknown>, value);
});
}