@@ -156,13 +156,13 @@ added: v12.10.0
156
156
157
157
* ` text/javascript ` for ES Modules
158
158
* ` application/json ` for JSON
159
- * ` application/wasm ` for WASM.
159
+ * ` application/wasm ` for Wasm
160
160
161
161
` data: ` URLs only resolve [ _ Bare specifiers_ ] [ Terminology ] for builtin modules
162
162
and [ _ Absolute specifiers_ ] [ Terminology ] . Resolving
163
- [ _ Relative specifiers_ ] [ Terminology ] will not work because ` data: ` is not a
163
+ [ _ Relative specifiers_ ] [ Terminology ] does not work because ` data: ` is not a
164
164
[ special scheme] [ ] . For example, attempting to load ` ./foo `
165
- from ` data:text/javascript,import "./foo"; ` will fail to resolve since there
165
+ from ` data:text/javascript,import "./foo"; ` fails to resolve because there
166
166
is no concept of relative resolution for ` data: ` URLs. An example of a ` data: `
167
167
URLs being used is:
168
168
@@ -234,7 +234,7 @@ from which to resolve from:
234
234
})();
235
235
` ` `
236
236
237
- This function is asynchronous since the ES module resolver in Node.js is
237
+ This function is asynchronous because the ES module resolver in Node.js is
238
238
asynchronous. With the introduction of [Top-Level Await][], these use cases
239
239
will be easier as they won't require an async function wrapper.
240
240
@@ -253,8 +253,8 @@ ES modules are resolved and cached based upon
253
253
[URL](https://url.spec.whatwg.org/) semantics. This means that files containing
254
254
special characters such as ` #` and ` ?` need to be escaped.
255
255
256
- Modules will be loaded multiple times if the ` import` specifier used to resolve
257
- them have a different query or fragment.
256
+ Modules are loaded multiple times if the ` import` specifier used to resolve
257
+ them has a different query or fragment.
258
258
259
259
` ` ` js
260
260
import ' ./foo.mjs?query=1' ; // loads ./foo.mjs with query of "?query=1"
@@ -329,8 +329,8 @@ console.log(cjs === cjsSugar);
329
329
// true
330
330
` ` `
331
331
332
- The ECMAScript Module Namespace representation of a CommonJS module will always
333
- be a namespace with a ` default` export key pointing to the CommonJS
332
+ The ECMAScript Module Namespace representation of a CommonJS module is always
333
+ a namespace with a ` default` export key pointing to the CommonJS
334
334
` module .exports ` value.
335
335
336
336
This Module Namespace Exotic Object can be directly observed either when using
@@ -346,19 +346,19 @@ console.log(m === await import('cjs'));
346
346
// true
347
347
` ` `
348
348
349
- For better compatibility with existing usage in the JS ecosystem, Node.js will
350
- in addition attempt to determine the CommonJS named exports of every imported
349
+ For better compatibility with existing usage in the JS ecosystem, Node.js
350
+ in addition attempts to determine the CommonJS named exports of every imported
351
351
CommonJS module to provide them as separate ES module exports using a static
352
352
analysis process.
353
353
354
- For example, a CommonJS module written:
354
+ For example, consider a CommonJS module written:
355
355
356
356
` ` ` js
357
357
// cjs.cjs
358
358
exports .name = ' exported' ;
359
359
` ` `
360
360
361
- will support named imports in ES modules:
361
+ The preceding module supports named imports in ES modules:
362
362
363
363
<!-- eslint-disable no-duplicate-imports -->
364
364
` ` ` js
@@ -382,8 +382,8 @@ directly on the ES module namespace when the module is imported.
382
382
Live binding updates or new exports added to ` module .exports ` are not detected
383
383
for these named exports.
384
384
385
- The detection of named exports is based on common syntax patterns but will not
386
- always correctly detect named exports, in these cases using the default
385
+ The detection of named exports is based on common syntax patterns but does not
386
+ always correctly detect named exports. In these cases, using the default
387
387
import form described above can be a better option.
388
388
389
389
Named exports detection covers many common export patterns, reexport patterns
@@ -392,7 +392,7 @@ semantics implemented.
392
392
393
393
## Builtin modules
394
394
395
- [Core modules][] will provide named exports of their public API. A
395
+ [Core modules][] provide named exports of their public API. A
396
396
default export is also provided which is the value of the CommonJS exports.
397
397
The default export can be used for, among other things, modifying the named
398
398
exports. Named exports of builtin modules are updated only by calling
@@ -449,11 +449,11 @@ and are loaded using the CJS loader. [WHATWG JSON modules specification][] are
449
449
still being standardized, and are experimentally supported by including the
450
450
additional flag ` -- experimental- json- modules` when running Node.js.
451
451
452
- When the ` -- experimental- json- modules` flag is included both the
453
- ` commonjs` and ` module ` mode will use the new experimental JSON
454
- loader. The imported JSON only exposes a ` default` , there is no
452
+ When the ` -- experimental- json- modules` flag is included, both the
453
+ ` commonjs` and ` module ` mode use the new experimental JSON
454
+ loader. The imported JSON only exposes a ` default` . There is no
455
455
support for named exports. A cache entry is created in the CommonJS
456
- cache, to avoid duplication. The same object will be returned in
456
+ cache to avoid duplication. The same object is returned in
457
457
CommonJS if the JSON module has already been imported from the
458
458
same path.
459
459
@@ -533,7 +533,7 @@ The `conditions` property on the `context` is an array of conditions for
533
533
for looking up conditional mappings elsewhere or to modify the list when calling
534
534
the default resolution logic.
535
535
536
- The current [package exports conditions][Conditional Exports] will always be in
536
+ The current [package exports conditions][Conditional Exports] are always in
537
537
the ` context.conditions` array passed into the hook. To guarantee _default
538
538
Node.js module specifier resolution behavior_ when calling ` defaultResolve` , the
539
539
` context.conditions` array passed to it _must_ include _all_ elements of the
@@ -604,7 +604,7 @@ Note: These types all correspond to classes defined in ECMAScript.
604
604
* The specific [` TypedArray` ][] object is a [` Uint8Array ` ][].
605
605
606
606
Note: If the source value of a text-based format (i.e., ` ' json' ` , ` ' module' ` ) is
607
- not a string, it will be converted to a string using [` util .TextDecoder ` ][].
607
+ not a string, it is converted to a string using [` util .TextDecoder ` ][].
608
608
609
609
` ` ` js
610
610
/**
@@ -719,15 +719,15 @@ export async function transformSource(source, context, defaultTransformSource) {
719
719
720
720
* Returns: {string}
721
721
722
- Sometimes it can be necessary to run some code inside of the same global scope
723
- that the application will run in. This hook allows to return a string that will
724
- be ran as sloppy-mode script on startup.
722
+ Sometimes it might be necessary to run some code inside of the same global scope
723
+ that the application runs in. This hook allows the return of a string that is
724
+ run as sloppy-mode script on startup.
725
725
726
726
Similar to how CommonJS wrappers work, the code runs in an implicit function
727
727
scope. The only argument is a ` require` -like function that can be used to load
728
728
builtins like "fs": ` getBuiltin (request: string)` .
729
729
730
- If the code needs more advanced ` require` features, it will have to construct
730
+ If the code needs more advanced ` require` features, it has to construct
731
731
its own ` require` using ` module .createRequire ()` .
732
732
733
733
` ` ` js
@@ -854,13 +854,9 @@ import { VERSION } from 'https://coffeescript.org/browser-compiler-modern/coffee
854
854
console.log(VERSION);
855
855
` ` `
856
856
857
- With this loader, running:
858
-
859
- ` ` ` bash
860
- node --experimental-loader ./https-loader.mjs ./main.mjs
861
- ` ` `
862
-
863
- Will print the current version of CoffeeScript per the module at the URL in
857
+ With the preceding loader, running
858
+ ` node --experimental-loader ./https-loader.mjs ./main.mjs`
859
+ prints the current version of CoffeeScript per the module at the URL in
864
860
` main.mjs` .
865
861
866
862
#### Transpiler loader
@@ -941,13 +937,9 @@ console.log "Brought to you by Node.js version #{version}"
941
937
export scream = (str) -> str.toUpperCase()
942
938
` ` `
943
939
944
- With this loader, running:
945
-
946
- ` ` ` console
947
- node --experimental-loader ./coffeescript-loader.mjs main.coffee
948
- ` ` `
949
-
950
- Will cause ` main.coffee` to be turned into JavaScript after its source code is
940
+ With the preceding loader, running
941
+ ` node --experimental-loader ./coffeescript-loader.mjs main.coffee`
942
+ causes ` main.coffee` to be turned into JavaScript after its source code is
951
943
loaded from disk but before Node .js executes it; and so on for any ` .coffee` ,
952
944
` .litcoffee` or ` .coffee.md` files referenced via ` import` statements of any
953
945
loaded file.
0 commit comments