diff options
author | David Sherret <dsherret@users.noreply.github.com> | 2023-10-24 09:37:02 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-10-24 09:37:02 -0400 |
commit | 8f065a60e79e221a6ce7f6ce06c3022a85edb56a (patch) | |
tree | e1be8f4d384b5dd4f73940b86fd60cc58f43aef1 /cli | |
parent | 9df36b33c6aa250daa200167eb0e1b9d6d738da1 (diff) |
fix: improved using declaration support (#20959)
Upgrades to deno_ast 0.30.
Diffstat (limited to 'cli')
-rw-r--r-- | cli/Cargo.toml | 14 | ||||
-rw-r--r-- | cli/lsp/code_lens.rs | 12 | ||||
-rw-r--r-- | cli/lsp/documents.rs | 6 | ||||
-rw-r--r-- | cli/lsp/testing/collectors.rs | 12 | ||||
-rw-r--r-- | cli/module_loader.rs | 7 | ||||
-rw-r--r-- | cli/resolver.rs | 2 | ||||
-rw-r--r-- | cli/tools/bundle.rs | 1 | ||||
-rw-r--r-- | cli/tools/coverage/mod.rs | 11 | ||||
-rw-r--r-- | cli/tools/fmt.rs | 11 | ||||
-rw-r--r-- | cli/tools/repl/editor.rs | 53 | ||||
-rw-r--r-- | cli/tools/repl/session.rs | 3 | ||||
-rw-r--r-- | cli/tools/vendor/build.rs | 9 | ||||
-rw-r--r-- | cli/tools/vendor/import_map.rs | 9 | ||||
-rw-r--r-- | cli/tools/vendor/mod.rs | 2 |
14 files changed, 88 insertions, 64 deletions
diff --git a/cli/Cargo.toml b/cli/Cargo.toml index 8da9599d8..fc08a7074 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -49,16 +49,16 @@ deno_ast = { workspace = true, features = ["bundler", "cjs", "codegen", "dep_gra deno_cache_dir = "=0.6.0" deno_config = "=0.4.0" deno_core = { workspace = true, features = ["include_js_files_for_snapshotting"] } -deno_doc = "=0.68.0" -deno_emit = "=0.29.0" -deno_graph = "=0.56.3" -deno_lint = { version = "=0.51.0", features = ["docs"] } +deno_doc = "=0.69.1" +deno_emit = "=0.31.0" +deno_graph = "=0.58.0" +deno_lint = { version = "=0.52.1", features = ["docs"] } deno_lockfile.workspace = true deno_npm = "0.15.2" deno_runtime = { workspace = true, features = ["dont_create_runtime_snapshot", "exclude_runtime_main_js", "include_js_files_for_snapshotting"] } deno_semver = "0.5.1" deno_task_shell = "=0.13.2" -eszip = "=0.54.0" +eszip = "=0.55.1" napi_sym.workspace = true async-trait.workspace = true @@ -76,9 +76,9 @@ dashmap = "5.5.3" data-encoding.workspace = true data-url.workspace = true dissimilar = "=1.0.4" -dprint-plugin-json = "=0.17.4" +dprint-plugin-json = "=0.19.0" dprint-plugin-markdown = "=0.16.2" -dprint-plugin-typescript = "=0.88.1" +dprint-plugin-typescript = "=0.88.2" encoding_rs.workspace = true env_logger = "=0.10.0" fancy-regex = "=0.10.0" diff --git a/cli/lsp/code_lens.rs b/cli/lsp/code_lens.rs index d64b2014f..cab7af1a6 100644 --- a/cli/lsp/code_lens.rs +++ b/cli/lsp/code_lens.rs @@ -153,9 +153,9 @@ impl Visit for DenoTestCollector { } ast::Expr::Member(member_expr) => { if let ast::MemberProp::Ident(ns_prop_ident) = &member_expr.prop { - if ns_prop_ident.sym.to_string() == "test" { + if ns_prop_ident.sym == "test" { if let ast::Expr::Ident(ident) = member_expr.obj.as_ref() { - if ident.sym.to_string() == "Deno" { + if ident.sym == "Deno" { self.check_call_expr(node, &ns_prop_ident.range()); } } @@ -173,7 +173,7 @@ impl Visit for DenoTestCollector { match init.as_ref() { // Identify destructured assignments of `test` from `Deno` ast::Expr::Ident(ident) => { - if ident.sym.to_string() == "Deno" { + if ident.sym == "Deno" { if let ast::Pat::Object(object_pat) = &decl.name { for prop in &object_pat.props { match prop { @@ -185,7 +185,7 @@ impl Visit for DenoTestCollector { } ast::ObjectPatProp::KeyValue(prop) => { if let ast::PropName::Ident(key_ident) = &prop.key { - if key_ident.sym.to_string() == "test" { + if key_ident.sym == "test" { if let ast::Pat::Ident(value_ident) = &prop.value.as_ref() { @@ -205,9 +205,9 @@ impl Visit for DenoTestCollector { // Identify variable assignments where the init is `Deno.test` ast::Expr::Member(member_expr) => { if let ast::Expr::Ident(obj_ident) = member_expr.obj.as_ref() { - if obj_ident.sym.to_string() == "Deno" { + if obj_ident.sym == "Deno" { if let ast::MemberProp::Ident(prop_ident) = &member_expr.prop { - if prop_ident.sym.to_string() == "test" { + if prop_ident.sym == "test" { if let ast::Pat::Ident(binding_ident) = &decl.name { self.test_vars.insert(binding_ident.id.sym.to_string()); } diff --git a/cli/lsp/documents.rs b/cli/lsp/documents.rs index 674540281..bab94080f 100644 --- a/cli/lsp/documents.rs +++ b/cli/lsp/documents.rs @@ -34,6 +34,7 @@ use deno_core::futures::FutureExt; use deno_core::parking_lot::Mutex; use deno_core::url; use deno_core::ModuleSpecifier; +use deno_graph::source::ResolutionMode; use deno_graph::GraphImport; use deno_graph::Resolution; use deno_runtime::deno_node; @@ -1073,7 +1074,10 @@ impl Documents { specifier: &str, referrer: &ModuleSpecifier, ) -> bool { - let maybe_specifier = self.get_resolver().resolve(specifier, referrer).ok(); + let maybe_specifier = self + .get_resolver() + .resolve(specifier, referrer, ResolutionMode::Types) + .ok(); if let Some(import_specifier) = maybe_specifier { self.exists(&import_specifier) } else { diff --git a/cli/lsp/testing/collectors.rs b/cli/lsp/testing/collectors.rs index bc8eb65f1..e4538ab9d 100644 --- a/cli/lsp/testing/collectors.rs +++ b/cli/lsp/testing/collectors.rs @@ -479,12 +479,12 @@ impl Visit for TestCollector { ns_prop_ident: &ast::Ident, member_expr: &ast::MemberExpr, ) { - if ns_prop_ident.sym.to_string() == "test" { + if ns_prop_ident.sym == "test" { let ast::Expr::Ident(ident) = member_expr.obj.as_ref() else { return; }; - if ident.sym.to_string() != "Deno" { + if ident.sym != "Deno" { return; } @@ -563,7 +563,7 @@ impl Visit for TestCollector { match init.as_ref() { // Identify destructured assignments of `test` from `Deno` ast::Expr::Ident(ident) => { - if ident.sym.to_string() != "Deno" { + if ident.sym != "Deno" { continue; } @@ -584,7 +584,7 @@ impl Visit for TestCollector { continue; }; - if key_ident.sym.to_string() == "test" { + if key_ident.sym == "test" { if let ast::Pat::Ident(value_ident) = &prop.value.as_ref() { self.vars.insert(value_ident.id.sym.to_string()); } @@ -600,7 +600,7 @@ impl Visit for TestCollector { continue; }; - if obj_ident.sym.to_string() != "Deno" { + if obj_ident.sym != "Deno" { continue; }; @@ -608,7 +608,7 @@ impl Visit for TestCollector { continue; }; - if prop_ident.sym.to_string() != "test" { + if prop_ident.sym != "test" { continue; } diff --git a/cli/module_loader.rs b/cli/module_loader.rs index 84e8b6122..3f5e82d8c 100644 --- a/cli/module_loader.rs +++ b/cli/module_loader.rs @@ -39,6 +39,7 @@ use deno_core::ModuleSpecifier; use deno_core::ModuleType; use deno_core::ResolutionKind; use deno_core::SourceMapGetter; +use deno_graph::source::ResolutionMode; use deno_graph::source::Resolver; use deno_graph::EsmModule; use deno_graph::JsonModule; @@ -549,7 +550,11 @@ impl ModuleLoader for CliModuleLoader { // FIXME(bartlomieju): this is another hack way to provide NPM specifier // support in REPL. This should be fixed. - let resolution = self.shared.resolver.resolve(specifier, &referrer); + let resolution = self.shared.resolver.resolve( + specifier, + &referrer, + ResolutionMode::Execution, + ); if self.shared.is_repl { let specifier = resolution diff --git a/cli/resolver.rs b/cli/resolver.rs index 7d17177b6..f48e62aae 100644 --- a/cli/resolver.rs +++ b/cli/resolver.rs @@ -8,6 +8,7 @@ use deno_core::futures::FutureExt; use deno_core::ModuleSpecifier; use deno_graph::source::NpmPackageReqResolution; use deno_graph::source::NpmResolver; +use deno_graph::source::ResolutionMode; use deno_graph::source::ResolveError; use deno_graph::source::Resolver; use deno_graph::source::UnknownBuiltInNodeModuleError; @@ -170,6 +171,7 @@ impl Resolver for CliGraphResolver { &self, specifier: &str, referrer: &ModuleSpecifier, + _mode: ResolutionMode, ) -> Result<ModuleSpecifier, ResolveError> { let result = match self .mapped_specifier_resolver diff --git a/cli/tools/bundle.rs b/cli/tools/bundle.rs index cbde8768f..b36ff023a 100644 --- a/cli/tools/bundle.rs +++ b/cli/tools/bundle.rs @@ -148,6 +148,7 @@ fn bundle_module_graph( deno_emit::bundle_graph( graph, deno_emit::BundleOptions { + minify: false, bundle_type: deno_emit::BundleType::Module, emit_options: crate::args::ts_config_to_emit_options( ts_config_result.ts_config, diff --git a/cli/tools/coverage/mod.rs b/cli/tools/coverage/mod.rs index 23aef89fb..67566d811 100644 --- a/cli/tools/coverage/mod.rs +++ b/cli/tools/coverage/mod.rs @@ -138,12 +138,13 @@ impl CoverageCollector { let filename = format!("{}.json", Uuid::new_v4()); let filepath = self.dir.join(filename); - let mut out = BufWriter::new(File::create(filepath)?); + let mut out = BufWriter::new(File::create(&filepath)?); let coverage = serde_json::to_string(&script_coverage)?; - let formatted_coverage = format_json(&coverage, &Default::default()) - .ok() - .flatten() - .unwrap_or(coverage); + let formatted_coverage = + format_json(&filepath, &coverage, &Default::default()) + .ok() + .flatten() + .unwrap_or(coverage); out.write_all(formatted_coverage.as_bytes())?; out.flush()?; diff --git a/cli/tools/fmt.rs b/cli/tools/fmt.rs index b9525b7b2..92facc7ec 100644 --- a/cli/tools/fmt.rs +++ b/cli/tools/fmt.rs @@ -191,13 +191,13 @@ fn format_markdown( rest => rest, }; + let fake_filename = + PathBuf::from(format!("deno_fmt_stdin.{extension}")); if matches!(extension, "json" | "jsonc") { let mut json_config = get_resolved_json_config(fmt_options); json_config.line_width = line_width; - dprint_plugin_json::format_text(text, &json_config) + dprint_plugin_json::format_text(&fake_filename, text, &json_config) } else { - let fake_filename = - PathBuf::from(format!("deno_fmt_stdin.{extension}")); let mut codeblock_config = get_resolved_typescript_config(fmt_options); codeblock_config.line_width = line_width; @@ -218,11 +218,12 @@ fn format_markdown( /// of configuration builder of <https://github.com/dprint/dprint-plugin-json>. /// See <https://github.com/dprint/dprint-plugin-json/blob/cfa1052dbfa0b54eb3d814318034cdc514c813d7/src/configuration/builder.rs#L87> for configuration. pub fn format_json( + file_path: &Path, file_text: &str, fmt_options: &FmtOptionsConfig, ) -> Result<Option<String>, AnyError> { let config = get_resolved_json_config(fmt_options); - dprint_plugin_json::format_text(file_text, &config) + dprint_plugin_json::format_text(file_path, file_text, &config) } /// Formats a single TS, TSX, JS, JSX, JSONC, JSON, or MD file. @@ -238,7 +239,7 @@ pub fn format_file( ) { format_markdown(file_text, fmt_options) } else if matches!(ext.as_str(), "json" | "jsonc") { - format_json(file_text, fmt_options) + format_json(file_path, file_text, fmt_options) } else { let config = get_resolved_typescript_config(fmt_options); dprint_plugin_typescript::format_text(file_path, file_text, &config) diff --git a/cli/tools/repl/editor.rs b/cli/tools/repl/editor.rs index 5c2832aab..52fad4759 100644 --- a/cli/tools/repl/editor.rs +++ b/cli/tools/repl/editor.rs @@ -374,32 +374,35 @@ impl Highlighter for EditorHelper { } Word::Keyword(_) => colors::cyan(&line[range]).to_string(), Word::Ident(ident) => { - if ident == *"undefined" { - colors::gray(&line[range]).to_string() - } else if ident == *"Infinity" || ident == *"NaN" { - colors::yellow(&line[range]).to_string() - } else if ident == *"async" || ident == *"of" { - colors::cyan(&line[range]).to_string() - } else { - let next = lexed_items.peek().map(|item| &item.inner); - if matches!( - next, - Some(deno_ast::TokenOrComment::Token(Token::LParen)) - ) { - // We're looking for something that looks like a function - // We use a simple heuristic: 'ident' followed by 'LParen' - colors::intense_blue(&line[range]).to_string() - } else if ident == *"from" - && matches!( + match ident.as_ref() { + "undefined" => colors::gray(&line[range]).to_string(), + "Infinity" | "NaN" => { + colors::yellow(&line[range]).to_string() + } + "async" | "of" => colors::cyan(&line[range]).to_string(), + _ => { + let next = lexed_items.peek().map(|item| &item.inner); + if matches!( next, - Some(deno_ast::TokenOrComment::Token(Token::Str { .. })) - ) - { - // When ident 'from' is followed by a string literal, highlight it - // E.g. "export * from 'something'" or "import a from 'something'" - colors::cyan(&line[range]).to_string() - } else { - line[range].to_string() + Some(deno_ast::TokenOrComment::Token(Token::LParen)) + ) { + // We're looking for something that looks like a function + // We use a simple heuristic: 'ident' followed by 'LParen' + colors::intense_blue(&line[range]).to_string() + } else if ident.as_ref() == "from" + && matches!( + next, + Some(deno_ast::TokenOrComment::Token( + Token::Str { .. } + )) + ) + { + // When ident 'from' is followed by a string literal, highlight it + // E.g. "export * from 'something'" or "import a from 'something'" + colors::cyan(&line[range]).to_string() + } else { + line[range].to_string() + } } } } diff --git a/cli/tools/repl/session.rs b/cli/tools/repl/session.rs index 338a253d2..8f8d085dd 100644 --- a/cli/tools/repl/session.rs +++ b/cli/tools/repl/session.rs @@ -32,6 +32,7 @@ use deno_core::serde_json; use deno_core::serde_json::Value; use deno_core::unsync::spawn; use deno_core::LocalInspectorSession; +use deno_graph::source::ResolutionMode; use deno_graph::source::Resolver; use deno_runtime::worker::MainWorker; use deno_semver::npm::NpmPackageReqReference; @@ -572,7 +573,7 @@ impl ReplSession { .flat_map(|i| { self .resolver - .resolve(i, &self.referrer) + .resolve(i, &self.referrer, ResolutionMode::Execution) .ok() .or_else(|| ModuleSpecifier::parse(i).ok()) }) diff --git a/cli/tools/vendor/build.rs b/cli/tools/vendor/build.rs index 3e5f13d81..dd7c053c1 100644 --- a/cli/tools/vendor/build.rs +++ b/cli/tools/vendor/build.rs @@ -11,6 +11,7 @@ use deno_core::anyhow::Context; use deno_core::error::AnyError; use deno_core::futures::future::LocalBoxFuture; use deno_core::parking_lot::Mutex; +use deno_graph::source::ResolutionMode; use deno_graph::EsmModule; use deno_graph::Module; use deno_graph::ModuleGraph; @@ -111,9 +112,11 @@ pub async fn build< // add the jsx import source to the entry points to ensure it is always vendored if let Some(jsx_import_source) = jsx_import_source { if let Some(specifier_text) = jsx_import_source.maybe_specifier_text() { - if let Ok(specifier) = - resolver.resolve(&specifier_text, &jsx_import_source.base_url) - { + if let Ok(specifier) = resolver.resolve( + &specifier_text, + &jsx_import_source.base_url, + ResolutionMode::Execution, + ) { entry_points.push(specifier); } } diff --git a/cli/tools/vendor/import_map.rs b/cli/tools/vendor/import_map.rs index 36a70d4e0..b5893e9f5 100644 --- a/cli/tools/vendor/import_map.rs +++ b/cli/tools/vendor/import_map.rs @@ -4,6 +4,7 @@ use deno_ast::LineAndColumnIndex; use deno_ast::ModuleSpecifier; use deno_ast::SourceTextInfo; use deno_core::error::AnyError; +use deno_graph::source::ResolutionMode; use deno_graph::Module; use deno_graph::ModuleGraph; use deno_graph::Position; @@ -213,9 +214,11 @@ pub fn build_import_map( // add the jsx import source to the destination import map, if mapped in the original import map if let Some(jsx_import_source) = jsx_import_source { if let Some(specifier_text) = jsx_import_source.maybe_specifier_text() { - if let Ok(resolved_url) = - resolver.resolve(&specifier_text, &jsx_import_source.base_url) - { + if let Ok(resolved_url) = resolver.resolve( + &specifier_text, + &jsx_import_source.base_url, + ResolutionMode::Execution, + ) { builder.imports.add(specifier_text, &resolved_url); } } diff --git a/cli/tools/vendor/mod.rs b/cli/tools/vendor/mod.rs index c324a56dd..42909598d 100644 --- a/cli/tools/vendor/mod.rs +++ b/cli/tools/vendor/mod.rs @@ -355,7 +355,7 @@ fn update_config_text( let new_text = deno_ast::apply_text_changes(text, text_changes); modified_result.new_text = if should_format { - format_json(&new_text, fmt_options) + format_json(&PathBuf::from("deno.json"), &new_text, fmt_options) .ok() .map(|formatted_text| formatted_text.unwrap_or(new_text)) } else { |