typescript 4.5.0-dev.20210927 → 4.5.0-dev.20210928
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/de/diagnosticMessages.generated.json +17 -5
- package/lib/it/diagnosticMessages.generated.json +15 -4
- package/lib/ko/diagnosticMessages.generated.json +15 -4
- package/lib/lib.dom.d.ts +669 -1896
- package/lib/lib.dom.iterable.d.ts +16 -48
- package/lib/lib.webworker.d.ts +183 -520
- package/lib/lib.webworker.iterable.d.ts +10 -30
- package/lib/ru/diagnosticMessages.generated.json +15 -4
- package/lib/tsc.js +204 -102
- package/lib/tsserver.js +677 -290
- package/lib/tsserverlibrary.d.ts +10 -8
- package/lib/tsserverlibrary.js +677 -290
- package/lib/typescript.d.ts +10 -8
- package/lib/typescript.js +677 -290
- package/lib/typescriptServices.d.ts +10 -8
- package/lib/typescriptServices.js +677 -290
- package/lib/typingsInstaller.js +255 -111
- package/lib/zh-tw/diagnosticMessages.generated.json +15 -4
- 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.20210928";
|
|
104
104
|
/* @internal */
|
|
105
105
|
var Comparison;
|
|
106
106
|
(function (Comparison) {
|
|
@@ -8198,6 +8198,8 @@ var ts;
|
|
|
8198
8198
|
Construct_signature_return_types_0_and_1_are_incompatible: diag(2203, ts.DiagnosticCategory.Error, "Construct_signature_return_types_0_and_1_are_incompatible_2203", "Construct signature return types '{0}' and '{1}' are incompatible.", /*reportsUnnecessary*/ undefined, /*elidedInCompatabilityPyramid*/ true),
|
|
8199
8199
|
Call_signatures_with_no_arguments_have_incompatible_return_types_0_and_1: diag(2204, ts.DiagnosticCategory.Error, "Call_signatures_with_no_arguments_have_incompatible_return_types_0_and_1_2204", "Call signatures with no arguments have incompatible return types '{0}' and '{1}'.", /*reportsUnnecessary*/ undefined, /*elidedInCompatabilityPyramid*/ true),
|
|
8200
8200
|
Construct_signatures_with_no_arguments_have_incompatible_return_types_0_and_1: diag(2205, ts.DiagnosticCategory.Error, "Construct_signatures_with_no_arguments_have_incompatible_return_types_0_and_1_2205", "Construct signatures with no arguments have incompatible return types '{0}' and '{1}'.", /*reportsUnnecessary*/ undefined, /*elidedInCompatabilityPyramid*/ true),
|
|
8201
|
+
The_type_modifier_cannot_be_used_on_a_named_import_when_import_type_is_used_on_its_import_statement: diag(2206, ts.DiagnosticCategory.Error, "The_type_modifier_cannot_be_used_on_a_named_import_when_import_type_is_used_on_its_import_statement_2206", "The 'type' modifier cannot be used on a named import when 'import type' is used on its import statement."),
|
|
8202
|
+
The_type_modifier_cannot_be_used_on_a_named_export_when_export_type_is_used_on_its_export_statement: diag(2207, ts.DiagnosticCategory.Error, "The_type_modifier_cannot_be_used_on_a_named_export_when_export_type_is_used_on_its_export_statement_2207", "The 'type' modifier cannot be used on a named export when 'export type' is used on its export statement."),
|
|
8201
8203
|
Duplicate_identifier_0: diag(2300, ts.DiagnosticCategory.Error, "Duplicate_identifier_0_2300", "Duplicate identifier '{0}'."),
|
|
8202
8204
|
Initializer_of_instance_member_variable_0_cannot_reference_identifier_1_declared_in_the_constructor: diag(2301, ts.DiagnosticCategory.Error, "Initializer_of_instance_member_variable_0_cannot_reference_identifier_1_declared_in_the_constructor_2301", "Initializer of instance member variable '{0}' cannot reference identifier '{1}' declared in the constructor."),
|
|
8203
8205
|
Static_members_cannot_reference_class_type_parameters: diag(2302, ts.DiagnosticCategory.Error, "Static_members_cannot_reference_class_type_parameters_2302", "Static members cannot reference class type parameters."),
|
|
@@ -12985,7 +12987,7 @@ var ts;
|
|
|
12985
12987
|
switch (node.kind) {
|
|
12986
12988
|
case 269 /* ImportSpecifier */:
|
|
12987
12989
|
case 274 /* ExportSpecifier */:
|
|
12988
|
-
return node.parent.parent.isTypeOnly;
|
|
12990
|
+
return node.isTypeOnly || node.parent.parent.isTypeOnly;
|
|
12989
12991
|
case 267 /* NamespaceImport */:
|
|
12990
12992
|
return node.parent.isTypeOnly;
|
|
12991
12993
|
case 266 /* ImportClause */:
|
|
@@ -19796,7 +19798,8 @@ var ts;
|
|
|
19796
19798
|
var aParts = ts.getPathComponents(ts.getNormalizedAbsolutePath(a, cwd));
|
|
19797
19799
|
var bParts = ts.getPathComponents(ts.getNormalizedAbsolutePath(b, cwd));
|
|
19798
19800
|
var isDirectory = false;
|
|
19799
|
-
while (
|
|
19801
|
+
while (aParts.length >= 2 && bParts.length >= 2 &&
|
|
19802
|
+
!isNodeModulesOrScopedPackageDirectory(aParts[aParts.length - 2], getCanonicalFileName) &&
|
|
19800
19803
|
!isNodeModulesOrScopedPackageDirectory(bParts[bParts.length - 2], getCanonicalFileName) &&
|
|
19801
19804
|
getCanonicalFileName(aParts[aParts.length - 1]) === getCanonicalFileName(bParts[bParts.length - 1])) {
|
|
19802
19805
|
aParts.pop();
|
|
@@ -19808,7 +19811,7 @@ var ts;
|
|
|
19808
19811
|
// KLUDGE: Don't assume one 'node_modules' links to another. More likely a single directory inside the node_modules is the symlink.
|
|
19809
19812
|
// ALso, don't assume that an `@foo` directory is linked. More likely the contents of that are linked.
|
|
19810
19813
|
function isNodeModulesOrScopedPackageDirectory(s, getCanonicalFileName) {
|
|
19811
|
-
return getCanonicalFileName(s) === "node_modules" || ts.startsWith(s, "@");
|
|
19814
|
+
return s !== undefined && (getCanonicalFileName(s) === "node_modules" || ts.startsWith(s, "@"));
|
|
19812
19815
|
}
|
|
19813
19816
|
function stripLeadingDirectorySeparator(s) {
|
|
19814
19817
|
return ts.isAnyDirectorySeparator(s.charCodeAt(0)) ? s.slice(1) : undefined;
|
|
@@ -20439,10 +20442,6 @@ var ts;
|
|
|
20439
20442
|
|| !(isExpressionNode(useSite) || isShorthandPropertyNameUseSite(useSite));
|
|
20440
20443
|
}
|
|
20441
20444
|
ts.isValidTypeOnlyAliasUseSite = isValidTypeOnlyAliasUseSite;
|
|
20442
|
-
function typeOnlyDeclarationIsExport(typeOnlyDeclaration) {
|
|
20443
|
-
return typeOnlyDeclaration.kind === 274 /* ExportSpecifier */;
|
|
20444
|
-
}
|
|
20445
|
-
ts.typeOnlyDeclarationIsExport = typeOnlyDeclarationIsExport;
|
|
20446
20445
|
function isShorthandPropertyNameUseSite(useSite) {
|
|
20447
20446
|
return ts.isIdentifier(useSite) && ts.isShorthandPropertyAssignment(useSite.parent) && useSite.parent.name === useSite;
|
|
20448
20447
|
}
|
|
@@ -24464,8 +24463,9 @@ var ts;
|
|
|
24464
24463
|
: node;
|
|
24465
24464
|
}
|
|
24466
24465
|
// @api
|
|
24467
|
-
function createImportSpecifier(propertyName, name) {
|
|
24466
|
+
function createImportSpecifier(isTypeOnly, propertyName, name) {
|
|
24468
24467
|
var node = createBaseNode(269 /* ImportSpecifier */);
|
|
24468
|
+
node.isTypeOnly = isTypeOnly;
|
|
24469
24469
|
node.propertyName = propertyName;
|
|
24470
24470
|
node.name = name;
|
|
24471
24471
|
node.transformFlags |=
|
|
@@ -24475,10 +24475,11 @@ var ts;
|
|
|
24475
24475
|
return node;
|
|
24476
24476
|
}
|
|
24477
24477
|
// @api
|
|
24478
|
-
function updateImportSpecifier(node, propertyName, name) {
|
|
24479
|
-
return node.
|
|
24478
|
+
function updateImportSpecifier(node, isTypeOnly, propertyName, name) {
|
|
24479
|
+
return node.isTypeOnly !== isTypeOnly
|
|
24480
|
+
|| node.propertyName !== propertyName
|
|
24480
24481
|
|| node.name !== name
|
|
24481
|
-
? update(createImportSpecifier(propertyName, name), node)
|
|
24482
|
+
? update(createImportSpecifier(isTypeOnly, propertyName, name), node)
|
|
24482
24483
|
: node;
|
|
24483
24484
|
}
|
|
24484
24485
|
// @api
|
|
@@ -24539,8 +24540,9 @@ var ts;
|
|
|
24539
24540
|
: node;
|
|
24540
24541
|
}
|
|
24541
24542
|
// @api
|
|
24542
|
-
function createExportSpecifier(propertyName, name) {
|
|
24543
|
+
function createExportSpecifier(isTypeOnly, propertyName, name) {
|
|
24543
24544
|
var node = createBaseNode(274 /* ExportSpecifier */);
|
|
24545
|
+
node.isTypeOnly = isTypeOnly;
|
|
24544
24546
|
node.propertyName = asName(propertyName);
|
|
24545
24547
|
node.name = asName(name);
|
|
24546
24548
|
node.transformFlags |=
|
|
@@ -24550,10 +24552,11 @@ var ts;
|
|
|
24550
24552
|
return node;
|
|
24551
24553
|
}
|
|
24552
24554
|
// @api
|
|
24553
|
-
function updateExportSpecifier(node, propertyName, name) {
|
|
24554
|
-
return node.
|
|
24555
|
+
function updateExportSpecifier(node, isTypeOnly, propertyName, name) {
|
|
24556
|
+
return node.isTypeOnly !== isTypeOnly
|
|
24557
|
+
|| node.propertyName !== propertyName
|
|
24555
24558
|
|| node.name !== name
|
|
24556
|
-
? update(createExportSpecifier(propertyName, name), node)
|
|
24559
|
+
? update(createExportSpecifier(isTypeOnly, propertyName, name), node)
|
|
24557
24560
|
: node;
|
|
24558
24561
|
}
|
|
24559
24562
|
// @api
|
|
@@ -25661,7 +25664,7 @@ var ts;
|
|
|
25661
25664
|
/*decorators*/ undefined,
|
|
25662
25665
|
/*modifiers*/ undefined,
|
|
25663
25666
|
/*isTypeOnly*/ false, createNamedExports([
|
|
25664
|
-
createExportSpecifier(/*propertyName*/ undefined, exportName)
|
|
25667
|
+
createExportSpecifier(/*isTypeOnly*/ false, /*propertyName*/ undefined, exportName)
|
|
25665
25668
|
]));
|
|
25666
25669
|
}
|
|
25667
25670
|
//
|
|
@@ -28928,8 +28931,8 @@ var ts;
|
|
|
28928
28931
|
// Alias the imports if the names are used somewhere in the file.
|
|
28929
28932
|
// NOTE: We don't need to care about global import collisions as this is a module.
|
|
28930
28933
|
namedBindings = nodeFactory.createNamedImports(ts.map(helperNames, function (name) { return ts.isFileLevelUniqueName(sourceFile, name)
|
|
28931
|
-
? nodeFactory.createImportSpecifier(/*propertyName*/ undefined, nodeFactory.createIdentifier(name))
|
|
28932
|
-
: nodeFactory.createImportSpecifier(nodeFactory.createIdentifier(name), helperFactory.getUnscopedHelperName(name)); }));
|
|
28934
|
+
? nodeFactory.createImportSpecifier(/*isTypeOnly*/ false, /*propertyName*/ undefined, nodeFactory.createIdentifier(name))
|
|
28935
|
+
: nodeFactory.createImportSpecifier(/*isTypeOnly*/ false, nodeFactory.createIdentifier(name), helperFactory.getUnscopedHelperName(name)); }));
|
|
28933
28936
|
var parseNode = ts.getOriginalNode(sourceFile, ts.isSourceFile);
|
|
28934
28937
|
var emitNode = ts.getOrCreateEmitNode(parseNode);
|
|
28935
28938
|
emitNode.externalHelpers = true;
|
|
@@ -36056,27 +36059,74 @@ var ts;
|
|
|
36056
36059
|
var checkIdentifierIsKeyword = ts.isKeyword(token()) && !isIdentifier();
|
|
36057
36060
|
var checkIdentifierStart = scanner.getTokenPos();
|
|
36058
36061
|
var checkIdentifierEnd = scanner.getTextPos();
|
|
36059
|
-
var
|
|
36062
|
+
var isTypeOnly = false;
|
|
36060
36063
|
var propertyName;
|
|
36061
|
-
var
|
|
36062
|
-
|
|
36063
|
-
|
|
36064
|
-
|
|
36065
|
-
|
|
36066
|
-
|
|
36067
|
-
|
|
36068
|
-
|
|
36064
|
+
var canParseAsKeyword = true;
|
|
36065
|
+
var name = parseIdentifierName();
|
|
36066
|
+
if (name.escapedText === "type") {
|
|
36067
|
+
// If the first token of an import specifier is 'type', there are a lot of possibilities,
|
|
36068
|
+
// especially if we see 'as' afterwards:
|
|
36069
|
+
//
|
|
36070
|
+
// import { type } from "mod"; - isTypeOnly: false, name: type
|
|
36071
|
+
// import { type as } from "mod"; - isTypeOnly: true, name: as
|
|
36072
|
+
// import { type as as } from "mod"; - isTypeOnly: false, name: as, propertyName: type
|
|
36073
|
+
// import { type as as as } from "mod"; - isTypeOnly: true, name: as, propertyName: as
|
|
36074
|
+
if (token() === 127 /* AsKeyword */) {
|
|
36075
|
+
// { type as ...? }
|
|
36076
|
+
var firstAs = parseIdentifierName();
|
|
36077
|
+
if (token() === 127 /* AsKeyword */) {
|
|
36078
|
+
// { type as as ...? }
|
|
36079
|
+
var secondAs = parseIdentifierName();
|
|
36080
|
+
if (ts.tokenIsIdentifierOrKeyword(token())) {
|
|
36081
|
+
// { type as as something }
|
|
36082
|
+
isTypeOnly = true;
|
|
36083
|
+
propertyName = firstAs;
|
|
36084
|
+
name = parseNameWithKeywordCheck();
|
|
36085
|
+
canParseAsKeyword = false;
|
|
36086
|
+
}
|
|
36087
|
+
else {
|
|
36088
|
+
// { type as as }
|
|
36089
|
+
propertyName = name;
|
|
36090
|
+
name = secondAs;
|
|
36091
|
+
canParseAsKeyword = false;
|
|
36092
|
+
}
|
|
36093
|
+
}
|
|
36094
|
+
else if (ts.tokenIsIdentifierOrKeyword(token())) {
|
|
36095
|
+
// { type as something }
|
|
36096
|
+
propertyName = name;
|
|
36097
|
+
canParseAsKeyword = false;
|
|
36098
|
+
name = parseNameWithKeywordCheck();
|
|
36099
|
+
}
|
|
36100
|
+
else {
|
|
36101
|
+
// { type as }
|
|
36102
|
+
isTypeOnly = true;
|
|
36103
|
+
name = firstAs;
|
|
36104
|
+
}
|
|
36105
|
+
}
|
|
36106
|
+
else if (ts.tokenIsIdentifierOrKeyword(token())) {
|
|
36107
|
+
// { type something ...? }
|
|
36108
|
+
isTypeOnly = true;
|
|
36109
|
+
name = parseNameWithKeywordCheck();
|
|
36110
|
+
}
|
|
36069
36111
|
}
|
|
36070
|
-
|
|
36071
|
-
|
|
36112
|
+
if (canParseAsKeyword && token() === 127 /* AsKeyword */) {
|
|
36113
|
+
propertyName = name;
|
|
36114
|
+
parseExpected(127 /* AsKeyword */);
|
|
36115
|
+
name = parseNameWithKeywordCheck();
|
|
36072
36116
|
}
|
|
36073
36117
|
if (kind === 269 /* ImportSpecifier */ && checkIdentifierIsKeyword) {
|
|
36074
36118
|
parseErrorAt(checkIdentifierStart, checkIdentifierEnd, ts.Diagnostics.Identifier_expected);
|
|
36075
36119
|
}
|
|
36076
36120
|
var node = kind === 269 /* ImportSpecifier */
|
|
36077
|
-
? factory.createImportSpecifier(propertyName, name)
|
|
36078
|
-
: factory.createExportSpecifier(propertyName, name);
|
|
36121
|
+
? factory.createImportSpecifier(isTypeOnly, propertyName, name)
|
|
36122
|
+
: factory.createExportSpecifier(isTypeOnly, propertyName, name);
|
|
36079
36123
|
return finishNode(node, pos);
|
|
36124
|
+
function parseNameWithKeywordCheck() {
|
|
36125
|
+
checkIdentifierIsKeyword = ts.isKeyword(token()) && !isIdentifier();
|
|
36126
|
+
checkIdentifierStart = scanner.getTokenPos();
|
|
36127
|
+
checkIdentifierEnd = scanner.getTextPos();
|
|
36128
|
+
return parseIdentifierName();
|
|
36129
|
+
}
|
|
36080
36130
|
}
|
|
36081
36131
|
function parseNamespaceExport(pos) {
|
|
36082
36132
|
return finishNode(factory.createNamespaceExport(parseIdentifierName()), pos);
|
|
@@ -46906,6 +46956,7 @@ var ts;
|
|
|
46906
46956
|
getLocalTypeParametersOfClassOrInterfaceOrTypeAlias: getLocalTypeParametersOfClassOrInterfaceOrTypeAlias,
|
|
46907
46957
|
isDeclarationVisible: isDeclarationVisible,
|
|
46908
46958
|
isPropertyAccessible: isPropertyAccessible,
|
|
46959
|
+
getTypeOnlyAliasDeclaration: getTypeOnlyAliasDeclaration,
|
|
46909
46960
|
};
|
|
46910
46961
|
function getResolvedSignatureWorker(nodeIn, candidatesOutArray, argumentCount, checkMode) {
|
|
46911
46962
|
var node = ts.getParseTreeNode(nodeIn, ts.isCallLikeExpression);
|
|
@@ -48282,8 +48333,7 @@ var ts;
|
|
|
48282
48333
|
if (!ts.isValidTypeOnlyAliasUseSite(useSite)) {
|
|
48283
48334
|
var typeOnlyDeclaration = getTypeOnlyAliasDeclaration(symbol);
|
|
48284
48335
|
if (typeOnlyDeclaration) {
|
|
48285
|
-
var
|
|
48286
|
-
var message = isExport
|
|
48336
|
+
var message = typeOnlyDeclaration.kind === 274 /* ExportSpecifier */
|
|
48287
48337
|
? ts.Diagnostics._0_cannot_be_used_as_a_value_because_it_was_exported_using_export_type
|
|
48288
48338
|
: ts.Diagnostics._0_cannot_be_used_as_a_value_because_it_was_imported_using_import_type;
|
|
48289
48339
|
var unescapedName = ts.unescapeLeadingUnderscores(name);
|
|
@@ -48294,7 +48344,7 @@ var ts;
|
|
|
48294
48344
|
function addTypeOnlyDeclarationRelatedInfo(diagnostic, typeOnlyDeclaration, unescapedName) {
|
|
48295
48345
|
if (!typeOnlyDeclaration)
|
|
48296
48346
|
return diagnostic;
|
|
48297
|
-
return ts.addRelatedInfo(diagnostic, ts.createDiagnosticForNode(typeOnlyDeclaration,
|
|
48347
|
+
return ts.addRelatedInfo(diagnostic, ts.createDiagnosticForNode(typeOnlyDeclaration, typeOnlyDeclaration.kind === 274 /* ExportSpecifier */ ? ts.Diagnostics._0_was_exported_here : ts.Diagnostics._0_was_imported_here, unescapedName));
|
|
48298
48348
|
}
|
|
48299
48349
|
function getIsDeferredContext(location, lastLocation) {
|
|
48300
48350
|
if (location.kind !== 213 /* ArrowFunction */ && location.kind !== 212 /* FunctionExpression */) {
|
|
@@ -48618,15 +48668,13 @@ var ts;
|
|
|
48618
48668
|
function checkAndReportErrorForResolvingImportAliasToTypeOnlySymbol(node, resolved) {
|
|
48619
48669
|
if (markSymbolOfAliasDeclarationIfTypeOnly(node, /*immediateTarget*/ undefined, resolved, /*overwriteEmpty*/ false) && !node.isTypeOnly) {
|
|
48620
48670
|
var typeOnlyDeclaration = getTypeOnlyAliasDeclaration(getSymbolOfNode(node));
|
|
48621
|
-
var isExport =
|
|
48671
|
+
var isExport = typeOnlyDeclaration.kind === 274 /* ExportSpecifier */;
|
|
48622
48672
|
var message = isExport
|
|
48623
48673
|
? ts.Diagnostics.An_import_alias_cannot_reference_a_declaration_that_was_exported_using_export_type
|
|
48624
48674
|
: ts.Diagnostics.An_import_alias_cannot_reference_a_declaration_that_was_imported_using_import_type;
|
|
48625
48675
|
var relatedMessage = isExport
|
|
48626
48676
|
? ts.Diagnostics._0_was_exported_here
|
|
48627
48677
|
: ts.Diagnostics._0_was_imported_here;
|
|
48628
|
-
// Non-null assertion is safe because the optionality comes from ImportClause,
|
|
48629
|
-
// but if an ImportClause was the typeOnlyDeclaration, it had to have a `name`.
|
|
48630
48678
|
var name = ts.unescapeLeadingUnderscores(typeOnlyDeclaration.name.escapedText);
|
|
48631
48679
|
ts.addRelatedInfo(error(node.moduleReference, message), ts.createDiagnosticForNode(typeOnlyDeclaration, relatedMessage, name));
|
|
48632
48680
|
}
|
|
@@ -49042,13 +49090,13 @@ var ts;
|
|
|
49042
49090
|
* and issue an error if so.
|
|
49043
49091
|
*
|
|
49044
49092
|
* @param aliasDeclaration The alias declaration not marked as type-only
|
|
49093
|
+
* @param immediateTarget The symbol to which the alias declaration immediately resolves
|
|
49094
|
+
* @param finalTarget The symbol to which the alias declaration ultimately resolves
|
|
49095
|
+
* @param overwriteEmpty Checks `resolvesToSymbol` for type-only declarations even if `aliasDeclaration`
|
|
49045
49096
|
* has already been marked as not resolving to a type-only alias. Used when recursively resolving qualified
|
|
49046
49097
|
* names of import aliases, e.g. `import C = a.b.C`. If namespace `a` is not found to be type-only, the
|
|
49047
49098
|
* import declaration will initially be marked as not resolving to a type-only symbol. But, namespace `b`
|
|
49048
49099
|
* must still be checked for a type-only marker, overwriting the previous negative result if found.
|
|
49049
|
-
* @param immediateTarget The symbol to which the alias declaration immediately resolves
|
|
49050
|
-
* @param finalTarget The symbol to which the alias declaration ultimately resolves
|
|
49051
|
-
* @param overwriteEmpty Checks `resolvesToSymbol` for type-only declarations even if `aliasDeclaration`
|
|
49052
49100
|
*/
|
|
49053
49101
|
function markSymbolOfAliasDeclarationIfTypeOnly(aliasDeclaration, immediateTarget, finalTarget, overwriteEmpty) {
|
|
49054
49102
|
if (!aliasDeclaration || ts.isPropertyAccessExpression(aliasDeclaration))
|
|
@@ -52181,7 +52229,7 @@ var ts;
|
|
|
52181
52229
|
ns = ts.factory.updateModuleDeclaration(ns, ns.decorators, ns.modifiers, ns.name, body = ts.factory.updateModuleBlock(body, ts.factory.createNodeArray(__spreadArray(__spreadArray([], ns.body.statements, true), [ts.factory.createExportDeclaration(
|
|
52182
52230
|
/*decorators*/ undefined,
|
|
52183
52231
|
/*modifiers*/ undefined,
|
|
52184
|
-
/*isTypeOnly*/ false, ts.factory.createNamedExports(ts.map(ts.flatMap(excessExports, function (e) { return getNamesOfDeclaration(e); }), function (id) { return ts.factory.createExportSpecifier(/*alias*/ undefined, id); })),
|
|
52232
|
+
/*isTypeOnly*/ false, ts.factory.createNamedExports(ts.map(ts.flatMap(excessExports, function (e) { return getNamesOfDeclaration(e); }), function (id) { return ts.factory.createExportSpecifier(/*isTypeOnly*/ false, /*alias*/ undefined, id); })),
|
|
52185
52233
|
/*moduleSpecifier*/ undefined)], false))));
|
|
52186
52234
|
statements = __spreadArray(__spreadArray(__spreadArray([], statements.slice(0, nsIndex), true), [ns], false), statements.slice(nsIndex + 1), true);
|
|
52187
52235
|
}
|
|
@@ -52409,7 +52457,7 @@ var ts;
|
|
|
52409
52457
|
addResult(ts.factory.createExportDeclaration(
|
|
52410
52458
|
/*decorators*/ undefined,
|
|
52411
52459
|
/*modifiers*/ undefined,
|
|
52412
|
-
/*isTypeOnly*/ false, ts.factory.createNamedExports([ts.factory.createExportSpecifier(alias, localName)])), 0 /* None */);
|
|
52460
|
+
/*isTypeOnly*/ false, ts.factory.createNamedExports([ts.factory.createExportSpecifier(/*isTypeOnly*/ false, alias, localName)])), 0 /* None */);
|
|
52413
52461
|
context.tracker.trackSymbol(type.symbol, context.enclosingDeclaration, 111551 /* Value */);
|
|
52414
52462
|
}
|
|
52415
52463
|
else {
|
|
@@ -52442,7 +52490,7 @@ var ts;
|
|
|
52442
52490
|
addResult(ts.factory.createExportDeclaration(
|
|
52443
52491
|
/*decorators*/ undefined,
|
|
52444
52492
|
/*modifiers*/ undefined,
|
|
52445
|
-
/*isTypeOnly*/ false, ts.factory.createNamedExports([ts.factory.createExportSpecifier(name, localName)])), 0 /* None */);
|
|
52493
|
+
/*isTypeOnly*/ false, ts.factory.createNamedExports([ts.factory.createExportSpecifier(/*isTypeOnly*/ false, name, localName)])), 0 /* None */);
|
|
52446
52494
|
needsExportDeclaration = false;
|
|
52447
52495
|
needsPostExportDefault = false;
|
|
52448
52496
|
}
|
|
@@ -52500,7 +52548,7 @@ var ts;
|
|
|
52500
52548
|
addResult(ts.factory.createExportDeclaration(
|
|
52501
52549
|
/*decorators*/ undefined,
|
|
52502
52550
|
/*modifiers*/ undefined,
|
|
52503
|
-
/*isTypeOnly*/ false, ts.factory.createNamedExports([ts.factory.createExportSpecifier(getInternalSymbolName(symbol, symbolName), symbolName)])), 0 /* None */);
|
|
52551
|
+
/*isTypeOnly*/ false, ts.factory.createNamedExports([ts.factory.createExportSpecifier(/*isTypeOnly*/ false, getInternalSymbolName(symbol, symbolName), symbolName)])), 0 /* None */);
|
|
52504
52552
|
}
|
|
52505
52553
|
}
|
|
52506
52554
|
function includePrivateSymbol(symbol) {
|
|
@@ -52622,7 +52670,7 @@ var ts;
|
|
|
52622
52670
|
var target = aliasDecl && getTargetOfAliasDeclaration(aliasDecl, /*dontRecursivelyResolve*/ true);
|
|
52623
52671
|
includePrivateSymbol(target || s);
|
|
52624
52672
|
var targetName = target ? getInternalSymbolName(target, ts.unescapeLeadingUnderscores(target.escapedName)) : localName;
|
|
52625
|
-
return ts.factory.createExportSpecifier(name === targetName ? undefined : targetName, name);
|
|
52673
|
+
return ts.factory.createExportSpecifier(/*isTypeOnly*/ false, name === targetName ? undefined : targetName, name);
|
|
52626
52674
|
})))]);
|
|
52627
52675
|
addResult(ts.factory.createModuleDeclaration(
|
|
52628
52676
|
/*decorators*/ undefined,
|
|
@@ -52713,7 +52761,7 @@ var ts;
|
|
|
52713
52761
|
var defaultReplaced = ts.map(declarations, function (d) { return ts.isExportAssignment(d) && !d.isExportEquals && ts.isIdentifier(d.expression) ? ts.factory.createExportDeclaration(
|
|
52714
52762
|
/*decorators*/ undefined,
|
|
52715
52763
|
/*modifiers*/ undefined,
|
|
52716
|
-
/*isTypeOnly*/ false, ts.factory.createNamedExports([ts.factory.createExportSpecifier(d.expression, ts.factory.createIdentifier("default" /* Default */))])) : d; });
|
|
52764
|
+
/*isTypeOnly*/ false, ts.factory.createNamedExports([ts.factory.createExportSpecifier(/*isTypeOnly*/ false, d.expression, ts.factory.createIdentifier("default" /* Default */))])) : d; });
|
|
52717
52765
|
var exportModifierStripped = ts.every(defaultReplaced, function (d) { return ts.hasSyntacticModifier(d, 1 /* Export */); }) ? ts.map(defaultReplaced, removeExportModifier) : defaultReplaced;
|
|
52718
52766
|
fakespace = ts.factory.updateModuleDeclaration(fakespace, fakespace.decorators, fakespace.modifiers, fakespace.name, ts.factory.createModuleBlock(exportModifierStripped));
|
|
52719
52767
|
addResult(fakespace, modifierFlags); // namespaces can never be default exported
|
|
@@ -52864,7 +52912,8 @@ var ts;
|
|
|
52864
52912
|
var propertyName = node.propertyName;
|
|
52865
52913
|
addResult(ts.factory.createImportDeclaration(
|
|
52866
52914
|
/*decorators*/ undefined,
|
|
52867
|
-
/*modifiers*/ undefined, ts.factory.createImportClause(/*isTypeOnly*/ false, /*name*/ undefined, ts.factory.createNamedImports([ts.factory.createImportSpecifier(
|
|
52915
|
+
/*modifiers*/ undefined, ts.factory.createImportClause(/*isTypeOnly*/ false, /*name*/ undefined, ts.factory.createNamedImports([ts.factory.createImportSpecifier(
|
|
52916
|
+
/*isTypeOnly*/ false, propertyName && ts.isIdentifier(propertyName) ? ts.factory.createIdentifier(ts.idText(propertyName)) : undefined, ts.factory.createIdentifier(localName))])), ts.factory.createStringLiteral(specifier_1),
|
|
52868
52917
|
/*importClause*/ undefined), 0 /* None */);
|
|
52869
52918
|
break;
|
|
52870
52919
|
}
|
|
@@ -52948,7 +52997,8 @@ var ts;
|
|
|
52948
52997
|
/*modifiers*/ undefined, ts.factory.createImportClause(
|
|
52949
52998
|
/*isTypeOnly*/ false,
|
|
52950
52999
|
/*importClause*/ undefined, ts.factory.createNamedImports([
|
|
52951
|
-
ts.factory.createImportSpecifier(
|
|
53000
|
+
ts.factory.createImportSpecifier(
|
|
53001
|
+
/*isTypeOnly*/ false, localName !== verbatimTargetName ? ts.factory.createIdentifier(verbatimTargetName) : undefined, ts.factory.createIdentifier(localName))
|
|
52952
53002
|
])), ts.factory.createStringLiteral(getSpecifierForModuleSymbol(target.parent || target, context)),
|
|
52953
53003
|
/*assertClause*/ undefined), 0 /* None */);
|
|
52954
53004
|
break;
|
|
@@ -52984,7 +53034,7 @@ var ts;
|
|
|
52984
53034
|
addResult(ts.factory.createExportDeclaration(
|
|
52985
53035
|
/*decorators*/ undefined,
|
|
52986
53036
|
/*modifiers*/ undefined,
|
|
52987
|
-
/*isTypeOnly*/ false, ts.factory.createNamedExports([ts.factory.createExportSpecifier(localName !== targetName ? targetName : undefined, localName)]), specifier), 0 /* None */);
|
|
53037
|
+
/*isTypeOnly*/ false, ts.factory.createNamedExports([ts.factory.createExportSpecifier(/*isTypeOnly*/ false, localName !== targetName ? targetName : undefined, localName)]), specifier), 0 /* None */);
|
|
52988
53038
|
}
|
|
52989
53039
|
/**
|
|
52990
53040
|
* Returns `true` if an export assignment or declaration was produced for the symbol
|
|
@@ -56479,6 +56529,23 @@ var ts;
|
|
|
56479
56529
|
function getIsLateCheckFlag(s) {
|
|
56480
56530
|
return ts.getCheckFlags(s) & 4096 /* Late */;
|
|
56481
56531
|
}
|
|
56532
|
+
function forEachMappedTypePropertyKeyTypeAndIndexSignatureKeyType(type, include, stringsOnly, cb) {
|
|
56533
|
+
for (var _i = 0, _a = getPropertiesOfType(type); _i < _a.length; _i++) {
|
|
56534
|
+
var prop = _a[_i];
|
|
56535
|
+
cb(getLiteralTypeFromProperty(prop, include));
|
|
56536
|
+
}
|
|
56537
|
+
if (type.flags & 1 /* Any */) {
|
|
56538
|
+
cb(stringType);
|
|
56539
|
+
}
|
|
56540
|
+
else {
|
|
56541
|
+
for (var _b = 0, _c = getIndexInfosOfType(type); _b < _c.length; _b++) {
|
|
56542
|
+
var info = _c[_b];
|
|
56543
|
+
if (!stringsOnly || info.keyType.flags & (4 /* String */ | 134217728 /* TemplateLiteral */)) {
|
|
56544
|
+
cb(info.keyType);
|
|
56545
|
+
}
|
|
56546
|
+
}
|
|
56547
|
+
}
|
|
56548
|
+
}
|
|
56482
56549
|
/** Resolve the members of a mapped type { [P in K]: T } */
|
|
56483
56550
|
function resolveMappedTypeMembers(type) {
|
|
56484
56551
|
var members = ts.createSymbolTable();
|
|
@@ -56496,21 +56563,7 @@ var ts;
|
|
|
56496
56563
|
var include = keyofStringsOnly ? 128 /* StringLiteral */ : 8576 /* StringOrNumberLiteralOrUnique */;
|
|
56497
56564
|
if (isMappedTypeWithKeyofConstraintDeclaration(type)) {
|
|
56498
56565
|
// We have a { [P in keyof T]: X }
|
|
56499
|
-
|
|
56500
|
-
var prop = _a[_i];
|
|
56501
|
-
addMemberForKeyType(getLiteralTypeFromProperty(prop, include));
|
|
56502
|
-
}
|
|
56503
|
-
if (modifiersType.flags & 1 /* Any */) {
|
|
56504
|
-
addMemberForKeyType(stringType);
|
|
56505
|
-
}
|
|
56506
|
-
else {
|
|
56507
|
-
for (var _b = 0, _c = getIndexInfosOfType(modifiersType); _b < _c.length; _b++) {
|
|
56508
|
-
var info = _c[_b];
|
|
56509
|
-
if (!keyofStringsOnly || info.keyType.flags & (4 /* String */ | 134217728 /* TemplateLiteral */)) {
|
|
56510
|
-
addMemberForKeyType(info.keyType);
|
|
56511
|
-
}
|
|
56512
|
-
}
|
|
56513
|
-
}
|
|
56566
|
+
forEachMappedTypePropertyKeyTypeAndIndexSignatureKeyType(modifiersType, include, keyofStringsOnly, addMemberForKeyType);
|
|
56514
56567
|
}
|
|
56515
56568
|
else {
|
|
56516
56569
|
forEachType(getLowerBoundOfKeyType(constraintType), addMemberForKeyType);
|
|
@@ -59627,18 +59680,56 @@ var ts;
|
|
|
59627
59680
|
type.resolvedStringIndexType || (type.resolvedStringIndexType = createIndexType(type, /*stringsOnly*/ true)) :
|
|
59628
59681
|
type.resolvedIndexType || (type.resolvedIndexType = createIndexType(type, /*stringsOnly*/ false));
|
|
59629
59682
|
}
|
|
59630
|
-
|
|
59631
|
-
|
|
59632
|
-
|
|
59633
|
-
|
|
59634
|
-
|
|
59635
|
-
|
|
59636
|
-
|
|
59637
|
-
|
|
59638
|
-
var
|
|
59639
|
-
|
|
59640
|
-
|
|
59641
|
-
|
|
59683
|
+
/**
|
|
59684
|
+
* This roughly mirrors `resolveMappedTypeMembers` in the nongeneric case, except only reports a union of the keys calculated,
|
|
59685
|
+
* rather than manufacturing the properties. We can't just fetch the `constraintType` since that would ignore mappings
|
|
59686
|
+
* and mapping the `constraintType` directly ignores how mapped types map _properties_ and not keys (thus ignoring subtype
|
|
59687
|
+
* reduction in the constraintType) when possible.
|
|
59688
|
+
* @param noIndexSignatures Indicates if _string_ index signatures should be elided. (other index signatures are always reported)
|
|
59689
|
+
*/
|
|
59690
|
+
function getIndexTypeForMappedType(type, stringsOnly, noIndexSignatures) {
|
|
59691
|
+
var typeParameter = getTypeParameterFromMappedType(type);
|
|
59692
|
+
var constraintType = getConstraintTypeFromMappedType(type);
|
|
59693
|
+
var nameType = getNameTypeFromMappedType(type.target || type);
|
|
59694
|
+
if (!nameType && !noIndexSignatures) {
|
|
59695
|
+
// no mapping and no filtering required, just quickly bail to returning the constraint in the common case
|
|
59696
|
+
return constraintType;
|
|
59697
|
+
}
|
|
59698
|
+
var keyTypes = [];
|
|
59699
|
+
if (isMappedTypeWithKeyofConstraintDeclaration(type)) {
|
|
59700
|
+
// We have a { [P in keyof T]: X }
|
|
59701
|
+
// `getApparentType` on the T in a generic mapped type can trigger a circularity
|
|
59702
|
+
// (conditionals and `infer` types create a circular dependency in the constraint resolution)
|
|
59703
|
+
// so we only eagerly manifest the keys if the constraint is nongeneric
|
|
59704
|
+
if (!isGenericIndexType(constraintType)) {
|
|
59705
|
+
var modifiersType = getApparentType(getModifiersTypeFromMappedType(type)); // The 'T' in 'keyof T'
|
|
59706
|
+
forEachMappedTypePropertyKeyTypeAndIndexSignatureKeyType(modifiersType, 8576 /* StringOrNumberLiteralOrUnique */, stringsOnly, addMemberForKeyType);
|
|
59707
|
+
}
|
|
59708
|
+
else {
|
|
59709
|
+
// we have a generic index and a homomorphic mapping (but a distributive key remapping) - we need to defer the whole `keyof whatever` for later
|
|
59710
|
+
// since it's not safe to resolve the shape of modifier type
|
|
59711
|
+
return getIndexTypeForGenericType(type, stringsOnly);
|
|
59712
|
+
}
|
|
59713
|
+
}
|
|
59714
|
+
else {
|
|
59715
|
+
forEachType(getLowerBoundOfKeyType(constraintType), addMemberForKeyType);
|
|
59716
|
+
}
|
|
59717
|
+
if (isGenericIndexType(constraintType)) { // include the generic component in the resulting type
|
|
59718
|
+
forEachType(constraintType, addMemberForKeyType);
|
|
59719
|
+
}
|
|
59720
|
+
// we had to pick apart the constraintType to potentially map/filter it - compare the final resulting list with the original constraintType,
|
|
59721
|
+
// so we can return the union that preserves aliases/origin data if possible
|
|
59722
|
+
var result = noIndexSignatures ? filterType(getUnionType(keyTypes), function (t) { return !(t.flags & (1 /* Any */ | 4 /* String */)); }) : getUnionType(keyTypes);
|
|
59723
|
+
if (result.flags & 1048576 /* Union */ && constraintType.flags & 1048576 /* Union */ && getTypeListId(result.types) === getTypeListId(constraintType.types)) {
|
|
59724
|
+
return constraintType;
|
|
59725
|
+
}
|
|
59726
|
+
return result;
|
|
59727
|
+
function addMemberForKeyType(keyType) {
|
|
59728
|
+
var propNameType = nameType ? instantiateType(nameType, appendTypeMapping(type.mapper, typeParameter, keyType)) : keyType;
|
|
59729
|
+
// `keyof` currently always returns `string | number` for concrete `string` index signatures - the below ternary keeps that behavior for mapped types
|
|
59730
|
+
// See `getLiteralTypeFromProperties` where there's a similar ternary to cause the same behavior.
|
|
59731
|
+
keyTypes.push(propNameType === stringType ? stringOrNumberType : propNameType);
|
|
59732
|
+
}
|
|
59642
59733
|
}
|
|
59643
59734
|
// Ordinarily we reduce a keyof M, where M is a mapped type { [P in K as N<P>]: X }, to simply N<K>. This however presumes
|
|
59644
59735
|
// that N distributes over union types, i.e. that N<A | B | C> is equivalent to N<A> | N<B> | N<C>. Specifically, we only
|
|
@@ -59696,7 +59787,7 @@ var ts;
|
|
|
59696
59787
|
return type.flags & 1048576 /* Union */ ? getIntersectionType(ts.map(type.types, function (t) { return getIndexType(t, stringsOnly, noIndexSignatures); })) :
|
|
59697
59788
|
type.flags & 2097152 /* Intersection */ ? getUnionType(ts.map(type.types, function (t) { return getIndexType(t, stringsOnly, noIndexSignatures); })) :
|
|
59698
59789
|
type.flags & 58982400 /* InstantiableNonPrimitive */ || isGenericTupleType(type) || isGenericMappedType(type) && !hasDistributiveNameType(type) ? getIndexTypeForGenericType(type, stringsOnly) :
|
|
59699
|
-
ts.getObjectFlags(type) & 32 /* Mapped */ ? getIndexTypeForMappedType(type, noIndexSignatures) :
|
|
59790
|
+
ts.getObjectFlags(type) & 32 /* Mapped */ ? getIndexTypeForMappedType(type, stringsOnly, noIndexSignatures) :
|
|
59700
59791
|
type === wildcardType ? wildcardType :
|
|
59701
59792
|
type.flags & 2 /* Unknown */ ? neverType :
|
|
59702
59793
|
type.flags & (1 /* Any */ | 131072 /* Never */) ? keyofConstraintType :
|
|
@@ -63455,24 +63546,24 @@ var ts;
|
|
|
63455
63546
|
}
|
|
63456
63547
|
}
|
|
63457
63548
|
else if (target.flags & 4194304 /* Index */) {
|
|
63458
|
-
var
|
|
63549
|
+
var targetType_1 = target.type;
|
|
63459
63550
|
// A keyof S is related to a keyof T if T is related to S.
|
|
63460
63551
|
if (source.flags & 4194304 /* Index */) {
|
|
63461
|
-
if (result = isRelatedTo(
|
|
63552
|
+
if (result = isRelatedTo(targetType_1, source.type, /*reportErrors*/ false)) {
|
|
63462
63553
|
return result;
|
|
63463
63554
|
}
|
|
63464
63555
|
}
|
|
63465
|
-
if (isTupleType(
|
|
63556
|
+
if (isTupleType(targetType_1)) {
|
|
63466
63557
|
// An index type can have a tuple type target when the tuple type contains variadic elements.
|
|
63467
63558
|
// Check if the source is related to the known keys of the tuple type.
|
|
63468
|
-
if (result = isRelatedTo(source, getKnownKeysOfTupleType(
|
|
63559
|
+
if (result = isRelatedTo(source, getKnownKeysOfTupleType(targetType_1), reportErrors)) {
|
|
63469
63560
|
return result;
|
|
63470
63561
|
}
|
|
63471
63562
|
}
|
|
63472
63563
|
else {
|
|
63473
63564
|
// A type S is assignable to keyof T if S is assignable to keyof C, where C is the
|
|
63474
63565
|
// simplified form of T or, if T doesn't simplify, the constraint of T.
|
|
63475
|
-
var constraint = getSimplifiedTypeOrConstraint(
|
|
63566
|
+
var constraint = getSimplifiedTypeOrConstraint(targetType_1);
|
|
63476
63567
|
if (constraint) {
|
|
63477
63568
|
// We require Ternary.True here such that circular constraints don't cause
|
|
63478
63569
|
// false positives. For example, given 'T extends { [K in keyof T]: string }',
|
|
@@ -63482,6 +63573,30 @@ var ts;
|
|
|
63482
63573
|
return -1 /* True */;
|
|
63483
63574
|
}
|
|
63484
63575
|
}
|
|
63576
|
+
else if (isGenericMappedType(targetType_1)) {
|
|
63577
|
+
// generic mapped types that don't simplify or have a constraint still have a very simple set of keys we can compare against
|
|
63578
|
+
// - their nameType or constraintType.
|
|
63579
|
+
// In many ways, this comparison is a deferred version of what `getIndexTypeForMappedType` does to actually resolve the keys for _non_-generic types
|
|
63580
|
+
var nameType_1 = getNameTypeFromMappedType(targetType_1);
|
|
63581
|
+
var constraintType = getConstraintTypeFromMappedType(targetType_1);
|
|
63582
|
+
var targetKeys = void 0;
|
|
63583
|
+
if (nameType_1 && isMappedTypeWithKeyofConstraintDeclaration(targetType_1)) {
|
|
63584
|
+
// we need to get the apparent mappings and union them with the generic mappings, since some properties may be
|
|
63585
|
+
// missing from the `constraintType` which will otherwise be mapped in the object
|
|
63586
|
+
var modifiersType = getApparentType(getModifiersTypeFromMappedType(targetType_1));
|
|
63587
|
+
var mappedKeys_1 = [];
|
|
63588
|
+
forEachMappedTypePropertyKeyTypeAndIndexSignatureKeyType(modifiersType, 8576 /* StringOrNumberLiteralOrUnique */,
|
|
63589
|
+
/*stringsOnly*/ false, function (t) { return void mappedKeys_1.push(instantiateType(nameType_1, appendTypeMapping(targetType_1.mapper, getTypeParameterFromMappedType(targetType_1), t))); });
|
|
63590
|
+
// We still need to include the non-apparent (and thus still generic) keys in the target side of the comparison (in case they're in the source side)
|
|
63591
|
+
targetKeys = getUnionType(__spreadArray(__spreadArray([], mappedKeys_1, true), [nameType_1], false));
|
|
63592
|
+
}
|
|
63593
|
+
else {
|
|
63594
|
+
targetKeys = nameType_1 || constraintType;
|
|
63595
|
+
}
|
|
63596
|
+
if (isRelatedTo(source, targetKeys, reportErrors) === -1 /* True */) {
|
|
63597
|
+
return -1 /* True */;
|
|
63598
|
+
}
|
|
63599
|
+
}
|
|
63485
63600
|
}
|
|
63486
63601
|
}
|
|
63487
63602
|
else if (target.flags & 8388608 /* IndexedAccess */) {
|
|
@@ -66512,8 +66627,16 @@ var ts;
|
|
|
66512
66627
|
function inferToTemplateLiteralType(source, target) {
|
|
66513
66628
|
var matches = inferTypesFromTemplateLiteralType(source, target);
|
|
66514
66629
|
var types = target.types;
|
|
66515
|
-
|
|
66516
|
-
|
|
66630
|
+
// When the target template literal contains only placeholders (meaning that inference is intended to extract
|
|
66631
|
+
// single characters and remainder strings) and inference fails to produce matches, we want to infer 'never' for
|
|
66632
|
+
// each placeholder such that instantiation with the inferred value(s) produces 'never', a type for which an
|
|
66633
|
+
// assignment check will fail. If we make no inferences, we'll likely end up with the constraint 'string' which,
|
|
66634
|
+
// upon instantiation, would collapse all the placeholders to just 'string', and an assignment check might
|
|
66635
|
+
// succeed. That would be a pointless and confusing outcome.
|
|
66636
|
+
if (matches || ts.every(target.texts, function (s) { return s.length === 0; })) {
|
|
66637
|
+
for (var i = 0; i < types.length; i++) {
|
|
66638
|
+
inferFromTypes(matches ? matches[i] : neverType, types[i]);
|
|
66639
|
+
}
|
|
66517
66640
|
}
|
|
66518
66641
|
}
|
|
66519
66642
|
function inferFromObjectTypes(source, target) {
|
|
@@ -70230,9 +70353,9 @@ var ts;
|
|
|
70230
70353
|
return getTypeOfPropertyOfContextualType(type, getSymbolOfNode(element).escapedName);
|
|
70231
70354
|
}
|
|
70232
70355
|
if (element.name) {
|
|
70233
|
-
var
|
|
70356
|
+
var nameType_2 = getLiteralTypeFromPropertyName(element.name);
|
|
70234
70357
|
// We avoid calling getApplicableIndexInfo here because it performs potentially expensive intersection reduction.
|
|
70235
|
-
return mapType(type, function (t) { var _a; return (_a = findApplicableIndexInfo(getIndexInfosOfStructuredType(t),
|
|
70358
|
+
return mapType(type, function (t) { var _a; return (_a = findApplicableIndexInfo(getIndexInfosOfStructuredType(t), nameType_2)) === null || _a === void 0 ? void 0 : _a.type; }, /*noReductions*/ true);
|
|
70236
70359
|
}
|
|
70237
70360
|
}
|
|
70238
70361
|
return undefined;
|
|
@@ -82375,11 +82498,15 @@ var ts;
|
|
|
82375
82498
|
}
|
|
82376
82499
|
function checkGrammarExportDeclaration(node) {
|
|
82377
82500
|
var _a;
|
|
82378
|
-
|
|
82379
|
-
|
|
82380
|
-
|
|
82501
|
+
if (node.isTypeOnly) {
|
|
82502
|
+
if (((_a = node.exportClause) === null || _a === void 0 ? void 0 : _a.kind) === 272 /* NamedExports */) {
|
|
82503
|
+
return checkGrammarNamedImportsOrExports(node.exportClause);
|
|
82504
|
+
}
|
|
82505
|
+
else {
|
|
82506
|
+
return grammarErrorOnNode(node, ts.Diagnostics.Only_named_exports_may_use_export_type);
|
|
82507
|
+
}
|
|
82381
82508
|
}
|
|
82382
|
-
return
|
|
82509
|
+
return false;
|
|
82383
82510
|
}
|
|
82384
82511
|
function checkGrammarModuleElementContext(node, errorMessage) {
|
|
82385
82512
|
var isInAppropriateContext = node.parent.kind === 303 /* SourceFile */ || node.parent.kind === 261 /* ModuleBlock */ || node.parent.kind === 260 /* ModuleDeclaration */;
|
|
@@ -86054,11 +86181,24 @@ var ts;
|
|
|
86054
86181
|
return ambientModulesCache;
|
|
86055
86182
|
}
|
|
86056
86183
|
function checkGrammarImportClause(node) {
|
|
86184
|
+
var _a;
|
|
86057
86185
|
if (node.isTypeOnly && node.name && node.namedBindings) {
|
|
86058
86186
|
return grammarErrorOnNode(node, ts.Diagnostics.A_type_only_import_can_specify_a_default_import_or_named_bindings_but_not_both);
|
|
86059
86187
|
}
|
|
86188
|
+
if (node.isTypeOnly && ((_a = node.namedBindings) === null || _a === void 0 ? void 0 : _a.kind) === 268 /* NamedImports */) {
|
|
86189
|
+
return checkGrammarNamedImportsOrExports(node.namedBindings);
|
|
86190
|
+
}
|
|
86060
86191
|
return false;
|
|
86061
86192
|
}
|
|
86193
|
+
function checkGrammarNamedImportsOrExports(namedBindings) {
|
|
86194
|
+
return !!ts.forEach(namedBindings.elements, function (specifier) {
|
|
86195
|
+
if (specifier.isTypeOnly) {
|
|
86196
|
+
return grammarErrorOnFirstToken(specifier, specifier.kind === 269 /* ImportSpecifier */
|
|
86197
|
+
? ts.Diagnostics.The_type_modifier_cannot_be_used_on_a_named_import_when_import_type_is_used_on_its_import_statement
|
|
86198
|
+
: ts.Diagnostics.The_type_modifier_cannot_be_used_on_a_named_export_when_export_type_is_used_on_its_export_statement);
|
|
86199
|
+
}
|
|
86200
|
+
});
|
|
86201
|
+
}
|
|
86062
86202
|
function checkGrammarImportCallExpression(node) {
|
|
86063
86203
|
if (moduleKind === ts.ModuleKind.ES2015) {
|
|
86064
86204
|
return grammarErrorOnNode(node, ts.Diagnostics.Dynamic_imports_are_only_supported_when_the_module_flag_is_set_to_es2020_esnext_commonjs_amd_system_umd_node12_or_nodenext);
|
|
@@ -86790,7 +86930,7 @@ var ts;
|
|
|
86790
86930
|
return factory.updateNamedImports(node, nodesVisitor(node.elements, visitor, ts.isImportSpecifier));
|
|
86791
86931
|
case 269 /* ImportSpecifier */:
|
|
86792
86932
|
ts.Debug.type(node);
|
|
86793
|
-
return factory.updateImportSpecifier(node, nodeVisitor(node.propertyName, visitor, ts.isIdentifier), nodeVisitor(node.name, visitor, ts.isIdentifier));
|
|
86933
|
+
return factory.updateImportSpecifier(node, node.isTypeOnly, nodeVisitor(node.propertyName, visitor, ts.isIdentifier), nodeVisitor(node.name, visitor, ts.isIdentifier));
|
|
86794
86934
|
case 270 /* ExportAssignment */:
|
|
86795
86935
|
ts.Debug.type(node);
|
|
86796
86936
|
return factory.updateExportAssignment(node, nodesVisitor(node.decorators, visitor, ts.isDecorator), nodesVisitor(node.modifiers, visitor, ts.isModifier), nodeVisitor(node.expression, visitor, ts.isExpression));
|
|
@@ -86802,7 +86942,7 @@ var ts;
|
|
|
86802
86942
|
return factory.updateNamedExports(node, nodesVisitor(node.elements, visitor, ts.isExportSpecifier));
|
|
86803
86943
|
case 274 /* ExportSpecifier */:
|
|
86804
86944
|
ts.Debug.type(node);
|
|
86805
|
-
return factory.updateExportSpecifier(node, nodeVisitor(node.propertyName, visitor, ts.isIdentifier), nodeVisitor(node.name, visitor, ts.isIdentifier));
|
|
86945
|
+
return factory.updateExportSpecifier(node, node.isTypeOnly, nodeVisitor(node.propertyName, visitor, ts.isIdentifier), nodeVisitor(node.name, visitor, ts.isIdentifier));
|
|
86806
86946
|
// Module references
|
|
86807
86947
|
case 276 /* ExternalModuleReference */:
|
|
86808
86948
|
ts.Debug.type(node);
|
|
@@ -90743,9 +90883,11 @@ var ts;
|
|
|
90743
90883
|
return shouldEmitAliasDeclaration(node) ? node : undefined;
|
|
90744
90884
|
}
|
|
90745
90885
|
else {
|
|
90746
|
-
// Elide named imports if all of its import specifiers are elided.
|
|
90886
|
+
// Elide named imports if all of its import specifiers are elided and settings allow.
|
|
90887
|
+
var allowEmpty = compilerOptions.preserveValueImports && (compilerOptions.importsNotUsedAsValues === 1 /* Preserve */ ||
|
|
90888
|
+
compilerOptions.importsNotUsedAsValues === 2 /* Error */);
|
|
90747
90889
|
var elements = ts.visitNodes(node.elements, visitImportSpecifier, ts.isImportSpecifier);
|
|
90748
|
-
return ts.some(elements) ? factory.updateNamedImports(node, elements) : undefined;
|
|
90890
|
+
return allowEmpty || ts.some(elements) ? factory.updateNamedImports(node, elements) : undefined;
|
|
90749
90891
|
}
|
|
90750
90892
|
}
|
|
90751
90893
|
/**
|
|
@@ -90754,7 +90896,7 @@ var ts;
|
|
|
90754
90896
|
* @param node The import specifier node.
|
|
90755
90897
|
*/
|
|
90756
90898
|
function visitImportSpecifier(node) {
|
|
90757
|
-
return shouldEmitAliasDeclaration(node) ? node : undefined;
|
|
90899
|
+
return !node.isTypeOnly && shouldEmitAliasDeclaration(node) ? node : undefined;
|
|
90758
90900
|
}
|
|
90759
90901
|
/**
|
|
90760
90902
|
* Visits an export assignment, eliding it if it does not contain a clause that resolves
|
|
@@ -90783,12 +90925,10 @@ var ts;
|
|
|
90783
90925
|
// type checker doesn't know about any exports
|
|
90784
90926
|
return node;
|
|
90785
90927
|
}
|
|
90786
|
-
if (!resolver.isValueAliasDeclaration(node)) {
|
|
90787
|
-
// Elide the export declaration if it does not export a value.
|
|
90788
|
-
return undefined;
|
|
90789
|
-
}
|
|
90790
90928
|
// Elide the export declaration if all of its named exports are elided.
|
|
90791
|
-
var
|
|
90929
|
+
var allowEmpty = !!node.moduleSpecifier && (compilerOptions.importsNotUsedAsValues === 1 /* Preserve */ ||
|
|
90930
|
+
compilerOptions.importsNotUsedAsValues === 2 /* Error */);
|
|
90931
|
+
var exportClause = ts.visitNode(node.exportClause, function (bindings) { return visitNamedExportBindings(bindings, allowEmpty); }, ts.isNamedExportBindings);
|
|
90792
90932
|
return exportClause
|
|
90793
90933
|
? factory.updateExportDeclaration(node,
|
|
90794
90934
|
/*decorators*/ undefined,
|
|
@@ -90801,16 +90941,16 @@ var ts;
|
|
|
90801
90941
|
*
|
|
90802
90942
|
* @param node The named exports node.
|
|
90803
90943
|
*/
|
|
90804
|
-
function visitNamedExports(node) {
|
|
90944
|
+
function visitNamedExports(node, allowEmpty) {
|
|
90805
90945
|
// Elide the named exports if all of its export specifiers were elided.
|
|
90806
90946
|
var elements = ts.visitNodes(node.elements, visitExportSpecifier, ts.isExportSpecifier);
|
|
90807
|
-
return ts.some(elements) ? factory.updateNamedExports(node, elements) : undefined;
|
|
90947
|
+
return allowEmpty || ts.some(elements) ? factory.updateNamedExports(node, elements) : undefined;
|
|
90808
90948
|
}
|
|
90809
90949
|
function visitNamespaceExports(node) {
|
|
90810
90950
|
return factory.updateNamespaceExport(node, ts.visitNode(node.name, visitor, ts.isIdentifier));
|
|
90811
90951
|
}
|
|
90812
|
-
function visitNamedExportBindings(node) {
|
|
90813
|
-
return ts.isNamespaceExport(node) ? visitNamespaceExports(node) : visitNamedExports(node);
|
|
90952
|
+
function visitNamedExportBindings(node, allowEmpty) {
|
|
90953
|
+
return ts.isNamespaceExport(node) ? visitNamespaceExports(node) : visitNamedExports(node, allowEmpty);
|
|
90814
90954
|
}
|
|
90815
90955
|
/**
|
|
90816
90956
|
* Visits an export specifier, eliding it if it does not resolve to a value.
|
|
@@ -90819,7 +90959,7 @@ var ts;
|
|
|
90819
90959
|
*/
|
|
90820
90960
|
function visitExportSpecifier(node) {
|
|
90821
90961
|
// Elide an export specifier if it does not reference a value.
|
|
90822
|
-
return resolver.isValueAliasDeclaration(node) ? node : undefined;
|
|
90962
|
+
return !node.isTypeOnly && resolver.isValueAliasDeclaration(node) ? node : undefined;
|
|
90823
90963
|
}
|
|
90824
90964
|
/**
|
|
90825
90965
|
* Determines whether to emit an import equals declaration.
|
|
@@ -94420,7 +94560,7 @@ var ts;
|
|
|
94420
94560
|
currentFileState.utilizedImplicitRuntimeImports.set(importSource, specifierSourceImports);
|
|
94421
94561
|
}
|
|
94422
94562
|
var generatedName = factory.createUniqueName("_" + name, 16 /* Optimistic */ | 32 /* FileLevel */ | 64 /* AllowNameSubstitution */);
|
|
94423
|
-
var specifier = factory.createImportSpecifier(factory.createIdentifier(name), generatedName);
|
|
94563
|
+
var specifier = factory.createImportSpecifier(/*isTypeOnly*/ false, factory.createIdentifier(name), generatedName);
|
|
94424
94564
|
generatedName.generatedImportReference = specifier;
|
|
94425
94565
|
specifierSourceImports.set(name, specifier);
|
|
94426
94566
|
return generatedName;
|
|
@@ -104136,7 +104276,7 @@ var ts;
|
|
|
104136
104276
|
/*modifiers*/ undefined, factory.createImportClause(
|
|
104137
104277
|
/*isTypeOnly*/ false,
|
|
104138
104278
|
/*name*/ undefined, factory.createNamedImports([
|
|
104139
|
-
factory.createImportSpecifier(factory.createIdentifier("createRequire"), createRequireName)
|
|
104279
|
+
factory.createImportSpecifier(/*isTypeOnly*/ false, factory.createIdentifier("createRequire"), createRequireName)
|
|
104140
104280
|
])), factory.createStringLiteral("module"));
|
|
104141
104281
|
var requireHelperName = factory.createUniqueName("__require", 16 /* Optimistic */ | 32 /* FileLevel */);
|
|
104142
104282
|
var requireStatement = factory.createVariableStatement(
|
|
@@ -104176,7 +104316,7 @@ var ts;
|
|
|
104176
104316
|
if (ts.hasSyntacticModifier(node, 1 /* Export */)) {
|
|
104177
104317
|
statements = ts.append(statements, factory.createExportDeclaration(
|
|
104178
104318
|
/*decorators*/ undefined,
|
|
104179
|
-
/*modifiers*/ undefined, node.isTypeOnly, factory.createNamedExports([factory.createExportSpecifier(/*propertyName*/ undefined, ts.idText(node.name))])));
|
|
104319
|
+
/*modifiers*/ undefined, node.isTypeOnly, factory.createNamedExports([factory.createExportSpecifier(/*isTypeOnly*/ false, /*propertyName*/ undefined, ts.idText(node.name))])));
|
|
104180
104320
|
}
|
|
104181
104321
|
return statements;
|
|
104182
104322
|
}
|
|
@@ -104204,7 +104344,7 @@ var ts;
|
|
|
104204
104344
|
var exportDecl = ts.isExportNamespaceAsDefaultDeclaration(node) ? factory.createExportDefault(synthName) : factory.createExportDeclaration(
|
|
104205
104345
|
/*decorators*/ undefined,
|
|
104206
104346
|
/*modifiers*/ undefined,
|
|
104207
|
-
/*isTypeOnly*/ false, factory.createNamedExports([factory.createExportSpecifier(synthName, oldIdentifier)]));
|
|
104347
|
+
/*isTypeOnly*/ false, factory.createNamedExports([factory.createExportSpecifier(/*isTypeOnly*/ false, synthName, oldIdentifier)]));
|
|
104208
104348
|
ts.setOriginalNode(exportDecl, node);
|
|
104209
104349
|
return [importDecl, exportDecl];
|
|
104210
104350
|
}
|
|
@@ -105771,7 +105911,7 @@ var ts;
|
|
|
105771
105911
|
/*modifiers*/ undefined,
|
|
105772
105912
|
/*isTypeOnly*/ false, factory.createNamedExports(ts.map(exportMappings_1, function (_a) {
|
|
105773
105913
|
var gen = _a[0], exp = _a[1];
|
|
105774
|
-
return factory.createExportSpecifier(gen, exp);
|
|
105914
|
+
return factory.createExportSpecifier(/*isTypeOnly*/ false, gen, exp);
|
|
105775
105915
|
}))));
|
|
105776
105916
|
}
|
|
105777
105917
|
var namespaceDecl = factory.createModuleDeclaration(/*decorators*/ undefined, ensureModifiers(input), input.name, factory.createModuleBlock(declarations), 16 /* Namespace */);
|
|
@@ -109710,6 +109850,10 @@ var ts;
|
|
|
109710
109850
|
writePunctuation("}");
|
|
109711
109851
|
}
|
|
109712
109852
|
function emitImportOrExportSpecifier(node) {
|
|
109853
|
+
if (node.isTypeOnly) {
|
|
109854
|
+
writeKeyword("type");
|
|
109855
|
+
writeSpace();
|
|
109856
|
+
}
|
|
109713
109857
|
if (node.propertyName) {
|
|
109714
109858
|
emit(node.propertyName);
|
|
109715
109859
|
writeSpace();
|
|
@@ -123750,6 +123894,10 @@ var ts;
|
|
|
123750
123894
|
return node.kind === 151 /* TypeKeyword */;
|
|
123751
123895
|
}
|
|
123752
123896
|
ts.isTypeKeywordToken = isTypeKeywordToken;
|
|
123897
|
+
function isTypeKeywordTokenOrIdentifier(node) {
|
|
123898
|
+
return isTypeKeywordToken(node) || ts.isIdentifier(node) && node.text === "type";
|
|
123899
|
+
}
|
|
123900
|
+
ts.isTypeKeywordTokenOrIdentifier = isTypeKeywordTokenOrIdentifier;
|
|
123753
123901
|
/** True if the symbol is for an external module, as opposed to a namespace. */
|
|
123754
123902
|
function isExternalModuleSymbol(moduleSymbol) {
|
|
123755
123903
|
return !!(moduleSymbol.flags & 1536 /* Module */) && moduleSymbol.name.charCodeAt(0) === 34 /* doubleQuote */;
|
|
@@ -126714,7 +126862,7 @@ var ts;
|
|
|
126714
126862
|
return convertPathCompletions(completion.paths);
|
|
126715
126863
|
case 1 /* Properties */: {
|
|
126716
126864
|
var entries = [];
|
|
126717
|
-
Completions.getCompletionEntriesFromSymbols(completion.symbols, entries, contextToken, sourceFile, sourceFile, checker, 99 /* ESNext */, log, 4 /* String */, preferences, options); // Target will not be used, so arbitrary
|
|
126865
|
+
Completions.getCompletionEntriesFromSymbols(completion.symbols, entries, contextToken, contextToken, sourceFile, sourceFile, checker, 99 /* ESNext */, log, 4 /* String */, preferences, options); // Target will not be used, so arbitrary
|
|
126718
126866
|
return { isGlobalCompletion: false, isMemberCompletion: true, isNewIdentifierLocation: completion.hasIndexSignature, optionalReplacementSpan: optionalReplacementSpan, entries: entries };
|
|
126719
126867
|
}
|
|
126720
126868
|
case 2 /* Types */: {
|
|
@@ -127486,6 +127634,7 @@ var ts;
|
|
|
127486
127634
|
KeywordCompletionFilters[KeywordCompletionFilters["FunctionLikeBodyKeywords"] = 5] = "FunctionLikeBodyKeywords";
|
|
127487
127635
|
KeywordCompletionFilters[KeywordCompletionFilters["TypeAssertionKeywords"] = 6] = "TypeAssertionKeywords";
|
|
127488
127636
|
KeywordCompletionFilters[KeywordCompletionFilters["TypeKeywords"] = 7] = "TypeKeywords";
|
|
127637
|
+
KeywordCompletionFilters[KeywordCompletionFilters["TypeKeyword"] = 8] = "TypeKeyword";
|
|
127489
127638
|
KeywordCompletionFilters[KeywordCompletionFilters["Last"] = 7] = "Last";
|
|
127490
127639
|
})(KeywordCompletionFilters || (KeywordCompletionFilters = {}));
|
|
127491
127640
|
var GlobalsSearch;
|
|
@@ -127587,7 +127736,7 @@ var ts;
|
|
|
127587
127736
|
case 3 /* JsDocParameterName */:
|
|
127588
127737
|
return jsdocCompletionInfo(ts.JsDoc.getJSDocParameterNameCompletions(completionData.tag));
|
|
127589
127738
|
case 4 /* Keywords */:
|
|
127590
|
-
return specificKeywordCompletionInfo(completionData.
|
|
127739
|
+
return specificKeywordCompletionInfo(completionData.keywordCompletions, completionData.isNewIdentifierLocation);
|
|
127591
127740
|
default:
|
|
127592
127741
|
return ts.Debug.assertNever(completionData);
|
|
127593
127742
|
}
|
|
@@ -127638,25 +127787,41 @@ var ts;
|
|
|
127638
127787
|
function jsdocCompletionInfo(entries) {
|
|
127639
127788
|
return { isGlobalCompletion: false, isMemberCompletion: false, isNewIdentifierLocation: false, entries: entries };
|
|
127640
127789
|
}
|
|
127641
|
-
function
|
|
127790
|
+
function keywordToCompletionEntry(keyword) {
|
|
127791
|
+
return {
|
|
127792
|
+
name: ts.tokenToString(keyword),
|
|
127793
|
+
kind: "keyword" /* keyword */,
|
|
127794
|
+
kindModifiers: "" /* none */,
|
|
127795
|
+
sortText: SortText.GlobalsOrKeywords,
|
|
127796
|
+
};
|
|
127797
|
+
}
|
|
127798
|
+
function specificKeywordCompletionInfo(entries, isNewIdentifierLocation) {
|
|
127642
127799
|
return {
|
|
127643
127800
|
isGlobalCompletion: false,
|
|
127644
127801
|
isMemberCompletion: false,
|
|
127645
|
-
isNewIdentifierLocation:
|
|
127646
|
-
entries:
|
|
127647
|
-
name: ts.tokenToString(k),
|
|
127648
|
-
kind: "keyword" /* keyword */,
|
|
127649
|
-
kindModifiers: "" /* none */,
|
|
127650
|
-
sortText: SortText.GlobalsOrKeywords,
|
|
127651
|
-
}); }),
|
|
127802
|
+
isNewIdentifierLocation: isNewIdentifierLocation,
|
|
127803
|
+
entries: entries.slice(),
|
|
127652
127804
|
};
|
|
127653
127805
|
}
|
|
127806
|
+
function keywordCompletionData(keywordFilters, filterOutTsOnlyKeywords, isNewIdentifierLocation) {
|
|
127807
|
+
return {
|
|
127808
|
+
kind: 4 /* Keywords */,
|
|
127809
|
+
keywordCompletions: getKeywordCompletions(keywordFilters, filterOutTsOnlyKeywords),
|
|
127810
|
+
isNewIdentifierLocation: isNewIdentifierLocation,
|
|
127811
|
+
};
|
|
127812
|
+
}
|
|
127813
|
+
function keywordFiltersFromSyntaxKind(keywordCompletion) {
|
|
127814
|
+
switch (keywordCompletion) {
|
|
127815
|
+
case 151 /* TypeKeyword */: return 8 /* TypeKeyword */;
|
|
127816
|
+
default: ts.Debug.fail("Unknown mapping from SyntaxKind to KeywordCompletionFilters");
|
|
127817
|
+
}
|
|
127818
|
+
}
|
|
127654
127819
|
function getOptionalReplacementSpan(location) {
|
|
127655
127820
|
// StringLiteralLike locations are handled separately in stringCompletions.ts
|
|
127656
127821
|
return (location === null || location === void 0 ? void 0 : location.kind) === 79 /* Identifier */ ? ts.createTextSpanFromNode(location) : undefined;
|
|
127657
127822
|
}
|
|
127658
127823
|
function completionInfoFromData(sourceFile, typeChecker, compilerOptions, log, completionData, preferences) {
|
|
127659
|
-
var symbols = completionData.symbols, 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;
|
|
127824
|
+
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;
|
|
127660
127825
|
// Verify if the file is JSX language variant
|
|
127661
127826
|
if (ts.getLanguageVariant(sourceFile.scriptKind) === 1 /* JSX */) {
|
|
127662
127827
|
var completionInfo = getJsxClosingTagCompletion(location, sourceFile);
|
|
@@ -127667,7 +127832,7 @@ var ts;
|
|
|
127667
127832
|
var entries = [];
|
|
127668
127833
|
if (isUncheckedFile(sourceFile, compilerOptions)) {
|
|
127669
127834
|
var uniqueNames = getCompletionEntriesFromSymbols(symbols, entries,
|
|
127670
|
-
/*
|
|
127835
|
+
/*replacementToken*/ undefined, contextToken, location, sourceFile, typeChecker, ts.getEmitScriptTarget(compilerOptions), log, completionKind, preferences, compilerOptions, isTypeOnlyLocation, propertyAccessToConvert, isJsxIdentifierExpected, isJsxInitializer, importCompletionNode, recommendedCompletion, symbolToOriginInfoMap, symbolToSortTextIdMap);
|
|
127671
127836
|
getJSCompletionEntries(sourceFile, location.pos, uniqueNames, ts.getEmitScriptTarget(compilerOptions), entries); // TODO: GH#18217
|
|
127672
127837
|
}
|
|
127673
127838
|
else {
|
|
@@ -127675,7 +127840,7 @@ var ts;
|
|
|
127675
127840
|
return undefined;
|
|
127676
127841
|
}
|
|
127677
127842
|
getCompletionEntriesFromSymbols(symbols, entries,
|
|
127678
|
-
/*
|
|
127843
|
+
/*replacementToken*/ undefined, contextToken, location, sourceFile, typeChecker, ts.getEmitScriptTarget(compilerOptions), log, completionKind, preferences, compilerOptions, isTypeOnlyLocation, propertyAccessToConvert, isJsxIdentifierExpected, isJsxInitializer, importCompletionNode, recommendedCompletion, symbolToOriginInfoMap, symbolToSortTextIdMap);
|
|
127679
127844
|
}
|
|
127680
127845
|
if (keywordFilters !== 0 /* None */) {
|
|
127681
127846
|
var entryNames = new ts.Set(entries.map(function (e) { return e.name; }));
|
|
@@ -127781,10 +127946,10 @@ var ts;
|
|
|
127781
127946
|
function createCompletionEntryForLiteral(sourceFile, preferences, literal) {
|
|
127782
127947
|
return { name: completionNameForLiteral(sourceFile, preferences, literal), kind: "string" /* string */, kindModifiers: "" /* none */, sortText: SortText.LocationPriority };
|
|
127783
127948
|
}
|
|
127784
|
-
function createCompletionEntry(symbol, sortText, contextToken, location, sourceFile, typeChecker, name, needsConvertPropertyAccess, origin, recommendedCompletion, propertyAccessToConvert, isJsxInitializer, importCompletionNode,
|
|
127949
|
+
function createCompletionEntry(symbol, sortText, replacementToken, contextToken, location, sourceFile, typeChecker, name, needsConvertPropertyAccess, origin, recommendedCompletion, propertyAccessToConvert, isJsxInitializer, importCompletionNode, useSemicolons, options, preferences) {
|
|
127785
127950
|
var _a;
|
|
127786
127951
|
var insertText;
|
|
127787
|
-
var replacementSpan = ts.getReplacementSpanForContextToken(
|
|
127952
|
+
var replacementSpan = ts.getReplacementSpanForContextToken(replacementToken);
|
|
127788
127953
|
var data;
|
|
127789
127954
|
var isSnippet;
|
|
127790
127955
|
var sourceDisplay;
|
|
@@ -127835,7 +128000,7 @@ var ts;
|
|
|
127835
128000
|
if (originIsResolvedExport(origin)) {
|
|
127836
128001
|
sourceDisplay = [ts.textPart(origin.moduleSpecifier)];
|
|
127837
128002
|
if (importCompletionNode) {
|
|
127838
|
-
(_a = getInsertTextAndReplacementSpanForImportCompletion(name, importCompletionNode,
|
|
128003
|
+
(_a = getInsertTextAndReplacementSpanForImportCompletion(name, importCompletionNode, contextToken, origin, useSemicolons, options, preferences), insertText = _a.insertText, replacementSpan = _a.replacementSpan);
|
|
127839
128004
|
isSnippet = preferences.includeCompletionsWithSnippetText ? true : undefined;
|
|
127840
128005
|
}
|
|
127841
128006
|
}
|
|
@@ -127908,22 +128073,26 @@ var ts;
|
|
|
127908
128073
|
moduleSpecifier: originIsResolvedExport(origin) ? origin.moduleSpecifier : undefined,
|
|
127909
128074
|
};
|
|
127910
128075
|
}
|
|
127911
|
-
function getInsertTextAndReplacementSpanForImportCompletion(name, importCompletionNode,
|
|
128076
|
+
function getInsertTextAndReplacementSpanForImportCompletion(name, importCompletionNode, contextToken, origin, useSemicolons, options, preferences) {
|
|
128077
|
+
var _a, _b, _c;
|
|
127912
128078
|
var sourceFile = importCompletionNode.getSourceFile();
|
|
127913
|
-
var replacementSpan = ts.createTextSpanFromNode(importCompletionNode, sourceFile);
|
|
128079
|
+
var replacementSpan = ts.createTextSpanFromNode(ts.findAncestor(importCompletionNode, ts.or(ts.isImportDeclaration, ts.isImportEqualsDeclaration)) || importCompletionNode, sourceFile);
|
|
127914
128080
|
var quotedModuleSpecifier = ts.quote(sourceFile, preferences, origin.moduleSpecifier);
|
|
127915
128081
|
var exportKind = origin.isDefaultExport ? 1 /* Default */ :
|
|
127916
128082
|
origin.exportName === "export=" /* ExportEquals */ ? 2 /* ExportEquals */ :
|
|
127917
128083
|
0 /* Named */;
|
|
127918
128084
|
var tabStop = preferences.includeCompletionsWithSnippetText ? "$1" : "";
|
|
127919
128085
|
var importKind = ts.codefix.getImportKind(sourceFile, exportKind, options, /*forceImportKeyword*/ true);
|
|
127920
|
-
var
|
|
128086
|
+
var isTopLevelTypeOnly = ((_b = (_a = ts.tryCast(importCompletionNode, ts.isImportDeclaration)) === null || _a === void 0 ? void 0 : _a.importClause) === null || _b === void 0 ? void 0 : _b.isTypeOnly) || ((_c = ts.tryCast(importCompletionNode, ts.isImportEqualsDeclaration)) === null || _c === void 0 ? void 0 : _c.isTypeOnly);
|
|
128087
|
+
var isImportSpecifierTypeOnly = couldBeTypeOnlyImportSpecifier(importCompletionNode, contextToken);
|
|
128088
|
+
var topLevelTypeOnlyText = isTopLevelTypeOnly ? " " + ts.tokenToString(151 /* TypeKeyword */) + " " : " ";
|
|
128089
|
+
var importSpecifierTypeOnlyText = isImportSpecifierTypeOnly ? ts.tokenToString(151 /* TypeKeyword */) + " " : "";
|
|
127921
128090
|
var suffix = useSemicolons ? ";" : "";
|
|
127922
128091
|
switch (importKind) {
|
|
127923
|
-
case 3 /* CommonJS */: return { replacementSpan: replacementSpan, insertText: "import" +
|
|
127924
|
-
case 1 /* Default */: return { replacementSpan: replacementSpan, insertText: "import" +
|
|
127925
|
-
case 2 /* Namespace */: return { replacementSpan: replacementSpan, insertText: "import" +
|
|
127926
|
-
case 0 /* Named */: return { replacementSpan: replacementSpan, insertText: "import" +
|
|
128092
|
+
case 3 /* CommonJS */: return { replacementSpan: replacementSpan, insertText: "import" + topLevelTypeOnlyText + escapeSnippetText(name) + tabStop + " = require(" + quotedModuleSpecifier + ")" + suffix };
|
|
128093
|
+
case 1 /* Default */: return { replacementSpan: replacementSpan, insertText: "import" + topLevelTypeOnlyText + escapeSnippetText(name) + tabStop + " from " + quotedModuleSpecifier + suffix };
|
|
128094
|
+
case 2 /* Namespace */: return { replacementSpan: replacementSpan, insertText: "import" + topLevelTypeOnlyText + "* as " + escapeSnippetText(name) + " from " + quotedModuleSpecifier + suffix };
|
|
128095
|
+
case 0 /* Named */: return { replacementSpan: replacementSpan, insertText: "import" + topLevelTypeOnlyText + "{ " + importSpecifierTypeOnlyText + escapeSnippetText(name) + tabStop + " } from " + quotedModuleSpecifier + suffix };
|
|
127927
128096
|
}
|
|
127928
128097
|
}
|
|
127929
128098
|
function quotePropertyName(sourceFile, preferences, name) {
|
|
@@ -127947,12 +128116,11 @@ var ts;
|
|
|
127947
128116
|
return CompletionSource.ThisProperty;
|
|
127948
128117
|
}
|
|
127949
128118
|
}
|
|
127950
|
-
function getCompletionEntriesFromSymbols(symbols, entries, contextToken, location, sourceFile, typeChecker, target, log, kind, preferences, compilerOptions, isTypeOnlyLocation, propertyAccessToConvert, jsxIdentifierExpected, isJsxInitializer, importCompletionNode, recommendedCompletion, symbolToOriginInfoMap, symbolToSortTextIdMap) {
|
|
128119
|
+
function getCompletionEntriesFromSymbols(symbols, entries, replacementToken, contextToken, location, sourceFile, typeChecker, target, log, kind, preferences, compilerOptions, isTypeOnlyLocation, propertyAccessToConvert, jsxIdentifierExpected, isJsxInitializer, importCompletionNode, recommendedCompletion, symbolToOriginInfoMap, symbolToSortTextIdMap) {
|
|
127951
128120
|
var _a;
|
|
127952
128121
|
var start = ts.timestamp();
|
|
127953
128122
|
var variableDeclaration = getVariableDeclaration(location);
|
|
127954
128123
|
var useSemicolons = ts.probablyUsesSemicolons(sourceFile);
|
|
127955
|
-
var isTypeOnlyImport = !!importCompletionNode && ts.isTypeOnlyImportOrExportDeclaration(location.parent);
|
|
127956
128124
|
// Tracks unique names.
|
|
127957
128125
|
// Value is set to false for global variables or completions from external module exports, because we can have multiple of those;
|
|
127958
128126
|
// true otherwise. Based on the order we add things we will always see locals first, then globals, then module exports.
|
|
@@ -127968,7 +128136,7 @@ var ts;
|
|
|
127968
128136
|
var name = info.name, needsConvertPropertyAccess = info.needsConvertPropertyAccess;
|
|
127969
128137
|
var sortTextId = (_a = symbolToSortTextIdMap === null || symbolToSortTextIdMap === void 0 ? void 0 : symbolToSortTextIdMap[ts.getSymbolId(symbol)]) !== null && _a !== void 0 ? _a : 11 /* LocationPriority */;
|
|
127970
128138
|
var sortText = (isDeprecated(symbol, typeChecker) ? 8 /* DeprecatedOffset */ + sortTextId : sortTextId).toString();
|
|
127971
|
-
var entry = createCompletionEntry(symbol, sortText, contextToken, location, sourceFile, typeChecker, name, needsConvertPropertyAccess, origin, recommendedCompletion, propertyAccessToConvert, isJsxInitializer, importCompletionNode,
|
|
128139
|
+
var entry = createCompletionEntry(symbol, sortText, replacementToken, contextToken, location, sourceFile, typeChecker, name, needsConvertPropertyAccess, origin, recommendedCompletion, propertyAccessToConvert, isJsxInitializer, importCompletionNode, useSemicolons, compilerOptions, preferences);
|
|
127972
128140
|
if (!entry) {
|
|
127973
128141
|
continue;
|
|
127974
128142
|
}
|
|
@@ -128117,7 +128285,7 @@ var ts;
|
|
|
128117
128285
|
case 3 /* JsDocParameterName */:
|
|
128118
128286
|
return ts.JsDoc.getJSDocParameterNameCompletionDetails(name);
|
|
128119
128287
|
case 4 /* Keywords */:
|
|
128120
|
-
return
|
|
128288
|
+
return ts.some(request.keywordCompletions, function (c) { return c.name === name; }) ? createSimpleDetails(name, "keyword" /* keyword */, ts.SymbolDisplayPartKind.keyword) : undefined;
|
|
128121
128289
|
default:
|
|
128122
128290
|
return ts.Debug.assertNever(request);
|
|
128123
128291
|
}
|
|
@@ -128156,7 +128324,7 @@ var ts;
|
|
|
128156
128324
|
function getCompletionEntryCodeActionsAndSourceDisplay(origin, symbol, program, host, compilerOptions, sourceFile, position, previousToken, formatContext, preferences, data) {
|
|
128157
128325
|
if (data === null || data === void 0 ? void 0 : data.moduleSpecifier) {
|
|
128158
128326
|
var _a = getRelevantTokens(position, sourceFile), contextToken = _a.contextToken, previousToken_1 = _a.previousToken;
|
|
128159
|
-
if (previousToken_1 &&
|
|
128327
|
+
if (previousToken_1 && getImportStatementCompletionInfo(contextToken || previousToken_1).replacementNode) {
|
|
128160
128328
|
// Import statement completion: 'import c|'
|
|
128161
128329
|
return { codeActions: undefined, sourceDisplay: [ts.textPart(data.moduleSpecifier)] };
|
|
128162
128330
|
}
|
|
@@ -128319,6 +128487,7 @@ var ts;
|
|
|
128319
128487
|
start = ts.timestamp();
|
|
128320
128488
|
// The decision to provide completion depends on the contextToken, which is determined through the previousToken.
|
|
128321
128489
|
// Note: 'previousToken' (and thus 'contextToken') can be undefined if we are the beginning of the file
|
|
128490
|
+
var isJsOnlyLocation = !insideJsDocTagTypeExpression && ts.isSourceFileJS(sourceFile);
|
|
128322
128491
|
var tokens = getRelevantTokens(position, sourceFile);
|
|
128323
128492
|
var previousToken = tokens.previousToken;
|
|
128324
128493
|
var contextToken = tokens.contextToken;
|
|
@@ -128336,22 +128505,34 @@ var ts;
|
|
|
128336
128505
|
var isJsxIdentifierExpected = false;
|
|
128337
128506
|
var importCompletionNode;
|
|
128338
128507
|
var location = ts.getTouchingPropertyName(sourceFile, position);
|
|
128508
|
+
var keywordFilters = 0 /* None */;
|
|
128509
|
+
var isNewIdentifierLocation = false;
|
|
128339
128510
|
if (contextToken) {
|
|
128340
|
-
var
|
|
128341
|
-
|
|
128342
|
-
|
|
128511
|
+
var importStatementCompletion = getImportStatementCompletionInfo(contextToken);
|
|
128512
|
+
isNewIdentifierLocation = importStatementCompletion.isNewIdentifierLocation;
|
|
128513
|
+
if (importStatementCompletion.keywordCompletion) {
|
|
128514
|
+
if (importStatementCompletion.isKeywordOnlyCompletion) {
|
|
128515
|
+
return {
|
|
128516
|
+
kind: 4 /* Keywords */,
|
|
128517
|
+
keywordCompletions: [keywordToCompletionEntry(importStatementCompletion.keywordCompletion)],
|
|
128518
|
+
isNewIdentifierLocation: isNewIdentifierLocation,
|
|
128519
|
+
};
|
|
128520
|
+
}
|
|
128521
|
+
keywordFilters = keywordFiltersFromSyntaxKind(importStatementCompletion.keywordCompletion);
|
|
128343
128522
|
}
|
|
128344
|
-
|
|
128345
|
-
|
|
128346
|
-
|
|
128347
|
-
|
|
128348
|
-
|
|
128349
|
-
importCompletionNode =
|
|
128523
|
+
if (importStatementCompletion.replacementNode && preferences.includeCompletionsForImportStatements && preferences.includeCompletionsWithInsertText) {
|
|
128524
|
+
// Import statement completions use `insertText`, and also require the `data` property of `CompletionEntryIdentifier`
|
|
128525
|
+
// added in TypeScript 4.3 to be sent back from the client during `getCompletionEntryDetails`. Since this feature
|
|
128526
|
+
// is not backward compatible with older clients, the language service defaults to disabling it, allowing newer clients
|
|
128527
|
+
// to opt in with the `includeCompletionsForImportStatements` user preference.
|
|
128528
|
+
importCompletionNode = importStatementCompletion.replacementNode;
|
|
128350
128529
|
}
|
|
128351
128530
|
// Bail out if this is a known invalid completion location
|
|
128352
128531
|
if (!importCompletionNode && isCompletionListBlocker(contextToken)) {
|
|
128353
128532
|
log("Returning an empty list because completion was requested in an invalid position.");
|
|
128354
|
-
return
|
|
128533
|
+
return keywordFilters
|
|
128534
|
+
? keywordCompletionData(keywordFilters, isJsOnlyLocation, isNewIdentifierDefinitionLocation())
|
|
128535
|
+
: undefined;
|
|
128355
128536
|
}
|
|
128356
128537
|
var parent = contextToken.parent;
|
|
128357
128538
|
if (contextToken.kind === 24 /* DotToken */ || contextToken.kind === 28 /* QuestionDotToken */) {
|
|
@@ -128471,10 +128652,8 @@ var ts;
|
|
|
128471
128652
|
}
|
|
128472
128653
|
var semanticStart = ts.timestamp();
|
|
128473
128654
|
var completionKind = 5 /* None */;
|
|
128474
|
-
var isNewIdentifierLocation = false;
|
|
128475
128655
|
var isNonContextualObjectLiteral = false;
|
|
128476
128656
|
var hasUnresolvedAutoImports = false;
|
|
128477
|
-
var keywordFilters = 0 /* None */;
|
|
128478
128657
|
// This also gets mutated in nested-functions after the return
|
|
128479
128658
|
var symbols = [];
|
|
128480
128659
|
var symbolToOriginInfoMap = [];
|
|
@@ -128508,7 +128687,9 @@ var ts;
|
|
|
128508
128687
|
// global symbols in scope. These results should be valid for either language as
|
|
128509
128688
|
// the set of symbols that can be referenced from this location.
|
|
128510
128689
|
if (!tryGetGlobalSymbols()) {
|
|
128511
|
-
return
|
|
128690
|
+
return keywordFilters
|
|
128691
|
+
? keywordCompletionData(keywordFilters, isJsOnlyLocation, isNewIdentifierLocation)
|
|
128692
|
+
: undefined;
|
|
128512
128693
|
}
|
|
128513
128694
|
}
|
|
128514
128695
|
log("getCompletionData: Semantic work: " + (ts.timestamp() - semanticStart));
|
|
@@ -128528,6 +128709,7 @@ var ts;
|
|
|
128528
128709
|
symbolToOriginInfoMap: symbolToOriginInfoMap,
|
|
128529
128710
|
recommendedCompletion: recommendedCompletion,
|
|
128530
128711
|
previousToken: previousToken,
|
|
128712
|
+
contextToken: contextToken,
|
|
128531
128713
|
isJsxInitializer: isJsxInitializer,
|
|
128532
128714
|
insideJsDocTagTypeExpression: insideJsDocTagTypeExpression,
|
|
128533
128715
|
symbolToSortTextIdMap: symbolToSortTextIdMap,
|
|
@@ -128914,8 +129096,14 @@ var ts;
|
|
|
128914
129096
|
// Asking for completion details for an item that is not an auto-import
|
|
128915
129097
|
return;
|
|
128916
129098
|
}
|
|
129099
|
+
// import { type | -> token text should be blank
|
|
129100
|
+
var isAfterTypeOnlyImportSpecifierModifier = previousToken === contextToken
|
|
129101
|
+
&& importCompletionNode
|
|
129102
|
+
&& couldBeTypeOnlyImportSpecifier(importCompletionNode, contextToken);
|
|
129103
|
+
var lowerCaseTokenText = isAfterTypeOnlyImportSpecifierModifier ? "" :
|
|
129104
|
+
previousToken && ts.isIdentifier(previousToken) ? previousToken.text.toLowerCase() :
|
|
129105
|
+
"";
|
|
128917
129106
|
var moduleSpecifierCache = (_a = host.getModuleSpecifierCache) === null || _a === void 0 ? void 0 : _a.call(host);
|
|
128918
|
-
var lowerCaseTokenText = previousToken && ts.isIdentifier(previousToken) ? previousToken.text.toLowerCase() : "";
|
|
128919
129107
|
var exportInfo = ts.getExportInfoMap(sourceFile, host, program, cancellationToken);
|
|
128920
129108
|
var packageJsonAutoImportProvider = (_b = host.getPackageJsonAutoImportProvider) === null || _b === void 0 ? void 0 : _b.call(host);
|
|
128921
129109
|
var packageJsonFilter = detailsEntryId ? undefined : ts.createPackageJsonImportFilter(sourceFile, preferences, host);
|
|
@@ -129048,6 +129236,7 @@ var ts;
|
|
|
129048
129236
|
|| containingNodeKind === 161 /* ComputedPropertyName */; // [ | /* this can become an index signature */
|
|
129049
129237
|
case 141 /* ModuleKeyword */: // module |
|
|
129050
129238
|
case 142 /* NamespaceKeyword */: // namespace |
|
|
129239
|
+
case 100 /* ImportKeyword */: // import |
|
|
129051
129240
|
return true;
|
|
129052
129241
|
case 24 /* DotToken */:
|
|
129053
129242
|
return containingNodeKind === 260 /* ModuleDeclaration */; // module A.|
|
|
@@ -129186,23 +129375,38 @@ var ts;
|
|
|
129186
129375
|
* Relevant symbols are stored in the captured 'symbols' variable.
|
|
129187
129376
|
*/
|
|
129188
129377
|
function tryGetImportOrExportClauseCompletionSymbols() {
|
|
129189
|
-
|
|
129190
|
-
|
|
129191
|
-
|
|
129378
|
+
if (!contextToken)
|
|
129379
|
+
return 0 /* Continue */;
|
|
129380
|
+
// `import { |` or `import { a as 0, | }` or `import { type | }`
|
|
129381
|
+
var namedImportsOrExports = contextToken.kind === 18 /* OpenBraceToken */ || contextToken.kind === 27 /* CommaToken */ ? ts.tryCast(contextToken.parent, ts.isNamedImportsOrExports) :
|
|
129382
|
+
ts.isTypeKeywordTokenOrIdentifier(contextToken) ? ts.tryCast(contextToken.parent.parent, ts.isNamedImportsOrExports) : undefined;
|
|
129192
129383
|
if (!namedImportsOrExports)
|
|
129193
129384
|
return 0 /* Continue */;
|
|
129385
|
+
// We can at least offer `type` at `import { |`
|
|
129386
|
+
if (!ts.isTypeKeywordTokenOrIdentifier(contextToken)) {
|
|
129387
|
+
keywordFilters = 8 /* TypeKeyword */;
|
|
129388
|
+
}
|
|
129194
129389
|
// try to show exported member for imported/re-exported module
|
|
129195
129390
|
var moduleSpecifier = (namedImportsOrExports.kind === 268 /* NamedImports */ ? namedImportsOrExports.parent.parent : namedImportsOrExports.parent).moduleSpecifier;
|
|
129196
|
-
if (!moduleSpecifier)
|
|
129391
|
+
if (!moduleSpecifier) {
|
|
129392
|
+
isNewIdentifierLocation = true;
|
|
129197
129393
|
return namedImportsOrExports.kind === 268 /* NamedImports */ ? 2 /* Fail */ : 0 /* Continue */;
|
|
129394
|
+
}
|
|
129198
129395
|
var moduleSpecifierSymbol = typeChecker.getSymbolAtLocation(moduleSpecifier); // TODO: GH#18217
|
|
129199
|
-
if (!moduleSpecifierSymbol)
|
|
129396
|
+
if (!moduleSpecifierSymbol) {
|
|
129397
|
+
isNewIdentifierLocation = true;
|
|
129200
129398
|
return 2 /* Fail */;
|
|
129399
|
+
}
|
|
129201
129400
|
completionKind = 3 /* MemberLike */;
|
|
129202
129401
|
isNewIdentifierLocation = false;
|
|
129203
129402
|
var exports = typeChecker.getExportsAndPropertiesOfModule(moduleSpecifierSymbol);
|
|
129204
129403
|
var existing = new ts.Set(namedImportsOrExports.elements.filter(function (n) { return !isCurrentlyEditingNode(n); }).map(function (n) { return (n.propertyName || n.name).escapedText; }));
|
|
129205
|
-
|
|
129404
|
+
var uniques = exports.filter(function (e) { return e.escapedName !== "default" /* Default */ && !existing.has(e.escapedName); });
|
|
129405
|
+
symbols = ts.concatenate(symbols, uniques);
|
|
129406
|
+
if (!uniques.length) {
|
|
129407
|
+
// If there's nothing else to import, don't offer `type` either
|
|
129408
|
+
keywordFilters = 0 /* None */;
|
|
129409
|
+
}
|
|
129206
129410
|
return 1 /* Success */;
|
|
129207
129411
|
}
|
|
129208
129412
|
/**
|
|
@@ -129463,6 +129667,14 @@ var ts;
|
|
|
129463
129667
|
case 136 /* GetKeyword */:
|
|
129464
129668
|
case 148 /* SetKeyword */:
|
|
129465
129669
|
return !isFromObjectTypeDeclaration(contextToken);
|
|
129670
|
+
case 79 /* Identifier */:
|
|
129671
|
+
if (containingNodeKind === 269 /* ImportSpecifier */ &&
|
|
129672
|
+
contextToken === parent.name &&
|
|
129673
|
+
contextToken.text === "type") {
|
|
129674
|
+
// import { type | }
|
|
129675
|
+
return false;
|
|
129676
|
+
}
|
|
129677
|
+
break;
|
|
129466
129678
|
case 84 /* ClassKeyword */:
|
|
129467
129679
|
case 92 /* EnumKeyword */:
|
|
129468
129680
|
case 118 /* InterfaceKeyword */:
|
|
@@ -129472,8 +129684,10 @@ var ts;
|
|
|
129472
129684
|
case 119 /* LetKeyword */:
|
|
129473
129685
|
case 85 /* ConstKeyword */:
|
|
129474
129686
|
case 137 /* InferKeyword */:
|
|
129475
|
-
case 151 /* TypeKeyword */: // type htm|
|
|
129476
129687
|
return true;
|
|
129688
|
+
case 151 /* TypeKeyword */:
|
|
129689
|
+
// import { type foo| }
|
|
129690
|
+
return containingNodeKind !== 269 /* ImportSpecifier */;
|
|
129477
129691
|
case 41 /* AsteriskToken */:
|
|
129478
129692
|
return ts.isFunctionLike(contextToken.parent) && !ts.isMethodDeclaration(contextToken.parent);
|
|
129479
129693
|
}
|
|
@@ -129834,6 +130048,8 @@ var ts;
|
|
|
129834
130048
|
return ts.isTypeKeyword(kind) || kind === 85 /* ConstKeyword */;
|
|
129835
130049
|
case 7 /* TypeKeywords */:
|
|
129836
130050
|
return ts.isTypeKeyword(kind);
|
|
130051
|
+
case 8 /* TypeKeyword */:
|
|
130052
|
+
return kind === 151 /* TypeKeyword */;
|
|
129837
130053
|
default:
|
|
129838
130054
|
return ts.Debug.assertNever(keywordFilter);
|
|
129839
130055
|
}
|
|
@@ -130107,34 +130323,67 @@ var ts;
|
|
|
130107
130323
|
}
|
|
130108
130324
|
return undefined;
|
|
130109
130325
|
}
|
|
130110
|
-
function
|
|
130326
|
+
function getImportStatementCompletionInfo(contextToken) {
|
|
130327
|
+
var keywordCompletion;
|
|
130328
|
+
var isKeywordOnlyCompletion = false;
|
|
130111
130329
|
var candidate = getCandidate();
|
|
130112
|
-
return
|
|
130330
|
+
return {
|
|
130331
|
+
isKeywordOnlyCompletion: isKeywordOnlyCompletion,
|
|
130332
|
+
keywordCompletion: keywordCompletion,
|
|
130333
|
+
isNewIdentifierLocation: !!(candidate || keywordCompletion === 151 /* TypeKeyword */),
|
|
130334
|
+
replacementNode: candidate && ts.rangeIsOnSingleLine(candidate, candidate.getSourceFile())
|
|
130335
|
+
? candidate
|
|
130336
|
+
: undefined
|
|
130337
|
+
};
|
|
130113
130338
|
function getCandidate() {
|
|
130114
130339
|
var parent = contextToken.parent;
|
|
130115
130340
|
if (ts.isImportEqualsDeclaration(parent)) {
|
|
130341
|
+
keywordCompletion = contextToken.kind === 151 /* TypeKeyword */ ? undefined : 151 /* TypeKeyword */;
|
|
130116
130342
|
return isModuleSpecifierMissingOrEmpty(parent.moduleReference) ? parent : undefined;
|
|
130117
130343
|
}
|
|
130344
|
+
if (couldBeTypeOnlyImportSpecifier(parent, contextToken) && canCompleteFromNamedBindings(parent.parent)) {
|
|
130345
|
+
return parent;
|
|
130346
|
+
}
|
|
130118
130347
|
if (ts.isNamedImports(parent) || ts.isNamespaceImport(parent)) {
|
|
130119
|
-
if (
|
|
130348
|
+
if (!parent.parent.isTypeOnly && (contextToken.kind === 18 /* OpenBraceToken */ ||
|
|
130349
|
+
contextToken.kind === 100 /* ImportKeyword */ ||
|
|
130350
|
+
contextToken.kind === 27 /* CommaToken */)) {
|
|
130351
|
+
keywordCompletion = 151 /* TypeKeyword */;
|
|
130352
|
+
}
|
|
130353
|
+
if (canCompleteFromNamedBindings(parent)) {
|
|
130120
130354
|
// At `import { ... } |` or `import * as Foo |`, the only possible completion is `from`
|
|
130121
|
-
|
|
130122
|
-
|
|
130123
|
-
|
|
130355
|
+
if (contextToken.kind === 19 /* CloseBraceToken */ || contextToken.kind === 79 /* Identifier */) {
|
|
130356
|
+
isKeywordOnlyCompletion = true;
|
|
130357
|
+
keywordCompletion = 155 /* FromKeyword */;
|
|
130358
|
+
}
|
|
130359
|
+
else {
|
|
130360
|
+
return parent.parent.parent;
|
|
130361
|
+
}
|
|
130124
130362
|
}
|
|
130125
130363
|
return undefined;
|
|
130126
130364
|
}
|
|
130127
130365
|
if (ts.isImportKeyword(contextToken) && ts.isSourceFile(parent)) {
|
|
130128
130366
|
// A lone import keyword with nothing following it does not parse as a statement at all
|
|
130367
|
+
keywordCompletion = 151 /* TypeKeyword */;
|
|
130129
130368
|
return contextToken;
|
|
130130
130369
|
}
|
|
130131
130370
|
if (ts.isImportKeyword(contextToken) && ts.isImportDeclaration(parent)) {
|
|
130132
130371
|
// `import s| from`
|
|
130372
|
+
keywordCompletion = 151 /* TypeKeyword */;
|
|
130133
130373
|
return isModuleSpecifierMissingOrEmpty(parent.moduleSpecifier) ? parent : undefined;
|
|
130134
130374
|
}
|
|
130135
130375
|
return undefined;
|
|
130136
130376
|
}
|
|
130137
130377
|
}
|
|
130378
|
+
function couldBeTypeOnlyImportSpecifier(importSpecifier, contextToken) {
|
|
130379
|
+
return ts.isImportSpecifier(importSpecifier)
|
|
130380
|
+
&& (importSpecifier.isTypeOnly || contextToken === importSpecifier.name && ts.isTypeKeywordTokenOrIdentifier(contextToken));
|
|
130381
|
+
}
|
|
130382
|
+
function canCompleteFromNamedBindings(namedBindings) {
|
|
130383
|
+
return isModuleSpecifierMissingOrEmpty(namedBindings.parent.parent.moduleSpecifier)
|
|
130384
|
+
&& (ts.isNamespaceImport(namedBindings) || namedBindings.elements.length < 2)
|
|
130385
|
+
&& !namedBindings.parent.name;
|
|
130386
|
+
}
|
|
130138
130387
|
function isModuleSpecifierMissingOrEmpty(specifier) {
|
|
130139
130388
|
var _a;
|
|
130140
130389
|
if (ts.nodeIsMissing(specifier))
|
|
@@ -136274,7 +136523,7 @@ var ts;
|
|
|
136274
136523
|
else {
|
|
136275
136524
|
for (var _e = 0, defaultImports_1 = defaultImports; _e < defaultImports_1.length; _e++) {
|
|
136276
136525
|
var defaultImport = defaultImports_1[_e];
|
|
136277
|
-
newImportSpecifiers.push(ts.factory.createImportSpecifier(ts.factory.createIdentifier("default"), defaultImport.importClause.name)); // TODO: GH#18217
|
|
136526
|
+
newImportSpecifiers.push(ts.factory.createImportSpecifier(/*isTypeOnly*/ false, ts.factory.createIdentifier("default"), defaultImport.importClause.name)); // TODO: GH#18217
|
|
136278
136527
|
}
|
|
136279
136528
|
}
|
|
136280
136529
|
newImportSpecifiers.push.apply(newImportSpecifiers, ts.flatMap(namedImports, function (i) { return i.importClause.namedBindings.elements; })); // TODO: GH#18217
|
|
@@ -136408,7 +136657,8 @@ var ts;
|
|
|
136408
136657
|
return ts.stableSort(specifiers, compareImportOrExportSpecifiers);
|
|
136409
136658
|
}
|
|
136410
136659
|
function compareImportOrExportSpecifiers(s1, s2) {
|
|
136411
|
-
return
|
|
136660
|
+
return ts.compareBooleans(s1.isTypeOnly, s2.isTypeOnly)
|
|
136661
|
+
|| compareIdentifiers(s1.propertyName || s1.name, s2.propertyName || s2.name)
|
|
136412
136662
|
|| compareIdentifiers(s1.name, s2.name);
|
|
136413
136663
|
}
|
|
136414
136664
|
OrganizeImports.compareImportOrExportSpecifiers = compareImportOrExportSpecifiers;
|
|
@@ -146566,7 +146816,7 @@ var ts;
|
|
|
146566
146816
|
*/
|
|
146567
146817
|
var newNodes = [
|
|
146568
146818
|
makeConst(/*modifiers*/ undefined, rename, assignment.right),
|
|
146569
|
-
makeExportDeclaration([ts.factory.createExportSpecifier(rename, text)]),
|
|
146819
|
+
makeExportDeclaration([ts.factory.createExportSpecifier(/*isTypeOnly*/ false, rename, text)]),
|
|
146570
146820
|
];
|
|
146571
146821
|
changes.replaceNodeWithNodes(sourceFile, assignment.parent, newNodes);
|
|
146572
146822
|
}
|
|
@@ -146588,7 +146838,7 @@ var ts;
|
|
|
146588
146838
|
return makeExportDeclaration(/*exportClause*/ undefined, moduleSpecifier);
|
|
146589
146839
|
}
|
|
146590
146840
|
function reExportDefault(moduleSpecifier) {
|
|
146591
|
-
return makeExportDeclaration([ts.factory.createExportSpecifier(/*propertyName*/ undefined, "default")], moduleSpecifier);
|
|
146841
|
+
return makeExportDeclaration([ts.factory.createExportSpecifier(/*isTypeOnly*/ false, /*propertyName*/ undefined, "default")], moduleSpecifier);
|
|
146592
146842
|
}
|
|
146593
146843
|
function convertExportsPropertyAssignment(_a, sourceFile, changes) {
|
|
146594
146844
|
var left = _a.left, right = _a.right, parent = _a.parent;
|
|
@@ -146730,7 +146980,7 @@ var ts;
|
|
|
146730
146980
|
}
|
|
146731
146981
|
var namedBindings = namedBindingsNames.size === 0 ? undefined : ts.arrayFrom(ts.mapIterator(namedBindingsNames.entries(), function (_a) {
|
|
146732
146982
|
var propertyName = _a[0], idName = _a[1];
|
|
146733
|
-
return ts.factory.createImportSpecifier(propertyName === idName ? undefined : ts.factory.createIdentifier(propertyName), ts.factory.createIdentifier(idName));
|
|
146983
|
+
return ts.factory.createImportSpecifier(/*isTypeOnly*/ false, propertyName === idName ? undefined : ts.factory.createIdentifier(propertyName), ts.factory.createIdentifier(idName));
|
|
146734
146984
|
}));
|
|
146735
146985
|
if (!namedBindings) {
|
|
146736
146986
|
// If it was unused, ensure that we at least import *something*.
|
|
@@ -146788,7 +147038,7 @@ var ts;
|
|
|
146788
147038
|
: ts.makeImport(/*name*/ undefined, [makeImportSpecifier(propertyName, localName)], moduleSpecifier, quotePreference);
|
|
146789
147039
|
}
|
|
146790
147040
|
function makeImportSpecifier(propertyName, name) {
|
|
146791
|
-
return ts.factory.createImportSpecifier(propertyName !== undefined && propertyName !== name ? ts.factory.createIdentifier(propertyName) : undefined, ts.factory.createIdentifier(name));
|
|
147041
|
+
return ts.factory.createImportSpecifier(/*isTypeOnly*/ false, propertyName !== undefined && propertyName !== name ? ts.factory.createIdentifier(propertyName) : undefined, ts.factory.createIdentifier(name));
|
|
146792
147042
|
}
|
|
146793
147043
|
function makeConst(modifiers, name, init) {
|
|
146794
147044
|
return ts.factory.createVariableStatement(modifiers, ts.factory.createVariableDeclarationList([ts.factory.createVariableDeclaration(name, /*exclamationToken*/ undefined, /*type*/ undefined, init)], 2 /* Const */));
|
|
@@ -147113,13 +147363,13 @@ var ts;
|
|
|
147113
147363
|
codefix.registerCodeFix({
|
|
147114
147364
|
errorCodes: errorCodes,
|
|
147115
147365
|
getCodeActions: function (context) {
|
|
147116
|
-
var errorCode = context.errorCode, preferences = context.preferences, sourceFile = context.sourceFile, span = context.span;
|
|
147366
|
+
var errorCode = context.errorCode, preferences = context.preferences, sourceFile = context.sourceFile, span = context.span, program = context.program;
|
|
147117
147367
|
var info = getFixesInfo(context, errorCode, span.start, /*useAutoImportProvider*/ true);
|
|
147118
147368
|
if (!info)
|
|
147119
147369
|
return undefined;
|
|
147120
147370
|
var fixes = info.fixes, symbolName = info.symbolName;
|
|
147121
147371
|
var quotePreference = ts.getQuotePreference(sourceFile, preferences);
|
|
147122
|
-
return fixes.map(function (fix) { return codeActionForFix(context, sourceFile, symbolName, fix, quotePreference); });
|
|
147372
|
+
return fixes.map(function (fix) { return codeActionForFix(context, sourceFile, symbolName, fix, quotePreference, program.getCompilerOptions()); });
|
|
147123
147373
|
},
|
|
147124
147374
|
fixIds: [importFixId],
|
|
147125
147375
|
getAllCodeActions: function (context) {
|
|
@@ -147138,8 +147388,9 @@ var ts;
|
|
|
147138
147388
|
// Namespace fixes don't conflict, so just build a list.
|
|
147139
147389
|
var addToNamespace = [];
|
|
147140
147390
|
var importType = [];
|
|
147141
|
-
|
|
147391
|
+
/** Keys are import clause node IDs. */
|
|
147142
147392
|
var addToExisting = new ts.Map();
|
|
147393
|
+
/** Use `getNewImportEntry` for access */
|
|
147143
147394
|
var newImports = new ts.Map();
|
|
147144
147395
|
return { addImportFromDiagnostic: addImportFromDiagnostic, addImportFromExportedSymbol: addImportFromExportedSymbol, writeFixes: writeFixes };
|
|
147145
147396
|
function addImportFromDiagnostic(diagnostic, context) {
|
|
@@ -147148,67 +147399,66 @@ var ts;
|
|
|
147148
147399
|
return;
|
|
147149
147400
|
addImport(info);
|
|
147150
147401
|
}
|
|
147151
|
-
function addImportFromExportedSymbol(exportedSymbol,
|
|
147402
|
+
function addImportFromExportedSymbol(exportedSymbol, isValidTypeOnlyUseSite) {
|
|
147152
147403
|
var moduleSymbol = ts.Debug.checkDefined(exportedSymbol.parent);
|
|
147153
147404
|
var symbolName = ts.getNameForExportedSymbol(exportedSymbol, ts.getEmitScriptTarget(compilerOptions));
|
|
147154
147405
|
var checker = program.getTypeChecker();
|
|
147155
147406
|
var symbol = checker.getMergedSymbol(ts.skipAlias(exportedSymbol, checker));
|
|
147156
147407
|
var exportInfos = getAllReExportingModules(sourceFile, symbol, moduleSymbol, symbolName, host, program, preferences, useAutoImportProvider);
|
|
147157
|
-
var preferTypeOnlyImport = !!usageIsTypeOnly && compilerOptions.importsNotUsedAsValues === 2 /* Error */;
|
|
147158
147408
|
var useRequire = shouldUseRequire(sourceFile, program);
|
|
147159
|
-
var fix = getImportFixForSymbol(sourceFile, exportInfos, moduleSymbol, symbolName, program, /*position*/ undefined,
|
|
147409
|
+
var fix = getImportFixForSymbol(sourceFile, exportInfos, moduleSymbol, symbolName, program, /*position*/ undefined, !!isValidTypeOnlyUseSite, useRequire, host, preferences);
|
|
147160
147410
|
if (fix) {
|
|
147161
147411
|
addImport({ fixes: [fix], symbolName: symbolName });
|
|
147162
147412
|
}
|
|
147163
147413
|
}
|
|
147164
147414
|
function addImport(info) {
|
|
147415
|
+
var _a, _b;
|
|
147165
147416
|
var fixes = info.fixes, symbolName = info.symbolName;
|
|
147166
147417
|
var fix = ts.first(fixes);
|
|
147167
147418
|
switch (fix.kind) {
|
|
147168
147419
|
case 0 /* UseNamespace */:
|
|
147169
147420
|
addToNamespace.push(fix);
|
|
147170
147421
|
break;
|
|
147171
|
-
case 1 /*
|
|
147422
|
+
case 1 /* JsdocTypeImport */:
|
|
147172
147423
|
importType.push(fix);
|
|
147173
147424
|
break;
|
|
147174
147425
|
case 2 /* AddToExisting */: {
|
|
147175
|
-
var importClauseOrBindingPattern = fix.importClauseOrBindingPattern, importKind = fix.importKind,
|
|
147426
|
+
var importClauseOrBindingPattern = fix.importClauseOrBindingPattern, importKind = fix.importKind, addAsTypeOnly = fix.addAsTypeOnly;
|
|
147176
147427
|
var key = String(ts.getNodeId(importClauseOrBindingPattern));
|
|
147177
147428
|
var entry = addToExisting.get(key);
|
|
147178
147429
|
if (!entry) {
|
|
147179
|
-
addToExisting.set(key, entry = { importClauseOrBindingPattern: importClauseOrBindingPattern, defaultImport: undefined, namedImports:
|
|
147430
|
+
addToExisting.set(key, entry = { importClauseOrBindingPattern: importClauseOrBindingPattern, defaultImport: undefined, namedImports: new ts.Map() });
|
|
147180
147431
|
}
|
|
147181
147432
|
if (importKind === 0 /* Named */) {
|
|
147182
|
-
|
|
147433
|
+
var prevValue = entry === null || entry === void 0 ? void 0 : entry.namedImports.get(symbolName);
|
|
147434
|
+
entry.namedImports.set(symbolName, reduceAddAsTypeOnlyValues(prevValue, addAsTypeOnly));
|
|
147183
147435
|
}
|
|
147184
147436
|
else {
|
|
147185
|
-
ts.Debug.assert(entry.defaultImport === undefined || entry.defaultImport === symbolName, "(Add to Existing) Default import should be missing or match symbolName");
|
|
147186
|
-
entry.defaultImport =
|
|
147437
|
+
ts.Debug.assert(entry.defaultImport === undefined || entry.defaultImport.name === symbolName, "(Add to Existing) Default import should be missing or match symbolName");
|
|
147438
|
+
entry.defaultImport = {
|
|
147439
|
+
name: symbolName,
|
|
147440
|
+
addAsTypeOnly: reduceAddAsTypeOnlyValues((_a = entry.defaultImport) === null || _a === void 0 ? void 0 : _a.addAsTypeOnly, addAsTypeOnly),
|
|
147441
|
+
};
|
|
147187
147442
|
}
|
|
147188
147443
|
break;
|
|
147189
147444
|
}
|
|
147190
147445
|
case 3 /* AddNew */: {
|
|
147191
|
-
var moduleSpecifier = fix.moduleSpecifier, importKind = fix.importKind, useRequire = fix.useRequire,
|
|
147192
|
-
var entry =
|
|
147193
|
-
|
|
147194
|
-
newImports.set(moduleSpecifier, entry = { namedImports: [], namespaceLikeImport: undefined, typeOnly: typeOnly, useRequire: useRequire });
|
|
147195
|
-
}
|
|
147196
|
-
else {
|
|
147197
|
-
// An import clause can only be type-only if every import fix contributing to it can be type-only.
|
|
147198
|
-
entry.typeOnly = entry.typeOnly && typeOnly;
|
|
147199
|
-
}
|
|
147446
|
+
var moduleSpecifier = fix.moduleSpecifier, importKind = fix.importKind, useRequire = fix.useRequire, addAsTypeOnly = fix.addAsTypeOnly;
|
|
147447
|
+
var entry = getNewImportEntry(moduleSpecifier, importKind, useRequire, addAsTypeOnly);
|
|
147448
|
+
ts.Debug.assert(entry.useRequire === useRequire, "(Add new) Tried to add an `import` and a `require` for the same module");
|
|
147200
147449
|
switch (importKind) {
|
|
147201
147450
|
case 1 /* Default */:
|
|
147202
|
-
ts.Debug.assert(entry.defaultImport === undefined || entry.defaultImport === symbolName, "(Add new) Default import should be missing or match symbolName");
|
|
147203
|
-
entry.defaultImport = symbolName;
|
|
147451
|
+
ts.Debug.assert(entry.defaultImport === undefined || entry.defaultImport.name === symbolName, "(Add new) Default import should be missing or match symbolName");
|
|
147452
|
+
entry.defaultImport = { name: symbolName, addAsTypeOnly: reduceAddAsTypeOnlyValues((_b = entry.defaultImport) === null || _b === void 0 ? void 0 : _b.addAsTypeOnly, addAsTypeOnly) };
|
|
147204
147453
|
break;
|
|
147205
147454
|
case 0 /* Named */:
|
|
147206
|
-
|
|
147455
|
+
var prevValue = (entry.namedImports || (entry.namedImports = new ts.Map())).get(symbolName);
|
|
147456
|
+
entry.namedImports.set(symbolName, reduceAddAsTypeOnlyValues(prevValue, addAsTypeOnly));
|
|
147207
147457
|
break;
|
|
147208
147458
|
case 3 /* CommonJS */:
|
|
147209
147459
|
case 2 /* Namespace */:
|
|
147210
147460
|
ts.Debug.assert(entry.namespaceLikeImport === undefined || entry.namespaceLikeImport.name === symbolName, "Namespacelike import shoudl be missing or match symbolName");
|
|
147211
|
-
entry.namespaceLikeImport = { importKind: importKind, name: symbolName };
|
|
147461
|
+
entry.namespaceLikeImport = { importKind: importKind, name: symbolName, addAsTypeOnly: addAsTypeOnly };
|
|
147212
147462
|
break;
|
|
147213
147463
|
}
|
|
147214
147464
|
break;
|
|
@@ -147216,6 +147466,50 @@ var ts;
|
|
|
147216
147466
|
default:
|
|
147217
147467
|
ts.Debug.assertNever(fix, "fix wasn't never - got kind " + fix.kind);
|
|
147218
147468
|
}
|
|
147469
|
+
function reduceAddAsTypeOnlyValues(prevValue, newValue) {
|
|
147470
|
+
// `NotAllowed` overrides `Required` because one addition of a new import might be required to be type-only
|
|
147471
|
+
// because of `--importsNotUsedAsValues=error`, but if a second addition of the same import is `NotAllowed`
|
|
147472
|
+
// to be type-only, the reason the first one was `Required` - the unused runtime dependency - is now moot.
|
|
147473
|
+
// Alternatively, if one addition is `Required` because it has no value meaning under `--preserveValueImports`
|
|
147474
|
+
// and `--isolatedModules`, it should be impossible for another addition to be `NotAllowed` since that would
|
|
147475
|
+
// mean a type is being referenced in a value location.
|
|
147476
|
+
return Math.max(prevValue !== null && prevValue !== void 0 ? prevValue : 0, newValue);
|
|
147477
|
+
}
|
|
147478
|
+
function getNewImportEntry(moduleSpecifier, importKind, useRequire, addAsTypeOnly) {
|
|
147479
|
+
// A default import that requires type-only makes the whole import type-only.
|
|
147480
|
+
// (We could add `default` as a named import, but that style seems undesirable.)
|
|
147481
|
+
// Under `--preserveValueImports` and `--importsNotUsedAsValues=error`, if a
|
|
147482
|
+
// module default-exports a type but named-exports some values (weird), you would
|
|
147483
|
+
// have to use a type-only default import and non-type-only named imports. These
|
|
147484
|
+
// require two separate import declarations, so we build this into the map key.
|
|
147485
|
+
var typeOnlyKey = newImportsKey(moduleSpecifier, /*topLevelTypeOnly*/ true);
|
|
147486
|
+
var nonTypeOnlyKey = newImportsKey(moduleSpecifier, /*topLevelTypeOnly*/ false);
|
|
147487
|
+
var typeOnlyEntry = newImports.get(typeOnlyKey);
|
|
147488
|
+
var nonTypeOnlyEntry = newImports.get(nonTypeOnlyKey);
|
|
147489
|
+
var newEntry = {
|
|
147490
|
+
defaultImport: undefined,
|
|
147491
|
+
namedImports: undefined,
|
|
147492
|
+
namespaceLikeImport: undefined,
|
|
147493
|
+
useRequire: useRequire
|
|
147494
|
+
};
|
|
147495
|
+
if (importKind === 1 /* Default */ && addAsTypeOnly === 2 /* Required */) {
|
|
147496
|
+
if (typeOnlyEntry)
|
|
147497
|
+
return typeOnlyEntry;
|
|
147498
|
+
newImports.set(typeOnlyKey, newEntry);
|
|
147499
|
+
return newEntry;
|
|
147500
|
+
}
|
|
147501
|
+
if (addAsTypeOnly === 1 /* Allowed */ && (typeOnlyEntry || nonTypeOnlyEntry)) {
|
|
147502
|
+
return (typeOnlyEntry || nonTypeOnlyEntry);
|
|
147503
|
+
}
|
|
147504
|
+
if (nonTypeOnlyEntry) {
|
|
147505
|
+
return nonTypeOnlyEntry;
|
|
147506
|
+
}
|
|
147507
|
+
newImports.set(nonTypeOnlyKey, newEntry);
|
|
147508
|
+
return newEntry;
|
|
147509
|
+
}
|
|
147510
|
+
function newImportsKey(moduleSpecifier, topLevelTypeOnly) {
|
|
147511
|
+
return (topLevelTypeOnly ? 1 : 0) + "|" + moduleSpecifier;
|
|
147512
|
+
}
|
|
147219
147513
|
}
|
|
147220
147514
|
function writeFixes(changeTracker) {
|
|
147221
147515
|
var quotePreference = ts.getQuotePreference(sourceFile, preferences);
|
|
@@ -147228,14 +147522,22 @@ var ts;
|
|
|
147228
147522
|
addImportType(changeTracker, sourceFile, fix, quotePreference);
|
|
147229
147523
|
}
|
|
147230
147524
|
addToExisting.forEach(function (_a) {
|
|
147231
|
-
var importClauseOrBindingPattern = _a.importClauseOrBindingPattern, defaultImport = _a.defaultImport, namedImports = _a.namedImports
|
|
147232
|
-
doAddExistingFix(changeTracker, sourceFile, importClauseOrBindingPattern, defaultImport, namedImports,
|
|
147525
|
+
var importClauseOrBindingPattern = _a.importClauseOrBindingPattern, defaultImport = _a.defaultImport, namedImports = _a.namedImports;
|
|
147526
|
+
doAddExistingFix(changeTracker, sourceFile, importClauseOrBindingPattern, defaultImport, ts.arrayFrom(namedImports.entries(), function (_a) {
|
|
147527
|
+
var name = _a[0], addAsTypeOnly = _a[1];
|
|
147528
|
+
return ({ addAsTypeOnly: addAsTypeOnly, name: name });
|
|
147529
|
+
}), compilerOptions);
|
|
147233
147530
|
});
|
|
147234
147531
|
var newDeclarations;
|
|
147235
|
-
newImports.forEach(function (_a,
|
|
147236
|
-
var useRequire = _a.useRequire,
|
|
147532
|
+
newImports.forEach(function (_a, key) {
|
|
147533
|
+
var useRequire = _a.useRequire, defaultImport = _a.defaultImport, namedImports = _a.namedImports, namespaceLikeImport = _a.namespaceLikeImport;
|
|
147534
|
+
var moduleSpecifier = key.slice(2); // From `${0 | 1}|${moduleSpecifier}` format
|
|
147237
147535
|
var getDeclarations = useRequire ? getNewRequires : getNewImports;
|
|
147238
|
-
|
|
147536
|
+
var declarations = getDeclarations(moduleSpecifier, quotePreference, defaultImport, namedImports && ts.arrayFrom(namedImports.entries(), function (_a) {
|
|
147537
|
+
var name = _a[0], addAsTypeOnly = _a[1];
|
|
147538
|
+
return ({ addAsTypeOnly: addAsTypeOnly, name: name });
|
|
147539
|
+
}), namespaceLikeImport);
|
|
147540
|
+
newDeclarations = ts.combine(newDeclarations, declarations);
|
|
147239
147541
|
});
|
|
147240
147542
|
if (newDeclarations) {
|
|
147241
147543
|
ts.insertImports(changeTracker, sourceFile, newDeclarations, /*blankLineBetween*/ true);
|
|
@@ -147246,24 +147548,37 @@ var ts;
|
|
|
147246
147548
|
var ImportFixKind;
|
|
147247
147549
|
(function (ImportFixKind) {
|
|
147248
147550
|
ImportFixKind[ImportFixKind["UseNamespace"] = 0] = "UseNamespace";
|
|
147249
|
-
ImportFixKind[ImportFixKind["
|
|
147551
|
+
ImportFixKind[ImportFixKind["JsdocTypeImport"] = 1] = "JsdocTypeImport";
|
|
147250
147552
|
ImportFixKind[ImportFixKind["AddToExisting"] = 2] = "AddToExisting";
|
|
147251
147553
|
ImportFixKind[ImportFixKind["AddNew"] = 3] = "AddNew";
|
|
147252
147554
|
})(ImportFixKind || (ImportFixKind = {}));
|
|
147555
|
+
// These should not be combined as bitflags, but are given powers of 2 values to
|
|
147556
|
+
// easily detect conflicts between `NotAllowed` and `Required` by giving them a unique sum.
|
|
147557
|
+
// They're also ordered in terms of increasing priority for a fix-all scenario (see
|
|
147558
|
+
// `reduceAddAsTypeOnlyValues`).
|
|
147559
|
+
var AddAsTypeOnly;
|
|
147560
|
+
(function (AddAsTypeOnly) {
|
|
147561
|
+
AddAsTypeOnly[AddAsTypeOnly["Allowed"] = 1] = "Allowed";
|
|
147562
|
+
AddAsTypeOnly[AddAsTypeOnly["Required"] = 2] = "Required";
|
|
147563
|
+
AddAsTypeOnly[AddAsTypeOnly["NotAllowed"] = 4] = "NotAllowed";
|
|
147564
|
+
})(AddAsTypeOnly || (AddAsTypeOnly = {}));
|
|
147253
147565
|
function getImportCompletionAction(exportedSymbol, moduleSymbol, sourceFile, symbolName, host, program, formatContext, position, preferences) {
|
|
147254
147566
|
var compilerOptions = program.getCompilerOptions();
|
|
147255
147567
|
var exportInfos = ts.pathIsBareSpecifier(ts.stripQuotes(moduleSymbol.name))
|
|
147256
147568
|
? [getSymbolExportInfoForSymbol(exportedSymbol, moduleSymbol, program, host)]
|
|
147257
147569
|
: getAllReExportingModules(sourceFile, exportedSymbol, moduleSymbol, symbolName, host, program, preferences, /*useAutoImportProvider*/ true);
|
|
147258
147570
|
var useRequire = shouldUseRequire(sourceFile, program);
|
|
147259
|
-
var
|
|
147260
|
-
var fix = ts.Debug.checkDefined(getImportFixForSymbol(sourceFile, exportInfos, moduleSymbol, symbolName, program, position,
|
|
147261
|
-
return {
|
|
147571
|
+
var isValidTypeOnlyUseSite = ts.isValidTypeOnlyAliasUseSite(ts.getTokenAtPosition(sourceFile, position));
|
|
147572
|
+
var fix = ts.Debug.checkDefined(getImportFixForSymbol(sourceFile, exportInfos, moduleSymbol, symbolName, program, position, isValidTypeOnlyUseSite, useRequire, host, preferences));
|
|
147573
|
+
return {
|
|
147574
|
+
moduleSpecifier: fix.moduleSpecifier,
|
|
147575
|
+
codeAction: codeFixActionToCodeAction(codeActionForFix({ host: host, formatContext: formatContext, preferences: preferences }, sourceFile, symbolName, fix, ts.getQuotePreference(sourceFile, preferences), compilerOptions))
|
|
147576
|
+
};
|
|
147262
147577
|
}
|
|
147263
147578
|
codefix.getImportCompletionAction = getImportCompletionAction;
|
|
147264
|
-
function getImportFixForSymbol(sourceFile, exportInfos, moduleSymbol, symbolName, program, position,
|
|
147579
|
+
function getImportFixForSymbol(sourceFile, exportInfos, moduleSymbol, symbolName, program, position, isValidTypeOnlyUseSite, useRequire, host, preferences) {
|
|
147265
147580
|
ts.Debug.assert(exportInfos.some(function (info) { return info.moduleSymbol === moduleSymbol || info.symbol.parent === moduleSymbol; }), "Some exportInfo should match the specified moduleSymbol");
|
|
147266
|
-
return getBestFix(getImportFixes(exportInfos, symbolName, position,
|
|
147581
|
+
return getBestFix(getImportFixes(exportInfos, symbolName, position, isValidTypeOnlyUseSite, useRequire, program, sourceFile, host, preferences), sourceFile, program, host, preferences);
|
|
147267
147582
|
}
|
|
147268
147583
|
function codeFixActionToCodeAction(_a) {
|
|
147269
147584
|
var description = _a.description, changes = _a.changes, commands = _a.commands;
|
|
@@ -147321,24 +147636,21 @@ var ts;
|
|
|
147321
147636
|
function getModuleSpecifierForBestExportInfo(exportInfo, importingFile, program, host, preferences, fromCacheOnly) {
|
|
147322
147637
|
var _a = getNewImportFixes(program, importingFile,
|
|
147323
147638
|
/*position*/ undefined,
|
|
147324
|
-
/*
|
|
147639
|
+
/*isValidTypeOnlyUseSite*/ false,
|
|
147325
147640
|
/*useRequire*/ false, exportInfo, host, preferences, fromCacheOnly), fixes = _a.fixes, computedWithoutCacheCount = _a.computedWithoutCacheCount;
|
|
147326
147641
|
var result = getBestFix(fixes, importingFile, program, host, preferences);
|
|
147327
147642
|
return result && __assign(__assign({}, result), { computedWithoutCacheCount: computedWithoutCacheCount });
|
|
147328
147643
|
}
|
|
147329
147644
|
codefix.getModuleSpecifierForBestExportInfo = getModuleSpecifierForBestExportInfo;
|
|
147330
|
-
function isTypeOnlyPosition(sourceFile, position) {
|
|
147331
|
-
return ts.isValidTypeOnlyAliasUseSite(ts.getTokenAtPosition(sourceFile, position));
|
|
147332
|
-
}
|
|
147333
147645
|
function getImportFixes(exportInfos, symbolName,
|
|
147334
147646
|
/** undefined only for missing JSX namespace */
|
|
147335
|
-
position,
|
|
147647
|
+
position, isValidTypeOnlyUseSite, useRequire, program, sourceFile, host, preferences) {
|
|
147336
147648
|
var checker = program.getTypeChecker();
|
|
147337
147649
|
var existingImports = ts.flatMap(exportInfos, function (info) { return getExistingImportDeclarations(info, checker, sourceFile, program.getCompilerOptions()); });
|
|
147338
147650
|
var useNamespace = position === undefined ? undefined : tryUseExistingNamespaceImport(existingImports, symbolName, position, checker);
|
|
147339
|
-
var addToExisting = tryAddToExistingImport(existingImports,
|
|
147651
|
+
var addToExisting = tryAddToExistingImport(existingImports, isValidTypeOnlyUseSite, checker, program.getCompilerOptions());
|
|
147340
147652
|
// Don't bother providing an action to add a new import if we can add to an existing one.
|
|
147341
|
-
var addImport = addToExisting ? [addToExisting] : getFixesForAddImport(exportInfos, existingImports, program, sourceFile, position,
|
|
147653
|
+
var addImport = addToExisting ? [addToExisting] : getFixesForAddImport(exportInfos, existingImports, program, sourceFile, position, isValidTypeOnlyUseSite, useRequire, host, preferences);
|
|
147342
147654
|
return __spreadArray(__spreadArray([], (useNamespace ? [useNamespace] : ts.emptyArray), true), addImport, true);
|
|
147343
147655
|
}
|
|
147344
147656
|
function tryUseExistingNamespaceImport(existingImports, symbolName, position, checker) {
|
|
@@ -147393,14 +147705,34 @@ var ts;
|
|
|
147393
147705
|
return ts.Debug.assertNever(declaration);
|
|
147394
147706
|
}
|
|
147395
147707
|
}
|
|
147396
|
-
function
|
|
147708
|
+
function getAddAsTypeOnly(isValidTypeOnlyUseSite, isForNewImportDeclaration, symbol, targetFlags, checker, compilerOptions) {
|
|
147709
|
+
if (!isValidTypeOnlyUseSite) {
|
|
147710
|
+
// Can't use a type-only import if the usage is an emitting position
|
|
147711
|
+
return 4 /* NotAllowed */;
|
|
147712
|
+
}
|
|
147713
|
+
if (isForNewImportDeclaration && compilerOptions.importsNotUsedAsValues === 2 /* Error */) {
|
|
147714
|
+
// Not writing a (top-level) type-only import here would create an error because the runtime dependency is unnecessary
|
|
147715
|
+
return 2 /* Required */;
|
|
147716
|
+
}
|
|
147717
|
+
if (compilerOptions.isolatedModules && compilerOptions.preserveValueImports &&
|
|
147718
|
+
(!(targetFlags & 111551 /* Value */) || !!checker.getTypeOnlyAliasDeclaration(symbol))) {
|
|
147719
|
+
// A type-only import is required for this symbol if under these settings if the symbol will
|
|
147720
|
+
// be erased, which will happen if the target symbol is purely a type or if it was exported/imported
|
|
147721
|
+
// as type-only already somewhere between this import and the target.
|
|
147722
|
+
return 2 /* Required */;
|
|
147723
|
+
}
|
|
147724
|
+
return 1 /* Allowed */;
|
|
147725
|
+
}
|
|
147726
|
+
function tryAddToExistingImport(existingImports, isValidTypeOnlyUseSite, checker, compilerOptions) {
|
|
147397
147727
|
return ts.firstDefined(existingImports, function (_a) {
|
|
147398
|
-
var declaration = _a.declaration, importKind = _a.importKind;
|
|
147399
|
-
if (declaration.kind === 264 /* ImportEqualsDeclaration */)
|
|
147728
|
+
var declaration = _a.declaration, importKind = _a.importKind, symbol = _a.symbol, targetFlags = _a.targetFlags;
|
|
147729
|
+
if (importKind === 3 /* CommonJS */ || importKind === 2 /* Namespace */ || declaration.kind === 264 /* ImportEqualsDeclaration */) {
|
|
147730
|
+
// These kinds of imports are not combinable with anything
|
|
147400
147731
|
return undefined;
|
|
147732
|
+
}
|
|
147401
147733
|
if (declaration.kind === 253 /* VariableDeclaration */) {
|
|
147402
147734
|
return (importKind === 0 /* Named */ || importKind === 1 /* Default */) && declaration.name.kind === 200 /* ObjectBindingPattern */
|
|
147403
|
-
? { kind: 2 /* AddToExisting */, importClauseOrBindingPattern: declaration.name, importKind: importKind, moduleSpecifier: declaration.initializer.arguments[0].text,
|
|
147735
|
+
? { kind: 2 /* AddToExisting */, importClauseOrBindingPattern: declaration.name, importKind: importKind, moduleSpecifier: declaration.initializer.arguments[0].text, addAsTypeOnly: 4 /* NotAllowed */ }
|
|
147404
147736
|
: undefined;
|
|
147405
147737
|
}
|
|
147406
147738
|
var importClause = declaration.importClause;
|
|
@@ -147411,13 +147743,29 @@ var ts;
|
|
|
147411
147743
|
// be added to an existing type-only import is adding a named import to existing named bindings.
|
|
147412
147744
|
if (importClause.isTypeOnly && !(importKind === 0 /* Named */ && namedBindings))
|
|
147413
147745
|
return undefined;
|
|
147414
|
-
|
|
147415
|
-
|
|
147416
|
-
|
|
147746
|
+
// N.B. we don't have to figure out whether to use the main program checker
|
|
147747
|
+
// or the AutoImportProvider checker because we're adding to an existing import; the existence of
|
|
147748
|
+
// the import guarantees the symbol came from the main program.
|
|
147749
|
+
var addAsTypeOnly = getAddAsTypeOnly(isValidTypeOnlyUseSite, /*isForNewImportDeclaration*/ false, symbol, targetFlags, checker, compilerOptions);
|
|
147750
|
+
if (importKind === 1 /* Default */ && (name || // Cannot add a default import to a declaration that already has one
|
|
147751
|
+
addAsTypeOnly === 2 /* Required */ && namedBindings // Cannot add a default import as type-only if the import already has named bindings
|
|
147752
|
+
))
|
|
147753
|
+
return undefined;
|
|
147754
|
+
if (importKind === 0 /* Named */ &&
|
|
147755
|
+
(namedBindings === null || namedBindings === void 0 ? void 0 : namedBindings.kind) === 267 /* NamespaceImport */ // Cannot add a named import to a declaration that has a namespace import
|
|
147756
|
+
)
|
|
147757
|
+
return undefined;
|
|
147758
|
+
return {
|
|
147759
|
+
kind: 2 /* AddToExisting */,
|
|
147760
|
+
importClauseOrBindingPattern: importClause,
|
|
147761
|
+
importKind: importKind,
|
|
147762
|
+
moduleSpecifier: declaration.moduleSpecifier.text,
|
|
147763
|
+
addAsTypeOnly: addAsTypeOnly,
|
|
147764
|
+
};
|
|
147417
147765
|
});
|
|
147418
147766
|
}
|
|
147419
147767
|
function getExistingImportDeclarations(_a, checker, importingFile, compilerOptions) {
|
|
147420
|
-
var moduleSymbol = _a.moduleSymbol, exportKind = _a.exportKind, targetFlags = _a.targetFlags;
|
|
147768
|
+
var moduleSymbol = _a.moduleSymbol, exportKind = _a.exportKind, targetFlags = _a.targetFlags, symbol = _a.symbol;
|
|
147421
147769
|
// Can't use an es6 import for a type in JS.
|
|
147422
147770
|
if (!(targetFlags & 111551 /* Value */) && ts.isSourceFileJS(importingFile))
|
|
147423
147771
|
return ts.emptyArray;
|
|
@@ -147425,10 +147773,10 @@ var ts;
|
|
|
147425
147773
|
return ts.mapDefined(importingFile.imports, function (moduleSpecifier) {
|
|
147426
147774
|
var i = ts.importFromModuleSpecifier(moduleSpecifier);
|
|
147427
147775
|
if (ts.isRequireVariableDeclaration(i.parent)) {
|
|
147428
|
-
return checker.resolveExternalModuleName(moduleSpecifier) === moduleSymbol ? { declaration: i.parent, importKind: importKind } : undefined;
|
|
147776
|
+
return checker.resolveExternalModuleName(moduleSpecifier) === moduleSymbol ? { declaration: i.parent, importKind: importKind, symbol: symbol, targetFlags: targetFlags } : undefined;
|
|
147429
147777
|
}
|
|
147430
147778
|
if (i.kind === 265 /* ImportDeclaration */ || i.kind === 264 /* ImportEqualsDeclaration */) {
|
|
147431
|
-
return checker.getSymbolAtLocation(moduleSpecifier) === moduleSymbol ? { declaration: i, importKind: importKind } : undefined;
|
|
147779
|
+
return checker.getSymbolAtLocation(moduleSpecifier) === moduleSymbol ? { declaration: i, importKind: importKind, symbol: symbol, targetFlags: targetFlags } : undefined;
|
|
147432
147780
|
}
|
|
147433
147781
|
});
|
|
147434
147782
|
}
|
|
@@ -147460,44 +147808,50 @@ var ts;
|
|
|
147460
147808
|
// 5. Literally nothing to go on
|
|
147461
147809
|
return true;
|
|
147462
147810
|
}
|
|
147463
|
-
function getNewImportFixes(program, sourceFile, position,
|
|
147811
|
+
function getNewImportFixes(program, sourceFile, position, isValidTypeOnlyUseSite, useRequire, moduleSymbols, host, preferences, fromCacheOnly) {
|
|
147464
147812
|
var isJs = ts.isSourceFileJS(sourceFile);
|
|
147465
147813
|
var compilerOptions = program.getCompilerOptions();
|
|
147466
147814
|
var moduleSpecifierResolutionHost = ts.createModuleSpecifierResolutionHost(program, host);
|
|
147467
|
-
var
|
|
147815
|
+
var getChecker = ts.memoizeOne(function (isFromPackageJson) { return isFromPackageJson ? host.getPackageJsonAutoImportProvider().getTypeChecker() : program.getTypeChecker(); });
|
|
147468
147816
|
var getModuleSpecifiers = fromCacheOnly
|
|
147469
147817
|
? function (moduleSymbol) { return ({ moduleSpecifiers: ts.moduleSpecifiers.tryGetModuleSpecifiersFromCache(moduleSymbol, sourceFile, moduleSpecifierResolutionHost, preferences), computedWithoutCache: false }); }
|
|
147470
|
-
: function (moduleSymbol) { return ts.moduleSpecifiers.getModuleSpecifiersWithCacheInfo(moduleSymbol, checker, compilerOptions, sourceFile, moduleSpecifierResolutionHost, preferences); };
|
|
147818
|
+
: function (moduleSymbol, checker) { return ts.moduleSpecifiers.getModuleSpecifiersWithCacheInfo(moduleSymbol, checker, compilerOptions, sourceFile, moduleSpecifierResolutionHost, preferences); };
|
|
147471
147819
|
var computedWithoutCacheCount = 0;
|
|
147472
147820
|
var fixes = ts.flatMap(moduleSymbols, function (exportInfo) {
|
|
147473
|
-
var
|
|
147821
|
+
var checker = getChecker(exportInfo.isFromPackageJson);
|
|
147822
|
+
var _a = getModuleSpecifiers(exportInfo.moduleSymbol, checker), computedWithoutCache = _a.computedWithoutCache, moduleSpecifiers = _a.moduleSpecifiers;
|
|
147823
|
+
var importedSymbolHasValueMeaning = !!(exportInfo.targetFlags & 111551 /* Value */);
|
|
147824
|
+
var addAsTypeOnly = getAddAsTypeOnly(isValidTypeOnlyUseSite, /*isForNewImportDeclaration*/ true, exportInfo.symbol, exportInfo.targetFlags, checker, compilerOptions);
|
|
147474
147825
|
computedWithoutCacheCount += computedWithoutCache ? 1 : 0;
|
|
147475
147826
|
return moduleSpecifiers === null || moduleSpecifiers === void 0 ? void 0 : moduleSpecifiers.map(function (moduleSpecifier) {
|
|
147476
147827
|
// `position` should only be undefined at a missing jsx namespace, in which case we shouldn't be looking for pure types.
|
|
147477
|
-
return !
|
|
147478
|
-
? { kind: 1 /*
|
|
147828
|
+
return !importedSymbolHasValueMeaning && isJs && position !== undefined
|
|
147829
|
+
? { kind: 1 /* JsdocTypeImport */, moduleSpecifier: moduleSpecifier, position: position, exportInfo: exportInfo }
|
|
147479
147830
|
: {
|
|
147480
147831
|
kind: 3 /* AddNew */,
|
|
147481
147832
|
moduleSpecifier: moduleSpecifier,
|
|
147482
147833
|
importKind: getImportKind(sourceFile, exportInfo.exportKind, compilerOptions),
|
|
147483
147834
|
useRequire: useRequire,
|
|
147484
|
-
|
|
147835
|
+
addAsTypeOnly: addAsTypeOnly,
|
|
147485
147836
|
exportInfo: exportInfo,
|
|
147486
147837
|
};
|
|
147487
147838
|
});
|
|
147488
147839
|
});
|
|
147489
147840
|
return { computedWithoutCacheCount: computedWithoutCacheCount, fixes: fixes };
|
|
147490
147841
|
}
|
|
147491
|
-
function getFixesForAddImport(exportInfos, existingImports, program, sourceFile, position,
|
|
147492
|
-
var existingDeclaration = ts.firstDefined(existingImports, function (info) { return newImportInfoFromExistingSpecifier(info,
|
|
147493
|
-
return existingDeclaration ? [existingDeclaration] : getNewImportFixes(program, sourceFile, position,
|
|
147842
|
+
function getFixesForAddImport(exportInfos, existingImports, program, sourceFile, position, isValidTypeOnlyUseSite, useRequire, host, preferences) {
|
|
147843
|
+
var existingDeclaration = ts.firstDefined(existingImports, function (info) { return newImportInfoFromExistingSpecifier(info, isValidTypeOnlyUseSite, useRequire, program.getTypeChecker(), program.getCompilerOptions()); });
|
|
147844
|
+
return existingDeclaration ? [existingDeclaration] : getNewImportFixes(program, sourceFile, position, isValidTypeOnlyUseSite, useRequire, exportInfos, host, preferences).fixes;
|
|
147494
147845
|
}
|
|
147495
|
-
function newImportInfoFromExistingSpecifier(_a,
|
|
147496
|
-
var declaration = _a.declaration, importKind = _a.importKind;
|
|
147846
|
+
function newImportInfoFromExistingSpecifier(_a, isValidTypeOnlyUseSite, useRequire, checker, compilerOptions) {
|
|
147847
|
+
var declaration = _a.declaration, importKind = _a.importKind, symbol = _a.symbol, targetFlags = _a.targetFlags;
|
|
147497
147848
|
var moduleSpecifier = ts.tryGetModuleSpecifierFromDeclaration(declaration);
|
|
147498
|
-
|
|
147499
|
-
|
|
147500
|
-
|
|
147849
|
+
if (moduleSpecifier) {
|
|
147850
|
+
var addAsTypeOnly = useRequire
|
|
147851
|
+
? 4 /* NotAllowed */
|
|
147852
|
+
: getAddAsTypeOnly(isValidTypeOnlyUseSite, /*isForNewImportDeclaration*/ true, symbol, targetFlags, checker, compilerOptions);
|
|
147853
|
+
return { kind: 3 /* AddNew */, moduleSpecifier: moduleSpecifier, importKind: importKind, addAsTypeOnly: addAsTypeOnly, useRequire: useRequire };
|
|
147854
|
+
}
|
|
147501
147855
|
}
|
|
147502
147856
|
function getFixesInfo(context, errorCode, pos, useAutoImportProvider) {
|
|
147503
147857
|
var symbolToken = ts.getTokenAtPosition(context.sourceFile, pos);
|
|
@@ -147547,7 +147901,7 @@ var ts;
|
|
|
147547
147901
|
var symbolName = umdSymbol.name;
|
|
147548
147902
|
var exportInfos = [{ symbol: umdSymbol, moduleSymbol: symbol, moduleFileName: undefined, exportKind: 3 /* UMD */, targetFlags: symbol.flags, isFromPackageJson: false }];
|
|
147549
147903
|
var useRequire = shouldUseRequire(sourceFile, program);
|
|
147550
|
-
var fixes = getImportFixes(exportInfos, symbolName, ts.isIdentifier(token) ? token.getStart(sourceFile) : undefined, /*
|
|
147904
|
+
var fixes = getImportFixes(exportInfos, symbolName, ts.isIdentifier(token) ? token.getStart(sourceFile) : undefined, /*isValidTypeOnlyUseSite*/ false, useRequire, program, sourceFile, host, preferences);
|
|
147551
147905
|
return { fixes: fixes, symbolName: symbolName };
|
|
147552
147906
|
}
|
|
147553
147907
|
function getUmdSymbol(token, checker) {
|
|
@@ -147611,12 +147965,12 @@ var ts;
|
|
|
147611
147965
|
var symbolName = getSymbolName(sourceFile, checker, symbolToken, compilerOptions);
|
|
147612
147966
|
// "default" is a keyword and not a legal identifier for the import, so we don't expect it here
|
|
147613
147967
|
ts.Debug.assert(symbolName !== "default" /* Default */, "'default' isn't a legal identifier and couldn't occur here");
|
|
147614
|
-
var
|
|
147968
|
+
var isValidTypeOnlyUseSite = ts.isValidTypeOnlyAliasUseSite(symbolToken);
|
|
147615
147969
|
var useRequire = shouldUseRequire(sourceFile, program);
|
|
147616
147970
|
var exportInfos = getExportInfos(symbolName, ts.getMeaningFromLocation(symbolToken), cancellationToken, sourceFile, program, useAutoImportProvider, host, preferences);
|
|
147617
147971
|
var fixes = ts.arrayFrom(ts.flatMapIterator(exportInfos.entries(), function (_a) {
|
|
147618
147972
|
var _ = _a[0], exportInfos = _a[1];
|
|
147619
|
-
return getImportFixes(exportInfos, symbolName, symbolToken.getStart(sourceFile),
|
|
147973
|
+
return getImportFixes(exportInfos, symbolName, symbolToken.getStart(sourceFile), isValidTypeOnlyUseSite, useRequire, program, sourceFile, host, preferences);
|
|
147620
147974
|
}));
|
|
147621
147975
|
return { fixes: fixes, symbolName: symbolName };
|
|
147622
147976
|
}
|
|
@@ -147694,63 +148048,81 @@ var ts;
|
|
|
147694
148048
|
// allowSyntheticDefaultImports/esModuleInterop is enabled.
|
|
147695
148049
|
return allowSyntheticDefaults ? 1 /* Default */ : 3 /* CommonJS */;
|
|
147696
148050
|
}
|
|
147697
|
-
function codeActionForFix(context, sourceFile, symbolName, fix, quotePreference) {
|
|
148051
|
+
function codeActionForFix(context, sourceFile, symbolName, fix, quotePreference, compilerOptions) {
|
|
147698
148052
|
var diag;
|
|
147699
148053
|
var changes = ts.textChanges.ChangeTracker.with(context, function (tracker) {
|
|
147700
|
-
diag = codeActionForFixWorker(tracker, sourceFile, symbolName, fix, quotePreference);
|
|
148054
|
+
diag = codeActionForFixWorker(tracker, sourceFile, symbolName, fix, quotePreference, compilerOptions);
|
|
147701
148055
|
});
|
|
147702
148056
|
return codefix.createCodeFixAction(codefix.importFixName, changes, diag, importFixId, ts.Diagnostics.Add_all_missing_imports);
|
|
147703
148057
|
}
|
|
147704
|
-
function codeActionForFixWorker(changes, sourceFile, symbolName, fix, quotePreference) {
|
|
148058
|
+
function codeActionForFixWorker(changes, sourceFile, symbolName, fix, quotePreference, compilerOptions) {
|
|
147705
148059
|
switch (fix.kind) {
|
|
147706
148060
|
case 0 /* UseNamespace */:
|
|
147707
148061
|
addNamespaceQualifier(changes, sourceFile, fix);
|
|
147708
148062
|
return [ts.Diagnostics.Change_0_to_1, symbolName, fix.namespacePrefix + "." + symbolName];
|
|
147709
|
-
case 1 /*
|
|
148063
|
+
case 1 /* JsdocTypeImport */:
|
|
147710
148064
|
addImportType(changes, sourceFile, fix, quotePreference);
|
|
147711
148065
|
return [ts.Diagnostics.Change_0_to_1, symbolName, getImportTypePrefix(fix.moduleSpecifier, quotePreference) + symbolName];
|
|
147712
148066
|
case 2 /* AddToExisting */: {
|
|
147713
|
-
var importClauseOrBindingPattern = fix.importClauseOrBindingPattern, importKind = fix.importKind,
|
|
147714
|
-
doAddExistingFix(changes, sourceFile, importClauseOrBindingPattern, importKind === 1 /* Default */ ? symbolName : undefined, importKind === 0 /* Named */ ? [symbolName] : ts.emptyArray,
|
|
148067
|
+
var importClauseOrBindingPattern = fix.importClauseOrBindingPattern, importKind = fix.importKind, addAsTypeOnly = fix.addAsTypeOnly, moduleSpecifier = fix.moduleSpecifier;
|
|
148068
|
+
doAddExistingFix(changes, sourceFile, importClauseOrBindingPattern, importKind === 1 /* Default */ ? { name: symbolName, addAsTypeOnly: addAsTypeOnly } : undefined, importKind === 0 /* Named */ ? [{ name: symbolName, addAsTypeOnly: addAsTypeOnly }] : ts.emptyArray, compilerOptions);
|
|
147715
148069
|
var moduleSpecifierWithoutQuotes = ts.stripQuotes(moduleSpecifier);
|
|
147716
|
-
return [
|
|
148070
|
+
return [
|
|
148071
|
+
importKind === 1 /* Default */ ? ts.Diagnostics.Add_default_import_0_to_existing_import_declaration_from_1 : ts.Diagnostics.Add_0_to_existing_import_declaration_from_1,
|
|
148072
|
+
symbolName,
|
|
148073
|
+
moduleSpecifierWithoutQuotes
|
|
148074
|
+
]; // you too!
|
|
147717
148075
|
}
|
|
147718
148076
|
case 3 /* AddNew */: {
|
|
147719
|
-
var importKind = fix.importKind, moduleSpecifier = fix.moduleSpecifier,
|
|
148077
|
+
var importKind = fix.importKind, moduleSpecifier = fix.moduleSpecifier, addAsTypeOnly = fix.addAsTypeOnly, useRequire = fix.useRequire;
|
|
147720
148078
|
var getDeclarations = useRequire ? getNewRequires : getNewImports;
|
|
147721
|
-
var
|
|
147722
|
-
|
|
147723
|
-
|
|
147724
|
-
ts.insertImports(changes, sourceFile, getDeclarations(moduleSpecifier, quotePreference,
|
|
148079
|
+
var defaultImport = importKind === 1 /* Default */ ? { name: symbolName, addAsTypeOnly: addAsTypeOnly } : undefined;
|
|
148080
|
+
var namedImports = importKind === 0 /* Named */ ? [{ name: symbolName, addAsTypeOnly: addAsTypeOnly }] : undefined;
|
|
148081
|
+
var namespaceLikeImport = importKind === 2 /* Namespace */ || importKind === 3 /* CommonJS */ ? { importKind: importKind, name: symbolName, addAsTypeOnly: addAsTypeOnly } : undefined;
|
|
148082
|
+
ts.insertImports(changes, sourceFile, getDeclarations(moduleSpecifier, quotePreference, defaultImport, namedImports, namespaceLikeImport), /*blankLineBetween*/ true);
|
|
147725
148083
|
return [importKind === 1 /* Default */ ? ts.Diagnostics.Import_default_0_from_module_1 : ts.Diagnostics.Import_0_from_module_1, symbolName, moduleSpecifier];
|
|
147726
148084
|
}
|
|
147727
148085
|
default:
|
|
147728
148086
|
return ts.Debug.assertNever(fix, "Unexpected fix kind " + fix.kind);
|
|
147729
148087
|
}
|
|
147730
148088
|
}
|
|
147731
|
-
function doAddExistingFix(changes, sourceFile, clause, defaultImport, namedImports,
|
|
148089
|
+
function doAddExistingFix(changes, sourceFile, clause, defaultImport, namedImports, compilerOptions) {
|
|
148090
|
+
var _a;
|
|
147732
148091
|
if (clause.kind === 200 /* ObjectBindingPattern */) {
|
|
147733
148092
|
if (defaultImport) {
|
|
147734
|
-
addElementToBindingPattern(clause, defaultImport, "default");
|
|
148093
|
+
addElementToBindingPattern(clause, defaultImport.name, "default");
|
|
147735
148094
|
}
|
|
147736
148095
|
for (var _i = 0, namedImports_1 = namedImports; _i < namedImports_1.length; _i++) {
|
|
147737
148096
|
var specifier = namedImports_1[_i];
|
|
147738
|
-
addElementToBindingPattern(clause, specifier, /*propertyName*/ undefined);
|
|
148097
|
+
addElementToBindingPattern(clause, specifier.name, /*propertyName*/ undefined);
|
|
147739
148098
|
}
|
|
147740
148099
|
return;
|
|
147741
148100
|
}
|
|
147742
|
-
var
|
|
148101
|
+
var promoteFromTypeOnly = clause.isTypeOnly && ts.some(__spreadArray([defaultImport], namedImports, true), function (i) { return (i === null || i === void 0 ? void 0 : i.addAsTypeOnly) === 4 /* NotAllowed */; });
|
|
148102
|
+
var existingSpecifiers = clause.namedBindings && ((_a = ts.tryCast(clause.namedBindings, ts.isNamedImports)) === null || _a === void 0 ? void 0 : _a.elements);
|
|
148103
|
+
// If we are promoting from a type-only import and `--isolatedModules` and `--preserveValueImports`
|
|
148104
|
+
// are enabled, we need to make every existing import specifier type-only. It may be possible that
|
|
148105
|
+
// some of them don't strictly need to be marked type-only (if they have a value meaning and are
|
|
148106
|
+
// never used in an emitting position). These are allowed to be imported without being type-only,
|
|
148107
|
+
// but the user has clearly already signified that they don't need them to be present at runtime
|
|
148108
|
+
// by placing them in a type-only import. So, just mark each specifier as type-only.
|
|
148109
|
+
var convertExistingToTypeOnly = promoteFromTypeOnly && compilerOptions.preserveValueImports && compilerOptions.isolatedModules;
|
|
147743
148110
|
if (defaultImport) {
|
|
147744
148111
|
ts.Debug.assert(!clause.name, "Cannot add a default import to an import clause that already has one");
|
|
147745
|
-
changes.insertNodeAt(sourceFile, clause.getStart(sourceFile), ts.factory.createIdentifier(defaultImport), { suffix: ", " });
|
|
148112
|
+
changes.insertNodeAt(sourceFile, clause.getStart(sourceFile), ts.factory.createIdentifier(defaultImport.name), { suffix: ", " });
|
|
147746
148113
|
}
|
|
147747
148114
|
if (namedImports.length) {
|
|
147748
|
-
var
|
|
147749
|
-
|
|
148115
|
+
var newSpecifiers = ts.stableSort(namedImports.map(function (namedImport) { return ts.factory.createImportSpecifier((!clause.isTypeOnly || promoteFromTypeOnly) && needsTypeOnly(namedImport),
|
|
148116
|
+
/*propertyName*/ undefined, ts.factory.createIdentifier(namedImport.name)); }), ts.OrganizeImports.compareImportOrExportSpecifiers);
|
|
147750
148117
|
if ((existingSpecifiers === null || existingSpecifiers === void 0 ? void 0 : existingSpecifiers.length) && ts.OrganizeImports.importSpecifiersAreSorted(existingSpecifiers)) {
|
|
147751
|
-
for (var
|
|
147752
|
-
var spec = newSpecifiers_1[
|
|
147753
|
-
|
|
148118
|
+
for (var _b = 0, newSpecifiers_1 = newSpecifiers; _b < newSpecifiers_1.length; _b++) {
|
|
148119
|
+
var spec = newSpecifiers_1[_b];
|
|
148120
|
+
// Organize imports puts type-only import specifiers last, so if we're
|
|
148121
|
+
// adding a non-type-only specifier and converting all the other ones to
|
|
148122
|
+
// type-only, there's no need to ask for the insertion index - it's 0.
|
|
148123
|
+
var insertionIndex = convertExistingToTypeOnly && !spec.isTypeOnly
|
|
148124
|
+
? 0
|
|
148125
|
+
: ts.OrganizeImports.getImportSpecifierInsertionIndex(existingSpecifiers, spec);
|
|
147754
148126
|
var prevSpecifier = clause.namedBindings.elements[insertionIndex - 1];
|
|
147755
148127
|
if (prevSpecifier) {
|
|
147756
148128
|
changes.insertNodeInListAfter(sourceFile, prevSpecifier, spec);
|
|
@@ -147761,8 +148133,8 @@ var ts;
|
|
|
147761
148133
|
}
|
|
147762
148134
|
}
|
|
147763
148135
|
else if (existingSpecifiers === null || existingSpecifiers === void 0 ? void 0 : existingSpecifiers.length) {
|
|
147764
|
-
for (var
|
|
147765
|
-
var spec = newSpecifiers_2[
|
|
148136
|
+
for (var _c = 0, newSpecifiers_2 = newSpecifiers; _c < newSpecifiers_2.length; _c++) {
|
|
148137
|
+
var spec = newSpecifiers_2[_c];
|
|
147766
148138
|
changes.insertNodeInListAfter(sourceFile, ts.last(existingSpecifiers), spec, existingSpecifiers);
|
|
147767
148139
|
}
|
|
147768
148140
|
}
|
|
@@ -147778,8 +148150,14 @@ var ts;
|
|
|
147778
148150
|
}
|
|
147779
148151
|
}
|
|
147780
148152
|
}
|
|
147781
|
-
if (
|
|
148153
|
+
if (promoteFromTypeOnly) {
|
|
147782
148154
|
changes.delete(sourceFile, ts.getTypeKeywordOfTypeOnlyImport(clause, sourceFile));
|
|
148155
|
+
if (convertExistingToTypeOnly && existingSpecifiers) {
|
|
148156
|
+
for (var _d = 0, existingSpecifiers_1 = existingSpecifiers; _d < existingSpecifiers_1.length; _d++) {
|
|
148157
|
+
var specifier = existingSpecifiers_1[_d];
|
|
148158
|
+
changes.insertModifierBefore(sourceFile, 151 /* TypeKeyword */, specifier);
|
|
148159
|
+
}
|
|
148160
|
+
}
|
|
147783
148161
|
}
|
|
147784
148162
|
function addElementToBindingPattern(bindingPattern, name, propertyName) {
|
|
147785
148163
|
var element = ts.factory.createBindingElement(/*dotDotDotToken*/ undefined, propertyName, name);
|
|
@@ -147803,44 +148181,53 @@ var ts;
|
|
|
147803
148181
|
var quote = ts.getQuoteFromPreference(quotePreference);
|
|
147804
148182
|
return "import(" + quote + moduleSpecifier + quote + ").";
|
|
147805
148183
|
}
|
|
147806
|
-
function
|
|
147807
|
-
var _a
|
|
148184
|
+
function needsTypeOnly(_a) {
|
|
148185
|
+
var addAsTypeOnly = _a.addAsTypeOnly;
|
|
148186
|
+
return addAsTypeOnly === 2 /* Required */;
|
|
148187
|
+
}
|
|
148188
|
+
function getNewImports(moduleSpecifier, quotePreference, defaultImport, namedImports, namespaceLikeImport) {
|
|
147808
148189
|
var quotedModuleSpecifier = ts.makeStringLiteral(moduleSpecifier, quotePreference);
|
|
147809
148190
|
var statements;
|
|
147810
|
-
if (
|
|
147811
|
-
|
|
148191
|
+
if (defaultImport !== undefined || (namedImports === null || namedImports === void 0 ? void 0 : namedImports.length)) {
|
|
148192
|
+
var topLevelTypeOnly_1 = (!defaultImport || needsTypeOnly(defaultImport)) && ts.every(namedImports, needsTypeOnly);
|
|
148193
|
+
statements = ts.combine(statements, ts.makeImport(defaultImport && ts.factory.createIdentifier(defaultImport.name), namedImports === null || namedImports === void 0 ? void 0 : namedImports.map(function (_a) {
|
|
148194
|
+
var addAsTypeOnly = _a.addAsTypeOnly, name = _a.name;
|
|
148195
|
+
return ts.factory.createImportSpecifier(!topLevelTypeOnly_1 && addAsTypeOnly === 2 /* Required */,
|
|
148196
|
+
/*propertyName*/ undefined, ts.factory.createIdentifier(name));
|
|
148197
|
+
}), moduleSpecifier, quotePreference, topLevelTypeOnly_1));
|
|
147812
148198
|
}
|
|
147813
|
-
var namespaceLikeImport = imports.namespaceLikeImport, typeOnly = imports.typeOnly;
|
|
147814
148199
|
if (namespaceLikeImport) {
|
|
147815
148200
|
var declaration = namespaceLikeImport.importKind === 3 /* CommonJS */
|
|
147816
148201
|
? ts.factory.createImportEqualsDeclaration(
|
|
147817
148202
|
/*decorators*/ undefined,
|
|
147818
|
-
/*modifiers*/ undefined,
|
|
148203
|
+
/*modifiers*/ undefined, needsTypeOnly(namespaceLikeImport), ts.factory.createIdentifier(namespaceLikeImport.name), ts.factory.createExternalModuleReference(quotedModuleSpecifier))
|
|
147819
148204
|
: ts.factory.createImportDeclaration(
|
|
147820
148205
|
/*decorators*/ undefined,
|
|
147821
|
-
/*modifiers*/ undefined, ts.factory.createImportClause(
|
|
148206
|
+
/*modifiers*/ undefined, ts.factory.createImportClause(needsTypeOnly(namespaceLikeImport),
|
|
147822
148207
|
/*name*/ undefined, ts.factory.createNamespaceImport(ts.factory.createIdentifier(namespaceLikeImport.name))), quotedModuleSpecifier,
|
|
147823
148208
|
/*assertClause*/ undefined);
|
|
147824
148209
|
statements = ts.combine(statements, declaration);
|
|
147825
148210
|
}
|
|
147826
148211
|
return ts.Debug.checkDefined(statements);
|
|
147827
148212
|
}
|
|
147828
|
-
function getNewRequires(moduleSpecifier, quotePreference,
|
|
147829
|
-
var _a, _b;
|
|
148213
|
+
function getNewRequires(moduleSpecifier, quotePreference, defaultImport, namedImports, namespaceLikeImport) {
|
|
147830
148214
|
var quotedModuleSpecifier = ts.makeStringLiteral(moduleSpecifier, quotePreference);
|
|
147831
148215
|
var statements;
|
|
147832
148216
|
// const { default: foo, bar, etc } = require('./mod');
|
|
147833
|
-
if (
|
|
147834
|
-
var bindingElements = (
|
|
147835
|
-
|
|
147836
|
-
|
|
148217
|
+
if (defaultImport || (namedImports === null || namedImports === void 0 ? void 0 : namedImports.length)) {
|
|
148218
|
+
var bindingElements = (namedImports === null || namedImports === void 0 ? void 0 : namedImports.map(function (_a) {
|
|
148219
|
+
var name = _a.name;
|
|
148220
|
+
return ts.factory.createBindingElement(/*dotDotDotToken*/ undefined, /*propertyName*/ undefined, name);
|
|
148221
|
+
})) || [];
|
|
148222
|
+
if (defaultImport) {
|
|
148223
|
+
bindingElements.unshift(ts.factory.createBindingElement(/*dotDotDotToken*/ undefined, "default", defaultImport.name));
|
|
147837
148224
|
}
|
|
147838
148225
|
var declaration = createConstEqualsRequireDeclaration(ts.factory.createObjectBindingPattern(bindingElements), quotedModuleSpecifier);
|
|
147839
148226
|
statements = ts.combine(statements, declaration);
|
|
147840
148227
|
}
|
|
147841
148228
|
// const foo = require('./mod');
|
|
147842
|
-
if (
|
|
147843
|
-
var declaration = createConstEqualsRequireDeclaration(
|
|
148229
|
+
if (namespaceLikeImport) {
|
|
148230
|
+
var declaration = createConstEqualsRequireDeclaration(namespaceLikeImport.name, quotedModuleSpecifier);
|
|
147844
148231
|
statements = ts.combine(statements, declaration);
|
|
147845
148232
|
}
|
|
147846
148233
|
return ts.Debug.checkDefined(statements);
|
|
@@ -151752,7 +152139,7 @@ var ts;
|
|
|
151752
152139
|
return ts.factory.createQualifiedName(replaceFirstIdentifierOfEntityName(name.left, newIdentifier), name.right);
|
|
151753
152140
|
}
|
|
151754
152141
|
function importSymbols(importAdder, symbols) {
|
|
151755
|
-
symbols.forEach(function (s) { return importAdder.addImportFromExportedSymbol(s, /*
|
|
152142
|
+
symbols.forEach(function (s) { return importAdder.addImportFromExportedSymbol(s, /*isValidTypeOnlyUseSite*/ true); });
|
|
151756
152143
|
}
|
|
151757
152144
|
codefix.importSymbols = importSymbols;
|
|
151758
152145
|
})(codefix = ts.codefix || (ts.codefix = {}));
|
|
@@ -152224,7 +152611,7 @@ var ts;
|
|
|
152224
152611
|
if (!ts.isIdentifier(element.name) || element.initializer) {
|
|
152225
152612
|
return undefined;
|
|
152226
152613
|
}
|
|
152227
|
-
importSpecifiers.push(ts.factory.createImportSpecifier(ts.tryCast(element.propertyName, ts.isIdentifier), element.name));
|
|
152614
|
+
importSpecifiers.push(ts.factory.createImportSpecifier(/*isTypeOnly*/ false, ts.tryCast(element.propertyName, ts.isIdentifier), element.name));
|
|
152228
152615
|
}
|
|
152229
152616
|
if (importSpecifiers.length) {
|
|
152230
152617
|
return ts.factory.createNamedImports(importSpecifiers);
|
|
@@ -152971,10 +153358,10 @@ var ts;
|
|
|
152971
153358
|
}
|
|
152972
153359
|
}
|
|
152973
153360
|
function makeImportSpecifier(propertyName, name) {
|
|
152974
|
-
return ts.factory.createImportSpecifier(propertyName === name ? undefined : ts.factory.createIdentifier(propertyName), ts.factory.createIdentifier(name));
|
|
153361
|
+
return ts.factory.createImportSpecifier(/*isTypeOnly*/ false, propertyName === name ? undefined : ts.factory.createIdentifier(propertyName), ts.factory.createIdentifier(name));
|
|
152975
153362
|
}
|
|
152976
153363
|
function makeExportSpecifier(propertyName, name) {
|
|
152977
|
-
return ts.factory.createExportSpecifier(propertyName === name ? undefined : ts.factory.createIdentifier(propertyName), ts.factory.createIdentifier(name));
|
|
153364
|
+
return ts.factory.createExportSpecifier(/*isTypeOnly*/ false, propertyName === name ? undefined : ts.factory.createIdentifier(propertyName), ts.factory.createIdentifier(name));
|
|
152978
153365
|
}
|
|
152979
153366
|
})(refactor = ts.refactor || (ts.refactor = {}));
|
|
152980
153367
|
})(ts || (ts = {}));
|
|
@@ -153087,7 +153474,7 @@ var ts;
|
|
|
153087
153474
|
}
|
|
153088
153475
|
var importSpecifiers = [];
|
|
153089
153476
|
exportNameToImportName.forEach(function (name, propertyName) {
|
|
153090
|
-
importSpecifiers.push(ts.factory.createImportSpecifier(name === propertyName ? undefined : ts.factory.createIdentifier(propertyName), ts.factory.createIdentifier(name)));
|
|
153477
|
+
importSpecifiers.push(ts.factory.createImportSpecifier(/*isTypeOnly*/ false, name === propertyName ? undefined : ts.factory.createIdentifier(propertyName), ts.factory.createIdentifier(name)));
|
|
153091
153478
|
});
|
|
153092
153479
|
var importDecl = toConvert.parent.parent;
|
|
153093
153480
|
if (usedAsNamespaceOrDefault && !allowSyntheticDefaultImports) {
|
|
@@ -153158,7 +153545,7 @@ var ts;
|
|
|
153158
153545
|
changes.replaceNode(sourceFile, toConvert, ts.factory.createNamespaceImport(ts.factory.createIdentifier(namespaceImportName)));
|
|
153159
153546
|
if (neededNamedImports.size) {
|
|
153160
153547
|
var newNamedImports = ts.arrayFrom(neededNamedImports.values()).map(function (element) {
|
|
153161
|
-
return ts.factory.createImportSpecifier(element.propertyName && ts.factory.createIdentifier(element.propertyName.text), ts.factory.createIdentifier(element.name.text));
|
|
153548
|
+
return ts.factory.createImportSpecifier(element.isTypeOnly, element.propertyName && ts.factory.createIdentifier(element.propertyName.text), ts.factory.createIdentifier(element.name.text));
|
|
153162
153549
|
});
|
|
153163
153550
|
changes.insertNodeAfter(sourceFile, toConvert.parent.parent, updateImport(importDecl, /*defaultImportName*/ undefined, newNamedImports));
|
|
153164
153551
|
}
|
|
@@ -155860,7 +156247,7 @@ var ts;
|
|
|
155860
156247
|
function makeImportOrRequire(defaultImport, imports, path, useEs6Imports, quotePreference) {
|
|
155861
156248
|
path = ts.ensurePathIsNonModuleName(path);
|
|
155862
156249
|
if (useEs6Imports) {
|
|
155863
|
-
var specifiers = imports.map(function (i) { return ts.factory.createImportSpecifier(/*propertyName*/ undefined, ts.factory.createIdentifier(i)); });
|
|
156250
|
+
var specifiers = imports.map(function (i) { return ts.factory.createImportSpecifier(/*isTypeOnly*/ false, /*propertyName*/ undefined, ts.factory.createIdentifier(i)); });
|
|
155864
156251
|
return ts.makeImportIfNecessary(defaultImport, specifiers, path, quotePreference);
|
|
155865
156252
|
}
|
|
155866
156253
|
else {
|