Skip to content

Commit 5770ae0

Browse files
bmacnaughtontargos
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 099d776 commit 5770ae0

1 file changed

Lines changed: 13 additions & 5 deletions

File tree

‎doc/api/module.md‎

Lines changed: 13 additions & 5 deletions
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
constfs=require('fs');
90+
constassert=require('assert');
9091
const { syncBuiltinESMExports } =require('module');
9192

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

9495
deletefs.readFileSync;
9596

96-
fs.newAPI=functionnewAPI() {
97+
functionnewAPI() {
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)