use std::{io::Read as _, sync::LazyLock};
use arcstr::ArcStr;
use flate2::read::DeflateDecoder;
use phf::{Map, phf_map};
pub const RUNTIME_HELPER_PREFIX: &str = "@oxc-project+runtime@0.159.0/helpers/";
pub const RUNTIME_HELPER_UNVERSIONED_PREFIX: &str = "@oxc-project/runtime/helpers/";
const UNCOMPRESSED_HELPERS_LEN: usize = 205624;
static COMPRESSED_HELPERS: &[u8] = include_bytes!("embedded_helpers.deflate");
static HELPER_SLOTS: Map<&'static str, u16> = phf_map! {
"esm/AwaitValue" => 0,
"esm/OverloadYield" => 1,
"esm/applyDecoratedDescriptor" => 2,
"esm/applyDecs" => 3,
"esm/applyDecs2203" => 4,
"esm/applyDecs2203R" => 5,
"esm/applyDecs2301" => 6,
"esm/applyDecs2305" => 7,
"esm/applyDecs2311" => 8,
"esm/arrayLikeToArray" => 9,
"esm/arrayWithHoles" => 10,
"esm/arrayWithoutHoles" => 11,
"esm/assertClassBrand" => 12,
"esm/assertThisInitialized" => 13,
"esm/asyncGeneratorDelegate" => 14,
"esm/asyncIterator" => 15,
"esm/asyncToGenerator" => 16,
"esm/awaitAsyncGenerator" => 17,
"esm/callSuper" => 18,
"esm/checkInRHS" => 19,
"esm/checkPrivateRedeclaration" => 20,
"esm/classApplyDescriptorDestructureSet" => 21,
"esm/classApplyDescriptorGet" => 22,
"esm/classApplyDescriptorSet" => 23,
"esm/classCallCheck" => 24,
"esm/classCheckPrivateStaticAccess" => 25,
"esm/classCheckPrivateStaticFieldDescriptor" => 26,
"esm/classExtractFieldDescriptor" => 27,
"esm/classNameTDZError" => 28,
"esm/classPrivateFieldDestructureSet" => 29,
"esm/classPrivateFieldGet" => 30,
"esm/classPrivateFieldGet2" => 31,
"esm/classPrivateFieldInitSpec" => 32,
"esm/classPrivateFieldLooseBase" => 33,
"esm/classPrivateFieldLooseKey" => 34,
"esm/classPrivateFieldSet" => 35,
"esm/classPrivateFieldSet2" => 36,
"esm/classPrivateGetter" => 37,
"esm/classPrivateMethodGet" => 38,
"esm/classPrivateMethodInitSpec" => 39,
"esm/classPrivateMethodSet" => 40,
"esm/classPrivateSetter" => 41,
"esm/classStaticPrivateFieldDestructureSet" => 42,
"esm/classStaticPrivateFieldSpecGet" => 43,
"esm/classStaticPrivateFieldSpecSet" => 44,
"esm/classStaticPrivateMethodGet" => 45,
"esm/classStaticPrivateMethodSet" => 46,
"esm/construct" => 47,
"esm/createClass" => 48,
"esm/createForOfIteratorHelper" => 49,
"esm/createForOfIteratorHelperLoose" => 50,
"esm/createSuper" => 51,
"esm/decorate" => 52,
"esm/decorateMetadata" => 53,
"esm/decorateParam" => 54,
"esm/defaults" => 55,
"esm/defineAccessor" => 56,
"esm/defineEnumerableProperties" => 57,
"esm/defineProperty" => 58,
"esm/dispose" => 59,
"esm/extends" => 60,
"esm/get" => 61,
"esm/getPrototypeOf" => 62,
"esm/identity" => 63,
"esm/importDeferProxy" => 64,
"esm/inherits" => 65,
"esm/inheritsLoose" => 66,
"esm/initializerDefineProperty" => 67,
"esm/initializerWarningHelper" => 68,
"esm/instanceof" => 69,
"esm/interopRequireDefault" => 70,
"esm/interopRequireWildcard" => 71,
"esm/isNativeFunction" => 72,
"esm/isNativeReflectConstruct" => 73,
"esm/iterableToArray" => 74,
"esm/iterableToArrayLimit" => 75,
"esm/jsx" => 76,
"esm/maybeArrayLike" => 77,
"esm/newArrowCheck" => 78,
"esm/nonIterableRest" => 79,
"esm/nonIterableSpread" => 80,
"esm/nullishReceiverError" => 81,
"esm/objectDestructuringEmpty" => 82,
"esm/objectSpread" => 83,
"esm/objectSpread2" => 84,
"esm/objectWithoutProperties" => 85,
"esm/objectWithoutPropertiesLoose" => 86,
"esm/possibleConstructorReturn" => 87,
"esm/readOnlyError" => 88,
"esm/regenerator" => 89,
"esm/regeneratorAsync" => 90,
"esm/regeneratorAsyncGen" => 91,
"esm/regeneratorAsyncIterator" => 92,
"esm/regeneratorDefine" => 93,
"esm/regeneratorKeys" => 94,
"esm/regeneratorRuntime" => 95,
"esm/regeneratorValues" => 96,
"esm/set" => 97,
"esm/setFunctionName" => 98,
"esm/setPrototypeOf" => 99,
"esm/skipFirstGeneratorNext" => 100,
"esm/slicedToArray" => 101,
"esm/superPropBase" => 102,
"esm/superPropGet" => 103,
"esm/superPropSet" => 104,
"esm/taggedTemplateLiteral" => 105,
"esm/taggedTemplateLiteralLoose" => 106,
"esm/tdz" => 107,
"esm/temporalRef" => 108,
"esm/temporalUndefined" => 109,
"esm/toArray" => 110,
"esm/toConsumableArray" => 111,
"esm/toPrimitive" => 112,
"esm/toPropertyKey" => 113,
"esm/toSetter" => 114,
"esm/tsRewriteRelativeImportExtensions" => 115,
"esm/typeof" => 116,
"esm/unsupportedIterableToArray" => 117,
"esm/using" => 118,
"esm/usingCtx" => 119,
"esm/wrapAsyncGenerator" => 120,
"esm/wrapNativeSuper" => 121,
"esm/wrapRegExp" => 122,
"esm/writeOnlyError" => 123,
"AwaitValue" => 124,
"OverloadYield" => 125,
"applyDecoratedDescriptor" => 126,
"applyDecs" => 127,
"applyDecs2203" => 128,
"applyDecs2203R" => 129,
"applyDecs2301" => 130,
"applyDecs2305" => 131,
"applyDecs2311" => 132,
"arrayLikeToArray" => 133,
"arrayWithHoles" => 134,
"arrayWithoutHoles" => 135,
"assertClassBrand" => 136,
"assertThisInitialized" => 137,
"asyncGeneratorDelegate" => 138,
"asyncIterator" => 139,
"asyncToGenerator" => 140,
"awaitAsyncGenerator" => 141,
"callSuper" => 142,
"checkInRHS" => 143,
"checkPrivateRedeclaration" => 144,
"classApplyDescriptorDestructureSet" => 145,
"classApplyDescriptorGet" => 146,
"classApplyDescriptorSet" => 147,
"classCallCheck" => 148,
"classCheckPrivateStaticAccess" => 149,
"classCheckPrivateStaticFieldDescriptor" => 150,
"classExtractFieldDescriptor" => 151,
"classNameTDZError" => 152,
"classPrivateFieldDestructureSet" => 153,
"classPrivateFieldGet" => 154,
"classPrivateFieldGet2" => 155,
"classPrivateFieldInitSpec" => 156,
"classPrivateFieldLooseBase" => 157,
"classPrivateFieldLooseKey" => 158,
"classPrivateFieldSet" => 159,
"classPrivateFieldSet2" => 160,
"classPrivateGetter" => 161,
"classPrivateMethodGet" => 162,
"classPrivateMethodInitSpec" => 163,
"classPrivateMethodSet" => 164,
"classPrivateSetter" => 165,
"classStaticPrivateFieldDestructureSet" => 166,
"classStaticPrivateFieldSpecGet" => 167,
"classStaticPrivateFieldSpecSet" => 168,
"classStaticPrivateMethodGet" => 169,
"classStaticPrivateMethodSet" => 170,
"construct" => 171,
"createClass" => 172,
"createForOfIteratorHelper" => 173,
"createForOfIteratorHelperLoose" => 174,
"createSuper" => 175,
"decorate" => 176,
"decorateMetadata" => 177,
"decorateParam" => 178,
"defaults" => 179,
"defineAccessor" => 180,
"defineEnumerableProperties" => 181,
"defineProperty" => 182,
"dispose" => 183,
"extends" => 184,
"get" => 185,
"getPrototypeOf" => 186,
"identity" => 187,
"importDeferProxy" => 188,
"inherits" => 189,
"inheritsLoose" => 190,
"initializerDefineProperty" => 191,
"initializerWarningHelper" => 192,
"instanceof" => 193,
"interopRequireDefault" => 194,
"interopRequireWildcard" => 195,
"isNativeFunction" => 196,
"isNativeReflectConstruct" => 197,
"iterableToArray" => 198,
"iterableToArrayLimit" => 199,
"jsx" => 200,
"maybeArrayLike" => 201,
"newArrowCheck" => 202,
"nonIterableRest" => 203,
"nonIterableSpread" => 204,
"nullishReceiverError" => 205,
"objectDestructuringEmpty" => 206,
"objectSpread" => 207,
"objectSpread2" => 208,
"objectWithoutProperties" => 209,
"objectWithoutPropertiesLoose" => 210,
"possibleConstructorReturn" => 211,
"readOnlyError" => 212,
"regenerator" => 213,
"regeneratorAsync" => 214,
"regeneratorAsyncGen" => 215,
"regeneratorAsyncIterator" => 216,
"regeneratorDefine" => 217,
"regeneratorKeys" => 218,
"regeneratorRuntime" => 219,
"regeneratorValues" => 220,
"set" => 221,
"setFunctionName" => 222,
"setPrototypeOf" => 223,
"skipFirstGeneratorNext" => 224,
"slicedToArray" => 225,
"superPropBase" => 226,
"superPropGet" => 227,
"superPropSet" => 228,
"taggedTemplateLiteral" => 229,
"taggedTemplateLiteralLoose" => 230,
"tdz" => 231,
"temporalRef" => 232,
"temporalUndefined" => 233,
"toArray" => 234,
"toConsumableArray" => 235,
"toPrimitive" => 236,
"toPropertyKey" => 237,
"toSetter" => 238,
"tsRewriteRelativeImportExtensions" => 239,
"typeof" => 240,
"unsupportedIterableToArray" => 241,
"using" => 242,
"usingCtx" => 243,
"wrapAsyncGenerator" => 244,
"wrapNativeSuper" => 245,
"wrapRegExp" => 246,
"writeOnlyError" => 247,
};
static HELPER_RANGES: &[(u32, u32)] = &[
(0, 82),
(82, 179),
(179, 759),
(759, 9026),
(9026, 15070),
(15070, 21468),
(21468, 28766),
(28766, 33757),
(33757, 38250),
(38250, 38445),
(38445, 38703),
(38703, 38885),
(38885, 39125),
(39125, 39328),
(39328, 40093),
(40093, 41579),
(41579, 42207),
(42207, 42369),
(42369, 42796),
(42796, 43035),
(43035, 43233),
(43233, 43570),
(43570, 43703),
(43703, 43941),
(43941, 44097),
(44097, 44293),
(44293, 44525),
(44525, 44726),
(44726, 44899),
(44899, 45250),
(45250, 45546),
(45546, 45727),
(45727, 45945),
(45945, 46152),
(46152, 46286),
(46286, 46591),
(46591, 46781),
(46781, 46955),
(46955, 47135),
(47135, 47349),
(47349, 47495),
(47495, 47678),
(47678, 48167),
(48167, 48609),
(48609, 49060),
(49060, 49252),
(49252, 49421),
(49421, 49817),
(49817, 50324),
(50324, 51673),
(51673, 52423),
(52423, 52980),
(52980, 53764),
(53764, 54100),
(54100, 54417),
(54417, 54713),
(54713, 54901),
(54901, 55408),
(55408, 55694),
(55694, 56595),
(56595, 56931),
(56931, 57343),
(57343, 57587),
(57587, 57657),
(57657, 58424),
(58424, 58884),
(58884, 59100),
(59100, 59392),
(59392, 59635),
(59635, 59823),
(59823, 59964),
(59964, 60570),
(60570, 60777),
(60777, 61085),
(61085, 61492),
(61492, 62347),
(62347, 63091),
(63091, 63391),
(63391, 63538),
(63538, 63773),
(63773, 64007),
(64007, 64157),
(64157, 64312),
(64312, 64845),
(64845, 65688),
(65688, 66165),
(66165, 66435),
(66435, 66838),
(66838, 66957),
(66957, 70608),
(70608, 70884),
(70884, 71172),
(71172, 72188),
(72188, 72758),
(72758, 73034),
(73034, 83881),
(83881, 84432),
(84432, 85206),
(85206, 85545),
(85545, 85777),
(85777, 85953),
(85953, 86306),
(86306, 86517),
(86517, 86825),
(86825, 87047),
(87047, 87263),
(87263, 87406),
(87406, 87536),
(87536, 87734),
(87734, 87808),
(87808, 88125),
(88125, 88548),
(88548, 88989),
(88989, 89216),
(89216, 89431),
(89431, 89785),
(89785, 90151),
(90151, 90648),
(90648, 91170),
(91170, 92903),
(92903, 94506),
(94506, 95490),
(95490, 97291),
(97291, 97413),
(97413, 97568),
(97568, 97738),
(97738, 98391),
(98391, 106751),
(106751, 112882),
(112882, 119468),
(119468, 126957),
(126957, 132044),
(132044, 136633),
(136633, 136901),
(136901, 137232),
(137232, 137490),
(137490, 137803),
(137803, 138079),
(138079, 138920),
(138920, 140479),
(140479, 141180),
(141180, 141418),
(141418, 141927),
(141927, 142253),
(142253, 142524),
(142524, 142934),
(142934, 143140),
(143140, 143451),
(143451, 143680),
(143680, 143952),
(143952, 144257),
(144257, 144534),
(144534, 144780),
(144780, 145210),
(145210, 145585),
(145585, 145842),
(145842, 146136),
(146136, 146416),
(146416, 146623),
(146623, 147007),
(147007, 147273),
(147273, 147523),
(147523, 147779),
(147779, 148069),
(148069, 148288),
(148288, 148547),
(148547, 149118),
(149118, 149642),
(149642, 150175),
(150175, 150443),
(150443, 150685),
(150685, 151160),
(151160, 151743),
(151743, 153168),
(153168, 153994),
(153994, 154633),
(154633, 155500),
(155500, 155919),
(155919, 156319),
(156319, 156688),
(156688, 156949),
(156949, 157529),
(157529, 157891),
(157891, 158865),
(158865, 159369),
(159369, 159952),
(159952, 160364),
(160364, 160507),
(160507, 161347),
(161347, 161883),
(161883, 162175),
(162175, 162540),
(162540, 162856),
(162856, 163117),
(163117, 163331),
(163331, 164010),
(164010, 164290),
(164290, 164766),
(164766, 165246),
(165246, 166174),
(166174, 166991),
(166991, 167367),
(167367, 167587),
(167587, 167895),
(167895, 168202),
(168202, 168425),
(168425, 168653),
(168653, 169262),
(169262, 170181),
(170181, 170734),
(170734, 171077),
(171077, 171570),
(171570, 171762),
(171762, 175584),
(175584, 175936),
(175936, 176303),
(176303, 177398),
(177398, 178136),
(178136, 178485),
(178485, 189514),
(189514, 190152),
(190152, 191005),
(191005, 191431),
(191431, 191831),
(191831, 192080),
(192080, 192515),
(192515, 192802),
(192802, 193189),
(193189, 193490),
(193490, 193779),
(193779, 193995),
(193995, 194198),
(194198, 194475),
(194475, 194622),
(194622, 195021),
(195021, 195529),
(195529, 196057),
(196057, 196374),
(196374, 196662),
(196662, 197089),
(197089, 197623),
(197623, 198196),
(198196, 198791),
(198791, 200597),
(200597, 202276),
(202276, 203440),
(203440, 205429),
(205429, 205624),
];
static DECODED_HELPERS: LazyLock<Box<[ArcStr]>> = LazyLock::new(|| {
let mut decoder = DeflateDecoder::new(COMPRESSED_HELPERS);
let mut decoded = Vec::with_capacity(UNCOMPRESSED_HELPERS_LEN);
decoder.read_to_end(&mut decoded).expect("embedded Oxc runtime helpers should decompress");
assert_eq!(decoded.len(), UNCOMPRESSED_HELPERS_LEN, "embedded Oxc runtime helper length");
let decoded = String::from_utf8(decoded).expect("embedded Oxc runtime helpers should be UTF-8");
HELPER_RANGES
.iter()
.map(|&(start, end)| ArcStr::from(&decoded[start as usize..end as usize]))
.collect()
});
pub fn get_helper_content(specifier: &str) -> Option<ArcStr> {
let helper_path = specifier.strip_prefix(RUNTIME_HELPER_PREFIX)?;
let helper_path = helper_path.strip_suffix(".js").unwrap_or(helper_path);
let slot = HELPER_SLOTS.get(helper_path)?;
Some(DECODED_HELPERS[*slot as usize].clone())
}
pub fn is_runtime_helper(specifier: &str) -> bool {
specifier.starts_with(RUNTIME_HELPER_UNVERSIONED_PREFIX)
}
pub fn is_virtual_runtime_helper(specifier: &str) -> bool {
specifier.starts_with(RUNTIME_HELPER_PREFIX)
}