typescript 4.6.0-dev.20220108 → 4.6.0-dev.20220112
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 +156 -43
- package/lib/tsserver.js +291 -116
- package/lib/tsserverlibrary.js +291 -116
- package/lib/typescript.js +237 -95
- package/lib/typescriptServices.js +237 -95
- package/lib/typingsInstaller.js +189 -50
- package/package.json +1 -1
package/lib/tsserverlibrary.js
CHANGED
|
@@ -294,7 +294,7 @@ var ts;
|
|
|
294
294
|
// The following is baselined as a literal template type without intervention
|
|
295
295
|
/** The version of the TypeScript compiler release */
|
|
296
296
|
// eslint-disable-next-line @typescript-eslint/no-inferrable-types
|
|
297
|
-
ts.version = ts.versionMajorMinor + ".0-dev.
|
|
297
|
+
ts.version = ts.versionMajorMinor + ".0-dev.20220112";
|
|
298
298
|
/* @internal */
|
|
299
299
|
var Comparison;
|
|
300
300
|
(function (Comparison) {
|
|
@@ -19985,16 +19985,6 @@ var ts;
|
|
|
19985
19985
|
(symlinkedDirectories || (symlinkedDirectories = new ts.Map())).set(symlinkPath, real);
|
|
19986
19986
|
}
|
|
19987
19987
|
},
|
|
19988
|
-
setSymlinkedDirectoryFromSymlinkedFile: function (symlink, real) {
|
|
19989
|
-
this.setSymlinkedFile(ts.toPath(symlink, cwd, getCanonicalFileName), real);
|
|
19990
|
-
var _a = guessDirectorySymlink(real, symlink, cwd, getCanonicalFileName) || ts.emptyArray, commonResolved = _a[0], commonOriginal = _a[1];
|
|
19991
|
-
if (commonResolved && commonOriginal) {
|
|
19992
|
-
this.setSymlinkedDirectory(commonOriginal, {
|
|
19993
|
-
real: commonResolved,
|
|
19994
|
-
realPath: ts.toPath(commonResolved, cwd, getCanonicalFileName),
|
|
19995
|
-
});
|
|
19996
|
-
}
|
|
19997
|
-
},
|
|
19998
19988
|
setSymlinksFromResolutions: function (files, typeReferenceDirectives) {
|
|
19999
19989
|
var _this = this;
|
|
20000
19990
|
var _a;
|
|
@@ -41703,9 +41693,7 @@ var ts;
|
|
|
41703
41693
|
}
|
|
41704
41694
|
}
|
|
41705
41695
|
var failedLookupLocations = [];
|
|
41706
|
-
var features =
|
|
41707
|
-
ts.getEmitModuleResolutionKind(options) === ts.ModuleResolutionKind.NodeNext ? NodeResolutionFeatures.NodeNextDefault :
|
|
41708
|
-
NodeResolutionFeatures.None;
|
|
41696
|
+
var features = getDefaultNodeResolutionFeatures(options);
|
|
41709
41697
|
var moduleResolutionState = { compilerOptions: options, host: host, traceEnabled: traceEnabled, failedLookupLocations: failedLookupLocations, packageJsonInfoCache: cache, features: features, conditions: ["node", "require", "types"] };
|
|
41710
41698
|
var resolved = primaryLookup();
|
|
41711
41699
|
var primary = true;
|
|
@@ -41790,6 +41778,34 @@ var ts;
|
|
|
41790
41778
|
}
|
|
41791
41779
|
}
|
|
41792
41780
|
ts.resolveTypeReferenceDirective = resolveTypeReferenceDirective;
|
|
41781
|
+
function getDefaultNodeResolutionFeatures(options) {
|
|
41782
|
+
return ts.getEmitModuleResolutionKind(options) === ts.ModuleResolutionKind.Node12 ? NodeResolutionFeatures.Node12Default :
|
|
41783
|
+
ts.getEmitModuleResolutionKind(options) === ts.ModuleResolutionKind.NodeNext ? NodeResolutionFeatures.NodeNextDefault :
|
|
41784
|
+
NodeResolutionFeatures.None;
|
|
41785
|
+
}
|
|
41786
|
+
/**
|
|
41787
|
+
* @internal
|
|
41788
|
+
* Does not try `@types/${packageName}` - use a second pass if needed.
|
|
41789
|
+
*/
|
|
41790
|
+
function resolvePackageNameToPackageJson(packageName, containingDirectory, options, host, cache) {
|
|
41791
|
+
var moduleResolutionState = {
|
|
41792
|
+
compilerOptions: options,
|
|
41793
|
+
host: host,
|
|
41794
|
+
traceEnabled: isTraceEnabled(options, host),
|
|
41795
|
+
failedLookupLocations: [],
|
|
41796
|
+
packageJsonInfoCache: cache === null || cache === void 0 ? void 0 : cache.getPackageJsonInfoCache(),
|
|
41797
|
+
conditions: ts.emptyArray,
|
|
41798
|
+
features: NodeResolutionFeatures.None,
|
|
41799
|
+
};
|
|
41800
|
+
return ts.forEachAncestorDirectory(containingDirectory, function (ancestorDirectory) {
|
|
41801
|
+
if (ts.getBaseFileName(ancestorDirectory) !== "node_modules") {
|
|
41802
|
+
var nodeModulesFolder = ts.combinePaths(ancestorDirectory, "node_modules");
|
|
41803
|
+
var candidate = ts.combinePaths(nodeModulesFolder, packageName);
|
|
41804
|
+
return getPackageJsonInfo(candidate, /*onlyRecordFailures*/ false, moduleResolutionState);
|
|
41805
|
+
}
|
|
41806
|
+
});
|
|
41807
|
+
}
|
|
41808
|
+
ts.resolvePackageNameToPackageJson = resolvePackageNameToPackageJson;
|
|
41793
41809
|
/**
|
|
41794
41810
|
* Given a set of options, returns the set of type directive names
|
|
41795
41811
|
* that should be included for this program automatically.
|
|
@@ -42363,11 +42379,6 @@ var ts;
|
|
|
42363
42379
|
}
|
|
42364
42380
|
ts.resolveJSModule = resolveJSModule;
|
|
42365
42381
|
/* @internal */
|
|
42366
|
-
function tryResolveJSModule(moduleName, initialDir, host) {
|
|
42367
|
-
return tryResolveJSModuleWorker(moduleName, initialDir, host).resolvedModule;
|
|
42368
|
-
}
|
|
42369
|
-
ts.tryResolveJSModule = tryResolveJSModule;
|
|
42370
|
-
/* @internal */
|
|
42371
42382
|
var NodeResolutionFeatures;
|
|
42372
42383
|
(function (NodeResolutionFeatures) {
|
|
42373
42384
|
NodeResolutionFeatures[NodeResolutionFeatures["None"] = 0] = "None";
|
|
@@ -42675,6 +42686,97 @@ var ts;
|
|
|
42675
42686
|
var versionPaths = packageInfo && packageInfo.versionPaths;
|
|
42676
42687
|
return withPackageId(packageInfo, loadNodeModuleFromDirectoryWorker(extensions, candidate, onlyRecordFailures, state, packageJsonContent, versionPaths));
|
|
42677
42688
|
}
|
|
42689
|
+
/* @internal */
|
|
42690
|
+
function getEntrypointsFromPackageJsonInfo(packageJsonInfo, options, host, cache, resolveJs) {
|
|
42691
|
+
if (!resolveJs && packageJsonInfo.resolvedEntrypoints !== undefined) {
|
|
42692
|
+
// Cached value excludes resolutions to JS files - those could be
|
|
42693
|
+
// cached separately, but they're used rarely.
|
|
42694
|
+
return packageJsonInfo.resolvedEntrypoints;
|
|
42695
|
+
}
|
|
42696
|
+
var entrypoints;
|
|
42697
|
+
var extensions = resolveJs ? Extensions.JavaScript : Extensions.TypeScript;
|
|
42698
|
+
var features = getDefaultNodeResolutionFeatures(options);
|
|
42699
|
+
var requireState = {
|
|
42700
|
+
compilerOptions: options,
|
|
42701
|
+
host: host,
|
|
42702
|
+
traceEnabled: isTraceEnabled(options, host),
|
|
42703
|
+
failedLookupLocations: [],
|
|
42704
|
+
packageJsonInfoCache: cache === null || cache === void 0 ? void 0 : cache.getPackageJsonInfoCache(),
|
|
42705
|
+
conditions: ["node", "require", "types"],
|
|
42706
|
+
features: features,
|
|
42707
|
+
};
|
|
42708
|
+
var requireResolution = loadNodeModuleFromDirectoryWorker(extensions, packageJsonInfo.packageDirectory,
|
|
42709
|
+
/*onlyRecordFailures*/ false, requireState, packageJsonInfo.packageJsonContent, packageJsonInfo.versionPaths);
|
|
42710
|
+
entrypoints = ts.append(entrypoints, requireResolution === null || requireResolution === void 0 ? void 0 : requireResolution.path);
|
|
42711
|
+
if (features & NodeResolutionFeatures.Exports && packageJsonInfo.packageJsonContent.exports) {
|
|
42712
|
+
for (var _i = 0, _a = [["node", "import", "types"], ["node", "require", "types"]]; _i < _a.length; _i++) {
|
|
42713
|
+
var conditions = _a[_i];
|
|
42714
|
+
var exportState = __assign(__assign({}, requireState), { failedLookupLocations: [], conditions: conditions });
|
|
42715
|
+
var exportResolutions = loadEntrypointsFromExportMap(packageJsonInfo, packageJsonInfo.packageJsonContent.exports, exportState, extensions);
|
|
42716
|
+
if (exportResolutions) {
|
|
42717
|
+
for (var _b = 0, exportResolutions_1 = exportResolutions; _b < exportResolutions_1.length; _b++) {
|
|
42718
|
+
var resolution = exportResolutions_1[_b];
|
|
42719
|
+
entrypoints = ts.appendIfUnique(entrypoints, resolution.path);
|
|
42720
|
+
}
|
|
42721
|
+
}
|
|
42722
|
+
}
|
|
42723
|
+
}
|
|
42724
|
+
return packageJsonInfo.resolvedEntrypoints = entrypoints || false;
|
|
42725
|
+
}
|
|
42726
|
+
ts.getEntrypointsFromPackageJsonInfo = getEntrypointsFromPackageJsonInfo;
|
|
42727
|
+
function loadEntrypointsFromExportMap(scope, exports, state, extensions) {
|
|
42728
|
+
var entrypoints;
|
|
42729
|
+
if (ts.isArray(exports)) {
|
|
42730
|
+
for (var _i = 0, exports_1 = exports; _i < exports_1.length; _i++) {
|
|
42731
|
+
var target = exports_1[_i];
|
|
42732
|
+
loadEntrypointsFromTargetExports(target);
|
|
42733
|
+
}
|
|
42734
|
+
}
|
|
42735
|
+
// eslint-disable-next-line no-null/no-null
|
|
42736
|
+
else if (typeof exports === "object" && exports !== null && allKeysStartWithDot(exports)) {
|
|
42737
|
+
for (var key in exports) {
|
|
42738
|
+
loadEntrypointsFromTargetExports(exports[key]);
|
|
42739
|
+
}
|
|
42740
|
+
}
|
|
42741
|
+
else {
|
|
42742
|
+
loadEntrypointsFromTargetExports(exports);
|
|
42743
|
+
}
|
|
42744
|
+
return entrypoints;
|
|
42745
|
+
function loadEntrypointsFromTargetExports(target) {
|
|
42746
|
+
var _a, _b;
|
|
42747
|
+
if (typeof target === "string" && ts.startsWith(target, "./") && target.indexOf("*") === -1) {
|
|
42748
|
+
var partsAfterFirst = ts.getPathComponents(target).slice(2);
|
|
42749
|
+
if (partsAfterFirst.indexOf("..") >= 0 || partsAfterFirst.indexOf(".") >= 0 || partsAfterFirst.indexOf("node_modules") >= 0) {
|
|
42750
|
+
return false;
|
|
42751
|
+
}
|
|
42752
|
+
var resolvedTarget = ts.combinePaths(scope.packageDirectory, target);
|
|
42753
|
+
var finalPath = ts.getNormalizedAbsolutePath(resolvedTarget, (_b = (_a = state.host).getCurrentDirectory) === null || _b === void 0 ? void 0 : _b.call(_a));
|
|
42754
|
+
var result = loadJSOrExactTSFileName(extensions, finalPath, /*recordOnlyFailures*/ false, state);
|
|
42755
|
+
if (result) {
|
|
42756
|
+
entrypoints = ts.appendIfUnique(entrypoints, result, function (a, b) { return a.path === b.path; });
|
|
42757
|
+
return true;
|
|
42758
|
+
}
|
|
42759
|
+
}
|
|
42760
|
+
else if (Array.isArray(target)) {
|
|
42761
|
+
for (var _i = 0, target_1 = target; _i < target_1.length; _i++) {
|
|
42762
|
+
var t = target_1[_i];
|
|
42763
|
+
var success = loadEntrypointsFromTargetExports(t);
|
|
42764
|
+
if (success) {
|
|
42765
|
+
return true;
|
|
42766
|
+
}
|
|
42767
|
+
}
|
|
42768
|
+
}
|
|
42769
|
+
// eslint-disable-next-line no-null/no-null
|
|
42770
|
+
else if (typeof target === "object" && target !== null) {
|
|
42771
|
+
return ts.forEach(ts.getOwnKeys(target), function (key) {
|
|
42772
|
+
if (key === "default" || ts.contains(state.conditions, key) || isApplicableVersionedTypesKey(state.conditions, key)) {
|
|
42773
|
+
loadEntrypointsFromTargetExports(target[key]);
|
|
42774
|
+
return true;
|
|
42775
|
+
}
|
|
42776
|
+
});
|
|
42777
|
+
}
|
|
42778
|
+
}
|
|
42779
|
+
}
|
|
42678
42780
|
/**
|
|
42679
42781
|
* A function for locating the package.json scope for a given path
|
|
42680
42782
|
*/
|
|
@@ -42731,7 +42833,7 @@ var ts;
|
|
|
42731
42833
|
trace(host, ts.Diagnostics.Found_package_json_at_0, packageJsonPath);
|
|
42732
42834
|
}
|
|
42733
42835
|
var versionPaths = readPackageJsonTypesVersionPaths(packageJsonContent, state);
|
|
42734
|
-
var result = { packageDirectory: packageDirectory, packageJsonContent: packageJsonContent, versionPaths: versionPaths };
|
|
42836
|
+
var result = { packageDirectory: packageDirectory, packageJsonContent: packageJsonContent, versionPaths: versionPaths, resolvedEntrypoints: undefined };
|
|
42735
42837
|
(_b = state.packageJsonInfoCache) === null || _b === void 0 ? void 0 : _b.setPackageJsonInfo(packageJsonPath, result);
|
|
42736
42838
|
return result;
|
|
42737
42839
|
}
|
|
@@ -43028,8 +43130,8 @@ var ts;
|
|
|
43028
43130
|
}
|
|
43029
43131
|
return toSearchResult(/*value*/ undefined);
|
|
43030
43132
|
}
|
|
43031
|
-
for (var _d = 0,
|
|
43032
|
-
var elem =
|
|
43133
|
+
for (var _d = 0, target_2 = target; _d < target_2.length; _d++) {
|
|
43134
|
+
var elem = target_2[_d];
|
|
43033
43135
|
var result = loadModuleFromTargetImportOrExport(elem, subpath, pattern);
|
|
43034
43136
|
if (result) {
|
|
43035
43137
|
return result;
|
|
@@ -50058,7 +50160,7 @@ var ts;
|
|
|
50058
50160
|
if (!sigs || !sigs.length) {
|
|
50059
50161
|
sigs = getSignaturesOfStructuredType(type, 1 /* Construct */);
|
|
50060
50162
|
}
|
|
50061
|
-
if ((sigs && sigs.length) || getPropertyOfType(type, "default" /* Default */)) {
|
|
50163
|
+
if ((sigs && sigs.length) || getPropertyOfType(type, "default" /* Default */, /*skipObjectFunctionPropertyAugment*/ true)) {
|
|
50062
50164
|
var moduleType = getTypeWithSyntheticDefaultImportType(type, symbol, moduleSymbol, reference);
|
|
50063
50165
|
return cloneTypeAsModuleType(symbol, moduleType, referenceParent);
|
|
50064
50166
|
}
|
|
@@ -52262,8 +52364,8 @@ var ts;
|
|
|
52262
52364
|
}
|
|
52263
52365
|
else {
|
|
52264
52366
|
if (parent && getExportsOfSymbol(parent)) {
|
|
52265
|
-
var
|
|
52266
|
-
ts.forEachEntry(
|
|
52367
|
+
var exports_2 = getExportsOfSymbol(parent);
|
|
52368
|
+
ts.forEachEntry(exports_2, function (ex, name) {
|
|
52267
52369
|
if (getSymbolIfSameReference(ex, symbol) && !isLateBoundName(name) && name !== "export=" /* ExportEquals */) {
|
|
52268
52370
|
symbolName = ts.unescapeLeadingUnderscores(name);
|
|
52269
52371
|
return true;
|
|
@@ -57374,6 +57476,11 @@ var ts;
|
|
|
57374
57476
|
return simplified !== type ? simplified : getConstraintOfType(type);
|
|
57375
57477
|
}
|
|
57376
57478
|
function getConstraintFromIndexedAccess(type) {
|
|
57479
|
+
if (isMappedTypeGenericIndexedAccess(type)) {
|
|
57480
|
+
// For indexed access types of the form { [P in K]: E }[X], where K is non-generic and X is generic,
|
|
57481
|
+
// we substitute an instantiation of E where P is replaced with X.
|
|
57482
|
+
return substituteIndexedMappedType(type.objectType, type.indexType);
|
|
57483
|
+
}
|
|
57377
57484
|
var indexConstraint = getSimplifiedTypeOrConstraint(type.indexType);
|
|
57378
57485
|
if (indexConstraint && indexConstraint !== type.indexType) {
|
|
57379
57486
|
var indexedAccess = getIndexedAccessTypeOrUndefined(type.objectType, indexConstraint, type.accessFlags);
|
|
@@ -57578,6 +57685,11 @@ var ts;
|
|
|
57578
57685
|
return constraint ? getStringMappingType(t.symbol, constraint) : stringType;
|
|
57579
57686
|
}
|
|
57580
57687
|
if (t.flags & 8388608 /* IndexedAccess */) {
|
|
57688
|
+
if (isMappedTypeGenericIndexedAccess(t)) {
|
|
57689
|
+
// For indexed access types of the form { [P in K]: E }[X], where K is non-generic and X is generic,
|
|
57690
|
+
// we substitute an instantiation of E where P is replaced with X.
|
|
57691
|
+
return getBaseConstraint(substituteIndexedMappedType(t.objectType, t.indexType));
|
|
57692
|
+
}
|
|
57581
57693
|
var baseObjectType = getBaseConstraint(t.objectType);
|
|
57582
57694
|
var baseIndexType = getBaseConstraint(t.indexType);
|
|
57583
57695
|
var baseIndexedAccess = baseObjectType && baseIndexType && getIndexedAccessTypeOrUndefined(baseObjectType, baseIndexType, t.accessFlags);
|
|
@@ -57662,13 +57774,7 @@ var ts;
|
|
|
57662
57774
|
* type itself.
|
|
57663
57775
|
*/
|
|
57664
57776
|
function getApparentType(type) {
|
|
57665
|
-
|
|
57666
|
-
// { [P in K]: E }[X], where K is non-generic and X is generic. For those types, we instead substitute an
|
|
57667
|
-
// instantiation of E where P is replaced with X. We do this because getBaseConstraintOfType directly
|
|
57668
|
-
// lowers to an instantiation where X's constraint is substituted for X, which isn't always desirable.
|
|
57669
|
-
var t = !(type.flags & 465829888 /* Instantiable */) ? type :
|
|
57670
|
-
isMappedTypeGenericIndexedAccess(type) ? substituteIndexedMappedType(type.objectType, type.indexType) :
|
|
57671
|
-
getBaseConstraintOfType(type) || unknownType;
|
|
57777
|
+
var t = !(type.flags & 465829888 /* Instantiable */) ? type : getBaseConstraintOfType(type) || unknownType;
|
|
57672
57778
|
return ts.getObjectFlags(t) & 32 /* Mapped */ ? getApparentTypeOfMappedType(t) :
|
|
57673
57779
|
t.flags & 2097152 /* Intersection */ ? getApparentTypeOfIntersectionType(t) :
|
|
57674
57780
|
t.flags & 402653316 /* StringLike */ ? globalStringType :
|
|
@@ -64332,6 +64438,17 @@ var ts;
|
|
|
64332
64438
|
resetErrorInfo(saveErrorInfo);
|
|
64333
64439
|
return result;
|
|
64334
64440
|
}
|
|
64441
|
+
if (isMappedTypeGenericIndexedAccess(source)) {
|
|
64442
|
+
// For an indexed access type { [P in K]: E}[X], above we have already explored an instantiation of E with X
|
|
64443
|
+
// substituted for P. We also want to explore type { [P in K]: E }[C], where C is the constraint of X.
|
|
64444
|
+
var indexConstraint = getConstraintOfType(source.indexType);
|
|
64445
|
+
if (indexConstraint) {
|
|
64446
|
+
if (result = isRelatedTo(getIndexedAccessType(source.objectType, indexConstraint), target, 1 /* Source */, reportErrors)) {
|
|
64447
|
+
resetErrorInfo(saveErrorInfo);
|
|
64448
|
+
return result;
|
|
64449
|
+
}
|
|
64450
|
+
}
|
|
64451
|
+
}
|
|
64335
64452
|
}
|
|
64336
64453
|
}
|
|
64337
64454
|
else if (source.flags & 4194304 /* Index */) {
|
|
@@ -83450,9 +83567,9 @@ var ts;
|
|
|
83450
83567
|
}
|
|
83451
83568
|
}
|
|
83452
83569
|
// Checks for export * conflicts
|
|
83453
|
-
var
|
|
83454
|
-
if (
|
|
83455
|
-
|
|
83570
|
+
var exports_3 = getExportsOfModule(moduleSymbol);
|
|
83571
|
+
if (exports_3) {
|
|
83572
|
+
exports_3.forEach(function (_a, id) {
|
|
83456
83573
|
var declarations = _a.declarations, flags = _a.flags;
|
|
83457
83574
|
if (id === "__export") {
|
|
83458
83575
|
return;
|
|
@@ -93008,6 +93125,11 @@ var ts;
|
|
|
93008
93125
|
ts.setSourceMapRange(statement, ts.moveRangePastModifiers(property));
|
|
93009
93126
|
ts.setCommentRange(statement, property);
|
|
93010
93127
|
ts.setOriginalNode(statement, property);
|
|
93128
|
+
// `setOriginalNode` *copies* the `emitNode` from `property`, so now both
|
|
93129
|
+
// `statement` and `expression` have a copy of the synthesized comments.
|
|
93130
|
+
// Drop the comments from expression to avoid printing them twice.
|
|
93131
|
+
ts.setSyntheticLeadingComments(expression, undefined);
|
|
93132
|
+
ts.setSyntheticTrailingComments(expression, undefined);
|
|
93011
93133
|
statements.push(statement);
|
|
93012
93134
|
}
|
|
93013
93135
|
}
|
|
@@ -119348,28 +119470,37 @@ var ts;
|
|
|
119348
119470
|
useCaseSensitiveFileNames: (_a = host.useCaseSensitiveFileNames) === null || _a === void 0 ? void 0 : _a.call(host),
|
|
119349
119471
|
};
|
|
119350
119472
|
}
|
|
119351
|
-
|
|
119352
|
-
|
|
119473
|
+
// `importingSourceFile` and `importingSourceFileName`? Why not just use `importingSourceFile.path`?
|
|
119474
|
+
// Because when this is called by the file renamer, `importingSourceFile` is the file being renamed,
|
|
119475
|
+
// while `importingSourceFileName` its *new* name. We need a source file just to get its
|
|
119476
|
+
// `impliedNodeFormat` and to detect certain preferences from existing import module specifiers.
|
|
119477
|
+
function updateModuleSpecifier(compilerOptions, importingSourceFile, importingSourceFileName, toFileName, host, oldImportSpecifier) {
|
|
119478
|
+
var res = getModuleSpecifierWorker(compilerOptions, importingSourceFile, importingSourceFileName, toFileName, host, getPreferencesForUpdate(compilerOptions, oldImportSpecifier, importingSourceFileName, host), {});
|
|
119353
119479
|
if (res === oldImportSpecifier)
|
|
119354
119480
|
return undefined;
|
|
119355
119481
|
return res;
|
|
119356
119482
|
}
|
|
119357
119483
|
moduleSpecifiers_1.updateModuleSpecifier = updateModuleSpecifier;
|
|
119358
|
-
//
|
|
119484
|
+
// `importingSourceFile` and `importingSourceFileName`? Why not just use `importingSourceFile.path`?
|
|
119485
|
+
// Because when this is called by the declaration emitter, `importingSourceFile` is the implementation
|
|
119486
|
+
// file, but `importingSourceFileName` and `toFileName` refer to declaration files (the former to the
|
|
119487
|
+
// one currently being produced; the latter to the one being imported). We need an implementation file
|
|
119488
|
+
// just to get its `impliedNodeFormat` and to detect certain preferences from existing import module
|
|
119489
|
+
// specifiers.
|
|
119359
119490
|
function getModuleSpecifier(compilerOptions, importingSourceFile, importingSourceFileName, toFileName, host) {
|
|
119360
|
-
return getModuleSpecifierWorker(compilerOptions, importingSourceFileName, toFileName, host, getPreferences(host, {}, compilerOptions, importingSourceFile), {});
|
|
119491
|
+
return getModuleSpecifierWorker(compilerOptions, importingSourceFile, importingSourceFileName, toFileName, host, getPreferences(host, {}, compilerOptions, importingSourceFile), {});
|
|
119361
119492
|
}
|
|
119362
119493
|
moduleSpecifiers_1.getModuleSpecifier = getModuleSpecifier;
|
|
119363
|
-
function getNodeModulesPackageName(compilerOptions,
|
|
119364
|
-
var info = getInfo(
|
|
119365
|
-
var modulePaths = getAllModulePaths(
|
|
119366
|
-
return ts.firstDefined(modulePaths, function (modulePath) { return tryGetModuleNameAsNodeModule(modulePath, info, host, compilerOptions, /*packageNameOnly*/ true); });
|
|
119494
|
+
function getNodeModulesPackageName(compilerOptions, importingSourceFile, nodeModulesFileName, host, preferences) {
|
|
119495
|
+
var info = getInfo(importingSourceFile.path, host);
|
|
119496
|
+
var modulePaths = getAllModulePaths(importingSourceFile.path, nodeModulesFileName, host, preferences);
|
|
119497
|
+
return ts.firstDefined(modulePaths, function (modulePath) { return tryGetModuleNameAsNodeModule(modulePath, info, importingSourceFile, host, compilerOptions, /*packageNameOnly*/ true); });
|
|
119367
119498
|
}
|
|
119368
119499
|
moduleSpecifiers_1.getNodeModulesPackageName = getNodeModulesPackageName;
|
|
119369
|
-
function getModuleSpecifierWorker(compilerOptions, importingSourceFileName, toFileName, host, preferences, userPreferences) {
|
|
119500
|
+
function getModuleSpecifierWorker(compilerOptions, importingSourceFile, importingSourceFileName, toFileName, host, preferences, userPreferences) {
|
|
119370
119501
|
var info = getInfo(importingSourceFileName, host);
|
|
119371
119502
|
var modulePaths = getAllModulePaths(importingSourceFileName, toFileName, host, userPreferences);
|
|
119372
|
-
return ts.firstDefined(modulePaths, function (modulePath) { return tryGetModuleNameAsNodeModule(modulePath, info, host, compilerOptions); }) ||
|
|
119503
|
+
return ts.firstDefined(modulePaths, function (modulePath) { return tryGetModuleNameAsNodeModule(modulePath, info, importingSourceFile, host, compilerOptions); }) ||
|
|
119373
119504
|
getLocalModuleSpecifier(toFileName, info, compilerOptions, host, preferences);
|
|
119374
119505
|
}
|
|
119375
119506
|
function tryGetModuleSpecifiersFromCache(moduleSymbol, importingSourceFile, host, userPreferences) {
|
|
@@ -119436,7 +119567,7 @@ var ts;
|
|
|
119436
119567
|
var relativeSpecifiers;
|
|
119437
119568
|
for (var _i = 0, modulePaths_1 = modulePaths; _i < modulePaths_1.length; _i++) {
|
|
119438
119569
|
var modulePath = modulePaths_1[_i];
|
|
119439
|
-
var specifier = tryGetModuleNameAsNodeModule(modulePath, info, host, compilerOptions);
|
|
119570
|
+
var specifier = tryGetModuleNameAsNodeModule(modulePath, info, importingSourceFile, host, compilerOptions);
|
|
119440
119571
|
nodeModulesSpecifiers = ts.append(nodeModulesSpecifiers, specifier);
|
|
119441
119572
|
if (specifier && modulePath.isRedirect) {
|
|
119442
119573
|
// If we got a specifier for a redirect, it was a bare package specifier (e.g. "@foo/bar",
|
|
@@ -119828,7 +119959,7 @@ var ts;
|
|
|
119828
119959
|
? removeExtensionAndIndexPostFix(relativePath, ending, compilerOptions)
|
|
119829
119960
|
: ts.removeFileExtension(relativePath);
|
|
119830
119961
|
}
|
|
119831
|
-
function tryGetModuleNameAsNodeModule(_a, _b, host, options, packageNameOnly) {
|
|
119962
|
+
function tryGetModuleNameAsNodeModule(_a, _b, importingSourceFile, host, options, packageNameOnly) {
|
|
119832
119963
|
var path = _a.path, isRedirect = _a.isRedirect;
|
|
119833
119964
|
var getCanonicalFileName = _b.getCanonicalFileName, sourceDirectory = _b.sourceDirectory;
|
|
119834
119965
|
if (!host.fileExists || !host.readFile) {
|
|
@@ -119891,11 +120022,19 @@ var ts;
|
|
|
119891
120022
|
var moduleFileToTry = path;
|
|
119892
120023
|
if (host.fileExists(packageJsonPath)) {
|
|
119893
120024
|
var packageJsonContent = JSON.parse(host.readFile(packageJsonPath));
|
|
119894
|
-
// TODO: Inject `require` or `import` condition based on the intended import mode
|
|
119895
120025
|
if (ts.getEmitModuleResolutionKind(options) === ts.ModuleResolutionKind.Node12 || ts.getEmitModuleResolutionKind(options) === ts.ModuleResolutionKind.NodeNext) {
|
|
119896
|
-
|
|
120026
|
+
// `conditions` *could* be made to go against `importingSourceFile.impliedNodeFormat` if something wanted to generate
|
|
120027
|
+
// an ImportEqualsDeclaration in an ESM-implied file or an ImportCall in a CJS-implied file. But since this function is
|
|
120028
|
+
// usually called to conjure an import out of thin air, we don't have an existing usage to call `getModeForUsageAtIndex`
|
|
120029
|
+
// with, so for now we just stick with the mode of the file.
|
|
120030
|
+
var conditions = ["node", importingSourceFile.impliedNodeFormat === ts.ModuleKind.ESNext ? "import" : "require", "types"];
|
|
120031
|
+
var fromExports = packageJsonContent.exports && typeof packageJsonContent.name === "string"
|
|
120032
|
+
? tryGetModuleNameFromExports(options, path, packageRootPath, ts.getPackageNameFromTypesPackageName(packageJsonContent.name), packageJsonContent.exports, conditions)
|
|
120033
|
+
: undefined;
|
|
119897
120034
|
if (fromExports) {
|
|
119898
|
-
var withJsExtension = !ts.hasTSFileExtension(fromExports.moduleFileToTry)
|
|
120035
|
+
var withJsExtension = !ts.hasTSFileExtension(fromExports.moduleFileToTry)
|
|
120036
|
+
? fromExports
|
|
120037
|
+
: { moduleFileToTry: ts.removeFileExtension(fromExports.moduleFileToTry) + tryGetJSExtensionForFile(fromExports.moduleFileToTry, options) };
|
|
119899
120038
|
return __assign(__assign({}, withJsExtension), { verbatimFromExports: true });
|
|
119900
120039
|
}
|
|
119901
120040
|
if (packageJsonContent.exports) {
|
|
@@ -126631,7 +126770,7 @@ var ts;
|
|
|
126631
126770
|
if (!ts.stringContains(importedFileName, "node_modules")) {
|
|
126632
126771
|
return undefined;
|
|
126633
126772
|
}
|
|
126634
|
-
var specifier = ts.moduleSpecifiers.getNodeModulesPackageName(host.getCompilationSettings(), fromFile
|
|
126773
|
+
var specifier = ts.moduleSpecifiers.getNodeModulesPackageName(host.getCompilationSettings(), fromFile, importedFileName, moduleSpecifierResolutionHost, preferences);
|
|
126635
126774
|
if (!specifier) {
|
|
126636
126775
|
return undefined;
|
|
126637
126776
|
}
|
|
@@ -136277,7 +136416,7 @@ var ts;
|
|
|
136277
136416
|
: getSourceFileToImport(importedModuleSymbol, importLiteral, sourceFile, program, host, oldToNew);
|
|
136278
136417
|
// Need an update if the imported file moved, or the importing file moved and was using a relative path.
|
|
136279
136418
|
return toImport !== undefined && (toImport.updated || (importingSourceFileMoved && ts.pathIsRelative(importLiteral.text)))
|
|
136280
|
-
? ts.moduleSpecifiers.updateModuleSpecifier(program.getCompilerOptions(), getCanonicalFileName(newImportFromPath), toImport.newFileName, ts.createModuleSpecifierResolutionHost(program, host), importLiteral.text)
|
|
136419
|
+
? ts.moduleSpecifiers.updateModuleSpecifier(program.getCompilerOptions(), sourceFile, getCanonicalFileName(newImportFromPath), toImport.newFileName, ts.createModuleSpecifierResolutionHost(program, host), importLiteral.text)
|
|
136281
136420
|
: undefined;
|
|
136282
136421
|
});
|
|
136283
136422
|
};
|
|
@@ -137922,6 +138061,9 @@ var ts;
|
|
|
137922
138061
|
// We use 1 NavNode to represent 'A.B.C', but there are multiple source nodes.
|
|
137923
138062
|
// Only merge module nodes that have the same chain. Don't merge 'A.B.C' with 'A'!
|
|
137924
138063
|
function areSameModule(a, b) {
|
|
138064
|
+
if (!a.body || !b.body) {
|
|
138065
|
+
return a.body === b.body;
|
|
138066
|
+
}
|
|
137925
138067
|
return a.body.kind === b.body.kind && (a.body.kind !== 260 /* ModuleDeclaration */ || areSameModule(a.body, b.body));
|
|
137926
138068
|
}
|
|
137927
138069
|
/** Merge source into target. Source should be thrown away after this is called. */
|
|
@@ -155136,7 +155278,7 @@ var ts;
|
|
|
155136
155278
|
defaultToNamedAction.kind,
|
|
155137
155279
|
namedToDefaultAction.kind
|
|
155138
155280
|
],
|
|
155139
|
-
getAvailableActions: function (context) {
|
|
155281
|
+
getAvailableActions: function getRefactorActionsToConvertBetweenNamedAndDefaultExports(context) {
|
|
155140
155282
|
var info = getInfo(context, context.triggerReason === "invoked");
|
|
155141
155283
|
if (!info)
|
|
155142
155284
|
return ts.emptyArray;
|
|
@@ -155154,7 +155296,7 @@ var ts;
|
|
|
155154
155296
|
}
|
|
155155
155297
|
return ts.emptyArray;
|
|
155156
155298
|
},
|
|
155157
|
-
getEditsForAction: function (context, actionName) {
|
|
155299
|
+
getEditsForAction: function getRefactorEditsToConvertBetweenNamedAndDefaultExports(context, actionName) {
|
|
155158
155300
|
ts.Debug.assert(actionName === defaultToNamedAction.name || actionName === namedToDefaultAction.name, "Unexpected action name");
|
|
155159
155301
|
var info = getInfo(context);
|
|
155160
155302
|
ts.Debug.assert(info && !refactor.isRefactorErrorInfo(info), "Expected applicable refactor info");
|
|
@@ -155382,7 +155524,7 @@ var ts;
|
|
|
155382
155524
|
namespaceToNamedAction.kind,
|
|
155383
155525
|
namedToNamespaceAction.kind
|
|
155384
155526
|
],
|
|
155385
|
-
getAvailableActions: function (context) {
|
|
155527
|
+
getAvailableActions: function getRefactorActionsToConvertBetweenNamedAndNamespacedImports(context) {
|
|
155386
155528
|
var info = getImportToConvert(context, context.triggerReason === "invoked");
|
|
155387
155529
|
if (!info)
|
|
155388
155530
|
return ts.emptyArray;
|
|
@@ -155401,7 +155543,7 @@ var ts;
|
|
|
155401
155543
|
}
|
|
155402
155544
|
return ts.emptyArray;
|
|
155403
155545
|
},
|
|
155404
|
-
getEditsForAction: function (context, actionName) {
|
|
155546
|
+
getEditsForAction: function getRefactorEditsToConvertBetweenNamedAndNamespacedImports(context, actionName) {
|
|
155405
155547
|
ts.Debug.assert(actionName === namespaceToNamedAction.name || actionName === namedToNamespaceAction.name, "Unexpected action name");
|
|
155406
155548
|
var info = getImportToConvert(context);
|
|
155407
155549
|
ts.Debug.assert(info && !refactor.isRefactorErrorInfo(info), "Expected applicable refactor info");
|
|
@@ -155567,10 +155709,10 @@ var ts;
|
|
|
155567
155709
|
};
|
|
155568
155710
|
refactor.registerRefactor(refactorName, {
|
|
155569
155711
|
kinds: [toOptionalChainAction.kind],
|
|
155570
|
-
|
|
155571
|
-
|
|
155712
|
+
getEditsForAction: getRefactorEditsToConvertToOptionalChain,
|
|
155713
|
+
getAvailableActions: getRefactorActionsToConvertToOptionalChain,
|
|
155572
155714
|
});
|
|
155573
|
-
function
|
|
155715
|
+
function getRefactorActionsToConvertToOptionalChain(context) {
|
|
155574
155716
|
var info = getInfo(context, context.triggerReason === "invoked");
|
|
155575
155717
|
if (!info)
|
|
155576
155718
|
return ts.emptyArray;
|
|
@@ -155590,7 +155732,7 @@ var ts;
|
|
|
155590
155732
|
}
|
|
155591
155733
|
return ts.emptyArray;
|
|
155592
155734
|
}
|
|
155593
|
-
function
|
|
155735
|
+
function getRefactorEditsToConvertToOptionalChain(context, actionName) {
|
|
155594
155736
|
var info = getInfo(context);
|
|
155595
155737
|
ts.Debug.assert(info && !refactor.isRefactorErrorInfo(info), "Expected applicable refactor info");
|
|
155596
155738
|
var edits = ts.textChanges.ChangeTracker.with(context, function (t) {
|
|
@@ -155833,10 +155975,10 @@ var ts;
|
|
|
155833
155975
|
};
|
|
155834
155976
|
refactor.registerRefactor(refactorName, {
|
|
155835
155977
|
kinds: [functionOverloadAction.kind],
|
|
155836
|
-
getEditsForAction:
|
|
155837
|
-
getAvailableActions:
|
|
155978
|
+
getEditsForAction: getRefactorEditsToConvertOverloadsToOneSignature,
|
|
155979
|
+
getAvailableActions: getRefactorActionsToConvertOverloadsToOneSignature
|
|
155838
155980
|
});
|
|
155839
|
-
function
|
|
155981
|
+
function getRefactorActionsToConvertOverloadsToOneSignature(context) {
|
|
155840
155982
|
var file = context.file, startPosition = context.startPosition, program = context.program;
|
|
155841
155983
|
var info = getConvertableOverloadListAtPosition(file, startPosition, program);
|
|
155842
155984
|
if (!info)
|
|
@@ -155847,7 +155989,7 @@ var ts;
|
|
|
155847
155989
|
actions: [functionOverloadAction]
|
|
155848
155990
|
}];
|
|
155849
155991
|
}
|
|
155850
|
-
function
|
|
155992
|
+
function getRefactorEditsToConvertOverloadsToOneSignature(context) {
|
|
155851
155993
|
var file = context.file, startPosition = context.startPosition, program = context.program;
|
|
155852
155994
|
var signatureDecls = getConvertableOverloadListAtPosition(file, startPosition, program);
|
|
155853
155995
|
if (!signatureDecls)
|
|
@@ -156003,14 +156145,14 @@ var ts;
|
|
|
156003
156145
|
extractConstantAction.kind,
|
|
156004
156146
|
extractFunctionAction.kind
|
|
156005
156147
|
],
|
|
156006
|
-
|
|
156007
|
-
|
|
156148
|
+
getEditsForAction: getRefactorEditsToExtractSymbol,
|
|
156149
|
+
getAvailableActions: getRefactorActionsToExtractSymbol,
|
|
156008
156150
|
});
|
|
156009
156151
|
/**
|
|
156010
156152
|
* Compute the associated code actions
|
|
156011
156153
|
* Exported for tests.
|
|
156012
156154
|
*/
|
|
156013
|
-
function
|
|
156155
|
+
function getRefactorActionsToExtractSymbol(context) {
|
|
156014
156156
|
var requestedRefactor = context.kind;
|
|
156015
156157
|
var rangeToExtract = getRangeToExtract(context.file, ts.getRefactorContextSpan(context), context.triggerReason === "invoked");
|
|
156016
156158
|
var targetRange = rangeToExtract.targetRange;
|
|
@@ -156139,9 +156281,9 @@ var ts;
|
|
|
156139
156281
|
return error;
|
|
156140
156282
|
}
|
|
156141
156283
|
}
|
|
156142
|
-
extractSymbol.
|
|
156284
|
+
extractSymbol.getRefactorActionsToExtractSymbol = getRefactorActionsToExtractSymbol;
|
|
156143
156285
|
/* Exported for tests */
|
|
156144
|
-
function
|
|
156286
|
+
function getRefactorEditsToExtractSymbol(context, actionName) {
|
|
156145
156287
|
var rangeToExtract = getRangeToExtract(context.file, ts.getRefactorContextSpan(context));
|
|
156146
156288
|
var targetRange = rangeToExtract.targetRange; // TODO:GH#18217
|
|
156147
156289
|
var parsedFunctionIndexMatch = /^function_scope_(\d+)$/.exec(actionName);
|
|
@@ -156158,7 +156300,7 @@ var ts;
|
|
|
156158
156300
|
}
|
|
156159
156301
|
ts.Debug.fail("Unrecognized action name");
|
|
156160
156302
|
}
|
|
156161
|
-
extractSymbol.
|
|
156303
|
+
extractSymbol.getRefactorEditsToExtractSymbol = getRefactorEditsToExtractSymbol;
|
|
156162
156304
|
// Move these into diagnostic messages if they become user-facing
|
|
156163
156305
|
var Messages;
|
|
156164
156306
|
(function (Messages) {
|
|
@@ -157709,7 +157851,7 @@ var ts;
|
|
|
157709
157851
|
extractToInterfaceAction.kind,
|
|
157710
157852
|
extractToTypeDefAction.kind
|
|
157711
157853
|
],
|
|
157712
|
-
getAvailableActions: function (context) {
|
|
157854
|
+
getAvailableActions: function getRefactorActionsToExtractType(context) {
|
|
157713
157855
|
var info = getRangeToExtract(context, context.triggerReason === "invoked");
|
|
157714
157856
|
if (!info)
|
|
157715
157857
|
return ts.emptyArray;
|
|
@@ -157734,7 +157876,7 @@ var ts;
|
|
|
157734
157876
|
}
|
|
157735
157877
|
return ts.emptyArray;
|
|
157736
157878
|
},
|
|
157737
|
-
getEditsForAction: function (context, actionName) {
|
|
157879
|
+
getEditsForAction: function getRefactorEditsToExtractType(context, actionName) {
|
|
157738
157880
|
var file = context.file;
|
|
157739
157881
|
var info = getRangeToExtract(context);
|
|
157740
157882
|
ts.Debug.assert(info && !refactor.isRefactorErrorInfo(info), "Expected to find a range to extract");
|
|
@@ -157902,7 +158044,7 @@ var ts;
|
|
|
157902
158044
|
};
|
|
157903
158045
|
refactor.registerRefactor(actionName, {
|
|
157904
158046
|
kinds: [generateGetSetAction.kind],
|
|
157905
|
-
getEditsForAction: function (context, actionName) {
|
|
158047
|
+
getEditsForAction: function getRefactorActionsToGenerateGetAndSetAccessors(context, actionName) {
|
|
157906
158048
|
if (!context.endPosition)
|
|
157907
158049
|
return undefined;
|
|
157908
158050
|
var info = ts.codefix.getAccessorConvertiblePropertyAtPosition(context.file, context.program, context.startPosition, context.endPosition);
|
|
@@ -157981,7 +158123,7 @@ var ts;
|
|
|
157981
158123
|
};
|
|
157982
158124
|
refactor.registerRefactor(refactorName, {
|
|
157983
158125
|
kinds: [moveToNewFileAction.kind],
|
|
157984
|
-
getAvailableActions: function (context) {
|
|
158126
|
+
getAvailableActions: function getRefactorActionsToMoveToNewFile(context) {
|
|
157985
158127
|
var statements = getStatementsToMove(context);
|
|
157986
158128
|
if (context.preferences.allowTextChangesInNewFiles && statements) {
|
|
157987
158129
|
return [{ name: refactorName, description: description, actions: [moveToNewFileAction] }];
|
|
@@ -157992,7 +158134,7 @@ var ts;
|
|
|
157992
158134
|
}
|
|
157993
158135
|
return ts.emptyArray;
|
|
157994
158136
|
},
|
|
157995
|
-
getEditsForAction: function (context, actionName) {
|
|
158137
|
+
getEditsForAction: function getRefactorEditsToMoveToNewFile(context, actionName) {
|
|
157996
158138
|
ts.Debug.assert(actionName === refactorName, "Wrong refactor invoked");
|
|
157997
158139
|
var statements = ts.Debug.checkDefined(getStatementsToMove(context));
|
|
157998
158140
|
var edits = ts.textChanges.ChangeTracker.with(context, function (t) { return doChange(context.file, context.program, statements, t, context.host, context.preferences); });
|
|
@@ -158723,10 +158865,10 @@ var ts;
|
|
|
158723
158865
|
};
|
|
158724
158866
|
refactor.registerRefactor(refactorName, {
|
|
158725
158867
|
kinds: [removeBracesAction.kind],
|
|
158726
|
-
getEditsForAction:
|
|
158727
|
-
getAvailableActions:
|
|
158868
|
+
getEditsForAction: getRefactorEditsToRemoveFunctionBraces,
|
|
158869
|
+
getAvailableActions: getRefactorActionsToRemoveFunctionBraces
|
|
158728
158870
|
});
|
|
158729
|
-
function
|
|
158871
|
+
function getRefactorActionsToRemoveFunctionBraces(context) {
|
|
158730
158872
|
var file = context.file, startPosition = context.startPosition, triggerReason = context.triggerReason;
|
|
158731
158873
|
var info = getConvertibleArrowFunctionAtPosition(file, startPosition, triggerReason === "invoked");
|
|
158732
158874
|
if (!info)
|
|
@@ -158752,7 +158894,7 @@ var ts;
|
|
|
158752
158894
|
}
|
|
158753
158895
|
return ts.emptyArray;
|
|
158754
158896
|
}
|
|
158755
|
-
function
|
|
158897
|
+
function getRefactorEditsToRemoveFunctionBraces(context, actionName) {
|
|
158756
158898
|
var file = context.file, startPosition = context.startPosition;
|
|
158757
158899
|
var info = getConvertibleArrowFunctionAtPosition(file, startPosition);
|
|
158758
158900
|
ts.Debug.assert(info && !refactor.isRefactorErrorInfo(info), "Expected applicable refactor info");
|
|
@@ -158826,10 +158968,10 @@ var ts;
|
|
|
158826
158968
|
};
|
|
158827
158969
|
refactor.registerRefactor(refactorName, {
|
|
158828
158970
|
kinds: [toDestructuredAction.kind],
|
|
158829
|
-
getEditsForAction:
|
|
158830
|
-
getAvailableActions:
|
|
158971
|
+
getEditsForAction: getRefactorEditsToConvertParametersToDestructuredObject,
|
|
158972
|
+
getAvailableActions: getRefactorActionsToConvertParametersToDestructuredObject
|
|
158831
158973
|
});
|
|
158832
|
-
function
|
|
158974
|
+
function getRefactorActionsToConvertParametersToDestructuredObject(context) {
|
|
158833
158975
|
var file = context.file, startPosition = context.startPosition;
|
|
158834
158976
|
var isJSFile = ts.isSourceFileJS(file);
|
|
158835
158977
|
if (isJSFile)
|
|
@@ -158843,7 +158985,7 @@ var ts;
|
|
|
158843
158985
|
actions: [toDestructuredAction]
|
|
158844
158986
|
}];
|
|
158845
158987
|
}
|
|
158846
|
-
function
|
|
158988
|
+
function getRefactorEditsToConvertParametersToDestructuredObject(context, actionName) {
|
|
158847
158989
|
ts.Debug.assert(actionName === refactorName, "Unexpected action name");
|
|
158848
158990
|
var file = context.file, startPosition = context.startPosition, program = context.program, cancellationToken = context.cancellationToken, host = context.host;
|
|
158849
158991
|
var functionDeclaration = getFunctionDeclarationAtPosition(file, startPosition, program.getTypeChecker());
|
|
@@ -159353,10 +159495,10 @@ var ts;
|
|
|
159353
159495
|
};
|
|
159354
159496
|
refactor.registerRefactor(refactorName, {
|
|
159355
159497
|
kinds: [convertStringAction.kind],
|
|
159356
|
-
getEditsForAction:
|
|
159357
|
-
getAvailableActions:
|
|
159498
|
+
getEditsForAction: getRefactorEditsToConvertToTemplateString,
|
|
159499
|
+
getAvailableActions: getRefactorActionsToConvertToTemplateString
|
|
159358
159500
|
});
|
|
159359
|
-
function
|
|
159501
|
+
function getRefactorActionsToConvertToTemplateString(context) {
|
|
159360
159502
|
var file = context.file, startPosition = context.startPosition;
|
|
159361
159503
|
var node = getNodeOrParentOfParentheses(file, startPosition);
|
|
159362
159504
|
var maybeBinary = getParentBinaryExpression(node);
|
|
@@ -159382,7 +159524,7 @@ var ts;
|
|
|
159382
159524
|
}
|
|
159383
159525
|
return node;
|
|
159384
159526
|
}
|
|
159385
|
-
function
|
|
159527
|
+
function getRefactorEditsToConvertToTemplateString(context, actionName) {
|
|
159386
159528
|
var file = context.file, startPosition = context.startPosition;
|
|
159387
159529
|
var node = getNodeOrParentOfParentheses(file, startPosition);
|
|
159388
159530
|
switch (actionName) {
|
|
@@ -159596,10 +159738,10 @@ var ts;
|
|
|
159596
159738
|
toNamedFunctionAction.kind,
|
|
159597
159739
|
toArrowFunctionAction.kind
|
|
159598
159740
|
],
|
|
159599
|
-
getEditsForAction:
|
|
159600
|
-
getAvailableActions:
|
|
159741
|
+
getEditsForAction: getRefactorEditsToConvertFunctionExpressions,
|
|
159742
|
+
getAvailableActions: getRefactorActionsToConvertFunctionExpressions
|
|
159601
159743
|
});
|
|
159602
|
-
function
|
|
159744
|
+
function getRefactorActionsToConvertFunctionExpressions(context) {
|
|
159603
159745
|
var file = context.file, startPosition = context.startPosition, program = context.program, kind = context.kind;
|
|
159604
159746
|
var info = getFunctionInfo(file, startPosition, program);
|
|
159605
159747
|
if (!info)
|
|
@@ -159643,7 +159785,7 @@ var ts;
|
|
|
159643
159785
|
errors : possibleActions
|
|
159644
159786
|
}];
|
|
159645
159787
|
}
|
|
159646
|
-
function
|
|
159788
|
+
function getRefactorEditsToConvertFunctionExpressions(context, actionName) {
|
|
159647
159789
|
var file = context.file, startPosition = context.startPosition, program = context.program;
|
|
159648
159790
|
var info = getFunctionInfo(file, startPosition, program);
|
|
159649
159791
|
if (!info)
|
|
@@ -159803,10 +159945,10 @@ var ts;
|
|
|
159803
159945
|
};
|
|
159804
159946
|
refactor.registerRefactor(refactorName, {
|
|
159805
159947
|
kinds: [inferReturnTypeAction.kind],
|
|
159806
|
-
getEditsForAction:
|
|
159807
|
-
getAvailableActions:
|
|
159948
|
+
getEditsForAction: getRefactorEditsToInferReturnType,
|
|
159949
|
+
getAvailableActions: getRefactorActionsToInferReturnType
|
|
159808
159950
|
});
|
|
159809
|
-
function
|
|
159951
|
+
function getRefactorEditsToInferReturnType(context) {
|
|
159810
159952
|
var info = getInfo(context);
|
|
159811
159953
|
if (info && !refactor.isRefactorErrorInfo(info)) {
|
|
159812
159954
|
var edits = ts.textChanges.ChangeTracker.with(context, function (t) { return doChange(context.file, t, info.declaration, info.returnTypeNode); });
|
|
@@ -159814,7 +159956,7 @@ var ts;
|
|
|
159814
159956
|
}
|
|
159815
159957
|
return undefined;
|
|
159816
159958
|
}
|
|
159817
|
-
function
|
|
159959
|
+
function getRefactorActionsToInferReturnType(context) {
|
|
159818
159960
|
var info = getInfo(context);
|
|
159819
159961
|
if (!info)
|
|
159820
159962
|
return ts.emptyArray;
|
|
@@ -166497,30 +166639,43 @@ var ts;
|
|
|
166497
166639
|
(_b = packageJson.peerDependencies) === null || _b === void 0 ? void 0 : _b.forEach(function (_, dependencyName) { return addDependency(dependencyName); });
|
|
166498
166640
|
}
|
|
166499
166641
|
if (dependencyNames) {
|
|
166500
|
-
var
|
|
166501
|
-
var types = ts.resolveTypeReferenceDirective(name, rootFileName, compilerOptions, moduleResolutionHost);
|
|
166502
|
-
if (types.resolvedTypeReferenceDirective) {
|
|
166503
|
-
return types.resolvedTypeReferenceDirective;
|
|
166504
|
-
}
|
|
166505
|
-
if (compilerOptions.allowJs && compilerOptions.maxNodeModuleJsDepth) {
|
|
166506
|
-
return ts.tryResolveJSModule(name, hostProject.currentDirectory, moduleResolutionHost);
|
|
166507
|
-
}
|
|
166508
|
-
});
|
|
166642
|
+
var dependenciesAdded = 0;
|
|
166509
166643
|
var symlinkCache = hostProject.getSymlinkCache();
|
|
166510
|
-
for (var _c = 0,
|
|
166511
|
-
var
|
|
166512
|
-
|
|
166644
|
+
for (var _c = 0, _d = ts.arrayFrom(dependencyNames.keys()); _c < _d.length; _c++) {
|
|
166645
|
+
var name = _d[_c];
|
|
166646
|
+
// Avoid creating a large project that would significantly slow down time to editor interactivity
|
|
166647
|
+
if (dependencySelection === 2 /* Auto */ && dependenciesAdded > this.maxDependencies) {
|
|
166648
|
+
hostProject.log("Auto-import provider attempted to add more than " + this.maxDependencies + " dependencies.");
|
|
166649
|
+
return ts.emptyArray;
|
|
166650
|
+
}
|
|
166651
|
+
// 1. Try to load from the implementation package. For many dependencies, the
|
|
166652
|
+
// package.json will exist, but the package will not contain any typings,
|
|
166653
|
+
// so `entrypoints` will be undefined. In that case, or if the dependency
|
|
166654
|
+
// is missing altogether, we will move on to trying the @types package (2).
|
|
166655
|
+
var packageJson = ts.resolvePackageNameToPackageJson(name, hostProject.currentDirectory, compilerOptions, moduleResolutionHost, program.getModuleResolutionCache());
|
|
166656
|
+
if (packageJson) {
|
|
166657
|
+
var entrypoints = getRootNamesFromPackageJson(packageJson, program, symlinkCache);
|
|
166658
|
+
if (entrypoints) {
|
|
166659
|
+
rootNames = ts.concatenate(rootNames, entrypoints);
|
|
166660
|
+
dependenciesAdded += entrypoints.length ? 1 : 0;
|
|
166661
|
+
continue;
|
|
166662
|
+
}
|
|
166663
|
+
}
|
|
166664
|
+
// 2. Try to load from the @types package.
|
|
166665
|
+
var typesPackageJson = ts.resolvePackageNameToPackageJson("@types/" + name, hostProject.currentDirectory, compilerOptions, moduleResolutionHost, program.getModuleResolutionCache());
|
|
166666
|
+
if (typesPackageJson) {
|
|
166667
|
+
var entrypoints = getRootNamesFromPackageJson(typesPackageJson, program, symlinkCache);
|
|
166668
|
+
rootNames = ts.concatenate(rootNames, entrypoints);
|
|
166669
|
+
dependenciesAdded += (entrypoints === null || entrypoints === void 0 ? void 0 : entrypoints.length) ? 1 : 0;
|
|
166513
166670
|
continue;
|
|
166514
|
-
var resolvedFileName = resolution.resolvedFileName, originalPath = resolution.originalPath;
|
|
166515
|
-
if (originalPath) {
|
|
166516
|
-
symlinkCache.setSymlinkedDirectoryFromSymlinkedFile(originalPath, resolvedFileName);
|
|
166517
166671
|
}
|
|
166518
|
-
|
|
166519
|
-
|
|
166520
|
-
|
|
166521
|
-
|
|
166522
|
-
|
|
166523
|
-
|
|
166672
|
+
// 3. If the @types package did not exist and the user has settings that
|
|
166673
|
+
// allow processing JS from node_modules, go back to the implementation
|
|
166674
|
+
// package and load the JS.
|
|
166675
|
+
if (packageJson && compilerOptions.allowJs && compilerOptions.maxNodeModuleJsDepth) {
|
|
166676
|
+
var entrypoints = getRootNamesFromPackageJson(packageJson, program, symlinkCache, /*allowJs*/ true);
|
|
166677
|
+
rootNames = ts.concatenate(rootNames, entrypoints);
|
|
166678
|
+
dependenciesAdded += (entrypoints === null || entrypoints === void 0 ? void 0 : entrypoints.length) ? 1 : 0;
|
|
166524
166679
|
}
|
|
166525
166680
|
}
|
|
166526
166681
|
}
|
|
@@ -166530,6 +166685,26 @@ var ts;
|
|
|
166530
166685
|
(dependencyNames || (dependencyNames = new ts.Set())).add(dependency);
|
|
166531
166686
|
}
|
|
166532
166687
|
}
|
|
166688
|
+
function getRootNamesFromPackageJson(packageJson, program, symlinkCache, resolveJs) {
|
|
166689
|
+
var _a;
|
|
166690
|
+
var entrypoints = ts.getEntrypointsFromPackageJsonInfo(packageJson, compilerOptions, moduleResolutionHost, program.getModuleResolutionCache(), resolveJs);
|
|
166691
|
+
if (entrypoints) {
|
|
166692
|
+
var real_1 = (_a = moduleResolutionHost.realpath) === null || _a === void 0 ? void 0 : _a.call(moduleResolutionHost, packageJson.packageDirectory);
|
|
166693
|
+
var isSymlink_1 = real_1 && real_1 !== packageJson.packageDirectory;
|
|
166694
|
+
if (isSymlink_1) {
|
|
166695
|
+
symlinkCache.setSymlinkedDirectory(packageJson.packageDirectory, {
|
|
166696
|
+
real: real_1,
|
|
166697
|
+
realPath: hostProject.toPath(real_1),
|
|
166698
|
+
});
|
|
166699
|
+
}
|
|
166700
|
+
return ts.mapDefined(entrypoints, function (entrypoint) {
|
|
166701
|
+
var resolvedFileName = isSymlink_1 ? entrypoint.replace(packageJson.packageDirectory, real_1) : entrypoint;
|
|
166702
|
+
if (!program.getSourceFile(resolvedFileName) && !(isSymlink_1 && program.getSourceFile(entrypoint))) {
|
|
166703
|
+
return resolvedFileName;
|
|
166704
|
+
}
|
|
166705
|
+
});
|
|
166706
|
+
}
|
|
166707
|
+
}
|
|
166533
166708
|
};
|
|
166534
166709
|
/*@internal*/
|
|
166535
166710
|
AutoImportProviderProject.create = function (dependencySelection, hostProject, moduleResolutionHost, documentRegistry) {
|