Skip to content

Commit

Permalink
[moduleResolution bundler] List restrictions from initial PR in docum…
Browse files Browse the repository at this point in the history
…entation (#2976)
  • Loading branch information
Ayc0 authored Nov 15, 2023
1 parent c562844 commit 6f5fdda
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 39 deletions.
4 changes: 2 additions & 2 deletions packages/documentation/scripts/types/AllFilenames.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ export type AllDocsPages =
| "modules-reference/Reference.md"
| "modules-reference/Theory.md"
| "modules-reference/appendices/ESM-CJS-Interop.md"
| "modules-reference/diagrams/README"
| "modules-reference/diagrams/declaration-files.svg"
| "modules-reference/diagrams/esm-cjs-interop.md"
| "modules-reference/diagrams/esm-cjs-interop.mmd-1.svg"
| "modules-reference/diagrams/esm-cjs-interop.mmd-2.svg"
| "modules-reference/diagrams/README"
| "modules-reference/diagrams/theory.md"
| "modules-reference/diagrams/theory.md-1.svg"
| "modules-reference/diagrams/theory.md-2.svg"
Expand Down Expand Up @@ -124,8 +124,8 @@ export type AllDocsPages =
| "release-notes/TypeScript 5.0.md"
| "release-notes/TypeScript 5.1.md"
| "release-notes/TypeScript 5.2.md"
| "tutorials/Angular.md"
| "tutorials/ASP.NET Core.md"
| "tutorials/Angular.md"
| "tutorials/Babel with TypeScript.md"
| "tutorials/DOM Manipulation.md"
| "tutorials/Gulp.md"
Expand Down
74 changes: 37 additions & 37 deletions packages/ts-twoslasher/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,43 @@ Turns to:
> }
> ```
#### `import_files.ts`
```ts
// @filename: file-with-export.ts
export const helloWorld = "Example string"
// @filename: index.ts
import { helloWorld } from "./file-with-export"
console.log(helloWorld)
```
Turns to:
> ```ts
> // @filename: file-with-export.ts
> export const helloWorld = "Example string"
>
> // @filename: index.ts
> import { helloWorld } from "./file-with-export"
> console.log(helloWorld)
> ```
> With:
> ```json
> {
> "code": "See above",
> "extension": "ts",
> "highlights": [],
> "queries": [],
> "staticQuickInfos": "[ 5 items ]",
> "errors": [],
> "playgroundURL": "https://www.typescriptlang.org/play/#code/PTAEAEDMEsBsFMB2BDAtvAXKGCC0B3aAFwAtd4APABwHsAnIgOiIGcAoS2h0AYxsRZFQJeLFg0A6vVgATUAF5QAIgCiFNFQShBdaIgDmSgNxs2ICDiRpMoPTMrN20VFyEBvEWMnSZAX2x0NKjKjMCWBMRknPRESmx8AjQIjOL6ABSe4lJ0sgCUbEA",
> "tags": []
> }
> ```
#### `importsModules.ts`
```ts
Expand Down Expand Up @@ -636,43 +673,6 @@ Turns to:
> }
> ```
#### `import_files.ts`
```ts
// @filename: file-with-export.ts
export const helloWorld = "Example string"
// @filename: index.ts
import { helloWorld } from "./file-with-export"
console.log(helloWorld)
```
Turns to:
> ```ts
> // @filename: file-with-export.ts
> export const helloWorld = "Example string"
>
> // @filename: index.ts
> import { helloWorld } from "./file-with-export"
> console.log(helloWorld)
> ```
> With:
> ```json
> {
> "code": "See above",
> "extension": "ts",
> "highlights": [],
> "queries": [],
> "staticQuickInfos": "[ 5 items ]",
> "errors": [],
> "playgroundURL": "https://www.typescriptlang.org/play/#code/PTAEAEDMEsBsFMB2BDAtvAXKGCC0B3aAFwAtd4APABwHsAnIgOiIGcAoS2h0AYxsRZFQJeLFg0A6vVgATUAF5QAIgCiFNFQShBdaIgDmSgNxs2ICDiRpMoPTMrN20VFyEBvEWMnSZAX2x0NKjKjMCWBMRknPRESmx8AjQIjOL6ABSe4lJ0sgCUbEA",
> "tags": []
> }
> ```
#### `multiFileErrors.ts`
```ts
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ Specify the module resolution strategy:
- `'node16'` or `'nodenext'` for modern versions of Node.js. Node.js v12 and later supports both ECMAScript imports and CommonJS `require`, which resolve using different algorithms. These `moduleResolution` values, when combined with the corresponding [`module`](#module) values, picks the right algorithm for each resolution based on whether Node.js will see an `import` or `require` in the output JavaScript code.
- `'node10'` (previously called `'node'`) for Node.js versions older than v10, which only support CommonJS `require`. You probably won't need to use `node10` in modern code.
- `'bundler'` for use with bundlers. Like `node16` and `nodenext`, this mode supports package.json `"imports"` and `"exports"`, but unlike the Node.js resolution modes, `bundler` never requires file extensions on relative paths in imports.

`bundler` does not support resolution of `require` calls. In TypeScript files, this means the `import mod = require("foo")` syntax is forbidden; in JavaScript files, `require` calls are not errors but only ever return the type `any` (or whatever an ambient declaration of a global require function is declared to `return`).

- `'classic'` was used in TypeScript before the release of 1.6. `classic` should not be used.

There is a handbook reference page on [Module Resolution](/docs/handbook/module-resolution.html)

0 comments on commit 6f5fdda

Please sign in to comment.