typescript 4.6.0-dev.20220111 → 4.6.0-dev.20220115
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 +341 -118
- package/lib/tsserver.js +553 -224
- package/lib/tsserverlibrary.js +553 -224
- package/lib/typescript.js +499 -203
- package/lib/typescriptServices.js +499 -203
- package/lib/typingsInstaller.js +421 -144
- 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.20220115";
|
|
104
104
|
/* @internal */
|
|
105
105
|
var Comparison;
|
|
106
106
|
(function (Comparison) {
|
|
@@ -8288,7 +8288,7 @@ var ts;
|
|
|
8288
8288
|
Parameter_0_cannot_reference_identifier_1_declared_after_it: diag(2373, ts.DiagnosticCategory.Error, "Parameter_0_cannot_reference_identifier_1_declared_after_it_2373", "Parameter '{0}' cannot reference identifier '{1}' declared after it."),
|
|
8289
8289
|
Duplicate_index_signature_for_type_0: diag(2374, ts.DiagnosticCategory.Error, "Duplicate_index_signature_for_type_0_2374", "Duplicate index signature for type '{0}'."),
|
|
8290
8290
|
Type_0_is_not_assignable_to_type_1_with_exactOptionalPropertyTypes_Colon_true_Consider_adding_undefined_to_the_types_of_the_target_s_properties: diag(2375, ts.DiagnosticCategory.Error, "Type_0_is_not_assignable_to_type_1_with_exactOptionalPropertyTypes_Colon_true_Consider_adding_undefi_2375", "Type '{0}' is not assignable to type '{1}' with 'exactOptionalPropertyTypes: true'. Consider adding 'undefined' to the types of the target's properties."),
|
|
8291
|
-
|
|
8291
|
+
A_super_call_must_be_the_first_statement_in_the_constructor_to_refer_to_super_or_this_when_a_derived_class_contains_initialized_properties_parameter_properties_or_private_identifiers: diag(2376, ts.DiagnosticCategory.Error, "A_super_call_must_be_the_first_statement_in_the_constructor_to_refer_to_super_or_this_when_a_derived_2376", "A 'super' call must be the first statement in the constructor to refer to 'super' or 'this' when a derived class contains initialized properties, parameter properties, or private identifiers."),
|
|
8292
8292
|
Constructors_for_derived_classes_must_contain_a_super_call: diag(2377, ts.DiagnosticCategory.Error, "Constructors_for_derived_classes_must_contain_a_super_call_2377", "Constructors for derived classes must contain a 'super' call."),
|
|
8293
8293
|
A_get_accessor_must_return_a_value: diag(2378, ts.DiagnosticCategory.Error, "A_get_accessor_must_return_a_value_2378", "A 'get' accessor must return a value."),
|
|
8294
8294
|
Argument_of_type_0_is_not_assignable_to_parameter_of_type_1_with_exactOptionalPropertyTypes_Colon_true_Consider_adding_undefined_to_the_types_of_the_target_s_properties: diag(2379, ts.DiagnosticCategory.Error, "Argument_of_type_0_is_not_assignable_to_parameter_of_type_1_with_exactOptionalPropertyTypes_Colon_tr_2379", "Argument of type '{0}' is not assignable to parameter of type '{1}' with 'exactOptionalPropertyTypes: true'. Consider adding 'undefined' to the types of the target's properties."),
|
|
@@ -8311,6 +8311,7 @@ var ts;
|
|
|
8311
8311
|
constructor_cannot_be_used_as_a_parameter_property_name: diag(2398, ts.DiagnosticCategory.Error, "constructor_cannot_be_used_as_a_parameter_property_name_2398", "'constructor' cannot be used as a parameter property name."),
|
|
8312
8312
|
Duplicate_identifier_this_Compiler_uses_variable_declaration_this_to_capture_this_reference: diag(2399, ts.DiagnosticCategory.Error, "Duplicate_identifier_this_Compiler_uses_variable_declaration_this_to_capture_this_reference_2399", "Duplicate identifier '_this'. Compiler uses variable declaration '_this' to capture 'this' reference."),
|
|
8313
8313
|
Expression_resolves_to_variable_declaration_this_that_compiler_uses_to_capture_this_reference: diag(2400, ts.DiagnosticCategory.Error, "Expression_resolves_to_variable_declaration_this_that_compiler_uses_to_capture_this_reference_2400", "Expression resolves to variable declaration '_this' that compiler uses to capture 'this' reference."),
|
|
8314
|
+
A_super_call_must_be_a_root_level_statement_within_a_constructor_of_a_derived_class_that_contains_initialized_properties_parameter_properties_or_private_identifiers: diag(2401, ts.DiagnosticCategory.Error, "A_super_call_must_be_a_root_level_statement_within_a_constructor_of_a_derived_class_that_contains_in_2401", "A 'super' call must be a root-level statement within a constructor of a derived class that contains initialized properties, parameter properties, or private identifiers."),
|
|
8314
8315
|
Expression_resolves_to_super_that_compiler_uses_to_capture_base_class_reference: diag(2402, ts.DiagnosticCategory.Error, "Expression_resolves_to_super_that_compiler_uses_to_capture_base_class_reference_2402", "Expression resolves to '_super' that compiler uses to capture base class reference."),
|
|
8315
8316
|
Subsequent_variable_declarations_must_have_the_same_type_Variable_0_must_be_of_type_1_but_here_has_type_2: diag(2403, ts.DiagnosticCategory.Error, "Subsequent_variable_declarations_must_have_the_same_type_Variable_0_must_be_of_type_1_but_here_has_t_2403", "Subsequent variable declarations must have the same type. Variable '{0}' must be of type '{1}', but here has type '{2}'."),
|
|
8316
8317
|
The_left_hand_side_of_a_for_in_statement_cannot_use_a_type_annotation: diag(2404, ts.DiagnosticCategory.Error, "The_left_hand_side_of_a_for_in_statement_cannot_use_a_type_annotation_2404", "The left-hand side of a 'for...in' statement cannot use a type annotation."),
|
|
@@ -15471,6 +15472,34 @@ var ts;
|
|
|
15471
15472
|
}
|
|
15472
15473
|
}
|
|
15473
15474
|
ts.getThisContainer = getThisContainer;
|
|
15475
|
+
/**
|
|
15476
|
+
* @returns Whether the node creates a new 'this' scope for its children.
|
|
15477
|
+
*/
|
|
15478
|
+
function isThisContainerOrFunctionBlock(node) {
|
|
15479
|
+
switch (node.kind) {
|
|
15480
|
+
// Arrow functions use the same scope, but may do so in a "delayed" manner
|
|
15481
|
+
// For example, `const getThis = () => this` may be before a super() call in a derived constructor
|
|
15482
|
+
case 213 /* ArrowFunction */:
|
|
15483
|
+
case 255 /* FunctionDeclaration */:
|
|
15484
|
+
case 212 /* FunctionExpression */:
|
|
15485
|
+
case 166 /* PropertyDeclaration */:
|
|
15486
|
+
return true;
|
|
15487
|
+
case 234 /* Block */:
|
|
15488
|
+
switch (node.parent.kind) {
|
|
15489
|
+
case 170 /* Constructor */:
|
|
15490
|
+
case 168 /* MethodDeclaration */:
|
|
15491
|
+
case 171 /* GetAccessor */:
|
|
15492
|
+
case 172 /* SetAccessor */:
|
|
15493
|
+
// Object properties can have computed names; only method-like bodies start a new scope
|
|
15494
|
+
return true;
|
|
15495
|
+
default:
|
|
15496
|
+
return false;
|
|
15497
|
+
}
|
|
15498
|
+
default:
|
|
15499
|
+
return false;
|
|
15500
|
+
}
|
|
15501
|
+
}
|
|
15502
|
+
ts.isThisContainerOrFunctionBlock = isThisContainerOrFunctionBlock;
|
|
15474
15503
|
function isInTopLevelContext(node) {
|
|
15475
15504
|
// The name of a class or function declaration is a BindingIdentifier in its surrounding scope.
|
|
15476
15505
|
if (ts.isIdentifier(node) && (ts.isClassDeclaration(node.parent) || ts.isFunctionDeclaration(node.parent)) && node.parent.name === node) {
|
|
@@ -19791,16 +19820,6 @@ var ts;
|
|
|
19791
19820
|
(symlinkedDirectories || (symlinkedDirectories = new ts.Map())).set(symlinkPath, real);
|
|
19792
19821
|
}
|
|
19793
19822
|
},
|
|
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
19823
|
setSymlinksFromResolutions: function (files, typeReferenceDirectives) {
|
|
19805
19824
|
var _this = this;
|
|
19806
19825
|
var _a;
|
|
@@ -26067,7 +26086,7 @@ var ts;
|
|
|
26067
26086
|
* @param visitor Optional callback used to visit any custom prologue directives.
|
|
26068
26087
|
*/
|
|
26069
26088
|
function copyPrologue(source, target, ensureUseStrict, visitor) {
|
|
26070
|
-
var offset = copyStandardPrologue(source, target, ensureUseStrict);
|
|
26089
|
+
var offset = copyStandardPrologue(source, target, 0, ensureUseStrict);
|
|
26071
26090
|
return copyCustomPrologue(source, target, offset, visitor);
|
|
26072
26091
|
}
|
|
26073
26092
|
function isUseStrictPrologue(node) {
|
|
@@ -26080,12 +26099,14 @@ var ts;
|
|
|
26080
26099
|
* Copies only the standard (string-expression) prologue-directives into the target statement-array.
|
|
26081
26100
|
* @param source origin statements array
|
|
26082
26101
|
* @param target result statements array
|
|
26102
|
+
* @param statementOffset The offset at which to begin the copy.
|
|
26083
26103
|
* @param ensureUseStrict boolean determining whether the function need to add prologue-directives
|
|
26104
|
+
* @returns Count of how many directive statements were copied.
|
|
26084
26105
|
*/
|
|
26085
|
-
function copyStandardPrologue(source, target, ensureUseStrict) {
|
|
26106
|
+
function copyStandardPrologue(source, target, statementOffset, ensureUseStrict) {
|
|
26107
|
+
if (statementOffset === void 0) { statementOffset = 0; }
|
|
26086
26108
|
ts.Debug.assert(target.length === 0, "Prologue directives should be at the first statement in the target statements array");
|
|
26087
26109
|
var foundUseStrict = false;
|
|
26088
|
-
var statementOffset = 0;
|
|
26089
26110
|
var numStatements = source.length;
|
|
26090
26111
|
while (statementOffset < numStatements) {
|
|
26091
26112
|
var statement = source[statementOffset];
|
|
@@ -27508,7 +27529,7 @@ var ts;
|
|
|
27508
27529
|
importName: "__createBinding",
|
|
27509
27530
|
scoped: false,
|
|
27510
27531
|
priority: 1,
|
|
27511
|
-
text: "\n var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {\n if (k2 === undefined) k2 = k;\n Object.
|
|
27532
|
+
text: "\n var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {\n if (k2 === undefined) k2 = k;\n var desc = Object.getOwnPropertyDescriptor(m, k);\n if (!desc || (\"get\" in desc ? !m.__esModule : desc.writable || desc.configurable)) {\n desc = { enumerable: true, get: function() { return m[k]; } };\n }\n Object.defineProperty(o, k2, desc);\n }) : (function(o, m, k, k2) {\n if (k2 === undefined) k2 = k;\n o[k2] = m[k];\n }));"
|
|
27512
27533
|
};
|
|
27513
27534
|
ts.setModuleDefaultHelper = {
|
|
27514
27535
|
name: "typescript:commonjscreatevalue",
|
|
@@ -41143,7 +41164,7 @@ var ts;
|
|
|
41143
41164
|
? 1 /* Recursive */ : 0 /* None */
|
|
41144
41165
|
};
|
|
41145
41166
|
}
|
|
41146
|
-
if (ts.isImplicitGlob(spec)) {
|
|
41167
|
+
if (ts.isImplicitGlob(spec.substring(spec.lastIndexOf(ts.directorySeparator) + 1))) {
|
|
41147
41168
|
return {
|
|
41148
41169
|
key: useCaseSensitiveFileNames ? spec : ts.toFileNameLowerCase(spec),
|
|
41149
41170
|
flags: 1 /* Recursive */
|
|
@@ -41509,9 +41530,7 @@ var ts;
|
|
|
41509
41530
|
}
|
|
41510
41531
|
}
|
|
41511
41532
|
var failedLookupLocations = [];
|
|
41512
|
-
var features =
|
|
41513
|
-
ts.getEmitModuleResolutionKind(options) === ts.ModuleResolutionKind.NodeNext ? NodeResolutionFeatures.NodeNextDefault :
|
|
41514
|
-
NodeResolutionFeatures.None;
|
|
41533
|
+
var features = getDefaultNodeResolutionFeatures(options);
|
|
41515
41534
|
var moduleResolutionState = { compilerOptions: options, host: host, traceEnabled: traceEnabled, failedLookupLocations: failedLookupLocations, packageJsonInfoCache: cache, features: features, conditions: ["node", "require", "types"] };
|
|
41516
41535
|
var resolved = primaryLookup();
|
|
41517
41536
|
var primary = true;
|
|
@@ -41596,6 +41615,34 @@ var ts;
|
|
|
41596
41615
|
}
|
|
41597
41616
|
}
|
|
41598
41617
|
ts.resolveTypeReferenceDirective = resolveTypeReferenceDirective;
|
|
41618
|
+
function getDefaultNodeResolutionFeatures(options) {
|
|
41619
|
+
return ts.getEmitModuleResolutionKind(options) === ts.ModuleResolutionKind.Node12 ? NodeResolutionFeatures.Node12Default :
|
|
41620
|
+
ts.getEmitModuleResolutionKind(options) === ts.ModuleResolutionKind.NodeNext ? NodeResolutionFeatures.NodeNextDefault :
|
|
41621
|
+
NodeResolutionFeatures.None;
|
|
41622
|
+
}
|
|
41623
|
+
/**
|
|
41624
|
+
* @internal
|
|
41625
|
+
* Does not try `@types/${packageName}` - use a second pass if needed.
|
|
41626
|
+
*/
|
|
41627
|
+
function resolvePackageNameToPackageJson(packageName, containingDirectory, options, host, cache) {
|
|
41628
|
+
var moduleResolutionState = {
|
|
41629
|
+
compilerOptions: options,
|
|
41630
|
+
host: host,
|
|
41631
|
+
traceEnabled: isTraceEnabled(options, host),
|
|
41632
|
+
failedLookupLocations: [],
|
|
41633
|
+
packageJsonInfoCache: cache === null || cache === void 0 ? void 0 : cache.getPackageJsonInfoCache(),
|
|
41634
|
+
conditions: ts.emptyArray,
|
|
41635
|
+
features: NodeResolutionFeatures.None,
|
|
41636
|
+
};
|
|
41637
|
+
return ts.forEachAncestorDirectory(containingDirectory, function (ancestorDirectory) {
|
|
41638
|
+
if (ts.getBaseFileName(ancestorDirectory) !== "node_modules") {
|
|
41639
|
+
var nodeModulesFolder = ts.combinePaths(ancestorDirectory, "node_modules");
|
|
41640
|
+
var candidate = ts.combinePaths(nodeModulesFolder, packageName);
|
|
41641
|
+
return getPackageJsonInfo(candidate, /*onlyRecordFailures*/ false, moduleResolutionState);
|
|
41642
|
+
}
|
|
41643
|
+
});
|
|
41644
|
+
}
|
|
41645
|
+
ts.resolvePackageNameToPackageJson = resolvePackageNameToPackageJson;
|
|
41599
41646
|
/**
|
|
41600
41647
|
* Given a set of options, returns the set of type directive names
|
|
41601
41648
|
* that should be included for this program automatically.
|
|
@@ -42169,11 +42216,6 @@ var ts;
|
|
|
42169
42216
|
}
|
|
42170
42217
|
ts.resolveJSModule = resolveJSModule;
|
|
42171
42218
|
/* @internal */
|
|
42172
|
-
function tryResolveJSModule(moduleName, initialDir, host) {
|
|
42173
|
-
return tryResolveJSModuleWorker(moduleName, initialDir, host).resolvedModule;
|
|
42174
|
-
}
|
|
42175
|
-
ts.tryResolveJSModule = tryResolveJSModule;
|
|
42176
|
-
/* @internal */
|
|
42177
42219
|
var NodeResolutionFeatures;
|
|
42178
42220
|
(function (NodeResolutionFeatures) {
|
|
42179
42221
|
NodeResolutionFeatures[NodeResolutionFeatures["None"] = 0] = "None";
|
|
@@ -42481,6 +42523,97 @@ var ts;
|
|
|
42481
42523
|
var versionPaths = packageInfo && packageInfo.versionPaths;
|
|
42482
42524
|
return withPackageId(packageInfo, loadNodeModuleFromDirectoryWorker(extensions, candidate, onlyRecordFailures, state, packageJsonContent, versionPaths));
|
|
42483
42525
|
}
|
|
42526
|
+
/* @internal */
|
|
42527
|
+
function getEntrypointsFromPackageJsonInfo(packageJsonInfo, options, host, cache, resolveJs) {
|
|
42528
|
+
if (!resolveJs && packageJsonInfo.resolvedEntrypoints !== undefined) {
|
|
42529
|
+
// Cached value excludes resolutions to JS files - those could be
|
|
42530
|
+
// cached separately, but they're used rarely.
|
|
42531
|
+
return packageJsonInfo.resolvedEntrypoints;
|
|
42532
|
+
}
|
|
42533
|
+
var entrypoints;
|
|
42534
|
+
var extensions = resolveJs ? Extensions.JavaScript : Extensions.TypeScript;
|
|
42535
|
+
var features = getDefaultNodeResolutionFeatures(options);
|
|
42536
|
+
var requireState = {
|
|
42537
|
+
compilerOptions: options,
|
|
42538
|
+
host: host,
|
|
42539
|
+
traceEnabled: isTraceEnabled(options, host),
|
|
42540
|
+
failedLookupLocations: [],
|
|
42541
|
+
packageJsonInfoCache: cache === null || cache === void 0 ? void 0 : cache.getPackageJsonInfoCache(),
|
|
42542
|
+
conditions: ["node", "require", "types"],
|
|
42543
|
+
features: features,
|
|
42544
|
+
};
|
|
42545
|
+
var requireResolution = loadNodeModuleFromDirectoryWorker(extensions, packageJsonInfo.packageDirectory,
|
|
42546
|
+
/*onlyRecordFailures*/ false, requireState, packageJsonInfo.packageJsonContent, packageJsonInfo.versionPaths);
|
|
42547
|
+
entrypoints = ts.append(entrypoints, requireResolution === null || requireResolution === void 0 ? void 0 : requireResolution.path);
|
|
42548
|
+
if (features & NodeResolutionFeatures.Exports && packageJsonInfo.packageJsonContent.exports) {
|
|
42549
|
+
for (var _i = 0, _a = [["node", "import", "types"], ["node", "require", "types"]]; _i < _a.length; _i++) {
|
|
42550
|
+
var conditions = _a[_i];
|
|
42551
|
+
var exportState = __assign(__assign({}, requireState), { failedLookupLocations: [], conditions: conditions });
|
|
42552
|
+
var exportResolutions = loadEntrypointsFromExportMap(packageJsonInfo, packageJsonInfo.packageJsonContent.exports, exportState, extensions);
|
|
42553
|
+
if (exportResolutions) {
|
|
42554
|
+
for (var _b = 0, exportResolutions_1 = exportResolutions; _b < exportResolutions_1.length; _b++) {
|
|
42555
|
+
var resolution = exportResolutions_1[_b];
|
|
42556
|
+
entrypoints = ts.appendIfUnique(entrypoints, resolution.path);
|
|
42557
|
+
}
|
|
42558
|
+
}
|
|
42559
|
+
}
|
|
42560
|
+
}
|
|
42561
|
+
return packageJsonInfo.resolvedEntrypoints = entrypoints || false;
|
|
42562
|
+
}
|
|
42563
|
+
ts.getEntrypointsFromPackageJsonInfo = getEntrypointsFromPackageJsonInfo;
|
|
42564
|
+
function loadEntrypointsFromExportMap(scope, exports, state, extensions) {
|
|
42565
|
+
var entrypoints;
|
|
42566
|
+
if (ts.isArray(exports)) {
|
|
42567
|
+
for (var _i = 0, exports_1 = exports; _i < exports_1.length; _i++) {
|
|
42568
|
+
var target = exports_1[_i];
|
|
42569
|
+
loadEntrypointsFromTargetExports(target);
|
|
42570
|
+
}
|
|
42571
|
+
}
|
|
42572
|
+
// eslint-disable-next-line no-null/no-null
|
|
42573
|
+
else if (typeof exports === "object" && exports !== null && allKeysStartWithDot(exports)) {
|
|
42574
|
+
for (var key in exports) {
|
|
42575
|
+
loadEntrypointsFromTargetExports(exports[key]);
|
|
42576
|
+
}
|
|
42577
|
+
}
|
|
42578
|
+
else {
|
|
42579
|
+
loadEntrypointsFromTargetExports(exports);
|
|
42580
|
+
}
|
|
42581
|
+
return entrypoints;
|
|
42582
|
+
function loadEntrypointsFromTargetExports(target) {
|
|
42583
|
+
var _a, _b;
|
|
42584
|
+
if (typeof target === "string" && ts.startsWith(target, "./") && target.indexOf("*") === -1) {
|
|
42585
|
+
var partsAfterFirst = ts.getPathComponents(target).slice(2);
|
|
42586
|
+
if (partsAfterFirst.indexOf("..") >= 0 || partsAfterFirst.indexOf(".") >= 0 || partsAfterFirst.indexOf("node_modules") >= 0) {
|
|
42587
|
+
return false;
|
|
42588
|
+
}
|
|
42589
|
+
var resolvedTarget = ts.combinePaths(scope.packageDirectory, target);
|
|
42590
|
+
var finalPath = ts.getNormalizedAbsolutePath(resolvedTarget, (_b = (_a = state.host).getCurrentDirectory) === null || _b === void 0 ? void 0 : _b.call(_a));
|
|
42591
|
+
var result = loadJSOrExactTSFileName(extensions, finalPath, /*recordOnlyFailures*/ false, state);
|
|
42592
|
+
if (result) {
|
|
42593
|
+
entrypoints = ts.appendIfUnique(entrypoints, result, function (a, b) { return a.path === b.path; });
|
|
42594
|
+
return true;
|
|
42595
|
+
}
|
|
42596
|
+
}
|
|
42597
|
+
else if (Array.isArray(target)) {
|
|
42598
|
+
for (var _i = 0, target_1 = target; _i < target_1.length; _i++) {
|
|
42599
|
+
var t = target_1[_i];
|
|
42600
|
+
var success = loadEntrypointsFromTargetExports(t);
|
|
42601
|
+
if (success) {
|
|
42602
|
+
return true;
|
|
42603
|
+
}
|
|
42604
|
+
}
|
|
42605
|
+
}
|
|
42606
|
+
// eslint-disable-next-line no-null/no-null
|
|
42607
|
+
else if (typeof target === "object" && target !== null) {
|
|
42608
|
+
return ts.forEach(ts.getOwnKeys(target), function (key) {
|
|
42609
|
+
if (key === "default" || ts.contains(state.conditions, key) || isApplicableVersionedTypesKey(state.conditions, key)) {
|
|
42610
|
+
loadEntrypointsFromTargetExports(target[key]);
|
|
42611
|
+
return true;
|
|
42612
|
+
}
|
|
42613
|
+
});
|
|
42614
|
+
}
|
|
42615
|
+
}
|
|
42616
|
+
}
|
|
42484
42617
|
/**
|
|
42485
42618
|
* A function for locating the package.json scope for a given path
|
|
42486
42619
|
*/
|
|
@@ -42537,7 +42670,7 @@ var ts;
|
|
|
42537
42670
|
trace(host, ts.Diagnostics.Found_package_json_at_0, packageJsonPath);
|
|
42538
42671
|
}
|
|
42539
42672
|
var versionPaths = readPackageJsonTypesVersionPaths(packageJsonContent, state);
|
|
42540
|
-
var result = { packageDirectory: packageDirectory, packageJsonContent: packageJsonContent, versionPaths: versionPaths };
|
|
42673
|
+
var result = { packageDirectory: packageDirectory, packageJsonContent: packageJsonContent, versionPaths: versionPaths, resolvedEntrypoints: undefined };
|
|
42541
42674
|
(_b = state.packageJsonInfoCache) === null || _b === void 0 ? void 0 : _b.setPackageJsonInfo(packageJsonPath, result);
|
|
42542
42675
|
return result;
|
|
42543
42676
|
}
|
|
@@ -42834,8 +42967,8 @@ var ts;
|
|
|
42834
42967
|
}
|
|
42835
42968
|
return toSearchResult(/*value*/ undefined);
|
|
42836
42969
|
}
|
|
42837
|
-
for (var _d = 0,
|
|
42838
|
-
var elem =
|
|
42970
|
+
for (var _d = 0, target_2 = target; _d < target_2.length; _d++) {
|
|
42971
|
+
var elem = target_2[_d];
|
|
42839
42972
|
var result = loadModuleFromTargetImportOrExport(elem, subpath, pattern);
|
|
42840
42973
|
if (result) {
|
|
42841
42974
|
return result;
|
|
@@ -52068,8 +52201,8 @@ var ts;
|
|
|
52068
52201
|
}
|
|
52069
52202
|
else {
|
|
52070
52203
|
if (parent && getExportsOfSymbol(parent)) {
|
|
52071
|
-
var
|
|
52072
|
-
ts.forEachEntry(
|
|
52204
|
+
var exports_2 = getExportsOfSymbol(parent);
|
|
52205
|
+
ts.forEachEntry(exports_2, function (ex, name) {
|
|
52073
52206
|
if (getSymbolIfSameReference(ex, symbol) && !isLateBoundName(name) && name !== "export=" /* ExportEquals */) {
|
|
52074
52207
|
symbolName = ts.unescapeLeadingUnderscores(name);
|
|
52075
52208
|
return true;
|
|
@@ -57180,6 +57313,11 @@ var ts;
|
|
|
57180
57313
|
return simplified !== type ? simplified : getConstraintOfType(type);
|
|
57181
57314
|
}
|
|
57182
57315
|
function getConstraintFromIndexedAccess(type) {
|
|
57316
|
+
if (isMappedTypeGenericIndexedAccess(type)) {
|
|
57317
|
+
// For indexed access types of the form { [P in K]: E }[X], where K is non-generic and X is generic,
|
|
57318
|
+
// we substitute an instantiation of E where P is replaced with X.
|
|
57319
|
+
return substituteIndexedMappedType(type.objectType, type.indexType);
|
|
57320
|
+
}
|
|
57183
57321
|
var indexConstraint = getSimplifiedTypeOrConstraint(type.indexType);
|
|
57184
57322
|
if (indexConstraint && indexConstraint !== type.indexType) {
|
|
57185
57323
|
var indexedAccess = getIndexedAccessTypeOrUndefined(type.objectType, indexConstraint, type.accessFlags);
|
|
@@ -57384,6 +57522,11 @@ var ts;
|
|
|
57384
57522
|
return constraint ? getStringMappingType(t.symbol, constraint) : stringType;
|
|
57385
57523
|
}
|
|
57386
57524
|
if (t.flags & 8388608 /* IndexedAccess */) {
|
|
57525
|
+
if (isMappedTypeGenericIndexedAccess(t)) {
|
|
57526
|
+
// For indexed access types of the form { [P in K]: E }[X], where K is non-generic and X is generic,
|
|
57527
|
+
// we substitute an instantiation of E where P is replaced with X.
|
|
57528
|
+
return getBaseConstraint(substituteIndexedMappedType(t.objectType, t.indexType));
|
|
57529
|
+
}
|
|
57387
57530
|
var baseObjectType = getBaseConstraint(t.objectType);
|
|
57388
57531
|
var baseIndexType = getBaseConstraint(t.indexType);
|
|
57389
57532
|
var baseIndexedAccess = baseObjectType && baseIndexType && getIndexedAccessTypeOrUndefined(baseObjectType, baseIndexType, t.accessFlags);
|
|
@@ -57468,13 +57611,7 @@ var ts;
|
|
|
57468
57611
|
* type itself.
|
|
57469
57612
|
*/
|
|
57470
57613
|
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;
|
|
57614
|
+
var t = !(type.flags & 465829888 /* Instantiable */) ? type : getBaseConstraintOfType(type) || unknownType;
|
|
57478
57615
|
return ts.getObjectFlags(t) & 32 /* Mapped */ ? getApparentTypeOfMappedType(t) :
|
|
57479
57616
|
t.flags & 2097152 /* Intersection */ ? getApparentTypeOfIntersectionType(t) :
|
|
57480
57617
|
t.flags & 402653316 /* StringLike */ ? globalStringType :
|
|
@@ -64138,6 +64275,17 @@ var ts;
|
|
|
64138
64275
|
resetErrorInfo(saveErrorInfo);
|
|
64139
64276
|
return result;
|
|
64140
64277
|
}
|
|
64278
|
+
if (isMappedTypeGenericIndexedAccess(source)) {
|
|
64279
|
+
// For an indexed access type { [P in K]: E}[X], above we have already explored an instantiation of E with X
|
|
64280
|
+
// substituted for P. We also want to explore type { [P in K]: E }[C], where C is the constraint of X.
|
|
64281
|
+
var indexConstraint = getConstraintOfType(source.indexType);
|
|
64282
|
+
if (indexConstraint) {
|
|
64283
|
+
if (result = isRelatedTo(getIndexedAccessType(source.objectType, indexConstraint), target, 1 /* Source */, reportErrors)) {
|
|
64284
|
+
resetErrorInfo(saveErrorInfo);
|
|
64285
|
+
return result;
|
|
64286
|
+
}
|
|
64287
|
+
}
|
|
64288
|
+
}
|
|
64141
64289
|
}
|
|
64142
64290
|
}
|
|
64143
64291
|
else if (source.flags & 4194304 /* Index */) {
|
|
@@ -78401,32 +78549,38 @@ var ts;
|
|
|
78401
78549
|
if (classExtendsNull) {
|
|
78402
78550
|
error(superCall, ts.Diagnostics.A_constructor_cannot_contain_a_super_call_when_its_class_extends_null);
|
|
78403
78551
|
}
|
|
78404
|
-
//
|
|
78405
|
-
// if both of the following are true:
|
|
78552
|
+
// A super call must be root-level in a constructor if both of the following are true:
|
|
78406
78553
|
// - The containing class is a derived class.
|
|
78407
78554
|
// - The constructor declares parameter properties
|
|
78408
78555
|
// or the containing class declares instance member variables with initializers.
|
|
78409
|
-
var
|
|
78556
|
+
var superCallShouldBeRootLevel = (ts.getEmitScriptTarget(compilerOptions) !== 99 /* ESNext */ || !useDefineForClassFields) &&
|
|
78410
78557
|
(ts.some(node.parent.members, isInstancePropertyWithInitializerOrPrivateIdentifierProperty) ||
|
|
78411
78558
|
ts.some(node.parameters, function (p) { return ts.hasSyntacticModifier(p, 16476 /* ParameterPropertyModifier */); }));
|
|
78412
|
-
|
|
78413
|
-
|
|
78414
|
-
|
|
78415
|
-
|
|
78416
|
-
|
|
78417
|
-
|
|
78418
|
-
|
|
78419
|
-
|
|
78420
|
-
|
|
78421
|
-
|
|
78559
|
+
if (superCallShouldBeRootLevel) {
|
|
78560
|
+
// Until we have better flow analysis, it is an error to place the super call within any kind of block or conditional
|
|
78561
|
+
// See GH #8277
|
|
78562
|
+
if (!superCallIsRootLevelInConstructor(superCall, node.body)) {
|
|
78563
|
+
error(superCall, ts.Diagnostics.A_super_call_must_be_a_root_level_statement_within_a_constructor_of_a_derived_class_that_contains_initialized_properties_parameter_properties_or_private_identifiers);
|
|
78564
|
+
}
|
|
78565
|
+
// Skip past any prologue directives to check statements for referring to 'super' or 'this' before a super call
|
|
78566
|
+
else {
|
|
78567
|
+
var superCallStatement = void 0;
|
|
78568
|
+
for (var _i = 0, _a = node.body.statements; _i < _a.length; _i++) {
|
|
78569
|
+
var statement = _a[_i];
|
|
78570
|
+
if (ts.isExpressionStatement(statement) && ts.isSuperCall(ts.skipOuterExpressions(statement.expression))) {
|
|
78571
|
+
superCallStatement = statement;
|
|
78572
|
+
break;
|
|
78573
|
+
}
|
|
78574
|
+
if (!ts.isPrologueDirective(statement) && nodeImmediatelyReferencesSuperOrThis(statement)) {
|
|
78575
|
+
break;
|
|
78576
|
+
}
|
|
78422
78577
|
}
|
|
78423
|
-
|
|
78424
|
-
|
|
78578
|
+
// Until we have better flow analysis, it is an error to place the super call within any kind of block or conditional
|
|
78579
|
+
// See GH #8277
|
|
78580
|
+
if (superCallStatement === undefined) {
|
|
78581
|
+
error(node, ts.Diagnostics.A_super_call_must_be_the_first_statement_in_the_constructor_to_refer_to_super_or_this_when_a_derived_class_contains_initialized_properties_parameter_properties_or_private_identifiers);
|
|
78425
78582
|
}
|
|
78426
78583
|
}
|
|
78427
|
-
if (!superCallStatement) {
|
|
78428
|
-
error(node, ts.Diagnostics.A_super_call_must_be_the_first_statement_in_the_constructor_when_a_class_contains_initialized_properties_parameter_properties_or_private_identifiers);
|
|
78429
|
-
}
|
|
78430
78584
|
}
|
|
78431
78585
|
}
|
|
78432
78586
|
else if (!classExtendsNull) {
|
|
@@ -78434,6 +78588,19 @@ var ts;
|
|
|
78434
78588
|
}
|
|
78435
78589
|
}
|
|
78436
78590
|
}
|
|
78591
|
+
function superCallIsRootLevelInConstructor(superCall, body) {
|
|
78592
|
+
var superCallParent = ts.walkUpParenthesizedExpressions(superCall.parent);
|
|
78593
|
+
return ts.isExpressionStatement(superCallParent) && superCallParent.parent === body;
|
|
78594
|
+
}
|
|
78595
|
+
function nodeImmediatelyReferencesSuperOrThis(node) {
|
|
78596
|
+
if (node.kind === 106 /* SuperKeyword */ || node.kind === 108 /* ThisKeyword */) {
|
|
78597
|
+
return true;
|
|
78598
|
+
}
|
|
78599
|
+
if (ts.isThisContainerOrFunctionBlock(node)) {
|
|
78600
|
+
return false;
|
|
78601
|
+
}
|
|
78602
|
+
return !!ts.forEachChild(node, nodeImmediatelyReferencesSuperOrThis);
|
|
78603
|
+
}
|
|
78437
78604
|
function checkAccessorDeclaration(node) {
|
|
78438
78605
|
if (produceDiagnostics) {
|
|
78439
78606
|
// Grammar checking accessors
|
|
@@ -83256,9 +83423,9 @@ var ts;
|
|
|
83256
83423
|
}
|
|
83257
83424
|
}
|
|
83258
83425
|
// Checks for export * conflicts
|
|
83259
|
-
var
|
|
83260
|
-
if (
|
|
83261
|
-
|
|
83426
|
+
var exports_3 = getExportsOfModule(moduleSymbol);
|
|
83427
|
+
if (exports_3) {
|
|
83428
|
+
exports_3.forEach(function (_a, id) {
|
|
83262
83429
|
var declarations = _a.declarations, flags = _a.flags;
|
|
83263
83430
|
if (id === "__export") {
|
|
83264
83431
|
return;
|
|
@@ -88556,34 +88723,31 @@ var ts;
|
|
|
88556
88723
|
}
|
|
88557
88724
|
ts.getNonAssignmentOperatorForCompoundAssignment = getNonAssignmentOperatorForCompoundAssignment;
|
|
88558
88725
|
/**
|
|
88559
|
-
*
|
|
88560
|
-
|
|
88561
|
-
|
|
88562
|
-
|
|
88563
|
-
|
|
88564
|
-
|
|
88726
|
+
* @returns Contained super() call from descending into the statement ignoring parentheses, if that call exists.
|
|
88727
|
+
*/
|
|
88728
|
+
function getSuperCallFromStatement(statement) {
|
|
88729
|
+
if (!ts.isExpressionStatement(statement)) {
|
|
88730
|
+
return undefined;
|
|
88731
|
+
}
|
|
88732
|
+
var expression = ts.skipParentheses(statement.expression);
|
|
88733
|
+
return ts.isSuperCall(expression)
|
|
88734
|
+
? expression
|
|
88735
|
+
: undefined;
|
|
88736
|
+
}
|
|
88737
|
+
ts.getSuperCallFromStatement = getSuperCallFromStatement;
|
|
88738
|
+
/**
|
|
88739
|
+
* @returns The index (after prologue statements) of a super call, or -1 if not found.
|
|
88565
88740
|
*/
|
|
88566
|
-
function
|
|
88567
|
-
|
|
88568
|
-
var
|
|
88569
|
-
|
|
88570
|
-
|
|
88571
|
-
if (index === statements.length) {
|
|
88572
|
-
// list contains nothing but prologue directives (or empty) - exit
|
|
88573
|
-
return index;
|
|
88574
|
-
}
|
|
88575
|
-
var superIndex = ts.findIndex(statements, function (s) { return ts.isExpressionStatement(s) && ts.isSuperCall(s.expression); }, index);
|
|
88576
|
-
if (superIndex > -1) {
|
|
88577
|
-
for (var i = index; i <= superIndex; i++) {
|
|
88578
|
-
result.push(ts.visitNode(statements[i], visitor, ts.isStatement));
|
|
88579
|
-
}
|
|
88580
|
-
return superIndex + 1;
|
|
88741
|
+
function findSuperStatementIndex(statements, indexAfterLastPrologueStatement) {
|
|
88742
|
+
for (var i = indexAfterLastPrologueStatement; i < statements.length; i += 1) {
|
|
88743
|
+
var statement = statements[i];
|
|
88744
|
+
if (getSuperCallFromStatement(statement)) {
|
|
88745
|
+
return i;
|
|
88581
88746
|
}
|
|
88582
|
-
return index;
|
|
88583
88747
|
}
|
|
88584
|
-
return
|
|
88748
|
+
return -1;
|
|
88585
88749
|
}
|
|
88586
|
-
ts.
|
|
88750
|
+
ts.findSuperStatementIndex = findSuperStatementIndex;
|
|
88587
88751
|
function getProperties(node, requireInitializer, isStatic) {
|
|
88588
88752
|
return ts.filter(node.members, function (m) { return isInitializedOrStaticProperty(m, requireInitializer, isStatic); });
|
|
88589
88753
|
}
|
|
@@ -90482,6 +90646,7 @@ var ts;
|
|
|
90482
90646
|
case 176 /* TypePredicate */:
|
|
90483
90647
|
case 133 /* BooleanKeyword */:
|
|
90484
90648
|
return factory.createIdentifier("Boolean");
|
|
90649
|
+
case 197 /* TemplateLiteralType */:
|
|
90485
90650
|
case 149 /* StringKeyword */:
|
|
90486
90651
|
return factory.createIdentifier("String");
|
|
90487
90652
|
case 147 /* ObjectKeyword */:
|
|
@@ -90820,10 +90985,14 @@ var ts;
|
|
|
90820
90985
|
return ts.visitFunctionBody(body, visitor, context);
|
|
90821
90986
|
}
|
|
90822
90987
|
var statements = [];
|
|
90823
|
-
var indexOfFirstStatement = 0;
|
|
90824
90988
|
resumeLexicalEnvironment();
|
|
90825
|
-
|
|
90826
|
-
|
|
90989
|
+
var indexAfterLastPrologueStatement = factory.copyPrologue(body.statements, statements, /*ensureUseStrict*/ false, visitor);
|
|
90990
|
+
var superStatementIndex = ts.findSuperStatementIndex(body.statements, indexAfterLastPrologueStatement);
|
|
90991
|
+
// If there was a super call, visit existing statements up to and including it
|
|
90992
|
+
if (superStatementIndex >= 0) {
|
|
90993
|
+
ts.addRange(statements, ts.visitNodes(body.statements, visitor, ts.isStatement, indexAfterLastPrologueStatement, superStatementIndex + 1 - indexAfterLastPrologueStatement));
|
|
90994
|
+
}
|
|
90995
|
+
// Transform parameters into property assignments. Transforms this:
|
|
90827
90996
|
//
|
|
90828
90997
|
// constructor (public x, public y) {
|
|
90829
90998
|
// }
|
|
@@ -90835,9 +91004,17 @@ var ts;
|
|
|
90835
91004
|
// this.y = y;
|
|
90836
91005
|
// }
|
|
90837
91006
|
//
|
|
90838
|
-
|
|
90839
|
-
//
|
|
90840
|
-
|
|
91007
|
+
var parameterPropertyAssignments = ts.mapDefined(parametersWithPropertyAssignments, transformParameterWithPropertyAssignment);
|
|
91008
|
+
// If there is a super() call, the parameter properties go immediately after it
|
|
91009
|
+
if (superStatementIndex >= 0) {
|
|
91010
|
+
ts.addRange(statements, parameterPropertyAssignments);
|
|
91011
|
+
}
|
|
91012
|
+
// Since there was no super() call, parameter properties are the first statements in the constructor
|
|
91013
|
+
else {
|
|
91014
|
+
statements = ts.addRange(parameterPropertyAssignments, statements);
|
|
91015
|
+
}
|
|
91016
|
+
// Add remaining statements from the body, skipping the super() call if it was found
|
|
91017
|
+
ts.addRange(statements, ts.visitNodes(body.statements, visitor, ts.isStatement, superStatementIndex + 1));
|
|
90841
91018
|
// End the lexical environment.
|
|
90842
91019
|
statements = factory.mergeLexicalEnvironment(statements, endLexicalEnvironment());
|
|
90843
91020
|
var block = factory.createBlock(ts.setTextRange(factory.createNodeArray(statements), body.statements), /*multiLine*/ true);
|
|
@@ -92735,6 +92912,7 @@ var ts;
|
|
|
92735
92912
|
/*modifiers*/ undefined, parameters !== null && parameters !== void 0 ? parameters : [], body), constructor || node), constructor));
|
|
92736
92913
|
}
|
|
92737
92914
|
function transformConstructorBody(node, constructor, isDerivedClass) {
|
|
92915
|
+
var _a;
|
|
92738
92916
|
var properties = ts.getProperties(node, /*requireInitializer*/ false, /*isStatic*/ false);
|
|
92739
92917
|
if (!useDefineForClassFields) {
|
|
92740
92918
|
properties = ts.filter(properties, function (property) { return !!property.initializer || ts.isPrivateIdentifier(property.name); });
|
|
@@ -92746,9 +92924,21 @@ var ts;
|
|
|
92746
92924
|
return ts.visitFunctionBody(/*node*/ undefined, visitor, context);
|
|
92747
92925
|
}
|
|
92748
92926
|
resumeLexicalEnvironment();
|
|
92749
|
-
var
|
|
92927
|
+
var needsSyntheticConstructor = !constructor && isDerivedClass;
|
|
92928
|
+
var indexOfFirstStatementAfterSuper = 0;
|
|
92929
|
+
var prologueStatementCount = 0;
|
|
92930
|
+
var superStatementIndex = -1;
|
|
92750
92931
|
var statements = [];
|
|
92751
|
-
if (
|
|
92932
|
+
if ((_a = constructor === null || constructor === void 0 ? void 0 : constructor.body) === null || _a === void 0 ? void 0 : _a.statements) {
|
|
92933
|
+
prologueStatementCount = factory.copyPrologue(constructor.body.statements, statements, /*ensureUseStrict*/ false, visitor);
|
|
92934
|
+
superStatementIndex = ts.findSuperStatementIndex(constructor.body.statements, prologueStatementCount);
|
|
92935
|
+
// If there was a super call, visit existing statements up to and including it
|
|
92936
|
+
if (superStatementIndex >= 0) {
|
|
92937
|
+
indexOfFirstStatementAfterSuper = superStatementIndex + 1;
|
|
92938
|
+
statements = __spreadArray(__spreadArray(__spreadArray([], statements.slice(0, prologueStatementCount), true), ts.visitNodes(constructor.body.statements, visitor, ts.isStatement, prologueStatementCount, indexOfFirstStatementAfterSuper - prologueStatementCount), true), statements.slice(prologueStatementCount), true);
|
|
92939
|
+
}
|
|
92940
|
+
}
|
|
92941
|
+
if (needsSyntheticConstructor) {
|
|
92752
92942
|
// Add a synthetic `super` call:
|
|
92753
92943
|
//
|
|
92754
92944
|
// super(...arguments);
|
|
@@ -92756,9 +92946,6 @@ var ts;
|
|
|
92756
92946
|
statements.push(factory.createExpressionStatement(factory.createCallExpression(factory.createSuper(),
|
|
92757
92947
|
/*typeArguments*/ undefined, [factory.createSpreadElement(factory.createIdentifier("arguments"))])));
|
|
92758
92948
|
}
|
|
92759
|
-
if (constructor) {
|
|
92760
|
-
indexOfFirstStatement = ts.addPrologueDirectivesAndInitialSuperCall(factory, constructor, statements, visitor);
|
|
92761
|
-
}
|
|
92762
92949
|
// Add the property initializers. Transforms this:
|
|
92763
92950
|
//
|
|
92764
92951
|
// public x = 1;
|
|
@@ -92769,31 +92956,59 @@ var ts;
|
|
|
92769
92956
|
// this.x = 1;
|
|
92770
92957
|
// }
|
|
92771
92958
|
//
|
|
92959
|
+
// If we do useDefineForClassFields, they'll be converted elsewhere.
|
|
92960
|
+
// We instead *remove* them from the transformed output at this stage.
|
|
92961
|
+
var parameterPropertyDeclarationCount = 0;
|
|
92772
92962
|
if (constructor === null || constructor === void 0 ? void 0 : constructor.body) {
|
|
92773
|
-
|
|
92774
|
-
|
|
92775
|
-
afterParameterProperties = constructor.body.statements.length;
|
|
92963
|
+
if (useDefineForClassFields) {
|
|
92964
|
+
statements = statements.filter(function (statement) { return !ts.isParameterPropertyDeclaration(ts.getOriginalNode(statement), constructor); });
|
|
92776
92965
|
}
|
|
92777
|
-
|
|
92778
|
-
|
|
92779
|
-
|
|
92966
|
+
else {
|
|
92967
|
+
for (var _i = 0, _b = constructor.body.statements; _i < _b.length; _i++) {
|
|
92968
|
+
var statement = _b[_i];
|
|
92969
|
+
if (ts.isParameterPropertyDeclaration(ts.getOriginalNode(statement), constructor)) {
|
|
92970
|
+
parameterPropertyDeclarationCount++;
|
|
92971
|
+
}
|
|
92972
|
+
}
|
|
92973
|
+
if (parameterPropertyDeclarationCount > 0) {
|
|
92974
|
+
var parameterProperties = ts.visitNodes(constructor.body.statements, visitor, ts.isStatement, indexOfFirstStatementAfterSuper, parameterPropertyDeclarationCount);
|
|
92975
|
+
// If there was a super() call found, add parameter properties immediately after it
|
|
92976
|
+
if (superStatementIndex >= 0) {
|
|
92977
|
+
ts.addRange(statements, parameterProperties);
|
|
92978
|
+
}
|
|
92979
|
+
// If a synthetic super() call was added, add them just after it
|
|
92980
|
+
else if (needsSyntheticConstructor) {
|
|
92981
|
+
statements = __spreadArray(__spreadArray([
|
|
92982
|
+
statements[0]
|
|
92983
|
+
], parameterProperties, true), statements.slice(1), true);
|
|
92984
|
+
}
|
|
92985
|
+
// Since there wasn't a super() call, add them to the top of the constructor
|
|
92986
|
+
else {
|
|
92987
|
+
statements = __spreadArray(__spreadArray([], parameterProperties, true), statements, true);
|
|
92988
|
+
}
|
|
92989
|
+
indexOfFirstStatementAfterSuper += parameterPropertyDeclarationCount;
|
|
92780
92990
|
}
|
|
92781
|
-
indexOfFirstStatement = afterParameterProperties;
|
|
92782
92991
|
}
|
|
92783
92992
|
}
|
|
92784
92993
|
var receiver = factory.createThis();
|
|
92785
92994
|
// private methods can be called in property initializers, they should execute first.
|
|
92786
92995
|
addMethodStatements(statements, privateMethodsAndAccessors, receiver);
|
|
92787
92996
|
addPropertyOrClassStaticBlockStatements(statements, properties, receiver);
|
|
92788
|
-
// Add existing statements
|
|
92997
|
+
// Add existing statements after the initial prologues and super call
|
|
92789
92998
|
if (constructor) {
|
|
92790
|
-
ts.addRange(statements, ts.visitNodes(constructor.body.statements,
|
|
92999
|
+
ts.addRange(statements, ts.visitNodes(constructor.body.statements, visitBodyStatement, ts.isStatement, indexOfFirstStatementAfterSuper + prologueStatementCount));
|
|
92791
93000
|
}
|
|
92792
93001
|
statements = factory.mergeLexicalEnvironment(statements, endLexicalEnvironment());
|
|
92793
93002
|
return ts.setTextRange(factory.createBlock(ts.setTextRange(factory.createNodeArray(statements),
|
|
92794
93003
|
/*location*/ constructor ? constructor.body.statements : node.members),
|
|
92795
93004
|
/*multiLine*/ true),
|
|
92796
93005
|
/*location*/ constructor ? constructor.body : undefined);
|
|
93006
|
+
function visitBodyStatement(statement) {
|
|
93007
|
+
if (useDefineForClassFields && ts.isParameterPropertyDeclaration(ts.getOriginalNode(statement), constructor)) {
|
|
93008
|
+
return undefined;
|
|
93009
|
+
}
|
|
93010
|
+
return visitor(statement);
|
|
93011
|
+
}
|
|
92797
93012
|
}
|
|
92798
93013
|
/**
|
|
92799
93014
|
* Generates assignment statements for property initializers.
|
|
@@ -92814,6 +93029,11 @@ var ts;
|
|
|
92814
93029
|
ts.setSourceMapRange(statement, ts.moveRangePastModifiers(property));
|
|
92815
93030
|
ts.setCommentRange(statement, property);
|
|
92816
93031
|
ts.setOriginalNode(statement, property);
|
|
93032
|
+
// `setOriginalNode` *copies* the `emitNode` from `property`, so now both
|
|
93033
|
+
// `statement` and `expression` have a copy of the synthesized comments.
|
|
93034
|
+
// Drop the comments from expression to avoid printing them twice.
|
|
93035
|
+
ts.setSyntheticLeadingComments(expression, undefined);
|
|
93036
|
+
ts.setSyntheticTrailingComments(expression, undefined);
|
|
92817
93037
|
statements.push(statement);
|
|
92818
93038
|
}
|
|
92819
93039
|
}
|
|
@@ -96580,37 +96800,39 @@ var ts;
|
|
|
96580
96800
|
var prologue = [];
|
|
96581
96801
|
var statements = [];
|
|
96582
96802
|
resumeLexicalEnvironment();
|
|
96803
|
+
// In derived classes, there may be code before the necessary super() call
|
|
96804
|
+
// We'll remove pre-super statements to be tacked on after the rest of the body
|
|
96805
|
+
var existingPrologue = ts.takeWhile(constructor.body.statements, ts.isPrologueDirective);
|
|
96806
|
+
var _a = findSuperCallAndStatementIndex(constructor.body.statements, existingPrologue), superCall = _a.superCall, superStatementIndex = _a.superStatementIndex;
|
|
96807
|
+
var postSuperStatementsStart = superStatementIndex === -1 ? existingPrologue.length : superStatementIndex + 1;
|
|
96583
96808
|
// If a super call has already been synthesized,
|
|
96584
96809
|
// we're going to assume that we should just transform everything after that.
|
|
96585
96810
|
// The assumption is that no prior step in the pipeline has added any prologue directives.
|
|
96586
|
-
var statementOffset =
|
|
96811
|
+
var statementOffset = postSuperStatementsStart;
|
|
96587
96812
|
if (!hasSynthesizedSuper)
|
|
96588
|
-
statementOffset = factory.copyStandardPrologue(constructor.body.statements, prologue, /*ensureUseStrict*/ false);
|
|
96589
|
-
addDefaultValueAssignmentsIfNeeded(statements, constructor);
|
|
96590
|
-
addRestParameterIfNeeded(statements, constructor, hasSynthesizedSuper);
|
|
96813
|
+
statementOffset = factory.copyStandardPrologue(constructor.body.statements, prologue, statementOffset, /*ensureUseStrict*/ false);
|
|
96591
96814
|
if (!hasSynthesizedSuper)
|
|
96592
|
-
statementOffset = factory.copyCustomPrologue(constructor.body.statements, statements, statementOffset, visitor);
|
|
96593
|
-
// If
|
|
96815
|
+
statementOffset = factory.copyCustomPrologue(constructor.body.statements, statements, statementOffset, visitor, /*filter*/ undefined);
|
|
96816
|
+
// If there already exists a call to `super()`, visit the statement directly
|
|
96594
96817
|
var superCallExpression;
|
|
96595
96818
|
if (hasSynthesizedSuper) {
|
|
96596
96819
|
superCallExpression = createDefaultSuperCallOrThis();
|
|
96597
96820
|
}
|
|
96598
|
-
else if (
|
|
96599
|
-
|
|
96600
|
-
if (ts.isExpressionStatement(firstStatement) && ts.isSuperCall(firstStatement.expression)) {
|
|
96601
|
-
superCallExpression = visitImmediateSuperCallInBody(firstStatement.expression);
|
|
96602
|
-
}
|
|
96821
|
+
else if (superCall) {
|
|
96822
|
+
superCallExpression = visitSuperCallInBody(superCall);
|
|
96603
96823
|
}
|
|
96604
96824
|
if (superCallExpression) {
|
|
96605
96825
|
hierarchyFacts |= 8192 /* ConstructorWithCapturedSuper */;
|
|
96606
|
-
statementOffset++; // skip this statement, we will add it after visiting the rest of the body.
|
|
96607
96826
|
}
|
|
96827
|
+
// Add parameter defaults at the beginning of the output, with prologue statements
|
|
96828
|
+
addDefaultValueAssignmentsIfNeeded(prologue, constructor);
|
|
96829
|
+
addRestParameterIfNeeded(prologue, constructor, hasSynthesizedSuper);
|
|
96608
96830
|
// visit the remaining statements
|
|
96609
96831
|
ts.addRange(statements, ts.visitNodes(constructor.body.statements, visitor, ts.isStatement, /*start*/ statementOffset));
|
|
96610
96832
|
factory.mergeLexicalEnvironment(prologue, endLexicalEnvironment());
|
|
96611
96833
|
insertCaptureNewTargetIfNeeded(prologue, constructor, /*copyOnWrite*/ false);
|
|
96612
|
-
if (isDerivedClass) {
|
|
96613
|
-
if (superCallExpression &&
|
|
96834
|
+
if (isDerivedClass || superCallExpression) {
|
|
96835
|
+
if (superCallExpression && postSuperStatementsStart === constructor.body.statements.length && !(constructor.body.transformFlags & 8192 /* ContainsLexicalThis */)) {
|
|
96614
96836
|
// If the subclass constructor does *not* contain `this` and *ends* with a `super()` call, we will use the
|
|
96615
96837
|
// following representation:
|
|
96616
96838
|
//
|
|
@@ -96630,10 +96852,10 @@ var ts;
|
|
|
96630
96852
|
// return C;
|
|
96631
96853
|
// })(Base);
|
|
96632
96854
|
// ```
|
|
96633
|
-
var
|
|
96855
|
+
var superCall_1 = ts.cast(ts.cast(superCallExpression, ts.isBinaryExpression).left, ts.isCallExpression);
|
|
96634
96856
|
var returnStatement = factory.createReturnStatement(superCallExpression);
|
|
96635
|
-
ts.setCommentRange(returnStatement, ts.getCommentRange(
|
|
96636
|
-
ts.setEmitFlags(
|
|
96857
|
+
ts.setCommentRange(returnStatement, ts.getCommentRange(superCall_1));
|
|
96858
|
+
ts.setEmitFlags(superCall_1, 1536 /* NoComments */);
|
|
96637
96859
|
statements.push(returnStatement);
|
|
96638
96860
|
}
|
|
96639
96861
|
else {
|
|
@@ -96658,9 +96880,19 @@ var ts;
|
|
|
96658
96880
|
// return C;
|
|
96659
96881
|
// })(Base);
|
|
96660
96882
|
// ```
|
|
96661
|
-
//
|
|
96662
|
-
|
|
96663
|
-
|
|
96883
|
+
// If the super() call is the first statement, we can directly create and assign its result to `_this`
|
|
96884
|
+
if (superStatementIndex <= existingPrologue.length) {
|
|
96885
|
+
insertCaptureThisForNode(statements, constructor, superCallExpression || createActualThis());
|
|
96886
|
+
}
|
|
96887
|
+
// Since the `super()` call isn't the first statement, it's split across 1-2 statements:
|
|
96888
|
+
// * A prologue `var _this = this;`, in case the constructor accesses this before super()
|
|
96889
|
+
// * If it exists, a reassignment to that `_this` of the super() call
|
|
96890
|
+
else {
|
|
96891
|
+
insertCaptureThisForNode(prologue, constructor, createActualThis());
|
|
96892
|
+
if (superCallExpression) {
|
|
96893
|
+
insertSuperThisCaptureThisForNode(statements, superCallExpression);
|
|
96894
|
+
}
|
|
96895
|
+
}
|
|
96664
96896
|
if (!isSufficientlyCoveredByReturnStatements(constructor.body)) {
|
|
96665
96897
|
statements.push(factory.createReturnStatement(factory.createUniqueName("_this", 16 /* Optimistic */ | 32 /* FileLevel */)));
|
|
96666
96898
|
}
|
|
@@ -96683,11 +96915,27 @@ var ts;
|
|
|
96683
96915
|
// ```
|
|
96684
96916
|
insertCaptureThisForNodeIfNeeded(prologue, constructor);
|
|
96685
96917
|
}
|
|
96686
|
-
var
|
|
96918
|
+
var body = factory.createBlock(ts.setTextRange(factory.createNodeArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray([], existingPrologue, true), prologue, true), (superStatementIndex <= existingPrologue.length ? ts.emptyArray : ts.visitNodes(constructor.body.statements, visitor, ts.isStatement, existingPrologue.length, superStatementIndex)), true), statements, true)),
|
|
96687
96919
|
/*location*/ constructor.body.statements),
|
|
96688
96920
|
/*multiLine*/ true);
|
|
96689
|
-
ts.setTextRange(
|
|
96690
|
-
return
|
|
96921
|
+
ts.setTextRange(body, constructor.body);
|
|
96922
|
+
return body;
|
|
96923
|
+
}
|
|
96924
|
+
function findSuperCallAndStatementIndex(originalBodyStatements, existingPrologue) {
|
|
96925
|
+
for (var i = existingPrologue.length; i < originalBodyStatements.length; i += 1) {
|
|
96926
|
+
var superCall = ts.getSuperCallFromStatement(originalBodyStatements[i]);
|
|
96927
|
+
if (superCall) {
|
|
96928
|
+
// With a super() call, split the statements into pre-super() and 'body' (post-super())
|
|
96929
|
+
return {
|
|
96930
|
+
superCall: superCall,
|
|
96931
|
+
superStatementIndex: i,
|
|
96932
|
+
};
|
|
96933
|
+
}
|
|
96934
|
+
}
|
|
96935
|
+
// Since there was no super() call found, consider all statements to be in the main 'body' (post-super())
|
|
96936
|
+
return {
|
|
96937
|
+
superStatementIndex: -1,
|
|
96938
|
+
};
|
|
96691
96939
|
}
|
|
96692
96940
|
/**
|
|
96693
96941
|
* We want to try to avoid emitting a return statement in certain cases if a user already returned something.
|
|
@@ -96916,6 +97164,18 @@ var ts;
|
|
|
96916
97164
|
}
|
|
96917
97165
|
return false;
|
|
96918
97166
|
}
|
|
97167
|
+
/**
|
|
97168
|
+
* Assigns the `this` in a constructor to the result of its `super()` call.
|
|
97169
|
+
*
|
|
97170
|
+
* @param statements Statements in the constructor body.
|
|
97171
|
+
* @param superExpression Existing `super()` call for the constructor.
|
|
97172
|
+
*/
|
|
97173
|
+
function insertSuperThisCaptureThisForNode(statements, superExpression) {
|
|
97174
|
+
enableSubstitutionsForCapturedThis();
|
|
97175
|
+
var assignSuperExpression = factory.createExpressionStatement(factory.createBinaryExpression(factory.createThis(), 63 /* EqualsToken */, superExpression));
|
|
97176
|
+
ts.insertStatementAfterCustomPrologue(statements, assignSuperExpression);
|
|
97177
|
+
ts.setCommentRange(assignSuperExpression, ts.getOriginalNode(superExpression).parent);
|
|
97178
|
+
}
|
|
96919
97179
|
function insertCaptureThisForNode(statements, node, initializer) {
|
|
96920
97180
|
enableSubstitutionsForCapturedThis();
|
|
96921
97181
|
var captureThisStatement = factory.createVariableStatement(
|
|
@@ -97225,7 +97485,7 @@ var ts;
|
|
|
97225
97485
|
if (ts.isBlock(body)) {
|
|
97226
97486
|
// ensureUseStrict is false because no new prologue-directive should be added.
|
|
97227
97487
|
// addStandardPrologue will put already-existing directives at the beginning of the target statement-array
|
|
97228
|
-
statementOffset = factory.copyStandardPrologue(body.statements, prologue, /*ensureUseStrict*/ false);
|
|
97488
|
+
statementOffset = factory.copyStandardPrologue(body.statements, prologue, 0, /*ensureUseStrict*/ false);
|
|
97229
97489
|
statementOffset = factory.copyCustomPrologue(body.statements, statements, statementOffset, visitor, ts.isHoistedFunction);
|
|
97230
97490
|
statementOffset = factory.copyCustomPrologue(body.statements, statements, statementOffset, visitor, ts.isHoistedVariableStatement);
|
|
97231
97491
|
}
|
|
@@ -98596,7 +98856,7 @@ var ts;
|
|
|
98596
98856
|
/*type*/ undefined, factory.updateBlock(func.body, statements))),
|
|
98597
98857
|
/*typeArguments*/ undefined, call.arguments))));
|
|
98598
98858
|
}
|
|
98599
|
-
function
|
|
98859
|
+
function visitSuperCallInBody(node) {
|
|
98600
98860
|
return visitCallExpressionWithPotentialCapturedThisAssignment(node, /*assignToCapturedThis*/ false);
|
|
98601
98861
|
}
|
|
98602
98862
|
function visitCallExpressionWithPotentialCapturedThisAssignment(node, assignToCapturedThis) {
|
|
@@ -119154,28 +119414,37 @@ var ts;
|
|
|
119154
119414
|
useCaseSensitiveFileNames: (_a = host.useCaseSensitiveFileNames) === null || _a === void 0 ? void 0 : _a.call(host),
|
|
119155
119415
|
};
|
|
119156
119416
|
}
|
|
119157
|
-
|
|
119158
|
-
|
|
119417
|
+
// `importingSourceFile` and `importingSourceFileName`? Why not just use `importingSourceFile.path`?
|
|
119418
|
+
// Because when this is called by the file renamer, `importingSourceFile` is the file being renamed,
|
|
119419
|
+
// while `importingSourceFileName` its *new* name. We need a source file just to get its
|
|
119420
|
+
// `impliedNodeFormat` and to detect certain preferences from existing import module specifiers.
|
|
119421
|
+
function updateModuleSpecifier(compilerOptions, importingSourceFile, importingSourceFileName, toFileName, host, oldImportSpecifier) {
|
|
119422
|
+
var res = getModuleSpecifierWorker(compilerOptions, importingSourceFile, importingSourceFileName, toFileName, host, getPreferencesForUpdate(compilerOptions, oldImportSpecifier, importingSourceFileName, host), {});
|
|
119159
119423
|
if (res === oldImportSpecifier)
|
|
119160
119424
|
return undefined;
|
|
119161
119425
|
return res;
|
|
119162
119426
|
}
|
|
119163
119427
|
moduleSpecifiers_1.updateModuleSpecifier = updateModuleSpecifier;
|
|
119164
|
-
//
|
|
119428
|
+
// `importingSourceFile` and `importingSourceFileName`? Why not just use `importingSourceFile.path`?
|
|
119429
|
+
// Because when this is called by the declaration emitter, `importingSourceFile` is the implementation
|
|
119430
|
+
// file, but `importingSourceFileName` and `toFileName` refer to declaration files (the former to the
|
|
119431
|
+
// one currently being produced; the latter to the one being imported). We need an implementation file
|
|
119432
|
+
// just to get its `impliedNodeFormat` and to detect certain preferences from existing import module
|
|
119433
|
+
// specifiers.
|
|
119165
119434
|
function getModuleSpecifier(compilerOptions, importingSourceFile, importingSourceFileName, toFileName, host) {
|
|
119166
|
-
return getModuleSpecifierWorker(compilerOptions, importingSourceFileName, toFileName, host, getPreferences(host, {}, compilerOptions, importingSourceFile), {});
|
|
119435
|
+
return getModuleSpecifierWorker(compilerOptions, importingSourceFile, importingSourceFileName, toFileName, host, getPreferences(host, {}, compilerOptions, importingSourceFile), {});
|
|
119167
119436
|
}
|
|
119168
119437
|
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); });
|
|
119438
|
+
function getNodeModulesPackageName(compilerOptions, importingSourceFile, nodeModulesFileName, host, preferences) {
|
|
119439
|
+
var info = getInfo(importingSourceFile.path, host);
|
|
119440
|
+
var modulePaths = getAllModulePaths(importingSourceFile.path, nodeModulesFileName, host, preferences);
|
|
119441
|
+
return ts.firstDefined(modulePaths, function (modulePath) { return tryGetModuleNameAsNodeModule(modulePath, info, importingSourceFile, host, compilerOptions, /*packageNameOnly*/ true); });
|
|
119173
119442
|
}
|
|
119174
119443
|
moduleSpecifiers_1.getNodeModulesPackageName = getNodeModulesPackageName;
|
|
119175
|
-
function getModuleSpecifierWorker(compilerOptions, importingSourceFileName, toFileName, host, preferences, userPreferences) {
|
|
119444
|
+
function getModuleSpecifierWorker(compilerOptions, importingSourceFile, importingSourceFileName, toFileName, host, preferences, userPreferences) {
|
|
119176
119445
|
var info = getInfo(importingSourceFileName, host);
|
|
119177
119446
|
var modulePaths = getAllModulePaths(importingSourceFileName, toFileName, host, userPreferences);
|
|
119178
|
-
return ts.firstDefined(modulePaths, function (modulePath) { return tryGetModuleNameAsNodeModule(modulePath, info, host, compilerOptions); }) ||
|
|
119447
|
+
return ts.firstDefined(modulePaths, function (modulePath) { return tryGetModuleNameAsNodeModule(modulePath, info, importingSourceFile, host, compilerOptions); }) ||
|
|
119179
119448
|
getLocalModuleSpecifier(toFileName, info, compilerOptions, host, preferences);
|
|
119180
119449
|
}
|
|
119181
119450
|
function tryGetModuleSpecifiersFromCache(moduleSymbol, importingSourceFile, host, userPreferences) {
|
|
@@ -119242,7 +119511,7 @@ var ts;
|
|
|
119242
119511
|
var relativeSpecifiers;
|
|
119243
119512
|
for (var _i = 0, modulePaths_1 = modulePaths; _i < modulePaths_1.length; _i++) {
|
|
119244
119513
|
var modulePath = modulePaths_1[_i];
|
|
119245
|
-
var specifier = tryGetModuleNameAsNodeModule(modulePath, info, host, compilerOptions);
|
|
119514
|
+
var specifier = tryGetModuleNameAsNodeModule(modulePath, info, importingSourceFile, host, compilerOptions);
|
|
119246
119515
|
nodeModulesSpecifiers = ts.append(nodeModulesSpecifiers, specifier);
|
|
119247
119516
|
if (specifier && modulePath.isRedirect) {
|
|
119248
119517
|
// If we got a specifier for a redirect, it was a bare package specifier (e.g. "@foo/bar",
|
|
@@ -119634,7 +119903,7 @@ var ts;
|
|
|
119634
119903
|
? removeExtensionAndIndexPostFix(relativePath, ending, compilerOptions)
|
|
119635
119904
|
: ts.removeFileExtension(relativePath);
|
|
119636
119905
|
}
|
|
119637
|
-
function tryGetModuleNameAsNodeModule(_a, _b, host, options, packageNameOnly) {
|
|
119906
|
+
function tryGetModuleNameAsNodeModule(_a, _b, importingSourceFile, host, options, packageNameOnly) {
|
|
119638
119907
|
var path = _a.path, isRedirect = _a.isRedirect;
|
|
119639
119908
|
var getCanonicalFileName = _b.getCanonicalFileName, sourceDirectory = _b.sourceDirectory;
|
|
119640
119909
|
if (!host.fileExists || !host.readFile) {
|
|
@@ -119697,11 +119966,19 @@ var ts;
|
|
|
119697
119966
|
var moduleFileToTry = path;
|
|
119698
119967
|
if (host.fileExists(packageJsonPath)) {
|
|
119699
119968
|
var packageJsonContent = JSON.parse(host.readFile(packageJsonPath));
|
|
119700
|
-
// TODO: Inject `require` or `import` condition based on the intended import mode
|
|
119701
119969
|
if (ts.getEmitModuleResolutionKind(options) === ts.ModuleResolutionKind.Node12 || ts.getEmitModuleResolutionKind(options) === ts.ModuleResolutionKind.NodeNext) {
|
|
119702
|
-
|
|
119970
|
+
// `conditions` *could* be made to go against `importingSourceFile.impliedNodeFormat` if something wanted to generate
|
|
119971
|
+
// an ImportEqualsDeclaration in an ESM-implied file or an ImportCall in a CJS-implied file. But since this function is
|
|
119972
|
+
// usually called to conjure an import out of thin air, we don't have an existing usage to call `getModeForUsageAtIndex`
|
|
119973
|
+
// with, so for now we just stick with the mode of the file.
|
|
119974
|
+
var conditions = ["node", importingSourceFile.impliedNodeFormat === ts.ModuleKind.ESNext ? "import" : "require", "types"];
|
|
119975
|
+
var fromExports = packageJsonContent.exports && typeof packageJsonContent.name === "string"
|
|
119976
|
+
? tryGetModuleNameFromExports(options, path, packageRootPath, ts.getPackageNameFromTypesPackageName(packageJsonContent.name), packageJsonContent.exports, conditions)
|
|
119977
|
+
: undefined;
|
|
119703
119978
|
if (fromExports) {
|
|
119704
|
-
var withJsExtension = !ts.hasTSFileExtension(fromExports.moduleFileToTry)
|
|
119979
|
+
var withJsExtension = !ts.hasTSFileExtension(fromExports.moduleFileToTry)
|
|
119980
|
+
? fromExports
|
|
119981
|
+
: { moduleFileToTry: ts.removeFileExtension(fromExports.moduleFileToTry) + tryGetJSExtensionForFile(fromExports.moduleFileToTry, options) };
|
|
119705
119982
|
return __assign(__assign({}, withJsExtension), { verbatimFromExports: true });
|
|
119706
119983
|
}
|
|
119707
119984
|
if (packageJsonContent.exports) {
|
|
@@ -119807,8 +120084,8 @@ var ts;
|
|
|
119807
120084
|
}
|
|
119808
120085
|
function getPathRelativeToRootDirs(path, rootDirs, getCanonicalFileName) {
|
|
119809
120086
|
return ts.firstDefined(rootDirs, function (rootDir) {
|
|
119810
|
-
var relativePath = getRelativePathIfInDirectory(path, rootDir, getCanonicalFileName);
|
|
119811
|
-
return isPathRelativeToParent(relativePath) ? undefined : relativePath;
|
|
120087
|
+
var relativePath = getRelativePathIfInDirectory(path, rootDir, getCanonicalFileName);
|
|
120088
|
+
return relativePath !== undefined && isPathRelativeToParent(relativePath) ? undefined : relativePath;
|
|
119812
120089
|
});
|
|
119813
120090
|
}
|
|
119814
120091
|
function removeExtensionAndIndexPostFix(fileName, ending, options) {
|
|
@@ -126020,7 +126297,7 @@ var ts;
|
|
|
126020
126297
|
if (!ts.stringContains(importedFileName, "node_modules")) {
|
|
126021
126298
|
return undefined;
|
|
126022
126299
|
}
|
|
126023
|
-
var specifier = ts.moduleSpecifiers.getNodeModulesPackageName(host.getCompilationSettings(), fromFile
|
|
126300
|
+
var specifier = ts.moduleSpecifiers.getNodeModulesPackageName(host.getCompilationSettings(), fromFile, importedFileName, moduleSpecifierResolutionHost, preferences);
|
|
126024
126301
|
if (!specifier) {
|
|
126025
126302
|
return undefined;
|
|
126026
126303
|
}
|
|
@@ -128836,7 +129113,7 @@ var ts;
|
|
|
128836
129113
|
return (location === null || location === void 0 ? void 0 : location.kind) === 79 /* Identifier */ ? ts.createTextSpanFromNode(location) : undefined;
|
|
128837
129114
|
}
|
|
128838
129115
|
function completionInfoFromData(sourceFile, host, program, compilerOptions, log, completionData, preferences, formatContext) {
|
|
128839
|
-
var symbols = completionData.symbols, contextToken = completionData.contextToken, completionKind = completionData.completionKind, isInSnippetScope = completionData.isInSnippetScope, isNewIdentifierLocation = completionData.isNewIdentifierLocation, location = completionData.location, propertyAccessToConvert = completionData.propertyAccessToConvert, keywordFilters = completionData.keywordFilters, literals = completionData.literals, symbolToOriginInfoMap = completionData.symbolToOriginInfoMap, recommendedCompletion = completionData.recommendedCompletion, isJsxInitializer = completionData.isJsxInitializer, isTypeOnlyLocation = completionData.isTypeOnlyLocation, isJsxIdentifierExpected = completionData.isJsxIdentifierExpected, importCompletionNode = completionData.importCompletionNode, insideJsDocTagTypeExpression = completionData.insideJsDocTagTypeExpression, symbolToSortTextIdMap = completionData.symbolToSortTextIdMap, hasUnresolvedAutoImports = completionData.hasUnresolvedAutoImports;
|
|
129116
|
+
var symbols = completionData.symbols, contextToken = completionData.contextToken, completionKind = completionData.completionKind, isInSnippetScope = completionData.isInSnippetScope, isNewIdentifierLocation = completionData.isNewIdentifierLocation, location = completionData.location, propertyAccessToConvert = completionData.propertyAccessToConvert, keywordFilters = completionData.keywordFilters, literals = completionData.literals, symbolToOriginInfoMap = completionData.symbolToOriginInfoMap, recommendedCompletion = completionData.recommendedCompletion, isJsxInitializer = completionData.isJsxInitializer, isTypeOnlyLocation = completionData.isTypeOnlyLocation, isJsxIdentifierExpected = completionData.isJsxIdentifierExpected, isRightOfOpenTag = completionData.isRightOfOpenTag, importCompletionNode = completionData.importCompletionNode, insideJsDocTagTypeExpression = completionData.insideJsDocTagTypeExpression, symbolToSortTextIdMap = completionData.symbolToSortTextIdMap, hasUnresolvedAutoImports = completionData.hasUnresolvedAutoImports;
|
|
128840
129117
|
// Verify if the file is JSX language variant
|
|
128841
129118
|
if (ts.getLanguageVariant(sourceFile.scriptKind) === 1 /* JSX */) {
|
|
128842
129119
|
var completionInfo = getJsxClosingTagCompletion(location, sourceFile);
|
|
@@ -128847,7 +129124,7 @@ var ts;
|
|
|
128847
129124
|
var entries = ts.createSortedArray();
|
|
128848
129125
|
if (isUncheckedFile(sourceFile, compilerOptions)) {
|
|
128849
129126
|
var uniqueNames = getCompletionEntriesFromSymbols(symbols, entries,
|
|
128850
|
-
/*replacementToken*/ undefined, contextToken, location, sourceFile, host, program, ts.getEmitScriptTarget(compilerOptions), log, completionKind, preferences, compilerOptions, formatContext, isTypeOnlyLocation, propertyAccessToConvert, isJsxIdentifierExpected, isJsxInitializer, importCompletionNode, recommendedCompletion, symbolToOriginInfoMap, symbolToSortTextIdMap);
|
|
129127
|
+
/*replacementToken*/ undefined, contextToken, location, sourceFile, host, program, ts.getEmitScriptTarget(compilerOptions), log, completionKind, preferences, compilerOptions, formatContext, isTypeOnlyLocation, propertyAccessToConvert, isJsxIdentifierExpected, isJsxInitializer, importCompletionNode, recommendedCompletion, symbolToOriginInfoMap, symbolToSortTextIdMap, isJsxIdentifierExpected, isRightOfOpenTag);
|
|
128851
129128
|
getJSCompletionEntries(sourceFile, location.pos, uniqueNames, ts.getEmitScriptTarget(compilerOptions), entries); // TODO: GH#18217
|
|
128852
129129
|
}
|
|
128853
129130
|
else {
|
|
@@ -128855,7 +129132,7 @@ var ts;
|
|
|
128855
129132
|
return undefined;
|
|
128856
129133
|
}
|
|
128857
129134
|
getCompletionEntriesFromSymbols(symbols, entries,
|
|
128858
|
-
/*replacementToken*/ undefined, contextToken, location, sourceFile, host, program, ts.getEmitScriptTarget(compilerOptions), log, completionKind, preferences, compilerOptions, formatContext, isTypeOnlyLocation, propertyAccessToConvert, isJsxIdentifierExpected, isJsxInitializer, importCompletionNode, recommendedCompletion, symbolToOriginInfoMap, symbolToSortTextIdMap);
|
|
129135
|
+
/*replacementToken*/ undefined, contextToken, location, sourceFile, host, program, ts.getEmitScriptTarget(compilerOptions), log, completionKind, preferences, compilerOptions, formatContext, isTypeOnlyLocation, propertyAccessToConvert, isJsxIdentifierExpected, isJsxInitializer, importCompletionNode, recommendedCompletion, symbolToOriginInfoMap, symbolToSortTextIdMap, isJsxIdentifierExpected, isRightOfOpenTag);
|
|
128859
129136
|
}
|
|
128860
129137
|
if (keywordFilters !== 0 /* None */) {
|
|
128861
129138
|
var entryNames = new ts.Set(entries.map(function (e) { return e.name; }));
|
|
@@ -128961,7 +129238,7 @@ var ts;
|
|
|
128961
129238
|
function createCompletionEntryForLiteral(sourceFile, preferences, literal) {
|
|
128962
129239
|
return { name: completionNameForLiteral(sourceFile, preferences, literal), kind: "string" /* string */, kindModifiers: "" /* none */, sortText: SortText.LocationPriority };
|
|
128963
129240
|
}
|
|
128964
|
-
function createCompletionEntry(symbol, sortText, replacementToken, contextToken, location, sourceFile, host, program, name, needsConvertPropertyAccess, origin, recommendedCompletion, propertyAccessToConvert, isJsxInitializer, importCompletionNode, useSemicolons, options, preferences, completionKind, formatContext) {
|
|
129241
|
+
function createCompletionEntry(symbol, sortText, replacementToken, contextToken, location, sourceFile, host, program, name, needsConvertPropertyAccess, origin, recommendedCompletion, propertyAccessToConvert, isJsxInitializer, importCompletionNode, useSemicolons, options, preferences, completionKind, formatContext, isJsxIdentifierExpected, isRightOfOpenTag) {
|
|
128965
129242
|
var _a, _b;
|
|
128966
129243
|
var insertText;
|
|
128967
129244
|
var replacementSpan = ts.getReplacementSpanForContextToken(replacementToken);
|
|
@@ -129032,8 +129309,7 @@ var ts;
|
|
|
129032
129309
|
source = CompletionSource.ClassMemberSnippet;
|
|
129033
129310
|
}
|
|
129034
129311
|
}
|
|
129035
|
-
|
|
129036
|
-
if (kind === "JSX attribute" /* jsxAttribute */ && preferences.includeCompletionsWithSnippetText && preferences.jsxAttributeCompletionStyle && preferences.jsxAttributeCompletionStyle !== "none") {
|
|
129312
|
+
if (isJsxIdentifierExpected && !isRightOfOpenTag && preferences.includeCompletionsWithSnippetText && preferences.jsxAttributeCompletionStyle && preferences.jsxAttributeCompletionStyle !== "none") {
|
|
129037
129313
|
var useBraces_1 = preferences.jsxAttributeCompletionStyle === "braces";
|
|
129038
129314
|
var type = typeChecker.getTypeOfSymbolAtLocation(symbol, location);
|
|
129039
129315
|
// If is boolean like or undefined, don't return a snippet we want just to return the completion.
|
|
@@ -129071,7 +129347,7 @@ var ts;
|
|
|
129071
129347
|
// entries (like JavaScript identifier entries).
|
|
129072
129348
|
return {
|
|
129073
129349
|
name: name,
|
|
129074
|
-
kind:
|
|
129350
|
+
kind: ts.SymbolDisplay.getSymbolKind(typeChecker, symbol, location),
|
|
129075
129351
|
kindModifiers: ts.SymbolDisplay.getSymbolModifiers(typeChecker, symbol),
|
|
129076
129352
|
sortText: sortText,
|
|
129077
129353
|
source: source,
|
|
@@ -129367,7 +129643,7 @@ var ts;
|
|
|
129367
129643
|
return CompletionSource.ThisProperty;
|
|
129368
129644
|
}
|
|
129369
129645
|
}
|
|
129370
|
-
function getCompletionEntriesFromSymbols(symbols, entries, replacementToken, contextToken, location, sourceFile, host, program, target, log, kind, preferences, compilerOptions, formatContext, isTypeOnlyLocation, propertyAccessToConvert, jsxIdentifierExpected, isJsxInitializer, importCompletionNode, recommendedCompletion, symbolToOriginInfoMap, symbolToSortTextIdMap) {
|
|
129646
|
+
function getCompletionEntriesFromSymbols(symbols, entries, replacementToken, contextToken, location, sourceFile, host, program, target, log, kind, preferences, compilerOptions, formatContext, isTypeOnlyLocation, propertyAccessToConvert, jsxIdentifierExpected, isJsxInitializer, importCompletionNode, recommendedCompletion, symbolToOriginInfoMap, symbolToSortTextIdMap, isJsxIdentifierExpected, isRightOfOpenTag) {
|
|
129371
129647
|
var _a;
|
|
129372
129648
|
var start = ts.timestamp();
|
|
129373
129649
|
var variableDeclaration = getVariableDeclaration(location);
|
|
@@ -129388,7 +129664,7 @@ var ts;
|
|
|
129388
129664
|
var name = info.name, needsConvertPropertyAccess = info.needsConvertPropertyAccess;
|
|
129389
129665
|
var sortTextId = (_a = symbolToSortTextIdMap === null || symbolToSortTextIdMap === void 0 ? void 0 : symbolToSortTextIdMap[ts.getSymbolId(symbol)]) !== null && _a !== void 0 ? _a : 11 /* LocationPriority */;
|
|
129390
129666
|
var sortText = (isDeprecated(symbol, typeChecker) ? 8 /* DeprecatedOffset */ + sortTextId : sortTextId).toString();
|
|
129391
|
-
var entry = createCompletionEntry(symbol, sortText, replacementToken, contextToken, location, sourceFile, host, program, name, needsConvertPropertyAccess, origin, recommendedCompletion, propertyAccessToConvert, isJsxInitializer, importCompletionNode, useSemicolons, compilerOptions, preferences, kind, formatContext);
|
|
129667
|
+
var entry = createCompletionEntry(symbol, sortText, replacementToken, contextToken, location, sourceFile, host, program, name, needsConvertPropertyAccess, origin, recommendedCompletion, propertyAccessToConvert, isJsxInitializer, importCompletionNode, useSemicolons, compilerOptions, preferences, kind, formatContext, isJsxIdentifierExpected, isRightOfOpenTag);
|
|
129392
129668
|
if (!entry) {
|
|
129393
129669
|
continue;
|
|
129394
129670
|
}
|
|
@@ -129982,6 +130258,7 @@ var ts;
|
|
|
129982
130258
|
symbolToSortTextIdMap: symbolToSortTextIdMap,
|
|
129983
130259
|
isTypeOnlyLocation: isTypeOnlyLocation,
|
|
129984
130260
|
isJsxIdentifierExpected: isJsxIdentifierExpected,
|
|
130261
|
+
isRightOfOpenTag: isRightOfOpenTag,
|
|
129985
130262
|
importCompletionNode: importCompletionNode,
|
|
129986
130263
|
hasUnresolvedAutoImports: hasUnresolvedAutoImports,
|
|
129987
130264
|
};
|
|
@@ -135666,7 +135943,7 @@ var ts;
|
|
|
135666
135943
|
: getSourceFileToImport(importedModuleSymbol, importLiteral, sourceFile, program, host, oldToNew);
|
|
135667
135944
|
// Need an update if the imported file moved, or the importing file moved and was using a relative path.
|
|
135668
135945
|
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)
|
|
135946
|
+
? ts.moduleSpecifiers.updateModuleSpecifier(program.getCompilerOptions(), sourceFile, getCanonicalFileName(newImportFromPath), toImport.newFileName, ts.createModuleSpecifierResolutionHost(program, host), importLiteral.text)
|
|
135670
135947
|
: undefined;
|
|
135671
135948
|
});
|
|
135672
135949
|
};
|
|
@@ -137311,6 +137588,9 @@ var ts;
|
|
|
137311
137588
|
// We use 1 NavNode to represent 'A.B.C', but there are multiple source nodes.
|
|
137312
137589
|
// Only merge module nodes that have the same chain. Don't merge 'A.B.C' with 'A'!
|
|
137313
137590
|
function areSameModule(a, b) {
|
|
137591
|
+
if (!a.body || !b.body) {
|
|
137592
|
+
return a.body === b.body;
|
|
137593
|
+
}
|
|
137314
137594
|
return a.body.kind === b.body.kind && (a.body.kind !== 260 /* ModuleDeclaration */ || areSameModule(a.body, b.body));
|
|
137315
137595
|
}
|
|
137316
137596
|
/** Merge source into target. Source should be thrown away after this is called. */
|
|
@@ -146088,20 +146368,31 @@ var ts;
|
|
|
146088
146368
|
codefix.registerCodeFix({
|
|
146089
146369
|
errorCodes: errorCodes,
|
|
146090
146370
|
getCodeActions: function getCodeActionsToAddConvertToUnknownForNonOverlappingTypes(context) {
|
|
146091
|
-
var
|
|
146371
|
+
var assertion = getAssertion(context.sourceFile, context.span.start);
|
|
146372
|
+
if (assertion === undefined)
|
|
146373
|
+
return undefined;
|
|
146374
|
+
var changes = ts.textChanges.ChangeTracker.with(context, function (t) { return makeChange(t, context.sourceFile, assertion); });
|
|
146092
146375
|
return [codefix.createCodeFixAction(fixId, changes, ts.Diagnostics.Add_unknown_conversion_for_non_overlapping_types, fixId, ts.Diagnostics.Add_unknown_to_all_conversions_of_non_overlapping_types)];
|
|
146093
146376
|
},
|
|
146094
146377
|
fixIds: [fixId],
|
|
146095
|
-
getAllCodeActions: function (context) { return codefix.codeFixAll(context, errorCodes, function (changes, diag) {
|
|
146378
|
+
getAllCodeActions: function (context) { return codefix.codeFixAll(context, errorCodes, function (changes, diag) {
|
|
146379
|
+
var assertion = getAssertion(diag.file, diag.start);
|
|
146380
|
+
if (assertion) {
|
|
146381
|
+
makeChange(changes, diag.file, assertion);
|
|
146382
|
+
}
|
|
146383
|
+
}); },
|
|
146096
146384
|
});
|
|
146097
|
-
function makeChange(changeTracker, sourceFile,
|
|
146098
|
-
var token = ts.getTokenAtPosition(sourceFile, pos);
|
|
146099
|
-
var assertion = ts.Debug.checkDefined(ts.findAncestor(token, function (n) { return ts.isAsExpression(n) || ts.isTypeAssertionExpression(n); }), "Expected to find an assertion expression");
|
|
146385
|
+
function makeChange(changeTracker, sourceFile, assertion) {
|
|
146100
146386
|
var replacement = ts.isAsExpression(assertion)
|
|
146101
146387
|
? ts.factory.createAsExpression(assertion.expression, ts.factory.createKeywordTypeNode(154 /* UnknownKeyword */))
|
|
146102
146388
|
: ts.factory.createTypeAssertion(ts.factory.createKeywordTypeNode(154 /* UnknownKeyword */), assertion.expression);
|
|
146103
146389
|
changeTracker.replaceNode(sourceFile, assertion.expression, replacement);
|
|
146104
146390
|
}
|
|
146391
|
+
function getAssertion(sourceFile, pos) {
|
|
146392
|
+
if (ts.isInJSFile(sourceFile))
|
|
146393
|
+
return undefined;
|
|
146394
|
+
return ts.findAncestor(ts.getTokenAtPosition(sourceFile, pos), function (n) { return ts.isAsExpression(n) || ts.isTypeAssertionExpression(n); });
|
|
146395
|
+
}
|
|
146105
146396
|
})(codefix = ts.codefix || (ts.codefix = {}));
|
|
146106
146397
|
})(ts || (ts = {}));
|
|
146107
146398
|
/* @internal */
|
|
@@ -149219,10 +149510,15 @@ var ts;
|
|
|
149219
149510
|
if (a.kind !== 0 /* UseNamespace */ && b.kind !== 0 /* UseNamespace */) {
|
|
149220
149511
|
return ts.compareBooleans(allowsImportingSpecifier(b.moduleSpecifier), allowsImportingSpecifier(a.moduleSpecifier))
|
|
149221
149512
|
|| compareNodeCoreModuleSpecifiers(a.moduleSpecifier, b.moduleSpecifier, importingFile, program)
|
|
149513
|
+
|| ts.compareBooleans(isOnlyDotsAndSlashes(a.moduleSpecifier), isOnlyDotsAndSlashes(b.moduleSpecifier))
|
|
149222
149514
|
|| ts.compareNumberOfDirectorySeparators(a.moduleSpecifier, b.moduleSpecifier);
|
|
149223
149515
|
}
|
|
149224
149516
|
return 0 /* EqualTo */;
|
|
149225
149517
|
}
|
|
149518
|
+
var notDotOrSlashPattern = /[^.\/]/;
|
|
149519
|
+
function isOnlyDotsAndSlashes(path) {
|
|
149520
|
+
return !notDotOrSlashPattern.test(path);
|
|
149521
|
+
}
|
|
149226
149522
|
function compareNodeCoreModuleSpecifiers(a, b, importingFile, program) {
|
|
149227
149523
|
if (ts.startsWith(a, "node:") && !ts.startsWith(b, "node:"))
|
|
149228
149524
|
return ts.shouldUseUriStyleNodeCoreModules(importingFile, program) ? -1 /* LessThan */ : 1 /* GreaterThan */;
|
|
@@ -154525,7 +154821,7 @@ var ts;
|
|
|
154525
154821
|
defaultToNamedAction.kind,
|
|
154526
154822
|
namedToDefaultAction.kind
|
|
154527
154823
|
],
|
|
154528
|
-
getAvailableActions: function (context) {
|
|
154824
|
+
getAvailableActions: function getRefactorActionsToConvertBetweenNamedAndDefaultExports(context) {
|
|
154529
154825
|
var info = getInfo(context, context.triggerReason === "invoked");
|
|
154530
154826
|
if (!info)
|
|
154531
154827
|
return ts.emptyArray;
|
|
@@ -154543,7 +154839,7 @@ var ts;
|
|
|
154543
154839
|
}
|
|
154544
154840
|
return ts.emptyArray;
|
|
154545
154841
|
},
|
|
154546
|
-
getEditsForAction: function (context, actionName) {
|
|
154842
|
+
getEditsForAction: function getRefactorEditsToConvertBetweenNamedAndDefaultExports(context, actionName) {
|
|
154547
154843
|
ts.Debug.assert(actionName === defaultToNamedAction.name || actionName === namedToDefaultAction.name, "Unexpected action name");
|
|
154548
154844
|
var info = getInfo(context);
|
|
154549
154845
|
ts.Debug.assert(info && !refactor.isRefactorErrorInfo(info), "Expected applicable refactor info");
|
|
@@ -154771,7 +155067,7 @@ var ts;
|
|
|
154771
155067
|
namespaceToNamedAction.kind,
|
|
154772
155068
|
namedToNamespaceAction.kind
|
|
154773
155069
|
],
|
|
154774
|
-
getAvailableActions: function (context) {
|
|
155070
|
+
getAvailableActions: function getRefactorActionsToConvertBetweenNamedAndNamespacedImports(context) {
|
|
154775
155071
|
var info = getImportToConvert(context, context.triggerReason === "invoked");
|
|
154776
155072
|
if (!info)
|
|
154777
155073
|
return ts.emptyArray;
|
|
@@ -154790,7 +155086,7 @@ var ts;
|
|
|
154790
155086
|
}
|
|
154791
155087
|
return ts.emptyArray;
|
|
154792
155088
|
},
|
|
154793
|
-
getEditsForAction: function (context, actionName) {
|
|
155089
|
+
getEditsForAction: function getRefactorEditsToConvertBetweenNamedAndNamespacedImports(context, actionName) {
|
|
154794
155090
|
ts.Debug.assert(actionName === namespaceToNamedAction.name || actionName === namedToNamespaceAction.name, "Unexpected action name");
|
|
154795
155091
|
var info = getImportToConvert(context);
|
|
154796
155092
|
ts.Debug.assert(info && !refactor.isRefactorErrorInfo(info), "Expected applicable refactor info");
|
|
@@ -154956,10 +155252,10 @@ var ts;
|
|
|
154956
155252
|
};
|
|
154957
155253
|
refactor.registerRefactor(refactorName, {
|
|
154958
155254
|
kinds: [toOptionalChainAction.kind],
|
|
154959
|
-
|
|
154960
|
-
|
|
155255
|
+
getEditsForAction: getRefactorEditsToConvertToOptionalChain,
|
|
155256
|
+
getAvailableActions: getRefactorActionsToConvertToOptionalChain,
|
|
154961
155257
|
});
|
|
154962
|
-
function
|
|
155258
|
+
function getRefactorActionsToConvertToOptionalChain(context) {
|
|
154963
155259
|
var info = getInfo(context, context.triggerReason === "invoked");
|
|
154964
155260
|
if (!info)
|
|
154965
155261
|
return ts.emptyArray;
|
|
@@ -154979,7 +155275,7 @@ var ts;
|
|
|
154979
155275
|
}
|
|
154980
155276
|
return ts.emptyArray;
|
|
154981
155277
|
}
|
|
154982
|
-
function
|
|
155278
|
+
function getRefactorEditsToConvertToOptionalChain(context, actionName) {
|
|
154983
155279
|
var info = getInfo(context);
|
|
154984
155280
|
ts.Debug.assert(info && !refactor.isRefactorErrorInfo(info), "Expected applicable refactor info");
|
|
154985
155281
|
var edits = ts.textChanges.ChangeTracker.with(context, function (t) {
|
|
@@ -155222,10 +155518,10 @@ var ts;
|
|
|
155222
155518
|
};
|
|
155223
155519
|
refactor.registerRefactor(refactorName, {
|
|
155224
155520
|
kinds: [functionOverloadAction.kind],
|
|
155225
|
-
getEditsForAction:
|
|
155226
|
-
getAvailableActions:
|
|
155521
|
+
getEditsForAction: getRefactorEditsToConvertOverloadsToOneSignature,
|
|
155522
|
+
getAvailableActions: getRefactorActionsToConvertOverloadsToOneSignature
|
|
155227
155523
|
});
|
|
155228
|
-
function
|
|
155524
|
+
function getRefactorActionsToConvertOverloadsToOneSignature(context) {
|
|
155229
155525
|
var file = context.file, startPosition = context.startPosition, program = context.program;
|
|
155230
155526
|
var info = getConvertableOverloadListAtPosition(file, startPosition, program);
|
|
155231
155527
|
if (!info)
|
|
@@ -155236,7 +155532,7 @@ var ts;
|
|
|
155236
155532
|
actions: [functionOverloadAction]
|
|
155237
155533
|
}];
|
|
155238
155534
|
}
|
|
155239
|
-
function
|
|
155535
|
+
function getRefactorEditsToConvertOverloadsToOneSignature(context) {
|
|
155240
155536
|
var file = context.file, startPosition = context.startPosition, program = context.program;
|
|
155241
155537
|
var signatureDecls = getConvertableOverloadListAtPosition(file, startPosition, program);
|
|
155242
155538
|
if (!signatureDecls)
|
|
@@ -155392,14 +155688,14 @@ var ts;
|
|
|
155392
155688
|
extractConstantAction.kind,
|
|
155393
155689
|
extractFunctionAction.kind
|
|
155394
155690
|
],
|
|
155395
|
-
|
|
155396
|
-
|
|
155691
|
+
getEditsForAction: getRefactorEditsToExtractSymbol,
|
|
155692
|
+
getAvailableActions: getRefactorActionsToExtractSymbol,
|
|
155397
155693
|
});
|
|
155398
155694
|
/**
|
|
155399
155695
|
* Compute the associated code actions
|
|
155400
155696
|
* Exported for tests.
|
|
155401
155697
|
*/
|
|
155402
|
-
function
|
|
155698
|
+
function getRefactorActionsToExtractSymbol(context) {
|
|
155403
155699
|
var requestedRefactor = context.kind;
|
|
155404
155700
|
var rangeToExtract = getRangeToExtract(context.file, ts.getRefactorContextSpan(context), context.triggerReason === "invoked");
|
|
155405
155701
|
var targetRange = rangeToExtract.targetRange;
|
|
@@ -155528,9 +155824,9 @@ var ts;
|
|
|
155528
155824
|
return error;
|
|
155529
155825
|
}
|
|
155530
155826
|
}
|
|
155531
|
-
extractSymbol.
|
|
155827
|
+
extractSymbol.getRefactorActionsToExtractSymbol = getRefactorActionsToExtractSymbol;
|
|
155532
155828
|
/* Exported for tests */
|
|
155533
|
-
function
|
|
155829
|
+
function getRefactorEditsToExtractSymbol(context, actionName) {
|
|
155534
155830
|
var rangeToExtract = getRangeToExtract(context.file, ts.getRefactorContextSpan(context));
|
|
155535
155831
|
var targetRange = rangeToExtract.targetRange; // TODO:GH#18217
|
|
155536
155832
|
var parsedFunctionIndexMatch = /^function_scope_(\d+)$/.exec(actionName);
|
|
@@ -155547,7 +155843,7 @@ var ts;
|
|
|
155547
155843
|
}
|
|
155548
155844
|
ts.Debug.fail("Unrecognized action name");
|
|
155549
155845
|
}
|
|
155550
|
-
extractSymbol.
|
|
155846
|
+
extractSymbol.getRefactorEditsToExtractSymbol = getRefactorEditsToExtractSymbol;
|
|
155551
155847
|
// Move these into diagnostic messages if they become user-facing
|
|
155552
155848
|
var Messages;
|
|
155553
155849
|
(function (Messages) {
|
|
@@ -157098,7 +157394,7 @@ var ts;
|
|
|
157098
157394
|
extractToInterfaceAction.kind,
|
|
157099
157395
|
extractToTypeDefAction.kind
|
|
157100
157396
|
],
|
|
157101
|
-
getAvailableActions: function (context) {
|
|
157397
|
+
getAvailableActions: function getRefactorActionsToExtractType(context) {
|
|
157102
157398
|
var info = getRangeToExtract(context, context.triggerReason === "invoked");
|
|
157103
157399
|
if (!info)
|
|
157104
157400
|
return ts.emptyArray;
|
|
@@ -157123,7 +157419,7 @@ var ts;
|
|
|
157123
157419
|
}
|
|
157124
157420
|
return ts.emptyArray;
|
|
157125
157421
|
},
|
|
157126
|
-
getEditsForAction: function (context, actionName) {
|
|
157422
|
+
getEditsForAction: function getRefactorEditsToExtractType(context, actionName) {
|
|
157127
157423
|
var file = context.file;
|
|
157128
157424
|
var info = getRangeToExtract(context);
|
|
157129
157425
|
ts.Debug.assert(info && !refactor.isRefactorErrorInfo(info), "Expected to find a range to extract");
|
|
@@ -157291,7 +157587,7 @@ var ts;
|
|
|
157291
157587
|
};
|
|
157292
157588
|
refactor.registerRefactor(actionName, {
|
|
157293
157589
|
kinds: [generateGetSetAction.kind],
|
|
157294
|
-
getEditsForAction: function (context, actionName) {
|
|
157590
|
+
getEditsForAction: function getRefactorActionsToGenerateGetAndSetAccessors(context, actionName) {
|
|
157295
157591
|
if (!context.endPosition)
|
|
157296
157592
|
return undefined;
|
|
157297
157593
|
var info = ts.codefix.getAccessorConvertiblePropertyAtPosition(context.file, context.program, context.startPosition, context.endPosition);
|
|
@@ -157370,7 +157666,7 @@ var ts;
|
|
|
157370
157666
|
};
|
|
157371
157667
|
refactor.registerRefactor(refactorName, {
|
|
157372
157668
|
kinds: [moveToNewFileAction.kind],
|
|
157373
|
-
getAvailableActions: function (context) {
|
|
157669
|
+
getAvailableActions: function getRefactorActionsToMoveToNewFile(context) {
|
|
157374
157670
|
var statements = getStatementsToMove(context);
|
|
157375
157671
|
if (context.preferences.allowTextChangesInNewFiles && statements) {
|
|
157376
157672
|
return [{ name: refactorName, description: description, actions: [moveToNewFileAction] }];
|
|
@@ -157381,7 +157677,7 @@ var ts;
|
|
|
157381
157677
|
}
|
|
157382
157678
|
return ts.emptyArray;
|
|
157383
157679
|
},
|
|
157384
|
-
getEditsForAction: function (context, actionName) {
|
|
157680
|
+
getEditsForAction: function getRefactorEditsToMoveToNewFile(context, actionName) {
|
|
157385
157681
|
ts.Debug.assert(actionName === refactorName, "Wrong refactor invoked");
|
|
157386
157682
|
var statements = ts.Debug.checkDefined(getStatementsToMove(context));
|
|
157387
157683
|
var edits = ts.textChanges.ChangeTracker.with(context, function (t) { return doChange(context.file, context.program, statements, t, context.host, context.preferences); });
|
|
@@ -158112,10 +158408,10 @@ var ts;
|
|
|
158112
158408
|
};
|
|
158113
158409
|
refactor.registerRefactor(refactorName, {
|
|
158114
158410
|
kinds: [removeBracesAction.kind],
|
|
158115
|
-
getEditsForAction:
|
|
158116
|
-
getAvailableActions:
|
|
158411
|
+
getEditsForAction: getRefactorEditsToRemoveFunctionBraces,
|
|
158412
|
+
getAvailableActions: getRefactorActionsToRemoveFunctionBraces
|
|
158117
158413
|
});
|
|
158118
|
-
function
|
|
158414
|
+
function getRefactorActionsToRemoveFunctionBraces(context) {
|
|
158119
158415
|
var file = context.file, startPosition = context.startPosition, triggerReason = context.triggerReason;
|
|
158120
158416
|
var info = getConvertibleArrowFunctionAtPosition(file, startPosition, triggerReason === "invoked");
|
|
158121
158417
|
if (!info)
|
|
@@ -158141,7 +158437,7 @@ var ts;
|
|
|
158141
158437
|
}
|
|
158142
158438
|
return ts.emptyArray;
|
|
158143
158439
|
}
|
|
158144
|
-
function
|
|
158440
|
+
function getRefactorEditsToRemoveFunctionBraces(context, actionName) {
|
|
158145
158441
|
var file = context.file, startPosition = context.startPosition;
|
|
158146
158442
|
var info = getConvertibleArrowFunctionAtPosition(file, startPosition);
|
|
158147
158443
|
ts.Debug.assert(info && !refactor.isRefactorErrorInfo(info), "Expected applicable refactor info");
|
|
@@ -158215,10 +158511,10 @@ var ts;
|
|
|
158215
158511
|
};
|
|
158216
158512
|
refactor.registerRefactor(refactorName, {
|
|
158217
158513
|
kinds: [toDestructuredAction.kind],
|
|
158218
|
-
getEditsForAction:
|
|
158219
|
-
getAvailableActions:
|
|
158514
|
+
getEditsForAction: getRefactorEditsToConvertParametersToDestructuredObject,
|
|
158515
|
+
getAvailableActions: getRefactorActionsToConvertParametersToDestructuredObject
|
|
158220
158516
|
});
|
|
158221
|
-
function
|
|
158517
|
+
function getRefactorActionsToConvertParametersToDestructuredObject(context) {
|
|
158222
158518
|
var file = context.file, startPosition = context.startPosition;
|
|
158223
158519
|
var isJSFile = ts.isSourceFileJS(file);
|
|
158224
158520
|
if (isJSFile)
|
|
@@ -158232,7 +158528,7 @@ var ts;
|
|
|
158232
158528
|
actions: [toDestructuredAction]
|
|
158233
158529
|
}];
|
|
158234
158530
|
}
|
|
158235
|
-
function
|
|
158531
|
+
function getRefactorEditsToConvertParametersToDestructuredObject(context, actionName) {
|
|
158236
158532
|
ts.Debug.assert(actionName === refactorName, "Unexpected action name");
|
|
158237
158533
|
var file = context.file, startPosition = context.startPosition, program = context.program, cancellationToken = context.cancellationToken, host = context.host;
|
|
158238
158534
|
var functionDeclaration = getFunctionDeclarationAtPosition(file, startPosition, program.getTypeChecker());
|
|
@@ -158742,10 +159038,10 @@ var ts;
|
|
|
158742
159038
|
};
|
|
158743
159039
|
refactor.registerRefactor(refactorName, {
|
|
158744
159040
|
kinds: [convertStringAction.kind],
|
|
158745
|
-
getEditsForAction:
|
|
158746
|
-
getAvailableActions:
|
|
159041
|
+
getEditsForAction: getRefactorEditsToConvertToTemplateString,
|
|
159042
|
+
getAvailableActions: getRefactorActionsToConvertToTemplateString
|
|
158747
159043
|
});
|
|
158748
|
-
function
|
|
159044
|
+
function getRefactorActionsToConvertToTemplateString(context) {
|
|
158749
159045
|
var file = context.file, startPosition = context.startPosition;
|
|
158750
159046
|
var node = getNodeOrParentOfParentheses(file, startPosition);
|
|
158751
159047
|
var maybeBinary = getParentBinaryExpression(node);
|
|
@@ -158771,7 +159067,7 @@ var ts;
|
|
|
158771
159067
|
}
|
|
158772
159068
|
return node;
|
|
158773
159069
|
}
|
|
158774
|
-
function
|
|
159070
|
+
function getRefactorEditsToConvertToTemplateString(context, actionName) {
|
|
158775
159071
|
var file = context.file, startPosition = context.startPosition;
|
|
158776
159072
|
var node = getNodeOrParentOfParentheses(file, startPosition);
|
|
158777
159073
|
switch (actionName) {
|
|
@@ -158985,10 +159281,10 @@ var ts;
|
|
|
158985
159281
|
toNamedFunctionAction.kind,
|
|
158986
159282
|
toArrowFunctionAction.kind
|
|
158987
159283
|
],
|
|
158988
|
-
getEditsForAction:
|
|
158989
|
-
getAvailableActions:
|
|
159284
|
+
getEditsForAction: getRefactorEditsToConvertFunctionExpressions,
|
|
159285
|
+
getAvailableActions: getRefactorActionsToConvertFunctionExpressions
|
|
158990
159286
|
});
|
|
158991
|
-
function
|
|
159287
|
+
function getRefactorActionsToConvertFunctionExpressions(context) {
|
|
158992
159288
|
var file = context.file, startPosition = context.startPosition, program = context.program, kind = context.kind;
|
|
158993
159289
|
var info = getFunctionInfo(file, startPosition, program);
|
|
158994
159290
|
if (!info)
|
|
@@ -159032,7 +159328,7 @@ var ts;
|
|
|
159032
159328
|
errors : possibleActions
|
|
159033
159329
|
}];
|
|
159034
159330
|
}
|
|
159035
|
-
function
|
|
159331
|
+
function getRefactorEditsToConvertFunctionExpressions(context, actionName) {
|
|
159036
159332
|
var file = context.file, startPosition = context.startPosition, program = context.program;
|
|
159037
159333
|
var info = getFunctionInfo(file, startPosition, program);
|
|
159038
159334
|
if (!info)
|
|
@@ -159192,10 +159488,10 @@ var ts;
|
|
|
159192
159488
|
};
|
|
159193
159489
|
refactor.registerRefactor(refactorName, {
|
|
159194
159490
|
kinds: [inferReturnTypeAction.kind],
|
|
159195
|
-
getEditsForAction:
|
|
159196
|
-
getAvailableActions:
|
|
159491
|
+
getEditsForAction: getRefactorEditsToInferReturnType,
|
|
159492
|
+
getAvailableActions: getRefactorActionsToInferReturnType
|
|
159197
159493
|
});
|
|
159198
|
-
function
|
|
159494
|
+
function getRefactorEditsToInferReturnType(context) {
|
|
159199
159495
|
var info = getInfo(context);
|
|
159200
159496
|
if (info && !refactor.isRefactorErrorInfo(info)) {
|
|
159201
159497
|
var edits = ts.textChanges.ChangeTracker.with(context, function (t) { return doChange(context.file, t, info.declaration, info.returnTypeNode); });
|
|
@@ -159203,7 +159499,7 @@ var ts;
|
|
|
159203
159499
|
}
|
|
159204
159500
|
return undefined;
|
|
159205
159501
|
}
|
|
159206
|
-
function
|
|
159502
|
+
function getRefactorActionsToInferReturnType(context) {
|
|
159207
159503
|
var info = getInfo(context);
|
|
159208
159504
|
if (!info)
|
|
159209
159505
|
return ts.emptyArray;
|
|
@@ -166303,30 +166599,43 @@ var ts;
|
|
|
166303
166599
|
(_b = packageJson.peerDependencies) === null || _b === void 0 ? void 0 : _b.forEach(function (_, dependencyName) { return addDependency(dependencyName); });
|
|
166304
166600
|
}
|
|
166305
166601
|
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
|
-
});
|
|
166602
|
+
var dependenciesAdded = 0;
|
|
166315
166603
|
var symlinkCache = hostProject.getSymlinkCache();
|
|
166316
|
-
for (var _c = 0,
|
|
166317
|
-
var
|
|
166318
|
-
|
|
166604
|
+
for (var _c = 0, _d = ts.arrayFrom(dependencyNames.keys()); _c < _d.length; _c++) {
|
|
166605
|
+
var name = _d[_c];
|
|
166606
|
+
// Avoid creating a large project that would significantly slow down time to editor interactivity
|
|
166607
|
+
if (dependencySelection === 2 /* Auto */ && dependenciesAdded > this.maxDependencies) {
|
|
166608
|
+
hostProject.log("Auto-import provider attempted to add more than " + this.maxDependencies + " dependencies.");
|
|
166609
|
+
return ts.emptyArray;
|
|
166610
|
+
}
|
|
166611
|
+
// 1. Try to load from the implementation package. For many dependencies, the
|
|
166612
|
+
// package.json will exist, but the package will not contain any typings,
|
|
166613
|
+
// so `entrypoints` will be undefined. In that case, or if the dependency
|
|
166614
|
+
// is missing altogether, we will move on to trying the @types package (2).
|
|
166615
|
+
var packageJson = ts.resolvePackageNameToPackageJson(name, hostProject.currentDirectory, compilerOptions, moduleResolutionHost, program.getModuleResolutionCache());
|
|
166616
|
+
if (packageJson) {
|
|
166617
|
+
var entrypoints = getRootNamesFromPackageJson(packageJson, program, symlinkCache);
|
|
166618
|
+
if (entrypoints) {
|
|
166619
|
+
rootNames = ts.concatenate(rootNames, entrypoints);
|
|
166620
|
+
dependenciesAdded += entrypoints.length ? 1 : 0;
|
|
166621
|
+
continue;
|
|
166622
|
+
}
|
|
166623
|
+
}
|
|
166624
|
+
// 2. Try to load from the @types package.
|
|
166625
|
+
var typesPackageJson = ts.resolvePackageNameToPackageJson("@types/" + name, hostProject.currentDirectory, compilerOptions, moduleResolutionHost, program.getModuleResolutionCache());
|
|
166626
|
+
if (typesPackageJson) {
|
|
166627
|
+
var entrypoints = getRootNamesFromPackageJson(typesPackageJson, program, symlinkCache);
|
|
166628
|
+
rootNames = ts.concatenate(rootNames, entrypoints);
|
|
166629
|
+
dependenciesAdded += (entrypoints === null || entrypoints === void 0 ? void 0 : entrypoints.length) ? 1 : 0;
|
|
166319
166630
|
continue;
|
|
166320
|
-
var resolvedFileName = resolution.resolvedFileName, originalPath = resolution.originalPath;
|
|
166321
|
-
if (originalPath) {
|
|
166322
|
-
symlinkCache.setSymlinkedDirectoryFromSymlinkedFile(originalPath, resolvedFileName);
|
|
166323
166631
|
}
|
|
166324
|
-
|
|
166325
|
-
|
|
166326
|
-
|
|
166327
|
-
|
|
166328
|
-
|
|
166329
|
-
|
|
166632
|
+
// 3. If the @types package did not exist and the user has settings that
|
|
166633
|
+
// allow processing JS from node_modules, go back to the implementation
|
|
166634
|
+
// package and load the JS.
|
|
166635
|
+
if (packageJson && compilerOptions.allowJs && compilerOptions.maxNodeModuleJsDepth) {
|
|
166636
|
+
var entrypoints = getRootNamesFromPackageJson(packageJson, program, symlinkCache, /*allowJs*/ true);
|
|
166637
|
+
rootNames = ts.concatenate(rootNames, entrypoints);
|
|
166638
|
+
dependenciesAdded += (entrypoints === null || entrypoints === void 0 ? void 0 : entrypoints.length) ? 1 : 0;
|
|
166330
166639
|
}
|
|
166331
166640
|
}
|
|
166332
166641
|
}
|
|
@@ -166336,6 +166645,26 @@ var ts;
|
|
|
166336
166645
|
(dependencyNames || (dependencyNames = new ts.Set())).add(dependency);
|
|
166337
166646
|
}
|
|
166338
166647
|
}
|
|
166648
|
+
function getRootNamesFromPackageJson(packageJson, program, symlinkCache, resolveJs) {
|
|
166649
|
+
var _a;
|
|
166650
|
+
var entrypoints = ts.getEntrypointsFromPackageJsonInfo(packageJson, compilerOptions, moduleResolutionHost, program.getModuleResolutionCache(), resolveJs);
|
|
166651
|
+
if (entrypoints) {
|
|
166652
|
+
var real_1 = (_a = moduleResolutionHost.realpath) === null || _a === void 0 ? void 0 : _a.call(moduleResolutionHost, packageJson.packageDirectory);
|
|
166653
|
+
var isSymlink_1 = real_1 && real_1 !== packageJson.packageDirectory;
|
|
166654
|
+
if (isSymlink_1) {
|
|
166655
|
+
symlinkCache.setSymlinkedDirectory(packageJson.packageDirectory, {
|
|
166656
|
+
real: real_1,
|
|
166657
|
+
realPath: hostProject.toPath(real_1),
|
|
166658
|
+
});
|
|
166659
|
+
}
|
|
166660
|
+
return ts.mapDefined(entrypoints, function (entrypoint) {
|
|
166661
|
+
var resolvedFileName = isSymlink_1 ? entrypoint.replace(packageJson.packageDirectory, real_1) : entrypoint;
|
|
166662
|
+
if (!program.getSourceFile(resolvedFileName) && !(isSymlink_1 && program.getSourceFile(entrypoint))) {
|
|
166663
|
+
return resolvedFileName;
|
|
166664
|
+
}
|
|
166665
|
+
});
|
|
166666
|
+
}
|
|
166667
|
+
}
|
|
166339
166668
|
};
|
|
166340
166669
|
/*@internal*/
|
|
166341
166670
|
AutoImportProviderProject.create = function (dependencySelection, hostProject, moduleResolutionHost, documentRegistry) {
|