2024-01-01 14:58:21 -05:00
|
|
|
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
2022-11-28 17:28:54 -05:00
|
|
|
|
|
|
|
// Note: Only add code in this folder that has no application specific logic
|
2024-08-08 03:19:05 -04:00
|
|
|
pub mod archive;
|
2022-11-28 17:28:54 -05:00
|
|
|
pub mod checksum;
|
2022-12-12 20:52:10 -05:00
|
|
|
pub mod console;
|
2022-11-28 17:28:54 -05:00
|
|
|
pub mod diff;
|
|
|
|
pub mod display;
|
2022-12-19 11:19:33 -05:00
|
|
|
pub mod draw_thread;
|
feat(cli): evaluate code snippets in JSDoc and markdown (#25220)
This commit lets `deno test --doc` command actually evaluate code snippets in
JSDoc and markdown files.
## How it works
1. Extract code snippets from JSDoc or code fences
2. Convert them into pseudo files by wrapping them in `Deno.test(...)`
3. Register the pseudo files as in-memory files
4. Run type-check and evaluation
We apply some magic at the step 2 - let's say we have the following file named
`mod.ts` as an input:
````ts
/**
* ```ts
* import { assertEquals } from "jsr:@std/assert/equals";
*
* assertEquals(add(1, 2), 3);
* ```
*/
export function add(a: number, b: number) {
return a + b;
}
````
This is virtually transformed into:
```ts
import { assertEquals } from "jsr:@std/assert/equals";
import { add } from "files:///path/to/mod.ts";
Deno.test("mod.ts$2-7.ts", async () => {
assertEquals(add(1, 2), 3);
});
```
Note that a new import statement is inserted here to make `add` function
available. In a nutshell, all items exported from `mod.ts` become available in
the generated pseudo file with this automatic import insertion.
The intention behind this design is that, from library user's standpoint, it
should be very obvious that this `add` function is what this example code is
attached to. Also, if there is an explicit import statement like
`import { add } from "./mod.ts"`, this import path `./mod.ts` is not helpful for
doc readers because they will need to import it in a different way.
The automatic import insertion has some edge cases, in particular where there is
a local variable in a snippet with the same name as one of the exported items.
This case is addressed by employing swc's scope analysis (see test cases for
more details).
## "type-checking only" mode stays around
This change will likely impact a lot of existing doc tests in the ecosystem
because some doc tests rely on the fact that they are not evaluated - some cause
side effects if executed, some throw errors at runtime although they do pass the
type check, etc. To help those tests gradually transition to the ones runnable
with the new `deno test --doc`, we will keep providing the ability to run
type-checking only via `deno check --doc`. Additionally there is a `--doc-only`
option added to the `check` subcommand too, which is useful when you want to
type-check on code snippets in markdown files, as normal `deno check` command
doesn't accept markdown.
## Demo
https://github.com/user-attachments/assets/47e9af73-d16e-472d-b09e-1853b9e8f5ce
---
Closes #4716
2024-09-18 00:35:48 -04:00
|
|
|
pub mod extract;
|
2022-11-28 17:28:54 -05:00
|
|
|
pub mod file_watcher;
|
|
|
|
pub mod fs;
|
|
|
|
pub mod logger;
|
|
|
|
pub mod path;
|
|
|
|
pub mod progress_bar;
|
2024-05-09 16:49:10 -04:00
|
|
|
pub mod result;
|
2023-04-11 18:10:51 -04:00
|
|
|
pub mod sync;
|
2022-11-28 17:28:54 -05:00
|
|
|
pub mod text_encoding;
|
|
|
|
pub mod unix;
|
2023-01-24 23:03:03 -05:00
|
|
|
pub mod v8;
|
2022-11-28 17:28:54 -05:00
|
|
|
pub mod windows;
|