diff options
author | David Sherret <dsherret@users.noreply.github.com> | 2022-01-04 17:02:56 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-01-04 17:02:56 -0500 |
commit | 19c8cd3a457b58bc62a6e0223ff78208a73d9435 (patch) | |
tree | 149bbd0cda5d0d0f1a4229f30937b950c4242d04 /cli | |
parent | b46da660563b175722937d9f29d45029bd6a0a74 (diff) |
fix: upgrade swc_ecmascript to 0.103 (#13284)
Diffstat (limited to 'cli')
-rw-r--r-- | cli/Cargo.toml | 20 | ||||
-rw-r--r-- | cli/ast/mod.rs | 55 | ||||
-rw-r--r-- | cli/ast/transforms.rs | 27 | ||||
-rw-r--r-- | cli/lsp/language_server.rs | 2 | ||||
-rw-r--r-- | cli/tests/testdata/bundle_jsx.out | 3 | ||||
-rw-r--r-- | cli/tests/unit/test_util.ts | 1 | ||||
-rw-r--r-- | cli/tools/fmt.rs | 40 |
7 files changed, 65 insertions, 83 deletions
diff --git a/cli/Cargo.toml b/cli/Cargo.toml index c02735a0f..bc202a410 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -32,18 +32,18 @@ deno_webgpu = { version = "0.31.0", path = "../ext/webgpu" } deno_websocket = { version = "0.35.0", path = "../ext/websocket" } deno_webstorage = { version = "0.25.0", path = "../ext/webstorage" } regex = "=1.5.4" -serde = { version = "=1.0.130", features = ["derive"] } +serde = { version = "=1.0.133", features = ["derive"] } [target.'cfg(windows)'.build-dependencies] winapi = "=0.3.9" winres = "=0.1.11" [dependencies] -deno_ast = { version = "0.7.0", features = ["bundler", "codegen", "dep_graph", "module_specifier", "proposal", "react", "sourcemap", "transforms", "typescript", "view", "visit"] } +deno_ast = { version = "0.8.0", features = ["bundler", "codegen", "dep_graph", "module_specifier", "proposal", "react", "sourcemap", "transforms", "typescript", "view", "visit"] } deno_core = { version = "0.112.0", path = "../core" } -deno_doc = "0.24.0" -deno_graph = "0.16.0" -deno_lint = { version = "0.20.0", features = ["docs"] } +deno_doc = "0.25.0" +deno_graph = "0.17.0" +deno_lint = { version = "0.21.0", features = ["docs"] } deno_runtime = { version = "0.38.0", path = "../runtime" } atty = "=0.2.14" @@ -53,15 +53,15 @@ chrono = "=0.4.19" clap = "=2.33.3" data-url = "=0.1.1" dissimilar = "=1.0.2" -dprint-plugin-json = "=0.13.2" -dprint-plugin-markdown = "=0.11.3" -dprint-plugin-typescript = "=0.60.0" +dprint-plugin-json = "=0.14.0" +dprint-plugin-markdown = "=0.12.0" +dprint-plugin-typescript = "=0.61.0" encoding_rs = "=0.8.29" env_logger = "=0.8.4" fancy-regex = "=0.7.1" http = "=0.2.4" import_map = "=0.4.0" -jsonc-parser = { version = "=0.17.0", features = ["serde"] } +jsonc-parser = { version = "=0.17.1", features = ["serde"] } libc = "=0.2.106" log = { version = "=0.4.14", features = ["serde"] } lspower = "=1.4.0" @@ -76,7 +76,7 @@ ring = "=0.16.20" rustyline = { version = "=9.0.0", default-features = false } rustyline-derive = "=0.5.0" semver-parser = "=0.10.2" -serde = { version = "=1.0.130", features = ["derive"] } +serde = { version = "=1.0.133", features = ["derive"] } shell-escape = "=0.1.5" sourcemap = "=6.0.1" tempfile = "=3.2.0" diff --git a/cli/ast/mod.rs b/cli/ast/mod.rs index 80cbd5c4b..b089d5421 100644 --- a/cli/ast/mod.rs +++ b/cli/ast/mod.rs @@ -602,8 +602,7 @@ mod tests { #[test] fn test_transpile() { - let specifier = resolve_url_or_path("https://deno.land/x/mod.ts") - .expect("could not resolve specifier"); + let specifier = resolve_url_or_path("https://deno.land/x/mod.ts").unwrap(); let source = r#" enum D { A, @@ -637,24 +636,21 @@ export class A { scope_analysis: false, }) .unwrap(); - let (code, maybe_map) = transpile(&module, &EmitOptions::default()) - .expect("could not strip types"); + let (code, maybe_map) = + transpile(&module, &EmitOptions::default()).unwrap(); let expected_text = r#"var D; (function(D) { D[D["A"] = 0] = "A"; D[D["B"] = 1] = "B"; -})(D || (D = { -})); +})(D || (D = {})); var N; (function(N1) { let D; (function(D) { D["A"] = "value"; - })(D = N1.D || (N1.D = { - })); - N1.Value = 5; -})(N || (N = { -})); + })(D = N1.D || (N1.D = {})); + var Value = N1.Value = 5; +})(N || (N = {})); export class A { d; b; @@ -677,8 +673,7 @@ export class A { #[test] fn test_transpile_tsx() { - let specifier = resolve_url_or_path("https://deno.land/x/mod.ts") - .expect("could not resolve specifier"); + let specifier = resolve_url_or_path("https://deno.land/x/mod.ts").unwrap(); let source = r#" export class A { render() { @@ -694,16 +689,14 @@ export class A { maybe_syntax: None, scope_analysis: true, // ensure scope analysis doesn't conflict with a second resolver pass }) - .expect("could not parse module"); - let (code, _) = transpile(&module, &EmitOptions::default()) - .expect("could not strip types"); + .unwrap(); + let (code, _) = transpile(&module, &EmitOptions::default()).unwrap(); assert!(code.contains("React.createElement(\"div\", null")); } #[test] fn test_transpile_jsx_pragma() { - let specifier = resolve_url_or_path("https://deno.land/x/mod.ts") - .expect("could not resolve specifier"); + let specifier = resolve_url_or_path("https://deno.land/x/mod.ts").unwrap(); let source = r#" /** @jsx h */ /** @jsxFrag Fragment */ @@ -733,8 +726,7 @@ function App() { #[test] fn test_transpile_jsx_import_source_pragma() { - let specifier = resolve_url_or_path("https://deno.land/x/mod.tsx") - .expect("could not resolve specifier"); + let specifier = resolve_url_or_path("https://deno.land/x/mod.tsx").unwrap(); let source = r#" /** @jsxImportSource jsx_lib */ @@ -756,8 +748,7 @@ function App() { let expected = r#"import { jsx as _jsx, Fragment as _Fragment } from "jsx_lib/jsx-runtime"; /** @jsxImportSource jsx_lib */ function App() { return(/*#__PURE__*/ _jsx("div", { - children: /*#__PURE__*/ _jsx(_Fragment, { - }) + children: /*#__PURE__*/ _jsx(_Fragment, {}) })); "#; assert_eq!(&code[..expected.len()], expected); @@ -765,8 +756,7 @@ function App() { #[test] fn test_transpile_jsx_import_source_no_pragma() { - let specifier = resolve_url_or_path("https://deno.land/x/mod.tsx") - .expect("could not resolve specifier"); + let specifier = resolve_url_or_path("https://deno.land/x/mod.tsx").unwrap(); let source = r#" function App() { return ( @@ -791,8 +781,7 @@ function App() { let expected = r#"import { jsx as _jsx, Fragment as _Fragment } from "jsx_lib/jsx-runtime"; function App() { return(/*#__PURE__*/ _jsx("div", { - children: /*#__PURE__*/ _jsx(_Fragment, { - }) + children: /*#__PURE__*/ _jsx(_Fragment, {}) })); } "#; @@ -802,8 +791,7 @@ function App() { // TODO(@kitsonk) https://github.com/swc-project/swc/issues/2656 // #[test] // fn test_transpile_jsx_import_source_no_pragma_dev() { - // let specifier = resolve_url_or_path("https://deno.land/x/mod.tsx") - // .expect("could not resolve specifier"); + // let specifier = resolve_url_or_path("https://deno.land/x/mod.tsx").unwrap(); // let source = r#" // function App() { // return ( @@ -839,8 +827,7 @@ function App() { #[test] fn test_transpile_decorators() { - let specifier = resolve_url_or_path("https://deno.land/x/mod.ts") - .expect("could not resolve specifier"); + let specifier = resolve_url_or_path("https://deno.land/x/mod.ts").unwrap(); let source = r#" function enumerable(value: boolean) { return function ( @@ -867,9 +854,8 @@ function App() { maybe_syntax: None, scope_analysis: false, }) - .expect("could not parse module"); - let (code, _) = transpile(&module, &EmitOptions::default()) - .expect("could not strip types"); + .unwrap(); + let (code, _) = transpile(&module, &EmitOptions::default()).unwrap(); assert!(code.contains("_applyDecoratedDescriptor(")); } @@ -903,8 +889,7 @@ export function g() { let (code, _) = transpile(&module, &emit_options).unwrap(); let expected = r#"export function g() { let algorithm; - algorithm = { - }; + algorithm = {}; return test(algorithm, false, keyUsages); }"#; assert_eq!(&code[..expected.len()], expected); diff --git a/cli/ast/transforms.rs b/cli/ast/transforms.rs index ba8af59af..a89edc01d 100644 --- a/cli/ast/transforms.rs +++ b/cli/ast/transforms.rs @@ -50,7 +50,10 @@ impl Fold for DownlevelImportsFolder { ImportSpecifier::Named(specifier) => { Some(match specifier.imported.as_ref() { Some(name) => create_key_value( - name.sym.to_string(), + match name { + ModuleExportName::Ident(ident) => ident.sym.to_string(), + ModuleExportName::Str(str) => str.value.to_string(), + }, specifier.local.sym.to_string(), ), None => create_assignment(specifier.local.sym.to_string()), @@ -200,10 +203,12 @@ fn create_ident(name: String) -> swc_ast::Ident { fn create_key_value(key: String, value: String) -> swc_ast::ObjectPatProp { swc_ast::ObjectPatProp::KeyValue(swc_ast::KeyValuePatProp { - key: swc_ast::PropName::Ident(swc_ast::Ident { + // use a string literal because it will work in more scenarios than an identifier + key: swc_ast::PropName::Str(swc_ast::Str { span: DUMMY_SP, - sym: key.into(), - optional: false, + value: key.into(), + has_escape: false, + kind: swc_ast::StrKind::Synthesized, }), value: Box::new(swc_ast::Pat::Ident(swc_ast::BindingIdent { id: swc_ast::Ident { @@ -320,7 +325,7 @@ mod test { test_transform( DownlevelImportsFolder, r#"import mod from "./mod.ts";"#, - r#"const { default: mod } = await import("./mod.ts");"#, + r#"const { "default": mod } = await import("./mod.ts");"#, ); } @@ -341,7 +346,7 @@ mod test { test_transform( DownlevelImportsFolder, r#"import { A as LocalA, B, C as LocalC } from "./mod.ts";"#, - r#"const { A: LocalA , B , C: LocalC } = await import("./mod.ts");"#, + r#"const { "A": LocalA , B , "C": LocalC } = await import("./mod.ts");"#, ); } @@ -359,13 +364,13 @@ mod test { test_transform( DownlevelImportsFolder, r#"import myDefault, { A, B as LocalB } from "./mod.ts";"#, - r#"const { default: myDefault , A , B: LocalB } = await import("./mod.ts");"#, + r#"const { "default": myDefault , A , "B": LocalB } = await import("./mod.ts");"#, ); test_transform( DownlevelImportsFolder, r#"import myDefault, * as mod from "./mod.ts";"#, - r#"const { default: myDefault } = await import("./mod.ts"), mod = await import("./mod.ts");"#, + r#"const { "default": myDefault } = await import("./mod.ts"), mod = await import("./mod.ts");"#, ); } @@ -374,7 +379,7 @@ mod test { test_transform( DownlevelImportsFolder, r#"import data from "./mod.json" assert { type: "json" };"#, - "const { default: data } = await import(\"./mod.json\", {\n assert: {\n type: \"json\"\n }\n});", + "const { \"default\": data } = await import(\"./mod.json\", {\n assert: {\n type: \"json\"\n }\n});", ); } @@ -433,7 +438,7 @@ mod test { test_transform( StripExportsFolder, "export default function test() {}", - "function test() {\n}", + "function test() {}", ); } @@ -455,7 +460,7 @@ mod test { test_transform( StripExportsFolder, "export function test() {}", - "function test() {\n}", + "function test() {}", ); test_transform(StripExportsFolder, "export enum Test {}", "enum Test {\n}"); diff --git a/cli/lsp/language_server.rs b/cli/lsp/language_server.rs index 384b100b2..5f28365fa 100644 --- a/cli/lsp/language_server.rs +++ b/cli/lsp/language_server.rs @@ -1035,7 +1035,7 @@ impl Inner { Some(Ok(parsed_source)) => { format_parsed_source(&parsed_source, fmt_options) } - Some(Err(err)) => Err(err.to_string()), + Some(Err(err)) => Err(anyhow!("{}", err)), None => { // it's not a js/ts file, so attempt to format its contents format_file(&file_path, document.content().as_str(), fmt_options) diff --git a/cli/tests/testdata/bundle_jsx.out b/cli/tests/testdata/bundle_jsx.out index 44c9e4555..da83cde82 100644 --- a/cli/tests/testdata/bundle_jsx.out +++ b/cli/tests/testdata/bundle_jsx.out @@ -1,7 +1,6 @@ [WILDCARD] const React = { - createElement () { - } + createElement () {} }; function app() { return React.createElement("div", null, React.createElement("h2", null, "asdf")); diff --git a/cli/tests/unit/test_util.ts b/cli/tests/unit/test_util.ts index 80af8fdfc..85c59717c 100644 --- a/cli/tests/unit/test_util.ts +++ b/cli/tests/unit/test_util.ts @@ -1,6 +1,5 @@ // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. -import { assert } from "../../../test_util/std/testing/asserts.ts"; import * as colors from "../../../test_util/std/fmt/colors.ts"; export { colors }; import { resolve } from "../../../test_util/std/path/mod.ts"; diff --git a/cli/tools/fmt.rs b/cli/tools/fmt.rs index 9172421b5..28256775a 100644 --- a/cli/tools/fmt.rs +++ b/cli/tools/fmt.rs @@ -19,12 +19,14 @@ use crate::fs_util::specifier_to_file_path; use crate::fs_util::{collect_files, get_extension, is_supported_ext_fmt}; use crate::text_encoding; use deno_ast::ParsedSource; +use deno_core::anyhow::bail; use deno_core::anyhow::Context; use deno_core::error::generic_error; use deno_core::error::AnyError; use deno_core::futures; use log::debug; use log::info; +use std::borrow::Cow; use std::fs; use std::io::stdin; use std::io::stdout; @@ -157,7 +159,7 @@ pub async fn format( fn format_markdown( file_text: &str, fmt_options: &FmtOptionsConfig, -) -> Result<String, String> { +) -> Result<String, AnyError> { let markdown_config = get_resolved_markdown_config(fmt_options); dprint_plugin_markdown::format_text( file_text, @@ -186,7 +188,7 @@ fn format_markdown( 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(text, &json_config).map(Cow::Owned) } else { let fake_filename = PathBuf::from(format!("deno_fmt_stdin.{}", extension)); @@ -198,13 +200,13 @@ fn format_markdown( text, &codeblock_config, ) + .map(Cow::Owned) } } else { - Ok(text.to_string()) + Ok(Cow::Borrowed(text)) } }, ) - .map_err(|e| e.to_string()) } /// Formats JSON and JSONC using the rules provided by .deno() @@ -213,9 +215,9 @@ fn format_markdown( pub fn format_json( file_text: &str, fmt_options: &FmtOptionsConfig, -) -> Result<String, String> { +) -> Result<String, AnyError> { let config = get_resolved_json_config(fmt_options); - dprint_plugin_json::format_text(file_text, &config).map_err(|e| e.to_string()) + dprint_plugin_json::format_text(file_text, &config) } /// Formats a single TS, TSX, JS, JSX, JSONC, JSON, or MD file. @@ -223,7 +225,7 @@ pub fn format_file( file_path: &Path, file_text: &str, fmt_options: FmtOptionsConfig, -) -> Result<String, String> { +) -> Result<String, AnyError> { let ext = get_extension(file_path).unwrap_or_else(String::new); if matches!( ext.as_str(), @@ -235,19 +237,17 @@ pub fn format_file( } else { let config = get_resolved_typescript_config(&fmt_options); dprint_plugin_typescript::format_text(file_path, file_text, &config) - .map_err(|e| e.to_string()) } } pub fn format_parsed_source( parsed_source: &ParsedSource, fmt_options: FmtOptionsConfig, -) -> Result<String, String> { +) -> Result<String, AnyError> { dprint_plugin_typescript::format_parsed_source( parsed_source, &get_resolved_typescript_config(&fmt_options), ) - .map_err(|e| e.to_string()) } async fn check_source_files( @@ -373,24 +373,18 @@ pub fn format_stdin( ) -> Result<(), AnyError> { let mut source = String::new(); if stdin().read_to_string(&mut source).is_err() { - return Err(generic_error("Failed to read from stdin")); + bail!("Failed to read from stdin"); } let file_path = PathBuf::from(format!("_stdin.{}", fmt_flags.ext)); let fmt_options = resolve_fmt_options(&fmt_flags, fmt_options); - match format_file(&file_path, &source, fmt_options) { - Ok(formatted_text) => { - if fmt_flags.check { - if formatted_text != source { - println!("Not formatted stdin"); - } - } else { - stdout().write_all(formatted_text.as_bytes())?; - } - } - Err(e) => { - return Err(generic_error(e)); + let formatted_text = format_file(&file_path, &source, fmt_options)?; + if fmt_flags.check { + if formatted_text != source { + println!("Not formatted stdin"); } + } else { + stdout().write_all(formatted_text.as_bytes())?; } Ok(()) } |