1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-24 15:19:26 -05:00
denoland-deno/cli
Yusuke Tanaka 0ea71abdef
fix(cli): handle edge cases around exports in doc tests and default export (#25720)
This commit fixes issues with the pseudo test file generation logic,
namely:

- `export`s declared in snippets
- auto import insertion for `default export`

## Case 1: `export`s declared in snippets

In the previous implementation, `export`s declared in snippets were
moved to the top level of the module in the generated pseudo test file.
This is required because `export` must be at the top level.

This becomes a problem if such a `export` has a body, containing a
reference to a local variable. Suppose we extract this snippet from
JSDoc:

```ts
const logger = createLogger("my-awesome-module");

export function sum(a: number, b: number): number {
  logger.debug("sum called");
  return a + b;
}
```

This gets converted into the following invalid code (note that `export
function sum` is moved to the top level, but its body references
`logger` variable which can't be referenced from here):

```ts
export function sum(a: number, b: number): number {
  logger.debug("sum called");
  return a + b;
}

Deno.test("./base.ts$1-7.ts", async () => {
  const logger = createLogger("my-awesome-module");
});
```

To resolve this issue, this commit adds a logic to remove the `export`
keyword, allowing the exported items to stay in the `Deno.test` block
scope, like so:

```ts
Deno.test("./base.ts$1-7.ts", async () => {
  const logger = createLogger("my-awesome-module");

  function sum(a: number, b: number): number {
    logger.debug("sum called");
    return a + b;
  }
});
```

## Case 2: default export

Previously `default export foo` was not captured by the export
collector, so auto import insertion didn't work for this case. To put it
concretely, the following code snippet didn't work when run with `deno
test --doc` because `import foo from "file:///path/to/mod.ts"` didn't
get inserted automatically:

```ts
/**
 * ```ts
 * console.log(foo);
 * ```
 * 
 * @module
 */

const foo = 42;
export default foo;
```

This commit fixes this issue and the above example works fine.

---

Fixes #25718
2024-09-19 00:19:40 -07:00
..
args feat: suggest deno install --entrypoint instead of deno cache (#25228) 2024-09-18 19:55:50 +00:00
bench bench: fix CI (#25547) 2024-09-10 00:19:49 +00:00
cache feat: default to TS for file extension and support ext flag in more scenarios (#25472) 2024-09-18 21:15:13 +02:00
js refactor(cli/js): align error messages (#25406) 2024-09-04 09:19:55 +02:00
lsp feat: suggest deno install --entrypoint instead of deno cache (#25228) 2024-09-18 19:55:50 +00:00
napi chore: forward v1.46.3 release commit to main (#25425) 2024-09-04 17:16:24 +00:00
npm feat: improve warnings for deprecations and lifecycle script for npm packages (#25694) 2024-09-18 19:04:25 +00:00
ops refactor(permissions): split up Descriptor into Allow, Deny, and Query (#25508) 2024-09-16 21:39:37 +01:00
schemas fix: update nodeModulesDir config JSON schema (#25653) 2024-09-18 22:38:09 +02:00
standalone chore: remove warnOnDeprecatedApi() (#25673) 2024-09-16 23:43:36 +00:00
tools feat: default to TS for file extension and support ext flag in more scenarios (#25472) 2024-09-18 21:15:13 +02:00
tsc feat(check): turn on noImplicitOverride (#25695) 2024-09-18 14:49:30 +01:00
util fix(cli): handle edge cases around exports in doc tests and default export (#25720) 2024-09-19 00:19:40 -07:00
auth_tokens.rs fix: trim space around DENO_AUTH_TOKENS (#25147) 2024-08-22 15:14:50 +02:00
build.rs feat: TypeScript 5.6 and npm:@types/node@22 (#25614) 2024-09-14 11:58:47 +01:00
Cargo.toml v2.0.0-rc.3 (#25704) 2024-09-18 23:21:45 +02:00
cdp.rs chore: upgrade to rust 1.79 (#24207) 2024-06-14 17:10:57 +05:30
clippy.toml refactor(lsp): changes for lsp_types 0.97.0 (#25169) 2024-08-24 01:21:21 +01:00
deno.ico fix(cli): add icon and metadata to deno.exe on Windows (#6693) 2020-07-15 21:54:38 +02:00
emit.rs feat: deprecate import assertions (#25281) 2024-08-29 01:06:09 +00:00
entitlements.plist chore: start codesigning mac release builds (#21303) 2023-11-23 15:30:26 -07:00
errors.rs fix(compile): support workspace members importing other members (#24909) 2024-08-07 07:43:05 +00:00
factory.rs chore: upgrade deno_core (#25674) 2024-09-17 01:13:34 +00:00
file_fetcher.rs feat: default to TS for file extension and support ext flag in more scenarios (#25472) 2024-09-18 21:15:13 +02:00
graph_container.rs feat: default to TS for file extension and support ext flag in more scenarios (#25472) 2024-09-18 21:15:13 +02:00
graph_util.rs fix: do not panic running invalid file specifier (#25530) 2024-09-18 14:51:39 +01:00
http_util.rs refactor: version module exports a single const struct (#25014) 2024-08-15 23:47:16 +02:00
integration_tests_runner.rs chore: continue tests/ re-org (#22396) 2024-02-12 17:13:14 -07:00
js.rs chore: rename __runtime_js_source to hmr (#24442) 2024-07-05 17:47:53 +05:30
jsr.rs refactor(permissions): split up Descriptor into Allow, Deny, and Query (#25508) 2024-09-16 21:39:37 +01:00
main.rs feat(cli): evaluate code snippets in JSDoc and markdown (#25220) 2024-09-17 21:35:48 -07:00
mainrt.rs fix(cli): update permission prompt message for compiled binaries (#24081) 2024-08-20 01:20:06 +00:00
module_loader.rs feat: default to TS for file extension and support ext flag in more scenarios (#25472) 2024-09-18 21:15:13 +02:00
node.rs refactor: decouple node resolution from deno_core (#24724) 2024-07-25 19:08:14 -04:00
README.md docs(cli): do not need gen doc for cli (#17260) 2023-01-04 13:19:58 +01:00
resolver.rs fix(node/byonm): do not accidentally resolve bare node built-ins (#25543) 2024-09-09 21:35:41 +00:00
shared.rs chore: Rust 1.80.1 (#25089) 2024-08-18 22:24:56 -04:00
task_runner.rs fix: lock down allow-run permissions more (#25370) 2024-09-04 14:51:24 +02:00
version.rs build: Allow building 'rc' release from source (#25227) 2024-08-28 14:31:25 +00:00
worker.rs refactor(permissions): split up Descriptor into Allow, Deny, and Query (#25508) 2024-09-16 21:39:37 +01:00

Deno CLI Crate

crates

This provides the actual deno executable and the user-facing APIs.

The deno crate uses the deno_core to provide the executable.