summaryrefslogtreecommitdiff
path: root/cli/lib.rs
diff options
context:
space:
mode:
authorNayeem Rahman <nayeemrmn99@gmail.com>2020-04-09 13:34:24 +0100
committerGitHub <noreply@github.com>2020-04-09 14:34:24 +0200
commit71ac552249cbded3823998d42cb2fcfd22b522d9 (patch)
tree6abd4014e63e3aefe70b547e88828ad60d81118d /cli/lib.rs
parent475a47cfb7b83e05872ce084bc4b13d60697711b (diff)
feat(cli/doc): Support doc for runtime built-ins (#4635)
Diffstat (limited to 'cli/lib.rs')
-rw-r--r--cli/lib.rs34
1 files changed, 22 insertions, 12 deletions
diff --git a/cli/lib.rs b/cli/lib.rs
index a87846c11..79fe312a1 100644
--- a/cli/lib.rs
+++ b/cli/lib.rs
@@ -251,6 +251,15 @@ async fn print_file_info(
Ok(())
}
+fn get_types() -> String {
+ format!(
+ "{}\n{}\n{}",
+ crate::js::DENO_NS_LIB,
+ crate::js::SHARED_GLOBALS_LIB,
+ crate::js::WINDOW_LIB
+ )
+}
+
async fn info_command(
flags: Flags,
file: Option<String>,
@@ -369,13 +378,12 @@ async fn bundle_command(
async fn doc_command(
flags: Flags,
- source_file: String,
+ source_file: Option<String>,
json: bool,
maybe_filter: Option<String>,
) -> Result<(), ErrBox> {
let global_state = GlobalState::new(flags.clone())?;
- let module_specifier =
- ModuleSpecifier::resolve_url_or_path(&source_file).unwrap();
+ let source_file = source_file.unwrap_or_else(|| "--builtin".to_string());
impl DocFileLoader for SourceFileFetcher {
fn load_source_code(
@@ -397,9 +405,16 @@ async fn doc_command(
let loader = Box::new(global_state.file_fetcher.clone());
let doc_parser = doc::DocParser::new(loader);
- let parse_result = doc_parser
- .parse_with_reexports(&module_specifier.to_string())
- .await;
+
+ let parse_result = if source_file == "--builtin" {
+ doc_parser.parse_source("lib.deno.d.ts", get_types().as_str())
+ } else {
+ let module_specifier =
+ ModuleSpecifier::resolve_url_or_path(&source_file).unwrap();
+ doc_parser
+ .parse_with_reexports(&module_specifier.to_string())
+ .await
+ };
let doc_nodes = match parse_result {
Ok(nodes) => nodes,
@@ -580,12 +595,7 @@ pub fn main() {
return;
}
DenoSubcommand::Types => {
- let types = format!(
- "{}\n{}\n{}",
- crate::js::DENO_NS_LIB,
- crate::js::SHARED_GLOBALS_LIB,
- crate::js::WINDOW_LIB
- );
+ let types = get_types();
if let Err(e) = write_to_stdout_ignore_sigpipe(types.as_bytes()) {
eprintln!("{}", e);
std::process::exit(1);