From 98cc79a2becb2218c5c4dffced12838dc5bf844c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Donny/=EA=B0=95=EB=8F=99=EC=9C=A4?= Date: Mon, 11 Oct 2021 16:44:42 +0900 Subject: [PATCH] fix(es/minifer): Fix bugs (#2397) swc_ecma_codegen: - Fix sourcemap of `export` tokens. - Fix codegen of numeric operands in left of a binary expression. - Fix codegen of unary operations. swc_ecma_minifier: - Visit `AssignPatProp.valie`. - Move `inline_prevented` to analyzer. - Add `Ctx.dont_invoke_iife`. - `iife`: Check for `arugments` swc: - `inline_sources_content`: true by default for `minify()`. --- Cargo.lock | 243 ++++----- Cargo.toml | 2 +- ecmascript/codegen/Cargo.toml | 2 +- ecmascript/codegen/src/lib.rs | 78 ++- .../tests/fixture/vercel/d3-color/1/input.js | 28 ++ .../tests/fixture/vercel/d3-color/1/output.js | 29 ++ .../fixture/vercel/d3-color/1/output.min.js | 1 + ecmascript/minifier/Cargo.toml | 2 +- ecmascript/minifier/src/analyzer/mod.rs | 44 +- .../minifier/src/compress/optimize/iife.rs | 17 +- .../minifier/src/compress/optimize/inline.rs | 5 +- .../minifier/src/compress/optimize/mod.rs | 39 +- .../minifier/src/pass/mangle_names/mod.rs | 3 + .../fixture/issues/2257/full/output.js | 12 +- .../fixture/issues/d3-color/1/input.js | 61 +++ .../fixture/issues/d3-color/1/output.js | 28 ++ .../compress/fixture/issues/stylis/1/input.js | 127 +++++ .../fixture/issues/stylis/1/output.js | 119 +++++ .../compress/fixture/issues/stylis/2/input.js | 129 +++++ .../fixture/issues/stylis/2/output.js | 117 +++++ ecmascript/minifier/tests/mangle.rs | 45 +- ecmascript/minifier/tests/mangle/1/input.js | 29 ++ ecmascript/minifier/tests/mangle/1/output.js | 34 ++ .../redefine_arguments_2/output.js | 24 +- .../redefine_arguments_3/output.js | 24 +- node-swc/__tests__/minify_test.mjs | 18 - src/config/mod.rs | 7 +- .../fixture/issue-1581/case2/output/index.map | 2 +- tests/fixture/sourcemap/002/output/index.map | 2 +- tests/fixture/sourcemap/003/output/index.map | 2 +- tests/source_map.rs | 5 +- tests/vercel/full-compact/.swcrc | 29 ++ .../full-compact/d3-color/1/input/index.js | 79 +++ .../full-compact/d3-color/1/output/index.js | 1 + tests/vercel/full/.swcrc | 8 +- tests/vercel/full/d3-color/1/input/index.js | 61 +++ tests/vercel/full/d3-color/1/output/index.js | 28 ++ .../react-instantsearch/2/output/index.js | 461 +++++++++--------- 38 files changed, 1459 insertions(+), 486 deletions(-) create mode 100644 ecmascript/codegen/tests/fixture/vercel/d3-color/1/input.js create mode 100644 ecmascript/codegen/tests/fixture/vercel/d3-color/1/output.js create mode 100644 ecmascript/codegen/tests/fixture/vercel/d3-color/1/output.min.js create mode 100644 ecmascript/minifier/tests/compress/fixture/issues/d3-color/1/input.js create mode 100644 ecmascript/minifier/tests/compress/fixture/issues/d3-color/1/output.js create mode 100644 ecmascript/minifier/tests/compress/fixture/issues/stylis/1/input.js create mode 100644 ecmascript/minifier/tests/compress/fixture/issues/stylis/1/output.js create mode 100644 ecmascript/minifier/tests/compress/fixture/issues/stylis/2/input.js create mode 100644 ecmascript/minifier/tests/compress/fixture/issues/stylis/2/output.js create mode 100644 ecmascript/minifier/tests/mangle/1/input.js create mode 100644 ecmascript/minifier/tests/mangle/1/output.js create mode 100644 tests/vercel/full-compact/.swcrc create mode 100644 tests/vercel/full-compact/d3-color/1/input/index.js create mode 100644 tests/vercel/full-compact/d3-color/1/output/index.js create mode 100644 tests/vercel/full/d3-color/1/input/index.js create mode 100644 tests/vercel/full/d3-color/1/output/index.js diff --git a/Cargo.lock b/Cargo.lock index 61ff57aea970..13e832f50086 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -24,8 +24,8 @@ dependencies = [ "crossbeam-channel", "generational-arena", "libloading", - "lock_api 0.4.4", - "parking_lot 0.11.1", + "lock_api 0.4.5", + "parking_lot 0.11.2", "repr_offset", "rustc_version 0.4.0", "serde", @@ -114,15 +114,15 @@ dependencies = [ [[package]] name = "anyhow" -version = "1.0.42" +version = "1.0.44" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "595d3cfa7a60d4555cb5067b99f07142a08ea778de5cf993f7b75c7d8fabc486" +checksum = "61604a8f862e1d5c3229fdd78f8b02c68dcf73a4c4b05fd636d12240aaa242c1" [[package]] name = "arbitrary" -version = "1.0.1" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "237430fd6ed3740afe94eefcc278ae21e050285be882804e0d6e8695f0c94691" +checksum = "577b08a4acd7b99869f863c50011b01eb73424ccc798ecd996f2e24817adfca7" dependencies = [ "derive_arbitrary", ] @@ -242,21 +242,21 @@ checksum = "b4ae4235e6dac0694637c763029ecea1a2ec9e4e06ec2729bd21ba4d9c863eb7" [[package]] name = "bumpalo" -version = "3.7.0" +version = "3.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c59e7af012c713f529e7a3ee57ce9b31ddd858d4b512923602f74608b009631" +checksum = "d9df67f7bf9ef8498769f994239c45613ef0c5899415fb58e9add412d2c1a538" [[package]] name = "bytes" -version = "1.0.1" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b700ce4376041dcd0a327fd0097c41095743c4c8af8887265942faf1100bd040" +checksum = "c4872d67bab6358e59559027aa3b9157c53d9358c51423c17554809a8858e0f8" [[package]] name = "cc" -version = "1.0.69" +version = "1.0.71" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e70cc2f62c6ce1868963827bd677764c62d07c3d9a3e1fb1177ee1a9ab199eb2" +checksum = "79c2681d6594606957bbb8631c4b90a7fcaaa72cdb714743a437b156d6a7eedd" [[package]] name = "cfg-if" @@ -354,9 +354,9 @@ checksum = "79b110b7cd430bd590fa60a5ba58a383488dab61912318bfb05d968a80cdda6d" [[package]] name = "cpufeatures" -version = "0.1.5" +version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "66c99696f6c9dd7f35d486b9d04d7e6e202aa3e8c40d553f2fdf5e7e0c6a71ef" +checksum = "95059428f66df56b63431fdb4e1947ed2190586af5c5a8a8b71122bdf5a7f469" dependencies = [ "libc", ] @@ -432,9 +432,9 @@ dependencies = [ [[package]] name = "cty" -version = "0.2.1" +version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7313c0d620d0cb4dbd9d019e461a4beb501071ff46ec0ab933efb4daa76d73e3" +checksum = "b365fabc795046672053e29c954733ec3b05e4be654ab130fe8f1f94d7051f35" [[package]] name = "darling" @@ -483,9 +483,9 @@ dependencies = [ [[package]] name = "derive_arbitrary" -version = "1.0.1" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5f1281ee141df08871db9fe261ab5312179eac32d1e314134ceaa8dd7c042f5a" +checksum = "b24629208e87a2d8b396ff43b15c4afb0a69cea3fbbaa9ed9b92b7c02f0aed73" dependencies = [ "proc-macro2", "quote", @@ -619,42 +619,42 @@ checksum = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba" [[package]] name = "futures-channel" -version = "0.3.16" +version = "0.3.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "74ed2411805f6e4e3d9bc904c95d5d423b89b3b25dc0250aa74729de20629ff9" +checksum = "5da6ba8c3bb3c165d3c7319fc1cc8304facf1fb8db99c5de877183c08a273888" dependencies = [ "futures-core", ] [[package]] name = "futures-core" -version = "0.3.16" +version = "0.3.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af51b1b4a7fdff033703db39de8802c673eb91855f2e0d47dcf3bf2c0ef01f99" +checksum = "88d1c26957f23603395cd326b0ffe64124b818f4449552f960d815cfba83a53d" [[package]] name = "futures-io" -version = "0.3.16" +version = "0.3.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b0e06c393068f3a6ef246c75cdca793d6a46347e75286933e5e75fd2fd11582" +checksum = "522de2a0fe3e380f1bc577ba0474108faf3f6b18321dbf60b3b9c39a75073377" [[package]] name = "futures-sink" -version = "0.3.16" +version = "0.3.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c0f30aaa67363d119812743aa5f33c201a7a66329f97d1a887022971feea4b53" +checksum = "36ea153c13024fe480590b3e3d4cad89a0cfacecc24577b68f86c6ced9c2bc11" [[package]] name = "futures-task" -version = "0.3.16" +version = "0.3.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbe54a98670017f3be909561f6ad13e810d9a51f3f061b902062ca3da80799f2" +checksum = "1d3d00f4eddb73e498a54394f228cd55853bdf059259e8e7bc6e69d408892e99" [[package]] name = "futures-util" -version = "0.3.16" +version = "0.3.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "67eb846bfd58e44a8481a00049e82c43e0ccb5d61f8dc071057cb19249dd4d78" +checksum = "36568465210a3a6ee45e1f165136d68671471a501e632e9a98d96872222b5481" dependencies = [ "autocfg 1.0.1", "futures-core", @@ -721,9 +721,9 @@ checksum = "9b919933a397b79c37e33b77bb2aa3dc8eb6e165ad809e58ff75bc7db2e34574" [[package]] name = "h2" -version = "0.3.3" +version = "0.3.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "825343c4eef0b63f541f8903f395dc5beb362a979b5799a84062527ef1e37726" +checksum = "6c06815895acec637cd6ed6e9662c935b866d20a106f8361892893a7d9234964" dependencies = [ "bytes", "fnv", @@ -764,9 +764,9 @@ checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" [[package]] name = "http" -version = "0.2.4" +version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "527e8c9ac747e28542699a951517aa9a6945af506cd1f2e1b53a576c17b6cc11" +checksum = "1323096b05d41827dadeaee54c9981958c0f94e670bc94ed80037d1a7b8b186b" dependencies = [ "bytes", "fnv", @@ -786,9 +786,9 @@ dependencies = [ [[package]] name = "httparse" -version = "1.4.1" +version = "1.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f3a87b616e37e93c22fb19bcd386f02f3af5ea98a25670ad0fce773de23c5e68" +checksum = "acd94fdbe1d4ff688b67b04eee2e17bd50995534a61539e45adfefb45e5e5503" [[package]] name = "httpdate" @@ -807,9 +807,9 @@ dependencies = [ [[package]] name = "hyper" -version = "0.14.11" +version = "0.14.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b61cf2d1aebcf6e6352c97b81dc2244ca29194be1b276f5d8ad5c6330fffb11" +checksum = "15d1cfb9e4f68655fa04c01f59edb405b6074a0f7118ea881e5026e4a1cd8593" dependencies = [ "bytes", "futures-channel", @@ -861,9 +861,9 @@ dependencies = [ [[package]] name = "if_chain" -version = "1.0.1" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1f7280c75fb2e2fc47080ec80ccc481376923acb04501957fc38f935c3de5088" +checksum = "cb56e1aa765b4b4f3aadfab769793b7087bb03a4ea4920644a6d238e2df5b9ed" [[package]] name = "indexmap" @@ -878,9 +878,9 @@ dependencies = [ [[package]] name = "instant" -version = "0.1.10" +version = "0.1.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bee0328b1209d157ef001c94dd85b4f8f64139adb0eac2659f4b08382b2f474d" +checksum = "716d3d89f35ac6a34fd0eed635395f4c3b76fa889338a4632e5231a8684216bd" dependencies = [ "cfg-if 1.0.0", ] @@ -906,9 +906,9 @@ dependencies = [ [[package]] name = "itoa" -version = "0.4.7" +version = "0.4.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd25036021b0de88a0aff6b850051563c6516d0bf53f8638938edbb9de732736" +checksum = "b71991ff56294aa922b450139ee08b3bfc70982c6b2c7562771375cf73542dd4" [[package]] name = "js-sys" @@ -966,15 +966,15 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.99" +version = "0.2.103" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a7f823d141fe0a24df1e23b4af4e3c7ba9e5966ec514ea068c93024aa7deb765" +checksum = "dd8f7255a17a627354f321ef0055d63b898c6fb27eff628af4d1b66b7331edf6" [[package]] name = "libloading" -version = "0.7.0" +version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f84d96438c15fcd6c3f244c8fce01d1e2b9c6b5623e9c711dc9286d8fc92d6a" +checksum = "c0cf036d15402bea3c5d4de17b3fce76b3e4a56ebc1f577be0e7a72f7c607cf0" dependencies = [ "cfg-if 1.0.0", "winapi", @@ -992,9 +992,9 @@ dependencies = [ [[package]] name = "lock_api" -version = "0.4.4" +version = "0.4.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0382880606dff6d15c9476c416d18690b72742aa7b605bb6dd6ec9030fbf07eb" +checksum = "712a4d093c9976e24e7dbca41db895dabcbac38eb5f4045393d17a95bdfb1109" dependencies = [ "scopeguard 1.1.0", ] @@ -1113,9 +1113,9 @@ dependencies = [ [[package]] name = "napi" -version = "1.7.5" +version = "1.7.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "59cd02f5de365f9bd6e85f1d11176a9ea70ff63ce55ea4412cb4e00fd5a0fe6c" +checksum = "2813a6f24e181eb1faba8bc632e56049901fb71df4bf3e0cd6b4086db6606c78" dependencies = [ "napi-sys", "serde", @@ -1307,9 +1307,9 @@ dependencies = [ [[package]] name = "object" -version = "0.26.0" +version = "0.26.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c55827317fb4c08822499848a14237d2874d6f139828893017237e7ab93eb386" +checksum = "39f37e50073ccad23b6d09bcb5b263f4e76d3bb6038e4a3c08e52162ffa8abc2" dependencies = [ "memchr", ] @@ -1328,9 +1328,9 @@ checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" [[package]] name = "openssl" -version = "0.10.35" +version = "0.10.36" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "549430950c79ae24e6d02e0b7404534ecf311d94cc9f861e9e4020187d13d885" +checksum = "8d9facdb76fec0b73c406f125d44d86fdad818d66fef0531eec9233ca425ff4a" dependencies = [ "bitflags", "cfg-if 1.0.0", @@ -1348,9 +1348,9 @@ checksum = "28988d872ab76095a6e6ac88d99b54fd267702734fd7ffe610ca27f533ddb95a" [[package]] name = "openssl-sys" -version = "0.9.65" +version = "0.9.67" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a7907e3bfa08bb85105209cdfcb6c63d109f8f6c1ed6ca318fff5c1853fbc1d" +checksum = "69df2d8dfc6ce3aaf44b40dec6f487d5a886516cf6879c49e98e0710f310a058" dependencies = [ "autocfg 1.0.1", "cc", @@ -1361,9 +1361,9 @@ dependencies = [ [[package]] name = "ordered-float" -version = "2.7.0" +version = "2.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "039f02eb0f69271f26abe3202189275d7aa2258b903cb0281b5de710a2570ff3" +checksum = "97c9d06878b3a851e8026ef94bf7fef9ba93062cd412601da4d9cf369b1cc62d" dependencies = [ "num-traits", ] @@ -1398,13 +1398,13 @@ dependencies = [ [[package]] name = "parking_lot" -version = "0.11.1" +version = "0.11.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d7744ac029df22dca6284efe4e898991d28e3085c706c972bcd7da4a27a15eb" +checksum = "7d17b78036a60663b797adeaee46f5c9dfebb86948d1255007a1d6be0271ff99" dependencies = [ "instant", - "lock_api 0.4.4", - "parking_lot_core 0.8.3", + "lock_api 0.4.5", + "parking_lot_core 0.8.5", ] [[package]] @@ -1422,15 +1422,15 @@ dependencies = [ [[package]] name = "parking_lot_core" -version = "0.8.3" +version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa7a782938e745763fe6907fc6ba86946d72f49fe7e21de074e08128a99fb018" +checksum = "d76e8e1493bcac0d2766c42737f34458f1c8c50c0d23bcb24ea953affb273216" dependencies = [ "cfg-if 1.0.0", "instant", "libc", "redox_syscall", - "smallvec 1.6.1", + "smallvec 1.7.0", "winapi", ] @@ -1442,9 +1442,9 @@ checksum = "ecba01bf2678719532c5e3059e0b5f0811273d94b397088b82e3bd0a78c78fdd" [[package]] name = "pathdiff" -version = "0.2.0" +version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "877630b3de15c0b64cc52f659345724fbf6bdad9bd9566699fc53688f3c34a34" +checksum = "8835116a5c179084a830efb3adc117ab007512b535bc1a21c991d3b32a6b44dd" [[package]] name = "percent-encoding" @@ -1520,9 +1520,9 @@ checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" [[package]] name = "pkg-config" -version = "0.3.19" +version = "0.3.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3831453b3449ceb48b6d9c7ad7c96d5ea673e9b470a1dc578c2ce6521230884c" +checksum = "7c9b1041b4387893b91ee6746cddfc28516aff326a3519fb2adf820932c5e6cb" [[package]] name = "pmutil" @@ -1623,9 +1623,9 @@ checksum = "dbf0c48bc1d91375ae5c3cd81e3722dff1abcf81a30960240640d223f59fe0e5" [[package]] name = "proc-macro2" -version = "1.0.28" +version = "1.0.29" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c7ed8b8c7b886ea3ed7dde405212185f423ab44682667c8c6dd14aa1d9f6612" +checksum = "b9f5105d4fdaab20335ca9565e106a5d9b82b6219b5ba735731124ac6711d23d" dependencies = [ "unicode-xid", ] @@ -1638,9 +1638,9 @@ checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0" [[package]] name = "quote" -version = "1.0.9" +version = "1.0.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3d0b9745dc2debf507c8422de05d7226cc1f0644216dfdfead988f9b1ab32a7" +checksum = "38bc8cc6a5f2e3655e0899c1b848643b2562f853f114bfec7be120678e3ace05" dependencies = [ "proc-macro2", ] @@ -1943,9 +1943,9 @@ dependencies = [ [[package]] name = "reqwest" -version = "0.11.4" +version = "0.11.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "246e9f61b9bb77df069a947682be06e31ac43ea37862e244a69f177694ea6d22" +checksum = "51c732d463dd300362ffb44b7b125f299c23d2990411a4253824630ebc7467fb" dependencies = [ "base64 0.13.0", "bytes", @@ -1965,6 +1965,7 @@ dependencies = [ "percent-encoding", "pin-project-lite", "serde", + "serde_json", "serde_urlencoded", "tokio", "tokio-native-tls", @@ -1977,15 +1978,15 @@ dependencies = [ [[package]] name = "retain_mut" -version = "0.1.3" +version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e9c17925a9027d298a4603d286befe3f9dc0e8ed02523141914eb628798d6e5b" +checksum = "448296241d034b96c11173591deaa1302f2c17b56092106c1f92c1bc0183a8c9" [[package]] name = "rustc-demangle" -version = "0.1.20" +version = "0.1.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dead70b0b5e03e9c814bcb6b01e03e68f7c57a80aa48c72ec92152ab3e818d49" +checksum = "7ef03e0a2b150c7a90d01faf6254c9c48a41e95fb2a8c2ac1c6f0d2b9aefc342" [[package]] name = "rustc-hash" @@ -2056,9 +2057,9 @@ checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" [[package]] name = "security-framework" -version = "2.3.1" +version = "2.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23a2ac85147a3a11d77ecf1bc7166ec0b92febfa4461c37944e180f319ece467" +checksum = "525bc1abfda2e1998d152c45cf13e696f76d0a4972310b22fac1658b05df7c87" dependencies = [ "bitflags", "core-foundation", @@ -2069,9 +2070,9 @@ dependencies = [ [[package]] name = "security-framework-sys" -version = "2.3.0" +version = "2.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e4effb91b4b8b6fb7732e670b6cee160278ff8e6bf485c7805d9e319d76e284" +checksum = "a9dd14d83160b528b7bfd66439110573efcfbe281b17fc2ca9f39f550d619c7e" dependencies = [ "core-foundation-sys", "libc", @@ -2121,9 +2122,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.66" +version = "1.0.68" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "336b10da19a12ad094b59d870ebde26a45402e5b470add4b5fd03c5048a32127" +checksum = "0f690853975602e1bfe1ccbf50504d67174e3bcf340f23b5ea9992e0587a52d8" dependencies = [ "itoa", "ryu", @@ -2154,9 +2155,9 @@ dependencies = [ [[package]] name = "sha-1" -version = "0.9.7" +version = "0.9.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a0c8611594e2ab4ebbf06ec7cbbf0a99450b8570e96cbf5188b5d5f6ef18d81" +checksum = "99cd6713db3cf16b6c84e06321e049a9b9f699826e16096d23bbcc44d15d51a6" dependencies = [ "block-buffer", "cfg-if 1.0.0", @@ -2176,9 +2177,9 @@ dependencies = [ [[package]] name = "siphasher" -version = "0.3.6" +version = "0.3.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "729a25c17d72b06c68cb47955d44fda88ad2d3e7d77e025663fdd69b93dd71a1" +checksum = "533494a8f9b724d33625ab53c6c4800f7cc445895924a8ef649222dcb76e938b" [[package]] name = "slab" @@ -2197,15 +2198,15 @@ dependencies = [ [[package]] name = "smallvec" -version = "1.6.1" +version = "1.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fe0f37c9e8f3c5a4a66ad655a93c74daac4ad00c441533bf5c6e7990bb42604e" +checksum = "1ecab6c735a6bb4139c0caafd0cc3635748bbb3acf4550e8138122099251f309" [[package]] name = "socket2" -version = "0.4.1" +version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "765f090f0e423d2b55843402a07915add955e7d60657db13707a159727326cad" +checksum = "5dc90fe6c7be1a323296982db1836d1ea9e47b6839496dde9a541bc496df3516" dependencies = [ "libc", "winapi", @@ -2306,7 +2307,7 @@ checksum = "6446ced80d6c486436db5c078dde11a9f73d42b57fb273121e160b84f63d894c" [[package]] name = "swc" -version = "0.67.0" +version = "0.67.1" dependencies = [ "ahash", "anyhow", @@ -2579,7 +2580,7 @@ dependencies = [ [[package]] name = "swc_ecma_codegen" -version = "0.74.3" +version = "0.74.4" dependencies = [ "bitflags", "memchr", @@ -2655,7 +2656,7 @@ dependencies = [ [[package]] name = "swc_ecma_minifier" -version = "0.37.1" +version = "0.37.2" dependencies = [ "ansi_term 0.12.1", "anyhow", @@ -2697,7 +2698,7 @@ dependencies = [ "pretty_assertions 0.6.1", "serde", "serde_json", - "smallvec 1.6.1", + "smallvec 1.7.0", "swc_atoms 0.2.7", "swc_common", "swc_ecma_ast", @@ -2769,7 +2770,7 @@ dependencies = [ "once_cell", "phf", "scoped-tls", - "smallvec 1.6.1", + "smallvec 1.7.0", "swc_atoms 0.2.7", "swc_common", "swc_ecma_ast", @@ -2803,7 +2804,7 @@ dependencies = [ "num-bigint", "ordered-float", "serde", - "smallvec 1.6.1", + "smallvec 1.7.0", "swc_atoms 0.2.7", "swc_common", "swc_ecma_ast", @@ -2886,7 +2887,7 @@ dependencies = [ "either", "serde", "serde_json", - "smallvec 1.6.1", + "smallvec 1.7.0", "swc_atoms 0.2.7", "swc_common", "swc_ecma_ast", @@ -3245,9 +3246,9 @@ dependencies = [ [[package]] name = "tinyvec" -version = "1.3.1" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "848a1e1181b9f6753b5e96a092749e29b11d19ede67dfbbd6c7dc7e0f49b5338" +checksum = "f83b2a3d4d9091d0abd7eba4dc2710b1718583bd4d8992e2190720ea38f391f7" dependencies = [ "tinyvec_macros", ] @@ -3286,9 +3287,9 @@ dependencies = [ [[package]] name = "tokio-util" -version = "0.6.7" +version = "0.6.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1caa0b0c8d94a049db56b5acf8cba99dc0623aab1b26d5b5f5e2d945846b3592" +checksum = "08d3725d3efa29485e87311c5b699de63cde14b00ed4d256b8318aa30ca452cd" dependencies = [ "bytes", "futures-core", @@ -3315,9 +3316,9 @@ checksum = "360dfd1d6d30e05fda32ace2c8c70e9c0a9da713275777f5a4dbb8a1893930c6" [[package]] name = "tracing" -version = "0.1.28" +version = "0.1.29" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "84f96e095c0c82419687c20ddf5cb3eadb61f4e1405923c9dc8e53a1adacbda8" +checksum = "375a639232caf30edfc78e8d89b2d4c375515393e7af7e16f01cd96917fb2105" dependencies = [ "cfg-if 1.0.0", "pin-project-lite", @@ -3327,9 +3328,9 @@ dependencies = [ [[package]] name = "tracing-attributes" -version = "0.1.16" +version = "0.1.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "98863d0dd09fa59a1b79c6750ad80dbda6b75f4e71c437a6a1a8cb91a8bcbd77" +checksum = "f4f480b8f81512e825f337ad51e94c1eb5d3bbdf2b363dcd01e2b19a9ffe3f8e" dependencies = [ "proc-macro2", "quote", @@ -3338,9 +3339,9 @@ dependencies = [ [[package]] name = "tracing-core" -version = "0.1.20" +version = "0.1.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "46125608c26121c81b0c6d693eab5a420e416da7e43c426d2e8f7df8da8a3acf" +checksum = "1f4ed65637b8390770814083d20756f87bfa2c21bf2f110babdc5438351746e4" dependencies = [ "lazy_static", ] @@ -3368,9 +3369,9 @@ dependencies = [ [[package]] name = "tracing-subscriber" -version = "0.2.24" +version = "0.2.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fdd0568dbfe3baf7048b7908d2b32bca0d81cd56bec6d2a8f894b01d74f86be3" +checksum = "0e0d2eaa99c3c2e41547cfa109e910a68ea03823cccad4a0525dcbc9b01e8c71" dependencies = [ "ansi_term 0.12.1", "chrono", @@ -3380,7 +3381,7 @@ dependencies = [ "serde", "serde_json", "sharded-slab", - "smallvec 1.6.1", + "smallvec 1.7.0", "thread_local", "tracing", "tracing-core", @@ -3417,15 +3418,15 @@ checksum = "0685c84d5d54d1c26f7d3eb96cd41550adb97baed141a761cf335d3d33bcd0ae" [[package]] name = "typenum" -version = "1.13.0" +version = "1.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "879f6906492a7cd215bfa4cf595b600146ccfac0c79bcbd1f3000162af5e8b06" +checksum = "b63708a265f51345575b27fe43f9500ad611579e764c79edbc2037b1121959ec" [[package]] name = "unicode-bidi" -version = "0.3.6" +version = "0.3.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "246f4c42e67e7a4e3c6106ff716a5d067d4132a642840b242e357e468a2a0085" +checksum = "1a01404663e3db436ed2746d9fefef640d868edae3cceb81c3b8d5732fda678f" [[package]] name = "unicode-normalization" @@ -3438,9 +3439,9 @@ dependencies = [ [[package]] name = "unicode-width" -version = "0.1.8" +version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9337591893a19b88d8d87f2cec1e73fad5cdfd10e5a6f349f498ad6ea2ffb1e3" +checksum = "3ed742d4ea2bd1176e236172c8429aaf54486e7ac098db29ffe6529e0ce50973" [[package]] name = "unicode-xid" diff --git a/Cargo.toml b/Cargo.toml index 4a851f5828ef..9ecce3438273 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,7 +20,7 @@ edition = "2018" license = "Apache-2.0/MIT" name = "swc" repository = "https://github.com/swc-project/swc.git" -version = "0.67.0" +version = "0.67.1" [lib] name = "swc" diff --git a/ecmascript/codegen/Cargo.toml b/ecmascript/codegen/Cargo.toml index e137ecf90191..8b7a7d97d693 100644 --- a/ecmascript/codegen/Cargo.toml +++ b/ecmascript/codegen/Cargo.toml @@ -7,7 +7,7 @@ include = ["Cargo.toml", "src/**/*.rs"] license = "Apache-2.0/MIT" name = "swc_ecma_codegen" repository = "https://github.com/swc-project/swc.git" -version = "0.74.3" +version = "0.74.4" [dependencies] bitflags = "1" diff --git a/ecmascript/codegen/src/lib.rs b/ecmascript/codegen/src/lib.rs index 3a0a18db7bc3..cc0250e5a78e 100644 --- a/ecmascript/codegen/src/lib.rs +++ b/ecmascript/codegen/src/lib.rs @@ -138,38 +138,60 @@ where } #[emitter] - fn emit_export_decl(&mut self, node: &ExportDecl) -> Result { - keyword!("export"); + fn emit_export_decl(&mut self, n: &ExportDecl) -> Result { + { + let span = if n.span.is_dummy() { + DUMMY_SP + } else { + Span::new(n.span.lo, n.span.lo + BytePos(6), Default::default()) + }; + keyword!(span, "export"); + } space!(); - emit!(node.decl); + emit!(n.decl); } #[emitter] - fn emit_export_default_expr(&mut self, node: &ExportDefaultExpr) -> Result { - keyword!("export"); + fn emit_export_default_expr(&mut self, n: &ExportDefaultExpr) -> Result { + { + let span = if n.span.is_dummy() { + DUMMY_SP + } else { + Span::new(n.span.lo, n.span.lo + BytePos(6), Default::default()) + }; + keyword!(span, "export"); + } + space!(); keyword!("default"); { - let starts_with_alpha_num = node.expr.starts_with_alpha_num(); + let starts_with_alpha_num = n.expr.starts_with_alpha_num(); if starts_with_alpha_num { space!(); } else { formatting_space!(); } - emit!(node.expr); + emit!(n.expr); } formatting_semi!(); } #[emitter] - fn emit_export_default_decl(&mut self, node: &ExportDefaultDecl) -> Result { - self.emit_leading_comments_of_span(node.span(), false)?; + fn emit_export_default_decl(&mut self, n: &ExportDefaultDecl) -> Result { + self.emit_leading_comments_of_span(n.span(), false)?; - keyword!("export"); + { + let span = if n.span.is_dummy() { + DUMMY_SP + } else { + Span::new(n.span.lo, n.span.lo + BytePos(6), Default::default()) + }; + keyword!(span, "export"); + } space!(); keyword!("default"); space!(); - match node.decl { + match n.decl { DefaultDecl::Class(ref n) => emit!(n), DefaultDecl::Fn(ref n) => emit!(n), DefaultDecl::TsInterfaceDecl(ref n) => emit!(n), @@ -347,7 +369,15 @@ where }, ); - keyword!("export"); + { + let span = if node.span.is_dummy() { + DUMMY_SP + } else { + Span::new(node.span.lo, node.span.lo + BytePos(6), Default::default()) + }; + keyword!(span, "export"); + } + formatting_space!(); if let Some(spec) = namespace_spec { emit!(spec); @@ -856,12 +886,7 @@ where }), ) => false, - (_, Expr::Update(UpdateExpr { prefix: true, .. }) | Expr::Unary(..)) => true, - - (_, Expr::Bin(BinExpr { left, .. })) => match &**left { - Expr::Update(UpdateExpr { prefix: true, .. }) | Expr::Unary(..) => true, - _ => false, - }, + (_, r) if is_space_require_before_rhs(r) => true, _ => false, } @@ -2799,7 +2824,7 @@ fn should_emit_whitespace_before_operand(node: &UnaryExpr) -> bool { _ => {} } - match *node.arg { + match &*node.arg { Expr::Update(UpdateExpr { op: op!("++"), prefix: true, @@ -2818,6 +2843,9 @@ fn should_emit_whitespace_before_operand(node: &UnaryExpr) -> bool { op: op!(unary, "-"), .. }) if node.op == op!(unary, "-") => true, + + Expr::Lit(Lit::Num(v)) if v.value.is_sign_negative() && node.op == op!(unary, "-") => true, + _ => false, } } @@ -3201,3 +3229,15 @@ fn handle_invalid_unicodes(s: &str) -> Cow { Cow::Owned(s.replace("\\\0", "\\")) } + +fn is_space_require_before_rhs(rhs: &Expr) -> bool { + match rhs { + Expr::Lit(Lit::Num(v)) if v.value.is_sign_negative() => true, + + Expr::Update(UpdateExpr { prefix: true, .. }) | Expr::Unary(..) => true, + + Expr::Bin(BinExpr { left, .. }) => is_space_require_before_rhs(&left), + + _ => false, + } +} diff --git a/ecmascript/codegen/tests/fixture/vercel/d3-color/1/input.js b/ecmascript/codegen/tests/fixture/vercel/d3-color/1/input.js new file mode 100644 index 000000000000..a8192b7e8a8d --- /dev/null +++ b/ecmascript/codegen/tests/fixture/vercel/d3-color/1/input.js @@ -0,0 +1,28 @@ +import define, { extend } from "./define.js"; +import { Color, rgbConvert, Rgb, darker, brighter } from "./color.js"; +import { deg2rad, rad2deg } from "./math.js"; +var A = -0.14861, B = 1.78277, C = -0.29227, D = -0.90649, E = 1.97294, ED = E * D, EB = E * B, BC_DA = B * C - D * A; +function cubehelixConvert(o) { + if (o instanceof Cubehelix) return new Cubehelix(o.h, o.s, o.l, o.opacity); + o instanceof Rgb || (o = rgbConvert(o)); + var r = o.r / 255, g = o.g / 255, b = o.b / 255, l = (BC_DA * b + ED * r - EB * g) / (BC_DA + ED - EB), bl = b - l, k = (E * (g - l) - C * bl) / D, s = Math.sqrt(k * k + bl * bl) / (E * l * (1 - l)), h = s ? Math.atan2(k, bl) * rad2deg - 120 : NaN; + return new Cubehelix(h < 0 ? h + 360 : h, s, l, o.opacity); +} +export default function cubehelix(h, s, l, opacity) { + return 1 === arguments.length ? cubehelixConvert(h) : new Cubehelix(h, s, l, null == opacity ? 1 : opacity); +}; +export function Cubehelix(h, s, l, opacity) { + this.h = +h, this.s = +s, this.l = +l, this.opacity = +opacity; +} +define(Cubehelix, cubehelix, extend(Color, { + brighter: function (k) { + return k = null == k ? brighter : Math.pow(brighter, k), new Cubehelix(this.h, this.s, this.l * k, this.opacity); + }, + darker: function (k) { + return k = null == k ? darker : Math.pow(darker, k), new Cubehelix(this.h, this.s, this.l * k, this.opacity); + }, + rgb: function () { + var h = isNaN(this.h) ? 0 : (this.h + 120) * deg2rad, l = +this.l, a = isNaN(this.s) ? 0 : this.s * l * (1 - l), cosh = Math.cos(h), sinh = Math.sin(h); + return new Rgb(255 * (l + a * (A * cosh + B * sinh)), 255 * (l + a * (C * cosh + D * sinh)), 255 * (l + a * (E * cosh)), this.opacity); + } +})); diff --git a/ecmascript/codegen/tests/fixture/vercel/d3-color/1/output.js b/ecmascript/codegen/tests/fixture/vercel/d3-color/1/output.js new file mode 100644 index 000000000000..e736a0734ce6 --- /dev/null +++ b/ecmascript/codegen/tests/fixture/vercel/d3-color/1/output.js @@ -0,0 +1,29 @@ +import define, { extend } from "./define.js"; +import { Color, rgbConvert, Rgb, darker, brighter } from "./color.js"; +import { deg2rad, rad2deg } from "./math.js"; +var A = -0.14861, B = 1.78277, C = -0.29227, D = -0.90649, E = 1.97294, ED = E * D, EB = E * B, BC_DA = B * C - D * A; +function cubehelixConvert(o) { + if (o instanceof Cubehelix) return new Cubehelix(o.h, o.s, o.l, o.opacity); + o instanceof Rgb || (o = rgbConvert(o)); + var r = o.r / 255, g = o.g / 255, b = o.b / 255, l = (BC_DA * b + ED * r - EB * g) / (BC_DA + ED - EB), bl = b - l, k = (E * (g - l) - C * bl) / D, s = Math.sqrt(k * k + bl * bl) / (E * l * (1 - l)), h = s ? Math.atan2(k, bl) * rad2deg - 120 : NaN; + return new Cubehelix(h < 0 ? h + 360 : h, s, l, o.opacity); +} +export default function cubehelix(h, s, l, opacity) { + return 1 === arguments.length ? cubehelixConvert(h) : new Cubehelix(h, s, l, null == opacity ? 1 : opacity); +}; +; +export function Cubehelix(h, s, l, opacity) { + this.h = +h, this.s = +s, this.l = +l, this.opacity = +opacity; +} +define(Cubehelix, cubehelix, extend(Color, { + brighter: function(k) { + return k = null == k ? brighter : Math.pow(brighter, k), new Cubehelix(this.h, this.s, this.l * k, this.opacity); + }, + darker: function(k) { + return k = null == k ? darker : Math.pow(darker, k), new Cubehelix(this.h, this.s, this.l * k, this.opacity); + }, + rgb: function() { + var h = isNaN(this.h) ? 0 : (this.h + 120) * deg2rad, l = +this.l, a = isNaN(this.s) ? 0 : this.s * l * (1 - l), cosh = Math.cos(h), sinh = Math.sin(h); + return new Rgb(255 * (l + a * (A * cosh + B * sinh)), 255 * (l + a * (C * cosh + D * sinh)), 255 * (l + a * (E * cosh)), this.opacity); + } +})); diff --git a/ecmascript/codegen/tests/fixture/vercel/d3-color/1/output.min.js b/ecmascript/codegen/tests/fixture/vercel/d3-color/1/output.min.js new file mode 100644 index 000000000000..d168dddfbc6e --- /dev/null +++ b/ecmascript/codegen/tests/fixture/vercel/d3-color/1/output.min.js @@ -0,0 +1 @@ +import define,{extend}from"./define.js";import{Color,rgbConvert,Rgb,darker,brighter}from"./color.js";import{deg2rad,rad2deg}from"./math.js";var A=-0.14861,B=1.78277,C=-0.29227,D=-0.90649,E=1.97294,ED=E*D,EB=E*B,BC_DA=B*C-D*A;function cubehelixConvert(o){if(o instanceof Cubehelix)return new Cubehelix(o.h,o.s,o.l,o.opacity);o instanceof Rgb||(o=rgbConvert(o));var r=o.r/255,g=o.g/255,b=o.b/255,l=(BC_DA*b+ED*r-EB*g)/(BC_DA+ED-EB),bl=b-l,k=(E*(g-l)-C*bl)/D,s=Math.sqrt(k*k+bl*bl)/(E*l*(1-l)),h=s?Math.atan2(k,bl)*rad2deg-120:NaN;return new Cubehelix(h<0?h+360:h,s,l,o.opacity)}export default function cubehelix(h,s,l,opacity){return 1===arguments.length?cubehelixConvert(h):new Cubehelix(h,s,l,null==opacity?1:opacity)};export function Cubehelix(h,s,l,opacity){this.h=+h,this.s=+s,this.l=+l,this.opacity=+opacity}define(Cubehelix,cubehelix,extend(Color,{brighter:function(k){return k=null==k?brighter:Math.pow(brighter,k),new Cubehelix(this.h,this.s,this.l*k,this.opacity)},darker:function(k){return k=null==k?darker:Math.pow(darker,k),new Cubehelix(this.h,this.s,this.l*k,this.opacity)},rgb:function(){var h=isNaN(this.h)?0:(this.h+120)*deg2rad,l=+this.l,a=isNaN(this.s)?0:this.s*l*(1-l),cosh=Math.cos(h),sinh=Math.sin(h);return new Rgb(255*(l+a*(A*cosh+B*sinh)),255*(l+a*(C*cosh+D*sinh)),255*(l+a*(E*cosh)),this.opacity)}})) diff --git a/ecmascript/minifier/Cargo.toml b/ecmascript/minifier/Cargo.toml index 6d23e2e9335d..36e6946cd1de 100644 --- a/ecmascript/minifier/Cargo.toml +++ b/ecmascript/minifier/Cargo.toml @@ -7,7 +7,7 @@ include = ["Cargo.toml", "src/**/*.rs", "src/lists/*.json"] license = "Apache-2.0/MIT" name = "swc_ecma_minifier" repository = "https://github.com/swc-project/swc.git" -version = "0.37.1" +version = "0.37.2" [features] debug = ["backtrace"] diff --git a/ecmascript/minifier/src/analyzer/mod.rs b/ecmascript/minifier/src/analyzer/mod.rs index 9475e4bd8dd8..c5be4851e51b 100644 --- a/ecmascript/minifier/src/analyzer/mod.rs +++ b/ecmascript/minifier/src/analyzer/mod.rs @@ -7,7 +7,7 @@ use crate::{ util::{can_end_conditionally, idents_used_by, now}, }; use std::time::Instant; -use swc_atoms::JsWord; +use swc_atoms::{js_word, JsWord}; use swc_common::{ collections::{AHashMap, AHashSet}, SyntaxContext, DUMMY_SP, @@ -733,18 +733,40 @@ where } fn visit_var_declarator(&mut self, e: &VarDeclarator, _: &dyn Node) { - let ctx = Ctx { - in_pat_of_var_decl: true, - in_pat_of_var_decl_with_init: e.init.is_some(), - in_var_decl_with_no_side_effect_for_member_access: match e.init.as_deref() { - Some(Expr::Array(..) | Expr::Lit(..)) => true, - _ => false, - }, - ..self.ctx + let prevent_inline = match &e.name { + Pat::Ident(BindingIdent { + id: + Ident { + sym: js_word!("arguments"), + .. + }, + .. + }) => true, + _ => false, }; - e.name.visit_with(e, &mut *self.with_ctx(ctx)); + { + let ctx = Ctx { + inline_prevented: self.ctx.inline_prevented || prevent_inline, + in_pat_of_var_decl: true, + in_pat_of_var_decl_with_init: e.init.is_some(), + in_var_decl_with_no_side_effect_for_member_access: match e.init.as_deref() { + Some(Expr::Array(..) | Expr::Lit(..)) => true, + _ => false, + }, + ..self.ctx + }; + e.name.visit_with(e, &mut *self.with_ctx(ctx)); + } - e.init.visit_with(e, self); + { + let ctx = Ctx { + inline_prevented: self.ctx.inline_prevented || prevent_inline, + in_pat_of_var_decl: false, + ..self.ctx + }; + + e.init.visit_with(e, &mut *self.with_ctx(ctx)); + } } fn visit_while_stmt(&mut self, n: &WhileStmt, _: &dyn Node) { diff --git a/ecmascript/minifier/src/compress/optimize/iife.rs b/ecmascript/minifier/src/compress/optimize/iife.rs index f4a0161b852d..9cd16bd41cf2 100644 --- a/ecmascript/minifier/src/compress/optimize/iife.rs +++ b/ecmascript/minifier/src/compress/optimize/iife.rs @@ -263,12 +263,9 @@ where if cfg!(feature = "debug") { tracing::trace!("inline: inline_vars_in_node"); } - let ctx = Ctx { - inline_prevented: false, - ..self.ctx - }; + let orig_vars = replace(&mut self.state.vars_for_inlining, vars); - n.visit_mut_with(&mut *self.with_ctx(ctx)); + n.visit_mut_with(self); self.state.vars_for_inlining = orig_vars; } @@ -316,7 +313,7 @@ where ExprOrSuper::Expr(e) => &mut **e, }; - if self.ctx.inline_prevented { + if self.ctx.dont_invoke_iife { tracing::trace!("iife: [x] Inline is prevented"); return; } @@ -531,6 +528,14 @@ where .. })) => { if decls.iter().any(|decl| match decl.name { + Pat::Ident(BindingIdent { + id: + Ident { + sym: js_word!("arguments"), + .. + }, + .. + }) => true, Pat::Ident(..) => false, _ => true, }) { diff --git a/ecmascript/minifier/src/compress/optimize/inline.rs b/ecmascript/minifier/src/compress/optimize/inline.rs index c6e967379cf4..1ca16cfddcaf 100644 --- a/ecmascript/minifier/src/compress/optimize/inline.rs +++ b/ecmascript/minifier/src/compress/optimize/inline.rs @@ -535,10 +535,6 @@ where /// Actually inlines variables. pub(super) fn inline(&mut self, e: &mut Expr) { - if self.ctx.inline_prevented { - return; - } - match e { Expr::Ident(i) => { // @@ -577,6 +573,7 @@ where return; } + // Check witohut cloning if let Some(value) = self.state.vars_for_inlining.get(&i.to_id()) { if self.ctx.is_exact_lhs_of_assign && !is_valid_for_lhs(&value) { return; diff --git a/ecmascript/minifier/src/compress/optimize/mod.rs b/ecmascript/minifier/src/compress/optimize/mod.rs index b22d4a8a5459..c467a35046f0 100644 --- a/ecmascript/minifier/src/compress/optimize/mod.rs +++ b/ecmascript/minifier/src/compress/optimize/mod.rs @@ -113,8 +113,6 @@ struct Ctx { var_kind: Option, - /// `true` if we should not inline values. - inline_prevented: bool, /// `true` if we are in the strict mode. This will be set to `true` for /// statements **after** `'use strict'` in_strict: bool, @@ -165,6 +163,8 @@ struct Ctx { is_nested_if_return_merging: bool, + dont_invoke_iife: bool, + /// Current scope. scope: SyntaxContext, } @@ -1604,8 +1604,6 @@ where } fn visit_mut_call_expr(&mut self, e: &mut CallExpr) { - let inline_prevented = self.ctx.inline_prevented || self.has_noinline(e.span); - let is_this_undefined = match &e.callee { ExprOrSuper::Super(_) => false, ExprOrSuper::Expr(e) => e.is_ident(), @@ -1613,7 +1611,6 @@ where { let ctx = Ctx { is_callee: true, - inline_prevented, is_this_aware_callee: is_this_undefined || match &e.callee { ExprOrSuper::Super(_) => false, @@ -1649,7 +1646,6 @@ where { let ctx = Ctx { in_call_arg: true, - inline_prevented, is_this_aware_callee: false, ..self.ctx }; @@ -1665,7 +1661,7 @@ where { let ctx = Ctx { - inline_prevented: true, + dont_invoke_iife: true, ..self.ctx }; n.super_class.visit_mut_with(&mut *self.with_ctx(ctx)); @@ -2376,11 +2372,7 @@ where } fn visit_mut_switch_stmt(&mut self, n: &mut SwitchStmt) { - let ctx = Ctx { - inline_prevented: !self.options.switches, - ..self.ctx - }; - n.discriminant.visit_mut_with(&mut *self.with_ctx(ctx)); + n.discriminant.visit_mut_with(self); self.drop_unreachable_cases(n); @@ -2490,28 +2482,9 @@ where } fn visit_mut_var_declarator(&mut self, var: &mut VarDeclarator) { - { - let prevent_inline = match &var.name { - Pat::Ident(BindingIdent { - id: - Ident { - sym: js_word!("arguments"), - .. - }, - .. - }) => true, - _ => false, - }; - - let ctx = Ctx { - inline_prevented: self.ctx.inline_prevented || prevent_inline, - ..self.ctx - }; + var.name.visit_mut_with(self); - var.name.visit_mut_with(&mut *self.with_ctx(ctx)); - - var.init.visit_mut_with(&mut *self.with_ctx(ctx)); - } + var.init.visit_mut_with(self); self.remove_duplicate_names(var); diff --git a/ecmascript/minifier/src/pass/mangle_names/mod.rs b/ecmascript/minifier/src/pass/mangle_names/mod.rs index ce3e9d95217c..e137289352f7 100644 --- a/ecmascript/minifier/src/pass/mangle_names/mod.rs +++ b/ecmascript/minifier/src/pass/mangle_names/mod.rs @@ -117,6 +117,7 @@ impl VisitMut for Mangler { n.class.visit_mut_with(self); } + fn visit_mut_export_named_specifier(&mut self, n: &mut ExportNamedSpecifier) { if n.exported.is_none() { n.exported = Some(n.orig.clone()); @@ -212,6 +213,8 @@ impl VisitMut for Mangler { } ObjectPatProp::Assign(p) => { + p.value.visit_mut_with(self); + let key_span = p.key.span.with_ctxt(SyntaxContext::empty()); let orig = p.key.sym.clone(); diff --git a/ecmascript/minifier/tests/compress/fixture/issues/2257/full/output.js b/ecmascript/minifier/tests/compress/fixture/issues/2257/full/output.js index 5c8852841c90..abda596a4505 100644 --- a/ecmascript/minifier/tests/compress/fixture/issues/2257/full/output.js +++ b/ecmascript/minifier/tests/compress/fixture/issues/2257/full/output.js @@ -15789,7 +15789,14 @@ case 16: e = b.elementType; a: { - switch(null !== a && (a.alternate = null, b.alternate = null, b.flags |= 2), a = b.pendingProps, e = (f = e._init)(e._payload), b.type = e, f = b.tag = hk(e), a = lg(e, a), f){ + switch(null !== a && (a.alternate = null, b.alternate = null, b.flags |= 2), a = b.pendingProps, e = (f = e._init)(e._payload), b.type = e, f = b.tag = (function(a) { + if ("function" == typeof a) return ji(a) ? 1 : 0; + if (null != a) { + if ((a = a.$$typeof) === Aa) return 11; + if (a === Da) return 14; + } + return 2; + })(e), a = lg(e, a), f){ case 0: b = li(null, b, e, a, c); break a; @@ -17552,7 +17559,7 @@ } }, exports.unstable_pauseExecution = function() { }, exports.unstable_requestPaint = k, exports.unstable_runWithPriority = function(a, b) { - switch(a){ + switch(3){ case 1: case 2: case 3: @@ -17560,7 +17567,6 @@ case 5: break; default: - a = 3; } var c = P; P = 3; diff --git a/ecmascript/minifier/tests/compress/fixture/issues/d3-color/1/input.js b/ecmascript/minifier/tests/compress/fixture/issues/d3-color/1/input.js new file mode 100644 index 000000000000..412680fa5090 --- /dev/null +++ b/ecmascript/minifier/tests/compress/fixture/issues/d3-color/1/input.js @@ -0,0 +1,61 @@ +import define, { extend } from "./define.js"; +import { Color, rgbConvert, Rgb, darker, brighter } from "./color.js"; +import { deg2rad, rad2deg } from "./math.js"; + +var A = -0.14861, + B = +1.78277, + C = -0.29227, + D = -0.90649, + E = +1.97294, + ED = E * D, + EB = E * B, + BC_DA = B * C - D * A; + +function cubehelixConvert(o) { + if (o instanceof Cubehelix) return new Cubehelix(o.h, o.s, o.l, o.opacity); + if (!(o instanceof Rgb)) o = rgbConvert(o); + var r = o.r / 255, + g = o.g / 255, + b = o.b / 255, + l = (BC_DA * b + ED * r - EB * g) / (BC_DA + ED - EB), + bl = b - l, + k = (E * (g - l) - C * bl) / D, + s = Math.sqrt(k * k + bl * bl) / (E * l * (1 - l)), // NaN if l=0 or l=1 + h = s ? Math.atan2(k, bl) * rad2deg - 120 : NaN; + return new Cubehelix(h < 0 ? h + 360 : h, s, l, o.opacity); +} + +export default function cubehelix(h, s, l, opacity) { + return arguments.length === 1 ? cubehelixConvert(h) : new Cubehelix(h, s, l, opacity == null ? 1 : opacity); +} + +export function Cubehelix(h, s, l, opacity) { + this.h = +h; + this.s = +s; + this.l = +l; + this.opacity = +opacity; +} + +define(Cubehelix, cubehelix, extend(Color, { + brighter: function (k) { + k = k == null ? brighter : Math.pow(brighter, k); + return new Cubehelix(this.h, this.s, this.l * k, this.opacity); + }, + darker: function (k) { + k = k == null ? darker : Math.pow(darker, k); + return new Cubehelix(this.h, this.s, this.l * k, this.opacity); + }, + rgb: function () { + var h = isNaN(this.h) ? 0 : (this.h + 120) * deg2rad, + l = +this.l, + a = isNaN(this.s) ? 0 : this.s * l * (1 - l), + cosh = Math.cos(h), + sinh = Math.sin(h); + return new Rgb( + 255 * (l + a * (A * cosh + B * sinh)), + 255 * (l + a * (C * cosh + D * sinh)), + 255 * (l + a * (E * cosh)), + this.opacity + ); + } +})); \ No newline at end of file diff --git a/ecmascript/minifier/tests/compress/fixture/issues/d3-color/1/output.js b/ecmascript/minifier/tests/compress/fixture/issues/d3-color/1/output.js new file mode 100644 index 000000000000..a8c8f1ef1792 --- /dev/null +++ b/ecmascript/minifier/tests/compress/fixture/issues/d3-color/1/output.js @@ -0,0 +1,28 @@ +import define, { extend } from "./define.js"; +import { Color, rgbConvert, Rgb, darker, brighter } from "./color.js"; +import { deg2rad, rad2deg } from "./math.js"; +var A = -0.14861, B = 1.78277, C = -0.29227, D = -0.90649, E = 1.97294, ED = E * D, EB = E * B, BC_DA = B * C - D * A; +function cubehelixConvert(o) { + if (o instanceof Cubehelix) return new Cubehelix(o.h, o.s, o.l, o.opacity); + o instanceof Rgb || (o = rgbConvert(o)); + var r = o.r / 255, g = o.g / 255, b = o.b / 255, l = (BC_DA * b + ED * r - EB * g) / (BC_DA + ED - EB), bl = b - l, k = (E * (g - l) - C * bl) / D, s = Math.sqrt(k * k + bl * bl) / (E * l * (1 - l)), h = s ? Math.atan2(k, bl) * rad2deg - 120 : NaN; + return new Cubehelix(h < 0 ? h + 360 : h, s, l, o.opacity); +} +export default function cubehelix(h, s, l, opacity) { + return 1 === arguments.length ? cubehelixConvert(h) : new Cubehelix(h, s, l, null == opacity ? 1 : opacity); +}; +export function Cubehelix(h, s, l, opacity) { + this.h = +h, this.s = +s, this.l = +l, this.opacity = +opacity; +} +define(Cubehelix, cubehelix, extend(Color, { + brighter: function(k) { + return k = null == k ? brighter : Math.pow(brighter, k), new Cubehelix(this.h, this.s, this.l * k, this.opacity); + }, + darker: function(k) { + return k = null == k ? darker : Math.pow(darker, k), new Cubehelix(this.h, this.s, this.l * k, this.opacity); + }, + rgb: function() { + var h = isNaN(this.h) ? 0 : (this.h + 120) * deg2rad, l = +this.l, a = isNaN(this.s) ? 0 : this.s * l * (1 - l), cosh = Math.cos(h), sinh = Math.sin(h); + return new Rgb(255 * (l + a * (A * cosh + B * sinh)), 255 * (l + a * (C * cosh + D * sinh)), 255 * (l + a * (E * cosh)), this.opacity); + } +})); diff --git a/ecmascript/minifier/tests/compress/fixture/issues/stylis/1/input.js b/ecmascript/minifier/tests/compress/fixture/issues/stylis/1/input.js new file mode 100644 index 000000000000..5ebb8f1a2387 --- /dev/null +++ b/ecmascript/minifier/tests/compress/fixture/issues/stylis/1/input.js @@ -0,0 +1,127 @@ +import { MS, MOZ, WEBKIT } from './Enum.js' +import { strlen, indexof, replace } from './Utility.js' + +function hash(value, length) { + return (((((((length << 2) ^ charat(value, 0)) << 2) ^ charat(value, 1)) << 2) ^ charat(value, 2)) << 2) ^ charat(value, 3) +} + +function charat(value, index) { + return value.charCodeAt(index) | 0 +} + +/** + * @param {string} value + * @param {number} length + * @return {string} + */ +export function prefix(value, length) { + switch (hash(value, length)) { + // color-adjust + case 5103: + return WEBKIT + 'print-' + value + value + // animation, animation-(delay|direction|duration|fill-mode|iteration-count|name|play-state|timing-function) + case 5737: case 4201: case 3177: case 3433: case 1641: case 4457: case 2921: + // text-decoration, filter, clip-path, backface-visibility, column, box-decoration-break + case 5572: case 6356: case 5844: case 3191: case 6645: case 3005: + // mask, mask-image, mask-(mode|clip|size), mask-(repeat|origin), mask-position, mask-composite, + case 6391: case 5879: case 5623: case 6135: case 4599: case 4855: + // background-clip, columns, column-(count|fill|gap|rule|rule-color|rule-style|rule-width|span|width) + case 4215: case 6389: case 5109: case 5365: case 5621: case 3829: + return WEBKIT + value + value + // appearance, user-select, transform, hyphens, text-size-adjust + case 5349: case 4246: case 4810: case 6968: case 2756: + return WEBKIT + value + MOZ + value + MS + value + value + // flex, flex-direction + case 6828: case 4268: + return WEBKIT + value + MS + value + value + // order + case 6165: + return WEBKIT + value + MS + 'flex-' + value + value + // align-items + case 5187: + return WEBKIT + value + replace(value, /(\w+).+(:[^]+)/, WEBKIT + 'box-$1$2' + MS + 'flex-$1$2') + value + // align-self + case 5443: + return WEBKIT + value + MS + 'flex-item-' + replace(value, /flex-|-self/, '') + value + // align-content + case 4675: + return WEBKIT + value + MS + 'flex-line-pack' + replace(value, /align-content|flex-|-self/, '') + value + // flex-shrink + case 5548: + return WEBKIT + value + MS + replace(value, 'shrink', 'negative') + value + // flex-basis + case 5292: + return WEBKIT + value + MS + replace(value, 'basis', 'preferred-size') + value + // flex-grow + case 6060: + return WEBKIT + 'box-' + replace(value, '-grow', '') + WEBKIT + value + MS + replace(value, 'grow', 'positive') + value + // transition + case 4554: + return WEBKIT + replace(value, /([^-])(transform)/g, '$1' + WEBKIT + '$2') + value + // cursor + case 6187: + return replace(replace(replace(value, /(zoom-|grab)/, WEBKIT + '$1'), /(image-set)/, WEBKIT + '$1'), value, '') + value + // background, background-image + case 5495: case 3959: + return replace(value, /(image-set\([^]*)/, WEBKIT + '$1' + '$`$1') + // justify-content + case 4968: + return replace(replace(value, /(.+:)(flex-)?(.*)/, WEBKIT + 'box-pack:$3' + MS + 'flex-pack:$3'), /s.+-b[^;]+/, 'justify') + WEBKIT + value + value + // (margin|padding)-inline-(start|end) + case 4095: case 3583: case 4068: case 2532: + return replace(value, /(.+)-inline(.+)/, WEBKIT + '$1$2') + value + // (min|max)?(width|height|inline-size|block-size) + case 8116: case 7059: case 5753: case 5535: + case 5445: case 5701: case 4933: case 4677: + case 5533: case 5789: case 5021: case 4765: + // stretch, max-content, min-content, fill-available + if (strlen(value) - 1 - length > 6) + switch (charat(value, length + 1)) { + // (m)ax-content, (m)in-content + case 109: + // - + if (charat(value, length + 4) !== 45) + break + // (f)ill-available, (f)it-content + case 102: + return replace(value, /(.+:)(.+)-([^]+)/, '$1' + WEBKIT + '$2-$3' + '$1' + MOZ + (charat(value, length + 3) == 108 ? '$3' : '$2-$3')) + value + // (s)tretch + case 115: + return ~indexof(value, 'stretch') ? prefix(replace(value, 'stretch', 'fill-available'), length) + value : value + } + break + // position: sticky + case 4949: + // (s)ticky? + if (charat(value, length + 1) !== 115) + break + // display: (flex|inline-flex) + case 6444: + switch (charat(value, strlen(value) - 3 - (~indexof(value, '!important') && 10))) { + // stic(k)y + case 107: + return replace(value, ':', ':' + WEBKIT) + value + // (inline-)?fl(e)x + case 101: + return replace(value, /(.+:)([^;!]+)(;|!.+)?/, '$1' + WEBKIT + (charat(value, 14) === 45 ? 'inline-' : '') + 'box$3' + '$1' + WEBKIT + '$2$3' + '$1' + MS + '$2box$3') + value + } + break + // writing-mode + case 5936: + switch (charat(value, length + 11)) { + // vertical-l(r) + case 114: + return WEBKIT + value + MS + replace(value, /[svh]\w+-[tblr]{2}/, 'tb') + value + // vertical-r(l) + case 108: + return WEBKIT + value + MS + replace(value, /[svh]\w+-[tblr]{2}/, 'tb-rl') + value + // horizontal(-)tb + case 45: + return WEBKIT + value + MS + replace(value, /[svh]\w+-[tblr]{2}/, 'lr') + value + } + + return WEBKIT + value + MS + value + value + } + + return value +} \ No newline at end of file diff --git a/ecmascript/minifier/tests/compress/fixture/issues/stylis/1/output.js b/ecmascript/minifier/tests/compress/fixture/issues/stylis/1/output.js new file mode 100644 index 000000000000..b1e37824701e --- /dev/null +++ b/ecmascript/minifier/tests/compress/fixture/issues/stylis/1/output.js @@ -0,0 +1,119 @@ +import { MS, MOZ, WEBKIT } from "./Enum.js"; +import { strlen, indexof, replace } from "./Utility.js"; +function hash(value, length) { + return (((length << 2 ^ charat(value, 0)) << 2 ^ charat(value, 1)) << 2 ^ charat(value, 2)) << 2 ^ charat(value, 3); +} +function charat(value, index) { + return 0 | value.charCodeAt(index); +} +export function prefix(value, length) { + switch(hash(value, length)){ + case 5103: + return WEBKIT + "print-" + value + value; + case 5737: + case 4201: + case 3177: + case 3433: + case 1641: + case 4457: + case 2921: + case 5572: + case 6356: + case 5844: + case 3191: + case 6645: + case 3005: + case 6391: + case 5879: + case 5623: + case 6135: + case 4599: + case 4855: + case 4215: + case 6389: + case 5109: + case 5365: + case 5621: + case 3829: + return WEBKIT + value + value; + case 5349: + case 4246: + case 4810: + case 6968: + case 2756: + return WEBKIT + value + MOZ + value + MS + value + value; + case 6828: + case 4268: + return WEBKIT + value + MS + value + value; + case 6165: + return WEBKIT + value + MS + "flex-" + value + value; + case 5187: + return WEBKIT + value + replace(value, /(\w+).+(:[^]+)/, WEBKIT + "box-$1$2" + MS + "flex-$1$2") + value; + case 5443: + return WEBKIT + value + MS + "flex-item-" + replace(value, /flex-|-self/, "") + value; + case 4675: + return WEBKIT + value + MS + "flex-line-pack" + replace(value, /align-content|flex-|-self/, "") + value; + case 5548: + return WEBKIT + value + MS + replace(value, "shrink", "negative") + value; + case 5292: + return WEBKIT + value + MS + replace(value, "basis", "preferred-size") + value; + case 6060: + return WEBKIT + "box-" + replace(value, "-grow", "") + WEBKIT + value + MS + replace(value, "grow", "positive") + value; + case 4554: + return WEBKIT + replace(value, /([^-])(transform)/g, "$1" + WEBKIT + "$2") + value; + case 6187: + return replace(replace(replace(value, /(zoom-|grab)/, WEBKIT + "$1"), /(image-set)/, WEBKIT + "$1"), value, "") + value; + case 5495: + case 3959: + return replace(value, /(image-set\([^]*)/, WEBKIT + "$1$`$1"); + case 4968: + return replace(replace(value, /(.+:)(flex-)?(.*)/, WEBKIT + "box-pack:$3" + MS + "flex-pack:$3"), /s.+-b[^;]+/, "justify") + WEBKIT + value + value; + case 4095: + case 3583: + case 4068: + case 2532: + return replace(value, /(.+)-inline(.+)/, WEBKIT + "$1$2") + value; + case 8116: + case 7059: + case 5753: + case 5535: + case 5445: + case 5701: + case 4933: + case 4677: + case 5533: + case 5789: + case 5021: + case 4765: + if (strlen(value) - 1 - length > 6) switch(charat(value, length + 1)){ + case 109: + if (45 !== charat(value, length + 4)) break; + case 102: + return replace(value, /(.+:)(.+)-([^]+)/, "$1" + WEBKIT + "$2-$3$1" + MOZ + (108 == charat(value, length + 3) ? "$3" : "$2-$3")) + value; + case 115: + return ~indexof(value, "stretch") ? prefix(replace(value, "stretch", "fill-available"), length) + value : value; + } + break; + case 4949: + if (115 !== charat(value, length + 1)) break; + case 6444: + switch(charat(value, strlen(value) - 3 - (~indexof(value, "!important") && 10))){ + case 107: + return replace(value, ":", ":" + WEBKIT) + value; + case 101: + return replace(value, /(.+:)([^;!]+)(;|!.+)?/, "$1" + WEBKIT + (45 === charat(value, 14) ? "inline-" : "") + "box$3$1" + WEBKIT + "$2$3$1" + MS + "$2box$3") + value; + } + break; + case 5936: + switch(charat(value, length + 11)){ + case 114: + return WEBKIT + value + MS + replace(value, /[svh]\w+-[tblr]{2}/, "tb") + value; + case 108: + return WEBKIT + value + MS + replace(value, /[svh]\w+-[tblr]{2}/, "tb-rl") + value; + case 45: + return WEBKIT + value + MS + replace(value, /[svh]\w+-[tblr]{2}/, "lr") + value; + } + return WEBKIT + value + MS + value + value; + } + return value; +} diff --git a/ecmascript/minifier/tests/compress/fixture/issues/stylis/2/input.js b/ecmascript/minifier/tests/compress/fixture/issues/stylis/2/input.js new file mode 100644 index 000000000000..0e646c284433 --- /dev/null +++ b/ecmascript/minifier/tests/compress/fixture/issues/stylis/2/input.js @@ -0,0 +1,129 @@ +import { MS, MOZ, WEBKIT } from './Enum.js.js' +import { strlen, indexof, replace } from './Utility.js.js' + + +function charat(value, index) { + return value.charCodeAt(index) | 0 +} + +/** + * @param {string} value + * @param {number} length + * @return {string} + */ +export function prefix(value, length) { + + function hash(value, length) { + return (((((((length << 2) ^ charat(value, 0)) << 2) ^ charat(value, 1)) << 2) ^ charat(value, 2)) << 2) ^ charat(value, 3) + } + + switch (hash(value, length)) { + // color-adjust + case 5103: + return WEBKIT + 'print-' + value + value + // animation, animation-(delay|direction|duration|fill-mode|iteration-count|name|play-state|timing-function) + case 5737: case 4201: case 3177: case 3433: case 1641: case 4457: case 2921: + // text-decoration, filter, clip-path, backface-visibility, column, box-decoration-break + case 5572: case 6356: case 5844: case 3191: case 6645: case 3005: + // mask, mask-image, mask-(mode|clip|size), mask-(repeat|origin), mask-position, mask-composite, + case 6391: case 5879: case 5623: case 6135: case 4599: case 4855: + // background-clip, columns, column-(count|fill|gap|rule|rule-color|rule-style|rule-width|span|width) + case 4215: case 6389: case 5109: case 5365: case 5621: case 3829: + return WEBKIT + value + value + // appearance, user-select, transform, hyphens, text-size-adjust + case 5349: case 4246: case 4810: case 6968: case 2756: + return WEBKIT + value + MOZ + value + MS + value + value + // flex, flex-direction + case 6828: case 4268: + return WEBKIT + value + MS + value + value + // order + case 6165: + return WEBKIT + value + MS + 'flex-' + value + value + // align-items + case 5187: + return WEBKIT + value + replace(value, /(\w+).+(:[^]+)/, WEBKIT + 'box-$1$2' + MS + 'flex-$1$2') + value + // align-self + case 5443: + return WEBKIT + value + MS + 'flex-item-' + replace(value, /flex-|-self/, '') + value + // align-content + case 4675: + return WEBKIT + value + MS + 'flex-line-pack' + replace(value, /align-content|flex-|-self/, '') + value + // flex-shrink + case 5548: + return WEBKIT + value + MS + replace(value, 'shrink', 'negative') + value + // flex-basis + case 5292: + return WEBKIT + value + MS + replace(value, 'basis', 'preferred-size') + value + // flex-grow + case 6060: + return WEBKIT + 'box-' + replace(value, '-grow', '') + WEBKIT + value + MS + replace(value, 'grow', 'positive') + value + // transition + case 4554: + return WEBKIT + replace(value, /([^-])(transform)/g, '$1' + WEBKIT + '$2') + value + // cursor + case 6187: + return replace(replace(replace(value, /(zoom-|grab)/, WEBKIT + '$1'), /(image-set)/, WEBKIT + '$1'), value, '') + value + // background, background-image + case 5495: case 3959: + return replace(value, /(image-set\([^]*)/, WEBKIT + '$1' + '$`$1') + // justify-content + case 4968: + return replace(replace(value, /(.+:)(flex-)?(.*)/, WEBKIT + 'box-pack:$3' + MS + 'flex-pack:$3'), /s.+-b[^;]+/, 'justify') + WEBKIT + value + value + // (margin|padding)-inline-(start|end) + case 4095: case 3583: case 4068: case 2532: + return replace(value, /(.+)-inline(.+)/, WEBKIT + '$1$2') + value + // (min|max)?(width|height|inline-size|block-size) + case 8116: case 7059: case 5753: case 5535: + case 5445: case 5701: case 4933: case 4677: + case 5533: case 5789: case 5021: case 4765: + // stretch, max-content, min-content, fill-available + if (strlen(value) - 1 - length > 6) + switch (charat(value, length + 1)) { + // (m)ax-content, (m)in-content + case 109: + // - + if (charat(value, length + 4) !== 45) + break + // (f)ill-available, (f)it-content + case 102: + return replace(value, /(.+:)(.+)-([^]+)/, '$1' + WEBKIT + '$2-$3' + '$1' + MOZ + (charat(value, length + 3) == 108 ? '$3' : '$2-$3')) + value + // (s)tretch + case 115: + return ~indexof(value, 'stretch') ? prefix(replace(value, 'stretch', 'fill-available'), length) + value : value + } + break + // position: sticky + case 4949: + // (s)ticky? + if (charat(value, length + 1) !== 115) + break + // display: (flex|inline-flex) + case 6444: + switch (charat(value, strlen(value) - 3 - (~indexof(value, '!important') && 10))) { + // stic(k)y + case 107: + return replace(value, ':', ':' + WEBKIT) + value + // (inline-)?fl(e)x + case 101: + return replace(value, /(.+:)([^;!]+)(;|!.+)?/, '$1' + WEBKIT + (charat(value, 14) === 45 ? 'inline-' : '') + 'box$3' + '$1' + WEBKIT + '$2$3' + '$1' + MS + '$2box$3') + value + } + break + // writing-mode + case 5936: + switch (charat(value, length + 11)) { + // vertical-l(r) + case 114: + return WEBKIT + value + MS + replace(value, /[svh]\w+-[tblr]{2}/, 'tb') + value + // vertical-r(l) + case 108: + return WEBKIT + value + MS + replace(value, /[svh]\w+-[tblr]{2}/, 'tb-rl') + value + // horizontal(-)tb + case 45: + return WEBKIT + value + MS + replace(value, /[svh]\w+-[tblr]{2}/, 'lr') + value + } + + return WEBKIT + value + MS + value + value + } + + return value +} \ No newline at end of file diff --git a/ecmascript/minifier/tests/compress/fixture/issues/stylis/2/output.js b/ecmascript/minifier/tests/compress/fixture/issues/stylis/2/output.js new file mode 100644 index 000000000000..51f0cb9047e8 --- /dev/null +++ b/ecmascript/minifier/tests/compress/fixture/issues/stylis/2/output.js @@ -0,0 +1,117 @@ +import { MS, MOZ, WEBKIT } from "./Enum.js.js"; +import { strlen, indexof, replace } from "./Utility.js.js"; +function charat(value, index) { + return 0 | value.charCodeAt(index); +} +export function prefix(value, length) { + var value1; + switch((((length << 2 ^ charat(value1 = value, 0)) << 2 ^ charat(value1, 1)) << 2 ^ charat(value1, 2)) << 2 ^ charat(value1, 3)){ + case 5103: + return WEBKIT + "print-" + value + value; + case 5737: + case 4201: + case 3177: + case 3433: + case 1641: + case 4457: + case 2921: + case 5572: + case 6356: + case 5844: + case 3191: + case 6645: + case 3005: + case 6391: + case 5879: + case 5623: + case 6135: + case 4599: + case 4855: + case 4215: + case 6389: + case 5109: + case 5365: + case 5621: + case 3829: + return WEBKIT + value + value; + case 5349: + case 4246: + case 4810: + case 6968: + case 2756: + return WEBKIT + value + MOZ + value + MS + value + value; + case 6828: + case 4268: + return WEBKIT + value + MS + value + value; + case 6165: + return WEBKIT + value + MS + "flex-" + value + value; + case 5187: + return WEBKIT + value + replace(value, /(\w+).+(:[^]+)/, WEBKIT + "box-$1$2" + MS + "flex-$1$2") + value; + case 5443: + return WEBKIT + value + MS + "flex-item-" + replace(value, /flex-|-self/, "") + value; + case 4675: + return WEBKIT + value + MS + "flex-line-pack" + replace(value, /align-content|flex-|-self/, "") + value; + case 5548: + return WEBKIT + value + MS + replace(value, "shrink", "negative") + value; + case 5292: + return WEBKIT + value + MS + replace(value, "basis", "preferred-size") + value; + case 6060: + return WEBKIT + "box-" + replace(value, "-grow", "") + WEBKIT + value + MS + replace(value, "grow", "positive") + value; + case 4554: + return WEBKIT + replace(value, /([^-])(transform)/g, "$1" + WEBKIT + "$2") + value; + case 6187: + return replace(replace(replace(value, /(zoom-|grab)/, WEBKIT + "$1"), /(image-set)/, WEBKIT + "$1"), value, "") + value; + case 5495: + case 3959: + return replace(value, /(image-set\([^]*)/, WEBKIT + "$1$`$1"); + case 4968: + return replace(replace(value, /(.+:)(flex-)?(.*)/, WEBKIT + "box-pack:$3" + MS + "flex-pack:$3"), /s.+-b[^;]+/, "justify") + WEBKIT + value + value; + case 4095: + case 3583: + case 4068: + case 2532: + return replace(value, /(.+)-inline(.+)/, WEBKIT + "$1$2") + value; + case 8116: + case 7059: + case 5753: + case 5535: + case 5445: + case 5701: + case 4933: + case 4677: + case 5533: + case 5789: + case 5021: + case 4765: + if (strlen(value) - 1 - length > 6) switch(charat(value, length + 1)){ + case 109: + if (45 !== charat(value, length + 4)) break; + case 102: + return replace(value, /(.+:)(.+)-([^]+)/, "$1" + WEBKIT + "$2-$3$1" + MOZ + (108 == charat(value, length + 3) ? "$3" : "$2-$3")) + value; + case 115: + return ~indexof(value, "stretch") ? prefix(replace(value, "stretch", "fill-available"), length) + value : value; + } + break; + case 4949: + if (115 !== charat(value, length + 1)) break; + case 6444: + switch(charat(value, strlen(value) - 3 - (~indexof(value, "!important") && 10))){ + case 107: + return replace(value, ":", ":" + WEBKIT) + value; + case 101: + return replace(value, /(.+:)([^;!]+)(;|!.+)?/, "$1" + WEBKIT + (45 === charat(value, 14) ? "inline-" : "") + "box$3$1" + WEBKIT + "$2$3$1" + MS + "$2box$3") + value; + } + break; + case 5936: + switch(charat(value, length + 11)){ + case 114: + return WEBKIT + value + MS + replace(value, /[svh]\w+-[tblr]{2}/, "tb") + value; + case 108: + return WEBKIT + value + MS + replace(value, /[svh]\w+-[tblr]{2}/, "tb-rl") + value; + case 45: + return WEBKIT + value + MS + replace(value, /[svh]\w+-[tblr]{2}/, "lr") + value; + } + return WEBKIT + value + MS + value + value; + } + return value; +} diff --git a/ecmascript/minifier/tests/mangle.rs b/ecmascript/minifier/tests/mangle.rs index b674d2a14d73..082a58a8094a 100644 --- a/ecmascript/minifier/tests/mangle.rs +++ b/ecmascript/minifier/tests/mangle.rs @@ -25,7 +25,7 @@ use swc_ecma_transforms::{ resolver_with_mark, }; use swc_ecma_visit::FoldWith; -use testing::DebugUsingDisplay; +use testing::{DebugUsingDisplay, NormalizedOutput}; fn print(cm: Lrc, m: &Module, minify: bool) -> String { let mut buf = vec![]; @@ -190,6 +190,49 @@ fn compressed(compressed_file: PathBuf) { .unwrap(); } +#[testing::fixture("tests/mangle/**/input.js")] +fn fixture(input: PathBuf) { + testing::run_test2(false, |cm, _handler| { + let m = parse(cm.clone(), &input); + + let top_level_mark = Mark::fresh(Mark::root()); + + let m = optimize( + m, + cm.clone(), + None, + None, + &MinifyOptions { + mangle: Some(MangleOptions { + props: Some(ManglePropertiesOptions { + reserved: Default::default(), + undeclared: false, + regex: Default::default(), + }), + top_level: true, + keep_class_names: false, + keep_fn_names: false, + keep_private_props: false, + ie8: false, + safari10: false, + }), + compress: None, + ..Default::default() + }, + &ExtraOptions { top_level_mark }, + ); + + let mangled = print(cm.clone(), &m, false); + + NormalizedOutput::from(mangled) + .compare_to_file(input.parent().unwrap().join("output.js")) + .unwrap(); + + Ok(()) + }) + .unwrap(); +} + /// Tests used to prevent regressions. #[testing::fixture("tests/exec/**/input.js")] #[testing::fixture("tests/exec/**/output.js")] diff --git a/ecmascript/minifier/tests/mangle/1/input.js b/ecmascript/minifier/tests/mangle/1/input.js new file mode 100644 index 000000000000..56cda54924e7 --- /dev/null +++ b/ecmascript/minifier/tests/mangle/1/input.js @@ -0,0 +1,29 @@ +"use strict"; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +const longlong1 = __importDefault(require("./config.json")); +function setup({ config = longlong1.default } = {}) { + function longlong2(longlong3) { + const longlong4 = config[longlong3] || null; + if (!longlong4) { + return false; + } + const { available, availableBy } = longlong4; + if (!availableBy) { + return available; + } + return Date.now() >= availableBy && available; + } + function longlong10(longlong5) { + const longlong6 = config[longlong5] || null; + return longlong6; + } + return { + longlong10, + longlong2, + longlong100: config + }; +} +exports.default = setup; \ No newline at end of file diff --git a/ecmascript/minifier/tests/mangle/1/output.js b/ecmascript/minifier/tests/mangle/1/output.js new file mode 100644 index 000000000000..578abea2f89d --- /dev/null +++ b/ecmascript/minifier/tests/mangle/1/output.js @@ -0,0 +1,34 @@ +"use strict"; +var a = (this && this.__importDefault) || function(b) { + return (b && b.a) ? b : { + "default": b + }; +}; +Object.defineProperty(exports, "a", { + value: true +}); +const c = a(require("./config.json")); +function d({ config =c.default } = { +}) { + function e(f) { + const g = config[f] || null; + if (!g) { + return false; + } + const { available , availableBy } = g; + if (!availableBy) { + return available; + } + return Date.now() >= availableBy && available; + } + function h(i) { + const j = config[i] || null; + return j; + } + return { + b: h, + c: e, + d: config + }; +} +exports.default = d; diff --git a/ecmascript/minifier/tests/terser/compress/reduce_vars/redefine_arguments_2/output.js b/ecmascript/minifier/tests/terser/compress/reduce_vars/redefine_arguments_2/output.js index 3687215d1a99..4cc5c97c7350 100644 --- a/ecmascript/minifier/tests/terser/compress/reduce_vars/redefine_arguments_2/output.js +++ b/ecmascript/minifier/tests/terser/compress/reduce_vars/redefine_arguments_2/output.js @@ -1,14 +1,10 @@ -console.log( - (function () { - var arguments; - return typeof arguments; - })(), - (function () { - var arguments = 42; - return typeof arguments; - })(), - (function (x) { - var arguments = x; - return typeof arguments; - })() -); +console.log(function() { + var arguments; + return typeof arguments; +}(), function() { + var arguments = 42; + return typeof arguments; +}(), function(x) { + var arguments = void 0; + return typeof arguments; +}()); diff --git a/ecmascript/minifier/tests/terser/compress/reduce_vars/redefine_arguments_3/output.js b/ecmascript/minifier/tests/terser/compress/reduce_vars/redefine_arguments_3/output.js index 3687215d1a99..4cc5c97c7350 100644 --- a/ecmascript/minifier/tests/terser/compress/reduce_vars/redefine_arguments_3/output.js +++ b/ecmascript/minifier/tests/terser/compress/reduce_vars/redefine_arguments_3/output.js @@ -1,14 +1,10 @@ -console.log( - (function () { - var arguments; - return typeof arguments; - })(), - (function () { - var arguments = 42; - return typeof arguments; - })(), - (function (x) { - var arguments = x; - return typeof arguments; - })() -); +console.log(function() { + var arguments; + return typeof arguments; +}(), function() { + var arguments = 42; + return typeof arguments; +}(), function(x) { + var arguments = void 0; + return typeof arguments; +}()); diff --git a/node-swc/__tests__/minify_test.mjs b/node-swc/__tests__/minify_test.mjs index 0b65da405a92..4dcd88d7762e 100644 --- a/node-swc/__tests__/minify_test.mjs +++ b/node-swc/__tests__/minify_test.mjs @@ -85,24 +85,6 @@ describe('soruce map', () => { expect(JSON.parse(map).names).not.toEqual([]) }); - it("should not have `sourcesContent` if file name is speicified`", async () => { - const { map } = await swc.minify({ - 'foo.js': `(function(){ - const longName = Math.random() + '_' + Math.random(); - console.log(longName); - })()` - }, { - sourceMap: true, - compress: false, - mangle: { - topLevel: true - }, - }); - - const j = JSON.parse(map); - expect(j.sourcesContent).toBeUndefined() - }); - it("should have `sources` if file name is speicified", async () => { const { map } = await swc.minify({ 'foo.js': `(function(){ diff --git a/src/config/mod.rs b/src/config/mod.rs index 6e2aac7f7510..7319a5a618d4 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -551,9 +551,14 @@ pub struct JsMinifyOptions { #[serde(default)] pub output_path: Option, - #[serde(default)] + #[serde(default = "true_by_default")] pub inline_sources_content: bool, } + +fn true_by_default() -> bool { + true +} + /// `jsc.minify.sourceMap` #[derive(Debug, Clone, Default, Serialize, Deserialize)] #[serde(deny_unknown_fields, rename_all = "camelCase")] diff --git a/tests/fixture/issue-1581/case2/output/index.map b/tests/fixture/issue-1581/case2/output/index.map index cac65f27062e..3a42ac017bb5 100644 --- a/tests/fixture/issue-1581/case2/output/index.map +++ b/tests/fixture/issue-1581/case2/output/index.map @@ -1,5 +1,5 @@ { - "mappings": "OAAO,GAAK,CAAC,GAAG,GAAG,QACnB,GADyB,CAAC;IACtB,MAAM,CAAC,CAAC;AACZ,CAAC", + "mappings": "AAAA,MAAM,CAAC,GAAK,CAAC,GAAG,GAAG,QACnB,GADyB,CAAC;IACtB,MAAM,CAAC,CAAC;AACZ,CAAC", "names": [ "foo" ], diff --git a/tests/fixture/sourcemap/002/output/index.map b/tests/fixture/sourcemap/002/output/index.map index fc25987d2e3a..6818c92e23fe 100644 --- a/tests/fixture/sourcemap/002/output/index.map +++ b/tests/fixture/sourcemap/002/output/index.map @@ -1,5 +1,5 @@ { - "mappings": ";;eAAe,QAAQ,CAAC,UAAU,CAAC,KAAQ,EAAE,CAAC;QAAT,IAAI,GAAN,KAAQ,CAAN,IAAI;IACrC,MAAM,mCAAE,CAAG,YAAE,IAAI,CAAC,GAAG;AACzB,CAAC;SAEqB,eAAc;IAAd,eAAc,uDAA7B,QAAQ,WAAwB,CAAC;;;;iDAC7B,CAAC;wBACJ,KAAK,EAAE,CAAC;4BACJ,IAAI,EAAE,CAAC;gCACH,GAAG,EAAE,CAAK;4BACd,CAAC;wBACL,CAAC;oBACL,CAAC;;;;;;IACL,CAAC;WARqB,eAAc;;gBAAd,cAAc;WAAd,eAAc", + "mappings": ";;AAAA,MAAM,SAAS,QAAQ,CAAC,UAAU,CAAC,KAAQ,EAAE,CAAC;QAAT,IAAI,GAAN,KAAQ,CAAN,IAAI;IACrC,MAAM,mCAAE,CAAG,YAAE,IAAI,CAAC,GAAG;AACzB,CAAC;SAEqB,eAAc;IAAd,eAAc,uDAA7B,QAAQ,WAAwB,CAAC;;;;iDAC7B,CAAC;wBACJ,KAAK,EAAE,CAAC;4BACJ,IAAI,EAAE,CAAC;gCACH,GAAG,EAAE,CAAK;4BACd,CAAC;wBACL,CAAC;oBACL,CAAC;;;;;;IACL,CAAC;WARqB,eAAc;;AAApC,MAAM,UAAgB,cAAc;WAAd,eAAc", "names": [ "StaticPage", "data", diff --git a/tests/fixture/sourcemap/003/output/index.map b/tests/fixture/sourcemap/003/output/index.map index 7a2fcb5ca4b6..6bcbcd83804e 100644 --- a/tests/fixture/sourcemap/003/output/index.map +++ b/tests/fixture/sourcemap/003/output/index.map @@ -1,5 +1,5 @@ { - "mappings": "iFAAe,QAAQ,CAAC,UAAU,CAAC,CAAQ,CAAE,CAAC,IAAT,CAAI,CAAN,CAAQ,CAAN,IAAI,CACrC,MAAM,qBAAE,CAAG,UAAE,CAAI,CAAC,GAAG,CACzB,CAAC,UAEqB,eAAc,UAAd,eAAc,2BAA7B,QAAQ,UAAwB,CAAC,uFAC7B,CAAC,AACJ,KAAK,CAAE,CAAC,AACJ,IAAI,CAAE,CAAC,AACH,GAAG,CAAE,CAAK,IACd,CAAC,AACL,CAAC,AACL,CAAC,6CACL,CAAC,0CARqB,cAAc,UAAd,eAAc", + "mappings": "kEAAA,MAAM,SAAS,QAAQ,CAAC,UAAU,CAAC,CAAQ,CAAE,CAAC,IAAT,CAAI,CAAN,CAAQ,CAAN,IAAI,CACrC,MAAM,qBAAE,CAAG,UAAE,CAAI,CAAC,GAAG,CACzB,CAAC,UAEqB,eAAc,UAAd,eAAc,2BAA7B,QAAQ,UAAwB,CAAC,uFAC7B,CAAC,AACJ,KAAK,CAAE,CAAC,AACJ,IAAI,CAAE,CAAC,AACH,GAAG,CAAE,CAAK,IACd,CAAC,AACL,CAAC,AACL,CAAC,6CACL,CAAC,0BARD,MAAM,UAAgB,cAAc,UAAd,eAAc", "names": [ "StaticPage", "data", diff --git a/tests/source_map.rs b/tests/source_map.rs index e68c7e9de51a..cc2a301c59c0 100644 --- a/tests/source_map.rs +++ b/tests/source_map.rs @@ -113,7 +113,7 @@ fn issue_706() { inline("tests/srcmap/issue-706/index.js").unwrap(); } -#[cfg(target_os = "node-16-breaks-the-test")] +#[cfg(feature = "node14-test")] #[testing::fixture("stacktrace/**/input/")] fn stacktrace(input_dir: PathBuf) { let dir = input_dir.parent().unwrap(); @@ -123,7 +123,7 @@ fn stacktrace(input_dir: PathBuf) { Tester::new() .print_errors(|cm, handler| { - let c = Compiler::new(cm.clone(), Arc::new(handler)); + let c = Compiler::new(cm.clone()); for entry in WalkDir::new(&input_dir) { let entry = entry.unwrap(); @@ -142,6 +142,7 @@ fn stacktrace(input_dir: PathBuf) { match c.process_js_file( fm, + &handler, &Options { swcrc: true, is_module: true, diff --git a/tests/vercel/full-compact/.swcrc b/tests/vercel/full-compact/.swcrc new file mode 100644 index 000000000000..342492856ab8 --- /dev/null +++ b/tests/vercel/full-compact/.swcrc @@ -0,0 +1,29 @@ +{ + "jsc": { + "target": "es5", + "parser": { + "syntax": "typescript", + "tsx": true + }, + "transform": { + "react": { + "runtime": "automatic", + "pragma": "React.createElement", + "pragmaFrag": "React.Fragment", + "throwIfNamespace": true, + "useBuiltins": true + } + }, + "minify": { + "compress": { + "toplevel": true + }, + "mangle": { + "toplevel": true + }, + "toplevel": true + }, + "externalHelpers": true + }, + "minify": true +} \ No newline at end of file diff --git a/tests/vercel/full-compact/d3-color/1/input/index.js b/tests/vercel/full-compact/d3-color/1/input/index.js new file mode 100644 index 000000000000..41706efd3ddd --- /dev/null +++ b/tests/vercel/full-compact/d3-color/1/input/index.js @@ -0,0 +1,79 @@ +import { Color, rgbConvert, Rgb, } from "./color.js"; + + +var darker = 0.7; +var brighter = 1 / darker; + + +function define(constructor, factory, prototype) { + constructor.prototype = factory.prototype = prototype; + prototype.constructor = constructor; +} + +function extend(parent, definition) { + var prototype = Object.create(parent.prototype); + for (var key in definition) prototype[key] = definition[key]; + return prototype; +} + + +var deg2rad = Math.PI / 180; +var rad2deg = 180 / Math.PI; + +var A = -0.14861, + B = +1.78277, + C = -0.29227, + D = -0.90649, + E = +1.97294, + ED = E * D, + EB = E * B, + BC_DA = B * C - D * A; + +function cubehelixConvert(o) { + if (o instanceof Cubehelix) return new Cubehelix(o.h, o.s, o.l, o.opacity); + if (!(o instanceof Rgb)) o = rgbConvert(o); + var r = o.r / 255, + g = o.g / 255, + b = o.b / 255, + l = (BC_DA * b + ED * r - EB * g) / (BC_DA + ED - EB), + bl = b - l, + k = (E * (g - l) - C * bl) / D, + s = Math.sqrt(k * k + bl * bl) / (E * l * (1 - l)), // NaN if l=0 or l=1 + h = s ? Math.atan2(k, bl) * rad2deg - 120 : NaN; + return new Cubehelix(h < 0 ? h + 360 : h, s, l, o.opacity); +} + +export default function cubehelix(h, s, l, opacity) { + return arguments.length === 1 ? cubehelixConvert(h) : new Cubehelix(h, s, l, opacity == null ? 1 : opacity); +} + +export function Cubehelix(h, s, l, opacity) { + this.h = +h; + this.s = +s; + this.l = +l; + this.opacity = +opacity; +} + +define(Cubehelix, cubehelix, extend(Color, { + brighter: function (k) { + k = k == null ? brighter : Math.pow(brighter, k); + return new Cubehelix(this.h, this.s, this.l * k, this.opacity); + }, + darker: function (k) { + k = k == null ? darker : Math.pow(darker, k); + return new Cubehelix(this.h, this.s, this.l * k, this.opacity); + }, + rgb: function () { + var h = isNaN(this.h) ? 0 : (this.h + 120) * deg2rad, + l = +this.l, + a = isNaN(this.s) ? 0 : this.s * l * (1 - l), + cosh = Math.cos(h), + sinh = Math.sin(h); + return new Rgb( + 255 * (l + a * (A * cosh + B * sinh)), + 255 * (l + a * (C * cosh + D * sinh)), + 255 * (l + a * (E * cosh)), + this.opacity + ); + } +})); \ No newline at end of file diff --git a/tests/vercel/full-compact/d3-color/1/output/index.js b/tests/vercel/full-compact/d3-color/1/output/index.js new file mode 100644 index 000000000000..09e1bb6558f7 --- /dev/null +++ b/tests/vercel/full-compact/d3-color/1/output/index.js @@ -0,0 +1 @@ +import*as a from"@swc/helpers";import{Color as b,rgbConvert as c,Rgb as d}from"./color.js";var e,f,g,h=Math.PI/180,i=180/Math.PI,j=-0.5210501878999999-0.1347134789;export default function cubehelix(k,l,m,n){return 1===arguments.length?(function(o){if(a._instanceof(o,Cubehelix))return new Cubehelix(o.h,o.s,o.l,o.opacity);a._instanceof(o,d)||(o=c(o));var p=o.r/255,q=o.g/255,r=o.b/255,s=(j*r+ -1.7884503806*p-3.5172982438*q)/(j+ -1.7884503806-3.5172982438),t=r-s,u=-((1.97294*(q-s)- -0.29227*t)/0.90649),v=Math.sqrt(u*u+t*t)/(1.97294*s*(1-s)),w=v?Math.atan2(u,t)*i-120:NaN;return new Cubehelix(w<0?w+360:w,v,s,o.opacity)})(k):new Cubehelix(k,l,m,null==n?1:n)};export function Cubehelix(x,y,z,A){this.h=+x,this.s=+y,this.l=+z,this.opacity=+A}e=Cubehelix,f=cubehelix,g=(function(B,C){var D=Object.create(B.prototype);for(var E in C)D[E]=C[E];return D})(b,{brighter:function(F){return F=null==F?1.4285714285714286:Math.pow(1.4285714285714286,F),new Cubehelix(this.h,this.s,this.l*F,this.opacity)},darker:function(G){return G=null==G?0.7:Math.pow(0.7,G),new Cubehelix(this.h,this.s,this.l*G,this.opacity)},rgb:function(){var H=isNaN(this.h)?0:(this.h+120)*h,I=+this.l,J=isNaN(this.s)?0:this.s*I*(1-I),K=Math.cos(H),L=Math.sin(H);return new d(255*(I+J*(-0.14861*K+1.78277*L)),255*(I+J*(-0.29227*K+ -0.90649*L)),255*(I+J*(1.97294*K)),this.opacity)}}),e.prototype=f.prototype=g,g.constructor=e diff --git a/tests/vercel/full/.swcrc b/tests/vercel/full/.swcrc index 9b4889bcaf2e..6d594882d70c 100644 --- a/tests/vercel/full/.swcrc +++ b/tests/vercel/full/.swcrc @@ -15,8 +15,12 @@ } }, "minify": { - "compress": true, - "mangle": true, + "compress": { + "toplevel": true + }, + "mangle": { + "toplevel": true + }, "toplevel": true }, "externalHelpers": true diff --git a/tests/vercel/full/d3-color/1/input/index.js b/tests/vercel/full/d3-color/1/input/index.js new file mode 100644 index 000000000000..412680fa5090 --- /dev/null +++ b/tests/vercel/full/d3-color/1/input/index.js @@ -0,0 +1,61 @@ +import define, { extend } from "./define.js"; +import { Color, rgbConvert, Rgb, darker, brighter } from "./color.js"; +import { deg2rad, rad2deg } from "./math.js"; + +var A = -0.14861, + B = +1.78277, + C = -0.29227, + D = -0.90649, + E = +1.97294, + ED = E * D, + EB = E * B, + BC_DA = B * C - D * A; + +function cubehelixConvert(o) { + if (o instanceof Cubehelix) return new Cubehelix(o.h, o.s, o.l, o.opacity); + if (!(o instanceof Rgb)) o = rgbConvert(o); + var r = o.r / 255, + g = o.g / 255, + b = o.b / 255, + l = (BC_DA * b + ED * r - EB * g) / (BC_DA + ED - EB), + bl = b - l, + k = (E * (g - l) - C * bl) / D, + s = Math.sqrt(k * k + bl * bl) / (E * l * (1 - l)), // NaN if l=0 or l=1 + h = s ? Math.atan2(k, bl) * rad2deg - 120 : NaN; + return new Cubehelix(h < 0 ? h + 360 : h, s, l, o.opacity); +} + +export default function cubehelix(h, s, l, opacity) { + return arguments.length === 1 ? cubehelixConvert(h) : new Cubehelix(h, s, l, opacity == null ? 1 : opacity); +} + +export function Cubehelix(h, s, l, opacity) { + this.h = +h; + this.s = +s; + this.l = +l; + this.opacity = +opacity; +} + +define(Cubehelix, cubehelix, extend(Color, { + brighter: function (k) { + k = k == null ? brighter : Math.pow(brighter, k); + return new Cubehelix(this.h, this.s, this.l * k, this.opacity); + }, + darker: function (k) { + k = k == null ? darker : Math.pow(darker, k); + return new Cubehelix(this.h, this.s, this.l * k, this.opacity); + }, + rgb: function () { + var h = isNaN(this.h) ? 0 : (this.h + 120) * deg2rad, + l = +this.l, + a = isNaN(this.s) ? 0 : this.s * l * (1 - l), + cosh = Math.cos(h), + sinh = Math.sin(h); + return new Rgb( + 255 * (l + a * (A * cosh + B * sinh)), + 255 * (l + a * (C * cosh + D * sinh)), + 255 * (l + a * (E * cosh)), + this.opacity + ); + } +})); \ No newline at end of file diff --git a/tests/vercel/full/d3-color/1/output/index.js b/tests/vercel/full/d3-color/1/output/index.js new file mode 100644 index 000000000000..0563a9eb25d5 --- /dev/null +++ b/tests/vercel/full/d3-color/1/output/index.js @@ -0,0 +1,28 @@ +import * as a from "@swc/helpers"; +import b, { extend as c } from "./define.js"; +import { Color as d, rgbConvert as e, Rgb as f, darker as g, brighter as h } from "./color.js"; +import { deg2rad as i, rad2deg as j } from "./math.js"; +var k = -0.5210501878999999 - 0.1347134789; +export default function cubehelix(l, m, n, o) { + return 1 === arguments.length ? (function(p) { + if (a._instanceof(p, Cubehelix)) return new Cubehelix(p.h, p.s, p.l, p.opacity); + a._instanceof(p, f) || (p = e(p)); + var q = p.r / 255, r = p.g / 255, s = p.b / 255, t = (k * s + -1.7884503806 * q - 3.5172982438 * r) / (k + -1.7884503806 - 3.5172982438), u = s - t, v = -((1.97294 * (r - t) - -0.29227 * u) / 0.90649), w = Math.sqrt(v * v + u * u) / (1.97294 * t * (1 - t)), x = w ? Math.atan2(v, u) * j - 120 : NaN; + return new Cubehelix(x < 0 ? x + 360 : x, w, t, p.opacity); + })(l) : new Cubehelix(l, m, n, null == o ? 1 : o); +}; +export function Cubehelix(y, z, A, B) { + this.h = +y, this.s = +z, this.l = +A, this.opacity = +B; +} +b(Cubehelix, cubehelix, c(d, { + brighter: function(C) { + return C = null == C ? h : Math.pow(h, C), new Cubehelix(this.h, this.s, this.l * C, this.opacity); + }, + darker: function(D) { + return D = null == D ? g : Math.pow(g, D), new Cubehelix(this.h, this.s, this.l * D, this.opacity); + }, + rgb: function() { + var E = isNaN(this.h) ? 0 : (this.h + 120) * i, F = +this.l, G = isNaN(this.s) ? 0 : this.s * F * (1 - F), H = Math.cos(E), I = Math.sin(E); + return new f(255 * (F + G * (-0.14861 * H + 1.78277 * I)), 255 * (F + G * (-0.29227 * H + -0.90649 * I)), 255 * (F + G * (1.97294 * H)), this.opacity); + } +})); diff --git a/tests/vercel/full/react-instantsearch/2/output/index.js b/tests/vercel/full/react-instantsearch/2/output/index.js index c5ba27e41ee8..c4d2b45da271 100644 --- a/tests/vercel/full/react-instantsearch/2/output/index.js +++ b/tests/vercel/full/react-instantsearch/2/output/index.js @@ -5,363 +5,362 @@ import { HIGHLIGHT_TAGS as d } from "./highlight"; import { hasMultipleIndices as e } from "./indexUtils"; import { version as f } from "react"; import g from "./version"; -function addAlgoliaAgents(h) { - "function" == typeof h.addAlgoliaAgent && (h.addAlgoliaAgent("react (".concat(f, ")")), h.addAlgoliaAgent("react-instantsearch (".concat(g, ")"))); +function h(i) { + "function" == typeof i.addAlgoliaAgent && (i.addAlgoliaAgent("react (".concat(f, ")")), i.addAlgoliaAgent("react-instantsearch (".concat(g, ")"))); } -var _obj, isMultiIndexContext = function(i) { +var j, k = function(l) { return e({ - ais: i.props.contextValue, - multiIndexContext: i.props.indexContextValue + ais: l.props.contextValue, + multiIndexContext: l.props.indexContextValue }); -}, isTargetedIndexEqualIndex = function(j, k) { - return j.props.indexContextValue.targetedIndex === k; -}, isIndexWidget = function(l) { - return Boolean(l.props.indexId); -}, isIndexWidgetEqualIndex = function(m, n) { - return m.props.indexId === n; -}, sortIndexWidgetsFirst = function(o, p) { - var q = isIndexWidget(o), r = isIndexWidget(p); - return q && !r ? -1 : !q && r ? 1 : 0; +}, m = function(n, o) { + return n.props.indexContextValue.targetedIndex === o; +}, p = function(q) { + return Boolean(q.props.indexId); +}, r = function(s, t) { + return s.props.indexId === t; +}, u = function(v, w) { + var x = p(v), y = p(w); + return x && !y ? -1 : !x && y ? 1 : 0; }; -function serializeQueryParameters(s) { - var t = function(u) { - for(var v = arguments.length, w = new Array(v > 1 ? v - 1 : 0), x = 1; x < v; x++)w[x - 1] = arguments[x]; - var y = 0; - return u.replace(/%s/g, function() { - return encodeURIComponent(w[y++]); +export default function createInstantSearchManager(z) { + var A = z.indexName, B = z.initialState, C = z.searchClient, D = z.resultsState, E = z.stalledSearchDelay, F = function(G) { + return H.getWidgets().filter(function(I) { + return Boolean(I.getMetadata); + }).map(function(J) { + return J.getMetadata(G); }); - }; - return Object.keys(s).map(function(z) { - var A; - return t("%s=%s", z, (A = s[z], "[object Object]" === Object.prototype.toString.call(A) || "[object Array]" === Object.prototype.toString.call(A)) ? JSON.stringify(s[z]) : s[z]); - }).join("&"); -} -export default function createInstantSearchManager(B) { - var C = B.indexName, D = B.initialState, E = B.searchClient, F = B.resultsState, G = B.stalledSearchDelay, H = function(I) { - return J.getWidgets().filter(function(K) { - return Boolean(K.getMetadata); - }).map(function(L) { - return L.getMetadata(I); - }); - }, M = function() { - var N = J.getWidgets().filter(function(O) { - return Boolean(O.getSearchParameters); - }).filter(function(P) { - return !isMultiIndexContext(P) && !isIndexWidget(P); - }).reduce(function(Q, R) { - return R.getSearchParameters(Q); - }, S), T = J.getWidgets().filter(function(U) { - return Boolean(U.getSearchParameters); - }).filter(function(V) { - var W = isMultiIndexContext(V) && isTargetedIndexEqualIndex(V, C), X = isIndexWidget(V) && isIndexWidgetEqualIndex(V, C); - return W || X; - }).sort(sortIndexWidgetsFirst).reduce(function(Y, Z) { - return Z.getSearchParameters(Y); - }, N), $ = J.getWidgets().filter(function(_) { - return Boolean(_.getSearchParameters); - }).filter(function(aa) { - var ba = isMultiIndexContext(aa) && !isTargetedIndexEqualIndex(aa, C), ca = isIndexWidget(aa) && !isIndexWidgetEqualIndex(aa, C); - return ba || ca; - }).sort(sortIndexWidgetsFirst).reduce(function(da, ea) { - var fa = isMultiIndexContext(ea) ? ea.props.indexContextValue.targetedIndex : ea.props.indexId, ga = da[fa] || []; + }, K = function() { + var L = H.getWidgets().filter(function(M) { + return Boolean(M.getSearchParameters); + }).filter(function(N) { + return !k(N) && !p(N); + }).reduce(function(O, P) { + return P.getSearchParameters(O); + }, Q), R = H.getWidgets().filter(function(S) { + return Boolean(S.getSearchParameters); + }).filter(function(T) { + var U = k(T) && m(T, A), V = p(T) && r(T, A); + return U || V; + }).sort(u).reduce(function(W, X) { + return X.getSearchParameters(W); + }, L), Y = H.getWidgets().filter(function(Z) { + return Boolean(Z.getSearchParameters); + }).filter(function($) { + var _ = k($) && !m($, A), aa = p($) && !r($, A); + return _ || aa; + }).sort(u).reduce(function(ba, ca) { + var da = k(ca) ? ca.props.indexContextValue.targetedIndex : ca.props.indexId, ea = ba[da] || []; return a.objectSpread({ - }, da, a.defineProperty({ - }, fa, ga.concat(ea))); + }, ba, a.defineProperty({ + }, da, ea.concat(ca))); }, { }); return { - mainParameters: T, - derivedParameters: Object.keys($).map(function(ha) { + mainParameters: R, + derivedParameters: Object.keys(Y).map(function(fa) { return { - parameters: $[ha].reduce(function(ia, ja) { - return ja.getSearchParameters(ia); - }, N), - indexId: ha + parameters: Y[fa].reduce(function(ga, ha) { + return ha.getSearchParameters(ga); + }, L), + indexId: fa }; }) }; - }, ka = function() { - if (!la) { - var ma = M(na.state), oa = ma.mainParameters, pa = ma.derivedParameters; - na.derivedHelpers.slice().forEach(function(qa) { - qa.detach(); - }), pa.forEach(function(ra) { - var sa = ra.indexId, ta = ra.parameters; - na.derive(function() { - return ta; - }).on("result", ua({ - indexId: sa - })).on("error", va); - }), na.setState(oa), na.search(); + }, ia = function() { + if (!ja) { + var ka = K(la.state), ma = ka.mainParameters, na = ka.derivedParameters; + la.derivedHelpers.slice().forEach(function(oa) { + oa.detach(); + }), na.forEach(function(pa) { + var qa = pa.indexId, ra = pa.parameters; + la.derive(function() { + return ra; + }).on("result", sa({ + indexId: qa + })).on("error", ta); + }), la.setState(ma), la.search(); } - }, ua = function(wa) { - var xa = wa.indexId; - return function(ya) { - var za = Aa.getState(), Ba = !na.derivedHelpers.length, Ca = za.results ? za.results : { + }, sa = function(ua) { + var va = ua.indexId; + return function(wa) { + var xa = ya.getState(), za = !la.derivedHelpers.length, Aa = xa.results ? xa.results : { }; - Ca = !Ba && Ca.getFacetByName ? { - } : Ca, Ca = Ba ? ya.results : a.objectSpread({ - }, Ca, a.defineProperty({ - }, xa, ya.results)); - var Da = Aa.getState(), Ea = Da.isSearchStalled; - na.hasPendingRequests() || (clearTimeout(Fa), Fa = null, Ea = !1), Da.resultsFacetValues; - var Ga = a.objectWithoutProperties(Da, ["resultsFacetValues"]); - Aa.setState(a.objectSpread({ - }, Ga, { - results: Ca, - isSearchStalled: Ea, + Aa = !za && Aa.getFacetByName ? { + } : Aa, Aa = za ? wa.results : a.objectSpread({ + }, Aa, a.defineProperty({ + }, va, wa.results)); + var Ba = ya.getState(), Ca = Ba.isSearchStalled; + la.hasPendingRequests() || (clearTimeout(Da), Da = null, Ca = !1), Ba.resultsFacetValues; + var Ea = a.objectWithoutProperties(Ba, ["resultsFacetValues"]); + ya.setState(a.objectSpread({ + }, Ea, { + results: Aa, + isSearchStalled: Ca, searching: !1, error: null })); }; - }, va = function(Ha) { - var Ia = Ha.error, Ja = Aa.getState(), Ka = Ja.isSearchStalled; - na.hasPendingRequests() || (clearTimeout(Fa), Ka = !1), Ja.resultsFacetValues; - var La = a.objectWithoutProperties(Ja, ["resultsFacetValues"]); - Aa.setState(a.objectSpread({ - }, La, { - isSearchStalled: Ka, - error: Ia, + }, ta = function(Fa) { + var Ga = Fa.error, Ha = ya.getState(), Ia = Ha.isSearchStalled; + la.hasPendingRequests() || (clearTimeout(Da), Ia = !1), Ha.resultsFacetValues; + var Ja = a.objectWithoutProperties(Ha, ["resultsFacetValues"]); + ya.setState(a.objectSpread({ + }, Ja, { + isSearchStalled: Ia, + error: Ga, searching: !1 })); - }, Ma = function(Na, Oa) { - if (Na.transporter) { - Na.transporter.responsesCache.set({ + }, Ka = function(La, Ma) { + if (La.transporter) { + La.transporter.responsesCache.set({ method: "search", args: [ - Oa.reduce(function(Pa, Qa) { - return Pa.concat(Qa.rawResults.map(function(Ra) { + Ma.reduce(function(Na, Oa) { + return Na.concat(Oa.rawResults.map(function(Pa) { return { - indexName: Ra.index, - params: Ra.params + indexName: Pa.index, + params: Pa.params }; })); }, []), ] }, { - results: Oa.reduce(function(Sa, Ta) { - return Sa.concat(Ta.rawResults); + results: Ma.reduce(function(Qa, Ra) { + return Qa.concat(Ra.rawResults); }, []) }); return; } - var Ua = "/1/indexes/*/queries_body_".concat(JSON.stringify({ - requests: Oa.reduce(function(Va, Wa) { - return Va.concat(Wa.rawResults.map(function(Xa) { + var Sa = "/1/indexes/*/queries_body_".concat(JSON.stringify({ + requests: Ma.reduce(function(Ta, Ua) { + return Ta.concat(Ua.rawResults.map(function(Va) { return { - indexName: Xa.index, - params: Xa.params + indexName: Va.index, + params: Va.params }; })); }, []) })); - Na.cache = a.objectSpread({ - }, Na.cache, a.defineProperty({ - }, Ua, JSON.stringify({ - results: Oa.reduce(function(Ya, Za) { - return Ya.concat(Za.rawResults); + La.cache = a.objectSpread({ + }, La.cache, a.defineProperty({ + }, Sa, JSON.stringify({ + results: Ma.reduce(function(Wa, Xa) { + return Wa.concat(Xa.rawResults); }, []) }))); - }, $a = function(_a, ab) { - if (_a.transporter) { - _a.transporter.responsesCache.set({ + }, Ya = function(Za, $a) { + if (Za.transporter) { + Za.transporter.responsesCache.set({ method: "search", args: [ - ab.rawResults.map(function(bb) { + $a.rawResults.map(function(_a) { return { - indexName: bb.index, - params: bb.params + indexName: _a.index, + params: _a.params }; }), ] }, { - results: ab.rawResults + results: $a.rawResults }); return; } - var cb = "/1/indexes/*/queries_body_".concat(JSON.stringify({ - requests: ab.rawResults.map(function(db) { + var ab = "/1/indexes/*/queries_body_".concat(JSON.stringify({ + requests: $a.rawResults.map(function(bb) { return { - indexName: db.index, - params: db.params + indexName: bb.index, + params: bb.params }; }) })); - _a.cache = a.objectSpread({ - }, _a.cache, a.defineProperty({ - }, cb, JSON.stringify({ - results: ab.rawResults + Za.cache = a.objectSpread({ + }, Za.cache, a.defineProperty({ + }, ab, JSON.stringify({ + results: $a.rawResults }))); - }, na = b(E, C, a.objectSpread({ + }, la = b(C, A, a.objectSpread({ }, d)); - addAlgoliaAgents(E), na.on("search", function() { - Fa || (Fa = setTimeout(function() { - var eb = Aa.getState(), fb = eb.resultsFacetValues, gb = a.objectWithoutProperties(eb, ["resultsFacetValues"]); - Aa.setState(a.objectSpread({ - }, gb, { + h(C), la.on("search", function() { + Da || (Da = setTimeout(function() { + var cb = ya.getState(), db = cb.resultsFacetValues, eb = a.objectWithoutProperties(cb, ["resultsFacetValues"]); + ya.setState(a.objectSpread({ + }, eb, { isSearchStalled: !0 })); - }, G)); - }).on("result", ua({ - indexId: C - })).on("error", va); - var la = !1, Fa = null, S = na.state, J = c(function() { - var hb = H(Aa.getState().widgets); - Aa.setState(a.objectSpread({ - }, Aa.getState(), { - metadata: hb, + }, E)); + }).on("result", sa({ + indexId: A + })).on("error", ta); + var ja = !1, Da = null, Q = la.state, H = c(function() { + var fb = F(ya.getState().widgets); + ya.setState(a.objectSpread({ + }, ya.getState(), { + metadata: fb, searching: !0 - })), ka(); + })), ia(); }); - !function(ib, jb) { - if (jb && (ib.transporter && !ib._cacheHydrated || ib._useCache && "function" == typeof ib.addAlgoliaAgent)) { - if (ib.transporter && !ib._cacheHydrated) { - ib._cacheHydrated = !0; - var kb = ib.search; - ib.search = function(lb) { - for(var mb = arguments.length, nb = new Array(mb > 1 ? mb - 1 : 0), ob = 1; ob < mb; ob++)nb[ob - 1] = arguments[ob]; - var pb = lb.map(function(qb) { + !function(gb, hb) { + if (hb && (gb.transporter && !gb._cacheHydrated || gb._useCache && "function" == typeof gb.addAlgoliaAgent)) { + if (gb.transporter && !gb._cacheHydrated) { + gb._cacheHydrated = !0; + var ib = gb.search; + gb.search = function(jb) { + for(var kb = arguments.length, lb = new Array(kb > 1 ? kb - 1 : 0), mb = 1; mb < kb; mb++)lb[mb - 1] = arguments[mb]; + var nb = jb.map(function(ob) { return a.objectSpread({ - }, qb, { - params: serializeQueryParameters(qb.params) + }, ob, { + params: function(pb) { + var qb = function(rb) { + for(var sb = arguments.length, tb = new Array(sb > 1 ? sb - 1 : 0), ub = 1; ub < sb; ub++)tb[ub - 1] = arguments[ub]; + var vb = 0; + return rb.replace(/%s/g, function() { + return encodeURIComponent(tb[vb++]); + }); + }; + return Object.keys(pb).map(function(wb) { + var xb; + return qb("%s=%s", wb, (xb = pb[wb], "[object Object]" === Object.prototype.toString.call(xb) || "[object Array]" === Object.prototype.toString.call(xb)) ? JSON.stringify(pb[wb]) : pb[wb]); + }).join("&"); + }(ob.params) }); }); - return ib.transporter.responsesCache.get({ + return gb.transporter.responsesCache.get({ method: "search", args: [ - pb - ].concat(a.toConsumableArray(nb)) + nb + ].concat(a.toConsumableArray(lb)) }, function() { - return kb.apply(void 0, [ - lb - ].concat(a.toConsumableArray(nb))); + return ib.apply(void 0, [ + jb + ].concat(a.toConsumableArray(lb))); }); }; } - if (Array.isArray(jb.results)) { - Ma(ib, jb.results); + if (Array.isArray(hb.results)) { + Ka(gb, hb.results); return; } - $a(ib, jb); + Ya(gb, hb); } - }(E, F); - var rb, sb, tb, Aa = (sb = { - widgets: void 0 === D ? { - } : D, - metadata: hydrateMetadata(F), - results: (rb = F) ? Array.isArray(rb.results) ? rb.results.reduce(function(ub, vb) { + }(C, D); + var yb, zb, Ab, ya = (zb = { + widgets: void 0 === B ? { + } : B, + metadata: Bb(D), + results: (yb = D) ? Array.isArray(yb.results) ? yb.results.reduce(function(Cb, Db) { return a.objectSpread({ - }, ub, a.defineProperty({ - }, vb._internalIndexId, new b.SearchResults(new b.SearchParameters(vb.state), vb.rawResults))); + }, Cb, a.defineProperty({ + }, Db._internalIndexId, new b.SearchResults(new b.SearchParameters(Db.state), Db.rawResults))); }, { - }) : new b.SearchResults(new b.SearchParameters(rb.state), rb.rawResults) : null, + }) : new b.SearchResults(new b.SearchParameters(yb.state), yb.rawResults) : null, error: null, searching: !1, isSearchStalled: !0, searchingForFacetValues: !1 - }, tb = [], { + }, Ab = [], { getState: function() { - return sb; + return zb; }, - setState: function(wb) { - sb = wb, tb.forEach(function(xb) { - return xb(); + setState: function(Eb) { + zb = Eb, Ab.forEach(function(Fb) { + return Fb(); }); }, - subscribe: function(yb) { - return tb.push(yb), function() { - tb.splice(tb.indexOf(yb), 1); + subscribe: function(Gb) { + return Ab.push(Gb), function() { + Ab.splice(Ab.indexOf(Gb), 1); }; } }); return { - store: Aa, - widgetsManager: J, + store: ya, + widgetsManager: H, getWidgetsIds: function() { - return Aa.getState().metadata.reduce(function(zb, Ab) { - return void 0 !== Ab.id ? zb.concat(Ab.id) : zb; + return ya.getState().metadata.reduce(function(Hb, Ib) { + return void 0 !== Ib.id ? Hb.concat(Ib.id) : Hb; }, []); }, - getSearchParameters: M, - onSearchForFacetValues: function(Bb) { - var Cb = Bb.facetName, Db = Bb.query, Eb = Bb.maxFacetHits; - Aa.setState(a.objectSpread({ - }, Aa.getState(), { + getSearchParameters: K, + onSearchForFacetValues: function(Jb) { + var Kb = Jb.facetName, Lb = Jb.query, Mb = Jb.maxFacetHits; + ya.setState(a.objectSpread({ + }, ya.getState(), { searchingForFacetValues: !0 - })), na.searchForFacetValues(Cb, Db, Math.max(1, Math.min(void 0 === Eb ? 10 : Eb, 100))).then(function(Fb) { - Aa.setState(a.objectSpread({ - }, Aa.getState(), { + })), la.searchForFacetValues(Kb, Lb, Math.max(1, Math.min(void 0 === Mb ? 10 : Mb, 100))).then(function(Nb) { + ya.setState(a.objectSpread({ + }, ya.getState(), { error: null, searchingForFacetValues: !1, resultsFacetValues: a.objectSpread({ - }, Aa.getState().resultsFacetValues, (_obj = { - }, a.defineProperty(_obj, Cb, Fb.facetHits), a.defineProperty(_obj, "query", Db), _obj)) + }, ya.getState().resultsFacetValues, (j = { + }, a.defineProperty(j, Kb, Nb.facetHits), a.defineProperty(j, "query", Lb), j)) })); - }, function(Gb) { - Aa.setState(a.objectSpread({ - }, Aa.getState(), { + }, function(Ob) { + ya.setState(a.objectSpread({ + }, ya.getState(), { searchingForFacetValues: !1, - error: Gb + error: Ob })); - }).catch(function(Hb) { + }).catch(function(Pb) { setTimeout(function() { - throw Hb; + throw Pb; }); }); }, - onExternalStateUpdate: function(Ib) { - var Jb = H(Ib); - Aa.setState(a.objectSpread({ - }, Aa.getState(), { - widgets: Ib, - metadata: Jb, + onExternalStateUpdate: function(Qb) { + var Rb = F(Qb); + ya.setState(a.objectSpread({ + }, ya.getState(), { + widgets: Qb, + metadata: Rb, searching: !0 - })), ka(); + })), ia(); }, - transitionState: function(Kb) { - var Lb = Aa.getState().widgets; - return J.getWidgets().filter(function(Mb) { - return Boolean(Mb.transitionState); - }).reduce(function(Nb, Ob) { - return Ob.transitionState(Lb, Nb); - }, Kb); + transitionState: function(Sb) { + var Tb = ya.getState().widgets; + return H.getWidgets().filter(function(Ub) { + return Boolean(Ub.transitionState); + }).reduce(function(Vb, Wb) { + return Wb.transitionState(Tb, Vb); + }, Sb); }, - updateClient: function(Pb) { - addAlgoliaAgents(Pb), na.setClient(Pb), ka(); + updateClient: function(Xb) { + h(Xb), la.setClient(Xb), ia(); }, - updateIndex: function(Qb) { - S = S.setIndex(Qb); + updateIndex: function(Yb) { + Q = Q.setIndex(Yb); }, clearCache: function() { - na.clearCache(), ka(); + la.clearCache(), ia(); }, skipSearch: function() { - la = !0; + ja = !0; } }; }; -function hydrateMetadata(Rb) { - return Rb ? Rb.metadata.map(function(Sb) { +function Bb(Zb) { + return Zb ? Zb.metadata.map(function($b) { return a.objectSpread({ value: function() { return { }; } - }, Sb, { - items: Sb.items && Sb.items.map(function(Tb) { + }, $b, { + items: $b.items && $b.items.map(function(_b) { return a.objectSpread({ value: function() { return { }; } - }, Tb, { - items: Tb.items && Tb.items.map(function(Ub) { + }, _b, { + items: _b.items && _b.items.map(function(ac) { return a.objectSpread({ value: function() { return { }; } - }, Ub); + }, ac); }) }); })