Skip to content

Commit

Permalink
Add strict mode assert typedefs
Browse files Browse the repository at this point in the history
Summary:
<!--
  If this is a change to library defintions, please include links to relevant documentation.
  If this is a documentation change, please prefix the title with [DOCS].

  If this is neither, ensure you opened a discussion issue and link it in the PR description.
-->

Closes #7217
Revived #7401

https://nodejs.org/api/assert.html#assert_strict_mode

Pull Request resolved: #7660

Reviewed By: mroch

Differential Revision: D26887564

Pulled By: nmote

fbshipit-source-id: f9713814b0628efba3d0d8797b64a1682be0effe
  • Loading branch information
goodmind authored and facebook-github-bot committed Mar 10, 2021
1 parent 44da322 commit 1ad5088
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 33 deletions.
22 changes: 22 additions & 0 deletions lib/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -2648,6 +2648,27 @@ declare module "zlib" {

declare module "assert" {
declare class AssertionError extends Error {}
declare type AssertStrict = {
(value: any, message?: string): void;
ok(value: any, message?: string): void;
fail(message?: string | Error): void;
// deprecated since v10.15
fail(actual: any, expected: any, message: string, operator: string): void;
equal(actual: any, expected: any, message?: string): void;
notEqual(actual: any, expected: any, message?: string): void;
deepEqual(actual: any, expected: any, message?: string): void;
notDeepEqual(actual: any, expected: any, message?: string): void;
throws(
block: Function,
error?: Function | RegExp | (err: any) => boolean,
message?: string
): void;
doesNotThrow(block: Function, message?: string): void;
ifError(value: any): void;
AssertionError: typeof AssertionError;
strict: AssertStrict;
...
}
declare module.exports: {
(value: any, message?: string): void,
ok(value: any, message?: string): void,
Expand All @@ -2670,6 +2691,7 @@ declare module "assert" {
doesNotThrow(block: Function, message?: string): void,
ifError(value: any): void,
AssertionError: typeof AssertionError,
strict: AssertStrict;
...
}
}
Expand Down
66 changes: 33 additions & 33 deletions tests/node_tests/node_tests.exp
Original file line number Diff line number Diff line change
Expand Up @@ -1636,26 +1636,26 @@ References:
process/emitWarning.js:10:1
10| process.emitWarning(); // error
^^^^^^^^^^^^^^^^^^^^^ [1]
<BUILTINS>/node.js:2771:24
2771| emitWarning(warning: string | Error): void;
<BUILTINS>/node.js:2793:24
2793| emitWarning(warning: string | Error): void;
^^^^^^ [2]
<BUILTINS>/node.js:2771:33
2771| emitWarning(warning: string | Error): void;
<BUILTINS>/node.js:2793:33
2793| emitWarning(warning: string | Error): void;
^^^^^ [3]
<BUILTINS>/node.js:2772:3
2772| emitWarning(warning: string, typeOrCtor: string | (...empty) => mixed): void;
<BUILTINS>/node.js:2794:3
2794| emitWarning(warning: string, typeOrCtor: string | (...empty) => mixed): void;
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ [4]
<BUILTINS>/node.js:2773:3
2773| emitWarning(warning: string, type: string, codeOrCtor: string | (...empty) => mixed): void;
<BUILTINS>/node.js:2795:3
2795| emitWarning(warning: string, type: string, codeOrCtor: string | (...empty) => mixed): void;
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ [5]
<BUILTINS>/node.js:2774:3
<BUILTINS>/node.js:2796:3
v-----------
2774| emitWarning(
2775| warning: string,
2776| type: string,
2777| code: string,
2778| ctor?: (...empty) => mixed
2779| ): void;
2796| emitWarning(
2797| warning: string,
2798| type: string,
2799| code: string,
2800| ctor?: (...empty) => mixed
2801| ): void;
------^ [6]


Expand All @@ -1674,14 +1674,14 @@ References:
process/emitWarning.js:11:21
11| process.emitWarning(42); // error
^^ [1]
<BUILTINS>/node.js:2772:24
2772| emitWarning(warning: string, typeOrCtor: string | (...empty) => mixed): void;
<BUILTINS>/node.js:2794:24
2794| emitWarning(warning: string, typeOrCtor: string | (...empty) => mixed): void;
^^^^^^ [2]
<BUILTINS>/node.js:2773:24
2773| emitWarning(warning: string, type: string, codeOrCtor: string | (...empty) => mixed): void;
<BUILTINS>/node.js:2795:24
2795| emitWarning(warning: string, type: string, codeOrCtor: string | (...empty) => mixed): void;
^^^^^^ [3]
<BUILTINS>/node.js:2775:14
2775| warning: string,
<BUILTINS>/node.js:2797:14
2797| warning: string,
^^^^^^ [4]


Expand All @@ -1699,11 +1699,11 @@ References:
process/emitWarning.js:12:29
12| process.emitWarning("blah", 42); // error
^^ [1]
<BUILTINS>/node.js:2773:38
2773| emitWarning(warning: string, type: string, codeOrCtor: string | (...empty) => mixed): void;
<BUILTINS>/node.js:2795:38
2795| emitWarning(warning: string, type: string, codeOrCtor: string | (...empty) => mixed): void;
^^^^^^ [2]
<BUILTINS>/node.js:2776:11
2776| type: string,
<BUILTINS>/node.js:2798:11
2798| type: string,
^^^^^^ [3]


Expand All @@ -1719,8 +1719,8 @@ References:
process/emitWarning.js:13:37
13| process.emitWarning("blah", "blah", 42); // error
^^ [1]
<BUILTINS>/node.js:2777:11
2777| code: string,
<BUILTINS>/node.js:2799:11
2799| code: string,
^^^^^^ [2]


Expand All @@ -1734,8 +1734,8 @@ Cannot cast `process.emitWarning(...)` to string because undefined [1] is incomp
^^^^^^^^^^^^^^^^^^^^^^^^^^^

References:
<BUILTINS>/node.js:2771:41
2771| emitWarning(warning: string | Error): void;
<BUILTINS>/node.js:2793:41
2793| emitWarning(warning: string | Error): void;
^^^^ [1]
process/emitWarning.js:14:31
14| (process.emitWarning("blah"): string); // error
Expand Down Expand Up @@ -1800,8 +1800,8 @@ References:
process/nextTick.js:27:3
27| (a: string, b: number, c: boolean) => {} // Error: too few arguments
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ [1]
<BUILTINS>/node.js:2800:21
2800| nextTick: <T>(cb: (...T) => mixed, ...T) => void;
<BUILTINS>/node.js:2822:21
2822| nextTick: <T>(cb: (...T) => mixed, ...T) => void;
^^^^^^^^^^^^^^^ [2]


Expand All @@ -1815,8 +1815,8 @@ Cannot cast `process.allowedNodeEnvironmentFlags` to string because `Set` [1] is
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

References:
<BUILTINS>/node.js:2760:32
2760| allowedNodeEnvironmentFlags: Set<string>;
<BUILTINS>/node.js:2782:32
2782| allowedNodeEnvironmentFlags: Set<string>;
^^^^^^^^^^^ [1]
process/process.js:5:39
5| (process.allowedNodeEnvironmentFlags: string); // error
Expand Down

0 comments on commit 1ad5088

Please sign in to comment.