typescript 5.5.0-dev.20240424 → 5.5.0-dev.20240426

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/typescript.js CHANGED
@@ -1894,7 +1894,6 @@ __export(typescript_exports, {
1894
1894
  loadWithModeAwareCache: () => loadWithModeAwareCache,
1895
1895
  makeIdentifierFromModuleName: () => makeIdentifierFromModuleName,
1896
1896
  makeImport: () => makeImport,
1897
- makeImportIfNecessary: () => makeImportIfNecessary,
1898
1897
  makeStringLiteral: () => makeStringLiteral,
1899
1898
  mangleScopedPackageName: () => mangleScopedPackageName,
1900
1899
  map: () => map,
@@ -2361,7 +2360,7 @@ module.exports = __toCommonJS(typescript_exports);
2361
2360
 
2362
2361
  // src/compiler/corePublic.ts
2363
2362
  var versionMajorMinor = "5.5";
2364
- var version = `${versionMajorMinor}.0-dev.20240424`;
2363
+ var version = `${versionMajorMinor}.0-dev.20240426`;
2365
2364
  var Comparison = /* @__PURE__ */ ((Comparison3) => {
2366
2365
  Comparison3[Comparison3["LessThan"] = -1] = "LessThan";
2367
2366
  Comparison3[Comparison3["EqualTo"] = 0] = "EqualTo";
@@ -7285,12 +7284,15 @@ var LanguageFeatureMinimumTarget = /* @__PURE__ */ ((LanguageFeatureMinimumTarge
7285
7284
  LanguageFeatureMinimumTarget2[LanguageFeatureMinimumTarget2["ArrowFunctions"] = 2 /* ES2015 */] = "ArrowFunctions";
7286
7285
  LanguageFeatureMinimumTarget2[LanguageFeatureMinimumTarget2["BlockScopedVariables"] = 2 /* ES2015 */] = "BlockScopedVariables";
7287
7286
  LanguageFeatureMinimumTarget2[LanguageFeatureMinimumTarget2["ObjectAssign"] = 2 /* ES2015 */] = "ObjectAssign";
7287
+ LanguageFeatureMinimumTarget2[LanguageFeatureMinimumTarget2["RegularExpressionFlagsUnicode"] = 2 /* ES2015 */] = "RegularExpressionFlagsUnicode";
7288
+ LanguageFeatureMinimumTarget2[LanguageFeatureMinimumTarget2["RegularExpressionFlagsSticky"] = 2 /* ES2015 */] = "RegularExpressionFlagsSticky";
7288
7289
  LanguageFeatureMinimumTarget2[LanguageFeatureMinimumTarget2["Exponentiation"] = 3 /* ES2016 */] = "Exponentiation";
7289
7290
  LanguageFeatureMinimumTarget2[LanguageFeatureMinimumTarget2["AsyncFunctions"] = 4 /* ES2017 */] = "AsyncFunctions";
7290
7291
  LanguageFeatureMinimumTarget2[LanguageFeatureMinimumTarget2["ForAwaitOf"] = 5 /* ES2018 */] = "ForAwaitOf";
7291
7292
  LanguageFeatureMinimumTarget2[LanguageFeatureMinimumTarget2["AsyncGenerators"] = 5 /* ES2018 */] = "AsyncGenerators";
7292
7293
  LanguageFeatureMinimumTarget2[LanguageFeatureMinimumTarget2["AsyncIteration"] = 5 /* ES2018 */] = "AsyncIteration";
7293
7294
  LanguageFeatureMinimumTarget2[LanguageFeatureMinimumTarget2["ObjectSpreadRest"] = 5 /* ES2018 */] = "ObjectSpreadRest";
7295
+ LanguageFeatureMinimumTarget2[LanguageFeatureMinimumTarget2["RegularExpressionFlagsDotAll"] = 5 /* ES2018 */] = "RegularExpressionFlagsDotAll";
7294
7296
  LanguageFeatureMinimumTarget2[LanguageFeatureMinimumTarget2["BindinglessCatch"] = 6 /* ES2019 */] = "BindinglessCatch";
7295
7297
  LanguageFeatureMinimumTarget2[LanguageFeatureMinimumTarget2["BigInt"] = 7 /* ES2020 */] = "BigInt";
7296
7298
  LanguageFeatureMinimumTarget2[LanguageFeatureMinimumTarget2["NullishCoalesce"] = 7 /* ES2020 */] = "NullishCoalesce";
@@ -7299,9 +7301,11 @@ var LanguageFeatureMinimumTarget = /* @__PURE__ */ ((LanguageFeatureMinimumTarge
7299
7301
  LanguageFeatureMinimumTarget2[LanguageFeatureMinimumTarget2["TopLevelAwait"] = 9 /* ES2022 */] = "TopLevelAwait";
7300
7302
  LanguageFeatureMinimumTarget2[LanguageFeatureMinimumTarget2["ClassFields"] = 9 /* ES2022 */] = "ClassFields";
7301
7303
  LanguageFeatureMinimumTarget2[LanguageFeatureMinimumTarget2["PrivateNamesAndClassStaticBlocks"] = 9 /* ES2022 */] = "PrivateNamesAndClassStaticBlocks";
7304
+ LanguageFeatureMinimumTarget2[LanguageFeatureMinimumTarget2["RegularExpressionFlagsHasIndices"] = 9 /* ES2022 */] = "RegularExpressionFlagsHasIndices";
7302
7305
  LanguageFeatureMinimumTarget2[LanguageFeatureMinimumTarget2["ShebangComments"] = 99 /* ESNext */] = "ShebangComments";
7303
7306
  LanguageFeatureMinimumTarget2[LanguageFeatureMinimumTarget2["UsingAndAwaitUsing"] = 99 /* ESNext */] = "UsingAndAwaitUsing";
7304
7307
  LanguageFeatureMinimumTarget2[LanguageFeatureMinimumTarget2["ClassAndClassElementDecorators"] = 99 /* ESNext */] = "ClassAndClassElementDecorators";
7308
+ LanguageFeatureMinimumTarget2[LanguageFeatureMinimumTarget2["RegularExpressionFlagsUnicodeSets"] = 99 /* ESNext */] = "RegularExpressionFlagsUnicodeSets";
7305
7309
  return LanguageFeatureMinimumTarget2;
7306
7310
  })(LanguageFeatureMinimumTarget || {});
7307
7311
  var ExternalEmitHelpers = /* @__PURE__ */ ((ExternalEmitHelpers2) => {
@@ -9813,8 +9817,8 @@ var Diagnostics = {
9813
9817
  Unicode_property_value_expressions_are_only_available_when_the_Unicode_u_flag_or_the_Unicode_Sets_v_flag_is_set: diag(1530, 1 /* Error */, "Unicode_property_value_expressions_are_only_available_when_the_Unicode_u_flag_or_the_Unicode_Sets_v__1530", "Unicode property value expressions are only available when the Unicode (u) flag or the Unicode Sets (v) flag is set."),
9814
9818
  _0_must_be_followed_by_a_Unicode_property_value_expression_enclosed_in_braces: diag(1531, 1 /* Error */, "_0_must_be_followed_by_a_Unicode_property_value_expression_enclosed_in_braces_1531", "'\\{0}' must be followed by a Unicode property value expression enclosed in braces."),
9815
9819
  There_is_no_capturing_group_named_0_in_this_regular_expression: diag(1532, 1 /* Error */, "There_is_no_capturing_group_named_0_in_this_regular_expression_1532", "There is no capturing group named '{0}' in this regular expression."),
9816
- A_decimal_escape_must_refer_to_an_existent_capturing_group_There_are_only_0_capturing_groups_in_this_regular_expression: diag(1533, 1 /* Error */, "A_decimal_escape_must_refer_to_an_existent_capturing_group_There_are_only_0_capturing_groups_in_this_1533", "A decimal escape must refer to an existent capturing group. There are only {0} capturing groups in this regular expression."),
9817
- Decimal_escapes_are_invalid_when_there_are_no_capturing_groups_in_a_regular_expression: diag(1534, 1 /* Error */, "Decimal_escapes_are_invalid_when_there_are_no_capturing_groups_in_a_regular_expression_1534", "Decimal escapes are invalid when there are no capturing groups in a regular expression."),
9820
+ This_backreference_refers_to_a_group_that_does_not_exist_There_are_only_0_capturing_groups_in_this_regular_expression: diag(1533, 1 /* Error */, "This_backreference_refers_to_a_group_that_does_not_exist_There_are_only_0_capturing_groups_in_this_r_1533", "This backreference refers to a group that does not exist. There are only {0} capturing groups in this regular expression."),
9821
+ This_backreference_is_invalid_because_the_containing_regular_expression_contains_no_capturing_groups: diag(1534, 1 /* Error */, "This_backreference_is_invalid_because_the_containing_regular_expression_contains_no_capturing_groups_1534", "This backreference is invalid because the containing regular expression contains no capturing groups."),
9818
9822
  This_character_cannot_be_escaped_in_a_regular_expression: diag(1535, 1 /* Error */, "This_character_cannot_be_escaped_in_a_regular_expression_1535", "This character cannot be escaped in a regular expression."),
9819
9823
  The_types_of_0_are_incompatible_between_these_types: diag(2200, 1 /* Error */, "The_types_of_0_are_incompatible_between_these_types_2200", "The types of '{0}' are incompatible between these types."),
9820
9824
  The_types_returned_by_0_are_incompatible_between_these_types: diag(2201, 1 /* Error */, "The_types_returned_by_0_are_incompatible_between_these_types_2201", "The types returned by '{0}' are incompatible between these types."),
@@ -11716,14 +11720,11 @@ var charToRegExpFlag = new Map(Object.entries({
11716
11720
  y: 128 /* Sticky */
11717
11721
  }));
11718
11722
  var regExpFlagToFirstAvailableLanguageVersion = /* @__PURE__ */ new Map([
11719
- [1 /* HasIndices */, 9 /* ES2022 */],
11720
- [2 /* Global */, 0 /* ES3 */],
11721
- [4 /* IgnoreCase */, 0 /* ES3 */],
11722
- [8 /* Multiline */, 0 /* ES3 */],
11723
- [16 /* DotAll */, 5 /* ES2018 */],
11724
- [32 /* Unicode */, 2 /* ES2015 */],
11725
- [64 /* UnicodeSets */, 99 /* ESNext */],
11726
- [128 /* Sticky */, 2 /* ES2015 */]
11723
+ [1 /* HasIndices */, 9 /* RegularExpressionFlagsHasIndices */],
11724
+ [16 /* DotAll */, 5 /* RegularExpressionFlagsDotAll */],
11725
+ [32 /* Unicode */, 2 /* RegularExpressionFlagsUnicode */],
11726
+ [64 /* UnicodeSets */, 99 /* RegularExpressionFlagsUnicodeSets */],
11727
+ [128 /* Sticky */, 2 /* RegularExpressionFlagsSticky */]
11727
11728
  ]);
11728
11729
  var unicodeES5IdentifierStart = [170, 170, 181, 181, 186, 186, 192, 214, 216, 246, 248, 705, 710, 721, 736, 740, 748, 748, 750, 750, 880, 884, 886, 887, 890, 893, 902, 902, 904, 906, 908, 908, 910, 929, 931, 1013, 1015, 1153, 1162, 1319, 1329, 1366, 1369, 1369, 1377, 1415, 1488, 1514, 1520, 1522, 1568, 1610, 1646, 1647, 1649, 1747, 1749, 1749, 1765, 1766, 1774, 1775, 1786, 1788, 1791, 1791, 1808, 1808, 1810, 1839, 1869, 1957, 1969, 1969, 1994, 2026, 2036, 2037, 2042, 2042, 2048, 2069, 2074, 2074, 2084, 2084, 2088, 2088, 2112, 2136, 2208, 2208, 2210, 2220, 2308, 2361, 2365, 2365, 2384, 2384, 2392, 2401, 2417, 2423, 2425, 2431, 2437, 2444, 2447, 2448, 2451, 2472, 2474, 2480, 2482, 2482, 2486, 2489, 2493, 2493, 2510, 2510, 2524, 2525, 2527, 2529, 2544, 2545, 2565, 2570, 2575, 2576, 2579, 2600, 2602, 2608, 2610, 2611, 2613, 2614, 2616, 2617, 2649, 2652, 2654, 2654, 2674, 2676, 2693, 2701, 2703, 2705, 2707, 2728, 2730, 2736, 2738, 2739, 2741, 2745, 2749, 2749, 2768, 2768, 2784, 2785, 2821, 2828, 2831, 2832, 2835, 2856, 2858, 2864, 2866, 2867, 2869, 2873, 2877, 2877, 2908, 2909, 2911, 2913, 2929, 2929, 2947, 2947, 2949, 2954, 2958, 2960, 2962, 2965, 2969, 2970, 2972, 2972, 2974, 2975, 2979, 2980, 2984, 2986, 2990, 3001, 3024, 3024, 3077, 3084, 3086, 3088, 3090, 3112, 3114, 3123, 3125, 3129, 3133, 3133, 3160, 3161, 3168, 3169, 3205, 3212, 3214, 3216, 3218, 3240, 3242, 3251, 3253, 3257, 3261, 3261, 3294, 3294, 3296, 3297, 3313, 3314, 3333, 3340, 3342, 3344, 3346, 3386, 3389, 3389, 3406, 3406, 3424, 3425, 3450, 3455, 3461, 3478, 3482, 3505, 3507, 3515, 3517, 3517, 3520, 3526, 3585, 3632, 3634, 3635, 3648, 3654, 3713, 3714, 3716, 3716, 3719, 3720, 3722, 3722, 3725, 3725, 3732, 3735, 3737, 3743, 3745, 3747, 3749, 3749, 3751, 3751, 3754, 3755, 3757, 3760, 3762, 3763, 3773, 3773, 3776, 3780, 3782, 3782, 3804, 3807, 3840, 3840, 3904, 3911, 3913, 3948, 3976, 3980, 4096, 4138, 4159, 4159, 4176, 4181, 4186, 4189, 4193, 4193, 4197, 4198, 4206, 4208, 4213, 4225, 4238, 4238, 4256, 4293, 4295, 4295, 4301, 4301, 4304, 4346, 4348, 4680, 4682, 4685, 4688, 4694, 4696, 4696, 4698, 4701, 4704, 4744, 4746, 4749, 4752, 4784, 4786, 4789, 4792, 4798, 4800, 4800, 4802, 4805, 4808, 4822, 4824, 4880, 4882, 4885, 4888, 4954, 4992, 5007, 5024, 5108, 5121, 5740, 5743, 5759, 5761, 5786, 5792, 5866, 5870, 5872, 5888, 5900, 5902, 5905, 5920, 5937, 5952, 5969, 5984, 5996, 5998, 6e3, 6016, 6067, 6103, 6103, 6108, 6108, 6176, 6263, 6272, 6312, 6314, 6314, 6320, 6389, 6400, 6428, 6480, 6509, 6512, 6516, 6528, 6571, 6593, 6599, 6656, 6678, 6688, 6740, 6823, 6823, 6917, 6963, 6981, 6987, 7043, 7072, 7086, 7087, 7098, 7141, 7168, 7203, 7245, 7247, 7258, 7293, 7401, 7404, 7406, 7409, 7413, 7414, 7424, 7615, 7680, 7957, 7960, 7965, 7968, 8005, 8008, 8013, 8016, 8023, 8025, 8025, 8027, 8027, 8029, 8029, 8031, 8061, 8064, 8116, 8118, 8124, 8126, 8126, 8130, 8132, 8134, 8140, 8144, 8147, 8150, 8155, 8160, 8172, 8178, 8180, 8182, 8188, 8305, 8305, 8319, 8319, 8336, 8348, 8450, 8450, 8455, 8455, 8458, 8467, 8469, 8469, 8473, 8477, 8484, 8484, 8486, 8486, 8488, 8488, 8490, 8493, 8495, 8505, 8508, 8511, 8517, 8521, 8526, 8526, 8544, 8584, 11264, 11310, 11312, 11358, 11360, 11492, 11499, 11502, 11506, 11507, 11520, 11557, 11559, 11559, 11565, 11565, 11568, 11623, 11631, 11631, 11648, 11670, 11680, 11686, 11688, 11694, 11696, 11702, 11704, 11710, 11712, 11718, 11720, 11726, 11728, 11734, 11736, 11742, 11823, 11823, 12293, 12295, 12321, 12329, 12337, 12341, 12344, 12348, 12353, 12438, 12445, 12447, 12449, 12538, 12540, 12543, 12549, 12589, 12593, 12686, 12704, 12730, 12784, 12799, 13312, 19893, 19968, 40908, 40960, 42124, 42192, 42237, 42240, 42508, 42512, 42527, 42538, 42539, 42560, 42606, 42623, 42647, 42656, 42735, 42775, 42783, 42786, 42888, 42891, 42894, 42896, 42899, 42912, 42922, 43e3, 43009, 43011, 43013, 43015, 43018, 43020, 43042, 43072, 43123, 43138, 43187, 43250, 43255, 43259, 43259, 43274, 43301, 43312, 43334, 43360, 43388, 43396, 43442, 43471, 43471, 43520, 43560, 43584, 43586, 43588, 43595, 43616, 43638, 43642, 43642, 43648, 43695, 43697, 43697, 43701, 43702, 43705, 43709, 43712, 43712, 43714, 43714, 43739, 43741, 43744, 43754, 43762, 43764, 43777, 43782, 43785, 43790, 43793, 43798, 43808, 43814, 43816, 43822, 43968, 44002, 44032, 55203, 55216, 55238, 55243, 55291, 63744, 64109, 64112, 64217, 64256, 64262, 64275, 64279, 64285, 64285, 64287, 64296, 64298, 64310, 64312, 64316, 64318, 64318, 64320, 64321, 64323, 64324, 64326, 64433, 64467, 64829, 64848, 64911, 64914, 64967, 65008, 65019, 65136, 65140, 65142, 65276, 65313, 65338, 65345, 65370, 65382, 65470, 65474, 65479, 65482, 65487, 65490, 65495, 65498, 65500];
11729
11730
  var unicodeES5IdentifierPart = [170, 170, 181, 181, 186, 186, 192, 214, 216, 246, 248, 705, 710, 721, 736, 740, 748, 748, 750, 750, 768, 884, 886, 887, 890, 893, 902, 902, 904, 906, 908, 908, 910, 929, 931, 1013, 1015, 1153, 1155, 1159, 1162, 1319, 1329, 1366, 1369, 1369, 1377, 1415, 1425, 1469, 1471, 1471, 1473, 1474, 1476, 1477, 1479, 1479, 1488, 1514, 1520, 1522, 1552, 1562, 1568, 1641, 1646, 1747, 1749, 1756, 1759, 1768, 1770, 1788, 1791, 1791, 1808, 1866, 1869, 1969, 1984, 2037, 2042, 2042, 2048, 2093, 2112, 2139, 2208, 2208, 2210, 2220, 2276, 2302, 2304, 2403, 2406, 2415, 2417, 2423, 2425, 2431, 2433, 2435, 2437, 2444, 2447, 2448, 2451, 2472, 2474, 2480, 2482, 2482, 2486, 2489, 2492, 2500, 2503, 2504, 2507, 2510, 2519, 2519, 2524, 2525, 2527, 2531, 2534, 2545, 2561, 2563, 2565, 2570, 2575, 2576, 2579, 2600, 2602, 2608, 2610, 2611, 2613, 2614, 2616, 2617, 2620, 2620, 2622, 2626, 2631, 2632, 2635, 2637, 2641, 2641, 2649, 2652, 2654, 2654, 2662, 2677, 2689, 2691, 2693, 2701, 2703, 2705, 2707, 2728, 2730, 2736, 2738, 2739, 2741, 2745, 2748, 2757, 2759, 2761, 2763, 2765, 2768, 2768, 2784, 2787, 2790, 2799, 2817, 2819, 2821, 2828, 2831, 2832, 2835, 2856, 2858, 2864, 2866, 2867, 2869, 2873, 2876, 2884, 2887, 2888, 2891, 2893, 2902, 2903, 2908, 2909, 2911, 2915, 2918, 2927, 2929, 2929, 2946, 2947, 2949, 2954, 2958, 2960, 2962, 2965, 2969, 2970, 2972, 2972, 2974, 2975, 2979, 2980, 2984, 2986, 2990, 3001, 3006, 3010, 3014, 3016, 3018, 3021, 3024, 3024, 3031, 3031, 3046, 3055, 3073, 3075, 3077, 3084, 3086, 3088, 3090, 3112, 3114, 3123, 3125, 3129, 3133, 3140, 3142, 3144, 3146, 3149, 3157, 3158, 3160, 3161, 3168, 3171, 3174, 3183, 3202, 3203, 3205, 3212, 3214, 3216, 3218, 3240, 3242, 3251, 3253, 3257, 3260, 3268, 3270, 3272, 3274, 3277, 3285, 3286, 3294, 3294, 3296, 3299, 3302, 3311, 3313, 3314, 3330, 3331, 3333, 3340, 3342, 3344, 3346, 3386, 3389, 3396, 3398, 3400, 3402, 3406, 3415, 3415, 3424, 3427, 3430, 3439, 3450, 3455, 3458, 3459, 3461, 3478, 3482, 3505, 3507, 3515, 3517, 3517, 3520, 3526, 3530, 3530, 3535, 3540, 3542, 3542, 3544, 3551, 3570, 3571, 3585, 3642, 3648, 3662, 3664, 3673, 3713, 3714, 3716, 3716, 3719, 3720, 3722, 3722, 3725, 3725, 3732, 3735, 3737, 3743, 3745, 3747, 3749, 3749, 3751, 3751, 3754, 3755, 3757, 3769, 3771, 3773, 3776, 3780, 3782, 3782, 3784, 3789, 3792, 3801, 3804, 3807, 3840, 3840, 3864, 3865, 3872, 3881, 3893, 3893, 3895, 3895, 3897, 3897, 3902, 3911, 3913, 3948, 3953, 3972, 3974, 3991, 3993, 4028, 4038, 4038, 4096, 4169, 4176, 4253, 4256, 4293, 4295, 4295, 4301, 4301, 4304, 4346, 4348, 4680, 4682, 4685, 4688, 4694, 4696, 4696, 4698, 4701, 4704, 4744, 4746, 4749, 4752, 4784, 4786, 4789, 4792, 4798, 4800, 4800, 4802, 4805, 4808, 4822, 4824, 4880, 4882, 4885, 4888, 4954, 4957, 4959, 4992, 5007, 5024, 5108, 5121, 5740, 5743, 5759, 5761, 5786, 5792, 5866, 5870, 5872, 5888, 5900, 5902, 5908, 5920, 5940, 5952, 5971, 5984, 5996, 5998, 6e3, 6002, 6003, 6016, 6099, 6103, 6103, 6108, 6109, 6112, 6121, 6155, 6157, 6160, 6169, 6176, 6263, 6272, 6314, 6320, 6389, 6400, 6428, 6432, 6443, 6448, 6459, 6470, 6509, 6512, 6516, 6528, 6571, 6576, 6601, 6608, 6617, 6656, 6683, 6688, 6750, 6752, 6780, 6783, 6793, 6800, 6809, 6823, 6823, 6912, 6987, 6992, 7001, 7019, 7027, 7040, 7155, 7168, 7223, 7232, 7241, 7245, 7293, 7376, 7378, 7380, 7414, 7424, 7654, 7676, 7957, 7960, 7965, 7968, 8005, 8008, 8013, 8016, 8023, 8025, 8025, 8027, 8027, 8029, 8029, 8031, 8061, 8064, 8116, 8118, 8124, 8126, 8126, 8130, 8132, 8134, 8140, 8144, 8147, 8150, 8155, 8160, 8172, 8178, 8180, 8182, 8188, 8204, 8205, 8255, 8256, 8276, 8276, 8305, 8305, 8319, 8319, 8336, 8348, 8400, 8412, 8417, 8417, 8421, 8432, 8450, 8450, 8455, 8455, 8458, 8467, 8469, 8469, 8473, 8477, 8484, 8484, 8486, 8486, 8488, 8488, 8490, 8493, 8495, 8505, 8508, 8511, 8517, 8521, 8526, 8526, 8544, 8584, 11264, 11310, 11312, 11358, 11360, 11492, 11499, 11507, 11520, 11557, 11559, 11559, 11565, 11565, 11568, 11623, 11631, 11631, 11647, 11670, 11680, 11686, 11688, 11694, 11696, 11702, 11704, 11710, 11712, 11718, 11720, 11726, 11728, 11734, 11736, 11742, 11744, 11775, 11823, 11823, 12293, 12295, 12321, 12335, 12337, 12341, 12344, 12348, 12353, 12438, 12441, 12442, 12445, 12447, 12449, 12538, 12540, 12543, 12549, 12589, 12593, 12686, 12704, 12730, 12784, 12799, 13312, 19893, 19968, 40908, 40960, 42124, 42192, 42237, 42240, 42508, 42512, 42539, 42560, 42607, 42612, 42621, 42623, 42647, 42655, 42737, 42775, 42783, 42786, 42888, 42891, 42894, 42896, 42899, 42912, 42922, 43e3, 43047, 43072, 43123, 43136, 43204, 43216, 43225, 43232, 43255, 43259, 43259, 43264, 43309, 43312, 43347, 43360, 43388, 43392, 43456, 43471, 43481, 43520, 43574, 43584, 43597, 43600, 43609, 43616, 43638, 43642, 43643, 43648, 43714, 43739, 43741, 43744, 43759, 43762, 43766, 43777, 43782, 43785, 43790, 43793, 43798, 43808, 43814, 43816, 43822, 43968, 44010, 44012, 44013, 44016, 44025, 44032, 55203, 55216, 55238, 55243, 55291, 63744, 64109, 64112, 64217, 64256, 64262, 64275, 64279, 64285, 64296, 64298, 64310, 64312, 64316, 64318, 64318, 64320, 64321, 64323, 64324, 64326, 64433, 64467, 64829, 64848, 64911, 64914, 64967, 65008, 65019, 65024, 65039, 65056, 65062, 65075, 65076, 65101, 65103, 65136, 65140, 65142, 65276, 65296, 65305, 65313, 65338, 65343, 65343, 65345, 65370, 65382, 65470, 65474, 65479, 65482, 65487, 65490, 65495, 65498, 65500];
@@ -12643,7 +12644,9 @@ function createScanner(languageVersion, skipTrivia2, languageVariant = 0 /* Stan
12643
12644
  tokenFlags |= 2048 /* ContainsInvalidEscape */;
12644
12645
  if (isRegularExpression || shouldEmitInvalidEscapeError) {
12645
12646
  const code = parseInt(text.substring(start2 + 1, pos), 8);
12646
- error2(Diagnostics.Octal_escape_sequences_are_not_allowed_Use_the_syntax_0, start2, pos - start2, "\\x" + code.toString(16).padStart(2, "0"));
12647
+ if (isRegularExpression !== "annex-b") {
12648
+ error2(Diagnostics.Octal_escape_sequences_are_not_allowed_Use_the_syntax_0, start2, pos - start2, "\\x" + code.toString(16).padStart(2, "0"));
12649
+ }
12647
12650
  return String.fromCharCode(code);
12648
12651
  }
12649
12652
  return text.substring(start2, pos);
@@ -12674,7 +12677,7 @@ function createScanner(languageVersion, skipTrivia2, languageVariant = 0 /* Stan
12674
12677
  case 117 /* u */:
12675
12678
  if ((!isRegularExpression || shouldEmitInvalidEscapeError) && pos < end && text.charCodeAt(pos) === 123 /* openBrace */) {
12676
12679
  pos -= 2;
12677
- return scanExtendedUnicodeEscape(isRegularExpression || shouldEmitInvalidEscapeError);
12680
+ return scanExtendedUnicodeEscape(!!isRegularExpression || shouldEmitInvalidEscapeError);
12678
12681
  }
12679
12682
  for (; pos < start2 + 6; pos++) {
12680
12683
  if (!(pos < end && isHexDigit(text.charCodeAt(pos)))) {
@@ -12724,7 +12727,7 @@ function createScanner(languageVersion, skipTrivia2, languageVariant = 0 /* Stan
12724
12727
  case 8233 /* paragraphSeparator */:
12725
12728
  return "";
12726
12729
  default:
12727
- if (isRegularExpression && (shouldEmitInvalidEscapeError || isIdentifierPart(ch, languageVersion))) {
12730
+ if (isRegularExpression === true && (shouldEmitInvalidEscapeError || isIdentifierPart(ch, languageVersion))) {
12728
12731
  error2(Diagnostics.This_character_cannot_be_escaped_in_a_regular_expression, pos - 2, 2);
12729
12732
  }
12730
12733
  return String.fromCharCode(ch);
@@ -13419,7 +13422,7 @@ function createScanner(languageVersion, skipTrivia2, languageVariant = 0 /* Stan
13419
13422
  pos = tokenStart + 1;
13420
13423
  return token = 64 /* EqualsToken */;
13421
13424
  }
13422
- function reScanSlashToken() {
13425
+ function reScanSlashToken(reportErrors2) {
13423
13426
  if (token === 44 /* SlashToken */ || token === 69 /* SlashEqualsToken */) {
13424
13427
  let p = tokenStart + 1;
13425
13428
  let inEscape = false;
@@ -13458,38 +13461,51 @@ function createScanner(languageVersion, skipTrivia2, languageVariant = 0 /* Stan
13458
13461
  if (!isIdentifierPart(ch, languageVersion)) {
13459
13462
  break;
13460
13463
  }
13461
- const flag = characterToRegularExpressionFlag(String.fromCharCode(ch));
13462
- if (flag === void 0) {
13463
- error2(Diagnostics.Unknown_regular_expression_flag, p, 1);
13464
- } else if (regExpFlags & flag) {
13465
- error2(Diagnostics.Duplicate_regular_expression_flag, p, 1);
13466
- } else if (((regExpFlags | flag) & 96 /* UnicodeMode */) === 96 /* UnicodeMode */) {
13467
- error2(Diagnostics.The_Unicode_u_flag_and_the_Unicode_Sets_v_flag_cannot_be_set_simultaneously, p, 1);
13468
- } else {
13469
- regExpFlags |= flag;
13470
- const availableFrom = regExpFlagToFirstAvailableLanguageVersion.get(flag);
13471
- if (languageVersion < availableFrom) {
13472
- error2(Diagnostics.This_regular_expression_flag_is_only_available_when_targeting_0_or_later, p, 1, getNameOfScriptTarget(availableFrom));
13464
+ if (reportErrors2) {
13465
+ const flag = characterToRegularExpressionFlag(String.fromCharCode(ch));
13466
+ if (flag === void 0) {
13467
+ error2(Diagnostics.Unknown_regular_expression_flag, p, 1);
13468
+ } else if (regExpFlags & flag) {
13469
+ error2(Diagnostics.Duplicate_regular_expression_flag, p, 1);
13470
+ } else if (((regExpFlags | flag) & 96 /* UnicodeMode */) === 96 /* UnicodeMode */) {
13471
+ error2(Diagnostics.The_Unicode_u_flag_and_the_Unicode_Sets_v_flag_cannot_be_set_simultaneously, p, 1);
13472
+ } else {
13473
+ regExpFlags |= flag;
13474
+ checkRegularExpressionFlagAvailable(flag, p);
13473
13475
  }
13474
13476
  }
13475
13477
  p++;
13476
13478
  }
13477
- pos = tokenStart + 1;
13478
- const saveTokenPos = tokenStart;
13479
- const saveTokenFlags = tokenFlags;
13480
- scanRegularExpressionWorker(text, endOfBody, regExpFlags, isUnterminated);
13481
- if (!isUnterminated) {
13479
+ if (reportErrors2) {
13480
+ pos = tokenStart + 1;
13481
+ const saveTokenPos = tokenStart;
13482
+ const saveTokenFlags = tokenFlags;
13483
+ scanRegularExpressionWorker(
13484
+ text,
13485
+ endOfBody,
13486
+ regExpFlags,
13487
+ isUnterminated,
13488
+ /*annexB*/
13489
+ true
13490
+ );
13491
+ if (!isUnterminated) {
13492
+ pos = p;
13493
+ }
13494
+ tokenStart = saveTokenPos;
13495
+ tokenFlags = saveTokenFlags;
13496
+ } else {
13482
13497
  pos = p;
13483
13498
  }
13484
- tokenStart = saveTokenPos;
13485
- tokenFlags = saveTokenFlags;
13486
13499
  tokenValue = text.substring(tokenStart, pos);
13487
13500
  token = 14 /* RegularExpressionLiteral */;
13488
13501
  }
13489
13502
  return token;
13490
- function scanRegularExpressionWorker(text2, end2, regExpFlags, isUnterminated) {
13491
- const unicodeMode = !!(regExpFlags & 96 /* UnicodeMode */);
13503
+ function scanRegularExpressionWorker(text2, end2, regExpFlags, isUnterminated, annexB) {
13492
13504
  const unicodeSetsMode = !!(regExpFlags & 64 /* UnicodeSets */);
13505
+ const unicodeMode = !!(regExpFlags & 96 /* UnicodeMode */);
13506
+ if (unicodeMode) {
13507
+ annexB = false;
13508
+ }
13493
13509
  let mayContainStrings = false;
13494
13510
  let numberOfCapturingGroups = 0;
13495
13511
  const groupSpecifiers = /* @__PURE__ */ new Set();
@@ -13540,7 +13556,7 @@ function createScanner(languageVersion, skipTrivia2, languageVariant = 0 /* Stan
13540
13556
  case 61 /* equals */:
13541
13557
  case 33 /* exclamation */:
13542
13558
  pos++;
13543
- isPreviousTermQuantifiable = false;
13559
+ isPreviousTermQuantifiable = annexB;
13544
13560
  break;
13545
13561
  case 60 /* lessThan */:
13546
13562
  const groupNameStart = pos;
@@ -13687,10 +13703,7 @@ function createScanner(languageVersion, skipTrivia2, languageVariant = 0 /* Stan
13687
13703
  error2(Diagnostics.This_regular_expression_flag_cannot_be_toggled_within_a_subpattern, pos, 1);
13688
13704
  } else {
13689
13705
  currFlags |= flag;
13690
- const availableFrom = regExpFlagToFirstAvailableLanguageVersion.get(flag);
13691
- if (languageVersion < availableFrom) {
13692
- error2(Diagnostics.This_regular_expression_flag_is_only_available_when_targeting_0_or_later, pos, 1, getNameOfScriptTarget(availableFrom));
13693
- }
13706
+ checkRegularExpressionFlagAvailable(flag, pos);
13694
13707
  }
13695
13708
  pos++;
13696
13709
  }
@@ -13719,7 +13732,10 @@ function createScanner(languageVersion, skipTrivia2, languageVariant = 0 /* Stan
13719
13732
  break;
13720
13733
  }
13721
13734
  default:
13722
- Debug.assert(scanCharacterClassEscape() || scanDecimalEscape() || scanCharacterEscape());
13735
+ Debug.assert(scanCharacterClassEscape() || scanDecimalEscape() || scanCharacterEscape(
13736
+ /*atomEscape*/
13737
+ true
13738
+ ));
13723
13739
  break;
13724
13740
  }
13725
13741
  }
@@ -13734,7 +13750,7 @@ function createScanner(languageVersion, skipTrivia2, languageVariant = 0 /* Stan
13734
13750
  }
13735
13751
  return false;
13736
13752
  }
13737
- function scanCharacterEscape() {
13753
+ function scanCharacterEscape(atomEscape) {
13738
13754
  Debug.assertEqual(text2.charCodeAt(pos - 1), 92 /* backslash */);
13739
13755
  let ch = text2.charCodeAt(pos);
13740
13756
  switch (ch) {
@@ -13747,6 +13763,9 @@ function createScanner(languageVersion, skipTrivia2, languageVariant = 0 /* Stan
13747
13763
  }
13748
13764
  if (unicodeMode) {
13749
13765
  error2(Diagnostics.c_must_be_followed_by_an_ASCII_letter, pos - 2, 2);
13766
+ } else if (atomEscape && annexB) {
13767
+ pos--;
13768
+ return "\\";
13750
13769
  }
13751
13770
  return String.fromCharCode(ch);
13752
13771
  case 94 /* caret */:
@@ -13776,7 +13795,7 @@ function createScanner(languageVersion, skipTrivia2, languageVariant = 0 /* Stan
13776
13795
  /*shouldEmitInvalidEscapeError*/
13777
13796
  unicodeMode,
13778
13797
  /*isRegularExpression*/
13779
- true
13798
+ annexB ? "annex-b" : true
13780
13799
  );
13781
13800
  }
13782
13801
  }
@@ -13816,12 +13835,12 @@ function createScanner(languageVersion, skipTrivia2, languageVariant = 0 /* Stan
13816
13835
  if (isClassContentExit(ch2)) {
13817
13836
  return;
13818
13837
  }
13819
- if (!minCharacter) {
13838
+ if (!minCharacter && !annexB) {
13820
13839
  error2(Diagnostics.A_character_class_range_must_not_be_bounded_by_another_character_class, minStart, pos - 1 - minStart);
13821
13840
  }
13822
13841
  const maxStart = pos;
13823
13842
  const maxCharacter = scanClassAtom();
13824
- if (!maxCharacter) {
13843
+ if (!maxCharacter && !annexB) {
13825
13844
  error2(Diagnostics.A_character_class_range_must_not_be_bounded_by_another_character_class, maxStart, pos - maxStart);
13826
13845
  continue;
13827
13846
  }
@@ -14104,7 +14123,10 @@ function createScanner(languageVersion, skipTrivia2, languageVariant = 0 /* Stan
14104
14123
  pos++;
14105
14124
  return String.fromCharCode(ch2);
14106
14125
  default:
14107
- return scanCharacterEscape();
14126
+ return scanCharacterEscape(
14127
+ /*atomEscape*/
14128
+ false
14129
+ );
14108
14130
  }
14109
14131
  } else if (ch === text2.charCodeAt(pos + 1)) {
14110
14132
  switch (ch) {
@@ -14161,7 +14183,10 @@ function createScanner(languageVersion, skipTrivia2, languageVariant = 0 /* Stan
14161
14183
  if (scanCharacterClassEscape()) {
14162
14184
  return "";
14163
14185
  }
14164
- return scanCharacterEscape();
14186
+ return scanCharacterEscape(
14187
+ /*atomEscape*/
14188
+ false
14189
+ );
14165
14190
  }
14166
14191
  } else {
14167
14192
  return scanSourceCharacter();
@@ -14276,15 +14301,21 @@ function createScanner(languageVersion, skipTrivia2, languageVariant = 0 /* Stan
14276
14301
  }
14277
14302
  });
14278
14303
  forEach(decimalEscapes, (escape) => {
14279
- if (escape.value > numberOfCapturingGroups) {
14304
+ if (!annexB && escape.value > numberOfCapturingGroups) {
14280
14305
  if (numberOfCapturingGroups) {
14281
- error2(Diagnostics.A_decimal_escape_must_refer_to_an_existent_capturing_group_There_are_only_0_capturing_groups_in_this_regular_expression, escape.pos, escape.end - escape.pos, numberOfCapturingGroups);
14306
+ error2(Diagnostics.This_backreference_refers_to_a_group_that_does_not_exist_There_are_only_0_capturing_groups_in_this_regular_expression, escape.pos, escape.end - escape.pos, numberOfCapturingGroups);
14282
14307
  } else {
14283
- error2(Diagnostics.Decimal_escapes_are_invalid_when_there_are_no_capturing_groups_in_a_regular_expression, escape.pos, escape.end - escape.pos);
14308
+ error2(Diagnostics.This_backreference_is_invalid_because_the_containing_regular_expression_contains_no_capturing_groups, escape.pos, escape.end - escape.pos);
14284
14309
  }
14285
14310
  }
14286
14311
  });
14287
14312
  }
14313
+ function checkRegularExpressionFlagAvailable(flag, pos2) {
14314
+ const availableFrom = regExpFlagToFirstAvailableLanguageVersion.get(flag);
14315
+ if (availableFrom && languageVersion < availableFrom) {
14316
+ error2(Diagnostics.This_regular_expression_flag_is_only_available_when_targeting_0_or_later, pos2, 1, getNameOfScriptTarget(availableFrom));
14317
+ }
14318
+ }
14288
14319
  }
14289
14320
  function appendIfCommentDirective(commentDirectives2, text2, commentDirectiveRegEx, lineStart) {
14290
14321
  const type = getDirectiveFromComment(text2.trimStart(), commentDirectiveRegEx);
@@ -50077,6 +50108,7 @@ function createTypeChecker(host) {
50077
50108
  var requestedExternalEmitHelperNames = /* @__PURE__ */ new Set();
50078
50109
  var requestedExternalEmitHelpers;
50079
50110
  var externalHelpersModule;
50111
+ var scanner2;
50080
50112
  var Symbol47 = objectAllocator.getSymbolConstructor();
50081
50113
  var Type28 = objectAllocator.getTypeConstructor();
50082
50114
  var Signature14 = objectAllocator.getSignatureConstructor();
@@ -54936,7 +54968,8 @@ function createTypeChecker(host) {
54936
54968
  deepCloneOrReuseNode,
54937
54969
  /*context*/
54938
54970
  void 0,
54939
- deepCloneOrReuseNodes
54971
+ deepCloneOrReuseNodes,
54972
+ deepCloneOrReuseNode
54940
54973
  )), node);
54941
54974
  }
54942
54975
  function deepCloneOrReuseNodes(nodes, visitor, test, start, count) {
@@ -75915,6 +75948,53 @@ function createTypeChecker(host) {
75915
75948
  return signatureList.length === 1 ? signatureList[0] : createUnionSignature(signatureList[0], signatureList);
75916
75949
  }
75917
75950
  }
75951
+ function checkGrammarRegularExpressionLiteral(node) {
75952
+ const sourceFile = getSourceFileOfNode(node);
75953
+ if (!hasParseDiagnostics(sourceFile)) {
75954
+ let lastError;
75955
+ scanner2 ?? (scanner2 = createScanner(
75956
+ 99 /* ESNext */,
75957
+ /*skipTrivia*/
75958
+ true
75959
+ ));
75960
+ scanner2.setScriptTarget(sourceFile.languageVersion);
75961
+ scanner2.setLanguageVariant(sourceFile.languageVariant);
75962
+ scanner2.setOnError((message, length2, arg0) => {
75963
+ const start = scanner2.getTokenEnd();
75964
+ if (message.category === 3 /* Message */ && lastError && start === lastError.start && length2 === lastError.length) {
75965
+ const error3 = createDetachedDiagnostic(sourceFile.fileName, sourceFile.text, start, length2, message, arg0);
75966
+ addRelatedInfo(lastError, error3);
75967
+ } else if (!lastError || start !== lastError.start) {
75968
+ lastError = createFileDiagnostic(sourceFile, start, length2, message, arg0);
75969
+ diagnostics.add(lastError);
75970
+ }
75971
+ });
75972
+ scanner2.setText(sourceFile.text, node.pos, node.end - node.pos);
75973
+ try {
75974
+ scanner2.scan();
75975
+ Debug.assert(scanner2.reScanSlashToken(
75976
+ /*reportErrors*/
75977
+ true
75978
+ ) === 14 /* RegularExpressionLiteral */, "Expected scanner to rescan RegularExpressionLiteral");
75979
+ return !!lastError;
75980
+ } finally {
75981
+ scanner2.setText("");
75982
+ scanner2.setOnError(
75983
+ /*onError*/
75984
+ void 0
75985
+ );
75986
+ }
75987
+ }
75988
+ return false;
75989
+ }
75990
+ function checkRegularExpressionLiteral(node) {
75991
+ const nodeLinks2 = getNodeLinks(node);
75992
+ if (!(nodeLinks2.flags & 1 /* TypeChecked */)) {
75993
+ nodeLinks2.flags |= 1 /* TypeChecked */;
75994
+ addLazyDiagnostic(() => checkGrammarRegularExpressionLiteral(node));
75995
+ }
75996
+ return globalRegExpType;
75997
+ }
75918
75998
  function checkSpreadExpression(node, checkMode) {
75919
75999
  if (languageVersion < 2 /* SpreadElements */) {
75920
76000
  checkExternalEmitHelpers(node, compilerOptions.downlevelIteration ? 1536 /* SpreadIncludes */ : 1024 /* SpreadArray */);
@@ -81818,7 +81898,7 @@ function createTypeChecker(host) {
81818
81898
  parent2 = parent2.parent;
81819
81899
  }
81820
81900
  if (operator === 56 /* AmpersandAmpersandToken */ || isIfStatement(parent2)) {
81821
- checkTestingKnownTruthyCallableOrAwaitableType(node.left, leftType, isIfStatement(parent2) ? parent2.thenStatement : void 0);
81901
+ checkTestingKnownTruthyCallableOrAwaitableOrEnumMemberType(node.left, leftType, isIfStatement(parent2) ? parent2.thenStatement : void 0);
81822
81902
  }
81823
81903
  checkTruthinessOfType(leftType, node.left);
81824
81904
  }
@@ -82376,7 +82456,7 @@ function createTypeChecker(host) {
82376
82456
  }
82377
82457
  function checkConditionalExpression(node, checkMode) {
82378
82458
  const type = checkTruthinessExpression(node.condition, checkMode);
82379
- checkTestingKnownTruthyCallableOrAwaitableType(node.condition, type, node.whenTrue);
82459
+ checkTestingKnownTruthyCallableOrAwaitableOrEnumMemberType(node.condition, type, node.whenTrue);
82380
82460
  const type1 = checkExpression(node.whenTrue, checkMode);
82381
82461
  const type2 = checkExpression(node.whenFalse, checkMode);
82382
82462
  return getUnionType([type1, type2], 2 /* Subtype */);
@@ -82849,7 +82929,7 @@ function createTypeChecker(host) {
82849
82929
  case 228 /* TemplateExpression */:
82850
82930
  return checkTemplateExpression(node);
82851
82931
  case 14 /* RegularExpressionLiteral */:
82852
- return globalRegExpType;
82932
+ return checkRegularExpressionLiteral(node);
82853
82933
  case 209 /* ArrayLiteralExpression */:
82854
82934
  return checkArrayLiteral(node, checkMode, forceTuple);
82855
82935
  case 210 /* ObjectLiteralExpression */:
@@ -85424,14 +85504,14 @@ function createTypeChecker(host) {
85424
85504
  function checkIfStatement(node) {
85425
85505
  checkGrammarStatementInAmbientContext(node);
85426
85506
  const type = checkTruthinessExpression(node.expression);
85427
- checkTestingKnownTruthyCallableOrAwaitableType(node.expression, type, node.thenStatement);
85507
+ checkTestingKnownTruthyCallableOrAwaitableOrEnumMemberType(node.expression, type, node.thenStatement);
85428
85508
  checkSourceElement(node.thenStatement);
85429
85509
  if (node.thenStatement.kind === 242 /* EmptyStatement */) {
85430
85510
  error2(node.thenStatement, Diagnostics.The_body_of_an_if_statement_cannot_be_the_empty_statement);
85431
85511
  }
85432
85512
  checkSourceElement(node.elseStatement);
85433
85513
  }
85434
- function checkTestingKnownTruthyCallableOrAwaitableType(condExpr, condType, body) {
85514
+ function checkTestingKnownTruthyCallableOrAwaitableOrEnumMemberType(condExpr, condType, body) {
85435
85515
  if (!strictNullChecks)
85436
85516
  return;
85437
85517
  bothHelper(condExpr, body);
@@ -85453,6 +85533,10 @@ function createTypeChecker(host) {
85453
85533
  return;
85454
85534
  }
85455
85535
  const type = location === condExpr2 ? condType : checkTruthinessExpression(location);
85536
+ if (type.flags & 1024 /* EnumLiteral */ && isPropertyAccessExpression(location) && (getNodeLinks(location.expression).resolvedSymbol ?? unknownSymbol).flags & 384 /* Enum */) {
85537
+ error2(location, Diagnostics.This_condition_will_always_return_0, !!type.value ? "true" : "false");
85538
+ return;
85539
+ }
85456
85540
  const isPropertyExpressionCast = isPropertyAccessExpression(location) && isTypeAssertion(location.expression);
85457
85541
  if (!hasTypeFacts(type, 4194304 /* Truthy */) || isPropertyExpressionCast)
85458
85542
  return;
@@ -87898,7 +87982,7 @@ function createTypeChecker(host) {
87898
87982
  if (checkGrammarModuleElementContext(node, isInJSFile(node) ? Diagnostics.An_import_declaration_can_only_be_used_at_the_top_level_of_a_module : Diagnostics.An_import_declaration_can_only_be_used_at_the_top_level_of_a_namespace_or_module)) {
87899
87983
  return;
87900
87984
  }
87901
- if (!checkGrammarModifiers(node) && hasEffectiveModifiers(node)) {
87985
+ if (!checkGrammarModifiers(node) && node.modifiers) {
87902
87986
  grammarErrorOnFirstToken(node, Diagnostics.An_import_declaration_cannot_have_modifiers);
87903
87987
  }
87904
87988
  if (checkExternalImportOrExportDeclaration(node)) {
@@ -137012,9 +137096,6 @@ function getModuleSpecifierResolverHost(program, host) {
137012
137096
  function moduleResolutionUsesNodeModules(moduleResolution) {
137013
137097
  return moduleResolution === 2 /* Node10 */ || moduleResolution >= 3 /* Node16 */ && moduleResolution <= 99 /* NodeNext */ || moduleResolution === 100 /* Bundler */;
137014
137098
  }
137015
- function makeImportIfNecessary(defaultImport, namedImports, moduleSpecifier, quotePreference) {
137016
- return defaultImport || namedImports && namedImports.length ? makeImport(defaultImport, namedImports, moduleSpecifier, quotePreference) : void 0;
137017
- }
137018
137099
  function makeImport(defaultImport, namedImports, moduleSpecifier, quotePreference, isTypeOnly) {
137019
137100
  return factory.createImportDeclaration(
137020
137101
  /*modifiers*/
@@ -137028,10 +137109,10 @@ function makeImport(defaultImport, namedImports, moduleSpecifier, quotePreferenc
137028
137109
  function makeStringLiteral(text, quotePreference) {
137029
137110
  return factory.createStringLiteral(text, quotePreference === 0 /* Single */);
137030
137111
  }
137031
- var QuotePreference = /* @__PURE__ */ ((QuotePreference7) => {
137032
- QuotePreference7[QuotePreference7["Single"] = 0] = "Single";
137033
- QuotePreference7[QuotePreference7["Double"] = 1] = "Double";
137034
- return QuotePreference7;
137112
+ var QuotePreference = /* @__PURE__ */ ((QuotePreference6) => {
137113
+ QuotePreference6[QuotePreference6["Single"] = 0] = "Single";
137114
+ QuotePreference6[QuotePreference6["Double"] = 1] = "Double";
137115
+ return QuotePreference6;
137035
137116
  })(QuotePreference || {});
137036
137117
  function quotePreferenceFromString(str, sourceFile) {
137037
137118
  return isStringDoubleQuoted(str, sourceFile) ? 1 /* Double */ : 0 /* Single */;
@@ -142614,16 +142695,16 @@ function cleanText(text) {
142614
142695
  var ts_refactor_exports = {};
142615
142696
  __export(ts_refactor_exports, {
142616
142697
  addExportToChanges: () => addExportToChanges,
142617
- addExports: () => addExports,
142698
+ addImportsForMovedSymbols: () => addImportsForMovedSymbols,
142618
142699
  addNewFileToTsconfig: () => addNewFileToTsconfig,
142619
142700
  addOrRemoveBracesToArrowFunction: () => ts_refactor_addOrRemoveBracesToArrowFunction_exports,
142701
+ addTargetFileImports: () => addTargetFileImports,
142620
142702
  containsJsx: () => containsJsx,
142621
142703
  convertArrowFunctionOrFunctionExpression: () => ts_refactor_convertArrowFunctionOrFunctionExpression_exports,
142622
142704
  convertParamsToDestructuredObject: () => ts_refactor_convertParamsToDestructuredObject_exports,
142623
142705
  convertStringOrTemplateLiteral: () => ts_refactor_convertStringOrTemplateLiteral_exports,
142624
142706
  convertToOptionalChainExpression: () => ts_refactor_convertToOptionalChainExpression_exports,
142625
142707
  createNewFileName: () => createNewFileName,
142626
- createOldFileImportsFromTargetFile: () => createOldFileImportsFromTargetFile,
142627
142708
  deleteMovedStatements: () => deleteMovedStatements,
142628
142709
  deleteUnusedImports: () => deleteUnusedImports,
142629
142710
  deleteUnusedOldImports: () => deleteUnusedOldImports,
@@ -142634,13 +142715,13 @@ __export(ts_refactor_exports, {
142634
142715
  generateGetAccessorAndSetAccessor: () => ts_refactor_generateGetAccessorAndSetAccessor_exports,
142635
142716
  getApplicableRefactors: () => getApplicableRefactors,
142636
142717
  getEditsForRefactor: () => getEditsForRefactor,
142718
+ getNewStatementsAndRemoveFromOldFile: () => getNewStatementsAndRemoveFromOldFile,
142637
142719
  getStatementsToMove: () => getStatementsToMove,
142638
142720
  getTopLevelDeclarationStatement: () => getTopLevelDeclarationStatement,
142639
142721
  getUsageInfo: () => getUsageInfo,
142640
142722
  inferFunctionReturnType: () => ts_refactor_inferFunctionReturnType_exports,
142641
142723
  isRefactorErrorInfo: () => isRefactorErrorInfo,
142642
142724
  isTopLevelDeclaration: () => isTopLevelDeclaration,
142643
- makeImportOrRequire: () => makeImportOrRequire,
142644
142725
  moduleSpecifierFromImport: () => moduleSpecifierFromImport,
142645
142726
  nameOfTopLevelDeclaration: () => nameOfTopLevelDeclaration,
142646
142727
  refactorKindBeginsWith: () => refactorKindBeginsWith,
@@ -143512,282 +143593,12 @@ function getExpandedSelectionNode(firstType, enclosingNode) {
143512
143593
  }) ?? firstType;
143513
143594
  }
143514
143595
 
143515
- // src/services/refactors/helpers.ts
143516
- function isRefactorErrorInfo(info) {
143517
- return info.error !== void 0;
143518
- }
143519
- function refactorKindBeginsWith(known, requested) {
143520
- if (!requested)
143521
- return true;
143522
- return known.substr(0, requested.length) === requested;
143523
- }
143524
-
143525
- // src/services/refactors/inlineVariable.ts
143526
- var refactorName4 = "Inline variable";
143527
- var refactorDescription = getLocaleSpecificMessage(Diagnostics.Inline_variable);
143528
- var inlineVariableAction = {
143529
- name: refactorName4,
143530
- description: refactorDescription,
143531
- kind: "refactor.inline.variable"
143532
- };
143533
- registerRefactor(refactorName4, {
143534
- kinds: [inlineVariableAction.kind],
143535
- getAvailableActions(context) {
143536
- const {
143537
- file,
143538
- program,
143539
- preferences,
143540
- startPosition,
143541
- triggerReason
143542
- } = context;
143543
- const info = getInliningInfo(file, startPosition, triggerReason === "invoked", program);
143544
- if (!info) {
143545
- return emptyArray;
143546
- }
143547
- if (!ts_refactor_exports.isRefactorErrorInfo(info)) {
143548
- return [{
143549
- name: refactorName4,
143550
- description: refactorDescription,
143551
- actions: [inlineVariableAction]
143552
- }];
143553
- }
143554
- if (preferences.provideRefactorNotApplicableReason) {
143555
- return [{
143556
- name: refactorName4,
143557
- description: refactorDescription,
143558
- actions: [{
143559
- ...inlineVariableAction,
143560
- notApplicableReason: info.error
143561
- }]
143562
- }];
143563
- }
143564
- return emptyArray;
143565
- },
143566
- getEditsForAction(context, actionName2) {
143567
- Debug.assert(actionName2 === refactorName4, "Unexpected refactor invoked");
143568
- const { file, program, startPosition } = context;
143569
- const info = getInliningInfo(
143570
- file,
143571
- startPosition,
143572
- /*tryWithReferenceToken*/
143573
- true,
143574
- program
143575
- );
143576
- if (!info || ts_refactor_exports.isRefactorErrorInfo(info)) {
143577
- return void 0;
143578
- }
143579
- const { references, declaration, replacement } = info;
143580
- const edits = ts_textChanges_exports.ChangeTracker.with(context, (tracker) => {
143581
- for (const node of references) {
143582
- tracker.replaceNode(file, node, getReplacementExpression(node, replacement));
143583
- }
143584
- tracker.delete(file, declaration);
143585
- });
143586
- return { edits };
143587
- }
143588
- });
143589
- function getInliningInfo(file, startPosition, tryWithReferenceToken, program) {
143590
- var _a, _b;
143591
- const checker = program.getTypeChecker();
143592
- const token = getTouchingPropertyName(file, startPosition);
143593
- const parent2 = token.parent;
143594
- if (!isIdentifier(token)) {
143595
- return void 0;
143596
- }
143597
- if (isInitializedVariable(parent2) && isVariableDeclarationInVariableStatement(parent2) && isIdentifier(parent2.name)) {
143598
- if (((_a = checker.getMergedSymbol(parent2.symbol).declarations) == null ? void 0 : _a.length) !== 1) {
143599
- return { error: getLocaleSpecificMessage(Diagnostics.Variables_with_multiple_declarations_cannot_be_inlined) };
143600
- }
143601
- if (isDeclarationExported(parent2)) {
143602
- return void 0;
143603
- }
143604
- const references = getReferenceNodes(parent2, checker, file);
143605
- return references && { references, declaration: parent2, replacement: parent2.initializer };
143606
- }
143607
- if (tryWithReferenceToken) {
143608
- let definition = checker.resolveName(
143609
- token.text,
143610
- token,
143611
- 111551 /* Value */,
143612
- /*excludeGlobals*/
143613
- false
143614
- );
143615
- definition = definition && checker.getMergedSymbol(definition);
143616
- if (((_b = definition == null ? void 0 : definition.declarations) == null ? void 0 : _b.length) !== 1) {
143617
- return { error: getLocaleSpecificMessage(Diagnostics.Variables_with_multiple_declarations_cannot_be_inlined) };
143618
- }
143619
- const declaration = definition.declarations[0];
143620
- if (!isInitializedVariable(declaration) || !isVariableDeclarationInVariableStatement(declaration) || !isIdentifier(declaration.name)) {
143621
- return void 0;
143622
- }
143623
- if (isDeclarationExported(declaration)) {
143624
- return void 0;
143625
- }
143626
- const references = getReferenceNodes(declaration, checker, file);
143627
- return references && { references, declaration, replacement: declaration.initializer };
143628
- }
143629
- return { error: getLocaleSpecificMessage(Diagnostics.Could_not_find_variable_to_inline) };
143630
- }
143631
- function isDeclarationExported(declaration) {
143632
- const variableStatement = cast(declaration.parent.parent, isVariableStatement);
143633
- return some(variableStatement.modifiers, isExportModifier);
143634
- }
143635
- function getReferenceNodes(declaration, checker, file) {
143636
- const references = [];
143637
- const cannotInline = ts_FindAllReferences_exports.Core.eachSymbolReferenceInFile(declaration.name, checker, file, (ref) => {
143638
- if (ts_FindAllReferences_exports.isWriteAccessForReference(ref) && !isShorthandPropertyAssignment(ref.parent)) {
143639
- return true;
143640
- }
143641
- if (isExportSpecifier(ref.parent) || isExportAssignment(ref.parent)) {
143642
- return true;
143643
- }
143644
- if (isTypeQueryNode(ref.parent)) {
143645
- return true;
143646
- }
143647
- if (textRangeContainsPositionInclusive(declaration, ref.pos)) {
143648
- return true;
143649
- }
143650
- references.push(ref);
143651
- });
143652
- return references.length === 0 || cannotInline ? void 0 : references;
143653
- }
143654
- function getReplacementExpression(reference, replacement) {
143655
- replacement = getSynthesizedDeepClone(replacement);
143656
- const { parent: parent2 } = reference;
143657
- if (isExpression(parent2) && (getExpressionPrecedence(replacement) < getExpressionPrecedence(parent2) || needsParentheses(parent2))) {
143658
- return factory.createParenthesizedExpression(replacement);
143659
- }
143660
- if (isFunctionLike(replacement) && (isCallLikeExpression(parent2) || isPropertyAccessExpression(parent2))) {
143661
- return factory.createParenthesizedExpression(replacement);
143662
- }
143663
- if (isPropertyAccessExpression(parent2) && (isNumericLiteral(replacement) || isObjectLiteralExpression(replacement))) {
143664
- return factory.createParenthesizedExpression(replacement);
143665
- }
143666
- if (isIdentifier(reference) && isShorthandPropertyAssignment(parent2)) {
143667
- return factory.createPropertyAssignment(reference, replacement);
143668
- }
143669
- return replacement;
143670
- }
143671
-
143672
- // src/services/refactors/moveToNewFile.ts
143673
- var refactorName5 = "Move to a new file";
143674
- var description = getLocaleSpecificMessage(Diagnostics.Move_to_a_new_file);
143675
- var moveToNewFileAction = {
143676
- name: refactorName5,
143677
- description,
143678
- kind: "refactor.move.newFile"
143679
- };
143680
- registerRefactor(refactorName5, {
143681
- kinds: [moveToNewFileAction.kind],
143682
- getAvailableActions: function getRefactorActionsToMoveToNewFile(context) {
143683
- const statements = getStatementsToMove(context);
143684
- if (context.preferences.allowTextChangesInNewFiles && statements) {
143685
- const file = context.file;
143686
- const affectedTextRange = {
143687
- start: { line: getLineAndCharacterOfPosition(file, statements.all[0].getStart(file)).line, offset: getLineAndCharacterOfPosition(file, statements.all[0].getStart(file)).character },
143688
- end: { line: getLineAndCharacterOfPosition(file, last(statements.all).end).line, offset: getLineAndCharacterOfPosition(file, last(statements.all).end).character }
143689
- };
143690
- return [{ name: refactorName5, description, actions: [{ ...moveToNewFileAction, range: affectedTextRange }] }];
143691
- }
143692
- if (context.preferences.provideRefactorNotApplicableReason) {
143693
- return [{ name: refactorName5, description, actions: [{ ...moveToNewFileAction, notApplicableReason: getLocaleSpecificMessage(Diagnostics.Selection_is_not_a_valid_statement_or_statements) }] }];
143694
- }
143695
- return emptyArray;
143696
- },
143697
- getEditsForAction: function getRefactorEditsToMoveToNewFile(context, actionName2) {
143698
- Debug.assert(actionName2 === refactorName5, "Wrong refactor invoked");
143699
- const statements = Debug.checkDefined(getStatementsToMove(context));
143700
- const edits = ts_textChanges_exports.ChangeTracker.with(context, (t) => doChange3(context.file, context.program, statements, t, context.host, context.preferences));
143701
- return { edits, renameFilename: void 0, renameLocation: void 0 };
143702
- }
143703
- });
143704
- function doChange3(oldFile, program, toMove, changes, host, preferences) {
143705
- const checker = program.getTypeChecker();
143706
- const usage = getUsageInfo(oldFile, toMove.all, checker);
143707
- const newFilename = createNewFileName(oldFile, program, host, toMove);
143708
- changes.createNewFile(oldFile, newFilename, getNewStatementsAndRemoveFromOldFile(oldFile, usage, changes, toMove, program, host, newFilename, preferences));
143709
- addNewFileToTsconfig(program, changes, oldFile.fileName, newFilename, hostGetCanonicalFileName(host));
143710
- }
143711
- function getNewStatementsAndRemoveFromOldFile(oldFile, usage, changes, toMove, program, host, newFilename, preferences) {
143712
- const checker = program.getTypeChecker();
143713
- const prologueDirectives = takeWhile(oldFile.statements, isPrologueDirective);
143714
- if (oldFile.externalModuleIndicator === void 0 && oldFile.commonJsModuleIndicator === void 0 && usage.oldImportsNeededByTargetFile.size === 0) {
143715
- deleteMovedStatements(oldFile, toMove.ranges, changes);
143716
- return [...prologueDirectives, ...toMove.all];
143717
- }
143718
- const useEsModuleSyntax = !fileShouldUseJavaScriptRequire(newFilename, program, host, !!oldFile.commonJsModuleIndicator);
143719
- const quotePreference = getQuotePreference(oldFile, preferences);
143720
- const importsFromNewFile = createOldFileImportsFromTargetFile(oldFile, usage.oldFileImportsFromTargetFile, newFilename, program, host, useEsModuleSyntax, quotePreference);
143721
- if (importsFromNewFile) {
143722
- insertImports(
143723
- changes,
143724
- oldFile,
143725
- importsFromNewFile,
143726
- /*blankLineBetween*/
143727
- true,
143728
- preferences
143729
- );
143730
- }
143731
- deleteUnusedOldImports(oldFile, toMove.all, changes, usage.unusedImportsFromOldFile, checker);
143732
- deleteMovedStatements(oldFile, toMove.ranges, changes);
143733
- updateImportsInOtherFiles(changes, program, host, oldFile, usage.movedSymbols, newFilename, quotePreference);
143734
- const imports = getNewFileImportsAndAddExportInOldFile(oldFile, usage.oldImportsNeededByTargetFile, usage.targetFileImportsFromOldFile, changes, checker, program, host, useEsModuleSyntax, quotePreference);
143735
- const body = addExports(oldFile, toMove.all, usage.oldFileImportsFromTargetFile, useEsModuleSyntax);
143736
- if (imports.length && body.length) {
143737
- return [
143738
- ...prologueDirectives,
143739
- ...imports,
143740
- 4 /* NewLineTrivia */,
143741
- ...body
143742
- ];
143743
- }
143744
- return [
143745
- ...prologueDirectives,
143746
- ...imports,
143747
- ...body
143748
- ];
143749
- }
143750
- function getNewFileImportsAndAddExportInOldFile(oldFile, importsToCopy, newFileImportsFromOldFile, changes, checker, program, host, useEsModuleSyntax, quotePreference) {
143751
- const copiedOldImports = [];
143752
- for (const oldStatement of oldFile.statements) {
143753
- forEachImportInStatement(oldStatement, (i) => {
143754
- append(copiedOldImports, filterImport(i, moduleSpecifierFromImport(i), (name) => importsToCopy.has(checker.getSymbolAtLocation(name))));
143755
- });
143756
- }
143757
- let oldFileDefault;
143758
- const oldFileNamedImports = [];
143759
- const markSeenTop = nodeSeenTracker();
143760
- newFileImportsFromOldFile.forEach((symbol) => {
143761
- if (!symbol.declarations) {
143762
- return;
143763
- }
143764
- for (const decl of symbol.declarations) {
143765
- if (!isTopLevelDeclaration(decl))
143766
- continue;
143767
- const name = nameOfTopLevelDeclaration(decl);
143768
- if (!name)
143769
- continue;
143770
- const top = getTopLevelDeclarationStatement(decl);
143771
- if (markSeenTop(top)) {
143772
- addExportToChanges(oldFile, top, name, changes, useEsModuleSyntax);
143773
- }
143774
- if (hasSyntacticModifier(decl, 2048 /* Default */)) {
143775
- oldFileDefault = name;
143776
- } else {
143777
- oldFileNamedImports.push(name.text);
143778
- }
143779
- }
143780
- });
143781
- append(copiedOldImports, makeImportOrRequire(oldFile, oldFileDefault, oldFileNamedImports, getBaseFileName(oldFile.fileName), program, host, useEsModuleSyntax, quotePreference));
143782
- return copiedOldImports;
143783
- }
143784
-
143785
143596
  // src/services/refactors/moveToFile.ts
143786
143597
  var refactorNameForMoveToFile = "Move to file";
143787
- var description2 = getLocaleSpecificMessage(Diagnostics.Move_to_file);
143598
+ var description = getLocaleSpecificMessage(Diagnostics.Move_to_file);
143788
143599
  var moveToFileAction = {
143789
143600
  name: "Move to file",
143790
- description: description2,
143601
+ description,
143791
143602
  kind: "refactor.move.file"
143792
143603
  };
143793
143604
  registerRefactor(refactorNameForMoveToFile, {
@@ -143810,10 +143621,10 @@ registerRefactor(refactorNameForMoveToFile, {
143810
143621
  start: { line: getLineAndCharacterOfPosition(file, statements.all[0].getStart(file)).line, offset: getLineAndCharacterOfPosition(file, statements.all[0].getStart(file)).character },
143811
143622
  end: { line: getLineAndCharacterOfPosition(file, last(statements.all).end).line, offset: getLineAndCharacterOfPosition(file, last(statements.all).end).character }
143812
143623
  };
143813
- return [{ name: refactorNameForMoveToFile, description: description2, actions: [{ ...moveToFileAction, range: affectedTextRange }] }];
143624
+ return [{ name: refactorNameForMoveToFile, description, actions: [{ ...moveToFileAction, range: affectedTextRange }] }];
143814
143625
  }
143815
143626
  if (context.preferences.provideRefactorNotApplicableReason) {
143816
- return [{ name: refactorNameForMoveToFile, description: description2, actions: [{ ...moveToFileAction, notApplicableReason: getLocaleSpecificMessage(Diagnostics.Selection_is_not_a_valid_statement_or_statements) }] }];
143627
+ return [{ name: refactorNameForMoveToFile, description, actions: [{ ...moveToFileAction, notApplicableReason: getLocaleSpecificMessage(Diagnostics.Selection_is_not_a_valid_statement_or_statements) }] }];
143817
143628
  }
143818
143629
  return emptyArray;
143819
143630
  },
@@ -143827,7 +143638,7 @@ registerRefactor(refactorNameForMoveToFile, {
143827
143638
  if (host.fileExists(targetFile) && program.getSourceFile(targetFile) === void 0) {
143828
143639
  return error(getLocaleSpecificMessage(Diagnostics.Cannot_move_statements_to_the_selected_file));
143829
143640
  }
143830
- const edits = ts_textChanges_exports.ChangeTracker.with(context, (t) => doChange4(context, context.file, interactiveRefactorArguments.targetFile, context.program, statements, t, context.host, context.preferences));
143641
+ const edits = ts_textChanges_exports.ChangeTracker.with(context, (t) => doChange3(context, context.file, interactiveRefactorArguments.targetFile, context.program, statements, t, context.host, context.preferences));
143831
143642
  return { edits, renameFilename: void 0, renameLocation: void 0 };
143832
143643
  }
143833
143644
  return error(getLocaleSpecificMessage(Diagnostics.Cannot_move_to_file_selected_file_is_invalid));
@@ -143836,144 +143647,46 @@ registerRefactor(refactorNameForMoveToFile, {
143836
143647
  function error(notApplicableReason) {
143837
143648
  return { edits: [], renameFilename: void 0, renameLocation: void 0, notApplicableReason };
143838
143649
  }
143839
- function doChange4(context, oldFile, targetFile, program, toMove, changes, host, preferences) {
143650
+ function doChange3(context, oldFile, targetFile, program, toMove, changes, host, preferences) {
143840
143651
  const checker = program.getTypeChecker();
143841
- if (!host.fileExists(targetFile)) {
143842
- changes.createNewFile(oldFile, targetFile, getNewStatementsAndRemoveFromOldFile2(oldFile, targetFile, getUsageInfo(oldFile, toMove.all, checker), changes, toMove, program, host, preferences));
143652
+ const isForNewFile = !host.fileExists(targetFile);
143653
+ const targetSourceFile = isForNewFile ? createFutureSourceFile(targetFile, oldFile.externalModuleIndicator ? 99 /* ESNext */ : oldFile.commonJsModuleIndicator ? 1 /* CommonJS */ : void 0, program, host) : Debug.checkDefined(program.getSourceFile(targetFile));
143654
+ const importAdderForOldFile = ts_codefix_exports.createImportAdder(oldFile, context.program, context.preferences, context.host);
143655
+ const importAdderForNewFile = ts_codefix_exports.createImportAdder(targetSourceFile, context.program, context.preferences, context.host);
143656
+ getNewStatementsAndRemoveFromOldFile(oldFile, targetSourceFile, getUsageInfo(oldFile, toMove.all, checker, isForNewFile ? void 0 : getExistingLocals(targetSourceFile, toMove.all, checker)), changes, toMove, program, host, preferences, importAdderForNewFile, importAdderForOldFile);
143657
+ if (isForNewFile) {
143843
143658
  addNewFileToTsconfig(program, changes, oldFile.fileName, targetFile, hostGetCanonicalFileName(host));
143844
- } else {
143845
- const targetSourceFile = Debug.checkDefined(program.getSourceFile(targetFile));
143846
- const importAdder = ts_codefix_exports.createImportAdder(targetSourceFile, context.program, context.preferences, context.host);
143847
- getNewStatementsAndRemoveFromOldFile2(oldFile, targetSourceFile, getUsageInfo(oldFile, toMove.all, checker, getExistingLocals(targetSourceFile, toMove.all, checker)), changes, toMove, program, host, preferences, importAdder);
143848
143659
  }
143849
143660
  }
143850
- function getNewStatementsAndRemoveFromOldFile2(oldFile, targetFile, usage, changes, toMove, program, host, preferences, importAdder) {
143661
+ function getNewStatementsAndRemoveFromOldFile(oldFile, targetFile, usage, changes, toMove, program, host, preferences, importAdderForNewFile, importAdderForOldFile) {
143851
143662
  const checker = program.getTypeChecker();
143852
143663
  const prologueDirectives = takeWhile(oldFile.statements, isPrologueDirective);
143853
- if (oldFile.externalModuleIndicator === void 0 && oldFile.commonJsModuleIndicator === void 0 && usage.oldImportsNeededByTargetFile.size === 0 && usage.targetFileImportsFromOldFile.size === 0 && typeof targetFile === "string") {
143854
- deleteMovedStatements(oldFile, toMove.ranges, changes);
143855
- return [...prologueDirectives, ...toMove.all];
143856
- }
143857
- const targetFileName = typeof targetFile === "string" ? targetFile : targetFile.fileName;
143858
- const useEsModuleSyntax = !fileShouldUseJavaScriptRequire(targetFileName, program, host, !!oldFile.commonJsModuleIndicator);
143664
+ const useEsModuleSyntax = !fileShouldUseJavaScriptRequire(targetFile.fileName, program, host, !!oldFile.commonJsModuleIndicator);
143859
143665
  const quotePreference = getQuotePreference(oldFile, preferences);
143860
- const importsFromTargetFile = createOldFileImportsFromTargetFile(oldFile, usage.oldFileImportsFromTargetFile, targetFileName, program, host, useEsModuleSyntax, quotePreference);
143861
- if (importsFromTargetFile) {
143862
- insertImports(
143863
- changes,
143864
- oldFile,
143865
- importsFromTargetFile,
143666
+ addImportsForMovedSymbols(usage.oldFileImportsFromTargetFile, targetFile.fileName, importAdderForOldFile, program);
143667
+ deleteUnusedOldImports(oldFile, toMove.all, usage.unusedImportsFromOldFile, importAdderForOldFile);
143668
+ importAdderForOldFile.writeFixes(changes, quotePreference);
143669
+ deleteMovedStatements(oldFile, toMove.ranges, changes);
143670
+ updateImportsInOtherFiles(changes, program, host, oldFile, usage.movedSymbols, targetFile.fileName, quotePreference);
143671
+ addExportsInOldFile(oldFile, usage.targetFileImportsFromOldFile, changes, useEsModuleSyntax);
143672
+ addTargetFileImports(oldFile, usage.oldImportsNeededByTargetFile, usage.targetFileImportsFromOldFile, checker, program, importAdderForNewFile);
143673
+ if (!isFullSourceFile(targetFile) && prologueDirectives.length) {
143674
+ changes.insertStatementsInNewFile(targetFile.fileName, prologueDirectives, oldFile);
143675
+ }
143676
+ importAdderForNewFile.writeFixes(changes, quotePreference);
143677
+ const body = addExports(oldFile, toMove.all, arrayFrom(usage.oldFileImportsFromTargetFile.keys()), useEsModuleSyntax);
143678
+ if (isFullSourceFile(targetFile) && targetFile.statements.length > 0) {
143679
+ moveStatementsToTargetFile(changes, program, body, targetFile, toMove);
143680
+ } else if (isFullSourceFile(targetFile)) {
143681
+ changes.insertNodesAtEndOfFile(
143682
+ targetFile,
143683
+ body,
143866
143684
  /*blankLineBetween*/
143867
- true,
143868
- preferences
143685
+ false
143869
143686
  );
143870
- }
143871
- deleteUnusedOldImports(oldFile, toMove.all, changes, usage.unusedImportsFromOldFile, checker);
143872
- deleteMovedStatements(oldFile, toMove.ranges, changes);
143873
- updateImportsInOtherFiles(changes, program, host, oldFile, usage.movedSymbols, targetFileName, quotePreference);
143874
- const imports = getTargetFileImportsAndAddExportInOldFile(oldFile, targetFileName, usage.oldImportsNeededByTargetFile, usage.targetFileImportsFromOldFile, changes, checker, program, host, useEsModuleSyntax, quotePreference, importAdder);
143875
- const body = addExports(oldFile, toMove.all, usage.oldFileImportsFromTargetFile, useEsModuleSyntax);
143876
- if (typeof targetFile !== "string") {
143877
- if (targetFile.statements.length > 0) {
143878
- moveStatementsToTargetFile(changes, program, body, targetFile, toMove);
143879
- } else {
143880
- changes.insertNodesAtEndOfFile(
143881
- targetFile,
143882
- body,
143883
- /*blankLineBetween*/
143884
- false
143885
- );
143886
- }
143887
- if (imports.length > 0) {
143888
- insertImports(
143889
- changes,
143890
- targetFile,
143891
- imports,
143892
- /*blankLineBetween*/
143893
- true,
143894
- preferences
143895
- );
143896
- }
143897
- }
143898
- if (importAdder) {
143899
- importAdder.writeFixes(changes, quotePreference);
143900
- }
143901
- if (imports.length && body.length) {
143902
- return [
143903
- ...prologueDirectives,
143904
- ...imports,
143905
- 4 /* NewLineTrivia */,
143906
- ...body
143907
- ];
143908
- }
143909
- return [
143910
- ...prologueDirectives,
143911
- ...imports,
143912
- ...body
143913
- ];
143914
- }
143915
- function getTargetFileImportsAndAddExportInOldFile(oldFile, targetFile, importsToCopy, targetFileImportsFromOldFile, changes, checker, program, host, useEsModuleSyntax, quotePreference, importAdder) {
143916
- const copiedOldImports = [];
143917
- if (importAdder) {
143918
- importsToCopy.forEach((isValidTypeOnlyUseSite, symbol) => {
143919
- try {
143920
- importAdder.addImportFromExportedSymbol(skipAlias(symbol, checker), isValidTypeOnlyUseSite);
143921
- } catch {
143922
- for (const oldStatement of oldFile.statements) {
143923
- forEachImportInStatement(oldStatement, (i) => {
143924
- append(copiedOldImports, filterImport(i, factory.createStringLiteral(moduleSpecifierFromImport(i).text), (name) => importsToCopy.has(checker.getSymbolAtLocation(name))));
143925
- });
143926
- }
143927
- }
143928
- });
143929
143687
  } else {
143930
- const targetSourceFile = program.getSourceFile(targetFile);
143931
- for (const oldStatement of oldFile.statements) {
143932
- forEachImportInStatement(oldStatement, (i) => {
143933
- var _a;
143934
- const moduleSpecifier = moduleSpecifierFromImport(i);
143935
- const compilerOptions = program.getCompilerOptions();
143936
- const resolved = program.getResolvedModuleFromModuleSpecifier(moduleSpecifier);
143937
- const fileName = (_a = resolved == null ? void 0 : resolved.resolvedModule) == null ? void 0 : _a.resolvedFileName;
143938
- if (fileName && targetSourceFile) {
143939
- const newModuleSpecifier = getModuleSpecifier(compilerOptions, targetSourceFile, targetSourceFile.fileName, fileName, createModuleSpecifierResolutionHost(program, host));
143940
- append(copiedOldImports, filterImport(i, makeStringLiteral(newModuleSpecifier, quotePreference), (name) => importsToCopy.has(checker.getSymbolAtLocation(name))));
143941
- } else {
143942
- append(copiedOldImports, filterImport(i, factory.createStringLiteral(moduleSpecifierFromImport(i).text), (name) => importsToCopy.has(checker.getSymbolAtLocation(name))));
143943
- }
143944
- });
143945
- }
143688
+ changes.insertStatementsInNewFile(targetFile.fileName, importAdderForNewFile.hasFixes() ? [4 /* NewLineTrivia */, ...body] : body, oldFile);
143946
143689
  }
143947
- const targetFileSourceFile = program.getSourceFile(targetFile);
143948
- let oldFileDefault;
143949
- const oldFileNamedImports = [];
143950
- const markSeenTop = nodeSeenTracker();
143951
- targetFileImportsFromOldFile.forEach((symbol) => {
143952
- if (!symbol.declarations) {
143953
- return;
143954
- }
143955
- for (const decl of symbol.declarations) {
143956
- if (!isTopLevelDeclaration(decl))
143957
- continue;
143958
- const name = nameOfTopLevelDeclaration(decl);
143959
- if (!name)
143960
- continue;
143961
- const top = getTopLevelDeclarationStatement(decl);
143962
- if (markSeenTop(top)) {
143963
- addExportToChanges(oldFile, top, name, changes, useEsModuleSyntax);
143964
- }
143965
- if (importAdder && checker.isUnknownSymbol(symbol)) {
143966
- importAdder.addImportFromExportedSymbol(skipAlias(symbol, checker));
143967
- } else {
143968
- if (hasSyntacticModifier(decl, 2048 /* Default */)) {
143969
- oldFileDefault = name;
143970
- } else {
143971
- oldFileNamedImports.push(name.text);
143972
- }
143973
- }
143974
- }
143975
- });
143976
- return targetFileSourceFile ? append(copiedOldImports, makeImportOrRequire(targetFileSourceFile, oldFileDefault, oldFileNamedImports, oldFile.fileName, program, host, useEsModuleSyntax, quotePreference)) : append(copiedOldImports, makeImportOrRequire(oldFile, oldFileDefault, oldFileNamedImports, oldFile.fileName, program, host, useEsModuleSyntax, quotePreference));
143977
143690
  }
143978
143691
  function addNewFileToTsconfig(program, changes, oldFileName, newFileNameWithExtension, getCanonicalFileName) {
143979
143692
  const cfg = program.getCompilerOptions().configFile;
@@ -143992,13 +143705,38 @@ function deleteMovedStatements(sourceFile, moved, changes) {
143992
143705
  changes.deleteNodeRangeExcludingEnd(sourceFile, first2, afterLast);
143993
143706
  }
143994
143707
  }
143995
- function deleteUnusedOldImports(oldFile, toMove, changes, toDelete, checker) {
143708
+ function deleteUnusedOldImports(oldFile, toMove, toDelete, importAdder) {
143996
143709
  for (const statement of oldFile.statements) {
143997
143710
  if (contains(toMove, statement))
143998
143711
  continue;
143999
- forEachImportInStatement(statement, (i) => deleteUnusedImports(oldFile, i, changes, (name) => toDelete.has(checker.getSymbolAtLocation(name))));
143712
+ forEachImportInStatement(statement, (i) => {
143713
+ forEachAliasDeclarationInImportOrRequire(i, (decl) => {
143714
+ if (toDelete.has(decl.symbol)) {
143715
+ importAdder.removeExistingImport(decl);
143716
+ }
143717
+ });
143718
+ });
144000
143719
  }
144001
143720
  }
143721
+ function addExportsInOldFile(oldFile, targetFileImportsFromOldFile, changes, useEsModuleSyntax) {
143722
+ const markSeenTop = nodeSeenTracker();
143723
+ targetFileImportsFromOldFile.forEach((_, symbol) => {
143724
+ if (!symbol.declarations) {
143725
+ return;
143726
+ }
143727
+ for (const decl of symbol.declarations) {
143728
+ if (!isTopLevelDeclaration(decl))
143729
+ continue;
143730
+ const name = nameOfTopLevelDeclaration(decl);
143731
+ if (!name)
143732
+ continue;
143733
+ const top = getTopLevelDeclarationStatement(decl);
143734
+ if (markSeenTop(top)) {
143735
+ addExportToChanges(oldFile, top, name, changes, useEsModuleSyntax);
143736
+ }
143737
+ }
143738
+ });
143739
+ }
144002
143740
  function updateImportsInOtherFiles(changes, program, host, oldFile, movedSymbols, targetFileName, quotePreference) {
144003
143741
  const checker = program.getTypeChecker();
144004
143742
  for (const sourceFile of program.getSourceFiles()) {
@@ -144137,45 +143875,39 @@ function forEachImportInStatement(statement, cb) {
144137
143875
  }
144138
143876
  }
144139
143877
  }
144140
- function createOldFileImportsFromTargetFile(sourceFile, targetFileNeedExport, targetFileNameWithExtension, program, host, useEs6Imports, quotePreference) {
144141
- let defaultImport;
144142
- const imports = [];
144143
- targetFileNeedExport.forEach((symbol) => {
144144
- if (symbol.escapedName === "default" /* Default */) {
144145
- defaultImport = factory.createIdentifier(symbolNameNoDefault(symbol));
144146
- } else {
144147
- imports.push(symbol.name);
143878
+ function forEachAliasDeclarationInImportOrRequire(importOrRequire, cb) {
143879
+ var _a, _b, _c, _d, _e;
143880
+ if (importOrRequire.kind === 272 /* ImportDeclaration */) {
143881
+ if ((_a = importOrRequire.importClause) == null ? void 0 : _a.name) {
143882
+ cb(importOrRequire.importClause);
144148
143883
  }
144149
- });
144150
- return makeImportOrRequire(sourceFile, defaultImport, imports, targetFileNameWithExtension, program, host, useEs6Imports, quotePreference);
143884
+ if (((_c = (_b = importOrRequire.importClause) == null ? void 0 : _b.namedBindings) == null ? void 0 : _c.kind) === 274 /* NamespaceImport */) {
143885
+ cb(importOrRequire.importClause.namedBindings);
143886
+ }
143887
+ if (((_e = (_d = importOrRequire.importClause) == null ? void 0 : _d.namedBindings) == null ? void 0 : _e.kind) === 275 /* NamedImports */) {
143888
+ for (const element of importOrRequire.importClause.namedBindings.elements) {
143889
+ cb(element);
143890
+ }
143891
+ }
143892
+ } else if (importOrRequire.kind === 271 /* ImportEqualsDeclaration */) {
143893
+ cb(importOrRequire);
143894
+ } else if (importOrRequire.kind === 260 /* VariableDeclaration */) {
143895
+ if (importOrRequire.name.kind === 80 /* Identifier */) {
143896
+ cb(importOrRequire);
143897
+ } else if (importOrRequire.name.kind === 206 /* ObjectBindingPattern */) {
143898
+ for (const element of importOrRequire.name.elements) {
143899
+ if (isIdentifier(element.name)) {
143900
+ cb(element);
143901
+ }
143902
+ }
143903
+ }
143904
+ }
144151
143905
  }
144152
- function makeImportOrRequire(sourceFile, defaultImport, imports, targetFileNameWithExtension, program, host, useEs6Imports, quotePreference) {
144153
- const pathToTargetFile = resolvePath(getDirectoryPath(getNormalizedAbsolutePath(sourceFile.fileName, program.getCurrentDirectory())), targetFileNameWithExtension);
144154
- const pathToTargetFileWithCorrectExtension = getModuleSpecifier(program.getCompilerOptions(), sourceFile, sourceFile.fileName, pathToTargetFile, createModuleSpecifierResolutionHost(program, host));
144155
- if (useEs6Imports) {
144156
- const specifiers = imports.map((i) => factory.createImportSpecifier(
144157
- /*isTypeOnly*/
144158
- false,
144159
- /*propertyName*/
144160
- void 0,
144161
- factory.createIdentifier(i)
144162
- ));
144163
- return makeImportIfNecessary(defaultImport, specifiers, pathToTargetFileWithCorrectExtension, quotePreference);
144164
- } else {
144165
- Debug.assert(!defaultImport, "No default import should exist");
144166
- const bindingElements = imports.map((i) => factory.createBindingElement(
144167
- /*dotDotDotToken*/
144168
- void 0,
144169
- /*propertyName*/
144170
- void 0,
144171
- i
144172
- ));
144173
- return bindingElements.length ? makeVariableStatement(
144174
- factory.createObjectBindingPattern(bindingElements),
144175
- /*type*/
144176
- void 0,
144177
- createRequireCall(makeStringLiteral(pathToTargetFileWithCorrectExtension, quotePreference))
144178
- ) : void 0;
143906
+ function addImportsForMovedSymbols(symbols, targetFileName, importAdder, program) {
143907
+ for (const [symbol, isValidTypeOnlyUseSite] of symbols) {
143908
+ const symbolName2 = getNameForExportedSymbol(symbol, getEmitScriptTarget(program.getCompilerOptions()));
143909
+ const exportKind = symbol.name === "default" && symbol.parent ? 1 /* Default */ : 0 /* Named */;
143910
+ importAdder.addImportForNonExistentExport(symbolName2, targetFileName, exportKind, symbol.flags, isValidTypeOnlyUseSite);
144179
143911
  }
144180
143912
  }
144181
143913
  function makeVariableStatement(name, type, initializer, flags = 2 /* Const */) {
@@ -144195,7 +143927,7 @@ function addExports(sourceFile, toMove, needExport, useEs6Exports) {
144195
143927
  return flatMap(toMove, (statement) => {
144196
143928
  if (isTopLevelDeclarationStatement(statement) && !isExported(sourceFile, statement, useEs6Exports) && forEachTopLevelDeclaration(statement, (d) => {
144197
143929
  var _a;
144198
- return needExport.has(Debug.checkDefined((_a = tryCast(d, canHaveSymbol)) == null ? void 0 : _a.symbol));
143930
+ return needExport.includes(Debug.checkDefined((_a = tryCast(d, canHaveSymbol)) == null ? void 0 : _a.symbol));
144199
143931
  })) {
144200
143932
  const exports2 = addExport(getSynthesizedDeepClone(statement), useEs6Exports);
144201
143933
  if (exports2)
@@ -144212,86 +143944,17 @@ function isExported(sourceFile, decl, useEs6Exports, name) {
144212
143944
  return !!sourceFile.symbol && !!sourceFile.symbol.exports && getNamesToExportInCommonJS(decl).some((name2) => sourceFile.symbol.exports.has(escapeLeadingUnderscores(name2)));
144213
143945
  }
144214
143946
  function deleteUnusedImports(sourceFile, importDecl, changes, isUnused) {
144215
- switch (importDecl.kind) {
144216
- case 272 /* ImportDeclaration */:
144217
- deleteUnusedImportsInDeclaration(sourceFile, importDecl, changes, isUnused);
144218
- break;
144219
- case 271 /* ImportEqualsDeclaration */:
144220
- if (isUnused(importDecl.name)) {
144221
- changes.delete(sourceFile, importDecl);
144222
- }
144223
- break;
144224
- case 260 /* VariableDeclaration */:
144225
- deleteUnusedImportsInVariableDeclaration(sourceFile, importDecl, changes, isUnused);
144226
- break;
144227
- default:
144228
- Debug.assertNever(importDecl, `Unexpected import decl kind ${importDecl.kind}`);
144229
- }
144230
- }
144231
- function deleteUnusedImportsInDeclaration(sourceFile, importDecl, changes, isUnused) {
144232
- if (!importDecl.importClause)
144233
- return;
144234
- const { name, namedBindings } = importDecl.importClause;
144235
- const defaultUnused = !name || isUnused(name);
144236
- const namedBindingsUnused = !namedBindings || (namedBindings.kind === 274 /* NamespaceImport */ ? isUnused(namedBindings.name) : namedBindings.elements.length !== 0 && namedBindings.elements.every((e) => isUnused(e.name)));
144237
- if (defaultUnused && namedBindingsUnused) {
144238
- changes.delete(sourceFile, importDecl);
144239
- } else {
144240
- if (name && defaultUnused) {
144241
- changes.delete(sourceFile, name);
143947
+ if (importDecl.kind === 272 /* ImportDeclaration */ && importDecl.importClause) {
143948
+ const { name, namedBindings } = importDecl.importClause;
143949
+ if ((!name || isUnused(name)) && (!namedBindings || namedBindings.kind === 275 /* NamedImports */ && namedBindings.elements.length !== 0 && namedBindings.elements.every((e) => isUnused(e.name)))) {
143950
+ return changes.delete(sourceFile, importDecl);
144242
143951
  }
144243
- if (namedBindings) {
144244
- if (namedBindingsUnused) {
144245
- changes.replaceNode(
144246
- sourceFile,
144247
- importDecl.importClause,
144248
- factory.updateImportClause(
144249
- importDecl.importClause,
144250
- importDecl.importClause.isTypeOnly,
144251
- name,
144252
- /*namedBindings*/
144253
- void 0
144254
- )
144255
- );
144256
- } else if (namedBindings.kind === 275 /* NamedImports */) {
144257
- for (const element of namedBindings.elements) {
144258
- if (isUnused(element.name))
144259
- changes.delete(sourceFile, element);
144260
- }
144261
- }
144262
- }
144263
- }
144264
- }
144265
- function deleteUnusedImportsInVariableDeclaration(sourceFile, varDecl, changes, isUnused) {
144266
- const { name } = varDecl;
144267
- switch (name.kind) {
144268
- case 80 /* Identifier */:
144269
- if (isUnused(name)) {
144270
- if (varDecl.initializer && isRequireCall(
144271
- varDecl.initializer,
144272
- /*requireStringLiteralLikeArgument*/
144273
- true
144274
- )) {
144275
- changes.delete(sourceFile, isVariableDeclarationList(varDecl.parent) && length(varDecl.parent.declarations) === 1 ? varDecl.parent.parent : varDecl);
144276
- } else {
144277
- changes.delete(sourceFile, name);
144278
- }
144279
- }
144280
- break;
144281
- case 207 /* ArrayBindingPattern */:
144282
- break;
144283
- case 206 /* ObjectBindingPattern */:
144284
- if (name.elements.every((e) => isIdentifier(e.name) && isUnused(e.name))) {
144285
- changes.delete(sourceFile, isVariableDeclarationList(varDecl.parent) && varDecl.parent.declarations.length === 1 ? varDecl.parent.parent : varDecl);
144286
- } else {
144287
- for (const element of name.elements) {
144288
- if (isIdentifier(element.name) && isUnused(element.name)) {
144289
- changes.delete(sourceFile, element.name);
144290
- }
144291
- }
144292
- }
144293
- break;
144294
143952
  }
143953
+ forEachAliasDeclarationInImportOrRequire(importDecl, (i) => {
143954
+ if (i.name && isIdentifier(i.name) && isUnused(i.name)) {
143955
+ changes.delete(sourceFile, i);
143956
+ }
143957
+ });
144295
143958
  }
144296
143959
  function isTopLevelDeclarationStatement(node) {
144297
143960
  Debug.assert(isSourceFile(node.parent), "Node parent should be a SourceFile");
@@ -144515,12 +144178,13 @@ function isPureImport(node) {
144515
144178
  }
144516
144179
  }
144517
144180
  function getUsageInfo(oldFile, toMove, checker, existingTargetLocals = /* @__PURE__ */ new Set()) {
144181
+ var _a;
144518
144182
  const movedSymbols = /* @__PURE__ */ new Set();
144519
144183
  const oldImportsNeededByTargetFile = /* @__PURE__ */ new Map();
144520
- const targetFileImportsFromOldFile = /* @__PURE__ */ new Set();
144184
+ const targetFileImportsFromOldFile = /* @__PURE__ */ new Map();
144521
144185
  const jsxNamespaceSymbol = getJsxNamespaceSymbol(containsJsx(toMove));
144522
144186
  if (jsxNamespaceSymbol) {
144523
- oldImportsNeededByTargetFile.set(jsxNamespaceSymbol, false);
144187
+ oldImportsNeededByTargetFile.set(jsxNamespaceSymbol, [false, tryCast((_a = jsxNamespaceSymbol.declarations) == null ? void 0 : _a[0], (d) => isImportSpecifier(d) || isImportClause(d) || isNamespaceImport(d) || isImportEqualsDeclaration(d) || isBindingElement(d) || isVariableDeclaration(d))]);
144524
144188
  }
144525
144189
  for (const statement of toMove) {
144526
144190
  forEachTopLevelDeclaration(statement, (decl) => {
@@ -144540,9 +144204,12 @@ function getUsageInfo(oldFile, toMove, checker, existingTargetLocals = /* @__PUR
144540
144204
  for (const decl of symbol.declarations) {
144541
144205
  if (isInImport(decl)) {
144542
144206
  const prevIsTypeOnly = oldImportsNeededByTargetFile.get(symbol);
144543
- oldImportsNeededByTargetFile.set(symbol, prevIsTypeOnly === void 0 ? isValidTypeOnlyUseSite : prevIsTypeOnly && isValidTypeOnlyUseSite);
144207
+ oldImportsNeededByTargetFile.set(symbol, [
144208
+ prevIsTypeOnly === void 0 ? isValidTypeOnlyUseSite : prevIsTypeOnly && isValidTypeOnlyUseSite,
144209
+ tryCast(decl, (d) => isImportSpecifier(d) || isImportClause(d) || isNamespaceImport(d) || isImportEqualsDeclaration(d) || isBindingElement(d) || isVariableDeclaration(d))
144210
+ ]);
144544
144211
  } else if (isTopLevelDeclaration(decl) && sourceFileOfTopLevelDeclaration(decl) === oldFile && !movedSymbols.has(symbol)) {
144545
- targetFileImportsFromOldFile.add(symbol);
144212
+ targetFileImportsFromOldFile.set(symbol, isValidTypeOnlyUseSite);
144546
144213
  }
144547
144214
  }
144548
144215
  });
@@ -144550,16 +144217,16 @@ function getUsageInfo(oldFile, toMove, checker, existingTargetLocals = /* @__PUR
144550
144217
  for (const unusedImport of oldImportsNeededByTargetFile.keys()) {
144551
144218
  unusedImportsFromOldFile.add(unusedImport);
144552
144219
  }
144553
- const oldFileImportsFromTargetFile = /* @__PURE__ */ new Set();
144220
+ const oldFileImportsFromTargetFile = /* @__PURE__ */ new Map();
144554
144221
  for (const statement of oldFile.statements) {
144555
144222
  if (contains(toMove, statement))
144556
144223
  continue;
144557
144224
  if (jsxNamespaceSymbol && !!(statement.transformFlags & 2 /* ContainsJsx */)) {
144558
144225
  unusedImportsFromOldFile.delete(jsxNamespaceSymbol);
144559
144226
  }
144560
- forEachReference(statement, checker, (symbol) => {
144227
+ forEachReference(statement, checker, (symbol, isValidTypeOnlyUseSite) => {
144561
144228
  if (movedSymbols.has(symbol))
144562
- oldFileImportsFromTargetFile.add(symbol);
144229
+ oldFileImportsFromTargetFile.set(symbol, isValidTypeOnlyUseSite);
144563
144230
  unusedImportsFromOldFile.delete(symbol);
144564
144231
  });
144565
144232
  }
@@ -144767,6 +144434,218 @@ function getExistingLocals(sourceFile, statements, checker) {
144767
144434
  return existingLocals;
144768
144435
  }
144769
144436
 
144437
+ // src/services/refactors/helpers.ts
144438
+ function isRefactorErrorInfo(info) {
144439
+ return info.error !== void 0;
144440
+ }
144441
+ function refactorKindBeginsWith(known, requested) {
144442
+ if (!requested)
144443
+ return true;
144444
+ return known.substr(0, requested.length) === requested;
144445
+ }
144446
+ function addTargetFileImports(oldFile, importsToCopy, targetFileImportsFromOldFile, checker, program, importAdder) {
144447
+ importsToCopy.forEach(([isValidTypeOnlyUseSite, declaration], symbol) => {
144448
+ var _a;
144449
+ const targetSymbol = skipAlias(symbol, checker);
144450
+ if (checker.isUnknownSymbol(targetSymbol)) {
144451
+ importAdder.addVerbatimImport(Debug.checkDefined(declaration ?? findAncestor((_a = symbol.declarations) == null ? void 0 : _a[0], isAnyImportOrRequireStatement)));
144452
+ } else {
144453
+ importAdder.addImportFromExportedSymbol(targetSymbol, isValidTypeOnlyUseSite, declaration);
144454
+ }
144455
+ });
144456
+ addImportsForMovedSymbols(targetFileImportsFromOldFile, oldFile.fileName, importAdder, program);
144457
+ }
144458
+
144459
+ // src/services/refactors/inlineVariable.ts
144460
+ var refactorName4 = "Inline variable";
144461
+ var refactorDescription = getLocaleSpecificMessage(Diagnostics.Inline_variable);
144462
+ var inlineVariableAction = {
144463
+ name: refactorName4,
144464
+ description: refactorDescription,
144465
+ kind: "refactor.inline.variable"
144466
+ };
144467
+ registerRefactor(refactorName4, {
144468
+ kinds: [inlineVariableAction.kind],
144469
+ getAvailableActions(context) {
144470
+ const {
144471
+ file,
144472
+ program,
144473
+ preferences,
144474
+ startPosition,
144475
+ triggerReason
144476
+ } = context;
144477
+ const info = getInliningInfo(file, startPosition, triggerReason === "invoked", program);
144478
+ if (!info) {
144479
+ return emptyArray;
144480
+ }
144481
+ if (!ts_refactor_exports.isRefactorErrorInfo(info)) {
144482
+ return [{
144483
+ name: refactorName4,
144484
+ description: refactorDescription,
144485
+ actions: [inlineVariableAction]
144486
+ }];
144487
+ }
144488
+ if (preferences.provideRefactorNotApplicableReason) {
144489
+ return [{
144490
+ name: refactorName4,
144491
+ description: refactorDescription,
144492
+ actions: [{
144493
+ ...inlineVariableAction,
144494
+ notApplicableReason: info.error
144495
+ }]
144496
+ }];
144497
+ }
144498
+ return emptyArray;
144499
+ },
144500
+ getEditsForAction(context, actionName2) {
144501
+ Debug.assert(actionName2 === refactorName4, "Unexpected refactor invoked");
144502
+ const { file, program, startPosition } = context;
144503
+ const info = getInliningInfo(
144504
+ file,
144505
+ startPosition,
144506
+ /*tryWithReferenceToken*/
144507
+ true,
144508
+ program
144509
+ );
144510
+ if (!info || ts_refactor_exports.isRefactorErrorInfo(info)) {
144511
+ return void 0;
144512
+ }
144513
+ const { references, declaration, replacement } = info;
144514
+ const edits = ts_textChanges_exports.ChangeTracker.with(context, (tracker) => {
144515
+ for (const node of references) {
144516
+ tracker.replaceNode(file, node, getReplacementExpression(node, replacement));
144517
+ }
144518
+ tracker.delete(file, declaration);
144519
+ });
144520
+ return { edits };
144521
+ }
144522
+ });
144523
+ function getInliningInfo(file, startPosition, tryWithReferenceToken, program) {
144524
+ var _a, _b;
144525
+ const checker = program.getTypeChecker();
144526
+ const token = getTouchingPropertyName(file, startPosition);
144527
+ const parent2 = token.parent;
144528
+ if (!isIdentifier(token)) {
144529
+ return void 0;
144530
+ }
144531
+ if (isInitializedVariable(parent2) && isVariableDeclarationInVariableStatement(parent2) && isIdentifier(parent2.name)) {
144532
+ if (((_a = checker.getMergedSymbol(parent2.symbol).declarations) == null ? void 0 : _a.length) !== 1) {
144533
+ return { error: getLocaleSpecificMessage(Diagnostics.Variables_with_multiple_declarations_cannot_be_inlined) };
144534
+ }
144535
+ if (isDeclarationExported(parent2)) {
144536
+ return void 0;
144537
+ }
144538
+ const references = getReferenceNodes(parent2, checker, file);
144539
+ return references && { references, declaration: parent2, replacement: parent2.initializer };
144540
+ }
144541
+ if (tryWithReferenceToken) {
144542
+ let definition = checker.resolveName(
144543
+ token.text,
144544
+ token,
144545
+ 111551 /* Value */,
144546
+ /*excludeGlobals*/
144547
+ false
144548
+ );
144549
+ definition = definition && checker.getMergedSymbol(definition);
144550
+ if (((_b = definition == null ? void 0 : definition.declarations) == null ? void 0 : _b.length) !== 1) {
144551
+ return { error: getLocaleSpecificMessage(Diagnostics.Variables_with_multiple_declarations_cannot_be_inlined) };
144552
+ }
144553
+ const declaration = definition.declarations[0];
144554
+ if (!isInitializedVariable(declaration) || !isVariableDeclarationInVariableStatement(declaration) || !isIdentifier(declaration.name)) {
144555
+ return void 0;
144556
+ }
144557
+ if (isDeclarationExported(declaration)) {
144558
+ return void 0;
144559
+ }
144560
+ const references = getReferenceNodes(declaration, checker, file);
144561
+ return references && { references, declaration, replacement: declaration.initializer };
144562
+ }
144563
+ return { error: getLocaleSpecificMessage(Diagnostics.Could_not_find_variable_to_inline) };
144564
+ }
144565
+ function isDeclarationExported(declaration) {
144566
+ const variableStatement = cast(declaration.parent.parent, isVariableStatement);
144567
+ return some(variableStatement.modifiers, isExportModifier);
144568
+ }
144569
+ function getReferenceNodes(declaration, checker, file) {
144570
+ const references = [];
144571
+ const cannotInline = ts_FindAllReferences_exports.Core.eachSymbolReferenceInFile(declaration.name, checker, file, (ref) => {
144572
+ if (ts_FindAllReferences_exports.isWriteAccessForReference(ref) && !isShorthandPropertyAssignment(ref.parent)) {
144573
+ return true;
144574
+ }
144575
+ if (isExportSpecifier(ref.parent) || isExportAssignment(ref.parent)) {
144576
+ return true;
144577
+ }
144578
+ if (isTypeQueryNode(ref.parent)) {
144579
+ return true;
144580
+ }
144581
+ if (textRangeContainsPositionInclusive(declaration, ref.pos)) {
144582
+ return true;
144583
+ }
144584
+ references.push(ref);
144585
+ });
144586
+ return references.length === 0 || cannotInline ? void 0 : references;
144587
+ }
144588
+ function getReplacementExpression(reference, replacement) {
144589
+ replacement = getSynthesizedDeepClone(replacement);
144590
+ const { parent: parent2 } = reference;
144591
+ if (isExpression(parent2) && (getExpressionPrecedence(replacement) < getExpressionPrecedence(parent2) || needsParentheses(parent2))) {
144592
+ return factory.createParenthesizedExpression(replacement);
144593
+ }
144594
+ if (isFunctionLike(replacement) && (isCallLikeExpression(parent2) || isPropertyAccessExpression(parent2))) {
144595
+ return factory.createParenthesizedExpression(replacement);
144596
+ }
144597
+ if (isPropertyAccessExpression(parent2) && (isNumericLiteral(replacement) || isObjectLiteralExpression(replacement))) {
144598
+ return factory.createParenthesizedExpression(replacement);
144599
+ }
144600
+ if (isIdentifier(reference) && isShorthandPropertyAssignment(parent2)) {
144601
+ return factory.createPropertyAssignment(reference, replacement);
144602
+ }
144603
+ return replacement;
144604
+ }
144605
+
144606
+ // src/services/refactors/moveToNewFile.ts
144607
+ var refactorName5 = "Move to a new file";
144608
+ var description2 = getLocaleSpecificMessage(Diagnostics.Move_to_a_new_file);
144609
+ var moveToNewFileAction = {
144610
+ name: refactorName5,
144611
+ description: description2,
144612
+ kind: "refactor.move.newFile"
144613
+ };
144614
+ registerRefactor(refactorName5, {
144615
+ kinds: [moveToNewFileAction.kind],
144616
+ getAvailableActions: function getRefactorActionsToMoveToNewFile(context) {
144617
+ const statements = getStatementsToMove(context);
144618
+ if (context.preferences.allowTextChangesInNewFiles && statements) {
144619
+ const file = context.file;
144620
+ const affectedTextRange = {
144621
+ start: { line: getLineAndCharacterOfPosition(file, statements.all[0].getStart(file)).line, offset: getLineAndCharacterOfPosition(file, statements.all[0].getStart(file)).character },
144622
+ end: { line: getLineAndCharacterOfPosition(file, last(statements.all).end).line, offset: getLineAndCharacterOfPosition(file, last(statements.all).end).character }
144623
+ };
144624
+ return [{ name: refactorName5, description: description2, actions: [{ ...moveToNewFileAction, range: affectedTextRange }] }];
144625
+ }
144626
+ if (context.preferences.provideRefactorNotApplicableReason) {
144627
+ return [{ name: refactorName5, description: description2, actions: [{ ...moveToNewFileAction, notApplicableReason: getLocaleSpecificMessage(Diagnostics.Selection_is_not_a_valid_statement_or_statements) }] }];
144628
+ }
144629
+ return emptyArray;
144630
+ },
144631
+ getEditsForAction: function getRefactorEditsToMoveToNewFile(context, actionName2) {
144632
+ Debug.assert(actionName2 === refactorName5, "Wrong refactor invoked");
144633
+ const statements = Debug.checkDefined(getStatementsToMove(context));
144634
+ const edits = ts_textChanges_exports.ChangeTracker.with(context, (t) => doChange4(context.file, context.program, statements, t, context.host, context, context.preferences));
144635
+ return { edits, renameFilename: void 0, renameLocation: void 0 };
144636
+ }
144637
+ });
144638
+ function doChange4(oldFile, program, toMove, changes, host, context, preferences) {
144639
+ const checker = program.getTypeChecker();
144640
+ const usage = getUsageInfo(oldFile, toMove.all, checker);
144641
+ const newFilename = createNewFileName(oldFile, program, host, toMove);
144642
+ const newSourceFile = createFutureSourceFile(newFilename, oldFile.externalModuleIndicator ? 99 /* ESNext */ : oldFile.commonJsModuleIndicator ? 1 /* CommonJS */ : void 0, program, host);
144643
+ const importAdderForOldFile = ts_codefix_exports.createImportAdder(oldFile, context.program, context.preferences, context.host);
144644
+ const importAdderForNewFile = ts_codefix_exports.createImportAdder(newSourceFile, context.program, context.preferences, context.host);
144645
+ getNewStatementsAndRemoveFromOldFile(oldFile, newSourceFile, usage, changes, toMove, program, host, preferences, importAdderForNewFile, importAdderForOldFile);
144646
+ addNewFileToTsconfig(program, changes, oldFile.fileName, newFilename, hostGetCanonicalFileName(host));
144647
+ }
144648
+
144770
144649
  // src/services/_namespaces/ts.refactor.addOrRemoveBracesToArrowFunction.ts
144771
144650
  var ts_refactor_addOrRemoveBracesToArrowFunction_exports = {};
144772
144651
 
@@ -154758,6 +154637,14 @@ function createImportAdderWorker(sourceFile, program, useAutoImportProvider, pre
154758
154637
  entry.namedImports.set(symbolName2, reduceAddAsTypeOnlyValues(prevValue, addAsTypeOnly));
154759
154638
  break;
154760
154639
  case 3 /* CommonJS */:
154640
+ if (compilerOptions.verbatimModuleSyntax) {
154641
+ const prevValue2 = (entry.namedImports || (entry.namedImports = /* @__PURE__ */ new Map())).get(symbolName2);
154642
+ entry.namedImports.set(symbolName2, reduceAddAsTypeOnlyValues(prevValue2, addAsTypeOnly));
154643
+ } else {
154644
+ Debug.assert(entry.namespaceLikeImport === void 0 || entry.namespaceLikeImport.name === symbolName2, "Namespacelike import shoudl be missing or match symbolName");
154645
+ entry.namespaceLikeImport = { importKind, name: symbolName2, addAsTypeOnly };
154646
+ }
154647
+ break;
154761
154648
  case 2 /* Namespace */:
154762
154649
  Debug.assert(entry.namespaceLikeImport === void 0 || entry.namespaceLikeImport.name === symbolName2, "Namespacelike import shoudl be missing or match symbolName");
154763
154650
  entry.namespaceLikeImport = { importKind, name: symbolName2, addAsTypeOnly };
@@ -179697,7 +179584,6 @@ __export(ts_exports2, {
179697
179584
  loadWithModeAwareCache: () => loadWithModeAwareCache,
179698
179585
  makeIdentifierFromModuleName: () => makeIdentifierFromModuleName,
179699
179586
  makeImport: () => makeImport,
179700
- makeImportIfNecessary: () => makeImportIfNecessary,
179701
179587
  makeStringLiteral: () => makeStringLiteral,
179702
179588
  mangleScopedPackageName: () => mangleScopedPackageName,
179703
179589
  map: () => map,
@@ -194124,7 +194010,6 @@ if (typeof console !== "undefined") {
194124
194010
  loadWithModeAwareCache,
194125
194011
  makeIdentifierFromModuleName,
194126
194012
  makeImport,
194127
- makeImportIfNecessary,
194128
194013
  makeStringLiteral,
194129
194014
  mangleScopedPackageName,
194130
194015
  map,