diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f98a42b4..9c856dba 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -21,16 +21,6 @@ jobs: - name: Test (Luau) run: cargo test --features luau - # TODO: ideally this step isn't needed, but we have to gate some tests behind release mode - # we do this to ensure they still run in CI - # https://github.com/Kampfkarren/full-moon/issues/140 - test_luau_release: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - name: Test (Luau - Release mode) - run: cargo test --features luau --release - test_lua52: runs-on: ubuntu-latest steps: @@ -52,6 +42,13 @@ jobs: - name: Test (Lua 5.4) run: cargo test --features lua54 + test_luajit: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Test (LuaJIT) + run: cargo test --features luajit + test_wasm: runs-on: ubuntu-latest steps: @@ -59,7 +56,7 @@ jobs: - name: Test Build (wasm) run: | rustup target add wasm32-unknown-unknown - cargo check --target wasm32-unknown-unknown + cargo check --target wasm32-unknown-unknown --features luau,lua52,lua53,lua54,luajit test_wasm_build: runs-on: ubuntu-latest diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index bc453585..cf4dcb09 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -67,7 +67,7 @@ jobs: sudo apt install ${{ matrix.linker }} - name: Build Binary (All features) - run: cargo build --verbose --locked --release --features lua52,lua53,lua54,luau --target ${{ matrix.cargo-target }} + run: cargo build --verbose --locked --release --features lua52,lua53,lua54,luau,luajit --target ${{ matrix.cargo-target }} env: CARGO_TARGET_DIR: output diff --git a/CHANGELOG.md b/CHANGELOG.md index 751a160e..36778783 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,8 +9,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added +- Added runtime syntax configuration option `syntax` to help handle ambiguous syntax. By default, StyLua builds and runs with a parser to handle all Lua versions. However, the syntax of some Lua versions conflict with eachother: most notably, Lua 5.2+ goto label syntax `::label::` and Luau type assertion operator `::`. This option allows choosing what syntax to parse, to handle these conflicts. ([#407](https://github.com/JohnnyMorganz/StyLua/issues/407)) - Added configuration option `space_after_function_names` to specify whether to include a space between a function name and parentheses ([#839](https://github.com/JohnnyMorganz/StyLua/issues/839)) +### Changed + +- Update internal Lua parser version (full-moon) to v1.1.0. This includes parser performance improvements. ([#854](https://github.com/JohnnyMorganz/StyLua/issues/854)) +- LuaJIT is now separated from Lua52, and is available in its own feature and syntax flag + ### Fixed - Fixed formatting of method call chain when there is a comment between the colon token `:` and the function name ([#890](https://github.com/JohnnyMorganz/StyLua/issues/890)) diff --git a/Cargo.lock b/Cargo.lock index 75a68022..f5d0316b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,9 +4,9 @@ version = 3 [[package]] name = "aho-corasick" -version = "1.0.5" +version = "1.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c378d78423fdad8089616f827526ee33c19f2fddbd5de1629152c9593ba4783" +checksum = "b2969dcb958b36655471fc61f7e416fa76033bdd4bfed0678d8fee1e2d07a1f0" dependencies = [ "memchr", ] @@ -19,21 +19,21 @@ checksum = "4b46cbb362ab8752921c97e041f5e366ee6297bd428a31275b9fcf1e380f7299" [[package]] name = "anstyle" -version = "1.0.3" +version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b84bf0a05bbb2a83e5eb6fa36bb6e87baa08193c35ff52bbf6b38d8af2890e46" +checksum = "7079075b41f533b8c61d2a4d073c4676e1f8b249ff94a393b0595db304e0dd87" [[package]] name = "anyhow" -version = "1.0.75" +version = "1.0.79" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4668cab20f66d8d020e1fbc0ebe47217433c1b6c8f2040faf858554e394ace6" +checksum = "080e9890a082662b09c1ad45f567faeeb47f22b5fb23895fbe1e651e718e25ca" [[package]] name = "assert_cmd" -version = "2.0.12" +version = "2.0.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88903cb14723e4d4003335bb7f8a14f27691649105346a0f0957466c096adfe6" +checksum = "00ad3f3a942eee60335ab4342358c161ee296829e0d16ff42fc1d6cb07815467" dependencies = [ "anstyle", "bstr", @@ -46,9 +46,9 @@ dependencies = [ [[package]] name = "assert_fs" -version = "1.0.13" +version = "1.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f070617a68e5c2ed5d06ee8dd620ee18fb72b99f6c094bed34cf8ab07c875b48" +checksum = "2cd762e110c8ed629b11b6cde59458cc1c71de78ebbcc30099fc8e0403a2a2ec" dependencies = [ "anstyle", "doc-comment", @@ -72,15 +72,9 @@ dependencies = [ [[package]] name = "autocfg" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" - -[[package]] -name = "beef" -version = "0.5.2" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3a8241f3ebb85c056b509d4327ad0358fbbba6ffb340bf388f26350aeda225b1" +checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] name = "bitflags" @@ -90,32 +84,41 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] name = "bitflags" -version = "2.4.0" +version = "2.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b4682ae6287fcf752ecaabbfcc7b6f9b72aa33933dc23a554d853aea8eea8635" +checksum = "ed570934406eb16438a4e976b1b4500774099c13b8cb96eec99f620f05090ddf" + +[[package]] +name = "borsh" +version = "1.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6362ed55def622cddc70a4746a68554d7b687713770de539e59a739b249f8ed" +dependencies = [ + "cfg_aliases", +] [[package]] name = "bstr" -version = "1.6.2" +version = "1.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c2f7349907b712260e64b0afe2f84692af14a454be26187d9df565c7f69266a" +checksum = "c48f0051a4b4c5e0b6d365cd04af53aeaa209e3cc15ec2cdb69e73cc87fbd0dc" dependencies = [ "memchr", - "regex-automata 0.3.9", + "regex-automata", "serde", ] [[package]] name = "bumpalo" -version = "3.12.0" +version = "3.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0d261e256854913907f67ed06efbc3338dfe6179796deefc1ff763fc1aee5535" +checksum = "7f30e7476521f6f8af1a1c4c0b8cc94f0bee37d91763d0ca2665f299b6cd8aec" [[package]] name = "bytecount" -version = "0.6.3" +version = "0.6.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2c676a478f63e9fa2dd5368a42f28bba0d6c560b775f38583c8bbaa7fcd67c9c" +checksum = "e1e5f035d16fc623ae5f74981db80a439803888314e3a555fd6f04acd51a3205" [[package]] name = "cast" @@ -123,26 +126,23 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "37b2a672a2cb129a2e41c10b1224bb368f9f37a2b16b612598138befd7b37eb5" -[[package]] -name = "cc" -version = "1.0.83" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1174fb0b6ec23863f8b971027804a42614e347eafb0a95bf0b12cdae21fc4d0" -dependencies = [ - "libc", -] - [[package]] name = "cfg-if" version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "cfg_aliases" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "613afe47fcd5fac7ccf1db93babcb082c5994d996f20b8b159f2ad1658eb5724" + [[package]] name = "ciborium" -version = "0.2.0" +version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b0c137568cc60b904a7724001b35ce2630fd00d5d84805fbb608ab89509d788f" +checksum = "42e69ffd6f0917f5c029256a24d0161db17cea3997d185db0d35926308770f0e" dependencies = [ "ciborium-io", "ciborium-ll", @@ -151,15 +151,15 @@ dependencies = [ [[package]] name = "ciborium-io" -version = "0.2.0" +version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "346de753af073cc87b52b2083a506b38ac176a44cfb05497b622e27be899b369" +checksum = "05afea1e0a06c9be33d539b876f1ce3692f4afea2cb41f740e7743225ed1c757" [[package]] name = "ciborium-ll" -version = "0.2.0" +version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "213030a2b5a4e0c0892b6652260cf6ccac84827b83a85a534e178e3906c4cf1b" +checksum = "57663b653d948a338bfb3eeba9bb2fd5fcfaecb9e199e87e1eda4d9e8b240fd9" dependencies = [ "ciborium-io", "half", @@ -167,16 +167,16 @@ dependencies = [ [[package]] name = "clap" -version = "3.1.6" +version = "3.2.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d8c93436c21e4698bacadf42917db28b23017027a4deccb35dbe47a7e7840123" +checksum = "4ea181bf566f71cb9a5d17a59e1871af638180a18fb0035c92ae62b705207123" dependencies = [ "atty", "bitflags 1.3.2", "clap_derive", - "indexmap 1.7.0", - "lazy_static", - "os_str_bytes", + "clap_lex", + "indexmap 1.9.3", + "once_cell", "strsim", "termcolor", "textwrap", @@ -184,36 +184,39 @@ dependencies = [ [[package]] name = "clap_derive" -version = "3.1.4" +version = "3.2.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da95d038ede1a964ce99f49cbe27a7fb538d1da595e4b4f70b8c8f338d17bf16" +checksum = "ae6371b8bdc8b7d3959e9cf7b22d4435ef3e79e138688421ec654acf8c81b008" dependencies = [ "heck", "proc-macro-error", "proc-macro2", "quote", - "syn 1.0.76", + "syn 1.0.109", +] + +[[package]] +name = "clap_lex" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2850f2f5a82cbf437dd5af4d49848fbdfc27c157c3d010345776f952765261c5" +dependencies = [ + "os_str_bytes", ] [[package]] name = "console" -version = "0.15.7" +version = "0.15.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c926e00cc70edefdc64d3a5ff31cc65bb97a3460097762bd23afb4d8145fccf8" +checksum = "0e1f83fc076bd6dd27517eacdf25fef6c4dfe5f1d7448bafaaf3a26f13b5e4eb" dependencies = [ "encode_unicode", "lazy_static", "libc", "unicode-width", - "windows-sys 0.45.0", + "windows-sys", ] -[[package]] -name = "convert_case" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6245d59a3e82a7fc217c5828a6692dbc6dfb63a0c8c90495621f7b9d79704a0e" - [[package]] name = "criterion" version = "0.4.0" @@ -226,7 +229,7 @@ dependencies = [ "ciborium", "clap", "criterion-plot", - "itertools 0.10.1", + "itertools", "lazy_static", "num-traits", "oorandom", @@ -247,64 +250,68 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6b50826342786a51a89e2da3a28f1c32b06e387201bc2d19791f622c673706b1" dependencies = [ "cast", - "itertools 0.10.1", + "itertools", ] [[package]] name = "crossbeam-channel" -version = "0.5.8" +version = "0.5.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a33c2bf77f2df06183c3aa30d1e96c0695a313d4f9c453cc3762a6db39f99200" +checksum = "176dc175b78f56c0f321911d9c8eb2b77a78a4860b9c19db83835fea1a46649b" dependencies = [ - "cfg-if", "crossbeam-utils", ] [[package]] name = "crossbeam-deque" -version = "0.8.1" +version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6455c0ca19f0d2fbf751b908d5c55c1f5cbc65e03c4225427254b46890bdde1e" +checksum = "613f8cc01fe9cf1a3eb3d7f488fd2fa8388403e97039e2f73692932e291a770d" dependencies = [ - "cfg-if", "crossbeam-epoch", "crossbeam-utils", ] [[package]] name = "crossbeam-epoch" -version = "0.9.5" +version = "0.9.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4ec02e091aa634e2c3ada4a392989e7c3116673ef0ac5b72232439094d73b7fd" +checksum = "5b82ac4a3c2ca9c3460964f020e1402edd5753411d7737aa39c3714ad1b5420e" dependencies = [ - "cfg-if", "crossbeam-utils", - "lazy_static", - "memoffset", - "scopeguard", ] [[package]] name = "crossbeam-utils" -version = "0.8.7" +version = "0.8.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "248e3bacc7dc6baa3b21e405ee045c3047101a49145e7e9eca583ab4c2ca5345" + +[[package]] +name = "crunchy" +version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5e5bed1f1c269533fa816a0a5492b3545209a205ca1a54842be180eb63a16a6" +checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7" + +[[package]] +name = "derive_more" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4a9b99b9cbbe49445b21764dc0625032a89b145a2642e67603e1c936f5458d05" dependencies = [ - "cfg-if", - "lazy_static", + "derive_more-impl", ] [[package]] -name = "derive_more" -version = "0.99.16" +name = "derive_more-impl" +version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "40eebddd2156ce1bb37b20bbe5151340a31828b1f2d22ba4141f3531710e38df" +checksum = "cb7330aeadfbe296029522e6c40f315320aba36fc43a5b3632f3795348f3bd22" dependencies = [ - "convert_case", "proc-macro2", "quote", - "rustc_version", - "syn 1.0.76", + "syn 2.0.48", + "unicode-xid", ] [[package]] @@ -327,9 +334,9 @@ checksum = "cbe77819d458aa1ffc58cfdc1cc240f6356952908ea4ee1864da53b0c7e19437" [[package]] name = "either" -version = "1.6.1" +version = "1.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457" +checksum = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07" [[package]] name = "encode_unicode" @@ -339,63 +346,45 @@ checksum = "a357d28ed41a50f9c765dbfe56cbc04a64e53e5fc58ba79fbc34c10ef3df831f" [[package]] name = "env_logger" -version = "0.10.0" +version = "0.10.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85cdab6a89accf66733ad5a1693a4dcced6aeff64602b634530dd73c1f3ee9f0" +checksum = "4cd405aab171cb85d6735e5c8d9db038c17d3ca007a4d2c25f337935c3d90580" dependencies = [ "log", ] [[package]] name = "equivalent" -version = "1.0.0" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88bffebc5d80432c9b140ee17875ff173a8ab62faad5b257da912bd2f6c1c0a1" +checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" [[package]] name = "errno" -version = "0.3.3" +version = "0.3.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "136526188508e25c6fef639d7927dfb3e0e3084488bf202267829cf7fc23dbdd" +checksum = "a258e46cdc063eb8519c00b9fc845fc47bcfca4130e2f08e88665ceda8474245" dependencies = [ - "errno-dragonfly", - "libc", - "windows-sys 0.48.0", -] - -[[package]] -name = "errno-dragonfly" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aa68f1b12764fab894d2755d2518754e71b4fd80ecfb822714a1206c2aab39bf" -dependencies = [ - "cc", "libc", + "windows-sys", ] [[package]] name = "fastrand" -version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6999dc1837253364c2ebb0704ba97994bd874e8f195d665c50b7548f6ea92764" - -[[package]] -name = "fnv" -version = "1.0.7" +version = "2.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" +checksum = "25cbce373ec4653f1a01a31e8a5e5ec0c622dc27ff9c4e6606eefef5cbbed4a5" [[package]] name = "full_moon" -version = "0.19.0" +version = "1.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "24ef4f8ad0689d3a86bb483650422d72e6f79a37fdc83ed5426cafe96b776ce1" +checksum = "56693bf48edbbe906076ed17158ad642146e94d7a8c64c4c40cb9b6ab96194b6" dependencies = [ "bytecount", "cfg-if", "derive_more", "full_moon_derive", - "logos", "paste", "serde", "smol_str", @@ -407,53 +396,57 @@ version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "99b4bd12ce56927d1dc5478d21528ea8c4b93ca85ff8f8043b6a5351a2a3c6f7" dependencies = [ - "indexmap 1.7.0", + "indexmap 1.9.3", "proc-macro2", "quote", - "syn 1.0.76", + "syn 1.0.109", ] [[package]] name = "globset" -version = "0.4.13" +version = "0.4.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "759c97c1e17c55525b57192c06a267cda0ac5210b222d6b82189a2338fa1c13d" +checksum = "57da3b9b5b85bd66f31093f8c408b90a74431672542466497dcbdfdc02034be1" dependencies = [ "aho-corasick", "bstr", - "fnv", "log", - "regex", + "regex-automata", + "regex-syntax", ] [[package]] name = "globwalk" -version = "0.8.1" +version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "93e3af942408868f6934a7b85134a3230832b9977cf66125df2f9edcfce4ddcc" +checksum = "0bf760ebf69878d9fd8f110c89703d90ce35095324d1f1edcb595c63945ee757" dependencies = [ - "bitflags 1.3.2", + "bitflags 2.4.2", "ignore", "walkdir", ] [[package]] name = "half" -version = "1.7.1" +version = "2.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62aca2aba2d62b4a7f5b33f3712cb1b0692779a56fb510499d5c0aa594daeaf3" +checksum = "bc52e53916c08643f1b56ec082790d1e86a32e58dc5268f897f313fbae7b4872" +dependencies = [ + "cfg-if", + "crunchy", +] [[package]] name = "hashbrown" -version = "0.11.2" +version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e" +checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" [[package]] name = "hashbrown" -version = "0.14.0" +version = "0.14.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2c6201b9ff9fd90a5a3bac2e56a830d0caa509576f0e503818ee82c181b3437a" +checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604" [[package]] name = "heck" @@ -472,45 +465,44 @@ dependencies = [ [[package]] name = "hermit-abi" -version = "0.3.1" +version = "0.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fed44880c466736ef9a5c5b5facefb5ed0785676d0c02d612db14e54f0d84286" +checksum = "5d3d0e0f38255e7fa3cf31335b3a56f05febd18025f4db5ef7a0cfb4f8da651f" [[package]] name = "ignore" -version = "0.4.20" +version = "0.4.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dbe7873dab538a9a44ad79ede1faf5f30d49f9a5c883ddbab48bce81b64b7492" +checksum = "b46810df39e66e925525d6e38ce1e7f6e1d208f72dc39757880fcb66e2c58af1" dependencies = [ + "crossbeam-deque", "globset", - "lazy_static", "log", "memchr", - "regex", + "regex-automata", "same-file", - "thread_local", "walkdir", "winapi-util", ] [[package]] name = "indexmap" -version = "1.7.0" +version = "1.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc633605454125dec4b66843673f01c7df2b89479b32e0ed634e43a91cff62a5" +checksum = "bd070e393353796e801d209ad339e89596eb4c8d430d18ede6a1cced8fafbd99" dependencies = [ "autocfg", - "hashbrown 0.11.2", + "hashbrown 0.12.3", ] [[package]] name = "indexmap" -version = "2.0.0" +version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d5477fe2230a79769d8dc68e0eabf5437907c0457a5614a9e8dddb67f65eb65d" +checksum = "d530e1a18b1cb4c484e6e34556a0d948706958449fca0cab753d649f2bce3d1f" dependencies = [ "equivalent", - "hashbrown 0.14.0", + "hashbrown 0.14.3", ] [[package]] @@ -530,33 +522,24 @@ dependencies = [ [[package]] name = "itertools" -version = "0.10.1" +version = "0.10.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "69ddb889f9d0d08a67338271fa9b62996bc788c7796a5c18cf057420aaed5eaf" -dependencies = [ - "either", -] - -[[package]] -name = "itertools" -version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1c173a5686ce8bfa551b3563d0c2170bf24ca44da99c7ca4bfdab5418c3fe57" +checksum = "b0fd2260e829bddf4cb6ea802289de2f86d6a7a690192fbe91b3f46e0f2c8473" dependencies = [ "either", ] [[package]] name = "itoa" -version = "1.0.1" +version = "1.0.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1aab8fc367588b89dcee83ab0fd66b72b50b72fa1904d7095045ace2b0c81c35" +checksum = "b1a46d1a171d865aa5f83f92695765caa047a9b4cbae2cbf37dbd613a793fd4c" [[package]] name = "js-sys" -version = "0.3.55" +version = "0.3.67" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7cc9ffccd38c451a86bf13657df244e9c3f37493cce8e5e21e940963777acc84" +checksum = "9a1d36f1235bc969acba30b7f5990b864423a6068a10f7c90ae8f0112e3a59d1" dependencies = [ "wasm-bindgen", ] @@ -581,9 +564,9 @@ checksum = "0717cef1bc8b636c6e1c1bbdefc09e6322da8a9321966e8928ef80d20f7f770f" [[package]] name = "linux-raw-sys" -version = "0.4.11" +version = "0.4.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "969488b55f8ac402214f3f5fd243ebb7206cf82de60d3172994707a4bcc2b829" +checksum = "01cda141df6706de531b6c46c3a33ecca755538219bd484262fa09410c13539c" [[package]] name = "log" @@ -591,49 +574,17 @@ version = "0.4.20" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f" -[[package]] -name = "logos" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf8b031682c67a8e3d5446840f9573eb7fe26efe7ec8d195c9ac4c0647c502f1" -dependencies = [ - "logos-derive", -] - -[[package]] -name = "logos-derive" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1d849148dbaf9661a6151d1ca82b13bb4c4c128146a88d05253b38d4e2f496c" -dependencies = [ - "beef", - "fnv", - "proc-macro2", - "quote", - "regex-syntax 0.6.29", - "syn 1.0.76", -] - [[package]] name = "memchr" -version = "2.6.3" +version = "2.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f232d6ef707e1956a43342693d2a31e72989554d58299d7a88738cc95b0d35c" - -[[package]] -name = "memoffset" -version = "0.6.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "59accc507f1338036a0477ef61afdae33cde60840f4dfe481319ce3ad116ddf9" -dependencies = [ - "autocfg", -] +checksum = "523dc4f511e55ab87b694dc30d0f820d60906ef06413f93d4d7a1385599cc149" [[package]] name = "num-traits" -version = "0.2.14" +version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a64b1ec5cda2586e284722486d802acf1f7dbdc623e2bfc57e65ca1cd099290" +checksum = "39e3200413f237f41ab11ad6d161bc7239c84dcb631773ccd7de3dfe4b5c267c" dependencies = [ "autocfg", ] @@ -644,15 +595,15 @@ version = "1.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" dependencies = [ - "hermit-abi 0.3.1", + "hermit-abi 0.3.4", "libc", ] [[package]] name = "once_cell" -version = "1.9.0" +version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da32515d9f6e6e489d7bc9d84c71b060db7247dc035bbe44eac88cf87486d8d5" +checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" [[package]] name = "oorandom" @@ -662,33 +613,21 @@ checksum = "0ab1bc2a289d34bd04a330323ac98a1b4bc82c9d9fcb1e66b63caa84da26b575" [[package]] name = "os_str_bytes" -version = "6.0.0" +version = "6.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e22443d1643a904602595ba1cd8f7d896afe56d26712531c5ff73a15b2fbf64" -dependencies = [ - "memchr", -] +checksum = "e2355d85b9a3786f481747ced0e0ff2ba35213a1f9bd406ed906554d7af805a1" [[package]] name = "paste" -version = "1.0.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9f746c4065a8fa3fe23974dd82f15431cc8d40779821001404d10d2e79ca7d79" - -[[package]] -name = "pest" -version = "2.1.3" +version = "1.0.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "10f4872ae94d7b90ae48754df22fd42ad52ce740b8f370b03da4835417403e53" -dependencies = [ - "ucd-trie", -] +checksum = "de3145af08024dea9fa9914f381a17b8fc6034dfb00f3a84013f7ff43f29ed4c" [[package]] name = "plotters" -version = "0.3.1" +version = "0.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "32a3fd9ec30b9749ce28cd91f255d569591cdf937fe280c312143e3c4bad6f2a" +checksum = "d2c224ba00d7cadd4d5c660deaf2098e5e80e07846537c51f9cfa4be50c1fd45" dependencies = [ "num-traits", "plotters-backend", @@ -699,28 +638,27 @@ dependencies = [ [[package]] name = "plotters-backend" -version = "0.3.2" +version = "0.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d88417318da0eaf0fdcdb51a0ee6c3bed624333bff8f946733049380be67ac1c" +checksum = "9e76628b4d3a7581389a35d5b6e2139607ad7c75b17aed325f210aa91f4a9609" [[package]] name = "plotters-svg" -version = "0.3.1" +version = "0.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "521fa9638fa597e1dc53e9412a4f9cefb01187ee1f7413076f9e6749e2885ba9" +checksum = "38f6d39893cca0701371e3c27294f09797214b86f1fb951b89ade8ec04e2abab" dependencies = [ "plotters-backend", ] [[package]] name = "predicates" -version = "3.0.4" +version = "3.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6dfc28575c2e3f19cb3c73b93af36460ae898d426eba6fc15b9bd2a5220758a0" +checksum = "68b87bfd4605926cdfefc1c3b5f8fe560e3feca9d5552cf68c466d3d8236c7e8" dependencies = [ "anstyle", "difflib", - "itertools 0.11.0", "predicates-core", ] @@ -732,9 +670,9 @@ checksum = "b794032607612e7abeb4db69adb4e33590fa6cf1149e95fd7cb00e634b92f174" [[package]] name = "predicates-tree" -version = "1.0.5" +version = "1.0.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4d86de6de25020a36c6d3643a86d9a6a9f552107c0559c60ea03551b5e16c032" +checksum = "368ba315fb8c5052ab692e68a0eefec6ec57b23a36959c14496f0b0df2c0cecf" dependencies = [ "predicates-core", "termtree", @@ -749,7 +687,7 @@ dependencies = [ "proc-macro-error-attr", "proc-macro2", "quote", - "syn 1.0.76", + "syn 1.0.109", "version_check", ] @@ -766,130 +704,104 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.63" +version = "1.0.78" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b368fba921b0dce7e60f5e04ec15e565b3303972b42bcfde1d0713b881959eb" +checksum = "e2422ad645d89c99f8f3e6b88a9fdeca7fabeac836b1002371c4367c8f984aae" dependencies = [ "unicode-ident", ] [[package]] name = "quote" -version = "1.0.29" +version = "1.0.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "573015e8ab27661678357f27dc26460738fd2b6c86e46f386fde94cb5d913105" +checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" dependencies = [ "proc-macro2", ] [[package]] name = "rayon" -version = "1.5.1" +version = "1.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c06aca804d41dbc8ba42dfd964f0d01334eceb64314b9ecf7c5fad5188a06d90" +checksum = "fa7237101a77a10773db45d62004a272517633fbcc3df19d96455ede1122e051" dependencies = [ - "autocfg", - "crossbeam-deque", "either", "rayon-core", ] [[package]] name = "rayon-core" -version = "1.9.1" +version = "1.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d78120e2c850279833f1dd3582f730c4ab53ed95aeaaaa862a2a5c71b1656d8e" +checksum = "1465873a3dfdaa8ae7cb14b4383657caab0b3e8a0aa9ae8e04b044854c8dfce2" dependencies = [ - "crossbeam-channel", "crossbeam-deque", "crossbeam-utils", - "lazy_static", - "num_cpus", ] [[package]] name = "redox_syscall" -version = "0.3.5" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "567664f262709473930a4bf9e51bf2ebf3348f2e748ccc50dea20646858f8f29" +checksum = "4722d768eff46b75989dd134e5c353f0d6296e5aaa3132e776cbdb56be7731aa" dependencies = [ "bitflags 1.3.2", ] [[package]] name = "regex" -version = "1.10.2" +version = "1.10.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "380b951a9c5e80ddfd6136919eef32310721aa4aacd4889a8d39124b026ab343" +checksum = "b62dbe01f0b06f9d8dc7d49e05a0785f153b00b2c227856282f671e0318c9b15" dependencies = [ "aho-corasick", "memchr", - "regex-automata 0.4.3", - "regex-syntax 0.8.2", + "regex-automata", + "regex-syntax", ] [[package]] name = "regex-automata" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "59b23e92ee4318893fa3fe3e6fb365258efbfe6ac6ab30f090cdcbb7aa37efa9" - -[[package]] -name = "regex-automata" -version = "0.4.3" +version = "0.4.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5f804c7828047e88b2d32e2d7fe5a105da8ee3264f01902f796c8e067dc2483f" +checksum = "5bb987efffd3c6d0d8f5f89510bb458559eab11e4f869acb20bf845e016259cd" dependencies = [ "aho-corasick", "memchr", - "regex-syntax 0.8.2", + "regex-syntax", ] -[[package]] -name = "regex-syntax" -version = "0.6.29" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1" - [[package]] name = "regex-syntax" version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f" -[[package]] -name = "rustc_version" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0dfe2087c51c460008730de8b57e6a320782fbfb312e1f4d520e6c6fae155ee" -dependencies = [ - "semver", -] - [[package]] name = "rustix" -version = "0.38.21" +version = "0.38.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b426b0506e5d50a7d8dafcf2e81471400deb602392c7dd110815afb4eaf02a3" +checksum = "322394588aaf33c24007e8bb3238ee3e4c5c09c084ab32bc73890b99ff326bca" dependencies = [ - "bitflags 2.4.0", + "bitflags 2.4.2", "errno", "libc", "linux-raw-sys", - "windows-sys 0.48.0", + "windows-sys", ] [[package]] name = "rustversion" -version = "1.0.9" +version = "1.0.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97477e48b4cf8603ad5f7aaf897467cf42ab4218a38ef76fb14c2d6773a6d6a8" +checksum = "7ffc183a10b4478d04cbbbfc96d0873219d962dd5accaff2ffbd4ceb7df837f4" [[package]] name = "ryu" -version = "1.0.5" +version = "1.0.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "71d301d4193d031abdd79ff7e3dd721168a9572ef3fe51a1517aba235bd8f86e" +checksum = "f98d2aa92eebf49b69786be48e4477826b256916e84a57ff2a4f21923b48eb4c" [[package]] name = "same-file" @@ -900,55 +812,31 @@ dependencies = [ "winapi-util", ] -[[package]] -name = "scopeguard" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" - -[[package]] -name = "semver" -version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f301af10236f6df4160f7c3f04eec6dbc70ace82d23326abad5edee88801c6b6" -dependencies = [ - "semver-parser", -] - -[[package]] -name = "semver-parser" -version = "0.10.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "00b0bef5b7f9e0df16536d3961cfb6e84331c065b4066afb39768d0e319411f7" -dependencies = [ - "pest", -] - [[package]] name = "serde" -version = "1.0.188" +version = "1.0.196" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf9e0fcba69a370eed61bcf2b728575f726b50b55cba78064753d708ddc7549e" +checksum = "870026e60fa08c69f064aa766c10f10b1d62db9ccd4d0abb206472bee0ce3b32" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.188" +version = "1.0.196" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4eca7ac642d82aa35b60049a6eccb4be6be75e599bd2e9adb5f875a737654af2" +checksum = "33c85360c95e7d137454dc81d9a4ed2b8efd8fbe19cee57357b32b9771fccb67" dependencies = [ "proc-macro2", "quote", - "syn 2.0.32", + "syn 2.0.48", ] [[package]] name = "serde_json" -version = "1.0.108" +version = "1.0.112" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d1c7e3eac408d115102c4c24ad393e0821bb3a5df4d506a80f85f7a742a526b" +checksum = "4d1bd37ce2324cf3bf85e5a25f96eb4baf0d5aa6eba43e7ae8958870c4ec48ed" dependencies = [ "itoa", "ryu", @@ -957,28 +845,29 @@ dependencies = [ [[package]] name = "serde_spanned" -version = "0.6.3" +version = "0.6.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96426c9936fd7a0124915f9185ea1d20aa9445cc9821142f0a73bc9207a2e186" +checksum = "eb3622f419d1296904700073ea6cc23ad690adbd66f13ea683df73298736f0c1" dependencies = [ "serde", ] [[package]] name = "similar" -version = "2.3.0" +version = "2.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2aeaf503862c419d66959f5d7ca015337d864e9c49485d771b732e2a20453597" +checksum = "32fea41aca09ee824cc9724996433064c89f7777e60762749a4170a14abbfa21" dependencies = [ "serde", ] [[package]] name = "smol_str" -version = "0.1.24" +version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fad6c857cbab2627dcf01ec85a623ca4e7dcb5691cbaa3d7fb7653671f0d09c9" +checksum = "9676b89cd56310a87b93dec47b11af744f34d5fc9f367b829474eec0a891350d" dependencies = [ + "borsh", "serde", ] @@ -999,15 +888,15 @@ dependencies = [ [[package]] name = "strum_macros" -version = "0.25.0" +version = "0.25.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fe9f3bd7d2e45dcc5e265fbb88d6513e4747d8ef9444cf01a533119bce28a157" +checksum = "23dc1fa9ac9c169a78ba62f0b841814b7abae11bdd047b9c58f893439e309ea0" dependencies = [ "heck", "proc-macro2", "quote", "rustversion", - "syn 2.0.32", + "syn 2.0.48", ] [[package]] @@ -1044,20 +933,20 @@ dependencies = [ [[package]] name = "syn" -version = "1.0.76" +version = "1.0.109" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c6f107db402c2c2055242dbf4d2af0e69197202e9faacbef9571bbe47f5a1b84" +checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" dependencies = [ "proc-macro2", "quote", - "unicode-xid", + "unicode-ident", ] [[package]] name = "syn" -version = "2.0.32" +version = "2.0.48" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "239814284fd6f1a4ffe4ca893952cdd93c224b6a1571c9a9eadd670295c0c9e2" +checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f" dependencies = [ "proc-macro2", "quote", @@ -1066,66 +955,56 @@ dependencies = [ [[package]] name = "tempfile" -version = "3.8.0" +version = "3.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cb94d2f3cc536af71caac6b6fcebf65860b347e7ce0cc9ebe8f70d3e521054ef" +checksum = "01ce4141aa927a6d1bd34a041795abd0db1cccba5d5f24b009f694bdf3a1f3fa" dependencies = [ "cfg-if", "fastrand", "redox_syscall", "rustix", - "windows-sys 0.48.0", + "windows-sys", ] [[package]] name = "termcolor" -version = "1.1.3" +version = "1.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bab24d30b911b2376f3a13cc2cd443142f0c81dda04c118693e35b3835757755" +checksum = "06794f8f6c5c898b3275aebefa6b8a1cb24cd2c6c79397ab15774837a0bc5755" dependencies = [ "winapi-util", ] [[package]] name = "termtree" -version = "0.2.4" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "507e9898683b6c43a9aa55b64259b721b52ba226e0f3779137e50ad114a4c90b" +checksum = "3369f5ac52d5eb6ab48c6b4ffdc8efbcad6b89c765749064ba298f2c68a16a76" [[package]] name = "textwrap" -version = "0.15.0" +version = "0.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1141d4d61095b28419e22cb0bbf02755f5e54e0526f97f1e3d1d160e60885fb" +checksum = "222a222a5bfe1bba4a77b45ec488a741b3cb8872e5e499451fd7d0129c9c7c3d" [[package]] name = "thiserror" -version = "1.0.49" +version = "1.0.56" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1177e8c6d7ede7afde3585fd2513e611227efd6481bd78d2e82ba1ce16557ed4" +checksum = "d54378c645627613241d077a3a79db965db602882668f9136ac42af9ecb730ad" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.49" +version = "1.0.56" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "10712f02019e9288794769fba95cd6847df9874d49d871d062172f9dd41bc4cc" +checksum = "fa0faa943b50f3db30a20aa7e265dbc66076993efed8463e8de414e5d06d3471" dependencies = [ "proc-macro2", "quote", - "syn 2.0.32", -] - -[[package]] -name = "thread_local" -version = "1.1.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fdd6f064ccff2d6567adcb3873ca630700f00b5ad3f060c25b5dcfd9a4ce152" -dependencies = [ - "cfg-if", - "once_cell", + "syn 2.0.48", ] [[package]] @@ -1149,9 +1028,9 @@ dependencies = [ [[package]] name = "toml" -version = "0.8.1" +version = "0.8.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bc1433177506450fe920e46a4f9812d0c211f5dd556da10e731a0a3dfa151f0" +checksum = "a1a195ec8c9da26928f773888e0742ca3ca1040c6cd859c919c9f59c1954ab35" dependencies = [ "serde", "serde_spanned", @@ -1161,55 +1040,49 @@ dependencies = [ [[package]] name = "toml_datetime" -version = "0.6.3" +version = "0.6.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7cda73e2f1397b1262d6dfdcef8aafae14d1de7748d66822d3bfeeb6d03e5e4b" +checksum = "3550f4e9685620ac18a50ed434eb3aec30db8ba93b0287467bca5826ea25baf1" dependencies = [ "serde", ] [[package]] name = "toml_edit" -version = "0.20.1" +version = "0.21.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ca676d9ba1a322c1b64eb8045a5ec5c0cfb0c9d08e15e9ff622589ad5221c8fe" +checksum = "d34d383cd00a163b4a5b85053df514d45bc330f6de7737edfe0a93311d1eaa03" dependencies = [ - "indexmap 2.0.0", + "indexmap 2.1.0", "serde", "serde_spanned", "toml_datetime", "winnow", ] -[[package]] -name = "ucd-trie" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "56dee185309b50d1f11bfedef0fe6d036842e3fb77413abef29f8f8d1c5d4c1c" - [[package]] name = "unicode-ident" -version = "1.0.8" +version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5464a87b239f13a63a501f2701565754bae92d243d4bb7eb12f6d57d2269bf4" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" [[package]] name = "unicode-width" -version = "0.1.8" +version = "0.1.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9337591893a19b88d8d87f2cec1e73fad5cdfd10e5a6f349f498ad6ea2ffb1e3" +checksum = "e51733f11c9c4f72aa0c160008246859e340b00807569a0da0e7a1079b27ba85" [[package]] name = "unicode-xid" -version = "0.2.2" +version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3" +checksum = "ebc1c04c71510c7f702b52b7c350734c9ff1295c464a03335b00bb84fc54f853" [[package]] name = "version_check" -version = "0.9.3" +version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5fecdca9a5291cc2b8dcf7dc02453fee791a280f3743cb0905f8822ae463b3fe" +checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" [[package]] name = "wait-timeout" @@ -1222,20 +1095,19 @@ dependencies = [ [[package]] name = "walkdir" -version = "2.3.2" +version = "2.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "808cf2735cd4b6866113f648b791c6adc5714537bc222d9347bb203386ffda56" +checksum = "d71d857dc86794ca4c280d616f7da00d2dbfd8cd788846559a6813e6aa4b54ee" dependencies = [ "same-file", - "winapi", "winapi-util", ] [[package]] name = "wasm-bindgen" -version = "0.2.81" +version = "0.2.90" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7c53b543413a17a202f4be280a7e5c62a1c69345f5de525ee64f8cfdbc954994" +checksum = "b1223296a201415c7fad14792dbefaace9bd52b62d33453ade1c5b5f07555406" dependencies = [ "cfg-if", "wasm-bindgen-macro", @@ -1243,24 +1115,24 @@ dependencies = [ [[package]] name = "wasm-bindgen-backend" -version = "0.2.81" +version = "0.2.90" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5491a68ab4500fa6b4d726bd67408630c3dbe9c4fe7bda16d5c82a1fd8c7340a" +checksum = "fcdc935b63408d58a32f8cc9738a0bffd8f05cc7c002086c6ef20b7312ad9dcd" dependencies = [ "bumpalo", - "lazy_static", "log", + "once_cell", "proc-macro2", "quote", - "syn 1.0.76", + "syn 2.0.48", "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-macro" -version = "0.2.81" +version = "0.2.90" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c441e177922bc58f1e12c022624b6216378e5febc2f0533e41ba443d505b80aa" +checksum = "3e4c238561b2d428924c49815533a8b9121c664599558a5d9ec51f8a1740a999" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -1268,28 +1140,28 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.81" +version = "0.2.90" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7d94ac45fcf608c1f45ef53e748d35660f168490c10b23704c7779ab8f5c3048" +checksum = "bae1abb6806dc1ad9e560ed242107c0f6c84335f1749dd4e8ddb012ebd5e25a7" dependencies = [ "proc-macro2", "quote", - "syn 1.0.76", + "syn 2.0.48", "wasm-bindgen-backend", "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-shared" -version = "0.2.81" +version = "0.2.90" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6a89911bd99e5f3659ec4acf9c4d93b0a90fe4a2a11f15328472058edc5261be" +checksum = "4d91413b1c31d7539ba5ef2451af3f0b833a005eb27a631cec32bc0635a8602b" [[package]] name = "web-sys" -version = "0.3.55" +version = "0.3.67" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38eb105f1c59d9eaa6b5cdc92b859d85b926e82cb2e0945cd0c9259faa6fe9fb" +checksum = "58cd2333b6e0be7a39605f0e255892fd7418a682d8da8fe042fe25128794d2ed" dependencies = [ "js-sys", "wasm-bindgen", @@ -1313,9 +1185,9 @@ checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" [[package]] name = "winapi-util" -version = "0.1.5" +version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" +checksum = "f29e6f9198ba0d26b4c9f07dbe6f9ed633e1f3d5b8b414090084349e46a52596" dependencies = [ "winapi", ] @@ -1328,141 +1200,75 @@ checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" [[package]] name = "windows-sys" -version = "0.45.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "75283be5efb2831d37ea142365f009c02ec203cd29a3ebecbc093d52315b66d0" -dependencies = [ - "windows-targets 0.42.2", -] - -[[package]] -name = "windows-sys" -version = "0.48.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" -dependencies = [ - "windows-targets 0.48.5", -] - -[[package]] -name = "windows-targets" -version = "0.42.2" +version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e5180c00cd44c9b1c88adb3693291f1cd93605ded80c250a75d472756b4d071" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" dependencies = [ - "windows_aarch64_gnullvm 0.42.2", - "windows_aarch64_msvc 0.42.2", - "windows_i686_gnu 0.42.2", - "windows_i686_msvc 0.42.2", - "windows_x86_64_gnu 0.42.2", - "windows_x86_64_gnullvm 0.42.2", - "windows_x86_64_msvc 0.42.2", + "windows-targets", ] [[package]] name = "windows-targets" -version = "0.48.5" +version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" +checksum = "8a18201040b24831fbb9e4eb208f8892e1f50a37feb53cc7ff887feb8f50e7cd" dependencies = [ - "windows_aarch64_gnullvm 0.48.5", - "windows_aarch64_msvc 0.48.5", - "windows_i686_gnu 0.48.5", - "windows_i686_msvc 0.48.5", - "windows_x86_64_gnu 0.48.5", - "windows_x86_64_gnullvm 0.48.5", - "windows_x86_64_msvc 0.48.5", + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", ] [[package]] name = "windows_aarch64_gnullvm" -version = "0.42.2" +version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "597a5118570b68bc08d8d59125332c54f1ba9d9adeedeef5b99b02ba2b0698f8" - -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.42.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e08e8864a60f06ef0d0ff4ba04124db8b0fb3be5776a5cd47641e942e58c4d43" +checksum = "cb7764e35d4db8a7921e09562a0304bf2f93e0a51bfccee0bd0bb0b666b015ea" [[package]] name = "windows_aarch64_msvc" -version = "0.48.5" +version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" +checksum = "bbaa0368d4f1d2aaefc55b6fcfee13f41544ddf36801e793edbbfd7d7df075ef" [[package]] name = "windows_i686_gnu" -version = "0.42.2" +version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c61d927d8da41da96a81f029489353e68739737d3beca43145c8afec9a31a84f" - -[[package]] -name = "windows_i686_gnu" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" +checksum = "a28637cb1fa3560a16915793afb20081aba2c92ee8af57b4d5f28e4b3e7df313" [[package]] name = "windows_i686_msvc" -version = "0.42.2" +version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "44d840b6ec649f480a41c8d80f9c65108b92d89345dd94027bfe06ac444d1060" - -[[package]] -name = "windows_i686_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" +checksum = "ffe5e8e31046ce6230cc7215707b816e339ff4d4d67c65dffa206fd0f7aa7b9a" [[package]] name = "windows_x86_64_gnu" -version = "0.42.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8de912b8b8feb55c064867cf047dda097f92d51efad5b491dfb98f6bbb70cb36" - -[[package]] -name = "windows_x86_64_gnu" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" - -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.42.2" +version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26d41b46a36d453748aedef1486d5c7a85db22e56aff34643984ea85514e94a3" +checksum = "3d6fa32db2bc4a2f5abeacf2b69f7992cd09dca97498da74a151a3132c26befd" [[package]] name = "windows_x86_64_gnullvm" -version = "0.48.5" +version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" +checksum = "1a657e1e9d3f514745a572a6846d3c7aa7dbe1658c056ed9c3344c4109a6949e" [[package]] name = "windows_x86_64_msvc" -version = "0.42.2" +version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9aec5da331524158c6d1a4ac0ab1541149c0b9505fde06423b02f5ef0106b9f0" - -[[package]] -name = "windows_x86_64_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" +checksum = "dff9641d1cd4be8d1a070daf9e3773c5f67e78b4d9d42263020c057706765c04" [[package]] name = "winnow" -version = "0.5.0" +version = "0.5.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81fac9742fd1ad1bd9643b991319f72dd031016d44b77039a26977eb667141e7" +checksum = "1931d78a9c73861da0134f453bb1f790ce49b2e30eba8410b4b79bac72b46a2d" dependencies = [ "memchr", ] diff --git a/Cargo.toml b/Cargo.toml index 0d92b8e7..ee331f91 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -30,6 +30,7 @@ luau = ["full_moon/roblox"] lua52 = ["full_moon/lua52"] lua53 = ["lua52", "full_moon/lua53"] lua54 = ["lua53", "full_moon/lua54"] +luajit = ["full_moon/luajit"] editorconfig = ["ec4rs"] [dependencies] @@ -40,7 +41,7 @@ console = "0.15.7" crossbeam-channel = "0.5.8" ec4rs = { version = "1.0.2", optional = true } env_logger = { version = "0.10.0", default-features = false } -full_moon = "0.19.0" +full_moon = "1.1.1" globset = "0.4.13" ignore = "0.4.20" lazy_static = "1.4.0" @@ -58,6 +59,11 @@ toml = "0.8.1" [target.'cfg(target_arch = "wasm32")'.dependencies] wasm-bindgen = { version = "0.2.81", optional = true } +# full-moon should be compiled to release optimisations in debug mode due to stack overflows +# https://github.com/Kampfkarren/full-moon/issues/140 +[profile.dev.package.full_moon] +opt-level = 3 + [dev-dependencies] criterion = "0.4.0" insta = { version = "1.34.0", features = ["glob"] } diff --git a/src/cli/config.rs b/src/cli/config.rs index c3fe9bb2..5c19864b 100644 --- a/src/cli/config.rs +++ b/src/cli/config.rs @@ -156,6 +156,9 @@ pub fn load_config(opt: &Opt) -> Result> { pub fn load_overrides(config: Config, opt: &Opt) -> Config { let mut new_config = config; + if let Some(syntax) = opt.format_opts.syntax { + new_config.syntax = syntax.into(); + }; if let Some(column_width) = opt.format_opts.column_width { new_config.column_width = column_width; }; @@ -191,7 +194,15 @@ pub fn load_overrides(config: Config, opt: &Opt) -> Config { mod tests { use super::*; use clap::StructOpt; - use stylua_lib::{CallParenType, IndentType, LineEndings, QuoteStyle}; + use stylua_lib::{CallParenType, IndentType, LineEndings, LuaVersion, QuoteStyle}; + + #[test] + fn test_override_syntax() { + let override_opt = Opt::parse_from(vec!["BINARY_NAME", "--syntax", "Lua51"]); + let default_config = Config::new(); + let config = load_overrides(default_config, &override_opt); + assert_eq!(config.syntax, LuaVersion::Lua51); + } #[test] fn test_override_column_width() { diff --git a/src/cli/main.rs b/src/cli/main.rs index 1a3e4701..f19debd6 100644 --- a/src/cli/main.rs +++ b/src/cli/main.rs @@ -47,60 +47,49 @@ struct ErrorFileWrapper { error: anyhow::Error, } -fn convert_parse_error_to_json(file: &str, err: &full_moon::Error) -> Option { - Some(match err { - full_moon::Error::AstError(full_moon::ast::AstError::UnexpectedToken { - token, - additional, - }) => json!({ - "type": "parse_error", - "message": format!("unexpected token `{}`{}", token, additional.as_ref().map(|x| format!(": {x}")).unwrap_or_default()), - "filename": file, - "location": { - "start": token.start_position().bytes(), - "start_line": token.start_position().line(), - "start_column": token.start_position().character(), - "end": token.end_position().bytes(), - "end_line": token.end_position().line(), - "end_column": token.end_position().character(), - }, - }), - full_moon::Error::TokenizerError(error) => json!({ - "type": "parse_error", - "message": match error.error() { - full_moon::tokenizer::TokenizerErrorType::UnclosedComment => { - "unclosed comment".to_string() - } - full_moon::tokenizer::TokenizerErrorType::UnclosedString => { - "unclosed string".to_string() - } - full_moon::tokenizer::TokenizerErrorType::UnexpectedShebang => { - "unexpected shebang".to_string() - } - full_moon::tokenizer::TokenizerErrorType::UnexpectedToken( - character, - ) => { - format!("unexpected character {character}") - } - full_moon::tokenizer::TokenizerErrorType::InvalidSymbol(symbol) => { - format!("invalid symbol {symbol}") - } - }, - "filename": file, - "location": { - "start": error.position().bytes(), - "start_line": error.position().line(), - "start_column": error.position().character(), - "end": error.position().bytes(), - "end_line": error.position().line(), - "end_column": error.position().character(), - }, - }), - _ => { - error!("{:#}", err); - return None; - } - }) +fn convert_parse_error_to_json(file: &str, errs: Vec) -> serde_json::Value { + errs.iter() + .map(|err| { + let message = match err { + full_moon::Error::AstError(ast_error) => format!( + "unexpected token `{}`: {}", + ast_error.token(), + ast_error.error_message() + ), + full_moon::Error::TokenizerError(error) => match error.error() { + full_moon::tokenizer::TokenizerErrorType::UnclosedComment => { + "unclosed comment".to_string() + } + full_moon::tokenizer::TokenizerErrorType::UnclosedString => { + "unclosed string".to_string() + } + full_moon::tokenizer::TokenizerErrorType::InvalidNumber => { + "invalid number".to_string() + } + full_moon::tokenizer::TokenizerErrorType::UnexpectedToken(character) => { + format!("unexpected character {character}") + } + full_moon::tokenizer::TokenizerErrorType::InvalidSymbol(symbol) => { + format!("invalid symbol {symbol}") + } + }, + }; + let (start_position, end_position) = err.range(); + json!({ + "type": "parse_error", + "message": message, + "filename": file, + "location": { + "start": start_position.bytes(), + "start_line": start_position.line(), + "start_column": start_position.character(), + "end": end_position.bytes(), + "end_line": end_position.line(), + "end_column": end_position.character(), + }, + }) + }) + .collect() } fn create_diff( @@ -394,22 +383,18 @@ fn format(opt: opt::Opt) -> Result { Some(ErrorFileWrapper { file, error }) => { match error.downcast_ref::() { Some(stylua_lib::Error::ParseError(err)) => { - if let Some(structured_err) = - convert_parse_error_to_json(file, err) - { - // Force write to stderr directly - // TODO: can we do this through error! instead? - let stderr = stderr(); - let mut handle = stderr.lock(); - match handle - .write_all(structured_err.to_string().as_bytes()) - { - Ok(_) => (), - Err(err) => { - error!("could not output to stdout: {:#}", err) - } - }; - } + let structured_err = + convert_parse_error_to_json(file, err.to_vec()); + // Force write to stderr directly + // TODO: can we do this through error! instead? + let stderr = stderr(); + let mut handle = stderr.lock(); + match handle.write_all(structured_err.to_string().as_bytes()) { + Ok(_) => (), + Err(err) => { + error!("could not output to stdout: {:#}", err) + } + }; } _ => error!("{:#}", err), } diff --git a/src/cli/opt.rs b/src/cli/opt.rs index 5ba37150..0e7c5884 100644 --- a/src/cli/opt.rs +++ b/src/cli/opt.rs @@ -1,7 +1,7 @@ use clap::{ArgEnum, StructOpt}; use std::path::PathBuf; use stylua_lib::{ - CallParenType, CollapseSimpleStatement, IndentType, LineEndings, QuoteStyle, + CallParenType, CollapseSimpleStatement, IndentType, LineEndings, LuaVersion, QuoteStyle, SpaceAfterFunctionNames, }; @@ -162,6 +162,9 @@ pub enum OutputFormat { #[derive(StructOpt, Debug)] pub struct FormatOpts { + /// The type of Lua syntax to parse + #[structopt(long, arg_enum, ignore_case = true)] + pub syntax: Option, /// The column width to use to attempt to wrap lines. #[structopt(long)] pub column_width: Option, @@ -192,11 +195,12 @@ pub struct FormatOpts { // Convert [`stylua_lib::Config`] enums into clap-friendly enums macro_rules! convert_enum { - ($from:tt, $arg:tt, { $($enum_name:ident,)+ }) => { + ($from:tt, $arg:tt, { $($(#[$inner:meta])* $enum_name:ident,)+ }) => { #[derive(ArgEnum, Clone, Copy, Debug)] #[clap(rename_all = "PascalCase")] pub enum $arg { $( + $(#[$inner])* $enum_name, )+ } @@ -205,6 +209,7 @@ macro_rules! convert_enum { fn from(other: $arg) -> $from { match other { $( + $(#[$inner])* $arg::$enum_name => $from::$enum_name, )+ } @@ -215,6 +220,7 @@ macro_rules! convert_enum { fn from(other: $from) -> $arg { match other { $( + $(#[$inner])* $from::$enum_name => $arg::$enum_name, )+ } @@ -223,6 +229,16 @@ macro_rules! convert_enum { }; } +convert_enum!(LuaVersion, ArgLuaVersion, { + All, + Lua51, + #[cfg(feature = "lua52")] Lua52, + #[cfg(feature = "lua53")] Lua53, + #[cfg(feature = "lua54")] Lua54, + #[cfg(feature = "luau")] Luau, + #[cfg(feature = "luajit")] LuaJIT, +}); + convert_enum!(LineEndings, ArgLineEndings, { Unix, Windows, diff --git a/src/formatters/assignment.rs b/src/formatters/assignment.rs index ddc31f79..2895eaa2 100644 --- a/src/formatters/assignment.rs +++ b/src/formatters/assignment.rs @@ -1,5 +1,5 @@ #[cfg(feature = "luau")] -use full_moon::ast::types::TypeSpecifier; +use full_moon::ast::luau::TypeSpecifier; use full_moon::tokenizer::{Token, TokenReference}; use full_moon::{ ast::{ diff --git a/src/formatters/expression.rs b/src/formatters/expression.rs index f0638c16..a1529e0c 100644 --- a/src/formatters/expression.rs +++ b/src/formatters/expression.rs @@ -1,5 +1,5 @@ #[cfg(feature = "luau")] -use full_moon::ast::types::{ +use full_moon::ast::luau::{ ElseIfExpression, IfExpression, InterpolatedString, InterpolatedStringSegment, }; use full_moon::{ @@ -167,9 +167,9 @@ fn check_excess_parentheses(internal_expression: &Expression, context: Expressio Expression::FunctionCall(_) => false, Expression::Symbol(token_ref) => { match token_ref.token_type() { - // If we have an ellipse inside of parentheses, we may also be culling values + // If we have an ellipsis inside of parentheses, we may also be culling values // Therefore, we don't remove parentheses - TokenType::Symbol { symbol } => !matches!(symbol, Symbol::Ellipse), + TokenType::Symbol { symbol } => !matches!(symbol, Symbol::Ellipsis), _ => true, } } @@ -194,9 +194,9 @@ fn format_expression_internal( shape: Shape, ) -> Expression { match expression { - Expression::Function((token_reference, function_body)) => Expression::Function( - format_anonymous_function(ctx, token_reference, function_body, shape), - ), + Expression::Function(anonymous_function) => { + Expression::Function(format_anonymous_function(ctx, anonymous_function, shape)) + } Expression::FunctionCall(function_call) => { Expression::FunctionCall(format_function_call(ctx, function_call, shape)) } diff --git a/src/formatters/functions.rs b/src/formatters/functions.rs index aa169c03..00babe60 100644 --- a/src/formatters/functions.rs +++ b/src/formatters/functions.rs @@ -42,17 +42,17 @@ use super::expression::process_dot_name; /// This doesn't have its own struct, but it is part of Value::Function pub fn format_anonymous_function( ctx: &Context, - function_token: &TokenReference, - function_body: &FunctionBody, + anonymous_function: &(TokenReference, FunctionBody), shape: Shape, -) -> (TokenReference, FunctionBody) { +) -> Box<(TokenReference, FunctionBody)> { const FUNCTION_LEN: usize = "function".len(); let function_definition_trivia = vec![create_function_definition_trivia(ctx)]; - let function_token = fmt_symbol!(ctx, function_token, "function", shape) + let function_token = fmt_symbol!(ctx, &anonymous_function.0, "function", shape) .update_trailing_trivia(FormatTriviaType::Append(function_definition_trivia)); - let function_body = format_function_body(ctx, function_body, shape.add_width(FUNCTION_LEN)); + let function_body = + format_function_body(ctx, &anonymous_function.1, shape.add_width(FUNCTION_LEN)); - (function_token, function_body) + Box::new((function_token, function_body)) } /// An enum providing information regarding the next AST node after a function call. @@ -228,9 +228,9 @@ fn function_args_multiline_heuristic( for pair in first_iter_formatted_arguments { let argument = pair.value(); match argument { - Expression::Function((_, function_body)) => { + Expression::Function(anonymous_function) => { // Check to see whether it has been expanded - let is_expanded = !should_collapse_function_body(ctx, function_body); + let is_expanded = !should_collapse_function_body(ctx, &anonymous_function.1); if is_expanded { // If we have a mixture of multiline args, and other arguments // Then the function args should be expanded @@ -1241,7 +1241,7 @@ pub fn format_method_call( /// Formats a single Parameter node pub fn format_parameter(ctx: &Context, parameter: &Parameter, shape: Shape) -> Parameter { match parameter { - Parameter::Ellipse(token) => Parameter::Ellipse(fmt_symbol!(ctx, token, "...", shape)), + Parameter::Ellipsis(token) => Parameter::Ellipsis(fmt_symbol!(ctx, token, "...", shape)), Parameter::Name(token_reference) => { Parameter::Name(format_token_reference(ctx, token_reference, shape)) } diff --git a/src/formatters/general.rs b/src/formatters/general.rs index 9c1f8785..16cc8fc6 100644 --- a/src/formatters/general.rs +++ b/src/formatters/general.rs @@ -118,7 +118,7 @@ pub fn format_token( } TokenType::StringLiteral { literal, - multi_line, + multi_line_depth, quote_type, } => { // If we have a brackets string, don't mess with it @@ -131,7 +131,7 @@ pub fn format_token( TokenType::StringLiteral { literal: literal.into(), - multi_line: *multi_line, + multi_line_depth: *multi_line_depth, quote_type: StringLiteralQuoteType::Brackets, } } else { @@ -188,11 +188,20 @@ pub fn format_token( .into(); TokenType::StringLiteral { literal, - multi_line: None, + multi_line_depth: *multi_line_depth, quote_type: quote_to_use, } } } + TokenType::Shebang { line } => { + let line = format_single_line_comment_string(line).into(); + + // Shebang must always be leading trivia, as it is start of file. Terminate it with a newline + debug_assert!(matches!(format_type, FormatTokenType::LeadingTrivia)); + trailing_trivia = Some(vec![create_newline_trivia(ctx)]); + + TokenType::Shebang { line } + } TokenType::SingleLineComment { comment } => { let comment = format_single_line_comment_string(comment).into(); @@ -292,7 +301,9 @@ fn load_token_trivia( // Move to next trivia continue; } - TokenType::SingleLineComment { .. } | TokenType::MultiLineComment { .. } => { + TokenType::Shebang { .. } + | TokenType::SingleLineComment { .. } + | TokenType::MultiLineComment { .. } => { // If we have a comment, when `format_token` is called, it will put a newline at the end // If this happens, we want to skip the next iteration if its a newline, as that has already been covered here if let FormatTokenType::LeadingTrivia = format_token_type { diff --git a/src/formatters/luau.rs b/src/formatters/luau.rs index f0698c05..21a74ac9 100644 --- a/src/formatters/luau.rs +++ b/src/formatters/luau.rs @@ -21,10 +21,14 @@ use crate::{ }, shape::Shape, }; -use full_moon::ast::types::{ - CompoundAssignment, CompoundOp, ExportedTypeDeclaration, GenericDeclaration, - GenericDeclarationParameter, GenericParameterInfo, IndexedTypeInfo, TypeArgument, - TypeAssertion, TypeDeclaration, TypeField, TypeFieldKey, TypeInfo, TypeSpecifier, +use full_moon::ast::{ + luau::{ + CompoundAssignment, CompoundOp, ExportedTypeDeclaration, GenericDeclaration, + GenericDeclarationParameter, GenericParameterInfo, IndexedTypeInfo, TypeArgument, + TypeAssertion, TypeDeclaration, TypeField, TypeFieldKey, TypeInfo, TypeIntersection, + TypeSpecifier, TypeUnion, + }, + punctuated::Pair, }; use full_moon::ast::{punctuated::Punctuated, span::ContainedSpan}; use full_moon::tokenizer::{Token, TokenReference, TokenType}; @@ -70,9 +74,8 @@ pub fn format_compound_assignment( // we should try and hug them together if possible fn should_hug_type(type_info: &TypeInfo) -> bool { match type_info { - TypeInfo::Union { left, right, .. } | TypeInfo::Intersection { left, right, .. } => { - should_hug_type(left) || should_hug_type(right) - } + TypeInfo::Union(union) => union.types().iter().any(should_hug_type), + TypeInfo::Intersection(intersection) => intersection.types().iter().any(should_hug_type), TypeInfo::Table { .. } => true, _ => false, } @@ -296,20 +299,37 @@ fn format_type_info_internal( shape: Shape, ) -> TypeInfo { match type_info { - TypeInfo::Array { braces, type_info } => { + TypeInfo::Array { + braces, + access, + type_info, + } => { const BRACKET_LEN: usize = "{ ".len(); let (start_brace, end_brace) = braces.tokens().to_owned(); let contains_comments = start_brace.trailing_trivia().any(trivia_is_comment) || end_brace.leading_trivia().any(trivia_is_comment) + || contains_comments(access) || contains_comments(type_info); + let access = access.as_ref().map(|token_reference| { + format_token_reference(ctx, token_reference, shape + BRACKET_LEN) + }); + + let access_shape_increment = access + .as_ref() + .map_or(0, |token| token.to_string().len() + 1); + let (table_type, new_type_info) = if contains_comments { (TableType::MultiLine, None) } else { - let new_type_info = - format_hangable_type_info(ctx, type_info, shape + BRACKET_LEN, 0); + let new_type_info = format_hangable_type_info( + ctx, + type_info, + shape + BRACKET_LEN + access_shape_increment, + 0, + ); ( if spans_multiple_lines(&new_type_info) { @@ -345,6 +365,7 @@ fn format_type_info_internal( TypeInfo::Array { braces, + access, type_info: Box::new(new_type_info.update_trivia(leading_trivia, trailing_trivia)), } } @@ -441,36 +462,53 @@ fn format_type_info_internal( } } - TypeInfo::GenericPack { name, ellipse } => { + TypeInfo::GenericPack { name, ellipsis } => { let name = format_token_reference(ctx, name, shape); - let ellipse = fmt_symbol!(ctx, ellipse, "...", shape); + let ellipsis = fmt_symbol!(ctx, ellipsis, "...", shape); - TypeInfo::GenericPack { name, ellipse } + TypeInfo::GenericPack { name, ellipsis } } - TypeInfo::Intersection { - left, - ampersand, - right, - } => { - let left = Box::new(format_type_info_internal( - ctx, - left, - context.mark_contains_intersect(), - shape, - )); - let ampersand = fmt_symbol!(ctx, ampersand, " & ", shape); - let right = Box::new(format_type_info_internal( - ctx, - right, - context.mark_contains_intersect(), - shape + 3, - )); // 3 = " & " - TypeInfo::Intersection { - left, - ampersand, - right, + TypeInfo::Intersection(intersection) => { + // TODO: reuse 'format_punctuated' from general.rs? + let mut types = Punctuated::new(); + let mut shape = shape; + + let leading = match intersection.leading() { + Some(leading) => { + let result = fmt_symbol!(ctx, leading, "& ", shape); + shape = shape + 2; + Some(result) + } + None => None, + }; + + for pair in intersection.types().pairs() { + let new_pair = match pair { + Pair::Punctuated(left, pipe) => { + let result = Pair::Punctuated( + format_type_info_internal( + ctx, + left, + context.mark_contains_intersect(), + shape, + ), + fmt_symbol!(ctx, pipe, " & ", shape), + ); + shape = shape + 3; + result + } + Pair::End(right) => Pair::End(format_type_info_internal( + ctx, + right, + context.mark_contains_intersect(), + shape + 3, + )), + }; + types.push(new_pair); } + + TypeInfo::Intersection(TypeIntersection::new(leading, types)) } TypeInfo::Module { @@ -632,26 +670,53 @@ fn format_type_info_internal( TypeInfo::Tuple { parentheses, types } } - TypeInfo::Union { left, pipe, right } => { - let left = Box::new(format_type_info_internal( - ctx, - left, - context.mark_contains_union(), - shape, - )); - let pipe = fmt_symbol!(ctx, pipe, " | ", shape); - let right = Box::new(format_type_info_internal( - ctx, - right, - context.mark_contains_union(), - shape + 3, - )); // 3 = " | " + TypeInfo::Union(union) => { + // TODO: reuse 'format_punctuated' from general.rs? + let mut types = Punctuated::new(); + let mut shape = shape; + + let leading = match union.leading() { + Some(leading) => { + let result = fmt_symbol!(ctx, leading, "| ", shape); + shape = shape + 2; + Some(result) + } + None => None, + }; + + for pair in union.types().pairs() { + let new_pair = match pair { + Pair::Punctuated(left, pipe) => { + let result = Pair::Punctuated( + format_type_info_internal( + ctx, + left, + context.mark_contains_union(), + shape, + ), + fmt_symbol!(ctx, pipe, " | ", shape), + ); + shape = shape + 3; + result + } + Pair::End(right) => Pair::End(format_type_info_internal( + ctx, + right, + context.mark_contains_union(), + shape + 3, + )), + }; + types.push(new_pair); + } - TypeInfo::Union { left, pipe, right } + TypeInfo::Union(TypeUnion::new(leading, types)) } - TypeInfo::Variadic { ellipse, type_info } => { - let ellipse = fmt_symbol!(ctx, ellipse, "...", shape); + TypeInfo::Variadic { + ellipsis, + type_info, + } => { + let ellipsis = fmt_symbol!(ctx, ellipsis, "...", shape); let type_info = Box::new(format_type_info_internal( ctx, type_info, @@ -659,14 +724,17 @@ fn format_type_info_internal( shape + 3, )); // 3 = "..." - TypeInfo::Variadic { ellipse, type_info } + TypeInfo::Variadic { + ellipsis, + type_info, + } } - TypeInfo::VariadicPack { ellipse, name } => { + TypeInfo::VariadicPack { ellipsis, name } => { let name = format_token_reference(ctx, name, shape); - let ellipse = fmt_symbol!(ctx, ellipse, "...", shape); + let ellipsis = fmt_symbol!(ctx, ellipsis, "...", shape); - TypeInfo::VariadicPack { ellipse, name } + TypeInfo::VariadicPack { ellipsis, name } } other => panic!("unknown node {:?}", other), @@ -678,7 +746,7 @@ fn hang_type_info_binop( ctx: &Context, binop: TokenReference, shape: Shape, - rhs: &TypeInfo, + next_comments: Vec, ) -> TokenReference { // Get the leading comments of a binop, as we need to preserve them // Intersperse a newline and indent trivia between them @@ -702,7 +770,7 @@ fn hang_type_info_binop( .flat_map(|x| vec![Token::new(TokenType::spaces(1)), x.to_owned()]), ) // If there are any leading comments to the RHS expression, we need to move them to before the BinOp - .chain(rhs.leading_comments().iter().flat_map(|x| { + .chain(next_comments.iter().flat_map(|x| { vec![ create_newline_trivia(ctx), create_indent_trivia(ctx, shape), @@ -733,42 +801,94 @@ fn hang_type_info( let hanging_shape = shape.with_indent(shape.indent().add_indent_level(hang_level)); match type_info { - TypeInfo::Union { left, pipe, right } => TypeInfo::Union { - left: Box::new(format_type_info_internal( - ctx, - left, - context.mark_contains_union(), - shape, - )), - pipe: hang_type_info_binop(ctx, pipe.to_owned(), hanging_shape, right), - right: Box::new(hang_type_info( - ctx, - &right.update_leading_trivia(FormatTriviaType::Replace(vec![])), - context.mark_contains_union(), - hanging_shape.reset() + PIPE_LENGTH, - 0, - )), - }, - TypeInfo::Intersection { - left, - ampersand, - right, - } => TypeInfo::Intersection { - left: Box::new(format_type_info_internal( - ctx, - left, - context.mark_contains_intersect(), - shape, - )), - ampersand: hang_type_info_binop(ctx, ampersand.to_owned(), hanging_shape, right), - right: Box::new(hang_type_info( - ctx, - &right.update_leading_trivia(FormatTriviaType::Replace(vec![])), - context.mark_contains_intersect(), - hanging_shape.reset() + PIPE_LENGTH, - 0, - )), - }, + TypeInfo::Union(union) => { + let mut types = Punctuated::new(); + let mut iter = union.types().pairs().peekable(); + let mut is_first = true; + while let Some(pair) = iter.next() { + let new_pair = match pair { + Pair::Punctuated(type_info, next_pipe) => { + let next_comments = iter.peek().leading_comments(); + Pair::Punctuated( + format_type_info_internal( + ctx, + &(if is_first { + type_info.clone() + } else { + type_info + .update_leading_trivia(FormatTriviaType::Replace(vec![])) + }), + context.mark_contains_union(), + if is_first { shape } else { hanging_shape }, + ), + hang_type_info_binop( + ctx, + next_pipe.to_owned(), + hanging_shape, + next_comments, + ), + ) + } + Pair::End(type_info) => Pair::End(format_type_info_internal( + ctx, + &type_info.update_leading_trivia(FormatTriviaType::Replace(vec![])), + context.mark_contains_union(), + hanging_shape.reset() + PIPE_LENGTH, + )), + }; + types.push(new_pair); + is_first = false; + } + + // TODO: handle leading + TypeInfo::Union(TypeUnion::new(union.leading().cloned(), types)) + } + + TypeInfo::Intersection(intersection) => { + let mut types = Punctuated::new(); + let mut iter = intersection.types().pairs().peekable(); + let mut is_first = true; + while let Some(pair) = iter.next() { + let new_pair = match pair { + Pair::Punctuated(type_info, next_pipe) => { + let next_comments = iter.peek().leading_comments(); + Pair::Punctuated( + format_type_info_internal( + ctx, + &(if is_first { + type_info.clone() + } else { + type_info + .update_leading_trivia(FormatTriviaType::Replace(vec![])) + }), + context.mark_contains_intersect(), + if is_first { shape } else { hanging_shape }, + ), + hang_type_info_binop( + ctx, + next_pipe.to_owned(), + hanging_shape, + next_comments, + ), + ) + } + Pair::End(type_info) => Pair::End(format_type_info_internal( + ctx, + &type_info.update_leading_trivia(FormatTriviaType::Replace(vec![])), + context.mark_contains_intersect(), + hanging_shape.reset() + PIPE_LENGTH, + )), + }; + types.push(new_pair); + is_first = false; + } + + // TODO: handle leading + TypeInfo::Intersection(TypeIntersection::new( + intersection.leading().cloned(), + types, + )) + } other => format_type_info_internal(ctx, other, context, shape), } } @@ -777,7 +897,7 @@ fn can_hang_type(type_info: &TypeInfo) -> bool { matches!( type_info, // Can hang a binary operation - TypeInfo::Union { .. } | TypeInfo::Intersection { .. } + TypeInfo::Union(_) | TypeInfo::Intersection(_) ) } @@ -851,9 +971,30 @@ pub fn format_type_field( _ => FormatTriviaType::NoChange, }; - let key = format_type_field_key(ctx, type_field.key(), leading_trivia, shape); + let access = type_field.access().map(|token_reference| { + format_token_reference(ctx, token_reference, shape) + .update_leading_trivia(leading_trivia.clone()) + .update_trailing_trivia(FormatTriviaType::Append(vec![Token::new( + TokenType::spaces(1), + )])) + }); + let access_shape_increment = access + .as_ref() + .map_or(0, |token| strip_leading_trivia(token).to_string().len() + 1); + + let key = format_type_field_key( + ctx, + type_field.key(), + if access.is_some() { + FormatTriviaType::NoChange + } else { + leading_trivia + }, + shape, + ); let colon_token = fmt_symbol!(ctx, type_field.colon_token(), ": ", shape); - let shape = shape + (strip_leading_trivia(&key).to_string().len() + 2); + let shape = shape + access_shape_increment + (strip_leading_trivia(&key).to_string().len() + 2); + let mut value = format_type_info(ctx, type_field.value(), shape); // Trailing trivia consists only of single line comments - multiline comments are kept in place @@ -876,6 +1017,7 @@ pub fn format_type_field( ( type_field .to_owned() + .with_access(access) .with_key(key) .with_colon_token(colon_token) .with_value(value), @@ -922,21 +1064,39 @@ pub fn format_type_assertion( fn should_hang_type(type_info: &TypeInfo, comment_search: CommentSearch) -> bool { // Only hang if its a binary type info, since it doesn't matter for unary types match type_info { - TypeInfo::Union { - left, - pipe: binop, - right, + TypeInfo::Union(union) => { + let has_leading = union.leading().is_some(); + union.leading().has_trailing_comments(comment_search) + || union + .types() + .pairs() + .enumerate() + .any(|(idx, pair)| match pair { + Pair::Punctuated(type_info, binop) => { + ((idx != 0 || has_leading) + && type_info.has_leading_comments(comment_search)) + || type_info.has_trailing_comments(comment_search) + || contains_comments(binop) + } + Pair::End(type_info) => type_info.has_leading_comments(comment_search), + }) } - | TypeInfo::Intersection { - left, - ampersand: binop, - right, - } => { - left.has_trailing_comments(comment_search) - || should_hang_type(left, comment_search) - || contains_comments(binop) - || right.has_leading_comments(comment_search) - || should_hang_type(right, comment_search) + TypeInfo::Intersection(intersection) => { + let has_leading = intersection.leading().is_some(); + intersection.leading().has_trailing_comments(comment_search) + || intersection + .types() + .pairs() + .enumerate() + .any(|(idx, pair)| match pair { + Pair::Punctuated(type_info, binop) => { + ((idx != 0 || has_leading) + && type_info.has_leading_comments(comment_search)) + || type_info.has_trailing_comments(comment_search) + || contains_comments(binop) + } + Pair::End(type_info) => type_info.has_leading_comments(comment_search), + }) } _ => false, } @@ -1188,11 +1348,11 @@ fn format_generic_parameter( GenericParameterInfo::Name(token_reference) => { GenericParameterInfo::Name(format_token_reference(ctx, token_reference, shape)) } - GenericParameterInfo::Variadic { name, ellipse } => { + GenericParameterInfo::Variadic { name, ellipsis } => { let name = format_token_reference(ctx, name, shape); - let ellipse = fmt_symbol!(ctx, ellipse, "...", shape); + let ellipsis = fmt_symbol!(ctx, ellipsis, "...", shape); - GenericParameterInfo::Variadic { name, ellipse } + GenericParameterInfo::Variadic { name, ellipsis } } other => panic!("unknown node {:?}", other), diff --git a/src/formatters/stmt.rs b/src/formatters/stmt.rs index c345f93f..d6fb7d67 100644 --- a/src/formatters/stmt.rs +++ b/src/formatters/stmt.rs @@ -930,9 +930,12 @@ pub(crate) mod stmt_block { unop: unop.to_owned(), expression: Box::new(format_expression_block(ctx, expression, shape)), }, - Expression::Function((function_token, body)) => { - let block = format_block(ctx, body.block(), shape); - Expression::Function((function_token.to_owned(), body.to_owned().with_block(block))) + Expression::Function(anonymous_function) => { + let block = format_block(ctx, anonymous_function.1.block(), shape); + Expression::Function(Box::new(( + anonymous_function.0.to_owned(), + anonymous_function.1.to_owned().with_block(block), + ))) } Expression::FunctionCall(function_call) => { Expression::FunctionCall(format_function_call_block(ctx, function_call, shape)) diff --git a/src/formatters/table.rs b/src/formatters/table.rs index db17bf0e..6c31f7a8 100644 --- a/src/formatters/table.rs +++ b/src/formatters/table.rs @@ -407,8 +407,8 @@ where } fn expression_is_multiline_function(ctx: &Context, expression: &Expression) -> bool { - if let Expression::Function((_, function_body)) = expression { - return !should_collapse_function_body(ctx, function_body); + if let Expression::Function(anonymous_function) = expression { + return !should_collapse_function_body(ctx, &anonymous_function.1); } false } diff --git a/src/formatters/trivia.rs b/src/formatters/trivia.rs index abcb86f8..97152c19 100644 --- a/src/formatters/trivia.rs +++ b/src/formatters/trivia.rs @@ -1,10 +1,11 @@ #[cfg(feature = "lua54")] use full_moon::ast::lua54::Attribute; #[cfg(feature = "luau")] -use full_moon::ast::types::{ +use full_moon::ast::luau::{ ElseIfExpression, GenericDeclaration, GenericDeclarationParameter, GenericParameterInfo, IfExpression, IndexedTypeInfo, InterpolatedString, InterpolatedStringSegment, TypeArgument, - TypeAssertion, TypeDeclaration, TypeField, TypeFieldKey, TypeInfo, TypeSpecifier, + TypeAssertion, TypeDeclaration, TypeField, TypeFieldKey, TypeInfo, TypeIntersection, + TypeSpecifier, TypeUnion, }; use full_moon::ast::{ punctuated::Punctuated, span::ContainedSpan, BinOp, Call, Expression, FunctionArgs, @@ -241,10 +242,10 @@ define_update_leading_trivia!(Expression, |this, leading| { binop: binop.to_owned(), rhs: rhs.to_owned(), }, - Expression::Function((token, function_body)) => Expression::Function(( - token.update_leading_trivia(leading), - function_body.to_owned(), - )), + Expression::Function(anonymous_function) => Expression::Function(Box::new(( + anonymous_function.0.update_leading_trivia(leading), + anonymous_function.1.to_owned(), + ))), Expression::FunctionCall(function_call) => { Expression::FunctionCall(function_call.update_leading_trivia(leading)) } @@ -283,10 +284,10 @@ define_update_leading_trivia!(Expression, |this, leading| { define_update_trailing_trivia!(Expression, |this, trailing| { match this { - Expression::Function((token, function_body)) => Expression::Function(( - token.to_owned(), - function_body.update_trailing_trivia(trailing), - )), + Expression::Function(anonymous_function) => Expression::Function(Box::new(( + anonymous_function.0.to_owned(), + anonymous_function.1.update_trailing_trivia(trailing), + ))), Expression::FunctionCall(function_call) => { Expression::FunctionCall(function_call.update_trailing_trivia(trailing)) } @@ -450,7 +451,7 @@ define_update_trivia!(MethodCall, |this, leading, trailing| { define_update_trivia!(Parameter, |this, leading, trailing| { match this { - Parameter::Ellipse(token) => Parameter::Ellipse(token.update_trivia(leading, trailing)), + Parameter::Ellipsis(token) => Parameter::Ellipsis(token.update_trivia(leading, trailing)), Parameter::Name(token) => Parameter::Name(token.update_trivia(leading, trailing)), other => panic!("unknown node {:?}", other), } @@ -758,11 +759,50 @@ define_update_trivia!(VarExpression, |this, leading, trailing| { this.to_owned().with_prefix(prefix).with_suffixes(suffixes) }); +#[cfg(feature = "luau")] +define_update_trivia!(TypeUnion, |this, leading, trailing| { + if let Some(leading_token) = this.leading() { + TypeUnion::new( + Some(leading_token.update_leading_trivia(leading)), + this.types().update_trailing_trivia(trailing), + ) + } else { + TypeUnion::new( + None, + this.types() + .update_leading_trivia(leading) + .update_trailing_trivia(trailing), + ) + } +}); + +#[cfg(feature = "luau")] +define_update_trivia!(TypeIntersection, |this, leading, trailing| { + if let Some(leading_token) = this.leading() { + TypeIntersection::new( + Some(leading_token.update_leading_trivia(leading)), + this.types().update_trailing_trivia(trailing), + ) + } else { + TypeIntersection::new( + None, + this.types() + .update_leading_trivia(leading) + .update_trailing_trivia(trailing), + ) + } +}); + #[cfg(feature = "luau")] define_update_trivia!(TypeInfo, |this, leading, trailing| { match this { - TypeInfo::Array { braces, type_info } => TypeInfo::Array { + TypeInfo::Array { + braces, + access, + type_info, + } => TypeInfo::Array { braces: braces.update_trivia(leading, trailing), + access: access.to_owned(), type_info: type_info.to_owned(), }, TypeInfo::Basic(token_reference) => { @@ -807,20 +847,14 @@ define_update_trivia!(TypeInfo, |this, leading, trailing| { generics: generics.to_owned(), }, - TypeInfo::GenericPack { name, ellipse } => TypeInfo::GenericPack { + TypeInfo::GenericPack { name, ellipsis } => TypeInfo::GenericPack { name: name.update_leading_trivia(leading), - ellipse: ellipse.update_trailing_trivia(trailing), + ellipsis: ellipsis.update_trailing_trivia(trailing), }, - TypeInfo::Intersection { - left, - ampersand, - right, - } => TypeInfo::Intersection { - left: Box::new(left.update_leading_trivia(leading)), - ampersand: ampersand.to_owned(), - right: Box::new(right.update_trailing_trivia(trailing)), - }, + TypeInfo::Intersection(intersection) => { + TypeInfo::Intersection(intersection.update_trivia(leading, trailing)) + } TypeInfo::Module { module, @@ -860,19 +894,18 @@ define_update_trivia!(TypeInfo, |this, leading, trailing| { types: types.to_owned(), }, - TypeInfo::Union { left, pipe, right } => TypeInfo::Union { - left: Box::new(left.update_leading_trivia(leading)), - pipe: pipe.to_owned(), - right: Box::new(right.update_trailing_trivia(trailing)), - }, + TypeInfo::Union(union) => TypeInfo::Union(union.update_trivia(leading, trailing)), - TypeInfo::Variadic { ellipse, type_info } => TypeInfo::Variadic { - ellipse: ellipse.update_leading_trivia(leading), + TypeInfo::Variadic { + ellipsis, + type_info, + } => TypeInfo::Variadic { + ellipsis: ellipsis.update_leading_trivia(leading), type_info: Box::new(type_info.update_trailing_trivia(trailing)), }, - TypeInfo::VariadicPack { ellipse, name } => TypeInfo::VariadicPack { - ellipse: ellipse.update_leading_trivia(leading), + TypeInfo::VariadicPack { ellipsis, name } => TypeInfo::VariadicPack { + ellipsis: ellipsis.update_leading_trivia(leading), name: name.update_trailing_trivia(trailing), }, @@ -935,8 +968,13 @@ define_update_trivia!(TypeAssertion, |this, leading, trailing| { #[cfg(feature = "luau")] define_update_leading_trivia!(TypeField, |this, leading| { - this.to_owned() - .with_key(this.key().update_leading_trivia(leading)) + if let Some(access) = this.access() { + this.to_owned() + .with_access(Some(access.update_leading_trivia(leading))) + } else { + this.to_owned() + .with_key(this.key().update_leading_trivia(leading)) + } }); #[cfg(feature = "luau")] @@ -975,9 +1013,9 @@ define_update_leading_trivia!(GenericDeclarationParameter, |this, leading| { GenericParameterInfo::Name(token) => { GenericParameterInfo::Name(token.update_leading_trivia(leading)) } - GenericParameterInfo::Variadic { name, ellipse } => GenericParameterInfo::Variadic { + GenericParameterInfo::Variadic { name, ellipsis } => GenericParameterInfo::Variadic { name: name.update_leading_trivia(leading), - ellipse: ellipse.to_owned(), + ellipsis: ellipsis.to_owned(), }, other => panic!("unknown node {:?}", other), }; @@ -996,9 +1034,9 @@ define_update_trailing_trivia!(GenericDeclarationParameter, |this, trailing| { GenericParameterInfo::Name(token) => { GenericParameterInfo::Name(token.update_trailing_trivia(trailing)) } - GenericParameterInfo::Variadic { name, ellipse } => GenericParameterInfo::Variadic { + GenericParameterInfo::Variadic { name, ellipsis } => GenericParameterInfo::Variadic { name: name.to_owned(), - ellipse: ellipse.update_trailing_trivia(trailing), + ellipsis: ellipsis.update_trailing_trivia(trailing), }, other => panic!("unknown node {:?}", other), }; diff --git a/src/formatters/trivia_util.rs b/src/formatters/trivia_util.rs index 96f19c7e..31981706 100644 --- a/src/formatters/trivia_util.rs +++ b/src/formatters/trivia_util.rs @@ -4,15 +4,15 @@ use crate::{ shape::Shape, }; #[cfg(feature = "luau")] -use full_moon::ast::types::{ +use full_moon::ast::luau::{ GenericDeclarationParameter, GenericParameterInfo, IndexedTypeInfo, TypeArgument, - TypeDeclaration, TypeInfo, TypeSpecifier, + TypeDeclaration, TypeInfo, TypeIntersection, TypeSpecifier, TypeUnion, }; use full_moon::{ ast::{ - punctuated::Punctuated, BinOp, Block, Call, Expression, Field, FunctionArgs, Index, - LastStmt, LocalAssignment, Parameter, Prefix, Stmt, Suffix, TableConstructor, UnOp, Var, - VarExpression, + punctuated::{Pair, Punctuated}, + BinOp, Block, Call, Expression, Field, FunctionArgs, Index, LastStmt, LocalAssignment, + Parameter, Prefix, Stmt, Suffix, TableConstructor, UnOp, Var, VarExpression, }, node::Node, tokenizer::{Token, TokenKind, TokenReference, TokenType}, @@ -156,6 +156,50 @@ pub fn is_block_simple(block: &Block) -> bool { }) } +impl GetLeadingTrivia for &T +where + T: GetLeadingTrivia, +{ + fn leading_trivia(&self) -> Vec { + (*self).leading_trivia() + } +} + +impl GetLeadingTrivia for Option<&T> +where + T: GetLeadingTrivia, +{ + fn leading_trivia(&self) -> Vec { + match self { + Some(node) => node.leading_trivia(), + None => Vec::new(), + } + } +} + +impl GetTrailingTrivia for Option<&T> +where + T: GetTrailingTrivia, +{ + fn trailing_trivia(&self) -> Vec { + match self { + Some(node) => node.trailing_trivia(), + None => Vec::new(), + } + } +} + +impl GetLeadingTrivia for Pair +where + T: GetLeadingTrivia, +{ + fn leading_trivia(&self) -> Vec { + match self { + Pair::Punctuated(node, _) | Pair::End(node) => node.leading_trivia(), + } + } +} + // TODO: Can we clean this up? A lot of this code is repeated in trivia_formatter impl GetTrailingTrivia for FunctionArgs { fn trailing_trivia(&self) -> Vec { @@ -247,8 +291,8 @@ impl GetTrailingTrivia for GenericDeclarationParameter { } else { match self.parameter() { GenericParameterInfo::Name(token) => token.trailing_trivia().cloned().collect(), - GenericParameterInfo::Variadic { ellipse, .. } => { - ellipse.trailing_trivia().cloned().collect() + GenericParameterInfo::Variadic { ellipsis, .. } => { + ellipsis.trailing_trivia().cloned().collect() } other => panic!("unknown node {:?}", other), } @@ -290,7 +334,9 @@ impl GetLeadingTrivia for Expression { other => panic!("unknown node {:?}", other), }, Expression::BinaryOperator { lhs, .. } => lhs.leading_trivia(), - Expression::Function((token_ref, _)) => GetLeadingTrivia::leading_trivia(token_ref), + Expression::Function(anonymous_function) => { + GetLeadingTrivia::leading_trivia(&anonymous_function.0) + } Expression::FunctionCall(function_call) => function_call.prefix().leading_trivia(), #[cfg(feature = "luau")] Expression::IfExpression(if_expression) => { @@ -326,8 +372,8 @@ impl GetTrailingTrivia for Expression { } Expression::UnaryOperator { expression, .. } => expression.trailing_trivia(), Expression::BinaryOperator { rhs, .. } => rhs.trailing_trivia(), - Expression::Function((_, function_body)) => { - GetTrailingTrivia::trailing_trivia(function_body.end_token()) + Expression::Function(anonymous_function) => { + GetTrailingTrivia::trailing_trivia(anonymous_function.1.end_token()) } Expression::FunctionCall(function_call) => function_call .suffixes() @@ -458,7 +504,7 @@ pub fn take_trailing_comments( impl GetTrailingTrivia for Parameter { fn trailing_trivia(&self) -> Vec { match self { - Parameter::Name(token) | Parameter::Ellipse(token) => { + Parameter::Name(token) | Parameter::Ellipsis(token) => { GetTrailingTrivia::trailing_trivia(token) } other => panic!("unknown node {:?}", other), @@ -493,6 +539,28 @@ impl GetTrailingTrivia for IndexedTypeInfo { } } +#[cfg(feature = "luau")] +impl GetTrailingTrivia for TypeIntersection { + fn trailing_trivia(&self) -> Vec { + self.types() + .last() + .expect("TypeIntersection was empty") + .value() + .trailing_trivia() + } +} + +#[cfg(feature = "luau")] +impl GetTrailingTrivia for TypeUnion { + fn trailing_trivia(&self) -> Vec { + self.types() + .last() + .expect("TypeIntersection was empty") + .value() + .trailing_trivia() + } +} + #[cfg(feature = "luau")] impl GetTrailingTrivia for TypeInfo { fn trailing_trivia(&self) -> Vec { @@ -505,8 +573,8 @@ impl GetTrailingTrivia for TypeInfo { TypeInfo::Generic { arrows, .. } => { GetTrailingTrivia::trailing_trivia(arrows.tokens().1) } - TypeInfo::GenericPack { ellipse, .. } => GetTrailingTrivia::trailing_trivia(ellipse), - TypeInfo::Intersection { right, .. } => right.trailing_trivia(), + TypeInfo::GenericPack { ellipsis, .. } => GetTrailingTrivia::trailing_trivia(ellipsis), + TypeInfo::Intersection(intersection) => intersection.trailing_trivia(), TypeInfo::Module { type_info, .. } => type_info.trailing_trivia(), TypeInfo::Optional { question_mark, .. } => { GetTrailingTrivia::trailing_trivia(question_mark) @@ -518,7 +586,7 @@ impl GetTrailingTrivia for TypeInfo { TypeInfo::Tuple { parentheses, .. } => { GetTrailingTrivia::trailing_trivia(parentheses.tokens().1) } - TypeInfo::Union { right, .. } => right.trailing_trivia(), + TypeInfo::Union(union) => union.trailing_trivia(), TypeInfo::Variadic { type_info, .. } => type_info.trailing_trivia(), TypeInfo::VariadicPack { name, .. } => GetTrailingTrivia::trailing_trivia(name), other => panic!("unknown node {:?}", other), @@ -526,6 +594,36 @@ impl GetTrailingTrivia for TypeInfo { } } +#[cfg(feature = "luau")] +impl GetLeadingTrivia for TypeIntersection { + fn leading_trivia(&self) -> Vec { + match self.leading() { + Some(leading) => GetLeadingTrivia::leading_trivia(leading), + None => self + .types() + .first() + .expect("TypeIntersection was empty") + .value() + .leading_trivia(), + } + } +} + +#[cfg(feature = "luau")] +impl GetLeadingTrivia for TypeUnion { + fn leading_trivia(&self) -> Vec { + match self.leading() { + Some(leading) => GetLeadingTrivia::leading_trivia(leading), + None => self + .types() + .first() + .expect("TypeUnion was empty") + .value() + .leading_trivia(), + } + } +} + #[cfg(feature = "luau")] impl GetLeadingTrivia for TypeInfo { fn leading_trivia(&self) -> Vec { @@ -544,7 +642,7 @@ impl GetLeadingTrivia for TypeInfo { }, TypeInfo::Generic { base, .. } => GetLeadingTrivia::leading_trivia(base), TypeInfo::GenericPack { name, .. } => GetLeadingTrivia::leading_trivia(name), - TypeInfo::Intersection { left, .. } => left.leading_trivia(), + TypeInfo::Intersection(intersection) => intersection.leading_trivia(), TypeInfo::Module { module, .. } => GetLeadingTrivia::leading_trivia(module), TypeInfo::Optional { base, .. } => base.leading_trivia(), TypeInfo::Table { braces, .. } => GetLeadingTrivia::leading_trivia(braces.tokens().0), @@ -552,9 +650,9 @@ impl GetLeadingTrivia for TypeInfo { TypeInfo::Tuple { parentheses, .. } => { GetLeadingTrivia::leading_trivia(parentheses.tokens().0) } - TypeInfo::Union { left, .. } => left.leading_trivia(), - TypeInfo::Variadic { ellipse, .. } => GetLeadingTrivia::leading_trivia(ellipse), - TypeInfo::VariadicPack { ellipse, .. } => GetLeadingTrivia::leading_trivia(ellipse), + TypeInfo::Union(union) => union.leading_trivia(), + TypeInfo::Variadic { ellipsis, .. } => GetLeadingTrivia::leading_trivia(ellipsis), + TypeInfo::VariadicPack { ellipsis, .. } => GetLeadingTrivia::leading_trivia(ellipsis), other => panic!("unknown node {:?}", other), } } diff --git a/src/lib.rs b/src/lib.rs index e6778c69..b9671827 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -14,6 +14,55 @@ mod shape; mod sort_requires; mod verify_ast; +/// The Lua syntax version to use +#[derive(Debug, Default, Copy, Clone, PartialEq, Eq, Deserialize)] +#[cfg_attr(all(target_arch = "wasm32", feature = "wasm-bindgen"), wasm_bindgen)] +#[cfg_attr(feature = "serialize", derive(serde::Serialize))] +#[cfg_attr(feature = "fromstr", derive(strum::EnumString))] +pub enum LuaVersion { + /// Parse all syntax versions at the same time. This allows most general usage. + /// For overlapping syntaxes (e.g., Lua5.2 label syntax and Luau type assertions), select a + /// specific syntax version + #[default] + All, + /// Parse Lua 5.1 code + Lua51, + /// Parse Lua 5.2 code + #[cfg(feature = "lua52")] + Lua52, + /// Parse Lua 5.3 code + #[cfg(feature = "lua53")] + Lua53, + /// Parse Lua 5.4 code + #[cfg(feature = "lua54")] + Lua54, + /// Parse Luau code + #[cfg(feature = "luau")] + Luau, + /// Parse LuaJIT code + #[cfg(feature = "luajit")] + LuaJIT, +} + +impl From for full_moon::LuaVersion { + fn from(val: LuaVersion) -> Self { + match val { + LuaVersion::All => full_moon::LuaVersion::new(), + LuaVersion::Lua51 => full_moon::LuaVersion::lua51(), + #[cfg(feature = "lua52")] + LuaVersion::Lua52 => full_moon::LuaVersion::lua52(), + #[cfg(feature = "lua53")] + LuaVersion::Lua53 => full_moon::LuaVersion::lua53(), + #[cfg(feature = "lua54")] + LuaVersion::Lua54 => full_moon::LuaVersion::lua54(), + #[cfg(feature = "luau")] + LuaVersion::Luau => full_moon::LuaVersion::luau(), + #[cfg(feature = "luajit")] + LuaVersion::LuaJIT => full_moon::LuaVersion::luajit(), + } + } +} + /// The type of indents to use when indenting #[derive(Debug, Default, Copy, Clone, PartialEq, Eq, Deserialize)] #[cfg_attr(all(target_arch = "wasm32", feature = "wasm-bindgen"), wasm_bindgen)] @@ -162,6 +211,8 @@ pub enum SpaceAfterFunctionNames { #[cfg_attr(all(target_arch = "wasm32", feature = "wasm-bindgen"), wasm_bindgen)] #[cfg_attr(feature = "serialize", derive(serde::Serialize))] pub struct Config { + /// The type of Lua syntax to parse. + pub syntax: LuaVersion, /// The approximate line length to use when printing the code. /// This is used as a guide to determine when to wrap lines, but note /// that this is not a hard upper bound. @@ -360,6 +411,7 @@ impl Default for Config { fn default() -> Self { #[allow(deprecated)] Self { + syntax: LuaVersion::default(), column_width: 120, line_endings: LineEndings::default(), indent_type: IndentType::default(), @@ -388,11 +440,11 @@ pub enum OutputVerification { #[derive(Clone, Debug, Error)] pub enum Error { /// The input AST has a parsing error. - #[error("error parsing: {0}")] - ParseError(full_moon::Error), + #[error("error parsing: {0:?}")] + ParseError(Vec), /// The output AST after formatting generated a parse error. This is a definite error. - #[error("INTERNAL ERROR: Output AST generated a syntax error. Please report this at https://github.com/johnnymorganz/stylua/issues\n{0}")] - VerificationAstError(full_moon::Error), + #[error("INTERNAL ERROR: Output AST generated a syntax error. Please report this at https://github.com/johnnymorganz/stylua/issues\n{0:?}")] + VerificationAstError(Vec), /// The output AST after formatting differs from the input AST. #[error("INTERNAL WARNING: Output AST may be different to input AST. Code correctness may have changed. Please examine the formatting diff and report any issues at https://github.com/johnnymorganz/stylua/issues")] VerificationAstDifference, @@ -426,13 +478,14 @@ pub fn format_ast( // If we are verifying, reparse the output then check it matches the original input if let Some(input_ast) = input_ast_for_verification { - let output = full_moon::print(&ast); - let reparsed_output = match full_moon::parse(&output) { - Ok(ast) => ast, - Err(error) => { - return Err(Error::VerificationAstError(error)); - } - }; + let output = ast.to_string(); + let reparsed_output = + match full_moon::parse_fallible(&output, config.syntax.into()).into_result() { + Ok(ast) => ast, + Err(error) => { + return Err(Error::VerificationAstError(error)); + } + }; let mut ast_verifier = verify_ast::AstVerifier::new(); if !ast_verifier.compare(input_ast, reparsed_output) { @@ -451,7 +504,7 @@ pub fn format_code( range: Option, verify_output: OutputVerification, ) -> Result { - let input_ast = match full_moon::parse(code) { + let input_ast = match full_moon::parse_fallible(code, config.syntax.into()).into_result() { Ok(ast) => ast, Err(error) => { return Err(Error::ParseError(error)); @@ -459,7 +512,7 @@ pub fn format_code( }; let ast = format_ast(input_ast, config, range, verify_output)?; - let output = full_moon::print(&ast); + let output = ast.to_string(); Ok(output) } diff --git a/src/verify_ast.rs b/src/verify_ast.rs index 32921483..ba1233fb 100644 --- a/src/verify_ast.rs +++ b/src/verify_ast.rs @@ -10,7 +10,7 @@ use full_moon::{ }; #[cfg(feature = "luau")] -use full_moon::ast::types::TypeInfo; +use full_moon::ast::luau::TypeInfo; pub struct AstVerifier {} @@ -130,7 +130,7 @@ impl VisitorMut for AstVerifier { #[cfg(feature = "luau")] let text = text.replace('_', ""); // LuaJIT (Lua52): remove suffixes - #[cfg(feature = "lua52")] + #[cfg(feature = "luajit")] let text = text .trim_end_matches("ULL") .trim_end_matches("LL") @@ -168,11 +168,11 @@ impl VisitorMut for AstVerifier { let token_type = match token.token_type() { TokenType::StringLiteral { literal, - multi_line, + multi_line_depth, .. } => TokenType::StringLiteral { literal: literal.to_owned().replace('\\', "").into(), - multi_line: multi_line.to_owned(), + multi_line_depth: multi_line_depth.to_owned(), quote_type: StringLiteralQuoteType::Brackets, }, _ => unreachable!(), @@ -277,8 +277,14 @@ mod tests { #[test] #[cfg(feature = "luau")] fn test_equivalent_binary_numbers() { - let input_ast = full_moon::parse("local x = 0B10101").unwrap(); - let output_ast = full_moon::parse("local x = 0b10101").unwrap(); + use full_moon::LuaVersion; + + let input_ast = full_moon::parse_fallible("local x = 0B10101", LuaVersion::luau()) + .into_result() + .unwrap(); + let output_ast = full_moon::parse_fallible("local x = 0b10101", LuaVersion::luau()) + .into_result() + .unwrap(); let mut ast_verifier = AstVerifier::new(); assert!(ast_verifier.compare(input_ast, output_ast)); @@ -287,18 +293,30 @@ mod tests { #[test] #[cfg(feature = "luau")] fn test_different_binary_numbers() { - let input_ast = full_moon::parse("local x = 0b1111").unwrap(); - let output_ast = full_moon::parse("local x = 0b1110").unwrap(); + use full_moon::LuaVersion; + + let input_ast = full_moon::parse_fallible("local x = 0b1111", LuaVersion::luau()) + .into_result() + .unwrap(); + let output_ast = full_moon::parse_fallible("local x = 0b1110", LuaVersion::luau()) + .into_result() + .unwrap(); let mut ast_verifier = AstVerifier::new(); assert!(!ast_verifier.compare(input_ast, output_ast)); } #[test] - #[cfg(feature = "lua52")] + #[cfg(feature = "luajit")] fn test_equivalent_luajit_numbers() { - let input_ast = full_moon::parse("local x = 2 ^ 63LL").unwrap(); - let output_ast = full_moon::parse("local x = 2 ^ 63").unwrap(); + use full_moon::LuaVersion; + + let input_ast = full_moon::parse_fallible("local x = 2 ^ 63LL", LuaVersion::luajit()) + .into_result() + .unwrap(); + let output_ast = full_moon::parse_fallible("local x = 2 ^ 63", LuaVersion::luajit()) + .into_result() + .unwrap(); let mut ast_verifier = AstVerifier::new(); assert!(ast_verifier.compare(input_ast, output_ast)); diff --git a/tests/snapshots/tests__luau@type-callback-hanging.lua.snap b/tests/snapshots/tests__luau@type-callback-hanging.lua.snap index c129c1e9..bec9a91e 100644 --- a/tests/snapshots/tests__luau@type-callback-hanging.lua.snap +++ b/tests/snapshots/tests__luau@type-callback-hanging.lua.snap @@ -1,12 +1,10 @@ --- source: tests/tests.rs -expression: format(&contents) +expression: "format(&contents, LuaVersion::Luau)" +input_file: tests/inputs-luau/type-callback-hanging.lua --- export type Thenable = { - andTheeeeeeeeeeeeeeen: ( - any, - (R) -> () | Thenable | U, - (any) -> () | Thenable | U - ) -> () | Thenable, + andTheeeeeeeeeeeeeeen: (any, (R) -> () | Thenable | U, (any) -> () | Thenable | U) -> () + | Thenable, } diff --git a/tests/test_ranges.rs b/tests/test_ranges.rs index a0ee070a..3fece4e3 100644 --- a/tests/test_ranges.rs +++ b/tests/test_ranges.rs @@ -92,10 +92,6 @@ fn test_incomplete_range() { } #[test] -#[cfg_attr( - all(debug_assertions, feature = "luau"), - ignore = "fails in debug mode" // TODO: https://github.com/Kampfkarren/full-moon/issues/140 -)] fn test_large_example() { insta::assert_snapshot!( format( diff --git a/tests/tests.rs b/tests/tests.rs index 187b8007..c5a49b43 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -1,26 +1,29 @@ use stylua_lib::{ - format_code, CollapseSimpleStatement, Config, OutputVerification, SortRequiresConfig, + format_code, CollapseSimpleStatement, Config, LuaVersion, OutputVerification, + SortRequiresConfig, }; -fn format(input: &str) -> String { - format_code(input, Config::default(), None, OutputVerification::None).unwrap() +fn format(input: &str, syntax: LuaVersion) -> String { + let config = Config { + syntax, + ..Config::default() + }; + format_code(input, config, None, OutputVerification::None).unwrap() } #[test] -#[cfg_attr(feature = "luau", ignore)] fn test_standard() { insta::glob!("inputs/*.lua", |path| { let contents = std::fs::read_to_string(path).unwrap(); - insta::assert_snapshot!(format(&contents)); + insta::assert_snapshot!(format(&contents, LuaVersion::Lua51)); }) } #[test] -#[cfg_attr(feature = "lua52", ignore)] // A test case has `goto` as an identifier, which is not allowed in Lua 5.2 fn test_full_moon_test_suite() { insta::glob!("inputs-full_moon/*.lua", |path| { let contents = std::fs::read_to_string(path).unwrap(); - insta::assert_snapshot!(format(&contents)); + insta::assert_snapshot!(format(&contents, LuaVersion::Lua51)); }) } @@ -30,7 +33,7 @@ fn test_luau() { insta::glob!("inputs-luau/*.lua", |path| { dbg!(path); let contents = std::fs::read_to_string(path).unwrap(); - insta::assert_snapshot!(format(&contents)); + insta::assert_snapshot!(format(&contents, LuaVersion::Luau)); }) } @@ -39,7 +42,7 @@ fn test_luau() { fn test_luau_full_moon() { insta::glob!("inputs-luau-full_moon/*.lua", |path| { let contents = std::fs::read_to_string(path).unwrap(); - insta::assert_snapshot!(format(&contents)); + insta::assert_snapshot!(format(&contents, LuaVersion::Luau)); }) } @@ -48,7 +51,7 @@ fn test_luau_full_moon() { fn test_lua52() { insta::glob!("inputs-lua52/*.lua", |path| { let contents = std::fs::read_to_string(path).unwrap(); - insta::assert_snapshot!(format(&contents)); + insta::assert_snapshot!(format(&contents, LuaVersion::Lua52)); }) } @@ -57,7 +60,7 @@ fn test_lua52() { fn test_lua53() { insta::glob!("inputs-lua53/*.lua", |path| { let contents = std::fs::read_to_string(path).unwrap(); - insta::assert_snapshot!(format(&contents)); + insta::assert_snapshot!(format(&contents, LuaVersion::Lua53)); }) } @@ -66,7 +69,7 @@ fn test_lua53() { fn test_lua54() { insta::glob!("inputs-lua54/*.lua", |path| { let contents = std::fs::read_to_string(path).unwrap(); - insta::assert_snapshot!(format(&contents)); + insta::assert_snapshot!(format(&contents, LuaVersion::Lua54)); }) } @@ -74,7 +77,7 @@ fn test_lua54() { fn test_ignores() { insta::glob!("inputs-ignore/*.lua", |path| { let contents = std::fs::read_to_string(path).unwrap(); - insta::assert_snapshot!(format(&contents)); + insta::assert_snapshot!(format(&contents, LuaVersion::Lua51)); }) } @@ -107,6 +110,7 @@ fn test_collapse_single_statement_lua_52() { end "###, Config { + syntax: LuaVersion::Lua52, collapse_simple_statement: CollapseSimpleStatement::Always, ..Config::default() }, @@ -152,7 +156,7 @@ local x = 1 "#; let code_crlf = code.lines().collect::>().join("\r\n"); - let output = format(&code_crlf); + let output = format(&code_crlf, LuaVersion::Lua51); assert_eq!(output.find("\r\n"), None); } @@ -170,6 +174,6 @@ local x = 1 "###; let code_crlf = code.lines().collect::>().join("\r\n"); - let output = format(&code_crlf); + let output = format(&code_crlf, LuaVersion::Lua51); assert_eq!(output.find("\r\n"), None); } diff --git a/wasm/build-wasm.sh b/wasm/build-wasm.sh index 1872d05f..87259bc2 100755 --- a/wasm/build-wasm.sh +++ b/wasm/build-wasm.sh @@ -1,7 +1,7 @@ # TODO: Ensure that version is up to date cp README.md wasm/ cp LICENSE.md wasm/ -npx wasm-pack@0.10.3 build --target web --out-dir wasm/stylua.web -- --features lua52,lua53,lua54,luau +npx wasm-pack@0.10.3 build --target web --out-dir wasm/stylua.web -- --features lua52,lua53,lua54,luajit,luau # workaround for bundler usage echo "export { getImports as __getImports, finalizeInit as __finalizeInit }" >> wasm/stylua.web/stylua_lib.js