Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 153be6c

Browse filesBrowse 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 <guybedford@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
1 parent b6f74b0 commit 153be6c
Copy full SHA for 153be6c

File tree

Expand file treeCollapse file tree

1 file changed

+13
-5
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+13
-5
lines changed
Open diff view settings
Collapse file

‎doc/api/module.md‎

Copy file name to clipboardExpand all lines: doc/api/module.md
+13-5Lines changed: 13 additions & 5 deletions
  • Display the source diff
  • Display the rich diff
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.