Skip to content

Commit

Permalink
doc: revise data imports and node: imports sections
Browse files Browse the repository at this point in the history
Revise for conformance with style guide and clarity.

PR-URL: nodejs#42734
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Mohammed Keyvanzadeh <mohammadkeyvanzade94@gmail.com>
  • Loading branch information
Trott authored and xtx1130 committed Apr 25, 2022
1 parent 8402a9c commit 8a6cfae
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions doc/api/esm.md
Expand Up @@ -178,32 +178,31 @@ The volume root may be referenced via `/`, `//` or `file:///`. Given the
differences between [URL][] and path resolution (such as percent encoding
details), it is recommended to use [url.pathToFileURL][] when importing a path.

#### `data:` Imports
#### `data:` imports

<!-- YAML
added: v12.10.0
-->

[`data:` URLs][] are supported for importing with the following MIME types:

* `text/javascript` for ES Modules
* `text/javascript` for ES modules
* `application/json` for JSON
* `application/wasm` for Wasm

`data:` URLs only resolve [_Bare specifiers_][Terminology] for builtin modules
and [_Absolute specifiers_][Terminology]. Resolving
[_Relative specifiers_][Terminology] does not work because `data:` is not a
[special scheme][]. For example, attempting to load `./foo`
from `data:text/javascript,import "./foo";` fails to resolve because there
is no concept of relative resolution for `data:` URLs. An example of a `data:`
URLs being used is:

```js
import 'data:text/javascript,console.log("hello!");';
import _ from 'data:application/json,"world!"' assert { type: 'json' };
```

#### `node:` Imports
`data:` URLs only resolve [bare specifiers][Terminology] for builtin modules
and [absolute specifiers][Terminology]. Resolving
[relative specifiers][Terminology] does not work because `data:` is not a
[special scheme][]. For example, attempting to load `./foo`
from `data:text/javascript,import "./foo";` fails to resolve because there
is no concept of relative resolution for `data:` URLs.

#### `node:` imports

<!-- YAML
added:
Expand Down

0 comments on commit 8a6cfae

Please sign in to comment.