| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent b6f74b0 commit 153be6c
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -95,21 +95,29 @@ does not add or remove exported names from the [ES Modules][]. | |||
| 95 | 95 | ||
| 96 | 96 | ```js | |
| 97 | 97 | const fs = require('fs'); | |
| 98 | + const assert = require('assert'); | ||
| 98 | 99 | const { syncBuiltinESMExports } = require('module'); | |
| 99 | 100 | ||
| 100 | - fs.readFile = null; | ||
| 101 | + fs.readFile = newAPI; | ||
| 101 | 102 | ||
| 102 | 103 | delete fs.readFileSync; | |
| 103 | 104 | ||
| 104 | - fs.newAPI = function newAPI() { | ||
| 105 | + function newAPI() { | ||
| 105 | 106 | // ... | |
| 106 | - }; | ||
| 107 | + } | ||
| 108 | + | ||
| 109 | + fs.newAPI = newAPI; | ||
| 107 | 110 | ||
| 108 | 111 | syncBuiltinESMExports(); | |
| 109 | 112 | ||
| 110 | 113 | 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 | ||
| 113 | 121 | assert.strictEqual(esmFS.newAPI, undefined); | |
| 114 | 122 | }); | |
| 115 | 123 | ``` | |
| Back | FazBrowse Home | New Git URL |
0 commit comments