perf(es/parser): Use SmartString as the buffer (#7033)

This commit is contained in:
Donny/강동윤 2023-03-09 17:07:40 +09:00 committed by GitHub
parent fd2619ca24
commit f378a14888
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 119 additions and 101 deletions

168
bindings/Cargo.lock generated
View File

@ -189,9 +189,9 @@ dependencies = [
[[package]]
name = "binding_macros"
version = "0.39.5"
version = "0.40.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "862f14db990f49acfa08559763beaa83f3c635f595b79ee6d84c8014ed05d1a5"
checksum = "ef1db5e1d0b930a77d32d9da5c3f0b4ec84277fefde804d63ae91823fa5e5de4"
dependencies = [
"anyhow",
"console_error_panic_hook",
@ -1120,9 +1120,9 @@ dependencies = [
[[package]]
name = "itoa"
version = "1.0.5"
version = "1.0.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fad582f4b9e86b6caa621cabeb0963332d92eea04729ab12892c2533951e6440"
checksum = "453ad9f582a441959e5f0d088b02ce04cfe8d51a8eaf077f12ac6d3e94164ca6"
[[package]]
name = "js-sys"
@ -2092,9 +2092,9 @@ dependencies = [
[[package]]
name = "rustversion"
version = "1.0.11"
version = "1.0.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5583e89e108996506031660fe09baa5011b9dd0341b89029313006d1fb508d70"
checksum = "4f3208ce4d8448b3f3e7d168a73f5e0c43a61e32930de3bceeccedb388b6bf06"
[[package]]
name = "ryu"
@ -2278,6 +2278,17 @@ version = "1.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a507befe795404456341dfab10cef66ead4c041f62b8b11bbb92bffe5d0953e0"
[[package]]
name = "smartstring"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3fb72c633efbaa2dd666986505016c32c3044395ceaf881518399d2f4127ee29"
dependencies = [
"autocfg",
"static_assertions",
"version_check",
]
[[package]]
name = "smawk"
version = "0.3.1"
@ -2406,9 +2417,9 @@ checksum = "213701ba3370744dcd1a12960caa4843b3d68b4d1c0a5d575e0d65b2ee9d16c0"
[[package]]
name = "string_cache"
version = "0.8.4"
version = "0.8.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "213494b7a2b503146286049378ce02b482200519accc31872ee8be91fa820a08"
checksum = "f91138e76242f575eb1d3b38b4f1362f10d3a43f47d182a5b359af488a02293b"
dependencies = [
"new_debug_unreachable",
"once_cell",
@ -2485,9 +2496,9 @@ dependencies = [
[[package]]
name = "swc"
version = "0.250.5"
version = "0.251.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bb4692e59d0b43c378e8d5cfed50a705fecef6aa3a1dc49417d7593de6c4cae1"
checksum = "790f0fcb4d209442a0c0423d99638040ab243ac436efcad1bbef1e82ca922a7f"
dependencies = [
"ahash",
"anyhow",
@ -2537,9 +2548,9 @@ dependencies = [
[[package]]
name = "swc_atoms"
version = "0.4.38"
version = "0.4.39"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5a172f2e444ae1378286cd27ff2a5cb26eadfd7a77c98ccb0edde8992857be1e"
checksum = "2ebef84c2948cd0d1ba25acbf1b4bd9d80ab6f057efdbe35d8449b8d54699401"
dependencies = [
"once_cell",
"rkyv",
@ -2552,9 +2563,9 @@ dependencies = [
[[package]]
name = "swc_bundler"
version = "0.204.3"
version = "0.205.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8d488dbc661de057831e255c92d9d7be0d50c156ece0e16ccee52d7de259cca6"
checksum = "240760e3754c4d5ebba065716305e68375a1eac00ae98585217957bd12f84aee"
dependencies = [
"ahash",
"anyhow",
@ -2621,9 +2632,9 @@ dependencies = [
[[package]]
name = "swc_common"
version = "0.29.33"
version = "0.29.35"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a8a75c46065858a37cdda2c1c6fd056986e3b7752d5ec332e91ce312c6a22749"
checksum = "2d515be281f603cb97afaa89896aca5e5c748fde11c7f926e35cdaa8ff8da705"
dependencies = [
"ahash",
"anyhow",
@ -2677,9 +2688,9 @@ dependencies = [
[[package]]
name = "swc_core"
version = "0.64.5"
version = "0.65.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7efb495293e2a0e594d6870723f52b6aca7a9e625b62ac5bccb4636c7633d4fe"
checksum = "fc90566581ebbe616434c008c13717034d550c05b870ac94e621b3b9ccbf7470"
dependencies = [
"binding_macros",
"swc",
@ -2703,9 +2714,9 @@ dependencies = [
[[package]]
name = "swc_ecma_ast"
version = "0.98.0"
version = "0.98.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7b1f6bc913d0f1daf0fa713a64660aed27848e0047ee671ab2206ad602730d1f"
checksum = "305d2aa5e36a775e0d376552b35b325fccf0d7d8c633da1e4aec8e16460251cf"
dependencies = [
"bitflags",
"is-macro",
@ -2721,9 +2732,9 @@ dependencies = [
[[package]]
name = "swc_ecma_codegen"
version = "0.133.1"
version = "0.133.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ec5b39a0d68361529eee6aa3aa3ddcd95643ede097239670976d09cbbfc630f4"
checksum = "2039354d02edb9ca28bd4689b53da4be3ba567996dc9ebb1964d36edfb6aa01a"
dependencies = [
"memchr",
"num-bigint",
@ -2753,9 +2764,9 @@ dependencies = [
[[package]]
name = "swc_ecma_ext_transforms"
version = "0.97.1"
version = "0.97.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "98d82148fefd864cb3b01aa53f00ac187fa9173a1434b885519ad907c34bd068"
checksum = "5078e4a9e3c0f51f2e8d40abb4bcd45452f363ca82f2f8aafc37b4c39f98af9d"
dependencies = [
"phf",
"swc_atoms",
@ -2767,9 +2778,9 @@ dependencies = [
[[package]]
name = "swc_ecma_lints"
version = "0.75.1"
version = "0.75.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "780d7e0d87ca893873db5c216dd9344cb7a351617f5149896b453f37d5b123b7"
checksum = "4f88ce80eb229f9d91357cac61722bcef343a7fdfb560cfda3c1e95ade60b0ad"
dependencies = [
"ahash",
"auto_impl",
@ -2788,9 +2799,9 @@ dependencies = [
[[package]]
name = "swc_ecma_loader"
version = "0.41.35"
version = "0.41.37"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6c51f1294809f4ffa69dc3c9777f741407a5ebfc2fe8bd283287e867c2fdf571"
checksum = "d42115d95265354ec5dce8ee2011b8a59a06c995bd81019cf90c94c2dbe1e72a"
dependencies = [
"ahash",
"anyhow",
@ -2810,9 +2821,9 @@ dependencies = [
[[package]]
name = "swc_ecma_minifier"
version = "0.171.3"
version = "0.172.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ee4cc67c4eaeb413168189c438f2b4588422e2c2c08396973b089dc2e8a54003"
checksum = "6b4e44a0c005af2a1523a32851d012c862c3a0e44ae051cb55b223efe7aea645"
dependencies = [
"ahash",
"arrayvec",
@ -2846,9 +2857,9 @@ dependencies = [
[[package]]
name = "swc_ecma_parser"
version = "0.128.1"
version = "0.128.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1e02b0bab1bf374f1957c68e848b6280c4905ad763d280e3508a41222c9e01fe"
checksum = "35e349e3f4c5561645b9042caae162dbaf55502be7b583ac99f3ccf3e65bccb7"
dependencies = [
"either",
"enum_kind",
@ -2856,6 +2867,7 @@ dependencies = [
"num-bigint",
"serde",
"smallvec",
"smartstring",
"stacker",
"swc_atoms",
"swc_common",
@ -2866,9 +2878,9 @@ dependencies = [
[[package]]
name = "swc_ecma_preset_env"
version = "0.185.4"
version = "0.186.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7072c5e28079afcfedffd936bced3b492655f51150ba7431f97be1e02f24d3a3"
checksum = "c1820b8ca33f8069694537a43a6a600efb9d8b09da70b93588eac3e33b444440"
dependencies = [
"ahash",
"anyhow",
@ -2891,9 +2903,9 @@ dependencies = [
[[package]]
name = "swc_ecma_transforms"
version = "0.208.3"
version = "0.209.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8386f75457b4a810f1e1a715a3359c36556125df176762224941b11b24c24300"
checksum = "346c299116f26ab871136694247a602fdffa96a3dca2a4afa6cbc93c1c7365bc"
dependencies = [
"swc_atoms",
"swc_common",
@ -2911,9 +2923,9 @@ dependencies = [
[[package]]
name = "swc_ecma_transforms_base"
version = "0.120.1"
version = "0.120.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "505d2470c8551b3ef84b2c6ce9b3fc80dd20c82fea97efa32bdb9e44e1356649"
checksum = "9d503fb75de1e6ee63893da5e3958c967607741166b63ae39a53472caf5668fd"
dependencies = [
"better_scoped_tls",
"bitflags",
@ -2934,9 +2946,9 @@ dependencies = [
[[package]]
name = "swc_ecma_transforms_classes"
version = "0.109.1"
version = "0.109.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ca208cf43a62fac0b7950dabd722daee123e0edea6c625089a045c7ff483feda"
checksum = "bb5f21c293a4364a97cef0bad0b8ad1bff05bd4cb646cf72f9e5b0a78e25ac01"
dependencies = [
"swc_atoms",
"swc_common",
@ -2948,9 +2960,9 @@ dependencies = [
[[package]]
name = "swc_ecma_transforms_compat"
version = "0.145.1"
version = "0.145.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e874bccf256b3c528858c7b5874abd06bc2b9269de4cd3f98f2f9caefd3a7d97"
checksum = "d3ded22bad9154e534c39d90627907bb18215b37505d8dbe08bc08cb502dec38"
dependencies = [
"ahash",
"arrayvec",
@ -2988,9 +3000,9 @@ dependencies = [
[[package]]
name = "swc_ecma_transforms_module"
version = "0.162.1"
version = "0.162.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3afe1e80e7bb9407dd46653d734301ab9469a8a6c66d219426f4b59336d7ac12"
checksum = "460b2f85d2a8d08c745f308d91395f63722de30f32a3f97eae5a2211466c4bca"
dependencies = [
"Inflector",
"ahash",
@ -3016,9 +3028,9 @@ dependencies = [
[[package]]
name = "swc_ecma_transforms_optimization"
version = "0.177.3"
version = "0.178.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ed2e5c472cf4bb7f9051e3bf2e05b8447df3c3023a34979c752c1af32ecceea7"
checksum = "e1fcb1a7a8ecf1130f3b2bfdbca5a87bf3d3da37bdd42521c10cf1aa061c518f"
dependencies = [
"ahash",
"dashmap",
@ -3042,9 +3054,9 @@ dependencies = [
[[package]]
name = "swc_ecma_transforms_proposal"
version = "0.153.1"
version = "0.153.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "990725a376ebd1783e28cd9e9e467144355934526bb17fd7bb1416ec414c83b6"
checksum = "2dbc55e227cc124f39b8b68a49e97a3e51902ec322df3978ce7dce1955067789"
dependencies = [
"either",
"serde",
@ -3061,9 +3073,9 @@ dependencies = [
[[package]]
name = "swc_ecma_transforms_react"
version = "0.164.1"
version = "0.164.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f26d8ed6d16f0202813942aa3b7e4e021cd96b2f62982760ae927732f17b4706"
checksum = "a4b4c071678abefa7e710777d04aa7685a3e8f9781442a6f3d5a3dd8e9923088"
dependencies = [
"ahash",
"base64",
@ -3088,9 +3100,9 @@ dependencies = [
[[package]]
name = "swc_ecma_transforms_typescript"
version = "0.168.2"
version = "0.168.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "520c5454aa524712d31840cfc17bb0c34ac425ded7e22a36cc9cb62e52b4075e"
checksum = "de73b4c49705ddd729e444d6d292163c43e3923f295ca3bbcd4fdfe4effda1cc"
dependencies = [
"serde",
"swc_atoms",
@ -3104,9 +3116,9 @@ dependencies = [
[[package]]
name = "swc_ecma_usage_analyzer"
version = "0.7.1"
version = "0.7.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e7a89b90cbf37dcae4183a6ee49a09d31ad820bb4c12334311f2cc08fef014d8"
checksum = "6b1b80b89e5a9508c86ff905647828228803bbe33a121e45d10ae2f4a22a46ec"
dependencies = [
"ahash",
"indexmap",
@ -3122,9 +3134,9 @@ dependencies = [
[[package]]
name = "swc_ecma_utils"
version = "0.111.1"
version = "0.111.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2bd8d4402ee17080eb9aece013d5873407e5e00f629f839868819ebf08162a55"
checksum = "ebe14c826ab8dbfb9b2d35bbfbda00a26ef56e4a10b691a333a76c1e557836d2"
dependencies = [
"indexmap",
"num_cpus",
@ -3141,9 +3153,9 @@ dependencies = [
[[package]]
name = "swc_ecma_visit"
version = "0.84.0"
version = "0.84.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "aa285890870239831b1f77987be6760cef3fde84a21b90df64fd159bbe5647d7"
checksum = "b65ccfca013571987f254fec04abeb963438be8bd1790a96ca17104797824667"
dependencies = [
"num-bigint",
"swc_atoms",
@ -3167,9 +3179,9 @@ dependencies = [
[[package]]
name = "swc_error_reporters"
version = "0.13.34"
version = "0.13.36"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ac5eac14b6e9f53f19b6366e848677f34e44c15916b76dcfaa2e600ddea4aa2c"
checksum = "f3a4b9d58ac9c32200abd416463276a9eb62e6be9c6cad9f3612008f4087de70"
dependencies = [
"anyhow",
"miette",
@ -3180,9 +3192,9 @@ dependencies = [
[[package]]
name = "swc_fast_graph"
version = "0.17.34"
version = "0.17.36"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "136af1ce1c012a1f307636d7d34747519f1961bc32bec11f0803487a4e589331"
checksum = "8340903aed0b03dd5476d3484ef4f9c8755486e26d9abe07e369fb55fa6bdac4"
dependencies = [
"ahash",
"indexmap",
@ -3192,9 +3204,9 @@ dependencies = [
[[package]]
name = "swc_graph_analyzer"
version = "0.18.36"
version = "0.18.38"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2bffc5c61e2f154279dff27c916651615401d1b0c1a4b10e8e7049ff50c4494e"
checksum = "d62a59c0a0fa0e2965b3f99cc393a8b55f09c61e616072fcf0671c8c07c1d292"
dependencies = [
"ahash",
"auto_impl",
@ -3227,9 +3239,9 @@ dependencies = [
[[package]]
name = "swc_node_bundler"
version = "0.37.5"
version = "0.38.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "64bd1c69d498b2b3b1e1e23dbff51e4516728fcda2553d329a39d276d16fcccf"
checksum = "1028b518b4fe7f13ee33854ff30585d56959b3c17d6014b70d6c3a1d1c1b41d2"
dependencies = [
"anyhow",
"dashmap",
@ -3256,9 +3268,9 @@ dependencies = [
[[package]]
name = "swc_node_comments"
version = "0.16.33"
version = "0.16.35"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "53e40f97bf1c722179b54ea93228a155ad25b05d67eed75bcb8c366a270fb457"
checksum = "08cb171a68ab30cfd386a167d8ac2d7001d2a734a6986c5a1e9890c5a1bf4d90"
dependencies = [
"ahash",
"dashmap",
@ -3282,9 +3294,9 @@ dependencies = [
[[package]]
name = "swc_plugin_proxy"
version = "0.27.0"
version = "0.27.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "58e2496a242d3e76f51ccdfa9a4fcbef29e452e8a6c0b51eb208f00925405abb"
checksum = "45f18c85d6ecc2ab5fa29a115a50e95f60cf57124d3aee7d65379f48cc153226"
dependencies = [
"better_scoped_tls",
"rkyv",
@ -3296,9 +3308,9 @@ dependencies = [
[[package]]
name = "swc_plugin_runner"
version = "0.89.1"
version = "0.89.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "50614c1fb9c99f90fd8dc8269a6bef358d9c9af964e8ae416b0ab87446d905e7"
checksum = "cd6dff4f575b19ae06c59201d8e3e9065a90aa8fd4e83033fe42789b7b200a7c"
dependencies = [
"anyhow",
"enumset",
@ -3319,9 +3331,9 @@ dependencies = [
[[package]]
name = "swc_timer"
version = "0.17.35"
version = "0.17.37"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a8859462448bb036356c3285498b98b0e59f09ef9b8b28d44254ddb156a9c1c4"
checksum = "2fc18fc8ebc4fbcbfba74720b5bcf1e5d20e94116cb0882501aa82d1f568d8c0"
dependencies = [
"tracing",
]
@ -3442,18 +3454,18 @@ dependencies = [
[[package]]
name = "thiserror"
version = "1.0.38"
version = "1.0.39"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6a9cd18aa97d5c45c6603caea1da6628790b37f7a34b6ca89522331c5180fed0"
checksum = "a5ab016db510546d856297882807df8da66a16fb8c4101cb8b30054b0d5b2d9c"
dependencies = [
"thiserror-impl",
]
[[package]]
name = "thiserror-impl"
version = "1.0.38"
version = "1.0.39"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1fb327af4685e4d03fa8cbcf1716380da910eeb2bb8be417e7f9fd3fb164f36f"
checksum = "5420d42e90af0c38c3290abcca25b9b3bdf379fc9f55c528f53a269d9c9a267e"
dependencies = [
"proc-macro2",
"quote",

View File

@ -56,7 +56,7 @@ tracing-chrome = "0.5.0"
tracing-futures = "0.2.5"
tracing-subscriber = { version = "0.3.9", features = ["env-filter"] }
swc_core = { version = "0.64.5", features = [
swc_core = { version = "0.65.0", features = [
"allocator_node",
"ecma_ast",
"common_concurrent",

View File

@ -23,7 +23,7 @@ plugin = ["swc_core/plugin_transform_host_js"]
anyhow = "1.0.66"
serde = { version = "1", features = ["derive"] }
serde-wasm-bindgen = "0.4.5"
swc_core = { version = "0.64.5", features = [
swc_core = { version = "0.65.0", features = [
"common_perf",
"binding_macro_wasm",
"ecma_transforms",

View File

@ -27,7 +27,7 @@ relative-path = "1.6.1"
serde = { version = "1", features = ["derive"] }
serde_json = { version = "1", features = ["unbounded_depth"] }
sourcemap = "6.2.2"
swc_core = { version = "0.64.5", features = [
swc_core = { version = "0.65.0", features = [
"trace_macro",
"common_concurrent",
"base_concurrent",

View File

@ -834,14 +834,14 @@ fn f64_to_precision(value: f64, precision: usize) -> String {
// iv, v
m.push_str(&e.to_string());
return s + &m;
return s + &*m;
}
}
// 11
let e_inc = e + 1;
if e_inc == p_i32 {
return s + &m;
return s + &*m;
}
// 12
@ -855,7 +855,7 @@ fn f64_to_precision(value: f64, precision: usize) -> String {
}
// 14
s + &m
s + &*m
}
fn flt_str_to_exp(flt: &str) -> i32 {

View File

@ -707,7 +707,7 @@ impl SyntaxError {
token_list.join(" or ")
} else {
token_list[0..token_list.len() - 1].join(" , ")
+ &format!("or {}", token_list[token_list.len() - 1])
+ &*format!("or {}", token_list[token_list.len() - 1])
};
format!("Unexpected token. Did you mean {}?", did_you_mean).into()
}

View File

@ -4,6 +4,7 @@ use std::{cell::RefCell, char, iter::FusedIterator, rc::Rc};
use either::Either::{Left, Right};
use smallvec::{smallvec, SmallVec};
use smartstring::SmartString;
use swc_atoms::{Atom, AtomGenerator};
use swc_common::{comments::Comments, input::StringInput, BytePos, Span};
use swc_ecma_ast::{op, EsVersion};
@ -1080,7 +1081,7 @@ impl<'a> Lexer<'a> {
'\\' => {
raw.push(c);
let mut wrapped = Raw(Some(String::new()));
let mut wrapped = Raw(Some(Default::default()));
if let Some(chars) = l.read_escaped_char(&mut wrapped, false)? {
for c in chars {
@ -1200,7 +1201,7 @@ impl<'a> Lexer<'a> {
let start = self.cur_pos();
let mut cooked = Ok(String::new());
let mut raw = String::new();
let mut raw = SmartString::new();
while let Some(c) = self.cur() {
if c == '`' || (c == '$' && self.peek() == Some('{')) {
@ -1218,7 +1219,7 @@ impl<'a> Lexer<'a> {
// TODO: Handle error
return Ok(Template {
cooked: cooked.map(Atom::from),
raw: Atom::new(raw),
raw: Atom::new(&*raw),
});
}

View File

@ -6,6 +6,7 @@ use std::{borrow::Cow, fmt::Write};
use either::Either;
use num_bigint::BigInt as BigIntValue;
use smartstring::{LazyCompact, SmartString};
use swc_common::SyntaxContext;
use tracing::trace;
@ -45,8 +46,8 @@ impl<'a> Lexer<'a> {
}
let start = self.cur_pos();
let mut raw_val = String::new();
let mut raw_str = String::new();
let mut raw_val = SmartString::<LazyCompact>::new();
let mut raw_str = SmartString::<LazyCompact>::new();
let val = if starts_with_dot {
// first char is '.'
@ -64,7 +65,7 @@ impl<'a> Lexer<'a> {
return Ok(Either::Right((
Box::new(s.into_value()),
self.atoms.borrow_mut().intern(raw),
self.atoms.borrow_mut().intern(&*raw),
)));
}
@ -85,7 +86,7 @@ impl<'a> Lexer<'a> {
if start.0 != self.last_pos().0 - 1 {
// `-1` is utf 8 length of `0`
return self.make_legacy_octal(start, 0f64).map(|value| {
Either::Left((value, self.atoms.borrow_mut().intern(raw)))
Either::Left((value, self.atoms.borrow_mut().intern(&*raw)))
});
}
} else {
@ -114,7 +115,7 @@ impl<'a> Lexer<'a> {
});
return self.make_legacy_octal(start, val).map(|value| {
Either::Left((value, self.atoms.borrow_mut().intern(raw)))
Either::Left((value, self.atoms.borrow_mut().intern(&*raw)))
});
}
}
@ -142,7 +143,7 @@ impl<'a> Lexer<'a> {
debug_assert!(self.cur().unwrap().is_ascii_digit());
}
let mut raw = Raw(Some(String::new()));
let mut raw = Raw(Some(Default::default()));
// Read numbers after dot
let dec_val = self.read_int::<10>(0, &mut raw)?;
@ -157,7 +158,7 @@ impl<'a> Lexer<'a> {
if raw_val.contains('_') {
Cow::Owned(raw_val.replace('_', ""))
} else {
Cow::Borrowed(&raw_val)
Cow::Borrowed(&*raw_val)
}
.parse()
.expect("failed to parse float using rust's impl")
@ -195,7 +196,7 @@ impl<'a> Lexer<'a> {
true
};
let mut raw = Raw(Some(String::new()));
let mut raw = Raw(Some(Default::default()));
let exp = self.read_number_no_dot::<10>(&mut raw)?;
raw_str.push_str(&raw.0.take().unwrap());
@ -216,7 +217,7 @@ impl<'a> Lexer<'a> {
if raw_val.contains('_') {
Cow::Owned(raw_val.replace('_', ""))
} else {
Cow::Borrowed(&raw_val)
Cow::Borrowed(&*raw_val)
}
.parse()
.expect("failed to parse float literal")
@ -227,7 +228,10 @@ impl<'a> Lexer<'a> {
self.ensure_not_ident()?;
Ok(Either::Left((val, self.atoms.borrow_mut().intern(raw_str))))
Ok(Either::Left((
val,
self.atoms.borrow_mut().intern(&*raw_str),
)))
}
/// Returns `Left(value)` or `Right(BigInt)`
@ -313,7 +317,7 @@ impl<'a> Lexer<'a> {
/// Returned bool is `true` is there was `8` or `9`.
fn read_number_no_dot_as_str<const RADIX: u8, const FORMAT: u128>(
&mut self,
) -> LexResult<(f64, LazyBigInt<RADIX>, String, bool)> {
) -> LexResult<(f64, LazyBigInt<RADIX>, SmartString<LazyCompact>, bool)> {
debug_assert!(
RADIX == 2 || RADIX == 8 || RADIX == 10 || RADIX == 16,
"radix for read_number_no_dot should be one of 2, 8, 10, 16, but got {}",
@ -324,7 +328,7 @@ impl<'a> Lexer<'a> {
let mut non_octal = false;
let mut read_any = false;
let mut raw = Raw(Some(String::new()));
let mut raw = Raw(Some(Default::default()));
self.read_digits::<_, f64, RADIX>(
|total, radix, v| {

View File

@ -4,6 +4,7 @@
//! [babylon/util/identifier.js]:https://github.com/babel/babel/blob/master/packages/babylon/src/util/identifier.js
use std::char;
use smartstring::{LazyCompact, SmartString};
use swc_common::{
comments::{Comment, CommentKind},
BytePos, Span, SyntaxContext,
@ -21,7 +22,7 @@ use crate::{
/// Collector for raw string.
///
/// Methods of this struct is noop if the value is [None].
pub(super) struct Raw(pub Option<String>);
pub(super) struct Raw(pub Option<SmartString<LazyCompact>>);
impl Raw {
#[inline]