Skip to content

Commit 153be6c

Browse files
bmacnaughtondanielleadams
authored andcommitted
doc: fix module syncBuiltinESMExports example
Fix failing code and add explanations of each assert. PR-URL: #34284 Reviewed-By: Guy Bedford <[email protected]> Reviewed-By: Antoine du Hamel <[email protected]>
1 parent b6f74b0 commit 153be6c

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
@@ -95,21 +95,29 @@ does not add or remove exported names from the [ES Modules][].
9595
9696
```js
9797
const fs = require('fs');
98+
const assert = require('assert');
9899
const { syncBuiltinESMExports } = require('module');
99100

100-
fs.readFile = null;
101+
fs.readFile = newAPI;
101102

102103
delete fs.readFileSync;
103104

104-
fs.newAPI = function newAPI() {
105+
function newAPI() {
105106
// ...
106-
};
107+
}
108+
109+
fs.newAPI = newAPI;
107110

108111
syncBuiltinESMExports();
109112

110113
import('fs').then((esmFS) => {
111-
assert.strictEqual(esmFS.readFile, null);
112-
assert.strictEqual('readFileSync' in fs, true);
114+
// It syncs the existing readFile property with the new value
115+
assert.strictEqual(esmFS.readFile, newAPI);
116+
// readFileSync has been deleted from the required fs
117+
assert.strictEqual('readFileSync' in fs, false);
118+
// syncBuiltinESMExports() does not remove readFileSync from esmFS
119+
assert.strictEqual('readFileSync' in esmFS, true);
120+
// syncBuiltinESMExports() does not add names
113121
assert.strictEqual(esmFS.newAPI, undefined);
114122
});
115123
```

0 commit comments

Comments
 (0)