summaryrefslogtreecommitdiff
path: root/cli
diff options
context:
space:
mode:
Diffstat (limited to 'cli')
-rw-r--r--cli/Cargo.toml15
-rw-r--r--cli/file_fetcher.rs7
-rw-r--r--cli/lsp/analysis.rs16
-rw-r--r--cli/main.rs2
-rw-r--r--cli/tests/testdata/060_deno_doc_displays_all_overloads_in_details_view.ts.out6
-rw-r--r--cli/tests/testdata/bundle/fixture11.out8
-rw-r--r--cli/tests/testdata/doc/types_header.out2
-rw-r--r--cli/tests/testdata/doc/types_hint.out2
-rw-r--r--cli/tests/testdata/doc/types_ref.out2
-rw-r--r--cli/tests/testdata/doc/use_import_map.out2
-rw-r--r--cli/tests/testdata/lint/expected_json.out2
-rw-r--r--cli/tests/unit/event_target_test.ts1
-rw-r--r--cli/tests/unit/globals_test.ts1
-rw-r--r--cli/tools/doc.rs158
-rw-r--r--cli/tools/lint.rs42
-rw-r--r--cli/tools/test.rs2
16 files changed, 157 insertions, 111 deletions
diff --git a/cli/Cargo.toml b/cli/Cargo.toml
index 3a7596b23..63b13c325 100644
--- a/cli/Cargo.toml
+++ b/cli/Cargo.toml
@@ -44,8 +44,9 @@ winres = "0.1.11"
[dependencies]
deno_core = { version = "0.98.0", path = "../core" }
-deno_doc = "0.10.0"
-deno_lint = "0.12.0"
+deno_doc = "0.12.1"
+deno_graph = "0.3.1"
+deno_lint = { version = "0.14.0", features = ["docs"] }
deno_runtime = { version = "0.24.0", path = "../runtime" }
deno_tls = { version = "0.3.0", path = "../ext/tls" }
@@ -56,8 +57,8 @@ clap = "2.33.3"
data-url = "0.1.0"
dissimilar = "1.0.2"
dprint-plugin-json = "0.12.3"
-dprint-plugin-markdown = "0.9.4"
-dprint-plugin-typescript = "0.50.2"
+dprint-plugin-markdown = "0.9.6"
+dprint-plugin-typescript = "0.53.0"
encoding_rs = "0.8.28"
env_logger = "0.8.4"
fancy-regex = "0.5.0"
@@ -83,9 +84,9 @@ semver-parser = "0.10.2"
serde = { version = "1.0.126", features = ["derive"] }
shell-escape = "0.1.5"
sourcemap = "6.0.1"
-swc_bundler = "0.50.0"
-swc_common = { version = "0.11.4", features = ["sourcemap"] }
-swc_ecmascript = { version = "0.52.1", features = ["codegen", "dep_graph", "parser", "proposal", "react", "transforms", "typescript", "visit"] }
+swc_bundler = "0.56.0"
+swc_common = { version = "0.11.9", features = ["sourcemap"] }
+swc_ecmascript = { version = "0.60.0", features = ["codegen", "dep_graph", "parser", "proposal", "react", "transforms", "typescript", "visit"] }
tempfile = "3.2.0"
termcolor = "1.1.2"
text-size = "1.1.0"
diff --git a/cli/file_fetcher.rs b/cli/file_fetcher.rs
index a1729825f..17bbb76f0 100644
--- a/cli/file_fetcher.rs
+++ b/cli/file_fetcher.rs
@@ -56,6 +56,8 @@ pub struct File {
/// The _final_ specifier for the file. The requested specifier and the final
/// specifier maybe different for remote files that have been redirected.
pub specifier: ModuleSpecifier,
+
+ pub maybe_headers: Option<HashMap<String, String>>,
}
/// Simple struct implementing in-process caching to prevent multiple
@@ -137,6 +139,7 @@ fn fetch_local(specifier: &ModuleSpecifier) -> Result<File, AnyError> {
media_type,
source,
specifier: specifier.clone(),
+ maybe_headers: None,
})
}
@@ -274,6 +277,7 @@ impl FileFetcher {
media_type,
source,
specifier: specifier.clone(),
+ maybe_headers: Some(headers.clone()),
})
}
@@ -365,6 +369,7 @@ impl FileFetcher {
media_type,
source,
specifier: specifier.clone(),
+ maybe_headers: None,
})
}
@@ -426,6 +431,7 @@ impl FileFetcher {
media_type,
source,
specifier: specifier.clone(),
+ maybe_headers: None,
})
}
/// Asynchronously fetch remote source file specified by the URL following
@@ -894,6 +900,7 @@ mod tests {
media_type: MediaType::TypeScript,
source: "some source code".to_string(),
specifier: specifier.clone(),
+ maybe_headers: None,
};
file_fetcher.insert_cached(file.clone());
diff --git a/cli/lsp/analysis.rs b/cli/lsp/analysis.rs
index 17fdf5d4c..4c5f1fea7 100644
--- a/cli/lsp/analysis.rs
+++ b/cli/lsp/analysis.rs
@@ -120,12 +120,12 @@ impl Reference {
fn as_lsp_range(range: &deno_lint::diagnostic::Range) -> Range {
Range {
start: Position {
- line: (range.start.line - 1) as u32,
- character: range.start.col as u32,
+ line: range.start.line_index as u32,
+ character: range.start.column_index as u32,
},
end: Position {
- line: (range.end.line - 1) as u32,
- character: range.end.col as u32,
+ line: range.end.line_index as u32,
+ character: range.end.column_index as u32,
},
}
}
@@ -1172,13 +1172,13 @@ mod tests {
fn test_as_lsp_range() {
let fixture = deno_lint::diagnostic::Range {
start: deno_lint::diagnostic::Position {
- line: 1,
- col: 2,
+ line_index: 0,
+ column_index: 2,
byte_pos: 23,
},
end: deno_lint::diagnostic::Position {
- line: 2,
- col: 0,
+ line_index: 1,
+ column_index: 0,
byte_pos: 33,
},
};
diff --git a/cli/main.rs b/cli/main.rs
index beb54cd23..b68539ad8 100644
--- a/cli/main.rs
+++ b/cli/main.rs
@@ -566,6 +566,7 @@ async fn eval_command(
},
source: String::from_utf8(source_code)?,
specifier: main_module.clone(),
+ maybe_headers: None,
};
// Save our fake file into file fetcher cache
@@ -815,6 +816,7 @@ async fn run_from_stdin(flags: Flags) -> Result<(), AnyError> {
media_type: MediaType::TypeScript,
source: String::from_utf8(source)?,
specifier: main_module.clone(),
+ maybe_headers: None,
};
// Save our fake file into file fetcher cache
// to allow module access by TS compiler
diff --git a/cli/tests/testdata/060_deno_doc_displays_all_overloads_in_details_view.ts.out b/cli/tests/testdata/060_deno_doc_displays_all_overloads_in_details_view.ts.out
index f1a5077d8..ac3026826 100644
--- a/cli/tests/testdata/060_deno_doc_displays_all_overloads_in_details_view.ts.out
+++ b/cli/tests/testdata/060_deno_doc_displays_all_overloads_in_details_view.ts.out
@@ -1,12 +1,12 @@
-Defined in [WILDCARD]/060_deno_doc_displays_all_overloads_in_details_view.ts:3:2
+Defined in [WILDCARD]/060_deno_doc_displays_all_overloads_in_details_view.ts:3:2
function test(name: string, fn: Function): void
-Defined in [WILDCARD]/060_deno_doc_displays_all_overloads_in_details_view.ts:4:2
+Defined in [WILDCARD]/060_deno_doc_displays_all_overloads_in_details_view.ts:4:2
function test(options: object): void
-Defined in [WILDCARD]/060_deno_doc_displays_all_overloads_in_details_view.ts:5:2
+Defined in [WILDCARD]/060_deno_doc_displays_all_overloads_in_details_view.ts:5:2
function test(name: string | object, fn?: Function): void
diff --git a/cli/tests/testdata/bundle/fixture11.out b/cli/tests/testdata/bundle/fixture11.out
index d143e8723..4f333a513 100644
--- a/cli/tests/testdata/bundle/fixture11.out
+++ b/cli/tests/testdata/bundle/fixture11.out
@@ -2,10 +2,10 @@ function a() {
console.log("a");
}
var O1;
-(function(O1) {
- O1[O1["A"] = 0] = "A";
- O1[O1["B"] = 1] = "B";
- O1[O1["C"] = 2] = "C";
+(function(O) {
+ O[O["A"] = 0] = "A";
+ O[O["B"] = 1] = "B";
+ O[O["C"] = 2] = "C";
})(O1 || (O1 = {
}));
export { O1 as O };
diff --git a/cli/tests/testdata/doc/types_header.out b/cli/tests/testdata/doc/types_header.out
index ccff1a373..c7eda2d87 100644
--- a/cli/tests/testdata/doc/types_header.out
+++ b/cli/tests/testdata/doc/types_header.out
@@ -1,6 +1,6 @@
Download http://127.0.0.1:4545/xTypeScriptTypes.js
Download http://127.0.0.1:4545/xTypeScriptTypes.d.ts
-Defined in http://127.0.0.1:4545/xTypeScriptTypes.d.ts:1:0
+Defined in http://127.0.0.1:4545/xTypeScriptTypes.d.ts:1:0
const foo: "foo"
diff --git a/cli/tests/testdata/doc/types_hint.out b/cli/tests/testdata/doc/types_hint.out
index 7eb05faed..dd975360a 100644
--- a/cli/tests/testdata/doc/types_hint.out
+++ b/cli/tests/testdata/doc/types_hint.out
@@ -1,4 +1,4 @@
-Defined in [WILDCARD]/type_definitions/foo.d.ts:2:0
+Defined in [WILDCARD]/type_definitions/foo.d.ts:2:0
const foo: string
An exported value.
diff --git a/cli/tests/testdata/doc/types_ref.out b/cli/tests/testdata/doc/types_ref.out
index 7eb05faed..dd975360a 100644
--- a/cli/tests/testdata/doc/types_ref.out
+++ b/cli/tests/testdata/doc/types_ref.out
@@ -1,4 +1,4 @@
-Defined in [WILDCARD]/type_definitions/foo.d.ts:2:0
+Defined in [WILDCARD]/type_definitions/foo.d.ts:2:0
const foo: string
An exported value.
diff --git a/cli/tests/testdata/doc/use_import_map.out b/cli/tests/testdata/doc/use_import_map.out
index 0b27ccf18..82de4dbb0 100644
--- a/cli/tests/testdata/doc/use_import_map.out
+++ b/cli/tests/testdata/doc/use_import_map.out
@@ -1,4 +1,4 @@
-Defined in [WILDCARD]/doc/module/fun.js:2:0
+Defined in [WILDCARD]/doc/module/fun.js:2:0
function fun(_a, _b)
This is some documentation
diff --git a/cli/tests/testdata/lint/expected_json.out b/cli/tests/testdata/lint/expected_json.out
index dbeb8039b..9af79ce3d 100644
--- a/cli/tests/testdata/lint/expected_json.out
+++ b/cli/tests/testdata/lint/expected_json.out
@@ -58,7 +58,7 @@
"errors": [
{
"file_path": "[WILDCARD]malformed.js",
- "message": "Expected }, got <eof> at [WILDCARD]malformed.js:4:15"
+ "message": "Expected }, got <eof> at [WILDCARD]malformed.js:4:16"
}
]
}
diff --git a/cli/tests/unit/event_target_test.ts b/cli/tests/unit/event_target_test.ts
index 0d0d89154..a6c942773 100644
--- a/cli/tests/unit/event_target_test.ts
+++ b/cli/tests/unit/event_target_test.ts
@@ -1,4 +1,5 @@
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
+// deno-lint-ignore-file no-window-prefix
import { assertEquals, unitTest } from "./test_util.ts";
unitTest(function addEventListenerTest() {
diff --git a/cli/tests/unit/globals_test.ts b/cli/tests/unit/globals_test.ts
index 0051dce49..d989ab54a 100644
--- a/cli/tests/unit/globals_test.ts
+++ b/cli/tests/unit/globals_test.ts
@@ -1,4 +1,5 @@
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
+// deno-lint-ignore-file no-window-prefix
import { assert, unitTest } from "./test_util.ts";
unitTest(function globalThisExists() {
diff --git a/cli/tools/doc.rs b/cli/tools/doc.rs
index ab9ea127e..339e046c3 100644
--- a/cli/tools/doc.rs
+++ b/cli/tools/doc.rs
@@ -5,75 +5,89 @@ use crate::colors;
use crate::file_fetcher::File;
use crate::flags::Flags;
use crate::get_types;
+use crate::import_map::ImportMap;
use crate::media_type::MediaType;
-use crate::module_graph;
use crate::program_state::ProgramState;
-use crate::specifier_handler::FetchHandler;
use crate::write_json_to_stdout;
use crate::write_to_stdout_ignore_sigpipe;
use deno_core::error::AnyError;
+use deno_core::futures::future;
use deno_core::futures::future::FutureExt;
-use deno_core::futures::Future;
-use deno_core::parking_lot::Mutex;
use deno_core::resolve_url_or_path;
use deno_doc as doc;
-use deno_doc::parser::DocFileLoader;
+use deno_graph::create_graph;
+use deno_graph::source::LoadFuture;
+use deno_graph::source::LoadResponse;
+use deno_graph::source::Loader;
+use deno_graph::source::Resolver;
+use deno_graph::ModuleSpecifier;
use deno_runtime::permissions::Permissions;
use std::path::PathBuf;
-use std::pin::Pin;
use std::sync::Arc;
-use swc_ecmascript::parser::Syntax;
-type DocResult = Result<(Syntax, String), doc::DocError>;
-
-/// When parsing lib.deno.d.ts, only `DocParser::parse_source` is used,
-/// which never even references the loader, so this is just a stub for that scenario.
-///
-/// TODO(Liamolucko): Refactor `deno_doc` so this isn't necessary.
struct StubDocLoader;
-impl DocFileLoader for StubDocLoader {
- fn resolve(
- &self,
- _specifier: &str,
- _referrer: &str,
- ) -> Result<String, doc::DocError> {
- unreachable!()
+impl Loader for StubDocLoader {
+ fn load(
+ &mut self,
+ specifier: &ModuleSpecifier,
+ _is_dynamic: bool,
+ ) -> LoadFuture {
+ Box::pin(future::ready((specifier.clone(), Ok(None))))
}
+}
- fn load_source_code(
- &self,
- _specifier: &str,
- ) -> Pin<Box<dyn Future<Output = DocResult>>> {
- unreachable!()
- }
+#[derive(Debug)]
+struct DocResolver {
+ import_map: Option<ImportMap>,
}
-impl DocFileLoader for module_graph::Graph {
+impl Resolver for DocResolver {
fn resolve(
&self,
specifier: &str,
- referrer: &str,
- ) -> Result<String, doc::DocError> {
- let referrer =
- resolve_url_or_path(referrer).expect("Expected valid specifier");
- match self.resolve(specifier, &referrer, true) {
- Ok(specifier) => Ok(specifier.to_string()),
- Err(e) => Err(doc::DocError::Resolve(e.to_string())),
+ referrer: &ModuleSpecifier,
+ ) -> Result<ModuleSpecifier, AnyError> {
+ if let Some(import_map) = &self.import_map {
+ return import_map
+ .resolve(specifier, referrer.as_str())
+ .map_err(AnyError::from);
}
+
+ let module_specifier =
+ deno_core::resolve_import(specifier, referrer.as_str())?;
+
+ Ok(module_specifier)
}
+}
- fn load_source_code(
- &self,
- specifier: &str,
- ) -> Pin<Box<dyn Future<Output = DocResult>>> {
- let specifier =
- resolve_url_or_path(specifier).expect("Expected valid specifier");
- let source = self.get_source(&specifier).expect("Unknown dependency");
- let media_type =
- self.get_media_type(&specifier).expect("Unknown media type");
- let syntax = ast::get_syntax(&media_type);
- async move { Ok((syntax, source)) }.boxed_local()
+struct DocLoader {
+ program_state: Arc<ProgramState>,
+}
+
+impl Loader for DocLoader {
+ fn load(
+ &mut self,
+ specifier: &ModuleSpecifier,
+ _is_dynamic: bool,
+ ) -> LoadFuture {
+ let specifier = specifier.clone();
+ let program_state = self.program_state.clone();
+ async move {
+ let result = program_state
+ .file_fetcher
+ .fetch(&specifier, &mut Permissions::allow_all())
+ .await
+ .map(|file| {
+ Some(LoadResponse {
+ specifier: specifier.clone(),
+ content: Arc::new(file.source),
+ maybe_headers: file.maybe_headers,
+ })
+ });
+ (specifier.clone(), result)
+ }
+ .boxed_local()
}
}
@@ -88,12 +102,21 @@ pub async fn print_docs(
let source_file = source_file.unwrap_or_else(|| "--builtin".to_string());
let parse_result = if source_file == "--builtin" {
- let loader = Box::new(StubDocLoader);
- let doc_parser = doc::DocParser::new(loader, private);
-
+ let mut loader = StubDocLoader;
+ let source_file_specifier =
+ ModuleSpecifier::parse("deno://lib.deno.d.ts").unwrap();
+ let graph = create_graph(
+ source_file_specifier.clone(),
+ &mut loader,
+ None,
+ None,
+ None,
+ )
+ .await;
+ let doc_parser = doc::DocParser::new(graph, private);
let syntax = ast::get_syntax(&MediaType::Dts);
doc_parser.parse_source(
- "lib.deno.d.ts",
+ &source_file_specifier,
syntax,
get_types(flags.unstable).as_str(),
)
@@ -109,31 +132,28 @@ pub async fn print_docs(
media_type: MediaType::TypeScript,
source: format!("export * from \"{}\";", module_specifier),
specifier: root_specifier.clone(),
+ maybe_headers: None,
};
// Save our fake file into file fetcher cache.
program_state.file_fetcher.insert_cached(root);
- let handler = Arc::new(Mutex::new(FetchHandler::new(
- &program_state,
- Permissions::allow_all(),
- Permissions::allow_all(),
- )?));
- let mut builder = module_graph::GraphBuilder::new(
- handler,
- program_state.maybe_import_map.clone(),
- program_state.lockfile.clone(),
- );
- builder.add(&root_specifier, false).await?;
- builder
- .analyze_config_file(&program_state.maybe_config_file)
- .await?;
- let graph = builder.get_graph();
-
- let doc_parser = doc::DocParser::new(Box::new(graph), private);
- doc_parser
- .parse_with_reexports(root_specifier.as_str())
- .await
+ let mut loader = DocLoader {
+ program_state: program_state.clone(),
+ };
+ let resolver = DocResolver {
+ import_map: program_state.maybe_import_map.clone(),
+ };
+ let graph = create_graph(
+ root_specifier.clone(),
+ &mut loader,
+ Some(&resolver),
+ None,
+ None,
+ )
+ .await;
+ let doc_parser = doc::DocParser::new(graph, private);
+ doc_parser.parse_with_reexports(&root_specifier)
};
let mut doc_nodes = match parse_result {
diff --git a/cli/tools/lint.rs b/cli/tools/lint.rs
index f87ad4359..7e6d2e923 100644
--- a/cli/tools/lint.rs
+++ b/cli/tools/lint.rs
@@ -239,8 +239,9 @@ impl LintReporter for PrettyLintReporter {
d.hint.as_ref(),
&fmt_errors::format_location(&JsStackFrame::from_location(
Some(d.filename.clone()),
- Some(d.range.start.line as i64),
- Some(d.range.start.col as i64),
+ Some(d.range.start.line_index as i64 + 1), // 1-indexed
+ // todo(#11111): make 1-indexed as well
+ Some(d.range.start.column_index as i64),
)),
);
@@ -277,24 +278,32 @@ pub fn format_diagnostic(
) -> String {
let mut lines = vec![];
- for i in range.start.line..=range.end.line {
- lines.push(source_lines[i - 1].to_string());
- if range.start.line == range.end.line {
+ for (i, line) in source_lines
+ .iter()
+ .enumerate()
+ .take(range.end.line_index + 1)
+ .skip(range.start.line_index)
+ {
+ lines.push(line.to_string());
+ if range.start.line_index == range.end.line_index {
lines.push(format!(
"{}{}",
- " ".repeat(range.start.col),
- colors::red(&"^".repeat(range.end.col - range.start.col))
+ " ".repeat(range.start.column_index),
+ colors::red(
+ &"^".repeat(range.end.column_index - range.start.column_index)
+ )
));
} else {
- let line_len = source_lines[i - 1].len();
- if range.start.line == i {
+ let line_len = line.len();
+ if range.start.line_index == i {
lines.push(format!(
"{}{}",
- " ".repeat(range.start.col),
- colors::red(&"^".repeat(line_len - range.start.col))
+ " ".repeat(range.start.column_index),
+ colors::red(&"^".repeat(line_len - range.start.column_index))
));
- } else if range.end.line == i {
- lines.push(colors::red(&"^".repeat(range.end.col)).to_string());
+ } else if range.end.line_index == i {
+ lines
+ .push(colors::red(&"^".repeat(range.end.column_index)).to_string());
} else if line_len != 0 {
lines.push(colors::red(&"^".repeat(line_len)).to_string());
}
@@ -363,9 +372,12 @@ fn sort_diagnostics(diagnostics: &mut Vec<LintDiagnostic>) {
let file_order = a.filename.cmp(&b.filename);
match file_order {
Ordering::Equal => {
- let line_order = a.range.start.line.cmp(&b.range.start.line);
+ let line_order =
+ a.range.start.line_index.cmp(&b.range.start.line_index);
match line_order {
- Ordering::Equal => a.range.start.col.cmp(&b.range.start.col),
+ Ordering::Equal => {
+ a.range.start.column_index.cmp(&b.range.start.column_index)
+ }
_ => line_order,
}
}
diff --git a/cli/tools/test.rs b/cli/tools/test.rs
index 8111293b4..90293173b 100644
--- a/cli/tools/test.rs
+++ b/cli/tools/test.rs
@@ -262,6 +262,7 @@ async fn test_specifier(
media_type: MediaType::JavaScript,
source: test_source.clone(),
specifier: test_specifier.clone(),
+ maybe_headers: None,
};
program_state.file_fetcher.insert_cached(test_file);
@@ -381,6 +382,7 @@ fn extract_files_from_regex_blocks(
media_type: file_media_type,
source: file_source,
specifier: file_specifier,
+ maybe_headers: None,
})
})
.collect();