Skip to content

Commit 1a8f3a8

Browse files
TrottMylesBorins
authored andcommittedNov 16, 2020
doc: copyedit esm.md
This provides a number of minor style adjustments and small corrections to esm.md text. Co-authored-by: Guy Bedford <guybedford@gmail.com> PR-URL: #35414 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Guy Bedford <guybedford@gmail.com> Reviewed-By: Derek Lewis <DerekNonGeneric@inf.is> Reviewed-By: Geoffrey Booth <webmaster@geoffreybooth.com>
1 parent d991200 commit 1a8f3a8

File tree

1 file changed

+31
-39
lines changed

1 file changed

+31
-39
lines changed
 

Diff for: ‎doc/api/esm.md

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

157157
* `text/javascript` for ES Modules
158158
* `application/json` for JSON
159-
* `application/wasm` for WASM.
159+
* `application/wasm` for Wasm
160160

161161
`data:` URLs only resolve [_Bare specifiers_][Terminology] for builtin modules
162162
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
164164
[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
166166
is no concept of relative resolution for `data:` URLs. An example of a `data:`
167167
URLs being used is:
168168

@@ -234,7 +234,7 @@ from which to resolve from:
234234
})();
235235
```
236236
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
238238
asynchronous. With the introduction of [Top-Level Await][], these use cases
239239
will be easier as they won't require an async function wrapper.
240240
@@ -253,8 +253,8 @@ ES modules are resolved and cached based upon
253253
[URL](https://url.spec.whatwg.org/) semantics. This means that files containing
254254
special characters such as `#` and `?` need to be escaped.
255255
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.
258258
259259
```js
260260
import './foo.mjs?query=1'; // loads ./foo.mjs with query of "?query=1"
@@ -329,8 +329,8 @@ console.log(cjs === cjsSugar);
329329
// true
330330
```
331331
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
334334
`module.exports` value.
335335
336336
This Module Namespace Exotic Object can be directly observed either when using
@@ -346,19 +346,19 @@ console.log(m === await import('cjs'));
346346
// true
347347
```
348348
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
351351
CommonJS module to provide them as separate ES module exports using a static
352352
analysis process.
353353
354-
For example, a CommonJS module written:
354+
For example, consider a CommonJS module written:
355355
356356
```js
357357
// cjs.cjs
358358
exports.name = 'exported';
359359
```
360360
361-
will support named imports in ES modules:
361+
The preceding module supports named imports in ES modules:
362362
363363
<!-- eslint-disable no-duplicate-imports -->
364364
```js
@@ -382,8 +382,8 @@ directly on the ES module namespace when the module is imported.
382382
Live binding updates or new exports added to `module.exports` are not detected
383383
for these named exports.
384384
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
387387
import form described above can be a better option.
388388
389389
Named exports detection covers many common export patterns, reexport patterns
@@ -392,7 +392,7 @@ semantics implemented.
392392
393393
## Builtin modules
394394
395-
[Core modules][] will provide named exports of their public API. A
395+
[Core modules][] provide named exports of their public API. A
396396
default export is also provided which is the value of the CommonJS exports.
397397
The default export can be used for, among other things, modifying the named
398398
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
449449
still being standardized, and are experimentally supported by including the
450450
additional flag `--experimental-json-modules` when running Node.js.
451451
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
455455
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
457457
CommonJS if the JSON module has already been imported from the
458458
same path.
459459
@@ -533,7 +533,7 @@ The `conditions` property on the `context` is an array of conditions for
533533
for looking up conditional mappings elsewhere or to modify the list when calling
534534
the default resolution logic.
535535
536-
The current [package exports conditions][Conditional Exports] will always be in
536+
The current [package exports conditions][Conditional Exports] are always in
537537
the `context.conditions` array passed into the hook. To guarantee _default
538538
Node.js module specifier resolution behavior_ when calling `defaultResolve`, the
539539
`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.
604604
* The specific [`TypedArray`][] object is a [`Uint8Array`][].
605605
606606
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`][].
608608
609609
```js
610610
/**
@@ -719,15 +719,15 @@ export async function transformSource(source, context, defaultTransformSource) {
719719
720720
* Returns: {string}
721721
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.
725725
726726
Similar to how CommonJS wrappers work, the code runs in an implicit function
727727
scope. The only argument is a `require`-like function that can be used to load
728728
builtins like "fs": `getBuiltin(request: string)`.
729729
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
731731
its own `require` using `module.createRequire()`.
732732
733733
```js
@@ -854,13 +854,9 @@ import { VERSION } from 'https://coffeescript.org/browser-compiler-modern/coffee
854854
console.log(VERSION);
855855
```
856856

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
864860
`main.mjs`.
865861

866862
#### Transpiler loader
@@ -941,13 +937,9 @@ console.log "Brought to you by Node.js version #{version}"
941937
export scream = (str) -> str.toUpperCase()
942938
```
943939

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

0 commit comments

Comments
 (0)
Please sign in to comment.