Skip to content

Commit

Permalink
feat: add --no-check option (#6456)
Browse files Browse the repository at this point in the history
This commit adds a "--no-check" option to following subcommands:
- "deno cache"
- "deno info"
- "deno run"
- "deno test"

The "--no-check" options allows to skip type checking step and instead 
directly transpiles TS sources to JS sources. 

This solution uses `ts.transpileModule()` API and is just an interim
solution before implementing it fully in Rust.
  • Loading branch information
kitsonk authored Jul 8, 2020
1 parent 862bc2e commit 82aabb6
Show file tree
Hide file tree
Showing 78 changed files with 567 additions and 200 deletions.
35 changes: 35 additions & 0 deletions cli/flags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ pub struct Flags {
pub lock_write: bool,
pub log_level: Option<Level>,
pub net_allowlist: Vec<String>,
pub no_check: bool,
pub no_prompts: bool,
pub no_remote: bool,
pub read_allowlist: Vec<PathBuf>,
Expand Down Expand Up @@ -453,6 +454,7 @@ fn eval_parse(flags: &mut Flags, matches: &clap::ArgMatches) {
fn info_parse(flags: &mut Flags, matches: &clap::ArgMatches) {
ca_file_arg_parse(flags, matches);
unstable_arg_parse(flags, matches);
no_check_arg_parse(flags, matches);

flags.subcommand = DenoSubcommand::Info {
file: matches.value_of("file").map(|f| f.to_string()),
Expand All @@ -464,6 +466,7 @@ fn cache_parse(flags: &mut Flags, matches: &clap::ArgMatches) {
lock_args_parse(flags, matches);
importmap_arg_parse(flags, matches);
config_arg_parse(flags, matches);
no_check_arg_parse(flags, matches);
no_remote_arg_parse(flags, matches);
ca_file_arg_parse(flags, matches);
unstable_arg_parse(flags, matches);
Expand Down Expand Up @@ -492,6 +495,7 @@ fn run_test_args_parse(flags: &mut Flags, matches: &clap::ArgMatches) {
importmap_arg_parse(flags, matches);
config_arg_parse(flags, matches);
v8_flags_arg_parse(flags, matches);
no_check_arg_parse(flags, matches);
no_remote_arg_parse(flags, matches);
permission_args_parse(flags, matches);
ca_file_arg_parse(flags, matches);
Expand Down Expand Up @@ -818,6 +822,7 @@ TypeScript compiler cache: Subdirectory containing TS compiler output.",
)
.arg(Arg::with_name("file").takes_value(true).required(false))
.arg(ca_file_arg())
.arg(no_check_arg())
.arg(unstable_arg())
}

Expand All @@ -829,6 +834,7 @@ fn cache_subcommand<'a, 'b>() -> App<'a, 'b> {
.arg(importmap_arg())
.arg(unstable_arg())
.arg(config_arg())
.arg(no_check_arg())
.arg(no_remote_arg())
.arg(
Arg::with_name("file")
Expand Down Expand Up @@ -1040,6 +1046,7 @@ fn run_test_args<'a, 'b>(app: App<'a, 'b>) -> App<'a, 'b> {
.arg(config_arg())
.arg(lock_arg())
.arg(lock_write_arg())
.arg(no_check_arg())
.arg(no_remote_arg())
.arg(v8_flags_arg())
.arg(ca_file_arg())
Expand Down Expand Up @@ -1314,6 +1321,18 @@ fn v8_flags_arg_parse(flags: &mut Flags, matches: &ArgMatches) {
}
}

fn no_check_arg<'a, 'b>() -> Arg<'a, 'b> {
Arg::with_name("no-check")
.long("no-check")
.help("Skip type checking modules")
}

fn no_check_arg_parse(flags: &mut Flags, matches: &clap::ArgMatches) {
if matches.is_present("no-check") {
flags.no_check = true;
}
}

fn no_remote_arg<'a, 'b>() -> Arg<'a, 'b> {
Arg::with_name("no-remote")
.long("no-remote")
Expand Down Expand Up @@ -2441,6 +2460,22 @@ mod tests {
}
*/

#[test]
fn no_check() {
let r =
flags_from_vec_safe(svec!["deno", "run", "--no-check", "script.ts"]);
assert_eq!(
r.unwrap(),
Flags {
subcommand: DenoSubcommand::Run {
script: "script.ts".to_string(),
},
no_check: true,
..Flags::default()
}
);
}

#[test]
fn no_remote() {
let r =
Expand Down
29 changes: 18 additions & 11 deletions cli/global_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,17 +170,24 @@ impl GlobalState {
let allow_js = should_allow_js(&module_graph_files);

if should_compile {
self
.ts_compiler
.compile(
self.clone(),
&out,
target_lib,
permissions,
module_graph,
allow_js,
)
.await?;
if self.flags.no_check {
self
.ts_compiler
.transpile(self.clone(), permissions, module_graph)
.await?;
} else {
self
.ts_compiler
.compile(
self.clone(),
&out,
target_lib,
permissions,
module_graph,
allow_js,
)
.await?;
}
}

if let Some(ref lockfile) = self.lockfile {
Expand Down
2 changes: 1 addition & 1 deletion cli/js/buffer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// Copyright 2009 The Go Authors. All rights reserved. BSD license.
// https://github.com/golang/go/blob/master/LICENSE

import { Reader, Writer, ReaderSync, WriterSync } from "./io.ts";
import type { Reader, Writer, ReaderSync, WriterSync } from "./io.ts";
import { assert } from "./util.ts";

// MIN_READ is the minimum ArrayBuffer size passed to a read call by
Expand Down
Loading

0 comments on commit 82aabb6

Please sign in to comment.