diff --git a/Cargo.lock b/Cargo.lock index 14313d9..731b7f5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -12,26 +12,11 @@ dependencies = [ "regex", ] -[[package]] -name = "addr2line" -version = "0.21.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb" -dependencies = [ - "gimli", -] - -[[package]] -name = "adler" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" - [[package]] name = "ahash" -version = "0.7.7" +version = "0.7.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a824f2aa7e75a0c98c5a504fceb80649e9c35265d44525b5f94de4771a395cd" +checksum = "891477e0c6a8957309ee5c45a6368af3ae14bb510732d2684ffa19af310920f9" dependencies = [ "getrandom", "once_cell", @@ -47,6 +32,15 @@ dependencies = [ "memchr", ] +[[package]] +name = "allocator-api2" +version = "0.2.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c6cb57a04249c6480766f7f7cef5467412af1490f8d1e243141daddada3264f" +dependencies = [ + "serde", +] + [[package]] name = "ansi_term" version = "0.12.1" @@ -91,21 +85,6 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" -[[package]] -name = "backtrace" -version = "0.3.69" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2089b7e3f35b9dd2d0ed921ead4f6d318c27680d4a5bd167b3ee120edb105837" -dependencies = [ - "addr2line", - "cc", - "cfg-if", - "libc", - "miniz_oxide", - "object", - "rustc-demangle", -] - [[package]] name = "base64" version = "0.21.7" @@ -163,6 +142,15 @@ dependencies = [ "generic-array", ] +[[package]] +name = "bumpalo" +version = "3.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" +dependencies = [ + "allocator-api2", +] + [[package]] name = "bytecheck" version = "0.6.11" @@ -185,6 +173,12 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "bytes" +version = "1.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a12916984aab3fa6e39d655a33e09c0071eb36d6ab3aea5c2d78551f1df6d952" + [[package]] name = "camino" version = "1.1.6" @@ -203,20 +197,6 @@ dependencies = [ "serde", ] -[[package]] -name = "cargo_metadata" -version = "0.15.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eee4243f1f26fc7a42710e7439c149e2b10b05472f88090acce52632f231a73a" -dependencies = [ - "camino", - "cargo-platform", - "semver 1.0.21", - "serde", - "serde_json", - "thiserror", -] - [[package]] name = "cargo_metadata" version = "0.18.1" @@ -396,12 +376,6 @@ dependencies = [ "wasi", ] -[[package]] -name = "gimli" -version = "0.28.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" - [[package]] name = "glob" version = "0.3.1" @@ -496,12 +470,6 @@ dependencies = [ "syn 2.0.48", ] -[[package]] -name = "is_ci" -version = "1.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "616cde7c720bb2bb5824a224687d8f77bfd38922027f01d825cd7453be5099fb" - [[package]] name = "itoa" version = "1.0.10" @@ -559,19 +527,13 @@ checksum = "523dc4f511e55ab87b694dc30d0f820d60906ef06413f93d4d7a1385599cc149" [[package]] name = "miette" -version = "4.7.1" +version = "7.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1c90329e44f9208b55f45711f9558cec15d7ef8295cc65ecd6d4188ae8edc58c" +checksum = "4edc8853320c2a0dab800fbda86253c8938f6ea88510dc92c5f1ed20e794afc1" dependencies = [ - "atty", - "backtrace", + "cfg-if", "miette-derive", - "once_cell", "owo-colors", - "supports-color", - "supports-hyperlinks", - "supports-unicode", - "terminal_size", "textwrap", "thiserror", "unicode-width", @@ -579,29 +541,20 @@ dependencies = [ [[package]] name = "miette-derive" -version = "4.7.1" +version = "7.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6b5bc45b761bcf1b5e6e6c4128cd93b84c218721a8d9b894aa0aff4ed180174c" +checksum = "dcf09caffaac8068c346b6df2a7fc27a177fd20b39421a39ce0a211bde679a6c" dependencies = [ "proc-macro2", "quote", - "syn 1.0.109", -] - -[[package]] -name = "miniz_oxide" -version = "0.7.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e7810e0be55b428ada41041c41f32c9f1a42817901b4ccf45fa3d4b6561e74c7" -dependencies = [ - "adler", + "syn 2.0.48", ] [[package]] name = "new_debug_unreachable" -version = "1.0.4" +version = "1.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e4a24736216ec316047a1fc4252e27dabb04218aa4a3f37c6e7ddbf1f9782b54" +checksum = "650eef8c711430f1a879fdd01d4745a7deea475becfb90269c06775983bbf086" [[package]] name = "nu-ansi-term" @@ -654,15 +607,6 @@ dependencies = [ "libc", ] -[[package]] -name = "object" -version = "0.32.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" -dependencies = [ - "memchr", -] - [[package]] name = "once_cell" version = "1.19.0" @@ -683,9 +627,9 @@ checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39" [[package]] name = "owo-colors" -version = "3.5.0" +version = "4.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c1b04fb49957986fdce4d6ee7a65027d55d4b6d2265e5848bbb507b58ccfdb6f" +checksum = "caff54706df99d2a78a5a4e3455ff45448d81ef1bb63c22cd14052ca0e993a3f" [[package]] name = "parking_lot" @@ -922,12 +866,13 @@ dependencies = [ [[package]] name = "rkyv" -version = "0.7.42" +version = "0.7.44" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0200c8230b013893c0b2d6213d6ec64ed2b9be2e0e016682b7224ff82cff5c58" +checksum = "5cba464629b3394fc4dbc6f940ff8f5b4ff5c7aef40f29166fd4ad12acbc99c0" dependencies = [ "bitvec", "bytecheck", + "bytes", "hashbrown 0.12.3", "ptr_meta", "rend", @@ -948,12 +893,6 @@ dependencies = [ "syn 1.0.109", ] -[[package]] -name = "rustc-demangle" -version = "0.1.23" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76" - [[package]] name = "rustc-hash" version = "1.1.0" @@ -994,6 +933,12 @@ version = "1.0.16" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f98d2aa92eebf49b69786be48e4477826b256916e84a57ff2a4f21923b48eb4c" +[[package]] +name = "ryu-js" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ad97d4ce1560a5e27cec89519dc8300d1aa6035b099821261c651486a19e44d5" + [[package]] name = "scoped-tls" version = "1.0.1" @@ -1187,34 +1132,6 @@ dependencies = [ "syn 2.0.48", ] -[[package]] -name = "supports-color" -version = "1.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ba6faf2ca7ee42fdd458f4347ae0a9bd6bcc445ad7cb57ad82b383f18870d6f" -dependencies = [ - "atty", - "is_ci", -] - -[[package]] -name = "supports-hyperlinks" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "590b34f7c5f01ecc9d78dba4b3f445f31df750a67621cf31626f3b7441ce6406" -dependencies = [ - "atty", -] - -[[package]] -name = "supports-unicode" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a8b945e45b417b125a8ec51f1b7df2f8df7920367700d1f98aedd21e5735f8b2" -dependencies = [ - "atty", -] - [[package]] name = "swc-plugin-vue-jsx" version = "0.3.1" @@ -1239,11 +1156,23 @@ dependencies = [ "testing", ] +[[package]] +name = "swc_allocator" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dae2f696639ba1834a7edb1765a5ea0a7ef57de52ac1403135929bd006748731" +dependencies = [ + "allocator-api2", + "bumpalo", + "ptr_meta", + "triomphe", +] + [[package]] name = "swc_atoms" -version = "0.6.6" +version = "0.6.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "04d9d1941a7d24fc503efa29c53f88dd61e6a15cc371947a75cca3b48d564b5b" +checksum = "bb6567e4e67485b3e7662b486f1565bdae54bd5b9d6b16b2ba1a9babb1e42125" dependencies = [ "bytecheck", "hstr", @@ -1255,9 +1184,9 @@ dependencies = [ [[package]] name = "swc_common" -version = "0.33.23" +version = "0.36.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0523b2acc3b9938c51dd454956493d887cc40f0050206287f8599840010442d0" +checksum = "df5ed098e191c0cb289aa89eeae8a5312993cf0997e7c83e011e0a7dd1f6ce7b" dependencies = [ "anyhow", "ast_node", @@ -1276,6 +1205,7 @@ dependencies = [ "serde", "siphasher", "sourcemap", + "swc_allocator", "swc_atoms", "swc_eq_ignore_macros", "swc_visit", @@ -1287,11 +1217,12 @@ dependencies = [ [[package]] name = "swc_core" -version = "0.90.37" +version = "0.99.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ecbbbf25e5d035165bde87f2388f9fbe6d5ce38ddd2c6cb9f24084823a9c0044" +checksum = "359e202690a515fda2149b5d2e28234577fcb9c7827561ee9c795e5f453eb6e1" dependencies = [ "once_cell", + "swc_allocator", "swc_atoms", "swc_common", "swc_ecma_ast", @@ -1308,9 +1239,9 @@ dependencies = [ [[package]] name = "swc_ecma_ast" -version = "0.112.6" +version = "0.117.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70656acd47c91918635f1e8589963428cb3170975b71d786c79fb7a25605f687" +checksum = "536e973cd624cada731c22ad9ba3aa7a6432a5c1b6e002ec4f12809a8718da5d" dependencies = [ "bitflags 2.5.0", "bytecheck", @@ -1322,14 +1253,14 @@ dependencies = [ "string_enum", "swc_atoms", "swc_common", - "unicode-id", + "unicode-id-start", ] [[package]] name = "swc_ecma_codegen" -version = "0.148.18" +version = "0.154.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "154d03dc43e4033b668bc5021bd67088ff27f0d8da054348b5cd4e6fe94e7f26" +checksum = "6ca6056bb7016fdeaee8e3d792e3242a8cfa6f2a81a2010e7f6c5cb961719a17" dependencies = [ "memchr", "num-bigint", @@ -1358,9 +1289,9 @@ dependencies = [ [[package]] name = "swc_ecma_parser" -version = "0.143.16" +version = "0.148.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "40b7faa481ac015b330f1c4bc8df2c9947242020e23ccdb10bc7a8ef84342509" +checksum = "59627c3704453c1bcb283c51ee161a5acf9988c80f80ef0250743fede0406602" dependencies = [ "either", "new_debug_unreachable", @@ -1380,9 +1311,9 @@ dependencies = [ [[package]] name = "swc_ecma_testing" -version = "0.22.22" +version = "0.25.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7c5704ef494b1805bc4566ff566b964bc1e9d3fb0f0e046ad6392b09a54de844" +checksum = "60432dde66f551adda7014459d28b43f361170a20029b47d163905c6dcfa33cd" dependencies = [ "anyhow", "hex", @@ -1393,9 +1324,9 @@ dependencies = [ [[package]] name = "swc_ecma_transforms_base" -version = "0.137.21" +version = "0.143.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "660badfe2eed8b6213ec9dcd71aa0786f8fb46ffa012e0313bcba1fe4a9a5c73" +checksum = "cfe85a837d11d62a9370cf0e06ac5d2afa417b1367c272930df038f29e22ff81" dependencies = [ "better_scoped_tls", "bitflags 2.5.0", @@ -1416,9 +1347,9 @@ dependencies = [ [[package]] name = "swc_ecma_transforms_testing" -version = "0.140.18" +version = "0.146.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7c0ea6f85b7bf04391a172d7a369e49865effa77ec3a6cd0e969a274cfcb982d" +checksum = "366434f6d636c0d8590572e6dc479549d50a3451f7176c615781e1c0cee000ef" dependencies = [ "ansi_term", "anyhow", @@ -1442,14 +1373,15 @@ dependencies = [ [[package]] name = "swc_ecma_utils" -version = "0.127.20" +version = "0.133.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "15d40abfc4f3a7bfdf54d11ac705cc9dd0836c48bf085b359143b4d40b50cb31" +checksum = "51b1346598210788a9dd16580a74cad627726bd166157e3ff4628d8324d125b9" dependencies = [ "indexmap", "num_cpus", "once_cell", "rustc-hash", + "ryu-js", "swc_atoms", "swc_common", "swc_ecma_ast", @@ -1460,10 +1392,11 @@ dependencies = [ [[package]] name = "swc_ecma_visit" -version = "0.98.7" +version = "0.103.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "93692bdcdbb63db8f5e10fea5d202b5487cb27eb443aec424f4335c88f9864af" +checksum = "0c6fd5dd0479b531085242c2b30f81a1bfdafa473c89f58e00f380006d204a2b" dependencies = [ + "new_debug_unreachable", "num-bigint", "swc_atoms", "swc_common", @@ -1485,9 +1418,9 @@ dependencies = [ [[package]] name = "swc_error_reporters" -version = "0.17.19" +version = "0.20.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3329e73f159a3d38d4cd5f606a0918eeff39f5bbdbdafd9b6fecb290d2e9a32d" +checksum = "e02c81943772dc4fb0a6228360552d353fedc1a368ee6d80a5172ecb376b1796" dependencies = [ "anyhow", "miette", @@ -1509,9 +1442,9 @@ dependencies = [ [[package]] name = "swc_plugin" -version = "0.90.0" +version = "0.90.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ca5df720531bfbd7ceb1139319c39c20c446abfb8f7e0eb47b104205a71152b4" +checksum = "30ea2e5b148572342aec7f1db0e72ef464f23f25d0317a7d9f612fa100274c88" dependencies = [ "once_cell", ] @@ -1529,9 +1462,9 @@ dependencies = [ [[package]] name = "swc_plugin_proxy" -version = "0.41.6" +version = "0.46.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "012e5996e3fe64805342b6e31a79d826402bbe4eed35be6a9366e54e41f5d75d" +checksum = "19712a471479078252c013a33f24a6b9215630a1a75973a0c1532d7235f8abd2" dependencies = [ "better_scoped_tls", "rkyv", @@ -1554,9 +1487,9 @@ dependencies = [ [[package]] name = "swc_visit" -version = "0.5.14" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "043d11fe683dcb934583ead49405c0896a5af5face522e4682c16971ef7871b9" +checksum = "52e2acde04c355dc8ffd62c56f263ba61a94b5c6d21ce2cdeaf857b5d74451a6" dependencies = [ "either", "swc_visit_macros", @@ -1625,24 +1558,14 @@ dependencies = [ "winapi-util", ] -[[package]] -name = "terminal_size" -version = "0.1.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "633c1a546cee861a1a6d0dc69ebeca693bf4296661ba7852b9d21d159e0506df" -dependencies = [ - "libc", - "winapi", -] - [[package]] name = "testing" -version = "0.35.23" +version = "0.38.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "689e2661712768726869f62945ccbe5d76ab3a3957b88221275bebe22a0761c8" +checksum = "4ab10ecb9cf00ddccd7216451bd3fa5842969ce85c1139e8ddf7c14924a799e2" dependencies = [ "ansi_term", - "cargo_metadata 0.15.4", + "cargo_metadata", "difference", "once_cell", "pretty_assertions", @@ -1658,9 +1581,9 @@ dependencies = [ [[package]] name = "testing_macros" -version = "0.2.12" +version = "0.2.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f9d3864d4184569c1428645a51a304b3b6e8d3094cd61fb3cce8dfdd9f6d0f72" +checksum = "32d8d51dafe71c966464b06d3b5c1eca715590e952d20a908d003fd34791a773" dependencies = [ "anyhow", "glob", @@ -1674,9 +1597,9 @@ dependencies = [ [[package]] name = "textwrap" -version = "0.15.2" +version = "0.16.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b7b3e525a49ec206798b40326a44121291b530c963cfb01018f63e135bac543d" +checksum = "23d434d3f8967a09480fb04132ebe0a3e088c173e6d0ee7897abbdf4eab0f8b9" dependencies = [ "smawk", "unicode-linebreak", @@ -1791,9 +1714,9 @@ dependencies = [ [[package]] name = "triomphe" -version = "0.1.11" +version = "0.1.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "859eb650cfee7434994602c3a68b25d77ad9e68c8a6cd491616ef86661382eb3" +checksum = "e6631e42e10b40c0690bf92f404ebcfe6e1fdb480391d15f17cc8e96eeed5369" dependencies = [ "serde", "stable_deref_trait", @@ -1825,9 +1748,9 @@ checksum = "b1b6def86329695390197b82c1e244a54a131ceb66c996f2088a3876e2ae083f" [[package]] name = "unicode-id-start" -version = "1.0.4" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "02aebfa694eccbbbffdd92922c7de136b9fe764396d2f10e21bce1681477cfc1" +checksum = "bc3882f69607a2ac8cc4de3ee7993d8f68bb06f2974271195065b3bd07f2edea" [[package]] name = "unicode-ident" @@ -1886,7 +1809,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e27d6bdd219887a9eadd19e1c34f32e47fa332301184935c6d9bca26f3cca525" dependencies = [ "anyhow", - "cargo_metadata 0.18.1", + "cargo_metadata", "regex", "rustversion", ] diff --git a/plugin/Cargo.toml b/plugin/Cargo.toml index 4282ebf..cee0385 100644 --- a/plugin/Cargo.toml +++ b/plugin/Cargo.toml @@ -13,5 +13,5 @@ crate-type = ["cdylib"] [dependencies] serde_json = "1.0" -swc_core = { version = "0.90", features = ["ecma_plugin_transform"] } +swc_core = { version = "0.99", features = ["ecma_plugin_transform"] } swc-vue-jsx-visitor = { path = "../visitor", version = "*" } diff --git a/visitor/Cargo.toml b/visitor/Cargo.toml index 7a4eb32..4c5455e 100644 --- a/visitor/Cargo.toml +++ b/visitor/Cargo.toml @@ -14,7 +14,7 @@ fnv = "1.0" indexmap = "2.1" regex = "1.10" serde = { version = "1.0", features = ["derive"] } -swc_core = { version = "0.90", features = [ +swc_core = { version = "0.99", features = [ "ecma_parser", "ecma_plugin_transform", "ecma_utils", @@ -22,4 +22,4 @@ swc_core = { version = "0.90", features = [ [dev-dependencies] serde_json = "1.0" -testing = "0.35" +testing = "0.38" diff --git a/visitor/src/directive.rs b/visitor/src/directive.rs index eb0047c..e05ea66 100644 --- a/visitor/src/directive.rs +++ b/visitor/src/directive.rs @@ -53,7 +53,7 @@ pub(crate) fn parse_directive(jsx_attr: &JSXAttr, is_component: bool) -> Directi splitted, ) } - JSXAttrName::JSXNamespacedName(JSXNamespacedName { ns, name }) => { + JSXAttrName::JSXNamespacedName(JSXNamespacedName { ns, name, .. }) => { let mut splitted = name.sym.split('_'); ( ns.sym @@ -87,7 +87,7 @@ pub(crate) fn parse_directive(jsx_attr: &JSXAttr, is_component: bool) -> Directi if let Expr::Array(ArrayLit { elems, .. }) = &**expr { value = match elems.get(0) { Some(Some(ExprOrSpread { spread: None, expr })) => (**expr).clone(), - _ => Expr::Ident(quote_ident!("")), + _ => Expr::Ident(quote_ident!("").into()), }; if let Some(Some(ExprOrSpread { spread: None, expr })) = elems.get(1) { match &**expr { @@ -114,7 +114,7 @@ pub(crate) fn parse_directive(jsx_attr: &JSXAttr, is_component: bool) -> Directi } } else { modifiers = Some(splitted.map(JsWord::from).collect()); - value = Expr::Ident(quote_ident!("")); + value = Expr::Ident(quote_ident!("").into()); } Directive::Normal(NormalDirective { @@ -240,7 +240,7 @@ fn parse_v_model_directive( "You have to use JSX Expression inside your `v-model`.", ); }); - Expr::Ident(quote_ident!("")) + Expr::Ident(quote_ident!("").into()) } }; @@ -250,7 +250,7 @@ fn parse_v_model_directive( if let Expr::Array(ArrayLit { elems, .. }) = attr_value { value = match elems.get(0) { Some(Some(ExprOrSpread { spread: None, expr })) => (**expr).clone(), - _ => Expr::Ident(quote_ident!("")), + _ => Expr::Ident(quote_ident!("").into()), }; if let Some(Some(ExprOrSpread { spread: None, expr })) = elems.get(1) { match &**expr { diff --git a/visitor/src/lib.rs b/visitor/src/lib.rs index 5981098..a2d132f 100644 --- a/visitor/src/lib.rs +++ b/visitor/src/lib.rs @@ -163,7 +163,7 @@ where span: DUMMY_SP, callee: Callee::Expr(Box::new(Expr::Ident(self.get_pragma()))), args: vnode_call_args, - type_args: None, + ..Default::default() }); if directives.is_empty() { @@ -224,7 +224,7 @@ where })), }, ], - type_args: None, + ..Default::default() }) } } @@ -251,7 +251,7 @@ where expr: Box::new(self.transform_children(&jsx_fragment.children, false, None)), }, ], - type_args: None, + ..Default::default() }) } @@ -284,7 +284,7 @@ where spread: None, expr: Box::new(Expr::Lit(Lit::Str(quote_str!(name)))), }], - type_args: None, + ..Default::default() }) } else { Expr::Ident(ident.clone()) @@ -448,7 +448,7 @@ where value: Box::new(Expr::Arrow(ArrowExpr { span: DUMMY_SP, params: vec![Pat::Ident(BindingIdent { - id: quote_ident!("$event"), + id: quote_ident!("$event").into(), type_ann: None, })], body: Box::new(BlockStmtOrExpr::Expr(Box::new( @@ -458,18 +458,17 @@ where left: AssignTarget::Simple( SimpleAssignTarget::Paren(ParenExpr { span: DUMMY_SP, - expr: Box::new(directive.value) + expr: Box::new(directive.value), }), ), - right: Box::new(Expr::Ident(quote_ident!( - "$event" - ))), + right: Box::new(Expr::Ident( + quote_ident!("$event").into(), + )), }), ))), is_async: false, is_generator: false, - type_params: None, - return_type: None, + ..Default::default() })), }, )))); @@ -557,7 +556,7 @@ where spread: None, expr: attr_value, }], - type_args: None, + ..Default::default() })); } else { props.push(PropOrSpread::Prop(Box::new(Prop::KeyValue( @@ -618,7 +617,7 @@ where expr: Box::new(expr), }) .collect(), - type_args: None, + ..Default::default() }), } } else if !props.is_empty() { @@ -764,7 +763,7 @@ where spread: None, expr: Box::new(expr.clone()), }], - type_args: None, + ..Default::default() })), cons: Box::new(expr.clone()), alt: Box::new(self.wrap_children(elems, slot_flag, slots)), @@ -790,15 +789,15 @@ where span: DUMMY_SP, op: op!("="), left: AssignTarget::Simple(SimpleAssignTarget::Paren( - ParenExpr{ + ParenExpr { span: DUMMY_SP, expr: Box::new(Expr::Ident(slot_ident.clone())), - } + }, )), right: Box::new(expr.clone()), })), }], - type_args: None, + ..Default::default() })), cons: Box::new(Expr::Ident(slot_ident.clone())), alt: { @@ -878,8 +877,7 @@ where })))), is_async: false, is_generator: false, - type_params: None, - return_type: None, + ..Default::default() })), })))]; @@ -946,7 +944,7 @@ where spread: None, expr: Box::new(Expr::Lit(Lit::Str(quote_str!(text)))), }], - type_args: None, + ..Default::default() })) } } @@ -997,7 +995,7 @@ where spread: None, expr: Box::new(Expr::Lit(Lit::Str(quote_str!(directive_name)))), }], - type_args: None, + ..Default::default() }), } } @@ -1033,7 +1031,7 @@ where self.pragma .as_ref() .or(self.options.pragma.as_ref()) - .map(|name| quote_ident!(name.as_str())) + .map(|name| quote_ident!(name.as_str()).into()) .unwrap_or_else(|| self.import_from_vue("createVNode")) } @@ -1085,15 +1083,15 @@ where span: DUMMY_SP, arg: Some(Box::new(Expr::Ident(ident))), })], + ..Default::default() }), is_generator: false, is_async: false, - type_params: None, - return_type: None, + ..Default::default() }), }))), args: vec![], - type_args: None, + ..Default::default() }))), definite: false, }); @@ -1121,7 +1119,7 @@ where .and_then(|expr| expr.as_ident()) .and_then(|ident| { self.define_component - .map(|ctxt| ctxt == ident.span.ctxt() && ident.sym == "defineComponent") + .map(|ctxt| ctxt == ident.ctxt && ident.sym == "defineComponent") }) .unwrap_or_default() } @@ -1146,8 +1144,8 @@ where ModuleItem::Stmt(Stmt::Decl(Decl::Var(Box::new(VarDecl { span: DUMMY_SP, kind: VarDeclKind::Const, - declare: false, decls: mem::take(&mut self.injecting_consts), + ..Default::default() })))), ); } @@ -1158,8 +1156,8 @@ where ModuleItem::Stmt(Stmt::Decl(Decl::Var(Box::new(VarDecl { span: DUMMY_SP, kind: VarDeclKind::Let, - declare: false, decls: mem::take(&mut self.injecting_vars), + ..Default::default() })))), ); self.slot_counter = 1; @@ -1204,7 +1202,9 @@ where ImportSpecifier::Named(ImportNamedSpecifier { span: DUMMY_SP, local: local.clone(), - imported: Some(ModuleExportName::Ident(quote_ident!(*imported))), + imported: Some(ModuleExportName::Ident( + quote_ident!(*imported).into(), + )), is_type_only: false, }) }) @@ -1227,8 +1227,8 @@ where Stmt::Decl(Decl::Var(Box::new(VarDecl { span: DUMMY_SP, kind: VarDeclKind::Const, - declare: false, decls: mem::take(&mut self.injecting_consts), + ..Default::default() }))), ); } @@ -1239,8 +1239,8 @@ where Stmt::Decl(Decl::Var(Box::new(VarDecl { span: DUMMY_SP, kind: VarDeclKind::Let, - declare: false, decls: mem::take(&mut self.injecting_vars), + ..Default::default() }))), ); self.slot_counter = 1; @@ -1258,8 +1258,8 @@ where stmts.push(Stmt::Decl(Decl::Var(Box::new(VarDecl { span: DUMMY_SP, kind: VarDeclKind::Const, - declare: false, decls: mem::take(&mut self.injecting_consts), + ..Default::default() })))); } @@ -1267,8 +1267,8 @@ where stmts.push(Stmt::Decl(Decl::Var(Box::new(VarDecl { span: DUMMY_SP, kind: VarDeclKind::Let, - declare: false, decls: mem::take(&mut self.injecting_vars), + ..Default::default() })))); self.slot_counter = 1; } @@ -1281,6 +1281,7 @@ where arrow_expr.body = Box::new(BlockStmtOrExpr::BlockStmt(BlockStmt { span: DUMMY_SP, stmts, + ..Default::default() })); } } @@ -1315,7 +1316,7 @@ where .enumerate() .find_map(|(i, jsx_attr_or_spread)| match jsx_attr_or_spread { JSXAttrOrSpread::JSXAttr(JSXAttr { - name: JSXAttrName::Ident(Ident { sym, .. }), + name: JSXAttrName::Ident(IdentName { sym, .. }), .. }) if sym == "v-models" => Some(i), _ => None, @@ -1372,7 +1373,7 @@ where .. }) = specifier { - (local.sym == "defineComponent").then_some(local.span.ctxt()) + (local.sym == "defineComponent").then_some(local.ctxt) } else { None } @@ -1385,10 +1386,7 @@ where fn visit_mut_ts_interface_decl(&mut self, ts_interface_decl: &mut TsInterfaceDecl) { ts_interface_decl.visit_mut_children_with(self); if self.options.resolve_type { - let key = ( - ts_interface_decl.id.sym.clone(), - ts_interface_decl.id.span.ctxt(), - ); + let key = (ts_interface_decl.id.sym.clone(), ts_interface_decl.id.ctxt); if let Some(interface) = self.interfaces.get_mut(&key) { interface .body @@ -1406,7 +1404,7 @@ where self.type_aliases.insert( ( ts_type_alias_decl.id.sym.clone(), - ts_type_alias_decl.id.span.ctxt(), + ts_type_alias_decl.id.ctxt, ), (*ts_type_alias_decl.type_ann).clone(), ); diff --git a/visitor/src/resolve_type.rs b/visitor/src/resolve_type.rs index 9b19e6b..20263bc 100644 --- a/visitor/src/resolve_type.rs +++ b/visitor/src/resolve_type.rs @@ -63,7 +63,7 @@ where if let PropOrSpread::Prop(prop) = prop { match &**prop { Prop::Shorthand(ident) => Some(( - Cow::Owned(PropName::Ident(ident.clone())), + Cow::Owned(PropName::Ident(ident.clone().into())), Expr::Arrow(ArrowExpr { params: vec![], body: Box::new(BlockStmtOrExpr::Expr(Box::new( @@ -71,9 +71,8 @@ where ))), is_async: false, is_generator: false, - type_params: None, - return_type: None, span: DUMMY_SP, + ..Default::default() }), )), Prop::KeyValue(KeyValueProp { key, value }) => { @@ -92,9 +91,8 @@ where )), is_async: false, is_generator: false, - type_params: None, - return_type: None, span: DUMMY_SP, + ..Default::default() }) }, )) @@ -116,9 +114,8 @@ where )), is_async: false, is_generator: false, - type_params: None, - return_type: None, span: DUMMY_SP, + ..Default::default() }), )) } @@ -171,7 +168,6 @@ where spread: None, }, ], - type_args: None, span: if let Some(comments) = &self.comments { let span = Span::dummy_with_cmt(); comments.add_pure_comment(span.lo); @@ -179,6 +175,7 @@ where } else { DUMMY_SP }, + ..Default::default() }) } None => Expr::Object(self.build_props_type(first_param_type, None)), @@ -204,13 +201,6 @@ where optional, type_ann, .. - }) - | RefinedTsTypeElement::GetterSignature(TsGetterSignature { - key, - computed, - optional, - type_ann, - .. }) => { let prop_name = extract_prop_name(*key, computed); let types = if let Some(type_ann) = type_ann { @@ -238,6 +228,36 @@ where ); } } + + RefinedTsTypeElement::GetterSignature(TsGetterSignature { + key, + computed, + type_ann, + .. + }) => { + let prop_name = extract_prop_name(*key, computed); + let types = if let Some(type_ann) = type_ann { + self.infer_runtime_type(&type_ann.type_ann) + } else { + let mut types = IndexSet::with_capacity(1); + types.insert(None); + types + }; + if let Some((_, ir)) = irs + .iter_mut() + .find(|(key, _)| prop_name.eq_ignore_span(key)) + { + ir.types.extend(types); + } else { + irs.insert( + prop_name, + PropIr { + types, + required: true, + }, + ); + } + } RefinedTsTypeElement::MethodSignature(TsMethodSignature { key, computed, @@ -281,7 +301,7 @@ where key: PropName::Ident(quote_ident!("type")), value: Box::new(if ir.types.len() == 1 { if let Some(ty) = ir.types.pop().unwrap() { - Expr::Ident(quote_ident!(ty)) + Expr::Ident(quote_ident!(ty).into()) } else { Expr::Lit(Lit::Null(Null { span: DUMMY_SP })) } @@ -293,7 +313,7 @@ where .map(|ty| { Some(ExprOrSpread { expr: Box::new(if let Some(ty) = ty { - Expr::Ident(quote_ident!(ty)) + Expr::Ident(quote_ident!(ty).into()) } else { Expr::Lit(Lit::Null(Null { span: DUMMY_SP })) }), @@ -316,12 +336,12 @@ where if let Some((_, default)) = defaults.iter().flatten().find(|(name, _)| { name.eq_ignore_span(&prop_name) || if let ( - PropName::Ident(Ident { sym: a, .. }), + PropName::Ident(IdentName { sym: a, .. }), PropName::Str(Str { value: b, .. }), ) | ( PropName::Str(Str { value: a, .. }), - PropName::Ident(Ident { sym: b, .. }), + PropName::Ident(IdentName { sym: b, .. }), ) = (&**name, &prop_name) { a == b @@ -380,7 +400,7 @@ where span, .. }) => { - let key = (ident.sym.clone(), ident.span.ctxt()); + let key = (ident.sym.clone(), ident.ctxt); if let Some(aliased) = self.type_aliases.get(&key) { self.resolve_type_elements(aliased, props); } else if let Some(TsInterfaceDecl { @@ -417,7 +437,7 @@ where props, ) }); - } else if ident.span.ctxt().has_mark(self.unresolved_mark) { + } else if ident.ctxt.has_mark(self.unresolved_mark) { match &*ident.sym { "Partial" => { if let Some(param) = type_params @@ -434,9 +454,7 @@ where RefinedTsTypeElement::MethodSignature(method) => { method.optional = true; } - RefinedTsTypeElement::GetterSignature(getter) => { - getter.optional = true; - } + RefinedTsTypeElement::GetterSignature(..) => {} RefinedTsTypeElement::CallSignature(..) => {} } prop @@ -458,13 +476,11 @@ where }) | RefinedTsTypeElement::MethodSignature( TsMethodSignature { optional, .. }, - ) - | RefinedTsTypeElement::GetterSignature( - TsGetterSignature { optional, .. }, ) => { *optional = false; } - RefinedTsTypeElement::CallSignature(..) => {} + RefinedTsTypeElement::GetterSignature(..) + | RefinedTsTypeElement::CallSignature(..) => {} } prop })); @@ -605,12 +621,9 @@ where type_name: TsEntityName::Ident(ident), .. }) => { - if let Some(aliased) = self - .type_aliases - .get(&(ident.sym.clone(), ident.span.ctxt())) - { + if let Some(aliased) = self.type_aliases.get(&(ident.sym.clone(), ident.ctxt)) { self.resolve_string_or_union_strings(aliased) - } else if ident.span.ctxt().has_mark(self.unresolved_mark) { + } else if ident.ctxt.has_mark(self.unresolved_mark) { HANDLER.with(|handler| { handler.span_err( ty.span(), @@ -640,7 +653,7 @@ where type_params, .. }) => { - let key = (ident.sym.clone(), ident.span.ctxt()); + let key = (ident.sym.clone(), ident.ctxt); if let Some(aliased) = self.type_aliases.get(&key) { self.resolve_indexed_access(aliased, index) } else if let Some(interface) = self.interfaces.get(&key) { @@ -678,7 +691,9 @@ where }) => type_ann.as_ref().map(|type_ann| type_ann.type_ann.clone()), TsTypeElement::TsMethodSignature(..) => { Some(Box::new(TsType::TsTypeRef(TsTypeRef { - type_name: TsEntityName::Ident(quote_ident!("Function")), + type_name: TsEntityName::Ident( + quote_ident!("Function").into(), + ), type_params: None, span: DUMMY_SP, }))) @@ -732,9 +747,9 @@ where { if keys.contains(key) { Some(Box::new(TsType::TsTypeRef(TsTypeRef { - type_name: TsEntityName::Ident(quote_ident!( - "Function" - )), + type_name: TsEntityName::Ident( + quote_ident!("Function").into(), + ), type_params: None, span: DUMMY_SP, }))) @@ -764,7 +779,7 @@ where }), )) } - } else if ident.span.ctxt().has_mark(self.unresolved_mark) { + } else if ident.ctxt.has_mark(self.unresolved_mark) { if ident.sym == "Array" { type_params .as_ref() @@ -809,7 +824,7 @@ where }) => type_ann.as_ref().map(|type_ann| type_ann.type_ann.clone()), TsTypeElement::TsMethodSignature(..) => { Some(Box::new(TsType::TsTypeRef(TsTypeRef { - type_name: TsEntityName::Ident(quote_ident!("Function")), + type_name: TsEntityName::Ident(quote_ident!("Function").into()), type_params: None, span: DUMMY_SP, }))) @@ -860,9 +875,9 @@ where { if keys.contains(key) { Some(Box::new(TsType::TsTypeRef(TsTypeRef { - type_name: TsEntityName::Ident(quote_ident!( - "Function" - )), + type_name: TsEntityName::Ident( + quote_ident!("Function").into(), + ), type_params: None, span: DUMMY_SP, }))) @@ -996,7 +1011,7 @@ where type_params, .. }) => { - let key = (ident.sym.clone(), ident.span.ctxt()); + let key = (ident.sym.clone(), ident.ctxt); if let Some(aliased) = self.type_aliases.get(&key) { runtime_types.extend(self.infer_runtime_type(aliased)); } else if let Some(TsInterfaceDecl { @@ -1180,7 +1195,7 @@ where fn extract_prop_name(expr: Expr, computed: bool) -> PropName { match expr { - Expr::Ident(ident) => PropName::Ident(ident), + Expr::Ident(ident) => PropName::Ident(ident.into()), Expr::Lit(Lit::Str(str)) => PropName::Str(str), Expr::Lit(Lit::Num(num)) => PropName::Num(num), Expr::Lit(Lit::BigInt(bigint)) => PropName::BigInt(bigint), @@ -1204,7 +1219,7 @@ fn try_unwrap_lit_prop_name(prop_name: &PropName) -> Option> { Some(Cow::Borrowed(prop_name)) } PropName::Computed(ComputedPropName { expr, .. }) => match &**expr { - Expr::Ident(ident) => Some(Cow::Owned(PropName::Ident(ident.clone()))), + Expr::Ident(ident) => Some(Cow::Owned(PropName::Ident(ident.clone().into()))), Expr::Lit(Lit::Str(str)) => Some(Cow::Owned(PropName::Str(str.clone()))), Expr::Lit(Lit::Num(num)) => Some(Cow::Owned(PropName::Num(num.clone()))), Expr::Lit(Lit::BigInt(bigint)) => Some(Cow::Owned(PropName::BigInt(bigint.clone()))), diff --git a/visitor/src/util.rs b/visitor/src/util.rs index 8691a21..8b1a294 100644 --- a/visitor/src/util.rs +++ b/visitor/src/util.rs @@ -64,7 +64,7 @@ pub(crate) fn build_slot_helper(helper_name: Ident, is_vnode: Ident) -> FnDecl { spread: None, expr: Box::new(Expr::Ident(arg.clone())), }], - type_args: None, + ..Default::default() })), right: Box::new(Expr::Lit(Lit::Str(quote_str!("[object Object]")))), })), @@ -78,17 +78,17 @@ pub(crate) fn build_slot_helper(helper_name: Ident, is_vnode: Ident) -> FnDecl { spread: None, expr: Box::new(Expr::Ident(arg)), }], - type_args: None, + ..Default::default() })), })), })), }))), })], + ..Default::default() }), is_generator: false, is_async: false, - type_params: None, - return_type: None, + ..Default::default() }), } } @@ -247,6 +247,7 @@ pub(crate) fn decouple_v_models( span: DUMMY_SP, name: if let Some(argument) = argument { JSXAttrName::JSXNamespacedName(JSXNamespacedName { + span: DUMMY_SP, ns: quote_ident!("v-model"), name: quote_ident!(argument), })