From fbb217a29dc0c54799bb0c268eea52be4fff6486 Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Mon, 23 Dec 2019 21:32:25 -0800 Subject: [PATCH] doc,esm: use code markup/markdown in headers PR-URL: https://github.com/nodejs/node/pull/31086 Reviewed-By: Anna Henningsen Reviewed-By: Ruben Bridgewater --- doc/api/esm.md | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/doc/api/esm.md b/doc/api/esm.md index 85f7b2d28dd054..4898edfc3a95a0 100644 --- a/doc/api/esm.md +++ b/doc/api/esm.md @@ -57,7 +57,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`. -### package.json "type" 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 @@ -159,7 +159,7 @@ package scope: extension (since both `.js` and `.cjs` files are treated as CommonJS within a `"commonjs"` package scope). -### --input-type 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 @@ -190,7 +190,7 @@ defined in `"exports"`. If package entry points are defined in both `"main"` and `"exports"`. [Conditional Exports][] can also be used within `"exports"` to define different package entry points per environment. -#### package.json "main" +#### `package.json` `"main"` The `package.json` `"main"` field defines the entry point for a package, whether the package is included into CommonJS via `require` or into an ES @@ -710,7 +710,7 @@ If the `--experimental-conditional-exports` flag is dropped and therefore easily updated to use conditional exports by adding conditions to the `"."` path; while keeping `"./module"` for backward compatibility. -## import Specifiers +## `import` Specifiers ### Terminology @@ -767,7 +767,7 @@ import 'data:text/javascript,console.log("hello!");'; import _ from 'data:application/json,"world!"'; ``` -## import.meta +## `import.meta` * {Object} @@ -786,12 +786,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 NODE_PATH +### No `NODE_PATH` `NODE_PATH` is not part of resolving `import` specifiers. Please use symlinks if this behavior is desired. -### No require, exports, module.exports, \_\_filename, \_\_dirname +### No `require`, `exports`, `module.exports`, `__filename`, `__dirname` These CommonJS variables are not available in ES modules. @@ -808,12 +808,12 @@ const __filename = fileURLToPath(import.meta.url); const __dirname = dirname(__filename); ``` -### No require.extensions +### No `require.extensions` `require.extensions` is not used by `import`. The expectation is that loader hooks can provide this workflow in the future. -### No require.cache +### No `require.cache` `require.cache` is not used by `import`. It has a separate cache. @@ -835,7 +835,7 @@ For now, only modules using the `file:` protocol can be loaded. ## Interoperability with CommonJS -### require +### `require` `require` always treats the files it references as CommonJS. This applies whether `require` is used the traditional way within a CommonJS environment, or @@ -843,7 +843,7 @@ in an ES module environment using [`module.createRequire()`][]. To include an ES module into CommonJS, use [`import()`][]. -### import statements +### `import` statements An `import` statement can reference an ES module or a CommonJS module. Other file types such as JSON or Native modules are not supported. For those, use @@ -874,7 +874,7 @@ import packageMain from 'commonjs-package'; // Works import { method } from 'commonjs-package'; // Errors ``` -### import() 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.