typescript 4.6.0-dev.20220109 → 4.6.0-dev.20220113
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 +158 -44
- package/lib/tsserver.js +294 -118
- package/lib/tsserverlibrary.js +294 -118
- package/lib/typescript.js +240 -97
- package/lib/typescriptServices.js +240 -97
- package/lib/typingsInstaller.js +192 -52
- package/package.json +1 -1
package/lib/tsserver.js
CHANGED
|
@@ -100,7 +100,7 @@ var ts;
|
|
|
100
100
|
// The following is baselined as a literal template type without intervention
|
|
101
101
|
/** The version of the TypeScript compiler release */
|
|
102
102
|
// eslint-disable-next-line @typescript-eslint/no-inferrable-types
|
|
103
|
-
ts.version = ts.versionMajorMinor + ".0-dev.
|
|
103
|
+
ts.version = ts.versionMajorMinor + ".0-dev.20220113";
|
|
104
104
|
/* @internal */
|
|
105
105
|
var Comparison;
|
|
106
106
|
(function (Comparison) {
|
|
@@ -19791,16 +19791,6 @@ var ts;
|
|
|
19791
19791
|
(symlinkedDirectories || (symlinkedDirectories = new ts.Map())).set(symlinkPath, real);
|
|
19792
19792
|
}
|
|
19793
19793
|
},
|
|
19794
|
-
setSymlinkedDirectoryFromSymlinkedFile: function (symlink, real) {
|
|
19795
|
-
this.setSymlinkedFile(ts.toPath(symlink, cwd, getCanonicalFileName), real);
|
|
19796
|
-
var _a = guessDirectorySymlink(real, symlink, cwd, getCanonicalFileName) || ts.emptyArray, commonResolved = _a[0], commonOriginal = _a[1];
|
|
19797
|
-
if (commonResolved && commonOriginal) {
|
|
19798
|
-
this.setSymlinkedDirectory(commonOriginal, {
|
|
19799
|
-
real: commonResolved,
|
|
19800
|
-
realPath: ts.toPath(commonResolved, cwd, getCanonicalFileName),
|
|
19801
|
-
});
|
|
19802
|
-
}
|
|
19803
|
-
},
|
|
19804
19794
|
setSymlinksFromResolutions: function (files, typeReferenceDirectives) {
|
|
19805
19795
|
var _this = this;
|
|
19806
19796
|
var _a;
|
|
@@ -41509,9 +41499,7 @@ var ts;
|
|
|
41509
41499
|
}
|
|
41510
41500
|
}
|
|
41511
41501
|
var failedLookupLocations = [];
|
|
41512
|
-
var features =
|
|
41513
|
-
ts.getEmitModuleResolutionKind(options) === ts.ModuleResolutionKind.NodeNext ? NodeResolutionFeatures.NodeNextDefault :
|
|
41514
|
-
NodeResolutionFeatures.None;
|
|
41502
|
+
var features = getDefaultNodeResolutionFeatures(options);
|
|
41515
41503
|
var moduleResolutionState = { compilerOptions: options, host: host, traceEnabled: traceEnabled, failedLookupLocations: failedLookupLocations, packageJsonInfoCache: cache, features: features, conditions: ["node", "require", "types"] };
|
|
41516
41504
|
var resolved = primaryLookup();
|
|
41517
41505
|
var primary = true;
|
|
@@ -41596,6 +41584,34 @@ var ts;
|
|
|
41596
41584
|
}
|
|
41597
41585
|
}
|
|
41598
41586
|
ts.resolveTypeReferenceDirective = resolveTypeReferenceDirective;
|
|
41587
|
+
function getDefaultNodeResolutionFeatures(options) {
|
|
41588
|
+
return ts.getEmitModuleResolutionKind(options) === ts.ModuleResolutionKind.Node12 ? NodeResolutionFeatures.Node12Default :
|
|
41589
|
+
ts.getEmitModuleResolutionKind(options) === ts.ModuleResolutionKind.NodeNext ? NodeResolutionFeatures.NodeNextDefault :
|
|
41590
|
+
NodeResolutionFeatures.None;
|
|
41591
|
+
}
|
|
41592
|
+
/**
|
|
41593
|
+
* @internal
|
|
41594
|
+
* Does not try `@types/${packageName}` - use a second pass if needed.
|
|
41595
|
+
*/
|
|
41596
|
+
function resolvePackageNameToPackageJson(packageName, containingDirectory, options, host, cache) {
|
|
41597
|
+
var moduleResolutionState = {
|
|
41598
|
+
compilerOptions: options,
|
|
41599
|
+
host: host,
|
|
41600
|
+
traceEnabled: isTraceEnabled(options, host),
|
|
41601
|
+
failedLookupLocations: [],
|
|
41602
|
+
packageJsonInfoCache: cache === null || cache === void 0 ? void 0 : cache.getPackageJsonInfoCache(),
|
|
41603
|
+
conditions: ts.emptyArray,
|
|
41604
|
+
features: NodeResolutionFeatures.None,
|
|
41605
|
+
};
|
|
41606
|
+
return ts.forEachAncestorDirectory(containingDirectory, function (ancestorDirectory) {
|
|
41607
|
+
if (ts.getBaseFileName(ancestorDirectory) !== "node_modules") {
|
|
41608
|
+
var nodeModulesFolder = ts.combinePaths(ancestorDirectory, "node_modules");
|
|
41609
|
+
var candidate = ts.combinePaths(nodeModulesFolder, packageName);
|
|
41610
|
+
return getPackageJsonInfo(candidate, /*onlyRecordFailures*/ false, moduleResolutionState);
|
|
41611
|
+
}
|
|
41612
|
+
});
|
|
41613
|
+
}
|
|
41614
|
+
ts.resolvePackageNameToPackageJson = resolvePackageNameToPackageJson;
|
|
41599
41615
|
/**
|
|
41600
41616
|
* Given a set of options, returns the set of type directive names
|
|
41601
41617
|
* that should be included for this program automatically.
|
|
@@ -42169,11 +42185,6 @@ var ts;
|
|
|
42169
42185
|
}
|
|
42170
42186
|
ts.resolveJSModule = resolveJSModule;
|
|
42171
42187
|
/* @internal */
|
|
42172
|
-
function tryResolveJSModule(moduleName, initialDir, host) {
|
|
42173
|
-
return tryResolveJSModuleWorker(moduleName, initialDir, host).resolvedModule;
|
|
42174
|
-
}
|
|
42175
|
-
ts.tryResolveJSModule = tryResolveJSModule;
|
|
42176
|
-
/* @internal */
|
|
42177
42188
|
var NodeResolutionFeatures;
|
|
42178
42189
|
(function (NodeResolutionFeatures) {
|
|
42179
42190
|
NodeResolutionFeatures[NodeResolutionFeatures["None"] = 0] = "None";
|
|
@@ -42481,6 +42492,97 @@ var ts;
|
|
|
42481
42492
|
var versionPaths = packageInfo && packageInfo.versionPaths;
|
|
42482
42493
|
return withPackageId(packageInfo, loadNodeModuleFromDirectoryWorker(extensions, candidate, onlyRecordFailures, state, packageJsonContent, versionPaths));
|
|
42483
42494
|
}
|
|
42495
|
+
/* @internal */
|
|
42496
|
+
function getEntrypointsFromPackageJsonInfo(packageJsonInfo, options, host, cache, resolveJs) {
|
|
42497
|
+
if (!resolveJs && packageJsonInfo.resolvedEntrypoints !== undefined) {
|
|
42498
|
+
// Cached value excludes resolutions to JS files - those could be
|
|
42499
|
+
// cached separately, but they're used rarely.
|
|
42500
|
+
return packageJsonInfo.resolvedEntrypoints;
|
|
42501
|
+
}
|
|
42502
|
+
var entrypoints;
|
|
42503
|
+
var extensions = resolveJs ? Extensions.JavaScript : Extensions.TypeScript;
|
|
42504
|
+
var features = getDefaultNodeResolutionFeatures(options);
|
|
42505
|
+
var requireState = {
|
|
42506
|
+
compilerOptions: options,
|
|
42507
|
+
host: host,
|
|
42508
|
+
traceEnabled: isTraceEnabled(options, host),
|
|
42509
|
+
failedLookupLocations: [],
|
|
42510
|
+
packageJsonInfoCache: cache === null || cache === void 0 ? void 0 : cache.getPackageJsonInfoCache(),
|
|
42511
|
+
conditions: ["node", "require", "types"],
|
|
42512
|
+
features: features,
|
|
42513
|
+
};
|
|
42514
|
+
var requireResolution = loadNodeModuleFromDirectoryWorker(extensions, packageJsonInfo.packageDirectory,
|
|
42515
|
+
/*onlyRecordFailures*/ false, requireState, packageJsonInfo.packageJsonContent, packageJsonInfo.versionPaths);
|
|
42516
|
+
entrypoints = ts.append(entrypoints, requireResolution === null || requireResolution === void 0 ? void 0 : requireResolution.path);
|
|
42517
|
+
if (features & NodeResolutionFeatures.Exports && packageJsonInfo.packageJsonContent.exports) {
|
|
42518
|
+
for (var _i = 0, _a = [["node", "import", "types"], ["node", "require", "types"]]; _i < _a.length; _i++) {
|
|
42519
|
+
var conditions = _a[_i];
|
|
42520
|
+
var exportState = __assign(__assign({}, requireState), { failedLookupLocations: [], conditions: conditions });
|
|
42521
|
+
var exportResolutions = loadEntrypointsFromExportMap(packageJsonInfo, packageJsonInfo.packageJsonContent.exports, exportState, extensions);
|
|
42522
|
+
if (exportResolutions) {
|
|
42523
|
+
for (var _b = 0, exportResolutions_1 = exportResolutions; _b < exportResolutions_1.length; _b++) {
|
|
42524
|
+
var resolution = exportResolutions_1[_b];
|
|
42525
|
+
entrypoints = ts.appendIfUnique(entrypoints, resolution.path);
|
|
42526
|
+
}
|
|
42527
|
+
}
|
|
42528
|
+
}
|
|
42529
|
+
}
|
|
42530
|
+
return packageJsonInfo.resolvedEntrypoints = entrypoints || false;
|
|
42531
|
+
}
|
|
42532
|
+
ts.getEntrypointsFromPackageJsonInfo = getEntrypointsFromPackageJsonInfo;
|
|
42533
|
+
function loadEntrypointsFromExportMap(scope, exports, state, extensions) {
|
|
42534
|
+
var entrypoints;
|
|
42535
|
+
if (ts.isArray(exports)) {
|
|
42536
|
+
for (var _i = 0, exports_1 = exports; _i < exports_1.length; _i++) {
|
|
42537
|
+
var target = exports_1[_i];
|
|
42538
|
+
loadEntrypointsFromTargetExports(target);
|
|
42539
|
+
}
|
|
42540
|
+
}
|
|
42541
|
+
// eslint-disable-next-line no-null/no-null
|
|
42542
|
+
else if (typeof exports === "object" && exports !== null && allKeysStartWithDot(exports)) {
|
|
42543
|
+
for (var key in exports) {
|
|
42544
|
+
loadEntrypointsFromTargetExports(exports[key]);
|
|
42545
|
+
}
|
|
42546
|
+
}
|
|
42547
|
+
else {
|
|
42548
|
+
loadEntrypointsFromTargetExports(exports);
|
|
42549
|
+
}
|
|
42550
|
+
return entrypoints;
|
|
42551
|
+
function loadEntrypointsFromTargetExports(target) {
|
|
42552
|
+
var _a, _b;
|
|
42553
|
+
if (typeof target === "string" && ts.startsWith(target, "./") && target.indexOf("*") === -1) {
|
|
42554
|
+
var partsAfterFirst = ts.getPathComponents(target).slice(2);
|
|
42555
|
+
if (partsAfterFirst.indexOf("..") >= 0 || partsAfterFirst.indexOf(".") >= 0 || partsAfterFirst.indexOf("node_modules") >= 0) {
|
|
42556
|
+
return false;
|
|
42557
|
+
}
|
|
42558
|
+
var resolvedTarget = ts.combinePaths(scope.packageDirectory, target);
|
|
42559
|
+
var finalPath = ts.getNormalizedAbsolutePath(resolvedTarget, (_b = (_a = state.host).getCurrentDirectory) === null || _b === void 0 ? void 0 : _b.call(_a));
|
|
42560
|
+
var result = loadJSOrExactTSFileName(extensions, finalPath, /*recordOnlyFailures*/ false, state);
|
|
42561
|
+
if (result) {
|
|
42562
|
+
entrypoints = ts.appendIfUnique(entrypoints, result, function (a, b) { return a.path === b.path; });
|
|
42563
|
+
return true;
|
|
42564
|
+
}
|
|
42565
|
+
}
|
|
42566
|
+
else if (Array.isArray(target)) {
|
|
42567
|
+
for (var _i = 0, target_1 = target; _i < target_1.length; _i++) {
|
|
42568
|
+
var t = target_1[_i];
|
|
42569
|
+
var success = loadEntrypointsFromTargetExports(t);
|
|
42570
|
+
if (success) {
|
|
42571
|
+
return true;
|
|
42572
|
+
}
|
|
42573
|
+
}
|
|
42574
|
+
}
|
|
42575
|
+
// eslint-disable-next-line no-null/no-null
|
|
42576
|
+
else if (typeof target === "object" && target !== null) {
|
|
42577
|
+
return ts.forEach(ts.getOwnKeys(target), function (key) {
|
|
42578
|
+
if (key === "default" || ts.contains(state.conditions, key) || isApplicableVersionedTypesKey(state.conditions, key)) {
|
|
42579
|
+
loadEntrypointsFromTargetExports(target[key]);
|
|
42580
|
+
return true;
|
|
42581
|
+
}
|
|
42582
|
+
});
|
|
42583
|
+
}
|
|
42584
|
+
}
|
|
42585
|
+
}
|
|
42484
42586
|
/**
|
|
42485
42587
|
* A function for locating the package.json scope for a given path
|
|
42486
42588
|
*/
|
|
@@ -42537,7 +42639,7 @@ var ts;
|
|
|
42537
42639
|
trace(host, ts.Diagnostics.Found_package_json_at_0, packageJsonPath);
|
|
42538
42640
|
}
|
|
42539
42641
|
var versionPaths = readPackageJsonTypesVersionPaths(packageJsonContent, state);
|
|
42540
|
-
var result = { packageDirectory: packageDirectory, packageJsonContent: packageJsonContent, versionPaths: versionPaths };
|
|
42642
|
+
var result = { packageDirectory: packageDirectory, packageJsonContent: packageJsonContent, versionPaths: versionPaths, resolvedEntrypoints: undefined };
|
|
42541
42643
|
(_b = state.packageJsonInfoCache) === null || _b === void 0 ? void 0 : _b.setPackageJsonInfo(packageJsonPath, result);
|
|
42542
42644
|
return result;
|
|
42543
42645
|
}
|
|
@@ -42834,8 +42936,8 @@ var ts;
|
|
|
42834
42936
|
}
|
|
42835
42937
|
return toSearchResult(/*value*/ undefined);
|
|
42836
42938
|
}
|
|
42837
|
-
for (var _d = 0,
|
|
42838
|
-
var elem =
|
|
42939
|
+
for (var _d = 0, target_2 = target; _d < target_2.length; _d++) {
|
|
42940
|
+
var elem = target_2[_d];
|
|
42839
42941
|
var result = loadModuleFromTargetImportOrExport(elem, subpath, pattern);
|
|
42840
42942
|
if (result) {
|
|
42841
42943
|
return result;
|
|
@@ -49864,7 +49966,7 @@ var ts;
|
|
|
49864
49966
|
if (!sigs || !sigs.length) {
|
|
49865
49967
|
sigs = getSignaturesOfStructuredType(type, 1 /* Construct */);
|
|
49866
49968
|
}
|
|
49867
|
-
if ((sigs && sigs.length) || getPropertyOfType(type, "default" /* Default */)) {
|
|
49969
|
+
if ((sigs && sigs.length) || getPropertyOfType(type, "default" /* Default */, /*skipObjectFunctionPropertyAugment*/ true)) {
|
|
49868
49970
|
var moduleType = getTypeWithSyntheticDefaultImportType(type, symbol, moduleSymbol, reference);
|
|
49869
49971
|
return cloneTypeAsModuleType(symbol, moduleType, referenceParent);
|
|
49870
49972
|
}
|
|
@@ -52068,8 +52170,8 @@ var ts;
|
|
|
52068
52170
|
}
|
|
52069
52171
|
else {
|
|
52070
52172
|
if (parent && getExportsOfSymbol(parent)) {
|
|
52071
|
-
var
|
|
52072
|
-
ts.forEachEntry(
|
|
52173
|
+
var exports_2 = getExportsOfSymbol(parent);
|
|
52174
|
+
ts.forEachEntry(exports_2, function (ex, name) {
|
|
52073
52175
|
if (getSymbolIfSameReference(ex, symbol) && !isLateBoundName(name) && name !== "export=" /* ExportEquals */) {
|
|
52074
52176
|
symbolName = ts.unescapeLeadingUnderscores(name);
|
|
52075
52177
|
return true;
|
|
@@ -57180,6 +57282,11 @@ var ts;
|
|
|
57180
57282
|
return simplified !== type ? simplified : getConstraintOfType(type);
|
|
57181
57283
|
}
|
|
57182
57284
|
function getConstraintFromIndexedAccess(type) {
|
|
57285
|
+
if (isMappedTypeGenericIndexedAccess(type)) {
|
|
57286
|
+
// For indexed access types of the form { [P in K]: E }[X], where K is non-generic and X is generic,
|
|
57287
|
+
// we substitute an instantiation of E where P is replaced with X.
|
|
57288
|
+
return substituteIndexedMappedType(type.objectType, type.indexType);
|
|
57289
|
+
}
|
|
57183
57290
|
var indexConstraint = getSimplifiedTypeOrConstraint(type.indexType);
|
|
57184
57291
|
if (indexConstraint && indexConstraint !== type.indexType) {
|
|
57185
57292
|
var indexedAccess = getIndexedAccessTypeOrUndefined(type.objectType, indexConstraint, type.accessFlags);
|
|
@@ -57384,6 +57491,11 @@ var ts;
|
|
|
57384
57491
|
return constraint ? getStringMappingType(t.symbol, constraint) : stringType;
|
|
57385
57492
|
}
|
|
57386
57493
|
if (t.flags & 8388608 /* IndexedAccess */) {
|
|
57494
|
+
if (isMappedTypeGenericIndexedAccess(t)) {
|
|
57495
|
+
// For indexed access types of the form { [P in K]: E }[X], where K is non-generic and X is generic,
|
|
57496
|
+
// we substitute an instantiation of E where P is replaced with X.
|
|
57497
|
+
return getBaseConstraint(substituteIndexedMappedType(t.objectType, t.indexType));
|
|
57498
|
+
}
|
|
57387
57499
|
var baseObjectType = getBaseConstraint(t.objectType);
|
|
57388
57500
|
var baseIndexType = getBaseConstraint(t.indexType);
|
|
57389
57501
|
var baseIndexedAccess = baseObjectType && baseIndexType && getIndexedAccessTypeOrUndefined(baseObjectType, baseIndexType, t.accessFlags);
|
|
@@ -57468,13 +57580,7 @@ var ts;
|
|
|
57468
57580
|
* type itself.
|
|
57469
57581
|
*/
|
|
57470
57582
|
function getApparentType(type) {
|
|
57471
|
-
|
|
57472
|
-
// { [P in K]: E }[X], where K is non-generic and X is generic. For those types, we instead substitute an
|
|
57473
|
-
// instantiation of E where P is replaced with X. We do this because getBaseConstraintOfType directly
|
|
57474
|
-
// lowers to an instantiation where X's constraint is substituted for X, which isn't always desirable.
|
|
57475
|
-
var t = !(type.flags & 465829888 /* Instantiable */) ? type :
|
|
57476
|
-
isMappedTypeGenericIndexedAccess(type) ? substituteIndexedMappedType(type.objectType, type.indexType) :
|
|
57477
|
-
getBaseConstraintOfType(type) || unknownType;
|
|
57583
|
+
var t = !(type.flags & 465829888 /* Instantiable */) ? type : getBaseConstraintOfType(type) || unknownType;
|
|
57478
57584
|
return ts.getObjectFlags(t) & 32 /* Mapped */ ? getApparentTypeOfMappedType(t) :
|
|
57479
57585
|
t.flags & 2097152 /* Intersection */ ? getApparentTypeOfIntersectionType(t) :
|
|
57480
57586
|
t.flags & 402653316 /* StringLike */ ? globalStringType :
|
|
@@ -64138,6 +64244,17 @@ var ts;
|
|
|
64138
64244
|
resetErrorInfo(saveErrorInfo);
|
|
64139
64245
|
return result;
|
|
64140
64246
|
}
|
|
64247
|
+
if (isMappedTypeGenericIndexedAccess(source)) {
|
|
64248
|
+
// For an indexed access type { [P in K]: E}[X], above we have already explored an instantiation of E with X
|
|
64249
|
+
// substituted for P. We also want to explore type { [P in K]: E }[C], where C is the constraint of X.
|
|
64250
|
+
var indexConstraint = getConstraintOfType(source.indexType);
|
|
64251
|
+
if (indexConstraint) {
|
|
64252
|
+
if (result = isRelatedTo(getIndexedAccessType(source.objectType, indexConstraint), target, 1 /* Source */, reportErrors)) {
|
|
64253
|
+
resetErrorInfo(saveErrorInfo);
|
|
64254
|
+
return result;
|
|
64255
|
+
}
|
|
64256
|
+
}
|
|
64257
|
+
}
|
|
64141
64258
|
}
|
|
64142
64259
|
}
|
|
64143
64260
|
else if (source.flags & 4194304 /* Index */) {
|
|
@@ -83256,9 +83373,9 @@ var ts;
|
|
|
83256
83373
|
}
|
|
83257
83374
|
}
|
|
83258
83375
|
// Checks for export * conflicts
|
|
83259
|
-
var
|
|
83260
|
-
if (
|
|
83261
|
-
|
|
83376
|
+
var exports_3 = getExportsOfModule(moduleSymbol);
|
|
83377
|
+
if (exports_3) {
|
|
83378
|
+
exports_3.forEach(function (_a, id) {
|
|
83262
83379
|
var declarations = _a.declarations, flags = _a.flags;
|
|
83263
83380
|
if (id === "__export") {
|
|
83264
83381
|
return;
|
|
@@ -90482,6 +90599,7 @@ var ts;
|
|
|
90482
90599
|
case 176 /* TypePredicate */:
|
|
90483
90600
|
case 133 /* BooleanKeyword */:
|
|
90484
90601
|
return factory.createIdentifier("Boolean");
|
|
90602
|
+
case 197 /* TemplateLiteralType */:
|
|
90485
90603
|
case 149 /* StringKeyword */:
|
|
90486
90604
|
return factory.createIdentifier("String");
|
|
90487
90605
|
case 147 /* ObjectKeyword */:
|
|
@@ -92814,6 +92932,11 @@ var ts;
|
|
|
92814
92932
|
ts.setSourceMapRange(statement, ts.moveRangePastModifiers(property));
|
|
92815
92933
|
ts.setCommentRange(statement, property);
|
|
92816
92934
|
ts.setOriginalNode(statement, property);
|
|
92935
|
+
// `setOriginalNode` *copies* the `emitNode` from `property`, so now both
|
|
92936
|
+
// `statement` and `expression` have a copy of the synthesized comments.
|
|
92937
|
+
// Drop the comments from expression to avoid printing them twice.
|
|
92938
|
+
ts.setSyntheticLeadingComments(expression, undefined);
|
|
92939
|
+
ts.setSyntheticTrailingComments(expression, undefined);
|
|
92817
92940
|
statements.push(statement);
|
|
92818
92941
|
}
|
|
92819
92942
|
}
|
|
@@ -119154,28 +119277,37 @@ var ts;
|
|
|
119154
119277
|
useCaseSensitiveFileNames: (_a = host.useCaseSensitiveFileNames) === null || _a === void 0 ? void 0 : _a.call(host),
|
|
119155
119278
|
};
|
|
119156
119279
|
}
|
|
119157
|
-
|
|
119158
|
-
|
|
119280
|
+
// `importingSourceFile` and `importingSourceFileName`? Why not just use `importingSourceFile.path`?
|
|
119281
|
+
// Because when this is called by the file renamer, `importingSourceFile` is the file being renamed,
|
|
119282
|
+
// while `importingSourceFileName` its *new* name. We need a source file just to get its
|
|
119283
|
+
// `impliedNodeFormat` and to detect certain preferences from existing import module specifiers.
|
|
119284
|
+
function updateModuleSpecifier(compilerOptions, importingSourceFile, importingSourceFileName, toFileName, host, oldImportSpecifier) {
|
|
119285
|
+
var res = getModuleSpecifierWorker(compilerOptions, importingSourceFile, importingSourceFileName, toFileName, host, getPreferencesForUpdate(compilerOptions, oldImportSpecifier, importingSourceFileName, host), {});
|
|
119159
119286
|
if (res === oldImportSpecifier)
|
|
119160
119287
|
return undefined;
|
|
119161
119288
|
return res;
|
|
119162
119289
|
}
|
|
119163
119290
|
moduleSpecifiers_1.updateModuleSpecifier = updateModuleSpecifier;
|
|
119164
|
-
//
|
|
119291
|
+
// `importingSourceFile` and `importingSourceFileName`? Why not just use `importingSourceFile.path`?
|
|
119292
|
+
// Because when this is called by the declaration emitter, `importingSourceFile` is the implementation
|
|
119293
|
+
// file, but `importingSourceFileName` and `toFileName` refer to declaration files (the former to the
|
|
119294
|
+
// one currently being produced; the latter to the one being imported). We need an implementation file
|
|
119295
|
+
// just to get its `impliedNodeFormat` and to detect certain preferences from existing import module
|
|
119296
|
+
// specifiers.
|
|
119165
119297
|
function getModuleSpecifier(compilerOptions, importingSourceFile, importingSourceFileName, toFileName, host) {
|
|
119166
|
-
return getModuleSpecifierWorker(compilerOptions, importingSourceFileName, toFileName, host, getPreferences(host, {}, compilerOptions, importingSourceFile), {});
|
|
119298
|
+
return getModuleSpecifierWorker(compilerOptions, importingSourceFile, importingSourceFileName, toFileName, host, getPreferences(host, {}, compilerOptions, importingSourceFile), {});
|
|
119167
119299
|
}
|
|
119168
119300
|
moduleSpecifiers_1.getModuleSpecifier = getModuleSpecifier;
|
|
119169
|
-
function getNodeModulesPackageName(compilerOptions,
|
|
119170
|
-
var info = getInfo(
|
|
119171
|
-
var modulePaths = getAllModulePaths(
|
|
119172
|
-
return ts.firstDefined(modulePaths, function (modulePath) { return tryGetModuleNameAsNodeModule(modulePath, info, host, compilerOptions, /*packageNameOnly*/ true); });
|
|
119301
|
+
function getNodeModulesPackageName(compilerOptions, importingSourceFile, nodeModulesFileName, host, preferences) {
|
|
119302
|
+
var info = getInfo(importingSourceFile.path, host);
|
|
119303
|
+
var modulePaths = getAllModulePaths(importingSourceFile.path, nodeModulesFileName, host, preferences);
|
|
119304
|
+
return ts.firstDefined(modulePaths, function (modulePath) { return tryGetModuleNameAsNodeModule(modulePath, info, importingSourceFile, host, compilerOptions, /*packageNameOnly*/ true); });
|
|
119173
119305
|
}
|
|
119174
119306
|
moduleSpecifiers_1.getNodeModulesPackageName = getNodeModulesPackageName;
|
|
119175
|
-
function getModuleSpecifierWorker(compilerOptions, importingSourceFileName, toFileName, host, preferences, userPreferences) {
|
|
119307
|
+
function getModuleSpecifierWorker(compilerOptions, importingSourceFile, importingSourceFileName, toFileName, host, preferences, userPreferences) {
|
|
119176
119308
|
var info = getInfo(importingSourceFileName, host);
|
|
119177
119309
|
var modulePaths = getAllModulePaths(importingSourceFileName, toFileName, host, userPreferences);
|
|
119178
|
-
return ts.firstDefined(modulePaths, function (modulePath) { return tryGetModuleNameAsNodeModule(modulePath, info, host, compilerOptions); }) ||
|
|
119310
|
+
return ts.firstDefined(modulePaths, function (modulePath) { return tryGetModuleNameAsNodeModule(modulePath, info, importingSourceFile, host, compilerOptions); }) ||
|
|
119179
119311
|
getLocalModuleSpecifier(toFileName, info, compilerOptions, host, preferences);
|
|
119180
119312
|
}
|
|
119181
119313
|
function tryGetModuleSpecifiersFromCache(moduleSymbol, importingSourceFile, host, userPreferences) {
|
|
@@ -119242,7 +119374,7 @@ var ts;
|
|
|
119242
119374
|
var relativeSpecifiers;
|
|
119243
119375
|
for (var _i = 0, modulePaths_1 = modulePaths; _i < modulePaths_1.length; _i++) {
|
|
119244
119376
|
var modulePath = modulePaths_1[_i];
|
|
119245
|
-
var specifier = tryGetModuleNameAsNodeModule(modulePath, info, host, compilerOptions);
|
|
119377
|
+
var specifier = tryGetModuleNameAsNodeModule(modulePath, info, importingSourceFile, host, compilerOptions);
|
|
119246
119378
|
nodeModulesSpecifiers = ts.append(nodeModulesSpecifiers, specifier);
|
|
119247
119379
|
if (specifier && modulePath.isRedirect) {
|
|
119248
119380
|
// If we got a specifier for a redirect, it was a bare package specifier (e.g. "@foo/bar",
|
|
@@ -119634,7 +119766,7 @@ var ts;
|
|
|
119634
119766
|
? removeExtensionAndIndexPostFix(relativePath, ending, compilerOptions)
|
|
119635
119767
|
: ts.removeFileExtension(relativePath);
|
|
119636
119768
|
}
|
|
119637
|
-
function tryGetModuleNameAsNodeModule(_a, _b, host, options, packageNameOnly) {
|
|
119769
|
+
function tryGetModuleNameAsNodeModule(_a, _b, importingSourceFile, host, options, packageNameOnly) {
|
|
119638
119770
|
var path = _a.path, isRedirect = _a.isRedirect;
|
|
119639
119771
|
var getCanonicalFileName = _b.getCanonicalFileName, sourceDirectory = _b.sourceDirectory;
|
|
119640
119772
|
if (!host.fileExists || !host.readFile) {
|
|
@@ -119697,11 +119829,19 @@ var ts;
|
|
|
119697
119829
|
var moduleFileToTry = path;
|
|
119698
119830
|
if (host.fileExists(packageJsonPath)) {
|
|
119699
119831
|
var packageJsonContent = JSON.parse(host.readFile(packageJsonPath));
|
|
119700
|
-
// TODO: Inject `require` or `import` condition based on the intended import mode
|
|
119701
119832
|
if (ts.getEmitModuleResolutionKind(options) === ts.ModuleResolutionKind.Node12 || ts.getEmitModuleResolutionKind(options) === ts.ModuleResolutionKind.NodeNext) {
|
|
119702
|
-
|
|
119833
|
+
// `conditions` *could* be made to go against `importingSourceFile.impliedNodeFormat` if something wanted to generate
|
|
119834
|
+
// an ImportEqualsDeclaration in an ESM-implied file or an ImportCall in a CJS-implied file. But since this function is
|
|
119835
|
+
// usually called to conjure an import out of thin air, we don't have an existing usage to call `getModeForUsageAtIndex`
|
|
119836
|
+
// with, so for now we just stick with the mode of the file.
|
|
119837
|
+
var conditions = ["node", importingSourceFile.impliedNodeFormat === ts.ModuleKind.ESNext ? "import" : "require", "types"];
|
|
119838
|
+
var fromExports = packageJsonContent.exports && typeof packageJsonContent.name === "string"
|
|
119839
|
+
? tryGetModuleNameFromExports(options, path, packageRootPath, ts.getPackageNameFromTypesPackageName(packageJsonContent.name), packageJsonContent.exports, conditions)
|
|
119840
|
+
: undefined;
|
|
119703
119841
|
if (fromExports) {
|
|
119704
|
-
var withJsExtension = !ts.hasTSFileExtension(fromExports.moduleFileToTry)
|
|
119842
|
+
var withJsExtension = !ts.hasTSFileExtension(fromExports.moduleFileToTry)
|
|
119843
|
+
? fromExports
|
|
119844
|
+
: { moduleFileToTry: ts.removeFileExtension(fromExports.moduleFileToTry) + tryGetJSExtensionForFile(fromExports.moduleFileToTry, options) };
|
|
119705
119845
|
return __assign(__assign({}, withJsExtension), { verbatimFromExports: true });
|
|
119706
119846
|
}
|
|
119707
119847
|
if (packageJsonContent.exports) {
|
|
@@ -119807,8 +119947,8 @@ var ts;
|
|
|
119807
119947
|
}
|
|
119808
119948
|
function getPathRelativeToRootDirs(path, rootDirs, getCanonicalFileName) {
|
|
119809
119949
|
return ts.firstDefined(rootDirs, function (rootDir) {
|
|
119810
|
-
var relativePath = getRelativePathIfInDirectory(path, rootDir, getCanonicalFileName);
|
|
119811
|
-
return isPathRelativeToParent(relativePath) ? undefined : relativePath;
|
|
119950
|
+
var relativePath = getRelativePathIfInDirectory(path, rootDir, getCanonicalFileName);
|
|
119951
|
+
return relativePath !== undefined && isPathRelativeToParent(relativePath) ? undefined : relativePath;
|
|
119812
119952
|
});
|
|
119813
119953
|
}
|
|
119814
119954
|
function removeExtensionAndIndexPostFix(fileName, ending, options) {
|
|
@@ -126020,7 +126160,7 @@ var ts;
|
|
|
126020
126160
|
if (!ts.stringContains(importedFileName, "node_modules")) {
|
|
126021
126161
|
return undefined;
|
|
126022
126162
|
}
|
|
126023
|
-
var specifier = ts.moduleSpecifiers.getNodeModulesPackageName(host.getCompilationSettings(), fromFile
|
|
126163
|
+
var specifier = ts.moduleSpecifiers.getNodeModulesPackageName(host.getCompilationSettings(), fromFile, importedFileName, moduleSpecifierResolutionHost, preferences);
|
|
126024
126164
|
if (!specifier) {
|
|
126025
126165
|
return undefined;
|
|
126026
126166
|
}
|
|
@@ -135666,7 +135806,7 @@ var ts;
|
|
|
135666
135806
|
: getSourceFileToImport(importedModuleSymbol, importLiteral, sourceFile, program, host, oldToNew);
|
|
135667
135807
|
// Need an update if the imported file moved, or the importing file moved and was using a relative path.
|
|
135668
135808
|
return toImport !== undefined && (toImport.updated || (importingSourceFileMoved && ts.pathIsRelative(importLiteral.text)))
|
|
135669
|
-
? ts.moduleSpecifiers.updateModuleSpecifier(program.getCompilerOptions(), getCanonicalFileName(newImportFromPath), toImport.newFileName, ts.createModuleSpecifierResolutionHost(program, host), importLiteral.text)
|
|
135809
|
+
? ts.moduleSpecifiers.updateModuleSpecifier(program.getCompilerOptions(), sourceFile, getCanonicalFileName(newImportFromPath), toImport.newFileName, ts.createModuleSpecifierResolutionHost(program, host), importLiteral.text)
|
|
135670
135810
|
: undefined;
|
|
135671
135811
|
});
|
|
135672
135812
|
};
|
|
@@ -137311,6 +137451,9 @@ var ts;
|
|
|
137311
137451
|
// We use 1 NavNode to represent 'A.B.C', but there are multiple source nodes.
|
|
137312
137452
|
// Only merge module nodes that have the same chain. Don't merge 'A.B.C' with 'A'!
|
|
137313
137453
|
function areSameModule(a, b) {
|
|
137454
|
+
if (!a.body || !b.body) {
|
|
137455
|
+
return a.body === b.body;
|
|
137456
|
+
}
|
|
137314
137457
|
return a.body.kind === b.body.kind && (a.body.kind !== 260 /* ModuleDeclaration */ || areSameModule(a.body, b.body));
|
|
137315
137458
|
}
|
|
137316
137459
|
/** Merge source into target. Source should be thrown away after this is called. */
|
|
@@ -154525,7 +154668,7 @@ var ts;
|
|
|
154525
154668
|
defaultToNamedAction.kind,
|
|
154526
154669
|
namedToDefaultAction.kind
|
|
154527
154670
|
],
|
|
154528
|
-
getAvailableActions: function (context) {
|
|
154671
|
+
getAvailableActions: function getRefactorActionsToConvertBetweenNamedAndDefaultExports(context) {
|
|
154529
154672
|
var info = getInfo(context, context.triggerReason === "invoked");
|
|
154530
154673
|
if (!info)
|
|
154531
154674
|
return ts.emptyArray;
|
|
@@ -154543,7 +154686,7 @@ var ts;
|
|
|
154543
154686
|
}
|
|
154544
154687
|
return ts.emptyArray;
|
|
154545
154688
|
},
|
|
154546
|
-
getEditsForAction: function (context, actionName) {
|
|
154689
|
+
getEditsForAction: function getRefactorEditsToConvertBetweenNamedAndDefaultExports(context, actionName) {
|
|
154547
154690
|
ts.Debug.assert(actionName === defaultToNamedAction.name || actionName === namedToDefaultAction.name, "Unexpected action name");
|
|
154548
154691
|
var info = getInfo(context);
|
|
154549
154692
|
ts.Debug.assert(info && !refactor.isRefactorErrorInfo(info), "Expected applicable refactor info");
|
|
@@ -154771,7 +154914,7 @@ var ts;
|
|
|
154771
154914
|
namespaceToNamedAction.kind,
|
|
154772
154915
|
namedToNamespaceAction.kind
|
|
154773
154916
|
],
|
|
154774
|
-
getAvailableActions: function (context) {
|
|
154917
|
+
getAvailableActions: function getRefactorActionsToConvertBetweenNamedAndNamespacedImports(context) {
|
|
154775
154918
|
var info = getImportToConvert(context, context.triggerReason === "invoked");
|
|
154776
154919
|
if (!info)
|
|
154777
154920
|
return ts.emptyArray;
|
|
@@ -154790,7 +154933,7 @@ var ts;
|
|
|
154790
154933
|
}
|
|
154791
154934
|
return ts.emptyArray;
|
|
154792
154935
|
},
|
|
154793
|
-
getEditsForAction: function (context, actionName) {
|
|
154936
|
+
getEditsForAction: function getRefactorEditsToConvertBetweenNamedAndNamespacedImports(context, actionName) {
|
|
154794
154937
|
ts.Debug.assert(actionName === namespaceToNamedAction.name || actionName === namedToNamespaceAction.name, "Unexpected action name");
|
|
154795
154938
|
var info = getImportToConvert(context);
|
|
154796
154939
|
ts.Debug.assert(info && !refactor.isRefactorErrorInfo(info), "Expected applicable refactor info");
|
|
@@ -154956,10 +155099,10 @@ var ts;
|
|
|
154956
155099
|
};
|
|
154957
155100
|
refactor.registerRefactor(refactorName, {
|
|
154958
155101
|
kinds: [toOptionalChainAction.kind],
|
|
154959
|
-
|
|
154960
|
-
|
|
155102
|
+
getEditsForAction: getRefactorEditsToConvertToOptionalChain,
|
|
155103
|
+
getAvailableActions: getRefactorActionsToConvertToOptionalChain,
|
|
154961
155104
|
});
|
|
154962
|
-
function
|
|
155105
|
+
function getRefactorActionsToConvertToOptionalChain(context) {
|
|
154963
155106
|
var info = getInfo(context, context.triggerReason === "invoked");
|
|
154964
155107
|
if (!info)
|
|
154965
155108
|
return ts.emptyArray;
|
|
@@ -154979,7 +155122,7 @@ var ts;
|
|
|
154979
155122
|
}
|
|
154980
155123
|
return ts.emptyArray;
|
|
154981
155124
|
}
|
|
154982
|
-
function
|
|
155125
|
+
function getRefactorEditsToConvertToOptionalChain(context, actionName) {
|
|
154983
155126
|
var info = getInfo(context);
|
|
154984
155127
|
ts.Debug.assert(info && !refactor.isRefactorErrorInfo(info), "Expected applicable refactor info");
|
|
154985
155128
|
var edits = ts.textChanges.ChangeTracker.with(context, function (t) {
|
|
@@ -155222,10 +155365,10 @@ var ts;
|
|
|
155222
155365
|
};
|
|
155223
155366
|
refactor.registerRefactor(refactorName, {
|
|
155224
155367
|
kinds: [functionOverloadAction.kind],
|
|
155225
|
-
getEditsForAction:
|
|
155226
|
-
getAvailableActions:
|
|
155368
|
+
getEditsForAction: getRefactorEditsToConvertOverloadsToOneSignature,
|
|
155369
|
+
getAvailableActions: getRefactorActionsToConvertOverloadsToOneSignature
|
|
155227
155370
|
});
|
|
155228
|
-
function
|
|
155371
|
+
function getRefactorActionsToConvertOverloadsToOneSignature(context) {
|
|
155229
155372
|
var file = context.file, startPosition = context.startPosition, program = context.program;
|
|
155230
155373
|
var info = getConvertableOverloadListAtPosition(file, startPosition, program);
|
|
155231
155374
|
if (!info)
|
|
@@ -155236,7 +155379,7 @@ var ts;
|
|
|
155236
155379
|
actions: [functionOverloadAction]
|
|
155237
155380
|
}];
|
|
155238
155381
|
}
|
|
155239
|
-
function
|
|
155382
|
+
function getRefactorEditsToConvertOverloadsToOneSignature(context) {
|
|
155240
155383
|
var file = context.file, startPosition = context.startPosition, program = context.program;
|
|
155241
155384
|
var signatureDecls = getConvertableOverloadListAtPosition(file, startPosition, program);
|
|
155242
155385
|
if (!signatureDecls)
|
|
@@ -155392,14 +155535,14 @@ var ts;
|
|
|
155392
155535
|
extractConstantAction.kind,
|
|
155393
155536
|
extractFunctionAction.kind
|
|
155394
155537
|
],
|
|
155395
|
-
|
|
155396
|
-
|
|
155538
|
+
getEditsForAction: getRefactorEditsToExtractSymbol,
|
|
155539
|
+
getAvailableActions: getRefactorActionsToExtractSymbol,
|
|
155397
155540
|
});
|
|
155398
155541
|
/**
|
|
155399
155542
|
* Compute the associated code actions
|
|
155400
155543
|
* Exported for tests.
|
|
155401
155544
|
*/
|
|
155402
|
-
function
|
|
155545
|
+
function getRefactorActionsToExtractSymbol(context) {
|
|
155403
155546
|
var requestedRefactor = context.kind;
|
|
155404
155547
|
var rangeToExtract = getRangeToExtract(context.file, ts.getRefactorContextSpan(context), context.triggerReason === "invoked");
|
|
155405
155548
|
var targetRange = rangeToExtract.targetRange;
|
|
@@ -155528,9 +155671,9 @@ var ts;
|
|
|
155528
155671
|
return error;
|
|
155529
155672
|
}
|
|
155530
155673
|
}
|
|
155531
|
-
extractSymbol.
|
|
155674
|
+
extractSymbol.getRefactorActionsToExtractSymbol = getRefactorActionsToExtractSymbol;
|
|
155532
155675
|
/* Exported for tests */
|
|
155533
|
-
function
|
|
155676
|
+
function getRefactorEditsToExtractSymbol(context, actionName) {
|
|
155534
155677
|
var rangeToExtract = getRangeToExtract(context.file, ts.getRefactorContextSpan(context));
|
|
155535
155678
|
var targetRange = rangeToExtract.targetRange; // TODO:GH#18217
|
|
155536
155679
|
var parsedFunctionIndexMatch = /^function_scope_(\d+)$/.exec(actionName);
|
|
@@ -155547,7 +155690,7 @@ var ts;
|
|
|
155547
155690
|
}
|
|
155548
155691
|
ts.Debug.fail("Unrecognized action name");
|
|
155549
155692
|
}
|
|
155550
|
-
extractSymbol.
|
|
155693
|
+
extractSymbol.getRefactorEditsToExtractSymbol = getRefactorEditsToExtractSymbol;
|
|
155551
155694
|
// Move these into diagnostic messages if they become user-facing
|
|
155552
155695
|
var Messages;
|
|
155553
155696
|
(function (Messages) {
|
|
@@ -157098,7 +157241,7 @@ var ts;
|
|
|
157098
157241
|
extractToInterfaceAction.kind,
|
|
157099
157242
|
extractToTypeDefAction.kind
|
|
157100
157243
|
],
|
|
157101
|
-
getAvailableActions: function (context) {
|
|
157244
|
+
getAvailableActions: function getRefactorActionsToExtractType(context) {
|
|
157102
157245
|
var info = getRangeToExtract(context, context.triggerReason === "invoked");
|
|
157103
157246
|
if (!info)
|
|
157104
157247
|
return ts.emptyArray;
|
|
@@ -157123,7 +157266,7 @@ var ts;
|
|
|
157123
157266
|
}
|
|
157124
157267
|
return ts.emptyArray;
|
|
157125
157268
|
},
|
|
157126
|
-
getEditsForAction: function (context, actionName) {
|
|
157269
|
+
getEditsForAction: function getRefactorEditsToExtractType(context, actionName) {
|
|
157127
157270
|
var file = context.file;
|
|
157128
157271
|
var info = getRangeToExtract(context);
|
|
157129
157272
|
ts.Debug.assert(info && !refactor.isRefactorErrorInfo(info), "Expected to find a range to extract");
|
|
@@ -157291,7 +157434,7 @@ var ts;
|
|
|
157291
157434
|
};
|
|
157292
157435
|
refactor.registerRefactor(actionName, {
|
|
157293
157436
|
kinds: [generateGetSetAction.kind],
|
|
157294
|
-
getEditsForAction: function (context, actionName) {
|
|
157437
|
+
getEditsForAction: function getRefactorActionsToGenerateGetAndSetAccessors(context, actionName) {
|
|
157295
157438
|
if (!context.endPosition)
|
|
157296
157439
|
return undefined;
|
|
157297
157440
|
var info = ts.codefix.getAccessorConvertiblePropertyAtPosition(context.file, context.program, context.startPosition, context.endPosition);
|
|
@@ -157370,7 +157513,7 @@ var ts;
|
|
|
157370
157513
|
};
|
|
157371
157514
|
refactor.registerRefactor(refactorName, {
|
|
157372
157515
|
kinds: [moveToNewFileAction.kind],
|
|
157373
|
-
getAvailableActions: function (context) {
|
|
157516
|
+
getAvailableActions: function getRefactorActionsToMoveToNewFile(context) {
|
|
157374
157517
|
var statements = getStatementsToMove(context);
|
|
157375
157518
|
if (context.preferences.allowTextChangesInNewFiles && statements) {
|
|
157376
157519
|
return [{ name: refactorName, description: description, actions: [moveToNewFileAction] }];
|
|
@@ -157381,7 +157524,7 @@ var ts;
|
|
|
157381
157524
|
}
|
|
157382
157525
|
return ts.emptyArray;
|
|
157383
157526
|
},
|
|
157384
|
-
getEditsForAction: function (context, actionName) {
|
|
157527
|
+
getEditsForAction: function getRefactorEditsToMoveToNewFile(context, actionName) {
|
|
157385
157528
|
ts.Debug.assert(actionName === refactorName, "Wrong refactor invoked");
|
|
157386
157529
|
var statements = ts.Debug.checkDefined(getStatementsToMove(context));
|
|
157387
157530
|
var edits = ts.textChanges.ChangeTracker.with(context, function (t) { return doChange(context.file, context.program, statements, t, context.host, context.preferences); });
|
|
@@ -158112,10 +158255,10 @@ var ts;
|
|
|
158112
158255
|
};
|
|
158113
158256
|
refactor.registerRefactor(refactorName, {
|
|
158114
158257
|
kinds: [removeBracesAction.kind],
|
|
158115
|
-
getEditsForAction:
|
|
158116
|
-
getAvailableActions:
|
|
158258
|
+
getEditsForAction: getRefactorEditsToRemoveFunctionBraces,
|
|
158259
|
+
getAvailableActions: getRefactorActionsToRemoveFunctionBraces
|
|
158117
158260
|
});
|
|
158118
|
-
function
|
|
158261
|
+
function getRefactorActionsToRemoveFunctionBraces(context) {
|
|
158119
158262
|
var file = context.file, startPosition = context.startPosition, triggerReason = context.triggerReason;
|
|
158120
158263
|
var info = getConvertibleArrowFunctionAtPosition(file, startPosition, triggerReason === "invoked");
|
|
158121
158264
|
if (!info)
|
|
@@ -158141,7 +158284,7 @@ var ts;
|
|
|
158141
158284
|
}
|
|
158142
158285
|
return ts.emptyArray;
|
|
158143
158286
|
}
|
|
158144
|
-
function
|
|
158287
|
+
function getRefactorEditsToRemoveFunctionBraces(context, actionName) {
|
|
158145
158288
|
var file = context.file, startPosition = context.startPosition;
|
|
158146
158289
|
var info = getConvertibleArrowFunctionAtPosition(file, startPosition);
|
|
158147
158290
|
ts.Debug.assert(info && !refactor.isRefactorErrorInfo(info), "Expected applicable refactor info");
|
|
@@ -158215,10 +158358,10 @@ var ts;
|
|
|
158215
158358
|
};
|
|
158216
158359
|
refactor.registerRefactor(refactorName, {
|
|
158217
158360
|
kinds: [toDestructuredAction.kind],
|
|
158218
|
-
getEditsForAction:
|
|
158219
|
-
getAvailableActions:
|
|
158361
|
+
getEditsForAction: getRefactorEditsToConvertParametersToDestructuredObject,
|
|
158362
|
+
getAvailableActions: getRefactorActionsToConvertParametersToDestructuredObject
|
|
158220
158363
|
});
|
|
158221
|
-
function
|
|
158364
|
+
function getRefactorActionsToConvertParametersToDestructuredObject(context) {
|
|
158222
158365
|
var file = context.file, startPosition = context.startPosition;
|
|
158223
158366
|
var isJSFile = ts.isSourceFileJS(file);
|
|
158224
158367
|
if (isJSFile)
|
|
@@ -158232,7 +158375,7 @@ var ts;
|
|
|
158232
158375
|
actions: [toDestructuredAction]
|
|
158233
158376
|
}];
|
|
158234
158377
|
}
|
|
158235
|
-
function
|
|
158378
|
+
function getRefactorEditsToConvertParametersToDestructuredObject(context, actionName) {
|
|
158236
158379
|
ts.Debug.assert(actionName === refactorName, "Unexpected action name");
|
|
158237
158380
|
var file = context.file, startPosition = context.startPosition, program = context.program, cancellationToken = context.cancellationToken, host = context.host;
|
|
158238
158381
|
var functionDeclaration = getFunctionDeclarationAtPosition(file, startPosition, program.getTypeChecker());
|
|
@@ -158742,10 +158885,10 @@ var ts;
|
|
|
158742
158885
|
};
|
|
158743
158886
|
refactor.registerRefactor(refactorName, {
|
|
158744
158887
|
kinds: [convertStringAction.kind],
|
|
158745
|
-
getEditsForAction:
|
|
158746
|
-
getAvailableActions:
|
|
158888
|
+
getEditsForAction: getRefactorEditsToConvertToTemplateString,
|
|
158889
|
+
getAvailableActions: getRefactorActionsToConvertToTemplateString
|
|
158747
158890
|
});
|
|
158748
|
-
function
|
|
158891
|
+
function getRefactorActionsToConvertToTemplateString(context) {
|
|
158749
158892
|
var file = context.file, startPosition = context.startPosition;
|
|
158750
158893
|
var node = getNodeOrParentOfParentheses(file, startPosition);
|
|
158751
158894
|
var maybeBinary = getParentBinaryExpression(node);
|
|
@@ -158771,7 +158914,7 @@ var ts;
|
|
|
158771
158914
|
}
|
|
158772
158915
|
return node;
|
|
158773
158916
|
}
|
|
158774
|
-
function
|
|
158917
|
+
function getRefactorEditsToConvertToTemplateString(context, actionName) {
|
|
158775
158918
|
var file = context.file, startPosition = context.startPosition;
|
|
158776
158919
|
var node = getNodeOrParentOfParentheses(file, startPosition);
|
|
158777
158920
|
switch (actionName) {
|
|
@@ -158985,10 +159128,10 @@ var ts;
|
|
|
158985
159128
|
toNamedFunctionAction.kind,
|
|
158986
159129
|
toArrowFunctionAction.kind
|
|
158987
159130
|
],
|
|
158988
|
-
getEditsForAction:
|
|
158989
|
-
getAvailableActions:
|
|
159131
|
+
getEditsForAction: getRefactorEditsToConvertFunctionExpressions,
|
|
159132
|
+
getAvailableActions: getRefactorActionsToConvertFunctionExpressions
|
|
158990
159133
|
});
|
|
158991
|
-
function
|
|
159134
|
+
function getRefactorActionsToConvertFunctionExpressions(context) {
|
|
158992
159135
|
var file = context.file, startPosition = context.startPosition, program = context.program, kind = context.kind;
|
|
158993
159136
|
var info = getFunctionInfo(file, startPosition, program);
|
|
158994
159137
|
if (!info)
|
|
@@ -159032,7 +159175,7 @@ var ts;
|
|
|
159032
159175
|
errors : possibleActions
|
|
159033
159176
|
}];
|
|
159034
159177
|
}
|
|
159035
|
-
function
|
|
159178
|
+
function getRefactorEditsToConvertFunctionExpressions(context, actionName) {
|
|
159036
159179
|
var file = context.file, startPosition = context.startPosition, program = context.program;
|
|
159037
159180
|
var info = getFunctionInfo(file, startPosition, program);
|
|
159038
159181
|
if (!info)
|
|
@@ -159192,10 +159335,10 @@ var ts;
|
|
|
159192
159335
|
};
|
|
159193
159336
|
refactor.registerRefactor(refactorName, {
|
|
159194
159337
|
kinds: [inferReturnTypeAction.kind],
|
|
159195
|
-
getEditsForAction:
|
|
159196
|
-
getAvailableActions:
|
|
159338
|
+
getEditsForAction: getRefactorEditsToInferReturnType,
|
|
159339
|
+
getAvailableActions: getRefactorActionsToInferReturnType
|
|
159197
159340
|
});
|
|
159198
|
-
function
|
|
159341
|
+
function getRefactorEditsToInferReturnType(context) {
|
|
159199
159342
|
var info = getInfo(context);
|
|
159200
159343
|
if (info && !refactor.isRefactorErrorInfo(info)) {
|
|
159201
159344
|
var edits = ts.textChanges.ChangeTracker.with(context, function (t) { return doChange(context.file, t, info.declaration, info.returnTypeNode); });
|
|
@@ -159203,7 +159346,7 @@ var ts;
|
|
|
159203
159346
|
}
|
|
159204
159347
|
return undefined;
|
|
159205
159348
|
}
|
|
159206
|
-
function
|
|
159349
|
+
function getRefactorActionsToInferReturnType(context) {
|
|
159207
159350
|
var info = getInfo(context);
|
|
159208
159351
|
if (!info)
|
|
159209
159352
|
return ts.emptyArray;
|
|
@@ -166303,30 +166446,43 @@ var ts;
|
|
|
166303
166446
|
(_b = packageJson.peerDependencies) === null || _b === void 0 ? void 0 : _b.forEach(function (_, dependencyName) { return addDependency(dependencyName); });
|
|
166304
166447
|
}
|
|
166305
166448
|
if (dependencyNames) {
|
|
166306
|
-
var
|
|
166307
|
-
var types = ts.resolveTypeReferenceDirective(name, rootFileName, compilerOptions, moduleResolutionHost);
|
|
166308
|
-
if (types.resolvedTypeReferenceDirective) {
|
|
166309
|
-
return types.resolvedTypeReferenceDirective;
|
|
166310
|
-
}
|
|
166311
|
-
if (compilerOptions.allowJs && compilerOptions.maxNodeModuleJsDepth) {
|
|
166312
|
-
return ts.tryResolveJSModule(name, hostProject.currentDirectory, moduleResolutionHost);
|
|
166313
|
-
}
|
|
166314
|
-
});
|
|
166449
|
+
var dependenciesAdded = 0;
|
|
166315
166450
|
var symlinkCache = hostProject.getSymlinkCache();
|
|
166316
|
-
for (var _c = 0,
|
|
166317
|
-
var
|
|
166318
|
-
|
|
166451
|
+
for (var _c = 0, _d = ts.arrayFrom(dependencyNames.keys()); _c < _d.length; _c++) {
|
|
166452
|
+
var name = _d[_c];
|
|
166453
|
+
// Avoid creating a large project that would significantly slow down time to editor interactivity
|
|
166454
|
+
if (dependencySelection === 2 /* Auto */ && dependenciesAdded > this.maxDependencies) {
|
|
166455
|
+
hostProject.log("Auto-import provider attempted to add more than " + this.maxDependencies + " dependencies.");
|
|
166456
|
+
return ts.emptyArray;
|
|
166457
|
+
}
|
|
166458
|
+
// 1. Try to load from the implementation package. For many dependencies, the
|
|
166459
|
+
// package.json will exist, but the package will not contain any typings,
|
|
166460
|
+
// so `entrypoints` will be undefined. In that case, or if the dependency
|
|
166461
|
+
// is missing altogether, we will move on to trying the @types package (2).
|
|
166462
|
+
var packageJson = ts.resolvePackageNameToPackageJson(name, hostProject.currentDirectory, compilerOptions, moduleResolutionHost, program.getModuleResolutionCache());
|
|
166463
|
+
if (packageJson) {
|
|
166464
|
+
var entrypoints = getRootNamesFromPackageJson(packageJson, program, symlinkCache);
|
|
166465
|
+
if (entrypoints) {
|
|
166466
|
+
rootNames = ts.concatenate(rootNames, entrypoints);
|
|
166467
|
+
dependenciesAdded += entrypoints.length ? 1 : 0;
|
|
166468
|
+
continue;
|
|
166469
|
+
}
|
|
166470
|
+
}
|
|
166471
|
+
// 2. Try to load from the @types package.
|
|
166472
|
+
var typesPackageJson = ts.resolvePackageNameToPackageJson("@types/" + name, hostProject.currentDirectory, compilerOptions, moduleResolutionHost, program.getModuleResolutionCache());
|
|
166473
|
+
if (typesPackageJson) {
|
|
166474
|
+
var entrypoints = getRootNamesFromPackageJson(typesPackageJson, program, symlinkCache);
|
|
166475
|
+
rootNames = ts.concatenate(rootNames, entrypoints);
|
|
166476
|
+
dependenciesAdded += (entrypoints === null || entrypoints === void 0 ? void 0 : entrypoints.length) ? 1 : 0;
|
|
166319
166477
|
continue;
|
|
166320
|
-
var resolvedFileName = resolution.resolvedFileName, originalPath = resolution.originalPath;
|
|
166321
|
-
if (originalPath) {
|
|
166322
|
-
symlinkCache.setSymlinkedDirectoryFromSymlinkedFile(originalPath, resolvedFileName);
|
|
166323
166478
|
}
|
|
166324
|
-
|
|
166325
|
-
|
|
166326
|
-
|
|
166327
|
-
|
|
166328
|
-
|
|
166329
|
-
|
|
166479
|
+
// 3. If the @types package did not exist and the user has settings that
|
|
166480
|
+
// allow processing JS from node_modules, go back to the implementation
|
|
166481
|
+
// package and load the JS.
|
|
166482
|
+
if (packageJson && compilerOptions.allowJs && compilerOptions.maxNodeModuleJsDepth) {
|
|
166483
|
+
var entrypoints = getRootNamesFromPackageJson(packageJson, program, symlinkCache, /*allowJs*/ true);
|
|
166484
|
+
rootNames = ts.concatenate(rootNames, entrypoints);
|
|
166485
|
+
dependenciesAdded += (entrypoints === null || entrypoints === void 0 ? void 0 : entrypoints.length) ? 1 : 0;
|
|
166330
166486
|
}
|
|
166331
166487
|
}
|
|
166332
166488
|
}
|
|
@@ -166336,6 +166492,26 @@ var ts;
|
|
|
166336
166492
|
(dependencyNames || (dependencyNames = new ts.Set())).add(dependency);
|
|
166337
166493
|
}
|
|
166338
166494
|
}
|
|
166495
|
+
function getRootNamesFromPackageJson(packageJson, program, symlinkCache, resolveJs) {
|
|
166496
|
+
var _a;
|
|
166497
|
+
var entrypoints = ts.getEntrypointsFromPackageJsonInfo(packageJson, compilerOptions, moduleResolutionHost, program.getModuleResolutionCache(), resolveJs);
|
|
166498
|
+
if (entrypoints) {
|
|
166499
|
+
var real_1 = (_a = moduleResolutionHost.realpath) === null || _a === void 0 ? void 0 : _a.call(moduleResolutionHost, packageJson.packageDirectory);
|
|
166500
|
+
var isSymlink_1 = real_1 && real_1 !== packageJson.packageDirectory;
|
|
166501
|
+
if (isSymlink_1) {
|
|
166502
|
+
symlinkCache.setSymlinkedDirectory(packageJson.packageDirectory, {
|
|
166503
|
+
real: real_1,
|
|
166504
|
+
realPath: hostProject.toPath(real_1),
|
|
166505
|
+
});
|
|
166506
|
+
}
|
|
166507
|
+
return ts.mapDefined(entrypoints, function (entrypoint) {
|
|
166508
|
+
var resolvedFileName = isSymlink_1 ? entrypoint.replace(packageJson.packageDirectory, real_1) : entrypoint;
|
|
166509
|
+
if (!program.getSourceFile(resolvedFileName) && !(isSymlink_1 && program.getSourceFile(entrypoint))) {
|
|
166510
|
+
return resolvedFileName;
|
|
166511
|
+
}
|
|
166512
|
+
});
|
|
166513
|
+
}
|
|
166514
|
+
}
|
|
166339
166515
|
};
|
|
166340
166516
|
/*@internal*/
|
|
166341
166517
|
AutoImportProviderProject.create = function (dependencySelection, hostProject, moduleResolutionHost, documentRegistry) {
|