From 153be6c80e1111b920373b0bcb5d19026280697c Mon Sep 17 00:00:00 2001 From: "Bruce A. MacNaughton" Date: Thu, 9 Jul 2020 17:27:46 -0700 Subject: [PATCH] doc: fix module syncBuiltinESMExports example Fix failing code and add explanations of each assert. PR-URL: https://github.com/nodejs/node/pull/34284 Reviewed-By: Guy Bedford Reviewed-By: Antoine du Hamel --- doc/api/module.md | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/doc/api/module.md b/doc/api/module.md index b78aa986da5778..637b7f3e059b0b 100644 --- a/doc/api/module.md +++ b/doc/api/module.md @@ -95,21 +95,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); }); ```