fix: upgrade swc_ecmascript to 0.103 (#13284)

This commit is contained in:
David Sherret 2022-01-04 17:02:56 -05:00 committed by GitHub
parent b46da66056
commit 19c8cd3a45
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 166 additions and 158 deletions

View file

@ -38,9 +38,9 @@
"tools/wpt/manifest.json"
],
"plugins": [
"https://plugins.dprint.dev/typescript-0.60.0.wasm",
"https://plugins.dprint.dev/json-0.13.2.wasm",
"https://plugins.dprint.dev/markdown-0.11.3.wasm",
"https://plugins.dprint.dev/typescript-0.61.0.wasm",
"https://plugins.dprint.dev/json-0.14.0.wasm",
"https://plugins.dprint.dev/markdown-0.12.0.wasm",
"https://plugins.dprint.dev/toml-0.5.3.wasm"
]
}

170
Cargo.lock generated
View file

@ -91,9 +91,9 @@ dependencies = [
[[package]]
name = "anyhow"
version = "1.0.51"
version = "1.0.52"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8b26702f315f53b6071259e15dd9d64528213b44d61de1ec926eca7715d62203"
checksum = "84450d0b4a8bd1ba4144ce8ce718fbc5d071358b1e5384bace6536b3d1f2d5b3"
[[package]]
name = "arrayvec"
@ -121,9 +121,9 @@ dependencies = [
[[package]]
name = "ast_node"
version = "0.7.4"
version = "0.7.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e96d5444b02f3080edac8a144f6baf29b2fb6ff589ad4311559731a7c7529381"
checksum = "82b2dd56b7c509b3a0bb47a97a066cba459983470d3b8a3c20428737270f70bd"
dependencies = [
"darling",
"pmutil",
@ -643,6 +643,15 @@ dependencies = [
"matches",
]
[[package]]
name = "debug_unreachable"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9a032eac705ca39214d169f83e3d3da290af06d8d1d344d1baad2fd002dca4b3"
dependencies = [
"unreachable",
]
[[package]]
name = "deno"
version = "1.17.1"
@ -716,9 +725,9 @@ dependencies = [
[[package]]
name = "deno_ast"
version = "0.7.0"
version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0f1c58caca74265d1c63a5c26069e037846f8bdf6a3e2dde3da66c6f6f51297d"
checksum = "72a3eb87c6fddf68e02f7438728a611ff6ca84a644fc00d3b9ad5a006e212484"
dependencies = [
"data-url",
"dprint-swc-ecma-ast-view",
@ -806,9 +815,9 @@ dependencies = [
[[package]]
name = "deno_doc"
version = "0.24.0"
version = "0.25.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6563f9d5f40a4e8c29a43a512536734f22eca1e7f86de1eb6d6d7d5a622c2afb"
checksum = "e3fd524cf36cae45b06de577f8f18b6ef786b56a3840fb721923ccddeeb09833"
dependencies = [
"cfg-if 1.0.0",
"deno_ast",
@ -852,9 +861,9 @@ dependencies = [
[[package]]
name = "deno_graph"
version = "0.16.0"
version = "0.17.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "db82fb9c644a51d9d4303ff21d04c4c3e32175576efbddc1c7498eda665ea4fd"
checksum = "c5eda28d50fc84d2b1774829316dcecdce1d41f0923b3a174f88cd599cafd529"
dependencies = [
"anyhow",
"cfg-if 1.0.0",
@ -888,9 +897,9 @@ dependencies = [
[[package]]
name = "deno_lint"
version = "0.20.1"
version = "0.21.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c213b1d00e3579f156d95cb8329de2d0fcc85b308cdec0b9ec954f840a5ebc7c"
checksum = "90b4b3dfb590568c6cb9ff24d4fb36645b47e480059517420fcb5d19758f75c9"
dependencies = [
"anyhow",
"deno_ast",
@ -1125,10 +1134,11 @@ dependencies = [
[[package]]
name = "dprint-core"
version = "0.47.1"
version = "0.49.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6400fcb8f2d6d4a231d2fc374edd1cf0e3713439e781a680b4b4f2afe2d31c7e"
checksum = "8113ac9998173de8fa4fcf6fc7fe80c15c93df290828afa060dbdbb84337afbf"
dependencies = [
"anyhow",
"bumpalo",
"rustc-hash",
"serde",
@ -1136,10 +1146,11 @@ dependencies = [
[[package]]
name = "dprint-plugin-json"
version = "0.13.2"
version = "0.14.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7aba7fe282566c4f217295b19d69ddaee7a4e179a6ea63f28efc7cc7b9fd766c"
checksum = "6c531c535098419053a6ad7a166c7cfb940a54f97a36f934315394e61a329d85"
dependencies = [
"anyhow",
"dprint-core",
"jsonc-parser",
"serde",
@ -1147,10 +1158,11 @@ dependencies = [
[[package]]
name = "dprint-plugin-markdown"
version = "0.11.3"
version = "0.12.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9b28f3f469ccd62d6e93fec9926dae032b8e8e05ffc20217c05e80b27ed372e3"
checksum = "835cf6371fc1474544f70dd28778789bd39474093997fb721c36082b0b4ee316"
dependencies = [
"anyhow",
"dprint-core",
"pulldown-cmark",
"regex",
@ -1159,10 +1171,11 @@ dependencies = [
[[package]]
name = "dprint-plugin-typescript"
version = "0.60.0"
version = "0.61.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b0a43c5093e898d4fc54b14c2583d83e9ab30d68e3bde374ab6a74996af2f1e2"
checksum = "e2cf0922de1556135f425df4de9968fd0b8e424eebc7fdb4001058c678bde475"
dependencies = [
"anyhow",
"deno_ast",
"dprint-core",
"parking_lot_core",
@ -1172,9 +1185,9 @@ dependencies = [
[[package]]
name = "dprint-swc-ecma-ast-view"
version = "0.45.0"
version = "0.47.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2d2654eb6e5d6e02096f6969d1370e9e474b43c9ad1a7142556c7d1e9d1afe0a"
checksum = "bbbf1d058db8ad7c9790db7dbe852d0cbddd2a314e592387232fa3db02fe0771"
dependencies = [
"bumpalo",
"num-bigint",
@ -1949,9 +1962,9 @@ dependencies = [
[[package]]
name = "jsonc-parser"
version = "0.17.0"
version = "0.17.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0cb8a8eb6349c33f5ff1c6f12d09936f048c039411c9a08cd54a378fbf1905e2"
checksum = "2ceb55b30bfc8869d48b43a7f117380bae1dc5e97484b46ecccf77fdc1ec057f"
dependencies = [
"serde_json",
]
@ -2768,9 +2781,9 @@ dependencies = [
[[package]]
name = "pulldown-cmark"
version = "0.8.0"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ffade02495f22453cd593159ea2f59827aae7f53fa8323f756799b670881dcf8"
checksum = "acd16514d1af5f7a71f909a44ef253cdb712a376d7ebc8ae4a471a9be9743548"
dependencies = [
"bitflags",
"memchr",
@ -3294,9 +3307,9 @@ dependencies = [
[[package]]
name = "serde"
version = "1.0.130"
version = "1.0.133"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f12d06de37cf59146fbdecab66aa99f9fe4f78722e3607577a5375d66bd0c913"
checksum = "97565067517b60e2d1ea8b268e59ce036de907ac523ad83a0475da04e818989a"
dependencies = [
"serde_derive",
]
@ -3312,9 +3325,9 @@ dependencies = [
[[package]]
name = "serde_derive"
version = "1.0.130"
version = "1.0.133"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d7bc1a1ab1961464eae040d96713baa5a724a8152c1222492465b54322ec508b"
checksum = "ed201699328568d8d08208fdd080e3ff594e6c422e438b6705905da01005d537"
dependencies = [
"proc-macro2 1.0.33",
"quote 1.0.10",
@ -3594,9 +3607,9 @@ dependencies = [
[[package]]
name = "swc_bundler"
version = "0.89.0"
version = "0.96.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7266b804885475a9f2d829946747d72b4806e23be690a44c8b6f7819453fd0bc"
checksum = "e4df8e45a1d523403a5f256fca9ab216bcccbd5883b7aba6f8b5a5c1e69bcd31"
dependencies = [
"ahash",
"anyhow",
@ -3626,13 +3639,14 @@ dependencies = [
[[package]]
name = "swc_common"
version = "0.15.0"
version = "0.16.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "560998b621793a613c98ec8cdbd729e46332dd3fbf7619b57e9d98c15e142e2e"
checksum = "757c84b893b4b16bbbe983acc8262f52fe5efd9b87b362f4196549e4f798c0a0"
dependencies = [
"ahash",
"ast_node",
"cfg-if 0.1.10",
"debug_unreachable",
"either",
"from_variant",
"num-bigint",
@ -3652,9 +3666,9 @@ dependencies = [
[[package]]
name = "swc_ecma_ast"
version = "0.59.1"
version = "0.62.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "49c93361aba26b56682cfa53709939b1511a09289dbed7753ace5f300b52d3b5"
checksum = "d00427977875928f37e92e260f226a91783812aaf3713562526a920befd6aa39"
dependencies = [
"is-macro",
"num-bigint",
@ -3662,13 +3676,14 @@ dependencies = [
"string_enum",
"swc_atoms",
"swc_common",
"unicode-xid 0.2.2",
]
[[package]]
name = "swc_ecma_codegen"
version = "0.83.1"
version = "0.86.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7af562472cb19a0a13912ee21aec49a8a8c19092994e2a5ee84f93f5fd762caa"
checksum = "025d9bb2d836fac57bf5579f7049ff96e702632c0affb362234b26d587f996d1"
dependencies = [
"bitflags",
"memchr",
@ -3698,9 +3713,9 @@ dependencies = [
[[package]]
name = "swc_ecma_dep_graph"
version = "0.50.1"
version = "0.55.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f07f7c6513e4eb53f92d116c1aaeff9e6b7eba969635d8b61af4da35f1f2cacf"
checksum = "a3368bafec3d3dd3f19e2108551b9d6dd1362c515cd138a652aff9f911409316"
dependencies = [
"swc_atoms",
"swc_common",
@ -3710,23 +3725,22 @@ dependencies = [
[[package]]
name = "swc_ecma_loader"
version = "0.25.0"
version = "0.26.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b0c9672f7cf71bf2a98fc0c66eed90d43db9252c82e52096c7159ea5521f3478"
checksum = "61e4a236d9fc809d88e8d346381e72936dc8a4e4a2418d1f66ea8acb6ed298be"
dependencies = [
"ahash",
"anyhow",
"serde",
"swc_atoms",
"swc_common",
"tracing",
]
[[package]]
name = "swc_ecma_parser"
version = "0.81.0"
version = "0.84.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "97570156b3eec2e91b43f3adf9526caaf5cdf656c65a7722715b3537c2952261"
checksum = "55406a1e109a7c4ad281ee4fe295249553b7fcbfa43b27f7b53d6112b2924af4"
dependencies = [
"either",
"enum_kind",
@ -3737,7 +3751,6 @@ dependencies = [
"swc_atoms",
"swc_common",
"swc_ecma_ast",
"swc_ecma_visit",
"tracing",
"typed-arena",
"unicode-xid 0.2.2",
@ -3745,9 +3758,9 @@ dependencies = [
[[package]]
name = "swc_ecma_transforms"
version = "0.101.0"
version = "0.106.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "15931263dab79ddee709e981b5222d84a684cfaa66d2913394bee6d5b4635cca"
checksum = "e7f2517337858bcbb43be51ff34033f80ca0379e0838e6cbdcdb62e88d56b9ec"
dependencies = [
"swc_atoms",
"swc_common",
@ -3764,9 +3777,9 @@ dependencies = [
[[package]]
name = "swc_ecma_transforms_base"
version = "0.48.1"
version = "0.52.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "12032e1af75c83a4c40c4784b4ae46c56b74326609aca7104e30ababfe9a7f28"
checksum = "06384503de52f097bbaa41fbe488510041906a69b3f01449ef024384eeb7fabf"
dependencies = [
"once_cell",
"phf",
@ -3783,9 +3796,9 @@ dependencies = [
[[package]]
name = "swc_ecma_transforms_classes"
version = "0.34.0"
version = "0.39.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7305d99e9851ae762e8bca1f7d43a0a1dd6c55b78220b10425b06a5f54c4498f"
checksum = "19ad7eb4fb019fc608ccff8a2ceffb7548ec94018cc2f523367b137b90b1d6a6"
dependencies = [
"swc_atoms",
"swc_common",
@ -3810,15 +3823,14 @@ dependencies = [
[[package]]
name = "swc_ecma_transforms_optimization"
version = "0.71.0"
version = "0.76.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7d528d813fd0af0c8727b0143b0c60759ff6a1cefb7223ee955da85c90edaaa6"
checksum = "eb91bd9aea0f0dd57688340306203ec776ed2fd1e2b75871b7135566c5a4e82a"
dependencies = [
"ahash",
"dashmap",
"indexmap",
"once_cell",
"retain_mut",
"serde_json",
"swc_atoms",
"swc_common",
@ -3833,9 +3845,9 @@ dependencies = [
[[package]]
name = "swc_ecma_transforms_proposal"
version = "0.63.0"
version = "0.68.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1185431bc8fb9d5460f662effbe4eaa10f1038f4e7fc7cfb2edfef4a7cc1104e"
checksum = "e6520f06130f57292dfd986c0484034f37f6a129699a139010a818e4cd164975"
dependencies = [
"either",
"serde",
@ -3853,9 +3865,9 @@ dependencies = [
[[package]]
name = "swc_ecma_transforms_react"
version = "0.65.1"
version = "0.70.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "99f7d18dca4fbdc563244658bcea15b8151cd37ae7462588bf4b15eada4e5688"
checksum = "3ef966c28b0f13412c546ebd777e61b197b2ef8c9214bee8393f25d0027adfef"
dependencies = [
"ahash",
"base64 0.13.0",
@ -3878,9 +3890,9 @@ dependencies = [
[[package]]
name = "swc_ecma_transforms_typescript"
version = "0.67.2"
version = "0.72.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "aff4b2e2bf68f042313dcb56c61b66410cb8232692e1ab0e789472ad6b32aa85"
checksum = "5ca12da83a3ce8fa61defa77256f11bf63048830d45b2e3a67fb7208d5dfa8b5"
dependencies = [
"serde",
"swc_atoms",
@ -3895,9 +3907,9 @@ dependencies = [
[[package]]
name = "swc_ecma_utils"
version = "0.55.1"
version = "0.59.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ba7fd9af7d4d4e972dd92f47c36094bbf6e345dc15d5e1260201156e74e21cb2"
checksum = "4684e029d1c06cd3ee86e83a3cffb7a90acb421b58204ed72c8e3719bc88eca5"
dependencies = [
"once_cell",
"swc_atoms",
@ -3905,14 +3917,13 @@ dependencies = [
"swc_ecma_ast",
"swc_ecma_visit",
"tracing",
"unicode-xid 0.2.2",
]
[[package]]
name = "swc_ecma_visit"
version = "0.45.0"
version = "0.48.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f0b3826abd1e68214fe9743437236608a0a22d27912e84a85a53f1e977e10468"
checksum = "3185cd9fa4460935d9a9f1efc5eed1efc5b57a58d471313b88bee1ecfdeff268"
dependencies = [
"num-bigint",
"swc_atoms",
@ -3924,9 +3935,9 @@ dependencies = [
[[package]]
name = "swc_ecmascript"
version = "0.95.0"
version = "0.103.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "703291bc32dd81c1d73761e02442bdefed5844490f853f9979b8b8cb21e7392b"
checksum = "ff3180fe209baa9f0fa4a693b2c569f40b010ee3e8155c72435b3b79fc0686e3"
dependencies = [
"swc_ecma_ast",
"swc_ecma_codegen",
@ -3951,9 +3962,9 @@ dependencies = [
[[package]]
name = "swc_fast_graph"
version = "0.2.0"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b4e08c814c7283238c72c61069614b55d58ccfeeb5e4fd9887913e9d34102632"
checksum = "4857942a9c79e9836f51dca4ca0df89f354acfedc573708006c4365bad07083c"
dependencies = [
"ahash",
"indexmap",
@ -3963,9 +3974,9 @@ dependencies = [
[[package]]
name = "swc_graph_analyzer"
version = "0.2.0"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "13707fe5ba172950c56e16ab206f4d2a7da4e16742e7f527c331c1e0973267d4"
checksum = "3c5f079d9350dee80a59ac2f8be9867ed0a8ac9fb0023461b173e9e42168ff30"
dependencies = [
"ahash",
"auto_impl",
@ -4548,6 +4559,15 @@ version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3"
[[package]]
name = "unreachable"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1f2ae5ddb18e1c92664717616dd9549dde73f539f01bd7b77c2edb2446bdff91"
dependencies = [
"void",
]
[[package]]
name = "untrusted"
version = "0.7.1"
@ -4633,6 +4653,12 @@ version = "0.9.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5fecdca9a5291cc2b8dcf7dc02453fee791a280f3743cb0905f8822ae463b3fe"
[[package]]
name = "void"
version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d"
[[package]]
name = "walkdir"
version = "2.3.2"

View file

@ -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"

View file

@ -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);

View file

@ -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}");

View file

@ -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)

View file

@ -1,7 +1,6 @@
[WILDCARD]
const React = {
createElement () {
}
createElement () {}
};
function app() {
return React.createElement("div", null, React.createElement("h2", null, "asdf"));

View file

@ -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";

View file

@ -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(())
}