1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-24 15:19:26 -05:00

chore: upgrade crates based on deno ast 0.3 (#12403)

This commit is contained in:
David Sherret 2021-10-12 09:58:04 -04:00 committed by GitHub
parent b1e7452cd3
commit 9b1f0c8ba3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
16 changed files with 315 additions and 248 deletions

View file

@ -35,9 +35,9 @@
"tools/wpt/manifest.json"
],
"plugins": [
"https://plugins.dprint.dev/typescript-0.54.0.wasm",
"https://plugins.dprint.dev/typescript-0.57.1.wasm",
"https://plugins.dprint.dev/json-0.13.0.wasm",
"https://plugins.dprint.dev/markdown-0.10.0.wasm",
"https://plugins.dprint.dev/toml-0.5.1.wasm"
"https://plugins.dprint.dev/toml-0.5.2.wasm"
]
}

190
Cargo.lock generated
View file

@ -407,6 +407,15 @@ dependencies = [
"winapi 0.3.9",
]
[[package]]
name = "cloudabi"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4344512281c643ae7638bbabc3af17a11307803ec8f0fcad9fae512a8bf36467"
dependencies = [
"bitflags",
]
[[package]]
name = "codespan-reporting"
version = "0.11.1"
@ -707,9 +716,9 @@ dependencies = [
[[package]]
name = "deno_ast"
version = "0.2.0"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "427e7091c1fd8a13b002824f43773b6ef2d5c8ded445ee20013bea7f6ca8bc5b"
checksum = "d177a5fbe88bec8d8b86882c77b7ba39ba03be99c5d80d3c9fc529191f3c0933"
dependencies = [
"data-url",
"dprint-swc-ecma-ast-view",
@ -793,9 +802,9 @@ dependencies = [
[[package]]
name = "deno_doc"
version = "0.15.0"
version = "0.16.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cac0571321c463d3cfa39d03084c9f823bcc812daa7202eb2e89b5f9abd6301f"
checksum = "73fa23e7482a6bce5a6dfbcca145e247aa282ef002db0f9f060d0a812ac18ff3"
dependencies = [
"cfg-if 1.0.0",
"deno_ast",
@ -838,9 +847,9 @@ dependencies = [
[[package]]
name = "deno_graph"
version = "0.6.0"
version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1d856f43e3fd84399d9f90200708fdd5f507bb5ee43770a5a88b3dbdf667619e"
checksum = "a9adc8acfce4c311ebb4cd08a70d3149cf2cd157d468bd46bb5c556db0754eec"
dependencies = [
"anyhow",
"cfg-if 1.0.0",
@ -873,9 +882,9 @@ dependencies = [
[[package]]
name = "deno_lint"
version = "0.16.0"
version = "0.17.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "32634706476ab0da1839d866b3f1765639afc894299bf96b83c980913c78275e"
checksum = "286985c2af9d4fcf162e2d5e08b196f68ab2f093ee6eaa28618842c47126c11d"
dependencies = [
"anyhow",
"deno_ast",
@ -1142,13 +1151,14 @@ dependencies = [
[[package]]
name = "dprint-plugin-typescript"
version = "0.55.0"
version = "0.57.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0f893075573bad180d06bcc673996a128b09e9ab608c45e40c379fd733f85636"
checksum = "85bf1bad85eb81020904b4e80271ab760be7aef3b5edf8b82567f51c8b2c7cba"
dependencies = [
"dprint-core",
"dprint-swc-ecma-ast-view",
"fnv",
"parking_lot_core",
"rustc-hash",
"serde",
"swc_common",
"swc_ecmascript",
@ -1156,13 +1166,13 @@ dependencies = [
[[package]]
name = "dprint-swc-ecma-ast-view"
version = "0.35.0"
version = "0.39.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3c561abeae30e338748557e2c85e7c73621877eba137951207a3fd32306d9ce2"
checksum = "3530a71ad541e1182d19a1fa4da83c8d134e38f6fffd4cd1035440444dd08d15"
dependencies = [
"bumpalo",
"fnv",
"num-bigint",
"rustc-hash",
"swc_atoms",
"swc_common",
"swc_ecmascript",
@ -1327,7 +1337,7 @@ checksum = "975ccf83d8d9d0d84682850a38c8169027be83368805971cc4f238c2b245bc98"
dependencies = [
"cfg-if 1.0.0",
"libc",
"redox_syscall",
"redox_syscall 0.2.10",
"winapi 0.3.9",
]
@ -2470,9 +2480,9 @@ dependencies = [
[[package]]
name = "parking_lot"
version = "0.11.2"
version = "0.11.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7d17b78036a60663b797adeaee46f5c9dfebb86948d1255007a1d6be0271ff99"
checksum = "6d7744ac029df22dca6284efe4e898991d28e3085c706c972bcd7da4a27a15eb"
dependencies = [
"instant",
"lock_api",
@ -2481,14 +2491,15 @@ dependencies = [
[[package]]
name = "parking_lot_core"
version = "0.8.5"
version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d76e8e1493bcac0d2766c42737f34458f1c8c50c0d23bcb24ea953affb273216"
checksum = "c361aa727dd08437f2f1447be8b59a33b0edd15e0fcee698f935613d9efbca9b"
dependencies = [
"cfg-if 1.0.0",
"cfg-if 0.1.10",
"cloudabi",
"instant",
"libc",
"redox_syscall",
"redox_syscall 0.1.57",
"smallvec",
"winapi 0.3.9",
]
@ -2894,6 +2905,12 @@ dependencies = [
"libc",
]
[[package]]
name = "redox_syscall"
version = "0.1.57"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "41cc0f7e4d5d4544e8861606a285bb08d3e70712ccc7d2b84d7c0ccfaf4b05ce"
[[package]]
name = "redox_syscall"
version = "0.2.10"
@ -3545,18 +3562,17 @@ dependencies = [
[[package]]
name = "swc_bundler"
version = "0.58.1"
version = "0.68.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "acfdeafdcfbfb0f4ca1838d775d8124da81168c4131a340c5b6682f078b34719"
checksum = "e39f8571be48d4397f9186d449ca9a435da3314dfe8db428f2485b8489ccbb53"
dependencies = [
"ahash 0.7.4",
"anyhow",
"crc",
"fxhash",
"indexmap",
"is-macro",
"log",
"once_cell",
"parking_lot",
"petgraph 0.5.1",
"radix_fmt",
"relative-path",
@ -3567,42 +3583,44 @@ dependencies = [
"swc_ecma_codegen",
"swc_ecma_loader",
"swc_ecma_parser",
"swc_ecma_transforms",
"swc_ecma_transforms_base",
"swc_ecma_transforms_optimization",
"swc_ecma_utils",
"swc_ecma_visit",
"tracing",
]
[[package]]
name = "swc_common"
version = "0.12.2"
version = "0.13.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "acc9ad667d8c220e1625e189933ffd9d29b643317aca7a211db2600ef622879e"
checksum = "259212df9a949aa6ec440b64244475bcda531609a85489a22eb27908dd8d1b0d"
dependencies = [
"ahash 0.7.4",
"ast_node",
"cfg-if 0.1.10",
"either",
"from_variant",
"fxhash",
"log",
"num-bigint",
"once_cell",
"owning_ref",
"rustc-hash",
"scoped-tls",
"serde",
"sourcemap",
"string_cache",
"swc_eq_ignore_macros",
"swc_visit",
"tracing",
"unicode-width",
"url",
]
[[package]]
name = "swc_ecma_ast"
version = "0.52.0"
version = "0.54.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "aa0efb0e13ba6545e2b86336937e1641594f78c48484b85c2dc9582eaccb41e1"
checksum = "eae24a6603262822de50069ff72394b0d208267e5bd5298678ba6a79f670c40f"
dependencies = [
"is-macro",
"num-bigint",
@ -3614,12 +3632,14 @@ dependencies = [
[[package]]
name = "swc_ecma_codegen"
version = "0.70.5"
version = "0.74.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e08e335585f54f85fa910ab771660f69d809f8f70160d4cf912c9a855970db81"
checksum = "e2f84ab8cdd0395372a9b94d2938ee787d18e4d6805b5e11d26756c8410ef78d"
dependencies = [
"bitflags",
"memchr",
"num-bigint",
"once_cell",
"sourcemap",
"swc_atoms",
"swc_common",
@ -3630,9 +3650,9 @@ dependencies = [
[[package]]
name = "swc_ecma_codegen_macros"
version = "0.5.2"
version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "51af418026cb4ea588e2b15fa206c44e09a3184b718e12a0919729c7c3ad20d3"
checksum = "bdbf826c739281cdb3b3c23883fd1a7586ea1c15b1287530e7123a7fad8f0e25"
dependencies = [
"pmutil",
"proc-macro2 1.0.29",
@ -3643,9 +3663,9 @@ dependencies = [
[[package]]
name = "swc_ecma_dep_graph"
version = "0.39.1"
version = "0.42.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c20a594158fbaa00e039867f96183e4daa5a867fa21331a3655c90789f2df6b3"
checksum = "8e27fde9ec4d2b24663836ac0bff26909db0505abad3b873d30808f7659d977a"
dependencies = [
"swc_atoms",
"swc_common",
@ -3655,30 +3675,28 @@ dependencies = [
[[package]]
name = "swc_ecma_loader"
version = "0.18.2"
version = "0.21.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c2f718f0335f9ab7437fecf9f3d73ae6a24c03a3d3f46910a68261703d407f03"
checksum = "8a1c79e93e0182da35ab5be1fcb6e8060b5af41bf4e9c1760cad3520dbc287ac"
dependencies = [
"ahash 0.7.4",
"anyhow",
"fxhash",
"log",
"swc_atoms",
"swc_common",
"swc_ecma_ast",
"swc_ecma_visit",
"tracing",
]
[[package]]
name = "swc_ecma_parser"
version = "0.70.4"
version = "0.73.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "04b2e3c0ac2132a7ab0679fe8bb89ad0a3311c6c5f44a22bffc559647e1f2e47"
checksum = "c8d7c0925ea8ad9ca8554ed668ab8cf98e057064a79a819893f71a008cd65e36"
dependencies = [
"either",
"enum_kind",
"fxhash",
"lexical",
"log",
"num-bigint",
"serde",
"smallvec",
@ -3686,21 +3704,21 @@ dependencies = [
"swc_common",
"swc_ecma_ast",
"swc_ecma_visit",
"tracing",
"unicode-xid 0.2.2",
]
[[package]]
name = "swc_ecma_transforms"
version = "0.71.1"
version = "0.81.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b2124504a4203cab8f903b8e8be49dbd6c4bad2b0405ba0c8188f952c224c44b"
checksum = "9170807286d86c713320a5122c299a5cd62c81ac62e572e2259aa1a93d80c171"
dependencies = [
"swc_atoms",
"swc_common",
"swc_ecma_ast",
"swc_ecma_parser",
"swc_ecma_transforms_base",
"swc_ecma_transforms_optimization",
"swc_ecma_transforms_proposal",
"swc_ecma_transforms_react",
"swc_ecma_transforms_typescript",
@ -3711,11 +3729,10 @@ dependencies = [
[[package]]
name = "swc_ecma_transforms_base"
version = "0.31.4"
version = "0.37.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fdcd1f3c1ca665605dcb2a7d6b536aeff1ed1da2eeebf32238d890e42b494312"
checksum = "e5ab2108361a8bb8664951ae0f533fab36c609aa849143b3358e29ed33060bbe"
dependencies = [
"fxhash",
"once_cell",
"phf",
"scoped-tls",
@ -3730,9 +3747,9 @@ dependencies = [
[[package]]
name = "swc_ecma_transforms_classes"
version = "0.17.1"
version = "0.23.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ad5a845d5ec140ba8580c6b8d0f51ce417b86395a7b74c4280bb6cdae3c042c6"
checksum = "cafd0ad50aedf503cd640c0a3b5a9e9c0a8a279c1772c523f78ee707f30d3423"
dependencies = [
"swc_atoms",
"swc_common",
@ -3743,15 +3760,27 @@ dependencies = [
]
[[package]]
name = "swc_ecma_transforms_optimization"
version = "0.41.1"
name = "swc_ecma_transforms_macros"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ea2600bc3bd557353511cd90b336943ae30e8807bce989a420cb004953fb940a"
checksum = "f7680ada61fa22c2164c3f32864efba31566710b503c30631ccc3b6f0fa800bc"
dependencies = [
"pmutil",
"proc-macro2 1.0.29",
"quote 1.0.10",
"swc_macros_common",
"syn 1.0.65",
]
[[package]]
name = "swc_ecma_transforms_optimization"
version = "0.51.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cc478afa98cd8272d75a994cddd598f903cc8c9d0fce6555516dcad0ed2a0c61"
dependencies = [
"ahash 0.7.4",
"dashmap",
"fxhash",
"indexmap",
"log",
"once_cell",
"retain_mut",
"serde_json",
@ -3762,16 +3791,16 @@ dependencies = [
"swc_ecma_transforms_base",
"swc_ecma_utils",
"swc_ecma_visit",
"tracing",
]
[[package]]
name = "swc_ecma_transforms_proposal"
version = "0.38.1"
version = "0.46.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "637093e49ee993b16fb7bf8918f3d409c986fc77850440a3c779de85d1442cfb"
checksum = "cdb257ed97c73338e9776a0c1404bc55570d14e69d0b57f1030105630dd36a5a"
dependencies = [
"either",
"fxhash",
"serde",
"smallvec",
"swc_atoms",
@ -3780,16 +3809,18 @@ dependencies = [
"swc_ecma_parser",
"swc_ecma_transforms_base",
"swc_ecma_transforms_classes",
"swc_ecma_transforms_macros",
"swc_ecma_utils",
"swc_ecma_visit",
]
[[package]]
name = "swc_ecma_transforms_react"
version = "0.39.1"
version = "0.48.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "18bf8799eb49b25f0632b9e60b7871b3f77e18fecb1972e4932ba08005b5c85f"
checksum = "4c30996f62170b3cad11ac85dc058c59655d66a6de134d3182e99324c903da58"
dependencies = [
"ahash 0.7.4",
"base64 0.13.0",
"dashmap",
"indexmap",
@ -3809,11 +3840,10 @@ dependencies = [
[[package]]
name = "swc_ecma_transforms_typescript"
version = "0.40.4"
version = "0.48.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "96bb017f32fd1559f10245112eeac1cf10e3b76415495e159b10c82ee667ac9e"
checksum = "62b8ba9d4bc21426d3b21e92c6007932f421dd4698d4e301352ff7e969c72295"
dependencies = [
"fxhash",
"serde",
"swc_atoms",
"swc_common",
@ -3826,9 +3856,9 @@ dependencies = [
[[package]]
name = "swc_ecma_utils"
version = "0.44.2"
version = "0.47.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3c811bca37142f7fe21ce800784db1d537645762ffe8d8a52e2a7179d8cc1723"
checksum = "e3e427f476cd95fa625678d2df2c8a56ad94ce4182034f9489f9249f3f1c7c9f"
dependencies = [
"once_cell",
"scoped-tls",
@ -3841,9 +3871,9 @@ dependencies = [
[[package]]
name = "swc_ecma_visit"
version = "0.38.1"
version = "0.40.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "78c6721dfbcb8bea64383edb0d59ccb02bc1e140024f2e0f8766792a14f5f466"
checksum = "2c24a7600061813d7df3248d93ff27cacc1a81f9eeec47701866f3adc9ae2930"
dependencies = [
"num-bigint",
"swc_atoms",
@ -3854,9 +3884,9 @@ dependencies = [
[[package]]
name = "swc_ecmascript"
version = "0.63.1"
version = "0.73.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ba53c5582d6e5881b093ece9aaa4b561465afab0560abb19948f2c4bbff1bdb9"
checksum = "8147c047015f4289b3202a5362a6ed8c384a585eee05c98f040299a0b303f22e"
dependencies = [
"swc_ecma_ast",
"swc_ecma_codegen",
@ -3968,7 +3998,7 @@ dependencies = [
"cfg-if 1.0.0",
"libc",
"rand 0.8.4",
"redox_syscall",
"redox_syscall 0.2.10",
"remove_dir_all",
"winapi 0.3.9",
]
@ -4189,9 +4219,21 @@ checksum = "375a639232caf30edfc78e8d89b2d4c375515393e7af7e16f01cd96917fb2105"
dependencies = [
"cfg-if 1.0.0",
"pin-project-lite",
"tracing-attributes",
"tracing-core",
]
[[package]]
name = "tracing-attributes"
version = "0.1.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f4f480b8f81512e825f337ad51e94c1eb5d3bbdf2b363dcd01e2b19a9ffe3f8e"
dependencies = [
"proc-macro2 1.0.29",
"quote 1.0.10",
"syn 1.0.65",
]
[[package]]
name = "tracing-core"
version = "0.1.21"

View file

@ -39,11 +39,11 @@ winapi = "0.3.9"
winres = "0.1.11"
[dependencies]
deno_ast = { version = "0.2.0", features = ["bundler", "codegen", "dep_graph", "module_specifier", "proposal", "react", "sourcemap", "transforms", "typescript", "view", "visit"] }
deno_ast = { version = "0.3.0", features = ["bundler", "codegen", "dep_graph", "module_specifier", "proposal", "react", "sourcemap", "transforms", "typescript", "view", "visit"] }
deno_core = { version = "0.102.0", path = "../core" }
deno_doc = "0.15.0"
deno_graph = "0.6.0"
deno_lint = { version = "0.16.0", features = ["docs"] }
deno_doc = "0.16.0"
deno_graph = "0.7.0"
deno_lint = { version = "0.17.0", features = ["docs"] }
deno_runtime = { version = "0.28.0", path = "../runtime" }
deno_tls = { version = "0.7.0", path = "../ext/tls" }
@ -54,7 +54,7 @@ data-url = "0.1.0"
dissimilar = "1.0.2"
dprint-plugin-json = "0.13.0"
dprint-plugin-markdown = "0.10.0"
dprint-plugin-typescript = "0.55.0"
dprint-plugin-typescript = "0.57.2"
encoding_rs = "0.8.28"
env_logger = "0.8.4"
fancy-regex = "0.7.1"

View file

@ -13,6 +13,7 @@ use deno_ast::swc::common::comments::SingleThreadedComments;
use deno_ast::swc::common::BytePos;
use deno_ast::swc::common::FileName;
use deno_ast::swc::common::Globals;
use deno_ast::swc::common::Mark;
use deno_ast::swc::common::SourceMap;
use deno_ast::swc::common::Spanned;
use deno_ast::swc::parser::lexer::Lexer;
@ -23,6 +24,7 @@ use deno_ast::swc::transforms::hygiene;
use deno_ast::swc::transforms::pass::Optional;
use deno_ast::swc::transforms::proposals;
use deno_ast::swc::transforms::react;
use deno_ast::swc::transforms::resolver_with_mark;
use deno_ast::swc::transforms::typescript;
use deno_ast::swc::visit::FoldWith;
use deno_ast::Diagnostic;
@ -214,77 +216,81 @@ pub fn transpile(
source_map
.new_source_file(file_name, parsed_source.source().text().to_string());
let comments = parsed_source.comments().as_single_threaded(); // needs to be mutable
let globals = Globals::new();
deno_ast::swc::common::GLOBALS.set(&globals, || {
let top_level_mark = Mark::fresh(Mark::root());
let jsx_pass = chain!(
resolver_with_mark(top_level_mark),
react::react(
source_map.clone(),
Some(&comments),
react::Options {
pragma: options.jsx_factory.clone(),
pragma_frag: options.jsx_fragment_factory.clone(),
// this will use `Object.assign()` instead of the `_extends` helper
// when spreading props.
use_builtins: true,
..Default::default()
},
top_level_mark,
),
);
let mut passes = chain!(
Optional::new(jsx_pass, options.transform_jsx),
Optional::new(transforms::DownlevelImportsFolder, options.repl_imports),
Optional::new(transforms::StripExportsFolder, options.repl_imports),
proposals::decorators::decorators(proposals::decorators::Config {
legacy: true,
emit_metadata: options.emit_metadata
}),
helpers::inject_helpers(),
typescript::strip::strip_with_config(strip_config_from_emit_options(
options
)),
fixer(Some(&comments)),
hygiene(),
);
let jsx_pass = react::react(
source_map.clone(),
Some(&comments),
react::Options {
pragma: options.jsx_factory.clone(),
pragma_frag: options.jsx_fragment_factory.clone(),
// this will use `Object.assign()` instead of the `_extends` helper
// when spreading props.
use_builtins: true,
..Default::default()
},
);
let mut passes = chain!(
Optional::new(jsx_pass, options.transform_jsx),
Optional::new(transforms::DownlevelImportsFolder, options.repl_imports),
Optional::new(transforms::StripExportsFolder, options.repl_imports),
proposals::decorators::decorators(proposals::decorators::Config {
legacy: true,
emit_metadata: options.emit_metadata
}),
// DownlevelImportsFolder::new(), // todo: make this conditional
helpers::inject_helpers(),
typescript::strip::strip_with_config(strip_config_from_emit_options(
options
)),
fixer(Some(&comments)),
hygiene(),
);
let program = deno_ast::swc::common::GLOBALS.set(&Globals::new(), || {
helpers::HELPERS.set(&helpers::Helpers::new(false), || {
let program = helpers::HELPERS.set(&helpers::Helpers::new(false), || {
program.fold_with(&mut passes)
})
});
});
let mut src_map_buf = vec![];
let mut buf = vec![];
{
let writer = Box::new(JsWriter::new(
source_map.clone(),
"\n",
&mut buf,
Some(&mut src_map_buf),
));
let config = deno_ast::swc::codegen::Config { minify: false };
let mut emitter = deno_ast::swc::codegen::Emitter {
cfg: config,
comments: Some(&comments),
cm: source_map.clone(),
wr: writer,
};
program.emit_with(&mut emitter)?;
}
let mut src = String::from_utf8(buf)?;
let mut map: Option<String> = None;
{
let mut buf = Vec::new();
source_map
.build_source_map_from(&mut src_map_buf, None)
.to_writer(&mut buf)?;
if options.inline_source_map {
src.push_str("//# sourceMappingURL=data:application/json;base64,");
let encoded_map = base64::encode(buf);
src.push_str(&encoded_map);
} else {
map = Some(String::from_utf8(buf)?);
let mut src_map_buf = vec![];
let mut buf = vec![];
{
let writer = Box::new(JsWriter::new(
source_map.clone(),
"\n",
&mut buf,
Some(&mut src_map_buf),
));
let config = deno_ast::swc::codegen::Config { minify: false };
let mut emitter = deno_ast::swc::codegen::Emitter {
cfg: config,
comments: Some(&comments),
cm: source_map.clone(),
wr: writer,
};
program.emit_with(&mut emitter)?;
}
}
Ok((src, map))
let mut src = String::from_utf8(buf)?;
let mut map: Option<String> = None;
{
let mut buf = Vec::new();
source_map
.build_source_map_from(&mut src_map_buf, None)
.to_writer(&mut buf)?;
if options.inline_source_map {
src.push_str("//# sourceMappingURL=data:application/json;base64,");
let encoded_map = base64::encode(buf);
src.push_str(&encoded_map);
} else {
map = Some(String::from_utf8(buf)?);
}
}
Ok((src, map))
})
}
/// A low level function which transpiles a source module into an swc
@ -317,38 +323,43 @@ pub fn transpile_module(
}
})?;
let jsx_pass = react::react(
cm,
Some(&comments),
react::Options {
pragma: emit_options.jsx_factory.clone(),
pragma_frag: emit_options.jsx_fragment_factory.clone(),
// this will use `Object.assign()` instead of the `_extends` helper
// when spreading props.
use_builtins: true,
..Default::default()
},
);
let mut passes = chain!(
Optional::new(jsx_pass, emit_options.transform_jsx),
proposals::decorators::decorators(proposals::decorators::Config {
legacy: true,
emit_metadata: emit_options.emit_metadata
}),
helpers::inject_helpers(),
typescript::strip::strip_with_config(strip_config_from_emit_options(
emit_options
)),
fixer(Some(&comments)),
);
deno_ast::swc::common::GLOBALS.set(globals, || {
let top_level_mark = Mark::fresh(Mark::root());
let jsx_pass = chain!(
resolver_with_mark(top_level_mark),
react::react(
cm,
Some(&comments),
react::Options {
pragma: emit_options.jsx_factory.clone(),
pragma_frag: emit_options.jsx_fragment_factory.clone(),
// this will use `Object.assign()` instead of the `_extends` helper
// when spreading props.
use_builtins: true,
..Default::default()
},
top_level_mark,
),
);
let mut passes = chain!(
Optional::new(jsx_pass, emit_options.transform_jsx),
proposals::decorators::decorators(proposals::decorators::Config {
legacy: true,
emit_metadata: emit_options.emit_metadata
}),
helpers::inject_helpers(),
typescript::strip::strip_with_config(strip_config_from_emit_options(
emit_options
)),
fixer(Some(&comments)),
);
let module = deno_ast::swc::common::GLOBALS.set(globals, || {
helpers::HELPERS.set(&helpers::Helpers::new(false), || {
let module = helpers::HELPERS.set(&helpers::Helpers::new(false), || {
module.fold_with(&mut passes)
})
});
});
Ok((source_file, module))
Ok((source_file, module))
})
}
#[cfg(test)]
@ -385,6 +396,7 @@ mod tests {
media_type: deno_ast::MediaType::TypeScript,
capture_tokens: false,
maybe_syntax: None,
scope_analysis: false,
})
.expect("could not parse module");
let (code, maybe_map) = transpile(&module, &EmitOptions::default())
@ -413,6 +425,7 @@ mod tests {
media_type: deno_ast::MediaType::Tsx,
capture_tokens: false,
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())
@ -448,6 +461,7 @@ mod tests {
media_type: deno_ast::MediaType::TypeScript,
capture_tokens: false,
maybe_syntax: None,
scope_analysis: false,
})
.expect("could not parse module");
let (code, _) = transpile(&module, &EmitOptions::default())

View file

@ -199,15 +199,10 @@ pub fn get_lint_references(
parsed_source: &deno_ast::ParsedSource,
maybe_lint_config: Option<&LintConfig>,
) -> Result<Vec<Reference>, AnyError> {
let syntax = deno_ast::get_syntax(parsed_source.media_type());
let lint_rules =
get_configured_rules(maybe_lint_config, vec![], vec![], vec![])?;
let linter = create_linter(syntax, lint_rules);
// TODO(dsherret): do not re-parse here again
let (_, lint_diagnostics) = linter.lint(
parsed_source.specifier().to_string(),
parsed_source.source().text_str().to_string(),
)?;
let linter = create_linter(parsed_source.media_type(), lint_rules);
let lint_diagnostics = linter.lint_with_ast(parsed_source);
Ok(
lint_diagnostics
@ -357,6 +352,7 @@ pub fn parse_module(
// capture the tokens for linting and formatting
capture_tokens: true,
maybe_syntax: None,
scope_analysis: true, // for deno_lint
})
}

View file

@ -13,7 +13,6 @@ use crate::fmt_errors;
use crate::fs_util::{collect_files, is_supported_ext};
use crate::tools::fmt::run_parallelized;
use crate::{colors, file_watcher};
use deno_ast::swc::parser::Syntax;
use deno_ast::MediaType;
use deno_core::error::{anyhow, generic_error, AnyError, JsStackFrame};
use deno_core::serde_json;
@ -231,27 +230,26 @@ pub fn print_rules_list(json: bool) {
}
pub fn create_linter(
syntax: Syntax,
rules: Arc<Vec<Box<dyn LintRule>>>,
media_type: MediaType,
rules: Vec<Arc<dyn LintRule>>,
) -> Linter {
LinterBuilder::default()
.ignore_file_directive("deno-lint-ignore-file")
.ignore_diagnostic_directive("deno-lint-ignore")
.syntax(syntax)
.media_type(media_type)
.rules(rules)
.build()
}
fn lint_file(
file_path: PathBuf,
lint_rules: Arc<Vec<Box<dyn LintRule>>>,
lint_rules: Vec<Arc<dyn LintRule>>,
) -> Result<(Vec<LintDiagnostic>, String), AnyError> {
let file_name = file_path.to_string_lossy().to_string();
let source_code = fs::read_to_string(&file_path)?;
let media_type = MediaType::from(&file_path);
let syntax = deno_ast::get_syntax(media_type);
let linter = create_linter(syntax, lint_rules);
let linter = create_linter(media_type, lint_rules);
let (_, file_diagnostics) = linter.lint(file_name, source_code.clone())?;
@ -262,15 +260,14 @@ fn lint_file(
/// Treats input as TypeScript.
/// Compatible with `--json` flag.
fn lint_stdin(
lint_rules: Arc<Vec<Box<dyn LintRule>>>,
lint_rules: Vec<Arc<dyn LintRule>>,
) -> Result<(Vec<LintDiagnostic>, String), AnyError> {
let mut source_code = String::new();
if stdin().read_to_string(&mut source_code).is_err() {
return Err(generic_error("Failed to read from stdin"));
}
let syntax = deno_ast::get_syntax(MediaType::TypeScript);
let linter = create_linter(syntax, lint_rules);
let linter = create_linter(MediaType::TypeScript, lint_rules);
let (_, file_diagnostics) =
linter.lint(STDIN_FILE_NAME.to_string(), source_code.clone())?;
@ -489,7 +486,7 @@ pub(crate) fn get_configured_rules(
rules_tags: Vec<String>,
rules_include: Vec<String>,
rules_exclude: Vec<String>,
) -> Result<Arc<Vec<Box<dyn LintRule>>>, AnyError> {
) -> Result<Vec<Arc<dyn LintRule>>, AnyError> {
if maybe_lint_config.is_none()
&& rules_tags.is_empty()
&& rules_include.is_empty()

View file

@ -655,6 +655,7 @@ impl ReplSession {
media_type: deno_ast::MediaType::TypeScript,
capture_tokens: false,
maybe_syntax: None,
scope_analysis: false,
})?;
let transpiled_src = transpile(

View file

@ -566,6 +566,7 @@ fn extract_files_from_source_comments(
media_type,
capture_tokens: false,
maybe_syntax: None,
scope_analysis: false,
})?;
let comments = parsed_source.comments().get_vec();
let blocks_regex = Regex::new(r"```([^\n]*)\n([\S\s]*?)```")?;

View file

@ -978,7 +978,7 @@
symbolKeys,
(s1, s2) =>
StringPrototypeLocaleCompare(
(s1.description ?? ""),
s1.description ?? "",
s2.description ?? "",
),
);

View file

@ -225,7 +225,7 @@
if (idlType === "BufferSource" && idlValue) {
normalizedAlgorithm[member] = TypedArrayPrototypeSlice(
new Uint8Array(
(ArrayBufferIsView(idlValue) ? idlValue.buffer : idlValue),
ArrayBufferIsView(idlValue) ? idlValue.buffer : idlValue,
idlValue.byteOffset ?? 0,
idlValue.byteLength,
),

View file

@ -266,7 +266,7 @@
StringPrototypeReplace(
StringPrototypeReplace(
StringPrototypeReplace(
(isFilename ? str : StringPrototypeReplace(str, /\r?\n|\r/g, "\r\n")),
isFilename ? str : StringPrototypeReplace(str, /\r?\n|\r/g, "\r\n"),
/\n/g,
"%0A",
),

View file

@ -294,7 +294,6 @@ pub(crate) fn format_error(e: dlopen::Error, path: String) -> String {
use std::ffi::OsStr;
use std::os::windows::ffi::OsStrExt;
use winapi::shared::minwindef::DWORD;
use winapi::shared::ntdef::WCHAR;
use winapi::shared::winerror::ERROR_INSUFFICIENT_BUFFER;
use winapi::um::errhandlingapi::GetLastError;
use winapi::um::winbase::FormatMessageW;
@ -314,7 +313,7 @@ pub(crate) fn format_error(e: dlopen::Error, path: String) -> String {
let lang_id =
MAKELANGID(LANG_SYSTEM_DEFAULT, SUBLANG_SYS_DEFAULT) as DWORD;
let mut buf = vec![0 as WCHAR; 500];
let mut buf = vec![0; 500];
let path = OsStr::new(&path)
.encode_wide()

View file

@ -105,8 +105,9 @@
this[_list] = ArrayPrototypeMap(init, (pair, i) => {
if (pair.length !== 2) {
throw new TypeError(
`${prefix}: Item ${i +
0} in the parameter list does have length 2 exactly.`,
`${prefix}: Item ${
i + 0
} in the parameter list does have length 2 exactly.`,
);
}
return [pair[0], pair[1]];

View file

@ -1499,17 +1499,17 @@
if (canceled1 === false) {
readableStreamDefaultControllerEnqueue(
/** @type {ReadableStreamDefaultController<any>} */ (branch1[
/** @type {ReadableStreamDefaultController<any>} */ branch1[
_controller
]),
],
value1,
);
}
if (canceled2 === false) {
readableStreamDefaultControllerEnqueue(
/** @type {ReadableStreamDefaultController<any>} */ (branch2[
/** @type {ReadableStreamDefaultController<any>} */ branch2[
_controller
]),
],
value2,
);
}
@ -1519,16 +1519,16 @@
reading = false;
if (canceled1 === false) {
readableStreamDefaultControllerClose(
/** @type {ReadableStreamDefaultController<any>} */ (branch1[
/** @type {ReadableStreamDefaultController<any>} */ branch1[
_controller
]),
],
);
}
if (canceled2 === false) {
readableStreamDefaultControllerClose(
/** @type {ReadableStreamDefaultController<any>} */ (branch2[
/** @type {ReadableStreamDefaultController<any>} */ branch2[
_controller
]),
],
);
}
cancelPromise.resolve(undefined);
@ -1586,15 +1586,15 @@
uponRejection(reader[_closedPromise].promise, (r) => {
readableStreamDefaultControllerError(
/** @type {ReadableStreamDefaultController<any>} */ (branch1[
/** @type {ReadableStreamDefaultController<any>} */ branch1[
_controller
]),
],
r,
);
readableStreamDefaultControllerError(
/** @type {ReadableStreamDefaultController<any>} */ (branch2[
/** @type {ReadableStreamDefaultController<any>} */ branch2[
_controller
]),
],
r,
);
if (canceled1 === false || canceled2 === false) {
@ -2142,14 +2142,14 @@
const readableController = stream[_readable][_controller];
if (
readableStreamDefaultControllerCanCloseOrEnqueue(
/** @type {ReadableStreamDefaultController<O>} */ (readableController),
/** @type {ReadableStreamDefaultController<O>} */ readableController,
) === false
) {
throw new TypeError("Readable stream is unavailable.");
}
try {
readableStreamDefaultControllerEnqueue(
/** @type {ReadableStreamDefaultController<O>} */ (readableController),
/** @type {ReadableStreamDefaultController<O>} */ readableController,
chunk,
);
} catch (e) {
@ -2157,7 +2157,7 @@
throw stream[_readable][_storedError];
}
const backpressure = readableStreamDefaultcontrollerHasBackpressure(
/** @type {ReadableStreamDefaultController<O>} */ (readableController),
/** @type {ReadableStreamDefaultController<O>} */ readableController,
);
if (backpressure !== stream[_backpressure]) {
assert(backpressure === true);
@ -2192,7 +2192,7 @@
const stream = controller[_stream];
const readableController = stream[_readable][_controller];
readableStreamDefaultControllerClose(
/** @type {ReadableStreamDefaultController} */ (readableController),
/** @type {ReadableStreamDefaultController} */ readableController,
);
const error = new TypeError("The stream has been terminated.");
transformStreamErrorWritableAndUnblockWrite(stream, error);
@ -2224,7 +2224,7 @@
throw readable[_storedError];
}
readableStreamDefaultControllerClose(
/** @type {ReadableStreamDefaultController} */ (readable[_controller]),
/** @type {ReadableStreamDefaultController} */ readable[_controller],
);
}, (r) => {
transformStreamError(stream, r);
@ -2278,9 +2278,9 @@
*/
function transformStreamError(stream, e) {
readableStreamDefaultControllerError(
/** @type {ReadableStreamDefaultController} */ (stream[_readable][
/** @type {ReadableStreamDefaultController} */ stream[_readable][
_controller
]),
],
e,
);
transformStreamErrorWritableAndUnblockWrite(stream, e);
@ -3858,7 +3858,7 @@
webidl.assertBranded(this, TransformStreamDefaultController);
const readableController = this[_stream][_readable][_controller];
return readableStreamDefaultControllerGetDesiredSize(
/** @type {ReadableStreamDefaultController<O>} */ (readableController),
/** @type {ReadableStreamDefaultController<O>} */ readableController,
);
}

View file

@ -849,7 +849,7 @@
descriptor.usage,
options,
);
device.trackResource((buffer));
device.trackResource(buffer);
return buffer;
}
@ -878,7 +878,7 @@
device,
rid,
);
device.trackResource((texture));
device.trackResource(texture);
return texture;
}
@ -905,7 +905,7 @@
device,
rid,
);
device.trackResource((sampler));
device.trackResource(sampler);
return sampler;
}
@ -948,7 +948,7 @@
device,
rid,
);
device.trackResource((bindGroupLayout));
device.trackResource(bindGroupLayout);
return bindGroupLayout;
}
@ -990,7 +990,7 @@
device,
rid,
);
device.trackResource((pipelineLayout));
device.trackResource(pipelineLayout);
return pipelineLayout;
}
@ -1083,7 +1083,7 @@
device,
rid,
);
device.trackResource((bindGroup));
device.trackResource(bindGroup);
return bindGroup;
}
@ -1115,7 +1115,7 @@
device,
rid,
);
device.trackResource((shaderModule));
device.trackResource(shaderModule);
return shaderModule;
}
@ -1172,7 +1172,7 @@
device,
rid,
);
device.trackResource((computePipeline));
device.trackResource(computePipeline);
return computePipeline;
}
@ -1247,7 +1247,7 @@
device,
rid,
);
device.trackResource((renderPipeline));
device.trackResource(renderPipeline);
return renderPipeline;
}
@ -1284,7 +1284,7 @@
device,
rid,
);
device.trackResource((commandEncoder));
device.trackResource(commandEncoder);
return commandEncoder;
}
@ -1319,7 +1319,7 @@
device,
rid,
);
device.trackResource((renderBundleEncoder));
device.trackResource(renderBundleEncoder);
return renderBundleEncoder;
}
@ -1351,7 +1351,7 @@
rid,
descriptor,
);
device.trackResource((querySet));
device.trackResource(querySet);
return querySet;
}
@ -2436,7 +2436,7 @@
device,
rid,
);
device.trackResource((bindGroupLayout));
device.trackResource(bindGroupLayout);
return bindGroupLayout;
}
@ -2511,7 +2511,7 @@
device,
rid,
);
device.trackResource((bindGroupLayout));
device.trackResource(bindGroupLayout);
return bindGroupLayout;
}
@ -3277,7 +3277,7 @@
device,
rid,
);
device.trackResource((commandBuffer));
device.trackResource(commandBuffer);
return commandBuffer;
}
@ -4606,7 +4606,7 @@
device,
rid,
);
device.trackResource((renderBundle));
device.trackResource(renderBundle);
return renderBundle;
}

View file

@ -35,10 +35,11 @@
// ops. Note that "unref" ops are ignored since in nature that are
// optional.
function assertOps(fn) {
return async function asyncOpSanitizer(...params) {
/** @param step {TestStep} */
return async function asyncOpSanitizer(step) {
const pre = metrics();
try {
await fn(...params);
await fn(step);
} finally {
// Defer until next event loop turn - that way timeouts and intervals
// cleared can actually be removed from resource table, otherwise
@ -46,6 +47,10 @@
await new Promise((resolve) => setTimeout(resolve, 0));
}
if (step.hasRunningChildren) {
return; // test step validation error thrown, don't check ops
}
const post = metrics();
// We're checking diff because one might spawn HTTP server in the background
@ -101,9 +106,15 @@ finishing test case.`;
function assertResources(
fn,
) {
return async function resourceSanitizer(...params) {
/** @param step {TestStep} */
return async function resourceSanitizer(step) {
const pre = core.resources();
await fn(...params);
await fn(step);
if (step.hasRunningChildren) {
return; // test step validation error thrown, don't check resources
}
const post = core.resources();
const preStr = JSONStringify(pre, null, 2);
@ -195,11 +206,7 @@ finishing test case.`;
function postValidation() {
// check for any running steps
const hasRunningSteps = ArrayPrototypeSome(
step.children,
(r) => r.status === "pending",
);
if (hasRunningSteps) {
if (step.hasRunningChildren) {
throw new Error(
"There were still test steps running after the current scope finished execution. " +
"Ensure all steps are awaited (ex. `await t.step(...)`).",
@ -411,7 +418,7 @@ finishing test case.`;
const only = ArrayPrototypeFilter(tests, (test) => test.only);
const filtered = ArrayPrototypeFilter(
(only.length > 0 ? only : tests),
only.length > 0 ? only : tests,
createTestFilter(filter),
);
@ -485,6 +492,7 @@ finishing test case.`;
#reportedResult = false;
finalized = false;
elapsed = 0;
/** @type "ok" | "ignored" | "pending" | "failed" */
status = "pending";
error = undefined;
/** @type {TestStep[]} */
@ -521,6 +529,14 @@ finishing test case.`;
this.#params.sanitizeExit;
}
get hasRunningChildren() {
return ArrayPrototypeSome(
this.children,
/** @param step {TestStep} */
(step) => step.status === "pending",
);
}
failedChildStepsCount() {
return ArrayPrototypeFilter(
this.children,