Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruce A. MacNaughton <bmacnaughton@gmail.com>2020-07-10 03:27:46 +0300
committerAntoine du Hamel <duhamelantoine1995@gmail.com>2021-01-10 12:37:11 +0300
commit28e9c10003aede86df930c94325bb10827cf6e1a (patch)
tree6d70f70c12288ceb1d298ae1587e7b1d867b6ab6 /doc/api/module.md
parent7a6af022e6e797ea8bfa6eb541bf13720abaaef4 (diff)
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 <guybedford@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Diffstat (limited to 'doc/api/module.md')
-rw-r--r--doc/api/module.md18
1 files changed, 13 insertions, 5 deletions
diff --git a/doc/api/module.md b/doc/api/module.md
index b78aa986da5..637b7f3e059 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);
});
```