Skip to content

Commit 5770ae0

Browse files
bmacnaughtontargos
authored andcommittedMay 1, 2021
doc: fix module syncBuiltinESMExports example
Fix failing code and add explanations of each assert. PR-URL: #34284 Reviewed-By: Guy Bedford <guybedford@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
1 parent 099d776 commit 5770ae0

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed
 

‎doc/api/module.md

+13-5
Original file line numberDiff line numberDiff line change
@@ -87,21 +87,29 @@ does not add or remove exported names from the [ES Modules][].
8787
8888
```js
8989
const fs = require('fs');
90+
const assert = require('assert');
9091
const { syncBuiltinESMExports } = require('module');
9192

92-
fs.readFile = null;
93+
fs.readFile = newAPI;
9394

9495
delete fs.readFileSync;
9596

96-
fs.newAPI = function newAPI() {
97+
function newAPI() {
9798
// ...
98-
};
99+
}
100+
101+
fs.newAPI = newAPI;
99102

100103
syncBuiltinESMExports();
101104

102105
import('fs').then((esmFS) => {
103-
assert.strictEqual(esmFS.readFile, null);
104-
assert.strictEqual('readFileSync' in fs, true);
106+
// It syncs the existing readFile property with the new value
107+
assert.strictEqual(esmFS.readFile, newAPI);
108+
// readFileSync has been deleted from the required fs
109+
assert.strictEqual('readFileSync' in fs, false);
110+
// syncBuiltinESMExports() does not remove readFileSync from esmFS
111+
assert.strictEqual('readFileSync' in esmFS, true);
112+
// syncBuiltinESMExports() does not add names
105113
assert.strictEqual(esmFS.newAPI, undefined);
106114
});
107115
```

0 commit comments

Comments
 (0)
Please sign in to comment.