typescript 5.5.0-dev.20240409 → 5.5.0-dev.20240410
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/tsc.js +10 -7
- package/lib/typescript.js +372 -42
- package/package.json +2 -2
package/lib/tsc.js
CHANGED
|
@@ -18,7 +18,7 @@ and limitations under the License.
|
|
|
18
18
|
|
|
19
19
|
// src/compiler/corePublic.ts
|
|
20
20
|
var versionMajorMinor = "5.5";
|
|
21
|
-
var version = `${versionMajorMinor}.0-dev.
|
|
21
|
+
var version = `${versionMajorMinor}.0-dev.20240410`;
|
|
22
22
|
|
|
23
23
|
// src/compiler/core.ts
|
|
24
24
|
var emptyArray = [];
|
|
@@ -13397,6 +13397,9 @@ function getExternalModuleRequireArgument(node) {
|
|
|
13397
13397
|
function isInternalModuleImportEqualsDeclaration(node) {
|
|
13398
13398
|
return node.kind === 271 /* ImportEqualsDeclaration */ && node.moduleReference.kind !== 283 /* ExternalModuleReference */;
|
|
13399
13399
|
}
|
|
13400
|
+
function isFullSourceFile(sourceFile) {
|
|
13401
|
+
return (sourceFile == null ? void 0 : sourceFile.kind) === 307 /* SourceFile */;
|
|
13402
|
+
}
|
|
13400
13403
|
function isSourceFileJS(file) {
|
|
13401
13404
|
return isInJSFile(file);
|
|
13402
13405
|
}
|
|
@@ -17038,12 +17041,12 @@ function getModuleSpecifierEndingPreference(preference, resolutionMode, compiler
|
|
|
17038
17041
|
return 1 /* Index */;
|
|
17039
17042
|
}
|
|
17040
17043
|
if (!shouldAllowImportingTsExtension(compilerOptions)) {
|
|
17041
|
-
return usesExtensionsOnImports(sourceFile) ? 2 /* JsExtension */ : 0 /* Minimal */;
|
|
17044
|
+
return sourceFile && usesExtensionsOnImports(sourceFile) ? 2 /* JsExtension */ : 0 /* Minimal */;
|
|
17042
17045
|
}
|
|
17043
17046
|
return inferPreference();
|
|
17044
17047
|
function inferPreference() {
|
|
17045
17048
|
let usesJsExtensions = false;
|
|
17046
|
-
const specifiers = sourceFile.imports.length ? sourceFile.imports : isSourceFileJS(sourceFile) ? getRequiresAtTopOfFile(sourceFile).map((r) => r.arguments[0]) : emptyArray;
|
|
17049
|
+
const specifiers = (sourceFile == null ? void 0 : sourceFile.imports.length) ? sourceFile.imports : sourceFile && isSourceFileJS(sourceFile) ? getRequiresAtTopOfFile(sourceFile).map((r) => r.arguments[0]) : emptyArray;
|
|
17047
17050
|
for (const specifier of specifiers) {
|
|
17048
17051
|
if (pathIsRelative(specifier.text)) {
|
|
17049
17052
|
if (moduleResolutionIsNodeNext && resolutionMode === 1 /* CommonJS */ && getModeForUsageLocation(sourceFile, specifier, compilerOptions) === 99 /* ESNext */) {
|
|
@@ -42665,7 +42668,7 @@ function getModuleSpecifierPreferences({ importModuleSpecifierPreference, import
|
|
|
42665
42668
|
importModuleSpecifierEnding,
|
|
42666
42669
|
resolutionMode ?? importingSourceFile.impliedNodeFormat,
|
|
42667
42670
|
compilerOptions,
|
|
42668
|
-
importingSourceFile
|
|
42671
|
+
isFullSourceFile(importingSourceFile) ? importingSourceFile : void 0
|
|
42669
42672
|
);
|
|
42670
42673
|
}
|
|
42671
42674
|
}
|
|
@@ -42725,7 +42728,7 @@ function getModuleSpecifiersWithCacheInfo(moduleSymbol, checker, compilerOptions
|
|
|
42725
42728
|
function computeModuleSpecifiers(modulePaths, compilerOptions, importingSourceFile, host, userPreferences, options = {}, forAutoImport) {
|
|
42726
42729
|
const info = getInfo(importingSourceFile.fileName, host);
|
|
42727
42730
|
const preferences = getModuleSpecifierPreferences(userPreferences, compilerOptions, importingSourceFile);
|
|
42728
|
-
const existingSpecifier = forEach(modulePaths, (modulePath) => forEach(
|
|
42731
|
+
const existingSpecifier = isFullSourceFile(importingSourceFile) && forEach(modulePaths, (modulePath) => forEach(
|
|
42729
42732
|
host.getFileIncludeReasons().get(toPath(modulePath.path, host.getCurrentDirectory(), info.getCanonicalFileName)),
|
|
42730
42733
|
(reason) => {
|
|
42731
42734
|
if (reason.kind !== 3 /* Import */ || reason.file !== importingSourceFile.path)
|
|
@@ -55717,13 +55720,13 @@ function createTypeChecker(host) {
|
|
|
55717
55720
|
}
|
|
55718
55721
|
function getUnionOrIntersectionProperty(type, name, skipObjectFunctionPropertyAugment) {
|
|
55719
55722
|
var _a, _b, _c;
|
|
55720
|
-
let property = (
|
|
55723
|
+
let property = skipObjectFunctionPropertyAugment ? (_a = type.propertyCacheWithoutObjectFunctionPropertyAugment) == null ? void 0 : _a.get(name) : (_b = type.propertyCache) == null ? void 0 : _b.get(name);
|
|
55721
55724
|
if (!property) {
|
|
55722
55725
|
property = createUnionOrIntersectionProperty(type, name, skipObjectFunctionPropertyAugment);
|
|
55723
55726
|
if (property) {
|
|
55724
55727
|
const properties = skipObjectFunctionPropertyAugment ? type.propertyCacheWithoutObjectFunctionPropertyAugment || (type.propertyCacheWithoutObjectFunctionPropertyAugment = createSymbolTable()) : type.propertyCache || (type.propertyCache = createSymbolTable());
|
|
55725
55728
|
properties.set(name, property);
|
|
55726
|
-
if (skipObjectFunctionPropertyAugment && !((_c = type.propertyCache) == null ? void 0 : _c.get(name))) {
|
|
55729
|
+
if (skipObjectFunctionPropertyAugment && !(getCheckFlags(property) & 48 /* Partial */) && !((_c = type.propertyCache) == null ? void 0 : _c.get(name))) {
|
|
55727
55730
|
const properties2 = type.propertyCache || (type.propertyCache = createSymbolTable());
|
|
55728
55731
|
properties2.set(name, property);
|
|
55729
55732
|
}
|
package/lib/typescript.js
CHANGED
|
@@ -414,6 +414,7 @@ __export(typescript_exports, {
|
|
|
414
414
|
createFileDiagnosticFromMessageChain: () => createFileDiagnosticFromMessageChain,
|
|
415
415
|
createFlowNode: () => createFlowNode,
|
|
416
416
|
createForOfBindingStatement: () => createForOfBindingStatement,
|
|
417
|
+
createFutureSourceFile: () => createFutureSourceFile,
|
|
417
418
|
createGetCanonicalFileName: () => createGetCanonicalFileName,
|
|
418
419
|
createGetSourceFile: () => createGetSourceFile,
|
|
419
420
|
createGetSymbolAccessibilityDiagnosticForNode: () => createGetSymbolAccessibilityDiagnosticForNode,
|
|
@@ -1185,6 +1186,7 @@ __export(typescript_exports, {
|
|
|
1185
1186
|
isAnyDirectorySeparator: () => isAnyDirectorySeparator,
|
|
1186
1187
|
isAnyImportOrBareOrAccessedRequire: () => isAnyImportOrBareOrAccessedRequire,
|
|
1187
1188
|
isAnyImportOrReExport: () => isAnyImportOrReExport,
|
|
1189
|
+
isAnyImportOrRequireStatement: () => isAnyImportOrRequireStatement,
|
|
1188
1190
|
isAnyImportSyntax: () => isAnyImportSyntax,
|
|
1189
1191
|
isAnySupportedFileExtension: () => isAnySupportedFileExtension,
|
|
1190
1192
|
isApplicableVersionedTypesKey: () => isApplicableVersionedTypesKey,
|
|
@@ -1375,6 +1377,7 @@ __export(typescript_exports, {
|
|
|
1375
1377
|
isForInitializer: () => isForInitializer,
|
|
1376
1378
|
isForOfStatement: () => isForOfStatement,
|
|
1377
1379
|
isForStatement: () => isForStatement,
|
|
1380
|
+
isFullSourceFile: () => isFullSourceFile,
|
|
1378
1381
|
isFunctionBlock: () => isFunctionBlock,
|
|
1379
1382
|
isFunctionBody: () => isFunctionBody,
|
|
1380
1383
|
isFunctionDeclaration: () => isFunctionDeclaration,
|
|
@@ -2335,7 +2338,7 @@ module.exports = __toCommonJS(typescript_exports);
|
|
|
2335
2338
|
|
|
2336
2339
|
// src/compiler/corePublic.ts
|
|
2337
2340
|
var versionMajorMinor = "5.5";
|
|
2338
|
-
var version = `${versionMajorMinor}.0-dev.
|
|
2341
|
+
var version = `${versionMajorMinor}.0-dev.20240410`;
|
|
2339
2342
|
var Comparison = /* @__PURE__ */ ((Comparison3) => {
|
|
2340
2343
|
Comparison3[Comparison3["LessThan"] = -1] = "LessThan";
|
|
2341
2344
|
Comparison3[Comparison3["EqualTo"] = 0] = "EqualTo";
|
|
@@ -16246,6 +16249,9 @@ function isAnyImportSyntax(node) {
|
|
|
16246
16249
|
function isAnyImportOrBareOrAccessedRequire(node) {
|
|
16247
16250
|
return isAnyImportSyntax(node) || isVariableDeclarationInitializedToBareOrAccessedRequire(node);
|
|
16248
16251
|
}
|
|
16252
|
+
function isAnyImportOrRequireStatement(node) {
|
|
16253
|
+
return isAnyImportSyntax(node) || isRequireVariableStatement(node);
|
|
16254
|
+
}
|
|
16249
16255
|
function isLateVisibilityPaintedStatement(node) {
|
|
16250
16256
|
switch (node.kind) {
|
|
16251
16257
|
case 272 /* ImportDeclaration */:
|
|
@@ -17282,6 +17288,9 @@ function getExternalModuleRequireArgument(node) {
|
|
|
17282
17288
|
function isInternalModuleImportEqualsDeclaration(node) {
|
|
17283
17289
|
return node.kind === 271 /* ImportEqualsDeclaration */ && node.moduleReference.kind !== 283 /* ExternalModuleReference */;
|
|
17284
17290
|
}
|
|
17291
|
+
function isFullSourceFile(sourceFile) {
|
|
17292
|
+
return (sourceFile == null ? void 0 : sourceFile.kind) === 307 /* SourceFile */;
|
|
17293
|
+
}
|
|
17285
17294
|
function isSourceFileJS(file) {
|
|
17286
17295
|
return isInJSFile(file);
|
|
17287
17296
|
}
|
|
@@ -21249,12 +21258,12 @@ function getModuleSpecifierEndingPreference(preference, resolutionMode, compiler
|
|
|
21249
21258
|
return 1 /* Index */;
|
|
21250
21259
|
}
|
|
21251
21260
|
if (!shouldAllowImportingTsExtension(compilerOptions)) {
|
|
21252
|
-
return usesExtensionsOnImports(sourceFile) ? 2 /* JsExtension */ : 0 /* Minimal */;
|
|
21261
|
+
return sourceFile && usesExtensionsOnImports(sourceFile) ? 2 /* JsExtension */ : 0 /* Minimal */;
|
|
21253
21262
|
}
|
|
21254
21263
|
return inferPreference();
|
|
21255
21264
|
function inferPreference() {
|
|
21256
21265
|
let usesJsExtensions = false;
|
|
21257
|
-
const specifiers = sourceFile.imports.length ? sourceFile.imports : isSourceFileJS(sourceFile) ? getRequiresAtTopOfFile(sourceFile).map((r) => r.arguments[0]) : emptyArray;
|
|
21266
|
+
const specifiers = (sourceFile == null ? void 0 : sourceFile.imports.length) ? sourceFile.imports : sourceFile && isSourceFileJS(sourceFile) ? getRequiresAtTopOfFile(sourceFile).map((r) => r.arguments[0]) : emptyArray;
|
|
21258
21267
|
for (const specifier of specifiers) {
|
|
21259
21268
|
if (pathIsRelative(specifier.text)) {
|
|
21260
21269
|
if (moduleResolutionIsNodeNext && resolutionMode === 1 /* CommonJS */ && getModeForUsageLocation(sourceFile, specifier, compilerOptions) === 99 /* ESNext */) {
|
|
@@ -47310,6 +47319,7 @@ __export(ts_moduleSpecifiers_exports, {
|
|
|
47310
47319
|
RelativePreference: () => RelativePreference,
|
|
47311
47320
|
countPathComponents: () => countPathComponents,
|
|
47312
47321
|
forEachFileNameOfModule: () => forEachFileNameOfModule,
|
|
47322
|
+
getLocalModuleSpecifierBetweenFileNames: () => getLocalModuleSpecifierBetweenFileNames,
|
|
47313
47323
|
getModuleSpecifier: () => getModuleSpecifier,
|
|
47314
47324
|
getModuleSpecifierPreferences: () => getModuleSpecifierPreferences,
|
|
47315
47325
|
getModuleSpecifiers: () => getModuleSpecifiers,
|
|
@@ -47370,7 +47380,7 @@ function getModuleSpecifierPreferences({ importModuleSpecifierPreference, import
|
|
|
47370
47380
|
importModuleSpecifierEnding,
|
|
47371
47381
|
resolutionMode ?? importingSourceFile.impliedNodeFormat,
|
|
47372
47382
|
compilerOptions,
|
|
47373
|
-
importingSourceFile
|
|
47383
|
+
isFullSourceFile(importingSourceFile) ? importingSourceFile : void 0
|
|
47374
47384
|
);
|
|
47375
47385
|
}
|
|
47376
47386
|
}
|
|
@@ -47475,10 +47485,22 @@ function getModuleSpecifiersWithCacheInfo(moduleSymbol, checker, compilerOptions
|
|
|
47475
47485
|
cache == null ? void 0 : cache.set(importingSourceFile.path, moduleSourceFile.path, userPreferences, options, modulePaths, result);
|
|
47476
47486
|
return { moduleSpecifiers: result, computedWithoutCache };
|
|
47477
47487
|
}
|
|
47488
|
+
function getLocalModuleSpecifierBetweenFileNames(importingFile, targetFileName, compilerOptions, host, options = {}) {
|
|
47489
|
+
const info = getInfo(importingFile.fileName, host);
|
|
47490
|
+
const importMode = options.overrideImportMode ?? importingFile.impliedNodeFormat;
|
|
47491
|
+
return getLocalModuleSpecifier(
|
|
47492
|
+
targetFileName,
|
|
47493
|
+
info,
|
|
47494
|
+
compilerOptions,
|
|
47495
|
+
host,
|
|
47496
|
+
importMode,
|
|
47497
|
+
getModuleSpecifierPreferences({}, compilerOptions, importingFile)
|
|
47498
|
+
);
|
|
47499
|
+
}
|
|
47478
47500
|
function computeModuleSpecifiers(modulePaths, compilerOptions, importingSourceFile, host, userPreferences, options = {}, forAutoImport) {
|
|
47479
47501
|
const info = getInfo(importingSourceFile.fileName, host);
|
|
47480
47502
|
const preferences = getModuleSpecifierPreferences(userPreferences, compilerOptions, importingSourceFile);
|
|
47481
|
-
const existingSpecifier = forEach(modulePaths, (modulePath) => forEach(
|
|
47503
|
+
const existingSpecifier = isFullSourceFile(importingSourceFile) && forEach(modulePaths, (modulePath) => forEach(
|
|
47482
47504
|
host.getFileIncludeReasons().get(toPath(modulePath.path, host.getCurrentDirectory(), info.getCanonicalFileName)),
|
|
47483
47505
|
(reason) => {
|
|
47484
47506
|
if (reason.kind !== 3 /* Import */ || reason.file !== importingSourceFile.path)
|
|
@@ -60486,13 +60508,13 @@ function createTypeChecker(host) {
|
|
|
60486
60508
|
}
|
|
60487
60509
|
function getUnionOrIntersectionProperty(type, name, skipObjectFunctionPropertyAugment) {
|
|
60488
60510
|
var _a, _b, _c;
|
|
60489
|
-
let property = (
|
|
60511
|
+
let property = skipObjectFunctionPropertyAugment ? (_a = type.propertyCacheWithoutObjectFunctionPropertyAugment) == null ? void 0 : _a.get(name) : (_b = type.propertyCache) == null ? void 0 : _b.get(name);
|
|
60490
60512
|
if (!property) {
|
|
60491
60513
|
property = createUnionOrIntersectionProperty(type, name, skipObjectFunctionPropertyAugment);
|
|
60492
60514
|
if (property) {
|
|
60493
60515
|
const properties = skipObjectFunctionPropertyAugment ? type.propertyCacheWithoutObjectFunctionPropertyAugment || (type.propertyCacheWithoutObjectFunctionPropertyAugment = createSymbolTable()) : type.propertyCache || (type.propertyCache = createSymbolTable());
|
|
60494
60516
|
properties.set(name, property);
|
|
60495
|
-
if (skipObjectFunctionPropertyAugment && !((_c = type.propertyCache) == null ? void 0 : _c.get(name))) {
|
|
60517
|
+
if (skipObjectFunctionPropertyAugment && !(getCheckFlags(property) & 48 /* Partial */) && !((_c = type.propertyCache) == null ? void 0 : _c.get(name))) {
|
|
60496
60518
|
const properties2 = type.propertyCache || (type.propertyCache = createSymbolTable());
|
|
60497
60519
|
properties2.set(name, property);
|
|
60498
60520
|
}
|
|
@@ -134688,7 +134710,7 @@ function getQuotePreference(sourceFile, preferences) {
|
|
|
134688
134710
|
if (preferences.quotePreference && preferences.quotePreference !== "auto") {
|
|
134689
134711
|
return preferences.quotePreference === "single" ? 0 /* Single */ : 1 /* Double */;
|
|
134690
134712
|
} else {
|
|
134691
|
-
const firstModuleSpecifier = sourceFile.imports && find(sourceFile.imports, (n) => isStringLiteral(n) && !nodeIsSynthesized(n.parent));
|
|
134713
|
+
const firstModuleSpecifier = isFullSourceFile(sourceFile) && sourceFile.imports && find(sourceFile.imports, (n) => isStringLiteral(n) && !nodeIsSynthesized(n.parent));
|
|
134692
134714
|
return firstModuleSpecifier ? quotePreferenceFromString(firstModuleSpecifier, sourceFile) : 1 /* Double */;
|
|
134693
134715
|
}
|
|
134694
134716
|
}
|
|
@@ -134746,14 +134768,24 @@ function findModifier(node, kind) {
|
|
|
134746
134768
|
return canHaveModifiers(node) ? find(node.modifiers, (m) => m.kind === kind) : void 0;
|
|
134747
134769
|
}
|
|
134748
134770
|
function insertImports(changes, sourceFile, imports, blankLineBetween, preferences) {
|
|
134771
|
+
var _a;
|
|
134749
134772
|
const decl = isArray(imports) ? imports[0] : imports;
|
|
134750
134773
|
const importKindPredicate = decl.kind === 243 /* VariableStatement */ ? isRequireVariableStatement : isAnyImportSyntax;
|
|
134751
134774
|
const existingImportStatements = filter(sourceFile.statements, importKindPredicate);
|
|
134752
134775
|
const { comparer, isSorted } = ts_OrganizeImports_exports.getOrganizeImportsStringComparerWithDetection(existingImportStatements, preferences);
|
|
134753
134776
|
const sortedNewImports = isArray(imports) ? stableSort(imports, (a, b) => ts_OrganizeImports_exports.compareImportsOrRequireStatements(a, b, comparer)) : [imports];
|
|
134754
|
-
if (!existingImportStatements.length) {
|
|
134755
|
-
|
|
134756
|
-
|
|
134777
|
+
if (!(existingImportStatements == null ? void 0 : existingImportStatements.length)) {
|
|
134778
|
+
if (isFullSourceFile(sourceFile)) {
|
|
134779
|
+
changes.insertNodesAtTopOfFile(sourceFile, sortedNewImports, blankLineBetween);
|
|
134780
|
+
} else {
|
|
134781
|
+
for (const newImport of sortedNewImports) {
|
|
134782
|
+
changes.insertStatementsInNewFile(sourceFile.fileName, [newImport], (_a = getOriginalNode(newImport)) == null ? void 0 : _a.getSourceFile());
|
|
134783
|
+
}
|
|
134784
|
+
}
|
|
134785
|
+
return;
|
|
134786
|
+
}
|
|
134787
|
+
Debug.assert(isFullSourceFile(sourceFile));
|
|
134788
|
+
if (existingImportStatements && isSorted) {
|
|
134757
134789
|
for (const newImport of sortedNewImports) {
|
|
134758
134790
|
const insertionIndex = ts_OrganizeImports_exports.getImportDeclarationInsertionIndex(existingImportStatements, newImport, comparer);
|
|
134759
134791
|
if (insertionIndex === 0) {
|
|
@@ -135679,7 +135711,7 @@ function createPackageJsonImportFilter(fromFile, preferences, host) {
|
|
|
135679
135711
|
return moduleSpecifierIsCoveredByPackageJson(moduleSpecifier);
|
|
135680
135712
|
}
|
|
135681
135713
|
function isAllowedCoreNodeModulesImport(moduleSpecifier) {
|
|
135682
|
-
if (isSourceFileJS(fromFile) && ts_JsTyping_exports.nodeCoreModules.has(moduleSpecifier)) {
|
|
135714
|
+
if (isFullSourceFile(fromFile) && isSourceFileJS(fromFile) && ts_JsTyping_exports.nodeCoreModules.has(moduleSpecifier)) {
|
|
135683
135715
|
if (usesNodeCoreModules === void 0) {
|
|
135684
135716
|
usesNodeCoreModules = consumesNodeCoreModules(fromFile);
|
|
135685
135717
|
}
|
|
@@ -135986,6 +136018,25 @@ function isBlockLike(node) {
|
|
|
135986
136018
|
return false;
|
|
135987
136019
|
}
|
|
135988
136020
|
}
|
|
136021
|
+
function createFutureSourceFile(fileName, syntaxModuleIndicator, program, moduleResolutionHost) {
|
|
136022
|
+
var _a;
|
|
136023
|
+
const result = getImpliedNodeFormatForFileWorker(fileName, (_a = program.getPackageJsonInfoCache) == null ? void 0 : _a.call(program), moduleResolutionHost, program.getCompilerOptions());
|
|
136024
|
+
let impliedNodeFormat, packageJsonScope;
|
|
136025
|
+
if (typeof result === "object") {
|
|
136026
|
+
impliedNodeFormat = result.impliedNodeFormat;
|
|
136027
|
+
packageJsonScope = result.packageJsonScope;
|
|
136028
|
+
}
|
|
136029
|
+
return {
|
|
136030
|
+
path: toPath(fileName, program.getCurrentDirectory(), program.getCanonicalFileName),
|
|
136031
|
+
fileName,
|
|
136032
|
+
externalModuleIndicator: syntaxModuleIndicator === 99 /* ESNext */ ? true : void 0,
|
|
136033
|
+
commonJsModuleIndicator: syntaxModuleIndicator === 1 /* CommonJS */ ? true : void 0,
|
|
136034
|
+
impliedNodeFormat,
|
|
136035
|
+
packageJsonScope,
|
|
136036
|
+
statements: emptyArray,
|
|
136037
|
+
imports: emptyArray
|
|
136038
|
+
};
|
|
136039
|
+
}
|
|
135989
136040
|
|
|
135990
136041
|
// src/services/exportInfoMap.ts
|
|
135991
136042
|
var ImportKind = /* @__PURE__ */ ((ImportKind2) => {
|
|
@@ -152163,15 +152214,27 @@ function createImportAdderWorker(sourceFile, program, useAutoImportProvider, pre
|
|
|
152163
152214
|
const addToNamespace = [];
|
|
152164
152215
|
const importType = [];
|
|
152165
152216
|
const addToExisting = /* @__PURE__ */ new Map();
|
|
152217
|
+
const removeExisting = /* @__PURE__ */ new Set();
|
|
152218
|
+
const verbatimImports = /* @__PURE__ */ new Set();
|
|
152166
152219
|
const newImports = /* @__PURE__ */ new Map();
|
|
152167
|
-
return { addImportFromDiagnostic, addImportFromExportedSymbol, writeFixes, hasFixes };
|
|
152220
|
+
return { addImportFromDiagnostic, addImportFromExportedSymbol, writeFixes, hasFixes, addImportForUnresolvedIdentifier, addImportForNonExistentExport, removeExistingImport, addVerbatimImport };
|
|
152221
|
+
function addVerbatimImport(declaration) {
|
|
152222
|
+
verbatimImports.add(declaration);
|
|
152223
|
+
}
|
|
152224
|
+
function addImportForUnresolvedIdentifier(context, symbolToken, useAutoImportProvider2) {
|
|
152225
|
+
const info = getFixInfosWithoutDiagnostic(context, symbolToken, useAutoImportProvider2);
|
|
152226
|
+
if (!info || !info.length)
|
|
152227
|
+
return;
|
|
152228
|
+
addImport(first(info));
|
|
152229
|
+
}
|
|
152168
152230
|
function addImportFromDiagnostic(diagnostic, context) {
|
|
152169
152231
|
const info = getFixInfos(context, diagnostic.code, diagnostic.start, useAutoImportProvider);
|
|
152170
152232
|
if (!info || !info.length)
|
|
152171
152233
|
return;
|
|
152172
152234
|
addImport(first(info));
|
|
152173
152235
|
}
|
|
152174
|
-
function addImportFromExportedSymbol(exportedSymbol, isValidTypeOnlyUseSite) {
|
|
152236
|
+
function addImportFromExportedSymbol(exportedSymbol, isValidTypeOnlyUseSite, referenceImport) {
|
|
152237
|
+
var _a;
|
|
152175
152238
|
const moduleSymbol = Debug.checkDefined(exportedSymbol.parent);
|
|
152176
152239
|
const symbolName2 = getNameForExportedSymbol(exportedSymbol, getEmitScriptTarget(compilerOptions));
|
|
152177
152240
|
const checker = program.getTypeChecker();
|
|
@@ -152189,7 +152252,7 @@ function createImportAdderWorker(sourceFile, program, useAutoImportProvider, pre
|
|
|
152189
152252
|
cancellationToken
|
|
152190
152253
|
);
|
|
152191
152254
|
const useRequire = shouldUseRequire(sourceFile, program);
|
|
152192
|
-
|
|
152255
|
+
let fix = getImportFixForSymbol(
|
|
152193
152256
|
sourceFile,
|
|
152194
152257
|
Debug.checkDefined(exportInfo),
|
|
152195
152258
|
program,
|
|
@@ -152201,9 +152264,72 @@ function createImportAdderWorker(sourceFile, program, useAutoImportProvider, pre
|
|
|
152201
152264
|
preferences
|
|
152202
152265
|
);
|
|
152203
152266
|
if (fix) {
|
|
152204
|
-
|
|
152267
|
+
const localName = ((_a = tryCast(referenceImport == null ? void 0 : referenceImport.name, isIdentifier)) == null ? void 0 : _a.text) ?? symbolName2;
|
|
152268
|
+
if (referenceImport && isTypeOnlyImportDeclaration(referenceImport) && (fix.kind === 3 /* AddNew */ || fix.kind === 2 /* AddToExisting */) && fix.addAsTypeOnly === 1 /* Allowed */) {
|
|
152269
|
+
fix = { ...fix, addAsTypeOnly: 2 /* Required */ };
|
|
152270
|
+
}
|
|
152271
|
+
addImport({ fix, symbolName: localName ?? symbolName2, errorIdentifierText: void 0 });
|
|
152272
|
+
}
|
|
152273
|
+
}
|
|
152274
|
+
function addImportForNonExistentExport(exportName, exportingFileName, exportKind, exportedMeanings, isImportUsageValidAsTypeOnly) {
|
|
152275
|
+
const exportingSourceFile = program.getSourceFile(exportingFileName);
|
|
152276
|
+
const useRequire = shouldUseRequire(sourceFile, program);
|
|
152277
|
+
if (exportingSourceFile && exportingSourceFile.symbol) {
|
|
152278
|
+
const { fixes } = getImportFixes(
|
|
152279
|
+
[{
|
|
152280
|
+
exportKind,
|
|
152281
|
+
isFromPackageJson: false,
|
|
152282
|
+
moduleFileName: exportingFileName,
|
|
152283
|
+
moduleSymbol: exportingSourceFile.symbol,
|
|
152284
|
+
targetFlags: exportedMeanings
|
|
152285
|
+
}],
|
|
152286
|
+
/*usagePosition*/
|
|
152287
|
+
void 0,
|
|
152288
|
+
isImportUsageValidAsTypeOnly,
|
|
152289
|
+
useRequire,
|
|
152290
|
+
program,
|
|
152291
|
+
sourceFile,
|
|
152292
|
+
host,
|
|
152293
|
+
preferences
|
|
152294
|
+
);
|
|
152295
|
+
if (fixes.length) {
|
|
152296
|
+
addImport({ fix: fixes[0], symbolName: exportName, errorIdentifierText: exportName });
|
|
152297
|
+
}
|
|
152298
|
+
} else {
|
|
152299
|
+
const futureExportingSourceFile = createFutureSourceFile(exportingFileName, 99 /* ESNext */, program, host);
|
|
152300
|
+
const moduleSpecifier = ts_moduleSpecifiers_exports.getLocalModuleSpecifierBetweenFileNames(
|
|
152301
|
+
sourceFile,
|
|
152302
|
+
exportingFileName,
|
|
152303
|
+
compilerOptions,
|
|
152304
|
+
createModuleSpecifierResolutionHost(program, host)
|
|
152305
|
+
);
|
|
152306
|
+
const importKind = getImportKind(futureExportingSourceFile, exportKind, compilerOptions);
|
|
152307
|
+
const addAsTypeOnly = getAddAsTypeOnly(
|
|
152308
|
+
isImportUsageValidAsTypeOnly,
|
|
152309
|
+
/*isForNewImportDeclaration*/
|
|
152310
|
+
true,
|
|
152311
|
+
/*symbol*/
|
|
152312
|
+
void 0,
|
|
152313
|
+
exportedMeanings,
|
|
152314
|
+
program.getTypeChecker(),
|
|
152315
|
+
compilerOptions
|
|
152316
|
+
);
|
|
152317
|
+
const fix = {
|
|
152318
|
+
kind: 3 /* AddNew */,
|
|
152319
|
+
moduleSpecifier,
|
|
152320
|
+
importKind,
|
|
152321
|
+
addAsTypeOnly,
|
|
152322
|
+
useRequire
|
|
152323
|
+
};
|
|
152324
|
+
addImport({ fix, symbolName: exportName, errorIdentifierText: exportName });
|
|
152205
152325
|
}
|
|
152206
152326
|
}
|
|
152327
|
+
function removeExistingImport(declaration) {
|
|
152328
|
+
if (declaration.kind === 273 /* ImportClause */) {
|
|
152329
|
+
Debug.assertIsDefined(declaration.name, "ImportClause should have a name if it's being removed");
|
|
152330
|
+
}
|
|
152331
|
+
removeExisting.add(declaration);
|
|
152332
|
+
}
|
|
152207
152333
|
function addImport(info) {
|
|
152208
152334
|
var _a, _b;
|
|
152209
152335
|
const { fix, symbolName: symbolName2 } = info;
|
|
@@ -152216,10 +152342,9 @@ function createImportAdderWorker(sourceFile, program, useAutoImportProvider, pre
|
|
|
152216
152342
|
break;
|
|
152217
152343
|
case 2 /* AddToExisting */: {
|
|
152218
152344
|
const { importClauseOrBindingPattern, importKind, addAsTypeOnly } = fix;
|
|
152219
|
-
|
|
152220
|
-
let entry = addToExisting.get(key);
|
|
152345
|
+
let entry = addToExisting.get(importClauseOrBindingPattern);
|
|
152221
152346
|
if (!entry) {
|
|
152222
|
-
addToExisting.set(
|
|
152347
|
+
addToExisting.set(importClauseOrBindingPattern, entry = { importClauseOrBindingPattern, defaultImport: void 0, namedImports: /* @__PURE__ */ new Map() });
|
|
152223
152348
|
}
|
|
152224
152349
|
if (importKind === 0 /* Named */) {
|
|
152225
152350
|
const prevValue = entry == null ? void 0 : entry.namedImports.get(symbolName2);
|
|
@@ -152301,8 +152426,9 @@ function createImportAdderWorker(sourceFile, program, useAutoImportProvider, pre
|
|
|
152301
152426
|
}
|
|
152302
152427
|
}
|
|
152303
152428
|
function writeFixes(changeTracker, oldFileQuotePreference) {
|
|
152429
|
+
var _a, _b;
|
|
152304
152430
|
let quotePreference;
|
|
152305
|
-
if (sourceFile.imports.length === 0 && oldFileQuotePreference !== void 0) {
|
|
152431
|
+
if (isFullSourceFile(sourceFile) && sourceFile.imports.length === 0 && oldFileQuotePreference !== void 0) {
|
|
152306
152432
|
quotePreference = oldFileQuotePreference;
|
|
152307
152433
|
} else {
|
|
152308
152434
|
quotePreference = getQuotePreference(sourceFile, preferences);
|
|
@@ -152313,6 +152439,82 @@ function createImportAdderWorker(sourceFile, program, useAutoImportProvider, pre
|
|
|
152313
152439
|
for (const fix of importType) {
|
|
152314
152440
|
addImportType(changeTracker, sourceFile, fix, quotePreference);
|
|
152315
152441
|
}
|
|
152442
|
+
let importSpecifiersToRemoveWhileAdding;
|
|
152443
|
+
if (removeExisting.size) {
|
|
152444
|
+
Debug.assert(isFullSourceFile(sourceFile), "Cannot remove imports from a future source file");
|
|
152445
|
+
const importDeclarationsWithRemovals = new Set(mapDefined([...removeExisting], (d) => findAncestor(d, isImportDeclaration)));
|
|
152446
|
+
const variableDeclarationsWithRemovals = new Set(mapDefined([...removeExisting], (d) => findAncestor(d, isVariableDeclarationInitializedToRequire)));
|
|
152447
|
+
const emptyImportDeclarations = [...importDeclarationsWithRemovals].filter(
|
|
152448
|
+
(d) => {
|
|
152449
|
+
var _a2, _b2, _c;
|
|
152450
|
+
return (
|
|
152451
|
+
// nothing added to the import declaration
|
|
152452
|
+
!addToExisting.has(d.importClause) && // no default, or default is being removed
|
|
152453
|
+
(!((_a2 = d.importClause) == null ? void 0 : _a2.name) || removeExisting.has(d.importClause)) && // no namespace import, or namespace import is being removed
|
|
152454
|
+
(!tryCast((_b2 = d.importClause) == null ? void 0 : _b2.namedBindings, isNamespaceImport) || removeExisting.has(d.importClause.namedBindings)) && // no named imports, or all named imports are being removed
|
|
152455
|
+
(!tryCast((_c = d.importClause) == null ? void 0 : _c.namedBindings, isNamedImports) || every(d.importClause.namedBindings.elements, (e) => removeExisting.has(e)))
|
|
152456
|
+
);
|
|
152457
|
+
}
|
|
152458
|
+
);
|
|
152459
|
+
const emptyVariableDeclarations = [...variableDeclarationsWithRemovals].filter(
|
|
152460
|
+
(d) => (
|
|
152461
|
+
// no binding elements being added to the variable declaration
|
|
152462
|
+
(d.name.kind !== 206 /* ObjectBindingPattern */ || !addToExisting.has(d.name)) && // no binding elements, or all binding elements are being removed
|
|
152463
|
+
(d.name.kind !== 206 /* ObjectBindingPattern */ || every(d.name.elements, (e) => removeExisting.has(e)))
|
|
152464
|
+
)
|
|
152465
|
+
);
|
|
152466
|
+
const namedBindingsToDelete = [...importDeclarationsWithRemovals].filter(
|
|
152467
|
+
(d) => {
|
|
152468
|
+
var _a2, _b2;
|
|
152469
|
+
return (
|
|
152470
|
+
// has named bindings
|
|
152471
|
+
((_a2 = d.importClause) == null ? void 0 : _a2.namedBindings) && // is not being fully removed
|
|
152472
|
+
emptyImportDeclarations.indexOf(d) === -1 && // is not gaining named imports
|
|
152473
|
+
!((_b2 = addToExisting.get(d.importClause)) == null ? void 0 : _b2.namedImports) && // all named imports are being removed
|
|
152474
|
+
(d.importClause.namedBindings.kind === 274 /* NamespaceImport */ || every(d.importClause.namedBindings.elements, (e) => removeExisting.has(e)))
|
|
152475
|
+
);
|
|
152476
|
+
}
|
|
152477
|
+
);
|
|
152478
|
+
for (const declaration of [...emptyImportDeclarations, ...emptyVariableDeclarations]) {
|
|
152479
|
+
changeTracker.delete(sourceFile, declaration);
|
|
152480
|
+
}
|
|
152481
|
+
for (const declaration of namedBindingsToDelete) {
|
|
152482
|
+
changeTracker.replaceNode(
|
|
152483
|
+
sourceFile,
|
|
152484
|
+
declaration.importClause,
|
|
152485
|
+
factory.updateImportClause(
|
|
152486
|
+
declaration.importClause,
|
|
152487
|
+
declaration.importClause.isTypeOnly,
|
|
152488
|
+
declaration.importClause.name,
|
|
152489
|
+
/*namedBindings*/
|
|
152490
|
+
void 0
|
|
152491
|
+
)
|
|
152492
|
+
);
|
|
152493
|
+
}
|
|
152494
|
+
for (const declaration of removeExisting) {
|
|
152495
|
+
const importDeclaration = findAncestor(declaration, isImportDeclaration);
|
|
152496
|
+
if (importDeclaration && emptyImportDeclarations.indexOf(importDeclaration) === -1 && namedBindingsToDelete.indexOf(importDeclaration) === -1) {
|
|
152497
|
+
if (declaration.kind === 273 /* ImportClause */) {
|
|
152498
|
+
changeTracker.delete(sourceFile, declaration.name);
|
|
152499
|
+
} else {
|
|
152500
|
+
Debug.assert(declaration.kind === 276 /* ImportSpecifier */, "NamespaceImport should have been handled earlier");
|
|
152501
|
+
if ((_a = addToExisting.get(importDeclaration.importClause)) == null ? void 0 : _a.namedImports) {
|
|
152502
|
+
(importSpecifiersToRemoveWhileAdding ?? (importSpecifiersToRemoveWhileAdding = /* @__PURE__ */ new Set())).add(declaration);
|
|
152503
|
+
} else {
|
|
152504
|
+
changeTracker.delete(sourceFile, declaration);
|
|
152505
|
+
}
|
|
152506
|
+
}
|
|
152507
|
+
} else if (declaration.kind === 208 /* BindingElement */) {
|
|
152508
|
+
if ((_b = addToExisting.get(declaration.parent)) == null ? void 0 : _b.namedImports) {
|
|
152509
|
+
(importSpecifiersToRemoveWhileAdding ?? (importSpecifiersToRemoveWhileAdding = /* @__PURE__ */ new Set())).add(declaration);
|
|
152510
|
+
} else {
|
|
152511
|
+
changeTracker.delete(sourceFile, declaration);
|
|
152512
|
+
}
|
|
152513
|
+
} else if (declaration.kind === 271 /* ImportEqualsDeclaration */) {
|
|
152514
|
+
changeTracker.delete(sourceFile, declaration);
|
|
152515
|
+
}
|
|
152516
|
+
}
|
|
152517
|
+
}
|
|
152316
152518
|
addToExisting.forEach(({ importClauseOrBindingPattern, defaultImport, namedImports }) => {
|
|
152317
152519
|
doAddExistingFix(
|
|
152318
152520
|
changeTracker,
|
|
@@ -152320,6 +152522,7 @@ function createImportAdderWorker(sourceFile, program, useAutoImportProvider, pre
|
|
|
152320
152522
|
importClauseOrBindingPattern,
|
|
152321
152523
|
defaultImport,
|
|
152322
152524
|
arrayFrom(namedImports.entries(), ([name, addAsTypeOnly]) => ({ addAsTypeOnly, name })),
|
|
152525
|
+
importSpecifiersToRemoveWhileAdding,
|
|
152323
152526
|
preferences
|
|
152324
152527
|
);
|
|
152325
152528
|
});
|
|
@@ -152338,6 +152541,7 @@ function createImportAdderWorker(sourceFile, program, useAutoImportProvider, pre
|
|
|
152338
152541
|
);
|
|
152339
152542
|
newDeclarations = combine(newDeclarations, declarations);
|
|
152340
152543
|
});
|
|
152544
|
+
newDeclarations = combine(newDeclarations, getCombinedVerbatimImports());
|
|
152341
152545
|
if (newDeclarations) {
|
|
152342
152546
|
insertImports(
|
|
152343
152547
|
changeTracker,
|
|
@@ -152349,8 +152553,85 @@ function createImportAdderWorker(sourceFile, program, useAutoImportProvider, pre
|
|
|
152349
152553
|
);
|
|
152350
152554
|
}
|
|
152351
152555
|
}
|
|
152556
|
+
function getCombinedVerbatimImports() {
|
|
152557
|
+
if (!verbatimImports.size)
|
|
152558
|
+
return void 0;
|
|
152559
|
+
const importDeclarations = new Set(mapDefined([...verbatimImports], (d) => findAncestor(d, isImportDeclaration)));
|
|
152560
|
+
const requireStatements = new Set(mapDefined([...verbatimImports], (d) => findAncestor(d, isRequireVariableStatement)));
|
|
152561
|
+
return [
|
|
152562
|
+
...mapDefined([...verbatimImports], (d) => d.kind === 271 /* ImportEqualsDeclaration */ ? getSynthesizedDeepClone(
|
|
152563
|
+
d,
|
|
152564
|
+
/*includeTrivia*/
|
|
152565
|
+
true
|
|
152566
|
+
) : void 0),
|
|
152567
|
+
...[...importDeclarations].map((d) => {
|
|
152568
|
+
var _a;
|
|
152569
|
+
if (verbatimImports.has(d)) {
|
|
152570
|
+
return getSynthesizedDeepClone(
|
|
152571
|
+
d,
|
|
152572
|
+
/*includeTrivia*/
|
|
152573
|
+
true
|
|
152574
|
+
);
|
|
152575
|
+
}
|
|
152576
|
+
return getSynthesizedDeepClone(
|
|
152577
|
+
factory.updateImportDeclaration(
|
|
152578
|
+
d,
|
|
152579
|
+
d.modifiers,
|
|
152580
|
+
d.importClause && factory.updateImportClause(
|
|
152581
|
+
d.importClause,
|
|
152582
|
+
d.importClause.isTypeOnly,
|
|
152583
|
+
verbatimImports.has(d.importClause) ? d.importClause.name : void 0,
|
|
152584
|
+
verbatimImports.has(d.importClause.namedBindings) ? d.importClause.namedBindings : ((_a = tryCast(d.importClause.namedBindings, isNamedImports)) == null ? void 0 : _a.elements.some((e) => verbatimImports.has(e))) ? factory.updateNamedImports(
|
|
152585
|
+
d.importClause.namedBindings,
|
|
152586
|
+
d.importClause.namedBindings.elements.filter((e) => verbatimImports.has(e))
|
|
152587
|
+
) : void 0
|
|
152588
|
+
),
|
|
152589
|
+
d.moduleSpecifier,
|
|
152590
|
+
d.attributes
|
|
152591
|
+
),
|
|
152592
|
+
/*includeTrivia*/
|
|
152593
|
+
true
|
|
152594
|
+
);
|
|
152595
|
+
}),
|
|
152596
|
+
...[...requireStatements].map((s) => {
|
|
152597
|
+
if (verbatimImports.has(s)) {
|
|
152598
|
+
return getSynthesizedDeepClone(
|
|
152599
|
+
s,
|
|
152600
|
+
/*includeTrivia*/
|
|
152601
|
+
true
|
|
152602
|
+
);
|
|
152603
|
+
}
|
|
152604
|
+
return getSynthesizedDeepClone(
|
|
152605
|
+
factory.updateVariableStatement(
|
|
152606
|
+
s,
|
|
152607
|
+
s.modifiers,
|
|
152608
|
+
factory.updateVariableDeclarationList(
|
|
152609
|
+
s.declarationList,
|
|
152610
|
+
mapDefined(s.declarationList.declarations, (d) => {
|
|
152611
|
+
if (verbatimImports.has(d)) {
|
|
152612
|
+
return d;
|
|
152613
|
+
}
|
|
152614
|
+
return factory.updateVariableDeclaration(
|
|
152615
|
+
d,
|
|
152616
|
+
d.name.kind === 206 /* ObjectBindingPattern */ ? factory.updateObjectBindingPattern(
|
|
152617
|
+
d.name,
|
|
152618
|
+
d.name.elements.filter((e) => verbatimImports.has(e))
|
|
152619
|
+
) : d.name,
|
|
152620
|
+
d.exclamationToken,
|
|
152621
|
+
d.type,
|
|
152622
|
+
d.initializer
|
|
152623
|
+
);
|
|
152624
|
+
})
|
|
152625
|
+
)
|
|
152626
|
+
),
|
|
152627
|
+
/*includeTrivia*/
|
|
152628
|
+
true
|
|
152629
|
+
);
|
|
152630
|
+
})
|
|
152631
|
+
];
|
|
152632
|
+
}
|
|
152352
152633
|
function hasFixes() {
|
|
152353
|
-
return addToNamespace.length > 0 || importType.length > 0 || addToExisting.size > 0 || newImports.size > 0;
|
|
152634
|
+
return addToNamespace.length > 0 || importType.length > 0 || addToExisting.size > 0 || newImports.size > 0 || verbatimImports.size > 0 || removeExisting.size > 0;
|
|
152354
152635
|
}
|
|
152355
152636
|
}
|
|
152356
152637
|
function createImportSpecifierResolver(importingFile, program, host, preferences) {
|
|
@@ -152459,9 +152740,12 @@ function getSingleExportInfoForSymbol(symbol, symbolName2, moduleSymbol, program
|
|
|
152459
152740
|
}
|
|
152460
152741
|
}
|
|
152461
152742
|
}
|
|
152462
|
-
function
|
|
152743
|
+
function isFutureSymbolExportInfoArray(info) {
|
|
152744
|
+
return info[0].symbol === void 0;
|
|
152745
|
+
}
|
|
152746
|
+
function getImportFixes(exportInfos, usagePosition, isValidTypeOnlyUseSite, useRequire, program, sourceFile, host, preferences, importMap = isFullSourceFile(sourceFile) ? createExistingImportMap(program.getTypeChecker(), sourceFile, program.getCompilerOptions()) : void 0, fromCacheOnly) {
|
|
152463
152747
|
const checker = program.getTypeChecker();
|
|
152464
|
-
const existingImports = flatMap(exportInfos, importMap.getImportsForExportInfo);
|
|
152748
|
+
const existingImports = importMap && !isFutureSymbolExportInfoArray(exportInfos) ? flatMap(exportInfos, importMap.getImportsForExportInfo) : emptyArray;
|
|
152465
152749
|
const useNamespace = usagePosition !== void 0 && tryUseExistingNamespaceImport(existingImports, usagePosition);
|
|
152466
152750
|
const addToExisting = tryAddToExistingImport(existingImports, isValidTypeOnlyUseSite, checker, program.getCompilerOptions());
|
|
152467
152751
|
if (addToExisting) {
|
|
@@ -152517,7 +152801,7 @@ function getAddAsTypeOnly(isValidTypeOnlyUseSite, isForNewImportDeclaration, sym
|
|
|
152517
152801
|
if (!isValidTypeOnlyUseSite) {
|
|
152518
152802
|
return 4 /* NotAllowed */;
|
|
152519
152803
|
}
|
|
152520
|
-
if (compilerOptions.verbatimModuleSyntax && (!(targetFlags & 111551 /* Value */) || !!checker.getTypeOnlyAliasDeclaration(symbol))) {
|
|
152804
|
+
if (symbol && compilerOptions.verbatimModuleSyntax && (!(targetFlags & 111551 /* Value */) || !!checker.getTypeOnlyAliasDeclaration(symbol))) {
|
|
152521
152805
|
return 2 /* Required */;
|
|
152522
152806
|
}
|
|
152523
152807
|
return 1 /* Allowed */;
|
|
@@ -152604,7 +152888,7 @@ function createExistingImportMap(checker, importingFile, compilerOptions) {
|
|
|
152604
152888
|
};
|
|
152605
152889
|
}
|
|
152606
152890
|
function shouldUseRequire(sourceFile, program) {
|
|
152607
|
-
if (!
|
|
152891
|
+
if (!hasJSFileExtension(sourceFile.fileName)) {
|
|
152608
152892
|
return false;
|
|
152609
152893
|
}
|
|
152610
152894
|
if (sourceFile.commonJsModuleIndicator && !sourceFile.externalModuleIndicator)
|
|
@@ -152633,14 +152917,14 @@ function createGetChecker(program, host) {
|
|
|
152633
152917
|
return memoizeOne((isFromPackageJson) => isFromPackageJson ? host.getPackageJsonAutoImportProvider().getTypeChecker() : program.getTypeChecker());
|
|
152634
152918
|
}
|
|
152635
152919
|
function getNewImportFixes(program, sourceFile, usagePosition, isValidTypeOnlyUseSite, useRequire, exportInfo, host, preferences, fromCacheOnly) {
|
|
152636
|
-
const isJs =
|
|
152920
|
+
const isJs = hasJSFileExtension(sourceFile.fileName);
|
|
152637
152921
|
const compilerOptions = program.getCompilerOptions();
|
|
152638
152922
|
const moduleSpecifierResolutionHost = createModuleSpecifierResolutionHost(program, host);
|
|
152639
152923
|
const getChecker = createGetChecker(program, host);
|
|
152640
152924
|
const moduleResolution = getEmitModuleResolutionKind(compilerOptions);
|
|
152641
152925
|
const rejectNodeModulesRelativePaths = moduleResolutionUsesNodeModules(moduleResolution);
|
|
152642
|
-
const getModuleSpecifiers2 = fromCacheOnly ? (
|
|
152643
|
-
moduleSymbol,
|
|
152926
|
+
const getModuleSpecifiers2 = fromCacheOnly ? (exportInfo2) => ({ moduleSpecifiers: ts_moduleSpecifiers_exports.tryGetModuleSpecifiersFromCache(exportInfo2.moduleSymbol, sourceFile, moduleSpecifierResolutionHost, preferences), computedWithoutCache: false }) : (exportInfo2, checker) => ts_moduleSpecifiers_exports.getModuleSpecifiersWithCacheInfo(
|
|
152927
|
+
exportInfo2.moduleSymbol,
|
|
152644
152928
|
checker,
|
|
152645
152929
|
compilerOptions,
|
|
152646
152930
|
sourceFile,
|
|
@@ -152654,7 +152938,7 @@ function getNewImportFixes(program, sourceFile, usagePosition, isValidTypeOnlyUs
|
|
|
152654
152938
|
let computedWithoutCacheCount = 0;
|
|
152655
152939
|
const fixes = flatMap(exportInfo, (exportInfo2, i) => {
|
|
152656
152940
|
const checker = getChecker(exportInfo2.isFromPackageJson);
|
|
152657
|
-
const { computedWithoutCache, moduleSpecifiers } = getModuleSpecifiers2(exportInfo2
|
|
152941
|
+
const { computedWithoutCache, moduleSpecifiers } = getModuleSpecifiers2(exportInfo2, checker);
|
|
152658
152942
|
const importedSymbolHasValueMeaning = !!(exportInfo2.targetFlags & 111551 /* Value */);
|
|
152659
152943
|
const addAsTypeOnly = getAddAsTypeOnly(
|
|
152660
152944
|
isValidTypeOnlyUseSite,
|
|
@@ -152745,6 +153029,11 @@ function sortFixInfo(fixes, sourceFile, program, packageJsonImportFilter, host)
|
|
|
152745
153029
|
const _toPath = (fileName) => toPath(fileName, host.getCurrentDirectory(), hostGetCanonicalFileName(host));
|
|
152746
153030
|
return sort(fixes, (a, b) => compareBooleans(!!a.isJsxNamespaceFix, !!b.isJsxNamespaceFix) || compareValues(a.fix.kind, b.fix.kind) || compareModuleSpecifiers(a.fix, b.fix, sourceFile, program, packageJsonImportFilter.allowsImportingSpecifier, _toPath));
|
|
152747
153031
|
}
|
|
153032
|
+
function getFixInfosWithoutDiagnostic(context, symbolToken, useAutoImportProvider) {
|
|
153033
|
+
const info = getFixesInfoForNonUMDImport(context, symbolToken, useAutoImportProvider);
|
|
153034
|
+
const packageJsonImportFilter = createPackageJsonImportFilter(context.sourceFile, context.preferences, context.host);
|
|
153035
|
+
return info && sortFixInfo(info, context.sourceFile, context.program, packageJsonImportFilter, context.host);
|
|
153036
|
+
}
|
|
152748
153037
|
function getBestFix(fixes, sourceFile, program, packageJsonImportFilter, host) {
|
|
152749
153038
|
if (!some(fixes))
|
|
152750
153039
|
return;
|
|
@@ -152768,17 +153057,17 @@ function getBestFix(fixes, sourceFile, program, packageJsonImportFilter, host) {
|
|
|
152768
153057
|
function compareModuleSpecifiers(a, b, importingFile, program, allowsImportingSpecifier, toPath3) {
|
|
152769
153058
|
if (a.kind !== 0 /* UseNamespace */ && b.kind !== 0 /* UseNamespace */) {
|
|
152770
153059
|
return compareBooleans(allowsImportingSpecifier(b.moduleSpecifier), allowsImportingSpecifier(a.moduleSpecifier)) || compareNodeCoreModuleSpecifiers(a.moduleSpecifier, b.moduleSpecifier, importingFile, program) || compareBooleans(
|
|
152771
|
-
isFixPossiblyReExportingImportingFile(a, importingFile
|
|
152772
|
-
isFixPossiblyReExportingImportingFile(b, importingFile
|
|
153060
|
+
isFixPossiblyReExportingImportingFile(a, importingFile.path, toPath3),
|
|
153061
|
+
isFixPossiblyReExportingImportingFile(b, importingFile.path, toPath3)
|
|
152773
153062
|
) || compareNumberOfDirectorySeparators(a.moduleSpecifier, b.moduleSpecifier);
|
|
152774
153063
|
}
|
|
152775
153064
|
return 0 /* EqualTo */;
|
|
152776
153065
|
}
|
|
152777
|
-
function isFixPossiblyReExportingImportingFile(fix,
|
|
153066
|
+
function isFixPossiblyReExportingImportingFile(fix, importingFilePath, toPath3) {
|
|
152778
153067
|
var _a;
|
|
152779
153068
|
if (fix.isReExport && ((_a = fix.exportInfo) == null ? void 0 : _a.moduleFileName) && isIndexFileName(fix.exportInfo.moduleFileName)) {
|
|
152780
153069
|
const reExportDir = toPath3(getDirectoryPath(fix.exportInfo.moduleFileName));
|
|
152781
|
-
return startsWith(
|
|
153070
|
+
return startsWith(importingFilePath, reExportDir);
|
|
152782
153071
|
}
|
|
152783
153072
|
return false;
|
|
152784
153073
|
}
|
|
@@ -152868,8 +153157,8 @@ function getUmdImportKind(importingFile, compilerOptions, forceImportKeyword) {
|
|
|
152868
153157
|
case 2 /* AMD */:
|
|
152869
153158
|
case 1 /* CommonJS */:
|
|
152870
153159
|
case 3 /* UMD */:
|
|
152871
|
-
if (
|
|
152872
|
-
return
|
|
153160
|
+
if (hasJSFileExtension(importingFile.fileName)) {
|
|
153161
|
+
return importingFile.externalModuleIndicator || forceImportKeyword ? 2 /* Namespace */ : 3 /* CommonJS */;
|
|
152873
153162
|
}
|
|
152874
153163
|
return 3 /* CommonJS */;
|
|
152875
153164
|
case 4 /* System */:
|
|
@@ -152980,14 +153269,14 @@ function getExportInfos(symbolName2, isJsxTagName, currentTokenMeaning, cancella
|
|
|
152980
153269
|
}
|
|
152981
153270
|
function getExportEqualsImportKind(importingFile, compilerOptions, forceImportKeyword) {
|
|
152982
153271
|
const allowSyntheticDefaults = getAllowSyntheticDefaultImports(compilerOptions);
|
|
152983
|
-
const isJS =
|
|
153272
|
+
const isJS = hasJSFileExtension(importingFile.fileName);
|
|
152984
153273
|
if (!isJS && getEmitModuleKind(compilerOptions) >= 5 /* ES2015 */) {
|
|
152985
153274
|
return allowSyntheticDefaults ? 1 /* Default */ : 2 /* Namespace */;
|
|
152986
153275
|
}
|
|
152987
153276
|
if (isJS) {
|
|
152988
|
-
return
|
|
153277
|
+
return importingFile.externalModuleIndicator || forceImportKeyword ? allowSyntheticDefaults ? 1 /* Default */ : 2 /* Namespace */ : 3 /* CommonJS */;
|
|
152989
153278
|
}
|
|
152990
|
-
for (const statement of importingFile.statements) {
|
|
153279
|
+
for (const statement of importingFile.statements ?? emptyArray) {
|
|
152991
153280
|
if (isImportEqualsDeclaration(statement) && !nodeIsMissing(statement.moduleReference)) {
|
|
152992
153281
|
return 3 /* CommonJS */;
|
|
152993
153282
|
}
|
|
@@ -153018,6 +153307,8 @@ function codeActionForFixWorker(changes, sourceFile, symbolName2, fix, includeSy
|
|
|
153018
153307
|
importClauseOrBindingPattern,
|
|
153019
153308
|
importKind === 1 /* Default */ ? { name: symbolName2, addAsTypeOnly } : void 0,
|
|
153020
153309
|
importKind === 0 /* Named */ ? [{ name: symbolName2, addAsTypeOnly }] : emptyArray,
|
|
153310
|
+
/*removeExistingImportSpecifiers*/
|
|
153311
|
+
void 0,
|
|
153021
153312
|
preferences
|
|
153022
153313
|
);
|
|
153023
153314
|
const moduleSpecifierWithoutQuotes = stripQuotes(moduleSpecifier);
|
|
@@ -153132,9 +153423,33 @@ function promoteFromTypeOnly(changes, aliasDeclaration, program, sourceFile, pre
|
|
|
153132
153423
|
}
|
|
153133
153424
|
}
|
|
153134
153425
|
}
|
|
153135
|
-
function doAddExistingFix(changes, sourceFile, clause, defaultImport, namedImports, preferences) {
|
|
153426
|
+
function doAddExistingFix(changes, sourceFile, clause, defaultImport, namedImports, removeExistingImportSpecifiers, preferences) {
|
|
153136
153427
|
var _a;
|
|
153137
153428
|
if (clause.kind === 206 /* ObjectBindingPattern */) {
|
|
153429
|
+
if (removeExistingImportSpecifiers && clause.elements.some((e) => removeExistingImportSpecifiers.has(e))) {
|
|
153430
|
+
changes.replaceNode(
|
|
153431
|
+
sourceFile,
|
|
153432
|
+
clause,
|
|
153433
|
+
factory.createObjectBindingPattern([
|
|
153434
|
+
...clause.elements.filter((e) => !removeExistingImportSpecifiers.has(e)),
|
|
153435
|
+
...defaultImport ? [factory.createBindingElement(
|
|
153436
|
+
/*dotDotDotToken*/
|
|
153437
|
+
void 0,
|
|
153438
|
+
/*propertyName*/
|
|
153439
|
+
"default",
|
|
153440
|
+
defaultImport.name
|
|
153441
|
+
)] : emptyArray,
|
|
153442
|
+
...namedImports.map((i) => factory.createBindingElement(
|
|
153443
|
+
/*dotDotDotToken*/
|
|
153444
|
+
void 0,
|
|
153445
|
+
/*propertyName*/
|
|
153446
|
+
void 0,
|
|
153447
|
+
i.name
|
|
153448
|
+
))
|
|
153449
|
+
])
|
|
153450
|
+
);
|
|
153451
|
+
return;
|
|
153452
|
+
}
|
|
153138
153453
|
if (defaultImport) {
|
|
153139
153454
|
addElementToBindingPattern(clause, defaultImport.name, "default");
|
|
153140
153455
|
}
|
|
@@ -153167,7 +153482,16 @@ function doAddExistingFix(changes, sourceFile, clause, defaultImport, namedImpor
|
|
|
153167
153482
|
),
|
|
153168
153483
|
specifierComparer
|
|
153169
153484
|
);
|
|
153170
|
-
if (
|
|
153485
|
+
if (removeExistingImportSpecifiers) {
|
|
153486
|
+
changes.replaceNode(
|
|
153487
|
+
sourceFile,
|
|
153488
|
+
clause.namedBindings,
|
|
153489
|
+
factory.updateNamedImports(
|
|
153490
|
+
clause.namedBindings,
|
|
153491
|
+
stableSort([...existingSpecifiers.filter((s) => !removeExistingImportSpecifiers.has(s)), ...newSpecifiers], specifierComparer)
|
|
153492
|
+
)
|
|
153493
|
+
);
|
|
153494
|
+
} else if ((existingSpecifiers == null ? void 0 : existingSpecifiers.length) && isSorted !== false) {
|
|
153171
153495
|
const transformedExistingSpecifiers = promoteFromTypeOnly2 && existingSpecifiers ? factory.updateNamedImports(
|
|
153172
153496
|
clause.namedBindings,
|
|
153173
153497
|
sameMap(existingSpecifiers, (e) => factory.updateImportSpecifier(
|
|
@@ -162003,13 +162327,13 @@ function getCompletionData(program, log, sourceFile, compilerOptions, position,
|
|
|
162003
162327
|
({ exportInfo: exportInfo2 = info[0], moduleSpecifier } = result);
|
|
162004
162328
|
}
|
|
162005
162329
|
const isDefaultExport = exportInfo2.exportKind === 1 /* Default */;
|
|
162006
|
-
const symbol = isDefaultExport && getLocalSymbolForExportDefault(exportInfo2.symbol) || exportInfo2.symbol;
|
|
162330
|
+
const symbol = isDefaultExport && getLocalSymbolForExportDefault(Debug.checkDefined(exportInfo2.symbol)) || Debug.checkDefined(exportInfo2.symbol);
|
|
162007
162331
|
pushAutoImportSymbol(symbol, {
|
|
162008
162332
|
kind: moduleSpecifier ? 32 /* ResolvedExport */ : 4 /* Export */,
|
|
162009
162333
|
moduleSpecifier,
|
|
162010
162334
|
symbolName: symbolName2,
|
|
162011
162335
|
exportMapKey,
|
|
162012
|
-
exportName: exportInfo2.exportKind === 2 /* ExportEquals */ ? "export=" /* ExportEquals */ : exportInfo2.symbol.name,
|
|
162336
|
+
exportName: exportInfo2.exportKind === 2 /* ExportEquals */ ? "export=" /* ExportEquals */ : Debug.checkDefined(exportInfo2.symbol).name,
|
|
162013
162337
|
fileName: exportInfo2.moduleFileName,
|
|
162014
162338
|
isDefaultExport,
|
|
162015
162339
|
moduleSymbol: exportInfo2.moduleSymbol,
|
|
@@ -175463,6 +175787,7 @@ __export(ts_exports2, {
|
|
|
175463
175787
|
createFileDiagnosticFromMessageChain: () => createFileDiagnosticFromMessageChain,
|
|
175464
175788
|
createFlowNode: () => createFlowNode,
|
|
175465
175789
|
createForOfBindingStatement: () => createForOfBindingStatement,
|
|
175790
|
+
createFutureSourceFile: () => createFutureSourceFile,
|
|
175466
175791
|
createGetCanonicalFileName: () => createGetCanonicalFileName,
|
|
175467
175792
|
createGetSourceFile: () => createGetSourceFile,
|
|
175468
175793
|
createGetSymbolAccessibilityDiagnosticForNode: () => createGetSymbolAccessibilityDiagnosticForNode,
|
|
@@ -176234,6 +176559,7 @@ __export(ts_exports2, {
|
|
|
176234
176559
|
isAnyDirectorySeparator: () => isAnyDirectorySeparator,
|
|
176235
176560
|
isAnyImportOrBareOrAccessedRequire: () => isAnyImportOrBareOrAccessedRequire,
|
|
176236
176561
|
isAnyImportOrReExport: () => isAnyImportOrReExport,
|
|
176562
|
+
isAnyImportOrRequireStatement: () => isAnyImportOrRequireStatement,
|
|
176237
176563
|
isAnyImportSyntax: () => isAnyImportSyntax,
|
|
176238
176564
|
isAnySupportedFileExtension: () => isAnySupportedFileExtension,
|
|
176239
176565
|
isApplicableVersionedTypesKey: () => isApplicableVersionedTypesKey,
|
|
@@ -176424,6 +176750,7 @@ __export(ts_exports2, {
|
|
|
176424
176750
|
isForInitializer: () => isForInitializer,
|
|
176425
176751
|
isForOfStatement: () => isForOfStatement,
|
|
176426
176752
|
isForStatement: () => isForStatement,
|
|
176753
|
+
isFullSourceFile: () => isFullSourceFile,
|
|
176427
176754
|
isFunctionBlock: () => isFunctionBlock,
|
|
176428
176755
|
isFunctionBody: () => isFunctionBody,
|
|
176429
176756
|
isFunctionDeclaration: () => isFunctionDeclaration,
|
|
@@ -189704,6 +190031,7 @@ if (typeof console !== "undefined") {
|
|
|
189704
190031
|
createFileDiagnosticFromMessageChain,
|
|
189705
190032
|
createFlowNode,
|
|
189706
190033
|
createForOfBindingStatement,
|
|
190034
|
+
createFutureSourceFile,
|
|
189707
190035
|
createGetCanonicalFileName,
|
|
189708
190036
|
createGetSourceFile,
|
|
189709
190037
|
createGetSymbolAccessibilityDiagnosticForNode,
|
|
@@ -190475,6 +190803,7 @@ if (typeof console !== "undefined") {
|
|
|
190475
190803
|
isAnyDirectorySeparator,
|
|
190476
190804
|
isAnyImportOrBareOrAccessedRequire,
|
|
190477
190805
|
isAnyImportOrReExport,
|
|
190806
|
+
isAnyImportOrRequireStatement,
|
|
190478
190807
|
isAnyImportSyntax,
|
|
190479
190808
|
isAnySupportedFileExtension,
|
|
190480
190809
|
isApplicableVersionedTypesKey,
|
|
@@ -190665,6 +190994,7 @@ if (typeof console !== "undefined") {
|
|
|
190665
190994
|
isForInitializer,
|
|
190666
190995
|
isForOfStatement,
|
|
190667
190996
|
isForStatement,
|
|
190997
|
+
isFullSourceFile,
|
|
190668
190998
|
isFunctionBlock,
|
|
190669
190999
|
isFunctionBody,
|
|
190670
191000
|
isFunctionDeclaration,
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "typescript",
|
|
3
3
|
"author": "Microsoft Corp.",
|
|
4
4
|
"homepage": "https://www.typescriptlang.org/",
|
|
5
|
-
"version": "5.5.0-dev.
|
|
5
|
+
"version": "5.5.0-dev.20240410",
|
|
6
6
|
"license": "Apache-2.0",
|
|
7
7
|
"description": "TypeScript is a language for application scale JavaScript development",
|
|
8
8
|
"keywords": [
|
|
@@ -111,5 +111,5 @@
|
|
|
111
111
|
"node": "20.1.0",
|
|
112
112
|
"npm": "8.19.4"
|
|
113
113
|
},
|
|
114
|
-
"gitHead": "
|
|
114
|
+
"gitHead": "b6351c61363f7ed11f160f1b54183a905335bcea"
|
|
115
115
|
}
|