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/typingsInstaller.js
CHANGED
|
@@ -89,7 +89,7 @@ var ts;
|
|
|
89
89
|
// The following is baselined as a literal template type without intervention
|
|
90
90
|
/** The version of the TypeScript compiler release */
|
|
91
91
|
// eslint-disable-next-line @typescript-eslint/no-inferrable-types
|
|
92
|
-
ts.version = ts.versionMajorMinor + ".0-dev.
|
|
92
|
+
ts.version = ts.versionMajorMinor + ".0-dev.20220112";
|
|
93
93
|
/* @internal */
|
|
94
94
|
var Comparison;
|
|
95
95
|
(function (Comparison) {
|
|
@@ -19780,16 +19780,6 @@ var ts;
|
|
|
19780
19780
|
(symlinkedDirectories || (symlinkedDirectories = new ts.Map())).set(symlinkPath, real);
|
|
19781
19781
|
}
|
|
19782
19782
|
},
|
|
19783
|
-
setSymlinkedDirectoryFromSymlinkedFile: function (symlink, real) {
|
|
19784
|
-
this.setSymlinkedFile(ts.toPath(symlink, cwd, getCanonicalFileName), real);
|
|
19785
|
-
var _a = guessDirectorySymlink(real, symlink, cwd, getCanonicalFileName) || ts.emptyArray, commonResolved = _a[0], commonOriginal = _a[1];
|
|
19786
|
-
if (commonResolved && commonOriginal) {
|
|
19787
|
-
this.setSymlinkedDirectory(commonOriginal, {
|
|
19788
|
-
real: commonResolved,
|
|
19789
|
-
realPath: ts.toPath(commonResolved, cwd, getCanonicalFileName),
|
|
19790
|
-
});
|
|
19791
|
-
}
|
|
19792
|
-
},
|
|
19793
19783
|
setSymlinksFromResolutions: function (files, typeReferenceDirectives) {
|
|
19794
19784
|
var _this = this;
|
|
19795
19785
|
var _a;
|
|
@@ -41498,9 +41488,7 @@ var ts;
|
|
|
41498
41488
|
}
|
|
41499
41489
|
}
|
|
41500
41490
|
var failedLookupLocations = [];
|
|
41501
|
-
var features =
|
|
41502
|
-
ts.getEmitModuleResolutionKind(options) === ts.ModuleResolutionKind.NodeNext ? NodeResolutionFeatures.NodeNextDefault :
|
|
41503
|
-
NodeResolutionFeatures.None;
|
|
41491
|
+
var features = getDefaultNodeResolutionFeatures(options);
|
|
41504
41492
|
var moduleResolutionState = { compilerOptions: options, host: host, traceEnabled: traceEnabled, failedLookupLocations: failedLookupLocations, packageJsonInfoCache: cache, features: features, conditions: ["node", "require", "types"] };
|
|
41505
41493
|
var resolved = primaryLookup();
|
|
41506
41494
|
var primary = true;
|
|
@@ -41585,6 +41573,34 @@ var ts;
|
|
|
41585
41573
|
}
|
|
41586
41574
|
}
|
|
41587
41575
|
ts.resolveTypeReferenceDirective = resolveTypeReferenceDirective;
|
|
41576
|
+
function getDefaultNodeResolutionFeatures(options) {
|
|
41577
|
+
return ts.getEmitModuleResolutionKind(options) === ts.ModuleResolutionKind.Node12 ? NodeResolutionFeatures.Node12Default :
|
|
41578
|
+
ts.getEmitModuleResolutionKind(options) === ts.ModuleResolutionKind.NodeNext ? NodeResolutionFeatures.NodeNextDefault :
|
|
41579
|
+
NodeResolutionFeatures.None;
|
|
41580
|
+
}
|
|
41581
|
+
/**
|
|
41582
|
+
* @internal
|
|
41583
|
+
* Does not try `@types/${packageName}` - use a second pass if needed.
|
|
41584
|
+
*/
|
|
41585
|
+
function resolvePackageNameToPackageJson(packageName, containingDirectory, options, host, cache) {
|
|
41586
|
+
var moduleResolutionState = {
|
|
41587
|
+
compilerOptions: options,
|
|
41588
|
+
host: host,
|
|
41589
|
+
traceEnabled: isTraceEnabled(options, host),
|
|
41590
|
+
failedLookupLocations: [],
|
|
41591
|
+
packageJsonInfoCache: cache === null || cache === void 0 ? void 0 : cache.getPackageJsonInfoCache(),
|
|
41592
|
+
conditions: ts.emptyArray,
|
|
41593
|
+
features: NodeResolutionFeatures.None,
|
|
41594
|
+
};
|
|
41595
|
+
return ts.forEachAncestorDirectory(containingDirectory, function (ancestorDirectory) {
|
|
41596
|
+
if (ts.getBaseFileName(ancestorDirectory) !== "node_modules") {
|
|
41597
|
+
var nodeModulesFolder = ts.combinePaths(ancestorDirectory, "node_modules");
|
|
41598
|
+
var candidate = ts.combinePaths(nodeModulesFolder, packageName);
|
|
41599
|
+
return getPackageJsonInfo(candidate, /*onlyRecordFailures*/ false, moduleResolutionState);
|
|
41600
|
+
}
|
|
41601
|
+
});
|
|
41602
|
+
}
|
|
41603
|
+
ts.resolvePackageNameToPackageJson = resolvePackageNameToPackageJson;
|
|
41588
41604
|
/**
|
|
41589
41605
|
* Given a set of options, returns the set of type directive names
|
|
41590
41606
|
* that should be included for this program automatically.
|
|
@@ -42158,11 +42174,6 @@ var ts;
|
|
|
42158
42174
|
}
|
|
42159
42175
|
ts.resolveJSModule = resolveJSModule;
|
|
42160
42176
|
/* @internal */
|
|
42161
|
-
function tryResolveJSModule(moduleName, initialDir, host) {
|
|
42162
|
-
return tryResolveJSModuleWorker(moduleName, initialDir, host).resolvedModule;
|
|
42163
|
-
}
|
|
42164
|
-
ts.tryResolveJSModule = tryResolveJSModule;
|
|
42165
|
-
/* @internal */
|
|
42166
42177
|
var NodeResolutionFeatures;
|
|
42167
42178
|
(function (NodeResolutionFeatures) {
|
|
42168
42179
|
NodeResolutionFeatures[NodeResolutionFeatures["None"] = 0] = "None";
|
|
@@ -42470,6 +42481,97 @@ var ts;
|
|
|
42470
42481
|
var versionPaths = packageInfo && packageInfo.versionPaths;
|
|
42471
42482
|
return withPackageId(packageInfo, loadNodeModuleFromDirectoryWorker(extensions, candidate, onlyRecordFailures, state, packageJsonContent, versionPaths));
|
|
42472
42483
|
}
|
|
42484
|
+
/* @internal */
|
|
42485
|
+
function getEntrypointsFromPackageJsonInfo(packageJsonInfo, options, host, cache, resolveJs) {
|
|
42486
|
+
if (!resolveJs && packageJsonInfo.resolvedEntrypoints !== undefined) {
|
|
42487
|
+
// Cached value excludes resolutions to JS files - those could be
|
|
42488
|
+
// cached separately, but they're used rarely.
|
|
42489
|
+
return packageJsonInfo.resolvedEntrypoints;
|
|
42490
|
+
}
|
|
42491
|
+
var entrypoints;
|
|
42492
|
+
var extensions = resolveJs ? Extensions.JavaScript : Extensions.TypeScript;
|
|
42493
|
+
var features = getDefaultNodeResolutionFeatures(options);
|
|
42494
|
+
var requireState = {
|
|
42495
|
+
compilerOptions: options,
|
|
42496
|
+
host: host,
|
|
42497
|
+
traceEnabled: isTraceEnabled(options, host),
|
|
42498
|
+
failedLookupLocations: [],
|
|
42499
|
+
packageJsonInfoCache: cache === null || cache === void 0 ? void 0 : cache.getPackageJsonInfoCache(),
|
|
42500
|
+
conditions: ["node", "require", "types"],
|
|
42501
|
+
features: features,
|
|
42502
|
+
};
|
|
42503
|
+
var requireResolution = loadNodeModuleFromDirectoryWorker(extensions, packageJsonInfo.packageDirectory,
|
|
42504
|
+
/*onlyRecordFailures*/ false, requireState, packageJsonInfo.packageJsonContent, packageJsonInfo.versionPaths);
|
|
42505
|
+
entrypoints = ts.append(entrypoints, requireResolution === null || requireResolution === void 0 ? void 0 : requireResolution.path);
|
|
42506
|
+
if (features & NodeResolutionFeatures.Exports && packageJsonInfo.packageJsonContent.exports) {
|
|
42507
|
+
for (var _i = 0, _a = [["node", "import", "types"], ["node", "require", "types"]]; _i < _a.length; _i++) {
|
|
42508
|
+
var conditions = _a[_i];
|
|
42509
|
+
var exportState = __assign(__assign({}, requireState), { failedLookupLocations: [], conditions: conditions });
|
|
42510
|
+
var exportResolutions = loadEntrypointsFromExportMap(packageJsonInfo, packageJsonInfo.packageJsonContent.exports, exportState, extensions);
|
|
42511
|
+
if (exportResolutions) {
|
|
42512
|
+
for (var _b = 0, exportResolutions_1 = exportResolutions; _b < exportResolutions_1.length; _b++) {
|
|
42513
|
+
var resolution = exportResolutions_1[_b];
|
|
42514
|
+
entrypoints = ts.appendIfUnique(entrypoints, resolution.path);
|
|
42515
|
+
}
|
|
42516
|
+
}
|
|
42517
|
+
}
|
|
42518
|
+
}
|
|
42519
|
+
return packageJsonInfo.resolvedEntrypoints = entrypoints || false;
|
|
42520
|
+
}
|
|
42521
|
+
ts.getEntrypointsFromPackageJsonInfo = getEntrypointsFromPackageJsonInfo;
|
|
42522
|
+
function loadEntrypointsFromExportMap(scope, exports, state, extensions) {
|
|
42523
|
+
var entrypoints;
|
|
42524
|
+
if (ts.isArray(exports)) {
|
|
42525
|
+
for (var _i = 0, exports_1 = exports; _i < exports_1.length; _i++) {
|
|
42526
|
+
var target = exports_1[_i];
|
|
42527
|
+
loadEntrypointsFromTargetExports(target);
|
|
42528
|
+
}
|
|
42529
|
+
}
|
|
42530
|
+
// eslint-disable-next-line no-null/no-null
|
|
42531
|
+
else if (typeof exports === "object" && exports !== null && allKeysStartWithDot(exports)) {
|
|
42532
|
+
for (var key in exports) {
|
|
42533
|
+
loadEntrypointsFromTargetExports(exports[key]);
|
|
42534
|
+
}
|
|
42535
|
+
}
|
|
42536
|
+
else {
|
|
42537
|
+
loadEntrypointsFromTargetExports(exports);
|
|
42538
|
+
}
|
|
42539
|
+
return entrypoints;
|
|
42540
|
+
function loadEntrypointsFromTargetExports(target) {
|
|
42541
|
+
var _a, _b;
|
|
42542
|
+
if (typeof target === "string" && ts.startsWith(target, "./") && target.indexOf("*") === -1) {
|
|
42543
|
+
var partsAfterFirst = ts.getPathComponents(target).slice(2);
|
|
42544
|
+
if (partsAfterFirst.indexOf("..") >= 0 || partsAfterFirst.indexOf(".") >= 0 || partsAfterFirst.indexOf("node_modules") >= 0) {
|
|
42545
|
+
return false;
|
|
42546
|
+
}
|
|
42547
|
+
var resolvedTarget = ts.combinePaths(scope.packageDirectory, target);
|
|
42548
|
+
var finalPath = ts.getNormalizedAbsolutePath(resolvedTarget, (_b = (_a = state.host).getCurrentDirectory) === null || _b === void 0 ? void 0 : _b.call(_a));
|
|
42549
|
+
var result = loadJSOrExactTSFileName(extensions, finalPath, /*recordOnlyFailures*/ false, state);
|
|
42550
|
+
if (result) {
|
|
42551
|
+
entrypoints = ts.appendIfUnique(entrypoints, result, function (a, b) { return a.path === b.path; });
|
|
42552
|
+
return true;
|
|
42553
|
+
}
|
|
42554
|
+
}
|
|
42555
|
+
else if (Array.isArray(target)) {
|
|
42556
|
+
for (var _i = 0, target_1 = target; _i < target_1.length; _i++) {
|
|
42557
|
+
var t = target_1[_i];
|
|
42558
|
+
var success = loadEntrypointsFromTargetExports(t);
|
|
42559
|
+
if (success) {
|
|
42560
|
+
return true;
|
|
42561
|
+
}
|
|
42562
|
+
}
|
|
42563
|
+
}
|
|
42564
|
+
// eslint-disable-next-line no-null/no-null
|
|
42565
|
+
else if (typeof target === "object" && target !== null) {
|
|
42566
|
+
return ts.forEach(ts.getOwnKeys(target), function (key) {
|
|
42567
|
+
if (key === "default" || ts.contains(state.conditions, key) || isApplicableVersionedTypesKey(state.conditions, key)) {
|
|
42568
|
+
loadEntrypointsFromTargetExports(target[key]);
|
|
42569
|
+
return true;
|
|
42570
|
+
}
|
|
42571
|
+
});
|
|
42572
|
+
}
|
|
42573
|
+
}
|
|
42574
|
+
}
|
|
42473
42575
|
/**
|
|
42474
42576
|
* A function for locating the package.json scope for a given path
|
|
42475
42577
|
*/
|
|
@@ -42526,7 +42628,7 @@ var ts;
|
|
|
42526
42628
|
trace(host, ts.Diagnostics.Found_package_json_at_0, packageJsonPath);
|
|
42527
42629
|
}
|
|
42528
42630
|
var versionPaths = readPackageJsonTypesVersionPaths(packageJsonContent, state);
|
|
42529
|
-
var result = { packageDirectory: packageDirectory, packageJsonContent: packageJsonContent, versionPaths: versionPaths };
|
|
42631
|
+
var result = { packageDirectory: packageDirectory, packageJsonContent: packageJsonContent, versionPaths: versionPaths, resolvedEntrypoints: undefined };
|
|
42530
42632
|
(_b = state.packageJsonInfoCache) === null || _b === void 0 ? void 0 : _b.setPackageJsonInfo(packageJsonPath, result);
|
|
42531
42633
|
return result;
|
|
42532
42634
|
}
|
|
@@ -42823,8 +42925,8 @@ var ts;
|
|
|
42823
42925
|
}
|
|
42824
42926
|
return toSearchResult(/*value*/ undefined);
|
|
42825
42927
|
}
|
|
42826
|
-
for (var _d = 0,
|
|
42827
|
-
var elem =
|
|
42928
|
+
for (var _d = 0, target_2 = target; _d < target_2.length; _d++) {
|
|
42929
|
+
var elem = target_2[_d];
|
|
42828
42930
|
var result = loadModuleFromTargetImportOrExport(elem, subpath, pattern);
|
|
42829
42931
|
if (result) {
|
|
42830
42932
|
return result;
|
|
@@ -49853,7 +49955,7 @@ var ts;
|
|
|
49853
49955
|
if (!sigs || !sigs.length) {
|
|
49854
49956
|
sigs = getSignaturesOfStructuredType(type, 1 /* Construct */);
|
|
49855
49957
|
}
|
|
49856
|
-
if ((sigs && sigs.length) || getPropertyOfType(type, "default" /* Default */)) {
|
|
49958
|
+
if ((sigs && sigs.length) || getPropertyOfType(type, "default" /* Default */, /*skipObjectFunctionPropertyAugment*/ true)) {
|
|
49857
49959
|
var moduleType = getTypeWithSyntheticDefaultImportType(type, symbol, moduleSymbol, reference);
|
|
49858
49960
|
return cloneTypeAsModuleType(symbol, moduleType, referenceParent);
|
|
49859
49961
|
}
|
|
@@ -52057,8 +52159,8 @@ var ts;
|
|
|
52057
52159
|
}
|
|
52058
52160
|
else {
|
|
52059
52161
|
if (parent && getExportsOfSymbol(parent)) {
|
|
52060
|
-
var
|
|
52061
|
-
ts.forEachEntry(
|
|
52162
|
+
var exports_2 = getExportsOfSymbol(parent);
|
|
52163
|
+
ts.forEachEntry(exports_2, function (ex, name) {
|
|
52062
52164
|
if (getSymbolIfSameReference(ex, symbol) && !isLateBoundName(name) && name !== "export=" /* ExportEquals */) {
|
|
52063
52165
|
symbolName = ts.unescapeLeadingUnderscores(name);
|
|
52064
52166
|
return true;
|
|
@@ -57169,6 +57271,11 @@ var ts;
|
|
|
57169
57271
|
return simplified !== type ? simplified : getConstraintOfType(type);
|
|
57170
57272
|
}
|
|
57171
57273
|
function getConstraintFromIndexedAccess(type) {
|
|
57274
|
+
if (isMappedTypeGenericIndexedAccess(type)) {
|
|
57275
|
+
// For indexed access types of the form { [P in K]: E }[X], where K is non-generic and X is generic,
|
|
57276
|
+
// we substitute an instantiation of E where P is replaced with X.
|
|
57277
|
+
return substituteIndexedMappedType(type.objectType, type.indexType);
|
|
57278
|
+
}
|
|
57172
57279
|
var indexConstraint = getSimplifiedTypeOrConstraint(type.indexType);
|
|
57173
57280
|
if (indexConstraint && indexConstraint !== type.indexType) {
|
|
57174
57281
|
var indexedAccess = getIndexedAccessTypeOrUndefined(type.objectType, indexConstraint, type.accessFlags);
|
|
@@ -57373,6 +57480,11 @@ var ts;
|
|
|
57373
57480
|
return constraint ? getStringMappingType(t.symbol, constraint) : stringType;
|
|
57374
57481
|
}
|
|
57375
57482
|
if (t.flags & 8388608 /* IndexedAccess */) {
|
|
57483
|
+
if (isMappedTypeGenericIndexedAccess(t)) {
|
|
57484
|
+
// For indexed access types of the form { [P in K]: E }[X], where K is non-generic and X is generic,
|
|
57485
|
+
// we substitute an instantiation of E where P is replaced with X.
|
|
57486
|
+
return getBaseConstraint(substituteIndexedMappedType(t.objectType, t.indexType));
|
|
57487
|
+
}
|
|
57376
57488
|
var baseObjectType = getBaseConstraint(t.objectType);
|
|
57377
57489
|
var baseIndexType = getBaseConstraint(t.indexType);
|
|
57378
57490
|
var baseIndexedAccess = baseObjectType && baseIndexType && getIndexedAccessTypeOrUndefined(baseObjectType, baseIndexType, t.accessFlags);
|
|
@@ -57457,13 +57569,7 @@ var ts;
|
|
|
57457
57569
|
* type itself.
|
|
57458
57570
|
*/
|
|
57459
57571
|
function getApparentType(type) {
|
|
57460
|
-
|
|
57461
|
-
// { [P in K]: E }[X], where K is non-generic and X is generic. For those types, we instead substitute an
|
|
57462
|
-
// instantiation of E where P is replaced with X. We do this because getBaseConstraintOfType directly
|
|
57463
|
-
// lowers to an instantiation where X's constraint is substituted for X, which isn't always desirable.
|
|
57464
|
-
var t = !(type.flags & 465829888 /* Instantiable */) ? type :
|
|
57465
|
-
isMappedTypeGenericIndexedAccess(type) ? substituteIndexedMappedType(type.objectType, type.indexType) :
|
|
57466
|
-
getBaseConstraintOfType(type) || unknownType;
|
|
57572
|
+
var t = !(type.flags & 465829888 /* Instantiable */) ? type : getBaseConstraintOfType(type) || unknownType;
|
|
57467
57573
|
return ts.getObjectFlags(t) & 32 /* Mapped */ ? getApparentTypeOfMappedType(t) :
|
|
57468
57574
|
t.flags & 2097152 /* Intersection */ ? getApparentTypeOfIntersectionType(t) :
|
|
57469
57575
|
t.flags & 402653316 /* StringLike */ ? globalStringType :
|
|
@@ -64127,6 +64233,17 @@ var ts;
|
|
|
64127
64233
|
resetErrorInfo(saveErrorInfo);
|
|
64128
64234
|
return result;
|
|
64129
64235
|
}
|
|
64236
|
+
if (isMappedTypeGenericIndexedAccess(source)) {
|
|
64237
|
+
// For an indexed access type { [P in K]: E}[X], above we have already explored an instantiation of E with X
|
|
64238
|
+
// substituted for P. We also want to explore type { [P in K]: E }[C], where C is the constraint of X.
|
|
64239
|
+
var indexConstraint = getConstraintOfType(source.indexType);
|
|
64240
|
+
if (indexConstraint) {
|
|
64241
|
+
if (result = isRelatedTo(getIndexedAccessType(source.objectType, indexConstraint), target, 1 /* Source */, reportErrors)) {
|
|
64242
|
+
resetErrorInfo(saveErrorInfo);
|
|
64243
|
+
return result;
|
|
64244
|
+
}
|
|
64245
|
+
}
|
|
64246
|
+
}
|
|
64130
64247
|
}
|
|
64131
64248
|
}
|
|
64132
64249
|
else if (source.flags & 4194304 /* Index */) {
|
|
@@ -83245,9 +83362,9 @@ var ts;
|
|
|
83245
83362
|
}
|
|
83246
83363
|
}
|
|
83247
83364
|
// Checks for export * conflicts
|
|
83248
|
-
var
|
|
83249
|
-
if (
|
|
83250
|
-
|
|
83365
|
+
var exports_3 = getExportsOfModule(moduleSymbol);
|
|
83366
|
+
if (exports_3) {
|
|
83367
|
+
exports_3.forEach(function (_a, id) {
|
|
83251
83368
|
var declarations = _a.declarations, flags = _a.flags;
|
|
83252
83369
|
if (id === "__export") {
|
|
83253
83370
|
return;
|
|
@@ -92803,6 +92920,11 @@ var ts;
|
|
|
92803
92920
|
ts.setSourceMapRange(statement, ts.moveRangePastModifiers(property));
|
|
92804
92921
|
ts.setCommentRange(statement, property);
|
|
92805
92922
|
ts.setOriginalNode(statement, property);
|
|
92923
|
+
// `setOriginalNode` *copies* the `emitNode` from `property`, so now both
|
|
92924
|
+
// `statement` and `expression` have a copy of the synthesized comments.
|
|
92925
|
+
// Drop the comments from expression to avoid printing them twice.
|
|
92926
|
+
ts.setSyntheticLeadingComments(expression, undefined);
|
|
92927
|
+
ts.setSyntheticTrailingComments(expression, undefined);
|
|
92806
92928
|
statements.push(statement);
|
|
92807
92929
|
}
|
|
92808
92930
|
}
|
|
@@ -119143,28 +119265,37 @@ var ts;
|
|
|
119143
119265
|
useCaseSensitiveFileNames: (_a = host.useCaseSensitiveFileNames) === null || _a === void 0 ? void 0 : _a.call(host),
|
|
119144
119266
|
};
|
|
119145
119267
|
}
|
|
119146
|
-
|
|
119147
|
-
|
|
119268
|
+
// `importingSourceFile` and `importingSourceFileName`? Why not just use `importingSourceFile.path`?
|
|
119269
|
+
// Because when this is called by the file renamer, `importingSourceFile` is the file being renamed,
|
|
119270
|
+
// while `importingSourceFileName` its *new* name. We need a source file just to get its
|
|
119271
|
+
// `impliedNodeFormat` and to detect certain preferences from existing import module specifiers.
|
|
119272
|
+
function updateModuleSpecifier(compilerOptions, importingSourceFile, importingSourceFileName, toFileName, host, oldImportSpecifier) {
|
|
119273
|
+
var res = getModuleSpecifierWorker(compilerOptions, importingSourceFile, importingSourceFileName, toFileName, host, getPreferencesForUpdate(compilerOptions, oldImportSpecifier, importingSourceFileName, host), {});
|
|
119148
119274
|
if (res === oldImportSpecifier)
|
|
119149
119275
|
return undefined;
|
|
119150
119276
|
return res;
|
|
119151
119277
|
}
|
|
119152
119278
|
moduleSpecifiers_1.updateModuleSpecifier = updateModuleSpecifier;
|
|
119153
|
-
//
|
|
119279
|
+
// `importingSourceFile` and `importingSourceFileName`? Why not just use `importingSourceFile.path`?
|
|
119280
|
+
// Because when this is called by the declaration emitter, `importingSourceFile` is the implementation
|
|
119281
|
+
// file, but `importingSourceFileName` and `toFileName` refer to declaration files (the former to the
|
|
119282
|
+
// one currently being produced; the latter to the one being imported). We need an implementation file
|
|
119283
|
+
// just to get its `impliedNodeFormat` and to detect certain preferences from existing import module
|
|
119284
|
+
// specifiers.
|
|
119154
119285
|
function getModuleSpecifier(compilerOptions, importingSourceFile, importingSourceFileName, toFileName, host) {
|
|
119155
|
-
return getModuleSpecifierWorker(compilerOptions, importingSourceFileName, toFileName, host, getPreferences(host, {}, compilerOptions, importingSourceFile), {});
|
|
119286
|
+
return getModuleSpecifierWorker(compilerOptions, importingSourceFile, importingSourceFileName, toFileName, host, getPreferences(host, {}, compilerOptions, importingSourceFile), {});
|
|
119156
119287
|
}
|
|
119157
119288
|
moduleSpecifiers_1.getModuleSpecifier = getModuleSpecifier;
|
|
119158
|
-
function getNodeModulesPackageName(compilerOptions,
|
|
119159
|
-
var info = getInfo(
|
|
119160
|
-
var modulePaths = getAllModulePaths(
|
|
119161
|
-
return ts.firstDefined(modulePaths, function (modulePath) { return tryGetModuleNameAsNodeModule(modulePath, info, host, compilerOptions, /*packageNameOnly*/ true); });
|
|
119289
|
+
function getNodeModulesPackageName(compilerOptions, importingSourceFile, nodeModulesFileName, host, preferences) {
|
|
119290
|
+
var info = getInfo(importingSourceFile.path, host);
|
|
119291
|
+
var modulePaths = getAllModulePaths(importingSourceFile.path, nodeModulesFileName, host, preferences);
|
|
119292
|
+
return ts.firstDefined(modulePaths, function (modulePath) { return tryGetModuleNameAsNodeModule(modulePath, info, importingSourceFile, host, compilerOptions, /*packageNameOnly*/ true); });
|
|
119162
119293
|
}
|
|
119163
119294
|
moduleSpecifiers_1.getNodeModulesPackageName = getNodeModulesPackageName;
|
|
119164
|
-
function getModuleSpecifierWorker(compilerOptions, importingSourceFileName, toFileName, host, preferences, userPreferences) {
|
|
119295
|
+
function getModuleSpecifierWorker(compilerOptions, importingSourceFile, importingSourceFileName, toFileName, host, preferences, userPreferences) {
|
|
119165
119296
|
var info = getInfo(importingSourceFileName, host);
|
|
119166
119297
|
var modulePaths = getAllModulePaths(importingSourceFileName, toFileName, host, userPreferences);
|
|
119167
|
-
return ts.firstDefined(modulePaths, function (modulePath) { return tryGetModuleNameAsNodeModule(modulePath, info, host, compilerOptions); }) ||
|
|
119298
|
+
return ts.firstDefined(modulePaths, function (modulePath) { return tryGetModuleNameAsNodeModule(modulePath, info, importingSourceFile, host, compilerOptions); }) ||
|
|
119168
119299
|
getLocalModuleSpecifier(toFileName, info, compilerOptions, host, preferences);
|
|
119169
119300
|
}
|
|
119170
119301
|
function tryGetModuleSpecifiersFromCache(moduleSymbol, importingSourceFile, host, userPreferences) {
|
|
@@ -119231,7 +119362,7 @@ var ts;
|
|
|
119231
119362
|
var relativeSpecifiers;
|
|
119232
119363
|
for (var _i = 0, modulePaths_1 = modulePaths; _i < modulePaths_1.length; _i++) {
|
|
119233
119364
|
var modulePath = modulePaths_1[_i];
|
|
119234
|
-
var specifier = tryGetModuleNameAsNodeModule(modulePath, info, host, compilerOptions);
|
|
119365
|
+
var specifier = tryGetModuleNameAsNodeModule(modulePath, info, importingSourceFile, host, compilerOptions);
|
|
119235
119366
|
nodeModulesSpecifiers = ts.append(nodeModulesSpecifiers, specifier);
|
|
119236
119367
|
if (specifier && modulePath.isRedirect) {
|
|
119237
119368
|
// If we got a specifier for a redirect, it was a bare package specifier (e.g. "@foo/bar",
|
|
@@ -119623,7 +119754,7 @@ var ts;
|
|
|
119623
119754
|
? removeExtensionAndIndexPostFix(relativePath, ending, compilerOptions)
|
|
119624
119755
|
: ts.removeFileExtension(relativePath);
|
|
119625
119756
|
}
|
|
119626
|
-
function tryGetModuleNameAsNodeModule(_a, _b, host, options, packageNameOnly) {
|
|
119757
|
+
function tryGetModuleNameAsNodeModule(_a, _b, importingSourceFile, host, options, packageNameOnly) {
|
|
119627
119758
|
var path = _a.path, isRedirect = _a.isRedirect;
|
|
119628
119759
|
var getCanonicalFileName = _b.getCanonicalFileName, sourceDirectory = _b.sourceDirectory;
|
|
119629
119760
|
if (!host.fileExists || !host.readFile) {
|
|
@@ -119686,11 +119817,19 @@ var ts;
|
|
|
119686
119817
|
var moduleFileToTry = path;
|
|
119687
119818
|
if (host.fileExists(packageJsonPath)) {
|
|
119688
119819
|
var packageJsonContent = JSON.parse(host.readFile(packageJsonPath));
|
|
119689
|
-
// TODO: Inject `require` or `import` condition based on the intended import mode
|
|
119690
119820
|
if (ts.getEmitModuleResolutionKind(options) === ts.ModuleResolutionKind.Node12 || ts.getEmitModuleResolutionKind(options) === ts.ModuleResolutionKind.NodeNext) {
|
|
119691
|
-
|
|
119821
|
+
// `conditions` *could* be made to go against `importingSourceFile.impliedNodeFormat` if something wanted to generate
|
|
119822
|
+
// an ImportEqualsDeclaration in an ESM-implied file or an ImportCall in a CJS-implied file. But since this function is
|
|
119823
|
+
// usually called to conjure an import out of thin air, we don't have an existing usage to call `getModeForUsageAtIndex`
|
|
119824
|
+
// with, so for now we just stick with the mode of the file.
|
|
119825
|
+
var conditions = ["node", importingSourceFile.impliedNodeFormat === ts.ModuleKind.ESNext ? "import" : "require", "types"];
|
|
119826
|
+
var fromExports = packageJsonContent.exports && typeof packageJsonContent.name === "string"
|
|
119827
|
+
? tryGetModuleNameFromExports(options, path, packageRootPath, ts.getPackageNameFromTypesPackageName(packageJsonContent.name), packageJsonContent.exports, conditions)
|
|
119828
|
+
: undefined;
|
|
119692
119829
|
if (fromExports) {
|
|
119693
|
-
var withJsExtension = !ts.hasTSFileExtension(fromExports.moduleFileToTry)
|
|
119830
|
+
var withJsExtension = !ts.hasTSFileExtension(fromExports.moduleFileToTry)
|
|
119831
|
+
? fromExports
|
|
119832
|
+
: { moduleFileToTry: ts.removeFileExtension(fromExports.moduleFileToTry) + tryGetJSExtensionForFile(fromExports.moduleFileToTry, options) };
|
|
119694
119833
|
return __assign(__assign({}, withJsExtension), { verbatimFromExports: true });
|
|
119695
119834
|
}
|
|
119696
119835
|
if (packageJsonContent.exports) {
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "typescript",
|
|
3
3
|
"author": "Microsoft Corp.",
|
|
4
4
|
"homepage": "https://www.typescriptlang.org/",
|
|
5
|
-
"version": "4.6.0-dev.
|
|
5
|
+
"version": "4.6.0-dev.20220112",
|
|
6
6
|
"license": "Apache-2.0",
|
|
7
7
|
"description": "TypeScript is a language for application scale JavaScript development",
|
|
8
8
|
"keywords": [
|