Skip to content

Commit

Permalink
doc,esm: use code markup/markdown in headers
Browse files Browse the repository at this point in the history
Backport-PR-URL: #31108
PR-URL: #31086
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
  • Loading branch information
Trott authored and BethGriggs committed Feb 6, 2020
1 parent 69da611 commit c4503ea
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions doc/api/esm.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ or when referenced by `import` statements within ES module code:
* Strings passed in as an argument to `--eval` or `--print`, or piped to
`node` via `STDIN`, with the flag `--input-type=commonjs`.

### <code>package.json</code> <code>"type"</code> field
### `package.json` `"type"` field

Files ending with `.js` or `.mjs`, or lacking any extension,
will be loaded as ES modules when the nearest parent `package.json` file
Expand Down Expand Up @@ -162,7 +162,7 @@ package scope:
extension (since both `.js` and `.cjs` files are treated as CommonJS within a
`"commonjs"` package scope).

### <code>--input-type</code> flag
### `--input-type` flag

Strings passed in as an argument to `--eval` or `--print` (or `-e` or `-p`), or
piped to `node` via `STDIN`, will be treated as ES modules when the
Expand Down Expand Up @@ -358,7 +358,7 @@ in order to be forward-compatible with fallback workflows in future:
Since `"not:valid"` is not a supported target, `"./submodule.js"` is used
instead as the fallback, as if it were the only target.

## <code>import</code> Specifiers
## `import` Specifiers

### Terminology

Expand Down Expand Up @@ -415,7 +415,7 @@ import 'data:text/javascript,console.log("hello!");';
import _ from 'data:application/json,"world!"';
```

## import.meta
## `import.meta`

* {Object}

Expand All @@ -434,12 +434,12 @@ indexes (e.g. `'./startup/index.js'`) must also be fully specified.
This behavior matches how `import` behaves in browser environments, assuming a
typically configured server.

### No <code>NODE_PATH</code>
### No `NODE_PATH`

`NODE_PATH` is not part of resolving `import` specifiers. Please use symlinks
if this behavior is desired.

### No <code>require</code>, <code>exports</code>, <code>module.exports</code>, <code>\_\_filename</code>, <code>\_\_dirname</code>
### No `require`, `exports`, `module.exports`, `__filename`, `__dirname`

These CommonJS variables are not available in ES modules.

Expand All @@ -456,12 +456,12 @@ const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
```
### No <code>require.extensions</code>
### No `require.extensions`
`require.extensions` is not used by `import`. The expectation is that loader
hooks can provide this workflow in the future.
### No <code>require.cache</code>
### No `require.cache`
`require.cache` is not used by `import`. It has a separate cache.
Expand All @@ -483,15 +483,15 @@ For now, only modules using the `file:` protocol can be loaded.
## Interoperability with CommonJS
### <code>require</code>
### `require`
`require` always treats the files it references as CommonJS. This applies
whether `require` is used the traditional way within a CommonJS environment, or
in an ES module environment using [`module.createRequire()`][].
To include an ES module into CommonJS, use [`import()`][].
### <code>import</code> statements
### `import` statements
An `import` statement can reference an ES module, a CommonJS module, or JSON.
Other file types such as Native modules are not supported. For those,
Expand Down Expand Up @@ -523,7 +523,7 @@ import { sin, cos } from 'geometry/trigonometry-functions.mjs';
>
> There are ongoing efforts to make the latter code possible.
### <code>import()</code> expressions
### `import()` expressions
Dynamic `import()` is supported in both CommonJS and ES modules. It can be used
to include ES module files from CommonJS code.
Expand Down

0 comments on commit c4503ea

Please sign in to comment.