typescript 5.0.0-dev.20221201 → 5.0.0-dev.20221202

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/tsserver.js CHANGED
@@ -253,6 +253,7 @@ var ts = (() => {
253
253
  canHaveModifiers: () => canHaveModifiers,
254
254
  canJsonReportNoInputFiles: () => canJsonReportNoInputFiles,
255
255
  canProduceDiagnostics: () => canProduceDiagnostics,
256
+ canUsePropertyAccess: () => canUsePropertyAccess,
256
257
  canWatchDirectoryOrFile: () => canWatchDirectoryOrFile,
257
258
  cartesianProduct: () => cartesianProduct,
258
259
  cast: () => cast,
@@ -529,6 +530,7 @@ var ts = (() => {
529
530
  createMethod: () => createMethod,
530
531
  createMethodSignature: () => createMethodSignature,
531
532
  createModeAwareCache: () => createModeAwareCache,
533
+ createModeAwareCacheKey: () => createModeAwareCacheKey,
532
534
  createModifier: () => createModifier,
533
535
  createModifiersFromModifierFlags: () => createModifiersFromModifierFlags,
534
536
  createModuleBlock: () => createModuleBlock,
@@ -1008,6 +1010,7 @@ var ts = (() => {
1008
1010
  getJSXImplicitImportBase: () => getJSXImplicitImportBase,
1009
1011
  getJSXRuntimeImport: () => getJSXRuntimeImport,
1010
1012
  getJSXTransformEnabled: () => getJSXTransformEnabled,
1013
+ getKeyForCompilerOptions: () => getKeyForCompilerOptions,
1011
1014
  getLanguageVariant: () => getLanguageVariant,
1012
1015
  getLastChild: () => getLastChild,
1013
1016
  getLeadingCommentRanges: () => getLeadingCommentRanges,
@@ -1279,6 +1282,7 @@ var ts = (() => {
1279
1282
  hasSyntacticModifier: () => hasSyntacticModifier,
1280
1283
  hasSyntacticModifiers: () => hasSyntacticModifiers,
1281
1284
  hasTSFileExtension: () => hasTSFileExtension,
1285
+ hasTabstop: () => hasTabstop,
1282
1286
  hasTrailingDirectorySeparator: () => hasTrailingDirectorySeparator,
1283
1287
  hasType: () => hasType,
1284
1288
  hasTypeArguments: () => hasTypeArguments,
@@ -1928,6 +1932,7 @@ var ts = (() => {
1928
1932
  isUnparsedSource: () => isUnparsedSource,
1929
1933
  isUnparsedTextLike: () => isUnparsedTextLike,
1930
1934
  isUrl: () => isUrl,
1935
+ isValidBigIntString: () => isValidBigIntString,
1931
1936
  isValidESSymbolDeclaration: () => isValidESSymbolDeclaration,
1932
1937
  isValidTypeOnlyAliasUseSite: () => isValidTypeOnlyAliasUseSite,
1933
1938
  isValueSignatureDeclaration: () => isValueSignatureDeclaration,
@@ -2059,6 +2064,7 @@ var ts = (() => {
2059
2064
  parameterIsThisKeyword: () => parameterIsThisKeyword,
2060
2065
  parameterNamePart: () => parameterNamePart,
2061
2066
  parseBaseNodeFactory: () => parseBaseNodeFactory,
2067
+ parseBigInt: () => parseBigInt,
2062
2068
  parseBuildCommand: () => parseBuildCommand,
2063
2069
  parseCommandLine: () => parseCommandLine,
2064
2070
  parseCommandLineWorker: () => parseCommandLineWorker,
@@ -2077,6 +2083,7 @@ var ts = (() => {
2077
2083
  parseNodeModuleFromPath: () => parseNodeModuleFromPath,
2078
2084
  parsePackageName: () => parsePackageName,
2079
2085
  parsePseudoBigInt: () => parsePseudoBigInt,
2086
+ parseValidBigInt: () => parseValidBigInt,
2080
2087
  patchWriteFileEnsuringDirectory: () => patchWriteFileEnsuringDirectory,
2081
2088
  pathContainsNodeModules: () => pathContainsNodeModules,
2082
2089
  pathIsAbsolute: () => pathIsAbsolute,
@@ -2648,7 +2655,7 @@ var ts = (() => {
2648
2655
 
2649
2656
  // src/compiler/corePublic.ts
2650
2657
  var versionMajorMinor = "5.0";
2651
- var version = `${versionMajorMinor}.0-dev.20221201`;
2658
+ var version = `${versionMajorMinor}.0-dev.20221202`;
2652
2659
  var Comparison = /* @__PURE__ */ ((Comparison3) => {
2653
2660
  Comparison3[Comparison3["LessThan"] = -1] = "LessThan";
2654
2661
  Comparison3[Comparison3["EqualTo"] = 0] = "EqualTo";
@@ -19762,6 +19769,32 @@ ${lanes.join("\n")}
19762
19769
  function pseudoBigIntToString({ negative, base10Value }) {
19763
19770
  return (negative && base10Value !== "0" ? "-" : "") + base10Value;
19764
19771
  }
19772
+ function parseBigInt(text) {
19773
+ if (!isValidBigIntString(text, false)) {
19774
+ return void 0;
19775
+ }
19776
+ return parseValidBigInt(text);
19777
+ }
19778
+ function parseValidBigInt(text) {
19779
+ const negative = text.startsWith("-");
19780
+ const base10Value = parsePseudoBigInt(`${negative ? text.slice(1) : text}n`);
19781
+ return { negative, base10Value };
19782
+ }
19783
+ function isValidBigIntString(s, roundTripOnly) {
19784
+ if (s === "")
19785
+ return false;
19786
+ const scanner2 = createScanner(99 /* ESNext */, false);
19787
+ let success = true;
19788
+ scanner2.setOnError(() => success = false);
19789
+ scanner2.setText(s + "n");
19790
+ let result = scanner2.scan();
19791
+ const negative = result === 40 /* MinusToken */;
19792
+ if (negative) {
19793
+ result = scanner2.scan();
19794
+ }
19795
+ const flags = scanner2.getTokenFlags();
19796
+ return success && result === 9 /* BigIntLiteral */ && scanner2.getTextPos() === s.length + 1 && !(flags & 512 /* ContainsSeparator */) && (!roundTripOnly || s === pseudoBigIntToString({ negative, base10Value: parsePseudoBigInt(scanner2.getTokenValue()) }));
19797
+ }
19765
19798
  function isValidTypeOnlyAliasUseSite(useSite) {
19766
19799
  return !!(useSite.flags & 16777216 /* Ambient */) || isPartOfTypeQuery(useSite) || isIdentifierInNonEmittingHeritageClause(useSite) || isPartOfPossiblyValidTypeOrAbstractComputedPropertyName(useSite) || !(isExpressionNode(useSite) || isShorthandPropertyNameUseSite(useSite));
19767
19800
  }
@@ -20088,6 +20121,17 @@ ${lanes.join("\n")}
20088
20121
  const { isBracketed, typeExpression } = node;
20089
20122
  return isBracketed || !!typeExpression && typeExpression.type.kind === 319 /* JSDocOptionalType */;
20090
20123
  }
20124
+ function canUsePropertyAccess(name, languageVersion) {
20125
+ if (name.length === 0) {
20126
+ return false;
20127
+ }
20128
+ const firstChar = name.charCodeAt(0);
20129
+ return firstChar === 35 /* hash */ ? name.length > 1 && isIdentifierStart(name.charCodeAt(1), languageVersion) : isIdentifierStart(firstChar, languageVersion);
20130
+ }
20131
+ function hasTabstop(node) {
20132
+ var _a2;
20133
+ return ((_a2 = getSnippetElement(node)) == null ? void 0 : _a2.kind) === 0 /* TabStop */;
20134
+ }
20091
20135
 
20092
20136
  // src/compiler/factory/baseNodeFactory.ts
20093
20137
  function createBaseNodeFactory() {
@@ -37716,41 +37760,86 @@ ${lanes.join("\n")}
37716
37760
  }
37717
37761
  return result;
37718
37762
  }
37719
- function createCacheWithRedirects(options) {
37720
- let ownMap = /* @__PURE__ */ new Map();
37763
+ function compilerOptionValueToString(value) {
37764
+ var _a2;
37765
+ if (value === null || typeof value !== "object") {
37766
+ return "" + value;
37767
+ }
37768
+ if (isArray(value)) {
37769
+ return `[${(_a2 = value.map((e) => compilerOptionValueToString(e))) == null ? void 0 : _a2.join(",")}]`;
37770
+ }
37771
+ let str = "{";
37772
+ for (const key in value) {
37773
+ if (hasProperty(value, key)) {
37774
+ str += `${key}: ${compilerOptionValueToString(value[key])}`;
37775
+ }
37776
+ }
37777
+ return str + "}";
37778
+ }
37779
+ function getKeyForCompilerOptions(options, affectingOptionDeclarations) {
37780
+ return affectingOptionDeclarations.map((option) => compilerOptionValueToString(getCompilerOptionValue(options, option))).join("|") + (options.pathsBasePath ? `|${options.pathsBasePath}` : void 0);
37781
+ }
37782
+ function createCacheWithRedirects(ownOptions) {
37721
37783
  const redirectsMap = /* @__PURE__ */ new Map();
37784
+ const optionsToRedirectsKey = /* @__PURE__ */ new Map();
37785
+ const redirectsKeyToMap = /* @__PURE__ */ new Map();
37786
+ let ownMap = /* @__PURE__ */ new Map();
37787
+ if (ownOptions)
37788
+ redirectsMap.set(ownOptions, ownMap);
37722
37789
  return {
37723
- getOwnMap,
37724
- redirectsMap,
37725
37790
  getOrCreateMapOfCacheRedirects,
37726
- clear: clear2,
37727
- setOwnOptions,
37728
- setOwnMap
37791
+ update,
37792
+ clear: clear2
37729
37793
  };
37730
- function getOwnMap() {
37731
- return ownMap;
37732
- }
37733
- function setOwnOptions(newOptions) {
37734
- options = newOptions;
37735
- }
37736
- function setOwnMap(newOwnMap) {
37737
- ownMap = newOwnMap;
37738
- }
37739
37794
  function getOrCreateMapOfCacheRedirects(redirectedReference) {
37740
- if (!redirectedReference) {
37741
- return ownMap;
37795
+ return redirectedReference ? getOrCreateMap(redirectedReference.commandLine.options) : ownMap;
37796
+ }
37797
+ function update(newOptions) {
37798
+ if (ownOptions !== newOptions) {
37799
+ if (ownOptions)
37800
+ ownMap = getOrCreateMap(newOptions);
37801
+ else
37802
+ redirectsMap.set(newOptions, ownMap);
37803
+ ownOptions = newOptions;
37742
37804
  }
37743
- const path = redirectedReference.sourceFile.path;
37744
- let redirects = redirectsMap.get(path);
37745
- if (!redirects) {
37746
- redirects = !options || optionsHaveModuleResolutionChanges(options, redirectedReference.commandLine.options) ? /* @__PURE__ */ new Map() : ownMap;
37747
- redirectsMap.set(path, redirects);
37805
+ }
37806
+ function getOrCreateMap(redirectOptions) {
37807
+ let result = redirectsMap.get(redirectOptions);
37808
+ if (result)
37809
+ return result;
37810
+ const key = getRedirectsCacheKey(redirectOptions);
37811
+ result = redirectsKeyToMap.get(key);
37812
+ if (!result) {
37813
+ if (ownOptions) {
37814
+ const ownKey = getRedirectsCacheKey(ownOptions);
37815
+ if (ownKey === key)
37816
+ result = ownMap;
37817
+ else if (!redirectsKeyToMap.has(ownKey))
37818
+ redirectsKeyToMap.set(ownKey, ownMap);
37819
+ }
37820
+ redirectsKeyToMap.set(key, result != null ? result : result = /* @__PURE__ */ new Map());
37748
37821
  }
37749
- return redirects;
37822
+ redirectsMap.set(redirectOptions, result);
37823
+ return result;
37750
37824
  }
37751
37825
  function clear2() {
37826
+ const ownKey = ownOptions && optionsToRedirectsKey.get(ownOptions);
37752
37827
  ownMap.clear();
37753
37828
  redirectsMap.clear();
37829
+ optionsToRedirectsKey.clear();
37830
+ redirectsKeyToMap.clear();
37831
+ if (ownOptions) {
37832
+ if (ownKey)
37833
+ optionsToRedirectsKey.set(ownOptions, ownKey);
37834
+ redirectsMap.set(ownOptions, ownMap);
37835
+ }
37836
+ }
37837
+ function getRedirectsCacheKey(options) {
37838
+ let result = optionsToRedirectsKey.get(options);
37839
+ if (!result) {
37840
+ optionsToRedirectsKey.set(options, result = getKeyForCompilerOptions(options, moduleResolutionOptionDeclarations));
37841
+ }
37842
+ return result;
37754
37843
  }
37755
37844
  }
37756
37845
  function createPackageJsonInfoCache(currentDirectory, getCanonicalFileName) {
@@ -37782,27 +37871,6 @@ ${lanes.join("\n")}
37782
37871
  }
37783
37872
  return result;
37784
37873
  }
37785
- function updateRedirectsMap(options, directoryToModuleNameMap, moduleNameToDirectoryMap) {
37786
- if (!options.configFile)
37787
- return;
37788
- if (directoryToModuleNameMap.redirectsMap.size === 0) {
37789
- Debug.assert(!moduleNameToDirectoryMap || moduleNameToDirectoryMap.redirectsMap.size === 0);
37790
- Debug.assert(directoryToModuleNameMap.getOwnMap().size === 0);
37791
- Debug.assert(!moduleNameToDirectoryMap || moduleNameToDirectoryMap.getOwnMap().size === 0);
37792
- directoryToModuleNameMap.redirectsMap.set(options.configFile.path, directoryToModuleNameMap.getOwnMap());
37793
- moduleNameToDirectoryMap == null ? void 0 : moduleNameToDirectoryMap.redirectsMap.set(options.configFile.path, moduleNameToDirectoryMap.getOwnMap());
37794
- } else {
37795
- Debug.assert(!moduleNameToDirectoryMap || moduleNameToDirectoryMap.redirectsMap.size > 0);
37796
- const ref = {
37797
- sourceFile: options.configFile,
37798
- commandLine: { options }
37799
- };
37800
- directoryToModuleNameMap.setOwnMap(directoryToModuleNameMap.getOrCreateMapOfCacheRedirects(ref));
37801
- moduleNameToDirectoryMap == null ? void 0 : moduleNameToDirectoryMap.setOwnMap(moduleNameToDirectoryMap.getOrCreateMapOfCacheRedirects(ref));
37802
- }
37803
- directoryToModuleNameMap.setOwnOptions(options);
37804
- moduleNameToDirectoryMap == null ? void 0 : moduleNameToDirectoryMap.setOwnOptions(options);
37805
- }
37806
37874
  function createPerDirectoryResolutionCache(currentDirectory, getCanonicalFileName, directoryToModuleNameMap) {
37807
37875
  return {
37808
37876
  getOrCreateCacheForDirectory,
@@ -37813,13 +37881,16 @@ ${lanes.join("\n")}
37813
37881
  directoryToModuleNameMap.clear();
37814
37882
  }
37815
37883
  function update(options) {
37816
- updateRedirectsMap(options, directoryToModuleNameMap);
37884
+ directoryToModuleNameMap.update(options);
37817
37885
  }
37818
37886
  function getOrCreateCacheForDirectory(directoryName, redirectedReference) {
37819
37887
  const path = toPath(directoryName, currentDirectory, getCanonicalFileName);
37820
37888
  return getOrCreateCache(directoryToModuleNameMap, redirectedReference, path, () => createModeAwareCache());
37821
37889
  }
37822
37890
  }
37891
+ function createModeAwareCacheKey(specifier, mode) {
37892
+ return mode === void 0 ? specifier : `${mode}|${specifier}`;
37893
+ }
37823
37894
  function createModeAwareCache() {
37824
37895
  const underlying = /* @__PURE__ */ new Map();
37825
37896
  const memoizedReverseKeys = /* @__PURE__ */ new Map();
@@ -37850,7 +37921,7 @@ ${lanes.join("\n")}
37850
37921
  };
37851
37922
  return cache;
37852
37923
  function getUnderlyingCacheKey(specifier, mode) {
37853
- const result = mode === void 0 ? specifier : `${mode}|${specifier}`;
37924
+ const result = createModeAwareCacheKey(specifier, mode);
37854
37925
  memoizedReverseKeys.set(result, [specifier, mode]);
37855
37926
  return result;
37856
37927
  }
@@ -37870,9 +37941,10 @@ ${lanes.join("\n")}
37870
37941
  }
37871
37942
  return map2;
37872
37943
  }
37873
- function createModuleResolutionCache(currentDirectory, getCanonicalFileName, options, directoryToModuleNameMap, moduleNameToDirectoryMap) {
37874
- const perDirectoryResolutionCache = createPerDirectoryResolutionCache(currentDirectory, getCanonicalFileName, directoryToModuleNameMap || (directoryToModuleNameMap = createCacheWithRedirects(options)));
37875
- moduleNameToDirectoryMap || (moduleNameToDirectoryMap = createCacheWithRedirects(options));
37944
+ function createModuleResolutionCache(currentDirectory, getCanonicalFileName, options) {
37945
+ const directoryToModuleNameMap = createCacheWithRedirects(options);
37946
+ const perDirectoryResolutionCache = createPerDirectoryResolutionCache(currentDirectory, getCanonicalFileName, directoryToModuleNameMap);
37947
+ const moduleNameToDirectoryMap = createCacheWithRedirects(options);
37876
37948
  const packageJsonInfoCache = createPackageJsonInfoCache(currentDirectory, getCanonicalFileName);
37877
37949
  return {
37878
37950
  ...packageJsonInfoCache,
@@ -37892,11 +37964,12 @@ ${lanes.join("\n")}
37892
37964
  moduleNameToDirectoryMap.clear();
37893
37965
  }
37894
37966
  function update(options2) {
37895
- updateRedirectsMap(options2, directoryToModuleNameMap, moduleNameToDirectoryMap);
37967
+ directoryToModuleNameMap.update(options2);
37968
+ moduleNameToDirectoryMap.update(options2);
37896
37969
  }
37897
37970
  function getOrCreateCacheForModuleName(nonRelativeModuleName, mode, redirectedReference) {
37898
37971
  Debug.assert(!isExternalModuleNameRelative(nonRelativeModuleName));
37899
- return getOrCreateCache(moduleNameToDirectoryMap, redirectedReference, mode === void 0 ? nonRelativeModuleName : `${mode}|${nonRelativeModuleName}`, createPerModuleNameCache);
37972
+ return getOrCreateCache(moduleNameToDirectoryMap, redirectedReference, createModeAwareCacheKey(nonRelativeModuleName, mode), createPerModuleNameCache);
37900
37973
  }
37901
37974
  function createPerModuleNameCache() {
37902
37975
  const directoryPathMap = /* @__PURE__ */ new Map();
@@ -37944,8 +38017,9 @@ ${lanes.join("\n")}
37944
38017
  }
37945
38018
  }
37946
38019
  }
37947
- function createTypeReferenceDirectiveResolutionCache(currentDirectory, getCanonicalFileName, options, packageJsonInfoCache, directoryToModuleNameMap) {
37948
- const perDirectoryResolutionCache = createPerDirectoryResolutionCache(currentDirectory, getCanonicalFileName, directoryToModuleNameMap || (directoryToModuleNameMap = createCacheWithRedirects(options)));
38020
+ function createTypeReferenceDirectiveResolutionCache(currentDirectory, getCanonicalFileName, options, packageJsonInfoCache) {
38021
+ const directoryToModuleNameMap = createCacheWithRedirects(options);
38022
+ const perDirectoryResolutionCache = createPerDirectoryResolutionCache(currentDirectory, getCanonicalFileName, directoryToModuleNameMap);
37949
38023
  packageJsonInfoCache || (packageJsonInfoCache = createPackageJsonInfoCache(currentDirectory, getCanonicalFileName));
37950
38024
  return {
37951
38025
  ...packageJsonInfoCache,
@@ -47713,7 +47787,7 @@ ${lanes.join("\n")}
47713
47787
  }
47714
47788
  const contextFile = getSourceFileOfNode(getOriginalNode(context.enclosingDeclaration));
47715
47789
  const resolutionMode = overrideImportMode || (contextFile == null ? void 0 : contextFile.impliedNodeFormat);
47716
- const cacheKey = getSpecifierCacheKey(contextFile.path, resolutionMode);
47790
+ const cacheKey = createModeAwareCacheKey(contextFile.path, resolutionMode);
47717
47791
  const links = getSymbolLinks(symbol);
47718
47792
  let specifier = links.specifierCache && links.specifierCache.get(cacheKey);
47719
47793
  if (!specifier) {
@@ -47736,9 +47810,6 @@ ${lanes.join("\n")}
47736
47810
  links.specifierCache.set(cacheKey, specifier);
47737
47811
  }
47738
47812
  return specifier;
47739
- function getSpecifierCacheKey(path, mode) {
47740
- return mode === void 0 ? path : `${mode}|${path}`;
47741
- }
47742
47813
  }
47743
47814
  function symbolToEntityNameNode(symbol) {
47744
47815
  const identifier = factory.createIdentifier(unescapeLeadingUnderscores(symbol.escapedName));
@@ -47952,8 +48023,7 @@ ${lanes.join("\n")}
47952
48023
  if (isSingleOrDoubleQuote(firstChar) && some(symbol2.declarations, hasNonGlobalAugmentationExternalModuleSymbol)) {
47953
48024
  return factory.createStringLiteral(getSpecifierForModuleSymbol(symbol2, context));
47954
48025
  }
47955
- const canUsePropertyAccess = firstChar === 35 /* hash */ ? symbolName2.length > 1 && isIdentifierStart(symbolName2.charCodeAt(1), languageVersion) : isIdentifierStart(firstChar, languageVersion);
47956
- if (index === 0 || canUsePropertyAccess) {
48026
+ if (index === 0 || canUsePropertyAccess(symbolName2, languageVersion)) {
47957
48027
  const identifier = setEmitFlags(factory.createIdentifier(symbolName2, typeParameterNodes), 33554432 /* NoAsciiEscaping */);
47958
48028
  identifier.symbol = symbol2;
47959
48029
  return index > 0 ? factory.createPropertyAccessExpression(createExpressionFromSymbolChain(chain2, index - 1), identifier) : identifier;
@@ -60025,24 +60095,7 @@ ${lanes.join("\n")}
60025
60095
  return isFinite(n) && (!roundTripOnly || "" + n === s);
60026
60096
  }
60027
60097
  function parseBigIntLiteralType(text) {
60028
- const negative = text.startsWith("-");
60029
- const base10Value = parsePseudoBigInt(`${negative ? text.slice(1) : text}n`);
60030
- return getBigIntLiteralType({ negative, base10Value });
60031
- }
60032
- function isValidBigIntString(s, roundTripOnly) {
60033
- if (s === "")
60034
- return false;
60035
- const scanner2 = createScanner(99 /* ESNext */, false);
60036
- let success = true;
60037
- scanner2.setOnError(() => success = false);
60038
- scanner2.setText(s + "n");
60039
- let result = scanner2.scan();
60040
- const negative = result === 40 /* MinusToken */;
60041
- if (negative) {
60042
- result = scanner2.scan();
60043
- }
60044
- const flags = scanner2.getTokenFlags();
60045
- return success && result === 9 /* BigIntLiteral */ && scanner2.getTextPos() === s.length + 1 && !(flags & 512 /* ContainsSeparator */) && (!roundTripOnly || s === pseudoBigIntToString({ negative, base10Value: parsePseudoBigInt(scanner2.getTokenValue()) }));
60098
+ return getBigIntLiteralType(parseValidBigInt(text));
60046
60099
  }
60047
60100
  function isMemberOfStringMapping(source, target) {
60048
60101
  if (target.flags & (4 /* String */ | 1 /* Any */)) {
@@ -67514,11 +67567,11 @@ ${lanes.join("\n")}
67514
67567
  }
67515
67568
  function checkSatisfiesExpression(node) {
67516
67569
  checkSourceElement(node.type);
67570
+ const exprType = checkExpression(node.expression);
67517
67571
  const targetType = getTypeFromTypeNode(node.type);
67518
67572
  if (isErrorType(targetType)) {
67519
67573
  return targetType;
67520
67574
  }
67521
- const exprType = checkExpression(node.expression);
67522
67575
  checkTypeAssignableToAndOptionallyElaborate(exprType, targetType, node.type, node.expression, Diagnostics.Type_0_does_not_satisfy_the_expected_type_1);
67523
67576
  return exprType;
67524
67577
  }
@@ -102391,16 +102444,15 @@ ${lanes.join("\n")}
102391
102444
  return [];
102392
102445
  }
102393
102446
  const resolutions = [];
102394
- const cache = /* @__PURE__ */ new Map();
102447
+ const cache = createModeAwareCache();
102395
102448
  for (const name of names) {
102396
102449
  let result;
102397
102450
  const mode = getModeForFileReference(name, containingFileMode);
102398
102451
  const strName = getResolutionName(name);
102399
- const cacheKey = mode !== void 0 ? `${mode}|${strName}` : strName;
102400
- if (cache.has(cacheKey)) {
102401
- result = cache.get(cacheKey);
102452
+ if (cache.has(strName, mode)) {
102453
+ result = cache.get(strName, mode);
102402
102454
  } else {
102403
- cache.set(cacheKey, result = loader(strName, containingFile, redirectedReference, mode));
102455
+ cache.set(strName, mode, result = loader(strName, containingFile, redirectedReference, mode));
102404
102456
  }
102405
102457
  resolutions.push(result);
102406
102458
  }
@@ -102476,18 +102528,17 @@ ${lanes.join("\n")}
102476
102528
  return [];
102477
102529
  }
102478
102530
  const resolutions = [];
102479
- const cache = /* @__PURE__ */ new Map();
102531
+ const cache = createModeAwareCache();
102480
102532
  let i = 0;
102481
102533
  for (const entry of resolutionInfo ? resolutionInfo.names : names) {
102482
102534
  let result;
102483
102535
  const mode = !isString(entry) ? getModeForUsageLocation(containingFile, entry) : getModeForResolutionAtIndex(containingFile, i);
102484
102536
  i++;
102485
102537
  const name = isString(entry) ? entry : entry.text;
102486
- const cacheKey = mode !== void 0 ? `${mode}|${name}` : name;
102487
- if (cache.has(cacheKey)) {
102488
- result = cache.get(cacheKey);
102538
+ if (cache.has(name, mode)) {
102539
+ result = cache.get(name, mode);
102489
102540
  } else {
102490
- cache.set(cacheKey, result = loader(name, mode, containingFileName, redirectedReference));
102541
+ cache.set(name, mode, result = loader(name, mode, containingFileName, redirectedReference));
102491
102542
  }
102492
102543
  resolutions.push(result);
102493
102544
  }
@@ -107013,23 +107064,17 @@ ${lanes.join("\n")}
107013
107064
  const getCurrentDirectory = memoize(() => resolutionHost.getCurrentDirectory());
107014
107065
  const cachedDirectoryStructureHost = resolutionHost.getCachedDirectoryStructureHost();
107015
107066
  const resolvedModuleNames = /* @__PURE__ */ new Map();
107016
- const perDirectoryResolvedModuleNames = createCacheWithRedirects();
107017
- const nonRelativeModuleNameCache = createCacheWithRedirects();
107018
107067
  const moduleResolutionCache = createModuleResolutionCache(
107019
107068
  getCurrentDirectory(),
107020
107069
  resolutionHost.getCanonicalFileName,
107021
- void 0,
107022
- perDirectoryResolvedModuleNames,
107023
- nonRelativeModuleNameCache
107070
+ resolutionHost.getCompilationSettings()
107024
107071
  );
107025
107072
  const resolvedTypeReferenceDirectives = /* @__PURE__ */ new Map();
107026
- const perDirectoryResolvedTypeReferenceDirectives = createCacheWithRedirects();
107027
107073
  const typeReferenceDirectiveResolutionCache = createTypeReferenceDirectiveResolutionCache(
107028
107074
  getCurrentDirectory(),
107029
107075
  resolutionHost.getCanonicalFileName,
107030
- void 0,
107031
- moduleResolutionCache.getPackageJsonInfoCache(),
107032
- perDirectoryResolvedTypeReferenceDirectives
107076
+ resolutionHost.getCompilationSettings(),
107077
+ moduleResolutionCache.getPackageJsonInfoCache()
107033
107078
  );
107034
107079
  const failedLookupDefaultExtensions = [".ts" /* Ts */, ".tsx" /* Tsx */, ".js" /* Js */, ".jsx" /* Jsx */, ".json" /* Json */];
107035
107080
  const customFailedLookupPaths = /* @__PURE__ */ new Map();
@@ -107090,6 +107135,8 @@ ${lanes.join("\n")}
107090
107135
  affectingPathChecksForFile = void 0;
107091
107136
  moduleResolutionCache.clear();
107092
107137
  typeReferenceDirectiveResolutionCache.clear();
107138
+ moduleResolutionCache.update(resolutionHost.getCompilationSettings());
107139
+ typeReferenceDirectiveResolutionCache.update(resolutionHost.getCompilationSettings());
107093
107140
  impliedFormatPackageJsons.clear();
107094
107141
  hasChangedAutomaticTypeDirectiveNames = false;
107095
107142
  }
@@ -107194,8 +107241,7 @@ ${lanes.join("\n")}
107194
107241
  names,
107195
107242
  containingFile,
107196
107243
  redirectedReference,
107197
- cache,
107198
- perDirectoryCacheWithRedirects,
107244
+ perFileCache,
107199
107245
  loader,
107200
107246
  getResolutionWithResolvedFileName,
107201
107247
  shouldRetryResolution,
@@ -107205,16 +107251,9 @@ ${lanes.join("\n")}
107205
107251
  containingSourceFile,
107206
107252
  containingSourceFileMode
107207
107253
  }) {
107208
- var _a2, _b, _c, _d;
107254
+ var _a2, _b, _c;
107209
107255
  const path = resolutionHost.toPath(containingFile);
107210
- const resolutionsInFile = cache.get(path) || cache.set(path, createModeAwareCache()).get(path);
107211
- const dirPath = getDirectoryPath(path);
107212
- const perDirectoryCache = perDirectoryCacheWithRedirects.getOrCreateMapOfCacheRedirects(redirectedReference);
107213
- let perDirectoryResolution = perDirectoryCache.get(dirPath);
107214
- if (!perDirectoryResolution) {
107215
- perDirectoryResolution = createModeAwareCache();
107216
- perDirectoryCache.set(dirPath, perDirectoryResolution);
107217
- }
107256
+ const resolutionsInFile = perFileCache.get(path) || perFileCache.set(path, createModeAwareCache()).get(path);
107218
107257
  const resolvedModules = [];
107219
107258
  const compilerOptions = resolutionHost.getCompilationSettings();
107220
107259
  const hasInvalidatedNonRelativeUnresolvedImport = logChanges && isFileWithInvalidatedNonRelativeUnresolvedImports(path);
@@ -107230,28 +107269,9 @@ ${lanes.join("\n")}
107230
107269
  let resolution = resolutionsInFile.get(name, mode);
107231
107270
  if (!seenNamesInFile.has(name, mode) && unmatchedRedirects || !resolution || resolution.isInvalidated || hasInvalidatedNonRelativeUnresolvedImport && !isExternalModuleNameRelative(name) && shouldRetryResolution(resolution)) {
107232
107271
  const existingResolution = resolution;
107233
- const resolutionInDirectory = perDirectoryResolution.get(name, mode);
107234
- if (resolutionInDirectory) {
107235
- resolution = resolutionInDirectory;
107236
- const host = ((_a2 = resolutionHost.getCompilerHost) == null ? void 0 : _a2.call(resolutionHost)) || resolutionHost;
107237
- if (isTraceEnabled(compilerOptions, host)) {
107238
- const resolved = getResolutionWithResolvedFileName(resolution);
107239
- trace(
107240
- host,
107241
- loader === resolveModuleName2 ? (resolved == null ? void 0 : resolved.resolvedFileName) ? resolved.packageId ? Diagnostics.Reusing_resolution_of_module_0_from_1_found_in_cache_from_location_2_it_was_successfully_resolved_to_3_with_Package_ID_4 : Diagnostics.Reusing_resolution_of_module_0_from_1_found_in_cache_from_location_2_it_was_successfully_resolved_to_3 : Diagnostics.Reusing_resolution_of_module_0_from_1_found_in_cache_from_location_2_it_was_not_resolved : (resolved == null ? void 0 : resolved.resolvedFileName) ? resolved.packageId ? Diagnostics.Reusing_resolution_of_type_reference_directive_0_from_1_found_in_cache_from_location_2_it_was_successfully_resolved_to_3_with_Package_ID_4 : Diagnostics.Reusing_resolution_of_type_reference_directive_0_from_1_found_in_cache_from_location_2_it_was_successfully_resolved_to_3 : Diagnostics.Reusing_resolution_of_type_reference_directive_0_from_1_found_in_cache_from_location_2_it_was_not_resolved,
107242
- name,
107243
- containingFile,
107244
- getDirectoryPath(containingFile),
107245
- resolved == null ? void 0 : resolved.resolvedFileName,
107246
- (resolved == null ? void 0 : resolved.packageId) && packageIdToString(resolved.packageId)
107247
- );
107248
- }
107249
- } else {
107250
- resolution = loader(name, containingFile, compilerOptions, ((_b = resolutionHost.getCompilerHost) == null ? void 0 : _b.call(resolutionHost)) || resolutionHost, redirectedReference, containingSourceFile, mode);
107251
- perDirectoryResolution.set(name, mode, resolution);
107252
- if (resolutionHost.onDiscoveredSymlink && resolutionIsSymlink(resolution)) {
107253
- resolutionHost.onDiscoveredSymlink();
107254
- }
107272
+ resolution = loader(name, containingFile, compilerOptions, ((_a2 = resolutionHost.getCompilerHost) == null ? void 0 : _a2.call(resolutionHost)) || resolutionHost, redirectedReference, containingSourceFile, mode);
107273
+ if (resolutionHost.onDiscoveredSymlink && resolutionIsSymlink(resolution)) {
107274
+ resolutionHost.onDiscoveredSymlink();
107255
107275
  }
107256
107276
  resolutionsInFile.set(name, mode, resolution);
107257
107277
  watchFailedLookupLocationsOfExternalModuleResolutions(name, resolution, path, getResolutionWithResolvedFileName);
@@ -107263,7 +107283,7 @@ ${lanes.join("\n")}
107263
107283
  logChanges = false;
107264
107284
  }
107265
107285
  } else {
107266
- const host = ((_c = resolutionHost.getCompilerHost) == null ? void 0 : _c.call(resolutionHost)) || resolutionHost;
107286
+ const host = ((_b = resolutionHost.getCompilerHost) == null ? void 0 : _b.call(resolutionHost)) || resolutionHost;
107267
107287
  if (isTraceEnabled(compilerOptions, host) && !seenNamesInFile.has(name, mode)) {
107268
107288
  const resolved = getResolutionWithResolvedFileName(resolution);
107269
107289
  trace(
@@ -107281,7 +107301,7 @@ ${lanes.join("\n")}
107281
107301
  resolvedModules.push(getResolutionWithResolvedFileName(resolution));
107282
107302
  }
107283
107303
  if (resolutionInfo && (loader === resolveTypeReferenceDirective2 || containingSourceFile)) {
107284
- (_d = resolutionInfo.reusedNames) == null ? void 0 : _d.forEach((entry) => seenNamesInFile.set(
107304
+ (_c = resolutionInfo.reusedNames) == null ? void 0 : _c.forEach((entry) => seenNamesInFile.set(
107285
107305
  getResolutionName(entry),
107286
107306
  !isString(entry) && isStringLiteralLike(entry) ? getModeForUsageLocation(containingSourceFile, entry) : getModeForFileReference(entry, containingSourceFileMode),
107287
107307
  true
@@ -107320,8 +107340,7 @@ ${lanes.join("\n")}
107320
107340
  names: typeDirectiveNames,
107321
107341
  containingFile,
107322
107342
  redirectedReference,
107323
- cache: resolvedTypeReferenceDirectives,
107324
- perDirectoryCacheWithRedirects: perDirectoryResolvedTypeReferenceDirectives,
107343
+ perFileCache: resolvedTypeReferenceDirectives,
107325
107344
  loader: resolveTypeReferenceDirective2,
107326
107345
  getResolutionWithResolvedFileName: getResolvedTypeReferenceDirective2,
107327
107346
  shouldRetryResolution: (resolution) => resolution.resolvedTypeReferenceDirective === void 0,
@@ -107334,8 +107353,7 @@ ${lanes.join("\n")}
107334
107353
  names: moduleNames,
107335
107354
  containingFile,
107336
107355
  redirectedReference,
107337
- cache: resolvedModuleNames,
107338
- perDirectoryCacheWithRedirects: perDirectoryResolvedModuleNames,
107356
+ perFileCache: resolvedModuleNames,
107339
107357
  loader: resolveModuleName2,
107340
107358
  getResolutionWithResolvedFileName: getResolvedModule2,
107341
107359
  shouldRetryResolution: (resolution) => !resolution.resolvedModule || !resolutionExtensionIsTSOrJson(resolution.resolvedModule.extension),
@@ -111584,6 +111602,7 @@ ${lanes.join("\n")}
111584
111602
  canHaveModifiers: () => canHaveModifiers,
111585
111603
  canJsonReportNoInputFiles: () => canJsonReportNoInputFiles,
111586
111604
  canProduceDiagnostics: () => canProduceDiagnostics,
111605
+ canUsePropertyAccess: () => canUsePropertyAccess,
111587
111606
  canWatchDirectoryOrFile: () => canWatchDirectoryOrFile,
111588
111607
  cartesianProduct: () => cartesianProduct,
111589
111608
  cast: () => cast,
@@ -111860,6 +111879,7 @@ ${lanes.join("\n")}
111860
111879
  createMethod: () => createMethod,
111861
111880
  createMethodSignature: () => createMethodSignature,
111862
111881
  createModeAwareCache: () => createModeAwareCache,
111882
+ createModeAwareCacheKey: () => createModeAwareCacheKey,
111863
111883
  createModifier: () => createModifier,
111864
111884
  createModifiersFromModifierFlags: () => createModifiersFromModifierFlags,
111865
111885
  createModuleBlock: () => createModuleBlock,
@@ -112339,6 +112359,7 @@ ${lanes.join("\n")}
112339
112359
  getJSXImplicitImportBase: () => getJSXImplicitImportBase,
112340
112360
  getJSXRuntimeImport: () => getJSXRuntimeImport,
112341
112361
  getJSXTransformEnabled: () => getJSXTransformEnabled,
112362
+ getKeyForCompilerOptions: () => getKeyForCompilerOptions,
112342
112363
  getLanguageVariant: () => getLanguageVariant,
112343
112364
  getLastChild: () => getLastChild,
112344
112365
  getLeadingCommentRanges: () => getLeadingCommentRanges,
@@ -112610,6 +112631,7 @@ ${lanes.join("\n")}
112610
112631
  hasSyntacticModifier: () => hasSyntacticModifier,
112611
112632
  hasSyntacticModifiers: () => hasSyntacticModifiers,
112612
112633
  hasTSFileExtension: () => hasTSFileExtension,
112634
+ hasTabstop: () => hasTabstop,
112613
112635
  hasTrailingDirectorySeparator: () => hasTrailingDirectorySeparator,
112614
112636
  hasType: () => hasType,
112615
112637
  hasTypeArguments: () => hasTypeArguments,
@@ -113259,6 +113281,7 @@ ${lanes.join("\n")}
113259
113281
  isUnparsedSource: () => isUnparsedSource,
113260
113282
  isUnparsedTextLike: () => isUnparsedTextLike,
113261
113283
  isUrl: () => isUrl,
113284
+ isValidBigIntString: () => isValidBigIntString,
113262
113285
  isValidESSymbolDeclaration: () => isValidESSymbolDeclaration,
113263
113286
  isValidTypeOnlyAliasUseSite: () => isValidTypeOnlyAliasUseSite,
113264
113287
  isValueSignatureDeclaration: () => isValueSignatureDeclaration,
@@ -113390,6 +113413,7 @@ ${lanes.join("\n")}
113390
113413
  parameterIsThisKeyword: () => parameterIsThisKeyword,
113391
113414
  parameterNamePart: () => parameterNamePart,
113392
113415
  parseBaseNodeFactory: () => parseBaseNodeFactory,
113416
+ parseBigInt: () => parseBigInt,
113393
113417
  parseBuildCommand: () => parseBuildCommand,
113394
113418
  parseCommandLine: () => parseCommandLine,
113395
113419
  parseCommandLineWorker: () => parseCommandLineWorker,
@@ -113408,6 +113432,7 @@ ${lanes.join("\n")}
113408
113432
  parseNodeModuleFromPath: () => parseNodeModuleFromPath,
113409
113433
  parsePackageName: () => parsePackageName,
113410
113434
  parsePseudoBigInt: () => parsePseudoBigInt,
113435
+ parseValidBigInt: () => parseValidBigInt,
113411
113436
  patchWriteFileEnsuringDirectory: () => patchWriteFileEnsuringDirectory,
113412
113437
  pathContainsNodeModules: () => pathContainsNodeModules,
113413
113438
  pathIsAbsolute: () => pathIsAbsolute,
@@ -118496,24 +118521,8 @@ ${lanes.join("\n")}
118496
118521
  getKeyForCompilationSettings
118497
118522
  };
118498
118523
  }
118499
- function compilerOptionValueToString(value) {
118500
- var _a2;
118501
- if (value === null || typeof value !== "object") {
118502
- return "" + value;
118503
- }
118504
- if (isArray(value)) {
118505
- return `[${(_a2 = map(value, (e) => compilerOptionValueToString(e))) == null ? void 0 : _a2.join(",")}]`;
118506
- }
118507
- let str = "{";
118508
- for (const key in value) {
118509
- if (hasProperty(value, key)) {
118510
- str += `${key}: ${compilerOptionValueToString(value[key])}`;
118511
- }
118512
- }
118513
- return str + "}";
118514
- }
118515
118524
  function getKeyForCompilationSettings(settings) {
118516
- return sourceFileAffectingCompilerOptions.map((option) => compilerOptionValueToString(getCompilerOptionValue(settings, option))).join("|") + (settings.pathsBasePath ? `|${settings.pathsBasePath}` : void 0);
118525
+ return getKeyForCompilerOptions(settings, sourceFileAffectingCompilerOptions);
118517
118526
  }
118518
118527
  function getDocumentRegistryBucketKeyWithMode(key, mode) {
118519
118528
  return mode ? `${key}|${mode}` : key;
@@ -120728,6 +120737,9 @@ ${lanes.join("\n")}
120728
120737
  const textPos = scanner.getTextPos();
120729
120738
  if (textPos <= end) {
120730
120739
  if (token === 79 /* Identifier */) {
120740
+ if (hasTabstop(parent2)) {
120741
+ continue;
120742
+ }
120731
120743
  Debug.fail(`Did not expect ${Debug.formatSyntaxKind(parent2.kind)} to have an Identifier in its trivia`);
120732
120744
  }
120733
120745
  nodes.push(createNode(token, pos, textPos, parent2));
@@ -133122,6 +133134,7 @@ ${lanes.join("\n")}
133122
133134
  CompletionSource2["ClassMemberSnippet"] = "ClassMemberSnippet/";
133123
133135
  CompletionSource2["TypeOnlyAlias"] = "TypeOnlyAlias/";
133124
133136
  CompletionSource2["ObjectLiteralMethodSnippet"] = "ObjectLiteralMethodSnippet/";
133137
+ CompletionSource2["SwitchCases"] = "SwitchCases/";
133125
133138
  return CompletionSource2;
133126
133139
  })(CompletionSource || {});
133127
133140
  var SymbolOriginInfoKind = /* @__PURE__ */ ((SymbolOriginInfoKind2) => {
@@ -133452,6 +133465,13 @@ ${lanes.join("\n")}
133452
133465
  if (!isChecked) {
133453
133466
  getJSCompletionEntries(sourceFile, location2.pos, uniqueNames, getEmitScriptTarget(compilerOptions), entries);
133454
133467
  }
133468
+ let caseBlock;
133469
+ if (preferences.includeCompletionsWithInsertText && contextToken && (caseBlock = findAncestor(contextToken, isCaseBlock))) {
133470
+ const cases = getExhaustiveCaseSnippets(caseBlock, sourceFile, preferences, compilerOptions, host, program, formatContext);
133471
+ if (cases) {
133472
+ entries.push(cases.entry);
133473
+ }
133474
+ }
133455
133475
  return {
133456
133476
  flags: completionData.flags,
133457
133477
  isGlobalCompletion: isInSnippetScope,
@@ -133465,6 +133485,187 @@ ${lanes.join("\n")}
133465
133485
  function isCheckedFile(sourceFile, compilerOptions) {
133466
133486
  return !isSourceFileJS(sourceFile) || !!isCheckJsEnabledForFile(sourceFile, compilerOptions);
133467
133487
  }
133488
+ function getExhaustiveCaseSnippets(caseBlock, sourceFile, preferences, options, host, program, formatContext) {
133489
+ const clauses = caseBlock.clauses;
133490
+ const checker = program.getTypeChecker();
133491
+ const switchType = checker.getTypeAtLocation(caseBlock.parent.expression);
133492
+ if (switchType && switchType.isUnion() && every(switchType.types, (type) => type.isLiteral())) {
133493
+ const tracker = newCaseClauseTracker(checker, clauses);
133494
+ const target = getEmitScriptTarget(options);
133495
+ const quotePreference = getQuotePreference(sourceFile, preferences);
133496
+ const importAdder = ts_codefix_exports.createImportAdder(sourceFile, program, preferences, host);
133497
+ const elements = [];
133498
+ for (const type of switchType.types) {
133499
+ if (type.flags & 1024 /* EnumLiteral */) {
133500
+ Debug.assert(type.symbol, "An enum member type should have a symbol");
133501
+ Debug.assert(type.symbol.parent, "An enum member type should have a parent symbol (the enum symbol)");
133502
+ const enumValue = type.symbol.valueDeclaration && checker.getConstantValue(type.symbol.valueDeclaration);
133503
+ if (enumValue !== void 0) {
133504
+ if (tracker.hasValue(enumValue)) {
133505
+ continue;
133506
+ }
133507
+ tracker.addValue(enumValue);
133508
+ }
133509
+ const typeNode = ts_codefix_exports.typeToAutoImportableTypeNode(checker, importAdder, type, caseBlock, target);
133510
+ if (!typeNode) {
133511
+ return void 0;
133512
+ }
133513
+ const expr = typeNodeToExpression(typeNode, target, quotePreference);
133514
+ if (!expr) {
133515
+ return void 0;
133516
+ }
133517
+ elements.push(expr);
133518
+ } else if (!tracker.hasValue(type.value)) {
133519
+ switch (typeof type.value) {
133520
+ case "object":
133521
+ elements.push(factory.createBigIntLiteral(type.value));
133522
+ break;
133523
+ case "number":
133524
+ elements.push(factory.createNumericLiteral(type.value));
133525
+ break;
133526
+ case "string":
133527
+ elements.push(factory.createStringLiteral(type.value));
133528
+ break;
133529
+ }
133530
+ }
133531
+ }
133532
+ if (elements.length === 0) {
133533
+ return void 0;
133534
+ }
133535
+ const newClauses = map(elements, (element) => factory.createCaseClause(element, []));
133536
+ const newLineChar = getNewLineCharacter(options, maybeBind(host, host.getNewLine));
133537
+ const printer = createSnippetPrinter({
133538
+ removeComments: true,
133539
+ module: options.module,
133540
+ target: options.target,
133541
+ newLine: getNewLineKind(newLineChar)
133542
+ });
133543
+ const printNode = formatContext ? (node) => printer.printAndFormatNode(4 /* Unspecified */, node, sourceFile, formatContext) : (node) => printer.printNode(4 /* Unspecified */, node, sourceFile);
133544
+ const insertText = map(newClauses, (clause, i) => {
133545
+ if (preferences.includeCompletionsWithSnippetText) {
133546
+ return `${printNode(clause)}$${i + 1}`;
133547
+ }
133548
+ return `${printNode(clause)}`;
133549
+ }).join(newLineChar);
133550
+ const firstClause = printer.printNode(4 /* Unspecified */, newClauses[0], sourceFile);
133551
+ return {
133552
+ entry: {
133553
+ name: `${firstClause} ...`,
133554
+ kind: "" /* unknown */,
133555
+ sortText: SortText.GlobalsOrKeywords,
133556
+ insertText,
133557
+ hasAction: importAdder.hasFixes() || void 0,
133558
+ source: "SwitchCases/" /* SwitchCases */,
133559
+ isSnippet: preferences.includeCompletionsWithSnippetText ? true : void 0
133560
+ },
133561
+ importAdder
133562
+ };
133563
+ }
133564
+ return void 0;
133565
+ }
133566
+ function newCaseClauseTracker(checker, clauses) {
133567
+ const existingStrings = /* @__PURE__ */ new Set();
133568
+ const existingNumbers = /* @__PURE__ */ new Set();
133569
+ const existingBigInts = /* @__PURE__ */ new Set();
133570
+ for (const clause of clauses) {
133571
+ if (!isDefaultClause(clause)) {
133572
+ if (isLiteralExpression(clause.expression)) {
133573
+ const expression = clause.expression;
133574
+ switch (expression.kind) {
133575
+ case 14 /* NoSubstitutionTemplateLiteral */:
133576
+ case 10 /* StringLiteral */:
133577
+ existingStrings.add(expression.text);
133578
+ break;
133579
+ case 8 /* NumericLiteral */:
133580
+ existingNumbers.add(parseInt(expression.text));
133581
+ break;
133582
+ case 9 /* BigIntLiteral */:
133583
+ const parsedBigInt = parseBigInt(endsWith(expression.text, "n") ? expression.text.slice(0, -1) : expression.text);
133584
+ if (parsedBigInt) {
133585
+ existingBigInts.add(pseudoBigIntToString(parsedBigInt));
133586
+ }
133587
+ break;
133588
+ }
133589
+ } else {
133590
+ const symbol = checker.getSymbolAtLocation(clause.expression);
133591
+ if (symbol && symbol.valueDeclaration && isEnumMember(symbol.valueDeclaration)) {
133592
+ const enumValue = checker.getConstantValue(symbol.valueDeclaration);
133593
+ if (enumValue !== void 0) {
133594
+ addValue(enumValue);
133595
+ }
133596
+ }
133597
+ }
133598
+ }
133599
+ }
133600
+ return {
133601
+ addValue,
133602
+ hasValue
133603
+ };
133604
+ function addValue(value) {
133605
+ switch (typeof value) {
133606
+ case "string":
133607
+ existingStrings.add(value);
133608
+ break;
133609
+ case "number":
133610
+ existingNumbers.add(value);
133611
+ }
133612
+ }
133613
+ function hasValue(value) {
133614
+ switch (typeof value) {
133615
+ case "string":
133616
+ return existingStrings.has(value);
133617
+ case "number":
133618
+ return existingNumbers.has(value);
133619
+ case "object":
133620
+ return existingBigInts.has(pseudoBigIntToString(value));
133621
+ }
133622
+ }
133623
+ }
133624
+ function typeNodeToExpression(typeNode, languageVersion, quotePreference) {
133625
+ switch (typeNode.kind) {
133626
+ case 180 /* TypeReference */:
133627
+ const typeName = typeNode.typeName;
133628
+ return entityNameToExpression(typeName, languageVersion, quotePreference);
133629
+ case 196 /* IndexedAccessType */:
133630
+ const objectExpression = typeNodeToExpression(typeNode.objectType, languageVersion, quotePreference);
133631
+ const indexExpression = typeNodeToExpression(typeNode.indexType, languageVersion, quotePreference);
133632
+ return objectExpression && indexExpression && factory.createElementAccessExpression(objectExpression, indexExpression);
133633
+ case 198 /* LiteralType */:
133634
+ const literal = typeNode.literal;
133635
+ switch (literal.kind) {
133636
+ case 10 /* StringLiteral */:
133637
+ return factory.createStringLiteral(literal.text, quotePreference === 0 /* Single */);
133638
+ case 8 /* NumericLiteral */:
133639
+ return factory.createNumericLiteral(literal.text, literal.numericLiteralFlags);
133640
+ }
133641
+ return void 0;
133642
+ case 193 /* ParenthesizedType */:
133643
+ const exp = typeNodeToExpression(typeNode.type, languageVersion, quotePreference);
133644
+ return exp && (isIdentifier(exp) ? exp : factory.createParenthesizedExpression(exp));
133645
+ case 183 /* TypeQuery */:
133646
+ return entityNameToExpression(typeNode.exprName, languageVersion, quotePreference);
133647
+ case 202 /* ImportType */:
133648
+ Debug.fail(`We should not get an import type after calling 'codefix.typeToAutoImportableTypeNode'.`);
133649
+ }
133650
+ return void 0;
133651
+ }
133652
+ function entityNameToExpression(entityName, languageVersion, quotePreference) {
133653
+ if (isIdentifier(entityName)) {
133654
+ return entityName;
133655
+ }
133656
+ const unescapedName = unescapeLeadingUnderscores(entityName.right.escapedText);
133657
+ if (canUsePropertyAccess(unescapedName, languageVersion)) {
133658
+ return factory.createPropertyAccessExpression(
133659
+ entityNameToExpression(entityName.left, languageVersion, quotePreference),
133660
+ unescapedName
133661
+ );
133662
+ } else {
133663
+ return factory.createElementAccessExpression(
133664
+ entityNameToExpression(entityName.left, languageVersion, quotePreference),
133665
+ factory.createStringLiteral(unescapedName, quotePreference === 0 /* Single */)
133666
+ );
133667
+ }
133668
+ }
133468
133669
  function isMemberCompletionKind(kind) {
133469
133670
  switch (kind) {
133470
133671
  case CompletionKind.ObjectPropertyDeclaration:
@@ -133871,7 +134072,9 @@ ${lanes.join("\n")}
133871
134072
  };
133872
134073
  return {
133873
134074
  printSnippetList,
133874
- printAndFormatSnippetList
134075
+ printAndFormatSnippetList,
134076
+ printNode,
134077
+ printAndFormatNode
133875
134078
  };
133876
134079
  function escapingWrite(s, write) {
133877
134080
  const escaped = escapeSnippetText(s);
@@ -133920,6 +134123,40 @@ ${lanes.join("\n")}
133920
134123
  const allChanges = escapes ? stableSort(concatenate(changes, escapes), (a, b) => compareTextSpans(a.span, b.span)) : changes;
133921
134124
  return ts_textChanges_exports.applyChanges(syntheticFile.text, allChanges);
133922
134125
  }
134126
+ function printNode(hint, node, sourceFile) {
134127
+ const unescaped = printUnescapedNode(hint, node, sourceFile);
134128
+ return escapes ? ts_textChanges_exports.applyChanges(unescaped, escapes) : unescaped;
134129
+ }
134130
+ function printUnescapedNode(hint, node, sourceFile) {
134131
+ escapes = void 0;
134132
+ writer.clear();
134133
+ printer.writeNode(hint, node, sourceFile, writer);
134134
+ return writer.getText();
134135
+ }
134136
+ function printAndFormatNode(hint, node, sourceFile, formatContext) {
134137
+ const syntheticFile = {
134138
+ text: printUnescapedNode(
134139
+ hint,
134140
+ node,
134141
+ sourceFile
134142
+ ),
134143
+ getLineAndCharacterOfPosition(pos) {
134144
+ return getLineAndCharacterOfPosition(this, pos);
134145
+ }
134146
+ };
134147
+ const formatOptions = getFormatCodeSettingsForWriting(formatContext, sourceFile);
134148
+ const nodeWithPos = ts_textChanges_exports.assignPositionsToNode(node);
134149
+ const changes = ts_formatting_exports.formatNodeGivenIndentation(
134150
+ nodeWithPos,
134151
+ syntheticFile,
134152
+ sourceFile.languageVariant,
134153
+ 0,
134154
+ 0,
134155
+ { ...formatContext, options: formatOptions }
134156
+ );
134157
+ const allChanges = escapes ? stableSort(concatenate(changes, escapes), (a, b) => compareTextSpans(a.span, b.span)) : changes;
134158
+ return ts_textChanges_exports.applyChanges(syntheticFile.text, allChanges);
134159
+ }
133923
134160
  }
133924
134161
  function originToCompletionEntryData(origin) {
133925
134162
  const ambientModuleName = origin.fileName ? void 0 : stripQuotes(origin.moduleSymbol.name);
@@ -134123,6 +134360,9 @@ ${lanes.join("\n")}
134123
134360
  return entries;
134124
134361
  }
134125
134362
  function getSymbolCompletionFromEntryId(program, log, sourceFile, position, entryId, host, preferences) {
134363
+ if (entryId.source === "SwitchCases/" /* SwitchCases */) {
134364
+ return { type: "cases" };
134365
+ }
134126
134366
  if (entryId.data) {
134127
134367
  const autoImport = getAutoImportSymbolFromCompletionEntryData(entryId.name, entryId.data, program, host);
134128
134368
  if (autoImport) {
@@ -134161,9 +134401,9 @@ ${lanes.join("\n")}
134161
134401
  const typeChecker = program.getTypeChecker();
134162
134402
  const compilerOptions = program.getCompilerOptions();
134163
134403
  const { name, source, data } = entryId;
134164
- const contextToken = findPrecedingToken(position, sourceFile);
134165
- if (isInString(sourceFile, position, contextToken)) {
134166
- return ts_Completions_StringCompletions_exports.getStringLiteralCompletionDetails(name, sourceFile, position, contextToken, typeChecker, compilerOptions, host, cancellationToken, preferences);
134404
+ const { previousToken, contextToken } = getRelevantTokens(position, sourceFile);
134405
+ if (isInString(sourceFile, position, previousToken)) {
134406
+ return ts_Completions_StringCompletions_exports.getStringLiteralCompletionDetails(name, sourceFile, position, previousToken, typeChecker, compilerOptions, host, cancellationToken, preferences);
134167
134407
  }
134168
134408
  const symbolCompletion = getSymbolCompletionFromEntryId(program, log, sourceFile, position, entryId, host, preferences);
134169
134409
  switch (symbolCompletion.type) {
@@ -134183,14 +134423,49 @@ ${lanes.join("\n")}
134183
134423
  }
134184
134424
  }
134185
134425
  case "symbol": {
134186
- const { symbol, location: location2, contextToken: contextToken2, origin, previousToken } = symbolCompletion;
134187
- const { codeActions, sourceDisplay } = getCompletionEntryCodeActionsAndSourceDisplay(name, location2, contextToken2, origin, symbol, program, host, compilerOptions, sourceFile, position, previousToken, formatContext, preferences, data, source, cancellationToken);
134426
+ const { symbol, location: location2, contextToken: contextToken2, origin, previousToken: previousToken2 } = symbolCompletion;
134427
+ const { codeActions, sourceDisplay } = getCompletionEntryCodeActionsAndSourceDisplay(name, location2, contextToken2, origin, symbol, program, host, compilerOptions, sourceFile, position, previousToken2, formatContext, preferences, data, source, cancellationToken);
134188
134428
  return createCompletionDetailsForSymbol(symbol, typeChecker, sourceFile, location2, cancellationToken, codeActions, sourceDisplay);
134189
134429
  }
134190
134430
  case "literal": {
134191
134431
  const { literal } = symbolCompletion;
134192
134432
  return createSimpleDetails(completionNameForLiteral(sourceFile, preferences, literal), "string" /* string */, typeof literal === "string" ? 8 /* stringLiteral */ : 7 /* numericLiteral */);
134193
134433
  }
134434
+ case "cases": {
134435
+ const { entry, importAdder } = getExhaustiveCaseSnippets(
134436
+ contextToken.parent,
134437
+ sourceFile,
134438
+ preferences,
134439
+ program.getCompilerOptions(),
134440
+ host,
134441
+ program,
134442
+ void 0
134443
+ );
134444
+ if (importAdder.hasFixes()) {
134445
+ const changes = ts_textChanges_exports.ChangeTracker.with(
134446
+ { host, formatContext, preferences },
134447
+ importAdder.writeFixes
134448
+ );
134449
+ return {
134450
+ name: entry.name,
134451
+ kind: "" /* unknown */,
134452
+ kindModifiers: "",
134453
+ displayParts: [],
134454
+ sourceDisplay: void 0,
134455
+ codeActions: [{
134456
+ changes,
134457
+ description: diagnosticToString([Diagnostics.Includes_imports_of_types_referenced_by_0, name])
134458
+ }]
134459
+ };
134460
+ }
134461
+ return {
134462
+ name: entry.name,
134463
+ kind: "" /* unknown */,
134464
+ kindModifiers: "",
134465
+ displayParts: [],
134466
+ sourceDisplay: void 0
134467
+ };
134468
+ }
134194
134469
  case "none":
134195
134470
  return allKeywordsCompletions().some((c) => c.name === name) ? createSimpleDetails(name, "keyword" /* keyword */, 5 /* keyword */) : void 0;
134196
134471
  default:
@@ -141251,7 +141526,7 @@ ${lanes.join("\n")}
141251
141526
  return emptyArray;
141252
141527
  },
141253
141528
  getEditsForAction: function getRefactorEditsToExtractType(context, actionName2) {
141254
- const { file } = context;
141529
+ const { file, program } = context;
141255
141530
  const info = getRangeToExtract(context);
141256
141531
  Debug.assert(info && !isRefactorErrorInfo(info), "Expected to find a range to extract");
141257
141532
  const name = getUniqueName("NewType", file);
@@ -141262,7 +141537,7 @@ ${lanes.join("\n")}
141262
141537
  return doTypeAliasChange(changes, file, name, info);
141263
141538
  case extractToTypeDefAction.name:
141264
141539
  Debug.assert(info.isJS, "Invalid actionName/JS combo");
141265
- return doTypedefChange(changes, file, name, info);
141540
+ return doTypedefChange(changes, program, file, name, info);
141266
141541
  case extractToInterfaceAction.name:
141267
141542
  Debug.assert(!info.isJS && !!info.typeElements, "Invalid actionName/JS combo");
141268
141543
  return doInterfaceChange(changes, file, name, info);
@@ -141285,12 +141560,14 @@ ${lanes.join("\n")}
141285
141560
  if (!selection || !isTypeNode(selection))
141286
141561
  return { error: getLocaleSpecificMessage(Diagnostics.Selection_is_not_a_valid_type_node) };
141287
141562
  const checker = context.program.getTypeChecker();
141288
- const firstStatement = Debug.checkDefined(findAncestor(selection, isStatement), "Should find a statement");
141289
- const typeParameters = collectTypeParameters(checker, selection, firstStatement, file);
141563
+ const enclosingNode = getEnclosingNode(selection, isJS);
141564
+ if (enclosingNode === void 0)
141565
+ return { error: getLocaleSpecificMessage(Diagnostics.No_type_could_be_extracted_from_this_type_node) };
141566
+ const typeParameters = collectTypeParameters(checker, selection, enclosingNode, file);
141290
141567
  if (!typeParameters)
141291
141568
  return { error: getLocaleSpecificMessage(Diagnostics.No_type_could_be_extracted_from_this_type_node) };
141292
141569
  const typeElements = flattenTypeLiteralNodeReference(checker, selection);
141293
- return { isJS, selection, firstStatement, typeParameters, typeElements };
141570
+ return { isJS, selection, enclosingNode, typeParameters, typeElements };
141294
141571
  }
141295
141572
  function flattenTypeLiteralNodeReference(checker, node) {
141296
141573
  if (!node)
@@ -141316,7 +141593,7 @@ ${lanes.join("\n")}
141316
141593
  function rangeContainsSkipTrivia(r1, node, file) {
141317
141594
  return rangeContainsStartEnd(r1, skipTrivia(file.text, node.pos), node.end);
141318
141595
  }
141319
- function collectTypeParameters(checker, selection, statement, file) {
141596
+ function collectTypeParameters(checker, selection, enclosingNode, file) {
141320
141597
  const result = [];
141321
141598
  return visitor(selection) ? void 0 : result;
141322
141599
  function visitor(node) {
@@ -141329,7 +141606,7 @@ ${lanes.join("\n")}
141329
141606
  if (decl.name.escapedText === typeName.escapedText && rangeContainsSkipTrivia(decl, selection, file)) {
141330
141607
  return true;
141331
141608
  }
141332
- if (rangeContainsSkipTrivia(statement, decl, file) && !rangeContainsSkipTrivia(selection, decl, file)) {
141609
+ if (rangeContainsSkipTrivia(enclosingNode, decl, file) && !rangeContainsSkipTrivia(selection, decl, file)) {
141333
141610
  pushIfUnique(result, decl);
141334
141611
  break;
141335
141612
  }
@@ -141349,7 +141626,7 @@ ${lanes.join("\n")}
141349
141626
  } else if (isTypeQueryNode(node)) {
141350
141627
  if (isIdentifier(node.exprName)) {
141351
141628
  const symbol = checker.resolveName(node.exprName.text, node.exprName, 111551 /* Value */, false);
141352
- if ((symbol == null ? void 0 : symbol.valueDeclaration) && rangeContainsSkipTrivia(statement, symbol.valueDeclaration, file) && !rangeContainsSkipTrivia(selection, symbol.valueDeclaration, file)) {
141629
+ if ((symbol == null ? void 0 : symbol.valueDeclaration) && rangeContainsSkipTrivia(enclosingNode, symbol.valueDeclaration, file) && !rangeContainsSkipTrivia(selection, symbol.valueDeclaration, file)) {
141353
141630
  return true;
141354
141631
  }
141355
141632
  } else {
@@ -141365,19 +141642,19 @@ ${lanes.join("\n")}
141365
141642
  }
141366
141643
  }
141367
141644
  function doTypeAliasChange(changes, file, name, info) {
141368
- const { firstStatement, selection, typeParameters } = info;
141645
+ const { enclosingNode, selection, typeParameters } = info;
141369
141646
  const newTypeNode = factory.createTypeAliasDeclaration(
141370
141647
  void 0,
141371
141648
  name,
141372
141649
  typeParameters.map((id) => factory.updateTypeParameterDeclaration(id, id.modifiers, id.name, id.constraint, void 0)),
141373
141650
  selection
141374
141651
  );
141375
- changes.insertNodeBefore(file, firstStatement, ignoreSourceNewlines(newTypeNode), true);
141652
+ changes.insertNodeBefore(file, enclosingNode, ignoreSourceNewlines(newTypeNode), true);
141376
141653
  changes.replaceNode(file, selection, factory.createTypeReferenceNode(name, typeParameters.map((id) => factory.createTypeReferenceNode(id.name, void 0))), { leadingTriviaOption: ts_textChanges_exports.LeadingTriviaOption.Exclude, trailingTriviaOption: ts_textChanges_exports.TrailingTriviaOption.ExcludeWhitespace });
141377
141654
  }
141378
141655
  function doInterfaceChange(changes, file, name, info) {
141379
141656
  var _a2;
141380
- const { firstStatement, selection, typeParameters, typeElements } = info;
141657
+ const { enclosingNode, selection, typeParameters, typeElements } = info;
141381
141658
  const newTypeNode = factory.createInterfaceDeclaration(
141382
141659
  void 0,
141383
141660
  name,
@@ -141386,11 +141663,11 @@ ${lanes.join("\n")}
141386
141663
  typeElements
141387
141664
  );
141388
141665
  setTextRange(newTypeNode, (_a2 = typeElements[0]) == null ? void 0 : _a2.parent);
141389
- changes.insertNodeBefore(file, firstStatement, ignoreSourceNewlines(newTypeNode), true);
141666
+ changes.insertNodeBefore(file, enclosingNode, ignoreSourceNewlines(newTypeNode), true);
141390
141667
  changes.replaceNode(file, selection, factory.createTypeReferenceNode(name, typeParameters.map((id) => factory.createTypeReferenceNode(id.name, void 0))), { leadingTriviaOption: ts_textChanges_exports.LeadingTriviaOption.Exclude, trailingTriviaOption: ts_textChanges_exports.TrailingTriviaOption.ExcludeWhitespace });
141391
141668
  }
141392
- function doTypedefChange(changes, file, name, info) {
141393
- const { firstStatement, selection, typeParameters } = info;
141669
+ function doTypedefChange(changes, program, file, name, info) {
141670
+ const { enclosingNode, selection, typeParameters } = info;
141394
141671
  setEmitFlags(selection, 3072 /* NoComments */ | 4096 /* NoNestedComments */);
141395
141672
  const node = factory.createJSDocTypedefTag(
141396
141673
  factory.createIdentifier("typedef"),
@@ -141408,9 +141685,21 @@ ${lanes.join("\n")}
141408
141685
  );
141409
141686
  templates.push(template);
141410
141687
  });
141411
- changes.insertNodeBefore(file, firstStatement, factory.createJSDocComment(void 0, factory.createNodeArray(concatenate(templates, [node]))), true);
141688
+ const jsDoc = factory.createJSDocComment(void 0, factory.createNodeArray(concatenate(templates, [node])));
141689
+ if (isJSDoc(enclosingNode)) {
141690
+ const pos = enclosingNode.getStart(file);
141691
+ const newLineCharacter = getNewLineCharacter(program.getCompilerOptions());
141692
+ changes.insertNodeAt(file, enclosingNode.getStart(file), jsDoc, {
141693
+ suffix: newLineCharacter + newLineCharacter + file.text.slice(getPrecedingNonSpaceCharacterPosition(file.text, pos - 1), pos)
141694
+ });
141695
+ } else {
141696
+ changes.insertNodeBefore(file, enclosingNode, jsDoc, true);
141697
+ }
141412
141698
  changes.replaceNode(file, selection, factory.createTypeReferenceNode(name, typeParameters.map((id) => factory.createTypeReferenceNode(id.name, void 0))));
141413
141699
  }
141700
+ function getEnclosingNode(node, isJS) {
141701
+ return findAncestor(node, isStatement) || (isJS ? findAncestor(node, isJSDoc) : void 0);
141702
+ }
141414
141703
 
141415
141704
  // src/services/refactors/helpers.ts
141416
141705
  function isRefactorErrorInfo(info) {