Skip to content

Commit 95c62a1

Browse files
Trottdanielleadams
authored andcommitted
doc: copyedit esm.md
This provides a number of minor style adjustments and small corrections to esm.md text. Co-authored-by: Guy Bedford <[email protected]> PR-URL: #35414 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Guy Bedford <[email protected]> Reviewed-By: Derek Lewis <[email protected]> Reviewed-By: Geoffrey Booth <[email protected]>
1 parent 86f2f83 commit 95c62a1

File tree

1 file changed

+31
-39
lines changed

1 file changed

+31
-39
lines changed

doc/api/esm.md

+31-39
Original file line numberDiff line numberDiff line change
@@ -122,13 +122,13 @@ added: v12.10.0
122122

123123
* `text/javascript` for ES Modules
124124
* `application/json` for JSON
125-
* `application/wasm` for WASM.
125+
* `application/wasm` for Wasm
126126

127127
`data:` URLs only resolve [_Bare specifiers_][Terminology] for builtin modules
128128
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
130130
[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
132132
is no concept of relative resolution for `data:` URLs. An example of a `data:`
133133
URLs being used is:
134134

@@ -200,7 +200,7 @@ from which to resolve from:
200200
})();
201201
```
202202
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
204204
asynchronous. With the introduction of [Top-Level Await][], these use cases
205205
will be easier as they won't require an async function wrapper.
206206
@@ -219,8 +219,8 @@ ES modules are resolved and cached based upon
219219
[URL](https://url.spec.whatwg.org/) semantics. This means that files containing
220220
special characters such as `#` and `?` need to be escaped.
221221
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.
224224
225225
```js
226226
import './foo.mjs?query=1'; // loads ./foo.mjs with query of "?query=1"
@@ -295,8 +295,8 @@ console.log(cjs === cjsSugar);
295295
// true
296296
```
297297
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
300300
`module.exports` value.
301301
302302
This Module Namespace Exotic Object can be directly observed either when using
@@ -312,19 +312,19 @@ console.log(m === await import('cjs'));
312312
// true
313313
```
314314
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
317317
CommonJS module to provide them as separate ES module exports using a static
318318
analysis process.
319319
320-
For example, a CommonJS module written:
320+
For example, consider a CommonJS module written:
321321
322322
```js
323323
// cjs.cjs
324324
exports.name = 'exported';
325325
```
326326
327-
will support named imports in ES modules:
327+
The preceding module supports named imports in ES modules:
328328
329329
<!-- eslint-disable no-duplicate-imports -->
330330
```js
@@ -348,8 +348,8 @@ directly on the ES module namespace when the module is imported.
348348
Live binding updates or new exports added to `module.exports` are not detected
349349
for these named exports.
350350
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
353353
import form described above can be a better option.
354354
355355
Named exports detection covers many common export patterns, reexport patterns
@@ -358,7 +358,7 @@ semantics implemented.
358358
359359
## Builtin modules
360360
361-
[Core modules][] will provide named exports of their public API. A
361+
[Core modules][] provide named exports of their public API. A
362362
default export is also provided which is the value of the CommonJS exports.
363363
The default export can be used for, among other things, modifying the named
364364
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
415415
still being standardized, and are experimentally supported by including the
416416
additional flag `--experimental-json-modules` when running Node.js.
417417
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
421421
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
423423
CommonJS if the JSON module has already been imported from the
424424
same path.
425425
@@ -523,7 +523,7 @@ The `conditions` property on the `context` is an array of conditions for
523523
for looking up conditional mappings elsewhere or to modify the list when calling
524524
the default resolution logic.
525525
526-
The current [package exports conditions][Conditional Exports] will always be in
526+
The current [package exports conditions][Conditional Exports] are always in
527527
the `context.conditions` array passed into the hook. To guarantee _default
528528
Node.js module specifier resolution behavior_ when calling `defaultResolve`, the
529529
`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.
593593
* The specific [`TypedArray`][] object is a [`Uint8Array`][].
594594
595595
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`][].
597597
598598
```js
599599
/**
@@ -704,15 +704,15 @@ export async function transformSource(source, context, defaultTransformSource) {
704704
705705
* Returns: {string}
706706
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.
710710
711711
Similar to how CommonJS wrappers work, the code runs in an implicit function
712712
scope. The only argument is a `require`-like function that can be used to load
713713
builtins like "fs": `getBuiltin(request: string)`.
714714
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
716716
its own `require` using `module.createRequire()`.
717717
718718
```js
@@ -807,13 +807,9 @@ import { VERSION } from 'https://coffeescript.org/browser-compiler-modern/coffee
807807
console.log(VERSION);
808808
```
809809

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
817813
`main.mjs`.
818814

819815
#### Transpiler loader
@@ -894,13 +890,9 @@ console.log "Brought to you by Node.js version #{version}"
894890
export scream = (str) -> str.toUpperCase()
895891
```
896892

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
904896
loaded from disk but before Node.js executes it; and so on for any `.coffee`,
905897
`.litcoffee` or `.coffee.md` files referenced via `import` statements of any
906898
loaded file.

0 commit comments

Comments
 (0)