diff --git a/doc/api/module.md b/doc/api/module.md index 2fb6ca884b4443..3a00e6d47b014e 100644 --- a/doc/api/module.md +++ b/doc/api/module.md @@ -87,21 +87,29 @@ does not add or remove exported names from the [ES Modules][]. ```js const fs = require('fs'); +const assert = require('assert'); const { syncBuiltinESMExports } = require('module'); -fs.readFile = null; +fs.readFile = newAPI; delete fs.readFileSync; -fs.newAPI = function newAPI() { +function newAPI() { // ... -}; +} + +fs.newAPI = newAPI; syncBuiltinESMExports(); import('fs').then((esmFS) => { - assert.strictEqual(esmFS.readFile, null); - assert.strictEqual('readFileSync' in fs, true); + // It syncs the existing readFile property with the new value + assert.strictEqual(esmFS.readFile, newAPI); + // readFileSync has been deleted from the required fs + assert.strictEqual('readFileSync' in fs, false); + // syncBuiltinESMExports() does not remove readFileSync from esmFS + assert.strictEqual('readFileSync' in esmFS, true); + // syncBuiltinESMExports() does not add names assert.strictEqual(esmFS.newAPI, undefined); }); ```