@@ -122,13 +122,13 @@ added: v12.10.0
122
122
123
123
* ` text/javascript ` for ES Modules
124
124
* ` application/json ` for JSON
125
- * ` application/wasm ` for WASM.
125
+ * ` application/wasm ` for Wasm
126
126
127
127
` data: ` URLs only resolve [ _ Bare specifiers_ ] [ Terminology ] for builtin modules
128
128
and [ _ Absolute specifiers_ ] [ Terminology ] . Resolving
129
- [ _ Relative specifiers_ ] [ Terminology ] will not work because ` data: ` is not a
129
+ [ _ Relative specifiers_ ] [ Terminology ] does not work because ` data: ` is not a
130
130
[ special scheme] [ ] . For example, attempting to load ` ./foo `
131
- from ` data:text/javascript,import "./foo"; ` will fail to resolve since there
131
+ from ` data:text/javascript,import "./foo"; ` fails to resolve because there
132
132
is no concept of relative resolution for ` data: ` URLs. An example of a ` data: `
133
133
URLs being used is:
134
134
@@ -200,7 +200,7 @@ from which to resolve from:
200
200
})();
201
201
` ` `
202
202
203
- This function is asynchronous since the ES module resolver in Node.js is
203
+ This function is asynchronous because the ES module resolver in Node.js is
204
204
asynchronous. With the introduction of [Top-Level Await][], these use cases
205
205
will be easier as they won't require an async function wrapper.
206
206
@@ -219,8 +219,8 @@ ES modules are resolved and cached based upon
219
219
[URL](https://url.spec.whatwg.org/) semantics. This means that files containing
220
220
special characters such as ` #` and ` ?` need to be escaped.
221
221
222
- Modules will be loaded multiple times if the ` import` specifier used to resolve
223
- them have a different query or fragment.
222
+ Modules are loaded multiple times if the ` import` specifier used to resolve
223
+ them has a different query or fragment.
224
224
225
225
` ` ` js
226
226
import ' ./foo.mjs?query=1' ; // loads ./foo.mjs with query of "?query=1"
@@ -295,8 +295,8 @@ console.log(cjs === cjsSugar);
295
295
// true
296
296
` ` `
297
297
298
- The ECMAScript Module Namespace representation of a CommonJS module will always
299
- be a namespace with a ` default` export key pointing to the CommonJS
298
+ The ECMAScript Module Namespace representation of a CommonJS module is always
299
+ a namespace with a ` default` export key pointing to the CommonJS
300
300
` module .exports ` value.
301
301
302
302
This Module Namespace Exotic Object can be directly observed either when using
@@ -312,19 +312,19 @@ console.log(m === await import('cjs'));
312
312
// true
313
313
` ` `
314
314
315
- For better compatibility with existing usage in the JS ecosystem, Node.js will
316
- in addition attempt to determine the CommonJS named exports of every imported
315
+ For better compatibility with existing usage in the JS ecosystem, Node.js
316
+ in addition attempts to determine the CommonJS named exports of every imported
317
317
CommonJS module to provide them as separate ES module exports using a static
318
318
analysis process.
319
319
320
- For example, a CommonJS module written:
320
+ For example, consider a CommonJS module written:
321
321
322
322
` ` ` js
323
323
// cjs.cjs
324
324
exports .name = ' exported' ;
325
325
` ` `
326
326
327
- will support named imports in ES modules:
327
+ The preceding module supports named imports in ES modules:
328
328
329
329
<!-- eslint-disable no-duplicate-imports -->
330
330
` ` ` js
@@ -348,8 +348,8 @@ directly on the ES module namespace when the module is imported.
348
348
Live binding updates or new exports added to ` module .exports ` are not detected
349
349
for these named exports.
350
350
351
- The detection of named exports is based on common syntax patterns but will not
352
- always correctly detect named exports, in these cases using the default
351
+ The detection of named exports is based on common syntax patterns but does not
352
+ always correctly detect named exports. In these cases, using the default
353
353
import form described above can be a better option.
354
354
355
355
Named exports detection covers many common export patterns, reexport patterns
@@ -358,7 +358,7 @@ semantics implemented.
358
358
359
359
## Builtin modules
360
360
361
- [Core modules][] will provide named exports of their public API. A
361
+ [Core modules][] provide named exports of their public API. A
362
362
default export is also provided which is the value of the CommonJS exports.
363
363
The default export can be used for, among other things, modifying the named
364
364
exports. Named exports of builtin modules are updated only by calling
@@ -415,11 +415,11 @@ and are loaded using the CJS loader. [WHATWG JSON modules specification][] are
415
415
still being standardized, and are experimentally supported by including the
416
416
additional flag ` -- experimental- json- modules` when running Node.js.
417
417
418
- When the ` -- experimental- json- modules` flag is included both the
419
- ` commonjs` and ` module ` mode will use the new experimental JSON
420
- loader. The imported JSON only exposes a ` default` , there is no
418
+ When the ` -- experimental- json- modules` flag is included, both the
419
+ ` commonjs` and ` module ` mode use the new experimental JSON
420
+ loader. The imported JSON only exposes a ` default` . There is no
421
421
support for named exports. A cache entry is created in the CommonJS
422
- cache, to avoid duplication. The same object will be returned in
422
+ cache to avoid duplication. The same object is returned in
423
423
CommonJS if the JSON module has already been imported from the
424
424
same path.
425
425
@@ -523,7 +523,7 @@ The `conditions` property on the `context` is an array of conditions for
523
523
for looking up conditional mappings elsewhere or to modify the list when calling
524
524
the default resolution logic.
525
525
526
- The current [package exports conditions][Conditional Exports] will always be in
526
+ The current [package exports conditions][Conditional Exports] are always in
527
527
the ` context.conditions` array passed into the hook. To guarantee _default
528
528
Node.js module specifier resolution behavior_ when calling ` defaultResolve` , the
529
529
` context.conditions` array passed to it _must_ include _all_ elements of the
@@ -593,7 +593,7 @@ Note: These types all correspond to classes defined in ECMAScript.
593
593
* The specific [` TypedArray` ][] object is a [` Uint8Array ` ][].
594
594
595
595
Note: If the source value of a text-based format (i.e., ` ' json' ` , ` ' module' ` ) is
596
- not a string, it will be converted to a string using [` util .TextDecoder ` ][].
596
+ not a string, it is converted to a string using [` util .TextDecoder ` ][].
597
597
598
598
` ` ` js
599
599
/**
@@ -704,15 +704,15 @@ export async function transformSource(source, context, defaultTransformSource) {
704
704
705
705
* Returns: {string}
706
706
707
- Sometimes it can be necessary to run some code inside of the same global scope
708
- that the application will run in. This hook allows to return a string that will
709
- be ran as sloppy-mode script on startup.
707
+ Sometimes it might be necessary to run some code inside of the same global scope
708
+ that the application runs in. This hook allows the return of a string that is
709
+ run as sloppy-mode script on startup.
710
710
711
711
Similar to how CommonJS wrappers work, the code runs in an implicit function
712
712
scope. The only argument is a ` require` -like function that can be used to load
713
713
builtins like "fs": ` getBuiltin (request: string)` .
714
714
715
- If the code needs more advanced ` require` features, it will have to construct
715
+ If the code needs more advanced ` require` features, it has to construct
716
716
its own ` require` using ` module .createRequire ()` .
717
717
718
718
` ` ` js
@@ -807,13 +807,9 @@ import { VERSION } from 'https://coffeescript.org/browser-compiler-modern/coffee
807
807
console.log(VERSION);
808
808
` ` `
809
809
810
- With this loader, running:
811
-
812
- ` ` ` bash
813
- node --experimental-loader ./https-loader.mjs ./main.mjs
814
- ` ` `
815
-
816
- Will print the current version of CoffeeScript per the module at the URL in
810
+ With the preceding loader, running
811
+ ` node --experimental-loader ./https-loader.mjs ./main.mjs`
812
+ prints the current version of CoffeeScript per the module at the URL in
817
813
` main.mjs` .
818
814
819
815
#### Transpiler loader
@@ -894,13 +890,9 @@ console.log "Brought to you by Node.js version #{version}"
894
890
export scream = (str) -> str.toUpperCase()
895
891
` ` `
896
892
897
- With this loader, running:
898
-
899
- ` ` ` console
900
- node --experimental-loader ./coffeescript-loader.mjs main.coffee
901
- ` ` `
902
-
903
- Will cause ` main.coffee` to be turned into JavaScript after its source code is
893
+ With the preceding loader, running
894
+ ` node --experimental-loader ./coffeescript-loader.mjs main.coffee`
895
+ causes ` main.coffee` to be turned into JavaScript after its source code is
904
896
loaded from disk but before Node .js executes it; and so on for any ` .coffee` ,
905
897
` .litcoffee` or ` .coffee.md` files referenced via ` import` statements of any
906
898
loaded file.
0 commit comments